@motionscript/charts 0.1.0-alpha.3 → 0.1.0-alpha.6
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 +63 -0
- package/LICENSE +201 -201
- package/NOTICE +48 -0
- package/README.md +99 -0
- package/dist/bar-chart/bar-chart.d.ts +93 -231
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +378 -565
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +24 -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 +36 -70
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +156 -210
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -2
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +6 -6
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +6 -6
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-XROBIRQK.js +2 -0
- package/dist/browser/chunks/chunk-XROBIRQK.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +3 -2
- package/dist/engine.d.ts +8 -6
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +8 -6
- package/dist/engine.js.map +1 -1
- package/dist/index.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 +8 -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 +23 -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 +79 -88
- 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 +59 -8
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +105 -10
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +36 -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 +27 -53
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +89 -120
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +14 -14
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +26 -64
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +32 -56
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +85 -123
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +2 -2
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +111 -311
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +403 -639
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +6 -6
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +22 -7
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +1 -1
- package/dist/line-chart/x-scale.js +1 -1
- 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 +77 -134
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +199 -268
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +54 -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 +142 -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 +3 -3
- package/dist/pie-chart/shared.js +3 -3
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +6 -5
- package/registry.json +23 -23
- package/src/bar-chart/bar-chart.ts +534 -814
- package/src/bar-chart/category-axis.ts +162 -177
- package/src/bar-chart/chart-bars.ts +288 -310
- package/src/bar-chart/index.ts +31 -31
- package/src/bar-chart/shared.ts +354 -354
- package/src/engine.ts +28 -26
- package/src/index.ts +5 -5
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +50 -61
- package/src/kit/chart-canvas.ts +122 -157
- package/src/kit/chart-legend.ts +229 -250
- 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 +782 -675
- package/src/kit/vertical-axis.ts +194 -224
- package/src/line-chart/chart-line.ts +181 -208
- package/src/line-chart/chart-region.ts +106 -135
- package/src/line-chart/horizontal-axis.ts +166 -202
- package/src/line-chart/index.ts +39 -39
- package/src/line-chart/line-chart.ts +585 -929
- package/src/line-chart/shared.ts +473 -459
- package/src/line-chart/x-scale.ts +367 -367
- package/src/nodes.ts +18 -20
- package/src/pie-chart/index.ts +37 -37
- package/src/pie-chart/pie-chart.ts +293 -381
- package/src/pie-chart/pie-legend.ts +169 -159
- package/src/pie-chart/pie-ring.ts +848 -903
- package/src/pie-chart/shared.ts +490 -490
- package/dist/browser/chunks/chunk-RMHQ6GYU.js +0 -2
- package/dist/browser/chunks/chunk-RMHQ6GYU.js.map +0 -7
package/src/kit/vertical-axis.ts
CHANGED
|
@@ -1,224 +1,194 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
} from "
|
|
15
|
-
|
|
16
|
-
import {
|
|
17
|
-
DEFAULT_Y_AXIS,
|
|
18
|
-
enterBudget,
|
|
19
|
-
formatMarker,
|
|
20
|
-
type AxisConfig,
|
|
21
|
-
type Range,
|
|
22
|
-
} from "./shared"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
*
|
|
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
|
-
|
|
62
|
-
*
|
|
63
|
-
* {@link
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {
|
|
196
|
-
const { stagger, slide = SLIDE } = args.data ?? {}
|
|
197
|
-
const easing = args.easing ?? easeOut()
|
|
198
|
-
const nodes = this.markerNodes
|
|
199
|
-
if (nodes.length === 0) return compose([])
|
|
200
|
-
const { step, per, caption } = enterBudget(
|
|
201
|
-
args.duration,
|
|
202
|
-
nodes.length,
|
|
203
|
-
this.labelNode !== null,
|
|
204
|
-
stagger
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
this.arm(slide)
|
|
208
|
-
|
|
209
|
-
// Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.
|
|
210
|
-
const markers = nodes.map((node, i) => {
|
|
211
|
-
const order = nodes.length - 1 - i // bottom-most = 0
|
|
212
|
-
return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))
|
|
213
|
-
})
|
|
214
|
-
const lastMarkerEnds = (nodes.length - 1) * step + per
|
|
215
|
-
|
|
216
|
-
// Once every marker has landed, the caption slides in from the right.
|
|
217
|
-
return compose([
|
|
218
|
-
...markers,
|
|
219
|
-
...(this.labelNode
|
|
220
|
-
? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]
|
|
221
|
-
: []),
|
|
222
|
-
])
|
|
223
|
-
}
|
|
224
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Rect,
|
|
3
|
+
RotatedBox,
|
|
4
|
+
Text,
|
|
5
|
+
Types,
|
|
6
|
+
component2d,
|
|
7
|
+
insetsOps,
|
|
8
|
+
textOps,
|
|
9
|
+
type NodeOf,
|
|
10
|
+
type Node2D,
|
|
11
|
+
type Node2DProps,
|
|
12
|
+
} from "@motionscript/sdk"
|
|
13
|
+
|
|
14
|
+
import { asParts, fresh } from "./entries"
|
|
15
|
+
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from "./motion"
|
|
16
|
+
import {
|
|
17
|
+
DEFAULT_Y_AXIS,
|
|
18
|
+
enterBudget,
|
|
19
|
+
formatMarker,
|
|
20
|
+
type AxisConfig,
|
|
21
|
+
type Range,
|
|
22
|
+
} from "./shared"
|
|
23
|
+
|
|
24
|
+
export interface VerticalAxisProps extends Node2DProps {
|
|
25
|
+
/** `[min, max]` of the vertical scale the markers are positioned within. */
|
|
26
|
+
range: Range
|
|
27
|
+
/**
|
|
28
|
+
* Tick values (in data units) to draw up the axis, each placed by its fraction
|
|
29
|
+
* across {@link VerticalAxisProps.range}. Need not be evenly spaced or include
|
|
30
|
+
* the ends.
|
|
31
|
+
*/
|
|
32
|
+
markers: number[]
|
|
33
|
+
/**
|
|
34
|
+
* How each marker is captioned, one per entry of `markers` and in its order.
|
|
35
|
+
* Empty (the default), or short, captions a marker with its bare numeric
|
|
36
|
+
* reading; a chart with a number format on this axis writes them through it.
|
|
37
|
+
*/
|
|
38
|
+
captions: string[]
|
|
39
|
+
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
40
|
+
axis: AxisConfig
|
|
41
|
+
/**
|
|
42
|
+
* Rotated caption drawn in the gutter to the left of the marker column. Empty
|
|
43
|
+
* string (the default) hides it — no caption node is built and no label gutter
|
|
44
|
+
* is reserved.
|
|
45
|
+
*/
|
|
46
|
+
label: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** How far a marker starts to the right of its slot when it enters, in px. */
|
|
50
|
+
const SLIDE = 24
|
|
51
|
+
|
|
52
|
+
/** How a tick value is captioned — see {@link VerticalAxisProps.captions}. */
|
|
53
|
+
export type MarkerLabel = (value: number) => string
|
|
54
|
+
|
|
55
|
+
/** What a marker's caption reads: the one listed for its value, else its bare reading. */
|
|
56
|
+
export function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {
|
|
57
|
+
const index = s.markers.indexOf(value)
|
|
58
|
+
return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The numeric vertical axis shared by the cartesian charts: a **column of
|
|
63
|
+
* {@link Text} nodes**, one per marker value, running top-to-bottom (highest
|
|
64
|
+
* value at the top). Pure layout — no `Graphics` — so the markers are real text
|
|
65
|
+
* nodes the scene can measure, restyle, or animate individually.
|
|
66
|
+
*
|
|
67
|
+
* Each marker is positioned so its centre lands exactly on its value's fraction
|
|
68
|
+
* across `range` within the axis's filled height, so unevenly-spaced markers
|
|
69
|
+
* land where their values fall. Both the caption and the position are *bound*,
|
|
70
|
+
* not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
|
|
71
|
+
* tweens `range`/`markers` live. Only the marker **count** is fixed at
|
|
72
|
+
* construction.
|
|
73
|
+
*
|
|
74
|
+
* `enter` staggers them in **bottom-to-top**: each marker starts pushed a
|
|
75
|
+
* little to the right and transparent, then fades and slides left into place.
|
|
76
|
+
* The resting state is the landed one, so a chart that is never told to enter
|
|
77
|
+
* still reads as a finished chart.
|
|
78
|
+
*/
|
|
79
|
+
export const VerticalAxis = component2d({
|
|
80
|
+
key: "verticalAxis",
|
|
81
|
+
state: {
|
|
82
|
+
range: fresh<Range>(() => [0, 1]),
|
|
83
|
+
markers: fresh<number[]>(() => []),
|
|
84
|
+
captions: fresh<string[]>(() => []),
|
|
85
|
+
axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),
|
|
86
|
+
label: "",
|
|
87
|
+
arrivals: arrivalsEntry(),
|
|
88
|
+
},
|
|
89
|
+
// A plain node filled its parent; one made of its markers would hug them.
|
|
90
|
+
defaults: { width: "fill", height: "fill" },
|
|
91
|
+
children: (state) => {
|
|
92
|
+
// Composed from plain entries (range/markers/label), so it's built once here.
|
|
93
|
+
const tickPad = insetsOps.resolve(state.axis.tickPadding).right
|
|
94
|
+
const titlePad = insetsOps.resolve(state.axis.titlePadding).right
|
|
95
|
+
|
|
96
|
+
const row: Node2D[] = []
|
|
97
|
+
// The row's parent is the axis: its box is what the markers are placed in.
|
|
98
|
+
const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }
|
|
99
|
+
/** The live tick values, top → bottom (highest first) — re-read every frame. */
|
|
100
|
+
const sorted = () => [...state.markers].sort((a, b) => b - a)
|
|
101
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
|
|
102
|
+
const fracAt = (value: number | undefined) => {
|
|
103
|
+
if (value === undefined) return 0
|
|
104
|
+
const [min, max] = state.range
|
|
105
|
+
return max <= min ? 0 : (value - min) / (max - min)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// One text node per marker, ordered top → bottom. A slot with no value (the
|
|
109
|
+
// live list is shorter than the column built for it) renders as empty text
|
|
110
|
+
// rather than repeating its neighbour.
|
|
111
|
+
const markers = state.markers.map((_, i) => {
|
|
112
|
+
const marker: Node2D = new Text({
|
|
113
|
+
...textOps.styleProps(state.axis.labelStyle),
|
|
114
|
+
text: () => {
|
|
115
|
+
const value = sorted()[i]
|
|
116
|
+
return value === undefined ? "" : markerCaption(state, value)
|
|
117
|
+
},
|
|
118
|
+
y: () => {
|
|
119
|
+
// Node2D space is y-up, so the fraction runs from the bottom.
|
|
120
|
+
const height = box().height
|
|
121
|
+
const centred = (fracAt(sorted()[i]) - 0.5) * height
|
|
122
|
+
// Held inside the axis's top edge — the backstop for a chart whose
|
|
123
|
+
// headroom is smaller than its marker text is tall, which a theme with
|
|
124
|
+
// much larger markers can arrange. Only the top, because what lies
|
|
125
|
+
// below the axis is the chart's own horizontal axis and legend.
|
|
126
|
+
const limit = height / 2 - marker.layoutBounds.height / 2
|
|
127
|
+
return Math.min(centred, limit)
|
|
128
|
+
},
|
|
129
|
+
opacity: () => arrivalOf(state.arrivals, i).opacity,
|
|
130
|
+
x: () => arrivalOf(state.arrivals, i).shift,
|
|
131
|
+
})
|
|
132
|
+
return marker
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const children: Node2D[] = []
|
|
136
|
+
if (state.label !== "") {
|
|
137
|
+
// Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
|
|
138
|
+
children.push(
|
|
139
|
+
new RotatedBox({
|
|
140
|
+
angle: -90,
|
|
141
|
+
width: "hug",
|
|
142
|
+
height: "hug",
|
|
143
|
+
children: new Text({
|
|
144
|
+
...textOps.styleProps(state.axis.titleStyle),
|
|
145
|
+
text: state.label,
|
|
146
|
+
opacity: () => arrivalOf(state.arrivals, "label").opacity,
|
|
147
|
+
x: () => arrivalOf(state.arrivals, "label").shift,
|
|
148
|
+
}),
|
|
149
|
+
})
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
children.push(new Rect({ height: "fill", width: "hug", padding: { right: tickPad }, children: markers }))
|
|
153
|
+
row.push(new Rect({ flow: "horizontal", gap: titlePad, children }))
|
|
154
|
+
return asParts(row)
|
|
155
|
+
},
|
|
156
|
+
commands: {
|
|
157
|
+
/**
|
|
158
|
+
* Stagger the markers in bottom to top, then slide the caption in from the
|
|
159
|
+
* right after them. Its first frame arms them all: shifted right by `slide`
|
|
160
|
+
* and transparent.
|
|
161
|
+
*
|
|
162
|
+
* The timeline's duration is the **whole** entrance, not one marker's slide:
|
|
163
|
+
* the stagger and the caption are carved out of it rather than added on top.
|
|
164
|
+
* See {@link enterBudget} for why that distinction matters here.
|
|
165
|
+
*
|
|
166
|
+
* `stagger` is seconds between successive markers (derived when omitted);
|
|
167
|
+
* `slide` is the starting rightward offset in px.
|
|
168
|
+
*/
|
|
169
|
+
enter: {
|
|
170
|
+
args: {
|
|
171
|
+
stagger: Types.custom<number | undefined>(undefined),
|
|
172
|
+
slide: Types.number(SLIDE),
|
|
173
|
+
},
|
|
174
|
+
run: (timeline, state) => {
|
|
175
|
+
const { stagger, slide } = timeline.args
|
|
176
|
+
const count = state.markers.length
|
|
177
|
+
const captioned = state.label !== ""
|
|
178
|
+
const from: Arrival = { opacity: 0, shift: slide }
|
|
179
|
+
const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])]
|
|
180
|
+
const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))
|
|
181
|
+
if (count === 0) return arm
|
|
182
|
+
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)
|
|
183
|
+
const ease = frameEase(timeline)
|
|
184
|
+
// Bottom marker leads: the column is top → bottom, so walk it in reverse.
|
|
185
|
+
const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))
|
|
186
|
+
// Once every marker has landed, the caption slides in from the right.
|
|
187
|
+
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : []
|
|
188
|
+
return timeline.together([arm, beats(timeline, [...markers, ...label])])
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
export type VerticalAxis = NodeOf<typeof VerticalAxis>
|