({
count = 5,
domain = [0, 1]
}: LinearTickOptions = {})
| 2 | import type { LinearTickOptions, TimeTickOptions, TimeTickUnit } from "./types"; |
| 3 | |
| 4 | export const generateLinearTicks = ({ |
| 5 | count = 5, |
| 6 | domain = [0, 1] |
| 7 | }: LinearTickOptions = {}): number[] => { |
| 8 | const [start, stop] = domain; |
| 9 | const reverse = stop < start; |
| 10 | const min = reverse ? stop : start; |
| 11 | const max = reverse ? start : stop; |
| 12 | const step = tickStep(min, max, Math.max(1, count)); |
| 13 | |
| 14 | if (step === 0) { |
| 15 | return [start]; |
| 16 | } |
| 17 | |
| 18 | const first = Math.ceil(min / step) * step; |
| 19 | const ticks: number[] = []; |
| 20 | |
| 21 | const epsilon = step * 1e-10; |
| 22 | |
| 23 | for (let value = first; value <= max + epsilon; value += step) { |
| 24 | ticks.push(Number(value.toPrecision(12))); |
| 25 | } |
| 26 | |
| 27 | return reverse ? ticks.reverse() : ticks; |
| 28 | }; |
| 29 | |
| 30 | const timeUnitMs: Record<TimeTickUnit, number> = { |
| 31 | millisecond: 1, |
no test coverage detected