import { useId } from "react"; import { cn } from "@/lib/utils"; import { sparklineGeometry, SPARKLINE_VIEW_W } from "./geometry"; export interface SparklineProps { /** Series of values, oldest first. */ data: Array; /** * Fixed value domain [min, max]. When omitted the domain is derived from the * data. Providing a stable domain (e.g. [0, 100] for percentages) avoids the * jittery rescaling the old sparkline had. */ domain?: [number, number]; className?: string; /** Tailwind text-color class for the line/fill (uses currentColor). */ colorClassName?: string; /** Show a dot on the last point. */ showLastDot?: boolean; /** Internal coordinate height; the SVG scales to its container. */ height?: number; } /** * Compact area + line chart. Uses a non-scaling stroke + a stable value domain * so the line stays crisp and readable regardless of container size. */ export function Sparkline({ data, domain, className, colorClassName = "text-accent-brand", showLastDot = true, height = 56, }: SparklineProps) { const gradientId = useId(); const { hasData, coords, linePath, areaPath } = sparklineGeometry( data, height, domain, ); const last = coords[coords.length - 1]; return (
{hasData && ( )}
); }