@niekes/charts-3d 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../lib/utils.ts","../registry/new-york/ui/chart-3d.tsx","../registry/new-york/ui/bar-chart-3d.tsx","../registry/new-york/ui/scatter-chart-3d.tsx","../registry/new-york/ui/surface-chart-3d.tsx","../registry/new-york/ui/sankey-chart-3d.tsx"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { nice, ticks } from \"d3-array\"\nimport {\n axes3D,\n camera3D,\n normal,\n points3D,\n sort,\n type AxesSpec,\n type AxisEdge,\n type AxisSpec,\n type Camera3DInstance,\n type CubeFace,\n type Point2D,\n type Point3D,\n type ShapeInstance,\n type TransformedPoint,\n} from \"d3-3d\"\nimport { KeyboardIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\n// The same shape as the ChartConfig of shadcn's chart, so one config drives\n// a 2D and a 3D chart side by side.\nconst THEMES = { light: \"\", dark: \".dark\" } as const\n\nexport type ChartConfig = {\n [k in string]: {\n label?: React.ReactNode\n icon?: React.ComponentType\n } & (\n | { color?: string; theme?: never }\n | { color?: never; theme: Record<keyof typeof THEMES, string> }\n )\n}\n\n/** How the camera looks at the chart box, angles in radians. */\nexport type View3D = {\n yaw: number\n /** The angle above the floor the camera looks down from. */\n tilt: number\n zoom?: number\n /** How far the chart is moved, in the units of the view box. */\n pan?: Point2D\n /** The distance of the eye in box units; Infinity, the default, is orthographic. */\n perspective?: number\n}\n\n/** How the marks of a chart are drawn. The box, its labels, the tooltip and the legend are always SVG and HTML. */\nexport type Renderer3D = \"svg\" | \"canvas\"\n\n/** Maps data values to the world box, which spans -1 to 1 on every axis, y up. */\nexport type World = Record<keyof AxesSpec, (value: number) => number>\n\nexport type Tooltip3D = {\n /** The anchor in the units of the view box. */\n at: Point2D\n title?: React.ReactNode\n items: { label: React.ReactNode; value: React.ReactNode; color?: string }[]\n}\n\n/** One shape of a chart, projected, in paint order: a polygon, or a circle of radius `r` around its one point. */\nexport type Mark3D = {\n /** Stable across renders, so React moves the shape instead of redrawing it. */\n key: string\n /** The corners of a polygon, or the center of a circle, in the units of the view box. */\n points: Point2D[]\n r?: number\n /** A CSS color, such as the result of `shade` or `var(--color-x)`. */\n fill: string\n /** The ring around a circle, a CSS color. */\n stroke?: string\n /** Shown while the pointer is over the mark. */\n tooltip?: Tooltip3D\n /**\n * What the mark belongs to, such as a flow, or connects, such as a node.\n * Pointing at a mark fades every mark and label that shares none of its\n * groups, until the pointer leaves the chart; one without groups never fades.\n */\n groups?: string[]\n}\n\n/** The groups in focus, a store, so a change reaches the marks and labels without rendering the chart again. */\ntype Focus3D = {\n get: () => string[] | undefined\n set: (groups?: string[]) => void\n subscribe: (listener: () => void) => () => void\n}\n\ntype ChartContext3D = {\n config: ChartConfig\n camera: Camera3DInstance\n renderer: Renderer3D\n /** The marks of the chart, which the hover and the canvas read. */\n scene: React.RefObject<Mark3D[]>\n repaint: () => void\n focus: Focus3D\n /** The time in ms a chart takes to glide into new data, 600 unless the container says. */\n animationDuration?: number\n}\n\nconst Chart3DContext = React.createContext<ChartContext3D | null>(null)\n\nexport function useChart3D() {\n const context = React.useContext(Chart3DContext)\n if (!context) {\n throw new Error(\"useChart3D must be used within a <ChartContainer3D />\")\n }\n return context\n}\n\nconst DRAG = Math.PI / 230\nconst KEY_STEP = Math.PI / 36\nconst PAN_STEP = 20\nconst ZOOM_STEP = 1.2\nconst CLICK_DISTANCE = 4\n\n/** A step of the camera: turned by `yaw` and `tilt`, moved by `pan`, zoomed by the factor `zoom`, or reset. */\ntype Move = { yaw?: number; tilt?: number; pan?: Point2D; zoom?: number; reset?: boolean }\n\n/** The actions a key triggers: each steps the camera, `help` opens the shortcut panel. */\nexport type KeyAction3D =\n | \"rotateLeft\"\n | \"rotateRight\"\n | \"rotateUp\"\n | \"rotateDown\"\n | \"panLeft\"\n | \"panRight\"\n | \"panUp\"\n | \"panDown\"\n | \"zoomIn\"\n | \"zoomOut\"\n | \"reset\"\n | \"help\"\n\n/** The gestures of the pointer: a drag turns the camera, with Space held it pans, Ctrl or ⌘ with the wheel zooms, a double click resets. */\nexport type Gesture3D = \"dragRotate\" | \"dragPan\" | \"wheelZoom\" | \"doubleClickReset\"\n\n/**\n * The shortcuts of a chart over their defaults, per action: `false` turns an\n * action off, keys replace its keys and a label renames it in the shortcut\n * panel, where the actions of one label share a row. Keys are written the way\n * `aria-keyshortcuts` writes them, such as `\"Shift+ArrowLeft\"` or\n * `\"Control+Plus\"`, and the panel shows the first.\n */\nexport type Keymap3D = {\n [A in KeyAction3D]?: false | string[] | { keys?: string[]; label?: string }\n} & { [G in Gesture3D]?: false | { label?: string } }\n\ntype Action3D = KeyAction3D | Gesture3D\n\n// The shortcuts of a chart, in the order of the shortcut panel: the keys of\n// an action move the camera, a gesture shows its hint, and the panel lists\n// every action that is on, so the two never disagree. `keymap` overrides them.\nconst SHORTCUTS: Record<\n Action3D,\n { label: string; keys?: string[]; hint?: string[]; move?: Move }\n> = {\n dragRotate: { label: \"Rotate\", hint: [\"Drag\"] },\n rotateLeft: { label: \"Rotate\", keys: [\"ArrowLeft\"], move: { yaw: -KEY_STEP } },\n rotateRight: { label: \"Rotate\", keys: [\"ArrowRight\"], move: { yaw: KEY_STEP } },\n rotateUp: { label: \"Rotate\", keys: [\"ArrowUp\"], move: { tilt: -KEY_STEP } },\n rotateDown: { label: \"Rotate\", keys: [\"ArrowDown\"], move: { tilt: KEY_STEP } },\n dragPan: { label: \"Pan\", hint: [\"Space\", \"Drag\"] },\n panLeft: { label: \"Pan\", keys: [\"Shift+ArrowLeft\"], move: { pan: { x: -PAN_STEP, y: 0 } } },\n panRight: { label: \"Pan\", keys: [\"Shift+ArrowRight\"], move: { pan: { x: PAN_STEP, y: 0 } } },\n panUp: { label: \"Pan\", keys: [\"Shift+ArrowUp\"], move: { pan: { x: 0, y: -PAN_STEP } } },\n panDown: { label: \"Pan\", keys: [\"Shift+ArrowDown\"], move: { pan: { x: 0, y: PAN_STEP } } },\n zoomIn: { label: \"Zoom\", keys: [\"Plus\", \"=\"], move: { zoom: ZOOM_STEP } },\n zoomOut: { label: \"Zoom\", keys: [\"-\"], move: { zoom: 1 / ZOOM_STEP } },\n wheelZoom: { label: \"Zoom\", hint: [\"Ctrl\", \"Scroll\"] },\n reset: { label: \"Reset\", keys: [\"0\"], move: { reset: true } },\n doubleClickReset: { label: \"Reset\", hint: [\"Double-click\"] },\n help: { label: \"Keyboard shortcuts\", keys: [\"?\"] },\n}\n\nconst MODIFIERS = [\"Control\", \"Alt\", \"Meta\", \"Shift\"]\n// The keys that `aria-keyshortcuts` names, because `+` delimits and a space separates.\nconst NAMED: Record<string, string> = { Plus: \"+\", Space: \" \" }\nconst ARIA: Record<string, string> = { \"+\": \"Plus\", \" \": \"Space\" }\nconst KBD: Record<string, string> = {\n ArrowLeft: \"←\",\n ArrowRight: \"→\",\n ArrowUp: \"↑\",\n ArrowDown: \"↓\",\n \"-\": \"−\",\n \" \": \"Space\",\n Control: \"Ctrl\",\n Meta: \"⌘\",\n}\n\n/** Keys split at `+`, which is the key itself at the end: `\"Control++\"` is Control and `+`. */\nconst split = (keys: string) => keys.split(/\\+(?!$)/)\n\n/**\n * Keys in the one form a binding and a press compare in: the modifiers in a\n * fixed order, then the key, Plus as `+` and Space as \" \". Shift counts only\n * beside a named key; a character such as \"?\" or \"A\" is typed with it already.\n */\nfunction combo(keys: string) {\n const parts = split(keys)\n const key = NAMED[parts.at(-1)!] ?? parts.at(-1)!\n const mods = MODIFIERS.filter((m) => parts.includes(m) && (m !== \"Shift\" || key.length > 1))\n return [...mods, key].join(\"+\")\n}\n\n/** The keys of a press, in the form of `combo`. */\nfunction pressed(e: Pick<KeyboardEvent, \"key\" | \"ctrlKey\" | \"altKey\" | \"metaKey\" | \"shiftKey\">) {\n const mods = [\n e.ctrlKey && \"Control\",\n e.altKey && \"Alt\",\n e.metaKey && \"Meta\",\n e.shiftKey && \"Shift\",\n ]\n return combo([...mods, e.key].filter(Boolean).join(\"+\"))\n}\n\n/** Keys in the form of `combo`, the way `aria-keyshortcuts` writes them. */\nfunction aria(keys: string) {\n const parts = split(keys)\n return [...parts.slice(0, -1), ARIA[parts.at(-1)!] ?? parts.at(-1)].join(\"+\")\n}\n\n/** Every action, `keymap` over its defaults: on unless it is off or a key action without keys. */\nfunction shortcutsOf(keymap: Keymap3D | false) {\n return (Object.keys(SHORTCUTS) as Action3D[]).map((action) => {\n const own: Keymap3D[KeyAction3D] = keymap && keymap[action]\n const { keys = [], ...shortcut } = {\n ...SHORTCUTS[action],\n ...(Array.isArray(own) ? { keys: own } : own || {}),\n }\n const on = own !== false && (shortcut.hint !== undefined || keys.length > 0)\n return { ...shortcut, action, on, keys: keys.map(combo) }\n })\n}\n\ntype Shortcut = ReturnType<typeof shortcutsOf>[number]\n\n/**\n * The rows of the shortcut panel: the actions by label, the keys of a row in\n * groups of the same modifiers, a gesture in a group of its own.\n */\nfunction rowsOf(shortcuts: Shortcut[]) {\n const rows = new Map<string, Map<string, string[]>>()\n for (const { action, label, keys, hint } of shortcuts) {\n const parts = hint ?? split(keys[0]).map((k) => KBD[k] ?? k)\n const group = hint ? action : parts.slice(0, -1).join(\"+\")\n const groups = rows.get(label) ?? new Map<string, string[]>()\n const known = groups.get(group)\n rows.set(label, groups.set(group, known ? [...known, parts.at(-1)!] : parts))\n }\n return [...rows].map(([label, groups]) => ({ label, groups: [...groups.values()] }))\n}\n\n/**\n * What a keymap does: the actions that are on, the step of each key, the help\n * keys and the rows of the panel. Without the `panel`, the help keys have\n * nothing to open and are off.\n */\nfunction keymapOf(keymap: Keymap3D | false, panel: boolean) {\n const all = shortcutsOf(keymap)\n const on = all.filter((s) => s.on && (panel || s.action !== \"help\"))\n return {\n on: (action: Action3D) => on.some((s) => s.action === action),\n moves: Object.fromEntries(on.flatMap((s) => s.keys.map((k) => [k, s.move]))) as Record<\n string,\n Move | undefined\n >,\n help: on.find((s) => s.action === \"help\")?.keys ?? [],\n label: all.find((s) => s.action === \"help\")!.label,\n aria: on.flatMap((s) => s.keys.map(aria)).join(\" \"),\n rows: panel ? rowsOf(on) : [],\n }\n}\n\ntype Keymap = ReturnType<typeof keymapOf>\n\nexport type ChartContainer3DProps = {\n /** The series of the chart: a label and a color per key, as in the chart of shadcn/ui. */\n config: ChartConfig\n /**\n * The time in ms a chart takes to glide into new data; 0 makes it jump.\n * @defaultValue 600\n */\n animationDuration?: number\n /**\n * Where the camera starts, and where a reset returns it.\n * @defaultValue { yaw: π/6, tilt: π/6 }\n */\n defaultView?: View3D\n /**\n * The width of the view box the chart is drawn in.\n * @defaultValue 640\n */\n width?: number\n /**\n * The height of the view box the chart is drawn in.\n * @defaultValue 400\n */\n height?: number\n /**\n * Shows the label and the color of every config key below the chart.\n * @defaultValue false\n */\n legend?: boolean\n /**\n * How the marks of the chart are drawn: \"canvas\" suits many marks. The\n * chart draws as SVG until the browser shows it has a canvas, and where it\n * has none.\n * @defaultValue \"svg\"\n */\n renderer?: Renderer3D\n /**\n * Shows a button that lists the keyboard shortcuts of the chart; `?` lists them too.\n * @defaultValue true\n */\n shortcuts?: boolean\n /**\n * Rebinds, renames or turns off the keys and the gestures of the chart, per\n * action; `false` turns them all off and the chart stands still.\n * @defaultValue {}\n */\n keymap?: Keymap3D | false\n /**\n * The corner that shows the axes of the chart, turned with the camera; `false` hides them.\n * @defaultValue \"bottom-left\"\n */\n gizmo?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\" | false\n}\n\nfunction ChartContainer3D({\n id,\n config,\n defaultView = { yaw: Math.PI / 6, tilt: Math.PI / 6 },\n width = 640,\n height = 400,\n animationDuration,\n legend = false,\n renderer: requested = \"svg\",\n shortcuts = true,\n keymap = {},\n gizmo = \"bottom-left\",\n className,\n children,\n \"aria-label\": ariaLabel,\n ...props\n}: React.ComponentProps<\"div\"> & ChartContainer3DProps) {\n const uniqueId = React.useId()\n const chartId = `chart-${id || uniqueId.replace(/:/g, \"\")}`\n const { scene, renderer, canvas, repaint, hover, hide, leave, tooltip, focus } = useScene(\n requested,\n width,\n height\n )\n const keys = keymapOf(keymap, shortcuts)\n const { view, handlers } = useOrbit(defaultView, width, keys, hide, hover)\n const camera = useCamera(view, width, height)\n const context = React.useMemo(\n () => ({ config, camera, renderer, scene, repaint, focus, animationDuration }),\n [config, camera, renderer, repaint, focus, animationDuration]\n )\n\n return (\n <div\n data-slot=\"chart-3d\"\n data-chart={chartId}\n className={cn(\"relative w-full text-xs\", className)}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <div className=\"relative rounded-lg has-focus-visible:ring-[3px] has-focus-visible:ring-ring/50\">\n <svg\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n {...keymapProps(keys, ariaLabel)}\n onPointerLeave={leave}\n {...handlers}\n >\n <Chart3DContext.Provider value={context}>{children}</Chart3DContext.Provider>\n </svg>\n <ChartCanvas3D renderer={renderer} canvas={canvas} width={width} height={height} />\n <ChartGizmo3D camera={camera} corner={gizmo} />\n <ChartTooltip3D tooltip={tooltip} width={width} height={height} />\n </div>\n <ChartShortcuts3D {...keys} />\n {legend && <ChartLegend3D config={config} />}\n </div>\n )\n}\n\n/**\n * What the svg says about its keymap: a label that names the drag and the\n * help key if they are on, the keys, the focus only if a key does something\n * and the grab cursor only if a drag does; without one, a touch scrolls the page.\n */\nfunction keymapProps(keys: Keymap, label?: string): React.SVGProps<SVGSVGElement> {\n const drag = keys.on(\"dragRotate\") || keys.on(\"dragPan\")\n const help = keys.help[0]\n const said = [\n \"3D chart.\",\n keys.on(\"dragRotate\") && \"Drag to rotate it.\",\n help && `Press ${aria(help)} for all shortcuts.`,\n ]\n return {\n \"aria-label\": label ?? said.filter(Boolean).join(\" \"),\n \"aria-keyshortcuts\": keys.aria || undefined,\n tabIndex: keys.aria ? 0 : undefined,\n className: cn(\n \"block h-auto w-full outline-hidden select-none mask-y-from-96%\",\n drag && \"cursor-grab touch-none active:cursor-grabbing\"\n ),\n }\n}\n\n/**\n * The marks of the chart and what reads them: the renderer that draws them,\n * the canvas it paints them on and the hover that shows their tooltips.\n */\nfunction useScene(requested: Renderer3D, width: number, height: number) {\n const scene = React.useRef<Mark3D[]>([])\n const [tooltip, setTooltip] = React.useState<Tooltip3D | null>(null)\n const focus = useFocus()\n const renderer = useRenderer(requested)\n const { canvas, repaint } = useCanvas(scene, width)\n const { hover, hide, leave } = useHover(scene, width, height, setTooltip, focus)\n return { scene, renderer, canvas, repaint, hover, hide, leave, tooltip, focus }\n}\n\n/** The camera of a view. The shapes of the chart hang on it, so a new view re-projects them all. */\nfunction useCamera(view: View3D, width: number, height: number) {\n return React.useMemo(\n () =>\n camera3D()\n .origin({ x: width / 2 + (view.pan?.x ?? 0), y: height / 2 + (view.pan?.y ?? 0) })\n .scale(Math.min(width, height) * 0.3 * (view.zoom ?? 1))\n .perspective(view.perspective ?? Infinity)\n .rotateY(view.yaw)\n .rotateX(-view.tilt),\n [view, width, height]\n )\n}\n\nconst clamp = (lo: number, hi: number, value: number) => Math.max(lo, Math.min(hi, value))\nconst ZERO = { x: 0, y: 0 }\n\n/** `view` moved by one step. The tilt stops at the zenith and the nadir, the zoom at 1/4 and 8. */\nfunction moved(view: View3D, move: Move, initial: View3D): View3D {\n if (move.reset) return initial\n const step = { yaw: 0, tilt: 0, zoom: 1, pan: { x: 0, y: 0 }, ...move }\n const pan = view.pan ?? { x: 0, y: 0 }\n return {\n ...view,\n yaw: view.yaw + step.yaw,\n tilt: clamp(-Math.PI / 2, Math.PI / 2, view.tilt + step.tilt),\n zoom: clamp(0.25, 8, (view.zoom ?? 1) * step.zoom),\n pan: { x: pan.x + step.pan.x, y: pan.y + step.pan.y },\n }\n}\n\n/**\n * Whether the chart may move on its own: only where the browser says the\n * reader has not asked for reduced motion. Where it cannot say, as on the\n * server and in jsdom, the chart jumps.\n */\nfunction animates() {\n return Boolean(globalThis.matchMedia?.(\"(prefers-reduced-motion: no-preference)\").matches)\n}\n\n/** One glide of numbers: from `from` into `to`, come the share `t` of the way. */\ntype Tween = { key: string; from: Record<string, number>; to: Record<string, number>; t: number }\n\n/**\n * Eases a chart into new data: the numbers of `values` glide from the ones\n * on screen to these over the animationDuration of the container. A key\n * that is new starts at `enter`, or where it ends; a key that is gone goes\n * at once. Without time, or with reduced motion, the numbers jump.\n */\nfunction useTween(values: Record<string, number>, enter?: number): Record<string, number> {\n const { animationDuration: duration = 600 } = useChart3D()\n // The content, not the record: a chart builds `values` at every render, also while it turns.\n const key = JSON.stringify(values)\n const [tween, setTween] = React.useState<Tween>({ key, from: values, to: values, t: 1 })\n const shown = tweenNumbers(tween, enter)\n\n // Numbers from the render before, the React pattern of state set while rendering.\n if (key !== tween.key) {\n setTween({ key, from: shown, to: values, t: duration > 0 && animates() ? 0 : 1 })\n }\n\n React.useEffect(() => {\n if (tween.t >= 1) return\n let start: number | null = null\n let frame = 0\n const step = (now: number) => {\n start ??= now\n const t = Math.min(1, (now - start) / duration)\n setTween((tw) => ({ ...tw, t }))\n if (t < 1) frame = requestAnimationFrame(step)\n }\n frame = requestAnimationFrame(step)\n return () => cancelAnimationFrame(frame)\n }, [tween.key, duration])\n\n return shown\n}\n\n/** The numbers of `tween` on screen: `from` eased into `to`, a new key from `enter` or where it ends. */\nfunction tweenNumbers({ from, to, t }: Tween, enter?: number) {\n const s = t * t * (3 - 2 * t)\n return Object.fromEntries(\n Object.entries(to).map(([k, end]) => {\n const start = from[k] ?? enter ?? end\n // At the end the number itself, so no float drift stays in the data.\n return [k, t >= 1 ? end : start + (end - start) * s]\n })\n )\n}\n\n/**\n * `spec` gliding into new data with the marks: the ends of every axis glide\n * as `useTween` glides the numbers, where ends rounded from the numbers on\n * screen would jump from one round number to the next, and the box with\n * them. The ticks are those of `spec` that lie between the ends.\n */\nfunction useTweenAxes(spec: AxesSpec): AxesSpec {\n const axes = [\"x\", \"y\", \"z\"] as const\n const ends = useTween(\n Object.fromEntries(\n axes.flatMap((a) => [\n [`${a}0`, spec[a].domain[0]],\n [`${a}1`, spec[a].domain[spec[a].domain.length - 1]],\n ])\n )\n )\n const glided = (a: keyof AxesSpec): AxisSpec => {\n const [lo, hi] = [ends[`${a}0`], ends[`${a}1`]]\n const inside = (t: number) => t >= Math.min(lo, hi) && t <= Math.max(lo, hi)\n return { domain: [lo, hi], ticks: spec[a].ticks.filter(inside) }\n }\n return { x: glided(\"x\"), y: glided(\"y\"), z: glided(\"z\") }\n}\n\n// How long the camera glides to the view a key asks for, in milliseconds.\nconst GLIDE = 200\n\n/**\n * The view of the camera, `jump`, which moves it at once, and `glide`, which\n * moves it there in `GLIDE` milliseconds, easing out. A glide under way\n * heads for the next view from where it is, so a held key turns the camera\n * smoothly; a jump stops it. Where the reader asks for reduced motion, or\n * the browser cannot say, a glide jumps.\n */\nfunction useGlide(defaultView: View3D) {\n const [view, setView] = React.useState(defaultView)\n const now = React.useRef(defaultView)\n const run = React.useRef<{ to: View3D; frame: number } | null>(null)\n const show = React.useCallback((v: View3D) => setView((now.current = v)), [])\n const stop = React.useCallback(() => {\n cancelAnimationFrame(run.current?.frame ?? 0)\n run.current = null\n }, [])\n const jump = React.useCallback(\n (to: (from: View3D) => View3D) => {\n stop()\n show(to(now.current))\n },\n [show, stop]\n )\n React.useEffect(() => stop, [stop])\n\n const glide = (to: (from: View3D) => View3D) => {\n if (!animates()) return jump(to)\n const end = to(run.current?.to ?? now.current)\n // The yaw turns the short way round, to an angle that looks the same.\n const from = { ...now.current, yaw: end.yaw + remainder(now.current.yaw - end.yaw) }\n const start = performance.now()\n stop()\n const frame = (time: number) => {\n const t = clamp(0, 1, (time - start) / GLIDE)\n show(t < 1 ? between(from, end, 1 - (1 - t) ** 3) : end)\n if (t < 1) run.current = { to: end, frame: requestAnimationFrame(frame) }\n else run.current = null\n }\n run.current = { to: end, frame: requestAnimationFrame(frame) }\n }\n\n return { view, jump, glide }\n}\n\n/** The angle `a` in the turn from -π to π. */\nfunction remainder(a: number) {\n return a - 2 * Math.PI * Math.round(a / (2 * Math.PI))\n}\n\n/** The view the share `k` of the way from `from` to `to`. */\nfunction between(from: View3D, to: View3D, k: number): View3D {\n const mix = (a: number, b: number) => a + (b - a) * k\n const pan = from.pan ?? ZERO\n const goal = to.pan ?? ZERO\n return {\n ...to,\n yaw: mix(from.yaw, to.yaw),\n tilt: mix(from.tilt, to.tilt),\n zoom: mix(from.zoom ?? 1, to.zoom ?? 1),\n pan: { x: mix(pan.x, goal.x), y: mix(pan.y, goal.y) },\n }\n}\n\n/**\n * The view of the camera, and the handlers that move it, as far as `keys`\n * has them on: a drag turns it, or pans it while Space is held, the keys\n * step it, Ctrl or ⌘ with the wheel zooms it and a double click resets it.\n * `data-orbiting` among them is true while the camera turns. `onDragStart`\n * runs when a press becomes a drag, `onHover` on a move without one.\n */\nfunction useOrbit(\n defaultView: View3D,\n width: number,\n keys: Keymap,\n onDragStart: () => void,\n onHover: (e: React.PointerEvent<SVGSVGElement>) => void\n) {\n const { view, jump, glide } = useGlide(defaultView)\n const [orbiting, setOrbiting] = React.useState(false)\n const drag = React.useRef<Point2D & { moved: boolean }>(null)\n const ref = useWheelZoom(jump, keys.on(\"wheelZoom\"))\n // A drag follows the pointer at once, a key and a double click glide.\n const move = (step: Move) => jump((v) => moved(v, step, defaultView))\n const step = (step: Move) => glide((v) => moved(v, step, defaultView))\n const { space, ...keyHandlers } = useKeys(keys, step, setOrbiting)\n const release = () => {\n drag.current = null\n setOrbiting(false)\n }\n\n const handlers: React.SVGProps<SVGSVGElement> & { \"data-orbiting\": boolean } = {\n ref,\n onPointerDown: (e) => {\n // Space is held only while the drag pans; without it, the drag turns.\n if (space.current || keys.on(\"dragRotate\")) {\n drag.current = { x: e.clientX, y: e.clientY, moved: false }\n }\n },\n onPointerMove: (e) => {\n const d = drag.current\n if (!d) return onHover(e)\n const dx = e.clientX - d.x\n const dy = e.clientY - d.y\n // A press that wanders a few pixels is still a click on a bar.\n if (!d.moved && Math.hypot(dx, dy) < CLICK_DISTANCE) return\n if (!d.moved) {\n e.currentTarget.setPointerCapture(e.pointerId)\n onDragStart()\n }\n drag.current = { x: e.clientX, y: e.clientY, moved: true }\n const k = width / e.currentTarget.getBoundingClientRect().width\n setOrbiting(!space.current)\n move(space.current ? { pan: { x: dx * k, y: dy * k } } : { yaw: dx * DRAG, tilt: dy * DRAG })\n },\n onPointerUp: release,\n onPointerCancel: release,\n onDoubleClick: keys.on(\"doubleClickReset\") ? () => step({ reset: true }) : undefined,\n ...keyHandlers,\n \"data-orbiting\": orbiting,\n }\n\n return { view, handlers }\n}\n\n/**\n * The handlers that step the camera with the keys of `keys`, and `space`,\n * which is true while Space is held for a drag to pan. A key that turns the\n * camera marks it as orbiting until it is let go.\n */\nfunction useKeys(\n keys: Keymap,\n move: (step: Move) => void,\n setOrbiting: (orbiting: boolean) => void\n) {\n const space = React.useRef(false)\n const onKeyDown = (e: React.KeyboardEvent<SVGSVGElement>) => {\n // Held on the chart, Space pans a drag instead of scrolling the page.\n const pan = e.key === \" \" && keys.on(\"dragPan\")\n if (pan) space.current = true\n const step = keys.moves[pressed(e)]\n if (!step && !pan) return\n e.preventDefault()\n if (!step) return\n setOrbiting(Boolean(step.yaw || step.tilt))\n move(step)\n }\n const onKeyUp = (e: React.KeyboardEvent<SVGSVGElement>) => {\n if (e.key === \" \") space.current = false\n setOrbiting(false)\n }\n return { space, onKeyDown, onKeyUp }\n}\n\n/**\n * A ref for the svg that zooms the view with Ctrl or ⌘ and the wheel, which\n * is also how a trackpad pinches, if `on`. The wheel alone still scrolls the page.\n */\nfunction useWheelZoom(jump: (to: (from: View3D) => View3D) => void, on: boolean) {\n // React listens to the wheel passively, and only a listener that is not\n // passive can keep the browser from zooming the page.\n return React.useCallback(\n (svg: SVGSVGElement | null) => {\n if (!on) return\n const onWheel = (e: WheelEvent) => {\n if (!e.ctrlKey && !e.metaKey) return\n e.preventDefault()\n jump((v) => moved(v, { zoom: 2 ** (-e.deltaY / 200) }, v))\n }\n svg?.addEventListener(\"wheel\", onWheel, { passive: false })\n return () => svg?.removeEventListener(\"wheel\", onWheel)\n },\n [jump, on]\n )\n}\n\n/**\n * The tooltip of the mark under the pointer, the one painted last, and the\n * focus on its groups. `hover` sets the tooltip only when the pointer moves\n * onto another mark, and the focus only when the groups change, so a move\n * within a mark does not render the chart again. Off the marks and while a\n * drag turns the chart, `hide` drops the tooltip but keeps the focus, so a\n * flow does not flash in the gaps beside it and can be followed from every\n * side; `leave` drops both.\n */\nfunction useHover(\n scene: React.RefObject<Mark3D[]>,\n width: number,\n height: number,\n setTooltip: (tooltip: Tooltip3D | null) => void,\n focus: Focus3D\n) {\n const hovered = React.useRef<Mark3D>(undefined)\n const show = (mark?: Mark3D) => {\n // Also within one mark, whose groups new data can change; the store ignores the groups it holds.\n if (mark?.groups) focus.set(mark.groups)\n if (mark?.key === hovered.current?.key) return\n hovered.current = mark\n setTooltip(mark?.tooltip ?? null)\n }\n\n return {\n hover: (e: React.PointerEvent<SVGSVGElement>) => {\n const rect = e.currentTarget.getBoundingClientRect()\n const at = {\n x: ((e.clientX - rect.left) / rect.width) * width,\n y: ((e.clientY - rect.top) / rect.height) * height,\n }\n show(hit(scene.current, at))\n },\n hide: () => show(undefined),\n leave: () => {\n show(undefined)\n focus.set(undefined)\n },\n }\n}\n\n/** A store for the groups in focus, which tells its listeners only when the groups change. */\nfunction useFocus(): Focus3D {\n const [focus] = React.useState(() => {\n let groups: string[] | undefined\n const listeners = new Set<() => void>()\n return {\n get: () => groups,\n set: (next?: string[]) => {\n if (JSON.stringify(next) === JSON.stringify(groups)) return\n groups = next\n listeners.forEach((listener) => listener())\n },\n subscribe: (listener: () => void) => {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n }\n })\n return focus\n}\n\n/**\n * Whether an item fades under the focus: it has groups and shares none with\n * the focus, while some item of `items` does, so a focus on groups that are\n * gone fades nothing.\n */\nfunction useFades(items: { groups?: string[] }[]) {\n const { focus } = useChart3D()\n const groups = React.useSyncExternalStore(focus.subscribe, focus.get, focus.get)\n const lit = (of?: string[]) => of?.some((group) => groups?.includes(group)) ?? false\n const on = items.some((item) => lit(item.groups))\n return (item: { groups?: string[] }) => on && item.groups !== undefined && !lit(item.groups)\n}\n\n/** The topmost mark under `at`: the last one painted that holds it. */\nfunction hit(marks: Mark3D[], at: Point2D) {\n for (let i = marks.length - 1; i >= 0; i -= 1) {\n const { points, r } = marks[i]\n const holds =\n r === undefined ? inside(points, at) : Math.hypot(points[0].x - at.x, points[0].y - at.y) <= r\n if (holds) return marks[i]\n }\n}\n\n/** Whether `at` lies inside `polygon`: a ray from it crosses an odd number of its edges. */\nfunction inside(polygon: Point2D[], at: Point2D) {\n let odd = false\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i, i += 1) {\n const a = polygon[i]\n const b = polygon[j]\n if (a.y > at.y !== b.y > at.y && at.x < ((b.x - a.x) * (at.y - a.y)) / (b.y - a.y) + a.x) {\n odd = !odd\n }\n }\n return odd\n}\n\n/**\n * The renderer the chart draws with: SVG on the server and in the first\n * render on the client, then the requested one if the browser has it.\n */\nfunction useRenderer(requested: Renderer3D) {\n const [renderer, setRenderer] = React.useState<Renderer3D>(\"svg\")\n React.useEffect(() => {\n // A canvas of its own, as one that gave out a context cannot give another.\n const canvas = requested === \"canvas\" && document.createElement(\"canvas\").getContext(\"2d\")\n setRenderer(canvas ? \"canvas\" : \"svg\")\n }, [requested])\n return renderer\n}\n\n/**\n * A ref for the canvas of the marks, and the repaint that paints them: on new\n * marks, when the canvas changes its size and when the theme changes. A color\n * resolves on the canvas itself, inside the chart, so the `--color-*` apply.\n */\nfunction useCanvas(scene: React.RefObject<Mark3D[]>, width: number) {\n const element = React.useRef<HTMLCanvasElement>(null)\n const colors = React.useRef(new Map<string, string>())\n\n const repaint = React.useCallback(() => {\n const canvas = element.current\n if (!canvas) return\n paint(canvas, scene.current, width, (css) => {\n let color = colors.current.get(css)\n if (color === undefined) {\n canvas.style.color = css\n color = getComputedStyle(canvas).color\n colors.current.set(css, color)\n }\n return color\n })\n }, [scene, width])\n\n const canvas = React.useCallback(\n // A ref that returns its cleanup is never called with null.\n (node: HTMLCanvasElement) => {\n element.current = node\n repaint()\n const resize = new ResizeObserver(repaint)\n resize.observe(node)\n // ponytail: watches the theme on <html> only, as the class `.dark` of THEMES does.\n const theme = new MutationObserver(() => {\n colors.current.clear()\n repaint()\n })\n theme.observe(document.documentElement, { attributeFilter: [\"class\", \"style\"] })\n return () => {\n element.current = null\n resize.disconnect()\n theme.disconnect()\n }\n },\n [repaint]\n )\n\n return { canvas, repaint }\n}\n\n/** Paints `marks` on `canvas`, from the view box of `width` to the pixels of the canvas. */\nfunction paint(\n canvas: HTMLCanvasElement,\n marks: Mark3D[],\n width: number,\n color: (css: string) => string\n) {\n canvas.width = Math.round(canvas.clientWidth * devicePixelRatio)\n canvas.height = Math.round(canvas.clientHeight * devicePixelRatio)\n // useRenderer draws on a canvas only where the browser gives one a 2D context.\n const ctx = canvas.getContext(\"2d\")!\n const scale = canvas.width / width\n ctx.setTransform(scale, 0, 0, scale, 0, 0)\n ctx.lineJoin = \"round\"\n\n for (const { points, r, fill, stroke } of marks) {\n ctx.beginPath()\n if (r === undefined) {\n for (const p of points) ctx.lineTo(p.x, p.y)\n ctx.closePath()\n } else {\n ctx.arc(points[0].x, points[0].y, r, 0, 2 * Math.PI)\n }\n ctx.fillStyle = color(fill)\n ctx.fill()\n // A polygon is outlined in its own color, which closes the seams to its neighbours.\n const outline = r === undefined ? fill : stroke\n if (!outline) continue\n ctx.strokeStyle = color(outline)\n ctx.lineWidth = r === undefined ? 0.5 : 1\n ctx.stroke()\n }\n}\n\n/** The canvas over the chart box that the marks are painted on, if the chart draws on one. */\nfunction ChartCanvas3D({\n renderer,\n canvas,\n width,\n height,\n}: {\n renderer: Renderer3D\n canvas: React.Ref<HTMLCanvasElement>\n width: number\n height: number\n}) {\n if (renderer !== \"canvas\") return null\n\n return (\n <canvas\n ref={canvas}\n className=\"pointer-events-none absolute top-0 left-0 w-full mask-y-from-96%\"\n style={{ aspectRatio: `${width} / ${height}` }}\n />\n )\n}\n\n// The ends of the axes of the gizmo, in the space of d3-3d, where y points down: up in the chart.\nconst GIZMO = [\n { axis: \"x\", x: 1, y: 0, z: 0 },\n { axis: \"y\", x: 0, y: -1, z: 0 },\n { axis: \"z\", x: 0, y: 0, z: 1 },\n]\n\nconst CORNERS = {\n \"top-left\": \"top-2 left-2\",\n \"top-right\": \"top-2 right-2\",\n \"bottom-left\": \"bottom-2 left-2\",\n \"bottom-right\": \"bottom-2 right-2\",\n}\n\n/**\n * The axes of the world in a corner of the chart: turned with the camera,\n * neither panned nor zoomed, the axis nearest the camera on top. An axis\n * draws in `currentColor`, so a text color on its `data-axis` recolors it.\n */\nfunction ChartGizmo3D({\n camera,\n corner,\n}: {\n camera: Camera3DInstance\n corner: ChartContainer3DProps[\"gizmo\"]\n}) {\n if (!corner) return null\n // The letters at the ends, in a box of 48 around its middle.\n const eye = camera3D()\n .origin({ x: 24, y: 24 })\n .scale(18)\n .rotateY(camera.rotateY())\n .rotateX(camera.rotateX())\n const ends = points3D<(typeof GIZMO)[number]>().camera(eye).data(GIZMO).sort(sort)\n\n return (\n <svg\n data-slot=\"chart-3d-gizmo\"\n viewBox=\"0 0 48 48\"\n aria-hidden=\"true\"\n className={cn(\"pointer-events-none absolute size-12 text-muted-foreground\", CORNERS[corner])}\n >\n {ends.map(({ axis, projected: p }) => (\n <g key={axis} data-axis={axis}>\n <line\n x1={24}\n y1={24}\n x2={24 + (p.x - 24) * 0.6}\n y2={24 + (p.y - 24) * 0.6}\n stroke=\"currentColor\"\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n />\n <text\n x={p.x}\n y={p.y}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n fill=\"currentColor\"\n className=\"text-[10px] font-medium\"\n >\n {axis.toUpperCase()}\n </text>\n </g>\n ))}\n </svg>\n )\n}\n\n/**\n * The marks of a chart, drawn by the renderer of the container: as SVG\n * elements, or on the canvas over the chart box. The hover reads them too.\n */\nfunction Marks3D({ marks }: { marks: Mark3D[] }) {\n const { renderer, scene, repaint } = useChart3D()\n const fades = useFades(marks)\n // Faded in place, so the order, and with it the depth, stays as the chart painted it.\n const drawn = marks.map((mark) => (fades(mark) ? { ...mark, fill: fade(mark.fill) } : mark))\n React.useLayoutEffect(() => {\n scene.current = drawn\n repaint()\n })\n\n if (renderer === \"canvas\") return null\n return drawn.map(({ key, points, r, fill, stroke }) =>\n r === undefined ? (\n <path\n key={key}\n d={`M${points.map((p) => `${+p.x.toFixed(2)},${+p.y.toFixed(2)}`).join(\"L\")}Z`}\n fill={fill}\n stroke={fill}\n strokeWidth={0.5}\n strokeLinejoin=\"round\"\n />\n ) : (\n <circle\n key={key}\n cx={points[0].x}\n cy={points[0].y}\n r={r}\n fill={fill}\n stroke={stroke}\n strokeWidth={stroke ? 1 : undefined}\n />\n )\n )\n}\n\n/**\n * A label beside a mark, at `at` in the units of the view box. `toward`, a\n * unit vector, lays the label on that side of `at`, touching it, and slides\n * it round `at` as the vector turns; without it, `anchor` is the end of the\n * text that sits at `at`.\n */\nexport type Label3D = {\n key: string\n at: Point2D\n text: React.ReactNode\n anchor?: \"start\" | \"middle\" | \"end\"\n toward?: Point2D\n /** The groups of the mark it names, so it fades with the mark out of focus. */\n groups?: string[]\n}\n\n/**\n * The labels of the marks of a chart, ringed by the background so that they\n * read on the marks. Like the labels of the box, they are SVG with every renderer.\n */\nfunction Labels3D({ labels }: { labels: Label3D[] }) {\n const fades = useFades(labels)\n // ponytail: under the canvas of the canvas renderer, as the labels of the box; an SVG layer over the canvas would lift them.\n return (\n <g data-slot=\"chart-3d-labels\">\n {labels.map((label) => {\n const { x, y } = label.toward\n ? beside(label.at, label.toward, textWidth(label.text, 10), 10, 0)\n : label.at\n return (\n <text\n key={label.key}\n x={x}\n y={y}\n textAnchor={label.toward ? \"middle\" : label.anchor}\n dominantBaseline=\"central\"\n paintOrder=\"stroke\"\n strokeWidth={3}\n strokeLinejoin=\"round\"\n className={cn(\n \"fill-foreground stroke-background text-[10px] font-medium\",\n fades(label) && \"opacity-25\"\n )}\n >\n {label.text}\n </text>\n )\n })}\n </g>\n )\n}\n\nfunction ChartStyle({ id, config }: { id: string; config: ChartConfig }) {\n const colorConfig = Object.entries(config).filter(([, c]) => c.theme || c.color)\n\n if (!colorConfig.length) {\n return null\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: Object.entries(THEMES)\n .map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, item]) => {\n const color = item.theme?.[theme as keyof typeof item.theme] || item.color\n return color ? ` --color-${key}: ${color};` : null\n })\n .join(\"\\n\")}\n}\n`\n )\n .join(\"\\n\"),\n }}\n />\n )\n}\n\nfunction ChartTooltip3D({\n tooltip,\n width,\n height,\n}: {\n tooltip: Tooltip3D | null\n width: number\n height: number\n}) {\n if (!tooltip) return null\n\n return (\n <div\n className=\"pointer-events-none absolute z-10 grid min-w-32 -translate-x-1/2 -translate-y-[calc(100%+0.5rem)] gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl\"\n style={{ left: `${(tooltip.at.x / width) * 100}%`, top: `${(tooltip.at.y / height) * 100}%` }}\n >\n {tooltip.title && <div className=\"font-medium\">{tooltip.title}</div>}\n {tooltip.items.map((item, i) => (\n <div key={i} className=\"flex items-center gap-2\">\n {item.color && (\n <span className=\"size-2.5 shrink-0 rounded-[2px]\" style={{ background: item.color }} />\n )}\n <span className=\"text-muted-foreground\">{item.label}</span>\n <span className=\"ml-auto font-mono font-medium text-foreground tabular-nums\">\n {typeof item.value === \"number\" ? item.value.toLocaleString() : item.value}\n </span>\n </div>\n ))}\n </div>\n )\n}\n\n/**\n * A button in the corner of the chart, named `label`, that lists the rows of\n * its keymap. The `help` keys on the chart open and close the list, Escape\n * closes it.\n */\nfunction ChartShortcuts3D({ rows, help, label }: Pick<Keymap, \"rows\" | \"help\" | \"label\">) {\n const [open, setOpen] = React.useState(false)\n const ref = React.useRef<HTMLDivElement>(null)\n const id = React.useId()\n // A dependency that stays the same while the keys do; no key is a line break.\n const keys = help.join(\"\\n\")\n\n React.useEffect(() => {\n const chart = ref.current?.parentElement\n const onKeyDown = (e: KeyboardEvent) => {\n if (keys.split(\"\\n\").includes(pressed(e))) setOpen((o) => !o)\n if (e.key === \"Escape\") setOpen(false)\n }\n chart?.addEventListener(\"keydown\", onKeyDown)\n return () => chart?.removeEventListener(\"keydown\", onKeyDown)\n }, [keys])\n\n // Without a key or a panel, there is nothing to list.\n if (!rows.length) return null\n return (\n <div ref={ref} className=\"absolute top-2 right-2 z-10 flex flex-col items-end gap-1\">\n <button\n type=\"button\"\n data-slot=\"chart-3d-shortcuts-trigger\"\n aria-label={label}\n aria-expanded={open}\n aria-controls={open ? id : undefined}\n onClick={() => setOpen((o) => !o)}\n className=\"inline-flex size-7 items-center justify-center rounded-md text-muted-foreground outline-none hover:bg-accent hover:text-accent-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4\"\n >\n <KeyboardIcon />\n </button>\n {open && <ChartShortcutList3D id={id} rows={rows} />}\n </div>\n )\n}\n\n/** The list of the shortcut panel: per row, its groups of keys and its label. */\nfunction ChartShortcutList3D({ id, rows }: { id: string; rows: Keymap[\"rows\"] }) {\n return (\n <dl\n id={id}\n data-slot=\"chart-3d-shortcuts\"\n className=\"grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-2 shadow-xl\"\n >\n {rows.map(({ label, groups }) => (\n <React.Fragment key={label}>\n <dt className=\"flex flex-wrap gap-x-2 gap-y-1\">\n {groups.map((group, i) => (\n <span key={i} data-slot=\"kbd-group\" className=\"flex gap-1\">\n {group.map((key, j) => (\n <kbd\n key={j}\n data-slot=\"kbd\"\n className=\"pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none\"\n >\n {key}\n </kbd>\n ))}\n </span>\n ))}\n </dt>\n <dd className=\"text-muted-foreground\">{label}</dd>\n </React.Fragment>\n ))}\n </dl>\n )\n}\n\nfunction ChartLegend3D({ config }: { config: ChartConfig }) {\n return (\n <div className=\"flex items-center justify-center gap-4 pt-3\">\n {Object.entries(config).map(([key, item]) => (\n <div key={key} className=\"flex items-center gap-1.5\">\n {item.icon ? (\n <item.icon />\n ) : (\n <span className=\"size-2 rounded-[2px]\" style={{ background: `var(--color-${key})` }} />\n )}\n {item.label ?? key}\n </div>\n ))}\n </div>\n )\n}\n\n/**\n * The walls of the chart box that face away from the camera, with their\n * gridlines, the line of every axis along its edge with the mark of each of\n * its ticks, and the labels of every axis on each of its four edges. Only the\n * edge the axis sits on shows them, so when the axis moves to another edge,\n * its line, its marks and its labels fade from one to the other.\n */\nfunction Axes3D({\n spec,\n world,\n format = {},\n titles = {},\n}: {\n spec: AxesSpec\n world: World\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}) {\n const { camera } = useChart3D()\n const box = intoWorld(axes3D().camera(camera), world)\n const { labels, lines, marks } = labelAxes(box.edges(spec), format, titles)\n\n return (\n <g data-slot=\"chart-3d-axes\">\n {box\n .data(spec)\n .filter((wall) => !wall.ccw)\n .map((wall) => (\n <path\n key={`${wall.axis}${wall.side}`}\n d={box.draw(wall)}\n className=\"fill-muted/40 stroke-border\"\n strokeWidth={0.75}\n />\n ))}\n {lines.map((line) => (\n <AxisLine3D key={line.key} line={line} ink=\"stroke-foreground\" width={1.5} />\n ))}\n {marks.map((mark) => (\n <AxisLine3D key={mark.key} line={mark} ink=\"stroke-foreground/60\" width={1} />\n ))}\n {labels.map((label) => (\n <AxisLabel3D key={label.key} label={label} />\n ))}\n </g>\n )\n}\n\n// The space between a tick and its label, the least space between two\n// labels, and the space over which a label fades as it nears another.\nconst GAP = 10\nconst PAD = 2\nconst FADE = 4\n// How far a label may slide along its edge to make room, before the labels take two rows.\nconst DODGE = 12\n// How far the mark of a tick reaches out from its edge.\nconst MARK = 6\n\n/**\n * A line of an axis: the line that carries its scale along the edge it sits\n * on, or the mark of one of its ticks. Its place follows the camera at once;\n * a change of edge fades it in a transition.\n */\ntype AxisLine = {\n key: string\n from: Point2D\n to: Point2D\n opacity: number\n}\n\n/**\n * A label of the chart box, a tick label or the title of an axis: its box\n * `w`×`h` in the units of the view box, centred at `at` and moved by `shift`\n * along its edge or into a second row.\n */\ntype AxisLabel = {\n key: string\n axis: keyof AxesSpec\n at: Point2D\n w: number\n h: number\n shift: Point2D\n text: React.ReactNode\n opacity: number\n title?: boolean\n}\n\n/**\n * The labels of the axes on all their edges, the line of every axis along its\n * edge and the mark of each of its ticks, shown on the edges the axes sit on.\n * Every edge fits its own tick labels; then the labels of an axis give way to\n * those of an axis with fewer ticks, which say more each, and the titles give\n * way to the ticks.\n */\nfunction labelAxes(\n edges: AxisEdge[],\n format: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>,\n titles: Partial<Record<keyof AxesSpec, React.ReactNode>>\n) {\n // An axis without ticks, such as the rows of an empty chart, has nothing to label.\n const axes = edges\n .filter((edge) => edge.length)\n .map((edge) => edgeLabels(edge, format[edge.axis] ?? String, titles[edge.axis]))\n const shown = axes.filter((axis) => axis.chosen).sort((a, b) => a.ticks.length - b.ticks.length)\n const placed: AxisLabel[] = []\n for (const label of [...shown.flatMap((a) => a.ticks), ...shown.flatMap((a) => a.title ?? [])]) {\n label.opacity = shows(label, placed)\n placed.push(label)\n }\n // The marks fade with their labels, also where a label of another axis takes its place.\n for (const axis of axes) axis.marks.forEach((mark, i) => (mark.opacity = axis.ticks[i].opacity))\n return {\n labels: axes.flatMap((axis) => [...axis.ticks, ...(axis.title ? [axis.title] : [])]),\n lines: axes.map((axis) => axis.line),\n marks: axes.flatMap((axis) => axis.marks),\n }\n}\n\n/**\n * The labels of one edge: a label per tick beside it, away from the box, in\n * the rows that `fit` finds, and the title of the axis beyond them. The\n * labels of an edge the axis does not sit on are there, but do not show.\n */\nfunction edgeLabels(\n edge: AxisEdge,\n format: (value: number) => React.ReactNode,\n title?: React.ReactNode\n) {\n const { axis, normal: n, chosen } = edge\n const label = (key: string, at: Point2D, text: React.ReactNode, h: number, gap: number) => {\n const w = textWidth(text, h)\n return { key, axis, at: beside(at, n, w, h, gap), w, h, shift: ZERO, text, opacity: 1 }\n }\n const id = `${axis}${edge.sides.join(\"\")}`\n // Keyed by value, so a tick that new data keeps glides on as the same label.\n const ticks = edge.map((tick) =>\n label(`${id}-${tick[axis]}`, tick.projected, format(tick[axis]), 10, GAP)\n )\n // How far a row of labels reaches out from the edge.\n const depth = Math.max(...ticks.map((t) => Math.abs(n.x) * t.w + Math.abs(n.y) * t.h))\n const row = { x: n.x * (depth + PAD), y: n.y * (depth + PAD) }\n const rows = fit(ticks, n, row)\n const start = edge[0].projected\n const end = edge[edge.length - 1].projected\n const middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 }\n const head: AxisLabel | undefined = title\n ? { ...label(`${id}-title`, middle, title, 12, GAP + depth + GAP), title: true }\n : undefined\n if (head && rows === 2) head.shift = row\n // The edges the axis does not sit on keep their labels in place, unseen, to fade them in.\n if (!chosen) for (const l of [...ticks, ...(head ? [head] : [])]) l.opacity = 0\n // The axis line runs its edge between its outermost ticks; a mark points out from every\n // tick, as far out as its label is clear of it, and hides where the label does.\n const line: AxisLine = { key: id, from: start, to: end, opacity: chosen ? 1 : 0 }\n const marks = edge.map((tick, i) => ({\n key: ticks[i].key,\n from: tick.projected,\n to: { x: tick.projected.x + n.x * MARK, y: tick.projected.y + n.y * MARK },\n opacity: ticks[i].opacity,\n }))\n return { chosen, ticks, title: head, line, marks }\n}\n\n/**\n * Fits the tick labels of an edge into the space between its ticks: in one\n * row if they keep `PAD` apart, or slid along the edge if no label has to\n * slide further than `DODGE`, else every other label a `row` further out if\n * that is enough, else every `stride`-th label of one row, 2, 4, 8… The\n * labels of a stride are among those of the one before, so as the edge\n * shortens, a label only ever leaves and none comes in for it. Returns the rows.\n */\nfunction fit(ticks: AxisLabel[], normal: Point2D, row: Point2D) {\n if (clear(ticks, 1) || slide(ticks, normal)) return 1\n ticks.forEach((t, i) => (t.shift = i % 2 ? row : ZERO))\n if (clear(ticks, 2)) return 2\n ticks.forEach((t) => (t.shift = ZERO))\n let stride = 2\n while (stride < ticks.length && !clear(ticks, stride, stride)) stride *= 2\n ticks.forEach((t, i) => (t.opacity = i % stride ? 0 : 1))\n return 1\n}\n\n/** Whether every label from every `every`-th keeps `PAD` apart from the one `step` after it. */\nfunction clear(ticks: AxisLabel[], step: number, every = 1) {\n // A hair under PAD, as labels that `slide` sets exactly PAD apart may round to less.\n return ticks.every(\n (t, i) => i % every > 0 || i + step >= ticks.length || apart(t, ticks[i + step]) > PAD - 1e-6\n )\n}\n\n/**\n * Slides the labels of an edge along it, square to its `normal`, as little\n * as they can until each has the room it needs. True if that is enough and\n * no label slides further than `DODGE`; the slide grows from nothing as the\n * labels near, so it follows the camera without a jump.\n */\nfunction slide(ticks: AxisLabel[], normal: Point2D) {\n const t = { x: -normal.y, y: normal.x }\n const along = ({ at }: AxisLabel) => at.x * t.x + at.y * t.y\n // The labels in their order along the edge, whichever way its ticks run.\n const line = [...ticks].sort((a, b) => along(a) - along(b))\n const gaps = line.slice(1).map((b, i) => room(line[i], b, normal, t))\n const placed = dodge(line.map(along), gaps)\n line.forEach((label, i) => {\n const d = placed[i] - along(label)\n label.shift = { x: t.x * d, y: t.y * d }\n })\n return line.every((label, i) => Math.abs(placed[i] - along(label)) <= DODGE) && clear(ticks, 1)\n}\n\n/**\n * How far along `t` the label `b` has to stand from `a`, which comes before\n * it there, for their boxes to keep `PAD` apart, as far as they stand apart\n * along `normal`, square to `t`.\n */\nfunction room(a: AxisLabel, b: AxisLabel, normal: Point2D, t: Point2D) {\n const off = (b.at.x - a.at.x) * normal.x + (b.at.y - a.at.y) * normal.y\n const x = ((a.w + b.w) / 2 + PAD - off * normal.x * Math.sign(t.x)) / Math.abs(t.x)\n const y = ((a.h + b.h) / 2 + PAD - off * normal.y * Math.sign(t.y)) / Math.abs(t.y)\n return Math.min(x, y)\n}\n\n/**\n * Places points on a line in their order, `gaps[i]` at least between the\n * i-th and the next, and moves them as little as it can: points that would\n * come too close move as one block, centred on the places they want.\n */\nfunction dodge(want: number[], gaps: number[]) {\n const blocks: { start: number; offsets: number[]; at: number }[] = []\n want.forEach((at, start) => {\n let block = { start, offsets: [0], at }\n let last = blocks.at(-1)\n while (last && last.at + last.offsets.at(-1)! + gaps[block.start - 1] > block.at) {\n blocks.pop()\n const base = last.offsets.at(-1)! + gaps[block.start - 1]\n const offsets = [...last.offsets, ...block.offsets.map((o) => o + base)]\n const first = last.start\n // Where the block moves its points the least: the mean of the places they want.\n const mean = offsets.reduce((sum, o, k) => sum + want[first + k] - o, 0) / offsets.length\n block = { start: first, offsets, at: mean }\n last = blocks.at(-1)\n }\n blocks.push(block)\n })\n return blocks.flatMap((block) => block.offsets.map((o) => block.at + o))\n}\n\n/**\n * How much of a label shows beside the labels placed before it: it fades as\n * it nears a label of another axis, by as much as that one shows. As this\n * follows the geometry, the label fades as smoothly as the camera turns.\n */\nfunction shows(label: AxisLabel, placed: AxisLabel[]) {\n return placed.reduce(\n (opacity, p) =>\n p.axis === label.axis\n ? opacity\n : Math.min(opacity, 1 - (1 - clamp(0, 1, apart(label, p) / FADE)) * p.opacity),\n label.opacity\n )\n}\n\n/** The space between the boxes of two labels, negative where they overlap. */\nfunction apart(a: AxisLabel, b: AxisLabel) {\n const dx = Math.abs(a.at.x + a.shift.x - b.at.x - b.shift.x) - (a.w + b.w) / 2\n const dy = Math.abs(a.at.y + a.shift.y - b.at.y - b.shift.y) - (a.h + b.h) / 2\n return Math.max(dx, dy)\n}\n\n/**\n * The centre of a box `w`×`h` that lies `gap` from `at` towards `toward`, a\n * unit vector. As the vector turns, the box slides round `at` and keeps the\n * gap, where an anchor that switches from start to end would jump.\n */\nfunction beside(at: Point2D, toward: Point2D, w: number, h: number, gap: number): Point2D {\n const out = gap + (Math.abs(toward.x) * w + Math.abs(toward.y) * h) / 2\n return { x: at.x + toward.x * out, y: at.y + toward.y * out }\n}\n\n/** The width of a label at the font size `size`, guessed from its text, as the browser lays it out only after the render. */\nfunction textWidth(text: React.ReactNode, size: number) {\n // ponytail: 0.6em a character; measure with getBBox if wide fonts or rich labels still overlap.\n const chars = typeof text === \"string\" || typeof text === \"number\" ? String(text).length : 4\n return chars * size * 0.6\n}\n\n/**\n * A line of the axes, in the ink of the kind it is: the line of an axis along\n * its edge, or the mark of one of its ticks. Its place follows the camera at\n * once; a change of edge fades it in a transition.\n */\nfunction AxisLine3D({\n line: { from, to, opacity },\n ink,\n width,\n}: {\n line: AxisLine\n ink: string\n width: number\n}) {\n return (\n <line\n x1={from.x}\n y1={from.y}\n x2={to.x}\n y2={to.y}\n strokeWidth={width}\n style={{ opacity: Math.round(opacity * 100) / 100 }}\n className={cn(\"transition-opacity duration-200 ease-out motion-reduce:transition-none\", ink)}\n />\n )\n}\n\n/**\n * A label of the chart box. Its place follows the camera at once; a change\n * of edge, of row or of the labels that fit fades and moves it in a transition.\n */\nfunction AxisLabel3D({ label: { at, shift, opacity, text, title } }: { label: AxisLabel }) {\n return (\n <text\n x={at.x}\n y={at.y}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n style={{ opacity: Math.round(opacity * 100) / 100, translate: `${shift.x}px ${shift.y}px` }}\n className={cn(\n \"transition-[opacity,translate] duration-200 ease-out motion-reduce:transition-none\",\n title ? \"fill-foreground font-medium\" : \"fill-muted-foreground text-[10px]\"\n )}\n >\n {text}\n </text>\n )\n}\n\n/** A nice axis from `lo` to `hi` with about `count` ticks. */\nfunction axis(lo: number, hi: number, count = 5): AxisSpec {\n const [start, stop] = nice(lo, lo === hi ? hi + 1 : hi, count)\n return { domain: [start, stop], ticks: ticks(start, stop, count) }\n}\n\n/**\n * The axis `spec` with its domain widened by half a `cell` on each side, so\n * the box keeps room between the outermost data and its walls. The ticks stay\n * where they were, on the data.\n */\nfunction pad(spec: AxisSpec, cell: number): AxisSpec {\n return { domain: [spec.domain[0] - cell / 2, spec.domain[1] + cell / 2], ticks: spec.ticks }\n}\n\n/** The linear map from `domain` to `range`. */\nfunction linear([d0, d1]: number[], [r0, r1]: number[]) {\n return (value: number) => r0 + ((value - d0) / (d1 - d0 || 1)) * (r1 - r0)\n}\n\n/** The world box of `spec`: x from -1 to 1, y up from 1 to -1, z from -`depth` to `depth`. */\nfunction worldBox(spec: AxesSpec, depth = 1): World {\n return {\n x: linear(spec.x.domain, [-1, 1]),\n y: linear(spec.y.domain, [1, -1]),\n z: linear(spec.z.domain, [-depth, depth]),\n }\n}\n\n/**\n * Hands the projection its accessors into the world box, so every chart maps\n * its shapes onto the screen the same way.\n */\nfunction intoWorld<Datum extends Point3D, T extends ShapeInstance<Datum>>(\n projection: T,\n world: World\n): T {\n return projection\n .x((p) => world.x(p.x))\n .y((p) => world.y(p.y))\n .z((p) => world.z(p.z))\n}\n\n// From the upper left, towards the viewer, in view space where y points down.\nconst LIGHT = { x: -0.4, y: -0.8, z: 0.44 }\n\n/**\n * `color` lit by the light from the upper left: the face that looks at it\n * keeps the color, one that turns away gets darker. A CSS color-mix, so the\n * shade follows the theme variables.\n */\nfunction shade(face: TransformedPoint<unknown>[], color: string) {\n const n = normal(face.map((p) => p.rotated))\n // The normal of the side the camera sees, whichever way the face winds.\n const side = n.z < 0 ? -1 : 1\n const light = Math.max(0, side * (n.x * LIGHT.x + n.y * LIGHT.y + n.z * LIGHT.z))\n return `color-mix(in oklch, ${color} ${Math.round(65 + 35 * light)}%, black)`\n}\n\n/** `color` out of focus: a quarter of it over the background, opaque, so the seams between faces stay closed. */\nfunction fade(color: string) {\n return `color-mix(in oklch, ${color} 25%, var(--background))`\n}\n\n/** The mean of the projected points, where a tooltip points at. */\nfunction center(points: TransformedPoint<unknown>[]): Point2D {\n const sum = points.reduce((s, p) => ({ x: s.x + p.projected.x, y: s.y + p.projected.y }), {\n x: 0,\n y: 0,\n })\n return { x: sum.x / points.length, y: sum.y / points.length }\n}\n\n/** The marks of a cube: its faces that look at the camera, shaded in `color`, each with `tooltip` on hover. */\nfunction cubeMarks(id: string, faces: CubeFace[], color: string, tooltip: Tooltip3D): Mark3D[] {\n // The faces point outwards: a convex shape shows the ones facing the camera.\n return faces\n .filter((face) => face.ccw)\n .map((face) => ({\n key: `${id}-${face.face}`,\n points: face.map((p) => p.projected),\n fill: shade(face, color),\n tooltip,\n }))\n}\n\nexport {\n ChartContainer3D,\n ChartLegend3D,\n Axes3D,\n Marks3D,\n Labels3D,\n axis,\n pad,\n linear,\n worldBox,\n intoWorld,\n shade,\n center,\n cubeMarks,\n useTween,\n useTweenAxes,\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { box, cubes3D, sort, type AxesSpec, type CubeFace } from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n center,\n cubeMarks,\n pad,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n type World,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type BarChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {\n /** One entry per row of bars, with a value per series. */\n data: T[]\n /** The field that names each entry, such as \"month\". */\n index: keyof T & string\n /**\n * The fields that hold the series, one row of bars each.\n * @defaultValue the keys of the chart config\n */\n keys?: string[]\n /**\n * The share of its cell a bar covers.\n * @defaultValue 0.6\n */\n barSize?: number\n /** Formats the labels of the entries along x and the values along y. */\n format?: { x?: (label: string) => React.ReactNode; y?: (value: number) => React.ReactNode }\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * Bars on a floor: one row per entry of `data` along x, one per series\n * along z, the value as the height. The series are the keys of the chart\n * config unless `keys` names them.\n */\nexport function BarChart3D<T extends Record<string, unknown>>({\n data,\n index,\n keys,\n barSize = 0.6,\n format = {},\n titles,\n}: BarChart3DProps<T>) {\n const { config, camera } = useChart3D()\n const series = keys ?? Object.keys(config)\n // A value that is not a number stands as no bar, one of height 0; a new one grows from the floor.\n const target = barValues(data, series)\n const values = useTween(target, 0)\n const cells = barCells(data, series, values)\n\n const box = barBox(data.length, series.length, Object.values(target), barSize)\n // The value axis glides with the bars; the rows and the series stand where they are.\n const spec = { ...box.spec, y: useTweenAxes(box.spec).y }\n const world = worldBox(spec, box.depth)\n const { size } = box\n const bars = cubes3D()\n .camera(camera)\n .data(\n cells.map(({ i, j, key, value }) =>\n Object.assign(barCorners(world, i, j, value, size), { i, key, value })\n )\n )\n .map((bar) => Object.assign(bar, { bottom: bar.faces.find((f) => f.face === \"bottom\")! }))\n // The bars stand on one floor, so they paint back to front by their footprint.\n .sort((a, b) => sort(a.bottom, b.bottom))\n\n return (\n <>\n <Axes3D\n spec={spec}\n world={world}\n titles={titles}\n format={{\n // The ticks along x are the indices of the entries.\n x: (i) => (format.x ?? String)(String(data[i][index] ?? \"\")),\n y: format.y,\n z: (j) => config[series[j]]?.label ?? series[j],\n }}\n />\n <Marks3D\n marks={bars.flatMap((bar) =>\n barMarks({\n id: `${bar.i}-${bar.key}`,\n faces: bar.faces,\n color: `var(--color-${bar.key})`,\n title: String(data[bar.i][index]),\n label: config[bar.key]?.label ?? bar.key,\n value: bar.value,\n })\n )}\n />\n </>\n )\n}\n\n/** The cell of every bar: the entry `i` along x, the series `key` along z, with its tweened value. */\nfunction barCells<T extends Record<string, unknown>>(\n data: T[],\n series: string[],\n values: Record<string, number>\n) {\n return data.flatMap((_, i) =>\n series.map((key, j) => ({ i, j, key, value: values[`${i}-${key}`] }))\n )\n}\n\n/**\n * The value of every cell of the chart, keyed as its mark: the entry `i`\n * along x and the series `key` along z, standing as 0 where the entry holds none.\n */\nfunction barValues<T extends Record<string, unknown>>(data: T[], series: string[]) {\n return Object.fromEntries(\n data.flatMap((d, i) => series.map((key) => [`${i}-${key}`, Number(d[key]) || 0]))\n )\n}\n\n/**\n * The box of a bar chart: a row per entry along x, a row per series along z,\n * with half a cell of room between the outer rows and the walls, and the\n * size of a bar, the share `barSize` of its cell.\n */\nfunction barBox(entries: number, series: number, values: number[], barSize: number) {\n const index = (length: number) => Array.from({ length }, (_, i) => i)\n const spec: AxesSpec = {\n x: pad({ domain: [-0.5, entries - 0.5], ticks: index(entries) }, 1),\n y: axis(Math.min(0, ...values), Math.max(0, ...values)),\n z: pad({ domain: [-0.5, series - 0.5], ticks: index(series) }, 1),\n }\n // A shallow box for few series, so the bars stay square.\n const depth = Math.min(1, Math.max(0.25, series / entries))\n // A bar covers `barSize` of its cell, the share of the domain the cell spans.\n const size = {\n width: (2 / (spec.x.domain[1] - spec.x.domain[0])) * barSize,\n depth: ((2 * depth) / (spec.z.domain[1] - spec.z.domain[0])) * barSize,\n }\n return { spec, depth, size }\n}\n\n/**\n * The corners of one bar, from the floor to its value, at row `x` and series\n * `z`. box() rises towards -y, so a negative bar starts at its value.\n */\nfunction barCorners(\n world: World,\n x: number,\n z: number,\n value: number,\n size: { width: number; depth: number }\n) {\n const floor = world.y(0)\n const top = world.y(value)\n return box({\n x: world.x(x),\n y: Math.max(floor, top),\n z: world.z(z),\n ...size,\n height: Math.abs(floor - top),\n })\n}\n\n/** The marks of one bar: the faces that look at the camera, shaded, each with its entry and value on hover. */\nfunction barMarks({\n id,\n faces,\n color,\n title,\n label,\n value,\n}: {\n id: string\n faces: CubeFace[]\n color: string\n title: string\n label: React.ReactNode\n value: number\n}) {\n const tooltip = {\n at: center(faces.find((face) => face.face === \"top\")!),\n title,\n items: [{ label, value, color }],\n }\n return cubeMarks(id, faces, color, tooltip)\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { extent } from \"d3-array\"\nimport { points3D, sort, type AxesSpec } from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type ScatterChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {\n /** One entry per point. */\n data: T[]\n /** The field of the position along x. */\n x: keyof T & string\n /** The field of the position along y, the height. */\n y: keyof T & string\n /** The field of the position along z. */\n z: keyof T & string\n /**\n * The field whose value is the config key of the color of a point.\n * @defaultValue the first key of the chart config for every point\n */\n series?: keyof T & string\n /**\n * The radius of a point in the units of the view box.\n * @defaultValue 4\n */\n radius?: number\n /** Formats the tick labels of each axis. */\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * Points in the chart box, at the fields `x`, `y` and `z` of each entry.\n * `series` names the field whose value is the config key of the color.\n */\nexport function ScatterChart3D<T extends Record<string, unknown>>({\n data,\n x,\n y,\n z,\n series,\n radius = 4,\n format,\n titles,\n}: ScatterChart3DProps<T>) {\n const { config, camera } = useChart3D()\n const fields = { x, y, z }\n // The positions glide entry by entry, so the points, the axes and the tooltips follow.\n const values = useTween(pointValues(data, fields))\n const read = (i: number, axis: keyof AxesSpec) => values[`${axis}${i}`]\n\n // The axes of the data the chart glides into; their ends glide along.\n const spec = useTweenAxes(pointAxes(data, fields))\n const world = worldBox(spec)\n\n const points = points3D<{ d: T; i: number }>()\n .camera(camera)\n .x(({ i }) => world.x(read(i, \"x\")))\n .y(({ i }) => world.y(read(i, \"y\")))\n .z(({ i }) => world.z(read(i, \"z\")))\n const fallback = Object.keys(config)[0]\n\n const marks = points\n .data(data.map((d, i) => ({ d, i })))\n .sort(sort)\n .map((p) => {\n const key = series ? String(p.d[series]) : fallback\n return {\n key: String(p.i),\n points: [p.projected],\n r: radius,\n fill: `var(--color-${key})`,\n // Ringed by the background, so that points in front stand out.\n stroke: \"var(--background)\",\n tooltip: {\n at: p.projected,\n title: series ? (config[key]?.label ?? key) : undefined,\n items: ([\"x\", \"y\", \"z\"] as const).map((a) => ({\n label: titles?.[a] ?? fields[a],\n value: read(p.i, a),\n })),\n },\n }\n })\n\n return (\n <>\n <Axes3D spec={spec} world={world} format={format} titles={titles} />\n <Marks3D marks={marks} />\n </>\n )\n}\n\n/** The axes that hold every entry of `data`, a nice one per field. */\nfunction pointAxes<T extends Record<string, unknown>>(\n data: T[],\n fields: Record<keyof AxesSpec, keyof T & string>\n): AxesSpec {\n const range = (a: keyof AxesSpec) => {\n const [lo = 0, hi = 0] = extent(data, (d) => Number(d[fields[a]]))\n return axis(lo, hi)\n }\n return { x: range(\"x\"), y: range(\"y\"), z: range(\"z\") }\n}\n\n/** The position of every entry, keyed by its axis and index, gliding into new data. */\nfunction pointValues<T extends Record<string, unknown>>(\n data: T[],\n fields: Record<keyof AxesSpec, keyof T & string>\n) {\n return Object.fromEntries(\n data.flatMap((d, i) =>\n ([\"x\", \"y\", \"z\"] as const).map((a) => [`${a}${i}`, Number(d[fields[a]])])\n )\n )\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { extent } from \"d3-array\"\nimport { gridPlanes3D, sort, type AxesSpec, type Point3D } from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n center,\n intoWorld,\n linear,\n pad,\n shade,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type SurfaceChart3DProps = {\n /** The heights on the grid, `data[row][column]`. */\n data: number[][]\n /**\n * The data values the first and the last column (x) and row (z) stand for.\n * The chart keeps half a cell between the grid and the walls of its box; a\n * domain given here names the box exactly, without that room.\n * @defaultValue the indices of the columns and rows\n */\n domain?: { x?: [number, number]; z?: [number, number] }\n /**\n * The config keys of the colors at the lowest and at the highest height.\n * @defaultValue the first two keys of the chart config\n */\n colors?: [string, string]\n /** Formats the tick labels of each axis. */\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * A surface over a grid: `data[row][column]` is the height, the columns run\n * along x and the rows along z. The fill ramps from the first color of\n * `colors` at the lowest height to the second at the highest; both are keys\n * of the chart config, by default its first two.\n */\nexport function SurfaceChart3D({ data, domain = {}, colors, format, titles }: SurfaceChart3DProps) {\n const { config, camera } = useChart3D()\n const [low, high = low] = colors ?? Object.keys(config)\n // The heights glide cell by cell, so the surface, its color ramp and the y axis follow.\n const tweened = useTween(gridValues(data))\n const heights = data.map((row, r) => row.map((_, c) => tweened[`${r}-${c}`]))\n const rows = data.length\n const columns = data[0]?.length ?? 0\n const [x0, x1] = domain.x ?? [0, columns - 1]\n const [z0, z1] = domain.z ?? [0, rows - 1]\n // A cell of the grid, along x and along z, in the values the data stands for.\n const cell = {\n x: (x1 - x0) / Math.max(1, columns - 1),\n z: (z1 - z0) / Math.max(1, rows - 1),\n }\n // The color ramp follows the heights on screen, the axes glide to those of the data.\n const [lo = 0, hi = 0] = extent(heights.flat())\n const [floor = 0, peak = 0] = extent(data.flat())\n\n // The box keeps half a cell beyond the grid; a domain the reader hands the\n // chart names the box exactly.\n const spec = useTweenAxes({\n x: domain.x ? axis(x0, x1) : pad(axis(x0, x1), cell.x),\n y: axis(floor, peak),\n z: domain.z ? axis(z0, z1) : pad(axis(z0, z1), cell.z),\n })\n const world = worldBox(spec)\n const toX = linear([0, columns - 1], [x0, x1])\n const toZ = linear([0, rows - 1], [z0, z1])\n\n const grid = intoWorld(gridPlanes3D<Point3D>().camera(camera), world)\n // d3-3d reads rows(0) as the getter; a grid without columns has no points anyway.\n .rows(Math.max(1, columns))\n const points = heights.flatMap((row, r) => row.map((y, c) => ({ x: toX(c), y, z: toZ(r) })))\n\n const marks = grid\n .data(points)\n .sort(sort)\n .map((quad) => {\n const height = quad.reduce((sum, p) => sum + p.y, 0) / quad.length\n const t = Math.round(((height - lo) / (hi - lo || 1)) * 100)\n return {\n key: quad.plane,\n points: quad.map((p) => p.projected),\n fill: shade(quad, `color-mix(in oklch, var(--color-${high}) ${t}%, var(--color-${low}))`),\n tooltip: { at: center(quad), items: [{ label: titles?.y ?? \"value\", value: height }] },\n }\n })\n\n return (\n <>\n <Axes3D spec={spec} world={world} format={format} titles={titles} />\n <Marks3D marks={marks} />\n </>\n )\n}\n\n/** The height of every cell, keyed by its row and column, gliding into new data. */\nfunction gridValues(data: number[][]) {\n return Object.fromEntries(data.flatMap((row, r) => row.map((y, c) => [`${r}-${c}`, y])))\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { cubes3D, sort, type Camera3DInstance, type Cube, type CubeFace, type Point3D } from \"d3-3d\"\n\nimport {\n Labels3D,\n Marks3D,\n center,\n cubeMarks,\n useChart3D,\n useTween,\n type ChartConfig,\n type Label3D,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type SankeyChart3DProps = {\n /** One entry per flow. `source` and `target` are keys of the chart config, which names and colors the nodes. */\n data: { source: string; target: string; value: number }[]\n /**\n * The width of a node, as a share of the distance between two columns.\n * @defaultValue 0.2\n */\n nodeWidth?: number\n /**\n * The gap between two nodes of a column, as a share of the height.\n * @defaultValue 0.05\n */\n nodePadding?: number\n /** Formats the values in the tooltip. */\n format?: (value: number) => React.ReactNode\n}\n\n// The depth of a node in world units, and the share of it a flow takes.\nconst DEPTH = 0.4\nconst RIBBON = 0.7\n// The slices of a flow from one column to the next: the more, the smoother it bends.\nconst SEGMENTS = 16\n// Where flows cross, they share the depth of a flow, each in a lane. The way into the lanes\n// turns a face at most this steeply; where it would turn one steeper, the lanes start at the node.\nconst STEEPEST = 1.5\n// Closer than this on the screen, the two sides of a node lift its label over it.\nconst SWING = 8\n\n/**\n * A node of the layout, from its top `y0` to its bottom `y1` in the world. A\n * node with a `flow` is a waypoint, where a flow that skips a column passes it.\n */\ntype SankeyNode = {\n id: string\n column: number\n value: number\n y0: number\n y1: number\n incoming: Hop[]\n outgoing: Hop[]\n flow?: Flow\n}\n\n/** An entry of `data` between its two nodes. */\ntype Flow = { key: string; source: SankeyNode; target: SankeyNode; value: number }\n\n/**\n * The part of a flow from one column to the next, from the middle of its slot\n * at the source, `y0`, to the one at the target, `y1`. A hop that crosses\n * others belongs to their `knot` and narrows into its lane, around the depth\n * `z`, while it passes them.\n */\ntype Hop = {\n flow: Flow\n source: SankeyNode\n target: SankeyNode\n y0: number\n y1: number\n z: number\n knot?: Knot\n}\n\n/**\n * Hops of one gap that cross, directly or through one another. Their lanes,\n * each `depth` deep, hold from the cross-section `from` to `to`, counted in\n * slices, and `first`, the topmost at the source, stands for the height of the knot.\n */\ntype Knot = { from: number; to: number; first: Hop; depth: number }\n\n/**\n * A part of the chart in the world: a node, or a slice of a flow that has come\n * the share `t` of its way there. `band` is the middle of the slab between two\n * planes x = const that the part lies in; `row`, `lane` and `level`, the height\n * of its knot, the depth of its lane and its own height, order it within the slab.\n */\ntype Piece = Point3D[] & {\n key: string\n band: number\n row: number\n lane: number\n level: number\n node?: SankeyNode\n flow?: Flow\n t: number\n}\n\n/**\n * Flows from left to right: every node a box in its column, as high as the\n * larger of what flows in and what flows out, and every flow a band from node\n * to node, as thick as its value, that turns from the color of its source to\n * the color of its target.\n */\nexport function SankeyChart3D({\n data,\n nodeWidth = 0.2,\n nodePadding = 0.05,\n format = (value) => value,\n}: SankeyChart3DProps) {\n const { config, camera } = useChart3D()\n // The values glide flow by flow, a new one growing from 0; the layout follows them.\n const values = useTween(Object.fromEntries(data.map((d, i) => [String(i), d.value])), 0)\n const flows = data.map((d, i) => ({ ...d, value: values[String(i)] }))\n const { nodes, columns, ky } = sankeyLayout(flows, nodePadding)\n const pieces = depthSort(\n cubes3D()\n .camera(camera)\n .data(sankeyPieces(nodes, columns, ky, nodeWidth)),\n camera\n )\n // The labels sit outside: left of the nodes in the left half, right of the others.\n const labels = pieces.flatMap(({ key, faces, node }) =>\n node\n ? [\n nodeLabel(\n key,\n faces,\n node.column < (columns - 1) / 2 ? \"left\" : \"right\",\n style(config, node).label,\n links(node)\n ),\n ]\n : []\n )\n\n return (\n <>\n <Marks3D marks={pieces.flatMap((piece) => pieceMarks(piece, config, format))} />\n <Labels3D labels={labels} />\n </>\n )\n}\n\n/** The label and the color of a node, from the chart config. */\nfunction style(config: ChartConfig, node: SankeyNode) {\n return {\n label: config[node.id]?.label ?? node.id,\n color: config[node.id] ? `var(--color-${node.id})` : \"var(--muted-foreground)\",\n }\n}\n\n/**\n * The keys of the flows at a node. Its marks and its label carry them, so the\n * focus on the node lights its flows and the nodes at their other ends, and\n * the focus on a flow lights its two nodes.\n */\nfunction links(node: SankeyNode) {\n return [...new Set([...node.incoming, ...node.outgoing].map((hop) => hop.flow.key))]\n}\n\n/**\n * The marks of a piece, each with its tooltip and its groups: the faces of a\n * node, or the faces of a slice of a flow, in the color it has turned to there.\n */\nfunction pieceMarks(\n { key, faces, node, flow, t }: Cube<Point3D, Piece>,\n config: ChartConfig,\n format: (value: number) => React.ReactNode\n) {\n const at = center(faces.find((face) => face.face === \"top\")!)\n if (node) {\n const { label, color } = style(config, node)\n const groups = links(node)\n return cubeMarks(key, faces, color, {\n at,\n items: [{ label, value: format(node.value), color }],\n }).map((mark) => ({ ...mark, groups }))\n }\n const source = style(config, flow!.source)\n const target = style(config, flow!.target)\n const item = {\n label: (\n <>\n {source.label} → {target.label}\n </>\n ),\n value: format(flow!.value),\n color: source.color,\n }\n // The ends of a slice are joints, inside the flow or against a node.\n const sides = faces.filter((face) => face.face !== \"left\" && face.face !== \"right\")\n // A flow is softer than the nodes, a quarter towards the background, so that they stand out of it.\n const gradient = `color-mix(in oklch, color-mix(in oklch, ${target.color} ${t}%, ${source.color}) 75%, var(--background))`\n return cubeMarks(key, sides, gradient, { at, items: [item] }).map((mark) => ({\n ...mark,\n groups: [flow!.key],\n }))\n}\n\n/** The nodes of `data`, waypoints included, stacked in their columns, and `ky`, the world units per value. */\nfunction sankeyLayout(data: SankeyChart3DProps[\"data\"], nodePadding: number) {\n const { nodes, flows, columns } = sankeyColumns(data)\n const all = sankeyHops(nodes, flows)\n const ky = stackColumns(all, columns, nodePadding)\n stackHops(all, ky)\n weaveHops(all, columns, ky)\n return { nodes: all, columns, ky }\n}\n\nfunction newNode(id: string, column: number, flow?: Flow): SankeyNode {\n return { id, column, value: 0, y0: 0, y1: 0, incoming: [], outgoing: [], flow }\n}\n\nfunction middle(node: SankeyNode) {\n return (node.y0 + node.y1) / 2\n}\n\n/**\n * The nodes of `data` in the order they first appear, and the flows between\n * them, without the ones of no value. The column of a node is the longest\n * path to it from a source; the sinks move to the last column.\n */\nfunction sankeyColumns(data: SankeyChart3DProps[\"data\"]) {\n const nodes = new Map<string, SankeyNode>()\n const node = (id: string) => {\n if (!nodes.has(id)) nodes.set(id, newNode(id, 0))\n return nodes.get(id)!\n }\n // A flow is known by its ends, a second one between the same nodes by its count, so its\n // key, and with it a focus on the flow, outlasts new data.\n const seen = new Map<string, number>()\n const flows = data\n .filter((d) => d.value > 0)\n .map((d) => {\n const ends = JSON.stringify([d.source, d.target])\n const count = seen.get(ends) ?? 0\n seen.set(ends, count + 1)\n return {\n key: count ? `${ends}#${count}` : ends,\n source: node(d.source),\n target: node(d.target),\n value: d.value,\n }\n })\n\n // Bellman-Ford for the longest paths: a pass more than there are nodes means a cycle.\n for (let pass = 0; flows.some((f) => f.target.column <= f.source.column); pass += 1) {\n if (pass === nodes.size) throw new Error(\"SankeyChart3D: the flows form a cycle\")\n for (const f of flows) f.target.column = Math.max(f.target.column, f.source.column + 1)\n }\n const last = Math.max(0, ...flows.map((f) => f.target.column))\n const sources = new Set(flows.map((f) => f.source))\n for (const n of nodes.values()) if (!sources.has(n)) n.column = last\n return { nodes: [...nodes.values()], flows, columns: last + 1 }\n}\n\n/**\n * Splits every flow into hops from one column to the next. A flow that skips a\n * column passes it at a waypoint, a node of its own, so it has a slot in every\n * column it crosses and never runs through another node.\n */\nfunction sankeyHops(nodes: SankeyNode[], flows: Flow[]) {\n const all = [...nodes]\n for (const flow of flows) {\n let source = flow.source\n for (let column = source.column + 1; column <= flow.target.column; column += 1) {\n const target =\n column < flow.target.column ? newNode(`${flow.key}:${column}`, column, flow) : flow.target\n if (target.flow) all.push(target)\n const hop = { flow, source, target, y0: 0, y1: 0, z: 0 }\n source.outgoing.push(hop)\n target.incoming.push(hop)\n source = target\n }\n }\n return all\n}\n\n/**\n * Sizes the nodes to the largest scale at which every column fits, and stacks\n * each column from the top, centered. A column after the first orders its nodes\n * by the mean height of their sources, which uncrosses most flows. Returns the\n * scale, world units per value.\n */\nfunction stackColumns(nodes: SankeyNode[], columns: number, nodePadding: number) {\n const total = (hops: Hop[]) => hops.reduce((sum, hop) => sum + hop.flow.value, 0)\n for (const node of nodes) node.value = Math.max(total(node.incoming), total(node.outgoing))\n const stacks = Array.from({ length: columns }, (_, c) => nodes.filter((n) => n.column === c))\n const sum = (stack: SankeyNode[]) => stack.reduce((s, n) => s + n.value, 0)\n // A crowded column narrows the gaps, so that its nodes keep a height.\n const pad = Math.min(2 * nodePadding, 2 / Math.max(1, ...stacks.map((s) => s.length)))\n const ky = Math.min(...stacks.map((s) => (2 - pad * (s.length - 1)) / sum(s)))\n const mean = (node: SankeyNode) =>\n node.incoming.reduce((s, hop) => s + hop.flow.value * middle(hop.source), 0) /\n total(node.incoming)\n\n for (const [c, stack] of stacks.entries()) {\n if (c > 0) stack.sort((a, b) => mean(a) - mean(b))\n let y = -(sum(stack) * ky + pad * (stack.length - 1)) / 2\n for (const node of stack) {\n node.y0 = y\n node.y1 = y + node.value * ky\n y = node.y1 + pad\n }\n }\n return ky\n}\n\n/**\n * Stacks the hops at every node from its top: the ones that leave it in the\n * order of their targets, the ones that arrive in the order of their sources,\n * so that the hops of a node do not cross.\n */\nfunction stackHops(nodes: SankeyNode[], ky: number) {\n for (const node of nodes) {\n let y = node.y0\n for (const hop of node.outgoing.sort((a, b) => middle(a.target) - middle(b.target))) {\n hop.y0 = y + (hop.flow.value * ky) / 2\n y += hop.flow.value * ky\n }\n y = node.y0\n for (const hop of node.incoming.sort((a, b) => middle(a.source) - middle(b.source))) {\n hop.y1 = y + (hop.flow.value * ky) / 2\n y += hop.flow.value * ky\n }\n }\n}\n\n/**\n * Parts the hops that cross, gap by gap. The hops of a gap that cross, directly\n * or through one another, form a knot. The knots of a gap lie one above the\n * other across the whole gap; only the hops within a knot share their depth in lanes.\n */\nfunction weaveHops(nodes: SankeyNode[], columns: number, ky: number) {\n for (let column = 0; column < columns - 1; column += 1) {\n const hops = nodes\n .filter((node) => node.column === column)\n .flatMap((node) => node.outgoing)\n .sort((a, b) => a.y0 - b.y0)\n const rank = new Map([...hops].sort((a, b) => a.y1 - b.y1).map((hop, i) => [hop, i]))\n // A knot closes where the hops that leave first are also the ones that arrive first.\n let start = 0\n let reach = 0\n hops.forEach((hop, i) => {\n reach = Math.max(reach, rank.get(hop)!)\n if (reach > i) return\n if (i > start) knotHops(hops.slice(start, i + 1), ky)\n start = i + 1\n })\n }\n}\n\n/**\n * The lanes of a knot. Every hop takes the lowest lane that no hop crossing it\n * holds, which needs the fewest, and the lightest lane goes to the front. The\n * lanes share the depth of a flow, a third of a lane apart, so nothing reaches\n * out of it. The hops hold their lanes over the slices where any two of them\n * overlap, so their depth is constant there, and leave the rest for the way in\n * and out.\n */\nfunction knotHops(hops: Hop[], ky: number) {\n const lanes: number[] = []\n // In the order of their sources, a hop crosses every earlier one that arrives below it.\n for (const [i, hop] of hops.entries()) {\n const taken = hops.slice(0, i).flatMap((above, j) => (above.y1 > hop.y1 ? [lanes[j]] : []))\n let lane = 0\n while (taken.includes(lane)) lane += 1\n lanes.push(lane)\n }\n const count = Math.max(...lanes) + 1\n const load = (lane: number) =>\n hops.reduce((sum, hop, i) => sum + (lanes[i] === lane ? hop.flow.value : 0), 0)\n const front = Array.from({ length: count }, (_, lane) => lane).sort((a, b) => load(a) - load(b))\n const slices = hops.flatMap((a, i) =>\n hops.slice(i + 1).flatMap((b) => (a.y1 > b.y1 ? overlaps(a, b, ky) : []))\n )\n // count lanes and count − 1 gaps of a third of a lane fill the depth of a flow.\n const ribbon = RIBBON * DEPTH\n const depth = (3 * ribbon) / (4 * count - 1)\n const knot = { from: Math.min(...slices), to: Math.max(...slices) + 1, first: hops[0], depth }\n for (const [i, hop] of hops.entries()) {\n hop.z = (ribbon - depth) / 2 - (front.indexOf(lanes[i]) * 4 * depth) / 3\n hop.knot = knot\n }\n}\n\n/**\n * The slices in which two hops, `a` and `b`, overlap in height. Along a slice\n * their distance runs straight from one cross-section to the next, so they\n * overlap in it if they are closer than half their thicknesses at one of its\n * ends, or pass each other within it.\n */\nfunction overlaps(a: Hop, b: Hop, ky: number) {\n const apart = (k: number) => a.y0 - b.y0 + (a.y1 - b.y1 - (a.y0 - b.y0)) * ease(k / SEGMENTS)\n const near = ((a.flow.value + b.flow.value) * ky) / 2\n return Array.from({ length: SEGMENTS }, (_, k) => k).filter(\n (k) =>\n Math.abs(apart(k)) < near ||\n Math.abs(apart(k + 1)) < near ||\n Math.sign(apart(k)) !== Math.sign(apart(k + 1))\n )\n}\n\n/** The S-curve of a flow, from 0 at t = 0 to 1 at t = 1, level at both ends. */\nfunction ease(t: number) {\n return t * t * (3 - 2 * t)\n}\n\n/**\n * How far a hop of `knot` has moved into its lane at the cross-section `k`:\n * not at all at a node, fully between the borders of the knot, and along the\n * S-curve in between. A knot that starts at a node starts there in its lanes.\n */\nfunction bump(k: number, knot?: Knot) {\n if (!knot) return 0\n if (k < knot.from) return ease(k / knot.from)\n if (k > knot.to) return ease((SEGMENTS - k) / (SEGMENTS - knot.to))\n return 1\n}\n\n/**\n * The pieces of the chart: a box per node, a flat slice of its flow per\n * waypoint and `SEGMENTS` slices per hop. The columns stand from x = -1 to 1,\n * a node the share `nodeWidth` of the distance between two of them wide.\n */\nfunction sankeyPieces(nodes: SankeyNode[], columns: number, ky: number, nodeWidth: number) {\n const step = 2 / Math.max(1, columns - 1)\n const x = (column: number) => -1 + column * step\n const half = (nodeWidth * step) / 2\n // How far a flow has come at `at`, from the side of its source to the side of its target, in percent.\n const share = (flow: Flow, at: number) => {\n const from = x(flow.source.column) + half\n return Math.round(((at - from) / (x(flow.target.column) - half - from)) * 100)\n }\n\n return nodes.flatMap((node): Piece[] => {\n const band = x(node.column)\n const y = middle(node)\n const own = node.flow\n ? { key: `way:${node.id}`, band, flow: node.flow, t: share(node.flow, band) }\n : { key: `node:${node.id}`, band, node, t: 0 }\n const d = node.flow ? RIBBON * DEPTH : DEPTH\n const box = slab(\n { x: band - half, y, z: 0, d },\n { x: band + half, y, z: 0, d },\n node.y1 - node.y0\n )\n return [\n Object.assign(box, own, { row: y, lane: 0, level: y }),\n ...node.outgoing.flatMap((hop) =>\n hopPieces(hop, band + half, x(node.column + 1) - half, ky, share)\n ),\n ]\n })\n}\n\n/**\n * The slices of a hop from `x0` to `x1`, along an S-curve that leaves and\n * arrives level, so that the hops of a flow join without a kink. A hop of a\n * knot narrows into its lane and widens back along the same curve. Every hop\n * between the same two columns has the same slices.\n */\nfunction hopPieces(\n hop: Hop,\n x0: number,\n x1: number,\n ky: number,\n share: (flow: Flow, at: number) => number\n): Piece[] {\n const ribbon = RIBBON * DEPTH\n // The S-curve turns a face steepest in its middle, at 1.5 times its mean slope, so a way into\n // the lanes over `slices` that would turn one steeper than STEEPEST starts in the lanes instead.\n const gentle = (slices: number, depth: number) =>\n ((ribbon - depth) * 1.5) / ((slices * (x1 - x0)) / SEGMENTS) <= STEEPEST\n const knot = hop.knot && {\n ...hop.knot,\n from: gentle(hop.knot.from, hop.knot.depth) ? hop.knot.from : 0,\n to: gentle(SEGMENTS - hop.knot.to, hop.knot.depth) ? hop.knot.to : SEGMENTS,\n }\n const at = (of: Hop, k: number) => {\n const into = bump(k, knot)\n return {\n x: x0 + ((x1 - x0) * k) / SEGMENTS,\n y: of.y0 + (of.y1 - of.y0) * ease(k / SEGMENTS),\n z: of.z * into,\n d: ribbon + ((knot?.depth ?? ribbon) - ribbon) * into,\n }\n }\n return Array.from({ length: SEGMENTS }, (_, k) => {\n const [from, to] = [at(hop, k), at(hop, k + 1)]\n const first = knot ? [at(knot.first, k), at(knot.first, k + 1)] : [from, to]\n const band = (from.x + to.x) / 2\n return Object.assign(slab(from, to, hop.flow.value * ky), {\n key: `hop:${hop.flow.key}:${hop.source.column}:${k}`,\n band,\n flow: hop.flow,\n t: share(hop.flow, band),\n row: (first[0].y + first[1].y) / 2,\n // Between the borders of its knot a hop holds its lane, so there the lanes part the hops.\n lane: knot && k >= knot.from && k < knot.to ? hop.z : 0,\n level: (from.y + to.y) / 2,\n })\n })\n}\n\n/**\n * The corners of a slab from the cross-section around `from` to the one around\n * `to`, `height` high and each `d` deep, in the order of box(). Two rectangles\n * of one height keep the faces planar and the slab convex.\n */\nfunction slab(from: Point3D & { d: number }, to: Point3D & { d: number }, height: number) {\n return [1, -1].flatMap((side) => [\n { x: from.x, y: from.y - height / 2, z: from.z + (side * from.d) / 2 },\n { x: from.x, y: from.y + height / 2, z: from.z + (side * from.d) / 2 },\n { x: to.x, y: to.y + height / 2, z: to.z + (side * to.d) / 2 },\n { x: to.x, y: to.y - height / 2, z: to.z + (side * to.d) / 2 },\n ])\n}\n\n/**\n * The pieces in the order to paint them, by the first plane that parts two of\n * them: the slabs of the columns and slices lie between planes x = const; the\n * knots of a slice, one above the other; the lanes of a knot, where its hops\n * hold them, one behind the other; and the hops of a lane, or of a knot\n * outside its borders, which do not overlap there, one above the other. Each\n * key paints the part farther from the eye first, so the order is exact for\n * every eye, and keys of numbers cannot form a cycle.\n */\nfunction depthSort<\n P extends Pick<Piece, \"band\" | \"row\" | \"lane\" | \"level\"> & { centroid: Point3D },\n>(pieces: P[], camera: Camera3DInstance) {\n const view = camera.viewDirection()\n const perspective = camera.perspective()\n // The distance from the eye along one axis: the eye sits at perspective · view, at infinity for\n // an orthographic camera, where NaN means it looks along the axis and the axis decides nothing.\n const far = (at: number, v: number) => {\n const eye = v * perspective\n return Number.isFinite(eye) ? Math.abs(at - eye) : -at * Math.sign(v)\n }\n return pieces.sort(\n (a, b) =>\n far(b.band, view.x) - far(a.band, view.x) ||\n far(b.row, view.y) - far(a.row, view.y) ||\n far(b.lane, view.z) - far(a.lane, view.z) ||\n far(b.level, view.y) - far(a.level, view.y) ||\n sort(a, b)\n )\n}\n\n/**\n * The label of a node beside its `outer` face, pushed away from the other side,\n * so that it stays outside whichever way the camera turns. Seen edge on, where\n * the two sides meet and away has no direction, the label lifts over the node,\n * so it swings round to the other side instead of jumping across. It carries\n * the groups of the node, so it fades with the node.\n */\nfunction nodeLabel(\n key: string,\n faces: CubeFace[],\n outer: \"left\" | \"right\",\n text: React.ReactNode,\n groups: string[]\n): Label3D {\n const side = (name: \"left\" | \"right\") => center(faces.find((face) => face.face === name)!)\n const at = side(outer)\n const away = at.x - side(outer === \"left\" ? \"right\" : \"left\").x\n const lift = Math.max(0, SWING - Math.abs(away))\n const length = Math.hypot(away, lift)\n const toward = { x: away / length, y: -lift / length }\n return { key, at: { x: at.x + 8 * toward.x, y: at.y + 8 * toward.y }, text, toward, groups }\n}\n"],"mappings":";;;;;;;;;AAGA,SAAgB,GAAG,GAAG,QAAsB;CAC1C,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;ACqBA,MAAM,SAAS;CAAE,OAAO;CAAI,MAAM;AAAQ;AA6E1C,MAAM,iBAAiB,MAAM,cAAqC,IAAI;AAEtE,SAAgB,aAAa;CAC3B,MAAM,UAAU,MAAM,WAAW,cAAc;CAC/C,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,uDAAuD;CAEzE,OAAO;AACT;AAEA,MAAM,OAAO,KAAK,KAAK;AACvB,MAAM,WAAW,KAAK,KAAK;AAC3B,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,iBAAiB;AAuCvB,MAAM,YAGF;CACF,YAAY;EAAE,OAAO;EAAU,MAAM,CAAC,MAAM;CAAE;CAC9C,YAAY;EAAE,OAAO;EAAU,MAAM,CAAC,WAAW;EAAG,MAAM,EAAE,KAAK,CAAC,SAAS;CAAE;CAC7E,aAAa;EAA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M,CAAC,CAAC;CAC9D,MAAM,OAAO,KAAK,IAAI,GAAG,QAAQ,KAAK,IAAI,IAAI,CAAC;CAC/C,MAAM,SAAS,KAAK,MAAM,MAAM,IAAI;CACpC,MAAM,SAAS;EAAE,GAAG,OAAO;EAAQ,GAAG,CAAC,OAAO;CAAO;CACrD,OAAO;EAAE;EAAK,IAAI;GAAE,GAAG,GAAG,IAAI,IAAI,OAAO;GAAG,GAAG,GAAG,IAAI,IAAI,OAAO;EAAE;EAAG;EAAM;EAAQ;CAAO;AAC7F"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/utils.ts","../registry/new-york/ui/chart-3d.tsx","../registry/new-york/ui/area-chart-3d.tsx","../registry/new-york/ui/bar-chart-3d.tsx","../registry/new-york/ui/scatter-chart-3d.tsx","../registry/new-york/ui/surface-chart-3d.tsx"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs))\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { nice, ticks } from \"d3-array\"\nimport {\n axes3D,\n camera3D,\n normal,\n points3D,\n sort,\n type AxesSpec,\n type AxisEdge,\n type AxisSpec,\n type AxisWall,\n type Camera3DInstance,\n type CubeFace,\n type Point2D,\n type Point3D,\n type ShapeInstance,\n type TransformedPoint,\n} from \"d3-3d\"\nimport { KeyboardIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\n// The same shape as the ChartConfig of shadcn's chart, so one config drives\n// a 2D and a 3D chart side by side.\nconst THEMES = { light: \"\", dark: \".dark\" } as const\n\nexport type ChartConfig = {\n [k in string]: {\n label?: React.ReactNode\n icon?: React.ComponentType\n } & (\n | { color?: string; theme?: never }\n | { color?: never; theme: Record<keyof typeof THEMES, string> }\n )\n}\n\n/** How the camera looks at the chart box, angles in radians. */\nexport type View3D = {\n yaw: number\n /** The angle above the floor the camera looks down from. */\n tilt: number\n zoom?: number\n /** How far the chart is moved, in the units of the view box. */\n pan?: Point2D\n /** The distance of the eye in box units; Infinity, the default, is orthographic. */\n perspective?: number\n}\n\n/** How the marks of a chart are drawn. The box, its labels, the tooltip and the legend are always SVG and HTML. */\nexport type Renderer3D = \"svg\" | \"canvas\" | \"webgl\"\n\n/** Maps data values to the world box, which spans -1 to 1 on every axis, y up. */\nexport type World = Record<keyof AxesSpec, (value: number) => number>\n\n/** What a mark says while the pointer is on it, beside the pointer. */\nexport type Tooltip3D = {\n title?: React.ReactNode\n items: { label: React.ReactNode; value: React.ReactNode; color?: string }[]\n}\n\n/** One shape of a chart, projected, in paint order: a polygon, or a circle of radius `r` around its one point. */\nexport type Mark3D = {\n /** Stable across renders, so React moves the shape instead of redrawing it. */\n key: string\n /** The corners of a polygon, or the center of a circle, in the units of the view box. */\n points: Point2D[]\n r?: number\n /** A CSS color, such as the result of `shade` or `var(--color-x)`. */\n fill: string\n /** The ring around a circle, a CSS color. */\n stroke?: string\n /** Shown while the pointer is over the mark. */\n tooltip?: Tooltip3D\n /**\n * The marks of the same element as this one: the faces of a bar, the\n * segments of a flow. Pointing at a mark gives them an edge in the focus\n * color - `--chart-3d-focus`, or their own fill lightened - until the\n * pointer leaves the mark; the fill never changes on hover.\n */\n groups?: string[]\n}\n\n/** The groups in focus, a store, so a change reaches the marks and labels without rendering the chart again. */\ntype Focus3D = {\n get: () => string[] | undefined\n set: (groups?: string[]) => void\n subscribe: (listener: () => void) => () => void\n}\n\ntype ChartContext3D = {\n config: ChartConfig\n camera: Camera3DInstance\n renderer: Renderer3D\n /** The marks of the chart, which the hover and the canvas read. */\n scene: React.RefObject<Mark3D[]>\n repaint: () => void\n focus: Focus3D\n /** The time in ms a chart takes to glide into new data, 600 unless the container says. */\n animationDuration?: number\n}\n\nconst Chart3DContext = React.createContext<ChartContext3D | null>(null)\n\nexport function useChart3D() {\n const context = React.useContext(Chart3DContext)\n if (!context) {\n throw new Error(\"useChart3D must be used within a <ChartContainer3D />\")\n }\n return context\n}\n\nconst DRAG = Math.PI / 230\nconst KEY_STEP = Math.PI / 36\nconst PAN_STEP = 20\nconst ZOOM_STEP = 1.2\nconst CLICK_DISTANCE = 4\n// How long the zoom cursor outlives the last wheel tick before the hand returns.\nconst ZOOM_CURSOR = 400\n\n/** A step of the camera: turned by `yaw` and `tilt`, moved by `pan`, zoomed by the factor `zoom`, or reset. */\ntype Move = { yaw?: number; tilt?: number; pan?: Point2D; zoom?: number; reset?: boolean }\n\n/** The actions a key triggers: each steps the camera, `help` opens the shortcut panel. */\nexport type KeyAction3D =\n | \"rotateLeft\"\n | \"rotateRight\"\n | \"rotateUp\"\n | \"rotateDown\"\n | \"panLeft\"\n | \"panRight\"\n | \"panUp\"\n | \"panDown\"\n | \"zoomIn\"\n | \"zoomOut\"\n | \"reset\"\n | \"help\"\n\n/** The gestures of the pointer, which `keymap` can turn off or rename but not rebind; the shortcut panel shows each with its modifier on the reader's platform. */\nexport type Gesture3D = \"dragRotate\" | \"dragPan\" | \"wheelZoom\" | \"doubleClickReset\"\n\n/**\n * The shortcuts of a chart over their defaults, per action: `false` turns an\n * action off, keys replace its keys and a label renames it in the shortcut\n * panel, where the actions of one label share a row. Keys are written the way\n * `aria-keyshortcuts` writes them, such as `\"Shift+ArrowLeft\"` or\n * `\"Control+Plus\"`, and the panel shows the first.\n */\nexport type Keymap3D = {\n [A in KeyAction3D]?: false | string[] | { keys?: string[]; label?: string }\n} & { [G in Gesture3D]?: false | { label?: string } }\n\ntype Action3D = KeyAction3D | Gesture3D\n\n// The shortcuts of a chart, in the order of the shortcut panel: the keys of\n// an action move the camera, a gesture shows its hint, and the panel lists\n// every action that is on, so the two never disagree. `keymap` overrides them.\nconst SHORTCUTS: Record<\n Action3D,\n { label: string; keys?: string[]; hint?: string[]; move?: Move }\n> = {\n dragRotate: { label: \"Rotate\", hint: [\"Mod\", \"Drag\"] },\n rotateLeft: { label: \"Rotate\", keys: [\"ArrowLeft\"], move: { yaw: -KEY_STEP } },\n rotateRight: { label: \"Rotate\", keys: [\"ArrowRight\"], move: { yaw: KEY_STEP } },\n rotateUp: { label: \"Rotate\", keys: [\"ArrowUp\"], move: { tilt: -KEY_STEP } },\n rotateDown: { label: \"Rotate\", keys: [\"ArrowDown\"], move: { tilt: KEY_STEP } },\n dragPan: { label: \"Pan\", hint: [\"Alt\", \"Drag\"] },\n panLeft: { label: \"Pan\", keys: [\"Shift+ArrowLeft\"], move: { pan: { x: -PAN_STEP, y: 0 } } },\n panRight: { label: \"Pan\", keys: [\"Shift+ArrowRight\"], move: { pan: { x: PAN_STEP, y: 0 } } },\n panUp: { label: \"Pan\", keys: [\"Shift+ArrowUp\"], move: { pan: { x: 0, y: -PAN_STEP } } },\n panDown: { label: \"Pan\", keys: [\"Shift+ArrowDown\"], move: { pan: { x: 0, y: PAN_STEP } } },\n zoomIn: { label: \"Zoom\", keys: [\"Plus\", \"=\"], move: { zoom: ZOOM_STEP } },\n zoomOut: { label: \"Zoom\", keys: [\"-\"], move: { zoom: 1 / ZOOM_STEP } },\n wheelZoom: { label: \"Zoom\", hint: [\"Mod\", \"Scroll\"] },\n reset: { label: \"Reset\", keys: [\"0\"], move: { reset: true } },\n doubleClickReset: { label: \"Reset\", hint: [\"Double-click\"] },\n help: { label: \"Keyboard shortcuts\", keys: [\"?\"] },\n}\n\nconst MODIFIERS = [\"Control\", \"Alt\", \"Meta\", \"Shift\"]\n\n/** Whether the reader is on a Mac, where the platform modifier is ⌘; elsewhere it is Ctrl. */\nconst mac = () =>\n /mac/i.test(\n (globalThis.navigator as Navigator & { userAgentData?: { platform?: string } })?.userAgentData\n ?.platform ??\n globalThis.navigator?.platform ??\n \"\"\n )\n\n/** The label of the platform modifier: ⌘ on a Mac, Ctrl elsewhere. */\nconst modLabel = () => (mac() ? \"⌘\" : \"Ctrl\")\n\n/** The label of the Alt key: ⌥ on a Mac, Alt elsewhere. */\nconst altLabel = () => (mac() ? \"⌥\" : \"Alt\")\n\n/** Whether the platform modifier - ⌘ on a Mac, Ctrl elsewhere - is held in `e`. */\nconst platformMod = (e: { metaKey: boolean; ctrlKey: boolean }) => (mac() ? e.metaKey : e.ctrlKey)\n\n/** Whether `value` lies between the ends `lo` and `hi`. */\nconst within = (lo: number, hi: number, value: number) => value >= lo && value <= hi\n// The keys that `aria-keyshortcuts` names, because `+` delimits and a space separates.\nconst NAMED: Record<string, string> = { Plus: \"+\", Space: \" \" }\nconst ARIA: Record<string, string> = { \"+\": \"Plus\", \" \": \"Space\" }\nconst KBD: Record<string, string> = {\n ArrowLeft: \"←\",\n ArrowRight: \"→\",\n ArrowUp: \"↑\",\n ArrowDown: \"↓\",\n \"-\": \"−\",\n \" \": \"Space\",\n Control: \"Ctrl\",\n Meta: \"⌘\",\n}\n\n/** Keys split at `+`, which is the key itself at the end: `\"Control++\"` is Control and `+`. */\nconst split = (keys: string) => keys.split(/\\+(?!$)/)\n\n/**\n * Keys in the one form a binding and a press compare in: the modifiers in a\n * fixed order, then the key, Plus as `+` and Space as \" \". Shift counts only\n * beside a named key; a character such as \"?\" or \"A\" is typed with it already.\n */\nfunction combo(keys: string) {\n const parts = split(keys)\n const key = NAMED[parts.at(-1)!] ?? parts.at(-1)!\n const mods = MODIFIERS.filter((m) => parts.includes(m) && (m !== \"Shift\" || key.length > 1))\n return [...mods, key].join(\"+\")\n}\n\n/** The keys of a press, in the form of `combo`. */\nfunction pressed(e: Pick<KeyboardEvent, \"key\" | \"ctrlKey\" | \"altKey\" | \"metaKey\" | \"shiftKey\">) {\n const mods = [\n e.ctrlKey && \"Control\",\n e.altKey && \"Alt\",\n e.metaKey && \"Meta\",\n e.shiftKey && \"Shift\",\n ]\n return combo([...mods, e.key].filter(Boolean).join(\"+\"))\n}\n\n/** Keys in the form of `combo`, the way `aria-keyshortcuts` writes them. */\nfunction aria(keys: string) {\n const parts = split(keys)\n return [...parts.slice(0, -1), ARIA[parts.at(-1)!] ?? parts.at(-1)].join(\"+\")\n}\n\n/** Every action, `keymap` over its defaults: on unless it is off or a key action without keys. */\nfunction shortcutsOf(keymap: Keymap3D | false) {\n return (Object.keys(SHORTCUTS) as Action3D[]).map((action) => {\n const own: Keymap3D[KeyAction3D] = keymap && keymap[action]\n const { keys = [], ...shortcut } = {\n ...SHORTCUTS[action],\n ...(Array.isArray(own) ? { keys: own } : own || {}),\n }\n const on = own !== false && (shortcut.hint !== undefined || keys.length > 0)\n return { ...shortcut, action, on, keys: keys.map(combo) }\n })\n}\n\ntype Shortcut = ReturnType<typeof shortcutsOf>[number]\n\n/**\n * The rows of the shortcut panel: the actions by label, the keys of a row in\n * groups of the same modifiers, left of its gestures, each a group of its own.\n */\nfunction rowsOf(shortcuts: Shortcut[]) {\n const rows = new Map<string, { keys: Map<string, string[]>; gestures: string[][] }>()\n for (const { label, keys, hint } of shortcuts) {\n const parts = (hint ?? split(keys[0])).map((k) =>\n k === \"Mod\" ? modLabel() : k === \"Alt\" ? altLabel() : (KBD[k] ?? k)\n )\n const row = rows.get(label) ?? { keys: new Map<string, string[]>(), gestures: [] }\n if (hint) row.gestures.push(parts)\n else {\n const group = parts.slice(0, -1).join(\"+\")\n const known = row.keys.get(group)\n row.keys.set(group, known ? [...known, parts.at(-1)!] : parts)\n }\n rows.set(label, row)\n }\n return [...rows].map(([label, row]) => ({\n label,\n keys: [...row.keys.values()],\n gestures: row.gestures,\n }))\n}\n\n/**\n * What a keymap does: the actions that are on, the step of each key, the help\n * keys and the rows of the panel. Without the `panel`, the help keys have\n * nothing to open and are off.\n */\nfunction keymapOf(keymap: Keymap3D | false, panel: boolean) {\n const all = shortcutsOf(keymap)\n const on = all.filter((s) => s.on && (panel || s.action !== \"help\"))\n return {\n on: (action: Action3D) => on.some((s) => s.action === action),\n moves: Object.fromEntries(on.flatMap((s) => s.keys.map((k) => [k, s.move]))) as Record<\n string,\n Move | undefined\n >,\n help: on.find((s) => s.action === \"help\")?.keys ?? [],\n label: all.find((s) => s.action === \"help\")!.label,\n aria: on.flatMap((s) => s.keys.map(aria)).join(\" \"),\n rows: panel ? rowsOf(on) : [],\n }\n}\n\ntype Keymap = ReturnType<typeof keymapOf>\n\nexport type ChartContainer3DProps = {\n /** The series of the chart: a label and a color per key, as in the chart of shadcn/ui. */\n config: ChartConfig\n /**\n * The time in ms a chart takes to glide into new data; 0 makes it jump.\n * @defaultValue 600\n */\n animationDuration?: number\n /**\n * Where the camera starts, and where a reset returns it.\n * @defaultValue { yaw: π/6, tilt: π/6 }\n */\n defaultView?: View3D\n /**\n * The width of the view box the chart is drawn in.\n * @defaultValue 640\n */\n width?: number\n /**\n * The height of the view box the chart is drawn in.\n * @defaultValue 400\n */\n height?: number\n /**\n * Shows the label and the color of every config key below the chart.\n * @defaultValue false\n */\n legend?: boolean\n /**\n * How the marks of the chart are drawn: \"canvas\" suits many marks, \"webgl\" more.\n * The chart draws as SVG until the browser shows it has the requested renderer,\n * \"webgl\" falling back to \"canvas\", and where it has none, as SVG.\n * @defaultValue \"svg\"\n */\n renderer?: Renderer3D\n /**\n * Shows a button that lists the keyboard shortcuts of the chart; `?` lists them too.\n * @defaultValue true\n */\n shortcuts?: boolean\n /**\n * Rebinds, renames or turns off the keys and the gestures of the chart, per\n * action; `false` turns them all off and the chart stands still.\n * @defaultValue {}\n */\n keymap?: Keymap3D | false\n /**\n * The corner that shows the axes of the chart, turned with the camera; `false` hides them.\n * @defaultValue \"bottom-left\"\n */\n gizmo?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\" | false\n /**\n * The corner beside the pointer the tooltip sits at. Where the tooltip would\n * leave the chart, it flips to the other side, on each axis alone.\n * @defaultValue \"top-right\"\n */\n tooltip?: \"top-left\" | \"top-right\" | \"bottom-left\" | \"bottom-right\"\n}\n\nfunction ChartContainer3D({\n id,\n config,\n defaultView = { yaw: Math.PI / 6, tilt: Math.PI / 6 },\n width = 640,\n height = 400,\n animationDuration,\n legend = false,\n renderer: requested = \"svg\",\n shortcuts = true,\n keymap = {},\n gizmo = \"bottom-left\",\n tooltip = \"top-right\",\n className,\n children,\n \"aria-label\": ariaLabel,\n ...props\n}: React.ComponentProps<\"div\"> & ChartContainer3DProps) {\n const chartId = chartIdOf(id, React.useId())\n const { scene, renderer, canvas, repaint, hover, hide, leave, tip, focus } = useScene(\n requested,\n width,\n height,\n tooltip\n )\n const keys = keymapOf(keymap, shortcuts)\n const { view, handlers } = useOrbit(defaultView, width, keys, hide, hover)\n const camera = useCamera(view, width, height)\n const context = React.useMemo(\n () => ({ config, camera, renderer, scene, repaint, focus, animationDuration }),\n [config, camera, renderer, repaint, focus, animationDuration]\n )\n\n return (\n <div\n data-slot=\"chart-3d\"\n data-chart={chartId}\n className={cn(\"relative w-full text-xs\", className)}\n {...props}\n >\n <ChartStyle id={chartId} config={config} />\n <div className=\"relative rounded-lg has-focus-visible:ring-[3px] has-focus-visible:ring-ring/50\">\n <svg\n viewBox={`0 0 ${width} ${height}`}\n role=\"img\"\n {...keymapProps(keys, ariaLabel)}\n onPointerLeave={leave}\n {...handlers}\n >\n <Chart3DContext.Provider value={context}>{children}</Chart3DContext.Provider>\n </svg>\n <ChartCanvas3D renderer={renderer} canvas={canvas} width={width} height={height} />\n <ChartGizmo3D camera={camera} corner={gizmo} />\n <ChartTooltip3D tip={tip} />\n </div>\n <ChartShortcuts3D {...keys} />\n {legend && <ChartLegend3D config={config} />}\n </div>\n )\n}\n\n/** The id the colors of a chart are scoped to: its own `id`, or the one React made up. */\nfunction chartIdOf(id: string | undefined, uniqueId: string) {\n return `chart-${id || uniqueId.replace(/:/g, \"\")}`\n}\n\n/**\n * What the svg says about its keymap: a label that names the drag and the\n * help key if they are on, the keys, the focus only if a key does something\n * and the grab cursor only if a drag does; without one, a touch scrolls the page.\n */\nfunction keymapProps(keys: Keymap, label?: string): React.SVGProps<SVGSVGElement> {\n const drag = keys.on(\"dragRotate\") || keys.on(\"dragPan\")\n const help = keys.help[0]\n const said = [\n \"3D chart.\",\n keys.on(\"dragRotate\") && `${modLabel()} and drag to rotate it.`,\n help && `Press ${aria(help)} for all shortcuts.`,\n ]\n return {\n \"aria-label\": label ?? said.filter(Boolean).join(\" \"),\n \"aria-keyshortcuts\": keys.aria || undefined,\n tabIndex: keys.aria ? 0 : undefined,\n className: cn(\n \"block h-auto w-full outline-hidden select-none mask-x-from-96% mask-y-from-96%\",\n // The default cursor stays, so a plain drag only inspects; the modifier and a drag rotate.\n drag && \"touch-none\"\n ),\n }\n}\n\n/**\n * The marks of the chart and what reads them: the renderer that draws them,\n * the canvas it paints them on and the hover that shows their tooltips.\n */\nfunction useScene(requested: Renderer3D, width: number, height: number, placement: Placement3D) {\n const scene = React.useRef<Mark3D[]>([])\n const tip = useTip(placement)\n const focus = useFocus()\n const renderer = useRenderer(requested)\n const { canvas, repaint } = useCanvas(scene, width, height, renderer)\n const { hover, hide, leave } = useHover(scene, width, height, tip, focus)\n return { scene, renderer, canvas, repaint, hover, hide, leave, tip, focus }\n}\n\ntype Tip3D = ReturnType<typeof useTip>\ntype Placement3D = NonNullable<ChartContainer3DProps[\"tooltip\"]>\n\n// The room between the pointer and its tooltip, in pixels, and the shift of\n// the tooltip on an axis: before the pointer by its own size and the room, or after it.\nconst TIP_GAP = 12\nconst shift = (isBefore: boolean) => (isBefore ? `calc(-100% - ${TIP_GAP}px)` : `${TIP_GAP}px`)\n\n/**\n * Whether a tooltip of `size` goes before the pointer at `at`, on an axis of\n * `length`: as `preferred`, unless it would leave the chart there and the\n * other side has more room.\n */\nfunction before(at: number, size: number, length: number, preferred: boolean) {\n const room = preferred ? at : length - at\n return room < size + TIP_GAP && length - room > room ? !preferred : preferred\n}\n\n/**\n * The tooltip of the hovered mark and where it sits: beside the pointer, in\n * the pixels of the chart, at `placement`. `follow` moves it with the pointer\n * straight in the DOM, so a move within a mark renders nothing; `place` puts\n * it there again once it shows, or its content changes its size.\n */\nfunction useTip(placement: Placement3D) {\n const [tooltip, set] = React.useState<Tooltip3D | null>(null)\n const ref = React.useRef<HTMLDivElement>(null)\n // The pointer in the chart, and the size of the chart.\n const pointer = React.useRef({ x: 0, y: 0, width: 0, height: 0 })\n const place = React.useCallback(() => {\n const el = ref.current\n if (!el) return\n // A tooltip that shows jumps into its corner; only one on screen glides when it flips.\n const shows = !el.dataset.placement\n if (shows) el.style.transition = \"none\"\n const { x, y, width, height } = pointer.current\n const top = before(y, el.offsetHeight, height, placement.startsWith(\"top\"))\n const left = before(x, el.offsetWidth, width, placement.endsWith(\"left\"))\n el.style.left = `${x}px`\n el.style.top = `${y}px`\n el.style.translate = `${shift(left)} ${shift(top)}`\n el.dataset.placement = `${top ? \"top\" : \"bottom\"}-${left ? \"left\" : \"right\"}`\n if (shows) {\n // Lays the corner out while the transition is off, then turns it on again.\n el.getBoundingClientRect()\n el.style.transition = \"\"\n }\n }, [placement])\n const follow = (at: typeof pointer.current) => {\n pointer.current = at\n place()\n }\n return { tooltip, set, ref, place, follow }\n}\n\n/** The camera of a view. The shapes of the chart hang on it, so a new view re-projects them all. */\nfunction useCamera(view: View3D, width: number, height: number) {\n return React.useMemo(\n () =>\n camera3D()\n .origin({ x: width / 2 + (view.pan?.x ?? 0), y: height / 2 + (view.pan?.y ?? 0) })\n .scale(Math.min(width, height) * 0.3 * (view.zoom ?? 1))\n .perspective(view.perspective ?? Infinity)\n .rotateY(view.yaw)\n .rotateX(-view.tilt),\n [view, width, height]\n )\n}\n\nconst clamp = (lo: number, hi: number, value: number) => Math.max(lo, Math.min(hi, value))\nconst ZERO = { x: 0, y: 0 }\n\n/** `view` moved by one step. The tilt stops at the zenith and the nadir, the zoom at 1/4 and 8. */\nfunction moved(view: View3D, move: Move, initial: View3D): View3D {\n if (move.reset) return initial\n const step = { yaw: 0, tilt: 0, zoom: 1, pan: { x: 0, y: 0 }, ...move }\n const pan = view.pan ?? { x: 0, y: 0 }\n return {\n ...view,\n yaw: view.yaw + step.yaw,\n tilt: clamp(-Math.PI / 2, Math.PI / 2, view.tilt + step.tilt),\n zoom: clamp(0.25, 8, (view.zoom ?? 1) * step.zoom),\n pan: { x: pan.x + step.pan.x, y: pan.y + step.pan.y },\n }\n}\n\n/**\n * Whether the chart may move on its own: only where the browser says the\n * reader has not asked for reduced motion. Where it cannot say, as on the\n * server and in jsdom, the chart jumps.\n */\nfunction animates() {\n return Boolean(globalThis.matchMedia?.(\"(prefers-reduced-motion: no-preference)\").matches)\n}\n\n/** One glide of numbers: from `from` into `to`, come the share `t` of the way. */\ntype Tween = { key: string; from: Record<string, number>; to: Record<string, number>; t: number }\n\n/**\n * Eases a chart into new data: the numbers of `values` glide from the ones\n * on screen to these over the animationDuration of the container. A key\n * that is new starts at `enter`, or where it ends; a key that is gone glides\n * back to `enter`, the mirror of its entering - without one it stands where\n * it is - and leaves when the glide is done. Without time, or with reduced\n * motion, the numbers jump.\n */\nfunction useTween(values: Record<string, number>, enter?: number): Record<string, number> {\n const { animationDuration: duration = 600 } = useChart3D()\n // The content, not the record: a chart builds `values` at every render, also while it turns.\n const key = JSON.stringify(values)\n const [tween, setTween] = React.useState<Tween>({ key, from: values, to: values, t: 1 })\n const shown = tweenNumbers(tween, enter)\n\n // Numbers from the render before, the React pattern of state set while rendering.\n if (key !== tween.key) {\n setTween({ key, from: shown, to: values, t: duration > 0 && animates() ? 0 : 1 })\n }\n\n React.useEffect(() => {\n if (tween.t >= 1) return\n let start: number | null = null\n let frame = 0\n const step = (now: number) => {\n start ??= now\n const t = Math.min(1, (now - start) / duration)\n setTween((tw) => ({ ...tw, t }))\n if (t < 1) frame = requestAnimationFrame(step)\n }\n frame = requestAnimationFrame(step)\n return () => cancelAnimationFrame(frame)\n }, [tween.key, duration])\n\n return shown\n}\n\n/** The numbers of `tween` on screen: `from` eased into `to`, a new key from `enter` or where it ends, a gone one gliding back to `enter` until the glide is done. */\nfunction tweenNumbers({ from, to, t }: Tween, enter?: number) {\n const s = t * t * (3 - 2 * t)\n const gone = t >= 1 ? [] : Object.entries(from).filter(([k]) => !(k in to))\n return Object.fromEntries([\n ...Object.entries(to).map(([k, end]) => {\n const start = from[k] ?? enter ?? end\n // At the end the number itself, so no float drift stays in the data.\n return [k, t >= 1 ? end : start + (end - start) * s]\n }),\n // A gone key glides back to `enter`, the mirror of its entering - without\n // one it stands where it is - and leaves when the glide is done.\n ...gone.map(([k, start]) => [k, start + ((enter ?? start) - start) * s]),\n ])\n}\n\n/**\n * An axis gliding into new data: its spec, the ticks the data dropped, fading\n * out in place, and the gliding `span` of its ticks, which its line runs.\n */\ntype GlidingAxis = AxisSpec & { leaving?: number[]; span?: number[] }\n\n/**\n * `spec` gliding into new data with the marks: the ends of every axis glide\n * as `useTween` glides the numbers, where ends rounded from the numbers on\n * screen would jump from one round number to the next, and the box with\n * them. The ticks stay those of `spec`; labels of ticks outside the gliding\n * ends fade out in `edgeLabels` instead of popping out of the range. The\n * outermost ticks glide too, so the line of the axis grows to a new tick and\n * shrinks from a dropped one instead of jumping when the glide is done.\n */\nfunction useTweenAxes(spec: AxesSpec): AxesSpec {\n const axes = [\"x\", \"y\", \"z\"] as const\n const last = (domain: number[]) => domain[domain.length - 1]\n const target = Object.fromEntries(\n axes.flatMap((a) => {\n const { domain, ticks } = spec[a]\n return [\n [`${a}0`, domain[0]],\n [`${a}1`, last(domain)],\n [`${a}t0`, ticks.at(0) ?? domain[0]],\n [`${a}t1`, ticks.at(-1) ?? last(domain)],\n ]\n })\n )\n const ends = useTween(target)\n // At the end of a glide useTween hands back the targets themselves, so the\n // ends tell whether the axes still glide.\n const gliding = Object.keys(target).some((k) => ends[k] !== target[k])\n // The target the glide left, remembered the way useTween keys its numbers,\n // so a retarget in the middle of a glide fades the ticks of that target out.\n const key = JSON.stringify(spec)\n const memory = React.useRef({ key, target: spec, from: spec })\n if (memory.current.key !== key) {\n memory.current = { key, target: spec, from: memory.current.target }\n }\n const glided = (a: keyof AxesSpec): GlidingAxis => {\n const [lo, hi] = [ends[`${a}0`], ends[`${a}1`]]\n // The ticks stay those of the target, so a label whose tick lies outside the\n // gliding ends fades out instead of popping out of the range. Every tick the\n // new data drops stays until the glide is done: one beyond the new ends\n // fades out as the gliding end sweeps past it, one within them fades out in\n // place, named in `leaving`.\n const [d0, d1] = [spec[a].domain[0], last(spec[a].domain)]\n const gone = gliding\n ? memory.current.from[a].ticks.filter((t) => !spec[a].ticks.includes(t))\n : []\n const ticks = gone.length ? [...spec[a].ticks, ...gone].sort((t, u) => t - u) : spec[a].ticks\n const leaving = gone.filter((t) => within(Math.min(d0, d1), Math.max(d0, d1), t))\n const span = [ends[`${a}t0`], ends[`${a}t1`]]\n return { domain: [lo, hi], ticks, span, ...(leaving.length ? { leaving } : {}) }\n }\n return { x: glided(\"x\"), y: glided(\"y\"), z: glided(\"z\") }\n}\n\n// How long the camera glides to the view a key asks for, in milliseconds.\nconst GLIDE = 200\n\n/**\n * The view of the camera, `jump`, which moves it at once, and `glide`, which\n * moves it there in `GLIDE` milliseconds, easing out. A glide under way\n * heads for the next view from where it is, so a held key turns the camera\n * smoothly; a jump stops it. Where the reader asks for reduced motion, or\n * the browser cannot say, a glide jumps.\n */\nfunction useGlide(defaultView: View3D) {\n const [view, setView] = React.useState(defaultView)\n const now = React.useRef(defaultView)\n const run = React.useRef<{ to: View3D; frame: number } | null>(null)\n const show = React.useCallback((v: View3D) => setView((now.current = v)), [])\n const stop = React.useCallback(() => {\n cancelAnimationFrame(run.current?.frame ?? 0)\n run.current = null\n }, [])\n const jump = React.useCallback(\n (to: (from: View3D) => View3D) => {\n stop()\n show(to(now.current))\n },\n [show, stop]\n )\n React.useEffect(() => stop, [stop])\n\n const glide = (to: (from: View3D) => View3D) => {\n if (!animates()) return jump(to)\n const end = to(run.current?.to ?? now.current)\n // The yaw turns the short way round, to an angle that looks the same.\n const from = { ...now.current, yaw: end.yaw + remainder(now.current.yaw - end.yaw) }\n const start = performance.now()\n stop()\n const frame = (time: number) => {\n const t = clamp(0, 1, (time - start) / GLIDE)\n show(t < 1 ? between(from, end, 1 - (1 - t) ** 3) : end)\n if (t < 1) run.current = { to: end, frame: requestAnimationFrame(frame) }\n else run.current = null\n }\n run.current = { to: end, frame: requestAnimationFrame(frame) }\n }\n\n return { view, jump, glide }\n}\n\n/** The angle `a` in the turn from -π to π. */\nfunction remainder(a: number) {\n return a - 2 * Math.PI * Math.round(a / (2 * Math.PI))\n}\n\n/** The view the share `k` of the way from `from` to `to`. */\nfunction between(from: View3D, to: View3D, k: number): View3D {\n const mix = (a: number, b: number) => a + (b - a) * k\n const pan = from.pan ?? ZERO\n const goal = to.pan ?? ZERO\n return {\n ...to,\n yaw: mix(from.yaw, to.yaw),\n tilt: mix(from.tilt, to.tilt),\n zoom: mix(from.zoom ?? 1, to.zoom ?? 1),\n pan: { x: mix(pan.x, goal.x), y: mix(pan.y, goal.y) },\n }\n}\n\n/**\n * The view of the camera, and the handlers that move it, as far as `keys`\n * has them on: a drag turns it, or pans it while Alt is held, the keys step\n * it, Ctrl or ⌘ with the wheel zooms it and a double click resets it.\n * `data-orbiting` among them is true while the camera turns. `onDragStart`\n * runs when a press becomes a drag, `onHover` on a move without one.\n */\nfunction useOrbit(\n defaultView: View3D,\n width: number,\n keys: Keymap,\n onDragStart: () => void,\n onHover: (e: React.PointerEvent<SVGSVGElement>) => void\n) {\n const { view, jump, glide } = useGlide(defaultView)\n const [orbiting, setOrbiting] = React.useState(false)\n const held = useModsHeld()\n const drag = React.useRef<(Point2D & { moved: boolean; rotate: boolean }) | null>(null)\n const ref = useWheelZoom(jump, keys.on(\"wheelZoom\"))\n // A drag follows the pointer at once, a key and a double click glide.\n const move = (step: Move) => jump((v) => moved(v, step, defaultView))\n const step = (step: Move) => glide((v) => moved(v, step, defaultView))\n const keyHandlers = useKeys(keys, step, setOrbiting)\n const release = () => {\n drag.current = null\n setOrbiting(false)\n }\n\n const handlers: OrbitHandlers = {\n ref,\n onPointerDown: (e) => {\n // Alt held, the drag pans; the platform modifier held, it turns.\n const pans = keys.on(\"dragPan\") && e.altKey\n if (pans || (keys.on(\"dragRotate\") && platformMod(e))) {\n drag.current = { x: e.clientX, y: e.clientY, moved: false, rotate: !pans }\n }\n },\n onPointerMove: (e) => {\n const d = drag.current\n if (!d) return onHover(e)\n // A drag moves only while its modifier is held: the platform modifier\n // turning, Alt panning.\n if (d.rotate ? !platformMod(e) : !e.altKey) return release()\n const dx = e.clientX - d.x\n const dy = e.clientY - d.y\n // A press that wanders a few pixels is still a click on a bar.\n if (!d.moved && Math.hypot(dx, dy) < CLICK_DISTANCE) return\n if (!d.moved) {\n e.currentTarget.setPointerCapture(e.pointerId)\n onDragStart()\n }\n drag.current = { x: e.clientX, y: e.clientY, moved: true, rotate: d.rotate }\n const k = width / e.currentTarget.getBoundingClientRect().width\n setOrbiting(d.rotate)\n move(d.rotate ? { yaw: dx * DRAG, tilt: dy * DRAG } : { pan: { x: dx * k, y: dy * k } })\n },\n onPointerUp: release,\n onPointerCancel: release,\n onDoubleClick: keys.on(\"doubleClickReset\") ? () => step({ reset: true }) : undefined,\n ...keyHandlers,\n \"data-orbiting\": orbiting,\n \"data-mod\": keys.on(\"dragRotate\") && held.mod ? true : undefined,\n \"data-alt\": keys.on(\"dragPan\") && held.alt ? true : undefined,\n }\n\n return { view, handlers }\n}\n\ntype OrbitHandlers = React.SVGProps<SVGSVGElement> & {\n \"data-orbiting\": boolean\n \"data-mod\"?: boolean\n \"data-alt\"?: boolean\n}\n\n/**\n * Whether the platform modifier or Alt is held, so the cursor shows a hand\n * before the drag rotates and the four arrows before it pans. A missed keyup\n * (window blur while held) must not stick either cursor.\n */\nfunction useModsHeld() {\n const [mod, setMod] = React.useState(false)\n const [alt, setAlt] = React.useState(false)\n React.useEffect(() => {\n const modKey = mac() ? \"Meta\" : \"Control\"\n const onKey = (e: KeyboardEvent) => {\n if (e.key === modKey) setMod(e.type === \"keydown\")\n if (e.key === \"Alt\") setAlt(e.type === \"keydown\")\n }\n const onBlur = () => {\n setMod(false)\n setAlt(false)\n }\n window.addEventListener(\"keydown\", onKey)\n window.addEventListener(\"keyup\", onKey)\n window.addEventListener(\"blur\", onBlur)\n return () => {\n window.removeEventListener(\"keydown\", onKey)\n window.removeEventListener(\"keyup\", onKey)\n window.removeEventListener(\"blur\", onBlur)\n }\n }, [])\n return { mod, alt }\n}\n\n/**\n * The handlers that step the camera with the keys of `keys`. A key that\n * turns the camera marks it as orbiting until it is let go.\n */\nfunction useKeys(\n keys: Keymap,\n move: (step: Move) => void,\n setOrbiting: (orbiting: boolean) => void\n) {\n const onKeyDown = (e: React.KeyboardEvent<SVGSVGElement>) => {\n const step = keys.moves[pressed(e)]\n if (!step) return\n e.preventDefault()\n setOrbiting(Boolean(step.yaw || step.tilt))\n move(step)\n }\n const onKeyUp = () => setOrbiting(false)\n return { onKeyDown, onKeyUp }\n}\n\n/**\n * A ref for the svg that zooms the view with the platform modifier and the\n * wheel, if `on`. Ctrl and the wheel zooms on a Mac too, because a trackpad\n * pinch arrives that way, indistinguishable from the keys. The wheel alone\n * still scrolls the page. While the wheel zooms, the svg says so in\n * `data-zoom` - `\"in\"` or `\"out\"`, the direction of its cursor - until\n * `ZOOM_CURSOR` after the last tick.\n */\nfunction useWheelZoom(jump: (to: (from: View3D) => View3D) => void, on: boolean) {\n // React listens to the wheel passively, and only a listener that is not\n // passive can keep the browser from zooming the page.\n return React.useCallback(\n (svg: SVGSVGElement | null) => {\n if (!on || !svg) return\n let timer: ReturnType<typeof setTimeout>\n const onWheel = (e: WheelEvent) => {\n if (!platformMod(e) && !e.ctrlKey) return\n e.preventDefault()\n jump((v) => moved(v, { zoom: 2 ** (-e.deltaY / 200) }, v))\n svg.dataset.zoom = e.deltaY < 0 ? \"in\" : \"out\"\n clearTimeout(timer)\n timer = setTimeout(() => delete svg.dataset.zoom, ZOOM_CURSOR)\n }\n svg.addEventListener(\"wheel\", onWheel, { passive: false })\n return () => {\n clearTimeout(timer)\n svg.removeEventListener(\"wheel\", onWheel)\n }\n },\n [jump, on]\n )\n}\n\n/**\n * The tooltip of the mark under the pointer, the one painted last, and the\n * focus on its groups. The highlight follows the mark: `hover` sets the\n * tooltip only when the pointer moves onto another mark, and the focus only\n * when the groups change, so a move within a mark does not render the chart\n * again; off the mark and when the pointer leaves the chart, `leave` drops\n * both. While a drag turns the chart under the captured pointer, `hide`\n * drops the tooltip and keeps the focus, so a flow does not flash away and\n * can be followed from every side.\n */\nfunction useHover(\n scene: React.RefObject<Mark3D[]>,\n width: number,\n height: number,\n tip: Tip3D,\n focus: Focus3D\n) {\n const hovered = React.useRef<Mark3D>(undefined)\n const show = (mark?: Mark3D) => {\n // Also within one mark, whose groups new data can change; the store ignores the groups it holds.\n focus.set(mark?.groups)\n if (mark?.key === hovered.current?.key) return\n hovered.current = mark\n tip.set(mark?.tooltip ?? null)\n }\n\n return {\n hover: (e: React.PointerEvent<SVGSVGElement>) => {\n const rect = e.currentTarget.getBoundingClientRect()\n const x = e.clientX - rect.left\n const y = e.clientY - rect.top\n tip.follow({ x, y, width: rect.width, height: rect.height })\n show(hit(scene.current, { x: (x / rect.width) * width, y: (y / rect.height) * height }))\n },\n hide: () => {\n hovered.current = undefined\n tip.set(null)\n },\n leave: () => show(undefined),\n }\n}\n\n/** A store for the groups in focus, which tells its listeners only when the groups change. */\nfunction useFocus(): Focus3D {\n const [focus] = React.useState(() => {\n let groups: string[] | undefined\n const listeners = new Set<() => void>()\n return {\n get: () => groups,\n set: (next?: string[]) => {\n if (JSON.stringify(next) === JSON.stringify(groups)) return\n groups = next\n listeners.forEach((listener) => listener())\n },\n subscribe: (listener: () => void) => {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n }\n })\n return focus\n}\n\n/** Whether an item shares a group with the focus: the hover highlights those items with an edge. */\nfunction useLit(items: { groups?: string[] }[]) {\n const { focus } = useChart3D()\n const groups = React.useSyncExternalStore(focus.subscribe, focus.get, focus.get)\n return (item: { groups?: string[] }) =>\n item.groups !== undefined && (groups?.some((group) => item.groups!.includes(group)) ?? false)\n}\n\n/** The topmost mark under `at`: the last one painted that holds it. */\nfunction hit(marks: Mark3D[], at: Point2D) {\n for (let i = marks.length - 1; i >= 0; i -= 1) {\n const { points, r } = marks[i]\n const holds =\n r === undefined ? inside(points, at) : Math.hypot(points[0].x - at.x, points[0].y - at.y) <= r\n if (holds) return marks[i]\n }\n}\n\n/** Whether `at` lies inside `polygon`: a ray from it crosses an odd number of its edges. */\nfunction inside(polygon: Point2D[], at: Point2D) {\n let odd = false\n for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i, i += 1) {\n const a = polygon[i]\n const b = polygon[j]\n if (a.y > at.y !== b.y > at.y && at.x < ((b.x - a.x) * (at.y - a.y)) / (b.y - a.y) + a.x) {\n odd = !odd\n }\n }\n return odd\n}\n\n/**\n * The renderer the chart draws with: SVG on the server and in the first\n * render on the client, then the requested one if the browser has it, with\n * \"webgl\" falling back to \"canvas\" and \"canvas\" to SVG.\n */\nfunction useRenderer(requested: Renderer3D) {\n const [renderer, setRenderer] = React.useState<Renderer3D>(\"svg\")\n React.useEffect(() => {\n // A canvas of its own per probe, as one that gave out a context cannot give another.\n if (requested === \"webgl\" && document.createElement(\"canvas\").getContext(\"webgl\")) {\n return setRenderer(\"webgl\")\n }\n const canvas = requested !== \"svg\" && document.createElement(\"canvas\").getContext(\"2d\")\n setRenderer(canvas ? \"canvas\" : \"svg\")\n }, [requested])\n return renderer\n}\n\n/** A resolved CSS color as bytes, which the webgl renderer draws with. */\ntype RGBA = [number, number, number, number]\n\n/**\n * A ref for the canvas of the marks, and the repaint that paints them: on new\n * marks, when the canvas changes its size and when the theme changes. A color\n * resolves on the canvas itself, inside the chart, so the `--color-*` apply;\n * webgl takes the resolved color as bytes from a 1×1 canvas.\n */\nfunction useCanvas(\n scene: React.RefObject<Mark3D[]>,\n width: number,\n height: number,\n renderer: Renderer3D\n) {\n const element = React.useRef<HTMLCanvasElement>(null)\n const colors = React.useRef(new Map<string, string>())\n const bytes = React.useRef(new Map<string, RGBA>())\n const pixel = React.useRef<CanvasRenderingContext2D | null>(null)\n\n const repaint = React.useCallback(() => {\n const canvas = element.current\n if (!canvas) return\n const resolve = (css: string) => {\n let color = colors.current.get(css)\n if (color === undefined) {\n canvas.style.color = css\n color = getComputedStyle(canvas).color\n colors.current.set(css, color)\n }\n return color\n }\n if (renderer === \"webgl\") {\n pixel.current ??= onePixel()\n paintGL(canvas, scene.current, width, height, (css) =>\n colorBytes(resolve(css), pixel.current!, bytes.current)\n )\n } else {\n paint(canvas, scene.current, width, resolve)\n }\n }, [scene, width, height, renderer])\n\n const canvas = React.useCallback(\n // A ref that returns its cleanup is never called with null.\n (node: HTMLCanvasElement) => {\n element.current = node\n repaint()\n const resize = new ResizeObserver(repaint)\n resize.observe(node)\n // ponytail: watches the theme on <html> only, as the class `.dark` of THEMES does.\n const theme = new MutationObserver(() => {\n colors.current.clear()\n bytes.current.clear()\n repaint()\n })\n theme.observe(document.documentElement, { attributeFilter: [\"class\", \"style\"] })\n return () => {\n element.current = null\n resize.disconnect()\n theme.disconnect()\n }\n },\n [repaint]\n )\n\n return { canvas, repaint }\n}\n\n/** Paints `marks` on `canvas`, from the view box of `width` to the pixels of the canvas. */\nfunction paint(\n canvas: HTMLCanvasElement,\n marks: Mark3D[],\n width: number,\n color: (css: string) => string\n) {\n canvas.width = Math.round(canvas.clientWidth * devicePixelRatio)\n canvas.height = Math.round(canvas.clientHeight * devicePixelRatio)\n // useRenderer draws on a canvas only where the browser gives one a 2D context.\n const ctx = canvas.getContext(\"2d\")!\n const scale = canvas.width / width\n ctx.setTransform(scale, 0, 0, scale, 0, 0)\n ctx.lineJoin = \"round\"\n\n for (const { points, r, fill, stroke } of marks) {\n ctx.beginPath()\n if (r === undefined) {\n for (const p of points) ctx.lineTo(p.x, p.y)\n ctx.closePath()\n } else {\n ctx.arc(points[0].x, points[0].y, r, 0, 2 * Math.PI)\n }\n ctx.fillStyle = color(fill)\n ctx.fill()\n // A polygon is outlined in its own color, which closes the seams to its neighbours.\n const outline = r === undefined ? (stroke ?? fill) : stroke\n if (!outline) continue\n ctx.strokeStyle = color(outline)\n ctx.lineWidth = r === undefined ? 0.5 : 1\n ctx.stroke()\n }\n}\n\n/** A 1×1 canvas whose 2D context resolves a color to bytes, for the webgl renderer. */\nfunction onePixel() {\n const canvas = document.createElement(\"canvas\")\n canvas.width = 1\n canvas.height = 1\n // useRenderer draws with webgl only where the browser gives a canvas a context; a 2D one comes with it.\n return canvas.getContext(\"2d\")!\n}\n\n/** The resolved `color` as bytes, drawn on the 1×1 `pixel` and read back, cached per color. */\nfunction colorBytes(\n color: string,\n pixel: CanvasRenderingContext2D,\n cache: Map<string, RGBA>\n): RGBA {\n let rgba = cache.get(color)\n if (rgba === undefined) {\n pixel.clearRect(0, 0, 1, 1)\n pixel.fillStyle = color\n pixel.fillRect(0, 0, 1, 1)\n rgba = [...pixel.getImageData(0, 0, 1, 1).data] as RGBA\n cache.set(color, rgba)\n }\n return rgba\n}\n\n/**\n * Paints `marks` on a webgl `canvas`, from the view box of `width`×`height` to\n * the pixels of the canvas: a polygon ear by ear, a fan of 12 segments per\n * circle, in paint order and without a depth test, the color of each as bytes.\n */\nfunction paintGL(\n canvas: HTMLCanvasElement,\n marks: Mark3D[],\n width: number,\n height: number,\n color: (css: string) => RGBA\n) {\n canvas.width = Math.round(canvas.clientWidth * devicePixelRatio)\n canvas.height = Math.round(canvas.clientHeight * devicePixelRatio)\n // useRenderer draws with webgl only where the browser gives one a context.\n const gl = canvas.getContext(\"webgl\")!\n gl.viewport(0, 0, canvas.width, canvas.height)\n gl.disable(gl.DEPTH_TEST)\n gl.enable(gl.BLEND)\n gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)\n const program = programOf(gl)\n gl.useProgram(program)\n gl.uniform2f(gl.getUniformLocation(program, \"u_res\"), 2 / width, 2 / height)\n const where = gl.getAttribLocation(program, \"a_pos\")\n gl.enableVertexAttribArray(where)\n gl.bindBuffer(gl.ARRAY_BUFFER, bufferOf(gl))\n gl.vertexAttribPointer(where, 2, gl.FLOAT, false, 0, 0)\n const tint = (css: string) => {\n const [r, g, b, a] = color(css)\n gl.uniform4f(gl.getUniformLocation(program, \"u_color\"), r / 255, g / 255, b / 255, a / 255)\n }\n const draw = (mode: number, points: Point2D[]) => {\n gl.bufferData(\n gl.ARRAY_BUFFER,\n new Float32Array(points.flatMap((p) => [p.x, p.y])),\n gl.DYNAMIC_DRAW\n )\n gl.drawArrays(mode, 0, points.length)\n }\n // A stroke - the focus edge, a ring - draws as a line loop over the outline,\n // as wide as the platform gives a line.\n const [, widest] = (gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE) as Float32Array | null) ?? [1, 1]\n gl.lineWidth(Math.min(1.5 * devicePixelRatio, widest))\n for (const mark of marks) {\n tint(mark.fill)\n draw(gl.TRIANGLES, trianglesOf(mark))\n if (mark.stroke) {\n tint(mark.stroke)\n draw(gl.LINE_LOOP, outlineOf(mark))\n }\n }\n}\n\n/** The 12 points of the circle around `c` of radius `r`. */\nconst ringOf = (c: Point2D, r: number) =>\n Array.from({ length: 12 }, (_, i) => ({\n x: c.x + r * Math.cos((i / 12) * 2 * Math.PI),\n y: c.y + r * Math.sin((i / 12) * 2 * Math.PI),\n }))\n\n/** The triangles of `mark` as view-box points: its polygon ear by ear, a fan of 12 segments per circle. */\nfunction trianglesOf(mark: Mark3D): Point2D[] {\n const { points, r } = mark\n if (r === undefined) return earsOf(points)\n const ring = ringOf(points[0], r)\n return ring.flatMap((p, i) => [points[0], p, ring[(i + 1) % 12]])\n}\n\n/** Twice the signed area of the triangle `a`, `b`, `c`: its sign tells which way it turns, 0 on a line. */\nconst turn = (a: Point2D, b: Point2D, c: Point2D) =>\n (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)\n\n/**\n * The triangles of a polygon, cut off ear by ear, so a concave one - the\n * front of a ribbon - fills as on the canvas, where a fan would spill over\n * its dents. An ear is a corner that turns the way of the polygon, or not at\n * all, with no other corner inside it; a simple polygon always has one. One\n * that crosses itself may have none, and then loses its first corner.\n */\nfunction earsOf(points: Point2D[]): Point2D[] {\n const left = [...points]\n const way = Math.sign(left.reduce((sum, p, i) => sum + turn(left[0], p, left[i + 1] ?? p), 0))\n const triangles: Point2D[] = []\n while (left.length > 3) {\n const corner = (i: number) => [left.at(i - 1)!, left[i], left[(i + 1) % left.length]]\n const ear = left.findIndex((_, i) => {\n const [a, b, c] = corner(i)\n if (way * turn(a, b, c) < 0) return false\n return !left.some(\n (p) => way * turn(a, b, p) > 0 && way * turn(b, c, p) > 0 && way * turn(c, a, p) > 0\n )\n })\n const i = Math.max(0, ear)\n triangles.push(...corner(i))\n left.splice(i, 1)\n }\n return [...triangles, ...left]\n}\n\n/** The outline of `mark` as view-box points: its polygon, or the ring of its circle. */\nconst outlineOf = (mark: Mark3D) =>\n mark.r === undefined ? mark.points : ringOf(mark.points[0], mark.r)\n\n// The paint program and the vertex buffer of a context, each made once.\nconst programs = new WeakMap<WebGLRenderingContext, WebGLProgram>()\nconst buffers = new WeakMap<WebGLRenderingContext, WebGLBuffer>()\n\n/** The paint program of `gl`, compiled once: view-box points in, clip space out, one color per draw. */\nfunction programOf(gl: WebGLRenderingContext) {\n let program = programs.get(gl)\n if (!program) {\n program = gl.createProgram()!\n gl.attachShader(\n program,\n shaderOf(\n gl,\n gl.VERTEX_SHADER,\n \"attribute vec2 a_pos; uniform vec2 u_res; void main() { gl_Position = vec4(a_pos.x * u_res.x - 1.0, 1.0 - a_pos.y * u_res.y, 0.0, 1.0); }\"\n )\n )\n gl.attachShader(\n program,\n shaderOf(\n gl,\n gl.FRAGMENT_SHADER,\n \"precision mediump float; uniform vec4 u_color; void main() { gl_FragColor = u_color; }\"\n )\n )\n gl.linkProgram(program)\n programs.set(gl, program)\n }\n return program\n}\n\nfunction shaderOf(gl: WebGLRenderingContext, type: number, source: string) {\n const shader = gl.createShader(type)!\n gl.shaderSource(shader, source)\n gl.compileShader(shader)\n return shader\n}\n\nfunction bufferOf(gl: WebGLRenderingContext) {\n let buffer = buffers.get(gl)\n if (!buffer) {\n buffer = gl.createBuffer()!\n buffers.set(gl, buffer)\n }\n return buffer\n}\n\n/** The canvas over the chart box that the marks are painted on, if the chart draws on one. */\nfunction ChartCanvas3D({\n renderer,\n canvas,\n width,\n height,\n}: {\n renderer: Renderer3D\n canvas: React.Ref<HTMLCanvasElement>\n width: number\n height: number\n}) {\n if (renderer === \"svg\") return null\n\n return (\n <canvas\n // A canvas that gave out one context cannot give another, so each renderer gets its own.\n key={renderer}\n data-slot=\"chart-3d-canvas\"\n ref={canvas}\n className=\"pointer-events-none absolute top-0 left-0 w-full mask-x-from-96% mask-y-from-96%\"\n style={{ aspectRatio: `${width} / ${height}` }}\n />\n )\n}\n\n// The ends of the axes of the gizmo, in the space of d3-3d, where y points down: up in the chart.\nconst GIZMO = [\n { axis: \"x\", x: 1, y: 0, z: 0 },\n { axis: \"y\", x: 0, y: -1, z: 0 },\n { axis: \"z\", x: 0, y: 0, z: 1 },\n]\n\nconst CORNERS = {\n \"top-left\": \"top-2 left-2\",\n \"top-right\": \"top-2 right-2\",\n \"bottom-left\": \"bottom-2 left-2\",\n \"bottom-right\": \"bottom-2 right-2\",\n}\n\n/**\n * The axes of the world in a corner of the chart: turned with the camera,\n * neither panned nor zoomed, the axis nearest the camera on top. An axis\n * draws in `currentColor`, so a text color on its `data-axis` recolors it.\n */\nfunction ChartGizmo3D({\n camera,\n corner,\n}: {\n camera: Camera3DInstance\n corner: ChartContainer3DProps[\"gizmo\"]\n}) {\n if (!corner) return null\n // The letters at the ends, in a box of 48 around its middle.\n const eye = camera3D()\n .origin({ x: 24, y: 24 })\n .scale(18)\n .rotateY(camera.rotateY())\n .rotateX(camera.rotateX())\n const ends = points3D<(typeof GIZMO)[number]>().camera(eye).data(GIZMO).sort(sort)\n\n return (\n <svg\n data-slot=\"chart-3d-gizmo\"\n viewBox=\"0 0 48 48\"\n aria-hidden=\"true\"\n className={cn(\"pointer-events-none absolute size-12 text-muted-foreground\", CORNERS[corner])}\n >\n {ends.map(({ axis, projected: p }) => (\n <g key={axis} data-axis={axis}>\n <line\n x1={24}\n y1={24}\n x2={24 + (p.x - 24) * 0.6}\n y2={24 + (p.y - 24) * 0.6}\n stroke=\"currentColor\"\n strokeWidth={1.5}\n strokeLinecap=\"round\"\n />\n <text\n x={p.x}\n y={p.y}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n fill=\"currentColor\"\n className=\"text-[10px] font-medium\"\n >\n {axis.toUpperCase()}\n </text>\n </g>\n ))}\n </svg>\n )\n}\n\n/**\n * The focus edge of a fill: `--chart-3d-focus`, or the fill itself lightened,\n * so the highlight carries the color of what it highlights.\n */\nconst focusOf = (fill: string) => `var(--chart-3d-focus, color-mix(in oklch, ${fill} 60%, white))`\n\n/**\n * The marks of a chart, drawn by the renderer of the container: as SVG\n * elements, or on the canvas over the chart box. The hover reads them too.\n */\nfunction Marks3D({ marks }: { marks: Mark3D[] }) {\n const { renderer, scene, repaint } = useChart3D()\n const lit = useLit(marks)\n // The lit marks get an edge in the focus color - `--chart-3d-focus`, their own fill\n // lightened unless set - unless they carry their own stroke: a background ring turns\n // into the edge, a flow's inner faces keep their color, so no seams. The fill never changes\n // on hover, and the order, and with it the depth, stays as painted.\n const drawn = marks.map((mark) =>\n lit(mark)\n ? {\n ...mark,\n stroke:\n mark.stroke && mark.stroke !== \"var(--background)\" ? mark.stroke : focusOf(mark.fill),\n }\n : mark\n )\n React.useLayoutEffect(() => {\n scene.current = drawn\n repaint()\n })\n\n if (renderer !== \"svg\") return null\n return (\n <g data-slot=\"chart-3d-marks\">\n {drawn.map(({ key, points, r, fill, stroke }) =>\n r === undefined ? (\n <path\n key={key}\n d={`M${points.map((p) => `${+p.x.toFixed(2)},${+p.y.toFixed(2)}`).join(\"L\")}Z`}\n fill={fill}\n stroke={stroke ?? fill}\n strokeWidth={stroke === focusOf(fill) ? 1.5 : 0.5}\n strokeLinejoin=\"round\"\n />\n ) : (\n <circle\n key={key}\n cx={points[0].x}\n cy={points[0].y}\n r={r}\n fill={fill}\n stroke={stroke}\n strokeWidth={stroke ? 1 : undefined}\n />\n )\n )}\n </g>\n )\n}\n\n/**\n * A label beside a mark, at `at` in the units of the view box. `toward`, a\n * unit vector, lays the label on that side of `at`, touching it, and slides\n * it round `at` as the vector turns; without it, `anchor` is the end of the\n * text that sits at `at`.\n */\nexport type Label3D = {\n key: string\n at: Point2D\n text: React.ReactNode\n anchor?: \"start\" | \"middle\" | \"end\"\n toward?: Point2D\n}\n\n/**\n * The labels of the marks of a chart, ringed by the background so that they\n * read on the marks. Like the labels of the box, they are SVG with every renderer.\n */\nfunction Labels3D({ labels }: { labels: Label3D[] }) {\n // ponytail: under the canvas of the canvas renderer, as the labels of the box; an SVG layer over the canvas would lift them.\n return (\n <g data-slot=\"chart-3d-labels\">\n {labels.map((label) => {\n const { x, y } = label.toward\n ? beside(label.at, label.toward, textWidth(label.text, 10), 10, 0)\n : label.at\n return (\n <text\n key={label.key}\n x={x}\n y={y}\n textAnchor={label.toward ? \"middle\" : label.anchor}\n dominantBaseline=\"central\"\n paintOrder=\"stroke\"\n strokeWidth={3}\n strokeLinejoin=\"round\"\n className=\"fill-foreground stroke-background text-[10px] font-medium\"\n >\n {label.text}\n </text>\n )\n })}\n </g>\n )\n}\n\nfunction ChartStyle({ id, config }: { id: string; config: ChartConfig }) {\n const colorConfig = Object.entries(config).filter(([, c]) => c.theme || c.color)\n // Every part of the axes that enters fades in: a label, a tick mark, a gridline, a wall.\n // The cursor names the gesture of the held modifier: the platform modifier\n // a hand (Alt, held with it, wins, as it does on pointer down), Alt the four\n // arrows of the pan, the wheel zoom its direction, and a turning drag grabbing.\n const entering = [\"text\", \"line\", \"path\"]\n .map((el) => `[data-chart=${id}] [data-slot=\"chart-3d-axes\"] ${el}`)\n .join(\", \")\n const base = `@keyframes chart-3d-axes-in { from { opacity: 0; } }\n${entering} { animation: chart-3d-axes-in 300ms ease-out; }\n@media (prefers-reduced-motion: reduce) { ${entering} { animation: none; } }\n[data-chart=${id}] svg[data-mod=\"true\"] { cursor: grab; }\n[data-chart=${id}] svg[data-alt=\"true\"] { cursor: move; }\n[data-chart=${id}] svg[data-zoom=\"in\"] { cursor: zoom-in; }\n[data-chart=${id}] svg[data-zoom=\"out\"] { cursor: zoom-out; }\n[data-chart=${id}] svg[data-orbiting=\"true\"] { cursor: grabbing; }`\n\n if (!colorConfig.length) {\n return <style dangerouslySetInnerHTML={{ __html: base }} />\n }\n\n return (\n <style\n dangerouslySetInnerHTML={{\n __html: [\n base,\n ...Object.entries(THEMES).map(\n ([theme, prefix]) => `\n${prefix} [data-chart=${id}] {\n${colorConfig\n .map(([key, item]) => {\n const color = item.theme?.[theme as keyof typeof item.theme] || item.color\n return color ? ` --color-${key}: ${color};` : null\n })\n .join(\"\\n\")}\n}\n`\n ),\n ].join(\"\\n\"),\n }}\n />\n )\n}\n\nfunction ChartTooltip3D({ tip }: { tip: Tip3D }) {\n const { tooltip, ref, place } = tip\n // Before the browser paints it, so a new tooltip never shows where the last one was.\n React.useLayoutEffect(place, [tooltip, place])\n if (!tooltip) return null\n\n return (\n <div\n ref={ref}\n data-slot=\"chart-3d-tooltip\"\n // As wide as its content wherever it sits, so a tooltip near the right edge is measured whole.\n className=\"pointer-events-none absolute z-10 grid w-max min-w-32 gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl motion-safe:transition-[translate]\"\n >\n {tooltip.title && <div className=\"font-medium\">{tooltip.title}</div>}\n {tooltip.items.map((item, i) => (\n <div key={i} className=\"flex items-center gap-2\">\n {item.color && (\n <span className=\"size-2.5 shrink-0 rounded-[2px]\" style={{ background: item.color }} />\n )}\n <span className=\"text-muted-foreground\">{item.label}</span>\n <span className=\"ml-auto font-mono font-medium text-foreground tabular-nums\">\n {typeof item.value === \"number\" ? item.value.toLocaleString() : item.value}\n </span>\n </div>\n ))}\n </div>\n )\n}\n\n/**\n * A button in the corner of the chart, named `label`, that lists the rows of\n * its keymap. The `help` keys on the chart open and close the list, Escape\n * closes it.\n */\nfunction ChartShortcuts3D({ rows, help, label }: Pick<Keymap, \"rows\" | \"help\" | \"label\">) {\n const [open, setOpen] = React.useState(false)\n const ref = React.useRef<HTMLDivElement>(null)\n const id = React.useId()\n // A dependency that stays the same while the keys do; no key is a line break.\n const keys = help.join(\"\\n\")\n\n React.useEffect(() => {\n const chart = ref.current?.parentElement\n const onKeyDown = (e: KeyboardEvent) => {\n if (keys.split(\"\\n\").includes(pressed(e))) setOpen((o) => !o)\n if (e.key === \"Escape\") setOpen(false)\n }\n chart?.addEventListener(\"keydown\", onKeyDown)\n return () => chart?.removeEventListener(\"keydown\", onKeyDown)\n }, [keys])\n\n // A pointer down outside the corner closes the list; the press still lands.\n React.useEffect(() => {\n if (!open) return\n const onPointerDown = (e: Event) => {\n if (!ref.current?.contains(e.target as Node)) setOpen(false)\n }\n document.addEventListener(\"pointerdown\", onPointerDown)\n return () => document.removeEventListener(\"pointerdown\", onPointerDown)\n }, [open])\n\n // Without a key or a panel, there is nothing to list.\n if (!rows.length) return null\n return (\n <div\n ref={ref}\n data-slot=\"chart-3d-shortcuts\"\n className=\"absolute top-2 right-2 z-10 flex flex-col items-end gap-1\"\n >\n <button\n type=\"button\"\n data-slot=\"chart-3d-shortcuts-trigger\"\n aria-label={label}\n aria-expanded={open}\n aria-controls={open ? id : undefined}\n onClick={() => setOpen((o) => !o)}\n className=\"inline-flex size-7 cursor-pointer items-center justify-center rounded-md bg-background/60 text-muted-foreground outline-none transition-colors hover:bg-background hover:text-accent-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4\"\n >\n <KeyboardIcon />\n </button>\n {open && <ChartShortcutList3D id={id} rows={rows} />}\n </div>\n )\n}\n\n/** One group of keys as chips. */\nfunction KbdGroup3D({ group }: { group: string[] }) {\n return (\n <span data-slot=\"kbd-group\" className=\"flex gap-1\">\n {group.map((key, j) => (\n <kbd\n key={j}\n data-slot=\"kbd\"\n className=\"pointer-events-none inline-flex h-5 min-w-5 items-center justify-center rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground select-none\"\n >\n {key}\n </kbd>\n ))}\n </span>\n )\n}\n\n/** The list of the shortcut panel: per row its label, then its keys, a rule, and its gestures. */\nfunction ChartShortcutList3D({ id, rows }: { id: string; rows: Keymap[\"rows\"] }) {\n return (\n <dl\n id={id}\n data-slot=\"chart-3d-shortcuts-panel\"\n className=\"grid grid-cols-[auto_1fr] items-center gap-x-3 gap-y-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-2 shadow-xl\"\n >\n {rows.map(({ label, keys, gestures }) => (\n <React.Fragment key={label}>\n <dt data-slot=\"chart-3d-shortcuts-label\" className=\"text-muted-foreground\">\n {label}\n </dt>\n <dd className=\"flex flex-wrap items-center justify-end gap-x-2 gap-y-1\">\n {keys.map((group, i) => (\n <KbdGroup3D key={i} group={group} />\n ))}\n {keys.length > 0 && gestures.length > 0 && (\n <span data-slot=\"chart-3d-shortcuts-rule\" className=\"h-4 w-px bg-border\" />\n )}\n {gestures.map((group, i) => (\n <KbdGroup3D key={i} group={group} />\n ))}\n </dd>\n </React.Fragment>\n ))}\n </dl>\n )\n}\n\nfunction ChartLegend3D({ config }: { config: ChartConfig }) {\n return (\n <div data-slot=\"chart-3d-legend\" className=\"flex items-center justify-center gap-4 pt-3\">\n {Object.entries(config).map(([key, item]) => (\n <div key={key} className=\"flex items-center gap-1.5\">\n {item.icon ? (\n <item.icon />\n ) : (\n <span className=\"size-2 rounded-[2px]\" style={{ background: `var(--color-${key})` }} />\n )}\n {item.label ?? key}\n </div>\n ))}\n </div>\n )\n}\n\n/**\n * The walls of the chart box that face away from the camera, with their\n * gridlines, the line of every axis along its edge with the mark of each of\n * its ticks, and the labels of every axis on each of its four edges. Only the\n * edge the axis sits on shows them, so when the axis moves to another edge,\n * its line, its marks and its labels fade from one to the other.\n */\nfunction Axes3D({\n spec,\n world,\n format = {},\n titles = {},\n}: {\n spec: AxesSpec\n world: World\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}) {\n const { camera } = useChart3D()\n const box = intoWorld(axes3D().camera(camera), world)\n const { labels, lines, marks } = labelAxes(box.edges(spec), spec, format, titles)\n // The gridline of a tick the new data dropped fades out with its label.\n const leaving = new Set(\n ([\"x\", \"y\", \"z\"] as const).flatMap((a) =>\n ((spec[a] as GlidingAxis).leaving ?? []).map((value) => `${a}-${value}`)\n )\n )\n\n return (\n <g data-slot=\"chart-3d-axes\">\n {box\n .data(spec)\n .filter((wall) => !wall.ccw)\n .map((wall) => (\n <React.Fragment key={`${wall.axis}${wall.side}`}>\n <path d={quad(wall)} className=\"fill-muted/40 stroke-border\" strokeWidth={0.75} />\n {wall.grid.map((segment) => {\n const [from, to] = [segment[0], segment[segment.length - 1]]\n const key = gridKey(wall, from, to)\n return (\n <line\n key={key}\n x1={from.projected.x}\n y1={from.projected.y}\n x2={to.projected.x}\n y2={to.projected.y}\n style={{ opacity: leaving.has(key) ? 0 : 1 }}\n className=\"stroke-border transition-opacity duration-300 ease-out motion-reduce:transition-none\"\n strokeWidth={0.75}\n />\n )\n })}\n </React.Fragment>\n ))}\n {lines.map((line) => (\n <AxisLine3D key={line.key} line={line} ink=\"stroke-foreground\" width={1.5} />\n ))}\n {marks.map((mark) => (\n <AxisLine3D key={mark.key} line={mark} ink=\"stroke-foreground/60\" width={1} />\n ))}\n {labels.map((label) => (\n <AxisLabel3D key={label.key} label={label} />\n ))}\n </g>\n )\n}\n\n// The space between a tick and its label, the least space between two\n// labels, and the space over which a label fades as it nears another.\nconst GAP = 10\nconst PAD = 2\nconst FADE = 4\n// How far a label may slide along its edge to make room, before the labels take two rows.\nconst DODGE = 12\n// How far the mark of a tick reaches out from its edge.\nconst MARK = 6\n\n/** The closed quad of a wall; its gridlines are their own lines, so a new one fades in. */\nfunction quad(wall: AxisWall) {\n return `M${wall.map(({ projected }) => `${projected.x},${projected.y}`).join(\"L\")}Z`\n}\n\n/**\n * The key of a gridline: the axis and value of the tick it marks - the one\n * coordinate its ends share beside the wall's own axis - so the gridline of\n * a tick that stays glides on, and one of a new tick mounts and fades in.\n * Exactly one coordinate differs along the line, because a domain always has\n * width: `axis` widens an empty extent.\n */\nfunction gridKey(wall: AxisWall, from: Point3D, to: Point3D) {\n const axis = ([\"x\", \"y\", \"z\"] as const).find((a) => a !== wall.axis && from[a] === to[a])!\n return `${axis}-${from[axis]}`\n}\n\n/**\n * A line of an axis: the line that carries its scale along the edge it sits\n * on, or the mark of one of its ticks. Its place follows the camera at once;\n * a change of edge fades it in a transition.\n */\ntype AxisLine = {\n key: string\n from: Point2D\n to: Point2D\n opacity: number\n}\n\n/**\n * A label of the chart box, a tick label or the title of an axis: its box\n * `w`×`h` in the units of the view box, centred at `at` and moved by `shift`\n * along its edge or into a second row.\n */\ntype AxisLabel = {\n key: string\n axis: keyof AxesSpec\n /** The tick value; the axis title has none. */\n value?: number\n at: Point2D\n w: number\n h: number\n shift: Point2D\n text: React.ReactNode\n opacity: number\n title?: boolean\n}\n\n/**\n * The labels of the axes on all their edges, the line of every axis along its\n * edge and the mark of each of its ticks, shown on the edges the axes sit on.\n * Every edge fits its own tick labels; then the labels of an axis give way to\n * those of an axis with fewer ticks, which say more each, and the titles give\n * way to the ticks.\n */\nfunction labelAxes(\n edges: AxisEdge[],\n spec: AxesSpec,\n format: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>,\n titles: Partial<Record<keyof AxesSpec, React.ReactNode>>\n) {\n // An axis without ticks, such as the rows of an empty chart, has nothing to label.\n const axes = edges\n .filter((edge) => edge.length)\n .map((edge) =>\n edgeLabels(edge, spec[edge.axis], format[edge.axis] ?? String, titles[edge.axis])\n )\n const shown = axes.filter((axis) => axis.chosen).sort((a, b) => a.ticks.length - b.ticks.length)\n const placed: AxisLabel[] = []\n for (const label of [...shown.flatMap((a) => a.ticks), ...shown.flatMap((a) => a.title ?? [])]) {\n // A tick outside the gliding ends stays faded out and does not take room from the others.\n if (label.opacity === 0) continue\n label.opacity = shows(label, placed)\n placed.push(label)\n }\n // The marks fade with their labels, also where a label of another axis takes its place.\n for (const axis of axes) axis.marks.forEach((mark, i) => (mark.opacity = axis.ticks[i].opacity))\n return {\n labels: axes.flatMap((axis) => [...axis.ticks, ...(axis.title ? [axis.title] : [])]),\n lines: axes.map((axis) => axis.line),\n marks: axes.flatMap((axis) => axis.marks),\n }\n}\n\n/**\n * The labels of one edge: a label per tick beside it, away from the box, in\n * the rows that `fit` finds, and the title of the axis beyond them. The\n * labels of an edge the axis does not sit on are there, but do not show.\n */\n/**\n * The point of `value` along `edge`, between the ticks that bracket it: the\n * projection keeps the edge straight, so the point lies on their line. An\n * axis of one tick is a point.\n */\nfunction along(edge: AxisEdge, value: number): Point2D {\n if (edge.length === 1) return edge[0].projected\n let i = 0\n while (i < edge.length - 2 && edge[i + 1][edge.axis] < value) i += 1\n const [a, b] = [edge[i][edge.axis], edge[i + 1][edge.axis]]\n // Neighbouring ticks are distinct values, so their span has width.\n const t = clamp(0, 1, (value - a) / (b - a))\n const [p, q] = [edge[i].projected, edge[i + 1].projected]\n return { x: p.x + (q.x - p.x) * t, y: p.y + (q.y - p.y) * t }\n}\n\n/** The ticks whose value lies in `domain`, with the ends of `domain`. */\nfunction inRange(ticks: AxisLabel[], domain: number[]) {\n const range = { lo: Math.min(...domain), hi: Math.max(...domain) }\n return {\n ranged: ticks.filter((t) => t.value !== undefined && within(range.lo, range.hi, t.value)),\n range,\n }\n}\n\n/** An edge the axis does not sit on hides its labels; on a chosen one, the ticks outside the gliding ends fade out. */\nfunction hideOffRange(labels: AxisLabel[], range: { lo: number; hi: number }, chosen: boolean) {\n if (!chosen) for (const l of labels) l.opacity = 0\n else\n for (const l of labels)\n if (l.value !== undefined && !within(range.lo, range.hi, l.value)) l.opacity = 0\n}\n\nfunction edgeLabels(\n edge: AxisEdge,\n { domain, leaving = [], span }: GlidingAxis,\n format: (value: number) => React.ReactNode,\n title?: React.ReactNode\n) {\n const { axis, normal: n, chosen } = edge\n const label = (\n key: string,\n at: Point2D,\n text: React.ReactNode,\n h: number,\n gap: number,\n value?: number\n ) => {\n const w = textWidth(text, h)\n return { key, axis, value, at: beside(at, n, w, h, gap), w, h, shift: ZERO, text, opacity: 1 }\n }\n const id = `${axis}${edge.sides.join(\"\")}`\n // Keyed by value, so a tick that new data keeps glides on as the same label.\n const ticks = edge.map((tick) =>\n label(`${id}-${tick[axis]}`, tick.projected, format(tick[axis]), 10, GAP, tick[axis])\n )\n // A tick the new data dropped fades out in place and takes no room from the others.\n for (const t of ticks) if (t.value !== undefined && leaving.includes(t.value)) t.opacity = 0\n // Ticks outside the gliding ends fade out; only the ones inside take room.\n const { ranged, range } = inRange(\n ticks.filter((t) => t.opacity > 0),\n domain\n )\n // How far a row of labels reaches out from the edge.\n const depth = Math.max(0, ...ranged.map((t) => Math.abs(n.x) * t.w + Math.abs(n.y) * t.h))\n const row = { x: n.x * (depth + PAD), y: n.y * (depth + PAD) }\n const rows = fit(ranged, n, row)\n // The line of the axis runs the gliding span of its ticks, within the\n // gliding ends: a tick beyond them would drag it out of the box, and one\n // the data adds or drops would make it jump instead of glide.\n const [s0, s1] = span ?? [edge[0][axis], edge[edge.length - 1][axis]]\n const start = along(edge, clamp(range.lo, range.hi, s0))\n const end = along(edge, clamp(range.lo, range.hi, s1))\n const middle = { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 }\n const head: AxisLabel | undefined = title\n ? { ...label(`${id}-title`, middle, title, 12, GAP + depth + GAP), title: true }\n : undefined\n if (head && rows === 2) head.shift = row\n // The edges the axis does not sit on keep their labels in place, unseen, to fade them in.\n hideOffRange([...ticks, ...(head ? [head] : [])], range, chosen)\n // The axis line runs its edge between its outermost ticks; a mark points out from every\n // tick, as far out as its label is clear of it, and hides where the label does.\n const line: AxisLine = { key: id, from: start, to: end, opacity: chosen ? 1 : 0 }\n const marks = edge.map((tick, i) => ({\n key: ticks[i].key,\n from: tick.projected,\n to: { x: tick.projected.x + n.x * MARK, y: tick.projected.y + n.y * MARK },\n opacity: ticks[i].opacity,\n }))\n return { chosen, ticks, title: head, line, marks }\n}\n\n/**\n * Fits the tick labels of an edge into the space between its ticks: in one\n * row if they keep `PAD` apart, or slid along the edge if no label has to\n * slide further than `DODGE`, else every other label a `row` further out if\n * that is enough, else every `stride`-th label of one row, 2, 4, 8… The\n * labels of a stride are among those of the one before, so as the edge\n * shortens, a label only ever leaves and none comes in for it. Returns the rows.\n */\nfunction fit(ticks: AxisLabel[], normal: Point2D, row: Point2D) {\n if (clear(ticks, 1) || slide(ticks, normal)) return 1\n ticks.forEach((t, i) => (t.shift = i % 2 ? row : ZERO))\n if (clear(ticks, 2)) return 2\n ticks.forEach((t) => (t.shift = ZERO))\n let stride = 2\n while (stride < ticks.length && !clear(ticks, stride, stride)) stride *= 2\n ticks.forEach((t, i) => (t.opacity = i % stride ? 0 : 1))\n return 1\n}\n\n/** Whether every label from every `every`-th keeps `PAD` apart from the one `step` after it. */\nfunction clear(ticks: AxisLabel[], step: number, every = 1) {\n // A hair under PAD, as labels that `slide` sets exactly PAD apart may round to less.\n return ticks.every(\n (t, i) => i % every > 0 || i + step >= ticks.length || apart(t, ticks[i + step]) > PAD - 1e-6\n )\n}\n\n/**\n * Slides the labels of an edge along it, square to its `normal`, as little\n * as they can until each has the room it needs. True if that is enough and\n * no label slides further than `DODGE`; the slide grows from nothing as the\n * labels near, so it follows the camera without a jump.\n */\nfunction slide(ticks: AxisLabel[], normal: Point2D) {\n const t = { x: -normal.y, y: normal.x }\n const along = ({ at }: AxisLabel) => at.x * t.x + at.y * t.y\n // The labels in their order along the edge, whichever way its ticks run.\n const line = [...ticks].sort((a, b) => along(a) - along(b))\n const gaps = line.slice(1).map((b, i) => room(line[i], b, normal, t))\n const placed = dodge(line.map(along), gaps)\n line.forEach((label, i) => {\n const d = placed[i] - along(label)\n label.shift = { x: t.x * d, y: t.y * d }\n })\n return line.every((label, i) => Math.abs(placed[i] - along(label)) <= DODGE) && clear(ticks, 1)\n}\n\n/**\n * How far along `t` the label `b` has to stand from `a`, which comes before\n * it there, for their boxes to keep `PAD` apart, as far as they stand apart\n * along `normal`, square to `t`.\n */\nfunction room(a: AxisLabel, b: AxisLabel, normal: Point2D, t: Point2D) {\n const off = (b.at.x - a.at.x) * normal.x + (b.at.y - a.at.y) * normal.y\n const x = ((a.w + b.w) / 2 + PAD - off * normal.x * Math.sign(t.x)) / Math.abs(t.x)\n const y = ((a.h + b.h) / 2 + PAD - off * normal.y * Math.sign(t.y)) / Math.abs(t.y)\n return Math.min(x, y)\n}\n\n/**\n * Places points on a line in their order, `gaps[i]` at least between the\n * i-th and the next, and moves them as little as it can: points that would\n * come too close move as one block, centred on the places they want.\n */\nfunction dodge(want: number[], gaps: number[]) {\n const blocks: { start: number; offsets: number[]; at: number }[] = []\n want.forEach((at, start) => {\n let block = { start, offsets: [0], at }\n let last = blocks.at(-1)\n while (last && last.at + last.offsets.at(-1)! + gaps[block.start - 1] > block.at) {\n blocks.pop()\n const base = last.offsets.at(-1)! + gaps[block.start - 1]\n const offsets = [...last.offsets, ...block.offsets.map((o) => o + base)]\n const first = last.start\n // Where the block moves its points the least: the mean of the places they want.\n const mean = offsets.reduce((sum, o, k) => sum + want[first + k] - o, 0) / offsets.length\n block = { start: first, offsets, at: mean }\n last = blocks.at(-1)\n }\n blocks.push(block)\n })\n return blocks.flatMap((block) => block.offsets.map((o) => block.at + o))\n}\n\n/**\n * How much of a label shows beside the labels placed before it: it fades as\n * it nears a label of another axis, by as much as that one shows. As this\n * follows the geometry, the label fades as smoothly as the camera turns.\n */\nfunction shows(label: AxisLabel, placed: AxisLabel[]) {\n return placed.reduce(\n (opacity, p) =>\n p.axis === label.axis\n ? opacity\n : Math.min(opacity, 1 - (1 - clamp(0, 1, apart(label, p) / FADE)) * p.opacity),\n label.opacity\n )\n}\n\n/** The space between the boxes of two labels, negative where they overlap. */\nfunction apart(a: AxisLabel, b: AxisLabel) {\n const dx = Math.abs(a.at.x + a.shift.x - b.at.x - b.shift.x) - (a.w + b.w) / 2\n const dy = Math.abs(a.at.y + a.shift.y - b.at.y - b.shift.y) - (a.h + b.h) / 2\n return Math.max(dx, dy)\n}\n\n/**\n * The centre of a box `w`×`h` that lies `gap` from `at` towards `toward`, a\n * unit vector. As the vector turns, the box slides round `at` and keeps the\n * gap, where an anchor that switches from start to end would jump.\n */\nfunction beside(at: Point2D, toward: Point2D, w: number, h: number, gap: number): Point2D {\n const out = gap + (Math.abs(toward.x) * w + Math.abs(toward.y) * h) / 2\n return { x: at.x + toward.x * out, y: at.y + toward.y * out }\n}\n\n/** The width of a label at the font size `size`, guessed from its text, as the browser lays it out only after the render. */\nfunction textWidth(text: React.ReactNode, size: number) {\n // ponytail: 0.6em a character; measure with getBBox if wide fonts or rich labels still overlap.\n const chars = typeof text === \"string\" || typeof text === \"number\" ? String(text).length : 4\n return chars * size * 0.6\n}\n\n/**\n * A line of the axes, in the ink of the kind it is: the line of an axis along\n * its edge, or the mark of one of its ticks. Its place follows the camera at\n * once; a change of edge fades it in a transition.\n */\nfunction AxisLine3D({\n line: { from, to, opacity },\n ink,\n width,\n}: {\n line: AxisLine\n ink: string\n width: number\n}) {\n return (\n <line\n x1={from.x}\n y1={from.y}\n x2={to.x}\n y2={to.y}\n strokeWidth={width}\n style={{ opacity: Math.round(opacity * 100) / 100 }}\n className={cn(\"transition-opacity duration-300 ease-out motion-reduce:transition-none\", ink)}\n />\n )\n}\n\n/**\n * A label of the chart box. Its place follows the camera at once; a change\n * of edge, of row or of the labels that fit fades and moves it in a transition.\n */\nfunction AxisLabel3D({ label: { at, shift, opacity, text, title } }: { label: AxisLabel }) {\n return (\n <text\n x={at.x}\n y={at.y}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n style={{ opacity: Math.round(opacity * 100) / 100, translate: `${shift.x}px ${shift.y}px` }}\n className={cn(\n \"transition-[opacity,translate] duration-300 ease-out motion-reduce:transition-none\",\n title ? \"fill-foreground font-medium\" : \"fill-muted-foreground text-[10px]\"\n )}\n >\n {text}\n </text>\n )\n}\n\n/** A nice axis from `lo` to `hi` with about `count` ticks. */\nfunction axis(lo: number, hi: number, count = 5): AxisSpec {\n const [start, stop] = nice(lo, lo === hi ? hi + 1 : hi, count)\n return { domain: [start, stop], ticks: ticks(start, stop, count) }\n}\n\n/**\n * The axis `spec` with its domain widened by half a `cell` on each side, so\n * the box keeps room between the outermost data and its walls. The ticks stay\n * where they were, on the data.\n */\nfunction pad(spec: AxisSpec, cell: number): AxisSpec {\n return { domain: [spec.domain[0] - cell / 2, spec.domain[1] + cell / 2], ticks: spec.ticks }\n}\n\n/** The linear map from `domain` to `range`. */\nfunction linear([d0, d1]: number[], [r0, r1]: number[]) {\n return (value: number) => r0 + ((value - d0) / (d1 - d0 || 1)) * (r1 - r0)\n}\n\n/** The world box of `spec`: x from -1 to 1, y up from 1 to -1, z from -`depth` to `depth`. */\nfunction worldBox(spec: AxesSpec, depth = 1): World {\n return {\n x: linear(spec.x.domain, [-1, 1]),\n y: linear(spec.y.domain, [1, -1]),\n z: linear(spec.z.domain, [-depth, depth]),\n }\n}\n\n/**\n * Hands the projection its accessors into the world box, so every chart maps\n * its shapes onto the screen the same way.\n */\nfunction intoWorld<Datum extends Point3D, T extends ShapeInstance<Datum>>(\n projection: T,\n world: World\n): T {\n return projection\n .x((p) => world.x(p.x))\n .y((p) => world.y(p.y))\n .z((p) => world.z(p.z))\n}\n\n// From the upper left, towards the viewer, in view space where y points down.\nconst LIGHT = { x: -0.4, y: -0.8, z: 0.44 }\n\n/**\n * `color` lit by the light from the upper left: the face that looks at it\n * keeps the color, one that turns away gets darker. A CSS color-mix, so the\n * shade follows the theme variables.\n */\nfunction shade(face: TransformedPoint<unknown>[], color: string) {\n const n = normal(face.map((p) => p.rotated))\n // The normal of the side the camera sees, whichever way the face winds.\n const side = n.z < 0 ? -1 : 1\n const light = Math.max(0, side * (n.x * LIGHT.x + n.y * LIGHT.y + n.z * LIGHT.z))\n return `color-mix(in oklch, ${color} ${Math.round(65 + 35 * light)}%, black)`\n}\n\n/**\n * `color` at `opacity`, from 0 to 1: a CSS color-mix with transparent, so a\n * mark fades on every renderer while its color stays in CSS. Rounded to a\n * percent, so the renderers that resolve colors cache a bounded few. Fade\n * after `shade`, which would mix a translucent color back towards opaque.\n */\nfunction faded(color: string, opacity: number) {\n const percent = Math.round(opacity * 100)\n return percent >= 100 ? color : `color-mix(in oklab, ${color} ${percent}%, transparent)`\n}\n\n/**\n * The entries of `data` and their series, for a chart that lays the entries\n * out along x and the series along z, as the bar and the area chart do. The\n * name of every entry comes from its `index` field, the series are `keys` or\n * the keys of the config, and the `target` of every cell is keyed by the name\n * of its entry and its series, so it follows its entry when the data\n * reorders; a value that is not a number stands as 0. Each glides by name:\n * `values` from 0, `rows` - the place of every entry - to where it stands, and\n * `presence` from 0 to 1 as an entry comes and back as it goes, the gone ones\n * still among them. `labels` name the ticks: the entry at a tick of x, through\n * `format.x` - a tick of a gone entry fades out unnamed - and the series at a\n * tick of z.\n */\nfunction useSeries<T extends Record<string, unknown>>({\n data,\n index,\n keys,\n format = {},\n}: {\n data: T[]\n index: keyof T & string\n keys?: string[]\n format?: { x?: (label: string) => React.ReactNode; y?: (value: number) => React.ReactNode }\n}) {\n const { config } = useChart3D()\n const series = keys ?? Object.keys(config)\n const names = data.map((d) => String(d[index] ?? \"\"))\n const target = Object.fromEntries(\n data.flatMap((d, i) => series.map((key) => [`${names[i]}-${key}`, Number(d[key]) || 0]))\n )\n const labels = {\n x: (i: number) => (format.x ?? String)(names[i] ?? \"\"),\n y: format.y,\n z: (j: number) => config[series[j]]?.label ?? series[j],\n }\n return {\n series,\n target,\n values: useTween(target, 0),\n rows: useTween(Object.fromEntries(names.map((name, i) => [name, i]))),\n presence: useTween(Object.fromEntries(names.map((name) => [name, 1])), 0),\n labels,\n }\n}\n\n/** The marks of a cube: its faces that look at the camera, shaded in `color`, each with `tooltip` on hover. */\nfunction cubeMarks(id: string, faces: CubeFace[], color: string, tooltip: Tooltip3D): Mark3D[] {\n // The faces point outwards: a convex shape shows the ones facing the camera.\n return faces\n .filter((face) => face.ccw)\n .map((face) => ({\n key: `${id}-${face.face}`,\n points: face.map((p) => p.projected),\n fill: shade(face, color),\n tooltip,\n }))\n}\n\nexport {\n ChartContainer3D,\n ChartLegend3D,\n Axes3D,\n Marks3D,\n Labels3D,\n axis,\n pad,\n linear,\n worldBox,\n intoWorld,\n shade,\n faded,\n useSeries,\n cubeMarks,\n useTween,\n useTweenAxes,\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { range, ticks } from \"d3-array\"\nimport {\n polygons3D,\n sort,\n type AxesSpec,\n type Point3D,\n type Polygon,\n type Polygons3DInstance,\n} from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n intoWorld,\n pad,\n useSeries,\n shade,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n type Mark3D,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type AreaChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {\n /** One entry per point along x, with a value per series. */\n data: T[]\n /** The field that names each entry, such as \"year\"; a point follows its name through updates, so the names should be unique. */\n index: keyof T & string\n /**\n * The fields that hold the series, one ribbon each.\n * @defaultValue the keys of the chart config\n */\n keys?: string[]\n /** Formats the labels of the entries along x and the values along y. */\n format?: { x?: (label: string) => React.ReactNode; y?: (value: number) => React.ReactNode }\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n// The share of its row along z a ribbon covers.\nconst RIBBON = 2 / 3\n\n/**\n * Areas pushed back into ribbons: the entries of `data` along x, one ribbon\n * per series along z, the area under its line reaching down to the floor of\n * the box. The series are the keys of the chart config unless `keys` names\n * them.\n */\nexport function AreaChart3D<T extends Record<string, unknown>>({\n data,\n index,\n keys,\n format = {},\n titles,\n}: AreaChart3DProps<T>) {\n const { config, camera } = useChart3D()\n // The rows glide to their new places, and an entry that comes or goes\n // unfolds from its neighbour as far as its presence.\n const { series, target, values, rows, presence, labels } = useSeries({\n data,\n index,\n keys,\n format,\n })\n const spec = useTweenAxes(areaAxes(data.length, series.length, Object.values(target)))\n // The box deepens with the series, so a ribbon stays a ribbon, and glides\n // there with the axes.\n const depth = useTween({ depth: Math.min(1, Math.max(0.25, series.length / 6)) }).depth\n const world = worldBox(spec, depth)\n const polygons = intoWorld(polygons3D().camera(camera), world)\n // The x axis keeps half a row beyond the first and the last entry.\n const ends = [spec.x.domain[0] + 0.5, spec.x.domain[1] - 0.5]\n const toward = Math.sign(camera.viewDirection().x)\n const marks = series\n .flatMap((key, j) => {\n const line = linePoints(rows, values, presence, key, ends)\n if (!line.length) return []\n const z = [j - RIBBON / 2, j + RIBBON / 2]\n return [{ key, line, faces: ribbonFaces(polygons, line, spec.y.domain[0], z) }]\n })\n // The ribbons lie in slices of z of their own, and their floors span the\n // same x at the same height: ordered by the middle of the floor, they are\n // painted back to front exactly.\n .sort((a, b) => sort(a.faces[4], b.faces[4]))\n .flatMap(({ key, line, faces }) =>\n ribbonMarks(key, painted(faces, toward), line, config[key]?.label ?? key, format.x ?? String)\n )\n\n return (\n <>\n <Axes3D spec={spec} world={world} titles={titles} format={labels} />\n <Marks3D marks={marks} />\n </>\n )\n}\n\n/** One point of a line: the entry it stands for, its place along x and its value. */\ntype LinePoint = { name: string; x: number; value: number }\n\n/** One face of a ribbon after the projection, with its name and, on the top, its segment. */\ntype RibbonFace = Polygon<\n Point3D,\n Point3D[] & { face: \"front\" | \"back\" | \"left\" | \"right\" | \"bottom\" | \"top\"; segment: number }\n>\n\n/**\n * The points of the line of the series `key`, in order along x: every entry,\n * the ones still gliding away among them, at its gliding row and value. An\n * entry that comes or goes unfolds from the point before it - the one after\n * it, at the start of the line - and folds back into it, as far as its\n * `presence`, so the ribbon opens and closes without a step. Its value comes\n * from nothing as its presence grows - the two glide in step - so the part of\n * its neighbour it has not yet left is added: the point heads straight from\n * the neighbour to its own, never down towards the floor. Every\n * point stays within the gliding `ends` of the x axis, so a line with no\n * neighbour to unfold from - one that was empty - grows inside the box\n * instead of standing beyond its walls. A point only one of the tweens still\n * knows is on its way out and stays unseen.\n */\nfunction linePoints(\n rows: Record<string, number>,\n values: Record<string, number>,\n presence: Record<string, number>,\n key: string,\n [lo, hi]: number[]\n): LinePoint[] {\n const own = Object.entries(rows)\n .sort(([, a], [, b]) => a - b)\n .flatMap(([name, x]) => {\n const value = values[`${name}-${key}`]\n return value === undefined ? [] : [{ name, x, value, seen: presence[name] }]\n })\n let anchor = own.find((p) => p.seen === 1)\n return own\n .map((p) => {\n if (p.seen === 1) anchor = p\n const { x } = anchor ?? p\n return {\n name: p.name,\n x: Math.min(hi, Math.max(lo, x + p.seen * (p.x - x))),\n value: p.value + (1 - p.seen) * (anchor?.value ?? 0),\n }\n })\n .sort((a, b) => a.x - b.x)\n}\n\n/**\n * The faces of the ribbon of `line`, projected: the area under the line,\n * down to `floor`, pushed back from `z[0]` to `z[1]`. Each is wound\n * counter-clockwise as seen from outside, so `ccw` tells whether it faces the\n * camera. The first five lie on its bounding box - the front and the back,\n * one polygon each however many points the line has, the two ends and the\n * bottom - the rest are its top, one quad per segment of the line.\n */\nfunction ribbonFaces(\n polygons: Polygons3DInstance<Point3D>,\n line: LinePoint[],\n floor: number,\n [back, front]: number[]\n): RibbonFace[] {\n const on = (p: LinePoint, z: number) => ({ x: p.x, y: p.value, z })\n const under = (p: LinePoint, z: number) => ({ x: p.x, y: floor, z })\n const face = (name: RibbonFace[\"face\"], points: Point3D[], segment = -1) =>\n Object.assign(points, { face: name, segment })\n const [a, o] = [line[0], line[line.length - 1]]\n return polygons.data([\n face(\"front\", [\n on(a, front),\n under(a, front),\n under(o, front),\n ...line\n .slice(1)\n .reverse()\n .map((p) => on(p, front)),\n ]),\n face(\"back\", [...line.map((p) => on(p, back)), under(o, back), under(a, back)]),\n face(\"left\", [on(a, back), under(a, back), under(a, front), on(a, front)]),\n face(\"right\", [on(o, front), under(o, front), under(o, back), on(o, back)]),\n face(\"bottom\", [under(a, front), under(a, back), under(o, back), under(o, front)]),\n ...line\n .slice(1)\n .map((p, i) =>\n face(\"top\", [on(line[i], front), on(p, front), on(p, back), on(line[i], back)], i)\n ),\n ])\n}\n\n/**\n * The faces of a ribbon that face the camera, in paint order. Every segment\n * of the top is a slab, and the planes x = const separate them: the top is\n * painted from the end of the ribbon away from the camera, which `toward`,\n * the sign of x in the view direction, names. The faces of the bounding box\n * come last: the ribbon lies wholly behind each of them.\n */\nfunction painted(faces: RibbonFace[], toward: number) {\n const shown = faces.filter((f) => f.ccw)\n return [\n ...shown.filter((f) => f.face === \"top\").sort((a, b) => toward * (a.segment - b.segment)),\n ...shown.filter((f) => f.face !== \"top\"),\n ]\n}\n\n/**\n * The marks of one ribbon, shaded in the color of its series. Each face is a\n * group of its own, so hovering highlights the face under the pointer alone.\n * A segment of the top is keyed by the entry it starts at, so it keeps its\n * mark when entries come or go before it. Every face names the series; a\n * segment of the top tells the values at its two ends.\n */\nfunction ribbonMarks(\n key: string,\n faces: RibbonFace[],\n line: LinePoint[],\n label: React.ReactNode,\n name: (label: string) => React.ReactNode\n): Mark3D[] {\n const color = `var(--color-${key})`\n const spans = (f: RibbonFace) => (f.face === \"top\" ? [line[f.segment], line[f.segment + 1]] : [])\n return faces.map((f) => {\n const id = f.face === \"top\" ? `${key}-top-${line[f.segment].name}` : `${key}-${f.face}`\n return {\n key: id,\n points: f.map((p) => p.projected),\n fill: shade(f, color),\n groups: [id],\n tooltip: {\n title: label,\n items: spans(f).map((p) => ({ label: name(p.name), value: p.value, color })),\n },\n }\n })\n}\n\n/**\n * The axes of an area chart: the entries along x, with half a row of room\n * between the first and the last and the walls, a row per series along z.\n * A line has many entries, so x ticks about ten of them, not every one.\n */\nfunction areaAxes(entries: number, series: number, values: number[]): AxesSpec {\n const every = entries ? ticks(0, entries - 1, 10).filter(Number.isInteger) : []\n return {\n x: pad({ domain: [0, Math.max(0, entries - 1)], ticks: every }, 1),\n y: axis(Math.min(0, ...values), Math.max(0, ...values)),\n z: pad({ domain: [0, Math.max(0, series - 1)], ticks: range(series) }, 1),\n }\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { box, cubes3D, sort, type AxesSpec, type Camera3DInstance, type CubeFace } from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n cubeMarks,\n faded,\n pad,\n useSeries,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n type World,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type BarChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {\n /** One entry per row of bars, with a value per series. */\n data: T[]\n /** The field that names each entry, such as \"month\"; a bar follows its name through updates, so the names should be unique. */\n index: keyof T & string\n /**\n * The fields that hold the series, one row of bars each.\n * @defaultValue the keys of the chart config\n */\n keys?: string[]\n /**\n * The share of its cell a bar covers.\n * @defaultValue 0.6\n */\n barSize?: number\n /** Formats the labels of the entries along x and the values along y. */\n format?: { x?: (label: string) => React.ReactNode; y?: (value: number) => React.ReactNode }\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * Bars on a floor: one row per entry of `data` along x, one per series\n * along z, the value as the height. The series are the keys of the chart\n * config unless `keys` names them.\n */\nexport function BarChart3D<T extends Record<string, unknown>>({\n data,\n index,\n keys,\n barSize = 0.6,\n format,\n titles,\n}: BarChart3DProps<T>) {\n const { config, camera } = useChart3D()\n // A value that is not a number stands as no bar, one of height 0; a new one\n // grows from the floor, and a gone one shrinks back into it. The rows glide\n // to their new cells when the data reorders; a gone row stands in its cell\n // while its bars shrink and fade away, so a flat bar never pops.\n const { series, target, values, rows, presence, labels } = useSeries({\n data,\n index,\n keys,\n format,\n })\n const cells = barCells(rows, series, values)\n\n const box = barBox(data.length, series.length, Object.values(target))\n // Every axis glides with the bars: the value ends with the heights, the row\n // and series ends - and the depth of the box - as rows come and go. The\n // size of a bar comes from the gliding ends, so it eases with its cell.\n const spec = useTweenAxes(box.spec)\n const depth = useTween({ depth: box.depth }).depth\n const world = worldBox(spec, depth)\n const bars = barShapes(camera, cells, world, cellSize(spec, depth, barSize))\n\n return (\n <>\n <Axes3D spec={spec} world={world} titles={titles} format={labels} />\n <Marks3D\n marks={bars.flatMap((bar) =>\n barMarks({\n id: `${bar.name}-${bar.key}`,\n faces: bar.faces,\n color: `var(--color-${bar.key})`,\n title: bar.name,\n label: config[bar.key]?.label ?? bar.key,\n value: bar.value,\n opacity: presence[bar.name],\n })\n )}\n />\n </>\n )\n}\n\n/** The cubes of the cells, projected by `camera` and painted back to front by their footprint, as the bars stand on one floor. */\nfunction barShapes(\n camera: Camera3DInstance,\n cells: ReturnType<typeof barCells>,\n world: World,\n size: { width: number; depth: number }\n) {\n return cubes3D()\n .camera(camera)\n .data(\n cells.map(({ name, x, j, key, value }) =>\n Object.assign(barCorners(world, x, j, value, size), { name, key, value })\n )\n )\n .map((bar) => Object.assign(bar, { bottom: bar.faces.find((f) => f.face === \"bottom\")! }))\n .sort((a, b) => sort(a.bottom, b.bottom))\n}\n\n/**\n * The cell of every bar, the rows still gliding away among them: the row\n * position along x, the series `key` along z, with the tweened value. A cell\n * only one of the tweens still knows is on its way out and stays unseen.\n */\nfunction barCells(rows: Record<string, number>, series: string[], values: Record<string, number>) {\n return Object.entries(rows).flatMap(([name, x]) =>\n series.flatMap((key, j) => {\n const value = values[`${name}-${key}`]\n return value === undefined ? [] : [{ name, x, j, key, value }]\n })\n )\n}\n\n/**\n * The box of a bar chart: a row per entry along x, a row per series along z,\n * with half a cell of room between the outer rows and the walls.\n */\nfunction barBox(entries: number, series: number, values: number[]) {\n const index = (length: number) => Array.from({ length }, (_, i) => i)\n const spec: AxesSpec = {\n x: pad({ domain: [-0.5, entries - 0.5], ticks: index(entries) }, 1),\n y: axis(Math.min(0, ...values), Math.max(0, ...values)),\n z: pad({ domain: [-0.5, series - 0.5], ticks: index(series) }, 1),\n }\n // A shallow box for few series, so the bars stay square.\n const depth = Math.min(1, Math.max(0.25, series / entries))\n return { spec, depth }\n}\n\n/**\n * The size of a bar, the share `barSize` of its cell - of the gliding ends of\n * `spec`, so a bar eases into a new cell size as rows come and go.\n */\nfunction cellSize(spec: AxesSpec, depth: number, barSize: number) {\n return {\n width: (2 / (spec.x.domain[1] - spec.x.domain[0])) * barSize,\n depth: ((2 * depth) / (spec.z.domain[1] - spec.z.domain[0])) * barSize,\n }\n}\n\n/**\n * The corners of one bar, from the floor to its value, at row `x` and series\n * `z`. box() rises towards -y, so a negative bar starts at its value.\n */\nfunction barCorners(\n world: World,\n x: number,\n z: number,\n value: number,\n size: { width: number; depth: number }\n) {\n const floor = world.y(0)\n const top = world.y(value)\n return box({\n x: world.x(x),\n y: Math.max(floor, top),\n z: world.z(z),\n ...size,\n height: Math.abs(floor - top),\n })\n}\n\n/** The marks of one bar: the faces that look at the camera, shaded and faded to `opacity`, each with its entry and value on hover. Its group is the bar alone, so hovering highlights one bar, not its series. */\nfunction barMarks({\n id,\n faces,\n color,\n title,\n label,\n value,\n opacity,\n}: {\n id: string\n faces: CubeFace[]\n color: string\n title: string\n label: React.ReactNode\n value: number\n opacity: number\n}) {\n const tooltip = {\n title,\n items: [{ label, value, color }],\n }\n return cubeMarks(id, faces, color, tooltip).map((mark) => ({\n ...mark,\n fill: faded(mark.fill, opacity),\n groups: [id],\n }))\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { extent } from \"d3-array\"\nimport { points3D, sort, type AxesSpec, type Point3D } from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n faded,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n type ChartConfig,\n type World,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type ScatterChart3DProps<T extends Record<string, unknown> = Record<string, unknown>> = {\n /** One entry per point. */\n data: T[]\n /** The field of the position along x. */\n x: keyof T & string\n /** The field of the position along y, the height. */\n y: keyof T & string\n /** The field of the position along z. */\n z: keyof T & string\n /**\n * The field that names an entry, so a point follows its name through\n * updates: a new one grows, a gone one shrinks away, one that moves glides.\n * The names should be unique.\n * @defaultValue the position of the entry\n */\n id?: keyof T & string\n /**\n * The field whose value is the config key of the color of a point.\n * @defaultValue the first key of the chart config for every point\n */\n series?: keyof T & string\n /**\n * The radius of a point in the units of the view box.\n * @defaultValue 4\n */\n radius?: number\n /** Formats the tick labels of each axis. */\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * Points in the chart box, at the fields `x`, `y` and `z` of each entry.\n * `series` names the field whose value is the config key of the color.\n */\nexport function ScatterChart3D<T extends Record<string, unknown>>({\n data,\n x,\n y,\n z,\n id,\n series,\n radius = 4,\n format,\n titles,\n}: ScatterChart3DProps<T>) {\n const { config, camera } = useChart3D()\n const fields = { x, y, z }\n const names = data.map((d, i) => (id ? String(d[id]) : String(i)))\n const { radii, opacity, read, key } = usePointTweens(names, data, fields, series, config, radius)\n\n // The axes of the data the chart glides into; their ends glide along.\n const spec = useTweenAxes(pointAxes(data, fields))\n const world = worldBox(spec)\n const placed = usePointPlaces(names, radii, read, world)\n\n const points = points3D<{ name: string } & Point3D>()\n .camera(camera)\n .x((p) => p.x)\n .y((p) => p.y)\n .z((p) => p.z)\n\n const marks = points\n .data(placed)\n .sort(sort)\n .map((p) => ({\n key: p.name,\n points: [p.projected],\n r: radii[p.name],\n fill: faded(`var(--color-${key(p.name)})`, opacity[p.name]),\n // Its group is the point alone, so hovering highlights that point only.\n groups: [p.name],\n // Ringed by the background, so that points in front stand out.\n stroke: faded(\"var(--background)\", opacity[p.name]),\n tooltip: {\n title: series ? (config[key(p.name)]?.label ?? key(p.name)) : undefined,\n items: ([\"x\", \"y\", \"z\"] as const).map((a) => ({\n label: titles?.[a] ?? fields[a],\n value: read(p.name, a),\n })),\n },\n }))\n\n return (\n <>\n <Axes3D spec={spec} world={world} format={format} titles={titles} />\n <Marks3D marks={marks} />\n </>\n )\n}\n\n/** The axes that hold every entry of `data`, a nice one per field. */\nfunction pointAxes<T extends Record<string, unknown>>(\n data: T[],\n fields: Record<keyof AxesSpec, keyof T & string>\n): AxesSpec {\n const range = (a: keyof AxesSpec) => {\n const [lo = 0, hi = 0] = extent(data, (d) => Number(d[fields[a]]))\n return axis(lo, hi)\n }\n return { x: range(\"x\"), y: range(\"y\"), z: range(\"z\") }\n}\n\n/**\n * The tweened numbers of the chart, by the name of each entry: the positions\n * glide entry by entry - a gone point stands in place - and the radius and\n * the opacity enter from 0, so a new point grows as it fades in and a gone\n * one shrinks as it fades away. `read` and `key` look them up, also for a\n * point still leaving.\n */\nfunction usePointTweens<T extends Record<string, unknown>>(\n names: string[],\n data: T[],\n fields: Record<keyof AxesSpec, keyof T & string>,\n series: (keyof T & string) | undefined,\n config: ChartConfig,\n radius: number\n) {\n const values = useTween(pointValues(names, data, fields))\n const radii = useTween(Object.fromEntries(names.map((name) => [name, radius])), 0)\n const opacity = useTween(Object.fromEntries(names.map((name) => [name, 1])), 0)\n const fallback = Object.keys(config)[0]\n return {\n radii,\n opacity,\n read: (name: string, axis: keyof AxesSpec) => values[`${axis}${name}`],\n key: usePointKeys(names, data, series, fallback, radii),\n }\n}\n\n/**\n * The place of every point in the world box, by name. A living point follows\n * its gliding numbers through the gliding axes; a gone one stays frozen where\n * it was, so it shrinks away in place instead of riding the rescaling axes\n * out of the box. A point only one of the tweens still knows stays unseen.\n */\nfunction usePointPlaces(\n names: string[],\n alive: Record<string, number>,\n read: (name: string, axis: keyof AxesSpec) => number,\n world: World\n) {\n const places = React.useRef(new Map<string, Point3D>())\n const live = new Set(names)\n const placed = Object.keys(alive).flatMap((name) => {\n if (!live.has(name)) {\n const held = places.current.get(name)\n return held ? [{ name, ...held }] : []\n }\n const p = {\n x: world.x(read(name, \"x\")),\n y: world.y(read(name, \"y\")),\n z: world.z(read(name, \"z\")),\n }\n places.current.set(name, p)\n return [{ name, ...p }]\n })\n // Forgotten with the point, so the memory stays the size of the chart.\n for (const name of places.current.keys()) if (!(name in alive)) places.current.delete(name)\n return placed\n}\n\n/** The position of every entry, keyed by its axis and name, gliding into new data. */\nfunction pointValues<T extends Record<string, unknown>>(\n names: string[],\n data: T[],\n fields: Record<keyof AxesSpec, keyof T & string>\n) {\n return Object.fromEntries(\n data.flatMap((d, i) =>\n ([\"x\", \"y\", \"z\"] as const).map((a) => [`${a}${names[i]}`, Number(d[fields[a]])])\n )\n )\n}\n\n/**\n * The config key of every point's color, by name - remembered while a gone\n * point shrinks away, since its entry has already left the data - and\n * forgotten with the point, so the memory stays the size of the chart.\n */\nfunction usePointKeys<T extends Record<string, unknown>>(\n names: string[],\n data: T[],\n series: (keyof T & string) | undefined,\n fallback: string,\n alive: Record<string, number>\n) {\n const known = React.useRef(new Map<string, string>())\n data.forEach((d, i) => known.current.set(names[i], series ? String(d[series]) : fallback))\n for (const name of known.current.keys()) {\n if (!(name in alive) && !names.includes(name)) known.current.delete(name)\n }\n return (name: string) => known.current.get(name) ?? fallback\n}\n","\"use client\"\n\nimport * as React from \"react\"\nimport { extent } from \"d3-array\"\nimport {\n gridPlanes3D,\n sort,\n type AxesSpec,\n type GridPlane,\n type GridPlanes3DInstance,\n type Point3D,\n} from \"d3-3d\"\n\nimport {\n Axes3D,\n Marks3D,\n axis,\n intoWorld,\n linear,\n pad,\n shade,\n useChart3D,\n useTween,\n useTweenAxes,\n worldBox,\n} from \"@/registry/new-york/ui/chart-3d\"\n\nexport type SurfaceChart3DProps = {\n /** The heights on the grid, `data[row][column]`. */\n data: number[][]\n /**\n * The data values the first and the last column (x) and row (z) stand for.\n * The chart keeps half a cell between the grid and the walls of its box; a\n * domain given here names the box exactly, without that room.\n * @defaultValue the indices of the columns and rows\n */\n domain?: { x?: [number, number]; z?: [number, number] }\n /**\n * The config keys of the colors at the lowest and at the highest height.\n * @defaultValue the first two keys of the chart config\n */\n colors?: [string, string]\n /** Formats the tick labels of each axis. */\n format?: Partial<Record<keyof AxesSpec, (value: number) => React.ReactNode>>\n /** The titles of the axes. */\n titles?: Partial<Record<keyof AxesSpec, React.ReactNode>>\n}\n\n/**\n * A surface over a grid: `data[row][column]` is the height, the columns run\n * along x and the rows along z. The fill ramps from the first color of\n * `colors` at the lowest height to the second at the highest; both are keys\n * of the chart config, by default its first two.\n */\nexport function SurfaceChart3D({ data, domain = {}, colors, format, titles }: SurfaceChart3DProps) {\n const { config, camera } = useChart3D()\n const [low, high = low] = colors ?? Object.keys(config)\n const [floor = 0, peak = 0] = extent(data.flat())\n const target = gridValues(data)\n // The heights glide cell by cell, so the surface, its color ramp and the y\n // axis follow. Coming and going is a fade in place - a new border cell\n // fades in where it belongs, a gone one fades out where it stands and\n // leaves when the glide is done - so the surface never moves where data\n // merely appears or disappears.\n const heights = gridHeights(useTween(target), floor)\n const fade = useTween(Object.fromEntries(Object.keys(target).map((k) => [k, 1])), 0)\n const rows = data.length\n const columns = data[0]?.length ?? 0\n const [x0, x1] = domain.x ?? [0, columns - 1]\n const [z0, z1] = domain.z ?? [0, rows - 1]\n // A cell of the grid, along x and along z, in the values the data stands for.\n const cell = {\n x: (x1 - x0) / Math.max(1, columns - 1),\n z: (z1 - z0) / Math.max(1, rows - 1),\n }\n // The color ramp follows the heights on screen, the axes glide to those of the data.\n const [lo = 0, hi = 0] = extent(heights.flat())\n\n // The box keeps half a cell beyond the grid; a domain the reader hands the\n // chart names the box exactly.\n const spec = useTweenAxes({\n x: domain.x ? axis(x0, x1) : pad(axis(x0, x1), cell.x),\n y: axis(floor, peak),\n z: domain.z ? axis(z0, z1) : pad(axis(z0, z1), cell.z),\n })\n const world = worldBox(spec)\n const toX = linear([0, columns - 1], [x0, x1])\n const toZ = linear([0, rows - 1], [z0, z1])\n\n const grid = intoWorld<GridPoint, GridPlanes3DInstance<GridPoint>>(\n gridPlanes3D<GridPoint>().camera(camera),\n world\n )\n // d3-3d reads rows(0) as the getter; a grid without columns has no points anyway.\n .rows(Math.max(1, heights[0]?.length ?? 0))\n const points = heights.flatMap((row, r) => row.map((y, c) => ({ x: toX(c), y, z: toZ(r), r, c })))\n\n const marks = grid\n .data(points)\n .sort(sort)\n .map((quad) => quadMark(quad, fade, { lo, hi, low, high }, titles?.y))\n\n return (\n <>\n <Axes3D spec={spec} world={world} format={format} titles={titles} />\n <Marks3D marks={marks} />\n </>\n )\n}\n\n/** A point of the lattice, carrying the row and column it stands for. */\ntype GridPoint = Point3D & { r: number; c: number }\n\n/**\n * The mark of one cell: its quad, shaded by the color ramp at its height and\n * faded in place by `fade` while the cell enters or leaves.\n */\nfunction quadMark(\n quad: GridPlane<GridPoint>,\n fade: Record<string, number>,\n ramp: { lo: number; hi: number; low: string; high: string },\n title: React.ReactNode\n) {\n const height = quad.reduce((sum, p) => sum + p.y, 0) / quad.length\n const t = Math.round(((height - ramp.lo) / (ramp.hi - ramp.lo || 1)) * 100)\n const shaded = shade(\n quad,\n `color-mix(in oklch, var(--color-${ramp.high}) ${t}%, var(--color-${ramp.low}))`\n )\n // A corner only one of the tweens still knows is on its way out and stays unseen.\n const seen = Math.min(...quad.map((p) => fade[`${p.r}-${p.c}`] ?? 0))\n return {\n key: quad.plane,\n points: quad.map((p) => p.projected),\n fill:\n seen < 1 ? `color-mix(in srgb, ${shaded} ${Math.round(seen * 100)}%, transparent)` : shaded,\n // Its group is the cell, so hovering it lights the cell alone.\n groups: [quad.plane],\n tooltip: { items: [{ label: title ?? \"value\", value: height }] },\n }\n}\n\n/** The height of every cell, keyed by its row and column, gliding into new data. */\nfunction gridValues(data: number[][]) {\n return Object.fromEntries(data.flatMap((row, r) => row.map((y, c) => [`${r}-${c}`, y])))\n}\n\n/**\n * The gliding heights as a lattice. It spans the cells still leaving too, so\n * a shrunken grid sinks away instead of popping; a corner only one dimension\n * kept stands at the floor until it goes.\n */\nfunction gridHeights(tweened: Record<string, number>, floor: number) {\n let rows = 0\n let columns = 0\n for (const key of Object.keys(tweened)) {\n const [r, c] = key.split(\"-\").map(Number)\n rows = Math.max(rows, r + 1)\n columns = Math.max(columns, c + 1)\n }\n return Array.from({ length: rows }, (_, r) =>\n Array.from({ length: columns }, (_, c) => tweened[`${r}-${c}`] ?? floor)\n )\n}\n"],"mappings":";;;;;;;;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