@motionscript/charts 0.1.0-alpha.0 → 0.1.0-alpha.10

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.
Files changed (152) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/NOTICE +49 -0
  3. package/README.md +99 -0
  4. package/dist/bar-chart/bar-chart.d.ts +133 -228
  5. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  6. package/dist/bar-chart/bar-chart.js +386 -565
  7. package/dist/bar-chart/bar-chart.js.map +1 -1
  8. package/dist/bar-chart/category-axis.d.ts +35 -41
  9. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  10. package/dist/bar-chart/category-axis.js +93 -115
  11. package/dist/bar-chart/category-axis.js.map +1 -1
  12. package/dist/bar-chart/chart-bars.d.ts +50 -70
  13. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  14. package/dist/bar-chart/chart-bars.js +155 -210
  15. package/dist/bar-chart/chart-bars.js.map +1 -1
  16. package/dist/bar-chart/index.d.ts +2 -2
  17. package/dist/bar-chart/index.d.ts.map +1 -1
  18. package/dist/bar-chart/index.js +1 -1
  19. package/dist/bar-chart/index.js.map +1 -1
  20. package/dist/bar-chart/shared.d.ts +7 -7
  21. package/dist/bar-chart/shared.d.ts.map +1 -1
  22. package/dist/bar-chart/shared.js +7 -7
  23. package/dist/bar-chart/shared.js.map +1 -1
  24. package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
  25. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
  26. package/dist/browser/index.js +1 -1
  27. package/dist/browser/index.js.map +3 -3
  28. package/dist/browser/kit.js +1 -1
  29. package/dist/browser/manifest.json +4 -3
  30. package/dist/engine.d.ts +10 -8
  31. package/dist/engine.d.ts.map +1 -1
  32. package/dist/engine.js +10 -8
  33. package/dist/engine.js.map +1 -1
  34. package/dist/kit/cartesian.d.ts +44 -0
  35. package/dist/kit/cartesian.d.ts.map +1 -0
  36. package/dist/kit/cartesian.js +59 -0
  37. package/dist/kit/cartesian.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +10 -11
  39. package/dist/kit/chart-border.d.ts.map +1 -1
  40. package/dist/kit/chart-border.js +15 -32
  41. package/dist/kit/chart-border.js.map +1 -1
  42. package/dist/kit/chart-canvas.d.ts +32 -21
  43. package/dist/kit/chart-canvas.d.ts.map +1 -1
  44. package/dist/kit/chart-canvas.js +33 -90
  45. package/dist/kit/chart-canvas.js.map +1 -1
  46. package/dist/kit/chart-legend.d.ts +123 -85
  47. package/dist/kit/chart-legend.d.ts.map +1 -1
  48. package/dist/kit/chart-legend.js +137 -186
  49. package/dist/kit/chart-legend.js.map +1 -1
  50. package/dist/kit/entries.d.ts +17 -0
  51. package/dist/kit/entries.d.ts.map +1 -0
  52. package/dist/kit/entries.js +19 -0
  53. package/dist/kit/entries.js.map +1 -0
  54. package/dist/kit/motion.d.ts +48 -0
  55. package/dist/kit/motion.d.ts.map +1 -0
  56. package/dist/kit/motion.js +63 -0
  57. package/dist/kit/motion.js.map +1 -0
  58. package/dist/kit/paints.d.ts +10 -0
  59. package/dist/kit/paints.d.ts.map +1 -0
  60. package/dist/kit/paints.js +12 -0
  61. package/dist/kit/paints.js.map +1 -0
  62. package/dist/kit/shared.d.ts +61 -10
  63. package/dist/kit/shared.d.ts.map +1 -1
  64. package/dist/kit/shared.js +108 -13
  65. package/dist/kit/shared.js.map +1 -1
  66. package/dist/kit/vertical-axis.d.ts +48 -61
  67. package/dist/kit/vertical-axis.d.ts.map +1 -1
  68. package/dist/kit/vertical-axis.js +97 -132
  69. package/dist/kit/vertical-axis.js.map +1 -1
  70. package/dist/line-chart/chart-line.d.ts +60 -77
  71. package/dist/line-chart/chart-line.d.ts.map +1 -1
  72. package/dist/line-chart/chart-line.js +100 -121
  73. package/dist/line-chart/chart-line.js.map +1 -1
  74. package/dist/line-chart/chart-region.d.ts +32 -33
  75. package/dist/line-chart/chart-region.d.ts.map +1 -1
  76. package/dist/line-chart/chart-region.js +31 -65
  77. package/dist/line-chart/chart-region.js.map +1 -1
  78. package/dist/line-chart/horizontal-axis.d.ts +58 -64
  79. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  80. package/dist/line-chart/horizontal-axis.js +94 -123
  81. package/dist/line-chart/horizontal-axis.js.map +1 -1
  82. package/dist/line-chart/index.d.ts +3 -3
  83. package/dist/line-chart/index.d.ts.map +1 -1
  84. package/dist/line-chart/index.js +2 -2
  85. package/dist/line-chart/index.js.map +1 -1
  86. package/dist/line-chart/line-chart.d.ts +156 -303
  87. package/dist/line-chart/line-chart.d.ts.map +1 -1
  88. package/dist/line-chart/line-chart.js +410 -638
  89. package/dist/line-chart/line-chart.js.map +1 -1
  90. package/dist/line-chart/shared.d.ts +7 -7
  91. package/dist/line-chart/shared.d.ts.map +1 -1
  92. package/dist/line-chart/shared.js +23 -8
  93. package/dist/line-chart/shared.js.map +1 -1
  94. package/dist/line-chart/x-scale.d.ts +4 -11
  95. package/dist/line-chart/x-scale.d.ts.map +1 -1
  96. package/dist/line-chart/x-scale.js +16 -5
  97. package/dist/line-chart/x-scale.js.map +1 -1
  98. package/dist/nodes.d.ts +6 -9
  99. package/dist/nodes.d.ts.map +1 -1
  100. package/dist/nodes.js +7 -9
  101. package/dist/nodes.js.map +1 -1
  102. package/dist/pie-chart/index.d.ts +2 -2
  103. package/dist/pie-chart/index.d.ts.map +1 -1
  104. package/dist/pie-chart/index.js +1 -1
  105. package/dist/pie-chart/index.js.map +1 -1
  106. package/dist/pie-chart/pie-chart.d.ts +108 -126
  107. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  108. package/dist/pie-chart/pie-chart.js +202 -271
  109. package/dist/pie-chart/pie-chart.js.map +1 -1
  110. package/dist/pie-chart/pie-legend.d.ts +84 -31
  111. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  112. package/dist/pie-chart/pie-legend.js +93 -107
  113. package/dist/pie-chart/pie-legend.js.map +1 -1
  114. package/dist/pie-chart/pie-ring.d.ts +160 -122
  115. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  116. package/dist/pie-chart/pie-ring.js +333 -361
  117. package/dist/pie-chart/pie-ring.js.map +1 -1
  118. package/dist/pie-chart/shared.d.ts +12 -6
  119. package/dist/pie-chart/shared.d.ts.map +1 -1
  120. package/dist/pie-chart/shared.js +14 -8
  121. package/dist/pie-chart/shared.js.map +1 -1
  122. package/package.json +7 -4
  123. package/src/bar-chart/bar-chart.ts +424 -686
  124. package/src/bar-chart/category-axis.ts +96 -111
  125. package/src/bar-chart/chart-bars.ts +178 -201
  126. package/src/bar-chart/index.ts +2 -2
  127. package/src/bar-chart/shared.ts +7 -7
  128. package/src/engine.ts +10 -8
  129. package/src/kit/cartesian.ts +81 -0
  130. package/src/kit/chart-border.ts +23 -34
  131. package/src/kit/chart-canvas.ts +45 -80
  132. package/src/kit/chart-legend.ts +185 -206
  133. package/src/kit/entries.ts +20 -0
  134. package/src/kit/motion.ts +90 -0
  135. package/src/kit/paints.ts +15 -0
  136. package/src/kit/shared.ts +120 -13
  137. package/src/kit/vertical-axis.ts +111 -141
  138. package/src/line-chart/chart-line.ts +103 -155
  139. package/src/line-chart/chart-region.ts +36 -81
  140. package/src/line-chart/horizontal-axis.ts +102 -153
  141. package/src/line-chart/index.ts +3 -3
  142. package/src/line-chart/line-chart.ts +463 -759
  143. package/src/line-chart/shared.ts +22 -8
  144. package/src/line-chart/x-scale.ts +20 -5
  145. package/src/nodes.ts +8 -10
  146. package/src/pie-chart/index.ts +2 -2
  147. package/src/pie-chart/pie-chart.ts +225 -303
  148. package/src/pie-chart/pie-legend.ts +125 -115
  149. package/src/pie-chart/pie-ring.ts +388 -443
  150. package/src/pie-chart/shared.ts +14 -8
  151. package/dist/browser/chunks/chunk-ZMBOBHYL.js +0 -2
  152. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +0 -7
