@lostgradient/cinder 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/components.json +1 -1
  3. package/dist/_internal/chart/chart-bar-model.d.ts +24 -0
  4. package/dist/_internal/chart/chart-cartesian-model.d.ts +16 -0
  5. package/dist/_internal/chart/chart-layout.d.ts +23 -0
  6. package/dist/_internal/chart/chart-model-utilities.d.ts +157 -0
  7. package/dist/_internal/chart/chart-scale.d.ts +37 -0
  8. package/dist/_internal/chart/chart-utilities.d.ts +7 -164
  9. package/dist/_internal/chart/heatmap-utilities.d.ts +5 -4
  10. package/dist/components/_internal/chart-tooltip.css +21 -0
  11. package/dist/components/_internal/chart-tooltip.svelte.d.ts +11 -0
  12. package/dist/components/approval-card/index.js +5 -5
  13. package/dist/components/area-chart/area-chart.css +27 -23
  14. package/dist/components/area-chart/area-chart.schema.js +38 -1
  15. package/dist/components/area-chart/area-chart.types.d.ts +6 -2
  16. package/dist/components/area-chart/index.js +1589 -768
  17. package/dist/components/badge/badge.css +2 -2
  18. package/dist/components/badge/badge.schema.js +2 -2
  19. package/dist/components/badge/badge.types.d.ts +3 -3
  20. package/dist/components/badge/index.js +4 -4
  21. package/dist/components/bar-chart/bar-chart.css +27 -21
  22. package/dist/components/bar-chart/bar-chart.schema.js +38 -1
  23. package/dist/components/bar-chart/bar-chart.types.d.ts +7 -3
  24. package/dist/components/bar-chart/index.js +1544 -740
  25. package/dist/components/chart.types.d.ts +98 -2
  26. package/dist/components/json-schema-editor/index.js +4 -4
  27. package/dist/components/line-chart/index.js +1587 -785
  28. package/dist/components/line-chart/line-chart.css +25 -24
  29. package/dist/components/line-chart/line-chart.schema.js +38 -1
  30. package/dist/components/line-chart/line-chart.types.d.ts +6 -2
  31. package/dist/components/matrix-chart/index.js +1038 -429
  32. package/dist/components/matrix-chart/matrix-chart.css +12 -6
  33. package/dist/components/matrix-chart/matrix-chart.schema.js +26 -1
  34. package/dist/components/matrix-chart/matrix-chart.types.d.ts +5 -1
  35. package/dist/components/payload-inspector/index.js +4 -4
  36. package/dist/components/run-step-timeline/index.js +6 -6
  37. package/dist/components/sparkbar/index.js +1291 -4
  38. package/dist/components/sparkbar/sparkbar.css +5 -4
  39. package/dist/components/sparkbar/sparkbar.schema.js +26 -1
  40. package/dist/components/sparkbar/sparkbar.types.d.ts +5 -0
  41. package/dist/components/spectrogram/index.js +1076 -437
  42. package/dist/components/spectrogram/spectrogram.css +7 -6
  43. package/dist/components/spectrogram/spectrogram.schema.js +26 -1
  44. package/dist/components/spectrogram/spectrogram.types.d.ts +5 -1
  45. package/dist/components/spectrum-chart/index.js +1037 -423
  46. package/dist/components/spectrum-chart/spectrum-chart.css +8 -7
  47. package/dist/components/spectrum-chart/spectrum-chart.schema.js +26 -1
  48. package/dist/components/spectrum-chart/spectrum-chart.types.d.ts +5 -1
  49. package/dist/components/statistic/index.js +1284 -2
  50. package/dist/components/statistic/statistic.css +6 -5
  51. package/dist/components/statistic/statistic.schema.js +26 -1
  52. package/dist/components/statistic/statistic.types.d.ts +5 -0
  53. package/dist/components/statistic-group/index.js +1284 -2
  54. package/dist/components/waveform/index.js +1004 -404
  55. package/dist/components/waveform/waveform.css +8 -7
  56. package/dist/components/waveform/waveform.schema.js +26 -1
  57. package/dist/components/waveform/waveform.types.d.ts +5 -1
  58. package/dist/index.d.ts +1 -1
  59. package/dist/index.js +17730 -16540
  60. package/dist/server/components/approval-card/index.js +3 -3
  61. package/dist/server/components/area-chart/index.js +3 -3
  62. package/dist/server/components/badge/index.js +2 -2
  63. package/dist/server/components/bar-chart/index.js +3 -3
  64. package/dist/server/components/json-schema-editor/index.js +2 -2
  65. package/dist/server/components/line-chart/index.js +3 -3
  66. package/dist/server/components/matrix-chart/index.js +3 -3
  67. package/dist/server/components/payload-inspector/index.js +3 -3
  68. package/dist/server/components/run-step-timeline/index.js +2 -2
  69. package/dist/server/components/sparkbar/index.js +3 -2
  70. package/dist/server/components/spectrogram/index.js +3 -3
  71. package/dist/server/components/spectrum-chart/index.js +2 -2
  72. package/dist/server/components/statistic/index.js +4 -3
  73. package/dist/server/components/statistic-group/index.js +4 -3
  74. package/dist/server/components/waveform/index.js +2 -2
  75. package/dist/server/index.js +21 -21
  76. package/dist/server/{index.server-3dkwzkd3.js → index.server-10r7yf13.js} +110 -27
  77. package/dist/server/{index.server-93943z3e.js → index.server-151dt1tx.js} +1 -1
  78. package/dist/server/{index.server-pp2n6def.js → index.server-2y0xz53g.js} +37 -14
  79. package/dist/server/{index.server-bd8rcgf0.js → index.server-4hvjet4z.js} +1 -1
  80. package/dist/server/{index.server-bsm39gpy.js → index.server-5d83fkyg.js} +75 -21
  81. package/dist/server/{index.server-4wweyb2e.js → index.server-8dh2rtnc.js} +1 -1
  82. package/dist/server/{index.server-abqbstkt.js → index.server-9gj583qs.js} +41 -14
  83. package/dist/server/{index.server-2nmwsacy.js → index.server-9scm7zf9.js} +4 -4
  84. package/dist/server/{index.server-5j6jv7rm.js → index.server-9vwxyy06.js} +108 -29
  85. package/dist/server/{index.server-abjsjsw8.js → index.server-afpjvfz1.js} +111 -35
  86. package/dist/server/{index.server-86sw5ea6.js → index.server-dw9bz17h.js} +4 -4
  87. package/dist/server/{index.server-d26jzn2m.js → index.server-en31rprd.js} +3 -3
  88. package/dist/server/{index.server-dx58qant.js → index.server-f3a0ecqg.js} +72 -9
  89. package/dist/server/{index.server-d63pwytk.js → index.server-kz8aeeq5.js} +18 -10
  90. package/dist/server/index.server-mmmrgvyd.js +1274 -0
  91. package/dist/server/{index.server-1221p7e4.js → index.server-scahngwv.js} +13 -1
  92. package/dist/server/{index.server-nj8kk5bv.js → index.server-t73q59c1.js} +1 -1
  93. package/dist/server/{index.server-5schb2vt.js → index.server-tdrncj5e.js} +16 -6
  94. package/dist/server/{index.server-wm8957be.js → index.server-veqke4sq.js} +10 -1
  95. package/dist/server/{index.server-fphvzcfb.js → index.server-wqajghn9.js} +1 -1
  96. package/dist/server/{index.server-yd9shwqq.js → index.server-zjcjzcv6.js} +1 -1
  97. package/package.json +1 -1
  98. package/src/_internal/chart/chart-bar-model.ts +330 -0
  99. package/src/_internal/chart/chart-cartesian-model.ts +450 -0
  100. package/src/_internal/chart/chart-interaction.svelte.ts +25 -6
  101. package/src/_internal/chart/chart-layout.ts +348 -0
  102. package/src/_internal/chart/chart-model-utilities.ts +357 -0
  103. package/src/_internal/chart/chart-scale.ts +487 -0
  104. package/src/_internal/chart/chart-utilities.ts +22 -1078
  105. package/src/_internal/chart/heatmap-utilities.ts +21 -17
  106. package/src/components/_internal/chart-tooltip.css +21 -0
  107. package/src/components/_internal/chart-tooltip.svelte +44 -0
  108. package/src/components/approval-card/approval-card.svelte +1 -1
  109. package/src/components/area-chart/area-chart.css +27 -23
  110. package/src/components/area-chart/area-chart.examples.json +1 -1
  111. package/src/components/area-chart/area-chart.schema.json +37 -0
  112. package/src/components/area-chart/area-chart.schema.ts +40 -0
  113. package/src/components/area-chart/area-chart.svelte +103 -35
  114. package/src/components/area-chart/area-chart.types.ts +7 -1
  115. package/src/components/badge/badge.css +2 -2
  116. package/src/components/badge/badge.schema.json +1 -1
  117. package/src/components/badge/badge.schema.ts +1 -1
  118. package/src/components/badge/badge.svelte +2 -2
  119. package/src/components/badge/badge.types.ts +3 -3
  120. package/src/components/bar-chart/bar-chart.css +27 -21
  121. package/src/components/bar-chart/bar-chart.schema.json +37 -0
  122. package/src/components/bar-chart/bar-chart.schema.ts +40 -0
  123. package/src/components/bar-chart/bar-chart.svelte +94 -33
  124. package/src/components/bar-chart/bar-chart.types.ts +9 -2
  125. package/src/components/chart.types.ts +112 -2
  126. package/src/components/line-chart/line-chart.css +25 -24
  127. package/src/components/line-chart/line-chart.examples.json +1 -1
  128. package/src/components/line-chart/line-chart.schema.json +37 -0
  129. package/src/components/line-chart/line-chart.schema.ts +40 -0
  130. package/src/components/line-chart/line-chart.svelte +95 -40
  131. package/src/components/line-chart/line-chart.types.ts +7 -1
  132. package/src/components/matrix-chart/matrix-chart.css +12 -6
  133. package/src/components/matrix-chart/matrix-chart.schema.json +25 -0
  134. package/src/components/matrix-chart/matrix-chart.schema.ts +25 -0
  135. package/src/components/matrix-chart/matrix-chart.svelte +30 -12
  136. package/src/components/matrix-chart/matrix-chart.types.ts +5 -1
  137. package/src/components/run-step-timeline/run-step-timeline.svelte +2 -2
  138. package/src/components/sparkbar/sparkbar.css +5 -4
  139. package/src/components/sparkbar/sparkbar.schema.json +25 -0
  140. package/src/components/sparkbar/sparkbar.schema.ts +26 -0
  141. package/src/components/sparkbar/sparkbar.svelte +8 -1
  142. package/src/components/sparkbar/sparkbar.types.ts +5 -0
  143. package/src/components/spectrogram/spectrogram.css +7 -6
  144. package/src/components/spectrogram/spectrogram.schema.json +25 -0
  145. package/src/components/spectrogram/spectrogram.schema.ts +25 -0
  146. package/src/components/spectrogram/spectrogram.svelte +73 -28
  147. package/src/components/spectrogram/spectrogram.types.ts +5 -1
  148. package/src/components/spectrum-chart/spectrum-chart.css +8 -7
  149. package/src/components/spectrum-chart/spectrum-chart.schema.json +25 -0
  150. package/src/components/spectrum-chart/spectrum-chart.schema.ts +26 -0
  151. package/src/components/spectrum-chart/spectrum-chart.svelte +38 -12
  152. package/src/components/spectrum-chart/spectrum-chart.types.ts +5 -1
  153. package/src/components/statistic/statistic.css +6 -5
  154. package/src/components/statistic/statistic.schema.json +25 -0
  155. package/src/components/statistic/statistic.schema.ts +26 -0
  156. package/src/components/statistic/statistic.svelte +6 -1
  157. package/src/components/statistic/statistic.types.ts +5 -0
  158. package/src/components/waveform/waveform.css +8 -7
  159. package/src/components/waveform/waveform.schema.json +25 -0
  160. package/src/components/waveform/waveform.schema.ts +26 -0
  161. package/src/components/waveform/waveform.svelte +16 -3
  162. package/src/components/waveform/waveform.types.ts +5 -1
  163. package/src/index.ts +8 -0
  164. package/dist/server/index.server-6vbpz6dd.js +0 -690
