@motionscript/charts 0.1.0 → 0.1.1-alpha.1

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 (215) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +98 -28
  3. package/dist/bar-chart/bar-chart.d.ts +242 -119
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  5. package/dist/bar-chart/bar-chart.js +231 -260
  6. package/dist/bar-chart/bar-chart.js.map +1 -1
  7. package/dist/bar-chart/category-axis.d.ts +16 -38
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  9. package/dist/bar-chart/category-axis.js +59 -68
  10. package/dist/bar-chart/category-axis.js.map +1 -1
  11. package/dist/bar-chart/chart-bars.d.ts +60 -91
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  13. package/dist/bar-chart/chart-bars.js +88 -125
  14. package/dist/bar-chart/chart-bars.js.map +1 -1
  15. package/dist/bar-chart/index.d.ts +5 -13
  16. package/dist/bar-chart/index.d.ts.map +1 -1
  17. package/dist/bar-chart/index.js +2 -9
  18. package/dist/bar-chart/index.js.map +1 -1
  19. package/dist/bar-chart/shared.d.ts +40 -132
  20. package/dist/bar-chart/shared.d.ts.map +1 -1
  21. package/dist/bar-chart/shared.js +70 -158
  22. package/dist/bar-chart/shared.js.map +1 -1
  23. package/dist/browser/chunks/chunk-R3Q5EE6E.js +2 -0
  24. package/dist/browser/chunks/chunk-R3Q5EE6E.js.map +7 -0
  25. package/dist/browser/index.js +1 -1
  26. package/dist/browser/index.js.map +4 -4
  27. package/dist/browser/kit.js +1 -1
  28. package/dist/browser/manifest.json +1 -1
  29. package/dist/engine.d.ts +8 -17
  30. package/dist/engine.d.ts.map +1 -1
  31. package/dist/engine.js +8 -17
  32. package/dist/engine.js.map +1 -1
  33. package/dist/index.d.ts +2 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/kit/cartesian.d.ts +49 -35
  38. package/dist/kit/cartesian.d.ts.map +1 -1
  39. package/dist/kit/cartesian.js +80 -42
  40. package/dist/kit/cartesian.js.map +1 -1
  41. package/dist/kit/chart-canvas.d.ts +37 -40
  42. package/dist/kit/chart-canvas.d.ts.map +1 -1
  43. package/dist/kit/chart-canvas.js +53 -47
  44. package/dist/kit/chart-canvas.js.map +1 -1
  45. package/dist/kit/chart-legend.d.ts +16 -59
  46. package/dist/kit/chart-legend.d.ts.map +1 -1
  47. package/dist/kit/chart-legend.js +38 -76
  48. package/dist/kit/chart-legend.js.map +1 -1
  49. package/dist/kit/entries.d.ts +2 -0
  50. package/dist/kit/entries.d.ts.map +1 -1
  51. package/dist/kit/entries.js +2 -0
  52. package/dist/kit/entries.js.map +1 -1
  53. package/dist/kit/horizontal-axis.d.ts +77 -0
  54. package/dist/kit/horizontal-axis.d.ts.map +1 -0
  55. package/dist/kit/horizontal-axis.js +99 -0
  56. package/dist/kit/horizontal-axis.js.map +1 -0
  57. package/dist/kit/motion.d.ts +16 -3
  58. package/dist/kit/motion.d.ts.map +1 -1
  59. package/dist/kit/motion.js +15 -1
  60. package/dist/kit/motion.js.map +1 -1
  61. package/dist/{pie-chart → kit}/pie-legend.d.ts +14 -29
  62. package/dist/kit/pie-legend.d.ts.map +1 -0
  63. package/dist/kit/pie-legend.js +93 -0
  64. package/dist/kit/pie-legend.js.map +1 -0
  65. package/dist/kit/polar.d.ts +31 -0
  66. package/dist/kit/polar.d.ts.map +1 -0
  67. package/dist/kit/polar.js +33 -0
  68. package/dist/kit/polar.js.map +1 -0
  69. package/dist/kit/shared.d.ts +60 -214
  70. package/dist/kit/shared.d.ts.map +1 -1
  71. package/dist/kit/shared.js +91 -291
  72. package/dist/kit/shared.js.map +1 -1
  73. package/dist/kit/style.d.ts +254 -0
  74. package/dist/kit/style.d.ts.map +1 -0
  75. package/dist/kit/style.js +197 -0
  76. package/dist/kit/style.js.map +1 -0
  77. package/dist/kit/vertical-axis.d.ts +36 -45
  78. package/dist/kit/vertical-axis.d.ts.map +1 -1
  79. package/dist/kit/vertical-axis.js +69 -81
  80. package/dist/kit/vertical-axis.js.map +1 -1
  81. package/dist/line-chart/chart-line.d.ts +107 -40
  82. package/dist/line-chart/chart-line.d.ts.map +1 -1
  83. package/dist/line-chart/chart-line.js +172 -89
  84. package/dist/line-chart/chart-line.js.map +1 -1
  85. package/dist/line-chart/chart-region.d.ts +14 -27
  86. package/dist/line-chart/chart-region.d.ts.map +1 -1
  87. package/dist/line-chart/chart-region.js +13 -28
  88. package/dist/line-chart/chart-region.js.map +1 -1
  89. package/dist/line-chart/index.d.ts +5 -18
  90. package/dist/line-chart/index.d.ts.map +1 -1
  91. package/dist/line-chart/index.js +3 -16
  92. package/dist/line-chart/index.js.map +1 -1
  93. package/dist/line-chart/line-chart.d.ts +272 -119
  94. package/dist/line-chart/line-chart.d.ts.map +1 -1
  95. package/dist/line-chart/line-chart.js +309 -257
  96. package/dist/line-chart/line-chart.js.map +1 -1
  97. package/dist/line-chart/shared.d.ts +73 -130
  98. package/dist/line-chart/shared.d.ts.map +1 -1
  99. package/dist/line-chart/shared.js +195 -156
  100. package/dist/line-chart/shared.js.map +1 -1
  101. package/dist/line-chart/x-scale.d.ts +16 -55
  102. package/dist/line-chart/x-scale.d.ts.map +1 -1
  103. package/dist/line-chart/x-scale.js +44 -111
  104. package/dist/line-chart/x-scale.js.map +1 -1
  105. package/dist/nodes.d.ts +3 -13
  106. package/dist/nodes.d.ts.map +1 -1
  107. package/dist/nodes.js +9 -13
  108. package/dist/nodes.js.map +1 -1
  109. package/dist/pie-chart/index.d.ts +3 -15
  110. package/dist/pie-chart/index.d.ts.map +1 -1
  111. package/dist/pie-chart/index.js +1 -11
  112. package/dist/pie-chart/index.js.map +1 -1
  113. package/dist/pie-chart/pie-chart.d.ts +147 -85
  114. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  115. package/dist/pie-chart/pie-chart.js +65 -86
  116. package/dist/pie-chart/pie-chart.js.map +1 -1
  117. package/dist/pie-chart/pie-ring.d.ts +65 -196
  118. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  119. package/dist/pie-chart/pie-ring.js +154 -292
  120. package/dist/pie-chart/pie-ring.js.map +1 -1
  121. package/dist/pie-chart/shared.d.ts +78 -172
  122. package/dist/pie-chart/shared.d.ts.map +1 -1
  123. package/dist/pie-chart/shared.js +54 -177
  124. package/dist/pie-chart/shared.js.map +1 -1
  125. package/dist/radar-chart/index.d.ts +5 -0
  126. package/dist/radar-chart/index.d.ts.map +1 -0
  127. package/dist/radar-chart/index.js +5 -0
  128. package/dist/radar-chart/index.js.map +1 -0
  129. package/dist/radar-chart/radar-chart.d.ts +218 -0
  130. package/dist/radar-chart/radar-chart.d.ts.map +1 -0
  131. package/dist/radar-chart/radar-chart.js +224 -0
  132. package/dist/radar-chart/radar-chart.js.map +1 -0
  133. package/dist/radar-chart/radar-grid.d.ts +43 -0
  134. package/dist/radar-chart/radar-grid.d.ts.map +1 -0
  135. package/dist/radar-chart/radar-grid.js +61 -0
  136. package/dist/radar-chart/radar-grid.js.map +1 -0
  137. package/dist/radar-chart/radar-series.d.ts +59 -0
  138. package/dist/radar-chart/radar-series.d.ts.map +1 -0
  139. package/dist/radar-chart/radar-series.js +71 -0
  140. package/dist/radar-chart/radar-series.js.map +1 -0
  141. package/dist/radar-chart/shared.d.ts +73 -0
  142. package/dist/radar-chart/shared.d.ts.map +1 -0
  143. package/dist/radar-chart/shared.js +123 -0
  144. package/dist/radar-chart/shared.js.map +1 -0
  145. package/dist/radial-chart/index.d.ts +6 -0
  146. package/dist/radial-chart/index.d.ts.map +1 -0
  147. package/dist/radial-chart/index.js +4 -0
  148. package/dist/radial-chart/index.js.map +1 -0
  149. package/dist/radial-chart/radial-chart.d.ts +216 -0
  150. package/dist/radial-chart/radial-chart.d.ts.map +1 -0
  151. package/dist/radial-chart/radial-chart.js +174 -0
  152. package/dist/radial-chart/radial-chart.js.map +1 -0
  153. package/dist/radial-chart/radial-rings.d.ts +121 -0
  154. package/dist/radial-chart/radial-rings.d.ts.map +1 -0
  155. package/dist/radial-chart/radial-rings.js +273 -0
  156. package/dist/radial-chart/radial-rings.js.map +1 -0
  157. package/dist/radial-chart/shared.d.ts +73 -0
  158. package/dist/radial-chart/shared.d.ts.map +1 -0
  159. package/dist/radial-chart/shared.js +79 -0
  160. package/dist/radial-chart/shared.js.map +1 -0
  161. package/package.json +4 -4
  162. package/registry.json +21 -6
  163. package/src/bar-chart/bar-chart.ts +274 -315
  164. package/src/bar-chart/category-axis.ts +53 -88
  165. package/src/bar-chart/chart-bars.ts +108 -205
  166. package/src/bar-chart/index.ts +8 -19
  167. package/src/bar-chart/shared.ts +81 -309
  168. package/src/engine.ts +8 -17
  169. package/src/index.ts +2 -0
  170. package/src/kit/cartesian.ts +118 -55
  171. package/src/kit/chart-canvas.ts +50 -80
  172. package/src/kit/chart-legend.ts +36 -97
  173. package/src/kit/entries.ts +4 -1
  174. package/src/kit/horizontal-axis.ts +114 -0
  175. package/src/kit/motion.ts +18 -2
  176. package/src/{pie-chart → kit}/pie-legend.ts +25 -65
  177. package/src/kit/polar.ts +54 -0
  178. package/src/kit/shared.ts +104 -487
  179. package/src/kit/style.ts +257 -0
  180. package/src/kit/vertical-axis.ts +81 -115
  181. package/src/line-chart/chart-line.ts +185 -91
  182. package/src/line-chart/chart-region.ts +14 -31
  183. package/src/line-chart/index.ts +14 -22
  184. package/src/line-chart/line-chart.ts +377 -315
  185. package/src/line-chart/shared.ts +229 -304
  186. package/src/line-chart/x-scale.ts +44 -121
  187. package/src/nodes.ts +9 -13
  188. package/src/pie-chart/index.ts +3 -35
  189. package/src/pie-chart/pie-chart.ts +83 -134
  190. package/src/pie-chart/pie-ring.ts +162 -368
  191. package/src/pie-chart/shared.ts +92 -379
  192. package/src/radar-chart/index.ts +4 -0
  193. package/src/radar-chart/radar-chart.ts +287 -0
  194. package/src/radar-chart/radar-grid.ts +78 -0
  195. package/src/radar-chart/radar-series.ts +88 -0
  196. package/src/radar-chart/shared.ts +146 -0
  197. package/src/radial-chart/index.ts +5 -0
  198. package/src/radial-chart/radial-chart.ts +210 -0
  199. package/src/radial-chart/radial-rings.ts +328 -0
  200. package/src/radial-chart/shared.ts +114 -0
  201. package/dist/browser/chunks/chunk-TJNHLQGV.js +0 -2
  202. package/dist/browser/chunks/chunk-TJNHLQGV.js.map +0 -7
  203. package/dist/kit/chart-border.d.ts +0 -27
  204. package/dist/kit/chart-border.d.ts.map +0 -1
  205. package/dist/kit/chart-border.js +0 -28
  206. package/dist/kit/chart-border.js.map +0 -1
  207. package/dist/line-chart/horizontal-axis.d.ts +0 -79
  208. package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
  209. package/dist/line-chart/horizontal-axis.js +0 -129
  210. package/dist/line-chart/horizontal-axis.js.map +0 -1
  211. package/dist/pie-chart/pie-legend.d.ts.map +0 -1
  212. package/dist/pie-chart/pie-legend.js +0 -117
  213. package/dist/pie-chart/pie-legend.js.map +0 -1
  214. package/src/kit/chart-border.ts +0 -50
  215. package/src/line-chart/horizontal-axis.ts +0 -151
