vue-chrts 2.0.0-beta.4 → 2.0.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,13 +1,13 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { Position as
|
|
3
|
-
import { createMarkers as
|
|
4
|
-
import
|
|
5
|
-
import { VisXYContainer as
|
|
6
|
-
import { LegendPosition as
|
|
7
|
-
const
|
|
1
|
+
import { defineComponent as z, useSlots as R, useTemplateRef as U, ref as H, computed as d, createElementBlock as f, openBlock as c, normalizeClass as K, normalizeStyle as p, createVNode as u, createCommentVNode as y, createElementVNode as q, unref as r, withCtx as J, createBlock as k, Fragment as T, renderList as Q, mergeProps as v, renderSlot as b } from "vue";
|
|
2
|
+
import { Position as $, CurveType as h } from "@unovis/ts";
|
|
3
|
+
import { createMarkers as Z } from "../../utils.js";
|
|
4
|
+
import I from "../Tooltip.js";
|
|
5
|
+
import { VisXYContainer as _, VisTooltip as ee, VisArea as B, VisLine as D, VisAxis as O, VisCrosshair as te, VisBulletLegend as ie } from "@unovis/vue";
|
|
6
|
+
import { LegendPosition as ae } from "../../types.js";
|
|
7
|
+
const ne = ["id"], oe = {
|
|
8
8
|
ref: "slotWrapper",
|
|
9
9
|
style: { display: "none" }
|
|
10
|
-
},
|
|
10
|
+
}, F = 0.5, A = "#3b82f6", ye = /* @__PURE__ */ z({
|
|
11
11
|
__name: "AreaChart",
|
|
12
12
|
props: {
|
|
13
13
|
data: {},
|
|
@@ -34,7 +34,7 @@ const _ = ["id"], ee = {
|
|
|
34
34
|
yNumTicks: {},
|
|
35
35
|
hideLegend: { type: Boolean, default: !1 },
|
|
36
36
|
hideTooltip: { type: Boolean },
|
|
37
|
-
legendPosition: { default:
|
|
37
|
+
legendPosition: { default: ae.BottomCenter },
|
|
38
38
|
legendStyle: { default: void 0 },
|
|
39
39
|
xDomainLine: { type: Boolean },
|
|
40
40
|
yDomainLine: { type: Boolean },
|
|
@@ -50,37 +50,38 @@ const _ = ["id"], ee = {
|
|
|
50
50
|
xAxisConfig: {},
|
|
51
51
|
yAxisConfig: {},
|
|
52
52
|
yDomain: {},
|
|
53
|
-
xDomain: {}
|
|
53
|
+
xDomain: {},
|
|
54
|
+
stacked: { type: Boolean }
|
|
54
55
|
},
|
|
55
56
|
emits: ["click"],
|
|
56
|
-
setup(e, { emit:
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
(l,
|
|
57
|
+
setup(e, { emit: V }) {
|
|
58
|
+
const j = V, n = e, G = R(), C = U("slotWrapper"), m = H(), g = d(() => {
|
|
59
|
+
const i = Object.values(n.categories).map(
|
|
60
|
+
(l, a) => `var(--vis-color${a})`
|
|
60
61
|
);
|
|
61
62
|
return Object.values(n.categories).map(
|
|
62
|
-
(l,
|
|
63
|
+
(l, a) => l.color ?? i[a]
|
|
63
64
|
);
|
|
64
|
-
}),
|
|
65
|
-
var
|
|
66
|
-
return (
|
|
67
|
-
}),
|
|
68
|
-
const
|
|
69
|
-
var
|
|
65
|
+
}), N = d(() => {
|
|
66
|
+
var i;
|
|
67
|
+
return (i = n.markerConfig) != null && i.config ? Z(n.markerConfig) : "";
|
|
68
|
+
}), S = d(() => n.legendPosition.startsWith("top")), W = d(() => n.legendPosition.includes("left") ? "flex-start" : n.legendPosition.includes("right") ? "flex-end" : "center"), M = d(() => {
|
|
69
|
+
const i = (a, t) => {
|
|
70
|
+
var o;
|
|
70
71
|
return `
|
|
71
|
-
<linearGradient id="gradient${
|
|
72
|
-
${((
|
|
72
|
+
<linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
|
|
73
|
+
${((o = n.gradientStops) == null ? void 0 : o.map(
|
|
73
74
|
(s) => `<stop offset="${s.offset}" stop-color="${t}" stop-opacity="${s.stopOpacity}" />`
|
|
74
75
|
).join("")) ?? ""}
|
|
75
76
|
<stop offset="100%" stop-color="${t}" stop-opacity="0" />
|
|
76
77
|
</linearGradient>
|
|
77
78
|
`;
|
|
78
|
-
}, l = (
|
|
79
|
-
var
|
|
79
|
+
}, l = (a, t) => {
|
|
80
|
+
var o;
|
|
80
81
|
return `
|
|
81
|
-
<linearGradient id="gradient${
|
|
82
|
+
<linearGradient id="gradient${a}-${t}" gradientTransform="rotate(90)">
|
|
82
83
|
|
|
83
|
-
${((
|
|
84
|
+
${((o = n.gradientStops) == null ? void 0 : o.map(
|
|
84
85
|
(s) => `
|
|
85
86
|
<stop offset="${s.offset}" style="stop-color:var(${t});stop-opacity:${s.stopOpacity}" />
|
|
86
87
|
`
|
|
@@ -88,67 +89,94 @@ const _ = ["id"], ee = {
|
|
|
88
89
|
</linearGradient>
|
|
89
90
|
`;
|
|
90
91
|
};
|
|
91
|
-
return
|
|
92
|
-
(
|
|
92
|
+
return g.value.map(
|
|
93
|
+
(a, t) => a != null && a.includes("#") ? i(t, a) : l(t, a ?? A)
|
|
93
94
|
).join("");
|
|
94
95
|
});
|
|
95
|
-
function
|
|
96
|
+
function P(i) {
|
|
96
97
|
var l;
|
|
97
98
|
return {
|
|
98
|
-
y: (
|
|
99
|
-
color: ((l = n.categories[
|
|
99
|
+
y: (a) => Number(a[i]),
|
|
100
|
+
color: ((l = n.categories[i]) == null ? void 0 : l.color) ?? A
|
|
100
101
|
};
|
|
101
102
|
}
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
const w = d(() => Object.keys(n.categories).map(
|
|
104
|
+
(i) => (l) => Number(l[i])
|
|
105
|
+
)), X = d(() => {
|
|
106
|
+
const i = Object.keys(n.categories);
|
|
107
|
+
return i.map((l, a) => (t) => {
|
|
108
|
+
let o = 0;
|
|
109
|
+
for (let s = 0; s <= a; s++)
|
|
110
|
+
o += Number(t[i[s]]) || 0;
|
|
111
|
+
return o;
|
|
112
|
+
});
|
|
113
|
+
}), L = d(() => (i, l) => g.value[l] ?? A);
|
|
114
|
+
function E(i) {
|
|
115
|
+
return typeof window > "u" ? "" : C.value ? C.value.innerHTML : "";
|
|
104
116
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
117
|
+
function Y(i) {
|
|
118
|
+
return m.value = i, E();
|
|
107
119
|
}
|
|
108
|
-
return (
|
|
109
|
-
var
|
|
120
|
+
return (i, l) => {
|
|
121
|
+
var a;
|
|
110
122
|
return c(), f("div", {
|
|
111
|
-
style:
|
|
123
|
+
style: p({
|
|
112
124
|
display: "flex",
|
|
113
|
-
flexDirection:
|
|
125
|
+
flexDirection: S.value ? "column-reverse" : "column",
|
|
114
126
|
gap: "var(--vis-legend-spacing)"
|
|
115
127
|
}),
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
class: K({ "stacked-area-chart": e.stacked }),
|
|
129
|
+
id: (a = e.markerConfig) == null ? void 0 : a.id,
|
|
130
|
+
onClick: l[0] || (l[0] = (t) => j("click", t, m.value))
|
|
118
131
|
}, [
|
|
119
|
-
|
|
132
|
+
u(r(_), {
|
|
120
133
|
data: e.data,
|
|
121
134
|
height: e.height,
|
|
122
135
|
padding: e.padding,
|
|
123
|
-
"svg-defs":
|
|
136
|
+
"svg-defs": M.value + N.value,
|
|
124
137
|
"y-domain": e.yDomain,
|
|
125
138
|
"x-domain": e.xDomain
|
|
126
139
|
}, {
|
|
127
|
-
default:
|
|
128
|
-
e.hideTooltip ?
|
|
140
|
+
default: J(() => [
|
|
141
|
+
e.hideTooltip ? y("", !0) : (c(), k(r(ee), {
|
|
129
142
|
key: 0,
|
|
130
|
-
"horizontal-placement":
|
|
131
|
-
"vertical-placement":
|
|
143
|
+
"horizontal-placement": r($).Right,
|
|
144
|
+
"vertical-placement": r($).Top
|
|
132
145
|
}, null, 8, ["horizontal-placement", "vertical-placement"])),
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
x: (
|
|
136
|
-
|
|
137
|
-
color:
|
|
138
|
-
opacity: e.hideArea ? 0 :
|
|
139
|
-
"curve-type": e.curveType ??
|
|
146
|
+
e.stacked ? (c(), f(T, { key: 1 }, [
|
|
147
|
+
u(r(B), {
|
|
148
|
+
x: (t, o) => o,
|
|
149
|
+
y: w.value,
|
|
150
|
+
color: L.value,
|
|
151
|
+
opacity: e.hideArea ? 0 : F,
|
|
152
|
+
"curve-type": e.curveType ?? r(h).MonotoneX
|
|
153
|
+
}, null, 8, ["x", "y", "color", "opacity", "curve-type"]),
|
|
154
|
+
u(r(D), {
|
|
155
|
+
x: (t, o) => o,
|
|
156
|
+
y: X.value,
|
|
157
|
+
color: L.value,
|
|
158
|
+
"curve-type": e.curveType ?? r(h).MonotoneX,
|
|
159
|
+
"line-width": e.lineWidth
|
|
160
|
+
}, null, 8, ["x", "y", "color", "curve-type", "line-width"])
|
|
161
|
+
], 64)) : (c(!0), f(T, { key: 2 }, Q(Object.keys(n.categories), (t, o) => (c(), f(T, { key: t }, [
|
|
162
|
+
u(r(B), v({
|
|
163
|
+
x: (s, x) => x
|
|
164
|
+
}, { ref_for: !0 }, P(t), {
|
|
165
|
+
color: `url(#gradient${o}-${g.value[o]})`,
|
|
166
|
+
opacity: e.hideArea ? 0 : F,
|
|
167
|
+
"curve-type": e.curveType ?? r(h).MonotoneX
|
|
140
168
|
}), null, 16, ["x", "color", "opacity", "curve-type"]),
|
|
141
|
-
|
|
142
|
-
x: (s,
|
|
169
|
+
u(r(D), {
|
|
170
|
+
x: (s, x) => x,
|
|
143
171
|
y: (s) => s[t],
|
|
144
|
-
color:
|
|
145
|
-
"curve-type": e.curveType ??
|
|
172
|
+
color: g.value[o],
|
|
173
|
+
"curve-type": e.curveType ?? r(h).MonotoneX,
|
|
146
174
|
"line-width": e.lineWidth,
|
|
147
|
-
lineDashArray: e.lineDashArray ? e.lineDashArray[
|
|
175
|
+
lineDashArray: e.lineDashArray ? e.lineDashArray[o] : void 0
|
|
148
176
|
}, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
|
|
149
177
|
], 64))), 128)),
|
|
150
|
-
e.hideXAxis ?
|
|
151
|
-
key:
|
|
178
|
+
e.hideXAxis ? y("", !0) : (c(), k(r(O), v({
|
|
179
|
+
key: 3,
|
|
152
180
|
type: "x",
|
|
153
181
|
label: e.xLabel,
|
|
154
182
|
"label-margin": 8,
|
|
@@ -160,8 +188,8 @@ const _ = ["id"], ee = {
|
|
|
160
188
|
"tick-line": e.xTickLine,
|
|
161
189
|
"min-max-ticks-only": e.minMaxTicksOnly
|
|
162
190
|
}, e.xAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
|
|
163
|
-
e.hideYAxis ?
|
|
164
|
-
key:
|
|
191
|
+
e.hideYAxis ? y("", !0) : (c(), k(r(O), v({
|
|
192
|
+
key: 4,
|
|
165
193
|
type: "y",
|
|
166
194
|
label: e.yLabel,
|
|
167
195
|
"num-ticks": e.yNumTicks,
|
|
@@ -170,19 +198,19 @@ const _ = ["id"], ee = {
|
|
|
170
198
|
"domain-line": e.yDomainLine,
|
|
171
199
|
"tick-line": e.yTickLine
|
|
172
200
|
}, e.yAxisConfig), null, 16, ["label", "num-ticks", "tick-format", "grid-line", "domain-line", "tick-line"])),
|
|
173
|
-
e.hideTooltip ?
|
|
201
|
+
e.hideTooltip ? y("", !0) : (c(), k(r(te), v({ key: 5 }, e.crosshairConfig, { template: Y }), null, 16))
|
|
174
202
|
]),
|
|
175
203
|
_: 1
|
|
176
204
|
}, 8, ["data", "height", "padding", "svg-defs", "y-domain", "x-domain"]),
|
|
177
|
-
n.hideLegend ?
|
|
205
|
+
n.hideLegend ? y("", !0) : (c(), f("div", {
|
|
178
206
|
key: 0,
|
|
179
|
-
style:
|
|
207
|
+
style: p({
|
|
180
208
|
display: "flex",
|
|
181
|
-
justifyContent:
|
|
209
|
+
justifyContent: W.value
|
|
182
210
|
})
|
|
183
211
|
}, [
|
|
184
|
-
|
|
185
|
-
style:
|
|
212
|
+
u(r(ie), {
|
|
213
|
+
style: p([
|
|
186
214
|
n.legendStyle,
|
|
187
215
|
"display: flex; gap: var(--vis-legend-spacing);"
|
|
188
216
|
]),
|
|
@@ -192,23 +220,23 @@ const _ = ["id"], ee = {
|
|
|
192
220
|
}))
|
|
193
221
|
}, null, 8, ["style", "items"])
|
|
194
222
|
], 4)),
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
q("div", oe, [
|
|
224
|
+
r(G).tooltip ? b(i.$slots, "tooltip", {
|
|
197
225
|
key: 0,
|
|
198
|
-
values:
|
|
199
|
-
}) :
|
|
200
|
-
|
|
201
|
-
data:
|
|
226
|
+
values: m.value
|
|
227
|
+
}) : m.value ? b(i.$slots, "fallback", { key: 1 }, () => [
|
|
228
|
+
u(I, {
|
|
229
|
+
data: m.value,
|
|
202
230
|
categories: e.categories,
|
|
203
231
|
"title-formatter": n.tooltipTitleFormatter,
|
|
204
232
|
yFormatter: n.yFormatter
|
|
205
233
|
}, null, 8, ["data", "categories", "title-formatter", "yFormatter"])
|
|
206
|
-
]) :
|
|
234
|
+
]) : y("", !0)
|
|
207
235
|
], 512)
|
|
208
|
-
],
|
|
236
|
+
], 14, ne);
|
|
209
237
|
};
|
|
210
238
|
}
|
|
211
239
|
});
|
|
212
240
|
export {
|
|
213
|
-
|
|
241
|
+
ye as default
|
|
214
242
|
};
|
|
@@ -165,4 +165,9 @@ export interface AreaChartProps<T> {
|
|
|
165
165
|
* The domain for the x-axis, specified as a tuple of two values.
|
|
166
166
|
*/
|
|
167
167
|
xDomain?: [number | undefined, number | undefined];
|
|
168
|
+
/**
|
|
169
|
+
* If `true`, creates a stacked area chart where areas are stacked on top of each other.
|
|
170
|
+
* When false (default), areas are overlaid on top of each other.
|
|
171
|
+
*/
|
|
172
|
+
stacked?: boolean;
|
|
168
173
|
}
|
|
@@ -36,15 +36,16 @@ const g = /* @__PURE__ */ n({
|
|
|
36
36
|
xAxisConfig: {},
|
|
37
37
|
yAxisConfig: {},
|
|
38
38
|
yDomain: {},
|
|
39
|
-
xDomain: {}
|
|
39
|
+
xDomain: {},
|
|
40
|
+
stacked: { type: Boolean }
|
|
40
41
|
},
|
|
41
42
|
setup(o) {
|
|
42
|
-
const
|
|
43
|
-
return a(), (e,
|
|
43
|
+
const t = o;
|
|
44
|
+
return a(), (e, B) => (l(), r(x, p(t, { "hide-area": !0 }), s({ _: 2 }, [
|
|
44
45
|
e.$slots.tooltip ? {
|
|
45
46
|
name: "tooltip",
|
|
46
|
-
fn: y((
|
|
47
|
-
c(e.$slots, "tooltip", m(d(
|
|
47
|
+
fn: y((i) => [
|
|
48
|
+
c(e.$slots, "tooltip", m(d(i)))
|
|
48
49
|
]),
|
|
49
50
|
key: "0"
|
|
50
51
|
} : void 0
|