vue-chrts 0.2.0-beta.1 → 0.2.0-beta.3
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 +19 -19
- package/dist/components/AreaChart/types.d.ts +3 -17
- package/dist/components/BarChart/BarChart.js +77 -102
- package/dist/components/BarChart/BarChart.vue.d.ts +1 -1
- package/dist/components/BarChart/stackedGroupedUtils.d.ts +19 -0
- package/dist/components/BarChart/stackedGroupedUtils.js +67 -0
- package/dist/components/BarChart/types.d.ts +34 -20
- package/dist/components/LineChart/LineChart.js +24 -24
- package/dist/components/LineChart/types.d.ts +3 -17
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +15 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +30 -15
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defineComponent as U, useSlots as j, useTemplateRef as w, ref as R, computed as d, createElementBlock as c, openBlock as a, normalizeClass as T, createVNode as u, createCommentVNode as p, createElementVNode as X, unref as i, withCtx as
|
|
2
|
-
import { Position as
|
|
3
|
-
import { createMarkers as
|
|
4
|
-
import
|
|
5
|
-
import { VisXYContainer as H, VisTooltip as K, VisArea as q, VisLine as J, VisAxis as
|
|
1
|
+
import { defineComponent as U, useSlots as j, useTemplateRef as w, ref as R, computed as d, createElementBlock as c, openBlock as a, normalizeClass as T, createVNode as u, createCommentVNode as p, createElementVNode as X, unref as i, withCtx as S, createBlock as m, Fragment as L, renderList as Y, mergeProps as C, renderSlot as A } from "vue";
|
|
2
|
+
import { Position as b, CurveType as D } from "@unovis/ts";
|
|
3
|
+
import { createMarkers as z, getFirstPropertyValue as I } from "../../utils.js";
|
|
4
|
+
import x from "../Tooltip.js";
|
|
5
|
+
import { VisXYContainer as H, VisTooltip as K, VisArea as q, VisLine as J, VisAxis as B, VisCrosshair as Q, VisBulletLegend as Z } from "@unovis/vue";
|
|
6
6
|
import { LegendPosition as _ } from "../../types.js";
|
|
7
7
|
const ee = {
|
|
8
8
|
ref: "slotWrapper",
|
|
@@ -45,7 +45,7 @@ const ee = {
|
|
|
45
45
|
setup(n, { emit: $ }) {
|
|
46
46
|
const G = $, r = n, O = j(), h = w("slotWrapper"), s = R(), f = d(
|
|
47
47
|
() => Object.values(r.categories).map((e) => e.color)
|
|
48
|
-
), N = d(() => r.markerConfig ?
|
|
48
|
+
), N = d(() => r.markerConfig ? z(r.markerConfig) : ""), g = d(() => r.legendPosition === _.Top), E = d(() => {
|
|
49
49
|
const e = (t, o) => `
|
|
50
50
|
<linearGradient id="gradient${t}-${o}" gradientTransform="rotate(90)">
|
|
51
51
|
<stop offset="0%" stop-color="${o}" stop-opacity="1" />
|
|
@@ -84,30 +84,30 @@ const ee = {
|
|
|
84
84
|
padding: e.padding,
|
|
85
85
|
"svg-defs": E.value + N.value
|
|
86
86
|
}, {
|
|
87
|
-
default:
|
|
87
|
+
default: S(() => [
|
|
88
88
|
e.hideTooltip ? p("", !0) : (a(), m(i(K), {
|
|
89
89
|
key: 0,
|
|
90
|
-
"horizontal-placement": i(
|
|
91
|
-
"vertical-placement": i(
|
|
90
|
+
"horizontal-placement": i(b).Right,
|
|
91
|
+
"vertical-placement": i(b).Top
|
|
92
92
|
}, null, 8, ["horizontal-placement", "vertical-placement"])),
|
|
93
|
-
(a(!0), c(L, null,
|
|
93
|
+
(a(!0), c(L, null, Y(Object.keys(r.categories), (t, o) => (a(), c(L, { key: t }, [
|
|
94
94
|
u(i(q), C({
|
|
95
95
|
x: (k, v) => v
|
|
96
96
|
}, { ref_for: !0 }, P(t), {
|
|
97
97
|
color: `url(#gradient${o}-${f.value[o]})`,
|
|
98
98
|
opacity: te,
|
|
99
|
-
"curve-type": e.curveType ?? i(
|
|
99
|
+
"curve-type": e.curveType ?? i(D).MonotoneX
|
|
100
100
|
}), null, 16, ["x", "color", "curve-type"]),
|
|
101
101
|
u(i(J), {
|
|
102
102
|
x: (k, v) => v,
|
|
103
103
|
y: (k) => k[t],
|
|
104
104
|
color: f.value[o],
|
|
105
|
-
"curve-type": e.curveType ?? i(
|
|
105
|
+
"curve-type": e.curveType ?? i(D).MonotoneX,
|
|
106
106
|
"line-width": e.lineWidth,
|
|
107
|
-
lineDashArray: e.lineDashArray
|
|
107
|
+
lineDashArray: e.lineDashArray ? e.lineDashArray[o] : void 0
|
|
108
108
|
}, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"])
|
|
109
109
|
], 64))), 128)),
|
|
110
|
-
e.hideXAxis ? p("", !0) : (a(), m(i(
|
|
110
|
+
e.hideXAxis ? p("", !0) : (a(), m(i(B), {
|
|
111
111
|
key: 1,
|
|
112
112
|
type: "x",
|
|
113
113
|
label: e.xLabel,
|
|
@@ -120,7 +120,7 @@ const ee = {
|
|
|
120
120
|
"tick-line": e.xTickLine,
|
|
121
121
|
"min-max-ticks-only": e.minMaxTicksOnly
|
|
122
122
|
}, null, 8, ["label", "num-ticks", "tick-format", "tick-values", "grid-line", "domain-line", "tick-line", "min-max-ticks-only"])),
|
|
123
|
-
e.hideYAxis ? p("", !0) : (a(), m(i(
|
|
123
|
+
e.hideYAxis ? p("", !0) : (a(), m(i(B), {
|
|
124
124
|
key: 2,
|
|
125
125
|
type: "y",
|
|
126
126
|
label: e.yLabel,
|
|
@@ -143,14 +143,14 @@ const ee = {
|
|
|
143
143
|
}, null, 8, ["items"])
|
|
144
144
|
], 2)),
|
|
145
145
|
X("div", ee, [
|
|
146
|
-
i(O).tooltip ?
|
|
146
|
+
i(O).tooltip ? A(e.$slots, "tooltip", {
|
|
147
147
|
key: 0,
|
|
148
148
|
values: s.value
|
|
149
|
-
}) : s.value ?
|
|
150
|
-
u(
|
|
149
|
+
}) : s.value ? A(e.$slots, "fallback", { key: 1 }, () => [
|
|
150
|
+
u(x, {
|
|
151
151
|
data: s.value,
|
|
152
152
|
categories: e.categories,
|
|
153
|
-
toolTipTitle: i(
|
|
153
|
+
toolTipTitle: i(I)(s.value) ?? "",
|
|
154
154
|
yFormatter: r.yFormatter
|
|
155
155
|
}, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
|
|
156
156
|
]) : p("", !0)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { axisFormatter, LegendPosition, MarkerConfig } from '../../types';
|
|
1
|
+
import { axisFormatter, CrosshairConfig, LegendPosition, MarkerConfig } from '../../types';
|
|
2
2
|
import { BulletLegendItemInterface, CurveType } from '@unovis/ts';
|
|
3
3
|
export interface AreaChartProps<T> {
|
|
4
4
|
/**
|
|
@@ -64,7 +64,7 @@ export interface AreaChartProps<T> {
|
|
|
64
64
|
/**
|
|
65
65
|
* Line dash array, see SVG's stroke-dasharray. Default: `undefined`
|
|
66
66
|
*/
|
|
67
|
-
lineDashArray?: number[];
|
|
67
|
+
lineDashArray?: number[][];
|
|
68
68
|
/**
|
|
69
69
|
* The desired number of ticks on the x-axis.
|
|
70
70
|
*/
|
|
@@ -129,19 +129,5 @@ export interface AreaChartProps<T> {
|
|
|
129
129
|
/**
|
|
130
130
|
* Crosshair configuration object for customizing the appearance of the crosshair line.
|
|
131
131
|
*/
|
|
132
|
-
crosshairConfig?:
|
|
133
|
-
/**
|
|
134
|
-
* The color of the crosshair line. Accepts any valid CSS color string.
|
|
135
|
-
* Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
|
|
136
|
-
*/
|
|
137
|
-
color?: string;
|
|
138
|
-
/**
|
|
139
|
-
* The stroke color of the crosshair line. Accepts any valid CSS color string.
|
|
140
|
-
*/
|
|
141
|
-
strokeColor?: string;
|
|
142
|
-
/**
|
|
143
|
-
* The stroke width of the crosshair line in pixels.
|
|
144
|
-
*/
|
|
145
|
-
strokeWidth?: number;
|
|
146
|
-
};
|
|
132
|
+
crosshairConfig?: CrosshairConfig;
|
|
147
133
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { Orientation as l, StackedBar as
|
|
3
|
-
import { getFirstPropertyValue as
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
1
|
+
import { defineComponent as C, useSlots as N, useTemplateRef as O, ref as D, computed as T, createElementBlock as m, openBlock as n, normalizeClass as L, createVNode as g, createCommentVNode as c, createElementVNode as w, unref as i, withCtx as E, createBlock as u, Fragment as M, renderList as S, renderSlot as v } from "vue";
|
|
2
|
+
import { Orientation as l, StackedBar as j, GroupedBar as z } from "@unovis/ts";
|
|
3
|
+
import { getFirstPropertyValue as H } from "../../utils.js";
|
|
4
|
+
import { useStackedGrouped as W } from "./stackedGroupedUtils.js";
|
|
5
|
+
import { VisXYContainer as X, VisTooltip as Y, VisStackedBar as B, VisGroupedBar as $, VisAxis as A, VisBulletLegend as R } from "@unovis/vue";
|
|
6
|
+
import q from "../Tooltip.js";
|
|
7
|
+
import { LegendPosition as U } from "../../types.js";
|
|
8
|
+
const I = {
|
|
8
9
|
ref: "slotWrapper",
|
|
9
10
|
class: "hidden"
|
|
10
|
-
},
|
|
11
|
+
}, ae = /* @__PURE__ */ C({
|
|
11
12
|
__name: "BarChart",
|
|
12
13
|
props: {
|
|
13
14
|
data: {},
|
|
14
15
|
stacked: { type: Boolean },
|
|
15
|
-
stackAndGrouped: { type: Boolean },
|
|
16
16
|
height: {},
|
|
17
17
|
xLabel: {},
|
|
18
18
|
yLabel: {},
|
|
@@ -25,9 +25,9 @@ const ee = {
|
|
|
25
25
|
categories: {},
|
|
26
26
|
xFormatter: {},
|
|
27
27
|
yFormatter: {},
|
|
28
|
-
yNumTicks: { default: (
|
|
28
|
+
yNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
|
|
29
29
|
minMaxTicksOnly: { type: Boolean },
|
|
30
|
-
xNumTicks: { default: (
|
|
30
|
+
xNumTicks: { default: (t) => t.data.length > 24 ? 24 / 4 : t.data.length - 1 },
|
|
31
31
|
xExplicitTicks: {},
|
|
32
32
|
yAxis: {},
|
|
33
33
|
groupPadding: {},
|
|
@@ -44,104 +44,79 @@ const ee = {
|
|
|
44
44
|
xGridLine: { type: Boolean },
|
|
45
45
|
yGridLine: { type: Boolean, default: !0 },
|
|
46
46
|
hideXAxis: { type: Boolean },
|
|
47
|
-
hideYAxis: { type: Boolean }
|
|
47
|
+
hideYAxis: { type: Boolean },
|
|
48
|
+
stackAndGrouped: { type: Boolean },
|
|
49
|
+
xAxis: {}
|
|
48
50
|
},
|
|
49
51
|
emits: ["click"],
|
|
50
|
-
setup(
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
52
|
+
setup(t, { emit: V }) {
|
|
53
|
+
const x = V, a = t, P = N(), y = O("slotWrapper"), r = D();
|
|
54
|
+
if (!a.yAxis || a.yAxis.length === 0)
|
|
53
55
|
throw new Error("yAxis is required");
|
|
54
|
-
const
|
|
55
|
-
var
|
|
56
|
-
return (
|
|
57
|
-
},
|
|
58
|
-
|
|
56
|
+
const k = T(() => a.yAxis.map((e) => (d) => d[e])), f = (e, d) => {
|
|
57
|
+
var o;
|
|
58
|
+
return (o = Object.values(a.categories)[d]) == null ? void 0 : o.color;
|
|
59
|
+
}, s = W({
|
|
60
|
+
data: a.data,
|
|
61
|
+
categories: a.categories,
|
|
62
|
+
stackAndGrouped: a.stackAndGrouped,
|
|
63
|
+
xAxis: a.xAxis
|
|
64
|
+
}), h = T(
|
|
65
|
+
() => a.legendPosition === U.Top
|
|
59
66
|
);
|
|
60
|
-
function
|
|
61
|
-
return
|
|
67
|
+
function b(e) {
|
|
68
|
+
return r.value = e, G();
|
|
62
69
|
}
|
|
63
|
-
function
|
|
64
|
-
return typeof window > "u" ? "" :
|
|
70
|
+
function G(e) {
|
|
71
|
+
return typeof window > "u" ? "" : y.value ? y.value.innerHTML : "";
|
|
65
72
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
month: t.month,
|
|
70
|
-
...w.value.flatMap(
|
|
71
|
-
(n) => i.map((c) => ({
|
|
72
|
-
[`${n}${c}`]: t[n][c.toLowerCase()]
|
|
73
|
-
}))
|
|
74
|
-
).reduce((n, c) => ({ ...n, ...c }), {})
|
|
75
|
-
}));
|
|
76
|
-
}, L = u(() => o.stackAndGrouped ? x(o.data) : o.data), M = [
|
|
77
|
-
(e) => e.desktopDone,
|
|
78
|
-
(e) => e.mobileDone,
|
|
79
|
-
(e) => e.androidDone,
|
|
80
|
-
(e) => e.iosDone
|
|
81
|
-
], E = [
|
|
82
|
-
(e) => e.desktopPending,
|
|
83
|
-
(e) => e.mobilePending,
|
|
84
|
-
(e) => e.androidPending,
|
|
85
|
-
(e) => e.iosPending
|
|
86
|
-
];
|
|
87
|
-
return (e, i) => (d(), y("div", {
|
|
88
|
-
class: B(["flex flex-col space-y-4", { "flex-col-reverse": v.value }]),
|
|
89
|
-
onClick: i[0] || (i[0] = (t) => C("click", t, s.value))
|
|
73
|
+
return (e, d) => (n(), m("div", {
|
|
74
|
+
class: L(["flex flex-col space-y-4", { "flex-col-reverse": h.value }]),
|
|
75
|
+
onClick: d[0] || (d[0] = (o) => x("click", o, r.value))
|
|
90
76
|
}, [
|
|
91
|
-
|
|
77
|
+
g(i(X), {
|
|
92
78
|
padding: e.padding,
|
|
93
79
|
height: e.height
|
|
94
80
|
}, {
|
|
95
|
-
default:
|
|
96
|
-
|
|
81
|
+
default: E(() => [
|
|
82
|
+
g(i(Y), {
|
|
97
83
|
triggers: {
|
|
98
|
-
[
|
|
99
|
-
[
|
|
84
|
+
[i(z).selectors.bar]: b,
|
|
85
|
+
[i(j).selectors.bar]: b
|
|
100
86
|
}
|
|
101
87
|
}, null, 8, ["triggers"]),
|
|
102
|
-
e.stackAndGrouped ? (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
p(a(k), {
|
|
114
|
-
data: L.value,
|
|
115
|
-
x: (t, n) => n + 0.2,
|
|
116
|
-
y: E,
|
|
117
|
-
color: N,
|
|
118
|
-
"rounded-corners": e.radius ?? 0,
|
|
119
|
-
"group-padding": e.groupPadding ?? 0,
|
|
120
|
-
"bar-padding": e.barPadding ?? 0.2,
|
|
121
|
-
orientation: e.orientation ?? a(l).Vertical
|
|
122
|
-
}, null, 8, ["data", "x", "rounded-corners", "group-padding", "bar-padding", "orientation"])
|
|
123
|
-
], 64)) : e.stacked ? (d(), m(a(k), {
|
|
88
|
+
e.stackAndGrouped ? (n(!0), m(M, { key: 0 }, S(i(s).states, (o) => (n(), u(i(B), {
|
|
89
|
+
key: o,
|
|
90
|
+
data: i(s).chartData,
|
|
91
|
+
x: (p, F) => F + i(s).positions[o],
|
|
92
|
+
y: i(s).bars[o],
|
|
93
|
+
color: i(s).colorFunctions[o],
|
|
94
|
+
"rounded-corners": e.radius ?? 0,
|
|
95
|
+
"group-padding": e.groupPadding ?? 0,
|
|
96
|
+
"bar-padding": e.barPadding ?? 0.2,
|
|
97
|
+
orientation: e.orientation ?? i(l).Vertical
|
|
98
|
+
}, null, 8, ["data", "x", "y", "color", "rounded-corners", "group-padding", "bar-padding", "orientation"]))), 128)) : e.stacked ? (n(), u(i(B), {
|
|
124
99
|
key: 2,
|
|
125
100
|
data: e.data,
|
|
126
|
-
x: (
|
|
127
|
-
y:
|
|
128
|
-
color:
|
|
101
|
+
x: (o, p) => p,
|
|
102
|
+
y: k.value,
|
|
103
|
+
color: f,
|
|
129
104
|
"rounded-corners": e.radius ?? 0,
|
|
130
105
|
"group-padding": e.groupPadding ?? 0,
|
|
131
106
|
"bar-padding": e.barPadding ?? 0.2,
|
|
132
|
-
orientation: e.orientation ??
|
|
133
|
-
}, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (
|
|
107
|
+
orientation: e.orientation ?? i(l).Vertical
|
|
108
|
+
}, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])) : (n(), u(i($), {
|
|
134
109
|
key: 1,
|
|
135
110
|
data: e.data,
|
|
136
|
-
x: (
|
|
137
|
-
y:
|
|
138
|
-
color:
|
|
111
|
+
x: (o, p) => p,
|
|
112
|
+
y: k.value,
|
|
113
|
+
color: f,
|
|
139
114
|
"rounded-corners": e.radius ?? 0,
|
|
140
115
|
"group-padding": e.groupPadding ?? 0,
|
|
141
116
|
"bar-padding": e.barPadding ?? 0.2,
|
|
142
|
-
orientation: e.orientation ??
|
|
117
|
+
orientation: e.orientation ?? i(l).Vertical
|
|
143
118
|
}, null, 8, ["data", "x", "y", "rounded-corners", "group-padding", "bar-padding", "orientation"])),
|
|
144
|
-
e.hideXAxis ?
|
|
119
|
+
e.hideXAxis ? c("", !0) : (n(), u(i(A), {
|
|
145
120
|
key: 3,
|
|
146
121
|
type: "x",
|
|
147
122
|
"tick-format": e.xFormatter,
|
|
@@ -153,11 +128,11 @@ const ee = {
|
|
|
153
128
|
"tick-values": e.xExplicitTicks,
|
|
154
129
|
minMaxTicksOnly: e.minMaxTicksOnly
|
|
155
130
|
}, null, 8, ["tick-format", "label", "grid-line", "domain-line", "tick-line", "num-ticks", "tick-values", "minMaxTicksOnly"])),
|
|
156
|
-
e.hideYAxis ?
|
|
131
|
+
e.hideYAxis ? c("", !0) : (n(), u(i(A), {
|
|
157
132
|
key: 4,
|
|
158
133
|
type: "y",
|
|
159
134
|
label: e.yLabel,
|
|
160
|
-
"grid-line": e.orientation !==
|
|
135
|
+
"grid-line": e.orientation !== i(l).Horizontal && e.yGridLine,
|
|
161
136
|
"domain-line": !!e.yDomainLine,
|
|
162
137
|
"tick-format": e.yFormatter,
|
|
163
138
|
"num-ticks": e.yNumTicks,
|
|
@@ -166,30 +141,30 @@ const ee = {
|
|
|
166
141
|
]),
|
|
167
142
|
_: 1
|
|
168
143
|
}, 8, ["padding", "height"]),
|
|
169
|
-
e.hideLegend ?
|
|
144
|
+
e.hideLegend ? c("", !0) : (n(), m("div", {
|
|
170
145
|
key: 0,
|
|
171
|
-
class:
|
|
146
|
+
class: L(["flex items center justify-end", { "pb-4": h.value }])
|
|
172
147
|
}, [
|
|
173
|
-
|
|
174
|
-
items: Object.values(
|
|
148
|
+
g(i(R), {
|
|
149
|
+
items: Object.values(a.categories)
|
|
175
150
|
}, null, 8, ["items"])
|
|
176
151
|
], 2)),
|
|
177
|
-
|
|
178
|
-
|
|
152
|
+
w("div", I, [
|
|
153
|
+
i(P).tooltip ? v(e.$slots, "tooltip", {
|
|
179
154
|
key: 0,
|
|
180
|
-
values:
|
|
181
|
-
}) :
|
|
182
|
-
|
|
183
|
-
data:
|
|
184
|
-
categories:
|
|
185
|
-
toolTipTitle:
|
|
186
|
-
yFormatter:
|
|
155
|
+
values: r.value
|
|
156
|
+
}) : r.value ? v(e.$slots, "fallback", { key: 1 }, () => [
|
|
157
|
+
g(q, {
|
|
158
|
+
data: r.value,
|
|
159
|
+
categories: a.categories,
|
|
160
|
+
toolTipTitle: i(H)(r.value) ?? "",
|
|
161
|
+
yFormatter: a.orientation === i(l).Horizontal ? a.xFormatter : a.yFormatter
|
|
187
162
|
}, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
|
|
188
|
-
]) :
|
|
163
|
+
]) : c("", !0)
|
|
189
164
|
], 512)
|
|
190
165
|
], 2));
|
|
191
166
|
}
|
|
192
167
|
});
|
|
193
168
|
export {
|
|
194
|
-
|
|
169
|
+
ae as default
|
|
195
170
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComputedRef } from 'vue';
|
|
2
|
+
export interface StackedGroupedConfig<T> {
|
|
3
|
+
data: T[];
|
|
4
|
+
categories: Record<string, {
|
|
5
|
+
color?: string;
|
|
6
|
+
}>;
|
|
7
|
+
stackAndGrouped: boolean;
|
|
8
|
+
xAxis?: keyof T;
|
|
9
|
+
}
|
|
10
|
+
export interface StackedGroupedResult<T> {
|
|
11
|
+
states: string[];
|
|
12
|
+
groupedByState: Record<string, string[]>;
|
|
13
|
+
colors: Record<string, string[]>;
|
|
14
|
+
bars: Record<string, ((d: any) => any)[]>;
|
|
15
|
+
colorFunctions: Record<string, (d: unknown, i: number) => string>;
|
|
16
|
+
positions: Record<string, number>;
|
|
17
|
+
chartData: T[] | any[];
|
|
18
|
+
}
|
|
19
|
+
export declare function useStackedGrouped<T extends {}>(config: StackedGroupedConfig<T>): ComputedRef<StackedGroupedResult<T>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { computed as u } from "vue";
|
|
2
|
+
import { flattenData as i } from "../../utils.js";
|
|
3
|
+
function b(t) {
|
|
4
|
+
return u(() => {
|
|
5
|
+
const o = f(t.categories), e = l(t.categories, o), r = p(e, t.categories), c = d(e), n = m(r), s = h(o);
|
|
6
|
+
console.log(t, "config");
|
|
7
|
+
const a = t.stackAndGrouped ? i(t.data, t.xAxis) : t.data;
|
|
8
|
+
return {
|
|
9
|
+
states: o,
|
|
10
|
+
groupedByState: e,
|
|
11
|
+
colors: r,
|
|
12
|
+
bars: c,
|
|
13
|
+
colorFunctions: n,
|
|
14
|
+
positions: s,
|
|
15
|
+
chartData: a
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function f(t) {
|
|
20
|
+
const o = /* @__PURE__ */ new Set();
|
|
21
|
+
return Object.keys(t).forEach((r) => {
|
|
22
|
+
const c = r.match(/([A-Z][a-z]+)$/);
|
|
23
|
+
c && o.add(c[1]);
|
|
24
|
+
}), Array.from(o);
|
|
25
|
+
}
|
|
26
|
+
function l(t, o) {
|
|
27
|
+
const e = {};
|
|
28
|
+
return o.forEach((r) => {
|
|
29
|
+
e[r] = Object.keys(t).filter(
|
|
30
|
+
(c) => c.endsWith(r)
|
|
31
|
+
);
|
|
32
|
+
}), e;
|
|
33
|
+
}
|
|
34
|
+
function p(t, o) {
|
|
35
|
+
const e = {};
|
|
36
|
+
return Object.entries(t).forEach(([r, c]) => {
|
|
37
|
+
e[r] = c.map((n) => {
|
|
38
|
+
var s;
|
|
39
|
+
return ((s = o[n]) == null ? void 0 : s.color) ?? "#ccc";
|
|
40
|
+
});
|
|
41
|
+
}), e;
|
|
42
|
+
}
|
|
43
|
+
function d(t) {
|
|
44
|
+
const o = {};
|
|
45
|
+
return Object.entries(t).forEach(([e, r]) => {
|
|
46
|
+
o[e] = r.map((c) => {
|
|
47
|
+
const n = c.replace(e, "").toLowerCase();
|
|
48
|
+
return (s) => s[n + e];
|
|
49
|
+
});
|
|
50
|
+
}), o;
|
|
51
|
+
}
|
|
52
|
+
function m(t) {
|
|
53
|
+
const o = {};
|
|
54
|
+
return Object.entries(t).forEach(([e, r]) => {
|
|
55
|
+
o[e] = (c, n) => r[n] ?? "#ccc";
|
|
56
|
+
}), o;
|
|
57
|
+
}
|
|
58
|
+
function h(t) {
|
|
59
|
+
const o = t.length, e = 0.4, r = {};
|
|
60
|
+
return t.forEach((c, n) => {
|
|
61
|
+
const s = (n - (o - 1) / 2) * e;
|
|
62
|
+
r[c] = s;
|
|
63
|
+
}), r;
|
|
64
|
+
}
|
|
65
|
+
export {
|
|
66
|
+
b as useStackedGrouped
|
|
67
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BulletLegendItemInterface, Orientation, LegendPosition, axisFormatter } from '../../types';
|
|
2
|
-
|
|
2
|
+
type BarChartPropsBase<T> = {
|
|
3
3
|
/**
|
|
4
4
|
* The data to be displayed in the bar chart.
|
|
5
5
|
* Each element of the array represents a data point.
|
|
@@ -10,10 +10,6 @@ export type BarChartProps<T> = {
|
|
|
10
10
|
* If `true`, creates a stacked bar chart instead of grouped bars.
|
|
11
11
|
*/
|
|
12
12
|
stacked?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* If `true`, creates a combination of stacked and grouped bar charts.
|
|
15
|
-
*/
|
|
16
|
-
stackAndGrouped?: boolean;
|
|
17
13
|
/**
|
|
18
14
|
* The height of the chart in pixels.
|
|
19
15
|
*/
|
|
@@ -27,9 +23,9 @@ export type BarChartProps<T> = {
|
|
|
27
23
|
*/
|
|
28
24
|
yLabel?: string;
|
|
29
25
|
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
* Optional padding applied to the chart.
|
|
27
|
+
* Allows specifying individual padding values for the top, right, bottom, and left sides.
|
|
28
|
+
*/
|
|
33
29
|
padding?: {
|
|
34
30
|
top: number;
|
|
35
31
|
right: number;
|
|
@@ -42,18 +38,18 @@ export type BarChartProps<T> = {
|
|
|
42
38
|
*/
|
|
43
39
|
categories: Record<string, BulletLegendItemInterface>;
|
|
44
40
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
* @param {number|Date} tick - The value of the tick. This can be a number or a Date object depending on the scale of the x-axis.
|
|
42
|
+
* @param {number} i - The index of the tick in the `ticks` array.
|
|
43
|
+
* @param {(number[]|Date[])} ticks - An array of all tick values for the x-axis.
|
|
44
|
+
* @returns {string} The formatted string representation of the tick.
|
|
45
|
+
*/
|
|
50
46
|
xFormatter?: axisFormatter;
|
|
51
47
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
48
|
+
* @param {number|Date} tick - The value of the tick. This can be a number or a Date object depending on the scale of the y-axis.
|
|
49
|
+
* @param {number} i - The index of the tick in the `ticks` array.
|
|
50
|
+
* @param {(number[]|Date[])} ticks - An array of all tick values for the y-axis.
|
|
51
|
+
* @returns {string} The formatted string representation of the tick.
|
|
52
|
+
*/
|
|
57
53
|
yFormatter?: axisFormatter;
|
|
58
54
|
/**
|
|
59
55
|
* The desired number of ticks on the y-axis.
|
|
@@ -92,8 +88,8 @@ export type BarChartProps<T> = {
|
|
|
92
88
|
*/
|
|
93
89
|
hideLegend?: boolean;
|
|
94
90
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
* If `true`, hides the chart tooltip.
|
|
92
|
+
*/
|
|
97
93
|
hideTooltip?: boolean;
|
|
98
94
|
/**
|
|
99
95
|
* The orientation of the bars (vertical or horizontal).
|
|
@@ -138,3 +134,21 @@ export type BarChartProps<T> = {
|
|
|
138
134
|
*/
|
|
139
135
|
hideYAxis?: boolean;
|
|
140
136
|
};
|
|
137
|
+
type BarChartPropsStackAndGrouped<T> = BarChartPropsBase<T> & {
|
|
138
|
+
stackAndGrouped: true;
|
|
139
|
+
/**
|
|
140
|
+
* The key in the data object type 'T' to be used for the x-axis values.
|
|
141
|
+
* Required when stackAndGrouped is true.
|
|
142
|
+
*/
|
|
143
|
+
xAxis: keyof T;
|
|
144
|
+
};
|
|
145
|
+
type BarChartPropsNormal<T> = BarChartPropsBase<T> & {
|
|
146
|
+
stackAndGrouped?: false;
|
|
147
|
+
/**
|
|
148
|
+
* The key in the data object type 'T' to be used for the x-axis values.
|
|
149
|
+
* Optional when stackAndGrouped is not true.
|
|
150
|
+
*/
|
|
151
|
+
xAxis?: keyof T;
|
|
152
|
+
};
|
|
153
|
+
export type BarChartProps<T> = BarChartPropsStackAndGrouped<T> | BarChartPropsNormal<T>;
|
|
154
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as P, computed as k, useSlots as
|
|
1
|
+
import { defineComponent as P, computed as k, useSlots as O, useTemplateRef as j, ref as w, createElementBlock as c, openBlock as n, normalizeClass as g, createVNode as s, createCommentVNode as l, createElementVNode as x, unref as i, withCtx as M, createBlock as d, Fragment as W, renderList as E, mergeProps as G, renderSlot as h } from "vue";
|
|
2
2
|
import { Position as v, CurveType as X } from "@unovis/ts";
|
|
3
3
|
import { createMarkers as $, getFirstPropertyValue as z } from "../../utils.js";
|
|
4
4
|
import R from "../Tooltip.js";
|
|
@@ -48,24 +48,24 @@ const J = {
|
|
|
48
48
|
},
|
|
49
49
|
emits: ["click"],
|
|
50
50
|
setup(o, { emit: L }) {
|
|
51
|
-
const C = L, t = o, b = k(() => t.markerConfig ? $(t.markerConfig) : ""), B =
|
|
51
|
+
const C = L, t = o, b = k(() => t.markerConfig ? $(t.markerConfig) : ""), B = O(), p = j("slotWrapper"), a = w();
|
|
52
52
|
function D(e) {
|
|
53
|
-
return typeof window > "u" ? "" :
|
|
53
|
+
return typeof window > "u" ? "" : p.value ? p.value.innerHTML : "";
|
|
54
54
|
}
|
|
55
55
|
function V(e) {
|
|
56
|
-
return
|
|
56
|
+
return a.value = e, D();
|
|
57
57
|
}
|
|
58
|
-
const
|
|
58
|
+
const y = k(
|
|
59
59
|
() => t.legendPosition === I.Top
|
|
60
60
|
), A = Object.values(t.categories).map(
|
|
61
61
|
(e, r) => `var(--vis-color${r})`
|
|
62
62
|
), F = (e) => Object.values(t.categories)[e].color ?? A[e];
|
|
63
|
-
return (e, r) => (n(),
|
|
63
|
+
return (e, r) => (n(), c("div", {
|
|
64
64
|
class: g(["flex flex-col space-y-4", {
|
|
65
|
-
"flex-col-reverse":
|
|
65
|
+
"flex-col-reverse": y.value,
|
|
66
66
|
markers: !!t.markerConfig
|
|
67
67
|
}]),
|
|
68
|
-
onClick: r[0] || (r[0] = (
|
|
68
|
+
onClick: r[0] || (r[0] = (m) => C("click", m, a.value))
|
|
69
69
|
}, [
|
|
70
70
|
s(i(Y), {
|
|
71
71
|
data: e.data,
|
|
@@ -78,16 +78,16 @@ const J = {
|
|
|
78
78
|
"horizontal-placement": i(v).Right,
|
|
79
79
|
"vertical-placement": i(v).Top
|
|
80
80
|
}, null, 8, ["horizontal-placement", "vertical-placement"]),
|
|
81
|
-
(n(!0),
|
|
82
|
-
key:
|
|
81
|
+
(n(!0), c(W, null, E(Object.keys(t.categories), (m, u) => (n(), d(i(H), {
|
|
82
|
+
key: u,
|
|
83
83
|
x: (f, N) => N,
|
|
84
|
-
y: (f) => f[
|
|
85
|
-
color: F(
|
|
84
|
+
y: (f) => f[m],
|
|
85
|
+
color: F(u),
|
|
86
86
|
"curve-type": e.curveType ?? i(X).MonotoneX,
|
|
87
87
|
"line-width": e.lineWidth,
|
|
88
|
-
lineDashArray: e.lineDashArray
|
|
88
|
+
lineDashArray: e.lineDashArray ? e.lineDashArray[u] : void 0
|
|
89
89
|
}, null, 8, ["x", "y", "color", "curve-type", "line-width", "lineDashArray"]))), 128)),
|
|
90
|
-
e.hideXAxis ?
|
|
90
|
+
e.hideXAxis ? l("", !0) : (n(), d(i(T), {
|
|
91
91
|
key: 0,
|
|
92
92
|
type: "x",
|
|
93
93
|
"tick-format": e.xFormatter,
|
|
@@ -100,7 +100,7 @@ const J = {
|
|
|
100
100
|
"tick-values": e.xExplicitTicks,
|
|
101
101
|
"min-max-ticks-only": e.minMaxTicksOnly
|
|
102
102
|
}, null, 8, ["tick-format", "label", "domain-line", "grid-line", "tick-line", "num-ticks", "tick-values", "min-max-ticks-only"])),
|
|
103
|
-
e.hideYAxis ?
|
|
103
|
+
e.hideYAxis ? l("", !0) : (n(), d(i(T), {
|
|
104
104
|
key: 1,
|
|
105
105
|
type: "y",
|
|
106
106
|
"tick-format": e.yFormatter,
|
|
@@ -110,30 +110,30 @@ const J = {
|
|
|
110
110
|
"grid-line": e.yGridLine,
|
|
111
111
|
"tick-line": e.yTickLine
|
|
112
112
|
}, null, 8, ["tick-format", "label", "num-ticks", "domain-line", "grid-line", "tick-line"])),
|
|
113
|
-
e.hideTooltip ?
|
|
113
|
+
e.hideTooltip ? l("", !0) : (n(), d(i(U), G({ key: 2 }, e.crosshairConfig, { template: V }), null, 16))
|
|
114
114
|
]),
|
|
115
115
|
_: 1
|
|
116
116
|
}, 8, ["data", "padding", "height", "svgDefs"]),
|
|
117
|
-
e.hideLegend ?
|
|
117
|
+
e.hideLegend ? l("", !0) : (n(), c("div", {
|
|
118
118
|
key: 0,
|
|
119
|
-
class: g(["flex items center justify-end", { "pb-4":
|
|
119
|
+
class: g(["flex items center justify-end", { "pb-4": y.value }])
|
|
120
120
|
}, [
|
|
121
121
|
s(i(q), {
|
|
122
122
|
items: Object.values(e.categories)
|
|
123
123
|
}, null, 8, ["items"])
|
|
124
124
|
], 2)),
|
|
125
|
-
|
|
125
|
+
x("div", J, [
|
|
126
126
|
i(B).tooltip ? h(e.$slots, "tooltip", {
|
|
127
127
|
key: 0,
|
|
128
|
-
values:
|
|
129
|
-
}) :
|
|
128
|
+
values: a.value
|
|
129
|
+
}) : a.value ? h(e.$slots, "fallback", { key: 1 }, () => [
|
|
130
130
|
s(R, {
|
|
131
|
-
data:
|
|
131
|
+
data: a.value,
|
|
132
132
|
categories: e.categories,
|
|
133
|
-
toolTipTitle: i(z)(
|
|
133
|
+
toolTipTitle: i(z)(a.value) ?? "",
|
|
134
134
|
yFormatter: t.yFormatter
|
|
135
135
|
}, null, 8, ["data", "categories", "toolTipTitle", "yFormatter"])
|
|
136
|
-
]) :
|
|
136
|
+
]) : l("", !0)
|
|
137
137
|
], 512)
|
|
138
138
|
], 2));
|
|
139
139
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { axisFormatter, BulletLegendItemInterface, CurveType, LegendPosition, MarkerConfig } from '../../types';
|
|
1
|
+
import { axisFormatter, BulletLegendItemInterface, CrosshairConfig, CurveType, LegendPosition, MarkerConfig } from '../../types';
|
|
2
2
|
export interface LineChartProps<T> {
|
|
3
3
|
/**
|
|
4
4
|
* The data to be displayed in the line chart.
|
|
@@ -63,7 +63,7 @@ export interface LineChartProps<T> {
|
|
|
63
63
|
/**
|
|
64
64
|
* Line dash array, see SVG's stroke-dasharray. Default: `undefined`
|
|
65
65
|
*/
|
|
66
|
-
lineDashArray?: number[];
|
|
66
|
+
lineDashArray?: number[][];
|
|
67
67
|
/**
|
|
68
68
|
* The desired number of ticks on the x-axis.
|
|
69
69
|
*/
|
|
@@ -128,19 +128,5 @@ export interface LineChartProps<T> {
|
|
|
128
128
|
/**
|
|
129
129
|
* Crosshair configuration object for customizing the appearance of the crosshair line.
|
|
130
130
|
*/
|
|
131
|
-
crosshairConfig?:
|
|
132
|
-
/**
|
|
133
|
-
* The color of the crosshair line. Accepts any valid CSS color string.
|
|
134
|
-
* Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
|
|
135
|
-
*/
|
|
136
|
-
color?: string;
|
|
137
|
-
/**
|
|
138
|
-
* The stroke color of the crosshair line. Accepts any valid CSS color string.
|
|
139
|
-
*/
|
|
140
|
-
strokeColor?: string;
|
|
141
|
-
/**
|
|
142
|
-
* The stroke width of the crosshair line in pixels.
|
|
143
|
-
*/
|
|
144
|
-
strokeWidth?: number;
|
|
145
|
-
};
|
|
131
|
+
crosshairConfig?: CrosshairConfig;
|
|
146
132
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import { default as AreaStackedChart } from './components/AreaStackedChart/AreaS
|
|
|
3
3
|
import { default as LineChart } from './components/LineChart/LineChart.vue';
|
|
4
4
|
import { default as BarChart } from './components/BarChart/BarChart.vue';
|
|
5
5
|
import { default as DonutChart } from './components/DonutChart/DonutChart.vue';
|
|
6
|
-
import { LegendPosition, CurveType, Orientation, BulletLegendItemInterface } from './types';
|
|
6
|
+
import { LegendPosition, CurveType, Orientation, BulletLegendItemInterface, MarkerConfig, CrosshairConfig } from './types';
|
|
7
7
|
export { AreaChart, AreaStackedChart, LineChart, BarChart, DonutChart, Orientation, CurveType, LegendPosition };
|
|
8
|
-
export type { BulletLegendItemInterface, };
|
|
8
|
+
export type { BulletLegendItemInterface, MarkerConfig, CrosshairConfig };
|
package/dist/types.d.ts
CHANGED
|
@@ -48,3 +48,18 @@ export interface MarkerConfig {
|
|
|
48
48
|
color?: string;
|
|
49
49
|
strokeColor?: string;
|
|
50
50
|
}
|
|
51
|
+
export interface CrosshairConfig {
|
|
52
|
+
/**
|
|
53
|
+
* The color of the crosshair line. Accepts any valid CSS color string.
|
|
54
|
+
* Example: '#f00', 'rgba(0,0,0,0.5)', 'blue'
|
|
55
|
+
*/
|
|
56
|
+
color?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The stroke color of the crosshair line. Accepts any valid CSS color string.
|
|
59
|
+
*/
|
|
60
|
+
strokeColor?: string;
|
|
61
|
+
/**
|
|
62
|
+
* The stroke width of the crosshair line in pixels.
|
|
63
|
+
*/
|
|
64
|
+
strokeWidth?: number;
|
|
65
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -3,3 +3,6 @@ export declare function getDistributedIndices(length: number, numTicks: number):
|
|
|
3
3
|
export declare function getFirstPropertyValue(obj: unknown): undefined;
|
|
4
4
|
export declare const markerShape: (type: string, size: number, strokeWidth: number, color: string, strokeColor: string) => string;
|
|
5
5
|
export declare function createMarkers(markerConfig: Record<string, MarkerConfig>): string;
|
|
6
|
+
export declare const flattenData: (data: any[], xAxis: string) => {
|
|
7
|
+
month: any;
|
|
8
|
+
}[];
|
package/dist/utils.js
CHANGED
|
@@ -1,34 +1,49 @@
|
|
|
1
|
-
function
|
|
1
|
+
function o(n) {
|
|
2
2
|
if (n && Object.keys(n).length > 0) {
|
|
3
|
-
const
|
|
4
|
-
return n[
|
|
3
|
+
const e = Object.keys(n)[0];
|
|
4
|
+
return n[e];
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
-
const u = (n, r,
|
|
7
|
+
const u = (n, e, r, t, $) => {
|
|
8
8
|
switch (n) {
|
|
9
9
|
case "circle":
|
|
10
|
-
return `<circle cx="${
|
|
10
|
+
return `<circle cx="${e / 2}" cy="${e / 2}" r="${(e - r) / 2}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
|
|
11
11
|
case "square":
|
|
12
|
-
return `<rect x="${
|
|
12
|
+
return `<rect x="${r / 2}" y="${r / 2}" width="${e - r}" height="${e - r}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
|
|
13
13
|
case "triangle":
|
|
14
|
-
return `<polygon points="${
|
|
14
|
+
return `<polygon points="${e / 2},${r / 2} ${e - r / 2},${e - r / 2} ${r / 2},${e - r / 2}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
|
|
15
15
|
case "diamond":
|
|
16
|
-
return `<polygon points="${
|
|
16
|
+
return `<polygon points="${e / 2},${r / 2} ${e - r / 2},${e / 2} ${e / 2},${e - r / 2} ${r / 2},${e / 2}" stroke-width="${r}" stroke="${$}" fill="${t}" />`;
|
|
17
17
|
default:
|
|
18
18
|
return "";
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
function
|
|
22
|
-
return Object.entries(n).map(([
|
|
23
|
-
const
|
|
24
|
-
return `<marker id="circle-marker-${
|
|
25
|
-
${u(
|
|
21
|
+
function m(n) {
|
|
22
|
+
return Object.entries(n).map(([e, r]) => {
|
|
23
|
+
const t = r.type || "circle", $ = r.size || 10, c = r.strokeWidth || 2, a = r.color || "#000", l = r.strokeColor || r.color || "#000";
|
|
24
|
+
return `<marker id="circle-marker-${e}" viewBox="0 0 ${$} ${$}" refX="${$ / 2}" refY="${$ / 2}" markerWidth="${$ / 2}" markerHeight="${$ / 2}">
|
|
25
|
+
${u(t, $, c, a, l)}
|
|
26
26
|
</marker>`;
|
|
27
27
|
}).join(`
|
|
28
28
|
`);
|
|
29
29
|
}
|
|
30
|
+
function p(n) {
|
|
31
|
+
return n.charAt(0).toUpperCase() + n.slice(1);
|
|
32
|
+
}
|
|
33
|
+
const y = (n, e) => {
|
|
34
|
+
const r = Object.keys(n[0]).filter(($) => $ !== e), t = Object.keys(n[0][r[0]]);
|
|
35
|
+
return n.map(($) => ({
|
|
36
|
+
month: $.month,
|
|
37
|
+
...r.flatMap(
|
|
38
|
+
(c) => t.map((a) => ({
|
|
39
|
+
[`${c}${p(a)}`]: $[c][a]
|
|
40
|
+
}))
|
|
41
|
+
).reduce((c, a) => ({ ...c, ...a }), {})
|
|
42
|
+
}));
|
|
43
|
+
};
|
|
30
44
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
m as createMarkers,
|
|
46
|
+
y as flattenData,
|
|
47
|
+
o as getFirstPropertyValue,
|
|
33
48
|
u as markerShape
|
|
34
49
|
};
|