@martinomagnifico/tablechart 1.1.2 → 1.2.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,5 +1,5 @@
1
- //#region src/js/config.ts
2
- var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablechart-bar", i = "tablechart-rule", a = "tablechart-line", o = "tablechart-reference", s = "tablechart-head", c = "tablechart-slice", l = "tablechart-name", u = "tablechart-legend", d = "tablechart-point", f = "tablechart-hole", p = "tablechart-centre", m = "tablechart-break", h = "is-placed", g = "tablechart-sr", _ = "is-shown", v = "is-printing", y = "tablechart-queued", b = "tablechart-axis", x = "tablechart-tick", S = "tablechart-grid", C = 1e3, w = {
1
+ // src/js/config.ts
2
+ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablechart-bar", i = "tablechart-rule", a = "tablechart-line", o = "tablechart-reference", s = "tablechart-quadrant", c = "tablechart-head", l = "tablechart-slice", u = "tablechart-series", d = "tablechart-area", f = "tablechart-name", p = "tablechart-legend", m = "tablechart-point", h = "tablechart-hole", g = "tablechart-centre", _ = "tablechart-break", v = "is-placed", y = "tablechart-sr", b = "is-shown", x = "is-printing", S = "is-at-once", C = "tablechart-queued", w = "tablechart-axis", T = "tablechart-tick", E = "tablechart-grid", D = 1e3, O = {
3
3
  selector: "[data-chart]",
4
4
  aspect: .38,
5
5
  barfill: .58,
@@ -7,6 +7,8 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
7
7
  animate: !0,
8
8
  entrance: .5,
9
9
  labels: "outside",
10
+ values: "auto",
11
+ ticks: !0,
10
12
  shape: "straight",
11
13
  legend: !1,
12
14
  axis: !1,
@@ -15,6 +17,8 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
15
17
  tooltip: "auto",
16
18
  tooltipparent: null,
17
19
  table: "never",
20
+ tablelimit: 15,
21
+ summary: "auto",
18
22
  totallabel: "Total",
19
23
  controls: !0,
20
24
  previouslabel: "Previous",
@@ -23,29 +27,62 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
23
27
  threshold: .5,
24
28
  replay: !1,
25
29
  langattribute: "data-i18n"
