@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.5
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 +59 -0
- package/LICENSE +201 -201
- package/NOTICE +48 -0
- package/README.md +85 -0
- package/dist/bar-chart/bar-chart.d.ts +33 -19
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +68 -64
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +2 -2
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +2 -2
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +1 -1
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +2 -2
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +4 -4
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +4 -4
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +2 -0
- package/dist/browser/chunks/chunk-5ZPBV6BU.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 +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +1 -1
- package/dist/engine.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/kit/chart-border.d.ts +1 -1
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +2 -2
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +1 -1
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +2 -2
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +6 -27
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +33 -57
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/shared.d.ts +31 -8
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +67 -11
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +2 -2
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +2 -2
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +3 -3
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +2 -2
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +1 -1
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +2 -2
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +2 -2
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +2 -2
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +25 -9
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +66 -43
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +4 -4
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +20 -5
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +2 -2
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +2 -2
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +16 -10
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +15 -16
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +2 -2
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +6 -6
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +14 -5
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +45 -15
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +4 -4
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +4 -4
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +6 -4
- package/registry.json +23 -23
- package/src/bar-chart/bar-chart.ts +820 -804
- package/src/bar-chart/category-axis.ts +177 -177
- package/src/bar-chart/chart-bars.ts +310 -310
- package/src/bar-chart/index.ts +31 -31
- package/src/bar-chart/shared.ts +354 -354
- package/src/engine.ts +26 -26
- package/src/index.ts +5 -5
- package/src/kit/chart-border.ts +61 -61
- package/src/kit/chart-canvas.ts +157 -157
- package/src/kit/chart-legend.ts +245 -250
- package/src/kit/shared.ts +733 -675
- package/src/kit/vertical-axis.ts +224 -224
- package/src/line-chart/chart-line.ts +208 -208
- package/src/line-chart/chart-region.ts +135 -135
- package/src/line-chart/horizontal-axis.ts +202 -202
- package/src/line-chart/index.ts +39 -39
- package/src/line-chart/line-chart.ts +961 -894
- package/src/line-chart/shared.ts +473 -459
- package/src/line-chart/x-scale.ts +367 -367
- package/src/nodes.ts +20 -20
- package/src/pie-chart/index.ts +37 -37
- package/src/pie-chart/pie-chart.ts +383 -374
- package/src/pie-chart/pie-legend.ts +159 -159
- package/src/pie-chart/pie-ring.ts +935 -903
- package/src/pie-chart/shared.ts +490 -490
- package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
- package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
package/src/kit/chart-legend.ts
CHANGED
|
@@ -1,250 +1,245 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Rect,
|
|
3
|
-
Text,
|
|
4
|
-
command,
|
|
5
|
-
easeOut,
|
|
6
|
-
property,
|
|
7
|
-
textOps,
|
|
8
|
-
type CommandArgs,
|
|
9
|
-
type EasingFunction,
|
|
10
|
-
type Fill,
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
* caption
|
|
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
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
*
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })
|
|
247
|
-
)
|
|
248
|
-
)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
Rect,
|
|
3
|
+
Text,
|
|
4
|
+
command,
|
|
5
|
+
easeOut,
|
|
6
|
+
property,
|
|
7
|
+
textOps,
|
|
8
|
+
type CommandArgs,
|
|
9
|
+
type EasingFunction,
|
|
10
|
+
type Fill,
|
|
11
|
+
type MeasureContext2D,
|
|
12
|
+
type NodeConfig,
|
|
13
|
+
type RectProps,
|
|
14
|
+
type Size2D,
|
|
15
|
+
type SizeConstraints,
|
|
16
|
+
} from "@motionscript/sdk"
|
|
17
|
+
|
|
18
|
+
import { drive, hold, together, type Seekable } from "@motionscript/sdk/component"
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
DEFAULT_LEGEND,
|
|
22
|
+
SPOTLIGHT_DIM,
|
|
23
|
+
type ChartSeries,
|
|
24
|
+
type LegendConfig,
|
|
25
|
+
} from "./shared"
|
|
26
|
+
|
|
27
|
+
export interface ChartLegendProps extends RectProps {
|
|
28
|
+
/**
|
|
29
|
+
* One entry per series: legend `label`, its `enabled` default, and — through
|
|
30
|
+
* {@link ChartLegendProps.swatches} — the colour its chip is painted. A series
|
|
31
|
+
* that starts enabled (the default) is added to the row up front; one that
|
|
32
|
+
* starts `false` is hidden until a later {@link ChartLegend.showSeries}.
|
|
33
|
+
*/
|
|
34
|
+
series: ChartSeries[]
|
|
35
|
+
/**
|
|
36
|
+
* The swatch colour for each series, by index — resolved by the chart, whose
|
|
37
|
+
* business it is whether a series' colour comes out of a stroke palette (a
|
|
38
|
+
* line) or a fill palette (a bar). Shorter than the series list means the
|
|
39
|
+
* missing entries fall back to white.
|
|
40
|
+
*/
|
|
41
|
+
swatches: Fill[]
|
|
42
|
+
/** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */
|
|
43
|
+
legend: LegendConfig
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One legend entry. It hugs its caption and swatch; `shown` scales that width from
|
|
48
|
+
* nothing to the whole of it.
|
|
49
|
+
*
|
|
50
|
+
* The width is taken from the content on every measure, at any reveal, so a frame
|
|
51
|
+
* never depends on whether the entry was once seen fully shown. A collapse needs a
|
|
52
|
+
* number to scale, and `"hug"` is not one until something measures it — this is
|
|
53
|
+
* the something.
|
|
54
|
+
*/
|
|
55
|
+
class LegendEntry extends Rect {
|
|
56
|
+
constructor(props: NodeConfig<Rect, RectProps>, private readonly _shown: () => number) {
|
|
57
|
+
super(props)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
override measure(constraints: SizeConstraints, scope: MeasureContext2D): Partial<Size2D> {
|
|
61
|
+
const size = super.measure(constraints, scope)
|
|
62
|
+
const shown = this._shown()
|
|
63
|
+
return shown >= 1 ? size : { ...size, width: shown * (size.width ?? 0) }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The legend of a chart: a **horizontal-flow row of entries**, one per series, laid out
|
|
69
|
+
* left-to-right with the theme's `itemGap`. Each entry pairs the series label
|
|
70
|
+
* with a rounded colour swatch; only the swatch carries the series colour, the
|
|
71
|
+
* caption reads in the legend's neutral ink.
|
|
72
|
+
*
|
|
73
|
+
* {@link showSeries}/{@link hideSeries} flip a series on or off — showing one
|
|
74
|
+
* adds its entry back into the row at its stable series position and grows it
|
|
75
|
+
* in, hiding one shrinks it away and removes it. So the row only ever holds the
|
|
76
|
+
* currently-enabled series, in series order, and closes the gap when one leaves.
|
|
77
|
+
*
|
|
78
|
+
* This node *is* the row, so the parent places it (centred below the chart) and
|
|
79
|
+
* it hugs its entries.
|
|
80
|
+
*/
|
|
81
|
+
export class ChartLegend extends Rect {
|
|
82
|
+
@property({ default: () => [] as ChartSeries[] }) declare series: ChartSeries[]
|
|
83
|
+
@property({ default: () => [] as Fill[] }) declare swatches: Fill[]
|
|
84
|
+
@property({ default: DEFAULT_LEGEND }) declare legend: LegendConfig
|
|
85
|
+
|
|
86
|
+
/** One entry per series. **Every** entry is a child — see {@link reveal}. */
|
|
87
|
+
private items: LegendEntry[] = []
|
|
88
|
+
/**
|
|
89
|
+
* How far each entry is shown, `0`–`1`. Drives its width, opacity and gap
|
|
90
|
+
* together, so `0` is an entry that takes no room and `1` is one at its
|
|
91
|
+
* natural size.
|
|
92
|
+
*
|
|
93
|
+
* This replaces adding and removing the entry from the row, which is what
|
|
94
|
+
* `showSeries`/`hideSeries` used to do. That could not be a command: a command
|
|
95
|
+
* is asked what it looks like at a time, and "is this node a child" is not a
|
|
96
|
+
* value a time can produce — the tree either contains it or it doesn't, and
|
|
97
|
+
* getting there means having run the add. Collapsed-but-present is the same
|
|
98
|
+
* picture reached by a route that *is* a function of `t`.
|
|
99
|
+
*
|
|
100
|
+
* One array in one slot, because the count is the series count, which is data.
|
|
101
|
+
* It is replaced rather than mutated: a write is a slot write, so the timeline
|
|
102
|
+
* sees it and restores it to the authored reveal before the command starts
|
|
103
|
+
* and after a seek back. The entries' props are bound to it, so writing it
|
|
104
|
+
* still moves the layout.
|
|
105
|
+
*/
|
|
106
|
+
@property({ default: () => [] as number[] }) private declare reveal: number[]
|
|
107
|
+
|
|
108
|
+
constructor(props?: NodeConfig<ChartLegend, ChartLegendProps>) {
|
|
109
|
+
// `flow` after the spread, with the rest of the geometry: this class *is*
|
|
110
|
+
// the row, so the direction is its own answer and not the caller's. It has
|
|
111
|
+
// to be stated — a `Rect` given no flow lays its children out `freeform`,
|
|
112
|
+
// which stacks every entry on the same spot. One series looks perfect that
|
|
113
|
+
// way and three look like one smeared caption, so the failure only shows up
|
|
114
|
+
// on the charts that most need a legend.
|
|
115
|
+
super({
|
|
116
|
+
...(props as RectProps),
|
|
117
|
+
flow: "horizontal",
|
|
118
|
+
align: "center",
|
|
119
|
+
width: "hug",
|
|
120
|
+
height: "hug",
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// Structure is one entry per series, so it's composed here from the resolved
|
|
124
|
+
// props super() applied. Fixed row geometry last, so it wins over super().
|
|
125
|
+
this.set({ gap: this.legend.itemGap, padding: this.legend.padding })
|
|
126
|
+
|
|
127
|
+
this.reveal = this.series.map((s) => ((s.enabled ?? true) ? 1 : 0))
|
|
128
|
+
this.items = this.series.map((s, i) => this.buildItem(s, i))
|
|
129
|
+
|
|
130
|
+
// All of them, in series order. Order is now fixed rather than depending on
|
|
131
|
+
// which siblings happen to be shown, so an entry always comes back where it
|
|
132
|
+
// belongs and `insertionIndex` has nothing left to compute.
|
|
133
|
+
for (const item of this.items) this.add(item)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** One entry: the series caption beside its colour swatch. */
|
|
137
|
+
private buildItem(series: ChartSeries, index: number): LegendEntry {
|
|
138
|
+
const marker = this.legend.markerStyle
|
|
139
|
+
const item = new LegendEntry({ flow: "horizontal",
|
|
140
|
+
gap: 12,
|
|
141
|
+
align: "center",
|
|
142
|
+
// Bound to the reveal, so showing and hiding is a number moving rather
|
|
143
|
+
// than a child arriving and leaving. The width follows it in `measure`.
|
|
144
|
+
width: "hug",
|
|
145
|
+
opacity: () => this.reveal[index] ?? 0,
|
|
146
|
+
height: "hug",
|
|
147
|
+
children: [
|
|
148
|
+
new Text({
|
|
149
|
+
...textOps.styleProps(this.legend.textStyle),
|
|
150
|
+
text: series.label,
|
|
151
|
+
}),
|
|
152
|
+
new Rect({
|
|
153
|
+
width: marker.width,
|
|
154
|
+
height: marker.height,
|
|
155
|
+
cornerRadius: marker.borderRadius,
|
|
156
|
+
fill: this.swatches[index] ?? "white",
|
|
157
|
+
stroke: marker.stroke,
|
|
158
|
+
shadow: marker.shadow,
|
|
159
|
+
}),
|
|
160
|
+
],
|
|
161
|
+
}, () => this.reveal[index] ?? 0)
|
|
162
|
+
// `gapScale` is a `Node` prop rather than a container one, so it is bound here
|
|
163
|
+
// instead of in the config. It tracks the reveal so the flanking gap closes
|
|
164
|
+
// with the entry rather than snapping when it reaches zero.
|
|
165
|
+
item.set({ gapScale: () => this.reveal[index] ?? 0 })
|
|
166
|
+
return item
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** True if series `index` is showing at all — see {@link reveal}. */
|
|
170
|
+
isEnabled(index: number): boolean {
|
|
171
|
+
return (this.reveal[index] ?? 0) > 0
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Grow series `index`'s entry back in at its series-order position, the
|
|
176
|
+
* siblings sliding over to make room.
|
|
177
|
+
*
|
|
178
|
+
* A reveal tween rather than an animated `addChildAt`. The entry never left —
|
|
179
|
+
* see {@link reveal} — so there is no add to have happened, and the whole
|
|
180
|
+
* thing is a function of `t`.
|
|
181
|
+
*/
|
|
182
|
+
@command()
|
|
183
|
+
showSeries(args: CommandArgs<{ index: number }>): Seekable {
|
|
184
|
+
const { index = 0 } = args.data ?? {}
|
|
185
|
+
return this.revealTo(index, 1, args.duration ?? 0.35, args.easing ?? easeOut())
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Shrink series `index`'s entry away, the gap closing behind it — the mirror
|
|
190
|
+
* of {@link showSeries}.
|
|
191
|
+
*/
|
|
192
|
+
@command()
|
|
193
|
+
hideSeries(args: CommandArgs<{ index: number }>): Seekable {
|
|
194
|
+
const { index = 0 } = args.data ?? {}
|
|
195
|
+
return this.revealTo(index, 0, args.duration ?? 0.35, args.easing ?? easeOut())
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Ramp one entry's reveal to `target`.
|
|
200
|
+
*
|
|
201
|
+
* `from` is read when the command is built, which for a driven scene is with
|
|
202
|
+
* the node in the state its own start time implies — so a hide that follows a
|
|
203
|
+
* show starts where the show left it rather than at whatever the node happens
|
|
204
|
+
* to hold now.
|
|
205
|
+
*/
|
|
206
|
+
private revealTo(
|
|
207
|
+
index: number,
|
|
208
|
+
target: number,
|
|
209
|
+
duration: number,
|
|
210
|
+
easing: EasingFunction
|
|
211
|
+
): Seekable {
|
|
212
|
+
if (this.items[index] === undefined) return hold(duration)
|
|
213
|
+
const from = this.reveal[index] ?? 0
|
|
214
|
+
return drive(duration, (t) => {
|
|
215
|
+
const next = [...this.reveal]
|
|
216
|
+
next[index] = from + (target - from) * easing(t)
|
|
217
|
+
this.reveal = next
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Dim every entry but series `index` to {@link SPOTLIGHT_DIM} and bring that
|
|
223
|
+
* one back to full — the legend half of a chart's `spotlightSeries`. Entries
|
|
224
|
+
* stay in place; only their opacity moves, so the row doesn't reflow.
|
|
225
|
+
*
|
|
226
|
+
* Only the currently-shown entries are touched — a hidden series' entry is
|
|
227
|
+
* left as {@link hideSeries} left it.
|
|
228
|
+
*/
|
|
229
|
+
@command()
|
|
230
|
+
spotlightSeries(args: CommandArgs<{ index: number }>): Seekable {
|
|
231
|
+
const { index = 0 } = args.data ?? {}
|
|
232
|
+
const duration = args.duration ?? 0.35
|
|
233
|
+
const easing = args.easing ?? easeOut()
|
|
234
|
+
// Opacity only, on entries that are already in the row — no membership
|
|
235
|
+
// changes, so unlike {@link showSeries} this is a plain function of `t`.
|
|
236
|
+
return together(
|
|
237
|
+
...this.items
|
|
238
|
+
.map((item, i) => ({ item, i }))
|
|
239
|
+
.filter(({ i }) => this.isEnabled(i))
|
|
240
|
+
.map(({ item, i }) =>
|
|
241
|
+
item.to({ data: { opacity: i === index ? 1 : SPOTLIGHT_DIM }, duration, easing })
|
|
242
|
+
)
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
}
|