@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.10

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 (152) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/NOTICE +49 -0
  3. package/README.md +99 -0
  4. package/dist/bar-chart/bar-chart.d.ts +133 -228
  5. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  6. package/dist/bar-chart/bar-chart.js +386 -565
  7. package/dist/bar-chart/bar-chart.js.map +1 -1
  8. package/dist/bar-chart/category-axis.d.ts +35 -41
  9. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  10. package/dist/bar-chart/category-axis.js +93 -115
  11. package/dist/bar-chart/category-axis.js.map +1 -1
  12. package/dist/bar-chart/chart-bars.d.ts +50 -70
  13. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  14. package/dist/bar-chart/chart-bars.js +155 -210
  15. package/dist/bar-chart/chart-bars.js.map +1 -1
  16. package/dist/bar-chart/index.d.ts +2 -2
  17. package/dist/bar-chart/index.d.ts.map +1 -1
  18. package/dist/bar-chart/index.js +1 -1
  19. package/dist/bar-chart/index.js.map +1 -1
  20. package/dist/bar-chart/shared.d.ts +7 -7
  21. package/dist/bar-chart/shared.d.ts.map +1 -1
  22. package/dist/bar-chart/shared.js +7 -7
  23. package/dist/bar-chart/shared.js.map +1 -1
  24. package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
  25. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
  26. package/dist/browser/index.js +1 -1
  27. package/dist/browser/index.js.map +3 -3
  28. package/dist/browser/kit.js +1 -1
  29. package/dist/browser/manifest.json +4 -3
  30. package/dist/engine.d.ts +10 -8
  31. package/dist/engine.d.ts.map +1 -1
  32. package/dist/engine.js +10 -8
  33. package/dist/engine.js.map +1 -1
  34. package/dist/kit/cartesian.d.ts +44 -0
  35. package/dist/kit/cartesian.d.ts.map +1 -0
  36. package/dist/kit/cartesian.js +59 -0
  37. package/dist/kit/cartesian.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +10 -11
  39. package/dist/kit/chart-border.d.ts.map +1 -1
  40. package/dist/kit/chart-border.js +15 -32
  41. package/dist/kit/chart-border.js.map +1 -1
  42. package/dist/kit/chart-canvas.d.ts +32 -21
  43. package/dist/kit/chart-canvas.d.ts.map +1 -1
  44. package/dist/kit/chart-canvas.js +33 -90
  45. package/dist/kit/chart-canvas.js.map +1 -1
  46. package/dist/kit/chart-legend.d.ts +123 -85
  47. package/dist/kit/chart-legend.d.ts.map +1 -1
  48. package/dist/kit/chart-legend.js +137 -186
  49. package/dist/kit/chart-legend.js.map +1 -1
  50. package/dist/kit/entries.d.ts +17 -0
  51. package/dist/kit/entries.d.ts.map +1 -0
  52. package/dist/kit/entries.js +19 -0
  53. package/dist/kit/entries.js.map +1 -0
  54. package/dist/kit/motion.d.ts +48 -0
  55. package/dist/kit/motion.d.ts.map +1 -0
  56. package/dist/kit/motion.js +63 -0
  57. package/dist/kit/motion.js.map +1 -0
  58. package/dist/kit/paints.d.ts +10 -0
  59. package/dist/kit/paints.d.ts.map +1 -0
  60. package/dist/kit/paints.js +12 -0
  61. package/dist/kit/paints.js.map +1 -0
  62. package/dist/kit/shared.d.ts +61 -10
  63. package/dist/kit/shared.d.ts.map +1 -1
  64. package/dist/kit/shared.js +108 -13
  65. package/dist/kit/shared.js.map +1 -1
  66. package/dist/kit/vertical-axis.d.ts +48 -61
  67. package/dist/kit/vertical-axis.d.ts.map +1 -1
  68. package/dist/kit/vertical-axis.js +97 -132
  69. package/dist/kit/vertical-axis.js.map +1 -1
  70. package/dist/line-chart/chart-line.d.ts +60 -77
  71. package/dist/line-chart/chart-line.d.ts.map +1 -1
  72. package/dist/line-chart/chart-line.js +100 -121
  73. package/dist/line-chart/chart-line.js.map +1 -1
  74. package/dist/line-chart/chart-region.d.ts +32 -33
  75. package/dist/line-chart/chart-region.d.ts.map +1 -1
  76. package/dist/line-chart/chart-region.js +31 -65
  77. package/dist/line-chart/chart-region.js.map +1 -1
  78. package/dist/line-chart/horizontal-axis.d.ts +58 -64
  79. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  80. package/dist/line-chart/horizontal-axis.js +94 -123
  81. package/dist/line-chart/horizontal-axis.js.map +1 -1
  82. package/dist/line-chart/index.d.ts +3 -3
  83. package/dist/line-chart/index.d.ts.map +1 -1
  84. package/dist/line-chart/index.js +2 -2
  85. package/dist/line-chart/index.js.map +1 -1
  86. package/dist/line-chart/line-chart.d.ts +156 -303
  87. package/dist/line-chart/line-chart.d.ts.map +1 -1
  88. package/dist/line-chart/line-chart.js +410 -638
  89. package/dist/line-chart/line-chart.js.map +1 -1
  90. package/dist/line-chart/shared.d.ts +7 -7
  91. package/dist/line-chart/shared.d.ts.map +1 -1
  92. package/dist/line-chart/shared.js +23 -8
  93. package/dist/line-chart/shared.js.map +1 -1
  94. package/dist/line-chart/x-scale.d.ts +4 -11
  95. package/dist/line-chart/x-scale.d.ts.map +1 -1
  96. package/dist/line-chart/x-scale.js +16 -5
  97. package/dist/line-chart/x-scale.js.map +1 -1
  98. package/dist/nodes.d.ts +6 -9
  99. package/dist/nodes.d.ts.map +1 -1
  100. package/dist/nodes.js +7 -9
  101. package/dist/nodes.js.map +1 -1
  102. package/dist/pie-chart/index.d.ts +2 -2
  103. package/dist/pie-chart/index.d.ts.map +1 -1
  104. package/dist/pie-chart/index.js +1 -1
  105. package/dist/pie-chart/index.js.map +1 -1
  106. package/dist/pie-chart/pie-chart.d.ts +108 -126
  107. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  108. package/dist/pie-chart/pie-chart.js +202 -271
  109. package/dist/pie-chart/pie-chart.js.map +1 -1
  110. package/dist/pie-chart/pie-legend.d.ts +84 -31
  111. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  112. package/dist/pie-chart/pie-legend.js +93 -107
  113. package/dist/pie-chart/pie-legend.js.map +1 -1
  114. package/dist/pie-chart/pie-ring.d.ts +160 -122
  115. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  116. package/dist/pie-chart/pie-ring.js +333 -361
  117. package/dist/pie-chart/pie-ring.js.map +1 -1
  118. package/dist/pie-chart/shared.d.ts +12 -6
  119. package/dist/pie-chart/shared.d.ts.map +1 -1
  120. package/dist/pie-chart/shared.js +14 -8
  121. package/dist/pie-chart/shared.js.map +1 -1
  122. package/package.json +7 -4
  123. package/src/bar-chart/bar-chart.ts +424 -686
  124. package/src/bar-chart/category-axis.ts +96 -111
  125. package/src/bar-chart/chart-bars.ts +178 -201
  126. package/src/bar-chart/index.ts +2 -2
  127. package/src/bar-chart/shared.ts +7 -7
  128. package/src/engine.ts +10 -8
  129. package/src/kit/cartesian.ts +81 -0
  130. package/src/kit/chart-border.ts +23 -34
  131. package/src/kit/chart-canvas.ts +45 -80
  132. package/src/kit/chart-legend.ts +185 -206
  133. package/src/kit/entries.ts +20 -0
  134. package/src/kit/motion.ts +90 -0
  135. package/src/kit/paints.ts +15 -0
  136. package/src/kit/shared.ts +120 -13
  137. package/src/kit/vertical-axis.ts +111 -141
  138. package/src/line-chart/chart-line.ts +103 -155
  139. package/src/line-chart/chart-region.ts +36 -81
  140. package/src/line-chart/horizontal-axis.ts +102 -153
  141. package/src/line-chart/index.ts +3 -3
  142. package/src/line-chart/line-chart.ts +463 -759
  143. package/src/line-chart/shared.ts +22 -8
  144. package/src/line-chart/x-scale.ts +20 -5
  145. package/src/nodes.ts +8 -10
  146. package/src/pie-chart/index.ts +2 -2
  147. package/src/pie-chart/pie-chart.ts +225 -303
  148. package/src/pie-chart/pie-legend.ts +125 -115
  149. package/src/pie-chart/pie-ring.ts +388 -443
  150. package/src/pie-chart/shared.ts +14 -8
  151. package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
  152. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
