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

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 +28 -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,90 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * One reading against a stated range, as an arc with the number under it.
4
+ *
5
+ * The track states where the ends are. A scale ring outside it sections the range.
6
+ */
7
+ import { dialLayout, gaugeAngle, polarPoint, GAUGE_SWEEP } from "../../core/internal.js";
8
+ /** How much larger the reading draws than the panel's axis type. */
9
+ const NUMBER_SCALE = 2.6;
10
+ /** Weight of an arc where the author states none, in pixels. */
11
+ const WEIGHT = 18;
12
+ /** Gap between the dial and the scale ring outside it, in pixels. */
13
+ const SCALE_GAP = 6;
14
+ /** Weight of the scale ring, in pixels. */
15
+ const RING_WEIGHT = 7;
16
+ /** Gap between one section of the scale ring and the next, in radians. */
17
+ const SECTION_GAP = 0.02;
18
+ /** A whole turn, in radians, less the rounding a sum of angles leaves. */
19
+ const FULL_TURN = Math.PI * 2 - 1e-9;
20
+ /**
21
+ * The two range ends as text, in panel pixels.
22
+ *
23
+ * A wrapped dial writes them outside the ring. A half dial writes them a line under the round cap.
24
+ */
25
+ function rangeEnds(layout, range, sweep, room, numbers) {
26
+ const type = numbers?.fontSize ?? 11;
27
+ const wrapped = sweep.turn > Math.PI;
28
+ const closed = sweep.turn >= FULL_TURN;
29
+ return range.map((end, side) => {
30
+ const angle = side === 0 ? sweep.start : sweep.start + sweep.turn;
31
+ const text = numbers ? numbers.format(end) : String(end);
32
+ if (wrapped) {
33
+ const on = polarPoint(layout, layout.outer + room.ring + type * 1.6, angle);
34
+ /* A closed ring puts both ends at its seam. The low end writes left of it and the high end right. */
35
+ if (closed)
36
+ return {
37
+ text,
38
+ x: on.x + (side === 0 ? -type : type) / 2,
39
+ y: on.y + type * 0.35,
40
+ anchor: side === 0 ? "end" : "start",
41
+ };
42
+ return { text, x: on.x, y: on.y + type * 0.35 };
43
+ }
44
+ const under = polarPoint(layout, (layout.inner + layout.outer + room.ring) / 2, angle);
45
+ return { text, x: under.x, y: layout.cy + room.weight / 2 + type * 1.5 };
46
+ });
47
+ }
48
+ /** The reading's ink. Over a scale ring it takes the hue of the section it lands in. */
49
+ function readingHue(fraction, color, bands, ramp) {
50
+ if (!bands || !ramp)
51
+ return color;
52
+ const landed = Math.min(bands - 1, Math.floor(fraction * bands));
53
+ return ramp((landed + 0.5) / bands);
54
+ }
55
+ /*
56
+ A dial carrying no number is a stat tile with decoration, and the critic reports it.
57
+
58
+ See the ADR "Polar is permitted where the figure writes its numbers".
59
+ */
60
+ export function Gauge({ value, range, width, height, color, trackColor, thickness = WEIGHT, opacity, sweep, radius, bands, ramp, numbers, label, }) {
61
+ const turn = sweep == null ? GAUGE_SWEEP : (Math.min(sweep, 360) * Math.PI) / 180;
62
+ const ringRoom = bands ? SCALE_GAP + RING_WEIGHT : 0;
63
+ const layout = dialLayout(width, height, thickness, turn, radius ?? 1);
64
+ if (layout.outer <= 0)
65
+ return null;
66
+ const start = -turn / 2;
67
+ const at = gaugeAngle(value, range, turn);
68
+ const ringRadius = layout.outer + ringRoom - RING_WEIGHT / 2;
69
+ const wrapped = turn > Math.PI;
70
+ /** One arc along a single radius, which takes a round cap at each end. A full turn draws as two halves. */
71
+ const arc = (reach, from, to) => {
72
+ const head = polarPoint(layout, reach, from);
73
+ const tail = polarPoint(layout, reach, to);
74
+ if (to - from >= FULL_TURN) {
75
+ const half = polarPoint(layout, reach, from + Math.PI);
76
+ return `M ${head.x} ${head.y} A ${reach} ${reach} 0 1 1 ${half.x} ${half.y} A ${reach} ${reach} 0 1 1 ${head.x} ${head.y}`;
77
+ }
78
+ return `M ${head.x} ${head.y} A ${reach} ${reach} 0 ${to - from > Math.PI ? 1 : 0} 1 ${tail.x} ${tail.y}`;
79
+ };
80
+ const ends = rangeEnds(layout, range, { start, turn }, { ring: ringRoom, weight: thickness }, numbers);
81
+ const cuts = bands ?? 1;
82
+ const reading = readingHue((at - start) / turn, color, bands, ramp);
83
+ const sections = Array.from({ length: bands ?? 0 }, (_, index) => ({
84
+ key: index,
85
+ path: arc(ringRadius, start + (index / cuts) * turn + SECTION_GAP, start + ((index + 1) / cuts) * turn - SECTION_GAP),
86
+ hue: ramp?.((index + 0.5) / cuts) ?? color,
87
+ }));
88
+ const numberY = wrapped ? layout.cy : layout.cy - layout.outer * 0.3;
89
+ return (_jsxs(_Fragment, { children: [_jsxs("g", { "data-geom": "gauge", fill: "none", strokeLinecap: "round", children: [_jsx("path", { d: arc(layout.labelRadius, start, start + turn), stroke: trackColor ?? "currentColor", strokeOpacity: 0.12, strokeWidth: thickness }), at > start && (_jsx("path", { d: arc(layout.labelRadius, start, at), stroke: reading, strokeOpacity: opacity, strokeWidth: thickness }))] }), sections.length > 0 && (_jsx("g", { "data-geom": "gauge-scale", fill: "none", strokeWidth: RING_WEIGHT, children: sections.map((section) => (_jsx("path", { d: section.path, stroke: section.hue }, section.key))) })), _jsxs("g", { pointerEvents: "none", textAnchor: "middle", fontSize: numbers?.fontSize, children: [ends.map((end, side) => (_jsx("text", { x: end.x, y: end.y, textAnchor: end.anchor, fill: numbers?.color ?? "var(--viz-ink-muted)", children: end.text }, side === 0 ? "low" : "high"))), numbers && (numbers.wanted?.(value) ?? true) && (_jsx("text", { x: layout.cx, y: numberY, fill: numbers.color ?? "var(--viz-ink)", fontSize: numbers.fontSize * NUMBER_SCALE, dominantBaseline: "central", children: numbers.format(value) })), label && (_jsx("text", { x: layout.cx, y: numberY + (numbers?.fontSize ?? 11) * 2.2, fill: "var(--viz-ink-muted)", opacity: 0.7, children: label }))] })] }));
90
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * A reduction over two categories, drawn as a grid of colored cells.
3
+ *
4
+ * Color is the only channel carrying the value here, so it takes the sequential map instead of the
5
+ * categorical one, per chart-design rule 8. The two axes carry identity and the cell carries
6
+ * magnitude, which is the division that keeps the reading unambiguous.
7
+ *
8
+ * A pair with no rows behind it leaves a gap instead of a cell at the bottom of the ramp. Absent
9
+ * and lowest are different facts, and a chart that draws them alike says a plate was tested and came
10
+ * back worst when it was never tested.
11
+ *
12
+ * The ramp takes a value in its own units and the geom runs no scale of its own. It used to take the
13
+ * extent of the cells it happened to be handed, which put each panel of a facet on its own scale and
14
+ * left the domain inside a closure where no legend could read it. `Trace.colorDomain` carries it now.
15
+ */
16
+ import { type Scale, type ThemeSnapshot } from "../../core/internal.js";
17
+ import type { GeomHit, HeatCell, ValueRamp } from "../../core/internal.js";
18
+ export type { HeatCell };
19
+ export interface HeatmapProps {
20
+ data: HeatCell[];
21
+ x: Scale;
22
+ y: Scale;
23
+ xBand: number;
24
+ yBand: number;
25
+ /** Maps a cell's value, in the units it carries, to a color. A cell with its own color skips it. */
26
+ ramp: ValueRamp;
27
+ /**
28
+ * Ink on the cell edge. Absent draws none, which is what pheatmap's `border_color = NA` gives.
29
+ *
30
+ * A grid's cells are the surface, so they tile: absent an edge the fills meet and the reader sees
31
+ * one field of color instead of a lattice. An author who wants pheatmap's gray border names it
32
+ * here, and the cells give up the width it takes.
33
+ */
34
+ stroke?: string;
35
+ /** Width of that edge, in pixels. Read only where `stroke` names a color. */
36
+ lineWidth?: number;
37
+ /** Opacity of each cell, over the fade a thin support gives it. */
38
+ opacity?: number;
39
+ /**
40
+ * The value written inside each cell. Absent writes none, which is pheatmap's own default.
41
+ *
42
+ * `format` takes a value in the cell's units, so the numbers read the same way the legend and the
43
+ * hover readout do. `color` absent picks black or white per cell off the fill, since a fixed ink
44
+ * disappears at one end of every ramp. `wanted` absent writes every cell.
45
+ */
46
+ numbers?: {
47
+ format: (value: number) => string;
48
+ wanted?: (value: number) => boolean;
49
+ color?: string;
50
+ fontSize: number;
51
+ };
52
+ /**
53
+ * Corner radius on a cell, in pixels. Absent tiles them square.
54
+ *
55
+ * A radius reads the grid as a set of chips instead of a continuous field. Right where a reader
56
+ * compares cells one at a time and wrong where the grid stands for a surface.
57
+ */
58
+ cornerRadius?: number;
59
+ /** Space held back between one cell and the next, in pixels. */
60
+ cellGap?: number;
61
+ /**
62
+ * Fades a cell by how many rows stand behind it.
63
+ *
64
+ * A mean of one reading and a mean of four hundred draw the same color and carry different
65
+ * weight. The thinnest cell keeps `SUPPORT_FLOOR` of its color, so a lone reading stays visible.
66
+ */
67
+ fadeBySupport?: boolean;
68
+ /** Color behind the grid. A faded cell's number takes its ink off the blend. Absent reads the light paper. */
69
+ paper?: string;
70
+ /** Theme a token fill resolves against before a number picks its ink. Absent reads the light theme. */
71
+ theme?: ThemeSnapshot;
72
+ /** Cell drawn at full strength, named by its pair of groups. The rest mute to context. */
73
+ active?: Pick<HeatCell, "x" | "y"> | null;
74
+ /** The cell under the pointer, placed at its center. */
75
+ onHover?: (hit: GeomHit<HeatCell> | null) => void;
76
+ /** A cell clicked. The pair of groups it reduces is what a linked view filters on. */
77
+ onSelect?: (hit: GeomHit<HeatCell>) => void;
78
+ }
79
+ export declare function Heatmap({ data, x, y, xBand, yBand, ramp, stroke, lineWidth, opacity, numbers, cornerRadius, cellGap, fadeBySupport, paper, theme, active, onHover, onSelect, }: HeatmapProps): import("react").JSX.Element | null;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A reduction over two categories, drawn as a grid of colored cells.
4
+ *
5
+ * Color is the only channel carrying the value here, so it takes the sequential map instead of the
6
+ * categorical one, per chart-design rule 8. The two axes carry identity and the cell carries
7
+ * magnitude, which is the division that keeps the reading unambiguous.
8
+ *
9
+ * A pair with no rows behind it leaves a gap instead of a cell at the bottom of the ramp. Absent
10
+ * and lowest are different facts, and a chart that draws them alike says a plate was tested and came
11
+ * back worst when it was never tested.
12
+ *
13
+ * The ramp takes a value in its own units and the geom runs no scale of its own. It used to take the
14
+ * extent of the cells it happened to be handed, which put each panel of a facet on its own scale and
15
+ * left the domain inside a closure where no legend could read it. `Trace.colorDomain` carries it now.
16
+ */
17
+ import { boundsOf, inkOn, LIGHT_THEME, VIZ_TOKENS } from "../../core/internal.js";
18
+ /** Color the thinnest cell keeps where a grid fades by support. A lone reading stays visible. */
19
+ const SUPPORT_FLOOR = 0.35;
20
+ export function Heatmap({ data, x, y, xBand, yBand, ramp, stroke, lineWidth = 1, opacity = 1, numbers, cornerRadius, cellGap = 0, fadeBySupport, paper = LIGHT_THEME["--viz-paper"], theme = LIGHT_THEME, active, onHover, onSelect, }) {
21
+ if (data.length === 0)
22
+ return null;
23
+ /*
24
+ An edge, where one is asked for, is drawn inside the band instead of on its boundary.
25
+
26
+ The cells stay the size the band gave them and two neighbors keep their strokes apart. With no
27
+ edge and no gap the rect is the whole band and the fills meet, which is the default a grid
28
+ wants: the lattice a hairline draws is structure the data did not ask for. A gap holds ground
29
+ back on all four sides, which is what lets a corner radius be seen.
30
+ */
31
+ const strokeWidth = stroke ? lineWidth : 0;
32
+ const edge = strokeWidth + cellGap;
33
+ const inset = edge / 2;
34
+ const w = Math.max(1, xBand - edge);
35
+ const h = Math.max(1, yBand - edge);
36
+ const heaviest = fadeBySupport ? Math.max(boundsOf(data.map((cell) => cell.n))[1], 1) : 1;
37
+ const weight = (cell) => fadeBySupport ? SUPPORT_FLOOR + (1 - SUPPORT_FLOOR) * Math.sqrt(Math.min(cell.n, heaviest) / heaviest) : 1;
38
+ const hitOf = (cell, index) => ({ datum: cell, index, at: { x: x(cell.x), y: y(cell.y) } });
39
+ const fillOf = (cell) => cell.color ?? ramp(cell.value);
40
+ /* A cell's fill as a literal color. A theme token reads its value in the theme. */
41
+ const seenFill = (cell) => {
42
+ const fill = fillOf(cell);
43
+ const token = VIZ_TOKENS.find((one) => fill === `var(${one})`);
44
+ return token ? theme[token] : fill;
45
+ };
46
+ /* A threshold leaves the rest of the grid bare, which is what marking the cells past a cut means. */
47
+ const written = numbers?.wanted ? data.filter((cell) => numbers.wanted(cell.value)) : data;
48
+ return (_jsxs(_Fragment, { children: [_jsx("g", { "data-grid": "cells", children: data.map((cell, index) => (_jsx("rect", { x: x(cell.x) - xBand / 2 + inset, y: y(cell.y) - yBand / 2 + inset, width: w, height: h, rx: cornerRadius, ry: cornerRadius, fill: fillOf(cell), stroke: stroke, strokeWidth: strokeWidth, shapeRendering: stroke || cornerRadius ? undefined : "crispEdges", fillOpacity: (active && (active.x !== cell.x || active.y !== cell.y) ? 0.45 : 1) * weight(cell) * opacity, onMouseEnter: () => onHover?.(hitOf(cell, index)), onMouseLeave: () => onHover?.(null), onClick: onSelect ? () => onSelect(hitOf(cell, index)) : undefined, style: onSelect ? { cursor: "pointer" } : undefined }, `${cell.x}-${cell.y}`))) }), numbers && (
49
+ /* Past the cells and not among them, so no later fill covers a number already written. */
50
+ _jsx("g", { "data-grid": "numbers", fontSize: numbers.fontSize, pointerEvents: "none", children: written.map((cell) => (_jsx("text", { x: x(cell.x), y: y(cell.y), textAnchor: "middle", dominantBaseline: "central", fill: numbers.color ?? inkOn(seenFill(cell), fadeBySupport ? { paper, opacity: weight(cell) } : undefined), children: numbers.format(cell.value) }, `${cell.x}-${cell.y}`))) }))] }));
51
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Hexbin density, and the switch that decides when it takes over from points.
3
+ *
4
+ * One component holding the geom-switch rule, so a chart cannot silently misrepresent its own
5
+ * density: points below 1,500 records, translucent points to 15,000, hexbin above. The switch gets
6
+ * reported in the footer, because a reader who thinks they are looking at individual records will
7
+ * misjudge what they see.
8
+ *
9
+ * Below the switch this delegates to `Points`, which is where a geom carries the record it stands
10
+ * for. Drawing them here meant a scatter under the threshold lost identity the same data had above
11
+ * it, for no reason a reader could see.
12
+ */
13
+ import type { Bin2dOptions, GeomHit, PlotPoint, PointTreatment, UnitRamp } from "../../core/internal.js";
14
+ import type { Scale } from "../../core/internal.js";
15
+ import { type PointHit } from "./Points.js";
16
+ export interface HexbinProps {
17
+ points: PlotPoint[];
18
+ x: Scale;
19
+ y: Scale;
20
+ /** Overrides the count-derived choice, which is `treatmentOf` the point count. */
21
+ mode?: PointTreatment;
22
+ /**
23
+ * How the bins tile. Hexagons unless asked.
24
+ *
25
+ * A hexagon has six neighbors all the same distance away, so a cluster reads as a cluster. A
26
+ * square is what a reader cross-references against an axis: one x interval by one y interval,
27
+ * and a count that reads back to the pair of ranges behind it.
28
+ */
29
+ tiling?: "hex" | "rect";
30
+ radius?: number;
31
+ /**
32
+ * Cell size and alignment in the data's own units, which is `stat_bin_2d`'s parameter set.
33
+ *
34
+ * Resolved to a pixel lattice against the scales, so `bins: 20` draws twenty cells across the
35
+ * range whatever the panel is wide. Absent takes `radius`, which is what every figure drew before
36
+ * the parameters existed.
37
+ */
38
+ bin?: Bin2dOptions;
39
+ /** Maps 0..1 to a color. Comes from the palette context a layer up. */
40
+ ramp: UnitRamp;
41
+ /** Colors a bin by the mean of its weight channel instead of by its count. */
42
+ colorBy?: "count" | "mean";
43
+ /** One paint for each bin, where the author picked one over the ramp. */
44
+ fill?: string;
45
+ /** Outline paint on each bin, and its width. Absent draws none. */
46
+ stroke?: string;
47
+ lineWidth?: number;
48
+ opacity?: number;
49
+ /** A bin under the pointer: the records it counts and their mean weight, placed at its center. */
50
+ onHover?: (hit: GeomHit<{
51
+ count: number;
52
+ mean?: number;
53
+ }> | null) => void;
54
+ /**
55
+ * How many bins the density drew, for a caller that has to state the substitution.
56
+ *
57
+ * Rule 7 asks the switch to be reported, and the footer wants a cell count the caller cannot see
58
+ * from outside. Called after a render in hexbin mode, with the bin count of what is on screen.
59
+ */
60
+ onBins?: (cells: number) => void;
61
+ /**
62
+ * A record under the pointer, below the density switch.
63
+ *
64
+ * Held apart from `onHover`: a bin reports a population and a point reports a lot, and a caller
65
+ * that conflated them would print a count where a name belongs.
66
+ */
67
+ onPoint?: (hit: PointHit | null) => void;
68
+ /** A record taken below the density switch. Absent above it, where no single geom is under the pointer. */
69
+ onSelectPoint?: (hit: PointHit) => void;
70
+ /** Plot area, so the point branch can catch the pointer across the frame. */
71
+ width?: number;
72
+ height?: number;
73
+ }
74
+ export declare function Hexbin({ points, x, y, mode, tiling, radius, bin, ramp, colorBy, fill, stroke, lineWidth, opacity, onHover, onBins, onPoint, onSelectPoint, width, height, }: HexbinProps): import("react").JSX.Element;
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Hexbin density, and the switch that decides when it takes over from points.
4
+ *
5
+ * One component holding the geom-switch rule, so a chart cannot silently misrepresent its own
6
+ * density: points below 1,500 records, translucent points to 15,000, hexbin above. The switch gets
7
+ * reported in the footer, because a reader who thinks they are looking at individual records will
8
+ * misjudge what they see.
9
+ *
10
+ * Below the switch this delegates to `Points`, which is where a geom carries the record it stands
11
+ * for. Drawing them here meant a scatter under the threshold lost identity the same data had above
12
+ * it, for no reason a reader could see.
13
+ */
14
+ import { useEffect, useMemo } from "react";
15
+ import { boundsOf, hexbin, hexPath, hexRadiusFor, latticeFor, rectPath, rectbin, treatmentOf, } from "../../core/internal.js";
16
+ import { Points } from "./Points.js";
17
+ export function Hexbin({ points, x, y, mode, tiling = "hex", radius = 6, bin, ramp, colorBy = "count", fill, stroke, lineWidth = 1, opacity, onHover, onBins, onPoint, onSelectPoint, width, height, }) {
18
+ const chosen = mode ?? treatmentOf(points.length);
19
+ const projected = useMemo(() => points.map((p) => ({ x: x(p.x), y: y(p.y), weight: p.weight })), [points, x, y]);
20
+ /* Stated parameters resolve against the ranges of the data, which is the dimension ggplot reads. */
21
+ const lattice = useMemo(() => {
22
+ if (!bin || points.length === 0)
23
+ return null;
24
+ const xs = points.map((point) => point.x);
25
+ const ys = points.map((point) => point.y);
26
+ return latticeFor(boundsOf(xs), boundsOf(ys), { x, y }, bin);
27
+ }, [bin, points, x, y]);
28
+ const bins = useMemo(() => {
29
+ if (chosen !== "binned")
30
+ return [];
31
+ /* A square of the hexagon's own width, so the two tilings draw cells of about one area. */
32
+ if (!lattice)
33
+ return tiling === "rect" ? rectbin(projected, radius * 1.732) : hexbin(projected, radius);
34
+ return tiling === "rect" ? rectbin(projected, lattice) : hexbin(projected, hexRadiusFor(lattice), lattice.origin);
35
+ }, [chosen, lattice, projected, radius, tiling]);
36
+ useEffect(() => {
37
+ if (chosen === "binned")
38
+ onBins?.(bins.length);
39
+ }, [chosen, bins, onBins]);
40
+ const extent = useMemo(() => {
41
+ if (bins.length === 0)
42
+ return [0, 1];
43
+ const values = bins.map((b) => (colorBy === "mean" ? (b.mean ?? 0) : b.count));
44
+ return boundsOf(values);
45
+ }, [bins, colorBy]);
46
+ /*
47
+ The point branch reads its weights against the same window the bins do.
48
+
49
+ A weight arrives in its own units, a stability in degrees or a titer in mg/L, and the ramp takes
50
+ zero to one. The bin branch scales against the extent of the bins; the point branch handed the
51
+ ramp a raw measurement, which clamped every geom to the top of the scale and drew a bound color
52
+ channel as one flat color. Scaling here keeps both sides of the switch on one reading, and the
53
+ points keep their own units for whatever the readout prints.
54
+ */
55
+ const pointRamp = useMemo(() => {
56
+ if (chosen === "binned")
57
+ return ramp;
58
+ let lo = Infinity;
59
+ let hi = -Infinity;
60
+ for (const point of points) {
61
+ if (point.weight == null)
62
+ continue;
63
+ if (point.weight < lo)
64
+ lo = point.weight;
65
+ if (point.weight > hi)
66
+ hi = point.weight;
67
+ }
68
+ if (hi < lo)
69
+ return ramp;
70
+ /* One shared reading takes the middle of the span the points read. */
71
+ if (hi === lo)
72
+ return () => ramp(0.55);
73
+ return (weight) => ramp(0.15 + Math.min(1, Math.max(0, (weight - lo) / (hi - lo))) * 0.8);
74
+ }, [chosen, points, ramp]);
75
+ if (chosen !== "binned") {
76
+ return (_jsx(Points, { points: points, x: x, y: y, faded: chosen === "faded", ramp: pointRamp, width: width, height: height, onHover: onPoint, onSelect: onSelectPoint }));
77
+ }
78
+ const path = tiling === "rect"
79
+ ? rectPath(lattice?.width ?? radius * 1.732, lattice?.height)
80
+ : hexPath(lattice ? hexRadiusFor(lattice) : radius);
81
+ const span = extent[1] - extent[0] || 1;
82
+ return (_jsx("g", { children: bins.map((bin, index) => {
83
+ const value = colorBy === "mean" ? (bin.mean ?? 0) : bin.count;
84
+ // Square root, so a bin twice as dark holds roughly twice the records instead of
85
+ // four times: linear on count makes a long tail invisible.
86
+ const t = Math.sqrt((value - extent[0]) / span);
87
+ return (_jsx("path", { d: path, transform: `translate(${bin.cx},${bin.cy})`, fill: fill ?? ramp(0.15 + t * 0.8), fillOpacity: opacity, ...(stroke ? { stroke, strokeWidth: lineWidth } : {}), onMouseEnter: () => onHover?.({ datum: { count: bin.count, mean: bin.mean }, index, at: { x: bin.cx, y: bin.cy } }), onMouseLeave: () => onHover?.(null) }, bin.key));
88
+ }) }));
89
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The same hierarchy with a row per level. A cell's width stands for its value.
3
+ *
4
+ * One layout serves both arrangements. This arrangement trades the second dimension for a shared
5
+ * baseline: within a row the cells sit on one line and the reading is a length, which a reader takes
6
+ * off the page more accurately than an area. Down the rows the nesting reads, since a cell sits
7
+ * inside its parent's span.
8
+ *
9
+ * `packed` like the treemap, so the frame draws no axes and the geom takes the plot area whole. Hue
10
+ * carries the root a cell descends from, the same grouping the treemap paints, so a figure holding
11
+ * both reads as one thing.
12
+ *
13
+ * Labels go inside a cell where the name fits along its own row. A row is the same height whatever
14
+ * the level, so width alone decides the fit, which is what lets the top row carry names where the
15
+ * bottom one has slivers. No corner radius, since a level's cells sit on one baseline and a rounded
16
+ * end would read as a gap in it.
17
+ */
18
+ import type { HierarchyCell } from "../../core/internal.js";
19
+ export interface IcicleProps {
20
+ cells: HierarchyCell[];
21
+ width: number;
22
+ height: number;
23
+ /** Hue per group, taken off the categorical map. Read where no `fill` is stated. */
24
+ identity: (index: number) => string;
25
+ /** One hue for the whole figure, where the author picked one. */
26
+ fill?: string;
27
+ /** Groups the legend names, with the categorical index of each. */
28
+ levels?: readonly {
29
+ value: string;
30
+ code: number;
31
+ }[];
32
+ opacity?: number;
33
+ /** Paint on each cell's edge. Absent is the paper, which reads as space between neighbors. */
34
+ stroke?: string;
35
+ /** Type size for the labels, in pixels. Absent writes none. */
36
+ fontSize?: number;
37
+ }
38
+ export declare function Icicle({ cells, width, height, identity, fill, levels, opacity, stroke, fontSize, }: IcicleProps): import("react").JSX.Element | null;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { EDGE, fits, hueFor, labelInk, placeCells } from "./hierarchy-cells.js";
3
+ export function Icicle({ cells, width, height, identity, fill, levels, opacity = 1, stroke = "var(--viz-paper)", fontSize, }) {
4
+ if (cells.length === 0 || width <= 0 || height <= 0)
5
+ return null;
6
+ const boxes = placeCells(cells, width, height, hueFor(cells, identity, fill, levels));
7
+ const written = fontSize == null ? [] : boxes.filter(({ cell, w, h }) => fits(cell.label, w, h, fontSize, 1));
8
+ return (_jsxs(_Fragment, { children: [_jsx("g", { "data-geom": "icicle", children: boxes.map(({ cell, x, y, w, h, hue }) => (_jsx("rect", { x: x + EDGE / 2, y: y + EDGE / 2, width: Math.max(0, w - EDGE), height: Math.max(0, h - EDGE), fill: hue, fillOpacity: opacity, stroke: stroke, strokeWidth: EDGE }, cell.label))) }), written.length > 0 && fontSize != null && (_jsx("g", { "data-geom": "icicle-labels", fontSize: fontSize, pointerEvents: "none", textAnchor: "middle", children: written.map(({ cell, x, y, w, h, hue }) => (_jsx("text", { x: x + w / 2, y: y + h / 2, dominantBaseline: "central", fill: labelInk(hue), children: cell.label }, cell.label))) }))] }));
9
+ }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * A genome round a circle, drawn as one sector per chromosome.
3
+ *
4
+ * `GRAMMAR` answers `polar`. A sector carries its own base-pair range and a tile keeps its span.
5
+ */
6
+ import { type PositionLink, type RingPanel, type RingReading, type SectorSpec } from "../../core/internal.js";
7
+ export interface IdeogramProps {
8
+ sectors: SectorSpec[];
9
+ /** One span per row, in its sector's own units. */
10
+ tiles: {
11
+ sector: string;
12
+ start: number;
13
+ end: number;
14
+ level?: string;
15
+ }[];
16
+ /** The stains a tile paints by, in the order they were met. */
17
+ levels: string[];
18
+ /** One pair of positions per link, drawn inside the band. */
19
+ links?: PositionLink[];
20
+ /** Where the links' own measure runs. A link with a value reads the magnitude map against it. */
21
+ linkDomain?: [number, number];
22
+ width: number;
23
+ height: number;
24
+ /** Hue per stain, taken off the categorical map. */
25
+ identity: (index: number) => string;
26
+ /** Distinct colors that map offers. More sectors than this draws them all in one ink. */
27
+ categoricalSize?: number;
28
+ /** The color a Giemsa stain draws with. A level it declines falls back to the categorical map. */
29
+ stain?: (stain: string) => string | undefined;
30
+ /** The magnitude map, over 0..1. A ring's dots read their own values against it. */
31
+ ramp?: (t: number) => string;
32
+ /** The value the magnitude map treats as its middle, where the map has two arms. */
33
+ center?: number;
34
+ /** One hue for the whole figure, where no stain is bound. */
35
+ fill?: string;
36
+ opacity?: number;
37
+ /** Gap after each sector, in degrees. */
38
+ gap?: number;
39
+ /** Where the first sector starts, in degrees counterclockwise from twelve. */
40
+ rotate?: number;
41
+ /** Type size for the names and the readings, in pixels. Absent writes neither. */
42
+ fontSize?: number;
43
+ /**
44
+ * The readings round each sector, in their own units. Absent draws no axis.
45
+ *
46
+ * `wanted` picks the readings written and `color` inks them.
47
+ */
48
+ numbers?: {
49
+ format: (value: number) => string;
50
+ wanted?: (value: number) => boolean;
51
+ color?: string;
52
+ };
53
+ /** Rings stacked outside the band, innermost first. */
54
+ panels?: readonly RingPanel[];
55
+ /** What each ring read, in the same order. */
56
+ rings?: (RingReading | null)[];
57
+ }
58
+ export declare function Ideogram({ sectors, tiles, levels, links, linkDomain, width, height, identity, categoricalSize, stain: stainOf, ramp, center, fill, opacity, gap, rotate, fontSize, numbers, panels, rings, }: IdeogramProps): import("react").JSX.Element | null;
@@ -0,0 +1,77 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * A genome round a circle, drawn as one sector per chromosome.
4
+ *
5
+ * `GRAMMAR` answers `polar`. A sector carries its own base-pair range and a tile keeps its span.
6
+ */
7
+ import { arcPath, circularLayout, linkPath, polarPoint, rampPosition, ringBands, ringLayout, sectorAngle, RING_GAP, } from "../../core/internal.js";
8
+ import { RingStack } from "./RingStack.js";
9
+ import { sectorAxis, sectorHues, sectorTextRoom, TICK_LEN, writtenAt } from "./sector-axis.js";
10
+ /** Weight of the band a chromosome draws, in pixels. */
11
+ const BAND_WEIGHT = 12;
12
+ /** Radial gap between the band and the links inside it, in pixels. */
13
+ const LINK_INSET = 4;
14
+ /** Weak enough that a link crossing another stays readable. */
15
+ const LINK_OPACITY = 0.55;
16
+ export function Ideogram({ sectors, tiles, levels, links = [], linkDomain, width, height, identity, categoricalSize, stain: stainOf, ramp, center, fill, opacity = 1, gap, rotate, fontSize, numbers, panels = [], rings = [], }) {
17
+ if (sectors.length === 0 || width <= 0 || height <= 0)
18
+ return null;
19
+ const panel = ringLayout(width, height);
20
+ const longestName = sectors.reduce((held, sector) => Math.max(held, sector.id.length), 0);
21
+ const room = fontSize == null ? 0 : sectorTextRoom(longestName, fontSize);
22
+ const stack = panels.reduce((held, one) => held + Math.max(0, one.size) + (one.gap ?? RING_GAP), 0);
23
+ const bandRadius = Math.max(0, panel.outer - room - stack) - BAND_WEIGHT / 2;
24
+ if (bandRadius <= 0)
25
+ return null;
26
+ const layout = circularLayout(sectors, { gap, start: rotate });
27
+ const placed = new Map(layout.sectors.map((sector) => [sector.id, sector]));
28
+ const bands = ringBands(bandRadius + BAND_WEIGHT / 2, panels);
29
+ const outermost = bands.length > 0 ? bands[bands.length - 1].outer : bandRadius + BAND_WEIGHT / 2;
30
+ const reads = numbers?.format ?? ((value) => String(value));
31
+ const hue = sectorHues(layout.sectors, identity, categoricalSize, fill);
32
+ const at = (radius, angle) => polarPoint(panel, radius, angle);
33
+ const written = (angle, radius) => writtenAt(panel, angle, radius);
34
+ const axis = sectorAxis({
35
+ sectors: layout.sectors,
36
+ panel,
37
+ from: outermost,
38
+ fontSize: fontSize ?? 11,
39
+ format: numbers?.format,
40
+ wanted: numbers?.wanted,
41
+ });
42
+ const axes = fontSize == null ? [] : axis.ticks;
43
+ /* The magnitude map, left out where the author's fill paints the whole figure. */
44
+ const valued = fill == null ? ramp : undefined;
45
+ /* A link with a measure reads the magnitude map. Anything else takes its source sector's hue. */
46
+ const linkInk = (link) => link.value != null && linkDomain && valued
47
+ ? valued(rampPosition(link.value, linkDomain[0], linkDomain[1], center))
48
+ : hue.get(link.sector);
49
+ /* Inside the band, anchored at the middle of the span each end covers. */
50
+ const linkRadius = Math.max(0, bandRadius - BAND_WEIGHT / 2 - LINK_INSET);
51
+ const drawn = links.flatMap((link) => {
52
+ const near = placed.get(link.sector);
53
+ const far = placed.get(link.other);
54
+ if (!near || !far)
55
+ return [];
56
+ const from = sectorAngle(near, (link.start + link.end) / 2);
57
+ const to = sectorAngle(far, (link.otherStart + link.otherEnd) / 2);
58
+ return [{ link, d: linkPath(panel, linkRadius, from, to) }];
59
+ });
60
+ return (_jsxs(_Fragment, { children: [drawn.length > 0 && (_jsx("g", { "data-geom": "ideogram-links", fill: "none", strokeOpacity: LINK_OPACITY * opacity, children: drawn.map(({ link, d }) => (_jsx("path", { d: d, stroke: linkInk(link), children: _jsx("title", { children: `${link.sector} ${reads(link.start)} to ${link.other} ${reads(link.otherStart)}${link.value == null ? "" : `, ${reads(link.value)}`}` }) }, `${link.sector}:${link.start}-${link.other}:${link.otherStart}`))) })), _jsx("g", { "data-geom": "ideogram", children: tiles.map((tile, index) => {
61
+ const sector = placed.get(tile.sector);
62
+ if (!sector)
63
+ return null;
64
+ const level = tile.level == null ? -1 : levels.indexOf(tile.level);
65
+ /* A stain the map knows paints by staining intensity. Anything else falls back. */
66
+ const stain = tile.level == null ? undefined : stainOf?.(tile.level);
67
+ return (_jsx("path", { d: arcPath({ ...panel, inner: bandRadius - BAND_WEIGHT / 2, outer: bandRadius + BAND_WEIGHT / 2 }, sectorAngle(sector, tile.start), sectorAngle(sector, tile.end)), fill: stain ?? (level < 0 ? hue.get(tile.sector) : identity(level)), fillOpacity: opacity, stroke: "var(--viz-paper)", strokeWidth: 0.4, children: _jsx("title", { children: `${tile.sector} ${reads(tile.start)} to ${reads(tile.end)}${tile.level ? `, ${tile.level}` : ""}` }) }, index));
68
+ }) }), _jsx(RingStack, { panel: panel, sectors: layout.sectors, bands: bands, readings: rings, hue: hue, identity: identity, ramp: valued, center: center, opacity: opacity, format: reads }), axes.length > 0 && fontSize != null && (_jsx("g", { "data-geom": "ideogram-axis", fontSize: fontSize, pointerEvents: "none", fill: numbers?.color ?? "var(--viz-ink-muted)", children: axes.map((tick) => {
69
+ const mark = written(tick.angle, axis.radius);
70
+ const head = at(outermost, tick.angle);
71
+ const tail = at(outermost + TICK_LEN, tick.angle);
72
+ return (_jsxs("g", { children: [_jsx("line", { x1: head.x, y1: head.y, x2: tail.x, y2: tail.y, stroke: "var(--viz-rule)" }), _jsx("text", { x: mark.x, y: mark.y, textAnchor: mark.anchor, dominantBaseline: "central", transform: mark.rotate, children: tick.text })] }, tick.key));
73
+ }) })), fontSize != null && (_jsx("g", { "data-geom": "ideogram-labels", fontSize: fontSize, pointerEvents: "none", fill: "var(--viz-ink)", children: layout.sectors.map((sector) => {
74
+ const mark = written(sector.mid, axis.nameRadius);
75
+ return (_jsx("text", { x: mark.x, y: mark.y, textAnchor: mark.anchor, dominantBaseline: "central", transform: mark.rotate, children: sector.id }, sector.id));
76
+ }) }))] }));
77
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The band geom: two bound columns filled between, with the estimate drawn over it where there is one.
3
+ *
4
+ * The other half of the confidence band. `FitCurve` already fills between `Fit.band`'s two arrays,
5
+ * which answers the fitted case; this answers the case where the analysis ran somewhere else and
6
+ * the author is holding the bounds as columns.
7
+ *
8
+ * `GRAMMAR` marks the kind unproportional, so the vertical scale is not grounded at zero. A band
9
+ * around a ratio of 1.0 is an interval and not a length, and grounding it would spend the axis on
10
+ * space the data does not occupy. See rule 11 of `CHART-DESIGN.md` for the reading that makes bars
11
+ * and areas the other answer.
12
+ *
13
+ * The fill runs at `FitCurve`'s own opacity, since a reader meeting a fitted band and a bound one in
14
+ * one figure should not have to work out whether the difference in wash means something.
15
+ */
16
+ import type { IntervalPoint, Scale } from "../../core/internal.js";
17
+ export interface IntervalProps {
18
+ /** In axis units, ordered along x the way the band is read. */
19
+ points: IntervalPoint[];
20
+ x: Scale;
21
+ y: Scale;
22
+ color: string;
23
+ /** Paint on the band's two bounds. Absent draws the band unbounded. */
24
+ stroke?: string;
25
+ lineWidth?: number;
26
+ opacity?: number;
27
+ }
28
+ export declare function Interval({ points, x, y, color, stroke, lineWidth, opacity }: IntervalProps): import("react").JSX.Element | null;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The band geom: two bound columns filled between, with the estimate drawn over it where there is one.
4
+ *
5
+ * The other half of the confidence band. `FitCurve` already fills between `Fit.band`'s two arrays,
6
+ * which answers the fitted case; this answers the case where the analysis ran somewhere else and
7
+ * the author is holding the bounds as columns.
8
+ *
9
+ * `GRAMMAR` marks the kind unproportional, so the vertical scale is not grounded at zero. A band
10
+ * around a ratio of 1.0 is an interval and not a length, and grounding it would spend the axis on
11
+ * space the data does not occupy. See rule 11 of `CHART-DESIGN.md` for the reading that makes bars
12
+ * and areas the other answer.
13
+ *
14
+ * The fill runs at `FitCurve`'s own opacity, since a reader meeting a fitted band and a bound one in
15
+ * one figure should not have to work out whether the difference in wash means something.
16
+ */
17
+ import { useMemo } from "react";
18
+ /** Matches `FitCurve`, so the two kinds of band read as one thing. */
19
+ const BAND_OPACITY = 0.13;
20
+ export function Interval({ points, x, y, color, stroke, lineWidth = 1.5, opacity = 1 }) {
21
+ const { band, estimate } = useMemo(() => {
22
+ /* Forward along the high bound and back along the low one, which closes the region in one path. */
23
+ let top = "";
24
+ let bottom = "";
25
+ let estimate = "";
26
+ for (const reading of points) {
27
+ const at = x(reading.x).toFixed(2);
28
+ top += `${top ? "L" : "M"}${at},${y(reading.hi).toFixed(2)}`;
29
+ bottom = `L${at},${y(reading.lo).toFixed(2)}${bottom}`;
30
+ if (reading.mid != null) {
31
+ estimate += `${estimate ? "L" : "M"}${at},${y(reading.mid).toFixed(2)}`;
32
+ }
33
+ }
34
+ return { band: top ? `${top}${bottom}Z` : "", estimate };
35
+ }, [points, x, y]);
36
+ if (points.length < 2)
37
+ return null;
38
+ return (_jsxs("g", { children: [_jsx("path", { d: band, fill: color, fillOpacity: BAND_OPACITY * opacity, stroke: stroke ?? "none", ...(stroke ? { strokeWidth: lineWidth, strokeOpacity: opacity } : {}) }), estimate && (_jsx("path", { d: estimate, fill: "none", stroke: color, strokeWidth: lineWidth, strokeOpacity: opacity, strokeLinejoin: "round", strokeLinecap: "round" }))] }));
39
+ }