MCPcopy Create free account
hub / github.com/feiyu563/PrometheusAlert / computeLabelSizes

Function computeLabelSizes

static/plugins/chart.js/Chart.bundle.js:11228–11284  ·  view source on GitHub ↗

* Returns {width, height, offset} objects for the first, last, widest, highest tick * labels where offset indicates the anchor point offset from the top in pixels.

(ctx, tickFonts, ticks, caches)

Source from the content-addressed store, hash-verified

11226 * labels where offset indicates the anchor point offset from the top in pixels.
11227 */
11228function computeLabelSizes(ctx, tickFonts, ticks, caches) {
11229 var length = ticks.length;
11230 var widths = [];
11231 var heights = [];
11232 var offsets = [];
11233 var widestLabelSize = 0;
11234 var highestLabelSize = 0;
11235 var i, j, jlen, label, tickFont, fontString, cache, lineHeight, width, height, nestedLabel, widest, highest;
11236
11237 for (i = 0; i < length; ++i) {
11238 label = ticks[i].label;
11239 tickFont = ticks[i].major ? tickFonts.major : tickFonts.minor;
11240 ctx.font = fontString = tickFont.string;
11241 cache = caches[fontString] = caches[fontString] || {data: {}, gc: []};
11242 lineHeight = tickFont.lineHeight;
11243 width = height = 0;
11244 // Undefined labels and arrays should not be measured
11245 if (!isNullOrUndef(label) && !isArray(label)) {
11246 width = helpers$1.measureText(ctx, cache.data, cache.gc, width, label);
11247 height = lineHeight;
11248 } else if (isArray(label)) {
11249 // if it is an array let's measure each element
11250 for (j = 0, jlen = label.length; j < jlen; ++j) {
11251 nestedLabel = label[j];
11252 // Undefined labels and arrays should not be measured
11253 if (!isNullOrUndef(nestedLabel) && !isArray(nestedLabel)) {
11254 width = helpers$1.measureText(ctx, cache.data, cache.gc, width, nestedLabel);
11255 height += lineHeight;
11256 }
11257 }
11258 }
11259 widths.push(width);
11260 heights.push(height);
11261 offsets.push(lineHeight / 2);
11262 widestLabelSize = Math.max(width, widestLabelSize);
11263 highestLabelSize = Math.max(height, highestLabelSize);
11264 }
11265 garbageCollect(caches, length);
11266
11267 widest = widths.indexOf(widestLabelSize);
11268 highest = heights.indexOf(highestLabelSize);
11269
11270 function valueAt(idx) {
11271 return {
11272 width: widths[idx] || 0,
11273 height: heights[idx] || 0,
11274 offset: offsets[idx] || 0
11275 };
11276 }
11277
11278 return {
11279 first: valueAt(0),
11280 last: valueAt(length - 1),
11281 widest: valueAt(widest),
11282 highest: valueAt(highest)
11283 };
11284}
11285

Callers 1

Chart.bundle.jsFile · 0.70

Calls 3

isArrayFunction · 0.70
garbageCollectFunction · 0.70
valueAtFunction · 0.70

Tested by

no test coverage detected