@@ -0,0 +1,12 @@
1
+ /** Declare `paints` from a component's `load`. */
2
+ export function loadPaints(loader, paints) {
3
+ for (const fill of paints.fills ?? [])
4
+ loader.fill(fill);
5
+ for (const strokes of paints.strokes ?? [])
6
+ for (const stroke of strokes)
7
+ loader.fill(stroke.fill);
8
+ for (const shadows of paints.shadows ?? [])
9
+ for (const shadow of shadows)
10
+ loader.fill(shadow.fill);
11
+ }
12
+ //# sourceMappingURL=paints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paints.js","sourceRoot":"","sources":["../../src/kit/paints.ts"],"names":[],"mappings":"AASA,kDAAkD;AAClD,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,MAAkB;IAC3D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,IAAI,EAAE;QAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACxD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,IAAI,EAAE;QAAE,KAAK,MAAM,MAAM,IAAI,OAAO;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAClG,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,OAAO,IAAI,EAAE;QAAE,KAAK,MAAM,MAAM,IAAI,OAAO;YAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;AACpG,CAAC","sourcesContent":["import type { FillResolved, Loader, ShadowResolved, StrokeResolved } from \"@motionscript/sdk\"\n\n/** Paints a chart part holds in entries of its own, which no paint entry loads for it. */\nexport interface PartPaints {\n readonly fills?: readonly (readonly FillResolved[])[]\n readonly strokes?: readonly (readonly StrokeResolved[])[]\n readonly shadows?: readonly (readonly ShadowResolved[])[]\n}\n\n/** Declare `paints` from a component's `load`. */\nexport function loadPaints(loader: Loader, paints: PartPaints): void {\n for (const fill of paints.fills ?? []) loader.fill(fill)\n for (const strokes of paints.strokes ?? []) for (const stroke of strokes) loader.fill(stroke.fill)\n for (const shadows of paints.shadows ?? []) for (const shadow of shadows) loader.fill(shadow.fill)\n}\n"]}
@@ -12,9 +12,8 @@
12
12
  * that three times would mean three answers to "how does a chart round its axis"
