@motionscript/charts 0.1.0-alpha.5 → 0.1.0-alpha.7

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 (146) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/README.md +30 -16
  3. package/dist/bar-chart/bar-chart.d.ts +133 -242
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  5. package/dist/bar-chart/bar-chart.js +378 -569
  6. package/dist/bar-chart/bar-chart.js.map +1 -1
  7. package/dist/bar-chart/category-axis.d.ts +35 -41
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  9. package/dist/bar-chart/category-axis.js +93 -115
  10. package/dist/bar-chart/category-axis.js.map +1 -1
  11. package/dist/bar-chart/chart-bars.d.ts +50 -70
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  13. package/dist/bar-chart/chart-bars.js +156 -210
  14. package/dist/bar-chart/chart-bars.js.map +1 -1
  15. package/dist/bar-chart/index.d.ts +2 -2
  16. package/dist/bar-chart/index.d.ts.map +1 -1
  17. package/dist/bar-chart/index.js +1 -1
  18. package/dist/bar-chart/index.js.map +1 -1
  19. package/dist/bar-chart/shared.d.ts +3 -3
  20. package/dist/bar-chart/shared.d.ts.map +1 -1
  21. package/dist/bar-chart/shared.js +3 -3
  22. package/dist/bar-chart/shared.js.map +1 -1
  23. package/dist/browser/chunks/chunk-XROBIRQK.js +2 -0
  24. package/dist/browser/chunks/chunk-XROBIRQK.js.map +7 -0
  25. package/dist/browser/index.js +1 -1
  26. package/dist/browser/index.js.map +3 -3
  27. package/dist/browser/kit.js +1 -1
  28. package/dist/browser/manifest.json +1 -1
  29. package/dist/engine.d.ts +8 -6
  30. package/dist/engine.d.ts.map +1 -1
  31. package/dist/engine.js +8 -6
  32. package/dist/engine.js.map +1 -1
  33. package/dist/kit/cartesian.d.ts +44 -0
  34. package/dist/kit/cartesian.d.ts.map +1 -0
  35. package/dist/kit/cartesian.js +59 -0
  36. package/dist/kit/cartesian.js.map +1 -0
  37. package/dist/kit/chart-border.d.ts +10 -11
  38. package/dist/kit/chart-border.d.ts.map +1 -1
  39. package/dist/kit/chart-border.js +15 -32
  40. package/dist/kit/chart-border.js.map +1 -1
  41. package/dist/kit/chart-canvas.d.ts +32 -21
  42. package/dist/kit/chart-canvas.d.ts.map +1 -1
  43. package/dist/kit/chart-canvas.js +33 -90
  44. package/dist/kit/chart-canvas.js.map +1 -1
  45. package/dist/kit/chart-legend.d.ts +123 -64
  46. package/dist/kit/chart-legend.d.ts.map +1 -1
  47. package/dist/kit/chart-legend.js +129 -154
  48. package/dist/kit/chart-legend.js.map +1 -1
  49. package/dist/kit/entries.d.ts +17 -0
  50. package/dist/kit/entries.d.ts.map +1 -0
  51. package/dist/kit/entries.js +19 -0
  52. package/dist/kit/entries.js.map +1 -0
  53. package/dist/kit/motion.d.ts +48 -0
  54. package/dist/kit/motion.d.ts.map +1 -0
  55. package/dist/kit/motion.js +63 -0
  56. package/dist/kit/motion.js.map +1 -0
  57. package/dist/kit/paints.d.ts +10 -0
  58. package/dist/kit/paints.d.ts.map +1 -0
  59. package/dist/kit/paints.js +12 -0
  60. package/dist/kit/paints.js.map +1 -0
  61. package/dist/kit/shared.d.ts +31 -3
  62. package/dist/kit/shared.d.ts.map +1 -1
  63. package/dist/kit/shared.js +42 -3
  64. package/dist/kit/shared.js.map +1 -1
  65. package/dist/kit/vertical-axis.d.ts +48 -61
  66. package/dist/kit/vertical-axis.d.ts.map +1 -1
  67. package/dist/kit/vertical-axis.js +97 -132
  68. package/dist/kit/vertical-axis.js.map +1 -1
  69. package/dist/line-chart/chart-line.d.ts +60 -77
  70. package/dist/line-chart/chart-line.d.ts.map +1 -1
  71. package/dist/line-chart/chart-line.js +100 -121
  72. package/dist/line-chart/chart-line.js.map +1 -1
  73. package/dist/line-chart/chart-region.d.ts +32 -33
  74. package/dist/line-chart/chart-region.d.ts.map +1 -1
  75. package/dist/line-chart/chart-region.js +31 -65
  76. package/dist/line-chart/chart-region.js.map +1 -1
  77. package/dist/line-chart/horizontal-axis.d.ts +58 -64
  78. package/dist/line-chart/horizontal-axis.d.ts.map +1 -1
  79. package/dist/line-chart/horizontal-axis.js +94 -123
  80. package/dist/line-chart/horizontal-axis.js.map +1 -1
  81. package/dist/line-chart/index.d.ts +2 -2
  82. package/dist/line-chart/index.d.ts.map +1 -1
  83. package/dist/line-chart/index.js +1 -1
  84. package/dist/line-chart/index.js.map +1 -1
  85. package/dist/line-chart/line-chart.d.ts +156 -319
  86. package/dist/line-chart/line-chart.d.ts.map +1 -1
  87. package/dist/line-chart/line-chart.js +403 -663
  88. package/dist/line-chart/line-chart.js.map +1 -1
  89. package/dist/line-chart/shared.d.ts +3 -3
  90. package/dist/line-chart/shared.d.ts.map +1 -1
  91. package/dist/line-chart/shared.js +3 -3
  92. package/dist/line-chart/shared.js.map +1 -1
  93. package/dist/nodes.d.ts +6 -9
  94. package/dist/nodes.d.ts.map +1 -1
  95. package/dist/nodes.js +7 -9
  96. package/dist/nodes.js.map +1 -1
  97. package/dist/pie-chart/index.d.ts +2 -2
  98. package/dist/pie-chart/index.d.ts.map +1 -1
  99. package/dist/pie-chart/index.js +1 -1
  100. package/dist/pie-chart/index.js.map +1 -1
  101. package/dist/pie-chart/pie-chart.d.ts +108 -132
  102. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  103. package/dist/pie-chart/pie-chart.js +200 -271
  104. package/dist/pie-chart/pie-chart.js.map +1 -1
  105. package/dist/pie-chart/pie-legend.d.ts +84 -31
  106. package/dist/pie-chart/pie-legend.d.ts.map +1 -1
  107. package/dist/pie-chart/pie-legend.js +93 -107
  108. package/dist/pie-chart/pie-legend.js.map +1 -1
  109. package/dist/pie-chart/pie-ring.d.ts +160 -131
  110. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  111. package/dist/pie-chart/pie-ring.js +333 -391
  112. package/dist/pie-chart/pie-ring.js.map +1 -1
  113. package/dist/pie-chart/shared.d.ts +2 -2
  114. package/dist/pie-chart/shared.d.ts.map +1 -1
  115. package/dist/pie-chart/shared.js +2 -2
  116. package/dist/pie-chart/shared.js.map +1 -1
  117. package/package.json +4 -4
  118. package/src/bar-chart/bar-chart.ts +415 -701
  119. package/src/bar-chart/category-axis.ts +95 -110
  120. package/src/bar-chart/chart-bars.ts +178 -200
  121. package/src/bar-chart/index.ts +2 -2
  122. package/src/bar-chart/shared.ts +3 -3
  123. package/src/engine.ts +8 -6
  124. package/src/kit/cartesian.ts +81 -0
  125. package/src/kit/chart-border.ts +22 -33
  126. package/src/kit/chart-canvas.ts +44 -79
  127. package/src/kit/chart-legend.ts +173 -189
  128. package/src/kit/entries.ts +20 -0
  129. package/src/kit/motion.ts +90 -0
  130. package/src/kit/paints.ts +15 -0
  131. package/src/kit/shared.ts +52 -3
  132. package/src/kit/vertical-axis.ts +110 -140
  133. package/src/line-chart/chart-line.ts +102 -154
  134. package/src/line-chart/chart-region.ts +35 -80
  135. package/src/line-chart/horizontal-axis.ts +101 -152
  136. package/src/line-chart/index.ts +2 -2
  137. package/src/line-chart/line-chart.ts +449 -825
  138. package/src/line-chart/shared.ts +3 -3
  139. package/src/nodes.ts +8 -10
  140. package/src/pie-chart/index.ts +2 -2
  141. package/src/pie-chart/pie-chart.ts +221 -311
  142. package/src/pie-chart/pie-legend.ts +124 -114
  143. package/src/pie-chart/pie-ring.ts +386 -473
  144. package/src/pie-chart/shared.ts +2 -2
  145. package/dist/browser/chunks/chunk-5ZPBV6BU.js +0 -2
  146. package/dist/browser/chunks/chunk-5ZPBV6BU.js.map +0 -7
