@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
@@ -1,63 +1,384 @@
1
1
  # Charts
2
2
 
3
- Import shared frames, legends and tones from `@mechane-ai/elements/charts`, and each plot from its own entry. The
4
- application queries, aggregates, ranks and samples. A chart draws supplied measurements and lets a reader inspect them.
3
+ Import shared props, formats, tone scope and linking from `@mechane-ai/elements/charts`, and each chart from its family
4
+ entry. The application queries, aggregates, ranks, samples and computes statistics. A chart draws supplied values and
5
+ lets a reader inspect them. To describe a figure as JSON, read [figures](figures.md). For ready-made domain pages, read
6
+ [kits](kits.md).
7
+
8
+ ## How every chart works
9
+
10
+ - One kernel draws all of them, so axes, ticks, marks, readout and keyboard cursor behave alike.
11
+ - Every chart takes the same figure props: `title`, `description`, `locale`, `source`, `coverage`, `transforms`,
12
+ `status`, `emptyLabel`, `report` and `actions`.
13
+ - A number or an instant is written from a declared format and the figure's `locale`. A format is data, not a function.
14
+ - Each visual channel has one meaning: hue names a thing, lightness is a magnitude, two hues around a neutral middle are
15
+ a signed value, a dashed stroke is modelled, a pale band is uncertainty, a hollow mark is missing, gray is context.
16
+ - Every figure has the same states: loading, empty, invalid, partial and ready.
5
17
 
6
18
  ## Choose the chart
7
19
 
