Plot axes: whole-number ticks in full (20000, not 2.0e+4)
1 changed file+9−2
src/ui/plot.tsmodified+9−2View file
@@ -55,6 +55,13 @@ export function niceTicks(lo: number, hi: number, count = 5): number[] {
5555 return out;
5656 }
5757
58+// Axis tick labels: whole numbers below 10^7 in full (20000 rather than 2.0e+4), the rest as fmtNum.
59+// Ticks are multiples of the step, so round off what adding the step accumulated.
60+export const fmtTick = (v: number) => {
61+ const r = Math.round(v);
62+ return Math.abs(r) >= 1 && Math.abs(r) < 1e7 && Math.abs(v - r) < 1e-9 * Math.abs(v) ? String(r) : fmtNum(v);
63+};
64+
5865 export const fmtNum = (v: number) => {
5966 const a = Math.abs(v);
6067 if (a === 0) return '0';
@@ -70,8 +77,8 @@ export function drawAxes(
7077 yr: [number, number],
7178 o: Pick<PlotOptions, 'xLabel' | 'yLabel' | 'fmtX' | 'fmtY'> & { grid?: boolean },
7279 ) {
73- const fx = o.fmtX ?? fmtNum;
74- const fy = o.fmtY ?? fmtNum;
80+ const fx = o.fmtX ?? fmtTick;
81+ const fy = o.fmtY ?? fmtTick;
7582 const X = (v: number) => PAD.l + ((v - xr[0]) / (xr[1] - xr[0])) * (w - PAD.l - PAD.r);
7683 const Y = (v: number) => h - PAD.b - ((v - yr[0]) / (yr[1] - yr[0])) * (h - PAD.t - PAD.b);
7784 ctx.font = '11px system-ui, sans-serif';