import { useElementWidth } from "./chart-hover" /** Мини-тренд для плитки: линия 2px и точка на последнем значении. */ export function Sparkline({ values, height = 28, color = "var(--chart-1)", }: { values: readonly (number | null)[] height?: number color?: string }) { const [ref, width] = useElementWidth() const points = values.map((v, i) => ({ i, v })).filter((p): p is { i: number; v: number } => p.v !== null) const min = Math.min(...points.map((p) => p.v)) const max = Math.max(...points.map((p) => p.v)) const x = (i: number) => 4 + (i / Math.max(1, values.length - 1)) * (width - 8) const y = (v: number) => 4 + (max === min ? 0.5 : 1 - (v - min) / (max - min)) * (height - 8) const d = points.map((p, k) => `${k ? "L" : "M"}${x(p.i).toFixed(1)},${y(p.v).toFixed(1)}`).join("") const last = points.at(-1) return (
{width > 0 && points.length > 1 && ( {last && } )}
) }