@motionscript/charts 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/dist/bar-chart/bar-chart.d.ts +286 -0
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -0
  5. package/dist/bar-chart/bar-chart.js +610 -0
  6. package/dist/bar-chart/bar-chart.js.map +1 -0
  7. package/dist/bar-chart/category-axis.d.ts +77 -0
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -0
  9. package/dist/bar-chart/category-axis.js +141 -0
  10. package/dist/bar-chart/category-axis.js.map +1 -0
  11. package/dist/bar-chart/chart-bars.d.ts +149 -0
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -0
  13. package/dist/bar-chart/chart-bars.js +236 -0
  14. package/dist/bar-chart/chart-bars.js.map +1 -0
  15. package/dist/bar-chart/index.d.ts +16 -0
  16. package/dist/bar-chart/index.d.ts.map +1 -0
  17. package/dist/bar-chart/index.js +12 -0
  18. package/dist/bar-chart/index.js.map +1 -0
  19. package/dist/bar-chart/shared.d.ts +146 -0
  20. package/dist/bar-chart/shared.d.ts.map +1 -0
  21. package/dist/bar-chart/shared.js +182 -0
  22. package/dist/bar-chart/shared.js.map +1 -0
  23. package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
  24. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
  25. package/dist/browser/index.js +2 -0
  26. package/dist/browser/index.js.map +7 -0
  27. package/dist/browser/kit.js +2 -0
  28. package/dist/browser/kit.js.map +7 -0
  29. package/dist/browser/manifest.json +12 -0
  30. package/dist/engine.d.ts +27 -0
  31. package/dist/engine.d.ts.map +1 -0
  32. package/dist/engine.js +27 -0
  33. package/dist/engine.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +6 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +28 -0
  39. package/dist/kit/chart-border.d.ts.map +1 -0
  40. package/dist/kit/chart-border.js +45 -0
  41. package/dist/kit/chart-border.js.map +1 -0
  42. package/dist/kit/chart-canvas.d.ts +56 -0
  43. package/dist/kit/chart-canvas.d.ts.map +1 -0
  44. package/dist/kit/chart-canvas.js +125 -0
  45. package/dist/kit/chart-canvas.js.map +1 -0
  46. package/dist/kit/chart-legend.d.ts +126 -0
  47. package/dist/kit/chart-legend.d.ts.map +1 -0
  48. package/dist/kit/chart-legend.js +212 -0
  49. package/dist/kit/chart-legend.js.map +1 -0
  50. package/dist/kit/shared.d.ts +251 -0
  51. package/dist/kit/shared.d.ts.map +1 -0
  52. package/dist/kit/shared.js +401 -0
  53. package/dist/kit/shared.js.map +1 -0
  54. package/dist/kit/vertical-axis.d.ts +99 -0
  55. package/dist/kit/vertical-axis.d.ts.map +1 -0
  56. package/dist/kit/vertical-axis.js +176 -0
  57. package/dist/kit/vertical-axis.js.map +1 -0
  58. package/dist/line-chart/chart-line.d.ts +91 -0
  59. package/dist/line-chart/chart-line.d.ts.map +1 -0
  60. package/dist/line-chart/chart-line.js +156 -0
  61. package/dist/line-chart/chart-line.js.map +1 -0
  62. package/dist/line-chart/chart-region.d.ts +47 -0
  63. package/dist/line-chart/chart-region.d.ts.map +1 -0
  64. package/dist/line-chart/chart-region.js +101 -0
  65. package/dist/line-chart/chart-region.js.map +1 -0
  66. package/dist/line-chart/horizontal-axis.d.ts +85 -0
  67. package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
  68. package/dist/line-chart/horizontal-axis.js +158 -0
  69. package/dist/line-chart/horizontal-axis.js.map +1 -0
  70. package/dist/line-chart/index.d.ts +22 -0
  71. package/dist/line-chart/index.d.ts.map +1 -0
  72. package/dist/line-chart/index.js +19 -0
  73. package/dist/line-chart/index.js.map +1 -0
  74. package/dist/line-chart/line-chart.d.ts +347 -0
  75. package/dist/line-chart/line-chart.d.ts.map +1 -0
  76. package/dist/line-chart/line-chart.js +701 -0
  77. package/dist/line-chart/line-chart.js.map +1 -0
  78. package/dist/line-chart/shared.d.ts +171 -0
  79. package/dist/line-chart/shared.d.ts.map +1 -0
  80. package/dist/line-chart/shared.js +270 -0
  81. package/dist/line-chart/shared.js.map +1 -0
  82. package/dist/line-chart/x-scale.d.ts +84 -0
  83. package/dist/line-chart/x-scale.d.ts.map +1 -0
  84. package/dist/line-chart/x-scale.js +302 -0
  85. package/dist/line-chart/x-scale.js.map +1 -0
  86. package/dist/nodes.d.ts +20 -0
  87. package/dist/nodes.d.ts.map +1 -0
  88. package/dist/nodes.js +20 -0
  89. package/dist/nodes.js.map +1 -0
  90. package/dist/pie-chart/index.d.ts +18 -0
  91. package/dist/pie-chart/index.d.ts.map +1 -0
  92. package/dist/pie-chart/index.js +14 -0
  93. package/dist/pie-chart/index.js.map +1 -0
  94. package/dist/pie-chart/pie-chart.d.ts +170 -0
  95. package/dist/pie-chart/pie-chart.d.ts.map +1 -0
  96. package/dist/pie-chart/pie-chart.js +291 -0
  97. package/dist/pie-chart/pie-chart.js.map +1 -0
  98. package/dist/pie-chart/pie-legend.d.ts +60 -0
  99. package/dist/pie-chart/pie-legend.d.ts.map +1 -0
  100. package/dist/pie-chart/pie-legend.js +131 -0
  101. package/dist/pie-chart/pie-legend.js.map +1 -0
  102. package/dist/pie-chart/pie-ring.d.ts +266 -0
  103. package/dist/pie-chart/pie-ring.d.ts.map +1 -0
  104. package/dist/pie-chart/pie-ring.js +708 -0
  105. package/dist/pie-chart/pie-ring.js.map +1 -0
  106. package/dist/pie-chart/shared.d.ts +210 -0
  107. package/dist/pie-chart/shared.d.ts.map +1 -0
  108. package/dist/pie-chart/shared.js +240 -0
  109. package/dist/pie-chart/shared.js.map +1 -0
  110. package/package.json +69 -3
  111. package/registry.json +23 -0
  112. package/src/bar-chart/bar-chart.ts +804 -0
  113. package/src/bar-chart/category-axis.ts +177 -0
  114. package/src/bar-chart/chart-bars.ts +310 -0
  115. package/src/bar-chart/index.ts +31 -0
  116. package/src/bar-chart/shared.ts +354 -0
  117. package/src/engine.ts +26 -0
  118. package/src/index.ts +5 -0
  119. package/src/kit/chart-border.ts +61 -0
  120. package/src/kit/chart-canvas.ts +157 -0
  121. package/src/kit/chart-legend.ts +250 -0
  122. package/src/kit/shared.ts +675 -0
  123. package/src/kit/vertical-axis.ts +224 -0
  124. package/src/line-chart/chart-line.ts +208 -0
  125. package/src/line-chart/chart-region.ts +135 -0
  126. package/src/line-chart/horizontal-axis.ts +202 -0
  127. package/src/line-chart/index.ts +39 -0
  128. package/src/line-chart/line-chart.ts +894 -0
  129. package/src/line-chart/shared.ts +459 -0
  130. package/src/line-chart/x-scale.ts +367 -0
  131. package/src/nodes.ts +20 -0
  132. package/src/pie-chart/index.ts +37 -0
  133. package/src/pie-chart/pie-chart.ts +374 -0
  134. package/src/pie-chart/pie-legend.ts +159 -0
  135. package/src/pie-chart/pie-ring.ts +903 -0
  136. package/src/pie-chart/shared.ts +490 -0
  137. package/README.md +0 -4
