{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sunburst-chart",
  "title": "Sunburst chart",
  "description": "A tree as rings round a centre, such as a bundle’s size by package and file: each ring a level and each arc a part of its parent, as large as its value, in its branch’s colour, a step nearer the background for each level, with its name on it where it fits. A press on an arc zooms into it until it rings the centre, and the centre, a path above it, or Escape zooms back out. The arc under the pointer or the keys and its path to the centre stay bright while the rest step back, and new data moves every arc from where it is.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/chart.json",
    "https://kinoui.com/r/chart-centre.json",
    "https://kinoui.com/r/chart-core.json",
    "https://kinoui.com/r/chart-root.json",
    "https://kinoui.com/r/chart-math.json",
    "https://kinoui.com/r/chart-radial.json",
    "https://kinoui.com/r/chart-tiles.json",
    "https://kinoui.com/r/chart-tree-path.json",
    "https://kinoui.com/r/number-format.json",
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/sunburst-chart.tsx",
      "content": "'use client'\n\nimport {\n  type CategoryChartProps,\n  type EntrancePhase,\n  figureProps,\n  IndexActive,\n  pickedName,\n  ShareTooltipContent,\n  useChartActive,\n  useChartLife,\n  useChartLoad,\n  useChartPick,\n  useIndexFocus,\n} from '@/registry/lib/chart-base'\nimport { ChartCentreText } from '@/registry/lib/chart-centre'\nimport type { ChartPattern } from '@/registry/lib/chart-math'\nimport {\n  arcAt,\n  arcBox,\n  type ArcFractions,\n  arcLabelFit,\n  arcLabelSpin,\n  arcLabelTransform,\n  arcPath,\n  outerPoint,\n  type RingRoom,\n  round,\n} from '@/registry/lib/chart-radial'\nimport {\n  ChartFrame,\n  type ChartRootValue,\n  ChartSvgPattern,\n  drawingFrame,\n  drawingSize,\n  forcedSeriesColor,\n  forcedSeriesTextColor,\n  labelOnClassName,\n  plotLayerClassName,\n  stepBackInkClassName,\n  swatchClassName,\n  useChartFocus,\n  useChartRootValue,\n  useLeaving,\n  usePointsMove,\n} from '@/registry/lib/chart-root'\nimport {\n  arcFrom,\n  middleOf,\n  type ArcPlace,\n  arcTo,\n  placeBetween,\n  type RingArc,\n  ringLayout,\n  type RingLayout,\n  ringTree,\n  type TileNode,\n  tileAncestors,\n  tileNodeAt,\n  tileTree,\n  topColor,\n} from '@/registry/lib/chart-tiles'\nimport {\n  TreeZoomContext,\n  TreeZoomPath,\n  useTreeZoomRoot,\n} from '@/registry/lib/chart-tree-path'\nimport {\n  groupTarget,\n  treeItem,\n  type TreeStop,\n  treeReader,\n} from '@/registry/lib/chart-tree-reader'\nimport { numberFormatter } from '@/registry/lib/number-format'\nimport {\n  placeholderBreatheClassName,\n  placeholderInkClassName,\n} from '@/registry/lib/placeholder'\nimport {\n  type ComponentProps,\n  createContext,\n  type CSSProperties,\n  memo,\n  type ReactNode,\n  use,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * The Sunburst chart: a tree as rings round a centre, each ring a level and\n * each arc a part of its parent, as large as its value, in the colour of\n * the top of the tree it is under. A press on an arc with parts zooms into\n * it until it rings the centre, and a press on the centre, Escape, or the\n * path above the chart zooms back out. The arc under the pointer or the\n * keys and its path to the centre stay bright while the rest step back, and\n * new data moves every arc from where it is. A path's shape can't\n * transition, so every arc's angles and radii follow the chart's clock.\n */\n\ninterface SunburstChartProps extends Omit<\n  CategoryChartProps,\n  | 'domain'\n  | 'tickCount'\n  | 'tickValues'\n  | 'allowDecimals'\n  | 'ordered'\n  | 'selected'\n  | 'defaultSelected'\n  | 'onSelectedChange'\n  | 'color'\n> {\n  /** The key of each row's value in the data. A row with `children` is worth them added up. */\n  dataKey: string\n  /** What the values are, such as \"Size\": the centre's caption, and the tooltip's and the data table's word for them. */\n  valueLabel?: string\n  /** The part zoomed into, as the `index` values from the top down to it; `[]`, the whole, by default. */\n  zoom?: string[]\n  defaultZoom?: string[]\n  onZoomChange?: (zoom: string[]) => void\n  /** What each arc writes on itself, where it has the room: its name, or nothing. */\n  labels?: 'name' | 'none'\n  /** The hole's radius as a share of the chart's, from 0, no hole, to 0.8. */\n  innerRadius?: number\n  /** Each part's arcs biggest first; `false` keeps the data's order. */\n  sort?: boolean\n  /**\n   * How the arcs arrive the first time the chart comes into view: drawn\n   * round from the top, or simply there, the default, since a page that\n   * loads doesn't animate into place.\n   */\n  entrance?: 'draw' | 'none'\n}\n\nconst sunburstChartKeys = [\n  'dataKey',\n  'valueLabel',\n  'zoom',\n  'defaultZoom',\n  'onZoomChange',\n  'labels',\n  'innerRadius',\n  'sort',\n  'entrance',\n]\n\n/** How far each level below the top steps toward the background. */\nconst LEVEL_LIFT = 0.18\n\n/** The furthest a level steps. */\nconst MOST_LIFT = 0.6\n\ninterface SunburstContextValue {\n  layout: RingLayout\n  /** The arcs in view, in the order the keys step through them. */\n  stops: readonly TreeStop[]\n  /** The view's worth, the hidden tops' left out. */\n  viewValue: number\n  valueLabel: string\n  innerRadius: number\n  room: RingRoom\n  nameOf: (node: TileNode) => string\n  colorOf: (arc: RingArc) => string\n}\n\nconst SunburstContext = createContext<SunburstContextValue | null>(null)\n\nfunction useSunburstChart() {\n  const sunburst = use(SunburstContext)\n  if (!sunburst) throw new Error('Sunburst chart parts go inside a `SunburstChart`.')\n  return sunburst\n}\n\n/**\n * The chart's root: the tree from the rows, laid round the turn, the part\n * of it in view as up to three rings, and the frame its centre, path,\n * legend and tooltip draw in.\n */\nfunction SunburstChart(props: SunburstChartProps) {\n  const {\n    data,\n    index,\n    dataKey,\n    valueLabel,\n    labels = 'name',\n    innerRadius = 0.4,\n    sort = true,\n    entrance = 'none',\n    messages,\n    description,\n    empty,\n    className,\n    ref,\n  } = props\n  const tree = tileTree(data, index, dataKey)\n  const { state, groups, hidden, view, nameOf, valueOf, zoomTo } = useTreeZoomRoot(\n    {\n      ...props,\n      messages: {\n        series: 'Branches',\n        allHidden: 'Every branch is hidden',\n        showAll: (count) => `Show all ${count} branches`,\n        ...messages,\n      },\n    },\n    tree,\n    { entrance: entrance !== 'none' },\n  )\n  const { messages: words, locale, direction } = state\n\n  // The arcs in view, in the order the keys step through them.\n  const load = useChartLoad(props)\n  const places = load.placeholder || load.failed ? [] : ringTree(tree, { hidden, sort })\n  const layout = ringLayout(view, places)\n  const stops: TreeStop[] = layout.arcs.map((arc, at) => ({\n    id: arc.key,\n    name: nameOf(arc.node),\n    value: arc.node.value,\n    datum: arc.node.datum,\n    index: at,\n  }))\n  const life = useChartLife(\n    props,\n    state,\n    load,\n    {\n      rows: layout.arcs.length,\n      shown: state.series.filter((key) => !hidden.includes(key)).length,\n      drawn: stops.length,\n    },\n    { entrance: entrance !== 'none', cascade: null },\n  )\n  const { status, phase } = life\n  // Its props leave out `selected`, so nothing is picked; a press opens or does nothing.\n  const pick = useChartPick({}, stops.map(stopId))\n\n  const size = drawingSize(state.plotSize)\n  const edge = Math.max(0, Math.min(size.width, size.height) / 2 - 0.5)\n  const hole = Math.min(0.8, Math.max(0, innerRadius))\n  const room: RingRoom = { hole: edge * hole, edge }\n\n  // The whole the shares are of: the tops shown, added up.\n  const wholeValue = layout.arcs.length === 0 ? 0 : sumTops(places)\n  const viewValue = view.path.length === 0 ? wholeValue : view.value\n  const percent = numberFormatter(locale, {\n    style: 'percent',\n    maximumFractionDigits: 1,\n  })\n  const parentOf = (node: TileNode) => tileNodeAt(tree, node.path.slice(0, -1))\n  const shareOf = (value: number, of: number) => percent.format(of === 0 ? 0 : value / of)\n  const label = valueLabel ?? words.value\n  /** The names from the top down to `node`, the whole left out. */\n  const pathOf = (node: TileNode) =>\n    [...tileAncestors(tree, node).slice(1), node].map((part) => nameOf(part))\n  const colorOf = (arc: RingArc) =>\n    levelColor(topColor(state.series, groups, arc.top), arc.depth)\n\n  const arcOf = (stop: TreeStop) => layout.arcs[stop.index]\n  const opens = (node: TileNode | undefined) =>\n    node && node.children.length > 0 ? () => zoomTo(node.path) : null\n  const back = view.path.length > 0 ? () => zoomTo(view.path.slice(0, -1)) : null\n  const under = (point: { x: number; y: number; width: number; height: number }) =>\n    arcAt(point.x - point.width / 2, point.y - point.height / 2, layout.arcs, room)\n\n  const reader = treeReader({\n    stops,\n    direction,\n    hit: (point) => {\n      const found = under(point)\n      if (!found) return null\n      // The hole stands for the part in view, which a press there leaves.\n      if (found.kind === 'hole') return back ? { kind: 'group', key: view.key } : null\n      return { kind: 'stop', index: found.index }\n    },\n    openAt: (point) => {\n      const found = under(point)\n      if (!found) return null\n      return found.kind === 'hole' ? back : opens(layout.arcs[found.index]?.node)\n    },\n    open: (stop) => opens(arcOf(stop)?.node),\n    back,\n    // The tooltip sits on the arc's outer edge, at its middle, opening away from the centre.\n    anchor: (stop) => {\n      const arc = arcOf(stop)\n      if (!arc || size.width === 0 || size.height === 0) return null\n      return outerPoint(\n        (arc.start + arc.end) / 2,\n        size.width,\n        size.height,\n        arcBox(arc, room).outer,\n      )\n    },\n    words: {\n      describe: (stop) => {\n        const arc = arcOf(stop)\n        const name = pickedName(stop.name, pick.picked === stop.id, words)\n        if (!arc) return name\n        const parent = parentOf(arc.node)\n        const parts = [\n          name,\n          valueOf(arc.node),\n          ...(arc.depth > 1\n            ? [words.shareOf(shareOf(arc.node.value, parent.value), nameOf(parent))]\n            : []),\n          words.shareOf(shareOf(arc.node.value, wholeValue), nameOf(tree)),\n          words.level(arc.depth),\n        ]\n        return parts.join(', ')\n      },\n      table: {\n        header: words.category,\n        columns: [words.group, label, words.share, words.ofPart(nameOf(tree))],\n        rows: stops.map((stop) => {\n          const arc = arcOf(stop)\n          const node = arc?.node\n          const parent = node ? parentOf(node) : tree\n          const parentValue = node && node.path.length > 1 ? parent.value : wholeValue\n          return {\n            key: stop.id,\n            name: stop.name,\n            cells: [\n              node ? pathOf(node).slice(0, -1).join(' / ') : '',\n              node ? valueOf(node) : words.noValue,\n              shareOf(node?.value ?? 0, parentValue),\n              shareOf(node?.value ?? 0, wholeValue),\n            ],\n          }\n        }),\n        footer: [],\n      },\n      tooltip: (stop) => {\n        const arc = arcOf(stop)\n        if (!arc) return null\n        const value = valueOf(arc.node)\n        const parent = parentOf(arc.node)\n        const slot = state.series.indexOf(arc.top)\n        return (\n          <ShareTooltipContent\n            chart={state}\n            category={treeItem(stop)}\n            name={pathOf(arc.node).join(' / ')}\n            rows={\n              arc.depth > 1\n                ? [\n                    {\n                      label: words.ofPart(nameOf(parent)),\n                      value,\n                      share: shareOf(arc.node.value, parent.value),\n                    },\n                    {\n                      label: words.ofPart(nameOf(tree)),\n                      value: null,\n                      share: shareOf(arc.node.value, wholeValue),\n                    },\n                  ]\n                : [\n                    {\n                      label: null,\n                      value,\n                      share: shareOf(arc.node.value, wholeValue),\n                    },\n                  ]\n            }\n            swatch={\n              <span\n                aria-hidden\n                className={cn(swatchClassName, forcedSeriesColor(slot === -1 ? 0 : slot))}\n                style={{ '--swatch': colorOf(arc) } as CSSProperties}\n              />\n            }\n          />\n        )\n      },\n    },\n  })\n  const root: ChartRootValue = {\n    ...state,\n    status,\n    reader,\n    markerOf: () => null,\n    selectable: pick.selectable,\n    picked: pick.picked === null ? null : { kind: 'node', id: pick.picked },\n    togglePicked: (target) => {\n      if (target.kind === 'node' && reader.holds(target)) pick.toggle(target.id)\n    },\n  }\n  const { focusProps, toldRef } = useIndexFocus(reader.items, props)\n\n  return (\n    <TreeZoomContext value={{ tree, view, zoomTo, nameOf }}>\n      <SunburstContext\n        value={{\n          layout,\n          stops,\n          viewValue,\n          valueLabel: label,\n          innerRadius: hole,\n          room,\n          nameOf,\n          colorOf,\n        }}\n      >\n        <ChartFrame\n          root={root}\n          focus={focusProps}\n          ref={ref}\n          slot='sunburst-chart'\n          description={description}\n          empty={empty}\n          measuring={false}\n          inset={0}\n          data-orientation='vertical'\n          className={className}\n          {...figureProps(props, sunburstChartKeys)}\n        >\n          <IndexActive items={reader.items} active={props} toldRef={toldRef}>\n            <SunburstArcs labels={labels} phase={phase} />\n            {props.children}\n            {load.placeholder && <SunburstPlaceholder />}\n          </IndexActive>\n        </ChartFrame>\n      </SunburstContext>\n    </TreeZoomContext>\n  )\n}\n\nfunction stopId(stop: TreeStop) {\n  return stop.id\n}\n\nfunction arcKey(arc: RingArc) {\n  return arc.key\n}\n\n/** What the tops shown are worth together: the whole the chart's shares are of. */\nfunction sumTops(places: readonly { depth: number; node: TileNode }[]) {\n  return places.reduce(\n    (sum, place) => (place.depth === 1 ? sum + place.node.value : sum),\n    0,\n  )\n}\n\n/**\n * The colour of an arc `depth` levels below the whole: its top's, a step\n * nearer the page's background for each level below the top, lighter in\n * light mode and darker in dark, so the rings read as one branch from the\n * centre out and the deeper ones step back.\n */\nfunction levelColor(color: string, depth: number) {\n  const lift = levelLift(depth)\n  if (lift === 0) return color\n  return `color-mix(in oklch, ${color} ${round((1 - lift) * 100)}%, var(--background))`\n}\n\n/** How far a level is from its top's colour, as a share of the way to the background. */\nfunction levelLift(depth: number) {\n  return round(Math.min(MOST_LIFT, Math.max(0, depth - 1) * LEVEL_LIFT))\n}\n\n/** What tells one layout from another: the view, its rings and every arc's place, to five places. */\nfunction layoutSignature(layout: RingLayout) {\n  const arcs = layout.arcs\n    .map((arc) =>\n      [arc.key, arc.start, arc.end, arc.inner, arc.outer]\n        .map((part) => (typeof part === 'number' ? part.toFixed(5) : part))\n        .join(':'),\n    )\n    .join('|')\n  return `${layout.view.key}#${layout.rings}#${arcs}`\n}\n\n/** An arc as the chart draws it: its place, and how far its label turns past the arc's direction. */\ninterface ArcPoint extends ArcPlace {\n  key: string\n  spin: number\n}\n\n/** An arc's move: where it is drawn now, and where it goes. */\ninterface ArcMove {\n  key: string\n  from: ArcPoint\n  to: ArcPoint\n}\n\nfunction pointsSignature(points: readonly ArcPoint[]) {\n  return points\n    .map((point) =>\n      [point.key, point.start, point.end, point.inner, point.outer, point.spin]\n        .map((part) => (typeof part === 'number' ? part.toFixed(5) : part))\n        .join(':'),\n    )\n    .join('|')\n}\n\n/** The middle of an arc's turn. */\nfunction middleTurn(place: ArcFractions) {\n  return (place.start + place.end) / 2\n}\n\n/**\n * Every arc, in its branch's colour, a step lighter for each level, with\n * its name on it where it fits. The arc under the pointer and its path to\n * the centre stay bright while the rest step back. Each frame of a move\n * writes every arc's path and label where it is, from where it was drawn.\n */\nfunction SunburstArcs({\n  labels,\n  phase,\n}: {\n  labels: 'name' | 'none'\n  phase: EntrancePhase\n}) {\n  const chart = useChartRootValue()\n  const { spotlit } = useChartActive()\n  const { focus } = useChartFocus()\n  const sunburst = useSunburstChart()\n  const { layout, room } = sunburst\n  // The layout shown before this one, which what arrives comes from.\n  const signature = layoutSignature(layout)\n  const [held, setHeld] = useState<{\n    signature: string\n    now: RingLayout\n    was: RingLayout | null\n  }>({ signature, now: layout, was: null })\n  if (held.signature !== signature) setHeld({ signature, now: layout, was: held.now })\n  const was = held.signature === signature ? held.was : held.now\n  const leaving = useLeaving(chart.moves, layout.arcs, arcKey)\n  const measured = chart.plotSize.width > 0 && chart.plotSize.height > 0\n  const { width, height } = drawingSize(chart.plotSize)\n  const waiting = phase === 'waiting'\n  const entering = phase === 'entering'\n\n  // Where each arc goes, and how its label lies there.\n  const fits = new Map(\n    layout.arcs.map((arc) => {\n      const fit =\n        labels === 'none' || !measured\n          ? 'none'\n          : arcLabelFit(arcBox(arc, room), chart.textWidth(sunburst.nameOf(arc.node)))\n      return [arc.key, fit] as const\n    }),\n  )\n  const spinOf = (key: string, place: ArcPlace) => {\n    const fit = fits.get(key)\n    return arcLabelSpin(fit === 'across' ? 'across' : 'along', middleTurn(place))\n  }\n  const current: ArcPoint[] = layout.arcs.map((arc) => {\n    // Before the entrance, every arc waits folded to nothing at the top.\n    const place: ArcPlace = waiting\n      ? { start: 0, end: 0, inner: arc.inner, outer: arc.outer }\n      : arc\n    return { key: arc.key, ...placeOf(place), spin: spinOf(arc.key, arc) }\n  })\n  const gone: ArcPoint[] = leaving.map((arc) => {\n    const place = arcTo(arc, layout)\n    return {\n      key: arc.key,\n      ...placeOf(place),\n      spin: arcLabelSpin('along', middleTurn(arc)),\n    }\n  })\n  const to = [...current, ...gone]\n  const arriving = new Map(\n    layout.arcs.map((arc) => [arc.key, arcFrom(arc, was)] as const),\n  )\n  const paths = useRef(new Map<string, SVGPathElement>())\n  const words = useRef(new Map<string, SVGTextElement>())\n  // One function for the chart's life, so the memoised arcs keep theirs.\n  const [register] = useState(\n    () =>\n      (\n        key: string,\n        kind: 'path' | 'text',\n        element: SVGPathElement | SVGTextElement | null,\n      ) => {\n        const into = kind === 'path' ? paths.current : words.current\n        if (element) into.set(key, element as SVGPathElement & SVGTextElement)\n        else into.delete(key)\n      },\n  )\n  const draw = (points: readonly ArcPoint[]) => {\n    for (const point of points) {\n      paths.current.get(point.key)?.setAttribute('d', arcPath(point, room))\n      const text = words.current.get(point.key)\n      if (text) {\n        const box = arcBox(point, room)\n        text.setAttribute(\n          'transform',\n          arcLabelTransform(middleTurn(point), (box.inner + box.outer) / 2, point.spin),\n        )\n      }\n    }\n  }\n  usePointsMove<ArcPoint, readonly ArcMove[]>(\n    // The entrance draws the arcs round from the top; every change after moves them.\n    entering ? 'draw' : 'layout',\n    to,\n    pointsSignature(to),\n    // With none drawn yet, such as after the placeholder, each grows from its middle.\n    to.map((point) => ({\n      ...point,\n      start: middleTurn(point),\n      end: middleTurn(point),\n    })),\n    `${round(room.hole)}:${round(room.edge)}`,\n    {\n      align: (from, next) => {\n        const drawn = new Map(from.map((point) => [point.key, point]))\n        return next.map((point) => {\n          const place = arriving.get(point.key)\n          return {\n            key: point.key,\n            from: drawn.get(point.key) ?? {\n              ...point,\n              ...placeOf(place ? place : middleOf(point)),\n            },\n            to: point,\n          }\n        })\n      },\n      at: (moves, progress) =>\n        moves.map(({ key, from, to: end }) => ({\n          key,\n          ...placeBetween(from, end, progress),\n          spin: from.spin + (end.spin - from.spin) * progress,\n        })),\n      draw,\n    },\n  )\n  if (chart.status === 'empty') return null\n  const lit = spotlit === null ? null : (layout.arcs[spotlit]?.node.path ?? null)\n  const brightens = (path: readonly string[]) =>\n    lit !== null &&\n    path.length <= lit.length &&\n    path.every((name, at) => lit[at] === name)\n  // Brought forward from the legend: a top, whose branch alone stays bright.\n  const emphasis =\n    chart.emphasis !== null && chart.series.includes(chart.emphasis)\n      ? chart.emphasis\n      : null\n  // The hole itself under the pointer, which zooms out; not the legend's item for the same branch.\n  const holeLit =\n    layout.view.path.length > 0 &&\n    focus?.kind === 'node' &&\n    focus.id === groupTarget(layout.view.key)\n  const drawn = [\n    ...layout.arcs.map((arc) => ({ arc, leaving: false })),\n    ...leaving.map((arc) => ({ arc, leaving: true })),\n  ]\n  const points = new Map(to.map((point) => [point.key, point]))\n  return (\n    <div\n      data-slot='sunburst-chart-arcs'\n      aria-hidden\n      className={cn(plotLayerClassName, 'z-10')}\n    >\n      <svg\n        className='absolute inset-0 size-full overflow-visible'\n        viewBox={`0 0 ${round(width)} ${round(height)}`}\n        {...drawingFrame(chart.plotSize, 'xMidYMid meet')}\n      >\n        <g transform={`translate(${round(width / 2)} ${round(height / 2)})`}>\n          {room.hole > 0 && (\n            <circle\n              r={round(Math.max(0, room.hole - 1))}\n              data-lit={holeLit ? '' : undefined}\n              className='fill-transparent transition-[fill] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) data-lit:fill-muted forced-colors:data-lit:fill-[Highlight]'\n            />\n          )}\n          {drawn.map(({ arc, leaving: gone }, at) => {\n            const point = points.get(arc.key)\n            if (!point) return null\n            const slot = chart.series.indexOf(arc.top)\n            const name = sunburst.nameOf(arc.node)\n            const fit = gone || waiting ? 'none' : (fits.get(arc.key) ?? 'none')\n            const dim =\n              !gone &&\n              ((lit !== null && !brightens(arc.node.path)) ||\n                (emphasis !== null && emphasis !== arc.top))\n            const box = arcBox(point, room)\n            return (\n              <SunburstArc\n                key={arc.key}\n                arcKey={arc.key}\n                register={register}\n                id={`${chart.id}-arc-${at}`}\n                d={arcPath(point, room)}\n                labelAt={arcLabelTransform(\n                  middleTurn(point),\n                  (box.inner + box.outer) / 2,\n                  point.spin,\n                )}\n                color={sunburst.colorOf(arc)}\n                slot={slot === -1 ? 0 : slot}\n                pattern={slot === -1 ? 'solid' : chart.patternOf(arc.top)}\n                dim={dim}\n                leaving={gone}\n                entering={entering}\n                name={fit === 'none' ? null : name}\n              />\n            )\n          })}\n        </g>\n      </svg>\n    </div>\n  )\n}\n\n/** An arc's place alone, without what else a point or an arc carries. */\nfunction placeOf(place: ArcPlace): ArcPlace {\n  return {\n    start: place.start,\n    end: place.end,\n    inner: place.inner,\n    outer: place.outer,\n  }\n}\n\n/**\n * One arc and its label. Memoised, so a pointer moving between arcs redraws\n * only the ones it lights or dims; a move writes their paths directly.\n */\nconst SunburstArc = memo(function SunburstArc({\n  arcKey: key,\n  register,\n  id,\n  d,\n  labelAt,\n  color,\n  slot,\n  pattern,\n  dim,\n  leaving,\n  entering,\n  name,\n}: {\n  arcKey: string\n  /** Hands the chart the arc's path and label, which each frame of a move writes. */\n  register: (\n    key: string,\n    kind: 'path' | 'text',\n    element: SVGPathElement | SVGTextElement | null,\n  ) => void\n  id: string\n  d: string\n  labelAt: string\n  color: string\n  slot: number\n  pattern: ChartPattern\n  dim: boolean\n  leaving: boolean\n  entering: boolean\n  /** The name written on the arc, or none where it doesn't fit. */\n  name: string | null\n}) {\n  // An arc that has never had room for its name draws no label at all, so a chart of hundreds\n  // of small arcs styles only the elements it shows.\n  const [labelled, setLabelled] = useState(name !== null)\n  if (name !== null && !labelled) setLabelled(true)\n  const [said, setSaid] = useState(name)\n  if (name !== null && name !== said) setSaid(name)\n  const patternId = `${id}-pattern`\n  return (\n    <g\n      data-dim={dim ? '' : undefined}\n      data-leaving={leaving ? '' : undefined}\n      data-entering={entering ? '' : undefined}\n      className={cn(\n        'text-(--mark-ink) transition-none duration-(--motion-layout-duration) ease-[var(--motion-layout-fade-easing),var(--motion-layout-fade-easing)] group-data-mounted/chart:transition-[color,opacity] group-data-mounted/chart:starting:opacity-0 data-leaving:opacity-0 data-leaving:duration-(--motion-exit-duration) data-leaving:ease-[var(--motion-exit-fade-easing),var(--motion-exit-fade-easing)] data-entering:duration-(--motion-draw-duration)',\n        stepBackInkClassName,\n        forcedSeriesTextColor(slot),\n      )}\n      style={{ '--mark-color': color } as CSSProperties}\n    >\n      {pattern !== 'solid' && <ChartSvgPattern id={patternId} pattern={pattern} />}\n      <path\n        ref={(element) => register(key, 'path', element)}\n        d={d}\n        style={{\n          fill: pattern === 'solid' ? 'currentColor' : `url(#${patternId})`,\n        }}\n      />\n      {labelled && (\n        <text\n          ref={(element) => register(key, 'text', element)}\n          transform={labelAt}\n          textAnchor='middle'\n          dominantBaseline='central'\n          data-off={name === null ? '' : undefined}\n          className={cn(\n            'text-xs font-medium [fill:currentColor] transition-none group-data-mounted/chart:transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) data-off:opacity-0',\n            labelOnClassName,\n          )}\n          style={{ '--label-on': color } as CSSProperties}\n        >\n          {/* A label that no longer fits keeps its words while it fades. */}\n          {said}\n        </text>\n      )}\n    </g>\n  )\n})\n\n/** The rings in the placeholder's tint, breathing slowly, while the data loads. */\nfunction SunburstPlaceholder() {\n  const chart = useChartRootValue()\n  const { room } = useSunburstChart()\n  const { width, height } = drawingSize(chart.plotSize)\n  const layout = ringLayout(PLACEHOLDER_TREE, ringTree(PLACEHOLDER_TREE))\n  return (\n    <div\n      data-slot='sunburst-chart-placeholder'\n      aria-hidden\n      className={cn(plotLayerClassName, 'z-10', placeholderBreatheClassName)}\n    >\n      <svg\n        className={cn(\n          'absolute inset-0 size-full overflow-visible',\n          placeholderInkClassName,\n        )}\n        viewBox={`0 0 ${round(width)} ${round(height)}`}\n        {...drawingFrame(chart.plotSize, 'xMidYMid meet')}\n      >\n        <g transform={`translate(${round(width / 2)} ${round(height / 2)})`}>\n          {layout.arcs.map((arc) => (\n            <path key={arc.key} d={arcPath(arc, room)} className='fill-current' />\n          ))}\n        </g>\n      </svg>\n    </div>\n  )\n}\n\n/** The shape the placeholder's rings take: a few branches of falling size, each with a few parts. */\nconst PLACEHOLDER_TREE = tileTree(\n  [\n    [14, 9, 6],\n    [10, 7],\n    [8, 4, 3],\n    [5, 3],\n  ].map((parts, at) => ({\n    name: String(at),\n    children: parts.map((value, part) => ({ name: String(part), value })),\n  })),\n  'name',\n  'value',\n)\n\n/**\n * What sits in the hole: the worth of the part in view, under the chart's\n * `valueLabel` at the whole or the part's name once zoomed in, and the value\n * and name of the arc under the pointer or the keys, rolling in as it\n * changes. A press on it zooms back out. A hole too small for words draws\n * nothing there.\n */\nfunction SunburstChartCentre({\n  label,\n  className,\n  style,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & {\n  /** The caption under the whole's worth; the chart's `valueLabel` by default. */\n  label?: ReactNode\n}) {\n  const chart = useChartRootValue()\n  const { spotlit } = useChartActive()\n  const sunburst = useSunburstChart()\n  if (chart.status !== 'ready' || sunburst.innerRadius < 0.3) return null\n  const arc = spotlit === null ? undefined : sunburst.layout.arcs[spotlit]\n  const view = sunburst.layout.view\n  const value = arc ? arc.node.value : sunburst.viewValue\n  const caption = arc\n    ? sunburst.nameOf(arc.node)\n    : view.path.length > 0\n      ? sunburst.nameOf(view)\n      : (label ?? sunburst.valueLabel)\n  const hole = sunburst.room.hole * 2\n  const drawn = drawingSize(chart.plotSize)\n  return (\n    <div\n      data-slot='sunburst-chart-centre'\n      aria-hidden\n      className={cn(\n        plotLayerClassName,\n        'z-20 flex items-center justify-center',\n        className,\n      )}\n      style={\n        {\n          // Before the plot is measured, the stand-in's hole as a share of the plot's shorter side.\n          '--centre-hole':\n            chart.plotSize.width > 0 && chart.plotSize.height > 0\n              ? `${round(hole)}px`\n              : `calc(min(100cqw, 100cqh) * ${hole / Math.min(drawn.width, drawn.height)})`,\n          ...style,\n        } as CSSProperties\n      }\n      {...props}\n    >\n      <ChartCentreText\n        value={value}\n        caption={caption}\n        format={chart.format}\n        locale={chart.locale}\n      />\n    </div>\n  )\n}\n\n/**\n * The way back out: the path of the parts above the one in view, the whole\n * first, each a button that zooms out to it, above the plot.\n */\nfunction SunburstChartPath(props: ComponentProps<'nav'>) {\n  return <TreeZoomPath slot='sunburst-chart-path' {...props} />\n}\n\nexport {\n  levelColor,\n  levelLift,\n  SunburstChart,\n  SunburstChartCentre,\n  SunburstChartPath,\n  type SunburstChartProps,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/sunburst-chart.tsx"
    }
  ],
  "type": "registry:component"
}