26
- }, T = "cubic-bezier(0.3, 0.3, 0.6, 1)", E = (e, t, n = 1) => ({
30
+ }, k = "cubic-bezier(0.3, 0.3, 0.6, 1)", A = (e, t, n = 1) => ({
27
31
  start: e,
28
32
  span: t,
29
- easing: e + t >= n - 1e-4 ? T : "linear"
30
- }), D = (e, t) => `${e}:${t}`, O = "http://www.w3.org/2000/svg", k = (e) => Math.round(e * 100) / 100, A = (e, t = {}) => {
31
- let n = document.createElementNS(O, e);
33
+ easing: e + t >= n - 1e-4 ? k : "linear"
34
+ }), j = (e, t) => `${e}:${t}`, M = "http://www.w3.org/2000/svg", N = (e) => Math.round(e * 100) / 100, P = (e, t = {}) => {
35
+ let n = document.createElementNS(M, e);
32
36
  for (let e in t) {
33
37
  let r = t[e];
34
- n.setAttribute(e, String(typeof r == "number" ? k(r) : r));
38
+ n.setAttribute(e, String(typeof r == "number" ? N(r) : r));
35
39
  }
36
40
  return n;
37
- }, j = (e, t) => [e, ...t.classes].join(" "), M = (e, t) => {
41
+ }, F = (e, t) => [e, ...t.classes].join(" "), I = (e, t) => {
38
42
  let n = document.createElement("span");
39
43
  return n.className = e, n.inert = !0, t.appendChild(n), n;
40
- }, N = (e, t, n, r, i) => {
44
+ }, L = (e, t, n, r, i) => {
41
45
  e.style.left = `${t / r * 100}%`, e.style.top = `${n / i * 100}%`;
42
- }, P = 0, ee = (e, t, n, r, i, a) => {
46
+ }, R = 0, z = 0, B = (e) => {
47
+ let t = e.querySelector(":scope > defs");
48
+ return t || (t = P("defs"), e.prepend(t)), t;
49
+ }, V = (e) => {
50
+ if (e.tagName === "circle") {
51
+ let [t, n, r] = [
52
+ "cx",
53
+ "cy",
54
+ "r"
55
+ ].map((t) => Number(e.getAttribute(t)) || 0);
56
+ return `M${N(t - r)},${N(n)}a${N(r)},${N(r)} 0 1 0 ${N(2 * r)},0a${N(r)},${N(r)} 0 1 0 ${N(-2 * r)},0z`;
57
+ }
58
+ if (e.tagName === "polygon") return `M${(e.getAttribute("points") ?? "").trim().split(/\s+/).join("L")}z`;
59
+ let [t, n, r, i, a, o] = [
60
+ "x",
61
+ "y",
62
+ "width",
63
+ "height",
64
+ "rx",
65
+ "ry"
66
+ ].map((t) => Number(e.getAttribute(t)) || 0), s = Math.min(a, r / 2), c = Math.min(o, i / 2), l = (e, t) => s && c ? `a${N(s)},${N(c)} 0 0 1 ${N(e)},${N(t)}` : "";
67
+ return `M${N(t + s)},${N(n)}h${N(r - 2 * s)}${l(s, c)}v${N(i - 2 * c)}${l(-s, c)}h${N(2 * s - r)}${l(-s, -c)}v${N(2 * c - i)}${l(s, -c)}z`;
68
+ }, H = (e, t, n, r, i) => {
69
+ if (!t.length || !i.length) return;
70
+ let a = `tablechart-clip-${++z}`, o = P("clipPath", {
71
+ id: a,
72
+ clipPathUnits: "userSpaceOnUse"
73
+ }), s = `M${-n},${-r}h${n * 3}v${r * 3}h${-n * 3}z`;
74
+ o.appendChild(P("path", {
75
+ d: s + t.map(V).join(""),
76
+ "clip-rule": "evenodd"
77
+ })), B(e).appendChild(o);
78
+ for (let e of i) e.setAttribute("clip-path", `url(#${a})`);
79
+ }, U = (e, t, n, r, i, a) => {
43
80
  if (!t.length) return;
44
- let o = `tablechart-cut-${++P}`, s = A("mask", {
81
+ let o = `tablechart-cut-${++R}`, s = P("mask", {
45
82
  id: o,
46
83
  maskUnits: "userSpaceOnUse"
47
84
  });
48
- s.appendChild(A("rect", {
85
+ s.appendChild(P("rect", {
49
86
  x: -n,
50
87
  y: -r,
51
88
  width: n * 3,
@@ -53,14 +90,14 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
53
90
  fill: "white"
54
91
  }));
55
92
  for (let e of t) e.setAttribute("fill", "black"), s.appendChild(e);
56
- let c = e.querySelector(":scope > defs");
57
- if (c || (c = A("defs"), e.prepend(c)), c.appendChild(s), i) {
93
+ let c = B(e);
94
+ if (c.appendChild(s), i) {
58
95
  for (let e of i) e.setAttribute("mask", `url(#${o})`);
59
96
  return;
60
97
  }
61
98
  let l = null;
62
- for (let t of Array.from(e.childNodes)) t !== c && (a && t instanceof Element && t.matches(a) ? (l = null, e.appendChild(t)) : (l ?? (l = e.appendChild(A("g", { mask: `url(#${o})` }))), l.appendChild(t)));
63
- }, F = 0, I = (e) => Array.from(e.querySelectorAll(`.${r}`)).map((e) => {
99
+ for (let t of Array.from(e.childNodes)) t !== c && (a && t instanceof Element && t.matches(a) ? (l = null, e.appendChild(t)) : (l ?? (l = e.appendChild(P("g", { mask: `url(#${o})` }))), l.appendChild(t)));
100
+ }, ee = 0, te = (e) => Array.from(e.querySelectorAll(`.${r}`)).map((e) => {
64
101
  let t = e.tagName === "rect" ? [e] : Array.from(e.querySelectorAll("rect")), n = (e, t) => Number(e.getAttribute(t)), r = Math.min(...t.map((e) => n(e, "x"))), i = Math.min(...t.map((e) => n(e, "y"))), a = Math.max(...t.map((e) => n(e, "x") + n(e, "width"))), o = Math.max(...t.map((e) => n(e, "y") + n(e, "height"))), s = ["--start", "--span"].map((t) => e.style.getPropertyValue(t) && `${t}:${e.style.getPropertyValue(t)}`).filter(Boolean).join("; ");
65
102
  return {
66
103
  row: Number(e.dataset.row),
@@ -71,7 +108,7 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
71
108
  sideways: e.dataset.grow === "right",
72
109
  part: s
73
110
  };
74
- }), L = {
111
+ }), ne = {
75
112
  create: () => null,
76
113
  draw(e, t, n) {
77
114
  let { rows: r, y: i, svg: a, breakAt: o } = n;
@@ -98,29 +135,29 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
98
135
  [c + 2 * l, t + o],
99
136
  [c + i, t - o]
100
137
  ];
101
- }, l = (e, t = !1) => e.map(([e, t], n) => `${n === 0 ? "M" : "L"} ${e.toFixed(1)} ${t.toFixed(1)}`).join(" ") + (t ? " Z" : ""), u = `tablechart-break-${++F}`, d = A("mask", {
138
+ }, l = (e, t = !1) => e.map(([e, t], n) => `${n === 0 ? "M" : "L"} ${e.toFixed(1)} ${t.toFixed(1)}`).join(" ") + (t ? " Z" : ""), u = `tablechart-break-${++ee}`, d = P("mask", {
102
139
  id: u,
103
140
  maskUnits: "userSpaceOnUse"
104
141
  });
105
- d.appendChild(A("rect", {
106
- x: -C,
142
+ d.appendChild(P("rect", {
143
+ x: -D,
107
144
  y: -n.height,
108
- width: C * 3,
145
+ width: D * 3,
109
146
  height: n.height * 3,
110
147
  fill: "white"
111
148
  }));
112
149
  let f = [], p = i(o);
113
- for (let e of I(a)) {
150
+ for (let e of te(a)) {
114
151
  let t = e.sideways ? n.breakX : p;
115
152
  if (t === void 0 || !(e.sideways ? e.x < t && e.x + e.width > t : e.y < p && e.y + e.height > p)) continue;
116
153
  let [i, o] = e.sideways ? [c(e, t), c(e, t + n.breakGap)] : [c(e, p - n.breakGap), c(e, p)];
117
- d.appendChild(A("path", {
154
+ d.appendChild(P("path", {
118
155
  d: l([...i, ...o.slice().reverse()], !0),
119
156
  fill: "black"
120
157
  })), f.push(i, o);
121
- let s = [D("--after", r[e.row - 1]?.slot ?? 0), e.part].filter(Boolean).join("; ");
122
- for (let e of [i, o]) a.appendChild(A("path", {
123
- class: m,
158
+ let s = [j("--after", r[e.row - 1]?.slot ?? 0), e.part].filter(Boolean).join("; ");
159
+ for (let e of [i, o]) a.appendChild(P("path", {
160
+ class: _,
124
161
  "data-part": "edge",
125
162
  "data-note": n.note,
126
163
  d: l(e),
@@ -128,22 +165,22 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
128
165
  }));
129
166
  }
130
167
  if (!f.length) return;
131
- let h = Array.from(a.querySelectorAll(`.${m}`)), g = A("g", { mask: `url(#${u})` });
132
- for (let e of Array.from(a.childNodes)) h.includes(e) || g.appendChild(e);
133
- let _ = A("defs");
134
- _.appendChild(d), a.prepend(_, g);
168
+ let m = Array.from(a.querySelectorAll(`.${_}`)), h = P("g", { mask: `url(#${u})` });
169
+ for (let e of Array.from(a.childNodes)) m.includes(e) || h.appendChild(e);
170
+ let g = P("defs");
171
+ g.appendChild(d), a.prepend(g, h);
135
172
  }
136
- }, R = (e) => {
173
+ }, W = (e) => {
137
174
  let t = -Infinity;
138
175
  for (let n of e) t = Math.max(t, n);
139
176
  return t;
140
- }, z = (e) => (e.split(/[.,]/)[1] || "").length, te = (e, t) => new Intl.NumberFormat(t || document.documentElement.lang || void 0, {
177
+ }, re = (e) => (e.split(/[.,]/)[1] || "").length, G = (e, t) => new Intl.NumberFormat(t || document.documentElement.lang || void 0, {
141
178
  minimumFractionDigits: e,
142
179
  maximumFractionDigits: e
143
- }), B = (e, t, n) => {
144
- let r = te(t, n).formatToParts(e), i = r[0]?.type === "minusSign" ? r[0].value : "";
180
+ }), ie = (e, t, n) => {
181
+ let r = G(t, n).formatToParts(e), i = r[0]?.type === "minusSign" ? r[0].value : "";
145
182
  return [i, r.slice(+!!i).map((e) => e.value).join("")];
146
- }, V = (e) => Number.parseFloat((e.match(/-?[\d.,]+/) || ["NaN"])[0].replace(",", ".")), H = (e, t) => {
183
+ }, K = (e) => Number.parseFloat((e.match(/-?[\d.,]+/) || ["NaN"])[0].replace(",", ".")), q = (e, t) => {
147
184
  let n = document.createElement("span");
148
185
  if (n.className = "tablechart-badge", n.inert = !0, e.childElementCount > 0) for (let t of Array.from(e.children)) n.appendChild(t.cloneNode(!0));
149
186
  else {
@@ -152,44 +189,44 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
152
189
  t && n.setAttribute("data-i18n", t);
153
190
  }
154
191
  return t.appendChild(n), n;
155
- }, U = (t, n, r, i, a = "%") => {
156
- let o = t?.textContent || "", s = V(o), c = a ? .5 : .5 * 10 ** -z(o.match(/-?[\d.,]+/)?.[0] ?? ""), l = Number.isNaN(s) ? !0 : Math.abs(n - s) <= c + 1e-9, u = {
192
+ }, ae = (t, n, r, i, a = "%") => {
193
+ let o = t?.textContent || "", s = K(o), c = a ? .5 : .5 * 10 ** -re(o.match(/-?[\d.,]+/)?.[0] ?? ""), l = Number.isNaN(s) ? !0 : Math.abs(n - s) <= c + 1e-9, u = {
157
194
  label: r,
158
195
  computed: n,
159
196
  stated: s,
160
197
  agrees: l
161
198
  };
162
199
  i.checks.push(u), l || console.warn(`[${e}] An annotation reads ${s}${a}, but ${r} is ${Number(n.toFixed(2))}${a}. The chart shows your number.`);
163
- }, W = (e, t) => (t - e) / Math.abs(e) * 100, ne = (e, t) => {
200
+ }, oe = (e, t) => (t - e) / Math.abs(e) * 100, se = (e, t) => {
164
201
  let n = (t, n) => {
165
202
  let r = Number.parseInt(e.getAttribute(t) ?? "", 10);
166
203
  return Number.isFinite(r) ? r - 1 : n;
167
204
  };
168
205
  return [n("data-from", 0), n("data-to", t - 1)];
169
- }, re = {
170
- create: H,
206
+ }, ce = {
207
+ create: q,
171
208
  draw(t, n, r) {
172
- let { rows: i, cx: o, y: c, unit: l, labelHeight: u, badgeHeight: d, height: f, svg: p, after: m } = r, [h, g] = ne(t, i.length), _ = i[h], v = i[g];
209
+ let { rows: i, cx: o, y: s, unit: l, labelHeight: u, badgeHeight: d, height: f, svg: p, after: m } = r, [h, g] = se(t, i.length), _ = i[h], v = i[g];
173
210
  if (!_ || !v) {
174
211
  console.warn(`[${e}] A bracket points at a row that is not there (row ${h + 1} to ${g + 1}, of ${i.length}).`);
175
212
  return;
176
213
  }
177
- let y = 7 * l, b = 4 * l, x = o(h), S = o(g), w = Math.min(c(_.value), c(v.value)) - u - b - d * .9, T = (e) => c(e) - u - b, E = `M ${x} ${T(_.value)} L ${x} ${w} L ${S} ${w} L ${S} ${T(v.value) - y}`, O = (T(_.value) - w + Math.abs(S - x) + (T(v.value) - y - w)) / l + 1;
178
- p.appendChild(A("path", {
214
+ let y = 7 * l, b = 4 * l, x = o(h), S = o(g), C = Math.min(s(_.value), s(v.value)) - u - b - d * .9, w = (e) => s(e) - u - b, T = `M ${x} ${w(_.value)} L ${x} ${C} L ${S} ${C} L ${S} ${w(v.value) - y}`, E = (w(_.value) - C + Math.abs(S - x) + (w(v.value) - y - C)) / l + 1;
215
+ p.appendChild(P("path", {
179
216
  class: a,
180
217
  "data-note": r.note,
181
- d: E,
182
- style: `--len:${O.toFixed(1)}; ${D("--after", m)}`
218
+ d: T,
219
+ style: `--len:${E.toFixed(1)}; ${j("--after", m)}`
183
220
  }));
184
- let k = T(v.value);
185
- p.appendChild(A("polygon", {
186
- class: s,
221
+ let O = w(v.value);
222
+ p.appendChild(P("polygon", {
223
+ class: c,
187
224
  "data-note": r.note,
188
- points: `${S},${k} ${S - y * .45},${k - y} ${S + y * .45},${k - y}`,
189
- style: D("--after", m)
190
- })), n && (N(n, (x + S) / 2, w, C, f), n.style.setProperty("--after", String(m))), U(n, W(_.value, v.value), `${_.value} to ${v.value}`, r);
225
+ points: `${S},${O} ${S - y * .45},${O - y} ${S + y * .45},${O - y}`,
226
+ style: j("--after", m)
227
+ })), n && (L(n, (x + S) / 2, C, D, f), n.style.setProperty("--after", String(m))), ae(n, oe(_.value, v.value), `${_.value} to ${v.value}`, r);
191
228
  }
192
- }, ie = (e, t) => e[0] < t[0] + t[2] && t[0] < e[0] + e[2] && e[1] < t[1] + t[3] && t[1] < e[1] + e[3], G = (e, t) => e[0] >= t[0] && e[1] >= t[1] && e[0] + e[2] <= t[0] + t[2] && e[1] + e[3] <= t[1] + t[3], ae = (e, t, n) => {
229
+ }, le = (e, t) => e[0] < t[0] + t[2] && t[0] < e[0] + e[2] && e[1] < t[1] + t[3] && t[1] < e[1] + e[3], ue = (e, t) => e[0] >= t[0] && e[1] >= t[1] && e[0] + e[2] <= t[0] + t[2] && e[1] + e[3] <= t[1] + t[3], de = (e, t, n) => {
193
230
  if (e.length > 400) return e.map(() => null);
194
231
  let r = 1;
195
232
  for (let t of e) for (let [, , e, n] of t) r = Math.max(r, e, n);
@@ -199,21 +236,120 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
199
236
  return a;
200
237
  }, o = (e) => {
201
238
  for (let t of a(e)) i.get(t)?.push(e) ?? i.set(t, [e]);
202
- }, s = (e) => G(e, n) && a(e).every((t) => !i.get(t)?.some((t) => ie(e, t)));
239
+ }, s = (e) => ue(e, n) && a(e).every((t) => !i.get(t)?.some((t) => le(e, t)));
203
240
  return t.forEach(o), e.map((e) => {
204
241
  let t = e.findIndex(s);
205
242
  return t < 0 ? null : (o(e[t]), t);
206
243
  });
207
- }, K = /* @__PURE__ */ new WeakMap(), oe = (e) => {
244
+ }, fe = /* @__PURE__ */ new WeakMap(), pe = (e) => {
208
245
  let t = [...e].filter((e) => !!e), n = t.map((e) => ({
209
246
  width: e.offsetWidth,
210
247
  height: e.offsetHeight
211
248
  }));
212
- t.forEach((e, t) => K.set(e, n[t]));
213
- }, q = (e) => K.get(e) ?? {
249
+ t.forEach((e, t) => fe.set(e, n[t]));
250
+ }, J = (e) => fe.get(e) ?? {
214
251
  width: e.offsetWidth,
215
252
  height: e.offsetHeight
216
- }, se = (e, t, n) => {
253
+ }, me = 6, he = (e, t, n) => e.some((e) => J(e).width * n > t - me * n), ge = (e, t, n) => t >= J(e).height * n * 1.6, _e = (e, t, n) => t >= J(e).width * n * 1.5, ve = (e, t, n, r, i = .7) => {
254
+ e.style.setProperty(r, "1");
255
+ let a = 1;
256
+ for (let e of t) {
257
+ let { size: t, room: r } = n(e);
258
+ t > r && (a = Math.min(a, r / t));
259
+ }
260
+ let o = a >= i ? a : 0;
261
+ return e.style.setProperty(r, String(o || i)), o;
262
+ }, ye = (e, t) => (e.sort((e, t) => e.y - t.y), e.forEach((n, r) => {
263
+ let i = e[r - 1];
264
+ i && n.y < i.y + t && (n.y = i.y + t);
265
+ }), e), be = {
266
+ outside: [.5, 1],
267
+ below: [.5, 0],
268
+ after: [0, .5],
269
+ before: [1, .5]
270
+ }, Y = (e, t, n, r, i = [.5, .5]) => {
271
+ let [a, o] = be[e.dataset.place ?? ""] ?? i, { width: s, height: c } = J(e);
272
+ return [
273
+ Number.parseFloat(e.style.left) / 100 * n - s * t * a,
274
+ Number.parseFloat(e.style.top) / 100 * r - c * t * o,
275
+ s * t,
276
+ c * t
277
+ ];
278
+ }, xe = (e, t, n) => {
279
+ for (let r of e) {
280
+ if (r.dataset.place === "none" || !r.style.left) continue;
281
+ let [e] = be[r.dataset.place ?? ""] ?? [.5, .5], i = J(r).width * t, a = Number.parseFloat(r.style.left) / 100 * n, o = Math.min(Math.max(a, i * e), n - i * (1 - e));
282
+ o !== a && (r.style.left = `${o / n * 100}%`);
283
+ }
284
+ }, Se = (e, t, n, r) => {
285
+ let i = e.filter((e) => e.dataset.place !== "none" && !e.hasAttribute("data-left-out")), a = Ce(i, t, n, r);
286
+ i.forEach((e, t) => {
287
+ t % a && e.setAttribute("data-left-out", "");
288
+ });
289
+ }, Ce = (e, t, n, r) => {
290
+ if (e.length < 2) return 1;
291
+ let i = e.map((e) => Y(e, t, n, r)), a = 2 * t, o = (e, t) => e[0] + e[2] + a <= t[0] || t[0] + t[2] + a <= e[0] || e[1] + e[3] <= t[1] || t[1] + t[3] <= e[1], s = 1;
292
+ for (; s < e.length && i.some((e, t) => t >= s && t % s === 0 && !o(i[t - s], e));) s++;
293
+ return s;
294
+ }, we = {
295
+ create(e, t) {
296
+ if (!e.textContent?.trim()) return null;
297
+ let n = q(e, t);
298
+ return n.dataset.kind = "note", n;
299
+ },
300
+ draw(t, n, r) {
301
+ let { rows: i, cx: a, y: s, height: c, unit: l, svg: u, after: d, seriesValues: f } = r;
302
+ if (r.x || r.centre || r.categories[0]?.parentElement?.dataset.place === "beside") {
303
+ console.warn(`[${e}] A note works on a chart with its rows across, such as a line or column chart.`);
304
+ return;
305
+ }
306
+ let p = (t.getAttribute("data-row") ?? "").trim(), h = /^\d+$/.test(p) ? Number(p) - 1 : i.findIndex((e) => e.label === p);
307
+ if (h < 0 || h >= i.length) {
308
+ console.warn(`[${e}] A note is for row "${p}", which is not there.`);
309
+ return;
310
+ }
311
+ let g = a(h), _ = s(0);
312
+ if (u.insertBefore(P("line", {
313
+ class: o,
314
+ "data-kind": "note",
315
+ "data-note": r.note,
316
+ x1: g,
317
+ x2: g,
318
+ y1: 0,
319
+ y2: _,
320
+ style: j("--after", d)
321
+ }), u.querySelector(`:scope > .${m}`)), !n) return;
322
+ let v = J(n).width * l, y = J(n).height * l, b = 4 * l, x = f.flat().flatMap((e) => !e.style.left || e.dataset.place === "none" || e.hasAttribute("data-left-out") ? [] : [{
323
+ label: e,
324
+ box: Y(e, l, D, c)
325
+ }]), S = [0, y + b / 2].flatMap((e) => [
326
+ [
327
+ g - v / 2,
328
+ e,
329
+ v,
330
+ y
331
+ ],
332
+ [
333
+ g + b,
334
+ e,
335
+ v,
336
+ y
337
+ ],
338
+ [
339
+ g - b - v,
340
+ e,
341
+ v,
342
+ y
343
+ ]
344
+ ]), [C] = de([S], [...r.taken, ...x.map((e) => e.box)], [
345
+ 0,
346
+ 0,
347
+ D,
348
+ c
349
+ ]), w = S[C ?? 0];
350
+ if (r.taken.push(w), L(n, w[0] + v / 2, w[1] + y / 2, D, c), n.style.setProperty("--after", String(d)), C === null) for (let e of x) le(e.box, w) && e.label.setAttribute("data-left-out", "");
351
+ }
352
+ }, Te = (e, t, n) => {
217
353
  let r = n.reduce((e, t) => e + t, 0);
218
354
  if (e === "mean") return r ? t.reduce((e, t, r) => e + t * n[r], 0) / r : null;
219
355
  if (e === "median") {
@@ -226,31 +362,31 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
226
362
  }
227
363
  let i = Number.parseFloat(e);
228
364
  return Number.isFinite(i) ? i : null;
229
- }, ce = {
365
+ }, Ee = {
230
366
  create(e, t) {
231
367
  if (!e.textContent?.trim()) return null;
232
- let n = H(e, t);
368
+ let n = q(e, t);
233
369
  return n.dataset.kind = "reference", n;
234
370
  },
235
371
  draw(t, n, r) {
236
- let { rows: i, cx: a, y: s, x: c, height: l, unit: u, svg: f, after: p } = r, m = i.filter((e) => !e.isTotal && !e.missing), h = t.hasAttribute("data-name"), g = (t.getAttribute(h ? "data-name" : "data-value") ?? "").trim(), _, v, y;
372
+ let { rows: i, cx: a, y: s, x: c, height: l, unit: u, svg: d, after: f } = r, p = i.filter((e) => !e.isTotal && !e.missing), h = t.hasAttribute("data-name"), g = (t.getAttribute(h ? "data-name" : "data-value") ?? "").trim(), _, v, y;
237
373
  if (h) {
238
- let t = m.map((e) => V(e.label));
374
+ let t = p.map((e) => K(e.label));
239
375
  if (r.categories[0]?.parentElement?.dataset.place === "beside" || t.some(Number.isNaN)) {
240
376
  console.warn(`[${e}] A reference line among the names needs names that are numbers, under columns or points.`);
241
377
  return;
242
378
  }
243
- let n = se(g, t, m.map((e) => e.value)), o = n === null ? -1 : t.findIndex((e, r) => e <= n && n <= (t[r + 1] ?? e)), [s, c] = [m[o], m[o + 1] ?? m[o]].map((e) => a(i.indexOf(e))), l = n === null || o < 0 || t[o + 1] === void 0 || t[o + 1] === t[o] ? 0 : (n - t[o]) / (t[o + 1] - t[o]);
379
+ let n = Te(g, t, p.map((e) => e.value)), o = n === null ? -1 : t.findIndex((e, r) => e <= n && n <= (t[r + 1] ?? e)), [s, c] = [p[o], p[o + 1] ?? p[o]].map((e) => a(i.indexOf(e))), l = n === null || o < 0 || t[o + 1] === void 0 || t[o + 1] === t[o] ? 0 : (n - t[o]) / (t[o + 1] - t[o]);
244
380
  y = n, v = o < 0 ? null : s + l * (c - s), _ = !1;
245
381
  } else {
246
382
  let e = !!r.frame && t.getAttribute("data-axis") === "y", n = r.frame ? r.series.flatMap((e, t) => e.group ? [] : [t])[+!!e] ?? 0 : 0;
247
- y = se(g, m.map((e) => e.cells[n]?.value ?? e.value), m.map(() => 1)), _ = e || !c, v = y === null ? null : c && !e ? c(y) : s(y);
383
+ y = Te(g, p.map((e) => e.cells[n]?.value ?? e.value), p.map(() => 1)), _ = e || !c, v = y === null ? null : c && !e ? c(y) : s(y);
248
384
  }
249
385
  if (v === null || y === null) {
250
386
  console.warn(`[${e}] A reference line needs a number, "mean" or "median", not "${g}".`);
251
387
  return;
252
388
  }
253
- let [b, x, S, w] = r.frame ? [
389
+ let [b, x, S, C] = r.frame ? [
254
390
  r.frame[0],
255
391
  r.frame[1],
256
392
  r.frame[0] + r.frame[2],
@@ -258,10 +394,10 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
258
394
  ] : [
259
395
  0,
260
396
  0,
261
- i.length > 0 ? a(i.length - 1) + a(0) : C,
397
+ i.length > 0 ? a(i.length - 1) + a(0) : D,
262
398
  c ? l : s(0)
263
399
  ];
264
- if (f.insertBefore(A("line", {
400
+ if (d.insertBefore(P("line", {
265
401
  class: o,
266
402
  "data-note": r.note,
267
403
  ...t.getAttribute("data-line") === "dotted" && { "data-line": "dotted" },
@@ -274,11 +410,11 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
274
410
  x1: v,
275
411
  x2: v,
276
412
  y1: x,
277
- y2: w
413
+ y2: C
278
414
  },
279
- style: D("--after", p)
280
- }), f.querySelector(`:scope > .${d}`)), n) {
281
- let e = q(n).width * u, t = q(n).height * u, i = 4 * u, a = _ ? [
415
+ style: j("--after", f)
416
+ }), d.querySelector(`:scope > .${m}`)), n) {
417
+ let e = J(n).width * u, t = J(n).height * u, i = 4 * u, a = _ ? [
282
418
  [
283
419
  S - e,
284
420
  v - t / 2,
@@ -320,80 +456,80 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
320
456
  e,
321
457
  t
322
458
  ]
323
- ]), [o] = ae([a], r.taken, [
459
+ ]), [o] = de([a], r.taken, [
324
460
  0,
325
461
  0,
326
- C,
462
+ D,
327
463
  l
328
464
  ]), s = a[o ?? 0];
329
- r.taken.push(s), N(n, s[0] + e / 2, s[1] + t / 2, C, l), n.style.setProperty("--after", String(p)), (g === "mean" || g === "median") && U(n, y, `the ${g}`, r, "");
465
+ r.taken.push(s), L(n, s[0] + e / 2, s[1] + t / 2, D, l), n.style.setProperty("--after", String(f)), (g === "mean" || g === "median") && ae(n, y, `the ${g}`, r, "");
330
466
  }
331
467
  }
332
- }, le = (e, t, n) => ((t / e) ** (1 / n) - 1) * 100, J = {
333
- create: H,
468
+ }, De = (e, t, n) => ((t / e) ** (1 / n) - 1) * 100, Oe = {
469
+ create: q,
334
470
  draw(e, t, n) {
335
- let { rows: r, cx: i, y: o, unit: c, labelHeight: l, height: u, svg: d, values: f, after: p } = n, m = r[0], h = r[r.length - 1];
471
+ let { rows: r, cx: i, y: o, unit: s, labelHeight: l, height: u, svg: d, values: f, after: p } = n, m = r[0], h = r[r.length - 1];
336
472
  if (!m || !h) return;
337
- let g = l + 18 * c, _ = 10 * c, v = 10 * c, y = i(0), b = o(m.value) - g, x = i(r.length - 1), S = o(h.value) - g, w = 0;
473
+ let g = l + 18 * s, _ = 10 * s, v = 10 * s, y = i(0), b = o(m.value) - g, x = i(r.length - 1), S = o(h.value) - g, C = 0;
338
474
  r.forEach((e, t) => {
339
475
  let n = x === y ? 0 : (i(t) - y) / (x - y), r = b + n * (S - b) - (o(e.value) - g);
340
- r > w && (w = r);
341
- }), b -= w, S -= w;
342
- let T = x - y, E = S - b, O = Math.hypot(T, E) || 1, k = T / O, j = E / O;
343
- y -= k * _, b -= j * _, x += k * _, S += j * _;
344
- let M = Number.parseFloat(e.getAttribute("data-at") || "0.5");
476
+ r > C && (C = r);
477
+ }), b -= C, S -= C;
478
+ let w = x - y, T = S - b, E = Math.hypot(w, T) || 1, O = w / E, k = T / E;
479
+ y -= O * _, b -= k * _, x += O * _, S += k * _;
480
+ let A = Number.parseFloat(e.getAttribute("data-at") || "0.5");
345
481
  if (t) {
346
- let e = y + (x - y) * M, n = b + (S - b) * M, a = q(t).width * c / 2, s = n + q(t).height * c / 2 + 8 * c, u = 0;
482
+ let e = y + (x - y) * A, n = b + (S - b) * A, a = J(t).width * s / 2, c = n + J(t).height * s / 2 + 8 * s, u = 0;
347
483
  r.forEach((t, n) => {
348
- let r = (f[n] ? q(f[n]).width : 0) * c / 2;
484
+ let r = (f[n] ? J(f[n]).width : 0) * s / 2;
349
485
  if (Math.abs(i(n) - e) >= a + r) return;
350
- let d = o(t.value) - 7 * c - l;
351
- u = Math.max(u, s - d);
486
+ let d = o(t.value) - 7 * s - l;
487
+ u = Math.max(u, c - d);
352
488
  }), b -= u, S -= u;
353
489
  }
354
- let P = x - k * v, ee = S - j * v, F = Math.hypot(P - y, ee - b) / c + 1;
355
- d.appendChild(A("line", {
490
+ let M = x - O * v, N = S - k * v, F = Math.hypot(M - y, N - b) / s + 1;
491
+ d.appendChild(P("line", {
356
492
  class: a,
357
493
  "data-note": n.note,
358
494
  x1: y,
359
495
  y1: b,
360
- x2: P,
361
- y2: ee,
362
- style: `--len:${F.toFixed(1)}; ${D("--after", p)}`
496
+ x2: M,
497
+ y2: N,
498
+ style: `--len:${F.toFixed(1)}; ${j("--after", p)}`
363
499
  }));
364
- let I = -j, L = k, R = v * .42;
365
- d.appendChild(A("polygon", {
366
- class: s,
500
+ let I = -k, R = O, z = v * .42;
501
+ d.appendChild(P("polygon", {
502
+ class: c,
367
503
  "data-note": n.note,
368
504
  points: [
369
505
  `${x},${S}`,
370
- `${P + I * R},${ee + L * R}`,
371
- `${P - I * R},${ee - L * R}`
506
+ `${M + I * z},${N + R * z}`,
507
+ `${M - I * z},${N - R * z}`
372
508
  ].join(" "),
373
- style: D("--after", p)
374
- })), t && (N(t, y + (x - y) * M, b + (S - b) * M, C, u), t.style.setProperty("--after", String(p)));
375
- let z = Number.parseFloat(e.getAttribute("data-years") || "");
376
- !Number.isNaN(z) && z > 0 && U(t, le(m.value, h.value, z), `${m.value} to ${h.value} over ${z} years`, n);
509
+ style: j("--after", p)
510
+ })), t && (L(t, y + (x - y) * A, b + (S - b) * A, D, u), t.style.setProperty("--after", String(p)));
511
+ let B = Number.parseFloat(e.getAttribute("data-years") || "");
512
+ !Number.isNaN(B) && B > 0 && ae(t, De(m.value, h.value, B), `${m.value} to ${h.value} over ${B} years`, n);
377
513
  }
378
- }, ue = (e, t, n, r, i) => {
514
+ }, ke = (e, t, n, r, i) => {
379
515
  if (!r) return e / t * n;
380
516
  let { lo: a, hi: o, gap: s, share: c } = r, l = n * c, u = (n - l - i) / (a + (t - o)), d = l / (o - a);
381
517
  return e <= a ? e * u : e <= s ? a * u + (e - a) * d : e <= o ? a * u + (e - a) * d + i : a * u + l + i + (e - o) * u;
382
- }, de = (e, t, n) => {
518
+ }, Ae = (e, t, n) => {
383
519
  let r = .15, i = Math.min(e * .7 / (t + (t - 1) * r), n), a = t * i + (t - 1) * i * r;
384
520
  return {
385
521
  size: i,
386
522
  gap: i * r,
387
523
  offset: (e) => -a / 2 + e * i * 1.15
388
524
  };
389
- }, Y = (e, t, n) => {
525
+ }, je = (e, t, n) => {
390
526
  let r = e.series[n], i = e.series.some((e) => e.focus) && !r.focus;
391
527
  return {
392
528
  "data-series": n + 1,
393
529
  ...i && { "data-muted": "" },
394
- style: `--n:${n}; --m:${+!!i}; --palette:var(--tablechart-color-${n + 1}); ${D("--i", t.slot)}`
530
+ style: `--n:${n}; --m:${+!!i}; --palette:var(--tablechart-color-${n + 1}); ${j("--i", t.slot)}`
395
531
  };
396
- }, fe = (e, t, n = !1) => {
532
+ }, Me = (e, t, n = !1) => {
397
533
  let r = 0, i = 0;
398
534
  return Array.from({ length: t }, (t, a) => {
399
535
  let o = e.cells[a] ?? e.cells[0], s = o.missing ? 0 : o.value;
@@ -420,52 +556,40 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
420
556
  cell: o
421
557
  };
422
558
  });
423
- }, pe = (e, t, n = !1) => {
424
- let r = fe(e, t, n);
559
+ }, Ne = (e, t, n = !1) => {
560
+ let r = Me(e, t, n);
425
561
  return {
426
562
  top: Math.max(0, ...r.map((e) => e.to)),
427
563
  bottom: Math.min(0, ...r.map((e) => e.to))
428
564
  };
429
- }, me = (e, t) => {
430
- let { top: n, bottom: r } = pe(e, t);
565
+ }, Pe = (e, t) => {
566
+ let { top: n, bottom: r } = Ne(e, t);
431
567
  return n + r;
432
- }, he = (e, t, n) => {
568
+ }, Fe = (e, t, n) => {
433
569
  let r = t.series.some((e) => e.focus);
434
570
  e.style.setProperty("--n", String(n)), e.style.setProperty("--m", r && !t.series[n].focus ? "1" : "0"), e.style.setProperty("--palette", `var(--tablechart-color-${n + 1})`);
435
- }, ge = (e, t, n, i = {}, a = "") => {
571
+ }, Ie = (e, t, n, i = {}, a = "") => {
436
572
  let o = {
437
- class: j(r, t),
573
+ class: F(r, t),
438
574
  "data-kind": "bar",
439
575
  "data-row": n + 1,
440
576
  ...i
441
- }, s = D("--i", t.slot) + (a ? `; transform-origin: ${a}` : ""), c = A("g", {
577
+ }, s = j("--i", t.slot) + (a ? `; transform-origin: ${a}` : ""), c = P("g", {
442
578
  ...o,
443
579
  "data-stack": "",
444
580
  style: s
445
581
  });
446
582
  return e.svg.appendChild(c), (r, a) => {
447
583
  let o = i["data-grow"] === void 0 ? {} : { "data-grow": i["data-grow"] };
448
- c.appendChild(A("rect", {
584
+ c.appendChild(P("rect", {
449
585
  ...o,
450
586
  ...a,
451
- class: j("tablechart-piece", t),
587
+ class: F("tablechart-piece", t),
452
588
  "data-row": n + 1,
453
- ...Y(e, t, r)
589
+ ...je(e, t, r)
454
590
  }));
455
591
  };
456
- }, _e = 6, ve = (e, t, n) => e.some((e) => q(e).width * n > t - _e * n), ye = (e, t, n) => t >= q(e).height * n * 1.6, be = (e, t, n) => t >= q(e).width * n * 1.5, xe = (e, t, n, r, i = .7) => {
457
- e.style.setProperty(r, "1");
458
- let a = 1;
459
- for (let e of t) {
460
- let { size: t, room: r } = n(e);
461
- t > r && (a = Math.min(a, r / t));
462
- }
463
- let o = a >= i ? a : 0;
464
- return e.style.setProperty(r, String(o || i)), o;
465
- }, Se = (e, t) => (e.sort((e, t) => e.y - t.y), e.forEach((n, r) => {
466
- let i = e[r - 1];
467
- i && n.y < i.y + t && (n.y = i.y + t);
468
- }), e), Ce = {
592
+ }, Le = {
469
593
  segments: (e) => e.map((e) => ({
470
594
  ...e,
471
595
  from: 0,
@@ -473,6 +597,7 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
473
597
  kind: "bar"
474
598
  })),
475
599
  series: !0,
600
+ groups: !0,
476
601
  legend: "box",
477
602
  stackable: !0,
478
603
  totals: !0,
@@ -485,57 +610,56 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
485
610
  categories: "beside",
486
611
  headroom: () => 0,
487
612
  draw(e) {
488
- let { segments: t, height: n, unit: a, svg: o, values: s, categories: c, config: l, barMax: u } = e, d = e.series.length > 1, f = Math.max(R(c.map((e) => q(e).width * a)), 0), p = Math.min(f + 10 * a, C * .42);
489
- c[0]?.parentElement?.style.setProperty("--_beside", `${((p - 8 * a) / C * 100).toFixed(2)}%`);
490
- let m = C - 4 * a, h = e.stacked ? Math.max(R(e.rows.map((t) => pe(t, e.series.length).top)), 0) || 1 : Math.max(R(e.rows.flatMap((t) => t.cells.slice(0, e.series.length).map((e) => Math.abs(e.value)))), 0) || 1, g = e.stacked ? Math.max(R(e.rows.map((t) => -pe(t, e.series.length).bottom)), 0) : Math.max(R(e.rows.flatMap((t) => t.cells.slice(0, e.series.length).map((e) => -e.value))), 0), _ = Math.max(h, e.domain?.[1] ?? 0), v = Math.max(g, -(e.domain?.[0] ?? 0)), y = Math.max(_, e.squeeze?.hi ?? 0) + v, b = (t, n) => ue(Math.abs(t), y, n, e.squeeze, e.breakGap), x = n / t.length, S = (e) => (e + .5) * x, w = Math.min(x * l.barfill, u), T = de(x, e.series.length, u), E = s[0] ?? e.totals[0], O = E ? q(E).height * a * .56 : 0, k = Math.max(((d && !e.stacked ? T.size : w) - O) / 2, 5 * a), M = (e) => q(e).width * a, P = (e) => e.length ? R(e.map(M)) + k + 4 * a : 0, ee = (t, n) => (e.rows[n].cells[t] ?? e.rows[n].cells[0]).value, F = e.seriesValues.flatMap((e, t) => e.map((e, n) => ({
613
+ let { segments: t, height: n, unit: a, svg: o, values: s, categories: c, config: l, barMax: u } = e, d = e.series.length > 1, f = Math.max(W(c.map((e) => J(e).width * a)), 0), p = Math.min(f + 10 * a, D * .42);
614
+ c[0]?.parentElement?.style.setProperty("--_beside", `${((p - 8 * a) / D * 100).toFixed(2)}%`);
615
+ let m = D - 4 * a, h = e.stacked ? Math.max(W(e.rows.map((t) => Ne(t, e.series.length).top)), 0) || 1 : Math.max(W(e.rows.flatMap((t) => t.cells.slice(0, e.series.length).map((e) => Math.abs(e.value)))), 0) || 1, g = e.stacked ? Math.max(W(e.rows.map((t) => -Ne(t, e.series.length).bottom)), 0) : Math.max(W(e.rows.flatMap((t) => t.cells.slice(0, e.series.length).map((e) => -e.value))), 0), _ = Math.max(h, e.domain?.[1] ?? 0), v = Math.max(g, -(e.domain?.[0] ?? 0)), y = Math.max(_, e.squeeze?.hi ?? 0) + v, b = (t, n) => ke(Math.abs(t), y, n, e.squeeze, e.breakGap), x = n / t.length, S = (e) => (e + .5) * x, C = Math.min(x * l.barfill, u), w = Ae(x, e.series.length, u), T = s[0] ?? e.totals[0], E = T ? J(T).height * a * .56 : 0, O = Math.max(((d && !e.stacked ? w.size : C) - E) / 2, 5 * a), k = (e) => J(e).width * a, A = (e) => e.length ? W(e.map(k)) + O + 4 * a : 0, M = (t, n) => (e.rows[n].cells[t] ?? e.rows[n].cells[0]).value, N = e.seriesValues.flatMap((e, t) => e.map((e, n) => ({
491
616
  label: e,
492
- value: ee(t, n)
617
+ value: M(t, n)
493
618
  }))), I = (t) => {
494
- let n = pe(e.rows[t], e.series.length);
619
+ let n = Ne(e.rows[t], e.series.length);
495
620
  return n.top === 0 && n.bottom < 0;
496
- }, L = e.stacked ? P(e.totals.filter((e, t) => !I(t))) : d ? P(F.filter((e) => e.value >= 0).map((e) => e.label)) : 0, z = e.stacked ? P(e.totals.filter((e, t) => I(t))) : d ? P(F.filter((e) => e.value < 0).map((e) => e.label)) : 0;
621
+ }, R = e.stacked ? A(e.totals.filter((e, t) => !I(t))) : d ? A(N.filter((e) => e.value >= 0).map((e) => e.label)) : 0, z = e.stacked ? A(e.totals.filter((e, t) => I(t))) : d ? A(N.filter((e) => e.value < 0).map((e) => e.label)) : 0, B = (t, n) => e.labels === "inside" && _e(t, n, a);
497
622
  if (!d && !e.stacked) for (let e = 0; e < 3; e++) {
498
- let e = m - p - L - z, n = t.map((e, t) => ({
623
+ let e = m - p - R - z, n = t.map((e, t) => ({
499
624
  seg: e,
500
625
  label: s[t]
501
- })).filter(({ seg: t, label: n }) => !be(n, b(t.value, e), a)), r = P(n.filter(({ seg: e }) => e.value >= 0).map(({ label: e }) => e)), i = P(n.filter(({ seg: e }) => e.value < 0).map(({ label: e }) => e));
502
- if (r <= L && i <= z) break;
503
- L = Math.max(L, r), z = Math.max(z, i);
626
+ })).filter(({ seg: t, label: n }) => !B(n, b(t.value, e))), r = A(n.filter(({ seg: e }) => e.value >= 0).map(({ label: e }) => e)), i = A(n.filter(({ seg: e }) => e.value < 0).map(({ label: e }) => e));
627
+ if (r <= R && i <= z) break;
628
+ R = Math.max(R, r), z = Math.max(z, i);
504
629
  }
505
- let te = m - p - L - z, B = p + z + b(v, te), V = (e) => e < 0 ? B - b(e, te) : B + b(e, te);
506
- if (e.squeeze && (e.breakX = V(e.squeeze.gap)), e.x = V, e.stacked) {
630
+ let V = m - p - R - z, H = p + z + b(v, V), U = (e) => e < 0 ? H - b(e, V) : H + b(e, V);
631
+ if (e.squeeze && (e.breakX = U(e.squeeze.gap)), e.x = U, e.stacked) {
507
632
  e.rows.forEach((t, r) => {
508
- let i = pe(t, e.series.length), o = ge(e, t, r, { "data-grow": "right" }, i.bottom < 0 ? `${B - V(i.bottom)}px center` : ""), s = S(r) - w / 2;
509
- fe(t, e.series.length).forEach(({ from: t, to: i, cell: c }, l) => {
633
+ let i = Ne(t, e.series.length), o = Ie(e, t, r, { "data-grow": "right" }, i.bottom < 0 ? `${H - U(i.bottom)}px center` : ""), s = S(r) - C / 2;
634
+ Me(t, e.series.length).forEach(({ from: t, to: i, cell: c }, l) => {
510
635
  let u = e.seriesValues[l][r];
511
636
  if (u.dataset.place = "none", c.missing || i === t) return;
512
- let d = Math.min(V(t), V(i)), f = Math.max(V(t), V(i));
637
+ let d = Math.min(U(t), U(i)), f = Math.max(U(t), U(i));
513
638
  o(l, {
514
639
  x: d,
515
640
  y: s,
516
641
  width: Math.max(f - d, 1),
517
- height: w,
642
+ height: C,
518
643
  ...i < t && { "data-grow": "left" }
519
- }), u.dataset.place = "inside", u.toggleAttribute("data-left-out", !be(u, f - d, a) || q(u).height * a > w), he(u, e, l), N(u, (d + f) / 2, S(r), C, n);
644
+ }), u.dataset.place = "inside", u.toggleAttribute("data-left-out", !_e(u, f - d, a) || J(u).height * a > C), Fe(u, e, l), L(u, (d + f) / 2, S(r), D, n);
520
645
  });
521
646
  let l = e.totals[r];
522
- l && (l.dataset.place = I(r) ? "before" : "after", N(l, I(r) ? V(i.bottom) - k : V(i.top) + k, S(r), C, n));
647
+ l && (l.dataset.place = I(r) ? "before" : "after", L(l, I(r) ? U(i.bottom) - O : U(i.top) + O, S(r), D, n));
523
648
  let u = c[r];
524
- u && N(u, p - 8 * a, S(r), C, n);
525
- }), o.appendChild(A("line", {
649
+ u && L(u, p - 8 * a, S(r), D, n);
650
+ }), o.appendChild(P("line", {
526
651
  class: i,
527
- x1: B,
528
- x2: B,
652
+ x1: H,
653
+ x2: H,
529
654
  y1: 0,
530
655
  y2: n
531
656
  }));
532
657
  return;
533
658
  }
534
659
  if (d) {
535
- e.plot.dataset.grouped = "";
536
- let t = e.seriesValues.flat().filter((e) => e.dataset.missing === void 0), s = xe(e.plot, t, (e) => ({
537
- size: q(e).height * a,
538
- room: T.size + T.gap * .5
660
+ let t = e.seriesValues.flat().filter((e) => e.dataset.missing === void 0), s = ve(e.plot, t, (e) => ({
661
+ size: J(e).height * a,
662
+ room: w.size + w.gap * .5
539
663
  }), "--_fit");
540
664
  e.rows.forEach((t, i) => {
541
665
  e.series.forEach((a, c) => {
@@ -544,57 +668,57 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
544
668
  u.dataset.place = "none";
545
669
  return;
546
670
  }
547
- let d = V(l.value), f = l.value < 0, p = S(i) + T.offset(c), m = Math.max(Math.abs(d - B), 1);
548
- l.value !== 0 && o.appendChild(A("rect", {
549
- class: j(r, t),
671
+ let d = U(l.value), f = l.value < 0, p = S(i) + w.offset(c), m = Math.max(Math.abs(d - H), 1);
672
+ l.value !== 0 && o.appendChild(P("rect", {
673
+ class: F(r, t),
550
674
  "data-kind": "bar",
551
675
  "data-row": i + 1,
552
676
  "data-grow": f ? "left" : "right",
553
- x: f ? B - m : B,
677
+ x: f ? H - m : H,
554
678
  y: p,
555
679
  width: m,
556
- height: T.size,
557
- ...Y(e, t, c)
558
- })), u.dataset.place = f ? "before" : "after", u.toggleAttribute("data-left-out", !s), N(u, f ? d - k : d + k, p + T.size / 2, C, n);
680
+ height: w.size,
681
+ ...je(e, t, c)
682
+ })), u.dataset.place = f ? "before" : "after", u.toggleAttribute("data-left-out", !s), L(u, f ? d - O : d + O, p + w.size / 2, D, n);
559
683
  });
560
684
  let l = c[i];
561
- l && N(l, p - 8 * a, S(i), C, n);
562
- }), o.appendChild(A("line", {
685
+ l && L(l, p - 8 * a, S(i), D, n);
686
+ }), o.appendChild(P("line", {
563
687
  class: i,
564
- x1: B,
565
- x2: B,
688
+ x1: H,
689
+ x2: H,
566
690
  y1: 0,
567
691
  y2: n
568
692
  }));
569
693
  return;
570
694
  }
571
- let H = t.map((e, t) => be(s[t], Math.abs(V(e.value) - B), a));
695
+ let ee = t.map((e, t) => B(s[t], Math.abs(U(e.value) - H)));
572
696
  t.forEach((t, i) => {
573
- let l = V(t.value), u = S(i), d = t.value < 0, f = Math.abs(l - B), m = Math.max(f, 1);
574
- t.value !== 0 && o.appendChild(A("rect", {
575
- class: j(r, t),
697
+ let l = U(t.value), u = S(i), d = t.value < 0, f = Math.abs(l - H), m = Math.max(f, 1);
698
+ t.value !== 0 && o.appendChild(P("rect", {
699
+ class: F(r, t),
576
700
  "data-kind": t.kind,
577
701
  "data-row": i + 1,
578
702
  "data-grow": d ? "left" : "right",
579
- x: d ? B - m : B,
580
- y: u - w / 2,
703
+ x: d ? H - m : H,
704
+ y: u - C / 2,
581
705
  width: m,
582
- height: w,
583
- style: D("--i", t.slot)
706
+ height: C,
707
+ style: j("--i", t.slot)
584
708
  }));
585
- let h = s[i], g = Math.max(Math.min(k, f - M(h) - 6 * a), 6 * a), _ = d ? 1 : -1;
586
- h.dataset.place = H[i] ? "inside" : d ? "before" : "after", h.dataset.kind = t.kind, N(h, H[i] ? e.insideAlign === "center" ? (B + l) / 2 : e.insideAlign === "start" ? B - _ * (g + M(h) / 2) : l + _ * (g + M(h) / 2) : l - _ * k, u, C, n);
709
+ let h = s[i], g = Math.max(Math.min(O, f - k(h) - 6 * a), 6 * a), _ = d ? 1 : -1;
710
+ h.dataset.place = ee[i] ? "inside" : d ? "before" : "after", h.dataset.kind = t.kind, L(h, ee[i] ? e.insideAlign === "center" ? (H + l) / 2 : e.insideAlign === "start" ? H - _ * (g + k(h) / 2) : l + _ * (g + k(h) / 2) : l - _ * O, u, D, n);
587
711
  let v = c[i];
588
- v && N(v, p - 8 * a, u, C, n);
589
- }), o.appendChild(A("line", {
712
+ v && L(v, p - 8 * a, u, D, n);
713
+ }), o.appendChild(P("line", {
590
714
  class: i,
591
- x1: B,
592
- x2: B,
715
+ x1: H,
716
+ x2: H,
593
717
  y1: 0,
594
718
  y2: n
595
719
  }));
596
720
  }
597
- }, we = {
721
+ }, Re = {
598
722
  segments: (e) => e.map((e) => ({
599
723
  ...e,
600
724
  from: 0,
@@ -602,6 +726,8 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
602
726
  kind: "bar"
603
727
  })),
604
728
  series: !0,
729
+ lines: !0,
730
+ groups: !0,
605
731
  legend: "box",
606
732
  stackable: !0,
607
733
  totals: !0,
@@ -611,8 +737,8 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
611
737
  let { segments: t, cx: n, y: a, barWidth: o, height: s, unit: c, svg: l, values: u, labels: d, insideAlign: f } = e, p = a(0);
612
738
  if (e.stacked) {
613
739
  e.rows.forEach((t, r) => {
614
- let i = pe(t, e.series.length), l = ge(e, t, r, {}, i.bottom < 0 ? `center ${p - a(i.top)}px` : ""), u = n(r) - o / 2;
615
- fe(t, e.series.length).forEach(({ from: t, to: i, cell: d }, f) => {
740
+ let i = Ne(t, e.series.length), l = Ie(e, t, r, {}, i.bottom < 0 ? `center ${p - a(i.top)}px` : ""), u = n(r) - o / 2;
741
+ Me(t, e.series.length).forEach(({ from: t, to: i, cell: d }, f) => {
616
742
  let p = e.seriesValues[f][r];
617
743
  if (p.dataset.place = "none", d.missing || i === t) return;
618
744
  let m = Math.min(a(i), a(t)), h = Math.max(a(i), a(t));
@@ -622,39 +748,37 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
622
748
  width: o,
623
749
  height: Math.max(h - m, 1),
624
750
  ...i < t && { "data-grow": "down" }
625
- }), p.dataset.place = "inside", p.toggleAttribute("data-left-out", !ye(p, h - m, c) || q(p).width * c > o - 4 * c), he(p, e, f), N(p, n(r), (m + h) / 2, C, s);
751
+ }), p.dataset.place = "inside", p.toggleAttribute("data-left-out", !ge(p, h - m, c) || J(p).width * c > o - 4 * c), Fe(p, e, f), L(p, n(r), (m + h) / 2, D, s);
626
752
  });
627
753
  let d = e.totals[r];
628
754
  if (d) {
629
755
  let e = i.top === 0 && i.bottom < 0;
630
- d.dataset.place = e ? "below" : "outside", N(d, n(r), e ? a(i.bottom) + 4 * c : a(i.top) - 4 * c, C, s);
756
+ d.dataset.place = e ? "below" : "outside", L(d, n(r), e ? a(i.bottom) + 4 * c : a(i.top) - 4 * c, D, s);
631
757
  }
632
- }), l.appendChild(A("line", {
758
+ }), l.appendChild(P("line", {
633
759
  class: i,
634
760
  x1: 0,
635
- x2: C,
761
+ x2: D,
636
762
  y1: p,
637
763
  y2: p
638
764
  }));
639
765
  return;
640
766
  }
641
- if (e.series.length > 1) {
642
- let t = de(n(1) - n(0) || n(0) * 2, e.series.length, e.barMax);
643
- e.plot.dataset.grouped = "";
644
- let o = e.seriesValues.flat().filter((e) => e.dataset.missing === void 0), u = xe(e.plot, o, (e) => ({
645
- size: q(e).width * c,
767
+ if (e.own.length > 1) {
768
+ let t = Ae(n(1) - n(0) || n(0) * 2, e.own.length, e.barMax), o = e.own.flatMap((t) => e.seriesValues[t]).filter((e) => e.dataset.missing === void 0), u = ve(e.plot, o, (e) => ({
769
+ size: J(e).width * c,
646
770
  room: t.size + t.gap * .5
647
771
  }), "--_fit");
648
772
  e.rows.forEach((i, o) => {
649
- e.series.forEach((d, f) => {
650
- let m = i.cells[f] ?? i.cells[0], h = e.seriesValues[f][o], g = n(o) + t.offset(f);
773
+ e.own.forEach((d, f) => {
774
+ let m = i.cells[d] ?? i.cells[0], h = e.seriesValues[d][o], g = n(o) + t.offset(f);
651
775
  if (m.missing) {
652
776
  h.dataset.place = "none";
653
777
  return;
654
778
  }
655
779
  let _ = a(m.value), v = m.value < 0, y = Math.max(Math.abs(p - _), 1);
656
- m.value !== 0 && l.appendChild(A("rect", {
657
- class: j(r, i),
780
+ m.value !== 0 && l.appendChild(P("rect", {
781
+ class: F(r, i),
658
782
  "data-kind": "bar",
659
783
  "data-row": o + 1,
660
784
  ...v && { "data-grow": "down" },
@@ -662,49 +786,50 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
662
786
  y: v ? p : p - y,
663
787
  width: t.size,
664
788
  height: y,
665
- ...Y(e, i, f)
666
- })), h.dataset.place = v ? "below" : "outside", h.toggleAttribute("data-left-out", !u), N(h, g + t.size / 2, v ? _ + 4 * c : _ - 4 * c, C, s);
789
+ ...je(e, i, d)
790
+ })), h.dataset.place = v ? "below" : "outside", h.toggleAttribute("data-left-out", !u), L(h, g + t.size / 2, v ? _ + 4 * c : _ - 4 * c, D, s);
667
791
  });
668
- }), l.appendChild(A("line", {
792
+ }), l.appendChild(P("line", {
669
793
  class: i,
670
794
  x1: 0,
671
- x2: C,
795
+ x2: D,
672
796
  y1: p,
673
797
  y2: p
674
798
  }));
675
799
  return;
676
800
  }
677
- let m = ve(u, o, c), h = t.map((e, t) => d === "inside" && !m && !e.missing && ye(u[t], Math.abs(p - a(e.value)), c)), g = u[0] ? q(u[0]).height * c * .56 : 0, _ = Infinity;
678
- for (let [e, t] of u.entries()) h[e] && (_ = Math.min(_, (o - q(t).width * c) / 2));
679
- t.forEach((e, t) => {
680
- let i = a(e.value), d = e.value < 0;
681
- if (e.missing) {
682
- N(u[t], n(t), p - 4 * c, C, s), u[t].dataset.place = "outside";
801
+ let m = e.own[0], h = e.own.length < e.series.length, g = he(u, o, c), _ = t.map((e, t) => d === "inside" && !g && !e.missing && ge(u[t], Math.abs(p - a(e.value)), c)), v = u[0] ? J(u[0]).height * c * .56 : 0, y = Infinity;
802
+ for (let [e, t] of u.entries()) _[e] && (y = Math.min(y, (o - J(t).width * c) / 2));
803
+ t.forEach((t, i) => {
804
+ let d = a(t.value), g = t.value < 0;
805
+ if (t.missing) {
806
+ L(u[i], n(i), p - 4 * c, D, s), u[i].dataset.place = "outside";
683
807
  return;
684
808
  }
685
- let m = Math.max(Math.abs(p - i), 1);
686
- e.value !== 0 && l.appendChild(A("rect", {
687
- class: j(r, e),
688
- "data-kind": e.kind,
689
- "data-row": t + 1,
690
- ...d && { "data-grow": "down" },
691
- x: n(t) - o / 2,
692
- y: d ? p : p - m,
809
+ let b = Math.max(Math.abs(p - d), 1);
810
+ t.value !== 0 && l.appendChild(P("rect", {
811
+ class: F(r, t),
812
+ "data-kind": t.kind,
813
+ "data-row": i + 1,
814
+ ...g && { "data-grow": "down" },
815
+ x: n(i) - o / 2,
816
+ y: g ? p : p - b,
693
817
  width: o,
694
- height: m,
695
- style: D("--i", e.slot)
818
+ height: b,
819
+ style: j("--i", t.slot),
820
+ ...h && je(e, t, m)
696
821
  }));
697
- let v = d ? -1 : 1, y = Math.min(_, (Math.abs(p - i) - g) / 2), b = f === "center" ? (i + p) / 2 : f === "start" ? p - v * (y + g / 2) : i + v * (y + g / 2), x = d ? i + 4 * c : i - 4 * c;
698
- N(u[t], n(t), h[t] ? b : x, C, s), u[t].dataset.place = h[t] ? "inside" : d ? "below" : "outside";
699
- }), l.appendChild(A("line", {
822
+ let x = g ? -1 : 1, S = Math.min(y, (Math.abs(p - d) - v) / 2), C = f === "center" ? (d + p) / 2 : f === "start" ? p - x * (S + v / 2) : d + x * (S + v / 2), w = g ? d + 4 * c : d - 4 * c;
823
+ L(u[i], n(i), _[i] ? C : w, D, s), u[i].dataset.place = _[i] ? "inside" : g ? "below" : "outside", h && _[i] && Fe(u[i], e, m);
824
+ }), l.appendChild(P("line", {
700
825
  class: i,
701
826
  x1: 0,
702
- x2: C,
827
+ x2: D,
703
828
  y1: p,
704
829
  y2: p
705
830
  }));
706
831
  }
707
- }, Te = 0, Ee = (e) => e.filter((e) => !e.isTotal), De = {
832
+ }, ze = 0, Be = (e) => e.filter((e) => !e.isTotal), Ve = {
708
833
  aspect: .66,
709
834
  centre: !0,
710
835
  headroom: () => 0,
@@ -715,81 +840,81 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
715
840
  kind: "bar"
716
841
  })),
717
842
  draw({ rows: e, height: t, unit: n, labelHeight: r, svg: i, values: a, config: o, centre: s }) {
718
- let l = C / 2, u = t / 2, d = Ee(e).reduce((e, t) => e + Math.abs(t.value), 0);
843
+ let c = D / 2, u = t / 2, d = Be(e).reduce((e, t) => e + Math.abs(t.value), 0);
719
844
  if (!d) return;
720
- let f = r * 1.2 + 10 * n, p = Math.max(Math.min(C, t) / 2 - f, 10), m = p * o.ringfill, h = p - m / 2, g = 2 * Math.PI * h, _ = [], v = 0, y = 0, b = 0;
845
+ let f = r * 1.2 + 10 * n, p = Math.max(Math.min(D, t) / 2 - f, 10), m = p * o.ringfill, h = p - m / 2, g = 2 * Math.PI * h, _ = [], v = 0, y = 0, b = 0;
721
846
  if (e.forEach((e, o) => {
722
847
  let s = a[o];
723
848
  if (e.isTotal) {
724
849
  s.dataset.place = "none";
725
850
  return;
726
851
  }
727
- let f = Math.abs(e.value) / d, x = E(b, f), S = `--share:${f.toFixed(4)}; --start:${x.start.toFixed(4)}; --span:${x.span.toFixed(4)};`, w = f * g, T = v / g * 2 * Math.PI - Math.PI / 2;
728
- _.push(T), i.appendChild(A("circle", {
729
- class: j(c, e),
852
+ let f = Math.abs(e.value) / d, x = A(b, f), S = `--share:${f.toFixed(4)}; --start:${x.start.toFixed(4)}; --span:${x.span.toFixed(4)};`, C = f * g, w = v / g * 2 * Math.PI - Math.PI / 2;
853
+ _.push(w), i.appendChild(P("circle", {
854
+ class: F(l, e),
730
855
  "data-slice": y + 1,
731
856
  "data-row": o + 1,
732
- cx: l,
857
+ cx: c,
733
858
  cy: u,
734
859
  r: h,
735
860
  "stroke-width": m,
736
- transform: `rotate(-90 ${l} ${u})`,
737
- "stroke-dasharray": `${w.toFixed(1)} ${(g - w).toFixed(1)}`,
861
+ transform: `rotate(-90 ${c} ${u})`,
862
+ "stroke-dasharray": `${C.toFixed(1)} ${(g - C).toFixed(1)}`,
738
863
  "stroke-dashoffset": (-v).toFixed(1),
739
- style: `--n:${y}; --palette:var(--tablechart-color-${y + 1}); --arc:${w.toFixed(1)}; --circ:${g.toFixed(1)}; ${S} --ease:${x.easing}; ${D("--i", e.slot)}`
864
+ style: `--n:${y}; --palette:var(--tablechart-color-${y + 1}); --arc:${C.toFixed(1)}; --circ:${g.toFixed(1)}; ${S} --ease:${x.easing}; ${j("--i", e.slot)}`
740
865
  }));
741
- let O = T + w / g * Math.PI, k = Math.cos(O), M = Math.sin(O);
742
- i.appendChild(A("line", {
866
+ let T = w + C / g * Math.PI, E = Math.cos(T), O = Math.sin(T);
867
+ i.appendChild(P("line", {
743
868
  class: "tablechart-leader",
744
- x1: l + k * (p + 2 * n),
745
- y1: u + M * (p + 2 * n),
746
- x2: l + k * (p + 7 * n),
747
- y2: u + M * (p + 7 * n),
869
+ x1: c + E * (p + 2 * n),
870
+ y1: u + O * (p + 2 * n),
871
+ x2: c + E * (p + 7 * n),
872
+ y2: u + O * (p + 7 * n),
748
873
  "data-row": o + 1,
749
- style: `${S} ${D("--i", e.slot)}`
874
+ style: `${S} ${j("--i", e.slot)}`
750
875
  })), s.style.setProperty("--start", x.start.toFixed(4)), s.style.setProperty("--span", x.span.toFixed(4));
751
- let P = p + 9 * n, ee = q(s).width * n / 2;
752
- N(s, l + k * (P + Math.abs(k) * ee), u + M * (P + Math.abs(M) * r * .7), C, t), s.dataset.place = "around", v += w, b += f, y += 1;
876
+ let k = p + 9 * n, M = J(s).width * n / 2;
877
+ L(s, c + E * (k + Math.abs(E) * M), u + O * (k + Math.abs(O) * r * .7), D, t), s.dataset.place = "around", v += C, b += f, y += 1;
753
878
  }), _.length > 1) {
754
- let e = h - m / 2 - 1, n = h + m / 2 + 1, r = `tablechart-slices-${++Te}`, a = A("mask", {
879
+ let e = h - m / 2 - 1, n = h + m / 2 + 1, r = `tablechart-slices-${++ze}`, a = P("mask", {
755
880
  id: r,
756
881
  maskUnits: "userSpaceOnUse"
757
882
  });
758
- a.appendChild(A("rect", {
883
+ a.appendChild(P("rect", {
759
884
  x: 0,
760
885
  y: 0,
761
- width: C,
886
+ width: D,
762
887
  height: t,
763
888
  fill: "white"
764
889
  }));
765
- for (let t of _) a.appendChild(A("line", {
890
+ for (let t of _) a.appendChild(P("line", {
766
891
  class: "tablechart-divide",
767
- x1: l + Math.cos(t) * e,
892
+ x1: c + Math.cos(t) * e,
768
893
  y1: u + Math.sin(t) * e,
769
- x2: l + Math.cos(t) * n,
894
+ x2: c + Math.cos(t) * n,
770
895
  y2: u + Math.sin(t) * n
771
896
  }));
772
- let o = A("g", { mask: `url(#${r})` });
773
- for (let e of Array.from(i.querySelectorAll(`.${c}`))) o.appendChild(e);
774
- let s = A("defs");
897
+ let o = P("g", { mask: `url(#${r})` });
898
+ for (let e of Array.from(i.querySelectorAll(`.${l}`))) o.appendChild(e);
899
+ let s = P("defs");
775
900
  s.appendChild(a), i.prepend(s, o);
776
901
  }
777
- s && N(s, l, u, C, t);
902
+ s && L(s, c, u, D, t);
778
903
  }
779
- }, Oe = [
904
+ }, He = [
780
905
  "circle",
781
906
  "square",
782
907
  "diamond"
783
- ], ke = (e, t) => {
784
- let n = e[t]?.marker?.toLowerCase().split(/\s+/) ?? [], r = Oe.find((e) => n.includes(e));
908
+ ], X = (e, t) => {
909
+ let n = e[t]?.marker?.toLowerCase().split(/\s+/) ?? [], r = He.find((e) => n.includes(e));
785
910
  return {
786
- shape: r ?? Oe[Math.floor(t / 2) % Oe.length],
911
+ shape: r ?? He[Math.floor(t / 2) % He.length],
787
912
  open: n.includes("open") || !n.includes("filled") && !r && t % 2 == 1
788
913
  };
789
- }, Ae = (e, t, n, r, i = {}) => {
914
+ }, Ue = (e, t, n, r, i = {}) => {
790
915
  if (e === "square") {
791
916
  let e = r * .88;
792
- return A("rect", {
917
+ return P("rect", {
793
918
  x: t - e,
794
919
  y: n - e,
795
920
  width: e * 2,
@@ -799,26 +924,26 @@ var e = "tablechart", t = "tablechart-plot", n = "tablechart-value", r = "tablec
799
924
  }
800
925
  if (e === "diamond") {
801
926
  let e = r * 1.2;
802
- return A("polygon", {
927
+ return P("polygon", {
803
928
  points: `${t},${n - e} ${t + e},${n} ${t},${n + e} ${t - e},${n}`,
804
929
  ...i
805
930
  });
806
931
  }
807
932
  if (e === "triangle") {
808
933
  let e = r * 1.3;
809
- return A("polygon", {
810
- points: `${t},${n - e} ${t + e * .87},${n + e / 2} ${t - e * .87},${n + e / 2}`,
934
+ return P("polygon", {
935
+ points: `${t},${n - e * .75} ${t + e * .87},${n + e * .75} ${t - e * .87},${n + e * .75}`,
811
936
  ...i
812
937
  });
813
938
  }
814
- return A("circle", {
939
+ return P("circle", {
815
940
  cx: t,
816
941
  cy: n,
817
942
  r,
818
943
  ...i
819
944
  });
820
- }, X = (e) => Number(e.toFixed(2));
821
- function je(e, t) {
945
+ }, Z = (e) => Number(e.toFixed(2));
946
+ function We(e, t) {
822
947
  let n = e.length;
823
948
  if (n < 2) return e.map(() => 0);
824
949
  let r = (n) => (t[n + 1] - t[n]) / (e[n + 1] - e[n] || 1), i = Array(n).fill(0);
@@ -835,32 +960,70 @@ function je(e, t) {
835
960
  };
836
961
  return i[0] = a(0, 1, i[1]), i[n - 1] = a(n - 2, n - 1, i[n - 2]), i;
837
962
  }
838
- function Me(e, t, n, r) {
963
+ function Ge(e, t, n, r) {
839
964
  let i = (t[0] - e[0]) / 3;
840
965
  return [[e[0] + i, e[1] + n * i], [t[0] - i, t[1] - r * i]];
841
966
  }
842
- function Ne(e, t, n, r) {
843
- let [i, a] = Me(e, t, n, r), o = ([e, t]) => `${X(e)},${X(t)}`;
967
+ function Ke(e, t, n, r) {
968
+ let [i, a] = Ge(e, t, n, r), o = ([e, t]) => `${Z(e)},${Z(t)}`;
844
969
  return `C${o(i)} ${o(a)} ${o(t)}`;
845
970
  }
846
- function Pe(e, t, n) {
971
+ function qe(e, t, n) {
847
972
  let r = Array(e).fill(0), i = [], a = () => {
848
- je(i.map((e) => n(e)[0]), i.map((e) => n(e)[1])).forEach((e, t) => {
973
+ We(i.map((e) => n(e)[0]), i.map((e) => n(e)[1])).forEach((e, t) => {
849
974
  r[i[t]] = e;
850
975
  }), i = [];
851
976
  };
852
977
  for (let n = 0; n < e; n++) t(n) ? a() : i.push(n);
853
978
  return a(), r;
854
979
  }
855
- //#endregion
856
- //#region src/js/charts/line.ts
857
- var Fe = (e) => e.map((e) => ({
980
+ var Je = (e) => {
981
+ let t = e.length, n = e.reduce((e, t) => e + t.x, 0) / t, r = e.reduce((e, t) => e + t.y, 0) / t, i = e.reduce((e, t) => e + (t.x - n) ** 2, 0), a = i ? e.reduce((e, t) => e + (t.x - n) * (t.y - r), 0) / i : 0, o = (e) => r + a * (e - n), s = t > 2 ? Math.sqrt(e.reduce((e, t) => e + (t.y - o(t.x)) ** 2, 0) / (t - 2)) : 0, c = i ? s / Math.sqrt(i) : 0;
982
+ return {
983
+ at: o,
984
+ spread: s,
985
+ t: c ? a / c : a ? Infinity : 0,
986
+ n: t
987
+ };
988
+ }, Ye = [
989
+ 12.71,
990
+ 4.3,
991
+ 3.18,
992
+ 2.78,
993
+ 2.57,
994
+ 2.45,
995
+ 2.36,
996
+ 2.31,
997
+ 2.26,
998
+ 2.23,
999
+ 2.2,
1000
+ 2.18,
1001
+ 2.16,
1002
+ 2.14,
1003
+ 2.13
1004
+ ], Xe = (e) => Ye[e - 1] ?? (e < 30 ? 2.1 : 2), Ze = (e) => {
1005
+ let t = e.map((e) => e.y), n = Math.min(...t), r = Math.max(...t), i = n < 0 && r > 0, a = r - n || 1;
1006
+ return {
1007
+ mean: t.reduce((e, t) => e + t, 0) / t.length,
1008
+ share: (e, t) => e / (i ? a : Math.abs(t) || a) * 100
1009
+ };
1010
+ }, Qe = (e, t = 5, n = 25) => {
1011
+ if (e.length < 4) return null;
1012
+ let { mean: r, share: i } = Ze(e), a = (t) => e.filter((e) => Math.abs(i(e.y - t(e.x), t(e.x))) > n), o = (t) => t.length <= e.length / 5, s = Je(e), c = a(s.at);
1013
+ c.length && o(c) && (s = Je(e.filter((e) => !c.includes(e))), c = a(s.at)), o(c) || (s = Je(e), c = []);
1014
+ let l = s.at, u = e[0], d = e[e.length - 1], f = i(l(d.x) - l(u.x), r), p = Math.abs(s.t) >= Xe(s.n - 2), m = Math.abs(i(s.spread, r)) < t, h = Math.abs(f) < t ? "flat" : f > 0 ? "up" : "down", g = h === "flat" ? m ? "flat" : "unclear" : p ? h : "unclear";
1015
+ return {
1016
+ course: g,
1017
+ line: l,
1018
+ outside: g === "unclear" ? [] : c
1019
+ };
1020
+ }, $e = (e) => e.map((e) => ({
858
1021
  ...e,
859
1022
  from: 0,
860
1023
  to: e.value,
861
1024
  kind: "bar"
862
- })), Ie = (e) => ({
863
- segments: Fe,
1025
+ })), et = (e) => ({
1026
+ segments: $e,
864
1027
  series: !0,
865
1028
  stackable: !0,
866
1029
  running: !0,
@@ -868,14 +1031,14 @@ var Fe = (e) => e.map((e) => ({
868
1031
  headroom: ({ labelHeight: e, unit: t }) => e * 1.6 + 6 * t,
869
1032
  footroom: ({ labelHeight: t, unit: n, series: r, focused: i, stacked: a }) => !e && !a && r === 2 && !i ? t + 7 * n : 0,
870
1033
  draw(t) {
871
- let { rows: n, series: r, seriesValues: a, names: o, cx: s, y: c, height: l, unit: u, labelHeight: p, svg: m, stacked: h } = t, g = t.shape === "step", _ = t.shape === "smooth", v = r.length > 1, y = r.some((e) => e.focus), b = n.length - 1, x = c(0), S = n.length > 1 ? s(1) - s(0) : s(0) * 2;
872
- m.style.setProperty("--_base", `${X(x)}px`);
873
- let w = (e) => `--rise:${X(x - e)}px; `, T = (e, t) => n[t]?.cells[e] ?? n[t]?.cells[0], E = (e, t) => !T(e, t) || !!T(e, t)?.missing, D = n.map((e) => h ? fe(e, r.length, !0) : null), O = (e, t) => D[t]?.[e].to ?? T(e, t)?.value ?? 0, k = (e, t) => D[t]?.[e].from ?? 0, j = (e, t) => [s(t), c(O(e, t))], M = r.map((e, t) => {
874
- if (!v) return {
1034
+ let { rows: n, series: r, own: a, seriesValues: o, names: s, cx: c, y: l, height: f, unit: p, labelHeight: g, svg: _, stacked: v } = t, y = a.length < r.length, b = t.shape === "step", x = t.shape === "smooth", S = r.length > 1, C = r.some((e) => e.focus), w = n.length - 1, T = l(0), E = n.length > 1 ? c(1) - c(0) : c(0) * 2;
1035
+ _.style.setProperty("--_base", `${Z(T)}px`);
1036
+ let O = (e) => `--rise:${Z(T - e)}px; `, k = (e, t) => n[t]?.cells[e] ?? n[t]?.cells[0], A = (e, t) => !k(e, t) || !!k(e, t)?.missing, j = n.map((e) => v ? Me(e, r.length, !0) : null), M = (e, t) => j[t]?.[e].to ?? k(e, t)?.value ?? 0, N = (e, t) => j[t]?.[e].from ?? 0, F = (e, t) => [c(t), l(M(e, t))], I = r.map((e, t) => {
1037
+ if (!S) return {
875
1038
  attrs: {},
876
1039
  ink: ""
877
1040
  };
878
- let n = y && !e.focus;
1041
+ let n = C && !e.focus;
879
1042
  return {
880
1043
  attrs: {
881
1044
  "data-series": t + 1,
@@ -883,177 +1046,340 @@ var Fe = (e) => e.map((e) => ({
883
1046
  },
884
1047
  ink: `--n:${t}; --m:${+!!n}; --palette:var(--tablechart-color-${t + 1}); `
885
1048
  };
886
- }), P = Math.min(b, 6);
887
- t.plot.style.setProperty("--count", String(P + 1));
888
- let F = b > 0 ? P / (g ? n.length : b) : 1, I = (e) => e * F, L = (e) => `--i:${X(I(e))}`, R = (e) => {
1049
+ }), R = y ? w : Math.min(w, 6);
1050
+ t.plot.style.setProperty("--count", String(R + 1));
1051
+ let z = w > 0 ? R / (b ? n.length : w) : 1, B = (e) => e * z, V = (e) => `--i:${Z(B(e))}`, H = (e) => {
889
1052
  let t = [], r = -1;
890
1053
  return n.forEach((n, i) => {
891
- E(e, i) || (r < 0 && (r = i), (i === b || E(e, i + 1)) && ((g || i > r) && t.push([r, i]), r = -1));
1054
+ A(e, i) || (r < 0 && (r = i), (i === w || A(e, i + 1)) && ((b || i > r) && t.push([r, i]), r = -1));
892
1055
  }), t;
893
- }, z = (e, t) => `--i:${X(I(e) + 1)}; --d:${X(I(g ? t + 1 : t) - I(e))}`, te = (e, t) => ({
1056
+ }, ee = (e, t) => `--i:${Z(B(e) + 1)}; --d:${Z(B(b ? t + 1 : t) - B(e))}`, te = (e, t) => ({
894
1057
  "data-from": e + 1,
895
1058
  "data-to": t + 1,
896
- ...g && { "data-flat": "" }
897
- }), B = _ ? r.map((e, t) => Pe(n.length, (e) => E(t, e), (e) => j(t, e))) : [], V = _ && e ? r.map((e, t) => Pe(n.length, (e) => E(t, e), (e) => [s(e), c(k(t, e))])) : [], H = (e, t, n) => {
1059
+ ...b && { "data-flat": "" }
1060
+ }), ne = x ? r.map((e, t) => qe(n.length, (e) => A(t, e), (e) => F(t, e))) : [], W = x && e ? r.map((e, t) => qe(n.length, (e) => A(t, e), (e) => [c(e), l(N(t, e))])) : [], re = (e, t, n) => {
898
1061
  let r = [];
899
1062
  return e.forEach(([i, a], o) => {
900
- g ? (r.push(`H${X(i + n * S / 2)}`), o < e.length - 1 && r.push(`V${X(e[o + 1][1])}`)) : o > 0 && r.push(t ? Ne(e[o - 1], [i, a], t[o - 1], t[o]) : `L${X(i)},${X(a)}`);
1063
+ b ? (r.push(`H${Z(i + n * E / 2)}`), o < e.length - 1 && r.push(`V${Z(e[o + 1][1])}`)) : o > 0 && r.push(t ? Ke(e[o - 1], [i, a], t[o - 1], t[o]) : `L${Z(i)},${Z(a)}`);
901
1064
  }), r;
902
- }, U = (e, t, r, i) => n.slice(t, r + 1).map((n, r) => [s(t + r), c(i(e, t + r))]), W = (e, t, n, r) => _ ? e[t].slice(n, r + 1) : null, ne = (e) => s(e) - (g ? S / 2 : 0), re = (e) => s(e) + (g ? S / 2 : 0), ie = (e) => {
903
- let t = A("g", {
904
- class: "tablechart-area",
905
- ...M[e].attrs,
906
- ...h && { "data-stacked": "" },
907
- style: M[e].ink
908
- }), n = R(e), r = A("g", {
1065
+ }, G = (e, t, r, i) => n.slice(t, r + 1).map((n, r) => [c(t + r), l(i(e, t + r))]), ie = (e, t, n, r) => x ? e[t].slice(n, r + 1) : null, K = (e) => c(e) - (b ? E / 2 : 0), q = (e) => c(e) + (b ? E / 2 : 0), ae = (e) => {
1066
+ let t = P("g", {
1067
+ class: d,
1068
+ ...I[e].attrs,
1069
+ ...v && { "data-stacked": "" },
1070
+ style: I[e].ink
1071
+ }), n = H(e), r = P("g", {
909
1072
  class: "tablechart-area-fill",
910
- style: `--rows:${X(P + 1)}; ${n.length ? z(...n[0]) : ""}`
1073
+ style: `--rows:${Z(R + 1)}; ${n.length ? ee(...n[0]) : ""}`
911
1074
  });
912
1075
  t.appendChild(r);
913
1076
  for (let [t, i] of n) {
914
- let n = U(e, t, i, O), a = U(e, t, i, k), o = W(V, e, t, i)?.reverse() ?? null, s = [
915
- `M${X(ne(t))},${X(a[0][1])}`,
916
- `L${X(ne(t))},${X(n[0][1])}`,
917
- ...H(n, W(B, e, t, i), 1),
918
- `L${X(re(i))},${X(a[a.length - 1][1])}`,
919
- ...H(a.reverse(), o, -1),
1077
+ let n = G(e, t, i, M), a = G(e, t, i, N), o = ie(W, e, t, i)?.reverse() ?? null, s = [
1078
+ `M${Z(K(t))},${Z(a[0][1])}`,
1079
+ `L${Z(K(t))},${Z(n[0][1])}`,
1080
+ ...re(n, ie(ne, e, t, i), 1),
1081
+ `L${Z(q(i))},${Z(a[a.length - 1][1])}`,
1082
+ ...re(a.reverse(), o, -1),
920
1083
  "Z"
921
1084
  ].join(" ");
922
- r.appendChild(A("path", {
1085
+ r.appendChild(P("path", {
923
1086
  d: s,
924
1087
  ...te(t, i),
925
- style: z(t, i)
1088
+ style: ee(t, i)
926
1089
  }));
927
1090
  }
928
- m.appendChild(t);
929
- }, G = (e) => {
1091
+ _.appendChild(t);
1092
+ }, oe = (e) => {
930
1093
  let t = r[e];
931
- for (let [n, r] of R(e)) {
932
- let i = U(e, n, r, O), a = [`M${X(ne(n))},${X(i[0][1])}`, ...H(i, W(B, e, n, r), 1)].join(" ");
933
- m.appendChild(A("path", {
934
- class: "tablechart-series",
935
- ...M[e].attrs,
1094
+ for (let [n, r] of H(e)) {
1095
+ let i = G(e, n, r, M), a = [`M${Z(K(n))},${Z(i[0][1])}`, ...re(i, ie(ne, e, n, r), 1)].join(" ");
1096
+ _.appendChild(P("path", {
1097
+ class: u,
1098
+ ...I[e].attrs,
936
1099
  d: a,
937
1100
  ...t.line && { "data-line": t.line },
938
1101
  ...te(n, r),
939
- style: `${M[e].ink}${z(n, r)}`
1102
+ style: `${I[e].ink}${ee(n, r)}`
940
1103
  }));
941
1104
  }
942
- };
943
- e && r.forEach((e, t) => ie(t)), r.forEach((e, t) => G(t)), g || (() => {
944
- let e = r.map((e, t) => v ? ke(r, t) : {
1105
+ }, se = (e) => {
1106
+ let i = a.map((e) => r[e]), o = r.map((e, t) => y ? X(i, a.indexOf(t)) : S ? X(r, t) : {
945
1107
  shape: "circle",
946
1108
  open: !1
947
- }), t = (t, n, r) => {
948
- let [i, a] = j(t, n);
949
- return Ae(e[t].shape, i, a, 4 * u, {
950
- ...r,
951
- style: `${r.style ?? ""}${w(a)}${L(n)}`
1109
+ }), s = (e, t, n) => {
1110
+ let [r, i] = F(e, t);
1111
+ return Ue(o[e].shape, r, i, 4 * p, {
1112
+ ...n,
1113
+ style: `${n.style ?? ""}${O(i)}${V(t)}`
952
1114
  });
953
- }, i = (e) => n.map((e, t) => t).filter((t) => !E(e, t)), a = r.flatMap((n, r) => e[r].open ? i(r).map((e) => t(r, e, {
954
- class: f,
955
- "data-row": e + 1,
956
- ...v && { "data-series": r + 1 }
1115
+ }, c = (t) => n.map((e, t) => t).filter((n) => !A(t, n) && e(t, n)), l = a.flatMap((e) => o[e].open ? c(e).map((t) => s(e, t, {
1116
+ class: h,
1117
+ "data-row": t + 1,
1118
+ ...S && { "data-series": e + 1 }
957
1119
  })) : []);
958
- ee(m, a, C, l), r.forEach((n, r) => {
959
- for (let n of i(r)) m.appendChild(t(r, n, {
960
- class: d,
961
- ...M[r].attrs,
962
- "data-marker": e[r].shape,
963
- ...e[r].open && { "data-open": "" },
964
- "data-row": n + 1,
965
- style: M[r].ink
1120
+ _.closest("[data-animate]")?.getAttribute("data-animate") === "grow" ? U(_, l, D, f) : t.lineHoles.push(...l), a.forEach((e) => {
1121
+ for (let t of c(e)) _.appendChild(s(e, t, {
1122
+ class: m,
1123
+ ...I[e].attrs,
1124
+ "data-marker": o[e].shape,
1125
+ ...o[e].open && { "data-open": "" },
1126
+ "data-row": t + 1,
1127
+ style: I[e].ink
966
1128
  }));
967
1129
  });
968
- })();
969
- let K = (e, t) => {
1130
+ };
1131
+ e && a.forEach((e) => ae(e)), a.forEach((e) => oe(e));
1132
+ let ce = y ? r.flatMap((e, t) => a.includes(t) ? [] : o[t].flatMap((e) => {
1133
+ let t = e.dataset.place;
1134
+ if (!t || t === "none" || e.hasAttribute("data-left-out")) return [];
1135
+ let [n, r, i, a] = Y(e, p, D, f);
1136
+ return [{
1137
+ label: e,
1138
+ box: [
1139
+ n - 2 * p,
1140
+ r - 3 * p,
1141
+ i + 4 * p,
1142
+ a + 6 * p
1143
+ ]
1144
+ }];
1145
+ })) : [], ue = b ? [] : a.flatMap((e) => n.flatMap((t, n) => {
1146
+ if (A(e, n)) return [];
1147
+ let [r, i] = F(e, n);
1148
+ return [[
1149
+ r - 4 * p,
1150
+ i - 4 * p,
1151
+ 8 * p,
1152
+ 8 * p
1153
+ ]];
1154
+ })), fe = ce.filter(({ label: e, box: t }) => {
1155
+ let n = ue.some((e) => le(e, t));
1156
+ return n && e.setAttribute("data-left-out", ""), !n;
1157
+ }), pe = (e, t) => {
970
1158
  let n = t;
971
- for (; n < b && !E(e, n + 1) && T(e, n + 1)?.value === T(e, t)?.value;) n++;
1159
+ for (; n < w && !A(e, n + 1) && k(e, n + 1)?.value === k(e, t)?.value;) n++;
972
1160
  return n;
973
- }, oe = (t, n) => {
974
- let i = T(t, n);
975
- if (!i || i.missing || g && n > 0 && !E(t, n - 1) && T(t, n - 1)?.value === i.value || y && !r[t].focus) return "none";
976
- if (h) return "middle";
1161
+ }, me = (e) => e === "above" ? "below" : "above", he = (e, t, n) => {
1162
+ let [r, i] = F(e, t), a = J(o[e][t]).width * p, s = [
1163
+ r - a / 2,
1164
+ n === "above" ? i - 7 * p - g : i + 7 * p,
1165
+ a,
1166
+ g
1167
+ ];
1168
+ return s[1] + g > f ? Infinity : [t - 1, t + 1].filter((t) => t >= 0 && t <= w && !A(e, t)).flatMap((n) => ge(e, t, n, 0)).filter((e) => le(e, s)).length;
1169
+ }, ge = (e, t, n, r) => {
1170
+ let [i, a] = F(e, t), [o, s] = F(e, n), c = Math.max(1, Math.ceil(Math.hypot(o - i, s - a) / (3 * p)));
1171
+ return Array.from({ length: c + 1 }, (e, t) => {
1172
+ let n = t / c;
1173
+ return [
1174
+ i + (o - i) * n - r,
1175
+ a + (s - a) * n - r,
1176
+ 2 * r,
1177
+ 2 * r
1178
+ ];
1179
+ });
1180
+ }, _e = (t, n) => {
1181
+ let i = k(t, n);
1182
+ if (!i || i.missing || b && n > 0 && !A(t, n - 1) && k(t, n - 1)?.value === i.value || C && !r[t].focus) return "none";
1183
+ if (v) return "middle";
977
1184
  let a = i.value < 0 ? "below" : "above";
978
- if (!v || y || r.length > 2) return a;
979
- let o = T(1 - t, n);
980
- return !o || o.missing ? a : i.value > o.value || i.value === o.value && t === 0 || e && i.value >= 0 && j(t, n)[1] + 7 * u + p > x ? "above" : "below";
981
- }, se = v && !y && r.length > 2 && !h && !g, ce = /* @__PURE__ */ new Map();
982
- if (se) {
983
- let e = n.flatMap((e, t) => r.map((e, n) => ({
984
- s: n,
1185
+ if (!S || C || r.length > 2) return e || b || he(t, n, a) <= he(t, n, me(a)) ? a : me(a);
1186
+ let o = k(1 - t, n);
1187
+ return !o || o.missing ? a : i.value > o.value || i.value === o.value && t === 0 || e && i.value >= 0 && F(t, n)[1] + 7 * p + g > T ? "above" : "below";
1188
+ }, ve = (y || S && !C && r.length > 2 && !v) && !b, be = /* @__PURE__ */ new Map();
1189
+ if (ve) {
1190
+ let e = n.flatMap((e, t) => a.map((e) => ({
1191
+ s: e,
985
1192
  i: t,
986
- value: T(n, t)?.value ?? 0
987
- }))).filter(({ s: e, i: t }) => oe(e, t) !== "none").sort((e, t) => e.i - t.i || t.value - e.value || e.s - t.s), t = (e) => e < 0 ? ["below", "above"] : ["above", "below"], i = ae(e.map(({ s: e, i: n, value: r }) => {
988
- let i = q(a[e][n]).width * u, [o, s] = j(e, n);
1193
+ value: k(e, t)?.value ?? 0
1194
+ }))).filter(({ s: e, i: t }) => _e(e, t) !== "none").sort((e, t) => e.i - t.i || t.value - e.value || e.s - t.s), t = (e) => e < 0 ? ["below", "above"] : ["above", "below"], r = de(e.map(({ s: e, i: n, value: r }) => {
1195
+ let i = J(o[e][n]).width * p, [a, s] = F(e, n);
989
1196
  return t(r).map((e) => [
990
- o - i / 2,
991
- e === "above" ? s - 7 * u - p : s + 7 * u,
1197
+ a - i / 2,
1198
+ e === "above" ? s - 7 * p - g : s + 7 * p,
992
1199
  i,
993
- p
1200
+ g
994
1201
  ]);
995
- }), r.flatMap((e, t) => n.flatMap((e, n) => {
996
- if (E(t, n)) return [];
997
- let [r, i] = j(t, n);
1202
+ }), [...a.flatMap((e) => n.flatMap((t, n) => {
1203
+ if (A(e, n)) return [];
1204
+ let [r, i] = F(e, n);
998
1205
  return [[
999
- r - 4 * u,
1000
- i - 4 * u,
1001
- 8 * u,
1002
- 8 * u
1206
+ r - 4 * p,
1207
+ i - 4 * p,
1208
+ 8 * p,
1209
+ 8 * p
1003
1210
  ]];
1004
- })), [
1211
+ })), ...fe.map(({ box: e }) => e)], [
1005
1212
  0,
1006
1213
  0,
1007
- s(b) + s(0),
1008
- l
1214
+ c(w) + c(0),
1215
+ f
1009
1216
  ]);
1010
- e.forEach(({ s: e, i: n, value: r }, o) => ce.set(a[e][n], i[o] === null ? null : t(r)[i[o]]));
1217
+ e.forEach(({ s: e, i: n, value: i }, a) => be.set(o[e][n], r[a] === null ? null : t(i)[r[a]]));
1011
1218
  }
1012
- let le = (e, t) => se ? ce.get(a[e][t]) === null : !h && !g ? !1 : q(a[e][t]).width * u > (g ? K(e, t) - t + 1 : 1) * S - 4 * u || h && e > 0 && O(e, t) < k(e, t) ? !0 : h && Math.abs(c(k(e, t)) - c(O(e, t))) < p * 1.2;
1013
- a.forEach((e, t) => {
1014
- e.forEach((e, n) => {
1015
- e.style.setProperty("--i", String(X(g ? (I(n) + I(n + 1)) / 2 : I(n))));
1016
- let r = ce.get(e) ?? oe(t, n);
1017
- if (e.dataset.place = r === "above" ? "outside" : r, e.toggleAttribute("data-left-out", r !== "none" && le(t, n)), g && r !== "none" ? e.dataset.rowEnd = String(K(t, n) + 1) : delete e.dataset.rowEnd, r === "none") return;
1018
- let i = q(e).width * u / 2 + 4 * u, a = s(n);
1019
- g ? a = (s(n) + s(K(t, n))) / 2 : r === "middle" && n === 0 ? a += i : r === "middle" && n === b && (a -= i);
1020
- let o = c(O(t, n)), d = {
1021
- middle: (c(k(t, n)) - o) / 2,
1022
- above: -7 * u,
1023
- below: 7 * u
1219
+ let xe = (e, t) => ve ? be.get(o[e][t]) === null : !v && !b ? !1 : J(o[e][t]).width * p > (b ? pe(e, t) - t + 1 : 1) * E - 4 * p || v && e > 0 && M(e, t) < N(e, t) ? !0 : v && Math.abs(l(N(e, t)) - l(M(e, t))) < g * 1.2;
1220
+ a.forEach((e) => {
1221
+ o[e].forEach((t, n) => {
1222
+ t.style.setProperty("--i", String(Z(b ? (B(n) + B(n + 1)) / 2 : B(n))));
1223
+ let r = be.get(t) ?? _e(e, n);
1224
+ if (t.dataset.place = r === "above" ? "outside" : r, t.toggleAttribute("data-left-out", r !== "none" && xe(e, n)), b && r !== "none" ? t.dataset.rowEnd = String(pe(e, n) + 1) : delete t.dataset.rowEnd, r === "none") return;
1225
+ let i = J(t).width * p / 2 + 4 * p, a = c(n);
1226
+ b ? a = (c(n) + c(pe(e, n))) / 2 : r === "middle" && n === 0 ? a += i : r === "middle" && n === w && (a -= i);
1227
+ let o = l(M(e, n)), s = {
1228
+ middle: (l(N(e, n)) - o) / 2,
1229
+ above: -7 * p,
1230
+ below: 7 * p
1024
1231
  };
1025
- N(e, a, o + d[r], C, l);
1232
+ L(t, a, o + s[r], D, f);
1026
1233
  });
1027
1234
  });
1028
- let J = o.map((e, t) => {
1029
- let n = b;
1030
- for (; n > 0 && E(t, n);) n--;
1031
- let [r, i] = j(t, n);
1235
+ let Se = (e) => {
1236
+ let r = n.flatMap((t, n) => t.pinned && !A(e, n) ? [n] : []), i = n.map((e, t) => t).filter((t) => !A(e, t)), a = (t) => k(e, t)?.value ?? 0, { keys: s } = t.pick;
1237
+ i.length && (s.includes("last") && r.push(i[i.length - 1]), s.includes("first") && r.push(i[0]), s.includes("highest") && r.push(i.reduce((e, t) => a(t) > a(e) ? t : e)), s.includes("lowest") && r.push(i.reduce((e, t) => a(t) < a(e) ? t : e)), s.includes("outliers") && r.push(...Qe(i.map((e) => ({
1238
+ x: e,
1239
+ y: a(e)
1240
+ })))?.outside.map((e) => e.x) ?? []));
1241
+ let c = [];
1242
+ for (let t of r) {
1243
+ let n = o[e][t];
1244
+ c.includes(t) || n.dataset.place === "none" || c.every((t) => Ce([o[e][t], n], p, 1e3, f) === 1) && c.push(t);
1245
+ }
1246
+ return new Set(c);
1247
+ }, we = (e) => Ce(o[e].filter((e) => e.dataset.place !== "none" && !e.hasAttribute("data-left-out")), p, D, f) === 1, Te = (e) => {
1248
+ let t = w;
1249
+ for (; t > 0 && A(e, t);) t--;
1250
+ return t;
1251
+ }, Ee = /* @__PURE__ */ new Map();
1252
+ for (let e of a) {
1253
+ let n = t.pick.mode === "all" || t.pick.mode === "auto" && we(e) ? null : Se(e);
1254
+ Ee.set(e, n), n && o[e].forEach((e, t) => {
1255
+ e.dataset.place !== "none" && !n.has(t) && e.setAttribute("data-left-out", "");
1256
+ });
1257
+ }
1258
+ if (!v && !b && a.some((e) => Ee.get(e))) {
1259
+ let e = c(w) + c(0), t = 2 * p, r = a.flatMap((e) => n.flatMap((n, r) => r === w || A(e, r) || A(e, r + 1) ? [] : ge(e, r, r + 1, t))), i = (s[0] ? J(s[0]).height : 0) * p, l = a.flatMap((e) => {
1260
+ let t = s[e];
1261
+ if (!t) return [];
1262
+ let n = w;
1263
+ for (; n > 0 && A(e, n);) n--;
1264
+ let [r, a] = F(e, n);
1265
+ return [[
1266
+ r + 10 * p,
1267
+ a - i / 2,
1268
+ J(t).width * p,
1269
+ i
1270
+ ]];
1271
+ }), u = a.flatMap((e) => [...Ee.get(e) ?? []].map((t) => ({
1272
+ s: e,
1273
+ i: t
1274
+ }))), d = ({ s: e, i: t }) => {
1275
+ let n = k(e, t)?.value ?? 0, r = t > 0 && !A(e, t - 1) ? k(e, t - 1)?.value : void 0, i = t < w && !A(e, t + 1) ? k(e, t + 1)?.value : void 0;
1276
+ return (r ?? i) !== void 0 && (r === void 0 || n <= r) && (i === void 0 || n <= i) ? [
1277
+ "below",
1278
+ "outside",
1279
+ "below far",
1280
+ "outside far",
1281
+ "after",
1282
+ "before"
1283
+ ] : [
1284
+ "outside",
1285
+ "below",
1286
+ "outside far",
1287
+ "below far",
1288
+ "after",
1289
+ "before"
1290
+ ];
1291
+ }, m = ({ s: t, i: n }, r) => {
1292
+ let i = J(o[t][n]).width * p, a = g, [s, c] = F(t, n), l = Math.min(Math.max(s - i / 2, 0), e - i);
1293
+ return r === "outside" ? [
1294
+ l,
1295
+ c - 7 * p - a,
1296
+ i,
1297
+ a
1298
+ ] : r === "below" ? [
1299
+ l,
1300
+ c + 7 * p,
1301
+ i,
1302
+ a
1303
+ ] : r === "outside far" ? [
1304
+ l,
1305
+ c - 7 * p - 2 * a,
1306
+ i,
1307
+ a
1308
+ ] : r === "below far" ? [
1309
+ l,
1310
+ c + 7 * p + a,
1311
+ i,
1312
+ a
1313
+ ] : r === "after" ? [
1314
+ s + 7 * p,
1315
+ c - a / 2,
1316
+ i,
1317
+ a
1318
+ ] : [
1319
+ s - 7 * p - i,
1320
+ c - a / 2,
1321
+ i,
1322
+ a
1323
+ ];
1324
+ }, h = u.map(d), _ = (t) => t[0] >= 0 && t[1] >= 0 && t[0] + t[2] <= e && t[1] + t[3] <= f - 2 * p, v = u.map(({ s: e, i: t }) => {
1325
+ let [n, r] = F(e, t);
1326
+ return [
1327
+ n - 6 * p,
1328
+ r - 6 * p,
1329
+ 12 * p,
1330
+ 12 * p
1331
+ ];
1332
+ }), y = [], b = /* @__PURE__ */ new Set(), x = u.map((e, t) => {
1333
+ let n = h[t].map((t) => m(e, t)), i = (e) => _(e) && ![
1334
+ ...y,
1335
+ ...l,
1336
+ ...v
1337
+ ].some((t) => le(e, t)), a = n.findIndex((e) => i(e) && !r.some((t) => le(e, t)));
1338
+ return a < 0 && (a = n.findIndex(i), a >= 0 && b.add(t)), a >= 0 && y.push(n[a]), a < 0 ? null : a;
1339
+ });
1340
+ u.forEach((e, t) => {
1341
+ let n = o[e.s][e.i];
1342
+ n.toggleAttribute("data-cut", b.has(t));
1343
+ let r = x[t];
1344
+ if (r === null) return n.setAttribute("data-left-out", "");
1345
+ let i = h[t][r], [a, s, c, l] = m(e, i), u = i.split(" ")[0];
1346
+ n.dataset.place = u, L(n, u === "after" ? a : u === "before" ? a + c : a + c / 2, u === "outside" ? s + l : u === "below" ? s : s + l / 2, D, f);
1347
+ });
1348
+ }
1349
+ b || se((e, t) => {
1350
+ let n = Ee.get(e);
1351
+ return n ? n.has(t) : E >= 10 * p;
1352
+ }), t.pointOf = (e) => {
1353
+ let t = a.filter((t) => !A(t, e)).map((t) => F(t, e));
1354
+ return t.length ? t.reduce((e, t) => t[1] < e[1] ? t : e) : null;
1355
+ };
1356
+ let De = (y ? [] : s).map((e, t) => {
1357
+ let n = Te(t), [r, i] = F(t, n);
1032
1358
  return {
1033
1359
  name: e,
1034
- x: (g ? r + S / 2 : r) + 10 * u,
1035
- y: h ? (i + c(k(t, n))) / 2 : i
1360
+ x: (b ? r + E / 2 : r) + 10 * p,
1361
+ y: v ? (i + l(N(t, n))) / 2 : i
1036
1362
  };
1037
- }), ue = (o[0] ? q(o[0]).height : 0) * u;
1038
- for (let e of Se(J, ue)) N(e.name, e.x, e.y, C, l);
1039
- let de = n.some((e) => e.cells.some((e) => !e.missing && e.value < 0)), Y = !e && !h && r.length === 2 && !y && !de ? l - 2 * u : x;
1040
- m.appendChild(A("line", {
1363
+ }), Oe = (s[0] ? J(s[0]).height : 0) * p;
1364
+ for (let e of ye(De, Oe)) L(e.name, e.x, e.y, D, f);
1365
+ let ke = n.some((e) => e.cells.some((e) => !e.missing && e.value < 0)), Ae = !e && !v && r.length === 2 && !C && !ke ? f - 2 * p : T;
1366
+ y || _.appendChild(P("line", {
1041
1367
  class: i,
1042
1368
  x1: 0,
1043
- x2: s(b) + s(0),
1044
- y1: Y,
1045
- y2: Y
1369
+ x2: c(w) + c(0),
1370
+ y1: Ae,
1371
+ y2: Ae
1046
1372
  }));
1047
1373
  }
1048
- }), Le = Ie(!1), Re = Ie(!0), ze = /* @__PURE__ */ new Set(), Be = (t, n) => {
1374
+ }), tt = et(!1), nt = et(!0), rt = /* @__PURE__ */ new Set(), it = (t, n) => {
1049
1375
  if (Math.abs(t - n) <= Math.abs(n) / 100) return;
1050
1376
  let r = `[${e}] A total reads ${t}, but the steps before it add up to ${Number(n.toFixed(6))}. The chart shows your number.`;
1051
- ze.has(r) || (ze.add(r), console.warn(r));
1052
- }, Ve = {
1377
+ rt.has(r) || (rt.add(r), console.warn(r));
1378
+ }, at = {
1053
1379
  segments: (e) => {
1054
1380
  let t = 0, n = !1;
1055
1381
  return e.map((e) => {
1056
- if (e.isTotal) return n && Be(e.value, t), n = !1, t = e.value, {
1382
+ if (e.isTotal) return n && it(e.value, t), n = !1, t = e.value, {
1057
1383
  ...e,
1058
1384
  from: 0,
1059
1385
  to: e.value,
@@ -1071,34 +1397,34 @@ var Fe = (e) => e.map((e) => ({
1071
1397
  breakable: !0,
1072
1398
  headroom: ({ labelHeight: e, badgeHeight: t, hasAnnotations: n, unit: r }) => e + 6 * r + (n ? t * 1.6 : 0),
1073
1399
  draw({ segments: e, cx: t, y: n, barWidth: a, height: o, unit: s, svg: c, values: l, breakAt: u, insideAlign: d }) {
1074
- let f = n(0), p = ve(l, a, s), m = d ?? "center", h = e.map((t, r) => {
1400
+ let f = n(0), p = he(l, a, s), m = d ?? "center", h = e.map((t, r) => {
1075
1401
  let i = n(Math.max(t.from, t.to)), a = Math.abs(n(t.from) - n(t.to)), o = u !== null && Math.min(t.from, t.to) < u && Math.max(t.from, t.to) > u, c = t.kind === "total" && r > 0 && r === e.length - 1;
1076
1402
  return {
1077
1403
  top: i,
1078
1404
  length: a,
1079
1405
  down: t.kind === "down" || t.kind === "total" && (c ? t.to >= 0 : t.to < 0),
1080
- inside: !o && !p && ye(l[r], a, s)
1406
+ inside: !o && !p && ge(l[r], a, s)
1081
1407
  };
1082
- }), g = l[0] ? q(l[0]).height * s * .56 : 0, _ = Infinity;
1083
- for (let [e, t] of h.entries()) t.inside && (_ = Math.min(_, (a - q(l[e]).width * s) / 2));
1084
- let v = e.length, y = (e, t, n = !1) => `--start:${(e / v).toFixed(4)}; --span:${(t / v).toFixed(4)}; --ease:${n ? T : "linear"};`;
1408
+ }), g = l[0] ? J(l[0]).height * s * .56 : 0, _ = Infinity;
1409
+ for (let [e, t] of h.entries()) t.inside && (_ = Math.min(_, (a - J(l[e]).width * s) / 2));
1410
+ let v = e.length, y = (e, t, n = !1) => `--start:${(e / v).toFixed(4)}; --span:${(t / v).toFixed(4)}; --ease:${n ? k : "linear"};`;
1085
1411
  e.forEach((r, i) => {
1086
1412
  let o = e[i + 1];
1087
1413
  if (!o) return;
1088
1414
  let s = n(r.to), l = t(i) + a / 2, u = t(i + 1) - a / 2;
1089
- c.appendChild(A("line", {
1415
+ c.appendChild(P("line", {
1090
1416
  class: "tablechart-connector",
1091
1417
  x1: l,
1092
1418
  x2: u,
1093
1419
  y1: s,
1094
1420
  y2: s,
1095
1421
  "data-row": i + 2,
1096
- style: `${D("--i", o.slot)}; ${y(i + 1, 1 / 3)}`
1422
+ style: `${j("--i", o.slot)}; ${y(i + 1, 1 / 3)}`
1097
1423
  }));
1098
1424
  }), e.forEach((n, i) => {
1099
1425
  let { top: u, length: d, down: f, inside: p } = h[i];
1100
- c.appendChild(A("rect", {
1101
- class: j(r, n),
1426
+ c.appendChild(P("rect", {
1427
+ class: F(r, n),
1102
1428
  "data-kind": n.kind,
1103
1429
  "data-row": i + 1,
1104
1430
  "data-grow": f ? "down" : "up",
@@ -1106,33 +1432,33 @@ var Fe = (e) => e.map((e) => ({
1106
1432
  y: u,
1107
1433
  width: a,
1108
1434
  height: Math.max(d, 1),
1109
- style: `${D("--i", n.slot)}; ${y(i, 1, i === e.length - 1)}`
1435
+ style: `${j("--i", n.slot)}; ${y(i, 1, i === e.length - 1)}`
1110
1436
  }));
1111
1437
  let b = l[i];
1112
1438
  b.style.setProperty("--start", (i / v).toFixed(4)), b.style.setProperty("--span", (1 / v).toFixed(4));
1113
- let x = Math.min(_, (d - g) / 2), S = u + x + g / 2, w = u + d - x - g / 2, T = m === "center" ? u + d / 2 : m === "end" === f ? w : S;
1439
+ let x = Math.min(_, (d - g) / 2), S = u + x + g / 2, C = u + d - x - g / 2, w = m === "center" ? u + d / 2 : m === "end" === f ? C : S;
1114
1440
  b.dataset.place = p ? "inside" : "outside", b.dataset.kind = n.kind;
1115
- let E = p ? T : n.kind === "down" ? u + d + q(b).height * s + 3 * s : u - 3 * s;
1116
- N(b, t(i), E, C, o);
1117
- }), c.appendChild(A("line", {
1441
+ let T = p ? w : n.kind === "down" ? u + d + J(b).height * s + 3 * s : u - 3 * s;
1442
+ L(b, t(i), T, D, o);
1443
+ }), c.appendChild(P("line", {
1118
1444
  class: i,
1119
1445
  x1: 0,
1120
- x2: C,
1446
+ x2: D,
1121
1447
  y1: f,
1122
1448
  y2: f
1123
1449
  }));
1124
1450
  }
1125
- }, Z = {
1451
+ }, Q = {
1126
1452
  enabled: !1,
1127
1453
  log(...t) {
1128
- Z.enabled && console.log(`[${e}]`, ...t);
1454
+ Q.enabled && console.log(`[${e}]`, ...t);
1129
1455
  },
1130
1456
  timed(t, n, r) {
1131
- if (!Z.enabled) return r();
1457
+ if (!Q.enabled) return r();
1132
1458
  let i = performance.now(), a = r(), o = performance.now() - i, s = n.querySelectorAll("tbody tr").length;
1133
- return o > 50 ? console.warn(`[${e}] ${t} took ${o.toFixed(1)} ms for ${s} rows, more than 50 ms.`, n) : Z.log(`${t} took ${o.toFixed(1)} ms for ${s} rows.`, n), a;
1459
+ return o > 50 ? console.warn(`[${e}] ${t} took ${o.toFixed(1)} ms for ${s} rows, more than 50 ms.`, n) : Q.log(`${t} took ${o.toFixed(1)} ms for ${s} rows.`, n), a;
1134
1460
  }
1135
- }, He = (e) => {
1461
+ }, ot = (e) => {
1136
1462
  let t = (e?.textContent || "").trim(), n = t.match(/^(.*?)(-?\d+(?:[.,]\d+)?)(.*)$/);
1137
1463
  return {
1138
1464
  raw: t,
@@ -1142,19 +1468,31 @@ var Fe = (e) => e.map((e) => ({
1142
1468
  missing: !n,
1143
1469
  value: n ? Number.parseFloat(n[2].replace(",", ".")) : 0
1144
1470
  };
1145
- }, Ue = (e, t = "data-i18n") => Array.from(e.querySelectorAll("tbody tr")).map((e, n) => {
1146
- let r = e.querySelector("th"), i = Array.from(e.querySelectorAll("td")).map(He);
1147
- return i.length || i.push(He(null)), {
1148
- ...i[0],
1149
- label: (r?.textContent || "").trim(),
1150
- key: t && r?.getAttribute(t) || null,
1151
- cells: i,
1152
- classes: Array.from(e.classList),
1153
- isTotal: e.getAttribute("data-kind") === "total",
1154
- slot: n
1155
- };
1156
- }), We = (e) => Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1), Ge = (e) => e === "dashed" || e === "dotted" ? e : null, Ke = (e, t, n = "data-i18n") => {
1157
- let r = We(e), i = Math.max(1, R(t.map((e) => e.cells.length)));
1471
+ }, st = (e) => Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1).flatMap((e, t) => e.hasAttribute("data-note") ? [t] : []), ct = (e, t) => {
1472
+ let n = st(e), r = e.querySelectorAll("tbody tr")[t]?.querySelectorAll("td") ?? [];
1473
+ return n.map((e) => r[e]).find((e) => e?.textContent?.trim()) ?? null;
1474
+ }, lt = (e, t = "data-i18n") => {
1475
+ let n = st(e);
1476
+ return Array.from(e.querySelectorAll("tbody tr")).map((e, r) => {
1477
+ let i = e.querySelector("th"), a = Array.from(e.querySelectorAll("td")), o = a.filter((e, t) => !n.includes(t)).map(ot);
1478
+ o.length || o.push(ot(null));
1479
+ let s = n.map((e) => a[e]).find((e) => e?.textContent?.trim());
1480
+ return {
1481
+ ...o[0],
1482
+ label: (i?.textContent || "").trim(),
1483
+ note: s?.textContent?.trim() ?? null,
1484
+ noteKey: t && s?.getAttribute(t) || null,
1485
+ short: i?.getAttribute("data-short") || null,
1486
+ pinned: e.getAttribute("data-value") === "show",
1487
+ key: t && i?.getAttribute(t) || null,
1488
+ cells: o,
1489
+ classes: Array.from(e.classList),
1490
+ isTotal: e.getAttribute("data-kind") === "total",
1491
+ slot: r
1492
+ };
1493
+ });
1494
+ }, ut = (e) => Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1).filter((e) => !e.hasAttribute("data-note")), dt = (e) => e === "dashed" || e === "dotted" ? e : null, ft = (e, t, n = "data-i18n") => {
1495
+ let r = ut(e), i = Math.max(1, W(t.map((e) => e.cells.length)));
1158
1496
  return Array.from({ length: i }, (e, t) => {
1159
1497
  let i = r[t];
1160
1498
  return {
@@ -1162,11 +1500,12 @@ var Fe = (e) => e.map((e) => ({
1162
1500
  key: n && i?.getAttribute(n) || null,
1163
1501
  focus: i?.getAttribute("data-kind") === "focus",
1164
1502
  marker: i?.getAttribute("data-marker") ?? null,
1165
- line: Ge(i?.getAttribute("data-line")),
1166
- group: !!i?.hasAttribute("data-group")
1503
+ line: dt(i?.getAttribute("data-line")),
1504
+ group: !!i?.hasAttribute("data-group"),
1505
+ chart: i?.getAttribute("data-chart") === "line" ? "line" : null
1167
1506
  };
1168
1507
  });
1169
- }, qe = (t, n) => {
1508
+ }, pt = (t, n) => {
1170
1509
  if (!n) return;
1171
1510
  let r = /* @__PURE__ */ new Map();
1172
1511
  for (let i of t) {
@@ -1179,7 +1518,7 @@ var Fe = (e) => e.map((e) => ({
1179
1518
  i.querySelectorAll("tbody th").forEach((e, r) => {
1180
1519
  e.getAttribute(n) || e.setAttribute(n, `${t}-row${r + 1}`);
1181
1520
  });
1182
- let a = We(i);
1521
+ let a = ut(i);
1183
1522
  a.length > 1 && a.forEach((e, r) => {
1184
1523
  e.getAttribute(n) || e.setAttribute(n, `${t}-col${r + 1}`);
1185
1524
  }), a.forEach((e, r) => {
@@ -1189,115 +1528,127 @@ var Fe = (e) => e.map((e) => ({
1189
1528
  let r = (e.textContent || "").trim();
1190
1529
  a.includes(r) || a.push(r), e.getAttribute(n) || e.setAttribute(n, `${t}-group${a.indexOf(r) + 1}`);
1191
1530
  });
1192
- }), Z?.log?.(`Keys for "${t}" written onto ${i.querySelectorAll("tbody th").length} rows`);
1531
+ });
1532
+ let o = st(i);
1533
+ i.querySelectorAll("tbody tr").forEach((e, r) => {
1534
+ let i = e.querySelectorAll("td");
1535
+ for (let e of o) {
1536
+ let a = i[e];
1537
+ a?.textContent?.trim() && !a.getAttribute(n) && a.setAttribute(n, `${t}-note${r + 1}`);
1538
+ }
1539
+ }), Q?.log?.(`Keys for "${t}" written onto ${i.querySelectorAll("tbody th").length} rows`);
1193
1540
  }
1194
- }, Je = (e) => Number(e.toPrecision(12)), Ye = (e, t) => {
1541
+ }, mt = (e) => Number(e.toPrecision(12)), ht = (e, t) => {
1195
1542
  let n = e / Math.max(1, t) || 1, r = 10 ** Math.floor(Math.log10(n)), i = n / r;
1196
- return Je((i < 1.42 ? 1 : i < 3.17 ? 2 : i < 7.08 ? 5 : 10) * r);
1197
- }, Xe = (e, t, n) => {
1543
+ return mt((i < 1.42 ? 1 : i < 3.17 ? 2 : i < 7.08 ? 5 : 10) * r);
1544
+ }, gt = (e, t, n) => {
1198
1545
  let r = [];
1199
- for (let i = Math.ceil(e / n - 1e-9); i * n <= t + n * 1e-9; i++) r.push(Je(i * n));
1546
+ for (let i = Math.ceil(e / n - 1e-9); i * n <= t + n * 1e-9; i++) r.push(mt(i * n));
1200
1547
  return r;
1201
- }, Ze = (e, t = e) => {
1548
+ }, _t = (e, t = e) => {
1202
1549
  do {
1203
1550
  let t = Math.round(e / 10 ** Math.floor(Math.log10(e) + 1e-9));
1204
- e = Je(e * (t === 2 ? 2.5 : 2));
1551
+ e = mt(e * (t === 2 ? 2.5 : 2));
1205
1552
  } while (Math.abs(e / t - Math.round(e / t)) > 1e-9);
1206
1553
  return e;
1207
- }, Qe = (e) => {
1554
+ }, vt = (e) => {
1208
1555
  let t = (e ?? "").trim().split(/\s+/).map(Number.parseFloat);
1209
1556
  return t.length > 1 && t.every(Number.isFinite) ? t.sort((e, t) => e - t) : null;
1210
- }, $e = (e, t, n) => {
1557
+ }, yt = (e, t, n) => {
1211
1558
  if (n && n.length > 2) return {
1212
1559
  min: n[0],
1213
1560
  max: n[n.length - 1],
1214
1561
  step: 0,
1215
1562
  ticks: n
1216
1563
  };
1217
- let r = n?.[0] ?? -R(e.map((e) => -e)), i = n?.[1] ?? R(e);
1564
+ let r = n?.[0] ?? -W(e.map((e) => -e)), i = n?.[1] ?? W(e);
1218
1565
  if (!n) {
1219
1566
  let e = (i - r || Math.abs(i) || 1) * .05;
1220
1567
  r -= e, i += e;
1221
1568
  }
1222
- let a = Ye(i - r, t);
1569
+ let a = ht(i - r, t);
1223
1570
  return {
1224
1571
  min: r,
1225
1572
  max: i,
1226
1573
  step: a,
1227
- ticks: Xe(r, i, a)
1574
+ ticks: gt(r, i, a)
1228
1575
  };
1229
- }, et = (e, t) => {
1576
+ }, bt = (e, t) => {
1230
1577
  let { step: n, ticks: r } = e;
1231
- for (; n && r.length > 2 && !t(r);) n = Ze(n, e.step), r = Xe(e.min, e.max, n);
1578
+ for (; n && r.length > 2 && !t(r);) n = _t(n, e.step), r = gt(e.min, e.max, n);
1232
1579
  return {
1233
1580
  ...e,
1234
1581
  step: n,
1235
1582
  ticks: r
1236
1583
  };
1237
- }, tt = [
1584
+ }, xt = [
1238
1585
  "axis-break",
1239
1586
  "trend",
1240
1587
  "bracket"
1241
- ], nt = (e) => {
1242
- let t = e.hasAttribute("data-fragment"), n = Array.from(e.querySelectorAll("tbody tr")), r = Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1), i = Array.from(e.querySelectorAll("[data-annotation]")).filter((e) => tt.includes(e.getAttribute("data-annotation") ?? "")), a = (e) => e.hasAttribute("data-fragment"), o = n.map((e) => Array.from(e.querySelectorAll(":scope > td")));
1243
- if (!t && !n.some(a) && !r.some(a) && !o.flat().some(a) && !i.some(a)) return null;
1244
- let s = [], c = /* @__PURE__ */ new Map(), l = [], u = (e) => {
1245
- let t = e === null ? void 0 : c.get(e);
1246
- return t === void 0 && (t = s.length, s.push(e), l.push(0), e !== null && c.set(e, t)), t;
1247
- }, d = 0, f = e.getAttribute("data-chart") === "donut", p = (e) => f && e.getAttribute("data-kind") === "total", m = n.map((e) => {
1248
- if (p(e)) return {
1588
+ ], St = (e, t = !1) => {
1589
+ let n = e.hasAttribute("data-fragment"), r = Array.from(e.querySelectorAll("tbody tr")), i = Array.from(e.querySelector("thead tr:last-child")?.children ?? []).slice(1), a = Array.from(e.querySelectorAll("[data-annotation]")).filter((e) => xt.includes(e.getAttribute("data-annotation") ?? "")), o = (e) => e.hasAttribute("data-fragment"), s = r.map((e) => Array.from(e.querySelectorAll(":scope > td")));
1590
+ if (!n && !r.some(o) && !i.some(o) && !s.flat().some(o) && !a.some(o) || t && !n) return null;
1591
+ let c = [], l = /* @__PURE__ */ new Map(), u = [], d = (e) => {
1592
+ let t = e === null ? void 0 : l.get(e);
1593
+ return t === void 0 && (t = c.length, c.push(e), u.push(0), e !== null && l.set(e, t)), t;
1594
+ }, f = 0, p = e.getAttribute("data-chart") === "donut", m = (e) => p && e.getAttribute("data-kind") === "total", h = t ? d(e.getAttribute("data-fragment-index")) : -1, g = r.map((e) => {
1595
+ if (m(e)) return {
1249
1596
  step: null,
1250
1597
  slot: 0
1251
1598
  };
1252
- if (!t && !a(e)) return {
1599
+ if (t) return {
1600
+ step: h,
1601
+ slot: u[h]++
1602
+ };
1603
+ if (!n && !o(e)) return {
1253
1604
  step: null,
1254
- slot: d++
1605
+ slot: f++
1255
1606
  };
1256
- let n = u(e.getAttribute("data-fragment-index"));
1607
+ let r = d(e.getAttribute("data-fragment-index"));
1257
1608
  return {
1258
- step: n,
1259
- slot: l[n]++
1609
+ step: r,
1610
+ slot: u[r]++
1260
1611
  };
1261
- }), h = Math.max(-1, ...m.map((e) => e.step ?? -1));
1262
- if (h >= 0) for (let [e, t] of n.entries()) p(t) && (m[e] = {
1263
- step: h,
1264
- slot: l[h]++
1612
+ }), _ = Math.max(-1, ...g.map((e) => e.step ?? -1));
1613
+ if (_ >= 0) for (let [e, t] of r.entries()) m(t) && (g[e] = {
1614
+ step: _,
1615
+ slot: u[_]++
1265
1616
  });
1266
- let g = r.map((e) => ({ step: a(e) ? u(e.getAttribute("data-fragment-index")) : null })), _ = o.map((e) => e.map(() => ({
1617
+ let v = i.map((e) => ({ step: o(e) ? d(e.getAttribute("data-fragment-index")) : null })), y = s.map((e) => e.map(() => ({
1267
1618
  step: null,
1268
1619
  slot: 0
1269
- }))), v = Math.max(0, ...o.map((e) => e.length));
1270
- for (let e = 0; e < v; e++) for (let [t, n] of o.entries()) {
1620
+ }))), b = Math.max(0, ...s.map((e) => e.length));
1621
+ for (let e = 0; e < b; e++) for (let [t, n] of s.entries()) {
1271
1622
  let r = n[e];
1272
- if (!r || !a(r)) continue;
1273
- let i = u(r.getAttribute("data-fragment-index"));
1274
- _[t][e] = {
1623
+ if (!r || !o(r)) continue;
1624
+ let i = d(r.getAttribute("data-fragment-index"));
1625
+ y[t][e] = {
1275
1626
  step: i,
1276
- slot: l[i]++
1627
+ slot: u[i]++
1277
1628
  };
1278
1629
  }
1279
1630
  return {
1280
- rows: m,
1281
- series: g,
1282
- cells: _,
1283
- notes: i.map((e) => {
1631
+ rows: g,
1632
+ series: v,
1633
+ cells: y,
1634
+ notes: a.map((e) => {
1284
1635
  let t = (t, n) => {
1285
1636
  let r = Number.parseInt(e.getAttribute(t) ?? "", 10);
1286
1637
  return Number.isFinite(r) ? r - 1 : n;
1287
- }, [n, r] = e.getAttribute("data-annotation") === "bracket" ? [t("data-from", 0), t("data-to", m.length - 1)] : [0, m.length - 1], i = null;
1288
- for (let e = Math.min(n, r); e <= Math.max(n, r); e++) for (let t of [m[e]?.step ?? null, ...(_[e] ?? []).map((e) => e.step)]) t !== null && (i === null || t > i) && (i = t);
1289
- let o = g[t("data-series", 0)]?.step ?? null;
1290
- o !== null && (i === null || o > i) && (i = o), a(e) && (i = u(e.getAttribute("data-fragment-index")));
1291
- let s = i === null ? m.length : m.filter((e) => e.step === i).length;
1638
+ }, [n, r] = e.getAttribute("data-annotation") === "bracket" ? [t("data-from", 0), t("data-to", g.length - 1)] : [0, g.length - 1], i = null;
1639
+ for (let e = Math.min(n, r); e <= Math.max(n, r); e++) for (let t of [g[e]?.step ?? null, ...(y[e] ?? []).map((e) => e.step)]) t !== null && (i === null || t > i) && (i = t);
1640
+ let a = v[t("data-series", 0)]?.step ?? null;
1641
+ a !== null && (i === null || a > i) && (i = a), o(e) && (i = d(e.getAttribute("data-fragment-index")));
1642
+ let s = i === null ? g.length : g.filter((e) => e.step === i).length;
1292
1643
  return {
1293
1644
  step: i,
1294
1645
  after: s
1295
1646
  };
1296
1647
  }),
1297
- count: s.length,
1298
- indexes: s
1648
+ count: c.length,
1649
+ indexes: c
1299
1650
  };
1300
- }, rt = (e) => {
1651
+ }, Ct = (e) => {
1301
1652
  let t = e.plan;
1302
1653
  if (!t) return;
1303
1654
  let n = (t) => t === null || e.step - t >= 1;
@@ -1308,68 +1659,68 @@ var Fe = (e) => e.map((e) => ({
1308
1659
  let u = r.hasAttribute("data-flat") ? (l - e + 1) / (i - e + 1) : i > e ? Math.max(0, l - e) / (i - e) : 0;
1309
1660
  r.style.setProperty("--reveal", String(u));
1310
1661
  }
1311
- }, it = (e) => {
1662
+ }, wt = (e) => {
1312
1663
  let t = e.plan;
1313
1664
  if (!t) return;
1314
1665
  let n = t.rows.length - 1, i = (e) => t.series.map((n, r) => t.cells[e]?.[r]?.step ?? n.step ?? t.rows[e]?.step ?? null), a = (e) => {
1315
1666
  let t = i(e);
1316
1667
  return t.some((e) => e === null) ? null : Math.min(...t);
1317
- }, o = new Set(e.totals), s = (e, t, n, r) => {
1318
- e.style.setProperty(n, String(r)), e.style.removeProperty("--d"), t === null ? e.style.removeProperty("--step") : e.style.setProperty("--step", String(t));
1668
+ }, o = new Set(e.totals), s = !!e.type.axes, c = (e, t, n, r) => {
1669
+ s && n === "--i" || e.style.setProperty(n, String(r)), e.style.removeProperty("--d"), t === null ? e.style.removeProperty("--step") : e.style.setProperty("--step", String(t));
1319
1670
  };
1320
1671
  for (let r of e.figure.querySelectorAll("[data-row], [data-series], [data-note]")) {
1321
1672
  if (r.closest("table, .tablechart-controls") || r.hasAttribute("data-from")) continue;
1322
1673
  let e = Number(r.dataset.note);
1323
1674
  if (e > 0) {
1324
1675
  let n = t.notes[e - 1];
1325
- n && s(r, n.step, "--after", n.after);
1676
+ n && c(r, n.step, "--after", n.after);
1326
1677
  continue;
1327
1678
  }
1328
- let c = r.dataset.row ? Number(r.dataset.row) - 1 : n;
1679
+ let s = r.dataset.row ? Number(r.dataset.row) - 1 : n;
1329
1680
  if (r.classList.contains("tablechart-connector")) {
1330
- let e = t.rows[c - 1], n = t.rows[c];
1681
+ let e = t.rows[s - 1], n = t.rows[s];
1331
1682
  if (e && n) {
1332
1683
  let t = (e.step ?? -1) > (n.step ?? -1);
1333
- s(r, t ? e.step : n.step, "--i", t ? e.slot + 1 : n.slot);
1684
+ c(r, t ? e.step : n.step, "--i", t ? e.slot + 1 : n.slot);
1334
1685
  }
1335
1686
  continue;
1336
1687
  }
1337
1688
  if (o.has(r)) {
1338
- let e = i(c).filter((e) => e !== null);
1339
- s(r, e.length ? Math.max(...e) : null, "--i", t.rows[c]?.slot ?? 0);
1689
+ let e = i(s).filter((e) => e !== null);
1690
+ c(r, e.length ? Math.max(...e) : null, "--i", t.rows[s]?.slot ?? 0);
1340
1691
  continue;
1341
1692
  }
1342
1693
  if (r.hasAttribute("data-stack")) {
1343
- s(r, a(c), "--i", t.rows[c]?.slot ?? 0);
1694
+ c(r, a(s), "--i", t.rows[s]?.slot ?? 0);
1344
1695
  continue;
1345
1696
  }
1346
1697
  let l = r.dataset.series ? Number(r.dataset.series) - 1 : 0, u = r.dataset.series ? t.series[l] : void 0;
1347
1698
  if (r.classList.contains("tablechart-piece")) {
1348
- let e = i(c)[l] ?? null, n = t.cells[c]?.[l];
1349
- s(r, e === a(c) ? null : e, "--i", n && n.step !== null ? n.slot : c);
1699
+ let e = i(s)[l] ?? null, n = t.cells[s]?.[l];
1700
+ c(r, e === a(s) ? null : e, "--i", n && n.step !== null ? n.slot : s);
1350
1701
  continue;
1351
1702
  }
1352
1703
  if (r.dataset.place === "legend") {
1353
1704
  let e = Math.min(...t.cells.map((e) => e[l]?.step ?? Infinity));
1354
- s(r, u?.step ?? (Number.isFinite(e) ? e : null), "--i", 0);
1705
+ c(r, u?.step ?? (Number.isFinite(e) ? e : null), "--i", 0);
1355
1706
  continue;
1356
1707
  }
1357
- let d = t.cells[c]?.[l];
1358
- d && d.step !== null ? s(r, d.step, "--i", d.slot) : u && u.step !== null ? s(r, u.step, "--i", c) : t.rows[c] && s(r, t.rows[c].step, "--i", t.rows[c].slot);
1708
+ let d = t.cells[s]?.[l];
1709
+ d && d.step !== null ? c(r, d.step, "--i", d.slot) : u && u.step !== null ? c(r, u.step, "--i", s) : t.rows[s] && c(r, t.rows[s].step, "--i", t.rows[s].slot);
1359
1710
  }
1360
- let l = e.figure.querySelector(`.${p}`);
1361
- if (l) {
1711
+ let u = e.figure.querySelector(`.${g}`);
1712
+ if (u) {
1362
1713
  let e = [...t.rows, ...t.cells.flat()].map((e) => e.step ?? -1), n = Math.max(-1, ...e);
1363
- n < 0 ? s(l, null, "--i", 0) : s(l, n, "--i", e.filter((e) => e === n).length);
1714
+ n < 0 ? c(u, null, "--i", 0) : c(u, n, "--i", e.filter((e) => e === n).length);
1364
1715
  }
1365
- let u = [...t.rows, ...t.cells.flat()].map((e) => e.slot + 1), d = t.series.some((e) => e.step !== null) ? t.rows.length : 1;
1366
- e.plot.style.setProperty("--count", String(Math.max(d, ...u)));
1367
- let f = e.figure.querySelectorAll(`.${r}`), m = f[f.length - 1];
1368
- if (e.figure.dataset.chart === "waterfall" && m?.dataset.kind === "total" && f.length > 1) {
1716
+ let d = [...t.rows, ...t.cells.flat()].map((e) => e.slot + 1), f = t.series.some((e) => e.step !== null) ? t.rows.length : 1;
1717
+ s || e.plot.style.setProperty("--count", String(Math.max(f, ...d)));
1718
+ let p = e.figure.querySelectorAll(`.${r}`), m = p[p.length - 1];
1719
+ if (e.figure.dataset.chart === "waterfall" && m?.dataset.kind === "total" && p.length > 1) {
1369
1720
  let e = Number(m.dataset.row) - 1;
1370
1721
  (t.rows[e - 1]?.step ?? -1) > (t.rows[e]?.step ?? -1) && (m.dataset.grow = m.dataset.grow === "down" ? "up" : "down");
1371
1722
  }
1372
- let h = Array.from(e.figure.querySelectorAll(`.${c}`));
1723
+ let h = Array.from(e.figure.querySelectorAll(`.${l}`));
1373
1724
  if (h.length) {
1374
1725
  let t = (e) => e.style.getPropertyValue("--step") || "none", n = (e) => Number(e.style.getPropertyValue("--share") || 0), r = h.length, i = Math.max(0, h.findIndex((e, n) => t(e) !== t(h[(n - 1 + r) % r]))), a = [];
1375
1726
  for (let e = 0; e < r; e++) {
@@ -1379,19 +1730,19 @@ var Fe = (e) => e.map((e) => ({
1379
1730
  let o = /* @__PURE__ */ new Map();
1380
1731
  for (let e of a) {
1381
1732
  let t = e.reduce((e, t) => e + n(t), 0), r = 0;
1382
- for (let i of e) o.set(i.dataset.row ?? "", E(r, n(i), t)), r += n(i);
1733
+ for (let i of e) o.set(i.dataset.row ?? "", A(r, n(i), t)), r += n(i);
1383
1734
  }
1384
1735
  for (let t of e.figure.querySelectorAll("[data-row]")) {
1385
1736
  let e = o.get(t.dataset.row ?? "");
1386
1737
  e && t.style.getPropertyValue("--start") && (t.style.setProperty("--start", e.start.toFixed(4)), t.style.setProperty("--span", e.span.toFixed(4)), t.classList.contains("tablechart-slice") && t.style.setProperty("--ease", e.easing));
1387
1738
  }
1388
1739
  }
1389
- rt(e);
1390
- }, at = (e, t, n = !1) => {
1740
+ Ct(e);
1741
+ }, Tt = (e, t, n = !1) => {
1391
1742
  let r = e.plan;
1392
1743
  if (!r) return;
1393
1744
  let i = Math.min(Math.max(Math.round(t), 0), r.count), a = i !== e.step;
1394
- e.step = i, e.figure.style.setProperty("--_step", String(i)), rt(e);
1745
+ e.step = i, e.figure.style.setProperty("--_step", String(i)), Ct(e);
1395
1746
  let [o, s] = e.controls?.querySelectorAll("button") ?? [];
1396
1747
  o && (o.disabled = i === 0), s && (s.disabled = i === r.count), a && !n && e.figure.dispatchEvent(new CustomEvent("tablechart:step", {
1397
1748
  bubbles: !0,
@@ -1400,7 +1751,7 @@ var Fe = (e) => e.map((e) => ({
1400
1751
  steps: r.count
1401
1752
  }
1402
1753
  }));
1403
- }, ot = (e, t, n) => {
1754
+ }, Et = (e, t, n) => {
1404
1755
  let r = document.createElement("div");
1405
1756
  r.className = "tablechart-controls";
1406
1757
  let i = (r) => {
@@ -1408,17 +1759,17 @@ var Fe = (e) => e.map((e) => ({
1408
1759
  i.type = "button", i.className = `tablechart-${r}`, i.dataset.go = r;
1409
1760
  let a = document.createElement("span");
1410
1761
  a.className = "tablechart-control-icon", a.setAttribute("aria-hidden", "true");
1411
- let o = A("svg", {
1762
+ let o = P("svg", {
1412
1763
  viewBox: "0 0 16 16",
1413
1764
  focusable: "false"
1414
1765
  });
1415
- o.appendChild(A("path", { d: r === "next" ? "M6 3l5 5-5 5" : "M10 3L5 8l5 5" })), a.appendChild(o);
1766
+ o.appendChild(P("path", { d: r === "next" ? "M6 3l5 5-5 5" : "M10 3L5 8l5 5" })), a.appendChild(o);
1416
1767
  let s = document.createElement("span");
1417
1768
  s.className = "tablechart-control-label", s.textContent = e[r];
1418
1769
  let c = t[r];
1419
1770
  c && n && s.setAttribute(n, c);
1420
1771
  let l = document.createElement("span");
1421
- return l.className = g, l.textContent = e.hint, t.hint && n && l.setAttribute(n, t.hint), i.append(...r === "next" ? [
1772
+ return l.className = y, l.textContent = e.hint, t.hint && n && l.setAttribute(n, t.hint), i.append(...r === "next" ? [
1422
1773
  s,
1423
1774
  l,
1424
1775
  a
@@ -1429,14 +1780,14 @@ var Fe = (e) => e.map((e) => ({
1429
1780
  ]), i;
1430
1781
  };
1431
1782
  return r.append(i("previous"), i("next")), r;
1432
- }, st = (e, t, n, r = {
1783
+ }, Dt = (e, t, n, r = {
1433
1784
  x: 0,
1434
1785
  y: 0,
1435
1786
  scale: 1
1436
1787
  }, i = 2, a = 8, o = 12) => {
1437
1788
  let s = e.getBoundingClientRect(), c = s.width, l = s.height, u = Number.parseFloat(getComputedStyle(e).borderLeftWidth) || 0, d = t.getBoundingClientRect().height / 2 + (i - u) * r.scale, f = o * r.scale, { clientWidth: p, clientHeight: m } = document.documentElement, h = n.top - a, g = m - n.bottom - a, _ = l + d <= h ? !0 : l + d <= g ? !1 : h >= g, v = _ ? n.top - d - l : n.bottom + d, y = n.left + n.width / 2, b = Math.max(a, Math.min(y - c / 2, p - c - a));
1438
1789
  e.style.left = `${(b - r.x) / r.scale}px`, e.style.top = `${(Math.max(a, Math.min(v, m - l - a)) - r.y) / r.scale}px`, e.dataset.side = _ ? "top" : "bottom", t.style.left = `${Math.max(f, Math.min(y - b, c - f)) / r.scale - u}px`;
1439
- }, ct = "tablechart-tooltip", lt = [
1790
+ }, Ot = "tablechart-tooltip", kt = [
1440
1791
  "--tablechart-surface",
1441
1792
  "--tablechart-tooltip-surface",
1442
1793
  "--tablechart-tooltip-color",
@@ -1444,51 +1795,51 @@ var Fe = (e) => e.map((e) => ({
1444
1795
  "--tablechart-tooltip-radius",
1445
1796
  "--tablechart-tooltip-padding",
1446
1797
  "--tablechart-tooltip-shadow"
1447
- ], Q = null, ut, dt, $ = null, ft = null, pt = 0, mt = () => {
1448
- clearTimeout(pt), Q && $ && (Q.hidden = !0, $ = null, ft = null);
1449
- }, ht = !1, gt = !0, _t = NaN, vt = NaN, yt = !1, bt = () => {
1450
- if (yt) return;
1451
- yt = !0, document.addEventListener("pointermove", (e) => {
1452
- e.pointerType === "mouse" && (gt = e.screenX !== _t || e.screenY !== vt, _t = e.screenX, vt = e.screenY, gt && (ht = !1));
1798
+ ], $ = null, At, jt, Mt = null, Nt = null, Pt = 0, Ft = () => {
1799
+ clearTimeout(Pt), $ && Mt && ($.hidden = !0, Mt = null, Nt = null);
1800
+ }, It = !1, Lt = !0, Rt = NaN, zt = NaN, Bt = !1, Vt = () => {
1801
+ if (Bt) return;
1802
+ Bt = !0, document.addEventListener("pointermove", (e) => {
1803
+ e.pointerType === "mouse" && (Lt = e.screenX !== Rt || e.screenY !== zt, Rt = e.screenX, zt = e.screenY, Lt && (It = !1));
1453
1804
  }, {
1454
1805
  capture: !0,
1455
1806
  passive: !0
1456
1807
  });
1457
1808
  let e = () => {
1458
- ht = !0, mt();
1809
+ It = !0, Ft();
1459
1810
  };
1460
1811
  document.addEventListener("keydown", e, !0), window.addEventListener("scroll", e, {
1461
1812
  capture: !0,
1462
1813
  passive: !0
1463
1814
  });
1464
- }, xt = (e, t) => t / Number.parseFloat(getComputedStyle(e).width) || 1, St = (e) => {
1815
+ }, Ht = (e, t) => t / Number.parseFloat(getComputedStyle(e).width) || 1, Ut = (e) => {
1465
1816
  let t = e.tooltipparent;
1466
1817
  return (typeof t == "string" ? document.querySelector(t) : t) ?? document.body;
1467
- }, Ct = () => {
1468
- clearTimeout(pt), pt = window.setTimeout(mt, 120);
1469
- }, wt = () => {
1818
+ }, Wt = () => {
1819
+ clearTimeout(Pt), Pt = window.setTimeout(Ft, 120);
1820
+ }, Gt = () => {
1470
1821
  let e = document.createElement("div");
1471
- return e.className = ct, e.setAttribute("aria-hidden", "true"), e.hidden = !0, ut = document.createElement("div"), dt = document.createElement("div"), dt.className = `${ct}-arrow`, e.append(ut, dt), document.body.append(e), e.addEventListener("pointerenter", () => clearTimeout(pt)), e.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && Ct()), document.addEventListener("pointerdown", (t) => {
1822
+ return e.className = Ot, e.setAttribute("aria-hidden", "true"), e.hidden = !0, At = document.createElement("div"), jt = document.createElement("div"), jt.className = `${Ot}-arrow`, e.append(At, jt), document.body.append(e), e.addEventListener("pointerenter", () => clearTimeout(Pt)), e.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && Wt()), document.addEventListener("pointerdown", (t) => {
1472
1823
  let n = t.target;
1473
- $ && !$.plot.contains(n) && !e.contains(n) && mt();
1474
- }), window.addEventListener("resize", mt), e;
1475
- }, Tt = (e, t) => {
1824
+ Mt && !Mt.plot.contains(n) && !e.contains(n) && Ft();
1825
+ }), window.addEventListener("resize", Ft), e;
1826
+ }, Kt = (e, t) => {
1476
1827
  let n = t ? t.style.getPropertyValue("--step") : "x";
1477
1828
  return n === "" || Number(n) < e.step;
1478
- }, Et = (e, t) => {
1829
+ }, qt = (e, t) => {
1479
1830
  let n = e.svg.querySelector(`[data-series="${t + 1}"]:not(.tablechart-hole)`);
1480
1831
  if (!n) return;
1481
1832
  let r = getComputedStyle(n);
1482
1833
  return r.fill && r.fill !== "none" ? r.fill : r.stroke;
1483
- }, Dt = (e, t, n) => {
1834
+ }, Jt = (e, t, n) => {
1484
1835
  let r = e.series.length > 1, i = [];
1485
1836
  for (let [n, a] of e.seriesValues.entries()) {
1486
- if (!Tt(e, a[t])) continue;
1837
+ if (!Kt(e, a[t])) continue;
1487
1838
  let o = r ? e.figure.querySelector(`.tablechart-name[data-series="${n + 1}"]`) : null;
1488
1839
  i.push({
1489
1840
  name: r ? o?.textContent ?? e.series[n].name : "",
1490
1841
  value: a[t].textContent ?? "",
1491
- colour: r ? Et(e, n) : void 0,
1842
+ colour: r ? qt(e, n) : void 0,
1492
1843
  sample: o ? {
1493
1844
  marker: o.dataset.marker ?? null,
1494
1845
  open: o.hasAttribute("data-open"),
@@ -1498,65 +1849,73 @@ var Fe = (e) => e.map((e) => ({
1498
1849
  });
1499
1850
  }
1500
1851
  let a = e.totals[t];
1501
- return i.length > 1 && Tt(e, a) && i.push({
1852
+ return i.length > 1 && Kt(e, a) && i.push({
1502
1853
  name: n.totallabel,
1503
1854
  value: a.textContent ?? ""
1504
1855
  }), i;
1505
- }, Ot = (e, t) => {
1856
+ }, Yt = (e, t) => {
1506
1857
  if (e.type.centre && e.values[t]) return e.values[t].getBoundingClientRect();
1507
- let n = e.svg.querySelectorAll(`[data-row="${t + 1}"]:not(.tablechart-connector, .tablechart-leader)`), r = null;
1508
- for (let e of n) {
1858
+ let n = e.pointOf?.(t);
1859
+ if (n) {
1860
+ let t = e.svg.getBoundingClientRect(), r = t.width / D, i = 4 * r * (D / e.plot.clientWidth);
1861
+ return new DOMRect(t.left + n[0] * r - i, t.top + n[1] * r - i, 2 * i, 2 * i);
1862
+ }
1863
+ let r = e.svg.querySelectorAll(`[data-row="${t + 1}"]:not(.tablechart-connector, .tablechart-leader)`), i = null;
1864
+ for (let e of r) {
1509
1865
  let t = e.getBoundingClientRect();
1510
- (t.width || t.height) && (r = r ? new DOMRect(Math.min(r.left, t.left), Math.min(r.top, t.top), Math.max(r.right, t.right) - Math.min(r.left, t.left), Math.max(r.bottom, t.bottom) - Math.min(r.top, t.top)) : t);
1866
+ (t.width || t.height) && (i = i ? new DOMRect(Math.min(i.left, t.left), Math.min(i.top, t.top), Math.max(i.right, t.right) - Math.min(i.left, t.left), Math.max(i.bottom, t.bottom) - Math.min(i.top, t.top)) : t);
1511
1867
  }
1512
- if (r) return r;
1513
- let i = e.plot.getBoundingClientRect(), [a, o, s, c] = e.rowBox?.(t) ?? [
1868
+ if (i) return i;
1869
+ let a = e.plot.getBoundingClientRect(), [o, s, c, l] = e.rowBox?.(t) ?? [
1514
1870
  0,
1515
1871
  0,
1516
1872
  100,
1517
1873
  100
1518
1874
  ];
1519
- return new DOMRect(i.left + i.width * a / 100, i.top + i.height * o / 100, i.width * s / 100, i.height * c / 100);
1520
- }, kt = (e, t, n) => {
1521
- if (clearTimeout(pt), $ === e && ft === t) return;
1522
- let r = (e.type.tooltip ?? Dt)(e, t, n);
1523
- if (!r.length) return mt();
1524
- $ && $ !== e && mt(), Q ?? (Q = wt());
1875
+ return new DOMRect(a.left + a.width * o / 100, a.top + a.height * s / 100, a.width * c / 100, a.height * l / 100);
1876
+ }, Xt = (e, t, n) => {
1877
+ if (clearTimeout(Pt), Mt === e && Nt === t) return;
1878
+ let r = (e.type.tooltip ?? Jt)(e, t, n);
1879
+ if (!r.length) return Ft();
1880
+ Mt && Mt !== e && Ft(), $ ?? ($ = Gt());
1525
1881
  let i = (e, t, n, r = !1, i) => {
1526
1882
  let a = document.createElement("div");
1527
- if (a.className = `${ct}-line`, n) {
1883
+ if (a.className = `${Ot}-line`, n) {
1528
1884
  let e = document.createElement("span");
1529
- e.className = `${ct}-key`, e.style.background = n, i?.box ? e.dataset.sample = "box" : i && (e.dataset.sample = "line", i.marker && (e.dataset.marker = i.marker), i.line && (e.dataset.line = i.line), e.toggleAttribute("data-open", i.open)), a.append(e);
1885
+ e.className = `${Ot}-key`, e.style.background = n, i?.box ? e.dataset.sample = "box" : i && (e.dataset.sample = "line", i.marker && (e.dataset.marker = i.marker), i.line && (e.dataset.line = i.line), e.toggleAttribute("data-open", i.open)), a.append(e);
1530
1886
  }
1531
1887
  let o = document.createElement("span");
1532
- if (o.className = `${ct}-${r ? "title" : "name"}`, o.textContent = e, a.append(o), t) {
1888
+ if (o.className = `${Ot}-${r ? "title" : "name"}`, o.textContent = e, a.append(o), t) {
1533
1889
  e && o.append(":");
1534
1890
  let n = document.createElement("span");
1535
- n.className = `${ct}-value`, n.textContent = t, a.append(n);
1891
+ n.className = `${Ot}-value`, n.textContent = t, a.append(n);
1536
1892
  }
1537
1893
  return a;
1538
- }, a = e.categories[t]?.textContent ?? e.rows[t].label, o = r.length === 1 && !r[0].name, s = r.every((e) => e.name && !e.value);
1539
- ut.replaceChildren(...s ? [] : [i(a, o ? r[0].value : "", void 0, !0)], ...o ? [] : r.map(({ name: e, value: t, colour: n, sample: r }) => i(e, t, n, !1, r)));
1540
- let c = getComputedStyle(e.figure);
1541
- for (let e of lt) {
1542
- let t = c.getPropertyValue(e).trim();
1543
- t ? Q.style.setProperty(e, t) : Q.style.removeProperty(e);
1894
+ }, a = (e.figure.querySelectorAll("tbody tr")[t]?.querySelector("th"))?.textContent?.trim() || e.categories[t]?.textContent || e.rows[t].label, o = r.length === 1 && !r[0].name, s = r.every((e) => e.name && !e.value), c = ct(e.figure, t)?.textContent?.trim(), l = c ? [Object.assign(document.createElement("div"), {
1895
+ className: `${Ot}-note`,
1896
+ textContent: c
1897
+ })] : [];
1898
+ At.replaceChildren(...s ? [] : [i(a, o ? r[0].value : "", void 0, !0)], ...o ? [] : r.map(({ name: e, value: t, colour: n, sample: r }) => i(e, t, n, !1, r)), ...l);
1899
+ let u = getComputedStyle(e.figure);
1900
+ for (let e of kt) {
1901
+ let t = u.getPropertyValue(e).trim();
1902
+ t ? $.style.setProperty(e, t) : $.style.removeProperty(e);
1544
1903
  }
1545
- Q.style.setProperty("--_color", c.color), Q.style.colorScheme = c.colorScheme, Q.style.fontFamily = c.fontFamily;
1546
- let l = St(n);
1547
- Q.parentElement !== l && l.append(Q), $ = e, ft = t, Q.hidden = !1, Q.style.left = "0px", Q.style.top = "0px";
1548
- let u = Q.getBoundingClientRect(), d = {
1549
- x: u.left,
1550
- y: u.top,
1551
- scale: xt(Q, u.width)
1552
- }, f = xt(e.plot, e.plot.getBoundingClientRect().width);
1553
- Q.style.fontSize = `${Number.parseFloat(c.fontSize) * f / d.scale}px`, st(Q, dt, Ot(e, t), d);
1554
- }, At = (e, t, n = !1) => {
1904
+ $.style.setProperty("--_color", u.color), $.style.colorScheme = u.colorScheme, $.style.fontFamily = u.fontFamily;
1905
+ let d = Ut(n);
1906
+ $.parentElement !== d && d.append($), Mt = e, Nt = t, $.hidden = !1, $.style.left = "0px", $.style.top = "0px";
1907
+ let f = $.getBoundingClientRect(), p = {
1908
+ x: f.left,
1909
+ y: f.top,
1910
+ scale: Ht($, f.width)
1911
+ }, m = Ht(e.plot, e.plot.getBoundingClientRect().width);
1912
+ $.style.fontSize = `${Number.parseFloat(u.fontSize) * m / p.scale}px`, Dt($, jt, Yt(e, t), p);
1913
+ }, Zt = (e, t, n = !1) => {
1555
1914
  let { plot: r } = e;
1556
- r.setAttribute("data-hover", ""), bt();
1915
+ r.setAttribute("data-hover", ""), Vt();
1557
1916
  let i = (t) => {
1558
1917
  if (e.rowAt) {
1559
- let n = r.getBoundingClientRect(), i = xt(r, n.width);
1918
+ let n = r.getBoundingClientRect(), i = Ht(r, n.width);
1560
1919
  return e.rowAt((t.clientX - n.left) / i, (t.clientY - n.top) / i);
1561
1920
  }
1562
1921
  let n = t.target.closest?.("[data-row]")?.getAttribute("data-row");
@@ -1566,13 +1925,13 @@ var Fe = (e) => e.map((e) => ({
1566
1925
  else if (t.getAttribute("data-row") === String(e + 1)) return !0;
1567
1926
  return !1;
1568
1927
  }, s = null, c = (a) => {
1569
- if (a.type === "pointerdown") ht = !1;
1570
- else if (a.pointerType === "mouse" && (!gt || ht)) return;
1928
+ if (a.type === "pointerdown") It = !1;
1929
+ else if (a.pointerType === "mouse" && (!Lt || It)) return;
1571
1930
  if (!r.classList.contains("is-placed") || !e.figure.classList.contains("is-shown")) return;
1572
- if (n && !e.figure.hasAttribute("data-left-out")) return $ === e ? mt() : void 0;
1931
+ if (n && !e.figure.hasAttribute("data-left-out")) return Mt === e ? Ft() : void 0;
1573
1932
  let c = i(a);
1574
- if (s = c, c === null || o(c)) return $ === e ? mt() : void 0;
1575
- kt(e, c, t);
1933
+ if (s = c, c === null || o(c)) return Mt === e ? Ft() : void 0;
1934
+ Xt(e, c, t);
1576
1935
  }, l = (t) => {
1577
1936
  let n = t.target;
1578
1937
  return e.svg.contains(n) && n.hasAttribute("data-row") ? n : null;
@@ -1586,36 +1945,37 @@ var Fe = (e) => e.map((e) => ({
1586
1945
  if (!r) return;
1587
1946
  a.delete(r);
1588
1947
  let i = Number(r.getAttribute("data-row")) - 1;
1589
- s === i && !o(i) && !ht && kt(e, i, t);
1948
+ s === i && !o(i) && !It && Xt(e, i, t);
1590
1949
  };
1591
1950
  e.svg.addEventListener("transitionend", u), e.svg.addEventListener("transitioncancel", u), r.addEventListener("pointermove", c), r.addEventListener("pointerdown", c), r.addEventListener("pointerleave", (t) => {
1592
- t.pointerType === "mouse" && (s = null, $ === e && Ct());
1951
+ t.pointerType === "mouse" && (s = null, Mt === e && Wt());
1593
1952
  });
1594
- }, jt = (e) => {
1595
- $ === e && mt();
1596
- }, Mt = {
1597
- area: Re,
1598
- bar: Ce,
1599
- column: we,
1600
- donut: De,
1601
- line: Le,
1602
- waterfall: Ve
1603
- }, Nt = (e, t) => {
1604
- Mt[e] = t;
1605
- }, Pt = {
1606
- "axis-break": L,
1607
- trend: J,
1608
- bracket: re,
1609
- reference: ce
1610
- }, Ft = Object.keys(Pt), It = (e) => {
1953
+ }, Qt = (e) => {
1954
+ Mt === e && Ft();
1955
+ }, $t = {
1956
+ area: nt,
1957
+ bar: Le,
1958
+ column: Re,
1959
+ donut: Ve,
1960
+ line: tt,
1961
+ waterfall: at
1962
+ }, en = (e, t) => {
1963
+ $t[e] = t, Object.assign(tn, t.annotations), nn.splice(0, Infinity, ...Object.keys(tn));
1964
+ }, tn = {
1965
+ "axis-break": ne,
1966
+ trend: Oe,
1967
+ bracket: ce,
1968
+ reference: Ee,
1969
+ note: we
1970
+ }, nn = Object.keys(tn), rn = (e) => {
1611
1971
  let t = "";
1612
1972
  for (let n = e.previousSibling; n && (t = (n.textContent ?? "") + t, !t.trim()); n = n.previousSibling);
1613
1973
  return t.trim();
1614
- }, Lt = [
1974
+ }, an = [
1615
1975
  "straight",
1616
1976
  "step",
1617
1977
  "smooth"
1618
- ], Rt = (e, t, n, r, i) => {
1978
+ ], on = (e, t, n, r, i) => {
1619
1979
  let a = t === r, [o, s, c] = a ? [
1620
1980
  Math.min(e, n),
1621
1981
  Math.max(e, n),
@@ -1626,17 +1986,17 @@ var Fe = (e) => e.map((e) => ({
1626
1986
  e
1627
1987
  ], l = i.filter(([e, t, n, r]) => a ? t <= c && c <= t + r : e <= c && c <= e + n).map(([e, t, n, r]) => a ? [e, e + n] : [t, t + r]).sort((e, t) => e[0] - t[0]), u = [], d = o;
1628
1988
  for (let [e, t] of l) e > d && u.push([d, Math.min(e, s)]), d = Math.max(d, t);
1629
- return d < s && u.push([d, s]), u.map(([e, t]) => a ? `M${k(e)},${k(c)}H${k(t)}` : `M${k(c)},${k(e)}V${k(t)}`).join("");
1630
- }, zt = (e, t) => {
1989
+ return d < s && u.push([d, s]), u.map(([e, t]) => a ? `M${N(e)},${N(c)}H${N(t)}` : `M${N(c)},${N(e)}V${N(t)}`).join("");
1990
+ }, sn = (e, t) => {
1631
1991
  let [n, r, i, a] = [
1632
1992
  "x1",
1633
1993
  "y1",
1634
1994
  "x2",
1635
1995
  "y2"
1636
- ].map((t) => Number(e.getAttribute(t))), o = A("path", { d: Rt(n, r, i, a, t) });
1996
+ ].map((t) => Number(e.getAttribute(t))), o = P("path", { d: on(n, r, i, a, t) });
1637
1997
  for (let { name: t, value: n } of Array.from(e.attributes)) /^[xy][12]$/.test(t) || o.setAttribute(t, n);
1638
1998
  e.replaceWith(o);
1639
- }, Bt = (e) => Array.from((e.getAttribute("d") ?? "").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g), ([, e, t, n, r]) => n === "H" ? [
1999
+ }, cn = (e) => Array.from((e.getAttribute("d") ?? "").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g), ([, e, t, n, r]) => n === "H" ? [
1640
2000
  +e,
1641
2001
  +t,
1642
2002
  +r,
@@ -1646,19 +2006,19 @@ var Fe = (e) => e.map((e) => ({
1646
2006
  +t,
1647
2007
  +e,
1648
2008
  +r
1649
- ]), Vt = (e, [t, n, r, i]) => e.map(([e, a, o, s]) => a === s ? n <= a && a <= n + i && Math.max(e, t) < Math.min(o, t + r) ? `M${k(Math.max(e, t))},${k(a)}H${k(Math.min(o, t + r))}` : "" : t <= e && e <= t + r && Math.max(a, n) < Math.min(s, n + i) ? `M${k(e)},${k(Math.max(a, n))}V${k(Math.min(s, n + i))}` : "").join(""), Ht = (e, t, n) => {
2009
+ ]), ln = (e, [t, n, r, i]) => e.map(([e, a, o, s]) => a === s ? n <= a && a <= n + i && Math.max(e, t) < Math.min(o, t + r) ? `M${N(Math.max(e, t))},${N(a)}H${N(Math.min(o, t + r))}` : "" : t <= e && e <= t + r && Math.max(a, n) < Math.min(s, n + i) ? `M${N(e)},${N(Math.max(a, n))}V${N(Math.min(s, n + i))}` : "").join(""), un = (e, t, n) => {
1650
2010
  let r = e.getAttribute(t);
1651
2011
  return r === null ? n : r !== "false";
1652
- }, Ut = (e, t) => !!t.animate && e.getAttribute("data-chart-animate") !== "false", Wt = (e, t) => {
2012
+ }, dn = (e, t) => !!t.animate && e.getAttribute("data-chart-animate") !== "false", fn = (e, t) => {
1653
2013
  let n = e.dataset.chartShape;
1654
- return n && Lt.includes(n) ? n : Lt.includes(t.shape) ? t.shape : "straight";
1655
- }, Gt = (e) => {
2014
+ return n && an.includes(n) ? n : an.includes(t.shape) ? t.shape : "straight";
2015
+ }, pn = (e) => {
1656
2016
  for (let t of e.querySelectorAll("br")) {
1657
- if (t.previousElementSibling?.classList.contains("tablechart-sr") || /[.!?:;,…]$/.test(It(t))) continue;
2017
+ if (t.previousElementSibling?.classList.contains("tablechart-sr") || /[.!?:;,…]$/.test(rn(t))) continue;
1658
2018
  let e = document.createElement("span");
1659
- e.className = g, e.textContent = ". ", t.before(e);
2019
+ e.className = y, e.textContent = ". ", t.before(e);
1660
2020
  }
1661
- }, Kt = (e, t, n) => {
2021
+ }, mn = (e, t, n) => {
1662
2022
  let r = e.querySelector("table");
1663
2023
  if (!r) return null;
1664
2024
  let i = r.querySelector("tfoot [data-chart-total]");
@@ -1669,240 +2029,306 @@ var Fe = (e) => e.map((e) => ({
1669
2029
  s && n.langattribute && o.setAttribute(n.langattribute, `${s}-total`);
1670
2030
  let c = a.insertCell();
1671
2031
  return c.setAttribute("data-chart-total", ""), c.dataset.value = t.dataset.value ?? "0", a.prepend(o), c;
1672
- }, qt = 0, Jt = (e) => {
2032
+ }, hn = 0, gn = (e) => {
1673
2033
  let t = e.querySelector(":scope > figcaption");
1674
2034
  if (!t) return;
1675
- Gt(t);
2035
+ pn(t);
1676
2036
  let n = (e) => e.hasAttribute("aria-label") || e.hasAttribute("aria-labelledby"), r = (e) => {
1677
- t.id || (t.id = `tablechart-caption-${++qt}`), e.setAttribute("aria-labelledby", t.id);
2037
+ t.id || (t.id = `tablechart-caption-${++hn}`), e.setAttribute("aria-labelledby", t.id);
1678
2038
  };
1679
2039
  e.tagName === "FIGURE" && !n(e) && r(e);
1680
2040
  let i = e.querySelector("table");
1681
2041
  i && !n(i) && !i.querySelector(":scope > caption") && r(i);
1682
- }, Yt = (r, i, a = null) => {
1683
- let o = a ?? (r.getAttribute("data-chart") || "column"), s = Mt[o];
1684
- if (!s) return console.warn(`[${e}] Unknown chart type "${o}". Known types: ${Object.keys(Mt).join(", ")}.`), r.setAttribute("data-chart-empty", ""), null;
1685
- let c = Ue(r, i.langattribute);
2042
+ }, _n = (r, i, a = null) => {
2043
+ let o = a ?? (r.getAttribute("data-chart") || "column"), s = $t[o];
2044
+ if (!s) return console.warn(`[${e}] Unknown chart type "${o}". Known types: ${Object.keys($t).join(", ")}.`), r.setAttribute("data-chart-empty", ""), null;
2045
+ let c = lt(r, i.langattribute);
1686
2046
  if (!c.length) return console.warn(r.querySelector("table") ? `[${e}] A chart has no rows in its table, so there is nothing to draw.` : `[${e}] A chart has no table, so there is nothing to draw.`, r), r.setAttribute("data-chart-empty", ""), null;
1687
- Jt(r);
1688
- let d = Ke(r, c, i.langattribute);
1689
- d.length > 1 && !s.series && !s.columns && (console.warn(`[${e}] A ${o} chart uses only the first of its ${d.length} value columns.`), d = d.slice(0, 1));
1690
- let f = d.length > 1;
1691
- f && r.style.setProperty("--_series-count", String(d.length));
2047
+ gn(r);
2048
+ let l = ft(r, c, i.langattribute);
2049
+ if (l.length > 1 && !s.series && !s.columns && (console.warn(`[${e}] A ${o} chart uses only the first of its ${l.length} value columns.`), l = l.slice(0, 1)), l.some((e) => e.chart)) {
2050
+ let t = s.lines ? l.every((e) => e.chart) ? "Every series has data-chart=\"line\", so the chart is a line chart: set data-chart=\"line\" on the figure." : null : `A ${o} chart cannot draw a series as a line.`;
2051
+ t && (console.warn(`[${e}] ${t}`), l = l.map((e) => ({
2052
+ ...e,
2053
+ chart: null
2054
+ })));
2055
+ }
2056
+ let u = l.some((e) => e.chart), d = l.length > 1;
2057
+ d && r.style.setProperty("--_series-count", String(l.length));
1692
2058
  let m = r.hasAttribute("data-chart-stack");
1693
- m && !s.stackable && console.warn(`[${e}] A ${o} chart cannot be stacked.`);
1694
- let h = m && !!s.stackable && f, g = document.createElement("div");
1695
- g.className = t, g.setAttribute("aria-hidden", "true");
1696
- let _ = A("svg", {
2059
+ m && !s.stackable && console.warn(`[${e}] A ${o} chart cannot be stacked.`), m && u && console.warn(`[${e}] A chart with a line cannot be stacked.`);
2060
+ let h = m && !!s.stackable && d && !u, _ = document.createElement("div");
2061
+ _.className = t, _.setAttribute("aria-hidden", "true");
2062
+ let v = P("svg", {
1697
2063
  role: "presentation",
1698
2064
  focusable: "false"
1699
2065
  });
1700
- g.appendChild(_), r.appendChild(g);
1701
- let v = s.centre ? c.filter((e) => !e.isTotal) : c, y = Math.max(0, R(v.flatMap((e) => e.cells.slice(0, d.length).map((e) => z(e.number))))), S = d.map((e, t) => Math.max(0, R(c.map((e) => z(e.cells[t]?.number ?? ""))))), C = document.createElement("div");
1702
- C.className = "tablechart-values", g.appendChild(C);
1703
- let w = d.map((e, t) => c.map((e, r) => {
1704
- let i = e.cells[t] ?? e.cells[0], a = M(n, C);
1705
- return a.classList.add(...e.classes), a.dataset.value = String(i.value), i.prefix && (a.dataset.prefix = i.prefix), i.suffix && (a.dataset.suffix = i.suffix), i.missing && (a.dataset.missing = i.raw), f && (a.dataset.series = String(t + 1)), s.columns && (a.dataset.decimals = String(S[t])), a.dataset.row = String(r + 1), a.style.setProperty("--i", String(e.slot)), a;
1706
- })), T = w[0], E = h && s.totals ? c.map((e, t) => {
1707
- let r = M(n, C);
1708
- r.classList.add(...e.classes), r.dataset.kind = "total", r.dataset.row = String(t + 1), r.dataset.value = String(me(e, d.length));
2066
+ _.appendChild(v);
2067
+ let y = r.querySelector(":scope > table"), b = (e) => y ? y.before(e) : r.append(e);
2068
+ b(_);
2069
+ let x = s.centre ? c.filter((e) => !e.isTotal) : c, S = Math.max(0, W(x.flatMap((e) => e.cells.slice(0, l.length).map((e) => re(e.number))))), C = l.map((e, t) => Math.max(0, W(c.map((e) => re(e.cells[t]?.number ?? ""))))), E = document.createElement("div");
2070
+ E.className = "tablechart-values", _.appendChild(E);
2071
+ let D = l.map((e, t) => c.map((e, r) => {
2072
+ let i = e.cells[t] ?? e.cells[0], a = I(n, E);
2073
+ return a.classList.add(...e.classes), a.dataset.value = String(i.value), i.prefix && (a.dataset.prefix = i.prefix), i.suffix && (a.dataset.suffix = i.suffix), i.missing && (a.dataset.missing = i.raw), d && (a.dataset.series = String(t + 1)), s.columns && (a.dataset.decimals = String(C[t])), a.dataset.row = String(r + 1), a.style.setProperty("--i", String(e.slot)), s.numbers === !1 && (t || r) && (a.dataset.place = "none"), a;
2074
+ })), O = D[0], k = h && s.totals ? c.map((e, t) => {
2075
+ let r = I(n, E);
2076
+ r.classList.add(...e.classes), r.dataset.kind = "total", r.dataset.row = String(t + 1), r.dataset.value = String(Pe(e, l.length));
1709
2077
  let i = e.cells[0];
1710
2078
  return i.prefix && (r.dataset.prefix = i.prefix), i.suffix && (r.dataset.suffix = i.suffix), r.style.setProperty("--i", String(e.slot)), r;
1711
- }) : [], D = c[c.length - 1], O = d.some((e) => e.focus), k = r.getAttribute("data-chart-legend"), j = f && !s.columns && (k === null ? i.legend || s.legend !== void 0 : k !== "false") ? document.createElement("div") : null;
1712
- j && (j.className = u, j.setAttribute("aria-hidden", "true"), j.inert = !0);
1713
- let N = f && !s.columns ? d.map((e, t) => {
1714
- let n = M(l, j ?? g);
1715
- j && (n.dataset.place = "legend");
1716
- let a = s.legend ?? s.swatch;
1717
- if (a && (n.dataset.swatch = a), n.textContent = e.name, !a && Wt(r, i) !== "step") {
1718
- let e = ke(d, t);
1719
- n.dataset.marker = e.shape, n.toggleAttribute("data-open", e.open);
2079
+ }) : [], A = c[c.length - 1], j = l.some((e) => e.focus), M = r.getAttribute("data-chart-legend"), N = d && !s.columns && (M === null ? i.legend || s.legend !== void 0 : M !== "false") ? document.createElement("div") : null;
2080
+ N && (N.className = p, N.setAttribute("aria-hidden", "true"), N.inert = !0);
2081
+ let F = l.filter((e) => e.chart), L = d && !s.columns ? l.map((e, t) => {
2082
+ let n = I(f, N ?? _);
2083
+ N && (n.dataset.place = "legend");
2084
+ let a = e.chart ? void 0 : s.legend ?? s.swatch;
2085
+ if (a && (n.dataset.swatch = a), n.textContent = e.name, !a && fn(r, i) !== "step") {
2086
+ let r = e.chart ? X(F, F.indexOf(e)) : X(l, t);
2087
+ n.dataset.marker = r.shape, n.toggleAttribute("data-open", r.open);
1720
2088
  }
1721
- return e.line && !a && (n.dataset.line = e.line), e.key && i.langattribute && n.setAttribute(i.langattribute, e.key), n.dataset.series = String(t + 1), n.style.setProperty("--n", String(t)), n.style.setProperty("--palette", `var(--tablechart-color-${t + 1})`), n.style.setProperty("--m", O && !e.focus ? "1" : "0"), n.style.setProperty("--i", String(D.slot)), n;
1722
- }) : [], P = s.centre ? M(p, g) : null;
1723
- if (P) {
2089
+ return e.line && !a && (n.dataset.line = e.line), e.key && i.langattribute && n.setAttribute(i.langattribute, e.key), n.dataset.series = String(t + 1), n.style.setProperty("--n", String(t)), n.style.setProperty("--palette", `var(--tablechart-color-${t + 1})`), n.style.setProperty("--m", j && !e.focus ? "1" : "0"), n.style.setProperty("--i", String(A.slot)), n;
2090
+ }) : [], R = s.centre ? I(g, _) : null;
2091
+ if (R) {
1724
2092
  let e = c.find((e) => e.isTotal), t = e ? e.value : c.reduce((e, t) => e + Math.abs(t.value), 0);
1725
- P.dataset.value = String(t), e && (P.dataset.decimals = String(z(e.number)));
2093
+ R.dataset.value = String(t), e && (R.dataset.decimals = String(re(e.number)));
1726
2094
  }
1727
- let ee = P && !c.some((e) => e.isTotal) ? Kt(r, P, i) : null, F = s.categories === "beside", I = document.createElement("div");
1728
- I.className = "tablechart-categories", I.setAttribute("aria-hidden", "true"), I.inert = !0, F ? I.dataset.place = "beside" : s.centre && (I.dataset.place = "key"), I.style.setProperty("--_columns", String(c.length));
1729
- let L = 0;
2095
+ let z = R && !c.some((e) => e.isTotal) ? mn(r, R, i) : null, B = s.categories === "beside", V = document.createElement("div");
2096
+ V.className = "tablechart-categories", V.setAttribute("aria-hidden", "true"), V.inert = !0, B ? V.dataset.place = "beside" : s.centre && (V.dataset.place = "key"), V.style.setProperty("--_columns", String(c.length));
2097
+ let H = 0;
1730
2098
  for (let [e, t] of c.entries()) {
1731
2099
  let n = document.createElement("span");
1732
- n.classList.add(...t.classes), n.textContent = t.label, t.key && i.langattribute && n.setAttribute(i.langattribute, t.key), s.centre && (n.dataset.kind = t.isTotal ? "total" : "slice", t.isTotal || (n.dataset.slice = String(L + 1), n.style.setProperty("--n", String(L)), n.style.setProperty("--palette", `var(--tablechart-color-${L + 1})`), L += 1)), n.style.setProperty("--i", String(t.slot)), n.dataset.row = String(e + 1), I.appendChild(n);
2100
+ n.classList.add(...t.classes), n.textContent = t.short ?? t.label, t.key && i.langattribute && n.setAttribute(i.langattribute, t.short ? `${t.key}-short` : t.key), s.centre && (n.dataset.kind = t.isTotal ? "total" : "slice", t.isTotal || (n.dataset.slice = String(H + 1), n.style.setProperty("--n", String(H)), n.style.setProperty("--palette", `var(--tablechart-color-${H + 1})`), H += 1)), n.style.setProperty("--i", String(t.slot)), n.dataset.row = String(e + 1), V.appendChild(n);
1733
2101
  }
1734
- (F ? g : r).appendChild(I), j && r.appendChild(j);
1735
- let te = d.filter((e) => !e.group), B = !s.axes && !s.centre && Ht(r, "data-chart-axis", i.axis), V = s.axes ? {
1736
- titles: te.slice(0, 2).map((e, t) => {
1737
- let n = M(`${b}-title`, g);
2102
+ B ? _.appendChild(V) : b(V), N && b(N);
2103
+ let U = l.filter((e) => !e.group), ee = !s.axes && !s.centre && un(r, "data-chart-axis", i.axis), te = s.axes ? {
2104
+ titles: U.slice(0, 2).map((e, t) => {
2105
+ let n = I(`${w}-title`, _);
1738
2106
  return n.dataset.axis = t ? "y" : "x", n.textContent = e.name, e.key && i.langattribute && n.setAttribute(i.langattribute, e.key), n;
1739
2107
  }),
1740
- ticks: M(`${x}s`, g),
2108
+ ticks: I(`${T}s`, _),
1741
2109
  numbers: !0
1742
- } : B || !s.centre && Ht(r, "data-chart-grid", i.grid) ? {
2110
+ } : ee || !s.centre && un(r, "data-chart-grid", i.grid) ? {
1743
2111
  titles: [],
1744
- ticks: M(`${x}s`, g),
1745
- numbers: B
2112
+ ticks: I(`${T}s`, _),
2113
+ numbers: ee
1746
2114
  } : null;
1747
2115
  s.text?.({
1748
2116
  figure: r,
1749
- plot: g,
2117
+ plot: _,
1750
2118
  rows: c,
1751
- series: d,
2119
+ series: l,
1752
2120
  config: i
1753
2121
  });
1754
- let H = Ut(r, i) && !s.axes ? nt(r) : null;
1755
- s.axes && r.querySelector("[data-fragment]") && Z.log(`A ${o} chart has no steps, so it is shown whole.`, r), H && r.setAttribute("data-steps", "");
1756
- let U = r.getAttribute("data-chart-keys"), W = H && i.controls ? ot({
2122
+ let ne = dn(r, i) ? St(r, !!s.axes) : null;
2123
+ s.axes && r.querySelector("tbody [data-fragment], thead [data-fragment]") && Q.log(`A ${o} chart has one step, with data-fragment on the figure; its rows and columns have no steps of their own.`, r), ne && r.setAttribute("data-steps", "");
2124
+ let G = r.getAttribute("data-chart-keys"), ie = ne && i.controls ? Et({
1757
2125
  previous: i.previouslabel,
1758
2126
  next: i.nextlabel,
1759
2127
  hint: i.stephint
1760
2128
  }, {
1761
- previous: U && `${U}-previous`,
1762
- next: U && `${U}-next`,
1763
- hint: U && `${U}-step`
2129
+ previous: G && `${G}-previous`,
2130
+ next: G && `${G}-next`,
2131
+ hint: G && `${G}-step`
1764
2132
  }, i.langattribute) : null;
1765
- W && r.appendChild(W);
1766
- let ne = r.getAttribute("data-chart-table"), re = ne && Zt.includes(ne) ? ne : i.table;
1767
- if (re === "never") r.removeAttribute("data-table");
1768
- else {
1769
- r.setAttribute("data-table", re);
1770
- let e = r.querySelector(":scope > table");
1771
- e && r.append(e);
1772
- }
1773
- let ie = Array.from(r.querySelectorAll("[data-annotation]")).map((t) => {
1774
- let n = t.getAttribute("data-annotation"), r = Pt[n];
1775
- if (!r) return console.warn(`[${e}] Unknown annotation "${n}". Known annotations: ${Object.keys(Pt).join(", ")}.`), null;
1776
- let i = Number.parseInt(t.getAttribute("data-series") ?? "1", 10), a = i >= 1 && i <= d.length ? i - 1 : 0;
2133
+ ie && b(ie);
2134
+ let K = Array.from(r.querySelectorAll("[data-annotation]")).map((t) => {
2135
+ let n = t.getAttribute("data-annotation"), r = tn[n];
2136
+ if (!r) return console.warn(`[${e}] Unknown annotation "${n}". Known annotations: ${Object.keys(tn).join(", ")}.`), null;
2137
+ let i = Number.parseInt(t.getAttribute("data-series") ?? "1", 10), a = i >= 1 && i <= l.length ? i - 1 : 0;
1777
2138
  return i !== a + 1 && console.warn(`[${e}] An annotation reads line ${i}, which is not there; it reads line 1.`), {
1778
2139
  spec: t,
1779
2140
  type: r,
1780
- badge: r.create(t, g),
2141
+ badge: r.create(t, _),
1781
2142
  series: a,
1782
2143
  after: c.length
1783
2144
  };
1784
2145
  }).filter((e) => e !== null);
1785
- Ut(r, i) && r.setAttribute("data-animate", Qt(r, o, i, !!H));
1786
- let G = {
2146
+ if (!B && !s.centre && !s.axes) for (let [e, t] of c.entries()) {
2147
+ if (!t.note) continue;
2148
+ let n = document.createElement("span");
2149
+ n.dataset.annotation = "note", n.dataset.row = String(e + 1), n.textContent = t.note, t.noteKey && n.setAttribute("data-i18n", t.noteKey), K.push({
2150
+ spec: n,
2151
+ type: we,
2152
+ badge: we.create(n, _),
2153
+ series: 0,
2154
+ after: c.length
2155
+ });
2156
+ }
2157
+ dn(r, i) && r.setAttribute("data-animate", bn(r, o, i, !!ne));
2158
+ let q = {
1787
2159
  figure: r,
1788
- plot: g,
1789
- svg: _,
2160
+ plot: _,
2161
+ svg: v,
1790
2162
  rows: c,
1791
- decimals: y,
2163
+ decimals: S,
1792
2164
  type: s,
1793
- values: T,
1794
- series: d,
1795
- seriesValues: w,
1796
- names: j ? [] : N,
1797
- categories: Array.from(I.children),
1798
- centre: P,
1799
- axes: V,
2165
+ values: O,
2166
+ series: l,
2167
+ seriesValues: D,
2168
+ names: N ? [] : L,
2169
+ categories: Array.from(V.children),
2170
+ centre: R,
2171
+ axes: te,
1800
2172
  stacked: h,
1801
- totals: E,
1802
- totalCell: ee,
2173
+ totals: k,
2174
+ totalCell: z,
1803
2175
  rowAt: null,
1804
2176
  rowBox: null,
1805
- annotations: ie,
2177
+ pointOf: null,
2178
+ annotations: K,
1806
2179
  checks: [],
1807
- plan: H,
2180
+ plan: ne,
1808
2181
  step: 0,
1809
- controls: W
1810
- }, ae = () => cn(r, _);
1811
- _.addEventListener("transitionend", ae), _.addEventListener("transitioncancel", ae), W?.addEventListener("click", (e) => {
2182
+ controls: ie
2183
+ }, ae = () => Nn(r, v);
2184
+ v.addEventListener("transitionend", ae), v.addEventListener("transitioncancel", ae), ie?.addEventListener("click", (e) => {
1812
2185
  let t = e.target.closest("button")?.dataset.go;
1813
- t && at(G, G.step + (t === "next" ? 1 : -1));
1814
- }), at(G, 0, !0);
1815
- let K = r.getAttribute("data-chart-tooltip"), oe = K === "false" ? !1 : K === "auto" ? "auto" : K !== null || i.tooltip;
1816
- return oe && At(G, i, oe === "auto"), rn(G, i), G;
1817
- }, Xt = {
2186
+ t && Tt(q, q.step + (t === "next" ? 1 : -1));
2187
+ }), Tt(q, 0, !0);
2188
+ let oe = r.getAttribute("data-chart-tooltip"), se = oe === "false" ? !1 : oe === "auto" ? "auto" : oe !== null || i.tooltip;
2189
+ return se && Zt(q, i, se === "auto"), kn(q, i), q;
2190
+ }, vn = {
1818
2191
  grow: "grow",
1819
2192
  sweep: "sweep"
1820
- }, Zt = [
2193
+ }, yn = [
1821
2194
  "never",
1822
2195
  "auto",
1823
2196
  "print",
1824
2197
  "always"
1825
- ], Qt = (e, t, n, r) => {
1826
- let i = t === "line" || t === "area", a = Xt[e.getAttribute("data-chart-animate") ?? ""] ?? Xt[String(n.animate)];
2198
+ ], bn = (e, t, n, r) => {
2199
+ let i = t === "line" || t === "area", a = vn[e.getAttribute("data-chart-animate") ?? ""] ?? vn[String(n.animate)];
1827
2200
  return i ? r ? "sweep" : a ?? "sweep" : t === "donut" || t === "waterfall" ? a ?? "grow" : "grow";
1828
- }, $t = (e) => {
2201
+ }, xn = (e) => {
1829
2202
  let t = getComputedStyle(e).getPropertyValue("--tablechart-value-align").trim();
1830
2203
  return t === "start" || t === "center" || t === "end" ? t : null;
1831
- }, en = (e, t, n, r) => {
2204
+ }, Sn = (e, t, n, r) => {
1832
2205
  let i = getComputedStyle(e), a = (i.getPropertyValue(n).trim() || r).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);
1833
2206
  if (!a) return null;
1834
2207
  let o = Number(a[1]);
1835
- return a[2] === "%" ? o / 100 * C : o * (a[2] === "em" ? Number.parseFloat(i.fontSize) : a[2] === "rem" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 1) * t;
1836
- }, tn = (e, t) => en(e, t, "--tablechart-bar-max", "60px") ?? Infinity, nn = (t, n) => {
1837
- let { plot: r, svg: i, rows: a, type: s, values: c, series: l, seriesValues: u, names: d, annotations: p } = t, m = Number.parseFloat(t.figure.dataset.chartAspect ?? ""), g = m > 0 ? m : s.aspect ?? n.aspect, _ = s.categories === "beside", v = t.axes && !s.axes ? t.axes : null, y = _ ? null : t.categories[0]?.parentElement, w = null;
1838
- if (v) {
1839
- r.style.margin = "", y && (y.style.marginLeft = "");
2208
+ return a[2] === "%" ? o / 100 * D : o * (a[2] === "em" ? Number.parseFloat(i.fontSize) : a[2] === "rem" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 1) * t;
2209
+ }, Cn = (e, t) => Sn(e, t, "--tablechart-bar-max", "60px") ?? Infinity, wn = (e, t) => {
2210
+ let n = e.getBoundingClientRect(), r = D / n.width, i = getComputedStyle(e), a = Number.parseFloat(i.lineHeight) / Number.parseFloat(i.fontSize) || 1.2;
2211
+ return (e) => {
2212
+ if (e.dataset.place === "none" || e.hidden || e.hasAttribute("data-left-out")) return [];
2213
+ let i = e.getBoundingClientRect(), o = i.height * r / a, s = Array.from(e.style).filter((e) => e.startsWith("--")).map((t) => `${t}:${e.style.getPropertyValue(t)}`);
2214
+ return i.width ? [P("rect", {
2215
+ class: h,
2216
+ "data-for": "text",
2217
+ x: (i.left - n.left) * r - 3 * t,
2218
+ y: (i.top - n.top) * r + (i.height * r - o) / 2 - t,
2219
+ width: i.width * r + 6 * t,
2220
+ height: o + 2 * t,
2221
+ style: s.join("; ")
2222
+ })] : [];
2223
+ };
2224
+ }, Tn = [
2225
+ "first",
2226
+ "last",
2227
+ "highest",
2228
+ "lowest",
2229
+ "outliers"
2230
+ ], En = (t, n) => {
2231
+ let r = (t.getAttribute("data-chart-values") ?? n.values).trim().toLowerCase().split(/\s+/).filter(Boolean);
2232
+ for (let t of r) [
2233
+ "auto",
2234
+ "all",
2235
+ "none",
2236
+ ...Tn
2237
+ ].includes(t) || console.warn(`[${e}] data-chart-values knows no "${t}". It takes auto, all, none, ${Tn.join(", ")}.`);
2238
+ let i = r.filter((e) => Tn.includes(e));
2239
+ return r.includes("all") ? {
2240
+ mode: "all",
2241
+ keys: []
2242
+ } : r.includes("none") ? {
2243
+ mode: "set",
2244
+ keys: []
2245
+ } : r.includes("auto") || !i.length ? {
2246
+ mode: "auto",
2247
+ keys: i.length ? i : Tn
2248
+ } : {
2249
+ mode: "set",
2250
+ keys: i
2251
+ };
2252
+ }, Dn = ({ figure: e, rows: t, series: n }, r) => {
2253
+ let i = e.getAttribute("data-chart-table"), a = i && yn.includes(i) ? i : r.table;
2254
+ a === "never" ? e.removeAttribute("data-table") : e.setAttribute("data-table", a);
2255
+ let o = e.getAttribute("data-chart-summary");
2256
+ e.setAttribute("data-summary", o && yn.includes(o) ? o : r.summary), e.toggleAttribute("data-long", t.length * n.filter((e) => !e.group).length > r.tablelimit);
2257
+ }, On = (t, n) => {
2258
+ let { plot: r, svg: i, rows: l, type: m, values: g, series: _, seriesValues: y, names: b, annotations: x } = t;
2259
+ Dn(t, n);
2260
+ let S = Number.parseFloat(t.figure.dataset.chartAspect ?? ""), C = S > 0 ? S : m.aspect ?? n.aspect, O = m.categories === "beside", k = t.axes && !m.axes ? t.axes : null, A = O ? null : t.categories[0]?.parentElement, j = null;
2261
+ if (k) {
2262
+ r.style.margin = "", A && (A.style.marginLeft = "");
1840
2263
  let e = r.clientWidth;
1841
2264
  if (!e) return !1;
1842
- let i = s.segments?.(a) ?? [], o = t.stacked ? a.flatMap((e) => Object.values(pe(e, l.length, s.running))) : i.some((e) => e.kind === "up" || e.kind === "down") ? i.flatMap((e) => [e.from, e.to]) : a.flatMap((e) => e.cells.slice(0, l.length).filter((e) => !e.missing).map((e) => e.value)), c = Math.min(0, -R(o.map((e) => -e))), u = Math.max(0, R(o)), d = Number.parseFloat(getComputedStyle(r).fontSize) || 16, { chartScaleY: f, chartScale: p } = t.figure.dataset, m = Qe(f ?? p);
1843
- if (m && m.length > 2) w = {
1844
- min: m[0],
1845
- max: m[m.length - 1],
2265
+ let i = m.segments?.(l) ?? [], a = t.stacked ? l.flatMap((e) => Object.values(Ne(e, _.length, m.running))) : i.some((e) => e.kind === "up" || e.kind === "down") ? i.flatMap((e) => [e.from, e.to]) : l.flatMap((e) => e.cells.slice(0, _.length).filter((e) => !e.missing).map((e) => e.value)), o = Math.min(0, -W(a.map((e) => -e))), s = Math.max(0, W(a)), c = Number.parseFloat(getComputedStyle(r).fontSize) || 16, { chartScaleY: u, chartScale: d } = t.figure.dataset, f = vt(u ?? d);
2266
+ if (f && f.length > 2) j = {
2267
+ min: f[0],
2268
+ max: f[f.length - 1],
1846
2269
  step: 0,
1847
- ticks: m
2270
+ ticks: f
1848
2271
  };
1849
2272
  else {
1850
- let [t, n] = m ?? [c, u], r = Ye(n - t, Math.max((_ ? e / 9 : e * g / 3) / d, 2)), i = (e, t) => m ? e : Number(((t ? Math.ceil : Math.floor)(e / r - 1e-9 * (t ? 1 : -1)) * r).toPrecision(12)), a = i(t, !1), o = i(n, !0);
1851
- w = {
2273
+ let [t, n] = f ?? [o, s], r = ht(n - t, Math.max((O ? e / 9 : e * C / 3) / c, 2)), i = (e, t) => f ? e : Number(((t ? Math.ceil : Math.floor)(e / r - 1e-9 * (t ? 1 : -1)) * r).toPrecision(12)), a = i(t, !1), l = i(n, !0);
2274
+ j = {
1852
2275
  min: a,
1853
- max: o,
2276
+ max: l,
1854
2277
  step: r,
1855
- ticks: Xe(a, o, r)
2278
+ ticks: gt(a, l, r)
1856
2279
  };
1857
2280
  }
1858
- v.ticks.textContent = "";
1859
- let h = a.find((e) => !e.missing), b = R(w.ticks.map((e) => z(String(e))));
1860
- for (let e of w.ticks) {
1861
- let t = M(x, v.ticks);
1862
- t.dataset.value = String(e), t.dataset.place = "none", h?.prefix && (t.dataset.prefix = h.prefix), h?.suffix && (t.dataset.suffix = h.suffix), an(t, b, n.locale);
2281
+ k.ticks.textContent = "";
2282
+ let p = l.find((e) => !e.missing), h = W(j.ticks.map((e) => re(String(e))));
2283
+ for (let e of j.ticks) {
2284
+ let t = I(T, k.ticks);
2285
+ t.dataset.value = String(e), t.dataset.place = "none", p?.prefix && (t.dataset.prefix = p.prefix), p?.suffix && (t.dataset.suffix = p.suffix), An(t, h, n.locale);
1863
2286
  }
1864
- if (v.numbers) {
1865
- let e = Array.from(v.ticks.children);
2287
+ if (k.numbers) {
2288
+ let e = Array.from(k.ticks.children);
1866
2289
  for (let t of e) delete t.dataset.place;
1867
- oe(e), _ ? r.style.marginBottom = `${(e[0] ? q(e[0]).height : 0) + 6}px` : (r.style.marginLeft = `${R([0, ...e.map((e) => q(e).width)]) + 10}px`, y && (y.style.marginLeft = r.style.marginLeft));
2290
+ pe(e), O ? r.style.marginBottom = `${(e[0] ? J(e[0]).height : 0) + 6}px` : (r.style.marginLeft = `${W([0, ...e.map((e) => J(e).width)]) + 10}px`, A && (A.style.marginLeft = r.style.marginLeft));
1868
2291
  }
1869
2292
  }
1870
- let T = r.clientWidth;
1871
- if (!T) return !1;
1872
- let E = C / T, D = C * g;
1873
- r.classList.add(h);
1874
- for (let e of [...u.flat(), ...t.totals]) delete e.dataset.place;
1875
- r.style.removeProperty("--_fit"), t.categories[0]?.parentElement?.style.removeProperty("--_beside");
1876
- let O = s.axes ? t.axes : null, j = [];
1877
- if (O) {
1878
- let e = Number.parseFloat(getComputedStyle(r).fontSize) || 16, i = l.flatMap((e, t) => e.group ? [] : [t]).slice(0, 2), o = a.filter((e) => i.every((t) => e.cells[t] && !e.cells[t].missing)), { chartScaleX: s, chartScaleY: c, chartScale: u } = t.figure.dataset, d = [Qe(s), Qe(c ?? u)];
1879
- j = i.map((t, n) => $e(o.length ? o.map((e) => e.cells[t].value) : [0, 1], Math.max(n ? D / E / (e * 4) : T / (e * 9), 4), d[n])), O.ticks.textContent = "", j.forEach((e, t) => {
1880
- let r = o[0]?.cells[i[t]], a = R(e.ticks.map((e) => z(String(e))));
2293
+ let M = r.clientWidth;
2294
+ if (!M) return !1;
2295
+ let F = D / M, R = D * C;
2296
+ r.classList.add(v);
2297
+ let z = m.numbers === !1 ? g.slice(0, 1) : [...y.flat(), ...t.totals];
2298
+ for (let e of z) delete e.dataset.place, e.removeAttribute("data-left-out"), e.removeAttribute("data-cut");
2299
+ r.style.removeProperty("--_fit"), r.toggleAttribute("data-grouped", !!m.groups && !t.stacked && _.filter((e) => !e.chart && !e.group).length > 1), t.categories[0]?.parentElement?.style.removeProperty("--_beside");
2300
+ let B = m.axes ? t.axes : null, V = [];
2301
+ if (B) {
2302
+ let e = Number.parseFloat(getComputedStyle(r).fontSize) || 16, i = _.flatMap((e, t) => e.group ? [] : [t]).slice(0, 2), a = l.filter((e) => i.every((t) => e.cells[t] && !e.cells[t].missing)), { chartScaleX: o, chartScaleY: s, chartScale: c } = t.figure.dataset, u = [vt(o), vt(s ?? c)];
2303
+ V = i.map((t, n) => yt(a.length ? a.map((e) => e.cells[t].value) : [0, 1], Math.max(n ? R / F / (e * 4) : M / (e * 9), 4), u[n])), B.ticks.textContent = "", V.forEach((e, t) => {
2304
+ let r = a[0]?.cells[i[t]], o = W(e.ticks.map((e) => re(String(e))));
1881
2305
  for (let i of e.ticks) {
1882
- let e = M(x, O.ticks);
1883
- e.dataset.axis = t ? "y" : "x", e.dataset.value = String(i), r?.prefix && (e.dataset.prefix = r.prefix), r?.suffix && (e.dataset.suffix = r.suffix), an(e, a, n.locale);
2306
+ let e = I(T, B.ticks);
2307
+ e.dataset.axis = t ? "y" : "x", e.dataset.value = String(i), r?.prefix && (e.dataset.prefix = r.prefix), r?.suffix && (e.dataset.suffix = r.suffix), An(e, o, n.locale);
1884
2308
  }
1885
2309
  });
1886
2310
  }
1887
- let P = O ? Array.from(O.ticks.children) : [];
1888
- oe([
1889
- ...u.flat(),
2311
+ let ee = B ? Array.from(B.ticks.children) : [];
2312
+ pe([
2313
+ ...y.flat(),
1890
2314
  ...t.totals,
1891
- ...d,
2315
+ ...b,
1892
2316
  ...t.categories,
1893
- ...p.map((e) => e.badge),
1894
- ...O?.titles ?? [],
1895
- ...P
2317
+ ...x.map((e) => e.badge),
2318
+ ...B?.titles ?? [],
2319
+ ...ee
1896
2320
  ]);
1897
- let F = (c[0] ? q(c[0]).height : 0) * E, I = p[0]?.badge ? q(p[0].badge).height * E : 0, L = Math.max(D, en(t.figure, E, "--tablechart-min-height", "200px") ?? 0, s.minHeight?.({
1898
- labelHeight: F,
1899
- nameHeight: Math.max(0, R(t.categories.map((e) => q(e).height))) * E,
1900
- unit: E,
1901
- rows: a.length,
1902
- series: l.length,
2321
+ let te = (g[0] ? J(g[0]).height : 0) * F;
2322
+ m.numbers === !1 && g[0] && (g[0].dataset.place = "none");
2323
+ let ne = x[0]?.badge ? J(x[0].badge).height * F : 0, G = Math.max(R, Sn(t.figure, F, "--tablechart-min-height", "200px") ?? 0, m.minHeight?.({
2324
+ labelHeight: te,
2325
+ nameHeight: Math.max(0, W(t.categories.map((e) => J(e).height))) * F,
2326
+ unit: F,
2327
+ rows: l.length,
2328
+ series: _.length,
1903
2329
  stacked: t.stacked
1904
- }) ?? 0), te = t.stacked ? a.map((e) => {
1905
- let t = me(e, l.length);
2330
+ }) ?? 0), ie = t.stacked ? l.map((e) => {
2331
+ let t = Pe(e, _.length);
1906
2332
  return {
1907
2333
  ...e,
1908
2334
  value: t,
@@ -1911,185 +2337,246 @@ var Fe = (e) => e.map((e) => ({
1911
2337
  value: t
1912
2338
  } : e)
1913
2339
  };
1914
- }) : a, B = (s.segments ?? ((e) => e.map((e) => ({
2340
+ }) : l, K = (m.segments ?? ((e) => e.map((e) => ({
1915
2341
  ...e,
1916
2342
  from: 0,
1917
2343
  to: e.value,
1918
2344
  kind: "bar"
1919
- }))))(t.stacked ? te.map((e) => ({
2345
+ }))))(t.stacked ? ie.map((e) => ({
1920
2346
  ...e,
1921
2347
  cells: [e.cells[0]]
1922
- })) : a), V = {
1923
- labelHeight: F,
1924
- badgeHeight: I,
1925
- hasAnnotations: p.length > 0,
1926
- unit: E,
1927
- series: l.length,
1928
- focused: l.some((e) => e.focus),
2348
+ })) : l), q = {
2349
+ labelHeight: te,
2350
+ badgeHeight: ne,
2351
+ hasAnnotations: x.length > 0,
2352
+ unit: F,
2353
+ series: _.length,
2354
+ focused: _.some((e) => e.focus),
1929
2355
  stacked: t.stacked
1930
- }, H = Math.max(((e) => t.stacked ? e(a.map((e) => pe(e, l.length, s.running).top)) : e([...B.flatMap((e) => [
2356
+ }, ae = Math.max(((e) => t.stacked ? e(l.map((e) => Ne(e, _.length, m.running).top)) : e([...K.flatMap((e) => [
1931
2357
  e.from,
1932
2358
  e.to,
1933
2359
  e.value
1934
- ]), ...a.flatMap((e) => e.cells.slice(0, l.length).map((e) => e.value))]))(R), 0), U = B.some((e) => e.kind === "up" || e.kind === "down") ? B.flatMap((e) => [e.from, e.to]) : t.stacked ? a.map((e) => pe(e, l.length, s.running).bottom) : a.flatMap((e) => e.cells.slice(0, l.length).map((e) => e.value)), W = Math.min(-R(U.map((e) => -e)), 0), ne = s.headroom?.(V) ?? F, re = 2 * E + (s.footroom?.(V) ?? 0) + (W < 0 ? F + 4 * E : 0), ie = L - ne - re, G = w ? Math.max(w.max, H) : H * 1.02, ae = w ? Math.min(w.min, W) : W * 1.02, K = p.find((e) => e.spec.getAttribute("data-annotation") === "axis-break")?.spec, se = (e) => {
1935
- let t = Number.parseFloat(K?.getAttribute(e) ?? "");
2360
+ ]), ...l.flatMap((e) => e.cells.slice(0, _.length).map((e) => e.value))]))(W), 0), oe = K.some((e) => e.kind === "up" || e.kind === "down") ? K.flatMap((e) => [e.from, e.to]) : t.stacked ? l.map((e) => Ne(e, _.length, m.running).bottom) : l.flatMap((e) => e.cells.slice(0, _.length).map((e) => e.value)), se = Math.min(-W(oe.map((e) => -e)), 0), ce = _.flatMap((e, t) => e.chart ? [t] : []), le = l.some((e) => e.note) ? ne + 4 * F : 0, ue = Math.max(m.headroom?.(q) ?? te, ce.length ? tt.headroom?.(q) ?? 0 : 0) + le, de = 2 * F + (m.footroom?.(q) ?? 0) + (se < 0 ? te + 4 * F : 0), fe = G - ue - de, me = j ? Math.max(j.max, ae) : ae * 1.02, he = j ? Math.min(j.min, se) : se * 1.02, ge = x.find((e) => e.spec.getAttribute("data-annotation") === "axis-break")?.spec, _e = (e) => {
2361
+ let t = Number.parseFloat(ge?.getAttribute(e) ?? "");
1936
2362
  return Number.isFinite(t) ? t : null;
1937
- }, ce = se("data-from") ?? se("data-at"), le = se("data-to"), J = null;
1938
- if (K && (ce !== null || le !== null)) {
1939
- let t = ce ?? 0, n = le ?? G, r = le === null ? t : ce === null ? n : (t + n) / 2, i = K.getAttribute("data-size"), a = i?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);
2363
+ }, ye = _e("data-from") ?? _e("data-at"), be = _e("data-to"), Y = null;
2364
+ if (ge && (ye !== null || be !== null)) {
2365
+ let t = ye ?? 0, n = be ?? me, r = be === null ? t : ye === null ? n : (t + n) / 2, i = ge.getAttribute("data-size"), a = i?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);
1940
2366
  i !== null && !a && console.warn(`[${e}] data-size="${i}" is not a percentage, such as 30%. Using the default.`);
1941
- let o = Math.min(Math.max(a ? Number(a[1]) / 100 : le === null ? .22 : .3, .05), .8), c = B.filter((e) => (e.kind === "up" || e.kind === "down") && Math.max(e.from, e.to) > t && Math.min(e.from, e.to) < n);
1942
- s.breakable ? W < 0 ? console.warn(`[${e}] A chart with values below zero cannot break its scale.`) : t < 0 || n <= t || n > G || t === 0 && n === G ? console.warn(`[${e}] A break from ${t} to ${n} does not fit a scale that runs from 0 to ${H}.`) : c.length ? console.warn(`[${e}] A break from ${t} to ${n} would cut a step that floats. Keep it below or above the steps.`) : J = {
2367
+ let o = Math.min(Math.max(a ? Number(a[1]) / 100 : be === null ? .22 : .3, .05), .8), s = K.filter((e) => (e.kind === "up" || e.kind === "down") && Math.max(e.from, e.to) > t && Math.min(e.from, e.to) < n);
2368
+ m.breakable ? se < 0 ? console.warn(`[${e}] A chart with values below zero cannot break its scale.`) : t < 0 || n <= t || n > me || t === 0 && n === me ? console.warn(`[${e}] A break from ${t} to ${n} does not fit a scale that runs from 0 to ${ae}.`) : s.length ? console.warn(`[${e}] A break from ${t} to ${n} would cut a step that floats. Keep it below or above the steps.`) : Y = {
1943
2369
  lo: t,
1944
2370
  hi: n,
1945
2371
  gap: r,
1946
2372
  share: o
1947
2373
  } : console.warn(`[${e}] This kind of chart cannot break its scale.`);
1948
2374
  }
1949
- let ue = J ? J.gap : null, de = (J && en(t.figure, E, "--tablechart-break-gap", "")) ?? 13, Y = L - re, fe = G - ae || 1, he = (e) => Y - (e - ae) / fe * ie;
1950
- if (J) {
1951
- let { lo: e, hi: t, gap: n, share: r } = J, i = ie * r, a = (ie - i - de) / (e + (G - t)), o = i / (t - e);
1952
- he = (r) => r <= e ? Y - r * a : r <= n ? Y - e * a - (r - e) * o : r <= t ? Y - e * a - (r - e) * o - de : Y - e * a - i - de - (r - t) * a;
2375
+ let Ce = Y ? Y.gap : null, we = (Y && Sn(t.figure, F, "--tablechart-break-gap", "")) ?? 13, Te = G - de, Ee = me - he || 1, De = (e) => Te - (e - he) / Ee * fe;
2376
+ if (Y) {
2377
+ let { lo: e, hi: t, gap: n, share: r } = Y, i = fe * r, a = (fe - i - we) / (e + (me - t)), o = i / (t - e);
2378
+ De = (r) => r <= e ? Te - r * a : r <= n ? Te - e * a - (r - e) * o : r <= t ? Te - e * a - (r - e) * o - we : Te - e * a - i - we - (r - t) * a;
1953
2379
  }
1954
- let ge, _e, ve = [];
1955
- if (O) {
1956
- let e = 6 * E, [t, n] = O.titles, r = (e) => e ? q(e).width * E : 0, i = (e) => e ? q(e).height * E : 0, a = P.filter((e) => e.dataset.axis === "x"), o = P.filter((e) => e.dataset.axis === "y"), s = i(P[0]), c = r(n) + R([0, ...o.map(r)]) + 2 * e, l = s / 2;
1957
- _e = [
2380
+ let Oe, ke, Ae = [];
2381
+ if (B) {
2382
+ let e = 6 * F, [t, n] = B.titles, r = (e) => e ? J(e).width * F : 0, i = (e) => e ? J(e).height * F : 0, a = ee.filter((e) => e.dataset.axis === "x"), o = ee.filter((e) => e.dataset.axis === "y"), s = i(ee[0]), c = r(n) + W([0, ...o.map(r)]) + 2 * e, l = s / 2;
2383
+ ke = [
1958
2384
  c,
1959
2385
  l,
1960
- C - c - R([0, ...a.map(r)]) / 2,
1961
- L - l - i(t) - s - 2 * e
2386
+ D - c - W([0, ...a.map(r)]) / 2,
2387
+ G - l - i(t) - s - 2 * e
1962
2388
  ];
1963
- let [u, d, f, p] = _e, [m, h] = j, g = (e) => u + (e - m.min) / (m.max - m.min || 1) * f, _ = (e) => d + p - (e - h.min) / (h.max - h.min || 1) * p;
1964
- ge = g, he = _;
2389
+ let [u, d, f, p] = ke, [m, h] = V, g = (e) => u + (e - m.min) / (m.max - m.min || 1) * f, _ = (e) => d + p - (e - h.min) / (h.max - h.min || 1) * p;
2390
+ Oe = g, De = _;
1965
2391
  let v = (e) => r(a.find((t) => Number(t.dataset.value) === e));
1966
- ve = [et(m, (t) => t.every((n, r) => !r || g(n) - g(t[r - 1]) > (v(n) + v(t[r - 1])) / 2 + e)).ticks, et(h, (t) => t.every((n, r) => !r || _(t[r - 1]) - _(n) > s + e / 2)).ticks];
1967
- for (let t of P) {
1968
- let n = Number(t.dataset.value), r = t.dataset.axis === "x" ? 0 : 1, i = ve[r].includes(n);
1969
- t.dataset.place = i ? r ? "before" : "below" : "none", i && N(t, r ? u - e : g(n), r ? _(n) : d + p + e, C, L);
2392
+ Ae = [bt(m, (t) => t.every((n, r) => !r || g(n) - g(t[r - 1]) > (v(n) + v(t[r - 1])) / 2 + e)).ticks, bt(h, (t) => t.every((n, r) => !r || _(t[r - 1]) - _(n) > s + e / 2)).ticks];
2393
+ for (let t of ee) {
2394
+ let n = Number(t.dataset.value), r = t.dataset.axis === "x" ? 0 : 1, i = Ae[r].includes(n);
2395
+ t.dataset.place = i ? r ? "before" : "below" : "none", i && L(t, r ? u - e : g(n), r ? _(n) : d + p + e, D, G);
1970
2396
  }
1971
- t && N(t, u + f / 2, L - i(t), C, L), n && N(n, 0, d + p / 2, C, L);
2397
+ t && L(t, u + f / 2, G - i(t), D, G), n && L(n, 0, d + p / 2, D, G);
1972
2398
  }
1973
- let ye = d.length ? R(d.map((e) => q(e).width)) * E + 12 * E : 0, be = t.categories[0]?.parentElement;
1974
- be && (be.style.paddingRight = ye ? `${ye / C * 100}%` : "");
1975
- let Se = (C - ye) / a.length, Ce = (e) => (e + .5) * Se, we = (e) => e >= 0 && e < a.length ? e : null;
1976
- t.rowAt = s.centre ? null : s.categories === "beside" ? (e, t) => we(Math.floor(t * E / (L / a.length))) : (e) => we(Math.floor(e * E / Se));
1977
- let Te = Se / C * 100, Ee = 100 / a.length;
1978
- if (t.rowBox = s.categories === "beside" ? (e) => [
2399
+ let je = b.length ? W(b.map((e) => J(e).width)) * F + 12 * F : 0, Me = t.categories[0]?.parentElement;
2400
+ Me && (Me.style.paddingRight = je ? `${je / D * 100}%` : "");
2401
+ let Fe = (D - je) / l.length, Ie = (e) => (e + .5) * Fe, Le = (e) => e >= 0 && e < l.length ? e : null;
2402
+ t.rowAt = m.centre ? null : m.categories === "beside" ? (e, t) => Le(Math.floor(t * F / (G / l.length))) : (e) => Le(Math.floor(e * F / Fe));
2403
+ let Re = Fe / D * 100, ze = 100 / l.length;
2404
+ if (t.rowBox = m.categories === "beside" ? (e) => [
1979
2405
  0,
1980
- e * Ee,
2406
+ e * ze,
1981
2407
  100,
1982
- Ee
2408
+ ze
1983
2409
  ] : (e) => [
1984
- e * Te,
2410
+ e * Re,
1985
2411
  0,
1986
- Te,
2412
+ Re,
1987
2413
  100
1988
- ], i.setAttribute("viewBox", `0 0 ${C} ${k(L)}`), i.textContent = "", _e && ge) {
1989
- let [e, r, a, o] = _e, [s, c] = ve, l = ge;
1990
- Ht(t.figure, "data-chart-grid", n.grid) && i.appendChild(A("path", {
1991
- class: S,
1992
- d: [...s.map((e) => `M${k(l(e))},${k(r)}V${k(r + o)}`), ...c.map((t) => `M${k(e)},${k(he(t))}H${k(e + a)}`)].join("")
1993
- })), i.appendChild(A("path", {
1994
- class: b,
2414
+ ], i.setAttribute("viewBox", `0 0 ${D} ${N(G)}`), i.textContent = "", ke && Oe) {
2415
+ let [e, r, a, o] = ke, [s, c] = Ae, l = Oe;
2416
+ un(t.figure, "data-chart-grid", n.grid) && i.appendChild(P("path", {
2417
+ class: E,
2418
+ d: [...s.map((e) => `M${N(l(e))},${N(r)}V${N(r + o)}`), ...c.map((t) => `M${N(e)},${N(De(t))}H${N(e + a)}`)].join("")
2419
+ })), i.appendChild(P("path", {
2420
+ class: w,
1995
2421
  d: [
1996
- `M${k(e)},${k(r)}V${k(r + o)}H${k(e + a)}`,
1997
- ...s.map((e) => `M${k(l(e))},${k(r + o)}v${k(4 * E)}`),
1998
- ...c.map((t) => `M${k(e)},${k(he(t))}h${k(-4 * E)}`)
2422
+ `M${N(e)},${N(r)}V${N(r + o)}H${N(e + a)}`,
2423
+ ...s.map((e) => `M${N(l(e))},${N(r + o)}v${N(4 * F)}`),
2424
+ ...c.map((t) => `M${N(e)},${N(De(t))}h${N(-4 * F)}`)
1999
2425
  ].join("")
2000
2426
  }));
2001
2427
  }
2002
2428
  t.checks = [];
2003
- let De = {
2004
- rows: a,
2005
- segments: B,
2006
- cx: Ce,
2007
- y: he,
2008
- x: ge,
2009
- frame: _e,
2010
- length: (e, n) => en(t.figure, E, e, n),
2011
- barWidth: Math.min(Se * n.barfill, tn(t.figure, E)),
2012
- barMax: tn(t.figure, E),
2013
- height: L,
2014
- unit: E,
2015
- labelHeight: F,
2016
- badgeHeight: I,
2017
- after: a.length,
2429
+ let Be = {
2430
+ rows: l,
2431
+ segments: K,
2432
+ cx: Ie,
2433
+ y: De,
2434
+ x: Oe,
2435
+ frame: ke,
2436
+ length: (e, n) => Sn(t.figure, F, e, n),
2437
+ barWidth: Math.min(Fe * n.barfill, Cn(t.figure, F)),
2438
+ barMax: Cn(t.figure, F),
2439
+ height: G,
2440
+ unit: F,
2441
+ labelHeight: te,
2442
+ badgeHeight: ne,
2443
+ after: l.length,
2018
2444
  note: 0,
2019
- labels: t.figure.dataset.chartLabels === "inside" || t.figure.dataset.chartLabels !== "outside" && n.labels === "inside" ? "inside" : "outside",
2020
- insideAlign: $t(t.figure),
2021
- breakAt: ue,
2022
- squeeze: J,
2023
- breakGap: de,
2024
- domain: w ? [w.min, w.max] : null,
2445
+ labels: t.figure.dataset.chartLabels === "inside" || t.figure.dataset.chartLabels !== "outside" && (n.labels === "inside" || ce.length > 0) ? "inside" : "outside",
2446
+ insideAlign: xn(t.figure),
2447
+ breakAt: Ce,
2448
+ squeeze: Y,
2449
+ breakGap: we,
2450
+ domain: j ? [j.min, j.max] : null,
2025
2451
  stacked: t.stacked,
2026
- shape: Wt(t.figure, n),
2452
+ shape: fn(t.figure, n),
2453
+ pick: En(t.figure, n),
2027
2454
  totals: t.totals,
2028
2455
  svg: i,
2029
2456
  plot: r,
2030
- values: c,
2031
- series: l,
2032
- seriesValues: u,
2033
- names: d,
2457
+ values: g,
2458
+ series: _,
2459
+ own: _.map((e, t) => t),
2460
+ seriesValues: y,
2461
+ names: b,
2034
2462
  categories: t.categories,
2035
2463
  centre: t.centre,
2036
2464
  config: n,
2037
2465
  checks: t.checks,
2038
- taken: []
2466
+ taken: [],
2467
+ lineHoles: []
2468
+ };
2469
+ r.style.setProperty("--count", String(Math.max(1, ...l.map((e) => e.slot + 1))));
2470
+ let Ve = (e) => {
2471
+ let t = (t) => ({
2472
+ ...t,
2473
+ ...t.cells[e] ?? t.cells[0]
2474
+ });
2475
+ return {
2476
+ rows: l.map(t),
2477
+ segments: K.map((e) => {
2478
+ let n = t(e);
2479
+ return e.kind === "bar" ? {
2480
+ ...n,
2481
+ to: n.value
2482
+ } : n;
2483
+ }),
2484
+ values: y[e]
2485
+ };
2039
2486
  };
2040
- if (r.style.setProperty("--count", String(Math.max(1, ...a.map((e) => e.slot + 1)))), s.draw(De), De.rowAt && (t.rowAt = De.rowAt), v && w) {
2041
- let e = 6 * E, r = _ && De.x ? De.x : he, a = Array.from(v.ticks.children), o = (e) => q(a.find((t) => Number(t.dataset.value) === e) ?? a[0]), s = et(w, (t) => t.every((n, i) => !i || (_ ? r(n) - r(t[i - 1]) > (o(n).width + o(t[i - 1]).width) / 2 * E + e : r(t[i - 1]) - r(n) > o(n).height * E + e / 2))).ticks.filter((e) => !J || e <= J.lo || e >= J.hi);
2487
+ if (ce.length) {
2488
+ let e = _.flatMap((e, t) => e.chart ? [] : [t]);
2489
+ m.draw({
2490
+ ...Be,
2491
+ own: e,
2492
+ ...e.length === 1 && Ve(e[0])
2493
+ }), tt.draw({
2494
+ ...Be,
2495
+ own: ce
2496
+ });
2497
+ } else m.draw(Be);
2498
+ Be.rowAt && (t.rowAt = Be.rowAt), t.pointOf = Be.pointOf ?? null;
2499
+ let He = Number(r.style.getPropertyValue("--count")) || l.length;
2500
+ for (let e of t.figure.querySelectorAll(`.${f}`)) e.style.setProperty("--i", String(Math.min(l[l.length - 1].slot, He - 1)));
2501
+ if (!t.stacked && !r.hasAttribute("data-grouped")) for (let e of y) xe(e, F, D), Se(e, F, D, G);
2502
+ if (k && j) {
2503
+ let e = 6 * F, r = O && Be.x ? Be.x : De, a = Array.from(k.ticks.children), o = (e) => J(a.find((t) => Number(t.dataset.value) === e) ?? a[0]), s = bt(j, (t) => t.every((n, i) => !i || (O ? r(n) - r(t[i - 1]) > (o(n).width + o(t[i - 1]).width) / 2 * F + e : r(t[i - 1]) - r(n) > o(n).height * F + e / 2))).ticks.filter((e) => !Y || e <= Y.lo || e >= Y.hi);
2042
2504
  for (let t of a) {
2043
- let n = Number(t.dataset.value), i = v.numbers && s.includes(n);
2044
- t.dataset.place = i ? _ ? "below" : "before" : "none", i && N(t, _ ? r(n) : -e, _ ? L + e : r(n), C, L);
2505
+ let n = Number(t.dataset.value), i = k.numbers && s.includes(n);
2506
+ t.dataset.place = i ? O ? "below" : "before" : "none", i && L(t, O ? r(n) : -e, O ? G + e : r(n), D, G);
2045
2507
  }
2046
- let c = C - ye;
2047
- Ht(t.figure, "data-chart-grid", n.grid) && i.prepend(A("path", {
2048
- class: S,
2049
- d: s.map((e) => _ ? `M${k(r(e))},0V${k(L)}` : `M0,${k(r(e))}H${k(c)}`).join("")
2050
- })), v.numbers && i.appendChild(A("path", {
2051
- class: b,
2052
- d: [_ ? `M${k(r(w.min))},${k(L)}H${k(r(w.max))}` : `M0,${k(r(w.max))}V${k(r(w.min))}`, ...s.map((e) => _ ? `M${k(r(e))},${k(L)}v${k(4 * E)}` : `M0,${k(r(e))}h${k(-4 * E)}`)].join("")
2508
+ let c = D - je;
2509
+ un(t.figure, "data-chart-grid", n.grid) && i.prepend(P("path", {
2510
+ class: E,
2511
+ d: s.map((e) => O ? `M${N(r(e))},0V${N(G)}` : `M0,${N(r(e))}H${N(c)}`).join("")
2512
+ })), k.numbers && i.appendChild(P("path", {
2513
+ class: w,
2514
+ d: [O ? `M${N(r(j.min))},${N(G)}H${N(r(j.max))}` : `M0,${N(r(j.max))}V${N(r(j.min))}`, ...s.map((e) => O ? `M${N(r(e))},${N(G)}v${N(4 * F)}` : `M0,${N(r(e))}h${N(-4 * F)}`)].join("")
2053
2515
  }));
2054
2516
  }
2055
- for (let [e, n] of p.entries()) {
2517
+ for (let [e, n] of x.entries()) {
2056
2518
  n.badge?.setAttribute("data-note", String(e + 1));
2057
- let i = n.series, o = (e) => ({
2058
- ...e,
2059
- ...e.cells[i] ?? e.cells[0]
2060
- });
2519
+ let i = n.series;
2061
2520
  n.type.draw(n.spec, n.badge, {
2062
- ...De,
2521
+ ...Be,
2063
2522
  ...t.stacked && {
2064
- rows: te,
2523
+ rows: ie,
2065
2524
  ...t.totals.length && { values: t.totals }
2066
2525
  },
2067
- ...i > 0 && !t.stacked && {
2068
- rows: a.map(o),
2069
- segments: B.map((e) => {
2070
- let t = o(e);
2071
- return e.kind === "bar" ? {
2072
- ...t,
2073
- to: t.value
2074
- } : t;
2075
- }),
2076
- values: u[i]
2077
- },
2526
+ ...i > 0 && !t.stacked && Ve(i),
2078
2527
  after: t.plan ? n.after : Math.min(n.after, Number(r.style.getPropertyValue("--count")) || n.after),
2079
2528
  note: e + 1
2080
2529
  });
2081
2530
  }
2082
- it(t);
2083
- let Oe = t.categories[0]?.parentElement;
2084
- Oe && s.categories !== "beside" && !s.centre && xe(Oe, t.categories.filter((e) => e.offsetParent !== null), (e) => ({
2085
- size: e.scrollWidth,
2086
- room: e.clientWidth
2087
- }), "--_name-fit");
2088
- let ke = p.flatMap(({ badge: e }) => {
2531
+ wt(t);
2532
+ for (let e of t.figure.querySelectorAll(`.${p}`)) {
2533
+ let n = Array.from(e.children);
2534
+ if (t.plan) for (let e of n) e.style.getPropertyValue("--step") || e.style.setProperty("--i", "0");
2535
+ let r = n.map((e) => Number.parseFloat(e.style.getPropertyValue("--step")));
2536
+ e.style.setProperty("--i", String(Math.min(...n.map((e) => Number(e.style.getPropertyValue("--i")) || 0)))), r.length && r.every(Number.isFinite) ? e.style.setProperty("--step", String(Math.min(...r))) : e.style.removeProperty("--step");
2537
+ }
2538
+ let X = t.categories[0]?.parentElement;
2539
+ if (X && m.categories !== "beside" && !m.centre) {
2540
+ X.style.height = `${X.offsetHeight}px`, X.removeAttribute("data-thinned");
2541
+ for (let e of t.categories) e.removeAttribute("data-left-out"), e.removeAttribute("data-edge");
2542
+ let e = t.categories.filter((e) => e.offsetParent !== null);
2543
+ if (!ve(X, e, (e) => ({
2544
+ size: e.scrollWidth,
2545
+ room: e.clientWidth
2546
+ }), "--_name-fit") && e.length > 1) {
2547
+ let t = getComputedStyle(X), n = (X.clientWidth - Number.parseFloat(t.paddingLeft) - Number.parseFloat(t.paddingRight)) / l.length;
2548
+ X.style.setProperty("--_name-fit", "1"), X.setAttribute("data-thinned", "");
2549
+ let r = W(e.map((e) => e.offsetWidth)), i = Math.max(Math.ceil((r + 8) / n), Math.ceil((1.5 * r + 8) / n - .5), 1);
2550
+ e.forEach((e, t) => {
2551
+ t % i && e.setAttribute("data-left-out", "");
2552
+ });
2553
+ let a = e.filter((e) => !e.hasAttribute("data-left-out")), o = a[0], s = a.at(-1), c = X.getBoundingClientRect(), u = [o, s].map((e) => e?.getBoundingClientRect());
2554
+ if (o && u[0] && u[0].left < c.left && o.setAttribute("data-edge", "start"), s && s !== o && u[1] && u[1].right > c.right - Number.parseFloat(t.paddingRight)) {
2555
+ s.setAttribute("data-edge", "end");
2556
+ let e = a.at(-2);
2557
+ e && e.getBoundingClientRect().right + 8 > s.getBoundingClientRect().left && s.setAttribute("data-left-out", "");
2558
+ }
2559
+ }
2560
+ let r = (m === tt || m === nt) && un(t.figure, "data-chart-ticks", n.ticks);
2561
+ if (X.toggleAttribute("data-ticks", r), X.style.removeProperty("--_tick-reach"), r) {
2562
+ let e = G - Number(i.querySelector(".tablechart-rule")?.getAttribute("y1") ?? G);
2563
+ e > 0 && e < 10 * F && X.style.setProperty("--_tick-reach", `${N(e / F)}px`);
2564
+ let n = X.getBoundingClientRect(), r = n.width / (X.offsetWidth || 1), a = getComputedStyle(X), o = Number.parseFloat(a.paddingLeft), s = (X.clientWidth - o - Number.parseFloat(a.paddingRight)) / l.length;
2565
+ t.categories.forEach((e, t) => {
2566
+ if (e.hasAttribute("data-left-out")) e.style.removeProperty("--_tick");
2567
+ else {
2568
+ let i = (e.getBoundingClientRect().left - n.left) / r - X.clientLeft;
2569
+ e.style.setProperty("--_tick", `${N(o + (t + .5) * s - i)}px`);
2570
+ }
2571
+ });
2572
+ }
2573
+ X.style.height = "";
2574
+ }
2575
+ let Ue = x.flatMap(({ badge: e }) => {
2089
2576
  if (!(e instanceof HTMLElement) || !e.offsetWidth) return [];
2090
- let t = e.offsetWidth * E, n = e.offsetHeight * E, r = Number.parseFloat(e.style.left) / 100 * C, i = Number.parseFloat(e.style.top) / 100 * L, a = getComputedStyle(e).borderTopLeftRadius, o = a.endsWith("%") ? Number.parseFloat(a) / 100 : null, s = (Number.parseFloat(a) || 0) * E;
2091
- return [A("rect", {
2092
- class: f,
2577
+ let t = e.offsetWidth * F, n = e.offsetHeight * F, r = Number.parseFloat(e.style.left) / 100 * D, i = Number.parseFloat(e.style.top) / 100 * G, a = getComputedStyle(e).borderTopLeftRadius, o = a.endsWith("%") ? Number.parseFloat(a) / 100 : null, s = (Number.parseFloat(a) || 0) * F;
2578
+ return [P("rect", {
2579
+ class: h,
2093
2580
  "data-for": "badge",
2094
2581
  "data-note": e.dataset.note ?? "",
2095
2582
  x: r - t / 2,
@@ -2100,94 +2587,96 @@ var Fe = (e) => e.map((e) => ({
2100
2587
  ry: o === null ? s : n * o,
2101
2588
  style: ["--after", "--step"].map((t) => e.style.getPropertyValue(t) && `${t}:${e.style.getPropertyValue(t)}`).filter(Boolean).join("; ")
2102
2589
  })];
2103
- }), Ae = i.querySelector(`.${S}`), X = Array.from(i.querySelectorAll(`.${o}`));
2104
- if (Ae || X.length) {
2105
- let e = r.getBoundingClientRect(), n = C / e.width, a = getComputedStyle(r), o = Number.parseFloat(a.lineHeight) / Number.parseFloat(a.fontSize) || 1.2, c = [
2106
- ...u.flat(),
2590
+ }), Z = i.querySelector(`.${E}`), We = Array.from(i.querySelectorAll(`.${o}`)), Ge = [...Z ? [Z] : [], ...i.querySelectorAll(`:scope > .${s}`)], Ke = wn(r, F), qe = t.figure.getAttribute("data-animate") === "grow", Je = y.flat().filter((e) => e.hasAttribute("data-cut")).flatMap(Ke), Ye = [...ce.flatMap((e) => y[e].flatMap(Ke)), ...qe ? Je : []];
2591
+ if (Ge.length || We.length) {
2592
+ let e = [
2593
+ ...y.flat(),
2107
2594
  ...t.totals,
2108
- ...s.categories === "beside" ? t.categories : []
2109
- ].flatMap((t) => {
2110
- if (t.dataset.place === "none" || t.hidden || t.hasAttribute("data-left-out")) return [];
2111
- let r = t.getBoundingClientRect(), i = r.height * n / o, a = Array.from(t.style).filter((e) => e.startsWith("--")).map((e) => `${e}:${t.style.getPropertyValue(e)}`);
2112
- return r.width ? [A("rect", {
2113
- class: f,
2114
- "data-for": "text",
2115
- x: (r.left - e.left) * n - 3 * E,
2116
- y: (r.top - e.top) * n + (r.height * n - i) / 2 - E,
2117
- width: r.width * n + 6 * E,
2118
- height: i + 2 * E,
2119
- style: a.join("; ")
2120
- })] : [];
2121
- }), l = (e) => [
2595
+ ...m.categories === "beside" ? t.categories : []
2596
+ ].flatMap(Ke), n = (e) => [
2122
2597
  "x",
2123
2598
  "y",
2124
2599
  "width",
2125
2600
  "height"
2126
2601
  ].map((t) => Number(e.getAttribute(t)));
2127
- for (let e of X) zt(e, [...c, ...ke].map(l));
2128
- if (Ae && t.plan) ee(i, c, C, L, [Ae]);
2129
- else if (Ae) {
2130
- let e = Bt(Ae);
2131
- Ae.setAttribute("d", e.map(([e, t, n, r]) => Rt(e, t, n, r, c.map(l))).join(""));
2132
- for (let t of c) {
2133
- let n = Vt(e, l(t));
2134
- n && Ae.after(A("path", {
2135
- class: S,
2136
- "data-gap": "",
2137
- d: n,
2138
- style: t.getAttribute("style") ?? ""
2602
+ for (let t of We) sn(t, [...e, ...Ue].map(n));
2603
+ if (Ge.length && t.plan) U(i, e, D, G, Ge);
2604
+ else for (let t of Ge) {
2605
+ let r = [...e, ...Ue], i = cn(t);
2606
+ t.setAttribute("d", i.map(([e, t, i, a]) => on(e, t, i, a, r.map(n))).join(""));
2607
+ for (let e of r) {
2608
+ let r = ln(i, n(e)), a = e.dataset.for === "badge" ? "badge" : "";
2609
+ r && t.after(P("path", {
2610
+ class: t.getAttribute("class") ?? "tablechart-grid",
2611
+ "data-gap": a,
2612
+ d: r,
2613
+ style: e.getAttribute("style") ?? ""
2139
2614
  }));
2140
2615
  }
2141
2616
  }
2142
2617
  }
2143
- ee(i, ke, C, L, void 0, `.${o}`), t.figure.hasAttribute("data-animate") && !t.figure.hasAttribute("data-steps") && !t.figure.classList.contains("is-shown") && ln(i);
2144
- let je = (e) => e.dataset.missing !== void 0 || s.centre && a[Number(e.dataset.row) - 1]?.isTotal, Me = (e) => e.dataset.place !== "none" && !e.hasAttribute("data-left-out"), Ne = (e, t) => {
2618
+ if (H(i, Ue, D, G, Array.from(i.querySelectorAll(`.${a}, .${c}`))), !qe && (Be.lineHoles.length || Je.length)) {
2619
+ let e = Array.from(i.querySelectorAll(`.${u}`)).map((e) => {
2620
+ let t = P("g", {});
2621
+ return e.before(t), t.append(e), t;
2622
+ });
2623
+ H(i, [...Be.lineHoles, ...Je], D, G, [...e, ...i.querySelectorAll(`.${d}`)]);
2624
+ }
2625
+ let Xe = [
2626
+ o,
2627
+ s,
2628
+ a,
2629
+ c,
2630
+ ...t.plan ? [] : [E]
2631
+ ];
2632
+ U(i, [...Ue, ...Ye], D, G, void 0, Xe.map((e) => `.${e}`).join(", ")), t.figure.hasAttribute("data-animate") && !t.figure.hasAttribute("data-steps") && !t.figure.classList.contains("is-shown") && Pn(i);
2633
+ let Ze = (e) => e.dataset.missing !== void 0 || m.centre && l[Number(e.dataset.row) - 1]?.isTotal, Qe = (e) => e.dataset.place !== "none" && !e.hasAttribute("data-left-out"), $e = (e, t) => {
2145
2634
  let n = Number(e.dataset.row);
2146
- return t.some((e) => Me(e) && Number(e.dataset.row) <= n && n <= Number(e.dataset.rowEnd ?? e.dataset.row));
2635
+ return t.some((e) => Qe(e) && Number(e.dataset.row) <= n && n <= Number(e.dataset.rowEnd ?? e.dataset.row));
2147
2636
  };
2148
- return t.figure.toggleAttribute("data-left-out", (s.columns ? [t.categories] : [...u, t.totals]).some((e) => e.some((t) => !je(t) && !Me(t) && !Ne(t, e)))), !0;
2149
- }, rn = (e, t) => {
2637
+ return t.figure.toggleAttribute("data-left-out", (m.columns ? [t.categories] : [...y, t.totals]).some((e) => e.some((t) => !Ze(t) && !Qe(t) && !$e(t, e)))), !0;
2638
+ }, kn = (e, t) => {
2150
2639
  let n = [
2151
2640
  ...e.seriesValues.flat(),
2152
2641
  ...e.totals,
2153
2642
  ...e.totalCell ? [e.totalCell] : []
2154
2643
  ];
2155
- for (let r of e.centre ? [...n, e.centre] : n) r.dataset.missing === void 0 ? an(r, r.dataset.decimals ? Number(r.dataset.decimals) : e.decimals, t.locale) : r.textContent = r.dataset.missing;
2156
- }, an = (e, t, n) => {
2157
- let { prefix: r = "", suffix: i = "" } = e.dataset, [a, o] = B(Number.parseFloat(e.dataset.value || "0"), t, n);
2644
+ for (let r of e.centre ? [...n, e.centre] : n) r.dataset.missing === void 0 ? An(r, r.dataset.decimals ? Number(r.dataset.decimals) : e.decimals, t.locale) : r.textContent = r.dataset.missing;
2645
+ }, An = (e, t, n) => {
2646
+ let { prefix: r = "", suffix: i = "" } = e.dataset, [a, o] = ie(Number.parseFloat(e.dataset.value || "0"), t, n);
2158
2647
  if (e.textContent = r + (r ? a : "") + o + i, a && !r) {
2159
2648
  let t = document.createElement("span");
2160
2649
  t.className = "tablechart-minus", t.textContent = a, e.prepend(t);
2161
2650
  }
2162
- }, on = (e) => {
2163
- jt(e), e.plot.remove(), e.categories[0]?.parentElement?.remove(), e.figure.querySelector(`:scope > .${u}`)?.remove(), e.controls?.remove();
2164
- }, sn = (e, t) => {
2165
- !t && !e.figure.hasAttribute("data-steps") && ln(e.svg), e.figure.classList.toggle(_, t), t && requestAnimationFrame(() => requestAnimationFrame(() => cn(e.figure, e.svg)));
2166
- }, cn = (e, t) => {
2167
- e.classList.contains("is-shown") && !t.getAnimations({ subtree: !0 }).length && un(t);
2168
- }, ln = (e) => {
2651
+ }, jn = (e) => {
2652
+ Qt(e), e.plot.remove(), e.categories[0]?.parentElement?.remove(), e.figure.querySelector(`:scope > .${p}`)?.remove(), e.controls?.remove();
2653
+ }, Mn = (e, t, n = !1) => {
2654
+ !t && !e.figure.hasAttribute("data-steps") && Pn(e.svg), n ? (e.figure.classList.add(S), e.figure.classList.toggle(b, t), e.figure.offsetWidth, t && Fn(e.svg), requestAnimationFrame(() => e.figure.classList.remove(S))) : (e.figure.classList.toggle(b, t), t && requestAnimationFrame(() => requestAnimationFrame(() => Nn(e.figure, e.svg))));
2655
+ }, Nn = (e, t) => {
2656
+ e.classList.contains("is-shown") && Array.from(t.querySelectorAll("[data-mask]")).every((e) => !e.getAnimations({ subtree: !0 }).length) && Fn(t);
2657
+ }, Pn = (e) => {
2169
2658
  for (let t of e.querySelectorAll("[mask^=\"url(#tablechart-cut-\"]")) t.dataset.mask = t.getAttribute("mask") ?? "", t.removeAttribute("mask");
2170
- }, un = (e) => {
2659
+ }, Fn = (e) => {
2171
2660
  for (let t of e.querySelectorAll("[data-mask]")) t.setAttribute("mask", t.dataset.mask ?? ""), t.removeAttribute("data-mask");
2172
- }, dn = (e) => e === "id" || e === "style" || e.startsWith("data-chart"), fn = /^\s*(?:Table)?:\s+/, pn = (e) => e?.tagName === "P" && fn.test(e.textContent ?? ""), mn = (e) => {
2661
+ }, In = (e) => e === "id" || e === "style" || e.startsWith("data-chart"), Ln = /^\s*(?:Table)?:\s+/, Rn = (e) => e?.tagName === "P" && Ln.test(e.textContent ?? ""), zn = (e) => {
2173
2662
  let t = document.createElement("figcaption");
2174
2663
  for (let { name: n, value: r } of Array.from(e.attributes)) t.setAttribute(n, r);
2175
2664
  let n = e.firstChild;
2176
- n?.nodeType === Node.TEXT_NODE && (n.textContent = (n.textContent ?? "").replace(fn, ""), n.textContent || n.remove());
2665
+ n?.nodeType === Node.TEXT_NODE && (n.textContent = (n.textContent ?? "").replace(Ln, ""), n.textContent || n.remove());
2177
2666
  let r = Array.from(e.childNodes), i = r.findIndex((e) => e.nodeName === "BR");
2178
2667
  if (t.append(...i === -1 ? r : r.slice(0, i + 1)), i !== -1 && i < r.length - 1) {
2179
2668
  let e = document.createElement("span");
2180
2669
  e.append(...r.slice(i + 1)), t.append(e);
2181
2670
  }
2182
2671
  return e.remove(), t;
2183
- }, hn = /^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/, gn = (e) => {
2184
- let t = wn(e);
2672
+ }, Bn = /^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/, Vn = (e) => {
2673
+ let t = Yn(e);
2185
2674
  return t?.tagName === "P" ? t : e;
2186
- }, _n = (e) => {
2187
- let t = gn(e).firstChild;
2675
+ }, Hn = (e) => {
2676
+ let t = Vn(e).firstChild;
2188
2677
  if (t?.nodeType !== Node.TEXT_NODE) return null;
2189
- let n = hn.exec(t.textContent ?? "");
2190
- if (!n || !Ft.includes(n[1]) || !n[3] && t.nextSibling) return null;
2678
+ let n = Bn.exec(t.textContent ?? "");
2679
+ if (!n || !nn.includes(n[1]) || !n[3] && t.nextSibling) return null;
2191
2680
  let r = n[2].trim().split(/\s+/).filter(Boolean).map((e) => e.split("="));
2192
2681
  return {
2193
2682
  name: n[1],
@@ -2195,11 +2684,11 @@ var Fe = (e) => e.map((e) => ({
2195
2684
  text: t,
2196
2685
  length: n[0].length
2197
2686
  };
2198
- }, vn = (e) => {
2687
+ }, Un = (e) => {
2199
2688
  if (e?.tagName !== "UL" && e?.tagName !== "OL") return null;
2200
- let t = Array.from(e.children), n = t.map((e) => e.hasAttribute("data-annotation") ? null : _n(e));
2689
+ let t = Array.from(e.children), n = t.map((e) => e.hasAttribute("data-annotation") ? null : Hn(e));
2201
2690
  return !t.length || t.some((e, t) => !n[t] && !e.hasAttribute("data-annotation")) ? null : (t.forEach((e, t) => {
2202
- let r = n[t], i = gn(e);
2691
+ let r = n[t], i = Vn(e);
2203
2692
  if (i !== e && i.replaceWith(...i.childNodes), r) {
2204
2693
  e.setAttribute("data-annotation", r.name);
2205
2694
  for (let [t, n] of r.options) e.setAttribute(`data-${t}`, n);
@@ -2210,20 +2699,21 @@ var Fe = (e) => e.map((e) => ({
2210
2699
  t === 0 && e instanceof HTMLElement && e.matches("em, i") ? (n.className = "tablechart-caption", n.append(...e.childNodes), e.replaceWith(n)) : e.nodeType === Node.TEXT_NODE && (n.textContent = (e.textContent ?? "").trim(), e.replaceWith(n));
2211
2700
  });
2212
2701
  }), e.classList.add("chart-annotations"), e);
2213
- }, yn = (e, t) => {
2214
- for (let { name: n, value: r } of Array.from(e.attributes)) (n === "class" || dn(n)) && (t.setAttribute(n, r), e.removeAttribute(n));
2215
- }, bn = (e) => e.map((e) => {
2216
- let t = e.closest("p"), n = pn(t) ? t : e;
2702
+ }, Wn = (e, t) => {
2703
+ for (let { name: n, value: r } of Array.from(e.attributes)) (n === "class" || In(n)) && (t.setAttribute(n, r), e.removeAttribute(n));
2704
+ }, Gn = (e) => e.map((e) => {
2705
+ let t = e.closest("p"), n = Rn(t) ? t : e;
2217
2706
  if (n.tagName !== "TABLE" && n.tagName !== "P") return n;
2218
2707
  let r = document.createElement("figure");
2219
- yn(e, r), e.classList.length || e.removeAttribute("class");
2220
- let i = n.tagName === "TABLE" ? n : null, a = n.previousElementSibling, o = n.nextElementSibling, s = i ? pn(a) ? a : pn(o) ? o : null : n;
2708
+ Wn(e, r), e.classList.length || e.removeAttribute("class");
2709
+ let i = n.tagName === "TABLE" ? n : null, a = n.previousElementSibling, o = n.nextElementSibling, s = i ? Rn(a) ? a : Rn(o) ? o : null : n;
2221
2710
  i && s === o && (o = o?.nextElementSibling ?? null);
2222
- let c = o?.classList.contains("chart-annotations") ? o : vn(o);
2223
- return n.replaceWith(r), s && r.append(mn(s)), i && r.append(i), c && r.append(c), Z?.log?.(`A ${i ? "table" : "caption"} with chart attributes was wrapped in a figure of its own`), r;
2224
- }), xn = (e, t, n, r = document.createElement("table")) => {
2711
+ let c = o?.classList.contains("chart-annotations") ? o : Un(o);
2712
+ return n.replaceWith(r), s && r.append(zn(s)), i && r.append(i), c && r.append(c), Q?.log?.(`A ${i ? "table" : "caption"} with chart attributes was wrapped in a figure of its own`), r;
2713
+ }), Kn = (e, t, n, r = document.createElement("table"), i = "Note") => {
2225
2714
  for (let e of r.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr")) e.remove();
2226
- if (!r.tHead && (t.length || n)) {
2715
+ let a = e.some((e) => e.note);
2716
+ if (!r.tHead && (t.length || n || a)) {
2227
2717
  let e = r.createTHead().insertRow(), i = document.createElement("th");
2228
2718
  i.textContent = n, e.append(i);
2229
2719
  for (let n of t) {
@@ -2231,17 +2721,25 @@ var Fe = (e) => e.map((e) => ({
2231
2721
  t.textContent = n, e.append(t);
2232
2722
  }
2233
2723
  }
2234
- let i = document.createElement("tbody");
2235
- r.append(i);
2724
+ let o = document.createElement("tbody");
2725
+ r.append(o);
2236
2726
  for (let t of e) {
2237
- let e = i.insertRow();
2727
+ let e = o.insertRow();
2238
2728
  t.kind === "total" && (e.dataset.kind = "total");
2239
2729
  let n = document.createElement("th");
2240
- n.textContent = String(t.label ?? ""), e.append(n);
2730
+ n.textContent = String(t.label ?? ""), t.short && (n.dataset.short = t.short), e.append(n);
2241
2731
  for (let n of t.values ?? [t.value ?? null]) e.insertCell().textContent = n === null ? "" : String(n);
2732
+ a && (e.insertCell().textContent = t.note ?? "");
2733
+ }
2734
+ let s = r.tHead?.rows[r.tHead.rows.length - 1];
2735
+ if (a && s && !s.querySelector("[data-note]")) {
2736
+ let t = Math.max(...e.map((e) => (e.values ?? [e.value]).length));
2737
+ for (; s.cells.length < t + 1;) s.append(document.createElement("th"));
2738
+ let n = document.createElement("th");
2739
+ n.dataset.note = "", n.textContent = i, s.append(n);
2242
2740
  }
2243
2741
  return r;
2244
- }, Sn = (e) => {
2742
+ }, qn = (e) => {
2245
2743
  if (!e || typeof e != "object") return;
2246
2744
  let t = Object.entries(e), n = (e) => e === null || typeof e == "string" || typeof e == "number";
2247
2745
  if (t.length && t.every(([, e]) => n(e) || Array.isArray(e) && e.every(n))) return t.map(([e, t]) => Array.isArray(t) ? {
@@ -2251,30 +2749,30 @@ var Fe = (e) => e.map((e) => ({
2251
2749
  label: e,
2252
2750
  value: t
2253
2751
  });
2254
- }, Cn = async (t) => {
2752
+ }, Jn = async (t) => {
2255
2753
  await Promise.all(t.filter((e) => e.hasAttribute("data-chart-src")).map(async (t) => {
2256
2754
  let n = t.getAttribute("data-chart-src"), r = Array.from(t.querySelectorAll("table")).find((e) => e.tHead) ?? null;
2257
2755
  for (let e of t.querySelectorAll("table")) e !== r && e.remove();
2258
2756
  try {
2259
2757
  let e = await fetch(n);
2260
2758
  if (!e.ok) throw Error(`${e.status} ${e.statusText}`);
2261
- let i = await e.json(), a = Array.isArray(i) ? i : i?.rows ? Array.isArray(i.rows) ? i.rows : Sn(i.rows) : Sn(i);
2759
+ let i = await e.json(), a = Array.isArray(i) ? i : i?.rows ? Array.isArray(i.rows) ? i.rows : qn(i.rows) : qn(i);
2262
2760
  if (!Array.isArray(a)) throw Error("no rows in it: a list of rows, an object with rows, or names with their values");
2263
- let o = xn(a, Array.isArray(i?.series) ? i.series.map(String) : [], typeof i?.label == "string" ? i.label : "", r ?? void 0);
2761
+ let o = Kn(a, Array.isArray(i?.series) ? i.series.map(String) : [], typeof i?.label == "string" ? i.label : "", r ?? void 0, typeof i?.note == "string" ? i.note : void 0);
2264
2762
  if (!r) {
2265
2763
  let e = t.querySelector(":scope > figcaption");
2266
2764
  e ? e.after(o) : t.prepend(o);
2267
2765
  }
2268
- o.tHead || Z?.log?.(`The table from "${n}" has no header row, so a screen reader cannot name its columns.`), Z?.log?.(`Read ${a.length} rows from "${n}"`);
2766
+ o.tHead || Q?.log?.(`The table from "${n}" has no header row, so a screen reader cannot name its columns.`), Q?.log?.(`Read ${a.length} rows from "${n}"`);
2269
2767
  } catch (t) {
2270
2768
  let r = window.location.protocol === "file:";
2271
2769
  console.warn(`[${e}] Could not read the chart data in "${n}": ${t.message}.` + (r ? " A page opened as a file cannot fetch files; open it from a server." : ""));
2272
2770
  }
2273
2771
  }));
2274
- }, wn = (e) => {
2772
+ }, Yn = (e) => {
2275
2773
  let t = Array.from(e.childNodes).filter((e) => e.nodeType === Node.ELEMENT_NODE || e.nodeType === Node.TEXT_NODE && e.textContent?.trim());
2276
2774
  return t.length === 1 && t[0] instanceof HTMLElement ? t[0] : null;
2277
- }, Tn = "strong, b, span.total", En = (e) => {
2775
+ }, Xn = "strong, b, span.total", Zn = (e) => {
2278
2776
  for (let t of e) {
2279
2777
  for (let e of t.querySelectorAll("tbody tr")) {
2280
2778
  let t = e.cells[0];
@@ -2282,16 +2780,16 @@ var Fe = (e) => e.map((e) => ({
2282
2780
  let n = document.createElement("th");
2283
2781
  for (let { name: e, value: r } of Array.from(t.attributes)) n.setAttribute(e, r);
2284
2782
  n.append(...t.childNodes), t.replaceWith(n);
2285
- for (let t = wn(n); t?.matches(Tn); t = wn(n)) e.dataset.kind = "total", t.replaceWith(...t.childNodes);
2783
+ for (let t = Yn(n); t?.matches(Xn); t = Yn(n)) e.dataset.kind = "total", t.replaceWith(...t.childNodes);
2286
2784
  }
2287
2785
  let e = Array.from(t.querySelector("thead tr:last-child")?.children ?? []);
2288
- for (let t of e.slice(1)) for (let e = wn(t); e?.matches(Tn); e = wn(t)) t.setAttribute("data-kind", "focus"), e.replaceWith(...e.childNodes);
2786
+ for (let t of e.slice(1)) for (let e = Yn(t); e?.matches(Xn); e = Yn(t)) t.setAttribute("data-kind", "focus"), e.replaceWith(...e.childNodes);
2289
2787
  }
2290
- }, Dn = "data-chart-made", On = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, kn = (e) => new Promise((t) => setTimeout(t, e)), An = (e, t) => {
2788
+ }, Qn = "data-chart-made", $n = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, er = (e) => new Promise((t) => setTimeout(t, e)), tr = (e, t) => {
2291
2789
  let n = Number.parseFloat(e.dataset.chartEntrance ?? ""), r = Number.isFinite(n) ? n : t.entrance;
2292
2790
  return Math.min(Math.max(r, 0), 1);
2293
- }, jn = async (e, t) => {
2294
- if (On()) return;
2791
+ }, nr = async (e, t) => {
2792
+ if ($n()) return;
2295
2793
  await new Promise(requestAnimationFrame);
2296
2794
  let n = e.getAnimations().filter((e) => e instanceof CSSAnimation);
2297
2795
  for (let t = e.parentElement; t && t !== document.body; t = t.parentElement) n.push(...t.getAnimations());
@@ -2302,11 +2800,11 @@ var Fe = (e) => e.map((e) => ({
2302
2800
  let a = Number(n.delay ?? 0) + i * t;
2303
2801
  r = Math.max(r, a - Number(e.currentTime ?? 0));
2304
2802
  }
2305
- r > 0 && await kn(r);
2306
- }, Mn = (e) => {
2803
+ r > 0 && await er(r);
2804
+ }, rr = (e) => {
2307
2805
  for (let t = e; t && t !== document.body; t = t.parentElement) if (getComputedStyle(t).opacity === "0") return t;
2308
2806
  return null;
2309
- }, Nn = (e) => new Promise((t) => {
2807
+ }, ir = (e) => new Promise((t) => {
2310
2808
  let n = ["animationstart", "transitionrun"], r = () => {
2311
2809
  for (let e of n) document.removeEventListener(e, i, !0);
2312
2810
  a.disconnect(), t();
@@ -2320,41 +2818,41 @@ var Fe = (e) => e.map((e) => ({
2320
2818
  attributes: !0,
2321
2819
  attributeFilter: ["class", "style"]
2322
2820
  });
2323
- }), Pn = /* @__PURE__ */ new Set(), Fn = null, In = (e) => {
2324
- Pn.add(e), !Fn && (Fn = new MutationObserver(() => {
2325
- for (let e of Pn) e.relabel();
2821
+ }), ar = /* @__PURE__ */ new Set(), or = null, sr = (e) => {
2822
+ ar.add(e), !or && (or = new MutationObserver(() => {
2823
+ for (let e of ar) e.relabel();
2326
2824
  requestAnimationFrame(() => requestAnimationFrame(() => {
2327
- for (let e of Pn) e.refresh();
2825
+ for (let e of ar) e.refresh();
2328
2826
  }));
2329
- }), Fn.observe(document.documentElement, {
2827
+ }), or.observe(document.documentElement, {
2330
2828
  attributes: !0,
2331
2829
  attributeFilter: ["lang"]
2332
2830
  }));
2333
- }, Ln = (e) => {
2334
- Pn.delete(e), !Pn.size && Fn && (Fn.disconnect(), Fn = null);
2335
- }, Rn = ["column", "bar"], zn = (e) => {
2831
+ }, cr = (e) => {
2832
+ ar.delete(e), !ar.size && or && (or.disconnect(), or = null);
2833
+ }, lr = ["column", "bar"], ur = (e) => {
2336
2834
  let t = e.getAttribute("data-chart") || "column";
2337
- if (!Rn.includes(t)) return null;
2835
+ if (!lr.includes(t)) return null;
2338
2836
  let n = getComputedStyle(e).getPropertyValue("--tablechart-type").trim();
2339
- return Rn.includes(n) ? n : t;
2340
- }, Bn = (e, t) => {
2341
- let n = e, r = zn(n.figure), i = null, a = !1, o = !1, s = async () => {
2342
- if (!Ut(n.figure, t)) return sn(n, !0);
2837
+ return lr.includes(n) ? n : t;
2838
+ }, dr = (e, t) => {
2839
+ let n = e, r = ur(n.figure), i = null, a = !1, o = !1, s = async () => {
2840
+ if (!dn(n.figure, t)) return Mn(n, !0);
2343
2841
  let e = n.figure.classList.contains("is-shown");
2344
2842
  if (a && i !== null && !e && !o) {
2345
2843
  o = !0;
2346
- let e = On() ? null : Mn(n.figure);
2347
- e && await Nn(e), await jn(n.figure, An(n.figure, t)), o = !1, (a || !t.replay) && sn(n, !0);
2348
- } else !a && t.replay && e && sn(n, !1);
2844
+ let e = $n() ? null : rr(n.figure);
2845
+ e && await ir(e), await nr(n.figure, tr(n.figure, t)), o = !1, (a || !t.replay) && Mn(n, !0);
2846
+ } else !a && t.replay && e && Mn(n, !1);
2349
2847
  }, c = () => {
2350
- let e = zn(n.figure);
2848
+ let e = ur(n.figure);
2351
2849
  if (!e || e === r) return;
2352
- let a = Z.timed("Building", n.figure, () => Yt(n.figure, t, e));
2353
- a && (on(n), at(a, n.step, !0), n = a, r = e, i = null);
2850
+ let a = Q.timed("Building", n.figure, () => _n(n.figure, t, e));
2851
+ a && (jn(n), Tt(a, n.step, !0), n = a, r = e, i = null);
2354
2852
  }, l = () => {
2355
2853
  c();
2356
2854
  let e = n.plot.clientWidth;
2357
- e && e !== i && Z.timed("Layout", n.figure, () => nn(n, t)) && (i = e, s());
2855
+ e && e !== i && Q.timed("Layout", n.figure, () => On(n, t)) && (i = e, s());
2358
2856
  }, u = !1, d = new ResizeObserver(() => {
2359
2857
  u || (u = !0, requestAnimationFrame(() => {
2360
2858
  u = !1, l();
@@ -2362,20 +2860,20 @@ var Fe = (e) => e.map((e) => ({
2362
2860
  }), f = new IntersectionObserver((e) => {
2363
2861
  for (let t of e) a = t.isIntersecting, s();
2364
2862
  }, { threshold: t.threshold }), p = () => {
2365
- n.figure.classList.add(v), sn(n, !0), un(n.svg), n.figure.offsetWidth;
2366
- }, m = () => n.figure.classList.remove(v), h = () => {
2863
+ n.figure.classList.add(x), Mn(n, !0), Fn(n.svg), n.figure.offsetWidth;
2864
+ }, m = () => n.figure.classList.remove(x), h = () => {
2367
2865
  i = null, l();
2368
2866
  }, g = {
2369
- relabel: () => rn(n, t),
2867
+ relabel: () => kn(n, t),
2370
2868
  refresh: h
2371
2869
  };
2372
- c(), l(), d.observe(n.figure), f.observe(n.figure), window.addEventListener("beforeprint", p), window.addEventListener("afterprint", m), In(g);
2870
+ c(), l(), d.observe(n.figure), f.observe(n.figure), window.addEventListener("beforeprint", p), window.addEventListener("afterprint", m), sr(g);
2373
2871
  let _ = {
2374
2872
  figure: n.figure,
2375
2873
  refresh: h,
2376
- next: () => at(n, n.step + 1),
2377
- previous: () => at(n, n.step - 1),
2378
- stepTo: (e) => at(n, e),
2874
+ next: () => Tt(n, n.step + 1),
2875
+ previous: () => Tt(n, n.step - 1),
2876
+ stepTo: (e) => Tt(n, e),
2379
2877
  get step() {
2380
2878
  return n.step;
2381
2879
  },
@@ -2383,36 +2881,38 @@ var Fe = (e) => e.map((e) => ({
2383
2881
  return n.plan?.count ?? 0;
2384
2882
  },
2385
2883
  destroy() {
2386
- d.disconnect(), f.disconnect(), window.removeEventListener("beforeprint", p), window.removeEventListener("afterprint", m), Ln(g), jt(n), n.figure.tablechart === _ && delete n.figure.tablechart;
2884
+ d.disconnect(), f.disconnect(), window.removeEventListener("beforeprint", p), window.removeEventListener("afterprint", m), cr(g), Qt(n), n.figure.tablechart === _ && delete n.figure.tablechart;
2387
2885
  }
2388
2886
  };
2389
2887
  return n.figure.tablechart = _, _;
2390
- }, Vn = !1, Hn = (t) => {
2888
+ }, fr = !1, pr = (t) => {
2391
2889
  let n = t.find((e) => e.tagName !== "FIGURE");
2392
- !Vn && n && (Vn = !0, console.warn(`[${e}] A chart is a <${n.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`, n));
2393
- }, Un = async (e, t) => {
2394
- let n = bn(e.filter((e) => !e.hasAttribute(Dn)));
2395
- return Hn(n), await Cn(n), En(n), qe(n, t.langattribute), n;
2396
- }, Wn = (e, t) => {
2397
- let n = Z.timed("Building", e, () => Yt(e, t));
2398
- return n ? (e.setAttribute(Dn, ""), Bn(n, t)) : null;
2399
- }, Gn = async (e, t = {}) => {
2890
+ !fr && n && (fr = !0, console.warn(`[${e}] A chart is a <${n.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`, n));
2891
+ }, mr = async (e, t) => {
2892
+ let n = Gn(e.filter((e) => !e.hasAttribute(Qn) && e.tagName !== "TH"));
2893
+ pr(n), await Jn(n), Zn(n), pt(n, t.langattribute);
2894
+ for (let e of n) e.dispatchEvent(new CustomEvent("tablechart:table", { bubbles: !0 }));
2895
+ return n;
2896
+ }, hr = (e, t) => {
2897
+ let n = Q.timed("Building", e, () => _n(e, t));
2898
+ return n ? (e.setAttribute(Qn, ""), dr(n, t)) : null;
2899
+ }, gr = async (e, t = {}) => {
2400
2900
  if (e.tablechart) return e.tablechart;
2401
2901
  let n = {
2402
- ...w,
2902
+ ...O,
2403
2903
  ...t
2404
2904
  };
2405
- n.debug && (Z.enabled = !0);
2406
- let [r] = await Un([e], n);
2407
- return r ? Wn(r, n) : null;
2408
- }, Kn = async (e = {}, t = document) => {
2905
+ n.debug && (Q.enabled = !0);
2906
+ let [r] = await mr([e], n);
2907
+ return r ? hr(r, n) : null;
2908
+ }, _r = async (e = {}, t = document) => {
2409
2909
  let n = {
2410
- ...w,
2910
+ ...O,
2411
2911
  ...e
2412
2912
  };
2413
- n.debug && (Z.enabled = !0);
2414
- let r = (await Un(Array.from(t.querySelectorAll(n.selector)), n)).map((e) => Wn(e, n)).filter((e) => e !== null);
2415
- return Z.log(`Made ${r.length} chart(s).`), {
2913
+ n.debug && (Q.enabled = !0);
2914
+ let r = (await mr(Array.from(t.querySelectorAll(n.selector)), n)).map((e) => hr(e, n)).filter((e) => e !== null);
2915
+ return Q.log(`Made ${r.length} chart(s).`), {
2416
2916
  charts: r,
2417
2917
  refresh: () => {
2418
2918
  for (let e of r) e.refresh();
@@ -2422,5 +2922,4 @@ var Fe = (e) => e.map((e) => ({
2422
2922
  }
2423
2923
  };
2424
2924
  };
2425
- //#endregion
2426
- export { _ as A, u as C, d as D, t as E, w as M, v as O, k as S, h as T, q as _, bn as a, M as b, Nt as c, rn as d, sn as f, Ae as g, qe as h, Un as i, C as j, y as k, Yt as l, at as m, An as n, Cn as o, on as p, Kn as r, En as s, Gn as t, nn as u, ae as v, l as w, N as x, R as y };
2925
+ export { N as A, x as B, de as C, ie as D, W as E, e as F, O as G, C as H, f as I, v as L, S as M, E as N, I as O, p as P, t as R, J as S, re as T, b as U, s as V, D as W, lt as _, Gn as a, Ue as b, en as c, kn as d, Mn as f, ft as g, pt as h, mr as i, P as j, L as k, _n as l, Tt as m, tr as n, Jn as o, jn as p, _r as r, Zn as s, gr as t, On as u, Ze as v, le as w, Y as x, Qe as y, m as z };