@@ -1,17 +1,12 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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/core";
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/core/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
- * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather
14
- * than its own `layoutBounds` — the box already carries the plot geometry.
8
+ * positioned entirely from the pre-mapped `box` rather
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,24 @@ import { declarePaints } from "@motionscript/core/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 class ChartRegion extends Node2D {
25
- /**
26
- * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
27
- * paint props it carries — see {@link declarePaints}.
28
- */
29
- declareAssets(assets) {
30
- super.declareAssets(assets);
31
- declarePaints(this, assets);
32
- }
33
- renderSelf(ctx) {
34
- const box = this.box;
19
+ export const ChartRegion = component2d({
20
+ key: "chartRegion",
21
+ state: {
22
+ /** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */
23
+ box: fresh(() => EMPTY_REGION_BOX),
24
+ /** Dashed rule marking each *bounded* edge of the box. */
25
+ stroke: Types.custom(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
26
+ /** Wash filling the box, under the series lines. */
27
+ fill: Types.custom(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),
28
+ /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
29
+ reveal: 0,
30
+ },
31
+ load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),
32
+ render: (ctx, state) => {
33
+ const box = state.box;
35
34
  if (!hasRegion(box))
36
35
  return;
37
- const r = Math.max(0, Math.min(1, this.reveal));
36
+ const r = Math.max(0, Math.min(1, state.reveal));
38
37
  if (r <= 0)
39
38
  return;
40
39
  const width = box.right - box.left;
@@ -42,60 +41,27 @@ export class ChartRegion extends Node2D {
42
41
  const cx = (box.left + box.right) / 2;
43
42
  const cy = (box.bottom + box.top) / 2;
44
43
  // Wash first, so the rules sit over their own tint.
45
- const layers = this.fill;
46
- if (layers.length > 0) {
47
- ctx.draw(new Graphics2D()
48
- .rect({ x: cx, y: cy, width, height })
49
- .fill(this.fill)
50
- .opacity(r));
44
+ if (state.fill.length > 0) {
45
+ ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
51
46
  }
52
47
  // One rule per bounded edge, growing from the region's centre outward as
53
48
  // `reveal` climbs — the same "trace it in" beat as the series lines.
54
- const stroke = this.stroke;
55
- if (stroke.length === 0)
49
+ if (state.stroke.length === 0)
56
50
  return;
57
51
  // One `draw` per rule rather than four line ops under a single paint:
58
52
  // shapes chained before a `stroke()` are combined into one surface, and
59
53
  // stroking a union of disjoint open paths doesn't paint.
60
- const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(this.stroke).opacity(r));
54
+ const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
61
55
  if (box.xBounded) {
62
56
  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
- }
57
+ for (const x of [box.left, box.right])
58
+ rule([{ x, y: cy - half }, { x, y: cy + half }]);
69
59
  }
70
60
  if (box.yBounded) {
71
61
  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
- }
62
+ for (const y of [box.bottom, box.top])
63
+ rule([{ x: cx - half, y }, { x: cx + half, y }]);
78
64
  }
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);
65
+ },
66
+ });
101
67
  //# sourceMappingURL=chart-region.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-region.js","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,OAAO,EACP,SAAS,EACT,QAAQ,GAOT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAqB5D;;;;;;;;;;;;;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,CAAC,gBAAgB,EAAE,CAAC;wCAAuB;AAM7D;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM;QAC1C,MAAM,EAAE,SAAS,CAAC,OAAO;QACzB,KAAK,EAAE,SAAS,CAAC,IAAI;KACtB,CAAC;2CACoB;AAMd;IALP,QAAQ,CAAC;QACR,OAAO,EAAE,mBAAmB,CAAC,MAAM,CAAC,IAAI;QACxC,MAAM,EAAE,OAAO,CAAC,OAAO;QACvB,KAAK,EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;yCACgB;AACgB;IAAjC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;2CAAuB","sourcesContent":["import {\n type AssetScope,\n Graphics2D,\n Node2D,\n fillOps,\n strokeOps,\n property,\n type Fill,\n type FillResolved,\n type Node2DProps,\n type RenderContext2D,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/core\"\n\nimport {\n DEFAULT_CHART_THEME,\n EMPTY_REGION_BOX,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\nimport { declarePaints } from \"@motionscript/core/component\"\n\nexport interface ChartRegionProps extends Node2DProps {\n /**\n * The highlighted slice, already resolved into this node's local pixel space\n * (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box\n * draws nothing.\n */\n box: RegionBox\n /** Dashed rule marking each *bounded* edge of the box. */\n stroke: Stroke\n /** Wash filling the box, under the series lines. */\n fill: Fill\n /**\n * Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven\n * by the chart's own `regionReveal`, so the rules and the series' dimming move\n * as one.\n */\n reveal: number\n}\n\n/**\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\n * plot with a dashed rule down each edge the author actually bounded. Sized and\n * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather\n * than its own `layoutBounds` — the box already carries the plot geometry.\n *\n * It draws only the *marking*; fading the series outside the region is\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\n * the two can't disagree about where the boundary is.\n *\n * Only bounded edges get a rule: a region given just an `x` range spans the full\n * plot height, so its top and bottom edges are the plot's own border, not a data\n * bound — drawing dashes there would assert a limit the author didn't set.\n */\nexport class ChartRegion extends Node2D<ChartRegionProps> {\n @property({ default: () => EMPTY_REGION_BOX }) declare box: RegionBox\n @property({\n default: DEFAULT_CHART_THEME.region.stroke,\n mapper: strokeOps.resolve,\n tween: strokeOps.lerp,\n })\n declare stroke: Stroke\n @property({\n default: DEFAULT_CHART_THEME.region.fill,\n mapper: fillOps.resolve,\n tween: fillOps.lerp,\n })\n declare fill: Fill\n @property({ default: 0 }) declare reveal: number\n\n /**\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\n * paint props it carries — see {@link declarePaints}.\n */\n override declareAssets(assets: AssetScope): void {\n super.declareAssets(assets)\n declarePaints(this, assets)\n }\n\n protected renderSelf(ctx: RenderContext2D): void {\n const box = this.box\n if (!hasRegion(box)) return\n\n const r = Math.max(0, Math.min(1, this.reveal))\n if (r <= 0) return\n\n const width = box.right - box.left\n const height = box.top - box.bottom\n const cx = (box.left + box.right) / 2\n const cy = (box.bottom + box.top) / 2\n\n // Wash first, so the rules sit over their own tint.\n const layers = this.fill as FillResolved[]\n if (layers.length > 0) {\n ctx.draw(\n new Graphics2D()\n .rect({ x: cx, y: cy, width, height })\n .fill(this.fill)\n .opacity(r)\n )\n }\n\n // One rule per bounded edge, growing from the region's centre outward as\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\n const stroke = this.stroke as StrokeResolved[]\n if (stroke.length === 0) return\n\n // One `draw` per rule rather than four line ops under a single paint:\n // shapes chained before a `stroke()` are combined into one surface, and\n // stroking a union of disjoint open paths doesn't paint.\n const rule = (points: { x: number; y: number }[]) =>\n ctx.draw(new Graphics2D().line({ points }).stroke(this.stroke).opacity(r))\n\n if (box.xBounded) {\n const half = (height / 2) * r\n for (const x of [box.left, box.right]) {\n rule([\n { x, y: cy - half },\n { x, y: cy + half },\n ])\n }\n }\n if (box.yBounded) {\n const half = (width / 2) * r\n for (const y of [box.bottom, box.top]) {\n rule([\n { x: cx - half, y },\n { x: cx + half, y },\n ])\n }\n }\n }\n}\n"]}
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,GAQV,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;AAEjB;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC;IACrC,GAAG,EAAE,aAAa;IAClB,KAAK,EAAE;QACL,2KAA2K;QAC3K,GAAG,EAAE,KAAK,CAAY,GAAG,EAAE,CAAC,gBAAgB,CAAC;QAC7C,0DAA0D;QAC1D,MAAM,EAAE,KAAK,CAAC,MAAM,CAA2B,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;QACvI,oDAAoD;QACpD,IAAI,EAAE,KAAK,CAAC,MAAM,CAAuB,mBAAmB,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;QAC3H,uIAAuI;QACvI,MAAM,EAAE,CAAC;KACV;IACD,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,CA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IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;QAE7E,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;YAC7B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC;gBAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;QACzF,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAA;YAC5B,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC;gBAAE,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;QACzF,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\n Graphics2D,\n Types,\n component2d,\n fillOps,\n strokeOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\n type Node2D as _Node2D,\n type Stroke,\n type StrokeResolved,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"../kit/entries\"\nimport { loadPaints } from \"../kit/paints\"\nimport {\n DEFAULT_CHART_THEME,\n EMPTY_REGION_BOX,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\n\n/**\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\n * plot with a dashed rule down each edge the author actually bounded. Sized and\n * positioned entirely from the pre-mapped `box` rather\n * than its own box — the region already carries the plot geometry.\n *\n * It draws only the *marking*; fading the series outside the region is\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\n * the two can't disagree about where the boundary is.\n *\n * Only bounded edges get a rule: a region given just an `x` range spans the full\n * plot height, so its top and bottom edges are the plot's own border, not a data\n * bound — drawing dashes there would assert a limit the author didn't set.\n */\nexport const ChartRegion = component2d({\n key: \"chartRegion\",\n state: {\n /** The highlighted slice, already resolved into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box draws nothing. */\n box: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n /** Dashed rule marking each *bounded* edge of the box. */\n stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n /** Wash filling the box, under the series lines. */\n fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */\n reveal: 0,\n },\n load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),\n render: (ctx, state) => {\n const box = state.box\n if (!hasRegion(box)) return\n\n const r = Math.max(0, Math.min(1, state.reveal))\n if (r <= 0) return\n\n const width = box.right - box.left\n const height = box.top - box.bottom\n const cx = (box.left + box.right) / 2\n const cy = (box.bottom + box.top) / 2\n\n // Wash first, so the rules sit over their own tint.\n if (state.fill.length > 0) {\n ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))\n }\n\n // One rule per bounded edge, growing from the region's centre outward as\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\n if (state.stroke.length === 0) return\n\n // One `draw` per rule rather than four line ops under a single paint:\n // shapes chained before a `stroke()` are combined into one surface, and\n // stroking a union of disjoint open paths doesn't paint.\n const rule = (points: { x: number; y: number }[]) =>\n ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))\n\n if (box.xBounded) {\n const half = (height / 2) * r\n for (const x of [box.left, box.right]) rule([{ x, y: cy - half }, { x, y: cy + half }])\n }\n if (box.yBounded) {\n const half = (width / 2) * r\n for (const y of [box.bottom, box.top]) rule([{ x: cx - half, y }, { x: cx + half, y }])\n }\n },\n})\n\nexport type ChartRegion = NodeOf<typeof ChartRegion>\n"]}
@@ -1,21 +1,6 @@
1
- import { Node2D, type CommandArgs, type NodeConfig, type Node2DProps } from "@motionscript/core";
1
+ import { type NodeOf, type Node2D } 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/core/component";
4
- export interface HorizontalAxisProps extends Node2DProps {
5
- /** `[min, max]` of the horizontal scale the markers are positioned within. */
6
- range: Range;
7
- /** Tick values (in data units) to draw along the axis. */
8
- markers: number[];
9
- /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
10
- axis: AxisConfig;
11
- /**
12
- * Caption drawn centred in the gutter beneath the marker row. Empty string
13
- * (the default) hides it.
14
- */
15
- label: string;
16
- }
17
- /** How a tick value is captioned — see {@link HorizontalAxis.labelFor}. */
18
- export type MarkerLabel = (value: number) => string;
19
4
  /**
20
5
  * The horizontal axis of a {@link LineChart}: a **row of {@link Text} nodes**,
21
6
  * one per marker value, running left-to-right. Pure layout — the mirror of the
@@ -26,60 +11,69 @@ export type MarkerLabel = (value: number) => string;
26
11
  * `2026-03` sits three months along, not three slots along. That is what keeps
27
12
  * it distinct from a bar chart's bottom axis, which centres a caption on each
28
13
  * 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 labelFor}.
14
+ * captioned *as* is the chart's to decide, in `captions`.
30
15
  *
31
- * {@link enter} staggers the markers in **left-to-right**: each starts lifted a
16
+ * `enter` staggers the markers in **left-to-right**: each starts lifted a
32
17
  * little above its slot and transparent, then fades and slides down into place.
33
18
  */
