@motionscript/charts 0.1.0 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/bar-chart/bar-chart.d.ts +22 -93
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +48 -121
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +11 -38
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +15 -38
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +43 -74
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +31 -59
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -10
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +0 -7
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +27 -90
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +15 -54
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-4SMRCU24.js +2 -0
- package/dist/browser/chunks/chunk-4SMRCU24.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 +4 -16
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +4 -16
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +8 -28
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +7 -19
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-border.d.ts +9 -18
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +4 -9
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +25 -36
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +13 -13
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +14 -61
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +17 -65
- 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/motion.d.ts +11 -3
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +7 -1
- package/dist/kit/motion.js.map +1 -1
- package/dist/kit/shared.d.ts +60 -175
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +40 -157
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +16 -45
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +17 -42
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +16 -41
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +14 -43
- 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 +8 -22
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +16 -43
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +13 -42
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +1 -13
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +0 -12
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +23 -109
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +45 -141
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +33 -107
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +28 -81
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +14 -55
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +29 -111
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -12
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +1 -12
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +0 -9
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +37 -71
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +31 -65
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +11 -26
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +14 -39
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +50 -192
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +75 -247
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +45 -131
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +29 -72
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +51 -165
- package/src/bar-chart/category-axis.ts +16 -57
- package/src/bar-chart/chart-bars.ts +43 -120
- package/src/bar-chart/index.ts +2 -10
- package/src/bar-chart/shared.ts +29 -97
- package/src/engine.ts +4 -16
- package/src/kit/cartesian.ts +11 -26
- package/src/kit/chart-border.ts +6 -20
- package/src/kit/chart-canvas.ts +15 -40
- package/src/kit/chart-legend.ts +17 -86
- package/src/kit/entries.ts +4 -1
- package/src/kit/motion.ts +11 -2
- package/src/kit/shared.ts +58 -219
- package/src/kit/vertical-axis.ts +18 -71
- package/src/line-chart/chart-line.ts +16 -44
- package/src/line-chart/chart-region.ts +10 -23
- package/src/line-chart/horizontal-axis.ts +13 -42
- package/src/line-chart/index.ts +1 -13
- package/src/line-chart/line-chart.ts +50 -184
- package/src/line-chart/shared.ts +51 -145
- package/src/line-chart/x-scale.ts +31 -121
- package/src/nodes.ts +0 -12
- package/src/pie-chart/index.ts +1 -12
- package/src/pie-chart/pie-chart.ts +34 -102
- package/src/pie-chart/pie-legend.ts +14 -55
- package/src/pie-chart/pie-ring.ts +80 -307
- package/src/pie-chart/shared.ts +50 -139
- package/dist/browser/chunks/chunk-TJNHLQGV.js +0 -2
- package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,MAAM,
|
|
1
|
+
{"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,MAAM,EAEX,KAAK,MAAM,EACX,KAAK,WAAW,IAAI,YAAY,EACjC,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,UAAU,CAAA;AACnG,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,UAAU,CAAA;AAIjB,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGrI;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY;;IAIrB,mHAAmH;;IAEnH,0FAA0F;;;IAG1F,8GAA8G;;;;;;;;;;IAL9G,mHAAmH;;IAEnH,0FAA0F;;;IAG1F,8GAA8G;;;;;IAL9G,mHAAmH;;IAEnH,0FAA0F;;;IAG1F,8GAA8G;;;;;;;;0BA2FhH,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Rect, RotatedBox, Text, Types, component2d, insetsOps, textOps, } from "@motionscript/sdk";
|
|
2
|
+
import { enterBudget } from "@motionscript/sdk/component";
|
|
2
3
|
import { asParts, fresh } from "./entries.js";
|
|
3
4
|
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "./motion.js";
|
|
4
|
-
import { DEFAULT_Y_AXIS,
|
|
5
|
-
/** How far a marker starts to the right of its slot when it enters, in px. */
|
|
5
|
+
import { DEFAULT_Y_AXIS, formatMarker, } from "./shared.js";
|
|
6
6
|
const SLIDE = 24;
|
|
7
7
|
/** What a marker's caption reads: the one listed for its value, else its bare reading. */
|
|
8
8
|
export function markerCaption(s, value) {
|
|
@@ -10,54 +10,40 @@ export function markerCaption(s, value) {
|
|
|
10
10
|
return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value);
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* The numeric vertical axis
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* Each marker is positioned so its centre lands exactly on its value's fraction
|
|
19
|
-
* across `range` within the axis's filled height, so unevenly-spaced markers
|
|
20
|
-
* land where their values fall. Both the caption and the position are *bound*,
|
|
21
|
-
* not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
|
|
22
|
-
* tweens `range`/`markers` live. Only the marker **count** is fixed at
|
|
23
|
-
* construction.
|
|
24
|
-
*
|
|
25
|
-
* `enter` staggers them in **bottom-to-top**: each marker starts pushed a
|
|
26
|
-
* little to the right and transparent, then fades and slides left into place.
|
|
27
|
-
* The resting state is the landed one, so a chart that is never told to enter
|
|
28
|
-
* still reads as a finished chart.
|
|
13
|
+
* The numeric vertical axis the cartesian charts share: a column of {@link Text}
|
|
14
|
+
* markers, highest at the top, each centred on its value's fraction across
|
|
15
|
+
* `range`. Caption and position are bound, so a rescale tweens live; only the
|
|
16
|
+
* marker count is fixed at construction. The resting state is landed.
|
|
29
17
|
*/
|
|
30
18
|
export const VerticalAxis = component2d({
|
|
31
19
|
key: "verticalAxis",
|
|
32
20
|
state: {
|
|
33
21
|
range: fresh(() => [0, 1]),
|
|
22
|
+
/** Tick values in data units, each placed by its fraction across `range`; need not be even or include the ends. */
|
|
34
23
|
markers: fresh(() => []),
|
|
24
|
+
/** One caption per marker in its order; a missing one reads as the bare numeric value. */
|
|
35
25
|
captions: fresh(() => []),
|
|
36
26
|
axis: Types.custom(DEFAULT_Y_AXIS),
|
|
27
|
+
/** Rotated caption in the gutter left of the markers; empty builds no caption node and reserves no gutter. */
|
|
37
28
|
label: "",
|
|
38
29
|
arrivals: arrivalsEntry(),
|
|
39
30
|
},
|
|
40
|
-
// A
|
|
31
|
+
// A node made of markers would otherwise hug them.
|
|
41
32
|
defaults: { width: "fill", height: "fill" },
|
|
42
33
|
children: (state) => {
|
|
43
|
-
// Composed from plain entries (range/markers/label), so it's built once here.
|
|
44
34
|
const tickPad = insetsOps.resolve(state.axis.tickPadding).right;
|
|
45
35
|
const titlePad = insetsOps.resolve(state.axis.titlePadding).right;
|
|
46
36
|
const row = [];
|
|
47
|
-
// The row's parent is the axis
|
|
37
|
+
// The row's parent is the axis, whose box the markers are placed in.
|
|
48
38
|
const box = () => row[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
|
|
49
|
-
/** The live tick values, top → bottom (highest first) — re-read every frame. */
|
|
50
39
|
const sorted = () => [...state.markers].sort((a, b) => b - a);
|
|
51
|
-
/** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
|
|
52
40
|
const fracAt = (value) => {
|
|
53
41
|
if (value === undefined)
|
|
54
42
|
return 0;
|
|
55
43
|
const [min, max] = state.range;
|
|
56
44
|
return max <= min ? 0 : (value - min) / (max - min);
|
|
57
45
|
};
|
|
58
|
-
//
|
|
59
|
-
// live list is shorter than the column built for it) renders as empty text
|
|
60
|
-
// rather than repeating its neighbour.
|
|
46
|
+
// A slot with no value (the live list is shorter than the column built) renders empty, not its neighbour.
|
|
61
47
|
const markers = state.markers.map((_, i) => {
|
|
62
48
|
const marker = new Text({
|
|
63
49
|
...textOps.styleProps(state.axis.labelStyle),
|
|
@@ -69,10 +55,7 @@ export const VerticalAxis = component2d({
|
|
|
69
55
|
// Node2D space is y-up, so the fraction runs from the bottom.
|
|
70
56
|
const height = box().height;
|
|
71
57
|
const centred = (fracAt(sorted()[i]) - 0.5) * height;
|
|
72
|
-
// Held inside the
|
|
73
|
-
// headroom is smaller than its marker text is tall, which a theme with
|
|
74
|
-
// much larger markers can arrange. Only the top, because what lies
|
|
75
|
-
// below the axis is the chart's own horizontal axis and legend.
|
|
58
|
+
// Held inside the top edge for a theme whose markers are taller than the headroom; only the top, since the chart's own axis and legend lie below.
|
|
76
59
|
const limit = height / 2 - marker.layoutBounds.height / 2;
|
|
77
60
|
return Math.min(centred, limit);
|
|
78
61
|
},
|
|
@@ -102,16 +85,9 @@ export const VerticalAxis = component2d({
|
|
|
102
85
|
},
|
|
103
86
|
commands: {
|
|
104
87
|
/**
|
|
105
|
-
* Stagger
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* The timeline's duration is the **whole** entrance, not one marker's slide:
|
|
110
|
-
* the stagger and the caption are carved out of it rather than added on top.
|
|
111
|
-
* See {@link enterBudget} for why that distinction matters here.
|
|
112
|
-
*
|
|
113
|
-
* `stagger` is seconds between successive markers (derived when omitted);
|
|
114
|
-
* `slide` is the starting rightward offset in px.
|
|
88
|
+
* Stagger markers in bottom to top, then the caption. The duration is the
|
|
89
|
+
* whole entrance ({@link enterBudget}). `stagger` is seconds between markers
|
|
90
|
+
* (derived when omitted); `slide` is the starting rightward offset in px.
|
|
115
91
|
*/
|
|
116
92
|
enter: {
|
|
117
93
|
args: {
|
|
@@ -129,9 +105,8 @@ export const VerticalAxis = component2d({
|
|
|
129
105
|
return arm;
|
|
130
106
|
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
|
|
131
107
|
const ease = frameEase(timeline);
|
|
132
|
-
//
|
|
108
|
+
// The bottom marker leads, so walk the top-to-bottom column in reverse.
|
|
133
109
|
const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }));
|
|
134
|
-
// Once every marker has landed, the caption slides in from the right.
|
|
135
110
|
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
|
|
136
111
|
return timeline.together([arm, beats(timeline, [...markers, ...label])]);
|
|
137
112
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAA;AACnG,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,UAAU,CAAA;AA2BjB,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAA;AAKhB,0FAA0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,IAAI,KAAK,KAAK,CAAC;oBAAE,OAAO,GAAG,CAAA;gBAC3B,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAA;gBACxF,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;gBAChC,0EAA0E;gBAC1E,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;gBACrI,sEAAsE;gBACtE,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACnI,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\n Rect,\n RotatedBox,\n Text,\n Types,\n component2d,\n insetsOps,\n textOps,\n type NodeOf,\n type Node2D,\n type Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { asParts, fresh } from \"./entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\nimport {\n DEFAULT_Y_AXIS,\n enterBudget,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\n\nexport interface VerticalAxisProps extends Node2DProps {\n /** `[min, max]` of the vertical scale the markers are positioned within. */\n range: Range\n /**\n * Tick values (in data units) to draw up the axis, each placed by its fraction\n * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include\n * the ends.\n */\n markers: number[]\n /**\n * How each marker is captioned, one per entry of `markers` and in its order.\n * Empty (the default), or short, captions a marker with its bare numeric\n * reading; a chart with a number format on this axis writes them through it.\n */\n captions: string[]\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\n axis: AxisConfig\n /**\n * Rotated caption drawn in the gutter to the left of the marker column. Empty\n * string (the default) hides it — no caption node is built and no label gutter\n * is reserved.\n */\n label: string\n}\n\n/** How far a marker starts to the right of its slot when it enters, in px. */\nconst SLIDE = 24\n\n/** How a tick value is captioned — see {@link VerticalAxisProps.captions}. */\nexport type MarkerLabel = (value: number) => string\n\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\n const index = s.markers.indexOf(value)\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\n}\n\n/**\n * The numeric vertical axis shared by the cartesian charts: a **column of\n * {@link Text} nodes**, one per marker value, running top-to-bottom (highest\n * value at the top). Pure layout — no `Graphics` — so the markers are real text\n * nodes the scene can measure, restyle, or animate individually.\n *\n * Each marker is positioned so its centre lands exactly on its value's fraction\n * across `range` within the axis's filled height, so unevenly-spaced markers\n * land where their values fall. Both the caption and the position are *bound*,\n * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)\n * tweens `range`/`markers` live. Only the marker **count** is fixed at\n * construction.\n *\n * `enter` staggers them in **bottom-to-top**: each marker starts pushed a\n * little to the right and transparent, then fades and slides left into place.\n * The resting state is the landed one, so a chart that is never told to enter\n * still reads as a finished chart.\n */\nexport const VerticalAxis = component2d({\n key: \"verticalAxis\",\n state: {\n range: fresh<Range>(() => [0, 1]),\n markers: fresh<number[]>(() => []),\n captions: fresh<string[]>(() => []),\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\n label: \"\",\n arrivals: arrivalsEntry(),\n },\n // A plain node filled its parent; one made of its markers would hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n children: (state) => {\n // Composed from plain entries (range/markers/label), so it's built once here.\n const tickPad = insetsOps.resolve(state.axis.tickPadding).right\n const titlePad = insetsOps.resolve(state.axis.titlePadding).right\n\n const row: Node2D[] = []\n // The row's parent is the axis: its box is what the markers are placed in.\n const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\n const sorted = () => [...state.markers].sort((a, b) => b - a)\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\n const fracAt = (value: number | undefined) => {\n if (value === undefined) return 0\n const [min, max] = state.range\n return max <= min ? 0 : (value - min) / (max - min)\n }\n\n // One text node per marker, ordered top → bottom. A slot with no value (the\n // live list is shorter than the column built for it) renders as empty text\n // rather than repeating its neighbour.\n const markers = state.markers.map((_, i) => {\n const marker: Node2D = new Text({\n ...textOps.styleProps(state.axis.labelStyle),\n text: () => {\n const value = sorted()[i]\n return value === undefined ? \"\" : markerCaption(state, value)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = box().height\n const centred = (fracAt(sorted()[i]) - 0.5) * height\n // Held inside the axis's top edge — the backstop for a chart whose\n // headroom is smaller than its marker text is tall, which a theme with\n // much larger markers can arrange. Only the top, because what lies\n // below the axis is the chart's own horizontal axis and legend.\n const limit = height / 2 - marker.layoutBounds.height / 2\n return Math.min(centred, limit)\n },\n opacity: () => arrivalOf(state.arrivals, i).opacity,\n x: () => arrivalOf(state.arrivals, i).shift,\n })\n return marker\n })\n\n const children: Node2D[] = []\n if (state.label !== \"\") {\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\n children.push(\n new RotatedBox({\n angle: -90,\n width: \"hug\",\n height: \"hug\",\n children: new Text({\n ...textOps.styleProps(state.axis.titleStyle),\n text: state.label,\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\n x: () => arrivalOf(state.arrivals, \"label\").shift,\n }),\n })\n )\n }\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: { right: tickPad }, children: markers }))\n row.push(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n return asParts(row)\n },\n commands: {\n /**\n * Stagger the markers in bottom to top, then slide the caption in from the\n * right after them. Its first frame arms them all: shifted right by `slide`\n * and transparent.\n *\n * The timeline's duration is the **whole** entrance, not one marker's slide:\n * the stagger and the caption are carved out of it rather than added on top.\n * See {@link enterBudget} for why that distinction matters here.\n *\n * `stagger` is seconds between successive markers (derived when omitted);\n * `slide` is the starting rightward offset in px.\n */\n enter: {\n args: {\n stagger: Types.custom<number | undefined>(undefined),\n slide: Types.number(SLIDE),\n },\n run: (timeline, state) => {\n const { stagger, slide } = timeline.args\n const count = state.markers.length\n const captioned = state.label !== \"\"\n const from: Arrival = { opacity: 0, shift: slide }\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\n if (count === 0) return arm\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\n const ease = frameEase(timeline)\n // Bottom marker leads: the column is top → bottom, so walk it in reverse.\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n // Once every marker has landed, the caption slides in from the right.\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\n },\n },\n },\n})\n\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\n"]}
|
|
1
|
+
{"version":3,"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C,CAAC,CAAC,CAAC,EAAE,CAAA;gBACnI,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\n Rect,\n RotatedBox,\n Text,\n Types,\n component2d,\n insetsOps,\n textOps,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D,\n type Node2DProps as _Node2DProps,\n} from \"@motionscript/sdk\"\nimport { enterBudget } from \"@motionscript/sdk/component\"\n\nimport { asParts, fresh } from \"./entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\nimport {\n DEFAULT_Y_AXIS,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\n\nconst SLIDE = 24\n\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\n const index = s.markers.indexOf(value)\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\n}\n\n/**\n * The numeric vertical axis the cartesian charts share: a column of {@link Text}\n * markers, highest at the top, each centred on its value's fraction across\n * `range`. Caption and position are bound, so a rescale tweens live; only the\n * marker count is fixed at construction. The resting state is landed.\n */\nexport const VerticalAxis = component2d({\n key: \"verticalAxis\",\n state: {\n range: fresh<Range>(() => [0, 1]),\n /** Tick values in data units, each placed by its fraction across `range`; need not be even or include the ends. */\n markers: fresh<number[]>(() => []),\n /** One caption per marker in its order; a missing one reads as the bare numeric value. */\n captions: fresh<string[]>(() => []),\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\n /** Rotated caption in the gutter left of the markers; empty builds no caption node and reserves no gutter. */\n label: \"\",\n arrivals: arrivalsEntry(),\n },\n // A node made of markers would otherwise hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n children: (state) => {\n const tickPad = insetsOps.resolve(state.axis.tickPadding).right\n const titlePad = insetsOps.resolve(state.axis.titlePadding).right\n\n const row: Node2D[] = []\n // The row's parent is the axis, whose box the markers are placed in.\n const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }\n const sorted = () => [...state.markers].sort((a, b) => b - a)\n const fracAt = (value: number | undefined) => {\n if (value === undefined) return 0\n const [min, max] = state.range\n return max <= min ? 0 : (value - min) / (max - min)\n }\n\n // A slot with no value (the live list is shorter than the column built) renders empty, not its neighbour.\n const markers = state.markers.map((_, i) => {\n const marker: Node2D = new Text({\n ...textOps.styleProps(state.axis.labelStyle),\n text: () => {\n const value = sorted()[i]\n return value === undefined ? \"\" : markerCaption(state, value)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = box().height\n const centred = (fracAt(sorted()[i]) - 0.5) * height\n // Held inside the top edge for a theme whose markers are taller than the headroom; only the top, since the chart's own axis and legend lie below.\n const limit = height / 2 - marker.layoutBounds.height / 2\n return Math.min(centred, limit)\n },\n opacity: () => arrivalOf(state.arrivals, i).opacity,\n x: () => arrivalOf(state.arrivals, i).shift,\n })\n return marker\n })\n\n const children: Node2D[] = []\n if (state.label !== \"\") {\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\n children.push(\n new RotatedBox({\n angle: -90,\n width: \"hug\",\n height: \"hug\",\n children: new Text({\n ...textOps.styleProps(state.axis.titleStyle),\n text: state.label,\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\n x: () => arrivalOf(state.arrivals, \"label\").shift,\n }),\n })\n )\n }\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: { right: tickPad }, children: markers }))\n row.push(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n return asParts(row)\n },\n commands: {\n /**\n * Stagger markers in bottom to top, then the caption. The duration is the\n * whole entrance ({@link enterBudget}). `stagger` is seconds between markers\n * (derived when omitted); `slide` is the starting rightward offset in px.\n */\n enter: {\n args: {\n stagger: Types.custom<number | undefined>(undefined),\n slide: Types.number(SLIDE),\n },\n run: (timeline, state) => {\n const { stagger, slide } = timeline.args\n const count = state.markers.length\n const captioned = state.label !== \"\"\n const from: Arrival = { opacity: 0, shift: slide }\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\n if (count === 0) return arm\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\n const ease = frameEase(timeline)\n // The bottom marker leads, so walk the top-to-bottom column in reverse.\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\n },\n },\n },\n})\n\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\n"]}
|
|
@@ -1,74 +1,49 @@
|
|
|
1
|
-
import { type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
1
|
+
import { type NodeOf, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
|
|
2
2
|
import { type RegionBox } from "./shared.js";
|
|
3
|
-
/**
|
|
4
|
-
* A single series line of a {@link LineChart}: one rounded polyline traced
|
|
5
|
-
* through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
|
|
6
|
-
* Sized and positioned by the parent, which shares the plot's coordinate frame.
|
|
7
|
-
*
|
|
8
|
-
* Two signals drive it: `progress` traces the line in
|
|
9
|
-
* (animated by `enter`) and `enabled` shows or hides it wholesale.
|
|
10
|
-
*/
|
|
3
|
+
/** One series of a {@link LineChart}: a rounded polyline through pre-mapped pixel `points`, one {@link Graphics2D} command list. `progress` traces it in; `enabled` shows or hides it wholesale. */
|
|
11
4
|
export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
12
|
-
/**
|
|
5
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
13
6
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
14
|
-
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
15
7
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
16
|
-
/**
|
|
17
|
-
* Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
|
|
18
|
-
* end to its right. Defaults to 1, so the paused editor canvas paints the line;
|
|
19
|
-
* `enter` drives it from 0 regardless of where it rests.
|
|
20
|
-
*/
|
|
8
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
21
9
|
readonly progress: 1;
|
|
22
|
-
/** Whether
|
|
10
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
23
11
|
readonly enabled: true;
|
|
24
|
-
/**
|
|
12
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
25
13
|
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
26
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
27
14
|
readonly dimOpacity: 0.2;
|
|
28
15
|
}>, {
|
|
29
16
|
readonly enter: {
|
|
30
17
|
readonly from: import("@motionscript/sdk").Type<number, number, false>;
|
|
31
18
|
readonly to: import("@motionscript/sdk").Type<number, number, false>;
|
|
32
19
|
};
|
|
33
|
-
}, null, _Node2D<
|
|
34
|
-
/**
|
|
20
|
+
}, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
21
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
35
22
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
36
|
-
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
37
23
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
38
|
-
/**
|
|
39
|
-
* Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
|
|
40
|
-
* end to its right. Defaults to 1, so the paused editor canvas paints the line;
|
|
41
|
-
* `enter` drives it from 0 regardless of where it rests.
|
|
42
|
-
*/
|
|
24
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
43
25
|
readonly progress: 1;
|
|
44
|
-
/** Whether
|
|
26
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
45
27
|
readonly enabled: true;
|
|
46
|
-
/**
|
|
28
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
47
29
|
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
48
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
49
30
|
readonly dimOpacity: 0.2;
|
|
50
31
|
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
51
|
-
/**
|
|
32
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
52
33
|
readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
|
|
53
|
-
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
54
34
|
readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
|
|
55
|
-
/**
|
|
56
|
-
* Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
|
|
57
|
-
* end to its right. Defaults to 1, so the paused editor canvas paints the line;
|
|
58
|
-
* `enter` drives it from 0 regardless of where it rests.
|
|
59
|
-
*/
|
|
35
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
60
36
|
readonly progress: 1;
|
|
61
|
-
/** Whether
|
|
37
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
62
38
|
readonly enabled: true;
|
|
63
|
-
/**
|
|
39
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
64
40
|
readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
|
|
65
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
66
41
|
readonly dimOpacity: 0.2;
|
|
67
42
|
}>, {
|
|
68
43
|
readonly enter: {
|
|
69
44
|
readonly from: import("@motionscript/sdk").Type<number, number, false>;
|
|
70
45
|
readonly to: import("@motionscript/sdk").Type<number, number, false>;
|
|
71
46
|
};
|
|
72
|
-
}, _Node2D<
|
|
47
|
+
}, _Node2D<_Node2DProps>>>>;
|
|
73
48
|
export type ChartLine = NodeOf<typeof ChartLine>;
|
|
74
49
|
//# sourceMappingURL=chart-line.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAkCjB,oMAAoM;AACpM,eAAO,MAAM,SAAS;IAGlB,qGAAqG;;;IAGrG,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;;;;;;IAP7E,qGAAqG;;;IAGrG,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;IAP7E,qGAAqG;;;IAGrG,yHAAyH;;IAEzH,4EAA4E;;IAE5E,6EAA6E;;;;;;;;2BAyD/E,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
|
|
@@ -4,12 +4,7 @@ import { frameEase } from "../kit/motion.js";
|
|
|
4
4
|
import { loadPaints } from "../kit/paints.js";
|
|
5
5
|
import { SPOTLIGHT_DIM } from "../kit/shared.js";
|
|
6
6
|
import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
|
|
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
|
-
*/
|
|
7
|
+
/** The prefix of `pts` revealed at fraction `p`, measured by cumulative arc length so the trace keeps a steady pace over uneven spacing. */
|
|
13
8
|
function tracePoints(pts, p) {
|
|
14
9
|
if (p >= 1 || pts.length < 2)
|
|
15
10
|
return pts;
|
|
@@ -42,45 +37,28 @@ function tracePoints(pts, p) {
|
|
|
42
37
|
}
|
|
43
38
|
return out;
|
|
44
39
|
}
|
|
45
|
-
/**
|
|
46
|
-
* A single series line of a {@link LineChart}: one rounded polyline traced
|
|
47
|
-
* through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
|
|
48
|
-
* Sized and positioned by the parent, which shares the plot's coordinate frame.
|
|
49
|
-
*
|
|
50
|
-
* Two signals drive it: `progress` traces the line in
|
|
51
|
-
* (animated by `enter`) and `enabled` shows or hides it wholesale.
|
|
52
|
-
*/
|
|
40
|
+
/** One series of a {@link LineChart}: a rounded polyline through pre-mapped pixel `points`, one {@link Graphics2D} command list. `progress` traces it in; `enabled` shows or hides it wholesale. */
|
|
53
41
|
export const ChartLine = component2d({
|
|
54
42
|
key: "chartLine",
|
|
55
43
|
state: {
|
|
56
|
-
/**
|
|
44
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
57
45
|
points: fresh(() => []),
|
|
58
|
-
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
59
46
|
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
|
-
*/
|
|
47
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
65
48
|
progress: 1,
|
|
66
|
-
/** Whether
|
|
49
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
67
50
|
enabled: true,
|
|
68
|
-
/**
|
|
51
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
69
52
|
spotlight: fresh(() => EMPTY_REGION_BOX),
|
|
70
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
71
53
|
dimOpacity: SPOTLIGHT_DIM,
|
|
72
54
|
},
|
|
73
55
|
load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
|
|
74
56
|
commands: {
|
|
75
57
|
/**
|
|
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.
|
|
58
|
+
* Trace the line from `from` to `to`; `showSeries`/`hideSeries` are this with
|
|
59
|
+
* the ends stated. `enabled` rides along in the same value, so the line is
|
|
60
|
+
* drawable for every `t` the trace covers and arriving backwards matches
|
|
61
|
+
* arriving forwards.
|
|
84
62
|
*/
|
|
85
63
|
enter: {
|
|
86
64
|
args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
|
|
@@ -89,8 +67,7 @@ export const ChartLine = component2d({
|
|
|
89
67
|
const ease = frameEase(timeline);
|
|
90
68
|
return timeline.animate((t) => {
|
|
91
69
|
const progress = from + (to - from) * ease(t);
|
|
92
|
-
// Hidden only once
|
|
93
|
-
// the empty plot rather than a line that vanished a frame early.
|
|
70
|
+
// Hidden only once fully retraced, so a hide does not vanish a frame early.
|
|
94
71
|
return { progress, enabled: progress > 0 };
|
|
95
72
|
});
|
|
96
73
|
},
|
|
@@ -109,24 +86,18 @@ export const ChartLine = component2d({
|
|
|
109
86
|
if (drawn.length < 2)
|
|
110
87
|
return;
|
|
111
88
|
const stroke = state.stroke;
|
|
112
|
-
const radius = (stroke[0]?.weight ?? 0) * 2;
|
|
89
|
+
const radius = (stroke[0]?.weight ?? 0) * 2;
|
|
113
90
|
const box = state.spotlight;
|
|
114
91
|
if (!hasRegion(box)) {
|
|
115
92
|
ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
|
|
116
93
|
return;
|
|
117
94
|
}
|
|
118
|
-
//
|
|
119
|
-
// inside the region are re-drawn over it at full strength. Two passes rather
|
|
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.
|
|
95
|
+
// Dim the whole line, then redraw the stretches inside the region at full strength: the bright run keeps continuous geometry and round joins, and the boundary lands on the region edge.
|
|
123
96
|
ctx.draw(new Graphics2D()
|
|
124
97
|
.line({ points: drawn, radius })
|
|
125
98
|
.stroke(stroke)
|
|
126
99
|
.opacity(Math.max(0, Math.min(1, state.dimOpacity))));
|
|
127
|
-
// One `draw` per run: shapes chained before
|
|
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.
|
|
100
|
+
// One `draw` per run: shapes chained before `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.
|
|
130
101
|
for (const run of clipPolylineToBox(drawn, box)) {
|
|
131
102
|
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
|
|
132
103
|
}
|
|
@@ -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,CAAC;QAAE,OAAO,GAAG,CAAA;IACxC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAErB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,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,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,WAAW,EACX,SAAS,GAQV,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,4IAA4I;AAC5I,SAAS,WAAW,CAAC,GAAc,EAAE,CAAS;IAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IACxC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAErB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CA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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,6IAA6I;QAC7I,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` 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 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/** The prefix of `pts` revealed at fraction `p`, measured by cumulative arc length so the trace keeps a steady pace over uneven spacing. */\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/** One series of a {@link LineChart}: a rounded polyline through pre-mapped pixel `points`, one {@link Graphics2D} command list. `progress` traces it in; `enabled` shows or hides it wholesale. */\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 stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.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, { 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 },\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\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 // Dim the whole line, then redraw the stretches inside the region at full strength: the bright run keeps continuous geometry and round joins, and the boundary lands 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 `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.\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,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 {@link ChartLine}'s job, clipped against the same box so the two 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;AAI1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB
|
|
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;AAI1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;IAGpB,iHAAiH;;;;IAIjH,8FAA8F;;;IAJ9F,iHAAiH;;;;IAIjH,8FAA8F;;;IAJ9F,iHAAiH;;;;IAIjH,8FAA8F;;gCAmChG,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
|
@@ -3,29 +3,20 @@ import { fresh } from "../kit/entries.js";
|
|
|
3
3
|
import { loadPaints } from "../kit/paints.js";
|
|
4
4
|
import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
|
|
5
5
|
/**
|
|
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.
|
|
6
|
+
* The call-out of a {@link LineChart}: a washed rectangle with a dashed rule on
|
|
7
|
+
* each bounded edge, drawn from the pre-mapped `box`. Dimming the series outside
|
|
8
|
+
* is {@link ChartLine}'s job, clipped against the same box so the two agree on
|
|
9
|
+
* the boundary. An unbounded edge is the plot's own border, and a rule there
|
|
10
|
+
* would assert a limit the author did not set.
|
|
18
11
|
*/
|
|
19
12
|
export const ChartRegion = component2d({
|
|
20
13
|
key: "chartRegion",
|
|
21
14
|
state: {
|
|
22
|
-
/**
|
|
15
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
23
16
|
box: fresh(() => EMPTY_REGION_BOX),
|
|
24
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
25
17
|
stroke: Types.custom(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
26
|
-
/** Wash filling the box, under the series lines. */
|
|
27
18
|
fill: Types.custom(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
28
|
-
/**
|
|
19
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
29
20
|
reveal: 0,
|
|
30
21
|
},
|
|
31
22
|
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
@@ -40,17 +31,12 @@ export const ChartRegion = component2d({
|
|
|
40
31
|
const height = box.top - box.bottom;
|
|
41
32
|
const cx = (box.left + box.right) / 2;
|
|
42
33
|
const cy = (box.bottom + box.top) / 2;
|
|
43
|
-
// Wash first, so the rules sit over their own tint.
|
|
44
34
|
if (state.fill.length > 0) {
|
|
45
35
|
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
|
|
46
36
|
}
|
|
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
37
|
if (state.stroke.length === 0)
|
|
50
38
|
return;
|
|
51
|
-
// One `draw` per rule
|
|
52
|
-
// shapes chained before a `stroke()` are combined into one surface, and
|
|
53
|
-
// stroking a union of disjoint open paths doesn't paint.
|
|
39
|
+
// One `draw` per rule: stroking a union of disjoint open paths paints nothing.
|
|
54
40
|
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
|
|
55
41
|
if (box.xBounded) {
|
|
56
42
|
const half = (height / 2) * r;
|