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