@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,377 @@
1
+ /**
2
+ * One WebGL2 context for the page, drawing every chart that asked for the GPU.
3
+ *
4
+ * A browser allows something between eight and sixteen contexts and drops the oldest past that, so
5
+ * a dashboard of thirty charts cannot have one each: plotly's own documentation puts its ceiling at
6
+ * four to eight GL figures a page for this reason. One context draws them all, each into its own
7
+ * scissored slice of a canvas that covers the viewport.
8
+ *
9
+ * The loop is the renderer's, outside React. A layer's buffers are uploaded when its data changes
10
+ * and nothing else, so a zoom moves two uniforms and a hover reads one pixel. React mounts the
11
+ * canvas once and stays out of the frame path.
12
+ */
13
+ import { type Packed, type Rect } from "./encode.js";
14
+ import { type Orbit } from "../../core/camera.js";
15
+ import { type PointShape } from "../../core/geom-types.js";
16
+ /** What a chart hands the renderer, and what it may change between frames. */
17
+ export interface GlLayerInput {
18
+ /** Positions, centered, as `packPositions` returns them. */
19
+ positions: Packed;
20
+ /**
21
+ * One RGBA byte quadruple per geom.
22
+ *
23
+ * Absent means the layer draws in `color` alone, which is four bytes instead of four a geom: at a
24
+ * hundred million geoms the difference is four hundred megabytes of buffer nobody needed.
25
+ */
26
+ colors?: Uint8Array;
27
+ /** The layer's one color, as four channels from nought to one. Read where `colors` is absent. */
28
+ color?: readonly [number, number, number, number];
29
+ /** Geom diameter in CSS pixels. Read where `sizes` is absent. */
30
+ size: number;
31
+ /**
32
+ * One diameter a geom, in CSS pixels, where the size channel binds a column.
33
+ *
34
+ * Absent means the layer draws at `size` alone, which is one uniform instead of four bytes a
35
+ * geom: at ten million the difference is forty megabytes of buffer a fixed-diameter chart never
36
+ * needed.
37
+ */
38
+ sizes?: Float32Array;
39
+ shape?: PointShape;
40
+ /**
41
+ * Draws each glyph as an outline with the page showing through it.
42
+ *
43
+ * The footprint is the filled glyph's, so a hollow layer over a filled one covers the same
44
+ * ground. Picking stays on the footprint too: a pointer aimed at the middle of a ring is aimed
45
+ * at that geom.
46
+ */
47
+ hollow?: boolean;
48
+ /**
49
+ * The third position scale, which turns the layer into a cube.
50
+ *
51
+ * Present means the layer draws under a camera the reader turns, on its own program: the flat
52
+ * program's two-uniform arithmetic stays as it was, and so do the frame numbers measured against
53
+ * it. Absent draws the flat layer this renderer has always drawn.
54
+ */
55
+ depth?: DepthInput;
56
+ /**
57
+ * Triangles over the layer's vertices, which turns the cube's cloud into a surface.
58
+ *
59
+ * Needs `depth`, since a triangle wants three coordinates. Present means the layer draws through
60
+ * the mesh program with a light on it, and the geoms, their diameter and their glyph go unread.
61
+ */
62
+ mesh?: MeshInput;
63
+ /**
64
+ * A scalar field read along the ray, which turns the box into a volume.
65
+ *
66
+ * Needs `depth` and a `mesh` holding the box's own faces, since the box is the surface a ray
67
+ * starts on. Present means the layer draws through the raymarching program and its colors come
68
+ * off the transfer strip instead of off a color a vertex.
69
+ */
70
+ volume?: VolumeInput;
71
+ /**
72
+ * Segments drawn as quads, which turns the cube's layer into rules under the camera.
73
+ *
74
+ * Needs `depth`. Present means the layer draws in `color` through the line program, ahead of the
75
+ * geoms, and writes no depth.
76
+ */
77
+ lines?: LineInput;
78
+ /** The plot area's domain, so the GPU and the axis agree. */
79
+ xDomain: [number, number];
80
+ yDomain: [number, number];
81
+ /** Where the plot area sits on the page, read fresh each frame by the callback below. */
82
+ rect: () => Rect | null;
83
+ /**
84
+ * Whether every geom in the layer is opaque.
85
+ *
86
+ * Blending is a read-modify-write per fragment, and a layer whose colors all carry full alpha
87
+ * gains nothing from it. Declared instead of derived, because deriving it means scanning ten
88
+ * million color bytes on every upload to answer a question the caller already knows.
89
+ */
90
+ opaque?: boolean;
91
+ /**
92
+ * Whether the layer answers a hover.
93
+ *
94
+ * The picking pass needs an id per geom, which is another four bytes each: forty megabytes at
95
+ * ten million, uploaded and never read by a chart nobody hovers. Off unless a caller asks.
96
+ */
97
+ pickable?: boolean;
98
+ }
99
+ /** What a cube layer adds: a third coordinate a geom, its domain, and where the reader stands. */
100
+ export interface DepthInput {
101
+ /** One offset a geom from `center`, as `packDepth` returns them. */
102
+ offsets: Float32Array;
103
+ center: number;
104
+ domain: [number, number];
105
+ orbit: Orbit;
106
+ }
107
+ /** What a surface adds to a cube layer: a normal a vertex, and the faces over them. */
108
+ export interface MeshInput {
109
+ /** Interleaved unit normals in the data's own axes, one a vertex. */
110
+ normals: Float32Array;
111
+ /** Three vertex indices a triangle. */
112
+ indices: Uint32Array;
113
+ }
114
+ /** What a raymarched kind carries: the field, the strip it reads color from, and how to read it. */
115
+ export interface VolumeInput {
116
+ /** One byte a cell, x fastest, as `field3d` packs them. Nought is a cell with no reading. */
117
+ field: Uint8Array;
118
+ dims: [number, number, number];
119
+ /** 256 RGBA bytes: the chart's magnitude map, sampled. */
120
+ ramp: Uint8Array;
121
+ /** Set to stop at the first crossing of `level`; clear to integrate along the ray. */
122
+ iso: boolean;
123
+ /** Where the shell stands, over nought to one. */
124
+ level: number;
125
+ /** How much of the field one step absorbs, for the integrating read. */
126
+ density: number;
127
+ steps: number;
128
+ }
129
+ /** What a line layer adds: each vertex's far end and corner, and the width. */
130
+ export interface LineInput {
131
+ /** The far end of each vertex's segment, as x, y, z offsets from the layer's centers. */
132
+ other: Float32Array;
133
+ /** The side of the segment, minus one or one, then one at the far end. Two floats a vertex. */
134
+ corners: Float32Array;
135
+ /** Line width in CSS pixels. At nought the triangles draw where their vertices stand and fill a pane. */
136
+ width: number;
137
+ }
138
+ export interface LayerHandle {
139
+ /** Replace what the layer draws. Uploads on the next frame. */
140
+ update(next: Partial<GlLayerInput>): void;
141
+ /** The geom under a point in page coordinates, or null. */
142
+ pick(clientX: number, clientY: number): number | null;
143
+ release(): void;
144
+ }
145
+ /** Everything the renderer needs from a host, so a test can stand in for the page. */
146
+ export interface Host {
147
+ canvas: HTMLCanvasElement;
148
+ /** The canvas rectangle in page coordinates. */
149
+ rect(): Rect;
150
+ dpr(): number;
151
+ }
152
+ export interface RendererOptions {
153
+ /**
154
+ * Time each frame.
155
+ *
156
+ * A draw call returns once the commands are submitted, so a wall clock around it measures how
157
+ * fast the CPU can ask. What the budget is about is how long the GPU took, and the two differ by
158
+ * more than an order of magnitude at ten million geoms. On means the GPU is timed as well, which
159
+ * costs a query per frame, so it stays off unless asked for.
160
+ */
161
+ measure?: boolean;
162
+ /**
163
+ * The host drives frames itself.
164
+ *
165
+ * `schedule` draws nothing under this, and `drawNow` is the only thing that puts a frame up. For
166
+ * a host with a loop of its own to fit this into, and for a harness: a browser that throttles
167
+ * frames delivers them in bursts, which lands an extra draw between the ones a benchmark asked
168
+ * for and leaves the distribution bimodal.
169
+ */
170
+ driven?: boolean;
171
+ }
172
+ /** Frame count, and the 50th, 95th and slowest frame times in milliseconds. */
173
+ export interface Times {
174
+ frames: number;
175
+ p50: number;
176
+ p95: number;
177
+ max: number;
178
+ }
179
+ /**
180
+ * What the frame budget is read against.
181
+ *
182
+ * `p50`, `p95` and `max` are the submission cost, which is the caller's own stack. `gpu` is what the
183
+ * hardware reported through `EXT_disjoint_timer_query_webgl2`, and that is the number the 8.3ms and
184
+ * 16.7ms targets mean. It is null where the extension is absent or where a disjoint event spoiled
185
+ * the readings, since a made-up number is worse than none.
186
+ */
187
+ export interface FrameStats extends Times {
188
+ gpu: Times | null;
189
+ /** Set where the GPU clock was asked for and could not answer. */
190
+ gpuProblem: string | null;
191
+ }
192
+ export declare class SharedRenderer {
193
+ private host;
194
+ private options;
195
+ private gl;
196
+ private program;
197
+ private uniforms;
198
+ /** The cube's program, built beside the flat one and used by the layers that carry a camera. */
199
+ private cubeProgram;
200
+ private cubeUniforms;
201
+ /** The surface's program, which is the cube's with a light and triangles in place of sprites. */
202
+ private meshProgram;
203
+ private meshUniforms;
204
+ /** The raymarching program, which reads a field through the box instead of drawing its surface. */
205
+ private volumeProgram;
206
+ private volumeUniforms;
207
+ /** The line program, for rules drawn under the cube's camera. */
208
+ private lineProgram;
209
+ private lineUniforms;
210
+ /** Vertex attribute slots the context has, read once and used to clear the ones a layer skips. */
211
+ private attribCount;
212
+ private layers;
213
+ private nextId;
214
+ private frame;
215
+ private lost;
216
+ /** Set once the owner disposed the renderer or the driver refused a program. Nothing is acquired after. */
217
+ private retired;
218
+ /** The one-pixel framebuffer a picking pass draws into. Built on the first pick. */
219
+ private picking;
220
+ private times;
221
+ private gpuTimes;
222
+ private timer;
223
+ private inFlight;
224
+ private gpuProblem;
225
+ /** Borrowers holding the frame clock. */
226
+ private clockLent;
227
+ /**
228
+ * The boxes the last frame painted, so this one can clear what it is no longer drawing.
229
+ *
230
+ * A frame clears the rectangles its layers own and nothing else, which is what lets a borrower
231
+ * keep the rest of the canvas. The cost is that a released layer leaves its pixels behind: the
232
+ * canvas is fixed to the viewport and outlives any chart on it, so a page that swapped one figure
233
+ * for another would show the first one's geoms under the second's.
234
+ */
235
+ private painted;
236
+ /** Whether the host drove the clock before any of them asked for it. */
237
+ private readonly ownClock;
238
+ constructor(host: Host, options?: RendererOptions);
239
+ /**
240
+ * Whether the GPU path is available at all.
241
+ *
242
+ * A caller that gets false draws its SVG treatment instead. A page with no WebGL2 is a real
243
+ * state, and a chart that answers with an empty canvas reads as a broken chart.
244
+ */
245
+ get available(): boolean;
246
+ /** Layers this renderer is holding, so a borrower can see whether the canvas is already in use. */
247
+ layerCount(): number;
248
+ /**
249
+ * Hands the frame clock to whoever borrowed the context, and takes it back on release.
250
+ *
251
+ * Two engines on one canvas need one clock or the frame is a race. cosmos clears the whole canvas
252
+ * every frame it draws, and this renderer clears the rectangles it owns and draws into them, so
253
+ * the charts survive only where they are drawn after the clear that would have taken them. On its
254
+ * own clock this renderer draws when something changes, which on a page with an animating graph
255
+ * means a chart is drawn once and cleared sixteen milliseconds later.
256
+ *
257
+ * So the borrower drives: it calls `drawNow` from its own frame callback, and the charts land in
258
+ * the same frame, after it. Released when the borrower stops drawing, since a clock nobody drives
259
+ * is a chart that never updates. Counted, so two borrowers cannot hand it back twice.
260
+ *
261
+ * See the ADR "The graph surface takes cosmos on the package's own context".
262
+ */
263
+ lendClock(): () => void;
264
+ /**
265
+ * The context this renderer owns, for a second engine to draw into.
266
+ *
267
+ * One shared WebGL2 context is the package's structural advantage, and a page holding charts and
268
+ * a physics graph would spend two of the eight to sixteen a browser allows if the graph made its
269
+ * own. Lending is the answer: the borrower attaches to this and does not destroy it, which is the
270
+ * path both luma and cosmos already support.
271
+ *
272
+ * Raw and not wrapped, so nothing in `/react` imports a second GL library. Whoever borrows it
273
+ * brings its own adapter. See the ADR "The graph surface takes cosmos on the package's own
274
+ * context".
275
+ */
276
+ context(): WebGL2RenderingContext | null;
277
+ add(input: GlLayerInput): LayerHandle;
278
+ /** Draws on the next frame. Repeated calls in one frame collapse into one draw. */
279
+ schedule(): void;
280
+ /**
281
+ * Reads one pixel back, which waits for the GPU to have finished.
282
+ *
283
+ * A hard barrier for a harness timing a run of frames. `finish` is documented as waiting for
284
+ * completion and returns early on the Metal backend, while a read of the framebuffer cannot
285
+ * answer until the work that fills it has run.
286
+ */
287
+ readOnePixel(): void;
288
+ /**
289
+ * Draws a frame and reports whether anything landed on the canvas.
290
+ *
291
+ * A benchmark over a canvas that drew nothing reads as the fastest renderer ever written, and
292
+ * that is the shape of a real failure: a hidden page reporting a viewport of nought, a layer
293
+ * whose rectangle scissored away, a context that never came back after a loss. Sampling the
294
+ * canvas answers it.
295
+ *
296
+ * The draw happens here because the context holds no drawing buffer between tasks: reading a
297
+ * frame drawn earlier answers empty whether or not that frame worked. `readPixels` stalls the
298
+ * pipeline, so this is for a harness and not for a frame loop.
299
+ */
300
+ drewPixels(samples?: number): boolean;
301
+ /**
302
+ * Draws now, on the caller's stack.
303
+ *
304
+ * `schedule` waits for a frame, and a page the browser calls hidden gets no frames at all, so a
305
+ * benchmark or an export asking for a frame there would wait forever. This is also what a caller
306
+ * wants before reading pixels back: the draw has happened by the time it returns.
307
+ */
308
+ drawNow(): void;
309
+ dispose(): void;
310
+ /** Deletes the five programs and forgets them. */
311
+ private dropPrograms;
312
+ private onLost;
313
+ private onRestored;
314
+ private acquire;
315
+ private build;
316
+ private free;
317
+ private upload;
318
+ /**
319
+ * The canvas at the size its host asks for, and the rectangle that size was read from.
320
+ *
321
+ * The size is a shared resource the same way the context is. A borrower that resizes the canvas
322
+ * to suit itself, which is what luma's `autoResize` does, will fight a renderer that resizes it
323
+ * back every frame: the two write different numbers, the borrower recomputes its own screen from
324
+ * the change, and the picture warps once a frame. So while the clock is lent the borrower owns the
325
+ * size and this reads what is there.
326
+ */
327
+ private sizeCanvas;
328
+ /**
329
+ * Device pixels a CSS pixel, as the drawing buffer actually stands.
330
+ *
331
+ * The host states one, and while the canvas belongs to a borrower the buffer may be another size
332
+ * entirely. Every scissor and viewport is computed against the buffer, so it is read off the
333
+ * buffer.
334
+ */
335
+ private dprNow;
336
+ /**
337
+ * How long the recent frames took.
338
+ *
339
+ * Null before anything has been drawn. The budget in the design doc is 60fps at ten million
340
+ * client-resident geoms, which is 16.7ms a frame, and this is the number that answers it.
341
+ */
342
+ stats(): FrameStats | null;
343
+ resetStats(): void;
344
+ /**
345
+ * Turns the per-frame finish on or off.
346
+ *
347
+ * A benchmark story wants it on for as long as it is reading; a chart in front of somebody wants
348
+ * it off, since a finish stalls the pipeline. Settable because the surface is shared: whichever
349
+ * chart mounts first builds the renderer, and a story measuring later cannot re-make it.
350
+ */
351
+ measure(on: boolean): void;
352
+ private draw;
353
+ /** The GPU clock, asked for once and remembered as absent where it is. */
354
+ private gpuClock;
355
+ private beginGpuTime;
356
+ private endGpuTime;
357
+ /**
358
+ * Reads whichever queries the GPU has finished with.
359
+ *
360
+ * A query answers a frame or two after the one it timed, so the readings arrive late and the
361
+ * window fills anyway. A disjoint event throws away everything in flight, since the timings
362
+ * either side of it are not comparable.
363
+ */
364
+ private collectGpuTimes;
365
+ /** Waits for the queries in flight, so a run's last frames are in the numbers. */
366
+ drainGpuTimes(timeoutMs?: number): Promise<void>;
367
+ private drawLayer;
368
+ /**
369
+ * The geom under the pointer, read off a picking pass.
370
+ *
371
+ * The pass draws the layer's ids into a cleared, single-sampled pixel of its own. The visible
372
+ * frame is untouched.
373
+ */
374
+ private pick;
375
+ /** The one-pixel color and depth target a picking pass draws into, built once per context. */
376
+ private pickTarget;
377
+ }