@@ -1,45 +1,116 @@
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/sdk";
1
+ import { Graphics2D, Types, component2d, strokeOps, } from "@motionscript/sdk";
2
+ import { fresh } from "../kit/entries.js";
3
+ import { frameEase } from "../kit/motion.js";
4
+ import { loadPaints } from "../kit/paints.js";
8
5
  import { SPOTLIGHT_DIM } from "../kit/shared.js";
9
6
  import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
10
- import { declarePaints } from "@motionscript/sdk/component";
7
+ /**
8
+ * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal
9
+ * by *cumulative arc length* so the line traces at a steady pace regardless of
10
+ * uneven point spacing. Returns the whole-point prefix plus one interpolated
11
+ * point partway along the active segment.
12
+ */
13
+ function tracePoints(pts, p) {
14
+ if (p >= 1 || pts.length < 2)
15
+ return pts;
16
+ if (p <= 0)
17
+ return [];
18
+ const segLen = [];
19
+ let total = 0;
20
+ for (let i = 1; i < pts.length; i++) {
21
+ const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y);
22
+ segLen.push(d);
23
+ total += d;
24
+ }
25
+ if (total === 0)
26
+ return pts;
27
+ let target = total * p;
28
+ const out = [pts[0]];
29
+ for (let i = 0; i < segLen.length; i++) {
30
+ if (target >= segLen[i]) {
31
+ out.push(pts[i + 1]);
32
+ target -= segLen[i];
33
+ }
34
+ else {
35
+ const t = segLen[i] === 0 ? 0 : target / segLen[i];
36
+ out.push({
37
+ x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,
38
+ y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,
39
+ });
40
+ break;
41
+ }
42
+ }
43
+ return out;
44
+ }
11
45
  /**
12
46
  * A single series line of a {@link LineChart}: one rounded polyline traced
13
47
  * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
14
48
  * Sized and positioned by the parent, which shares the plot's coordinate frame.
15
49
  *
16
- * Two signals drive it: {@link ChartLineProps.progress} traces the line in
17
- * (animated by {@link enter}) and `enabled` shows or hides it wholesale.
50
+ * Two signals drive it: `progress` traces the line in
51
+ * (animated by `enter`) and `enabled` shows or hides it wholesale.
18
52
  */
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)
53
+ export const ChartLine = component2d({
54
+ key: "chartLine",
55
+ state: {
56
+ /** The series polyline, already mapped into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x. */
57
+ points: fresh(() => []),
58
+ /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
59
+ stroke: Types.custom([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
60
+ /**
61
+ * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
62
+ * end to its right. Defaults to 1, so the paused editor canvas paints the line;
63
+ * `enter` drives it from 0 regardless of where it rests.
64
+ */
65
+ progress: 1,
66
+ /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */
67
+ enabled: true,
68
+ /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */
69
+ spotlight: fresh(() => EMPTY_REGION_BOX),
70
+ /** Opacity the out-of-region stretches fade to. */
71
+ dimOpacity: SPOTLIGHT_DIM,
72
+ },
73
+ load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),
74
+ commands: {
75
+ /**
76
+ * Trace the line from `from` to `to` over the command — by default in from
77
+ * its left end to its right. `showSeries` and `hideSeries` are the same
78
+ * motion in opposite directions, so both are this with their ends stated.
79
+ *
80
+ * `enabled` rides along in the same value rather than being set before or
81
+ * after the command: a line is drawable for every `t` the trace covers and
82
+ * undrawn outside it, which is what makes arriving at a time backwards show
83
+ * what arriving forwards does.
84
+ */
85
+ enter: {
86
+ args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },
87
+ run: (timeline) => {
88
+ const { from, to } = timeline.args;
89
+ const ease = frameEase(timeline);
90
+ return timeline.animate((t) => {
91
+ const progress = from + (to - from) * ease(t);
92
+ // Hidden only once it has fully retraced, so the last frame of a hide is
93
+ // the empty plot rather than a line that vanished a frame early.
94
+ return { progress, enabled: progress > 0 };
95
+ });
96
+ },
97
+ },
98
+ },
99
+ render: (ctx, state) => {
100
+ if (!state.enabled)
30
101
  return;
31
- const pts = this.points;
102
+ const pts = state.points;
32
103
  if (pts.length < 2)
33
104
  return;
34
- const p = Math.max(0, Math.min(1, this.progress));
105
+ const p = Math.max(0, Math.min(1, state.progress));
35
106
  if (p <= 0)
36
107
  return;
37
- const drawn = this.tracePoints(pts, p);
108
+ const drawn = tracePoints(pts, p);
38
109
  if (drawn.length < 2)
39
110
  return;
40
- const stroke = this.stroke;
111
+ const stroke = state.stroke;
41
112
  const radius = (stroke[0]?.weight ?? 0) * 2; // round the joins
42
- const box = this.spotlight;
113
+ const box = state.spotlight;
43
114
  if (!hasRegion(box)) {
44
115
  ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
45
116
  return;
@@ -52,105 +123,13 @@ export class ChartLine extends Node2D {
52
123
  ctx.draw(new Graphics2D()
53
124
  .line({ points: drawn, radius })
54
125
  .stroke(stroke)
55
- .opacity(Math.max(0, Math.min(1, this.dimOpacity))));
126
+ .opacity(Math.max(0, Math.min(1, state.dimOpacity))));
56
127
  // One `draw` per run: shapes chained before a `stroke()` are combined into a
57
128
  // single surface, and stroking a union of disjoint open paths doesn't paint
58
129
  // — so a line that leaves the region and comes back would lose both halves.
59
130
  for (const run of clipPolylineToBox(drawn, box)) {
60
131
  ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
61
132
  }
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);
133
+ },
134
+ });
156
135
  //# sourceMappingURL=chart-line.js.map
