Sparkline A word-sized chart with no axes, no gridlines and no tooltip. Everything a normal chart adds is what makes a sparkline stop working, so the component has to actively refuse those things rather than merely omit them. Tokens this needs: --foreground, --card, --muted, --muted-foreground, --border, --chart-1, --direction-up The status, chart, scale, state and direction names are an extension, not a rename. shadcn has --destructive and five --chart-* and nothing else in this territory. ──────────────────────────────────────────────────────────────────────── // Sparkline.tsx ──────────────────────────────────────────────────────────────────────── /** * A sparkline is sized to sit in a line of text, so it gets no axes, no * gridlines, no legend and no tooltip. Those are the things that make a chart * readable at chart size and unreadable at word size. * * The one piece of emphasis is the final point, because the question a * sparkline answers is "what shape got us to the number beside it". */ export function Sparkline({ values, width = 72, height = 20, }: { values: number[]; width?: number; height?: number; }) { if (values.length < 2) return null; const min = Math.min(...values); const max = Math.max(...values); const span = max - min || 1; const x = (i: number) => (i / (values.length - 1)) * (width - 2) + 1; const y = (v: number) => height - 1 - ((v - min) / span) * (height - 2); const d = values.map((v, i) => `${i ? "L" : "M"}${x(i).toFixed(1)} ${y(v).toFixed(1)}`).join(" "); return ( ); } ──────────────────────────────────────────────────────────────────────── // demo.tsx ──────────────────────────────────────────────────────────────────────── import { Sparkline } from "./Sparkline"; /** Inline beside the number it belongs to, at text size, with the window named. */ export default function Demo() { return (
Checkout p95