@@ -1,146 +1,54 @@
1
- /**
2
- * Types and pure helpers specific to the {@link BarChart} family: how a row's
3
- * values become the spans its columns cover, how the value axis is scaled around
4
- * them, and the theme the bars add to the shared chart vocabulary.
5
- *
6
- * Everything a line or a pie chart would want too — what a series is, the axis
7
- * domain model, the theme leaf resolvers, the legend and plot-panel branches —
8
- * lives in `../kit/shared.ts` and is imported here.
9
- *
10
- * Kept renderer-agnostic (no `Node` imports) so a host's inspector mapping
11
- * can build a partial {@link BarChartTheme} without
12
- * pulling the components in.
13
- */
14
- import { type DataRecord, type Fill, type Shadow, type Stroke, type TextStyle } from "@motionscript/sdk";
15
- import { type AxisConfig, type ChartSeries, type LegendConfig, type LegendTheme, type PlotAreaConfig, type Range } from "../kit/shared.js";
16
- /**
17
- * One series in a {@link BarChart}: a column of the table drawn as one bar per
18
- * row — side by side with its siblings within each category's slot, or stacked
19
- * on top of them.
20
- *
21
- * The family-wide {@link ChartSeries} under a name that says what it draws here.
22
- */
1
+ import { type DataRecord, type Fill } from "@motionscript/sdk";
2
+ import { type ChartSeries, type Range } from "../kit/shared.js";
3
+ /** One bar per row, beside its siblings in the category slot or stacked on them: {@link ChartSeries} under the name for what it draws here. */
23
4
  export type BarSeries = ChartSeries;
5
+ /** How the series share a category: side by side, stacked, or stacked as shares of 100. */
6
+ export type BarStack = "none" | "stacked" | "percent";
7
+ /** Which way the bars grow: up from a category row, or right from a category column. */
8
+ export type BarOrientation = "vertical" | "horizontal";
24
9
  /**
25
- * One drawn bar's span in **data units**: the value its base sits at and the
26
- * value its far end reaches.
27
- *
28
- * A span rather than a height because that is the one shape both modes fit. A
29
- * grouped bar runs from zero to its value; a stacked segment runs from the
30
- * running total below it to that total plus its own value. Negative values fall
31
- * out of the same arithmetic — the span simply runs the other way — so a chart
32
- * with a loss in it needs no special case, only a baseline that isn't the floor.
10
+ * One bar's span in data units. A span rather than a height because every mode
11
+ * fits it, and a negative value just runs the other way with no special case.
33
12
  */
34
13
  export interface BarSpan {
35
- /** Value the bar's base sits at — 0 when grouped, the running total when stacked. */
14
+ /** Where the base sits: 0 apart, the running total below (or above, for a negative) when stacked. */
36
15
  from: number;
37
- /** Value its far end reaches. */
38
16
  to: number;
39
- /** The value this bar plots — `to - from`, kept for the figure printed on it. */
17
+ /** `to - from`. */
40
18
  value: number;
19
+ /** Whether it ends its stack on its side of zero, so its far end is rounded. */
20
+ outer: boolean;
41
21
  }
42
22
  /**
43
- * The spans one row's bars cover, one per series, in series order.
44
- *
45
- * Stacking is a running sum in the order the series are listed, which is also
46
- * the order they're drawn: series 0 sits on the baseline and each later one
47
- * rides on what's below it. A zero-valued series still yields a (degenerate)
48
- * span so the returned list stays index-aligned with the series list.
23
+ * One row's spans, in series order. Stacking keeps a running sum on each side
24
+ * of zero, so a negative value stacks downward from the baseline rather than
25
+ * eating into the positives. In `percent` each value is its share of the row's
26
+ * total magnitude. A zero value still yields a degenerate span, keeping the list
27
+ * index-aligned with the series. `weights` scale each series' contribution.
49
28
  */
50
- export declare function barSpans(row: DataRecord, series: BarSeries[], stacked: boolean): BarSpan[];
51
- /**
52
- * The index of the series whose segment ends a row's stack — the one that gets
53
- * the rounded cap, so a stack reads as one capped column rather than a pile of
54
- * separate boxes. `-1` when every value in the row is zero.
55
- *
56
- * Read off the *last non-zero* series rather than the last one listed, so a
57
- * series that happens to be 0 in this row doesn't take the cap and leave the
58
- * segment below it square.
59
- */
60
- export declare function stackCapIndex(row: DataRecord, series: BarSeries[]): number;
61
- /** The captions beneath the baseline: one per row, read off the category column. */
29
+ export declare function barSpans(row: DataRecord, series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): BarSpan[];
62
30
  export declare function barCategories(data: DataRecord[], field: string): string[];
