@motionscript/charts 0.1.1-alpha.0 → 0.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +98 -28
- package/dist/bar-chart/bar-chart.d.ts +233 -39
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +215 -171
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +12 -7
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +56 -42
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +52 -52
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +80 -89
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +4 -4
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +2 -2
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +36 -65
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +68 -117
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-R3Q5EE6E.js +2 -0
- package/dist/browser/chunks/chunk-R3Q5EE6E.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +5 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +5 -2
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kit/cartesian.d.ts +49 -15
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +79 -29
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -24
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +52 -46
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +8 -4
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +30 -20
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/{line-chart → kit}/horizontal-axis.d.ts +31 -6
- package/dist/kit/horizontal-axis.d.ts.map +1 -0
- package/dist/{line-chart → kit}/horizontal-axis.js +23 -24
- package/dist/kit/horizontal-axis.js.map +1 -0
- package/dist/kit/motion.d.ts +5 -0
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +8 -0
- package/dist/kit/motion.js.map +1 -1
- package/dist/{pie-chart → kit}/pie-legend.d.ts +3 -3
- package/dist/kit/pie-legend.d.ts.map +1 -0
- package/dist/{pie-chart → kit}/pie-legend.js +11 -10
- package/dist/kit/pie-legend.js.map +1 -0
- package/dist/kit/polar.d.ts +31 -0
- package/dist/kit/polar.d.ts.map +1 -0
- package/dist/kit/polar.js +33 -0
- package/dist/kit/polar.js.map +1 -0
- package/dist/kit/shared.d.ts +11 -50
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +58 -141
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/style.d.ts +254 -0
- package/dist/kit/style.d.ts.map +1 -0
- package/dist/kit/style.js +197 -0
- package/dist/kit/style.js.map +1 -0
- package/dist/kit/vertical-axis.d.ts +22 -2
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +56 -43
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +95 -3
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +165 -53
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +1 -1
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +7 -8
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/index.d.ts +5 -6
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +3 -4
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +257 -18
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +282 -134
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +51 -34
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +175 -83
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +2 -0
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +15 -0
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +3 -1
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +9 -1
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -3
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -2
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +114 -18
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +37 -24
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +16 -5
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +89 -55
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +53 -61
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +41 -121
- package/dist/pie-chart/shared.js.map +1 -1
- package/dist/radar-chart/index.d.ts +5 -0
- package/dist/radar-chart/index.d.ts.map +1 -0
- package/dist/radar-chart/index.js +5 -0
- package/dist/radar-chart/index.js.map +1 -0
- package/dist/radar-chart/radar-chart.d.ts +218 -0
- package/dist/radar-chart/radar-chart.d.ts.map +1 -0
- package/dist/radar-chart/radar-chart.js +224 -0
- package/dist/radar-chart/radar-chart.js.map +1 -0
- package/dist/radar-chart/radar-grid.d.ts +43 -0
- package/dist/radar-chart/radar-grid.d.ts.map +1 -0
- package/dist/radar-chart/radar-grid.js +61 -0
- package/dist/radar-chart/radar-grid.js.map +1 -0
- package/dist/radar-chart/radar-series.d.ts +59 -0
- package/dist/radar-chart/radar-series.d.ts.map +1 -0
- package/dist/radar-chart/radar-series.js +71 -0
- package/dist/radar-chart/radar-series.js.map +1 -0
- package/dist/radar-chart/shared.d.ts +73 -0
- package/dist/radar-chart/shared.d.ts.map +1 -0
- package/dist/radar-chart/shared.js +123 -0
- package/dist/radar-chart/shared.js.map +1 -0
- package/dist/radial-chart/index.d.ts +6 -0
- package/dist/radial-chart/index.d.ts.map +1 -0
- package/dist/radial-chart/index.js +4 -0
- package/dist/radial-chart/index.js.map +1 -0
- package/dist/radial-chart/radial-chart.d.ts +216 -0
- package/dist/radial-chart/radial-chart.d.ts.map +1 -0
- package/dist/radial-chart/radial-chart.js +174 -0
- package/dist/radial-chart/radial-chart.js.map +1 -0
- package/dist/radial-chart/radial-rings.d.ts +121 -0
- package/dist/radial-chart/radial-rings.d.ts.map +1 -0
- package/dist/radial-chart/radial-rings.js +273 -0
- package/dist/radial-chart/radial-rings.js.map +1 -0
- package/dist/radial-chart/shared.d.ts +73 -0
- package/dist/radial-chart/shared.d.ts.map +1 -0
- package/dist/radial-chart/shared.js +79 -0
- package/dist/radial-chart/shared.js.map +1 -0
- package/package.json +4 -4
- package/registry.json +21 -6
- package/src/bar-chart/bar-chart.ts +252 -179
- package/src/bar-chart/category-axis.ts +46 -40
- package/src/bar-chart/chart-bars.ts +97 -117
- package/src/bar-chart/index.ts +7 -10
- package/src/bar-chart/shared.ts +78 -238
- package/src/engine.ts +5 -2
- package/src/index.ts +2 -0
- package/src/kit/cartesian.ts +118 -40
- package/src/kit/chart-canvas.ts +49 -54
- package/src/kit/chart-legend.ts +28 -20
- package/src/kit/horizontal-axis.ts +114 -0
- package/src/kit/motion.ts +7 -0
- package/src/{pie-chart → kit}/pie-legend.ts +12 -11
- package/src/kit/polar.ts +54 -0
- package/src/kit/shared.ts +55 -277
- package/src/kit/style.ts +257 -0
- package/src/kit/vertical-axis.ts +67 -48
- package/src/line-chart/chart-line.ts +176 -54
- package/src/line-chart/chart-region.ts +6 -10
- package/src/line-chart/index.ts +14 -10
- package/src/line-chart/line-chart.ts +347 -151
- package/src/line-chart/shared.ts +193 -174
- package/src/line-chart/x-scale.ts +13 -0
- package/src/nodes.ts +9 -1
- package/src/pie-chart/index.ts +2 -23
- package/src/pie-chart/pie-chart.ts +52 -35
- package/src/pie-chart/pie-ring.ts +92 -71
- package/src/pie-chart/shared.ts +68 -266
- package/src/radar-chart/index.ts +4 -0
- package/src/radar-chart/radar-chart.ts +287 -0
- package/src/radar-chart/radar-grid.ts +78 -0
- package/src/radar-chart/radar-series.ts +88 -0
- package/src/radar-chart/shared.ts +146 -0
- package/src/radial-chart/index.ts +5 -0
- package/src/radial-chart/radial-chart.ts +210 -0
- package/src/radial-chart/radial-rings.ts +328 -0
- package/src/radial-chart/shared.ts +114 -0
- package/dist/browser/chunks/chunk-4SMRCU24.js +0 -2
- package/dist/browser/chunks/chunk-4SMRCU24.js.map +0 -7
- package/dist/kit/chart-border.d.ts +0 -18
- package/dist/kit/chart-border.d.ts.map +0 -1
- package/dist/kit/chart-border.js +0 -23
- package/dist/kit/chart-border.js.map +0 -1
- package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
- package/dist/line-chart/horizontal-axis.js.map +0 -1
- package/dist/pie-chart/pie-legend.d.ts.map +0 -1
- package/dist/pie-chart/pie-legend.js.map +0 -1
- package/src/kit/chart-border.ts +0 -36
- package/src/line-chart/horizontal-axis.ts +0 -122
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Rect, RotatedBox, Text, Types, component2d, insetsOps,
|
|
1
|
+
import { Rect, RotatedBox, Text, Types, component2d, insetsOps, } from "@motionscript/sdk";
|
|
2
2
|
import { enterBudget } from "@motionscript/sdk/component";
|
|
3
|
+
import { boundText } from "./cartesian.js";
|
|
3
4
|
import { asParts, fresh } from "./entries.js";
|
|
4
5
|
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "./motion.js";
|
|
5
6
|
import { DEFAULT_Y_AXIS, formatMarker, } from "./shared.js";
|
|
@@ -9,11 +10,53 @@ export function markerCaption(s, value) {
|
|
|
9
10
|
const index = s.markers.indexOf(value);
|
|
10
11
|
return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value);
|
|
11
12
|
}
|
|
13
|
+
/** The gap between an axis's markers and the plot, and between the markers and the caption, read off its config. */
|
|
14
|
+
export function axisPads(axis, side) {
|
|
15
|
+
return { tick: insetsOps.resolve(axis.tickPadding)[side], title: insetsOps.resolve(axis.titlePadding)[side] };
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A column of right-aligned captions beside the plot: `place(i)` is caption
|
|
19
|
+
* `i`'s centre height in the column (y-up), whose height it is handed. The
|
|
20
|
+
* value axis and a horizontal bar chart's category axis are both this column.
|
|
21
|
+
*/
|
|
22
|
+
export function captionColumn(spec) {
|
|
23
|
+
const pads = () => axisPads(spec.axis(), "right");
|
|
24
|
+
const markers = Array.from({ length: spec.count }, (_, i) => {
|
|
25
|
+
const column = () => marker.parent?.layoutBounds ?? { width: 0, height: 0 };
|
|
26
|
+
const marker = new Text({
|
|
27
|
+
...boundText(() => spec.axis().labelStyle),
|
|
28
|
+
text: () => spec.text(i),
|
|
29
|
+
// Right-aligned against the tick padding: freeform children sit on the content box's centre.
|
|
30
|
+
x: () => (column().width - pads().tick) / 2 - marker.layoutBounds.width / 2 + arrivalOf(spec.arrivals(), i).shift,
|
|
31
|
+
y: () => spec.place(i, column().height),
|
|
32
|
+
opacity: () => arrivalOf(spec.arrivals(), i).opacity * (spec.opacity?.(i) ?? 1),
|
|
33
|
+
});
|
|
34
|
+
return marker;
|
|
35
|
+
});
|
|
36
|
+
const children = [];
|
|
37
|
+
if (spec.label !== "") {
|
|
38
|
+
// Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
|
|
39
|
+
children.push(new RotatedBox({
|
|
40
|
+
angle: -90,
|
|
41
|
+
width: "hug",
|
|
42
|
+
height: "hug",
|
|
43
|
+
children: new Text({
|
|
44
|
+
...boundText(() => spec.axis().titleStyle),
|
|
45
|
+
text: spec.label,
|
|
46
|
+
opacity: () => arrivalOf(spec.arrivals(), "label").opacity,
|
|
47
|
+
x: () => arrivalOf(spec.arrivals(), "label").shift,
|
|
48
|
+
}),
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
51
|
+
children.push(new Rect({ height: "fill", width: "hug", padding: () => ({ right: pads().tick }), children: markers }));
|
|
52
|
+
return new Rect({ flow: "horizontal", gap: () => pads().title, height: "fill", children });
|
|
53
|
+
}
|
|
12
54
|
/**
|
|
13
55
|
* The numeric vertical axis the cartesian charts share: a column of {@link Text}
|
|
14
56
|
* markers, highest at the top, each centred on its value's fraction across
|
|
15
|
-
* `range
|
|
16
|
-
* marker count is fixed at construction. The
|
|
57
|
+
* `range` and right-aligned against the plot. Caption and position are bound, so
|
|
58
|
+
* a rescale tweens live; only the marker count is fixed at construction. The
|
|
59
|
+
* resting state is landed.
|
|
17
60
|
*/
|
|
18
61
|
export const VerticalAxis = component2d({
|
|
19
62
|
key: "verticalAxis",
|
|
@@ -31,11 +74,6 @@ export const VerticalAxis = component2d({
|
|
|
31
74
|
// A node made of markers would otherwise hug them.
|
|
32
75
|
defaults: { width: "fill", height: "fill" },
|
|
33
76
|
children: (state) => {
|
|
34
|
-
const tickPad = insetsOps.resolve(state.axis.tickPadding).right;
|
|
35
|
-
const titlePad = insetsOps.resolve(state.axis.titlePadding).right;
|
|
36
|
-
const row = [];
|
|
37
|
-
// The row's parent is the axis, whose box the markers are placed in.
|
|
38
|
-
const box = () => row[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
|
|
39
77
|
const sorted = () => [...state.markers].sort((a, b) => b - a);
|
|
40
78
|
const fracAt = (value) => {
|
|
41
79
|
if (value === undefined)
|
|
@@ -44,44 +82,19 @@ export const VerticalAxis = component2d({
|
|
|
44
82
|
return max <= min ? 0 : (value - min) / (max - min);
|
|
45
83
|
};
|
|
46
84
|
// A slot with no value (the live list is shorter than the column built) renders empty, not its neighbour.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
85
|
+
return asParts([
|
|
86
|
+
captionColumn({
|
|
87
|
+
count: state.markers.length,
|
|
88
|
+
axis: () => state.axis,
|
|
89
|
+
text: (i) => {
|
|
51
90
|
const value = sorted()[i];
|
|
52
91
|
return value === undefined ? "" : markerCaption(state, value);
|
|
53
92
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const limit = height / 2 - marker.layoutBounds.height / 2;
|
|
60
|
-
return Math.min(centred, limit);
|
|
61
|
-
},
|
|
62
|
-
opacity: () => arrivalOf(state.arrivals, i).opacity,
|
|
63
|
-
x: () => arrivalOf(state.arrivals, i).shift,
|
|
64
|
-
});
|
|
65
|
-
return marker;
|
|
66
|
-
});
|
|
67
|
-
const children = [];
|
|
68
|
-
if (state.label !== "") {
|
|
69
|
-
// Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
|
|
70
|
-
children.push(new RotatedBox({
|
|
71
|
-
angle: -90,
|
|
72
|
-
width: "hug",
|
|
73
|
-
height: "hug",
|
|
74
|
-
children: new Text({
|
|
75
|
-
...textOps.styleProps(state.axis.titleStyle),
|
|
76
|
-
text: state.label,
|
|
77
|
-
opacity: () => arrivalOf(state.arrivals, "label").opacity,
|
|
78
|
-
x: () => arrivalOf(state.arrivals, "label").shift,
|
|
79
|
-
}),
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
children.push(new Rect({ height: "fill", width: "hug", padding: { right: tickPad }, children: markers }));
|
|
83
|
-
row.push(new Rect({ flow: "horizontal", gap: titlePad, children }));
|
|
84
|
-
return asParts(row);
|
|
93
|
+
place: (i, height) => (fracAt(sorted()[i]) - 0.5) * height,
|
|
94
|
+
arrivals: () => state.arrivals,
|
|
95
|
+
label: state.label,
|
|
96
|
+
}),
|
|
97
|
+
]);
|
|
85
98
|
},
|
|
86
99
|
commands: {
|
|
87
100
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAKR,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAA;AACnG,OAAO,EACL,cAAc,EACd,YAAY,GAGb,MAAM,UAAU,CAAA;AAEjB,MAAM,KAAK,GAAG,EAAE,CAAA;AAEhB,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,CAAgF,EAAE,KAAa;IAC3H,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5E,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC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E,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;gBACrI,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACnI,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\n Rect,\n RotatedBox,\n Text,\n Types,\n component2d,\n insetsOps,\n textOps,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\nimport { enterBudget } from \"@motionscript/sdk/component\"\n\nimport { asParts, fresh } from \"./entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\nimport {\n DEFAULT_Y_AXIS,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\n\nconst SLIDE = 24\n\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\n const index = s.markers.indexOf(value)\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\n}\n\n/**\n * The numeric vertical axis the cartesian charts share: a column of {@link Text}\n * markers, highest at the top, each centred on its value's fraction across\n * `range`. Caption and position are bound, so a rescale tweens live; only the\n * marker count is fixed at construction. The resting state is landed.\n */\nexport const VerticalAxis = component2d({\n key: \"verticalAxis\",\n state: {\n range: fresh<Range>(() => [0, 1]),\n /** Tick values in data units, each placed by its fraction across `range`; need not be even or include the ends. */\n markers: fresh<number[]>(() => []),\n /** One caption per marker in its order; a missing one reads as the bare numeric value. */\n captions: fresh<string[]>(() => []),\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\n /** Rotated caption in the gutter left of the markers; empty builds no caption node and reserves no gutter. */\n label: \"\",\n arrivals: arrivalsEntry(),\n },\n // A node made of markers would otherwise hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n children: (state) => {\n const tickPad = insetsOps.resolve(state.axis.tickPadding).right\n const titlePad = insetsOps.resolve(state.axis.titlePadding).right\n\n const row: Node2D[] = []\n // The row's parent is the axis, whose box the markers are placed in.\n const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }\n const sorted = () => [...state.markers].sort((a, b) => b - a)\n const fracAt = (value: number | undefined) => {\n if (value === undefined) return 0\n const [min, max] = state.range\n return max <= min ? 0 : (value - min) / (max - min)\n }\n\n // A slot with no value (the live list is shorter than the column built) renders empty, not its neighbour.\n const markers = state.markers.map((_, i) => {\n const marker: Node2D = new Text({\n ...textOps.styleProps(state.axis.labelStyle),\n text: () => {\n const value = sorted()[i]\n return value === undefined ? \"\" : markerCaption(state, value)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = box().height\n const centred = (fracAt(sorted()[i]) - 0.5) * height\n // Held inside the top edge for a theme whose markers are taller than the headroom; only the top, since the chart's own axis and legend lie below.\n const limit = height / 2 - marker.layoutBounds.height / 2\n return Math.min(centred, limit)\n },\n opacity: () => arrivalOf(state.arrivals, i).opacity,\n x: () => arrivalOf(state.arrivals, i).shift,\n })\n return marker\n })\n\n const children: Node2D[] = []\n if (state.label !== \"\") {\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\n children.push(\n new RotatedBox({\n angle: -90,\n width: \"hug\",\n height: \"hug\",\n children: new Text({\n ...textOps.styleProps(state.axis.titleStyle),\n text: state.label,\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\n x: () => arrivalOf(state.arrivals, \"label\").shift,\n }),\n })\n )\n }\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: { right: tickPad }, children: markers }))\n row.push(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n return asParts(row)\n },\n commands: {\n /**\n * Stagger markers in bottom to top, then the caption. The duration is the\n * whole entrance ({@link enterBudget}). `stagger` is seconds between markers\n * (derived when omitted); `slide` is the starting rightward offset in px.\n */\n enter: {\n args: {\n stagger: Types.custom<number | undefined>(undefined),\n slide: Types.number(SLIDE),\n },\n run: (timeline, state) => {\n const { stagger, slide } = timeline.args\n const count = state.markers.length\n const captioned = state.label !== \"\"\n const from: Arrival = { opacity: 0, shift: slide }\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\n if (count === 0) return arm\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\n const ease = frameEase(timeline)\n // The bottom marker leads, so walk the top-to-bottom column in reverse.\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\n },\n },\n },\n})\n\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\n"]}
|
|
1
|
+
{"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,GAKV,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO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G,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;gBACrI,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACnI,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\n Rect,\n RotatedBox,\n Text,\n Types,\n component2d,\n insetsOps,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\nimport { enterBudget } from \"@motionscript/sdk/component\"\n\nimport { boundText } from \"./cartesian\"\nimport { asParts, fresh } from \"./entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\nimport {\n DEFAULT_Y_AXIS,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\n\nconst SLIDE = 24\n\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\n const index = s.markers.indexOf(value)\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\n}\n\n/** The gap between an axis's markers and the plot, and between the markers and the caption, read off its config. */\nexport function axisPads(axis: AxisConfig, side: \"top\" | \"right\"): { tick: number; title: number } {\n return { tick: insetsOps.resolve(axis.tickPadding)[side], title: insetsOps.resolve(axis.titlePadding)[side] }\n}\n\n/**\n * A column of right-aligned captions beside the plot: `place(i)` is caption\n * `i`'s centre height in the column (y-up), whose height it is handed. The\n * value axis and a horizontal bar chart's category axis are both this column.\n */\nexport function captionColumn(spec: {\n readonly count: number\n readonly axis: () => AxisConfig\n readonly text: (i: number) => string\n readonly place: (i: number, height: number) => number\n readonly arrivals: () => Readonly<Record<string, Arrival>>\n readonly opacity?: (i: number) => number\n readonly label: string\n}): Node2D {\n const pads = () => axisPads(spec.axis(), \"right\")\n const markers = Array.from({ length: spec.count }, (_, i) => {\n const column = () => (marker.parent as Node2D | null)?.layoutBounds ?? { width: 0, height: 0 }\n const marker: Node2D = new Text({\n ...boundText(() => spec.axis().labelStyle),\n text: () => spec.text(i),\n // Right-aligned against the tick padding: freeform children sit on the content box's centre.\n x: () => (column().width - pads().tick) / 2 - marker.layoutBounds.width / 2 + arrivalOf(spec.arrivals(), i).shift,\n y: () => spec.place(i, column().height),\n opacity: () => arrivalOf(spec.arrivals(), i).opacity * (spec.opacity?.(i) ?? 1),\n })\n return marker\n })\n const children: Node2D[] = []\n if (spec.label !== \"\") {\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\n children.push(\n new RotatedBox({\n angle: -90,\n width: \"hug\",\n height: \"hug\",\n children: new Text({\n ...boundText(() => spec.axis().titleStyle),\n text: spec.label,\n opacity: () => arrivalOf(spec.arrivals(), \"label\").opacity,\n x: () => arrivalOf(spec.arrivals(), \"label\").shift,\n }),\n }) as unknown as Node2D\n )\n }\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: () => ({ right: pads().tick }), children: markers }) as unknown as Node2D)\n return new Rect({ flow: \"horizontal\", gap: () => pads().title, height: \"fill\", children }) as unknown as Node2D\n}\n\n/**\n * The numeric vertical axis the cartesian charts share: a column of {@link Text}\n * markers, highest at the top, each centred on its value's fraction across\n * `range` and right-aligned against the plot. Caption and position are bound, so\n * a rescale tweens live; only the marker count is fixed at construction. The\n * resting state is landed.\n */\nexport const VerticalAxis = component2d({\n key: \"verticalAxis\",\n state: {\n range: fresh<Range>(() => [0, 1]),\n /** Tick values in data units, each placed by its fraction across `range`; need not be even or include the ends. */\n markers: fresh<number[]>(() => []),\n /** One caption per marker in its order; a missing one reads as the bare numeric value. */\n captions: fresh<string[]>(() => []),\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\n /** Rotated caption in the gutter left of the markers; empty builds no caption node and reserves no gutter. */\n label: \"\",\n arrivals: arrivalsEntry(),\n },\n // A node made of markers would otherwise hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n children: (state) => {\n const sorted = () => [...state.markers].sort((a, b) => b - a)\n const fracAt = (value: number | undefined) => {\n if (value === undefined) return 0\n const [min, max] = state.range\n return max <= min ? 0 : (value - min) / (max - min)\n }\n // A slot with no value (the live list is shorter than the column built) renders empty, not its neighbour.\n return asParts([\n captionColumn({\n count: state.markers.length,\n axis: () => state.axis,\n text: (i) => {\n const value = sorted()[i]\n return value === undefined ? \"\" : markerCaption(state, value)\n },\n place: (i, height) => (fracAt(sorted()[i]) - 0.5) * height,\n arrivals: () => state.arrivals,\n label: state.label,\n }),\n ])\n },\n commands: {\n /**\n * Stagger markers in bottom to top, then the caption. The duration is the\n * whole entrance ({@link enterBudget}). `stagger` is seconds between markers\n * (derived when omitted); `slide` is the starting rightward offset in px.\n */\n enter: {\n args: {\n stagger: Types.custom<number | undefined>(undefined),\n slide: Types.number(SLIDE),\n },\n run: (timeline, state) => {\n const { stagger, slide } = timeline.args\n const count = state.markers.length\n const captioned = state.label !== \"\"\n const from: Arrival = { opacity: 0, shift: slide }\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\n if (count === 0) return arm\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\n const ease = frameEase(timeline)\n // The bottom marker leads, so walk the top-to-bottom column in reverse.\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\n },\n },\n },\n})\n\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\n"]}
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import { type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
2
|
-
import { type RegionBox } from "./shared.js";
|
|
3
|
-
/**
|
|
1
|
+
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
2
|
+
import { type LineCurve, type RegionBox } from "./shared.js";
|
|
3
|
+
/** The x a trace at `progress` has reached, across `points` ordered along x. */
|
|
4
|
+
export declare function traceX(points: readonly Vector2[], progress: number): number;
|
|
5
|
+
/**
|
|
6
|
+
* One series of a {@link LineChart}: its line through pre-mapped pixel `points`,
|
|
7
|
+
* shaped by `curve`, and a dot on each point. `progress` traces it in from the
|
|
8
|
+
* left; `enabled` shows or hides it wholesale.
|
|
9
|
+
*/
|
|
4
10
|
export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
5
11
|
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
6
12
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
13
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
7
14
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
15
|
+
/** A dot of `dotSize` on each point, in `dotFill`; none at size 0. */
|
|
16
|
+
readonly dotSize: 0;
|
|
17
|
+
readonly dotFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
8
18
|
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
9
19
|
readonly progress: 1;
|
|
10
20
|
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
@@ -17,10 +27,17 @@ export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine
|
|
|
17
27
|
readonly from: import("@motionscript/sdk").Type<number, number, false>;
|
|
18
28
|
readonly to: import("@motionscript/sdk").Type<number, number, false>;
|
|
19
29
|
};
|
|
30
|
+
readonly hold: {
|
|
31
|
+
readonly shown: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
32
|
+
};
|
|
20
33
|
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
21
34
|
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
22
35
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
36
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
23
37
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
38
|
+
/** A dot of `dotSize` on each point, in `dotFill`; none at size 0. */
|
|
39
|
+
readonly dotSize: 0;
|
|
40
|
+
readonly dotFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
24
41
|
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
25
42
|
readonly progress: 1;
|
|
26
43
|
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
@@ -31,7 +48,11 @@ export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine
|
|
|
31
48
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
32
49
|
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
33
50
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
51
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
34
52
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
53
|
+
/** A dot of `dotSize` on each point, in `dotFill`; none at size 0. */
|
|
54
|
+
readonly dotSize: 0;
|
|
55
|
+
readonly dotFill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
35
56
|
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
36
57
|
readonly progress: 1;
|
|
37
58
|
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
@@ -44,6 +65,77 @@ export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine
|
|
|
44
65
|
readonly from: import("@motionscript/sdk").Type<number, number, false>;
|
|
45
66
|
readonly to: import("@motionscript/sdk").Type<number, number, false>;
|
|
46
67
|
};
|
|
68
|
+
readonly hold: {
|
|
69
|
+
readonly shown: import("@motionscript/sdk").Type<boolean, boolean, false>;
|
|
70
|
+
};
|
|
47
71
|
}, _Node2D<_Node2DProps>>>>;
|
|
48
72
|
export type ChartLine = NodeOf<typeof ChartLine>;
|
|
73
|
+
/**
|
|
74
|
+
* The fill under one series of a {@link LineChart}: down to `base` (the series
|
|
75
|
+
* below it in a stack) or, without one, to the `baseline`. Drawn by its own node
|
|
76
|
+
* so every area sits under every line; the chart binds its trace, switch and
|
|
77
|
+
* opacity to its line's, so the two move as one.
|
|
78
|
+
*/
|
|
79
|
+
export declare const ChartArea: import("@motionscript/sdk").Component<"chartArea", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
80
|
+
/** The series' points, as its line has them. */
|
|
81
|
+
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
82
|
+
/** The line the area fills down to, at the same x positions; empty for the baseline. */
|
|
83
|
+
readonly base: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
84
|
+
/** Pixel y of the baseline. */
|
|
85
|
+
readonly baseline: 0;
|
|
86
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
87
|
+
readonly area: import("@motionscript/sdk").Type<"none" | "solid" | "gradient", "none" | "solid" | "gradient", false>;
|
|
88
|
+
/** The series colour; the area paints it at `areaOpacity`, a gradient fading it out towards the bottom. */
|
|
89
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
90
|
+
readonly areaOpacity: 0.4;
|
|
91
|
+
readonly progress: 1;
|
|
92
|
+
readonly enabled: true;
|
|
93
|
+
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
94
|
+
readonly dimOpacity: 0.2;
|
|
95
|
+
}>, {}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
96
|
+
/** The series' points, as its line has them. */
|
|
97
|
+
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
98
|
+
/** The line the area fills down to, at the same x positions; empty for the baseline. */
|
|
99
|
+
readonly base: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
100
|
+
/** Pixel y of the baseline. */
|
|
101
|
+
readonly baseline: 0;
|
|
102
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
103
|
+
readonly area: import("@motionscript/sdk").Type<"none" | "solid" | "gradient", "none" | "solid" | "gradient", false>;
|
|
104
|
+
/** The series colour; the area paints it at `areaOpacity`, a gradient fading it out towards the bottom. */
|
|
105
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
106
|
+
readonly areaOpacity: 0.4;
|
|
107
|
+
readonly progress: 1;
|
|
108
|
+
readonly enabled: true;
|
|
109
|
+
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
110
|
+
readonly dimOpacity: 0.2;
|
|
111
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
112
|
+
/** The series' points, as its line has them. */
|
|
113
|
+
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
114
|
+
/** The line the area fills down to, at the same x positions; empty for the baseline. */
|
|
115
|
+
readonly base: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
116
|
+
/** Pixel y of the baseline. */
|
|
117
|
+
readonly baseline: 0;
|
|
118
|
+
readonly curve: import("@motionscript/sdk").Type<LineCurve, LineCurve, false>;
|
|
119
|
+
readonly area: import("@motionscript/sdk").Type<"none" | "solid" | "gradient", "none" | "solid" | "gradient", false>;
|
|
120
|
+
/** The series colour; the area paints it at `areaOpacity`, a gradient fading it out towards the bottom. */
|
|
121
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
122
|
+
readonly areaOpacity: 0.4;
|
|
123
|
+
readonly progress: 1;
|
|
124
|
+
readonly enabled: true;
|
|
125
|
+
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
126
|
+
readonly dimOpacity: 0.2;
|
|
127
|
+
}>, {}, _Node2D<_Node2DProps>>>>;
|
|
128
|
+
interface Span {
|
|
129
|
+
readonly top: number;
|
|
130
|
+
readonly bottom: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* The area's paint for an outline spanning `own`: the series colour at
|
|
134
|
+
* `opacity`, or for a gradient that colour fading to nearly nothing across
|
|
135
|
+
* `whole`. A gradient maps onto the bounds of the shape it fills, so its ends
|
|
136
|
+
* are placed in `own`'s unit box (y-up) at `whole`'s top and bottom.
|
|
137
|
+
*/
|
|
138
|
+
export declare function areaFill(colour: FillResolved[], area: "none" | "solid" | "gradient", opacity: number, whole: Span, own: Span): FillResolved[];
|
|
139
|
+
export type ChartArea = NodeOf<typeof ChartArea>;
|
|
140
|
+
export {};
|
|
49
141
|
//# sourceMappingURL=chart-line.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAGhC,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAO1B,OAAO,EAOL,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB,gFAAgF;AAChF,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAK3E;AAuBD;;;;GAIG;AACH,eAAO,MAAM,SAAS;IAGlB,qGAAqG;;;;IAIrG,sEAAsE;;;IAGtE,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;;;;;;;;;IAX7E,qGAAqG;;;;IAIrG,sEAAsE;;;IAGtE,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;IAX7E,qGAAqG;;;;IAIrG,sEAAsE;;;IAGtE,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;;;;;;;;2BAyE/E,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,SAAS;IAGlB,gDAAgD;;IAEhD,wFAAwF;;IAExF,+BAA+B;;;;IAI/B,2GAA2G;;;;;;;;IAR3G,gDAAgD;;IAEhD,wFAAwF;;IAExF,+BAA+B;;;;IAI/B,2GAA2G;;;;;;;;IAR3G,gDAAgD;;IAEhD,wFAAwF;;IAExF,+BAA+B;;;;IAI/B,2GAA2G;;;;;;;gCAkC7G,CAAA;AAEF,UAAU,IAAI;IACZ,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAYD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,YAAY,EAAE,CAY7I;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
|
|
@@ -1,49 +1,51 @@
|
|
|
1
|
-
import { Graphics2D, Types, component2d, strokeOps, } from "@motionscript/sdk";
|
|
1
|
+
import { Graphics2D, Types, clamp, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fade } from "../kit/cartesian.js";
|
|
2
3
|
import { fresh } from "../kit/entries.js";
|
|
3
4
|
import { frameEase } from "../kit/motion.js";
|
|
4
5
|
import { loadPaints } from "../kit/paints.js";
|
|
5
6
|
import { SPOTLIGHT_DIM } from "../kit/shared.js";
|
|
6
|
-
import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
|
|
7
|
-
/** The
|
|
8
|
-
function
|
|
9
|
-
if (
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
let total = 0;
|
|
15
|
-
for (let i = 1; i < pts.length; i++) {
|
|
16
|
-
const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
|
|
17
|
-
segLen.push(d);
|
|
18
|
-
total += d;
|
|
19
|
-
}
|
|
20
|
-
if (total === 0)
|
|
21
|
-
return pts;
|
|
22
|
-
let target = total * p;
|
|
23
|
-
const out = [pts[0]];
|
|
24
|
-
for (let i = 0; i < segLen.length; i++) {
|
|
25
|
-
if (target >= segLen[i]) {
|
|
26
|
-
out.push(pts[i + 1]);
|
|
27
|
-
target -= segLen[i];
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const t = segLen[i] === 0 ? 0 : target / segLen[i];
|
|
31
|
-
out.push({
|
|
32
|
-
x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
|
|
33
|
-
y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
|
|
34
|
-
});
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return out;
|
|
7
|
+
import { EMPTY_REGION_BOX, clipPolygonToBox, clipPolylineToBox, cutAt, curvePoints, hasRegion, } from "./shared.js";
|
|
8
|
+
/** The x a trace at `progress` has reached, across `points` ordered along x. */
|
|
9
|
+
export function traceX(points, progress) {
|
|
10
|
+
if (points.length === 0)
|
|
11
|
+
return 0;
|
|
12
|
+
const first = points[0].x;
|
|
13
|
+
const last = points[points.length - 1].x;
|
|
14
|
+
return progress >= 1 ? Infinity : first + (last - first) * progress;
|
|
39
15
|
}
|
|
40
|
-
/**
|
|
16
|
+
/** The drawn path at `progress`: the whole curve once traced, else the part left of the trace. */
|
|
17
|
+
function traced(points, curve, progress) {
|
|
18
|
+
const path = curvePoints(points, curve);
|
|
19
|
+
return progress >= 1 ? path : cutAt(path, traceX(points, progress));
|
|
20
|
+
}
|
|
21
|
+
const curveEntry = () => Types.custom("smooth");
|
|
22
|
+
/** A closed outline as path commands. */
|
|
23
|
+
function outlineCommands(points) {
|
|
24
|
+
return [...points.map((p, i) => ({ type: i === 0 ? "M" : "L", x: p.x, y: p.y })), { type: "Z" }];
|
|
25
|
+
}
|
|
26
|
+
function fillOutline(ctx, outline, fill, opacity) {
|
|
27
|
+
if (outline.length < 3 || opacity <= 0)
|
|
28
|
+
return;
|
|
29
|
+
const { width, height } = ctx.size;
|
|
30
|
+
// A frame symmetric about the origin, so the outline draws where its points say rather than re-centred on itself.
|
|
31
|
+
const centerBounds = [-width / 2, -height / 2, width / 2, height / 2];
|
|
32
|
+
ctx.draw(new Graphics2D().path({ data: outlineCommands(outline), centerBounds }).fill(fill).opacity(opacity));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* One series of a {@link LineChart}: its line through pre-mapped pixel `points`,
|
|
36
|
+
* shaped by `curve`, and a dot on each point. `progress` traces it in from the
|
|
37
|
+
* left; `enabled` shows or hides it wholesale.
|
|
38
|
+
*/
|
|
41
39
|
export const ChartLine = component2d({
|
|
42
40
|
key: "chartLine",
|
|
43
41
|
state: {
|
|
44
42
|
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
45
43
|
points: fresh(() => []),
|
|
44
|
+
curve: curveEntry(),
|
|
46
45
|
stroke: Types.custom([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
46
|
+
/** A dot of `dotSize` on each point, in `dotFill`; none at size 0. */
|
|
47
|
+
dotSize: 0,
|
|
48
|
+
dotFill: Types.custom([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
47
49
|
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
48
50
|
progress: 1,
|
|
49
51
|
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
@@ -52,7 +54,7 @@ export const ChartLine = component2d({
|
|
|
52
54
|
spotlight: fresh(() => EMPTY_REGION_BOX),
|
|
53
55
|
dimOpacity: SPOTLIGHT_DIM,
|
|
54
56
|
},
|
|
55
|
-
load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
|
|
57
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.dotFill], strokes: [state.stroke] }),
|
|
56
58
|
commands: {
|
|
57
59
|
/**
|
|
58
60
|
* Trace the line from `from` to `to`; `showSeries`/`hideSeries` are this with
|
|
@@ -72,35 +74,145 @@ export const ChartLine = component2d({
|
|
|
72
74
|
});
|
|
73
75
|
},
|
|
74
76
|
},
|
|
77
|
+
/** Hold the line fully traced while its chart moves it, switched on throughout a show and off once a hide lands. */
|
|
78
|
+
hold: {
|
|
79
|
+
args: { shown: Types.boolean(true) },
|
|
80
|
+
run: (timeline) => {
|
|
81
|
+
const { shown } = timeline.args;
|
|
82
|
+
return timeline.animate((t) => ({ progress: 1, enabled: shown || t < 1 }), { eased: false });
|
|
83
|
+
},
|
|
84
|
+
},
|
|
75
85
|
},
|
|
76
86
|
render: (ctx, state) => {
|
|
77
87
|
if (!state.enabled)
|
|
78
88
|
return;
|
|
79
89
|
const pts = state.points;
|
|
80
|
-
|
|
90
|
+
const p = clamp(state.progress, 0, 1);
|
|
91
|
+
if (pts.length === 0 || p <= 0)
|
|
81
92
|
return;
|
|
82
|
-
const
|
|
83
|
-
|
|
93
|
+
const box = state.spotlight;
|
|
94
|
+
const lit = hasRegion(box);
|
|
95
|
+
const dim = clamp(state.dimOpacity, 0, 1);
|
|
96
|
+
const stroke = state.stroke;
|
|
97
|
+
const weight = stroke[0]?.weight ?? 0;
|
|
98
|
+
const drawn = traced(pts, state.curve, p);
|
|
99
|
+
if (drawn.length >= 2 && weight > 0) {
|
|
100
|
+
// Rounded corners only where the line has corners to round.
|
|
101
|
+
const radius = state.curve === "linear" ? weight * 2 : 0;
|
|
102
|
+
ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke).opacity(lit ? dim : 1));
|
|
103
|
+
// One `draw` per run: shapes chained before `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.
|
|
104
|
+
if (lit)
|
|
105
|
+
for (const run of clipPolylineToBox(drawn, box))
|
|
106
|
+
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
|
|
107
|
+
}
|
|
108
|
+
const size = state.dotSize;
|
|
109
|
+
if (size <= 0)
|
|
84
110
|
return;
|
|
85
|
-
const
|
|
86
|
-
|
|
111
|
+
const reach = traceX(pts, p);
|
|
112
|
+
const bright = new Graphics2D();
|
|
113
|
+
const dimmed = new Graphics2D();
|
|
114
|
+
let brightAny = false;
|
|
115
|
+
let dimAny = false;
|
|
116
|
+
for (const pt of pts) {
|
|
117
|
+
// A dot grows in as the trace passes it.
|
|
118
|
+
const grown = reach === Infinity ? 1 : clamp((reach - pt.x) / (size * 2), 0, 1);
|
|
119
|
+
if (grown <= 0)
|
|
120
|
+
continue;
|
|
121
|
+
const inside = !lit || (pt.x >= box.left && pt.x <= box.right && pt.y >= box.bottom && pt.y <= box.top);
|
|
122
|
+
(inside ? bright : dimmed).ellipse({ x: pt.x, y: pt.y, width: size * grown, height: size * grown });
|
|
123
|
+
if (inside)
|
|
124
|
+
brightAny = true;
|
|
125
|
+
else
|
|
126
|
+
dimAny = true;
|
|
127
|
+
}
|
|
128
|
+
if (dimAny)
|
|
129
|
+
ctx.draw(dimmed.fill(state.dotFill).opacity(dim));
|
|
130
|
+
if (brightAny)
|
|
131
|
+
ctx.draw(bright.fill(state.dotFill));
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
/**
|
|
135
|
+
* The fill under one series of a {@link LineChart}: down to `base` (the series
|
|
136
|
+
* below it in a stack) or, without one, to the `baseline`. Drawn by its own node
|
|
137
|
+
* so every area sits under every line; the chart binds its trace, switch and
|
|
138
|
+
* opacity to its line's, so the two move as one.
|
|
139
|
+
*/
|
|
140
|
+
export const ChartArea = component2d({
|
|
141
|
+
key: "chartArea",
|
|
142
|
+
state: {
|
|
143
|
+
/** The series' points, as its line has them. */
|
|
144
|
+
points: fresh(() => []),
|
|
145
|
+
/** The line the area fills down to, at the same x positions; empty for the baseline. */
|
|
146
|
+
base: fresh(() => []),
|
|
147
|
+
/** Pixel y of the baseline. */
|
|
148
|
+
baseline: 0,
|
|
149
|
+
curve: curveEntry(),
|
|
150
|
+
area: Types.custom("solid"),
|
|
151
|
+
/** The series colour; the area paints it at `areaOpacity`, a gradient fading it out towards the bottom. */
|
|
152
|
+
fill: Types.custom([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
153
|
+
areaOpacity: 0.4,
|
|
154
|
+
progress: 1,
|
|
155
|
+
enabled: true,
|
|
156
|
+
spotlight: fresh(() => EMPTY_REGION_BOX),
|
|
157
|
+
dimOpacity: SPOTLIGHT_DIM,
|
|
158
|
+
},
|
|
159
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.fill] }),
|
|
160
|
+
render: (ctx, state) => {
|
|
161
|
+
const pts = state.points;
|
|
162
|
+
const p = clamp(state.progress, 0, 1);
|
|
163
|
+
if (!state.enabled || state.area === "none" || pts.length < 2 || p <= 0 || state.fill.length === 0)
|
|
87
164
|
return;
|
|
88
|
-
const
|
|
89
|
-
|
|
165
|
+
const outlineAt = (progress) => {
|
|
166
|
+
const top = traced(pts, state.curve, progress);
|
|
167
|
+
if (top.length < 2)
|
|
168
|
+
return [];
|
|
169
|
+
const base = state.base.length === pts.length
|
|
170
|
+
? traced(state.base, state.curve, progress)
|
|
171
|
+
: [{ x: top[0].x, y: state.baseline }, { x: top[top.length - 1].x, y: state.baseline }];
|
|
172
|
+
return [...top, ...[...base].reverse()];
|
|
173
|
+
};
|
|
174
|
+
// The gradient spans the whole area's height, so it holds still while the area traces in and across a spotlight's cut.
|
|
175
|
+
const span = verticalSpan(outlineAt(1));
|
|
176
|
+
const paint = (outline, opacity) => fillOutline(ctx, outline, areaFill(state.fill, state.area, state.areaOpacity, span, verticalSpan(outline)), opacity);
|
|
177
|
+
const outline = outlineAt(p);
|
|
90
178
|
const box = state.spotlight;
|
|
91
179
|
if (!hasRegion(box)) {
|
|
92
|
-
|
|
180
|
+
paint(outline, 1);
|
|
93
181
|
return;
|
|
94
182
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
.line({ points: drawn, radius })
|
|
98
|
-
.stroke(stroke)
|
|
99
|
-
.opacity(Math.max(0, Math.min(1, state.dimOpacity))));
|
|
100
|
-
// One `draw` per run: shapes chained before `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.
|
|
101
|
-
for (const run of clipPolylineToBox(drawn, box)) {
|
|
102
|
-
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
|
|
103
|
-
}
|
|
183
|
+
paint(outline, clamp(state.dimOpacity, 0, 1));
|
|
184
|
+
paint(clipPolygonToBox(outline, box), 1);
|
|
104
185
|
},
|
|
105
186
|
});
|
|
187
|
+
function verticalSpan(points) {
|
|
188
|
+
let top = -Infinity;
|
|
189
|
+
let bottom = Infinity;
|
|
190
|
+
for (const p of points) {
|
|
191
|
+
if (p.y > top)
|
|
192
|
+
top = p.y;
|
|
193
|
+
if (p.y < bottom)
|
|
194
|
+
bottom = p.y;
|
|
195
|
+
}
|
|
196
|
+
return { top, bottom };
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The area's paint for an outline spanning `own`: the series colour at
|
|
200
|
+
* `opacity`, or for a gradient that colour fading to nearly nothing across
|
|
201
|
+
* `whole`. A gradient maps onto the bounds of the shape it fills, so its ends
|
|
202
|
+
* are placed in `own`'s unit box (y-up) at `whole`'s top and bottom.
|
|
203
|
+
*/
|
|
204
|
+
export function areaFill(colour, area, opacity, whole, own) {
|
|
205
|
+
const top = colour[colour.length - 1];
|
|
206
|
+
if (area !== "gradient" || top?.type !== "solid" || !(own.top > own.bottom))
|
|
207
|
+
return fade(colour, opacity);
|
|
208
|
+
const [r, g, b, a] = top.color;
|
|
209
|
+
const middle = (own.top + own.bottom) / 2;
|
|
210
|
+
const half = (own.top - own.bottom) / 2;
|
|
211
|
+
return fillOps.resolve({
|
|
212
|
+
type: "linear-gradient",
|
|
213
|
+
colors: [[r, g, b, a * opacity], [r, g, b, a * opacity * 0.04]],
|
|
214
|
+
start: { x: 0, y: (whole.top - middle) / half },
|
|
215
|
+
end: { x: 0, y: (whole.bottom - middle) / half },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
106
218
|
//# sourceMappingURL=chart-line.js.map
|