(
intervalStub: IntervalScale,
opt: Pick<
ScaleCalcNiceMethodOpt,
'splitNumber' | 'minInterval' | 'maxInterval' | 'userInterval'
>
)
| 155 | // ------ START: LogScale Nice ------ |
| 156 | |
| 157 | function logScaleCalcNiceTicks( |
| 158 | intervalStub: IntervalScale, |
| 159 | opt: Pick< |
| 160 | ScaleCalcNiceMethodOpt, |
| 161 | 'splitNumber' | 'minInterval' | 'maxInterval' | 'userInterval' |
| 162 | > |
| 163 | ): IntervalScaleConfig { |
| 164 | // [CAVEAT]: If updating this impl, need to sync it to `axisAlignTicks.ts`. |
| 165 | |
| 166 | const splitNumber = ensureValidSplitNumber(opt.splitNumber, 10); |
| 167 | // Find nice ticks in the "logarithmic space". Notice that "logarithmic space" is a middle space |
| 168 | // rather than the innermost linear space when axis breaks exist. |
| 169 | const intervalExtent = intervalStub.getExtent(); |
| 170 | // But use the span in the innermost linear space to calculate nice ticks. |
| 171 | const span = getScaleLinearSpanEffective(intervalStub); |
| 172 | |
| 173 | if (__DEV__) { |
| 174 | assert(isFinite(span) && span > 0); // It should be ensured by `intervalScaleEnsureValidExtent`. |
| 175 | } |
| 176 | |
| 177 | // Interval should be integer |
| 178 | let interval = mathMax(quantity(span), 1); |
| 179 | const err = splitNumber / span * interval; |
| 180 | // Filter ticks to get closer to the desired count. |
| 181 | if (err <= 0.5) { |
| 182 | // TODO: support other bases other than 10? |
| 183 | interval *= 10; |
| 184 | } |
| 185 | |
| 186 | const intervalPrecision = getIntervalPrecision(interval); |
| 187 | // For LogScale, we use a `niceExtent` in the "logarithmic space" rather than |
| 188 | // the original "pow space", because it is used in `intervalStub.getTicks()` thereafter. |
| 189 | const niceExtent = [ |
| 190 | round(mathCeil(intervalExtent[0] / interval) * interval, intervalPrecision), |
| 191 | round(mathFloor(intervalExtent[1] / interval) * interval, intervalPrecision) |
| 192 | ] as [number, number]; |
| 193 | |
| 194 | return {intervalPrecision, interval, niceExtent}; |
| 195 | }; |
| 196 | |
| 197 | // ------ END: LogScale Nice ------ |
| 198 |
no test coverage detected
searching dependent graphs…