34
- export declare class HorizontalAxis extends Node2D<HorizontalAxisProps> {
35
- range: Range;
36
- markers: number[];
37
- axis: AxisConfig;
38
- label: string;
19
+ export declare const HorizontalAxis: import("@motionscript/sdk").Component<"horizontalAxis", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
20
+ /** `[min, max]` of the horizontal scale the markers are positioned within. */
21
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
22
+ /** Tick values (in data units) to draw along the axis. */
23
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
39
24
  /**
40
- * How a tick value is captioned. Defaults to the numeric formatting the
41
- * vertical axis uses; a chart whose x column names months or categories
42
- * replaces it (see `x-scale.ts`).
43
- *
44
- * A plain field rather than a `@property`, because it is a **policy, not a
45
- * value**: there is nothing to tween between two formatters, and a signal
46
- * holding a function is a signal every `set`/`to` on this node would have to
47
- * know not to touch. Read inside each marker's `text` binding, so replacing it
48
- * before the first frame is enough — which is when the chart does it.
25
+ * How each marker is captioned, one per entry of `markers` and in its order.
26
+ * Empty (the default), or short, captions a marker with its bare numeric
27
+ * reading; a chart whose x column names months or categories writes those.
49
28
  */
50
- labelFor: MarkerLabel;
51
- /** One text node per marker, ordered left → right, for the staggered enter. */
52
- private markerNodes;
53
- /** The caption node, or null when `label` is empty. */
54
- private labelNode;
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>);
29
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
30
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
31
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
32
+ /** Caption drawn centred in the gutter beneath the marker row; empty (the default) hides it. */
33
+ readonly label: "";
34
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
35
+ }>, {
36
+ readonly enter: {
37
+ readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
38
+ readonly slide: import("@motionscript/sdk").Type<number, number, false>;
39
+ };
40
+ }, null, Node2D<import("@motionscript/core").Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
41
+ /** `[min, max]` of the horizontal scale the markers are positioned within. */
42
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
43
+ /** Tick values (in data units) to draw along the axis. */
44
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
61
45
  /**
62
- * Primes every marker (and the caption) at its pre-entrance state: lifted
63
- * above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.
46
+ * How each marker is captioned, one per entry of `markers` and in its order.
47
+ * Empty (the default), or short, captions a marker with its bare numeric
48
+ * reading; a chart whose x column names months or categories writes those.
64
49
  */
