@motionscript/charts 0.1.1-alpha.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 (207) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +98 -28
  3. package/dist/bar-chart/bar-chart.d.ts +233 -39
  4. package/dist/bar-chart/bar-chart.d.ts.map +1 -1
  5. package/dist/bar-chart/bar-chart.js +215 -171
  6. package/dist/bar-chart/bar-chart.js.map +1 -1
  7. package/dist/bar-chart/category-axis.d.ts +12 -7
  8. package/dist/bar-chart/category-axis.d.ts.map +1 -1
  9. package/dist/bar-chart/category-axis.js +56 -42
  10. package/dist/bar-chart/category-axis.js.map +1 -1
  11. package/dist/bar-chart/chart-bars.d.ts +52 -52
  12. package/dist/bar-chart/chart-bars.d.ts.map +1 -1
  13. package/dist/bar-chart/chart-bars.js +80 -89
  14. package/dist/bar-chart/chart-bars.js.map +1 -1
  15. package/dist/bar-chart/index.d.ts +4 -4
  16. package/dist/bar-chart/index.d.ts.map +1 -1
  17. package/dist/bar-chart/index.js +2 -2
  18. package/dist/bar-chart/index.js.map +1 -1
  19. package/dist/bar-chart/shared.d.ts +36 -65
  20. package/dist/bar-chart/shared.d.ts.map +1 -1
  21. package/dist/bar-chart/shared.js +68 -117
  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 +5 -2
  30. package/dist/engine.d.ts.map +1 -1
  31. package/dist/engine.js +5 -2
  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 -15
  38. package/dist/kit/cartesian.d.ts.map +1 -1
  39. package/dist/kit/cartesian.js +79 -29
  40. package/dist/kit/cartesian.js.map +1 -1
  41. package/dist/kit/chart-canvas.d.ts +32 -24
  42. package/dist/kit/chart-canvas.d.ts.map +1 -1
  43. package/dist/kit/chart-canvas.js +52 -46
  44. package/dist/kit/chart-canvas.js.map +1 -1
  45. package/dist/kit/chart-legend.d.ts +8 -4
  46. package/dist/kit/chart-legend.d.ts.map +1 -1
  47. package/dist/kit/chart-legend.js +30 -20
  48. package/dist/kit/chart-legend.js.map +1 -1
  49. package/dist/{line-chart → kit}/horizontal-axis.d.ts +31 -6
  50. package/dist/kit/horizontal-axis.d.ts.map +1 -0
  51. package/dist/{line-chart → kit}/horizontal-axis.js +23 -24
  52. package/dist/kit/horizontal-axis.js.map +1 -0
  53. package/dist/kit/motion.d.ts +5 -0
  54. package/dist/kit/motion.d.ts.map +1 -1
  55. package/dist/kit/motion.js +8 -0
  56. package/dist/kit/motion.js.map +1 -1
  57. package/dist/{pie-chart → kit}/pie-legend.d.ts +3 -3
  58. package/dist/kit/pie-legend.d.ts.map +1 -0
  59. package/dist/{pie-chart → kit}/pie-legend.js +11 -10
  60. package/dist/kit/pie-legend.js.map +1 -0
  61. package/dist/kit/polar.d.ts +31 -0
  62. package/dist/kit/polar.d.ts.map +1 -0
  63. package/dist/kit/polar.js +33 -0
  64. package/dist/kit/polar.js.map +1 -0
  65. package/dist/kit/shared.d.ts +11 -50
  66. package/dist/kit/shared.d.ts.map +1 -1
  67. package/dist/kit/shared.js +58 -141
  68. package/dist/kit/shared.js.map +1 -1
  69. package/dist/kit/style.d.ts +254 -0
  70. package/dist/kit/style.d.ts.map +1 -0
  71. package/dist/kit/style.js +197 -0
  72. package/dist/kit/style.js.map +1 -0
  73. package/dist/kit/vertical-axis.d.ts +22 -2
  74. package/dist/kit/vertical-axis.d.ts.map +1 -1
  75. package/dist/kit/vertical-axis.js +56 -43
  76. package/dist/kit/vertical-axis.js.map +1 -1
  77. package/dist/line-chart/chart-line.d.ts +95 -3
  78. package/dist/line-chart/chart-line.d.ts.map +1 -1
  79. package/dist/line-chart/chart-line.js +165 -53
  80. package/dist/line-chart/chart-line.js.map +1 -1
  81. package/dist/line-chart/chart-region.d.ts +1 -1
  82. package/dist/line-chart/chart-region.d.ts.map +1 -1
  83. package/dist/line-chart/chart-region.js +7 -8
  84. package/dist/line-chart/chart-region.js.map +1 -1
  85. package/dist/line-chart/index.d.ts +5 -6
  86. package/dist/line-chart/index.d.ts.map +1 -1
  87. package/dist/line-chart/index.js +3 -4
  88. package/dist/line-chart/index.js.map +1 -1
  89. package/dist/line-chart/line-chart.d.ts +257 -18
  90. package/dist/line-chart/line-chart.d.ts.map +1 -1
  91. package/dist/line-chart/line-chart.js +282 -134
  92. package/dist/line-chart/line-chart.js.map +1 -1
  93. package/dist/line-chart/shared.d.ts +51 -34
  94. package/dist/line-chart/shared.d.ts.map +1 -1
  95. package/dist/line-chart/shared.js +175 -83
  96. package/dist/line-chart/shared.js.map +1 -1
  97. package/dist/line-chart/x-scale.d.ts +2 -0
  98. package/dist/line-chart/x-scale.d.ts.map +1 -1
  99. package/dist/line-chart/x-scale.js +15 -0
  100. package/dist/line-chart/x-scale.js.map +1 -1
  101. package/dist/nodes.d.ts +3 -1
  102. package/dist/nodes.d.ts.map +1 -1
  103. package/dist/nodes.js +9 -1
  104. package/dist/nodes.js.map +1 -1
  105. package/dist/pie-chart/index.d.ts +2 -3
  106. package/dist/pie-chart/index.d.ts.map +1 -1
  107. package/dist/pie-chart/index.js +1 -2
  108. package/dist/pie-chart/index.js.map +1 -1
  109. package/dist/pie-chart/pie-chart.d.ts +114 -18
  110. package/dist/pie-chart/pie-chart.d.ts.map +1 -1
  111. package/dist/pie-chart/pie-chart.js +37 -24
  112. package/dist/pie-chart/pie-chart.js.map +1 -1
  113. package/dist/pie-chart/pie-ring.d.ts +16 -5
  114. package/dist/pie-chart/pie-ring.d.ts.map +1 -1
  115. package/dist/pie-chart/pie-ring.js +89 -55
  116. package/dist/pie-chart/pie-ring.js.map +1 -1
  117. package/dist/pie-chart/shared.d.ts +53 -61
  118. package/dist/pie-chart/shared.d.ts.map +1 -1
  119. package/dist/pie-chart/shared.js +41 -121
  120. package/dist/pie-chart/shared.js.map +1 -1
  121. package/dist/radar-chart/index.d.ts +5 -0
  122. package/dist/radar-chart/index.d.ts.map +1 -0
  123. package/dist/radar-chart/index.js +5 -0
  124. package/dist/radar-chart/index.js.map +1 -0
  125. package/dist/radar-chart/radar-chart.d.ts +218 -0
  126. package/dist/radar-chart/radar-chart.d.ts.map +1 -0
  127. package/dist/radar-chart/radar-chart.js +224 -0
  128. package/dist/radar-chart/radar-chart.js.map +1 -0
  129. package/dist/radar-chart/radar-grid.d.ts +43 -0
  130. package/dist/radar-chart/radar-grid.d.ts.map +1 -0
  131. package/dist/radar-chart/radar-grid.js +61 -0
  132. package/dist/radar-chart/radar-grid.js.map +1 -0
  133. package/dist/radar-chart/radar-series.d.ts +59 -0
  134. package/dist/radar-chart/radar-series.d.ts.map +1 -0
  135. package/dist/radar-chart/radar-series.js +71 -0
  136. package/dist/radar-chart/radar-series.js.map +1 -0
  137. package/dist/radar-chart/shared.d.ts +73 -0
  138. package/dist/radar-chart/shared.d.ts.map +1 -0
  139. package/dist/radar-chart/shared.js +123 -0
  140. package/dist/radar-chart/shared.js.map +1 -0
  141. package/dist/radial-chart/index.d.ts +6 -0
  142. package/dist/radial-chart/index.d.ts.map +1 -0
  143. package/dist/radial-chart/index.js +4 -0
  144. package/dist/radial-chart/index.js.map +1 -0
  145. package/dist/radial-chart/radial-chart.d.ts +216 -0
  146. package/dist/radial-chart/radial-chart.d.ts.map +1 -0
  147. package/dist/radial-chart/radial-chart.js +174 -0
  148. package/dist/radial-chart/radial-chart.js.map +1 -0
  149. package/dist/radial-chart/radial-rings.d.ts +121 -0
  150. package/dist/radial-chart/radial-rings.d.ts.map +1 -0
  151. package/dist/radial-chart/radial-rings.js +273 -0
  152. package/dist/radial-chart/radial-rings.js.map +1 -0
  153. package/dist/radial-chart/shared.d.ts +73 -0
  154. package/dist/radial-chart/shared.d.ts.map +1 -0
  155. package/dist/radial-chart/shared.js +79 -0
  156. package/dist/radial-chart/shared.js.map +1 -0
  157. package/package.json +4 -4
  158. package/registry.json +21 -6
  159. package/src/bar-chart/bar-chart.ts +252 -179
  160. package/src/bar-chart/category-axis.ts +46 -40
  161. package/src/bar-chart/chart-bars.ts +97 -117
  162. package/src/bar-chart/index.ts +7 -10
  163. package/src/bar-chart/shared.ts +78 -238
  164. package/src/engine.ts +5 -2
  165. package/src/index.ts +2 -0
  166. package/src/kit/cartesian.ts +118 -40
  167. package/src/kit/chart-canvas.ts +49 -54
  168. package/src/kit/chart-legend.ts +28 -20
  169. package/src/kit/horizontal-axis.ts +114 -0
  170. package/src/kit/motion.ts +7 -0
  171. package/src/{pie-chart → kit}/pie-legend.ts +12 -11
  172. package/src/kit/polar.ts +54 -0
  173. package/src/kit/shared.ts +55 -277
  174. package/src/kit/style.ts +257 -0
  175. package/src/kit/vertical-axis.ts +67 -48
  176. package/src/line-chart/chart-line.ts +176 -54
  177. package/src/line-chart/chart-region.ts +6 -10
  178. package/src/line-chart/index.ts +14 -10
  179. package/src/line-chart/line-chart.ts +347 -151
  180. package/src/line-chart/shared.ts +193 -174
  181. package/src/line-chart/x-scale.ts +13 -0
  182. package/src/nodes.ts +9 -1
  183. package/src/pie-chart/index.ts +2 -23
  184. package/src/pie-chart/pie-chart.ts +52 -35
  185. package/src/pie-chart/pie-ring.ts +92 -71
  186. package/src/pie-chart/shared.ts +68 -266
  187. package/src/radar-chart/index.ts +4 -0
  188. package/src/radar-chart/radar-chart.ts +287 -0
  189. package/src/radar-chart/radar-grid.ts +78 -0
  190. package/src/radar-chart/radar-series.ts +88 -0
  191. package/src/radar-chart/shared.ts +146 -0
  192. package/src/radial-chart/index.ts +5 -0
  193. package/src/radial-chart/radial-chart.ts +210 -0
  194. package/src/radial-chart/radial-rings.ts +328 -0
  195. package/src/radial-chart/shared.ts +114 -0
  196. package/dist/browser/chunks/chunk-4SMRCU24.js +0 -2
  197. package/dist/browser/chunks/chunk-4SMRCU24.js.map +0 -7
  198. package/dist/kit/chart-border.d.ts +0 -18
  199. package/dist/kit/chart-border.d.ts.map +0 -1
  200. package/dist/kit/chart-border.js +0 -23
  201. package/dist/kit/chart-border.js.map +0 -1
  202. package/dist/line-chart/horizontal-axis.d.ts.map +0 -1
  203. package/dist/line-chart/horizontal-axis.js.map +0 -1
  204. package/dist/pie-chart/pie-legend.d.ts.map +0 -1
  205. package/dist/pie-chart/pie-legend.js.map +0 -1
  206. package/src/kit/chart-border.ts +0 -36
  207. package/src/line-chart/horizontal-axis.ts +0 -122
