vue-chrts 0.1.0-beta.4 → 0.1.0-beta.5
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.
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { Position as
|
|
3
|
-
import { VisXYContainer as
|
|
4
|
-
import
|
|
5
|
-
import { LegendPosition as
|
|
6
|
-
const Y = /* @__PURE__ */
|
|
1
|
+
import { defineComponent as E, ref as T, computed as g, createApp as F, onUnmounted as $, createElementBlock as p, openBlock as r, normalizeClass as L, createVNode as s, createCommentVNode as v, unref as o, withCtx as N, createBlock as h, Fragment as b, renderList as G, mergeProps as P } from "vue";
|
|
2
|
+
import { Position as x, CurveType as C } from "@unovis/ts";
|
|
3
|
+
import { VisXYContainer as U, VisTooltip as j, VisArea as I, VisLine as M, VisAxis as B, VisCrosshair as w, VisBulletLegend as z } from "@unovis/vue";
|
|
4
|
+
import R from "../Tooltip.js";
|
|
5
|
+
import { LegendPosition as X } from "../../types.js";
|
|
6
|
+
const m = 24, A = 4, Y = 0.5, H = "#3b82f6", Z = /* @__PURE__ */ E({
|
|
7
7
|
__name: "AreaChart",
|
|
8
8
|
props: {
|
|
9
9
|
data: {},
|
|
@@ -14,82 +14,91 @@ const Y = /* @__PURE__ */ V({
|
|
|
14
14
|
xFormatter: {},
|
|
15
15
|
yFormatter: {},
|
|
16
16
|
curveType: {},
|
|
17
|
-
xNumTicks: { default: (i) => i.data.length >
|
|
17
|
+
xNumTicks: { default: (i) => i.data.length > m ? m / A : i.data.length - 1 },
|
|
18
18
|
xExplicitTicks: {},
|
|
19
19
|
minMaxTicksOnly: {},
|
|
20
|
-
yNumTicks: { default: (i) => i.data.length >
|
|
20
|
+
yNumTicks: { default: (i) => i.data.length > m ? m / A : i.data.length - 1 },
|
|
21
21
|
hideLegend: { type: Boolean },
|
|
22
22
|
hideTooltip: { type: Boolean },
|
|
23
23
|
xGridLine: { type: Boolean },
|
|
24
24
|
xDomainLine: { type: Boolean },
|
|
25
25
|
yGridLine: { type: Boolean },
|
|
26
26
|
yDomainLine: { type: Boolean },
|
|
27
|
+
xTickLine: { type: Boolean },
|
|
27
28
|
legendPosition: {}
|
|
28
29
|
},
|
|
29
30
|
setup(i) {
|
|
30
|
-
const
|
|
31
|
+
const l = i, d = Object.values(l.categories).map((e) => e.color), n = T(null), a = T(null), D = g(() => (e) => {
|
|
31
32
|
if (typeof window > "u" || typeof document > "u")
|
|
32
33
|
return "";
|
|
33
34
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
35
|
+
if (a.value || (a.value = document.createElement("div")), !n.value)
|
|
36
|
+
n.value = F(R, {
|
|
37
|
+
data: e,
|
|
38
|
+
categories: l.categories
|
|
39
|
+
}), n.value.mount(a.value);
|
|
40
|
+
else {
|
|
41
|
+
const t = n.value._instance;
|
|
42
|
+
t != null && t.proxy && (t.proxy.$props.data = e, t.proxy.$props.categories = l.categories);
|
|
43
|
+
}
|
|
44
|
+
return a.value.innerHTML;
|
|
45
|
+
} catch (t) {
|
|
46
|
+
return console.error("Error generating tooltip:", t), "";
|
|
43
47
|
}
|
|
44
48
|
});
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
$(() => {
|
|
50
|
+
n.value && (n.value.unmount(), n.value = null), a.value && (a.value = null);
|
|
51
|
+
});
|
|
52
|
+
function O(e) {
|
|
53
|
+
var t;
|
|
47
54
|
return {
|
|
48
|
-
y: (
|
|
49
|
-
color: ((
|
|
55
|
+
y: (c) => Number(c[e]),
|
|
56
|
+
color: ((t = l.categories[e]) == null ? void 0 : t.color) ?? H
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
|
-
const
|
|
53
|
-
(
|
|
54
|
-
|
|
59
|
+
const V = g(
|
|
60
|
+
() => d.map(
|
|
61
|
+
(e, t) => `
|
|
62
|
+
<linearGradient id="gradient${t}-${e}" gradientTransform="rotate(90)">
|
|
55
63
|
<stop offset="0%" stop-color="${e}" stop-opacity="1" />
|
|
56
64
|
<stop offset="100%" stop-color="${e}" stop-opacity="0" />
|
|
57
65
|
</linearGradient>
|
|
58
66
|
`
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
).join("")
|
|
68
|
+
), k = g(
|
|
69
|
+
() => l.legendPosition === X.Top
|
|
61
70
|
);
|
|
62
|
-
return (e,
|
|
63
|
-
class:
|
|
71
|
+
return (e, t) => (r(), p("div", {
|
|
72
|
+
class: L(["flex flex-col space-y-4", { "flex-col-reverse": k.value }])
|
|
64
73
|
}, [
|
|
65
|
-
|
|
74
|
+
s(o(U), {
|
|
66
75
|
data: e.data,
|
|
67
76
|
height: e.height,
|
|
68
|
-
"svg-defs":
|
|
77
|
+
"svg-defs": V.value
|
|
69
78
|
}, {
|
|
70
|
-
default:
|
|
71
|
-
e.hideTooltip ?
|
|
79
|
+
default: N(() => [
|
|
80
|
+
e.hideTooltip ? v("", !0) : (r(), h(o(j), {
|
|
72
81
|
key: 0,
|
|
73
|
-
"horizontal-placement":
|
|
74
|
-
"vertical-placement":
|
|
82
|
+
"horizontal-placement": o(x).Right,
|
|
83
|
+
"vertical-placement": o(x).Top
|
|
75
84
|
}, null, 8, ["horizontal-placement", "vertical-placement"])),
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
x: (
|
|
85
|
+
(r(!0), p(b, null, G(Object.keys(l.categories), (c, u) => (r(), p(b, { key: u }, [
|
|
86
|
+
s(o(I), P({
|
|
87
|
+
x: (y, f) => f,
|
|
79
88
|
ref_for: !0
|
|
80
|
-
},
|
|
81
|
-
color: `url(#gradient${
|
|
82
|
-
opacity:
|
|
83
|
-
"curve-type": e.curveType ??
|
|
89
|
+
}, O(c), {
|
|
90
|
+
color: `url(#gradient${u}-${o(d)[u]})`,
|
|
91
|
+
opacity: Y,
|
|
92
|
+
"curve-type": e.curveType ?? o(C).MonotoneX
|
|
84
93
|
}), null, 16, ["x", "color", "curve-type"]),
|
|
85
|
-
|
|
86
|
-
x: (
|
|
87
|
-
y: (
|
|
88
|
-
color:
|
|
89
|
-
"curve-type": e.curveType ??
|
|
94
|
+
s(o(M), {
|
|
95
|
+
x: (y, f) => f,
|
|
96
|
+
y: (y) => y[c],
|
|
97
|
+
color: o(d)[u],
|
|
98
|
+
"curve-type": e.curveType ?? o(C).MonotoneX
|
|
90
99
|
}, null, 8, ["x", "y", "color", "curve-type"])
|
|
91
100
|
], 64))), 128)),
|
|
92
|
-
|
|
101
|
+
s(o(B), {
|
|
93
102
|
type: "x",
|
|
94
103
|
"tick-format": e.xFormatter,
|
|
95
104
|
label: e.xLabel,
|
|
@@ -97,10 +106,11 @@ const Y = /* @__PURE__ */ V({
|
|
|
97
106
|
"domain-line": e.xDomainLine,
|
|
98
107
|
"grid-line": e.xGridLine,
|
|
99
108
|
"num-ticks": e.xNumTicks,
|
|
109
|
+
"tick-line": e.xTickLine,
|
|
100
110
|
"tick-values": e.xExplicitTicks,
|
|
101
111
|
"min-max-ticks-only": e.minMaxTicksOnly
|
|
102
|
-
}, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-values", "min-max-ticks-only"]),
|
|
103
|
-
|
|
112
|
+
}, null, 8, ["tick-format", "label", "domain-line", "grid-line", "num-ticks", "tick-line", "tick-values", "min-max-ticks-only"]),
|
|
113
|
+
s(o(B), {
|
|
104
114
|
type: "y",
|
|
105
115
|
"num-ticks": e.yNumTicks,
|
|
106
116
|
"tick-format": e.yFormatter,
|
|
@@ -109,19 +119,19 @@ const Y = /* @__PURE__ */ V({
|
|
|
109
119
|
"domain-line": e.yDomainLine,
|
|
110
120
|
"tick-line": !!e.yGridLine
|
|
111
121
|
}, null, 8, ["num-ticks", "tick-format", "label", "grid-line", "domain-line", "tick-line"]),
|
|
112
|
-
e.hideTooltip ?
|
|
122
|
+
e.hideTooltip ? v("", !0) : (r(), h(o(w), {
|
|
113
123
|
key: 1,
|
|
114
124
|
color: "#666",
|
|
115
|
-
template:
|
|
125
|
+
template: D.value
|
|
116
126
|
}, null, 8, ["template"]))
|
|
117
127
|
]),
|
|
118
128
|
_: 1
|
|
119
129
|
}, 8, ["data", "height", "svg-defs"]),
|
|
120
|
-
e.hideLegend ?
|
|
130
|
+
e.hideLegend ? v("", !0) : (r(), p("div", {
|
|
121
131
|
key: 0,
|
|
122
|
-
class:
|
|
132
|
+
class: L(["flex items-center justify-end", { "pb-4": k.value }])
|
|
123
133
|
}, [
|
|
124
|
-
|
|
134
|
+
s(o(z), {
|
|
125
135
|
items: Object.values(e.categories)
|
|
126
136
|
}, null, 8, ["items"])
|
|
127
137
|
], 2))
|
|
@@ -129,5 +139,5 @@ const Y = /* @__PURE__ */ V({
|
|
|
129
139
|
}
|
|
130
140
|
});
|
|
131
141
|
export {
|
|
132
|
-
|
|
142
|
+
Z as default
|
|
133
143
|
};
|
|
@@ -27,10 +27,10 @@ export interface AreaChartProps<T> {
|
|
|
27
27
|
/**
|
|
28
28
|
* A function that formats the x-axis tick labels.
|
|
29
29
|
* @param i The x-axis key of the item to be formatted.
|
|
30
|
-
* @param idx The index of the data point.
|
|
30
|
+
* @param idx The index of the data point (optional).
|
|
31
31
|
* @returns The formatted x-axis label.
|
|
32
32
|
*/
|
|
33
|
-
xFormatter: (i: number, idx
|
|
33
|
+
xFormatter: (i: number, idx?: number) => string | number;
|
|
34
34
|
/**
|
|
35
35
|
* An optional function that formats the y-axis tick labels.
|
|
36
36
|
* @param i The y-axis key of the item to be formatted.
|
|
@@ -83,6 +83,10 @@ export interface AreaChartProps<T> {
|
|
|
83
83
|
* If `true`, displays a domain line (axis line) along the y-axis.
|
|
84
84
|
*/
|
|
85
85
|
yDomainLine?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* If `true`, displays tick lines on the x-axis.
|
|
88
|
+
*/
|
|
89
|
+
xTickLine?: boolean;
|
|
86
90
|
/**
|
|
87
91
|
* Optional position for the legend, if applicable.
|
|
88
92
|
* See `LegendPosition` for available options.
|
|
@@ -87,7 +87,7 @@ const M = /* @__PURE__ */ b({
|
|
|
87
87
|
"tick-format": e.xFormatter,
|
|
88
88
|
label: e.xLabel,
|
|
89
89
|
"grid-line": e.xGridLine,
|
|
90
|
-
"domain-line": e.xDomainLine,
|
|
90
|
+
"domain-line": !!e.xDomainLine,
|
|
91
91
|
"tick-line": e.xTickLine,
|
|
92
92
|
"num-ticks": e.xNumTicks,
|
|
93
93
|
"tick-values": e.xExplicitTicks,
|
|
@@ -97,7 +97,7 @@ const M = /* @__PURE__ */ b({
|
|
|
97
97
|
type: "y",
|
|
98
98
|
label: e.yLabel,
|
|
99
99
|
"grid-line": e.orientation !== i(s).Horizontal && e.yGridLine,
|
|
100
|
-
"domain-line": e.yDomainLine,
|
|
100
|
+
"domain-line": !!e.yDomainLine,
|
|
101
101
|
"tick-format": e.yFormatter,
|
|
102
102
|
"num-ticks": e.yNumTicks,
|
|
103
103
|
"tick-line": e.yTickLine
|
|
@@ -30,10 +30,10 @@ export interface BarChartProps<T> {
|
|
|
30
30
|
/**
|
|
31
31
|
* A function that formats the x-axis tick labels.
|
|
32
32
|
* @param i The x-axis key of the item to be formatted.
|
|
33
|
-
* @param idx The index of the data point.
|
|
33
|
+
* @param idx The index of the data point (optional).
|
|
34
34
|
* @returns The formatted x-axis label.
|
|
35
35
|
*/
|
|
36
|
-
xFormatter: (i: number, idx
|
|
36
|
+
xFormatter: (i: number, idx?: number) => string | number;
|
|
37
37
|
/**
|
|
38
38
|
* An optional function that formats the y-axis tick labels.
|
|
39
39
|
* @param i The y-axis key of the item to be formatted.
|
|
@@ -26,17 +26,17 @@ export interface LineChartProps<T> {
|
|
|
26
26
|
/**
|
|
27
27
|
* A function that formats the x-axis tick labels.
|
|
28
28
|
* @param i The x-axis key of the item to be formatted.
|
|
29
|
-
* @param idx The index of the data point.
|
|
29
|
+
* @param idx The index of the data point (optional).
|
|
30
30
|
* @returns The formatted x-axis label.
|
|
31
31
|
*/
|
|
32
|
-
xFormatter: (i: number, idx
|
|
32
|
+
xFormatter: (i: number, idx?: number) => string | number;
|
|
33
33
|
/**
|
|
34
34
|
* An optional function that formats the y-axis tick labels.
|
|
35
35
|
* @param i The y-axis key of the item to be formatted.
|
|
36
36
|
* @param idx The index of the data point.
|
|
37
37
|
* @returns The formatted y-axis label.
|
|
38
38
|
*/
|
|
39
|
-
yFormatter?: (i: number, idx
|
|
39
|
+
yFormatter?: (i: number, idx?: number) => string;
|
|
40
40
|
/**
|
|
41
41
|
* The type of curve to use for the line chart.
|
|
42
42
|
* See `CurveType` for available options.
|