@martinomagnifico/tablechart 1.2.6 → 1.4.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/CHANGELOG.md +52 -0
- package/README.md +5 -4
- package/dist/tablechart-additional-types.d.mts +2 -2
- package/dist/tablechart-additional-types.js +1 -1
- package/dist/tablechart-additional-types.mjs +185 -91
- package/dist/tablechart-core.d.mts +1 -1
- package/dist/tablechart-core.mjs +1 -1
- package/dist/tablechart-shared.d.mts +108 -9
- package/dist/tablechart-shared.mjs +2854 -2535
- package/dist/tablechart-summary.d.mts +3 -31
- package/dist/tablechart-summary.js +1 -1
- package/dist/tablechart-summary.mjs +299 -162
- package/dist/tablechart.css +1 -1
- package/dist/tablechart.d.mts +1 -1
- package/dist/tablechart.js +1 -1
- package/dist/tablechart.mjs +1 -1
- package/package.json +8 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
// src/js/summary.ts
|
|
3
|
-
var
|
|
1
|
+
import { E as e, S as t, V as n, _ as r, b as i, g as a, w as o, x as s } from "./tablechart-shared.mjs";
|
|
2
|
+
// src/js/summary/config.ts
|
|
3
|
+
var c = {
|
|
4
4
|
selector: "[data-chart]:not(th)",
|
|
5
5
|
delimiters: ["{", "}"],
|
|
6
6
|
langattribute: "data-i18n",
|
|
@@ -13,43 +13,69 @@ var s = {
|
|
|
13
13
|
unclear: "unclear",
|
|
14
14
|
above: "above",
|
|
15
15
|
below: "below"
|
|
16
|
-
}
|
|
17
|
-
|
|
16
|
+
},
|
|
17
|
+
groups: 10
|
|
18
|
+
}, l = { config: null }, u = [
|
|
19
|
+
"delimiters",
|
|
20
|
+
"locale",
|
|
21
|
+
"flat",
|
|
22
|
+
"outliers",
|
|
23
|
+
"words",
|
|
24
|
+
"groups"
|
|
25
|
+
], d = "chart-summary", f = "data-summary-ready", p = "data-summary-template", m = "data-summary-text", h = [
|
|
26
|
+
"line",
|
|
27
|
+
"area",
|
|
28
|
+
"candlestick"
|
|
29
|
+
], g = { candlestick: 4 }, _ = [
|
|
18
30
|
"extremes",
|
|
19
31
|
"range",
|
|
20
32
|
"change",
|
|
21
33
|
"trend",
|
|
22
34
|
"outliers",
|
|
23
|
-
"notes"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
"notes",
|
|
36
|
+
"groups"
|
|
37
|
+
], v = /* @__PURE__ */ new Set(["rank", "rank.low"]), y = /* @__PURE__ */ new Set(), b = (e) => {
|
|
38
|
+
y.has(e) || (y.add(e), console.warn(`[${n}] ${e}`));
|
|
39
|
+
}, x = (e, t) => {
|
|
40
|
+
let n = Math.max(1, Math.min(Math.round(t), e.length));
|
|
41
|
+
return Array.from({ length: n }, (t, r) => e.slice(Math.floor(r * e.length / n), Math.floor((r + 1) * e.length / n)));
|
|
42
|
+
}, S = (e) => (t) => ({
|
|
43
|
+
high: 1 + e.filter((e) => e > t).length,
|
|
44
|
+
low: 1 + e.filter((e) => e < t).length
|
|
45
|
+
}), C = (e) => {
|
|
46
|
+
let t = e.filter((e) => !e.missing), n = t.reduce((e, t) => o(t.number) > o(e.number) ? t : e, t[0] ?? e[0]);
|
|
47
|
+
if (!n) return;
|
|
48
|
+
let r = t.reduce((e, t) => e + t.value, 0);
|
|
49
|
+
return {
|
|
50
|
+
...n,
|
|
51
|
+
raw: "",
|
|
52
|
+
number: r.toFixed(o(n.number)),
|
|
53
|
+
missing: !t.length,
|
|
54
|
+
value: r
|
|
55
|
+
};
|
|
56
|
+
}, w = (t, n, c, l) => {
|
|
57
|
+
let u = s(t, c.langattribute), d = i(t, u.filter((e) => !e.isTotal), c.langattribute), f = n < 0, p = u.filter((e) => !e.isTotal).map((e) => f ? {
|
|
58
|
+
...e,
|
|
59
|
+
cells: [C(e.cells.slice(0, d.length))].filter((e) => !!e)
|
|
60
|
+
} : e), m = f ? 0 : n, g = f ? void 0 : d[n], _ = (e, t) => {
|
|
28
61
|
if (!t || !c.langattribute) return e;
|
|
29
62
|
let n = document.createElement("span");
|
|
30
63
|
return n.setAttribute(c.langattribute, t), n.textContent = e, n;
|
|
31
|
-
},
|
|
32
|
-
let [i, a] =
|
|
33
|
-
return
|
|
34
|
-
},
|
|
64
|
+
}, v = Math.max(0, ...p.map((e) => o(e.cells[m]?.number ?? ""))), y = (t, n, r = v) => {
|
|
65
|
+
let [i, a] = e(t, r, l);
|
|
66
|
+
return n.prefix + i + a + n.suffix;
|
|
67
|
+
}, b = (e) => new Intl.NumberFormat(l, {
|
|
35
68
|
style: "percent",
|
|
36
69
|
maximumFractionDigits: +(Math.abs(e) < 10)
|
|
37
|
-
}).format(e / 100),
|
|
70
|
+
}).format(e / 100), w = (e) => _(e.label, e.key), T = t.querySelector(":scope > figcaption"), E = T?.querySelector("b, strong") ?? T, D = {
|
|
38
71
|
values: {
|
|
39
|
-
title:
|
|
40
|
-
rows:
|
|
41
|
-
series:
|
|
72
|
+
title: _((E?.textContent ?? "").trim(), c.langattribute && E?.getAttribute(c.langattribute) || null),
|
|
73
|
+
rows: e(p.length, 0, l).join(""),
|
|
74
|
+
series: g ? _(g.name, g.key) : ""
|
|
42
75
|
},
|
|
43
|
-
counts: { rows:
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
counts: { "notes.count": x.length },
|
|
47
|
-
items: x.map((e) => ({
|
|
48
|
-
name: _(e),
|
|
49
|
-
note: p(e.note ?? "", e.noteKey)
|
|
50
|
-
}))
|
|
51
|
-
} : null, C = u.flatMap((e, t) => {
|
|
52
|
-
let n = e.cells[s];
|
|
76
|
+
counts: { rows: p.length }
|
|
77
|
+
}, O = p.flatMap((e, t) => {
|
|
78
|
+
let n = e.cells[m];
|
|
53
79
|
return n && !n.missing ? [{
|
|
54
80
|
row: e,
|
|
55
81
|
cell: n,
|
|
@@ -57,111 +83,164 @@ var s = {
|
|
|
57
83
|
y: n.value
|
|
58
84
|
}] : [];
|
|
59
85
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
D.values.values = e(O.length, 0, l).join(""), D.counts.values = O.length;
|
|
87
|
+
let k = S(O.map((e) => e.y)), A = (t) => {
|
|
88
|
+
let { high: n, low: r } = k(t);
|
|
89
|
+
return {
|
|
90
|
+
values: {
|
|
91
|
+
rank: e(n, 0, l).join(""),
|
|
92
|
+
"rank.low": e(r, 0, l).join("")
|
|
93
|
+
},
|
|
94
|
+
counts: {
|
|
95
|
+
rank: n,
|
|
96
|
+
"rank.low": r
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}, j = (e, t) => {
|
|
100
|
+
if (t === void 0) return { values: e };
|
|
101
|
+
let n = A(t);
|
|
102
|
+
return {
|
|
103
|
+
values: {
|
|
104
|
+
...e,
|
|
105
|
+
...n.values
|
|
106
|
+
},
|
|
107
|
+
counts: n.counts
|
|
108
|
+
};
|
|
109
|
+
}, M = p.filter((e) => e.note), N = M.length ? {
|
|
110
|
+
values: { "notes.count": e(M.length, 0, l).join("") },
|
|
111
|
+
counts: { "notes.count": M.length },
|
|
112
|
+
items: M.map((e) => {
|
|
113
|
+
let t = e.cells[m], n = t && !t.missing ? t : void 0, r = {
|
|
114
|
+
name: w(e),
|
|
115
|
+
note: _(e.note ?? "", e.noteKey)
|
|
116
|
+
};
|
|
117
|
+
return n && (r.value = y(n.value, n)), j(r, n?.value);
|
|
118
|
+
})
|
|
119
|
+
} : null;
|
|
120
|
+
if (!O.length) return {
|
|
121
|
+
chart: D,
|
|
122
|
+
notes: N,
|
|
63
123
|
extremes: null,
|
|
64
124
|
range: null,
|
|
65
125
|
change: null,
|
|
66
126
|
trend: null,
|
|
67
|
-
outliers: null
|
|
127
|
+
outliers: null,
|
|
128
|
+
groups: null
|
|
68
129
|
};
|
|
69
|
-
let
|
|
70
|
-
for (let e of
|
|
71
|
-
let
|
|
72
|
-
"highest.name":
|
|
73
|
-
"highest.value":
|
|
74
|
-
"lowest.name":
|
|
75
|
-
"lowest.value":
|
|
76
|
-
} },
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"range.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
130
|
+
let P = O[0], F = O[0];
|
|
131
|
+
for (let e of O) e.y > P.y && (P = e), e.y < F.y && (F = e);
|
|
132
|
+
let I = { values: {
|
|
133
|
+
"highest.name": w(P.row),
|
|
134
|
+
"highest.value": y(P.y, P.cell),
|
|
135
|
+
"lowest.name": w(F.row),
|
|
136
|
+
"lowest.value": y(F.y, F.cell)
|
|
137
|
+
} }, L = f ? void 0 : u.find((e) => e.isTotal)?.cells[m], R = L && !L.missing ? L.value : O.reduce((e, t) => e + t.y, 0);
|
|
138
|
+
I.values.total = y(R, P.cell), R > 0 && O.every((e) => e.y >= 0) && (I.values["highest.share"] = b(P.y / R * 100), I.values["lowest.share"] = b(F.y / R * 100));
|
|
139
|
+
let z = { values: {
|
|
140
|
+
"range.from": y(F.y, F.cell),
|
|
141
|
+
"range.to": y(P.y, P.cell),
|
|
142
|
+
"range.difference": y(P.y - F.y, P.cell)
|
|
143
|
+
} }, B = t.getAttribute("data-chart") || "column";
|
|
144
|
+
if (!h.includes(B) && !t.hasAttribute("data-chart-ordered")) return {
|
|
145
|
+
chart: D,
|
|
146
|
+
notes: N,
|
|
147
|
+
extremes: I,
|
|
148
|
+
range: z
|
|
86
149
|
};
|
|
87
|
-
if (
|
|
88
|
-
chart:
|
|
89
|
-
notes:
|
|
90
|
-
extremes:
|
|
91
|
-
range:
|
|
150
|
+
if (O.length < 2) return {
|
|
151
|
+
chart: D,
|
|
152
|
+
notes: N,
|
|
153
|
+
extremes: I,
|
|
154
|
+
range: z,
|
|
92
155
|
change: null,
|
|
93
156
|
trend: null,
|
|
94
|
-
outliers: null
|
|
157
|
+
outliers: null,
|
|
158
|
+
groups: null
|
|
95
159
|
};
|
|
96
|
-
let
|
|
160
|
+
let V = {
|
|
161
|
+
values: {},
|
|
162
|
+
items: x(O, c.groups).map((e) => {
|
|
163
|
+
let t = e.map((e) => e.y), n = e[0].cell;
|
|
164
|
+
return { values: {
|
|
165
|
+
from: w(e[0].row),
|
|
166
|
+
to: w(e[e.length - 1].row),
|
|
167
|
+
lowest: y(Math.min(...t), n),
|
|
168
|
+
average: y(t.reduce((e, t) => e + t, 0) / t.length, n),
|
|
169
|
+
highest: y(Math.max(...t), n)
|
|
170
|
+
} };
|
|
171
|
+
})
|
|
172
|
+
}, { share: H } = a(O), U = (e) => Math.abs(e) < c.flat ? "flat" : e > 0 ? "up" : "down", W = O[0], G = O[O.length - 1], K = H(G.y - W.y, W.y), q = {
|
|
97
173
|
values: {
|
|
98
|
-
"first.name":
|
|
99
|
-
"first.value":
|
|
100
|
-
"last.name":
|
|
101
|
-
"last.value":
|
|
102
|
-
"change.difference":
|
|
103
|
-
"change.percent":
|
|
104
|
-
change: c.words[
|
|
174
|
+
"first.name": w(W.row),
|
|
175
|
+
"first.value": y(W.y, W.cell),
|
|
176
|
+
"last.name": w(G.row),
|
|
177
|
+
"last.value": y(G.y, G.cell),
|
|
178
|
+
"change.difference": y(Math.abs(G.y - W.y), G.cell),
|
|
179
|
+
"change.percent": b(Math.abs(K)),
|
|
180
|
+
change: c.words[U(K)]
|
|
105
181
|
},
|
|
106
|
-
when:
|
|
107
|
-
},
|
|
108
|
-
if (!
|
|
109
|
-
chart:
|
|
110
|
-
notes:
|
|
111
|
-
extremes:
|
|
112
|
-
range:
|
|
113
|
-
change:
|
|
182
|
+
when: U(K)
|
|
183
|
+
}, J = r(O, c.flat, c.outliers);
|
|
184
|
+
if (!J) return {
|
|
185
|
+
chart: D,
|
|
186
|
+
notes: N,
|
|
187
|
+
extremes: I,
|
|
188
|
+
range: z,
|
|
189
|
+
change: q,
|
|
190
|
+
groups: V,
|
|
114
191
|
trend: null,
|
|
115
192
|
outliers: null
|
|
116
193
|
};
|
|
117
|
-
let { course:
|
|
194
|
+
let { course: Y, line: X, outside: Z } = J, Q = {
|
|
118
195
|
values: {
|
|
119
|
-
trend: c.words[
|
|
120
|
-
"trend.percent":
|
|
121
|
-
"trend.from":
|
|
122
|
-
"trend.to":
|
|
123
|
-
"flat.percent":
|
|
124
|
-
"outliers.percent":
|
|
196
|
+
trend: c.words[Y],
|
|
197
|
+
"trend.percent": b(Math.abs(H(X(G.x) - X(W.x), X(W.x)))),
|
|
198
|
+
"trend.from": y(X(W.x), W.cell),
|
|
199
|
+
"trend.to": y(X(G.x), G.cell),
|
|
200
|
+
"flat.percent": b(c.flat),
|
|
201
|
+
"outliers.percent": b(c.outliers)
|
|
125
202
|
},
|
|
126
|
-
when:
|
|
203
|
+
when: Y
|
|
127
204
|
};
|
|
128
|
-
return
|
|
129
|
-
chart:
|
|
130
|
-
notes:
|
|
131
|
-
extremes:
|
|
132
|
-
range:
|
|
133
|
-
change:
|
|
134
|
-
|
|
205
|
+
return Y === "unclear" ? {
|
|
206
|
+
chart: D,
|
|
207
|
+
notes: N,
|
|
208
|
+
extremes: I,
|
|
209
|
+
range: z,
|
|
210
|
+
change: q,
|
|
211
|
+
groups: V,
|
|
212
|
+
trend: Q
|
|
135
213
|
} : {
|
|
136
|
-
chart:
|
|
137
|
-
notes:
|
|
138
|
-
extremes:
|
|
139
|
-
range:
|
|
140
|
-
change:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
214
|
+
chart: D,
|
|
215
|
+
notes: N,
|
|
216
|
+
extremes: I,
|
|
217
|
+
range: z,
|
|
218
|
+
change: q,
|
|
219
|
+
groups: V,
|
|
220
|
+
trend: Q,
|
|
221
|
+
outliers: Z.length ? {
|
|
222
|
+
values: { "outliers.count": e(Z.length, 0, l).join("") },
|
|
223
|
+
counts: { "outliers.count": Z.length },
|
|
224
|
+
items: Z.map((e) => j({
|
|
225
|
+
name: w(e.row),
|
|
226
|
+
value: y(e.y, e.cell),
|
|
227
|
+
expected: y(X(e.x), e.cell),
|
|
228
|
+
deviation: b(Math.abs(H(e.y - X(e.x), X(e.x)))),
|
|
229
|
+
side: c.words[e.y > X(e.x) ? "above" : "below"]
|
|
230
|
+
}, e.y))
|
|
152
231
|
} : null
|
|
153
232
|
};
|
|
154
|
-
},
|
|
155
|
-
let [a, o] = r.delimiters, s = RegExp(`${
|
|
233
|
+
}, T = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), E = (e, t, n, r, i) => {
|
|
234
|
+
let [a, o] = r.delimiters, s = RegExp(`${T(a)}([\\w.]+)(\\|.*?)?${T(o)}`, "g"), c = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), l = [];
|
|
156
235
|
for (; c.nextNode();) l.push(c.currentNode);
|
|
157
236
|
for (let e of l) {
|
|
158
237
|
let r = e.textContent ?? "", a = [], o = 0;
|
|
159
238
|
for (let e of r.matchAll(s)) {
|
|
160
239
|
let [s, c, l] = e, u = t[c];
|
|
161
|
-
if (u === void 0)
|
|
240
|
+
if (u === void 0) b(`A summary has the placeholder ${s}, which no analysis fills.`);
|
|
162
241
|
else {
|
|
163
242
|
if (l && n[c] !== void 0) {
|
|
164
|
-
let e = Object.fromEntries(l.slice(1).split("|").map((e) => [e.slice(0, e.indexOf(":")), e.slice(e.indexOf(":") + 1)])), t = e[new Intl.PluralRules(i).select(n[c])] ?? e.other;
|
|
243
|
+
let e = Object.fromEntries(l.slice(1).split("|").map((e) => [e.slice(0, e.indexOf(":")), e.slice(e.indexOf(":") + 1)])), t = e[new Intl.PluralRules(i, { type: v.has(c) ? "ordinal" : "cardinal" }).select(n[c])] ?? e.other;
|
|
165
244
|
t !== void 0 && (u = t.replace("#", typeof u == "string" ? u : u.textContent ?? ""));
|
|
166
245
|
}
|
|
167
246
|
a.push(r.slice(o, e.index), typeof u == "string" ? u : u.cloneNode(!0)), o = (e.index ?? 0) + s.length;
|
|
@@ -169,16 +248,59 @@ var s = {
|
|
|
169
248
|
}
|
|
170
249
|
a.length && (a.push(r.slice(o)), e.replaceWith(...a));
|
|
171
250
|
}
|
|
172
|
-
},
|
|
251
|
+
}, D = "data-summary-options", O = (e, t, r) => {
|
|
252
|
+
try {
|
|
253
|
+
return JSON.parse(e);
|
|
254
|
+
} catch {
|
|
255
|
+
console.warn(`[${n}] ${r} needs JSON.`, t);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
}, k = (e, t) => {
|
|
259
|
+
let n = e.getAttribute(`data-summary-${t}`)?.trim();
|
|
260
|
+
if (!n) return;
|
|
261
|
+
if (t === "locale") return n;
|
|
262
|
+
if (t === "words") return O(n, e, "data-summary-words");
|
|
263
|
+
if (t === "delimiters") {
|
|
264
|
+
let e = n.split(/\s+/);
|
|
265
|
+
return e.length === 2 ? e : void 0;
|
|
266
|
+
}
|
|
267
|
+
let r = Number.parseFloat(n);
|
|
268
|
+
return Number.isFinite(r) ? r : void 0;
|
|
269
|
+
}, A = (e, t) => {
|
|
270
|
+
let n = [];
|
|
271
|
+
for (let t = e; t; t = t.parentElement) {
|
|
272
|
+
let e = t.getAttribute(D), r = e ? O(e, t, D) : void 0;
|
|
273
|
+
r && typeof r == "object" && n.unshift(r);
|
|
274
|
+
}
|
|
275
|
+
let r = {};
|
|
276
|
+
for (let t of u) {
|
|
277
|
+
let n = k(e, t);
|
|
278
|
+
n !== void 0 && (r[t] = n);
|
|
279
|
+
}
|
|
280
|
+
n.push(r);
|
|
281
|
+
let i = t;
|
|
282
|
+
for (let e of n) {
|
|
283
|
+
let t = Object.fromEntries(Object.entries(e).filter(([e]) => u.includes(e)));
|
|
284
|
+
i = {
|
|
285
|
+
...i,
|
|
286
|
+
...t,
|
|
287
|
+
words: {
|
|
288
|
+
...i.words,
|
|
289
|
+
...t.words
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
return i;
|
|
294
|
+
}, j = 0, M = (e, t) => {
|
|
173
295
|
let n = e.dataset.summary;
|
|
174
296
|
if (n === void 0) return !0;
|
|
175
|
-
if (
|
|
297
|
+
if (_.includes(n) || b(`A summary asks for the analysis "${n}", which does not exist.`), !(n in t)) return !1;
|
|
176
298
|
let r = t[n], i = e.dataset.when;
|
|
177
299
|
return e.hasAttribute("data-none") ? !r : !!r && (!i || r.when === i);
|
|
178
|
-
},
|
|
300
|
+
}, N = (e, t, n, r) => {
|
|
179
301
|
let i = e.cloneNode(!0);
|
|
180
302
|
for (let e of [
|
|
181
|
-
|
|
303
|
+
p,
|
|
182
304
|
"hidden",
|
|
183
305
|
"id",
|
|
184
306
|
"data-summary",
|
|
@@ -187,9 +309,9 @@ var s = {
|
|
|
187
309
|
"data-series",
|
|
188
310
|
...n.langattribute ? [n.langattribute] : []
|
|
189
311
|
]) i.removeAttribute(e);
|
|
190
|
-
i.setAttribute(
|
|
312
|
+
i.setAttribute(m, "");
|
|
191
313
|
let a = Object.values(t).filter((e) => !!e), o = Object.assign({}, ...a.map((e) => e.values)), s = Object.assign({}, ...a.map((e) => e.counts ?? {}));
|
|
192
|
-
for (let e of i.querySelectorAll("[data-summary]")) if (!
|
|
314
|
+
for (let e of i.querySelectorAll("[data-summary]")) if (!M(e, t)) e.remove();
|
|
193
315
|
else for (let t of [
|
|
194
316
|
"data-summary",
|
|
195
317
|
"data-none",
|
|
@@ -198,72 +320,87 @@ var s = {
|
|
|
198
320
|
for (let e of i.querySelectorAll("[data-each]")) {
|
|
199
321
|
let i = (t[e.dataset.each ?? ""]?.items ?? []).map((t) => {
|
|
200
322
|
let i = e.cloneNode(!0);
|
|
201
|
-
return i.removeAttribute("data-each"),
|
|
323
|
+
return i.removeAttribute("data-each"), E(i, {
|
|
202
324
|
...o,
|
|
203
|
-
...t
|
|
204
|
-
},
|
|
205
|
-
|
|
325
|
+
...t.values
|
|
326
|
+
}, {
|
|
327
|
+
...s,
|
|
328
|
+
...t.counts
|
|
329
|
+
}, n, r), i;
|
|
330
|
+
});
|
|
331
|
+
if (e.matches("tr, li")) {
|
|
332
|
+
e.replaceWith(...i);
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
let a = new Intl.ListFormat(r, { type: "conjunction" }).formatToParts(i.map((e, t) => String(t)));
|
|
206
336
|
e.replaceWith(...a.map((e) => e.type === "element" ? i[Number(e.value)] : e.value));
|
|
207
337
|
}
|
|
208
|
-
return
|
|
209
|
-
},
|
|
210
|
-
let
|
|
211
|
-
...
|
|
212
|
-
...
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
338
|
+
return E(i, o, s, n, r), i;
|
|
339
|
+
}, P = (e, n = l.config ?? {}) => {
|
|
340
|
+
let r = A(e, {
|
|
341
|
+
...c,
|
|
342
|
+
...n,
|
|
343
|
+
words: {
|
|
344
|
+
...c.words,
|
|
345
|
+
...n.words
|
|
346
|
+
}
|
|
347
|
+
}), i = r.locale || document.documentElement.lang || void 0, a = e.querySelector(`:scope > .${d}`);
|
|
348
|
+
if (!a || !t(e)?.querySelector("tbody tr")) return;
|
|
349
|
+
a.id || (a.id = `tablechart-summary-${++j}`);
|
|
350
|
+
let o = (e.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
|
|
351
|
+
o.includes(a.id) || e.setAttribute("aria-describedby", [...o, a.id].join(" "));
|
|
352
|
+
for (let e of a.querySelectorAll(`:scope > [${m}]`)) e.remove();
|
|
353
|
+
let s = /* @__PURE__ */ new Map();
|
|
354
|
+
for (let t of a.querySelectorAll(":scope > *")) {
|
|
355
|
+
t.setAttribute(p, ""), t.hidden = !0;
|
|
356
|
+
let n = String(g[e.getAttribute("data-chart") ?? ""] ?? 1), a = t.dataset.series === "total" ? -1 : Math.max(1, Number.parseInt(t.dataset.series ?? n, 10) || 1) - 1;
|
|
357
|
+
s.has(a) || s.set(a, w(e, a, r, i));
|
|
358
|
+
let o = s.get(a);
|
|
359
|
+
M(t, o) && t.after(N(t, o, r, i));
|
|
226
360
|
}
|
|
227
|
-
},
|
|
228
|
-
let
|
|
229
|
-
...
|
|
361
|
+
}, F = (e = {}) => {
|
|
362
|
+
let n = {
|
|
363
|
+
...c,
|
|
230
364
|
...e,
|
|
231
365
|
words: {
|
|
232
|
-
...
|
|
366
|
+
...c.words,
|
|
233
367
|
...e.words
|
|
234
368
|
}
|
|
235
369
|
};
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
let
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
370
|
+
if (l.config) return;
|
|
371
|
+
l.config = n;
|
|
372
|
+
let r = () => Array.from(document.querySelectorAll(n.selector)).filter((e) => e.querySelector(`:scope > .${d}`)), i = /* @__PURE__ */ new Set(), a = document.documentElement, o = () => {
|
|
373
|
+
i.size || a.hasAttribute("data-summary-ready") || !r().every((e) => t(e)?.querySelector("tbody tr")) || (a.setAttribute(f, ""), document.dispatchEvent(new CustomEvent("tablechart:summary-ready")));
|
|
374
|
+
}, s = (e) => {
|
|
375
|
+
a.removeAttribute(f), i.size || requestAnimationFrame(() => {
|
|
376
|
+
let e = [...i];
|
|
377
|
+
i.clear();
|
|
378
|
+
for (let t of e) P(t, n);
|
|
379
|
+
o();
|
|
380
|
+
}), i.add(e);
|
|
381
|
+
}, u = /* @__PURE__ */ new WeakSet(), m = (e) => {
|
|
382
|
+
let t = [...e.querySelectorAll(`:scope > .${d} > [${p}]`), ...e.querySelectorAll(":scope > table")];
|
|
383
|
+
for (let n of t) u.has(n) || (u.add(n), new MutationObserver(() => s(e)).observe(n, {
|
|
247
384
|
subtree: !0,
|
|
248
385
|
childList: !0,
|
|
249
386
|
characterData: !0
|
|
250
387
|
}));
|
|
251
|
-
},
|
|
252
|
-
|
|
388
|
+
}, h = (e) => {
|
|
389
|
+
P(e, n), m(e);
|
|
253
390
|
};
|
|
254
|
-
for (let e of
|
|
255
|
-
document.addEventListener("tablechart:table", (e) => {
|
|
256
|
-
let
|
|
257
|
-
|
|
258
|
-
}),
|
|
259
|
-
for (let e of
|
|
391
|
+
for (let e of r()) h(e);
|
|
392
|
+
o(), document.addEventListener("tablechart:table", (e) => {
|
|
393
|
+
let t = e.target;
|
|
394
|
+
t instanceof HTMLElement && t.matches(n.selector) && t.querySelector(":scope > .chart-summary") && (h(t), o());
|
|
395
|
+
}), n.locale || new MutationObserver(() => {
|
|
396
|
+
for (let e of r()) s(e);
|
|
260
397
|
}).observe(document.documentElement, {
|
|
261
398
|
attributes: !0,
|
|
262
399
|
attributeFilter: ["lang"]
|
|
263
400
|
});
|
|
264
|
-
},
|
|
265
|
-
init:
|
|
266
|
-
fill:
|
|
267
|
-
defaults:
|
|
401
|
+
}, I = {
|
|
402
|
+
init: F,
|
|
403
|
+
fill: P,
|
|
404
|
+
defaults: c
|
|
268
405
|
};
|
|
269
|
-
export {
|
|
406
|
+
export { I as Summary, P as fill, F as init, c as summaryDefaults };
|