/** Round axis ticks (0, 5, 10… / 0, 0.5, 1…) covering 0..max, about `count` of them. */ export function niceTicks(max: number, count = 4): number[] { if (!(max > 0)) return [0, 1] const raw = max / count const magnitude = 10 ** Math.floor(Math.log10(raw)) const step = [1, 2, 2.5, 5, 10].map((m) => m * magnitude).find((s) => s >= raw) ?? raw const ticks: number[] = [] for (let v = 0; v <= max + step * 0.999; v += step) ticks.push(Math.round(v * 1000) / 1000) return ticks } export const formatNumber = (value: number) => value.toLocaleString('en-US', { maximumFractionDigits: 2 })