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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +201 -0
  3. package/dist/bar-chart/bar-chart.d.ts +286 -0
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -0
  5. package/dist/bar-chart/bar-chart.js +610 -0
  6. package/dist/bar-chart/bar-chart.js.map +1 -0
  7. package/dist/bar-chart/category-axis.d.ts +77 -0
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -0
  9. package/dist/bar-chart/category-axis.js +141 -0
  10. package/dist/bar-chart/category-axis.js.map +1 -0
  11. package/dist/bar-chart/chart-bars.d.ts +149 -0
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -0
  13. package/dist/bar-chart/chart-bars.js +236 -0
  14. package/dist/bar-chart/chart-bars.js.map +1 -0
  15. package/dist/bar-chart/index.d.ts +16 -0
  16. package/dist/bar-chart/index.d.ts.map +1 -0
  17. package/dist/bar-chart/index.js +12 -0
  18. package/dist/bar-chart/index.js.map +1 -0
  19. package/dist/bar-chart/shared.d.ts +146 -0
  20. package/dist/bar-chart/shared.d.ts.map +1 -0
  21. package/dist/bar-chart/shared.js +182 -0
  22. package/dist/bar-chart/shared.js.map +1 -0
  23. package/dist/browser/chunks/chunk-ZMBOBHYL.js +2 -0
  24. package/dist/browser/chunks/chunk-ZMBOBHYL.js.map +7 -0
  25. package/dist/browser/index.js +2 -0
  26. package/dist/browser/index.js.map +7 -0
  27. package/dist/browser/kit.js +2 -0
  28. package/dist/browser/kit.js.map +7 -0
  29. package/dist/browser/manifest.json +12 -0
  30. package/dist/engine.d.ts +27 -0
  31. package/dist/engine.d.ts.map +1 -0
  32. package/dist/engine.js +27 -0
  33. package/dist/engine.js.map +1 -0
  34. package/dist/index.d.ts +6 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +6 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/kit/chart-border.d.ts +28 -0
  39. package/dist/kit/chart-border.d.ts.map +1 -0
  40. package/dist/kit/chart-border.js +45 -0
  41. package/dist/kit/chart-border.js.map +1 -0
  42. package/dist/kit/chart-canvas.d.ts +56 -0
  43. package/dist/kit/chart-canvas.d.ts.map +1 -0
  44. package/dist/kit/chart-canvas.js +125 -0
  45. package/dist/kit/chart-canvas.js.map +1 -0
  46. package/dist/kit/chart-legend.d.ts +126 -0
  47. package/dist/kit/chart-legend.d.ts.map +1 -0
  48. package/dist/kit/chart-legend.js +212 -0
  49. package/dist/kit/chart-legend.js.map +1 -0
  50. package/dist/kit/shared.d.ts +251 -0
  51. package/dist/kit/shared.d.ts.map +1 -0
  52. package/dist/kit/shared.js +401 -0
  53. package/dist/kit/shared.js.map +1 -0
  54. package/dist/kit/vertical-axis.d.ts +99 -0
  55. package/dist/kit/vertical-axis.d.ts.map +1 -0
  56. package/dist/kit/vertical-axis.js +176 -0
  57. package/dist/kit/vertical-axis.js.map +1 -0
  58. package/dist/line-chart/chart-line.d.ts +91 -0
  59. package/dist/line-chart/chart-line.d.ts.map +1 -0
  60. package/dist/line-chart/chart-line.js +156 -0
  61. package/dist/line-chart/chart-line.js.map +1 -0
  62. package/dist/line-chart/chart-region.d.ts +47 -0
  63. package/dist/line-chart/chart-region.d.ts.map +1 -0
  64. package/dist/line-chart/chart-region.js +101 -0
  65. package/dist/line-chart/chart-region.js.map +1 -0
  66. package/dist/line-chart/horizontal-axis.d.ts +85 -0
  67. package/dist/line-chart/horizontal-axis.d.ts.map +1 -0
  68. package/dist/line-chart/horizontal-axis.js +158 -0
  69. package/dist/line-chart/horizontal-axis.js.map +1 -0
  70. package/dist/line-chart/index.d.ts +22 -0
  71. package/dist/line-chart/index.d.ts.map +1 -0
  72. package/dist/line-chart/index.js +19 -0
  73. package/dist/line-chart/index.js.map +1 -0
  74. package/dist/line-chart/line-chart.d.ts +347 -0
  75. package/dist/line-chart/line-chart.d.ts.map +1 -0
  76. package/dist/line-chart/line-chart.js +701 -0
  77. package/dist/line-chart/line-chart.js.map +1 -0
  78. package/dist/line-chart/shared.d.ts +171 -0
  79. package/dist/line-chart/shared.d.ts.map +1 -0
  80. package/dist/line-chart/shared.js +270 -0
  81. package/dist/line-chart/shared.js.map +1 -0
  82. package/dist/line-chart/x-scale.d.ts +84 -0
  83. package/dist/line-chart/x-scale.d.ts.map +1 -0
  84. package/dist/line-chart/x-scale.js +302 -0
  85. package/dist/line-chart/x-scale.js.map +1 -0
  86. package/dist/nodes.d.ts +20 -0
  87. package/dist/nodes.d.ts.map +1 -0
  88. package/dist/nodes.js +20 -0
  89. package/dist/nodes.js.map +1 -0
  90. package/dist/pie-chart/index.d.ts +18 -0
  91. package/dist/pie-chart/index.d.ts.map +1 -0
  92. package/dist/pie-chart/index.js +14 -0
  93. package/dist/pie-chart/index.js.map +1 -0
  94. package/dist/pie-chart/pie-chart.d.ts +170 -0
  95. package/dist/pie-chart/pie-chart.d.ts.map +1 -0
  96. package/dist/pie-chart/pie-chart.js +291 -0
  97. package/dist/pie-chart/pie-chart.js.map +1 -0
  98. package/dist/pie-chart/pie-legend.d.ts +60 -0
  99. package/dist/pie-chart/pie-legend.d.ts.map +1 -0
  100. package/dist/pie-chart/pie-legend.js +131 -0
  101. package/dist/pie-chart/pie-legend.js.map +1 -0
  102. package/dist/pie-chart/pie-ring.d.ts +266 -0
  103. package/dist/pie-chart/pie-ring.d.ts.map +1 -0
  104. package/dist/pie-chart/pie-ring.js +708 -0
  105. package/dist/pie-chart/pie-ring.js.map +1 -0
  106. package/dist/pie-chart/shared.d.ts +210 -0
  107. package/dist/pie-chart/shared.d.ts.map +1 -0
  108. package/dist/pie-chart/shared.js +240 -0
  109. package/dist/pie-chart/shared.js.map +1 -0
  110. package/package.json +69 -3
  111. package/registry.json +23 -0
  112. package/src/bar-chart/bar-chart.ts +804 -0
  113. package/src/bar-chart/category-axis.ts +177 -0
  114. package/src/bar-chart/chart-bars.ts +310 -0
  115. package/src/bar-chart/index.ts +31 -0
  116. package/src/bar-chart/shared.ts +354 -0
  117. package/src/engine.ts +26 -0
  118. package/src/index.ts +5 -0
  119. package/src/kit/chart-border.ts +61 -0
  120. package/src/kit/chart-canvas.ts +157 -0
  121. package/src/kit/chart-legend.ts +250 -0
  122. package/src/kit/shared.ts +675 -0
  123. package/src/kit/vertical-axis.ts +224 -0
  124. package/src/line-chart/chart-line.ts +208 -0
  125. package/src/line-chart/chart-region.ts +135 -0
  126. package/src/line-chart/horizontal-axis.ts +202 -0
  127. package/src/line-chart/index.ts +39 -0
  128. package/src/line-chart/line-chart.ts +894 -0
  129. package/src/line-chart/shared.ts +459 -0
  130. package/src/line-chart/x-scale.ts +367 -0
  131. package/src/nodes.ts +20 -0
  132. package/src/pie-chart/index.ts +37 -0
  133. package/src/pie-chart/pie-chart.ts +374 -0
  134. package/src/pie-chart/pie-legend.ts +159 -0
  135. package/src/pie-chart/pie-ring.ts +903 -0
  136. package/src/pie-chart/shared.ts +490 -0
  137. package/README.md +0 -4
