"use client"; import { useId } from "react"; export interface SparklineProps { data: number[]; width?: number; height?: number; stroke?: string; className?: string; fill?: boolean; } export function Sparkline({ data, width = 120, height = 36, stroke = "var(--color-signal)", className, fill = true, }: SparklineProps) { const id = useId().replace(/:/g, ""); if (data.length < 2) return ( ); const min = Math.min(...data); const max = Math.max(...data); const span = max - min || 1; const stepX = width / (data.length - 1); const pts = data.map((v, i) => { const x = i * stepX; const y = height - ((v - min) / span) * (height - 4) - 2; return [x, y] as const; }); const line = pts .map( (p, i) => `${i === 0 ? "M" : "L"}${p[0].toFixed(1)},${p[1].toFixed(1)}`, ) .join(" "); const area = `${line} L${width},${height} L0,${height} Z`; return ( {fill && } ); }