65
- arm(slide?: number): void;
50
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
51
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
52
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
53
+ /** Caption drawn centred in the gutter beneath the marker row; empty (the default) hides it. */
54
+ readonly label: "";
55
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
56
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
57
+ /** `[min, max]` of the horizontal scale the markers are positioned within. */
58
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
59
+ /** Tick values (in data units) to draw along the axis. */
60
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
66
61
  /**
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}.
62
+ * How each marker is captioned, one per entry of `markers` and in its order.
63
+ * Empty (the default), or short, captions a marker with its bare numeric
64
+ * reading; a chart whose x column names months or categories writes those.
77
65
  */
78
- enter(args: CommandArgs<{
79
- stagger?: number;
80
- slide?: number;
81
- }> & {
82
- duration: number;
83
- }): Seekable;
84
- }
66
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
67
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
68
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
69
+ /** Caption drawn centred in the gutter beneath the marker row; empty (the default) hides it. */
70
+ readonly label: "";
71
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
72
+ }>, {
73
+ readonly enter: {
74
+ readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
75
+ readonly slide: import("@motionscript/sdk").Type<number, number, false>;
76
+ };
77
+ }, Node2D<import("@motionscript/core").Node2DProps>>>>;
78
+ export type HorizontalAxis = NodeOf<typeof HorizontalAxis>;
85
79
  //# 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,EAEL,MAAM,EAON,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EACjB,MAAM,oBAAoB,CAAC;AAE5B,OA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Z"}
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,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AACzG,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAMvB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc;IAGvB,8EAA8E;;IAE9E,0DAA0D;;IAE1D;;;;OAIG;;IAEH,oFAAoF;;IAEpF,gGAAgG;;;;;;;;;IAZhG,8EAA8E;;IAE9E,0DAA0D;;IAE1D;;;;OAIG;;IAEH,oFAAoF;;IAEpF,gGAAgG;;;;IAZhG,8EAA8E;;IAE9E,0DAA0D;;IAE1D;;;;OAIG;;IAEH,oFAAoF;;IAEpF,gGAAgG;;;;;;;;sDA8FlG,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC"}
@@ -1,12 +1,8 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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 { command, Node2D, Rect, Text, easeOut, property, insetsOps, textOps, } from "@motionscript/core";
8
- import { DEFAULT_X_AXIS, enterBudget, formatMarker, } from "../kit/shared.js";
9
- import { at, compose } from "@motionscript/core/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,57 @@ 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 labelFor}.
18
+ * captioned *as* is the chart's to decide, in `captions`.
23
19
  *
