@motionscript/charts 0.1.0 → 0.1.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/bar-chart/bar-chart.d.ts +22 -93
- package/dist/bar-chart/bar-chart.d.ts.map +1 -1
- package/dist/bar-chart/bar-chart.js +48 -121
- package/dist/bar-chart/bar-chart.js.map +1 -1
- package/dist/bar-chart/category-axis.d.ts +11 -38
- package/dist/bar-chart/category-axis.d.ts.map +1 -1
- package/dist/bar-chart/category-axis.js +15 -38
- package/dist/bar-chart/category-axis.js.map +1 -1
- package/dist/bar-chart/chart-bars.d.ts +43 -74
- package/dist/bar-chart/chart-bars.d.ts.map +1 -1
- package/dist/bar-chart/chart-bars.js +31 -59
- package/dist/bar-chart/chart-bars.js.map +1 -1
- package/dist/bar-chart/index.d.ts +2 -10
- package/dist/bar-chart/index.d.ts.map +1 -1
- package/dist/bar-chart/index.js +0 -7
- package/dist/bar-chart/index.js.map +1 -1
- package/dist/bar-chart/shared.d.ts +27 -90
- package/dist/bar-chart/shared.d.ts.map +1 -1
- package/dist/bar-chart/shared.js +15 -54
- package/dist/bar-chart/shared.js.map +1 -1
- package/dist/browser/chunks/chunk-4SMRCU24.js +2 -0
- package/dist/browser/chunks/chunk-4SMRCU24.js.map +7 -0
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +3 -3
- package/dist/browser/kit.js +1 -1
- package/dist/browser/manifest.json +1 -1
- package/dist/engine.d.ts +4 -16
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +4 -16
- package/dist/engine.js.map +1 -1
- package/dist/kit/cartesian.d.ts +8 -28
- package/dist/kit/cartesian.d.ts.map +1 -1
- package/dist/kit/cartesian.js +7 -19
- package/dist/kit/cartesian.js.map +1 -1
- package/dist/kit/chart-border.d.ts +9 -18
- package/dist/kit/chart-border.d.ts.map +1 -1
- package/dist/kit/chart-border.js +4 -9
- package/dist/kit/chart-border.js.map +1 -1
- package/dist/kit/chart-canvas.d.ts +25 -36
- package/dist/kit/chart-canvas.d.ts.map +1 -1
- package/dist/kit/chart-canvas.js +13 -13
- package/dist/kit/chart-canvas.js.map +1 -1
- package/dist/kit/chart-legend.d.ts +14 -61
- package/dist/kit/chart-legend.d.ts.map +1 -1
- package/dist/kit/chart-legend.js +17 -65
- package/dist/kit/chart-legend.js.map +1 -1
- package/dist/kit/entries.d.ts +2 -0
- package/dist/kit/entries.d.ts.map +1 -1
- package/dist/kit/entries.js +2 -0
- package/dist/kit/entries.js.map +1 -1
- package/dist/kit/motion.d.ts +11 -3
- package/dist/kit/motion.d.ts.map +1 -1
- package/dist/kit/motion.js +7 -1
- package/dist/kit/motion.js.map +1 -1
- package/dist/kit/shared.d.ts +60 -175
- package/dist/kit/shared.d.ts.map +1 -1
- package/dist/kit/shared.js +40 -157
- package/dist/kit/shared.js.map +1 -1
- package/dist/kit/vertical-axis.d.ts +16 -45
- package/dist/kit/vertical-axis.d.ts.map +1 -1
- package/dist/kit/vertical-axis.js +17 -42
- package/dist/kit/vertical-axis.js.map +1 -1
- package/dist/line-chart/chart-line.d.ts +16 -41
- package/dist/line-chart/chart-line.d.ts.map +1 -1
- package/dist/line-chart/chart-line.js +14 -43
- package/dist/line-chart/chart-line.js.map +1 -1
- package/dist/line-chart/chart-region.d.ts +14 -27
- package/dist/line-chart/chart-region.d.ts.map +1 -1
- package/dist/line-chart/chart-region.js +8 -22
- package/dist/line-chart/chart-region.js.map +1 -1
- package/dist/line-chart/horizontal-axis.d.ts +16 -43
- package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
- package/dist/line-chart/horizontal-axis.js +13 -42
- package/dist/line-chart/horizontal-axis.js.map +1 -1
- package/dist/line-chart/index.d.ts +1 -13
- package/dist/line-chart/index.d.ts.map +1 -1
- package/dist/line-chart/index.js +0 -12
- package/dist/line-chart/index.js.map +1 -1
- package/dist/line-chart/line-chart.d.ts +23 -109
- package/dist/line-chart/line-chart.d.ts.map +1 -1
- package/dist/line-chart/line-chart.js +45 -141
- package/dist/line-chart/line-chart.js.map +1 -1
- package/dist/line-chart/shared.d.ts +33 -107
- package/dist/line-chart/shared.d.ts.map +1 -1
- package/dist/line-chart/shared.js +28 -81
- package/dist/line-chart/shared.js.map +1 -1
- package/dist/line-chart/x-scale.d.ts +14 -55
- package/dist/line-chart/x-scale.d.ts.map +1 -1
- package/dist/line-chart/x-scale.js +29 -111
- package/dist/line-chart/x-scale.js.map +1 -1
- package/dist/nodes.d.ts +0 -12
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +0 -12
- package/dist/nodes.js.map +1 -1
- package/dist/pie-chart/index.d.ts +1 -12
- package/dist/pie-chart/index.d.ts.map +1 -1
- package/dist/pie-chart/index.js +0 -9
- package/dist/pie-chart/index.js.map +1 -1
- package/dist/pie-chart/pie-chart.d.ts +37 -71
- package/dist/pie-chart/pie-chart.d.ts.map +1 -1
- package/dist/pie-chart/pie-chart.js +31 -65
- package/dist/pie-chart/pie-chart.js.map +1 -1
- package/dist/pie-chart/pie-legend.d.ts +11 -26
- package/dist/pie-chart/pie-legend.d.ts.map +1 -1
- package/dist/pie-chart/pie-legend.js +14 -39
- package/dist/pie-chart/pie-legend.js.map +1 -1
- package/dist/pie-chart/pie-ring.d.ts +50 -192
- package/dist/pie-chart/pie-ring.d.ts.map +1 -1
- package/dist/pie-chart/pie-ring.js +75 -247
- package/dist/pie-chart/pie-ring.js.map +1 -1
- package/dist/pie-chart/shared.d.ts +45 -131
- package/dist/pie-chart/shared.d.ts.map +1 -1
- package/dist/pie-chart/shared.js +29 -72
- package/dist/pie-chart/shared.js.map +1 -1
- package/package.json +4 -4
- package/src/bar-chart/bar-chart.ts +51 -165
- package/src/bar-chart/category-axis.ts +16 -57
- package/src/bar-chart/chart-bars.ts +43 -120
- package/src/bar-chart/index.ts +2 -10
- package/src/bar-chart/shared.ts +29 -97
- package/src/engine.ts +4 -16
- package/src/kit/cartesian.ts +11 -26
- package/src/kit/chart-border.ts +6 -20
- package/src/kit/chart-canvas.ts +15 -40
- package/src/kit/chart-legend.ts +17 -86
- package/src/kit/entries.ts +4 -1
- package/src/kit/motion.ts +11 -2
- package/src/kit/shared.ts +58 -219
- package/src/kit/vertical-axis.ts +18 -71
- package/src/line-chart/chart-line.ts +16 -44
- package/src/line-chart/chart-region.ts +10 -23
- package/src/line-chart/horizontal-axis.ts +13 -42
- package/src/line-chart/index.ts +1 -13
- package/src/line-chart/line-chart.ts +50 -184
- package/src/line-chart/shared.ts +51 -145
- package/src/line-chart/x-scale.ts +31 -121
- package/src/nodes.ts +0 -12
- package/src/pie-chart/index.ts +1 -12
- package/src/pie-chart/pie-chart.ts +34 -102
- package/src/pie-chart/pie-legend.ts +14 -55
- package/src/pie-chart/pie-ring.ts +80 -307
- package/src/pie-chart/shared.ts +50 -139
- package/dist/browser/chunks/chunk-TJNHLQGV.js +0 -2
- package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
|
@@ -4,8 +4,9 @@ import {
|
|
|
4
4
|
component2d,
|
|
5
5
|
strokeOps,
|
|
6
6
|
type NodeOf,
|
|
7
|
-
// Named so this component's emitted type reaches `Node2D` through the sdk, not core.
|
|
7
|
+
// Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.
|
|
8
8
|
type Node2D as _Node2D,
|
|
9
|
+
type Node2DProps as _Node2DProps,
|
|
9
10
|
type Stroke,
|
|
10
11
|
type StrokeResolved,
|
|
11
12
|
type Vector2,
|
|
@@ -22,12 +23,7 @@ import {
|
|
|
22
23
|
type RegionBox,
|
|
23
24
|
} from "./shared"
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
-
* The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
|
|
27
|
-
* by *cumulative arc length* so the line traces at a steady pace regardless of
|
|
28
|
-
* uneven point spacing. Returns the whole-point prefix plus one interpolated
|
|
29
|
-
* point partway along the active segment.
|
|
30
|
-
*/
|
|
26
|
+
/** The prefix of `pts` revealed at fraction `p`, measured by cumulative arc length so the trace keeps a steady pace over uneven spacing. */
|
|
31
27
|
function tracePoints(pts: Vector2[], p: number): Vector2[] {
|
|
32
28
|
if (p >= 1 || pts.length < 2) return pts
|
|
33
29
|
if (p <= 0) return []
|
|
@@ -59,45 +55,28 @@ function tracePoints(pts: Vector2[], p: number): Vector2[] {
|
|
|
59
55
|
return out
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
/**
|
|
63
|
-
* A single series line of a {@link LineChart}: one rounded polyline traced
|
|
64
|
-
* through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
|
|
65
|
-
* Sized and positioned by the parent, which shares the plot's coordinate frame.
|
|
66
|
-
*
|
|
67
|
-
* Two signals drive it: `progress` traces the line in
|
|
68
|
-
* (animated by `enter`) and `enabled` shows or hides it wholesale.
|
|
69
|
-
*/
|
|
58
|
+
/** One series of a {@link LineChart}: a rounded polyline through pre-mapped pixel `points`, one {@link Graphics2D} command list. `progress` traces it in; `enabled` shows or hides it wholesale. */
|
|
70
59
|
export const ChartLine = component2d({
|
|
71
60
|
key: "chartLine",
|
|
72
61
|
state: {
|
|
73
|
-
/**
|
|
62
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent and ordered along x. */
|
|
74
63
|
points: fresh<Vector2[]>(() => []),
|
|
75
|
-
/** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
|
|
76
64
|
stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
77
|
-
/**
|
|
78
|
-
* Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
|
|
79
|
-
* end to its right. Defaults to 1, so the paused editor canvas paints the line;
|
|
80
|
-
* `enter` drives it from 0 regardless of where it rests.
|
|
81
|
-
*/
|
|
65
|
+
/** Trace from the left end, `[0, 1]`. Rests at 1 so a paused editor canvas paints the line; `enter` drives it from 0. */
|
|
82
66
|
progress: 1,
|
|
83
|
-
/** Whether
|
|
67
|
+
/** Whether the line is drawn at all, flipped alongside its legend entry. */
|
|
84
68
|
enabled: true,
|
|
85
|
-
/**
|
|
69
|
+
/** In this node's pixel space; outside it the line drops to `dimOpacity`. */
|
|
86
70
|
spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),
|
|
87
|
-
/** Opacity the out-of-region stretches fade to. */
|
|
88
71
|
dimOpacity: SPOTLIGHT_DIM,
|
|
89
72
|
},
|
|
90
73
|
load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
|
|
91
74
|
commands: {
|
|
92
75
|
/**
|
|
93
|
-
* Trace the line from `from` to `to`
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* `enabled` rides along in the same value rather than being set before or
|
|
98
|
-
* after the command: a line is drawable for every `t` the trace covers and
|
|
99
|
-
* undrawn outside it, which is what makes arriving at a time backwards show
|
|
100
|
-
* what arriving forwards does.
|
|
76
|
+
* Trace the line from `from` to `to`; `showSeries`/`hideSeries` are this with
|
|
77
|
+
* the ends stated. `enabled` rides along in the same value, so the line is
|
|
78
|
+
* drawable for every `t` the trace covers and arriving backwards matches
|
|
79
|
+
* arriving forwards.
|
|
101
80
|
*/
|
|
102
81
|
enter: {
|
|
103
82
|
args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
|
|
@@ -106,8 +85,7 @@ export const ChartLine = component2d({
|
|
|
106
85
|
const ease = frameEase(timeline)
|
|
107
86
|
return timeline.animate((t) => {
|
|
108
87
|
const progress = from + (to - from) * ease(t)
|
|
109
|
-
// Hidden only once
|
|
110
|
-
// the empty plot rather than a line that vanished a frame early.
|
|
88
|
+
// Hidden only once fully retraced, so a hide does not vanish a frame early.
|
|
111
89
|
return { progress, enabled: progress > 0 }
|
|
112
90
|
})
|
|
113
91
|
},
|
|
@@ -124,7 +102,7 @@ export const ChartLine = component2d({
|
|
|
124
102
|
const drawn = tracePoints(pts, p)
|
|
125
103
|
if (drawn.length < 2) return
|
|
126
104
|
const stroke = state.stroke
|
|
127
|
-
const radius = (stroke[0]?.weight ?? 0) * 2
|
|
105
|
+
const radius = (stroke[0]?.weight ?? 0) * 2
|
|
128
106
|
|
|
129
107
|
const box = state.spotlight
|
|
130
108
|
if (!hasRegion(box)) {
|
|
@@ -132,11 +110,7 @@ export const ChartLine = component2d({
|
|
|
132
110
|
return
|
|
133
111
|
}
|
|
134
112
|
|
|
135
|
-
//
|
|
136
|
-
// inside the region are re-drawn over it at full strength. Two passes rather
|
|
137
|
-
// than one dim + one bright *complementary* pair, so the bright run has
|
|
138
|
-
// continuous geometry through the region and its joins round the way an
|
|
139
|
-
// unspotlit line's do — and so the boundary lands exactly on the region edge.
|
|
113
|
+
// Dim the whole line, then redraw the stretches inside the region at full strength: the bright run keeps continuous geometry and round joins, and the boundary lands on the region edge.
|
|
140
114
|
ctx.draw(
|
|
141
115
|
new Graphics2D()
|
|
142
116
|
.line({ points: drawn, radius })
|
|
@@ -144,9 +118,7 @@ export const ChartLine = component2d({
|
|
|
144
118
|
.opacity(Math.max(0, Math.min(1, state.dimOpacity)))
|
|
145
119
|
)
|
|
146
120
|
|
|
147
|
-
// One `draw` per run: shapes chained before
|
|
148
|
-
// single surface, and stroking a union of disjoint open paths doesn't paint
|
|
149
|
-
// — so a line that leaves the region and comes back would lose both halves.
|
|
121
|
+
// One `draw` per run: shapes chained before `stroke()` combine into one surface, and stroking a union of disjoint open paths paints nothing.
|
|
150
122
|
for (const run of clipPolylineToBox(drawn, box)) {
|
|
151
123
|
ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))
|
|
152
124
|
}
|
|
@@ -7,8 +7,9 @@ import {
|
|
|
7
7
|
type Fill,
|
|
8
8
|
type FillResolved,
|
|
9
9
|
type NodeOf,
|
|
10
|
-
// Named so this component's emitted type reaches `Node2D` through the sdk, not core.
|
|
10
|
+
// Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.
|
|
11
11
|
type Node2D as _Node2D,
|
|
12
|
+
type Node2DProps as _Node2DProps,
|
|
12
13
|
type Stroke,
|
|
13
14
|
type StrokeResolved,
|
|
14
15
|
} from "@motionscript/sdk"
|
|
@@ -23,29 +24,20 @@ import {
|
|
|
23
24
|
} from "./shared"
|
|
24
25
|
|
|
25
26
|
/**
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* It draws only the *marking*; fading the series outside the region is
|
|
32
|
-
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
33
|
-
* the two can't disagree about where the boundary is.
|
|
34
|
-
*
|
|
35
|
-
* Only bounded edges get a rule: a region given just an `x` range spans the full
|
|
36
|
-
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
37
|
-
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
27
|
+
* The call-out of a {@link LineChart}: a washed rectangle with a dashed rule on
|
|
28
|
+
* each bounded edge, drawn from the pre-mapped `box`. Dimming the series outside
|
|
29
|
+
* is {@link ChartLine}'s job, clipped against the same box so the two agree on
|
|
30
|
+
* the boundary. An unbounded edge is the plot's own border, and a rule there
|
|
31
|
+
* would assert a limit the author did not set.
|
|
38
32
|
*/
|
|
39
33
|
export const ChartRegion = component2d({
|
|
40
34
|
key: "chartRegion",
|
|
41
35
|
state: {
|
|
42
|
-
/**
|
|
36
|
+
/** In this node's pixel space (origin at centre, y-up), mapped by the parent. A degenerate box draws nothing. */
|
|
43
37
|
box: fresh<RegionBox>(() => EMPTY_REGION_BOX),
|
|
44
|
-
/** Dashed rule marking each *bounded* edge of the box. */
|
|
45
38
|
stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
46
|
-
/** Wash filling the box, under the series lines. */
|
|
47
39
|
fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
48
|
-
/**
|
|
40
|
+
/** Driven by the chart's `regionReveal`, so the rules and the series' dimming move as one. */
|
|
49
41
|
reveal: 0,
|
|
50
42
|
},
|
|
51
43
|
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
@@ -61,18 +53,13 @@ export const ChartRegion = component2d({
|
|
|
61
53
|
const cx = (box.left + box.right) / 2
|
|
62
54
|
const cy = (box.bottom + box.top) / 2
|
|
63
55
|
|
|
64
|
-
// Wash first, so the rules sit over their own tint.
|
|
65
56
|
if (state.fill.length > 0) {
|
|
66
57
|
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))
|
|
67
58
|
}
|
|
68
59
|
|
|
69
|
-
// One rule per bounded edge, growing from the region's centre outward as
|
|
70
|
-
// `reveal` climbs — the same "trace it in" beat as the series lines.
|
|
71
60
|
if (state.stroke.length === 0) return
|
|
72
61
|
|
|
73
|
-
// One `draw` per rule
|
|
74
|
-
// shapes chained before a `stroke()` are combined into one surface, and
|
|
75
|
-
// stroking a union of disjoint open paths doesn't paint.
|
|
62
|
+
// One `draw` per rule: stroking a union of disjoint open paths paints nothing.
|
|
76
63
|
const rule = (points: { x: number; y: number }[]) =>
|
|
77
64
|
ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))
|
|
78
65
|
|
|
@@ -7,67 +7,50 @@ import {
|
|
|
7
7
|
textOps,
|
|
8
8
|
type NodeOf,
|
|
9
9
|
type Node2D,
|
|
10
|
+
type Node2DProps as _Node2DProps,
|
|
10
11
|
} from "@motionscript/sdk";
|
|
12
|
+
import { enterBudget } from "@motionscript/sdk/component";
|
|
11
13
|
|
|
12
14
|
import { asParts, fresh } from "../kit/entries";
|
|
13
15
|
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from "../kit/motion";
|
|
14
16
|
import {
|
|
15
17
|
DEFAULT_X_AXIS,
|
|
16
|
-
enterBudget,
|
|
17
18
|
type AxisConfig,
|
|
18
19
|
type Range,
|
|
19
20
|
} from "../kit/shared";
|
|
20
21
|
import { markerCaption } from "../kit/vertical-axis";
|
|
21
22
|
|
|
22
|
-
/** How far a marker starts above its slot when it enters, in px. */
|
|
23
23
|
const SLIDE = 24;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* The horizontal axis of a {@link LineChart}: a
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* Markers are always placed **by value** across the range, whatever they say:
|
|
32
|
-
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
33
|
-
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
34
|
-
* slot and has no scale at all — the two only look alike. What the values are
|
|
35
|
-
* captioned *as* is the chart's to decide, in `captions`.
|
|
36
|
-
*
|
|
37
|
-
* `enter` staggers the markers in **left-to-right**: each starts lifted a
|
|
38
|
-
* little above its slot and transparent, then fades and slides down into place.
|
|
26
|
+
* The horizontal axis of a {@link LineChart}: a row of {@link Text} markers, the
|
|
27
|
+
* mirror of `VerticalAxis` (bound text and positions, landed resting state).
|
|
28
|
+
* Markers are placed by value across the range, whatever they say: `2026-03`
|
|
29
|
+
* sits three months along, not three slots along, unlike a bar chart's axis.
|
|
39
30
|
*/
|
|
40
31
|
export const HorizontalAxis = component2d({
|
|
41
32
|
key: "horizontalAxis",
|
|
42
33
|
state: {
|
|
43
|
-
/** `[min, max]` of the horizontal scale the markers are positioned within. */
|
|
44
34
|
range: fresh<Range>(() => [0, 1]),
|
|
45
|
-
/** Tick values
|
|
35
|
+
/** Tick values in data units. */
|
|
46
36
|
markers: fresh<number[]>(() => []),
|
|
47
|
-
/**
|
|
48
|
-
* How each marker is captioned, one per entry of `markers` and in its order.
|
|
49
|
-
* Empty (the default), or short, captions a marker with its bare numeric
|
|
50
|
-
* reading; a chart whose x column names months or categories writes those.
|
|
51
|
-
*/
|
|
37
|
+
/** One caption per marker in its order; a missing one reads as the bare numeric value. */
|
|
52
38
|
captions: fresh<string[]>(() => []),
|
|
53
|
-
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
54
39
|
axis: Types.custom<AxisConfig>(DEFAULT_X_AXIS),
|
|
55
|
-
/** Caption
|
|
40
|
+
/** Caption centred beneath the markers; empty hides it. */
|
|
56
41
|
label: "",
|
|
57
42
|
arrivals: arrivalsEntry(),
|
|
58
43
|
},
|
|
59
|
-
// A
|
|
44
|
+
// A node made of markers would otherwise hug them.
|
|
60
45
|
defaults: { width: "fill", height: "fill" },
|
|
61
46
|
children: (state) => {
|
|
62
47
|
const tickPad = insetsOps.resolve(state.axis.tickPadding).top;
|
|
63
48
|
const titlePad = insetsOps.resolve(state.axis.titlePadding).top;
|
|
64
49
|
|
|
65
50
|
const column: Node2D[] = [];
|
|
66
|
-
// The column's parent is the axis
|
|
51
|
+
// The column's parent is the axis, whose box the markers are placed in.
|
|
67
52
|
const box = () => (column[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 };
|
|
68
|
-
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
69
53
|
const sorted = () => [...state.markers].sort((a, b) => a - b);
|
|
70
|
-
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
71
54
|
const fracAt = (value: number | undefined) => {
|
|
72
55
|
if (value === undefined) return 0;
|
|
73
56
|
const [min, max] = state.range;
|
|
@@ -84,12 +67,7 @@ export const HorizontalAxis = component2d({
|
|
|
84
67
|
x: () => {
|
|
85
68
|
const width = box().width;
|
|
86
69
|
const centred = (fracAt(sorted()[i]) - 0.5) * width;
|
|
87
|
-
// Held inside the
|
|
88
|
-
// last marker is centred on the last grid line, so half of `2026-06`
|
|
89
|
-
// — or of `3300` — would be drawn outside the node's box and outside
|
|
90
|
-
// the rectangle the editor draws around it. Only the right edge is
|
|
91
|
-
// held, because the left one has the vertical axis's whole gutter
|
|
92
|
-
// beyond it, and a marker overhanging into that is inside the chart.
|
|
70
|
+
// Held inside the right edge, the chart's own: the last marker is centred on the last grid line, so half of it would fall outside the box. The left edge has the vertical axis's gutter beyond it.
|
|
93
71
|
const limit = width / 2 - marker.layoutBounds.width / 2;
|
|
94
72
|
return Math.min(centred, limit);
|
|
95
73
|
},
|
|
@@ -117,13 +95,7 @@ export const HorizontalAxis = component2d({
|
|
|
117
95
|
return asParts(column);
|
|
118
96
|
},
|
|
119
97
|
commands: {
|
|
120
|
-
/**
|
|
121
|
-
* Stagger the markers in left to right, then slide the caption in after
|
|
122
|
-
* them. Its first frame arms them all: lifted by `slide` and transparent.
|
|
123
|
-
*
|
|
124
|
-
* The timeline's duration is the **whole** entrance — see
|
|
125
|
-
* `VerticalAxis.enter` and {@link enterBudget}.
|
|
126
|
-
*/
|
|
98
|
+
/** Stagger markers in left to right, then the caption. The duration is the whole entrance ({@link enterBudget}). */
|
|
127
99
|
enter: {
|
|
128
100
|
args: {
|
|
129
101
|
stagger: Types.custom<number | undefined>(undefined),
|
|
@@ -139,7 +111,6 @@ export const HorizontalAxis = component2d({
|
|
|
139
111
|
if (count === 0) return arm;
|
|
140
112
|
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
|
|
141
113
|
const ease = frameEase(timeline);
|
|
142
|
-
// Left marker leads: the row is already left → right.
|
|
143
114
|
const markers = state.markers.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
|
|
144
115
|
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
|
|
145
116
|
return timeline.together([arm, beats(timeline, [...markers, ...label])]);
|
package/src/line-chart/index.ts
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The line chart: a cartesian plot with a traced polyline, spotlit regions and
|
|
3
|
-
* a staggered entrance.
|
|
4
|
-
*
|
|
5
|
-
* {@link LineChart} composes the parts below plus the shared ones in the kit
|
|
6
|
-
* (the plot panel, the value axis, the legend); each part is exported too, so
|
|
7
|
-
* another node type can reuse one on its own.
|
|
8
|
-
*
|
|
9
|
-
* These files are what a copy of the line chart takes (`registry.json`). Everything they reach for
|
|
10
|
-
* that is *not* here comes from the kit and stays a dependency — see
|
|
11
|
-
* `../engine.ts` for why that line is where it is.
|
|
12
|
-
*/
|
|
13
1
|
export { LineChart, lineChartDomains } from "./line-chart"
|
|
14
|
-
export type { LineChartDomains,
|
|
2
|
+
export type { LineChartDomains, LineChartValues } from "./line-chart"
|
|
15
3
|
export { ChartRegion } from "./chart-region"
|
|
16
4
|
export { ChartLine } from "./chart-line"
|
|
17
5
|
export { HorizontalAxis } from "./horizontal-axis"
|