@@ -1,25 +1,19 @@
1
- import { Graphics2D, Text, Types, clamp, component2d, fillOps, shadowOps, strokeOps, textOps, } from "@motionscript/sdk";
2
- import { fresh } from "../kit/entries.js";
1
+ import { Graphics2D, Text, Types, clamp, component2d, fillOps, } from "@motionscript/sdk";
2
+ import { boundText } from "../kit/cartesian.js";
3
+ import { asParts, fresh } from "../kit/entries.js";
3
4
  import { frameEase } from "../kit/motion.js";
4
5
  import { loadPaints } from "../kit/paints.js";
5
6
  import { formatMarker } from "../kit/shared.js";
6
- import { DEFAULT_BAR_CHART_THEME } from "./shared.js";
7
- /** Gap between a grouped column's end and the figure printed over it, in px. */
8
- const VALUE_GAP = 10;
9
- /** A segment shorter than this many multiples of the type size prints no figure. */
10
- const VALUE_FIT = 1.6;
11
- /** Fallback type size when the theme's value style leaves it unset or autofit. */
12
- const VALUE_SIZE = 24;
13
- /**
14
- * Column `i`'s dimming: the category spotlight, then the series switch. Captions
15
- * read this because they are child nodes, which a `render` guard would leave on
16
- * screen over a series that is not there.
17
- */
7
+ import { inkOn } from "./shared.js";
8
+ /** A figure inside a bar needs this much room around it, in multiples of the type size. */
9
+ const INSIDE_ROOM = 0.6;
10
+ /** Bar `i`'s dimming: the category spotlight, then the series switch. */
18
11
  function dimAt(s, index) {
19
12
  if (!s.enabled)
20
13
  return 0;
21
14
  return clamp(s.dims[index] ?? 1, 0, 1);
22
15
  }
