@motionscript/charts 0.1.0 → 0.1.1-alpha.1

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 (215) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +98 -28
  3. package/dist/bar-chart/bar-chart.d.ts +242 -119
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  5. package/dist/bar-chart/bar-chart.js +231 -260
  6. package/dist/bar-chart/bar-chart.js.map +1 -1
  7. package/dist/bar-chart/category-axis.d.ts +16 -38
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  9. package/dist/bar-chart/category-axis.js +59 -68
  10. package/dist/bar-chart/category-axis.js.map +1 -1
  11. package/dist/bar-chart/chart-bars.d.ts +60 -91
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  13. package/dist/bar-chart/chart-bars.js +88 -125
  14. package/dist/bar-chart/chart-bars.js.map +1 -1
  15. package/dist/bar-chart/index.d.ts +5 -13
  16. package/dist/bar-chart/index.d.ts.map +1 -1
  17. package/dist/bar-chart/index.js +2 -9
  18. package/dist/bar-chart/index.js.map +1 -1
  19. package/dist/bar-chart/shared.d.ts +40 -132
  20. package/dist/bar-chart/shared.d.ts.map +1 -1
  21. package/dist/bar-chart/shared.js +70 -158
  22. package/dist/bar-chart/shared.js.map +1 -1
  23. package/dist/browser/chunks/chunk-R3Q5EE6E.js +2 -0
  24. package/dist/browser/chunks/chunk-R3Q5EE6E.js.map +7 -0
  25. package/dist/browser/index.js +1 -1
  26. package/dist/browser/index.js.map +4 -4
  27. package/dist/browser/kit.js +1 -1
  28. package/dist/browser/manifest.json +1 -1
  29. package/dist/engine.d.ts +8 -17
  30. package/dist/engine.d.ts.map +1 -1
  31. package/dist/engine.js +8 -17
  32. package/dist/engine.js.map +1 -1
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/kit/cartesian.d.ts +49 -35
  38. package/dist/kit/cartesian.d.ts.map +1 -1
  39. package/dist/kit/cartesian.js +80 -42
  40. package/dist/kit/cartesian.js.map +1 -1
  41. package/dist/kit/chart-canvas.d.ts +37 -40
  42. package/dist/kit/chart-canvas.d.ts.map +1 -1
  43. package/dist/kit/chart-canvas.js +53 -47
  44. package/dist/kit/chart-canvas.js.map +1 -1
  45. package/dist/kit/chart-legend.d.ts +16 -59
  46. package/dist/kit/chart-legend.d.ts.map +1 -1
  47. package/dist/kit/chart-legend.js +38 -76
  48. package/dist/kit/chart-legend.js.map +1 -1
  49. package/dist/kit/entries.d.ts +2 -0
  50. package/dist/kit/entries.d.ts.map +1 -1
  51. package/dist/kit/entries.js +2 -0
  52. package/dist/kit/entries.js.map +1 -1
  53. package/dist/kit/horizontal-axis.d.ts +77 -0
  54. package/dist/kit/horizontal-axis.d.ts.map +1 -0
  55. package/dist/kit/horizontal-axis.js +99 -0
  56. package/dist/kit/horizontal-axis.js.map +1 -0
  57. package/dist/kit/motion.d.ts +16 -3
  58. package/dist/kit/motion.d.ts.map +1 -1
  59. package/dist/kit/motion.js +15 -1
  60. package/dist/kit/motion.js.map +1 -1
  61. package/dist/{pie-chart → kit}/pie-legend.d.ts +14 -29
  62. package/dist/kit/pie-legend.d.ts.map +1 -0
  63. package/dist/kit/pie-legend.js +93 -0
  64. package/dist/kit/pie-legend.js.map +1 -0
  65. package/dist/kit/polar.d.ts +31 -0
  66. package/dist/kit/polar.d.ts.map +1 -0
  67. package/dist/kit/polar.js +33 -0
  68. package/dist/kit/polar.js.map +1 -0
  69. package/dist/kit/shared.d.ts +60 -214
  70. package/dist/kit/shared.d.ts.map +1 -1
  71. package/dist/kit/shared.js +91 -291
  72. package/dist/kit/shared.js.map +1 -1
  73. package/dist/kit/style.d.ts +254 -0
  74. package/dist/kit/style.d.ts.map +1 -0
  75. package/dist/kit/style.js +197 -0
  76. package/dist/kit/style.js.map +1 -0
  77. package/dist/kit/vertical-axis.d.ts +36 -45
  78. package/dist/kit/vertical-axis.d.ts.map +1 -1
  79. package/dist/kit/vertical-axis.js +69 -81
  80. package/dist/kit/vertical-axis.js.map +1 -1
  81. package/dist/line-chart/chart-line.d.ts +107 -40
  82. package/dist/line-chart/chart-line.d.ts.map +1 -1
  83. package/dist/line-chart/chart-line.js +172 -89
  84. package/dist/line-chart/chart-line.js.map +1 -1
  85. package/dist/line-chart/chart-region.d.ts +14 -27
  86. package/dist/line-chart/chart-region.d.ts.map +1 -1
  87. package/dist/line-chart/chart-region.js +13 -28
  88. package/dist/line-chart/chart-region.js.map +1 -1
  89. package/dist/line-chart/index.d.ts +5 -18
  90. package/dist/line-chart/index.d.ts.map +1 -1
  91. package/dist/line-chart/index.js +3 -16
  92. package/dist/line-chart/index.js.map +1 -1
  93. package/dist/line-chart/line-chart.d.ts +272 -119
  94. package/dist/line-chart/line-chart.d.ts.map +1 -1
  95. package/dist/line-chart/line-chart.js +309 -257
  96. package/dist/line-chart/line-chart.js.map +1 -1
  97. package/dist/line-chart/shared.d.ts +73 -130
  98. package/dist/line-chart/shared.d.ts.map +1 -1
  99. package/dist/line-chart/shared.js +195 -156
  100. package/dist/line-chart/shared.js.map +1 -1
  101. package/dist/line-chart/x-scale.d.ts +16 -55
  102. package/dist/line-chart/x-scale.d.ts.map +1 -1
  103. package/dist/line-chart/x-scale.js +44 -111
  104. package/dist/line-chart/x-scale.js.map +1 -1
  105. package/dist/nodes.d.ts +3 -13
  106. package/dist/nodes.d.ts.map +1 -1
  107. package/dist/nodes.js +9 -13
  108. package/dist/nodes.js.map +1 -1
  109. package/dist/pie-chart/index.d.ts +3 -15
  110. package/dist/pie-chart/index.d.ts.map +1 -1
  111. package/dist/pie-chart/index.js +1 -11
  112. package/dist/pie-chart/index.js.map +1 -1
  113. package/dist/pie-chart/pie-chart.d.ts +147 -85
  114. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  115. package/dist/pie-chart/pie-chart.js +65 -86
  116. package/dist/pie-chart/pie-chart.js.map +1 -1
  117. package/dist/pie-chart/pie-ring.d.ts +65 -196
  118. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  119. package/dist/pie-chart/pie-ring.js +154 -292
  120. package/dist/pie-chart/pie-ring.js.map +1 -1
  121. package/dist/pie-chart/shared.d.ts +78 -172
  122. package/dist/pie-chart/shared.d.ts.map +1 -1
  123. package/dist/pie-chart/shared.js +54 -177
  124. package/dist/pie-chart/shared.js.map +1 -1
  125. package/dist/radar-chart/index.d.ts +5 -0
  126. package/dist/radar-chart/index.d.ts.map +1 -0
  127. package/dist/radar-chart/index.js +5 -0
  128. package/dist/radar-chart/index.js.map +1 -0
  129. package/dist/radar-chart/radar-chart.d.ts +218 -0
  130. package/dist/radar-chart/radar-chart.d.ts.map +1 -0
  131. package/dist/radar-chart/radar-chart.js +224 -0
  132. package/dist/radar-chart/radar-chart.js.map +1 -0
  133. package/dist/radar-chart/radar-grid.d.ts +43 -0
  134. package/dist/radar-chart/radar-grid.d.ts.map +1 -0
  135. package/dist/radar-chart/radar-grid.js +61 -0
  136. package/dist/radar-chart/radar-grid.js.map +1 -0
  137. package/dist/radar-chart/radar-series.d.ts +59 -0
  138. package/dist/radar-chart/radar-series.d.ts.map +1 -0
  139. package/dist/radar-chart/radar-series.js +71 -0
  140. package/dist/radar-chart/radar-series.js.map +1 -0
  141. package/dist/radar-chart/shared.d.ts +73 -0
  142. package/dist/radar-chart/shared.d.ts.map +1 -0
  143. package/dist/radar-chart/shared.js +123 -0
  144. package/dist/radar-chart/shared.js.map +1 -0
  145. package/dist/radial-chart/index.d.ts +6 -0
  146. package/dist/radial-chart/index.d.ts.map +1 -0
  147. package/dist/radial-chart/index.js +4 -0
  148. package/dist/radial-chart/index.js.map +1 -0
  149. package/dist/radial-chart/radial-chart.d.ts +216 -0
  150. package/dist/radial-chart/radial-chart.d.ts.map +1 -0
  151. package/dist/radial-chart/radial-chart.js +174 -0
  152. package/dist/radial-chart/radial-chart.js.map +1 -0
  153. package/dist/radial-chart/radial-rings.d.ts +121 -0
  154. package/dist/radial-chart/radial-rings.d.ts.map +1 -0
  155. package/dist/radial-chart/radial-rings.js +273 -0
  156. package/dist/radial-chart/radial-rings.js.map +1 -0
  157. package/dist/radial-chart/shared.d.ts +73 -0
  158. package/dist/radial-chart/shared.d.ts.map +1 -0
  159. package/dist/radial-chart/shared.js +79 -0
  160. package/dist/radial-chart/shared.js.map +1 -0
  161. package/package.json +4 -4
  162. package/registry.json +21 -6
  163. package/src/bar-chart/bar-chart.ts +274 -315
  164. package/src/bar-chart/category-axis.ts +53 -88
  165. package/src/bar-chart/chart-bars.ts +108 -205
  166. package/src/bar-chart/index.ts +8 -19
  167. package/src/bar-chart/shared.ts +81 -309
  168. package/src/engine.ts +8 -17
  169. package/src/index.ts +2 -0
  170. package/src/kit/cartesian.ts +118 -55
  171. package/src/kit/chart-canvas.ts +50 -80
  172. package/src/kit/chart-legend.ts +36 -97
  173. package/src/kit/entries.ts +4 -1
  174. package/src/kit/horizontal-axis.ts +114 -0
  175. package/src/kit/motion.ts +18 -2
  176. package/src/{pie-chart → kit}/pie-legend.ts +25 -65
  177. package/src/kit/polar.ts +54 -0
  178. package/src/kit/shared.ts +104 -487
  179. package/src/kit/style.ts +257 -0
  180. package/src/kit/vertical-axis.ts +81 -115
  181. package/src/line-chart/chart-line.ts +185 -91
  182. package/src/line-chart/chart-region.ts +14 -31
  183. package/src/line-chart/index.ts +14 -22
  184. package/src/line-chart/line-chart.ts +377 -315
  185. package/src/line-chart/shared.ts +229 -304
  186. package/src/line-chart/x-scale.ts +44 -121
  187. package/src/nodes.ts +9 -13
  188. package/src/pie-chart/index.ts +3 -35
  189. package/src/pie-chart/pie-chart.ts +83 -134
  190. package/src/pie-chart/pie-ring.ts +162 -368
  191. package/src/pie-chart/shared.ts +92 -379
  192. package/src/radar-chart/index.ts +4 -0
  193. package/src/radar-chart/radar-chart.ts +287 -0
  194. package/src/radar-chart/radar-grid.ts +78 -0
  195. package/src/radar-chart/radar-series.ts +88 -0
  196. package/src/radar-chart/shared.ts +146 -0
  197. package/src/radial-chart/index.ts +5 -0
  198. package/src/radial-chart/radial-chart.ts +210 -0
  199. package/src/radial-chart/radial-rings.ts +328 -0
  200. package/src/radial-chart/shared.ts +114 -0
  201. package/dist/browser/chunks/chunk-TJNHLQGV.js +0 -2
  202. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
  203. package/dist/kit/chart-border.d.ts +0 -27
  204. package/dist/kit/chart-border.d.ts.map +0 -1
  205. package/dist/kit/chart-border.js +0 -28
  206. package/dist/kit/chart-border.js.map +0 -1
  207. package/dist/line-chart/horizontal-axis.d.ts +0 -79
  208. package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
  209. package/dist/line-chart/horizontal-axis.js +0 -129
  210. package/dist/line-chart/horizontal-axis.js.map +0 -1
  211. package/dist/pie-chart/pie-legend.d.ts.map +0 -1
  212. package/dist/pie-chart/pie-legend.js +0 -117
  213. package/dist/pie-chart/pie-legend.js.map +0 -1
  214. package/src/kit/chart-border.ts +0 -50
  215. package/src/line-chart/horizontal-axis.ts +0 -151
