{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tally-stats",
  "type": "registry:block",
  "title": "Tally Stats",
  "description": "Stats Section built with Tally (animated dot chart): requests fly between regions when one goes dark. A take on the chart (graph). A stats section for a GPU network: requests per hour as one dot cluster per region, each in its own color. Pick a scenario and the dots move: an outage sends a region's requests to its neighbours with retries showing as hollow rings, and a launch-day peak brings new traffic in from the edge. Three plain numbers sit underneath.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "blocks",
    "stats-sections",
    "stats",
    "chart"
  ],
  "docs": "Live preview and the components it's built with: https://keyframeui.com/blocks/stats-sections/tally-stats",
  "registryDependencies": [
    "https://keyframeui.com/r/tally.json"
  ],
  "files": [
    {
      "path": "components/tally-stats.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Tally, type TallyItem } from \"@/components/ui/tally\";\n\n/* ── Content ─────────────────────────────────────────────────\n * Everything you'd change to make the section yours: the\n * heading, the scenarios a visitor can switch between, the\n * regions in each, and the numbers under the chart. Each dot\n * is a share of the requests; switching scenarios moves the\n * dots that changed region, and new traffic flies in from the\n * edge. Hollow rings are requests that were retried.\n * ─────────────────────────────────────────────────────────── */\n\nconst EYEBROW = \"Network\";\nconst HEADING = \"When a region goes dark, the work moves.\";\nconst LEAD =\n  \"Every request runs on the nearest free GPU. When a region drops out, its requests move to the next nearest within seconds, and none of them are lost on the way.\";\n\n/** One color per region, bright on white and on night: `text-*` classes the chart reads. */\nconst REGION_COLORS: Record<string, string> = {\n  \"us-east\": \"text-[#ff5a1f] dark:text-[#ff7a45]\",\n  \"eu-central\": \"text-[#ff2d87] dark:text-[#ff5ca8]\",\n  \"ap-northeast\": \"text-[#7c3aed] dark:text-[#a78bfa]\",\n  \"sa-east\": \"text-[#00b25d] dark:text-[#34d399]\",\n};\n\nconst region = (id: string, value: number, hollow: number): TallyItem => ({\n  id,\n  label: id,\n  value,\n  hollow,\n  dotClassName: REGION_COLORS[id],\n});\n\n/** What a visitor can switch between. Requests per hour, in each region. */\nconst SCENARIOS = [\n  {\n    id: \"normal\",\n    label: \"Normal hour\",\n    note: \"A normal hour. Requests run where they're made.\",\n    items: [region(\"us-east\", 52000, 600), region(\"eu-central\", 38000, 400), region(\"ap-northeast\", 26000, 300), region(\"sa-east\", 12000, 200)],\n  },\n  {\n    id: \"outage\",\n    label: \"Outage\",\n    note: \"eu-central drops out. Its 38,000 requests move west and east; retries rise, nothing is lost.\",\n    items: [region(\"us-east\", 74000, 2600), region(\"eu-central\", 0, 0), region(\"ap-northeast\", 40000, 1400), region(\"sa-east\", 14000, 400)],\n  },\n  {\n    id: \"peak\",\n    label: \"Launch peak\",\n    note: \"A customer launches. Traffic grows by half, and idle GPUs in every region pick it up.\",\n    items: [region(\"us-east\", 76000, 900), region(\"eu-central\", 58000, 700), region(\"ap-northeast\", 39000, 500), region(\"sa-east\", 19000, 300)],\n  },\n];\n\nconst FACTS = [\n  { label: \"Failover\", value: \"4.2 s\", note: \"median, region to region\" },\n  { label: \"Requests lost\", value: \"0\", note: \"in the last 12 outages\" },\n  { label: \"Regions\", value: \"12\", note: \"on four continents\" },\n];\n\n/** Seconds the first scenario holds before the outage plays by itself, if nobody has picked one. */\nconst AUTOPLAY_HOLD = 1.6;\n\nconst thousands = (n: number) => (n >= 1000 ? `${Math.round(n / 1000)}k` : String(n));\n\n/* ── Section ─────────────────────────────────────────────── */\n\nexport function TallyStats() {\n  const [index, setIndex] = React.useState(0);\n  const touched = React.useRef(false);\n  const played = React.useRef(false);\n  const timer = React.useRef(0);\n  const scenario = SCENARIOS[index];\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  // After the first settle, play the outage once, unless the visitor has already picked.\n  const onSettle = React.useCallback(() => {\n    if (played.current || touched.current) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    played.current = true;\n    timer.current = window.setTimeout(() => {\n      if (!touched.current) setIndex(1);\n    }, AUTOPLAY_HOLD * 1000);\n  }, []);\n\n  const pick = (i: number) => {\n    touched.current = true;\n    window.clearTimeout(timer.current);\n    setIndex(i);\n  };\n\n  // A radio group: arrow keys move the choice and the focus together.\n  const radios = React.useRef<(HTMLButtonElement | null)[]>([]);\n  const onKeyDown = (event: React.KeyboardEvent) => {\n    const step = event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? 1 : event.key === \"ArrowLeft\" || event.key === \"ArrowUp\" ? -1 : 0;\n    if (!step) return;\n    event.preventDefault();\n    const next = (index + step + SCENARIOS.length) % SCENARIOS.length;\n    pick(next);\n    radios.current[next]?.focus();\n  };\n\n  return (\n    <section className=\"bg-white text-zinc-950 dark:bg-[#09090b] dark:text-white\">\n      <div className=\"mx-auto max-w-6xl px-6 py-20 sm:py-24\">\n        <div className=\"grid grid-cols-1 items-end gap-x-16 gap-y-8 lg:grid-cols-[minmax(0,1fr)_auto]\">\n          <div className=\"min-w-0\">\n            <p className=\"font-mono text-[11px] tracking-wide text-[#d93f06] uppercase dark:text-[#ff7a45]\">{EYEBROW}</p>\n            <h2 className=\"mt-4 max-w-2xl text-4xl leading-[1.05] font-semibold tracking-[-0.035em] text-balance sm:text-5xl\">{HEADING}</h2>\n            <p className=\"mt-5 max-w-xl text-base leading-relaxed text-zinc-600 dark:text-zinc-400\">{LEAD}</p>\n          </div>\n          <div role=\"radiogroup\" aria-label=\"Scenario\" onKeyDown={onKeyDown} className=\"flex flex-wrap gap-1 justify-self-start rounded-full border border-zinc-950/10 p-1 dark:border-white/10\">\n            {SCENARIOS.map((s, i) => (\n              <button\n                key={s.id}\n                ref={(el) => {\n                  radios.current[i] = el;\n                }}\n                type=\"button\"\n                role=\"radio\"\n                aria-checked={i === index}\n                tabIndex={i === index ? 0 : -1}\n                onClick={() => pick(i)}\n                className=\"rounded-full px-3.5 py-1.5 font-mono text-xs text-zinc-600 transition-colors duration-150 hover:text-zinc-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 aria-checked:bg-zinc-950 aria-checked:text-white dark:text-zinc-400 dark:hover:text-white dark:focus-visible:outline-white dark:aria-checked:bg-white dark:aria-checked:text-zinc-950\"\n              >\n                {s.label}\n              </button>\n            ))}\n          </div>\n        </div>\n\n        <div className=\"mt-10 border border-zinc-950/10 dark:border-white/10\">\n          <Tally\n            items={scenario.items}\n            unit=\"requests\"\n            hollowLabel=\"retried\"\n            format={thousands}\n            dotSize={8}\n            gap={2}\n            label=\"Requests per hour by region\"\n            onSettle={onSettle}\n            className=\"mx-4 mt-4 h-[26rem] sm:mx-6 sm:h-80 lg:h-[21rem]\"\n          />\n          <p aria-live=\"polite\" className=\"border-t border-zinc-950/10 px-4 py-3.5 font-mono text-xs leading-relaxed text-zinc-600 sm:px-6 dark:border-white/10 dark:text-zinc-400\">\n            {scenario.note}\n          </p>\n        </div>\n\n        <dl className=\"mt-10 grid grid-cols-1 gap-8 sm:grid-cols-3\">\n          {FACTS.map((f) => (\n            <div key={f.label} className=\"border-t border-zinc-950/10 pt-4 dark:border-white/10\">\n              <dt className=\"font-mono text-[11px] tracking-wide text-zinc-500 uppercase dark:text-zinc-400\">{f.label}</dt>\n              <dd className=\"mt-2 text-3xl font-semibold tracking-tight tabular-nums\">{f.value}</dd>\n              <dd className=\"mt-1 text-sm text-zinc-600 dark:text-zinc-400\">{f.note}</dd>\n            </div>\n          ))}\n        </dl>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}