{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chart-points",
  "title": "Chart points",
  "description": "What the charts drawn as points share: each series’ shape, a point that glides, grows in and shrinks away, and a series’ layer of points that steps back while one is lit and shows that one bright above it. The Scatter chart and the Composed chart draw with it.",
  "registryDependencies": [
    "https://kinoui.com/r/chart-core.json",
    "https://kinoui.com/r/chart-frame.json",
    "https://kinoui.com/r/chart-root.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/chart-points.tsx",
      "content": "'use client'\n\nimport { plotOffset } from '@/registry/lib/chart-base'\nimport { markLayer } from '@/registry/lib/chart-frame'\nimport {\n  forcedSeriesTextColor,\n  plotLayerClassName,\n  seriesColor,\n  stepBackLayerClassName,\n} from '@/registry/lib/chart-root'\nimport {\n  type ComponentProps,\n  type CSSProperties,\n  memo,\n  type ReactNode,\n  useState,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * What the charts drawn as points share: each series' shape, a point that\n * glides, grows in and shrinks away, and a series' layer of points, which\n * steps back while one is lit and shows that one bright above it. The\n * Scatter chart's points and the Composed chart's draw with it.\n */\n\n/**\n * The shapes each series' points take, in series order, as SVG paths in a\n * box 2 across: shapes of about the same weight, told apart at a glance and\n * in grey.\n */\nconst markers = [\n  // A circle.\n  'M1,0A1,1,0,1,1,-1,0A1,1,0,1,1,1,0Z',\n  // A square.\n  'M-0.85,-0.85H0.85V0.85H-0.85Z',\n  // A triangle, pointing up, centred on its height.\n  'M0,-0.975L1.126,0.975H-1.126Z',\n  // A diamond.\n  'M0,-1.15L1.15,0L0,1.15L-1.15,0Z',\n  // A plus.\n  'M-0.36,-1H0.36V-0.36H1V0.36H0.36V1H-0.36V0.36H-1V-0.36H-0.36Z',\n] as const\n\n/** The shape of the series at `slot`: the five in turn. */\nfunction markerAt(slot: number): string {\n  return markers[slot % markers.length]!\n}\n\n/**\n * One point: placed by `x` and `y`, fractions of the plot from its left\n * and top, and drawn as the series' shape at `radius` px. It glides to a\n * new place, grows in as it arrives and shrinks away as it leaves; a\n * `still` one, the lit point's copy, is simply there. Memoised, so lighting\n * a point redraws none of them.\n */\nconst PointMark = memo(function PointMark({\n  x,\n  y,\n  radius,\n  marker,\n  slot,\n  depth,\n  leaving,\n  still = false,\n}: {\n  x: number\n  y: number\n  radius: number\n  marker: string\n  slot: number\n  depth: number\n  leaving: boolean\n  still?: boolean\n}) {\n  return (\n    <span\n      data-slot='chart-point'\n      data-leaving={leaving ? '' : undefined}\n      data-still={still ? '' : undefined}\n      className={cn(\n        // A point that leaves goes on the exit role, faster than it came and with no bounce.\n        'group/point absolute top-0 left-0 size-0 text-(--point-color) [translate:var(--point-at)] transition-none group-data-mounted/chart:transition-[translate,opacity] duration-(--motion-layout-duration) ease-[var(--motion-layout-easing),var(--motion-layout-fade-easing)] group-data-mounted/chart:starting:opacity-0 data-leaving:opacity-0 data-leaving:duration-(--motion-exit-duration) data-leaving:ease-[var(--motion-exit-easing),var(--motion-exit-fade-easing)] data-still:transition-none! motion-reduce:group-data-mounted/chart:transition-[opacity] motion-reduce:ease-(--motion-layout-fade-easing) motion-reduce:data-leaving:ease-(--motion-exit-fade-easing)',\n        forcedSeriesTextColor(slot),\n      )}\n      style={\n        {\n          '--point-at': `${plotOffset(x, 'cqw')} ${plotOffset(y, 'cqh')}`,\n          zIndex: depth,\n        } as CSSProperties\n      }\n    >\n      <svg aria-hidden width={1} height={1} className='absolute overflow-visible'>\n        <path\n          d={marker}\n          vectorEffect='non-scaling-stroke'\n          // The page's colour around each shape keeps overlapping points apart. Under reduced\n          // motion a leaving shape keeps its size, so it fades out as an arriving one fades in.\n          className='stroke-background fill-current [stroke-width:1.5] [transform:scale(var(--point-radius))] transition-none group-data-mounted/chart:transition-[transform] duration-(--motion-layout-duration) ease-(--motion-layout-easing) group-data-mounted/chart:starting:[transform:scale(0)] group-data-leaving/point:[transform:scale(0)] group-data-leaving/point:duration-(--motion-exit-duration) group-data-leaving/point:ease-(--motion-exit-easing) group-data-still/point:transition-none! motion-reduce:group-data-mounted/chart:transition-none motion-reduce:group-data-leaving/point:[transform:scale(var(--point-radius))] forced-colors:stroke-[Canvas]'\n          style={{ '--point-radius': radius } as CSSProperties}\n        />\n      </svg>\n    </span>\n  )\n})\n\n/** A point as a series' layer draws it: where it sits, as fractions of the plot from its left and top, its radius in px, and where it sits from the back. */\ninterface PlacedPoint {\n  key: string\n  x: number\n  y: number\n  radius: number\n  depth: number\n  leaving: boolean\n}\n\n/**\n * A series' points: a layer of the plot holding each of `points` in the\n * series' colour and shape. While a point is lit, or another series is\n * brought forward, the layer steps back as one, with a filter the\n * compositor runs, and the lit point shows bright above it, kept while its\n * copy fades as the series comes back, so it never blinks. `name` is the\n * chart's, which names its slots. `around` holds the marks in each layer,\n * as a live chart's layer that moves with the clock does.\n */\nfunction PointSeries({\n  name,\n  dataKey,\n  points,\n  lit,\n  seriesIndex,\n  marker,\n  dim,\n  around,\n  className,\n  style,\n  ...props\n}: Omit<ComponentProps<'div'>, 'children'> & {\n  name: string\n  dataKey: string\n  points: readonly PlacedPoint[]\n  /** The point lit now, or none. */\n  lit: PlacedPoint | undefined\n  /** The series' place in the config, which picks its colour in forced colours. */\n  seriesIndex: number\n  marker: string\n  dim: boolean\n  around: (marks: ReactNode) => ReactNode\n}) {\n  const [held, setHeld] = useState<string | null>(null)\n  if (lit && lit.key !== held) setHeld(lit.key)\n  const shownLit = lit ?? points.find((point) => point.key === held && !point.leaving)\n  const colours = {\n    '--point-color': seriesColor(dataKey),\n  } as CSSProperties\n  return (\n    <>\n      <div\n        data-slot={`${name}-series`}\n        data-series={dataKey}\n        data-dim={dim ? '' : undefined}\n        aria-hidden\n        className={cn(\n          plotLayerClassName,\n          markLayer.point,\n          stepBackLayerClassName,\n          className,\n        )}\n        style={{ ...colours, ...style }}\n        {...props}\n      >\n        {around(\n          points.map((point) => (\n            <PointMark\n              key={point.key}\n              x={point.x}\n              y={point.y}\n              radius={point.radius}\n              marker={marker}\n              slot={seriesIndex}\n              depth={point.depth}\n              leaving={point.leaving}\n            />\n          )),\n        )}\n      </div>\n      {shownLit && (\n        <div\n          data-slot={`${name}-lit`}\n          data-off={lit === undefined ? '' : undefined}\n          aria-hidden\n          className={cn(\n            plotLayerClassName,\n            'z-13 transition-opacity duration-(--motion-layout-duration) ease-(--motion-layout-fade-easing) data-off:opacity-0',\n          )}\n          style={colours}\n        >\n          {around(\n            <PointMark\n              key={shownLit.key}\n              x={shownLit.x}\n              y={shownLit.y}\n              radius={shownLit.radius}\n              marker={marker}\n              slot={seriesIndex}\n              depth={0}\n              leaving={false}\n              still\n            />,\n          )}\n        </div>\n      )}\n    </>\n  )\n}\n\nexport { markerAt, type PlacedPoint, PointMark, PointSeries }\n",
      "type": "registry:lib",
      "target": "@lib/chart-points.tsx"
    }
  ],
  "type": "registry:lib"
}