@@ -1,38 +1,20 @@
1
1
  /**
2
- * The vocabulary every chart node shares: what a *series* is, how an axis is
3
- * scaled and formatted, and the theme leaves each chart's own theme is assembled
4
- * from.
2
+ * What every chart shares: series, axis scaling and formatting, and the theme
3
+ * leaves each chart's theme is assembled from. No `Node` imports, so a host's
4
+ * inspector mappings can build a partial theme without the components.
5
5
  *
6
- * This module exists because the three chart types are three ways of drawing the
7
- * same table. A line chart, a bar chart and a pie chart disagree about almost
8
- * everything visible — polylines against columns against wedges — and agree
9
- * about almost everything underneath: a series is a column with a caption and a
10
- * paint, a marker is a number formatted one way, a legend is a swatch beside a
11
- * label, and a theme is a tree of paints with one mapper and one tween. Writing
12
- * that three times would mean three answers to "how does a chart round its axis"
13
- * within one app.
14
- *
15
- * Kept renderer-agnostic (no `Node` imports) so a host's own inspector
16
- * mappings can build a partial theme without pulling the components in.
17
- *
18
- * **Two conventions run through every resolver and lerp below**, inherited from
19
- * the shape system's `resolveStroke`/`resolveShadow`:
20
- *
21
- * - A **mapper** merges the author's loose, partial input onto a `previous`
22
- * resolved value and resolves every leaf, so the tween always has resolved
23
- * data to interpolate. It is idempotent.
24
- * - A **tween** interpolates two resolved values leaf by leaf. Categorical
25
- * fields (`fontFamily`, `textAlign`) and fields that are `undefined` on either
26
- * side **step at the midpoint**, because there is no meaningful in-between and
27
- * defaulting the missing side to 0 would animate a font weight down to nothing
28
- * on the way to "unset".
6
+ * A mapper merges partial input onto a `previous` resolved value (idempotent). A
7
+ * tween interpolates two resolved values leaf by leaf, but categorical fields
8
+ * (`fontFamily`, `textAlign`) and any field `undefined` on either side step at
9
+ * the midpoint: defaulting the missing side to 0 would animate a font weight
10
+ * down to nothing on the way to "unset".
29
11
  */
30
- import { fillOps, lerpNumber, shadowOps, strokeOps, insetsOps, textOps, } from "@motionscript/sdk";
12
+ import { lerpNumber, } from "@motionscript/sdk";
13
+ import { niceStep } from "@motionscript/sdk/component";
31
14
  /**
32
- * An axis domain entry's resolve: merges the author's partial input onto
33
- * `previous`, so a later partial `.set({ yAxis: {...} })` patches
34
- * `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`
35
- * after the merge is the auto-derive signal the scale getters read.
15
+ * Merges partial input onto `previous`, so a later `.set({ yAxis: {...} })`
16
+ * patches `label`/`range`/`ticks` independently. An unset `range`/`ticks` is the
17
+ * auto-derive signal.
36
18
  */
37
19
  export function resolveAxisDomain(domain, previous) {
38
20
  return {
@@ -43,18 +25,15 @@ export function resolveAxisDomain(domain, previous) {
43
25
  };
44
26
  }
45
27
  /**
46
- * An axis domain entry's lerp: interpolates `range`/`ticks` numerically
47
- * (pairwise by index for `ticks`), so a `to` command that restates a range
48
- * rescales the plot smoothly. `label`, and either field when one side is in
49
- * auto-derive mode, step at the midpoint.
28
+ * Interpolates `range` and `ticks` numerically (ticks pairwise by index).
29
+ * `label`, `format`, and either field when one side is auto, step at the
30
+ * midpoint: there is no halfway between `$#,##0` and `0.0%`.
50
31
  */
51
32
  export function lerpAxisDomain(from, to, t) {
52
33
  return {
53
34
  label: t < 0.5 ? from.label : to.label,
54
35
  range: lerpOptionalRange(from.range, to.range, t),
55
36
  ticks: lerpOptionalTicks(from.ticks, to.ticks, t),
56
- // Steps at the midpoint with the caption, for the same reason: there is no
57
- // halfway between `$#,##0` and `0.0%`.
58
37
  format: t < 0.5 ? from.format : to.format,
59
38
  };
60
39
  }
@@ -73,39 +52,15 @@ function lerpOptionalTicks(from, to, t) {
73
52
  }
74
53
  return out;
75
54
  }
76
- /**
77
- * Where a generic `to()` of an axis domain should land, given the domain as it
78
- * is *drawn* (`drawn`, with `range` and `ticks` resolved off the data), or
79
- * `undefined` when the request states neither a `range` nor `ticks` and the
80
- * plain property tween will do.
81
- *
82
- * The stored domain of an auto axis has no `range` and no `ticks`, and
83
- * {@link lerpAxisDomain} steps an unset side at the midpoint, so tweening the
84
- * stored value from an auto axis is a cut. The charts therefore tween between
85
- * resolved domains, as their zoom does; this builds the destination. A `range`
86
- * given without `ticks` keeps the tick *count* the axis already draws, so each
87
- * marker slides from its old value to its new one instead of the row popping.
88
- */
89
- export function axisTweenTarget(drawn, requested) {
90
- if (requested?.range === undefined && requested?.ticks === undefined)
91
- return undefined;
92
- const target = resolveAxisDomain(requested, drawn);
93
- if (requested.ticks === undefined && requested.range !== undefined) {
94
- const count = Math.max(2, drawn.ticks?.length ?? 2);
95
- target.ticks = markerValues(requested.range, count - 1);
96
- }
97
- return target;
98
- }
99
55
  function blendOf(domain) {
100
56
  return domain.blend;
101
57
  }
102
58
  /**
103
- * A chart's axis entry tween: what `to({ yAxis: { range } })` moves through.
104
- * Between two explicit domains it is {@link lerpAxisDomain}, and a restated
105
- * `range` without `ticks` spreads explicit ticks across it, keeping their count.
106
- * When either end leaves `range` or `ticks` to the data, the value between is an
107
- * {@link AxisDomainBlend}, which the chart draws as the blend of what each end
108
- * draws: a rescale from an auto axis is continuous, not a cut at the midpoint.
59
+ * The axis entry tween behind `to({ yAxis: { range } })`. Between explicit
60
+ * domains it is {@link lerpAxisDomain}, and a restated `range` without `ticks`
61
+ * spreads ticks across it, keeping their count. When either end leaves `range`
62
+ * or `ticks` to the data, the value between is an {@link AxisDomainBlend}, so a
63
+ * rescale from an auto axis is continuous rather than a cut at the midpoint.
109
64
  */