@@ -1,3 +1,7 @@
1
+ import {
2
+ chartPaletteColor,
3
+ resolveChartTheme
4
+ } from "./index.server-mmmrgvyd.js";
1
5
  import {
2
6
  classNames
3
7
  } from "./index.server-z7nvkz8v.js";
@@ -13,6 +17,7 @@ function Sparkbar($$renderer, $$props) {
13
17
  trailing,
14
18
  size = "md",
15
19
  variant = "accent",
20
+ theme,
16
21
  ariaLabel,
17
22
  ariaValueText,
18
23
  class: customClassName,
@@ -28,6 +33,7 @@ function Sparkbar($$renderer, $$props) {
28
33
  const normalizedAriaValueText = $.derived(() => ariaValueText?.trim() || undefined);
29
34
  const accessibleName = $.derived(() => normalizedAriaLabel() ?? `${label}, ${percent()}%`);
30
35
  const accessibleValueText = $.derived(() => normalizedAriaValueText() ?? normalizedTrailing());
36
+ const resolvedTheme = $.derived(() => resolveChartTheme(theme));
31
37
  $$renderer2.push(`<div${$.attributes({
32
38
  ...rest,
33
39
  class: $.clsx(classNames("cinder-sparkbar", customClassName)),
@@ -39,6 +45,12 @@ function Sparkbar($$renderer, $$props) {
39
45
  "aria-valuetext": accessibleValueText(),
40
46
  "data-cinder-size": size,
41
47
  "data-cinder-variant": variant
48
+ }, undefined, undefined, {
49
+ "--_cinder-chart-foreground": resolvedTheme().foreground,
50
+ "--_cinder-chart-muted": resolvedTheme().muted,
51
+ "--_cinder-chart-background": resolvedTheme().background,
52
+ "--_cinder-chart-accent": chartPaletteColor(0, resolvedTheme().palette),
53
+ "--_cinder-sparkbar-track-background": theme?.background ?? "var(--cinder-surface-inset)"
42
54
  })}><div class="cinder-sparkbar__row"><span class="cinder-sparkbar__label">${$.escape(label)}</span> `);
43
55
  if (normalizedTrailing()) {
44
56
  $$renderer2.push("<!--[0-->");
@@ -56,4 +68,4 @@ function Sparkbar($$renderer, $$props) {
56
68
  var sparkbar_default = Sparkbar;
57
69
  export { Sparkbar, sparkbar_default };
58
70
 
59
- //# debugId=9B0C7A4786C55C3264756E2164756E21
71
+ //# debugId=D4B957EDA584CB5464756E2164756E21
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Badge
3
- } from "./index.server-d26jzn2m.js";
3
+ } from "./index.server-en31rprd.js";
4
4
 
5
5
  // src/components/badge/index.ts
6
6
  var badge_default = Badge;
@@ -1,6 +1,8 @@
1
1
  import {
2
- dataTableClass
3
- } from "./index.server-6vbpz6dd.js";
2
+ chartPaletteColor,
3
+ dataTableClass,
4
+ resolveChartTheme
5
+ } from "./index.server-mmmrgvyd.js";
4
6
  import {
5
7
  useResizeObserver
6
8
  } from "./index.server-6gzzpcyd.js";
@@ -22,6 +24,7 @@ function Waveform($$renderer, $$props) {
22
24
  loading = false,
23
25
  dataTableVisibility = "screen-reader-only",
24
26
  dataTableCaption,
27
+ theme,
25
28
  class: customClassName,
26
29
  empty,
27
30
  loadingContent,
@@ -32,6 +35,7 @@ function Waveform($$renderer, $$props) {
32
35
  } = $$props;
33
36
  const rootId = $.derived(() => id ?? generatedId);
34
37
  const descriptionId = $.derived(() => description ? `${rootId()}-description` : undefined);
38
+ const resolvedTheme = $.derived(() => resolveChartTheme(theme));
35
39
  let measuredWidth = 400;
36
40
  const observeResize = useResizeObserver((entries) => {
37
41
  const entry = entries[0];
@@ -137,6 +141,12 @@ function Waveform($$renderer, $$props) {
137
141
  "aria-label": label,
138
142
  "aria-describedby": descriptionId(),
139
143
  "data-cinder-render-mode": renderMode
144
+ }, undefined, undefined, {
145
+ "--_cinder-chart-foreground": resolvedTheme().foreground,
146
+ "--_cinder-chart-muted": resolvedTheme().muted,
147
+ "--_cinder-chart-grid": resolvedTheme().grid,
148
+ "--_cinder-chart-background": resolvedTheme().background,
149
+ "--_cinder-chart-series-color": chartPaletteColor(0, resolvedTheme().palette)
140
150
  })}>`);
141
151
  if (description) {
142
152
  $$renderer2.push("<!--[0-->");
@@ -182,19 +192,19 @@ function Waveform($$renderer, $$props) {
182
192
  $$renderer2.push(`<!--]-->`);
183
193
  if (!loading && !isEmpty()) {
184
194
  $$renderer2.push("<!--[0-->");
185
- $$renderer2.push(`<line class="cinder-waveform__baseline" x1="0"${$.attr("x2", measuredWidth)}${$.attr("y1", midY())}${$.attr("y2", midY())} aria-hidden="true"></line>`);
195
+ $$renderer2.push(`<line class="cinder-waveform__baseline" x1="0"${$.attr("x2", measuredWidth)}${$.attr("y1", midY())}${$.attr("y2", midY())}${$.attr("stroke", resolvedTheme().grid)} aria-hidden="true"></line>`);
186
196
  if (renderMode === "bars") {
187
197
  $$renderer2.push("<!--[0-->");
188
198
  $$renderer2.push(`<!--[-->`);
189
199
  const each_array = $.ensure_array_like(waveformBars());
190
200
  for (let index = 0, $$length = each_array.length;index < $$length; index++) {
191
201
  let bar = each_array[index];
192
- $$renderer2.push(`<rect class="cinder-waveform__bar"${$.attr("x", bar.x)}${$.attr("y", bar.y)}${$.attr("width", bar.width)}${$.attr("height", bar.height)} aria-hidden="true"></rect>`);
202
+ $$renderer2.push(`<rect class="cinder-waveform__bar"${$.attr("x", bar.x)}${$.attr("y", bar.y)}${$.attr("width", bar.width)}${$.attr("height", bar.height)}${$.attr("fill", chartPaletteColor(0, resolvedTheme().palette))} aria-hidden="true"></rect>`);
193
203
  }
194
204
  $$renderer2.push(`<!--]-->`);
195
205
  } else {
196
206
  $$renderer2.push("<!--[-1-->");
197
- $$renderer2.push(`<path class="cinder-waveform__path"${$.attr("d", waveformPath())} aria-hidden="true"></path>`);
207
+ $$renderer2.push(`<path class="cinder-waveform__path"${$.attr("d", waveformPath())}${$.attr("stroke", chartPaletteColor(0, resolvedTheme().palette))} aria-hidden="true"></path>`);
198
208
  }
199
209
  $$renderer2.push(`<!--]-->`);
200
210
  } else {
@@ -221,4 +231,4 @@ function Waveform($$renderer, $$props) {
221
231
  var waveform_default = Waveform;
222
232
  export { Waveform, waveform_default };
223
233
 
224
- //# debugId=7D2C857152B6849C64756E2164756E21
234
+ //# debugId=A30082752EC1FED564756E2164756E21
@@ -4,6 +4,9 @@ import {
4
4
  import {
5
5
  getLocaleContext
6
6
  } from "./index.server-sz8sxsj6.js";
7
+ import {
8
+ resolveChartTheme
9
+ } from "./index.server-mmmrgvyd.js";
7
10
  import {
8
11
  classNames
9
12
  } from "./index.server-z7nvkz8v.js";
@@ -18,6 +21,7 @@ function Statistic($$renderer, $$props) {
18
21
  value,
19
22
  change,
20
23
  icon,
24
+ theme,
21
25
  valueFormatOptions,
22
26
  valueLocale,
23
27
  class: customClassName,
@@ -44,6 +48,7 @@ function Statistic($$renderer, $$props) {
44
48
  return `decreased by ${change.value}${suffix}`;
45
49
  return `no change, ${change.value}${suffix}`;
46
50
  });
51
+ const resolvedTheme = $.derived(() => resolveChartTheme(theme));
47
52
  $$renderer2.push(`<div${$.attributes({
48
53
  ...rest,
49
54
  id,
@@ -51,6 +56,10 @@ function Statistic($$renderer, $$props) {
51
56
  role: "group",
52
57
  "aria-labelledby": `${labelId()} ${valueId()}`,
53
58
  "data-cinder-has-icon": icon ? "" : undefined
59
+ }, undefined, undefined, {
60
+ "--_cinder-chart-foreground": resolvedTheme().foreground,
61
+ "--_cinder-chart-muted": resolvedTheme().muted,
62
+ "--_cinder-chart-background": resolvedTheme().background
54
63
  })}>`);
55
64
  if (icon) {
56
65
  $$renderer2.push("<!--[0-->");
@@ -80,4 +89,4 @@ function Statistic($$renderer, $$props) {
80
89
 
81
90
  export { Statistic };
82
91
 
83
- //# debugId=E5A71842EAA13E7A64756E2164756E21
92
+ //# debugId=E1E126A5413A462064756E2164756E21
@@ -6,7 +6,7 @@ import {
6
6
  } from "./index.server-e97zrck0.js";
7
7
  import {
8
8
  Badge
9
- } from "./index.server-d26jzn2m.js";
9
+ } from "./index.server-en31rprd.js";
10
10
  import {
11
11
  classNames
12
12
  } from "./index.server-z7nvkz8v.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Payload_inspector
3
- } from "./index.server-fphvzcfb.js";
3
+ } from "./index.server-wqajghn9.js";
4
4
 
5
5
  // src/components/payload-inspector/index.ts
6
6
  var payload_inspector_default = Payload_inspector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lostgradient/cinder",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "A Svelte 5 component library and design system focused on accessibility, theming, and per-component tree-shaking.",
5
5
  "keywords": [
6
6
  "svelte",
@@ -0,0 +1,330 @@
1
+ import type {
2
+ BarChartDatum,
3
+ BarChartMode,
4
+ BarChartOrientation,
5
+ BarChartSeries,
6
+ ChartAxisConfiguration,
7
+ ChartTheme,
8
+ ChartXAxisConfiguration,
9
+ } from '../../components/chart.types.ts';
10
+ import {
11
+ createChartGeometry,
12
+ createHorizontalCategoryLabelLayout,
13
+ HORIZONTAL_CATEGORY_LABEL_GAP,
14
+ } from './chart-layout.ts';
15
+ import {
16
+ assertUniqueSeriesIds,
17
+ assertValidChartNumber,
18
+ assertValidTickCount,
19
+ chartPaletteColor,
20
+ formatNumericValue,
21
+ formatXValue,
22
+ normalizeXValue,
23
+ resolveChartTheme,
24
+ type BarChartModel,
25
+ type ChartTarget,
26
+ type NormalizedXValue,
27
+ } from './chart-model-utilities.ts';
28
+ import {
29
+ createBandScale,
30
+ createLinearScale,
31
+ createPaddedDomain,
32
+ createStackedBarDomainValues,
33
+ createTicks,
34
+ normalizeNumericValue,
35
+ sortXValues,
36
+ } from './chart-scale.ts';
37
+ export function createBarModel(options: {
38
+ data: BarChartDatum[];
39
+ categoryKey: string;
40
+ series: BarChartSeries[];
41
+ hiddenSeriesIds: string[];
42
+ width: number;
43
+ height: number;
44
+ orientation: BarChartOrientation;
45
+ mode: BarChartMode;
46
+ xAxis?: ChartXAxisConfiguration | undefined;
47
+ yAxis?: ChartAxisConfiguration | undefined;
48
+ theme?: ChartTheme | undefined;
49
+ measureText?: boolean | undefined;
50
+ measurementElement?: Element | undefined;
51
+ measurementVersion?: number | undefined;
52
+ }): BarChartModel {
53
+ const {
54
+ data,
55
+ categoryKey,
56
+ series,
57
+ hiddenSeriesIds,
58
+ width,
59
+ height,
60
+ orientation,
61
+ mode,
62
+ xAxis,
63
+ yAxis,
64
+ theme,
65
+ measureText = false,
66
+ measurementElement,
67
+ measurementVersion = 0,
68
+ } = options;
69
+ assertUniqueSeriesIds('bar-chart', series);
70
+ assertValidChartNumber('bar-chart', 'invalid-height', height, 'height');
71
+ assertValidTickCount('bar-chart', xAxis);
72
+ assertValidTickCount('bar-chart', yAxis);
73
+ const resolvedTheme = resolveChartTheme(theme);
74
+
75
+ const categories: NormalizedXValue[] = [];
76
+ const seenCategories = new Set<string>();
77
+ const categoryKinds = new Set<string>();
78
+ const visibleSeries = series.filter((item) => !hiddenSeriesIds.includes(item.id));
79
+ const visibleValues: number[] = [0];
80
+ // Build a key-keyed lookup once so the render loop is O(categories), not
81
+ // O(categories * rows) with allocations per probe.
82
+ const datumByKey = new Map<string, BarChartDatum>();
83
+
84
+ for (const datum of data) {
85
+ if (!(categoryKey in datum)) {
86
+ throw new Error(
87
+ `[cinder/bar-chart] rule=invalid-bar-category key="${categoryKey}": category key is missing.`,
88
+ );
89
+ }
90
+ const rawCategory = datum[categoryKey];
91
+ if (
92
+ !(
93
+ typeof rawCategory === 'string' ||
94
+ typeof rawCategory === 'number' ||
95
+ rawCategory instanceof Date
96
+ )
97
+ ) {
98
+ throw new Error(
99
+ `[cinder/bar-chart] rule=invalid-bar-category key="${categoryKey}": category must be string, number, or Date.`,
100
+ );
101
+ }
102
+ const category = normalizeXValue(rawCategory);
103
+ categoryKinds.add(category.kind);
104
+ if (seenCategories.has(category.key)) {
105
+ throw new Error(
106
+ `[cinder/bar-chart] rule=duplicate-category key="${categoryKey}" category="${category.label}": duplicate categories are not supported.`,
107
+ );
108
+ }
109
+ seenCategories.add(category.key);
110
+ categories.push(category);
111
+ datumByKey.set(category.key, datum);
112
+ for (const item of series) {
113
+ if (!(item.valueKey in datum)) {
114
+ throw new Error(
115
+ `[cinder/bar-chart] rule=missing-bar-value-key key="${item.valueKey}": value key is missing.`,
116
+ );
117
+ }
118
+ const value = datum[item.valueKey];
119
+ if (!(typeof value === 'number' || value === null || value === undefined)) {
120
+ throw new Error(
121
+ `[cinder/bar-chart] rule=invalid-bar-value key="${item.valueKey}" category="${category.label}": value must be number, null, or undefined.`,
122
+ );
123
+ }
124
+ const numericValue = normalizeNumericValue('bar-chart', item.id, category.label, value);
125
+ if (numericValue !== null && !hiddenSeriesIds.includes(item.id))
126
+ visibleValues.push(numericValue);
127
+ }
128
+ }
129
+
130
+ if (categoryKinds.size > 1) {
131
+ throw new Error(
132
+ `[cinder/bar-chart] rule=mixed-bar-category-kind key="${categoryKey}": category values must share one domain kind.`,
133
+ );
134
+ }
135
+
136
+ const sortedCategories = sortXValues(categories);
137
+ const categoryLabels = sortedCategories.map((category, index) =>
138
+ formatXValue(category, orientation === 'vertical' ? xAxis : yAxis, { index }),
139
+ );
140
+ const horizontalCategoryLabelLayout =
141
+ orientation === 'horizontal'
142
+ ? createHorizontalCategoryLabelLayout(categoryLabels, width, {
143
+ measureText,
144
+ measurementElement,
145
+ measurementVersion,
146
+ })
147
+ : undefined;
148
+ // Domain is computed from visible series only — same convention as cartesian
149
+ // charts — so the value scale shrinks correctly when a series is hidden.
150
+ const valueDomain = createPaddedDomain(
151
+ mode === 'stacked'
152
+ ? createStackedBarDomainValues(datumByKey, sortedCategories, visibleSeries)
153
+ : visibleValues,
154
+ );
155
+ const valueTickAxis = orientation === 'vertical' ? yAxis : xAxis;
156
+ const valueTicks = createTicks(valueDomain, valueTickAxis?.tickCount ?? 5);
157
+ const valueTickLabels = valueTicks.map((tick, index) =>
158
+ formatNumericValue(tick, valueTickAxis, undefined, { index }),
159
+ );
160
+ const geometry = createChartGeometry(width, height, {
161
+ xTickLabels: orientation === 'vertical' ? categoryLabels : valueTickLabels,
162
+ yTickLabels: orientation === 'vertical' ? valueTickLabels : categoryLabels,
163
+ xAxis,
164
+ yAxis,
165
+ measureText,
166
+ measurementElement,
167
+ measurementVersion,
168
+ marginLeft: horizontalCategoryLabelLayout?.marginLeft,
169
+ });
170
+ if (sortedCategories.length === 0) {
171
+ return {
172
+ geometry,
173
+ categories: [],
174
+ yTicks: valueTicks,
175
+ categoryTicks: [],
176
+ bars: [],
177
+ tableRows: [],
178
+ targets: [],
179
+ empty: true,
180
+ valueDomain,
181
+ theme: resolvedTheme,
182
+ };
183
+ }
184
+ const valueScale = createLinearScale(
185
+ valueDomain,
186
+ orientation === 'vertical' ? [geometry.plotHeight, 0] : [0, geometry.plotWidth],
187
+ );
188
+ const categoryScale = createBandScale(
189
+ sortedCategories.map((category) => category.key),
190
+ orientation === 'vertical' ? [0, geometry.plotWidth] : [0, geometry.plotHeight],
191
+ 0.18,
192
+ );
193
+ const groupScale = createBandScale(
194
+ visibleSeries.map((item) => item.id),
195
+ [0, categoryScale.bandwidth()],
196
+ 0.12,
197
+ );
198
+ const categoryTicks = sortedCategories.map((category, index) => {
199
+ const categoryPosition = categoryScale(category.key) ?? 0;
200
+ return {
201
+ categoryKey: category.key,
202
+ label:
203
+ horizontalCategoryLabelLayout?.labels[index] ?? categoryLabels[index] ?? category.label,
204
+ fullLabel: categoryLabels[index] ?? category.label,
205
+ x:
206
+ orientation === 'vertical'
207
+ ? categoryPosition + categoryScale.bandwidth() / 2
208
+ : -HORIZONTAL_CATEGORY_LABEL_GAP,
209
+ y:
210
+ orientation === 'vertical'
211
+ ? geometry.plotHeight + 20
212
+ : categoryPosition + categoryScale.bandwidth() / 2,
213
+ };
214
+ });
215
+
216
+ const bars: BarChartModel['bars'] = [];
217
+ const targets: ChartTarget[] = [];
218
+ const tableRows: BarChartModel['tableRows'] = [];
219
+ for (const [categoryIndex, category] of sortedCategories.entries()) {
220
+ const datum = datumByKey.get(category.key);
221
+ if (!datum) continue;
222
+ let positiveOffset = 0;
223
+ let negativeOffset = 0;
224
+ const rowValues: BarChartModel['tableRows'][number]['values'] = [];
225
+ visibleSeries.forEach((item) => {
226
+ const rawValue = datum[item.valueKey];
227
+ if (typeof rawValue !== 'number') return;
228
+ const value = rawValue;
229
+ const seriesColorIndex = Math.max(
230
+ 0,
231
+ series.findIndex((entry) => entry.id === item.id),
232
+ );
233
+ const color = item.color ?? chartPaletteColor(seriesColorIndex, resolvedTheme.palette);
234
+ const categoryPosition = categoryScale(category.key) ?? 0;
235
+ let x = 0;
236
+ let y = 0;
237
+ let barWidth = 0;
238
+ let barHeight = 0;
239
+ if (orientation === 'vertical') {
240
+ const groupX = mode === 'grouped' ? (groupScale(item.id) ?? 0) : 0;
241
+ const start = mode === 'stacked' ? (value >= 0 ? positiveOffset : negativeOffset) : 0;
242
+ const end = start + value;
243
+ if (mode === 'stacked') {
244
+ if (value >= 0) positiveOffset = end;
245
+ else negativeOffset = end;
246
+ }
247
+ const y0 = valueScale(start);
248
+ const y1 = valueScale(end);
249
+ x = categoryPosition + groupX;
250
+ y = Math.min(y0, y1);
251
+ barWidth = mode === 'grouped' ? groupScale.bandwidth() : categoryScale.bandwidth();
252
+ barHeight = Math.abs(y1 - y0);
253
+ } else {
254
+ const groupY = mode === 'grouped' ? (groupScale(item.id) ?? 0) : 0;
255
+ const start = mode === 'stacked' ? (value >= 0 ? positiveOffset : negativeOffset) : 0;
256
+ const end = start + value;
257
+ if (mode === 'stacked') {
258
+ if (value >= 0) positiveOffset = end;
259
+ else negativeOffset = end;
260
+ }
261
+ const x0 = valueScale(start);
262
+ const x1 = valueScale(end);
263
+ x = Math.min(x0, x1);
264
+ y = categoryPosition + groupY;
265
+ barWidth = Math.abs(x1 - x0);
266
+ barHeight = mode === 'grouped' ? groupScale.bandwidth() : categoryScale.bandwidth();
267
+ }
268
+ const valueLabel = formatNumericValue(
269
+ value,
270
+ orientation === 'vertical' ? yAxis : xAxis,
271
+ item.valueFormatter,
272
+ { seriesId: item.id, seriesLabel: item.label, index: categoryIndex },
273
+ );
274
+ const categoryLabel = formatXValue(category, orientation === 'vertical' ? xAxis : yAxis, {
275
+ seriesId: item.id,
276
+ seriesLabel: item.label,
277
+ index: categoryIndex,
278
+ });
279
+ rowValues.push({ seriesId: item.id, seriesLabel: item.label, valueLabel });
280
+ const bar = {
281
+ id: `${item.id}-${category.key}`,
282
+ seriesId: item.id,
283
+ seriesLabel: item.label,
284
+ categoryLabel,
285
+ valueLabel,
286
+ x,
287
+ y,
288
+ width: barWidth,
289
+ height: barHeight,
290
+ color,
291
+ hidden: false,
292
+ };
293
+ bars.push(bar);
294
+ targets.push({ ...bar, x: x + barWidth / 2, y: y + barHeight / 2, xLabel: categoryLabel });
295
+ });
296
+ if (rowValues.length > 0) {
297
+ tableRows.push({
298
+ categoryKey: category.key,
299
+ categoryLabel: formatXValue(category, orientation === 'vertical' ? xAxis : yAxis, {
300
+ index: tableRows.length,
301
+ }),
302
+ values: rowValues,
303
+ });
304
+ }
305
+ }
306
+
307
+ // Sort targets by the dominant axis for binary-search nearestTarget. For
308
+ // vertical bars the dominant axis is x; for horizontal bars it is y.
309
+ targets.sort((a, b) => (orientation === 'vertical' ? a.x - b.x : a.y - b.y));
310
+
311
+ return {
312
+ geometry,
313
+ categories: sortedCategories,
314
+ yTicks: valueTicks,
315
+ categoryTicks,
316
+ bars,
317
+ tableRows,
318
+ targets,
319
+ empty: targets.length === 0,
320
+ valueDomain,
321
+ theme: resolvedTheme,
322
+ };
323
+ }
324
+
325
+ /**
326
+ * Locates the target closest to a (x, y) pointer. Uses binary search on the
327
+ * provided `axis` (defaults to `x`) — targets MUST be sorted ascending on that
328
+ * axis (createCartesianModel and createBarModel guarantee this). Falls back to
329
+ * a linear scan when targets are empty.
330
+ */