8
- | The reader asks | Use | Entry |
9
- | -------------------------------------------- | ----------------------------------------------- | ------------------------------------------- |
10
- | How did it move over time? | `LineChart`, `AreaChart` | `/charts/cartesian` |
11
- | The same period for several measures | `SmallMultiples` | `/charts/cartesian` |
12
- | A trend inside a metric row, not inspectable | `Sparkline` | `/charts/cartesian` |
13
- | How do categories compare? | `BarChart`, or `RankedBars` in a supplied order | `/charts/cartesian`, `/charts/distribution` |
14
- | What makes up one total? | `BreakdownBar`, or `Treemap` for many parts | `/charts/cartesian`, `/charts/hierarchy` |
15
- | How did a total become another total? | `BridgeChart` | `/charts/cartesian` |
16
- | Where does an amount flow between stages? | `FlowDiagram` | `/charts/graph` |
17
- | How are values distributed? | `Histogram`, `ECDF`, `IntervalPlot` | `/charts/distribution` |
18
- | How do two measures relate per record? | `ScatterPlot` | `/charts/cartesian` |
19
- | A value for every pair of two indexes | `Matrix`, `TokenHeatmap`, with `ColorLegend` | `/charts/matrix` |
20
- | Which records connect to which? | `RelationGraph` | `/charts/graph` |
21
- | How long did each step take, and when? | `Waterfall` | `/charts/timeline` |
22
-
23
- Use a table when exact comparison matters more than shape.
20
+ Pick by the question. The tables are the library's `chartGuide`, written out: one entry per registered chart, 50 in all,
21
+ grouped by family. `chartGuide` is exported from `@mechane-ai/elements/charts/figure`, so you can read the same guidance
22
+ at run time. Each entry has `chart`, `family`, `question`, `use`, `avoid` and `example`, a small valid figure spec to
23
+ start from.
24
+
25
+ ```ts
26
+ import { chartGuide } from '@mechane-ai/elements/charts/figure';
27
+
28
+ const entry = chartGuide.find((item) => item.chart === 'DotPlot');
29
+ ```
30
+
31
+ `ColorLegend` (`/charts/matrix`), the table cells (`/charts/cells`: `BarCell`, `HeatCell`, `ChangeCell`, `IntervalCell`
32
+ and `SparkCell`), the placeholders and the kits are not registered charts, so the guide does not list them. Use a bar,
33
+ heat, change, interval or spark cell for a graphic inside a table column. Use a table when exact comparison matters more
34
+ than shape.
35
+
36
+ ### `trend`
37
+
38
+ Import from `@mechane-ai/elements/charts/trend`.
39
+
40
+ | Chart | Shows | Use it when | Another chart is better when |
41
+ | -------------- | ------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
42
+ | `CurveChart` | How did a metric change over training steps or another ordered variable? | Use it for loss, accuracy or any measure over steps, layers or doses, on linear or log axes, with bands for spread across seeds. | Use LineChart when the ordered variable is a timestamp, and RunsChart when there are dozens of runs to show as context. |
43
+ | `RunsChart` | How does one run compare with the whole sweep it belongs to? | Use it for many training runs at once: every run stays gray context and only the runs you name are drawn in color. | Use CurveChart for a handful of series that each deserve a color and a legend entry. |
44
+ | `SlopeChart` | How did each item move between two to six conditions? | Use it to compare before and after, or a few checkpoints, where the direction of each change matters more than the path. | Use DumbbellPlot when there are many rows and exactly two conditions, and CurveChart when the conditions are many ordered steps. |
45
+ | `BumpChart` | How did the ranking of items change across stages? | Use it when the order matters more than the values: a leaderboard over releases, or model rank per evaluation round. | Use SlopeChart or CurveChart when the size of the gaps between items matters. |
46
+ | `HorizonChart` | Which of many series run above or below normal, and when? | Use it for dozens of aligned series in little height, such as the error rate of every service over a day. | Use LineChart or SmallMultiples when there are only a few series and readers need exact levels. |
47
+
48
+ ### `comparison`
49
+
50
+ Import from `@mechane-ai/elements/charts/comparison`.
51
+
52
+ | Chart | Shows | Use it when | Another chart is better when |
53
+ | -------------- | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
54
+ | `DotPlot` | How do a few models compare on each of several measures? | Use it to compare values across categories without bars, when the axis need not start at zero and intervals matter. | Use BarChart when the amount itself, measured from zero, is the point. |
55
+ | `DumbbellPlot` | How much did each row change between two measurements? | Use it for many rows with exactly two values each, such as scores before and after fine-tuning. | Use SlopeChart for few rows or more than two conditions, and BridgeChart for how parts add up to a total change. |
56
+ | `BulletBar` | Is each measure meeting its target? | Use it for a few key measures held against targets and qualitative bands, such as latency against its objective. | Use BarChart when there are no targets, and a table when readers need many exact values. |
57
+
58
+ ### `cartesian`
59
+
60
+ Import from `@mechane-ai/elements/charts/cartesian`.
61
+
62
+ | Chart | Shows | Use it when | Another chart is better when |
63
+ | ---------------- | ----------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
64
+ | `BarChart` | How large is each amount, by category and series? | Use it for amounts measured from zero across a few categories, grouped or stacked by series. | Use DotPlot when the values do not start at zero, and LineChart when the categories are instants. |
65
+ | `BridgeChart` | Which changes add up to the difference between two totals? | Use it to explain a change from one total to another as a sequence of signed parts, such as cost by cause. | Use BarChart when the parts are independent amounts, not steps from one total to the next. |
66
+ | `BreakdownBar` | How does one total split into parts? | Use it for a single total and a few named parts, such as where the time of a request went. | Use Treemap for many parts, and BarChart to compare several totals. |
67
+ | `ScatterPlot` | How do two measures of the same records relate? | Use it for up to a thousand records with two measures each, such as cost and accuracy per model. | Use EmbeddingMap or DensityMap for many thousands of points, and ScatterMatrix for more than two measures. |
68
+ | `LineChart` | How did a measure change over time? | Use it for a few series over timestamps, such as latency per minute or requests per hour. | Use CurveChart when the ordered variable is not time, and HorizonChart for dozens of series. |
69
+ | `AreaChart` | How did a total and its parts change over time? | Use it stacked for parts that add up to a meaningful total over time, such as requests by region. | Use LineChart when the series do not add up, or when readers compare series that are not at the bottom. |
70
+ | `SmallMultiples` | How do several related measures move together over the same time? | Use it for a few measures with different units on one shared time axis, inspected together. | Use LineChart when the series share one unit and belong on one plot. |
71
+ | `Sparkline` | Which way is one measure trending, at a glance? | Use it inline beside a number or in a dense summary, where a full chart would be too much. | Use LineChart when readers need axes, exact values or several series. |
72
+
73
+ ### `distribution`
74
+
75
+ Import from `@mechane-ai/elements/charts/distribution`.
76
+
77
+ | Chart | Shows | Use it when | Another chart is better when |
78
+ | -------------- | ----------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
79
+ | `Histogram` | How are the values of one measure distributed? | Use it for the shape of one distribution from prepared bins, such as response lengths or latencies. | Use ECDF to read percentiles exactly, and BoxPlot or ViolinPlot to compare several groups. |
80
+ | `ECDF` | What share of values falls below a given level? | Use it to read percentiles and compare tails exactly, such as the share of requests under a latency objective. | Use Histogram when the shape of the distribution matters more than its percentiles. |
81
+ | `IntervalPlot` | What is each estimate, and how uncertain is it? | Use it for estimates with confidence or credible intervals, such as an effect size per benchmark. | Use DotPlot to compare several series per row, and BoxPlot to show the spread of raw values. |
82
+ | `RankedBars` | Which items rank highest on one measure? | Use it for a sorted top list, such as the features or prompts with the largest effect. | Use BarChart when the categories have a natural order, and DotPlot when values do not start at zero. |
83
+ | `BoxPlot` | How do the distributions of several groups compare? | Use it for prepared quartiles of a handful of groups, such as latency per region, with outliers marked. | Use ViolinPlot when the shape matters, and StripPlot when there are few enough values to show each. |
84
+ | `ViolinPlot` | How does the shape of a distribution differ between groups? | Use it for prepared densities of a few groups when bimodality or skew matters, such as reward per policy. | Use BoxPlot when quartiles are enough, and Ridgeline for many groups in order. |
85
+ | `StripPlot` | Where does every single value of each group fall? | Use it when there are few enough values to show each one, such as the score of every seed. | Use BoxPlot or ViolinPlot when there are hundreds of values per group. |
86
+ | `Ridgeline` | How does a distribution shift across many ordered groups? | Use it for prepared densities of many groups in order, such as activation values per layer. | Use ViolinPlot for a few unordered groups, and Histogram for one distribution. |
87
+
88
+ ### `matrix`
89
+
90
+ Import from `@mechane-ai/elements/charts/matrix`.
91
+
92
+ | Chart | Shows | Use it when | Another chart is better when |
93
+ | ------------------- | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
94
+ | `Matrix` | What is the value for every pair of two categories? | Use it for a measured value per row and column, such as accuracy per model and benchmark, with missing cells marked. | Use ConfusionMatrix, CorrelationMatrix or AttentionMatrix for those specific matrices, and DotPlot for few rows. |
95
+ | `TokenHeatmap` | Which tokens of a text carry the most of a score? | Use it to shade a passage by a per-token value, such as a feature’s activation or a token’s loss. | Use TokenExamples for several passages, and TokenPredictions for the next-token distribution. |
96
+ | `ConfusionMatrix` | Which classes does a classifier confuse with which? | Use it for counts of true against predicted classes, raw or normalized per true class. | Use Matrix for any other value per pair, and BarChart for per-class accuracy alone. |
97
+ | `CorrelationMatrix` | Which measures move together? | Use it for prepared correlation coefficients between a few measures, such as benchmark scores across models. | Use ScatterMatrix to see the points behind each coefficient. |
98
+ | `AttentionMatrix` | Which earlier tokens does each token attend to? | Use it for one head’s attention weights over a short sequence, with the causal mask shown. | Use TokenLinks to read the strongest links as lines between two rows of the text. |
99
+ | `CalendarHeatmap` | How does a daily measure vary by week and weekday? | Use it for one value per day over weeks or months, such as daily evaluation runs or incidents. | Use LineChart when the trend matters more than the weekly pattern. |
100
+
101
+ ### `graph`
102
+
103
+ Import from `@mechane-ai/elements/charts/graph`.
104
+
105
+ | Chart | Shows | Use it when | Another chart is better when |
106
+ | ------------------ | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
107
+ | `RelationGraph` | How are a few named things connected? | Use it for a small graph whose positions the application lays out, such as services and their calls. | Use FlowDiagram when links carry amounts, and TreeDiagram for a strict hierarchy. |
108
+ | `FlowDiagram` | Where does a quantity go between stages? | Use it for amounts flowing between stages, such as requests from source through filter to outcome. | Use BridgeChart for changes to one total, and RelationGraph when links carry no amount. |
109
+ | `AttributionGraph` | Which features carry a model’s answer from the prompt to the output? | Use it for an attribution graph: tokens, features by layer and the output, with signed edge weights. | Use FlowDiagram for amounts that are conserved between stages, and TokenLinks for token-to-token weights. |
110
+ | `TreeDiagram` | How is a hierarchy structured? | Use it to show parent and child relations, such as a run’s spans or an agent’s plan, when the structure is the point. | Use Treemap or Icicle when each node carries an amount readers should compare. |
111
+
112
+ ### `hierarchy`
113
+
114
+ Import from `@mechane-ai/elements/charts/hierarchy`.
115
+
116
+ | Chart | Shows | Use it when | Another chart is better when |
117
+ | --------- | --------------------------------------------- | ------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------- |
118
+ | `Treemap` | Which parts make up most of a total? | Use it for many parts of one total where the large parts matter, such as spend by project. | Use BreakdownBar for a few parts, Icicle for nested levels and RankedBars to compare parts exactly. |
119
+ | `Icicle` | How does a total split through nested levels? | Use it for a hierarchy whose nodes carry amounts, such as time spent per span of a trace. | Use Treemap for one level of many parts, and TreeDiagram when there are no amounts. |
120
+
121
+ ### `timeline`
122
+
123
+ Import from `@mechane-ai/elements/charts/timeline`.
124
+
125
+ | Chart | Shows | Use it when | Another chart is better when |
126
+ | ------------ | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
127
+ | `Waterfall` | When did each step of a request or run start and end? | Use it for the recorded timing of many steps on one scale, with exact timing stated for each row. | Use EventStrip for events in a few lanes over a long window, and BreakdownBar for totals per step. |
128
+ | `EventStrip` | What happened when, across a few kinds of events? | Use it for deploys, incidents, runs and alerts over hours or days, where overlaps between lanes matter. | Use Waterfall for the steps of one request, and LineChart for a measured value over time. |
129
+
130
+ ### `relationship`
131
+
132
+ Import from `@mechane-ai/elements/charts/relationship`.
133
+
134
+ | Chart | Shows | Use it when | Another chart is better when |
135
+ | --------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------ |
136
+ | `ContourPlot` | What does a value look like over two continuous inputs? | Use it for a prepared grid over two inputs, such as loss over two hyperparameters, with an optimizer’s path. | Use DensityMap for counts of points, and Matrix for a value per pair of categories. |
137
+ | `ScatterMatrix` | How do several measures relate to each other, pair by pair? | Use it for up to six measures of a few hundred records, such as cost, latency and accuracy per model. | Use ScatterPlot for one pair, ParallelCoordinates for many measures, and CorrelationMatrix for coefficients alone. |
138
+ | `ParallelCoordinates` | Which records do well on many measures at once? | Use it to filter records across many measures, such as hyperparameter trials by their settings and score. | Use ScatterMatrix to see pairwise relations, and a table for exact values. |
139
+ | `EmbeddingMap` | How do many items cluster in a learned embedding space? | Use it for thousands to a million projected points with groups and landmarks, drawn on canvas or WebGL. | Use ScatterPlot when every point needs to be inspected by name, and DensityMap when only density matters. |
140
+ | `DensityMap` | Where are points concentrated over two measures? | Use it for prepared two-dimensional counts of very many points, such as prompt length against latency. | Use ScatterPlot when there are few enough points to show each, and ContourPlot for a measured surface. |
141
+
142
+ ### `text`
143
+
144
+ Import from `@mechane-ai/elements/charts/text`.
145
+
146
+ | Chart | Shows | Use it when | Another chart is better when |
147
+ | ------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
148
+ | `TokenExamples` | On which passages, and which tokens, does a feature fire? | Use it for the top activating examples of a feature, each passage shaded by activation around its peak. | Use TokenHeatmap for one passage, and TokenGrid to compare several values per token. |
149
+ | `TokenPredictions` | Which tokens does the model expect next, and how did that change? | Use it for the top next-token probabilities at one position, against a baseline such as before an intervention. | Use RankedBars for ranked values that are not token probabilities. |
150
+ | `TokenGrid` | How does a per-token value change across layers or conditions? | Use it for one value per token and row, such as a logit-lens probability per layer. | Use TokenHeatmap for a single row, and Matrix when the columns are not tokens. |
151
+ | `TokenLinks` | Which tokens most influence which later tokens? | Use it for the strongest token-to-token weights, such as attention or attribution, drawn as lines between two rows of the text. | Use AttentionMatrix to see every weight of a head. |
152
+
153
+ ### `image`
154
+
155
+ Import from `@mechane-ai/elements/charts/image`.
156
+
157
+ | Chart | Shows | Use it when | Another chart is better when |
158
+ | -------------------- | --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
159
+ | `ImageGrid` | What do a set of images look like, with a value for each? | Use it for a gallery of inputs or samples with a score each, such as a classifier’s most confident errors. | Use ImageAtlas when the images sit at positions in a two-dimensional layout. |
160
+ | `AttributionOverlay` | Which parts of an image drove the model’s output? | Use it for a saliency or attribution grid laid over one image, with an adjustable opacity. | Use ImageGrid to compare many images. |
161
+ | `ImageAtlas` | How do images arrange over a two-dimensional layout? | Use it for images placed on a grid by a projection or two factors, such as a feature visualization atlas. | Use ImageGrid for a plain gallery, and EmbeddingMap for many points without pictures. |
162
+
163
+ ## Shared props
164
+
165
+ Every chart except `Sparkline`, `Waterfall`, `ColorLegend` and the cells takes `FigureProps`. `Waterfall` takes `title`,
166
+ `report`, `locale` and `emptyLabel`.
167
+
168
+ | Prop | Meaning |
169
+ | ------------- | ----------------------------------------------------------------------------------------- |
170
+ | `title` | Required. What was measured. |
171
+ | `description` | A string. One or two sentences: the period or sample and how to read it. |
172
+ | `locale` | Required. The locale of every number and date, such as `"en-US"`. |
173
+ | `source` | Where the data came from. It goes in the footnote. |
174
+ | `coverage` | `{ shown, total, unit }` when the figure draws part of the data. It is stated by title. |
175
+ | `transforms` | What you did to the data, in words: `["Smoothed over 5 steps"]`. It goes in the footnote. |
176
+ | `status` | `'ready'`, `'loading'` or `'refreshing'`. Loading holds the final geometry. |
177
+ | `emptyLabel` | The sentence shown when there is nothing to draw. |
178
+ | `report` | Sets the figure in a bordered report with a summary. See "Compose a report". |
179
+ | `actions` | Controls beside the title. A React slot, so a JSON spec cannot carry it. |
180
+ | `height` | `'compact'` (160), `'regular'` (260) or `'tall'` (380). Never a number. |
181
+
182
+ Application state arrives as a value with a change callback that receives the change details:
183
+
184
+ - `selected` with `onSelectedChange(id, details)` for a record the reader pressed or chose with Enter.
185
+ - `range` with `onRangeChange(range, details)` for a drawn range. `LineChart` and `AreaChart` also need `rangeStep`, a
186
+ number in the timestamp unit. `ScatterPlot` needs `rangeStep={{ x, y }}`.
187
+ - `highlighted` for emphasis from outside, such as a table row. It does not change selection. `CurveChart`, `DotPlot`
188
+ and `BarChart` take the id of one series, or `null` for none. `RunsChart` takes `featured`, a required list of run ids
189
+ drawn in their hue.
190
+ - `inspected` with `onInspectedChange` on `ChartLink`.
191
+
192
+ ## Declare formats
193
+
194
+ A figure never takes `formatValue`, `formatX` or a similar function prop.
195
+
196
+ ```tsx
197
+ import { CurveChart } from '@mechane-ai/elements/charts/trend';
198
+
199
+ <CurveChart
200
+ title="Validation loss"
201
+ description="Synthetic runs. Bands span three seeds."
202
+ locale="en-US"
203
+ series={series}
204
+ x={{ label: 'Training step', scale: 'log', format: { maximumFractionDigits: 0 } }}
205
+ y={{ label: 'Loss (nats)', domain: [1, 5], format: { maximumFractionDigits: 2 } }}
206
+ source="Synthetic sweep"
207
+ transforms={['Mean of three seeds']}
208
+ />;
209
+ ```
210
+
211
+ - A measured axis is a `PlotAxis`: `{ label, domain?, scale?, format, tickFormat? }`. Put the unit in `label`. Leave
212
+ `domain` out to fit round bounds. `scale` is `'linear'`, `'log'` or `'symlog'`.
213
+ - A lone measure is `valueFormat` with an optional `tickFormat`. A time axis uses `timeFormat`.
214
+ - A `ValueFormat` is `Intl.NumberFormat` options. Ticks use its compact form unless you set `tickFormat`.
215
+ - A `TimeFormat` is `Intl.DateTimeFormat` options that name a `timeZone`. A function is allowed only where no option can
216
+ write the text, and a JSON figure spec cannot carry one.
217
+ - Timestamps reach `formatTime` in milliseconds. Set `timestampUnit` to `'seconds'` or `'milliseconds'`.
218
+
219
+ ## Newer props
220
+
221
+ - `valueLabel` is the value axis title on `LineChart`, `AreaChart`, each `SmallMultiples` panel, `BarChart` and
222
+ `BridgeChart`.
223
+ - `Sparkline` takes `layout` of `'inline'` or `'figure'`. `SparkCell` takes `label` of `'last'` or `'peak'`.
224
+ - `CurveChart` takes `markers`, a list of `{ x, label }`. `SmallMultiples` panels take `bands`.
225
+ - `EventStrip` takes `gutterWidth`. `eventStripGutter(labels)` returns one wide enough for every lane label, so stacked
226
+ strips line up.
227
+ - `Waterfall` draws in the shared frame and takes `description`, `actions`, `source` and `transforms`.
228
+ - `IntervalPlot` and `RankedBars` take `height`, the room per row. They write no value beside a row. The readout and the
229
+ exact-value table carry the values.
230
+ - `Matrix`, `AttentionMatrix`, `ConfusionMatrix` and `CorrelationMatrix` take `cellValues` of `'shown'` or `'hidden'`.
231
+ - Attention: the source is the token attended to and the destination is the token that attends. `AttentionMatrix` rows
232
+ are `destinations`, columns are `sources`, and `weights` has one line per destination. A `TokenLinks` link is
233
+ `{ sourceId, destinationId, weight }`, and `direction` is `'source-to-destination'`.
24
234
 