24
- * {@link enter} staggers the markers in **left-to-right**: each starts lifted a
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 class HorizontalAxis extends Node2D {
28
- /**
29
- * How a tick value is captioned. Defaults to the numeric formatting the
30
- * vertical axis uses; a chart whose x column names months or categories
31
- * replaces it (see `x-scale.ts`).
32
- *
33
- * A plain field rather than a `@property`, because it is a **policy, not a
34
- * value**: there is nothing to tween between two formatters, and a signal
35
- * holding a function is a signal every `set`/`to` on this node would have to
36
- * know not to touch. Read inside each marker's `text` binding, so replacing it
37
- * before the first frame is enough — which is when the chart does it.
38
- */
39
- labelFor = formatMarker;
40
- /** One text node per marker, ordered left → right, for the staggered enter. */
41
- markerNodes = [];
42
- /** The caption node, or null when `label` is empty. */
43
- labelNode = null;
44
- /** The live tick values, left → right — re-read every frame, not snapshotted. */
45
- get sortedMarkers() {
46
- return [...this.markers].sort((a, b) => a - b);
47
- }
48
- valueAt(index) {
49
- return this.sortedMarkers[index];
50
- }
51
- /** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
52
- fracAt(index) {
53
- const v = this.valueAt(index);
54
- if (v === undefined)
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
+ /** `[min, max]` of the horizontal scale the markers are positioned within. */
27
+ range: fresh(() => [0, 1]),
28
+ /** Tick values (in data units) to draw along the axis. */
29
+ markers: fresh(() => []),
30
+ /**
31
+ * How each marker is captioned, one per entry of `markers` and in its order.
32
+ * Empty (the default), or short, captions a marker with its bare numeric
33
+ * reading; a chart whose x column names months or categories writes those.
34
+ */
35
+ captions: fresh(() => []),
36
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
37
+ axis: Types.custom(DEFAULT_X_AXIS),
38
+ /** Caption drawn centred in the gutter beneath the marker row; empty (the default) hides it. */
39
+ label: "",
40
+ arrivals: arrivalsEntry(),
41
+ },
42
+ // A plain node filled its parent; one made of its markers would hug them.
43
+ defaults: { width: "fill", height: "fill" },
44
+ children: (state) => {
45
+ const tickPad = insetsOps.resolve(state.axis.tickPadding).top;
46
+ const titlePad = insetsOps.resolve(state.axis.titlePadding).top;
47
+ const column = [];
48
+ // The column's parent is the axis: its box is what the markers are placed in.
49
+ const box = () => column[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
50
+ /** The live tick values, left → right — re-read every frame, not snapshotted. */
51
+ const sorted = () => [...state.markers].sort((a, b) => a - b);
52
+ /** Tick `i`'s fraction across the live `range`, 0 at the left edge. */
53
+ const fracAt = (value) => {
54
+ if (value === undefined)
55
+ return 0;
56
+ const [min, max] = state.range;
57
+ return max <= min ? 0 : (value - min) / (max - min);
58
+ };
59
+ const markers = state.markers.map((_, i) => {
64
60
  const marker = new Text({
65
- ...textOps.styleProps(this.axis.labelStyle),
61
+ ...textOps.styleProps(state.axis.labelStyle),
66
62
  text: () => {
67
- const v = this.valueAt(i);
68
- return v === undefined ? "" : this.labelFor(v);
63
+ const value = sorted()[i];
64
+ return value === undefined ? "" : markerCaption(state, value);
69
65
  },
70
66
  x: () => {
71
- const width = this.layoutBounds.width;
72
- const centred = (this.fracAt(i) - 0.5) * width;
67
+ const width = box().width;
68
+ const centred = (fracAt(sorted()[i]) - 0.5) * width;
73
69
  // Held inside the axis's right edge, which is also the *chart's*: the
74
70
  // last marker is centred on the last grid line, so half of `2026-06`
75
71
  // — or of `3300` — would be drawn outside the node's box and outside
@@ -79,80 +75,55 @@ export class HorizontalAxis extends Node2D {
79
75
  const limit = width / 2 - marker.layoutBounds.width / 2;
80
76
  return Math.min(centred, limit);
81
77
  },
78
+ opacity: () => arrivalOf(state.arrivals, i).opacity,
79
+ y: () => arrivalOf(state.arrivals, i).shift,
82
80
  });
83
81
  return marker;
84
82
  });
85
83
  const children = [
86
- new Rect({
87
- width: "fill",
88
- height: "hug",
89
- padding: { top: tickPad },
90
- children: this.markerNodes,
91
- }),
84
+ new Rect({ width: "fill", height: "hug", padding: { top: tickPad }, children: markers }),
92
85
  ];
93
- if (this.label !== "") {
94
- this.labelNode = new Text({
95
- ...textOps.styleProps(this.axis.titleStyle),
96
- text: this.label,
97
- });
98
- children.push(this.labelNode);
86
+ if (state.label !== "") {
87
+ children.push(new Text({
88
+ ...textOps.styleProps(state.axis.titleStyle),
89
+ text: state.label,
90
+ opacity: () => arrivalOf(state.arrivals, "label").opacity,
91
+ y: () => arrivalOf(state.arrivals, "label").shift,
92
+ }));
99
93
  }
100
- this.add(new Rect({ flow: "vertical", gap: titlePad, height: "hug", width: "fill", children }));
101
- }
102
- /**
103
- * Primes every marker (and the caption) at its pre-entrance state: lifted
104
- * above its slot and transparent. Idempotent — see {@link VerticalAxis.arm}.
105
- */
106
- arm(slide = SLIDE) {
107
- for (const marker of this.markerNodes)
108
- marker.set({ opacity: 0, y: slide });
109
- this.labelNode?.set({ opacity: 0, y: slide });
110
- }
111
- /**
112
- * Stagger the markers in left to right, then slide the caption in after them.
113
- *
114
- * A {@link Seekable} rather than a generator. The offsets were always static —
115
- * `i * step` per marker — but expressed as `wait` inside a generator they only
116
- * existed while it ran, so knowing what the axis looked like partway through
117
- * meant running it from zero. Placed explicitly, the same stagger can be asked
118
- * for a time, which is what lets a chart scene scrub in constant time.
119
- *
120
- * `duration` is the **whole** entrance — see {@link VerticalAxis.enter} and
121
- * {@link enterBudget}.
122
- */
123
- enter(args) {
124
- const { stagger, slide = SLIDE } = args.data ?? {};
125
- const duration = args.duration;
126
- const easing = args.easing ?? easeOut();
127
- const nodes = this.markerNodes;
128
- if (nodes.length === 0)
129
- return compose([]);
130
- const { step, per, caption } = enterBudget(duration, nodes.length, this.labelNode !== null, stagger);
131
- this.arm(slide);
132
- // Left marker leads: markerNodes is already left → right.
133
- const markers = nodes.map((node, i) => at(i * step, node.to({ data: { opacity: 1, y: 0 }, duration: per, easing })));
134
- const lastMarkerEnds = nodes.length === 0 ? 0 : (nodes.length - 1) * step + per;
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);
94
+ column.push(new Rect({ flow: "vertical", gap: titlePad, height: "hug", width: "fill", children }));
95
+ return asParts(column);
96
+ },
97
+ commands: {
98
+ /**
99
+ * Stagger the markers in left to right, then slide the caption in after
100
+ * them. Its first frame arms them all: lifted by `slide` and transparent.
101
+ *
102
+ * The timeline's duration is the **whole** entrance — see
103
+ * `VerticalAxis.enter` and {@link enterBudget}.
104
+ */
105
+ enter: {
106
+ args: {
107
+ stagger: Types.custom(undefined),
108
+ slide: Types.number(SLIDE),
109
+ },
110
+ run: (timeline, state) => {
111
+ const { stagger, slide } = timeline.args;
112
+ const count = state.markers.length;
113
+ const captioned = state.label !== "";
114
+ const from = { opacity: 0, shift: slide };
115
+ const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])];
116
+ const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));
117
+ if (count === 0)
118
+ return arm;
119
+ const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
120
+ const ease = frameEase(timeline);
121
+ // Left marker leads: the row is already left → right.
122
+ const markers = state.markers.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
123
+ const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
124
+ return timeline.together([arm, beats(timeline, [...markers, ...label])]);
125
+ },
126
+ },
127
+ },
128
+ });
158
129
  //# sourceMappingURL=horizontal-axis.js.map