{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stats-section-v5",
  "title": "Stats Section v5",
  "description": "A response-time stats section written for non-technical readers. The title sits on the left and a plain-language description on the right. Below them, a histogram of response times, colored green, amber and red by speed with a matching strip along the axis, has dashed lines marking the typical response time and the time 99% of requests finish under. Hovering a bar shows what share of requests finished by then and highlights the matching line. Four stats sit under the chart in a fully bordered, square-cornered grid. Static data, no API.",
  "dependencies": [
    "recharts"
  ],
  "registryDependencies": [
    "chart"
  ],
  "files": [
    {
      "path": "registry/new-york/blocks/stats-section-v5/page.tsx",
      "content": "import StatsSectionV5 from \"./components/stats-section-v5\"\n\nexport default function Page() {\n  return <StatsSectionV5 />\n}\n",
      "type": "registry:page",
      "target": "app/stats-section-v5/page.tsx"
    },
    {
      "path": "registry/new-york/blocks/stats-section-v5/components/stats-section-v5.tsx",
      "content": "import { sectionHeader } from \"../lib/config\"\nimport LatencyPanel from \"./latency-panel\"\n\nexport default function StatsSectionV5() {\n  return (\n    <section className=\"py-16 md:py-24\">\n      <div className=\"mx-auto max-w-6xl px-6\">\n        <div className=\"grid gap-4 md:grid-cols-2 md:items-start md:gap-12\">\n          <h2 className=\"max-w-md text-3xl leading-[1.15] font-medium tracking-tight text-foreground md:text-4xl\">\n            {sectionHeader.title}\n          </h2>\n          <p className=\"max-w-md text-[0.9375rem] leading-relaxed text-muted-foreground md:justify-self-end\">\n            {sectionHeader.subtitle}\n          </p>\n        </div>\n\n        <LatencyPanel />\n      </div>\n    </section>\n  )\n}\n",
      "type": "registry:component",
      "target": "app/stats-section-v5/components/stats-section-v5.tsx"
    },
    {
      "path": "registry/new-york/blocks/stats-section-v5/components/latency-chart.tsx",
      "content": "\"use client\"\n\nimport { type PointerEvent, useState } from \"react\"\nimport { Bar, BarChart, Cell, ReferenceLine, XAxis, YAxis } from \"recharts\"\n\nimport { type ChartConfig, ChartContainer } from \"@/components/ui/chart\"\nimport { cn } from \"@/lib/utils\"\n\nimport {\n  type Band,\n  BAND_COLORS,\n  BUCKET_MS,\n  bucketOf,\n  latencyBuckets,\n  type Marker,\n  P50_MS,\n  P99_MS,\n} from \"../lib/config\"\n\nconst chartConfig = {\n  p50: { label: \"Fast\", color: BAND_COLORS.p50 },\n  p99: { label: \"Slower\", color: BAND_COLORS.p99 },\n  tail: { label: \"Slowest 1%\", color: BAND_COLORS.tail },\n} satisfies ChartConfig\n\nconst BAR_OPACITY = 0.8\n/** Bars outside the hovered bar's band fade to this opacity. */\nconst DIMMED = 0.2\n/** Opacity of a reference line while the other one has focus. */\nconst MUTED_LINE = 0.2\n\nconst AXIS_TICKS = [0, 100, 200]\n/** The hover handle starts on the median line, so the first hover slides out from it. */\nconst MEDIAN_INDEX = bucketOf(P50_MS) / BUCKET_MS\nconst peak = Math.max(...latencyBuckets.map((bucket) => bucket.requests))\n/** Room above the tallest bar for the reference line labels. */\nconst HEADROOM = 1.3\n/** Height recharts gives the x-axis, so the hover handle stops at the baseline. */\nconst AXIS_HEIGHT = 30\nconst BANDS: Band[] = [\"p50\", \"p99\", \"tail\"]\n/** Buckets per band, so each strip segment spans exactly its bars. */\nconst bandWidths = BANDS.map(\n  (band) => latencyBuckets.filter((bucket) => bucket.band === band).length\n)\n\nfunction AxisTick({\n  x,\n  y,\n  payload,\n}: {\n  x?: number\n  y?: number\n  payload?: { value: number }\n}) {\n  const value = payload?.value ?? 0\n\n  return (\n    <text\n      x={x}\n      y={y}\n      dy={14}\n      textAnchor={value === 0 ? \"start\" : \"middle\"}\n      className=\"fill-muted-foreground text-xs tabular-nums\"\n    >\n      {value} ms\n    </text>\n  )\n}\n\n/** Vertical step between the two reference line labels, so they never overlap. */\nconst LABEL_ROW = 18\n\nfunction MarkerLabel({\n  viewBox,\n  text,\n  muted,\n  side,\n  row,\n}: {\n  viewBox?: { x?: number; y?: number }\n  text: string\n  muted: boolean\n  /** Which side of its line the label sits on. */\n  side: \"right\" | \"left\"\n  row: number\n}) {\n  const x = viewBox?.x ?? 0\n  const y = viewBox?.y ?? 0\n\n  return (\n    <text\n      x={side === \"right\" ? x + 6 : x - 6}\n      y={y + 4 + row * LABEL_ROW}\n      textAnchor={side === \"right\" ? \"start\" : \"end\"}\n      dominantBaseline=\"hanging\"\n      className={cn(\n        \"fill-foreground text-xs font-medium tabular-nums transition-opacity duration-300\",\n        muted && \"opacity-20\"\n      )}\n    >\n      {text}\n    </text>\n  )\n}\n\nfunction formatShare(share: number) {\n  return share >= 99 ? share.toFixed(1) : Math.round(share).toString()\n}\n\nfunction barOpacity(index: number, band: Band, activeIndex: number | null) {\n  if (activeIndex === null) return BAR_OPACITY\n  if (index === activeIndex) return 1\n  const activeBand = latencyBuckets[activeIndex].band\n  return band === activeBand ? BAR_OPACITY : DIMMED\n}\n\nexport function LatencyChart({\n  activeIndex,\n  focus,\n  onActiveChange,\n  className,\n}: {\n  activeIndex: number | null\n  focus: Marker | null\n  onActiveChange: (index: number | null) => void\n  className?: string\n}) {\n  // Keep the last hovered bucket so the label holds its text while it fades out.\n  const [shownIndex, setShownIndex] = useState(MEDIAN_INDEX)\n  if (activeIndex !== null && activeIndex !== shownIndex) {\n    setShownIndex(activeIndex)\n  }\n  const shown = latencyBuckets[shownIndex]\n  const handleLeft = ((shownIndex + 0.5) / latencyBuckets.length) * 100\n  const flipLabel = handleLeft > 70\n\n  function handlePointerMove(event: PointerEvent<HTMLDivElement>) {\n    const rect = event.currentTarget.getBoundingClientRect()\n    const ratio = (event.clientX - rect.left) / rect.width\n    const index = Math.floor(ratio * latencyBuckets.length)\n    onActiveChange(Math.min(Math.max(index, 0), latencyBuckets.length - 1))\n  }\n\n  return (\n    <div\n      className={cn(\"relative h-full w-full touch-pan-y\", className)}\n      onPointerMove={handlePointerMove}\n      onPointerLeave={() => onActiveChange(null)}\n    >\n      <ChartContainer\n        config={chartConfig}\n        className=\"aspect-auto h-full w-full [&_.recharts-bar-rectangle_path]:transition-[fill-opacity] [&_.recharts-bar-rectangle_path]:duration-300 [&_.recharts-reference-line_line]:transition-[stroke-opacity] [&_.recharts-reference-line_line]:duration-300\"\n      >\n        <BarChart\n          data={latencyBuckets}\n          margin={{ left: 0, right: 0, top: 0, bottom: 0 }}\n          barCategoryGap={2}\n        >\n          <XAxis\n            dataKey=\"ms\"\n            ticks={AXIS_TICKS}\n            interval={0}\n            tickLine={false}\n            axisLine={{ stroke: \"var(--border)\" }}\n            height={AXIS_HEIGHT}\n            tick={<AxisTick />}\n          />\n          <YAxis hide domain={[0, peak * HEADROOM]} />\n          <Bar\n            dataKey=\"requests\"\n            radius={[2, 2, 0, 0]}\n            animationDuration={900}\n            animationEasing=\"ease-out\"\n          >\n            {latencyBuckets.map((bucket, index) => (\n              <Cell\n                key={bucket.ms}\n                fill={`var(--color-${bucket.band})`}\n                fillOpacity={barOpacity(index, bucket.band, activeIndex)}\n              />\n            ))}\n          </Bar>\n          <ReferenceLine\n            x={bucketOf(P50_MS)}\n            stroke=\"var(--foreground)\"\n            strokeDasharray=\"4 4\"\n            strokeOpacity={focus === \"p99\" ? MUTED_LINE : 1}\n            label={\n              <MarkerLabel\n                text={`Typical · ${P50_MS} ms`}\n                muted={focus === \"p99\"}\n                side=\"right\"\n                row={0}\n              />\n            }\n          />\n          <ReferenceLine\n            x={bucketOf(P99_MS)}\n            stroke=\"var(--foreground)\"\n            strokeDasharray=\"4 4\"\n            strokeOpacity={focus === \"p50\" ? MUTED_LINE : 1}\n            label={\n              <MarkerLabel\n                text={`99% under ${P99_MS} ms`}\n                muted={focus === \"p50\"}\n                side=\"left\"\n                row={1}\n              />\n            }\n          />\n        </BarChart>\n      </ChartContainer>\n\n      {/* Speed strip along the axis, so the thin red tail stays visible. */}\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-x-0 flex h-[3px]\"\n        style={{ bottom: AXIS_HEIGHT - 4 }}\n      >\n        {BANDS.map((band, index) => (\n          <span\n            key={band}\n            className={cn(\n              \"h-full transition-opacity duration-300\",\n              activeIndex !== null &&\n                latencyBuckets[activeIndex].band !== band &&\n                \"opacity-20\"\n            )}\n            style={{\n              flexGrow: bandWidths[index],\n              backgroundColor: BAND_COLORS[band],\n            }}\n          />\n        ))}\n      </div>\n\n      <div\n        className={cn(\n          \"pointer-events-none absolute top-0 border-l border-foreground transition-[left,opacity] duration-200 ease-out\",\n          activeIndex === null ? \"opacity-0\" : \"opacity-100\"\n        )}\n        style={{ left: `${handleLeft}%`, bottom: AXIS_HEIGHT }}\n      >\n        <div\n          className={cn(\n            \"absolute top-14 flex items-center gap-1.5 rounded-md border border-border bg-background px-2.5 py-1.5 text-xs font-medium whitespace-nowrap text-foreground tabular-nums shadow-sm\",\n            flipLabel ? \"right-2\" : \"left-2\"\n          )}\n        >\n          <span\n            aria-hidden\n            className=\"size-2 rounded-full transition-colors duration-200\"\n            style={{ backgroundColor: BAND_COLORS[shown.band] }}\n          />\n          {formatShare(shown.doneBy)}% under {shown.ms + BUCKET_MS} ms\n        </div>\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "app/stats-section-v5/components/latency-chart.tsx"
    },
    {
      "path": "registry/new-york/blocks/stats-section-v5/components/latency-panel.tsx",
      "content": "\"use client\"\n\nimport { useState } from \"react\"\n\nimport { BAND_COLORS, latencyBuckets, markerFor, stats } from \"../lib/config\"\nimport { LatencyChart } from \"./latency-chart\"\n\nexport default function LatencyPanel() {\n  const [activeIndex, setActiveIndex] = useState<number | null>(null)\n  const focus =\n    activeIndex === null ? null : markerFor(latencyBuckets[activeIndex].band)\n\n  return (\n    <>\n      <div\n        aria-hidden\n        className=\"mt-12 h-56 text-muted-foreground sm:h-64 md:mt-16 md:h-80\"\n      >\n        <LatencyChart\n          activeIndex={activeIndex}\n          focus={focus}\n          onActiveChange={setActiveIndex}\n        />\n      </div>\n\n      <dl className=\"mt-12 grid grid-cols-2 border-t border-l border-border md:grid-cols-4\">\n        {stats.map((stat) => (\n          <div\n            key={stat.id}\n            className=\"flex flex-col gap-2 border-r border-b border-border p-4 md:p-6\"\n          >\n            <dt className=\"flex items-start gap-2 text-sm text-muted-foreground\">\n              {stat.marker && (\n                <span\n                  aria-hidden\n                  className=\"mt-2.5 w-4 shrink-0 border-t-2 border-dashed\"\n                  style={{ borderColor: BAND_COLORS[stat.marker] }}\n                />\n              )}\n              {stat.label}\n            </dt>\n            <dd className=\"text-3xl font-semibold tracking-tight text-foreground tabular-nums md:text-4xl\">\n              {stat.value}\n            </dd>\n          </div>\n        ))}\n      </dl>\n    </>\n  )\n}\n",
      "type": "registry:component",
      "target": "app/stats-section-v5/components/latency-panel.tsx"
    },
    {
      "path": "registry/new-york/blocks/stats-section-v5/lib/config.ts",
      "content": "export const sectionHeader = {\n  title: \"Most requests finish faster than a blink.\",\n  subtitle:\n    \"We timed every request to Acme over the last 24 hours. 90% finished in under 100 ms, about one blink. Green bars finished faster than typical, amber bars took longer, and red bars are the slowest 1%.\",\n} as const\n\n/** Width of one histogram bucket, in milliseconds. */\nexport const BUCKET_MS = 5\nconst BUCKETS = 48\nconst TOTAL_REQUESTS = 2_100_000_000\n\n/** Log-normal latency: the median is e^MU, the spread is SIGMA. */\nconst MEDIAN_MS = 48\nconst MU = Math.log(MEDIAN_MS)\nconst SIGMA = 0.55\n/** z-score of the 99th percentile of a standard normal distribution. */\nconst Z_99 = 2.326\n\nexport const P50_MS = MEDIAN_MS\nexport const P99_MS = Math.round(Math.exp(MU + Z_99 * SIGMA))\n\nexport type Band = \"p50\" | \"p99\" | \"tail\"\n\n/**\n * Speed colors, green to red. Mid-tone oklch values so they read on both\n * light and dark backgrounds without a theme variable.\n */\nexport const BAND_COLORS: Record<Band, string> = {\n  p50: \"oklch(0.72 0.17 155)\",\n  p99: \"oklch(0.78 0.16 75)\",\n  tail: \"oklch(0.64 0.21 25)\",\n}\n\nexport type LatencyBucket = {\n  /** Start of the bucket, in milliseconds. */\n  ms: number\n  requests: number\n  band: Band\n  /** Share of all requests, 0 to 100, that finish by the end of the bucket. */\n  doneBy: number\n}\n\n/** Abramowitz and Stegun 7.1.26 approximation of the error function. */\nfunction erf(x: number) {\n  const t = 1 / (1 + 0.3275911 * Math.abs(x))\n  const poly =\n    t *\n    (0.254829592 +\n      t *\n        (-0.284496736 +\n          t * (1.421413741 + t * (-1.453152027 + t * 1.061405429))))\n  const value = 1 - poly * Math.exp(-x * x)\n  return x < 0 ? -value : value\n}\n\nfunction logNormalShareBy(ms: number) {\n  const z = (Math.log(ms) - MU) / SIGMA\n  return 0.5 * (1 + erf(z / Math.SQRT2))\n}\n\nfunction logNormalDensity(ms: number) {\n  const x = Math.max(ms, 0.5)\n  const z = (Math.log(x) - MU) / SIGMA\n  return Math.exp(-0.5 * z * z) / (x * SIGMA * Math.sqrt(2 * Math.PI))\n}\n\nfunction bandFor(ms: number): Band {\n  if (ms < P50_MS) return \"p50\"\n  if (ms < P99_MS) return \"p99\"\n  return \"tail\"\n}\n\n/** Requests per bucket, drawn from the same curve that sets P50_MS and P99_MS. */\nexport const latencyBuckets: LatencyBucket[] = Array.from(\n  { length: BUCKETS },\n  (_, index) => {\n    const ms = index * BUCKET_MS\n    const center = ms + BUCKET_MS / 2\n    return {\n      ms,\n      requests: Math.round(\n        TOTAL_REQUESTS * logNormalDensity(center) * BUCKET_MS\n      ),\n      band: bandFor(ms),\n      doneBy: logNormalShareBy(ms + BUCKET_MS) * 100,\n    }\n  }\n)\n\n/** Snaps a latency to the start of its bucket so it lines up with a bar. */\nexport function bucketOf(ms: number) {\n  return Math.floor(ms / BUCKET_MS) * BUCKET_MS\n}\n\nexport type Marker = \"p50\" | \"p99\"\n\n/** The reference line a bucket belongs to: the median, or the 99th percentile past it. */\nexport function markerFor(band: Band): Marker {\n  return band === \"p50\" ? \"p50\" : \"p99\"\n}\n\nexport type Stat = {\n  id: string\n  value: string\n  label: string\n  /** Stats with a marker match a dashed reference line on the chart. */\n  marker?: Marker\n}\n\nexport const stats: Stat[] = [\n  {\n    id: \"p50\",\n    value: `${P50_MS} ms`,\n    label: \"Typical response\",\n    marker: \"p50\",\n  },\n  {\n    id: \"p99\",\n    value: `${P99_MS} ms`,\n    label: \"99% under\",\n    marker: \"p99\",\n  },\n  { id: \"requests\", value: \"2.1B\", label: \"Requests a day\" },\n  { id: \"uptime\", value: \"99.99%\", label: \"Uptime\" },\n]\n",
      "type": "registry:lib",
      "target": "app/stats-section-v5/lib/config.ts"
    }
  ],
  "type": "registry:block"
}