@angx/ngx-chart-kit 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1039 @@
1
+ import { isPlatformBrowser } from "@angular/common";
2
+ import * as i0 from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, PLATFORM_ID, booleanAttribute, computed, effect, inject, input, numberAttribute, output, signal, viewChild } from "@angular/core";
4
+ let modulePromise = null;
5
+ const registeredForms = /* @__PURE__ */ new Set();
6
+ function registrablesFor(module, type) {
7
+ const shared = [module.Legend, module.Tooltip];
8
+ switch (type) {
9
+ case "bar":
10
+ case "hbar": return [
11
+ ...shared,
12
+ module.BarController,
13
+ module.BarElement,
14
+ module.CategoryScale,
15
+ module.LinearScale
16
+ ];
17
+ case "line":
18
+ case "area": return [
19
+ ...shared,
20
+ module.LineController,
21
+ module.LineElement,
22
+ module.PointElement,
23
+ module.CategoryScale,
24
+ module.LinearScale,
25
+ module.Filler
26
+ ];
27
+ case "pie": return [
28
+ ...shared,
29
+ module.PieController,
30
+ module.ArcElement
31
+ ];
32
+ case "doughnut": return [
33
+ ...shared,
34
+ module.DoughnutController,
35
+ module.ArcElement
36
+ ];
37
+ case "radar": return [
38
+ ...shared,
39
+ module.RadarController,
40
+ module.LineElement,
41
+ module.PointElement,
42
+ module.RadialLinearScale,
43
+ module.Filler
44
+ ];
45
+ }
46
+ }
47
+ async function loadChartJs(type) {
48
+ modulePromise ??= import("chart.js");
49
+ const module = await modulePromise;
50
+ if (!registeredForms.has(type)) {
51
+ module.Chart.register(...registrablesFor(module, type));
52
+ registeredForms.add(type);
53
+ }
54
+ return module.Chart;
55
+ }
56
+ const CHART_KIT_PALETTE = [
57
+ "#0072b2",
58
+ "#e69f00",
59
+ "#009e73",
60
+ "#cc79a7",
61
+ "#56b4e9",
62
+ "#d55e00",
63
+ "#785ef0",
64
+ "#7f7f7f"
65
+ ];
66
+ const CHART_KIT_CSS_PROPERTIES = {
67
+ palette: "--chart-kit-palette",
68
+ seriesPrefix: "--chart-kit-series-",
69
+ text: "--chart-kit-text",
70
+ muted: "--chart-kit-muted",
71
+ grid: "--chart-kit-grid",
72
+ surface: "--chart-kit-surface",
73
+ tooltipBackground: "--chart-kit-tooltip-bg",
74
+ tooltipText: "--chart-kit-tooltip-text",
75
+ font: "--chart-kit-font"
76
+ };
77
+ const HEX = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
78
+ const RGB_FUNCTION = /^rgba?\(([^)]*)\)$/i;
79
+ function splitCssList(value) {
80
+ const parts = [];
81
+ let depth = 0;
82
+ let current = "";
83
+ for (const character of value) {
84
+ if (character === "(") depth += 1;
85
+ else if (character === ")") depth = Math.max(depth - 1, 0);
86
+ if (character === "," && depth === 0) {
87
+ parts.push(current);
88
+ current = "";
89
+ continue;
90
+ }
91
+ current += character;
92
+ }
93
+ parts.push(current);
94
+ return parts.map((part) => part.trim()).filter((part) => part.length > 0);
95
+ }
96
+ function parseColor(color) {
97
+ const value = color.trim();
98
+ if (HEX.test(value)) {
99
+ const digits = value.slice(1);
100
+ const expand = (text) => text.length === 1 ? parseInt(text + text, 16) : parseInt(text, 16);
101
+ const step = digits.length <= 4 ? 1 : 2;
102
+ const channels = [];
103
+ for (let index = 0; index < digits.length; index += step) channels.push(expand(digits.slice(index, index + step)));
104
+ const [r = 0, g = 0, b = 0, a] = channels;
105
+ return [
106
+ r,
107
+ g,
108
+ b,
109
+ a === void 0 ? 1 : a / 255
110
+ ];
111
+ }
112
+ const functional = RGB_FUNCTION.exec(value);
113
+ if (functional) {
114
+ const [channels, alphaText] = functional[1].split("/");
115
+ const numbers = channels.split(/[\s,]+/).map((part) => part.trim()).filter((part) => part.length > 0);
116
+ if (numbers.length < 3) return null;
117
+ const toChannel = (part) => part.endsWith("%") ? Number.parseFloat(part) / 100 * 255 : Number.parseFloat(part);
118
+ const toAlpha = (part) => {
119
+ if (part === void 0) return 1;
120
+ const trimmed = part.trim();
121
+ return trimmed.endsWith("%") ? Number.parseFloat(trimmed) / 100 : Number.parseFloat(trimmed);
122
+ };
123
+ const rgb = numbers.slice(0, 3).map(toChannel);
124
+ const alpha = toAlpha(alphaText ?? numbers[3]);
125
+ if (rgb.some((channel) => !Number.isFinite(channel)) || !Number.isFinite(alpha)) return null;
126
+ return [
127
+ rgb[0],
128
+ rgb[1],
129
+ rgb[2],
130
+ alpha
131
+ ];
132
+ }
133
+ return null;
134
+ }
135
+ function withAlpha(color, alpha) {
136
+ const parsed = parseColor(color);
137
+ if (!parsed) return color;
138
+ const [r, g, b, existing] = parsed;
139
+ const round = (channel) => Math.round(Math.min(Math.max(channel, 0), 255));
140
+ const combined = Math.min(Math.max(existing * alpha, 0), 1);
141
+ return `rgba(${round(r)}, ${round(g)}, ${round(b)}, ${Number(combined.toFixed(3))})`;
142
+ }
143
+ function relativeLuminance(color) {
144
+ const parsed = parseColor(color);
145
+ if (!parsed) return null;
146
+ const [r, g, b] = parsed;
147
+ const channel = (value) => {
148
+ const sRgb = value / 255;
149
+ return sRgb <= .03928 ? sRgb / 12.92 : Math.pow((sRgb + .055) / 1.055, 2.4);
150
+ };
151
+ return .2126 * channel(r) + .7152 * channel(g) + .0722 * channel(b);
152
+ }
153
+ const MAX_SERIES_SLOTS = 24;
154
+ const FALLBACK_TEXT = "#1f2328";
155
+ const FALLBACK_FONT = "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
156
+ function read(style, property) {
157
+ const value = style.getPropertyValue(property)?.trim();
158
+ return value ? value : void 0;
159
+ }
160
+ function isTransparent(color) {
161
+ if (!color) return true;
162
+ const value = color.trim().toLowerCase();
163
+ return value === "transparent" || /^rgba?\([^)]*[\s,/]0(?:\.0+)?\)$/.test(value);
164
+ }
165
+ function readPalette(style, override) {
166
+ const listed = read(style, CHART_KIT_CSS_PROPERTIES.palette);
167
+ const base = override && override.length > 0 ? [...override] : listed ? splitCssList(listed) : [...CHART_KIT_PALETTE];
168
+ const palette = base.length > 0 ? base : [...CHART_KIT_PALETTE];
169
+ for (let slot = 1; slot <= MAX_SERIES_SLOTS; slot += 1) {
170
+ const value = read(style, `${CHART_KIT_CSS_PROPERTIES.seriesPrefix}${slot}`);
171
+ if (!value) continue;
172
+ palette[slot - 1] = value;
173
+ }
174
+ for (let index = 0; index < palette.length; index += 1) palette[index] ??= CHART_KIT_PALETTE[index % CHART_KIT_PALETTE.length];
175
+ return palette;
176
+ }
177
+ function readChartKitTheme(style, paletteOverride) {
178
+ const text = read(style, CHART_KIT_CSS_PROPERTIES.text) ?? read(style, "color") ?? FALLBACK_TEXT;
179
+ const textLuminance = relativeLuminance(text);
180
+ const onDarkSurface = textLuminance !== null && textLuminance > .5;
181
+ const backgroundColor = read(style, "background-color");
182
+ const surface = read(style, CHART_KIT_CSS_PROPERTIES.surface) ?? (isTransparent(backgroundColor) ? onDarkSurface ? "#16181d" : "#ffffff" : backgroundColor);
183
+ const tooltipBackground = read(style, CHART_KIT_CSS_PROPERTIES.tooltipBackground) ?? (onDarkSurface ? "rgba(244, 246, 250, 0.94)" : "rgba(24, 26, 31, 0.92)");
184
+ const tooltipText = read(style, CHART_KIT_CSS_PROPERTIES.tooltipText) ?? (onDarkSurface ? "#16181d" : "#f7f8fa");
185
+ return {
186
+ palette: readPalette(style, paletteOverride),
187
+ text,
188
+ muted: read(style, CHART_KIT_CSS_PROPERTIES.muted) ?? withAlpha(text, .74),
189
+ grid: read(style, CHART_KIT_CSS_PROPERTIES.grid) ?? withAlpha(text, .14),
190
+ surface,
191
+ tooltipBackground,
192
+ tooltipText,
193
+ font: read(style, CHART_KIT_CSS_PROPERTIES.font) ?? read(style, "font-family") ?? FALLBACK_FONT
194
+ };
195
+ }
196
+ function paletteColor(theme, index) {
197
+ const { palette } = theme;
198
+ if (palette.length === 0) return CHART_KIT_PALETTE[index % CHART_KIT_PALETTE.length];
199
+ return palette[index % palette.length];
200
+ }
201
+ function fallbackLabel(index) {
202
+ return `Item ${index + 1}`;
203
+ }
204
+ function toChartValue(value) {
205
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
206
+ }
207
+ function chartKitRowCount(data) {
208
+ return data.series.reduce((longest, series) => Math.max(longest, series.data.length), data.labels.length);
209
+ }
210
+ function chartKitLabels(data) {
211
+ const count = chartKitRowCount(data);
212
+ const labels = [];
213
+ for (let index = 0; index < count; index += 1) {
214
+ const label = data.labels[index];
215
+ labels.push(label !== void 0 && label !== "" ? label : fallbackLabel(index));
216
+ }
217
+ return labels;
218
+ }
219
+ function createDefaultValueFormat(locale, emptyText = "No data") {
220
+ return (value) => value === null ? emptyText : value.toLocaleString(locale);
221
+ }
222
+ function buildChartKitTable(input) {
223
+ const { data, caption, categoryHeader, format } = input;
224
+ const rows = chartKitLabels(data).map((label, pointIndex) => ({
225
+ label,
226
+ cells: data.series.map((series, seriesIndex) => {
227
+ const value = toChartValue(series.data[pointIndex]);
228
+ return {
229
+ value,
230
+ text: format(value, {
231
+ seriesIndex,
232
+ pointIndex,
233
+ seriesLabel: series.label,
234
+ label
235
+ })
236
+ };
237
+ })
238
+ }));
239
+ return {
240
+ caption,
241
+ categoryHeader,
242
+ seriesHeaders: data.series.map((series) => series.label),
243
+ rows
244
+ };
245
+ }
246
+ const CHART_JS_TYPE = {
247
+ bar: "bar",
248
+ hbar: "bar",
249
+ line: "line",
250
+ area: "line",
251
+ pie: "pie",
252
+ doughnut: "doughnut",
253
+ radar: "radar"
254
+ };
255
+ function isRadial(type) {
256
+ return type === "pie" || type === "doughnut";
257
+ }
258
+ function isCartesian(type) {
259
+ return type === "bar" || type === "hbar" || type === "line" || type === "area";
260
+ }
261
+ function valueAxis(type) {
262
+ return type === "hbar" ? "x" : "y";
263
+ }
264
+ function buildChartKitDatasets(input) {
265
+ const { type, data, theme } = input;
266
+ const rows = chartKitLabels(data).length;
267
+ const radial = isRadial(type);
268
+ return data.series.map((series, seriesIndex) => {
269
+ const values = [];
270
+ for (let index = 0; index < rows; index += 1) values.push(toChartValue(series.data[index]));
271
+ const color = series.color ?? paletteColor(theme, seriesIndex);
272
+ const sliceColors = radial ? Array.from({ length: rows }, (_, index) => series.color ?? paletteColor(theme, index)) : void 0;
273
+ const base = {
274
+ label: series.label,
275
+ data: values,
276
+ backgroundColor: sliceColors ?? color,
277
+ borderColor: sliceColors ?? color,
278
+ borderWidth: 0
279
+ };
280
+ switch (type) {
281
+ case "bar":
282
+ case "hbar": return {
283
+ ...base,
284
+ borderRadius: 4,
285
+ maxBarThickness: 64
286
+ };
287
+ case "line":
288
+ case "area": return {
289
+ ...base,
290
+ backgroundColor: type === "area" ? withAlpha(color, .22) : color,
291
+ borderColor: color,
292
+ borderWidth: 2,
293
+ fill: type === "area",
294
+ tension: .32,
295
+ pointRadius: 3,
296
+ pointHoverRadius: 5,
297
+ pointBackgroundColor: color,
298
+ pointBorderColor: theme.surface,
299
+ spanGaps: false
300
+ };
301
+ case "radar": return {
302
+ ...base,
303
+ backgroundColor: withAlpha(color, .2),
304
+ borderColor: color,
305
+ borderWidth: 2,
306
+ fill: true,
307
+ pointRadius: 3,
308
+ pointHoverRadius: 5,
309
+ pointBackgroundColor: color,
310
+ pointBorderColor: theme.surface
311
+ };
312
+ case "pie":
313
+ case "doughnut": return {
314
+ ...base,
315
+ borderColor: theme.surface,
316
+ borderWidth: 2,
317
+ hoverOffset: 6
318
+ };
319
+ }
320
+ });
321
+ }
322
+ function cartesianAxis(input, axis) {
323
+ const { theme, type, stacked, beginAtZero } = input;
324
+ const carriesValues = valueAxis(type) === axis;
325
+ return {
326
+ stacked,
327
+ grid: {
328
+ display: carriesValues,
329
+ color: theme.grid,
330
+ drawTicks: false
331
+ },
332
+ border: {
333
+ color: theme.grid,
334
+ display: true
335
+ },
336
+ ticks: {
337
+ color: theme.muted,
338
+ font: {
339
+ family: theme.font,
340
+ size: 12
341
+ },
342
+ padding: 8,
343
+ ...carriesValues ? {} : { autoSkipPadding: 12 }
344
+ },
345
+ ...carriesValues && beginAtZero ? { beginAtZero: true } : {}
346
+ };
347
+ }
348
+ function tooltipLabel(input, item) {
349
+ const { data, format } = input;
350
+ const labels = chartKitLabels(data);
351
+ const seriesIndex = item.datasetIndex;
352
+ const pointIndex = item.dataIndex;
353
+ const series = data.series[seriesIndex];
354
+ const text = format(toChartValue(item.raw), {
355
+ seriesIndex,
356
+ pointIndex,
357
+ seriesLabel: series?.label ?? "",
358
+ label: labels[pointIndex] ?? ""
359
+ });
360
+ return data.series.length > 1 && series ? `${series.label}: ${text}` : text;
361
+ }
362
+ function buildChartKitOptions(input) {
363
+ const { type, theme, data, legend, tooltips, animate, locale, onPointSelect } = input;
364
+ const labels = chartKitLabels(data);
365
+ const options = {
366
+ responsive: true,
367
+ maintainAspectRatio: false,
368
+ ...locale ? { locale } : {},
369
+ animation: animate ? { duration: 420 } : false,
370
+ interaction: isCartesian(type) ? {
371
+ mode: "index",
372
+ intersect: false
373
+ } : {
374
+ mode: "nearest",
375
+ intersect: true
376
+ },
377
+ plugins: {
378
+ legend: {
379
+ display: legend && (data.series.length > 1 || isRadial(type)),
380
+ position: "bottom",
381
+ labels: {
382
+ color: theme.text,
383
+ font: {
384
+ family: theme.font,
385
+ size: 12
386
+ },
387
+ usePointStyle: true,
388
+ pointStyle: "circle",
389
+ boxWidth: 8,
390
+ boxHeight: 8,
391
+ padding: 16
392
+ }
393
+ },
394
+ tooltip: {
395
+ enabled: tooltips,
396
+ backgroundColor: theme.tooltipBackground,
397
+ titleColor: theme.tooltipText,
398
+ bodyColor: theme.tooltipText,
399
+ borderColor: theme.grid,
400
+ borderWidth: 1,
401
+ padding: 10,
402
+ cornerRadius: 6,
403
+ displayColors: data.series.length > 1,
404
+ titleFont: {
405
+ family: theme.font,
406
+ size: 12,
407
+ weight: "bold"
408
+ },
409
+ bodyFont: {
410
+ family: theme.font,
411
+ size: 12
412
+ },
413
+ callbacks: { label: (item) => tooltipLabel(input, item) }
414
+ }
415
+ }
416
+ };
417
+ if (type === "hbar") options.indexAxis = "y";
418
+ if (type === "doughnut") options.cutout = "62%";
419
+ if (isCartesian(type)) options.scales = {
420
+ x: cartesianAxis(input, "x"),
421
+ y: cartesianAxis(input, "y")
422
+ };
423
+ if (type === "radar") options.scales = { r: {
424
+ beginAtZero: input.beginAtZero,
425
+ grid: { color: theme.grid },
426
+ angleLines: { color: theme.grid },
427
+ pointLabels: {
428
+ color: theme.muted,
429
+ font: {
430
+ family: theme.font,
431
+ size: 12
432
+ }
433
+ },
434
+ ticks: {
435
+ color: theme.muted,
436
+ backdropColor: "transparent",
437
+ font: {
438
+ family: theme.font,
439
+ size: 11
440
+ }
441
+ }
442
+ } };
443
+ if (onPointSelect) options.onClick = (_event, elements) => {
444
+ const first = elements[0];
445
+ if (!first) return;
446
+ const series = data.series[first.datasetIndex];
447
+ if (!series) return;
448
+ const value = toChartValue(series.data[first.index]);
449
+ onPointSelect({
450
+ seriesIndex: first.datasetIndex,
451
+ pointIndex: first.index,
452
+ seriesLabel: series.label,
453
+ label: labels[first.index] ?? "",
454
+ value
455
+ });
456
+ };
457
+ return options;
458
+ }
459
+ function toChartConfiguration(input) {
460
+ return {
461
+ type: CHART_JS_TYPE[input.type],
462
+ data: {
463
+ labels: chartKitLabels(input.data),
464
+ datasets: buildChartKitDatasets(input)
465
+ },
466
+ options: buildChartKitOptions(input)
467
+ };
468
+ }
469
+ function applyChartKitData(chart, input) {
470
+ chart.data.labels = chartKitLabels(input.data);
471
+ chart.data.datasets = buildChartKitDatasets(input);
472
+ chart.options = buildChartKitOptions(input);
473
+ chart.update(input.animate ? void 0 : "none");
474
+ }
475
+ function chartJsTypeFor(type) {
476
+ return CHART_JS_TYPE[type];
477
+ }
478
+ const TYPE_NAMES = {
479
+ bar: "bar chart",
480
+ hbar: "horizontal bar chart",
481
+ line: "line chart",
482
+ area: "area chart",
483
+ pie: "pie chart",
484
+ doughnut: "doughnut chart",
485
+ radar: "radar chart"
486
+ };
487
+ const THEME_ATTRIBUTES = [
488
+ "class",
489
+ "style",
490
+ "data-theme",
491
+ "data-mode",
492
+ "data-color-scheme"
493
+ ];
494
+ const DEFAULT_HEIGHT = 320;
495
+ let instanceCounter = 0;
496
+ var NgxChartKitComponent = class NgxChartKitComponent {
497
+ host = inject(ElementRef);
498
+ canvasRef = viewChild("canvas", ...ngDevMode ? [{ debugName: "canvasRef" }] : /* istanbul ignore next */ []);
499
+ isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
500
+ descriptionId = `chart-kit-description-${instanceCounter += 1}`;
501
+ data = input.required(...ngDevMode ? [{ debugName: "data" }] : /* istanbul ignore next */ []);
502
+ caption = input.required(...ngDevMode ? [{ debugName: "caption" }] : /* istanbul ignore next */ []);
503
+ type = input("bar", ...ngDevMode ? [{ debugName: "type" }] : /* istanbul ignore next */ []);
504
+ description = input("", ...ngDevMode ? [{ debugName: "description" }] : /* istanbul ignore next */ []);
505
+ categoryHeader = input("Category", ...ngDevMode ? [{ debugName: "categoryHeader" }] : /* istanbul ignore next */ []);
506
+ dataTable = input("hidden", ...ngDevMode ? [{ debugName: "dataTable" }] : /* istanbul ignore next */ []);
507
+ height = input(DEFAULT_HEIGHT, {
508
+ ...ngDevMode ? { debugName: "height" } : /* istanbul ignore next */ {},
509
+ transform: numberAttribute
510
+ });
511
+ stacked = input(false, {
512
+ ...ngDevMode ? { debugName: "stacked" } : /* istanbul ignore next */ {},
513
+ transform: booleanAttribute
514
+ });
515
+ legend = input(true, {
516
+ ...ngDevMode ? { debugName: "legend" } : /* istanbul ignore next */ {},
517
+ transform: booleanAttribute
518
+ });
519
+ tooltips = input(true, {
520
+ ...ngDevMode ? { debugName: "tooltips" } : /* istanbul ignore next */ {},
521
+ transform: booleanAttribute
522
+ });
523
+ animate = input(true, {
524
+ ...ngDevMode ? { debugName: "animate" } : /* istanbul ignore next */ {},
525
+ transform: booleanAttribute
526
+ });
527
+ beginAtZero = input(true, {
528
+ ...ngDevMode ? { debugName: "beginAtZero" } : /* istanbul ignore next */ {},
529
+ transform: booleanAttribute
530
+ });
531
+ palette = input(void 0, ...ngDevMode ? [{ debugName: "palette" }] : /* istanbul ignore next */ []);
532
+ locale = input(void 0, ...ngDevMode ? [{ debugName: "locale" }] : /* istanbul ignore next */ []);
533
+ valueFormat = input(void 0, ...ngDevMode ? [{ debugName: "valueFormat" }] : /* istanbul ignore next */ []);
534
+ emptyValueText = input("No data", ...ngDevMode ? [{ debugName: "emptyValueText" }] : /* istanbul ignore next */ []);
535
+ pointSelect = output();
536
+ chartCreate = output();
537
+ renderError = output();
538
+ themeRevision = signal(0, ...ngDevMode ? [{ debugName: "themeRevision" }] : /* istanbul ignore next */ []);
539
+ reducedMotion = signal(false, ...ngDevMode ? [{ debugName: "reducedMotion" }] : /* istanbul ignore next */ []);
540
+ safeHeight = computed(() => {
541
+ const height = this.height();
542
+ return Number.isFinite(height) && height > 0 ? height : DEFAULT_HEIGHT;
543
+ }, ...ngDevMode ? [{ debugName: "safeHeight" }] : /* istanbul ignore next */ []);
544
+ theme = computed(() => {
545
+ this.themeRevision();
546
+ return readChartKitTheme(this.isBrowser ? getComputedStyle(this.host.nativeElement) : { getPropertyValue: () => "" }, this.palette());
547
+ }, ...ngDevMode ? [{ debugName: "theme" }] : /* istanbul ignore next */ []);
548
+ format = computed(() => this.valueFormat() ?? createDefaultValueFormat(this.locale(), this.emptyValueText()), ...ngDevMode ? [{ debugName: "format" }] : /* istanbul ignore next */ []);
549
+ accessibleName = computed(() => `${this.caption()}. ${TYPE_NAMES[this.type()]}. Described by the table that follows.`, ...ngDevMode ? [{ debugName: "accessibleName" }] : /* istanbul ignore next */ []);
550
+ table = computed(() => buildChartKitTable({
551
+ data: this.data(),
552
+ caption: this.caption(),
553
+ categoryHeader: this.categoryHeader(),
554
+ format: this.format()
555
+ }), ...ngDevMode ? [{ debugName: "table" }] : /* istanbul ignore next */ []);
556
+ renderInput = computed(() => ({
557
+ type: this.type(),
558
+ data: this.data(),
559
+ theme: this.theme(),
560
+ format: this.format(),
561
+ caption: this.caption(),
562
+ stacked: this.stacked(),
563
+ legend: this.legend(),
564
+ tooltips: this.tooltips(),
565
+ animate: this.animate() && !this.reducedMotion(),
566
+ beginAtZero: this.beginAtZero(),
567
+ locale: this.locale(),
568
+ onPointSelect: (point) => this.pointSelect.emit(point)
569
+ }), ...ngDevMode ? [{ debugName: "renderInput" }] : /* istanbul ignore next */ []);
570
+ chart;
571
+ chartJsType;
572
+ drawToken = 0;
573
+ destroyed = false;
574
+ themeRefreshScheduled = false;
575
+ constructor() {
576
+ const destroyRef = inject(DestroyRef);
577
+ if (this.isBrowser) this.watchColorScheme(destroyRef);
578
+ effect(() => {
579
+ const input = this.renderInput();
580
+ const canvas = this.canvasRef()?.nativeElement;
581
+ if (!canvas) return;
582
+ this.draw(input, canvas).catch((error) => {
583
+ if (!this.destroyed) this.renderError.emit(error);
584
+ });
585
+ });
586
+ destroyRef.onDestroy(() => {
587
+ this.destroyed = true;
588
+ this.chart?.destroy();
589
+ this.chart = void 0;
590
+ });
591
+ }
592
+ refreshTheme() {
593
+ this.themeRevision.update((revision) => revision + 1);
594
+ }
595
+ async draw(input, canvas) {
596
+ const token = this.drawToken += 1;
597
+ const ChartConstructor = await loadChartJs(input.type);
598
+ if (this.destroyed || token !== this.drawToken) return;
599
+ const chartJsType = chartJsTypeFor(input.type);
600
+ if (this.chart && this.chartJsType === chartJsType) {
601
+ applyChartKitData(this.chart, input);
602
+ return;
603
+ }
604
+ this.chart?.destroy();
605
+ this.chart = new ChartConstructor(canvas, toChartConfiguration(input));
606
+ this.chartJsType = chartJsType;
607
+ this.chartCreate.emit(this.chart);
608
+ }
609
+ watchColorScheme(destroyRef) {
610
+ const onSchemeChange = () => this.scheduleThemeRefresh();
611
+ if (typeof window.matchMedia === "function") {
612
+ const dark = window.matchMedia("(prefers-color-scheme: dark)");
613
+ const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
614
+ const onMotionChange = () => this.reducedMotion.set(motion.matches);
615
+ this.reducedMotion.set(motion.matches);
616
+ dark.addEventListener("change", onSchemeChange);
617
+ motion.addEventListener("change", onMotionChange);
618
+ destroyRef.onDestroy(() => {
619
+ dark.removeEventListener("change", onSchemeChange);
620
+ motion.removeEventListener("change", onMotionChange);
621
+ });
622
+ }
623
+ if (typeof MutationObserver === "function") {
624
+ const observer = new MutationObserver(onSchemeChange);
625
+ for (const element of [
626
+ document.documentElement,
627
+ document.body,
628
+ this.host.nativeElement
629
+ ]) if (element) observer.observe(element, {
630
+ attributes: true,
631
+ attributeFilter: THEME_ATTRIBUTES
632
+ });
633
+ destroyRef.onDestroy(() => observer.disconnect());
634
+ }
635
+ }
636
+ scheduleThemeRefresh() {
637
+ if (this.themeRefreshScheduled) return;
638
+ this.themeRefreshScheduled = true;
639
+ const run = () => {
640
+ this.themeRefreshScheduled = false;
641
+ if (!this.destroyed) this.refreshTheme();
642
+ };
643
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(run);
644
+ else setTimeout(run);
645
+ }
646
+ static ɵfac = i0.ɵɵngDeclareFactory({
647
+ minVersion: "12.0.0",
648
+ version: "22.3.2",
649
+ ngImport: i0,
650
+ type: NgxChartKitComponent,
651
+ deps: [],
652
+ target: i0.ɵɵFactoryTarget.Component
653
+ });
654
+ static ɵcmp = i0.ɵɵngDeclareComponent({
655
+ minVersion: "17.0.0",
656
+ version: "22.3.2",
657
+ type: NgxChartKitComponent,
658
+ isStandalone: true,
659
+ selector: "chart-kit",
660
+ inputs: {
661
+ data: {
662
+ classPropertyName: "data",
663
+ publicName: "data",
664
+ isSignal: true,
665
+ isRequired: true,
666
+ transformFunction: null
667
+ },
668
+ caption: {
669
+ classPropertyName: "caption",
670
+ publicName: "caption",
671
+ isSignal: true,
672
+ isRequired: true,
673
+ transformFunction: null
674
+ },
675
+ type: {
676
+ classPropertyName: "type",
677
+ publicName: "type",
678
+ isSignal: true,
679
+ isRequired: false,
680
+ transformFunction: null
681
+ },
682
+ description: {
683
+ classPropertyName: "description",
684
+ publicName: "description",
685
+ isSignal: true,
686
+ isRequired: false,
687
+ transformFunction: null
688
+ },
689
+ categoryHeader: {
690
+ classPropertyName: "categoryHeader",
691
+ publicName: "categoryHeader",
692
+ isSignal: true,
693
+ isRequired: false,
694
+ transformFunction: null
695
+ },
696
+ dataTable: {
697
+ classPropertyName: "dataTable",
698
+ publicName: "dataTable",
699
+ isSignal: true,
700
+ isRequired: false,
701
+ transformFunction: null
702
+ },
703
+ height: {
704
+ classPropertyName: "height",
705
+ publicName: "height",
706
+ isSignal: true,
707
+ isRequired: false,
708
+ transformFunction: null
709
+ },
710
+ stacked: {
711
+ classPropertyName: "stacked",
712
+ publicName: "stacked",
713
+ isSignal: true,
714
+ isRequired: false,
715
+ transformFunction: null
716
+ },
717
+ legend: {
718
+ classPropertyName: "legend",
719
+ publicName: "legend",
720
+ isSignal: true,
721
+ isRequired: false,
722
+ transformFunction: null
723
+ },
724
+ tooltips: {
725
+ classPropertyName: "tooltips",
726
+ publicName: "tooltips",
727
+ isSignal: true,
728
+ isRequired: false,
729
+ transformFunction: null
730
+ },
731
+ animate: {
732
+ classPropertyName: "animate",
733
+ publicName: "animate",
734
+ isSignal: true,
735
+ isRequired: false,
736
+ transformFunction: null
737
+ },
738
+ beginAtZero: {
739
+ classPropertyName: "beginAtZero",
740
+ publicName: "beginAtZero",
741
+ isSignal: true,
742
+ isRequired: false,
743
+ transformFunction: null
744
+ },
745
+ palette: {
746
+ classPropertyName: "palette",
747
+ publicName: "palette",
748
+ isSignal: true,
749
+ isRequired: false,
750
+ transformFunction: null
751
+ },
752
+ locale: {
753
+ classPropertyName: "locale",
754
+ publicName: "locale",
755
+ isSignal: true,
756
+ isRequired: false,
757
+ transformFunction: null
758
+ },
759
+ valueFormat: {
760
+ classPropertyName: "valueFormat",
761
+ publicName: "valueFormat",
762
+ isSignal: true,
763
+ isRequired: false,
764
+ transformFunction: null
765
+ },
766
+ emptyValueText: {
767
+ classPropertyName: "emptyValueText",
768
+ publicName: "emptyValueText",
769
+ isSignal: true,
770
+ isRequired: false,
771
+ transformFunction: null
772
+ }
773
+ },
774
+ outputs: {
775
+ pointSelect: "pointSelect",
776
+ chartCreate: "chartCreate",
777
+ renderError: "renderError"
778
+ },
779
+ viewQueries: [{
780
+ propertyName: "canvasRef",
781
+ first: true,
782
+ predicate: ["canvas"],
783
+ descendants: true,
784
+ isSignal: true
785
+ }],
786
+ ngImport: i0,
787
+ template: `
788
+ @if (isBrowser) {
789
+ <div class="chart-kit__canvas" [style.height.px]="safeHeight()">
790
+ <canvas
791
+ #canvas
792
+ role="img"
793
+ [attr.aria-label]="accessibleName()"
794
+ [attr.aria-describedby]="description() ? descriptionId : null"
795
+ ></canvas>
796
+ </div>
797
+ }
798
+
799
+ <div class="chart-kit__data" [class.chart-kit__data--hidden]="dataTable() === 'hidden'">
800
+ @if (description()) {
801
+ <p class="chart-kit__description" [id]="descriptionId">{{ description() }}</p>
802
+ }
803
+
804
+ <table class="chart-kit__table">
805
+ <caption class="chart-kit__caption">
806
+ {{ caption() }}
807
+ </caption>
808
+ <thead>
809
+ <tr>
810
+ <th scope="col">{{ table().categoryHeader }}</th>
811
+ @for (header of table().seriesHeaders; track $index) {
812
+ <th scope="col">{{ header }}</th>
813
+ }
814
+ </tr>
815
+ </thead>
816
+ <tbody>
817
+ @for (row of table().rows; track $index) {
818
+ <tr>
819
+ <th scope="row">{{ row.label }}</th>
820
+ @for (cell of row.cells; track $index) {
821
+ <td>{{ cell.text }}</td>
822
+ }
823
+ </tr>
824
+ }
825
+ </tbody>
826
+ </table>
827
+ </div>
828
+ `,
829
+ isInline: true,
830
+ styles: [":host{display:block;position:relative}.chart-kit__canvas{position:relative;width:100%}.chart-kit__canvas canvas{display:block}.chart-kit__data--hidden{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;white-space:nowrap;border:0;clip-path:inset(50%)}.chart-kit__description{margin:0 0 .5rem}.chart-kit__table{width:100%;border-collapse:collapse;font:inherit;text-align:left}.chart-kit__caption{padding-block:.5rem;font-weight:600;text-align:left}.chart-kit__table th,.chart-kit__table td{padding:.375rem .5rem;border-bottom:1px solid var(--chart-kit-grid, currentColor)}.chart-kit__table td{text-align:right;font-variant-numeric:tabular-nums}\n"],
831
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
832
+ });
833
+ };
834
+ i0.ɵɵngDeclareClassMetadata({
835
+ minVersion: "12.0.0",
836
+ version: "22.3.2",
837
+ ngImport: i0,
838
+ type: NgxChartKitComponent,
839
+ decorators: [{
840
+ type: Component,
841
+ args: [{
842
+ selector: "chart-kit",
843
+ changeDetection: ChangeDetectionStrategy.OnPush,
844
+ template: `
845
+ @if (isBrowser) {
846
+ <div class="chart-kit__canvas" [style.height.px]="safeHeight()">
847
+ <canvas
848
+ #canvas
849
+ role="img"
850
+ [attr.aria-label]="accessibleName()"
851
+ [attr.aria-describedby]="description() ? descriptionId : null"
852
+ ></canvas>
853
+ </div>
854
+ }
855
+
856
+ <div class="chart-kit__data" [class.chart-kit__data--hidden]="dataTable() === 'hidden'">
857
+ @if (description()) {
858
+ <p class="chart-kit__description" [id]="descriptionId">{{ description() }}</p>
859
+ }
860
+
861
+ <table class="chart-kit__table">
862
+ <caption class="chart-kit__caption">
863
+ {{ caption() }}
864
+ </caption>
865
+ <thead>
866
+ <tr>
867
+ <th scope="col">{{ table().categoryHeader }}</th>
868
+ @for (header of table().seriesHeaders; track $index) {
869
+ <th scope="col">{{ header }}</th>
870
+ }
871
+ </tr>
872
+ </thead>
873
+ <tbody>
874
+ @for (row of table().rows; track $index) {
875
+ <tr>
876
+ <th scope="row">{{ row.label }}</th>
877
+ @for (cell of row.cells; track $index) {
878
+ <td>{{ cell.text }}</td>
879
+ }
880
+ </tr>
881
+ }
882
+ </tbody>
883
+ </table>
884
+ </div>
885
+ `,
886
+ styles: [":host{display:block;position:relative}.chart-kit__canvas{position:relative;width:100%}.chart-kit__canvas canvas{display:block}.chart-kit__data--hidden{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;white-space:nowrap;border:0;clip-path:inset(50%)}.chart-kit__description{margin:0 0 .5rem}.chart-kit__table{width:100%;border-collapse:collapse;font:inherit;text-align:left}.chart-kit__caption{padding-block:.5rem;font-weight:600;text-align:left}.chart-kit__table th,.chart-kit__table td{padding:.375rem .5rem;border-bottom:1px solid var(--chart-kit-grid, currentColor)}.chart-kit__table td{text-align:right;font-variant-numeric:tabular-nums}\n"]
887
+ }]
888
+ }],
889
+ ctorParameters: () => [],
890
+ propDecorators: {
891
+ canvasRef: [{
892
+ type: i0.ViewChild,
893
+ args: ["canvas", { isSignal: true }]
894
+ }],
895
+ data: [{
896
+ type: i0.Input,
897
+ args: [{
898
+ isSignal: true,
899
+ alias: "data",
900
+ required: true
901
+ }]
902
+ }],
903
+ caption: [{
904
+ type: i0.Input,
905
+ args: [{
906
+ isSignal: true,
907
+ alias: "caption",
908
+ required: true
909
+ }]
910
+ }],
911
+ type: [{
912
+ type: i0.Input,
913
+ args: [{
914
+ isSignal: true,
915
+ alias: "type",
916
+ required: false
917
+ }]
918
+ }],
919
+ description: [{
920
+ type: i0.Input,
921
+ args: [{
922
+ isSignal: true,
923
+ alias: "description",
924
+ required: false
925
+ }]
926
+ }],
927
+ categoryHeader: [{
928
+ type: i0.Input,
929
+ args: [{
930
+ isSignal: true,
931
+ alias: "categoryHeader",
932
+ required: false
933
+ }]
934
+ }],
935
+ dataTable: [{
936
+ type: i0.Input,
937
+ args: [{
938
+ isSignal: true,
939
+ alias: "dataTable",
940
+ required: false
941
+ }]
942
+ }],
943
+ height: [{
944
+ type: i0.Input,
945
+ args: [{
946
+ isSignal: true,
947
+ alias: "height",
948
+ required: false
949
+ }]
950
+ }],
951
+ stacked: [{
952
+ type: i0.Input,
953
+ args: [{
954
+ isSignal: true,
955
+ alias: "stacked",
956
+ required: false
957
+ }]
958
+ }],
959
+ legend: [{
960
+ type: i0.Input,
961
+ args: [{
962
+ isSignal: true,
963
+ alias: "legend",
964
+ required: false
965
+ }]
966
+ }],
967
+ tooltips: [{
968
+ type: i0.Input,
969
+ args: [{
970
+ isSignal: true,
971
+ alias: "tooltips",
972
+ required: false
973
+ }]
974
+ }],
975
+ animate: [{
976
+ type: i0.Input,
977
+ args: [{
978
+ isSignal: true,
979
+ alias: "animate",
980
+ required: false
981
+ }]
982
+ }],
983
+ beginAtZero: [{
984
+ type: i0.Input,
985
+ args: [{
986
+ isSignal: true,
987
+ alias: "beginAtZero",
988
+ required: false
989
+ }]
990
+ }],
991
+ palette: [{
992
+ type: i0.Input,
993
+ args: [{
994
+ isSignal: true,
995
+ alias: "palette",
996
+ required: false
997
+ }]
998
+ }],
999
+ locale: [{
1000
+ type: i0.Input,
1001
+ args: [{
1002
+ isSignal: true,
1003
+ alias: "locale",
1004
+ required: false
1005
+ }]
1006
+ }],
1007
+ valueFormat: [{
1008
+ type: i0.Input,
1009
+ args: [{
1010
+ isSignal: true,
1011
+ alias: "valueFormat",
1012
+ required: false
1013
+ }]
1014
+ }],
1015
+ emptyValueText: [{
1016
+ type: i0.Input,
1017
+ args: [{
1018
+ isSignal: true,
1019
+ alias: "emptyValueText",
1020
+ required: false
1021
+ }]
1022
+ }],
1023
+ pointSelect: [{
1024
+ type: i0.Output,
1025
+ args: ["pointSelect"]
1026
+ }],
1027
+ chartCreate: [{
1028
+ type: i0.Output,
1029
+ args: ["chartCreate"]
1030
+ }],
1031
+ renderError: [{
1032
+ type: i0.Output,
1033
+ args: ["renderError"]
1034
+ }]
1035
+ }
1036
+ });
1037
+ export { CHART_KIT_CSS_PROPERTIES, CHART_KIT_PALETTE, NgxChartKitComponent, buildChartKitTable, chartKitLabels, chartKitRowCount, createDefaultValueFormat, paletteColor, readChartKitTheme, toChartValue };
1038
+
1039
+ //# sourceMappingURL=angx-ngx-chart-kit.mjs.map