25
235
  ## Supply honest data
26
236
 
27
- - A formatter declares its locale, time zone, precision and unit. Use `formatTick` for compact axes and `formatValue`
28
- for exact readings.
29
- - A missing value is `null` and draws a gap. A zero is a zero. Never fill a gap to make a line continuous.
30
- - Time series need strictly increasing timestamps, with one observation per series at each timestamp.
31
- - A chart shows an error for invalid or oversized input. It never draws a partial chart that looks complete. Choose and
32
- label a window or an aggregate first; the entries export their limits, such as `timeSeriesLimits`.
237
+ - A missing value is `null`. It draws a hollow mark or a gap and reads "Unavailable". Never write it as zero.
238
+ - Bars, histograms and other length marks start at zero. Position marks such as dots need not.
239
+ - A log axis needs positive values and says so in its title. A symlog axis holds zero and negative values.
240
+ - A chart refuses invalid input with a stated reason and never repairs, clamps, reorders or drops a record.
241
+ - A chart takes prepared values. Compute quartiles, bins, densities, fits, smoothing and ranks first, with
242
+ `@mechane-ai/elements/charts/transforms`, and name each step in `transforms`.
243
+ - A figure that draws a sample or a window sets `coverage`, so the reader sees how much is shown.
244
+ - Grid data counts from the lowest value. `DensityMap` takes a `histogram` with one count per cell, row by row. Row 0
245
+ holds the lowest `y` and column 0 the lowest `x`, so rows count up from the bottom. The `bin2d` transform returns this
246
+ order.
33
247
  - The title and description say what was measured, and for which period or sample.
