x-next 1.7.0 → 1.8.0
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/AI_USAGE.md +129 -4
- package/CHANGELOG.md +38 -0
- package/dist/_hooks/use-chart-size.d.ts +25 -0
- package/dist/_utils/chart/index.d.ts +6 -0
- package/dist/_utils/chart/padding.d.ts +15 -0
- package/dist/_utils/chart/path.d.ts +34 -0
- package/dist/_utils/chart/scale.d.ts +55 -0
- package/dist/components/_components/chart/ChartAxis.d.ts +85 -0
- package/dist/components/_components/chart/ChartLegend.d.ts +26 -0
- package/dist/components/_components/chart/ChartTooltip.d.ts +76 -0
- package/dist/components/_components/chart/colors.d.ts +10 -0
- package/dist/components/_components/chart/interface.d.ts +38 -0
- package/dist/components/bar-chart/BarChart.d.ts +278 -0
- package/dist/components/bar-chart/helpers/layout.d.ts +55 -0
- package/dist/components/bar-chart/index.d.ts +600 -0
- package/dist/components/bar-chart/interface.d.ts +74 -0
- package/dist/components/bar-chart/props.d.ts +145 -0
- package/dist/components/heatmap/Heatmap.d.ts +10 -0
- package/dist/components/heatmap/index.d.ts +30 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/line-chart/LineChart.d.ts +295 -0
- package/dist/components/line-chart/helpers/layout.d.ts +74 -0
- package/dist/components/line-chart/index.d.ts +614 -0
- package/dist/components/line-chart/interface.d.ts +76 -0
- package/dist/components/line-chart/props.d.ts +173 -0
- package/dist/components/pie-chart/PieChart.d.ts +219 -0
- package/dist/components/pie-chart/index.d.ts +470 -0
- package/dist/components/pie-chart/interface.d.ts +58 -0
- package/dist/components/pie-chart/props.d.ts +107 -0
- package/dist/components/trend-chart/components/TrendChart.d.ts +19 -96
- package/dist/components/trend-chart/index.d.ts +33 -187
- package/dist/components/trend-chart/props.d.ts +9 -78
- package/dist/components/trend-chart/themes.d.ts +0 -1
- package/dist/es/_hooks/use-chart-size.js +25 -0
- package/dist/es/_styles/palette-aliases.js +5 -0
- package/dist/es/_utils/chart/padding.js +22 -0
- package/dist/es/_utils/chart/path.js +69 -0
- package/dist/es/_utils/chart/scale.js +77 -0
- package/dist/es/components/_components/chart/ChartAxis.js +79 -0
- package/dist/es/components/_components/chart/ChartLegend.js +53 -0
- package/dist/es/components/_components/chart/ChartTooltip.js +64 -0
- package/dist/es/components/_components/chart/colors.js +12 -0
- package/dist/es/components/bar-chart/BarChart.js +470 -0
- package/dist/es/components/bar-chart/helpers/layout.js +53 -0
- package/dist/es/components/bar-chart/index.js +8 -0
- package/dist/es/components/bar-chart/props.js +148 -0
- package/dist/es/components/heatmap/Heatmap.js +244 -169
- package/dist/es/components/index.js +132 -126
- package/dist/es/components/line-chart/LineChart.js +532 -0
- package/dist/es/components/line-chart/helpers/layout.js +80 -0
- package/dist/es/components/line-chart/index.js +8 -0
- package/dist/es/components/line-chart/props.js +178 -0
- package/dist/es/components/pie-chart/PieChart.js +397 -0
- package/dist/es/components/pie-chart/index.js +8 -0
- package/dist/es/components/pie-chart/props.js +104 -0
- package/dist/es/components/trend-chart/components/TrendChart.js +143 -183
- package/dist/es/components/trend-chart/components/trend-chart-curve.js +85 -81
- package/dist/es/components/trend-chart/props.js +28 -74
- package/dist/es/components/trend-chart/themes.js +30 -31
- package/dist/es/index.js +193 -187
- package/dist/es/locale/en-US.js +8 -1
- package/dist/es/locale/zh-CN.js +8 -1
- package/dist/es/style.css +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.umd.js +4 -4
- package/dist/locale/interface.d.ts +13 -0
- package/dist/style/bar-chart.css +1 -0
- package/dist/style/bar-chart.js +2 -0
- package/dist/style/base.css +1 -1
- package/dist/style/heatmap.css +1 -1
- package/dist/style/line-chart.css +1 -0
- package/dist/style/line-chart.js +2 -0
- package/dist/style/pie-chart.css +1 -0
- package/dist/style/pie-chart.js +2 -0
- package/dist/style.css +1 -1
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
- package/volar.d.ts +3 -0
- package/dist/components/trend-chart/components/trend-chart-grid.d.ts +0 -55
- package/dist/components/trend-chart/components/trend-chart-labels.d.ts +0 -26
- package/dist/components/trend-chart/helpers/genPath.d.ts +0 -8
- package/dist/components/trend-chart/helpers/getPadding.d.ts +0 -8
- package/dist/components/trend-chart/helpers/validatePadding.d.ts +0 -2
- package/dist/es/components/trend-chart/components/trend-chart-grid.js +0 -62
- package/dist/es/components/trend-chart/components/trend-chart-labels.js +0 -75
- package/dist/es/components/trend-chart/helpers/genPath.js +0 -22
- package/dist/es/components/trend-chart/helpers/getPadding.js +0 -21
- package/dist/es/components/trend-chart/helpers/validatePadding.js +0 -7
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
import { defineComponent as Le, createVNode as v, mergeProps as Ce, Fragment as Te, ref as re, reactive as Ae, computed as i, watch as de, nextTick as Se } from "vue";
|
|
2
|
+
import { getComponentPrefix as Ee, getClassNameMixin as Ne } from "../../_utils/config.js";
|
|
3
|
+
import { useLocale as Ve } from "../../locale/index.js";
|
|
4
|
+
import { isObject as Pe } from "../../_utils/is.js";
|
|
5
|
+
import { useChartSize as ze } from "../../_hooks/use-chart-size.js";
|
|
6
|
+
import { getSeriesColor as Fe } from "../_components/chart/colors.js";
|
|
7
|
+
import { Spin as _e } from "../spin/index.js";
|
|
8
|
+
import De from "../_components/chart/ChartAxis.js";
|
|
9
|
+
import $e from "../_components/chart/ChartLegend.js";
|
|
10
|
+
import Oe from "../_components/chart/ChartTooltip.js";
|
|
11
|
+
import { lineChartProps as Re } from "./props.js";
|
|
12
|
+
import { buildStackedLayers as We, buildLineChartSeries as ve } from "./helpers/layout.js";
|
|
13
|
+
import { getDomain as He, estimateTextWidth as he, pickLabelIndices as Xe } from "../../_utils/chart/scale.js";
|
|
14
|
+
import { getPadding as Ye } from "../../_utils/chart/padding.js";
|
|
15
|
+
const Be = 4, me = 10, je = 60, ot = /* @__PURE__ */ Le({
|
|
16
|
+
name: Ee("LineChart"),
|
|
17
|
+
props: Re,
|
|
18
|
+
emits: {
|
|
19
|
+
/**
|
|
20
|
+
* @zh 点击数据点或绘图区时触发
|
|
21
|
+
* @en Emitted when a data point or the plot area is clicked
|
|
22
|
+
*/
|
|
23
|
+
"line-click": (a) => !0,
|
|
24
|
+
/**
|
|
25
|
+
* @zh 图例切换后触发,参数为当前可见的系列下标
|
|
26
|
+
* @en Emitted after a legend toggle, with the visible series indexes
|
|
27
|
+
*/
|
|
28
|
+
"legend-change": (a) => !0
|
|
29
|
+
},
|
|
30
|
+
slots: Object,
|
|
31
|
+
setup(a, {
|
|
32
|
+
emit: I,
|
|
33
|
+
slots: W
|
|
34
|
+
}) {
|
|
35
|
+
const {
|
|
36
|
+
t: w
|
|
37
|
+
} = Ve(), h = Ne("line-chart"), Q = re(null), H = re(null), F = re(null), Z = {
|
|
38
|
+
root: Q,
|
|
39
|
+
canvas: H,
|
|
40
|
+
tooltip: F
|
|
41
|
+
}, s = Ae({
|
|
42
|
+
activeIndex: null,
|
|
43
|
+
/** 键盘导航触发的激活态才做读屏播报,鼠标悬浮不播报 */
|
|
44
|
+
keyboardActive: !1,
|
|
45
|
+
hiddenIndexes: [],
|
|
46
|
+
tooltipWidth: 0
|
|
47
|
+
}), {
|
|
48
|
+
size: T
|
|
49
|
+
} = ze({
|
|
50
|
+
elementRef: H,
|
|
51
|
+
width: () => a.width,
|
|
52
|
+
height: () => a.height
|
|
53
|
+
}), y = i(() => {
|
|
54
|
+
var e;
|
|
55
|
+
return ((e = a.labels) == null ? void 0 : e.fontSize) ?? 12;
|
|
56
|
+
}), _ = i(() => {
|
|
57
|
+
var e;
|
|
58
|
+
return ((e = a.labels) == null ? void 0 : e.yVisible) !== !1;
|
|
59
|
+
}), X = i(() => {
|
|
60
|
+
var e;
|
|
61
|
+
return ((e = a.labels) == null ? void 0 : e.xVisible) !== !1;
|
|
62
|
+
}), p = i(() => {
|
|
63
|
+
var e;
|
|
64
|
+
return Math.max(2, Math.floor(((e = a.grid) == null ? void 0 : e.horizontalLinesNumber) ?? Be));
|
|
65
|
+
}), Y = i(() => {
|
|
66
|
+
var e;
|
|
67
|
+
return ((e = a.grid) == null ? void 0 : e.horizontalLines) !== !1;
|
|
68
|
+
}), x = i(() => a.series ?? []), B = i(() => (a.categories ?? []).map((e) => String(e))), k = i(() => x.value.length), b = i(() => k.value === 0 ? [] : Array.from({
|
|
69
|
+
length: k.value
|
|
70
|
+
}, (e, t) => t).filter((e) => !s.hiddenIndexes.includes(e))), c = i(() => {
|
|
71
|
+
const e = x.value.reduce((t, n) => Math.max(t, (n.data ?? []).length), 0);
|
|
72
|
+
return Math.max(B.value.length, e);
|
|
73
|
+
}), A = i(() => x.value.map((e) => {
|
|
74
|
+
const t = e.data ?? [];
|
|
75
|
+
return Array.from({
|
|
76
|
+
length: c.value
|
|
77
|
+
}, (n, l) => {
|
|
78
|
+
const r = t[l];
|
|
79
|
+
return Number.isFinite(r) ? r : null;
|
|
80
|
+
});
|
|
81
|
+
})), D = i(() => b.value.map((e) => A.value[e] ?? [])), S = i(() => a.stack ? We(D.value) : []), $ = i(() => {
|
|
82
|
+
if (!a.stack) return D.value;
|
|
83
|
+
const e = [];
|
|
84
|
+
return S.value.forEach((t) => {
|
|
85
|
+
e.push(t.base.map((n) => n)), e.push(t.top.map((n) => n));
|
|
86
|
+
}), e;
|
|
87
|
+
}), j = i(() => A.value.some((e) => e.some((t) => t !== null))), K = i(() => {
|
|
88
|
+
let e = 0, t = 0;
|
|
89
|
+
return $.value.forEach((n) => {
|
|
90
|
+
n.forEach((l) => {
|
|
91
|
+
l === null || !Number.isFinite(l) || (l < e && (e = l), l > t && (t = l));
|
|
92
|
+
});
|
|
93
|
+
}), {
|
|
94
|
+
min: e,
|
|
95
|
+
max: t
|
|
96
|
+
};
|
|
97
|
+
}), g = i(() => He(K.value.min, K.value.max, p.value, a.min, a.max)), M = i(() => a.valueFormatter), G = (e) => {
|
|
98
|
+
var t;
|
|
99
|
+
return (t = a.labels) != null && t.yFormatter ? a.labels.yFormatter(e) : M.value(e);
|
|
100
|
+
}, ee = i(() => {
|
|
101
|
+
var e;
|
|
102
|
+
return ((e = a.labels) == null ? void 0 : e.color) ?? "var(--x-chart-color-axis-text)";
|
|
103
|
+
}), L = (e) => {
|
|
104
|
+
var n;
|
|
105
|
+
const t = B.value[e] ?? String(e + 1);
|
|
106
|
+
return (n = a.labels) != null && n.xFormatter ? a.labels.xFormatter(t, e) : t;
|
|
107
|
+
}, te = i(() => {
|
|
108
|
+
if (!_.value) return 0;
|
|
109
|
+
const e = g.value.ticks, t = e.reduce((n, l) => Math.max(n, he(G(l), y.value)), 0);
|
|
110
|
+
return e.length ? Math.round(t) + 6 : 0;
|
|
111
|
+
}), ne = i(() => !X.value || c.value === 0 ? 0 : Math.ceil(8 + y.value * 1.15)), f = i(() => {
|
|
112
|
+
const e = Ye(a.padding), t = _.value ? Math.ceil(y.value * 0.7) : 0, n = e.left + te.value, l = Math.max(e.top, t), r = T.width - e.right, d = T.height - e.bottom - ne.value;
|
|
113
|
+
return {
|
|
114
|
+
left: n,
|
|
115
|
+
top: l,
|
|
116
|
+
right: r,
|
|
117
|
+
bottom: d,
|
|
118
|
+
width: Math.max(0, r - n),
|
|
119
|
+
height: Math.max(0, d - l)
|
|
120
|
+
};
|
|
121
|
+
}), U = (e) => {
|
|
122
|
+
const {
|
|
123
|
+
min: t,
|
|
124
|
+
max: n
|
|
125
|
+
} = g.value, l = n - t;
|
|
126
|
+
if (l <= 0) return f.value.bottom;
|
|
127
|
+
const r = (e - t) / l;
|
|
128
|
+
return f.value.bottom - Math.min(1, Math.max(0, r)) * f.value.height;
|
|
129
|
+
}, E = i(() => U(Math.max(0, g.value.min))), N = i(() => a.stack ? ve({
|
|
130
|
+
values: S.value.map((e) => e.top),
|
|
131
|
+
lower: S.value.map((e) => e.base),
|
|
132
|
+
plot: f.value,
|
|
133
|
+
domainMin: g.value.min,
|
|
134
|
+
domainMax: g.value.max,
|
|
135
|
+
smooth: a.smooth,
|
|
136
|
+
connectNulls: !1,
|
|
137
|
+
area: a.area,
|
|
138
|
+
baseline: E.value
|
|
139
|
+
}) : ve({
|
|
140
|
+
values: D.value,
|
|
141
|
+
plot: f.value,
|
|
142
|
+
domainMin: g.value.min,
|
|
143
|
+
domainMax: g.value.max,
|
|
144
|
+
smooth: a.smooth,
|
|
145
|
+
connectNulls: a.connectNulls,
|
|
146
|
+
area: a.area,
|
|
147
|
+
baseline: E.value
|
|
148
|
+
})), V = (e) => {
|
|
149
|
+
var t;
|
|
150
|
+
return ((t = x.value[e]) == null ? void 0 : t.color) ?? Fe(e);
|
|
151
|
+
}, le = i(() => {
|
|
152
|
+
if (c.value === 0) return [];
|
|
153
|
+
const e = f.value.width / c.value, t = Array.from({
|
|
154
|
+
length: c.value
|
|
155
|
+
}, (n, l) => he(L(l), y.value)).reduce((n, l) => Math.max(n, l), 0);
|
|
156
|
+
return Xe(c.value, e, t, y.value * 0.6);
|
|
157
|
+
}), ae = i(() => g.value.ticks.map((e) => ({
|
|
158
|
+
y: U(e),
|
|
159
|
+
label: G(e),
|
|
160
|
+
isBaseline: e === 0
|
|
161
|
+
}))), q = i(() => {
|
|
162
|
+
const e = c.value > 0 ? f.value.width / c.value : 0;
|
|
163
|
+
return Array.from({
|
|
164
|
+
length: c.value
|
|
165
|
+
}, (t, n) => f.value.left + e * (n + 0.5));
|
|
166
|
+
}), ie = i(() => le.value.map((e) => ({
|
|
167
|
+
x: q.value[e] ?? 0,
|
|
168
|
+
text: L(e)
|
|
169
|
+
}))), u = i(() => a.showPoints === !0 ? !0 : a.showPoints === !1 ? !1 : N.value.reduce((e, t) => e + t.points.length, 0) <= je), o = i(() => {
|
|
170
|
+
const e = s.activeIndex;
|
|
171
|
+
if (e === null || e < 0 || e >= c.value) return null;
|
|
172
|
+
const t = b.value.map((l) => {
|
|
173
|
+
var r, d, m;
|
|
174
|
+
return {
|
|
175
|
+
seriesIndex: l,
|
|
176
|
+
name: (r = x.value[l]) == null ? void 0 : r.name,
|
|
177
|
+
value: a.stack ? ((d = S.value[b.value.indexOf(l)]) == null ? void 0 : d.values[e]) ?? null : ((m = A.value[l]) == null ? void 0 : m[e]) ?? null,
|
|
178
|
+
color: V(l)
|
|
179
|
+
};
|
|
180
|
+
}).filter((l) => l.value !== null || b.value.length === 1), n = t.reduce((l, r) => l + (r.value ?? 0), 0);
|
|
181
|
+
return {
|
|
182
|
+
index: e,
|
|
183
|
+
label: L(e),
|
|
184
|
+
items: t,
|
|
185
|
+
total: n
|
|
186
|
+
};
|
|
187
|
+
}), P = i(() => {
|
|
188
|
+
const e = o.value;
|
|
189
|
+
return e ? {
|
|
190
|
+
...e,
|
|
191
|
+
formatValue: M.value
|
|
192
|
+
} : null;
|
|
193
|
+
}), O = i(() => {
|
|
194
|
+
var e;
|
|
195
|
+
return (((e = o.value) == null ? void 0 : e.items) ?? []).map((t) => ({
|
|
196
|
+
key: t.seriesIndex,
|
|
197
|
+
name: t.name ?? se(t.seriesIndex),
|
|
198
|
+
value: t.value === null ? "-" : M.value(t.value),
|
|
199
|
+
color: t.color
|
|
200
|
+
}));
|
|
201
|
+
}), fe = i(() => {
|
|
202
|
+
const e = o.value;
|
|
203
|
+
return !e || e.items.length <= 1 || !e.items.some((n) => n.value !== null) ? null : {
|
|
204
|
+
label: w("chart.total"),
|
|
205
|
+
value: M.value(e.total)
|
|
206
|
+
};
|
|
207
|
+
}), xe = i(() => {
|
|
208
|
+
const e = o.value;
|
|
209
|
+
if (!e) return {};
|
|
210
|
+
const t = s.tooltipWidth / 2 || 0, n = q.value[e.index] ?? 0, l = t + 4, r = Math.max(l, T.width - t - 4), d = Math.min(Math.max(n, l), r);
|
|
211
|
+
let m = f.value.bottom;
|
|
212
|
+
N.value.forEach((J) => {
|
|
213
|
+
const R = J.points.find((z) => z.index === e.index);
|
|
214
|
+
R && R.y < m && (m = R.y);
|
|
215
|
+
});
|
|
216
|
+
const C = Math.max(me, m - me);
|
|
217
|
+
return {
|
|
218
|
+
left: `${d}px`,
|
|
219
|
+
top: `${C}px`
|
|
220
|
+
};
|
|
221
|
+
}), se = (e) => {
|
|
222
|
+
var t;
|
|
223
|
+
return ((t = x.value[e]) == null ? void 0 : t.name) ?? w("chart.seriesName", {
|
|
224
|
+
index: e + 1
|
|
225
|
+
});
|
|
226
|
+
}, ge = i(() => x.value.map((e, t) => ({
|
|
227
|
+
key: t,
|
|
228
|
+
name: se(t),
|
|
229
|
+
color: V(t),
|
|
230
|
+
hidden: s.hiddenIndexes.includes(t)
|
|
231
|
+
})));
|
|
232
|
+
de(() => [c.value, k.value], () => {
|
|
233
|
+
s.activeIndex !== null && s.activeIndex >= c.value && (s.activeIndex = null), s.hiddenIndexes = s.hiddenIndexes.filter((e) => e < k.value);
|
|
234
|
+
}), de(() => s.activeIndex, (e) => {
|
|
235
|
+
e !== null && Se(() => {
|
|
236
|
+
var n;
|
|
237
|
+
const t = ((n = F.value) == null ? void 0 : n.offsetWidth) ?? 0;
|
|
238
|
+
t !== s.tooltipWidth && (s.tooltipWidth = t);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
const oe = (e) => {
|
|
242
|
+
const {
|
|
243
|
+
left: t,
|
|
244
|
+
width: n
|
|
245
|
+
} = f.value;
|
|
246
|
+
if (n <= 0 || e < t || e > t + n) return null;
|
|
247
|
+
const l = n / c.value;
|
|
248
|
+
return Math.min(c.value - 1, Math.max(0, Math.floor((e - t) / l)));
|
|
249
|
+
}, be = (e) => {
|
|
250
|
+
var J;
|
|
251
|
+
const t = e.currentTarget.getBoundingClientRect(), n = e.clientY - t.top, l = e.target, r = (J = l == null ? void 0 : l.closest) == null ? void 0 : J.call(l, "[data-line-point]");
|
|
252
|
+
if (r)
|
|
253
|
+
return {
|
|
254
|
+
seriesIndex: Number(r.getAttribute("data-line-series")),
|
|
255
|
+
value: Number(r.getAttribute("data-line-value"))
|
|
256
|
+
};
|
|
257
|
+
const d = oe(e.clientX - t.left);
|
|
258
|
+
if (d === null) return {
|
|
259
|
+
seriesIndex: null,
|
|
260
|
+
value: null
|
|
261
|
+
};
|
|
262
|
+
let m = null, C = Number.POSITIVE_INFINITY;
|
|
263
|
+
return N.value.forEach((R) => {
|
|
264
|
+
const z = R.points.find((ke) => ke.index === d);
|
|
265
|
+
if (!z) return;
|
|
266
|
+
const ce = Math.abs(z.y - n);
|
|
267
|
+
ce < C && (C = ce, m = {
|
|
268
|
+
seriesIndex: z.seriesIndex,
|
|
269
|
+
value: z.value
|
|
270
|
+
});
|
|
271
|
+
}), m ?? {
|
|
272
|
+
seriesIndex: null,
|
|
273
|
+
value: null
|
|
274
|
+
};
|
|
275
|
+
}, Ie = (e) => {
|
|
276
|
+
if (!a.tooltip || !j.value) return;
|
|
277
|
+
const t = e.currentTarget.getBoundingClientRect();
|
|
278
|
+
s.keyboardActive = !1, s.activeIndex = oe(e.clientX - t.left);
|
|
279
|
+
}, ue = () => {
|
|
280
|
+
s.activeIndex = null, s.keyboardActive = !1;
|
|
281
|
+
}, ye = (e) => {
|
|
282
|
+
const t = oe(e.clientX - e.currentTarget.getBoundingClientRect().left);
|
|
283
|
+
if (t === null) return;
|
|
284
|
+
const n = be(e), l = o.value, r = (l == null ? void 0 : l.index) === t ? l.items : b.value.map((d) => {
|
|
285
|
+
var m, C;
|
|
286
|
+
return {
|
|
287
|
+
seriesIndex: d,
|
|
288
|
+
name: (m = x.value[d]) == null ? void 0 : m.name,
|
|
289
|
+
value: ((C = A.value[d]) == null ? void 0 : C[t]) ?? null,
|
|
290
|
+
color: V(d)
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
I("line-click", {
|
|
294
|
+
index: t,
|
|
295
|
+
label: L(t),
|
|
296
|
+
items: r,
|
|
297
|
+
total: r.reduce((d, m) => d + (m.value ?? 0), 0),
|
|
298
|
+
seriesIndex: n.seriesIndex,
|
|
299
|
+
value: n.value
|
|
300
|
+
});
|
|
301
|
+
}, pe = (e) => {
|
|
302
|
+
if (!a.tooltip) return;
|
|
303
|
+
const t = c.value - 1;
|
|
304
|
+
if (t < 0) return;
|
|
305
|
+
let n = null;
|
|
306
|
+
if (e.key === "ArrowRight") n = Math.min(t, (s.activeIndex ?? -1) + 1);
|
|
307
|
+
else if (e.key === "ArrowLeft") n = Math.max(0, (s.activeIndex ?? t + 1) - 1);
|
|
308
|
+
else if (e.key === "Home") n = 0;
|
|
309
|
+
else if (e.key === "End") n = t;
|
|
310
|
+
else if (e.key === "Escape") {
|
|
311
|
+
ue();
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
n !== null && (e.preventDefault(), s.keyboardActive = !0, s.activeIndex = n);
|
|
315
|
+
}, Me = (e) => {
|
|
316
|
+
const t = s.hiddenIndexes.includes(e) ? s.hiddenIndexes.filter((n) => n !== e) : [...s.hiddenIndexes, e];
|
|
317
|
+
s.hiddenIndexes = t, I("legend-change", Array.from({
|
|
318
|
+
length: k.value
|
|
319
|
+
}, (n, l) => l).filter((n) => !t.includes(n)));
|
|
320
|
+
}, we = i(() => {
|
|
321
|
+
const e = o.value;
|
|
322
|
+
if (!s.keyboardActive || !e) return "";
|
|
323
|
+
const t = e.items.map((n) => {
|
|
324
|
+
const l = n.name ?? se(n.seriesIndex), r = n.value === null ? w("common.noData") : M.value(n.value);
|
|
325
|
+
return `${l} ${r}`;
|
|
326
|
+
});
|
|
327
|
+
return `${e.label}:${t.join(",")}`;
|
|
328
|
+
});
|
|
329
|
+
return {
|
|
330
|
+
className: h,
|
|
331
|
+
state: s,
|
|
332
|
+
size: T,
|
|
333
|
+
refs: Z,
|
|
334
|
+
slots: W,
|
|
335
|
+
t: w,
|
|
336
|
+
fontSize: y,
|
|
337
|
+
labelColor: ee,
|
|
338
|
+
yVisible: _,
|
|
339
|
+
xVisible: X,
|
|
340
|
+
showHorizontalLines: Y,
|
|
341
|
+
seriesList: x,
|
|
342
|
+
visibleSeriesIndexes: b,
|
|
343
|
+
categoryCount: c,
|
|
344
|
+
hasData: j,
|
|
345
|
+
plot: f,
|
|
346
|
+
domain: g,
|
|
347
|
+
seriesPaths: N,
|
|
348
|
+
pointsAlwaysVisible: u,
|
|
349
|
+
axisTicks: ae,
|
|
350
|
+
axisXLabels: ie,
|
|
351
|
+
activeCategory: o,
|
|
352
|
+
tooltipSlotProps: P,
|
|
353
|
+
tooltipEntries: O,
|
|
354
|
+
tooltipTotal: fe,
|
|
355
|
+
tooltipStyle: xe,
|
|
356
|
+
legendItems: ge,
|
|
357
|
+
categoryLabel: L,
|
|
358
|
+
formatValue: M,
|
|
359
|
+
seriesColor: V,
|
|
360
|
+
liveText: we,
|
|
361
|
+
handleMouseMove: Ie,
|
|
362
|
+
handleClick: ye,
|
|
363
|
+
handleKeydown: pe,
|
|
364
|
+
clearActive: ue,
|
|
365
|
+
toggleSeries: Me,
|
|
366
|
+
setTooltipElement: (e) => {
|
|
367
|
+
F.value = e;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
},
|
|
371
|
+
render() {
|
|
372
|
+
const {
|
|
373
|
+
className: a,
|
|
374
|
+
state: I,
|
|
375
|
+
size: W,
|
|
376
|
+
refs: w,
|
|
377
|
+
slots: h,
|
|
378
|
+
t: Q,
|
|
379
|
+
fontSize: H,
|
|
380
|
+
labelColor: F,
|
|
381
|
+
yVisible: Z,
|
|
382
|
+
xVisible: s,
|
|
383
|
+
showHorizontalLines: T,
|
|
384
|
+
seriesList: y,
|
|
385
|
+
visibleSeriesIndexes: _,
|
|
386
|
+
hasData: X,
|
|
387
|
+
plot: p,
|
|
388
|
+
seriesPaths: Y,
|
|
389
|
+
pointsAlwaysVisible: x,
|
|
390
|
+
axisTicks: B,
|
|
391
|
+
axisXLabels: k,
|
|
392
|
+
tooltipSlotProps: b,
|
|
393
|
+
tooltipEntries: c,
|
|
394
|
+
tooltipTotal: A,
|
|
395
|
+
tooltipStyle: D,
|
|
396
|
+
legendItems: S,
|
|
397
|
+
seriesColor: $,
|
|
398
|
+
liveText: j,
|
|
399
|
+
handleMouseMove: K,
|
|
400
|
+
handleClick: g,
|
|
401
|
+
handleKeydown: M,
|
|
402
|
+
clearActive: G,
|
|
403
|
+
toggleSeries: ee,
|
|
404
|
+
setTooltipElement: L,
|
|
405
|
+
categoryCount: te,
|
|
406
|
+
area: ne
|
|
407
|
+
} = this, f = typeof this.width == "number" ? `${this.width}px` : this.width, U = typeof this.height == "number" ? `${this.height}px` : this.height, E = W.width > 0 && W.height > 0 && p.width > 0, N = () => Y.map((u) => {
|
|
408
|
+
const o = $(u.seriesIndex), P = I.activeIndex !== null && u.points.some((O) => O.index === I.activeIndex);
|
|
409
|
+
return v("g", {
|
|
410
|
+
key: u.seriesIndex,
|
|
411
|
+
class: [a.element("series"), {
|
|
412
|
+
[a.is("active")]: P
|
|
413
|
+
}],
|
|
414
|
+
"data-line-series": u.seriesIndex
|
|
415
|
+
}, [ne && u.areaD && v("path", {
|
|
416
|
+
class: a.element("area"),
|
|
417
|
+
d: u.areaD,
|
|
418
|
+
fill: o,
|
|
419
|
+
"data-line-area": u.seriesIndex
|
|
420
|
+
}, null), v("path", {
|
|
421
|
+
class: a.element("line"),
|
|
422
|
+
d: u.d,
|
|
423
|
+
fill: "none",
|
|
424
|
+
stroke: o
|
|
425
|
+
}, null)]);
|
|
426
|
+
}), V = () => !E || x === !1 ? null : v("g", {
|
|
427
|
+
class: a.element("points")
|
|
428
|
+
}, [Y.flatMap((u) => u.points.map((o) => {
|
|
429
|
+
const P = I.activeIndex === o.index, O = h.point ? h.point({
|
|
430
|
+
seriesIndex: o.seriesIndex,
|
|
431
|
+
index: o.index,
|
|
432
|
+
value: o.value,
|
|
433
|
+
x: o.x,
|
|
434
|
+
y: o.y,
|
|
435
|
+
color: $(o.seriesIndex)
|
|
436
|
+
}) : v("circle", {
|
|
437
|
+
class: a.element("point-dot"),
|
|
438
|
+
cx: o.x,
|
|
439
|
+
cy: o.y,
|
|
440
|
+
r: P ? 4.5 : 3,
|
|
441
|
+
fill: $(o.seriesIndex)
|
|
442
|
+
}, null);
|
|
443
|
+
return v("g", {
|
|
444
|
+
key: `${o.seriesIndex}-${o.index}`,
|
|
445
|
+
class: [a.element("point"), {
|
|
446
|
+
[a.is("active")]: P
|
|
447
|
+
}],
|
|
448
|
+
"data-line-point": o.index,
|
|
449
|
+
"data-line-series": o.seriesIndex,
|
|
450
|
+
"data-line-value": o.value
|
|
451
|
+
}, [O]);
|
|
452
|
+
}))]), le = () => {
|
|
453
|
+
if (I.activeIndex === null || !E) return null;
|
|
454
|
+
const u = p.left + p.width / Math.max(1, te) * (I.activeIndex + 0.5);
|
|
455
|
+
return v("line", {
|
|
456
|
+
class: a.element("active-line"),
|
|
457
|
+
x1: u,
|
|
458
|
+
x2: u,
|
|
459
|
+
y1: p.top,
|
|
460
|
+
y2: p.bottom
|
|
461
|
+
}, null);
|
|
462
|
+
}, ae = () => !this.legend || y.length === 0 ? null : v($e, {
|
|
463
|
+
items: S,
|
|
464
|
+
onToggle: ee
|
|
465
|
+
}, h.legend ? {
|
|
466
|
+
default: () => {
|
|
467
|
+
var u;
|
|
468
|
+
return (u = h.legend) == null ? void 0 : u.call(h, {
|
|
469
|
+
series: y,
|
|
470
|
+
hiddenIndexes: I.hiddenIndexes
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
} : void 0), q = () => !this.tooltip || !b ? null : v(Oe, {
|
|
474
|
+
visible: !0,
|
|
475
|
+
title: b.label,
|
|
476
|
+
entries: c,
|
|
477
|
+
total: A,
|
|
478
|
+
position: D,
|
|
479
|
+
onElement: L
|
|
480
|
+
}, h.tooltip ? {
|
|
481
|
+
default: () => {
|
|
482
|
+
var u;
|
|
483
|
+
return (u = h.tooltip) == null ? void 0 : u.call(h, b);
|
|
484
|
+
}
|
|
485
|
+
} : void 0), ie = () => X && _.length > 0 ? null : v("div", {
|
|
486
|
+
class: "x-chart--empty"
|
|
487
|
+
}, [h.empty ? h.empty() : Q("common.noData")]);
|
|
488
|
+
return v("div", {
|
|
489
|
+
ref: w.root,
|
|
490
|
+
class: a.block
|
|
491
|
+
}, [v(_e, Ce(Pe(this.loading) ? this.loading : {
|
|
492
|
+
loading: this.loading
|
|
493
|
+
}, {
|
|
494
|
+
display: "block"
|
|
495
|
+
}), {
|
|
496
|
+
default: () => [v("div", {
|
|
497
|
+
ref: w.canvas,
|
|
498
|
+
class: a.element("canvas"),
|
|
499
|
+
role: this.ariaLabel ? "img" : void 0,
|
|
500
|
+
"aria-label": this.ariaLabel
|
|
501
|
+
}, [v("svg", {
|
|
502
|
+
class: a.element("svg"),
|
|
503
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
504
|
+
style: {
|
|
505
|
+
width: f,
|
|
506
|
+
height: U
|
|
507
|
+
},
|
|
508
|
+
"aria-hidden": this.ariaLabel ? "true" : void 0,
|
|
509
|
+
tabindex: this.tooltip ? 0 : void 0,
|
|
510
|
+
onMousemove: K,
|
|
511
|
+
onMouseleave: G,
|
|
512
|
+
onClick: g,
|
|
513
|
+
onKeydown: M
|
|
514
|
+
}, [E && v(Te, null, [v(De, {
|
|
515
|
+
plot: p,
|
|
516
|
+
ticks: B,
|
|
517
|
+
xLabels: k,
|
|
518
|
+
fontSize: H,
|
|
519
|
+
color: F,
|
|
520
|
+
showX: s,
|
|
521
|
+
showY: Z,
|
|
522
|
+
showHorizontalLines: T
|
|
523
|
+
}, null), le(), N(), V()])]), q(), ie()])]
|
|
524
|
+
}), ae(), v("span", {
|
|
525
|
+
class: "x-chart--live",
|
|
526
|
+
"aria-live": "polite"
|
|
527
|
+
}, [j])]);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
export {
|
|
531
|
+
ot as default
|
|
532
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const t = (f) => Math.round(f * 100) / 100, I = (f) => {
|
|
2
|
+
const { values: h, lower: r, plot: s, domainMin: x, domainMax: p, smooth: L, connectNulls: M, area: l, baseline: i } = f, d = h.reduce((e, c) => Math.max(e, c.length), 0), X = d > 0 ? s.width / d : 0, w = p - x, k = (e) => s.left + X * (e + 0.5), S = (e) => {
|
|
3
|
+
if (w <= 0) return s.bottom;
|
|
4
|
+
const c = (e - x) / w;
|
|
5
|
+
return s.bottom - Math.min(1, Math.max(0, c)) * s.height;
|
|
6
|
+
}, j = (e) => {
|
|
7
|
+
if (!e.length) return "";
|
|
8
|
+
if (e.length === 1) return `M${t(e[0].x)},${t(e[0].y)}`;
|
|
9
|
+
if (!L)
|
|
10
|
+
return e.map((a, $) => `${$ === 0 ? "M" : "L"}${t(a.x)},${t(a.y)}`).join("");
|
|
11
|
+
let c = `M${t(e[0].x)},${t(e[0].y)}`;
|
|
12
|
+
for (let a = 1; a < e.length; a += 1) {
|
|
13
|
+
const $ = e[a - 1], o = e[a], g = ($.x + o.x) / 2;
|
|
14
|
+
c += `C${t(g)},${t($.y)} ${t(g)},${t(o.y)} ${t(
|
|
15
|
+
o.x
|
|
16
|
+
)},${t(o.y)}`;
|
|
17
|
+
}
|
|
18
|
+
return c;
|
|
19
|
+
}, C = [];
|
|
20
|
+
for (let e = 0; e < h.length; e += 1) {
|
|
21
|
+
const c = h[e] ?? [], a = (r == null ? void 0 : r[e]) ?? [], $ = [], o = [], g = [];
|
|
22
|
+
let y = [], v = [];
|
|
23
|
+
const N = () => {
|
|
24
|
+
y.length && (o.push(y), g.push(v)), y = [], v = [];
|
|
25
|
+
};
|
|
26
|
+
for (let n = 0; n < c.length; n += 1) {
|
|
27
|
+
const u = c[n];
|
|
28
|
+
if (u == null || !Number.isFinite(u)) {
|
|
29
|
+
M || N();
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
M && y.length === 0 && o.length && (y = o.pop(), v = g.pop());
|
|
33
|
+
const m = k(n);
|
|
34
|
+
if ($.push({ index: n, seriesIndex: e, value: u, x: t(m), y: t(S(u)) }), y.push({ x: m, y: S(u) }), r !== void 0) {
|
|
35
|
+
const b = a[n];
|
|
36
|
+
v.push({
|
|
37
|
+
x: m,
|
|
38
|
+
y: S(Number.isFinite(b) ? b : 0)
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
N();
|
|
43
|
+
const z = o.map((n) => j(n)).filter(Boolean).join("");
|
|
44
|
+
let F = "";
|
|
45
|
+
l && o.length && (F = o.map((n, u) => {
|
|
46
|
+
if (!n.length) return "";
|
|
47
|
+
const m = j(n), b = n[n.length - 1], Z = n[0];
|
|
48
|
+
if (r !== void 0) {
|
|
49
|
+
const A = [...g[u] ?? []].reverse().map((B) => `L${t(B.x)},${t(B.y)}`).join("");
|
|
50
|
+
return A ? `${m}${A}Z` : `${m}L${t(b.x)},${t(
|
|
51
|
+
i
|
|
52
|
+
)}L${t(Z.x)},${t(i)}Z`;
|
|
53
|
+
}
|
|
54
|
+
return `${m}L${t(b.x)},${t(i)}L${t(Z.x)},${t(
|
|
55
|
+
i
|
|
56
|
+
)}Z`;
|
|
57
|
+
}).filter(Boolean).join("")), C.push({ seriesIndex: e, d: z, areaD: F, points: $ });
|
|
58
|
+
}
|
|
59
|
+
return C;
|
|
60
|
+
}, P = (f) => {
|
|
61
|
+
const h = f.reduce((s, x) => Math.max(s, x.length), 0), r = new Array(h).fill(0);
|
|
62
|
+
return f.map((s, x) => {
|
|
63
|
+
const p = Array.from({ length: h }, (l, i) => {
|
|
64
|
+
const d = s[i];
|
|
65
|
+
return Number.isFinite(d) && d > 0 ? d : 0;
|
|
66
|
+
}), L = p.map((l, i) => r[i] + l), M = {
|
|
67
|
+
seriesIndex: x,
|
|
68
|
+
values: p,
|
|
69
|
+
base: [...r],
|
|
70
|
+
top: [...L]
|
|
71
|
+
};
|
|
72
|
+
for (let l = 0; l < h; l += 1)
|
|
73
|
+
r[l] = L[l];
|
|
74
|
+
return M;
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export {
|
|
78
|
+
I as buildLineChartSeries,
|
|
79
|
+
P as buildStackedLayers
|
|
80
|
+
};
|