@mantine-vue/charts 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/cjs/index.cjs +822 -0
  2. package/cjs/index.cjs.map +1 -0
  3. package/esm/index.mjs +780 -0
  4. package/esm/index.mjs.map +1 -0
  5. package/lib/AreaChart/AreaChart.d.ts +2 -0
  6. package/lib/AreaChart/index.d.ts +1 -0
  7. package/lib/BarChart/BarChart.d.ts +2 -0
  8. package/lib/BarChart/index.d.ts +1 -0
  9. package/lib/BarsList/BarsList.d.ts +2 -0
  10. package/lib/BarsList/index.d.ts +1 -0
  11. package/lib/BubbleChart/BubbleChart.d.ts +2 -0
  12. package/lib/BubbleChart/index.d.ts +1 -0
  13. package/lib/ChartLegend/ChartLegend.d.ts +54 -0
  14. package/lib/ChartLegend/index.d.ts +2 -0
  15. package/lib/ChartTooltip/ChartTooltip.d.ts +48 -0
  16. package/lib/ChartTooltip/index.d.ts +2 -0
  17. package/lib/CompositeChart/CompositeChart.d.ts +2 -0
  18. package/lib/CompositeChart/index.d.ts +1 -0
  19. package/lib/DonutChart/DonutChart.d.ts +2 -0
  20. package/lib/DonutChart/index.d.ts +1 -0
  21. package/lib/FunnelChart/FunnelChart.d.ts +2 -0
  22. package/lib/FunnelChart/index.d.ts +1 -0
  23. package/lib/Heatmap/Heatmap.d.ts +2 -0
  24. package/lib/Heatmap/index.d.ts +1 -0
  25. package/lib/LineChart/LineChart.d.ts +2 -0
  26. package/lib/LineChart/index.d.ts +1 -0
  27. package/lib/PieChart/PieChart.d.ts +2 -0
  28. package/lib/PieChart/index.d.ts +1 -0
  29. package/lib/RadarChart/RadarChart.d.ts +2 -0
  30. package/lib/RadarChart/index.d.ts +1 -0
  31. package/lib/RadialBarChart/RadialBarChart.d.ts +2 -0
  32. package/lib/RadialBarChart/index.d.ts +1 -0
  33. package/lib/SankeyChart/SankeyChart.d.ts +2 -0
  34. package/lib/SankeyChart/index.d.ts +1 -0
  35. package/lib/ScatterChart/ScatterChart.d.ts +2 -0
  36. package/lib/ScatterChart/index.d.ts +1 -0
  37. package/lib/Sparkline/Sparkline.d.ts +2 -0
  38. package/lib/Sparkline/index.d.ts +1 -0
  39. package/lib/Treemap/Treemap.d.ts +2 -0
  40. package/lib/Treemap/index.d.ts +1 -0
  41. package/lib/charts.d.ts +319 -0
  42. package/lib/index.d.mts +6 -0
  43. package/lib/index.d.ts +6 -0
  44. package/lib/internal/colors.d.ts +1 -0
  45. package/lib/internal/component.d.ts +4 -0
  46. package/lib/internal/echarts.d.ts +1 -0
  47. package/lib/internal/options.d.ts +11 -0
  48. package/lib/types.d.ts +79 -0
  49. package/lib/utils/get-series-labels/get-series-labels.d.ts +2 -0
  50. package/lib/utils/index.d.ts +1 -0
  51. package/package.json +46 -0
  52. package/styles.css +12 -0
  53. package/styles.layer.css +14 -0
