* In ascending order.
(opt?: ScaleGetTicksOpt)
| 181 | * In ascending order. |
| 182 | */ |
| 183 | getTicks(opt?: ScaleGetTicksOpt): ScaleTick[] { |
| 184 | opt = opt || {}; |
| 185 | const cfg = this._cfg; |
| 186 | const interval = cfg.interval; |
| 187 | const extent = getScaleExtentForTickUnsafe(this); |
| 188 | const niceExtent = cfg.niceExtent; |
| 189 | const intervalPrecision = cfg.intervalPrecision; |
| 190 | const scaleBreakHelper = getScaleBreakHelper(); |
| 191 | const brk = this.brk; |
| 192 | const brkAvailable = scaleBreakHelper && brk; |
| 193 | |
| 194 | const ticks = [] as ScaleTick[]; |
| 195 | // If interval is 0, return []; |
| 196 | if (!interval) { |
| 197 | return ticks; |
| 198 | } |
| 199 | |
| 200 | if (opt.breakTicks === 'only_break' && brkAvailable) { |
| 201 | scaleBreakHelper.addBreaksToTicks(ticks, brk.breaks, extent); |
| 202 | return ticks; |
| 203 | } |
| 204 | |
| 205 | if (__DEV__) { |
| 206 | assert(niceExtent != null); |
| 207 | } |
| 208 | |
| 209 | // [CAVEAT]: If changing this logic, must sync it to `axisAlignTicks.ts`. |
| 210 | |
| 211 | // A fail-safe is required since `interval` can be user specified, or for the case |
| 212 | // that using dataZoom toolbox and zoom repeatedly. |
| 213 | const safeLimit = 3000; |
| 214 | |
| 215 | if (extent[0] < niceExtent[0]) { |
| 216 | ticks.push({ |
| 217 | value: opt.expandToNicedExtent |
| 218 | ? round(niceExtent[0] - interval, intervalPrecision) |
| 219 | : extent[0] |
| 220 | }); |
| 221 | } |
| 222 | |
| 223 | const estimateNiceMultiple = (tickVal: number, targetTick: number) => { |
| 224 | return mathRound((targetTick - tickVal) / interval); |
| 225 | }; |
| 226 | |
| 227 | const intervalCount = cfg.intervalCount; |
| 228 | for ( |
| 229 | let tick = niceExtent[0], niceTickIdx = 0; |
| 230 | ; |
| 231 | niceTickIdx++ |
| 232 | ) { |
| 233 | // Consider case `_extent: [5.2, 5.8], _niceExtent: [6, 5], interval: 1`, |
| 234 | // `_intervalCount` makes sense iff `-1`. |
| 235 | // Consider case `_extent: [5, 5.8], _niceExtent: [5, 5], interval: 1`, |
| 236 | // `_intervalCount` makes sense iff `0`. |
| 237 | if (intervalCount == null) { |
| 238 | if (tick > niceExtent[1] || !isFinite(tick) || !isFinite(niceExtent[1])) { |
| 239 | break; |
| 240 | } |