@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.10
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 +105 -0
- package/NOTICE +49 -0
- package/README.md +99 -0
- package/dist/bar-chart/bar-chart.d.ts +133 -228
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +386 -565
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +35 -41
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +93 -115
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +50 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +155 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +7 -7
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +7 -7
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
- package/dist/browser/chunks/chunk-TJNHLQGV.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 +4 -3
- package/dist/engine.d.ts +10 -8
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +10 -8
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +44 -0
- package/dist/kit/cartesian.d.ts.map +1 -0
- package/dist/kit/cartesian.js +59 -0
- package/dist/kit/cartesian.js.map +1 -0
- package/dist/kit/chart-border.d.ts +10 -11
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +15 -32
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +32 -21
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +33 -90
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +123 -85
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +137 -186
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +17 -0
- package/dist/kit/entries.d.ts.map +1 -0
- package/dist/kit/entries.js +19 -0
- package/dist/kit/entries.js.map +1 -0
- package/dist/kit/motion.d.ts +48 -0
- package/dist/kit/motion.d.ts.map +1 -0
- package/dist/kit/motion.js +63 -0
- package/dist/kit/motion.js.map +1 -0
- package/dist/kit/paints.d.ts +10 -0
- package/dist/kit/paints.d.ts.map +1 -0
- package/dist/kit/paints.js +12 -0
- package/dist/kit/paints.js.map +1 -0
- package/dist/kit/shared.d.ts +61 -10
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +108 -13
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +48 -61
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +97 -132
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +60 -77
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +100 -121
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +32 -33
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +31 -65
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +58 -64
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +94 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +3 -3
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +2 -2
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +156 -303
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +410 -638
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +7 -7
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +23 -8
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +4 -11
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +16 -5
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +6 -9
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +7 -9
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +2 -2
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +108 -126
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +202 -271
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +84 -31
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +93 -107
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +160 -122
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -361
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +12 -6
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +14 -8
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +7 -4
- package/src/bar-chart/bar-chart.ts +424 -686
- package/src/bar-chart/category-axis.ts +96 -111
- package/src/bar-chart/chart-bars.ts +178 -201
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +7 -7
- package/src/engine.ts +10 -8
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +23 -34
- package/src/kit/chart-canvas.ts +45 -80
- package/src/kit/chart-legend.ts +185 -206
- package/src/kit/entries.ts +20 -0
- package/src/kit/motion.ts +90 -0
- package/src/kit/paints.ts +15 -0
- package/src/kit/shared.ts +120 -13
- package/src/kit/vertical-axis.ts +111 -141
- package/src/line-chart/chart-line.ts +103 -155
- package/src/line-chart/chart-region.ts +36 -81
- package/src/line-chart/horizontal-axis.ts +102 -153
- package/src/line-chart/index.ts +3 -3
- package/src/line-chart/line-chart.ts +463 -759
- package/src/line-chart/shared.ts +22 -8
- package/src/line-chart/x-scale.ts +20 -5
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +225 -303
- package/src/pie-chart/pie-legend.ts +125 -115
- package/src/pie-chart/pie-ring.ts +388 -443
- package/src/pie-chart/shared.ts +14 -8
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type NodeOf, type Node2D, type Node2DProps } from "@motionscript/sdk";
|
|
2
|
+
import { type Arrival } from "./motion.js";
|
|
2
3
|
import { type AxisConfig, type Range } from "./shared.js";
|
|
3
|
-
import { type Seekable } from "@motionscript/core/component";
|
|
4
4
|
export interface VerticalAxisProps extends Node2DProps {
|
|
5
5
|
/** `[min, max]` of the vertical scale the markers are positioned within. */
|
|
6
6
|
range: Range;
|
|
@@ -10,6 +10,12 @@ export interface VerticalAxisProps extends Node2DProps {
|
|
|
10
10
|
* the ends.
|
|
11
11
|
*/
|
|
12
12
|
markers: number[];
|
|
13
|
+
/**
|
|
14
|
+
* How each marker is captioned, one per entry of `markers` and in its order.
|
|
15
|
+
* Empty (the default), or short, captions a marker with its bare numeric
|
|
16
|
+
* reading; a chart with a number format on this axis writes them through it.
|
|
17
|
+
*/
|
|
18
|
+
captions: string[];
|
|
13
19
|
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
14
20
|
axis: AxisConfig;
|
|
15
21
|
/**
|
|
@@ -19,8 +25,13 @@ export interface VerticalAxisProps extends Node2DProps {
|
|
|
19
25
|
*/
|
|
20
26
|
label: string;
|
|
21
27
|
}
|
|
22
|
-
/** How a tick value is captioned — see {@link
|
|
28
|
+
/** How a tick value is captioned — see {@link VerticalAxisProps.captions}. */
|
|
23
29
|
export type MarkerLabel = (value: number) => string;
|
|
30
|
+
/** What a marker's caption reads: the one listed for its value, else its bare reading. */
|
|
31
|
+
export declare function markerCaption(s: {
|
|
32
|
+
readonly markers: readonly number[];
|
|
33
|
+
readonly captions: readonly string[];
|
|
34
|
+
}, value: number): string;
|
|
24
35
|
/**
|
|
25
36
|
* The numeric vertical axis shared by the cartesian charts: a **column of
|
|
26
37
|
* {@link Text} nodes**, one per marker value, running top-to-bottom (highest
|
|
@@ -34,66 +45,42 @@ export type MarkerLabel = (value: number) => string;
|
|
|
34
45
|
* tweens `range`/`markers` live. Only the marker **count** is fixed at
|
|
35
46
|
* construction.
|
|
36
47
|
*
|
|
37
|
-
*
|
|
48
|
+
* `enter` staggers them in **bottom-to-top**: each marker starts pushed a
|
|
38
49
|
* little to the right and transparent, then fades and slides left into place.
|
|
39
50
|
* The resting state is the landed one, so a chart that is never told to enter
|
|
40
51
|
* still reads as a finished chart.
|
|
41
52
|
*/
|
|
42
|
-
export declare
|
|
43
|
-
range: Range
|
|
44
|
-
markers: number[]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*/
|
|
76
|
-
arm(slide?: number): void;
|
|
77
|
-
/**
|
|
78
|
-
* Stagger the markers in bottom to top, then slide the caption in from the
|
|
79
|
-
* right after them.
|
|
80
|
-
*
|
|
81
|
-
* A {@link Seekable} rather than a generator — see the note on the horizontal
|
|
82
|
-
* axis's `enter`. The offsets were always static; expressing them as `wait`
|
|
83
|
-
* inside a generator is what made them reachable only by running it.
|
|
84
|
-
*
|
|
85
|
-
* `args.duration` is the **whole** entrance, not one marker's slide: the
|
|
86
|
-
* stagger and the caption are carved out of it rather than added on top. See
|
|
87
|
-
* {@link enterBudget} for why that distinction matters here.
|
|
88
|
-
*
|
|
89
|
-
* `args.data.stagger` is seconds between successive markers (derived when
|
|
90
|
-
* omitted); `args.data.slide` is the starting rightward offset in px.
|
|
91
|
-
*/
|
|
92
|
-
enter(args: CommandArgs<{
|
|
93
|
-
stagger?: number;
|
|
94
|
-
slide?: number;
|
|
95
|
-
}> & {
|
|
96
|
-
duration: number;
|
|
97
|
-
}): Seekable;
|
|
98
|
-
}
|
|
53
|
+
export declare const VerticalAxis: import("@motionscript/sdk").Component<"verticalAxis", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
54
|
+
readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
|
|
55
|
+
readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
56
|
+
readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
57
|
+
readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
|
|
58
|
+
readonly label: "";
|
|
59
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
60
|
+
}>, {
|
|
61
|
+
readonly enter: {
|
|
62
|
+
readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
63
|
+
readonly slide: import("@motionscript/sdk").Type<number, number, false>;
|
|
64
|
+
};
|
|
65
|
+
}, null, Node2D<Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
66
|
+
readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
|
|
67
|
+
readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
68
|
+
readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
69
|
+
readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
|
|
70
|
+
readonly label: "";
|
|
71
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
72
|
+
}>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
73
|
+
readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
|
|
74
|
+
readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
75
|
+
readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
76
|
+
readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
|
|
77
|
+
readonly label: "";
|
|
78
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
79
|
+
}>, {
|
|
80
|
+
readonly enter: {
|
|
81
|
+
readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
82
|
+
readonly slide: import("@motionscript/sdk").Type<number, number, false>;
|
|
83
|
+
};
|
|
84
|
+
}, Node2D<Node2DProps>>>>;
|
|
85
|
+
export type VerticalAxis = NodeOf<typeof VerticalAxis>;
|
|
99
86
|
//# sourceMappingURL=vertical-axis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,UAAU,CAAA;AACnG,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,4EAA4E;IAC5E,KAAK,EAAE,KAAK,CAAA;IACZ;;;;OAIG;IACH,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,oFAAoF;IACpF,IAAI,EAAE,UAAU,CAAA;IAChB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAKD,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAEnD,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;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAiHvB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { command, Node2D, Rect, RotatedBox, Text, easeOut, property, insetsOps, textOps, } from "@motionscript/core";
|
|
1
|
+
import { Rect, RotatedBox, Text, Types, component2d, insetsOps, textOps, } from "@motionscript/sdk";
|
|
2
|
+
import { asParts, fresh } from "./entries.js";
|
|
3
|
+
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "./motion.js";
|
|
8
4
|
import { DEFAULT_Y_AXIS, enterBudget, formatMarker, } from "./shared.js";
|
|
9
|
-
import { at, compose } from "@motionscript/core/component";
|
|
10
5
|
/** How far a marker starts to the right of its slot when it enters, in px. */
|
|
11
6
|
const SLIDE = 24;
|
|
7
|
+
/** What a marker's caption reads: the one listed for its value, else its bare reading. */
|
|
8
|
+
export function markerCaption(s, value) {
|
|
9
|
+
const index = s.markers.indexOf(value);
|
|
10
|
+
return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value);
|
|
11
|
+
}
|
|
12
12
|
/**
|
|
13
13
|
* The numeric vertical axis shared by the cartesian charts: a **column of
|
|
14
14
|
* {@link Text} nodes**, one per marker value, running top-to-bottom (highest
|
|
@@ -22,62 +22,53 @@ const SLIDE = 24;
|
|
|
22
22
|
* tweens `range`/`markers` live. Only the marker **count** is fixed at
|
|
23
23
|
* construction.
|
|
24
24
|
*
|
|
25
|
-
*
|
|
25
|
+
* `enter` staggers them in **bottom-to-top**: each marker starts pushed a
|
|
26
26
|
* little to the right and transparent, then fades and slides left into place.
|
|
27
27
|
* The resting state is the landed one, so a chart that is never told to enter
|
|
28
28
|
* still reads as a finished chart.
|
|
29
29
|
*/
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
return max <= min ? 0 : (v - min) / (max - min);
|
|
63
|
-
}
|
|
64
|
-
constructor(props) {
|
|
65
|
-
super(props);
|
|
66
|
-
// Composed from plain props (range/markers/label) — no context needed, so
|
|
67
|
-
// it's built here. super() applied the props, so the reads below resolve.
|
|
68
|
-
const tickPad = insetsOps.resolve(this.axis.tickPadding).right;
|
|
69
|
-
const titlePad = insetsOps.resolve(this.axis.titlePadding).right;
|
|
70
|
-
this.markerNodes = this.markers.map((_, i) => {
|
|
30
|
+
export const VerticalAxis = component2d({
|
|
31
|
+
key: "verticalAxis",
|
|
32
|
+
state: {
|
|
33
|
+
range: fresh(() => [0, 1]),
|
|
34
|
+
markers: fresh(() => []),
|
|
35
|
+
captions: fresh(() => []),
|
|
36
|
+
axis: Types.custom(DEFAULT_Y_AXIS),
|
|
37
|
+
label: "",
|
|
38
|
+
arrivals: arrivalsEntry(),
|
|
39
|
+
},
|
|
40
|
+
// A plain node filled its parent; one made of its markers would hug them.
|
|
41
|
+
defaults: { width: "fill", height: "fill" },
|
|
42
|
+
children: (state) => {
|
|
43
|
+
// Composed from plain entries (range/markers/label), so it's built once here.
|
|
44
|
+
const tickPad = insetsOps.resolve(state.axis.tickPadding).right;
|
|
45
|
+
const titlePad = insetsOps.resolve(state.axis.titlePadding).right;
|
|
46
|
+
const row = [];
|
|
47
|
+
// The row's parent is the axis: its box is what the markers are placed in.
|
|
48
|
+
const box = () => row[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
|
|
49
|
+
/** The live tick values, top → bottom (highest first) — re-read every frame. */
|
|
50
|
+
const sorted = () => [...state.markers].sort((a, b) => b - a);
|
|
51
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
|
|
52
|
+
const fracAt = (value) => {
|
|
53
|
+
if (value === undefined)
|
|
54
|
+
return 0;
|
|
55
|
+
const [min, max] = state.range;
|
|
56
|
+
return max <= min ? 0 : (value - min) / (max - min);
|
|
57
|
+
};
|
|
58
|
+
// One text node per marker, ordered top → bottom. A slot with no value (the
|
|
59
|
+
// live list is shorter than the column built for it) renders as empty text
|
|
60
|
+
// rather than repeating its neighbour.
|
|
61
|
+
const markers = state.markers.map((_, i) => {
|
|
71
62
|
const marker = new Text({
|
|
72
|
-
...textOps.styleProps(
|
|
63
|
+
...textOps.styleProps(state.axis.labelStyle),
|
|
73
64
|
text: () => {
|
|
74
|
-
const
|
|
75
|
-
return
|
|
65
|
+
const value = sorted()[i];
|
|
66
|
+
return value === undefined ? "" : markerCaption(state, value);
|
|
76
67
|
},
|
|
77
68
|
y: () => {
|
|
78
69
|
// Node2D space is y-up, so the fraction runs from the bottom.
|
|
79
|
-
const height =
|
|
80
|
-
const centred = (
|
|
70
|
+
const height = box().height;
|
|
71
|
+
const centred = (fracAt(sorted()[i]) - 0.5) * height;
|
|
81
72
|
// Held inside the axis's top edge — the backstop for a chart whose
|
|
82
73
|
// headroom is smaller than its marker text is tall, which a theme with
|
|
83
74
|
// much larger markers can arrange. Only the top, because what lies
|
|
@@ -85,92 +76,66 @@ export class VerticalAxis extends Node2D {
|
|
|
85
76
|
const limit = height / 2 - marker.layoutBounds.height / 2;
|
|
86
77
|
return Math.min(centred, limit);
|
|
87
78
|
},
|
|
79
|
+
opacity: () => arrivalOf(state.arrivals, i).opacity,
|
|
80
|
+
x: () => arrivalOf(state.arrivals, i).shift,
|
|
88
81
|
});
|
|
89
82
|
return marker;
|
|
90
83
|
});
|
|
91
84
|
const children = [];
|
|
92
|
-
if (
|
|
93
|
-
this.labelNode = new Text({
|
|
94
|
-
...textOps.styleProps(this.axis.titleStyle),
|
|
95
|
-
text: this.label,
|
|
96
|
-
});
|
|
85
|
+
if (state.label !== "") {
|
|
97
86
|
// Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
|
|
98
87
|
children.push(new RotatedBox({
|
|
99
88
|
angle: -90,
|
|
100
89
|
width: "hug",
|
|
101
90
|
height: "hug",
|
|
102
|
-
children:
|
|
91
|
+
children: new Text({
|
|
92
|
+
...textOps.styleProps(state.axis.titleStyle),
|
|
93
|
+
text: state.label,
|
|
94
|
+
opacity: () => arrivalOf(state.arrivals, "label").opacity,
|
|
95
|
+
x: () => arrivalOf(state.arrivals, "label").shift,
|
|
96
|
+
}),
|
|
103
97
|
}));
|
|
104
98
|
}
|
|
105
|
-
children.push(new Rect({
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const markers = nodes.map((node, i) => {
|
|
148
|
-
const order = nodes.length - 1 - i; // bottom-most = 0
|
|
149
|
-
return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }));
|
|
150
|
-
});
|
|
151
|
-
const lastMarkerEnds = (nodes.length - 1) * step + per;
|
|
152
|
-
// Once every marker has landed, the caption slides in from the right.
|
|
153
|
-
return compose([
|
|
154
|
-
...markers,
|
|
155
|
-
...(this.labelNode
|
|
156
|
-
? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]
|
|
157
|
-
: []),
|
|
158
|
-
]);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
__decorate([
|
|
162
|
-
property({ default: () => [0, 1] })
|
|
163
|
-
], VerticalAxis.prototype, "range", void 0);
|
|
164
|
-
__decorate([
|
|
165
|
-
property({ default: () => [] })
|
|
166
|
-
], VerticalAxis.prototype, "markers", void 0);
|
|
167
|
-
__decorate([
|
|
168
|
-
property({ default: DEFAULT_Y_AXIS })
|
|
169
|
-
], VerticalAxis.prototype, "axis", void 0);
|
|
170
|
-
__decorate([
|
|
171
|
-
property({ default: "" })
|
|
172
|
-
], VerticalAxis.prototype, "label", void 0);
|
|
173
|
-
__decorate([
|
|
174
|
-
command()
|
|
175
|
-
], VerticalAxis.prototype, "enter", null);
|
|
99
|
+
children.push(new Rect({ height: "fill", width: "hug", padding: { right: tickPad }, children: markers }));
|
|
100
|
+
row.push(new Rect({ flow: "horizontal", gap: titlePad, children }));
|
|
101
|
+
return asParts(row);
|
|
102
|
+
},
|
|
103
|
+
commands: {
|
|
104
|
+
/**
|
|
105
|
+
* Stagger the markers in bottom to top, then slide the caption in from the
|
|
106
|
+
* right after them. Its first frame arms them all: shifted right by `slide`
|
|
107
|
+
* and transparent.
|
|
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.
|
|
115
|
+
*/
|
|
116
|
+
enter: {
|
|
117
|
+
args: {
|
|
118
|
+
stagger: Types.custom(undefined),
|
|
119
|
+
slide: Types.number(SLIDE),
|
|
120
|
+
},
|
|
121
|
+
run: (timeline, state) => {
|
|
122
|
+
const { stagger, slide } = timeline.args;
|
|
123
|
+
const count = state.markers.length;
|
|
124
|
+
const captioned = state.label !== "";
|
|
125
|
+
const from = { opacity: 0, shift: slide };
|
|
126
|
+
const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])];
|
|
127
|
+
const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));
|
|
128
|
+
if (count === 0)
|
|
129
|
+
return arm;
|
|
130
|
+
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
|
|
131
|
+
const ease = frameEase(timeline);
|
|
132
|
+
// Bottom marker leads: the column is top → bottom, so walk it in reverse.
|
|
133
|
+
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
|
+
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
|
|
136
|
+
return timeline.together([arm, beats(timeline, [...markers, ...label])]);
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
176
141
|
//# sourceMappingURL=vertical-axis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,GAIR,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB,MAAM,8BAA8B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AqB;AACb;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA0B;AACvB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;0CAAyB;AAC5B;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;2CAAsB;AA2HhD;IADC,OAAO,EAAE;yCA6BT","sourcesContent":["import {\n command,\n Node2D,\n Rect,\n RotatedBox,\n Text,\n easeOut,\n property,\n insetsOps,\n textOps,\n type CommandArgs,\n type NodeConfig,\n type Node2DProps,\n} from \"@motionscript/core\"\n\nimport {\n DEFAULT_Y_AXIS,\n enterBudget,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\nimport { at, compose, type Seekable } from \"@motionscript/core/component\"\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 /** 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 VerticalAxis.labelFor}. */\nexport type MarkerLabel = (value: number) => string\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 * {@link 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 class VerticalAxis extends Node2D<VerticalAxisProps> {\n @property({ default: () => [0, 1] as Range }) declare range: Range\n @property({ default: () => [] as number[] }) declare markers: number[]\n @property({ default: DEFAULT_Y_AXIS }) declare axis: AxisConfig\n @property({ default: \"\" }) declare label: string\n\n /**\n * How a tick value is captioned. Defaults to the bare numeric reading; a\n * chart with a number format on this axis replaces it (see `number-format`).\n *\n * A plain field rather than a `@property`, for the reason the horizontal\n * axis's twin spells out: it is a policy, not a value, and there is nothing\n * to tween between two formatters.\n */\n labelFor: MarkerLabel = formatMarker\n\n /** One text node per marker, ordered top → bottom, for the staggered enter. */\n private markerNodes: Text[] = []\n /** The caption node, or null when `label` is empty. Entered after the markers. */\n private labelNode: Text | null = null\n\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\n private get sortedMarkers(): number[] {\n return [...this.markers].sort((a, b) => b - a)\n }\n\n /**\n * Tick `i`'s value, or `undefined` once the live `markers` list is shorter\n * than the column of text nodes built for it — a slot with no value renders as\n * empty text rather than repeating its neighbour.\n */\n private valueAt(index: number): number | undefined {\n return this.sortedMarkers[index]\n }\n\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\n private fracAt(index: number): number {\n const v = this.valueAt(index)\n if (v === undefined) return 0\n const [min, max] = this.range\n return max <= min ? 0 : (v - min) / (max - min)\n }\n\n constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>) {\n super(props)\n\n // Composed from plain props (range/markers/label) — no context needed, so\n // it's built here. super() applied the props, so the reads below resolve.\n const tickPad = insetsOps.resolve(this.axis.tickPadding).right\n const titlePad = insetsOps.resolve(this.axis.titlePadding).right\n\n this.markerNodes = this.markers.map((_, i) => {\n const marker: Text = new Text({\n ...textOps.styleProps(this.axis.labelStyle),\n text: () => {\n const v = this.valueAt(i)\n return v === undefined ? \"\" : this.labelFor(v)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = this.layoutBounds.height\n const centred = (this.fracAt(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 })\n return marker\n })\n\n const children: Node2D[] = []\n if (this.label !== \"\") {\n this.labelNode = new Text({\n ...textOps.styleProps(this.axis.titleStyle),\n text: this.label,\n })\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: this.labelNode,\n })\n )\n }\n children.push(\n new Rect({\n height: \"fill\",\n width: \"hug\",\n padding: { right: tickPad },\n children: this.markerNodes,\n })\n )\n\n this.add(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n }\n\n /**\n * Primes every marker (and the caption) at its pre-entrance state: shifted\n * right and transparent. Idempotent, and separate from {@link enter} so the\n * chart can arm its whole composition before the first frame is drawn.\n */\n arm(slide = SLIDE): void {\n for (const marker of this.markerNodes) marker.set({ opacity: 0, x: slide })\n this.labelNode?.set({ opacity: 0, x: slide })\n }\n\n /**\n * Stagger the markers in bottom to top, then slide the caption in from the\n * right after them.\n *\n * A {@link Seekable} rather than a generator — see the note on the horizontal\n * axis's `enter`. The offsets were always static; expressing them as `wait`\n * inside a generator is what made them reachable only by running it.\n *\n * `args.duration` is the **whole** entrance, not one marker's slide: the\n * stagger and the caption are carved out of it rather than added on top. See\n * {@link enterBudget} for why that distinction matters here.\n *\n * `args.data.stagger` is seconds between successive markers (derived when\n * omitted); `args.data.slide` is the starting rightward offset in px.\n */\n @command()\n enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {\n const { stagger, slide = SLIDE } = args.data ?? {}\n const easing = args.easing ?? easeOut()\n const nodes = this.markerNodes\n if (nodes.length === 0) return compose([])\n const { step, per, caption } = enterBudget(\n args.duration,\n nodes.length,\n this.labelNode !== null,\n stagger\n )\n\n this.arm(slide)\n\n // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.\n const markers = nodes.map((node, i) => {\n const order = nodes.length - 1 - i // bottom-most = 0\n return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))\n })\n const lastMarkerEnds = (nodes.length - 1) * step + per\n\n // Once every marker has landed, the caption slides in from the right.\n return compose([\n ...markers,\n ...(this.labelNode\n ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]\n : []),\n ])\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,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,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,CAAgF,EAAE,KAAa;IAC3H,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CA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AAC,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"]}
|