{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "orbit-radial-chart",
  "title": "Orbit Radial Chart",
  "description": "Goals as concentric orbits: each ring closes as its target is met, a small satellite circles every track, and pointing at a ring brings its number to the centre.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/orbit-radial-chart/orbit-radial-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface OrbitRing {\n  label: string;\n  value: number;\n  /** The value that closes the ring. */\n  target: number;\n}\n\nexport interface OrbitView {\n  label: string;\n  rings: OrbitRing[];\n}\n\nexport interface OrbitRadialChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  /** Sets of rings to switch between. They should list the same rings in the same order. */\n  views?: OrbitView[];\n  /** Index of the view shown first. */\n  defaultView?: number;\n  /** Share of the target that counts as on track. */\n  onTrackAt?: number;\n  /** Colour of the rings. */\n  color?: string;\n  formatValue?: (value: number) => string;\n}\n\nconst PALETTES = {\n  dark: {\n    card: \"#08090A\",\n    surface: \"#0F1011\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    tip: \"#161718\",\n    tipShadow: \"0 4px 24px rgba(0,0,0,0.4)\",\n    chip: \"rgba(255,255,255,0.05)\",\n    chipOn: \"rgba(255,255,255,0.1)\",\n    accent: \"#5E6AD2\",\n    track: \"rgba(255,255,255,0.05)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    surface: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    tip: \"#FFFFFF\",\n    tipShadow: \"0 3px 12px rgba(8,9,10,0.09)\",\n    chip: \"rgba(8,9,10,0.04)\",\n    chipOn: \"#FFFFFF\",\n    accent: \"#5E6AD2\",\n    track: \"rgba(8,9,10,0.05)\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst CARD_FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\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 Stat({\n  value,\n  label,\n  pal,\n}: {\n  value: string;\n  label: string;\n  pal: Palette;\n}) {\n  return (\n    <div className=\"text-left sm:text-right\">\n      <p className=\"m-0 text-[18px] leading-[1.2] font-[510] tracking-[-0.018em] tabular-nums\">\n        {value}\n      </p>\n      <p\n        className=\"m-0 mt-0.5 text-[12px] tracking-[-0.011em]\"\n        style={{ color: pal.sub }}\n      >\n        {label}\n      </p>\n    </div>\n  );\n}\n\nfunction Pills({\n  label,\n  options,\n  value,\n  onChange,\n  pal,\n}: {\n  label: string;\n  options: string[];\n  value: number;\n  onChange: (index: number) => void;\n  pal: Palette;\n}) {\n  return (\n    <div\n      className=\"flex rounded-full p-0.5\"\n      style={{ background: pal.chip }}\n      role=\"radiogroup\"\n      aria-label={label}\n    >\n      {options.map((option, i) => (\n        <button\n          key={option}\n          type=\"button\"\n          role=\"radio\"\n          aria-checked={i === value}\n          onClick={() => onChange(i)}\n          className=\"h-7 cursor-pointer rounded-full px-3 text-[13px] font-[510] tracking-[-0.011em] transition-colors outline-none focus-visible:ring-2\"\n          style={{\n            background: i === value ? pal.chipOn : \"transparent\",\n            color: i === value ? pal.text : pal.sub,\n          }}\n        >\n          {option}\n        </button>\n      ))}\n    </div>\n  );\n}\n\nconst VIEWS: OrbitView[] = [\n  {\n    label: \"This quarter\",\n    rings: [\n      { label: \"Activation\", value: 86, target: 100 },\n      { label: \"Retention\", value: 71, target: 80 },\n      { label: \"Expansion\", value: 38, target: 60 },\n      { label: \"Referrals\", value: 214, target: 500 },\n      { label: \"Reviews\", value: 118, target: 150 },\n    ],\n  },\n  {\n    label: \"Last quarter\",\n    rings: [\n      { label: \"Activation\", value: 64, target: 100 },\n      { label: \"Retention\", value: 66, target: 80 },\n      { label: \"Expansion\", value: 47, target: 60 },\n      { label: \"Referrals\", value: 142, target: 500 },\n      { label: \"Reviews\", value: 61, target: 150 },\n    ],\n  },\n];\n\nconst FORMAT = (n: number) => Math.round(n).toLocaleString(\"en-US\");\n\nconst SIZE = 264;\nconst CENTRE = SIZE / 2;\nconst OUTER = 122;\nconst STEP = 19;\nconst THICK = 8;\n/** Every satellite's lap divides into eight seconds, so they all meet up again. */\nconst LAPS = [8000, 4000, 8000, 4000, 8000, 4000];\n\nconst share = (r: OrbitRing) => Math.min(1, r.value / Math.max(1, r.target));\n\nexport function OrbitRadialChart({\n  theme = \"dark\",\n  title = \"Quarter goals\",\n  subtitle = \"Each ring closes when its goal is met.\",\n  views = VIEWS,\n  defaultView = 0,\n  onTrackAt = 0.7,\n  color,\n  formatValue = FORMAT,\n  className,\n  style,\n  ...props\n}: OrbitRadialChartProps) {\n  const pal = PALETTES[theme];\n  const accent = color ?? pal.accent;\n  const reduce = useReducedMotion();\n  const boxRef = React.useRef<HTMLDivElement>(null);\n  const satelliteRefs = React.useRef<(SVGGElement | null)[]>([]);\n  const [view, setView] = React.useState(defaultView);\n  const [active, setActive] = React.useState<number | null>(null);\n  const [seen, setSeen] = React.useState(false);\n  const rings = (views[view] ?? views[0])?.rings ?? [];\n  const count = rings.length;\n\n  React.useEffect(() => {\n    const el = boxRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        setSeen(true);\n      },\n      { threshold: 0.2 },\n    );\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  // The satellites turn on their own animations, so nothing re-renders while they go round.\n  React.useEffect(() => {\n    if (reduce) return;\n    const runs = satelliteRefs.current.slice(0, count).map((el, i) =>\n      el?.animate(\n        [{ transform: \"rotate(0deg)\" }, { transform: \"rotate(360deg)\" }],\n        {\n          duration: LAPS[i % LAPS.length],\n          iterations: Infinity,\n          direction: i % 2 ? \"reverse\" : \"normal\",\n        },\n      ),\n    );\n    return () => runs.forEach((run) => run?.cancel());\n  }, [reduce, count]);\n\n  const overall = rings.reduce((n, r) => n + share(r), 0) / Math.max(1, count);\n  const onTrack = rings.filter((r) => share(r) >= onTrackAt).length;\n  const ring = active === null ? null : rings[active];\n\n  return (\n    <section\n      className={`w-full rounded-2xl p-5 sm:p-6 ${className ?? \"\"}`}\n      style={{\n        background: pal.card,\n        boxShadow: `inset 0 0 0 1px ${pal.border}`,\n        color: pal.text,\n        fontFamily: CARD_FONT,\n        ...style,\n      }}\n      {...props}\n    >\n      <div className=\"flex flex-wrap items-start justify-between gap-x-8 gap-y-3\">\n        <div>\n          <h3 className=\"m-0 text-[17px] leading-[1.33] font-[590] tracking-[-0.012em]\">\n            {title}\n          </h3>\n          <p\n            className=\"m-0 mt-0.5 text-[13px] tracking-[-0.011em]\"\n            style={{ color: pal.sub }}\n          >\n            {subtitle}\n          </p>\n        </div>\n        <div className=\"flex gap-7\">\n          <Stat\n            value={`${Math.round(overall * 100)}%`}\n            label=\"Overall\"\n            pal={pal}\n          />\n          <Stat value={String(onTrack)} label=\"On track\" pal={pal} />\n          <Stat value={String(count - onTrack)} label=\"Behind\" pal={pal} />\n        </div>\n      </div>\n\n      {!count ? (\n        <p className=\"py-16 text-center text-sm\" style={{ color: pal.sub }}>\n          No data available.\n        </p>\n      ) : (\n        <div\n          ref={boxRef}\n          className=\"mt-5 flex flex-col items-center gap-6 sm:flex-row sm:gap-10\"\n          onPointerLeave={() => setActive(null)}\n        >\n          <div\n            className=\"relative shrink-0\"\n            style={{ width: SIZE, height: SIZE }}\n          >\n            <svg\n              viewBox={`0 0 ${SIZE} ${SIZE}`}\n              width={SIZE}\n              height={SIZE}\n              role=\"img\"\n              aria-label={rings\n                .map((r) => `${r.label} ${Math.round(share(r) * 100)}%`)\n                .join(\", \")}\n            >\n              {rings.map((r, i) => {\n                const radius = OUTER - i * STEP;\n                const on = active === i;\n                const dim = active !== null && !on;\n                return (\n                  <g key={r.label}>\n                    <circle\n                      cx={CENTRE}\n                      cy={CENTRE}\n                      r={radius}\n                      fill=\"none\"\n                      stroke={pal.track}\n                      strokeWidth={THICK}\n                    />\n                    <circle\n                      cx={CENTRE}\n                      cy={CENTRE}\n                      r={radius}\n                      fill=\"none\"\n                      stroke={accent}\n                      strokeWidth={THICK}\n                      strokeLinecap=\"round\"\n                      pathLength={100}\n                      strokeDasharray={`${seen ? share(r) * 100 : 0} 100`}\n                      transform={`rotate(-90 ${CENTRE} ${CENTRE})`}\n                      className=\"motion-safe:transition-[stroke-dasharray,opacity] motion-safe:duration-700\"\n                      style={{\n                        opacity: dim ? 0.3 : 1 - i * 0.12,\n                        transitionTimingFunction:\n                          \"cubic-bezier(0.22, 1, 0.36, 1)\",\n                      }}\n                    />\n                    <g\n                      ref={(el) => {\n                        satelliteRefs.current[i] = el;\n                      }}\n                      style={{\n                        transformBox: \"view-box\",\n                        transformOrigin: \"50% 50%\",\n                      }}\n                    >\n                      <circle\n                        cx={CENTRE}\n                        cy={CENTRE - radius}\n                        r=\"2\"\n                        fill={pal.text}\n                        opacity={dim ? 0.3 : 0.9}\n                      />\n                    </g>\n                    {/* A wider invisible ring, so the thin one is easy to point at. */}\n                    <circle\n                      cx={CENTRE}\n                      cy={CENTRE}\n                      r={radius}\n                      fill=\"none\"\n                      stroke=\"transparent\"\n                      strokeWidth={STEP}\n                      pointerEvents=\"stroke\"\n                      onPointerEnter={() => setActive(i)}\n                    />\n                  </g>\n                );\n              })}\n            </svg>\n            <div\n              aria-hidden=\"true\"\n              className=\"pointer-events-none absolute inset-0 flex flex-col items-center justify-center text-center\"\n            >\n              <p className=\"m-0 text-[22px] leading-none font-[510] tracking-[-0.022em] tabular-nums\">\n                {Math.round((ring ? share(ring) : overall) * 100)}%\n              </p>\n              <p\n                className=\"m-0 mt-1 text-[11px] tracking-[-0.011em]\"\n                style={{ color: pal.sub }}\n              >\n                {ring?.label ?? \"Overall\"}\n              </p>\n            </div>\n          </div>\n\n          <ul className=\"m-0 flex w-full min-w-0 flex-1 list-none flex-col gap-0.5 p-0\">\n            {rings.map((r, i) => {\n              const on = active === i;\n              return (\n                <li key={r.label}>\n                  <button\n                    type=\"button\"\n                    onPointerEnter={() => setActive(i)}\n                    onFocus={() => setActive(i)}\n                    onBlur={() => setActive(null)}\n                    className=\"flex h-10 w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 text-left outline-none transition-colors focus-visible:ring-2\"\n                    style={{ background: on ? pal.chip : \"transparent\" }}\n                  >\n                    <span\n                      className=\"size-2 shrink-0 rounded-full\"\n                      style={{ background: accent, opacity: 1 - i * 0.12 }}\n                    />\n                    <span\n                      className=\"min-w-0 flex-1 truncate text-[13px] font-[510] tracking-[-0.011em]\"\n                      style={{ color: on ? pal.text : pal.soft }}\n                    >\n                      {r.label}\n                    </span>\n                    <span\n                      className=\"text-[12px] tabular-nums\"\n                      style={{ color: pal.sub }}\n                    >\n                      {formatValue(r.value)} of {formatValue(r.target)}\n                    </span>\n                    <span className=\"w-9 text-right text-[13px] font-[510] tabular-nums\">\n                      {Math.round(share(r) * 100)}%\n                    </span>\n                  </button>\n                </li>\n              );\n            })}\n          </ul>\n        </div>\n      )}\n\n      <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2\">\n        <Pills\n          label=\"View\"\n          options={views.map((v) => v.label)}\n          value={view}\n          onChange={setView}\n          pal={pal}\n        />\n        <span className=\"text-[12px]\" style={{ color: pal.sub }}>\n          On track at {Math.round(onTrackAt * 100)}% of target\n        </span>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}