@mechane-ai/elements 0.46.0 → 0.47.0

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 (276) hide show
  1. package/README.md +306 -33
  2. package/dist/ai.js +4 -4
  3. package/dist/catalog.json +2382 -33
  4. package/dist/categorical-values-DdfGIowV.js +107 -0
  5. package/dist/cells--Bd1fQFR.js +384 -0
  6. package/dist/chart-link-AE_xuxiP.js +35 -0
  7. package/dist/chart-tones-ei3BC2AL.js +27 -0
  8. package/dist/charts/cartesian.js +1 -2958
  9. package/dist/charts/cells.js +1 -0
  10. package/dist/charts/comparison.js +1 -0
  11. package/dist/charts/distribution.js +1 -781
  12. package/dist/charts/figure.js +3404 -0
  13. package/dist/charts/graph.js +1 -655
  14. package/dist/charts/hierarchy.js +1 -121
  15. package/dist/charts/image.js +1 -0
  16. package/dist/charts/matrix.js +3 -644
  17. package/dist/charts/plot.js +15 -0
  18. package/dist/charts/relationship.js +1 -0
  19. package/dist/charts/text.js +1 -0
  20. package/dist/charts/timeline.js +1 -266
  21. package/dist/charts/transforms.js +677 -0
  22. package/dist/charts/trend.js +1 -0
  23. package/dist/charts.js +8 -3
  24. package/dist/collections.js +1 -2195
  25. package/dist/color-legend-CIo7DhXB.js +62 -0
  26. package/dist/dates-Cww8UR_n.js +810 -0
  27. package/dist/dumbbell-plot-B2ZTgQaI.js +508 -0
  28. package/dist/embedding-map-CGM_k6lC.js +1929 -0
  29. package/dist/feedback.js +1 -1
  30. package/dist/figure-format-B8kRZMlo.js +36 -0
  31. package/dist/figure-frame-wRkIEAwe.js +270 -0
  32. package/dist/forms/dates.js +1 -810
  33. package/dist/heatmap-scale-Zte6Ya-g.js +20 -0
  34. package/dist/image-grid-CVA4SOy_.js +598 -0
  35. package/dist/kits/evaluation.js +431 -0
  36. package/dist/kits/explainers.js +452 -0
  37. package/dist/kits/interpretability.js +1033 -0
  38. package/dist/kits/operations.js +239 -0
  39. package/dist/kits/training.js +335 -0
  40. package/dist/label-place-Z0fryBZb.js +42 -0
  41. package/dist/locate-Bcg3QcP4.js +11 -0
  42. package/dist/packages/charts/src/cartesian/bar-chart.d.ts +40 -21
  43. package/dist/packages/charts/src/cartesian/bar-data.d.ts +15 -4
  44. package/dist/packages/charts/src/cartesian/bar-overlays.d.ts +7 -3
  45. package/dist/packages/charts/src/cartesian/breakdown-bar.d.ts +10 -8
  46. package/dist/packages/charts/src/cartesian/bridge-chart.d.ts +20 -16
  47. package/dist/packages/charts/src/cartesian/bridge-data.d.ts +5 -4
  48. package/dist/packages/charts/src/cartesian/composition-bars.d.ts +8 -4
  49. package/dist/packages/charts/src/cartesian/index.d.ts +5 -5
  50. package/dist/packages/charts/src/cartesian/reference-lines.d.ts +25 -18
  51. package/dist/packages/charts/src/cartesian/scatter-plot.d.ts +30 -25
  52. package/dist/packages/charts/src/cartesian/sparkline.d.ts +14 -2
  53. package/dist/packages/charts/src/cartesian/time-series-bands.d.ts +3 -2
  54. package/dist/packages/charts/src/cartesian/time-series-data.d.ts +12 -2
  55. package/dist/packages/charts/src/cartesian/time-series-line.d.ts +2 -2
  56. package/dist/packages/charts/src/cartesian/time-series-overlays.d.ts +6 -4
  57. package/dist/packages/charts/src/cartesian/time-series.d.ts +60 -36
  58. package/dist/packages/charts/src/cartesian/value-labels.d.ts +22 -0
  59. package/dist/packages/charts/src/categorical-values.d.ts +1 -1
  60. package/dist/packages/charts/src/cells/bar-cell.d.ts +13 -0
  61. package/dist/packages/charts/src/cells/cell-layout.d.ts +81 -0
  62. package/dist/packages/charts/src/cells/change-cell.d.ts +17 -0
  63. package/dist/packages/charts/src/cells/heat-cell.d.ts +19 -0
  64. package/dist/packages/charts/src/cells/index.d.ts +11 -0
  65. package/dist/packages/charts/src/cells/interval-cell.d.ts +16 -0
  66. package/dist/packages/charts/src/cells/spark-cell.d.ts +22 -0
  67. package/dist/packages/charts/src/chart-frame.d.ts +14 -7
  68. package/dist/packages/charts/src/chart-grid.d.ts +19 -0
  69. package/dist/packages/charts/src/chart-input.d.ts +1 -9
  70. package/dist/packages/charts/src/chart-link.d.ts +56 -0
  71. package/dist/packages/charts/src/chart.d.ts +0 -8
  72. package/dist/packages/charts/src/comparison/bullet-bar.d.ts +34 -0
  73. package/dist/packages/charts/src/comparison/comparison-plot.d.ts +54 -0
  74. package/dist/packages/charts/src/comparison/dot-plot.d.ts +41 -0
  75. package/dist/packages/charts/src/comparison/dumbbell-plot.d.ts +33 -0
  76. package/dist/packages/charts/src/comparison/index.d.ts +6 -0
  77. package/dist/packages/charts/src/distribution/box-plot.d.ts +40 -0
  78. package/dist/packages/charts/src/distribution/distribution-input.d.ts +5 -3
  79. package/dist/packages/charts/src/distribution/distribution-plot.d.ts +28 -161
  80. package/dist/packages/charts/src/distribution/ecdf.d.ts +16 -15
  81. package/dist/packages/charts/src/distribution/group-plot-input.d.ts +35 -0
  82. package/dist/packages/charts/src/distribution/group-plot-layout.d.ts +79 -0
  83. package/dist/packages/charts/src/distribution/group-plot.d.ts +73 -0
  84. package/dist/packages/charts/src/distribution/histogram.d.ts +16 -16
  85. package/dist/packages/charts/src/distribution/index.d.ts +11 -0
  86. package/dist/packages/charts/src/distribution/interval-plot.d.ts +16 -13
  87. package/dist/packages/charts/src/distribution/ranked-bars.d.ts +17 -14
  88. package/dist/packages/charts/src/distribution/ridgeline.d.ts +34 -0
  89. package/dist/packages/charts/src/distribution/strip-plot.d.ts +37 -0
  90. package/dist/packages/charts/src/distribution/violin-plot.d.ts +34 -0
  91. package/dist/packages/charts/src/figure/figure-format.d.ts +34 -0
  92. package/dist/packages/charts/src/figure/figure-frame.d.ts +47 -0
  93. package/dist/packages/charts/src/figure/figure-props.d.ts +54 -0
  94. package/dist/packages/charts/src/figure/tone-scope.d.ts +32 -0
  95. package/dist/packages/charts/src/graph/attribution-graph.d.ts +62 -0
  96. package/dist/packages/charts/src/graph/attribution-layout.d.ts +88 -0
  97. package/dist/packages/charts/src/graph/flow-diagram.d.ts +14 -15
  98. package/dist/packages/charts/src/graph/flow-layout.d.ts +4 -2
  99. package/dist/packages/charts/src/graph/graph-canvas.d.ts +33 -0
  100. package/dist/packages/charts/src/graph/index.d.ts +6 -2
  101. package/dist/packages/charts/src/graph/relation-graph.d.ts +24 -13
  102. package/dist/packages/charts/src/graph/tree-diagram.d.ts +41 -0
  103. package/dist/packages/charts/src/graph/tree-layout.d.ts +71 -0
  104. package/dist/packages/charts/src/hierarchy/area-mark.d.ts +17 -0
  105. package/dist/packages/charts/src/hierarchy/icicle.d.ts +35 -0
  106. package/dist/packages/charts/src/hierarchy/index.d.ts +2 -0
  107. package/dist/packages/charts/src/hierarchy/partition-layout.d.ts +25 -0
  108. package/dist/packages/charts/src/hierarchy/treemap-layout.d.ts +26 -0
  109. package/dist/packages/charts/src/hierarchy/treemap.d.ts +11 -9
  110. package/dist/packages/charts/src/image/attribution-legend.d.ts +13 -0
  111. package/dist/packages/charts/src/image/attribution-overlay.d.ts +50 -0
  112. package/dist/packages/charts/src/image/attribution-ramp.d.ts +16 -0
  113. package/dist/packages/charts/src/image/image-atlas.d.ts +37 -0
  114. package/dist/packages/charts/src/image/image-fill.d.ts +9 -0
  115. package/dist/packages/charts/src/image/image-grid.d.ts +26 -0
  116. package/dist/packages/charts/src/image/image-input.d.ts +27 -0
  117. package/dist/packages/charts/src/image/image-tile.d.ts +27 -0
  118. package/dist/packages/charts/src/image/index.d.ts +7 -0
  119. package/dist/packages/charts/src/index.d.ts +15 -1
  120. package/dist/packages/charts/src/matrix/attention-matrix.d.ts +41 -0
  121. package/dist/packages/charts/src/matrix/calendar-heatmap.d.ts +37 -0
  122. package/dist/packages/charts/src/matrix/color-legend.d.ts +9 -2
  123. package/dist/packages/charts/src/matrix/confusion-matrix.d.ts +36 -0
  124. package/dist/packages/charts/src/matrix/correlation-matrix.d.ts +34 -0
  125. package/dist/packages/charts/src/matrix/heatmap-scale.d.ts +8 -2
  126. package/dist/packages/charts/src/matrix/index.d.ts +14 -3
  127. package/dist/packages/charts/src/matrix/matrix-cells.d.ts +27 -3
  128. package/dist/packages/charts/src/matrix/matrix-figure.d.ts +50 -0
  129. package/dist/packages/charts/src/matrix/matrix-mark.d.ts +34 -0
  130. package/dist/packages/charts/src/matrix/matrix-presets.d.ts +20 -0
  131. package/dist/packages/charts/src/matrix/matrix-range.d.ts +45 -0
  132. package/dist/packages/charts/src/matrix/matrix-strip.d.ts +13 -14
  133. package/dist/packages/charts/src/matrix/matrix-types.d.ts +40 -0
  134. package/dist/packages/charts/src/matrix/matrix.d.ts +13 -11
  135. package/dist/packages/charts/src/matrix/token-heatmap.d.ts +16 -10
  136. package/dist/packages/charts/src/plot/contours.d.ts +45 -0
  137. package/dist/packages/charts/src/plot/index.d.ts +49 -0
  138. package/dist/packages/charts/src/plot/label-place.d.ts +35 -0
  139. package/dist/packages/charts/src/plot/locate.d.ts +18 -0
  140. package/dist/packages/charts/src/plot/path.d.ts +39 -0
  141. package/dist/packages/charts/src/plot/plot-axes.d.ts +20 -0
  142. package/dist/packages/charts/src/plot/plot-layout.d.ts +221 -0
  143. package/dist/packages/charts/src/plot/plot-marks.d.ts +124 -0
  144. package/dist/packages/charts/src/plot/plot-surface.d.ts +32 -0
  145. package/dist/packages/charts/src/plot/render/density-layer.d.ts +17 -0
  146. package/dist/packages/charts/src/plot/render/hit-index.d.ts +37 -0
  147. package/dist/packages/charts/src/plot/render/plot-viewport.d.ts +39 -0
  148. package/dist/packages/charts/src/plot/render/point-layer.d.ts +41 -0
  149. package/dist/packages/charts/src/plot/render/theme-colors.d.ts +15 -0
  150. package/dist/packages/charts/src/plot/scale.d.ts +48 -0
  151. package/dist/packages/charts/src/plot/ticks.d.ts +34 -0
  152. package/dist/packages/charts/src/plot-width.d.ts +3 -2
  153. package/dist/packages/charts/src/relationship/contour-plot.d.ts +61 -0
  154. package/dist/packages/charts/src/relationship/density-map.d.ts +45 -0
  155. package/dist/packages/charts/src/relationship/embedding-map.d.ts +75 -0
  156. package/dist/packages/charts/src/relationship/index.d.ts +11 -0
  157. package/dist/packages/charts/src/relationship/level-legend.d.ts +11 -0
  158. package/dist/packages/charts/src/relationship/measures.d.ts +85 -0
  159. package/dist/packages/charts/src/relationship/parallel-coordinates.d.ts +30 -0
  160. package/dist/packages/charts/src/relationship/range-controls.d.ts +20 -0
  161. package/dist/packages/charts/src/relationship/scatter-matrix.d.ts +20 -0
  162. package/dist/packages/charts/src/spec/chart-guide.d.ts +21 -0
  163. package/dist/packages/charts/src/spec/figure-registry.d.ts +44 -0
  164. package/dist/packages/charts/src/spec/figure-spec.d.ts +147 -0
  165. package/dist/packages/charts/src/spec/figure-text.d.ts +8 -0
  166. package/dist/packages/charts/src/spec/figure.d.ts +12 -0
  167. package/dist/packages/charts/src/spec/guide-data.d.ts +85 -0
  168. package/dist/packages/charts/src/spec/index.d.ts +10 -0
  169. package/dist/packages/charts/src/spec/validate-figure.d.ts +15 -0
  170. package/dist/packages/charts/src/text/index.d.ts +11 -0
  171. package/dist/packages/charts/src/text/token-examples.d.ts +42 -0
  172. package/dist/packages/charts/src/text/token-grid.d.ts +47 -0
  173. package/dist/packages/charts/src/text/token-links.d.ts +49 -0
  174. package/dist/packages/charts/src/text/token-predictions.d.ts +38 -0
  175. package/dist/packages/charts/src/text/token-scale.d.ts +20 -0
  176. package/dist/packages/charts/src/text/token-text.d.ts +39 -0
  177. package/dist/packages/charts/src/timeline/event-strip.d.ts +70 -0
  178. package/dist/packages/charts/src/timeline/index.d.ts +3 -1
  179. package/dist/packages/charts/src/timeline/waterfall.d.ts +24 -13
  180. package/dist/packages/charts/src/transforms/bins.d.ts +91 -0
  181. package/dist/packages/charts/src/transforms/density.d.ts +53 -0
  182. package/dist/packages/charts/src/transforms/fits.d.ts +50 -0
  183. package/dist/packages/charts/src/transforms/index.d.ts +19 -0
  184. package/dist/packages/charts/src/transforms/matrices.d.ts +49 -0
  185. package/dist/packages/charts/src/transforms/quantiles.d.ts +96 -0
  186. package/dist/packages/charts/src/transforms/ranks.d.ts +44 -0
  187. package/dist/packages/charts/src/transforms/runs.d.ts +47 -0
  188. package/dist/packages/charts/src/transforms/sampling.d.ts +75 -0
  189. package/dist/packages/charts/src/transforms/smoothing.d.ts +41 -0
  190. package/dist/packages/charts/src/transforms/values.d.ts +70 -0
  191. package/dist/packages/charts/src/trend/bump-chart.d.ts +33 -0
  192. package/dist/packages/charts/src/trend/column-figure.d.ts +38 -0
  193. package/dist/packages/charts/src/trend/column-positions.d.ts +21 -0
  194. package/dist/packages/charts/src/trend/curve-chart.d.ts +69 -0
  195. package/dist/packages/charts/src/trend/end-labels.d.ts +40 -0
  196. package/dist/packages/charts/src/trend/horizon-chart.d.ts +37 -0
  197. package/dist/packages/charts/src/trend/index.d.ts +10 -0
  198. package/dist/packages/charts/src/trend/line-locate.d.ts +21 -0
  199. package/dist/packages/charts/src/trend/runs-chart.d.ts +50 -0
  200. package/dist/packages/charts/src/trend/slope-chart.d.ts +35 -0
  201. package/dist/packages/kits/src/evaluation/evaluation-data.d.ts +31 -0
  202. package/dist/packages/kits/src/evaluation/index.d.ts +8 -0
  203. package/dist/packages/kits/src/evaluation/leaderboard-cells.d.ts +62 -0
  204. package/dist/packages/kits/src/evaluation/leaderboard.d.ts +59 -0
  205. package/dist/packages/kits/src/evaluation/model-comparison.d.ts +59 -0
  206. package/dist/packages/kits/src/evaluation/score-breakdown.d.ts +33 -0
  207. package/dist/packages/kits/src/explainers/bound-value.d.ts +29 -0
  208. package/dist/packages/kits/src/explainers/figures.d.ts +31 -0
  209. package/dist/packages/kits/src/explainers/index.d.ts +8 -0
  210. package/dist/packages/kits/src/explainers/linked-target.d.ts +22 -0
  211. package/dist/packages/kits/src/explainers/story-steps.d.ts +46 -0
  212. package/dist/packages/kits/src/explainers/term.d.ts +29 -0
  213. package/dist/packages/kits/src/interpretability/attention-head-grid.d.ts +56 -0
  214. package/dist/packages/kits/src/interpretability/attribution-workbench.d.ts +29 -0
  215. package/dist/packages/kits/src/interpretability/embedding-atlas.d.ts +41 -0
  216. package/dist/packages/kits/src/interpretability/feature-card.d.ts +33 -0
  217. package/dist/packages/kits/src/interpretability/feature-list.d.ts +51 -0
  218. package/dist/packages/kits/src/interpretability/feature-logits.d.ts +23 -0
  219. package/dist/packages/kits/src/interpretability/features.d.ts +70 -0
  220. package/dist/packages/kits/src/interpretability/index.d.ts +16 -0
  221. package/dist/packages/kits/src/interpretability/kit-styles.d.ts +118 -0
  222. package/dist/packages/kits/src/interpretability/logit-lens.d.ts +50 -0
  223. package/dist/packages/kits/src/interpretability/node-panel.d.ts +32 -0
  224. package/dist/packages/kits/src/interpretability/shared-link.d.ts +8 -0
  225. package/dist/packages/kits/src/interpretability/steering-panel.d.ts +52 -0
  226. package/dist/packages/kits/src/operations/budget-board.d.ts +49 -0
  227. package/dist/packages/kits/src/operations/incident-timeline.d.ts +30 -0
  228. package/dist/packages/kits/src/operations/index.d.ts +6 -0
  229. package/dist/packages/kits/src/operations/service-health.d.ts +66 -0
  230. package/dist/packages/kits/src/training/index.d.ts +8 -0
  231. package/dist/packages/kits/src/training/run-dashboard.d.ts +49 -0
  232. package/dist/packages/kits/src/training/run-legend.d.ts +21 -0
  233. package/dist/packages/kits/src/training/run-marker.d.ts +5 -0
  234. package/dist/packages/kits/src/training/run-state.d.ts +7 -0
  235. package/dist/packages/kits/src/training/run-table.d.ts +63 -0
  236. package/dist/packages/kits/src/training/runs-overview.d.ts +20 -0
  237. package/dist/packages/kits/src/training/runs.d.ts +34 -0
  238. package/dist/path-BglsXpnO.js +59 -0
  239. package/dist/plot-axes-DJkLW4wk.js +100 -0
  240. package/dist/plot-layout-BEuoOHbs.js +911 -0
  241. package/dist/plot-marks-A64v7aTw.js +226 -0
  242. package/dist/plot-surface-CJTIqtck.js +51 -0
  243. package/dist/plot-width-DcqtSgzb.js +124 -0
  244. package/dist/point-layer-C-EYETAt.js +655 -0
  245. package/dist/reference-lines-CWA8VeUR.js +82 -0
  246. package/dist/scale-C2xgZyZN.js +63 -0
  247. package/dist/slope-chart-DT22h_ym.js +1279 -0
  248. package/dist/{src-DVHlknB6.js → src-CExIrXPC.js} +169 -193
  249. package/dist/src-D5NXRJZe.js +2195 -0
  250. package/dist/src-DIS0YOj0.js +44 -0
  251. package/dist/styles2.css +453 -62
  252. package/dist/time-series-IB3CB93O.js +2668 -0
  253. package/dist/token-heatmap-C00DnoNO.js +1354 -0
  254. package/dist/token-predictions-Cxx29iDr.js +1093 -0
  255. package/dist/tone-scope-DKiSw-JR.js +32 -0
  256. package/dist/tree-diagram-DsckNKaW.js +1629 -0
  257. package/dist/treemap-9_DpLCW9.js +472 -0
  258. package/dist/values-963L6n1m.js +65 -0
  259. package/dist/violin-plot-BhPHKXsN.js +1291 -0
  260. package/dist/waterfall-CGksuTy5.js +576 -0
  261. package/package.json +57 -4
  262. package/recipes/allocation-report.tsx +15 -7
  263. package/skills/extend-elements/SKILL.md +60 -0
  264. package/skills/review-elements/SKILL.md +43 -1
  265. package/skills/upgrade-elements/SKILL.md +3 -1
  266. package/skills/upgrade-elements/references/releases.md +184 -0
  267. package/skills/use-elements/SKILL.md +19 -13
  268. package/skills/use-elements/references/charts.md +362 -41
  269. package/skills/use-elements/references/figures.md +173 -0
  270. package/skills/use-elements/references/kits.md +198 -0
  271. package/dist/categorical-values-BXi-rJuv.js +0 -74
  272. package/dist/chart-data-CIJVWCYt.js +0 -21
  273. package/dist/chart-frame-BaxKn_MB.js +0 -236
  274. package/dist/chart-input-Bm82_9Rd.js +0 -22
  275. package/dist/chart-theme-4zprJ3rW.js +0 -404
  276. package/dist/plot-width-v2c_rA20.js +0 -63
