{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-band-latency",
  "title": "Band Chart",
  "description": "Live latency percentiles: a median line over p25–p75 and p5–p95 bands.",
  "dependencies": [
    "@wick-charts/react@^0.9.2"
  ],
  "registryDependencies": [
    "card",
    "https://wick-charts.eeff.io/r/wick-chart.json"
  ],
  "files": [
    {
      "path": "blocks/chart-band-latency.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useMemo, useState } from \"react\"\n\nimport {\n  BandSeries,\n  Crosshair,\n  LineSeries,\n  NumberFlow,\n  TimeAxis,\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 = 90\nconst TICK_MS = 1000\n\nconst formatMs = (value: number) => `${Math.round(value)} ms`\n\nconst medianOptions = { area: { visible: false } }\n\ninterface LatencyRow {\n  time: number\n  p5: number\n  p25: number\n  p50: number\n  p75: number\n  p95: number\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: replace with your own percentiles, one row a second.\nfunction nextRow(\n  previous: LatencyRow,\n  random: () => number = Math.random\n): LatencyRow {\n  const p50 = previous.p50 + (120 - previous.p50) * 0.08 + (random() - 0.5) * 14\n  const spread = 18 + random() * 10\n\n  return {\n    time: previous.time + TICK_MS,\n    p5: p50 - spread * 1.6,\n    p25: p50 - spread * 0.6,\n    p50,\n    p75: p50 + spread * 0.8,\n    p95: p50 + spread * 2.6 + random() * 30,\n  }\n}\n\nfunction seedRows(): LatencyRow[] {\n  const random = seededRandom(120)\n  let row: LatencyRow = {\n    time: Date.now() - POINTS * TICK_MS,\n    p5: 90,\n    p25: 110,\n    p50: 120,\n    p75: 135,\n    p95: 180,\n  }\n  const rows = [row]\n\n  while (rows.length < POINTS) {\n    row = nextRow(row, random)\n    rows.push(row)\n  }\n\n  return rows\n}\n\nexport function ChartBandLatency() {\n  const [rows, setRows] = useState(seedRows)\n\n  useEffect(() => {\n    const timer = setInterval(() => {\n      setRows((previous) => {\n        const last = previous[previous.length - 1]\n        if (!last) return previous\n\n        return [...previous.slice(1), nextRow(last)]\n      })\n    }, TICK_MS)\n\n    return () => clearInterval(timer)\n  }, [])\n\n  const bands = useMemo(\n    () => [\n      {\n        label: \"p5–p95\",\n        data: rows.map((row) => ({\n          time: row.time,\n          low: row.p5,\n          high: row.p95,\n        })),\n      },\n      {\n        label: \"p25–p75\",\n        data: rows.map((row) => ({\n          time: row.time,\n          low: row.p25,\n          high: row.p75,\n        })),\n      },\n    ],\n    [rows]\n  )\n  const median = useMemo(\n    () => rows.map((row) => ({ time: row.time, value: row.p50 })),\n    [rows]\n  )\n  const latest = rows[rows.length - 1]?.p50 ?? 0\n\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>API latency</CardTitle>\n        <CardDescription>Median with p25–p75 and p5–p95 bands</CardDescription>\n        <CardAction className=\"text-right\">\n          <NumberFlow\n            value={latest}\n            format={formatMs}\n            className=\"text-2xl font-semibold tabular-nums\"\n          />\n          <div className=\"text-xs text-muted-foreground\">p50</div>\n        </CardAction>\n      </CardHeader>\n      <CardContent>\n        <WickChart\n          className=\"aspect-auto h-[280px]\"\n          viewport={{ maxVisibleBars: POINTS }}\n        >\n          {/* Bands first, so the median draws over them. */}\n          <BandSeries data={bands} />\n          <LineSeries\n            data={{ label: \"p50\", data: median }}\n            options={medianOptions}\n          />\n          <YAxis format={formatMs} />\n          <TimeAxis />\n          <Crosshair />\n          <Tooltip format={formatMs} />\n        </WickChart>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "charts",
    "monitoring"
  ],
  "type": "registry:block"
}