@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,690 +0,0 @@
|
|
|
1
|
-
// src/_internal/chart/chart-utilities.ts
|
|
2
|
-
var chartPalette = [
|
|
3
|
-
"var(--cinder-chart-series-1)",
|
|
4
|
-
"var(--cinder-chart-series-2)",
|
|
5
|
-
"var(--cinder-chart-series-3)",
|
|
6
|
-
"var(--cinder-chart-series-4)",
|
|
7
|
-
"var(--cinder-chart-series-5)",
|
|
8
|
-
"var(--cinder-chart-series-6)",
|
|
9
|
-
"var(--cinder-chart-series-7)",
|
|
10
|
-
"var(--cinder-chart-series-8)"
|
|
11
|
-
];
|
|
12
|
-
function chartPaletteColor(index) {
|
|
13
|
-
return chartPalette[index % chartPalette.length] ?? "var(--cinder-chart-series-1)";
|
|
14
|
-
}
|
|
15
|
-
function assertValidChartNumber(componentId, rule, value, label) {
|
|
16
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
17
|
-
throw new Error(`[cinder/${componentId}] rule=${rule} ${label}="${value}": expected a positive finite number.`);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function assertValidTickCount(componentId, axis) {
|
|
21
|
-
if (axis?.tickCount === undefined)
|
|
22
|
-
return;
|
|
23
|
-
if (!Number.isInteger(axis.tickCount) || axis.tickCount <= 0) {
|
|
24
|
-
throw new Error(`[cinder/${componentId}] rule=invalid-tick-count tickCount="${axis.tickCount}": expected a positive integer.`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
function dataTableClass(visibility) {
|
|
28
|
-
return visibility === "screen-reader-only" ? "cinder-sr-only" : undefined;
|
|
29
|
-
}
|
|
30
|
-
function formatXValue(value, axis, context) {
|
|
31
|
-
return axis?.format ? axis.format(value.raw, context) : value.label;
|
|
32
|
-
}
|
|
33
|
-
function formatNumericValue(value, axis, formatter, context) {
|
|
34
|
-
if (formatter)
|
|
35
|
-
return formatter(value, context);
|
|
36
|
-
if (axis?.format)
|
|
37
|
-
return axis.format(value, context);
|
|
38
|
-
return new Intl.NumberFormat(undefined, { maximumFractionDigits: 2 }).format(value);
|
|
39
|
-
}
|
|
40
|
-
function normalizeXValue(value) {
|
|
41
|
-
if (value instanceof Date) {
|
|
42
|
-
const comparable = value.getTime();
|
|
43
|
-
return {
|
|
44
|
-
raw: value,
|
|
45
|
-
key: `date:${comparable}`,
|
|
46
|
-
label: value.toISOString(),
|
|
47
|
-
comparable,
|
|
48
|
-
kind: "date"
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
if (typeof value === "number") {
|
|
52
|
-
return {
|
|
53
|
-
raw: value,
|
|
54
|
-
key: `number:${value}`,
|
|
55
|
-
label: String(value),
|
|
56
|
-
comparable: value,
|
|
57
|
-
kind: "number"
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
return { raw: value, key: `string:${value}`, label: value, comparable: value, kind: "string" };
|
|
61
|
-
}
|
|
62
|
-
function assertUniqueSeriesIds(componentId, series) {
|
|
63
|
-
const seen = new Set;
|
|
64
|
-
for (const item of series) {
|
|
65
|
-
if (seen.has(item.id)) {
|
|
66
|
-
throw new Error(`[cinder/${componentId}] rule=duplicate-series-id series="${item.id}": duplicate series ids are not supported.`);
|
|
67
|
-
}
|
|
68
|
-
seen.add(item.id);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function toggleSeriesId(hiddenSeriesIds, seriesId) {
|
|
72
|
-
return hiddenSeriesIds.includes(seriesId) ? hiddenSeriesIds.filter((id) => id !== seriesId) : [...hiddenSeriesIds, seriesId];
|
|
73
|
-
}
|
|
74
|
-
function createCartesianModel(options) {
|
|
75
|
-
const {
|
|
76
|
-
componentId,
|
|
77
|
-
series,
|
|
78
|
-
hiddenSeriesIds,
|
|
79
|
-
width,
|
|
80
|
-
height,
|
|
81
|
-
xAxis,
|
|
82
|
-
yAxis,
|
|
83
|
-
stackedArea = false
|
|
84
|
-
} = options;
|
|
85
|
-
assertUniqueSeriesIds(componentId, series);
|
|
86
|
-
assertValidChartNumber(componentId, "invalid-height", height, "height");
|
|
87
|
-
assertValidTickCount(componentId, xAxis);
|
|
88
|
-
assertValidTickCount(componentId, yAxis);
|
|
89
|
-
const geometry = createGeometry(width, height);
|
|
90
|
-
const allKinds = new Set;
|
|
91
|
-
const xValuesByKey = new Map;
|
|
92
|
-
const normalizedSeries = series.map((item, seriesIndex) => {
|
|
93
|
-
const seenX = new Set;
|
|
94
|
-
const color = item.color ?? chartPaletteColor(seriesIndex);
|
|
95
|
-
const points = item.data.map((point, pointIndex) => {
|
|
96
|
-
const x = normalizeXValue(point.x);
|
|
97
|
-
allKinds.add(x.kind);
|
|
98
|
-
if (seenX.has(x.key)) {
|
|
99
|
-
throw new Error(`[cinder/${componentId}] rule=duplicate-x series="${item.id}" x="${x.label}": duplicate x values are not supported.`);
|
|
100
|
-
}
|
|
101
|
-
seenX.add(x.key);
|
|
102
|
-
xValuesByKey.set(x.key, x);
|
|
103
|
-
const y = normalizeNumericValue(componentId, item.id, x.label, point.y);
|
|
104
|
-
return {
|
|
105
|
-
seriesId: item.id,
|
|
106
|
-
seriesLabel: item.label,
|
|
107
|
-
color,
|
|
108
|
-
x,
|
|
109
|
-
y,
|
|
110
|
-
originalY: point.y,
|
|
111
|
-
index: pointIndex
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
return { id: item.id, label: item.label, color, points };
|
|
115
|
-
});
|
|
116
|
-
if (allKinds.size > 1) {
|
|
117
|
-
throw new Error(`[cinder/${componentId}] rule=mixed-x-domain-kind: all x values must share one domain kind.`);
|
|
118
|
-
}
|
|
119
|
-
if (stackedArea) {
|
|
120
|
-
for (const item of normalizedSeries) {
|
|
121
|
-
for (const point of item.points) {
|
|
122
|
-
if ((point.y ?? 0) < 0) {
|
|
123
|
-
throw new Error(`[cinder/${componentId}] rule=negative-stacked-area series="${item.id}" x="${point.x.label}": stacked areas do not support negative values.`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
const sortedXValues = sortXValues([...xValuesByKey.values()]);
|
|
129
|
-
const orderByKey = new Map(sortedXValues.map((value, index) => [value.key, index]));
|
|
130
|
-
const visibleNumericValues = [];
|
|
131
|
-
for (const item of normalizedSeries) {
|
|
132
|
-
if (hiddenSeriesIds.includes(item.id))
|
|
133
|
-
continue;
|
|
134
|
-
for (const point of item.points) {
|
|
135
|
-
if (point.y !== null)
|
|
136
|
-
visibleNumericValues.push(point.y);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const stackedTotalsByKey = new Map(sortedXValues.map((value) => [value.key, 0]));
|
|
140
|
-
if (stackedArea) {
|
|
141
|
-
for (const item of normalizedSeries) {
|
|
142
|
-
if (hiddenSeriesIds.includes(item.id))
|
|
143
|
-
continue;
|
|
144
|
-
for (const point of item.points) {
|
|
145
|
-
if (point.y === null)
|
|
146
|
-
continue;
|
|
147
|
-
stackedTotalsByKey.set(point.x.key, (stackedTotalsByKey.get(point.x.key) ?? 0) + point.y);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
const domainValues = stackedArea ? [0, ...stackedTotalsByKey.values()] : visibleNumericValues;
|
|
152
|
-
const [yMinimum, yMaximum] = createPaddedDomain(domainValues);
|
|
153
|
-
const xStringScale = sortedXValues[0]?.kind === "string" ? createPointScale(sortedXValues.map((value) => value.key), [0, geometry.plotWidth], 0.5) : undefined;
|
|
154
|
-
const xNumericScale = sortedXValues[0] && sortedXValues[0].kind !== "string" ? createLinearScale(createNumericDomain(sortedXValues), [0, geometry.plotWidth]) : undefined;
|
|
155
|
-
const yScale = createLinearScale([yMinimum, yMaximum], [geometry.plotHeight, 0]);
|
|
156
|
-
function scaleX(value) {
|
|
157
|
-
if (value.kind === "string")
|
|
158
|
-
return xStringScale?.(value.key) ?? 0;
|
|
159
|
-
return xNumericScale?.(Number(value.comparable)) ?? 0;
|
|
160
|
-
}
|
|
161
|
-
const tickCount = xAxis?.tickCount ?? sortedXValues.length;
|
|
162
|
-
const xTicks = buildXAxisTicks(sortedXValues, tickCount, xAxis, scaleX);
|
|
163
|
-
const targets = [];
|
|
164
|
-
const tableRows = [];
|
|
165
|
-
const stackedOffsetsByKey = new Map(sortedXValues.map((value) => [value.key, 0]));
|
|
166
|
-
const renderedSeries = normalizedSeries.map((item) => {
|
|
167
|
-
const hidden = hiddenSeriesIds.includes(item.id);
|
|
168
|
-
const points = item.points.filter((point) => point.y !== null).toSorted((a, b) => (orderByKey.get(a.x.key) ?? 0) - (orderByKey.get(b.x.key) ?? 0));
|
|
169
|
-
const placedPoints = points.map((point) => {
|
|
170
|
-
const lowerValue = stackedArea ? stackedOffsetsByKey.get(point.x.key) ?? 0 : 0;
|
|
171
|
-
const upperValue = lowerValue + (point.y ?? 0);
|
|
172
|
-
return {
|
|
173
|
-
...point,
|
|
174
|
-
pixelX: scaleX(point.x),
|
|
175
|
-
pixelY: yScale(stackedArea ? upperValue : point.y ?? 0)
|
|
176
|
-
};
|
|
177
|
-
});
|
|
178
|
-
const coordinates = placedPoints.map((placed) => ({
|
|
179
|
-
x: placed.pixelX,
|
|
180
|
-
y: placed.pixelY,
|
|
181
|
-
y0: yScale(stackedArea ? stackedOffsetsByKey.get(placed.x.key) ?? 0 : 0)
|
|
182
|
-
}));
|
|
183
|
-
if (!hidden) {
|
|
184
|
-
for (const placed of placedPoints) {
|
|
185
|
-
const xLabel = formatXValue(placed.x, xAxis, {
|
|
186
|
-
seriesId: item.id,
|
|
187
|
-
seriesLabel: item.label,
|
|
188
|
-
index: placed.index
|
|
189
|
-
});
|
|
190
|
-
const valueLabel = formatNumericValue(placed.y ?? 0, yAxis, series.find((entry) => entry.id === item.id)?.valueFormatter, { seriesId: item.id, seriesLabel: item.label, index: placed.index });
|
|
191
|
-
targets.push({
|
|
192
|
-
id: `${item.id}-${placed.x.key}`,
|
|
193
|
-
seriesId: item.id,
|
|
194
|
-
seriesLabel: item.label,
|
|
195
|
-
xLabel,
|
|
196
|
-
valueLabel,
|
|
197
|
-
x: placed.pixelX,
|
|
198
|
-
y: placed.pixelY,
|
|
199
|
-
color: item.color
|
|
200
|
-
});
|
|
201
|
-
tableRows.push({
|
|
202
|
-
id: `${item.id}-${placed.x.key}`,
|
|
203
|
-
seriesLabel: item.label,
|
|
204
|
-
xLabel,
|
|
205
|
-
valueLabel
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
if (stackedArea) {
|
|
209
|
-
for (const placed of placedPoints) {
|
|
210
|
-
stackedOffsetsByKey.set(placed.x.key, (stackedOffsetsByKey.get(placed.x.key) ?? 0) + (placed.y ?? 0));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return {
|
|
215
|
-
...item,
|
|
216
|
-
hidden,
|
|
217
|
-
points: hidden ? [] : placedPoints,
|
|
218
|
-
path: hidden ? "" : createLinePath(coordinates),
|
|
219
|
-
areaPath: hidden ? "" : createAreaPath(coordinates, stackedArea ? undefined : geometry.plotHeight)
|
|
220
|
-
};
|
|
221
|
-
});
|
|
222
|
-
targets.sort((a, b) => a.x - b.x);
|
|
223
|
-
return {
|
|
224
|
-
geometry,
|
|
225
|
-
xTicks,
|
|
226
|
-
yTicks: yScale.ticks(yAxis?.tickCount ?? 5),
|
|
227
|
-
normalizedSeries: renderedSeries,
|
|
228
|
-
tableRows,
|
|
229
|
-
targets,
|
|
230
|
-
empty: targets.length === 0,
|
|
231
|
-
yDomain: [yMinimum, yMaximum]
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
function buildXAxisTicks(sortedXValues, tickCount, xAxis, scaleX) {
|
|
235
|
-
if (sortedXValues.length === 0)
|
|
236
|
-
return [];
|
|
237
|
-
const safeTickCount = Math.max(1, Math.min(tickCount, sortedXValues.length));
|
|
238
|
-
if (safeTickCount >= sortedXValues.length) {
|
|
239
|
-
return sortedXValues.map((value, index) => ({
|
|
240
|
-
label: formatXValue(value, xAxis, { index }),
|
|
241
|
-
x: scaleX(value)
|
|
242
|
-
}));
|
|
243
|
-
}
|
|
244
|
-
if (safeTickCount === 1) {
|
|
245
|
-
const value = sortedXValues[0];
|
|
246
|
-
return value ? [{ label: formatXValue(value, xAxis, { index: 0 }), x: scaleX(value) }] : [];
|
|
247
|
-
}
|
|
248
|
-
const step = (sortedXValues.length - 1) / (safeTickCount - 1);
|
|
249
|
-
const ticks = [];
|
|
250
|
-
for (let i = 0;i < safeTickCount; i++) {
|
|
251
|
-
const sourceIndex = Math.round(i * step);
|
|
252
|
-
const value = sortedXValues[sourceIndex];
|
|
253
|
-
if (!value)
|
|
254
|
-
continue;
|
|
255
|
-
ticks.push({
|
|
256
|
-
label: formatXValue(value, xAxis, { index: i }),
|
|
257
|
-
x: scaleX(value)
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
return ticks;
|
|
261
|
-
}
|
|
262
|
-
function createBarModel(options) {
|
|
263
|
-
const {
|
|
264
|
-
data,
|
|
265
|
-
categoryKey,
|
|
266
|
-
series,
|
|
267
|
-
hiddenSeriesIds,
|
|
268
|
-
width,
|
|
269
|
-
height,
|
|
270
|
-
orientation,
|
|
271
|
-
mode,
|
|
272
|
-
xAxis,
|
|
273
|
-
yAxis
|
|
274
|
-
} = options;
|
|
275
|
-
assertUniqueSeriesIds("bar-chart", series);
|
|
276
|
-
assertValidChartNumber("bar-chart", "invalid-height", height, "height");
|
|
277
|
-
assertValidTickCount("bar-chart", xAxis);
|
|
278
|
-
assertValidTickCount("bar-chart", yAxis);
|
|
279
|
-
const categories = [];
|
|
280
|
-
const seenCategories = new Set;
|
|
281
|
-
const categoryKinds = new Set;
|
|
282
|
-
const visibleSeries = series.filter((item) => !hiddenSeriesIds.includes(item.id));
|
|
283
|
-
const visibleValues = [0];
|
|
284
|
-
const datumByKey = new Map;
|
|
285
|
-
for (const datum of data) {
|
|
286
|
-
if (!(categoryKey in datum)) {
|
|
287
|
-
throw new Error(`[cinder/bar-chart] rule=invalid-bar-category key="${categoryKey}": category key is missing.`);
|
|
288
|
-
}
|
|
289
|
-
const rawCategory = datum[categoryKey];
|
|
290
|
-
if (!(typeof rawCategory === "string" || typeof rawCategory === "number" || rawCategory instanceof Date)) {
|
|
291
|
-
throw new Error(`[cinder/bar-chart] rule=invalid-bar-category key="${categoryKey}": category must be string, number, or Date.`);
|
|
292
|
-
}
|
|
293
|
-
const category = normalizeXValue(rawCategory);
|
|
294
|
-
categoryKinds.add(category.kind);
|
|
295
|
-
if (seenCategories.has(category.key)) {
|
|
296
|
-
throw new Error(`[cinder/bar-chart] rule=duplicate-category key="${categoryKey}" category="${category.label}": duplicate categories are not supported.`);
|
|
297
|
-
}
|
|
298
|
-
seenCategories.add(category.key);
|
|
299
|
-
categories.push(category);
|
|
300
|
-
datumByKey.set(category.key, datum);
|
|
301
|
-
for (const item of series) {
|
|
302
|
-
if (!(item.valueKey in datum)) {
|
|
303
|
-
throw new Error(`[cinder/bar-chart] rule=missing-bar-value-key key="${item.valueKey}": value key is missing.`);
|
|
304
|
-
}
|
|
305
|
-
const value = datum[item.valueKey];
|
|
306
|
-
if (!(typeof value === "number" || value === null || value === undefined)) {
|
|
307
|
-
throw new Error(`[cinder/bar-chart] rule=invalid-bar-value key="${item.valueKey}" category="${category.label}": value must be number, null, or undefined.`);
|
|
308
|
-
}
|
|
309
|
-
const numericValue = normalizeNumericValue("bar-chart", item.id, category.label, value);
|
|
310
|
-
if (numericValue !== null && !hiddenSeriesIds.includes(item.id))
|
|
311
|
-
visibleValues.push(numericValue);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
if (categoryKinds.size > 1) {
|
|
315
|
-
throw new Error(`[cinder/bar-chart] rule=mixed-bar-category-kind key="${categoryKey}": category values must share one domain kind.`);
|
|
316
|
-
}
|
|
317
|
-
const sortedCategories = sortXValues(categories);
|
|
318
|
-
const categoryLabels = sortedCategories.map((category, index) => formatXValue(category, orientation === "vertical" ? xAxis : yAxis, { index }));
|
|
319
|
-
const horizontalCategoryLabelLayout = orientation === "horizontal" ? createHorizontalCategoryLabelLayout(categoryLabels, width) : undefined;
|
|
320
|
-
const geometry = createGeometry(width, height, horizontalCategoryLabelLayout?.marginLeft);
|
|
321
|
-
const valueDomain = createPaddedDomain(mode === "stacked" ? createStackedBarDomainValues(datumByKey, sortedCategories, visibleSeries) : visibleValues);
|
|
322
|
-
if (sortedCategories.length === 0) {
|
|
323
|
-
const tickAxis = orientation === "vertical" ? yAxis : xAxis;
|
|
324
|
-
return {
|
|
325
|
-
geometry,
|
|
326
|
-
categories: [],
|
|
327
|
-
yTicks: createTicks(valueDomain, tickAxis?.tickCount ?? 5),
|
|
328
|
-
categoryTicks: [],
|
|
329
|
-
bars: [],
|
|
330
|
-
tableRows: [],
|
|
331
|
-
targets: [],
|
|
332
|
-
empty: true,
|
|
333
|
-
valueDomain
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
const valueScale = createLinearScale(valueDomain, orientation === "vertical" ? [geometry.plotHeight, 0] : [0, geometry.plotWidth]);
|
|
337
|
-
const categoryScale = createBandScale(sortedCategories.map((category) => category.key), orientation === "vertical" ? [0, geometry.plotWidth] : [0, geometry.plotHeight], 0.18);
|
|
338
|
-
const groupScale = createBandScale(visibleSeries.map((item) => item.id), [0, categoryScale.bandwidth()], 0.12);
|
|
339
|
-
const categoryTicks = sortedCategories.map((category, index) => {
|
|
340
|
-
const categoryPosition = categoryScale(category.key) ?? 0;
|
|
341
|
-
return {
|
|
342
|
-
categoryKey: category.key,
|
|
343
|
-
label: horizontalCategoryLabelLayout?.labels[index] ?? categoryLabels[index] ?? category.label,
|
|
344
|
-
fullLabel: categoryLabels[index] ?? category.label,
|
|
345
|
-
x: orientation === "vertical" ? categoryPosition + categoryScale.bandwidth() / 2 : -HORIZONTAL_CATEGORY_LABEL_GAP,
|
|
346
|
-
y: orientation === "vertical" ? geometry.plotHeight + 20 : categoryPosition + categoryScale.bandwidth() / 2
|
|
347
|
-
};
|
|
348
|
-
});
|
|
349
|
-
const bars = [];
|
|
350
|
-
const targets = [];
|
|
351
|
-
const tableRows = [];
|
|
352
|
-
for (const [categoryIndex, category] of sortedCategories.entries()) {
|
|
353
|
-
const datum = datumByKey.get(category.key);
|
|
354
|
-
if (!datum)
|
|
355
|
-
continue;
|
|
356
|
-
let positiveOffset = 0;
|
|
357
|
-
let negativeOffset = 0;
|
|
358
|
-
const rowValues = [];
|
|
359
|
-
visibleSeries.forEach((item) => {
|
|
360
|
-
const rawValue = datum[item.valueKey];
|
|
361
|
-
if (typeof rawValue !== "number")
|
|
362
|
-
return;
|
|
363
|
-
const value = rawValue;
|
|
364
|
-
const seriesColorIndex = Math.max(0, series.findIndex((entry) => entry.id === item.id));
|
|
365
|
-
const color = item.color ?? chartPaletteColor(seriesColorIndex);
|
|
366
|
-
const categoryPosition = categoryScale(category.key) ?? 0;
|
|
367
|
-
let x = 0;
|
|
368
|
-
let y = 0;
|
|
369
|
-
let barWidth = 0;
|
|
370
|
-
let barHeight = 0;
|
|
371
|
-
if (orientation === "vertical") {
|
|
372
|
-
const groupX = mode === "grouped" ? groupScale(item.id) ?? 0 : 0;
|
|
373
|
-
const start = mode === "stacked" ? value >= 0 ? positiveOffset : negativeOffset : 0;
|
|
374
|
-
const end = start + value;
|
|
375
|
-
if (mode === "stacked") {
|
|
376
|
-
if (value >= 0)
|
|
377
|
-
positiveOffset = end;
|
|
378
|
-
else
|
|
379
|
-
negativeOffset = end;
|
|
380
|
-
}
|
|
381
|
-
const y0 = valueScale(start);
|
|
382
|
-
const y1 = valueScale(end);
|
|
383
|
-
x = categoryPosition + groupX;
|
|
384
|
-
y = Math.min(y0, y1);
|
|
385
|
-
barWidth = mode === "grouped" ? groupScale.bandwidth() : categoryScale.bandwidth();
|
|
386
|
-
barHeight = Math.abs(y1 - y0);
|
|
387
|
-
} else {
|
|
388
|
-
const groupY = mode === "grouped" ? groupScale(item.id) ?? 0 : 0;
|
|
389
|
-
const start = mode === "stacked" ? value >= 0 ? positiveOffset : negativeOffset : 0;
|
|
390
|
-
const end = start + value;
|
|
391
|
-
if (mode === "stacked") {
|
|
392
|
-
if (value >= 0)
|
|
393
|
-
positiveOffset = end;
|
|
394
|
-
else
|
|
395
|
-
negativeOffset = end;
|
|
396
|
-
}
|
|
397
|
-
const x0 = valueScale(start);
|
|
398
|
-
const x1 = valueScale(end);
|
|
399
|
-
x = Math.min(x0, x1);
|
|
400
|
-
y = categoryPosition + groupY;
|
|
401
|
-
barWidth = Math.abs(x1 - x0);
|
|
402
|
-
barHeight = mode === "grouped" ? groupScale.bandwidth() : categoryScale.bandwidth();
|
|
403
|
-
}
|
|
404
|
-
const valueLabel = formatNumericValue(value, orientation === "vertical" ? yAxis : xAxis, item.valueFormatter, { seriesId: item.id, seriesLabel: item.label, index: categoryIndex });
|
|
405
|
-
const categoryLabel = formatXValue(category, orientation === "vertical" ? xAxis : yAxis, {
|
|
406
|
-
seriesId: item.id,
|
|
407
|
-
seriesLabel: item.label,
|
|
408
|
-
index: categoryIndex
|
|
409
|
-
});
|
|
410
|
-
rowValues.push({ seriesId: item.id, seriesLabel: item.label, valueLabel });
|
|
411
|
-
const bar = {
|
|
412
|
-
id: `${item.id}-${category.key}`,
|
|
413
|
-
seriesId: item.id,
|
|
414
|
-
seriesLabel: item.label,
|
|
415
|
-
categoryLabel,
|
|
416
|
-
valueLabel,
|
|
417
|
-
x,
|
|
418
|
-
y,
|
|
419
|
-
width: barWidth,
|
|
420
|
-
height: barHeight,
|
|
421
|
-
color,
|
|
422
|
-
hidden: false
|
|
423
|
-
};
|
|
424
|
-
bars.push(bar);
|
|
425
|
-
targets.push({ ...bar, x: x + barWidth / 2, y: y + barHeight / 2, xLabel: categoryLabel });
|
|
426
|
-
});
|
|
427
|
-
if (rowValues.length > 0) {
|
|
428
|
-
tableRows.push({
|
|
429
|
-
categoryKey: category.key,
|
|
430
|
-
categoryLabel: formatXValue(category, orientation === "vertical" ? xAxis : yAxis, {
|
|
431
|
-
index: tableRows.length
|
|
432
|
-
}),
|
|
433
|
-
values: rowValues
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
targets.sort((a, b) => orientation === "vertical" ? a.x - b.x : a.y - b.y);
|
|
438
|
-
return {
|
|
439
|
-
geometry,
|
|
440
|
-
categories: sortedCategories,
|
|
441
|
-
yTicks: valueScale.ticks((orientation === "vertical" ? yAxis : xAxis)?.tickCount ?? 5),
|
|
442
|
-
categoryTicks,
|
|
443
|
-
bars,
|
|
444
|
-
tableRows,
|
|
445
|
-
targets,
|
|
446
|
-
empty: targets.length === 0,
|
|
447
|
-
valueDomain
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
function nearestTarget(targets, x, y, axis = "x") {
|
|
451
|
-
if (targets.length === 0)
|
|
452
|
-
return;
|
|
453
|
-
if (targets.length === 1)
|
|
454
|
-
return targets[0];
|
|
455
|
-
const pointerKey = axis === "x" ? x : y;
|
|
456
|
-
let low = 0;
|
|
457
|
-
let high = targets.length - 1;
|
|
458
|
-
while (low < high) {
|
|
459
|
-
const mid = low + high >> 1;
|
|
460
|
-
const midKey = axis === "x" ? targets[mid]?.x ?? 0 : targets[mid]?.y ?? 0;
|
|
461
|
-
if (midKey < pointerKey)
|
|
462
|
-
low = mid + 1;
|
|
463
|
-
else
|
|
464
|
-
high = mid;
|
|
465
|
-
}
|
|
466
|
-
const candidates = [];
|
|
467
|
-
function addBucket(start) {
|
|
468
|
-
const target = targets[start];
|
|
469
|
-
if (!target)
|
|
470
|
-
return;
|
|
471
|
-
const bucketKey = axis === "x" ? target.x : target.y;
|
|
472
|
-
for (let index = start;index >= 0; index--) {
|
|
473
|
-
const candidate = targets[index];
|
|
474
|
-
if (!candidate)
|
|
475
|
-
continue;
|
|
476
|
-
const candidateKey = axis === "x" ? candidate.x : candidate.y;
|
|
477
|
-
if (candidateKey !== bucketKey)
|
|
478
|
-
break;
|
|
479
|
-
candidates.push(candidate);
|
|
480
|
-
}
|
|
481
|
-
for (let index = start + 1;index < targets.length; index++) {
|
|
482
|
-
const candidate = targets[index];
|
|
483
|
-
if (!candidate)
|
|
484
|
-
continue;
|
|
485
|
-
const candidateKey = axis === "x" ? candidate.x : candidate.y;
|
|
486
|
-
if (candidateKey !== bucketKey)
|
|
487
|
-
break;
|
|
488
|
-
candidates.push(candidate);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
addBucket(low);
|
|
492
|
-
if (low > 0) {
|
|
493
|
-
addBucket(low - 1);
|
|
494
|
-
}
|
|
495
|
-
let nearest;
|
|
496
|
-
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
497
|
-
for (const target of candidates) {
|
|
498
|
-
const targetDistance = Math.hypot(target.x - x, target.y - y);
|
|
499
|
-
if (targetDistance >= nearestDistance)
|
|
500
|
-
continue;
|
|
501
|
-
nearest = target;
|
|
502
|
-
nearestDistance = targetDistance;
|
|
503
|
-
}
|
|
504
|
-
return nearest;
|
|
505
|
-
}
|
|
506
|
-
function legendVisible(legendPosition, seriesCount) {
|
|
507
|
-
return legendPosition !== "none" && seriesCount > 0;
|
|
508
|
-
}
|
|
509
|
-
var DEFAULT_CHART_MARGIN_LEFT = 48;
|
|
510
|
-
var HORIZONTAL_CATEGORY_LABEL_CHARACTER_WIDTH = 12;
|
|
511
|
-
var HORIZONTAL_CATEGORY_LABEL_GAP = 8;
|
|
512
|
-
var HORIZONTAL_CATEGORY_LABEL_OUTER_PADDING = 8;
|
|
513
|
-
var MAXIMUM_HORIZONTAL_CATEGORY_LABEL_FRACTION = 0.4;
|
|
514
|
-
function createGeometry(width, height, marginLeft = DEFAULT_CHART_MARGIN_LEFT) {
|
|
515
|
-
const marginTop = 16;
|
|
516
|
-
const marginRight = 16;
|
|
517
|
-
const marginBottom = 36;
|
|
518
|
-
return {
|
|
519
|
-
plotWidth: Math.max(1, width - marginLeft - marginRight),
|
|
520
|
-
plotHeight: Math.max(1, height - marginTop - marginBottom),
|
|
521
|
-
marginTop,
|
|
522
|
-
marginRight,
|
|
523
|
-
marginBottom,
|
|
524
|
-
marginLeft
|
|
525
|
-
};
|
|
526
|
-
}
|
|
527
|
-
function createHorizontalCategoryLabelLayout(labels, chartWidth) {
|
|
528
|
-
const maximumMarginLeft = Math.max(DEFAULT_CHART_MARGIN_LEFT, Math.floor(chartWidth * MAXIMUM_HORIZONTAL_CATEGORY_LABEL_FRACTION));
|
|
529
|
-
let longestLabelWidth = 0;
|
|
530
|
-
for (const label of labels) {
|
|
531
|
-
longestLabelWidth = Math.max(longestLabelWidth, estimateHorizontalCategoryLabelWidth(label));
|
|
532
|
-
}
|
|
533
|
-
const requestedMarginLeft = longestLabelWidth + HORIZONTAL_CATEGORY_LABEL_GAP + HORIZONTAL_CATEGORY_LABEL_OUTER_PADDING;
|
|
534
|
-
const marginLeft = Math.min(maximumMarginLeft, Math.max(DEFAULT_CHART_MARGIN_LEFT, requestedMarginLeft));
|
|
535
|
-
const availableLabelWidth = Math.max(0, marginLeft - HORIZONTAL_CATEGORY_LABEL_GAP - HORIZONTAL_CATEGORY_LABEL_OUTER_PADDING);
|
|
536
|
-
return {
|
|
537
|
-
marginLeft,
|
|
538
|
-
labels: labels.map((label) => truncateHorizontalCategoryLabel(label, availableLabelWidth))
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
function estimateHorizontalCategoryLabelWidth(label) {
|
|
542
|
-
return Array.from(label).length * HORIZONTAL_CATEGORY_LABEL_CHARACTER_WIDTH;
|
|
543
|
-
}
|
|
544
|
-
function truncateHorizontalCategoryLabel(label, availableWidth) {
|
|
545
|
-
if (estimateHorizontalCategoryLabelWidth(label) <= availableWidth)
|
|
546
|
-
return label;
|
|
547
|
-
const availableCharacterCount = Math.floor(availableWidth / HORIZONTAL_CATEGORY_LABEL_CHARACTER_WIDTH);
|
|
548
|
-
if (availableCharacterCount <= 0)
|
|
549
|
-
return "";
|
|
550
|
-
if (availableCharacterCount === 1)
|
|
551
|
-
return "…";
|
|
552
|
-
return `${Array.from(label).slice(0, availableCharacterCount - 1).join("")}…`;
|
|
553
|
-
}
|
|
554
|
-
function normalizeNumericValue(componentId, seriesId, xLabel, value) {
|
|
555
|
-
if (value === null || value === undefined)
|
|
556
|
-
return null;
|
|
557
|
-
if (!Number.isFinite(value)) {
|
|
558
|
-
throw new Error(`[cinder/${componentId}] rule=non-finite-y series="${seriesId}" x="${xLabel}": y values must be finite numbers.`);
|
|
559
|
-
}
|
|
560
|
-
return value;
|
|
561
|
-
}
|
|
562
|
-
function sortXValues(values) {
|
|
563
|
-
if (values[0]?.kind === "string")
|
|
564
|
-
return values;
|
|
565
|
-
return [...values].toSorted((a, b) => Number(a.comparable) - Number(b.comparable));
|
|
566
|
-
}
|
|
567
|
-
function createPaddedDomain(values) {
|
|
568
|
-
if (values.length === 0)
|
|
569
|
-
return [-1, 1];
|
|
570
|
-
let minimum = values[0];
|
|
571
|
-
let maximum = values[0];
|
|
572
|
-
for (let index = 1;index < values.length; index++) {
|
|
573
|
-
const value = values[index];
|
|
574
|
-
if (value < minimum)
|
|
575
|
-
minimum = value;
|
|
576
|
-
if (value > maximum)
|
|
577
|
-
maximum = value;
|
|
578
|
-
}
|
|
579
|
-
if (minimum === maximum)
|
|
580
|
-
return [minimum - 1, maximum + 1];
|
|
581
|
-
return [Math.min(0, minimum), Math.max(0, maximum)];
|
|
582
|
-
}
|
|
583
|
-
function createLinearScale(domain, range) {
|
|
584
|
-
const [domainMinimum, domainMaximum] = domain[0] === domain[1] ? [domain[0] - 1, domain[1] + 1] : domain;
|
|
585
|
-
const [rangeMinimum, rangeMaximum] = range;
|
|
586
|
-
const domainSpan = domainMaximum - domainMinimum;
|
|
587
|
-
const rangeSpan = rangeMaximum - rangeMinimum;
|
|
588
|
-
const scale = Object.assign((value) => rangeMinimum + (value - domainMinimum) / domainSpan * rangeSpan, {
|
|
589
|
-
ticks: (count) => createTicks([domainMinimum, domainMaximum], count)
|
|
590
|
-
});
|
|
591
|
-
return scale;
|
|
592
|
-
}
|
|
593
|
-
function createPointScale(domain, range, padding) {
|
|
594
|
-
const positions = new Map;
|
|
595
|
-
const [rangeMinimum, rangeMaximum] = range;
|
|
596
|
-
if (domain.length === 1) {
|
|
597
|
-
positions.set(domain[0] ?? "", rangeMinimum + (rangeMaximum - rangeMinimum) / 2);
|
|
598
|
-
} else {
|
|
599
|
-
const step = (rangeMaximum - rangeMinimum) / Math.max(1, domain.length - 1 + padding * 2);
|
|
600
|
-
const start = rangeMinimum + step * padding;
|
|
601
|
-
domain.forEach((value, index) => positions.set(value, start + step * index));
|
|
602
|
-
}
|
|
603
|
-
return (value) => positions.get(value);
|
|
604
|
-
}
|
|
605
|
-
function createBandScale(domain, range, padding) {
|
|
606
|
-
const positions = new Map;
|
|
607
|
-
const [rangeMinimum, rangeMaximum] = range;
|
|
608
|
-
const availableSize = Math.max(0, rangeMaximum - rangeMinimum);
|
|
609
|
-
const step = domain.length === 0 ? 0 : availableSize / Math.max(1, domain.length + padding * (domain.length - 1));
|
|
610
|
-
const bandWidth = Math.max(0, step * (1 - padding));
|
|
611
|
-
domain.forEach((value, index) => positions.set(value, rangeMinimum + step * index));
|
|
612
|
-
const scale = Object.assign((value) => positions.get(value), {
|
|
613
|
-
bandwidth: () => bandWidth
|
|
614
|
-
});
|
|
615
|
-
return scale;
|
|
616
|
-
}
|
|
617
|
-
function createNumericDomain(values) {
|
|
618
|
-
if (values.length === 0)
|
|
619
|
-
return [0, 1];
|
|
620
|
-
let minimum = Number(values[0].comparable);
|
|
621
|
-
let maximum = minimum;
|
|
622
|
-
for (let index = 1;index < values.length; index++) {
|
|
623
|
-
const numeric = Number(values[index].comparable);
|
|
624
|
-
if (numeric < minimum)
|
|
625
|
-
minimum = numeric;
|
|
626
|
-
if (numeric > maximum)
|
|
627
|
-
maximum = numeric;
|
|
628
|
-
}
|
|
629
|
-
return minimum === maximum ? [minimum - 1, maximum + 1] : [minimum, maximum];
|
|
630
|
-
}
|
|
631
|
-
function createTicks(domain, count) {
|
|
632
|
-
const safeCount = Math.max(1, Math.floor(count));
|
|
633
|
-
if (safeCount === 1)
|
|
634
|
-
return [domain[0]];
|
|
635
|
-
const step = (domain[1] - domain[0]) / (safeCount - 1);
|
|
636
|
-
return Array.from({ length: safeCount }, (_, index) => domain[0] + step * index);
|
|
637
|
-
}
|
|
638
|
-
function createLinePath(points) {
|
|
639
|
-
if (points.length === 0)
|
|
640
|
-
return "";
|
|
641
|
-
const [firstPoint, ...remainingPoints] = points;
|
|
642
|
-
return [
|
|
643
|
-
`M${formatPathNumber(firstPoint?.x ?? 0)},${formatPathNumber(firstPoint?.y ?? 0)}`,
|
|
644
|
-
...remainingPoints.map((point) => `L${formatPathNumber(point.x)},${formatPathNumber(point.y)}`)
|
|
645
|
-
].join("");
|
|
646
|
-
}
|
|
647
|
-
function createAreaPath(points, baseline) {
|
|
648
|
-
if (points.length === 0)
|
|
649
|
-
return "";
|
|
650
|
-
const firstPoint = points[0];
|
|
651
|
-
const lastPoint = points.at(-1);
|
|
652
|
-
if (!firstPoint || !lastPoint)
|
|
653
|
-
return "";
|
|
654
|
-
const lowerPoints = points.toReversed().map((point) => `L${formatPathNumber(point.x)},${formatPathNumber(point.y0 ?? baseline ?? 0)}`);
|
|
655
|
-
return [
|
|
656
|
-
`M${formatPathNumber(firstPoint.x)},${formatPathNumber(firstPoint.y0 ?? baseline ?? 0)}`,
|
|
657
|
-
`L${formatPathNumber(firstPoint.x)},${formatPathNumber(firstPoint.y)}`,
|
|
658
|
-
...points.slice(1).map((point) => `L${formatPathNumber(point.x)},${formatPathNumber(point.y)}`),
|
|
659
|
-
...lowerPoints,
|
|
660
|
-
"Z"
|
|
661
|
-
].join("");
|
|
662
|
-
}
|
|
663
|
-
function createStackedBarDomainValues(datumByKey, categories, series) {
|
|
664
|
-
const values = [0];
|
|
665
|
-
for (const category of categories) {
|
|
666
|
-
const datum = datumByKey.get(category.key);
|
|
667
|
-
if (!datum)
|
|
668
|
-
continue;
|
|
669
|
-
let positiveTotal = 0;
|
|
670
|
-
let negativeTotal = 0;
|
|
671
|
-
for (const item of series) {
|
|
672
|
-
const value = datum[item.valueKey];
|
|
673
|
-
if (typeof value !== "number")
|
|
674
|
-
continue;
|
|
675
|
-
if (value >= 0)
|
|
676
|
-
positiveTotal += value;
|
|
677
|
-
else
|
|
678
|
-
negativeTotal += value;
|
|
679
|
-
}
|
|
680
|
-
values.push(positiveTotal, negativeTotal);
|
|
681
|
-
}
|
|
682
|
-
return values;
|
|
683
|
-
}
|
|
684
|
-
function formatPathNumber(value) {
|
|
685
|
-
return Number(value.toFixed(3)).toString();
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
export { chartPaletteColor, dataTableClass, formatNumericValue, toggleSeriesId, createCartesianModel, createBarModel, nearestTarget, legendVisible };
|
|
689
|
-
|
|
690
|
-
//# debugId=C949D290726F282964756E2164756E21
|