@@ -0,0 +1,176 @@
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, RotatedBox, Text, easeOut, property, insetsOps, textOps, } from "@motionscript/core";
8
+ import { DEFAULT_Y_AXIS, enterBudget, formatMarker, } from "./shared.js";
9
+ import { at, compose } from "@motionscript/core/component";
10
+ /** How far a marker starts to the right of its slot when it enters, in px. */
11
+ const SLIDE = 24;
12
+ /**
13
+ * The numeric vertical axis shared by the cartesian charts: a **column of
14
+ * {@link Text} nodes**, one per marker value, running top-to-bottom (highest
15
+ * value at the top). Pure layout — no `Graphics` — so the markers are real text
16
+ * nodes the scene can measure, restyle, or animate individually.
17
+ *
18
+ * Each marker is positioned so its centre lands exactly on its value's fraction
19
+ * across `range` within the axis's filled height, so unevenly-spaced markers
20
+ * land where their values fall. Both the caption and the position are *bound*,
21
+ * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
22
+ * tweens `range`/`markers` live. Only the marker **count** is fixed at
23
+ * construction.
24
+ *
25
+ * {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a
26
+ * little to the right and transparent, then fades and slides left into place.
27
+ * The resting state is the landed one, so a chart that is never told to enter
28
+ * still reads as a finished chart.
29
+ */
30
+ export class VerticalAxis extends Node2D {
31
+ /**
32
+ * How a tick value is captioned. Defaults to the bare numeric reading; a
33
+ * chart with a number format on this axis replaces it (see `number-format`).
34
+ *
35
+ * A plain field rather than a `@property`, for the reason the horizontal
36
+ * axis's twin spells out: it is a policy, not a value, and there is nothing
37
+ * to tween between two formatters.
38
+ */
39
+ labelFor = formatMarker;
40
+ /** One text node per marker, ordered top → bottom, for the staggered enter. */
41
+ markerNodes = [];
42
+ /** The caption node, or null when `label` is empty. Entered after the markers. */
43
+ labelNode = null;
44
+ /** The live tick values, top → bottom (highest first) — re-read every frame. */
45
+ get sortedMarkers() {
46
+ return [...this.markers].sort((a, b) => b - a);
47
+ }
48
+ /**
49
+ * Tick `i`'s value, or `undefined` once the live `markers` list is shorter
50
+ * than the column of text nodes built for it — a slot with no value renders as
51
+ * empty text rather than repeating its neighbour.
52
+ */
53
+ valueAt(index) {
54
+ return this.sortedMarkers[index];
55
+ }
56
+ /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
57
+ fracAt(index) {
58
+ const v = this.valueAt(index);
59
+ if (v === undefined)
60
+ return 0;
61
+ const [min, max] = this.range;
62
+ return max <= min ? 0 : (v - min) / (max - min);
63
+ }
64
+ constructor(props) {
65
+ super(props);
66
+ // Composed from plain props (range/markers/label) — no context needed, so
67
+ // it's built here. super() applied the props, so the reads below resolve.
68
+ const tickPad = insetsOps.resolve(this.axis.tickPadding).right;
69
+ const titlePad = insetsOps.resolve(this.axis.titlePadding).right;
70
+ this.markerNodes = this.markers.map((_, i) => {
71
+ const marker = new Text({
72
+ ...textOps.styleProps(this.axis.labelStyle),
73
+ text: () => {
74
+ const v = this.valueAt(i);
75
+ return v === undefined ? "" : this.labelFor(v);
76
+ },
77
+ y: () => {
78
+ // Node2D space is y-up, so the fraction runs from the bottom.
79
+ const height = this.layoutBounds.height;
80
+ const centred = (this.fracAt(i) - 0.5) * height;
81
+ // Held inside the axis's top edge — the backstop for a chart whose
82
+ // headroom is smaller than its marker text is tall, which a theme with
83
+ // much larger markers can arrange. Only the top, because what lies
84
+ // below the axis is the chart's own horizontal axis and legend.
85
+ const limit = height / 2 - marker.layoutBounds.height / 2;
86
+ return Math.min(centred, limit);
87
+ },
88
+ });
89
+ return marker;
90
+ });
91
+ const children = [];
92
+ if (this.label !== "") {
93
+ this.labelNode = new Text({
94
+ ...textOps.styleProps(this.axis.titleStyle),
95
+ text: this.label,
96
+ });
97
+ // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
98
+ children.push(new RotatedBox({
99
+ angle: -90,
100
+ width: "hug",
101
+ height: "hug",
102
+ children: this.labelNode,
103
+ }));
104
+ }
105
+ children.push(new Rect({
106
+ height: "fill",
107
+ width: "hug",
108
+ padding: { right: tickPad },
109
+ children: this.markerNodes,
110
+ }));
111
+ this.add(new Rect({ flow: "horizontal", gap: titlePad, children }));
112
+ }
113
+ /**
114
+ * Primes every marker (and the caption) at its pre-entrance state: shifted
115
+ * right and transparent. Idempotent, and separate from {@link enter} so the
116
+ * chart can arm its whole composition before the first frame is drawn.
117
+ */
118
+ arm(slide = SLIDE) {
119
+ for (const marker of this.markerNodes)
120
+ marker.set({ opacity: 0, x: slide });
121
+ this.labelNode?.set({ opacity: 0, x: slide });
122
+ }
123
+ /**
124
+ * Stagger the markers in bottom to top, then slide the caption in from the
125
+ * right after them.
126
+ *
127
+ * A {@link Seekable} rather than a generator — see the note on the horizontal
128
+ * axis's `enter`. The offsets were always static; expressing them as `wait`
129
+ * inside a generator is what made them reachable only by running it.
130
+ *
131
+ * `args.duration` is the **whole** entrance, not one marker's slide: the
132
+ * stagger and the caption are carved out of it rather than added on top. See
133
+ * {@link enterBudget} for why that distinction matters here.
134
+ *
135
+ * `args.data.stagger` is seconds between successive markers (derived when
136
+ * omitted); `args.data.slide` is the starting rightward offset in px.
137
+ */
138
+ enter(args) {
139
+ const { stagger, slide = SLIDE } = args.data ?? {};
140
+ const easing = args.easing ?? easeOut();
141
+ const nodes = this.markerNodes;
142
+ if (nodes.length === 0)
143
+ return compose([]);
144
+ const { step, per, caption } = enterBudget(args.duration, nodes.length, this.labelNode !== null, stagger);
145
+ this.arm(slide);
146
+ // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.
147
+ const markers = nodes.map((node, i) => {
148
+ const order = nodes.length - 1 - i; // bottom-most = 0
149
+ return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }));
150
+ });
151
+ const lastMarkerEnds = (nodes.length - 1) * step + per;
152
+ // Once every marker has landed, the caption slides in from the right.
153
+ return compose([
154
+ ...markers,
155
+ ...(this.labelNode
156
+ ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]
157
+ : []),
158
+ ]);
159
+ }
160
+ }
161
+ __decorate([
162
+ property({ default: () => [0, 1] })
163
+ ], VerticalAxis.prototype, "range", void 0);
164
+ __decorate([
165
+ property({ default: () => [] })
166
+ ], VerticalAxis.prototype, "markers", void 0);
167
+ __decorate([
168
+ property({ default: DEFAULT_Y_AXIS })
169
+ ], VerticalAxis.prototype, "axis", void 0);
170
+ __decorate([
171
+ property({ default: "" })
172
+ ], VerticalAxis.prototype, "label", void 0);
173
+ __decorate([
174
+ command()
175
+ ], VerticalAxis.prototype, "enter", null);
176
+ //# sourceMappingURL=vertical-axis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vertical-axis.js","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,OAAO,EACP,MAAM,EACN,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,SAAS,EACT,OAAO,GAIR,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,EAAE,EAAE,OAAO,EAAiB,MAAM,8BAA8B,CAAA;AAqBzE,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAA;AAKhB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,YAAa,SAAQ,MAAyB;IAMzD;;;;;;;OAOG;IACH,QAAQ,GAAgB,YAAY,CAAA;IAEpC,+EAA+E;IACvE,WAAW,GAAW,EAAE,CAAA;IAChC,kFAAkF;IAC1E,SAAS,GAAgB,IAAI,CAAA;IAErC,gFAAgF;IAChF,IAAY,aAAa;QACvB,OAAO,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAChD,CAAC;IAED;;;;OAIG;IACK,OAAO,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC;IAED,yEAAyE;IACjE,MAAM,CAAC,KAAa;QAC1B,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAC7B,IAAI,CAAC,KAAK,SAAS;YAAE,OAAO,CAAC,CAAA;QAC7B,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QAC7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;YACV,GAAG,CAAC,IAAI,CAAC,SAAS;gBAChB,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;gBACpG,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAA;IACJ,CAAC;CACF;AA3JuD;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAU,EAAE,CAAC;2CAAqB;AACb;IAApD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAc,EAAE,CAAC;6CAA0B;AACvB;IAA9C,QAAQ,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;0CAAyB;AAC5B;IAAlC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;2CAAsB;AA2HhD;IADC,OAAO,EAAE;yCA6BT","sourcesContent":["import {\n command,\n Node2D,\n Rect,\n RotatedBox,\n Text,\n easeOut,\n property,\n insetsOps,\n textOps,\n type CommandArgs,\n type NodeConfig,\n type Node2DProps,\n} from \"@motionscript/core\"\n\nimport {\n DEFAULT_Y_AXIS,\n enterBudget,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\nimport { at, compose, type Seekable } from \"@motionscript/core/component\"\n\nexport interface VerticalAxisProps extends Node2DProps {\n /** `[min, max]` of the vertical scale the markers are positioned within. */\n range: Range\n /**\n * Tick values (in data units) to draw up the axis, each placed by its fraction\n * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include\n * the ends.\n */\n markers: number[]\n /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */\n axis: AxisConfig\n /**\n * Rotated caption drawn in the gutter to the left of the marker column. Empty\n * string (the default) hides it — no caption node is built and no label gutter\n * is reserved.\n */\n label: string\n}\n\n/** How far a marker starts to the right of its slot when it enters, in px. */\nconst SLIDE = 24\n\n/** How a tick value is captioned — see {@link VerticalAxis.labelFor}. */\nexport type MarkerLabel = (value: number) => string\n\n/**\n * The numeric vertical axis shared by the cartesian charts: a **column of\n * {@link Text} nodes**, one per marker value, running top-to-bottom (highest\n * value at the top). Pure layout — no `Graphics` — so the markers are real text\n * nodes the scene can measure, restyle, or animate individually.\n *\n * Each marker is positioned so its centre lands exactly on its value's fraction\n * across `range` within the axis's filled height, so unevenly-spaced markers\n * land where their values fall. Both the caption and the position are *bound*,\n * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)\n * tweens `range`/`markers` live. Only the marker **count** is fixed at\n * construction.\n *\n * {@link enter} staggers them in **bottom-to-top**: each marker starts pushed a\n * little to the right and transparent, then fades and slides left into place.\n * The resting state is the landed one, so a chart that is never told to enter\n * still reads as a finished chart.\n */\nexport class VerticalAxis extends Node2D<VerticalAxisProps> {\n @property({ default: () => [0, 1] as Range }) declare range: Range\n @property({ default: () => [] as number[] }) declare markers: number[]\n @property({ default: DEFAULT_Y_AXIS }) declare axis: AxisConfig\n @property({ default: \"\" }) declare label: string\n\n /**\n * How a tick value is captioned. Defaults to the bare numeric reading; a\n * chart with a number format on this axis replaces it (see `number-format`).\n *\n * A plain field rather than a `@property`, for the reason the horizontal\n * axis's twin spells out: it is a policy, not a value, and there is nothing\n * to tween between two formatters.\n */\n labelFor: MarkerLabel = formatMarker\n\n /** One text node per marker, ordered top → bottom, for the staggered enter. */\n private markerNodes: Text[] = []\n /** The caption node, or null when `label` is empty. Entered after the markers. */\n private labelNode: Text | null = null\n\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\n private get sortedMarkers(): number[] {\n return [...this.markers].sort((a, b) => b - a)\n }\n\n /**\n * Tick `i`'s value, or `undefined` once the live `markers` list is shorter\n * than the column of text nodes built for it — a slot with no value renders as\n * empty text rather than repeating its neighbour.\n */\n private valueAt(index: number): number | undefined {\n return this.sortedMarkers[index]\n }\n\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\n private fracAt(index: number): number {\n const v = this.valueAt(index)\n if (v === undefined) return 0\n const [min, max] = this.range\n return max <= min ? 0 : (v - min) / (max - min)\n }\n\n constructor(props?: NodeConfig<VerticalAxis, VerticalAxisProps>) {\n super(props)\n\n // Composed from plain props (range/markers/label) — no context needed, so\n // it's built here. super() applied the props, so the reads below resolve.\n const tickPad = insetsOps.resolve(this.axis.tickPadding).right\n const titlePad = insetsOps.resolve(this.axis.titlePadding).right\n\n this.markerNodes = this.markers.map((_, i) => {\n const marker: Text = new Text({\n ...textOps.styleProps(this.axis.labelStyle),\n text: () => {\n const v = this.valueAt(i)\n return v === undefined ? \"\" : this.labelFor(v)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = this.layoutBounds.height\n const centred = (this.fracAt(i) - 0.5) * height\n // Held inside the axis's top edge — the backstop for a chart whose\n // headroom is smaller than its marker text is tall, which a theme with\n // much larger markers can arrange. Only the top, because what lies\n // below the axis is the chart's own horizontal axis and legend.\n const limit = height / 2 - marker.layoutBounds.height / 2\n return Math.min(centred, limit)\n },\n })\n return marker\n })\n\n const children: Node2D[] = []\n if (this.label !== \"\") {\n this.labelNode = new Text({\n ...textOps.styleProps(this.axis.titleStyle),\n text: this.label,\n })\n // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.\n children.push(\n new RotatedBox({\n angle: -90,\n width: \"hug\",\n height: \"hug\",\n children: this.labelNode,\n })\n )\n }\n children.push(\n new Rect({\n height: \"fill\",\n width: \"hug\",\n padding: { right: tickPad },\n children: this.markerNodes,\n })\n )\n\n this.add(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n }\n\n /**\n * Primes every marker (and the caption) at its pre-entrance state: shifted\n * right and transparent. Idempotent, and separate from {@link enter} so the\n * chart can arm its whole composition before the first frame is drawn.\n */\n arm(slide = SLIDE): void {\n for (const marker of this.markerNodes) marker.set({ opacity: 0, x: slide })\n this.labelNode?.set({ opacity: 0, x: slide })\n }\n\n /**\n * Stagger the markers in bottom to top, then slide the caption in from the\n * right after them.\n *\n * A {@link Seekable} rather than a generator — see the note on the horizontal\n * axis's `enter`. The offsets were always static; expressing them as `wait`\n * inside a generator is what made them reachable only by running it.\n *\n * `args.duration` is the **whole** entrance, not one marker's slide: the\n * stagger and the caption are carved out of it rather than added on top. See\n * {@link enterBudget} for why that distinction matters here.\n *\n * `args.data.stagger` is seconds between successive markers (derived when\n * omitted); `args.data.slide` is the starting rightward offset in px.\n */\n @command()\n enter(args: CommandArgs<{ stagger?: number; slide?: number }> & { duration: number }): Seekable {\n const { stagger, slide = SLIDE } = args.data ?? {}\n const easing = args.easing ?? easeOut()\n const nodes = this.markerNodes\n if (nodes.length === 0) return compose([])\n const { step, per, caption } = enterBudget(\n args.duration,\n nodes.length,\n this.labelNode !== null,\n stagger\n )\n\n this.arm(slide)\n\n // Bottom marker leads: markerNodes is top → bottom, so walk it in reverse.\n const markers = nodes.map((node, i) => {\n const order = nodes.length - 1 - i // bottom-most = 0\n return at(order * step, node.to({ data: { opacity: 1, x: 0 }, duration: per, easing }))\n })\n const lastMarkerEnds = (nodes.length - 1) * step + per\n\n // Once every marker has landed, the caption slides in from the right.\n return compose([\n ...markers,\n ...(this.labelNode\n ? [at(lastMarkerEnds, this.labelNode.to({ data: { opacity: 1, x: 0 }, duration: caption, easing }))]\n : []),\n ])\n }\n}\n"]}
@@ -0,0 +1,91 @@
1
+ import { type AssetScope, Node2D, type Command, type CommandArgs, type EasingFunction, type Node2DProps, type RenderContext2D, type Stroke, type Vector2 } from "@motionscript/core";
2
+ import { type RegionBox } from "./shared.js";
3
+ export interface ChartLineProps extends Node2DProps {
4
+ /**
5
+ * The series polyline, already mapped into this node's local pixel space
6
+ * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.
7
+ */
8
+ points: Vector2[];
9
+ /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
10
+ stroke: Stroke;
11
+ /**
12
+ * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
13
+ * end to its right.
14
+ *
15
+ * Defaults to **1**, unlike the standalone chart this was ported from: in the
16
+ * studio a node's resting state is what the paused editor canvas paints, so a
17
+ * chart that only appeared once a command had run would edit blind. {@link
18
+ * enter} drives it from 0 regardless of where it rests, so the animation is
19
+ * unchanged.
20
+ */
21
+ progress: number;
22
+ /**
23
+ * Whether this line is drawn at all. `false` hides it outright — the switch
24
+ * the chart flips alongside its legend's per-series toggle.
25
+ */
26
+ enabled: boolean;
27
+ /**
28
+ * A slice of the plot to spotlight, in this node's own pixel space. When set
29
+ * to a real box, the stretches of the line *outside* it drop to
30
+ * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.
31
+ */
32
+ spotlight: RegionBox;
33
+ /** Opacity the out-of-region stretches fade to. */
34
+ dimOpacity: number;
35
+ }
36
+ /**
37
+ * A single series line of a {@link LineChart}: one rounded polyline traced
38
+ * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
39
+ * Sized and positioned by the parent, which shares the plot's coordinate frame.
40
+ *
41
+ * Two signals drive it: {@link ChartLineProps.progress} traces the line in
42
+ * (animated by {@link enter}) and `enabled` shows or hides it wholesale.
43
+ */
44
+ export declare class ChartLine extends Node2D<ChartLineProps> {
45
+ points: Vector2[];
46
+ stroke: Stroke;
47
+ progress: number;
48
+ enabled: boolean;
49
+ spotlight: RegionBox;
50
+ dimOpacity: number;
51
+ /**
52
+ * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
53
+ * paint props it carries — see {@link declarePaints}.
54
+ */
55
+ declareAssets(assets: AssetScope): void;
56
+ protected renderSelf(ctx: RenderContext2D): void;
57
+ /**
58
+ * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
59
+ * by *cumulative arc length* so the line traces at a steady pace regardless of
60
+ * uneven point spacing. Returns the whole-point prefix plus one interpolated
61
+ * point partway along the active segment.
62
+ */
63
+ private tracePoints;
64
+ /**
65
+ * Trace the line in from its left end to its right over `duration` seconds.
66
+ * Drives `progress` `0 → 1`.
67
+ *
68
+ * A `Command` rather than a generator, so the trace can be *evaluated* at a
69
+ * time instead of run to one — which is what lets a scene containing this
70
+ * chart be scrubbed in constant time. It no longer needs to prime `progress`
71
+ * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces
72
+ * by definition rather than by having reset something.
73
+ */
74
+ enter(args: CommandArgs<Record<string, never>> & {
75
+ duration: number;
76
+ }): Command<ChartLineProps>;
77
+ /**
78
+ * The trace, with both ends stated: `progress` runs `from` → `to`.
79
+ *
80
+ * What {@link LineChart.showSeries} and `hideSeries` are both made of — they
81
+ * are the same motion in opposite directions, and expressing them as one thing
82
+ * with endpoints is what stops the pair drifting apart.
83
+ *
84
+ * `enabled` rides along in the same value rather than being set before or after
85
+ * the command. A line is drawable for every `t` the trace covers and undrawn
86
+ * outside it, which is what makes arriving at a time backwards show what
87
+ * arriving forwards does — a flag flipped by a side effect would not.
88
+ */
89
+ enterFrom(from: number, duration: number, easing?: EasingFunction, to?: number): Command<ChartLineProps>;
90
+ }
91
+ //# sourceMappingURL=chart-line.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-line.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAKN,KAAK,OAAO,EACZ,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EAEX,KAAK,OAAO,EACb,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAGjB,MAAM,WAAW,cAAe,SAAQ,WAAW;IACjD;;;OAGG;IACH,MAAM,EAAE,OAAO,EAAE,CAAA;IACjB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAA;IACd;;;;;;;;;OASG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,SAAS,EAAE,SAAS,CAAA;IACpB,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,MAAM,CAAC,cAAc,CAAC;IACG,MAAM,EAAE,OAAO,EAAE,CAAA;IAE/D,MAAM,EAAE,MAAM,CAAA;IACY,QAAQ,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IACE,SAAS,EAAE,SAAS,CAAA;IAC7B,UAAU,EAAE,MAAM,CAAA;IAEhE;;;OAGG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;IAuChD;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IA+BnB;;;;;;;;;OASG;IAEH,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI/F;;;;;;;;;;;OAWG;IACH,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,cAA0B,EAClC,EAAE,SAAI,GACL,OAAO,CAAC,cAAc,CAAC;CAY3B"}
@@ -0,0 +1,156 @@
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, command, easeOut, strokeOps, property, } from "@motionscript/core";
8
+ import { SPOTLIGHT_DIM } from "../kit/shared.js";
9
+ import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
10
+ import { declarePaints } from "@motionscript/core/component";
11
+ /**
12
+ * A single series line of a {@link LineChart}: one rounded polyline traced
13
+ * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
14
+ * Sized and positioned by the parent, which shares the plot's coordinate frame.
15
+ *
16
+ * Two signals drive it: {@link ChartLineProps.progress} traces the line in
17
+ * (animated by {@link enter}) and `enabled` shows or hides it wholesale.
18
+ */
19
+ export class ChartLine extends Node2D {
20
+ /**
21
+ * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
22
+ * paint props it carries — see {@link declarePaints}.
23
+ */
24
+ declareAssets(assets) {
25
+ super.declareAssets(assets);
26
+ declarePaints(this, assets);
27
+ }
28
+ renderSelf(ctx) {
29
+ if (!this.enabled)
30
+ return;
31
+ const pts = this.points;
32
+ if (pts.length < 2)
33
+ return;
34
+ const p = Math.max(0, Math.min(1, this.progress));
35
+ if (p <= 0)
36
+ return;
37
+ const drawn = this.tracePoints(pts, p);
38
+ if (drawn.length < 2)
39
+ return;
40
+ const stroke = this.stroke;
41
+ const radius = (stroke[0]?.weight ?? 0) * 2; // round the joins
42
+ const box = this.spotlight;
43
+ if (!hasRegion(box)) {
44
+ ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
45
+ return;
46
+ }
47
+ // Spotlit: the whole line goes down to `dimOpacity`, then the stretches
48
+ // inside the region are re-drawn over it at full strength. Two passes rather
49
+ // than one dim + one bright *complementary* pair, so the bright run has
50
+ // continuous geometry through the region and its joins round the way an
51
+ // unspotlit line's do — and so the boundary lands exactly on the region edge.
52
+ ctx.draw(new Graphics2D()
53
+ .line({ points: drawn, radius })
54
+ .stroke(stroke)
55
+ .opacity(Math.max(0, Math.min(1, this.dimOpacity))));
56
+ // One `draw` per run: shapes chained before a `stroke()` are combined into a
57
+ // single surface, and stroking a union of disjoint open paths doesn't paint
58
+ // — so a line that leaves the region and comes back would lose both halves.
59
+ for (const run of clipPolylineToBox(drawn, box)) {
60
+ ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
61
+ }
62
+ }
63
+ /**
64
+ * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
65
+ * by *cumulative arc length* so the line traces at a steady pace regardless of
66
+ * uneven point spacing. Returns the whole-point prefix plus one interpolated
67
+ * point partway along the active segment.
68
+ */
69
+ tracePoints(pts, p) {
70
+ if (p >= 1 || pts.length < 2)
71
+ return pts;
72
+ if (p <= 0)
73
+ return [];
74
+ const segLen = [];
75
+ let total = 0;
76
+ for (let i = 1; i < pts.length; i++) {
77
+ const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
78
+ segLen.push(d);
79
+ total += d;
80
+ }
81
+ if (total === 0)
82
+ return pts;
83
+ let target = total * p;
84
+ const out = [pts[0]];
85
+ for (let i = 0; i < segLen.length; i++) {
86
+ if (target >= segLen[i]) {
87
+ out.push(pts[i + 1]);
88
+ target -= segLen[i];
89
+ }
90
+ else {
91
+ const t = segLen[i] === 0 ? 0 : target / segLen[i];
92
+ out.push({
93
+ x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
94
+ y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
95
+ });
96
+ break;
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+ /**
102
+ * Trace the line in from its left end to its right over `duration` seconds.
103
+ * Drives `progress` `0 → 1`.
104
+ *
105
+ * A `Command` rather than a generator, so the trace can be *evaluated* at a
106
+ * time instead of run to one — which is what lets a scene containing this
107
+ * chart be scrubbed in constant time. It no longer needs to prime `progress`
108
+ * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces
109
+ * by definition rather than by having reset something.
110
+ */
111
+ enter(args) {
112
+ return this.enterFrom(0, args.duration, args.easing ?? easeOut());
113
+ }
114
+ /**
115
+ * The trace, with both ends stated: `progress` runs `from` → `to`.
116
+ *
117
+ * What {@link LineChart.showSeries} and `hideSeries` are both made of — they
118
+ * are the same motion in opposite directions, and expressing them as one thing
119
+ * with endpoints is what stops the pair drifting apart.
120
+ *
121
+ * `enabled` rides along in the same value rather than being set before or after
122
+ * the command. A line is drawable for every `t` the trace covers and undrawn
123
+ * outside it, which is what makes arriving at a time backwards show what
124
+ * arriving forwards does — a flag flipped by a side effect would not.
125
+ */
126
+ enterFrom(from, duration, easing = easeOut(), to = 1) {
127
+ return this.command((t) => {
128
+ const progress = from + (to - from) * t;
129
+ // Hidden only once it has fully retraced, so the last frame of a hide is
130
+ // the empty plot rather than a line that vanished a frame early.
131
+ return { progress, enabled: progress > 0 };
132
+ }, duration, easing);
133
+ }
134
+ }
135
+ __decorate([
136
+ property({ default: () => [] })
137
+ ], ChartLine.prototype, "points", void 0);
138
+ __decorate([
139
+ property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })
140
+ ], ChartLine.prototype, "stroke", void 0);
141
+ __decorate([
142
+ property({ default: 1 })
143
+ ], ChartLine.prototype, "progress", void 0);
144
+ __decorate([
145
+ property({ default: true })
146
+ ], ChartLine.prototype, "enabled", void 0);
147
+ __decorate([
148
+ property({ default: () => EMPTY_REGION_BOX })
149
+ ], ChartLine.prototype, "spotlight", void 0);
150
+ __decorate([
151
+ property({ default: SPOTLIGHT_DIM })
152
+ ], ChartLine.prototype, "dimOpacity", void 0);
153
+ __decorate([
154
+ command()
155
+ ], ChartLine.prototype, "enter", null);
156
+ //# sourceMappingURL=chart-line.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,OAAO,EACP,OAAO,EACP,SAAS,EACT,QA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AAE,CAAC;6CAA2B;AAkGhE;IADC,OAAO,EAAE;sCAGT","sourcesContent":["import {\n type AssetScope,\n Graphics2D,\n Node2D,\n command,\n easeOut,\n strokeOps,\n property,\n type Command,\n type CommandArgs,\n type EasingFunction,\n type Node2DProps,\n type RenderContext2D,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/core\"\n\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\nimport {\n EMPTY_REGION_BOX,\n clipPolylineToBox,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\nimport { declarePaints } from \"@motionscript/core/component\"\n\nexport interface ChartLineProps extends Node2DProps {\n /**\n * The series polyline, already mapped into this node's local pixel space\n * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.\n */\n points: Vector2[]\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\n stroke: Stroke\n /**\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\n * end to its right.\n *\n * Defaults to **1**, unlike the standalone chart this was ported from: in the\n * studio a node's resting state is what the paused editor canvas paints, so a\n * chart that only appeared once a command had run would edit blind. {@link\n * enter} drives it from 0 regardless of where it rests, so the animation is\n * unchanged.\n */\n progress: number\n /**\n * Whether this line is drawn at all. `false` hides it outright — the switch\n * the chart flips alongside its legend's per-series toggle.\n */\n enabled: boolean\n /**\n * A slice of the plot to spotlight, in this node's own pixel space. When set\n * to a real box, the stretches of the line *outside* it drop to\n * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.\n */\n spotlight: RegionBox\n /** Opacity the out-of-region stretches fade to. */\n dimOpacity: number\n}\n\n/**\n * A single series line of a {@link LineChart}: one rounded polyline traced\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\n *\n * Two signals drive it: {@link ChartLineProps.progress} traces the line in\n * (animated by {@link enter}) and `enabled` shows or hides it wholesale.\n */\nexport class ChartLine extends Node2D<ChartLineProps> {\n @property({ default: () => [] as Vector2[] }) declare points: Vector2[]\n @property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })\n declare stroke: Stroke\n @property({ default: 1 }) declare progress: number\n @property({ default: true }) declare enabled: boolean\n @property({ default: () => EMPTY_REGION_BOX }) declare spotlight: RegionBox\n @property({ default: SPOTLIGHT_DIM }) declare dimOpacity: 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 if (!this.enabled) return\n const pts = this.points\n if (pts.length < 2) return\n\n const p = Math.max(0, Math.min(1, this.progress))\n if (p <= 0) return\n\n const drawn = this.tracePoints(pts, p)\n if (drawn.length < 2) return\n const stroke = this.stroke as StrokeResolved[]\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\n\n const box = this.spotlight\n if (!hasRegion(box)) {\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\n return\n }\n\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\n // inside the region are re-drawn over it at full strength. Two passes rather\n // than one dim + one bright *complementary* pair, so the bright run has\n // continuous geometry through the region and its joins round the way an\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\n ctx.draw(\n new Graphics2D()\n .line({ points: drawn, radius })\n .stroke(stroke)\n .opacity(Math.max(0, Math.min(1, this.dimOpacity)))\n )\n\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\n // single surface, and stroking a union of disjoint open paths doesn't paint\n // — so a line that leaves the region and comes back would lose both halves.\n for (const run of clipPolylineToBox(drawn, box)) {\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\n }\n }\n\n /**\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\n * by *cumulative arc length* so the line traces at a steady pace regardless of\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\n * point partway along the active segment.\n */\n private tracePoints(pts: Vector2[], p: number): Vector2[] {\n if (p >= 1 || pts.length < 2) return pts\n if (p <= 0) return []\n\n const segLen: number[] = []\n let total = 0\n for (let i = 1; i < pts.length; i++) {\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\n segLen.push(d)\n total += d\n }\n if (total === 0) return pts\n\n let target = total * p\n const out: Vector2[] = [pts[0]]\n for (let i = 0; i < segLen.length; i++) {\n if (target >= segLen[i]) {\n out.push(pts[i + 1])\n target -= segLen[i]\n } else {\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\n out.push({\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\n })\n break\n }\n }\n return out\n }\n\n /**\n * Trace the line in from its left end to its right over `duration` seconds.\n * Drives `progress` `0 → 1`.\n *\n * A `Command` rather than a generator, so the trace can be *evaluated* at a\n * time instead of run to one — which is what lets a scene containing this\n * chart be scrubbed in constant time. It no longer needs to prime `progress`\n * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces\n * by definition rather than by having reset something.\n */\n @command()\n enter(args: CommandArgs<Record<string, never>> & { duration: number }): Command<ChartLineProps> {\n return this.enterFrom(0, args.duration, args.easing ?? easeOut())\n }\n\n /**\n * The trace, with both ends stated: `progress` runs `from` → `to`.\n *\n * What {@link LineChart.showSeries} and `hideSeries` are both made of — they\n * are the same motion in opposite directions, and expressing them as one thing\n * with endpoints is what stops the pair drifting apart.\n *\n * `enabled` rides along in the same value rather than being set before or after\n * the command. A line is drawable for every `t` the trace covers and undrawn\n * outside it, which is what makes arriving at a time backwards show what\n * arriving forwards does — a flag flipped by a side effect would not.\n */\n enterFrom(\n from: number,\n duration: number,\n easing: EasingFunction = easeOut(),\n to = 1\n ): Command<ChartLineProps> {\n return this.command<ChartLineProps>(\n (t) => {\n const progress = from + (to - from) * t\n // Hidden only once it has fully retraced, so the last frame of a hide is\n // the empty plot rather than a line that vanished a frame early.\n return { progress, enabled: progress > 0 }\n },\n duration,\n easing\n )\n }\n}\n"]}
@@ -0,0 +1,47 @@
1
+ import { type AssetScope, Node2D, type Fill, type Node2DProps, type RenderContext2D, type Stroke } from "@motionscript/core";
2
+ import { type RegionBox } from "./shared.js";
3
+ export interface ChartRegionProps extends Node2DProps {
4
+ /**
5
+ * The highlighted slice, already resolved into this node's local pixel space
6
+ * (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box
7
+ * draws nothing.
8
+ */
9
+ box: RegionBox;
10
+ /** Dashed rule marking each *bounded* edge of the box. */
11
+ stroke: Stroke;
12
+ /** Wash filling the box, under the series lines. */
13
+ fill: Fill;
14
+ /**
15
+ * Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven
16
+ * by the chart's own `regionReveal`, so the rules and the series' dimming move
17
+ * as one.
18
+ */
19
+ reveal: number;
20
+ }
21
+ /**
22
+ * The **region call-out** of a {@link LineChart}: a washed rectangle over the
23
+ * plot with a dashed rule down each edge the author actually bounded. Sized and
24
+ * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather
25
+ * than its own `layoutBounds` — the box already carries the plot geometry.
26
+ *
27
+ * It draws only the *marking*; fading the series outside the region is
28
+ * {@link ChartLine}'s job (it clips its own polyline against the same box), so
29
+ * the two can't disagree about where the boundary is.
30
+ *
31
+ * Only bounded edges get a rule: a region given just an `x` range spans the full
32
+ * plot height, so its top and bottom edges are the plot's own border, not a data
33
+ * bound — drawing dashes there would assert a limit the author didn't set.
34
+ */
35
+ export declare class ChartRegion extends Node2D<ChartRegionProps> {
36
+ box: RegionBox;
37
+ stroke: Stroke;
38
+ fill: Fill;
39
+ reveal: number;
40
+ /**
41
+ * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the
42
+ * paint props it carries — see {@link declarePaints}.
43
+ */
44
+ declareAssets(assets: AssetScope): void;
45
+ protected renderSelf(ctx: RenderContext2D): void;
46
+ }
47
+ //# sourceMappingURL=chart-region.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,MAAM,EAIN,KAAK,IAAI,EAET,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAGjB,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD;;;;OAIG;IACH,GAAG,EAAE,SAAS,CAAA;IACd,0DAA0D;IAC1D,MAAM,EAAE,MAAM,CAAA;IACd,oDAAoD;IACpD,IAAI,EAAE,IAAI,CAAA;IACV;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAY,SAAQ,MAAM,CAAC,gBAAgB,CAAC;IACA,GAAG,EAAE,SAAS,CAAA;IAM7D,MAAM,EAAE,MAAM,CAAA;IAMd,IAAI,EAAE,IAAI,CAAA;IACgB,MAAM,EAAE,MAAM,CAAA;IAEhD;;;OAGG;IACM,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAKhD,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,eAAe,GAAG,IAAI;CAqDjD"}
@@ -0,0 +1,101 @@
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";
8
+ import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
9
+ import { declarePaints } from "@motionscript/core/component";
10
+ /**
11
+ * The **region call-out** of a {@link LineChart}: a washed rectangle over the
12
+ * 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.
15
+ *
16
+ * It draws only the *marking*; fading the series outside the region is
17
+ * {@link ChartLine}'s job (it clips its own polyline against the same box), so
18
+ * the two can't disagree about where the boundary is.
19
+ *
20
+ * Only bounded edges get a rule: a region given just an `x` range spans the full
21
+ * plot height, so its top and bottom edges are the plot's own border, not a data
22
+ * bound — drawing dashes there would assert a limit the author didn't set.
23
+ */
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;
35
+ if (!hasRegion(box))
36
+ return;
37
+ const r = Math.max(0, Math.min(1, this.reveal));
38
+ if (r <= 0)
39
+ return;
40
+ const width = box.right - box.left;
41
+ const height = box.top - box.bottom;
42
+ const cx = (box.left + box.right) / 2;
43
+ const cy = (box.bottom + box.top) / 2;
44
+ // 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));
51
+ }
52
+ // One rule per bounded edge, growing from the region's centre outward as
53
+ // `reveal` climbs — the same "trace it in" beat as the series lines.
54
+ const stroke = this.stroke;
55
+ if (stroke.length === 0)
56
+ return;
57
+ // One `draw` per rule rather than four line ops under a single paint:
58
+ // shapes chained before a `stroke()` are combined into one surface, and
59
+ // 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));
61
+ if (box.xBounded) {
62
+ 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
+ }
69
+ }
70
+ if (box.yBounded) {
71
+ 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
+ }
78
+ }
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);
101
+ //# sourceMappingURL=chart-region.js.map