svelte-multistyle-ui 0.0.1-alpha
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/LICENSE +201 -0
- package/README.md +183 -0
- package/dist/actions/portal.d.ts +20 -0
- package/dist/actions/portal.js +32 -0
- package/dist/components/Accordion.svelte +64 -0
- package/dist/components/Accordion.svelte.d.ts +19 -0
- package/dist/components/Alert.svelte +61 -0
- package/dist/components/Alert.svelte.d.ts +23 -0
- package/dist/components/Avatar.svelte +31 -0
- package/dist/components/Avatar.svelte.d.ts +21 -0
- package/dist/components/Breadcrumb.svelte +35 -0
- package/dist/components/Breadcrumb.svelte.d.ts +15 -0
- package/dist/components/Button.svelte +34 -0
- package/dist/components/Button.svelte.d.ts +25 -0
- package/dist/components/ButtonGroup.svelte +45 -0
- package/dist/components/ButtonGroup.svelte.d.ts +23 -0
- package/dist/components/Card.svelte +29 -0
- package/dist/components/Card.svelte.d.ts +21 -0
- package/dist/components/Carousel.svelte +111 -0
- package/dist/components/Carousel.svelte.d.ts +23 -0
- package/dist/components/Checkbox.svelte +64 -0
- package/dist/components/Checkbox.svelte.d.ts +21 -0
- package/dist/components/Chip.svelte +43 -0
- package/dist/components/Chip.svelte.d.ts +27 -0
- package/dist/components/Column.svelte +38 -0
- package/dist/components/Column.svelte.d.ts +21 -0
- package/dist/components/CommandPalette.svelte +207 -0
- package/dist/components/CommandPalette.svelte.d.ts +19 -0
- package/dist/components/DatePicker.svelte +365 -0
- package/dist/components/DatePicker.svelte.d.ts +31 -0
- package/dist/components/Divider.svelte +32 -0
- package/dist/components/Divider.svelte.d.ts +17 -0
- package/dist/components/Drawer.svelte +69 -0
- package/dist/components/Drawer.svelte.d.ts +21 -0
- package/dist/components/DropdownMenu.svelte +113 -0
- package/dist/components/DropdownMenu.svelte.d.ts +25 -0
- package/dist/components/FAB.svelte +27 -0
- package/dist/components/FAB.svelte.d.ts +19 -0
- package/dist/components/FileUpload.svelte +76 -0
- package/dist/components/FileUpload.svelte.d.ts +21 -0
- package/dist/components/Grid.svelte +51 -0
- package/dist/components/Grid.svelte.d.ts +27 -0
- package/dist/components/IconButton.svelte +39 -0
- package/dist/components/IconButton.svelte.d.ts +27 -0
- package/dist/components/Input.svelte +121 -0
- package/dist/components/Input.svelte.d.ts +69 -0
- package/dist/components/Modal.svelte +57 -0
- package/dist/components/Modal.svelte.d.ts +23 -0
- package/dist/components/MultiSelect.svelte +125 -0
- package/dist/components/MultiSelect.svelte.d.ts +23 -0
- package/dist/components/Pagination.svelte +52 -0
- package/dist/components/Pagination.svelte.d.ts +19 -0
- package/dist/components/Popover.svelte +114 -0
- package/dist/components/Popover.svelte.d.ts +23 -0
- package/dist/components/ProgressBar.svelte +72 -0
- package/dist/components/ProgressBar.svelte.d.ts +21 -0
- package/dist/components/Radio.svelte +39 -0
- package/dist/components/Radio.svelte.d.ts +21 -0
- package/dist/components/Rating.svelte +102 -0
- package/dist/components/Rating.svelte.d.ts +25 -0
- package/dist/components/Row.svelte +39 -0
- package/dist/components/Row.svelte.d.ts +23 -0
- package/dist/components/Select.svelte +80 -0
- package/dist/components/Select.svelte.d.ts +23 -0
- package/dist/components/Skeleton.svelte +26 -0
- package/dist/components/Skeleton.svelte.d.ts +19 -0
- package/dist/components/Slider.svelte +46 -0
- package/dist/components/Slider.svelte.d.ts +25 -0
- package/dist/components/Spinner.svelte +27 -0
- package/dist/components/Spinner.svelte.d.ts +15 -0
- package/dist/components/Stepper.svelte +34 -0
- package/dist/components/Stepper.svelte.d.ts +17 -0
- package/dist/components/Table.svelte +59 -0
- package/dist/components/Table.svelte.d.ts +19 -0
- package/dist/components/Tabs.svelte +32 -0
- package/dist/components/Tabs.svelte.d.ts +17 -0
- package/dist/components/Textarea.svelte +86 -0
- package/dist/components/Textarea.svelte.d.ts +31 -0
- package/dist/components/Toast.svelte +90 -0
- package/dist/components/Toast.svelte.d.ts +19 -0
- package/dist/components/Toggle.svelte +46 -0
- package/dist/components/Toggle.svelte.d.ts +21 -0
- package/dist/components/Tooltip.svelte +35 -0
- package/dist/components/Tooltip.svelte.d.ts +19 -0
- package/dist/components/accordion-styles.css +89 -0
- package/dist/components/alert-styles.css +66 -0
- package/dist/components/avatar-styles.css +50 -0
- package/dist/components/breadcrumb-styles.css +73 -0
- package/dist/components/button-styles.css +272 -0
- package/dist/components/buttongroup-styles.css +118 -0
- package/dist/components/card-styles.css +101 -0
- package/dist/components/carousel-styles.css +145 -0
- package/dist/components/charts/BarChart.svelte +5 -0
- package/dist/components/charts/BarChart.svelte.d.ts +29 -0
- package/dist/components/charts/BubbleChart.svelte +5 -0
- package/dist/components/charts/BubbleChart.svelte.d.ts +29 -0
- package/dist/components/charts/Chart.svelte +186 -0
- package/dist/components/charts/Chart.svelte.d.ts +37 -0
- package/dist/components/charts/ComboChart.svelte +5 -0
- package/dist/components/charts/ComboChart.svelte.d.ts +29 -0
- package/dist/components/charts/DoughnutChart.svelte +5 -0
- package/dist/components/charts/DoughnutChart.svelte.d.ts +29 -0
- package/dist/components/charts/LineChart.svelte +5 -0
- package/dist/components/charts/LineChart.svelte.d.ts +29 -0
- package/dist/components/charts/PieChart.svelte +5 -0
- package/dist/components/charts/PieChart.svelte.d.ts +29 -0
- package/dist/components/charts/PolarAreaChart.svelte +5 -0
- package/dist/components/charts/PolarAreaChart.svelte.d.ts +29 -0
- package/dist/components/charts/RadarChart.svelte +5 -0
- package/dist/components/charts/RadarChart.svelte.d.ts +29 -0
- package/dist/components/charts/ScatterChart.svelte +5 -0
- package/dist/components/charts/ScatterChart.svelte.d.ts +29 -0
- package/dist/components/charts/StackedBarChart.svelte +18 -0
- package/dist/components/charts/StackedBarChart.svelte.d.ts +29 -0
- package/dist/components/charts/StackedLineChart.svelte +21 -0
- package/dist/components/charts/StackedLineChart.svelte.d.ts +29 -0
- package/dist/components/charts/chart-config.d.ts +102 -0
- package/dist/components/charts/chart-config.js +616 -0
- package/dist/components/charts/chart-styles.css +159 -0
- package/dist/components/checkbox-styles.css +125 -0
- package/dist/components/chip-styles.css +107 -0
- package/dist/components/column-styles.css +6 -0
- package/dist/components/commandpalette-styles.css +162 -0
- package/dist/components/datepicker-styles.css +1011 -0
- package/dist/components/divider-styles.css +56 -0
- package/dist/components/drawer-styles.css +83 -0
- package/dist/components/dropdown-styles.css +128 -0
- package/dist/components/fab-styles.css +61 -0
- package/dist/components/fileupload-styles.css +125 -0
- package/dist/components/grid-styles.css +6 -0
- package/dist/components/iconbutton-styles.css +146 -0
- package/dist/components/input-styles.css +436 -0
- package/dist/components/modal-styles.css +103 -0
- package/dist/components/multiselect-styles.css +202 -0
- package/dist/components/pagination-styles.css +63 -0
- package/dist/components/popover-styles.css +122 -0
- package/dist/components/progressbar-styles.css +106 -0
- package/dist/components/radio-styles.css +120 -0
- package/dist/components/rating-styles.css +68 -0
- package/dist/components/row-styles.css +6 -0
- package/dist/components/select-styles.css +218 -0
- package/dist/components/skeleton-styles.css +48 -0
- package/dist/components/slider-styles.css +85 -0
- package/dist/components/spinner-styles.css +52 -0
- package/dist/components/stepper-styles.css +93 -0
- package/dist/components/table-styles.css +114 -0
- package/dist/components/tabs-styles.css +74 -0
- package/dist/components/textarea-styles.css +224 -0
- package/dist/components/theme-base.css +64 -0
- package/dist/components/theme.css +440 -0
- package/dist/components/toast-styles.css +106 -0
- package/dist/components/toggle-styles.css +131 -0
- package/dist/components/tooltip-styles.css +56 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +9 -0
- package/dist/config.svelte.d.ts +25 -0
- package/dist/config.svelte.js +41 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +69 -0
- package/package.json +65 -0
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Chart,
|
|
3
|
+
BarController,
|
|
4
|
+
LineController,
|
|
5
|
+
PieController,
|
|
6
|
+
DoughnutController,
|
|
7
|
+
RadarController,
|
|
8
|
+
PolarAreaController,
|
|
9
|
+
BubbleController,
|
|
10
|
+
ScatterController,
|
|
11
|
+
CategoryScale,
|
|
12
|
+
LinearScale,
|
|
13
|
+
RadialLinearScale,
|
|
14
|
+
BarElement,
|
|
15
|
+
LineElement,
|
|
16
|
+
PointElement,
|
|
17
|
+
ArcElement,
|
|
18
|
+
Filler,
|
|
19
|
+
Legend,
|
|
20
|
+
Tooltip,
|
|
21
|
+
Title,
|
|
22
|
+
} from "chart.js";
|
|
23
|
+
|
|
24
|
+
// Register everything we use once at module top — tree-shaken, explicit.
|
|
25
|
+
Chart.register(
|
|
26
|
+
BarController,
|
|
27
|
+
LineController,
|
|
28
|
+
PieController,
|
|
29
|
+
DoughnutController,
|
|
30
|
+
RadarController,
|
|
31
|
+
PolarAreaController,
|
|
32
|
+
BubbleController,
|
|
33
|
+
ScatterController,
|
|
34
|
+
CategoryScale,
|
|
35
|
+
LinearScale,
|
|
36
|
+
RadialLinearScale,
|
|
37
|
+
BarElement,
|
|
38
|
+
LineElement,
|
|
39
|
+
PointElement,
|
|
40
|
+
ArcElement,
|
|
41
|
+
Filler,
|
|
42
|
+
Legend,
|
|
43
|
+
Tooltip,
|
|
44
|
+
Title,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
// Safety patch: ensure setLineDash always receives a valid array.
|
|
48
|
+
// Chart.js v4 can pass undefined/null internal values that throw "cannot be
|
|
49
|
+
// converted to a sequence" in some browser environments.
|
|
50
|
+
const origSetLineDash = CanvasRenderingContext2D.prototype.setLineDash;
|
|
51
|
+
CanvasRenderingContext2D.prototype.setLineDash = function (segments) {
|
|
52
|
+
if (!segments || typeof segments !== "object" || typeof segments[Symbol.iterator] !== "function") {
|
|
53
|
+
return origSetLineDash.call(this, []);
|
|
54
|
+
}
|
|
55
|
+
return origSetLineDash.call(this, segments);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Read theme tokens from a DOM element's computed style.
|
|
60
|
+
* Every returned value is a resolved CSS color string.
|
|
61
|
+
*/
|
|
62
|
+
export function readTokens(el) {
|
|
63
|
+
const cs = getComputedStyle(el);
|
|
64
|
+
return {
|
|
65
|
+
primary: cs.getPropertyValue("--t-primary").trim(),
|
|
66
|
+
secondary: cs.getPropertyValue("--t-secondary").trim(),
|
|
67
|
+
surface: cs.getPropertyValue("--t-surface").trim(),
|
|
68
|
+
text: cs.getPropertyValue("--t-text").trim(),
|
|
69
|
+
textHint: cs.getPropertyValue("--t-text-hint").trim(),
|
|
70
|
+
textSecondary: cs.getPropertyValue("--t-text-secondary").trim(),
|
|
71
|
+
cardBg: cs.getPropertyValue("--t-card-bg").trim(),
|
|
72
|
+
border: cs.getPropertyValue("--t-border").trim() ||
|
|
73
|
+
cs.getPropertyValue("--t-card-border-color").trim(),
|
|
74
|
+
info: cs.getPropertyValue("--t-info").trim(),
|
|
75
|
+
success: cs.getPropertyValue("--t-success").trim(),
|
|
76
|
+
warning: cs.getPropertyValue("--t-warning").trim(),
|
|
77
|
+
error: cs.getPropertyValue("--t-error").trim(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Generate a palette of n colors cycling through the theme's status colors.
|
|
83
|
+
* For n > 6, alpha-reduced repeats are used (no external color deps).
|
|
84
|
+
*/
|
|
85
|
+
export function palette(n, tokens) {
|
|
86
|
+
const colors = [
|
|
87
|
+
tokens.primary,
|
|
88
|
+
tokens.secondary,
|
|
89
|
+
tokens.info,
|
|
90
|
+
tokens.success,
|
|
91
|
+
tokens.warning,
|
|
92
|
+
tokens.error,
|
|
93
|
+
];
|
|
94
|
+
if (n <= colors.length) return colors.slice(0, n);
|
|
95
|
+
// More than 6: repeat with alpha stepping
|
|
96
|
+
const result = [];
|
|
97
|
+
for (let i = 0; i < n; i++) {
|
|
98
|
+
const base = colors[i % colors.length];
|
|
99
|
+
const step = Math.floor(i / colors.length);
|
|
100
|
+
const alpha = Math.max(0.35, 1 - step * 0.2);
|
|
101
|
+
result.push(alpha < 1 ? `${base}${Math.round(alpha * 255).toString(16).padStart(2, "0")}` : base);
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Build a Chart.js data object from the canonical user-facing API.
|
|
108
|
+
*/
|
|
109
|
+
export function buildData(type, { data, series, labels }, tokens) {
|
|
110
|
+
// Normalize object-style data: {q1:12, q2:19} → labels=["q1","q2"], data=[12,19]
|
|
111
|
+
if (data && typeof data === "object" && !Array.isArray(data) && data.constructor === Object) {
|
|
112
|
+
labels = Object.keys(data);
|
|
113
|
+
data = Object.values(data);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Combo chart: row-oriented data + optional series for chartType overrides
|
|
117
|
+
// [{label:"jan", Revenue:40, Target:50, Cost:20}, ...] → labels + series
|
|
118
|
+
// If series is also provided, chartType is merged from matching series entries
|
|
119
|
+
if (type === "combo" && Array.isArray(data) && data.length > 0 && data[0] &&
|
|
120
|
+
typeof data[0] === "object" && !Array.isArray(data[0]) && "label" in data[0]) {
|
|
121
|
+
const keys = Object.keys(data[0]).filter(k => k !== "label");
|
|
122
|
+
labels = data.map(d => d.label);
|
|
123
|
+
const chartTypeMap = {};
|
|
124
|
+
if (series) {
|
|
125
|
+
series.forEach(s => { chartTypeMap[s.name] = s.chartType; });
|
|
126
|
+
}
|
|
127
|
+
series = keys.map(key => ({
|
|
128
|
+
name: key,
|
|
129
|
+
values: data.map(d => d[key]),
|
|
130
|
+
chartType: chartTypeMap[key] || "line",
|
|
131
|
+
}));
|
|
132
|
+
data = null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Normalize single-series {label, value} format: [{label:"q1", value:5}, ...]
|
|
136
|
+
// → labels=["q1","q2"], data=[5,19] — order preserved (unlike plain objects)
|
|
137
|
+
if (Array.isArray(data) && data.length > 0 && data[0] &&
|
|
138
|
+
typeof data[0] === "object" && !Array.isArray(data[0]) &&
|
|
139
|
+
"label" in data[0] && "value" in data[0] && !series) {
|
|
140
|
+
labels = data.map(d => d.label);
|
|
141
|
+
data = data.map(d => d.value);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Normalize multi-series row-oriented data: [{label:"jan", revenue:10, Cost:5}, ...]
|
|
145
|
+
// → labels=["jan","feb"], series=[{name:"revenue",values:[10,20]}, {name:"Cost",values:[5,8]}]
|
|
146
|
+
else if (Array.isArray(data) && data.length > 0 && data[0] &&
|
|
147
|
+
typeof data[0] === "object" && !Array.isArray(data[0]) &&
|
|
148
|
+
"label" in data[0] && !series) {
|
|
149
|
+
const keys = Object.keys(data[0]).filter(k => k !== "label");
|
|
150
|
+
labels = data.map(d => d.label);
|
|
151
|
+
series = keys.map(key => ({ name: key, values: data.map(d => d[key]) }));
|
|
152
|
+
data = null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Bubble chart: row-oriented {label, x, y, r} format
|
|
156
|
+
// [{label:"Product A", x:10, y:20, r:15}, ...] → single dataset with points
|
|
157
|
+
if (type === "bubble" && Array.isArray(series) && series.length > 0 && series[0] &&
|
|
158
|
+
typeof series[0] === "object" && !Array.isArray(series[0]) &&
|
|
159
|
+
"x" in series[0] && "y" in series[0]) {
|
|
160
|
+
const points = series.map(s => ({
|
|
161
|
+
x: s.x,
|
|
162
|
+
y: s.y,
|
|
163
|
+
r: s.r ?? 10,
|
|
164
|
+
}));
|
|
165
|
+
const datasetLabel = series[0].label || "Data";
|
|
166
|
+
series = [{ name: datasetLabel, points }];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Normalize row-oriented format passed via series prop (for consistency).
|
|
170
|
+
// Allows: <Bar series={[{label:"q1", value:5}, ...]} />
|
|
171
|
+
// and: <Line series={[{label:"jan", Revenue:10, Cost:5}, ...]} />
|
|
172
|
+
// Detection: traditional series has {name, values}, row-oriented has {label, ...}
|
|
173
|
+
else if (!data && Array.isArray(series) && series.length > 0 && series[0] &&
|
|
174
|
+
typeof series[0] === "object" && !Array.isArray(series[0]) &&
|
|
175
|
+
"label" in series[0]) {
|
|
176
|
+
if ("value" in series[0]) {
|
|
177
|
+
// Single-series {label, value}
|
|
178
|
+
labels = series.map(s => s.label);
|
|
179
|
+
data = series.map(s => s.value);
|
|
180
|
+
series = null;
|
|
181
|
+
} else {
|
|
182
|
+
// Multi-series row-oriented
|
|
183
|
+
const keys = Object.keys(series[0]).filter(k => k !== "label");
|
|
184
|
+
labels = series.map(s => s.label);
|
|
185
|
+
series = keys.map(key => ({ name: key, values: series.map(s => s[key]) }));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Single-series shortcut
|
|
190
|
+
if (data && !series) {
|
|
191
|
+
if (type === "scatter") {
|
|
192
|
+
return {
|
|
193
|
+
datasets: [{
|
|
194
|
+
label: undefined,
|
|
195
|
+
data: data,
|
|
196
|
+
backgroundColor: tokens.primary,
|
|
197
|
+
}],
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (type === "bubble") {
|
|
201
|
+
return {
|
|
202
|
+
datasets: [{
|
|
203
|
+
label: undefined,
|
|
204
|
+
data: data,
|
|
205
|
+
backgroundColor: tokens.primary,
|
|
206
|
+
}],
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// Category charts (bar, line, pie, doughnut, radar, polarArea)
|
|
210
|
+
const isSlice = ["pie", "doughnut", "polarArea"].includes(type);
|
|
211
|
+
const cols = isSlice ? palette(data.length, tokens) : [tokens.primary];
|
|
212
|
+
return {
|
|
213
|
+
labels: labels || [],
|
|
214
|
+
datasets: [{
|
|
215
|
+
label: undefined,
|
|
216
|
+
data: data,
|
|
217
|
+
backgroundColor: isSlice ? cols : cols[0],
|
|
218
|
+
borderColor: isSlice ? cols.map(() => tokens.surface) : cols[0],
|
|
219
|
+
borderWidth: isSlice ? 2 : undefined,
|
|
220
|
+
}],
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Multi-series
|
|
225
|
+
if (series && series.length > 0) {
|
|
226
|
+
const cols = palette(series.length, tokens);
|
|
227
|
+
return {
|
|
228
|
+
labels: labels || [],
|
|
229
|
+
datasets: series.map((s, i) => {
|
|
230
|
+
const color = s.color || cols[i];
|
|
231
|
+
const isSlice = ["pie", "doughnut", "polarArea"].includes(type);
|
|
232
|
+
if (isSlice) {
|
|
233
|
+
// For slice charts with multiple series, treat each series as a separate ring
|
|
234
|
+
return {
|
|
235
|
+
label: s.name,
|
|
236
|
+
data: s.values || [],
|
|
237
|
+
backgroundColor: palette((s.values || []).length, tokens),
|
|
238
|
+
borderColor: tokens.surface,
|
|
239
|
+
borderWidth: 2,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (type === "scatter" || type === "bubble") {
|
|
243
|
+
return {
|
|
244
|
+
label: s.name,
|
|
245
|
+
data: s.points || [],
|
|
246
|
+
backgroundColor: color,
|
|
247
|
+
borderColor: color,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// Combo chart: per-series type override ("bar" or "line")
|
|
251
|
+
if (type === "combo") {
|
|
252
|
+
const chartType = s.chartType || "line";
|
|
253
|
+
if (chartType === "line") {
|
|
254
|
+
return {
|
|
255
|
+
type: "line",
|
|
256
|
+
label: s.name,
|
|
257
|
+
data: s.values || [],
|
|
258
|
+
backgroundColor: color,
|
|
259
|
+
borderColor: color,
|
|
260
|
+
borderWidth: 2,
|
|
261
|
+
tension: s.tension ?? 0.35,
|
|
262
|
+
fill: s.fill ?? false,
|
|
263
|
+
pointRadius: s.pointRadius ?? 3,
|
|
264
|
+
pointHoverRadius: s.pointHoverRadius ?? 6,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
type: "bar",
|
|
269
|
+
label: s.name,
|
|
270
|
+
data: s.values || [],
|
|
271
|
+
backgroundColor: color,
|
|
272
|
+
borderColor: color,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
label: s.name,
|
|
277
|
+
data: s.values || [],
|
|
278
|
+
backgroundColor: color,
|
|
279
|
+
borderColor: color,
|
|
280
|
+
borderWidth: type === "line" ? 2 : undefined,
|
|
281
|
+
};
|
|
282
|
+
}),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Edge case: no data, no series — empty chart
|
|
287
|
+
return { labels: labels || [], datasets: [] };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Per-style Chart.js option overrides.
|
|
292
|
+
* Keys: barRadius, lineTension, fill, gridStyle, shadow, extra.
|
|
293
|
+
*/
|
|
294
|
+
const STYLE_OVERRIDES = {
|
|
295
|
+
material: {
|
|
296
|
+
barRadius: 4,
|
|
297
|
+
lineTension: 0.35,
|
|
298
|
+
fill: false,
|
|
299
|
+
gridDash: [],
|
|
300
|
+
gridColor: undefined,
|
|
301
|
+
extra: {},
|
|
302
|
+
},
|
|
303
|
+
material3: {
|
|
304
|
+
barRadius: 999, // pill bars
|
|
305
|
+
lineTension: 0.3,
|
|
306
|
+
fill: false,
|
|
307
|
+
gridDash: [],
|
|
308
|
+
gridColor: undefined,
|
|
309
|
+
pointRadius: 4,
|
|
310
|
+
extra: { pointRadius: 4 },
|
|
311
|
+
},
|
|
312
|
+
fluent: {
|
|
313
|
+
barRadius: 2,
|
|
314
|
+
lineTension: 0.4,
|
|
315
|
+
fill: false,
|
|
316
|
+
gridDash: [],
|
|
317
|
+
gridColor: undefined,
|
|
318
|
+
extra: {},
|
|
319
|
+
},
|
|
320
|
+
brutalist: {
|
|
321
|
+
barRadius: 0,
|
|
322
|
+
lineTension: 0, // segments
|
|
323
|
+
fill: false,
|
|
324
|
+
gridDash: [4, 4],
|
|
325
|
+
gridColor: undefined, // will use --t-text
|
|
326
|
+
extra: { borderWidth: 2 },
|
|
327
|
+
},
|
|
328
|
+
pixel: {
|
|
329
|
+
barRadius: 0,
|
|
330
|
+
lineTension: 0,
|
|
331
|
+
fill: false,
|
|
332
|
+
gridDash: [],
|
|
333
|
+
gridColor: undefined,
|
|
334
|
+
extra: {},
|
|
335
|
+
},
|
|
336
|
+
neon: {
|
|
337
|
+
barRadius: 0,
|
|
338
|
+
lineTension: 0.3,
|
|
339
|
+
fill: true,
|
|
340
|
+
fillAlpha: 0.15,
|
|
341
|
+
gridDash: [],
|
|
342
|
+
gridColor: undefined,
|
|
343
|
+
extra: {
|
|
344
|
+
pointRadius: 4,
|
|
345
|
+
pointHoverRadius: 6,
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
metro: {
|
|
349
|
+
barRadius: 0,
|
|
350
|
+
lineTension: 0.2,
|
|
351
|
+
fill: false,
|
|
352
|
+
gridDash: [],
|
|
353
|
+
gridColor: "transparent",
|
|
354
|
+
extra: {},
|
|
355
|
+
},
|
|
356
|
+
bootstrap: {
|
|
357
|
+
barRadius: 4,
|
|
358
|
+
lineTension: 0.4,
|
|
359
|
+
fill: false,
|
|
360
|
+
gridDash: [],
|
|
361
|
+
gridColor: undefined,
|
|
362
|
+
extra: {},
|
|
363
|
+
},
|
|
364
|
+
cartoon: {
|
|
365
|
+
barRadius: 8,
|
|
366
|
+
lineTension: 0.2,
|
|
367
|
+
fill: false,
|
|
368
|
+
gridDash: [],
|
|
369
|
+
gridColor: undefined,
|
|
370
|
+
extra: { borderWidth: 2 },
|
|
371
|
+
},
|
|
372
|
+
illustration: {
|
|
373
|
+
barRadius: 6,
|
|
374
|
+
lineTension: 0.4,
|
|
375
|
+
fill: true,
|
|
376
|
+
fillAlpha: 0.2,
|
|
377
|
+
gridDash: [2, 4],
|
|
378
|
+
gridColor: undefined,
|
|
379
|
+
extra: {},
|
|
380
|
+
},
|
|
381
|
+
carbon: {
|
|
382
|
+
barRadius: 0,
|
|
383
|
+
lineTension: 0,
|
|
384
|
+
fill: false,
|
|
385
|
+
gridDash: [],
|
|
386
|
+
gridColor: "transparent",
|
|
387
|
+
extra: { borderWidth: 1 },
|
|
388
|
+
},
|
|
389
|
+
"liquid-glass": {
|
|
390
|
+
barRadius: 6,
|
|
391
|
+
lineTension: 0.3,
|
|
392
|
+
fill: true,
|
|
393
|
+
fillAlpha: 0.3,
|
|
394
|
+
gridDash: [],
|
|
395
|
+
gridColor: undefined,
|
|
396
|
+
extra: {},
|
|
397
|
+
},
|
|
398
|
+
"legacy-ios": {
|
|
399
|
+
barRadius: 4,
|
|
400
|
+
lineTension: 0.3,
|
|
401
|
+
fill: true,
|
|
402
|
+
fillAlpha: 0.25,
|
|
403
|
+
gridDash: [],
|
|
404
|
+
gridColor: undefined,
|
|
405
|
+
extra: {},
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Deep-merge b into a (mutates a, returns a).
|
|
411
|
+
*/
|
|
412
|
+
function deepMerge(a, b) {
|
|
413
|
+
for (const key of Object.keys(b)) {
|
|
414
|
+
if (b[key] && typeof b[key] === "object" && !Array.isArray(b[key])) {
|
|
415
|
+
if (!a[key]) a[key] = {};
|
|
416
|
+
deepMerge(a[key], b[key]);
|
|
417
|
+
} else {
|
|
418
|
+
a[key] = b[key];
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return a;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Build a full Chart.js options object inferred from type, style, and tokens.
|
|
426
|
+
* @param {string} type - chart type
|
|
427
|
+
* @param {string} style - visual design language
|
|
428
|
+
* @param {object} tokens - resolved CSS theme tokens
|
|
429
|
+
* @param {{ title, legend, animated, userOptions, seriesCount, xAxisLabel, yAxisLabel }} params
|
|
430
|
+
*/
|
|
431
|
+
export function buildOptions(type, style, tokens, { title, legend, animated, userOptions, seriesCount = 0, xAxisLabel, yAxisLabel }) {
|
|
432
|
+
const so = STYLE_OVERRIDES[style] || STYLE_OVERRIDES.material;
|
|
433
|
+
const isCategory = ["bar", "line", "radar"].includes(type);
|
|
434
|
+
const isSlice = ["pie", "doughnut", "polarArea"].includes(type);
|
|
435
|
+
const isCartesian = isCategory || type === "scatter" || type === "bubble";
|
|
436
|
+
|
|
437
|
+
// Determine legend visibility
|
|
438
|
+
let showLegend;
|
|
439
|
+
if (legend === true) showLegend = true;
|
|
440
|
+
else if (legend === false) showLegend = false;
|
|
441
|
+
else showLegend = isSlice || seriesCount > 1; // auto: show for slice charts or multi-series
|
|
442
|
+
|
|
443
|
+
const opts = {
|
|
444
|
+
responsive: true,
|
|
445
|
+
maintainAspectRatio: false,
|
|
446
|
+
animation: animated ? undefined : false,
|
|
447
|
+
color: tokens.text,
|
|
448
|
+
font: {
|
|
449
|
+
family: getComputedFontFamily(),
|
|
450
|
+
},
|
|
451
|
+
plugins: {
|
|
452
|
+
legend: {
|
|
453
|
+
display: showLegend,
|
|
454
|
+
position: isSlice ? "right" : "top",
|
|
455
|
+
labels: {
|
|
456
|
+
color: tokens.text,
|
|
457
|
+
usePointStyle: true,
|
|
458
|
+
padding: 12,
|
|
459
|
+
font: { size: 12 },
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
tooltip: {
|
|
463
|
+
enabled: true,
|
|
464
|
+
backgroundColor: tokens.cardBg,
|
|
465
|
+
titleColor: tokens.text,
|
|
466
|
+
bodyColor: tokens.textHint,
|
|
467
|
+
borderColor: tokens.border,
|
|
468
|
+
borderWidth: 1,
|
|
469
|
+
padding: 10,
|
|
470
|
+
cornerRadius: 4,
|
|
471
|
+
boxPadding: 4,
|
|
472
|
+
},
|
|
473
|
+
title: title
|
|
474
|
+
? {
|
|
475
|
+
display: true,
|
|
476
|
+
text: title,
|
|
477
|
+
color: tokens.text,
|
|
478
|
+
font: { size: 14, weight: "600" },
|
|
479
|
+
padding: { bottom: 12 },
|
|
480
|
+
}
|
|
481
|
+
: undefined,
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// Combo charts: use cartesian scales with per-dataset types
|
|
486
|
+
const effectiveType = type === "combo" ? "bar" : type;
|
|
487
|
+
|
|
488
|
+
if (isCartesian || type === "combo") {
|
|
489
|
+
opts.scales = buildCartesianScales(effectiveType, tokens, so, xAxisLabel, yAxisLabel);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
if (isSlice) {
|
|
493
|
+
opts.cutout = type === "doughnut" ? "60%" : "0%";
|
|
494
|
+
opts.plugins.legend.position = "right";
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Combo chart: allow combined legend, shared y-axis
|
|
498
|
+
if (type === "combo") {
|
|
499
|
+
opts.borderRadius = so.barRadius;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// Apply per-type defaults
|
|
503
|
+
if (type === "radar") {
|
|
504
|
+
opts.scales = {
|
|
505
|
+
r: {
|
|
506
|
+
grid: {
|
|
507
|
+
color: tokens.border,
|
|
508
|
+
borderDash: so.gridDash && so.gridDash.length > 0 ? so.gridDash : undefined,
|
|
509
|
+
circular: true,
|
|
510
|
+
},
|
|
511
|
+
angleLines: {
|
|
512
|
+
color: tokens.border,
|
|
513
|
+
borderDash: so.gridDash && so.gridDash.length > 0 ? so.gridDash : undefined,
|
|
514
|
+
},
|
|
515
|
+
pointLabels: {
|
|
516
|
+
color: tokens.text,
|
|
517
|
+
font: { size: 11 },
|
|
518
|
+
},
|
|
519
|
+
ticks: {
|
|
520
|
+
display: false,
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Apply style overrides to datasets
|
|
527
|
+
if (type === "bar" && so.barRadius !== undefined) {
|
|
528
|
+
opts.borderRadius = so.barRadius;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Apply style overrides
|
|
532
|
+
if (so.extra) {
|
|
533
|
+
deepMerge(opts, so.extra);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// User escape hatch — deep merge last
|
|
537
|
+
if (userOptions && Object.keys(userOptions).length > 0) {
|
|
538
|
+
deepMerge(opts, userOptions);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
return opts;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function buildCartesianScales(type, tokens, so, xAxisLabel, yAxisLabel) {
|
|
545
|
+
const scales = {};
|
|
546
|
+
const isVertical = type !== "bar";
|
|
547
|
+
|
|
548
|
+
const gridColor = so.gridColor || tokens.border;
|
|
549
|
+
// Always provide a valid borderDash array to avoid Canvas setLineDash(non-iterable) errors
|
|
550
|
+
const borderDash = so.gridDash && so.gridDash.length > 0 ? so.gridDash : undefined;
|
|
551
|
+
const gridOpts = { color: gridColor, drawBorder: false };
|
|
552
|
+
if (borderDash) {
|
|
553
|
+
gridOpts.borderDash = borderDash;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (type === "scatter" || type === "bubble") {
|
|
557
|
+
scales.x = {
|
|
558
|
+
type: "linear",
|
|
559
|
+
position: "bottom",
|
|
560
|
+
grid: { ...gridOpts },
|
|
561
|
+
ticks: { color: tokens.textHint },
|
|
562
|
+
};
|
|
563
|
+
scales.y = {
|
|
564
|
+
type: "linear",
|
|
565
|
+
grid: { ...gridOpts },
|
|
566
|
+
ticks: { color: tokens.textHint },
|
|
567
|
+
};
|
|
568
|
+
} else {
|
|
569
|
+
scales.x = {
|
|
570
|
+
type: "category",
|
|
571
|
+
grid: { display: false },
|
|
572
|
+
ticks: { color: tokens.textHint },
|
|
573
|
+
};
|
|
574
|
+
scales.y = {
|
|
575
|
+
type: "linear",
|
|
576
|
+
beginAtZero: true,
|
|
577
|
+
grid: { ...gridOpts },
|
|
578
|
+
ticks: { color: tokens.textHint },
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// Axis titles
|
|
583
|
+
if (xAxisLabel) {
|
|
584
|
+
scales.x.title = {
|
|
585
|
+
display: true,
|
|
586
|
+
text: xAxisLabel,
|
|
587
|
+
color: tokens.textHint,
|
|
588
|
+
font: { size: 12 },
|
|
589
|
+
padding: { top: 8 },
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (yAxisLabel) {
|
|
593
|
+
scales.y.title = {
|
|
594
|
+
display: true,
|
|
595
|
+
text: yAxisLabel,
|
|
596
|
+
color: tokens.textHint,
|
|
597
|
+
font: { size: 12 },
|
|
598
|
+
padding: { bottom: 8 },
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// Bar-specific: center bars over category labels
|
|
603
|
+
if (type === "bar") {
|
|
604
|
+
scales.x.offset = true;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
return scales;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function getComputedFontFamily() {
|
|
611
|
+
try {
|
|
612
|
+
return getComputedStyle(document.documentElement).fontFamily || "inherit";
|
|
613
|
+
} catch {
|
|
614
|
+
return "inherit";
|
|
615
|
+
}
|
|
616
|
+
}
|