@motionscript/charts 0.1.0 → 0.1.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/README.md +98 -28
- package/dist/bar-chart/bar-chart.d.ts +242 -119
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +231 -260
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +16 -38
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +59 -68
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +60 -91
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +88 -125
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +5 -13
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +2 -9
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +40 -132
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +70 -158
- 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 +8 -17
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +8 -17
- 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 -35
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +80 -42
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +37 -40
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +53 -47
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +16 -59
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +38 -76
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +2 -0
- package/dist/kit/entries.d.ts.map +1 -1
- package/dist/kit/entries.js +2 -0
- package/dist/kit/entries.js.map +1 -1
- package/dist/kit/horizontal-axis.d.ts +77 -0
- package/dist/kit/horizontal-axis.d.ts.map +1 -0
- package/dist/kit/horizontal-axis.js +99 -0
- package/dist/kit/horizontal-axis.js.map +1 -0
- package/dist/kit/motion.d.ts +16 -3
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +15 -1
- package/dist/kit/motion.js.map +1 -1
- package/dist/{pie-chart → kit}/pie-legend.d.ts +14 -29
- package/dist/kit/pie-legend.d.ts.map +1 -0
- package/dist/kit/pie-legend.js +93 -0
- 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 +60 -214
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +91 -291
- 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 +36 -45
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +69 -81
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +107 -40
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +172 -89
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +14 -27
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +13 -28
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/index.d.ts +5 -18
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +3 -16
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +272 -119
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +309 -257
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +73 -130
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +195 -156
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +16 -55
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +44 -111
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +3 -13
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +9 -13
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +3 -15
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -11
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +147 -85
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +65 -86
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +65 -196
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +154 -292
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +78 -172
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +54 -177
- 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 +274 -315
- package/src/bar-chart/category-axis.ts +53 -88
- package/src/bar-chart/chart-bars.ts +108 -205
- package/src/bar-chart/index.ts +8 -19
- package/src/bar-chart/shared.ts +81 -309
- package/src/engine.ts +8 -17
- package/src/index.ts +2 -0
- package/src/kit/cartesian.ts +118 -55
- package/src/kit/chart-canvas.ts +50 -80
- package/src/kit/chart-legend.ts +36 -97
- package/src/kit/entries.ts +4 -1
- package/src/kit/horizontal-axis.ts +114 -0
- package/src/kit/motion.ts +18 -2
- package/src/{pie-chart → kit}/pie-legend.ts +25 -65
- package/src/kit/polar.ts +54 -0
- package/src/kit/shared.ts +104 -487
- package/src/kit/style.ts +257 -0
- package/src/kit/vertical-axis.ts +81 -115
- package/src/line-chart/chart-line.ts +185 -91
- package/src/line-chart/chart-region.ts +14 -31
- package/src/line-chart/index.ts +14 -22
- package/src/line-chart/line-chart.ts +377 -315
- package/src/line-chart/shared.ts +229 -304
- package/src/line-chart/x-scale.ts +44 -121
- package/src/nodes.ts +9 -13
- package/src/pie-chart/index.ts +3 -35
- package/src/pie-chart/pie-chart.ts +83 -134
- package/src/pie-chart/pie-ring.ts +162 -368
- package/src/pie-chart/shared.ts +92 -379
- 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-TJNHLQGV.js +0 -2
- package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
- package/dist/kit/chart-border.d.ts +0 -27
- package/dist/kit/chart-border.d.ts.map +0 -1
- package/dist/kit/chart-border.js +0 -28
- package/dist/kit/chart-border.js.map +0 -1
- package/dist/line-chart/horizontal-axis.d.ts +0 -79
- package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
- package/dist/line-chart/horizontal-axis.js +0 -129
- 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 +0 -117
- package/dist/pie-chart/pie-legend.js.map +0 -1
- package/src/kit/chart-border.ts +0 -50
- package/src/line-chart/horizontal-axis.ts +0 -151
|
@@ -1,86 +1,66 @@
|
|
|
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
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
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;
|
|
15
|
+
}
|
|
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));
|
|
44
33
|
}
|
|
45
34
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* Two signals drive it: `progress` traces the line in
|
|
51
|
-
* (animated by `enter`) and `enabled` shows or hides it wholesale.
|
|
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.
|
|
52
38
|
*/
|
|
53
39
|
export const ChartLine = component2d({
|
|
54
40
|
key: "chartLine",
|
|
55
41
|
state: {
|
|
56
|
-
/**
|
|
42
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
57
43
|
points: fresh(() => []),
|
|
58
|
-
|
|
44
|
+
curve: curveEntry(),
|
|
59
45
|
stroke: Types.custom([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
*/
|
|
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 }),
|
|
49
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
65
50
|
progress: 1,
|
|
66
|
-
/** Whether
|
|
51
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
67
52
|
enabled: true,
|
|
68
|
-
/**
|
|
53
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
69
54
|
spotlight: fresh(() => EMPTY_REGION_BOX),
|
|
70
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
71
55
|
dimOpacity: SPOTLIGHT_DIM,
|
|
72
56
|
},
|
|
73
|
-
load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
|
|
57
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.dotFill], strokes: [state.stroke] }),
|
|
74
58
|
commands: {
|
|
75
59
|
/**
|
|
76
|
-
* Trace the line from `from` to `to`
|
|
77
|
-
*
|
|
78
|
-
*
|
|
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.
|
|
60
|
+
* Trace the line from `from` to `to`; `showSeries`/`hideSeries` are this with
|
|
61
|
+
* the ends stated. `enabled` rides along in the same value, so the line is
|
|
62
|
+
* drawable for every `t` the trace covers and arriving backwards matches
|
|
63
|
+
* arriving forwards.
|
|
84
64
|
*/
|
|
85
65
|
enter: {
|
|
86
66
|
args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
|
|
@@ -89,47 +69,150 @@ export const ChartLine = component2d({
|
|
|
89
69
|
const ease = frameEase(timeline);
|
|
90
70
|
return timeline.animate((t) => {
|
|
91
71
|
const progress = from + (to - from) * ease(t);
|
|
92
|
-
// Hidden only once
|
|
93
|
-
// the empty plot rather than a line that vanished a frame early.
|
|
72
|
+
// Hidden only once fully retraced, so a hide does not vanish a frame early.
|
|
94
73
|
return { progress, enabled: progress > 0 };
|
|
95
74
|
});
|
|
96
75
|
},
|
|
97
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
|
+
},
|
|
98
85
|
},
|
|
99
86
|
render: (ctx, state) => {
|
|
100
87
|
if (!state.enabled)
|
|
101
88
|
return;
|
|
102
89
|
const pts = state.points;
|
|
103
|
-
|
|
90
|
+
const p = clamp(state.progress, 0, 1);
|
|
91
|
+
if (pts.length === 0 || p <= 0)
|
|
104
92
|
return;
|
|
105
|
-
const
|
|
106
|
-
|
|
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)
|
|
107
110
|
return;
|
|
108
|
-
const
|
|
109
|
-
|
|
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)
|
|
110
164
|
return;
|
|
111
|
-
const
|
|
112
|
-
|
|
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);
|
|
113
178
|
const box = state.spotlight;
|
|
114
179
|
if (!hasRegion(box)) {
|
|
115
|
-
|
|
180
|
+
paint(outline, 1);
|
|
116
181
|
return;
|
|
117
182
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
// than one dim + one bright *complementary* pair, so the bright run has
|
|
121
|
-
// continuous geometry through the region and its joins round the way an
|
|
122
|
-
// unspotlit line's do — and so the boundary lands exactly on the region edge.
|
|
123
|
-
ctx.draw(new Graphics2D()
|
|
124
|
-
.line({ points: drawn, radius })
|
|
125
|
-
.stroke(stroke)
|
|
126
|
-
.opacity(Math.max(0, Math.min(1, state.dimOpacity))));
|
|
127
|
-
// One `draw` per run: shapes chained before a `stroke()` are combined into a
|
|
128
|
-
// single surface, and stroking a union of disjoint open paths doesn't paint
|
|
129
|
-
// — so a line that leaves the region and comes back would lose both halves.
|
|
130
|
-
for (const run of clipPolylineToBox(drawn, box)) {
|
|
131
|
-
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
|
|
132
|
-
}
|
|
183
|
+
paint(outline, clamp(state.dimOpacity, 0, 1));
|
|
184
|
+
paint(clipPolygonToBox(outline, box), 1);
|
|
133
185
|
},
|
|
134
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
|
+
}
|
|
135
218
|
//# 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,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,GAOV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GAEV,MAAM,UAAU,CAAA;AAEjB;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAc,EAAE,CAAS;IAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,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,GAAG,KAAK,CAAC,MAAM,CAAA;QAC3B,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA,CAAC,kBAAkB;QAE9D,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAA;QAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;YACzE,OAAM;QACR,CAAC;QAED,wEAAwE;QACxE,6EAA6E;QAC7E,wEAAwE;QACxE,wEAAwE;QACxE,8EAA8E;QAC9E,GAAG,CAAC,IAAI,CACN,IAAI,UAAU,EAAE;aACb,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;aAC/B,MAAM,CAAC,MAAM,CAAC;aACd,OAAO,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 {\n Graphics2D,\n Types,\n component2d,\n strokeOps,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\n type Node2D as _Node2D,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"../kit/entries\"\nimport { frameEase } from \"../kit/motion\"\nimport { loadPaints } from \"../kit/paints\"\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\nimport {\n EMPTY_REGION_BOX,\n clipPolylineToBox,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\n\n/**\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\n * by *cumulative arc length* so the line traces at a steady pace regardless of\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\n * point partway along the active segment.\n */\nfunction tracePoints(pts: Vector2[], p: number): Vector2[] {\n if (p >= 1 || pts.length < 2) return pts\n if (p <= 0) return []\n\n const segLen: number[] = []\n let total = 0\n for (let i = 1; i < pts.length; i++) {\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\n segLen.push(d)\n total += d\n }\n if (total === 0) return pts\n\n let target = total * p\n const out: Vector2[] = [pts[0]]\n for (let i = 0; i < segLen.length; i++) {\n if (target >= segLen[i]) {\n out.push(pts[i + 1])\n target -= segLen[i]\n } else {\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\n out.push({\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\n })\n break\n }\n }\n return out\n}\n\n/**\n * A single series line of a {@link LineChart}: one rounded polyline traced\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\n *\n * Two signals drive it: `progress` traces the line in\n * (animated by `enter`) and `enabled` shows or hides it wholesale.\n */\nexport const ChartLine = component2d({\n key: \"chartLine\",\n state: {\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. */\n points: fresh<Vector2[]>(() => []),\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n /**\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\n * end to its right. Defaults to 1, so the paused editor canvas paints the line;\n * `enter` drives it from 0 regardless of where it rests.\n */\n progress: 1,\n /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */\n enabled: true,\n /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n /** Opacity the out-of-region stretches fade to. */\n dimOpacity: SPOTLIGHT_DIM,\n },\n load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),\n commands: {\n /**\n * Trace the line from `from` to `to` over the command — by default in from\n * its left end to its right. `showSeries` and `hideSeries` are the same\n * motion in opposite directions, so both are this with their ends stated.\n *\n * `enabled` rides along in the same value rather than being set before or\n * after the command: a line is drawable for every `t` the trace covers and\n * undrawn outside it, which is what makes arriving at a time backwards show\n * what arriving forwards does.\n */\n enter: {\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\n run: (timeline) => {\n const { from, to } = timeline.args\n const ease = frameEase(timeline)\n return timeline.animate((t) => {\n const progress = from + (to - from) * ease(t)\n // Hidden only once it has fully retraced, so the last frame of a hide is\n // the empty plot rather than a line that vanished a frame early.\n return { progress, enabled: progress > 0 }\n })\n },\n },\n },\n render: (ctx, state) => {\n if (!state.enabled) return\n const pts = state.points\n if (pts.length < 2) return\n\n const p = Math.max(0, Math.min(1, state.progress))\n if (p <= 0) return\n\n const drawn = tracePoints(pts, p)\n if (drawn.length < 2) return\n const stroke = state.stroke\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\n\n const box = state.spotlight\n if (!hasRegion(box)) {\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\n return\n }\n\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\n // inside the region are re-drawn over it at full strength. Two passes rather\n // than one dim + one bright *complementary* pair, so the bright run has\n // continuous geometry through the region and its joins round the way an\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\n ctx.draw(\n new Graphics2D()\n .line({ points: drawn, radius })\n .stroke(stroke)\n .opacity(Math.max(0, Math.min(1, state.dimOpacity)))\n )\n\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\n // single surface, and stroking a union of disjoint open paths doesn't paint\n // — so a line that leaves the region and comes back would lose both halves.\n for (const run of clipPolylineToBox(drawn, box)) {\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\n }\n },\n})\n\nexport type ChartLine = NodeOf<typeof ChartLine>\n"]}
|
|
1
|
+
{"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,SAAS,GAYV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,KAAK,EACL,WAAW,EACX,SAAS,GAGV,MAAM,UAAU,CAAA;AAEjB,gFAAgF;AAChF,MAAM,UAAU,MAAM,CAAC,MAA0B,EAAE,QAAgB;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAA;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACzB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CA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AAE,IAAmC,EAAE,OAAe,EAAE,KAAW,EAAE,GAAS;IAC3H,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACrC,IAAI,IAAI,KAAK,UAAU,IAAI,GAAG,EAAE,IAAI,KAAK,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC,MAAM,EAAE,OAAO,CAAmB,CAAA;IAC3H,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAA;IAC9B,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACzC,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IACvC,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;QAC/D,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,EAAE;QAC/C,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,IAAI,EAAE;KACjD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {\n Graphics2D,\n Types,\n clamp,\n component2d,\n fillOps,\n strokeOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type PathCommand,\n type RenderContext,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/sdk\"\n\nimport { fade } from \"../kit/cartesian\"\nimport { fresh } from \"../kit/entries\"\nimport { frameEase } from \"../kit/motion\"\nimport { loadPaints } from \"../kit/paints\"\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\nimport {\n EMPTY_REGION_BOX,\n clipPolygonToBox,\n clipPolylineToBox,\n cutAt,\n curvePoints,\n hasRegion,\n type LineCurve,\n type RegionBox,\n} from \"./shared\"\n\n/** The x a trace at `progress` has reached, across `points` ordered along x. */\nexport function traceX(points: readonly Vector2[], progress: number): number {\n if (points.length === 0) return 0\n const first = points[0].x\n const last = points[points.length - 1].x\n return progress >= 1 ? Infinity : first + (last - first) * progress\n}\n\n/** The drawn path at `progress`: the whole curve once traced, else the part left of the trace. */\nfunction traced(points: readonly Vector2[], curve: LineCurve, progress: number): Vector2[] {\n const path = curvePoints(points, curve)\n return progress >= 1 ? path : cutAt(path, traceX(points, progress))\n}\n\nconst curveEntry = () => Types.custom<LineCurve>(\"smooth\")\n\n/** A closed outline as path commands. */\nfunction outlineCommands(points: readonly Vector2[]): PathCommand[] {\n return [...points.map((p, i): PathCommand => ({ type: i === 0 ? \"M\" : \"L\", x: p.x, y: p.y })), { type: \"Z\" }]\n}\n\nfunction fillOutline(ctx: RenderContext, outline: readonly Vector2[], fill: FillResolved[], opacity: number): void {\n if (outline.length < 3 || opacity <= 0) return\n const { width, height } = ctx.size\n // A frame symmetric about the origin, so the outline draws where its points say rather than re-centred on itself.\n const centerBounds: [number, number, number, number] = [-width / 2, -height / 2, width / 2, height / 2]\n ctx.draw(new Graphics2D().path({ data: outlineCommands(outline), centerBounds }).fill(fill).opacity(opacity))\n}\n\n/**\n * One series of a {@link LineChart}: its line through pre-mapped pixel `points`,\n * shaped by `curve`, and a dot on each point. `progress` traces it in from the\n * left; `enabled` shows or hides it wholesale.\n */\nexport const ChartLine = component2d({\n key: \"chartLine\",\n state: {\n /** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */\n points: fresh<Vector2[]>(() => []),\n curve: curveEntry(),\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n /** A dot of `dotSize` on each point, in `dotFill`; none at size 0. */\n dotSize: 0,\n dotFill: Types.custom<Fill, FillResolved[]>([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n /** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */\n progress: 1,\n /** Whether the line is drawn at all, flipped alongside its legend entry. */\n enabled: true,\n /** In this node's pixel space; outside it the line drops to `dimOpacity`. */\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n dimOpacity: SPOTLIGHT_DIM,\n },\n load: (loader, state) => loadPaints(loader, { fills: [state.dotFill], strokes: [state.stroke] }),\n commands: {\n /**\n * Trace the line from `from` to `to`; `showSeries`/`hideSeries` are this with\n * the ends stated. `enabled` rides along in the same value, so the line is\n * drawable for every `t` the trace covers and arriving backwards matches\n * arriving forwards.\n */\n enter: {\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\n run: (timeline) => {\n const { from, to } = timeline.args\n const ease = frameEase(timeline)\n return timeline.animate((t) => {\n const progress = from + (to - from) * ease(t)\n // Hidden only once fully retraced, so a hide does not vanish a frame early.\n return { progress, enabled: progress > 0 }\n })\n },\n },\n /** Hold the line fully traced while its chart moves it, switched on throughout a show and off once a hide lands. */\n hold: {\n args: { shown: Types.boolean(true) },\n run: (timeline) => {\n const { shown } = timeline.args\n return timeline.animate((t) => ({ progress: 1, enabled: shown || t < 1 }), { eased: false })\n },\n },\n },\n render: (ctx, state) => {\n if (!state.enabled) return\n const pts = state.points\n const p = clamp(state.progress, 0, 1)\n if (pts.length === 0 || p <= 0) return\n\n const box = state.spotlight\n const lit = hasRegion(box)\n const dim = clamp(state.dimOpacity, 0, 1)\n const stroke = state.stroke\n const weight = stroke[0]?.weight ?? 0\n const drawn = traced(pts, state.curve, p)\n\n if (drawn.length >= 2 && weight > 0) {\n // Rounded corners only where the line has corners to round.\n const radius = state.curve === \"linear\" ? weight * 2 : 0\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke).opacity(lit ? dim : 1))\n // One `draw` per run: shapes chained before `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.\n if (lit) for (const run of clipPolylineToBox(drawn, box)) ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\n }\n\n const size = state.dotSize\n if (size <= 0) return\n const reach = traceX(pts, p)\n const bright = new Graphics2D()\n const dimmed = new Graphics2D()\n let brightAny = false\n let dimAny = false\n for (const pt of pts) {\n // A dot grows in as the trace passes it.\n const grown = reach === Infinity ? 1 : clamp((reach - pt.x) / (size * 2), 0, 1)\n if (grown <= 0) continue\n const inside = !lit || (pt.x >= box.left && pt.x <= box.right && pt.y >= box.bottom && pt.y <= box.top)\n ;(inside ? bright : dimmed).ellipse({ x: pt.x, y: pt.y, width: size * grown, height: size * grown })\n if (inside) brightAny = true\n else dimAny = true\n }\n if (dimAny) ctx.draw(dimmed.fill(state.dotFill).opacity(dim))\n if (brightAny) ctx.draw(bright.fill(state.dotFill))\n },\n})\n\nexport type ChartLine = NodeOf<typeof ChartLine>\n\n/**\n * The fill under one series of a {@link LineChart}: down to `base` (the series\n * below it in a stack) or, without one, to the `baseline`. Drawn by its own node\n * so every area sits under every line; the chart binds its trace, switch and\n * opacity to its line's, so the two move as one.\n */\nexport const ChartArea = component2d({\n key: \"chartArea\",\n state: {\n /** The series' points, as its line has them. */\n points: fresh<Vector2[]>(() => []),\n /** The line the area fills down to, at the same x positions; empty for the baseline. */\n base: fresh<Vector2[]>(() => []),\n /** Pixel y of the baseline. */\n baseline: 0,\n curve: curveEntry(),\n area: Types.custom<\"none\" | \"solid\" | \"gradient\">(\"solid\"),\n /** The series colour; the area paints it at `areaOpacity`, a gradient fading it out towards the bottom. */\n fill: Types.custom<Fill, FillResolved[]>([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n areaOpacity: 0.4,\n progress: 1,\n enabled: true,\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n dimOpacity: SPOTLIGHT_DIM,\n },\n load: (loader, state) => loadPaints(loader, { fills: [state.fill] }),\n render: (ctx, state) => {\n const pts = state.points\n const p = clamp(state.progress, 0, 1)\n if (!state.enabled || state.area === \"none\" || pts.length < 2 || p <= 0 || state.fill.length === 0) return\n const outlineAt = (progress: number) => {\n const top = traced(pts, state.curve, progress)\n if (top.length < 2) return []\n const base = state.base.length === pts.length\n ? traced(state.base, state.curve, progress)\n : [{ x: top[0].x, y: state.baseline }, { x: top[top.length - 1].x, y: state.baseline }]\n return [...top, ...[...base].reverse()]\n }\n // The gradient spans the whole area's height, so it holds still while the area traces in and across a spotlight's cut.\n const span = verticalSpan(outlineAt(1))\n const paint = (outline: readonly Vector2[], opacity: number) =>\n fillOutline(ctx, outline, areaFill(state.fill, state.area, state.areaOpacity, span, verticalSpan(outline)), opacity)\n const outline = outlineAt(p)\n const box = state.spotlight\n if (!hasRegion(box)) {\n paint(outline, 1)\n return\n }\n paint(outline, clamp(state.dimOpacity, 0, 1))\n paint(clipPolygonToBox(outline, box), 1)\n },\n})\n\ninterface Span {\n readonly top: number\n readonly bottom: number\n}\n\nfunction verticalSpan(points: readonly Vector2[]): Span {\n let top = -Infinity\n let bottom = Infinity\n for (const p of points) {\n if (p.y > top) top = p.y\n if (p.y < bottom) bottom = p.y\n }\n return { top, bottom }\n}\n\n/**\n * The area's paint for an outline spanning `own`: the series colour at\n * `opacity`, or for a gradient that colour fading to nearly nothing across\n * `whole`. A gradient maps onto the bounds of the shape it fills, so its ends\n * are placed in `own`'s unit box (y-up) at `whole`'s top and bottom.\n */\nexport function areaFill(colour: FillResolved[], area: \"none\" | \"solid\" | \"gradient\", opacity: number, whole: Span, own: Span): FillResolved[] {\n const top = colour[colour.length - 1]\n if (area !== \"gradient\" || top?.type !== \"solid\" || !(own.top > own.bottom)) return fade(colour, opacity) as FillResolved[]\n const [r, g, b, a] = top.color\n const middle = (own.top + own.bottom) / 2\n const half = (own.top - own.bottom) / 2\n return fillOps.resolve({\n type: \"linear-gradient\",\n colors: [[r, g, b, a * opacity], [r, g, b, a * opacity * 0.04]],\n start: { x: 0, y: (whole.top - middle) / half },\n end: { x: 0, y: (whole.bottom - middle) / half },\n })\n}\n\nexport type ChartArea = NodeOf<typeof ChartArea>\n"]}
|
|
@@ -1,46 +1,33 @@
|
|
|
1
|
-
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved } from "@motionscript/sdk";
|
|
1
|
+
import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Stroke, type StrokeResolved } from "@motionscript/sdk";
|
|
2
2
|
import { type RegionBox } from "./shared.js";
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* It draws only the *marking*; fading the series outside the region is
|
|
10
|
-
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
11
|
-
* the two can't disagree about where the boundary is.
|
|
12
|
-
*
|
|
13
|
-
* Only bounded edges get a rule: a region given just an `x` range spans the full
|
|
14
|
-
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
15
|
-
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
4
|
+
* The call-out of a {@link LineChart}: a washed rectangle with a dashed rule on
|
|
5
|
+
* each bounded edge, drawn from the pre-mapped `box`. Dimming the series outside
|
|
6
|
+
* is the line's and area's job, clipped against the same box so they agree on
|
|
7
|
+
* the boundary. An unbounded edge is the plot's own border, and a rule there
|
|
8
|
+
* would assert a limit the author did not set.
|
|
16
9
|
*/
|
|
17
10
|
export declare const ChartRegion: import("@motionscript/sdk").Component<"chartRegion", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
18
|
-
/**
|
|
11
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
19
12
|
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
20
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
21
13
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
22
|
-
/** Wash filling the box, under the series lines. */
|
|
23
14
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
24
|
-
/**
|
|
15
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
25
16
|
readonly reveal: 0;
|
|
26
|
-
}>, {}, null, _Node2D<
|
|
27
|
-
/**
|
|
17
|
+
}>, {}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
18
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
28
19
|
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
29
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
30
20
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
31
|
-
/** Wash filling the box, under the series lines. */
|
|
32
21
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
33
|
-
/**
|
|
22
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
34
23
|
readonly reveal: 0;
|
|
35
24
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
36
|
-
/**
|
|
25
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
37
26
|
readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
38
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
39
27
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
40
|
-
/** Wash filling the box, under the series lines. */
|
|
41
28
|
readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
|
|
42
|
-
/**
|
|
29
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
43
30
|
readonly reveal: 0;
|
|
44
|
-
}>, {}, _Node2D<
|
|
31
|
+
}>, {}, _Node2D<_Node2DProps>>>>;
|
|
45
32
|
export type ChartRegion = NodeOf<typeof ChartRegion>;
|
|
46
33
|
//# 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,EAML,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;
|
|
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,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAK1B,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;IAGpB,iHAAiH;;;;IAIjH,8FAA8F;;;IAJ9F,iHAAiH;;;;IAIjH,8FAA8F;;;IAJ9F,iHAAiH;;;;IAIjH,8FAA8F;;gCA+BhG,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import { Graphics2D, Types, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
|
|
2
|
+
import { rule } from "../kit/chart-canvas.js";
|
|
2
3
|
import { fresh } from "../kit/entries.js";
|
|
3
4
|
import { loadPaints } from "../kit/paints.js";
|
|
4
|
-
import {
|
|
5
|
+
import { EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
|
|
5
6
|
/**
|
|
6
|
-
* The
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* It draws only the *marking*; fading the series outside the region is
|
|
12
|
-
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
13
|
-
* the two can't disagree about where the boundary is.
|
|
14
|
-
*
|
|
15
|
-
* Only bounded edges get a rule: a region given just an `x` range spans the full
|
|
16
|
-
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
17
|
-
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
7
|
+
* The call-out of a {@link LineChart}: a washed rectangle with a dashed rule on
|
|
8
|
+
* each bounded edge, drawn from the pre-mapped `box`. Dimming the series outside
|
|
9
|
+
* is the line's and area's job, clipped against the same box so they agree on
|
|
10
|
+
* the boundary. An unbounded edge is the plot's own border, and a rule there
|
|
11
|
+
* would assert a limit the author did not set.
|
|
18
12
|
*/
|
|
19
13
|
export const ChartRegion = component2d({
|
|
20
14
|
key: "chartRegion",
|
|
21
15
|
state: {
|
|
22
|
-
/**
|
|
16
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
23
17
|
box: fresh(() => EMPTY_REGION_BOX),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
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. */
|
|
18
|
+
stroke: Types.custom({ weight: 2, fill: "white/70", dash: [14, 12], cap: "butt", align: "center" }, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
19
|
+
fill: Types.custom("white/6", { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
20
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
29
21
|
reveal: 0,
|
|
30
22
|
},
|
|
31
23
|
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
@@ -40,27 +32,20 @@ export const ChartRegion = component2d({
|
|
|
40
32
|
const height = box.top - box.bottom;
|
|
41
33
|
const cx = (box.left + box.right) / 2;
|
|
42
34
|
const cy = (box.bottom + box.top) / 2;
|
|
43
|
-
// Wash first, so the rules sit over their own tint.
|
|
44
35
|
if (state.fill.length > 0) {
|
|
45
36
|
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
|
|
46
37
|
}
|
|
47
|
-
// One rule per bounded edge, growing from the region's centre outward as
|
|
48
|
-
// `reveal` climbs — the same "trace it in" beat as the series lines.
|
|
49
38
|
if (state.stroke.length === 0)
|
|
50
39
|
return;
|
|
51
|
-
// One `draw` per rule rather than four line ops under a single paint:
|
|
52
|
-
// shapes chained before a `stroke()` are combined into one surface, and
|
|
53
|
-
// stroking a union of disjoint open paths doesn't paint.
|
|
54
|
-
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
|
|
55
40
|
if (box.xBounded) {
|
|
56
41
|
const half = (height / 2) * r;
|
|
57
42
|
for (const x of [box.left, box.right])
|
|
58
|
-
rule(
|
|
43
|
+
rule(ctx, { x, y: cy - half }, { x, y: cy + half }, state.stroke, r);
|
|
59
44
|
}
|
|
60
45
|
if (box.yBounded) {
|
|
61
46
|
const half = (width / 2) * r;
|
|
62
47
|
for (const y of [box.bottom, box.top])
|
|
63
|
-
rule(
|
|
48
|
+
rule(ctx, { x: cx - half, y }, { x: cx + half, y }, state.stroke, r);
|
|
64
49
|
}
|
|
65
50
|
},
|
|
66
51
|
});
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,GASV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EACL,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACrC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACL,iHAAiH;QACjH,GAAG,EAAE,KAAK,CAAY,GAAG,EAAE,CAAC,gBAAgB,CAAC;QAC7C,MAAM,EAAE,KAAK,CAAC,MAAM,CAA2B,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;QACnL,IAAI,EAAE,KAAK,CAAC,MAAM,CAAuB,SAAS,EAA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K,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAC9F,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,OAAM;QAErC,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;YAC7B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC;gBAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;QAC7G,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;YAC5B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;QAC7G,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\n Graphics2D,\n Types,\n component2d,\n fillOps,\n strokeOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { rule } from \"../kit/chart-canvas\"\nimport { fresh } from \"../kit/entries\"\nimport { loadPaints } from \"../kit/paints\"\nimport {\n EMPTY_REGION_BOX,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\n\n/**\n * The call-out of a {@link LineChart}: a washed rectangle with a dashed rule on\n * each bounded edge, drawn from the pre-mapped `box`. Dimming the series outside\n * is the line's and area's job, clipped against the same box so they agree on\n * the boundary. An unbounded edge is the plot's own border, and a rule there\n * would assert a limit the author did not set.\n */\nexport const ChartRegion = component2d({\n key: \"chartRegion\",\n state: {\n /** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */\n box: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n stroke: Types.custom<Stroke, StrokeResolved[]>({ weight: 2, fill: \"white/70\", dash: [14, 12], cap: \"butt\", align: \"center\" }, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n fill: Types.custom<Fill, FillResolved[]>(\"white/6\", { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n /** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */\n reveal: 0,\n },\n load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),\n render: (ctx, state) => {\n const box = state.box\n if (!hasRegion(box)) return\n\n const r = Math.max(0, Math.min(1, state.reveal))\n if (r <= 0) return\n\n const width = box.right - box.left\n const height = box.top - box.bottom\n const cx = (box.left + box.right) / 2\n const cy = (box.bottom + box.top) / 2\n\n if (state.fill.length > 0) {\n ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))\n }\n\n if (state.stroke.length === 0) return\n\n if (box.xBounded) {\n const half = (height / 2) * r\n for (const x of [box.left, box.right]) rule(ctx, { x, y: cy - half }, { x, y: cy + half }, state.stroke, r)\n }\n if (box.yBounded) {\n const half = (width / 2) * r\n for (const y of [box.bottom, box.top]) rule(ctx, { x: cx - half, y }, { x: cx + half, y }, state.stroke, r)\n }\n },\n})\n\nexport type ChartRegion = NodeOf<typeof ChartRegion>\n"]}
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The line chart: a cartesian plot with a traced polyline, spotlit regions and
|
|
3
|
-
* a staggered entrance.
|
|
4
|
-
*
|
|
5
|
-
* {@link LineChart} composes the parts below plus the shared ones in the kit
|
|
6
|
-
* (the plot panel, the value axis, the legend); each part is exported too, so
|
|
7
|
-
* another node type can reuse one on its own.
|
|
8
|
-
*
|
|
9
|
-
* These files are what a copy of the line chart takes (`registry.json`). Everything they reach for
|
|
10
|
-
* that is *not* here comes from the kit and stays a dependency — see
|
|
11
|
-
* `../engine.ts` for why that line is where it is.
|
|
12
|
-
*/
|
|
13
1
|
export { LineChart, lineChartDomains } from "./line-chart.js";
|
|
14
|
-
export type { LineChartDomains,
|
|
2
|
+
export type { LineChartDomains, LineChartStyle, LineChartValues } from "./line-chart.js";
|
|
15
3
|
export { ChartRegion } from "./chart-region.js";
|
|
16
|
-
export { ChartLine } from "./chart-line.js";
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export
|
|
20
|
-
export { formatInstant, parseInstant, resolveXScale } from "./x-scale.js";
|
|
4
|
+
export { ChartArea, ChartLine, areaFill, traceX } from "./chart-line.js";
|
|
5
|
+
export { EMPTY_REGION_BOX, LINE_LABELS, LINE_MARKS, clipPolygonToBox, clipPolylineToBox, curvePoints, cutAt, hasRegion, resolveRegionBox, resolveYScale, seriesPoints, stackExtent, stackSeries, yExtent, } from "./shared.js";
|
|
6
|
+
export type { LineCurve, LineSeries, LineStack, PlotRegion, RegionBox, StackedSeries, } from "./shared.js";
|
|
7
|
+
export { EVERY_SAMPLE, formatInstant, parseInstant, resolveXScale } from "./x-scale.js";
|
|
21
8
|
export type { XScale, XScaleKind } from "./x-scale.js";
|
|
22
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC1D,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrE,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,KAAK,EACL,SAAS,EAET,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,WAAW,EACX,WAAW,EACX,OAAO,GACR,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,GACd,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACpF,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|