package/esm/index.mjs ADDED
@@ -0,0 +1,780 @@
1
+ import { computed, defineComponent, h, ref } from "vue";
2
+ import VChart from "vue-echarts";
3
+ import { use } from "echarts/core";
4
+ import { BarChart as BarChart$1, EffectScatterChart, FunnelChart as FunnelChart$1, GaugeChart, GraphChart, HeatmapChart, LineChart as LineChart$1, PieChart as PieChart$1, RadarChart as RadarChart$1, SankeyChart as SankeyChart$1, ScatterChart as ScatterChart$1, TreemapChart } from "echarts/charts";
5
+ import { AriaComponent, CalendarComponent, DataZoomComponent, DatasetComponent, GraphicComponent, GridComponent, LegendComponent, MarkLineComponent, PolarComponent, RadarComponent, TitleComponent, ToolboxComponent, TooltipComponent, TransformComponent, VisualMapComponent } from "echarts/components";
6
+ import { CanvasRenderer, SVGRenderer } from "echarts/renderers";
7
+ //#region src/internal/echarts.ts
8
+ var registered = false;
9
+ function registerECharts() {
10
+ if (registered) return;
11
+ use([
12
+ BarChart$1,
13
+ EffectScatterChart,
14
+ FunnelChart$1,
15
+ GaugeChart,
16
+ GraphChart,
17
+ HeatmapChart,
18
+ LineChart$1,
19
+ PieChart$1,
20
+ RadarChart$1,
21
+ SankeyChart$1,
22
+ ScatterChart$1,
23
+ TreemapChart,
24
+ AriaComponent,
25
+ CalendarComponent,
26
+ DatasetComponent,
27
+ DataZoomComponent,
28
+ GraphicComponent,
29
+ GridComponent,
30
+ LegendComponent,
31
+ MarkLineComponent,
32
+ PolarComponent,
33
+ RadarComponent,
34
+ TitleComponent,
35
+ ToolboxComponent,
36
+ TooltipComponent,
37
+ TransformComponent,
38
+ VisualMapComponent,
39
+ CanvasRenderer,
40
+ SVGRenderer
41
+ ]);
42
+ registered = true;
43
+ }
44
+ //#endregion
45
+ //#region src/internal/component.ts
46
+ registerECharts();
47
+ function createChartComponent(name, buildOption) {
48
+ return defineComponent({
49
+ name: `Mantine${name}`,
50
+ inheritAttrs: false,
51
+ props: {
52
+ option: Object,
53
+ height: {
54
+ type: [Number, String],
55
+ default: 300
56
+ },
57
+ width: {
58
+ type: [Number, String],
59
+ default: "100%"
60
+ },
61
+ loading: Boolean,
62
+ autoresize: {
63
+ type: Boolean,
64
+ default: true
65
+ },
66
+ renderer: {
67
+ type: String,
68
+ default: "canvas"
69
+ },
70
+ initOptions: Object
71
+ },
72
+ emits: [
73
+ "click",
74
+ "dblclick",
75
+ "mouseover",
76
+ "mouseout",
77
+ "legendselectchanged",
78
+ "datazoom"
79
+ ],
80
+ setup(props, { attrs, emit, expose }) {
81
+ const chart = ref();
82
+ const option = computed(() => ({
83
+ ...buildOption(attrs),
84
+ ...props.option
85
+ }));
86
+ expose({
87
+ getEchartsInstance: () => chart.value?.chart,
88
+ resize: () => chart.value?.resize(),
89
+ setOption: (next) => chart.value?.setOption(next)
90
+ });
91
+ const size = (value) => typeof value === "number" ? `${value}px` : value;
92
+ const rootAttributes = computed(() => Object.fromEntries(Object.entries(attrs).filter(([key]) => [
93
+ "id",
94
+ "dir",
95
+ "role",
96
+ "tabindex",
97
+ "title"
98
+ ].includes(key) || key.startsWith("aria-") || key.startsWith("data-") && key !== "data")));
99
+ return () => h("div", {
100
+ ...rootAttributes.value,
101
+ class: [
102
+ "mantine-Chart-root",
103
+ `mantine-${name}-root`,
104
+ attrs.class
105
+ ],
106
+ style: [{
107
+ width: size(props.width),
108
+ height: size(props.height)
109
+ }, attrs.style]
110
+ }, [h(VChart, {
111
+ ref: chart,
112
+ option: option.value,
113
+ autoresize: props.autoresize,
114
+ loading: props.loading,
115
+ initOptions: {
116
+ ...props.initOptions,
117
+ renderer: props.renderer
118
+ },
119
+ class: "mantine-Chart-container",
120
+ onClick: (event) => emit("click", event),
121
+ onDblclick: (event) => emit("dblclick", event),
122
+ onMouseover: (event) => emit("mouseover", event),
123
+ onMouseout: (event) => emit("mouseout", event),
124
+ onLegendselectchanged: (event) => emit("legendselectchanged", event),
125
+ onDatazoom: (event) => emit("datazoom", event)
126
+ })]);
127
+ }
128
+ });
129
+ }
130
+ //#endregion
131
+ //#region src/internal/colors.ts
132
+ var shadeMap = {
133
+ blue: [
134
+ "#e7f5ff",
135
+ "#d0ebff",
136
+ "#a5d8ff",
137
+ "#74c0fc",
138
+ "#4dabf7",
139
+ "#339af0",
140
+ "#228be6",
141
+ "#1c7ed6",
142
+ "#1971c2",
143
+ "#1864ab"
144
+ ],
145
+ cyan: [
146
+ "#e3fafc",
147
+ "#c5f6fa",
148
+ "#99e9f2",
149
+ "#66d9e8",
150
+ "#3bc9db",
151
+ "#22b8cf",
152
+ "#15aabf",
153
+ "#1098ad",
154
+ "#0c8599",
155
+ "#0b7285"
156
+ ],
157
+ green: [
158
+ "#ebfbee",
159
+ "#d3f9d8",
160
+ "#b2f2bb",
161
+ "#8ce99a",
162
+ "#69db7c",
163
+ "#51cf66",
164
+ "#40c057",
165
+ "#37b24d",
166
+ "#2f9e44",
167
+ "#2b8a3e"
168
+ ],
169
+ grape: [
170
+ "#f8f0fc",
171
+ "#f3d9fa",
172
+ "#eebefa",
173
+ "#e599f7",
174
+ "#da77f2",
175
+ "#cc5de8",
176
+ "#be4bdb",
177
+ "#ae3ec9",
178
+ "#9c36b5",
179
+ "#862e9c"
180
+ ],
181
+ gray: [
182
+ "#f8f9fa",
183
+ "#f1f3f5",
184
+ "#e9ecef",
185
+ "#dee2e6",
186
+ "#ced4da",
187
+ "#adb5bd",
188
+ "#868e96",
189
+ "#495057",
190
+ "#343a40",
191
+ "#212529"
192
+ ],
193
+ orange: [
194
+ "#fff4e6",
195
+ "#ffe8cc",
196
+ "#ffd8a8",
197
+ "#ffc078",
198
+ "#ffa94d",
199
+ "#ff922b",
200
+ "#fd7e14",
201
+ "#f76707",
202
+ "#e8590c",
203
+ "#d9480f"
204
+ ],
205
+ pink: [
206
+ "#fff0f6",
207
+ "#ffdeeb",
208
+ "#fcc2d7",
209
+ "#faa2c1",
210
+ "#f783ac",
211
+ "#f06595",
212
+ "#e64980",
213
+ "#d6336c",
214
+ "#c2255c",
215
+ "#a61e4d"
216
+ ],
217
+ red: [
218
+ "#fff5f5",
219
+ "#ffe3e3",
220
+ "#ffc9c9",
221
+ "#ffa8a8",
222
+ "#ff8787",
223
+ "#ff6b6b",
224
+ "#fa5252",
225
+ "#f03e3e",
226
+ "#e03131",
227
+ "#c92a2a"
228
+ ],
229
+ teal: [
230
+ "#e6fcf5",
231
+ "#c3fae8",
232
+ "#96f2d7",
233
+ "#63e6be",
234
+ "#38d9a9",
235
+ "#20c997",
236
+ "#12b886",
237
+ "#0ca678",
238
+ "#099268",
239
+ "#087f5b"
240
+ ],
241
+ violet: [
242
+ "#f3f0ff",
243
+ "#e5dbff",
244
+ "#d0bfff",
245
+ "#b197fc",
246
+ "#9775fa",
247
+ "#845ef7",
248
+ "#7950f2",
249
+ "#7048e8",
250
+ "#6741d9",
251
+ "#5f3dc4"
252
+ ],
253
+ yellow: [
254
+ "#fff9db",
255
+ "#fff3bf",
256
+ "#ffec99",
257
+ "#ffe066",
258
+ "#ffd43b",
259
+ "#fcc419",
260
+ "#fab005",
261
+ "#f59f00",
262
+ "#f08c00",
263
+ "#e67700"
264
+ ]
265
+ };
266
+ function resolveColor(color, fallback = "#228be6") {
267
+ if (typeof color !== "string" || !color) return fallback;
268
+ const [name, rawShade] = color.split(".");
269
+ const shade = Number(rawShade ?? 6);
270
+ return shadeMap[name]?.[Number.isInteger(shade) ? shade : 6] ?? color;
271
+ }
272
+ //#endregion
273
+ //#region src/internal/options.ts
274
+ var bool = (value, fallback) => typeof value === "boolean" ? value : fallback;
275
+ var num = (value, fallback) => typeof value === "number" ? value : fallback;
276
+ var obj = (value) => value && typeof value === "object" ? value : {};
277
+ var list = (value) => Array.isArray(value) ? value : [];
278
+ var formatter = (props) => typeof props.valueFormatter === "function" ? props.valueFormatter : void 0;
279
+ function tooltip(props) {
280
+ if (!bool(props.withTooltip, true)) return { show: false };
281
+ const format = formatter(props);
282
+ return {
283
+ trigger: "axis",
284
+ transitionDuration: num(props.tooltipAnimationDuration, 0) / 1e3,
285
+ valueFormatter: format ? (value) => format(Number(value)) : void 0,
286
+ ...obj(props.tooltipProps)
287
+ };
288
+ }
289
+ function markLine(referenceLines) {
290
+ if (!referenceLines?.length) return void 0;
291
+ return {
292
+ silent: true,
293
+ symbol: "none",
294
+ data: referenceLines.map((line) => ({
295
+ xAxis: line.x,
296
+ yAxis: line.y,
297
+ label: typeof line.label === "string" ? { formatter: line.label } : line.label,
298
+ lineStyle: {
299
+ color: resolveColor(line.color, "#868e96"),
300
+ type: line.strokeDasharray ? "dashed" : "solid"
301
+ }
302
+ }))
303
+ };
304
+ }
305
+ function cartesianOption(props, kind) {
306
+ const data = list(props.data);
307
+ const series = list(props.series);
308
+ const dataKey = String(props.dataKey ?? "name");
309
+ const horizontal = props.orientation !== "vertical";
310
+ const chartType = String(props.type ?? "default");
311
+ const category = data.map((item) => item[dataKey]);
312
+ const commonAxis = { axisLabel: { color: resolveColor(props.textColor, "#868e96") } };
313
+ const categoryAxis = {
314
+ type: "category",
315
+ data: category,
316
+ ...commonAxis
317
+ };
318
+ const valueAxis = {
319
+ type: "value",
320
+ name: props.yAxisLabel,
321
+ ...commonAxis
322
+ };
323
+ const mapped = series.map((item, index) => {
324
+ const itemKind = kind === "composite" ? item.type ?? "line" : kind === "area" ? "line" : kind;
325
+ const color = resolveColor(item.color, resolveColor(`blue.${6 + index % 3}`));
326
+ const stack = chartType === "stacked" || chartType === "percent" ? "stack" : item.stackId;
327
+ const base = {
328
+ name: item.label ?? item.name,
329
+ data: data.map((entry) => entry[item.name]),
330
+ yAxisIndex: item.yAxisId ? 1 : 0,
331
+ stack,
332
+ markLine: index === 0 ? markLine(props.referenceLines) : void 0
333
+ };
334
+ if (itemKind === "bar") return {
335
+ ...base,
336
+ type: "bar",
337
+ barMaxWidth: props.maxBarWidth,
338
+ barMinHeight: num(props.minBarSize, 0),
339
+ itemStyle: {
340
+ color,
341
+ opacity: num(props.fillOpacity, 1)
342
+ },
343
+ label: {
344
+ show: bool(props.withBarValueLabel, false),
345
+ position: horizontal ? "top" : "right"
346
+ }
347
+ };
348
+ return {
349
+ ...base,
350
+ type: "line",
351
+ smooth: ![
352
+ "linear",
353
+ "step",
354
+ "stepBefore",
355
+ "stepAfter"
356
+ ].includes(String(props.curveType ?? item.curveType ?? "monotone")),
357
+ step: String(props.curveType).startsWith("step") ? "middle" : false,
358
+ connectNulls: bool(props.connectNulls, true),
359
+ showSymbol: bool(props.withDots, true),
360
+ symbolSize: 6,
361
+ lineStyle: {
362
+ color,
363
+ width: num(props.strokeWidth, 2),
364
+ type: item.strokeDasharray ? "dashed" : "solid"
365
+ },
366
+ itemStyle: {
367
+ color,
368
+ opacity: num(props.fillOpacity, 1)
369
+ },
370
+ areaStyle: itemKind === "area" ? {
371
+ color,
372
+ opacity: num(props.fillOpacity, .2)
373
+ } : void 0,
374
+ label: {
375
+ show: bool(props.withPointLabels, false),
376
+ position: "top"
377
+ }
378
+ };
379
+ });
380
+ return {
381
+ animationDurationUpdate: num(props.tooltipAnimationDuration, 0),
382
+ color: series.map((item) => resolveColor(item.color)),
383
+ grid: {
384
+ left: 48,
385
+ right: bool(props.withRightYAxis, false) ? 48 : 16,
386
+ top: bool(props.withLegend, false) ? 44 : 16,
387
+ bottom: 38,
388
+ containLabel: true,
389
+ ...obj(props.gridProps)
390
+ },
391
+ legend: {
392
+ show: bool(props.withLegend, false),
393
+ ...obj(props.legendProps)
394
+ },
395
+ tooltip: tooltip(props),
396
+ xAxis: horizontal ? {
397
+ ...categoryAxis,
398
+ show: bool(props.withXAxis, true),
399
+ name: props.xAxisLabel,
400
+ ...obj(props.xAxisProps)
401
+ } : {
402
+ ...valueAxis,
403
+ show: bool(props.withXAxis, true),
404
+ ...obj(props.xAxisProps)
405
+ },
406
+ yAxis: horizontal ? [{
407
+ ...valueAxis,
408
+ show: bool(props.withYAxis, true),
409
+ ...obj(props.yAxisProps)
410
+ }, {
411
+ ...valueAxis,
412
+ show: bool(props.withRightYAxis, false),
413
+ position: "right",
414
+ name: props.rightYAxisLabel,
415
+ ...obj(props.rightYAxisProps)
416
+ }] : {
417
+ ...categoryAxis,
418
+ show: bool(props.withYAxis, true),
419
+ ...obj(props.yAxisProps)
420
+ },
421
+ series: mapped
422
+ };
423
+ }
424
+ function radialOption(props, donut = false) {
425
+ const data = list(props.data);
426
+ return {
427
+ color: data.map((item) => resolveColor(item.color)),
428
+ legend: {
429
+ show: bool(props.withLabels, false) || bool(props.withLegend, false),
430
+ ...obj(props.legendProps)
431
+ },
432
+ tooltip: {
433
+ trigger: "item",
434
+ show: bool(props.withTooltip, true),
435
+ ...obj(props.tooltipProps)
436
+ },
437
+ series: [{
438
+ type: "pie",
439
+ radius: donut ? [`${num(props.thickness, 40)}%`, "75%"] : ["0%", "75%"],
440
+ startAngle: num(props.startAngle, 90),
441
+ minAngle: num(props.minAngle, 0),
442
+ padAngle: num(props.paddingAngle, 0),
443
+ roseType: props.type === "pie" ? void 0 : props.type === "donut" ? void 0 : props.type,
444
+ label: {
445
+ show: bool(props.withLabels, false),
446
+ formatter: props.withLabelsLine ? "{b}: {d}%" : "{b}"
447
+ },
448
+ labelLine: { show: bool(props.withLabelsLine, false) },
449
+ data: data.map((item) => ({
450
+ ...item,
451
+ itemStyle: { color: resolveColor(item.color) }
452
+ }))
453
+ }],
454
+ graphic: props.chartLabel ? [{
455
+ type: "text",
456
+ left: "center",
457
+ top: "middle",
458
+ style: {
459
+ text: String(props.chartLabel),
460
+ fill: resolveColor(props.chartLabelColor, "#212529"),
461
+ fontSize: num(props.chartLabelFontSize, 18)
462
+ }
463
+ }] : void 0
464
+ };
465
+ }
466
+ function scatterOption(props, bubble = false) {
467
+ const data = list(props.data);
468
+ const series = list(props.series);
469
+ const xKey = String(props.dataKey ?? props.xAxisKey ?? "x");
470
+ const yKey = String(props.yAxisKey ?? "y");
471
+ const zKey = String(props.zAxisKey ?? "z");
472
+ return {
473
+ grid: {
474
+ containLabel: true,
475
+ ...obj(props.gridProps)
476
+ },
477
+ legend: {
478
+ show: bool(props.withLegend, false),
479
+ ...obj(props.legendProps)
480
+ },
481
+ tooltip: {
482
+ trigger: "item",
483
+ show: bool(props.withTooltip, true),
484
+ ...obj(props.tooltipProps)
485
+ },
486
+ xAxis: {
487
+ type: "value",
488
+ show: bool(props.withXAxis, true),
489
+ ...obj(props.xAxisProps)
490
+ },
491
+ yAxis: {
492
+ type: "value",
493
+ show: bool(props.withYAxis, true),
494
+ ...obj(props.yAxisProps)
495
+ },
496
+ series: (series.length ? series : [{
497
+ name: String(props.name ?? "value"),
498
+ color: props.color
499
+ }]).map((item) => ({
500
+ type: "scatter",
501
+ name: item.label ?? item.name,
502
+ data: data.filter((entry) => !entry.name || entry.name === item.name).map((entry) => [
503
+ entry[xKey],
504
+ entry[yKey],
505
+ entry[zKey],
506
+ entry
507
+ ]),
508
+ symbolSize: bubble ? (value) => Math.max(4, Math.sqrt(Number(value[2] ?? 1)) * num(props.range, 4)) : num(props.size, 10),
509
+ itemStyle: { color: resolveColor(item.color) }
510
+ }))
511
+ };
512
+ }
513
+ function sparklineOption(props) {
514
+ const data = list(props.data);
515
+ const trend = props.trendColors;
516
+ const color = trend ? resolveColor(data.at(-1) > data[0] ? trend.positive : data.at(-1) < data[0] ? trend.negative : trend.neutral) : resolveColor(props.color);
517
+ return {
518
+ grid: {
519
+ left: 0,
520
+ right: 0,
521
+ top: 1,
522
+ bottom: 1
523
+ },
524
+ xAxis: {
525
+ type: "category",
526
+ show: false
527
+ },
528
+ yAxis: {
529
+ type: "value",
530
+ show: false,
531
+ scale: true
532
+ },
533
+ series: [{
534
+ type: "line",
535
+ data,
536
+ showSymbol: false,
537
+ connectNulls: bool(props.connectNulls, true),
538
+ smooth: props.curveType !== "linear",
539
+ lineStyle: {
540
+ color,
541
+ width: num(props.strokeWidth, 2)
542
+ },
543
+ areaStyle: bool(props.withGradient, true) ? {
544
+ color,
545
+ opacity: num(props.fillOpacity, .6)
546
+ } : void 0
547
+ }]
548
+ };
549
+ }
550
+ function radarOption(props) {
551
+ const data = list(props.data);
552
+ const series = list(props.series);
553
+ const key = String(props.dataKey ?? "name");
554
+ const max = num(props.maxValue, Math.max(1, ...data.flatMap((row) => series.map((s) => Number(row[s.name] ?? 0)))));
555
+ return {
556
+ legend: { show: bool(props.withLegend, false) },
557
+ tooltip: { show: bool(props.withTooltip, true) },
558
+ radar: {
559
+ indicator: data.map((row) => ({
560
+ name: String(row[key]),
561
+ max
562
+ })),
563
+ shape: props.shape === "circle" ? "circle" : "polygon"
564
+ },
565
+ series: [{
566
+ type: "radar",
567
+ data: series.map((s) => ({
568
+ name: s.label ?? s.name,
569
+ value: data.map((row) => Number(row[s.name] ?? 0)),
570
+ lineStyle: { color: resolveColor(s.color) },
571
+ itemStyle: { color: resolveColor(s.color) },
572
+ areaStyle: bool(props.withPolarGrid, false) ? {} : void 0
573
+ }))
574
+ }]
575
+ };
576
+ }
577
+ function simpleOption(type, props) {
578
+ const data = list(props.data);
579
+ if (type === "sankey") return {
580
+ tooltip: { show: bool(props.withTooltip, true) },
581
+ series: [{
582
+ type,
583
+ data: list(props.nodes ?? data),
584
+ links: list(props.links),
585
+ emphasis: { focus: "adjacency" },
586
+ ...obj(props.sankeyProps)
587
+ }]
588
+ };
589
+ return {
590
+ tooltip: { show: bool(props.withTooltip, true) },
591
+ legend: { show: bool(props.withLegend, false) },
592
+ series: [{
593
+ type,
594
+ data: data.map((item) => ({
595
+ ...item,
596
+ itemStyle: { color: resolveColor(item.color) }
597
+ })),
598
+ ...obj(props[`${type}Props`])
599
+ }]
600
+ };
601
+ }
602
+ function radialBarOption(props) {
603
+ const data = list(props.data);
604
+ return {
605
+ legend: { show: bool(props.withLegend, false) },
606
+ tooltip: { show: bool(props.withTooltip, true) },
607
+ polar: {},
608
+ angleAxis: {
609
+ max: num(props.maxValue, 100),
610
+ show: false
611
+ },
612
+ radiusAxis: {
613
+ type: "category",
614
+ data: data.map((i) => i.name),
615
+ show: bool(props.withLabels, true)
616
+ },
617
+ series: [{
618
+ type: "bar",
619
+ coordinateSystem: "polar",
620
+ roundCap: true,
621
+ data: data.map((i) => ({
622
+ value: i.value,
623
+ itemStyle: { color: resolveColor(i.color) }
624
+ }))
625
+ }]
626
+ };
627
+ }
628
+ function heatmapOption(props) {
629
+ const input = props.data && typeof props.data === "object" ? props.data : {};
630
+ const data = Object.entries(input).map(([date, value]) => [date, value]);
631
+ const values = Object.values(input);
632
+ const date = (value, fallback) => value instanceof Date ? value.toISOString().slice(0, 10) : typeof value === "string" ? value : fallback;
633
+ const start = date(props.startDate, String(data[0]?.[0] ?? (/* @__PURE__ */ new Date()).toISOString().slice(0, 10)));
634
+ const end = date(props.endDate, String(data.at(-1)?.[0] ?? start));
635
+ return {
636
+ tooltip: { show: bool(props.withTooltip, false) },
637
+ visualMap: {
638
+ show: bool(props.withLegend, false),
639
+ min: props.domain?.[0] ?? Math.min(0, ...values),
640
+ max: props.domain?.[1] ?? Math.max(1, ...values),
641
+ inRange: { color: list(props.colors).length ? list(props.colors).map((color) => resolveColor(color)) : ["#ebfbee", "#2f9e44"] },
642
+ orient: "horizontal",
643
+ left: "center",
644
+ bottom: 0
645
+ },
646
+ calendar: {
647
+ range: [start, end],
648
+ cellSize: num(props.rectSize, 10) + num(props.gap, 1),
649
+ dayLabel: {
650
+ show: bool(props.withWeekdayLabels, false),
651
+ firstDay: num(props.firstDayOfWeek, 1)
652
+ },
653
+ monthLabel: { show: bool(props.withMonthLabels, false) },
654
+ itemStyle: {
655
+ borderWidth: num(props.gap, 1),
656
+ borderColor: "transparent",
657
+ borderRadius: num(props.rectRadius, 2)
658
+ }
659
+ },
660
+ series: [{
661
+ type: "heatmap",
662
+ coordinateSystem: "calendar",
663
+ data
664
+ }]
665
+ };
666
+ }
667
+ //#endregion
668
+ //#region src/charts.ts
669
+ var AreaChart = createChartComponent("AreaChart", (p) => cartesianOption(p, "area"));
670
+ var BarChart = createChartComponent("BarChart", (p) => cartesianOption(p, "bar"));
671
+ var LineChart = createChartComponent("LineChart", (p) => cartesianOption(p, "line"));
672
+ var CompositeChart = createChartComponent("CompositeChart", (p) => cartesianOption(p, "composite"));
673
+ var PieChart = createChartComponent("PieChart", (p) => radialOption(p));
674
+ var DonutChart = createChartComponent("DonutChart", (p) => radialOption(p, true));
675
+ var ScatterChart = createChartComponent("ScatterChart", (p) => scatterOption(p));
676
+ var BubbleChart = createChartComponent("BubbleChart", (p) => scatterOption(p, true));
677
+ var RadarChart = createChartComponent("RadarChart", radarOption);
678
+ var RadialBarChart = createChartComponent("RadialBarChart", radialBarOption);
679
+ var FunnelChart = createChartComponent("FunnelChart", (p) => simpleOption("funnel", p));
680
+ var Treemap = createChartComponent("Treemap", (p) => simpleOption("treemap", p));
681
+ var SankeyChart = createChartComponent("SankeyChart", (p) => simpleOption("sankey", p));
682
+ var Sparkline = createChartComponent("Sparkline", sparklineOption);
683
+ var Heatmap = createChartComponent("Heatmap", heatmapOption);
684
+ var BarsList = createChartComponent("BarsList", (p) => cartesianOption({
685
+ ...p,
686
+ dataKey: "name",
687
+ series: [{
688
+ name: "value",
689
+ color: p.barColor
690
+ }],
691
+ orientation: "vertical",
692
+ withXAxis: false,
693
+ withYAxis: true,
694
+ withTooltip: false,
695
+ maxBarWidth: p.barHeight
696
+ }, "bar"));
697
+ //#endregion
698
+ //#region src/ChartTooltip/ChartTooltip.ts
699
+ var ChartTooltip = defineComponent({
700
+ name: "MantineChartTooltip",
701
+ props: {
702
+ label: null,
703
+ payload: Array,
704
+ unit: String,
705
+ type: {
706
+ type: String,
707
+ default: "area"
708
+ },
709
+ segmentId: String,
710
+ series: Array,
711
+ valueFormatter: Function,
712
+ showColor: {
713
+ type: Boolean,
714
+ default: true
715
+ }
716
+ },
717
+ setup(props) {
718
+ const labels = computed(() => Object.fromEntries((props.series ?? []).map((item) => [item.name, item.label ?? item.name])));
719
+ return () => {
720
+ const payload = props.segmentId ? props.payload?.filter((item) => item.name === props.segmentId || item.dataKey === props.segmentId) : props.payload;
721
+ if (!payload?.length) return null;
722
+ return h("div", {
723
+ class: "mantine-ChartTooltip-tooltip",
724
+ "data-type": props.type
725
+ }, [props.label != null ? h("div", { class: "mantine-ChartTooltip-tooltipLabel" }, [props.label]) : null, h("div", { class: "mantine-ChartTooltip-tooltipBody" }, payload.map((item) => h("div", { class: "mantine-ChartTooltip-tooltipItem" }, [h("div", { class: "mantine-ChartTooltip-tooltipItemBody" }, [props.showColor ? h("span", {
726
+ class: "mantine-ChartTooltip-tooltipItemColor",
727
+ style: { background: resolveColor(item.color) }
728
+ }) : null, h("span", { class: "mantine-ChartTooltip-tooltipItemName" }, labels.value[item.name ?? ""] ?? item.name)]), h("span", { class: "mantine-ChartTooltip-tooltipItemData" }, `${props.valueFormatter ? props.valueFormatter(Number(item.value)) : item.value ?? ""}${props.unit ?? item.unit ?? ""}`)])))]);
729
+ };
730
+ }
731
+ });
732
+ //#endregion
733
+ //#region src/ChartLegend/ChartLegend.ts
734
+ var ChartLegend = defineComponent({
735
+ name: "MantineChartLegend",
736
+ props: {
737
+ payload: Array,
738
+ onHighlight: {
739
+ type: Function,
740
+ required: true
741
+ },
742
+ legendPosition: {
743
+ type: String,
744
+ required: true
745
+ },
746
+ series: Array,
747
+ showColor: {
748
+ type: Boolean,
749
+ default: true
750
+ },
751
+ centered: Boolean
752
+ },
753
+ setup(props) {
754
+ return () => h("div", {
755
+ class: "mantine-ChartLegend-legend",
756
+ "data-position": props.legendPosition,
757
+ "data-centered": props.centered || void 0,
758
+ onMouseleave: () => props.onHighlight(null)
759
+ }, props.payload?.map((item) => {
760
+ const key = item.dataKey ?? item.name ?? "";
761
+ const label = props.series?.find((s) => s.name === key)?.label ?? key;
762
+ return h("div", {
763
+ class: "mantine-ChartLegend-legendItem",
764
+ onMouseenter: () => props.onHighlight(key)
765
+ }, [props.showColor ? h("span", {
766
+ class: "mantine-ChartLegend-legendItemColor",
767
+ style: { background: resolveColor(item.color) }
768
+ }) : null, h("span", { class: "mantine-ChartLegend-legendItemName" }, label)]);
769
+ }));
770
+ }
771
+ });
772
+ //#endregion
773
+ //#region src/utils/get-series-labels/get-series-labels.ts
774
+ function getSeriesLabels(series) {
775
+ return Object.fromEntries((series ?? []).map((item) => [item.name, item.label ?? item.name]));
776
+ }
777
+ //#endregion
778
+ export { AreaChart, BarChart, BarsList, BubbleChart, ChartLegend, ChartTooltip, CompositeChart, DonutChart, FunnelChart, Heatmap, LineChart, PieChart, RadarChart, RadialBarChart, SankeyChart, ScatterChart, Sparkline, Treemap, getSeriesLabels };
779
+
780
+ //# sourceMappingURL=index.mjs.map