@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,92 @@
1
+ /**
2
+ * The point program, and the picking pass that shares its geometry.
3
+ *
4
+ * One vertex per geom, drawn as a point sprite, with the glyph cut out in the fragment stage from
5
+ * `gl_PointCoord`. A quad per geom was the first shape this took and it ran four vertex shader
6
+ * invocations for every geom: at ten million that is forty million, and the measurement said so.
7
+ *
8
+ * Drawing the glyph in the shader keeps the four shapes the SVG path offers, which is the channel
9
+ * that survives a printout and a color-blind reader, and it costs no extra geometry.
10
+ *
11
+ * The picking pass runs the same vertex shader with the id color in place of the fill, so a hit
12
+ * cannot land on a geom the visible pass drew somewhere else.
13
+ */
14
+ export declare const POINT_VERTEX = "#version 300 es\nprecision highp float;\n\n/** Offset from the layer's center, in data units. */\nin vec2 a_offset;\nin vec4 a_color;\nin vec4 a_pick;\n/** Geom diameter in CSS pixels, where the size channel bound a column. */\nin float a_size;\n\n/** Pixels per data unit. */\nuniform vec2 u_scale;\n/** Where the layer's center sits in the viewport, in pixels. */\nuniform vec2 u_translate;\nuniform vec2 u_viewport;\n/** Geom diameter in CSS pixels, and the ratio that turns it into device pixels. */\nuniform float u_size;\nuniform float u_dpr;\n/** One diameter for the whole layer, where the caller packed no per-geom sizes. */\nuniform bool u_flatSize;\n/** One color for the whole layer, where the caller supplied no per-geom colors. */\nuniform vec4 u_flat;\nuniform bool u_flatColor;\n\n/** Outline width of a hollow glyph, in CSS pixels. The fragment stage reads it as v_band. */\nuniform float u_outline;\n\nout vec4 v_color;\nout vec4 v_pick;\n/** Outline width in sprite units, which is what the glyph test can measure against. */\nout float v_band;\n\n\nfloat band(float outline, float dpr, float sprite) {\n return clamp(2.0 * outline * dpr / max(sprite, 1.0), 0.0, 0.5);\n}\n\n\nvoid main() {\n v_color = u_flatColor ? u_flat : a_color;\n v_pick = a_pick;\n\n vec2 pixels = a_offset * u_scale + u_translate;\n vec2 clip = (pixels / u_viewport) * 2.0 - 1.0;\n gl_Position = vec4(clip, 0.0, 1.0);\n gl_PointSize = (u_flatSize ? u_size : a_size) * u_dpr;\n v_band = band(u_outline, u_dpr, gl_PointSize);\n}\n";
15
+ /**
16
+ * The glyph, cut from the sprite.
17
+ *
18
+ * `u_shape` names one of the four the point geom offers, in the same order the spec's `PointShape`
19
+ * lists them: circle, square, triangle, diamond. A fragment outside the glyph is discarded, which
20
+ * is what keeps a triangle from reading as a box at four pixels.
21
+ *
22
+ * Each glyph is a signed distance in sprite units and not a boolean, since `u_hollow` needs to know
23
+ * how deep inside the edge a fragment sits. The four boundaries are where they were: a hollow glyph
24
+ * is the filled one with its middle taken out, so switching one series to outlines leaves both
25
+ * series covering the same footprint.
26
+ *
27
+ * Picking reads the filled footprint whatever `u_hollow` says. A pointer aimed at the center of a
28
+ * ring is aimed at that geom, and a hit that fell through the hole would land on whatever sits
29
+ * behind it.
30
+ */
31
+ export declare const POINT_FRAGMENT = "#version 300 es\nprecision highp float;\n\nin vec4 v_color;\nin vec4 v_pick;\nin float v_band;\n\nuniform int u_shape;\n/** Draws the glyph as an outline v_band deep, with the page showing through the middle. */\nuniform bool u_hollow;\n/** Picking writes the address instead of the fill. */\nuniform bool u_picking;\n\nout vec4 fragColor;\n\nvoid main() {\n // Sprite coordinates run 0 to 1 with y down; the glyphs want -1 to 1 with y up.\n vec2 p = vec2(gl_PointCoord.x, 1.0 - gl_PointCoord.y) * 2.0 - 1.0;\n float d;\n\n if (u_shape == 1) {\n d = max(abs(p.x), abs(p.y)) - 1.0;\n } else if (u_shape == 2) {\n /* Triangle: two half-planes from the apex at (0, 1) to the base corners, and the base itself.\n Divided by the edge normal's length so the result is a distance and not a half-plane test,\n which is what makes the outline the same width down all three sides. */\n d = max((2.0 * abs(p.x) + p.y - 1.0) * 0.4472136, -1.0 - p.y);\n } else if (u_shape == 3) {\n d = (abs(p.x) + abs(p.y) - 1.0) * 0.7071068;\n } else {\n d = length(p) - 1.0;\n }\n\n if (d > 0.0) discard;\n if (u_hollow && !u_picking && d < -v_band) discard;\n fragColor = u_picking ? v_pick : v_color;\n}\n";
32
+ /**
33
+ * The cube's vertex program, which is the point program under a camera.
34
+ *
35
+ * The 2D path maps offsets to pixels with two uniforms and writes a flat z. A cube needs the whole
36
+ * model-view-projection product, so it takes a matrix and leaves the other path alone: the frame
37
+ * numbers measured against the flat program stand as they were measured.
38
+ *
39
+ * The third coordinate arrives as its own attribute beside the interleaved pair, so a caller packs
40
+ * x and y the way it already does and adds one float a geom for depth.
41
+ *
42
+ * Geoms scale with distance, which is the first of the two depth cues the design language asks for.
43
+ * The projection divides by view depth and the sprite is divided by the same number, so a geom that
44
+ * moves away shrinks the way the geometry around it does. See the ADR "A third position scale is
45
+ * permitted where the reader can rotate".
46
+ */
47
+ export declare const CUBE_VERTEX = "#version 300 es\nprecision highp float;\n\n/** Offset from the layer's center on the floor plane, in data units. */\nin vec2 a_offset;\n/** Offset from the layer's center on the third scale, in data units. */\nin float a_depth;\nin vec4 a_color;\nin vec4 a_pick;\nin float a_size;\n\n/** Model, view and projection, multiplied on the CPU where it changes once a frame. */\nuniform mat4 u_mvp;\n/** Geom diameter in CSS pixels, and the ratio that turns it into device pixels. */\nuniform float u_size;\nuniform float u_dpr;\nuniform bool u_flatSize;\n/** View depth at which a geom draws its stated diameter. Geoms either side of it scale around it. */\nuniform float u_depthRef;\nuniform vec4 u_flat;\nuniform bool u_flatColor;\n\n/** Outline width of a hollow glyph, in CSS pixels. */\nuniform float u_outline;\n\nout vec4 v_color;\nout vec4 v_pick;\nout float v_band;\n\n\nfloat band(float outline, float dpr, float sprite) {\n return clamp(2.0 * outline * dpr / max(sprite, 1.0), 0.0, 0.5);\n}\n\n\nvoid main() {\n v_color = u_flatColor ? u_flat : a_color;\n v_pick = a_pick;\n\n gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);\n\n float diameter = u_flatSize ? u_size : a_size;\n // A geom behind the eye has no size worth computing, and a divide by nought writes a NaN.\n float depth = max(gl_Position.w, 0.001);\n gl_PointSize = max(1.0, diameter * u_dpr * u_depthRef / depth);\n /* A geom that moved away shrinks, and its outline shrinks with it, so a receding hollow cloud\n stays hollow instead of closing into dots. */\n v_band = band(u_outline, u_dpr, gl_PointSize);\n}\n";
48
+ /**
49
+ * The mesh program: triangles with a light on them.
50
+ *
51
+ * A relief and a structure read as objects or they read as nothing, and what makes a projected
52
+ * object an object is shading. The light is fixed in the world instead of to the camera, so a
53
+ * reader turning the figure watches the light cross it, which says as much about the shape as the
54
+ * parallax does.
55
+ *
56
+ * Positions arrive the way a cube's points do, as offsets on the pair plus one on the third scale,
57
+ * so one camera serves both programs. The normals come off the CPU, averaged over the faces each
58
+ * vertex belongs to.
59
+ */
60
+ export declare const MESH_VERTEX = "#version 300 es\nprecision highp float;\n\nin vec2 a_offset;\nin float a_depth;\nin vec3 a_normal;\nin vec4 a_color;\n\nuniform mat4 u_mvp;\n/** Turns a normal in the data's axes into one in the world, past the model's own scaling. */\nuniform mat3 u_normalMatrix;\n\nout vec4 v_color;\nout vec3 v_normal;\n\nvoid main() {\n v_color = a_color;\n v_normal = normalize(u_normalMatrix * a_normal);\n gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);\n}\n";
61
+ export declare const MESH_FRAGMENT = "#version 300 es\nprecision highp float;\n\nin vec4 v_color;\nin vec3 v_normal;\n\nuniform vec3 u_light;\nuniform float u_ambient;\n\nout vec4 fragColor;\n\nvoid main() {\n // Absolute, so a relief seen from beneath is lit instead of black: both faces are the same surface.\n float lambert = abs(dot(normalize(v_normal), normalize(u_light)));\n fragColor = vec4(v_color.rgb * (u_ambient + (1.0 - u_ambient) * lambert), v_color.a);\n}\n";
62
+ /**
63
+ * The line program. It draws segments under the cube's camera as quads a set number of pixels wide.
64
+ *
65
+ * Each segment is six vertices with its far end and a corner code. The vertex stage widens it on screen.
66
+ * At nought width the triangles draw in place, as a pane.
67
+ */
68
+ export declare const LINE_VERTEX = "#version 300 es\nprecision highp float;\n\nin vec2 a_offset;\nin float a_depth;\n/** The segment's other end, as offsets from the layer's center. */\nin vec3 a_other;\n/** Which side of the segment the vertex stands, minus one or one, and whether it is the far end. */\nin vec2 a_corner;\n\nuniform mat4 u_mvp;\n/** The plot area in device pixels. */\nuniform vec2 u_viewport;\n/** Line width in device pixels. */\nuniform float u_width;\n\nvoid main() {\n vec4 self = u_mvp * vec4(a_offset, a_depth, 1.0);\n vec4 other = u_mvp * vec4(a_other, 1.0);\n float w = max(self.w, 0.001);\n vec2 half_viewport = 0.5 * u_viewport;\n vec2 here = self.xy / w * half_viewport;\n vec2 there = other.xy / max(other.w, 0.001) * half_viewport;\n\n vec2 run = a_corner.y > 0.5 ? here - there : there - here;\n float span = length(run);\n vec2 dir = span > 0.0 ? run / span : vec2(1.0, 0.0);\n vec2 shift = vec2(-dir.y, dir.x) * a_corner.x * 0.5 * u_width;\n\n gl_Position = vec4(self.xy + shift / half_viewport * w, self.z, self.w);\n}\n";
69
+ export declare const LINE_FRAGMENT = "#version 300 es\nprecision highp float;\n\nuniform vec4 u_color;\n\nout vec4 fragColor;\n\nvoid main() {\n fragColor = u_color;\n}\n";
70
+ /**
71
+ * The raymarched program, for the two kinds that read a field through its depth.
72
+ *
73
+ * The geometry is the box itself: the front faces are drawn, each fragment is where a ray enters,
74
+ * and the ray walks to where it leaves. `isosurface` stops at the first crossing of the level and
75
+ * shades it with the gradient, which is the normal of the shell it just hit. `volume` keeps walking
76
+ * and composites front to back, which is what makes a field readable through itself.
77
+ *
78
+ * The field is a byte a cell in a 3D texture, and the transfer function is a 256-wide strip of the
79
+ * chart's own magnitude map. Byte nought is the cell nothing landed in and it stays clear, so a
80
+ * sparse field reads as sparse instead of as a block of the low color.
81
+ *
82
+ * See the ADR "A third position scale is permitted where the reader can rotate".
83
+ */
84
+ export declare const VOLUME_VERTEX = "#version 300 es\nprecision highp float;\n\nin vec2 a_offset;\nin float a_depth;\n\nuniform mat4 u_mvp;\n/** The model alone, so the fragment stage has the ray's start in the unit box. */\nuniform mat4 u_model;\n\nout vec3 v_entry;\n\nvoid main() {\n vec4 world = u_model * vec4(a_offset, a_depth, 1.0);\n v_entry = world.xyz;\n gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);\n}\n";
85
+ export declare const VOLUME_FRAGMENT = "#version 300 es\nprecision highp float;\nprecision highp sampler3D;\n\nin vec3 v_entry;\n\nuniform sampler3D u_field;\n/** The magnitude map as a strip, so the ray reads the chart's own colors. */\nuniform sampler2D u_ramp;\n/** Where the reader is standing, in the unit box. */\nuniform vec3 u_eye;\n/** Steps a ray takes across the box. */\nuniform int u_steps;\n/** Set for an isosurface, clear for a volume. */\nuniform bool u_iso;\n/** The level an isosurface stands at, over nought to one. */\nuniform float u_level;\n/** How much of the field one step of a volume ray absorbs. */\nuniform float u_density;\nuniform vec3 u_light;\nuniform float u_ambient;\n\nout vec4 fragColor;\n\n/** Where a ray leaves the box, as a distance along it. */\nfloat exitAt(vec3 from, vec3 dir) {\n vec3 far = (sign(dir) - from) / max(abs(dir), vec3(1e-6)) * sign(dir);\n return min(min(far.x, far.y), far.z);\n}\n\n/*\n The world draws the third scale upward, so world y is the data's z and world z is the data's y.\n The field is packed in the data's own axis order, and the lookup is where the swap is undone.\n*/\nfloat sampleAt(vec3 p) {\n return texture(u_field, vec3(p.x, p.z, p.y) * 0.5 + 0.5).r;\n}\n\n/** The field's gradient, by central differences, which is the shell's own normal. */\nvec3 gradientAt(vec3 p, float step) {\n vec2 d = vec2(step, 0.0);\n return normalize(vec3(\n sampleAt(p + d.xyy) - sampleAt(p - d.xyy),\n sampleAt(p + d.yxy) - sampleAt(p - d.yxy),\n sampleAt(p + d.yyx) - sampleAt(p - d.yyx)\n ) + vec3(1e-6));\n}\n\nvoid main() {\n vec3 dir = normalize(v_entry - u_eye);\n float span = exitAt(v_entry, dir);\n float stride = span / float(u_steps);\n\n vec3 p = v_entry;\n vec4 out_color = vec4(0.0);\n\n for (int step = 0; step < 512; step += 1) {\n if (step >= u_steps) break;\n\n float value = sampleAt(p);\n if (value > 0.0) {\n if (u_iso) {\n if (value >= u_level) {\n vec3 normal = gradientAt(p, stride);\n float lambert = abs(dot(normal, normalize(u_light)));\n vec3 tint = texture(u_ramp, vec2(value, 0.5)).rgb;\n fragColor = vec4(tint * (u_ambient + (1.0 - u_ambient) * lambert), 1.0);\n return;\n }\n } else {\n vec4 sampled = texture(u_ramp, vec2(value, 0.5));\n float alpha = value * u_density;\n // Front to back: what is already written blocks what is behind it.\n out_color.rgb += (1.0 - out_color.a) * sampled.rgb * alpha;\n out_color.a += (1.0 - out_color.a) * alpha;\n if (out_color.a > 0.98) break;\n }\n }\n\n p += dir * stride;\n }\n\n if (u_iso && out_color.a == 0.0) discard;\n if (out_color.a <= 0.001) discard;\n fragColor = out_color;\n}\n";
86
+ /** Shape codes, in the order the spec's `PointShape` union lists them. */
87
+ export declare const SHAPE_CODE: {
88
+ readonly circle: 0;
89
+ readonly square: 1;
90
+ readonly triangle: 2;
91
+ readonly diamond: 3;
92
+ };
@@ -0,0 +1,405 @@
1
+ /**
2
+ * The point program, and the picking pass that shares its geometry.
3
+ *
4
+ * One vertex per geom, drawn as a point sprite, with the glyph cut out in the fragment stage from
5
+ * `gl_PointCoord`. A quad per geom was the first shape this took and it ran four vertex shader
6
+ * invocations for every geom: at ten million that is forty million, and the measurement said so.
7
+ *
8
+ * Drawing the glyph in the shader keeps the four shapes the SVG path offers, which is the channel
9
+ * that survives a printout and a color-blind reader, and it costs no extra geometry.
10
+ *
11
+ * The picking pass runs the same vertex shader with the id color in place of the fill, so a hit
12
+ * cannot land on a geom the visible pass drew somewhere else.
13
+ */
14
+ /**
15
+ * The outline band a hollow glyph keeps, shared by both point programs.
16
+ *
17
+ * A sprite spans two units across the geom's diameter, so one unit is the radius in device pixels
18
+ * and an outline of `outline` CSS pixels is `2 * outline * dpr / gl_PointSize` of it. Capped at half
19
+ * the glyph so a geom small enough for its own outline to meet in the middle keeps a visible center.
20
+ */
21
+ const BAND_FN = `
22
+ float band(float outline, float dpr, float sprite) {
23
+ return clamp(2.0 * outline * dpr / max(sprite, 1.0), 0.0, 0.5);
24
+ }
25
+ `;
26
+ export const POINT_VERTEX = `#version 300 es
27
+ precision highp float;
28
+
29
+ /** Offset from the layer's center, in data units. */
30
+ in vec2 a_offset;
31
+ in vec4 a_color;
32
+ in vec4 a_pick;
33
+ /** Geom diameter in CSS pixels, where the size channel bound a column. */
34
+ in float a_size;
35
+
36
+ /** Pixels per data unit. */
37
+ uniform vec2 u_scale;
38
+ /** Where the layer's center sits in the viewport, in pixels. */
39
+ uniform vec2 u_translate;
40
+ uniform vec2 u_viewport;
41
+ /** Geom diameter in CSS pixels, and the ratio that turns it into device pixels. */
42
+ uniform float u_size;
43
+ uniform float u_dpr;
44
+ /** One diameter for the whole layer, where the caller packed no per-geom sizes. */
45
+ uniform bool u_flatSize;
46
+ /** One color for the whole layer, where the caller supplied no per-geom colors. */
47
+ uniform vec4 u_flat;
48
+ uniform bool u_flatColor;
49
+
50
+ /** Outline width of a hollow glyph, in CSS pixels. The fragment stage reads it as v_band. */
51
+ uniform float u_outline;
52
+
53
+ out vec4 v_color;
54
+ out vec4 v_pick;
55
+ /** Outline width in sprite units, which is what the glyph test can measure against. */
56
+ out float v_band;
57
+
58
+ ${BAND_FN}
59
+
60
+ void main() {
61
+ v_color = u_flatColor ? u_flat : a_color;
62
+ v_pick = a_pick;
63
+
64
+ vec2 pixels = a_offset * u_scale + u_translate;
65
+ vec2 clip = (pixels / u_viewport) * 2.0 - 1.0;
66
+ gl_Position = vec4(clip, 0.0, 1.0);
67
+ gl_PointSize = (u_flatSize ? u_size : a_size) * u_dpr;
68
+ v_band = band(u_outline, u_dpr, gl_PointSize);
69
+ }
70
+ `;
71
+ /**
72
+ * The glyph, cut from the sprite.
73
+ *
74
+ * `u_shape` names one of the four the point geom offers, in the same order the spec's `PointShape`
75
+ * lists them: circle, square, triangle, diamond. A fragment outside the glyph is discarded, which
76
+ * is what keeps a triangle from reading as a box at four pixels.
77
+ *
78
+ * Each glyph is a signed distance in sprite units and not a boolean, since `u_hollow` needs to know
79
+ * how deep inside the edge a fragment sits. The four boundaries are where they were: a hollow glyph
80
+ * is the filled one with its middle taken out, so switching one series to outlines leaves both
81
+ * series covering the same footprint.
82
+ *
83
+ * Picking reads the filled footprint whatever `u_hollow` says. A pointer aimed at the center of a
84
+ * ring is aimed at that geom, and a hit that fell through the hole would land on whatever sits
85
+ * behind it.
86
+ */
87
+ export const POINT_FRAGMENT = `#version 300 es
88
+ precision highp float;
89
+
90
+ in vec4 v_color;
91
+ in vec4 v_pick;
92
+ in float v_band;
93
+
94
+ uniform int u_shape;
95
+ /** Draws the glyph as an outline v_band deep, with the page showing through the middle. */
96
+ uniform bool u_hollow;
97
+ /** Picking writes the address instead of the fill. */
98
+ uniform bool u_picking;
99
+
100
+ out vec4 fragColor;
101
+
102
+ void main() {
103
+ // Sprite coordinates run 0 to 1 with y down; the glyphs want -1 to 1 with y up.
104
+ vec2 p = vec2(gl_PointCoord.x, 1.0 - gl_PointCoord.y) * 2.0 - 1.0;
105
+ float d;
106
+
107
+ if (u_shape == 1) {
108
+ d = max(abs(p.x), abs(p.y)) - 1.0;
109
+ } else if (u_shape == 2) {
110
+ /* Triangle: two half-planes from the apex at (0, 1) to the base corners, and the base itself.
111
+ Divided by the edge normal's length so the result is a distance and not a half-plane test,
112
+ which is what makes the outline the same width down all three sides. */
113
+ d = max((2.0 * abs(p.x) + p.y - 1.0) * 0.4472136, -1.0 - p.y);
114
+ } else if (u_shape == 3) {
115
+ d = (abs(p.x) + abs(p.y) - 1.0) * 0.7071068;
116
+ } else {
117
+ d = length(p) - 1.0;
118
+ }
119
+
120
+ if (d > 0.0) discard;
121
+ if (u_hollow && !u_picking && d < -v_band) discard;
122
+ fragColor = u_picking ? v_pick : v_color;
123
+ }
124
+ `;
125
+ /**
126
+ * The cube's vertex program, which is the point program under a camera.
127
+ *
128
+ * The 2D path maps offsets to pixels with two uniforms and writes a flat z. A cube needs the whole
129
+ * model-view-projection product, so it takes a matrix and leaves the other path alone: the frame
130
+ * numbers measured against the flat program stand as they were measured.
131
+ *
132
+ * The third coordinate arrives as its own attribute beside the interleaved pair, so a caller packs
133
+ * x and y the way it already does and adds one float a geom for depth.
134
+ *
135
+ * Geoms scale with distance, which is the first of the two depth cues the design language asks for.
136
+ * The projection divides by view depth and the sprite is divided by the same number, so a geom that
137
+ * moves away shrinks the way the geometry around it does. See the ADR "A third position scale is
138
+ * permitted where the reader can rotate".
139
+ */
140
+ export const CUBE_VERTEX = `#version 300 es
141
+ precision highp float;
142
+
143
+ /** Offset from the layer's center on the floor plane, in data units. */
144
+ in vec2 a_offset;
145
+ /** Offset from the layer's center on the third scale, in data units. */
146
+ in float a_depth;
147
+ in vec4 a_color;
148
+ in vec4 a_pick;
149
+ in float a_size;
150
+
151
+ /** Model, view and projection, multiplied on the CPU where it changes once a frame. */
152
+ uniform mat4 u_mvp;
153
+ /** Geom diameter in CSS pixels, and the ratio that turns it into device pixels. */
154
+ uniform float u_size;
155
+ uniform float u_dpr;
156
+ uniform bool u_flatSize;
157
+ /** View depth at which a geom draws its stated diameter. Geoms either side of it scale around it. */
158
+ uniform float u_depthRef;
159
+ uniform vec4 u_flat;
160
+ uniform bool u_flatColor;
161
+
162
+ /** Outline width of a hollow glyph, in CSS pixels. */
163
+ uniform float u_outline;
164
+
165
+ out vec4 v_color;
166
+ out vec4 v_pick;
167
+ out float v_band;
168
+
169
+ ${BAND_FN}
170
+
171
+ void main() {
172
+ v_color = u_flatColor ? u_flat : a_color;
173
+ v_pick = a_pick;
174
+
175
+ gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);
176
+
177
+ float diameter = u_flatSize ? u_size : a_size;
178
+ // A geom behind the eye has no size worth computing, and a divide by nought writes a NaN.
179
+ float depth = max(gl_Position.w, 0.001);
180
+ gl_PointSize = max(1.0, diameter * u_dpr * u_depthRef / depth);
181
+ /* A geom that moved away shrinks, and its outline shrinks with it, so a receding hollow cloud
182
+ stays hollow instead of closing into dots. */
183
+ v_band = band(u_outline, u_dpr, gl_PointSize);
184
+ }
185
+ `;
186
+ /**
187
+ * The mesh program: triangles with a light on them.
188
+ *
189
+ * A relief and a structure read as objects or they read as nothing, and what makes a projected
190
+ * object an object is shading. The light is fixed in the world instead of to the camera, so a
191
+ * reader turning the figure watches the light cross it, which says as much about the shape as the
192
+ * parallax does.
193
+ *
194
+ * Positions arrive the way a cube's points do, as offsets on the pair plus one on the third scale,
195
+ * so one camera serves both programs. The normals come off the CPU, averaged over the faces each
196
+ * vertex belongs to.
197
+ */
198
+ export const MESH_VERTEX = `#version 300 es
199
+ precision highp float;
200
+
201
+ in vec2 a_offset;
202
+ in float a_depth;
203
+ in vec3 a_normal;
204
+ in vec4 a_color;
205
+
206
+ uniform mat4 u_mvp;
207
+ /** Turns a normal in the data's axes into one in the world, past the model's own scaling. */
208
+ uniform mat3 u_normalMatrix;
209
+
210
+ out vec4 v_color;
211
+ out vec3 v_normal;
212
+
213
+ void main() {
214
+ v_color = a_color;
215
+ v_normal = normalize(u_normalMatrix * a_normal);
216
+ gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);
217
+ }
218
+ `;
219
+ export const MESH_FRAGMENT = `#version 300 es
220
+ precision highp float;
221
+
222
+ in vec4 v_color;
223
+ in vec3 v_normal;
224
+
225
+ uniform vec3 u_light;
226
+ uniform float u_ambient;
227
+
228
+ out vec4 fragColor;
229
+
230
+ void main() {
231
+ // Absolute, so a relief seen from beneath is lit instead of black: both faces are the same surface.
232
+ float lambert = abs(dot(normalize(v_normal), normalize(u_light)));
233
+ fragColor = vec4(v_color.rgb * (u_ambient + (1.0 - u_ambient) * lambert), v_color.a);
234
+ }
235
+ `;
236
+ /**
237
+ * The line program. It draws segments under the cube's camera as quads a set number of pixels wide.
238
+ *
239
+ * Each segment is six vertices with its far end and a corner code. The vertex stage widens it on screen.
240
+ * At nought width the triangles draw in place, as a pane.
241
+ */
242
+ export const LINE_VERTEX = `#version 300 es
243
+ precision highp float;
244
+
245
+ in vec2 a_offset;
246
+ in float a_depth;
247
+ /** The segment's other end, as offsets from the layer's center. */
248
+ in vec3 a_other;
249
+ /** Which side of the segment the vertex stands, minus one or one, and whether it is the far end. */
250
+ in vec2 a_corner;
251
+
252
+ uniform mat4 u_mvp;
253
+ /** The plot area in device pixels. */
254
+ uniform vec2 u_viewport;
255
+ /** Line width in device pixels. */
256
+ uniform float u_width;
257
+
258
+ void main() {
259
+ vec4 self = u_mvp * vec4(a_offset, a_depth, 1.0);
260
+ vec4 other = u_mvp * vec4(a_other, 1.0);
261
+ float w = max(self.w, 0.001);
262
+ vec2 half_viewport = 0.5 * u_viewport;
263
+ vec2 here = self.xy / w * half_viewport;
264
+ vec2 there = other.xy / max(other.w, 0.001) * half_viewport;
265
+
266
+ vec2 run = a_corner.y > 0.5 ? here - there : there - here;
267
+ float span = length(run);
268
+ vec2 dir = span > 0.0 ? run / span : vec2(1.0, 0.0);
269
+ vec2 shift = vec2(-dir.y, dir.x) * a_corner.x * 0.5 * u_width;
270
+
271
+ gl_Position = vec4(self.xy + shift / half_viewport * w, self.z, self.w);
272
+ }
273
+ `;
274
+ export const LINE_FRAGMENT = `#version 300 es
275
+ precision highp float;
276
+
277
+ uniform vec4 u_color;
278
+
279
+ out vec4 fragColor;
280
+
281
+ void main() {
282
+ fragColor = u_color;
283
+ }
284
+ `;
285
+ /**
286
+ * The raymarched program, for the two kinds that read a field through its depth.
287
+ *
288
+ * The geometry is the box itself: the front faces are drawn, each fragment is where a ray enters,
289
+ * and the ray walks to where it leaves. `isosurface` stops at the first crossing of the level and
290
+ * shades it with the gradient, which is the normal of the shell it just hit. `volume` keeps walking
291
+ * and composites front to back, which is what makes a field readable through itself.
292
+ *
293
+ * The field is a byte a cell in a 3D texture, and the transfer function is a 256-wide strip of the
294
+ * chart's own magnitude map. Byte nought is the cell nothing landed in and it stays clear, so a
295
+ * sparse field reads as sparse instead of as a block of the low color.
296
+ *
297
+ * See the ADR "A third position scale is permitted where the reader can rotate".
298
+ */
299
+ export const VOLUME_VERTEX = `#version 300 es
300
+ precision highp float;
301
+
302
+ in vec2 a_offset;
303
+ in float a_depth;
304
+
305
+ uniform mat4 u_mvp;
306
+ /** The model alone, so the fragment stage has the ray's start in the unit box. */
307
+ uniform mat4 u_model;
308
+
309
+ out vec3 v_entry;
310
+
311
+ void main() {
312
+ vec4 world = u_model * vec4(a_offset, a_depth, 1.0);
313
+ v_entry = world.xyz;
314
+ gl_Position = u_mvp * vec4(a_offset, a_depth, 1.0);
315
+ }
316
+ `;
317
+ export const VOLUME_FRAGMENT = `#version 300 es
318
+ precision highp float;
319
+ precision highp sampler3D;
320
+
321
+ in vec3 v_entry;
322
+
323
+ uniform sampler3D u_field;
324
+ /** The magnitude map as a strip, so the ray reads the chart's own colors. */
325
+ uniform sampler2D u_ramp;
326
+ /** Where the reader is standing, in the unit box. */
327
+ uniform vec3 u_eye;
328
+ /** Steps a ray takes across the box. */
329
+ uniform int u_steps;
330
+ /** Set for an isosurface, clear for a volume. */
331
+ uniform bool u_iso;
332
+ /** The level an isosurface stands at, over nought to one. */
333
+ uniform float u_level;
334
+ /** How much of the field one step of a volume ray absorbs. */
335
+ uniform float u_density;
336
+ uniform vec3 u_light;
337
+ uniform float u_ambient;
338
+
339
+ out vec4 fragColor;
340
+
341
+ /** Where a ray leaves the box, as a distance along it. */
342
+ float exitAt(vec3 from, vec3 dir) {
343
+ vec3 far = (sign(dir) - from) / max(abs(dir), vec3(1e-6)) * sign(dir);
344
+ return min(min(far.x, far.y), far.z);
345
+ }
346
+
347
+ /*
348
+ The world draws the third scale upward, so world y is the data's z and world z is the data's y.
349
+ The field is packed in the data's own axis order, and the lookup is where the swap is undone.
350
+ */
351
+ float sampleAt(vec3 p) {
352
+ return texture(u_field, vec3(p.x, p.z, p.y) * 0.5 + 0.5).r;
353
+ }
354
+
355
+ /** The field's gradient, by central differences, which is the shell's own normal. */
356
+ vec3 gradientAt(vec3 p, float step) {
357
+ vec2 d = vec2(step, 0.0);
358
+ return normalize(vec3(
359
+ sampleAt(p + d.xyy) - sampleAt(p - d.xyy),
360
+ sampleAt(p + d.yxy) - sampleAt(p - d.yxy),
361
+ sampleAt(p + d.yyx) - sampleAt(p - d.yyx)
362
+ ) + vec3(1e-6));
363
+ }
364
+
365
+ void main() {
366
+ vec3 dir = normalize(v_entry - u_eye);
367
+ float span = exitAt(v_entry, dir);
368
+ float stride = span / float(u_steps);
369
+
370
+ vec3 p = v_entry;
371
+ vec4 out_color = vec4(0.0);
372
+
373
+ for (int step = 0; step < 512; step += 1) {
374
+ if (step >= u_steps) break;
375
+
376
+ float value = sampleAt(p);
377
+ if (value > 0.0) {
378
+ if (u_iso) {
379
+ if (value >= u_level) {
380
+ vec3 normal = gradientAt(p, stride);
381
+ float lambert = abs(dot(normal, normalize(u_light)));
382
+ vec3 tint = texture(u_ramp, vec2(value, 0.5)).rgb;
383
+ fragColor = vec4(tint * (u_ambient + (1.0 - u_ambient) * lambert), 1.0);
384
+ return;
385
+ }
386
+ } else {
387
+ vec4 sampled = texture(u_ramp, vec2(value, 0.5));
388
+ float alpha = value * u_density;
389
+ // Front to back: what is already written blocks what is behind it.
390
+ out_color.rgb += (1.0 - out_color.a) * sampled.rgb * alpha;
391
+ out_color.a += (1.0 - out_color.a) * alpha;
392
+ if (out_color.a > 0.98) break;
393
+ }
394
+ }
395
+
396
+ p += dir * stride;
397
+ }
398
+
399
+ if (u_iso && out_color.a == 0.0) discard;
400
+ if (out_color.a <= 0.001) discard;
401
+ fragColor = out_color;
402
+ }
403
+ `;
404
+ /** Shape codes, in the order the spec's `PointShape` union lists them. */
405
+ export const SHAPE_CODE = { circle: 0, square: 1, triangle: 2, diamond: 3 };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The page's one GL canvas, and the renderer over it.
3
+ *
4
+ * Created on first use and kept for the document's life, because the context is the scarce thing:
5
+ * dropping and remaking one per chart is what the shared context exists to avoid. A caller that
6
+ * wants an isolated renderer mounts a `VizGlProvider`, over a canvas of its own through `host`.
7
+ *
8
+ * The canvas is fixed to the viewport and takes no pointer events, so it paints behind the charts'
9
+ * own SVG chrome and never intercepts a hover.
10
+ */
11
+ import { SharedRenderer, type Host, type RendererOptions } from "./renderer.js";
12
+ /** A canvas element read as a host: its rectangle in page coordinates, and the display's ratio. */
13
+ export declare const hostFor: (canvas: HTMLCanvasElement) => Host;
14
+ /**
15
+ * The page's renderer, built on first ask.
16
+ *
17
+ * Returns null where there is no document, which is the headless case: a caller reads that as the
18
+ * GPU tier being unavailable and draws its SVG treatment.
19
+ */
20
+ export declare function glSurface(options?: RendererOptions): SharedRenderer | null;
21
+ /** The page's renderer where something already built it, and null otherwise. Builds nothing. */
22
+ export declare const existingGlSurface: () => SharedRenderer | null;
23
+ /** Drops the page renderer and its canvas. For a test, or a host tearing down its own root. */
24
+ export declare function releaseGlSurface(): void;
25
+ /**
26
+ * Redraws every layer.
27
+ *
28
+ * The layers' rectangles are read fresh each frame, so a scroll or a resize needs nothing but a
29
+ * new frame. A host binds this to whatever moves its charts.
30
+ */
31
+ export declare function refreshGlSurface(): void;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The page's one GL canvas, and the renderer over it.
3
+ *
4
+ * Created on first use and kept for the document's life, because the context is the scarce thing:
5
+ * dropping and remaking one per chart is what the shared context exists to avoid. A caller that
6
+ * wants an isolated renderer mounts a `VizGlProvider`, over a canvas of its own through `host`.
7
+ *
8
+ * The canvas is fixed to the viewport and takes no pointer events, so it paints behind the charts'
9
+ * own SVG chrome and never intercepts a hover.
10
+ */
11
+ import { SharedRenderer } from "./renderer.js";
12
+ let renderer = null;
13
+ let canvas = null;
14
+ const CANVAS_STYLE = {
15
+ position: "fixed",
16
+ inset: "0",
17
+ width: "100%",
18
+ height: "100%",
19
+ pointerEvents: "none",
20
+ // Behind the chart chrome, above the page's own ground.
21
+ zIndex: "0",
22
+ };
23
+ function surfaceCanvas() {
24
+ if (canvas)
25
+ return canvas;
26
+ const element = document.createElement("canvas");
27
+ element.dataset.tsLibViz = "gl-surface";
28
+ Object.assign(element.style, CANVAS_STYLE);
29
+ document.body.appendChild(element);
30
+ canvas = element;
31
+ return element;
32
+ }
33
+ /** A canvas element read as a host: its rectangle in page coordinates, and the display's ratio. */
34
+ export const hostFor = (canvas) => ({
35
+ canvas,
36
+ rect: () => {
37
+ const box = canvas.getBoundingClientRect();
38
+ return { left: box.left, top: box.top, width: box.width, height: box.height };
39
+ },
40
+ dpr: () => window.devicePixelRatio || 1,
41
+ });
42
+ /**
43
+ * The page's renderer, built on first ask.
44
+ *
45
+ * Returns null where there is no document, which is the headless case: a caller reads that as the
46
+ * GPU tier being unavailable and draws its SVG treatment.
47
+ */
48
+ export function glSurface(options = {}) {
49
+ if (typeof document === "undefined")
50
+ return null;
51
+ if (renderer)
52
+ return renderer.available ? renderer : null;
53
+ renderer = new SharedRenderer(hostFor(surfaceCanvas()), options);
54
+ return renderer.available ? renderer : null;
55
+ }
56
+ /** The page's renderer where something already built it, and null otherwise. Builds nothing. */
57
+ export const existingGlSurface = () => (renderer?.available ? renderer : null);
58
+ /** Drops the page renderer and its canvas. For a test, or a host tearing down its own root. */
59
+ export function releaseGlSurface() {
60
+ renderer?.dispose();
61
+ renderer = null;
62
+ canvas?.remove();
63
+ canvas = null;
64
+ }
65
+ /**
66
+ * Redraws every layer.
67
+ *
68
+ * The layers' rectangles are read fresh each frame, so a scroll or a resize needs nothing but a
69
+ * new frame. A host binds this to whatever moves its charts.
70
+ */
71
+ export function refreshGlSurface() {
72
+ renderer?.schedule();
73
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The `/react` surface: `Viz`, the GPU provider, the export path and the theme hooks.
3
+ *
4
+ * `Viz` draws a chart from its spec. The frame, the geoms and the legends it draws through stay
5
+ * inside the package, and the arithmetic behind them is in `/core`.
6
+ */
7
+ export { Viz, type VizProps } from "./Viz.js";
8
+ export { exportPng, exportSvg, type PngOptions, type SvgOptions } from "./export.js";
9
+ export { resolveTheme, useVizTheme, watchTheme } from "./theme.js";
10
+ export type { ToolbarItem, ToolbarOptions, ToolbarView } from "./Toolbar.js";
11
+ export { MARK_RADIUS, roundedTop } from "./geoms/Bars.js";
12
+ export { hostFor, refreshGlSurface, releaseGlSurface, useGlRenderer, VizGlProvider, type FrameStats, type GlRenderer, type Host, type Rect, type Times, type VizGlProviderProps, } from "./gl/index.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The `/react` surface: `Viz`, the GPU provider, the export path and the theme hooks.
3
+ *
4
+ * `Viz` draws a chart from its spec. The frame, the geoms and the legends it draws through stay
5
+ * inside the package, and the arithmetic behind them is in `/core`.
6
+ */
7
+ export { Viz } from "./Viz.js";
8
+ export { exportPng, exportSvg } from "./export.js";
9
+ export { resolveTheme, useVizTheme, watchTheme } from "./theme.js";
10
+ export { MARK_RADIUS, roundedTop } from "./geoms/Bars.js";
11
+ export { hostFor, refreshGlSurface, releaseGlSurface, useGlRenderer, VizGlProvider, } from "./gl/index.js";