@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,222 @@
1
+ import { Rect, Types, component2d, easeOut, } from "@motionscript/sdk";
2
+ import { asParts, fresh } from "../kit/entries.js";
3
+ import { beats } from "../kit/motion.js";
4
+ import { clampUnit } from "../kit/shared.js";
5
+ import { PieLegend } from "./pie-legend.js";
6
+ import { PieRing } from "./pie-ring.js";
7
+ import { DEFAULT_PIE_CHART_THEME, lerpPieChartTheme, resolvePieChartTheme, resolvePieSlices, } from "./shared.js";
8
+ /**
9
+ * How `enter` divides its duration: the wedges sweeping in, then the labels and
10
+ * the legend arriving together. Shares of the whole, so they sum to 1.
11
+ */
12
+ const SWEEP_SHARE = 0.65;
13
+ const LABEL_SHARE = 0.35;
14
+ const SLICE_ARG = Types.number(0, { min: 0, step: 1 });
15
+ /** The slices the ring and the legend draw, resolved from the rows and the palette. */
16
+ function slicesOf(s) {
17
+ return resolvePieSlices(s.data, s.categoryField, s.valueField, s.theme.sliceFills);
18
+ }
19
+ /** How far slice `index` is pushed out, in `[0, 1]`. */
20
+ function popAt(s, index) {
21
+ return clampUnit(s.pops[index] ?? 0);
22
+ }
23
+ /** Whether slice `index` is grown out past the ring's rim: past half way, so a slice mid-swell is not yet counted. */
24
+ export function isSliceSelected(s, index) {
25
+ return popAt(s, index) > 0.5;
26
+ }
27
+ /**
28
+ * How far each slice is dimmed by the selection, one entry per slice: 1 while
29
+ * nothing is out, and for the selected slice itself; falling toward the theme's
30
+ * `dimOpacity` for the rest in proportion to how far the selection has grown.
31
+ */
32
+ function sliceDims(s) {
33
+ let focus = 0;
34
+ for (let i = 0; i < s.data.length; i++)
35
+ focus = Math.max(focus, popAt(s, i));
36
+ const dim = s.theme.spotlight.dimOpacity;
37
+ if (focus <= 0)
38
+ return s.data.map(() => 1);
39
+ return s.data.map((_, i) => 1 - (1 - clampUnit(dim)) * focus * (1 - popAt(s, i)));
40
+ }
41
+ /**
42
+ * Every slice's pop eased from where it is to what `pop` asks for. A move that
43
+ * changes nothing still takes its slot, writing nothing.
44
+ */
45
+ function popping(timeline, s, pop) {
46
+ const from = s.data.map((_, i) => popAt(s, i));
47
+ const targets = s.data.map((_, i) => clampUnit(pop(i)));
48
+ if (from.every((value, i) => value === targets[i]))
49
+ return timeline.wait(timeline.duration);
50
+ return timeline.animate((t) => ({ pops: from.map((value, i) => value + (targets[i] - value) * t) }));
51
+ }
52
+ /** The ring and the legend, found through the chart's children: the last row of them is the one it built. */
53
+ function partsOf(children) {
54
+ for (let i = children.length - 1; i >= 0; i--) {
55
+ const row = children[i];
56
+ const ring = Rect.is(row) ? row.children.find(PieRing.is) : undefined;
57
+ if (ring)
58
+ return { ring, legend: row.children.find(PieLegend.is) ?? null };
59
+ }
60
+ return null;
61
+ }
62
+ /**
63
+ * A pie or donut chart, composed from two parts laid out by a horizontal-flow
64
+ * {@link Rect} — the ring filling whatever the hugging legend leaves, both
65
+ * centred:
66
+ *
67
+ * - {@link PieRing} — the wedges, each sized by its share of the total, with its
68
+ * label inside its own band or pinned outside on a leader line, and the
69
+ * summary in the hole.
70
+ * - {@link PieLegend} — a column of swatch-and-caption rows naming each slice.
71
+ *
72
+ * **One mark per row, not per column**: a pie's palette is indexed by row and
73
+ * there is nothing to hide, since dropping a slice would re-cut every other
74
+ * wedge. `selectSlice` and its siblings are what a pie has instead — a slice
75
+ * swells out of the ring and everything else dims behind it.
76
+ *
77
+ * **Resting state is the finished chart**; `enter` arms every part on its first
78
+ * frame. The one exception is the hole's summary, which a scene can hold back
79
+ * with `showCenter: false`, because it is usually the chart's *conclusion*.
80
+ */
81
+ export const PieChart = component2d({
82
+ key: "pieChart",
83
+ state: {
84
+ data: fresh(() => []),
85
+ categoryField: "",
86
+ valueField: "",
87
+ theme: Types.custom(DEFAULT_PIE_CHART_THEME, { resolve: resolvePieChartTheme, lerp: lerpPieChartTheme }),
88
+ labelMode: Types.custom("percent"),
89
+ labelPlacement: Types.custom("leader"),
90
+ gap: 40,
91
+ centerLabel: "",
92
+ centerCaption: "",
93
+ /**
94
+ * How far each slice is pushed out of the ring, `0`–`1` per index. Held here
95
+ * rather than on the ring because two parts read it: the wedges grow out by
96
+ * it, and the legend entries dim by it. Seeded flush, one to a row.
97
+ */
98
+ pops: fresh(() => []),
99
+ /** Read as the chart is built: the legend is a part the chart builds or doesn't. */
100
+ showLegend: Types.boolean(true, { animatable: false }),
101
+ /** Read as the chart is built: whether the hole's summary is drawn at rest. */
102
+ showCenter: Types.boolean(true, { animatable: false }),
103
+ },
104
+ defaults: {
105
+ // Its parts fill it; a node made of them would hug them.
106
+ width: "fill",
107
+ height: "fill",
108
+ pops: (state) => slicesOf(state).map(() => 0),
109
+ },
110
+ allowedChildren: [],
111
+ // The slice *structure* (one label and one legend row per row) is read once;
112
+ // the slices themselves, their paint and the selection are bound, so a theme
113
+ // tween re-paints and a `set` of `data` re-cuts the wedges.
114
+ children: (state) => {
115
+ const theme = () => state.theme;
116
+ const slices = () => slicesOf(state);
117
+ const parts = [
118
+ new PieRing({
119
+ width: "fill",
120
+ height: "fill",
121
+ slices,
122
+ ring: () => theme().ring,
123
+ label: () => theme().label,
124
+ centerStyle: () => theme().center,
125
+ labelMode: state.labelMode,
126
+ labelPlacement: state.labelPlacement,
127
+ pops: () => state.pops,
128
+ dimOpacity: () => theme().spotlight.dimOpacity,
129
+ centerLabel: state.centerLabel,
130
+ centerCaption: state.centerCaption,
131
+ centerReveal: state.showCenter === false ? 0 : 1,
132
+ }),
133
+ ];
134
+ if (state.showLegend !== false) {
135
+ parts.push(new PieLegend({
136
+ slices,
137
+ legend: () => theme().legend,
138
+ dims: () => sliceDims(state),
139
+ // The column's spacing is the theme's as the chart was built, like the
140
+ // entries' type and chips.
141
+ gap: state.theme.legend.itemGap / 3,
142
+ padding: state.theme.legend.padding,
143
+ }));
144
+ }
145
+ const row = new Rect({ flow: "horizontal", width: "fill", height: "fill", gap: state.gap, align: "center", children: parts });
146
+ return asParts([row]);
147
+ },
148
+ commands: {
149
+ /**
150
+ * Animate the whole chart in: the wedges sweep in clockwise from the theme's
151
+ * `startAngle`, then the labels fade up and the legend staggers in together.
152
+ * Its first frame arms the wedges, the labels and the legend; the hole's
153
+ * summary keeps its own signal. `duration` is the **whole** entrance.
154
+ */
155
+ enter: {
156
+ args: {},
157
+ // Held from the chart's arrival, so it never shows finished ahead of its draw.
158
+ entrance: true,
159
+ easing: easeOut(),
160
+ run: (timeline, _state, children) => {
161
+ const parts = partsOf(children);
162
+ if (!parts)
163
+ return timeline.wait(timeline.duration);
164
+ const { ring, legend } = parts;
165
+ const sweep = timeline.duration * SWEEP_SHARE;
166
+ const labels = timeline.duration * LABEL_SHARE;
167
+ const at0 = (piece) => ({ at: 0, duration: 0, piece });
168
+ return beats(timeline, [
169
+ at0(ring.to({ growth: 0, labelReveal: 0 })),
170
+ ...(legend ? [at0(legend.run("arm"))] : []),
171
+ { at: 0, duration: sweep, piece: ring.run("sweep") },
172
+ { at: sweep, duration: labels, piece: ring.run("revealLabels") },
173
+ ...(legend ? [{ at: sweep, duration: labels, piece: legend.run("enter") }] : []),
174
+ ]);
175
+ },
176
+ },
177
+ /**
178
+ * Fade the hole's summary up. Held out of `enter` on purpose: what sits in a
179
+ * donut's hole is usually the chart's conclusion, so the scene lands it on
180
+ * its own beat. Pair it with `showCenter: false`.
181
+ */
182
+ revealCenter: {
183
+ args: {},
184
+ easing: easeOut(),
185
+ run: (timeline, _state, children) => partsOf(children)?.ring.run("revealCenter") ?? timeline.wait(timeline.duration),
186
+ },
187
+ /** Grow slice `index` out past the ring's rim and dim the rest, leaving any other selected slice where it is. */
188
+ selectSlice: {
189
+ args: { sliceIndex: SLICE_ARG },
190
+ easing: easeOut(),
191
+ run: (timeline, state) => {
192
+ const index = timeline.args.sliceIndex;
193
+ return popping(timeline, state, (i) => (i === index ? 1 : popAt(state, i)));
194
+ },
195
+ },
196
+ /** Settle slice `index` back flush with the ring. */
197
+ deselectSlice: {
198
+ args: { sliceIndex: SLICE_ARG },
199
+ easing: easeOut(),
200
+ run: (timeline, state) => {
201
+ const index = timeline.args.sliceIndex;
202
+ return popping(timeline, state, (i) => (i === index ? 0 : popAt(state, i)));
203
+ },
204
+ },
205
+ /** Move the focus to slice `index` alone, settling whatever else was out. */
206
+ selectOnlySlice: {
207
+ args: { sliceIndex: SLICE_ARG },
208
+ easing: easeOut(),
209
+ run: (timeline, state) => {
210
+ const index = timeline.args.sliceIndex;
211
+ return popping(timeline, state, (i) => (i === index ? 1 : 0));
212
+ },
213
+ },
214
+ /** Settle every slice flush and bring the whole chart back to full. */
215
+ clearSelection: {
216
+ args: {},
217
+ easing: easeOut(),
218
+ run: (timeline, state) => popping(timeline, state, () => 0),
219
+ },
220
+ },
221
+ });
222
+ //# sourceMappingURL=pie-chart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-chart.js","sourceRoot":"","sources":["../../src/pie-chart/pie-chart.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,WAAW,EACX,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAa,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GAMjB,MAAM,UAAU,CAAA;AA4CjB;;;GAGG;AACH,MAAM,WAAW,GAAG,IAAI,CAAA;AACxB,MAAM,WAAW,GAAG,IAAI,CAAA;AAExB,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;AAEtD,uFAAuF;AACvF,SAAS,QAAQ,CAAC,CAAiB;I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types,\n component2d,\n easeOut,\n type ChildView,\n type DataRecord,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` through the sdk, not core.\n type Node2D,\n type Node2DProps,\n type Timeline,\n} from \"@motionscript/sdk\"\n\nimport { asParts, fresh } from \"../kit/entries\"\nimport { beats, type Beat } from \"../kit/motion\"\nimport { clampUnit } from \"../kit/shared\"\nimport { PieLegend } from \"./pie-legend\"\nimport { PieRing } from \"./pie-ring\"\nimport {\n DEFAULT_PIE_CHART_THEME,\n lerpPieChartTheme,\n resolvePieChartTheme,\n resolvePieSlices,\n type PieChartConfig,\n type PieChartTheme,\n type PieLabelMode,\n type PieLabelPlacement,\n type PieSlice,\n} from \"./shared\"\n\nexport interface PieChartProps extends Node2DProps {\n /** One row per slice — a plain record of field name to value. */\n data: DataRecord[]\n /** Key into each row for its slice caption, used on the labels and the legend. */\n categoryField: string\n /** Key into each row for its slice magnitude — the wedge's share of the ring. */\n valueField: string\n /**\n * The chart's visual theme — slice palette, ring geometry, label and centre\n * type, legend. Every branch is optional and deep-merged onto\n * {@link DEFAULT_PIE_CHART_THEME}.\n */\n theme?: PieChartTheme\n /** What the ring's labels say. */\n labelMode?: PieLabelMode\n /** Where they sit: inside their wedge, outside on a leader, or nowhere. */\n labelPlacement?: PieLabelPlacement\n /** Whether the legend column beside the ring is drawn at all. */\n showLegend?: boolean\n /** Gap between the ring and the legend, in px. */\n gap?: number\n /** Text set in the ring's hole — see `revealCenter`. */\n centerLabel?: string\n /** Smaller second line under {@link centerLabel}. */\n centerCaption?: string\n /**\n * Whether the hole's summary is drawn at rest. `true` (the default) is the\n * plain answer; a scene that wants the conclusion to land on a later beat sets\n * this `false` and runs `revealCenter` when it gets there.\n */\n showCenter?: boolean\n}\n\n/** What the selection reads: the rows, how they are cut, and the pops the commands move. */\nexport interface PieChartValues {\n readonly data: DataRecord[]\n readonly categoryField: string\n readonly valueField: string\n readonly theme: PieChartConfig\n readonly pops: number[]\n}\n\n/**\n * How `enter` divides its duration: the wedges sweeping in, then the labels and\n * the legend arriving together. Shares of the whole, so they sum to 1.\n */\nconst SWEEP_SHARE = 0.65\nconst LABEL_SHARE = 0.35\n\nconst SLICE_ARG = Types.number(0, { min: 0, step: 1 })\n\n/** The slices the ring and the legend draw, resolved from the rows and the palette. */\nfunction slicesOf(s: PieChartValues): PieSlice[] {\n return resolvePieSlices(s.data, s.categoryField, s.valueField, s.theme.sliceFills)\n}\n\n/** How far slice `index` is pushed out, in `[0, 1]`. */\nfunction popAt(s: PieChartValues, index: number): number {\n return clampUnit(s.pops[index] ?? 0)\n}\n\n/** Whether slice `index` is grown out past the ring's rim: past half way, so a slice mid-swell is not yet counted. */\nexport function isSliceSelected(s: PieChartValues, index: number): boolean {\n return popAt(s, index) > 0.5\n}\n\n/**\n * How far each slice is dimmed by the selection, one entry per slice: 1 while\n * nothing is out, and for the selected slice itself; falling toward the theme's\n * `dimOpacity` for the rest in proportion to how far the selection has grown.\n */\nfunction sliceDims(s: PieChartValues): number[] {\n let focus = 0\n for (let i = 0; i < s.data.length; i++) focus = Math.max(focus, popAt(s, i))\n const dim = s.theme.spotlight.dimOpacity\n if (focus <= 0) return s.data.map(() => 1)\n return s.data.map((_, i) => 1 - (1 - clampUnit(dim)) * focus * (1 - popAt(s, i)))\n}\n\ntype AnyTimeline = Timeline<any, any>\n\n/**\n * Every slice's pop eased from where it is to what `pop` asks for. A move that\n * changes nothing still takes its slot, writing nothing.\n */\nfunction popping(timeline: AnyTimeline, s: PieChartValues, pop: (index: number) => number) {\n const from = s.data.map((_, i) => popAt(s, i))\n const targets = s.data.map((_, i) => clampUnit(pop(i)))\n if (from.every((value, i) => value === targets[i])) return timeline.wait(timeline.duration)\n return timeline.animate((t) => ({ pops: from.map((value, i) => value + (targets[i] - value) * t) }))\n}\n\n/** The ring and the legend, found through the chart's children: the last row of them is the one it built. */\nfunction partsOf(children: readonly ChildView[]) {\n for (let i = children.length - 1; i >= 0; i--) {\n const row = children[i]\n const ring = Rect.is(row) ? row.children.find(PieRing.is) : undefined\n if (ring) return { ring, legend: row.children.find(PieLegend.is) ?? null }\n }\n return null\n}\n\n/**\n * A pie or donut chart, composed from two parts laid out by a horizontal-flow\n * {@link Rect} — the ring filling whatever the hugging legend leaves, both\n * centred:\n *\n * - {@link PieRing} — the wedges, each sized by its share of the total, with its\n * label inside its own band or pinned outside on a leader line, and the\n * summary in the hole.\n * - {@link PieLegend} — a column of swatch-and-caption rows naming each slice.\n *\n * **One mark per row, not per column**: a pie's palette is indexed by row and\n * there is nothing to hide, since dropping a slice would re-cut every other\n * wedge. `selectSlice` and its siblings are what a pie has instead — a slice\n * swells out of the ring and everything else dims behind it.\n *\n * **Resting state is the finished chart**; `enter` arms every part on its first\n * frame. The one exception is the hole's summary, which a scene can hold back\n * with `showCenter: false`, because it is usually the chart's *conclusion*.\n */\nexport const PieChart = component2d({\n key: \"pieChart\",\n state: {\n data: fresh<DataRecord[]>(() => []),\n categoryField: \"\",\n valueField: \"\",\n theme: Types.custom<PieChartTheme, PieChartConfig>(DEFAULT_PIE_CHART_THEME, { resolve: resolvePieChartTheme, lerp: lerpPieChartTheme }),\n labelMode: Types.custom<PieLabelMode>(\"percent\"),\n labelPlacement: Types.custom<PieLabelPlacement>(\"leader\"),\n gap: 40,\n centerLabel: \"\",\n centerCaption: \"\",\n /**\n * How far each slice is pushed out of the ring, `0`–`1` per index. Held here\n * rather than on the ring because two parts read it: the wedges grow out by\n * it, and the legend entries dim by it. Seeded flush, one to a row.\n */\n pops: fresh<number[]>(() => []),\n /** Read as the chart is built: the legend is a part the chart builds or doesn't. */\n showLegend: Types.boolean(true, { animatable: false }),\n /** Read as the chart is built: whether the hole's summary is drawn at rest. */\n showCenter: Types.boolean(true, { animatable: false }),\n },\n defaults: {\n // Its parts fill it; a node made of them would hug them.\n width: \"fill\",\n height: \"fill\",\n pops: (state) => slicesOf(state).map(() => 0),\n },\n allowedChildren: [],\n // The slice *structure* (one label and one legend row per row) is read once;\n // the slices themselves, their paint and the selection are bound, so a theme\n // tween re-paints and a `set` of `data` re-cuts the wedges.\n children: (state) => {\n const theme = () => state.theme\n const slices = () => slicesOf(state)\n const parts: Node2D[] = [\n new PieRing({\n width: \"fill\",\n height: \"fill\",\n slices,\n ring: () => theme().ring,\n label: () => theme().label,\n centerStyle: () => theme().center,\n labelMode: state.labelMode,\n labelPlacement: state.labelPlacement,\n pops: () => state.pops,\n dimOpacity: () => theme().spotlight.dimOpacity,\n centerLabel: state.centerLabel,\n centerCaption: state.centerCaption,\n centerReveal: state.showCenter === false ? 0 : 1,\n }) as unknown as Node2D,\n ]\n if (state.showLegend !== false) {\n parts.push(\n new PieLegend({\n slices,\n legend: () => theme().legend,\n dims: () => sliceDims(state),\n // The column's spacing is the theme's as the chart was built, like the\n // entries' type and chips.\n gap: state.theme.legend.itemGap / 3,\n padding: state.theme.legend.padding,\n }) as unknown as Node2D\n )\n }\n const row = new Rect({ flow: \"horizontal\", width: \"fill\", height: \"fill\", gap: state.gap, align: \"center\", children: parts })\n return asParts([row as unknown as Node2D])\n },\n commands: {\n /**\n * Animate the whole chart in: the wedges sweep in clockwise from the theme's\n * `startAngle`, then the labels fade up and the legend staggers in together.\n * Its first frame arms the wedges, the labels and the legend; the hole's\n * summary keeps its own signal. `duration` is the **whole** entrance.\n */\n enter: {\n args: {},\n // Held from the chart's arrival, so it never shows finished ahead of its draw.\n entrance: true,\n easing: easeOut(),\n run: (timeline, _state, children) => {\n const parts = partsOf(children)\n if (!parts) return timeline.wait(timeline.duration)\n const { ring, legend } = parts\n const sweep = timeline.duration * SWEEP_SHARE\n const labels = timeline.duration * LABEL_SHARE\n const at0 = (piece: Beat[\"piece\"]): Beat => ({ at: 0, duration: 0, piece })\n return beats(timeline, [\n at0(ring.to({ growth: 0, labelReveal: 0 })),\n ...(legend ? [at0(legend.run(\"arm\"))] : []),\n { at: 0, duration: sweep, piece: ring.run(\"sweep\") },\n { at: sweep, duration: labels, piece: ring.run(\"revealLabels\") },\n ...(legend ? [{ at: sweep, duration: labels, piece: legend.run(\"enter\") }] : []),\n ])\n },\n },\n /**\n * Fade the hole's summary up. Held out of `enter` on purpose: what sits in a\n * donut's hole is usually the chart's conclusion, so the scene lands it on\n * its own beat. Pair it with `showCenter: false`.\n */\n revealCenter: {\n args: {},\n easing: easeOut(),\n run: (timeline, _state, children) => partsOf(children)?.ring.run(\"revealCenter\") ?? timeline.wait(timeline.duration),\n },\n /** Grow slice `index` out past the ring's rim and dim the rest, leaving any other selected slice where it is. */\n selectSlice: {\n args: { sliceIndex: SLICE_ARG },\n easing: easeOut(),\n run: (timeline, state) => {\n const index = timeline.args.sliceIndex\n return popping(timeline, state, (i) => (i === index ? 1 : popAt(state, i)))\n },\n },\n /** Settle slice `index` back flush with the ring. */\n deselectSlice: {\n args: { sliceIndex: SLICE_ARG },\n easing: easeOut(),\n run: (timeline, state) => {\n const index = timeline.args.sliceIndex\n return popping(timeline, state, (i) => (i === index ? 0 : popAt(state, i)))\n },\n },\n /** Move the focus to slice `index` alone, settling whatever else was out. */\n selectOnlySlice: {\n args: { sliceIndex: SLICE_ARG },\n easing: easeOut(),\n run: (timeline, state) => {\n const index = timeline.args.sliceIndex\n return popping(timeline, state, (i) => (i === index ? 1 : 0))\n },\n },\n /** Settle every slice flush and bring the whole chart back to full. */\n clearSelection: {\n args: {},\n easing: easeOut(),\n run: (timeline, state) => popping(timeline, state, () => 0),\n },\n },\n})\n\nexport type PieChart = NodeOf<typeof PieChart>\n"]}
@@ -0,0 +1,113 @@
1
+ import { type NodeOf, type RectProps, type Alignment as _Alignment, type CornerRadiusResolved as _CornerRadiusResolved, type CornerStyleResolved as _CornerStyleResolved, type Fill as _Fill, type FillResolved as _FillResolved, type FlowMode as _FlowMode, type FlowResolved as _FlowResolved, type GapSize as _GapSize, type Node2D as _Node2D, type Node2DProps as _Node2DProps, type RectCornerRadius as _RectCornerRadius, type RectCornerStyle as _RectCornerStyle, type Shadow as _Shadow, type ShadowResolved as _ShadowResolved, type Stroke as _Stroke, type StrokeResolved as _StrokeResolved, type Vector2 as _Vector2 } from "@motionscript/sdk";
2
+ import { type Arrival } from "../kit/motion.js";
3
+ import { type LegendConfig } from "../kit/shared.js";
4
+ import type { PieSlice } from "./shared.js";
5
+ export interface PieLegendProps extends RectProps {
6
+ /** One entry per slice, in ring order. */
7
+ slices: PieSlice[];
8
+ /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */
9
+ legend: LegendConfig;
10
+ /**
11
+ * Per-slice opacity multiplier, by index — the same signal that dims the ring,
12
+ * so an entry fades in step with the wedge it names. Missing entries read as 1.
13
+ */
14
+ dims: number[];
15
+ }
16
+ /**
17
+ * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per
18
+ * slice, each pairing the slice's caption with its colour swatch.
19
+ *
20
+ * A column rather than the cartesian charts' row, because it sits *beside* the
21
+ * ring rather than beneath the plot — a pie is as tall as it is wide, so the
22
+ * space it leaves over is a vertical strip. It is otherwise the same entry: the
23
+ * swatch carries the colour, the caption reads in the legend's neutral ink, and
24
+ * both take the shared {@link LegendConfig}.
25
+ *
26
+ * There is no show/hide here. A pie's marks are its *rows*, and a row that
27
+ * shouldn't be in the chart shouldn't be in the table — removing one would
28
+ * silently re-cut every other wedge's share, which is a different chart rather
29
+ * than the same chart with something hidden. Selection is what a pie has
30
+ * instead, and it arrives through {@link PieLegendProps.dims}.
31
+ */
32
+ export declare const PieLegend: import("@motionscript/sdk").Component<"pieLegend", import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
33
+ readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
34
+ readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
35
+ readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
36
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
37
+ readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
38
+ readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
39
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
40
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
41
+ readonly wrap: boolean;
42
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
43
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
44
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
45
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
46
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
47
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
48
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
49
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
50
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
51
+ }>, {
52
+ readonly arm: unknown;
53
+ readonly enter: unknown;
54
+ readonly fillTo: readonly ["fill"];
55
+ readonly strokeTo: readonly ["stroke"];
56
+ readonly shadowTo: readonly ["shadow"];
57
+ readonly overlayTo: readonly ["overlay"];
58
+ readonly progressTo: readonly ["start", "end"];
59
+ readonly flash: {
60
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
61
+ };
62
+ }, null, _Node2D<_Node2DProps>, import("@motionscript/sdk").CallProps<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
63
+ readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
64
+ readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
65
+ readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
66
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
67
+ readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
68
+ readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
69
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
70
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
71
+ readonly wrap: boolean;
72
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
73
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
74
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
75
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
76
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
77
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
78
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
79
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
80
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
81
+ }>, null, import("@motionscript/sdk").BuiltNode<import("@motionscript/sdk").Merge<import("@motionscript/sdk").Box2DState, {
82
+ readonly slices: import("@motionscript/sdk").Type<PieSlice[], PieSlice[], false>;
83
+ readonly legend: import("@motionscript/sdk").Type<LegendConfig, LegendConfig, false>;
84
+ readonly dims: import("@motionscript/sdk").Type<number[], number[], false>;
85
+ readonly arrivals: import("@motionscript/sdk").Type<Readonly<Record<string, Arrival>>, Readonly<Record<string, Arrival>>, false>;
86
+ readonly cornerRadius: import("@motionscript/sdk").Attribute<_RectCornerRadius, _CornerRadiusResolved>;
87
+ readonly cornerStyle: import("@motionscript/sdk").Attribute<_RectCornerStyle, _CornerStyleResolved>;
88
+ readonly flow: import("@motionscript/sdk").Type<_FlowMode, _FlowResolved, false>;
89
+ readonly gap: import("@motionscript/sdk").Type<_GapSize, _GapSize, false>;
90
+ readonly wrap: boolean;
91
+ readonly crossGap: import("@motionscript/sdk").Type<number | undefined, number | undefined, false>;
92
+ readonly columns: import("@motionscript/sdk").Type<number, number, false>;
93
+ readonly align: import("@motionscript/sdk").Attribute<_Alignment, _Vector2>;
94
+ readonly fill: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
95
+ readonly stroke: import("@motionscript/sdk").Attribute<_Stroke, _StrokeResolved[]>;
96
+ readonly shadow: import("@motionscript/sdk").Attribute<_Shadow, _ShadowResolved[]>;
97
+ readonly overlay: import("@motionscript/sdk").Attribute<_Fill, _FillResolved[]>;
98
+ readonly start: import("@motionscript/sdk").Type<number, number, false>;
99
+ readonly end: import("@motionscript/sdk").Type<number, number, false>;
100
+ }>, {
101
+ readonly arm: unknown;
102
+ readonly enter: unknown;
103
+ readonly fillTo: readonly ["fill"];
104
+ readonly strokeTo: readonly ["stroke"];
105
+ readonly shadowTo: readonly ["shadow"];
106
+ readonly overlayTo: readonly ["overlay"];
107
+ readonly progressTo: readonly ["start", "end"];
108
+ readonly flash: {
109
+ readonly portion: import("@motionscript/sdk").Type<number, number, false>;
110
+ };
111
+ }, _Node2D<_Node2DProps>>>>;
112
+ export type PieLegend = NodeOf<typeof PieLegend>;
113
+ //# sourceMappingURL=pie-legend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-legend.d.ts","sourceRoot":"","sources":["../../src/pie-chart/pie-legend.ts"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,MAAM,EACX,KAAK,SAAS,EAEd,KAAK,SAAS,IAAI,UAAU,EAC5B,KAAK,oBAAoB,IAAI,qBAAqB,EAClD,KAAK,mBAAmB,IAAI,oBAAoB,EAChD,KAAK,IAAI,IAAI,KAAK,EAClB,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,QAAQ,IAAI,SAAS,EAC1B,KAAK,YAAY,IAAI,aAAa,EAClC,KAAK,OAAO,IAAI,QAAQ,EACxB,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,WAAW,IAAI,YAAY,EAChC,KAAK,gBAAgB,IAAI,iBAAiB,EAC1C,KAAK,eAAe,IAAI,gBAAgB,EACxC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,MAAM,IAAI,OAAO,EACtB,KAAK,cAAc,IAAI,eAAe,EACtC,KAAK,OAAO,IAAI,QAAQ,EACzB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAA8D,KAAK,OAAO,EAAE,MAAM,eAAe,CAAA;AACxG,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,0CAA0C;IAC1C,MAAM,EAAE,QAAQ,EAAE,CAAA;IAClB,oFAAoF;IACpF,MAAM,EAAE,YAAY,CAAA;IACpB;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAKD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA+FpB,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,SAAS,CAAC,CAAA"}
@@ -0,0 +1,117 @@
1
+ import { Flow, Paint, Rect, Shapes, Text, Types, component2d, textOps, } from "@motionscript/sdk";
2
+ import { fresh } from "../kit/entries.js";
3
+ import { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase } from "../kit/motion.js";
4
+ import { DEFAULT_LEGEND, clampUnit, } from "../kit/shared.js";
5
+ /** How far an entry starts to the right of its slot when it enters, in px. */
6
+ const SLIDE = 16;
7
+ /**
8
+ * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per
9
+ * slice, each pairing the slice's caption with its colour swatch.
10
+ *
11
+ * A column rather than the cartesian charts' row, because it sits *beside* the
12
+ * ring rather than beneath the plot — a pie is as tall as it is wide, so the
13
+ * space it leaves over is a vertical strip. It is otherwise the same entry: the
14
+ * swatch carries the colour, the caption reads in the legend's neutral ink, and
15
+ * both take the shared {@link LegendConfig}.
16
+ *
17
+ * There is no show/hide here. A pie's marks are its *rows*, and a row that
18
+ * shouldn't be in the chart shouldn't be in the table — removing one would
19
+ * silently re-cut every other wedge's share, which is a different chart rather
20
+ * than the same chart with something hidden. Selection is what a pie has
21
+ * instead, and it arrives through {@link PieLegendProps.dims}.
22
+ */
23
+ export const PieLegend = component2d({
24
+ key: "pieLegend",
25
+ state: {
26
+ ...Paint.state,
27
+ ...Flow.state,
28
+ ...Shapes.corners,
29
+ slices: fresh(() => []),
30
+ legend: Types.custom(DEFAULT_LEGEND),
31
+ dims: fresh(() => []),
32
+ arrivals: arrivalsEntry(),
33
+ },
34
+ // A column, for the reason `ChartLegend` gives for its row: a `Rect` given no
35
+ // flow lays its children out `freeform`, every caption on top of the last.
36
+ defaults: {
37
+ flow: "vertical",
38
+ align: "centerLeft",
39
+ width: "hug",
40
+ height: "hug",
41
+ gap: (state) => state.legend.itemGap / 3,
42
+ padding: (state) => state.legend.padding,
43
+ },
44
+ // One entry per slice, ordered top → bottom. The selection dim rides a wrapper
45
+ // rather than the entry itself, so the entrance can animate the entry's own
46
+ // opacity without the two fighting over one value — opacity multiplies down
47
+ // the tree, which is exactly the composition wanted here.
48
+ children: (state) => {
49
+ const marker = state.legend.markerStyle;
50
+ return state.slices.map((_, index) => Rect({
51
+ width: "hug",
52
+ height: "hug",
53
+ flow: "freeform",
54
+ opacity: () => clampUnit(state.dims[index] ?? 1),
55
+ children: [
56
+ Rect({
57
+ flow: "horizontal",
58
+ gap: 12,
59
+ align: "center",
60
+ width: "hug",
61
+ height: "hug",
62
+ opacity: () => arrivalOf(state.arrivals, index).opacity,
63
+ x: () => arrivalOf(state.arrivals, index).shift,
64
+ children: [
65
+ Rect({
66
+ width: marker.height,
67
+ height: marker.height,
68
+ cornerRadius: marker.borderRadius,
69
+ fill: () => state.slices[index]?.fill ?? "white",
70
+ stroke: marker.stroke,
71
+ shadow: marker.shadow,
72
+ }),
73
+ Text({
74
+ ...textOps.styleProps(state.legend.textStyle),
75
+ text: () => state.slices[index]?.category ?? "",
76
+ }),
77
+ ],
78
+ }),
79
+ ],
80
+ }));
81
+ },
82
+ commands: {
83
+ ...Paint.commands,
84
+ /**
85
+ * Every entry at its pre-entrance state, shifted right and transparent: what
86
+ * a chart shows ahead of this legend's own beat in its entrance, since
87
+ * `enter` arms the entries only on its first frame.
88
+ */
89
+ arm: (timeline, state) => timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], { opacity: 0, shift: SLIDE }) })),
90
+ /**
91
+ * Slide + fade every entry in from the right, staggered top-to-bottom. Its
92
+ * first frame arms them all: shifted right and transparent.
93
+ *
94
+ * The timeline's duration is the **whole** entrance: the stagger is carved
95
+ * out of it rather than added on top, so the command takes exactly the time
96
+ * the timeline laid out for it.
97
+ */
98
+ enter: (timeline, state) => {
99
+ const count = state.slices.length;
100
+ if (count === 0)
101
+ return timeline.wait(timeline.duration);
102
+ const from = { opacity: 0, shift: SLIDE };
103
+ const arm = timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], from) }));
104
+ // Each gap is a fifth of an entry's own move, the rhythm the axes use;
105
+ // solved for from the budget rather than added to it.
106
+ const per = timeline.duration / (1 + Math.max(0, count - 1) / 5);
107
+ const step = per / 5;
108
+ const ease = frameEase(timeline);
109
+ const entries = state.slices.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }));
110
+ return timeline.together([arm, beats(timeline, entries)]);
111
+ },
112
+ },
113
+ measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),
114
+ layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),
115
+ render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),
116
+ });
117
+ //# sourceMappingURL=pie-legend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-legend.js","sourceRoot":"","sources":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QAAQ,CAAC,CAAA;YAChC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;YACtH,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;QAC3D,CAAC;KACF;IACD,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACnG,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvF,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;CAC7E,CAAC,CAAA","sourcesContent":["import {\n Flow,\n Paint,\n Rect,\n Shapes,\n Text,\n Types,\n component2d,\n textOps,\n type NodeOf,\n type RectProps,\n // Named so the column's emitted type reaches the Rect surface it spreads through the sdk, not core.\n type Alignment as _Alignment,\n type CornerRadiusResolved as _CornerRadiusResolved,\n type CornerStyleResolved as _CornerStyleResolved,\n type Fill as _Fill,\n type FillResolved as _FillResolved,\n type FlowMode as _FlowMode,\n type FlowResolved as _FlowResolved,\n type GapSize as _GapSize,\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type RectCornerRadius as _RectCornerRadius,\n type RectCornerStyle as _RectCornerStyle,\n type Shadow as _Shadow,\n type ShadowResolved as _ShadowResolved,\n type Stroke as _Stroke,\n type StrokeResolved as _StrokeResolved,\n type Vector2 as _Vector2,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"../kit/entries\"\nimport { armed, arrival, arrivalOf, arrivalsEntry, beats, frameEase, type Arrival } from \"../kit/motion\"\nimport {\n DEFAULT_LEGEND,\n clampUnit,\n type LegendConfig,\n} from \"../kit/shared\"\nimport type { PieSlice } from \"./shared\"\n\nexport interface PieLegendProps extends RectProps {\n /** One entry per slice, in ring order. */\n slices: PieSlice[]\n /** Padding, caption style, gaps, and swatch geometry — see {@link LegendConfig}. */\n legend: LegendConfig\n /**\n * Per-slice opacity multiplier, by index — the same signal that dims the ring,\n * so an entry fades in step with the wedge it names. Missing entries read as 1.\n */\n dims: number[]\n}\n\n/** How far an entry starts to the right of its slot when it enters, in px. */\nconst SLIDE = 16\n\n/**\n * The legend of a {@link PieChart}: a **vertical-flow column** of entries, one per\n * slice, each pairing the slice's caption with its colour swatch.\n *\n * A column rather than the cartesian charts' row, because it sits *beside* the\n * ring rather than beneath the plot — a pie is as tall as it is wide, so the\n * space it leaves over is a vertical strip. It is otherwise the same entry: the\n * swatch carries the colour, the caption reads in the legend's neutral ink, and\n * both take the shared {@link LegendConfig}.\n *\n * There is no show/hide here. A pie's marks are its *rows*, and a row that\n * shouldn't be in the chart shouldn't be in the table — removing one would\n * silently re-cut every other wedge's share, which is a different chart rather\n * than the same chart with something hidden. Selection is what a pie has\n * instead, and it arrives through {@link PieLegendProps.dims}.\n */\nexport const PieLegend = component2d({\n key: \"pieLegend\",\n state: {\n ...Paint.state,\n ...Flow.state,\n ...Shapes.corners,\n slices: fresh<PieSlice[]>(() => []),\n legend: Types.custom<LegendConfig>(DEFAULT_LEGEND),\n dims: fresh<number[]>(() => []),\n arrivals: arrivalsEntry(),\n },\n // A column, for the reason `ChartLegend` gives for its row: a `Rect` given no\n // flow lays its children out `freeform`, every caption on top of the last.\n defaults: {\n flow: \"vertical\",\n align: \"centerLeft\",\n width: \"hug\",\n height: \"hug\",\n gap: (state) => state.legend.itemGap / 3,\n padding: (state) => state.legend.padding,\n },\n // One entry per slice, ordered top → bottom. The selection dim rides a wrapper\n // rather than the entry itself, so the entrance can animate the entry's own\n // opacity without the two fighting over one value — opacity multiplies down\n // the tree, which is exactly the composition wanted here.\n children: (state) => {\n const marker = state.legend.markerStyle\n return state.slices.map((_, index) =>\n Rect({\n width: \"hug\",\n height: \"hug\",\n flow: \"freeform\",\n opacity: () => clampUnit(state.dims[index] ?? 1),\n children: [\n Rect({\n flow: \"horizontal\",\n gap: 12,\n align: \"center\",\n width: \"hug\",\n height: \"hug\",\n opacity: () => arrivalOf(state.arrivals, index).opacity,\n x: () => arrivalOf(state.arrivals, index).shift,\n children: [\n Rect({\n width: marker.height,\n height: marker.height,\n cornerRadius: marker.borderRadius,\n fill: () => state.slices[index]?.fill ?? \"white\",\n stroke: marker.stroke,\n shadow: marker.shadow,\n }),\n Text({\n ...textOps.styleProps(state.legend.textStyle),\n text: () => state.slices[index]?.category ?? \"\",\n }),\n ],\n }),\n ],\n })\n )\n },\n commands: {\n ...Paint.commands,\n /**\n * Every entry at its pre-entrance state, shifted right and transparent: what\n * a chart shows ahead of this legend's own beat in its entrance, since\n * `enter` arms the entries only on its first frame.\n */\n arm: (timeline, state) =>\n timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], { opacity: 0, shift: SLIDE }) })),\n /**\n * Slide + fade every entry in from the right, staggered top-to-bottom. Its\n * first frame arms them all: shifted right and transparent.\n *\n * The timeline's duration is the **whole** entrance: the stagger is carved\n * out of it rather than added on top, so the command takes exactly the time\n * the timeline laid out for it.\n */\n enter: (timeline, state) => {\n const count = state.slices.length\n if (count === 0) return timeline.wait(timeline.duration)\n const from: Arrival = { opacity: 0, shift: SLIDE }\n const arm = timeline.animate(() => ({ arrivals: armed([...state.slices.keys()], from) }))\n // Each gap is a fifth of an entry's own move, the rhythm the axes use;\n // solved for from the budget rather than added to it.\n const per = timeline.duration / (1 + Math.max(0, count - 1) / 5)\n const step = per / 5\n const ease = frameEase(timeline)\n const entries = state.slices.map((_, i) => ({ at: i * step, duration: per, piece: arrival(timeline, i, from, ease) }))\n return timeline.together([arm, beats(timeline, entries)])\n },\n },\n measure: (measurer, state, children) => Flow.measure(measurer, state, children, Paint.inset(state)),\n layout: (box, state, children) => Flow.layout(box, state, children, Paint.inset(state)),\n render: (ctx, state) => Paint.draw(ctx, state, Shapes.rect(ctx.size, state)),\n})\n\nexport type PieLegend = NodeOf<typeof PieLegend>\n"]}