(
scale: IntervalScale,
opt: Pick<ScaleCalcNiceMethodOpt, 'splitNumber' | 'minInterval' | 'maxInterval' | 'userInterval'>
)
| 116 | // ------ START: IntervalScale Nice ------ |
| 117 | |
| 118 | function intervalScaleCalcNiceTicks( |
| 119 | scale: IntervalScale, |
| 120 | opt: Pick<ScaleCalcNiceMethodOpt, 'splitNumber' | 'minInterval' | 'maxInterval' | 'userInterval'> |
| 121 | ): IntervalScaleConfig { |
| 122 | const splitNumber = ensureValidSplitNumber(opt.splitNumber, 5); |
| 123 | // Use the span in the innermost linear space to calculate nice ticks. |
| 124 | const span = getScaleLinearSpanEffective(scale); |
| 125 | |
| 126 | if (__DEV__) { |
| 127 | assert(isFinite(span) && span > 0); // It should have been ensured by `intervalScaleEnsureValidExtent`. |
| 128 | } |
| 129 | |
| 130 | const minInterval = opt.minInterval; |
| 131 | const maxInterval = opt.maxInterval; |
| 132 | |
| 133 | let interval = nice(span / splitNumber, true); |
| 134 | if (minInterval != null && interval < minInterval) { |
| 135 | interval = minInterval; |
| 136 | } |
| 137 | if (maxInterval != null && interval > maxInterval) { |
| 138 | interval = maxInterval; |
| 139 | } |
| 140 | |
| 141 | const intervalPrecision = getIntervalPrecision(interval); |
| 142 | const extent = scale.getExtent(); |
| 143 | // By design, the `niceExtent` is inside the original extent |
| 144 | const niceExtent = [ |
| 145 | round(mathCeil(extent[0] / interval) * interval, intervalPrecision), |
| 146 | round(mathFloor(extent[1] / interval) * interval, intervalPrecision) |
| 147 | ]; |
| 148 | |
| 149 | return {interval, intervalPrecision, niceExtent}; |
| 150 | }; |
| 151 | |
| 152 | // ------ END: IntervalScale Nice ------ |
| 153 |
no test coverage detected
searching dependent graphs…