{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-sparkline",
  "title": "Sparkline",
  "description": "A KPI card with a live value, a change badge and an edge-to-edge sparkline.",
  "dependencies": [
    "@wick-charts/react@^0.9.2"
  ],
  "registryDependencies": [
    "card",
    "https://wick-charts.eeff.io/r/wick-chart.json"
  ],
  "files": [
    {
      "path": "blocks/chart-sparkline.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useState } from \"react\"\n\nimport { LineSeries, NumberFlow, type TimePoint } from \"@wick-charts/react\"\n\nimport {\n  Card,\n  CardAction,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport { WickChart } from \"@/components/ui/wick-chart\"\n\nconst POINTS = 40\nconst TICK_MS = 1500\n\nexport interface SparklineMetric {\n  label: string\n  base: number\n  volatility: number\n  format: (value: number) => string\n  /** `true` when a falling value is the good direction, e.g. latency. */\n  lowerIsBetter?: boolean\n}\n\nconst revenue: SparklineMetric = {\n  label: \"Revenue\",\n  base: 48_200,\n  volatility: 0.01,\n  format: (value) =>\n    value.toLocaleString(\"en-US\", {\n      style: \"currency\",\n      currency: \"USD\",\n      maximumFractionDigits: 0,\n    }),\n}\n\n// Seeded, so the server render and the browser start from the same values.\nfunction seededRandom(seed: number): () => number {\n  let state = seed\n\n  return () => {\n    state = (state * 1_664_525 + 1_013_904_223) % 4_294_967_296\n\n    return state / 4_294_967_296\n  }\n}\n\n// Demo feed: a random walk pulled back toward the metric's base value.\nfunction nextPoint(\n  previous: TimePoint,\n  metric: SparklineMetric,\n  random: () => number = Math.random\n): TimePoint {\n  const drift = (metric.base - previous.value) * 0.08\n  const noise = (random() - 0.5) * 2 * metric.volatility * metric.base\n\n  return {\n    time: previous.time + TICK_MS,\n    value: previous.value + drift + noise,\n  }\n}\n\nfunction seedPoints(metric: SparklineMetric): TimePoint[] {\n  const random = seededRandom(metric.base)\n  let point: TimePoint = {\n    time: Date.now() - POINTS * TICK_MS,\n    value: metric.base,\n  }\n  const points = [point]\n\n  while (points.length < POINTS) {\n    point = nextPoint(point, metric, random)\n    points.push(point)\n  }\n\n  return points\n}\n\nexport function SparklineCard({ metric }: { metric: SparklineMetric }) {\n  const [data, setData] = useState(() => seedPoints(metric))\n\n  useEffect(() => {\n    const timer = setInterval(() => {\n      setData((points) => {\n        const last = points[points.length - 1]\n        if (!last) return points\n\n        return [...points.slice(1), nextPoint(last, metric)]\n      })\n    }, TICK_MS)\n\n    return () => clearInterval(timer)\n  }, [metric])\n\n  const first = data[0]?.value ?? 0\n  const latest = data[data.length - 1]?.value ?? 0\n  const change = first === 0 ? 0 : ((latest - first) / first) * 100\n  const isGood = metric.lowerIsBetter ? change <= 0 : change >= 0\n\n  return (\n    <Card className=\"gap-2 overflow-hidden pb-0\">\n      <CardHeader>\n        <CardDescription>{metric.label}</CardDescription>\n        <CardTitle>\n          <NumberFlow\n            value={latest}\n            format={metric.format}\n            className=\"text-2xl font-semibold tabular-nums\"\n          />\n        </CardTitle>\n        <CardAction\n          className={\n            isGood\n              ? \"text-xs text-emerald-600 dark:text-emerald-400\"\n              : \"text-xs text-red-600 dark:text-red-400\"\n          }\n        >\n          {change >= 0 ? \"+\" : \"\"}\n          {change.toFixed(1)}%\n        </CardAction>\n      </CardHeader>\n      <CardContent className=\"px-0\">\n        <WickChart\n          className=\"aspect-auto h-16\"\n          axis={{\n            y: { visible: false, width: 0 },\n            x: { visible: false, height: 0 },\n          }}\n          padding={{ top: 4, right: 0, bottom: 4, left: 0 }}\n          grid={{ visible: false }}\n          interactive={false}\n          viewport={{ maxVisibleBars: POINTS }}\n        >\n          <LineSeries\n            data={{ label: metric.label, data }}\n            options={{ pulse: false }}\n          />\n        </WickChart>\n      </CardContent>\n    </Card>\n  )\n}\n\nexport function ChartSparkline() {\n  return (\n    <div className=\"mx-auto w-full max-w-sm\">\n      <SparklineCard metric={revenue} />\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "charts",
    "dashboard"
  ],
  "type": "registry:block"
}