@tetrascience-npm/ts-lib-viz 0.0.0-stage → 0.1.5

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.
Files changed (278) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +2171 -2
  3. package/dist/src/builder/PlotPanel.d.ts +42 -0
  4. package/dist/src/builder/PlotPanel.js +433 -0
  5. package/dist/src/builder/Popover.d.ts +37 -0
  6. package/dist/src/builder/Popover.js +32 -0
  7. package/dist/src/builder/Stepper.d.ts +21 -0
  8. package/dist/src/builder/Stepper.js +41 -0
  9. package/dist/src/builder/index.d.ts +10 -0
  10. package/dist/src/builder/index.js +10 -0
  11. package/dist/src/core/adapters.d.ts +86 -0
  12. package/dist/src/core/adapters.js +219 -0
  13. package/dist/src/core/aggregate.d.ts +74 -0
  14. package/dist/src/core/aggregate.js +102 -0
  15. package/dist/src/core/annotations.d.ts +34 -0
  16. package/dist/src/core/annotations.js +71 -0
  17. package/dist/src/core/band-order.d.ts +86 -0
  18. package/dist/src/core/band-order.js +132 -0
  19. package/dist/src/core/binning.d.ts +123 -0
  20. package/dist/src/core/binning.js +193 -0
  21. package/dist/src/core/bounds.d.ts +40 -0
  22. package/dist/src/core/bounds.js +107 -0
  23. package/dist/src/core/brush.d.ts +73 -0
  24. package/dist/src/core/brush.js +102 -0
  25. package/dist/src/core/build.d.ts +322 -0
  26. package/dist/src/core/build.js +496 -0
  27. package/dist/src/core/camera.d.ts +152 -0
  28. package/dist/src/core/camera.js +303 -0
  29. package/dist/src/core/capabilities.d.ts +24 -0
  30. package/dist/src/core/capabilities.js +307 -0
  31. package/dist/src/core/chord.d.ts +49 -0
  32. package/dist/src/core/chord.js +57 -0
  33. package/dist/src/core/circular.d.ts +83 -0
  34. package/dist/src/core/circular.js +63 -0
  35. package/dist/src/core/cluster.d.ts +136 -0
  36. package/dist/src/core/cluster.js +607 -0
  37. package/dist/src/core/critique.d.ts +92 -0
  38. package/dist/src/core/critique.js +905 -0
  39. package/dist/src/core/density.d.ts +38 -0
  40. package/dist/src/core/density.js +82 -0
  41. package/dist/src/core/figure-set.d.ts +34 -0
  42. package/dist/src/core/figure-set.js +55 -0
  43. package/dist/src/core/finding-codes.d.ts +10 -0
  44. package/dist/src/core/finding-codes.js +1 -0
  45. package/dist/src/core/fit-types.d.ts +46 -0
  46. package/dist/src/core/fit-types.js +7 -0
  47. package/dist/src/core/fitter.d.ts +62 -0
  48. package/dist/src/core/fitter.js +102 -0
  49. package/dist/src/core/frame-geometry.d.ts +407 -0
  50. package/dist/src/core/frame-geometry.js +612 -0
  51. package/dist/src/core/frame.d.ts +329 -0
  52. package/dist/src/core/frame.js +1432 -0
  53. package/dist/src/core/geom-table.d.ts +503 -0
  54. package/dist/src/core/geom-table.js +484 -0
  55. package/dist/src/core/geom-types.d.ts +182 -0
  56. package/dist/src/core/geom-types.js +17 -0
  57. package/dist/src/core/grammar.d.ts +359 -0
  58. package/dist/src/core/grammar.js +397 -0
  59. package/dist/src/core/heat-reductions.d.ts +36 -0
  60. package/dist/src/core/heat-reductions.js +133 -0
  61. package/dist/src/core/hexbin.d.ts +84 -0
  62. package/dist/src/core/hexbin.js +168 -0
  63. package/dist/src/core/hierarchy.d.ts +59 -0
  64. package/dist/src/core/hierarchy.js +248 -0
  65. package/dist/src/core/hit.d.ts +75 -0
  66. package/dist/src/core/hit.js +37 -0
  67. package/dist/src/core/index.d.ts +33 -0
  68. package/dist/src/core/index.js +18 -0
  69. package/dist/src/core/internal.d.ts +58 -0
  70. package/dist/src/core/internal.js +58 -0
  71. package/dist/src/core/labels.d.ts +37 -0
  72. package/dist/src/core/labels.js +54 -0
  73. package/dist/src/core/layers.d.ts +594 -0
  74. package/dist/src/core/layers.js +2892 -0
  75. package/dist/src/core/load.d.ts +17 -0
  76. package/dist/src/core/load.js +356 -0
  77. package/dist/src/core/marginal.d.ts +65 -0
  78. package/dist/src/core/marginal.js +116 -0
  79. package/dist/src/core/mesh.d.ts +69 -0
  80. package/dist/src/core/mesh.js +237 -0
  81. package/dist/src/core/omission.d.ts +41 -0
  82. package/dist/src/core/omission.js +62 -0
  83. package/dist/src/core/palette-sets.d.ts +623 -0
  84. package/dist/src/core/palette-sets.js +1058 -0
  85. package/dist/src/core/palette.d.ts +871 -0
  86. package/dist/src/core/palette.js +511 -0
  87. package/dist/src/core/plot-data.d.ts +71 -0
  88. package/dist/src/core/plot-data.js +82 -0
  89. package/dist/src/core/predicate.d.ts +50 -0
  90. package/dist/src/core/predicate.js +20 -0
  91. package/dist/src/core/profile.d.ts +111 -0
  92. package/dist/src/core/profile.js +221 -0
  93. package/dist/src/core/readout.d.ts +108 -0
  94. package/dist/src/core/readout.js +215 -0
  95. package/dist/src/core/region.d.ts +56 -0
  96. package/dist/src/core/region.js +101 -0
  97. package/dist/src/core/rings.d.ts +96 -0
  98. package/dist/src/core/rings.js +171 -0
  99. package/dist/src/core/rules.d.ts +45 -0
  100. package/dist/src/core/rules.js +69 -0
  101. package/dist/src/core/sankey.d.ts +49 -0
  102. package/dist/src/core/sankey.js +96 -0
  103. package/dist/src/core/select.d.ts +52 -0
  104. package/dist/src/core/select.js +216 -0
  105. package/dist/src/core/side-track.d.ts +98 -0
  106. package/dist/src/core/side-track.js +197 -0
  107. package/dist/src/core/sizing.d.ts +54 -0
  108. package/dist/src/core/sizing.js +37 -0
  109. package/dist/src/core/spec-edit.d.ts +68 -0
  110. package/dist/src/core/spec-edit.js +105 -0
  111. package/dist/src/core/spec.d.ts +1111 -0
  112. package/dist/src/core/spec.js +39 -0
  113. package/dist/src/core/stats.d.ts +161 -0
  114. package/dist/src/core/stats.js +318 -0
  115. package/dist/src/core/tick-format.d.ts +21 -0
  116. package/dist/src/core/tick-format.js +87 -0
  117. package/dist/src/core/tokens.d.ts +47 -0
  118. package/dist/src/core/tokens.js +138 -0
  119. package/dist/src/core/transform.d.ts +21 -0
  120. package/dist/src/core/transform.js +19 -0
  121. package/dist/src/core/voxels.d.ts +53 -0
  122. package/dist/src/core/voxels.js +129 -0
  123. package/dist/src/core/zoom.d.ts +76 -0
  124. package/dist/src/core/zoom.js +103 -0
  125. package/dist/src/graph/GraphSurface.d.ts +127 -0
  126. package/dist/src/graph/GraphSurface.js +423 -0
  127. package/dist/src/graph/data.d.ts +103 -0
  128. package/dist/src/graph/data.js +140 -0
  129. package/dist/src/graph/index.d.ts +7 -0
  130. package/dist/src/graph/index.js +7 -0
  131. package/dist/src/mcp/data.d.ts +28 -0
  132. package/dist/src/mcp/data.js +131 -0
  133. package/dist/src/mcp/index.d.ts +7 -0
  134. package/dist/src/mcp/index.js +7 -0
  135. package/dist/src/mcp/paths.d.ts +12 -0
  136. package/dist/src/mcp/paths.js +30 -0
  137. package/dist/src/mcp/render.d.ts +67 -0
  138. package/dist/src/mcp/render.js +189 -0
  139. package/dist/src/mcp/server.d.ts +7 -0
  140. package/dist/src/mcp/server.js +25 -0
  141. package/dist/src/mcp/tools.d.ts +82 -0
  142. package/dist/src/mcp/tools.js +412 -0
  143. package/dist/src/react/BrushLayer.d.ts +20 -0
  144. package/dist/src/react/BrushLayer.js +98 -0
  145. package/dist/src/react/ColorLegend.d.ts +45 -0
  146. package/dist/src/react/ColorLegend.js +64 -0
  147. package/dist/src/react/Figure.d.ts +19 -0
  148. package/dist/src/react/Figure.js +6 -0
  149. package/dist/src/react/Frame.d.ts +87 -0
  150. package/dist/src/react/Frame.js +192 -0
  151. package/dist/src/react/MarkLegend.d.ts +32 -0
  152. package/dist/src/react/MarkLegend.js +24 -0
  153. package/dist/src/react/SeriesLegend.d.ts +38 -0
  154. package/dist/src/react/SeriesLegend.js +27 -0
  155. package/dist/src/react/SizeLegend.d.ts +24 -0
  156. package/dist/src/react/SizeLegend.js +25 -0
  157. package/dist/src/react/Toolbar.d.ts +109 -0
  158. package/dist/src/react/Toolbar.js +483 -0
  159. package/dist/src/react/Tooltip.d.ts +37 -0
  160. package/dist/src/react/Tooltip.js +59 -0
  161. package/dist/src/react/Viz.d.ts +112 -0
  162. package/dist/src/react/Viz.js +1311 -0
  163. package/dist/src/react/export.d.ts +32 -0
  164. package/dist/src/react/export.js +181 -0
  165. package/dist/src/react/geoms/Area.d.ts +38 -0
  166. package/dist/src/react/geoms/Area.js +48 -0
  167. package/dist/src/react/geoms/Bars.d.ts +130 -0
  168. package/dist/src/react/geoms/Bars.js +164 -0
  169. package/dist/src/react/geoms/Box.d.ts +50 -0
  170. package/dist/src/react/geoms/Box.js +32 -0
  171. package/dist/src/react/geoms/Chord.d.ts +60 -0
  172. package/dist/src/react/geoms/Chord.js +78 -0
  173. package/dist/src/react/geoms/Contour.d.ts +44 -0
  174. package/dist/src/react/geoms/Contour.js +78 -0
  175. package/dist/src/react/geoms/DensityCurve.d.ts +30 -0
  176. package/dist/src/react/geoms/DensityCurve.js +38 -0
  177. package/dist/src/react/geoms/FitCurve.d.ts +26 -0
  178. package/dist/src/react/geoms/FitCurve.js +52 -0
  179. package/dist/src/react/geoms/Freqpoly.d.ts +30 -0
  180. package/dist/src/react/geoms/Freqpoly.js +45 -0
  181. package/dist/src/react/geoms/Gauge.d.ts +42 -0
  182. package/dist/src/react/geoms/Gauge.js +90 -0
  183. package/dist/src/react/geoms/Heatmap.d.ts +79 -0
  184. package/dist/src/react/geoms/Heatmap.js +51 -0
  185. package/dist/src/react/geoms/Hexbin.d.ts +74 -0
  186. package/dist/src/react/geoms/Hexbin.js +89 -0
  187. package/dist/src/react/geoms/Icicle.d.ts +38 -0
  188. package/dist/src/react/geoms/Icicle.js +9 -0
  189. package/dist/src/react/geoms/Ideogram.d.ts +58 -0
  190. package/dist/src/react/geoms/Ideogram.js +77 -0
  191. package/dist/src/react/geoms/Interval.d.ts +30 -0
  192. package/dist/src/react/geoms/Interval.js +39 -0
  193. package/dist/src/react/geoms/Line.d.ts +39 -0
  194. package/dist/src/react/geoms/Line.js +52 -0
  195. package/dist/src/react/geoms/Parallel.d.ts +38 -0
  196. package/dist/src/react/geoms/Parallel.js +131 -0
  197. package/dist/src/react/geoms/Pie.d.ts +62 -0
  198. package/dist/src/react/geoms/Pie.js +59 -0
  199. package/dist/src/react/geoms/Points.d.ts +84 -0
  200. package/dist/src/react/geoms/Points.js +207 -0
  201. package/dist/src/react/geoms/Points3d.d.ts +49 -0
  202. package/dist/src/react/geoms/Points3d.js +58 -0
  203. package/dist/src/react/geoms/Radar.d.ts +39 -0
  204. package/dist/src/react/geoms/Radar.js +59 -0
  205. package/dist/src/react/geoms/Range.d.ts +31 -0
  206. package/dist/src/react/geoms/Range.js +20 -0
  207. package/dist/src/react/geoms/RingStack.d.ts +39 -0
  208. package/dist/src/react/geoms/RingStack.js +65 -0
  209. package/dist/src/react/geoms/Rule.d.ts +29 -0
  210. package/dist/src/react/geoms/Rule.js +51 -0
  211. package/dist/src/react/geoms/Sankey.d.ts +24 -0
  212. package/dist/src/react/geoms/Sankey.js +51 -0
  213. package/dist/src/react/geoms/Segment.d.ts +36 -0
  214. package/dist/src/react/geoms/Segment.js +39 -0
  215. package/dist/src/react/geoms/Sunburst.d.ts +46 -0
  216. package/dist/src/react/geoms/Sunburst.js +64 -0
  217. package/dist/src/react/geoms/Surface.d.ts +32 -0
  218. package/dist/src/react/geoms/Surface.js +49 -0
  219. package/dist/src/react/geoms/Text.d.ts +35 -0
  220. package/dist/src/react/geoms/Text.js +40 -0
  221. package/dist/src/react/geoms/Treemap.d.ts +39 -0
  222. package/dist/src/react/geoms/Treemap.js +16 -0
  223. package/dist/src/react/geoms/Violin.d.ts +56 -0
  224. package/dist/src/react/geoms/Violin.js +60 -0
  225. package/dist/src/react/geoms/Volume.d.ts +37 -0
  226. package/dist/src/react/geoms/Volume.js +40 -0
  227. package/dist/src/react/geoms/Waterfall.d.ts +43 -0
  228. package/dist/src/react/geoms/Waterfall.js +18 -0
  229. package/dist/src/react/geoms/cube-stage.d.ts +39 -0
  230. package/dist/src/react/geoms/cube-stage.js +85 -0
  231. package/dist/src/react/geoms/hierarchy-cells.d.ts +42 -0
  232. package/dist/src/react/geoms/hierarchy-cells.js +59 -0
  233. package/dist/src/react/geoms/sector-axis.d.ts +66 -0
  234. package/dist/src/react/geoms/sector-axis.js +99 -0
  235. package/dist/src/react/gl/GlMesh.d.ts +22 -0
  236. package/dist/src/react/gl/GlMesh.js +78 -0
  237. package/dist/src/react/gl/GlPoints.d.ts +45 -0
  238. package/dist/src/react/gl/GlPoints.js +117 -0
  239. package/dist/src/react/gl/GlVolume.d.ts +28 -0
  240. package/dist/src/react/gl/GlVolume.js +112 -0
  241. package/dist/src/react/gl/GlWalls.d.ts +24 -0
  242. package/dist/src/react/gl/GlWalls.js +55 -0
  243. package/dist/src/react/gl/context.d.ts +71 -0
  244. package/dist/src/react/gl/context.js +98 -0
  245. package/dist/src/react/gl/encode.d.ts +120 -0
  246. package/dist/src/react/gl/encode.js +215 -0
  247. package/dist/src/react/gl/index.d.ts +10 -0
  248. package/dist/src/react/gl/index.js +8 -0
  249. package/dist/src/react/gl/refresh.d.ts +7 -0
  250. package/dist/src/react/gl/refresh.js +19 -0
  251. package/dist/src/react/gl/renderer.d.ts +377 -0
  252. package/dist/src/react/gl/renderer.js +1081 -0
  253. package/dist/src/react/gl/shaders.d.ts +92 -0
  254. package/dist/src/react/gl/shaders.js +405 -0
  255. package/dist/src/react/gl/surface.d.ts +31 -0
  256. package/dist/src/react/gl/surface.js +73 -0
  257. package/dist/src/react/index.d.ts +12 -0
  258. package/dist/src/react/index.js +11 -0
  259. package/dist/src/react/orbit.d.ts +38 -0
  260. package/dist/src/react/orbit.js +81 -0
  261. package/dist/src/react/sides/DendrogramPanel.d.ts +32 -0
  262. package/dist/src/react/sides/DendrogramPanel.js +39 -0
  263. package/dist/src/react/sides/DensityPanel.d.ts +31 -0
  264. package/dist/src/react/sides/DensityPanel.js +37 -0
  265. package/dist/src/react/sides/HistogramPanel.d.ts +30 -0
  266. package/dist/src/react/sides/HistogramPanel.js +18 -0
  267. package/dist/src/react/sides/RugPanel.d.ts +28 -0
  268. package/dist/src/react/sides/RugPanel.js +21 -0
  269. package/dist/src/react/sides/TrackPanel.d.ts +37 -0
  270. package/dist/src/react/sides/TrackPanel.js +27 -0
  271. package/dist/src/react/theme.d.ts +48 -0
  272. package/dist/src/react/theme.js +148 -0
  273. package/dist/src/react/useFits.d.ts +26 -0
  274. package/dist/src/react/useFits.js +62 -0
  275. package/dist/src/react/useZoom.d.ts +50 -0
  276. package/dist/src/react/useZoom.js +141 -0
  277. package/package.json +164 -5
  278. package/theme/default.css +62 -0
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The gesture that turns a cube.
3
+ *
4
+ * The design language permits a third position scale where the reader can rotate, so this is part
5
+ * of the geom and not a control beside it. A cube that mounts without it is the static projection
6
+ * the rule refuses.
7
+ *
8
+ * The arithmetic is in `core/camera.ts` for the reason the 2D zoom's is in `core/zoom.ts`: what the
9
+ * orbit does to a matrix is a fact about numbers, and only the pointer handling needs a DOM. See
10
+ * the ADR "A third position scale is permitted where the reader can rotate".
11
+ */
12
+ import { type Orbit } from "../core/internal.js";
13
+ export interface OrbitControl {
14
+ orbit: Orbit;
15
+ /**
16
+ * Attach to the group the gesture is read over, which is also where the wheel is caught.
17
+ *
18
+ * The group and not a rectangle inside it: a rectangle drawn over the geoms to catch the drag
19
+ * takes their hover and their click along with it, and one drawn under them catches nothing
20
+ * where a geom is. Handlers on the group see both, since what a geom does not stop bubbles.
21
+ */
22
+ ref: React.RefObject<SVGGElement | null>;
23
+ onPointerDown: (event: React.PointerEvent) => void;
24
+ onPointerMove: (event: React.PointerEvent) => void;
25
+ onPointerUp: (event: React.PointerEvent) => void;
26
+ /** Whether a drag is in progress, so a cursor can say so. */
27
+ turning: boolean;
28
+ /**
29
+ * Whether the press that just ended turned the cube.
30
+ *
31
+ * A turn ends over a geom and the click that follows would select it. The flag holds until the
32
+ * next press, so the click belonging to a turn is the only one it suppresses. Same contract as
33
+ * the flat viewport's `panned`.
34
+ */
35
+ turned: () => boolean;
36
+ reset: () => void;
37
+ }
38
+ export declare function useOrbit(initial?: Orbit): OrbitControl;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The gesture that turns a cube.
3
+ *
4
+ * The design language permits a third position scale where the reader can rotate, so this is part
5
+ * of the geom and not a control beside it. A cube that mounts without it is the static projection
6
+ * the rule refuses.
7
+ *
8
+ * The arithmetic is in `core/camera.ts` for the reason the 2D zoom's is in `core/zoom.ts`: what the
9
+ * orbit does to a matrix is a fact about numbers, and only the pointer handling needs a DOM. See
10
+ * the ADR "A third position scale is permitted where the reader can rotate".
11
+ */
12
+ import { useCallback, useEffect, useRef, useState } from "react";
13
+ import { AT_REST_ORBIT, dollied, orbited } from "../core/internal.js";
14
+ /** Pointer travel that makes a press a turn and not a click, in pixels. */
15
+ const TURN_FLOOR = 3;
16
+ /** A notch of wheel, in the units `dollied` counts. Trackpads report pixels and mice report lines. */
17
+ const notchesOf = (event) => (event.deltaMode === 0 ? event.deltaY / 100 : event.deltaY);
18
+ export function useOrbit(initial = AT_REST_ORBIT) {
19
+ const [orbit, setOrbit] = useState(initial);
20
+ const [turning, setTurning] = useState(false);
21
+ const from = useRef(null);
22
+ /** Where the press began. A turn is read off the travel from here. */
23
+ const origin = useRef({ x: 0, y: 0 });
24
+ const moved = useRef(false);
25
+ const ref = useRef(null);
26
+ /*
27
+ The wheel listener is attached by hand because React's is passive, and a passive listener
28
+ cannot stop the page scrolling out from under a reader who meant to dolly in.
29
+ */
30
+ useEffect(() => {
31
+ const surface = ref.current;
32
+ if (!surface)
33
+ return;
34
+ const onWheel = (event) => {
35
+ /* A pinch arrives as a wheel with the control key held. A plain wheel scrolls the page. */
36
+ if (!event.ctrlKey)
37
+ return;
38
+ event.preventDefault();
39
+ setOrbit((held) => dollied(held, notchesOf(event)));
40
+ };
41
+ surface.addEventListener("wheel", onWheel, { passive: false });
42
+ return () => surface.removeEventListener("wheel", onWheel);
43
+ }, []);
44
+ const onPointerDown = useCallback((event) => {
45
+ /*
46
+ A turn is a drag, and a drag over text is a selection unless something says otherwise.
47
+
48
+ Without this the axis names and every tick number highlight as the reader turns the box, and
49
+ the selection survives the gesture. `user-select: none` on the group covers the text inside
50
+ it; this covers the drag that carries on past the group's edge.
51
+ */
52
+ event.preventDefault();
53
+ event.currentTarget.setPointerCapture?.(event.pointerId);
54
+ from.current = { x: event.clientX, y: event.clientY };
55
+ origin.current = { x: event.clientX, y: event.clientY };
56
+ moved.current = false;
57
+ setTurning(true);
58
+ }, []);
59
+ const onPointerMove = useCallback((event) => {
60
+ const start = from.current;
61
+ if (!start)
62
+ return;
63
+ const dx = event.clientX - start.x;
64
+ const dy = event.clientY - start.y;
65
+ const travel = Math.hypot(event.clientX - origin.current.x, event.clientY - origin.current.y);
66
+ if (travel >= TURN_FLOOR)
67
+ moved.current = true;
68
+ from.current = { x: event.clientX, y: event.clientY };
69
+ setOrbit((held) => orbited(held, dx, dy));
70
+ }, []);
71
+ const onPointerUp = useCallback((event) => {
72
+ if (event.currentTarget.hasPointerCapture?.(event.pointerId)) {
73
+ event.currentTarget.releasePointerCapture(event.pointerId);
74
+ }
75
+ from.current = null;
76
+ setTurning(false);
77
+ }, []);
78
+ const turned = useCallback(() => moved.current, []);
79
+ const reset = useCallback(() => setOrbit(initial), [initial]);
80
+ return { orbit, ref, onPointerDown, onPointerMove, onPointerUp, turning, turned, reset };
81
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The tree behind a band's cluster order, drawn in the side panel beside it.
3
+ *
4
+ * Chrome and not a geom. It encodes nothing the geoms do not already carry: the permutation is on
5
+ * the axis and this is the picture explaining it, which is why it takes the tree the build produced
6
+ * instead of clustering anything itself. A second clustering here would pay the quadratic term twice
7
+ * for an answer that could disagree with the rows it sits beside.
8
+ *
9
+ * Depth runs away from the geoms, so the leaves touch the categories they name and the root sits on
10
+ * the far edge. That direction is what the four edges differ in, and it is the whole of what this
11
+ * knows about where it was put: the shared span and the origin come off `sideLayout`, which hands the
12
+ * panel the plot area's own extent.
13
+ *
14
+ * See the ADRs "A figure takes side panels that share one axis" and "A band carries an order and
15
+ * clustering is one source of it".
16
+ */
17
+ import { type ClusterTree, type DepthScale, type SidePanel } from "../../core/internal.js";
18
+ export interface DendrogramPanelProps {
19
+ /** The tree and the labels its leaves point at, off `ReadyFrame.clusterTrees`. */
20
+ tree: ClusterTree;
21
+ /** Where a category sits along the shared axis. The band scale answers with its center. */
22
+ at: (label: string) => number;
23
+ position: SidePanel["position"];
24
+ width: number;
25
+ height: number;
26
+ /** How a merge's height becomes the depth it draws at. R's own plot is `height`. */
27
+ depth?: DepthScale;
28
+ stroke?: string;
29
+ /** Width of the tree's strokes, in pixels. */
30
+ lineWidth?: number;
31
+ }
32
+ export declare function DendrogramPanel({ tree, at, position, width, height, depth, stroke, lineWidth, }: DendrogramPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * The tree behind a band's cluster order, drawn in the side panel beside it.
4
+ *
5
+ * Chrome and not a geom. It encodes nothing the geoms do not already carry: the permutation is on
6
+ * the axis and this is the picture explaining it, which is why it takes the tree the build produced
7
+ * instead of clustering anything itself. A second clustering here would pay the quadratic term twice
8
+ * for an answer that could disagree with the rows it sits beside.
9
+ *
10
+ * Depth runs away from the geoms, so the leaves touch the categories they name and the root sits on
11
+ * the far edge. That direction is what the four edges differ in, and it is the whole of what this
12
+ * knows about where it was put: the shared span and the origin come off `sideLayout`, which hands the
13
+ * panel the plot area's own extent.
14
+ *
15
+ * See the ADRs "A figure takes side panels that share one axis" and "A band carries an order and
16
+ * clustering is one source of it".
17
+ */
18
+ import { dendrogramBrackets } from "../../core/internal.js";
19
+ export function DendrogramPanel({ tree, at, position, width, height, depth = "height", stroke = "var(--viz-ink-muted)", lineWidth = 1, }) {
20
+ const brackets = dendrogramBrackets(tree.tree, tree.labels.map((label) => at(label)), depth);
21
+ if (brackets.length === 0)
22
+ return null;
23
+ const across = position === "top" || position === "bottom";
24
+ const span = across ? height : width;
25
+ /* Nought is the edge nearest the geoms, which is the far side of the box on a top or left panel. */
26
+ const away = (depth) => (position === "top" || position === "left" ? span - depth * span : depth * span);
27
+ const point = (along, depth) => (across ? `${along},${away(depth)}` : `${away(depth)},${along}`);
28
+ /*
29
+ One path over every merge, since a grid at the cluster cap is 255 of them.
30
+
31
+ Each is the bracket the merge draws: up from the first child's own depth, across at the merge's,
32
+ and back down to the second child. A leaf's depth is nought, so its segment reaches the category.
33
+ */
34
+ const drawn = brackets
35
+ .map((bracket) => `M${point(bracket.from[0], bracket.base[0])}L${point(bracket.from[0], bracket.depth)}` +
36
+ `L${point(bracket.from[1], bracket.depth)}L${point(bracket.from[1], bracket.base[1])}`)
37
+ .join("");
38
+ return _jsx("path", { d: drawn, fill: "none", stroke: stroke, strokeWidth: lineWidth, "data-dendrogram": position });
39
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * A marginal density, drawn against the scale the geoms are drawn against.
3
+ *
4
+ * The curve form of `HistogramPanel`, and the reason both exist: three overlapping distributions
5
+ * read as three curves and as one muddle of bars. A histogram states where the mass is at the
6
+ * resolution of its bins; a density states the shape, which is what a reader compares between
7
+ * groups.
8
+ *
9
+ * The density carries no axis, for the reason the histogram carries none: a marginal is read as
10
+ * shape, and an axis on one is a second scale for a number nobody is asked to take off the figure.
11
+ * Each curve is scaled so its own peak fills the panel, which is what makes two groups of
12
+ * different size comparable in shape instead of in count.
13
+ *
14
+ * Filled and stroked. The fill is what lets a reader see the overlap and the stroke is what keeps
15
+ * three of them separable inside it, which is the same argument `Area` makes about a wash with no
16
+ * boundary.
17
+ *
18
+ * See the ADR "A figure takes side panels that share one axis", and decision 8 for the binning the
19
+ * histogram inherited.
20
+ */
21
+ import type { Marginal, Scale, SidePanel } from "../../core/internal.js";
22
+ export declare function DensityPanel({ marginal, along, position, width, height, fillOpacity, lineWidth, }: {
23
+ marginal: Marginal;
24
+ /** The geoms' own scale for the shared axis, in the measure's units. */
25
+ along: Scale;
26
+ position: SidePanel["position"];
27
+ width: number;
28
+ height: number;
29
+ fillOpacity?: number;
30
+ lineWidth?: number;
31
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /** How much of a curve's own peak the panel gives it, leaving the outline room to sit inside. */
3
+ const FILL = 0.92;
4
+ export function DensityPanel({ marginal, along, position, width, height, fillOpacity = 0.45, lineWidth = 1, }) {
5
+ const curves = marginal.curves ?? [];
6
+ if (curves.length === 0)
7
+ return null;
8
+ const across = position === "top" || position === "bottom";
9
+ const span = across ? height : width;
10
+ /*
11
+ Which way the curve grows.
12
+
13
+ A top panel and a left one grow away from the geoms, which is toward their own outer edge; a
14
+ bottom and a right grow toward it. So the baseline sits where the panel meets the plot area and
15
+ the peak reaches the far side, and a marginal always opens away from the cloud it describes.
16
+ */
17
+ const grows = position === "top" || position === "left" ? -1 : 1;
18
+ const base = position === "top" || position === "left" ? span : 0;
19
+ return (_jsx("g", { children: curves.map((curve) => {
20
+ let path = "";
21
+ for (let i = 0; i < curve.grid.length; i += 1) {
22
+ const at = along(curve.grid[i]);
23
+ const out = base + grows * curve.weight[i] * span * FILL;
24
+ const [x, y] = across ? [at, out] : [out, at];
25
+ path += `${path ? "L" : "M"}${x.toFixed(2)},${y.toFixed(2)}`;
26
+ }
27
+ if (!path)
28
+ return null;
29
+ /* Closed along the baseline, so the fill is the area under the curve and not a smear. */
30
+ const first = along(curve.grid[0]);
31
+ const last = along(curve.grid[curve.grid.length - 1]);
32
+ const [closeA, closeB] = across
33
+ ? [`L${last.toFixed(2)},${base}`, `L${first.toFixed(2)},${base}`]
34
+ : [`L${base},${last.toFixed(2)}`, `L${base},${first.toFixed(2)}`];
35
+ return (_jsxs("g", { children: [_jsx("path", { d: `${path}${closeA}${closeB}Z`, fill: curve.color, fillOpacity: fillOpacity, stroke: "none" }), _jsx("path", { d: path, fill: "none", stroke: curve.color, strokeWidth: lineWidth, strokeLinejoin: "round" })] }, curve.label || "pooled"));
36
+ }) }));
37
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A marginal histogram, drawn against the scale the geoms are drawn against.
3
+ *
4
+ * The point of the primitive: two frames over one domain at different extents. A bar sits between the
5
+ * pixels its interval's ends map to, so a peak in the margin is above the part of the cloud that made
6
+ * it and a reader lines the two up by eye instead of by reading numbers off both.
7
+ *
8
+ * The counts have no axis of their own. Marginals are read as shape, and an axis on one is a second
9
+ * scale for a number the reader is not asked to take off the figure; the tallest bar filling the
10
+ * panel is what says the counts were scaled. What the reader gets from it is where the mass is.
11
+ *
12
+ * An interval reaching past the axis is cut off where the axis ends, since the scale clamps and the
13
+ * strip covers the plot area and nothing beyond it. The count is the height, so what a clipped bar
14
+ * loses is width, and the reader still reads its count against the rest.
15
+ *
16
+ * See the ADR "A figure takes side panels that share one axis", decision 8.
17
+ */
18
+ import type { Marginal, Scale, SidePanel } from "../../core/internal.js";
19
+ export interface HistogramPanelProps {
20
+ marginal: Marginal;
21
+ /** The geoms' own scale for the shared axis, in the measure's units. */
22
+ along: Scale;
23
+ position: SidePanel["position"];
24
+ width: number;
25
+ height: number;
26
+ fill?: string;
27
+ /** Pixels taken off a bar so a run of them reads as bars and not as a block. */
28
+ gap?: number;
29
+ }
30
+ export declare function HistogramPanel({ marginal, along, position, width, height, fill, gap, }: HistogramPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function HistogramPanel({ marginal, along, position, width, height, fill = "var(--viz-ink-muted)", gap = 1, }) {
3
+ const bins = marginal.bins ?? [];
4
+ const most = marginal.most ?? 0;
5
+ if (bins.length === 0 || most <= 0)
6
+ return null;
7
+ const across = position === "top" || position === "bottom";
8
+ const span = across ? height : width;
9
+ /* Nought is the edge nearest the geoms, so a bar grows away from the cloud it counts. */
10
+ const from = position === "top" || position === "left" ? (reach) => span - reach : () => 0;
11
+ return (_jsx("g", { "data-histogram": marginal.axis, children: bins.map((bin) => {
12
+ const ends = [along(bin.from), along(bin.to)].sort((a, b) => a - b);
13
+ const thick = Math.max(1, ends[1] - ends[0] - gap);
14
+ const reach = Math.max(1, (bin.count / most) * span);
15
+ const start = from(reach);
16
+ return (_jsx("rect", { x: across ? ends[0] + gap / 2 : start, y: across ? start : ends[0] + gap / 2, width: across ? thick : reach, height: across ? reach : thick, fill: fill, fillOpacity: 0.75 }, bin.from));
17
+ }) }));
18
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A rug: one tick per reading along the axis it shares with the geoms.
3
+ *
4
+ * What it adds over the histogram is the tail. A bin holding one reading and a bin holding none draw
5
+ * nearly alike at any panel height worth using, and the lone reading three deviations out is the one
6
+ * a scientist is looking for. A rug draws it at full strength.
7
+ *
8
+ * Deduplicated by pixel, which is what keeps a quarter of a million readings drawable: two ticks at
9
+ * one pixel are one geom of ink, so the path holds at most one segment per pixel of the shared axis
10
+ * however many rows there are. No reading is lost by it, since a value far from the rest has a pixel
11
+ * to itself, which is the opposite of what sampling would do.
12
+ *
13
+ * See the ADR "A figure takes side panels that share one axis", decision 8.
14
+ */
15
+ import type { Marginal, Scale, SidePanel } from "../../core/internal.js";
16
+ export interface RugPanelProps {
17
+ marginal: Marginal;
18
+ /** The geoms' own scale for the shared axis, in the measure's units. */
19
+ along: Scale;
20
+ position: SidePanel["position"];
21
+ width: number;
22
+ height: number;
23
+ stroke?: string;
24
+ lineWidth?: number;
25
+ /** How far across the panel a tick runs, as a fraction of it. */
26
+ reach?: number;
27
+ }
28
+ export declare function RugPanel({ marginal, along, position, width, height, stroke, lineWidth, reach, }: RugPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function RugPanel({ marginal, along, position, width, height, stroke = "var(--viz-ink-muted)", lineWidth = 1, reach = 0.7, }) {
3
+ const across = position === "top" || position === "bottom";
4
+ const span = across ? height : width;
5
+ const depth = Math.max(1, span * Math.min(1, Math.max(0, reach)));
6
+ const at = new Set();
7
+ for (const value of marginal.values) {
8
+ const pixel = Math.round(along(value));
9
+ if (Number.isFinite(pixel))
10
+ at.add(pixel);
11
+ }
12
+ if (at.size === 0)
13
+ return null;
14
+ /* Ticks start on the edge nearest the geoms and run away from them. */
15
+ const near = position === "top" || position === "left" ? span : 0;
16
+ const far = position === "top" || position === "left" ? span - depth : depth;
17
+ const drawn = [...at]
18
+ .map((pixel) => (across ? `M${pixel},${near}L${pixel},${far}` : `M${near},${pixel}L${far},${pixel}`))
19
+ .join("");
20
+ return (_jsx("path", { d: drawn, fill: "none", stroke: stroke, strokeOpacity: 0.6, strokeWidth: lineWidth, "data-rug": marginal.axis }));
21
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * An annotation track drawn as a strip of cells beside the band it annotates.
3
+ *
4
+ * The same shape a grid's row is, and for the same reason: one cell per category, filling the band
5
+ * the category holds, so the strip and the grid line up cell for cell and a reader traces across.
6
+ * The extent perpendicular to that is the panel's, which is one cell's worth in pheatmap and
7
+ * whatever the author asked for here.
8
+ *
9
+ * A category with no reading leaves a gap instead of a cell. Absent and lowest are different facts,
10
+ * which is the argument the grid's own gaps make: a strip that fills them says a lot was annotated
11
+ * when nobody annotated it.
12
+ *
13
+ * See the ADR "A figure takes side panels that share one axis", decisions 5 to 7.
14
+ */
15
+ import type { SideTrack, SidePanel } from "../../core/internal.js";
16
+ export interface TrackPanelProps {
17
+ track: SideTrack;
18
+ /** Where a category sits along the shared axis. The band scale answers with its center. */
19
+ at: (category: string) => number;
20
+ /** The category's extent along the shared axis, which is the band scale's own bandwidth. */
21
+ band: number;
22
+ position: SidePanel["position"];
23
+ width: number;
24
+ height: number;
25
+ /** The category's color, or null where it carries no reading. */
26
+ fill: (category: string) => string | null;
27
+ /**
28
+ * Ink on the cell edge, which is the grid's own. Absent draws none, as the grid's cells do.
29
+ *
30
+ * pheatmap's `border_color` draws the annotation strip and the matrix alike, and the arithmetic
31
+ * here is the grid's: an edge lands inside the band instead of on its boundary, so a strip cell
32
+ * is the same size as the cell beside it instead of a hairline taller.
33
+ */
34
+ stroke?: string;
35
+ lineWidth?: number;
36
+ }
37
+ export declare function TrackPanel({ track, at, band, position, width, height, fill, stroke, lineWidth }: TrackPanelProps): import("react").JSX.Element | null;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function TrackPanel({ track, at, band, position, width, height, fill, stroke, lineWidth = 1.5 }) {
3
+ const across = position === "top" || position === "bottom";
4
+ const reach = Math.max(1, band);
5
+ const hairline = stroke ? lineWidth : 0;
6
+ const inset = hairline / 2;
7
+ const thick = Math.max(1, reach - hairline);
8
+ const cells = [...track.at.keys()].flatMap((category) => {
9
+ const color = fill(category);
10
+ if (color == null)
11
+ return [];
12
+ const along = at(category) - reach / 2 + inset;
13
+ return [
14
+ {
15
+ category,
16
+ color,
17
+ x: across ? along : inset,
18
+ y: across ? inset : along,
19
+ w: across ? thick : Math.max(1, width - hairline),
20
+ h: across ? Math.max(1, height - hairline) : thick,
21
+ },
22
+ ];
23
+ });
24
+ if (cells.length === 0)
25
+ return null;
26
+ return (_jsx("g", { "data-track": track.field, children: cells.map((cell) => (_jsx("rect", { x: cell.x, y: cell.y, width: cell.w, height: cell.h, fill: cell.color, stroke: stroke, strokeWidth: hairline }, cell.category))) }));
27
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Reading the live token values, and noticing when they change.
3
+ *
4
+ * The SVG geoms need none of this: a `var(--viz-ink)` in a `stroke` attribute is resolved by the
5
+ * browser, and a theme flip repaints without React hearing about it. The GPU path is the caller:
6
+ * a shader takes three floats, so the set has to be resolved to numbers once at mount and again
7
+ * whenever the theme changes, and the color buffers repacked from the result.
8
+ *
9
+ * Two things make a snapshot trustworthy. A custom property resolves to whatever the author wrote,
10
+ * so a theme declared in `oklch()` arrives in that syntax and the package's parser cannot read it;
11
+ * the probe below hands the value to the browser as a `color` and reads back the computed form,
12
+ * which is normalized to `rgb()`. And a flip is two separate signals: a class on the root element
13
+ * for a host with a theme switch, and `prefers-color-scheme` for a host without one. Watching only
14
+ * the class left a chart painted for the wrong theme on a machine that flipped at sunset.
15
+ *
16
+ * See the ADR "The theme tokens belong to the package".
17
+ */
18
+ import { type ThemeSnapshot } from "../core/internal.js";
19
+ /**
20
+ * The token set as declared where this element sits.
21
+ *
22
+ * A token the host has not declared falls back to the shipped light value, so a chart mounted with
23
+ * no theme installed draws in neutral grays instead of picking up whatever the browser defaults a
24
+ * missing custom property to.
25
+ */
26
+ export declare function resolveTheme(element: Element): ThemeSnapshot;
27
+ /**
28
+ * Calls back with a fresh snapshot each time the resolved values change.
29
+ *
30
+ * Watches the root element's `class` and `style` attributes, which is where a host's theme switch
31
+ * writes, and the `prefers-color-scheme` query for a host that leaves it to the system. Returns the
32
+ * teardown.
33
+ *
34
+ * The callback fires on a real change and not on the signal. A class toggle that moves no token is
35
+ * common on a page with one theme, and repacking color buffers for it would put a stall in a
36
+ * scroll.
37
+ */
38
+ export declare function watchTheme(element: Element, onChange: (snapshot: ThemeSnapshot) => void): () => void;
39
+ /**
40
+ * The token set where a component sits, kept current across theme flips.
41
+ *
42
+ * A client render starts from the page root's set, so a chart on a dark page builds once. The server
43
+ * and a hydrating pass start at null, the one signal for "nothing to read yet", and the element's own
44
+ * set replaces the seed once the ref attaches.
45
+ */
46
+ export declare function useVizTheme(ref: {
47
+ current: Element | null;
48
+ }): ThemeSnapshot | null;
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Reading the live token values, and noticing when they change.
3
+ *
4
+ * The SVG geoms need none of this: a `var(--viz-ink)` in a `stroke` attribute is resolved by the
5
+ * browser, and a theme flip repaints without React hearing about it. The GPU path is the caller:
6
+ * a shader takes three floats, so the set has to be resolved to numbers once at mount and again
7
+ * whenever the theme changes, and the color buffers repacked from the result.
8
+ *
9
+ * Two things make a snapshot trustworthy. A custom property resolves to whatever the author wrote,
10
+ * so a theme declared in `oklch()` arrives in that syntax and the package's parser cannot read it;
11
+ * the probe below hands the value to the browser as a `color` and reads back the computed form,
12
+ * which is normalized to `rgb()`. And a flip is two separate signals: a class on the root element
13
+ * for a host with a theme switch, and `prefers-color-scheme` for a host without one. Watching only
14
+ * the class left a chart painted for the wrong theme on a machine that flipped at sunset.
15
+ *
16
+ * See the ADR "The theme tokens belong to the package".
17
+ */
18
+ import { useEffect, useRef, useState, useSyncExternalStore } from "react";
19
+ import { LIGHT_THEME, VIZ_TOKENS, rgbOf } from "../core/internal.js";
20
+ /** One pixel of a color, read back as `rgb()`. Null where the document draws no 2D canvas. */
21
+ function painted(color, doc) {
22
+ const canvas = doc.createElement("canvas");
23
+ canvas.width = 1;
24
+ canvas.height = 1;
25
+ const context = canvas.getContext("2d", { willReadFrequently: true });
26
+ if (!context)
27
+ return null;
28
+ context.fillStyle = color;
29
+ context.fillRect(0, 0, 1, 1);
30
+ const [r, g, b] = context.getImageData(0, 0, 1, 1).data;
31
+ return `rgb(${r}, ${g}, ${b})`;
32
+ }
33
+ /**
34
+ * A color in the form the parser reads.
35
+ *
36
+ * Computed off a detached element. An `oklch()`, `lab()` or `color()` is painted to one pixel. A
37
+ * rejected value returns as written.
38
+ */
39
+ function normalize(value, probe) {
40
+ if (!value)
41
+ return value;
42
+ probe.style.color = "";
43
+ probe.style.color = value;
44
+ if (!probe.style.color)
45
+ return value;
46
+ const computed = getComputedStyle(probe).color || value;
47
+ return rgbOf(computed) ? computed : (painted(computed, probe.ownerDocument) ?? computed);
48
+ }
49
+ /**
50
+ * The token set as declared where this element sits.
51
+ *
52
+ * A token the host has not declared falls back to the shipped light value, so a chart mounted with
53
+ * no theme installed draws in neutral grays instead of picking up whatever the browser defaults a
54
+ * missing custom property to.
55
+ */
56
+ export function resolveTheme(element) {
57
+ const style = getComputedStyle(element);
58
+ const doc = element.ownerDocument;
59
+ const probe = doc.createElement("span");
60
+ probe.style.display = "none";
61
+ doc.body?.appendChild(probe);
62
+ try {
63
+ const out = {};
64
+ for (const token of VIZ_TOKENS) {
65
+ const declared = style.getPropertyValue(token).trim();
66
+ out[token] = declared ? normalize(declared, probe) : LIGHT_THEME[token];
67
+ }
68
+ return out;
69
+ }
70
+ finally {
71
+ probe.remove();
72
+ }
73
+ }
74
+ const sameSnapshot = (a, b) => VIZ_TOKENS.every((token) => a[token] === b[token]);
75
+ /**
76
+ * Calls back with a fresh snapshot each time the resolved values change.
77
+ *
78
+ * Watches the root element's `class` and `style` attributes, which is where a host's theme switch
79
+ * writes, and the `prefers-color-scheme` query for a host that leaves it to the system. Returns the
80
+ * teardown.
81
+ *
82
+ * The callback fires on a real change and not on the signal. A class toggle that moves no token is
83
+ * common on a page with one theme, and repacking color buffers for it would put a stall in a
84
+ * scroll.
85
+ */
86
+ export function watchTheme(element, onChange) {
87
+ const doc = element.ownerDocument;
88
+ const view = doc.defaultView;
89
+ let held = resolveTheme(element);
90
+ const check = () => {
91
+ const next = resolveTheme(element);
92
+ if (sameSnapshot(held, next))
93
+ return;
94
+ held = next;
95
+ onChange(next);
96
+ };
97
+ const observer = new MutationObserver(check);
98
+ observer.observe(doc.documentElement, { attributes: true, attributeFilter: ["class", "style"] });
99
+ if (element !== doc.documentElement) {
100
+ observer.observe(element, { attributes: true, attributeFilter: ["class", "style"] });
101
+ }
102
+ const query = view?.matchMedia?.("(prefers-color-scheme: dark)");
103
+ query?.addEventListener?.("change", check);
104
+ return () => {
105
+ observer.disconnect();
106
+ query?.removeEventListener?.("change", check);
107
+ };
108
+ }
109
+ /** The page root's set, held while the root's class and style and the color scheme hold. */
110
+ let pageKey = null;
111
+ let pageHeld = null;
112
+ function pageTheme() {
113
+ const root = document.documentElement;
114
+ const scheme = root.ownerDocument.defaultView?.matchMedia?.("(prefers-color-scheme: dark)").matches;
115
+ const key = `${root.className}|${root.getAttribute("style") ?? ""}|${scheme}`;
116
+ if (key !== pageKey || !pageHeld) {
117
+ pageKey = key;
118
+ pageHeld = resolveTheme(root);
119
+ }
120
+ return pageHeld;
121
+ }
122
+ /* The element's own watcher carries a flip after mount, so the seed subscribes to nothing. */
123
+ const unwatched = () => () => undefined;
124
+ const noTheme = () => null;
125
+ /**
126
+ * The token set where a component sits, kept current across theme flips.
127
+ *
128
+ * A client render starts from the page root's set, so a chart on a dark page builds once. The server
129
+ * and a hydrating pass start at null, the one signal for "nothing to read yet", and the element's own
130
+ * set replaces the seed once the ref attaches.
131
+ */
132
+ export function useVizTheme(ref) {
133
+ const seed = useSyncExternalStore(unwatched, pageTheme, noTheme);
134
+ const seeded = useRef(seed);
135
+ seeded.current = seed;
136
+ const [snapshot, setSnapshot] = useState(null);
137
+ useEffect(() => {
138
+ const element = ref.current;
139
+ if (!element)
140
+ return;
141
+ /* The seed's identity survives where the element reads the same set, so nothing keyed on it reruns. */
142
+ const next = resolveTheme(element);
143
+ const held = seeded.current;
144
+ setSnapshot(held && sameSnapshot(held, next) ? held : next);
145
+ return watchTheme(element, setSnapshot);
146
+ }, [ref]);
147
+ return snapshot ?? seed;
148
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The fitter, held against a chart's lifetime.
3
+ *
4
+ * A curve arrives long after the geoms do, so this is the one place that knows a chart can be
5
+ * drawn and correct while its fits are still in flight. What it turns a `Fitter` into is the
6
+ * `FitState` the frame derivation already reads, which is why nothing downstream has to learn that
7
+ * the answer came over a wire.
8
+ *
9
+ * Refits on `fitSignature` and on nothing else. A chart re-renders on a hover, a theme flip, a
10
+ * recolor and a resize, and a curve survives all of them; keying the effect on the signature is
11
+ * what keeps a pointer moving across a scatter from putting a solver under load.
12
+ *
13
+ * The fitter is read through a ref, so one written inline asks nothing new. A host swapping services
14
+ * under an unchanged signature changes the chart's `key`.
15
+ */
16
+ import { type FitRequest, type Fitter } from "../core/internal.js";
17
+ import type { FitState } from "../core/internal.js";
18
+ /**
19
+ * Fits for the requests a frame produced.
20
+ *
21
+ * Idle where the consumer passed no fitter, which is the ordinary case: a chart with no `fit` on
22
+ * any series asks for nothing, and a chart that asks stays drawn and uncurved until a fitter
23
+ * reaches it. A response that lands after its question was replaced is dropped, so a slow answer to
24
+ * an old signature cannot overwrite a fast answer to the current one.
25
+ */
26
+ export declare function useFits(requests: FitRequest[], fitter?: Fitter): FitState;