@iyulab/u-widgets 0.7.1 → 0.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.
@@ -1,204 +1,239 @@
1
- import { css as M, LitElement as V, nothing as P, html as E } from "lit";
2
- import { property as R, customElement as D } from "lit/decorators.js";
3
- import { a as T, t as $ } from "./tokens-x1kDxgG8.js";
4
- import * as z from "echarts/core";
5
- import { BarChart as B, LineChart as q, PieChart as W, ScatterChart as G, RadarChart as H, HeatmapChart as K, BoxplotChart as U, FunnelChart as Y, TreemapChart as J } from "echarts/charts";
6
- import { GridComponent as Q, TooltipComponent as X, LegendComponent as Z, RadarComponent as ee, MarkLineComponent as te, VisualMapComponent as re } from "echarts/components";
7
- import { CanvasRenderer as se } from "echarts/renderers";
8
- function ie(e) {
9
- const t = e.widget, i = e.data, r = e.mapping ? T(e.mapping) : void 0, n = e.options ?? {};
1
+ import { css as P, LitElement as E, nothing as R, html as T } from "lit";
2
+ import { property as D, customElement as $ } from "lit/decorators.js";
3
+ import { a as B, t as W } from "./tokens-x1kDxgG8.js";
4
+ import * as O from "echarts/core";
5
+ import { BarChart as q, LineChart as G, PieChart as H, ScatterChart as K, RadarChart as U, HeatmapChart as Y, BoxplotChart as J, FunnelChart as Q, TreemapChart as X } from "echarts/charts";
6
+ import { GridComponent as Z, TooltipComponent as ee, LegendComponent as te, RadarComponent as re, MarkLineComponent as ie, VisualMapComponent as se } from "echarts/components";
7
+ import { CanvasRenderer as ne } from "echarts/renderers";
8
+ function L(e, r) {
9
+ for (const i of r) {
10
+ const t = e[i.field];
11
+ if (t == null) continue;
12
+ const n = Number(t);
13
+ if (Number.isNaN(n)) continue;
14
+ const s = i.above === void 0 || n > i.above, d = i.below === void 0 || n < i.below;
15
+ if (s && d) return i;
16
+ }
17
+ }
18
+ function ae(e) {
19
+ const r = e.widget, i = e.data, t = e.mapping ? B(e.mapping) : void 0, n = e.options ?? {};
10
20
  if (!i) return {};
11
21
  let s;
12
- switch (t) {
22
+ switch (r) {
13
23
  case "chart.bar":
14
- s = F(i, r, "bar", n);
24
+ s = z(i, t, "bar", n);
15
25
  break;
16
26
  case "chart.line":
17
- s = F(i, r, "line", n);
27
+ s = z(i, t, "line", n);
18
28
  break;
19
29
  case "chart.area":
20
- s = F(i, r, "line", { ...n, _area: !0 });
30
+ s = z(i, t, "line", { ...n, _area: !0 });
21
31
  break;
22
32
  case "chart.pie":
23
- s = ae(i, r, n);
33
+ s = le(i, t, n);
24
34
  break;
25
35
  case "chart.scatter":
26
- s = ne(i, r, n);
36
+ s = oe(i, t, n);
27
37
  break;
28
38
  case "chart.radar":
29
- s = oe(i, r);
39
+ s = ce(i, t);
30
40
  break;
31
41
  case "chart.heatmap":
32
- s = le(i, r, n);
42
+ s = ue(i, t, n);
33
43
  break;
34
44
  case "chart.box":
35
- s = ce(i, r);
45
+ s = fe(i, t);
36
46
  break;
37
47
  case "chart.funnel":
38
- s = ue(i, r);
48
+ s = ye(i, t);
39
49
  break;
40
50
  case "chart.waterfall":
41
- s = fe(i, r);
51
+ s = he(i, t);
42
52
  break;
43
53
  case "chart.treemap":
44
- s = ye(i);
54
+ s = de(i);
55
+ break;
56
+ case "chart.histogram":
57
+ s = me(i, t, n);
45
58
  break;
46
59
  default:
47
60
  return {};
48
61
  }
49
62
  n.legend === !1 && s.legend && (s.legend = { ...s.legend, show: !1 }), n.grid === !1 && (s.xAxis && typeof s.xAxis == "object" && !Array.isArray(s.xAxis) && (s.xAxis = { ...s.xAxis, splitLine: { show: !1 } }), s.yAxis && typeof s.yAxis == "object" && !Array.isArray(s.yAxis) && (s.yAxis = { ...s.yAxis, splitLine: { show: !1 } })), n.animate === !1 && (s.animation = !1), Array.isArray(n.colors) && n.colors.length > 0 && (s.color = n.colors);
50
- const y = n.echarts;
51
- return y && typeof y == "object" && (s = L(s, y)), s;
63
+ const d = n.echarts;
64
+ return d && typeof d == "object" && (s = I(s, d)), s;
52
65
  }
53
- function F(e, t, i, r) {
66
+ function z(e, r, i, t) {
54
67
  if (!Array.isArray(e)) return {};
55
- const n = t?.x ?? C(e), s = t?.y ?? [k(e)].filter(Boolean);
68
+ const n = r?.x ?? C(e), s = r?.y ?? [_(e)].filter(Boolean);
56
69
  if (!n || s.length === 0) return {};
57
- const y = e.map((a) => String(a[n] ?? "")), f = !!r.horizontal, d = Array.isArray(r.series) ? r.series : [], c = s.map((a, o) => {
58
- const l = {
70
+ const d = e.map((a) => String(a[n] ?? "")), m = !!t.horizontal, h = Array.isArray(t.series) ? t.series : [], y = t.conditionalStyles, u = s.map((a, l) => {
71
+ const c = {
59
72
  name: a,
60
73
  type: i,
61
- data: e.map((p) => p[a] ?? null)
74
+ data: e.map((p) => {
75
+ const w = p[a] ?? null;
76
+ if (y?.length) {
77
+ const S = L(p, y);
78
+ if (S) {
79
+ const F = { value: w, itemStyle: { color: S.color } };
80
+ return S.symbol && (F.symbol = S.symbol), S.symbolSize && (F.symbolSize = S.symbolSize), F;
81
+ }
82
+ }
83
+ return w;
84
+ })
62
85
  };
63
- r._area && (l.areaStyle = {}), r.smooth && (l.smooth = !0), r.step && (l.step = r.step === !0 ? "end" : r.step);
64
- const u = d[o];
65
- return u && (u.color && (l.itemStyle = { color: u.color }, l.lineStyle = { ...l.lineStyle ?? {}, color: u.color }), u.lineStyle && (l.lineStyle = { ...l.lineStyle ?? {}, ...u.lineStyle }), u.symbol !== void 0 && (l.symbol = u.symbol), u.label && (l.name = u.label), u.type && (l.type = u.type), u.yAxisIndex !== void 0 && (l.yAxisIndex = u.yAxisIndex)), l;
66
- }), h = { type: "category", data: y }, m = { type: "value" };
67
- r.histogram && (h.axisTick = { alignWithLabel: !0 }, c.forEach((a) => {
86
+ t._area && (c.areaStyle = {}), t.smooth && (c.smooth = !0), t.step && (c.step = t.step === !0 ? "end" : t.step);
87
+ const o = h[l];
88
+ return o && (o.color && (c.itemStyle = { color: o.color }, c.lineStyle = { ...c.lineStyle ?? {}, color: o.color }), o.lineStyle && (c.lineStyle = { ...c.lineStyle ?? {}, ...o.lineStyle }), o.symbol !== void 0 && (c.symbol = o.symbol), o.label && (c.name = o.label), o.type && (c.type = o.type), o.yAxisIndex !== void 0 && (c.yAxisIndex = o.yAxisIndex)), c;
89
+ }), x = { type: "category", data: d }, g = { type: "value" };
90
+ t.histogram && (x.axisTick = { alignWithLabel: !0 }, u.forEach((a) => {
68
91
  a.barCategoryGap = "0%";
69
92
  }));
70
- const x = !f && c.some((a) => a.yAxisIndex >= 1);
71
- let b;
72
- if (x) {
73
- const a = Array.isArray(r.yAxis) && r.yAxis.length >= 2 ? r.yAxis[1] : { type: "value" };
74
- b = [m, a];
93
+ const A = !m && u.some((a) => a.yAxisIndex >= 1);
94
+ let f;
95
+ if (A) {
96
+ const a = Array.isArray(t.yAxis) && t.yAxis.length >= 2 ? t.yAxis[1] : { type: "value" };
97
+ f = [g, a];
75
98
  } else
76
- b = f ? h : m;
77
- const A = {
78
- xAxis: f ? m : h,
79
- yAxis: b,
80
- series: c,
99
+ f = m ? x : g;
100
+ const b = {
101
+ xAxis: m ? g : x,
102
+ yAxis: f,
103
+ series: u,
81
104
  tooltip: { trigger: "axis" }
82
105
  };
83
106
  if (s.length > 1) {
84
- const a = c.map((o) => o.name);
85
- A.legend = { data: a };
107
+ const a = u.map((l) => l.name);
108
+ b.legend = { data: a };
86
109
  }
87
- r.stack && A.series.forEach((a) => {
110
+ t.stack && b.series.forEach((a) => {
88
111
  a.stack = "total";
89
112
  });
90
- const v = r.referenceLines;
91
- return Array.isArray(v) && v.length > 0 && c.length > 0 && (c[0].markLine = {
113
+ const v = t.referenceLines;
114
+ return Array.isArray(v) && v.length > 0 && u.length > 0 && (u[0].markLine = {
92
115
  silent: !0,
93
116
  symbol: "none",
94
117
  data: v.map((a) => {
95
- const o = {};
96
- a.axis === "x" ? o.xAxis = a.value : o.yAxis = a.value, a.label && (o.name = a.label);
97
118
  const l = {};
98
- return a.color && (l.color = a.color), a.style && (l.type = a.style), Object.keys(l).length > 0 && (o.lineStyle = l), a.label && (o.label = { formatter: a.label, position: "end" }), o;
119
+ a.axis === "x" ? l.xAxis = a.value : l.yAxis = a.value, a.label && (l.name = a.label);
120
+ const c = {};
121
+ return a.color && (c.color = a.color), a.style && (c.type = a.style), Object.keys(c).length > 0 && (l.lineStyle = c), a.label && (l.label = { formatter: a.label, position: "end" }), l;
99
122
  })
100
- }), A;
123
+ }), b;
101
124
  }
102
- function ne(e, t, i) {
125
+ function oe(e, r, i) {
103
126
  if (!Array.isArray(e)) return {};
104
- const r = j(e), n = t?.x ?? r[0], s = (t?.y ?? [r[1]])[0], y = t?.color, f = t?.size, d = t?.opacity;
127
+ const t = j(e), n = r?.x ?? t[0], s = (r?.y ?? [t[1]])[0], d = r?.color, m = r?.size, h = r?.opacity;
105
128
  if (!n || !s) return {};
106
- const c = {
129
+ const y = {
107
130
  xAxis: { type: "value" },
108
131
  yAxis: { type: "value" },
109
132
  tooltip: { trigger: "item" }
110
133
  };
111
- let h = 1 / 0, m = -1 / 0;
112
- if (d)
134
+ let u = 1 / 0, x = -1 / 0;
135
+ if (h)
113
136
  for (const a of e) {
114
- const o = Number(a[d] ?? 0);
115
- o < h && (h = o), o > m && (m = o);
137
+ const l = Number(a[h] ?? 0);
138
+ l < u && (u = l), l > x && (x = l);
139
+ }
140
+ const g = x - u || 1, A = i.conditionalStyles, f = (a) => {
141
+ const l = [Number(a[n] ?? 0), Number(a[s] ?? 0)];
142
+ if (m && l.push(Number(a[m] ?? 0)), A?.length) {
143
+ const c = L(a, A);
144
+ if (c) {
145
+ const o = { color: c.color };
146
+ if (h) {
147
+ const w = Number(a[h] ?? 0);
148
+ o.opacity = Math.round((0.1 + 0.9 * ((w - u) / g)) * 100) / 100;
149
+ }
150
+ const p = { value: l, itemStyle: o };
151
+ return c.symbol && (p.symbol = c.symbol), c.symbolSize && (p.symbolSize = c.symbolSize), p;
152
+ }
116
153
  }
117
- const x = m - h || 1, b = (a) => {
118
- const o = [Number(a[n] ?? 0), Number(a[s] ?? 0)];
119
- if (f && o.push(Number(a[f] ?? 0)), d) {
120
- const u = 0.1 + 0.9 * ((Number(a[d] ?? 0) - h) / x);
121
- return { value: o, itemStyle: { opacity: Math.round(u * 100) / 100 } };
154
+ if (h) {
155
+ const o = 0.1 + 0.9 * ((Number(a[h] ?? 0) - u) / g);
156
+ return { value: l, itemStyle: { opacity: Math.round(o * 100) / 100 } };
122
157
  }
123
- return o;
124
- }, A = f ? (a) => {
125
- const l = (Array.isArray(a) ? a : a.value)[2] ?? 0;
126
- return Math.max(4, Math.min(60, Math.sqrt(l) * 4));
158
+ return l;
159
+ }, b = m ? (a) => {
160
+ const c = (Array.isArray(a) ? a : a.value)[2] ?? 0;
161
+ return Math.max(4, Math.min(60, Math.sqrt(c) * 4));
127
162
  } : void 0;
128
- if (y) {
163
+ if (d) {
129
164
  const a = /* @__PURE__ */ new Map();
130
- for (const l of e) {
131
- const u = String(l[y] ?? "unknown");
132
- a.has(u) || a.set(u, []), a.get(u).push(b(l));
165
+ for (const c of e) {
166
+ const o = String(c[d] ?? "unknown");
167
+ a.has(o) || a.set(o, []), a.get(o).push(f(c));
133
168
  }
134
- const o = [];
135
- for (const [l, u] of a) {
136
- const p = { name: l, type: "scatter", data: u };
137
- A && (p.symbolSize = A), o.push(p);
169
+ const l = [];
170
+ for (const [c, o] of a) {
171
+ const p = { name: c, type: "scatter", data: o };
172
+ b && (p.symbolSize = b), l.push(p);
138
173
  }
139
- c.series = o, c.legend = { data: Array.from(a.keys()) };
174
+ y.series = l, y.legend = { data: Array.from(a.keys()) };
140
175
  } else {
141
- const o = { type: "scatter", data: e.map((l) => b(l)) };
142
- A && (o.symbolSize = A), c.series = [o];
176
+ const l = { type: "scatter", data: e.map((c) => f(c)) };
177
+ b && (l.symbolSize = b), y.series = [l];
143
178
  }
144
179
  const v = i.referenceLines;
145
180
  if (Array.isArray(v) && v.length > 0) {
146
- const a = c.series[0];
181
+ const a = y.series[0];
147
182
  a.markLine = {
148
183
  silent: !0,
149
184
  symbol: "none",
150
- data: v.map((o) => {
151
- const l = {};
152
- o.axis === "x" ? l.xAxis = o.value : l.yAxis = o.value, o.label && (l.name = o.label);
153
- const u = {};
154
- return o.color && (u.color = o.color), o.style && (u.type = o.style), Object.keys(u).length > 0 && (l.lineStyle = u), o.label && (l.label = { formatter: o.label, position: "end" }), l;
185
+ data: v.map((l) => {
186
+ const c = {};
187
+ l.axis === "x" ? c.xAxis = l.value : c.yAxis = l.value, l.label && (c.name = l.label);
188
+ const o = {};
189
+ return l.color && (o.color = l.color), l.style && (o.type = l.style), Object.keys(o).length > 0 && (c.lineStyle = o), l.label && (c.label = { formatter: l.label, position: "end" }), c;
155
190
  })
156
191
  };
157
192
  }
158
- return c;
193
+ return y;
159
194
  }
160
- function ae(e, t, i) {
195
+ function le(e, r, i) {
161
196
  if (!Array.isArray(e)) return {};
162
- const r = t?.label ?? C(e), n = t?.value ?? k(e);
163
- if (!r || !n) return {};
164
- const s = e.map((h) => ({
165
- name: String(h[r] ?? ""),
166
- value: Number(h[n] ?? 0)
167
- })), f = {
197
+ const t = r?.label ?? C(e), n = r?.value ?? _(e);
198
+ if (!t || !n) return {};
199
+ const s = e.map((u) => ({
200
+ name: String(u[t] ?? ""),
201
+ value: Number(u[n] ?? 0)
202
+ })), m = {
168
203
  type: "pie",
169
204
  radius: i.donut ? ["40%", "70%"] : "50%",
170
205
  data: s,
171
206
  label: { overflow: "truncate", width: 80 }
172
207
  };
173
- i.showLabel === !1 && (f.label = { show: !1 });
174
- const d = {
208
+ i.showLabel === !1 && (m.label = { show: !1 });
209
+ const h = {
175
210
  tooltip: { trigger: "item" },
176
211
  legend: { orient: "vertical", left: "left" },
177
- series: [f]
178
- }, c = i.center;
179
- if (i.donut && c && (c.label || c.value)) {
180
- const h = [];
181
- c.label && h.push({
212
+ series: [m]
213
+ }, y = i.center;
214
+ if (i.donut && y && (y.label || y.value)) {
215
+ const u = [];
216
+ y.label && u.push({
182
217
  type: "text",
183
- top: c.value ? -16 : 0,
184
- style: { text: c.label, fontSize: 13, fill: "#999", textAlign: "center" }
185
- }), c.value && h.push({
218
+ top: y.value ? -16 : 0,
219
+ style: { text: y.label, fontSize: 13, fill: "#999", textAlign: "center" }
220
+ }), y.value && u.push({
186
221
  type: "text",
187
- top: c.label ? 8 : 0,
188
- style: { text: c.value, fontSize: 20, fontWeight: "bold", fill: "#333", textAlign: "center" }
189
- }), d.graphic = [{ type: "group", left: "center", top: "middle", children: h }];
222
+ top: y.label ? 8 : 0,
223
+ style: { text: y.value, fontSize: 20, fontWeight: "bold", fill: "#333", textAlign: "center" }
224
+ }), h.graphic = [{ type: "group", left: "center", top: "middle", children: u }];
190
225
  }
191
- return d;
226
+ return h;
192
227
  }
193
- function oe(e, t, i) {
228
+ function ce(e, r, i) {
194
229
  if (!Array.isArray(e)) return {};
195
- const r = t?.axis ?? C(e), n = t?.y ?? j(e);
196
- if (!r || n.length === 0) return {};
197
- const s = e.map((f) => ({
198
- name: String(f[r] ?? "")
199
- })), y = n.map((f) => ({
200
- name: f,
201
- value: e.map((d) => Number(d[f] ?? 0))
230
+ const t = r?.axis ?? C(e), n = r?.y ?? j(e);
231
+ if (!t || n.length === 0) return {};
232
+ const s = e.map((m) => ({
233
+ name: String(m[t] ?? "")
234
+ })), d = n.map((m) => ({
235
+ name: m,
236
+ value: e.map((h) => Number(h[m] ?? 0))
202
237
  }));
203
238
  return {
204
239
  tooltip: {},
@@ -207,98 +242,98 @@ function oe(e, t, i) {
207
242
  series: [
208
243
  {
209
244
  type: "radar",
210
- data: y
245
+ data: d
211
246
  }
212
247
  ]
213
248
  };
214
249
  }
215
- function le(e, t, i) {
250
+ function ue(e, r, i) {
216
251
  if (!Array.isArray(e)) return {};
217
- const r = e[0] ?? {}, n = Object.keys(r), s = n.filter((p) => typeof r[p] == "string"), y = n.filter((p) => typeof r[p] == "number"), f = t?.x ?? s[0], d = t?.y?.[0] ?? s.find((p) => p !== f), c = t?.value ?? y[0];
218
- if (!f || !d || !c) return {};
219
- const h = [], m = [], x = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Set();
220
- for (const p of e) {
221
- const g = String(p[f] ?? ""), w = String(p[d] ?? "");
222
- x.has(g) || (x.add(g), h.push(g)), b.has(w) || (b.add(w), m.push(w));
252
+ const t = e[0] ?? {}, n = Object.keys(t), s = n.filter((o) => typeof t[o] == "string"), d = n.filter((o) => typeof t[o] == "number"), m = r?.x ?? s[0], h = r?.y?.[0] ?? s.find((o) => o !== m), y = r?.value ?? d[0];
253
+ if (!m || !h || !y) return {};
254
+ const u = [], x = [], g = /* @__PURE__ */ new Set(), A = /* @__PURE__ */ new Set();
255
+ for (const o of e) {
256
+ const p = String(o[m] ?? ""), w = String(o[h] ?? "");
257
+ g.has(p) || (g.add(p), u.push(p)), A.has(w) || (A.add(w), x.push(w));
223
258
  }
224
- const A = /* @__PURE__ */ new Map();
225
- h.forEach((p, g) => A.set(p, g));
226
- const v = /* @__PURE__ */ new Map();
227
- m.forEach((p, g) => v.set(p, g));
228
- const a = [];
229
- let o = 1 / 0, l = -1 / 0;
230
- for (const p of e) {
231
- const g = A.get(String(p[f] ?? "")) ?? 0, w = v.get(String(p[d] ?? "")) ?? 0, S = p[c] != null ? Number(p[c]) : null;
232
- a.push([g, w, S]), S != null && (S < o && (o = S), S > l && (l = S));
259
+ const f = /* @__PURE__ */ new Map();
260
+ u.forEach((o, p) => f.set(o, p));
261
+ const b = /* @__PURE__ */ new Map();
262
+ x.forEach((o, p) => b.set(o, p));
263
+ const v = [];
264
+ let a = 1 / 0, l = -1 / 0;
265
+ for (const o of e) {
266
+ const p = f.get(String(o[m] ?? "")) ?? 0, w = b.get(String(o[h] ?? "")) ?? 0, S = o[y] != null ? Number(o[y]) : null;
267
+ v.push([p, w, S]), S != null && (S < a && (a = S), S > l && (l = S));
233
268
  }
234
- isFinite(o) || (o = 0, l = 1);
235
- const u = i.colorRange ?? ["#313695", "#4575b4", "#74add1", "#abd9e9", "#fee090", "#fdae61", "#f46d43", "#d73027"];
269
+ isFinite(a) || (a = 0, l = 1);
270
+ const c = i.colorRange ?? ["#313695", "#4575b4", "#74add1", "#abd9e9", "#fee090", "#fdae61", "#f46d43", "#d73027"];
236
271
  return {
237
- xAxis: { type: "category", data: h, splitArea: { show: !0 } },
238
- yAxis: { type: "category", data: m, splitArea: { show: !0 } },
272
+ xAxis: { type: "category", data: u, splitArea: { show: !0 } },
273
+ yAxis: { type: "category", data: x, splitArea: { show: !0 } },
239
274
  visualMap: {
240
- min: i.min != null ? Number(i.min) : o,
275
+ min: i.min != null ? Number(i.min) : a,
241
276
  max: i.max != null ? Number(i.max) : l,
242
277
  calculable: !0,
243
278
  orient: "horizontal",
244
279
  left: "center",
245
280
  bottom: 0,
246
- inRange: { color: u }
281
+ inRange: { color: c }
247
282
  },
248
283
  tooltip: {
249
284
  trigger: "item",
250
- formatter: (p) => {
251
- const g = p.data;
252
- return g ? `${h[g[0]]} × ${m[g[1]]}: ${g[2] != null ? g[2] : "-"}` : "";
285
+ formatter: (o) => {
286
+ const p = o.data;
287
+ return p ? `${u[p[0]]} × ${x[p[1]]}: ${p[2] != null ? p[2] : "-"}` : "";
253
288
  }
254
289
  },
255
290
  grid: { bottom: 60 },
256
291
  series: [{
257
292
  type: "heatmap",
258
- data: a,
293
+ data: v,
259
294
  label: { show: i.showLabel !== !1 }
260
295
  }]
261
296
  };
262
297
  }
263
- function ce(e, t, i) {
298
+ function fe(e, r, i) {
264
299
  if (!Array.isArray(e) || e.length === 0) return {};
265
- const r = e[0] ?? {}, n = Object.keys(r), s = n.filter((x) => typeof r[x] == "string"), y = n.filter((x) => typeof r[x] == "number"), f = t?.x ?? s[0];
266
- let d;
267
- if (t?.y && t.y.length >= 5)
268
- d = t.y.slice(0, 5);
300
+ const t = e[0] ?? {}, n = Object.keys(t), s = n.filter((g) => typeof t[g] == "string"), d = n.filter((g) => typeof t[g] == "number"), m = r?.x ?? s[0];
301
+ let h;
302
+ if (r?.y && r.y.length >= 5)
303
+ h = r.y.slice(0, 5);
269
304
  else {
270
- const b = ["min", "q1", "median", "q3", "max"].filter((A) => y.includes(A));
271
- d = b.length === 5 ? b : y.slice(0, 5);
305
+ const A = ["min", "q1", "median", "q3", "max"].filter((f) => d.includes(f));
306
+ h = A.length === 5 ? A : d.slice(0, 5);
272
307
  }
273
- if (d.length < 5) return {};
274
- const c = f ? e.map((x) => String(x[f] ?? "")) : void 0, h = e.map(
275
- (x) => d.map((b) => Number(x[b] ?? 0))
276
- ), m = {
308
+ if (h.length < 5) return {};
309
+ const y = m ? e.map((g) => String(g[m] ?? "")) : void 0, u = e.map(
310
+ (g) => h.map((A) => Number(g[A] ?? 0))
311
+ ), x = {
277
312
  tooltip: { trigger: "item" },
278
313
  series: [{
279
314
  type: "boxplot",
280
- data: h
315
+ data: u
281
316
  }]
282
317
  };
283
- return c ? (m.xAxis = { type: "category", data: c }, m.yAxis = { type: "value" }) : (m.xAxis = { type: "category" }, m.yAxis = { type: "value" }), m;
318
+ return y ? (x.xAxis = { type: "category", data: y }, x.yAxis = { type: "value" }) : (x.xAxis = { type: "category" }, x.yAxis = { type: "value" }), x;
284
319
  }
285
320
  function C(e) {
286
321
  if (e.length === 0) return;
287
- const t = e[0];
288
- return Object.keys(t).find((i) => typeof t[i] == "string");
322
+ const r = e[0];
323
+ return Object.keys(r).find((i) => typeof r[i] == "string");
289
324
  }
290
- function k(e) {
325
+ function _(e) {
291
326
  if (e.length === 0) return;
292
- const t = e[0];
293
- return Object.keys(t).find((i) => typeof t[i] == "number");
327
+ const r = e[0];
328
+ return Object.keys(r).find((i) => typeof r[i] == "number");
294
329
  }
295
- function ue(e, t, i) {
330
+ function ye(e, r, i) {
296
331
  if (!Array.isArray(e)) return {};
297
- const r = t?.label ?? C(e), n = t?.value ?? k(e);
298
- if (!r || !n) return {};
299
- const s = e.map((y) => ({
300
- name: String(y[r] ?? ""),
301
- value: Number(y[n] ?? 0)
332
+ const t = r?.label ?? C(e), n = r?.value ?? _(e);
333
+ if (!t || !n) return {};
334
+ const s = e.map((d) => ({
335
+ name: String(d[t] ?? ""),
336
+ value: Number(d[n] ?? 0)
302
337
  }));
303
338
  return {
304
339
  tooltip: { trigger: "item", formatter: "{b}: {c} ({d}%)" },
@@ -312,19 +347,19 @@ function ue(e, t, i) {
312
347
  }]
313
348
  };
314
349
  }
315
- function fe(e, t, i) {
350
+ function he(e, r, i) {
316
351
  if (!Array.isArray(e)) return {};
317
- const r = e, n = t?.x ?? C(r), s = (t?.y ?? [k(r)])[0];
352
+ const t = e, n = r?.x ?? C(t), s = (r?.y ?? [_(t)])[0];
318
353
  if (!n || !s) return {};
319
- const y = [], f = [], d = [], c = [];
320
- let h = 0;
321
- for (const m of r) {
322
- const x = String(m[n] ?? ""), b = Number(m[s] ?? 0);
323
- y.push(x), b >= 0 ? (f.push(h), d.push(b), c.push(null)) : (f.push(h + b), d.push(null), c.push(Math.abs(b))), h += b;
354
+ const d = [], m = [], h = [], y = [];
355
+ let u = 0;
356
+ for (const x of t) {
357
+ const g = String(x[n] ?? ""), A = Number(x[s] ?? 0);
358
+ d.push(g), A >= 0 ? (m.push(u), h.push(A), y.push(null)) : (m.push(u + A), h.push(null), y.push(Math.abs(A))), u += A;
324
359
  }
325
360
  return {
326
361
  tooltip: { trigger: "axis", axisPointer: { type: "shadow" } },
327
- xAxis: { type: "category", data: y },
362
+ xAxis: { type: "category", data: d },
328
363
  yAxis: { type: "value" },
329
364
  series: [
330
365
  {
@@ -333,26 +368,26 @@ function fe(e, t, i) {
333
368
  stack: "waterfall",
334
369
  itemStyle: { borderColor: "transparent", color: "transparent" },
335
370
  emphasis: { itemStyle: { borderColor: "transparent", color: "transparent" } },
336
- data: f
371
+ data: m
337
372
  },
338
373
  {
339
374
  name: "Positive",
340
375
  type: "bar",
341
376
  stack: "waterfall",
342
- data: d
377
+ data: h
343
378
  },
344
379
  {
345
380
  name: "Negative",
346
381
  type: "bar",
347
382
  stack: "waterfall",
348
- data: c
383
+ data: y
349
384
  }
350
385
  ]
351
386
  };
352
387
  }
353
- function ye(e, t) {
388
+ function de(e, r) {
354
389
  if (!Array.isArray(e)) return {};
355
- const i = e.map((r) => N(r));
390
+ const i = e.map((t) => M(t));
356
391
  return {
357
392
  tooltip: { trigger: "item" },
358
393
  series: [{
@@ -364,38 +399,77 @@ function ye(e, t) {
364
399
  }]
365
400
  };
366
401
  }
367
- function N(e) {
368
- const t = {
402
+ function M(e) {
403
+ const r = {
369
404
  name: String(e.name ?? ""),
370
405
  value: Number(e.value ?? 0)
371
406
  };
372
- return Array.isArray(e.children) && (t.children = e.children.map((i) => N(i))), t;
407
+ return Array.isArray(e.children) && (r.children = e.children.map((i) => M(i))), r;
408
+ }
409
+ function me(e, r, i) {
410
+ let t;
411
+ if (!Array.isArray(e) || e.length === 0) return {};
412
+ if (typeof e[0] == "number")
413
+ t = e;
414
+ else {
415
+ const f = r?.value ?? _(e);
416
+ if (!f) return {};
417
+ t = e.map((b) => Number(b[f] ?? 0));
418
+ }
419
+ if (t.length === 0) return {};
420
+ const n = typeof i.bins == "number" ? i.bins : Math.ceil(Math.log2(t.length) + 1), s = Math.min(...t), h = (Math.max(...t) - s) / n || 1, y = new Array(n).fill(0), u = [];
421
+ for (let f = 0; f < n; f++) {
422
+ const b = s + f * h, v = s + (f + 1) * h, a = (l) => Number.isInteger(l) ? String(l) : l.toFixed(1);
423
+ u.push(`${a(b)}–${a(v)}`);
424
+ }
425
+ for (const f of t) {
426
+ let b = Math.floor((f - s) / h);
427
+ b >= n && (b = n - 1), y[b]++;
428
+ }
429
+ const x = {
430
+ type: "bar",
431
+ data: y,
432
+ barCategoryGap: "0%"
433
+ }, g = {
434
+ xAxis: { type: "category", data: u, axisTick: { alignWithLabel: !0 } },
435
+ yAxis: { type: "value" },
436
+ series: [x],
437
+ tooltip: { trigger: "axis" }
438
+ }, A = i.referenceLines;
439
+ return Array.isArray(A) && A.length > 0 && (x.markLine = {
440
+ silent: !0,
441
+ symbol: "none",
442
+ data: A.map((f) => {
443
+ const b = {};
444
+ f.axis === "x" ? b.xAxis = f.value : b.yAxis = f.value, f.label && (b.name = f.label);
445
+ const v = {};
446
+ return f.color && (v.color = f.color), f.style && (v.type = f.style), Object.keys(v).length > 0 && (b.lineStyle = v), f.label && (b.label = { formatter: f.label, position: "end" }), b;
447
+ })
448
+ }), g;
373
449
  }
374
450
  function j(e) {
375
451
  if (e.length === 0) return [];
376
- const t = e[0];
377
- return Object.keys(t).filter((i) => typeof t[i] == "number");
452
+ const r = e[0];
453
+ return Object.keys(r).filter((i) => typeof r[i] == "number");
378
454
  }
379
- function L(e, t) {
455
+ function I(e, r) {
380
456
  const i = { ...e };
381
- for (const r of Object.keys(t)) {
382
- const n = e[r], s = t[r];
383
- O(n) && O(s) ? i[r] = L(n, s) : i[r] = s;
457
+ for (const t of Object.keys(r)) {
458
+ const n = e[t], s = r[t];
459
+ N(n) && N(s) ? i[t] = I(n, s) : i[t] = s;
384
460
  }
385
461
  return i;
386
462
  }
387
- function O(e) {
463
+ function N(e) {
388
464
  return e != null && typeof e == "object" && !Array.isArray(e);
389
465
  }
390
- var he = Object.defineProperty, de = Object.getOwnPropertyDescriptor, I = (e, t, i, r) => {
391
- for (var n = r > 1 ? void 0 : r ? de(t, i) : t, s = e.length - 1, y; s >= 0; s--)
392
- (y = e[s]) && (n = (r ? y(t, i, n) : y(n)) || n);
393
- return r && n && he(t, i, n), n;
466
+ var be = Object.defineProperty, pe = Object.getOwnPropertyDescriptor, V = (e, r, i, t) => {
467
+ for (var n = t > 1 ? void 0 : t ? pe(r, i) : r, s = e.length - 1, d; s >= 0; s--)
468
+ (d = e[s]) && (n = (t ? d(r, i, n) : d(n)) || n);
469
+ return t && n && be(r, i, n), n;
394
470
  };
395
- z.use([
396
- B,
471
+ O.use([
397
472
  q,
398
- W,
399
473
  G,
400
474
  H,
401
475
  K,
@@ -408,16 +482,18 @@ z.use([
408
482
  ee,
409
483
  te,
410
484
  re,
411
- se
485
+ ie,
486
+ se,
487
+ ne
412
488
  ]);
413
- let _ = class extends V {
489
+ let k = class extends E {
414
490
  constructor() {
415
491
  super(...arguments), this.spec = null, this._chart = null, this._container = null, this._resizeObserver = null;
416
492
  }
417
493
  render() {
418
- if (!this.spec) return P;
494
+ if (!this.spec) return R;
419
495
  const e = this.spec.title ?? `${this.spec.widget} chart`;
420
- return E`<div class="chart-container" part="chart" role="img" aria-label=${e}></div>`;
496
+ return T`<div class="chart-container" part="chart" role="img" aria-label=${e}></div>`;
421
497
  }
422
498
  firstUpdated() {
423
499
  this._container = this.shadowRoot?.querySelector(".chart-container"), this._initChart(), this._container && (this._resizeObserver = new ResizeObserver(() => this._chart?.resize()), this._resizeObserver.observe(this._container));
@@ -428,7 +504,7 @@ let _ = class extends V {
428
504
  _initChart() {
429
505
  if (!(!this._container || !this.spec))
430
506
  try {
431
- this._chart = z.init(this._container), this._chart.on("click", (e) => {
507
+ this._chart = O.init(this._container), this._chart.on("click", (e) => {
432
508
  this._onChartClick(e);
433
509
  }), this._updateChart();
434
510
  } catch (e) {
@@ -437,7 +513,7 @@ let _ = class extends V {
437
513
  }
438
514
  _onChartClick(e) {
439
515
  if (!this.spec) return;
440
- const t = {
516
+ const r = {
441
517
  type: "select",
442
518
  widget: this.spec.widget,
443
519
  id: this.spec.id,
@@ -450,7 +526,7 @@ let _ = class extends V {
450
526
  };
451
527
  this.dispatchEvent(
452
528
  new CustomEvent("u-widget-internal", {
453
- detail: t,
529
+ detail: r,
454
530
  bubbles: !0,
455
531
  composed: !0
456
532
  })
@@ -458,30 +534,30 @@ let _ = class extends V {
458
534
  }
459
535
  _updateChart() {
460
536
  if (!this._chart || !this.spec) return;
461
- const e = ie(this.spec), t = this._readThemeColors();
462
- t.length > 0 && (e.color = t), this._readCSSVar("--u-widget-bg") && (e.backgroundColor = "transparent"), this._applyThemeStyle(e), this._chart.setOption(e, !0);
537
+ const e = ae(this.spec), r = this._readThemeColors();
538
+ r.length > 0 && (e.color = r), this._readCSSVar("--u-widget-bg") && (e.backgroundColor = "transparent"), this._applyThemeStyle(e), this._chart.setOption(e, !0);
463
539
  }
464
540
  _applyThemeStyle(e) {
465
- const t = this._readCSSVar("--u-widget-text"), i = this._readCSSVar("--u-widget-text-secondary"), r = this._readCSSVar("--u-widget-border");
466
- if (!t) return;
467
- e.textStyle = { ...e.textStyle, color: t };
541
+ const r = this._readCSSVar("--u-widget-text"), i = this._readCSSVar("--u-widget-text-secondary"), t = this._readCSSVar("--u-widget-border");
542
+ if (!r) return;
543
+ e.textStyle = { ...e.textStyle, color: r };
468
544
  const n = {
469
- axisLabel: { color: i || t },
470
- axisLine: { lineStyle: { color: r || i } },
471
- splitLine: { lineStyle: { color: r } }
545
+ axisLabel: { color: i || r },
546
+ axisLine: { lineStyle: { color: t || i } },
547
+ splitLine: { lineStyle: { color: t } }
472
548
  };
473
- e.xAxis && typeof e.xAxis == "object" && (e.xAxis = { ...e.xAxis, ...n }), e.yAxis && typeof e.yAxis == "object" && (e.yAxis = { ...e.yAxis, ...n }), e.legend && typeof e.legend == "object" && (e.legend = { ...e.legend, textStyle: { color: t } });
549
+ e.xAxis && typeof e.xAxis == "object" && (e.xAxis = { ...e.xAxis, ...n }), e.yAxis && typeof e.yAxis == "object" && (e.yAxis = { ...e.yAxis, ...n }), e.legend && typeof e.legend == "object" && (e.legend = { ...e.legend, textStyle: { color: r } });
474
550
  }
475
551
  _readThemeColors() {
476
552
  const e = [];
477
- for (let t = 1; t <= 10; t++) {
478
- const i = this._readCSSVar(`--u-widget-chart-color-${t}`);
553
+ for (let r = 1; r <= 10; r++) {
554
+ const i = this._readCSSVar(`--u-widget-chart-color-${r}`);
479
555
  if (i) e.push(i);
480
556
  else break;
481
557
  }
482
558
  if (e.length === 0) {
483
- const t = this._readCSSVar("--u-widget-primary");
484
- t && e.push(t);
559
+ const r = this._readCSSVar("--u-widget-primary");
560
+ r && e.push(r);
485
561
  }
486
562
  return e;
487
563
  }
@@ -496,9 +572,9 @@ let _ = class extends V {
496
572
  this._chart?.resize();
497
573
  }
498
574
  };
499
- _.styles = [
500
- $,
501
- M`
575
+ k.styles = [
576
+ W,
577
+ P`
502
578
  :host {
503
579
  display: block;
504
580
  container: uw-chart / inline-size;
@@ -516,14 +592,14 @@ _.styles = [
516
592
  }
517
593
  `
518
594
  ];
519
- I([
520
- R({ type: Object })
521
- ], _.prototype, "spec", 2);
522
- _ = I([
523
- D("uw-chart")
524
- ], _);
595
+ V([
596
+ D({ type: Object })
597
+ ], k.prototype, "spec", 2);
598
+ k = V([
599
+ $("uw-chart")
600
+ ], k);
525
601
  export {
526
- _ as UwChart,
527
- ie as toEChartsOption
602
+ k as UwChart,
603
+ ae as toEChartsOption
528
604
  };
529
605
  //# sourceMappingURL=u-widgets-charts.js.map