@@ -1 +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,QAAQ,GAST,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GAEV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAoC3D;;;;;;;GAOG;AACH,MAAM,OAAO,SAAU,SAAQ,MAAsB;IASnD;;;OAGG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAA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,EACZ,QAAgB,EAChB,SAAyB,OAAO,EAAE,EAClC,EAAE,GAAG,CAAC;QAEN,OAAO,IAAI,CAAC,OAAO,CACjB,CAAC,CAAC,EAAE,EAAE;YACJ,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;YACvC,yEAAyE;YACzE,iEAAiE;YACjE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,CAAC,EAAE,CAAA;QAC5C,CAAC,EACD,QAAQ,EACR,MAAM,CACP,CAAA;IACH,CAAC;CACF;AAzIuD;IAArD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAe,EAAE,CAAC;yCAA0B;AAE/D;IADP,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;yCACtD;AACY;IAAjC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;2CAAyB;AACb;IAApC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAAyB;AACE;IAAtD,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC;4CAA6B;AAC7B;IAA7C,QAAQ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;6CAA2B;AAkGhE;IADC,OAAO,EAAE;sCAGT","sourcesContent":["import {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n command,\r\n easeOut,\r\n strokeOps,\r\n property,\r\n type Command,\r\n type CommandArgs,\r\n type EasingFunction,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\n\r\nexport interface ChartLineProps extends Node2DProps {\r\n /**\r\n * The series polyline, already mapped into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x.\r\n */\r\n points: Vector2[]\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Stroke\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right.\r\n *\r\n * Defaults to **1**, unlike the standalone chart this was ported from: in an\r\n * editor a node's resting state is what the paused editor canvas paints, so a\r\n * chart that only appeared once a command had run would edit blind. {@link\r\n * enter} drives it from 0 regardless of where it rests, so the animation is\r\n * unchanged.\r\n */\r\n progress: number\r\n /**\r\n * Whether this line is drawn at all. `false` hides it outright — the switch\r\n * the chart flips alongside its legend's per-series toggle.\r\n */\r\n enabled: boolean\r\n /**\r\n * A slice of the plot to spotlight, in this node's own pixel space. When set\r\n * to a real box, the stretches of the line *outside* it drop to\r\n * {@link ChartLineProps.dimOpacity} while the stretches inside stay full.\r\n */\r\n spotlight: RegionBox\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: number\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: {@link ChartLineProps.progress} traces the line in\r\n * (animated by {@link enter}) and `enabled` shows or hides it wholesale.\r\n */\r\nexport class ChartLine extends Node2D<ChartLineProps> {\r\n @property({ default: () => [] as Vector2[] }) declare points: Vector2[]\r\n @property({ default: [], mapper: strokeOps.resolve, tween: strokeOps.lerp })\r\n declare stroke: Stroke\r\n @property({ default: 1 }) declare progress: number\r\n @property({ default: true }) declare enabled: boolean\r\n @property({ default: () => EMPTY_REGION_BOX }) declare spotlight: RegionBox\r\n @property({ default: SPOTLIGHT_DIM }) declare dimOpacity: number\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n if (!this.enabled) return\r\n const pts = this.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, this.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = this.tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = this.stroke as StrokeResolved[]\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = this.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, this.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n }\r\n\r\n /**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\n private tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n }\r\n\r\n /**\r\n * Trace the line in from its left end to its right over `duration` seconds.\r\n * Drives `progress` `0 → 1`.\r\n *\r\n * A `Command` rather than a generator, so the trace can be *evaluated* at a\r\n * time instead of run to one — which is what lets a scene containing this\r\n * chart be scrubbed in constant time. It no longer needs to prime `progress`\r\n * to 0 first: the value at `t` is a function of `t`, so a repeat call re-traces\r\n * by definition rather than by having reset something.\r\n */\r\n @command()\r\n enter(args: CommandArgs<Record<string, never>> & { duration: number }): Command<ChartLineProps> {\r\n return this.enterFrom(0, args.duration, args.easing ?? easeOut())\r\n }\r\n\r\n /**\r\n * The trace, with both ends stated: `progress` runs `from` → `to`.\r\n *\r\n * What {@link LineChart.showSeries} and `hideSeries` are both made of — they\r\n * are the same motion in opposite directions, and expressing them as one thing\r\n * with endpoints is what stops the pair drifting apart.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or after\r\n * the command. A line is drawable for every `t` the trace covers and undrawn\r\n * outside it, which is what makes arriving at a time backwards show what\r\n * arriving forwards does — a flag flipped by a side effect would not.\r\n */\r\n enterFrom(\r\n from: number,\r\n duration: number,\r\n easing: EasingFunction = easeOut(),\r\n to = 1\r\n ): Command<ChartLineProps> {\r\n return this.command<ChartLineProps>(\r\n (t) => {\r\n const progress = from + (to - from) * t\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n },\r\n duration,\r\n easing\r\n )\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"chart-line.js","sourceRoot":"","sources":["../../src/line-chart/chart-line.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,KAAK,EACL,WAAW,EACX,SAAS,GAOV,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,GAEV,MAAM,UAAU,CAAA;AAEjB;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAc,EAAE,CAAS;IAC5C,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAA;IACxC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IAErB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,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6E;QAC7E,wEAAwE;QACxE,wEAAwE;QACxE,8EAA8E;QAC9E,GAAG,CAAC,IAAI,CACN,IAAI,UAAU,EAAE;aACb,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;aAC/B,MAAM,CAAC,MAAM,CAAC;aACd,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CACvD,CAAA;QAED,6EAA6E;QAC7E,4EAA4E;QAC5E,4EAA4E;QAC5E,KAAK,MAAM,GAAG,IAAI,iBAAiB,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YAChD,GAAG,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n strokeOps,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n type Vector2,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { frameEase } from \"../kit/motion\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\r\nimport {\r\n EMPTY_REGION_BOX,\r\n clipPolylineToBox,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\n/**\r\n * The prefix of `pts` revealed at fraction `p ∈ [0, 1]`, measuring the reveal\r\n * by *cumulative arc length* so the line traces at a steady pace regardless of\r\n * uneven point spacing. Returns the whole-point prefix plus one interpolated\r\n * point partway along the active segment.\r\n */\r\nfunction tracePoints(pts: Vector2[], p: number): Vector2[] {\r\n if (p >= 1 || pts.length < 2) return pts\r\n if (p <= 0) return []\r\n\r\n const segLen: number[] = []\r\n let total = 0\r\n for (let i = 1; i < pts.length; i++) {\r\n const d = Math.hypot(pts[i].x - pts[i - 1].x, pts[i].y - pts[i - 1].y)\r\n segLen.push(d)\r\n total += d\r\n }\r\n if (total === 0) return pts\r\n\r\n let target = total * p\r\n const out: Vector2[] = [pts[0]]\r\n for (let i = 0; i < segLen.length; i++) {\r\n if (target >= segLen[i]) {\r\n out.push(pts[i + 1])\r\n target -= segLen[i]\r\n } else {\r\n const t = segLen[i] === 0 ? 0 : target / segLen[i]\r\n out.push({\r\n x: pts[i].x + (pts[i + 1].x - pts[i].x) * t,\r\n y: pts[i].y + (pts[i + 1].y - pts[i].y) * t,\r\n })\r\n break\r\n }\r\n }\r\n return out\r\n}\r\n\r\n/**\r\n * A single series line of a {@link LineChart}: one rounded polyline traced\r\n * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.\r\n * Sized and positioned by the parent, which shares the plot's coordinate frame.\r\n *\r\n * Two signals drive it: `progress` traces the line in\r\n * (animated by `enter`) and `enabled` shows or hides it wholesale.\r\n */\r\nexport const ChartLine = component2d({\r\n key: \"chartLine\",\r\n state: {\r\n /** The series polyline, already mapped into this node's local pixel space (origin at centre, y-up) by the parent {@link LineChart}. Ordered along x. */\r\n points: fresh<Vector2[]>(() => []),\r\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\r\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n /**\r\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\r\n * end to its right. Defaults to 1, so the paused editor canvas paints the line;\r\n * `enter` drives it from 0 regardless of where it rests.\r\n */\r\n progress: 1,\r\n /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */\r\n enabled: true,\r\n /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */\r\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n /** Opacity the out-of-region stretches fade to. */\r\n dimOpacity: SPOTLIGHT_DIM,\r\n },\r\n load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),\r\n commands: {\r\n /**\r\n * Trace the line from `from` to `to` over the command — by default in from\r\n * its left end to its right. `showSeries` and `hideSeries` are the same\r\n * motion in opposite directions, so both are this with their ends stated.\r\n *\r\n * `enabled` rides along in the same value rather than being set before or\r\n * after the command: a line is drawable for every `t` the trace covers and\r\n * undrawn outside it, which is what makes arriving at a time backwards show\r\n * what arriving forwards does.\r\n */\r\n enter: {\r\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\r\n run: (timeline) => {\r\n const { from, to } = timeline.args\r\n const ease = frameEase(timeline)\r\n return timeline.animate((t) => {\r\n const progress = from + (to - from) * ease(t)\r\n // Hidden only once it has fully retraced, so the last frame of a hide is\r\n // the empty plot rather than a line that vanished a frame early.\r\n return { progress, enabled: progress > 0 }\r\n })\r\n },\r\n },\r\n },\r\n render: (ctx, state) => {\r\n if (!state.enabled) return\r\n const pts = state.points\r\n if (pts.length < 2) return\r\n\r\n const p = Math.max(0, Math.min(1, state.progress))\r\n if (p <= 0) return\r\n\r\n const drawn = tracePoints(pts, p)\r\n if (drawn.length < 2) return\r\n const stroke = state.stroke\r\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\r\n\r\n const box = state.spotlight\r\n if (!hasRegion(box)) {\r\n ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke))\r\n return\r\n }\r\n\r\n // Spotlit: the whole line goes down to `dimOpacity`, then the stretches\r\n // inside the region are re-drawn over it at full strength. Two passes rather\r\n // than one dim + one bright *complementary* pair, so the bright run has\r\n // continuous geometry through the region and its joins round the way an\r\n // unspotlit line's do — and so the boundary lands exactly on the region edge.\r\n ctx.draw(\r\n new Graphics2D()\r\n .line({ points: drawn, radius })\r\n .stroke(stroke)\r\n .opacity(Math.max(0, Math.min(1, state.dimOpacity)))\r\n )\r\n\r\n // One `draw` per run: shapes chained before a `stroke()` are combined into a\r\n // single surface, and stroking a union of disjoint open paths doesn't paint\r\n // — so a line that leaves the region and comes back would lose both halves.\r\n for (const run of clipPolylineToBox(drawn, box)) {\r\n ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke))\r\n }\r\n },\r\n})\r\n\r\nexport type ChartLine = NodeOf<typeof ChartLine>\r\n"]}
@@ -1,28 +1,10 @@
1
- import { type AssetScope, Node2D, type Fill, type Node2DProps, type RenderContext2D, type Stroke } from "@motionscript/sdk";
1
+ import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved } from "@motionscript/sdk";
2
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
3
  /**
22
4
  * The **region call-out** of a {@link LineChart}: a washed rectangle over the
23
5
  * 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.
6
+ * positioned entirely from the pre-mapped `box` rather
7
+ * than its own box — the region already carries the plot geometry.
26
8
  *
27
9
  * It draws only the *marking*; fading the series outside the region is
28
10
  * {@link ChartLine}'s job (it clips its own polyline against the same box), so
@@ -32,16 +14,33 @@ export interface ChartRegionProps extends Node2DProps {
32
14
  * plot height, so its top and bottom edges are the plot's own border, not a data
33
15
  * bound — drawing dashes there would assert a limit the author didn't set.
34
16
  */
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
- }
17
+ export declare const ChartRegion: import("@motionscript/sdk").Component<"chartRegion", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
18
+ /** 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. */
19
+ readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
20
+ /** Dashed rule marking each *bounded* edge of the box. */
21
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
22
+ /** Wash filling the box, under the series lines. */
23
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
24
+ /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
25
+ readonly reveal: 0;
26
+ }>, {}, null, _Node2D<import("@motionscript/core").Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
27
+ /** 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. */
28
+ readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
29
+ /** Dashed rule marking each *bounded* edge of the box. */
30
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
31
+ /** Wash filling the box, under the series lines. */
32
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
33
+ /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
34
+ readonly reveal: 0;
35
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
36
+ /** 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. */
37
+ readonly box: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
38
+ /** Dashed rule marking each *bounded* edge of the box. */
39
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
40
+ /** Wash filling the box, under the series lines. */
41
+ readonly fill: import("@motionscript/sdk").Type<Fill, FillResolved[], false>;
42
+ /** Reveal of the annotation in `[0, 1]`, driven by the chart's own `regionReveal` so the rules and the series' dimming move as one. */
43
+ readonly reveal: 0;
44
+ }>, {}, _Node2D<import("@motionscript/core").Node2DProps>>>>;
45
+ export type ChartRegion = NodeOf<typeof ChartRegion>;
47
46
  //# sourceMappingURL=chart-region.d.ts.map