@@ -0,0 +1,170 @@
1
+ import { Node2D, type CommandArgs, type DataRecord, type NodeConfig, type Node2DProps } from "@motionscript/core";
2
+ import { type PieChartTheme, type PieLabelMode, type PieLabelPlacement } from "./shared.js";
3
+ import { type Seekable } from "@motionscript/core/component";
4
+ export interface PieChartProps extends Node2DProps {
5
+ /** One row per slice — a plain record of field name to value. */
6
+ data: DataRecord[];
7
+ /** Key into each row for its slice caption, used on the labels and the legend. */
8
+ categoryField: string;
9
+ /** Key into each row for its slice magnitude — the wedge's share of the ring. */
10
+ valueField: string;
11
+ /**
12
+ * The chart's visual theme — slice palette, ring geometry, label and centre
13
+ * type, legend. Every branch is optional and deep-merged onto
14
+ * {@link DEFAULT_PIE_CHART_THEME}.
15
+ */
16
+ theme?: PieChartTheme;
17
+ /** What the ring's labels say. */
18
+ labelMode?: PieLabelMode;
19
+ /** Where they sit: inside their wedge, outside on a leader, or nowhere. */
20
+ labelPlacement?: PieLabelPlacement;
21
+ /** Whether the legend column beside the ring is drawn at all. */
22
+ showLegend?: boolean;
23
+ /** Gap between the ring and the legend, in px. */
24
+ gap?: number;
25
+ /** Text set in the ring's hole — see {@link revealCenter}. */
26
+ centerLabel?: string;
27
+ /** Smaller second line under {@link centerLabel}. */
28
+ centerCaption?: string;
29
+ /**
30
+ * Whether the hole's summary is drawn at rest. `true` (the default) is the
31
+ * plain answer; a scene that wants the conclusion to land on a later beat sets
32
+ * this `false` and calls {@link revealCenter} when it gets there.
33
+ */
34
+ showCenter?: boolean;
35
+ }
36
+ /**
37
+ * A pie or donut chart, composed from two independent parts rather than one
38
+ * monolithic draw — the third of the chart family, built the same way as the
39
+ * line and bar charts beside it:
40
+ *
41
+ * - {@link PieRing} — the wedges, each sized by its share of the total, with its
42
+ * label set inside its own band or pinned outside on a leader line, and the
43
+ * summary in the hole. The only part of the family that draws a path.
44
+ * - {@link PieLegend} — a column of swatch-and-caption rows naming each slice.
45
+ *
46
+ * The two are laid out by a plain horizontal-flow {@link Rect}: the ring fills whatever the
47
+ * hugging legend leaves, both centred, so the chart re-flows if its box changes.
48
+ *
49
+ * **One mark per row, not per column** — which is what makes this the odd one of
50
+ * the three. A line or a bar chart plots *series*, so its colours belong to
51
+ * columns and hiding one is a sensible thing to ask for. A pie plots rows, so its
52
+ * palette is indexed by row and there is nothing to hide: dropping a slice would
53
+ * silently re-cut every other wedge's share, which is a different chart rather
54
+ * than the same chart with a series switched off. {@link selectSlice} and its
55
+ * siblings are what a pie has instead — a slice swells out of the ring, its hole
56
+ * edge staying put, and everything else dims behind it.
57
+ *
58
+ * **Resting state is the finished chart** — the same bargain the other two make:
59
+ * the studio paints a node's Initial state on a paused canvas, so a chart that
60
+ * only appeared once a command had run would be edited blind. {@link enter} arms
61
+ * every part back to its pre-entrance state before animating. The one exception
62
+ * is the hole's summary, which a scene can hold back with `showCenter: false`
63
+ * because it is usually the chart's *conclusion* rather than part of its setup.
64
+ */
65
+ export declare class PieChart extends Node2D<PieChartProps> {
66
+ data: DataRecord[];
67
+ categoryField: string;
68
+ valueField: string;
69
+ theme: PieChartTheme;
70
+ labelMode: PieLabelMode;
71
+ labelPlacement: PieLabelPlacement;
72
+ gap: number;
73
+ centerLabel: string;
74
+ centerCaption: string;
75
+ /**
76
+ * How far each slice is currently pushed out of the ring, `0`–`1` per index.
77
+ *
78
+ * Held here rather than on the ring because two parts read it: the wedges grow
79
+ * out by it, and the legend entries dim by it. One signal, one tween, and the
80
+ * two can't drift.
81
+ */
82
+ pops: number[];
83
+ private ring;
84
+ private legend;
85
+ /** `this.theme` read back through its *resolved* shape — see `LineChart.theme`. */
86
+ private get resolvedTheme();
87
+ /** The slices the ring and the legend draw, resolved from the rows and the palette. */
88
+ private get slices();
89
+ /**
90
+ * How far each slice is dimmed by the current selection, one entry per slice —
91
+ * 1 while nothing is selected, and for the selected slice itself; falling
92
+ * toward the theme's `dimOpacity` for the rest in proportion to how far the
93
+ * selection has grown.
94
+ */
95
+ private sliceDims;
96
+ /** How far slice `index` is currently pushed out, in `[0, 1]`. */
97
+ private popAt;
98
+ constructor(props?: NodeConfig<PieChart, PieChartProps>);
99
+ /**
100
+ * Prime every part at its pre-entrance state — no wedges swept, no labels, the
101
+ * legend shifted and transparent.
102
+ *
103
+ * Called by {@link enter} before its first frame so nothing flashes ahead of
104
+ * its beat. Idempotent, and public so a scene can hide a chart ahead of time
105
+ * without starting the entrance. The hole's summary is deliberately untouched:
106
+ * it has its own signal, so a scene that set it up to land later keeps that.
107
+ */
108
+ arm(): void;
109
+ /**
110
+ * Animate the whole chart in: the wedges sweep in clockwise from the theme's
111
+ * `startAngle`, then the labels fade up and the legend staggers in together.
112
+ *
113
+ * `duration` is the **whole** entrance; the phases are shares of it.
114
+ */
115
+ enter(args: CommandArgs<Record<string, never>> & {
116
+ duration: number;
117
+ }): Seekable;
118
+ /**
119
+ * Fade the hole's summary up.
120
+ *
121
+ * Held out of {@link enter} on purpose: what sits in a donut's hole is usually
122
+ * the chart's conclusion, so the scene lands it on the beat it belongs to
123
+ * rather than giving it away with the first frame. Pair it with
124
+ * `showCenter: false`, which is what leaves the hole clear to begin with.
125
+ */
126
+ revealCenter(args?: CommandArgs<Record<string, never>> & {
127
+ duration?: number;
128
+ }): Seekable;
129
+ /** True when slice `index` is currently grown out past the ring's rim. */
130
+ isSelected(index: number): boolean;
131
+ /**
132
+ * Grow slice `index` out past the ring's rim and dim the rest of the chart
133
+ * behind it, leaving any other selected slice where it is.
134
+ */
135
+ selectSlice(args: CommandArgs<{
136
+ sliceIndex: number;
137
+ }> & {
138
+ duration?: number;
139
+ }): Seekable;
140
+ /** Settle slice `index` back flush with the ring. */
141
+ deselectSlice(args: CommandArgs<{
142
+ sliceIndex: number;
143
+ }> & {
144
+ duration?: number;
145
+ }): Seekable;
146
+ /** Move the focus to slice `index` alone, settling whatever else was out. */
147
+ selectOnlySlice(args: CommandArgs<{
148
+ sliceIndex: number;
149
+ }> & {
150
+ duration?: number;
151
+ }): Seekable;
152
+ /** Settle every slice flush and bring the whole chart back to full. */
153
+ clearSelection(args?: CommandArgs<Record<string, never>> & {
154
+ duration?: number;
155
+ }): Seekable;
156
+ /**
157
+ * Ease every slice's pop from where it is now to what `pop` asks for.
158
+ *
159
+ * Consumes its full duration even when nothing moves: in the studio a
160
+ * command's duration is what the timeline lays out and what its parallel
161
+ * siblings are timed against, so a no-op that took no frames would pull
162
+ * everything after it forward.
163
+ *
164
+ * `from` and the targets are read when the command is *built*, which for a
165
+ * driven scene is with the node in the state its own start time implies — so a
166
+ * select that follows another starts from where that one left the ring.
167
+ */
168
+ private tweenPops;
169
+ }
170
+ //# sourceMappingURL=pie-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pie-chart.d.ts","sourceRoot":"","sources":["../../src/pie-chart/pie-chart.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EAGN,KAAK,WAAW,EAChB,KAAK,UAAU,EAEf,KAAK,UAAU,EACf,K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,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAO,GACpE,QAAQ;IAMX;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,SAAS;CAclB"}
@@ -0,0 +1,291 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { Rect, command, node, Node2D, easeOut, property, } from "@motionscript/core";
8
+ import { clampUnit } from "../kit/shared.js";
9
+ import { PieLegend } from "./pie-legend.js";
10
+ import { PieRing } from "./pie-ring.js";
11
+ import { DEFAULT_PIE_CHART_THEME, lerpPieChartTheme, resolvePieChartTheme, resolvePieSlices, } from "./shared.js";
12
+ import { drive, hold, sequence as sequenceOf, together, } from "@motionscript/core/component";
13
+ /**
14
+ * How {@link PieChart.enter} divides its duration: the wedges sweeping in, then
15
+ * the labels and the legend arriving together. Shares of the whole, so they sum
16
+ * to 1 — the entrance takes exactly the time it was given, for the reason spelt
17
+ * out on `LineChart.enter`.
18
+ */
19
+ const SWEEP_SHARE = 0.65;
20
+ const LABEL_SHARE = 0.35;
21
+ /**
22
+ * A pie or donut chart, composed from two independent parts rather than one
23
+ * monolithic draw — the third of the chart family, built the same way as the
24
+ * line and bar charts beside it:
25
+ *
26
+ * - {@link PieRing} — the wedges, each sized by its share of the total, with its
27
+ * label set inside its own band or pinned outside on a leader line, and the
28
+ * summary in the hole. The only part of the family that draws a path.
29
+ * - {@link PieLegend} — a column of swatch-and-caption rows naming each slice.
30
+ *
31
+ * The two are laid out by a plain horizontal-flow {@link Rect}: the ring fills whatever the
32
+ * hugging legend leaves, both centred, so the chart re-flows if its box changes.
33
+ *
34
+ * **One mark per row, not per column** — which is what makes this the odd one of
35
+ * the three. A line or a bar chart plots *series*, so its colours belong to
36
+ * columns and hiding one is a sensible thing to ask for. A pie plots rows, so its
37
+ * palette is indexed by row and there is nothing to hide: dropping a slice would
38
+ * silently re-cut every other wedge's share, which is a different chart rather
39
+ * than the same chart with a series switched off. {@link selectSlice} and its
40
+ * siblings are what a pie has instead — a slice swells out of the ring, its hole
41
+ * edge staying put, and everything else dims behind it.
42
+ *
43
+ * **Resting state is the finished chart** — the same bargain the other two make:
44
+ * the studio paints a node's Initial state on a paused canvas, so a chart that
45
+ * only appeared once a command had run would be edited blind. {@link enter} arms
46
+ * every part back to its pre-entrance state before animating. The one exception
47
+ * is the hole's summary, which a scene can hold back with `showCenter: false`
48
+ * because it is usually the chart's *conclusion* rather than part of its setup.
49
+ */
50
+ let PieChart = class PieChart extends Node2D {
51
+ // ---- Part handles (built in the constructor) --------------------------
52
+ ring;
53
+ legend = null;
54
+ /** `this.theme` read back through its *resolved* shape — see `LineChart.theme`. */
55
+ get resolvedTheme() {
56
+ return this.theme;
57
+ }
58
+ /** The slices the ring and the legend draw, resolved from the rows and the palette. */
59
+ get slices() {
60
+ return resolvePieSlices(this.data, this.categoryField, this.valueField, this.resolvedTheme.sliceFills);
61
+ }
62
+ /**
63
+ * How far each slice is dimmed by the current selection, one entry per slice —
64
+ * 1 while nothing is selected, and for the selected slice itself; falling
65
+ * toward the theme's `dimOpacity` for the rest in proportion to how far the
66
+ * selection has grown.
67
+ */
68
+ sliceDims() {
69
+ let focus = 0;
70
+ for (let i = 0; i < this.data.length; i++) {
71
+ focus = Math.max(focus, this.popAt(i));
72
+ }
73
+ const dim = this.resolvedTheme.spotlight.dimOpacity;
74
+ if (focus <= 0)
75
+ return this.data.map(() => 1);
76
+ return this.data.map((_, i) => 1 - (1 - clampUnit(dim)) * focus * (1 - this.popAt(i)));
77
+ }
78
+ /** How far slice `index` is currently pushed out, in `[0, 1]`. */
79
+ popAt(index) {
80
+ return clampUnit(this.pops[index] ?? 0);
81
+ }
82
+ constructor(props) {
83
+ super(props);
84
+ // The whole chart is composed from plain props/`data` — no context needed,
85
+ // so the parts are built here (super() applied the props above). The slice
86
+ // *structure* (one wedge and one legend row each) is read once, like every
87
+ // other chart's series list; everything the parts draw with is passed as a
88
+ // closure, so `chart.to({ theme })` genuinely re-paints the ring.
89
+ const slices = this.slices;
90
+ const showLegend = props?.showLegend !== false;
91
+ this.pops = slices.map(() => 0);
92
+ this.ring = new PieRing({
93
+ width: "fill",
94
+ height: "fill",
95
+ slices,
96
+ ring: () => this.resolvedTheme.ring,
97
+ label: () => this.resolvedTheme.label,
98
+ centerStyle: () => this.resolvedTheme.center,
99
+ labelMode: this.labelMode,
100
+ labelPlacement: this.labelPlacement,
101
+ pops: () => this.pops,
102
+ dimOpacity: () => this.resolvedTheme.spotlight.dimOpacity,
103
+ centerLabel: this.centerLabel,
104
+ centerCaption: this.centerCaption,
105
+ centerReveal: props?.showCenter === false ? 0 : 1,
106
+ });
107
+ const children = [this.ring];
108
+ if (showLegend) {
109
+ this.legend = new PieLegend({
110
+ slices,
111
+ legend: () => this.resolvedTheme.legend,
112
+ dims: () => this.sliceDims(),
113
+ });
114
+ children.push(this.legend);
115
+ }
116
+ this.add(new Rect({ flow: "horizontal",
117
+ width: "fill",
118
+ height: "fill",
119
+ gap: this.gap,
120
+ align: "center",
121
+ children,
122
+ }));
123
+ }
124
+ // ---- Orchestrated entrance --------------------------------------------
125
+ /**
126
+ * Prime every part at its pre-entrance state — no wedges swept, no labels, the
127
+ * legend shifted and transparent.
128
+ *
129
+ * Called by {@link enter} before its first frame so nothing flashes ahead of
130
+ * its beat. Idempotent, and public so a scene can hide a chart ahead of time
131
+ * without starting the entrance. The hole's summary is deliberately untouched:
132
+ * it has its own signal, so a scene that set it up to land later keeps that.
133
+ */
134
+ arm() {
135
+ this.ring.set({ growth: 0, labelReveal: 0 });
136
+ this.legend?.arm();
137
+ }
138
+ /**
139
+ * Animate the whole chart in: the wedges sweep in clockwise from the theme's
140
+ * `startAngle`, then the labels fade up and the legend staggers in together.
141
+ *
142
+ * `duration` is the **whole** entrance; the phases are shares of it.
143
+ */
144
+ enter(args) {
145
+ const duration = args.duration;
146
+ const easing = args.easing ?? easeOut();
147
+ this.arm();
148
+ return sequenceOf(this.ring.sweep({ duration: duration * SWEEP_SHARE, easing }), together(this.ring.revealLabels({ duration: duration * LABEL_SHARE, easing }), this.legend
149
+ ? this.legend.enter({ duration: duration * LABEL_SHARE, easing })
150
+ : hold(duration * LABEL_SHARE)));
151
+ }
152
+ /**
153
+ * Fade the hole's summary up.
154
+ *
155
+ * Held out of {@link enter} on purpose: what sits in a donut's hole is usually
156
+ * the chart's conclusion, so the scene lands it on the beat it belongs to
157
+ * rather than giving it away with the first frame. Pair it with
158
+ * `showCenter: false`, which is what leaves the hole clear to begin with.
159
+ */
160
+ revealCenter(args = {}) {
161
+ return this.ring.revealCenter({ duration: args.duration ?? 0.6, easing: args.easing ?? easeOut() });
162
+ }
163
+ // ---- Selection ---------------------------------------------------------
164
+ /** True when slice `index` is currently grown out past the ring's rim. */
165
+ isSelected(index) {
166
+ return this.popAt(index) > 0.5;
167
+ }
168
+ /**
169
+ * Grow slice `index` out past the ring's rim and dim the rest of the chart
170
+ * behind it, leaving any other selected slice where it is.
171
+ */
172
+ selectSlice(args) {
173
+ const { sliceIndex: index } = args.data;
174
+ const duration = args.duration ?? 0.45;
175
+ const easing = args.easing ?? easeOut();
176
+ return this.tweenPops((i) => (i === index ? 1 : this.popAt(i)), duration, easing);
177
+ }
178
+ /** Settle slice `index` back flush with the ring. */
179
+ deselectSlice(args) {
180
+ const { sliceIndex: index } = args.data;
181
+ const duration = args.duration ?? 0.45;
182
+ const easing = args.easing ?? easeOut();
183
+ return this.tweenPops((i) => (i === index ? 0 : this.popAt(i)), duration, easing);
184
+ }
185
+ /** Move the focus to slice `index` alone, settling whatever else was out. */
186
+ selectOnlySlice(args) {
187
+ const { sliceIndex: index } = args.data;
188
+ const duration = args.duration ?? 0.45;
189
+ const easing = args.easing ?? easeOut();
190
+ return this.tweenPops((i) => (i === index ? 1 : 0), duration, easing);
191
+ }
192
+ /** Settle every slice flush and bring the whole chart back to full. */
193
+ clearSelection(args = {}) {
194
+ const duration = args.duration ?? 0.45;
195
+ const easing = args.easing ?? easeOut();
196
+ return this.tweenPops(() => 0, duration, easing);
197
+ }
198
+ /**
199
+ * Ease every slice's pop from where it is now to what `pop` asks for.
200
+ *
201
+ * Consumes its full duration even when nothing moves: in the studio a
202
+ * command's duration is what the timeline lays out and what its parallel
203
+ * siblings are timed against, so a no-op that took no frames would pull
204
+ * everything after it forward.
205
+ *
206
+ * `from` and the targets are read when the command is *built*, which for a
207
+ * driven scene is with the node in the state its own start time implies — so a
208
+ * select that follows another starts from where that one left the ring.
209
+ */
210
+ tweenPops(pop, duration, easing) {
211
+ const from = this.data.map((_, i) => this.popAt(i));
212
+ const targets = this.data.map((_, i) => clampUnit(pop(i)));
213
+ if (from.every((value, i) => value === targets[i]))
214
+ return hold(duration);
215
+ return drive(duration, (t) => {
216
+ const e = easing(t);
217
+ this.pops = from.map((value, i) => value + (targets[i] - value) * e);
218
+ });
219
+ }
220
+ };
221
+ __decorate([
222
+ property({ default: () => [] })
223
+ ], PieChart.prototype, "data", void 0);
224
+ __decorate([
225
+ property({ default: "" })
226
+ ], PieChart.prototype, "categoryField", void 0);
227
+ __decorate([
228
+ property({ default: "" })
229
+ ], PieChart.prototype, "valueField", void 0);
230
+ __decorate([
231
+ property({
232
+ default: DEFAULT_PIE_CHART_THEME,
233
+ mapper: resolvePieChartTheme,
234
+ tween: lerpPieChartTheme,
235
+ })
236
+ ], PieChart.prototype, "theme", void 0);
237
+ __decorate([
238
+ property({ default: "percent" })
239
+ ], PieChart.prototype, "labelMode", void 0);
240
+ __decorate([
241
+ property({ default: "leader" })
242
+ ], PieChart.prototype, "labelPlacement", void 0);
243
+ __decorate([
244
+ property({ default: 40 })
245
+ ], PieChart.prototype, "gap", void 0);
246
+ __decorate([
247
+ property({ default: "" })
248
+ ], PieChart.prototype, "centerLabel", void 0);
249
+ __decorate([
250
+ property({ default: "" })
251
+ ], PieChart.prototype, "centerCaption", void 0);
252
+ __decorate([
253
+ property({ default: () => [] })
254
+ ], PieChart.prototype, "pops", void 0);
255
+ __decorate([
256
+ command()
257
+ ], PieChart.prototype, "enter", null);
258
+ __decorate([
259
+ command()
260
+ ], PieChart.prototype, "revealCenter", null);
261
+ __decorate([
262
+ command({ args: [{ key: "sliceIndex", kind: "number", default: 0, min: 0, step: 1 }] })
263
+ ], PieChart.prototype, "selectSlice", null);
264
+ __decorate([
265
+ command({ args: [{ key: "sliceIndex", kind: "number", default: 0, min: 0, step: 1 }] })
266
+ ], PieChart.prototype, "deselectSlice", null);
267
+ __decorate([
268
+ command({ args: [{ key: "sliceIndex", kind: "number", default: 0, min: 0, step: 1 }] })
269
+ ], PieChart.prototype, "selectOnlySlice", null);
270
+ __decorate([
271
+ command()
272
+ ], PieChart.prototype, "clearSelection", null);
273
+ PieChart = __decorate([
274
+ node({
275
+ key: "pieChart",
276
+ parentKey: "node",
277
+ forkable: true,
278
+ layout: {
279
+ children: "freeform",
280
+ defaultWidthMode: "fixed",
281
+ defaultHeightMode: "fixed",
282
+ acceptsChildren: true,
283
+ },
284
+ seed: {
285
+ width: 680,
286
+ height: 480,
287
+ },
288
+ })
289
+ ], PieChart);
290
+ export { PieChart };
291
+ //# 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,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,QAAQ,GAMT,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAAE,SAAS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,GAAG,EAAE,UAAU;QACf,SAAS,EAAE,MAAM;QACjB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE;YACN,QAAQ,EAAE,UAAU;YACpB,gBAAgB,EAAE,OAAO;YACzB,iBAAiB,EAAE,OAAO;YAC1B,eAAe,EAAE,IAAI;SACtB;QACD,IAAI,EAAE;YACJ,KAAK,EAAE,GAAG;YACV,MAAM,EAAE,GAAG;SACZ;KACF,CAAC;GACW,QAAQ,CA2PpB","sourcesContent":["import {\n Rect,\n command,\n node,\n Node2D,\n easeOut,\n property,\n type CommandArgs,\n type DataRecord,\n type EasingFunction,\n type NodeConfig,\n type Node2DProps,\n} from \"@motionscript/core\"\n\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\"\nimport {\n drive,\n hold,\n sequence as sequenceOf,\n together,\n type Seekable,\n} from \"@motionscript/core/component\"\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 {@link 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 calls {@link revealCenter} when it gets there.\n */\n showCenter?: boolean\n}\n\n/**\n * How {@link PieChart.enter} divides its duration: the wedges sweeping in, then\n * the labels and the legend arriving together. Shares of the whole, so they sum\n * to 1 — the entrance takes exactly the time it was given, for the reason spelt\n * out on `LineChart.enter`.\n */\nconst SWEEP_SHARE = 0.65\nconst LABEL_SHARE = 0.35\n\n/**\n * A pie or donut chart, composed from two independent parts rather than one\n * monolithic draw — the third of the chart family, built the same way as the\n * line and bar charts beside it:\n *\n * - {@link PieRing} — the wedges, each sized by its share of the total, with its\n * label set inside its own band or pinned outside on a leader line, and the\n * summary in the hole. The only part of the family that draws a path.\n * - {@link PieLegend} — a column of swatch-and-caption rows naming each slice.\n *\n * The two are laid out by a plain horizontal-flow {@link Rect}: the ring fills whatever the\n * hugging legend leaves, both centred, so the chart re-flows if its box changes.\n *\n * **One mark per row, not per column** — which is what makes this the odd one of\n * the three. A line or a bar chart plots *series*, so its colours belong to\n * columns and hiding one is a sensible thing to ask for. A pie plots rows, so its\n * palette is indexed by row and there is nothing to hide: dropping a slice would\n * silently re-cut every other wedge's share, which is a different chart rather\n * than the same chart with a series switched off. {@link selectSlice} and its\n * siblings are what a pie has instead — a slice swells out of the ring, its hole\n * edge staying put, and everything else dims behind it.\n *\n * **Resting state is the finished chart** — the same bargain the other two make:\n * the studio paints a node's Initial state on a paused canvas, so a chart that\n * only appeared once a command had run would be edited blind. {@link enter} arms\n * every part back to its pre-entrance state before animating. The one exception\n * is the hole's summary, which a scene can hold back with `showCenter: false`\n * because it is usually the chart's *conclusion* rather than part of its setup.\n */\n@node({\n key: \"pieChart\",\n parentKey: \"node\",\n forkable: true,\n layout: {\n children: \"freeform\",\n defaultWidthMode: \"fixed\",\n defaultHeightMode: \"fixed\",\n acceptsChildren: true,\n },\n seed: {\n width: 680,\n height: 480,\n },\n})\nexport class PieChart extends Node2D<PieChartProps> {\n @property({ default: () => [] as DataRecord[] }) declare data: DataRecord[]\n @property({ default: \"\" }) declare categoryField: string\n @property({ default: \"\" }) declare valueField: string\n @property({\n default: DEFAULT_PIE_CHART_THEME,\n mapper: resolvePieChartTheme,\n tween: lerpPieChartTheme,\n })\n declare theme: PieChartTheme\n @property({ default: \"percent\" }) declare labelMode: PieLabelMode\n @property({ default: \"leader\" }) declare labelPlacement: PieLabelPlacement\n @property({ default: 40 }) declare gap: number\n @property({ default: \"\" }) declare centerLabel: string\n @property({ default: \"\" }) declare centerCaption: string\n\n /**\n * How far each slice is currently pushed out of the ring, `0`–`1` per index.\n *\n * Held here rather than on the ring because two parts read it: the wedges grow\n * out by it, and the legend entries dim by it. One signal, one tween, and the\n * two can't drift.\n */\n @property({ default: () => [] as number[] }) declare pops: number[]\n\n // ---- Part handles (built in the constructor) --------------------------\n private ring: PieRing\n private legend: PieLegend | null = null\n\n /** `this.theme` read back through its *resolved* shape — see `LineChart.theme`. */\n private get resolvedTheme(): PieChartConfig {\n return this.theme as unknown as PieChartConfig\n }\n\n /** The slices the ring and the legend draw, resolved from the rows and the palette. */\n private get slices(): PieSlice[] {\n return resolvePieSlices(\n this.data,\n this.categoryField,\n this.valueField,\n this.resolvedTheme.sliceFills\n )\n }\n\n /**\n * How far each slice is dimmed by the current selection, one entry per slice —\n * 1 while nothing is selected, and for the selected slice itself; falling\n * toward the theme's `dimOpacity` for the rest in proportion to how far the\n * selection has grown.\n */\n private sliceDims(): number[] {\n let focus = 0\n for (let i = 0; i < this.data.length; i++) {\n focus = Math.max(focus, this.popAt(i))\n }\n const dim = this.resolvedTheme.spotlight.dimOpacity\n if (focus <= 0) return this.data.map(() => 1)\n return this.data.map(\n (_, i) => 1 - (1 - clampUnit(dim)) * focus * (1 - this.popAt(i))\n )\n }\n\n /** How far slice `index` is currently pushed out, in `[0, 1]`. */\n private popAt(index: number): number {\n return clampUnit(this.pops[index] ?? 0)\n }\n\n constructor(props?: NodeConfig<PieChart, PieChartProps>) {\n super(props)\n\n // The whole chart is composed from plain props/`data` — no context needed,\n // so the parts are built here (super() applied the props above). The slice\n // *structure* (one wedge and one legend row each) is read once, like every\n // other chart's series list; everything the parts draw with is passed as a\n // closure, so `chart.to({ theme })` genuinely re-paints the ring.\n const slices = this.slices\n const showLegend = props?.showLegend !== false\n this.pops = slices.map(() => 0)\n\n this.ring = new PieRing({\n width: \"fill\",\n height: \"fill\",\n slices,\n ring: () => this.resolvedTheme.ring,\n label: () => this.resolvedTheme.label,\n centerStyle: () => this.resolvedTheme.center,\n labelMode: this.labelMode,\n labelPlacement: this.labelPlacement,\n pops: () => this.pops,\n dimOpacity: () => this.resolvedTheme.spotlight.dimOpacity,\n centerLabel: this.centerLabel,\n centerCaption: this.centerCaption,\n centerReveal: props?.showCenter === false ? 0 : 1,\n })\n\n const children: Node2D[] = [this.ring]\n if (showLegend) {\n this.legend = new PieLegend({\n slices,\n legend: () => this.resolvedTheme.legend,\n dims: () => this.sliceDims(),\n })\n children.push(this.legend)\n }\n\n this.add(\n new Rect({ flow: \"horizontal\",\n width: \"fill\",\n height: \"fill\",\n gap: this.gap,\n align: \"center\",\n children,\n })\n )\n }\n\n // ---- Orchestrated entrance --------------------------------------------\n\n /**\n * Prime every part at its pre-entrance state — no wedges swept, no labels, the\n * legend shifted and transparent.\n *\n * Called by {@link enter} before its first frame so nothing flashes ahead of\n * its beat. Idempotent, and public so a scene can hide a chart ahead of time\n * without starting the entrance. The hole's summary is deliberately untouched:\n * it has its own signal, so a scene that set it up to land later keeps that.\n */\n arm(): void {\n this.ring.set({ growth: 0, labelReveal: 0 })\n this.legend?.arm()\n }\n\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 *\n * `duration` is the **whole** entrance; the phases are shares of it.\n */\n @command()\n enter(\n args: CommandArgs<Record<string, never>> & { duration: number }\n ): Seekable {\n const duration = args.duration\n const easing = args.easing ?? easeOut()\n this.arm()\n\n return sequenceOf(\n this.ring.sweep({ duration: duration * SWEEP_SHARE, easing }),\n together(\n this.ring.revealLabels({ duration: duration * LABEL_SHARE, easing }),\n this.legend\n ? this.legend.enter({ duration: duration * LABEL_SHARE, easing })\n : hold(duration * LABEL_SHARE)\n )\n )\n }\n\n /**\n * Fade the hole's summary up.\n *\n * Held out of {@link enter} on purpose: what sits in a donut's hole is usually\n * the chart's conclusion, so the scene lands it on the beat it belongs to\n * rather than giving it away with the first frame. Pair it with\n * `showCenter: false`, which is what leaves the hole clear to begin with.\n */\n @command()\n revealCenter(\n args: CommandArgs<Record<string, never>> & { duration?: number } = {}\n ): Seekable {\n return this.ring.revealCenter({ duration: args.duration ?? 0.6, easing: args.easing ?? easeOut() })\n }\n\n // ---- Selection ---------------------------------------------------------\n\n /** True when slice `index` is currently grown out past the ring's rim. */\n isSelected(index: number): boolean {\n return this.popAt(index) > 0.5\n }\n\n /**\n * Grow slice `index` out past the ring's rim and dim the rest of the chart\n * behind it, leaving any other selected slice where it is.\n */\n @command({ args: [{ key: \"sliceIndex\", kind: \"number\", default: 0, min: 0, step: 1 }] })\n selectSlice(\n args: CommandArgs<{ sliceIndex: number }> & { duration?: number }\n ): Seekable {\n const { sliceIndex: index } = args.data as { sliceIndex: number }\n const duration = args.duration ?? 0.45\n const easing = args.easing ?? easeOut()\n return this.tweenPops((i) => (i === index ? 1 : this.popAt(i)), duration, easing)\n }\n\n /** Settle slice `index` back flush with the ring. */\n @command({ args: [{ key: \"sliceIndex\", kind: \"number\", default: 0, min: 0, step: 1 }] })\n deselectSlice(\n args: CommandArgs<{ sliceIndex: number }> & { duration?: number }\n ): Seekable {\n const { sliceIndex: index } = args.data as { sliceIndex: number }\n const duration = args.duration ?? 0.45\n const easing = args.easing ?? easeOut()\n return this.tweenPops((i) => (i === index ? 0 : this.popAt(i)), duration, easing)\n }\n\n /** Move the focus to slice `index` alone, settling whatever else was out. */\n @command({ args: [{ key: \"sliceIndex\", kind: \"number\", default: 0, min: 0, step: 1 }] })\n selectOnlySlice(\n args: CommandArgs<{ sliceIndex: number }> & { duration?: number }\n ): Seekable {\n const { sliceIndex: index } = args.data as { sliceIndex: number }\n const duration = args.duration ?? 0.45\n const easing = args.easing ?? easeOut()\n return this.tweenPops((i) => (i === index ? 1 : 0), duration, easing)\n }\n\n /** Settle every slice flush and bring the whole chart back to full. */\n @command()\n clearSelection(\n args: CommandArgs<Record<string, never>> & { duration?: number } = {}\n ): Seekable {\n const duration = args.duration ?? 0.45\n const easing = args.easing ?? easeOut()\n return this.tweenPops(() => 0, duration, easing)\n }\n\n /**\n * Ease every slice's pop from where it is now to what `pop` asks for.\n *\n * Consumes its full duration even when nothing moves: in the studio a\n * command's duration is what the timeline lays out and what its parallel\n * siblings are timed against, so a no-op that took no frames would pull\n * everything after it forward.\n *\n * `from` and the targets are read when the command is *built*, which for a\n * driven scene is with the node in the state its own start time implies — so a\n * select that follows another starts from where that one left the ring.\n */\n private tweenPops(\n pop: (index: number) => number,\n duration: number,\n easing: EasingFunction\n ): Seekable {\n const from = this.data.map((_, i) => this.popAt(i))\n const targets = this.data.map((_, i) => clampUnit(pop(i)))\n if (from.every((value, i) => value === targets[i])) return hold(duration)\n\n return drive(duration, (t) => {\n const e = easing(t)\n this.pops = from.map((value, i) => value + (targets[i] - value) * e)\n })\n }\n}\n"]}
@@ -0,0 +1,60 @@
1
+ import { Rect, type CommandArgs, type NodeConfig, type RectProps } from "@motionscript/core";
2
+ import { type LegendConfig } from "../kit/shared.js";
3
+ import { type Seekable } from "@motionscript/core/component";
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 dims}.
31
+ */
32
+ export declare class PieLegend extends Rect {
33
+ slices: PieSlice[];
34
+ legend: LegendConfig;
35
+ dims: number[];
36
+ /** One entry per slice, ordered top → bottom, for the staggered entrance. */
37
+ private items;
38
+ constructor(props?: NodeConfig<PieLegend, PieLegendProps>);
39
+ /** One entry: the slice's colour swatch beside its caption. */
40
+ private buildItem;
41
+ /**
42
+ * Prime every entry at its pre-entrance state: shifted right and transparent.
43
+ *
44
+ * Idempotent, and separate from {@link enter} so the chart can arm its whole
45
+ * composition before the first frame is drawn — the resting state is the
46
+ * finished legend, so there is nothing hidden to reveal unless a scene asks.
47
+ */
48
+ arm(slide?: number): void;
49
+ /**
50
+ * Slide + fade every entry in from the right, staggered top-to-bottom.
51
+ *
52
+ * `duration` is the **whole** entrance: the stagger is carved out of it rather
53
+ * than added on top, so the command takes exactly the time the timeline laid
54
+ * out for it.
55
+ */
56
+ enter(args: CommandArgs<Record<string, never>> & {
57
+ duration: number;
58
+ }): Seekable;
59
+ }
60
+ //# 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,EAEL,IAAI,EAKJ,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC/E,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,qBAAa,SAAU,SAAQ,IAAI;IACsB,MAAM,EAAE,QAAQ,EAAE,CAAA;IAC1B,MAAM,EAAE,YAAY,CAAA;IACd,IAAI,EAAE,MAAM,EAAE,CAAA;IAEnE,6EAA6E;IAC7E,OAAO,CAAC,KAAK,CAAa;gBAEd,KAAK,CAAC,EAAE,UAAU,CAAC,SAAS,EAAE,cAAc,CAAC;IAmCzD,+DAA+D;IAC/D,OAAO,CAAC,SAAS;IAwBjB;;;;;;OAMG;IACH,GAAG,CAAC,KAAK,SAAQ,GAAG,IAAI;IAIxB;;;;;;OAMG;IAEH,KAAK,CACH,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAC9D,QAAQ;CAkBZ"}