diff --git a/generator/frontend/src/components/GrowthChart.tsx b/generator/frontend/src/components/GrowthChart.tsx index 4eb0d2e..ef7475f 100644 --- a/generator/frontend/src/components/GrowthChart.tsx +++ b/generator/frontend/src/components/GrowthChart.tsx @@ -59,20 +59,25 @@ function Line({ label, values, labels, mode, stroke }: { }) { const width = 600 const height = 70 + const vbH = height + 10 // viewBox height; bottom 10 holds the x-tick marks const max = Math.max(1, ...values) const n = values.length const stepX = n > 1 ? width / (n - 1) : 0 const total = values.reduce((a, b) => a + b, 0) const latest = values[n - 1] ?? 0 - const xy = values.map((v, i) => { - const x = n > 1 ? i * stepX : width / 2 - const y = height - (v / max) * (height - 4) - 2 - return { x, y } - }) + // Map a value to its y coordinate in viewBox space; reused for both the + // line points and the y-axis label positions so they stay aligned. + const yFor = (v: number) => height - (v / max) * (height - 4) - 2 + const xy = values.map((v, i) => ({ x: n > 1 ? i * stepX : width / 2, y: yFor(v) })) const pts = xy.map(p => `${p.x.toFixed(1)},${p.y.toFixed(1)}`).join(' ') // Sealed area polygon: only valid when we have a real line (n >= 2). const area = n > 1 ? `0,${height} ${pts} ${width},${height}` : '' const ticks = pickTicks(labels, Math.min(6, n)) + // y-axis labels: top (max), middle, baseline (0). Percent positions are + // relative to the same viewBox the chart is drawn in. + const yMarks = max > 1 + ? [max, Math.round(max / 2), 0] + : [max, 0] return (