@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,17 +1,12 @@
|
|
|
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 { Graphics2D, Node2D, fillOps, strokeOps, property, } from "@motionscript/sdk";
|
|
1
|
+
import { Graphics2D, Types, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
|
|
2
|
+
import { fresh } from "../kit/entries.js";
|
|
3
|
+
import { loadPaints } from "../kit/paints.js";
|
|
8
4
|
import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
|
|
9
|
-
import { declarePaints } from "@motionscript/sdk/component";
|
|
10
5
|
/**
|
|
11
6
|
* The **region call-out** of a {@link LineChart}: a washed rectangle over the
|
|
12
7
|
* plot with a dashed rule down each edge the author actually bounded. Sized and
|
|
13
8
|
* positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather
|
|
14
|
-
* than its own
|
|
9
|
+
* than its own box — the region already carries the plot geometry.
|
|
15
10
|
*
|
|
16
11
|
* It draws only the *marking*; fading the series outside the region is
|
|
17
12
|
* {@link ChartLine}'s job (it clips its own polyline against the same box), so
|
|
@@ -21,20 +16,20 @@ import { declarePaints } from "@motionscript/sdk/component";
|
|
|
21
16
|
* plot height, so its top and bottom edges are the plot's own border, not a data
|
|
22
17
|
* bound — drawing dashes there would assert a limit the author didn't set.
|
|
23
18
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const box =
|
|
19
|
+
export const ChartRegion = component2d({
|
|
20
|
+
key: "chartRegion",
|
|
21
|
+
state: {
|
|
22
|
+
box: fresh(() => EMPTY_REGION_BOX),
|
|
23
|
+
stroke: Types.custom(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
|
|
24
|
+
fill: Types.custom(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
|
|
25
|
+
reveal: 0,
|
|
26
|
+
},
|
|
27
|
+
load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
|
|
28
|
+
render: (ctx, state) => {
|
|
29
|
+
const box = state.box;
|
|
35
30
|
if (!hasRegion(box))
|
|
36
31
|
return;
|
|
37
|
-
const r = Math.max(0, Math.min(1,
|
|
32
|
+
const r = Math.max(0, Math.min(1, state.reveal));
|
|
38
33
|
if (r <= 0)
|
|
39
34
|
return;
|
|
40
35
|
const width = box.right - box.left;
|
|
@@ -42,60 +37,27 @@ export class ChartRegion extends Node2D {
|
|
|
42
37
|
const cx = (box.left + box.right) / 2;
|
|
43
38
|
const cy = (box.bottom + box.top) / 2;
|
|
44
39
|
// Wash first, so the rules sit over their own tint.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
ctx.draw(new Graphics2D()
|
|
48
|
-
.rect({ x: cx, y: cy, width, height })
|
|
49
|
-
.fill(this.fill)
|
|
50
|
-
.opacity(r));
|
|
40
|
+
if (state.fill.length > 0) {
|
|
41
|
+
ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
|
|
51
42
|
}
|
|
52
43
|
// One rule per bounded edge, growing from the region's centre outward as
|
|
53
44
|
// `reveal` climbs — the same "trace it in" beat as the series lines.
|
|
54
|
-
|
|
55
|
-
if (stroke.length === 0)
|
|
45
|
+
if (state.stroke.length === 0)
|
|
56
46
|
return;
|
|
57
47
|
// One `draw` per rule rather than four line ops under a single paint:
|
|
58
48
|
// shapes chained before a `stroke()` are combined into one surface, and
|
|
59
49
|
// stroking a union of disjoint open paths doesn't paint.
|
|
60
|
-
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(
|
|
50
|
+
const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
|
|
61
51
|
if (box.xBounded) {
|
|
62
52
|
const half = (height / 2) * r;
|
|
63
|
-
for (const x of [box.left, box.right])
|
|
64
|
-
rule([
|
|
65
|
-
{ x, y: cy - half },
|
|
66
|
-
{ x, y: cy + half },
|
|
67
|
-
]);
|
|
68
|
-
}
|
|
53
|
+
for (const x of [box.left, box.right])
|
|
54
|
+
rule([{ x, y: cy - half }, { x, y: cy + half }]);
|
|
69
55
|
}
|
|
70
56
|
if (box.yBounded) {
|
|
71
57
|
const half = (width / 2) * r;
|
|
72
|
-
for (const y of [box.bottom, box.top])
|
|
73
|
-
rule([
|
|
74
|
-
{ x: cx - half, y },
|
|
75
|
-
{ x: cx + half, y },
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
58
|
+
for (const y of [box.bottom, box.top])
|
|
59
|
+
rule([{ x: cx - half, y }, { x: cx + half, y }]);
|
|
78
60
|
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
__decorate([
|
|
82
|
-
property({ default: () => EMPTY_REGION_BOX })
|
|
83
|
-
], ChartRegion.prototype, "box", void 0);
|
|
84
|
-
__decorate([
|
|
85
|
-
property({
|
|
86
|
-
default: DEFAULT_CHART_THEME.region.stroke,
|
|
87
|
-
mapper: strokeOps.resolve,
|
|
88
|
-
tween: strokeOps.lerp,
|
|
89
|
-
})
|
|
90
|
-
], ChartRegion.prototype, "stroke", void 0);
|
|
91
|
-
__decorate([
|
|
92
|
-
property({
|
|
93
|
-
default: DEFAULT_CHART_THEME.region.fill,
|
|
94
|
-
mapper: fillOps.resolve,
|
|
95
|
-
tween: fillOps.lerp,
|
|
96
|
-
})
|
|
97
|
-
], ChartRegion.prototype, "fill", void 0);
|
|
98
|
-
__decorate([
|
|
99
|
-
property({ default: 0 })
|
|
100
|
-
], ChartRegion.prototype, "reveal", void 0);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
101
63
|
//# sourceMappingURL=chart-region.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,OAAO,EACP,SAAS,GASV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AAqBjB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACrC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACL,GAAG,EAAE,KAAK,CAAY,GAAG,EAAE,CAAC,gBAAgB,CAAC;QAC7C,MAAM,EAAE,KAAK,CAAC,MAAM,CAA2B,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,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,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QACzF,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n fillOps,\r\n strokeOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Node2DProps,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport {\r\n DEFAULT_CHART_THEME,\r\n EMPTY_REGION_BOX,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\nexport interface ChartRegionProps extends Node2DProps {\r\n /**\r\n * The highlighted slice, already resolved into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box\r\n * draws nothing.\r\n */\r\n box: RegionBox\r\n /** Dashed rule marking each *bounded* edge of the box. */\r\n stroke: Stroke\r\n /** Wash filling the box, under the series lines. */\r\n fill: Fill\r\n /**\r\n * Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven\r\n * by the chart's own `regionReveal`, so the rules and the series' dimming move\r\n * as one.\r\n */\r\n reveal: number\r\n}\r\n\r\n/**\r\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\r\n * plot with a dashed rule down each edge the author actually bounded. Sized and\r\n * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather\r\n * than its own box — the region already carries the plot geometry.\r\n *\r\n * It draws only the *marking*; fading the series outside the region is\r\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\r\n * the two can't disagree about where the boundary is.\r\n *\r\n * Only bounded edges get a rule: a region given just an `x` range spans the full\r\n * plot height, so its top and bottom edges are the plot's own border, not a data\r\n * bound — drawing dashes there would assert a limit the author didn't set.\r\n */\r\nexport const ChartRegion = component2d({\r\n key: \"chartRegion\",\r\n state: {\r\n box: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),\r\n reveal: 0,\r\n },\r\n load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),\r\n render: (ctx, state) => {\r\n const box = state.box\r\n if (!hasRegion(box)) return\r\n\r\n const r = Math.max(0, Math.min(1, state.reveal))\r\n if (r <= 0) return\r\n\r\n const width = box.right - box.left\r\n const height = box.top - box.bottom\r\n const cx = (box.left + box.right) / 2\r\n const cy = (box.bottom + box.top) / 2\r\n\r\n // Wash first, so the rules sit over their own tint.\r\n if (state.fill.length > 0) {\r\n ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))\r\n }\r\n\r\n // One rule per bounded edge, growing from the region's centre outward as\r\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\r\n if (state.stroke.length === 0) return\r\n\r\n // One `draw` per rule rather than four line ops under a single paint:\r\n // shapes chained before a `stroke()` are combined into one surface, and\r\n // stroking a union of disjoint open paths doesn't paint.\r\n const rule = (points: { x: number; y: number }[]) =>\r\n ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))\r\n\r\n if (box.xBounded) {\r\n const half = (height / 2) * r\r\n for (const x of [box.left, box.right]) rule([{ x, y: cy - half }, { x, y: cy + half }])\r\n }\r\n if (box.yBounded) {\r\n const half = (width / 2) * r\r\n for (const y of [box.bottom, box.top]) rule([{ x: cx - half, y }, { x: cx + half, y }])\r\n }\r\n },\r\n})\r\n\r\nexport type ChartRegion = NodeOf<typeof ChartRegion>\r\n"]}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type NodeOf, type Node2D, type Node2DProps } from "@motionscript/sdk";
|
|
2
|
+
import { type Arrival } from "../kit/motion.js";
|
|
2
3
|
import { type AxisConfig, type Range } from "../kit/shared.js";
|
|
3
|
-
import { type Seekable } from "@motionscript/sdk/component";
|
|
4
4
|
export interface HorizontalAxisProps extends Node2DProps {
|
|
5
5
|
/** `[min, max]` of the horizontal scale the markers are positioned within. */
|
|
6
6
|
range: Range;
|
|
7
7
|
/** Tick values (in data units) to draw along the axis. */
|
|
8
8
|
markers: number[];
|
|
9
|
+
/**
|
|
10
|
+
* How each marker is captioned, one per entry of `markers` and in its order.
|
|
11
|
+
* Empty (the default), or short, captions a marker with its bare numeric
|
|
12
|
+
* reading; a chart whose x column names months or categories writes those.
|
|
13
|
+
*/
|
|
14
|
+
captions: string[];
|
|
9
15
|
/** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
|
|
10
16
|
axis: AxisConfig;
|
|
11
17
|
/**
|
|
@@ -14,7 +20,7 @@ export interface HorizontalAxisProps extends Node2DProps {
|
|
|
14
20
|
*/
|
|
15
21
|
label: string;
|
|
16
22
|
}
|
|
17
|
-
/** How a tick value is captioned — see {@link
|
|
23
|
+
/** How a tick value is captioned — see {@link HorizontalAxisProps.captions}. */
|
|
18
24
|
export type MarkerLabel = (value: number) => string;
|
|
19
25
|
/**
|
|
20
26
|
* The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,
|
|
@@ -26,60 +32,30 @@ export type MarkerLabel = (value: number) => string;
|
|
|
26
32
|
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
27
33
|
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
28
34
|
* slot and has no scale at all — the two only look alike. What the values are
|
|
29
|
-
* captioned *as* is the chart's to decide; see {@link
|
|
35
|
+
* captioned *as* is the chart's to decide; see {@link HorizontalAxisProps.captions}.
|
|
30
36
|
*
|
|
31
|
-
*
|
|
37
|
+
* `enter` staggers the markers in **left-to-right**: each starts lifted a
|
|
32
38
|
* little above its slot and transparent, then fades and slides down into place.
|
|
33
39
|
*/
|
|
34
|
-
export declare
|
|
35
|
-
range: Range
|
|
36
|
-
markers: number[]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
56
|
-
private get sortedMarkers();
|
|
57
|
-
private valueAt;
|
|
58
|
-
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
59
|
-
private fracAt;
|
|
60
|
-
constructor(props?: NodeConfig<HorizontalAxis, HorizontalAxisProps>);
|
|
61
|
-
/**
|
|
62
|
-
* Primes every marker (and the caption) at its pre-entrance state: lifted
|
|
63
|
-
* above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.
|
|
64
|
-
*/
|
|
65
|
-
arm(slide?: number): void;
|
|
66
|
-
/**
|
|
67
|
-
* Stagger the markers in left to right, then slide the caption in after them.
|
|
68
|
-
*
|
|
69
|
-
* A {@link Seekable} rather than a generator. The offsets were always static —
|
|
70
|
-
* `i * step` per marker — but expressed as `wait` inside a generator they only
|
|
71
|
-
* existed while it ran, so knowing what the axis looked like partway through
|
|
72
|
-
* meant running it from zero. Placed explicitly, the same stagger can be asked
|
|
73
|
-
* for a time, which is what lets a chart scene scrub in constant time.
|
|
74
|
-
*
|
|
75
|
-
* `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and
|
|
76
|
-
* {@link enterBudget}.
|
|
77
|
-
*/
|
|
78
|
-
enter(args: CommandArgs<{
|
|
79
|
-
stagger?: number;
|
|
80
|
-
slide?: number;
|
|
81
|
-
}> & {
|
|
82
|
-
duration: number;
|
|
83
|
-
}): Seekable;
|
|
84
|
-
}
|
|
40
|
+
export declare const HorizontalAxis: import("@motionscript/sdk").Component<"horizontalAxis", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
41
|
+
readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
|
|
42
|
+
readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
43
|
+
readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
44
|
+
readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
|
|
45
|
+
readonly label: "";
|
|
46
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
47
|
+
}>, {
|
|
48
|
+
readonly enter: {
|
|
49
|
+
readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
|
|
50
|
+
readonly slide: import("@motionscript/sdk").Type<number, number, false>;
|
|
51
|
+
};
|
|
52
|
+
}, null, Node2D<Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
|
|
53
|
+
readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
|
|
54
|
+
readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
|
|
55
|
+
readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
|
|
56
|
+
readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
|
|
57
|
+
readonly label: "";
|
|
58
|
+
readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
|
|
59
|
+
}>, null>>;
|
|
60
|
+
export type HorizontalAxis = NodeOf<typeof HorizontalAxis>;
|
|
85
61
|
//# sourceMappingURL=horizontal-axis.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"horizontal-axis.d.ts","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"horizontal-axis.d.ts","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAGvB,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,8EAA8E;IAC9E,KAAK,EAAE,KAAK,CAAC;IACb,0DAA0D;IAC1D,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,oFAAoF;IACpF,IAAI,EAAE,UAAU,CAAC;IACjB;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,gFAAgF;AAChF,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;UAoGzB,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
import { command, Node2D, Rect, Text, easeOut, property, insetsOps, textOps, } from "@motionscript/sdk";
|
|
8
|
-
import { DEFAULT_X_AXIS, enterBudget, formatMarker, } from "../kit/shared.js";
|
|
9
|
-
import { at, compose } from "@motionscript/sdk/component";
|
|
1
|
+
import { Rect, Text, Types, component2d, insetsOps, textOps, } from "@motionscript/sdk";
|
|
2
|
+
import { asParts, fresh } from "../kit/entries.js";
|
|
3
|
+
import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "../kit/motion.js";
|
|
4
|
+
import { DEFAULT_X_AXIS, enterBudget, } from "../kit/shared.js";
|
|
5
|
+
import { markerCaption } from "../kit/vertical-axis.js";
|
|
10
6
|
/** How far a marker starts above its slot when it enters, in px. */
|
|
11
7
|
const SLIDE = 24;
|
|
12
8
|
/**
|
|
@@ -19,57 +15,48 @@ const SLIDE = 24;
|
|
|
19
15
|
* `2026-03` sits three months along, not three slots along. That is what keeps
|
|
20
16
|
* it distinct from a bar chart's bottom axis, which centres a caption on each
|
|
21
17
|
* slot and has no scale at all — the two only look alike. What the values are
|
|
22
|
-
* captioned *as* is the chart's to decide; see {@link
|
|
18
|
+
* captioned *as* is the chart's to decide; see {@link HorizontalAxisProps.captions}.
|
|
23
19
|
*
|
|
24
|
-
*
|
|
20
|
+
* `enter` staggers the markers in **left-to-right**: each starts lifted a
|
|
25
21
|
* little above its slot and transparent, then fades and slides down into place.
|
|
26
22
|
*/
|
|
27
|
-
export
|
|
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
|
-
return 0;
|
|
56
|
-
const [min, max] = this.range;
|
|
57
|
-
return max <= min ? 0 : (v - min) / (max - min);
|
|
58
|
-
}
|
|
59
|
-
constructor(props) {
|
|
60
|
-
super(props);
|
|
61
|
-
const tickPad = insetsOps.resolve(this.axis.tickPadding).top;
|
|
62
|
-
const titlePad = insetsOps.resolve(this.axis.titlePadding).top;
|
|
63
|
-
this.markerNodes = this.markers.map((_, i) => {
|
|
23
|
+
export const HorizontalAxis = component2d({
|
|
24
|
+
key: "horizontalAxis",
|
|
25
|
+
state: {
|
|
26
|
+
range: fresh(() => [0, 1]),
|
|
27
|
+
markers: fresh(() => []),
|
|
28
|
+
captions: fresh(() => []),
|
|
29
|
+
axis: Types.custom(DEFAULT_X_AXIS),
|
|
30
|
+
label: "",
|
|
31
|
+
arrivals: arrivalsEntry(),
|
|
32
|
+
},
|
|
33
|
+
// A plain node filled its parent; one made of its markers would hug them.
|
|
34
|
+
defaults: { width: "fill", height: "fill" },
|
|
35
|
+
children: (state) => {
|
|
36
|
+
const tickPad = insetsOps.resolve(state.axis.tickPadding).top;
|
|
37
|
+
const titlePad = insetsOps.resolve(state.axis.titlePadding).top;
|
|
38
|
+
const column = [];
|
|
39
|
+
// The column's parent is the axis: its box is what the markers are placed in.
|
|
40
|
+
const box = () => column[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
|
|
41
|
+
/** The live tick values, left → right — re-read every frame, not snapshotted. */
|
|
42
|
+
const sorted = () => [...state.markers].sort((a, b) => a - b);
|
|
43
|
+
/** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
|
|
44
|
+
const fracAt = (value) => {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return 0;
|
|
47
|
+
const [min, max] = state.range;
|
|
48
|
+
return max <= min ? 0 : (value - min) / (max - min);
|
|
49
|
+
};
|
|
50
|
+
const markers = state.markers.map((_, i) => {
|
|
64
51
|
const marker = new Text({
|
|
65
|
-
...textOps.styleProps(
|
|
52
|
+
...textOps.styleProps(state.axis.labelStyle),
|
|
66
53
|
text: () => {
|
|
67
|
-
const
|
|
68
|
-
return
|
|
54
|
+
const value = sorted()[i];
|
|
55
|
+
return value === undefined ? "" : markerCaption(state, value);
|
|
69
56
|
},
|
|
70
57
|
x: () => {
|
|
71
|
-
const width =
|
|
72
|
-
const centred = (
|
|
58
|
+
const width = box().width;
|
|
59
|
+
const centred = (fracAt(sorted()[i]) - 0.5) * width;
|
|
73
60
|
// Held inside the axis's right edge, which is also the *chart's*: the
|
|
74
61
|
// last marker is centred on the last grid line, so half of `2026-06`
|
|
75
62
|
// — or of `3300` — would be drawn outside the node's box and outside
|
|
@@ -79,80 +66,55 @@ export class HorizontalAxis extends Node2D {
|
|
|
79
66
|
const limit = width / 2 - marker.layoutBounds.width / 2;
|
|
80
67
|
return Math.min(centred, limit);
|
|
81
68
|
},
|
|
69
|
+
opacity: () => arrivalOf(state.arrivals, i).opacity,
|
|
70
|
+
y: () => arrivalOf(state.arrivals, i).shift,
|
|
82
71
|
});
|
|
83
72
|
return marker;
|
|
84
73
|
});
|
|
85
74
|
const children = [
|
|
86
|
-
new Rect({
|
|
87
|
-
width: "fill",
|
|
88
|
-
height: "hug",
|
|
89
|
-
padding: { top: tickPad },
|
|
90
|
-
children: this.markerNodes,
|
|
91
|
-
}),
|
|
75
|
+
new Rect({ width: "fill", height: "hug", padding: { top: tickPad }, children: markers }),
|
|
92
76
|
];
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
...textOps.styleProps(
|
|
96
|
-
text:
|
|
97
|
-
|
|
98
|
-
|
|
77
|
+
if (state.label !== "") {
|
|
78
|
+
children.push(new Text({
|
|
79
|
+
...textOps.styleProps(state.axis.titleStyle),
|
|
80
|
+
text: state.label,
|
|
81
|
+
opacity: () => arrivalOf(state.arrivals, "label").opacity,
|
|
82
|
+
y: () => arrivalOf(state.arrivals, "label").shift,
|
|
83
|
+
}));
|
|
99
84
|
}
|
|
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
|
-
return compose([
|
|
136
|
-
...markers,
|
|
137
|
-
...(this.labelNode
|
|
138
|
-
? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, y: 0 }, duration: caption, easing }))]
|
|
139
|
-
: []),
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
__decorate([
|
|
144
|
-
property({ default: () => [0, 1] })
|
|
145
|
-
], HorizontalAxis.prototype, "range", void 0);
|
|
146
|
-
__decorate([
|
|
147
|
-
property({ default: () => [] })
|
|
148
|
-
], HorizontalAxis.prototype, "markers", void 0);
|
|
149
|
-
__decorate([
|
|
150
|
-
property({ default: DEFAULT_X_AXIS })
|
|
151
|
-
], HorizontalAxis.prototype, "axis", void 0);
|
|
152
|
-
__decorate([
|
|
153
|
-
property({ default: "" })
|
|
154
|
-
], HorizontalAxis.prototype, "label", void 0);
|
|
155
|
-
__decorate([
|
|
156
|
-
command()
|
|
157
|
-
], HorizontalAxis.prototype, "enter", null);
|
|
85
|
+
column.push(new Rect({ flow: "vertical", gap: titlePad, height: "hug", width: "fill", children }));
|
|
86
|
+
return asParts(column);
|
|
87
|
+
},
|
|
88
|
+
commands: {
|
|
89
|
+
/**
|
|
90
|
+
* Stagger the markers in left to right, then slide the caption in after
|
|
91
|
+
* them. Its first frame arms them all: lifted by `slide` and transparent.
|
|
92
|
+
*
|
|
93
|
+
* The timeline's duration is the **whole** entrance — see
|
|
94
|
+
* `VerticalAxis.enter` and {@link enterBudget}.
|
|
95
|
+
*/
|
|
96
|
+
enter: {
|
|
97
|
+
args: {
|
|
98
|
+
stagger: Types.custom(undefined),
|
|
99
|
+
slide: Types.number(SLIDE),
|
|
100
|
+
},
|
|
101
|
+
run: (timeline, state) => {
|
|
102
|
+
const { stagger, slide } = timeline.args;
|
|
103
|
+
const count = state.markers.length;
|
|
104
|
+
const captioned = state.label !== "";
|
|
105
|
+
const from = { opacity: 0, shift: slide };
|
|
106
|
+
const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])];
|
|
107
|
+
const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));
|
|
108
|
+
if (count === 0)
|
|
109
|
+
return arm;
|
|
110
|
+
const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
|
|
111
|
+
const ease = frameEase(timeline);
|
|
112
|
+
// Left marker leads: the row is already left → right.
|
|
113
|
+
const markers = state.markers.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
|
|
114
|
+
const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
|
|
115
|
+
return timeline.together([arm, beats(timeline, [...markers, ...label])]);
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
});
|
|
158
120
|
//# sourceMappingURL=horizontal-axis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"horizontal-axis.js","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB,MAAM,6BAA6B,CAAA;AAgBxE,oEAAoE;AACpE,MAAM,KAAK,GAAG,EAAE,CAAC;AAKjB;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,cAAe,SAAQ,MAA2B;IAM7D;;;;;;;;;;OAUG;IACH,QAAQ,GAAgB,YAAY,CAAC;IAErC,+EAA+E;IACvE,WAAW,GAAW,EAAE,CAAC;IACjC,u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motionscript/sdk\";\r\n\r\nimport {\r\n DEFAULT_X_AXIS,\r\n enterBudget,\r\n formatMarker,\r\n type AxisConfig,\r\n type Range,\r\n} from \"../kit/shared\";\r\nimport { at, compose, type Seekable } from \"@motionscript/sdk/component\"\r\n\r\nexport interface HorizontalAxisProps extends Node2DProps {\r\n /** `[min, max]` of the horizontal scale the markers are positioned within. */\r\n range: Range;\r\n /** Tick values (in data units) to draw along the axis. */\r\n markers: number[];\r\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\r\n axis: AxisConfig;\r\n /**\r\n * Caption drawn centred in the gutter beneath the marker row. Empty string\r\n * (the default) hides it.\r\n */\r\n label: string;\r\n}\r\n\r\n/** How far a marker starts above its slot when it enters, in px. */\r\nconst SLIDE = 24;\r\n\r\n/** How a tick value is captioned — see {@link HorizontalAxis.labelFor}. */\r\nexport type MarkerLabel = (value: number) => string;\r\n\r\n/**\r\n * The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,\r\n * one per marker value, running left-to-right. Pure layout — the mirror of the\r\n * kit's `VerticalAxis`, including its bound (not snapshotted) marker text and\r\n * positions, and its landed resting state.\r\n *\r\n * Markers are always placed **by value** across the range, whatever they say:\r\n * `2026-03` sits three months along, not three slots along. That is what keeps\r\n * it distinct from a bar chart's bottom axis, which centres a caption on each\r\n * slot and has no scale at all — the two only look alike. What the values are\r\n * captioned *as* is the chart's to decide; see {@link labelFor}.\r\n *\r\n * {@link enter} staggers the markers in **left-to-right**: each starts lifted a\r\n * little above its slot and transparent, then fades and slides down into place.\r\n */\r\nexport class HorizontalAxis extends Node2D<HorizontalAxisProps> {\r\n @property({ default: () => [0, 1] as Range }) declare range: Range;\r\n @property({ default: () => [] as number[] }) declare markers: number[];\r\n @property({ default: DEFAULT_X_AXIS }) declare axis: AxisConfig;\r\n @property({ default: \"\" }) declare label: string;\r\n\r\n /**\r\n * How a tick value is captioned. Defaults to the numeric formatting the\r\n * vertical axis uses; a chart whose x column names months or categories\r\n * replaces it (see `x-scale.ts`).\r\n *\r\n * A plain field rather than a `@property`, because it is a **policy, not a\r\n * value**: there is nothing to tween between two formatters, and a signal\r\n * holding a function is a signal every `set`/`to` on this node would have to\r\n * know not to touch. Read inside each marker's `text` binding, so replacing it\r\n * before the first frame is enough — which is when the chart does it.\r\n */\r\n labelFor: MarkerLabel = formatMarker;\r\n\r\n /** One text node per marker, ordered left → right, for the staggered enter. */\r\n private markerNodes: Text[] = [];\r\n /** The caption node, or null when `label` is empty. */\r\n private labelNode: Text | null = null;\r\n\r\n /** The live tick values, left → right — re-read every frame, not snapshotted. */\r\n private get sortedMarkers(): number[] {\r\n return [...this.markers].sort((a, b) => a - b);\r\n }\r\n\r\n private valueAt(index: number): number | undefined {\r\n return this.sortedMarkers[index];\r\n }\r\n\r\n /** Tick `i`'s fraction across the live `range`, 0 at the left edge. */\r\n private fracAt(index: number): number {\r\n const v = this.valueAt(index);\r\n if (v === undefined) return 0;\r\n const [min, max] = this.range;\r\n return max <= min ? 0 : (v - min) / (max - min);\r\n }\r\n\r\n constructor(props?: NodeConfig<HorizontalAxis, HorizontalAxisProps>) {\r\n super(props);\r\n\r\n const tickPad = insetsOps.resolve(this.axis.tickPadding).top;\r\n const titlePad = insetsOps.resolve(this.axis.titlePadding).top;\r\n\r\n this.markerNodes = this.markers.map((_, i) => {\r\n const marker: Text = new Text({\r\n ...textOps.styleProps(this.axis.labelStyle),\r\n text: () => {\r\n const v = this.valueAt(i);\r\n return v === undefined ? \"\" : this.labelFor(v);\r\n },\r\n x: () => {\r\n const width = this.layoutBounds.width;\r\n const centred = (this.fracAt(i) - 0.5) * width;\r\n // Held inside the axis's right edge, which is also the *chart's*: the\r\n // last marker is centred on the last grid line, so half of `2026-06`\r\n // — or of `3300` — would be drawn outside the node's box and outside\r\n // the rectangle the editor draws around it. Only the right edge is\r\n // held, because the left one has the vertical axis's whole gutter\r\n // beyond it, and a marker overhanging into that is inside the chart.\r\n const limit = width / 2 - marker.layoutBounds.width / 2;\r\n return Math.min(centred, limit);\r\n },\r\n });\r\n return marker;\r\n });\r\n\r\n const children: Node2D[] = [\r\n new Rect({\r\n width: \"fill\",\r\n height: \"hug\",\r\n padding: { top: tickPad },\r\n children: this.markerNodes,\r\n }),\r\n ];\r\n if (this.label !== \"\") {\r\n this.labelNode = new Text({\r\n ...textOps.styleProps(this.axis.titleStyle),\r\n text: this.label,\r\n });\r\n children.push(this.labelNode);\r\n }\r\n\r\n this.add(\r\n new Rect({ flow: \"vertical\", gap: titlePad, height: \"hug\", width: \"fill\", children }),\r\n );\r\n }\r\n\r\n /**\r\n * Primes every marker (and the caption) at its pre-entrance state: lifted\r\n * above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.\r\n */\r\n arm(slide = SLIDE): void {\r\n for (const marker of this.markerNodes) marker.set({ opacity: 0, y: slide });\r\n this.labelNode?.set({ opacity: 0, y: slide });\r\n }\r\n\r\n /**\r\n * Stagger the markers in left to right, then slide the caption in after them.\r\n *\r\n * A {@link Seekable} rather than a generator. The offsets were always static —\r\n * `i * step` per marker — but expressed as `wait` inside a generator they only\r\n * existed while it ran, so knowing what the axis looked like partway through\r\n * meant running it from zero. Placed explicitly, the same stagger can be asked\r\n * for a time, which is what lets a chart scene scrub in constant time.\r\n *\r\n * `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and\r\n * {@link enterBudget}.\r\n */\r\n @command()\r\n enter(\r\n args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number },\r\n ): Seekable {\r\n const { stagger, slide = SLIDE } = args.data ?? {};\r\n const duration = args.duration;\r\n const easing = args.easing ?? easeOut();\r\n const nodes = this.markerNodes;\r\n if (nodes.length === 0) return compose([]);\r\n const { step, per, caption } = enterBudget(\r\n duration,\r\n nodes.length,\r\n this.labelNode !== null,\r\n stagger,\r\n );\r\n\r\n this.arm(slide);\r\n\r\n // Left marker leads: markerNodes is already left → right.\r\n const markers = nodes.map((node, i) =>\r\n at(i * step, node.to({ data: { opacity: 1, y: 0 }, duration: per, easing })),\r\n );\r\n const lastMarkerEnds = nodes.length === 0 ? 0 : (nodes.length - 1) * step + per;\r\n\r\n return compose([\r\n ...markers,\r\n ...(this.labelNode\r\n ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, y: 0 }, duration: caption, easing }))]\r\n : []),\r\n ]);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"horizontal-axis.js","sourceRoot":"","sources":["../../src/line-chart/horizontal-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAgB,MAAM,eAAe,CAAC;AACzG,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAsBrD,oEAAoE;AACpE,MAAM,KAAK,GAAG,EAAE,CAAC;AAKjB;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;IACxC,GAAG,EAAE,gBAAgB;IACrB,KAAK,EAAE;QACL,KAAK,EAAE,KAAK,CAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,OAAO,EAAE,KAAK,CAAW,GAAG,EAAE,CAAC,EAAE,CAAC;QAClC,QAAQ,EAAE,KAAK,CAAW,GAAG,EAAE,CAAC,EAAE,CAAC;QACnC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAa,cAAc,CAAC;QAC9C,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,aAAa,EAAE;KAC1B;IACD,0EAA0E;IAC1E,QAAQ,EAAE,EAAE,KA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AAC;SACF;KACF;CACF,CAAC,CAAC","sourcesContent":["import {\r\n Rect,\r\n Text,\r\n Types,\r\n component2d,\r\n insetsOps,\r\n textOps,\r\n type NodeOf,\r\n type Node2D,\r\n type Node2DProps,\r\n} from \"@motionscript/sdk\";\r\n\r\nimport { asParts, fresh } from \"../kit/entries\";\r\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"../kit/motion\";\r\nimport {\r\n DEFAULT_X_AXIS,\r\n enterBudget,\r\n type AxisConfig,\r\n type Range,\r\n} from \"../kit/shared\";\r\nimport { markerCaption } from \"../kit/vertical-axis\";\r\n\r\nexport interface HorizontalAxisProps extends Node2DProps {\r\n /** `[min, max]` of the horizontal scale the markers are positioned within. */\r\n range: Range;\r\n /** Tick values (in data units) to draw along the axis. */\r\n markers: number[];\r\n /**\r\n * How each marker is captioned, one per entry of `markers` and in its order.\r\n * Empty (the default), or short, captions a marker with its bare numeric\r\n * reading; a chart whose x column names months or categories writes those.\r\n */\r\n captions: string[];\r\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\r\n axis: AxisConfig;\r\n /**\r\n * Caption drawn centred in the gutter beneath the marker row. Empty string\r\n * (the default) hides it.\r\n */\r\n label: string;\r\n}\r\n\r\n/** How far a marker starts above its slot when it enters, in px. */\r\nconst SLIDE = 24;\r\n\r\n/** How a tick value is captioned — see {@link HorizontalAxisProps.captions}. */\r\nexport type MarkerLabel = (value: number) => string;\r\n\r\n/**\r\n * The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,\r\n * one per marker value, running left-to-right. Pure layout — the mirror of the\r\n * kit's `VerticalAxis`, including its bound (not snapshotted) marker text and\r\n * positions, and its landed resting state.\r\n *\r\n * Markers are always placed **by value** across the range, whatever they say:\r\n * `2026-03` sits three months along, not three slots along. That is what keeps\r\n * it distinct from a bar chart's bottom axis, which centres a caption on each\r\n * slot and has no scale at all — the two only look alike. What the values are\r\n * captioned *as* is the chart's to decide; see {@link HorizontalAxisProps.captions}.\r\n *\r\n * `enter` staggers the markers in **left-to-right**: each starts lifted a\r\n * little above its slot and transparent, then fades and slides down into place.\r\n */\r\nexport const HorizontalAxis = component2d({\r\n key: \"horizontalAxis\",\r\n state: {\r\n range: fresh<Range>(() => [0, 1]),\r\n markers: fresh<number[]>(() => []),\r\n captions: fresh<string[]>(() => []),\r\n axis: Types.custom<AxisConfig>(DEFAULT_X_AXIS),\r\n label: \"\",\r\n arrivals: arrivalsEntry(),\r\n },\r\n // A plain node filled its parent; one made of its markers would hug them.\r\n defaults: { width: \"fill\", height: \"fill\" },\r\n children: (state) => {\r\n const tickPad = insetsOps.resolve(state.axis.tickPadding).top;\r\n const titlePad = insetsOps.resolve(state.axis.titlePadding).top;\r\n\r\n const column: Node2D[] = [];\r\n // The column's parent is the axis: its box is what the markers are placed in.\r\n const box = () => (column[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 };\r\n /** The live tick values, left → right — re-read every frame, not snapshotted. */\r\n const sorted = () => [...state.markers].sort((a, b) => a - b);\r\n /** Tick `i`'s fraction across the live `range`, 0 at the left edge. */\r\n const fracAt = (value: number | undefined) => {\r\n if (value === undefined) return 0;\r\n const [min, max] = state.range;\r\n return max <= min ? 0 : (value - min) / (max - min);\r\n };\r\n\r\n const markers = state.markers.map((_, i) => {\r\n const marker: Node2D = new Text({\r\n ...textOps.styleProps(state.axis.labelStyle),\r\n text: () => {\r\n const value = sorted()[i];\r\n return value === undefined ? \"\" : markerCaption(state, value);\r\n },\r\n x: () => {\r\n const width = box().width;\r\n const centred = (fracAt(sorted()[i]) - 0.5) * width;\r\n // Held inside the axis's right edge, which is also the *chart's*: the\r\n // last marker is centred on the last grid line, so half of `2026-06`\r\n // — or of `3300` — would be drawn outside the node's box and outside\r\n // the rectangle the editor draws around it. Only the right edge is\r\n // held, because the left one has the vertical axis's whole gutter\r\n // beyond it, and a marker overhanging into that is inside the chart.\r\n const limit = width / 2 - marker.layoutBounds.width / 2;\r\n return Math.min(centred, limit);\r\n },\r\n opacity: () => arrivalOf(state.arrivals, i).opacity,\r\n y: () => arrivalOf(state.arrivals, i).shift,\r\n });\r\n return marker;\r\n });\r\n\r\n const children: Node2D[] = [\r\n new Rect({ width: \"fill\", height: \"hug\", padding: { top: tickPad }, children: markers }),\r\n ];\r\n if (state.label !== \"\") {\r\n children.push(\r\n new Text({\r\n ...textOps.styleProps(state.axis.titleStyle),\r\n text: state.label,\r\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\r\n y: () => arrivalOf(state.arrivals, \"label\").shift,\r\n }),\r\n );\r\n }\r\n\r\n column.push(new Rect({ flow: \"vertical\", gap: titlePad, height: \"hug\", width: \"fill\", children }));\r\n return asParts(column);\r\n },\r\n commands: {\r\n /**\r\n * Stagger the markers in left to right, then slide the caption in after\r\n * them. Its first frame arms them all: lifted by `slide` and transparent.\r\n *\r\n * The timeline's duration is the **whole** entrance — see\r\n * `VerticalAxis.enter` and {@link enterBudget}.\r\n */\r\n enter: {\r\n args: {\r\n stagger: Types.custom<number | undefined>(undefined),\r\n slide: Types.number(SLIDE),\r\n },\r\n run: (timeline, state) => {\r\n const { stagger, slide } = timeline.args;\r\n const count = state.markers.length;\r\n const captioned = state.label !== \"\";\r\n const from: Arrival = { opacity: 0, shift: slide };\r\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])];\r\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));\r\n if (count === 0) return arm;\r\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);\r\n const ease = frameEase(timeline);\r\n // Left marker leads: the row is already left → right.\r\n const markers = state.markers.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));\r\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : [];\r\n return timeline.together([arm, beats(timeline, [...markers, ...label])]);\r\n },\r\n },\r\n },\r\n});\r\n\r\nexport type HorizontalAxis = NodeOf<typeof HorizontalAxis>;\r\n"]}
|
|
@@ -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.js";
|
|
14
|
-
export type { LineChartProps } from "./line-chart.js";
|
|
13
|
+
export { LineChart, lineChartDomains } from "./line-chart.js";
|
|
14
|
+
export type { LineChartDomains, LineChartProps, LineChartValues } from "./line-chart.js";
|
|
15
15
|
export { ChartRegion } from "./chart-region.js";
|
|
16
16
|
export { ChartLine } from "./chart-line.js";
|
|
17
17
|
export { HorizontalAxis } from "./horizontal-axis.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/line-chart/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC1D,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EACb,YAAY,EACZ,OAAO,GACR,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACtE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA"}
|