MCPcopy
hub / github.com/apache/echarts / scaleCalcAlign

Function scaleCalcAlign

src/coord/axisAlignTicks.ts:44–360  ·  view source on GitHub ↗
(
    targetAxis: Axis,
    alignToScale: IntervalScale | LogScale
)

Source from the content-addressed store, hash-verified

42 * @see SCALE_EXTENT_CONSTRUCTION for the full processing flow.
43 */
44export function scaleCalcAlign(
45 targetAxis: Axis,
46 alignToScale: IntervalScale | LogScale
47): void {
48
49 const targetScale = targetAxis.scale as (IntervalScale | LogScale) & Scale;
50 const targetAxisModel = targetAxis.model;
51 if (__DEV__) {
52 assert(targetScale && targetAxisModel
53 && (targetScale instanceof IntervalScale || targetScale instanceof LogScale)
54 && (alignToScale instanceof IntervalScale || alignToScale instanceof LogScale)
55 );
56 }
57 const targetExtentInfo = adoptScaleRawExtentInfoAndPrepare(
58 targetScale, targetAxisModel, targetAxisModel.ecModel, targetAxis, null
59 );
60
61 // FIXME:
62 // (1) Axis inverse is not considered yet.
63 // (2) `SCALE_EXTENT_KIND_MAPPING` is not considered yet.
64
65 const isTargetLogScale = isLogScale(targetScale);
66 const alignToScaleLinear = isLogScale(alignToScale) ? alignToScale.intervalStub : alignToScale;
67 const targetIntervalStub = isTargetLogScale ? targetScale.intervalStub : targetScale;
68
69 const targetLogScaleBase = (targetScale as LogScale).base;
70 const alignToTicks = alignToScaleLinear.getTicks();
71 const alignToExpNiceTicks = alignToScaleLinear.getTicks({expandToNicedExtent: true});
72 const alignToSegCount = alignToTicks.length - 1;
73
74 if (__DEV__) {
75 // This is guards for future changes of `Interval#getTicks`.
76 assert(!hasBreaks(alignToScale) && !hasBreaks(targetScale));
77 assert(alignToSegCount > 0); // Ticks length >= 2 even on a blank scale.
78 assert(alignToExpNiceTicks.length === alignToTicks.length);
79 assert(alignToTicks[0].value <= alignToTicks[alignToSegCount].value);
80 assert(
81 alignToExpNiceTicks[0].value <= alignToTicks[0].value
82 && alignToTicks[alignToSegCount].value <= alignToExpNiceTicks[alignToSegCount].value
83 );
84 if (alignToSegCount >= 2) {
85 assert(alignToExpNiceTicks[1].value === alignToTicks[1].value);
86 assert(alignToExpNiceTicks[alignToSegCount - 1].value === alignToTicks[alignToSegCount - 1].value);
87 }
88 }
89
90 // The Current strategy: Find a proper interval and an extent for the target scale to derive ticks
91 // matching exactly to ticks of `alignTo` scale.
92
93 // Adjust min, max based on the extent of alignTo. When min or max is set in alignTo scale
94 let t0: number; // diff ratio on min not-nice segment. 0 <= t0 < 1
95 let t1: number; // diff ratio on max not-nice segment. 0 <= t1 < 1
96 let alignToNiceSegCount: number; // >= 1
97 // Consider ticks of `alignTo`, only these cases below may occur:
98 if (alignToSegCount === 1) {
99 // `alignToTicks` is like:
100 // |--|
101 // In this case, we make the corresponding 2 target ticks "nice".

Callers 2

updateAxisTicksMethod · 0.90
updateMethod · 0.90

Calls 15

isLogScaleFunction · 0.90
hasBreaksFunction · 0.90
isNullableNumberFiniteFunction · 0.90
roundFunction · 0.90
quantityFunction · 0.90
niceFunction · 0.90
getIntervalPrecisionFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…