@motionscript/charts 0.1.0-alpha.5 → 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 +22 -0
- package/README.md +30 -16
- package/dist/bar-chart/bar-chart.d.ts +93 -246
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +378 -569
- 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 +3 -3
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +3 -3
- 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 +1 -1
- 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/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 -67
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +129 -154
- 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 +31 -3
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +42 -3
- 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 +25 -51
- 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 -319
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +403 -663
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +3 -3
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +3 -3
- package/dist/line-chart/shared.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 +200 -271
- 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 -131
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +333 -391
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +415 -701
- package/src/bar-chart/category-axis.ts +95 -110
- package/src/bar-chart/chart-bars.ts +178 -200
- package/src/bar-chart/index.ts +2 -2
- package/src/bar-chart/shared.ts +3 -3
- package/src/engine.ts +8 -6
- package/src/kit/cartesian.ts +81 -0
- package/src/kit/chart-border.ts +22 -33
- package/src/kit/chart-canvas.ts +44 -79
- package/src/kit/chart-legend.ts +173 -189
- 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 +52 -3
- package/src/kit/vertical-axis.ts +110 -140
- package/src/line-chart/chart-line.ts +95 -122
- package/src/line-chart/chart-region.ts +30 -59
- package/src/line-chart/horizontal-axis.ts +99 -135
- package/src/line-chart/index.ts +2 -2
- package/src/line-chart/line-chart.ts +449 -825
- package/src/line-chart/shared.ts +3 -3
- package/src/nodes.ts +8 -10
- package/src/pie-chart/index.ts +2 -2
- package/src/pie-chart/pie-chart.ts +221 -311
- package/src/pie-chart/pie-legend.ts +124 -114
- package/src/pie-chart/pie-ring.ts +386 -473
- package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
- package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type AssetScope,
|
|
3
2
|
Graphics2D,
|
|
4
|
-
|
|
3
|
+
Types,
|
|
4
|
+
component2d,
|
|
5
5
|
fillOps,
|
|
6
6
|
strokeOps,
|
|
7
|
-
property,
|
|
8
7
|
type Fill,
|
|
9
8
|
type FillResolved,
|
|
9
|
+
type NodeOf,
|
|
10
|
+
// Named so this component's emitted type reaches `Node2D` through the sdk, not core.
|
|
11
|
+
type Node2D as _Node2D,
|
|
10
12
|
type Node2DProps,
|
|
11
|
-
type RenderContext2D,
|
|
12
13
|
type Stroke,
|
|
13
14
|
type StrokeResolved,
|
|
14
15
|
} from "@motionscript/sdk"
|
|
15
16
|
|
|
17
|
+
import { fresh } from "../kit/entries"
|
|
18
|
+
import { loadPaints } from "../kit/paints"
|
|
16
19
|
import {
|
|
17
20
|
DEFAULT_CHART_THEME,
|
|
18
21
|
EMPTY_REGION_BOX,
|
|
19
22
|
hasRegion,
|
|
20
23
|
type RegionBox,
|
|
21
24
|
} from "./shared"
|
|
22
|
-
import { declarePaints } from "@motionscript/sdk/component"
|
|
23
25
|
|
|
24
26
|
export interface ChartRegionProps extends Node2DProps {
|
|
25
27
|
/**
|
|
@@ -44,7 +46,7 @@ export interface ChartRegionProps extends Node2DProps {
|
|
|
44
46
|
* The **region call-out** of a {@link LineChart}: a washed rectangle over the
|
|
45
47
|
* plot with a dashed rule down each edge the author actually bounded. Sized and
|
|
46
48
|
* positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather
|
|
47
|
-
* than its own
|
|
49
|
+
* than its own box — the region already carries the plot geometry.
|
|
48
50
|
*
|
|
49
51
|
* It draws only the *marking*; fading the series outside the region is
|
|
50
52
|
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
@@ -54,36 +56,20 @@ export interface ChartRegionProps extends Node2DProps {
|
|
|
54
56
|
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
55
57
|
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
56
58
|
*/
|
|
57
|
-
export
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
tween: fillOps.lerp,
|
|
69
|
-
})
|
|
70
|
-
declare fill: Fill
|
|
71
|
-
@property({ default: 0 }) declare reveal: number
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
|
|
75
|
-
* paint props it carries — see {@link declarePaints}.
|
|
76
|
-
*/
|
|
77
|
-
override declareAssets(assets: AssetScope): void {
|
|
78
|
-
super.declareAssets(assets)
|
|
79
|
-
declarePaints(this, assets)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
protected renderSelf(ctx: RenderContext2D): void {
|
|
83
|
-
const box = this.box
|
|
59
|
+
export const ChartRegion = component2d({
|
|
60
|
+
key: "chartRegion",
|
|
61
|
+
state: {
|
|
62
|
+
box: fresh<RegionBox>(() => EMPTY_REGION_BOX),
|
|
63
|
+
stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
64
|
+
fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
65
|
+
reveal: 0,
|
|
66
|
+
},
|
|
67
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
68
|
+
render: (ctx, state) => {
|
|
69
|
+
const box = state.box
|
|
84
70
|
if (!hasRegion(box)) return
|
|
85
71
|
|
|
86
|
-
const r = Math.max(0, Math.min(1,
|
|
72
|
+
const r = Math.max(0, Math.min(1, state.reveal))
|
|
87
73
|
if (r <= 0) return
|
|
88
74
|
|
|
89
75
|
const width = box.right - box.left
|
|
@@ -92,44 +78,29 @@ export class ChartRegion extends Node2D<ChartRegionProps> {
|
|
|
92
78
|
const cy = (box.bottom + box.top) / 2
|
|
93
79
|
|
|
94
80
|
// Wash first, so the rules sit over their own tint.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
ctx.draw(
|
|
98
|
-
new Graphics2D()
|
|
99
|
-
.rect({ x: cx, y: cy, width, height })
|
|
100
|
-
.fill(this.fill)
|
|
101
|
-
.opacity(r)
|
|
102
|
-
)
|
|
81
|
+
if (state.fill.length > 0) {
|
|
82
|
+
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))
|
|
103
83
|
}
|
|
104
84
|
|
|
105
85
|
// One rule per bounded edge, growing from the region's centre outward as
|
|
106
86
|
// `reveal` climbs — the same "trace it in" beat as the series lines.
|
|
107
|
-
|
|
108
|
-
if (stroke.length === 0) return
|
|
87
|
+
if (state.stroke.length === 0) return
|
|
109
88
|
|
|
110
89
|
// One `draw` per rule rather than four line ops under a single paint:
|
|
111
90
|
// shapes chained before a `stroke()` are combined into one surface, and
|
|
112
91
|
// stroking a union of disjoint open paths doesn't paint.
|
|
113
92
|
const rule = (points: { x: number; y: number }[]) =>
|
|
114
|
-
ctx.draw(new Graphics2D().line({ points }).stroke(
|
|
93
|
+
ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))
|
|
115
94
|
|
|
116
95
|
if (box.xBounded) {
|
|
117
96
|
const half = (height / 2) * r
|
|
118
|
-
for (const x of [box.left, box.right]) {
|
|
119
|
-
rule([
|
|
120
|
-
{ x, y: cy - half },
|
|
121
|
-
{ x, y: cy + half },
|
|
122
|
-
])
|
|
123
|
-
}
|
|
97
|
+
for (const x of [box.left, box.right]) rule([{ x, y: cy - half }, { x, y: cy + half }])
|
|
124
98
|
}
|
|
125
99
|
if (box.yBounded) {
|
|
126
100
|
const half = (width / 2) * r
|
|
127
|
-
for (const y of [box.bottom, box.top]) {
|
|
128
|
-
rule([
|
|
129
|
-
{ x: cx - half, y },
|
|
130
|
-
{ x: cx + half, y },
|
|
131
|
-
])
|
|
132
|
-
}
|
|
101
|
+
for (const y of [box.bottom, box.top]) rule([{ x: cx - half, y }, { x: cx + half, y }])
|
|
133
102
|
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
103
|
+
},
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
export type ChartRegion = NodeOf<typeof ChartRegion>
|
|
@@ -1,31 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
-
command,
|
|
3
|
-
Node2D,
|
|
4
2
|
Rect,
|
|
5
3
|
Text,
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
Types,
|
|
5
|
+
component2d,
|
|
8
6
|
insetsOps,
|
|
9
7
|
textOps,
|
|
10
|
-
type
|
|
11
|
-
type
|
|
8
|
+
type NodeOf,
|
|
9
|
+
type Node2D,
|
|
12
10
|
type Node2DProps,
|
|
13
11
|
} from "@motionscript/sdk";
|
|
14
12
|
|
|
13
|
+
import { asParts, fresh } from "../kit/entries";
|
|
14
|
+
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from "../kit/motion";
|
|
15
15
|
import {
|
|
16
16
|
DEFAULT_X_AXIS,
|
|
17
17
|
enterBudget,
|
|
18
|
-
formatMarker,
|
|
19
18
|
type AxisConfig,
|
|
20
19
|
type Range,
|
|
21
20
|
} from "../kit/shared";
|
|
22
|
-
import {
|
|
21
|
+
import { markerCaption } from "../kit/vertical-axis";
|
|
23
22
|
|
|
24
23
|
export interface HorizontalAxisProps extends Node2DProps {
|
|
25
24
|
/** `[min, max]` of the horizontal scale the markers are positioned within. */
|
|
26
25
|
range: Range;
|
|
27
26
|
/** Tick values (in data units) to draw along the axis. */
|
|
28
27
|
markers: number[];
|
|
28
|
+
/**
|
|
29
|
+
* How each marker is captioned, one per entry of `markers` and in its order.
|
|
30
|
+
* Empty (the default), or short, captions a marker with its bare numeric
|
|
31
|
+
* reading; a chart whose x column names months or categories writes those.
|
|
32
|
+
*/
|
|
33
|
+
captions: string[];
|
|
29
34
|
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
30
35
|
axis: AxisConfig;
|
|
31
36
|
/**
|
|
@@ -38,7 +43,7 @@ export interface HorizontalAxisProps extends Node2DProps {
|
|
|
38
43
|
/** How far a marker starts above its slot when it enters, in px. */
|
|
39
44
|
const SLIDE = 24;
|
|
40
45
|
|
|
41
|
-
/** How a tick value is captioned — see {@link
|
|
46
|
+
/** How a tick value is captioned — see {@link HorizontalAxisProps.captions}. */
|
|
42
47
|
export type MarkerLabel = (value: number) => string;
|
|
43
48
|
|
|
44
49
|
/**
|
|
@@ -51,68 +56,49 @@ export type MarkerLabel = (value: number) => string;
|
|
|
51
56
|
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
52
57
|
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
53
58
|
* slot and has no scale at all — the two only look alike. What the values are
|
|
54
|
-
* captioned *as* is the chart's to decide; see {@link
|
|
59
|
+
* captioned *as* is the chart's to decide; see {@link HorizontalAxisProps.captions}.
|
|
55
60
|
*
|
|
56
|
-
*
|
|
61
|
+
* `enter` staggers the markers in **left-to-right**: each starts lifted a
|
|
57
62
|
* little above its slot and transparent, then fades and slides down into place.
|
|
58
63
|
*/
|
|
59
|
-
export
|
|
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
|
-
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
93
|
-
private fracAt(index: number): number {
|
|
94
|
-
const v = this.valueAt(index);
|
|
95
|
-
if (v === undefined) return 0;
|
|
96
|
-
const [min, max] = this.range;
|
|
97
|
-
return max <= min ? 0 : (v - min) / (max - min);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
constructor(props?: NodeConfig<HorizontalAxis, HorizontalAxisProps>) {
|
|
101
|
-
super(props);
|
|
102
|
-
|
|
103
|
-
const tickPad = insetsOps.resolve(this.axis.tickPadding).top;
|
|
104
|
-
const titlePad = insetsOps.resolve(this.axis.titlePadding).top;
|
|
105
|
-
|
|
106
|
-
this.markerNodes = this.markers.map((_, i) => {
|
|
107
|
-
const marker: Text = new Text({
|
|
108
|
-
...textOps.styleProps(this.axis.labelStyle),
|
|
64
|
+
export const HorizontalAxis = component2d({
|
|
65
|
+
key: "horizontalAxis",
|
|
66
|
+
state: {
|
|
67
|
+
range: fresh<Range>(() => [0, 1]),
|
|
68
|
+
markers: fresh<number[]>(() => []),
|
|
69
|
+
captions: fresh<string[]>(() => []),
|
|
70
|
+
axis: Types.custom<AxisConfig>(DEFAULT_X_AXIS),
|
|
71
|
+
label: "",
|
|
72
|
+
arrivals: arrivalsEntry(),
|
|
73
|
+
},
|
|
74
|
+
// A plain node filled its parent; one made of its markers would hug them.
|
|
75
|
+
defaults: { width: "fill", height: "fill" },
|
|
76
|
+
children: (state) => {
|
|
77
|
+
const tickPad = insetsOps.resolve(state.axis.tickPadding).top;
|
|
78
|
+
const titlePad = insetsOps.resolve(state.axis.titlePadding).top;
|
|
79
|
+
|
|
80
|
+
const column: Node2D[] = [];
|
|
81
|
+
// The column's parent is the axis: its box is what the markers are placed in.
|
|
82
|
+
const box = () => (column[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 };
|
|
83
|
+
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
84
|
+
const sorted = () => [...state.markers].sort((a, b) => a - b);
|
|
85
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
86
|
+
const fracAt = (value: number | undefined) => {
|
|
87
|
+
if (value === undefined) return 0;
|
|
88
|
+
const [min, max] = state.range;
|
|
89
|
+
return max <= min ? 0 : (value - min) / (max - min);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const markers = state.markers.map((_, i) => {
|
|
93
|
+
const marker: Node2D = new Text({
|
|
94
|
+
...textOps.styleProps(state.axis.labelStyle),
|
|
109
95
|
text: () => {
|
|
110
|
-
const
|
|
111
|
-
return
|
|
96
|
+
const value = sorted()[i];
|
|
97
|
+
return value === undefined ? "" : markerCaption(state, value);
|
|
112
98
|
},
|
|
113
99
|
x: () => {
|
|
114
|
-
const width =
|
|
115
|
-
const centred = (
|
|
100
|
+
const width = box().width;
|
|
101
|
+
const centred = (fracAt(sorted()[i]) - 0.5) * width;
|
|
116
102
|
// Held inside the axis's right edge, which is also the *chart's*: the
|
|
117
103
|
// last marker is centred on the last grid line, so half of `2026-06`
|
|
118
104
|
// — or of `3300` — would be drawn outside the node's box and outside
|
|
@@ -122,81 +108,59 @@ export class HorizontalAxis extends Node2D<HorizontalAxisProps> {
|
|
|
122
108
|
const limit = width / 2 - marker.layoutBounds.width / 2;
|
|
123
109
|
return Math.min(centred, limit);
|
|
124
110
|
},
|
|
111
|
+
opacity: () => arrivalOf(state.arrivals, i).opacity,
|
|
112
|
+
y: () => arrivalOf(state.arrivals, i).shift,
|
|
125
113
|
});
|
|
126
114
|
return marker;
|
|
127
115
|
});
|
|
128
116
|
|
|
129
117
|
const children: Node2D[] = [
|
|
130
|
-
new Rect({
|
|
131
|
-
width: "fill",
|
|
132
|
-
height: "hug",
|
|
133
|
-
padding: { top: tickPad },
|
|
134
|
-
children: this.markerNodes,
|
|
135
|
-
}),
|
|
118
|
+
new Rect({ width: "fill", height: "hug", padding: { top: tickPad }, children: markers }),
|
|
136
119
|
];
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
120
|
+
if (state.label !== "") {
|
|
121
|
+
children.push(
|
|
122
|
+
new Text({
|
|
123
|
+
...textOps.styleProps(state.axis.titleStyle),
|
|
124
|
+
text: state.label,
|
|
125
|
+
opacity: () => arrivalOf(state.arrivals, "label").opacity,
|
|
126
|
+
y: () => arrivalOf(state.arrivals, "label").shift,
|
|
127
|
+
}),
|
|
128
|
+
);
|
|
143
129
|
}
|
|
144
130
|
|
|
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
|
-
duration,
|
|
182
|
-
nodes.length,
|
|
183
|
-
this.labelNode !== null,
|
|
184
|
-
stagger,
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
this.arm(slide);
|
|
188
|
-
|
|
189
|
-
// Left marker leads: markerNodes is already left → right.
|
|
190
|
-
const markers = nodes.map((node, i) =>
|
|
191
|
-
at(i * step, node.to({ data: { opacity: 1, y: 0 }, duration: per, easing })),
|
|
192
|
-
);
|
|
193
|
-
const lastMarkerEnds = nodes.length === 0 ? 0 : (nodes.length - 1) * step + per;
|
|
194
|
-
|
|
195
|
-
return compose([
|
|
196
|
-
...markers,
|
|
197
|
-
...(this.labelNode
|
|
198
|
-
? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, y: 0 }, duration: caption, easing }))]
|
|
199
|
-
: []),
|
|
200
|
-
]);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
131
|
+
column.push(new Rect({ flow: "vertical", gap: titlePad, height: "hug", width: "fill", children }));
|
|
132
|
+
return asParts(column);
|
|
133
|
+
},
|
|
134
|
+
commands: {
|
|
135
|
+
/**
|
|
136
|
+
* Stagger the markers in left to right, then slide the caption in after
|
|
137
|
+
* them. Its first frame arms them all: lifted by `slide` and transparent.
|
|
138
|
+
*
|
|
139
|
+
* The timeline's duration is the **whole** entrance — see
|
|
140
|
+
* `VerticalAxis.enter` and {@link enterBudget}.
|
|
141
|
+
*/
|
|
142
|
+
enter: {
|
|
143
|
+
args: {
|
|
144
|
+
stagger: Types.custom<number | undefined>(undefined),
|
|
145
|
+
slide: Types.number(SLIDE),
|
|
146
|
+
},
|
|
147
|
+
run: (timeline, state) => {
|
|
148
|
+
const { stagger, slide } = timeline.args;
|
|
149
|
+
const count = state.markers.length;
|
|
150
|
+
const captioned = state.label !== "";
|
|
151
|
+
const from: Arrival = { opacity: 0, shift: slide };
|
|
152
|
+
const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])];
|
|
153
|
+
const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));
|
|
154
|
+
if (count === 0) return arm;
|
|
155
|
+
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
|
|
156
|
+
const ease = frameEase(timeline);
|
|
157
|
+
// Left marker leads: the row is already left → right.
|
|
158
|
+
const markers = state.markers.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
|
|
159
|
+
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
|
|
160
|
+
return timeline.together([arm, beats(timeline, [...markers, ...label])]);
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export type HorizontalAxis = NodeOf<typeof HorizontalAxis>;
|
package/src/line-chart/index.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* that is *not* here comes from the kit and stays a dependency — see
|
|
11
11
|
* `../engine.ts` for why that line is where it is.
|
|
12
12
|
*/
|
|
13
|
-
export { LineChart } from "./line-chart"
|
|
14
|
-
export type { LineChartProps } from "./line-chart"
|
|
13
|
+
export { LineChart, lineChartDomains } from "./line-chart"
|
|
14
|
+
export type { LineChartDomains, LineChartProps, LineChartValues } from "./line-chart"
|
|
15
15
|
export { ChartRegion } from "./chart-region"
|
|
16
16
|
export { ChartLine } from "./chart-line"
|
|
17
17
|
export { HorizontalAxis } from "./horizontal-axis"
|