{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-line-live",
  "title": "Live Line Chart",
  "description": "A line chart that streams a new point every second, with an animated live value in the card header.",
  "dependencies": [
    "@wick-charts/react@^0.9.2"
  ],
  "registryDependencies": [
    "card",
    "https://wick-charts.eeff.io/r/wick-chart.json"
  ],
  "files": [
    {
      "path": "blocks/chart-line-live.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useState } from \"react\"\n\nimport {\n  Crosshair,\n  LineSeries,\n  NumberFlow,\n  TimeAxis,\n  type TimePoint,\n  Tooltip,\n  YAxis,\n} 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 = 120\nconst TICK_MS = 1000\n\nconst formatRate = (value: number) => Math.round(value).toLocaleString(\"en-US\")\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: replace with your own stream and keep the array immutable.\nfunction nextPoint(\n  previous: TimePoint,\n  random: () => number = Math.random\n): TimePoint {\n  const drift = (1200 - previous.value) * 0.05\n  const value = Math.max(0, previous.value + drift + (random() - 0.5) * 120)\n\n  return { time: previous.time + TICK_MS, value }\n}\n\nfunction seedPoints(): TimePoint[] {\n  const random = seededRandom(1_200)\n  let point: TimePoint = { time: Date.now() - POINTS * TICK_MS, value: 1200 }\n  const points = [point]\n\n  while (points.length < POINTS) {\n    point = nextPoint(point, random)\n    points.push(point)\n  }\n\n  return points\n}\n\nexport function ChartLineLive() {\n  const [data, setData] = useState(seedPoints)\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)]\n      })\n    }, TICK_MS)\n\n    return () => clearInterval(timer)\n  }, [])\n\n  const latest = data[data.length - 1]?.value ?? 0\n\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Live traffic</CardTitle>\n        <CardDescription>Requests per second, last 2 minutes</CardDescription>\n        <CardAction className=\"text-right\">\n          <NumberFlow\n            value={latest}\n            format={formatRate}\n            className=\"text-2xl font-semibold tabular-nums\"\n          />\n          <div className=\"text-xs text-muted-foreground\">req/s</div>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <WickChart\n          className=\"aspect-auto h-[280px]\"\n          viewport={{ maxVisibleBars: POINTS }}\n        >\n          <LineSeries data={{ label: \"Requests\", data }} />\n          <YAxis format={formatRate} />\n          <TimeAxis />\n          <Crosshair />\n          <Tooltip format={formatRate} />\n        </WickChart>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "charts",
    "dashboard"
  ],
  "type": "registry:block"
}