@@ -1 +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,mBAAmB,CAAA;AAE1B,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"}
1
+ {"version":3,"file":"chart-region.d.ts","sourceRoot":"","sources":["../../src/line-chart/chart-region.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EACT,KAAK,YAAY,EACjB,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAEjB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW;IAGpB,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;;IANvI,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;;IANvI,2KAA2K;;IAE3K,0DAA0D;;IAE1D,oDAAoD;;IAEpD,uIAAuI;;4DAwCzI,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,CAAA"}
@@ -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/sdk";
1
+ import { Graphics2D, Types, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
2
+ import { fresh } from "../kit/entries.js";
3
+ import { loadPaints } from "../kit/paints.js";
8
4
  import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
9
- import { declarePaints } from "@motionscript/sdk/component";
10
5
  /**
11
6
  * The **region call-out** of a {@link LineChart}: a washed rectangle over the
12
7
  * plot with a dashed rule down each edge the author actually bounded. Sized and
13
- * 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/sdk/component";
21
16
  * plot height, so its top and bottom edges are the plot's own border, not a data
22
17
  * bound — drawing dashes there would assert a limit the author didn't set.
23
18
  */
24
- export 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,mBAAmB,CAAA;AAE1B,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,SAAS,GAEV,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAqB3D;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,WAAY,SAAQ,MAAwB;IAgBvD;;;OAGG;IACM,aAAa,CAAC,MAAkB;QACvC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QAC3B,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7B,CAAC;IAES,UAAU,CAAC,GAAoB;QACvC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACpB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;YAAE,OAAM;QAE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EAAE,OAAO,CAAC,IAAI;KACpB,CAAC;yCACgB;AACgB;IAAjC,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;2CAAuB","sourcesContent":["import {\r\n type AssetScope,\r\n Graphics2D,\r\n Node2D,\r\n fillOps,\r\n strokeOps,\r\n property,\r\n type Fill,\r\n type FillResolved,\r\n type Node2DProps,\r\n type RenderContext2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport {\r\n DEFAULT_CHART_THEME,\r\n EMPTY_REGION_BOX,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\nimport { declarePaints } from \"@motionscript/sdk/component\"\r\n\r\nexport interface ChartRegionProps extends Node2DProps {\r\n /**\r\n * The highlighted slice, already resolved into this node's local pixel space\r\n * (origin at centre, y-up) by the parent {@link LineChart}. A degenerate box\r\n * draws nothing.\r\n */\r\n box: RegionBox\r\n /** Dashed rule marking each *bounded* edge of the box. */\r\n stroke: Stroke\r\n /** Wash filling the box, under the series lines. */\r\n fill: Fill\r\n /**\r\n * Reveal of the annotation in `[0, 1]`: 0 hides it, 1 draws it fully. Driven\r\n * by the chart's own `regionReveal`, so the rules and the series' dimming move\r\n * as one.\r\n */\r\n reveal: number\r\n}\r\n\r\n/**\r\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\r\n * plot with a dashed rule down each edge the author actually bounded. Sized and\r\n * positioned entirely from the pre-mapped {@link ChartRegionProps.box} rather\r\n * than its own `layoutBounds` — the box already carries the plot geometry.\r\n *\r\n * It draws only the *marking*; fading the series outside the region is\r\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\r\n * the two can't disagree about where the boundary is.\r\n *\r\n * Only bounded edges get a rule: a region given just an `x` range spans the full\r\n * plot height, so its top and bottom edges are the plot's own border, not a data\r\n * bound — drawing dashes there would assert a limit the author didn't set.\r\n */\r\nexport class ChartRegion extends Node2D<ChartRegionProps> {\r\n @property({ default: () => EMPTY_REGION_BOX }) declare box: RegionBox\r\n @property({\r\n default: DEFAULT_CHART_THEME.region.stroke,\r\n mapper: strokeOps.resolve,\r\n tween: strokeOps.lerp,\r\n })\r\n declare stroke: Stroke\r\n @property({\r\n default: DEFAULT_CHART_THEME.region.fill,\r\n mapper: fillOps.resolve,\r\n tween: fillOps.lerp,\r\n })\r\n declare fill: Fill\r\n @property({ default: 0 }) declare reveal: number\r\n\r\n /**\r\n * This node extends `Node2D` rather than `ShapeNode`, so nothing declares the\r\n * paint props it carries — see {@link declarePaints}.\r\n */\r\n override declareAssets(assets: AssetScope): void {\r\n super.declareAssets(assets)\r\n declarePaints(this, assets)\r\n }\r\n\r\n protected renderSelf(ctx: RenderContext2D): void {\r\n const box = this.box\r\n if (!hasRegion(box)) return\r\n\r\n const r = Math.max(0, Math.min(1, this.reveal))\r\n if (r <= 0) return\r\n\r\n const width = box.right - box.left\r\n const height = box.top - box.bottom\r\n const cx = (box.left + box.right) / 2\r\n const cy = (box.bottom + box.top) / 2\r\n\r\n // Wash first, so the rules sit over their own tint.\r\n const layers = this.fill as FillResolved[]\r\n if (layers.length > 0) {\r\n ctx.draw(\r\n new Graphics2D()\r\n .rect({ x: cx, y: cy, width, height })\r\n .fill(this.fill)\r\n .opacity(r)\r\n )\r\n }\r\n\r\n // One rule per bounded edge, growing from the region's centre outward as\r\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\r\n const stroke = this.stroke as StrokeResolved[]\r\n if (stroke.length === 0) return\r\n\r\n // One `draw` per rule rather than four line ops under a single paint:\r\n // shapes chained before a `stroke()` are combined into one surface, and\r\n // stroking a union of disjoint open paths doesn't paint.\r\n const rule = (points: { x: number; y: number }[]) =>\r\n ctx.draw(new Graphics2D().line({ points }).stroke(this.stroke).opacity(r))\r\n\r\n if (box.xBounded) {\r\n const half = (height / 2) * r\r\n for (const x of [box.left, box.right]) {\r\n rule([\r\n { x, y: cy - half },\r\n { x, y: cy + half },\r\n ])\r\n }\r\n }\r\n if (box.yBounded) {\r\n const half = (width / 2) * r\r\n for (const y of [box.bottom, box.top]) {\r\n rule([\r\n { x: cx - half, y },\r\n { x: cx + half, y },\r\n ])\r\n }\r\n }\r\n }\r\n}\r\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,KAA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AAC,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 {\r\n Graphics2D,\r\n Types,\r\n component2d,\r\n fillOps,\r\n strokeOps,\r\n type Fill,\r\n type FillResolved,\r\n type NodeOf,\r\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\r\n type Node2D as _Node2D,\r\n type Stroke,\r\n type StrokeResolved,\r\n} from \"@motionscript/sdk\"\r\n\r\nimport { fresh } from \"../kit/entries\"\r\nimport { loadPaints } from \"../kit/paints\"\r\nimport {\r\n DEFAULT_CHART_THEME,\r\n EMPTY_REGION_BOX,\r\n hasRegion,\r\n type RegionBox,\r\n} from \"./shared\"\r\n\r\n/**\r\n * The **region call-out** of a {@link LineChart}: a washed rectangle over the\r\n * plot with a dashed rule down each edge the author actually bounded. Sized and\r\n * positioned entirely from the pre-mapped `box` rather\r\n * than its own box — the region already carries the plot geometry.\r\n *\r\n * It draws only the *marking*; fading the series outside the region is\r\n * {@link ChartLine}'s job (it clips its own polyline against the same box), so\r\n * the two can't disagree about where the boundary is.\r\n *\r\n * Only bounded edges get a rule: a region given just an `x` range spans the full\r\n * plot height, so its top and bottom edges are the plot's own border, not a data\r\n * bound — drawing dashes there would assert a limit the author didn't set.\r\n */\r\nexport const ChartRegion = component2d({\r\n key: \"chartRegion\",\r\n state: {\r\n /** 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. */\r\n box: fresh<RegionBox>(() => EMPTY_REGION_BOX),\r\n /** Dashed rule marking each *bounded* edge of the box. */\r\n stroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_CHART_THEME.region.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\r\n /** Wash filling the box, under the series lines. */\r\n fill: Types.custom<Fill, FillResolved[]>(DEFAULT_CHART_THEME.region.fill, { resolve: fillOps.resolve, lerp: fillOps.lerp }),\r\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. */\r\n reveal: 0,\r\n },\r\n load: (loader, state) => loadPaints(loader, { fills: [state.fill], strokes: [state.stroke] }),\r\n render: (ctx, state) => {\r\n const box = state.box\r\n if (!hasRegion(box)) return\r\n\r\n const r = Math.max(0, Math.min(1, state.reveal))\r\n if (r <= 0) return\r\n\r\n const width = box.right - box.left\r\n const height = box.top - box.bottom\r\n const cx = (box.left + box.right) / 2\r\n const cy = (box.bottom + box.top) / 2\r\n\r\n // Wash first, so the rules sit over their own tint.\r\n if (state.fill.length > 0) {\r\n ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r))\r\n }\r\n\r\n // One rule per bounded edge, growing from the region's centre outward as\r\n // `reveal` climbs — the same \"trace it in\" beat as the series lines.\r\n if (state.stroke.length === 0) return\r\n\r\n // One `draw` per rule rather than four line ops under a single paint:\r\n // shapes chained before a `stroke()` are combined into one surface, and\r\n // stroking a union of disjoint open paths doesn't paint.\r\n const rule = (points: { x: number; y: number }[]) =>\r\n ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r))\r\n\r\n if (box.xBounded) {\r\n const half = (height / 2) * r\r\n for (const x of [box.left, box.right]) rule([{ x, y: cy - half }, { x, y: cy + half }])\r\n }\r\n if (box.yBounded) {\r\n const half = (width / 2) * r\r\n for (const y of [box.bottom, box.top]) rule([{ x: cx - half, y }, { x: cx + half, y }])\r\n }\r\n },\r\n})\r\n\r\nexport type ChartRegion = NodeOf<typeof ChartRegion>\r\n"]}