{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bump-chart",
  "title": "Bump chart",
  "description": "Ranks over time, one line per item, crossing where one overtakes another: ranks as given, or worked out from amounts, highest or lowest first, with names and ranks at both ends and gaps where an item has no rank. The line under the pointer, or the one the Up and Down arrows reach, stays bright end to end while the rest step back, and new ranks move every line from where it is.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/chart-line-marks.json",
    "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-line.json",
    "https://kinoui.com/r/chart-math.json",
    "https://kinoui.com/r/cut.json",
    "https://kinoui.com/r/line-path.json",
    "https://kinoui.com/r/number-format.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/bump-chart.tsx",
      "content": "'use client'\n\nimport {\n  axisLayerClassName,\n  type CategoryChartProps,\n  figureProps,\n  seriesWords,\n  slideLine,\n  useDeclared,\n} from '@/registry/lib/chart-base'\nimport {\n  cartesianChartKeys,\n  cartesianSignature,\n  type CartesianStop,\n  cartesianTable,\n  cartesianWords,\n  type ChartPartDeclaration,\n  useCartesian,\n  useCartesianChart,\n} from '@/registry/lib/chart-cartesian'\nimport {\n  framePoints,\n  frameRest,\n  frameTop,\n  LineFamilyFrame,\n  LinePlaceholder,\n  LineSeries,\n  type LineSeriesProps,\n  useLineFamily,\n} from '@/registry/lib/chart-line'\nimport { lineMarks } from '@/registry/lib/chart-line-marks'\nimport {\n  type ChartDatum,\n  numberOf,\n  plotPoint,\n  stepThrough,\n} from '@/registry/lib/chart-math'\nimport {\n  ChangeText,\n  type ChartItem,\n  type ChartMessages,\n  defaultMessages,\n  forcedSeriesColor,\n  swatchClassName,\n  swatchStyle,\n  tooltipQuietClassName,\n  type MoveRun,\n  useChartMoves,\n} from '@/registry/lib/chart-root'\nimport type { LinearScale } from '@/registry/lib/chart-scale'\nimport { CutTooltip } from '@/registry/lib/cut'\nimport { heightAt, type LinePoint } from '@/registry/lib/line-path'\nimport { numberFormatter } from '@/registry/lib/number-format'\nimport {\n  type ComponentProps,\n  createContext,\n  type CSSProperties,\n  type ReactNode,\n  use,\n  useLayoutEffect,\n  useMemo,\n  useRef,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * The Bump chart: ranks over time, one line per item, crossing where one\n * overtakes another. Rank 1 is the top row and each rank has a row of its\n * own. Its lines, their moves and their dots come from the chart line lib,\n * which the Line chart shares, drawn as S-curves that leave each period\n * level. The line under the pointer, or the one the Up and Down arrows\n * reach, stays bright from end to end while the rest step back, and a new\n * range or new ranks move every line from where it is.\n */\n\n/**\n * What the values in the data are: ranks already, 1 the top, or amounts\n * the chart ranks in each period, the highest first or the lowest first.\n */\ntype BumpRankBy = 'given' | 'highest' | 'lowest'\n\n/** Every word the Bump chart says or reads out, beyond what every chart says. */\ninterface BumpChartMessages extends ChartMessages {\n  /** A rank, as a screen reader hears it, with the rank written: \"rank 2\". */\n  rank: (rank: number, written: string) => string\n  /** A move since the period before, `places` up when positive, with its size written: \"up 2 places\". */\n  moved: (places: number, written: string) => string\n  /** Said of an item with no rank in a period. */\n  unranked: string\n}\n\nconst bumpMessages = {\n  rank: (_rank: number, written: string) => `rank ${written}`,\n  moved: (places: number, written: string) => {\n    const size = `${written} ${Math.abs(places) === 1 ? 'place' : 'places'}`\n    return places > 0 ? `up ${size}` : places < 0 ? `down ${size}` : 'no change'\n  },\n  unranked: 'not ranked',\n} satisfies Partial<BumpChartMessages>\n\ninterface BumpChartProps extends Omit<\n  CategoryChartProps,\n  | 'domain'\n  | 'tickCount'\n  | 'tickValues'\n  | 'allowDecimals'\n  | 'patterns'\n  | 'messages'\n  | 'ordered'\n> {\n  /**\n   * What the values in the data are: ranks already, 1 the top, the default;\n   * or amounts ranked in each period, the highest first or the lowest first.\n   * Equal amounts share a rank, and the next rank is skipped (1, 1, 3).\n   */\n  rankBy?: BumpRankBy\n  /**\n   * How the lines arrive the first time the chart comes into view: drawn\n   * along from the reading start, or simply there, the default, since a page\n   * that loads doesn't animate into place.\n   */\n  entrance?: 'draw' | 'none'\n  /** Every word the chart says or reads out, for a chart in another language. */\n  messages?: Partial<BumpChartMessages>\n}\n\nconst bumpChartKeys = [...cartesianChartKeys, 'rankBy', 'entrance']\n\n/** Each period's ranks, and the row each series sits on. */\ninterface BumpRanking {\n  /** Each row with every series' rank, as given or worked out from its amount; null with none. */\n  ranks: ChartDatum[]\n  /**\n   * Each row with every series' row on the chart, 1 the top: in the order\n   * of their ranks, a series sharing a rank on the next row free, so no two\n   * lines lie on each other, and no row that no series reaches.\n   */\n  places: ChartDatum[]\n}\n\n/**\n * The ranks of each row: as given, or by amount, the highest or the lowest\n * first, equal amounts sharing a rank and the next rank skipped (1, 1, 3). A\n * missing value, or a given rank below 1, has none. Each series gets a row\n * of its own as well: series sharing a rank take the rows from it down, in\n * the order they held in the row before, so lines cross no more than they\n * must, and then in the order of `keys`. A row no series reaches in any\n * period is left out, so three songs in a top 100 take three rows, not 100.\n */\nfunction bumpRanks(\n  rows: readonly ChartDatum[],\n  keys: readonly string[],\n  rankBy: BumpRankBy,\n): BumpRanking {\n  const ranks: ChartDatum[] = []\n  const places: ChartDatum[] = []\n  rows.forEach((row, at) => {\n    const values = keys.map((key) => numberOf(row[key]))\n    const ranked: ChartDatum = { ...row }\n    keys.forEach((key, slot) => {\n      const value = values[slot] ?? null\n      if (value === null) ranked[key] = null\n      else if (rankBy === 'given') ranked[key] = value >= 1 ? Math.round(value) : null\n      else {\n        const ahead = values.filter(\n          (other) =>\n            other !== null && (rankBy === 'highest' ? other > value : other < value),\n        ).length\n        ranked[key] = ahead + 1\n      }\n    })\n    const before = places[at - 1]\n    const order = keys\n      .filter((key) => numberOf(ranked[key]) !== null)\n      .toSorted(\n        (a, b) =>\n          (numberOf(ranked[a]) ?? 0) - (numberOf(ranked[b]) ?? 0) ||\n          (numberOf(before?.[a]) ?? Infinity) - (numberOf(before?.[b]) ?? Infinity) ||\n          keys.indexOf(a) - keys.indexOf(b),\n      )\n    const placed: ChartDatum = { ...row }\n    for (const key of keys) placed[key] = null\n    let last = 0\n    for (const key of order) {\n      last = Math.max(numberOf(ranked[key]) ?? 0, last + 1)\n      placed[key] = last\n    }\n    ranks.push(ranked)\n    places.push(placed)\n  })\n  const reached = [\n    ...new Set(places.flatMap((row) => keys.map((key) => numberOf(row[key])))),\n  ]\n    .filter((place) => place !== null)\n    .toSorted((a, b) => a - b)\n  const dense = new Map(reached.map((place, at) => [place, at + 1]))\n  for (const row of places) {\n    for (const key of keys) {\n      const place = numberOf(row[key])\n      if (place !== null) row[key] = dense.get(place) ?? null\n    }\n  }\n  return { ranks, places }\n}\n\n/** How many rows the chart has: the lowest any series sits on in any row, at least 1. */\nfunction rankCount(rows: readonly ChartDatum[], keys: readonly string[]): number {\n  let count = 1\n  for (const row of rows) {\n    for (const key of keys) count = Math.max(count, numberOf(row[key]) ?? 1)\n  }\n  return count\n}\n\n/** How many places a series moved since the period before, up when positive; null with no rank in either. */\nfunction rankMove(before: unknown, now: unknown): number | null {\n  const was = numberOf(before)\n  const is = numberOf(now)\n  return was === null || is === null ? null : was - is\n}\n\n/** The series with a row in `row`, from the top. */\nfunction rankOrder(row: ChartDatum, keys: readonly string[]): string[] {\n  return keys\n    .filter((key) => numberOf(row[key]) !== null)\n    .toSorted((a, b) => (numberOf(row[a]) ?? 0) - (numberOf(row[b]) ?? 0))\n}\n\n/**\n * The series a step up (-1) or down (1) the rows of `row` from `from`,\n * kept at the ends; from none, or from one not ranked there, the top one.\n */\nfunction stepRank(\n  row: ChartDatum,\n  keys: readonly string[],\n  from: string | null,\n  step: -1 | 1,\n): string | null {\n  return stepThrough(rankOrder(row, keys), from, step)\n}\n\n/**\n * The series whose line passes nearest a point of the plot, as fractions of\n * it from the reading start and the top, among `lines` drawn as bumps; null\n * where none is drawn.\n */\nfunction nearestLine(\n  lines: readonly { key: string; points: readonly LinePoint[] }[],\n  point: { x: number; y: number },\n): string | null {\n  let nearest: string | null = null\n  let distance = Infinity\n  for (const line of lines) {\n    const y = heightAt(line.points, 'bump', point.x)\n    if (y === null || Math.abs(y - point.y) >= distance) continue\n    nearest = line.key\n    distance = Math.abs(y - point.y)\n  }\n  return nearest\n}\n\n/** Where a row sits, as a fraction of the plot from its top: its middle. */\nfunction rowOf(place: number, scale: LinearScale) {\n  return 1 - scale.place(place)\n}\n\n/** What the Bump chart's own parts read: each series' row, rank and amount in a period, and its words. */\ninterface BumpContextValue {\n  /** The row each series sits on in a period, from 1 at the top, by its key. */\n  placesOf: (period: CartesianStop) => ChartDatum\n  rankOf: (period: CartesianStop, key: string) => number | null\n  /** The amount a series was ranked by, or null when the ranks were given. */\n  amountOf: (period: CartesianStop, key: string) => number | null\n  /** A rank or a number of places, written in the chart's locale. */\n  rankText: (rank: number) => string\n  messages: BumpChartMessages\n}\n\nconst BumpContext = createContext<BumpContextValue | null>(null)\n\nfunction useBump() {\n  const bump = use(BumpContext)\n  if (!bump) throw new Error('`BumpNames` goes inside a `BumpChart`.')\n  return bump\n}\n\n/** The legend's keys are plain swatches. */\nfunction noMarker() {\n  return null\n}\n\n/**\n * The chart's root: it lays out the frame its parts draw in, places each\n * period along the plot from edge to edge and gives each rank a row, rank 1\n * at the top. The plot is at least a row's height for each rank,\n * `--bump-chart-row`, so names never crowd; a height of yours that is\n * taller spreads the rows.\n */\nfunction BumpChart(props: BumpChartProps) {\n  const {\n    data,\n    index,\n    config,\n    rankBy = 'given',\n    entrance = 'none',\n    messages,\n    description,\n    empty,\n    className,\n    style,\n    children,\n    ref,\n  } = props\n  const keys = Object.keys(config)\n  const keyList = keys.join('\\u0000')\n  // Ranked once per change of the data, so the chart sees the same rows from render to render.\n  const ranking = useMemo(\n    () => bumpRanks(data, keyList.split('\\u0000'), rankBy),\n    [data, keyList, rankBy],\n  )\n  // Every series counts, the hidden ones too, so hiding one never moves the rows.\n  const rows = rankCount(ranking.places, keys)\n  const said: BumpChartMessages = { ...defaultMessages, ...bumpMessages, ...messages }\n  const made = useCartesianChart(\n    {\n      ...props,\n      // The chart places each series on its row; its rank and amount are looked up by period.\n      data: ranking.places,\n      // Rank 1 at the top: the axis runs from the last row's bottom edge up to the first's top.\n      domain: [rows + 0.5, 0.5],\n      tickValues: Array.from({ length: rows }, (_, at) => at + 1),\n      messages,\n    },\n    {\n      kinds: [lineMarks],\n      orientation: 'vertical',\n      stack: 'none',\n      entrance: entrance !== 'none',\n      // The lines grow from the bottom row's edge, so one drawn in rises from below every rank.\n      y: { nice: false, zero: false, base: rows + 0.5 },\n    },\n  )\n  const { model, placeholder, phase } = made\n  // A line has no fill to pattern, so its key in the legend and the tooltip stays solid too.\n  const chart = { ...made.chart, patternOf: () => 'solid' as const }\n  const byPeriod = useMemo(() => {\n    const out = new Map<string, { rank: ChartDatum; amount: ChartDatum }>()\n    data.forEach((row, at) => {\n      out.set(String(row[index]), { rank: ranking.ranks[at] ?? {}, amount: row })\n    })\n    return out\n  }, [data, index, ranking])\n  const bump: BumpContextValue = {\n    // The chart draws each series on its row, so its value at a period is its row there.\n    placesOf: (period) =>\n      Object.fromEntries(keys.map((key) => [key, chart.valueOf(key, period)])),\n    rankOf: (period, key) => numberOf(byPeriod.get(period.key)?.rank[key]),\n    amountOf: (period, key) =>\n      rankBy === 'given' ? null : numberOf(byPeriod.get(period.key)?.amount[key]),\n    rankText: (rank) => numberFormatter(chart.locale).format(rank),\n    messages: said,\n  }\n  const shown = chart.series.filter((key) => !chart.hidden.includes(key))\n  // A period a series has no rank in leaves a gap; a hidden line fades where it is.\n  const pointsOf = (key: string) => framePoints(chart, model, key, false, false)\n  const labelOf = (key: string) => {\n    const label = config[key]?.label\n    return typeof label === 'string' ? label : key\n  }\n  // What each item says for a period: its rank, its move since the period before and, ranked\n  // by amount, the amount.\n  const itemText = (key: string, period: CartesianStop) => {\n    const rank = bump.rankOf(period, key)\n    if (rank === null) return `${labelOf(key)}, ${said.unranked}`\n    const before = chart.current[period.index - 1]\n    const move = before ? rankMove(bump.rankOf(before, key), rank) : null\n    const amount = bump.amountOf(period, key)\n    return [\n      labelOf(key),\n      said.rank(rank, bump.rankText(rank)),\n      move === null ? null : said.moved(move, bump.rankText(Math.abs(move))),\n      amount === null ? null : chart.valueText(amount),\n    ]\n      .filter(Boolean)\n      .join(', ')\n  }\n  const byKey = new Map(chart.current.map((period) => [period.key, period]))\n  // The series brought forward alone, so Up and Down are heard to move; with none, every ranked\n  // one, best first.\n  const periodText = (item: ChartItem) => {\n    const period = byKey.get(item.key)\n    if (!period) return ''\n    if (chart.emphasis !== null && shown.includes(chart.emphasis)) {\n      return itemText(chart.emphasis, period)\n    }\n    return rankOrder(bump.placesOf(period), shown)\n      .map((key) => itemText(key, period))\n      .join('; ')\n  }\n  const words = {\n    ...seriesWords(chart, cartesianWords(chart, { name: '', text: periodText })),\n    tooltip: (item: ChartItem) => <BumpTooltipContent index={item.index} />,\n    table: cartesianTable(chart, shown.map(labelOf), (period) =>\n      shown.map((key) => {\n        const rank = bump.rankOf(period, key)\n        const amount = bump.amountOf(period, key)\n        if (rank === null) return said.unranked\n        return amount === null\n          ? said.rank(rank, bump.rankText(rank))\n          : `${said.rank(rank, bump.rankText(rank))}, ${chart.valueText(amount)}`\n      }),\n    ),\n  }\n  return (\n    <BumpContext value={bump}>\n      <LineFamilyFrame\n        chart={{ ...made, chart }}\n        markerOf={noMarker}\n        // The tooltip sits over the period's top point, so it covers no line.\n        anchor={(period) =>\n          plotPoint(\n            period.band,\n            model.reach(period.index) ?? 1,\n            'vertical',\n            chart.direction,\n          )\n        }\n        words={words}\n        // The pointer brings forward the line nearest it, and Up and Down step through the ranks.\n        browse={{\n          kind: 'x-series',\n          seriesAt: (point) =>\n            nearestLine(\n              shown.map((key) => ({ key, points: pointsOf(key) })),\n              point,\n            ),\n          step: (at, from, step) => {\n            const period = chart.current[at]\n            return period ? stepRank(bump.placesOf(period), shown, from, step) : null\n          },\n        }}\n        family={{\n          name: 'bump-chart',\n          phase,\n          entrance,\n          pointsOf,\n          topOf: (key, period) => frameTop(model, key, period),\n          restOf: (key) => frameRest(model, key),\n        }}\n        description={description}\n        empty={empty}\n        placeholder={placeholder && <LinePlaceholder name='bump-chart' fill={false} />}\n        // Each rank's row is at least `--bump-chart-row` tall; the chart is as tall as its rows,\n        // unless a height of yours spreads them.\n        className={cn(\n          'h-auto grid-rows-[auto_auto_minmax(calc(var(--bump-rows)*var(--bump-chart-row,2rem)),1fr)_auto_auto]',\n          className,\n        )}\n        style={{ '--bump-rows': rows, ...style } as CSSProperties}\n        ref={ref}\n        {...figureProps(props, [...bumpChartKeys, 'style'])}\n      >\n        {children}\n      </LineFamilyFrame>\n    </BumpContext>\n  )\n}\n\n/**\n * The tooltip of a period: every shown item, best first, with its rank, its\n * move since the period before and, ranked by amount, its amount. The item\n * brought forward reads in full, the rest a step back.\n */\nfunction BumpTooltipContent({ index }: { index: number }) {\n  const chart = useCartesian()\n  const { placesOf, rankOf, amountOf, rankText } = useBump()\n  const { id, current, series, hidden, config, stopText, valueText, emphasis, locale } =\n    chart\n  const period = current[index]\n  if (!period) return null\n  const before = current[index - 1]\n  const shown = series.filter((key) => !hidden.includes(key))\n  return (\n    // The tooltip sits outside the chart, so it carries the chart's id for its colours.\n    <div data-chart={id} className='grid min-w-40 gap-1'>\n      <div className='font-medium'>{stopText(period)}</div>\n      {/* One grid, so each column lines up from row to row. */}\n      <div className='grid grid-cols-[auto_auto_minmax(0,1fr)_auto_auto] items-center gap-x-2 gap-y-1'>\n        {rankOrder(placesOf(period), shown).map((key) => {\n          const rank = rankOf(period, key)\n          const move = before ? rankMove(rankOf(before, key), rank) : null\n          const amount = amountOf(period, key)\n          return (\n            // The item brought forward reads in full colour; the rest stay as they are, legible.\n            <div\n              key={key}\n              data-lit={emphasis === key ? '' : undefined}\n              className='group/row col-span-full grid grid-cols-subgrid items-center'\n            >\n              <span className={cn(tooltipQuietClassName, 'text-end tabular-nums')}>\n                {rank === null ? null : rankText(rank)}\n              </span>\n              <span\n                aria-hidden\n                className={cn(swatchClassName, forcedSeriesColor(series.indexOf(key)))}\n                style={swatchStyle(key, 'solid')}\n              />\n              <span className={cn(tooltipQuietClassName, 'min-w-0 truncate')}>\n                {config[key]?.label ?? key}\n              </span>\n              {/* A move up or down, in places; none says nothing. */}\n              <ChangeText\n                change={move === 0 ? null : move}\n                locale={locale}\n                format={rankText}\n                className={cn(tooltipQuietClassName, 'text-end')}\n              />\n              <span dir='auto' className='text-end font-medium tabular-nums'>\n                {amount === null ? null : valueText(amount)}\n              </span>\n            </div>\n          )\n        })}\n      </div>\n    </div>\n  )\n}\n\ntype BumpProps = Omit<\n  LineSeriesProps,\n  'curve' | 'dots' | 'dashed' | 'forecastFrom' | 'connectNulls'\n> & {\n  /** Marks each period's rank with a dot; off draws the line alone, for a long run of periods. */\n  dots?: boolean\n}\n\n/**\n * One item's line, in its colour, through its rank in each period: a dot on\n * each, an S from one to the next, and a gap where it has no rank. While\n * another item is brought forward, it steps back.\n */\nfunction Bump({ dots = true, ...props }: BumpProps) {\n  useDeclared('Bump', Bump.declare(props), cartesianSignature)\n  return <LineSeries {...props} curve='bump' dots={dots} />\n}\n\nBump.declare = ({ dataKey }: BumpProps): ChartPartDeclaration => ({\n  series: { key: dataKey, mark: 'line' },\n})\n\n/**\n * Each item's name at one end of its line: its rank in the first period\n * beside the plot's start, or with `side='end'`, in the last beside its\n * end, with the rank between the name and the line. The names glide to new\n * ranks with the lines. The item brought forward reads in full while the\n * rest step back, and pointing at a name brings its item forward.\n */\nfunction BumpNames({\n  side = 'start',\n  className,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & { side?: 'start' | 'end' }) {\n  const {\n    current,\n    series,\n    hidden,\n    config,\n    frame,\n    status,\n    emphasis,\n    setEmphasis,\n    entered,\n  } = useCartesian()\n  const { scale } = frame.y.value\n  const { placesOf, rankOf, rankText } = useBump()\n  const family = useLineFamily()\n  const period = side === 'start' ? current[0] : current.at(-1)\n  // Where each name last sat, so one that loses its rank fades where it was.\n  const [places, setPlaces] = useState<Record<string, number>>({})\n  const now: Record<string, number> = {}\n  for (const key of series) {\n    const place = period ? numberOf(placesOf(period)[key]) : null\n    if (place !== null) now[key] = rowOf(place, scale)\n  }\n  if (Object.entries(now).some(([key, place]) => places[key] !== place)) {\n    setPlaces({ ...places, ...now })\n  }\n  const ready = status === 'ready'\n  const labelOf = (key: string): ReactNode => config[key]?.label ?? key\n  const last = current.at(-1)\n  const namedAtEnd = (key: string) => !!last && numberOf(placesOf(last)[key]) !== null\n  return (\n    <div\n      data-slot='bump-chart-names'\n      data-side={side}\n      // With the lines drawn in, the end's names wait for the lines to reach them.\n      data-held={\n        side === 'end' && family.entrance === 'draw' && !entered ? '' : undefined\n      }\n      aria-hidden\n      // The ranks take the width of the longest, so the names beside them line up.\n      style={{ '--bump-rank': `${String(scale.ticks.length).length}ch` } as CSSProperties}\n      className={cn(\n        'text-muted-foreground relative grid min-h-0 min-w-0 transition-opacity delay-[calc(var(--motion-draw-duration)*0.5)] duration-[calc(var(--motion-draw-duration)*0.5)] ease-(--motion-draw-fade-easing) select-none data-held:opacity-0',\n        side === 'start'\n          ? 'pe-2.5 [grid-area:start-axis]'\n          : 'ps-2.5 [grid-area:end-axis]',\n        className,\n      )}\n      {...props}\n    >\n      {/*\n        The longest name holds the column open, up to its cap; the names\n        themselves are placed. A pixel over it, since a track rounds a name's\n        fractional width down and would cut it by a hair.\n      */}\n      <span className='invisible col-start-1 row-start-1 grid'>\n        {series.map((key) => (\n          <span key={key} className='col-start-1 row-start-1 flex max-w-[28cqw] gap-1.5'>\n            <span\n              className={cn(\n                'min-w-0 overflow-hidden pe-px font-medium',\n                side === 'start' && namedAtEnd(key) && startNamesNarrow,\n              )}\n            >\n              {labelOf(key)}\n            </span>\n            <span className='w-(--bump-rank) shrink-0' />\n          </span>\n        ))}\n      </span>\n      <span className={axisLayerClassName}>\n        {/* Each row's rank, beside the plot: it stays in its row while names glide past it. */}\n        {scale.ticks.map((row) => {\n          const key = series.find(\n            (key) =>\n              period && numberOf(placesOf(period)[key]) === row && !hidden.includes(key),\n          )\n          const rank = key === undefined || !period ? null : rankOf(period, key)\n          return (\n            <span\n              key={row}\n              data-gone={ready && rank !== null ? undefined : ''}\n              data-lit={emphasis !== null && emphasis === key ? '' : undefined}\n              className={cn(\n                slideLine.y,\n                'transition-[color,opacity] duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) data-gone:opacity-0 data-lit:text-foreground forced-colors:text-[CanvasText]',\n              )}\n              style={{ translate: `0 ${rowOf(row, scale) * 100}cqh` }}\n            >\n              <span\n                className={cn(\n                  'absolute top-0 w-(--bump-rank) -translate-y-1/2 text-end tabular-nums',\n                  side === 'start' ? nameInset.start : nameInset.end,\n                )}\n              >\n                {rank === null ? null : rankText(rank)}\n              </span>\n            </span>\n          )\n        })}\n        {series.map((key) => {\n          const place = now[key] ?? places[key]\n          if (place === undefined) return null\n          const there = ready && key in now && !hidden.includes(key)\n          return (\n            <NameSlide\n              key={key}\n              at={place}\n              data-gone={there ? undefined : ''}\n              className={cn(side === 'start' && namedAtEnd(key) && startNamesNarrow)}\n            >\n              <CutTooltip\n                render={\n                  <span\n                    data-dim={emphasis !== null && emphasis !== key ? '' : undefined}\n                    onPointerEnter={() => {\n                      if (there) setEmphasis(key)\n                    }}\n                    onPointerLeave={() => setEmphasis(null)}\n                    className={cn(\n                      'text-foreground data-dim:text-muted-foreground absolute top-0 flex -translate-y-1/2 font-medium whitespace-nowrap transition-colors duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) forced-colors:text-[CanvasText]',\n                      // The name takes the pointer from the plot's edge, over its rank.\n                      side === 'start' ? nameInset.startReach : nameInset.endReach,\n                      side === 'start' ? nameInset.startName : nameInset.endName,\n                      // The layer lets the pointer through; a name that shows takes it.\n                      there && 'pointer-events-auto',\n                    )}\n                  >\n                    <span data-cut className='truncate'>\n                      {labelOf(key)}\n                    </span>\n                  </span>\n                }\n              />\n            </NameSlide>\n          )\n        })}\n      </span>\n    </div>\n  )\n}\n\n/** The number a name glides on, from 0 where it was to 1 where it goes, written each frame of the chart's move, as a line's points are. */\nconst NAME_PROGRESS = '--bump-name-progress'\n\n/**\n * One name's row, `at` a fraction of the plot from its top. A new row\n * glides it there from where it shows, on the same role, start and length\n * as the lines' move, so a move cut short turns both back alike and the\n * name stays on its line's end.\n */\nfunction NameSlide({\n  at,\n  className,\n  style,\n  ...props\n}: Omit<ComponentProps<'span'>, 'children'> & { at: number; children: ReactNode }) {\n  const ref = useRef<HTMLSpanElement>(null)\n  const moves = useChartMoves()\n  const glide = useRef<NameGlide>({ from: at, to: at, run: null, stop: () => {} })\n  useLayoutEffect(() => {\n    const element = ref.current\n    const was = glide.current\n    if (!element || at === was.to) return\n    // From where it shows now, mid-glide too.\n    const shown =\n      was.from + (was.to - was.from) * (was.run?.running() ? was.run.progress() : 1)\n    was.stop()\n    element.style.setProperty('--name-from', `${shown * 100}cqh`)\n    const write = (progress: number) =>\n      element.style.setProperty(NAME_PROGRESS, String(progress))\n    // On a chart not yet painted, it is there at once.\n    if (!element.closest('[data-mounted]')) {\n      write(1)\n      glide.current = { from: shown, to: at, run: null, stop: () => {} }\n      return\n    }\n    write(0)\n    const { run, stop } = moves.follow('layout', write, 1)\n    glide.current = { from: shown, to: at, run, stop }\n  }, [at, moves])\n  useLayoutEffect(() => () => glide.current.stop(), [])\n  return (\n    <span\n      ref={ref}\n      className={cn(\n        slideLine.y,\n        '[translate:0_calc(var(--name-from,var(--name-to))+(var(--name-to)-var(--name-from,var(--name-to)))*var(--bump-name-progress,1))] transition-none group-data-mounted/chart:transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) data-gone:opacity-0',\n        className,\n      )}\n      style={{ '--name-to': `${at * 100}cqh`, ...style } as CSSProperties}\n      {...props}\n    />\n  )\n}\n\n/** A name's glide: from where it was, to where it goes, on its run of the chart's moves. */\ninterface NameGlide {\n  from: number\n  to: number\n  run: MoveRun | null\n  stop: () => void\n}\n\n/**\n * In a chart as narrow as a phone's, names at both ends would leave the\n * lines little room: with names at the end too, the start keeps its ranks\n * and names only the lines that don't reach the end.\n */\nconst startNamesNarrow =\n  '@max-[20rem]/chart:group-has-[[data-slot=bump-chart-names][data-side=end]]/chart:hidden'\n\n/**\n * Where the ranks and the names sit in their column: the ranks clear of a\n * line's end dot, which reaches 0.25rem past the plot, and the names past\n * the ranks, as wide as the column leaves them.\n */\nconst nameInset = {\n  start: 'end-2.5',\n  end: 'start-2.5',\n  startName: 'end-[calc(1rem+var(--bump-rank))] max-w-[calc(100%-1rem-var(--bump-rank))]',\n  endName: 'start-[calc(1rem+var(--bump-rank))] max-w-[calc(100%-1rem-var(--bump-rank))]',\n  startReach:\n    'before:absolute before:inset-y-0 before:start-0 before:-end-[calc(1rem+var(--bump-rank))]',\n  endReach:\n    'before:absolute before:inset-y-0 before:end-0 before:-start-[calc(1rem+var(--bump-rank))]',\n} as const\n\nexport {\n  Bump,\n  BumpChart,\n  type BumpChartMessages,\n  type BumpChartProps,\n  BumpNames,\n  type BumpProps,\n  type BumpRankBy,\n  bumpRanks,\n  nearestLine,\n  rankCount,\n  rankMove,\n  rankOrder,\n  stepRank,\n}\n",
      "type": "registry:component",
      "target": "@components/kino/bump-chart.tsx"
    }
  ],
  "type": "registry:component"
}