@motionscript/charts 0.0.0-stage → 0.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/dist/bar-chart/bar-chart.d.ts +286 -0
- package/dist/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/bar-chart/bar-chart.js +610 -0
- package/dist/bar-chart/bar-chart.js.map +1 -0
- package/dist/bar-chart/category-axis.d.ts +77 -0
- package/dist/bar-chart/category-axis.d.ts.map +1 -0
- package/dist/bar-chart/category-axis.js +141 -0
- package/dist/bar-chart/category-axis.js.map +1 -0
- package/dist/bar-chart/chart-bars.d.ts +149 -0
- package/dist/bar-chart/chart-bars.d.ts.map +1 -0
- package/dist/bar-chart/chart-bars.js +236 -0
- package/dist/bar-chart/chart-bars.js.map +1 -0
- package/dist/bar-chart/index.d.ts +16 -0
- package/dist/bar-chart/index.d.ts.map +1 -0
- package/dist/bar-chart/index.js +12 -0
- package/dist/bar-chart/index.js.map +1 -0
- package/dist/bar-chart/shared.d.ts +146 -0
- package/dist/bar-chart/shared.d.ts.map +1 -0
- package/dist/bar-chart/shared.js +182 -0
- package/dist/bar-chart/shared.js.map +1 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
- package/dist/browser/index.js +2 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/kit.js +2 -0
- package/dist/browser/kit.js.map +7 -0
- package/dist/browser/manifest.json +12 -0
- package/dist/engine.d.ts +27 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +27 -0
- package/dist/engine.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/kit/chart-border.d.ts +28 -0
- package/dist/kit/chart-border.d.ts.map +1 -0
- package/dist/kit/chart-border.js +45 -0
- package/dist/kit/chart-border.js.map +1 -0
- package/dist/kit/chart-canvas.d.ts +56 -0
- package/dist/kit/chart-canvas.d.ts.map +1 -0
- package/dist/kit/chart-canvas.js +125 -0
- package/dist/kit/chart-canvas.js.map +1 -0
- package/dist/kit/chart-legend.d.ts +126 -0
- package/dist/kit/chart-legend.d.ts.map +1 -0
- package/dist/kit/chart-legend.js +212 -0
- package/dist/kit/chart-legend.js.map +1 -0
- package/dist/kit/shared.d.ts +251 -0
- package/dist/kit/shared.d.ts.map +1 -0
- package/dist/kit/shared.js +401 -0
- package/dist/kit/shared.js.map +1 -0
- package/dist/kit/vertical-axis.d.ts +99 -0
- package/dist/kit/vertical-axis.d.ts.map +1 -0
- package/dist/kit/vertical-axis.js +176 -0
- package/dist/kit/vertical-axis.js.map +1 -0
- package/dist/line-chart/chart-line.d.ts +91 -0
- package/dist/line-chart/chart-line.d.ts.map +1 -0
- package/dist/line-chart/chart-line.js +156 -0
- package/dist/line-chart/chart-line.js.map +1 -0
- package/dist/line-chart/chart-region.d.ts +47 -0
- package/dist/line-chart/chart-region.d.ts.map +1 -0
- package/dist/line-chart/chart-region.js +101 -0
- package/dist/line-chart/chart-region.js.map +1 -0
- package/dist/line-chart/horizontal-axis.d.ts +85 -0
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
- package/dist/line-chart/horizontal-axis.js +158 -0
- package/dist/line-chart/horizontal-axis.js.map +1 -0
- package/dist/line-chart/index.d.ts +22 -0
- package/dist/line-chart/index.d.ts.map +1 -0
- package/dist/line-chart/index.js +19 -0
- package/dist/line-chart/index.js.map +1 -0
- package/dist/line-chart/line-chart.d.ts +347 -0
- package/dist/line-chart/line-chart.d.ts.map +1 -0
- package/dist/line-chart/line-chart.js +701 -0
- package/dist/line-chart/line-chart.js.map +1 -0
- package/dist/line-chart/shared.d.ts +171 -0
- package/dist/line-chart/shared.d.ts.map +1 -0
- package/dist/line-chart/shared.js +270 -0
- package/dist/line-chart/shared.js.map +1 -0
- package/dist/line-chart/x-scale.d.ts +84 -0
- package/dist/line-chart/x-scale.d.ts.map +1 -0
- package/dist/line-chart/x-scale.js +302 -0
- package/dist/line-chart/x-scale.js.map +1 -0
- package/dist/nodes.d.ts +20 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/nodes.js +20 -0
- package/dist/nodes.js.map +1 -0
- package/dist/pie-chart/index.d.ts +18 -0
- package/dist/pie-chart/index.d.ts.map +1 -0
- package/dist/pie-chart/index.js +14 -0
- package/dist/pie-chart/index.js.map +1 -0
- package/dist/pie-chart/pie-chart.d.ts +170 -0
- package/dist/pie-chart/pie-chart.d.ts.map +1 -0
- package/dist/pie-chart/pie-chart.js +291 -0
- package/dist/pie-chart/pie-chart.js.map +1 -0
- package/dist/pie-chart/pie-legend.d.ts +60 -0
- package/dist/pie-chart/pie-legend.d.ts.map +1 -0
- package/dist/pie-chart/pie-legend.js +131 -0
- package/dist/pie-chart/pie-legend.js.map +1 -0
- package/dist/pie-chart/pie-ring.d.ts +266 -0
- package/dist/pie-chart/pie-ring.d.ts.map +1 -0
- package/dist/pie-chart/pie-ring.js +708 -0
- package/dist/pie-chart/pie-ring.js.map +1 -0
- package/dist/pie-chart/shared.d.ts +210 -0
- package/dist/pie-chart/shared.d.ts.map +1 -0
- package/dist/pie-chart/shared.js +240 -0
- package/dist/pie-chart/shared.js.map +1 -0
- package/package.json +69 -3
- package/registry.json +23 -0
- package/src/bar-chart/bar-chart.ts +804 -0
- package/src/bar-chart/category-axis.ts +177 -0
- package/src/bar-chart/chart-bars.ts +310 -0
- package/src/bar-chart/index.ts +31 -0
- package/src/bar-chart/shared.ts +354 -0
- package/src/engine.ts +26 -0
- package/src/index.ts +5 -0
- package/src/kit/chart-border.ts +61 -0
- package/src/kit/chart-canvas.ts +157 -0
- package/src/kit/chart-legend.ts +250 -0
- package/src/kit/shared.ts +675 -0
- package/src/kit/vertical-axis.ts +224 -0
- package/src/line-chart/chart-line.ts +208 -0
- package/src/line-chart/chart-region.ts +135 -0
- package/src/line-chart/horizontal-axis.ts +202 -0
- package/src/line-chart/index.ts +39 -0
- package/src/line-chart/line-chart.ts +894 -0
- package/src/line-chart/shared.ts +459 -0
- package/src/line-chart/x-scale.ts +367 -0
- package/src/nodes.ts +20 -0
- package/src/pie-chart/index.ts +37 -0
- package/src/pie-chart/pie-chart.ts +374 -0
- package/src/pie-chart/pie-legend.ts +159 -0
- package/src/pie-chart/pie-ring.ts +903 -0
- package/src/pie-chart/shared.ts +490 -0
- package/README.md +0 -4
|
@@ -0,0 +1,401 @@
|
|
|
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.
|
|
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 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.
|
|
18
|
+
*
|
|
19
|
+
* **Two conventions run through every resolver and lerp below**, inherited from
|
|
20
|
+
* the shape system's `resolveStroke`/`resolveShadow`:
|
|
21
|
+
*
|
|
22
|
+
* - A **mapper** merges the author's loose, partial input onto a `previous`
|
|
23
|
+
* resolved value and resolves every leaf, so the tween always has resolved
|
|
24
|
+
* data to interpolate. It is idempotent.
|
|
25
|
+
* - A **tween** interpolates two resolved values leaf by leaf. Categorical
|
|
26
|
+
* fields (`fontFamily`, `textAlign`) and fields that are `undefined` on either
|
|
27
|
+
* side **step at the midpoint**, because there is no meaningful in-between and
|
|
28
|
+
* defaulting the missing side to 0 would animate a font weight down to nothing
|
|
29
|
+
* on the way to "unset".
|
|
30
|
+
*/
|
|
31
|
+
import { fillOps, lerpNumber, shadowOps, strokeOps, insetsOps, textOps, } from "@motionscript/core";
|
|
32
|
+
/**
|
|
33
|
+
* An axis domain's @property mapper: merges the author's partial input onto
|
|
34
|
+
* `previous`, so a later partial `.set({ yAxis: {...} })` patches
|
|
35
|
+
* `label`/`range`/`ticks` independently. `range`/`ticks` staying `undefined`
|
|
36
|
+
* after the merge is the auto-derive signal the scale getters read.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveAxisDomain(domain, previous) {
|
|
39
|
+
return {
|
|
40
|
+
label: domain?.label ?? previous?.label ?? "",
|
|
41
|
+
range: domain?.range ?? previous?.range,
|
|
42
|
+
ticks: domain?.ticks ?? previous?.ticks,
|
|
43
|
+
format: domain?.format ?? previous?.format,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* An axis domain's @property tween: interpolates `range`/`ticks` numerically
|
|
48
|
+
* (pairwise by index for `ticks`), so a `to` command that restates a range
|
|
49
|
+
* rescales the plot smoothly. `label`, and either field when one side is in
|
|
50
|
+
* auto-derive mode, step at the midpoint.
|
|
51
|
+
*/
|
|
52
|
+
export function lerpAxisDomain(from, to, t) {
|
|
53
|
+
return {
|
|
54
|
+
label: t < 0.5 ? from.label : to.label,
|
|
55
|
+
range: lerpOptionalRange(from.range, to.range, t),
|
|
56
|
+
ticks: lerpOptionalTicks(from.ticks, to.ticks, t),
|
|
57
|
+
// Steps at the midpoint with the caption, for the same reason: there is no
|
|
58
|
+
// halfway between `$#,##0` and `0.0%`.
|
|
59
|
+
format: t < 0.5 ? from.format : to.format,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function lerpOptionalRange(from, to, t) {
|
|
63
|
+
if (!from || !to)
|
|
64
|
+
return t < 0.5 ? from : to;
|
|
65
|
+
return [lerpNumber(from[0], to[0], t), lerpNumber(from[1], to[1], t)];
|
|
66
|
+
}
|
|
67
|
+
function lerpOptionalTicks(from, to, t) {
|
|
68
|
+
if (!from || !to)
|
|
69
|
+
return t < 0.5 ? from : to;
|
|
70
|
+
const n = Math.max(from.length, to.length);
|
|
71
|
+
const out = [];
|
|
72
|
+
for (let i = 0; i < n; i++) {
|
|
73
|
+
out.push(lerpNumber(from[i] ?? to[i], to[i] ?? from[i], t));
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The low-level colour tokens the default themes are built from — a dark plot
|
|
79
|
+
* panel with warm-grey axis furniture.
|
|
80
|
+
*/
|
|
81
|
+
export const CHART_PALETTE = {
|
|
82
|
+
/** Fill of the plot panel behind the marks. */
|
|
83
|
+
plotFill: "#15130e",
|
|
84
|
+
/** Colour of the plot's thick border. */
|
|
85
|
+
borderColor: "#4a4036",
|
|
86
|
+
/** Colour of the faint grid lines spanning the plot. */
|
|
87
|
+
gridColor: "#2c2820",
|
|
88
|
+
/** Colour of the numeric axis markers, axis captions, and legend labels. */
|
|
89
|
+
markerColor: "#8a7f70",
|
|
90
|
+
/** Colour of a spotlit region's dashed rules and its wash. */
|
|
91
|
+
regionColor: "#d99a3a",
|
|
92
|
+
};
|
|
93
|
+
/** The out-of-the-box series palette, cycled by series index. */
|
|
94
|
+
export const DEFAULT_SERIES_COLORS = [
|
|
95
|
+
"#d9603b",
|
|
96
|
+
"#8194ad",
|
|
97
|
+
"#e0a93b",
|
|
98
|
+
"#5e9d6b",
|
|
99
|
+
"#9ec85a",
|
|
100
|
+
];
|
|
101
|
+
/**
|
|
102
|
+
* Opacity an *un*-spotlighted series fades to — its mark and its legend entry
|
|
103
|
+
* alike, so the two dim together.
|
|
104
|
+
*/
|
|
105
|
+
export const SPOTLIGHT_DIM = 0.2;
|
|
106
|
+
/** Clamp a number into `[0, 1]` — the range every reveal signal here runs in. */
|
|
107
|
+
export function clampUnit(value) {
|
|
108
|
+
return value < 0 ? 0 : value > 1 ? 1 : value;
|
|
109
|
+
}
|
|
110
|
+
// ---- Row readers ---------------------------------------------------------
|
|
111
|
+
/**
|
|
112
|
+
* Read a numeric field off a row, defaulting missing/non-numeric values to 0.
|
|
113
|
+
*
|
|
114
|
+
* A column left as strings silently plots as 0, which is why the CSV parser's
|
|
115
|
+
* numeric auto-coercion matters — a quoted or unit-suffixed column won't plot
|
|
116
|
+
* until it's coerced.
|
|
117
|
+
*/
|
|
118
|
+
export function num(row, field) {
|
|
119
|
+
if (field === undefined)
|
|
120
|
+
return 0;
|
|
121
|
+
const v = row[field];
|
|
122
|
+
return typeof v === "number" ? v : 0;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Read a field off a row as its caption — the counterpart to {@link num} for
|
|
126
|
+
* the columns a chart *names* things by rather than measures them by (a bar's
|
|
127
|
+
* category, a wedge's slice). A missing cell reads as empty rather than as the
|
|
128
|
+
* string `"undefined"`.
|
|
129
|
+
*/
|
|
130
|
+
export function text(row, field) {
|
|
131
|
+
if (field === undefined || field === "")
|
|
132
|
+
return "";
|
|
133
|
+
const v = row[field];
|
|
134
|
+
return v === undefined || v === null ? "" : String(v);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Every column that holds numbers across `data`, in header order, skipping the
|
|
138
|
+
* names in `exclude` (typically the category column).
|
|
139
|
+
*
|
|
140
|
+
* A column counts as numeric only if every non-empty cell in it is a number, so
|
|
141
|
+
* a stray text cell leaves the column out rather than plotting zeros. This is
|
|
142
|
+
* what lets a chart plot "every other column" without the author naming twenty
|
|
143
|
+
* fields.
|
|
144
|
+
*/
|
|
145
|
+
export function numericFields(data, exclude = []) {
|
|
146
|
+
if (data.length === 0)
|
|
147
|
+
return [];
|
|
148
|
+
const skip = new Set(exclude);
|
|
149
|
+
const seen = new Set();
|
|
150
|
+
const order = [];
|
|
151
|
+
for (const row of data)
|
|
152
|
+
for (const key of Object.keys(row))
|
|
153
|
+
if (!skip.has(key) && !seen.has(key)) {
|
|
154
|
+
seen.add(key);
|
|
155
|
+
order.push(key);
|
|
156
|
+
}
|
|
157
|
+
return order.filter((key) => {
|
|
158
|
+
let sawValue = false;
|
|
159
|
+
for (const row of data) {
|
|
160
|
+
const v = row[key];
|
|
161
|
+
if (v === undefined || v === "")
|
|
162
|
+
continue;
|
|
163
|
+
if (typeof v !== "number")
|
|
164
|
+
return false;
|
|
165
|
+
sawValue = true;
|
|
166
|
+
}
|
|
167
|
+
return sawValue;
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
const AXIS_LABEL_STYLE = {
|
|
171
|
+
fontSize: 24,
|
|
172
|
+
fontWeight: 700,
|
|
173
|
+
textAlign: "center",
|
|
174
|
+
fill: CHART_PALETTE.markerColor,
|
|
175
|
+
};
|
|
176
|
+
const AXIS_TITLE_STYLE = {
|
|
177
|
+
fontSize: 30,
|
|
178
|
+
fontWeight: 600,
|
|
179
|
+
textAlign: "center",
|
|
180
|
+
fill: CHART_PALETTE.markerColor,
|
|
181
|
+
};
|
|
182
|
+
const AXIS_LINE_STYLE = { weight: 2, fill: CHART_PALETTE.gridColor };
|
|
183
|
+
/** The default styling of a horizontal (marker row beneath the plot) axis. */
|
|
184
|
+
export const DEFAULT_X_AXIS = {
|
|
185
|
+
labelStyle: AXIS_LABEL_STYLE,
|
|
186
|
+
titleStyle: AXIS_TITLE_STYLE,
|
|
187
|
+
lineStyle: AXIS_LINE_STYLE,
|
|
188
|
+
tickPadding: 20,
|
|
189
|
+
titlePadding: 4,
|
|
190
|
+
};
|
|
191
|
+
/** The default styling of a vertical (marker column beside the plot) axis. */
|
|
192
|
+
export const DEFAULT_Y_AXIS = {
|
|
193
|
+
labelStyle: { ...AXIS_LABEL_STYLE, fontWeight: 500, textAlign: "right" },
|
|
194
|
+
titleStyle: AXIS_TITLE_STYLE,
|
|
195
|
+
lineStyle: AXIS_LINE_STYLE,
|
|
196
|
+
tickPadding: 40,
|
|
197
|
+
titlePadding: 24,
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* The default plot panel: **unpainted**, framed. A chart reads against the
|
|
201
|
+
* stage rather than punching a panel into it, which is the look the family was
|
|
202
|
+
* designed at.
|
|
203
|
+
*/
|
|
204
|
+
export const DEFAULT_PLOT_AREA = {
|
|
205
|
+
fill: [],
|
|
206
|
+
stroke: { weight: 6, fill: CHART_PALETTE.borderColor },
|
|
207
|
+
shadow: [],
|
|
208
|
+
};
|
|
209
|
+
/** The default legend styling, shared by every chart that draws one. */
|
|
210
|
+
export const DEFAULT_LEGEND = {
|
|
211
|
+
padding: 0,
|
|
212
|
+
textStyle: {
|
|
213
|
+
fontSize: 30,
|
|
214
|
+
fontWeight: 600,
|
|
215
|
+
textAlign: "left",
|
|
216
|
+
fill: CHART_PALETTE.markerColor,
|
|
217
|
+
},
|
|
218
|
+
itemGap: 44,
|
|
219
|
+
markerStyle: {
|
|
220
|
+
width: 60,
|
|
221
|
+
height: 24,
|
|
222
|
+
borderRadius: 6,
|
|
223
|
+
stroke: [],
|
|
224
|
+
shadow: [],
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
/** The default per-series stroke palette — {@link DEFAULT_SERIES_COLORS}, drawn 4px. */
|
|
228
|
+
export const DEFAULT_SERIES_STROKES = DEFAULT_SERIES_COLORS.map((fill) => ({ weight: 4, fill }));
|
|
229
|
+
/** The default per-series fill palette — the same colours, as solid paint. */
|
|
230
|
+
export const DEFAULT_SERIES_FILLS = DEFAULT_SERIES_COLORS.map((fill) => fill);
|
|
231
|
+
// ---- Theme branch resolvers ----------------------------------------------
|
|
232
|
+
// Each chart type assembles its own theme out of these, so "the axis furniture"
|
|
233
|
+
// means one thing across the family and each chart still declares only the
|
|
234
|
+
// branches it actually draws.
|
|
235
|
+
export function resolveAxisConfig(axis, previous) {
|
|
236
|
+
return {
|
|
237
|
+
labelStyle: textOps.resolveStyle(axis?.labelStyle, previous.labelStyle),
|
|
238
|
+
titleStyle: textOps.resolveStyle(axis?.titleStyle, previous.titleStyle),
|
|
239
|
+
lineStyle: strokeOps.resolve(axis?.lineStyle ?? previous.lineStyle),
|
|
240
|
+
tickPadding: insetsOps.resolve(axis?.tickPadding ?? previous.tickPadding, previous.tickPadding),
|
|
241
|
+
titlePadding: insetsOps.resolve(axis?.titlePadding ?? previous.titlePadding, previous.titlePadding),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
export function lerpAxisConfig(from, to, t) {
|
|
245
|
+
return {
|
|
246
|
+
labelStyle: textOps.lerpStyle(from.labelStyle, to.labelStyle, t),
|
|
247
|
+
titleStyle: textOps.lerpStyle(from.titleStyle, to.titleStyle, t),
|
|
248
|
+
lineStyle: strokeOps.lerp(from.lineStyle, to.lineStyle, t),
|
|
249
|
+
tickPadding: insetsOps.lerp(from.tickPadding, to.tickPadding, t),
|
|
250
|
+
titlePadding: insetsOps.lerp(from.titlePadding, to.titlePadding, t),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export function resolvePlotArea(plotArea, previous) {
|
|
254
|
+
return {
|
|
255
|
+
fill: fillOps.resolve(plotArea?.fill ?? previous.fill),
|
|
256
|
+
stroke: strokeOps.resolve(plotArea?.stroke ?? previous.stroke),
|
|
257
|
+
shadow: shadowOps.resolve(plotArea?.shadow ?? previous.shadow),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
export function lerpPlotArea(from, to, t) {
|
|
261
|
+
return {
|
|
262
|
+
fill: fillOps.lerp(from.fill, to.fill, t),
|
|
263
|
+
stroke: strokeOps.lerp(from.stroke, to.stroke, t),
|
|
264
|
+
shadow: shadowOps.lerp(from.shadow, to.shadow, t),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function resolveLegendMarkerConfig(marker, previous) {
|
|
268
|
+
return {
|
|
269
|
+
width: marker?.width ?? previous.width,
|
|
270
|
+
height: marker?.height ?? previous.height,
|
|
271
|
+
borderRadius: marker?.borderRadius ?? previous.borderRadius,
|
|
272
|
+
stroke: strokeOps.resolve(marker?.stroke ?? previous.stroke),
|
|
273
|
+
shadow: shadowOps.resolve(marker?.shadow ?? previous.shadow),
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function lerpLegendMarkerConfig(from, to, t) {
|
|
277
|
+
return {
|
|
278
|
+
width: lerpNumber(from.width, to.width, t),
|
|
279
|
+
height: lerpNumber(from.height, to.height, t),
|
|
280
|
+
borderRadius: lerpNumber(from.borderRadius, to.borderRadius, t),
|
|
281
|
+
stroke: strokeOps.lerp(from.stroke, to.stroke, t),
|
|
282
|
+
shadow: shadowOps.lerp(from.shadow, to.shadow, t),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
export function resolveLegendConfig(legend, previous) {
|
|
286
|
+
return {
|
|
287
|
+
padding: insetsOps.resolve(legend?.padding ?? previous.padding, previous.padding),
|
|
288
|
+
textStyle: textOps.resolveStyle(legend?.textStyle, previous.textStyle),
|
|
289
|
+
itemGap: legend?.itemGap ?? previous.itemGap,
|
|
290
|
+
markerStyle: resolveLegendMarkerConfig(legend?.markerStyle, previous.markerStyle),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
export function lerpLegendConfig(from, to, t) {
|
|
294
|
+
return {
|
|
295
|
+
padding: insetsOps.lerp(from.padding, to.padding, t),
|
|
296
|
+
textStyle: textOps.lerpStyle(from.textStyle, to.textStyle, t),
|
|
297
|
+
itemGap: lerpNumber(from.itemGap, to.itemGap, t),
|
|
298
|
+
markerStyle: lerpLegendMarkerConfig(from.markerStyle, to.markerStyle, t),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
/** A whole-palette override replaces the previous palette outright. */
|
|
302
|
+
export function resolveSeriesStrokes(styles, previous) {
|
|
303
|
+
return (styles ?? previous).map((s) => strokeOps.resolve(s));
|
|
304
|
+
}
|
|
305
|
+
/** Pairwise by index; a palette that grows/shrinks holds the longer side's tail. */
|
|
306
|
+
export function lerpSeriesStrokes(from, to, t) {
|
|
307
|
+
const n = Math.max(from.length, to.length);
|
|
308
|
+
const out = [];
|
|
309
|
+
for (let i = 0; i < n; i++) {
|
|
310
|
+
const a = (from[i] ?? to[i]);
|
|
311
|
+
const b = (to[i] ?? from[i]);
|
|
312
|
+
out.push(strokeOps.lerp(a, b, t));
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
/** The fill-palette twin of {@link resolveSeriesStrokes}, for filled marks. */
|
|
317
|
+
export function resolveSeriesFills(fills, previous) {
|
|
318
|
+
return (fills ?? previous).map((f) => fillOps.resolve(f));
|
|
319
|
+
}
|
|
320
|
+
/** The fill-palette twin of {@link lerpSeriesStrokes}. */
|
|
321
|
+
export function lerpSeriesFills(from, to, t) {
|
|
322
|
+
const n = Math.max(from.length, to.length);
|
|
323
|
+
const out = [];
|
|
324
|
+
for (let i = 0; i < n; i++) {
|
|
325
|
+
const a = (from[i] ?? to[i]);
|
|
326
|
+
const b = (to[i] ?? from[i]);
|
|
327
|
+
out.push(fillOps.lerp(a, b, t));
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
// ---- Per-series paint ----------------------------------------------------
|
|
332
|
+
/**
|
|
333
|
+
* The effective stroke for series `index`: the palette's entry at
|
|
334
|
+
* `index % palette.length`, with the series' own `fill`, if set, overriding just
|
|
335
|
+
* the last (topmost) layer's colour.
|
|
336
|
+
*/
|
|
337
|
+
export function resolveSeriesStroke(palette, series, index) {
|
|
338
|
+
const entry = palette.length > 0
|
|
339
|
+
? palette[index % palette.length]
|
|
340
|
+
: { weight: 4, fill: "white" };
|
|
341
|
+
if (series.fill == null)
|
|
342
|
+
return entry;
|
|
343
|
+
const layers = strokeOps.resolve(entry);
|
|
344
|
+
if (layers.length === 0)
|
|
345
|
+
return { weight: 4, fill: series.fill };
|
|
346
|
+
const next = [...layers];
|
|
347
|
+
next[next.length - 1] = {
|
|
348
|
+
...next[next.length - 1],
|
|
349
|
+
fill: fillOps.resolve(series.fill),
|
|
350
|
+
};
|
|
351
|
+
return next;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The effective *colour* for series `index` — the same colour
|
|
355
|
+
* {@link resolveSeriesStroke} draws its line in — for contexts (a legend
|
|
356
|
+
* swatch) that only need the fill.
|
|
357
|
+
*/
|
|
358
|
+
export function resolveSeriesFill(palette, series, index) {
|
|
359
|
+
const layers = strokeOps.resolve(resolveSeriesStroke(palette, series, index));
|
|
360
|
+
return layers[layers.length - 1]?.fill ?? "white";
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* The effective paint for mark `index` of a **filled** chart (a bar, a wedge):
|
|
364
|
+
* the series' own `fill` when it carries one, else the palette's entry for its
|
|
365
|
+
* index, cycled.
|
|
366
|
+
*
|
|
367
|
+
* The stroke twin above has to reach inside a stroke to swap one layer's colour;
|
|
368
|
+
* a filled mark has no such geometry wrapped around its paint, so an override is
|
|
369
|
+
* simply the whole answer.
|
|
370
|
+
*/
|
|
371
|
+
export function resolvePalettePaint(palette, override, index) {
|
|
372
|
+
if (override != null)
|
|
373
|
+
return override;
|
|
374
|
+
if (palette.length === 0)
|
|
375
|
+
return "white";
|
|
376
|
+
return palette[index % palette.length];
|
|
377
|
+
}
|
|
378
|
+
// ---- Scales and formatting -----------------------------------------------
|
|
379
|
+
/** Format a marker value: integers plain, otherwise trimmed to one decimal. */
|
|
380
|
+
export function formatMarker(value) {
|
|
381
|
+
if (Number.isInteger(value))
|
|
382
|
+
return String(value);
|
|
383
|
+
return value.toFixed(1).replace(/\.0$/, "");
|
|
384
|
+
}
|
|
385
|
+
/** Format a fraction in `[0, 1]` as a percentage: integers plain, else one decimal. */
|
|
386
|
+
export function formatPercent(fraction) {
|
|
387
|
+
const pct = fraction * 100;
|
|
388
|
+
if (Number.isInteger(pct))
|
|
389
|
+
return `${pct}%`;
|
|
390
|
+
return `${pct.toFixed(1).replace(/\.0$/, "")}%`;
|
|
391
|
+
}
|
|
392
|
+
/** `markerCount` evenly-spaced tick values across `[min, max]`, ends inclusive. */
|
|
393
|
+
export function markerValues([min, max], markerCount) {
|
|
394
|
+
const n = Math.max(2, Math.round(markerCount));
|
|
395
|
+
return Array.from({ length: n + 1 }, (_, i) => min + ((max - min) / n) * i);
|
|
396
|
+
}
|
|
397
|
+
// 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
|
|
399
|
+
// copied one, still reaches them where it always did.
|
|
400
|
+
export { niceStep, enterBudget } from "@motionscript/core/component";
|
|
401
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/kit/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,GAWR,MAAM,oBAAoB,CAAA;AAuD3B;;;;;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,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;;;;;GAKG;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,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C,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 \"@motionscript/core/component\"\n"]}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Node2D, type CommandArgs, type NodeConfig, type Node2DProps } from "@motionscript/core";
|
|
2
|
+
import { type AxisConfig, type Range } from "./shared.js";
|
|
3
|
+
import { type Seekable } from "@motionscript/core/component";
|
|
4
|
+
export interface VerticalAxisProps extends Node2DProps {
|
|
5
|
+
/** `[min, max]` of the vertical scale the markers are positioned within. */
|
|
6
|
+
range: Range;
|
|
7
|
+
/**
|
|
8
|
+
* Tick values (in data units) to draw up the axis, each placed by its fraction
|
|
9
|
+
* across {@link VerticalAxisProps.range}. Need not be evenly spaced or include
|
|
10
|
+
* the ends.
|
|
11
|
+
*/
|
|
12
|
+
markers: number[];
|
|
13
|
+
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
14
|
+
axis: AxisConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Rotated caption drawn in the gutter to the left of the marker column. Empty
|
|
17
|
+
* string (the default) hides it — no caption node is built and no label gutter
|
|
18
|
+
* is reserved.
|
|
19
|
+
*/
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
/** How a tick value is captioned — see {@link VerticalAxis.labelFor}. */
|
|
23
|
+
export type MarkerLabel = (value: number) => string;
|
|
24
|
+
/**
|
|
25
|
+
* The numeric vertical axis shared by the cartesian charts: a **column of
|
|
26
|
+
* {@link Text} nodes**, one per marker value, running top-to-bottom (highest
|
|
27
|
+
* value at the top). Pure layout — no `Graphics` — so the markers are real text
|
|
28
|
+
* nodes the scene can measure, restyle, or animate individually.
|
|
29
|
+
*
|
|
30
|
+
* Each marker is positioned so its centre lands exactly on its value's fraction
|
|
31
|
+
* across `range` within the axis's filled height, so unevenly-spaced markers
|
|
32
|
+
* land where their values fall. Both the caption and the position are *bound*,
|
|
33
|
+
* not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
|
|
34
|
+
* tweens `range`/`markers` live. Only the marker **count** is fixed at
|
|
35
|
+
* construction.
|
|
36
|
+
*
|
|
37
|
+
* {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a
|
|
38
|
+
* little to the right and transparent, then fades and slides left into place.
|
|
39
|
+
* The resting state is the landed one, so a chart that is never told to enter
|
|
40
|
+
* still reads as a finished chart.
|
|
41
|
+
*/
|
|
42
|
+
export declare class VerticalAxis extends Node2D<VerticalAxisProps> {
|
|
43
|
+
range: Range;
|
|
44
|
+
markers: number[];
|
|
45
|
+
axis: AxisConfig;
|
|
46
|
+
label: string;
|
|
47
|
+
/**
|
|
48
|
+
* How a tick value is captioned. Defaults to the bare numeric reading; a
|
|
49
|
+
* chart with a number format on this axis replaces it (see `number-format`).
|
|
50
|
+
*
|
|
51
|
+
* A plain field rather than a `@property`, for the reason the horizontal
|
|
52
|
+
* axis's twin spells out: it is a policy, not a value, and there is nothing
|
|
53
|
+
* to tween between two formatters.
|
|
54
|
+
*/
|
|
55
|
+
labelFor: MarkerLabel;
|
|
56
|
+
/** One text node per marker, ordered top → bottom, for the staggered enter. */
|
|
57
|
+
private markerNodes;
|
|
58
|
+
/** The caption node, or null when `label` is empty. Entered after the markers. */
|
|
59
|
+
private labelNode;
|
|
60
|
+
/** The live tick values, top → bottom (highest first) — re-read every frame. */
|
|
61
|
+
private get sortedMarkers();
|
|
62
|
+
/**
|
|
63
|
+
* Tick `i`'s value, or `undefined` once the live `markers` list is shorter
|
|
64
|
+
* than the column of text nodes built for it — a slot with no value renders as
|
|
65
|
+
* empty text rather than repeating its neighbour.
|
|
66
|
+
*/
|
|
67
|
+
private valueAt;
|
|
68
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
|
|
69
|
+
private fracAt;
|
|
70
|
+
constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>);
|
|
71
|
+
/**
|
|
72
|
+
* Primes every marker (and the caption) at its pre-entrance state: shifted
|
|
73
|
+
* right and transparent. Idempotent, and separate from {@link enter} so the
|
|
74
|
+
* chart can arm its whole composition before the first frame is drawn.
|
|
75
|
+
*/
|
|
76
|
+
arm(slide?: number): void;
|
|
77
|
+
/**
|
|
78
|
+
* Stagger the markers in bottom to top, then slide the caption in from the
|
|
79
|
+
* right after them.
|
|
80
|
+
*
|
|
81
|
+
* A {@link Seekable} rather than a generator — see the note on the horizontal
|
|
82
|
+
* axis's `enter`. The offsets were always static; expressing them as `wait`
|
|
83
|
+
* inside a generator is what made them reachable only by running it.
|
|
84
|
+
*
|
|
85
|
+
* `args.duration` is the **whole** entrance, not one marker's slide: the
|
|
86
|
+
* stagger and the caption are carved out of it rather than added on top. See
|
|
87
|
+
* {@link enterBudget} for why that distinction matters here.
|
|
88
|
+
*
|
|
89
|
+
* `args.data.stagger` is seconds between successive markers (derived when
|
|
90
|
+
* omitted); `args.data.slide` is the starting rightward offset in px.
|
|
91
|
+
*/
|
|
92
|
+
enter(args: CommandArgs<{
|
|
93
|
+
stagger?: number;
|
|
94
|
+
slide?: number;
|
|
95
|
+
}> & {
|
|
96
|
+
duration: number;
|
|
97
|
+
}): Seekable;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=vertical-axis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/k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