@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,511 @@
1
+ /**
2
+ * The maps a chart draws with, and the ramps built from them.
3
+ *
4
+ * Chart-design rule 8 splits them. Magnitude takes magma and identity takes the house rainbow.
5
+ */
6
+ import { PALETTE_SETS } from "./palette-sets.js";
7
+ import { rgbOf } from "./tokens.js";
8
+ /**
9
+ * The house rainbow, red to pink.
10
+ *
11
+ * Twelve stops in spectral order. A legend reads C0 to C11 as a sweep.
12
+ */
13
+ const HOUSE = [
14
+ "#ff6961",
15
+ "#f69552",
16
+ "#ffd347",
17
+ "#b2cc00",
18
+ "#4fd377",
19
+ "#1cc38c",
20
+ "#00bbd4",
21
+ "#448aff",
22
+ "#5a7ad3",
23
+ "#966fd6",
24
+ "#c173ff",
25
+ "#f984e5",
26
+ ];
27
+ /** Okabe-Ito without black. Identity colors a color-vision-deficient reader can tell apart. */
28
+ const OKABE_ITO = ["#0072b2", "#e69f00", "#009e73", "#d55e00", "#cc79a7", "#56b4e9", "#f0e442"];
29
+ /*
30
+ * The diverging sets, eleven anchors each. The neutral lands on a stop.
31
+ *
32
+ * ColorBrewer marks all three as safe under color-vision deficiency.
33
+ */
34
+ const DIVERGING_RDBU = [
35
+ "#67001f",
36
+ "#b1182b",
37
+ "#d6604d",
38
+ "#f3a481",
39
+ "#fddbc7",
40
+ "#f6f7f7",
41
+ "#d1e5f0",
42
+ "#90c4dd",
43
+ "#4393c3",
44
+ "#2065ab",
45
+ "#053061",
46
+ ];
47
+ const DIVERGING_BRBG = [
48
+ "#543005",
49
+ "#8b500a",
50
+ "#bf812d",
51
+ "#dec17b",
52
+ "#f6e8c3",
53
+ "#f4f5f5",
54
+ "#c7eae5",
55
+ "#7fccc0",
56
+ "#35978f",
57
+ "#01655d",
58
+ "#003c30",
59
+ ];
60
+ const DIVERGING_PUOR = [
61
+ "#7f3b08",
62
+ "#b25706",
63
+ "#e08214",
64
+ "#fcb761",
65
+ "#fee0b6",
66
+ "#f6f6f7",
67
+ "#d8daeb",
68
+ "#b1aad1",
69
+ "#8073ac",
70
+ "#532687",
71
+ "#2d004b",
72
+ ];
73
+ /*
74
+ * The UI kit's chart maps, copied from its `CHART_*` exports. The kit marks each as safe under
75
+ * color-vision deficiency. A test holds the two equal.
76
+ */
77
+ const KIT_BRAND = [
78
+ "#2f45b5",
79
+ "#fd972f",
80
+ "#038599",
81
+ "#e15759",
82
+ "#8243ba",
83
+ "#94c2ff",
84
+ "#465364",
85
+ "#f4d03f",
86
+ "#cc79a7",
87
+ "#117733",
88
+ "#88ccee",
89
+ "#882255",
90
+ ];
91
+ const KIT_BLUE = [
92
+ "#f0f3fc",
93
+ "#dce3f8",
94
+ "#c5d1f2",
95
+ "#a9bcec",
96
+ "#8aa5e4",
97
+ "#6c8ddb",
98
+ "#5276d0",
99
+ "#3d62c5",
100
+ "#2f45b5",
101
+ "#27399a",
102
+ "#1f2d7e",
103
+ "#172261",
104
+ ];
105
+ const KIT_PURPLE = [
106
+ "#f8eefb",
107
+ "#efd8f4",
108
+ "#e3bceb",
109
+ "#d49de0",
110
+ "#c27cd2",
111
+ "#ad5dc3",
112
+ "#9544b0",
113
+ "#8243ba",
114
+ "#6e2fa0",
115
+ "#5a2487",
116
+ "#481b6e",
117
+ "#371454",
118
+ ];
119
+ /* The kit's diverging maps put the neutral between the sixth and seventh stops. */
120
+ const KIT_BLUE_ORANGE = [
121
+ "#1f3d9e",
122
+ "#2f45b5",
123
+ "#5276d0",
124
+ "#7a95dd",
125
+ "#a9bcec",
126
+ "#dce3f8",
127
+ "#fce6cc",
128
+ "#facb99",
129
+ "#f7ae63",
130
+ "#fd972f",
131
+ "#d87410",
132
+ "#a6580a",
133
+ ];
134
+ const KIT_TEAL_MAGENTA = [
135
+ "#055a66",
136
+ "#099db3",
137
+ "#34b9cc",
138
+ "#88dae6",
139
+ "#cff1f5",
140
+ "#f0fafb",
141
+ "#fbebf3",
142
+ "#f0c8de",
143
+ "#e29ec2",
144
+ "#cc79a7",
145
+ "#a85585",
146
+ "#7e3b62",
147
+ ];
148
+ const KIT_PURPLE_YELLOWGREEN = [
149
+ "#481b6e",
150
+ "#8243ba",
151
+ "#a767d0",
152
+ "#c593e0",
153
+ "#e3c5ee",
154
+ "#f4e6f8",
155
+ "#f2f7d9",
156
+ "#dceb9f",
157
+ "#b8d266",
158
+ "#8fb939",
159
+ "#6e9a1f",
160
+ "#527516",
161
+ ];
162
+ const SHIPPED = {
163
+ /*
164
+ Giemsa staining, dark to light. The values are circlize's own `cytoband.col`.
165
+
166
+ The safe span keeps the unstained end off light paper.
167
+ */
168
+ giemsa: {
169
+ label: "Giemsa",
170
+ kind: "sequential",
171
+ safe: { light: [0, 0.92], dark: [0.08, 1] },
172
+ stops: ["#000000", "#828282", "#a0a0a0", "#c8c8c8", "#d2d2d2", "#dcdcdc", "#ffffff"],
173
+ },
174
+ "tetra-rainbow": { label: "Tetra rainbow", kind: "categorical", continuous: true, stops: HOUSE },
175
+ "okabe-ito": { label: "Okabe-Ito", kind: "categorical", stops: OKABE_ITO },
176
+ "tetra-brand": { label: "Tetra brand", kind: "categorical", stops: KIT_BRAND },
177
+ viridis: {
178
+ label: "Viridis",
179
+ kind: "sequential",
180
+ safe: { light: [0, 0.92], dark: [0.12, 1] },
181
+ stops: [
182
+ "#440154",
183
+ "#482878",
184
+ "#3e4989",
185
+ "#31688e",
186
+ "#26828e",
187
+ "#1f9e89",
188
+ "#35b779",
189
+ "#6ece58",
190
+ "#b5de2b",
191
+ "#fde725",
192
+ ],
193
+ },
194
+ mako: {
195
+ label: "Mako",
196
+ kind: "sequential",
197
+ safe: { light: [0, 0.82], dark: [0.22, 1] },
198
+ stops: [
199
+ "#0b0405",
200
+ "#28192e",
201
+ "#3b2e5d",
202
+ "#40498e",
203
+ "#366a9f",
204
+ "#348ba6",
205
+ "#38aaac",
206
+ "#55caad",
207
+ "#a1dfb9",
208
+ "#def5e5",
209
+ ],
210
+ },
211
+ rocket: {
212
+ label: "Rocket",
213
+ kind: "sequential",
214
+ safe: { light: [0, 0.82], dark: [0.22, 1] },
215
+ stops: [
216
+ "#03051a",
217
+ "#2a1636",
218
+ "#541e4e",
219
+ "#841e5a",
220
+ "#b41658",
221
+ "#dd2c45",
222
+ "#f06043",
223
+ "#f5946b",
224
+ "#f6c19f",
225
+ "#faebdd",
226
+ ],
227
+ },
228
+ magma: {
229
+ label: "Magma",
230
+ kind: "sequential",
231
+ safe: { light: [0, 0.82], dark: [0.22, 1] },
232
+ stops: [
233
+ "#000004",
234
+ "#180f3d",
235
+ "#440f76",
236
+ "#721f81",
237
+ "#9e2f7f",
238
+ "#cd4071",
239
+ "#f1605d",
240
+ "#fd9668",
241
+ "#feca8d",
242
+ "#fcfdbf",
243
+ ],
244
+ },
245
+ inferno: {
246
+ label: "Inferno",
247
+ kind: "sequential",
248
+ safe: { light: [0, 0.82], dark: [0.22, 1] },
249
+ stops: [
250
+ "#000004",
251
+ "#1b0c41",
252
+ "#4a0c6b",
253
+ "#781c6d",
254
+ "#a52c60",
255
+ "#cf4446",
256
+ "#ed6925",
257
+ "#fb9b06",
258
+ "#f7d13d",
259
+ "#fcffa4",
260
+ ],
261
+ },
262
+ plasma: {
263
+ label: "Plasma",
264
+ kind: "sequential",
265
+ safe: { light: [0, 0.9], dark: [0.08, 1] },
266
+ stops: [
267
+ "#0d0887",
268
+ "#46039f",
269
+ "#7201a8",
270
+ "#9c179e",
271
+ "#bd3786",
272
+ "#d8576b",
273
+ "#ed7953",
274
+ "#fb9f3a",
275
+ "#fdca26",
276
+ "#f0f921",
277
+ ],
278
+ },
279
+ cividis: {
280
+ label: "Cividis",
281
+ kind: "sequential",
282
+ safe: { light: [0, 0.94], dark: [0.06, 1] },
283
+ stops: [
284
+ "#00224e",
285
+ "#123570",
286
+ "#3b496c",
287
+ "#575d6d",
288
+ "#707173",
289
+ "#8a8678",
290
+ "#a59c74",
291
+ "#c3b369",
292
+ "#e1cc55",
293
+ "#fee838",
294
+ ],
295
+ },
296
+ /* Light to dark. Each span ends on the last stop clearing 1.5:1 against its paper. */
297
+ "tetra-blue": {
298
+ label: "Tetra blue",
299
+ kind: "sequential",
300
+ safe: { light: [2 / 11, 1], dark: [0, 10 / 11] },
301
+ stops: KIT_BLUE,
302
+ },
303
+ "tetra-purple": {
304
+ label: "Tetra purple",
305
+ kind: "sequential",
306
+ safe: { light: [2 / 11, 1], dark: [0, 10 / 11] },
307
+ stops: KIT_PURPLE,
308
+ },
309
+ rdbu: {
310
+ label: "Red-Blue",
311
+ kind: "diverging",
312
+ stops: DIVERGING_RDBU,
313
+ },
314
+ brbg: {
315
+ label: "Brown-Teal",
316
+ kind: "diverging",
317
+ stops: DIVERGING_BRBG,
318
+ },
319
+ puor: {
320
+ label: "Orange-Purple",
321
+ kind: "diverging",
322
+ stops: DIVERGING_PUOR,
323
+ },
324
+ "tetra-blue-orange": { label: "Tetra blue-orange", kind: "diverging", stops: KIT_BLUE_ORANGE },
325
+ "tetra-teal-magenta": { label: "Tetra teal-magenta", kind: "diverging", stops: KIT_TEAL_MAGENTA },
326
+ "tetra-purple-yellowgreen": { label: "Tetra purple-yellowgreen", kind: "diverging", stops: KIT_PURPLE_YELLOWGREEN },
327
+ ...PALETTE_SETS,
328
+ };
329
+ /** A map copied and frozen with its stops and its safe span. */
330
+ const frozen = ({ safe, ...palette }) => Object.freeze({
331
+ ...palette,
332
+ stops: Object.freeze([...palette.stops]),
333
+ ...(safe
334
+ ? {
335
+ safe: Object.freeze({
336
+ light: Object.freeze([safe.light[0], safe.light[1]]),
337
+ dark: Object.freeze([safe.dark[0], safe.dark[1]]),
338
+ }),
339
+ }
340
+ : {}),
341
+ });
342
+ /**
343
+ * The maps the package ships, by name. Frozen, each map with its stops and its safe span.
344
+ *
345
+ * A host adds its own through `registerPalette`. A name resolves against both.
346
+ */
347
+ export const PALETTES = Object.freeze(Object.fromEntries(Object.entries(SHIPPED).map(([name, palette]) => [name, frozen(palette)])));
348
+ /** Each map a name resolves to: the shipped ones and those a host registered. */
349
+ const registry = new Map(Object.entries(PALETTES));
350
+ /**
351
+ * Adds a host's own map under a name, for a layer's `palette`, a track's or a `PaletteChoice`.
352
+ *
353
+ * A shipped name is refused. Registering a name again replaces its map.
354
+ */
355
+ export function registerPalette(name, palette) {
356
+ if (Object.hasOwn(PALETTES, name))
357
+ throw new Error(`ts-lib-viz: ${name} is a shipped palette and keeps its map`);
358
+ registry.set(name, frozen(palette));
359
+ }
360
+ export const DEFAULT_SEQUENTIAL = "magma";
361
+ export const DEFAULT_DIVERGING = "rdbu";
362
+ export const DEFAULT_CATEGORICAL = "tetra-rainbow";
363
+ /** Where a diverging map's neutral stop falls when the caller names no other value. */
364
+ export const DEFAULT_CENTER = 0;
365
+ /** Names of the maps of one kind, for a switcher to offer. */
366
+ export const palettesOf = (kind) => [...registry].filter(([, palette]) => palette.kind === kind).map(([name]) => name);
367
+ const paletteFor = (name, fallback) => registry.get(name) ?? registry.get(fallback);
368
+ /** A map's stops, for a legend swatch or a caller building its own sampler. */
369
+ export const stopsOf = (name) => paletteFor(name, DEFAULT_CATEGORICAL).stops;
370
+ const channel = (value) => Math.round(value * 255);
371
+ /* Parsed once per map, keyed on the map a name resolved to. Two kinds asking for one
372
+ unregistered name reach two maps. */
373
+ const parsed = new WeakMap();
374
+ /** A map's stops as numbers. A stop the parser cannot read drops out. */
375
+ function rgbStops(palette) {
376
+ const held = parsed.get(palette);
377
+ if (held)
378
+ return held;
379
+ const rgb = palette.stops.flatMap((stop) => {
380
+ const one = rgbOf(stop);
381
+ return one ? [one] : [];
382
+ });
383
+ parsed.set(palette, rgb);
384
+ return rgb;
385
+ }
386
+ /** A map sampled at `t`, with the span applied where the map declares one. */
387
+ function sample(palette, t, dark) {
388
+ const rgb = rgbStops(palette);
389
+ /* Black where no stop parsed, matching `inkOn`. */
390
+ if (rgb.length === 0)
391
+ return "#000000";
392
+ const span = palette.safe?.[dark ? "dark" : "light"];
393
+ const held = Number.isNaN(t) ? 0 : Math.min(1, Math.max(0, t));
394
+ const placed = span ? span[0] + (span[1] - span[0]) * held : held;
395
+ const scaled = placed * (rgb.length - 1);
396
+ /* A single stop leaves no pair to interpolate. Both ends read it. */
397
+ const at = Math.max(0, Math.min(rgb.length - 2, Math.floor(scaled)));
398
+ const between = scaled - at;
399
+ const [r0, g0, b0] = rgb[at];
400
+ const [r1, g1, b1] = rgb[at + 1] ?? rgb[at];
401
+ return `rgb(${channel(r0 + (r1 - r0) * between)}, ${channel(g0 + (g1 - g0) * between)}, ${channel(b0 + (b1 - b0) * between)})`;
402
+ }
403
+ /**
404
+ * A sequential map over 0..1, as a CSS color. Input past either end clamps. NaN reads as 0.
405
+ *
406
+ * `dark` maps the request into the span that survives dark paper.
407
+ */
408
+ export function sequentialCss(t, name = DEFAULT_SEQUENTIAL, dark = false) {
409
+ return sample(paletteFor(name, DEFAULT_SEQUENTIAL), t, dark);
410
+ }
411
+ /**
412
+ * A diverging map over 0..1, with its neutral stop at the middle.
413
+ *
414
+ * No safe span applies. Clipping one end would move the neutral off center.
415
+ */
416
+ export function divergingCss(t, name = DEFAULT_DIVERGING) {
417
+ return sample(paletteFor(name, DEFAULT_DIVERGING), t, false);
418
+ }
419
+ /**
420
+ * Where each Giemsa level falls along the stain map, from fully stained to unstained.
421
+ *
422
+ * circlize gives gpos25 and gpos50 one gray, and gpos33 a lighter one than either.
423
+ */
424
+ const STAIN_AT = {
425
+ gpos100: 0,
426
+ gpos: 0,
427
+ gpos75: 1 / 6,
428
+ gpos66: 2 / 6,
429
+ gpos50: 3 / 6,
430
+ gpos25: 3 / 6,
431
+ gpos33: 4 / 6,
432
+ gvar: 5 / 6,
433
+ gneg: 1,
434
+ };
435
+ /**
436
+ * The two cytoband levels that name a structure, not a staining intensity.
437
+ *
438
+ * A centromere and a stalk take a fixed color under any palette.
439
+ */
440
+ const STAIN_FIXED = {
441
+ acen: "#d92f27",
442
+ stalk: "#647fa4",
443
+ };
444
+ /**
445
+ * The color one cytogenetic band draws with. An unknown level answers undefined.
446
+ *
447
+ * A caller falls back to its own map where this declines.
448
+ */
449
+ export function cytobandCss(stain, dark = false) {
450
+ const fixed = Object.hasOwn(STAIN_FIXED, stain) ? STAIN_FIXED[stain] : undefined;
451
+ if (fixed)
452
+ return fixed;
453
+ const at = Object.hasOwn(STAIN_AT, stain) ? STAIN_AT[stain] : undefined;
454
+ return at === undefined ? undefined : sequentialCss(at, "giemsa", dark);
455
+ }
456
+ /** Distinct colors a categorical map offers before it repeats. */
457
+ export const categoricalSize = (name = DEFAULT_CATEGORICAL) => paletteFor(name, DEFAULT_CATEGORICAL).stops.length;
458
+ /** A categorical map by index, cycling past its end the way a palette switcher's would. */
459
+ export function categoricalCss(index, name = DEFAULT_CATEGORICAL) {
460
+ const { stops } = paletteFor(name, DEFAULT_CATEGORICAL);
461
+ return stops[((index % stops.length) + stops.length) % stops.length];
462
+ }
463
+ /* sRGB's own transfer function, undone. The weighted sum below is then a luminance. */
464
+ const linear = (value) => (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4);
465
+ /** Where black and white swap places over a background, in relative luminance. */
466
+ const CROSSOVER = 0.179;
467
+ /**
468
+ * Ink that reads against a given fill, as black or white.
469
+ *
470
+ * A translucent fill blends over the paper first. A syntax the parser cannot read falls back to
471
+ * black.
472
+ */
473
+ export function inkOn(fill, over) {
474
+ const rgb = rgbOf(fill);
475
+ if (!rgb)
476
+ return "#000000";
477
+ const paper = over ? rgbOf(over.paper) : null;
478
+ const seen = (at) => (paper ? paper[at] + (rgb[at] - paper[at]) * over.opacity : rgb[at]);
479
+ const light = 0.2126 * linear(seen(0)) + 0.7152 * linear(seen(1)) + 0.0722 * linear(seen(2));
480
+ return light > CROSSOVER ? "#000000" : "#ffffff";
481
+ }
482
+ /**
483
+ * The pair of ramps a frame draws with.
484
+ *
485
+ * A diverging choice puts its center onto the result. The layer build reads `center` when it
486
+ * normalizes a value.
487
+ */
488
+ export function palettesFor({ sequential, diverging, center, categorical, dark } = {}) {
489
+ const magnitude = diverging
490
+ ? (t) => divergingCss(t, diverging)
491
+ : (t) => sequentialCss(t, sequential ?? DEFAULT_SEQUENTIAL, dark ?? false);
492
+ /* A two-armed map has a middle. A one-armed one takes one where the caller states it. */
493
+ const middle = diverging ? (center ?? DEFAULT_CENTER) : center;
494
+ return {
495
+ sequential: magnitude,
496
+ /*
497
+ A second magnitude map, for a series that named one of its own. The trim span depends on
498
+ the paper behind it and `dark` belongs to the caller.
499
+ */
500
+ sequentialFor: (name) => (t) => sequentialCss(t, name, dark ?? false),
501
+ categoricalFor: (name) => registry.get(name)?.kind === "categorical"
502
+ ? { categorical: (index) => categoricalCss(index, name), categoricalSize: categoricalSize(name) }
503
+ : undefined,
504
+ categorical: (index) => categoricalCss(index, categorical ?? DEFAULT_CATEGORICAL),
505
+ categoricalSize: categoricalSize(categorical ?? DEFAULT_CATEGORICAL),
506
+ stain: (stain) => cytobandCss(stain, dark ?? false),
507
+ ...(middle === undefined ? {} : { center: middle }),
508
+ };
509
+ }
510
+ /** What a `Viz` component colors with when the caller hands it nothing. Frozen. */
511
+ export const DEFAULT_PALETTES = Object.freeze(palettesFor());
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The reading surface -- the number in this row for this field.
3
+ *
4
+ * Accessors over materialized arrays. Copying 250k rows to plot a scatter is the cost this
5
+ * avoids.
6
+ */
7
+ import { type Aggregate, type Group } from "./aggregate.js";
8
+ /** How a field reads on a chart. A subset of the app's role vocabulary as an open string. */
9
+ export type PlotFieldRole = string;
10
+ /** A column a channel can bind, flattened from whichever table it came from. */
11
+ export interface PlotField {
12
+ id: string;
13
+ label: string;
14
+ numeric: boolean;
15
+ role?: PlotFieldRole;
16
+ unit?: string;
17
+ digits?: number;
18
+ /** Values span orders of magnitude. The axis defaults to log. */
19
+ logScale?: boolean;
20
+ /** Values are epoch milliseconds. The axis defaults to a UTC calendar scale. */
21
+ timeScale?: boolean;
22
+ /**
23
+ * The cut a gate grid compares the measure against.
24
+ *
25
+ * A reading at or above it clears, or at or below where `direction` is `lower`.
26
+ */
27
+ target?: number;
28
+ /** Which way counts as better. Seeds the axis-end captions. */
29
+ direction?: "higher" | "lower";
30
+ }
31
+ export interface PlotData {
32
+ fields: PlotField[];
33
+ rowCount: number;
34
+ /** Numeric value, or null where absent or not a number. */
35
+ number(row: number, field: string): number | null;
36
+ /** Display value, or null. */
37
+ text(row: number, field: string): string | null;
38
+ /**
39
+ * Index of this row in the source that owns it.
40
+ *
41
+ * Row 12 of the plot is another row of the table and opening a record needs that second
42
+ * number.
43
+ */
44
+ rowIndex(row: number): number;
45
+ /** Field naming a record, for the readout title. */
46
+ keyField?: string;
47
+ /**
48
+ * A numeric field read whole, NaN where `number` answers null.
49
+ *
50
+ * Optional. A walker over each row reads it where a table offers it.
51
+ */
52
+ numbers?(field: string): Float64Array | null;
53
+ /** A field read whole as display text, null where `text` answers null. Optional, as `numbers` is. */
54
+ texts?(field: string): readonly (string | null)[] | null;
55
+ }
56
+ /**
57
+ * The table with each whole-column read made once and reused.
58
+ *
59
+ * Scoped to one build. A later build wraps the table afresh and reads current values. Each
60
+ * accessor delegates, which keeps a class instance's prototype methods.
61
+ */
62
+ export declare function readOnce(data: PlotData): PlotData;
63
+ /**
64
+ * One aggregate per category, over the plot's table.
65
+ *
66
+ * Walks the accessors and shares the reduction with the columnar path. Categories come back in
67
+ * first-seen order and the caller sorts.
68
+ */
69
+ export declare function groupRows(data: PlotData, keyField: string, valueField: string | null, aggregate?: Aggregate,
70
+ /** Returns the readings beside each reduction, for a geom that draws them. */
71
+ keepValues?: boolean): Group[];
@@ -0,0 +1,82 @@
1
+ /**
2
+ * The reading surface -- the number in this row for this field.
3
+ *
4
+ * Accessors over materialized arrays. Copying 250k rows to plot a scatter is the cost this
5
+ * avoids.
6
+ */
7
+ import { NEEDS_VALUES, reduceBucket, spreadOf } from "./aggregate.js";
8
+ /** Calls a whole-column read once per field. */
9
+ function once(read) {
10
+ const columns = new Map();
11
+ return (field) => {
12
+ if (!columns.has(field))
13
+ columns.set(field, read(field));
14
+ return columns.get(field) ?? null;
15
+ };
16
+ }
17
+ /**
18
+ * The table with each whole-column read made once and reused.
19
+ *
20
+ * Scoped to one build. A later build wraps the table afresh and reads current values. Each
21
+ * accessor delegates, which keeps a class instance's prototype methods.
22
+ */
23
+ export function readOnce(data) {
24
+ const { numbers, texts } = data;
25
+ if (!numbers && !texts)
26
+ return data;
27
+ return {
28
+ fields: data.fields,
29
+ rowCount: data.rowCount,
30
+ keyField: data.keyField,
31
+ number: (row, field) => data.number(row, field),
32
+ text: (row, field) => data.text(row, field),
33
+ rowIndex: (row) => data.rowIndex(row),
34
+ numbers: numbers && once((field) => numbers.call(data, field)),
35
+ texts: texts && once((field) => texts.call(data, field)),
36
+ };
37
+ }
38
+ /**
39
+ * One aggregate per category, over the plot's table.
40
+ *
41
+ * Walks the accessors and shares the reduction with the columnar path. Categories come back in
42
+ * first-seen order and the caller sorts.
43
+ */
44
+ export function groupRows(data, keyField, valueField, aggregate = "mean",
45
+ /** Returns the readings beside each reduction, for a geom that draws them. */
46
+ keepValues = false) {
47
+ const running = new Map();
48
+ const collected = keepValues || NEEDS_VALUES.includes(aggregate) ? new Map() : null;
49
+ for (let row = 0; row < data.rowCount; row += 1) {
50
+ const key = data.text(row, keyField);
51
+ if (key == null)
52
+ continue;
53
+ // No measure bound counts rows. Each row is one.
54
+ const value = valueField ? data.number(row, valueField) : 1;
55
+ if (value == null)
56
+ continue;
57
+ let bucket = running.get(key);
58
+ if (!bucket) {
59
+ bucket = { n: 0, sum: 0, sumSq: 0, min: Infinity, max: -Infinity };
60
+ running.set(key, bucket);
61
+ }
62
+ bucket.n += 1;
63
+ bucket.sum += value;
64
+ bucket.sumSq += value * value;
65
+ bucket.min = Math.min(bucket.min, value);
66
+ bucket.max = Math.max(bucket.max, value);
67
+ if (collected) {
68
+ const values = collected.get(key);
69
+ if (values)
70
+ values.push(value);
71
+ else
72
+ collected.set(key, [value]);
73
+ }
74
+ }
75
+ return [...running].map(([key, bucket]) => ({
76
+ key,
77
+ n: bucket.n,
78
+ value: reduceBucket(bucket, aggregate, collected?.get(key)),
79
+ ...spreadOf(bucket),
80
+ ...(keepValues ? { values: collected?.get(key) ?? [] } : {}),
81
+ }));
82
+ }