import { useMemo } from "react"; import { useHive } from "../store"; import { fmtCost, fmtNum } from "../lib/format"; import { smooth } from "../lib/agents"; import { cumulativeSeries, seriesTotals } from "../lib/series"; // Downsample a numeric series to N points in [0..1] then map into the 56×24 // sparkline box (y inverted). Returns smoothed line + closed area paths. function sparkPaths(values: number[]): { line: string; area: string } | null { if (values.length < 2) return null; const N = 14; const step = (values.length - 1) / (N - 1); const sampled: number[] = []; for (let i = 0; i < N; i++) sampled.push(values[Math.round(i * step)]); const min = Math.min(...sampled), max = Math.max(...sampled); const span = max - min || 1; const pts: [number, number][] = sampled.map((v, i) => [ (i / (N - 1)) * 56, 24 - ((v - min) / span) * 18 - 3, ]); const line = smooth(pts); return { line, area: line + " L 56 24 L 0 24 Z" }; } function Sparkline({ paths, color }: { paths: { line: string; area: string } | null; color: string }) { if (!paths) return