{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "petal-radar-chart",
  "title": "Petal Radar Chart",
  "description": "A radar chart that blooms: each score is a petal, a dashed outline shows the benchmark, and petals ease to their new size as you switch between teams.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/petal-radar-chart/petal-radar-chart.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PetalView {\n  label: string;\n  /** One score per axis, from 0 to 100. */\n  values: number[];\n}\n\nexport interface PetalRadarChartProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  /** One name per petal, clockwise from the top. */\n  axes?: string[];\n  views?: PetalView[];\n  /** Scores drawn as an outline behind every view. Pass null to hide it. */\n  benchmark?: number[] | null;\n  /** Name of the outline in the legend. */\n  benchmarkLabel?: string;\n  /** Index of the view shown first. */\n  defaultView?: number;\n  /** Colour of the petals. */\n  color?: 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  },\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  },\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 AXES = [\n  \"Focus\",\n  \"Delivery\",\n  \"Quality\",\n  \"Morale\",\n  \"Autonomy\",\n  \"Learning\",\n  \"Teamwork\",\n  \"Clarity\",\n];\n\nconst VIEWS: PetalView[] = [\n  { label: \"Engineering\", values: [78, 84, 91, 66, 72, 58, 74, 62] },\n  { label: \"Design\", values: [64, 70, 88, 82, 76, 80, 86, 74] },\n  { label: \"Product\", values: [58, 76, 68, 72, 84, 66, 80, 90] },\n];\n\nconst BENCHMARK = [70, 74, 78, 72, 70, 68, 76, 72];\n\nconst SIZE = 328;\nconst CENTRE = SIZE / 2;\nconst REACH = 98;\n\n/** A petal pointing straight up, from the centre to its tip. */\nfunction petal(length: number) {\n  const w = length * 0.3;\n  return `M0 0C${-w} ${-length * 0.32} ${-w} ${-length * 0.84} 0 ${-length}C${w} ${-length * 0.84} ${w} ${-length * 0.32} 0 0Z`;\n}\n\nexport function PetalRadarChart({\n  theme = \"dark\",\n  title = \"Team health\",\n  subtitle = \"Each petal is a score out of 100, against the company average.\",\n  axes = AXES,\n  views = VIEWS,\n  benchmark = BENCHMARK,\n  benchmarkLabel = \"Company average\",\n  defaultView = 0,\n  color,\n  className,\n  style,\n  ...props\n}: PetalRadarChartProps) {\n  const pal = PALETTES[theme];\n  const accent = color ?? pal.accent;\n  const reduce = useReducedMotion();\n  const boxRef = React.useRef<HTMLDivElement>(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 count = axes.length;\n  const values = React.useMemo(\n    () => (views[view] ?? views[0])?.values ?? [],\n    [views, view],\n  );\n  const [shown, setShown] = React.useState<number[]>(() =>\n    new Array<number>(count).fill(0),\n  );\n  const liveRef = React.useRef<number[]>(new Array<number>(count).fill(0));\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  // Petals open one after another the first time, and all ease together after that.\n  React.useEffect(() => {\n    if (!seen) return;\n    const from = liveRef.current;\n    const opening = from.every((v) => v === 0);\n    let raf = 0;\n    let start = 0;\n    const frame = (now: number) => {\n      start = start || now;\n      const elapsed = now - start;\n      let busy = false;\n      const next = values.map((v, i) => {\n        const delay = opening ? i * 70 : 0;\n        const k = reduce\n          ? 1\n          : Math.max(0, Math.min(1, (elapsed - delay) / 750));\n        if (k < 1) busy = true;\n        const e = 1 - Math.pow(1 - k, 3);\n        return (from[i] ?? 0) + (v - (from[i] ?? 0)) * e;\n      });\n      liveRef.current = next;\n      setShown(next);\n      if (busy) raf = requestAnimationFrame(frame);\n    };\n    raf = requestAnimationFrame(frame);\n    return () => cancelAnimationFrame(raf);\n  }, [seen, values, reduce]);\n\n  const angle = (i: number) => (i / Math.max(1, count)) * 360;\n  const average =\n    values.reduce((n, v) => n + v, 0) / Math.max(1, values.length);\n  const high = values.indexOf(Math.max(...values));\n  const low = values.indexOf(Math.min(...values));\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 value={String(Math.round(average))} label=\"Score\" pal={pal} />\n          <Stat value={axes[high] ?? \"—\"} label=\"Strongest\" pal={pal} />\n          <Stat value={axes[low] ?? \"—\"} label=\"Weakest\" pal={pal} />\n        </div>\n      </div>\n\n      <div\n        ref={boxRef}\n        className=\"mt-3 flex flex-col items-center gap-4 sm:flex-row sm:gap-8\"\n        onPointerLeave={() => setActive(null)}\n      >\n        <svg\n          viewBox={`0 0 ${SIZE} ${SIZE}`}\n          width={SIZE}\n          height={SIZE}\n          className=\"h-auto max-w-full shrink-0\"\n          role=\"img\"\n          aria-label={axes.map((a, i) => `${a} ${values[i] ?? 0}`).join(\", \")}\n        >\n          {[0.25, 0.5, 0.75, 1].map((t) => (\n            <circle\n              key={t}\n              cx={CENTRE}\n              cy={CENTRE}\n              r={REACH * t}\n              fill=\"none\"\n              stroke={pal.grid}\n            />\n          ))}\n          {axes.map((a, i) => {\n            const on = active === i;\n            const length = (REACH * (shown[i] ?? 0)) / 100;\n            const turn = `translate(${CENTRE} ${CENTRE}) rotate(${angle(i)})`;\n            const rad = ((angle(i) - 90) * Math.PI) / 180;\n            const lx = Math.round(CENTRE + Math.cos(rad) * (REACH + 15));\n            const ly = Math.round(CENTRE + Math.sin(rad) * (REACH + 15));\n            const cos = Math.cos(rad);\n            return (\n              <g key={a} onPointerEnter={() => setActive(i)}>\n                <path\n                  d={petal(length)}\n                  transform={turn}\n                  fill={accent}\n                  fillOpacity={active !== null && !on ? 0.28 : 0.82}\n                  stroke={accent}\n                  strokeWidth=\"1\"\n                  className=\"motion-safe:transition-[fill-opacity] motion-safe:duration-150\"\n                />\n                {benchmark && (\n                  <path\n                    d={petal((REACH * (benchmark[i] ?? 0)) / 100)}\n                    transform={turn}\n                    fill=\"none\"\n                    stroke={pal.text}\n                    strokeOpacity={active !== null && !on ? 0.15 : 0.45}\n                    strokeWidth=\"1\"\n                    strokeDasharray=\"3 3\"\n                    pointerEvents=\"none\"\n                  />\n                )}\n                <text\n                  x={lx}\n                  y={ly + 4}\n                  textAnchor={\n                    Math.abs(cos) < 0.2 ? \"middle\" : cos > 0 ? \"start\" : \"end\"\n                  }\n                  fontSize=\"11\"\n                  fill={on ? pal.text : pal.sub}\n                >\n                  {a}\n                </text>\n              </g>\n            );\n          })}\n        </svg>\n\n        <ul className=\"m-0 grid w-full min-w-0 flex-1 list-none grid-cols-1 gap-0 p-0\">\n          {axes.map((a, i) => {\n            const value = values[i] ?? 0;\n            const delta = benchmark ? value - (benchmark[i] ?? 0) : null;\n            return (\n              <li key={a}>\n                <button\n                  type=\"button\"\n                  onPointerEnter={() => setActive(i)}\n                  onFocus={() => setActive(i)}\n                  onBlur={() => setActive(null)}\n                  className=\"flex h-8 w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 text-left transition-colors outline-none focus-visible:ring-2\"\n                  style={{\n                    background: active === i ? pal.chip : \"transparent\",\n                  }}\n                >\n                  <span\n                    className=\"min-w-0 flex-1 truncate text-[13px] font-[510] tracking-[-0.011em]\"\n                    style={{ color: active === i ? pal.text : pal.soft }}\n                  >\n                    {a}\n                  </span>\n                  {delta !== null && (\n                    <span\n                      className=\"text-[12px] tabular-nums\"\n                      style={{ color: delta >= 0 ? pal.sub : pal.faint }}\n                    >\n                      {delta >= 0 ? \"+\" : \"−\"}\n                      {Math.abs(delta)}\n                    </span>\n                  )}\n                  <span className=\"w-7 text-right text-[13px] font-[510] tabular-nums\">\n                    {value}\n                  </span>\n                </button>\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n\n      <div className=\"mt-3 flex flex-wrap items-center justify-between gap-2\">\n        <Pills\n          label=\"Team\"\n          options={views.map((v) => v.label)}\n          value={view}\n          onChange={setView}\n          pal={pal}\n        />\n        {benchmark && (\n          <span\n            className=\"flex items-center gap-2 text-[12px]\"\n            style={{ color: pal.sub }}\n          >\n            <span\n              className=\"w-4 border-t border-dashed\"\n              style={{ borderColor: pal.sub }}\n            />\n            {benchmarkLabel}\n          </span>\n        )}\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}