@mekari/pixel3-chart 0.0.1-dev.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.
package/dist/index.js ADDED
@@ -0,0 +1,868 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ MpChart: () => MpChart
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/chart.tsx
39
+ var import_vue2 = require("vue");
40
+ var import_vue3 = require("vue");
41
+ var import_pixel3_text = require("@mekari/pixel3-text");
42
+
43
+ // src/modules/chart.props.ts
44
+ var chartProps = {
45
+ id: {
46
+ type: String,
47
+ default: ""
48
+ },
49
+ title: {
50
+ type: String,
51
+ default: ""
52
+ },
53
+ type: {
54
+ type: String,
55
+ default: "bar"
56
+ },
57
+ widthChart: {
58
+ type: String,
59
+ default: "100%"
60
+ },
61
+ heightChart: {
62
+ type: String,
63
+ default: "256px"
64
+ },
65
+ widthContainer: {
66
+ type: String,
67
+ default: "100%"
68
+ },
69
+ heightContainer: {
70
+ type: String,
71
+ default: "100%"
72
+ },
73
+ data: {
74
+ type: Object,
75
+ default: () => {
76
+ return {
77
+ labels: "",
78
+ dataSets: []
79
+ };
80
+ }
81
+ },
82
+ options: {
83
+ type: Object,
84
+ default: () => {
85
+ }
86
+ },
87
+ colorPattern: {
88
+ type: String,
89
+ default: "categorical"
90
+ },
91
+ colorStart: {
92
+ type: Number,
93
+ default: 1
94
+ },
95
+ colorRatio: {
96
+ type: Number,
97
+ default: 0.2
98
+ },
99
+ legendPosition: {
100
+ type: String,
101
+ default: "bottom"
102
+ },
103
+ legendDirection: {
104
+ type: String,
105
+ default: "left"
106
+ },
107
+ tooltipMarginTop: {
108
+ type: Number,
109
+ default: 0
110
+ },
111
+ tooltipMarginLeft: {
112
+ type: Number,
113
+ default: 0
114
+ },
115
+ tooltipOptions: {
116
+ type: Object,
117
+ default: () => {
118
+ return {
119
+ offsetTop: 0,
120
+ offsetLeft: 0
121
+ };
122
+ }
123
+ },
124
+ isShowLegend: {
125
+ type: Boolean,
126
+ default: true
127
+ },
128
+ isShowTooltip: {
129
+ type: Boolean,
130
+ default: true
131
+ },
132
+ isShowDataLabels: {
133
+ type: Boolean,
134
+ default: false
135
+ },
136
+ isHorizontal: {
137
+ type: Boolean,
138
+ default: false
139
+ },
140
+ isStacked: {
141
+ type: Boolean,
142
+ default: false
143
+ },
144
+ isArea: {
145
+ type: Boolean,
146
+ default: false
147
+ },
148
+ isDebug: {
149
+ type: Boolean,
150
+ default: false
151
+ },
152
+ isShowBackgroundHover: {
153
+ type: Boolean,
154
+ default: false
155
+ },
156
+ isShowGaugePointer: {
157
+ type: Boolean,
158
+ default: false
159
+ },
160
+ isMixedChart: {
161
+ type: Boolean,
162
+ default: false
163
+ }
164
+ };
165
+
166
+ // src/modules/chart.hooks.ts
167
+ var import_vue = require("vue");
168
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
169
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
170
+ var import_tokens = require("@mekari/pixel3-styled-system/tokens");
171
+ var import_lodash_es = require("lodash-es");
172
+ var import_color = __toESM(require("color"));
173
+ var import_auto = __toESM(require("chart.js/auto"));
174
+ var import_chartjs_plugin_datalabels = __toESM(require("chartjs-plugin-datalabels"));
175
+ function useChart(props, emit) {
176
+ const {
177
+ id,
178
+ title,
179
+ type,
180
+ widthChart,
181
+ heightChart,
182
+ widthContainer,
183
+ heightContainer,
184
+ data,
185
+ options,
186
+ colorPattern,
187
+ colorStart,
188
+ colorRatio,
189
+ legendPosition,
190
+ legendDirection,
191
+ tooltipMarginTop,
192
+ tooltipMarginLeft,
193
+ isShowDataLabels,
194
+ isHorizontal,
195
+ isStacked,
196
+ isArea,
197
+ isDebug,
198
+ isShowBackgroundHover,
199
+ isShowGaugePointer,
200
+ isMixedChart,
201
+ tooltipOptions
202
+ } = (0, import_vue.toRefs)(props);
203
+ const chart = (0, import_vue.shallowRef)(null);
204
+ const tooltip = (0, import_vue.ref)({
205
+ top: 0,
206
+ left: 0,
207
+ opacity: 0,
208
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
209
+ data: null
210
+ });
211
+ const legend = (0, import_vue.ref)([]);
212
+ const baseColor = (0, import_vue.ref)();
213
+ const chartContainerNode = (0, import_vue.ref)();
214
+ const chartLegendNode = (0, import_vue.ref)();
215
+ const chartCanvasNode = (0, import_vue.ref)();
216
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "chart").value;
217
+ const isHorizontalBarChart = (0, import_vue.computed)(() => {
218
+ return type.value === "bar" && isHorizontal.value;
219
+ });
220
+ const isCircularChart = (0, import_vue.computed)(() => {
221
+ return type.value === "pie" || type.value === "doughnut";
222
+ });
223
+ const getLegendPosition = (0, import_vue.computed)(() => {
224
+ let position = "column";
225
+ if (legendPosition.value === "right") {
226
+ position = "row";
227
+ }
228
+ if (legendPosition.value === "top") {
229
+ position = "column-reverse";
230
+ }
231
+ if (legendPosition.value === "left") {
232
+ position = "row-reverse";
233
+ }
234
+ return position;
235
+ });
236
+ const getLegendDirection = (0, import_vue.computed)(() => {
237
+ let direction = "flex-start";
238
+ if (legendDirection.value === "center") {
239
+ direction = "center";
240
+ }
241
+ if (legendDirection.value === "right") {
242
+ direction = "flex-end";
243
+ }
244
+ return direction;
245
+ });
246
+ const getOptions = (0, import_vue.computed)(() => {
247
+ const basicOptions = {
248
+ maintainAspectRatio: false,
249
+ responsive: true,
250
+ animation: true,
251
+ cutout: type.value === "doughnut" ? 70 : 0,
252
+ ...isHorizontalBarChart.value && {
253
+ indexAxis: "y"
254
+ },
255
+ interaction: {
256
+ intersect: !isArea.value
257
+ },
258
+ plugins: {
259
+ PluginHtmlLegend: true,
260
+ PluginHoverBackgroundColors: isShowBackgroundHover.value,
261
+ gaugeChartPointer: isShowGaugePointer.value,
262
+ title: {
263
+ display: false
264
+ },
265
+ legend: {
266
+ display: false
267
+ },
268
+ tooltip: {
269
+ enabled: false,
270
+ position: "average",
271
+ external: handleExternalTooltip
272
+ },
273
+ filler: {
274
+ propagate: false
275
+ },
276
+ datalabels: {
277
+ display: isShowDataLabels.value,
278
+ color: "#626B79",
279
+ clamp: true,
280
+ font: {
281
+ size: 10
282
+ },
283
+ labels: {
284
+ value: {
285
+ anchor: "end",
286
+ align: "end"
287
+ }
288
+ }
289
+ }
290
+ },
291
+ elements: {
292
+ bar: {
293
+ backgroundColor: getListColors.value[1],
294
+ borderRadius: "4",
295
+ ...isStacked.value && {
296
+ borderWidth: {
297
+ top: !isHorizontal.value ? 2 : 0,
298
+ right: isHorizontal.value ? 2 : 0
299
+ },
300
+ borderColor: "#FFFFFF"
301
+ }
302
+ },
303
+ line: {
304
+ borderColor: isArea.value ? "#FFFFFF" : getListColors.value[1],
305
+ borderWidth: 2,
306
+ tension: isArea.value ? 0.4 : 0
307
+ },
308
+ point: {
309
+ radius: isArea.value || type.value === "radar" ? 0 : 6,
310
+ borderWidth: 2,
311
+ hoverRadius: isArea.value || type.value === "radar" ? 0 : 6,
312
+ hoverBorderWidth: 2
313
+ },
314
+ arc: {
315
+ backgroundColor: getListColors.value[1],
316
+ borderColor: "#FFFFFF",
317
+ hoverBorderColor: "#FFFFFF"
318
+ }
319
+ },
320
+ scales: {
321
+ x: {
322
+ stacked: isStacked.value,
323
+ border: {
324
+ display: false
325
+ },
326
+ grid: {
327
+ display: false,
328
+ drawOnChartArea: false,
329
+ drawTicks: false
330
+ },
331
+ ticks: {
332
+ display: !isCircularChart.value && type.value !== "radar",
333
+ color: "#626B79"
334
+ }
335
+ },
336
+ y: {
337
+ stacked: isStacked.value,
338
+ border: {
339
+ display: false
340
+ },
341
+ grid: {
342
+ display: !isHorizontal.value,
343
+ drawOnChartArea: !isCircularChart.value && type.value !== "radar",
344
+ drawTicks: false,
345
+ color: "#D0D6DD"
346
+ },
347
+ ticks: {
348
+ display: !isCircularChart.value && type.value !== "radar",
349
+ beginAtZero: true,
350
+ color: "#626B79",
351
+ padding: 8
352
+ }
353
+ },
354
+ ...type.value === "radar" && {
355
+ r: {
356
+ angleLines: {
357
+ display: true,
358
+ color: "#D0D6DD"
359
+ },
360
+ grid: {
361
+ color: "#D0D6DD"
362
+ },
363
+ ticks: {
364
+ color: "#626B79"
365
+ },
366
+ pointLabels: {
367
+ color: "#626B79"
368
+ }
369
+ }
370
+ }
371
+ }
372
+ };
373
+ return (0, import_lodash_es.merge)(basicOptions, options.value);
374
+ });
375
+ const getDataset = (0, import_vue.computed)(() => {
376
+ const datasets = data.value.datasets || [];
377
+ if (type.value === "bar") {
378
+ datasets.forEach((item, index) => {
379
+ item.backgroundColor = item.backgroundColor || handleColorPattern(index);
380
+ item.barPercentage = item.barPercentage || 0.68;
381
+ item.categoryPercentage = item.categoryPercentage || 1;
382
+ });
383
+ }
384
+ if (isCircularChart.value) {
385
+ const backgroundColor = [];
386
+ datasets.forEach((item) => {
387
+ item.data.forEach((_, index) => {
388
+ return backgroundColor.push(handleColorPattern(index));
389
+ });
390
+ item.backgroundColor = item.backgroundColor || backgroundColor;
391
+ });
392
+ }
393
+ if (isArea.value && (type.value === "line" || isMixedChart.value)) {
394
+ datasets.forEach((item, index) => {
395
+ item.fill = "start";
396
+ item.backgroundColor = item.backgroundColor || handleColorPattern(index);
397
+ });
398
+ }
399
+ if (!isArea.value && (type.value === "line" || type.value === "radar" || isMixedChart.value)) {
400
+ const isFading = type.value === "radar";
401
+ datasets.forEach((item, index) => {
402
+ item.backgroundColor = item.backgroundColor || handleColorPattern(index, isFading);
403
+ item.borderColor = item.borderColor || handleColorPattern(index);
404
+ item.pointBackgroundColor = item.pointBackgroundColor || "#FFFFFF";
405
+ });
406
+ }
407
+ return datasets;
408
+ });
409
+ const getListColors = (0, import_vue.computed)(() => {
410
+ return {
411
+ 1: (0, import_tokens.token)("colors.sky.400"),
412
+ 2: (0, import_tokens.token)("colors.sky.100"),
413
+ 3: (0, import_tokens.token)("colors.teal.400"),
414
+ 4: (0, import_tokens.token)("colors.teal.100"),
415
+ 5: (0, import_tokens.token)("colors.violet.400"),
416
+ 6: (0, import_tokens.token)("colors.violet.100"),
417
+ 7: (0, import_tokens.token)("colors.amber.400"),
418
+ 8: (0, import_tokens.token)("colors.amber.100"),
419
+ 9: (0, import_tokens.token)("colors.rose.400"),
420
+ 10: (0, import_tokens.token)("colors.rose.100"),
421
+ 11: (0, import_tokens.token)("colors.stone.400"),
422
+ 12: (0, import_tokens.token)("colors.stone.100"),
423
+ 13: (0, import_tokens.token)("colors.lime.400"),
424
+ 14: (0, import_tokens.token)("colors.lime.100"),
425
+ 15: (0, import_tokens.token)("colors.pink.400"),
426
+ 16: (0, import_tokens.token)("colors.pink.100"),
427
+ 17: (0, import_tokens.token)("colors.apricot.400"),
428
+ 18: (0, import_tokens.token)("colors.apricot.100"),
429
+ 19: (0, import_tokens.token)("colors.aqua.400"),
430
+ 20: (0, import_tokens.token)("colors.aqua.100"),
431
+ 21: (0, import_tokens.token)("colors.leaf.400"),
432
+ 22: (0, import_tokens.token)("colors.leaf.100"),
433
+ 23: (0, import_tokens.token)("colors.fuchsia.400"),
434
+ 24: (0, import_tokens.token)("colors.fuchsia.100")
435
+ };
436
+ });
437
+ const rootAttrs = (0, import_vue.computed)(() => {
438
+ return {
439
+ "data-pixel-component": "MpChart",
440
+ id: getId,
441
+ class: (0, import_recipes.chartSlotRecipe)().root,
442
+ style: {
443
+ width: widthContainer.value
444
+ }
445
+ };
446
+ });
447
+ const chartHeaderAttrs = (0, import_vue.computed)(() => {
448
+ return {
449
+ class: (0, import_recipes.chartSlotRecipe)().chartHeader
450
+ };
451
+ });
452
+ const chartWrapperAttrs = (0, import_vue.computed)(() => {
453
+ return {
454
+ class: (0, import_recipes.chartSlotRecipe)().chartWrapper,
455
+ style: {
456
+ flexDirection: getLegendPosition.value
457
+ }
458
+ };
459
+ });
460
+ const chartContainerAttrs = (0, import_vue.computed)(() => {
461
+ return {
462
+ ref: chartContainerNode,
463
+ id: `chart-container--${getId}`,
464
+ class: (0, import_recipes.chartSlotRecipe)().chartContainer,
465
+ style: {
466
+ width: widthContainer.value,
467
+ height: heightContainer.value
468
+ }
469
+ };
470
+ });
471
+ const canvasContainerAttrs = (0, import_vue.computed)(() => {
472
+ return {
473
+ id: `canvas-container--${getId}`,
474
+ class: (0, import_recipes.chartSlotRecipe)().canvasContainer,
475
+ style: {
476
+ width: widthChart.value,
477
+ height: heightChart.value
478
+ }
479
+ };
480
+ });
481
+ const canvasAttrs = (0, import_vue.computed)(() => {
482
+ return {
483
+ ref: chartCanvasNode,
484
+ id: `canvas-${getId}`,
485
+ ariaLabel: `Piel Chart ${title.value}`,
486
+ role: "img"
487
+ };
488
+ });
489
+ const chartLegendAttrs = (0, import_vue.computed)(() => {
490
+ return {
491
+ ref: chartLegendNode,
492
+ id: `chart-legend--${getId}`,
493
+ class: (0, import_recipes.chartSlotRecipe)().chartLegend,
494
+ style: {
495
+ justifyContent: getLegendDirection.value,
496
+ marginTop: legendPosition.value === "bottom" ? (0, import_tokens.token)("spacing.4") : "0",
497
+ marginBottom: legendPosition.value === "top" ? (0, import_tokens.token)("spacing.4") : "0"
498
+ }
499
+ };
500
+ });
501
+ const legendWrapperAttrs = /* @__PURE__ */ __name((item, index) => {
502
+ return {
503
+ key: index,
504
+ class: (0, import_recipes.chartSlotRecipe)().legendWrapper,
505
+ onClick: () => handleClickLegend(item)
506
+ };
507
+ }, "legendWrapperAttrs");
508
+ const legendBoxAttrs = /* @__PURE__ */ __name((item) => {
509
+ return {
510
+ class: (0, import_recipes.chartSlotRecipe)().legendBox,
511
+ style: {
512
+ width: (0, import_tokens.token)("sizes.3"),
513
+ height: (0, import_tokens.token)("sizes.3"),
514
+ background: item.fillStyle
515
+ }
516
+ };
517
+ }, "legendBoxAttrs");
518
+ const chartTooltipAttrs = (0, import_vue.computed)(() => {
519
+ return {
520
+ class: (0, import_recipes.chartSlotRecipe)().chartTooltip,
521
+ style: {
522
+ top: `${tooltip.value.top}px`,
523
+ left: `${tooltip.value.left}px`,
524
+ opacity: tooltip.value.opacity
525
+ }
526
+ };
527
+ });
528
+ const tooltipWrapperAttrs = (0, import_vue.computed)(() => {
529
+ return {
530
+ class: (0, import_recipes.chartSlotRecipe)().tooltipWrapper
531
+ };
532
+ });
533
+ const tooltipRowAttrs = (0, import_vue.computed)(() => {
534
+ return {
535
+ class: (0, import_recipes.chartSlotRecipe)().tooltipRow
536
+ };
537
+ });
538
+ const tooltipItemAttrs = (0, import_vue.computed)(() => {
539
+ return {
540
+ class: (0, import_recipes.chartSlotRecipe)().tooltipItem
541
+ };
542
+ });
543
+ const tooltipBoxAttrs = (0, import_vue.computed)(() => {
544
+ var _a, _b, _c, _d;
545
+ return {
546
+ class: (0, import_recipes.chartSlotRecipe)().tooltipBox,
547
+ style: {
548
+ backgroundColor: type.value === "line" ? (_b = (_a = tooltip.value.data) == null ? void 0 : _a.labelColors[0]) == null ? void 0 : _b.borderColor : (_d = (_c = tooltip.value.data) == null ? void 0 : _c.labelColors[0]) == null ? void 0 : _d.backgroundColor
549
+ }
550
+ };
551
+ });
552
+ function createChart() {
553
+ if (!chartCanvasNode.value)
554
+ return;
555
+ chart.value = new import_auto.default(chartCanvasNode.value, {
556
+ type: type.value,
557
+ data: {
558
+ labels: typeof data.value.labels === "undefined" ? [] : [...data.value.labels],
559
+ datasets: getDataset.value
560
+ },
561
+ options: getOptions.value,
562
+ plugins: [import_chartjs_plugin_datalabels.default, handleExternalLegend(), hoverBackgroundColors(), gaugeChartPointer()]
563
+ });
564
+ if (isDebug.value) {
565
+ console.log(`[MpChart] The context chart of ${getId} is:`, chart.value);
566
+ }
567
+ }
568
+ __name(createChart, "createChart");
569
+ function destroyChart() {
570
+ var _a;
571
+ (_a = chart.value) == null ? void 0 : _a.destroy();
572
+ }
573
+ __name(destroyChart, "destroyChart");
574
+ function updateChart() {
575
+ destroyChart();
576
+ createChart();
577
+ }
578
+ __name(updateChart, "updateChart");
579
+ function handleExternalTooltip(context) {
580
+ const {
581
+ tooltip: tooltipCtx
582
+ } = context;
583
+ const legendHeight = chartLegendNode.value ? chartLegendNode.value.clientHeight + 16 : tooltipMarginTop.value;
584
+ const extendTopValue = legendPosition.value === "top" ? legendHeight.value : 0;
585
+ const legendWidth = chartLegendNode.value ? chartLegendNode.value.clientWidth : tooltipMarginLeft.value;
586
+ const extendLeftValue = legendPosition.value === "left" ? legendWidth.value : 0;
587
+ const tooltipLeftPosition = tooltipCtx.x - chartContainerNode.value.scrollLeft;
588
+ const tooltipTopPosition = tooltipCtx.y > chartContainerNode.value.scrollTop ? tooltipCtx.caretY - chartContainerNode.value.scrollTop : tooltipCtx.caretY;
589
+ if (tooltipCtx.opacity === 1) {
590
+ tooltip.value = {
591
+ opacity: tooltipCtx.opacity,
592
+ left: tooltipLeftPosition + extendLeftValue + tooltipOptions.value.offsetLeft,
593
+ top: tooltipTopPosition + extendTopValue + tooltipOptions.value.offsetTop,
594
+ data: tooltipCtx
595
+ };
596
+ emit("show-tooltip", context);
597
+ } else {
598
+ tooltip.value.opacity = 0;
599
+ emit("hide-tooltip", context);
600
+ }
601
+ if (isDebug.value) {
602
+ console.log(`[MpChart] The context tooltip of ${getId} is:`, tooltip.value);
603
+ }
604
+ }
605
+ __name(handleExternalTooltip, "handleExternalTooltip");
606
+ function gaugeChartPointer() {
607
+ return {
608
+ id: "gaugeChartPointer",
609
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
610
+ afterDatasetsDraw(chart2, args, options2) {
611
+ const {
612
+ ctx,
613
+ data: data2
614
+ } = chart2;
615
+ const pointerIndexStart = options2.pointerIndexStart || 1;
616
+ const xCenter = chart2.getDatasetMeta(0).data[pointerIndexStart].x;
617
+ const yCenter = chart2.getDatasetMeta(0).data[pointerIndexStart].y;
618
+ const innerRadius = chart2.getDatasetMeta(0).data[pointerIndexStart].innerRadius;
619
+ const outerRadius = chart2.getDatasetMeta(0).data[pointerIndexStart].outerRadius;
620
+ const circumference = chart2.getDatasetMeta(0).data[pointerIndexStart].circumference;
621
+ const halfCircle = circumference / Math.PI / data2.datasets[0].data[pointerIndexStart];
622
+ const pointerRadius = outerRadius - innerRadius - 10;
623
+ const pointerColor = options2.pointerColor || "black";
624
+ const pointerValue = options2.pointerValue || 1;
625
+ const pointerRatio = options2.pointerRatio || 1.47;
626
+ const pointerPosition = halfCircle * pointerValue;
627
+ const pointerAngle = Math.PI * (pointerPosition + pointerRatio);
628
+ ctx.save();
629
+ ctx.translate(xCenter, yCenter);
630
+ ctx.rotate(pointerAngle);
631
+ ctx.beginPath();
632
+ ctx.strokeStyle = "white";
633
+ ctx.fillStyle = pointerColor;
634
+ ctx.lineWidth = 8;
635
+ ctx.shadowColor = "rgba(0, 0, 0, 0.08)";
636
+ ctx.shadowBlur = 8;
637
+ ctx.shadowOffsetX = 6;
638
+ ctx.shadowOffsetY = 6;
639
+ ctx.beginPath();
640
+ ctx.roundRect(0, -outerRadius + 6, pointerRadius, pointerRadius, 100);
641
+ ctx.fill();
642
+ ctx.stroke();
643
+ ctx.restore();
644
+ }
645
+ };
646
+ }
647
+ __name(gaugeChartPointer, "gaugeChartPointer");
648
+ function hoverBackgroundColors() {
649
+ return {
650
+ id: "PluginHoverBackgroundColors",
651
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
652
+ beforeDatasetsDraw(chart2) {
653
+ const {
654
+ ctx,
655
+ tooltip: tooltip2,
656
+ chartArea: {
657
+ top,
658
+ height
659
+ },
660
+ scales: {
661
+ x
662
+ }
663
+ } = chart2;
664
+ if (tooltip2._active[0]) {
665
+ const index = tooltip2._active[0].index;
666
+ const leftStart = x._gridLineItems[index + 1] ? x._gridLineItems[index + 1].x1 : 0;
667
+ const newWidth = x._gridLineItems[0].x1 - x._gridLineItems[1].x1;
668
+ ctx.fillStyle = "rgba(236, 240, 242, 0.6)";
669
+ ctx.fillRect(leftStart, top, newWidth, height);
670
+ }
671
+ }
672
+ };
673
+ }
674
+ __name(hoverBackgroundColors, "hoverBackgroundColors");
675
+ function handleExternalLegend() {
676
+ return {
677
+ id: "PluginHtmlLegend",
678
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
679
+ afterUpdate(chart2) {
680
+ var _a, _b, _c, _d;
681
+ const items = (_d = (_c = (_b = (_a = chart2 == null ? void 0 : chart2.options) == null ? void 0 : _a.plugins) == null ? void 0 : _b.legend) == null ? void 0 : _c.labels) == null ? void 0 : _d.generateLabels(chart2);
682
+ items.forEach((item) => {
683
+ item.chart = chart2;
684
+ item.click = () => {
685
+ if (isCircularChart.value) {
686
+ chart2.toggleDataVisibility(item.index);
687
+ } else {
688
+ chart2.setDatasetVisibility(item.datasetIndex, !chart2.isDatasetVisible(item.datasetIndex));
689
+ }
690
+ chart2.update();
691
+ };
692
+ });
693
+ legend.value = items;
694
+ if (isDebug.value) {
695
+ console.log(`[MpChart] The context legend of ${getId} is:`, legend.value);
696
+ }
697
+ }
698
+ };
699
+ }
700
+ __name(handleExternalLegend, "handleExternalLegend");
701
+ function handleColorPattern(idx, isFading) {
702
+ let color = "";
703
+ const startIndex = colorStart.value - 1;
704
+ const indexColors = Object.keys(getListColors.value);
705
+ const odds = indexColors.filter((number) => {
706
+ return Number(number) % 2 !== 0;
707
+ });
708
+ if (colorPattern.value === "") {
709
+ color = getListColors.value[Number(indexColors[startIndex + idx])];
710
+ }
711
+ if (colorPattern.value === "categorical") {
712
+ const oddsLength = odds.length - startIndex;
713
+ if (idx < oddsLength) {
714
+ color = getListColors.value[Number(odds[startIndex + idx])];
715
+ } else {
716
+ const multiplier = Math.floor(idx / oddsLength);
717
+ const darkenRatio = (colorRatio.value * multiplier).toFixed(1);
718
+ baseColor.value = getListColors.value[Number(odds[startIndex + idx - oddsLength * multiplier])];
719
+ color = (0, import_color.default)(baseColor.value).darken(Number(darkenRatio)).hex();
720
+ }
721
+ }
722
+ if (colorPattern.value === "comparison") {
723
+ color = getListColors.value[Number(indexColors[startIndex + idx])];
724
+ }
725
+ if (colorPattern.value === "dark-shades" || colorPattern.value === "light-shades") {
726
+ if (idx === 0) {
727
+ color = getListColors.value[Number(indexColors[startIndex])];
728
+ } else {
729
+ if (colorPattern.value === "dark-shades") {
730
+ color = (0, import_color.default)(baseColor.value).darken(colorRatio.value).hex();
731
+ }
732
+ if (colorPattern.value === "light-shades") {
733
+ color = (0, import_color.default)(baseColor.value).lighten(colorRatio.value).hex();
734
+ }
735
+ }
736
+ baseColor.value = color;
737
+ }
738
+ color = isFading ? (0, import_color.default)(color).fade(0.5).string() : color;
739
+ return color;
740
+ }
741
+ __name(handleColorPattern, "handleColorPattern");
742
+ function handleClickLegend(item) {
743
+ item.click();
744
+ emit("click-legend", item);
745
+ }
746
+ __name(handleClickLegend, "handleClickLegend");
747
+ (0, import_vue.watch)([() => data.value, () => options.value, () => type.value], ([newData, newOptions, newType]) => {
748
+ if (newData || newOptions || newType) {
749
+ updateChart();
750
+ }
751
+ }, {
752
+ deep: true
753
+ });
754
+ (0, import_vue.onMounted)(() => {
755
+ createChart();
756
+ chartContainerNode.value.scrollTo(0, chartContainerNode.value.scrollHeight);
757
+ });
758
+ (0, import_vue.onUnmounted)(() => {
759
+ destroyChart();
760
+ });
761
+ return {
762
+ rootAttrs,
763
+ chartHeaderAttrs,
764
+ chartWrapperAttrs,
765
+ chartContainerAttrs,
766
+ canvasContainerAttrs,
767
+ canvasAttrs,
768
+ chartLegendAttrs,
769
+ legendWrapperAttrs,
770
+ legendBoxAttrs,
771
+ chartTooltipAttrs,
772
+ tooltipWrapperAttrs,
773
+ tooltipRowAttrs,
774
+ tooltipItemAttrs,
775
+ tooltipBoxAttrs,
776
+ chart,
777
+ legend,
778
+ tooltip
779
+ };
780
+ }
781
+ __name(useChart, "useChart");
782
+
783
+ // src/chart.tsx
784
+ var import_lodash_es2 = require("lodash-es");
785
+ function _isSlot(s) {
786
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, import_vue2.isVNode)(s);
787
+ }
788
+ __name(_isSlot, "_isSlot");
789
+ var MpChart = (0, import_vue3.defineComponent)({
790
+ name: "MpChart",
791
+ props: chartProps,
792
+ emits: ["show-tooltip", "hide-tooltip", "click-legend"],
793
+ setup(props, {
794
+ slots,
795
+ emit
796
+ }) {
797
+ const {
798
+ rootAttrs,
799
+ chartHeaderAttrs,
800
+ chartWrapperAttrs,
801
+ chartContainerAttrs,
802
+ canvasContainerAttrs,
803
+ canvasAttrs,
804
+ chartLegendAttrs,
805
+ legendWrapperAttrs,
806
+ legendBoxAttrs,
807
+ chartTooltipAttrs,
808
+ tooltipWrapperAttrs,
809
+ tooltipRowAttrs,
810
+ tooltipItemAttrs,
811
+ tooltipBoxAttrs,
812
+ chart,
813
+ legend,
814
+ tooltip
815
+ } = useChart(props, emit);
816
+ return () => {
817
+ const children = slots.default && slots.default();
818
+ const {
819
+ title,
820
+ isShowLegend,
821
+ isShowTooltip
822
+ } = props;
823
+ return (0, import_vue2.createVNode)("div", rootAttrs.value, [(title || slots.action) && (0, import_vue2.createVNode)("div", chartHeaderAttrs.value, [(0, import_vue2.createVNode)(import_pixel3_text.MpText, {
824
+ "size": "h2",
825
+ "weight": "semiBold"
826
+ }, _isSlot(title) ? title : {
827
+ default: () => [title]
828
+ }), slots.action && slots.action(chart.value)]), (0, import_vue2.createVNode)("div", chartWrapperAttrs.value, [(0, import_vue2.createVNode)("div", chartContainerAttrs.value, [(0, import_vue2.createVNode)("div", canvasContainerAttrs.value, [(0, import_vue2.createVNode)("canvas", canvasAttrs.value, null)]), children]), isShowLegend ? slots.legend ? slots.legend((0, import_lodash_es2.merge)(legend.value)) : (0, import_vue2.createVNode)("div", chartLegendAttrs.value, [
829
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
830
+ legend.value.map((item, index) => {
831
+ return (0, import_vue2.createVNode)("div", legendWrapperAttrs(item, index), [(0, import_vue2.createVNode)("div", legendBoxAttrs(item), null), (0, import_vue2.createVNode)(import_pixel3_text.MpText, {
832
+ "is-strike": item.hidden
833
+ }, {
834
+ default: () => [item.text]
835
+ })]);
836
+ })
837
+ ]) : "", isShowTooltip && (0, import_vue2.createVNode)("div", chartTooltipAttrs.value, [slots.tooltip ? slots.tooltip(tooltip.value.data) : (0, import_vue2.createVNode)("div", tooltipWrapperAttrs.value, [(0, import_vue2.createVNode)(import_pixel3_text.MpText, {
838
+ "size": "label",
839
+ "color": "gray.600"
840
+ }, {
841
+ default: () => {
842
+ var _a, _b;
843
+ return [(_b = (_a = tooltip.value.data) == null ? void 0 : _a.dataPoints[0]) == null ? void 0 : _b.label];
844
+ }
845
+ }), (0, import_vue2.createVNode)("div", tooltipRowAttrs.value, [(0, import_vue2.createVNode)("div", tooltipItemAttrs.value, [(0, import_vue2.createVNode)("div", tooltipBoxAttrs.value, null), (0, import_vue2.createVNode)(import_pixel3_text.MpText, {
846
+ "size": "label-small",
847
+ "weight": "semiBold"
848
+ }, {
849
+ default: () => {
850
+ var _a, _b;
851
+ return [(_b = (_a = tooltip.value.data) == null ? void 0 : _a.dataPoints[0]) == null ? void 0 : _b.dataset.label];
852
+ }
853
+ })]), (0, import_vue2.createVNode)(import_pixel3_text.MpText, {
854
+ "size": "label-small",
855
+ "color": "gray.600"
856
+ }, {
857
+ default: () => {
858
+ var _a, _b;
859
+ return [(_b = (_a = tooltip.value.data) == null ? void 0 : _a.dataPoints[0]) == null ? void 0 : _b.formattedValue];
860
+ }
861
+ })])])])])]);
862
+ };
863
+ }
864
+ });
865
+ // Annotate the CommonJS export names for ESM import in node:
866
+ 0 && (module.exports = {
867
+ MpChart
868
+ });