16
+ /** Bar `i`'s two ends as grown so far, along the value axis. */
23
17
  function endsAt(s, index) {
24
18
  const bar = s.bars[index];
25
19
  if (!bar)
@@ -27,90 +21,87 @@ function endsAt(s, index) {
27
21
  const g = clamp(s.growth, 0, 1);
28
22
  return { base: s.baseline + (bar.from - s.baseline) * g, end: s.baseline + (bar.to - s.baseline) * g };
29
23
  }
30
- function valueSize(s) {
31
- const size = s.valueStyle.fontSize;
32
- return typeof size === "number" ? size : VALUE_SIZE;
33
- }
34
- function insideAt(s, index) {
35
- const bar = s.bars[index];
36
- return bar !== undefined && Math.abs(bar.from - s.baseline) > 0.5;
37
- }
38
- /** Column `i`'s figure, or `""` where there is no room. Blanking rather than dropping the node keeps captions index-aligned, so a rescale into more room prints again. */
39
- function captionAt(s, index) {
40
- const bar = s.bars[index];
41
- if (!bar || bar.value === 0)
42
- return "";
43
- // An interior segment prints inside itself and must hold a line of type; a grouped column prints past its end.
44
- if (insideAt(s, index)) {
45
- const ends = endsAt(s, index);
46
- if (!ends)
47
- return "";
48
- if (Math.abs(ends.end - ends.base) < valueSize(s) * VALUE_FIT)
49
- return "";
50
- }
51
- return bar.caption ?? formatMarker(bar.value);
24
+ function sizeOf(style) {
25
+ return typeof style.fontSize === "number" ? style.fontSize : 24;
52
26
  }
53
- function captionY(s, index) {
27
+ /** Where bar `i`'s figure sits along the value axis: past its end, or in its middle. */
28
+ function captionAlong(s, index, extent) {
54
29
  const ends = endsAt(s, index);
55
30
  if (!ends)
56
31
  return 0;
57
- if (insideAt(s, index))
32
+ if (s.values === "inside")
58
33
  return (ends.base + ends.end) / 2;
59
- // Text is centred on `y`: clear the end by the gap plus half a line, on the side the column reached.
60
34
  const direction = ends.end >= ends.base ? 1 : -1;
61
- return ends.end + direction * (VALUE_GAP + valueSize(s) / 2);
35
+ return ends.end + direction * (sizeOf(s.valueStyle) * 0.4 + extent / 2);
36
+ }
37
+ /** Whether bar `i` has room for a figure `extent` long inside it. */
38
+ function fitsInside(s, index, extent, across) {
39
+ const bar = s.bars[index];
40
+ const ends = endsAt(s, index);
41
+ if (!bar || !ends)
42
+ return false;
43
+ const room = sizeOf(s.valueStyle) * INSIDE_ROOM;
44
+ return Math.abs(ends.end - ends.base) >= extent + room && bar.thickness >= across;
62
45
  }
63
46
  /**
64
- * One series of a {@link BarChart}: its column in every category plus the
65
- * printed figures. A node per series, like `ChartLine`, so `showSeries` and
47
+ * One series of a {@link BarChart}: its bar in every category plus the printed
48
+ * figures. A node per series, like `ChartLine`, so `showSeries` and
66
49
  * `spotlightSeries` mean the same on both: enable the node or tween its opacity.
67
50
  * Positions come from the parent, which owns the slot arithmetic.
68
- *
69
- * The figures are {@link Text} children, so they take the theme's type style,
70
- * are measured by layout, and hide with the series.
71
51
  */
72
52
  export const ChartBars = component2d({
73
53
  key: "chartBars",
74
54
  state: {
75
55
  bars: fresh(() => []),
76
- /** Pixel y of value 0, where every column grows from. */
56
+ /** Pixel position of value 0 along the value axis, where every bar grows from. */
77
57
  baseline: 0,
58
+ /** Bars grow along x from a category column rather than along y from a row. */
59
+ horizontal: false,
78
60
  fill: Types.custom([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),
79
- barStroke: Types.custom(DEFAULT_BAR_CHART_THEME.bar.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),
80
- barShadow: Types.custom(DEFAULT_BAR_CHART_THEME.bar.shadow, { resolve: shadowOps.resolve, lerp: shadowOps.lerp }),
81
- cornerRadius: DEFAULT_BAR_CHART_THEME.bar.cornerRadius,
61
+ cornerRadius: 8,
82
62
  /**
83
- * Rise of every column in `[0, 1]` about the baseline, not each column's own
84
- * base: every segment travels by the same factor, so a stack stays flush
85
- * mid-animation and a negative column grows down.
63
+ * Rise of every bar in `[0, 1]` about the baseline, not each bar's own base:
64
+ * every segment travels by the same factor, so a stack stays flush
65
+ * mid-animation and a negative bar grows the other way.
86
66
  */
87
67
  growth: 1,
88
- /** Per-column opacity by row index, how the category spotlight reaches one column. Missing reads as 1. */
68
+ /** Per-bar opacity by row index, how the category spotlight reaches one bar. Missing reads as 1. */
89
69
  dims: fresh(() => []),
90
- showValues: false,
91
- valueStyle: Types.custom(DEFAULT_BAR_CHART_THEME.valueStyle),
92
- /** The wholesale switch behind `showSeries`/`hideSeries`; off skips the columns and their figures. */
70
+ /** Read as built: whether each bar prints its figure, and where. */
71
+ values: Types.custom("none"),
72
+ valueStyle: Types.custom({ fontSize: 24, fill: "white" }),
73
+ /** The wholesale switch behind `showSeries`/`hideSeries`; off skips the bars and their figures. */
93
74
  enabled: true,
94
75
  },
95
76
  // A node made of its figures would otherwise hug them.
96
77
  defaults: { width: "fill", height: "fill" },
97
- // One caption per column, built once (the row count is fixed at construction)
98
- // and bound to the live geometry so it travels with its column.
78
+ // One figure per bar, built once (the row count is fixed at construction)
79
+ // and bound to the live geometry so it travels with its bar.
99
80
  children: (state) => {
100
- if (!state.showValues)
81
+ if (state.values === "none")
101
82
  return [];
102
- return state.bars.map((_, i) => Text({
103
- ...textOps.styleProps(state.valueStyle),
104
- text: () => captionAt(state, i),
105
- x: () => state.bars[i]?.x ?? 0,
106
- y: () => captionY(state, i),
107
- opacity: () => dimAt(state, i),
83
+ return asParts(state.bars.map((_, i) => {
84
+ const caption = new Text({
85
+ ...boundText(() => ({ ...state.valueStyle, ...(state.values === "inside" && { fill: inkOn(state.fill) }) })),
86
+ text: () => state.bars[i]?.caption ?? "",
87
+ x: () => (state.horizontal ? captionAlong(state, i, caption.layoutBounds.width) : (state.bars[i]?.center ?? 0)),
88
+ y: () => (state.horizontal ? (state.bars[i]?.center ?? 0) : captionAlong(state, i, caption.layoutBounds.height)),
89
+ opacity: () => {
90
+ const box = caption.layoutBounds;
91
+ const along = state.horizontal ? box.width : box.height;
92
+ const across = state.horizontal ? box.height : box.width;
93
+ if (state.values === "inside" && !fitsInside(state, i, along, across))
94
+ return 0;
95
+ // A figure past the end rises in with its bar's last stretch.
96
+ return dimAt(state, i) * clamp((state.growth - 0.6) / 0.4, 0, 1);
97
+ },
98
+ });
99
+ return caption;
108
100
  }));
109
101
  },
110
- // The stroke and shadow sit past the conventional slots, so they are named here.
111
- load: (loader, state) => loadPaints(loader, { fills: [state.fill], shadows: [state.barShadow], strokes: [state.barStroke] }),
102
+ load: (loader, state) => loadPaints(loader, { fills: [state.fill] }),
112
103
  commands: {
113
- /** Raise every column from the baseline (`growth` 0 to 1). The resting state is the finished one; the chart arms it back to 0. */
104
+ /** Raise every bar from the baseline (`growth` 0 to 1). The resting state is the finished one; the chart arms it back to 0. */
114
105
  enter: (timeline) => {
115
106
  const ease = frameEase(timeline);
116
107
  return timeline.animate((t) => ({ growth: ease(t) }));
@@ -121,33 +112,33 @@ export const ChartBars = component2d({
121
112
  for (let i = 0; i < state.bars.length; i++) {
122
113
  const bar = state.bars[i];
123
114
  const ends = endsAt(state, i);
124
- if (!ends || bar.width <= 0)
115
+ if (!ends || bar.thickness <= 0)
125
116
  continue;
126
- const height = Math.abs(ends.end - ends.base);
127
- if (height <= 0)
117
+ // A segment inside a stack reaches a pixel under the next, so no seam of background shows between them.
118
+ const seam = bar.round ? 0 : 1;
119
+ const length = Math.abs(ends.end - ends.base) + seam;
120
+ if (length <= seam)
128
121
  continue;
129
- const radius = bar.round ? Math.min(state.cornerRadius, height) : 0;
130
- // One `Graphics2D` per column: opacity belongs to the command list, and the spotlight dims single columns.
131
- const g = new Graphics2D();
132
- const rect = g.rect({
133
- x: bar.x,
134
- y: (ends.base + ends.end) / 2,
135
- width: bar.width,
136
- height,
137
- // Corner keys are visual (y-up): a column reaching up rounds `top*`, one reaching down `bottom*`. Only the far end rounds.
138
- cornerRadius: radius > 0
139
- ? ends.end >= ends.base
140
- ? { topLeft: radius, topRight: radius, bottomLeft: 0, bottomRight: 0 }
141
- : { bottomLeft: radius, bottomRight: radius, topLeft: 0, topRight: 0 }
142
- : 0,
143
- });
144
- rect.shadow(state.barShadow);
145
- rect.fill(state.fill);
146
- rect.stroke(state.barStroke);
122
+ const radius = bar.round ? Math.max(0, Math.min(state.cornerRadius, length, bar.thickness / 2)) : 0;
123
+ const forward = ends.end >= ends.base;
124
+ const mid = (ends.base + ends.end) / 2 + (forward ? seam : -seam) / 2;
125
+ // Corner keys are visual (y-up): only the far end rounds.
126
+ const far = state.horizontal
127
+ ? (forward ? { topRight: radius, bottomRight: radius, topLeft: 0, bottomLeft: 0 } : { topLeft: radius, bottomLeft: radius, topRight: 0, bottomRight: 0 })
128
+ : (forward ? { topLeft: radius, topRight: radius, bottomLeft: 0, bottomRight: 0 } : { bottomLeft: radius, bottomRight: radius, topLeft: 0, topRight: 0 });
129
+ // One `Graphics2D` per bar: opacity belongs to the command list, and the spotlight dims single bars.
130
+ const g = new Graphics2D().rect(state.horizontal
131
+ ? { x: mid, y: bar.center, width: length, height: bar.thickness, cornerRadius: radius > 0 ? far : 0 }
132
+ : { x: bar.center, y: mid, width: bar.thickness, height: length, cornerRadius: radius > 0 ? far : 0 });
133
+ g.fill(state.fill);
147
134
  ctx.draw(g.opacity(dimAt(state, i)));
148
135
  }
149
136
  }
150
137
  ctx.children();
151
138
  },
152
139
  });
140
+ /** A figure as the bar prints it when the chart gives no caption. */
141
+ export function barCaption(value) {
142
+ return value === 0 ? "" : formatMarker(value);
143
+ }
153
144
  //# sourceMappingURL=chart-bars.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chart-bars.js","sourceRoot":"","sources":["../../src/bar-chart/chart-bars.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,IAAI,EACJ,KAAK,EACL,KAAK,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,GAYR,MAAM,mBAAmB,CAAA;AAE1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC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UAAU,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE;4BACtE,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE;wBACxE,CAAC,CAAC,CAAC;iBACR,CAAC,CAAA;gBACF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;gBAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;gBAC5B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YACtC,CAAC;QACH,CAAC;QACD,GAAG,CAAC,QAAQ,EAAE,CAAA;IAChB,CAAC;CACF,CAAC,CAAA","sourcesContent":["import {\n Graphics2D,\n Text,\n Types,\n clamp,\n component2d,\n fillOps,\n shadowOps,\n strokeOps,\n textOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D as _Node2D,\n type Node2DProps as _Node2DProps,\n type Shadow,\n type ShadowResolved,\n type Stroke,\n type StrokeResolved,\n type TextStyle,\n} from \"@motionscript/sdk\"\n\nimport { fresh } from \"../kit/entries\"\nimport { frameEase } from \"../kit/motion\"\nimport { loadPaints } from \"../kit/paints\"\nimport { formatMarker } from \"../kit/shared\"\nimport { DEFAULT_BAR_CHART_THEME } from \"./shared\"\n\n/**\n * One drawn column in the plot's centred pixel space (origin at the centre,\n * y-up), mapped by the parent {@link BarChart}. `from`/`to` are the two ends\n * rather than a base and a height, like {@link BarSpan}: one shape fits grouped,\n * stacked and negative.\n */\nexport interface BarGeometry {\n /** Centre x. */\n x: number\n width: number\n /** Pixel y of the base: the baseline when grouped, the running stack top when stacked. */\n from: number\n /** Pixel y of the far end at full growth. */\n to: number\n /** Whether the far end takes the corner radius (the stack's cap). */\n round: boolean\n /** The value plotted, for the printed figure. */\n value: number\n /** The printed figure, written as the value axis writes its ticks; absent, the bare marker reading of `value`. */\n caption?: string\n}\n\n/** Gap between a grouped column's end and the figure printed over it, in px. */\nconst VALUE_GAP = 10\n/** A segment shorter than this many multiples of the type size prints no figure. */\nconst VALUE_FIT = 1.6\n/** Fallback type size when the theme's value style leaves it unset or autofit. */\nconst VALUE_SIZE = 24\n\ninterface Columns {\n readonly bars: readonly BarGeometry[]\n readonly baseline: number\n readonly growth: number\n readonly dims: readonly number[]\n readonly enabled: boolean\n readonly valueStyle: TextStyle\n}\n\n/**\n * Column `i`'s dimming: the category spotlight, then the series switch. Captions\n * read this because they are child nodes, which a `render` guard would leave on\n * screen over a series that is not there.\n */\nfunction dimAt(s: Columns, index: number): number {\n if (!s.enabled) return 0\n return clamp(s.dims[index] ?? 1, 0, 1)\n}\n\nfunction endsAt(s: Columns, index: number): { base: number; end: number } | null {\n const bar = s.bars[index]\n if (!bar) return null\n const g = clamp(s.growth, 0, 1)\n return { base: s.baseline + (bar.from - s.baseline) * g, end: s.baseline + (bar.to - s.baseline) * g }\n}\n\nfunction valueSize(s: Columns): number {\n const size = s.valueStyle.fontSize\n return typeof size === \"number\" ? size : VALUE_SIZE\n}\n\nfunction insideAt(s: Columns, index: number): boolean {\n const bar = s.bars[index]\n return bar !== undefined && Math.abs(bar.from - s.baseline) > 0.5\n}\n\n/** Column `i`'s figure, or `\"\"` where there is no room. Blanking rather than dropping the node keeps captions index-aligned, so a rescale into more room prints again. */\nfunction captionAt(s: Columns, index: number): string {\n const bar = s.bars[index]\n if (!bar || bar.value === 0) return \"\"\n // An interior segment prints inside itself and must hold a line of type; a grouped column prints past its end.\n if (insideAt(s, index)) {\n const ends = endsAt(s, index)\n if (!ends) return \"\"\n if (Math.abs(ends.end - ends.base) < valueSize(s) * VALUE_FIT) return \"\"\n }\n return bar.caption ?? formatMarker(bar.value)\n}\n\nfunction captionY(s: Columns, index: number): number {\n const ends = endsAt(s, index)\n if (!ends) return 0\n if (insideAt(s, index)) return (ends.base + ends.end) / 2\n // Text is centred on `y`: clear the end by the gap plus half a line, on the side the column reached.\n const direction = ends.end >= ends.base ? 1 : -1\n return ends.end + direction * (VALUE_GAP + valueSize(s) / 2)\n}\n\n/**\n * One series of a {@link BarChart}: its column in every category plus the\n * printed figures. A node per series, like `ChartLine`, so `showSeries` and\n * `spotlightSeries` mean the same on both: enable the node or tween its opacity.\n * Positions come from the parent, which owns the slot arithmetic.\n *\n * The figures are {@link Text} children, so they take the theme's type style,\n * are measured by layout, and hide with the series.\n */\nexport const ChartBars = component2d({\n key: \"chartBars\",\n state: {\n bars: fresh<BarGeometry[]>(() => []),\n /** Pixel y of value 0, where every column grows from. */\n baseline: 0,\n fill: Types.custom<Fill, FillResolved[]>([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n barStroke: Types.custom<Stroke, StrokeResolved[]>(DEFAULT_BAR_CHART_THEME.bar.stroke, { resolve: strokeOps.resolve, lerp: strokeOps.lerp }),\n barShadow: Types.custom<Shadow, ShadowResolved[]>(DEFAULT_BAR_CHART_THEME.bar.shadow, { resolve: shadowOps.resolve, lerp: shadowOps.lerp }),\n cornerRadius: DEFAULT_BAR_CHART_THEME.bar.cornerRadius,\n /**\n * Rise of every column in `[0, 1]` about the baseline, not each column's own\n * base: every segment travels by the same factor, so a stack stays flush\n * mid-animation and a negative column grows down.\n */\n growth: 1,\n /** Per-column opacity by row index, how the category spotlight reaches one column. Missing reads as 1. */\n dims: fresh<number[]>(() => []),\n showValues: false,\n valueStyle: Types.custom<TextStyle>(DEFAULT_BAR_CHART_THEME.valueStyle),\n /** The wholesale switch behind `showSeries`/`hideSeries`; off skips the columns and their figures. */\n enabled: true,\n },\n // A node made of its figures would otherwise hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n // One caption per column, built once (the row count is fixed at construction)\n // and bound to the live geometry so it travels with its column.\n children: (state) => {\n if (!state.showValues) return []\n return state.bars.map((_, i) =>\n Text({\n ...textOps.styleProps(state.valueStyle),\n text: () => captionAt(state, i),\n x: () => state.bars[i]?.x ?? 0,\n y: () => captionY(state, i),\n opacity: () => dimAt(state, i),\n })\n )\n },\n // The stroke and shadow sit past the conventional slots, so they are named here.\n load: (loader, state) =>\n loadPaints(loader, { fills: [state.fill], shadows: [state.barShadow], strokes: [state.barStroke] }),\n commands: {\n /** Raise every column from the baseline (`growth` 0 to 1). The resting state is the finished one; the chart arms it back to 0. */\n enter: (timeline) => {\n const ease = frameEase(timeline)\n return timeline.animate((t) => ({ growth: ease(t) }))\n },\n },\n render: (ctx, state) => {\n if (state.enabled) {\n for (let i = 0; i < state.bars.length; i++) {\n const bar = state.bars[i]\n const ends = endsAt(state, i)\n if (!ends || bar.width <= 0) continue\n const height = Math.abs(ends.end - ends.base)\n if (height <= 0) continue\n\n const radius = bar.round ? Math.min(state.cornerRadius, height) : 0\n // One `Graphics2D` per column: opacity belongs to the command list, and the spotlight dims single columns.\n const g = new Graphics2D()\n const rect = g.rect({\n x: bar.x,\n y: (ends.base + ends.end) / 2,\n width: bar.width,\n height,\n // Corner keys are visual (y-up): a column reaching up rounds `top*`, one reaching down `bottom*`. Only the far end rounds.\n cornerRadius:\n radius > 0\n ? ends.end >= ends.base\n ? { topLeft: radius, topRight: radius, bottomLeft: 0, bottomRight: 0 }\n : { bottomLeft: radius, bottomRight: radius, topLeft: 0, topRight: 0 }\n : 0,\n })\n rect.shadow(state.barShadow)\n rect.fill(state.fill)\n rect.stroke(state.barStroke)\n ctx.draw(g.opacity(dimAt(state, i)))\n }\n }\n ctx.children()\n },\n})\n\nexport type ChartBars = NodeOf<typeof ChartBars>\n"]}
1
+ {"version":3,"file":"chart-bars.js","sourceRoot":"","sources":["../../src/bar-chart/chart-bars.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,IAAI,EACJ,KAAK,EACL,KAAK,EACL,WAAW,EAC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AAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU;oBAC9C,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;oBACrG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;gBACxG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBAClB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YACtC,CAAC;QACH,CAAC;QACD,GAAG,CAAC,QAAQ,EAAE,CAAA;IAChB,CAAC;CACF,CAAC,CAAA;AAIF,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC","sourcesContent":["import {\n Graphics2D,\n Text,\n Types,\n clamp,\n component2d,\n fillOps,\n type Fill,\n type FillResolved,\n type NodeOf,\n // Named so this component's emitted type reaches `Node2D` and its props through the sdk, not core.\n type Node2D,\n type Node2DProps as _Node2DProps,\n type TextStyle,\n} from \"@motionscript/sdk\"\n\nimport { boundText } from \"../kit/cartesian\"\nimport { asParts, fresh } from \"../kit/entries\"\nimport { frameEase } from \"../kit/motion\"\nimport { loadPaints } from \"../kit/paints\"\nimport { formatMarker } from \"../kit/shared\"\nimport { inkOn } from \"./shared\"\n\n/**\n * One drawn bar in the plot's centred pixel space (origin at the centre, y-up),\n * mapped by the parent {@link BarChart}: `center` and `thickness` across the\n * category slot, `from` and `to` along the value axis (y for a column, x for a\n * horizontal bar). Two ends rather than a base and a length, like `BarSpan`:\n * one shape fits grouped, stacked and negative.\n */\nexport interface BarGeometry {\n center: number\n thickness: number\n /** The base: the baseline when grouped, the running stack end when stacked. */\n from: number\n /** The far end at full growth. */\n to: number\n /** Whether the far end takes the corner radius (the stack's last segment on its side). */\n round: boolean\n /** The figure printed by the bar; empty for none. */\n caption: string\n}\n\n/** A figure inside a bar needs this much room around it, in multiples of the type size. */\nconst INSIDE_ROOM = 0.6\n\ninterface Bars {\n readonly bars: readonly BarGeometry[]\n readonly baseline: number\n readonly horizontal: boolean\n readonly growth: number\n readonly dims: readonly number[]\n readonly enabled: boolean\n readonly values: \"none\" | \"end\" | \"inside\"\n readonly valueStyle: TextStyle\n}\n\n/** Bar `i`'s dimming: the category spotlight, then the series switch. */\nfunction dimAt(s: Bars, index: number): number {\n if (!s.enabled) return 0\n return clamp(s.dims[index] ?? 1, 0, 1)\n}\n\n/** Bar `i`'s two ends as grown so far, along the value axis. */\nfunction endsAt(s: Bars, index: number): { base: number; end: number } | null {\n const bar = s.bars[index]\n if (!bar) return null\n const g = clamp(s.growth, 0, 1)\n return { base: s.baseline + (bar.from - s.baseline) * g, end: s.baseline + (bar.to - s.baseline) * g }\n}\n\nfunction sizeOf(style: TextStyle): number {\n return typeof style.fontSize === \"number\" ? style.fontSize : 24\n}\n\n/** Where bar `i`'s figure sits along the value axis: past its end, or in its middle. */\nfunction captionAlong(s: Bars, index: number, extent: number): number {\n const ends = endsAt(s, index)\n if (!ends) return 0\n if (s.values === \"inside\") return (ends.base + ends.end) / 2\n const direction = ends.end >= ends.base ? 1 : -1\n return ends.end + direction * (sizeOf(s.valueStyle) * 0.4 + extent / 2)\n}\n\n/** Whether bar `i` has room for a figure `extent` long inside it. */\nfunction fitsInside(s: Bars, index: number, extent: number, across: number): boolean {\n const bar = s.bars[index]\n const ends = endsAt(s, index)\n if (!bar || !ends) return false\n const room = sizeOf(s.valueStyle) * INSIDE_ROOM\n return Math.abs(ends.end - ends.base) >= extent + room && bar.thickness >= across\n}\n\n/**\n * One series of a {@link BarChart}: its bar in every category plus the printed\n * figures. A node per series, like `ChartLine`, so `showSeries` and\n * `spotlightSeries` mean the same on both: enable the node or tween its opacity.\n * Positions come from the parent, which owns the slot arithmetic.\n */\nexport const ChartBars = component2d({\n key: \"chartBars\",\n state: {\n bars: fresh<BarGeometry[]>(() => []),\n /** Pixel position of value 0 along the value axis, where every bar grows from. */\n baseline: 0,\n /** Bars grow along x from a category column rather than along y from a row. */\n horizontal: false,\n fill: Types.custom<Fill, FillResolved[]>([], { resolve: fillOps.resolve, lerp: fillOps.lerp }),\n cornerRadius: 8,\n /**\n * Rise of every bar in `[0, 1]` about the baseline, not each bar's own base:\n * every segment travels by the same factor, so a stack stays flush\n * mid-animation and a negative bar grows the other way.\n */\n growth: 1,\n /** Per-bar opacity by row index, how the category spotlight reaches one bar. Missing reads as 1. */\n dims: fresh<number[]>(() => []),\n /** Read as built: whether each bar prints its figure, and where. */\n values: Types.custom<\"none\" | \"end\" | \"inside\">(\"none\"),\n valueStyle: Types.custom<TextStyle>({ fontSize: 24, fill: \"white\" }),\n /** The wholesale switch behind `showSeries`/`hideSeries`; off skips the bars and their figures. */\n enabled: true,\n },\n // A node made of its figures would otherwise hug them.\n defaults: { width: \"fill\", height: \"fill\" },\n // One figure per bar, built once (the row count is fixed at construction)\n // and bound to the live geometry so it travels with its bar.\n children: (state) => {\n if (state.values === \"none\") return []\n return asParts(state.bars.map((_, i) => {\n const caption: Node2D = new Text({\n ...boundText(() => ({ ...state.valueStyle, ...(state.values === \"inside\" && { fill: inkOn(state.fill) }) })),\n text: () => state.bars[i]?.caption ?? \"\",\n x: () => (state.horizontal ? captionAlong(state, i, caption.layoutBounds.width) : (state.bars[i]?.center ?? 0)),\n y: () => (state.horizontal ? (state.bars[i]?.center ?? 0) : captionAlong(state, i, caption.layoutBounds.height)),\n opacity: () => {\n const box = caption.layoutBounds\n const along = state.horizontal ? box.width : box.height\n const across = state.horizontal ? box.height : box.width\n if (state.values === \"inside\" && !fitsInside(state, i, along, across)) return 0\n // A figure past the end rises in with its bar's last stretch.\n return dimAt(state, i) * clamp((state.growth - 0.6) / 0.4, 0, 1)\n },\n }) as unknown as Node2D\n return caption\n }))\n },\n load: (loader, state) => loadPaints(loader, { fills: [state.fill] }),\n commands: {\n /** Raise every bar from the baseline (`growth` 0 to 1). The resting state is the finished one; the chart arms it back to 0. */\n enter: (timeline) => {\n const ease = frameEase(timeline)\n return timeline.animate((t) => ({ growth: ease(t) }))\n },\n },\n render: (ctx, state) => {\n if (state.enabled) {\n for (let i = 0; i < state.bars.length; i++) {\n const bar = state.bars[i]\n const ends = endsAt(state, i)\n if (!ends || bar.thickness <= 0) continue\n // A segment inside a stack reaches a pixel under the next, so no seam of background shows between them.\n const seam = bar.round ? 0 : 1\n const length = Math.abs(ends.end - ends.base) + seam\n if (length <= seam) continue\n const radius = bar.round ? Math.max(0, Math.min(state.cornerRadius, length, bar.thickness / 2)) : 0\n const forward = ends.end >= ends.base\n const mid = (ends.base + ends.end) / 2 + (forward ? seam : -seam) / 2\n // Corner keys are visual (y-up): only the far end rounds.\n const far = state.horizontal\n ? (forward ? { topRight: radius, bottomRight: radius, topLeft: 0, bottomLeft: 0 } : { topLeft: radius, bottomLeft: radius, topRight: 0, bottomRight: 0 })\n : (forward ? { topLeft: radius, topRight: radius, bottomLeft: 0, bottomRight: 0 } : { bottomLeft: radius, bottomRight: radius, topLeft: 0, topRight: 0 })\n // One `Graphics2D` per bar: opacity belongs to the command list, and the spotlight dims single bars.\n const g = new Graphics2D().rect(state.horizontal\n ? { x: mid, y: bar.center, width: length, height: bar.thickness, cornerRadius: radius > 0 ? far : 0 }\n : { x: bar.center, y: mid, width: bar.thickness, height: length, cornerRadius: radius > 0 ? far : 0 })\n g.fill(state.fill)\n ctx.draw(g.opacity(dimAt(state, i)))\n }\n }\n ctx.children()\n },\n})\n\nexport type ChartBars = NodeOf<typeof ChartBars>\n\n/** A figure as the bar prints it when the chart gives no caption. */\nexport function barCaption(value: number): string {\n return value === 0 ? \"\" : formatMarker(value)\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  export { BarChart, barChartDomain } from "./bar-chart.js";
2
- export type { BarChartDomain, BarChartValues } from "./bar-chart.js";
2
+ export type { BarChartDomain, BarChartStyle, BarChartValues } from "./bar-chart.js";
3
3
  export { ChartBars } from "./chart-bars.js";
4
4
  export type { BarGeometry } from "./chart-bars.js";
5
- export { CategoryAxis } from "./category-axis.js";
6
- export { DEFAULT_BAR_CHART_THEME, barCategories, barSpans, barValueExtent, lerpBarChartTheme, resolveBarChartTheme, resolveBarFill, resolveBarScale, stackCapIndex, } from "./shared.js";
7
- export type { BarChartConfig, BarChartTheme, BarSeries, BarSpan, BarStyleConfig, } from "./shared.js";
5
+ export { CategoryAxis, slotCentre } from "./category-axis.js";
6
+ export { BAR_LABELS, BAR_MARKS, barCategories, barSpans, barValueExtent, inkOn, resolveBarScale, } from "./shared.js";
7
+ export type { BarOrientation, BarSeries, BarSpan, BarStack, } from "./shared.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bar-chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,aAAa,GACd,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,cAAc,EACd,aAAa,EACb,SAAS,EACT,OAAO,EACP,cAAc,GACf,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bar-chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACtD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,cAAc,EACd,KAAK,EACL,eAAe,GAChB,MAAM,UAAU,CAAA;AACjB,YAAY,EACV,cAAc,EACd,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,UAAU,CAAA"}
@@ -1,5 +1,5 @@
1
1
  export { BarChart, barChartDomain } from "./bar-chart.js";
2
2
  export { ChartBars } from "./chart-bars.js";
3
- export { CategoryAxis } from "./category-axis.js";
4
- export { DEFAULT_BAR_CHART_THEME, barCategories, barSpans, barValueExtent, lerpBarChartTheme, resolveBarChartTheme, resolveBarFill, resolveBarScale, stackCapIndex, } from "./shared.js";
3
+ export { CategoryAxis, slotCentre } from "./category-axis.js";
4
+ export { BAR_LABELS, BAR_MARKS, barCategories, barSpans, barValueExtent, inkOn, resolveBarScale, } from "./shared.js";
5
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bar-chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,aAAa,GACd,MAAM,UAAU,CAAA","sourcesContent":["export { BarChart, barChartDomain } from \"./bar-chart\"\nexport type { BarChartDomain, BarChartValues } from \"./bar-chart\"\nexport { ChartBars } from \"./chart-bars\"\nexport type { BarGeometry } from \"./chart-bars\"\nexport { CategoryAxis } from \"./category-axis\"\nexport {\n DEFAULT_BAR_CHART_THEME,\n barCategories,\n barSpans,\n barValueExtent,\n lerpBarChartTheme,\n resolveBarChartTheme,\n resolveBarFill,\n resolveBarScale,\n stackCapIndex,\n} from \"./shared\"\nexport type {\n BarChartConfig,\n BarChartTheme,\n BarSeries,\n BarSpan,\n BarStyleConfig,\n} from \"./shared\"\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bar-chart/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAExC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,QAAQ,EACR,cAAc,EACd,KAAK,EACL,eAAe,GAChB,MAAM,UAAU,CAAA","sourcesContent":["export { BarChart, barChartDomain } from \"./bar-chart\"\nexport type { BarChartDomain, BarChartStyle, BarChartValues } from \"./bar-chart\"\nexport { ChartBars } from \"./chart-bars\"\nexport type { BarGeometry } from \"./chart-bars\"\nexport { CategoryAxis, slotCentre } from \"./category-axis\"\nexport {\n BAR_LABELS,\n BAR_MARKS,\n barCategories,\n barSpans,\n barValueExtent,\n inkOn,\n resolveBarScale,\n} from \"./shared\"\nexport type {\n BarOrientation,\n BarSeries,\n BarSpan,\n BarStack,\n} from \"./shared\"\n"]}
@@ -1,83 +1,54 @@
1
- import { type DataRecord, type Fill, type Shadow, type Stroke, type TextStyle } from "@motionscript/sdk";
2
- import { type AxisConfig, type ChartSeries, type LegendConfig, type LegendTheme, type PlotAreaConfig, type Range } from "../kit/shared.js";
1
+ import { type DataRecord, type Fill } from "@motionscript/sdk";
2
+ import { type ChartSeries, type Range } from "../kit/shared.js";
3
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. */
4
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";
5
9
  /**
6
- * One bar's span in data units. A span rather than a height because both modes
7
- * fit it, and a negative value just runs the other way with no special case.
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.
8
12
  */
9
13
  export interface BarSpan {
10
- /** Where the base sits: 0 when grouped, the running total below when stacked. */
14
+ /** Where the base sits: 0 apart, the running total below (or above, for a negative) when stacked. */
11
15
  from: number;
12
16
  to: number;
13
- /** `to - from`, kept for the figure printed on the bar. */
17
+ /** `to - from`. */
14
18
  value: number;
19
+ /** Whether it ends its stack on its side of zero, so its far end is rounded. */
20
+ outer: boolean;
15
21
  }
16
22
  /**
17
- * One row's spans, in series order. Stacking is a running sum in listed order,
18
- * so series 0 sits on the baseline. A zero value still yields a degenerate span,
19
- * keeping the list index-aligned with the series.
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.
20
28
  */
21
- export declare function barSpans(row: DataRecord, series: BarSeries[], stacked: boolean): BarSpan[];
22
- /**
23
- * The series ending a row's stack, which gets the rounded cap; `-1` when the row
24
- * is all zero. It is the last non-zero series, so a zero one does not take the
25
- * cap and leave the segment below square.
26
- */
27
- export declare function stackCapIndex(row: DataRecord, series: BarSeries[]): number;
29
+ export declare function barSpans(row: DataRecord, series: readonly BarSeries[], stack: BarStack, weights?: readonly number[]): BarSpan[];
28
30
  export declare function barCategories(data: DataRecord[], field: string): string[];
29
31
  /**
30
32
  * The `[min, max]` of everything drawn, zero always included: a scale starting
31
- * at 40 draws a column three times its neighbour for a 10% difference. A cropped
33
+ * at 40 draws a bar three times its neighbour for a 10% difference. A cropped
32
34
  * axis takes an explicit range.
33
35
  */
34
- export declare function barValueExtent(data: DataRecord[], series: BarSeries[], stacked: boolean): Range;
35
- /** The explicit `range`, else the data's extent nudged to tidy bounds; `divisions` (one fewer than the marker count) makes the drawn ticks land on them. */
36
- export declare function resolveBarScale(data: DataRecord[], series: BarSeries[], stacked: boolean, range: Range | undefined, divisions: number): Range;
37
- /** How the columns are drawn and the slot divided. */
38
- export interface BarStyleConfig {
39
- /** Radius in px of a column's far-end corners; an interior stacked segment stays square. */
40
- cornerRadius: number;
41
- /** Fraction of the category slot the bars fill, `[0, 1]`; the rest separates groups. */
42
- slotFill: number;
43
- /** Gap in px between grouped bars within a slot; ignored when stacked. */
44
- groupGap: number;
45
- stroke: Stroke;
46
- shadow: Shadow;
47
- }
48
- /** A {@link BarChart}'s full, resolved visual theme. */
49
- export interface BarChartConfig {
50
- /** Cycled by series index; a series' own `fill` replaces its entry outright. */
51
- seriesFills: Fill[];
52
- bar: BarStyleConfig;
53
- /** The category axis. */
54
- xAxis: AxisConfig;
55
- /** The value axis. */
56
- yAxis: AxisConfig;
57
- plotArea: PlotAreaConfig;
58
- legend: LegendConfig;
59
- /** The figure printed on each column. */
60
- valueStyle: TextStyle;
61
- /** How far everything outside a spotlit series or category fades. */
62
- spotlight: {
63
- dimOpacity: number;
64
- };
65
- }
66
- /** The author's partial theme, deep-merged onto {@link DEFAULT_BAR_CHART_THEME}. */
67
- export type BarChartTheme = {
68
- seriesFills?: Fill[];
69
- bar?: Partial<BarStyleConfig>;
70
- xAxis?: Partial<AxisConfig>;
71
- yAxis?: Partial<AxisConfig>;
72
- plotArea?: Partial<PlotAreaConfig>;
73
- legend?: LegendTheme;
74
- valueStyle?: TextStyle;
75
- spotlight?: Partial<BarChartConfig["spotlight"]>;
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>;
76
53
  };
77
- export declare const DEFAULT_BAR_CHART_THEME: BarChartConfig;
78
- /** The `theme` entry's resolve: merges a partial {@link BarChartTheme} onto `previous` (first resolution: the default). */
79
- export declare function resolveBarChartTheme(theme: BarChartTheme | undefined, previous?: BarChartConfig): BarChartConfig;
80
- export declare function lerpBarChartTheme(from: BarChartConfig, to: BarChartConfig, t: number): BarChartConfig;
81
- /** Series `index`'s own `fill`, else the palette's entry. */
82
- export declare function resolveBarFill(palette: Fill[], series: BarSeries, index: number): Fill;
83
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,OAAO,EAML,KAAK,UAAU,EACf,KAAK,IAAI,EACT,KAAK,MAAM,EAEX,KAAK,MAAM,EAEX,KAAK,SAAS,EACf,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAkBL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,KAAK,EACX,MAAM,eAAe,CAAA;AAEtB,+IAA+I;AAC/I,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AAEnC;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,iFAAiF;IACjF,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,2DAA2D;IAC3D,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,EAAE,OAAO,GACf,OAAO,EAAE,CASX;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAM1E;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,UAAU,EAAE,EAClB,MAAM,EAAE,SAAS,EAAE,EACnB,OAAO,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