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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +49 -0
  4. package/README.md +98 -3
  5. package/dist/bar-chart/bar-chart.d.ts +191 -0
  6. package/dist/bar-chart/bar-chart.d.ts.map +1 -0
  7. package/dist/bar-chart/bar-chart.js +431 -0
  8. package/dist/bar-chart/bar-chart.js.map +1 -0
  9. package/dist/bar-chart/category-axis.d.ts +71 -0
  10. package/dist/bar-chart/category-axis.d.ts.map +1 -0
  11. package/dist/bar-chart/category-axis.js +119 -0
  12. package/dist/bar-chart/category-axis.js.map +1 -0
  13. package/dist/bar-chart/chart-bars.d.ts +129 -0
  14. package/dist/bar-chart/chart-bars.d.ts.map +1 -0
  15. package/dist/bar-chart/chart-bars.js +181 -0
  16. package/dist/bar-chart/chart-bars.js.map +1 -0
  17. package/dist/bar-chart/index.d.ts +16 -0
  18. package/dist/bar-chart/index.d.ts.map +1 -0
  19. package/dist/bar-chart/index.js +12 -0
  20. package/dist/bar-chart/index.js.map +1 -0
  21. package/dist/bar-chart/shared.d.ts +146 -0
  22. package/dist/bar-chart/shared.d.ts.map +1 -0
  23. package/dist/bar-chart/shared.js +182 -0
  24. package/dist/bar-chart/shared.js.map +1 -0
  25. package/dist/browser/chunks/chunk-TJNHLQGV.js +2 -0
  26. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +7 -0
  27. package/dist/browser/index.js +2 -0
  28. package/dist/browser/index.js.map +7 -0
  29. package/dist/browser/kit.js +2 -0
  30. package/dist/browser/kit.js.map +7 -0
  31. package/dist/browser/manifest.json +13 -0
  32. package/dist/engine.d.ts +29 -0
  33. package/dist/engine.d.ts.map +1 -0
  34. package/dist/engine.js +29 -0
  35. package/dist/engine.js.map +1 -0
  36. package/dist/index.d.ts +6 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +6 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/kit/cartesian.d.ts +44 -0
  41. package/dist/kit/cartesian.d.ts.map +1 -0
  42. package/dist/kit/cartesian.js +59 -0
  43. package/dist/kit/cartesian.js.map +1 -0
  44. package/dist/kit/chart-border.d.ts +27 -0
  45. package/dist/kit/chart-border.d.ts.map +1 -0
  46. package/dist/kit/chart-border.js +28 -0
  47. package/dist/kit/chart-border.js.map +1 -0
  48. package/dist/kit/chart-canvas.d.ts +67 -0
  49. package/dist/kit/chart-canvas.d.ts.map +1 -0
  50. package/dist/kit/chart-canvas.js +68 -0
  51. package/dist/kit/chart-canvas.js.map +1 -0
  52. package/dist/kit/chart-legend.d.ts +164 -0
  53. package/dist/kit/chart-legend.d.ts.map +1 -0
  54. package/dist/kit/chart-legend.js +163 -0
  55. package/dist/kit/chart-legend.js.map +1 -0
  56. package/dist/kit/entries.d.ts +17 -0
  57. package/dist/kit/entries.d.ts.map +1 -0
  58. package/dist/kit/entries.js +19 -0
  59. package/dist/kit/entries.js.map +1 -0
  60. package/dist/kit/motion.d.ts +48 -0
  61. package/dist/kit/motion.d.ts.map +1 -0
  62. package/dist/kit/motion.js +63 -0
  63. package/dist/kit/motion.js.map +1 -0
  64. package/dist/kit/paints.d.ts +10 -0
  65. package/dist/kit/paints.d.ts.map +1 -0
  66. package/dist/kit/paints.js +12 -0
  67. package/dist/kit/paints.js.map +1 -0
  68. package/dist/kit/shared.d.ts +302 -0
  69. package/dist/kit/shared.d.ts.map +1 -0
  70. package/dist/kit/shared.js +496 -0
  71. package/dist/kit/shared.js.map +1 -0
  72. package/dist/kit/vertical-axis.d.ts +86 -0
  73. package/dist/kit/vertical-axis.d.ts.map +1 -0
  74. package/dist/kit/vertical-axis.js +141 -0
  75. package/dist/kit/vertical-axis.js.map +1 -0
  76. package/dist/line-chart/chart-line.d.ts +74 -0
  77. package/dist/line-chart/chart-line.d.ts.map +1 -0
  78. package/dist/line-chart/chart-line.js +135 -0
  79. package/dist/line-chart/chart-line.js.map +1 -0
  80. package/dist/line-chart/chart-region.d.ts +46 -0
  81. package/dist/line-chart/chart-region.d.ts.map +1 -0
  82. package/dist/line-chart/chart-region.js +67 -0
  83. package/dist/line-chart/chart-region.js.map +1 -0
  84. package/dist/line-chart/horizontal-axis.d.ts +79 -0
  85. package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
  86. package/dist/line-chart/horizontal-axis.js +129 -0
  87. package/dist/line-chart/horizontal-axis.js.map +1 -0
  88. package/dist/line-chart/index.d.ts +22 -0
  89. package/dist/line-chart/index.d.ts.map +1 -0
  90. package/dist/line-chart/index.js +19 -0
  91. package/dist/line-chart/index.js.map +1 -0
  92. package/dist/line-chart/line-chart.d.ts +200 -0
  93. package/dist/line-chart/line-chart.d.ts.map +1 -0
  94. package/dist/line-chart/line-chart.js +473 -0
  95. package/dist/line-chart/line-chart.js.map +1 -0
  96. package/dist/line-chart/shared.d.ts +171 -0
  97. package/dist/line-chart/shared.d.ts.map +1 -0
  98. package/dist/line-chart/shared.js +285 -0
  99. package/dist/line-chart/shared.js.map +1 -0
  100. package/dist/line-chart/x-scale.d.ts +77 -0
  101. package/dist/line-chart/x-scale.d.ts.map +1 -0
  102. package/dist/line-chart/x-scale.js +313 -0
  103. package/dist/line-chart/x-scale.js.map +1 -0
  104. package/dist/nodes.d.ts +17 -0
  105. package/dist/nodes.d.ts.map +1 -0
  106. package/dist/nodes.js +18 -0
  107. package/dist/nodes.js.map +1 -0
  108. package/dist/pie-chart/index.d.ts +18 -0
  109. package/dist/pie-chart/index.d.ts.map +1 -0
  110. package/dist/pie-chart/index.js +14 -0
  111. package/dist/pie-chart/index.js.map +1 -0
  112. package/dist/pie-chart/pie-chart.d.ts +152 -0
  113. package/dist/pie-chart/pie-chart.d.ts.map +1 -0
  114. package/dist/pie-chart/pie-chart.js +222 -0
  115. package/dist/pie-chart/pie-chart.js.map +1 -0
  116. package/dist/pie-chart/pie-legend.d.ts +113 -0
  117. package/dist/pie-chart/pie-legend.d.ts.map +1 -0
  118. package/dist/pie-chart/pie-legend.js +117 -0
  119. package/dist/pie-chart/pie-legend.js.map +1 -0
  120. package/dist/pie-chart/pie-ring.d.ts +304 -0
  121. package/dist/pie-chart/pie-ring.d.ts.map +1 -0
  122. package/dist/pie-chart/pie-ring.js +680 -0
  123. package/dist/pie-chart/pie-ring.js.map +1 -0
  124. package/dist/pie-chart/shared.d.ts +216 -0
  125. package/dist/pie-chart/shared.d.ts.map +1 -0
  126. package/dist/pie-chart/shared.js +246 -0
  127. package/dist/pie-chart/shared.js.map +1 -0
  128. package/package.json +72 -3
  129. package/registry.json +23 -0
  130. package/src/bar-chart/bar-chart.ts +542 -0
  131. package/src/bar-chart/category-axis.ts +162 -0
  132. package/src/bar-chart/chart-bars.ts +287 -0
  133. package/src/bar-chart/index.ts +31 -0
  134. package/src/bar-chart/shared.ts +354 -0
  135. package/src/engine.ts +28 -0
  136. package/src/index.ts +5 -0
  137. package/src/kit/cartesian.ts +81 -0
  138. package/src/kit/chart-border.ts +50 -0
  139. package/src/kit/chart-canvas.ts +122 -0
  140. package/src/kit/chart-legend.ts +229 -0
  141. package/src/kit/entries.ts +20 -0
  142. package/src/kit/motion.ts +90 -0
  143. package/src/kit/paints.ts +15 -0
  144. package/src/kit/shared.ts +782 -0
  145. package/src/kit/vertical-axis.ts +194 -0
  146. package/src/line-chart/chart-line.ts +156 -0
  147. package/src/line-chart/chart-region.ts +90 -0
  148. package/src/line-chart/horizontal-axis.ts +151 -0
  149. package/src/line-chart/index.ts +39 -0
  150. package/src/line-chart/line-chart.ts +598 -0
  151. package/src/line-chart/shared.ts +473 -0
  152. package/src/line-chart/x-scale.ts +382 -0
  153. package/src/nodes.ts +18 -0
  154. package/src/pie-chart/index.ts +37 -0
  155. package/src/pie-chart/pie-chart.ts +296 -0
  156. package/src/pie-chart/pie-legend.ts +169 -0
  157. package/src/pie-chart/pie-ring.ts +848 -0
  158. package/src/pie-chart/shared.ts +496 -0
