diff --git a/src/shared/history.test.ts b/src/shared/history.test.ts index 9c71d09..4ee536a 100644 --- a/src/shared/history.test.ts +++ b/src/shared/history.test.ts @@ -177,6 +177,9 @@ test('the x grid: sections about as wide as the value lines are apart, each wide expect(chartColumns(150, 360, 33, 71)).toEqual([50, 99]); // a line pushed by rounding so its date would touch the last date is not drawn at all, never a line without a date expect(chartColumns(4, 300, 100)).toEqual([]); + // the same on the left: a first line rounded so close to the left edge that its date would touch the first day's date + // is not drawn (4 sections, the first line at 94 px, its date from 59 px; the first day's date ends at 70 + 12) + expect(chartColumns(6, 470, 117)).toEqual([3]); expect(chartColumns(2, 900, 150)).toEqual([]); expect(chartColumns(61, 60, 150)).toEqual([]); }); diff --git a/src/shared/history.ts b/src/shared/history.ts index 4986259..9745067 100644 --- a/src/shared/history.ts +++ b/src/shared/history.ts @@ -201,9 +201,10 @@ export function chartLevelsShown(values: number[], label: (v: number) => string) /** * The x grid of a chart: the points under its inner vertical lines, each date centred under its line (owner 2026-12-03: * "we should see line in a mid on top of label and label should represent it, left border we dont care, but right would - * be today latest date border"). The lines cut the plot into equal sections about as far apart as the value lines (owner - * 2026-12-01), never so close that two dates touch: a section is at least one and a half dates and `gap` wide, so the - * last line's date also clears the series' last date, which ends at the plot's right edge. Every line has its date: a + * be today latest date border"; then "we should have see beginning date on the left": the first day starts at the plot's + * left edge, the last day ends at its right edge). The lines cut the plot into equal sections about as far apart as the + * value lines (owner 2026-12-01), never so close that two dates touch: a section is at least one and a half dates and + * `gap` wide, so the first and the last line's dates also clear the edge dates. Every line has its date: a * line whose date would not fit is not drawn. None when the plot is too narrow. `count`: points in the series, * `labelWidth`: the width of one date */ @@ -211,7 +212,7 @@ export function chartColumns(count: number, plotWidth: number, rowGap: number, l if (count < 3 || plotWidth <= 0 || rowGap <= 0) return []; const n = Math.min(Math.max(1, Math.round(plotWidth / rowGap)), Math.floor(plotWidth / (1.5 * labelWidth + gap)), count - 1); const out: number[] = []; - let free = 0; // where the next date may start + let free = labelWidth + gap; // where the next date may start: after the first day's date at the left edge for (let k = 1; k < n; k++) { const i = Math.round((k / n) * (count - 1)); const at = (i / (count - 1)) * plotWidth; diff --git a/src/viewer/ui/LineChart.tsx b/src/viewer/ui/LineChart.tsx index 93d6942..777894d 100644 --- a/src/viewer/ui/LineChart.tsx +++ b/src/viewer/ui/LineChart.tsx @@ -3,7 +3,7 @@ import { chartColumns, chartLevelsShown, resample, valueRange, type Point } from import { shortUsd, siteDate, usd } from './format'; // A light SVG line chart in the Fidelity look: the line with a soft fill, five value levels on the right (three when the -// rounded labels would repeat), dates below, each centred under its grid line and the last day at the right edge, a crosshair with the date and value under the pointer. Sizes itself to its box (ResizeObserver) +// rounded labels would repeat), dates below, each centred under its grid line, the first day at the left edge and the last at the right, a crosshair with the date and value under the pointer. Sizes itself to its box (ResizeObserver) export function LineChart({ points, height = 220, up }: { points: Point[]; height?: number; up: boolean }) { const box = useRef(null); const [width, setWidth] = useState(600); @@ -99,7 +99,9 @@ export function LineChart({ points, height = 220, up }: { points: Point[]; heigh ))} - {/* the left edge has no date, the right edge the series' last day (owner 2026-12-03) */} + {/* the left edge has the series' first day, the right edge its last (owner 2026-12-03: "similarly like we have + Dec 3 for today, we should have see beginning date on the left") */} + {siteDate(points[0]!.date)} {siteDate(points[points.length - 1]!.date)} {hp && (