@motionscript/charts 0.1.0-alpha.5 → 0.1.0-alpha.7
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 +40 -0
- package/README.md +30 -16
- package/dist/bar-chart/bar-chart.d.ts +133 -242
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +378 -569
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +35 -41
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +93 -115
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +50 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +156 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +3 -3
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +3 -3
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-XROBIRQK.js +2 -0
- package/dist/browser/chunks/chunk-XROBIRQK.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +8 -6
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +8 -6
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +44 -0
- package/dist/kit/cartesian.d.ts.map +1 -0
- package/dist/kit/cartesian.js +59 -0
- package/dist/kit/cartesian.js.map +1 -0
- package/dist/kit/chart-border.d.ts +10 -11
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +15 -32
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -21
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +33 -90
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +123 -64
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +129 -154
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +17 -0
- package/dist/kit/entries.d.ts.map +1 -0
- package/dist/kit/entries.js +19 -0
- package/dist/kit/entries.js.map +1 -0
- package/dist/kit/motion.d.ts +48 -0
- package/dist/kit/motion.d.ts.map +1 -0
- package/dist/kit/motion.js +63 -0
- package/dist/kit/motion.js.map +1 -0
- package/dist/kit/paints.d.ts +10 -0
- package/dist/kit/paints.d.ts.map +1 -0
- package/dist/kit/paints.js +12 -0
- package/dist/kit/paints.js.map +1 -0
- package/dist/kit/shared.d.ts +31 -3
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +42 -3
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +48 -61
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +97 -132
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +60 -77
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +100 -121
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +32 -33
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +31 -65
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +58 -64
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +94 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +156 -319
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +403 -663
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +3 -3
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +3 -3
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -2
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +108 -132
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +200 -271
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +84 -31
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +93 -107
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +160 -131
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -391
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +2 -2
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +2 -2
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +415 -701
- package/src/bar-chart/category-axis.ts +95 -110
- package/src/bar-chart/chart-bars.ts +178 -200
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +3 -3
- package/src/engine.ts +8 -6
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +22 -33
- package/src/kit/chart-canvas.ts +44 -79
- package/src/kit/chart-legend.ts +173 -189
- package/src/kit/entries.ts +20 -0
- package/src/kit/motion.ts +90 -0
- package/src/kit/paints.ts +15 -0
- package/src/kit/shared.ts +52 -3
- package/src/kit/vertical-axis.ts +110 -140
- package/src/line-chart/chart-line.ts +102 -154
- package/src/line-chart/chart-region.ts +35 -80
- package/src/line-chart/horizontal-axis.ts +101 -152
- package/src/line-chart/index.ts +2 -2
- package/src/line-chart/line-chart.ts +449 -825
- package/src/line-chart/shared.ts +3 -3
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +221 -311
- package/src/pie-chart/pie-legend.ts +124 -114
- package/src/pie-chart/pie-ring.ts +386 -473
- package/src/pie-chart/shared.ts +2 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
|
@@ -1,45 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Graphics2D, Node2D, command, easeOut, strokeOps, property, } from "@motionscript/sdk";
|
|
1
|
+
import { Graphics2D, Types, component2d, strokeOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fresh } from "../kit/entries.js";
|
|
3
|
+
import { frameEase } from "../kit/motion.js";
|
|
4
|
+
import { loadPaints } from "../kit/paints.js";
|
|
8
5
|
import { SPOTLIGHT_DIM } from "../kit/shared.js";
|
|
9
6
|
import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
|
|
10
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
|
|
9
|
+
* by *cumulative arc length* so the line traces at a steady pace regardless of
|
|
10
|
+
* uneven point spacing. Returns the whole-point prefix plus one interpolated
|
|
11
|
+
* point partway along the active segment.
|
|
12
|
+
*/
|
|
13
|
+
function tracePoints(pts, p) {
|
|
14
|
+
if (p >= 1 || pts.length < 2)
|
|
15
|
+
return pts;
|
|
16
|
+
if (p <= 0)
|
|
17
|
+
return [];
|
|
18
|
+
const segLen = [];
|
|
19
|
+
let total = 0;
|
|
20
|
+
for (let i = 1; i < pts.length; i++) {
|
|
21
|
+
const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
|
|
22
|
+
segLen.push(d);
|
|
23
|
+
total += d;
|
|
24
|
+
}
|
|
25
|
+
if (total === 0)
|
|
26
|
+
return pts;
|
|
27
|
+
let target = total * p;
|
|
28
|
+
const out = [pts[0]];
|
|
29
|
+
for (let i = 0; i < segLen.length; i++) {
|
|
30
|
+
if (target >= segLen[i]) {
|
|
31
|
+
out.push(pts[i + 1]);
|
|
32
|
+
target -= segLen[i];
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const t = segLen[i] === 0 ? 0 : target / segLen[i];
|
|
36
|
+
out.push({
|
|
37
|
+
x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
|
|
38
|
+
y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
|
|
39
|
+
});
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
11
45
|
/**
|
|
12
46
|
* A single series line of a {@link LineChart}: one rounded polyline traced
|
|
13
47
|
* through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
|
|
14
48
|
* Sized and positioned by the parent, which shares the plot's coordinate frame.
|
|
15
49
|
*
|
|
16
|
-
* Two signals drive it:
|
|
17
|
-
* (animated by
|
|
50
|
+
* Two signals drive it: `progress` traces the line in
|
|
51
|
+
* (animated by `enter`) and `enabled` shows or hides it wholesale.
|
|
18
52
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
export const ChartLine = component2d({
|
|
54
|
+
key: "chartLine",
|
|
55
|
+
state: {
|
|
56
|
+
/** The series polyline, already mapped into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x. */
|
|
57
|
+
points: fresh(() => []),
|
|
58
|
+
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
59
|
+
stroke: Types.custom([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
60
|
+
/**
|
|
61
|
+
* Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
|
|
62
|
+
* end to its right. Defaults to 1, so the paused editor canvas paints the line;
|
|
63
|
+
* `enter` drives it from 0 regardless of where it rests.
|
|
64
|
+
*/
|
|
65
|
+
progress: 1,
|
|
66
|
+
/** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */
|
|
67
|
+
enabled: true,
|
|
68
|
+
/** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */
|
|
69
|
+
spotlight: fresh(() => EMPTY_REGION_BOX),
|
|
70
|
+
/** Opacity the out-of-region stretches fade to. */
|
|
71
|
+
dimOpacity: SPOTLIGHT_DIM,
|
|
72
|
+
},
|
|
73
|
+
load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
|
|
74
|
+
commands: {
|
|
75
|
+
/**
|
|
76
|
+
* Trace the line from `from` to `to` over the command — by default in from
|
|
77
|
+
* its left end to its right. `showSeries` and `hideSeries` are the same
|
|
78
|
+
* motion in opposite directions, so both are this with their ends stated.
|
|
79
|
+
*
|
|
80
|
+
* `enabled` rides along in the same value rather than being set before or
|
|
81
|
+
* after the command: a line is drawable for every `t` the trace covers and
|
|
82
|
+
* undrawn outside it, which is what makes arriving at a time backwards show
|
|
83
|
+
* what arriving forwards does.
|
|
84
|
+
*/
|
|
85
|
+
enter: {
|
|
86
|
+
args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
|
|
87
|
+
run: (timeline) => {
|
|
88
|
+
const { from, to } = timeline.args;
|
|
89
|
+
const ease = frameEase(timeline);
|
|
90
|
+
return timeline.animate((t) => {
|
|
91
|
+
const progress = from + (to - from) * ease(t);
|
|
92
|
+
// Hidden only once it has fully retraced, so the last frame of a hide is
|
|
93
|
+
// the empty plot rather than a line that vanished a frame early.
|
|
94
|
+
return { progress, enabled: progress > 0 };
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
render: (ctx, state) => {
|
|
100
|
+
if (!state.enabled)
|
|
30
101
|
return;
|
|
31
|
-
const pts =
|
|
102
|
+
const pts = state.points;
|
|
32
103
|
if (pts.length < 2)
|
|
33
104
|
return;
|
|
34
|
-
const p = Math.max(0, Math.min(1,
|
|
105
|
+
const p = Math.max(0, Math.min(1, state.progress));
|
|
35
106
|
if (p <= 0)
|
|
36
107
|
return;
|
|
37
|
-
const drawn =
|
|
108
|
+
const drawn = tracePoints(pts, p);
|
|
38
109
|
if (drawn.length < 2)
|
|
39
110
|
return;
|
|
40
|
-
const stroke =
|
|
111
|
+
const stroke = state.stroke;
|
|
41
112
|
const radius = (stroke[0]?.weight ?? 0) * 2; // round the joins
|
|
42
|
-
const box =
|
|
113
|
+
const box = state.spotlight;
|
|
43
114
|
if (!hasRegion(box)) {
|
|
44
115
|
ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
|
|
45
116
|
return;
|
|
@@ -52,105 +123,13 @@ export class ChartLine extends Node2D {
|
|
|
52
123
|
ctx.draw(new Graphics2D()
|
|
53
124
|
.line({ points: drawn, radius })
|
|
54
125
|
.stroke(stroke)
|
|
55
|
-
.opacity(Math.max(0, Math.min(1,
|
|
126
|
+
.opacity(Math.max(0, Math.min(1, state.dimOpacity))));
|
|
56
127
|
// One `draw` per run: shapes chained before a `stroke()` are combined into a
|
|
57
128
|
// single surface, and stroking a union of disjoint open paths doesn't paint
|
|
58
129
|
// — so a line that leaves the region and comes back would lose both halves.
|
|
59
130
|
for (const run of clipPolylineToBox(drawn, box)) {
|
|
60
131
|
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
|
|
61
132
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
* The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
|
|
65
|
-
* by *cumulative arc length* so the line traces at a steady pace regardless of
|
|
66
|
-
* uneven point spacing. Returns the whole-point prefix plus one interpolated
|
|
67
|
-
* point partway along the active segment.
|
|
68
|
-
*/
|
|
69
|
-
tracePoints(pts, p) {
|
|
70
|
-
if (p >= 1 || pts.length < 2)
|
|
71
|
-
return pts;
|
|
72
|
-
if (p <= 0)
|
|
73
|
-
return [];
|
|
74
|
-
const segLen = [];
|
|
75
|
-
let total = 0;
|
|
76
|
-
for (let i = 1; i < pts.length; i++) {
|
|
77
|
-
const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
|
|
78
|
-
segLen.push(d);
|
|
79
|
-
total += d;
|
|
80
|
-
}
|
|
81
|
-
if (total === 0)
|
|
82
|
-
return pts;
|
|
83
|
-
let target = total * p;
|
|
84
|
-
const out = [pts[0]];
|
|
85
|
-
for (let i = 0; i < segLen.length; i++) {
|
|
86
|
-
if (target >= segLen[i]) {
|
|
87
|
-
out.push(pts[i + 1]);
|
|
88
|
-
target -= segLen[i];
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const t = segLen[i] === 0 ? 0 : target / segLen[i];
|
|
92
|
-
out.push({
|
|
93
|
-
x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
|
|
94
|
-
y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return out;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Trace the line in from its left end to its right over `duration` seconds.
|
|
103
|
-
* Drives `progress` `0 → 1`.
|
|
104
|
-
*
|
|
105
|
-
* A `Command` rather than a generator, so the trace can be *evaluated* at a
|
|
106
|
-
* time instead of run to one — which is what lets a scene containing this
|
|
107
|
-
* chart be scrubbed in constant time. It no longer needs to prime `progress`
|
|
108
|
-
* to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces
|
|
109
|
-
* by definition rather than by having reset something.
|
|
110
|
-
*/
|
|
111
|
-
enter(args) {
|
|
112
|
-
return this.enterFrom(0, args.duration, args.easing ?? easeOut());
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* The trace, with both ends stated: `progress` runs `from` → `to`.
|
|
116
|
-
*
|
|
117
|
-
* What {@link LineChart.showSeries} and `hideSeries` are both made of — they
|
|
118
|
-
* are the same motion in opposite directions, and expressing them as one thing
|
|
119
|
-
* with endpoints is what stops the pair drifting apart.
|
|
120
|
-
*
|
|
121
|
-
* `enabled` rides along in the same value rather than being set before or after
|
|
122
|
-
* the command. A line is drawable for every `t` the trace covers and undrawn
|
|
123
|
-
* outside it, which is what makes arriving at a time backwards show what
|
|
124
|
-
* arriving forwards does — a flag flipped by a side effect would not.
|
|
125
|
-
*/
|
|
126
|
-
enterFrom(from, duration, easing = easeOut(), to = 1) {
|
|
127
|
-
return this.command((t) => {
|
|
128
|
-
const progress = from + (to - from) * t;
|
|
129
|
-
// Hidden only once it has fully retraced, so the last frame of a hide is
|
|
130
|
-
// the empty plot rather than a line that vanished a frame early.
|
|
131
|
-
return { progress, enabled: progress > 0 };
|
|
132
|
-
}, duration, easing);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
__decorate([
|
|
136
|
-
property({ default: () => [] })
|
|
137
|
-
], ChartLine.prototype, "points", void 0);
|
|
138
|
-
__decorate([
|
|
139
|
-
property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })
|
|
140
|
-
], ChartLine.prototype, "stroke", void 0);
|
|
141
|
-
__decorate([
|
|
142
|
-
property({ default: 1 })
|
|
143
|
-
], ChartLine.prototype, "progress", void 0);
|
|
144
|
-
__decorate([
|
|
145
|
-
property({ default: true })
|
|
146
|
-
], ChartLine.prototype, "enabled", void 0);
|
|
147
|
-
__decorate([
|
|
148
|
-
property({ default: () => EMPTY_REGION_BOX })
|
|
149
|
-
], ChartLine.prototype, "spotlight", void 0);
|
|
150
|
-
__decorate([
|
|
151
|
-
property({ default: SPOTLIGHT_DIM })
|
|
152
|
-
], ChartLine.prototype, "dimOpacity", void 0);
|
|
153
|
-
__decorate([
|
|
154
|
-
command()
|
|
155
|
-
], ChartLine.prototype, "enter", null);
|
|
133
|
+
},
|
|
134
|
+
});
|
|
156
135
|
//# sourceMappingURL=chart-line.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,QAAQ,GAST,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GAEV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAoC3D;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,MAAsB;IASnD;;;OAGG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7B,CAAC;IAES,UAAU,CAAC,GAAoB;QACvC,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAM;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QACvB,IAAI,GAA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A;YACvC,yEAAyE;YACzE,iEAAiE;YACjE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,CAAC,EAAE,CAAA;QAC5C,CAAC,EACD,QAAQ,EACR,MAAM,CACP,CAAA;IACH,CAAC;CACF;AAzIuD;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAe,EAAE,CAAC;yCAA0B;AAE/D;IADP,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;yCACtD;AACY;IAAjC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;2CAAyB;AACb;IAApC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAAyB;AACE;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC;4CAA6B;AAC7B;IAA7C,QAAQ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;6CAA2B;AAkGhE;IADC,OAAO,EAAE;sCAGT","sourcesContent":["import {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n command,\r\n easeOut,\r\n strokeOps,\r\n property,\r\n type Command,\r\n type CommandArgs,\r\n type EasingFunction,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\n\r\nexport interface ChartLineProps extends Node2DProps {\r\n /**\r\n * The series polyline, already mapped into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.\r\n */\r\n points: Vector2[]\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Stroke\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right.\r\n *\r\n * Defaults to **1**, unlike the standalone chart this was ported from: in an\r\n * editor a node's resting state is what the paused editor canvas paints, so a\r\n * chart that only appeared once a command had run would edit blind. {@link\r\n * enter} drives it from 0 regardless of where it rests, so the animation is\r\n * unchanged.\r\n */\r\n progress: number\r\n /**\r\n * Whether this line is drawn at all. `false` hides it outright — the switch\r\n * the chart flips alongside its legend's per-series toggle.\r\n */\r\n enabled: boolean\r\n /**\r\n * A slice of the plot to spotlight, in this node's own pixel space. When set\r\n * to a real box, the stretches of the line *outside* it drop to\r\n * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.\r\n */\r\n spotlight: RegionBox\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: number\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: {@link ChartLineProps.progress} traces the line in\r\n * (animated by {@link enter}) and `enabled` shows or hides it wholesale.\r\n */\r\nexport class ChartLine extends Node2D<ChartLineProps> {\r\n @property({ default: () => [] as Vector2[] }) declare points: Vector2[]\r\n @property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })\r\n declare stroke: Stroke\r\n @property({ default: 1 }) declare progress: number\r\n @property({ default: true }) declare enabled: boolean\r\n @property({ default: () => EMPTY_REGION_BOX }) declare spotlight: RegionBox\r\n @property({ default: SPOTLIGHT_DIM }) declare dimOpacity: number\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n if (!this.enabled) return\r\n const pts = this.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, this.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = this.tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = this.stroke as StrokeResolved[]\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = this.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, this.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n }\r\n\r\n /**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\n private tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n }\r\n\r\n /**\r\n * Trace the line in from its left end to its right over `duration` seconds.\r\n * Drives `progress` `0 → 1`.\r\n *\r\n * A `Command` rather than a generator, so the trace can be *evaluated* at a\r\n * time instead of run to one — which is what lets a scene containing this\r\n * chart be scrubbed in constant time. It no longer needs to prime `progress`\r\n * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces\r\n * by definition rather than by having reset something.\r\n */\r\n @command()\r\n enter(args: CommandArgs<Record<string, never>> & { duration: number }): Command<ChartLineProps> {\r\n return this.enterFrom(0, args.duration, args.easing ?? easeOut())\r\n }\r\n\r\n /**\r\n * The trace, with both ends stated: `progress` runs `from` → `to`.\r\n *\r\n * What {@link LineChart.showSeries} and `hideSeries` are both made of — they\r\n * are the same motion in opposite directions, and expressing them as one thing\r\n * with endpoints is what stops the pair drifting apart.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or after\r\n * the command. A line is drawable for every `t` the trace covers and undrawn\r\n * outside it, which is what makes arriving at a time backwards show what\r\n * arriving forwards does — a flag flipped by a side effect would not.\r\n */\r\n enterFrom(\r\n from: number,\r\n duration: number,\r\n easing: EasingFunction = easeOut(),\r\n to = 1\r\n ): Command<ChartLineProps> {\r\n return this.command<ChartLineProps>(\r\n (t) => {\r\n const progress = from + (to - from) * t\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n },\r\n duration,\r\n easing\r\n )\r\n }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AO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CACvD,CAAA;QAED,6EAA6E;QAC7E,4EAA4E;QAC5E,4EAA4E;QAC5E,KAAK,MAAM,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n strokeOps,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { frameEase } from \"../kit/motion\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\n/**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\nfunction tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: `progress` traces the line in\r\n * (animated by `enter`) and `enabled` shows or hides it wholesale.\r\n */\r\nexport const ChartLine = component2d({\r\n key: \"chartLine\",\r\n state: {\r\n /** The series polyline, already mapped into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x. */\r\n points: fresh<Vector2[]>(() => []),\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right. Defaults to 1, so the paused editor canvas paints the line;\r\n * `enter` drives it from 0 regardless of where it rests.\r\n */\r\n progress: 1,\r\n /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */\r\n enabled: true,\r\n /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */\r\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: SPOTLIGHT_DIM,\r\n },\r\n load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),\r\n commands: {\r\n /**\r\n * Trace the line from `from` to `to` over the command — by default in from\r\n * its left end to its right. `showSeries` and `hideSeries` are the same\r\n * motion in opposite directions, so both are this with their ends stated.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or\r\n * after the command: a line is drawable for every `t` the trace covers and\r\n * undrawn outside it, which is what makes arriving at a time backwards show\r\n * what arriving forwards does.\r\n */\r\n enter: {\r\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\r\n run: (timeline) => {\r\n const { from, to } = timeline.args\r\n const ease = frameEase(timeline)\r\n return timeline.animate((t) => {\r\n const progress = from + (to - from) * ease(t)\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n })\r\n },\r\n },\r\n },\r\n render: (ctx, state) => {\r\n if (!state.enabled) return\r\n const pts = state.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, state.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = state.stroke\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = state.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, state.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n },\r\n})\r\n\r\nexport type ChartLine = NodeOf<typeof ChartLine>\r\n"]}
|
|
@@ -1,28 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved } from "@motionscript/sdk";
|
|
2
2
|
import { type RegionBox } from "./shared.js";
|
|
3
|
-
export interface ChartRegionProps extends Node2DProps {
|
|
4
|
-
/**
|
|
5
|
-
* The highlighted slice, already resolved into this node's local pixel space
|
|
6
|
-
* (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box
|
|
7
|
-
* draws nothing.
|
|
8
|
-
*/
|
|
9
|
-
box: RegionBox;
|
|
10
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
11
|
-
stroke: Stroke;
|
|
12
|
-
/** Wash filling the box, under the series lines. */
|
|
13
|
-
fill: Fill;
|
|
14
|
-
/**
|
|
15
|
-
* Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven
|
|
16
|
-
* by the chart's own `regionReveal`, so the rules and the series' dimming move
|
|
17
|
-
* as one.
|
|
18
|
-
*/
|
|
19
|
-
reveal: number;
|
|
20
|
-
}
|
|
21
3
|
/**
|
|
22
4
|
* The **region call-out** of a {@link LineChart}: a washed rectangle over the
|
|
23
5
|
* plot with a dashed rule down each edge the author actually bounded. Sized and
|
|
24
|
-
* positioned entirely from the pre-mapped
|
|
25
|
-
* than its own
|
|
6
|
+
* positioned entirely from the pre-mapped `box` rather
|
|
7
|
+
* than its own box — the region already carries the plot geometry.
|
|
26
8
|
*
|
|
27
9
|
* It draws only the *marking*; fading the series outside the region is
|
|
28
10
|
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
@@ -32,16 +14,33 @@ export interface ChartRegionProps extends Node2DProps {
|
|
|
32
14
|
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
33
15
|
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
34
16
|
*/
|
|
35
|
-
export declare
|
|
36
|
-
box
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
17
|
+
export declare const ChartRegion: import("@motionscript/sdk").Component<"chartRegion", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
18
|
+
/** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */
|
|
19
|
+
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
20
|
+
/** Dashed rule marking each *bounded* edge of the box. */
|
|
21
|
+
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
22
|
+
/** Wash filling the box, under the series lines. */
|
|
23
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
24
|
+
/** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
|
|
25
|
+
readonly reveal: 0;
|
|
26
|
+
}>, {}, null, _Node2D<import("@motionscript/core").Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
27
|
+
/** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */
|
|
28
|
+
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
29
|
+
/** Dashed rule marking each *bounded* edge of the box. */
|
|
30
|
+
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
31
|
+
/** Wash filling the box, under the series lines. */
|
|
32
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
33
|
+
/** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
|
|
34
|
+
readonly reveal: 0;
|
|
35
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
+
/** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */
|
|
37
|
+
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
38
|
+
/** Dashed rule marking each *bounded* edge of the box. */
|
|
39
|
+
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
40
|
+
/** Wash filling the box, under the series lines. */
|
|
41
|
+
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
42
|
+
/** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
|
|
43
|
+
readonly reveal: 0;
|
|
44
|
+
}>, {}, _Node2D<import("@motionscript/core").Node2DProps>>>>;
|
|
45
|
+
export type ChartRegion = NodeOf<typeof ChartRegion>;
|
|
47
46
|
//# sourceMappingURL=chart-region.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW;IAGpB,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;;IANvI,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;;IANvI,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;4DAwCzI,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Graphics2D, Node2D, fillOps, strokeOps, property, } from "@motionscript/sdk";
|
|
1
|
+
import { Graphics2D, Types, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fresh } from "../kit/entries.js";
|
|
3
|
+
import { loadPaints } from "../kit/paints.js";
|
|
8
4
|
import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
|
|
9
|
-
import { declarePaints } from "@motionscript/sdk/component";
|
|
10
5
|
/**
|
|
11
6
|
* The **region call-out** of a {@link LineChart}: a washed rectangle over the
|
|
12
7
|
* plot with a dashed rule down each edge the author actually bounded. Sized and
|
|
13
|
-
* positioned entirely from the pre-mapped
|
|
14
|
-
* than its own
|
|
8
|
+
* positioned entirely from the pre-mapped `box` rather
|
|
9
|
+
* than its own box — the region already carries the plot geometry.
|
|
15
10
|
*
|
|
16
11
|
* It draws only the *marking*; fading the series outside the region is
|
|
17
12
|
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
@@ -21,20 +16,24 @@ import { declarePaints } from "@motionscript/sdk/component";
|
|
|
21
16
|
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
22
17
|
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
23
18
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
export const ChartRegion = component2d({
|
|
20
|
+
key: "chartRegion",
|
|
21
|
+
state: {
|
|
22
|
+
/** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */
|
|
23
|
+
box: fresh(() => EMPTY_REGION_BOX),
|
|
24
|
+
/** Dashed rule marking each *bounded* edge of the box. */
|
|
25
|
+
stroke: Types.custom(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
26
|
+
/** Wash filling the box, under the series lines. */
|
|
27
|
+
fill: Types.custom(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
28
|
+
/** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
|
|
29
|
+
reveal: 0,
|
|
30
|
+
},
|
|
31
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
32
|
+
render: (ctx, state) => {
|
|
33
|
+
const box = state.box;
|
|
35
34
|
if (!hasRegion(box))
|
|
36
35
|
return;
|
|
37
|
-
const r = Math.max(0, Math.min(1,
|
|
36
|
+
const r = Math.max(0, Math.min(1, state.reveal));
|
|
38
37
|
if (r <= 0)
|
|
39
38
|
return;
|
|
40
39
|
const width = box.right - box.left;
|
|
@@ -42,60 +41,27 @@ export class ChartRegion extends Node2D {
|
|
|
42
41
|
const cx = (box.left + box.right) / 2;
|
|
43
42
|
const cy = (box.bottom + box.top) / 2;
|
|
44
43
|
// Wash first, so the rules sit over their own tint.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ctx.draw(new Graphics2D()
|
|
48
|
-
.rect({ x: cx, y: cy, width, height })
|
|
49
|
-
.fill(this.fill)
|
|
50
|
-
.opacity(r));
|
|
44
|
+
if (state.fill.length > 0) {
|
|
45
|
+
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
|
|
51
46
|
}
|
|
52
47
|
// One rule per bounded edge, growing from the region's centre outward as
|
|
53
48
|
// `reveal` climbs — the same "trace it in" beat as the series lines.
|
|
54
|
-
|
|
55
|
-
if (stroke.length === 0)
|
|
49
|
+
if (state.stroke.length === 0)
|
|
56
50
|
return;
|
|
57
51
|
// One `draw` per rule rather than four line ops under a single paint:
|
|
58
52
|
// shapes chained before a `stroke()` are combined into one surface, and
|
|
59
53
|
// stroking a union of disjoint open paths doesn't paint.
|
|
60
|
-
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(
|
|
54
|
+
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
|
|
61
55
|
if (box.xBounded) {
|
|
62
56
|
const half = (height / 2) * r;
|
|
63
|
-
for (const x of [box.left, box.right])
|
|
64
|
-
rule([
|
|
65
|
-
{ x, y: cy - half },
|
|
66
|
-
{ x, y: cy + half },
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
57
|
+
for (const x of [box.left, box.right])
|
|
58
|
+
rule([{ x, y: cy - half }, { x, y: cy + half }]);
|
|
69
59
|
}
|
|
70
60
|
if (box.yBounded) {
|
|
71
61
|
const half = (width / 2) * r;
|
|
72
|
-
for (const y of [box.bottom, box.top])
|
|
73
|
-
rule([
|
|
74
|
-
{ x: cx - half, y },
|
|
75
|
-
{ x: cx + half, y },
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
62
|
+
for (const y of [box.bottom, box.top])
|
|
63
|
+
rule([{ x: cx - half, y }, { x: cx + half, y }]);
|
|
78
64
|
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
__decorate([
|
|
82
|
-
property({ default: () => EMPTY_REGION_BOX })
|
|
83
|
-
], ChartRegion.prototype, "box", void 0);
|
|
84
|
-
__decorate([
|
|
85
|
-
property({
|
|
86
|
-
default: DEFAULT_CHART_THEME.region.stroke,
|
|
87
|
-
mapper: strokeOps.resolve,
|
|
88
|
-
tween: strokeOps.lerp,
|
|
89
|
-
})
|
|
90
|
-
], ChartRegion.prototype, "stroke", void 0);
|
|
91
|
-
__decorate([
|
|
92
|
-
property({
|
|
93
|
-
default: DEFAULT_CHART_THEME.region.fill,
|
|
94
|
-
mapper: fillOps.resolve,
|
|
95
|
-
tween: fillOps.lerp,
|
|
96
|
-
})
|
|
97
|
-
], ChartRegion.prototype, "fill", void 0);
|
|
98
|
-
__decorate([
|
|
99
|
-
property({ default: 0 })
|
|
100
|
-
], ChartRegion.prototype, "reveal", void 0);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
101
67
|
//# sourceMappingURL=chart-region.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,OAAO,EACP,SAAS,GAQV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACrC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACL,2KAA2K;QAC3K,GAAG,EAAE,KAAK,CAAY,GAAG,EAAE,CAAC,gBAAgB,CAAC;QAC7C,0DAA0D;QAC1D,MAAM,EAAE,KAAK,CAAC,MAAM,CAA2B,mBAAmB,C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AAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QACzF,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n fillOps,\r\n strokeOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport {\r\n DEFAULT_CHART_THEME,\r\n EMPTY_REGION_BOX,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\n/**\r\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\r\n * plot with a dashed rule down each edge the author actually bounded. Sized and\r\n * positioned entirely from the pre-mapped `box` rather\r\n * than its own box — the region already carries the plot geometry.\r\n *\r\n * It draws only the *marking*; fading the series outside the region is\r\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\r\n * the two can't disagree about where the boundary is.\r\n *\r\n * Only bounded edges get a rule: a region given just an `x` range spans the full\r\n * plot height, so its top and bottom edges are the plot's own border, not a data\r\n * bound — drawing dashes there would assert a limit the author didn't set.\r\n */\r\nexport const ChartRegion = component2d({\r\n key: \"chartRegion\",\r\n state: {\r\n /** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */\r\n box: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n /** Dashed rule marking each *bounded* edge of the box. */\r\n stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n /** Wash filling the box, under the series lines. */\r\n fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),\r\n /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */\r\n reveal: 0,\r\n },\r\n load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),\r\n render: (ctx, state) => {\r\n const box = state.box\r\n if (!hasRegion(box)) return\r\n\r\n const r = Math.max(0, Math.min(1, state.reveal))\r\n if (r <= 0) return\r\n\r\n const width = box.right - box.left\r\n const height = box.top - box.bottom\r\n const cx = (box.left + box.right) / 2\r\n const cy = (box.bottom + box.top) / 2\r\n\r\n // Wash first, so the rules sit over their own tint.\r\n if (state.fill.length > 0) {\r\n ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))\r\n }\r\n\r\n // One rule per bounded edge, growing from the region's centre outward as\r\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\r\n if (state.stroke.length === 0) return\r\n\r\n // One `draw` per rule rather than four line ops under a single paint:\r\n // shapes chained before a `stroke()` are combined into one surface, and\r\n // stroking a union of disjoint open paths doesn't paint.\r\n const rule = (points: { x: number; y: number }[]) =>\r\n ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))\r\n\r\n if (box.xBounded) {\r\n const half = (height / 2) * r\r\n for (const x of [box.left, box.right]) rule([{ x, y: cy - half }, { x, y: cy + half }])\r\n }\r\n if (box.yBounded) {\r\n const half = (width / 2) * r\r\n for (const y of [box.bottom, box.top]) rule([{ x: cx - half, y }, { x: cx + half, y }])\r\n }\r\n },\r\n})\r\n\r\nexport type ChartRegion = NodeOf<typeof ChartRegion>\r\n"]}
|