@lostgradient/cinder 0.22.0 → 0.23.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.
- package/CHANGELOG.md +63 -0
- package/components.json +1 -1
- package/dist/_internal/chart/chart-bar-model.d.ts +24 -0
- package/dist/_internal/chart/chart-cartesian-model.d.ts +16 -0
- package/dist/_internal/chart/chart-layout.d.ts +23 -0
- package/dist/_internal/chart/chart-model-utilities.d.ts +157 -0
- package/dist/_internal/chart/chart-scale.d.ts +37 -0
- package/dist/_internal/chart/chart-utilities.d.ts +7 -164
- package/dist/_internal/chart/heatmap-utilities.d.ts +5 -4
- package/dist/components/_internal/chart-tooltip.css +21 -0
- package/dist/components/_internal/chart-tooltip.svelte.d.ts +11 -0
- package/dist/components/approval-card/index.js +5 -5
- package/dist/components/area-chart/area-chart.css +27 -23
- package/dist/components/area-chart/area-chart.schema.js +38 -1
- package/dist/components/area-chart/area-chart.types.d.ts +6 -2
- package/dist/components/area-chart/index.js +1589 -768
- package/dist/components/badge/badge.css +2 -2
- package/dist/components/badge/badge.schema.js +2 -2
- package/dist/components/badge/badge.types.d.ts +3 -3
- package/dist/components/badge/index.js +4 -4
- package/dist/components/bar-chart/bar-chart.css +27 -21
- package/dist/components/bar-chart/bar-chart.schema.js +38 -1
- package/dist/components/bar-chart/bar-chart.types.d.ts +7 -3
- package/dist/components/bar-chart/index.js +1544 -740
- package/dist/components/chart.types.d.ts +98 -2
- package/dist/components/json-schema-editor/index.js +4 -4
- package/dist/components/line-chart/index.js +1587 -785
- package/dist/components/line-chart/line-chart.css +25 -24
- package/dist/components/line-chart/line-chart.schema.js +38 -1
- package/dist/components/line-chart/line-chart.types.d.ts +6 -2
- package/dist/components/matrix-chart/index.js +1038 -429
- package/dist/components/matrix-chart/matrix-chart.css +12 -6
- package/dist/components/matrix-chart/matrix-chart.schema.js +26 -1
- package/dist/components/matrix-chart/matrix-chart.types.d.ts +5 -1
- package/dist/components/payload-inspector/index.js +4 -4
- package/dist/components/run-step-timeline/index.js +6 -6
- package/dist/components/sparkbar/index.js +1291 -4
- package/dist/components/sparkbar/sparkbar.css +5 -4
- package/dist/components/sparkbar/sparkbar.schema.js +26 -1
- package/dist/components/sparkbar/sparkbar.types.d.ts +5 -0
- package/dist/components/spectrogram/index.js +1076 -437
- package/dist/components/spectrogram/spectrogram.css +7 -6
- package/dist/components/spectrogram/spectrogram.schema.js +26 -1
- package/dist/components/spectrogram/spectrogram.types.d.ts +5 -1
- package/dist/components/spectrum-chart/index.js +1037 -423
- package/dist/components/spectrum-chart/spectrum-chart.css +8 -7
- package/dist/components/spectrum-chart/spectrum-chart.schema.js +26 -1
- package/dist/components/spectrum-chart/spectrum-chart.types.d.ts +5 -1
- package/dist/components/statistic/index.js +1288 -2
- package/dist/components/statistic/statistic.css +6 -5
- package/dist/components/statistic/statistic.schema.js +26 -1
- package/dist/components/statistic/statistic.types.d.ts +5 -0
- package/dist/components/statistic-group/index.js +1288 -2
- package/dist/components/waveform/index.js +1004 -404
- package/dist/components/waveform/waveform.css +8 -7
- package/dist/components/waveform/waveform.schema.js +26 -1
- package/dist/components/waveform/waveform.types.d.ts +5 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17734 -16540
- package/dist/server/components/approval-card/index.js +3 -3
- package/dist/server/components/area-chart/index.js +3 -3
- package/dist/server/components/badge/index.js +2 -2
- package/dist/server/components/bar-chart/index.js +3 -3
- package/dist/server/components/json-schema-editor/index.js +2 -2
- package/dist/server/components/line-chart/index.js +3 -3
- package/dist/server/components/matrix-chart/index.js +3 -3
- package/dist/server/components/payload-inspector/index.js +3 -3
- package/dist/server/components/run-step-timeline/index.js +2 -2
- package/dist/server/components/sparkbar/index.js +3 -2
- package/dist/server/components/spectrogram/index.js +3 -3
- package/dist/server/components/spectrum-chart/index.js +2 -2
- package/dist/server/components/statistic/index.js +4 -3
- package/dist/server/components/statistic-group/index.js +4 -3
- package/dist/server/components/waveform/index.js +2 -2
- package/dist/server/index.js +21 -21
- package/dist/server/{index.server-3dkwzkd3.js → index.server-10r7yf13.js} +110 -27
- package/dist/server/{index.server-pp2n6def.js → index.server-2y0xz53g.js} +37 -14
- package/dist/server/{index.server-bd8rcgf0.js → index.server-4hvjet4z.js} +1 -1
- package/dist/server/{index.server-bsm39gpy.js → index.server-5d83fkyg.js} +75 -21
- package/dist/server/{index.server-abqbstkt.js → index.server-9gj583qs.js} +41 -14
- package/dist/server/{index.server-2nmwsacy.js → index.server-9scm7zf9.js} +4 -4
- package/dist/server/{index.server-5j6jv7rm.js → index.server-9vwxyy06.js} +108 -29
- package/dist/server/{index.server-abjsjsw8.js → index.server-afpjvfz1.js} +111 -35
- package/dist/server/{index.server-wm8957be.js → index.server-bp0vzxby.js} +14 -1
- package/dist/server/{index.server-86sw5ea6.js → index.server-dw9bz17h.js} +4 -4
- package/dist/server/{index.server-d26jzn2m.js → index.server-en31rprd.js} +3 -3
- package/dist/server/{index.server-dx58qant.js → index.server-f3a0ecqg.js} +72 -9
- package/dist/server/{index.server-d63pwytk.js → index.server-kz8aeeq5.js} +18 -10
- package/dist/server/index.server-mmmrgvyd.js +1274 -0
- package/dist/server/{index.server-93943z3e.js → index.server-rx9aszk6.js} +1 -1
- package/dist/server/{index.server-1221p7e4.js → index.server-scahngwv.js} +13 -1
- package/dist/server/{index.server-nj8kk5bv.js → index.server-t73q59c1.js} +1 -1
- package/dist/server/{index.server-5schb2vt.js → index.server-tdrncj5e.js} +16 -6
- package/dist/server/{index.server-4wweyb2e.js → index.server-vnr1h5g5.js} +1 -1
- package/dist/server/{index.server-fphvzcfb.js → index.server-wqajghn9.js} +1 -1
- package/dist/server/{index.server-yd9shwqq.js → index.server-zjcjzcv6.js} +1 -1
- package/package.json +1 -1
- package/src/_internal/chart/chart-bar-model.ts +330 -0
- package/src/_internal/chart/chart-cartesian-model.ts +450 -0
- package/src/_internal/chart/chart-interaction.svelte.ts +25 -6
- package/src/_internal/chart/chart-layout.ts +348 -0
- package/src/_internal/chart/chart-model-utilities.ts +357 -0
- package/src/_internal/chart/chart-scale.ts +487 -0
- package/src/_internal/chart/chart-utilities.ts +22 -1078
- package/src/_internal/chart/heatmap-utilities.ts +21 -17
- package/src/components/_internal/chart-tooltip.css +21 -0
- package/src/components/_internal/chart-tooltip.svelte +44 -0
- package/src/components/approval-card/approval-card.svelte +1 -1
- package/src/components/area-chart/area-chart.css +27 -23
- package/src/components/area-chart/area-chart.examples.json +1 -1
- package/src/components/area-chart/area-chart.schema.json +37 -0
- package/src/components/area-chart/area-chart.schema.ts +40 -0
- package/src/components/area-chart/area-chart.svelte +103 -35
- package/src/components/area-chart/area-chart.types.ts +7 -1
- package/src/components/badge/badge.css +2 -2
- package/src/components/badge/badge.schema.json +1 -1
- package/src/components/badge/badge.schema.ts +1 -1
- package/src/components/badge/badge.svelte +2 -2
- package/src/components/badge/badge.types.ts +3 -3
- package/src/components/bar-chart/bar-chart.css +27 -21
- package/src/components/bar-chart/bar-chart.schema.json +37 -0
- package/src/components/bar-chart/bar-chart.schema.ts +40 -0
- package/src/components/bar-chart/bar-chart.svelte +94 -33
- package/src/components/bar-chart/bar-chart.types.ts +9 -2
- package/src/components/chart.types.ts +112 -2
- package/src/components/line-chart/line-chart.css +25 -24
- package/src/components/line-chart/line-chart.examples.json +1 -1
- package/src/components/line-chart/line-chart.schema.json +37 -0
- package/src/components/line-chart/line-chart.schema.ts +40 -0
- package/src/components/line-chart/line-chart.svelte +95 -40
- package/src/components/line-chart/line-chart.types.ts +7 -1
- package/src/components/matrix-chart/matrix-chart.css +12 -6
- package/src/components/matrix-chart/matrix-chart.schema.json +25 -0
- package/src/components/matrix-chart/matrix-chart.schema.ts +25 -0
- package/src/components/matrix-chart/matrix-chart.svelte +30 -12
- package/src/components/matrix-chart/matrix-chart.types.ts +5 -1
- package/src/components/run-step-timeline/run-step-timeline.svelte +2 -2
- package/src/components/sparkbar/sparkbar.css +5 -4
- package/src/components/sparkbar/sparkbar.schema.json +25 -0
- package/src/components/sparkbar/sparkbar.schema.ts +26 -0
- package/src/components/sparkbar/sparkbar.svelte +8 -1
- package/src/components/sparkbar/sparkbar.types.ts +5 -0
- package/src/components/spectrogram/spectrogram.css +7 -6
- package/src/components/spectrogram/spectrogram.schema.json +25 -0
- package/src/components/spectrogram/spectrogram.schema.ts +25 -0
- package/src/components/spectrogram/spectrogram.svelte +73 -28
- package/src/components/spectrogram/spectrogram.types.ts +5 -1
- package/src/components/spectrum-chart/spectrum-chart.css +8 -7
- package/src/components/spectrum-chart/spectrum-chart.schema.json +25 -0
- package/src/components/spectrum-chart/spectrum-chart.schema.ts +26 -0
- package/src/components/spectrum-chart/spectrum-chart.svelte +38 -12
- package/src/components/spectrum-chart/spectrum-chart.types.ts +5 -1
- package/src/components/statistic/statistic.css +6 -5
- package/src/components/statistic/statistic.schema.json +25 -0
- package/src/components/statistic/statistic.schema.ts +26 -0
- package/src/components/statistic/statistic.svelte +42 -1
- package/src/components/statistic/statistic.types.ts +5 -0
- package/src/components/waveform/waveform.css +8 -7
- package/src/components/waveform/waveform.schema.json +25 -0
- package/src/components/waveform/waveform.schema.ts +26 -0
- package/src/components/waveform/waveform.svelte +16 -3
- package/src/components/waveform/waveform.types.ts +5 -1
- package/src/index.ts +8 -0
- 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=
|
|
71
|
+
//# debugId=D4B957EDA584CB5464756E2164756E21
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
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=
|
|
234
|
+
//# debugId=A30082752EC1FED564756E2164756E21
|
package/package.json
CHANGED
|
@@ -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
|
+
*/
|