13
13
  * within one app.
14
14
  *
15
- * Kept renderer-agnostic (no `Node` imports) so the studio's own inspector
16
- * mappings can build a partial theme without pulling the node classes in, the
17
- * same way `line-chart-props.ts` always has.
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.
18
17
  *
19
18
  * **Two conventions run through every resolver and lerp below**, inherited from
20
19
  * the shape system's `resolveStroke`/`resolveShadow`:
@@ -28,7 +27,7 @@
28
27
  * defaulting the missing side to 0 would animate a font weight down to nothing
29
28
  * on the way to "unset".
30
29
  */
31
- import { type DataRecord, type Fill, type Insets, type Shadow, type Stroke, type TextStyle } from "@motionscript/core";
30
+ import { type DataRecord, type Fill, type Insets, type Shadow, type Stroke, type TextStyle } from "@motionscript/sdk";
32
31
  /**
33
32
  * One series of a chart: a column of the table, captioned and painted.
34
33
  *
@@ -80,19 +79,61 @@ export interface AxisDomainConfig {
80
79
  format?: string;
81
80
  }
82
81
  /**
83
- * An axis domain's @property mapper: merges the author's partial input onto
82
+ * An axis domain entry's resolve: merges the author's partial input onto
84
83
  * `previous`, so a later partial `.set({ yAxis: {...} })` patches
85
84
  * `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`
86
85
  * after the merge is the auto-derive signal the scale getters read.
87
86
  */
88
87
  export declare function resolveAxisDomain(domain: AxisDomainConfig | undefined, previous?: AxisDomainConfig): AxisDomainConfig;
89
88
  /**
90
- * An axis domain's @property tween: interpolates `range`/`ticks` numerically
89
+ * An axis domain entry's lerp: interpolates `range`/`ticks` numerically
91
90
  * (pairwise by index for `ticks`), so a `to` command that restates a range
92
91
  * rescales the plot smoothly. `label`, and either field when one side is in
93
92
  * auto-derive mode, step at the midpoint.
94
93
  */
