{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radial-bar-chart",
  "title": "Radial Bar Chart",
  "description": "A radial bar chart laid out like a clock: rounded bars radiate from a centre ring for each hour, coloured from quiet to busy, with faint outlines for last week, a centre readout that follows the hovered hour and stat tiles for the peak and quietest times.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/radial-bar-chart/radial-bar-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport type ChartTheme = \"dark\" | \"light\";\n\nexport interface RadialBarChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"title\"\n> {\n  theme?: ChartTheme;\n  title?: string;\n  subtitle?: string;\n  /** One value per slice, clockwise from the top (24 for hours of the day). */\n  values?: number[];\n  /** Optional comparison values (same length), drawn as faint outlines behind the bars; null hides them. */\n  compare?: number[] | null;\n  /** Label for each slice; defaults to hours \"00\"–\"23\". */\n  labels?: string[];\n  /** Names for the two series, used in the legend and tooltip. */\n  seriesLabels?: [current: string, compare: string];\n  /** Bars blend from the first colour (quiet) to the second (busy). */\n  colors?: [string, string];\n  /** Diameter of the chart, in px (smaller when the card is narrow). */\n  size?: number;\n  formatValue?: (value: number) => string;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#0E0E0E\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F4F5F7\",\n    sub: \"rgba(255,255,255,0.55)\",\n    grid: \"rgba(255,255,255,0.08)\",\n    axis: \"rgba(255,255,255,0.45)\",\n    ghost: \"rgba(255,255,255,0.75)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    ends: [\"#3B5BDB\", \"#87FFE3\"] as [string, string],\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(0,0,0,0.07)\",\n    text: \"#111317\",\n    sub: \"rgba(17,19,23,0.55)\",\n    grid: \"rgba(17,19,23,0.08)\",\n    axis: \"rgba(17,19,23,0.5)\",\n    ghost: \"rgba(17,19,23,0.6)\",\n    chip: \"rgba(17,19,23,0.04)\",\n    ends: [\"#93B4F5\", \"#0E9F80\"] as [string, string],\n  },\n};\n\nconst DEFAULT_VALUES = [\n  210, 140, 96, 72, 64, 88, 190, 420, 760, 980, 1120, 1180, 1050, 1160, 1240,\n  1310, 1220, 1040, 860, 720, 640, 560, 430, 300,\n];\nconst DEFAULT_COMPARE = [\n  180, 120, 90, 70, 66, 80, 170, 380, 690, 900, 1010, 1080, 990, 1030, 1110,\n  1150, 1090, 930, 800, 690, 610, 520, 410, 260,\n];\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction useWidth(ref: React.RefObject<HTMLElement | null>) {\n  const [width, setWidth] = React.useState(0);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) =>\n      setWidth(entry.contentRect.width),\n    );\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, [ref]);\n  return width;\n}\n\n/** 0 → 1 (linear) once the element scrolls into view; 1 straight away with reduced motion. */\nfunction useReveal(\n  ref: React.RefObject<HTMLElement | null>,\n  reduce: boolean,\n  duration = 1400,\n) {\n  const [t, setT] = React.useState(0);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || reduce) return;\n    let raf = 0;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        const start = performance.now();\n        const tick = (now: number) => {\n          const k = Math.min(1, (now - start) / duration);\n          setT(k);\n          if (k < 1) raf = requestAnimationFrame(tick);\n        };\n        raf = requestAnimationFrame(tick);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [ref, reduce, duration]);\n  return reduce ? 1 : t;\n}\n\nfunction mix(a: string, b: string, t: number) {\n  const p = (h: string) => {\n    const s = h.replace(\"#\", \"\");\n    const f =\n      s.length === 3\n        ? s\n            .split(\"\")\n            .map((c) => c + c)\n            .join(\"\")\n        : s;\n    return [0, 2, 4].map((i) => parseInt(f.slice(i, i + 2), 16));\n  };\n  const [x, y] = [p(a), p(b)];\n  return `rgb(${x.map((v, i) => Math.round(v + (y[i] - v) * t)).join(\",\")})`;\n}\n\nconst easeOut = (t: number) => 1 - Math.pow(1 - Math.min(1, Math.max(0, t)), 3);\n\nexport function RadialBarChart({\n  theme = \"dark\",\n  title = \"Sessions by hour\",\n  subtitle = \"Average weekday, local time\",\n  values = DEFAULT_VALUES,\n  compare = DEFAULT_COMPARE,\n  labels,\n  seriesLabels = [\"This week\", \"Last week\"],\n  colors,\n  size = 380,\n  formatValue = (v) => Math.round(v).toLocaleString(\"en-US\"),\n  className,\n  style,\n  ...props\n}: RadialBarChartProps) {\n  const pal = PALETTES[theme];\n  const [c0, c1] = colors ?? pal.ends;\n  const reduce = useReducedMotion();\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const width = useWidth(boxRef);\n  const reveal = useReveal(boxRef, reduce);\n  const [active, setActive] = React.useState<number | null>(null);\n\n  const n = values.length;\n  const names = labels ?? values.map((_, i) => String(i).padStart(2, \"0\"));\n  const wide = width >= 620;\n  const D = width ? Math.min(size, wide ? width - 240 : width) : size;\n  const R = D / 2;\n  const outer = R - 22;\n  const inner = outer * 0.36;\n  const max = Math.max(1, ...values, ...(compare ?? []));\n  const step = (Math.PI * 2) / Math.max(1, n);\n  const angle = (i: number) => -Math.PI / 2 + step * i + step / 2;\n  const barW = Math.max(3, Math.min(14, inner * step * 0.62));\n  const rAt = (v: number) =>\n    inner + barW / 2 + ((outer - inner - barW) * v) / max;\n  const total = values.reduce((s, v) => s + v, 0);\n  const compareTotal = compare?.reduce((s, v) => s + v, 0) ?? 0;\n  const peak = values.indexOf(Math.max(...values));\n  const quiet = values.indexOf(Math.min(...values));\n  const ringFracs = [0.25, 0.5, 0.75, 1];\n\n  const pick = (clientX: number, clientY: number) => {\n    const el = boxRef.current?.querySelector(\"svg\");\n    const r = el?.getBoundingClientRect();\n    if (!r) return;\n    const x = clientX - r.left - R;\n    const y = clientY - r.top - R;\n    const dist = Math.hypot(x, y);\n    if (dist < inner * 0.6 || dist > R) return setActive(null);\n    let a = Math.atan2(y, x) + Math.PI / 2;\n    if (a < 0) a += Math.PI * 2;\n    setActive(Math.floor(a / step) % n);\n  };\n  const onKey = (event: React.KeyboardEvent) => {\n    if (!n) return;\n    if (\n      [\"ArrowRight\", \"ArrowDown\", \"ArrowLeft\", \"ArrowUp\"].includes(event.key)\n    ) {\n      event.preventDefault();\n      const dir =\n        event.key === \"ArrowRight\" || event.key === \"ArrowDown\" ? 1 : -1;\n      setActive((a) =>\n        a === null ? (dir > 0 ? 0 : n - 1) : (a + dir + n) % n,\n      );\n    } else if (event.key === \"Escape\") setActive(null);\n  };\n\n  const shownLabel =\n    active !== null\n      ? labels\n        ? names[active]\n        : `${names[active]}:00 – ${names[(active + 1) % n]}:00`\n      : \"Daily total\";\n  const shownValue = active !== null ? values[active] : total;\n  const delta =\n    active !== null && compare\n      ? values[active] - compare[active]\n      : total - compareTotal;\n  const deltaBase = active !== null && compare ? compare[active] : compareTotal;\n  const summary = `${title}. ${values.map((v, i) => `${names[i]}: ${formatValue(v)}`).join(\", \")}. Peak at ${names[peak]}, quietest at ${names[quiet]}.`;\n  const good = theme === \"dark\" ? \"#87FFE3\" : \"#0E9F80\";\n  const bad = theme === \"dark\" ? \"#FF7A6B\" : \"#E5484D\";\n\n  return (\n    <div\n      className={cn(\n        \"w-full overflow-hidden rounded-[20px] p-5 sm:p-7\",\n        className,\n      )}\n      style={{\n        background: pal.card,\n        border: `1px solid ${pal.border}`,\n        color: pal.text,\n        fontFamily: \"Inter, -apple-system, BlinkMacSystemFont, sans-serif\",\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-4\">\n        <div className=\"min-w-0\">\n          <p className=\"text-[15px] font-semibold tracking-[-0.01em]\">\n            {title}\n          </p>\n          {subtitle && (\n            <p className=\"mt-1 text-[12.5px]\" style={{ color: pal.sub }}>\n              {subtitle}\n            </p>\n          )}\n        </div>\n        <div className=\"flex flex-wrap gap-x-4 gap-y-1.5 text-[12px] font-medium\">\n          <span className=\"flex items-center gap-1.5\">\n            <span\n              className=\"h-2.5 w-4 rounded-full\"\n              style={{ background: `linear-gradient(90deg, ${c0}, ${c1})` }}\n            />\n            {seriesLabels[0]}\n          </span>\n          {compare && (\n            <span\n              className=\"flex items-center gap-1.5\"\n              style={{ color: pal.sub }}\n            >\n              <span\n                className=\"h-0.5 w-3 rounded-full\"\n                style={{ background: pal.ghost }}\n              />\n              {seriesLabels[1]}\n            </span>\n          )}\n        </div>\n      </div>\n\n      <div\n        ref={boxRef}\n        className={cn(\n          \"mt-5 flex items-center gap-8\",\n          wide ? \"flex-row justify-center\" : \"flex-col\",\n        )}\n      >\n        {width > 0 && (\n          <div\n            role=\"img\"\n            aria-label={summary}\n            tabIndex={0}\n            onKeyDown={onKey}\n            onBlur={() => setActive(null)}\n            onPointerMove={(e) => pick(e.clientX, e.clientY)}\n            onPointerDown={(e) => pick(e.clientX, e.clientY)}\n            onPointerLeave={(e) => e.pointerType === \"mouse\" && setActive(null)}\n            className=\"relative shrink-0 rounded-full outline-none focus-visible:ring-2\"\n            style={{ width: D, height: D }}\n          >\n            <svg width={D} height={D} aria-hidden=\"true\" className=\"block\">\n              <g transform={`translate(${R} ${R})`}>\n                {ringFracs.map((f) => (\n                  <circle\n                    key={f}\n                    r={inner + barW / 2 + (outer - inner - barW) * f}\n                    fill=\"none\"\n                    stroke={pal.grid}\n                    strokeDasharray={f === 1 ? undefined : \"2 4\"}\n                  />\n                ))}\n                {values.map((v, i) => {\n                  const a = angle(i);\n                  const cos = Math.cos(a);\n                  const sin = Math.sin(a);\n                  const t = easeOut(reveal * 1.6 - (i / n) * 0.6);\n                  const r0 = inner + barW / 2;\n                  const r1 = r0 + (rAt(v) - r0) * t;\n                  const on = active === null || active === i;\n                  const cmp = compare?.[i];\n                  return (\n                    <g\n                      key={i}\n                      opacity={on ? 1 : 0.35}\n                      style={{ transition: \"opacity 160ms\" }}\n                    >\n                      <line\n                        x1={r0 * cos}\n                        y1={r0 * sin}\n                        x2={r1 * cos}\n                        y2={r1 * sin}\n                        stroke={mix(c0, c1, v / max)}\n                        strokeWidth={barW}\n                        strokeLinecap=\"round\"\n                      />\n                      {cmp !== undefined && (\n                        // Last week's value: a short tick across the bar.\n                        <line\n                          x1={rAt(cmp) * cos - sin * (barW / 2 + 3)}\n                          y1={rAt(cmp) * sin + cos * (barW / 2 + 3)}\n                          x2={rAt(cmp) * cos + sin * (barW / 2 + 3)}\n                          y2={rAt(cmp) * sin - cos * (barW / 2 + 3)}\n                          stroke={pal.ghost}\n                          strokeWidth={2}\n                          strokeLinecap=\"round\"\n                          opacity={t}\n                        />\n                      )}\n                    </g>\n                  );\n                })}\n                {names.map((name, i) => {\n                  const a = angle(i);\n                  const major = n === 24 ? i % 6 === 0 : true;\n                  const show = n === 24 ? i % 3 === 0 : n <= 16 || i % 2 === 0;\n                  if (!show) return null;\n                  return (\n                    <text\n                      key={name + i}\n                      x={(outer + 13) * Math.cos(a)}\n                      y={(outer + 13) * Math.sin(a) + 3.5}\n                      textAnchor=\"middle\"\n                      fontSize={major ? 11 : 10}\n                      fontWeight={major ? 600 : 400}\n                      fill={active === i ? pal.text : pal.axis}\n                    >\n                      {name}\n                    </text>\n                  );\n                })}\n              </g>\n            </svg>\n            <div className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center\">\n              <p className=\"text-[11px]\" style={{ color: pal.sub }}>\n                {shownLabel}\n              </p>\n              <p\n                className=\"mt-0.5 font-semibold tracking-[-0.03em] tabular-nums\"\n                style={{ fontSize: Math.max(18, inner * 0.38) }}\n              >\n                {formatValue(shownValue)}\n              </p>\n              {compare && deltaBase > 0 && (\n                <p\n                  className=\"mt-0.5 text-[11px] font-medium tabular-nums\"\n                  style={{ color: delta >= 0 ? good : bad }}\n                >\n                  {delta >= 0 ? \"▲\" : \"▼\"}{\" \"}\n                  {Math.abs((delta / deltaBase) * 100).toFixed(1)}%\n                </p>\n              )}\n            </div>\n          </div>\n        )}\n        <dl\n          className={cn(\n            \"grid w-full gap-3 text-[12.5px]\",\n            wide ? \"max-w-[240px] grid-cols-1\" : \"grid-cols-2\",\n          )}\n        >\n          {(\n            [\n              [\n                \"Peak hour\",\n                labels ? names[peak] : `${names[peak]}:00`,\n                formatValue(values[peak]),\n              ],\n              [\n                \"Quietest\",\n                labels ? names[quiet] : `${names[quiet]}:00`,\n                formatValue(values[quiet]),\n              ],\n              [\n                \"Busiest 4 hours\",\n                `${((values.map((_, i) => [0, 1, 2, 3].reduce((s, k) => s + values[(i + k) % n], 0)).reduce((m, v) => Math.max(m, v), 0) / Math.max(1, total)) * 100).toFixed(0)}%`,\n                \"of the day\",\n              ],\n              ...(compare\n                ? [\n                    [\n                      \"vs \" + seriesLabels[1].toLowerCase(),\n                      `${total >= compareTotal ? \"+\" : \"−\"}${Math.abs(compareTotal ? ((total - compareTotal) / compareTotal) * 100 : 0).toFixed(1)}%`,\n                      `${formatValue(compareTotal)} before`,\n                    ],\n                  ]\n                : []),\n            ] as [string, string, string][]\n          ).map(([k, v, note]) => (\n            <div\n              key={k}\n              className=\"rounded-xl px-3.5 py-3\"\n              style={{ background: pal.chip }}\n            >\n              <dt style={{ color: pal.sub }}>{k}</dt>\n              <dd className=\"mt-1 flex items-baseline justify-between gap-2\">\n                <span className=\"text-[18px] font-semibold tracking-[-0.02em] tabular-nums\">\n                  {v}\n                </span>\n                <span\n                  className=\"text-[11.5px] tabular-nums\"\n                  style={{ color: pal.sub }}\n                >\n                  {note}\n                </span>\n              </dd>\n            </div>\n          ))}\n        </dl>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}