63
31
  /**
64
- * The `[min, max]` of everything the chart draws, **zero always included**.
65
- *
66
- * Zero is in the range whatever the data says, because a bar chart's baseline is
67
- * zero: a scale starting at 40 draws a column three times its neighbour for a
68
- * 10% difference, which is the classic way to lie with one. A chart that really
69
- * does want a cropped axis says so with an explicit range.
70
- */
71
- export declare function barValueExtent(data: DataRecord[], series: BarSeries[], stacked: boolean): Range;
72
- /**
73
- * Effective value scale: the explicit `range`, else the data's extent nudged out
74
- * to tidy step bounds so the markers read as round numbers.
75
- *
76
- * `divisions` is how many segments the auto-range is stepped into (one fewer
77
- * than the marker count), so the ticks the axis draws land on the bounds this
78
- * picks.
79
- */
80
- export declare function resolveBarScale(data: DataRecord[], series: BarSeries[], stacked: boolean, range: Range | undefined, divisions: number): Range;
81
- /** How the columns themselves are drawn and how the slot is divided up. */
82
- export interface BarStyleConfig {
83
- /**
84
- * Radius of a column's far-end corners, in px. Only the outer end rounds — an
85
- * interior stacked segment stays square, so the stack reads as one column.
86
- */
87
- cornerRadius: number;
88
- /**
89
- * Fraction of its category's slot the bars fill, `[0, 1]`. The remainder is
90
- * the channel between one category and the next, which is what makes a bar
91
- * chart read as groups rather than as a solid block.
92
- */
93
- slotFill: number;
94
- /** Gap between the grouped bars *within* one slot, in px. Ignored when stacked. */
95
- groupGap: number;
96
- /** Optional outline on every column. */
97
- stroke: Stroke;
98
- /** Optional drop shadow on every column. */
99
- shadow: Shadow;
100
- }
101
- /** A {@link BarChart}'s full, resolved visual theme. */
102
- export interface BarChartConfig {
103
- /**
104
- * Default per-series bar paint, cycled by series index (`i % length`). A
105
- * series' own `fill`, when set, replaces its entry outright.
106
- */
107
- seriesFills: Fill[];
108
- bar: BarStyleConfig;
109
- /** The category axis beneath the baseline. */
110
- xAxis: AxisConfig;
111
- /** The numeric value axis up the left. */
112
- yAxis: AxisConfig;
113
- plotArea: PlotAreaConfig;
114
- legend: LegendConfig;
115
- /** The figure printed on each column, when the chart prints them. */
116
- valueStyle: TextStyle;
117
- /** How far everything *outside* a spotlit series or category fades. */
118
- spotlight: {
119
- dimOpacity: number;
120
- };
121
- }
122
- /** Author-facing partial theme — every branch optional and deep-merged. */
123
- export type BarChartTheme = {
124
- seriesFills?: Fill[];
125
- bar?: Partial<BarStyleConfig>;
126
- xAxis?: Partial<AxisConfig>;
127
- yAxis?: Partial<AxisConfig>;
128
- plotArea?: Partial<PlotAreaConfig>;
129
- legend?: LegendTheme;
130
- valueStyle?: TextStyle;
131
- spotlight?: Partial<BarChartConfig["spotlight"]>;
32
+ * The `[min, max]` of everything drawn, zero always included: a scale starting
33
+ * at 40 draws a bar three times its neighbour for a 10% difference. A cropped
34
+ * axis takes an explicit range.
35
+ */
36
+ export declare function barValueExtent(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): Range;
37
+ /** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
38
+ export declare function resolveBarScale(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, range: Range | undefined, divisions: number, weights?: readonly number[]): Range;
39
+ /** Black or white, whichever reads on `fill`: a figure printed inside a bar. */
40
+ export declare function inkOn(fill: Fill): string;
41
+ /** A bar chart's own look: how round and how wide the bars are. */
42
+ export declare const BAR_MARKS: {
43
+ /** Radius of each bar's far corners; a stacked segment inside the stack stays square. */
44
+ barRadius: import("@motionscript/sdk").Type<number, number, false>;
45
+ /** How much of its category slot a bar group fills, the rest spacing the groups. */
46
+ barWidth: import("@motionscript/sdk").Type<number, number, false>;
47
+ /** Space between the bars of one group, side by side. */
48
+ barGap: import("@motionscript/sdk").Type<number, number, false>;
49
+ };
50
+ export declare const BAR_LABELS: {
51
+ /** Read as the chart is built: each bar's value past its end, inside it, or none. */
52
+ values: import("@motionscript/sdk").Type<"end" | "inside" | "none", "end" | "inside" | "none", false>;
132
53
  };
133
- /** The bar chart's out-of-the-box look. */
134
- export declare const DEFAULT_BAR_CHART_THEME: BarChartConfig;
135
- /**
136
- * {@link BarChart}'s `theme` entry's resolve: merges the author's partial
137
- * {@link BarChartTheme} onto `previous` (falling back to
138
- * {@link DEFAULT_BAR_CHART_THEME} on first resolution), fully resolving every
139
- * leaf so the tween below always has resolved data to interpolate.
140
- */
141
- export declare function resolveBarChartTheme(theme: BarChartTheme | undefined, previous?: BarChartConfig): BarChartConfig;
142
- /** {@link BarChart}'s `theme` entry's lerp — leaf by leaf. */
143
- export declare function lerpBarChartTheme(from: BarChartConfig, to: BarChartConfig, t: number): BarChartConfig;
144
- /** The paint series `index` is drawn in: its own override, else the palette's entry. */
145
- export declare function resolveBarFill(palette: Fill[], series: BarSeries, index: number): Fill;
146
54
  //# sourceMappingURL=shared.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAML,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,MAAM,EAEX,KAAK,MAAM,EAEX,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAmBL,KAAK,UAAU,EACf,KAAK,W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,SAAS,MAAM,EAAE,GAAG,KAAK,CAUpI;AAED,2LAA2L;AAC3L,wBAAgB,eAAe,CAC7B,IAAI,EAAE,UAAU,EAAE,EAClB,MAAM,EAAE,SAAS,SAAS,EAAE,EAC5B,KAAK,EAAE,QAAQ,EACf,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,GAC1B,KAAK,CAKP;AAED,gFAAgF;AAChF,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAQxC;AAED,mEAAmE;AACnE,eAAO,MAAM,SAAS;IACpB,yFAAyF;;IAEzF,oFAAoF;;IAEpF,yDAAyD;;CAE1D,CAAA;AAED,eAAO,MAAM,UAAU;IACrB,qFAAqF;;CAEtF,CAAA"}
@@ -1,182 +1,94 @@
1
+ import { Types, fillOps } from "@motionscript/sdk";
2
+ import { niceRange, num, text } from "../kit/shared.js";
1
3
  /**
2
- * Types and pure helpers specific to the {@link BarChart} family: how a row's
3
- * values become the spans its columns cover, how the value axis is scaled around
4
- * them, and the theme the bars add to the shared chart vocabulary.
5
- *
6
- * Everything a line or a pie chart would want too — what a series is, the axis
7
- * domain model, the theme leaf resolvers, the legend and plot-panel branches —
8
- * lives in `../kit/shared.ts` and is imported here.
9
- *
10
- * Kept renderer-agnostic (no `Node` imports) so a host's inspector mapping
11
- * can build a partial {@link BarChartTheme} without
12
- * pulling the components in.
4
+ * One row's spans, in series order. Stacking keeps a running sum on each side
5
+ * of zero, so a negative value stacks downward from the baseline rather than
6
+ * eating into the positives. In `percent` each value is its share of the row's
7
+ * total magnitude. A zero value still yields a degenerate span, keeping the list
8
+ * index-aligned with the series. `weights` scale each series' contribution.
13
9
  */
14
- import { fillOps, lerpNumber, shadowOps, strokeOps, textOps, } from "@motionscript/sdk";
15
- import { CHART_PALETTE, DEFAULT_LEGEND, DEFAULT_PLOT_AREA, DEFAULT_SERIES_FILLS, DEFAULT_X_AXIS, DEFAULT_Y_AXIS, SPOTLIGHT_DIM, lerpAxisConfig, lerpLegendConfig, lerpPlotArea, lerpSeriesFills, niceStep, num, resolveAxisConfig, resolveLegendConfig, resolvePlotArea, resolveSeriesFills, text, } from "../kit/shared.js";
16
- /**
17
- * The spans one row's bars cover, one per series, in series order.
18
- *
19
- * Stacking is a running sum in the order the series are listed, which is also
20
- * the order they're drawn: series 0 sits on the baseline and each later one
21
- * rides on what's below it. A zero-valued series still yields a (degenerate)
22
- * span so the returned list stays index-aligned with the series list.
23
- */
24
- export function barSpans(row, series, stacked) {
25
- let running = 0;
26
- return series.map((s) => {
27
- const value = num(row, s.field);
28
- if (!stacked)
29
- return { from: 0, to: value, value };
30
- const from = running;
31
- running += value;
32
- return { from, to: running, value };
33
- });
34
- }
35
- /**
36
- * The index of the series whose segment ends a row's stack — the one that gets
37
- * the rounded cap, so a stack reads as one capped column rather than a pile of
38
- * separate boxes. `-1` when every value in the row is zero.
39
- *
40
- * Read off the *last non-zero* series rather than the last one listed, so a
41
- * series that happens to be 0 in this row doesn't take the cap and leave the
42
- * segment below it square.
43
- */
44
- export function stackCapIndex(row, series) {
45
- let last = -1;
46
- for (let i = 0; i < series.length; i++) {
47
- if (num(row, series[i].field) !== 0)
48
- last = i;
10
+ export function barSpans(row, series, stack, weights = []) {
11
+ const weight = (i) => Math.max(0, weights[i] ?? 1);
12
+ if (stack !== "stacked" && stack !== "percent") {
13
+ return series.map((s) => {
14
+ const value = num(row, s.field);
15
+ return { from: 0, to: value, value, outer: true };
16
+ });
49
17
  }
50
- return last;
18
+ const values = series.map((s, i) => num(row, s.field) * weight(i));
19
+ const total = values.reduce((sum, v) => sum + Math.abs(v), 0);
20
+ const scaled = stack === "percent" ? values.map((v) => (total > 0 ? (v / total) * 100 : 0)) : values;
21
+ let lastUp = -1;
22
+ let lastDown = -1;
23
+ scaled.forEach((v, i) => {
24
+ if (v > 0)
25
+ lastUp = i;
26
+ else if (v < 0)
27
+ lastDown = i;
28
+ });
29
+ let up = 0;
30
+ let down = 0;
31
+ return scaled.map((value, i) => {
32
+ if (value < 0) {
33
+ const from = down;
34
+ down += value;
35
+ return { from, to: down, value, outer: i === lastDown };
36
+ }
37
+ const from = up;
38
+ up += value;
39
+ return { from, to: up, value, outer: i === lastUp };
40
+ });
51
41
  }
52
- /** The captions beneath the baseline: one per row, read off the category column. */
53
42
  export function barCategories(data, field) {
54
43
  return data.map((row) => text(row, field));
55
44
  }
56
45
  /**
57
- * The `[min, max]` of everything the chart draws, **zero always included**.
58
- *
59
- * Zero is in the range whatever the data says, because a bar chart's baseline is
60
- * zero: a scale starting at 40 draws a column three times its neighbour for a
61
- * 10% difference, which is the classic way to lie with one. A chart that really
62
- * does want a cropped axis says so with an explicit range.
46
+ * The `[min, max]` of everything drawn, zero always included: a scale starting
47
+ * at 40 draws a bar three times its neighbour for a 10% difference. A cropped
48
+ * axis takes an explicit range.
63
49
  */
64
- export function barValueExtent(data, series, stacked) {
50
+ export function barValueExtent(data, series, stack, weights) {
65
51
  let lo = 0;
66
52
  let hi = 0;
67
53
  for (const row of data) {
68
- for (const span of barSpans(row, series, stacked)) {
54
+ for (const span of barSpans(row, series, stack, weights)) {
69
55
  lo = Math.min(lo, span.from, span.to);
70
56
  hi = Math.max(hi, span.from, span.to);
71
57
  }
72
58
  }
73
59
  return lo < hi ? [lo, hi] : [0, 1];
74
60
  }
75
- /**
76
- * Effective value scale: the explicit `range`, else the data's extent nudged out
77
- * to tidy step bounds so the markers read as round numbers.
78
- *
79
- * `divisions` is how many segments the auto-range is stepped into (one fewer
80
- * than the marker count), so the ticks the axis draws land on the bounds this
81
- * picks.
82
- */
83
- export function resolveBarScale(data, series, stacked, range, divisions) {
61
+ /** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
62
+ export function resolveBarScale(data, series, stack, range, divisions, weights) {
84
63
  if (range)
85
64
  return range;
86
- const [lo, hi] = barValueExtent(data, series, stacked);
87
- const segments = Math.max(1, Math.round(divisions));
88
- const step = niceStep((hi - lo) / segments || 1);
89
- return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step];
90
- }
91
- /** The bar chart's out-of-the-box look. */
92
- export const DEFAULT_BAR_CHART_THEME = {
93
- seriesFills: DEFAULT_SERIES_FILLS,
94
- bar: {
95
- cornerRadius: 6,
96
- slotFill: 0.72,
97
- groupGap: 6,
98
- stroke: [],
99
- shadow: [],
100
- },
101
- // A category axis names its slots, so its captions are set like a caption
102
- // rather than like a numeric marker: same size, less weight than the line
103
- // chart's ticks, and centred on the slot.
104
- xAxis: {
105
- ...DEFAULT_X_AXIS,
106
- labelStyle: { ...DEFAULT_X_AXIS.labelStyle, fontWeight: 600 },
107
- tickPadding: 16,
108
- },
109
- yAxis: DEFAULT_Y_AXIS,
110
- plotArea: DEFAULT_PLOT_AREA,
111
- legend: DEFAULT_LEGEND,
112
- valueStyle: {
113
- fontSize: 24,
114
- fontWeight: 700,
115
- textAlign: "center",
116
- fill: CHART_PALETTE.markerColor,
117
- },
118
- spotlight: { dimOpacity: SPOTLIGHT_DIM },
119
- };
120
- function resolveBarStyle(bar, previous) {
121
- return {
122
- cornerRadius: bar?.cornerRadius ?? previous.cornerRadius,
123
- slotFill: bar?.slotFill ?? previous.slotFill,
124
- groupGap: bar?.groupGap ?? previous.groupGap,
125
- stroke: strokeOps.resolve(bar?.stroke ?? previous.stroke),
126
- shadow: shadowOps.resolve(bar?.shadow ?? previous.shadow),
127
- };
128
- }
129
- function lerpBarStyle(from, to, t) {
130
- return {
131
- cornerRadius: lerpNumber(from.cornerRadius, to.cornerRadius, t),
132
- slotFill: lerpNumber(from.slotFill, to.slotFill, t),
133
- groupGap: lerpNumber(from.groupGap, to.groupGap, t),
134
- stroke: strokeOps.lerp(from.stroke, to.stroke, t),
135
- shadow: shadowOps.lerp(from.shadow, to.shadow, t),
136
- };
137
- }
138
- /**
139
- * {@link BarChart}'s `theme` entry's resolve: merges the author's partial
140
- * {@link BarChartTheme} onto `previous` (falling back to
141
- * {@link DEFAULT_BAR_CHART_THEME} on first resolution), fully resolving every
142
- * leaf so the tween below always has resolved data to interpolate.
143
- */
144
- export function resolveBarChartTheme(theme, previous) {
145
- const base = previous ?? DEFAULT_BAR_CHART_THEME;
146
- return {
147
- seriesFills: resolveSeriesFills(theme?.seriesFills, base.seriesFills),
148
- bar: resolveBarStyle(theme?.bar, base.bar),
149
- xAxis: resolveAxisConfig(theme?.xAxis, base.xAxis),
150
- yAxis: resolveAxisConfig(theme?.yAxis, base.yAxis),
151
- plotArea: resolvePlotArea(theme?.plotArea, base.plotArea),
152
- legend: resolveLegendConfig(theme?.legend, base.legend),
153
- valueStyle: textOps.resolveStyle(theme?.valueStyle, base.valueStyle),
154
- spotlight: {
155
- dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,
156
- },
157
- };
158
- }
159
- /** {@link BarChart}'s `theme` entry's lerp — leaf by leaf. */
160
- export function lerpBarChartTheme(from, to, t) {
161
- return {
162
- seriesFills: lerpSeriesFills(from.seriesFills, to.seriesFills, t),
163
- bar: lerpBarStyle(from.bar, to.bar, t),
164
- xAxis: lerpAxisConfig(from.xAxis, to.xAxis, t),
165
- yAxis: lerpAxisConfig(from.yAxis, to.yAxis, t),
166
- plotArea: lerpPlotArea(from.plotArea, to.plotArea, t),
167
- legend: lerpLegendConfig(from.legend, to.legend, t),
168
- valueStyle: textOps.lerpStyle(from.valueStyle, to.valueStyle, t),
169
- spotlight: {
170
- dimOpacity: lerpNumber(from.spotlight.dimOpacity, to.spotlight.dimOpacity, t),
171
- },
172
- };
65
+ const [lo, hi] = barValueExtent(data, series, stack, weights);
66
+ if (stack === "percent")
67
+ return [lo < 0 ? -100 : 0, hi > 0 ? 100 : 0];
68
+ return niceRange([lo, hi], divisions);
173
69
  }
174
- /** The paint series `index` is drawn in: its own override, else the palette's entry. */
175
- export function resolveBarFill(palette, series, index) {
176
- if (series.fill != null)
177
- return fillOps.resolve(series.fill);
178
- if (palette.length === 0)
70
+ /** Black or white, whichever reads on `fill`: a figure printed inside a bar. */
71
+ export function inkOn(fill) {
72
+ const layers = fillOps.resolve(fill);
73
+ const top = layers[layers.length - 1];
74
+ if (top?.type !== "solid")
179
75
  return "white";
180
- return palette[index % palette.length];
76
+ const [r, g, b] = top.color;
77
+ const lift = (c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);
78
+ const luminance = 0.2126 * lift(r) + 0.7152 * lift(g) + 0.0722 * lift(b);
79
+ return luminance > 0.4 ? "#0a0a0a" : "white";
181
80
  }
81
+ /** A bar chart's own look: how round and how wide the bars are. */
82
+ export const BAR_MARKS = {
83
+ /** Radius of each bar's far corners; a stacked segment inside the stack stays square. */
84
+ barRadius: Types.number(10, { min: 0, max: 64, step: 1, unit: "px" }),
85
+ /** How much of its category slot a bar group fills, the rest spacing the groups. */
86
+ barWidth: Types.number(0.7, { min: 0.05, max: 1, step: 0.05 }),
87
+ /** Space between the bars of one group, side by side. */
88
+ barGap: Types.number(6, { min: 0, max: 40, step: 1, unit: "px" }),
89
+ };
90
+ export const BAR_LABELS = {
91
+ /** Read as the chart is built: each bar's value past its end, inside it, or none. */
92
+ values: Types.oneOf(["none", "end", "inside"], { animatable: false }),
93
+ };
182
94
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/bar-chart/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,SAAS,EACT,OAAO,GAQR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,GAAG,EACH,iBAAiB,EACjB,mBAAmB,EACnB,e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AO,CAAA;IACxC,OAAO,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AACxC,CAAC","sourcesContent":["/**\n * Types and pure helpers specific to the {@link BarChart} family: how a row's\n * values become the spans its columns cover, how the value axis is scaled around\n * them, and the theme the bars add to the shared chart vocabulary.\n *\n * Everything a line or a pie chart would want too — what a series is, the axis\n * domain model, the theme leaf resolvers, the legend and plot-panel branches —\n * lives in `../kit/shared.ts` and is imported here.\n *\n * Kept renderer-agnostic (no `Node` imports) so a host's inspector mapping\n * can build a partial {@link BarChartTheme} without\n * pulling the components in.\n */\n\nimport {\n fillOps,\n lerpNumber,\n shadowOps,\n strokeOps,\n textOps,\n type DataRecord,\n type Fill,\n type Shadow,\n type ShadowResolved,\n type Stroke,\n type StrokeResolved,\n type TextStyle,\n} from \"@motionscript/sdk\"\n\nimport {\n CHART_PALETTE,\n DEFAULT_LEGEND,\n DEFAULT_PLOT_AREA,\n DEFAULT_SERIES_FILLS,\n DEFAULT_X_AXIS,\n DEFAULT_Y_AXIS,\n SPOTLIGHT_DIM,\n lerpAxisConfig,\n lerpLegendConfig,\n lerpPlotArea,\n lerpSeriesFills,\n niceStep,\n num,\n resolveAxisConfig,\n resolveLegendConfig,\n resolvePlotArea,\n resolveSeriesFills,\n text,\n type AxisConfig,\n type ChartSeries,\n type LegendConfig,\n type LegendTheme,\n type PlotAreaConfig,\n type Range,\n} from \"../kit/shared\"\n\n/**\n * One series in a {@link BarChart}: a column of the table drawn as one bar per\n * row — side by side with its siblings within each category's slot, or stacked\n * on top of them.\n *\n * The family-wide {@link ChartSeries} under a name that says what it draws here.\n */\nexport type BarSeries = ChartSeries\n\n/**\n * One drawn bar's span in **data units**: the value its base sits at and the\n * value its far end reaches.\n *\n * A span rather than a height because that is the one shape both modes fit. A\n * grouped bar runs from zero to its value; a stacked segment runs from the\n * running total below it to that total plus its own value. Negative values fall\n * out of the same arithmetic — the span simply runs the other way — so a chart\n * with a loss in it needs no special case, only a baseline that isn't the floor.\n */\nexport interface BarSpan {\n /** Value the bar's base sits at — 0 when grouped, the running total when stacked. */\n from: number\n /** Value its far end reaches. */\n to: number\n /** The value this bar plots — `to - from`, kept for the figure printed on it. */\n value: number\n}\n\n/**\n * The spans one row's bars cover, one per series, in series order.\n *\n * Stacking is a running sum in the order the series are listed, which is also\n * the order they're drawn: series 0 sits on the baseline and each later one\n * rides on what's below it. A zero-valued series still yields a (degenerate)\n * span so the returned list stays index-aligned with the series list.\n */\nexport function barSpans(\n row: DataRecord,\n series: BarSeries[],\n stacked: boolean\n): BarSpan[] {\n let running = 0\n return series.map((s) => {\n const value = num(row, s.field)\n if (!stacked) return { from: 0, to: value, value }\n const from = running\n running += value\n return { from, to: running, value }\n })\n}\n\n/**\n * The index of the series whose segment ends a row's stack — the one that gets\n * the rounded cap, so a stack reads as one capped column rather than a pile of\n * separate boxes. `-1` when every value in the row is zero.\n *\n * Read off the *last non-zero* series rather than the last one listed, so a\n * series that happens to be 0 in this row doesn't take the cap and leave the\n * segment below it square.\n */\nexport function stackCapIndex(row: DataRecord, series: BarSeries[]): number {\n let last = -1\n for (let i = 0; i < series.length; i++) {\n if (num(row, series[i].field) !== 0) last = i\n }\n return last\n}\n\n/** The captions beneath the baseline: one per row, read off the category column. */\nexport function barCategories(data: DataRecord[], field: string): string[] {\n return data.map((row) => text(row, field))\n}\n\n/**\n * The `[min, max]` of everything the chart draws, **zero always included**.\n *\n * Zero is in the range whatever the data says, because a bar chart's baseline is\n * zero: a scale starting at 40 draws a column three times its neighbour for a\n * 10% difference, which is the classic way to lie with one. A chart that really\n * does want a cropped axis says so with an explicit range.\n */\nexport function barValueExtent(\n data: DataRecord[],\n series: BarSeries[],\n stacked: boolean\n): Range {\n let lo = 0\n let hi = 0\n for (const row of data) {\n for (const span of barSpans(row, series, stacked)) {\n lo = Math.min(lo, span.from, span.to)\n hi = Math.max(hi, span.from, span.to)\n }\n }\n return lo < hi ? [lo, hi] : [0, 1]\n}\n\n/**\n * Effective value scale: the explicit `range`, else the data's extent nudged out\n * to tidy step bounds so the markers read as round numbers.\n *\n * `divisions` is how many segments the auto-range is stepped into (one fewer\n * than the marker count), so the ticks the axis draws land on the bounds this\n * picks.\n */\nexport function resolveBarScale(\n data: DataRecord[],\n series: BarSeries[],\n stacked: boolean,\n range: Range | undefined,\n divisions: number\n): Range {\n if (range) return range\n const [lo, hi] = barValueExtent(data, series, stacked)\n const segments = Math.max(1, Math.round(divisions))\n const step = niceStep((hi - lo) / segments || 1)\n return [Math.floor(lo / step) * step, Math.ceil(hi / step) * step]\n}\n\n// ---- Theme ---------------------------------------------------------------\n\n/** How the columns themselves are drawn and how the slot is divided up. */\nexport interface BarStyleConfig {\n /**\n * Radius of a column's far-end corners, in px. Only the outer end rounds — an\n * interior stacked segment stays square, so the stack reads as one column.\n */\n cornerRadius: number\n /**\n * Fraction of its category's slot the bars fill, `[0, 1]`. The remainder is\n * the channel between one category and the next, which is what makes a bar\n * chart read as groups rather than as a solid block.\n */\n slotFill: number\n /** Gap between the grouped bars *within* one slot, in px. Ignored when stacked. */\n groupGap: number\n /** Optional outline on every column. */\n stroke: Stroke\n /** Optional drop shadow on every column. */\n shadow: Shadow\n}\n\n/** A {@link BarChart}'s full, resolved visual theme. */\nexport interface BarChartConfig {\n /**\n * Default per-series bar paint, cycled by series index (`i % length`). A\n * series' own `fill`, when set, replaces its entry outright.\n */\n seriesFills: Fill[]\n bar: BarStyleConfig\n /** The category axis beneath the baseline. */\n xAxis: AxisConfig\n /** The numeric value axis up the left. */\n yAxis: AxisConfig\n plotArea: PlotAreaConfig\n legend: LegendConfig\n /** The figure printed on each column, when the chart prints them. */\n valueStyle: TextStyle\n /** How far everything *outside* a spotlit series or category fades. */\n spotlight: { dimOpacity: number }\n}\n\n/** Author-facing partial theme — every branch optional and deep-merged. */\nexport type BarChartTheme = {\n seriesFills?: Fill[]\n bar?: Partial<BarStyleConfig>\n xAxis?: Partial<AxisConfig>\n yAxis?: Partial<AxisConfig>\n plotArea?: Partial<PlotAreaConfig>\n legend?: LegendTheme\n valueStyle?: TextStyle\n spotlight?: Partial<BarChartConfig[\"spotlight\"]>\n}\n\n/** The bar chart's out-of-the-box look. */\nexport const DEFAULT_BAR_CHART_THEME: BarChartConfig = {\n seriesFills: DEFAULT_SERIES_FILLS,\n bar: {\n cornerRadius: 6,\n slotFill: 0.72,\n groupGap: 6,\n stroke: [],\n shadow: [],\n },\n // A category axis names its slots, so its captions are set like a caption\n // rather than like a numeric marker: same size, less weight than the line\n // chart's ticks, and centred on the slot.\n xAxis: {\n ...DEFAULT_X_AXIS,\n labelStyle: { ...DEFAULT_X_AXIS.labelStyle, fontWeight: 600 },\n tickPadding: 16,\n },\n yAxis: DEFAULT_Y_AXIS,\n plotArea: DEFAULT_PLOT_AREA,\n legend: DEFAULT_LEGEND,\n valueStyle: {\n fontSize: 24,\n fontWeight: 700,\n textAlign: \"center\",\n fill: CHART_PALETTE.markerColor,\n },\n spotlight: { dimOpacity: SPOTLIGHT_DIM },\n}\n\nfunction resolveBarStyle(\n bar: Partial<BarStyleConfig> | undefined,\n previous: BarStyleConfig\n): BarStyleConfig {\n return {\n cornerRadius: bar?.cornerRadius ?? previous.cornerRadius,\n slotFill: bar?.slotFill ?? previous.slotFill,\n groupGap: bar?.groupGap ?? previous.groupGap,\n stroke: strokeOps.resolve(bar?.stroke ?? previous.stroke),\n shadow: shadowOps.resolve(bar?.shadow ?? previous.shadow),\n }\n}\n\nfunction lerpBarStyle(\n from: BarStyleConfig,\n to: BarStyleConfig,\n t: number\n): BarStyleConfig {\n return {\n cornerRadius: lerpNumber(from.cornerRadius, to.cornerRadius, t),\n slotFill: lerpNumber(from.slotFill, to.slotFill, t),\n groupGap: lerpNumber(from.groupGap, to.groupGap, t),\n stroke: strokeOps.lerp(\n from.stroke as StrokeResolved[],\n to.stroke as StrokeResolved[],\n t\n ),\n shadow: shadowOps.lerp(\n from.shadow as ShadowResolved[],\n to.shadow as ShadowResolved[],\n t\n ),\n }\n}\n\n/**\n * {@link BarChart}'s `theme` entry's resolve: merges the author's partial\n * {@link BarChartTheme} onto `previous` (falling back to\n * {@link DEFAULT_BAR_CHART_THEME} on first resolution), fully resolving every\n * leaf so the tween below always has resolved data to interpolate.\n */\nexport function resolveBarChartTheme(\n theme: BarChartTheme | undefined,\n previous?: BarChartConfig\n): BarChartConfig {\n const base = previous ?? DEFAULT_BAR_CHART_THEME\n return {\n seriesFills: resolveSeriesFills(theme?.seriesFills, base.seriesFills),\n bar: resolveBarStyle(theme?.bar, base.bar),\n xAxis: resolveAxisConfig(theme?.xAxis, base.xAxis),\n yAxis: resolveAxisConfig(theme?.yAxis, base.yAxis),\n plotArea: resolvePlotArea(theme?.plotArea, base.plotArea),\n legend: resolveLegendConfig(theme?.legend, base.legend),\n valueStyle: textOps.resolveStyle(theme?.valueStyle, base.valueStyle),\n spotlight: {\n dimOpacity: theme?.spotlight?.dimOpacity ?? base.spotlight.dimOpacity,\n },\n }\n}\n\n/** {@link BarChart}'s `theme` entry's lerp — leaf by leaf. */\nexport function lerpBarChartTheme(\n from: BarChartConfig,\n to: BarChartConfig,\n t: number\n): BarChartConfig {\n return {\n seriesFills: lerpSeriesFills(from.seriesFills, to.seriesFills, t),\n bar: lerpBarStyle(from.bar, to.bar, t),\n xAxis: lerpAxisConfig(from.xAxis, to.xAxis, t),\n yAxis: lerpAxisConfig(from.yAxis, to.yAxis, t),\n plotArea: lerpPlotArea(from.plotArea, to.plotArea, t),\n legend: lerpLegendConfig(from.legend, to.legend, t),\n valueStyle: textOps.lerpStyle(from.valueStyle, to.valueStyle, t),\n spotlight: {\n dimOpacity: lerpNumber(\n from.spotlight.dimOpacity,\n to.spotlight.dimOpacity,\n t\n ),\n },\n }\n}\n\n/** The paint series `index` is drawn in: its own override, else the palette's entry. */\nexport function resolveBarFill(\n palette: Fill[],\n series: BarSeries,\n index: number\n): Fill {\n if (series.fill != null) return fillOps.resolve(series.fill)\n if (palette.length === 0) return \"white\"\n return palette[index % palette.length]\n}\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AAyD;IACzD,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;CAClE,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,qFAAqF;IACrF,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAU,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;CAC/E,CAAA","sourcesContent":["import { Types, fillOps, type DataRecord, type Fill } from \"@motionscript/sdk\"\n\nimport { niceRange, num, text, type ChartSeries, type Range } from \"../kit/shared\"\n\n/** One bar per row, beside its siblings in the category slot or stacked on them: {@link ChartSeries} under the name for what it draws here. */\nexport type BarSeries = ChartSeries\n\n/** How the series share a category: side by side, stacked, or stacked as shares of 100. */\nexport type BarStack = \"none\" | \"stacked\" | \"percent\"\n\n/** Which way the bars grow: up from a category row, or right from a category column. */\nexport type BarOrientation = \"vertical\" | \"horizontal\"\n\n/**\n * One bar's span in data units. A span rather than a height because every mode\n * fits it, and a negative value just runs the other way with no special case.\n */\nexport interface BarSpan {\n /** Where the base sits: 0 apart, the running total below (or above, for a negative) when stacked. */\n from: number\n to: number\n /** `to - from`. */\n value: number\n /** Whether it ends its stack on its side of zero, so its far end is rounded. */\n outer: boolean\n}\n\n/**\n * One row's spans, in series order. Stacking keeps a running sum on each side\n * of zero, so a negative value stacks downward from the baseline rather than\n * eating into the positives. In `percent` each value is its share of the row's\n * total magnitude. A zero value still yields a degenerate span, keeping the list\n * index-aligned with the series. `weights` scale each series' contribution.\n */\nexport function barSpans(row: DataRecord, series: readonly BarSeries[], stack: BarStack, weights: readonly number[] = []): BarSpan[] {\n const weight = (i: number) => Math.max(0, weights[i] ?? 1)\n if (stack !== \"stacked\" && stack !== \"percent\") {\n return series.map((s) => {\n const value = num(row, s.field)\n return { from: 0, to: value, value, outer: true }\n })\n }\n const values = series.map((s, i) => num(row, s.field) * weight(i))\n const total = values.reduce((sum, v) => sum + Math.abs(v), 0)\n const scaled = stack === \"percent\" ? values.map((v) => (total > 0 ? (v / total) * 100 : 0)) : values\n let lastUp = -1\n let lastDown = -1\n scaled.forEach((v, i) => {\n if (v > 0) lastUp = i\n else if (v < 0) lastDown = i\n })\n let up = 0\n let down = 0\n return scaled.map((value, i) => {\n if (value < 0) {\n const from = down\n down += value\n return { from, to: down, value, outer: i === lastDown }\n }\n const from = up\n up += value\n return { from, to: up, value, outer: i === lastUp }\n })\n}\n\nexport function barCategories(data: DataRecord[], field: string): string[] {\n return data.map((row) => text(row, field))\n}\n\n/**\n * The `[min, max]` of everything drawn, zero always included: a scale starting\n * at 40 draws a bar three times its neighbour for a 10% difference. A cropped\n * axis takes an explicit range.\n */\nexport function barValueExtent(data: DataRecord[], series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): Range {\n let lo = 0\n let hi = 0\n for (const row of data) {\n for (const span of barSpans(row, series, stack, weights)) {\n lo = Math.min(lo, span.from, span.to)\n hi = Math.max(hi, span.from, span.to)\n }\n }\n return lo < hi ? [lo, hi] : [0, 1]\n}\n\n/** The explicit `range`, else the data's extent nudged to tidy bounds (a percent stack reads to 100); `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */\nexport function resolveBarScale(\n data: DataRecord[],\n series: readonly BarSeries[],\n stack: BarStack,\n range: Range | undefined,\n divisions: number,\n weights?: readonly number[]\n): Range {\n if (range) return range\n const [lo, hi] = barValueExtent(data, series, stack, weights)\n if (stack === \"percent\") return [lo < 0 ? -100 : 0, hi > 0 ? 100 : 0]\n return niceRange([lo, hi], divisions)\n}\n\n/** Black or white, whichever reads on `fill`: a figure printed inside a bar. */\nexport function inkOn(fill: Fill): string {\n const layers = fillOps.resolve(fill)\n const top = layers[layers.length - 1]\n if (top?.type !== \"solid\") return \"white\"\n const [r, g, b] = top.color\n const lift = (c: number) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4)\n const luminance = 0.2126 * lift(r) + 0.7152 * lift(g) + 0.0722 * lift(b)\n return luminance > 0.4 ? \"#0a0a0a\" : \"white\"\n}\n\n/** A bar chart's own look: how round and how wide the bars are. */\nexport const BAR_MARKS = {\n /** Radius of each bar's far corners; a stacked segment inside the stack stays square. */\n barRadius: Types.number(10, { min: 0, max: 64, step: 1, unit: \"px\" }),\n /** How much of its category slot a bar group fills, the rest spacing the groups. */\n barWidth: Types.number(0.7, { min: 0.05, max: 1, step: 0.05 }),\n /** Space between the bars of one group, side by side. */\n barGap: Types.number(6, { min: 0, max: 40, step: 1, unit: \"px\" }),\n}\n\nexport const BAR_LABELS = {\n /** Read as the chart is built: each bar's value past its end, inside it, or none. */\n values: Types.oneOf([\"none\", \"end\", \"inside\"] as const, { animatable: false }),\n}\n"]}
@@ -0,0 +1,2 @@
1
+ import{lerpNumber as O}from"@motionscript/sdk";import{niceStep as C}from"@motionscript/sdk/component";function se(t,e){return{label:t?.label??e?.label??"",range:t?.range??e?.range,ticks:t?.ticks??e?.ticks,format:t?.format??e?.format}}function D(t,e,r){return{label:r<.5?t.label:e.label,range:Et(t.range,e.range,r),ticks:Tt(t.ticks,e.ticks,r),format:r<.5?t.format:e.format}}function Et(t,e,r){return!t||!e?r<.5?t:e:[O(t[0],e[0],r),O(t[1],e[1],r)]}function Tt(t,e,r){if(!t||!e)return r<.5?t:e;let n=Math.max(t.length,e.length),o=[];for(let i=0;i<n;i++)o.push(O(t[i]??e[i],e[i]??t[i],r));return o}function q(t){return t.blend}function ce(t,e,r){let n=e.range!==t.range,o=n&&e.range&&e.ticks&&e.ticks===t.ticks?{...e,ticks:I(e.range,Math.max(2,e.ticks.length)-1)}:e,i=q(t)!==void 0,a=i||n||o.ticks!==t.ticks,l=i||t.range===void 0||t.ticks===void 0||o.range===void 0||o.ticks===void 0;return!a||!l?D(t,o,r):r===0?t:r===1?o:{...D(t,o,r),blend:{from:t,to:o,t:r}}}function V(t,e){let r=q(t);return r?D(V(r.from,e),V(r.to,e),r.t):e(t)}var z={plotFill:"#15130e",borderColor:"#4a4036",gridColor:"#2c2820",markerColor:"#8a7f70",regionColor:"#d99a3a"},K=.2;function fe(t,e){if(e===void 0)return 0;let r=t[e];return typeof r=="number"&&Number.isFinite(r)?r:0}function de(t,e){if(e===void 0||e==="")return"";let r=t[e];return r==null?"":String(r)}function he(t,e=[]){if(t.length===0)return[];let r=new Set(e),n=new Set,o=[];for(let i of t)for(let a of Object.keys(i))!r.has(a)&&!n.has(a)&&(n.add(a),o.push(a));return o.filter(i=>{let a=!1;for(let l of t){let f=l[i];if(!(f===void 0||f==="")){if(typeof f!="number")return!1;a=!0}}return a})}var J={fontSize:24,fontWeight:700,textAlign:"center",fill:z.markerColor},Q={fontSize:30,fontWeight:600,textAlign:"center",fill:z.markerColor},Z={weight:2,fill:z.gridColor},tt={labelStyle:J,titleStyle:Q,lineStyle:Z,tickPadding:20,titlePadding:4},et={labelStyle:{...J,fontWeight:500,textAlign:"right"},titleStyle:Q,lineStyle:Z,tickPadding:40,titlePadding:24},_={padding:0,textStyle:{fontSize:30,fontWeight:600,textAlign:"left",fill:z.markerColor},itemGap:44,markerStyle:{width:60,height:24,borderRadius:6,stroke:[],shadow:[]}};function rt(t,e){if(Number.isInteger(t))return String(t);let r=Math.max(1,e===void 0?1:zt(e));return t.toFixed(r).replace(/(\.\d*?)0+$/,"$1").replace(/\.$/,"")}function zt(t){if(!(t>0)||!Number.isFinite(t))return 1;for(let e=0;e<=6;e++){let r=t*10**e;if(Math.abs(r-Math.round(r))<1e-6*Math.max(1,r))return e}return Math.min(6,Math.max(1,Math.ceil(-Math.log10(t))+1))}function ue(t){let e=[...t].filter(Number.isFinite).sort((n,o)=>n-o),r;for(let n=1;n<e.length;n++){let o=e[n]-e[n-1];o>1e-12&&(r===void 0||o<r)&&(r=o)}return r}function ge(t){let e=t*100;return Number.isInteger(e)?`${e}%`:`${e.toFixed(1).replace(/\.0$/,"")}%`}function I([t,e],r){let n=Math.max(2,Math.round(r));return Array.from({length:n+1},(o,i)=>t+(e-t)/n*i)}function pe([t,e],r){let n=Math.max(1,Math.round(r));if(e===t)return _t(t,n);let o=C((e-t)/n);return[Math.floor(t/o)*o,Math.ceil(e/o)*o]}function _t(t,e){if(t===0)return[0,1];let r=C(Math.abs(t)/e);return[t-r,t+r]}function me([t,e],r){let n=e-t,o=Math.max(1,Math.round(r));if(!(n>0))return I([t,e],o);let i=c=>Math.abs(c-Math.round(c))<1e-6,a=C(n/o),l;for(let c of Lt(a)){let s=n/c;!i(s)||!i(t/c)||s<2||s>8||(l===void 0||Math.abs(s-o)<Math.abs(n/l-o))&&(l=c)}if(l===void 0)return I([t,e],o);let f=Math.round(t/l);return Array.from({length:Math.round(n/l)+1},(c,s)=>Number(((f+s)*l).toPrecision(12)))}function Lt(t){let e=10**Math.floor(Math.log10(t)),r=[];for(let o of[e/10,e,e*10])for(let i of[1,2,5])r.push(i*o);let n=r.findIndex(o=>Math.abs(o-t)<t*1e-9);return r.slice(Math.max(0,n-2),n+3)}import{Types as h}from"@motionscript/sdk";var ke="chart",nt=["#4f8cff","#2fbf8f","#f5a524","#e5547a","#9b6cf0"],be={palette:h.palette(nt),foreground:h.fill("#f4f4f5"),muted:h.fill("#a1a1aa"),background:h.fill([])},Se={fontFamily:h.font(""),fontSize:h.number(28,{min:8,max:160,step:1,unit:"px"}),fontWeight:h.number(500,{min:100,max:900,step:100})},Gt={horizontalGrid:h.stroke({weight:2,fill:"white/15"}),verticalGrid:h.stroke([]),axisStroke:h.stroke([]),showXAxis:h.boolean(!0,{animatable:!1}),showYAxis:h.boolean(!0,{animatable:!1})},ye={legend:h.oneOf(["bottom","top","right","none"],{animatable:!1}),swatch:h.oneOf(["square","circle","line"])},Ae={horizontalGrid:Gt.horizontalGrid,gridStroke:h.stroke([]),spokeStroke:h.stroke([]),track:h.fill([])},ve={midnight:{palette:[...nt],foreground:"#f4f4f5",muted:"#a1a1aa",horizontalGrid:{weight:2,fill:"white/15"},gridStroke:{weight:2,fill:"white/15"},spokeStroke:{weight:2,fill:"white/15"},track:"white/10",background:[]},paper:{palette:["#2563eb","#059669","#d97706","#db2777","#7c3aed"],foreground:"#1c1917",muted:"#57534e",horizontalGrid:{weight:2,fill:"#1c1917/12"},gridStroke:{weight:2,fill:"#1c1917/12"},spokeStroke:{weight:2,fill:"#1c1917/12"},track:"#1c1917/12",background:"#fafaf9"},ember:{palette:["#d9603b","#8194ad","#e0a93b","#5e9d6b","#9ec85a"],foreground:"#e9e1d4",muted:"#8a7f70",horizontalGrid:{weight:2,fill:"#2c2820"},gridStroke:{weight:2,fill:"#2c2820"},spokeStroke:{weight:2,fill:"#2c2820"},track:"#2c2820",background:"#15130e"},neon:{palette:["#22d3ee","#a3e635","#f472b6","#facc15","#818cf8"],foreground:"#ffffff",muted:"#94a3b8",horizontalGrid:{weight:2,fill:"white/10"},gridStroke:{weight:2,fill:"white/10"},spokeStroke:{weight:2,fill:"white/10"},track:"white/10",background:[]},ocean:{palette:["#0ea5e9","#14b8a6","#6366f1","#38bdf8","#2dd4bf"],foreground:"#e0f2fe",muted:"#7dd3fc",horizontalGrid:{weight:2,fill:"#7dd3fc/20"},gridStroke:{weight:2,fill:"#7dd3fc/20"},spokeStroke:{weight:2,fill:"#7dd3fc/20"},track:"#7dd3fc/20",background:"#082f49"},sunset:{palette:["#f97316","#ef4444","#ec4899","#f59e0b","#a855f7"],foreground:"#fff7ed",muted:"#fdba74",horizontalGrid:{weight:2,fill:"#fdba74/20"},gridStroke:{weight:2,fill:"#fdba74/20"},spokeStroke:{weight:2,fill:"#fdba74/20"},track:"#fdba74/20",background:[]},pastel:{palette:["#a5b4fc","#f9a8d4","#86efac","#fde68a","#7dd3fc"],foreground:"#f8fafc",muted:"#cbd5e1",horizontalGrid:{weight:2,fill:"white/12"},gridStroke:{weight:2,fill:"white/12"},spokeStroke:{weight:2,fill:"white/12"},track:"white/12",background:[]},mono:{palette:["#fafafa","#a3a3a3","#737373","#d4d4d4","#525252"],foreground:"#fafafa",muted:"#a3a3a3",horizontalGrid:{weight:2,fill:"white/12"},gridStroke:{weight:2,fill:"white/12"},spokeStroke:{weight:2,fill:"white/12"},track:"white/12",background:[]}};function Rt(t,e,r){if(r!=null)return r;let n=t.palette;return n.length>0?n[e%n.length]:"white"}function Me(t,e,r){return Rt(t,r,e.fill)}function L(t){return t.fontFamily?{fontFamily:t.fontFamily}:{}}function Pt(t,e="center"){return{...L(t),fontSize:t.fontSize,fontWeight:t.fontWeight,textAlign:e,fill:t.muted}}function Ft(t){return{...L(t),fontSize:Math.round(t.fontSize*1.1),fontWeight:Math.min(900,t.fontWeight+100),textAlign:"center",fill:t.muted}}function Ee(t,e="center"){return{...L(t),fontSize:t.fontSize,fontWeight:Math.min(900,t.fontWeight+100),textAlign:e,fill:t.foreground}}function Te(t,e){let r=Math.round(t.fontSize*.6);return{labelStyle:Pt(t,e==="x"?"center":"right"),titleStyle:Ft(t),lineStyle:e==="x"?t.verticalGrid:t.horizontalGrid,tickPadding:e==="x"?{top:r}:{right:r},titlePadding:e==="x"?{top:Math.round(r/2)}:{right:r}}}function ze(t){let e=Math.max(8,Math.round(t.fontSize*.6)),r=t.swatch==="line"?{width:Math.round(e*2),height:Math.max(3,Math.round(e/4)),borderRadius:e}:t.swatch==="circle"?{width:e,height:e,borderRadius:e/2}:{width:e,height:e,borderRadius:Math.round(e/4)};return{padding:0,textStyle:{...L(t),fontSize:t.fontSize,fontWeight:t.fontWeight,textAlign:"left",fill:t.foreground},itemGap:Math.round(t.fontSize*1.4),markerStyle:{...r,stroke:[],shadow:[]}}}import{Rect as k,RotatedBox as Ot,Text as ot,textOps as Dt}from"@motionscript/sdk";function Ge(t){return Math.round(t.fontSize*.9)}function Re(t){return Math.ceil(t.fontSize*.7)}function Pe(t){return Math.ceil(t.fontSize*1.1)}function Fe(t){let r=[new k({flow:"horizontal",width:"fill",height:"fill",children:[...t.left?[t.left]:[],t.plot]})];t.bottom&&r.push(new k({flow:"horizontal",width:"fill",height:"hug",children:[...t.ghost?[t.ghost]:[],t.bottom]}));let n=new k({flow:"vertical",width:"fill",height:"fill",children:r}),o=t.legend&&t.legendAt!=="none"?t.legend:void 0,i=new k({flow:"horizontal",width:"fill",height:"fill",align:"center",gap:t.gap,children:[n,...o&&t.legendAt==="right"?[o]:[]]}),a=l=>new k({flow:"horizontal",width:"fill",height:"hug",align:"center",children:[l]});return new k({flow:"vertical",width:"fill",height:"fill",gap:t.gap,padding:t.padding,children:[...o&&t.legendAt==="top"?[a(o)]:[],i,...o&&t.legendAt==="bottom"?[a(o)]:[]]})}function Oe(t){let e=[],r=n=>{for(let o of n)e.push(o),r(o.children)};return r(t),e}function De(t){let e=t?.layoutBounds;return{width:e?.width??0,height:e?.height??0}}function m(t){let e=Object.keys(Dt.styleProps(t())),r={};for(let n of e)r[n]=()=>t()[n];return r}function Ie(t){let e=Array.from({length:t.count},(n,o)=>new ot({...m(t.text),text:()=>t.captions()[o]??""})),r=[];return t.title!==""&&r.push(new Ot({angle:-90,width:"hug",height:"hug",children:new ot({...m(t.titleText),text:t.title})})),r.push(new k({flow:"vertical",width:"hug",height:"hug",padding:()=>({right:t.tickPad()}),children:e})),new k({opacity:0,flow:"horizontal",gap:t.titlePad,width:"hug",height:0,children:r})}function Ce(t,e){return(Array.isArray(t)?t:[t]).map(n=>typeof n=="object"&&n!==null?{...n,opacity:(n.opacity??1)*e}:n)}import{Graphics2D as ht,Types as G,component2d as It,fillOps as st,strokeOps as ct}from"@motionscript/sdk";import{Types as it}from"@motionscript/sdk";function d(t,e){return it.custom(t,e)}function at(t){return t}var He=it.custom(0,{kind:"series",min:0,step:1});function lt(t,e){for(let r of e.fills??[])t.fill(r);for(let r of e.strokes??[])for(let n of r)t.fill(n.fill);for(let r of e.shadows??[])for(let n of r)t.fill(n.fill)}var N=()=>G.custom([],{resolve:ct.resolve,lerp:ct.lerp});function ft(t,[e,r],n){return(r<=e?0:(t-e)/(r-e)-.5)*n}function dt(t,e,r,n,o=1){t.draw(new ht().line({points:[e,r]}).stroke(n).opacity(o))}var je=It({key:"chartCanvas",state:{fill:G.custom([],{resolve:st.resolve,lerp:st.lerp}),xGridStroke:N(),yGridStroke:N(),xMarkers:d(()=>[]),yMarkers:d(()=>[]),xExtent:d(()=>[0,1]),yExtent:d(()=>[0,1]),axisStroke:N(),xAxisAt:G.custom(null),yAxisAt:G.custom(null)},load:(t,e)=>lt(t,{fills:[e.fill],strokes:[e.xGridStroke,e.yGridStroke,e.axisStroke]}),render:(t,e)=>{let{width:r,height:n}=t.size;if(r<=0||n<=0)return;e.fill.length>0&&t.draw(new ht().rect({x:0,y:0,width:r,height:n}).fill(e.fill));let o=(f,c,s)=>Math.max(-c/2+s/2,Math.min(c/2-s/2,f)),i=(f,c)=>{let s=c[0]?.weight??0;if(!(s<=0))for(let p of f){let u=o(ft(p,e.xExtent,r),r,s);dt(t,{x:u,y:-n/2},{x:u,y:n/2},c)}},a=(f,c)=>{let s=c[0]?.weight??0;if(!(s<=0))for(let p of f){let u=o(ft(p,e.yExtent,n),n,s);dt(t,{x:-r/2,y:u},{x:r/2,y:u},c)}},l=([f,c])=>s=>s>=Math.min(f,c)-1e-9&&s<=Math.max(f,c)+1e-9;i(e.xMarkers.filter(l(e.xExtent)),e.xGridStroke),a(e.yMarkers.filter(l(e.yExtent)),e.yGridStroke),e.xAxisAt!==null&&a([e.xAxisAt],e.axisStroke),e.yAxisAt!==null&&i([e.yAxisAt],e.axisStroke)}});import{Rect as mt,Text as xt,Types as R,component2d as $t}from"@motionscript/sdk";import{enterBudget as jt}from"@motionscript/sdk/component";import{Types as Ct,easeOut as Nt}from"@motionscript/sdk";var Wt=t=>t,W=20;function Ke(t){return t==="top"?{y:W}:t==="right"?{x:W}:{y:-W}}var Je=5,Qe={axes:.35,marks:.5,legend:.15};function x(t){return t.easing?Wt:Nt()}function y(t,e){let r=t.duration,n=e.reduce((i,a)=>Math.max(i,a.at+a.duration),0),o=n>r&&n>0?r/n:1;return t.together(e.map(({at:i,duration:a,piece:l})=>{let f=i*o,c=a*o;return t.sequence([t.wait(f),l,t.wait(Math.max(0,r-f-c))])}))}var H={opacity:1,shift:0};function A(){return Ct.custom({},{private:!0,resolve:(t,e)=>({...e,...t})})}function g(t,e){return t[e]??H}function S(t,e){let r={};for(let n of t)r[n]=e;return r}function b(t,e,r,n){return t.animate(o=>{let i=n(o);return{arrivals:{[e]:{opacity:r.opacity+(H.opacity-r.opacity)*i,shift:r.shift+(H.shift-r.shift)*i}}}})}import{Rect as ut,RotatedBox as Ht,Text as gt,Types as X,component2d as Xt,insetsOps as pt}from"@motionscript/sdk";import{enterBudget as Bt}from"@motionscript/sdk/component";var Ut=24;function B(t,e){let r=t.markers.indexOf(e);return(r>=0?t.captions[r]:void 0)??rt(e)}function U(t,e){return{tick:pt.resolve(t.tickPadding)[e],title:pt.resolve(t.titlePadding)[e]}}function Yt(t){let e=()=>U(t.axis(),"right"),r=Array.from({length:t.count},(o,i)=>{let a=()=>l.parent?.layoutBounds??{width:0,height:0},l=new gt({...m(()=>t.axis().labelStyle),text:()=>t.text(i),x:()=>(a().width-e().tick)/2-l.layoutBounds.width/2+g(t.arrivals(),i).shift,y:()=>t.place(i,a().height),opacity:()=>g(t.arrivals(),i).opacity*(t.opacity?.(i)??1)});return l}),n=[];return t.label!==""&&n.push(new Ht({angle:-90,width:"hug",height:"hug",children:new gt({...m(()=>t.axis().titleStyle),text:t.label,opacity:()=>g(t.arrivals(),"label").opacity,x:()=>g(t.arrivals(),"label").shift})})),n.push(new ut({height:"fill",width:"hug",padding:()=>({right:e().tick}),children:r})),new ut({flow:"horizontal",gap:()=>e().title,height:"fill",children:n})}var ar=Xt({key:"verticalAxis",state:{range:d(()=>[0,1]),markers:d(()=>[]),captions:d(()=>[]),axis:X.custom(et),label:"",arrivals:A()},defaults:{width:"fill",height:"fill"},children:t=>{let e=()=>[...t.markers].sort((n,o)=>o-n),r=n=>{if(n===void 0)return 0;let[o,i]=t.range;return i<=o?0:(n-o)/(i-o)};return[Yt({count:t.markers.length,axis:()=>t.axis,text:n=>{let o=e()[n];return o===void 0?"":B(t,o)},place:(n,o)=>(r(e()[n])-.5)*o,arrivals:()=>t.arrivals,label:t.label})]},commands:{enter:{args:{stagger:X.custom(void 0),slide:X.number(Ut)},run:(t,e)=>{let{stagger:r,slide:n}=t.args,o=e.markers.length,i=e.label!=="",a={opacity:0,shift:n},l=[...e.markers.keys(),...i?["label"]:[]],f=t.animate(()=>({arrivals:S(l,a)}));if(o===0)return f;let{step:c,per:s,caption:p}=Bt(t.duration,o,i,r),u=x(t),P=e.markers.map((Mt,M)=>({at:(o-1-M)*c,duration:s,piece:b(t,M,a,u)})),F=i?[{at:(o-1)*c+s,duration:p,piece:b(t,"label",a,u)}]:[];return t.together([f,y(t,[...P,...F])])}}}});var Vt=24,pr=$t({key:"horizontalAxis",state:{range:d(()=>[0,1]),markers:d(()=>[]),captions:d(()=>[]),axis:R.custom(tt),label:"",overhang:R.custom({left:0,right:0}),arrivals:A()},defaults:{width:"fill",height:"fill"},children:t=>{let e=()=>U(t.axis,"top"),r=()=>[...t.markers].sort((a,l)=>a-l),n=a=>{if(a===void 0)return 0;let[l,f]=t.range;return f<=l?0:(a-l)/(f-l)},o=t.markers.map((a,l)=>{let f=()=>c.parent?.layoutBounds.width??0,c=new xt({...m(()=>t.axis.labelStyle),text:()=>{let s=r()[l];return s===void 0?"":B(t,s)},x:()=>{let s=f(),p=c.layoutBounds.width/2,u=(n(r()[l])-.5)*s;return Math.max(-s/2-t.overhang.left+p,Math.min(s/2+t.overhang.right-p,u))},opacity:()=>g(t.arrivals,l).opacity,y:()=>g(t.arrivals,l).shift});return c}),i=[new mt({width:"fill",height:"hug",padding:()=>({top:e().tick}),children:o})];return t.label!==""&&i.push(new xt({...m(()=>t.axis.titleStyle),text:t.label,opacity:()=>g(t.arrivals,"label").opacity,y:()=>g(t.arrivals,"label").shift})),[new mt({flow:"vertical",gap:()=>e().title,height:"hug",width:"fill",children:i})]},commands:{enter:{args:{stagger:R.custom(void 0),slide:R.number(Vt)},run:(t,e)=>{let{stagger:r,slide:n}=t.args,o=e.markers.length,i=e.label!=="",a={opacity:0,shift:n},l=[...e.markers.keys(),...i?["label"]:[]],f=t.animate(()=>({arrivals:S(l,a)}));if(o===0)return f;let{step:c,per:s,caption:p}=jt(t.duration,o,i,r),u=x(t),P=e.markers.map((Mt,M)=>({at:M*c,duration:s,piece:b(t,M,a,u)})),F=i?[{at:(o-1)*c+s,duration:p,piece:b(t,"label",a,u)}]:[];return t.together([f,y(t,[...P,...F])])}}}});import{Flow as E,Paint as w,Rect as qt,Shapes as Y,Text as Kt,Types as v,component2d as kt}from"@motionscript/sdk";var bt={...w.state,...E.state,...Y.corners},Jt=kt({key:"legendEntry",state:{...bt,shown:v.number(1),along:v.oneOf(["horizontal","vertical"])},commands:{...w.commands},measure:(t,e,r)=>{let n=E.measure(t,e,r,w.inset(e));return e.shown>=1?n:e.along==="vertical"?{...n,height:e.shown*n.height}:{...n,width:e.shown*n.width}},layout:(t,e,r)=>E.layout(t,e,r,w.inset(e)),render:(t,e)=>w.draw(t,e,Y.rect(t.size,e))});function Qt(t,e){if(Array.isArray(t))return t;let r=[...e??[]];for(let[n,o]of Object.entries(t))r[Number(n)]=o;return r}var yr=kt({key:"chartLegend",state:{...bt,series:d(()=>[]),swatches:d(()=>[]),legend:v.custom(_),reveal:d(()=>[],{resolve:Qt})},defaults:{flow:"horizontal",width:"hug",height:"hug",gap:t=>t.flow==="vertical"?Math.round(t.legend.itemGap*.4):t.legend.itemGap,padding:t=>t.legend.padding,align:t=>t.flow==="vertical"?"centerLeft":"center",reveal:t=>t.series.map(e=>e.enabled??!0?1:0)},children:t=>{let e=()=>t.legend.markerStyle,r=t.flow==="vertical"?"vertical":"horizontal";return t.series.map((n,o)=>Jt({flow:"horizontal",gap:()=>Math.round((t.legend.textStyle.fontSize??24)*.45),align:"center",width:"hug",height:"hug",along:r,opacity:()=>t.reveal[o]??0,gapScale:()=>t.reveal[o]??0,shown:()=>t.reveal[o]??0,children:[qt({width:()=>e().width,height:()=>e().height,cornerRadius:()=>e().borderRadius,fill:()=>t.swatches[o]??"white",stroke:()=>e().stroke,shadow:()=>e().shadow}),Kt({...m(()=>t.legend.textStyle),text:n.label||n.field})]}))},commands:{...w.commands,showSeries:{args:{index:v.number(0,{min:0,step:1})},run:(t,e)=>t.args.index in e.series?t.animate(wt(e,t.args.index,1,x(t))):t.wait(t.duration)},hideSeries:{args:{index:v.number(0,{min:0,step:1})},run:(t,e)=>t.args.index in e.series?t.animate(wt(e,t.args.index,0,x(t))):t.wait(t.duration)},spotlightSeries:{args:{index:v.number(0,{min:0,step:1})},run:(t,e,r)=>t.together(r.flatMap((n,o)=>(e.reveal[o]??0)>0?[n.to({opacity:o===t.args.index?1:K})]:[]))}},measure:(t,e,r)=>E.measure(t,e,r,w.inset(e)),layout:(t,e,r)=>E.layout(t,e,r,w.inset(e)),render:(t,e)=>w.draw(t,e,Y.rect(t.size,e))});function wt(t,e,r,n){let o=t.reveal[e]??0;return i=>({reveal:{[e]:o+(r-o)*n(i)}})}import{Flow as $,Paint as T,Rect as j,Shapes as St,Text as Zt,Types as te,clamp as ee,component2d as re,textOps as ne}from"@motionscript/sdk";var yt=16,zr=re({key:"pieLegend",state:{...T.state,...$.state,...St.corners,slices:d(()=>[]),legend:te.custom(_),dims:d(()=>[]),arrivals:A()},defaults:{flow:"vertical",align:"centerLeft",width:"hug",height:"hug",gap:t=>t.legend.itemGap/3,padding:t=>t.legend.padding},children:t=>{let e=()=>t.legend.markerStyle;return t.slices.map((r,n)=>j({width:"hug",height:"hug",flow:"freeform",opacity:()=>ee(t.dims[n]??1,0,1),children:[j({flow:"horizontal",gap:()=>Math.round(t.legend.textStyle.fontSize===void 0?12:Number(t.legend.textStyle.fontSize)*.4),align:"center",width:"hug",height:"hug",opacity:()=>g(t.arrivals,n).opacity,x:()=>g(t.arrivals,n).shift,children:[j({width:()=>e().width,height:()=>e().height,cornerRadius:()=>e().borderRadius,fill:()=>t.slices[n]?.fill??"white"}),Zt({...ne.styleProps(t.legend.textStyle),fill:()=>t.legend.textStyle.fill??"white",fontSize:()=>t.legend.textStyle.fontSize??28,fontWeight:()=>t.legend.textStyle.fontWeight??500,text:()=>t.slices[n]?.category??""})]})]}))},commands:{...T.commands,arm:(t,e)=>t.animate(()=>({arrivals:S([...e.slices.keys()],{opacity:0,shift:yt})})),enter:(t,e)=>{let r=e.slices.length;if(r===0)return t.wait(t.duration);let n={opacity:0,shift:yt},o=t.animate(()=>({arrivals:S([...e.slices.keys()],n)})),i=t.duration/(1+Math.max(0,r-1)/5),a=i/5,l=x(t),f=e.slices.map((c,s)=>({at:s*a,duration:i,piece:b(t,s,n,l)}));return t.together([o,y(t,f)])}},measure:(t,e,r)=>$.measure(t,e,r,T.inset(e)),layout:(t,e,r)=>$.layout(t,e,r,T.inset(e)),render:(t,e)=>T.draw(t,e,St.rect(t.size,e))});import{clamp as oe,fillOps as At}from"@motionscript/sdk";var Gr=Math.PI/180;function Rr(t,e,r){return t<=0?1:1-(1-oe(e,0,1))*t*(1-r)}function Pr(t,e){return{x:t*Math.sin(e),y:t*Math.cos(e)}}var Fr=.15,vt=new WeakMap;function ie(t){if(typeof t!="object"||t===null)return At.resolve(t);let e=vt.get(t);return e===void 0&&vt.set(t,e=At.resolve(t)),e}function Or(t){return t.map(e=>ie(e.fill))}export*from"@motionscript/sdk/component";export{Ge as a,Re as b,Pe as c,Fe as d,Oe as e,De as f,m as g,Ie as h,Ce as i,d as j,at as k,He as l,lt as m,dt as n,je as o,W as p,Ke as q,Je as r,Qe as s,x as t,y as u,A as v,g as w,S as x,b as y,se as z,D as A,ce as B,V as C,K as D,fe as E,de as F,he as G,tt as H,et as I,_ as J,rt as K,ue as L,ge as M,I as N,pe as O,me as P,yr as Q,B as R,U as S,Yt as T,ar as U,pr as V,ke as W,nt as X,be as Y,Se as Z,Gt as _,ye as $,ve as aa,Rt as ba,Me as ca,Pt as da,Ft as ea,Ee as fa,Te as ga,ze as ha,zr as ia,Gr as ja,Rr as ka,Pr as la,Fr as ma,ie as na,Or as oa};
2
+ //# sourceMappingURL=chunk-R3Q5EE6E.js.map