{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radar-chart",
  "title": "Radar chart",
  "description": "Several values of each series on axes round a centre, one shape per series, on a grid of polygons or circles, with names that wrap and never clip, a value axis, and axes on scales of their own. A dot on each shape marks the axis under the pointer or the keys and turns round with its name, a series whose outline the pointer is on comes forward, and new data moves each point along its spoke from where it is.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/chart.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/highlight.json",
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/radar-chart.tsx",
      "content": "'use client'\n\nimport {\n  type CategoryChartProps,\n  chartParts,\n  ChartPartsContext,\n  figureProps,\n  seriesWords,\n  SeriesWordsContext,\n  type SeriesWordsInput,\n  tickMove,\n  useChartActive,\n  useDeclared,\n  usePreviousScales,\n  useTicks,\n} from '@/registry/lib/chart-base'\nimport {\n  ListChartFrame,\n  type ListChartStop,\n  useListChart,\n} from '@/registry/lib/chart-list'\nimport { listReader, type ListStop } from '@/registry/lib/chart-list-reader'\nimport {\n  allWhole,\n  type ChartDatum,\n  numberOf,\n  type Span,\n  stepThrough,\n} from '@/registry/lib/chart-math'\nimport {\n  edgeRoom,\n  labelBoxAt,\n  type RadialBox,\n  outerPoint,\n  RadialLabel,\n  standsClear,\n  round,\n  TEXT_HEIGHT,\n  tooltipSide,\n  turnOf,\n} from '@/registry/lib/chart-radial'\nimport {\n  type ChartFormat,\n  type ChartItem,\n  ChartSvgPattern,\n  drawingFrame,\n  drawingSize,\n  forcedSeriesColor,\n  forcedSeriesTextColor,\n  formatterOf,\n  type MoveRole,\n  plotLayerClassName,\n  seriesColor,\n  stepBackInkClassName,\n  useChartRootValue,\n  useFromRest,\n  usePointsMove,\n} from '@/registry/lib/chart-root'\nimport { type LinearScale, linearScale, tickCountFor } from '@/registry/lib/chart-scale'\nimport {\n  createHighlight,\n  type Highlight,\n  highlightClassName,\n} from '@/registry/lib/highlight'\nimport {\n  placeholderBreatheClassName,\n  placeholderInkClassName,\n} from '@/registry/lib/placeholder'\nimport {\n  type ComponentProps,\n  createContext,\n  type CSSProperties,\n  use,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * The Radar chart: several values of each series on axes round a centre,\n * one shape per series. The axes are the chart's categories, clockwise from\n * the top. New data moves each point along its spoke from where it is, an\n * axis that arrives grows out of the old outline and one that leaves folds\n * into the new, on one CSS transition of a number, `--radar-progress`, so\n * the feel, reduced motion and a slowed playback time it as they time\n * everything else.\n *\n * A dot on each shape marks the axis under the pointer or the keys, turning\n * round with the axis's pill; a series whose outline the pointer is on, or\n * the Up and Down arrows reach, or its legend entry, comes forward while the\n * rest step back.\n */\n\ninterface RadarChartProps extends Omit<CategoryChartProps, 'ordered'> {\n  /**\n   * The key of each axis's own top value in the data, for axes measured on\n   * different scales, such as a price beside a score: each point is drawn as\n   * its share of its axis's top, so the rings read as shares and the value\n   * axis has nothing to write.\n   */\n  maxKey?: string\n  /**\n   * How the shapes arrive the first time the chart comes into view: growing\n   * out of the centre, or simply there, the default, since a page that loads\n   * doesn't animate into place.\n   */\n  entrance?: 'rise' | 'none'\n}\n\n/** A point of an outline: its axis, how far round it is, and how far out, as a fraction of the edge. */\ninterface RadarVertex {\n  key: string\n  turn: number\n  r: number\n}\n\n/** Where a point of an outline moves from and to. */\ninterface VertexMove {\n  key: string\n  from: { turn: number; r: number }\n  to: { turn: number; r: number }\n}\n\n/** Where the axes' names sit: each name's box, the room they take past the edge, and those with no room, which show only in the pill. */\ninterface RadarNames {\n  room: number\n  boxes: ReadonlyMap<string, { width: number; height: number }>\n  hidden: ReadonlySet<string>\n}\n\n/** What a part written inside the Radar tells it as it renders. */\ninterface RadarPartDeclaration {\n  /** The axes' names a part writes round the chart, which the radius leaves room for: written by `format`, or the chart's `categoryFormat` with null. */\n  names: { format: ((value: unknown) => string) | null } | null\n}\n\n/** What tells a part's declaration apart; empty for one that says nothing. */\nfunction radarSignature(declaration: RadarPartDeclaration) {\n  return declaration.names ? 'names' : ''\n}\n\ninterface RadarContextValue {\n  /** Every axis to draw, a leaving one too, in a fixed order that sorting the data doesn't change. */\n  stops: readonly ListChartStop[]\n  /** The axes still in the data, in order. */\n  current: readonly ListStop[]\n  /** An axis's name, as the chart writes it, from its value under the chart's `index`. */\n  nameText: (value: unknown) => string\n  /** The value axis, the rings' ticks, and the one before its last change, so the rings grow from where they were. */\n  scale: LinearScale\n  previous: LinearScale\n  /** Where `RadarAxis` writes the names, or null with no `RadarAxis`. */\n  names: RadarNames | null\n  /** How far out the outer ring is, in px. */\n  edge: number\n  /** The plot's centre, in px. */\n  centre: { x: number; y: number }\n  /** Each axis's turn, by its key: the shown axes', and a leaving one's last. */\n  turns: ReadonlyMap<string, number>\n  /**\n   * Each axis's turn as its spoke and name are turned, counting past a whole\n   * turn, so when the axes reorder they turn the short way, as the outline's\n   * points do.\n   */\n  rotations: ReadonlyMap<string, number>\n  /** A series' outline over the shown axes: at the centre when `flat`. */\n  outlineOf: (key: string, flat: boolean) => RadarVertex[]\n  /** Where the point of `key` on `stop` sits, as a fraction of the edge; null for no value. */\n  fractionAt: (stop: ListStop, key: string) => number | null\n  /** Each axis on a scale of its own, so the values have no shared axis. */\n  ownScales: boolean\n  entrance: 'rise' | 'none'\n  /** The entrance has played, or wasn't asked for. */\n  entered: boolean\n  entering: boolean\n}\n\nconst RadarContext = createContext<RadarContextValue | null>(null)\n\nfunction useRadar() {\n  const radar = use(RadarContext)\n  if (!radar) throw new Error('Radar chart parts go inside a `RadarChart`.')\n  return radar\n}\n\nconst radarChartKeys = ['maxKey', 'entrance']\n\n/** The room between the edge and the axes' names, in px. */\nconst NAME_GAP = 8\n/** The narrowest names wrap at, in px: a few words a line. */\nconst NARROWEST_NAME = 56\n\n/** A name's padding inside the pill, across and down, in px. */\nconst NAME_PADDING = { x: 12, y: 4 } as const\n\n/** The least room between two rings, in px. */\nconst RING_SPACING = 24\n/** The least room between rings given as values, in px: a line of the value axis's text. */\nconst GIVEN_RING_SPACING = 16\nconst OWN_SCALE_TICKS = [0, 0.25, 0.5, 0.75, 1]\n\n/**\n * The ticks a radius with room for `most` rings keeps: the outermost, then every\n * so many inward, evenly where a step lands on the innermost too, so rings given\n * as values thin out as `tickCount` does.\n */\nfunction thinTicks(values: readonly number[], most: number): number[] {\n  const sorted = [...values].sort((a, b) => a - b)\n  const least = Math.max(1, Math.ceil(sorted.length / Math.max(1, most)))\n  // A step up to twice as long that lands on the innermost value too keeps the rings even.\n  const span = sorted.length - 1\n  const even = Array.from({ length: least }, (_, at) => least + at).find(\n    (step) => step <= span && span % step === 0,\n  )\n  const every = even ?? least\n  return sorted.filter((_, at) => (sorted.length - 1 - at) % every === 0)\n}\n\n/** The placeholder's shape while the data loads, as fractions of the edge: six axes, uneven, so it reads as a radar. */\nconst PLACEHOLDER_SHAPE = [0.72, 0.5, 0.64, 0.42, 0.7, 0.48] as const\n\n/** The placeholder's outline, which the shapes fold into while the data loads and grow back out of. */\nconst PLACEHOLDER_OUTLINE: readonly RadarVertex[] = PLACEHOLDER_SHAPE.map((r, at) => ({\n  // Keys no axis has, so the shapes that grow out of it match none of its points.\n  key: `\\u0000${at}`,\n  turn: at / PLACEHOLDER_SHAPE.length,\n  r,\n}))\n\nconst PLACEHOLDER_RINGS = [1 / 3, 2 / 3, 1]\n\n/** The lowest and highest the shown series reach, from zero: a radar's centre is zero. */\nfunction radarExtent(rows: readonly ChartDatum[], keys: readonly string[]): Span {\n  let high = 0\n  for (const row of rows) {\n    for (const key of keys) {\n      const value = numberOf(row[key])\n      if (value !== null) high = Math.max(high, value)\n    }\n  }\n  return [0, high]\n}\n\n/**\n * How the Radar fits its plot, in px: each name's box and the room they take\n * past the edge (none with no `names`), how far out the edge is, then as many\n * rings as the radius has room for, a ring every 24px or more, or rings given\n * as values (`given`) at least a line of text apart. Until the plot is\n * measured, the chart is drawn in a stand-in and keeps every ring asked for.\n */\nfunction radarFit({\n  names,\n  plot,\n  space,\n  tickCount,\n  given,\n}: {\n  names: readonly NameToFit[] | null\n  plot: { width: number; height: number }\n  /** A space's width, in px, where long names wrap. */\n  space: number\n  tickCount: number\n  given: readonly number[] | undefined\n}) {\n  const measured = plot.width > 0 && plot.height > 0\n  const { width, height } = drawingSize(plot)\n  const named = names ? fitNamesOn(names, plot, space) : null\n  const edge = Math.max(0, Math.min(width, height) / 2 - 0.5 - (named?.room ?? 0))\n  const measuredEdge = measured ? Math.round(edge) : null\n  return {\n    named,\n    edge,\n    rings: tickCountFor(tickCount, measuredEdge ?? 0, RING_SPACING),\n    tickValues:\n      given && measuredEdge !== null\n        ? thinTicks(given, Math.floor(measuredEdge / GIVEN_RING_SPACING))\n        : given,\n  }\n}\n\n/**\n * The chart's root: it places each axis round the centre, fits the value\n * axis to the shapes, and lays out the frame its grid, names, shapes and\n * tooltip draw in.\n */\nfunction RadarChart(props: RadarChartProps) {\n  const {\n    maxKey,\n    entrance = 'none',\n    tickCount = 4,\n    domain,\n    description,\n    empty,\n    className,\n    children,\n    ref,\n  } = props\n  const ownScales = maxKey !== undefined\n  const chart = useListChart(props, {\n    entrance: entrance !== 'none',\n    rowsAreSeries: false,\n  })\n  const { state, current, stops, shown, stopText } = chart\n  const parts = chartParts(children, radarSignature)\n  const axis = parts.declarations.findLast((part) => part.names !== null)?.names ?? null\n  const { width, height } = drawingSize(state.plotSize)\n  const measured = state.plotSize.width > 0 && state.plotSize.height > 0\n  const turns = useAxisTurns(stops, current)\n  const rotations = useAxisRotations(turns)\n  // The names' room sets the radius, and the radius how many rings it has room for, all worked\n  // out as the chart renders: until the plot is measured, it waits unseen.\n  const fit = radarFit({\n    names: axis\n      ? namesToFit(stops, turns, axis.format ?? stopText, state.textWidth)\n      : null,\n    plot: state.plotSize,\n    space: state.textWidth(' '),\n    tickCount,\n    given: ownScales ? OWN_SCALE_TICKS : props.tickValues,\n  })\n  const { named, edge } = fit\n  const centre = { x: width / 2, y: height / 2 }\n  const scale = linearScale(ownScales ? [0, 1] : radarExtent(chart.drawn, shown), {\n    // On scales of their own, every axis runs from nothing to its top.\n    domain: ownScales ? [0, 1] : domain,\n    tickCount: fit.rings,\n    tickValues: fit.tickValues,\n    nice: !ownScales,\n    allowDecimals: ownScales\n      ? true\n      : (props.allowDecimals ?? !allWhole(chart.rows, shown)),\n  })\n  const previous = usePreviousScales({ value: scale }).value ?? scale\n\n  const fractionAt = (stop: ListStop, key: string) => {\n    const value = numberOf(stop.datum?.[key])\n    if (value === null) return null\n    if (!ownScales) return scale.place(value)\n    const top = numberOf(stop.datum?.[maxKey])\n    return top === null || top <= 0 ? 0 : Math.min(1, Math.max(0, value / top))\n  }\n  const outlineOf = (key: string, flat: boolean): RadarVertex[] =>\n    current.map((stop) => ({\n      key: stop.key,\n      turn: turns.get(stop.key) ?? 0,\n      r: flat ? 0 : (fractionAt(stop, key) ?? 0),\n    }))\n  // On scales of their own, each value is written against its axis's top, as the shape draws it.\n  const seriesText = (stop: ChartItem, key: string) => {\n    const value = numberOf(stop.datum?.[key])\n    const top = ownScales ? numberOf(stop.datum?.[maxKey]) : null\n    return value === null || top === null\n      ? chart.datumText(stop.datum?.[key])\n      : state.messages.outOf(state.valueText(value), state.valueText(top))\n  }\n  const words: SeriesWordsInput = {\n    stops: current,\n    seriesText,\n    // Every axis holds a row of each series.\n    seriesNear: (stop, key) => ({ text: seriesText(stop, key), at: null }),\n    // Its axes don't run in order, so a value has no change since the one before.\n    seriesChange: () => null,\n    stopText: (stop) => stopText(stop.value),\n    ordered: false,\n    totals: (stop) =>\n      shown.length > 1\n        ? shown.reduce((all, key) => all + (numberOf(stop.datum?.[key]) ?? 0), 0)\n        : null,\n    totalByDefault: false,\n    forecast: () => false,\n    picked: chart.picked,\n    // The series brought forward alone, so Up and Down are heard to move.\n    alone: state.emphasis,\n    own: null,\n  }\n  const reader = listReader({\n    current,\n    walk: { kind: 'round' },\n    // With one series shown there is none to bring forward, so the axis stays lit.\n    series: {\n      kind: 'step',\n      step: (at, from, step) => {\n        const stop = current[at]\n        if (!stop || shown.length < 2) return null\n        return stepOutward(\n          shown.map((key) => ({ key, value: fractionAt(stop, key) })),\n          from,\n          step,\n        )\n      },\n      shown,\n    },\n    direction: state.direction,\n    hit: (point) => {\n      const x = point.x - point.width / 2\n      const y = point.y - point.height / 2\n      // On an axis's name, which the pill shows there, that axis, wherever round the plot it is.\n      const onName = current.findIndex((stop) => {\n        const size = named?.boxes.get(stop.key)\n        if (!size) return false\n        const name = labelBoxAt(\n          turns.get(stop.key) ?? 0,\n          edge + NAME_GAP,\n          size.width,\n          size.height,\n        )\n        return x >= name.left && x <= name.right && y >= name.top && y <= name.bottom\n      })\n      if (onName !== -1) return onName\n      if (Math.hypot(x, y) > Math.min(point.width, point.height) / 2 + NAME_GAP)\n        return null\n      return axisAt(turnOf(x, y), current.length)\n    },\n    // The tooltip sits past the axis's name, so it covers neither the name nor the shapes.\n    anchor: (stop) => {\n      if (width === 0 || height === 0) return null\n      const turn = turns.get(stop.key) ?? 0\n      const box = named?.boxes.get(stop.key)\n      if (!box) return outerPoint(turn, width, height, edge)\n      const { left, right, top, bottom } = labelBoxAt(\n        turn,\n        edge + NAME_GAP,\n        box.width,\n        box.height,\n      )\n      const side = nameSide(turn)\n      const x = side === 'left' ? left : side === 'right' ? right : (left + right) / 2\n      const y = side === 'top' ? top : side === 'bottom' ? bottom : (top + bottom) / 2\n      return { x: (centre.x + x) / width, y: (centre.y + y) / height, side }\n    },\n    words: seriesWords(state, words),\n  })\n\n  return (\n    <RadarContext\n      value={{\n        stops,\n        current,\n        nameText: stopText,\n        scale,\n        previous,\n        names: named,\n        edge,\n        centre,\n        turns,\n        rotations,\n        outlineOf,\n        fractionAt,\n        ownScales,\n        entrance,\n        entered: chart.entered,\n        entering: chart.entering,\n      }}\n    >\n      <ChartPartsContext value={parts}>\n        <SeriesWordsContext value={words}>\n          <ListChartFrame\n            chart={chart}\n            reader={reader}\n            ref={ref}\n            slot='radar-chart'\n            description={description}\n            empty={empty}\n            measuring={!measured}\n            className={className}\n            placeholder={chart.placeholder && <RadarPlaceholder />}\n            {...figureProps(props, radarChartKeys)}\n          >\n            {children}\n            <RadarLitMarks />\n          </ListChartFrame>\n        </SeriesWordsContext>\n      </ChartPartsContext>\n    </RadarContext>\n  )\n}\n\n/**\n * Each axis's turn, by its key: the shown axes evenly round from the top,\n * and an axis that leaves keeps the turn it had, so it fades where it was.\n */\nfunction useAxisTurns(\n  stops: readonly { key: string }[],\n  current: readonly { key: string }[],\n): ReadonlyMap<string, number> {\n  const signature = current.map((category) => category.key).join('\\u0000')\n  const now = new Map(\n    current.map((category, at) => [category.key, at / current.length] as const),\n  )\n  const [kept, setKept] = useState({ signature, turns: now })\n  if (kept.signature !== signature)\n    setKept({ signature, turns: new Map([...kept.turns, ...now]) })\n  const turns = new Map(now)\n  for (const stop of stops) {\n    if (turns.has(stop.key)) continue\n    const last = kept.turns.get(stop.key)\n    if (last !== undefined) turns.set(stop.key, last)\n  }\n  return turns\n}\n\n/** Each axis's `turns`, counted on from the turn it was last drawn at, so it turns the short way. */\nfunction useAxisRotations(\n  turns: ReadonlyMap<string, number>,\n): ReadonlyMap<string, number> {\n  const [kept, setKept] = useState<ReadonlyMap<string, number>>(turns)\n  const next = new Map(\n    [...turns].map(([key, turn]) => {\n      const was = kept.get(key)\n      if (was === undefined) return [key, turn] as const\n      const near = nearestTurn(was, turn)\n      // The same axis where it was stays exactly as kept, so a rounding error never renders again.\n      return [key, Math.abs(near - was) < 1e-9 ? was : near] as const\n    }),\n  )\n  const changed =\n    next.size !== kept.size || [...next].some(([key, turn]) => kept.get(key) !== turn)\n  if (changed) setKept(next)\n  return next\n}\n\n/**\n * Where the lit axis points, in turns that keep counting past a whole turn,\n * so the dots and the spoke glide the short way round from the\n * last axis to the first. Kept where it was while nothing is lit.\n */\nfunction useLitTurn() {\n  const radar = useRadar()\n  const { spotlit } = useChartActive()\n  const key = spotlit === null ? undefined : radar.current[spotlit]?.key\n  const target = key === undefined ? undefined : radar.turns.get(key)\n  const [turn, setTurn] = useState(target ?? 0)\n  const next = target === undefined ? turn : nearestTurn(turn, target)\n  if (next !== turn) setTurn(next)\n  return { lit: target !== undefined, turn: next }\n}\n\n/**\n * Moves an outline to `to` whenever it changes, from wherever it is, on the\n * frames of `--radar-progress` on `element`, calling `draw` with each\n * frame's outline. A new size alone redraws at once.\n */\nfunction useOutlineMove(\n  role: MoveRole,\n  draw: (outline: readonly RadarVertex[]) => void,\n  to: readonly RadarVertex[],\n  start: readonly RadarVertex[],\n  size: string,\n) {\n  usePointsMove(\n    role,\n    to,\n    to\n      .map((vertex) => `${vertex.key}:${vertex.turn.toFixed(5)}:${vertex.r.toFixed(5)}`)\n      .join('|'),\n    start,\n    size,\n    { align: alignOutlines, at: outlineAt, draw },\n  )\n}\n\ninterface RadarProps extends Omit<ComponentProps<'div'>, 'children' | 'color'> {\n  /** The key of this series' values in the data, and of its entry in the config. */\n  dataKey: string\n  /** Fills the shape with a light wash of the series' colour; off draws only its outline. */\n  fill?: boolean\n  /** Marks each point with a dot, not only those on the lit axis. */\n  dots?: boolean\n  /** Draws the outline dashed, such as a target or last year's shape. */\n  dashed?: boolean\n}\n\n/**\n * One series' shape, in its colour: a light fill and an outline through its\n * value on each axis, and a dot on each point with `dots`. It steps back\n * while another series is brought forward.\n */\nfunction Radar({\n  dataKey,\n  fill = true,\n  dots = false,\n  dashed = false,\n  className,\n  style,\n  ...props\n}: RadarProps) {\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const id = useId().replaceAll(':', '')\n  const hidden = chart.hidden.includes(dataKey)\n  const rising = !radar.entered && radar.entrance === 'rise'\n  // While the chart loads, the shape folds into the placeholder's and fades, and grows back\n  // out of it when the data arrives.\n  const loading = chart.status === 'loading'\n  const drawn = chart.status === 'ready' || chart.status === 'hidden' || loading\n  const to = loading\n    ? PLACEHOLDER_OUTLINE\n    : drawn\n      ? radar.outlineOf(dataKey, rising || hidden)\n      : []\n  const start = to.map((vertex) => ({ ...vertex, r: 0 }))\n  const outlines = useRef<(SVGPathElement | null)[]>([])\n  const marks = useRef<SVGGElement>(null)\n  const { edge, centre } = radar\n  useOutlineMove(\n    // The entrance grows the outline out of the centre; every change after moves it.\n    radar.entering ? 'draw' : 'layout',\n    (outline) => {\n      const d = outlinePath(outline, centre.x, centre.y, edge)\n      for (const path of outlines.current) path?.setAttribute('d', d)\n      for (const dot of marks.current?.querySelectorAll<SVGCircleElement>('[data-key]') ??\n        []) {\n        const vertex = outline.find((point) => point.key === dot.dataset.key)\n        if (!vertex) continue\n        const [x, y] = pointOf(vertex, centre.x, centre.y, edge)\n        dot.setAttribute('cx', String(round(x)))\n        dot.setAttribute('cy', String(round(y)))\n      }\n    },\n    to,\n    start,\n    `${round(edge)}:${round(centre.x)}:${round(centre.y)}`,\n  )\n  if (!drawn) return null\n  const slot = chart.series.indexOf(dataKey)\n  const pattern = chart.patternOf(dataKey)\n  const emphasised = chart.emphasis === dataKey\n  // The shape steps back, whole, while another series is brought forward.\n  const stepsBack = chart.emphasis !== null && !emphasised\n  const { width, height } = drawingSize(chart.plotSize)\n  const frame = drawingFrame(chart.plotSize, 'xMidYMid meet')\n  const viewBox = `0 0 ${round(width)} ${round(height)}`\n  const d = outlinePath(to, centre.x, centre.y, edge)\n  const points = chart.status === 'ready' && !hidden && dots ? radar.current : []\n  const patternId = `${id}-pattern`\n\n  return (\n    <div\n      data-slot='radar-chart-series'\n      data-series={dataKey}\n      data-hidden={hidden || loading ? '' : undefined}\n      data-forward={emphasised ? '' : undefined}\n      aria-hidden\n      className={cn(\n        plotLayerClassName,\n        // The series brought forward paints over the rest, under the lit marks' z-20.\n        'z-10 data-forward:z-15 transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-easing) data-hidden:opacity-0',\n        className,\n      )}\n      style={{ '--mark-color': seriesColor(dataKey), ...style } as CSSProperties}\n      {...props}\n    >\n      <svg\n        viewBox={viewBox}\n        {...frame}\n        data-entering={radar.entering ? '' : undefined}\n        data-dim={stepsBack ? '' : undefined}\n        className={cn(\n          'absolute inset-0 size-full overflow-visible text-(--mark-ink) transition-[color] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) forced-colors:data-dim:[--radar-chart-width:1px] data-entering:duration-(--motion-draw-duration) data-entering:ease-(--motion-draw-fade-easing)',\n          stepBackInkClassName,\n          forcedSeriesTextColor(slot),\n        )}\n      >\n        {fill && (\n          <>\n            {pattern !== 'solid' && <ChartSvgPattern id={patternId} pattern={pattern} />}\n            <path\n              ref={(element) => {\n                outlines.current[1] = element\n              }}\n              d={d}\n              className='stroke-none [fill-opacity:var(--radar-chart-fill,0.24)]'\n              style={{\n                fill: pattern === 'solid' ? 'currentColor' : `url(#${patternId})`,\n              }}\n            />\n          </>\n        )}\n        <path\n          ref={(element) => {\n            outlines.current[0] = element\n          }}\n          d={d}\n          className={cn(\n            'fill-none stroke-current [stroke-width:var(--radar-chart-width,2px)] [stroke-linejoin:round] [vector-effect:non-scaling-stroke]',\n            dashed && '[stroke-dasharray:6_5]',\n          )}\n        />\n        {points.length > 0 && (\n          <g ref={marks}>\n            {points.map((category) => {\n              const r = radar.fractionAt(category, dataKey)\n              if (r === null) return null\n              const [x, y] = pointOf(\n                {\n                  key: category.key,\n                  turn: radar.turns.get(category.key) ?? 0,\n                  r,\n                },\n                centre.x,\n                centre.y,\n                edge,\n              )\n              return (\n                <circle\n                  key={category.key}\n                  data-key={category.key}\n                  cx={round(x)}\n                  cy={round(y)}\n                  r={3}\n                  className='fill-background stroke-current [stroke-width:2px] [vector-effect:non-scaling-stroke]'\n                />\n              )\n            })}\n          </g>\n        )}\n      </svg>\n    </div>\n  )\n}\n\n/**\n * What marks the lit axis: a dot on each shown series where it crosses the\n * axis. They turn round the centre from axis to axis with the spoke, appear\n * in place after a rest, and fade where they are when the pointer leaves.\n */\nfunction RadarLitMarks() {\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const { spotlit } = useChartActive()\n  const lit = useLitTurn()\n  const layer = useRef<HTMLDivElement>(null)\n  const fromRest = useFromRest(spotlit)\n  // The axis last lit, where the dots stay while they fade out.\n  const [last, setLast] = useState(spotlit)\n  if (spotlit !== null && spotlit !== last) setLast(spotlit)\n  const shownAt = spotlit ?? last\n  const category = shownAt === null ? undefined : radar.current[shownAt]\n  if (chart.status !== 'ready' || !category || !radar.entered) return null\n  const shown = chart.series.filter((key) => !chart.hidden.includes(key))\n  const snap = fromRest ? '' : undefined\n  return (\n    <div\n      ref={layer}\n      aria-hidden\n      data-slot='radar-chart-lit'\n      data-hidden={spotlit === null ? '' : undefined}\n      className={cn(\n        plotLayerClassName,\n        'z-20 transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) data-hidden:opacity-0 data-hidden:duration-(--motion-exit-duration) data-hidden:ease-(--motion-exit-easing)',\n      )}\n    >\n      {shown.map((key) => {\n        const r = radar.fractionAt(category, key)\n        if (r === null) return null\n        return (\n          <span\n            key={key}\n            data-snap={snap}\n            // Turned round the centre and out along the axis in one transform, so a glide to the\n            // next axis turns round the centre rather than cutting across the shape.\n            className='absolute top-1/2 left-1/2 size-0 [transform:rotate(var(--dot-turn))_translateY(var(--dot-out))] transition-none duration-(--motion-layout-duration) ease-(--motion-layout-easing) group-data-mounted/chart:transition-[transform] data-snap:group-data-mounted/chart:transition-none motion-reduce:group-data-mounted/chart:transition-none'\n            style={\n              {\n                '--dot-turn': `${round(lit.turn * 360)}deg`,\n                '--dot-out': `${-round(r * radar.edge)}px`,\n                '--mark-color': seriesColor(key),\n              } as CSSProperties\n            }\n          >\n            {/* A series that steps back while another is brought forward takes its dot with it. */}\n            <span\n              data-dim={\n                chart.emphasis !== null && chart.emphasis !== key ? '' : undefined\n              }\n              className={cn(\n                'ring-background absolute -top-1 -left-1 size-2 rounded-full bg-(--mark-ink) ring-2 transition-[background-color] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing)',\n                stepBackInkClassName,\n                forcedSeriesColor(chart.series.indexOf(key)),\n              )}\n            />\n          </span>\n        )\n      })}\n    </div>\n  )\n}\n\n/**\n * The grid: a ring at each of the value axis's ticks, as the axes'\n * polygon or as circles, and a spoke out to each axis. Rings grow and\n * shrink to their new place when the range changes, spokes turn to their\n * axis's new place when axes come and go, and the lit axis's spoke stands\n * out, turning with the lit dots.\n */\nfunction RadarGrid({\n  shape = 'polygon',\n  spokes = true,\n  className,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & {\n  /** The rings' shape: the axes' polygon, or circles. */\n  shape?: 'polygon' | 'circle'\n  /** Draws a spoke from the centre out to each axis. */\n  spokes?: boolean\n}) {\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const { spotlit } = useChartActive()\n  const lit = useLitTurn()\n  const layer = useRef<HTMLDivElement>(null)\n  const litSpoke = useRef<SVGLineElement>(null)\n  const fromRest = useFromRest(spotlit)\n  const ticks = useTicks(radar.scale)\n  const framePath = useRef<SVGPathElement>(null)\n  const id = useId().replaceAll(':', '')\n  const { edge, centre } = radar\n  const ready = chart.status === 'ready' || chart.status === 'hidden'\n  const polygon = shape === 'polygon' && ready\n  const outline = polygon\n    ? radar.current.map((stop) => ({\n        key: stop.key,\n        turn: radar.turns.get(stop.key) ?? 0,\n        r: 1,\n      }))\n    : []\n  useOutlineMove(\n    'layout',\n    (now) =>\n      framePath.current?.setAttribute('d', outlinePath(now, centre.x, centre.y, edge)),\n    outline,\n    outline,\n    `${round(edge)}:${round(centre.x)}:${round(centre.y)}`,\n  )\n  const { width, height } = drawingSize(chart.plotSize)\n  const { scale, previous: previousScale } = radar\n  const line =\n    'fill-none stroke-border [stroke-dasharray:3_3] [stroke-width:1px] [vector-effect:non-scaling-stroke] forced-colors:stroke-[GrayText]'\n  const turning =\n    'transition-none duration-(--motion-layout-duration) ease-[var(--motion-layout-easing),var(--motion-layout-fade-easing)] group-data-mounted/chart:transition-[transform,opacity] group-data-mounted/chart:starting:opacity-0 data-leaving:opacity-0 motion-reduce:group-data-mounted/chart:transition-[opacity]'\n  return (\n    <div\n      ref={layer}\n      data-slot='radar-chart-grid'\n      aria-hidden\n      className={cn(plotLayerClassName, 'z-0', className)}\n      {...props}\n    >\n      {ready && (\n        <svg\n          viewBox={`0 0 ${round(width)} ${round(height)}`}\n          {...drawingFrame(chart.plotSize, 'xMidYMid meet')}\n          className='absolute inset-0 size-full overflow-visible'\n        >\n          {polygon && (\n            <defs>\n              <path\n                ref={framePath}\n                id={`${id}-frame`}\n                d={outlinePath(outline, centre.x, centre.y, edge)}\n              />\n            </defs>\n          )}\n          {ticks.map(({ value: tick, leaving }) => {\n            const place = scale.place(tick)\n            if (place <= 0 && !leaving) return null\n            const ring = {\n              'data-leaving': leaving ? '' : undefined,\n              className: cn(line, '[transform:scale(var(--ring-to))]', tickTurn),\n              style: {\n                transformOrigin: `${round(centre.x)}px ${round(centre.y)}px`,\n                '--ring-to': round(place * 1e4) / 1e4,\n                '--ring-from': round(previousScale.place(tick) * 1e4) / 1e4,\n              } as CSSProperties,\n            }\n            return polygon ? (\n              <use key={tick} href={`#${id}-frame`} {...ring} />\n            ) : (\n              <circle\n                key={tick}\n                cx={round(centre.x)}\n                cy={round(centre.y)}\n                r={round(edge)}\n                {...ring}\n              />\n            )\n          })}\n          {spokes &&\n            radar.stops.map((category) => (\n              <line\n                key={category.key}\n                data-leaving={category.leaving ? '' : undefined}\n                x1={round(centre.x)}\n                y1={round(centre.y)}\n                x2={round(centre.x)}\n                y2={round(centre.y - edge)}\n                className={cn(line, '[transform:rotate(var(--spoke-turn))]', turning)}\n                style={\n                  {\n                    transformOrigin: `${round(centre.x)}px ${round(centre.y)}px`,\n                    '--spoke-turn': `${round((radar.rotations.get(category.key) ?? 0) * 360)}deg`,\n                  } as CSSProperties\n                }\n              />\n            ))}\n          {/* The lit axis's spoke, turning with the lit dots. */}\n          <line\n            ref={litSpoke}\n            data-snap={fromRest ? '' : undefined}\n            data-hidden={spotlit === null ? '' : undefined}\n            x1={round(centre.x)}\n            y1={round(centre.y)}\n            x2={round(centre.x)}\n            y2={round(centre.y - edge)}\n            className='stroke-muted-foreground/60 [stroke-width:1px] [transform:rotate(var(--spoke-turn))] [vector-effect:non-scaling-stroke] transition-[transform,opacity] duration-(--motion-layout-duration) ease-[var(--motion-layout-easing),var(--motion-layout-fade-easing)] data-hidden:opacity-0 data-hidden:duration-(--motion-exit-duration) data-hidden:ease-[var(--motion-exit-easing),var(--motion-exit-fade-easing)] data-snap:transition-[opacity] motion-reduce:transition-[opacity] forced-colors:stroke-[CanvasText]'\n            style={\n              {\n                transformOrigin: `${round(centre.x)}px ${round(centre.y)}px`,\n                '--spoke-turn': `${round(lit.turn * 360)}deg`,\n              } as CSSProperties\n            }\n          />\n        </svg>\n      )}\n    </div>\n  )\n}\n\n/** A ring growing to its tick's new place, and in from where the old range put it. */\nconst tickTurn =\n  'transition-none duration-(--motion-layout-duration) ease-[var(--motion-layout-easing),var(--motion-layout-fade-easing)] group-data-mounted/chart:transition-[transform,opacity] group-data-mounted/chart:starting:[transform:scale(var(--ring-from))] group-data-mounted/chart:starting:opacity-0 data-leaving:opacity-0 motion-reduce:group-data-mounted/chart:transition-[opacity]'\n\ninterface RadarAxisProps extends Omit<ComponentProps<'div'>, 'children'> {\n  /** How each axis is named; the chart's `categoryFormat` by default. */\n  categoryFormat?: (value: unknown) => string\n}\n\n/**\n * Each axis's name, outside the outer ring at its turn, against it and\n * upright, wrapping when it is long, with room kept for it inside the\n * chart's own box. The name of the axis lit sits in the pill, which slides\n * from name to name as the axis lit changes.\n */\nfunction RadarAxis(props: RadarAxisProps) {\n  const { categoryFormat, className, ...rest } = props\n  useDeclared('RadarAxis', RadarAxis.declare(props), radarSignature)\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const { spotlit } = useChartActive()\n  const pill = useRef<HTMLSpanElement>(null)\n  const names = useRef(new Map<string, HTMLElement>())\n  const write = categoryFormat ?? radar.nameText\n  const measured = chart.plotSize.width > 0 && chart.plotSize.height > 0\n  const { width, height } = drawingSize(chart.plotSize)\n  // Long names wrap, narrower until neighbours stop meeting, and the grid makes room for them.\n  const boxes = radar.names?.boxes\n  const hidden = radar.names?.hidden\n  const highlight = useRef<Highlight | null>(null)\n  useEffect(() => {\n    const element = pill.current\n    if (!element) return\n    const created = createHighlight(element)\n    highlight.current = created\n    return () => {\n      created.stop()\n      highlight.current = null\n    }\n  }, [])\n  useEffect(() => {\n    const key = spotlit === null ? undefined : radar.current[spotlit]?.key\n    const item = key === undefined ? null : (names.current.get(key) ?? null)\n    // An axis lit as the chart first paints, such as a pick, has the pill there at once.\n    if (item && !item.closest('[data-mounted]')) highlight.current?.jump(item)\n    else highlight.current?.move(item)\n  }, [spotlit, radar, radar.edge])\n  const ready = chart.status === 'ready'\n  // Before the plot is measured, the names sit round the stand-in the chart is drawn in.\n  const stretch = measured ? null : 1 / Math.min(width, height)\n\n  // The names, drawn twice: once round the chart, and once in the pill's colours inside the pill,\n  // which shows only the part under it, so the name it slides onto reads in its colours.\n  const layer = (copy: boolean) => (\n    <span className='absolute inset-0 [container-type:size]'>\n      {ready &&\n        radar.stops.map((category) => {\n          const turn = radar.rotations.get(category.key) ?? 0\n          const box = boxes?.get(category.key)\n          const sin = Math.sin(turn * Math.PI * 2)\n          return (\n            <RadialLabel\n              key={category.key}\n              ref={\n                copy\n                  ? undefined\n                  : (element) => {\n                      if (!element || category.leaving) return\n                      names.current.set(category.key, element)\n                      return () => {\n                        if (names.current.get(category.key) === element)\n                          names.current.delete(category.key)\n                      }\n                    }\n              }\n              turn={turn}\n              radius={radar.edge + NAME_GAP}\n              stretch={stretch}\n              // A name with no room shows only in the pill, which is above the rest.\n              shown={!category.leaving && (copy || !hidden?.has(category.key))}\n              dir='auto'\n              className='rounded-(--control-radius-xs) px-1.5 py-0.5 text-balance'\n              style={{\n                width: box?.width,\n                // Each side reads from the chart outward, so wrapped lines hug the grid.\n                textAlign: Math.abs(sin) < 0.2 ? 'center' : sin > 0 ? 'left' : 'right',\n              }}\n            >\n              {write(category.value)}\n            </RadialLabel>\n          )\n        })}\n    </span>\n  )\n  return (\n    <div\n      data-slot='radar-chart-axis'\n      aria-hidden\n      className={cn(plotLayerClassName, 'text-muted-foreground z-20', className)}\n      {...rest}\n    >\n      {layer(false)}\n      <span\n        ref={pill}\n        data-slot='radar-chart-pill'\n        className={cn(\n          highlightClassName,\n          'bg-foreground text-background z-10 forced-colors:bg-[Highlight] forced-colors:text-[HighlightText] forced-colors:forced-color-adjust-none',\n        )}\n      >\n        {layer(true)}\n      </span>\n    </div>\n  )\n}\n\nRadarAxis.declare = ({ categoryFormat }: RadarAxisProps): RadarPartDeclaration => ({\n  names: { format: categoryFormat ?? null },\n})\n\n/**\n * The value axis: each ring's value up the top spoke, sliding to its ring's\n * new place when the range changes. Axes on scales of their own share no\n * values, so it writes nothing then.\n */\nfunction RadarValueAxis({\n  format,\n  className,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & {\n  /** How the values are written; the chart's `format`, shortened, by default. */\n  format?: ChartFormat\n}) {\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const layer = useRef<HTMLDivElement>(null)\n  const own = chart.format\n  const write = formatterOf(\n    chart.locale,\n    format ??\n      (typeof own === 'function'\n        ? own\n        : { maximumFractionDigits: 1, ...own, notation: 'compact' }),\n  )\n  const all = useTicks(radar.scale, undefined, write)\n  if (radar.ownScales) return null\n  const ticks = chart.status === 'ready' ? all : []\n  const { edge, centre } = radar\n  const { width, height } = drawingSize(chart.plotSize)\n  const place = (tick: number, scale: LinearScale) =>\n    `0.25rem calc(${round(centre.y - scale.place(tick) * edge)} / ${round(height)} * 100cqh - 50%)`\n  return (\n    <div\n      ref={layer}\n      data-slot='radar-chart-value-axis'\n      aria-hidden\n      className={cn(plotLayerClassName, 'text-foreground z-20 tabular-nums', className)}\n      {...props}\n    >\n      {ticks.map(({ value: tick, text, leaving }) =>\n        radar.scale.place(tick) <= 0 && !leaving ? null : (\n          <span\n            key={tick}\n            data-leaving={leaving ? '' : undefined}\n            // A halo of the page's colour keeps each value legible over the shapes.\n            className={cn(\n              tickMove,\n              'absolute top-0 whitespace-nowrap [text-shadow:0_0_2px_var(--background),0_0_4px_var(--background)]',\n            )}\n            style={\n              {\n                left: `${round((centre.x / width) * 100)}%`,\n                '--tick-to': place(tick, radar.scale),\n                '--tick-from': place(tick, radar.previous),\n              } as CSSProperties\n            }\n          >\n            {text}\n          </span>\n        ),\n      )}\n    </div>\n  )\n}\n\n/**\n * The placeholder while the data loads: rings and a soft shape breathing\n * slowly, which the shapes grow out of when the data arrives.\n */\nfunction RadarPlaceholder() {\n  const chart = useChartRootValue()\n  const radar = useRadar()\n  const { width, height } = drawingSize(chart.plotSize)\n  const { edge, centre } = radar\n  return (\n    <div\n      data-slot='radar-chart-placeholder'\n      aria-hidden\n      className={cn(\n        plotLayerClassName,\n        'z-10 transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) group-data-mounted/chart:starting:opacity-0',\n      )}\n    >\n      <div\n        className={cn(\n          'absolute inset-0',\n          placeholderInkClassName,\n          placeholderBreatheClassName,\n        )}\n      >\n        <svg\n          viewBox={`0 0 ${round(width)} ${round(height)}`}\n          {...drawingFrame(chart.plotSize, 'xMidYMid meet')}\n          className='absolute inset-0 size-full overflow-visible'\n        >\n          {/* A radar's frame, its rings and spokes, under a shape still to come. */}\n          <g className='fill-none stroke-current' strokeWidth={1}>\n            {PLACEHOLDER_RINGS.map((r) => (\n              <path\n                key={r}\n                d={outlinePath(\n                  PLACEHOLDER_OUTLINE.map((vertex) => ({ ...vertex, r })),\n                  centre.x,\n                  centre.y,\n                  edge,\n                )}\n              />\n            ))}\n            {PLACEHOLDER_OUTLINE.map((vertex) => {\n              const [x, y] = pointOf({ ...vertex, r: 1 }, centre.x, centre.y, edge)\n              return (\n                <line\n                  key={vertex.key}\n                  x1={centre.x}\n                  y1={centre.y}\n                  x2={round(x)}\n                  y2={round(y)}\n                />\n              )\n            })}\n          </g>\n          <path\n            d={outlinePath(PLACEHOLDER_OUTLINE, centre.x, centre.y, edge)}\n            className='fill-current stroke-none'\n          />\n        </svg>\n      </div>\n    </div>\n  )\n}\n\n/** About a radar's plot, in px, to fit its names against before the plot is measured. */\nconst TYPICAL_PLOT = 320\n\n/**\n * `fitNames` on a plot `size` px. Before it is measured, the names, in px,\n * fit round a plot of a typical size, and their room scales to the\n * stand-in the chart is drawn in, which then stretches to the plot.\n */\nfunction fitNamesOn(\n  names: readonly NameToFit[],\n  size: { width: number; height: number },\n  space: number,\n) {\n  if (size.width > 0 && size.height > 0)\n    return fitNames(names, size.width, size.height, space)\n  const fitted = fitNames(names, TYPICAL_PLOT, TYPICAL_PLOT, space)\n  const drawn = drawingSize(size)\n  return {\n    ...fitted,\n    room: (fitted.room * Math.min(drawn.width, drawn.height)) / TYPICAL_PLOT,\n  }\n}\n\n/** The axes' names to fit round the chart, written by `write`, each word `textWidth` px wide. */\nfunction namesToFit(\n  stops: readonly ListChartStop[],\n  turns: ReadonlyMap<string, number>,\n  write: (value: unknown) => string,\n  textWidth: (text: string) => number,\n): NameToFit[] {\n  return stops.map((stop) => ({\n    key: stop.key,\n    turn: turns.get(stop.key) ?? 0,\n    words: write(stop.value)\n      .split(/\\s+/)\n      .filter(Boolean)\n      .map((word) => textWidth(word)),\n    shown: !stop.leaving,\n  }))\n}\n\n/** An axis's name to fit round the chart: where it is, and how wide its words are, in px. */\ninterface NameToFit {\n  key: string\n  turn: number\n  /** Each word's width on one line, in px. */\n  words: readonly number[]\n  /** Still in the data; a leaving name takes no room. */\n  shown: boolean\n}\n\n/**\n * Each name's box, the room the names take past the edge, and which names\n * show, in a plot `width` by `height` px. A name wraps at about a quarter\n * of the plot's width; where two names would still meet, every name wraps\n * narrower, down to a few words a line. Names that meet even then make way\n * for the ones before them, as the Donut's labels do: the pill still shows\n * the lit axis's name in full.\n */\nfunction fitNames(\n  names: readonly NameToFit[],\n  width: number,\n  height: number,\n  space: number,\n) {\n  const widest = Math.max(72, Math.min(160, width * 0.28))\n  const shown = names.filter((name) => name.shown).toSorted((a, b) => a.turn - b.turn)\n  let fitted = boxesAt(names, widest, width, height, space)\n  for (\n    let most = widest - 8;\n    most >= NARROWEST_NAME && placedClear(shown, fitted, width, height).includes(false);\n    most -= 8\n  ) {\n    fitted = boxesAt(names, most, width, height, space)\n  }\n  const clear = placedClear(shown, fitted, width, height)\n  const hidden = new Set(shown.filter((_, at) => !clear[at]).map((name) => name.key))\n  return { ...fitted, hidden }\n}\n\n/** How many lines words `words` px wide take, wrapped at spaces `space` px wide to `most` px, and the widest line. */\nfunction wrapWords(words: readonly number[], space: number, most: number) {\n  let lines = 0\n  let line = 0\n  let widest = 0\n  for (const word of words) {\n    if (lines > 0 && line + space + word <= most) line += space + word\n    else {\n      lines += 1\n      line = word\n    }\n    widest = Math.max(widest, line)\n  }\n  return { lines: Math.max(1, lines), widest }\n}\n\n/** The names' boxes when they wrap at `most` px, and the room they take. */\nfunction boxesAt(\n  names: readonly NameToFit[],\n  most: number,\n  width: number,\n  height: number,\n  space: number,\n) {\n  const boxes = new Map(\n    names.map((name) => {\n      // The box's padding is outside the text's width.\n      const { lines, widest } = wrapWords(name.words, space, most - NAME_PADDING.x)\n      return [\n        name.key,\n        {\n          // A pixel to spare, so the page's text never wraps where the measure didn't.\n          width: Math.ceil(widest) + 1 + NAME_PADDING.x,\n          height: lines * TEXT_HEIGHT + NAME_PADDING.y,\n        },\n      ] as const\n    }),\n  )\n  const room = edgeRoom(\n    width,\n    height,\n    names\n      .filter((name) => name.shown)\n      .map((name) => ({ turn: name.turn, ...boxes.get(name.key)! })),\n    NAME_GAP,\n  )\n  return { boxes, room }\n}\n\n/**\n * Whether each of `shown`, in turn order, stands clear of every name kept\n * before it, with the edge where `fitted` leaves it.\n */\nfunction placedClear(\n  shown: readonly NameToFit[],\n  { boxes, room }: ReturnType<typeof boxesAt>,\n  width: number,\n  height: number,\n) {\n  const radius = Math.max(0, Math.min(width, height) / 2 - 0.5 - room) + NAME_GAP\n  const kept: RadialBox[] = []\n  return shown.map((name) => {\n    const size = boxes.get(name.key)!\n    const box = labelBoxAt(name.turn, radius, size.width, size.height)\n    const clear = standsClear(box, kept)\n    if (clear) kept.push(box)\n    return clear\n  })\n}\n\n/** Where a point of an outline sits, in px, round a centre `cx`, `cy` with the edge `edge` px out. */\nfunction pointOf(vertex: RadarVertex, cx: number, cy: number, edge: number) {\n  const angle = vertex.turn * Math.PI * 2\n  const out = vertex.r * edge\n  return [cx + out * Math.sin(angle), cy - out * Math.cos(angle)] as const\n}\n\n/** An outline as a closed SVG path round a centre `cx`, `cy`, with the edge `edge` px out. */\nfunction outlinePath(\n  outline: readonly RadarVertex[],\n  cx: number,\n  cy: number,\n  edge: number,\n): string {\n  if (outline.length === 0) return ''\n  return `${outline\n    .map((vertex, at) => {\n      const [x, y] = pointOf(vertex, cx, cy, edge)\n      return `${at === 0 ? 'M' : 'L'}${round(x)} ${round(y)}`\n    })\n    .join('')}Z`\n}\n\n/**\n * The side a tooltip opens on past an axis's name at `turn`: outward, so it\n * covers neither the name nor the shapes; beside the name for the axes at\n * the sides, above or below it for those at the top and bottom.\n */\nfunction nameSide(turn: number): 'top' | 'bottom' | 'left' | 'right' {\n  const angle = turn * Math.PI * 2\n  const sin = Math.sin(angle)\n  if (Math.abs(sin) > Math.SQRT1_2) return sin > 0 ? 'right' : 'left'\n  return tooltipSide(turn)\n}\n\n/** The axis nearest `turn`, among `count` axes evenly round from the top. */\nfunction axisAt(turn: number, count: number): number | null {\n  if (count === 0) return null\n  return Math.round((((turn % 1) + 1) % 1) * count) % count\n}\n\n/** `target`, a turn from 0 to 1, as the turn nearest `from` that lands on it, whole turns apart. */\nfunction nearestTurn(from: number, target: number) {\n  const delta = ((((target - from) % 1) + 1.5) % 1) - 0.5\n  return from + delta\n}\n\n/**\n * How far out an outline is at `turn`, as a fraction of the edge: where a\n * line from the centre at that turn crosses it, between the two points\n * either side of it. Nothing to cross is the centre.\n */\nfunction outlineRadius(outline: readonly RadarVertex[], turn: number): number {\n  if (outline.length === 0) return 0\n  if (outline.length === 1) return 0\n  const sorted = outline.toSorted((a, b) => a.turn - b.turn)\n  const at = ((turn % 1) + 1) % 1\n  let after = sorted.findIndex((vertex) => vertex.turn > at)\n  if (after === -1) after = 0\n  const a = sorted[(after - 1 + sorted.length) % sorted.length]!\n  const b = sorted[after]!\n  const [ax, ay] = pointOf(a, 0, 0, 1)\n  const [bx, by] = pointOf(b, 0, 0, 1)\n  const angle = at * Math.PI * 2\n  const dx = Math.sin(angle)\n  const dy = -Math.cos(angle)\n  const ex = bx - ax\n  const ey = by - ay\n  const across = dx * ey - dy * ex\n  // The line runs along the edge: the nearer of its ends.\n  if (Math.abs(across) < 1e-12) return Math.max(a.r, b.r)\n  return Math.max(0, (ax * ey - ay * ex) / across)\n}\n\n/**\n * Matches the points of an outline drawn now, `from`, with those it moves\n * to: a point on an axis in both moves along its spoke; one on an axis that\n * arrives starts on the old outline at its own turn, so it grows out of it;\n * and one on an axis that leaves ends on the new outline at its turn, so it\n * folds into it. In the order they are drawn round, those that leave beside\n * the point before them.\n */\nfunction alignOutlines(\n  from: readonly RadarVertex[],\n  to: readonly RadarVertex[],\n): VertexMove[] {\n  const after = new Map(to.map((vertex) => [vertex.key, vertex] as const))\n  const before = new Map(from.map((vertex) => [vertex.key, vertex] as const))\n  const order = to.map((vertex) => vertex.key)\n  // Those that leave go in after the point before them that stays, or first.\n  for (const [at, vertex] of from.entries()) {\n    if (after.has(vertex.key)) continue\n    let anchor = -1\n    for (let back = at - 1; back >= 0 && anchor === -1; back--) {\n      anchor = order.indexOf(from[back]!.key)\n    }\n    order.splice(anchor + 1, 0, vertex.key)\n  }\n  return order.map((key) => {\n    const target = after.get(key)\n    const source = before.get(key)\n    if (target && source) return { key, from: source, to: target }\n    if (target) {\n      return {\n        key,\n        from: { turn: target.turn, r: outlineRadius(from, target.turn) },\n        to: target,\n      }\n    }\n    return {\n      key,\n      from: source!,\n      to: { turn: source!.turn, r: outlineRadius(to, source!.turn) },\n    }\n  })\n}\n\n/** The outline `progress` of the way through `moves`, each point turning the short way round. */\nfunction outlineAt(moves: readonly VertexMove[], progress: number): RadarVertex[] {\n  return moves.map((move) => {\n    const turn = nearestTurn(move.from.turn, move.to.turn)\n    return {\n      key: move.key,\n      turn: move.from.turn + (turn - move.from.turn) * progress,\n      r: move.from.r + (move.to.r - move.from.r) * progress,\n    }\n  })\n}\n\n/**\n * The series the Up or Down arrow brings forward from `from` on one axis:\n * Up the next further out, Down the next further in, and past either end\n * every series again. From none, Up the furthest out and Down the furthest\n * in. A series with no value there is skipped.\n */\nfunction stepOutward(\n  values: readonly { key: string; value: number | null }[],\n  from: string | null,\n  step: -1 | 1,\n): string | null {\n  const order = values\n    .filter((item): item is { key: string; value: number } => item.value !== null)\n    .toSorted((a, b) => b.value - a.value)\n    .map((item) => item.key)\n  return stepThrough(order, from, step)\n}\n\nexport {\n  alignOutlines,\n  axisAt,\n  fitNames,\n  nameSide,\n  nearestTurn,\n  outlineAt,\n  outlinePath,\n  outlineRadius,\n  namesToFit,\n  Radar,\n  RadarAxis,\n  type RadarAxisProps,\n  RadarChart,\n  type RadarChartProps,\n  RadarGrid,\n  type RadarProps,\n  RadarValueAxis,\n  type RadarVertex,\n  radarExtent,\n  radarFit,\n  type RadarPartDeclaration,\n  stepOutward,\n  thinTicks,\n  wrapWords,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/radar-chart.tsx"
    }
  ],
  "type": "registry:component"
}