34
248
 
35
- ## Selection and ranges
249
+ ## Limits
250
+
251
+ Most charts export a limits object and refuse more with a message that names the limit. Choose a window or an aggregate
252
+ first. A selection of the limits:
253
+
254
+ | Chart | Limits |
255
+ | ------------------ | --------------------------------------------------------- |
256
+ | `LineChart` etc. | `timeSeriesLimits`: 12 series, 2000 points, 200 markers |
257
+ | `BarChart` etc. | 200 items and 12 series. The message names the limit. |
258
+ | `ScatterPlot` | `scatterLimits`: 1000 points |
259
+ | `Matrix` | `matrixLimits`: 4096 cells |
260
+ | `TokenHeatmap` | `tokenHeatmapLimits`: 2048 tokens |
261
+ | `RelationGraph` | `relationGraphLimits`: 256 nodes, 1024 edges |
262
+ | `FlowDiagram` | `flowLimits`: 64 nodes, 256 links |
263
+ | `CurveChart` | `curveLimits`: 12 series, 2000 points per series |
264
+ | `EmbeddingMap` | `embeddingLimits`: 100,000 canvas points, 1,000,000 WebGL |
265
+ | `EventStrip` | `eventStripLimits`: 12 lanes, 1000 events |
266
+ | `AttributionGraph` | `attributionLimits`: 400 nodes, 2000 edges, 40 layers |
267
+ | `TreeDiagram` | `treeLimits`: 300 nodes, depth 12 |
268
+
269
+ The others follow the same pattern, such as `boxLimits` and `runsLimits`. Read the declaration file of the chart you
270
+ use. `BarChart`, `BridgeChart`, `BreakdownBar` and `Treemap` share `categoricalLimits` from `/charts`, and `Histogram`,
271
+ `ECDF`, `IntervalPlot` and `RankedBars` share `distributionLimits` from `/charts/distribution`. `densityLimits` from
272
+ `/charts/relationship` bounds `DensityMap`, and `densityLimits` from `/charts/transforms` bounds a density estimate.
273
+
274
+ Marks a reader inspects one by one draw as SVG. `EmbeddingMap` draws on canvas up to 100,000 points and with WebGL up to
275
+ 1,000,000, and `DensityMap` draws on canvas. A canvas or WebGL plot keeps the same inspection, selection, readout and
276
+ text alternative. The WebGL figure was measured in a headless software renderer, not on a GPU.
277
+
278
+ ## Selection, inspection and ranges
279
+
280
+ Inspection is built in. A plot is one Tab stop. Hover or the arrow keys inspect, Home and End reach the ends, a press or
281
+ Enter selects, a drag draws a range and Escape closes the readout. Pan and zoom are opt-in, as `isExplorable` on
282
+ `EmbeddingMap`, and a plain scroll always scrolls the page. Do not add your own tooltip or key handler.
283
+
284
+ ```tsx
285
+ <RankedBars
286
+ title="Top error sources"
287
+ locale="en-US"
288
+ items={items}
289
+ value={{ label: 'Share of errors', format: { style: 'percent' } }}
290
+ selected={selectedId}
291
+ onSelectedChange={(id) => setSelectedId(id)}
292
+ />
293
+ ```
36
294
 
