// Zero-dependency SVG charts — bar and multi-series line. No charting library; // this app ships zero npm deps on the frontend by design (see CONTRIBUTING.md). const CHART_PALETTE = ['var(--primary)', 'var(--accent)', 'var(--success)', 'var(--gold)', 'var(--sky)']; function niceMax(n) { if (n <= 0) return 1; const magnitude = Math.pow(10, Math.floor(Math.log10(n))); const steps = [1, 2, 2.5, 5, 10]; for (const s of steps) { if (n <= s * magnitude) return s * magnitude; } return 10 * magnitude; } function LineChart({ series, labels, width = 640, height = 260, yMin = 0, yMax, yFormat, ariaLabel }) { const padding = { top: 16, right: 16, bottom: 32, left: 40 }; const plotW = width - padding.left - padding.right; const plotH = height - padding.top - padding.bottom; const allValues = series.flatMap(s => s.values).filter(v => v != null); const computedMax = yMax ?? niceMax(Math.max(...allValues, 1)); const fmt = yFormat || (v => v); const xFor = (i) => padding.left + (labels.length > 1 ? (i / (labels.length - 1)) * plotW : plotW / 2); const yFor = (v) => padding.top + plotH - ((v - yMin) / (computedMax - yMin)) * plotH; const gridLines = 4; const gridValues = Array.from({ length: gridLines + 1 }, (_, i) => yMin + (i / gridLines) * (computedMax - yMin)); return ( ); } function BarChart({ categories, values, width = 640, height = 260, color = 'var(--primary)', yFormat, ariaLabel }) { const padding = { top: 16, right: 16, bottom: 32, left: 40 }; const plotW = width - padding.left - padding.right; const plotH = height - padding.top - padding.bottom; const computedMax = niceMax(Math.max(...values, 1)); const fmt = yFormat || (v => v); const gap = 0.35; const slot = plotW / values.length; const barW = slot * (1 - gap); const gridLines = 4; const gridValues = Array.from({ length: gridLines + 1 }, (_, i) => (i / gridLines) * computedMax); return ( ); } function ChartLegend({ series }) { return (