(
scale: Scale,
splitNumber: number,
breaks: ParsedAxisBreakList,
scaleInterval: number
)
| 25 | |
| 26 | |
| 27 | export function getMinorTicks( |
| 28 | scale: Scale, |
| 29 | splitNumber: number, |
| 30 | breaks: ParsedAxisBreakList, |
| 31 | scaleInterval: number |
| 32 | ): number[][] { |
| 33 | const ticks = scale.getTicks({ |
| 34 | expandToNicedExtent: true, |
| 35 | }); |
| 36 | // NOTE: In log-scale, do not support minor ticks when breaks exist. |
| 37 | // because currently log-scale minor ticks is calculated based on raw values |
| 38 | // rather than log-transformed value, due to an odd effect when breaks exist. |
| 39 | const minorTicks = []; |
| 40 | const extent = scale.getExtent(); |
| 41 | |
| 42 | for (let i = 1; i < ticks.length; i++) { |
| 43 | const nextTick = ticks[i]; |
| 44 | const prevTick = ticks[i - 1]; |
| 45 | |
| 46 | if (prevTick.break || nextTick.break) { |
| 47 | // Do not build minor ticks to the adjacent ticks to breaks ticks, |
| 48 | // since the interval might be irregular. |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | let count = 0; |
| 53 | const minorTicksGroup = []; |
| 54 | const interval = nextTick.value - prevTick.value; |
| 55 | const minorInterval = interval / splitNumber; |
| 56 | const minorIntervalPrecision = getIntervalPrecision(minorInterval); |
| 57 | |
| 58 | while (count < splitNumber - 1) { |
| 59 | const minorTick = round(prevTick.value + (count + 1) * minorInterval, minorIntervalPrecision); |
| 60 | |
| 61 | // For the first and last interval. The count may be less than splitNumber. |
| 62 | if (minorTick > extent[0] && minorTick < extent[1]) { |
| 63 | minorTicksGroup.push(minorTick); |
| 64 | } |
| 65 | count++; |
| 66 | } |
| 67 | |
| 68 | const scaleBreakHelper = getScaleBreakHelper(); |
| 69 | scaleBreakHelper && scaleBreakHelper.pruneTicksByBreak( |
| 70 | 'auto', |
| 71 | minorTicksGroup, |
| 72 | breaks, |
| 73 | value => value, |
| 74 | scaleInterval, |
| 75 | extent |
| 76 | ); |
| 77 | minorTicks.push(minorTicksGroup); |
| 78 | } |
| 79 | |
| 80 | return minorTicks; |
| 81 | } |
no test coverage detected
searching dependent graphs…