37
- Inspection is built in. A plot is one Tab stop. Arrow keys, Home and End move a cursor, the readout shows exact values,
38
- and Escape closes it. Hover and touch do the same. Do not add your own tooltip or key handler.
295
+ The app owns the linked inspector, route or filter. Leave `onSelectedChange` out for a read-only figure. `Waterfall`
296
+ requires it.
39
297
 
40
- Pass `selection={{ selectedId, onSelect }}` when a click or Enter should select a record. The chart reports an
41
- identifier and the change details. The app owns the linked inspector, route or filter. Leave `selection` out for a
42
- read-only graphic. On bars, bridge columns and treemap cells the selected mark keeps an ink edge while another mark is
43
- inspected.
298
+ ## Link figures and keep one hue per thing
44
299
 
45
- `LineChart` and `AreaChart` take `rangeSelection={{ value, onChange, step }}` for a time range the reader draws, moves
46
- and resizes. The range is application state in the axis's own unit. `ScatterPlot` takes a controlled rectangular range.
300
+ Give a thing one id in every figure. `ToneScope` gives each id one hue. `ChartLink` shares one inspected id between the
301
+ figures inside it: pointing at a record in one figure marks the record with the same id in the others.
47
302
 
48
- To link a table and a bar chart, set `BarChart`'s `highlightedSeriesId` from the table's `onRowHighlightChange`.
303
+ ```tsx
304
+ import { ChartLink, ToneScope } from '@mechane-ai/elements/charts';
305
+ import { DotPlot } from '@mechane-ai/elements/charts/comparison';
306
+ import { CurveChart } from '@mechane-ai/elements/charts/trend';
307
+
308
+ <ToneScope ids={['small', 'base']}>
309
+ <ChartLink>
310
+ <CurveChart title="Loss" locale="en-US" series={curves} x={step} y={loss} />
311
+ <DotPlot title="Score by task" locale="en-US" rows={tasks} series={scores} value={score} />
312
+ </ChartLink>
313
+ </ToneScope>;
314
+ ```
315
+
316
+ - A record's own `tone` wins over the scope. Pin a tone when color carries identity across filters.
317
+ - `ChartGrid` is a `ChartLink` and a `ToneScope` laid out as panels with one title. It takes `ids` and `tones` for the
318
+ scope and `minPanelWidth` for the panels.
319
+ - Hovering a row in one figure highlights the same id in the others. `CurveChart` and `DotPlot` also draw the series
320
+ with that id at full strength and fade the rest. Their `highlighted` prop overrides the link.
321
+ - `useScopedTone(id)` returns the hue the scope gives an id, or `undefined` outside a scope, so a sentence or a diagram
322
+ matches its chart. `useChartLinkControl()` returns `{ inspected, inspect }`, or `undefined` outside a link. Call
323
+ `inspect(id, { reason, event })` from prose to point every linked figure at an id.
324
+ - `CurveChart` takes `labels`: `'legend'` (the default), `'inline'` to write each name at the end of its line when there
325
+ is room, or `'none'` when a legend beside a grid already names the series.
326
+ - These charts read the link: `CurveChart`, `RunsChart`, `SlopeChart`, `BumpChart`, `HorizonChart`, `DotPlot`,
327
+ `DumbbellPlot`, `BulletBar`, `IntervalPlot`, `RankedBars`, `BoxPlot`, `ViolinPlot`, `StripPlot`, `Ridgeline`,
328
+ `ScatterMatrix`, `ParallelCoordinates`, `EmbeddingMap`, `EventStrip`, `Icicle`, `AttributionGraph` and `TreeDiagram`.
329
+
330
+ ## States
331
+
332
+ Every figure handles the same states:
333
+
334
+ - `status="loading"` shows the final geometry before the first read. Keep it inside an `AsyncRegion`.
335
+ - `status="refreshing"` keeps the drawn data while a newer read is under way.
336
+ - Empty input shows `emptyLabel`. Invalid input shows why it cannot be drawn.
337
+ - A figure that draws part of its data states how much beside its title. Set `coverage`.
338
+
339
+ `LineChart`, `AreaChart`, `SmallMultiples` and `BarChart` also have placeholders: `TimeSeriesChartPlaceholder`,
340
+ `SmallMultiplesPlaceholder` and `BarChartPlaceholder`. Use the same title, report and height as the loaded chart.
49
341
 
