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