@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,50 @@
1
+ /**
2
+ * Typed predicates.
3
+ *
4
+ * A filter is data. The same filter runs in a SQL compiler, a vectorized pass over columnar
5
+ * batches, and a toolbar chip. Chip copy stays with the app.
6
+ */
7
+ export type Predicate = {
8
+ kind: "text";
9
+ fields: string[];
10
+ needle: string;
11
+ } | {
12
+ kind: "range";
13
+ field: string;
14
+ lo: number | null;
15
+ hi: number | null;
16
+ } | {
17
+ kind: "in";
18
+ field: string;
19
+ values: string[];
20
+ } | {
21
+ kind: "eq";
22
+ field: string;
23
+ value: string | number;
24
+ negate?: boolean;
25
+ } | {
26
+ kind: "regex";
27
+ field: string;
28
+ pattern: string;
29
+ caseInsensitive?: boolean;
30
+ } | {
31
+ kind: "null";
32
+ field: string;
33
+ negate?: boolean;
34
+ } | {
35
+ kind: "time";
36
+ field: string;
37
+ from: number | null;
38
+ to: number | null;
39
+ } | {
40
+ kind: "and";
41
+ of: Predicate[];
42
+ } | {
43
+ kind: "or";
44
+ of: Predicate[];
45
+ } | {
46
+ kind: "not";
47
+ of: Predicate;
48
+ };
49
+ /** Leaf predicates. A chip row lists what is in force without walking the tree twice. */
50
+ export declare function leaves(predicates: Predicate[]): Predicate[];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Typed predicates.
3
+ *
4
+ * A filter is data. The same filter runs in a SQL compiler, a vectorized pass over columnar
5
+ * batches, and a toolbar chip. Chip copy stays with the app.
6
+ */
7
+ /** Leaf predicates. A chip row lists what is in force without walking the tree twice. */
8
+ export function leaves(predicates) {
9
+ const out = [];
10
+ const walk = (p) => {
11
+ if (p.kind === "and" || p.kind === "or")
12
+ p.of.forEach(walk);
13
+ else if (p.kind === "not")
14
+ walk(p.of);
15
+ else
16
+ out.push(p);
17
+ };
18
+ predicates.forEach(walk);
19
+ return out;
20
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Capability profiles -- what a given role may author.
3
+ *
4
+ * A profile is serializable and the same object gates three places. Kinds and aesthetics are
5
+ * allowlists, and setting groups are withheld by name. Absent means unrestricted.
6
+ */
7
+ import { type Aesthetic } from "./geom-table.js";
8
+ import type { ChartSpec, PlotKind } from "./spec.js";
9
+ /**
10
+ * The settings a profile can withhold.
11
+ *
12
+ * Grouped by the question a reader asks of the chart. Each spec field sits in one group or is the
13
+ * chart's content, which kinds and aesthetics gate.
14
+ */
15
+ export type SettingGroup =
16
+ /** A transform on a position scale: log, sqrt or pseudo-log. */
17
+ "log-scale"
18
+ /** What the position scales span and mark: limits, breaks, ticks, formats, labels, band order and size, and the coord. */
19
+ | "axis-range"
20
+ /** Rule width, tick length and side, label angle, title placement, type size, ink and grid. */
21
+ | "axis-chrome"
22
+ /** Notes and axis-end captions. */
23
+ | "annotations"
24
+ /** Fitted curves and smooths, with their confidence bands. */
25
+ | "fits"
26
+ /** Small-multiple grids. */
27
+ | "facets"
28
+ /** Geom size, width, opacity, color and glyph, and where geoms sharing a band sit. */
29
+ | "geom-style"
30
+ /** Direct labels on geoms, and the numbers written in cells. */
31
+ | "labels"
32
+ /** A second vertical scale. */
33
+ | "second-axis"
34
+ /** The figure's width and height, the panel's aspect, the data's ratio, and the sizing. */
35
+ | "figure-size"
36
+ /** The color and fill maps past their titles, and the palette a layer names. */
37
+ | "color-scale"
38
+ /** Where the legends draw, and which layers reach them. */
39
+ | "legend"
40
+ /** Panels beside the plot area, and rings outside a circular figure. */
41
+ | "side-panels"
42
+ /** What a layer computes: its aggregate, running total, statistic parameters, error bars and replicates. */
43
+ | "statistics"
44
+ /** Findings the author waived. A `wrong` finding passes the gate only through one. */
45
+ | "overrides";
46
+ /**
47
+ * A drawing surface a profile can withhold whole.
48
+ *
49
+ * `PlotKind` is the unit for a chart. A graph has no row in the grammar table and its gate is the
50
+ * surface.
51
+ */
52
+ export type SurfaceKind = "chart" | "graph";
53
+ export interface CapabilityProfile {
54
+ id: string;
55
+ label?: string;
56
+ /**
57
+ * Surfaces the role may author. Absent allows both.
58
+ *
59
+ * Separate from `kinds`. Withholding a chart kind still leaves the chart surface.
60
+ */
61
+ surfaces?: readonly SurfaceKind[];
62
+ /** Plot kinds the role may author. Absent allows each kind the package draws. */
63
+ kinds?: readonly PlotKind[];
64
+ /**
65
+ * Aesthetics the role may bind, per kind.
66
+ *
67
+ * Absent allows each one the kind's geom table row binds. A kind listed with a subset keeps its
68
+ * required aesthetics.
69
+ */
70
+ aesthetics?: Partial<Record<PlotKind, readonly Aesthetic[]>>;
71
+ /**
72
+ * Setting groups the role may not set. Absent withholds none.
73
+ *
74
+ * A group a later version adds is open under a profile saved before it.
75
+ */
76
+ withhold?: readonly SettingGroup[];
77
+ /** Caps on a spec's size. Absent means the package's own limits alone. */
78
+ limits?: {
79
+ layers?: number;
80
+ annotations?: number;
81
+ };
82
+ }
83
+ /** Where a spec fell outside the profile. A loader names the field. */
84
+ export interface Failure {
85
+ /** Dotted path into the spec, as in `layers[1].fit`. */
86
+ path: string;
87
+ reason: string;
88
+ }
89
+ export interface Verdict {
90
+ ok: boolean;
91
+ failures: Failure[];
92
+ }
93
+ export declare const allowsKind: (profile: CapabilityProfile, kind: PlotKind) => boolean;
94
+ /** Whether the role may author on this surface at all. */
95
+ export declare const allowsSurface: (profile: CapabilityProfile, surface: SurfaceKind) => boolean;
96
+ export declare const allowsSetting: (profile: CapabilityProfile, group: SettingGroup) => boolean;
97
+ /**
98
+ * Aesthetics a role may bind on a kind, required ones included.
99
+ *
100
+ * The kind's geom table row bounds the answer. A profile naming an aesthetic the kind lacks narrows
101
+ * to nothing.
102
+ */
103
+ export declare function allowedAesthetics(profile: CapabilityProfile, kind: PlotKind): Aesthetic[];
104
+ /**
105
+ * Whether a spec falls inside a profile.
106
+ *
107
+ * Each field is checked and each failure collected. The paths are what a loader prints.
108
+ */
109
+ export declare function validate(spec: ChartSpec, profile: CapabilityProfile): Verdict;
110
+ /** Everything on. What a role with no restrictions gets, and the default a loader assumes. */
111
+ export declare const OPEN_PROFILE: Readonly<CapabilityProfile>;
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Capability profiles -- what a given role may author.
3
+ *
4
+ * A profile is serializable and the same object gates three places. Kinds and aesthetics are
5
+ * allowlists, and setting groups are withheld by name. Absent means unrestricted.
6
+ */
7
+ import { GEOMS } from "./geom-table.js";
8
+ import { KINDS } from "./grammar.js";
9
+ export const allowsKind = (profile, kind) => (profile.kinds ?? KINDS).includes(kind);
10
+ /** Whether the role may author on this surface at all. */
11
+ export const allowsSurface = (profile, surface) => profile.surfaces == null || profile.surfaces.includes(surface);
12
+ export const allowsSetting = (profile, group) => !profile.withhold?.includes(group);
13
+ /**
14
+ * Aesthetics a role may bind on a kind, required ones included.
15
+ *
16
+ * The kind's geom table row bounds the answer. A profile naming an aesthetic the kind lacks narrows
17
+ * to nothing.
18
+ */
19
+ export function allowedAesthetics(profile, kind) {
20
+ const row = GEOMS[kind];
21
+ if (!row)
22
+ return [];
23
+ const bound = [...row.requires, ...row.accepts];
24
+ const named = profile.aesthetics?.[kind];
25
+ return named == null
26
+ ? bound
27
+ : bound.filter((aesthetic) => named.includes(aesthetic) || row.requires.includes(aesthetic));
28
+ }
29
+ /* In the order failures are reported. */
30
+ const CHART_GROUPS = {
31
+ version: null,
32
+ id: null,
33
+ headline: null,
34
+ subtitle: null,
35
+ caption: null,
36
+ layers: null,
37
+ facet: "facets",
38
+ coord: "axis-range",
39
+ scales: null,
40
+ tooltip: null,
41
+ annotations: "annotations",
42
+ overrides: "overrides",
43
+ legend: "legend",
44
+ sides: "side-panels",
45
+ height: "figure-size",
46
+ width: "figure-size",
47
+ aspect: "figure-size",
48
+ ratio: "figure-size",
49
+ sizing: "figure-size",
50
+ };
51
+ const LAYER_GROUPS = {
52
+ id: null,
53
+ name: null,
54
+ kind: null,
55
+ aes: null,
56
+ fit: "fits",
57
+ smooth: "fits",
58
+ directLabels: "labels",
59
+ numbers: "labels",
60
+ style: "geom-style",
61
+ position: "geom-style",
62
+ axis: "second-axis",
63
+ aggregate: "statistics",
64
+ cumulative: "statistics",
65
+ statParams: "statistics",
66
+ error: "statistics",
67
+ replicates: "statistics",
68
+ rings: "side-panels",
69
+ palette: "color-scale",
70
+ scales: null,
71
+ showLegend: "legend",
72
+ links: null,
73
+ visible: null,
74
+ data: null,
75
+ };
76
+ const POSITION_GROUPS = {
77
+ title: null,
78
+ transform: "log-scale",
79
+ reverse: "axis-range",
80
+ time: "axis-range",
81
+ timezone: "axis-range",
82
+ limits: "axis-range",
83
+ oob: "axis-range",
84
+ kind: "axis-range",
85
+ bandSize: "axis-range",
86
+ order: "axis-range",
87
+ labels: "axis-range",
88
+ breaks: "axis-range",
89
+ minorBreaks: "axis-range",
90
+ expand: "axis-range",
91
+ include: "axis-range",
92
+ breakWidth: "axis-range",
93
+ format: "axis-range",
94
+ decimals: "axis-range",
95
+ grid: "axis-chrome",
96
+ minorGrid: "axis-chrome",
97
+ minorTicks: "axis-chrome",
98
+ linewidth: "axis-chrome",
99
+ tickLength: "axis-chrome",
100
+ tickSide: "axis-chrome",
101
+ tickAngle: "axis-chrome",
102
+ titleAlign: "axis-chrome",
103
+ fontSize: "axis-chrome",
104
+ ink: "axis-chrome",
105
+ };
106
+ const COLOR_GROUPS = {
107
+ title: null,
108
+ limits: "color-scale",
109
+ center: "color-scale",
110
+ transform: "color-scale",
111
+ format: "color-scale",
112
+ decimals: "color-scale",
113
+ bins: "color-scale",
114
+ breaks: "color-scale",
115
+ labels: "color-scale",
116
+ standardize: "color-scale",
117
+ values: "color-scale",
118
+ };
119
+ const GUIDE_GROUPS = { title: null };
120
+ const SCALE_GROUPS = {
121
+ x: POSITION_GROUPS,
122
+ y: POSITION_GROUPS,
123
+ y2: POSITION_GROUPS,
124
+ color: COLOR_GROUPS,
125
+ fill: COLOR_GROUPS,
126
+ size: GUIDE_GROUPS,
127
+ shape: GUIDE_GROUPS,
128
+ alpha: GUIDE_GROUPS,
129
+ linetype: GUIDE_GROUPS,
130
+ };
131
+ /**
132
+ * Whether a field holds something the author said.
133
+ *
134
+ * An empty list or object says nothing. The first vertical scale and the identity transform are
135
+ * what an unstated field draws.
136
+ */
137
+ function stated(field, value) {
138
+ if (value == null)
139
+ return false;
140
+ if (field === "axis")
141
+ return value === "y2";
142
+ if (field === "transform")
143
+ return value !== "identity";
144
+ if (Array.isArray(value))
145
+ return value.length > 0;
146
+ if (typeof value === "object")
147
+ return Object.values(value).some((held) => held !== undefined);
148
+ return true;
149
+ }
150
+ /**
151
+ * Whether a spec falls inside a profile.
152
+ *
153
+ * Each field is checked and each failure collected. The paths are what a loader prints.
154
+ */
155
+ export function validate(spec, profile) {
156
+ const failures = [];
157
+ const refuse = (path, reason) => failures.push({ path, reason });
158
+ /* Each stated field of `record` whose group the profile withholds, at `at` plus the field. */
159
+ const check = (record, groups, at) => {
160
+ for (const [field, group] of Object.entries(groups)) {
161
+ const value = record[field];
162
+ if (group && stated(field, value) && !allowsSetting(profile, group)) {
163
+ refuse(`${at}${field}`, `${group} is outside this profile`);
164
+ }
165
+ }
166
+ };
167
+ if (!allowsSurface(profile, "chart"))
168
+ refuse("layers", "the chart surface is outside this profile");
169
+ const maxLayers = profile.limits?.layers;
170
+ if (maxLayers != null && spec.layers.length > maxLayers) {
171
+ refuse("layers", `${spec.layers.length} layers, ${maxLayers} allowed`);
172
+ }
173
+ for (const [field, group] of Object.entries(CHART_GROUPS)) {
174
+ if (field === "layers") {
175
+ spec.layers.forEach((layer, index) => {
176
+ const at = `layers[${index}]`;
177
+ if (!allowsKind(profile, layer.kind)) {
178
+ refuse(`${at}.kind`, `${layer.kind} is outside this profile`);
179
+ // The aesthetic check reads the kind's row, which says nothing once the kind is out.
180
+ return;
181
+ }
182
+ const allowed = allowedAesthetics(profile, layer.kind);
183
+ for (const aesthetic of Object.keys(layer.aes)) {
184
+ if (layer.aes[aesthetic] == null || allowed.includes(aesthetic))
185
+ continue;
186
+ refuse(`${at}.aes.${aesthetic}`, `the ${aesthetic} aesthetic is outside this profile`);
187
+ }
188
+ /* A layer drawing its own rows keeps out of the legend, as ggplot's annotate does. That flag is unstated. */
189
+ check(layer.data && layer.showLegend === false ? { ...layer, showLegend: undefined } : layer, LAYER_GROUPS, `${at}.`);
190
+ for (const paint of ["color", "fill"]) {
191
+ const scale = layer.scales?.[paint];
192
+ if (scale)
193
+ check(scale, COLOR_GROUPS, `${at}.scales.${paint}.`);
194
+ }
195
+ });
196
+ }
197
+ else if (field === "scales") {
198
+ for (const [aesthetic, groups] of Object.entries(SCALE_GROUPS)) {
199
+ const scale = spec.scales?.[aesthetic];
200
+ if (scale)
201
+ check(scale, groups, `scales.${aesthetic}.`);
202
+ }
203
+ if (stated("y2", spec.scales?.y2) && !allowsSetting(profile, "second-axis")) {
204
+ refuse("scales.y2", "second-axis is outside this profile");
205
+ }
206
+ }
207
+ else if (field === "annotations") {
208
+ const maxNotes = profile.limits?.annotations;
209
+ const notes = spec.annotations?.length ?? 0;
210
+ if (maxNotes != null && notes > maxNotes)
211
+ refuse("annotations", `${notes} annotations, ${maxNotes} allowed`);
212
+ check(spec, { annotations: group }, "");
213
+ }
214
+ else {
215
+ check(spec, { [field]: group }, "");
216
+ }
217
+ }
218
+ return { ok: failures.length === 0, failures };
219
+ }
220
+ /** Everything on. What a role with no restrictions gets, and the default a loader assumes. */
221
+ export const OPEN_PROFILE = Object.freeze({ id: "open", label: "Unrestricted" });
@@ -0,0 +1,108 @@
1
+ /**
2
+ * What a hover says, whichever geom is under the pointer.
3
+ *
4
+ * One union and one reader. A hover on any geom ends in one card.
5
+ */
6
+ import type { Trace } from "./layers.js";
7
+ import type { PlotData, PlotField } from "./plot-data.js";
8
+ import type { ChartSpec } from "./spec.js";
9
+ import type { TooltipRow } from "./geom-types.js";
10
+ import type { BarDatum } from "./geom-types.js";
11
+ import type { HeatCell } from "./geom-types.js";
12
+ import type { BoxDatum } from "./geom-types.js";
13
+ import type { ViolinDatum } from "./geom-types.js";
14
+ import type { ParallelLine } from "./geom-types.js";
15
+ import type { PointHit } from "./geom-types.js";
16
+ import type { GeomHit, SegmentPoint } from "./geom-types.js";
17
+ import type { SankeyLinkInput } from "./geom-types.js";
18
+ import type { HierarchyCell } from "./hierarchy.js";
19
+ export type LayerHit = {
20
+ kind: "point";
21
+ trace: Trace;
22
+ hit: PointHit;
23
+ }
24
+ /** The same record a point stands for, read on a third scale as well. */
25
+ | {
26
+ kind: "cube";
27
+ trace: Trace;
28
+ hit: PointHit;
29
+ } | {
30
+ kind: "cell";
31
+ trace: Trace;
32
+ cell: HeatCell;
33
+ } | {
34
+ kind: "bar";
35
+ trace: Trace;
36
+ datum: BarDatum;
37
+ }
38
+ /** A pie's slice, read as the bar it was built from. */
39
+ | {
40
+ kind: "slice";
41
+ trace: Trace;
42
+ datum: BarDatum;
43
+ } | {
44
+ kind: "box";
45
+ trace: Trace;
46
+ datum: BoxDatum;
47
+ } | {
48
+ kind: "violin";
49
+ trace: Trace;
50
+ datum: ViolinDatum;
51
+ }
52
+ /** A record read across several measures. One line of a parallel plot. */
53
+ | {
54
+ kind: "record";
55
+ trace: Trace;
56
+ line: ParallelLine;
57
+ at: {
58
+ x: number;
59
+ y: number;
60
+ };
61
+ }
62
+ /** One record's run from its start to its end. */
63
+ | {
64
+ kind: "segment";
65
+ trace: Trace;
66
+ hit: GeomHit<SegmentPoint>;
67
+ }
68
+ /** A ribbon. The one number on a flow with nothing written beside it. */
69
+ | {
70
+ kind: "flow";
71
+ trace: Trace;
72
+ link: SankeyLinkInput;
73
+ }
74
+ /** A chord's sector, with the total passing through it. */
75
+ | {
76
+ kind: "sector";
77
+ trace: Trace;
78
+ sector: {
79
+ id: string;
80
+ value: number;
81
+ };
82
+ }
83
+ /** One node of a hierarchy, and the total it stands for. */
84
+ | {
85
+ kind: "node";
86
+ trace: Trace;
87
+ cell: HierarchyCell;
88
+ };
89
+ export declare const numberOf: (field: PlotField | undefined, value: number) => string;
90
+ /**
91
+ * A value beside the interval drawn around it, as one string.
92
+ *
93
+ * The half-width takes the value's digits and the unit is written once at the end.
94
+ */
95
+ export declare const intervalOf: (field: PlotField | undefined, value: number, half: number) => string;
96
+ /**
97
+ * The readout shows what the plot says it shows.
98
+ *
99
+ * Bound channels are the default and the author can add the fields nobody plotted.
100
+ */
101
+ export declare function tooltipRows(hit: LayerHit, context: {
102
+ plot: ChartSpec;
103
+ data: PlotData;
104
+ /** Absent where the geom reads no horizontal axis. No point can be hit there. */
105
+ xField?: PlotField;
106
+ fieldAt: Map<string, PlotField>;
107
+ }): TooltipRow[];
108
+ export declare const tooltipTitle: (hit: LayerHit) => string;