95
94
  export declare function lerpAxisDomain(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig;
95
+ /**
96
+ * Where a generic `to()` of an axis domain should land, given the domain as it
97
+ * is *drawn* (`drawn`, with `range` and `ticks` resolved off the data), or
98
+ * `undefined` when the request states neither a `range` nor `ticks` and the
99
+ * plain property tween will do.
100
+ *
101
+ * The stored domain of an auto axis has no `range` and no `ticks`, and
102
+ * {@link lerpAxisDomain} steps an unset side at the midpoint, so tweening the
103
+ * stored value from an auto axis is a cut. The charts therefore tween between
104
+ * resolved domains, as their zoom does; this builds the destination. A `range`
105
+ * given without `ticks` keeps the tick *count* the axis already draws, so each
106
+ * marker slides from its old value to its new one instead of the row popping.
107
+ */
108
+ export declare function axisTweenTarget(drawn: AxisDomainConfig, requested: AxisDomainConfig | undefined): AxisDomainConfig | undefined;
109
+ /**
110
+ * An axis domain part-way through a tween that leaves or reaches a `range` or
111
+ * `ticks` left to the data: both ends as stored, and how far along. Only the
112
+ * chart knows what an auto side draws as, so {@link settleAxisDomain} resolves
113
+ * it there. Its own fields are the plain {@link lerpAxisDomain} of its ends, so
114
+ * a mapper merging onto one still reads a domain.
115
+ */
116
+ export interface AxisDomainBlend extends AxisDomainConfig {
117
+ readonly blend: {
118
+ readonly from: AxisDomainConfig;
119
+ readonly to: AxisDomainConfig;
120
+ readonly t: number;
121
+ };
122
+ }
123
+ /**
124
+ * A chart's axis entry tween: what `to({ yAxis: { range } })` moves through.
125
+ * Between two explicit domains it is {@link lerpAxisDomain}, and a restated
126
+ * `range` without `ticks` spreads explicit ticks across it, keeping their count.
127
+ * When either end leaves `range` or `ticks` to the data, the value between is an
128
+ * {@link AxisDomainBlend}, which the chart draws as the blend of what each end
129
+ * draws: a rescale from an auto axis is continuous, not a cut at the midpoint.
130
+ */
131
+ export declare function lerpAxisEntry(from: AxisDomainConfig, to: AxisDomainConfig, t: number): AxisDomainConfig;
132
+ /**
133
+ * `domain` as the chart draws it: `drawn` resolves a plain domain's auto `range`
134
+ * and `ticks` off the data, and a blend is the lerp of what its two ends draw.
135
+ */
136
+ export declare function settleAxisDomain(domain: AxisDomainConfig, drawn: (domain: AxisDomainConfig) => AxisDomainConfig): AxisDomainConfig;
96
137
  /**
97
138
  * The low-level colour tokens the default themes are built from — a dark plot
98
139
  * panel with warm-grey axis furniture.
@@ -119,7 +160,8 @@ export declare const SPOTLIGHT_DIM = 0.2;
119
160
  /** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */
120
161
  export declare function clampUnit(value: number): number;
121
162
  /**
122
- * Read a numeric field off a row, defaulting missing/non-numeric values to 0.
163
+ * Read a numeric field off a row, defaulting missing, non-numeric and non-finite
164
+ * values to 0.
123
165
  *
124
166
  * A column left as strings silently plots as 0, which is why the CSV parser's
125
167
  * numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
@@ -241,11 +283,20 @@ export declare function resolveSeriesFill(palette: Stroke[], series: ChartSeries
241
283
  * simply the whole answer.
242
284
  */
243
285
  export declare function resolvePalettePaint(palette: Fill[], override: Fill | undefined, index: number): Fill;
244
- /** Format a marker value: integers plain, otherwise trimmed to one decimal. */
245
- export declare function formatMarker(value: number): string;
286
+ /**
287
+ * Format a marker value: integers plain, otherwise trimmed to one decimal, or to
288
+ * as many as the axis's tick `step` needs to tell neighbouring ticks apart.
289
+ *
290
+ * One decimal is the floor, so a step of 0.1 or more reads exactly as it always
291
+ * has; a finer step (a unit axis ticked every 0.05) gets two, instead of five
292
+ * ticks captioned `0.1 0.1 0.2 0.2 0.3`. Trailing zeros are dropped either way.
293
+ */
294
+ export declare function formatMarker(value: number, step?: number): string;
295
+ /** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */
296
+ export declare function markerStep(markers: readonly number[]): number | undefined;
246
297
  /** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
247
298
  export declare function formatPercent(fraction: number): string;
248
299
  /** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */
249
300
  export declare function markerValues([min, max]: Range, markerCount: number): number[];
250
- export { niceStep, enterBudget } from "@motionscript/core/component";
301
+ export { niceStep, enterBudget } from "@motionscript/sdk/component";
251
302
  //# sourceMappingURL=shared.d.ts.map
@@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@ -12,9 +12,8 @@
12
12
  * that three times would mean three answers to "how does a chart round its axis"
13
13
  * within one app.
14
14
  *
15
- * Kept renderer-agnostic (no `Node` imports) so the studio's own inspector
16
- * mappings can build a partial theme without pulling the node classes in, the
17
- * same way `line-chart-props.ts` always has.
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.
18
17
  *
19
18
  * **Two conventions run through every resolver and lerp below**, inherited from
20
19
  * the shape system's `resolveStroke`/`resolveShadow`:
@@ -28,9 +27,9 @@
28
27
  * defaulting the missing side to 0 would animate a font weight down to nothing
29
28
  * on the way to "unset".
30
29
  */
31
- import { fillOps, lerpNumber, shadowOps, strokeOps, insetsOps, textOps, } from "@motionscript/core";
30
+ import { fillOps, lerpNumber, shadowOps, strokeOps, insetsOps, textOps, } from "@motionscript/sdk";
32
31
  /**
33
- * An axis domain's @property mapper: merges the author's partial input onto
32
+ * An axis domain entry's resolve: merges the author's partial input onto
34
33
  * `previous`, so a later partial `.set({ yAxis: {...} })` patches
35
34
  * `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`
36
35
  * after the merge is the auto-derive signal the scale getters read.
@@ -44,7 +43,7 @@ export function resolveAxisDomain(domain, previous) {
44
43
  };
45
44
  }
46
45
  /**
47
- * An axis domain's @property tween: interpolates `range`/`ticks` numerically
46
+ * An axis domain entry's lerp: interpolates `range`/`ticks` numerically
48
47
  * (pairwise by index for `ticks`), so a `to` command that restates a range
49
48
  * rescales the plot smoothly. `label`, and either field when one side is in
50
49
  * auto-derive mode, step at the midpoint.
@@ -74,6 +73,68 @@ function lerpOptionalTicks(from, to, t) {
74
73
  }
75
74
  return out;
76
75
  }
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
+ function blendOf(domain) {
100
+ return domain.blend;
101
+ }
102
+ /**
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.
109
+ */
110
+ export function lerpAxisEntry(from, to, t) {
111
+ // The mapper merged the request onto `from`, so a field it left unstated is `from`'s own, by identity.
112
+ const rangeMoved = to.range !== from.range;
113
+ const target = rangeMoved && to.range && to.ticks && to.ticks === from.ticks
114
+ ? { ...to, ticks: markerValues(to.range, Math.max(2, to.ticks.length) - 1) }
115
+ : to;
116
+ const blended = blendOf(from) !== undefined;
117
+ const moved = blended || rangeMoved || target.ticks !== from.ticks;
118
+ const auto = blended || from.range === undefined || from.ticks === undefined || target.range === undefined || target.ticks === undefined;
119
+ if (!moved || !auto)
120
+ return lerpAxisDomain(from, target, t);
121
+ if (t === 0)
122
+ return from;
123
+ if (t === 1)
124
+ return target;
125
+ const blend = { ...lerpAxisDomain(from, target, t), blend: { from, to: target, t } };
126
+ return blend;
127
+ }
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
+ */
132
+ export function settleAxisDomain(domain, drawn) {
133
+ const blend = blendOf(domain);
134
+ if (!blend)
135
+ return drawn(domain);
136
+ return lerpAxisDomain(settleAxisDomain(blend.from, drawn), settleAxisDomain(blend.to, drawn), blend.t);
137
+ }
77
138
  /**
78
139
  * The low-level colour tokens the default themes are built from — a dark plot
79
140
  * panel with warm-grey axis furniture.
@@ -109,7 +170,8 @@ export function clampUnit(value) {
109
170
  }
110
171
  // ---- Row readers ---------------------------------------------------------
111
172
  /**
112
- * Read a numeric field off a row, defaulting missing/non-numeric values to 0.
173
+ * Read a numeric field off a row, defaulting missing, non-numeric and non-finite
174
+ * values to 0.
113
175
  *
114
176
  * A column left as strings silently plots as 0, which is why the CSV parser's
115
177
  * numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
@@ -119,7 +181,9 @@ export function num(row, field) {
119
181
  if (field === undefined)
120
182
  return 0;
121
183
  const v = row[field];
122
- return typeof v === "number" ? v : 0;
184
+ // A `NaN` or infinite cell is no more a measurement than a missing one: read
185
+ // as 0, it cannot poison the scale and turn every point into `NaN`.
186
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
123
187
  }
124
188
  /**
125
189
  * Read a field off a row as its caption — the counterpart to {@link num} for
@@ -376,11 +440,42 @@ export function resolvePalettePaint(palette, override, index) {
376
440
  return palette[index % palette.length];
377
441
  }
378
442
  // ---- Scales and formatting -----------------------------------------------
379
- /** Format a marker value: integers plain, otherwise trimmed to one decimal. */
380
- export function formatMarker(value) {
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.
450
+ */
451
+ export function formatMarker(value, step) {
381
452
  if (Number.isInteger(value))
382
453
  return String(value);
383
- return value.toFixed(1).replace(/\.0$/, "");
454
+ const decimals = Math.max(1, step === undefined ? 1 : decimalsFor(step));
455
+ return value.toFixed(decimals).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
456
+ }
457
+ /** Decimal places needed to write `step` exactly, capped at six. */
458
+ function decimalsFor(step) {
459
+ if (!(step > 0) || !Number.isFinite(step))
460
+ return 1;
461
+ for (let d = 0; d <= 6; d++) {
462
+ const scaled = step * 10 ** d;
463
+ if (Math.abs(scaled - Math.round(scaled)) < 1e-6 * Math.max(1, scaled))
464
+ return d;
465
+ }
466
+ // An irrational-looking step (a third): as many places as separate the ticks.
467
+ return Math.min(6, Math.max(1, Math.ceil(-Math.log10(step)) + 1));
468
+ }
469
+ /** The gap between neighbouring tick values, or `undefined` for fewer than two distinct ones. */
470
+ export function markerStep(markers) {
471
+ const sorted = [...markers].filter(Number.isFinite).sort((a, b) => a - b);
472
+ let step;
473
+ for (let i = 1; i < sorted.length; i++) {
474
+ const gap = sorted[i] - sorted[i - 1];
475
+ if (gap > 1e-12 && (step === undefined || gap < step))
476
+ step = gap;
477
+ }
478
+ return step;
384
479
  }
385
480
  /** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
386
481
  export function formatPercent(fraction) {
@@ -395,7 +490,7 @@ export function markerValues([min, max], markerCount) {
395
490
  return Array.from({ length: n + 1 }, (_, i) => min + ((max - min) / n) * i);
396
491
  }
397
492
  // Lifted into the engine, because a graph and a diagram want them too — see
398
- // `@motionscript/core/component`. Re-exported so a chart, and anything that
493
+ // `@motionscript/sdk/component`. Re-exported so a chart, and anything that
399
494
  // copied one, still reaches them where it always did.
400
- export { niceStep, enterBudget } from "@motionscript/core/component";
495
+ export { niceStep, enterBudget } from "@motionscript/sdk/component";
401
496
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.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AAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,aAAa,CAAC,QAAgB;IAC5C,MAAM,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,4EAA4E;AAC5E,sDAAsD;AACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,8BAA8B,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 the studio's own inspector\n * mappings can build a partial theme without pulling the node classes in, the\n * same way `line-chart-props.ts` always has.\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/core\"\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's @property mapper: 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's @property tween: 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 * 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 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 return typeof v === \"number\" ? 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/** Format a marker value: integers plain, otherwise trimmed to one decimal. */\nexport function formatMarker(value: number): string {\n if (Number.isInteger(value)) return String(value)\n return value.toFixed(1).replace(/\\.0$/, \"\")\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/core/component`. Re-exported so a chart, and anything that\n// copied one, still reaches them where it always did.\nexport { niceStep, enterBudget } from \"@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ary 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"]}