@@ -0,0 +1,35 @@
1
+ /** A label a chart could draw: where its baseline starts, how it is anchored, and its text. */
2
+ export type LabelSpot = {
3
+ readonly x: number;
4
+ /** The text's baseline. */
5
+ readonly y: number;
6
+ readonly anchor: 'start' | 'middle' | 'end';
7
+ readonly text: string;
8
+ };
9
+ /** A point in plot pixels on a line a label must avoid. */
10
+ export type LabelObstacle = {
11
+ readonly x: number;
12
+ readonly y: number;
13
+ };
14
+ /** A box in plot pixels. */
15
+ export type LabelBox = {
16
+ readonly left: number;
17
+ readonly right: number;
18
+ readonly top: number;
19
+ readonly bottom: number;
20
+ };
21
+ /** The box a label's text covers, with a few pixels of clearance on every side. */
22
+ export declare function labelBox(spot: LabelSpot): LabelBox;
23
+ export type FreeLabelSpotInput = {
24
+ /** Where the label may go, in order of preference. */
25
+ readonly spots: ReadonlyArray<LabelSpot>;
26
+ /** The lines and marks the label must not sit on, as pixel polylines. A single point stands for a dot. */
27
+ readonly lines: ReadonlyArray<ReadonlyArray<LabelObstacle>>;
28
+ /** Boxes already taken, such as other labels. */
29
+ readonly taken?: ReadonlyArray<LabelBox> | undefined;
30
+ };
31
+ /**
32
+ * The first spot where a label touches no line and no taken box, or else the spot it touches least. Use it for a
33
+ * reference or marker label that may sit at either end of its line, so it never covers a series.
34
+ */
35
+ export declare function freeLabelSpot({ spots, lines, taken }: FreeLabelSpotInput): LabelSpot | undefined;
@@ -0,0 +1,18 @@
1
+ import type { ChartPoint } from '../chart.tsx';
2
+ /** Where a mark sits in the plot's drawn pixels. */
3
+ export type MarkPosition = {
4
+ readonly id: string;
5
+ readonly x: number;
6
+ readonly y: number;
7
+ };
8
+ /**
9
+ * A chart `locate` for marks at known positions: the pointer inspects the nearest one. The `axis` option limits the
10
+ * distance to one direction, for marks a reader scans along a single axis such as the steps of a curve.
11
+ */
12
+ export declare function locateNearest({ marks, width, height, axis, }: {
13
+ readonly marks: ReadonlyArray<MarkPosition>;
14
+ /** The size the marks were laid out in. The pointer arrives in rendered pixels and is rescaled to it. */
15
+ readonly width: number;
16
+ readonly height: number;
17
+ readonly axis?: 'x' | 'y' | 'both' | undefined;
18
+ }): (point: ChartPoint) => string | undefined;
@@ -0,0 +1,39 @@
1
+ /** A vertex of a line. A null `y` is a missing observation: the line breaks there and is never drawn through it. */
2
+ export type PathPoint = {
3
+ readonly x: number;
4
+ readonly y: number | null;
5
+ };
6
+ /** A vertex of a filled region between two edges. A null edge breaks the region. */
7
+ export type AreaPoint = {
8
+ readonly x: number;
9
+ readonly y0: number | null;
10
+ readonly y1: number | null;
11
+ };
12
+ type Vertex = {
13
+ readonly x: number;
14
+ readonly y: number;
15
+ };
16
+ /** How neighbors join: a straight segment, or a step that holds each value until the next observation. */
17
+ export type PathCurve = 'linear' | 'step';
18
+ /** The SVG path of a line through the present points, broken at each missing one. */
19
+ export declare function linePath(points: ReadonlyArray<PathPoint>, curve?: PathCurve): string;
20
+ /** The present points with a missing or absent neighbor on both sides. A line cannot show them, so charts draw dots. */
21
+ export declare function isolatedPoints(points: ReadonlyArray<PathPoint>): ReadonlyArray<Vertex>;
22
+ /** The SVG path of the region between two edges, joined by straight segments and broken where an edge is missing. */
23
+ export declare function areaPath(points: ReadonlyArray<AreaPoint>): string;
24
+ /** How a link joins two marks: a smooth curve, or right-angled elbows that turn halfway along. */
25
+ export type LinkShape = 'curve' | 'elbow';
26
+ type Segment = {
27
+ readonly x1: number;
28
+ readonly y1: number;
29
+ readonly x2: number;
30
+ readonly y2: number;
31
+ };
32
+ export type LinkPathInput = Segment & {
33
+ /** The axis the link advances along, from its source to its target: `y` for a link that runs up or down. */
34
+ readonly axis: 'x' | 'y';
35
+ readonly shape?: LinkShape | undefined;
36
+ };
37
+ /** The SVG path of a link from one mark to another, such as a graph edge or a tree branch. */
38
+ export declare function linkPath({ x1, y1, x2, y2, axis, shape }: LinkPathInput): string;
39
+ export {};
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { PlotBox, PlotTick } from './plot-layout.ts';
3
+ export type PlotAxesProps = {
4
+ readonly box: PlotBox;
5
+ /** The ticks along the bottom, at horizontal positions. */
6
+ readonly xTicks: ReadonlyArray<PlotTick>;
7
+ /** The ticks down the side, at vertical positions. */
8
+ readonly yTicks: ReadonlyArray<PlotTick>;
9
+ readonly xTitle?: string | undefined;
10
+ readonly yTitle?: string | undefined;
11
+ /** Which ticks draw a line across the plot. Lines follow the measured axis: horizontal ones by default. */
12
+ readonly grid?: PlotGrid | undefined;
13
+ };
14
+ export type PlotGrid = 'x' | 'y' | 'both' | 'none';
15
+ /**
16
+ * The grid, tick labels and axis titles of a plot, which every chart draws here so its axes all read alike. A side
17
+ * label longer than the left margin is cut with an ellipsis and keeps its full text in a title. Bottom labels that
18
+ * would touch are thinned, and the readout still names every category.
19
+ */
20
+ export declare function PlotAxes({ box, xTicks, yTicks, xTitle, yTitle, grid }: PlotAxesProps): ReactNode;
@@ -0,0 +1,221 @@
1
+ import type { TimeFormat, ValueFormat } from '../figure/figure-format.ts';
2
+ import type { BandScale, ContinuousScale, NumericDomain, ScaleType } from './scale.ts';
3
+ /** The named plot heights, in CSS pixels. A figure picks one, so charts side by side share a baseline. */
4
+ export declare const plotHeights: {
5
+ readonly compact: 160;
6
+ readonly regular: 260;
7
+ readonly tall: 380;
8
+ };
9
+ export type PlotHeight = keyof typeof plotHeights;
10
+ export type PlotMargins = {
11
+ readonly top: number;
12
+ readonly right: number;
13
+ readonly bottom: number;
14
+ readonly left: number;
15
+ };
16
+ /** The drawing area inside the axes, in the CSS pixels of the plot's own top left corner. */
17
+ export type PlotBox = {
18
+ readonly width: number;
19
+ readonly height: number;
20
+ readonly left: number;
21
+ readonly right: number;
22
+ readonly top: number;
23
+ readonly bottom: number;
24
+ readonly innerWidth: number;
25
+ readonly innerHeight: number;
26
+ };
27
+ /** One labelled position on an axis. A category label wrapped by `categoryPlot` holds one line break. */
28
+ export type PlotTick = {
29
+ readonly key: string;
30
+ readonly position: number;
31
+ readonly label: string;
32
+ };
33
+ /** A measured axis as a chart's caller declares it. */
34
+ export type PlotAxis = {
35
+ /** The axis title, with its unit: "Latency (ms)". */
36
+ readonly label: string;
37
+ /** The values the axis spans. Leave it out to fit the supplied values on round bounds. */
38
+ readonly domain?: NumericDomain | undefined;
39
+ readonly scale?: ScaleType | undefined;
40
+ /** How readouts and tables write a value on this axis. Ticks use its compact form unless `tickFormat` is set. */
41
+ readonly format: ValueFormat;
42
+ readonly tickFormat?: ValueFormat | undefined;
43
+ };
44
+ export type PlotCategory = {
45
+ readonly id: string;
46
+ readonly label: string;
47
+ };
48
+ /** The axis title a reader sees. A log axis always says so, because equal distances no longer mean equal amounts. */
49
+ export declare function axisTitle(axis: Pick<PlotAxis, 'label' | 'scale'>): string;
50
+ export type FitDomainInput = {
51
+ readonly values: ReadonlyArray<number | null>;
52
+ /** True for marks whose length carries the amount, such as bars: their axis always starts at zero. */
53
+ readonly isZeroBased?: boolean | undefined;
54
+ readonly scale?: ScaleType | undefined;
55
+ };
56
+ /**
57
+ * The domain a chart uses when its caller declares none: the finite values, widened to round bounds. A linear axis with
58
+ * no spread gets one unit on each side; a log axis rounds out to powers of ten.
59
+ */
60
+ export declare function fitDomain({ values, isZeroBased, scale }: FitDomainInput): NumericDomain;
61
+ /** The margins that hold a plot's tick labels and axis titles. The left one grows with the longest value label. */
62
+ export declare function plotMargins({ width, valueLabels, hasXTitle, hasYTitle, leftShare, }: {
63
+ readonly width: number;
64
+ /** The labels drawn beside the vertical axis. */
65
+ readonly valueLabels: ReadonlyArray<string>;
66
+ readonly hasXTitle: boolean;
67
+ readonly hasYTitle: boolean;
68
+ /** The largest share of the width the left margin may take. Rows of named categories may take more than values. */
69
+ readonly leftShare?: number | undefined;
70
+ }): PlotMargins;
71
+ export declare function plotBox({ width, height, margins, }: {
72
+ readonly width: number;
73
+ readonly height: number;
74
+ readonly margins: PlotMargins;
75
+ }): PlotBox;
76
+ /** Tick values with the text each one shows. */
77
+ export type AxisTicks = {
78
+ readonly values: ReadonlyArray<number>;
79
+ readonly labels: ReadonlyArray<string>;
80
+ };
81
+ export type AxisTicksInput = {
82
+ readonly axis: PlotAxis;
83
+ readonly domain: NumericDomain;
84
+ /** The axis length in pixels: the plot's height for a vertical axis, its inner width for a horizontal one. */
85
+ readonly length: number;
86
+ /** About how many pixels apart neighbouring ticks sit. */
87
+ readonly spacing: number;
88
+ readonly locale: string;
89
+ /**
90
+ * True when the axis draws its title. The title names the unit, so the ticks leave out a `unit` style and stay short;
91
+ * currency and percent signs remain.
92
+ */
93
+ readonly hasTitle: boolean;
94
+ };
95
+ /**
96
+ * The text of each tick, raised in precision until no two read the same. The order is the compact form, then the
97
+ * compact form with one to four digits after the point, then the full form with as many. A function format is used as
98
+ * supplied.
99
+ */
100
+ export declare function tickTexts({ values, axis, locale, hasTitle, }: Pick<AxisTicksInput, 'axis' | 'locale' | 'hasTitle'> & {
101
+ readonly values: ReadonlyArray<number>;
102
+ }): ReadonlyArray<string>;
103
+ /**
104
+ * The fewest ticks an axis of this length shows: three once it is longer than 120 pixels, two below. Charts that place
105
+ * their own ticks use it, so every axis agrees.
106
+ */
107
+ export declare function ticksMinimum(length: number): number;
108
+ /**
109
+ * The ticks of a measured axis: round values on its scale, at least three on an axis longer than 120 pixels, each
110
+ * labelled so that no two read the same. Ticks that land on both ends of the domain win when they fit, so the lowest
111
+ * and highest marks never sit beyond the outer ticks. Every kernel layout labels its axes with it; a chart that draws
112
+ * an axis of its own calls it too.
113
+ */
114
+ export declare function axisTicks({ axis, domain, length, spacing, locale, hasTitle }: AxisTicksInput): AxisTicks;
115
+ /**
116
+ * The ticks of a band axis: one at the center of each category, labelled with its name. A label may hold a line break,
117
+ * which `PlotAxes` draws as a second line.
118
+ */
119
+ export declare function bandTicks(scale: BandScale, categories: ReadonlyArray<PlotCategory>): ReadonlyArray<PlotTick>;
120
+ export type NumericPlotLayout = {
121
+ readonly box: PlotBox;
122
+ readonly x: ContinuousScale;
123
+ readonly y: ContinuousScale;
124
+ readonly xTicks: ReadonlyArray<PlotTick>;
125
+ readonly yTicks: ReadonlyArray<PlotTick>;
126
+ };
127
+ /** The layout of a plot with a measured axis on both sides: margins from the tick labels, then scales and ticks. */
128
+ export declare function numericPlot({ width, height, x, y, xDomain, yDomain, locale, rightGutter, }: {
129
+ readonly width: number;
130
+ readonly height: number;
131
+ readonly x: PlotAxis;
132
+ readonly y: PlotAxis;
133
+ /** The resolved domains: the caller's own, or the result of `fitDomain`. */
134
+ readonly xDomain: NumericDomain;
135
+ readonly yDomain: NumericDomain;
136
+ readonly locale: string;
137
+ /** Extra room right of the plot, in pixels, for labels at the end of lines. */
138
+ readonly rightGutter?: number | undefined;
139
+ }): NumericPlotLayout;
140
+ export type CategoryPlotLayout = {
141
+ readonly box: PlotBox;
142
+ readonly band: BandScale;
143
+ readonly value: ContinuousScale;
144
+ readonly bandTicks: ReadonlyArray<PlotTick>;
145
+ readonly valueTicks: ReadonlyArray<PlotTick>;
146
+ };
147
+ /**
148
+ * The layout of a plot with named categories on one axis and a measured value on the other. The `columns` direction
149
+ * stands the categories along the bottom. The `rows` direction lists them down the side, which suits long names.
150
+ */
151
+ export declare function categoryPlot({ width, height, direction, categories, value, valueDomain, locale, padding, topInset, rightGutter, hasValueTitle, }: {
152
+ readonly width: number;
153
+ readonly height: number;
154
+ readonly direction: 'columns' | 'rows';
155
+ readonly categories: ReadonlyArray<PlotCategory>;
156
+ readonly value: PlotAxis;
157
+ readonly valueDomain: NumericDomain;
158
+ readonly locale: string;
159
+ readonly padding?: number | undefined;
160
+ /** Extra room above the plot, in pixels, for notes drawn over the tallest marks. */
161
+ readonly topInset?: number | undefined;
162
+ /** Extra room right of the plot, in pixels, for labels at the end of reference lines. */
163
+ readonly rightGutter?: number | undefined;
164
+ /** False when the value axis draws no title, so its margin holds only the tick labels. */
165
+ readonly hasValueTitle?: boolean | undefined;
166
+ }): CategoryPlotLayout;
167
+ export type ValueGutterInput = {
168
+ readonly height: number;
169
+ /** The value axis of each plot that shares the gutter, with its resolved domain. */
170
+ readonly axes: ReadonlyArray<{
171
+ readonly axis: PlotAxis;
172
+ readonly domain: NumericDomain;
173
+ }>;
174
+ readonly locale: string;
175
+ /** True when the plots draw their value-axis titles, as `timePlot` does with `hasValueTitle`. */
176
+ readonly hasValueTitle?: boolean | undefined;
177
+ };
178
+ /**
179
+ * The left margin that holds the value tick labels of every listed plot. Plots stacked in a column, such as small
180
+ * multiples, pass it to `timePlot` so their value axes line up on one gutter.
181
+ */
182
+ export declare function valueGutter({ height, axes, locale, hasValueTitle }: ValueGutterInput): number;
183
+ export type TimePlotInput = {
184
+ readonly width: number;
185
+ readonly height: number;
186
+ readonly value: PlotAxis;
187
+ readonly valueDomain: NumericDomain;
188
+ /** The first and last instant the plot spans, in milliseconds since the epoch. */
189
+ readonly timeDomain: NumericDomain;
190
+ /** How the time axis writes its ticks. A format with a time zone puts the ticks on that zone's clock steps. */
191
+ readonly timeFormat: TimeFormat;
192
+ readonly locale: string;
193
+ /** Extra room above the plot, in pixels, for labels drawn along its top edge. */
194
+ readonly topInset?: number | undefined;
195
+ /** A left margin shared with other plots, from `valueGutter`. The plot never takes less. */
196
+ readonly gutter?: number | undefined;
197
+ /** True when the plot draws its value-axis title, so the margin holds it and the ticks leave the unit to it. */
198
+ readonly hasValueTitle?: boolean | undefined;
199
+ };
200
+ /**
201
+ * The layout of a plot of values over time: elapsed time along the bottom, on round clock steps, and a measured value
202
+ * up the side. Its scales and ticks match `numericPlot`, so a time series and a curve placed side by side read alike.
203
+ */
204
+ export declare function timePlot({ width, height, value, valueDomain, timeDomain, timeFormat, locale, topInset, gutter, hasValueTitle, }: TimePlotInput): NumericPlotLayout;
205
+ export type TimeAxisTicksInput = {
206
+ /** The first and last instant, in milliseconds since the epoch. */
207
+ readonly domain: NumericDomain;
208
+ /** The axis length in pixels. */
209
+ readonly length: number;
210
+ readonly timeFormat: TimeFormat;
211
+ readonly locale: string;
212
+ /** The zone whose clock steps the ticks land on, for a function format. Options formats name their own zone. */
213
+ readonly timeZone?: string | undefined;
214
+ };
215
+ /**
216
+ * The ticks of a time axis: instants on round clock steps in the format's zone, at least three on an axis longer than
217
+ * 120 pixels. When two ticks would read alike, such as two midnights written "00:00", the labels gain the date, then
218
+ * the year, then seconds. Fields the format sets itself stay as it sets them, and a function format is used as
219
+ * supplied.
220
+ */
221
+ export declare function timeAxisTicks({ domain, length, timeFormat, locale, timeZone }: TimeAxisTicksInput): AxisTicks;
@@ -0,0 +1,124 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ChartTone } from '../../../foundations/src/chart-tones.ts';
3
+ /** A solid stroke is an observation. A dashed one is modelled: a fit, a projection, a baseline or a target. */
4
+ export type MarkStroke = 'solid' | 'dashed';
5
+ /** How much a mark asks for attention: itself, gray context behind the subject, or receded while another is focused. */
6
+ export type MarkEmphasis = 'normal' | 'context' | 'receded';
7
+ /** What a pointer or the application has done to a mark. */
8
+ export type MarkState = {
9
+ readonly isInspected?: boolean | undefined;
10
+ readonly isSelected?: boolean | undefined;
11
+ };
12
+ export type LineMarkProps = {
13
+ /** The path from `linePath`. */
14
+ readonly d: string;
15
+ readonly tone: ChartTone;
16
+ readonly stroke?: MarkStroke | undefined;
17
+ readonly emphasis?: MarkEmphasis | undefined;
18
+ };
19
+ /** A line through ordered observations. Its hue names the series. */
20
+ export declare function LineMark({ d, tone, stroke, emphasis }: LineMarkProps): ReactNode;
21
+ export type AreaMarkProps = Omit<LineMarkProps, 'stroke'> & {
22
+ /** True for areas drawn over one another, not stacked. A pale fill under the series line keeps each visible. */
23
+ readonly isPale?: boolean | undefined;
24
+ };
25
+ /** A filled amount, such as a stacked area or a density. Its height carries the value. */
26
+ export declare function AreaMark({ d, tone, emphasis, isPale }: AreaMarkProps): ReactNode;
27
+ /** A pale band of uncertainty around a line: an interval, a spread across seeds or a range of runs. */
28
+ export declare function BandMark({ d, tone, emphasis }: Omit<LineMarkProps, 'stroke'>): ReactNode;
29
+ export type DotMarkProps = MarkState & {
30
+ readonly x: number;
31
+ readonly y: number;
32
+ readonly tone: ChartTone;
33
+ readonly radius?: number | undefined;
34
+ /** True for a value that is missing, masked or excluded: an outline with no fill. */
35
+ readonly isHollow?: boolean | undefined;
36
+ readonly emphasis?: MarkEmphasis | undefined;
37
+ };
38
+ /** One observation at a position. */
39
+ export declare function DotMark({ x, y, tone, radius, isHollow, emphasis, isInspected, isSelected, }: DotMarkProps): ReactNode;
40
+ export type BarMarkProps = MarkState & {
41
+ readonly x: number;
42
+ readonly y: number;
43
+ readonly width: number;
44
+ readonly height: number;
45
+ readonly tone: ChartTone;
46
+ readonly isHollow?: boolean | undefined;
47
+ readonly emphasis?: MarkEmphasis | undefined;
48
+ };
49
+ /** A rectangle whose length carries an amount from a zero baseline, or whose area fills a cell. */
50
+ export declare function BarMark({ x, y, width, height, tone, isHollow, emphasis, isInspected, isSelected, }: BarMarkProps): ReactNode;
51
+ /** The outline of a symbol: a shape names a kind of record, so it never relies on hue alone. */
52
+ export type SymbolShape = 'circle' | 'square' | 'diamond';
53
+ export type SymbolMarkProps = DotMarkProps & {
54
+ readonly shape: SymbolShape;
55
+ };
56
+ /**
57
+ * One record drawn as a circle, a square or a diamond, such as a node whose kind the shape names. A hollow symbol is
58
+ * missing, masked or unexplained. Use `DotMark` when every record has the same kind.
59
+ */
60
+ export declare function SymbolMark({ shape, x, y, tone, radius, isHollow, emphasis, isInspected, isSelected, }: SymbolMarkProps): ReactNode;
61
+ export type LinkMarkProps = {
62
+ /** The path from `linkPath`. */
63
+ readonly d: string;
64
+ readonly tone: ChartTone;
65
+ /** The stroke width in CSS pixels. A width that carries a magnitude, such as an edge weight, needs a legend. */
66
+ readonly width?: number | undefined;
67
+ readonly stroke?: MarkStroke | undefined;
68
+ readonly emphasis?: MarkEmphasis | undefined;
69
+ };
70
+ /**
71
+ * A link between two marks: an edge of a graph or a branch of a tree. Gray context suits a structure; two hues around
72
+ * neutral suit a signed weight. Draw only links the application supplied: position never implies one.
73
+ */
74
+ export declare function LinkMark({ d, tone, width, stroke, emphasis, }: LinkMarkProps): ReactNode;
75
+ export type Segment = {
76
+ readonly x1: number;
77
+ readonly y1: number;
78
+ readonly x2: number;
79
+ readonly y2: number;
80
+ };
81
+ /**
82
+ * A straight guide in ink: a threshold, a target or a reference value. Dashed when the value is modelled. A tone colors
83
+ * a guide the legend names, such as a budget drawn in the same hue as its legend entry.
84
+ */
85
+ export declare function RuleMark({ x1, y1, x2, y2, stroke, tone, }: Segment & {
86
+ readonly stroke?: MarkStroke | undefined;
87
+ readonly tone?: ChartTone | undefined;
88
+ }): ReactNode;
89
+ /**
90
+ * A faint dotted segment that carries a level from one mark to the next, such as a running total between the columns of
91
+ * a bridge. It claims no value of its own, so it stays lighter than a `RuleMark`.
92
+ */
93
+ export declare function ConnectorMark({ x1, y1, x2, y2 }: Segment): ReactNode;
94
+ /** A segment in a series' hue: an interval between two bounds, a whisker, or the link between two paired values. */
95
+ export declare function IntervalMark({ x1, y1, x2, y2, tone, emphasis, }: Segment & {
96
+ readonly tone: ChartTone;
97
+ readonly emphasis?: MarkEmphasis | undefined;
98
+ }): ReactNode;
99
+ export type LabelMarkProps = {
100
+ readonly x: number;
101
+ readonly y: number;
102
+ readonly anchor?: 'start' | 'middle' | 'end' | undefined;
103
+ /** The series the label names, when it sits at the end of that series' line in place of a legend entry. */
104
+ readonly tone?: ChartTone | undefined;
105
+ /** True for a label that states a total rather than a part, such as the start and end columns of a bridge. */
106
+ readonly isStrong?: boolean | undefined;
107
+ readonly children: string;
108
+ };
109
+ /** Text drawn in the plot beside the mark it names, with a halo so it stays readable over marks and grid lines. */
110
+ export declare function LabelMark({ x, y, anchor, tone, isStrong, children }: LabelMarkProps): ReactNode;
111
+ /**
112
+ * A faint dotted vertical guide: the position a reader inspects, a flagged period, or an event named beside it. It
113
+ * claims no value, so it stays lighter than a `RuleMark`.
114
+ */
115
+ export declare function GuideMark({ x, top, bottom, }: {
116
+ readonly x: number;
117
+ readonly top: number;
118
+ readonly bottom: number;
119
+ }): ReactNode;
120
+ /** A ring in ink that points out one spot on a line: an annotated observation, or where the line reaches a value. */
121
+ export declare function RingMark({ x, y }: {
122
+ readonly x: number;
123
+ readonly y: number;
124
+ }): ReactNode;
@@ -0,0 +1,32 @@
1
+ import type { PointerEventHandler, ReactNode, Ref } from 'react';
2
+ import type { PlotBox, PlotHeight } from './plot-layout.ts';
3
+ /** Measures a plot: the width its container gives it and the named height its figure chose. */
4
+ export declare function usePlotSize(height?: PlotHeight): {
5
+ readonly ref: Ref<HTMLDivElement>;
6
+ readonly width: number;
7
+ readonly height: number;
8
+ };
9
+ export type PlotSurfaceProps = {
10
+ /** The ref from `usePlotSize`. */
11
+ readonly plotRef: Ref<HTMLDivElement>;
12
+ readonly box: PlotBox;
13
+ /** The plot's accessible name. Build it with `plotLabel`, so every chart explains its keys the same way. */
14
+ readonly label: string;
15
+ /** The id of the readout that states the inspected mark's exact values. */
16
+ readonly readoutId: string;
17
+ /** The SVG marks, axes and guides. */
18
+ readonly children: ReactNode;
19
+ /** HTML drawn over the marks in the same pixel space, such as a canvas layer or point targets. */
20
+ readonly overlay?: ReactNode;
21
+ readonly onPointerDown?: PointerEventHandler<SVGSVGElement> | undefined;
22
+ };
23
+ /**
24
+ * The plot of a chart: one Tab stop that owns the keyboard cursor, pointer inspection and dismissal for the marks drawn
25
+ * inside it. Use it inside `Chart`, which supplies the items.
26
+ */
27
+ export declare function PlotSurface({ plotRef, box, label, readoutId, children, overlay, onPointerDown, }: PlotSurfaceProps): ReactNode;
28
+ /** Keeps marks inside the axes. Wrap the marks, never the axes or the labels beside them. */
29
+ export declare function PlotClip({ box, children }: {
30
+ readonly box: PlotBox;
31
+ readonly children: ReactNode;
32
+ }): ReactNode;
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { PlotBox } from '../plot-layout.ts';
3
+ export type DensityLayerProps = {
4
+ /** The plot the layer covers. The grid fills its drawing area, inside the axes. */
5
+ readonly box: PlotBox;
6
+ readonly columns: number;
7
+ readonly rows: number;
8
+ /** One value per cell, row by row. Row 0 is the bottom row and column 0 the leftmost. */
9
+ readonly counts: ReadonlyArray<number>;
10
+ /** The value drawn with the full hue. Zero draws nothing; values between draw lighter shades of the same hue. */
11
+ readonly maximum: number;
12
+ };
13
+ /**
14
+ * A grid of cell values drawn on one canvas as the lightness of one hue, for a 2D histogram such as `DensityMap`. It
15
+ * draws a 512 by 512 grid in one image copy, matches the matrix heatmap's sequential colors, and follows the theme.
16
+ */
17
+ export declare function DensityLayer({ box, columns, rows, counts, maximum }: DensityLayerProps): ReactNode;
@@ -0,0 +1,37 @@
1
+ import type { NumericDomain } from '../scale.ts';
2
+ /**
3
+ * Many points as plain columns: the nth point sits at `x[n]`, `y[n]` in data units and belongs to the group at index
4
+ * `group[n]`. Columns keep a million points cheap to hold, send and draw.
5
+ */
6
+ export type PointColumns = {
7
+ readonly x: ReadonlyArray<number>;
8
+ readonly y: ReadonlyArray<number>;
9
+ readonly group: ReadonlyArray<number>;
10
+ };
11
+ /** A rectangle in data units. */
12
+ export type DataRect = {
13
+ readonly x: NumericDomain;
14
+ readonly y: NumericDomain;
15
+ };
16
+ /** Where to look for a point: a position in data units and how far to look along each axis, also in data units. */
17
+ export type HitQuery = {
18
+ readonly x: number;
19
+ readonly y: number;
20
+ readonly radiusX: number;
21
+ readonly radiusY: number;
22
+ };
23
+ /** Finds the point nearest a position, such as the one under a pointer, without visiting every point. */
24
+ export type HitIndex = {
25
+ /** The index of the nearest point inside the query's ellipse, or undefined when none lies there. */
26
+ readonly nearest: (query: HitQuery) => number | undefined;
27
+ };
28
+ /**
29
+ * A uniform grid over the points' domain. Building it visits each point twice; a query visits only the points in the
30
+ * cells its ellipse touches. Rebuild it when the points change, not when the view pans or zooms.
31
+ */
32
+ export declare function hitIndex({ points, domain }: {
33
+ readonly points: PointColumns;
34
+ readonly domain: DataRect;
35
+ }): HitIndex;
36
+ /** How many points lie inside a rectangle, edges included. */
37
+ export declare function countInside(points: PointColumns, rect: DataRect): number;
@@ -0,0 +1,39 @@
1
+ import type { ChangeDetails, Viewport, ViewportReason } from '@ui-sdk/core';
2
+ import type { PartProps } from '@ui-sdk/react/primitive';
3
+ import type { ReactNode } from 'react';
4
+ import type { PlotBox } from '../plot-layout.ts';
5
+ import type { ContinuousScale, NumericDomain } from '../scale.ts';
6
+ /** Where an explored plot looks: its pan in CSS pixels and its zoom, where 1 shows the whole domain. */
7
+ export type PlotView = Viewport;
8
+ /** Why the view moved: a drag, a pinch, a modifier and scroll, a zoom key, the reset button or an agent's call. */
9
+ export type PlotViewDetails = ChangeDetails<ViewportReason>;
10
+ export type PlotViewportOptions = {
11
+ /** The view now. The application or the chart holds it and passes back what `onViewChange` asks for. */
12
+ readonly view: PlotView;
13
+ readonly onViewChange: (view: PlotView, details: PlotViewDetails) => void;
14
+ /** False leaves every gesture to the page and the chart: scrolling scrolls, dragging draws. */
15
+ readonly isEnabled: boolean;
16
+ /** How far the view zooms in. It never zooms out past the whole domain. */
17
+ readonly maxZoom?: number | undefined;
18
+ };
19
+ /** The view that shows the whole domain. */
20
+ export declare const WHOLE_VIEW: Readonly<PlotView>;
21
+ export type PlotViewportRootProps = PlotViewportOptions & Omit<PartProps<'div'>, 'id'>;
22
+ /**
23
+ * Pans and zooms a plot with the UI SDK viewport. A drag pans, a pinch or Control or Command with a scroll zooms, and
24
+ * `+`, `−` and `0` zoom from the keyboard while the plot has focus. Wrap the plot in it and put `PlotViewportSurface`
25
+ * over the drawing area, and the caller holds `view` so a reset button sets it back to `WHOLE_VIEW`.
26
+ */
27
+ export declare function PlotViewportRoot({ view, onViewChange, isEnabled, maxZoom, ...props }: PlotViewportRootProps): ReactNode;
28
+ /** The area that takes the pan and zoom gestures: the plot's drawing area, inside its axes. */
29
+ export declare function PlotViewportSurface(props: Omit<PartProps<'div'>, 'id'>): ReactNode;
30
+ /** The part of each axis's domain an explored plot shows, from the scales that show the whole domain. */
31
+ export declare function visibleDomains({ view, box, x, y, }: {
32
+ readonly view: PlotView;
33
+ readonly box: PlotBox;
34
+ readonly x: ContinuousScale;
35
+ readonly y: ContinuousScale;
36
+ }): {
37
+ readonly x: NumericDomain;
38
+ readonly y: NumericDomain;
39
+ };
@@ -0,0 +1,41 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ChartTone } from '../../../../foundations/src/chart-tones.ts';
3
+ import type { PlotBox } from '../plot-layout.ts';
4
+ import type { ContinuousScale } from '../scale.ts';
5
+ import type { PointColumns } from './hit-index.ts';
6
+ /** How a point layer draws: canvas 2D for up to about a hundred thousand points, WebGL for up to about a million. */
7
+ export type PointRenderer = 'canvas' | 'webgl';
8
+ /** Where data values land on one axis: its domain and the CSS pixels it spans. A point layer maps both linearly. */
9
+ export type PointAxis = Pick<ContinuousScale, 'domain' | 'range'>;
10
+ /** What one finished draw reports: the renderer that drew, which is canvas when WebGL is unavailable, and its cost. */
11
+ export type PointDraw = {
12
+ readonly renderer: PointRenderer;
13
+ /** Main-thread time spent issuing the draw, in milliseconds. */
14
+ readonly milliseconds: number;
15
+ readonly points: number;
16
+ };
17
+ export type PointLayerProps = {
18
+ /** The plot the layer covers. Points draw inside its axes only. */
19
+ readonly box: PlotBox;
20
+ /** The points in data units, with each point's group as an index into `tones`. */
21
+ readonly points: PointColumns;
22
+ readonly x: PointAxis;
23
+ readonly y: PointAxis;
24
+ /** One tone per group, at most 16. */
25
+ readonly tones: ReadonlyArray<ChartTone>;
26
+ /** A group drawn in its hue on top, while every other group recedes to gray context. */
27
+ readonly highlight?: number | null | undefined;
28
+ /** The radius of each point, in CSS pixels. */
29
+ readonly radius?: number | undefined;
30
+ /** The opacity of each point, from 0 to 1, so dense regions read darker than sparse ones. */
31
+ readonly opacity?: number | undefined;
32
+ readonly renderer: PointRenderer;
33
+ /** Hears each finished draw, including which renderer drew it, so the chart can say when WebGL was unavailable. */
34
+ readonly onDraw?: ((draw: PointDraw) => void) | undefined;
35
+ };
36
+ /**
37
+ * Many points drawn on a canvas over a plot: up to about a hundred thousand with canvas 2D, up to about a million with
38
+ * WebGL in one draw call. Put it in `PlotSurface`'s `overlay`, beside the SVG axes. Its colors follow the theme, and
39
+ * when WebGL is unavailable it draws with canvas and says so through `onDraw`.
40
+ */
41
+ export declare function PointLayer(props: PointLayerProps): ReactNode;
@@ -0,0 +1,15 @@
1
+ /** A color as a canvas draws it: red, green, blue and alpha, each from 0 to 255. */
2
+ export type DrawColor = readonly [red: number, green: number, blue: number, alpha: number];
3
+ /**
4
+ * The concrete colors of theme colors, such as `chartToneColors[tone]`, where `element` sits in the page. A canvas
5
+ * cannot read CSS custom properties, so a layer resolves its colors here before each draw.
6
+ */
7
+ export declare function resolveColors(element: HTMLElement, colors: ReadonlyArray<string>): ReadonlyArray<DrawColor>;
8
+ /** A color with its channels from 0 to 1, as a shader takes it. */
9
+ export declare function unitColor([red, green, blue, alpha]: DrawColor): DrawColor;
10
+ /**
11
+ * A number that changes whenever the colors or the pixel density under `element` may have changed. The causes are a
12
+ * theme class on an ancestor, the system color scheme, or the window moving to a screen with another pixel ratio. A
13
+ * canvas layer redraws when it changes.
14
+ */
15
+ export declare function useDrawRevision(element: HTMLElement | null): number;