110
65
  export function lerpAxisEntry(from, to, t) {
111
66
  // The mapper merged the request onto `from`, so a field it left unstated is `from`'s own, by identity.
@@ -125,57 +80,28 @@ export function lerpAxisEntry(from, to, t) {
125
80
  const blend = { ...lerpAxisDomain(from, target, t), blend: { from, to: target, t } };
126
81
  return blend;
127
82
  }
128
- /**
129
- * `domain` as the chart draws it: `drawn` resolves a plain domain's auto `range`
130
- * and `ticks` off the data, and a blend is the lerp of what its two ends draw.
131
- */
83
+ /** `domain` as drawn: `drawn` resolves a plain domain's auto `range` and `ticks`; a blend is the lerp of what its ends draw. */
132
84
  export function settleAxisDomain(domain, drawn) {
133
85
  const blend = blendOf(domain);
134
86
  if (!blend)
135
87
  return drawn(domain);
136
88
  return lerpAxisDomain(settleAxisDomain(blend.from, drawn), settleAxisDomain(blend.to, drawn), blend.t);
137
89
  }
138
- /**
139
- * The low-level colour tokens the default themes are built from — a dark plot
140
- * panel with warm-grey axis furniture.
141
- */
142
- export const CHART_PALETTE = {
143
- /** Fill of the plot panel behind the marks. */
90
+ /** The colour tokens the default themes are built from: a dark plot panel with warm-grey axis furniture. */
91
+ const CHART_PALETTE = {
144
92
  plotFill: "#15130e",
145
- /** Colour of the plot's thick border. */
146
93
  borderColor: "#4a4036",
147
- /** Colour of the faint grid lines spanning the plot. */
148
94
  gridColor: "#2c2820",
149
- /** Colour of the numeric axis markers, axis captions, and legend labels. */
95
+ /** Axis markers, axis captions and legend labels. */
150
96
  markerColor: "#8a7f70",
151
- /** Colour of a spotlit region's dashed rules and its wash. */
97
+ /** A spotlit region's dashed rules and wash. */
152
98
  regionColor: "#d99a3a",
153
99
  };
154
- /** The out-of-the-box series palette, cycled by series index. */
155
- export const DEFAULT_SERIES_COLORS = [
156
- "#d9603b",
157
- "#8194ad",
158
- "#e0a93b",
159
- "#5e9d6b",
160
- "#9ec85a",
161
- ];
162
- /**
163
- * Opacity an *un*-spotlighted series fades to — its mark and its legend entry
164
- * alike, so the two dim together.
165
- */
100
+ /** Opacity an un-spotlighted series fades to, mark and legend entry alike. */
166
101
  export const SPOTLIGHT_DIM = 0.2;
167
- /** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */
168
- export function clampUnit(value) {
169
- return value < 0 ? 0 : value > 1 ? 1 : value;
170
- }
171
- // ---- Row readers ---------------------------------------------------------
172
102
  /**
173
- * Read a numeric field off a row, defaulting missing, non-numeric and non-finite
174
- * values to 0.
175
- *
176
- * A column left as strings silently plots as 0, which is why the CSV parser's
177
- * numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
178
- * until it's coerced.
103
+ * Reads a numeric field off a row. A string column plots as 0, so a quoted or
104
+ * unit-suffixed column needs the CSV parser's numeric coercion first.
179
105
  */
180
106
  export function num(row, field) {
181
107
  if (field === undefined)
@@ -185,12 +111,7 @@ export function num(row, field) {
185
111
  // as 0, it cannot poison the scale and turn every point into `NaN`.
186
112
  return typeof v === "number" && Number.isFinite(v) ? v : 0;
187
113
  }
188
- /**
189
- * Read a field off a row as its caption — the counterpart to {@link num} for
190
- * the columns a chart *names* things by rather than measures them by (a bar's
191
- * category, a wedge's slice). A missing cell reads as empty rather than as the
192
- * string `"undefined"`.
193
- */
114
+ /** The counterpart to {@link num} for the columns a chart names things by; a missing cell reads as empty, not `"undefined"`. */
194
115
  export function text(row, field) {
195
116
  if (field === undefined || field === "")
196
117
  return "";
@@ -198,13 +119,9 @@ export function text(row, field) {
198
119
  return v === undefined || v === null ? "" : String(v);
199
120
  }
200
121
  /**
201
- * Every column that holds numbers across `data`, in header order, skipping the
202
- * names in `exclude` (typically the category column).
203
- *
204
- * A column counts as numeric only if every non-empty cell in it is a number, so
205
- * a stray text cell leaves the column out rather than plotting zeros. This is
206
- * what lets a chart plot "every other column" without the author naming twenty
207
- * fields.
122
+ * Every numeric column of `data` in header order, skipping `exclude`. A column
123
+ * is numeric only if every non-empty cell is a number, so a stray text cell
124
+ * drops the column rather than plotting zeros.
208
125
  */
209
126
  export function numericFields(data, exclude = []) {
210
127
  if (data.length === 0)
@@ -244,7 +161,6 @@ const AXIS_TITLE_STYLE = {
244
161
  fill: CHART_PALETTE.markerColor,
245
162
  };
246
163
  const AXIS_LINE_STYLE = { weight: 2, fill: CHART_PALETTE.gridColor };
247
- /** The default styling of a horizontal (marker row beneath the plot) axis. */
248
164
  export const DEFAULT_X_AXIS = {
249
165
  labelStyle: AXIS_LABEL_STYLE,
250
166
  titleStyle: AXIS_TITLE_STYLE,
@@ -252,7 +168,6 @@ export const DEFAULT_X_AXIS = {
252
168
  tickPadding: 20,
253
169
  titlePadding: 4,
254
170
  };
255
- /** The default styling of a vertical (marker column beside the plot) axis. */
256
171
  export const DEFAULT_Y_AXIS = {
257
172
  labelStyle: { ...AXIS_LABEL_STYLE, fontWeight: 500, textAlign: "right" },
258
173
  titleStyle: AXIS_TITLE_STYLE,
@@ -260,17 +175,6 @@ export const DEFAULT_Y_AXIS = {
260
175
  tickPadding: 40,
261
176
  titlePadding: 24,
262
177
  };
263
- /**
264
- * The default plot panel: **unpainted**, framed. A chart reads against the
265
- * stage rather than punching a panel into it, which is the look the family was
266
- * designed at.
267
- */
268
- export const DEFAULT_PLOT_AREA = {
269
- fill: [],
270
- stroke: { weight: 6, fill: CHART_PALETTE.borderColor },
271
- shadow: [],
272
- };
273
- /** The default legend styling, shared by every chart that draws one. */
274
178
  export const DEFAULT_LEGEND = {
275
179
  padding: 0,
276
180
  textStyle: {
@@ -288,165 +192,10 @@ export const DEFAULT_LEGEND = {
288
192
  shadow: [],
289
193
  },
290
194
  };
291
- /** The default per-series stroke palette — {@link DEFAULT_SERIES_COLORS}, drawn 4px. */
292
- export const DEFAULT_SERIES_STROKES = DEFAULT_SERIES_COLORS.map((fill) => ({ weight: 4, fill }));
293
- /** The default per-series fill palette — the same colours, as solid paint. */
294
- export const DEFAULT_SERIES_FILLS = DEFAULT_SERIES_COLORS.map((fill) => fill);
295
- // ---- Theme branch resolvers ----------------------------------------------
296
- // Each chart type assembles its own theme out of these, so "the axis furniture"
297
- // means one thing across the family and each chart still declares only the
298
- // branches it actually draws.
299
- export function resolveAxisConfig(axis, previous) {
300
- return {
301
- labelStyle: textOps.resolveStyle(axis?.labelStyle, previous.labelStyle),
302
- titleStyle: textOps.resolveStyle(axis?.titleStyle, previous.titleStyle),
303
- lineStyle: strokeOps.resolve(axis?.lineStyle ?? previous.lineStyle),
304
- tickPadding: insetsOps.resolve(axis?.tickPadding ?? previous.tickPadding, previous.tickPadding),
305
- titlePadding: insetsOps.resolve(axis?.titlePadding ?? previous.titlePadding, previous.titlePadding),
306
- };
307
- }
308
- export function lerpAxisConfig(from, to, t) {
309
- return {
310
- labelStyle: textOps.lerpStyle(from.labelStyle, to.labelStyle, t),
311
- titleStyle: textOps.lerpStyle(from.titleStyle, to.titleStyle, t),
312
- lineStyle: strokeOps.lerp(from.lineStyle, to.lineStyle, t),
313
- tickPadding: insetsOps.lerp(from.tickPadding, to.tickPadding, t),
314
- titlePadding: insetsOps.lerp(from.titlePadding, to.titlePadding, t),
315
- };
316
- }
317
- export function resolvePlotArea(plotArea, previous) {
318
- return {
319
- fill: fillOps.resolve(plotArea?.fill ?? previous.fill),
320
- stroke: strokeOps.resolve(plotArea?.stroke ?? previous.stroke),
321
- shadow: shadowOps.resolve(plotArea?.shadow ?? previous.shadow),
322
- };
323
- }
324
- export function lerpPlotArea(from, to, t) {
325
- return {
326
- fill: fillOps.lerp(from.fill, to.fill, t),
327
- stroke: strokeOps.lerp(from.stroke, to.stroke, t),
328
- shadow: shadowOps.lerp(from.shadow, to.shadow, t),
329
- };
330
- }
331
- function resolveLegendMarkerConfig(marker, previous) {
332
- return {
333
- width: marker?.width ?? previous.width,
334
- height: marker?.height ?? previous.height,
335
- borderRadius: marker?.borderRadius ?? previous.borderRadius,
336
- stroke: strokeOps.resolve(marker?.stroke ?? previous.stroke),
337
- shadow: shadowOps.resolve(marker?.shadow ?? previous.shadow),
338
- };
339
- }
340
- function lerpLegendMarkerConfig(from, to, t) {
341
- return {
342
- width: lerpNumber(from.width, to.width, t),
343
- height: lerpNumber(from.height, to.height, t),
344
- borderRadius: lerpNumber(from.borderRadius, to.borderRadius, t),
345
- stroke: strokeOps.lerp(from.stroke, to.stroke, t),
346
- shadow: shadowOps.lerp(from.shadow, to.shadow, t),
347
- };
348
- }
349
- export function resolveLegendConfig(legend, previous) {
350
- return {
351
- padding: insetsOps.resolve(legend?.padding ?? previous.padding, previous.padding),
352
- textStyle: textOps.resolveStyle(legend?.textStyle, previous.textStyle),
353
- itemGap: legend?.itemGap ?? previous.itemGap,
354
- markerStyle: resolveLegendMarkerConfig(legend?.markerStyle, previous.markerStyle),
355
- };
356
- }
357
- export function lerpLegendConfig(from, to, t) {
358
- return {
359
- padding: insetsOps.lerp(from.padding, to.padding, t),
360
- textStyle: textOps.lerpStyle(from.textStyle, to.textStyle, t),
361
- itemGap: lerpNumber(from.itemGap, to.itemGap, t),
362
- markerStyle: lerpLegendMarkerConfig(from.markerStyle, to.markerStyle, t),
363
- };
364
- }
365
- /** A whole-palette override replaces the previous palette outright. */
366
- export function resolveSeriesStrokes(styles, previous) {
367
- return (styles ?? previous).map((s) => strokeOps.resolve(s));
368
- }
369
- /** Pairwise by index; a palette that grows/shrinks holds the longer side's tail. */
370
- export function lerpSeriesStrokes(from, to, t) {
371
- const n = Math.max(from.length, to.length);
372
- const out = [];
373
- for (let i = 0; i < n; i++) {
374
- const a = (from[i] ?? to[i]);
375
- const b = (to[i] ?? from[i]);
376
- out.push(strokeOps.lerp(a, b, t));
377
- }
378
- return out;
379
- }
380
- /** The fill-palette twin of {@link resolveSeriesStrokes}, for filled marks. */
381
- export function resolveSeriesFills(fills, previous) {
382
- return (fills ?? previous).map((f) => fillOps.resolve(f));
383
- }
384
- /** The fill-palette twin of {@link lerpSeriesStrokes}. */
385
- export function lerpSeriesFills(from, to, t) {
386
- const n = Math.max(from.length, to.length);
387
- const out = [];
388
- for (let i = 0; i < n; i++) {
389
- const a = (from[i] ?? to[i]);
390
- const b = (to[i] ?? from[i]);
391
- out.push(fillOps.lerp(a, b, t));
392
- }
393
- return out;
394
- }
395
- // ---- Per-series paint ----------------------------------------------------
396
195
  /**
397
- * The effective stroke for series `index`: the palette's entry at
398
- * `index % palette.length`, with the series' own `fill`, if set, overriding just
399
- * the last (topmost) layer's colour.
400
- */
401
- export function resolveSeriesStroke(palette, series, index) {
402
- const entry = palette.length > 0
403
- ? palette[index % palette.length]
404
- : { weight: 4, fill: "white" };
405
- if (series.fill == null)
406
- return entry;
407
- const layers = strokeOps.resolve(entry);
408
- if (layers.length === 0)
409
- return { weight: 4, fill: series.fill };
410
- const next = [...layers];
411
- next[next.length - 1] = {
412
- ...next[next.length - 1],
413
- fill: fillOps.resolve(series.fill),
414
- };
415
- return next;
416
- }
417
- /**
418
- * The effective *colour* for series `index` — the same colour
419
- * {@link resolveSeriesStroke} draws its line in — for contexts (a legend
420
- * swatch) that only need the fill.
421
- */
422
- export function resolveSeriesFill(palette, series, index) {
423
- const layers = strokeOps.resolve(resolveSeriesStroke(palette, series, index));
424
- return layers[layers.length - 1]?.fill ?? "white";
425
- }
426
- /**
427
- * The effective paint for mark `index` of a **filled** chart (a bar, a wedge):
428
- * the series' own `fill` when it carries one, else the palette's entry for its
429
- * index, cycled.
430
- *
431
- * The stroke twin above has to reach inside a stroke to swap one layer's colour;
432
- * a filled mark has no such geometry wrapped around its paint, so an override is
433
- * simply the whole answer.
434
- */
435
- export function resolvePalettePaint(palette, override, index) {
436
- if (override != null)
437
- return override;
438
- if (palette.length === 0)
439
- return "white";
440
- return palette[index % palette.length];
441
- }
442
- // ---- Scales and formatting -----------------------------------------------
443
- /**
444
- * Format a marker value: integers plain, otherwise trimmed to one decimal, or to
445
- * as many as the axis's tick `step` needs to tell neighbouring ticks apart.
446
- *
447
- * One decimal is the floor, so a step of 0.1 or more reads exactly as it always
448
- * has; a finer step (a unit axis ticked every 0.05) gets two, instead of five
449
- * ticks captioned `0.1 0.1 0.2 0.2 0.3`. Trailing zeros are dropped either way.
196
+ * Format a marker value: integers plain, otherwise one decimal, or as many as
197
+ * the tick `step` needs to tell neighbours apart (a unit axis ticked every 0.05
198
+ * gets two, not `0.1 0.1 0.2 0.2 0.3`). Trailing zeros are dropped.
450
199
  */
451
200
  export function formatMarker(value, step) {
452
201
  if (Number.isInteger(value))
@@ -489,8 +238,59 @@ export function markerValues([min, max], markerCount) {
489
238
  const n = Math.max(2, Math.round(markerCount));
490
239
  return Array.from({ length: n + 1 }, (_, i) => min + ((max - min) / n) * i);
491
240
  }
492
- // Lifted into the engine, because a graph and a diagram want them too — see
493
- // `@motionscript/sdk/component`. Re-exported so a chart, and anything that
494
- // copied one, still reaches them where it always did.
495
- export { niceStep, enterBudget } from "@motionscript/sdk/component";
241
+ /** `[lo, hi]` nudged out to bounds a whole number of tidy steps apart, about `divisions` of them. */
242
+ export function niceRange([lo, hi], divisions) {
243
+ const segments = Math.max(1, Math.round(divisions));
244
+ if (hi === lo)
245
+ return constantScale(lo, segments);
246
+ const step = niceStep((hi - lo) / segments);
247
+ return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step];
248
+ }
249
+ /**
250
+ * The scale for constant data. A zero-width scale would put every tick on one
251
+ * value and the line on the floor, so it widens by a step sized to the
252
+ * magnitude (`5` gets `[3, 7]`), or `[0, 1]` for zero.
253
+ */
254
+ function constantScale(value, segments) {
255
+ if (value === 0)
256
+ return [0, 1];
257
+ const step = niceStep(Math.abs(value) / segments);
258
+ return [value - step, value + step];
259
+ }
260
+ /**
261
+ * Ticks for a range worked out from the data: every multiple of the tidiest
262
+ * step (1, 2 or 5 times a power of ten) that divides it into about `divisions`
263
+ * parts, so zero is a tick whenever the range spans it. A range no such step
264
+ * divides (an author's) is split evenly instead.
265
+ */
266
+ export function niceTicks([lo, hi], divisions) {
267
+ const span = hi - lo;
268
+ const target = Math.max(1, Math.round(divisions));
269
+ if (!(span > 0))
270
+ return markerValues([lo, hi], target);
271
+ const whole = (v) => Math.abs(v - Math.round(v)) < 1e-6;
272
+ const base = niceStep(span / target);
273
+ let best;
274
+ for (const step of ladder(base)) {
275
+ const parts = span / step;
276
+ if (!whole(parts) || !whole(lo / step) || parts < 2 || parts > 8)
277
+ continue;
278
+ if (best === undefined || Math.abs(parts - target) < Math.abs(span / best - target))
279
+ best = step;
280
+ }
281
+ if (best === undefined)
282
+ return markerValues([lo, hi], target);
283
+ const first = Math.round(lo / best);
284
+ return Array.from({ length: Math.round(span / best) + 1 }, (_, k) => Number(((first + k) * best).toPrecision(12)));
285
+ }
286
+ /** `step` and its neighbours on the 1-2-5 ladder, two either side. */
287
+ function ladder(step) {
288
+ const mag = 10 ** Math.floor(Math.log10(step));
289
+ const rungs = [];
290
+ for (const m of [mag / 10, mag, mag * 10])
291
+ for (const k of [1, 2, 5])
292
+ rungs.push(k * m);
293
+ const at = rungs.findIndex((r) => Math.abs(r - step) < step * 1e-9);
294
+ return rungs.slice(Math.max(0, at - 2), at + 3);
295
+ }
496
296
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,GAWR,MAAM,mBAAmB,CAAA;AAuD1B;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAoC,EACpC,QAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC7C,KAAK,EAAE,MAAM,EAAE,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AAM,GAAG,GAAG,QAAQ,GAAG,GAAG,CAAA;IAC1B,IAAI,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,GAAG,GAAG,CAAA;IAC3C,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAA;AACjD,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,CAAQ,EAAE,WAAmB;IACjE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;IAC9C,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;AAC7E,CAAC;AAED,4EAA4E;AAC5E,2EAA2E;AAC3E,sDAAsD;AACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA","sourcesContent":["/**\n * The vocabulary every chart node shares: what a *series* is, how an axis is\n * scaled and formatted, and the theme leaves each chart's own theme is assembled\n * from.\n *\n * This module exists because the three chart types are three ways of drawing the\n * same table. A line chart, a bar chart and a pie chart disagree about almost\n * everything visible — polylines against columns against wedges — and agree\n * about almost everything underneath: a series is a column with a caption and a\n * paint, a marker is a number formatted one way, a legend is a swatch beside a\n * label, and a theme is a tree of paints with one mapper and one tween. Writing\n * that three times would mean three answers to \"how does a chart round its axis\"\n * within one app.\n *\n * Kept renderer-agnostic (no `Node` imports) so a host's own inspector\n * mappings can build a partial theme without pulling the components in.\n *\n * **Two conventions run through every resolver and lerp below**, inherited from\n * the shape system's `resolveStroke`/`resolveShadow`:\n *\n * - A **mapper** merges the author's loose, partial input onto a `previous`\n * resolved value and resolves every leaf, so the tween always has resolved\n * data to interpolate. It is idempotent.\n * - A **tween** interpolates two resolved values leaf by leaf. Categorical\n * fields (`fontFamily`, `textAlign`) and fields that are `undefined` on either\n * side **step at the midpoint**, because there is no meaningful in-between and\n * defaulting the missing side to 0 would animate a font weight down to nothing\n * on the way to \"unset\".\n */\n\nimport {\n fillOps,\n lerpNumber,\n shadowOps,\n strokeOps,\n insetsOps,\n textOps,\n type DataRecord,\n type Fill,\n type FillResolved,\n type Insets,\n type InsetsResolved,\n type Shadow,\n type ShadowResolved,\n type Stroke,\n type StrokeResolved,\n type TextStyle,\n} from \"@motionscript/sdk\"\n\n/**\n * One series of a chart: a column of the table, captioned and painted.\n *\n * `field` names the column carrying this series' values. What that becomes is\n * the chart's business — a traced polyline, a column of bars, a wedge — but the\n * three questions asked of it are the same everywhere: which column, what to\n * call it, what to paint it, and whether it is currently drawn.\n *\n * `fill` is an **override**: omit it and the series takes the theme palette's\n * entry for its own index, which is what makes a chart nobody has themed come\n * out in five distinct colours rather than five identical ones.\n */\nexport interface ChartSeries {\n /** Key into each data row for this series' value. */\n field: string\n /** Legend caption for this series. */\n label: string\n /**\n * Paint override for this series' mark and its legend swatch. Omit to take\n * the theme palette's entry for this series' index.\n */\n fill?: Fill\n /** Whether the series shows by default. Defaults to `true`. */\n enabled?: boolean\n}\n\n/** A `[min, max]` numeric range in data units. */\nexport type Range = [min: number, max: number]\n\n/**\n * One axis's *data* domain — what it shows — as opposed to {@link AxisConfig},\n * which is how it's *styled*. Every field is optional: `range`/`ticks` derive\n * from the plotted data when omitted, and `label` defaults to `\"\"`.\n */\nexport interface AxisDomainConfig {\n /** Caption drawn alongside the axis. Pass `\"\"` (the default) to hide it. */\n label?: string\n /** `[min, max]` of the scale. Derived from the data bounds when omitted. */\n range?: Range\n /** Tick values (in data units). Derived (five evenly-spaced) when omitted. */\n ticks?: number[]\n /**\n * How a tick value is written down — a `number-format` pattern such as\n * `#,##0.00` or `$#,##0`.\n *\n * Here rather than in {@link AxisConfig} because it is a statement about the\n * *numbers*, not about the ink they are set in: `$` on a revenue axis says\n * what the column holds, and it has to survive a re-theme. It sits beside\n * `range` and `ticks` for the same reason those do.\n */\n format?: string\n}\n\n/**\n * An axis domain entry's resolve: merges the author's partial input onto\n * `previous`, so a later partial `.set({ yAxis: {...} })` patches\n * `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`\n * after the merge is the auto-derive signal the scale getters read.\n */\nexport function resolveAxisDomain(\n domain: AxisDomainConfig | undefined,\n previous?: AxisDomainConfig\n): AxisDomainConfig {\n return {\n label: domain?.label ?? previous?.label ?? \"\",\n range: domain?.range ?? previous?.range,\n ticks: domain?.ticks ?? previous?.ticks,\n format: domain?.format ?? previous?.format,\n }\n}\n\n/**\n * An axis domain entry's lerp: interpolates `range`/`ticks` numerically\n * (pairwise by index for `ticks`), so a `to` command that restates a range\n * rescales the plot smoothly. `label`, and either field when one side is in\n * auto-derive mode, step at the midpoint.\n */\nexport function lerpAxisDomain(\n from: AxisDomainConfig,\n to: AxisDomainConfig,\n t: number\n): AxisDomainConfig {\n return {\n label: t < 0.5 ? from.label : to.label,\n range: lerpOptionalRange(from.range, to.range, t),\n ticks: lerpOptionalTicks(from.ticks, to.ticks, t),\n // Steps at the midpoint with the caption, for the same reason: there is no\n // halfway between `$#,##0` and `0.0%`.\n format: t < 0.5 ? from.format : to.format,\n }\n}\n\nfunction lerpOptionalRange(\n from: Range | undefined,\n to: Range | undefined,\n t: number\n): Range | undefined {\n if (!from || !to) return t < 0.5 ? from : to\n return [lerpNumber(from[0], to[0], t), lerpNumber(from[1], to[1], t)]\n}\n\nfunction lerpOptionalTicks(\n from: number[] | undefined,\n to: number[] | undefined,\n t: number\n): number[] | undefined {\n if (!from || !to) return t < 0.5 ? from : to\n const n = Math.max(from.length, to.length)\n const out: number[] = []\n for (let i = 0; i < n; i++) {\n out.push(lerpNumber(from[i] ?? to[i], to[i] ?? from[i], t))\n }\n return out\n}\n\n/**\n * Where a generic `to()` of an axis domain should land, given the domain as it\n * is *drawn* (`drawn`, with `range` and `ticks` resolved off the data), or\n * `undefined` when the request states neither a `range` nor `ticks` and the\n * plain property tween will do.\n *\n * The stored domain of an auto axis has no `range` and no `ticks`, and\n * {@link lerpAxisDomain} steps an unset side at the midpoint, so tweening the\n * stored value from an auto axis is a cut. The charts therefore tween between\n * resolved domains, as their zoom does; this builds the destination. A `range`\n * given without `ticks` keeps the tick *count* the axis already draws, so each\n * marker slides from its old value to its new one instead of the row popping.\n */\nexport function axisTweenTarget(\n drawn: AxisDomainConfig,\n requested: AxisDomainConfig | undefined\n): AxisDomainConfig | undefined {\n if (requested?.range === undefined && requested?.ticks === undefined) return undefined\n const target = resolveAxisDomain(requested, drawn)\n if (requested.ticks === undefined && requested.range !== undefined) {\n const count = Math.max(2, drawn.ticks?.length ?? 2)\n target.ticks = markerValues(requested.range, count - 1)\n }\n return target\n}\n\n/**\n * An axis domain part-way through a tween that leaves or reaches a `range` or\n * `ticks` left to the data: both ends as stored, and how far along. Only the\n * chart knows what an auto side draws as, so {@link settleAxisDomain} resolves\n * it there. Its own fields are the plain {@link lerpAxisDomain} of its ends, so\n * a mapper merging onto one still reads a domain.\n */\nexport interface AxisDomainBlend extends AxisDomainConfig {\n readonly blend: { readonly from: AxisDomainConfig; readonly to: AxisDomainConfig; readonly t: number }\n}\n\nfunction blendOf(domain: AxisDomainConfig): AxisDomainBlend[\"blend\"] | undefined {\n return (domain as Partial<AxisDomainBlend>).blend\n}\n\n/**\n * A chart's axis entry tween: what `to({ yAxis: { range } })` moves through.\n * Between two explicit domains it is {@link lerpAxisDomain}, and a restated\n * `range` without `ticks` spreads explicit ticks across it, keeping their count.\n * When either end leaves `range` or `ticks` to the data, the value between is an\n * {@link AxisDomainBlend}, which the chart draws as the blend of what each end\n * draws: a rescale from an auto axis is continuous, not a cut at the midpoint.\n */\nexport function lerpAxisEntry(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig {\n // The mapper merged the request onto `from`, so a field it left unstated is `from`'s own, by identity.\n const rangeMoved = to.range !== from.range\n const target = rangeMoved && to.range && to.ticks && to.ticks === from.ticks\n ? { ...to, ticks: markerValues(to.range, Math.max(2, to.ticks.length) - 1) }\n : to\n const blended = blendOf(from) !== undefined\n const moved = blended || rangeMoved || target.ticks !== from.ticks\n const auto = blended || from.range === undefined || from.ticks === undefined || target.range === undefined || target.ticks === undefined\n if (!moved || !auto) return lerpAxisDomain(from, target, t)\n if (t === 0) return from\n if (t === 1) return target\n const blend: AxisDomainBlend = { ...lerpAxisDomain(from, target, t), blend: { from, to: target, t } }\n return blend\n}\n\n/**\n * `domain` as the chart draws it: `drawn` resolves a plain domain's auto `range`\n * and `ticks` off the data, and a blend is the lerp of what its two ends draw.\n */\nexport function settleAxisDomain(domain: AxisDomainConfig, drawn: (domain: AxisDomainConfig) => AxisDomainConfig): AxisDomainConfig {\n const blend = blendOf(domain)\n if (!blend) return drawn(domain)\n return lerpAxisDomain(settleAxisDomain(blend.from, drawn), settleAxisDomain(blend.to, drawn), blend.t)\n}\n\n/**\n * The low-level colour tokens the default themes are built from — a dark plot\n * panel with warm-grey axis furniture.\n */\nexport const CHART_PALETTE = {\n /** Fill of the plot panel behind the marks. */\n plotFill: \"#15130e\",\n /** Colour of the plot's thick border. */\n borderColor: \"#4a4036\",\n /** Colour of the faint grid lines spanning the plot. */\n gridColor: \"#2c2820\",\n /** Colour of the numeric axis markers, axis captions, and legend labels. */\n markerColor: \"#8a7f70\",\n /** Colour of a spotlit region's dashed rules and its wash. */\n regionColor: \"#d99a3a\",\n} as const\n\n/** The out-of-the-box series palette, cycled by series index. */\nexport const DEFAULT_SERIES_COLORS = [\n \"#d9603b\",\n \"#8194ad\",\n \"#e0a93b\",\n \"#5e9d6b\",\n \"#9ec85a\",\n] as const\n\n/**\n * Opacity an *un*-spotlighted series fades to — its mark and its legend entry\n * alike, so the two dim together.\n */\nexport const SPOTLIGHT_DIM = 0.2\n\n/** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */\nexport function clampUnit(value: number): number {\n return value < 0 ? 0 : value > 1 ? 1 : value\n}\n\n// ---- Row readers ---------------------------------------------------------\n\n/**\n * Read a numeric field off a row, defaulting missing, non-numeric and non-finite\n * values to 0.\n *\n * A column left as strings silently plots as 0, which is why the CSV parser's\n * numeric auto-coercion matters — a quoted or unit-suffixed column won't plot\n * until it's coerced.\n */\nexport function num(row: DataRecord, field: string | undefined): number {\n if (field === undefined) return 0\n const v = row[field]\n // A `NaN` or infinite cell is no more a measurement than a missing one: read\n // as 0, it cannot poison the scale and turn every point into `NaN`.\n return typeof v === \"number\" && Number.isFinite(v) ? v : 0\n}\n\n/**\n * Read a field off a row as its caption — the counterpart to {@link num} for\n * the columns a chart *names* things by rather than measures them by (a bar's\n * category, a wedge's slice). A missing cell reads as empty rather than as the\n * string `\"undefined\"`.\n */\nexport function text(row: DataRecord, field: string | undefined): string {\n if (field === undefined || field === \"\") return \"\"\n const v = row[field]\n return v === undefined || v === null ? \"\" : String(v)\n}\n\n/**\n * Every column that holds numbers across `data`, in header order, skipping the\n * names in `exclude` (typically the category column).\n *\n * A column counts as numeric only if every non-empty cell in it is a number, so\n * a stray text cell leaves the column out rather than plotting zeros. This is\n * what lets a chart plot \"every other column\" without the author naming twenty\n * fields.\n */\nexport function numericFields(\n data: DataRecord[],\n exclude: string[] = []\n): string[] {\n if (data.length === 0) return []\n const skip = new Set(exclude)\n const seen = new Set<string>()\n const order: string[] = []\n for (const row of data)\n for (const key of Object.keys(row))\n if (!skip.has(key) && !seen.has(key)) {\n seen.add(key)\n order.push(key)\n }\n\n return order.filter((key) => {\n let sawValue = false\n for (const row of data) {\n const v = row[key]\n if (v === undefined || v === \"\") continue\n if (typeof v !== \"number\") return false\n sawValue = true\n }\n return sawValue\n })\n}\n\n// ---- Theme branches ------------------------------------------------------\n\n/** One axis's (x or y) style vocabulary. */\nexport interface AxisConfig {\n /** Style of each marker along the axis. */\n labelStyle: TextStyle\n /** Style of the axis caption. */\n titleStyle: TextStyle\n /**\n * This axis's direction of the plot's internal grid — weight+fill honoured,\n * dash/cap/join ignored (grid lines are drawn as filled rects).\n */\n lineStyle: Stroke\n /**\n * Gap between the plot and the marker row. Only the side facing the plot is\n * read — `.top` for a horizontal axis, `.right` for a vertical one.\n */\n tickPadding: Insets\n /** Gap between the marker row and the caption, read the same side. */\n titlePadding: Insets\n}\n\n/** A legend's per-series colour swatch — a rounded chip, not the caption. */\nexport interface LegendMarkerConfig {\n width: number\n height: number\n borderRadius: number\n stroke: Stroke\n shadow: Shadow\n}\n\n/** A legend's visual theme. */\nexport interface LegendConfig {\n padding: Insets\n /** Caption style — only the swatch carries the series colour. */\n textStyle: TextStyle\n /** Gap between legend entries. */\n itemGap: number\n markerStyle: LegendMarkerConfig\n}\n\n/** The plot panel a cartesian chart draws its marks over. */\nexport interface PlotAreaConfig {\n stroke: Stroke\n fill: Fill\n shadow: Shadow\n}\n\nconst AXIS_LABEL_STYLE: TextStyle = {\n fontSize: 24,\n fontWeight: 700,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n}\nconst AXIS_TITLE_STYLE: TextStyle = {\n fontSize: 30,\n fontWeight: 600,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n}\nconst AXIS_LINE_STYLE: Stroke = { weight: 2, fill: CHART_PALETTE.gridColor }\n\n/** The default styling of a horizontal (marker row beneath the plot) axis. */\nexport const DEFAULT_X_AXIS: AxisConfig = {\n labelStyle: AXIS_LABEL_STYLE,\n titleStyle: AXIS_TITLE_STYLE,\n lineStyle: AXIS_LINE_STYLE,\n tickPadding: 20,\n titlePadding: 4,\n}\n\n/** The default styling of a vertical (marker column beside the plot) axis. */\nexport const DEFAULT_Y_AXIS: AxisConfig = {\n labelStyle: { ...AXIS_LABEL_STYLE, fontWeight: 500, textAlign: \"right\" },\n titleStyle: AXIS_TITLE_STYLE,\n lineStyle: AXIS_LINE_STYLE,\n tickPadding: 40,\n titlePadding: 24,\n}\n\n/**\n * The default plot panel: **unpainted**, framed. A chart reads against the\n * stage rather than punching a panel into it, which is the look the family was\n * designed at.\n */\nexport const DEFAULT_PLOT_AREA: PlotAreaConfig = {\n fill: [],\n stroke: { weight: 6, fill: CHART_PALETTE.borderColor },\n shadow: [],\n}\n\n/** The default legend styling, shared by every chart that draws one. */\nexport const DEFAULT_LEGEND: LegendConfig = {\n padding: 0,\n textStyle: {\n fontSize: 30,\n fontWeight: 600,\n textAlign: \"left\",\n fill: CHART_PALETTE.markerColor,\n },\n itemGap: 44,\n markerStyle: {\n width: 60,\n height: 24,\n borderRadius: 6,\n stroke: [],\n shadow: [],\n },\n}\n\n/** The default per-series stroke palette — {@link DEFAULT_SERIES_COLORS}, drawn 4px. */\nexport const DEFAULT_SERIES_STROKES: Stroke[] = DEFAULT_SERIES_COLORS.map(\n (fill) => ({ weight: 4, fill })\n)\n\n/** The default per-series fill palette — the same colours, as solid paint. */\nexport const DEFAULT_SERIES_FILLS: Fill[] = DEFAULT_SERIES_COLORS.map(\n (fill) => fill\n)\n\n// ---- Theme branch resolvers ----------------------------------------------\n// Each chart type assembles its own theme out of these, so \"the axis furniture\"\n// means one thing across the family and each chart still declares only the\n// branches it actually draws.\n\nexport function resolveAxisConfig(\n axis: Partial<AxisConfig> | undefined,\n previous: AxisConfig\n): AxisConfig {\n return {\n labelStyle: textOps.resolveStyle(axis?.labelStyle, previous.labelStyle),\n titleStyle: textOps.resolveStyle(axis?.titleStyle, previous.titleStyle),\n lineStyle: strokeOps.resolve(axis?.lineStyle ?? previous.lineStyle),\n tickPadding: insetsOps.resolve(\n axis?.tickPadding ?? previous.tickPadding,\n previous.tickPadding as InsetsResolved\n ),\n titlePadding: insetsOps.resolve(\n axis?.titlePadding ?? previous.titlePadding,\n previous.titlePadding as InsetsResolved\n ),\n }\n}\n\nexport function lerpAxisConfig(\n from: AxisConfig,\n to: AxisConfig,\n t: number\n): AxisConfig {\n return {\n labelStyle: textOps.lerpStyle(from.labelStyle, to.labelStyle, t),\n titleStyle: textOps.lerpStyle(from.titleStyle, to.titleStyle, t),\n lineStyle: strokeOps.lerp(\n from.lineStyle as StrokeResolved[],\n to.lineStyle as StrokeResolved[],\n t\n ),\n tickPadding: insetsOps.lerp(\n from.tickPadding as InsetsResolved,\n to.tickPadding as InsetsResolved,\n t\n ),\n titlePadding: insetsOps.lerp(\n from.titlePadding as InsetsResolved,\n to.titlePadding as InsetsResolved,\n t\n ),\n }\n}\n\nexport function resolvePlotArea(\n plotArea: Partial<PlotAreaConfig> | undefined,\n previous: PlotAreaConfig\n): PlotAreaConfig {\n return {\n fill: fillOps.resolve(plotArea?.fill ?? previous.fill),\n stroke: strokeOps.resolve(plotArea?.stroke ?? previous.stroke),\n shadow: shadowOps.resolve(plotArea?.shadow ?? previous.shadow),\n }\n}\n\nexport function lerpPlotArea(\n from: PlotAreaConfig,\n to: PlotAreaConfig,\n t: number\n): PlotAreaConfig {\n return {\n fill: fillOps.lerp(\n from.fill as FillResolved[],\n to.fill as FillResolved[],\n t\n ),\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n shadow: shadowOps.lerp(\n from.shadow as ShadowResolved[],\n to.shadow as ShadowResolved[],\n t\n ),\n }\n}\n\nfunction resolveLegendMarkerConfig(\n marker: Partial<LegendMarkerConfig> | undefined,\n previous: LegendMarkerConfig\n): LegendMarkerConfig {\n return {\n width: marker?.width ?? previous.width,\n height: marker?.height ?? previous.height,\n borderRadius: marker?.borderRadius ?? previous.borderRadius,\n stroke: strokeOps.resolve(marker?.stroke ?? previous.stroke),\n shadow: shadowOps.resolve(marker?.shadow ?? previous.shadow),\n }\n}\n\nfunction lerpLegendMarkerConfig(\n from: LegendMarkerConfig,\n to: LegendMarkerConfig,\n t: number\n): LegendMarkerConfig {\n return {\n width: lerpNumber(from.width, to.width, t),\n height: lerpNumber(from.height, to.height, t),\n borderRadius: lerpNumber(from.borderRadius, to.borderRadius, t),\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n shadow: shadowOps.lerp(\n from.shadow as ShadowResolved[],\n to.shadow as ShadowResolved[],\n t\n ),\n }\n}\n\n/** A legend theme as the author may state it — every branch optional. */\nexport type LegendTheme = Partial<Omit<LegendConfig, \"markerStyle\">> & {\n markerStyle?: Partial<LegendMarkerConfig>\n}\n\nexport function resolveLegendConfig(\n legend: LegendTheme | undefined,\n previous: LegendConfig\n): LegendConfig {\n return {\n padding: insetsOps.resolve(\n legend?.padding ?? previous.padding,\n previous.padding as InsetsResolved\n ),\n textStyle: textOps.resolveStyle(legend?.textStyle, previous.textStyle),\n itemGap: legend?.itemGap ?? previous.itemGap,\n markerStyle: resolveLegendMarkerConfig(\n legend?.markerStyle,\n previous.markerStyle\n ),\n }\n}\n\nexport function lerpLegendConfig(\n from: LegendConfig,\n to: LegendConfig,\n t: number\n): LegendConfig {\n return {\n padding: insetsOps.lerp(\n from.padding as InsetsResolved,\n to.padding as InsetsResolved,\n t\n ),\n textStyle: textOps.lerpStyle(from.textStyle, to.textStyle, t),\n itemGap: lerpNumber(from.itemGap, to.itemGap, t),\n markerStyle: lerpLegendMarkerConfig(from.markerStyle, to.markerStyle, t),\n }\n}\n\n/** A whole-palette override replaces the previous palette outright. */\nexport function resolveSeriesStrokes(\n styles: Stroke[] | undefined,\n previous: Stroke[]\n): Stroke[] {\n return (styles ?? previous).map((s) => strokeOps.resolve(s))\n}\n\n/** Pairwise by index; a palette that grows/shrinks holds the longer side's tail. */\nexport function lerpSeriesStrokes(\n from: Stroke[],\n to: Stroke[],\n t: number\n): Stroke[] {\n const n = Math.max(from.length, to.length)\n const out: Stroke[] = []\n for (let i = 0; i < n; i++) {\n const a = (from[i] ?? to[i]) as StrokeResolved[]\n const b = (to[i] ?? from[i]) as StrokeResolved[]\n out.push(strokeOps.lerp(a, b, t))\n }\n return out\n}\n\n/** The fill-palette twin of {@link resolveSeriesStrokes}, for filled marks. */\nexport function resolveSeriesFills(\n fills: Fill[] | undefined,\n previous: Fill[]\n): Fill[] {\n return (fills ?? previous).map((f) => fillOps.resolve(f))\n}\n\n/** The fill-palette twin of {@link lerpSeriesStrokes}. */\nexport function lerpSeriesFills(from: Fill[], to: Fill[], t: number): Fill[] {\n const n = Math.max(from.length, to.length)\n const out: Fill[] = []\n for (let i = 0; i < n; i++) {\n const a = (from[i] ?? to[i]) as FillResolved[]\n const b = (to[i] ?? from[i]) as FillResolved[]\n out.push(fillOps.lerp(a, b, t))\n }\n return out\n}\n\n// ---- Per-series paint ----------------------------------------------------\n\n/**\n * The effective stroke for series `index`: the palette's entry at\n * `index % palette.length`, with the series' own `fill`, if set, overriding just\n * the last (topmost) layer's colour.\n */\nexport function resolveSeriesStroke(\n palette: Stroke[],\n series: ChartSeries,\n index: number\n): Stroke {\n const entry: Stroke =\n palette.length > 0\n ? palette[index % palette.length]\n : { weight: 4, fill: \"white\" }\n if (series.fill == null) return entry\n const layers = strokeOps.resolve(entry)\n if (layers.length === 0) return { weight: 4, fill: series.fill }\n const next = [...layers]\n next[next.length - 1] = {\n ...next[next.length - 1],\n fill: fillOps.resolve(series.fill),\n }\n return next\n}\n\n/**\n * The effective *colour* for series `index` — the same colour\n * {@link resolveSeriesStroke} draws its line in — for contexts (a legend\n * swatch) that only need the fill.\n */\nexport function resolveSeriesFill(\n palette: Stroke[],\n series: ChartSeries,\n index: number\n): Fill {\n const layers = strokeOps.resolve(resolveSeriesStroke(palette, series, index))\n return layers[layers.length - 1]?.fill ?? \"white\"\n}\n\n/**\n * The effective paint for mark `index` of a **filled** chart (a bar, a wedge):\n * the series' own `fill` when it carries one, else the palette's entry for its\n * index, cycled.\n *\n * The stroke twin above has to reach inside a stroke to swap one layer's colour;\n * a filled mark has no such geometry wrapped around its paint, so an override is\n * simply the whole answer.\n */\nexport function resolvePalettePaint(\n palette: Fill[],\n override: Fill | undefined,\n index: number\n): Fill {\n if (override != null) return override\n if (palette.length === 0) return \"white\"\n return palette[index % palette.length]\n}\n\n// ---- Scales and formatting -----------------------------------------------\n\n\n/**\n * Format a marker value: integers plain, otherwise trimmed to one decimal, or to\n * as many as the axis's tick `step` needs to tell neighbouring ticks apart.\n *\n * One decimal is the floor, so a step of 0.1 or more reads exactly as it always\n * has; a finer step (a unit axis ticked every 0.05) gets two, instead of five\n * ticks captioned `0.1 0.1 0.2 0.2 0.3`. Trailing zeros are dropped either way.\n */\nexport function formatMarker(value: number, step?: number): string {\n if (Number.isInteger(value)) return String(value)\n const decimals = Math.max(1, step === undefined ? 1 : decimalsFor(step))\n return value.toFixed(decimals).replace(/(\\.\\d*?)0+$/, \"$1\").replace(/\\.$/, \"\")\n}\n\n/** Decimal places needed to write `step` exactly, capped at six. */\nfunction decimalsFor(step: number): number {\n if (!(step > 0) || !Number.isFinite(step)) return 1\n for (let d = 0; d <= 6; d++) {\n const scaled = step * 10 ** d\n if (Math.abs(scaled - Math.round(scaled)) < 1e-6 * Math.max(1, scaled)) return d\n }\n // An irrational-looking step (a third): as many places as separate the ticks.\n return Math.min(6, Math.max(1, Math.ceil(-Math.log10(step)) + 1))\n}\n\n/** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */\nexport function markerStep(markers: readonly number[]): number | undefined {\n const sorted = [...markers].filter(Number.isFinite).sort((a, b) => a - b)\n let step: number | undefined\n for (let i = 1; i < sorted.length; i++) {\n const gap = sorted[i] - sorted[i - 1]\n if (gap > 1e-12 && (step === undefined || gap < step)) step = gap\n }\n return step\n}\n\n/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */\nexport function formatPercent(fraction: number): string {\n const pct = fraction * 100\n if (Number.isInteger(pct)) return `${pct}%`\n return `${pct.toFixed(1).replace(/\\.0$/, \"\")}%`\n}\n\n/** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */\nexport function markerValues([min, max]: Range, markerCount: number): number[] {\n const n = Math.max(2, Math.round(markerCount))\n return Array.from({ length: n + 1 }, (_, i) => min + ((max - min) / n) * i)\n}\n\n// Lifted into the engine, because a graph and a diagram want them too — see\n// `@motionscript/sdk/component`. Re-exported so a chart, and anything that\n// copied one, still reaches them where it always did.\nexport { niceStep, enterBudget } from \"@motionscript/sdk/component\"\n"]}
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,UAAU,GAOX,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAoCtD;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,MAAoC,EACpC,QAA2B;IAE3B,OAAO;QACL,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,QAAQ,EAAE,KAAK,IAAI,EAAE;QAC7C,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,QAAQ,EAAE,KAAK;QACvC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,QAAQ,EAAE,KAAK;QACvC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM;KAC3C,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAsB,EACtB,EAAoB,EACpB,CAAS;IAET,OAAO;QACL,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK;QACtC,KAAK,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,KAAK,EAAE,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;QACjD,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM;KAC1C,CAAA;A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KAAK,GAAa,EAAE,CAAA;IAC1B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;QAAE,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACvF,MAAM,EAAE,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAA;IACnE,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;AACjD,CAAC","sourcesContent":["/**\n * What every chart shares: series, axis scaling and formatting, and the theme\n * leaves each chart's theme is assembled from. No `Node` imports, so a host's\n * inspector mappings can build a partial theme without the components.\n *\n * A mapper merges partial input onto a `previous` resolved value (idempotent). A\n * tween interpolates two resolved values leaf by leaf, but categorical fields\n * (`fontFamily`, `textAlign`) and any field `undefined` on either side step at\n * the midpoint: defaulting the missing side to 0 would animate a font weight\n * down to nothing on the way to \"unset\".\n */\n\nimport {\n lerpNumber,\n type DataRecord,\n type Fill,\n type Insets,\n type Shadow,\n type Stroke,\n type TextStyle,\n} from \"@motionscript/sdk\"\nimport { niceStep } from \"@motionscript/sdk/component\"\n\n/** One series of a chart: a column of the table, captioned and painted. */\nexport interface ChartSeries {\n /** Key into each data row for this series' value. */\n field: string\n /** The legend caption; empty or absent shows `field`. */\n label?: string\n /** Overrides the theme palette's entry for this series' index, for its mark and legend swatch. */\n fill?: Fill\n /** Defaults to `true`. */\n enabled?: boolean\n}\n\n/** A `[min, max]` numeric range in data units. */\nexport type Range = [min: number, max: number]\n\n/** One axis's *data* domain, as opposed to {@link AxisConfig}, which is how it is styled. */\nexport interface AxisDomainConfig {\n /** Caption drawn alongside the axis; `\"\"` hides it. */\n label?: string\n /** Derived from the data bounds when omitted. */\n range?: Range\n /** Derived (five evenly spaced) when omitted. */\n ticks?: number[]\n /**\n * A `number-format` pattern such as `#,##0.00` or `$#,##0`. It lives here, not\n * in {@link AxisConfig}, because it says what the column holds and has to\n * survive a re-theme.\n */\n format?: string\n}\n\n/** An {@link AxisDomainConfig} with `range` and `ticks` worked out. */\nexport type ResolvedAxisDomain = AxisDomainConfig & { readonly range: Range; readonly ticks: number[] }\n\n/**\n * Merges partial input onto `previous`, so a later `.set({ yAxis: {...} })`\n * patches `label`/`range`/`ticks` independently. An unset `range`/`ticks` is the\n * auto-derive signal.\n */\nexport function resolveAxisDomain(\n domain: AxisDomainConfig | undefined,\n previous?: AxisDomainConfig\n): AxisDomainConfig {\n return {\n label: domain?.label ?? previous?.label ?? \"\",\n range: domain?.range ?? previous?.range,\n ticks: domain?.ticks ?? previous?.ticks,\n format: domain?.format ?? previous?.format,\n }\n}\n\n/**\n * Interpolates `range` and `ticks` numerically (ticks pairwise by index).\n * `label`, `format`, and either field when one side is auto, step at the\n * midpoint: there is no halfway between `$#,##0` and `0.0%`.\n */\nexport function lerpAxisDomain(\n from: AxisDomainConfig,\n to: AxisDomainConfig,\n t: number\n): AxisDomainConfig {\n return {\n label: t < 0.5 ? from.label : to.label,\n range: lerpOptionalRange(from.range, to.range, t),\n ticks: lerpOptionalTicks(from.ticks, to.ticks, t),\n format: t < 0.5 ? from.format : to.format,\n }\n}\n\nfunction lerpOptionalRange(\n from: Range | undefined,\n to: Range | undefined,\n t: number\n): Range | undefined {\n if (!from || !to) return t < 0.5 ? from : to\n return [lerpNumber(from[0], to[0], t), lerpNumber(from[1], to[1], t)]\n}\n\nfunction lerpOptionalTicks(\n from: number[] | undefined,\n to: number[] | undefined,\n t: number\n): number[] | undefined {\n if (!from || !to) return t < 0.5 ? from : to\n const n = Math.max(from.length, to.length)\n const out: number[] = []\n for (let i = 0; i < n; i++) {\n out.push(lerpNumber(from[i] ?? to[i], to[i] ?? from[i], t))\n }\n return out\n}\n\n/**\n * An axis domain part-way through a tween that leaves or reaches a `range` or\n * `ticks` left to the data: both ends as stored, and how far along. Only the\n * chart knows what an auto side draws as, so {@link settleAxisDomain} resolves\n * it there. Its own fields are the plain {@link lerpAxisDomain} of its ends, so\n * a mapper merging onto one still reads a domain.\n */\nexport interface AxisDomainBlend extends AxisDomainConfig {\n readonly blend: { readonly from: AxisDomainConfig; readonly to: AxisDomainConfig; readonly t: number }\n}\n\nfunction blendOf(domain: AxisDomainConfig): AxisDomainBlend[\"blend\"] | undefined {\n return (domain as Partial<AxisDomainBlend>).blend\n}\n\n/**\n * The axis entry tween behind `to({ yAxis: { range } })`. Between explicit\n * domains it is {@link lerpAxisDomain}, and a restated `range` without `ticks`\n * spreads ticks across it, keeping their count. When either end leaves `range`\n * or `ticks` to the data, the value between is an {@link AxisDomainBlend}, so a\n * rescale from an auto axis is continuous rather than a cut at the midpoint.\n */\nexport function lerpAxisEntry(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig {\n // The mapper merged the request onto `from`, so a field it left unstated is `from`'s own, by identity.\n const rangeMoved = to.range !== from.range\n const target = rangeMoved && to.range && to.ticks && to.ticks === from.ticks\n ? { ...to, ticks: markerValues(to.range, Math.max(2, to.ticks.length) - 1) }\n : to\n const blended = blendOf(from) !== undefined\n const moved = blended || rangeMoved || target.ticks !== from.ticks\n const auto = blended || from.range === undefined || from.ticks === undefined || target.range === undefined || target.ticks === undefined\n if (!moved || !auto) return lerpAxisDomain(from, target, t)\n if (t === 0) return from\n if (t === 1) return target\n const blend: AxisDomainBlend = { ...lerpAxisDomain(from, target, t), blend: { from, to: target, t } }\n return blend\n}\n\n/** `domain` as drawn: `drawn` resolves a plain domain's auto `range` and `ticks`; a blend is the lerp of what its ends draw. */\nexport function settleAxisDomain(domain: AxisDomainConfig, drawn: (domain: AxisDomainConfig) => AxisDomainConfig): AxisDomainConfig {\n const blend = blendOf(domain)\n if (!blend) return drawn(domain)\n return lerpAxisDomain(settleAxisDomain(blend.from, drawn), settleAxisDomain(blend.to, drawn), blend.t)\n}\n\n/** The colour tokens the default themes are built from: a dark plot panel with warm-grey axis furniture. */\nconst CHART_PALETTE = {\n plotFill: \"#15130e\",\n borderColor: \"#4a4036\",\n gridColor: \"#2c2820\",\n /** Axis markers, axis captions and legend labels. */\n markerColor: \"#8a7f70\",\n /** A spotlit region's dashed rules and wash. */\n regionColor: \"#d99a3a\",\n} as const\n\n/** Opacity an un-spotlighted series fades to, mark and legend entry alike. */\nexport const SPOTLIGHT_DIM = 0.2\n\n/**\n * Reads a numeric field off a row. A string column plots as 0, so a quoted or\n * unit-suffixed column needs the CSV parser's numeric coercion first.\n */\nexport function num(row: DataRecord, field: string | undefined): number {\n if (field === undefined) return 0\n const v = row[field]\n // A `NaN` or infinite cell is no more a measurement than a missing one: read\n // as 0, it cannot poison the scale and turn every point into `NaN`.\n return typeof v === \"number\" && Number.isFinite(v) ? v : 0\n}\n\n/** The counterpart to {@link num} for the columns a chart names things by; a missing cell reads as empty, not `\"undefined\"`. */\nexport function text(row: DataRecord, field: string | undefined): string {\n if (field === undefined || field === \"\") return \"\"\n const v = row[field]\n return v === undefined || v === null ? \"\" : String(v)\n}\n\n/**\n * Every numeric column of `data` in header order, skipping `exclude`. A column\n * is numeric only if every non-empty cell is a number, so a stray text cell\n * drops the column rather than plotting zeros.\n */\nexport function numericFields(\n data: DataRecord[],\n exclude: string[] = []\n): string[] {\n if (data.length === 0) return []\n const skip = new Set(exclude)\n const seen = new Set<string>()\n const order: string[] = []\n for (const row of data)\n for (const key of Object.keys(row))\n if (!skip.has(key) && !seen.has(key)) {\n seen.add(key)\n order.push(key)\n }\n\n return order.filter((key) => {\n let sawValue = false\n for (const row of data) {\n const v = row[key]\n if (v === undefined || v === \"\") continue\n if (typeof v !== \"number\") return false\n sawValue = true\n }\n return sawValue\n })\n}\n\n/** One axis's (x or y) style vocabulary. */\nexport interface AxisConfig {\n /** Style of each marker along the axis. */\n labelStyle: TextStyle\n titleStyle: TextStyle\n /** This axis's grid lines: weight and fill honoured, dash/cap/join ignored (they are filled rects). */\n lineStyle: Stroke\n /** Gap between the plot and the marker row; only the side facing the plot is read (`.top` horizontal, `.right` vertical). */\n tickPadding: Insets\n /** Gap between the marker row and the caption, read the same side. */\n titlePadding: Insets\n}\n\n/** A legend's per-series colour swatch. */\nexport interface LegendMarkerConfig {\n width: number\n height: number\n borderRadius: number\n stroke: Stroke\n shadow: Shadow\n}\n\nexport interface LegendConfig {\n padding: Insets\n /** Only the swatch carries the series colour. */\n textStyle: TextStyle\n itemGap: number\n markerStyle: LegendMarkerConfig\n}\n\nconst AXIS_LABEL_STYLE: TextStyle = {\n fontSize: 24,\n fontWeight: 700,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n}\nconst AXIS_TITLE_STYLE: TextStyle = {\n fontSize: 30,\n fontWeight: 600,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n}\nconst AXIS_LINE_STYLE: Stroke = { weight: 2, fill: CHART_PALETTE.gridColor }\n\nexport const DEFAULT_X_AXIS: AxisConfig = {\n labelStyle: AXIS_LABEL_STYLE,\n titleStyle: AXIS_TITLE_STYLE,\n lineStyle: AXIS_LINE_STYLE,\n tickPadding: 20,\n titlePadding: 4,\n}\n\nexport const DEFAULT_Y_AXIS: AxisConfig = {\n labelStyle: { ...AXIS_LABEL_STYLE, fontWeight: 500, textAlign: \"right\" },\n titleStyle: AXIS_TITLE_STYLE,\n lineStyle: AXIS_LINE_STYLE,\n tickPadding: 40,\n titlePadding: 24,\n}\n\nexport const DEFAULT_LEGEND: LegendConfig = {\n padding: 0,\n textStyle: {\n fontSize: 30,\n fontWeight: 600,\n textAlign: \"left\",\n fill: CHART_PALETTE.markerColor,\n },\n itemGap: 44,\n markerStyle: {\n width: 60,\n height: 24,\n borderRadius: 6,\n stroke: [],\n shadow: [],\n },\n}\n\n/**\n * Format a marker value: integers plain, otherwise one decimal, or as many as\n * the tick `step` needs to tell neighbours apart (a unit axis ticked every 0.05\n * gets two, not `0.1 0.1 0.2 0.2 0.3`). Trailing zeros are dropped.\n */\nexport function formatMarker(value: number, step?: number): string {\n if (Number.isInteger(value)) return String(value)\n const decimals = Math.max(1, step === undefined ? 1 : decimalsFor(step))\n return value.toFixed(decimals).replace(/(\\.\\d*?)0+$/, \"$1\").replace(/\\.$/, \"\")\n}\n\n/** Decimal places needed to write `step` exactly, capped at six. */\nfunction decimalsFor(step: number): number {\n if (!(step > 0) || !Number.isFinite(step)) return 1\n for (let d = 0; d <= 6; d++) {\n const scaled = step * 10 ** d\n if (Math.abs(scaled - Math.round(scaled)) < 1e-6 * Math.max(1, scaled)) return d\n }\n // An irrational-looking step (a third): as many places as separate the ticks.\n return Math.min(6, Math.max(1, Math.ceil(-Math.log10(step)) + 1))\n}\n\n/** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */\nexport function markerStep(markers: readonly number[]): number | undefined {\n const sorted = [...markers].filter(Number.isFinite).sort((a, b) => a - b)\n let step: number | undefined\n for (let i = 1; i < sorted.length; i++) {\n const gap = sorted[i] - sorted[i - 1]\n if (gap > 1e-12 && (step === undefined || gap < step)) step = gap\n }\n return step\n}\n\n/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */\nexport function formatPercent(fraction: number): string {\n const pct = fraction * 100\n if (Number.isInteger(pct)) return `${pct}%`\n return `${pct.toFixed(1).replace(/\\.0$/, \"\")}%`\n}\n\n/** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */\nexport function markerValues([min, max]: Range, markerCount: number): number[] {\n const n = Math.max(2, Math.round(markerCount))\n return Array.from({ length: n + 1 }, (_, i) => min + ((max - min) / n) * i)\n}\n\n/** `[lo, hi]` nudged out to bounds a whole number of tidy steps apart, about `divisions` of them. */\nexport function niceRange([lo, hi]: Range, divisions: number): Range {\n const segments = Math.max(1, Math.round(divisions))\n if (hi === lo) return constantScale(lo, segments)\n const step = niceStep((hi - lo) / segments)\n return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]\n}\n\n/**\n * The scale for constant data. A zero-width scale would put every tick on one\n * value and the line on the floor, so it widens by a step sized to the\n * magnitude (`5` gets `[3, 7]`), or `[0, 1]` for zero.\n */\nfunction constantScale(value: number, segments: number): Range {\n if (value === 0) return [0, 1]\n const step = niceStep(Math.abs(value) / segments)\n return [value - step, value + step]\n}\n\n/**\n * Ticks for a range worked out from the data: every multiple of the tidiest\n * step (1, 2 or 5 times a power of ten) that divides it into about `divisions`\n * parts, so zero is a tick whenever the range spans it. A range no such step\n * divides (an author's) is split evenly instead.\n */\nexport function niceTicks([lo, hi]: Range, divisions: number): number[] {\n const span = hi - lo\n const target = Math.max(1, Math.round(divisions))\n if (!(span > 0)) return markerValues([lo, hi], target)\n const whole = (v: number) => Math.abs(v - Math.round(v)) < 1e-6\n const base = niceStep(span / target)\n let best: number | undefined\n for (const step of ladder(base)) {\n const parts = span / step\n if (!whole(parts) || !whole(lo / step) || parts < 2 || parts > 8) continue\n if (best === undefined || Math.abs(parts - target) < Math.abs(span / best - target)) best = step\n }\n if (best === undefined) return markerValues([lo, hi], target)\n const first = Math.round(lo / best)\n return Array.from({ length: Math.round(span / best) + 1 }, (_, k) => Number(((first + k) * best).toPrecision(12)))\n}\n\n/** `step` and its neighbours on the 1-2-5 ladder, two either side. */\nfunction ladder(step: number): number[] {\n const mag = 10 ** Math.floor(Math.log10(step))\n const rungs: number[] = []\n for (const m of [mag / 10, mag, mag * 10]) for (const k of [1, 2, 5]) rungs.push(k * m)\n const at = rungs.findIndex((r) => Math.abs(r - step) < step * 1e-9)\n return rungs.slice(Math.max(0, at - 2), at + 3)\n}\n"]}