MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / calculateCategoryInterval

Function calculateCategoryInterval

libs/echarts/echarts.simple.js:38432–38523  ·  view source on GitHub ↗

* Calculate interval for category axis ticks and labels. * To get precise result, at least one of `getRotate` and `isHorizontal` * should be implemented in axis.

(axis)

Source from the content-addressed store, hash-verified

38430 * should be implemented in axis.
38431 */
38432function calculateCategoryInterval(axis) {
38433 var params = fetchAutoCategoryIntervalCalculationParams(axis);
38434 var labelFormatter = makeLabelFormatter(axis);
38435 var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
38436
38437 var ordinalScale = axis.scale;
38438 var ordinalExtent = ordinalScale.getExtent();
38439 // Providing this method is for optimization:
38440 // avoid generating a long array by `getTicks`
38441 // in large category data case.
38442 var tickCount = ordinalScale.count();
38443
38444 if (ordinalExtent[1] - ordinalExtent[0] < 1) {
38445 return 0;
38446 }
38447
38448 var step = 1;
38449 // Simple optimization. Empirical value: tick count should less than 40.
38450 if (tickCount > 40) {
38451 step = Math.max(1, Math.floor(tickCount / 40));
38452 }
38453 var tickValue = ordinalExtent[0];
38454 var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
38455 var unitW = Math.abs(unitSpan * Math.cos(rotation));
38456 var unitH = Math.abs(unitSpan * Math.sin(rotation));
38457
38458 var maxW = 0;
38459 var maxH = 0;
38460
38461 // Caution: Performance sensitive for large category data.
38462 // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
38463 for (; tickValue <= ordinalExtent[1]; tickValue += step) {
38464 var width = 0;
38465 var height = 0;
38466
38467 // Not precise, do not consider align and vertical align
38468 // and each distance from axis line yet.
38469 var rect = getBoundingRect(
38470 labelFormatter(tickValue), params.font, 'center', 'top'
38471 );
38472 // Magic number
38473 width = rect.width * 1.3;
38474 height = rect.height * 1.3;
38475
38476 // Min size, void long loop.
38477 maxW = Math.max(maxW, width, 7);
38478 maxH = Math.max(maxH, height, 7);
38479 }
38480
38481 var dw = maxW / unitW;
38482 var dh = maxH / unitH;
38483 // 0/0 is NaN, 1/0 is Infinity.
38484 isNaN(dw) && (dw = Infinity);
38485 isNaN(dh) && (dh = Infinity);
38486 var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
38487
38488 var cache = inner$6(axis.model);
38489 var axisExtent = axis.getExtent();

Callers 1

echarts.simple.jsFile · 0.70

Calls 8

maxMethod · 0.80
cosMethod · 0.80
sinMethod · 0.80
minMethod · 0.80
makeLabelFormatterFunction · 0.70
getBoundingRectFunction · 0.70
getExtentMethod · 0.45

Tested by

no test coverage detected