{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-histogram",
  "title": "Histogram",
  "description": "Live response times binned into a histogram, with p50 and p95 lines and the bin range, count and share on hover.",
  "dependencies": [
    "@wick-charts/react@^0.9.2"
  ],
  "registryDependencies": [
    "card",
    "https://wick-charts.eeff.io/r/wick-chart.json"
  ],
  "files": [
    {
      "path": "blocks/chart-histogram.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useState } from \"react\"\n\nimport { HistogramSeries, Tooltip, XAxis, YAxis } from \"@wick-charts/react\"\n\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\"\nimport { WickChart } from \"@/components/ui/wick-chart\"\n\nconst WINDOW = 2000\nconst BATCH = 40\nconst TICK_MS = 1000\n\n// Read once, when the chart mounts.\nconst axis = { x: { type: \"numeric\" as const } }\n\nconst histogramOptions = { binWidth: 20, quantiles: [0.5, 0.95] }\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 response times, in ms.\nfunction responseTimes(count: number, random: () => number = Math.random) {\n  return Array.from({ length: count }, () => {\n    const normal =\n      Math.sqrt(-2 * Math.log(Math.max(random(), 1e-9))) *\n      Math.cos(2 * Math.PI * random())\n\n    return Math.round(120 * Math.exp(0.45 * normal))\n  })\n}\n\nexport function ChartHistogram() {\n  const [samples, setSamples] = useState(() =>\n    responseTimes(WINDOW, seededRandom(42))\n  )\n\n  useEffect(() => {\n    const timer = setInterval(() => {\n      setSamples((previous) => [\n        ...previous.slice(BATCH),\n        ...responseTimes(BATCH),\n      ])\n    }, TICK_MS)\n\n    return () => clearInterval(timer)\n  }, [])\n\n  return (\n    <Card>\n      <CardHeader>\n        <CardTitle>Response times</CardTitle>\n        <CardDescription>Last 2,000 requests, ms</CardDescription>\n      </CardHeader>\n      <CardContent>\n        <WickChart axis={axis} className=\"aspect-auto h-[250px]\">\n          <HistogramSeries data={samples} options={histogramOptions} />\n          <Tooltip />\n          <YAxis />\n          <XAxis />\n        </WickChart>\n      </CardContent>\n    </Card>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "charts",
    "monitoring"
  ],
  "type": "registry:block"
}