vue-chrts 0.2.0-beta.1 → 0.2.0-beta.2
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/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/utils.d.ts +3 -0
- package/dist/utils.js +30 -15
- package/package.json +1 -1
|
@@ -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 {};
|
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
|
};
|