50
342
  ## Compose a report
51
343
 
52
344
  Pass `report` when the chart is a self-contained analytical report with a caption, a period summary and the plot. Use
53
345
  `report.summary` for mixed metrics or `report.seriesValues` for one value per series. Put scoped controls in
54
- `report.actions` with `density="compact"`.
346
+ `report.actions` with `density="compact"`. Inside a region that already groups its content, use the chart without
347
+ `report`.
348
+
349
+ ## Build a chart the library lacks
350
+
351
+ When no chart answers the question, build one from the kernel in `@mechane-ai/elements/charts/plot` so it shares the
352
+ axes, marks, readout, keyboard cursor, states and tones of the others. Do not draw your own scale, axis or SVG mark.
55
353
 
56
- Inside a region that already groups its content, such as an inspector, use the chart without `report`. Use `ChartFrame`
57
- and `ChartLegend` for a custom plot, with `chartToneColors` and `chartToneOutlines` for its marks. Pin a series `tone`
58
- when color carries identity across filters, and reuse it in `ChartSeriesMarker` beside the matching table row.
354
+ - Lay out with `numericPlot`, `categoryPlot` or `timePlot`, and draw with `PlotSurface`, `PlotAxes`, `PlotClip` and the
355
+ marks: `LineMark`, `AreaMark`, `BandMark`, `DotMark`, `BarMark`, `RuleMark`, `IntervalMark`, `LabelMark`,
356
+ `SymbolMark`, `RingMark`, `LinkMark`, `ConnectorMark` and `GuideMark`.
357
+ - Write ticks with `axisTicks` (or `timeAxisTicks` for time) and `tickTexts`. Tick text gains precision until neighbours
358
+ differ, an axis longer than 120 px shows at least three ticks (`ticksMinimum`), and an axis that draws its title drops
359
+ a `style: 'unit'` from its ticks. Place labels with `freeLabelSpot` and `labelBox` so they do not collide.
360
+ - Give `FigureFrame` a `seriesLegend` for a legend that names things, drawn above the plot, and a `scaleLegend` for a
361
+ color or size scale, drawn below it.
362
+ - Wrap the plot in `Chart` for inspection, the keyboard cursor and selection. Add `ChartCursor`, `ChartInspection` or
363
+ `ChartReadout`, and `ChartData` for the exact-value table.
364
+ - Return `FigureLoading`, `FigureEmpty` and `FigureInvalid` for the shared states, and `FigureFrame` around the plot.
365
+ - Take `FigureProps` and the format types from `@mechane-ai/elements/charts`. Write numbers with `formatValue`, instants
366
+ with `formatTime` and hues with `useTones()`. Spread `useLinkedInspection()` into `Chart` when item ids mean the same
367
+ thing in other charts.
368
+ - Refuse input the chart cannot draw with a reason. Do not repair it.
59
369
 
