{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sparkline",
  "type": "registry:component",
  "title": "Sparkline",
  "description": "A lightweight inline trend for cards and compact summaries, with a text alternative.",
  "categories": [
    "charts"
  ],
  "dependencies": [],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/sparkline.tsx",
      "type": "registry:component",
      "target": "components/overtrue/sparkline.tsx",
      "content": "\"use client\";\nimport { useId, type CSSProperties } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface SparklineProps {\n  data: number[];\n  label: string;\n  className?: string;\n  filled?: boolean;\n  /** Mark the most recent value. */\n  endpoint?: boolean;\n  /** Any CSS color. Defaults to the current text color, which is primary. */\n  color?: string;\n  /** Draw the line in and raise the area when the sparkline mounts. Skipped under reduced motion. */\n  animate?: boolean;\n}\n\nconst WIDTH = 240;\nconst HEIGHT = 48;\nconst PAD_X = 3;\nconst PAD_Y = 5;\nconst EASE = \"ease-[cubic-bezier(0.22,1,0.36,1)]\";\n\n/** Monotone cubic path: smooth, but never overshoots the data. */\nfunction monotonePath(points: [number, number][]) {\n  const n = points.length;\n  if (n < 2) return \"\";\n  const dx: number[] = [];\n  const slope: number[] = [];\n  for (let i = 0; i < n - 1; i++) {\n    dx.push(points[i + 1][0] - points[i][0]);\n    slope.push((points[i + 1][1] - points[i][1]) / dx[i]);\n  }\n  const tangent = [slope[0]];\n  for (let i = 1; i < n - 1; i++) {\n    tangent.push(\n      slope[i - 1] * slope[i] <= 0 ? 0 : (slope[i - 1] + slope[i]) / 2,\n    );\n  }\n  tangent.push(slope[n - 2]);\n  for (let i = 0; i < n - 1; i++) {\n    if (slope[i] === 0) {\n      tangent[i] = tangent[i + 1] = 0;\n      continue;\n    }\n    const a = tangent[i] / slope[i];\n    const b = tangent[i + 1] / slope[i];\n    const h = a * a + b * b;\n    if (h > 9) {\n      const t = 3 / Math.sqrt(h);\n      tangent[i] = t * a * slope[i];\n      tangent[i + 1] = t * b * slope[i];\n    }\n  }\n  const r = (value: number) => Math.round(value * 100) / 100;\n  let d = `M${r(points[0][0])},${r(points[0][1])}`;\n  for (let i = 0; i < n - 1; i++) {\n    const [x0, y0] = points[i];\n    const [x1, y1] = points[i + 1];\n    const h = dx[i] / 3;\n    d += `C${r(x0 + h)},${r(y0 + tangent[i] * h)} ${r(x1 - h)},${r(y1 - tangent[i + 1] * h)} ${r(x1)},${r(y1)}`;\n  }\n  return d;\n}\n\n/** A compact overview. Use a full chart when individual values need inspection. */\nexport function Sparkline({\n  data,\n  label,\n  className,\n  filled = true,\n  endpoint = true,\n  color,\n  animate = true,\n}: SparklineProps) {\n  const gradient = `sparkline-${useId().replace(/:/g, \"\")}`;\n  const values = data.filter(Number.isFinite);\n  let low = Infinity,\n    high = -Infinity;\n  for (const value of values) {\n    low = Math.min(low, value);\n    high = Math.max(high, value);\n  }\n  const points = values.map((value, i): [number, number] => [\n    values.length > 1\n      ? PAD_X + (i / (values.length - 1)) * (WIDTH - PAD_X * 2)\n      : WIDTH / 2,\n    high === low\n      ? HEIGHT / 2\n      : HEIGHT - PAD_Y - ((value - low) / (high - low)) * (HEIGHT - PAD_Y * 2),\n  ]);\n  const line = monotonePath(points);\n  const last = points[points.length - 1];\n  const lastValue = values[values.length - 1];\n  const motion = animate ? \"motion-reduce:transition-none\" : \"transition-none\";\n  return (\n    <div\n      data-slot=\"sparkline\"\n      role=\"img\"\n      aria-label={`${label}: ${values.length ? values.join(\", \") : \"No data\"}`}\n      className={cn(\"relative h-12 w-full text-primary\", className)}\n      style={color ? { color } : undefined}\n    >\n      {values.length > 1 && filled && (\n        <svg\n          viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n          preserveAspectRatio=\"none\"\n          aria-hidden=\"true\"\n          data-slot=\"sparkline-area\"\n          className={cn(\n            \"absolute inset-0 size-full origin-bottom overflow-visible transition-[opacity,scale] delay-75 duration-700\",\n            EASE,\n            animate && \"starting:scale-y-0 starting:opacity-0\",\n            motion,\n          )}\n        >\n          <defs>\n            <linearGradient id={gradient} x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\">\n              <stop offset=\"0%\" stopColor=\"currentColor\" stopOpacity=\"0.28\" />\n              <stop offset=\"100%\" stopColor=\"currentColor\" stopOpacity=\"0\" />\n            </linearGradient>\n          </defs>\n          <path\n            d={`${line}L${last[0]},${HEIGHT}L${points[0][0]},${HEIGHT}Z`}\n            fill={`url(#${gradient})`}\n            className={cn(\"transition-[d] duration-500\", EASE, motion)}\n          />\n        </svg>\n      )}\n      <svg\n        viewBox={`0 0 ${WIDTH} ${HEIGHT}`}\n        preserveAspectRatio=\"none\"\n        aria-hidden=\"true\"\n        data-slot=\"sparkline-line\"\n        className={cn(\n          // The line wipes in from the left; the inset leaves room for its glow.\n          \"absolute inset-0 size-full overflow-visible [clip-path:inset(-60%_-8%_-60%_-8%)] transition-[clip-path] duration-700\",\n          EASE,\n          animate &&\n            values.length > 1 &&\n            \"starting:[clip-path:inset(-60%_100%_-60%_-8%)]\",\n          motion,\n        )}\n      >\n        {values.length > 1 ? (\n          <path\n            d={line}\n            fill=\"none\"\n            stroke=\"currentColor\"\n            strokeWidth=\"2\"\n            strokeLinejoin=\"round\"\n            strokeLinecap=\"round\"\n            vectorEffect=\"non-scaling-stroke\"\n            className={cn(\n              \"transition-[d] duration-500 dark:[filter:drop-shadow(0_0_6px_color-mix(in_oklab,currentColor_50%,transparent))]\",\n              EASE,\n              motion,\n            )}\n          />\n        ) : values.length === 0 ? (\n          <path\n            d={`M${PAD_X} ${HEIGHT / 2}H${WIDTH - PAD_X}`}\n            stroke=\"currentColor\"\n            strokeDasharray=\"2 5\"\n            strokeLinecap=\"round\"\n            opacity=\"0.3\"\n            vectorEffect=\"non-scaling-stroke\"\n          />\n        ) : null}\n      </svg>\n      {/* Drawn in HTML so the marker stays round when the line stretches. */}\n      {endpoint && last && (\n        <span\n          aria-hidden=\"true\"\n          data-slot=\"sparkline-endpoint\"\n          className={cn(\n            // Moves with the line, and on mount appears once the line has drawn in.\n            \"absolute -translate-x-1/2 -translate-y-1/2 [transition:left_500ms_cubic-bezier(0.22,1,0.36,1),top_500ms_cubic-bezier(0.22,1,0.36,1),opacity_300ms_ease-out_550ms,scale_500ms_cubic-bezier(0.22,1,0.36,1)_550ms]\",\n            animate && \"starting:scale-0 starting:opacity-0\",\n            motion,\n          )}\n          style={\n            {\n              left: `${(last[0] / WIDTH) * 100}%`,\n              top: `${(last[1] / HEIGHT) * 100}%`,\n            } as CSSProperties\n          }\n        >\n          {/* Pulses once whenever the latest value changes. */}\n          <span\n            key={lastValue}\n            className={cn(\n              \"absolute inset-0 scale-[3.2] rounded-full bg-current opacity-0 transition-[opacity,scale] duration-1000 ease-out starting:scale-100 starting:opacity-40 motion-reduce:hidden\",\n              !animate && \"hidden\",\n            )}\n          />\n          <span className=\"relative block size-2 rounded-full border-[1.5px] border-card bg-current shadow-[0_0_0_3px_color-mix(in_oklab,currentColor_18%,transparent)] dark:shadow-[0_0_0_3px_color-mix(in_oklab,currentColor_24%,transparent),0_0_12px_1px_color-mix(in_oklab,currentColor_70%,transparent)]\" />\n        </span>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/sparkline. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