@@ -0,0 +1,86 @@
1
+ import { type NodeOf, type Node2D, type Node2DProps } from "@motionscript/sdk";
2
+ import { type Arrival } from "./motion.js";
3
+ import { type AxisConfig, type Range } from "./shared.js";
4
+ export interface VerticalAxisProps extends Node2DProps {
5
+ /** `[min, max]` of the vertical scale the markers are positioned within. */
6
+ range: Range;
7
+ /**
8
+ * Tick values (in data units) to draw up the axis, each placed by its fraction
9
+ * across {@link VerticalAxisProps.range}. Need not be evenly spaced or include
10
+ * the ends.
11
+ */
12
+ markers: number[];
13
+ /**
14
+ * How each marker is captioned, one per entry of `markers` and in its order.
15
+ * Empty (the default), or short, captions a marker with its bare numeric
16
+ * reading; a chart with a number format on this axis writes them through it.
17
+ */
18
+ captions: string[];
19
+ /** Marker/caption text style, grid stroke, and gutters — see {@link AxisConfig}. */
20
+ axis: AxisConfig;
21
+ /**
22
+ * Rotated caption drawn in the gutter to the left of the marker column. Empty
23
+ * string (the default) hides it — no caption node is built and no label gutter
24
+ * is reserved.
25
+ */
26
+ label: string;
27
+ }
28
+ /** How a tick value is captioned — see {@link VerticalAxisProps.captions}. */
29
+ export type MarkerLabel = (value: number) => string;
30
+ /** What a marker's caption reads: the one listed for its value, else its bare reading. */
31
+ export declare function markerCaption(s: {
32
+ readonly markers: readonly number[];
33
+ readonly captions: readonly string[];
34
+ }, value: number): string;
35
+ /**
36
+ * The numeric vertical axis shared by the cartesian charts: a **column of
37
+ * {@link Text} nodes**, one per marker value, running top-to-bottom (highest
38
+ * value at the top). Pure layout — no `Graphics` — so the markers are real text
39
+ * nodes the scene can measure, restyle, or animate individually.
40
+ *
41
+ * Each marker is positioned so its centre lands exactly on its value's fraction
42
+ * across `range` within the axis's filled height, so unevenly-spaced markers
43
+ * land where their values fall. Both the caption and the position are *bound*,
44
+ * not snapshotted: a chart that rescales its axes (see `LineChart.zoomTo`)
45
+ * tweens `range`/`markers` live. Only the marker **count** is fixed at
46
+ * construction.
47
+ *
48
+ * `enter` staggers them in **bottom-to-top**: each marker starts pushed a
49
+ * little to the right and transparent, then fades and slides left into place.
50
+ * The resting state is the landed one, so a chart that is never told to enter
51
+ * still reads as a finished chart.
52
+ */
53
+ export declare const VerticalAxis: import("@motionscript/sdk").Component<"verticalAxis", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
54
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
55
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
56
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
57
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
58
+ readonly label: "";
59
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
60
+ }>, {
61
+ readonly enter: {
62
+ readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
63
+ readonly slide: import("@motionscript/sdk").Type<number, number, false>;
64
+ };
65
+ }, null, Node2D<Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
66
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
67
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
68
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
69
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
70
+ readonly label: "";
71
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
72
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
73
+ readonly range: import("@motionscript/sdk").Type<Range, Range, false>;
74
+ readonly markers: import("@motionscript/sdk").Type<number[], number[], false>;
75
+ readonly captions: import("@motionscript/sdk").Type<string[], string[], false>;
76
+ readonly axis: import("@motionscript/sdk").Type<AxisConfig, AxisConfig, false>;
77
+ readonly label: "";
78
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
79
+ }>, {
80
+ readonly enter: {
81
+ readonly stagger: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
82
+ readonly slide: import("@motionscript/sdk").Type<number, number, false>;
83
+ };
84
+ }, Node2D<Node2DProps>>>>;
85
+ export type VerticalAxis = NodeOf<typeof VerticalAxis>;
86
+ //# sourceMappingURL=vertical-axis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vertical-axis.d.ts","sourceRoot":"","sources":["../../src/kit/vertical-axis.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,MAAM,EACX,KAAK,MAAM,EACX,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,UAAU,CAAA;AACnG,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,UAAU,CAAA;AAEjB,MAAM,WAAW,iBAAkB,SAAQ,WAAW;IACpD,4EAA4E;IAC5E,KAAK,EAAE,KAAK,CAAA;IACZ;;;;OAIG;IACH,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,oFAAoF;IACpF,IAAI,EAAE,UAAU,CAAA;IAChB;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAKD,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAA;AAEnD,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,CAAC,EAAE;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGrI;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAiHvB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,YAAY,CAAC,CAAA"}
@@ -0,0 +1,141 @@
1
+ import { Rect, RotatedBox, Text, Types, component2d, insetsOps, textOps, } from "@motionscript/sdk";
2
+ import { asParts, fresh } from "./entries.js";
3
+ import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "./motion.js";
4
+ import { DEFAULT_Y_AXIS, enterBudget, formatMarker, } from "./shared.js";
5
+ /** How far a marker starts to the right of its slot when it enters, in px. */
6
+ const SLIDE = 24;
7
+ /** What a marker's caption reads: the one listed for its value, else its bare reading. */
8
+ export function markerCaption(s, value) {
9
+ const index = s.markers.indexOf(value);
10
+ return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value);
11
+ }
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
+ * `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 const VerticalAxis = component2d({
31
+ key: "verticalAxis",
32
+ state: {
33
+ range: fresh(() => [0, 1]),
34
+ markers: fresh(() => []),
35
+ captions: fresh(() => []),
36
+ axis: Types.custom(DEFAULT_Y_AXIS),
37
+ label: "",
38
+ arrivals: arrivalsEntry(),
39
+ },
40
+ // A plain node filled its parent; one made of its markers would hug them.
41
+ defaults: { width: "fill", height: "fill" },
42
+ children: (state) => {
43
+ // Composed from plain entries (range/markers/label), so it's built once here.
44
+ const tickPad = insetsOps.resolve(state.axis.tickPadding).right;
45
+ const titlePad = insetsOps.resolve(state.axis.titlePadding).right;
46
+ const row = [];
47
+ // The row's parent is the axis: its box is what the markers are placed in.
48
+ const box = () => row[0]?.parent?.layoutBounds ?? { width: 0, height: 0 };
49
+ /** The live tick values, top → bottom (highest first) — re-read every frame. */
50
+ const sorted = () => [...state.markers].sort((a, b) => b - a);
51
+ /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */
52
+ const fracAt = (value) => {
53
+ if (value === undefined)
54
+ return 0;
55
+ const [min, max] = state.range;
56
+ return max <= min ? 0 : (value - min) / (max - min);
57
+ };
58
+ // One text node per marker, ordered top → bottom. A slot with no value (the
59
+ // live list is shorter than the column built for it) renders as empty text
60
+ // rather than repeating its neighbour.
61
+ const markers = state.markers.map((_, i) => {
62
+ const marker = new Text({
63
+ ...textOps.styleProps(state.axis.labelStyle),
64
+ text: () => {
65
+ const value = sorted()[i];
66
+ return value === undefined ? "" : markerCaption(state, value);
67
+ },
68
+ y: () => {
69
+ // Node2D space is y-up, so the fraction runs from the bottom.
70
+ const height = box().height;
71
+ const centred = (fracAt(sorted()[i]) - 0.5) * height;
72
+ // Held inside the axis's top edge — the backstop for a chart whose
73
+ // headroom is smaller than its marker text is tall, which a theme with
74
+ // much larger markers can arrange. Only the top, because what lies
75
+ // below the axis is the chart's own horizontal axis and legend.
76
+ const limit = height / 2 - marker.layoutBounds.height / 2;
77
+ return Math.min(centred, limit);
78
+ },
79
+ opacity: () => arrivalOf(state.arrivals, i).opacity,
80
+ x: () => arrivalOf(state.arrivals, i).shift,
81
+ });
82
+ return marker;
83
+ });
84
+ const children = [];
85
+ if (state.label !== "") {
86
+ // Node2D space is y-up and rotation is clockwise, so -90° reads bottom-to-top.
87
+ children.push(new RotatedBox({
88
+ angle: -90,
89
+ width: "hug",
90
+ height: "hug",
91
+ children: new Text({
92
+ ...textOps.styleProps(state.axis.titleStyle),
93
+ text: state.label,
94
+ opacity: () => arrivalOf(state.arrivals, "label").opacity,
95
+ x: () => arrivalOf(state.arrivals, "label").shift,
96
+ }),
97
+ }));
98
+ }
99
+ children.push(new Rect({ height: "fill", width: "hug", padding: { right: tickPad }, children: markers }));
100
+ row.push(new Rect({ flow: "horizontal", gap: titlePad, children }));
101
+ return asParts(row);
102
+ },
103
+ commands: {
104
+ /**
105
+ * Stagger the markers in bottom to top, then slide the caption in from the
106
+ * right after them. Its first frame arms them all: shifted right by `slide`
107
+ * and transparent.
108
+ *
109
+ * The timeline's duration is the **whole** entrance, not one marker's slide:
110
+ * the stagger and the caption are carved out of it rather than added on top.
111
+ * See {@link enterBudget} for why that distinction matters here.
112
+ *
113
+ * `stagger` is seconds between successive markers (derived when omitted);
114
+ * `slide` is the starting rightward offset in px.
115
+ */
116
+ enter: {
117
+ args: {
118
+ stagger: Types.custom(undefined),
119
+ slide: Types.number(SLIDE),
120
+ },
121
+ run: (timeline, state) => {
122
+ const { stagger, slide } = timeline.args;
123
+ const count = state.markers.length;
124
+ const captioned = state.label !== "";
125
+ const from = { opacity: 0, shift: slide };
126
+ const keys = [...state.markers.keys(), ...(captioned ? ["label"] : [])];
127
+ const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }));
128
+ if (count === 0)
129
+ return arm;
130
+ const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger);
131
+ const ease = frameEase(timeline);
132
+ // Bottom marker leads: the column is top → bottom, so walk it in reverse.
133
+ const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }));
134
+ // Once every marker has landed, the caption slides in from the right.
135
+ const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, "label", from, ease) }] : [];
136
+ return timeline.together([arm, beats(timeline, [...markers, ...label])]);
137
+ },
138
+ },
139
+ },
140
+ });
141
+ //# 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,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,GAIR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAA;AACnG,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,GAGb,MAAM,UAAU,CAAA;AA2BjB,8EAA8E;AAC9E,MAAM,KAAK,GAAG,EAAE,CAAA;AAKhB,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,CAAgF,EAAE,KAAa;IAC3H,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACtC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,KAAK,CAAC,CAAA;AAC5E,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC;IACtC,GAAG,EAAE,cAAc;IACnB,KAAK,EAAE;QACL,KAAK,EAAE,KAAK,CAAQ,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACjC,OAAO,EAAE,KAAK,CAAW,GAAG,EAAE,CAAC,EAAE,CAAC;QAClC,QAAQ,EAAE,KAAK,CAAW,GAAG,EAAE,CAAC,EAAE,CAAC;QACnC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAa,c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KAAK,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;gBACnI,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC1E,CAAC;SACF;KACF;CACF,CAAC,CAAA","sourcesContent":["import {\n Rect,\n RotatedBox,\n Text,\n Types,\n component2d,\n insetsOps,\n textOps,\n type NodeOf,\n type Node2D,\n type Node2DProps,\n} from \"@motionscript/sdk\"\n\nimport { asParts, fresh } from \"./entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"./motion\"\nimport {\n DEFAULT_Y_AXIS,\n enterBudget,\n formatMarker,\n type AxisConfig,\n type Range,\n} from \"./shared\"\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 /**\n * How each marker is captioned, one per entry of `markers` and in its order.\n * Empty (the default), or short, captions a marker with its bare numeric\n * reading; a chart with a number format on this axis writes them through it.\n */\n captions: string[]\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 VerticalAxisProps.captions}. */\nexport type MarkerLabel = (value: number) => string\n\n/** What a marker's caption reads: the one listed for its value, else its bare reading. */\nexport function markerCaption(s: { readonly markers: readonly number[]; readonly captions: readonly string[] }, value: number): string {\n const index = s.markers.indexOf(value)\n return (index >= 0 ? s.captions[index] : undefined) ?? formatMarker(value)\n}\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 * `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 const VerticalAxis = component2d({\n key: \"verticalAxis\",\n state: {\n range: fresh<Range>(() => [0, 1]),\n markers: fresh<number[]>(() => []),\n captions: fresh<string[]>(() => []),\n axis: Types.custom<AxisConfig>(DEFAULT_Y_AXIS),\n label: \"\",\n arrivals: arrivalsEntry(),\n },\n // A plain node filled its parent; one made of its markers would hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n children: (state) => {\n // Composed from plain entries (range/markers/label), so it's built once here.\n const tickPad = insetsOps.resolve(state.axis.tickPadding).right\n const titlePad = insetsOps.resolve(state.axis.titlePadding).right\n\n const row: Node2D[] = []\n // The row's parent is the axis: its box is what the markers are placed in.\n const box = () => (row[0]?.parent as Node2D | null | undefined)?.layoutBounds ?? { width: 0, height: 0 }\n /** The live tick values, top → bottom (highest first) — re-read every frame. */\n const sorted = () => [...state.markers].sort((a, b) => b - a)\n /** Tick `i`'s fraction across the live `range`, 0 at the bottom edge. */\n const fracAt = (value: number | undefined) => {\n if (value === undefined) return 0\n const [min, max] = state.range\n return max <= min ? 0 : (value - min) / (max - min)\n }\n\n // One text node per marker, ordered top → bottom. A slot with no value (the\n // live list is shorter than the column built for it) renders as empty text\n // rather than repeating its neighbour.\n const markers = state.markers.map((_, i) => {\n const marker: Node2D = new Text({\n ...textOps.styleProps(state.axis.labelStyle),\n text: () => {\n const value = sorted()[i]\n return value === undefined ? \"\" : markerCaption(state, value)\n },\n y: () => {\n // Node2D space is y-up, so the fraction runs from the bottom.\n const height = box().height\n const centred = (fracAt(sorted()[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 opacity: () => arrivalOf(state.arrivals, i).opacity,\n x: () => arrivalOf(state.arrivals, i).shift,\n })\n return marker\n })\n\n const children: Node2D[] = []\n if (state.label !== \"\") {\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: new Text({\n ...textOps.styleProps(state.axis.titleStyle),\n text: state.label,\n opacity: () => arrivalOf(state.arrivals, \"label\").opacity,\n x: () => arrivalOf(state.arrivals, \"label\").shift,\n }),\n })\n )\n }\n children.push(new Rect({ height: \"fill\", width: \"hug\", padding: { right: tickPad }, children: markers }))\n row.push(new Rect({ flow: \"horizontal\", gap: titlePad, children }))\n return asParts(row)\n },\n commands: {\n /**\n * Stagger the markers in bottom to top, then slide the caption in from the\n * right after them. Its first frame arms them all: shifted right by `slide`\n * and transparent.\n *\n * The timeline's duration is the **whole** entrance, not one marker's slide:\n * the stagger and the caption are carved out of it rather than added on top.\n * See {@link enterBudget} for why that distinction matters here.\n *\n * `stagger` is seconds between successive markers (derived when omitted);\n * `slide` is the starting rightward offset in px.\n */\n enter: {\n args: {\n stagger: Types.custom<number | undefined>(undefined),\n slide: Types.number(SLIDE),\n },\n run: (timeline, state) => {\n const { stagger, slide } = timeline.args\n const count = state.markers.length\n const captioned = state.label !== \"\"\n const from: Arrival = { opacity: 0, shift: slide }\n const keys = [...state.markers.keys(), ...(captioned ? [\"label\"] : [])]\n const arm = timeline.animate(() => ({ arrivals: armed(keys, from) }))\n if (count === 0) return arm\n const { step, per, caption } = enterBudget(timeline.duration, count, captioned, stagger)\n const ease = frameEase(timeline)\n // Bottom marker leads: the column is top → bottom, so walk it in reverse.\n const markers = state.markers.map((_, i) => ({ at: (count - 1 - i) * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n // Once every marker has landed, the caption slides in from the right.\n const label = captioned ? [{ at: (count - 1) * step + per, duration: caption, piece: arrival(timeline, \"label\", from, ease) }] : []\n return timeline.together([arm, beats(timeline, [...markers, ...label])])\n },\n },\n },\n})\n\nexport type VerticalAxis = NodeOf<typeof VerticalAxis>\n"]}
@@ -0,0 +1,74 @@
1
+ import { type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved, type Vector2 } from "@motionscript/sdk";
2
+ import { type RegionBox } from "./shared.js";
3
+ /**
4
+ * A single series line of a {@link LineChart}: one rounded polyline traced
5
+ * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
6
+ * Sized and positioned by the parent, which shares the plot's coordinate frame.
7
+ *
8
+ * Two signals drive it: `progress` traces the line in
9
+ * (animated by `enter`) and `enabled` shows or hides it wholesale.
10
+ */
11
+ export declare const ChartLine: import("@motionscript/sdk").Component<"chartLine", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
12
+ /** 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. */
13
+ readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
14
+ /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
15
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
16
+ /**
17
+ * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
18
+ * end to its right. Defaults to 1, so the paused editor canvas paints the line;
19
+ * `enter` drives it from 0 regardless of where it rests.
20
+ */
21
+ readonly progress: 1;
22
+ /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */
23
+ readonly enabled: true;
24
+ /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */
25
+ readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
26
+ /** Opacity the out-of-region stretches fade to. */
27
+ readonly dimOpacity: 0.2;
28
+ }>, {
29
+ readonly enter: {
30
+ readonly from: import("@motionscript/sdk").Type<number, number, false>;
31
+ readonly to: import("@motionscript/sdk").Type<number, number, false>;
32
+ };
33
+ }, null, _Node2D<import("@motionscript/core").Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
34
+ /** 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. */
35
+ readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
36
+ /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
37
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
38
+ /**
39
+ * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
40
+ * end to its right. Defaults to 1, so the paused editor canvas paints the line;
41
+ * `enter` drives it from 0 regardless of where it rests.
42
+ */
43
+ readonly progress: 1;
44
+ /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */
45
+ readonly enabled: true;
46
+ /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */
47
+ readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
48
+ /** Opacity the out-of-region stretches fade to. */
49
+ readonly dimOpacity: 0.2;
50
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
51
+ /** 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. */
52
+ readonly points: import("@motionscript/sdk").Type<Vector2[], Vector2[], false>;
53
+ /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */
54
+ readonly stroke: import("@motionscript/sdk").Type<Stroke, StrokeResolved[], false>;
55
+ /**
56
+ * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left
57
+ * end to its right. Defaults to 1, so the paused editor canvas paints the line;
58
+ * `enter` drives it from 0 regardless of where it rests.
59
+ */
60
+ readonly progress: 1;
61
+ /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */
62
+ readonly enabled: true;
63
+ /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */
64
+ readonly spotlight: import("@motionscript/sdk").Type<RegionBox, RegionBox, false>;
65
+ /** Opacity the out-of-region stretches fade to. */
66
+ readonly dimOpacity: 0.2;
67
+ }>, {
68
+ readonly enter: {
69
+ readonly from: import("@motionscript/sdk").Type<number, number, false>;
70
+ readonly to: import("@motionscript/sdk").Type<number, number, false>;
71
+ };
72
+ }, _Node2D<import("@motionscript/core").Node2DProps>>>>;
73
+ export type ChartLine = NodeOf<typeof ChartLine>;
74
+ //# 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,EAKL,KAAK,MAAM,EAEX,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,MAAM,EACX,KAAK,cAAc,EACnB,KAAK,OAAO,EACb,MAAM,mBAAmB,CAAA;AAM1B,OAAO,EAIL,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAuCjB;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;IAGlB,wJAAwJ;;IAExJ,+EAA+E;;IAE/E;;;;OAIG;;IAEH,8GAA8G;;IAE9G,mHAAmH;;IAEnH,mDAAmD;;;;;;;;IAdnD,wJAAwJ;;IAExJ,+EAA+E;;IAE/E;;;;OAIG;;IAEH,8GAA8G;;IAE9G,mHAAmH;;IAEnH,mDAAmD;;;IAdnD,wJAAwJ;;IAExJ,+EAA+E;;IAE/E;;;;OAIG;;IAEH,8GAA8G;;IAE9G,mHAAmH;;IAEnH,mDAAmD;;;;;;;uDAmErD,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
@@ -0,0 +1,135 @@
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";
5
+ import { SPOTLIGHT_DIM } from "../kit/shared.js";
6
+ import { EMPTY_REGION_BOX, clipPolylineToBox, hasRegion, } from "./shared.js";
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
+ }
45
+ /**
46
+ * A single series line of a {@link LineChart}: one rounded polyline traced
47
+ * through pre-mapped pixel `points`, drawn as one {@link Graphics2D} command list.
48
+ * Sized and positioned by the parent, which shares the plot's coordinate frame.
49
+ *
50
+ * Two signals drive it: `progress` traces the line in
51
+ * (animated by `enter`) and `enabled` shows or hides it wholesale.
52
+ */
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)
101
+ return;
102
+ const pts = state.points;
103
+ if (pts.length < 2)
104
+ return;
105
+ const p = Math.max(0, Math.min(1, state.progress));
106
+ if (p <= 0)
107
+ return;
108
+ const drawn = tracePoints(pts, p);
109
+ if (drawn.length < 2)
110
+ return;
111
+ const stroke = state.stroke;
112
+ const radius = (stroke[0]?.weight ?? 0) * 2; // round the joins
113
+ const box = state.spotlight;
114
+ if (!hasRegion(box)) {
115
+ ctx.draw(new Graphics2D().line({ points: drawn, radius }).stroke(stroke));
116
+ return;
117
+ }
118
+ // Spotlit: the whole line goes down to `dimOpacity`, then the stretches
119
+ // inside the region are re-drawn over it at full strength. Two passes rather
120
+ // than one dim + one bright *complementary* pair, so the bright run has
121
+ // continuous geometry through the region and its joins round the way an
122
+ // unspotlit line's do — and so the boundary lands exactly on the region edge.
123
+ ctx.draw(new Graphics2D()
124
+ .line({ points: drawn, radius })
125
+ .stroke(stroke)
126
+ .opacity(Math.max(0, Math.min(1, state.dimOpacity))));
127
+ // One `draw` per run: shapes chained before a `stroke()` are combined into a
128
+ // single surface, and stroking a union of disjoint open paths doesn't paint
129
+ // — so a line that leaves the region and comes back would lose both halves.
130
+ for (const run of clipPolylineToBox(drawn, box)) {
131
+ ctx.draw(new Graphics2D().line({ points: run, radius }).stroke(stroke));
132
+ }
133
+ },
134
+ });
135
+ //# 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,EACL,UAAU,EACV,KA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;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 {\n Graphics2D,\n Types,\n component2d,\n strokeOps,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\n type Node2D as _Node2D,\n type Stroke,\n type StrokeResolved,\n type Vector2,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"../kit/entries\"\nimport { frameEase } from \"../kit/motion\"\nimport { loadPaints } from \"../kit/paints\"\nimport { SPOTLIGHT_DIM } from \"../kit/shared\"\nimport {\n EMPTY_REGION_BOX,\n clipPolylineToBox,\n hasRegion,\n type RegionBox,\n} from \"./shared\"\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 */\nfunction 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 * 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: `progress` traces the line in\n * (animated by `enter`) and `enabled` shows or hides it wholesale.\n */\nexport const ChartLine = component2d({\n key: \"chartLine\",\n state: {\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. */\n points: fresh<Vector2[]>(() => []),\n /** Line colour + weight (+ optional dash/cap/join) — the per-series stroke. */\n stroke: Types.custom<Stroke, StrokeResolved[]>([], { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n /**\n * Reveal of the line in `[0, 1]`: 0 hides it, 1 traces it fully from its left\n * end to its right. Defaults to 1, so the paused editor canvas paints the line;\n * `enter` drives it from 0 regardless of where it rests.\n */\n progress: 1,\n /** Whether this line is drawn at all: the switch the chart flips alongside its legend's per-series toggle. */\n enabled: true,\n /** A slice of the plot to spotlight, in this node's own pixel space: outside it the line drops to `dimOpacity`. */\n spotlight: fresh<RegionBox>(() => EMPTY_REGION_BOX),\n /** Opacity the out-of-region stretches fade to. */\n dimOpacity: SPOTLIGHT_DIM,\n },\n load: (loader, state) => loadPaints(loader, { strokes: [state.stroke] }),\n commands: {\n /**\n * Trace the line from `from` to `to` over the command — by default in from\n * its left end to its right. `showSeries` and `hideSeries` are the same\n * motion in opposite directions, so both are this with their ends stated.\n *\n * `enabled` rides along in the same value rather than being set before or\n * after the command: a line is drawable for every `t` the trace covers and\n * undrawn outside it, which is what makes arriving at a time backwards show\n * what arriving forwards does.\n */\n enter: {\n args: { from: Types.number(0, { min: 0, max: 1 }), to: Types.number(1, { min: 0, max: 1 }) },\n run: (timeline) => {\n const { from, to } = timeline.args\n const ease = frameEase(timeline)\n return timeline.animate((t) => {\n const progress = from + (to - from) * ease(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 },\n },\n },\n render: (ctx, state) => {\n if (!state.enabled) return\n const pts = state.points\n if (pts.length < 2) return\n\n const p = Math.max(0, Math.min(1, state.progress))\n if (p <= 0) return\n\n const drawn = tracePoints(pts, p)\n if (drawn.length < 2) return\n const stroke = state.stroke\n const radius = (stroke[0]?.weight ?? 0) * 2 // round the joins\n\n const box = state.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, state.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\nexport type ChartLine = NodeOf<typeof ChartLine>\n"]}
@@ -0,0 +1,46 @@
1
+ import { type Fill, type FillResolved, type NodeOf, type Node2D as _Node2D, type Stroke, type StrokeResolved } from "@motionscript/sdk";
2
+ import { type RegionBox } from "./shared.js";
3
+ /**
4
+ * The **region call-out** of a {@link LineChart}: a washed rectangle over the
5
+ * plot with a dashed rule down each edge the author actually bounded. Sized and
6
+ * positioned entirely from the pre-mapped `box` rather
7
+ * than its own box — the region already carries the plot geometry.
8
+ *
9
+ * It draws only the *marking*; fading the series outside the region is
10
+ * {@link ChartLine}'s job (it clips its own polyline against the same box), so
11
+ * the two can't disagree about where the boundary is.
12
+ *
13
+ * Only bounded edges get a rule: a region given just an `x` range spans the full
14
+ * plot height, so its top and bottom edges are the plot's own border, not a data
15
+ * bound — drawing dashes there would assert a limit the author didn't set.
16
+ */
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>;
46
+ //# 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,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"}
@@ -0,0 +1,67 @@
1
+ import { Graphics2D, Types, component2d, fillOps, strokeOps, } from "@motionscript/sdk";
2
+ import { fresh } from "../kit/entries.js";
3
+ import { loadPaints } from "../kit/paints.js";
4
+ import { DEFAULT_CHART_THEME, EMPTY_REGION_BOX, hasRegion, } from "./shared.js";
5
+ /**
6
+ * The **region call-out** of a {@link LineChart}: a washed rectangle over the
7
+ * plot with a dashed rule down each edge the author actually bounded. Sized and
8
+ * positioned entirely from the pre-mapped `box` rather
9
+ * than its own box — the region already carries the plot geometry.
10
+ *
11
+ * It draws only the *marking*; fading the series outside the region is
12
+ * {@link ChartLine}'s job (it clips its own polyline against the same box), so
13
+ * the two can't disagree about where the boundary is.
14
+ *
15
+ * Only bounded edges get a rule: a region given just an `x` range spans the full
16
+ * plot height, so its top and bottom edges are the plot's own border, not a data
17
+ * bound — drawing dashes there would assert a limit the author didn't set.
18
+ */
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;
34
+ if (!hasRegion(box))
35
+ return;
36
+ const r = Math.max(0, Math.min(1, state.reveal));
37
+ if (r <= 0)
38
+ return;
39
+ const width = box.right - box.left;
40
+ const height = box.top - box.bottom;
41
+ const cx = (box.left + box.right) / 2;
42
+ const cy = (box.bottom + box.top) / 2;
43
+ // Wash first, so the rules sit over their own tint.
44
+ if (state.fill.length > 0) {
45
+ ctx.draw(new Graphics2D().rect({ x: cx, y: cy, width, height }).fill(state.fill).opacity(r));
46
+ }
47
+ // One rule per bounded edge, growing from the region's centre outward as
48
+ // `reveal` climbs — the same "trace it in" beat as the series lines.
49
+ if (state.stroke.length === 0)
50
+ return;
51
+ // One `draw` per rule rather than four line ops under a single paint:
52
+ // shapes chained before a `stroke()` are combined into one surface, and
53
+ // stroking a union of disjoint open paths doesn't paint.
54
+ const rule = (points) => ctx.draw(new Graphics2D().line({ points }).stroke(state.stroke).opacity(r));
55
+ if (box.xBounded) {
56
+ const half = (height / 2) * r;
57
+ for (const x of [box.left, box.right])
58
+ rule([{ x, y: cy - half }, { x, y: cy + half }]);
59
+ }
60
+ if (box.yBounded) {
61
+ const half = (width / 2) * r;
62
+ for (const y of [box.bottom, box.top])
63
+ rule([{ x: cx - half, y }, { x: cx + half, y }]);
64
+ }
65
+ },
66
+ });
67
+ //# sourceMappingURL=chart-region.js.map