60
- ## Loading
370
+ ## Do not
61
371
 
62
- Use `TimeSeriesChartPlaceholder`, `SmallMultiplesPlaceholder` or `BarChartPlaceholder` inside an `AsyncRegion`, with the
63
- same title, report and height as the loaded chart. Keep the real chart mounted during a refresh.
372
+ - Do not pass a formatter function such as `formatValue`, `formatX` or `formatTick`. Declare a format.
373
+ - Do not hard-code a color. Use a `tone`, a `ToneScope` and the library's tokens.
374
+ - Do not compute a statistic inside a chart or in its props. Use `transforms` and name the step.
375
+ - Do not draw two value scales on one plot. Use `SmallMultiples` or two figures.
376
+ - Do not start a bar, histogram or area at a value other than zero.
377
+ - Do not use a log axis for zero or negative values. Use `scale: 'symlog'`.
378
+ - Do not fill a gap to make a line continuous, or write a missing value as zero.
379
+ - Do not use `selectedId`, `onSelect` or a `selection` object. They were removed in 0.47.
380
+ - Do not pass a pixel `height`. Use `'compact'`, `'regular'` or `'tall'`. `RelationGraph` `width` and `height` stay
381
+ numbers: they are the extent of your node positions.
382
+ - Do not omit `locale`. A server and a browser must render the same text.
383
+ - Do not draw SVG marks yourself in a page. Build the chart from the kernel in `@mechane-ai/elements/charts/plot`, or
384
+ add one to the library through the `extend-elements` skill.
@@ -0,0 +1,173 @@
1
+ # Figures as JSON
2
+
3
+ A figure spec names one chart and its props as plain JSON. An agent or a server writes it, `validateFigureSpec` checks
4
+ it and `Figure` draws it. Use it when the figure comes from data that is not code: a model's answer, a saved report or
5
+ an API response.
6
+
7
+ ```tsx
8
+ import {
9
+ Figure,
10
+ chartGuide,
11
+ describeFigure,
12
+ figureCharts,
13
+ validateFigureSpec,
14
+ } from '@mechane-ai/elements/charts/figure';
15
+ import type { FigureSpec } from '@mechane-ai/elements/charts/figure';
16
+ ```
17
+
18
+ | Export | What it is |
19
+ | -------------------- | ---------------------------------------------------------------------------------------------------- |
20
+ | `FigureSpec` | The spec type: a union with one member per registered chart. `FigureSpecOf<'Histogram'>` is one. |
21
+ | `validateFigureSpec` | Checks the structure of any input. Returns `{ kind: 'ok', spec }` or `{ kind: 'invalid', message }`. |
22
+ | `Figure` | Draws a spec. It takes `selected`, `onSelectedChange` and `status` beside it. |
23
+ | `describeFigure` | Returns the figure as short plain text. |
24
+ | `figureCharts` | `{ chart, family }` for each of the 50 registered charts. |
25
+ | `chartGuide` | One entry per registered chart: `question`, `use`, `avoid`, `family` and a valid `example` spec. |
26
+
27
+ ## The shape
28
+
29
+ A `FigureSpec` is `{ chart, props }`. The type is a union with one member for each registered chart, so
30
+ `chart: 'Histogram'` goes with the props of `Histogram`, and a TypeScript caller gets the right props for the name.
31
+
32
+ - `chart` is the exact name of a registered chart, such as `"Histogram"`. The charts and what each answers are in
33
+ [charts](charts.md), and in `chartGuide`.
34
+ - `props` are that chart's props, minus what JSON cannot carry: callbacks (`on...`), React slots such as `actions` and a
35
+ function format. Read the chart's declaration file for its props.
36
+ - Every spec needs `title` and `locale` in `props`, plus the props the chart cannot draw without.
37
+ - A format is an `Intl` options object. A `TimeFormat` names its `timeZone`.
38
+ - `ColorLegend`, the table cells, the placeholders and the kits are not registered, so a spec cannot name them.
39
+
40
+ ## Start from the guide
41
+
42
+ `chartGuide` is the same guidance as the chooser in [charts](charts.md), as data. Read it to pick a chart and to start
43
+ from a spec that is known to be valid.
44
+
45
+ ```ts
46
+ const entry = chartGuide.find((item) => item.chart === 'DumbbellPlot');
47
+
48
+ // entry?.question: "How much did each row change between two measurements?"
49
+ // entry?.use, entry?.avoid, entry?.family
50
+ // entry?.example is a FigureSpec to copy and change.
51
+ ```
52
+
53
+ ## Write one
54
+
55
+ ```json
56
+ {
57
+ "chart": "Histogram",
58
+ "props": {
59
+ "title": "Request latency",
60
+ "description": "Synthetic requests over one hour, in 25 ms bins.",
61
+ "locale": "en-US",
62
+ "source": "Synthetic trace",
63
+ "transforms": ["Binned at 25 ms"],
64
+ "value": { "label": "Latency (ms)", "format": { "maximumFractionDigits": 0 } },
65
+ "count": { "label": "Requests", "format": { "maximumFractionDigits": 0 } },
66
+ "bins": [
67
+ { "id": "b0", "label": "0 to 25 ms", "lowerBound": 0, "upperBound": 25, "count": 120 },
68
+ { "id": "b1", "label": "25 to 50 ms", "lowerBound": 25, "upperBound": 50, "count": 340 },
69
+ { "id": "b2", "label": "50 to 75 ms", "lowerBound": 50, "upperBound": 75, "count": 180 },
70
+ { "id": "b3", "label": "75 to 100 ms", "lowerBound": 75, "upperBound": 100, "count": null }
71
+ ]
72
+ }
73
+ }
74
+ ```
75
+
76
+ The last bin has `"count": null`. The chart draws it hollow, not as zero.
77
+
78
+ ## Check and draw it
79
+
80
+ ```tsx
81
+ import { Notice } from '@mechane-ai/elements/feedback';
82
+ import { useState } from 'react';
83
+
84
+ function AgentFigure({ input }: { readonly input: unknown }) {
85
+ const [selected, setSelected] = useState<string | null>(null);
86
+ const result = validateFigureSpec(input);
87
+
88
+ if (result.kind === 'invalid') {
89
+ return <Notice hasError>{result.message}</Notice>;
90
+ }
91
+
92
+ return <Figure spec={result.spec} selected={selected} onSelectedChange={(id) => setSelected(id)} />;
93
+ }
94
+ ```
95
+
96
+ `validateFigureSpec(input)` takes `unknown`, so it accepts parsed JSON. The check is structural and never throws. It
97
+ confirms:
98
+
99
+ - the input is an object with a `chart` string that is registered;
100
+ - `props` is an object holding every required prop of the chart, each with the right JSON kind;
101
+ - no value anywhere in `props` is a function;
102
+ - `locale`, when present, is a non-empty string.
103
+
104
+ It does not check the deeper values. Each chart checks its own values and shows an invalid figure with the reason. A
105
+ chart name that is not registered gets up to three close names:
106
+
107
+ ```ts
108
+ validateFigureSpec({ chart: 'Histogramm', props: { title: 'Request latency', locale: 'en-US' } });
109
+ // { kind: 'invalid', message: '"Histogramm" is not a registered chart. Did you mean Histogram?' }
110
+
111
+ validateFigureSpec({ chart: 'Bar', props: {} });
112
+ // { kind: 'invalid', message: '"Bar" is not a registered chart. Did you mean BarChart, BreakdownBar, RankedBars?' }
113
+ ```
114
+
115
+ Other messages state the first problem found:
116
+
117
+ | Input | `message` |
118
+ | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
119
+ | A `Histogram` with no `bins` | ``Histogram needs the prop `bins` (an array).`` |
120
+ | A `Histogram` with `count: 5` | ``Histogram needs `count` as an object, not a number.`` |
121
+ | A `Histogram` with `locale: ''` | ``Histogram needs `locale` as a non-empty string, such as "en-US".`` |
122
+ | A function inside `props` | `A figure spec is plain JSON, and its props hold a function. Pass callbacks to Figure beside the spec.` |
123
+ | A string, an array or `null` | ``A figure spec is an object with `chart` and `props`.`` |
124
+
125
+ `Figure` takes `spec: unknown` and these props beside it:
126
+
127
+ - `selected` and `onSelectedChange(id, details)` reach only the charts that take a selection. A press or Enter on a
128
+ record calls `onSelectedChange`. Leave both out for a read-only figure. A `Waterfall` drawn without a callback still
129
+ draws, and a press does nothing.
130
+ - `status` is `'ready'`, `'loading'` or `'refreshing'`, and replaces the spec's own `status` while newer data loads.
131
+
132
+ `Figure` runs `validateFigureSpec` itself. For a bad spec it draws the shared invalid figure, with the spec's `title`
133
+ and `locale` when they are strings, and the reason as its message. It never throws. Call `validateFigureSpec` first when
134
+ you want the message elsewhere, as above.
135
+
136
+ ## Read it back as text
137
+
138
+ `describeFigure(spec)` returns a short plain-text account of a figure for a place that cannot draw it, such as a chat
139
+ transcript, a log or an agent reading its result back. It names the chart and its title, then the description, how much
140
+ of the data is drawn when `coverage` is set, the source, the transforms and how many records the spec holds. It does not
141
+ restate the values.
142
+
143
+ ```ts
144
+ const text: string = describeFigure(result.spec);
145
+ ```
146
+
147
+ For the spec above, `describeFigure` returns:
148
+
149
+ ```text
150
+ A histogram, "Request latency", with 4 bins. Synthetic requests over one hour, in 25 ms bins. Source: Synthetic trace. Transforms: Binned at 25 ms.
151
+ ```
152
+
153
+ With `"coverage": { "shown": 640, "total": 1200, "unit": "requests" }` added to `props`, it adds a sentence after the
154
+ description:
155
+
156
+ ```text
157
+ A histogram, "Request latency", with 4 bins. Synthetic requests over one hour, in 25 ms bins. 640 of 1,200 requests shown. Source: Synthetic trace. Transforms: Binned at 25 ms.
158
+ ```
159
+
160
+ These two texts came from running `describeFigure` on those specs.
161
+
162
+ ## Rules for an agent that writes a spec
163
+
164
+ - Pick the chart from the question, with the chooser in [charts](charts.md) or `chartGuide`. Do not invent a chart name.
165
+ - Start from the chart's `example` in the guide when you can. It is a valid spec.
166
+ - Write only props the chart declares. Do not add a function, a color, a pixel height or a formatter.
167
+ - Use a declared format and a `locale`. Put the unit in the axis `label`. Write a time format as options with a
168
+ `timeZone`, never as a function.
169
+ - Write a missing value as `null`. Never write it as zero.
170
+ - Put prepared values in the spec. Name each step you applied in `transforms` and the data's origin in `source`.
171
+ - Set `coverage` when the spec holds a sample or a window.
172
+ - Read the figure back after drawing it. The readout, the exact-value table and the invalid message state what was
173
+ drawn.