@martinomagnifico/tablechart 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.6] - 2026-10-16
4
+
5
+ ### Changed
6
+
7
+ - Any key closes a tooltip, not only Escape.
8
+ - Only a mouse that moves opens a tooltip.
9
+ - A Markdown table with chart attributes is wrapped in a `figure`, not a `div`.
10
+ - The console asks for a `figure` when a chart is another element.
11
+
12
+
13
+
3
14
  ## [1.0.5] - 2026-10-16
4
15
 
5
16
  ### Added
package/README.md CHANGED
@@ -89,7 +89,7 @@ Most options can also be set on one chart with a `data-chart-*` attribute. All o
89
89
 
90
90
  `init()` returns `{ charts, refresh, destroy }`. `refresh()` lays out every chart again. `destroy()` stops watching scroll, size and language changes.
91
91
 
92
- To make a chart of one element, use `create()`. Each chart is also on its element, as `element.tablechart`.
92
+ To make a chart of one figure, use `create()`. Each chart is also on its figure, as `figure.tablechart`.
93
93
 
94
94
  ```js
95
95
  import { create } from "@martinomagnifico/tablechart";
@@ -12,7 +12,7 @@ export declare const unbuild: (state: ChartState) => void;
12
12
  export declare const setShown: (state: ChartState, shown: boolean) => void;
13
13
  //#endregion
14
14
  //#region src/js/functions/sources.d.ts
15
- /** A Markdown table, or a caption with chart attributes, is wrapped in a div with the caption and annotations beside it. */
15
+ /** A Markdown table, or a caption with chart attributes, is wrapped in a figure with the caption and annotations beside it. */
16
16
  export declare const adoptTables: (figures: HTMLElement[]) => HTMLElement[];
17
17
  /** `data-chart-src` fills the figure's table with the rows of a JSON file, keeping a header row the author wrote; a file that fails is reported. */
18
18
  export declare const loadSources: (figures: HTMLElement[]) => Promise<void>;
@@ -316,9 +316,9 @@ declare global {
316
316
  declare const entranceOf: (figure: HTMLElement, config: Config) => number;
317
317
  /** Turns elements into figures with a table and translation keys, all at once, so duplicate keys are found. */
318
318
  declare const prepare: (found: HTMLElement[], config: Config) => Promise<HTMLElement[]>;
319
- /** Makes a chart of one element; returns the existing chart if there is one, or null without data. */
319
+ /** Makes a chart of one figure; returns the existing chart if there is one, or null without data. */
320
320
  declare const create: (element: HTMLElement, options?: Partial<Config>) => Promise<TablechartChart | null>;
321
- /** Makes a chart of every element in `root` that matches the selector, skipping existing charts. */
321
+ /** Makes a chart of every figure in `root` that matches the selector, skipping existing charts. */
322
322
  declare const init: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
323
323
  //#endregion
324
324
  export { StepPlan as _, init as a, PLACED_CLASS as c, QUEUED_CLASS as d, SHOWN_CLASS as f, Series as g, Row as h, entranceOf as i, PLOT_CLASS as l, ChartState as m, TablechartInstance as n, prepare as o, defaultConfig as p, create as r, Config as s, TablechartChart as t, PRINTING_CLASS as u, stepTo as v };
@@ -1215,34 +1215,43 @@ var Te = (e) => e.map((e) => ({
1215
1215
  "--tablechart-tooltip-shadow"
1216
1216
  ], Z = null, qe, Je, Q = null, Ye = null, Xe = 0, $ = () => {
1217
1217
  clearTimeout(Xe), Z && Q && (Z.hidden = !0, Q = null, Ye = null);
1218
- }, Ze = () => {
1218
+ }, Ze = !1, Qe = !0, $e = NaN, et = NaN, tt = !1, nt = () => {
1219
+ tt || (tt = !0, document.addEventListener("pointermove", (e) => {
1220
+ e.pointerType === "mouse" && (Qe = e.screenX !== $e || e.screenY !== et, $e = e.screenX, et = e.screenY, Qe && (Ze = !1));
1221
+ }, {
1222
+ capture: !0,
1223
+ passive: !0
1224
+ }), document.addEventListener("keydown", () => {
1225
+ Ze = !0, $();
1226
+ }, !0));
1227
+ }, rt = () => {
1219
1228
  clearTimeout(Xe), Xe = window.setTimeout($, 120);
1220
- }, Qe = () => {
1229
+ }, it = () => {
1221
1230
  let e = document.createElement("div");
1222
- return e.className = Ge, e.setAttribute("aria-hidden", "true"), e.hidden = !0, qe = document.createElement("div"), Je = document.createElement("div"), Je.className = `${Ge}-arrow`, e.append(qe, Je), document.body.append(e), e.addEventListener("pointerenter", () => clearTimeout(Xe)), e.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && Ze()), document.addEventListener("keydown", (e) => e.key === "Escape" && $()), document.addEventListener("pointerdown", (t) => {
1231
+ return e.className = Ge, e.setAttribute("aria-hidden", "true"), e.hidden = !0, qe = document.createElement("div"), Je = document.createElement("div"), Je.className = `${Ge}-arrow`, e.append(qe, Je), document.body.append(e), e.addEventListener("pointerenter", () => clearTimeout(Xe)), e.addEventListener("pointerleave", (e) => e.pointerType === "mouse" && rt()), document.addEventListener("pointerdown", (t) => {
1223
1232
  let n = t.target;
1224
1233
  Q && !Q.plot.contains(n) && !e.contains(n) && $();
1225
1234
  }), window.addEventListener("scroll", $, {
1226
1235
  capture: !0,
1227
1236
  passive: !0
1228
1237
  }), window.addEventListener("resize", $), e;
1229
- }, $e = (e, t) => {
1238
+ }, at = (e, t) => {
1230
1239
  let n = t ? t.style.getPropertyValue("--step") : "x";
1231
1240
  return n === "" || Number(n) < e.step;
1232
- }, et = (e, t) => {
1241
+ }, ot = (e, t) => {
1233
1242
  let n = e.svg.querySelector(`[data-series="${t + 1}"]:not(.tablechart-hole)`);
1234
1243
  if (!n) return;
1235
1244
  let r = getComputedStyle(n);
1236
1245
  return r.fill && r.fill !== "none" ? r.fill : r.stroke;
1237
- }, tt = (e, t, n) => {
1246
+ }, st = (e, t, n) => {
1238
1247
  let r = e.series.length > 1, i = [];
1239
1248
  for (let [n, a] of e.seriesValues.entries()) {
1240
- if (!$e(e, a[t])) continue;
1249
+ if (!at(e, a[t])) continue;
1241
1250
  let o = r ? e.figure.querySelector(`.tablechart-name[data-series="${n + 1}"]`) : null;
1242
1251
  i.push({
1243
1252
  name: r ? o?.textContent ?? e.series[n].name : "",
1244
1253
  value: a[t].textContent ?? "",
1245
- colour: r ? et(e, n) : void 0,
1254
+ colour: r ? ot(e, n) : void 0,
1246
1255
  sample: o ? {
1247
1256
  marker: o.dataset.marker ?? null,
1248
1257
  open: o.hasAttribute("data-open"),
@@ -1252,11 +1261,11 @@ var Te = (e) => e.map((e) => ({
1252
1261
  });
1253
1262
  }
1254
1263
  let a = e.totals[t];
1255
- return i.length > 1 && $e(e, a) && i.push({
1264
+ return i.length > 1 && at(e, a) && i.push({
1256
1265
  name: n.totallabel,
1257
1266
  value: a.textContent ?? ""
1258
1267
  }), i;
1259
- }, nt = (e, t) => {
1268
+ }, ct = (e, t) => {
1260
1269
  if (e.type.centre && e.values[t]) return e.values[t].getBoundingClientRect();
1261
1270
  let n = e.svg.querySelectorAll(`[data-row="${t + 1}"]:not(.tablechart-connector, .tablechart-leader)`), r = null;
1262
1271
  for (let e of n) {
@@ -1271,11 +1280,11 @@ var Te = (e) => e.map((e) => ({
1271
1280
  100
1272
1281
  ];
1273
1282
  return new DOMRect(i.left + i.width * a / 100, i.top + i.height * o / 100, i.width * s / 100, i.height * c / 100);
1274
- }, rt = (e, t, n) => {
1283
+ }, lt = (e, t, n) => {
1275
1284
  if (clearTimeout(Xe), Q === e && Ye === t) return;
1276
- let r = (e.type.tooltip ?? tt)(e, t, n);
1285
+ let r = (e.type.tooltip ?? st)(e, t, n);
1277
1286
  if (!r.length) return $();
1278
- Q && Q !== e && $(), Z ?? (Z = Qe());
1287
+ Q && Q !== e && $(), Z ?? (Z = it());
1279
1288
  let i = (e, t, n, r = !1, i) => {
1280
1289
  let a = document.createElement("div");
1281
1290
  if (a.className = `${Ge}-line`, n) {
@@ -1296,10 +1305,10 @@ var Te = (e) => e.map((e) => ({
1296
1305
  let t = s.getPropertyValue(e).trim();
1297
1306
  t ? Z.style.setProperty(e, t) : Z.style.removeProperty(e);
1298
1307
  }
1299
- Z.style.setProperty("--_color", s.color), Z.style.colorScheme = s.colorScheme, Z.style.fontFamily = s.fontFamily, Z.style.fontSize = s.fontSize, Q = e, Ye = t, Z.hidden = !1, Z.style.left = "0px", We(Z, Je, nt(e, t));
1300
- }, it = (e, t, n = !1) => {
1308
+ Z.style.setProperty("--_color", s.color), Z.style.colorScheme = s.colorScheme, Z.style.fontFamily = s.fontFamily, Z.style.fontSize = s.fontSize, Q = e, Ye = t, Z.hidden = !1, Z.style.left = "0px", We(Z, Je, ct(e, t));
1309
+ }, ut = (e, t, n = !1) => {
1301
1310
  let { plot: r } = e;
1302
- r.setAttribute("data-hover", "");
1311
+ r.setAttribute("data-hover", ""), nt();
1303
1312
  let i = (t) => {
1304
1313
  if (e.rowAt) {
1305
1314
  let n = r.getBoundingClientRect(), i = n.width / r.offsetWidth || 1;
@@ -1312,11 +1321,13 @@ var Te = (e) => e.map((e) => ({
1312
1321
  else if (t.getAttribute("data-row") === String(e + 1)) return !0;
1313
1322
  return !1;
1314
1323
  }, s = null, c = (a) => {
1324
+ if (a.type === "pointerdown") Ze = !1;
1325
+ else if (a.pointerType === "mouse" && (!Qe || Ze)) return;
1315
1326
  if (!r.classList.contains("is-placed") || !e.figure.classList.contains("is-shown")) return;
1316
1327
  if (n && !e.figure.hasAttribute("data-left-out")) return Q === e ? $() : void 0;
1317
1328
  let c = i(a);
1318
- if (s = c, c === null || o(c)) return Q === e ? Ze() : void 0;
1319
- rt(e, c, t);
1329
+ if (s = c, c === null || o(c)) return Q === e ? rt() : void 0;
1330
+ lt(e, c, t);
1320
1331
  }, l = (t) => {
1321
1332
  let n = t.target;
1322
1333
  return e.svg.contains(n) && n.hasAttribute("data-row") ? n : null;
@@ -1330,42 +1341,42 @@ var Te = (e) => e.map((e) => ({
1330
1341
  if (!r) return;
1331
1342
  a.delete(r);
1332
1343
  let i = Number(r.getAttribute("data-row")) - 1;
1333
- s === i && !o(i) && rt(e, i, t);
1344
+ s === i && !o(i) && !Ze && lt(e, i, t);
1334
1345
  };
1335
1346
  e.svg.addEventListener("transitionend", u), e.svg.addEventListener("transitioncancel", u), r.addEventListener("pointermove", c), r.addEventListener("pointerdown", c), r.addEventListener("pointerleave", (t) => {
1336
- t.pointerType === "mouse" && (s = null, Q === e && Ze());
1347
+ t.pointerType === "mouse" && (s = null, Q === e && rt());
1337
1348
  });
1338
- }, at = (e) => {
1349
+ }, dt = (e) => {
1339
1350
  Q === e && $();
1340
- }, ot = {
1351
+ }, ft = {
1341
1352
  area: Oe,
1342
1353
  bar: pe,
1343
1354
  column: me,
1344
1355
  donut: _e,
1345
1356
  line: De,
1346
1357
  waterfall: je
1347
- }, st = {
1358
+ }, pt = {
1348
1359
  "axis-break": M,
1349
1360
  trend: te,
1350
1361
  bracket: H
1351
- }, ct = Object.keys(st), lt = (e) => {
1362
+ }, mt = Object.keys(pt), ht = (e) => {
1352
1363
  let t = "";
1353
1364
  for (let n = e.previousSibling; n && (t = (n.textContent ?? "") + t, !t.trim()); n = n.previousSibling);
1354
1365
  return t.trim();
1355
- }, ut = [
1366
+ }, gt = [
1356
1367
  "straight",
1357
1368
  "step",
1358
1369
  "smooth"
1359
- ], dt = (e, t) => {
1370
+ ], _t = (e, t) => {
1360
1371
  let n = e.dataset.chartShape;
1361
- return n && ut.includes(n) ? n : ut.includes(t.shape) ? t.shape : "straight";
1362
- }, ft = (e) => {
1372
+ return n && gt.includes(n) ? n : gt.includes(t.shape) ? t.shape : "straight";
1373
+ }, vt = (e) => {
1363
1374
  for (let t of e.querySelectorAll("br")) {
1364
- if (t.previousElementSibling?.classList.contains("tablechart-sr") || /[.!?:;,…]$/.test(lt(t))) continue;
1375
+ if (t.previousElementSibling?.classList.contains("tablechart-sr") || /[.!?:;,…]$/.test(ht(t))) continue;
1365
1376
  let e = document.createElement("span");
1366
1377
  e.className = p, e.textContent = ". ", t.before(e);
1367
1378
  }
1368
- }, pt = (e, t, n) => {
1379
+ }, yt = (e, t, n) => {
1369
1380
  let r = e.querySelector("table");
1370
1381
  if (!r) return null;
1371
1382
  let i = r.querySelector("tfoot [data-chart-total]");
@@ -1376,22 +1387,22 @@ var Te = (e) => e.map((e) => ({
1376
1387
  s && n.langattribute && o.setAttribute(n.langattribute, `${s}-total`);
1377
1388
  let c = a.insertCell();
1378
1389
  return c.setAttribute("data-chart-total", ""), c.dataset.value = t.dataset.value ?? "0", a.prepend(o), c;
1379
- }, mt = 0, ht = (e) => {
1390
+ }, bt = 0, xt = (e) => {
1380
1391
  let t = e.querySelector(":scope > figcaption");
1381
1392
  if (!t) return;
1382
- ft(t);
1393
+ vt(t);
1383
1394
  let n = (e) => e.hasAttribute("aria-label") || e.hasAttribute("aria-labelledby"), r = (e) => {
1384
- t.id || (t.id = `tablechart-caption-${++mt}`), e.setAttribute("aria-labelledby", t.id);
1395
+ t.id || (t.id = `tablechart-caption-${++bt}`), e.setAttribute("aria-labelledby", t.id);
1385
1396
  };
1386
1397
  e.tagName === "FIGURE" && !n(e) && r(e);
1387
1398
  let i = e.querySelector("table");
1388
1399
  i && !n(i) && !i.querySelector(":scope > caption") && r(i);
1389
- }, gt = (r, i, a = null) => {
1390
- let o = a ?? (r.getAttribute("data-chart") || "column"), s = ot[o];
1391
- if (!s) return console.warn(`[${e}] Unknown chart type "${o}". Known types: ${Object.keys(ot).join(", ")}.`), r.setAttribute("data-chart-empty", ""), null;
1400
+ }, St = (r, i, a = null) => {
1401
+ let o = a ?? (r.getAttribute("data-chart") || "column"), s = ft[o];
1402
+ if (!s) return console.warn(`[${e}] Unknown chart type "${o}". Known types: ${Object.keys(ft).join(", ")}.`), r.setAttribute("data-chart-empty", ""), null;
1392
1403
  let l = Ne(r, i.langattribute);
1393
- if (!l.length) return console.warn(`[${e}] A chart has no rows in its table, so there is nothing to draw.`), r.setAttribute("data-chart-empty", ""), null;
1394
- ht(r);
1404
+ if (!l.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;
1405
+ xt(r);
1395
1406
  let d = Ie(r, l, i.langattribute);
1396
1407
  d.length > 1 && !s.series && (console.warn(`[${e}] A ${o} chart uses only the first of its ${d.length} value columns.`), d = d.slice(0, 1));
1397
1408
  let f = d.length > 1;
@@ -1419,7 +1430,7 @@ var Te = (e) => e.map((e) => ({
1419
1430
  let n = E("tablechart-name", D ?? h);
1420
1431
  D && (n.dataset.place = "legend");
1421
1432
  let a = s.legend ?? s.swatch;
1422
- if (a && (n.dataset.swatch = a), n.textContent = e.name, !a && dt(r, i) !== "step") {
1433
+ if (a && (n.dataset.swatch = a), n.textContent = e.name, !a && _t(r, i) !== "step") {
1423
1434
  let e = ye(d, t);
1424
1435
  n.dataset.marker = e.shape, n.toggleAttribute("data-open", e.open);
1425
1436
  }
@@ -1429,7 +1440,7 @@ var Te = (e) => e.map((e) => ({
1429
1440
  let e = l.find((e) => e.isTotal), t = e ? e.value : l.reduce((e, t) => e + Math.abs(t.value), 0);
1430
1441
  k.dataset.value = String(t), e && (k.dataset.decimals = String(P(e.number)));
1431
1442
  }
1432
- let A = k && !l.some((e) => e.isTotal) ? pt(r, k, i) : null, j = s.categories === "beside", M = document.createElement("div");
1443
+ let A = k && !l.some((e) => e.isTotal) ? yt(r, k, i) : null, j = s.categories === "beside", M = document.createElement("div");
1433
1444
  M.className = "tablechart-categories", M.setAttribute("aria-hidden", "true"), M.inert = !0, j ? M.dataset.place = "beside" : s.centre && (M.dataset.place = "key"), M.style.setProperty("--_columns", String(l.length));
1434
1445
  let F = 0;
1435
1446
  for (let [e, t] of l.entries()) {
@@ -1449,7 +1460,7 @@ var Te = (e) => e.map((e) => ({
1449
1460
  hint: L && `${L}-step`
1450
1461
  }, i.langattribute) : null;
1451
1462
  R && r.appendChild(R);
1452
- let z = r.getAttribute("data-chart-table"), B = z && vt.includes(z) ? z : i.table;
1463
+ let z = r.getAttribute("data-chart-table"), B = z && wt.includes(z) ? z : i.table;
1453
1464
  if (B === "never") r.removeAttribute("data-table");
1454
1465
  else {
1455
1466
  r.setAttribute("data-table", B);
@@ -1457,8 +1468,8 @@ var Te = (e) => e.map((e) => ({
1457
1468
  e && r.append(e);
1458
1469
  }
1459
1470
  let V = Array.from(r.querySelectorAll("[data-annotation]")).map((t) => {
1460
- let n = t.getAttribute("data-annotation"), r = st[n];
1461
- if (!r) return console.warn(`[${e}] Unknown annotation "${n}". Known annotations: ${Object.keys(st).join(", ")}.`), null;
1471
+ let n = t.getAttribute("data-annotation"), r = pt[n];
1472
+ if (!r) return console.warn(`[${e}] Unknown annotation "${n}". Known annotations: ${Object.keys(pt).join(", ")}.`), null;
1462
1473
  let i = Number.parseInt(t.getAttribute("data-series") ?? "1", 10), a = i >= 1 && i <= d.length ? i - 1 : 0;
1463
1474
  return i !== a + 1 && console.warn(`[${e}] An annotation reads line ${i}, which is not there; it reads line 1.`), {
1464
1475
  spec: t,
@@ -1468,7 +1479,7 @@ var Te = (e) => e.map((e) => ({
1468
1479
  after: l.length
1469
1480
  };
1470
1481
  }).filter((e) => e !== null);
1471
- i.animate && r.setAttribute("data-animate", bt(r, o, i, !!I));
1482
+ i.animate && r.setAttribute("data-animate", Et(r, o, i, !!I));
1472
1483
  let H = {
1473
1484
  figure: r,
1474
1485
  plot: h,
@@ -1498,31 +1509,31 @@ var Te = (e) => e.map((e) => ({
1498
1509
  t && He(H, H.step + (t === "next" ? 1 : -1));
1499
1510
  }), He(H, 0, !0);
1500
1511
  let U = r.getAttribute("data-chart-tooltip") ?? r.getAttribute("data-chart-hover"), ee = U === "false" ? !1 : U === "auto" ? "auto" : U !== null || i.hover !== !1 && i.tooltip;
1501
- return ee && it(H, i, ee === "auto"), Tt(H, i), H;
1502
- }, _t = {
1512
+ return ee && ut(H, i, ee === "auto"), jt(H, i), H;
1513
+ }, Ct = {
1503
1514
  grow: "grow",
1504
1515
  sweep: "sweep"
1505
- }, vt = [
1516
+ }, wt = [
1506
1517
  "never",
1507
1518
  "auto",
1508
1519
  "print",
1509
1520
  "always"
1510
- ], yt = {
1511
- ..._t,
1521
+ ], Tt = {
1522
+ ...Ct,
1512
1523
  up: "grow",
1513
1524
  across: "sweep"
1514
- }, bt = (e, t, n, r) => {
1515
- let i = t === "line" || t === "area", a = i ? yt : _t, o = a[e.getAttribute("data-chart-animate") ?? ""] ?? a[String(n.animate)];
1525
+ }, Et = (e, t, n, r) => {
1526
+ let i = t === "line" || t === "area", a = i ? Tt : Ct, o = a[e.getAttribute("data-chart-animate") ?? ""] ?? a[String(n.animate)];
1516
1527
  return i ? r ? "sweep" : o ?? "sweep" : t === "donut" || t === "waterfall" ? o ?? "grow" : "grow";
1517
- }, xt = (e) => {
1528
+ }, Dt = (e) => {
1518
1529
  let t = getComputedStyle(e), n = (t.getPropertyValue("--tablechart-value-align") || t.getPropertyValue("--tablechart-inside-align")).trim();
1519
1530
  return n === "start" || n === "center" || n === "end" ? n : null;
1520
- }, St = (e, t, n, r) => {
1531
+ }, Ot = (e, t, n, r) => {
1521
1532
  let i = getComputedStyle(e), a = (i.getPropertyValue(n).trim() || r).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);
1522
1533
  if (!a) return null;
1523
1534
  let o = Number(a[1]);
1524
1535
  return a[2] === "%" ? o / 100 * _ : o * (a[2] === "em" ? Number.parseFloat(i.fontSize) : a[2] === "rem" ? Number.parseFloat(getComputedStyle(document.documentElement).fontSize) : 1) * t;
1525
- }, Ct = (e, t) => St(e, t, "--tablechart-bar-max", "60px") ?? Infinity, wt = (t, n) => {
1536
+ }, kt = (e, t) => Ot(e, t, "--tablechart-bar-max", "60px") ?? Infinity, At = (t, n) => {
1526
1537
  let { plot: r, svg: i, rows: a, type: o, values: s, series: c, seriesValues: u, names: d, annotations: p } = t, m = r.clientWidth;
1527
1538
  if (!m) return !1;
1528
1539
  let h = _ / m, g = Number.parseFloat(t.figure.dataset.chartAspect ?? ""), v = _ * (g > 0 ? g : o.aspect ?? n.aspect);
@@ -1535,7 +1546,7 @@ var Te = (e) => e.map((e) => ({
1535
1546
  ...t.categories,
1536
1547
  ...p.map((e) => e.badge)
1537
1548
  ]);
1538
- let y = (s[0] ? W(s[0]).height : 0) * h, b = p[0]?.badge ? W(p[0].badge).height * h : 0, x = Math.max(v, St(t.figure, h, "--tablechart-min-height", "200px") ?? 0, o.minHeight?.({
1549
+ let y = (s[0] ? W(s[0]).height : 0) * h, b = p[0]?.badge ? W(p[0].badge).height * h : 0, x = Math.max(v, Ot(t.figure, h, "--tablechart-min-height", "200px") ?? 0, o.minHeight?.({
1539
1550
  labelHeight: y,
1540
1551
  nameHeight: Math.max(0, N(t.categories.map((e) => W(e).height))) * h,
1541
1552
  unit: h,
@@ -1587,7 +1598,7 @@ var Te = (e) => e.map((e) => ({
1587
1598
  share: s
1588
1599
  } : console.warn(`[${e}] This kind of chart cannot break its scale.`);
1589
1600
  }
1590
- let H = V ? V.gap : null, U = (V && St(t.figure, h, "--tablechart-break-gap", "")) ?? 13, G = x - M, te = F - I || 1, ne = (e) => G - (e - I) / te * P;
1601
+ let H = V ? V.gap : null, U = (V && Ot(t.figure, h, "--tablechart-break-gap", "")) ?? 13, G = x - M, te = F - I || 1, ne = (e) => G - (e - I) / te * P;
1591
1602
  if (V) {
1592
1603
  let { lo: e, hi: t, gap: n, share: r } = V, i = P * r, a = (P - i - U) / (e + (F - t)), o = i / (t - e);
1593
1604
  ne = (r) => r <= e ? G - r * a : r <= n ? G - e * a - (r - e) * o : r <= t ? G - e * a - (r - e) * o - U : G - e * a - i - U - (r - t) * a;
@@ -1613,8 +1624,8 @@ var Te = (e) => e.map((e) => ({
1613
1624
  segments: T,
1614
1625
  cx: oe,
1615
1626
  y: ne,
1616
- barWidth: Math.min(K * n.barfill, Ct(t.figure, h)),
1617
- barMax: Ct(t.figure, h),
1627
+ barWidth: Math.min(K * n.barfill, kt(t.figure, h)),
1628
+ barMax: kt(t.figure, h),
1618
1629
  height: x,
1619
1630
  unit: h,
1620
1631
  labelHeight: y,
@@ -1622,12 +1633,12 @@ var Te = (e) => e.map((e) => ({
1622
1633
  after: a.length,
1623
1634
  note: 0,
1624
1635
  labels: t.figure.dataset.chartLabels === "inside" || t.figure.dataset.chartLabels !== "outside" && n.labels === "inside" ? "inside" : "outside",
1625
- insideAlign: xt(t.figure),
1636
+ insideAlign: Dt(t.figure),
1626
1637
  breakAt: H,
1627
1638
  squeeze: V,
1628
1639
  breakGap: U,
1629
1640
  stacked: t.stacked,
1630
- shape: dt(t.figure, n),
1641
+ shape: _t(t.figure, n),
1631
1642
  totals: t.totals,
1632
1643
  svg: i,
1633
1644
  plot: r,
@@ -1694,7 +1705,7 @@ var Te = (e) => e.map((e) => ({
1694
1705
  return t.some((e) => pe(e) && Number(e.dataset.row) <= n && n <= Number(e.dataset.rowEnd ?? e.dataset.row));
1695
1706
  };
1696
1707
  return t.figure.toggleAttribute("data-left-out", [...u, t.totals].some((e) => e.some((t) => !fe(t) && !pe(t) && !me(t, e)))), !0;
1697
- }, Tt = (e, t) => {
1708
+ }, jt = (e, t) => {
1698
1709
  let n = [
1699
1710
  ...e.seriesValues.flat(),
1700
1711
  ...e.totals,
@@ -1712,29 +1723,29 @@ var Te = (e) => e.map((e) => ({
1712
1723
  e.className = "tablechart-minus", e.textContent = o, r.prepend(e);
1713
1724
  }
1714
1725
  }
1715
- }, Et = (e) => {
1716
- at(e), e.plot.remove(), e.categories[0]?.parentElement?.remove(), e.figure.querySelector(`:scope > .${c}`)?.remove(), e.controls?.remove();
1717
- }, Dt = (e, t) => {
1726
+ }, Mt = (e) => {
1727
+ dt(e), e.plot.remove(), e.categories[0]?.parentElement?.remove(), e.figure.querySelector(`:scope > .${c}`)?.remove(), e.controls?.remove();
1728
+ }, Nt = (e, t) => {
1718
1729
  e.figure.classList.toggle(m, t);
1719
- }, Ot = (e) => e === "id" || e === "style" || e.startsWith("data-chart"), kt = /^\s*(?:Table)?:\s+/, At = (e) => e?.tagName === "P" && kt.test(e.textContent ?? ""), jt = (e) => {
1730
+ }, Pt = (e) => e === "id" || e === "style" || e.startsWith("data-chart"), Ft = /^\s*(?:Table)?:\s+/, It = (e) => e?.tagName === "P" && Ft.test(e.textContent ?? ""), Lt = (e) => {
1720
1731
  let t = document.createElement("figcaption");
1721
1732
  for (let { name: n, value: r } of Array.from(e.attributes)) t.setAttribute(n, r);
1722
1733
  let n = e.firstChild;
1723
- n?.nodeType === Node.TEXT_NODE && (n.textContent = (n.textContent ?? "").replace(kt, ""), n.textContent || n.remove());
1734
+ n?.nodeType === Node.TEXT_NODE && (n.textContent = (n.textContent ?? "").replace(Ft, ""), n.textContent || n.remove());
1724
1735
  let r = Array.from(e.childNodes), i = r.findIndex((e) => e.nodeName === "BR");
1725
1736
  if (t.append(...i === -1 ? r : r.slice(0, i + 1)), i !== -1 && i < r.length - 1) {
1726
1737
  let e = document.createElement("span");
1727
1738
  e.append(...r.slice(i + 1)), t.append(e);
1728
1739
  }
1729
1740
  return e.remove(), t;
1730
- }, Mt = /^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/, Nt = (e) => {
1731
- let t = Vt(e);
1741
+ }, Rt = /^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/, zt = (e) => {
1742
+ let t = qt(e);
1732
1743
  return t?.tagName === "P" ? t : e;
1733
- }, Pt = (e) => {
1734
- let t = Nt(e).firstChild;
1744
+ }, Bt = (e) => {
1745
+ let t = zt(e).firstChild;
1735
1746
  if (t?.nodeType !== Node.TEXT_NODE) return null;
1736
- let n = Mt.exec(t.textContent ?? "");
1737
- if (!n || !ct.includes(n[1]) || !n[3] && t.nextSibling) return null;
1747
+ let n = Rt.exec(t.textContent ?? "");
1748
+ if (!n || !mt.includes(n[1]) || !n[3] && t.nextSibling) return null;
1738
1749
  let r = n[2].trim().split(/\s+/).filter(Boolean).map((e) => e.split("="));
1739
1750
  return {
1740
1751
  name: n[1],
@@ -1742,11 +1753,11 @@ var Te = (e) => e.map((e) => ({
1742
1753
  text: t,
1743
1754
  length: n[0].length
1744
1755
  };
1745
- }, Ft = (e) => {
1756
+ }, Vt = (e) => {
1746
1757
  if (e?.tagName !== "UL" && e?.tagName !== "OL") return null;
1747
- let t = Array.from(e.children), n = t.map((e) => e.hasAttribute("data-annotation") ? null : Pt(e));
1758
+ let t = Array.from(e.children), n = t.map((e) => e.hasAttribute("data-annotation") ? null : Bt(e));
1748
1759
  return !t.length || t.some((e, t) => !n[t] && !e.hasAttribute("data-annotation")) ? null : (t.forEach((e, t) => {
1749
- let r = n[t], i = Nt(e);
1760
+ let r = n[t], i = zt(e);
1750
1761
  if (i !== e && i.replaceWith(...i.childNodes), r) {
1751
1762
  e.setAttribute("data-annotation", r.name);
1752
1763
  for (let [t, n] of r.options) e.setAttribute(`data-${t}`, n);
@@ -1757,18 +1768,18 @@ var Te = (e) => e.map((e) => ({
1757
1768
  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));
1758
1769
  });
1759
1770
  }), e.classList.add("chart-annotations"), e);
1760
- }, It = (e, t) => {
1761
- for (let { name: n, value: r } of Array.from(e.attributes)) (n === "class" || Ot(n)) && (t.setAttribute(n, r), e.removeAttribute(n));
1762
- }, Lt = (e) => e.map((e) => {
1763
- let t = e.closest("p"), n = At(t) ? t : e;
1771
+ }, Ht = (e, t) => {
1772
+ for (let { name: n, value: r } of Array.from(e.attributes)) (n === "class" || Pt(n)) && (t.setAttribute(n, r), e.removeAttribute(n));
1773
+ }, Ut = (e) => e.map((e) => {
1774
+ let t = e.closest("p"), n = It(t) ? t : e;
1764
1775
  if (n.tagName !== "TABLE" && n.tagName !== "P") return n;
1765
- let r = document.createElement("div");
1766
- It(e, r), e.classList.length || e.removeAttribute("class");
1767
- let i = n.tagName === "TABLE" ? n : null, a = n.previousElementSibling, o = n.nextElementSibling, s = i ? At(a) ? a : At(o) ? o : null : n;
1776
+ let r = document.createElement("figure");
1777
+ Ht(e, r), e.classList.length || e.removeAttribute("class");
1778
+ let i = n.tagName === "TABLE" ? n : null, a = n.previousElementSibling, o = n.nextElementSibling, s = i ? It(a) ? a : It(o) ? o : null : n;
1768
1779
  i && s === o && (o = o?.nextElementSibling ?? null);
1769
- let c = o?.classList.contains("chart-annotations") ? o : Ft(o);
1770
- return n.replaceWith(r), s && r.append(jt(s)), i && r.append(i), c && r.append(c), X?.log?.(`A ${i ? "table" : "caption"} with chart attributes was wrapped in a figure of its own`), r;
1771
- }), Rt = (e, t, n, r = document.createElement("table")) => {
1780
+ let c = o?.classList.contains("chart-annotations") ? o : Vt(o);
1781
+ return n.replaceWith(r), s && r.append(Lt(s)), i && r.append(i), c && r.append(c), X?.log?.(`A ${i ? "table" : "caption"} with chart attributes was wrapped in a figure of its own`), r;
1782
+ }), Wt = (e, t, n, r = document.createElement("table")) => {
1772
1783
  for (let e of r.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr")) e.remove();
1773
1784
  if (!r.tHead && (t.length || n)) {
1774
1785
  let e = r.createTHead().insertRow(), i = document.createElement("th");
@@ -1788,7 +1799,7 @@ var Te = (e) => e.map((e) => ({
1788
1799
  for (let n of t.values ?? [t.value ?? null]) e.insertCell().textContent = n === null ? "" : String(n);
1789
1800
  }
1790
1801
  return r;
1791
- }, zt = (e) => {
1802
+ }, Gt = (e) => {
1792
1803
  if (!e || typeof e != "object") return;
1793
1804
  let t = Object.entries(e), n = (e) => e === null || typeof e == "string" || typeof e == "number";
1794
1805
  if (t.length && t.every(([, e]) => n(e) || Array.isArray(e) && e.every(n))) return t.map(([e, t]) => Array.isArray(t) ? {
@@ -1798,16 +1809,16 @@ var Te = (e) => e.map((e) => ({
1798
1809
  label: e,
1799
1810
  value: t
1800
1811
  });
1801
- }, Bt = async (t) => {
1812
+ }, Kt = async (t) => {
1802
1813
  await Promise.all(t.filter((e) => e.hasAttribute("data-chart-src")).map(async (t) => {
1803
1814
  let n = t.getAttribute("data-chart-src"), r = Array.from(t.querySelectorAll("table")).find((e) => e.tHead) ?? null;
1804
1815
  for (let e of t.querySelectorAll("table")) e !== r && e.remove();
1805
1816
  try {
1806
1817
  let e = await fetch(n);
1807
1818
  if (!e.ok) throw Error(`${e.status} ${e.statusText}`);
1808
- let i = await e.json(), a = Array.isArray(i) ? i : i?.rows ? Array.isArray(i.rows) ? i.rows : zt(i.rows) : zt(i);
1819
+ let i = await e.json(), a = Array.isArray(i) ? i : i?.rows ? Array.isArray(i.rows) ? i.rows : Gt(i.rows) : Gt(i);
1809
1820
  if (!Array.isArray(a)) throw Error("no rows in it: a list of rows, an object with rows, or names with their values");
1810
- let o = Rt(a, Array.isArray(i?.series) ? i.series.map(String) : [], typeof i?.label == "string" ? i.label : "", r ?? void 0);
1821
+ let o = Wt(a, Array.isArray(i?.series) ? i.series.map(String) : [], typeof i?.label == "string" ? i.label : "", r ?? void 0);
1811
1822
  if (!r) {
1812
1823
  let e = t.querySelector(":scope > figcaption");
1813
1824
  e ? e.after(o) : t.prepend(o);
@@ -1818,10 +1829,10 @@ var Te = (e) => e.map((e) => ({
1818
1829
  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." : ""));
1819
1830
  }
1820
1831
  }));
1821
- }, Vt = (e) => {
1832
+ }, qt = (e) => {
1822
1833
  let t = Array.from(e.childNodes).filter((e) => e.nodeType === Node.ELEMENT_NODE || e.nodeType === Node.TEXT_NODE && e.textContent?.trim());
1823
1834
  return t.length === 1 && t[0] instanceof HTMLElement ? t[0] : null;
1824
- }, Ht = "strong, b, span.total", Ut = (e) => {
1835
+ }, Jt = "strong, b, span.total", Yt = (e) => {
1825
1836
  for (let t of e) {
1826
1837
  for (let e of t.querySelectorAll("tbody tr")) {
1827
1838
  let t = e.cells[0];
@@ -1829,16 +1840,16 @@ var Te = (e) => e.map((e) => ({
1829
1840
  let n = document.createElement("th");
1830
1841
  for (let { name: e, value: r } of Array.from(t.attributes)) n.setAttribute(e, r);
1831
1842
  n.append(...t.childNodes), t.replaceWith(n);
1832
- for (let t = Vt(n); t?.matches(Ht); t = Vt(n)) e.dataset.kind = "total", t.replaceWith(...t.childNodes);
1843
+ for (let t = qt(n); t?.matches(Jt); t = qt(n)) e.dataset.kind = "total", t.replaceWith(...t.childNodes);
1833
1844
  }
1834
1845
  let e = Array.from(t.querySelector("thead tr:last-child")?.children ?? []);
1835
- for (let t of e.slice(1)) for (let e = Vt(t); e?.matches(Ht); e = Vt(t)) t.setAttribute("data-kind", "focus"), e.replaceWith(...e.childNodes);
1846
+ for (let t of e.slice(1)) for (let e = qt(t); e?.matches(Jt); e = qt(t)) t.setAttribute("data-kind", "focus"), e.replaceWith(...e.childNodes);
1836
1847
  }
1837
- }, Wt = "data-chart-made", Gt = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, Kt = (e) => new Promise((t) => setTimeout(t, e)), qt = (e, t) => {
1848
+ }, Xt = "data-chart-made", Zt = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches, Qt = (e) => new Promise((t) => setTimeout(t, e)), $t = (e, t) => {
1838
1849
  let n = Number.parseFloat(e.dataset.chartEntrance ?? ""), r = Number.isFinite(n) ? n : t.entrance;
1839
1850
  return Math.min(Math.max(r, 0), 1);
1840
- }, Jt = async (e, t) => {
1841
- if (Gt()) return;
1851
+ }, en = async (e, t) => {
1852
+ if (Zt()) return;
1842
1853
  await new Promise(requestAnimationFrame);
1843
1854
  let n = e.getAnimations().filter((e) => e instanceof CSSAnimation);
1844
1855
  for (let t = e.parentElement; t && t !== document.body; t = t.parentElement) n.push(...t.getAnimations());
@@ -1849,11 +1860,11 @@ var Te = (e) => e.map((e) => ({
1849
1860
  let a = Number(n.delay ?? 0) + i * t;
1850
1861
  r = Math.max(r, a - Number(e.currentTime ?? 0));
1851
1862
  }
1852
- r > 0 && await Kt(r);
1853
- }, Yt = (e) => {
1863
+ r > 0 && await Qt(r);
1864
+ }, tn = (e) => {
1854
1865
  for (let t = e; t && t !== document.body; t = t.parentElement) if (getComputedStyle(t).opacity === "0") return t;
1855
1866
  return null;
1856
- }, Xt = (e) => new Promise((t) => {
1867
+ }, nn = (e) => new Promise((t) => {
1857
1868
  let n = ["animationstart", "transitionrun"], r = () => {
1858
1869
  for (let e of n) document.removeEventListener(e, i, !0);
1859
1870
  a.disconnect(), t();
@@ -1867,41 +1878,41 @@ var Te = (e) => e.map((e) => ({
1867
1878
  attributes: !0,
1868
1879
  attributeFilter: ["class", "style"]
1869
1880
  });
1870
- }), Zt = /* @__PURE__ */ new Set(), Qt = null, $t = (e) => {
1871
- Zt.add(e), !Qt && (Qt = new MutationObserver(() => {
1872
- for (let e of Zt) e.relabel();
1881
+ }), rn = /* @__PURE__ */ new Set(), an = null, on = (e) => {
1882
+ rn.add(e), !an && (an = new MutationObserver(() => {
1883
+ for (let e of rn) e.relabel();
1873
1884
  requestAnimationFrame(() => requestAnimationFrame(() => {
1874
- for (let e of Zt) e.refresh();
1885
+ for (let e of rn) e.refresh();
1875
1886
  }));
1876
- }), Qt.observe(document.documentElement, {
1887
+ }), an.observe(document.documentElement, {
1877
1888
  attributes: !0,
1878
1889
  attributeFilter: ["lang"]
1879
1890
  }));
1880
- }, en = (e) => {
1881
- Zt.delete(e), !Zt.size && Qt && (Qt.disconnect(), Qt = null);
1882
- }, tn = ["column", "bar"], nn = (e) => {
1891
+ }, sn = (e) => {
1892
+ rn.delete(e), !rn.size && an && (an.disconnect(), an = null);
1893
+ }, cn = ["column", "bar"], ln = (e) => {
1883
1894
  let t = e.getAttribute("data-chart") || "column";
1884
- if (!tn.includes(t)) return null;
1895
+ if (!cn.includes(t)) return null;
1885
1896
  let n = getComputedStyle(e).getPropertyValue("--tablechart-type").trim();
1886
- return tn.includes(n) ? n : t;
1887
- }, rn = (e, t) => {
1888
- let n = e, r = nn(n.figure), i = null, a = !1, o = !1, s = async () => {
1889
- if (!t.animate) return Dt(n, !0);
1897
+ return cn.includes(n) ? n : t;
1898
+ }, un = (e, t) => {
1899
+ let n = e, r = ln(n.figure), i = null, a = !1, o = !1, s = async () => {
1900
+ if (!t.animate) return Nt(n, !0);
1890
1901
  let e = n.figure.classList.contains("is-shown");
1891
1902
  if (a && i !== null && !e && !o) {
1892
1903
  o = !0;
1893
- let e = Gt() ? null : Yt(n.figure);
1894
- e && await Xt(e), await Jt(n.figure, qt(n.figure, t)), o = !1, (a || !t.replay) && Dt(n, !0);
1895
- } else !a && t.replay && e && Dt(n, !1);
1904
+ let e = Zt() ? null : tn(n.figure);
1905
+ e && await nn(e), await en(n.figure, $t(n.figure, t)), o = !1, (a || !t.replay) && Nt(n, !0);
1906
+ } else !a && t.replay && e && Nt(n, !1);
1896
1907
  }, c = () => {
1897
- let e = nn(n.figure);
1908
+ let e = ln(n.figure);
1898
1909
  if (!e || e === r) return;
1899
- let a = X.timed("Building", n.figure, () => gt(n.figure, t, e));
1900
- a && (Et(n), He(a, n.step, !0), n = a, r = e, i = null);
1910
+ let a = X.timed("Building", n.figure, () => St(n.figure, t, e));
1911
+ a && (Mt(n), He(a, n.step, !0), n = a, r = e, i = null);
1901
1912
  }, l = () => {
1902
1913
  c();
1903
1914
  let e = n.plot.clientWidth;
1904
- e && e !== i && X.timed("Layout", n.figure, () => wt(n, t)) && (i = e, s());
1915
+ e && e !== i && X.timed("Layout", n.figure, () => At(n, t)) && (i = e, s());
1905
1916
  }, u = !1, d = new ResizeObserver(() => {
1906
1917
  u || (u = !0, requestAnimationFrame(() => {
1907
1918
  u = !1, l();
@@ -1909,14 +1920,14 @@ var Te = (e) => e.map((e) => ({
1909
1920
  }), f = new IntersectionObserver((e) => {
1910
1921
  for (let t of e) a = t.isIntersecting, s();
1911
1922
  }, { threshold: t.threshold }), p = () => {
1912
- n.figure.classList.add(h), Dt(n, !0), n.figure.offsetWidth;
1923
+ n.figure.classList.add(h), Nt(n, !0), n.figure.offsetWidth;
1913
1924
  }, m = () => n.figure.classList.remove(h), g = () => {
1914
1925
  i = null, l();
1915
1926
  }, _ = {
1916
- relabel: () => Tt(n, t),
1927
+ relabel: () => jt(n, t),
1917
1928
  refresh: g
1918
1929
  };
1919
- c(), l(), d.observe(n.figure), f.observe(n.figure), window.addEventListener("beforeprint", p), window.addEventListener("afterprint", m), $t(_);
1930
+ c(), l(), d.observe(n.figure), f.observe(n.figure), window.addEventListener("beforeprint", p), window.addEventListener("afterprint", m), on(_);
1920
1931
  let v = {
1921
1932
  figure: n.figure,
1922
1933
  refresh: g,
@@ -1930,26 +1941,29 @@ var Te = (e) => e.map((e) => ({
1930
1941
  return n.plan?.count ?? 0;
1931
1942
  },
1932
1943
  destroy() {
1933
- d.disconnect(), f.disconnect(), window.removeEventListener("beforeprint", p), window.removeEventListener("afterprint", m), en(_), at(n), n.figure.tablechart === v && delete n.figure.tablechart;
1944
+ d.disconnect(), f.disconnect(), window.removeEventListener("beforeprint", p), window.removeEventListener("afterprint", m), sn(_), dt(n), n.figure.tablechart === v && delete n.figure.tablechart;
1934
1945
  }
1935
1946
  };
1936
1947
  return n.figure.tablechart = v, v;
1937
- }, an = async (e, t) => {
1938
- let n = Lt(e.filter((e) => !e.hasAttribute(Wt)));
1939
- return await Bt(n), Ut(n), Le(n, t.langattribute), n;
1940
- }, on = (e, t) => {
1941
- let n = X.timed("Building", e, () => gt(e, t));
1942
- return n ? (e.setAttribute(Wt, ""), rn(n, t)) : null;
1943
- }, sn = async (e, t = {}) => {
1948
+ }, dn = !1, fn = (t) => {
1949
+ let n = t.find((e) => e.tagName !== "FIGURE");
1950
+ !dn && n && (dn = !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));
1951
+ }, pn = async (e, t) => {
1952
+ let n = Ut(e.filter((e) => !e.hasAttribute(Xt)));
1953
+ return fn(n), await Kt(n), Yt(n), Le(n, t.langattribute), n;
1954
+ }, mn = (e, t) => {
1955
+ let n = X.timed("Building", e, () => St(e, t));
1956
+ return n ? (e.setAttribute(Xt, ""), un(n, t)) : null;
1957
+ }, hn = async (e, t = {}) => {
1944
1958
  if (e.tablechart) return e.tablechart;
1945
1959
  let n = {
1946
1960
  ...v,
1947
1961
  ...t
1948
1962
  };
1949
1963
  n.debug && (X.enabled = !0);
1950
- let [r] = await an([e], n);
1951
- return r ? on(r, n) : null;
1952
- }, cn = [
1964
+ let [r] = await pn([e], n);
1965
+ return r ? mn(r, n) : null;
1966
+ }, gn = [
1953
1967
  ["--tablechart-duration", "--tablechart-animation-element-duration"],
1954
1968
  ["--tablechart-stagger", "--tablechart-animation-stagger, a share of the element time"],
1955
1969
  ["--tablechart-easing", "--tablechart-animation-ease"],
@@ -1972,32 +1986,32 @@ var Te = (e) => e.map((e) => ({
1972
1986
  ["--tablechart-key-size", "--tablechart-legend-key-size"],
1973
1987
  ["--tablechart-controls-justify", "--tablechart-control-justify"],
1974
1988
  ["--tablechart-controls-gap", "--tablechart-control-gap"]
1975
- ], ln = {
1989
+ ], _n = {
1976
1990
  up: "grow",
1977
1991
  across: "sweep"
1978
- }, un = !1, dn = (t, n) => {
1979
- if (un) return;
1992
+ }, vn = !1, yn = (t, n) => {
1993
+ if (vn) return;
1980
1994
  let r = (e) => {
1981
- let t = ln[String(e)];
1995
+ let t = _n[String(e)];
1982
1996
  return t ? [`"${e}" is now "${t}"`] : [];
1983
1997
  }, i = new Set(r(n.animate));
1984
1998
  n.hover !== void 0 && i.add("the \"hover\" option is now \"tooltip\"");
1985
1999
  for (let e of t) {
1986
2000
  e.hasAttribute("data-chart-hover") && i.add("data-chart-hover is now data-chart-tooltip");
1987
2001
  let t = getComputedStyle(e);
1988
- for (let [e, n] of cn) t.getPropertyValue(e).trim() && i.add(`${e} is now ${n}`);
2002
+ for (let [e, n] of gn) t.getPropertyValue(e).trim() && i.add(`${e} is now ${n}`);
1989
2003
  for (let t of r(e.getAttribute("data-chart-animate"))) i.add(t);
1990
2004
  }
1991
- i.size && (un = !0, console.warn(`[${e}] ${[...i].join("; ")}. The old names work until the next minor version.`));
1992
- }, fn = async (e = {}, t = document) => {
2005
+ i.size && (vn = !0, console.warn(`[${e}] ${[...i].join("; ")}. The old names work until the next minor version.`));
2006
+ }, bn = async (e = {}, t = document) => {
1993
2007
  let n = {
1994
2008
  ...v,
1995
2009
  ...e
1996
2010
  };
1997
2011
  n.debug && (X.enabled = !0);
1998
- let r = await an(Array.from(t.querySelectorAll(n.selector)), n);
1999
- dn(r, n);
2000
- let i = r.map((e) => on(e, n)).filter((e) => e !== null);
2012
+ let r = await pn(Array.from(t.querySelectorAll(n.selector)), n);
2013
+ yn(r, n);
2014
+ let i = r.map((e) => mn(e, n)).filter((e) => e !== null);
2001
2015
  return X.log(`Made ${i.length} chart(s).`), {
2002
2016
  charts: i,
2003
2017
  refresh: () => {
@@ -2009,4 +2023,4 @@ var Te = (e) => e.map((e) => ({
2009
2023
  };
2010
2024
  };
2011
2025
  //#endregion
2012
- export { h as _, Lt as a, v as b, gt as c, Dt as d, Et as f, t as g, f as h, an as i, wt as l, Le as m, qt as n, Bt as o, He as p, fn as r, Ut as s, sn as t, Tt as u, g as v, m as y };
2026
+ export { h as _, Ut as a, v as b, St as c, Nt as d, Mt as f, t as g, f as h, pn as i, At as l, Le as m, $t as n, Kt as o, He as p, bn as r, Yt as s, hn as t, jt as u, g as v, m as y };
@@ -1 +1 @@
1
- !function(){var t="tablechart",e="tablechart-value",n="tablechart-bar",a="tablechart-rule",o="tablechart-line",r="tablechart-head",s="tablechart-slice",c="tablechart-legend",l="tablechart-hole",i="tablechart-centre",u="tablechart-break",d="tablechart-sr",h="is-printing",f=1e3,b={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",shape:"straight",legend:!1,tooltip:"auto",table:"never",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},m="cubic-bezier(0.3, 0.3, 0.6, 1)",g=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?m:"linear"}),p=(t,e)=>`${t}:${e}`,w=t=>Math.round(100*t)/100,$=(t,e={})=>{const n=document.createElementNS("http://www.w3.org/2000/svg",t);for(const a in e){const t=e[a];n.setAttribute(a,String("number"==typeof t?w(t):t))}return n},y=(t,e)=>[t,...e.classes].join(" "),M=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},v=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},k=0,x=(t,e,n,a)=>{if(!e.length)return;const o="tablechart-cut-"+ ++k,r=$("mask",{id:o,maskUnits:"userSpaceOnUse"});r.appendChild($("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const l of e)l.setAttribute("fill","black"),r.appendChild(l);let s=t.querySelector(":scope > defs");s||(s=$("defs"),t.prepend(s)),s.appendChild(r);const c=$("g",{mask:`url(#${o})`});for(const l of Array.from(t.childNodes))l!==s&&c.appendChild(l);t.appendChild(c)},A=0,N={create:()=>null,draw(t,e,a){const{rows:o,y:r,svg:s,breakAt:c}=a;if(null===c)return;const l="zigzag"===t.getAttribute("data-mark"),i=(t,e)=>{const n=t.sideways?t.height:t.width,a=.09*n,o=n+2*a,r=.3*o,s=.06*o;if(t.sideways){const n=t.y-a;if(!l)return[[e-r/2,n],[e+r/2,n+o]];const c=o/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+o]]}const c=t.x-a;if(!l)return[[c,e+r/2],[c+o,e-r/2]];const i=o/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+o,e-s]]},d=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),h="tablechart-break-"+ ++A,f=$("mask",{id:h,maskUnits:"userSpaceOnUse"});f.appendChild($("rect",{x:-1e3,y:-a.height,width:3e3,height:3*a.height,fill:"white"}));const b=[],m=r(c);for(const M of(t=>Array.from(t.querySelectorAll(`.${n}`)).map(t=>{const e="rect"===t.tagName?[t]:Array.from(t.querySelectorAll("rect")),n=(t,e)=>Number(t.getAttribute(e)),a=Math.min(...e.map(t=>n(t,"x"))),o=Math.min(...e.map(t=>n(t,"y"))),r=Math.max(...e.map(t=>n(t,"x")+n(t,"width"))),s=Math.max(...e.map(t=>n(t,"y")+n(t,"height"))),c=["--start","--span"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ");return{row:Number(t.dataset.row),x:a,y:o,width:r-a,height:s-o,sideways:"right"===t.dataset.grow,part:c}}))(s)){const t=M.sideways?a.breakX:m;if(void 0===t)continue;if(!(M.sideways?M.x<t&&M.x+M.width>t:M.y<m&&M.y+M.height>m))continue;const[e,n]=M.sideways?[i(M,t),i(M,t+a.breakGap)]:[i(M,m-a.breakGap),i(M,m)];f.appendChild($("path",{d:d([...e,...n.slice().reverse()],!0),fill:"black"})),b.push(e,n);const r=[p("--after",o[M.row-1]?.slot??0),M.part].filter(Boolean).join("; ");for(const o of[e,n])s.appendChild($("path",{class:u,"data-part":"edge","data-note":a.note,d:d(o),style:r}))}if(!b.length)return;const g=Array.from(s.querySelectorAll(`.${u}`)),w=$("g",{mask:`url(#${h})`});for(const n of Array.from(s.childNodes))g.includes(n)||w.appendChild(n);const y=$("defs");y.appendChild(f),s.prepend(y,w)}},S=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},H=t=>(t.split(/[.,]/)[1]||"").length,T=(t,e,n)=>{const a=((t,e)=>new Intl.NumberFormat(e||document.documentElement.lang||void 0,{minimumFractionDigits:t,maximumFractionDigits:t}))(e,n).formatToParts(t),o="minusSign"===a[0]?.type?a[0].value:"";return[o,a.slice(o?1:0).map(t=>t.value).join("")]},z=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const a of Array.from(t.children))n.appendChild(a.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},C=(e,n,a,o)=>{const r=(s=e?.textContent||"",Number.parseFloat((s.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")));var s;const c=!!Number.isNaN(r)||Math.abs(n-r)<=.5,l={label:a,computed:n,stated:r,agrees:c};o.checks.push(l),c||console.warn(`[${t}] An annotation reads ${r}%, but ${a} is ${n.toFixed(1)}%. The chart shows your number.`)},L={create:z,draw(e,n,a){const{rows:s,cx:c,y:l,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:b,after:m}=a,[g,w]=((t,e)=>{const n=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n};return[n("data-from",0),n("data-to",e-1)]})(e,s.length),y=s[g],M=s[w];if(!y||!M)return void console.warn(`[${t}] A bracket points at a row that is not there (row ${g+1} to ${w+1}, of ${s.length}).`);const k=7*i,x=4*i,A=c(g),N=c(w),S=Math.min(l(y.value),l(M.value))-u-x-.9*d,H=t=>l(t)-u-x,T=`M ${A} ${H(y.value)} L ${A} ${S} L ${N} ${S} L ${N} ${H(M.value)-k}`,z=(H(y.value)-S+Math.abs(N-A)+(H(M.value)-k-S))/i+1;b.appendChild($("path",{class:o,"data-note":a.note,d:T,style:`--len:${z.toFixed(1)}; ${p("--after",m)}`}));const L=H(M.value);var O;b.appendChild($("polygon",{class:r,"data-note":a.note,points:`${N},${L} ${N-.45*k},${L-k} ${N+.45*k},${L-k}`,style:p("--after",m)})),n&&(v(n,(A+N)/2,S,f,h),n.style.setProperty("--after",String(m))),C(n,(O=y.value,(M.value-O)/Math.abs(O)*100),`${y.value} to ${M.value}`,a)}},O=new WeakMap,B=t=>O.get(t)??{width:t.offsetWidth,height:t.offsetHeight},U={create:z,draw(t,e,n){const{rows:a,cx:s,y:c,unit:l,labelHeight:i,height:u,svg:d,values:h,after:b}=n,m=a[0],g=a[a.length-1];if(!m||!g)return;const w=i+18*l,y=10*l,M=10*l;let k=s(0),x=c(m.value)-w,A=s(a.length-1),N=c(g.value)-w,S=0;a.forEach((t,e)=>{const n=A===k?0:(s(e)-k)/(A-k),a=x+n*(N-x)-(c(t.value)-w);a>S&&(S=a)}),x-=S,N-=S;const H=A-k,T=N-x,z=Math.hypot(H,T)||1,L=H/z,O=T/z;k-=L*y,x-=O*y,A+=L*y,N+=O*y;const U=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=k+(A-k)*U,n=x+(N-x)*U,o=B(e).width*l/2,r=n+B(e).height*l/2+8*l;let u=0;a.forEach((e,n)=>{const a=(h[n]?B(h[n]).width:0)*l/2;if(Math.abs(s(n)-t)>=o+a)return;const d=c(e.value)-7*l-i;u=Math.max(u,r-d)}),x-=u,N-=u}const _=A-L*M,E=N-O*M,F=Math.hypot(_-k,E-x)/l+1;d.appendChild($("line",{class:o,"data-note":n.note,x1:k,y1:x,x2:_,y2:E,style:`--len:${F.toFixed(1)}; ${p("--after",b)}`}));const j=-O,P=L,q=.42*M;d.appendChild($("polygon",{class:r,"data-note":n.note,points:[`${A},${N}`,`${_+j*q},${E+P*q}`,`${_-j*q},${E-P*q}`].join(" "),style:p("--after",b)})),e&&(v(e,k+(A-k)*U,x+(N-x)*U,f,u),e.style.setProperty("--after",String(b)));const R=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(R)&&R>0&&C(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(m.value,g.value,R),`${m.value} to ${g.value} over ${R} years`,n)}},_=(t,e,n)=>{const a=.15,o=Math.min(.7*t/(e+(e-1)*a),n),r=e*o+(e-1)*o*a;return{size:o,gap:o*a,offset:t=>-r/2+t*o*1.15}},E=(t,e,n)=>{const a=t.series[n],o=t.series.some(t=>t.focus)&&!a.focus;return{"data-series":n+1,...o&&{"data-muted":""},style:`--n:${n}; --m:${o?1:0}; --palette:var(--tablechart-color-${n+1}); ${p("--i",e.slot)}`}},F=(t,e,n=!1)=>{let a=0,o=0;return Array.from({length:e},(e,r)=>{const s=t.cells[r]??t.cells[0],c=s.missing?0:s.value;if(n){const t=a;return a+=c,{from:t,to:a,cell:s}}if(c<0){const t=o;return o+=c,{from:t,to:o,cell:s}}const l=a;return a+=c,{from:l,to:a,cell:s}})},j=(t,e,n=!1)=>{const a=F(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},P=(t,e)=>{const{top:n,bottom:a}=j(t,e);return n+a},q=(t,e,n)=>{const a=e.series.some(t=>t.focus);t.style.setProperty("--n",String(n)),t.style.setProperty("--m",a&&!e.series[n].focus?"1":"0"),t.style.setProperty("--palette",`var(--tablechart-color-${n+1})`)},R=(t,e,a,o={},r="")=>{const s={class:y(n,e),"data-kind":"bar","data-row":a+1,...o},c=p("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=$("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(n,r)=>{const s=void 0!==o["data-grow"]?{"data-grow":o["data-grow"]}:{};l.appendChild($("rect",{...s,...r,class:y("tablechart-piece",e),"data-row":a+1,...E(t,e,n)}))}},W=(t,e,n)=>t.some(t=>B(t).width*n>e-6*n),D=(t,e,n)=>e>=B(t).height*n*1.6,V=(t,e,n)=>e>=B(t).width*n*1.5,K=(t,e,n,a,o=.7)=>{t.style.setProperty(a,"1");let r=1;for(const c of e){const{size:t,room:e}=n(c);t>e&&(r=Math.min(r,e/t))}const s=r>=o?r:0;return t.style.setProperty(a,String(s||o)),s},I={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,aspect:.5,minHeight:({labelHeight:t,nameHeight:e,rows:n,series:a,stacked:o})=>{const r=1.1*t,s=a>1&&!o?r*(a+.15*(a-1))/.7:r/.58;return n*Math.max(s,1.2*e)},categories:"beside",headroom:()=>0,draw(t){const{segments:e,height:o,unit:r,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(S(l.map(t=>B(t).width*r)),0),b=Math.min(h+10*r,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((b-8*r)/f*100).toFixed(2)}%`);const m=f-4*r,g=t.stacked?Math.max(S(t.rows.map(e=>j(e,t.series.length).top)),0)||1:Math.max(S(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,w=t.stacked?Math.max(S(t.rows.map(e=>-j(e,t.series.length).bottom)),0):Math.max(S(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),M=Math.max(g,t.squeeze?.hi??0)+w,k=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),M,n,t.squeeze,t.breakGap),x=o/e.length,A=t=>(t+.5)*x,N=Math.min(x*i.barfill,u),H=_(x,t.series.length,u),T=c[0]??t.totals[0],z=T?B(T).height*r*.56:0,C=Math.max(((d&&!t.stacked?H.size:N)-z)/2,5*r),L=t=>B(t).width*r,O=t=>t.length?S(t.map(L))+C+4*r:0,U=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,P=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:U(e,n)}))),W=e=>{const n=j(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let D=t.stacked?O(t.totals.filter((t,e)=>!W(e))):d?O(P.filter(t=>t.value>=0).map(t=>t.label)):0,I=t.stacked?O(t.totals.filter((t,e)=>W(e))):d?O(P.filter(t=>t.value<0).map(t=>t.label)):0;if(!d&&!t.stacked)for(let n=0;n<3;n++){const t=m-b-D-I,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!V(n,k(e.value,t),r)),a=O(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),o=O(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(a<=D&&o<=I)break;D=Math.max(D,a),I=Math.max(I,o)}const G=m-b-D-I,Z=b+I+k(w,G),J=t=>t<0?Z-k(t,G):Z+k(t,G);if(t.squeeze&&(t.breakX=J(t.squeeze.gap)),t.stacked)return t.rows.forEach((e,n)=>{const a=j(e,t.series.length),s=R(t,e,n,{"data-grow":"right"},a.bottom<0?Z-J(a.bottom)+"px center":""),c=A(n)-N/2;F(e,t.series.length).forEach(({from:e,to:a,cell:l},i)=>{const u=t.seriesValues[i][n];if(u.dataset.place="none",l.missing||a===e)return;const d=Math.min(J(e),J(a)),h=Math.max(J(e),J(a));s(i,{x:d,y:c,width:Math.max(h-d,1),height:N,...a<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!V(u,h-d,r)||B(u).height*r>N),q(u,t,i),v(u,(d+h)/2,A(n),f,o)});const i=t.totals[n];i&&(i.dataset.place=W(n)?"before":"after",v(i,W(n)?J(a.bottom)-C:J(a.top)+C,A(n),f,o));const u=l[n];u&&v(u,b-8*r,A(n),f,o)}),void s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=K(t.plot,e,t=>({size:B(t).height*r,room:H.size+.5*H.gap}),"--_fit");return t.rows.forEach((e,a)=>{t.series.forEach((r,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][a];if(i.missing)return void(u.dataset.place="none");const d=J(i.value),h=i.value<0,b=A(a)+H.offset(l);s.appendChild($("rect",{class:y(n,e),"data-kind":"bar","data-row":a+1,"data-grow":h?"left":"right",x:Math.min(d,Z),y:b,width:Math.max(Math.abs(d-Z),1),height:H.size,...E(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),v(u,h?d-C:d+C,b+H.size/2,f,o)});const i=l[a];i&&v(i,b-8*r,A(a),f,o)}),void s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}))}const Q=e.map((t,e)=>V(c[e],Math.abs(J(t.value)-Z),r));e.forEach((e,a)=>{const i=J(e.value),u=A(a),d=e.value<0,h=Math.abs(i-Z);s.appendChild($("rect",{class:y(n,e),"data-kind":e.kind,"data-row":a+1,"data-grow":d?"left":"right",x:Math.min(i,Z),y:u-N/2,width:Math.max(h,1),height:N,style:p("--i",e.slot)}));const m=c[a],g=Math.max(Math.min(C,h-L(m)-6*r),6*r),w=d?1:-1;m.dataset.place=Q[a]?"inside":d?"before":"after",m.dataset.kind=e.kind,v(m,Q[a]?"center"===t.insideAlign?(Z+i)/2:"start"===t.insideAlign?Z-w*(g+L(m)/2):i+w*(g+L(m)/2):i-w*C,u,f,o);const M=l[a];M&&v(M,b-8*r,u,f,o)}),s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}))}},G={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+4*a+(n?1.6*e:0),draw(t){const{segments:e,cx:o,y:r,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,b=r(0);if(t.stacked)return t.rows.forEach((e,n)=>{const a=j(e,t.series.length),i=R(t,e,n,{},a.bottom<0?`center ${b-r(a.top)}px`:""),u=o(n)-s/2;F(e,t.series.length).forEach(({from:e,to:a,cell:d},h)=>{const b=t.seriesValues[h][n];if(b.dataset.place="none",d.missing||a===e)return;const m=Math.min(r(a),r(e)),g=Math.max(r(a),r(e));i(h,{x:u,y:m,width:s,height:Math.max(g-m,1),...a<e&&{"data-grow":"down"}}),b.dataset.place="inside",b.toggleAttribute("data-left-out",!D(b,g-m,l)||B(b).width*l>s-4*l),q(b,t,h),v(b,o(n),(m+g)/2,f,c)});const d=t.totals[n];if(d){const t=0===a.top&&a.bottom<0;d.dataset.place=t?"below":"outside",v(d,o(n),t?r(a.bottom)+4*l:r(a.top)-4*l,f,c)}}),void i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}));if(t.series.length>1){const e=o(1)-o(0)||2*o(0),s=_(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=K(t.plot,u,t=>({size:B(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,a)=>{t.series.forEach((u,h)=>{const m=e.cells[h]??e.cells[0],g=t.seriesValues[h][a],p=o(a)+s.offset(h);if(m.missing)return void(g.dataset.place="none");const w=r(m.value),M=m.value<0;i.appendChild($("rect",{class:y(n,e),"data-kind":"bar","data-row":a+1,...M&&{"data-grow":"down"},x:p,y:Math.min(w,b),width:s.size,height:Math.max(Math.abs(b-w),1),...E(t,e,h)})),g.dataset.place=M?"below":"outside",g.toggleAttribute("data-left-out",!d),v(g,p+s.size/2,M?w+4*l:w-4*l,f,c)})}),void i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}))}const m=W(u,s,l),g=e.map((t,e)=>"inside"===d&&!m&&!t.missing&&D(u[e],Math.abs(b-r(t.value)),l)),w=u[0]?B(u[0]).height*l*.56:0;let M=Number.POSITIVE_INFINITY;for(const[n,a]of u.entries())g[n]&&(M=Math.min(M,(s-B(a).width*l)/2));e.forEach((t,e)=>{const a=r(t.value),d=t.value<0;if(t.missing)return v(u[e],o(e),b-4*l,f,c),void(u[e].dataset.place="outside");i.appendChild($("rect",{class:y(n,t),"data-kind":t.kind,"data-row":e+1,...d&&{"data-grow":"down"},x:o(e)-s/2,y:Math.min(a,b),width:s,height:Math.max(Math.abs(b-a),1),style:p("--i",t.slot)}));const m=d?-1:1,k=Math.min(M,(Math.abs(b-a)-w)/2),x="center"===h?(a+b)/2:"start"===h?b-m*(k+w/2):a+m*(k+w/2),A=d?a+4*l:a-4*l;v(u[e],o(e),g[e]?x:A,f,c),u[e].dataset.place=g[e]?"inside":d?"below":"outside"}),i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}))}},Z=0,J={aspect:.66,centre:!0,headroom:()=>0,segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),draw({rows:t,height:e,unit:n,labelHeight:a,svg:o,values:r,config:c,centre:l}){const i=500,u=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,b=Math.max(Math.min(f,e)/2-h,10),m=b*c.ringfill,w=b-m/2,M=2*Math.PI*w,k=[];let x=0,A=0,N=0;if(t.forEach((t,c)=>{const l=r[c];if(t.isTotal)return void(l.dataset.place="none");const h=Math.abs(t.value)/d,S=g(N,h),H=`--share:${h.toFixed(4)}; --start:${S.start.toFixed(4)}; --span:${S.span.toFixed(4)};`,T=h*M,z=x/M*2*Math.PI-Math.PI/2;k.push(z),o.appendChild($("circle",{class:y(s,t),"data-slice":A+1,"data-row":c+1,cx:i,cy:u,r:w,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${T.toFixed(1)} ${(M-T).toFixed(1)}`,"stroke-dashoffset":(-x).toFixed(1),style:`--n:${A}; --palette:var(--tablechart-color-${A+1}); --arc:${T.toFixed(1)}; --circ:${M.toFixed(1)}; ${H} --ease:${S.easing}; ${p("--i",t.slot)}`}));const C=z+T/M*Math.PI,L=Math.cos(C),O=Math.sin(C);o.appendChild($("line",{class:"tablechart-leader",x1:i+L*(b+2*n),y1:u+O*(b+2*n),x2:i+L*(b+7*n),y2:u+O*(b+7*n),"data-row":c+1,style:`${H} ${p("--i",t.slot)}`})),l.style.setProperty("--start",S.start.toFixed(4)),l.style.setProperty("--span",S.span.toFixed(4));const U=b+9*n,_=B(l).width*n/2;v(l,i+L*(U+Math.abs(L)*_),u+O*(U+Math.abs(O)*a*.7),f,e),l.dataset.place="around",x+=T,N+=h,A+=1}),k.length>1){const t=w-m/2-1,n=w+m/2+1,a="tablechart-slices-"+ ++Z,r=$("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild($("rect",{x:0,y:0,width:f,height:e,fill:"white"}));for(const e of k)r.appendChild($("line",{class:"tablechart-divide",x1:i+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:i+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const c=$("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${s}`)))c.appendChild(e);const l=$("defs");l.appendChild(r),o.prepend(l,c)}l&&v(l,i,u,f,e)}},Q=["circle","square","diamond"],X=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=Q.find(t=>n.includes(t));return{shape:a??Q[Math.floor(e/2)%Q.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},Y=t=>Number(t.toFixed(2));function tt(t,e,n){const a=new Array(t).fill(0);let o=[];const r=()=>{(function(t,e){const n=t.length;if(n<2)return t.map(()=>0);const a=n=>(e[n+1]-e[n])/(t[n+1]-t[n]||1),o=new Array(n).fill(0);for(let s=1;s<n-1;s++){const e=a(s-1),n=a(s);if(e*n<=0)continue;const r=t[s]-t[s-1],c=t[s+1]-t[s],l=(e*c+n*r)/(r+c||1),i=Math.min(2*Math.abs(e),2*Math.abs(n),Math.abs(l));o[s]=Math.sign(e)*i||0}if(2===n)return o[0]=a(0),o[1]=a(0),o;const r=(n,a,o)=>{const r=t[a]-t[n];return r?((e[a]-e[n])/r*3-o)/2:o};return o[0]=r(0,1,o[1]),o[n-1]=r(n-2,n-1,o[n-2]),o})(o.map(t=>n(t)[0]),o.map(t=>n(t)[1])).forEach((t,e)=>{a[o[e]]=t}),o=[]};for(let s=0;s<t;s++)e(s)?r():o.push(s);return r(),a}var et,nt,at=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),ot=t=>({segments:at,series:!0,stackable:!0,running:!0,swatch:t?"box":void 0,headroom:({labelHeight:t,unit:e})=>1.6*t+6*e,footroom:({labelHeight:e,unit:n,series:a,focused:o,stacked:r})=>t||r||2!==a||o?0:e+7*n,draw(e){const{rows:n,series:o,seriesValues:r,names:s,cx:c,y:i,height:u,unit:d,labelHeight:h,svg:b,stacked:m}=e,g="step"===e.shape,p="smooth"===e.shape,w=o.length>1,y=o.some(t=>t.focus),M=n.length-1,k=i(0),A=n.length>1?c(1)-c(0):2*c(0);b.style.setProperty("--_base",`${Y(k)}px`);const N=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],S=(t,e)=>!N(t,e)||!!N(t,e)?.missing,H=n.map(t=>m?F(t,o.length,!0):null),T=(t,e)=>H[e]?.[t].to??N(t,e)?.value??0,z=(t,e)=>H[e]?.[t].from??0,C=(t,e)=>[c(e),i(T(t,e))],L=o.map((t,e)=>{if(!w)return{attrs:{},ink:""};const n=y&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),O=Math.min(M,6);e.plot.style.setProperty("--count",String(O+1));const U=M>0?O/(g?n.length:M):1,_=t=>t*U,E=t=>`--i:${Y(_(t))}`,j=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{S(t,o)||(a<0&&(a=o),(o===M||S(t,o+1))&&((g||o>a)&&e.push([a,o]),a=-1))}),e},P=(t,e)=>`--i:${Y(_(t)+1)}; --d:${Y(_(g?e+1:e)-_(t))}`,q=(t,e)=>({"data-from":t+1,"data-to":e+1,...g&&{"data-flat":""}}),R=p?o.map((t,e)=>tt(n.length,t=>S(e,t),t=>C(e,t))):[],W=p&&t?o.map((t,e)=>tt(n.length,t=>S(e,t),t=>[c(t),i(z(e,t))])):[],D=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{g?(a.push(`H${Y(o+n*A/2)}`),s<t.length-1&&a.push(`V${Y(t[s+1][1])}`)):s>0&&a.push(e?function(t,e,n,a){const[o,r]=function(t,e,n,a){const o=(e[0]-t[0])/3;return[[t[0]+o,t[1]+n*o],[e[0]-o,e[1]-a*o]]}(t,e,n,a),s=([t,e])=>`${Y(t)},${Y(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${Y(o)},${Y(r)}`)}),a},V=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),i(o(t,e+a))]),K=(t,e,n,a)=>p?t[e].slice(n,a+1):null,I=t=>c(t)-(g?A/2:0),G=t=>c(t)+(g?A/2:0);t&&o.forEach((t,e)=>(t=>{const e=$("g",{class:"tablechart-area",...L[t].attrs,...m&&{"data-stacked":""},style:L[t].ink}),n=j(t),a=$("g",{class:"tablechart-area-fill",style:`--rows:${Y(O+1)}; ${n.length?P(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=V(t,o,r,T),n=V(t,o,r,z),s=K(W,t,o,r)?.reverse()??null,c=[`M${Y(I(o))},${Y(n[0][1])}`,`L${Y(I(o))},${Y(e[0][1])}`,...D(e,K(R,t,o,r),1),`L${Y(G(r))},${Y(n[n.length-1][1])}`,...D(n.reverse(),s,-1),"Z"].join(" ");a.appendChild($("path",{d:c,...q(o,r),style:P(o,r)}))}b.appendChild(e)})(e)),o.forEach((t,e)=>(t=>{const e=o[t];for(const[n,a]of j(t)){const o=V(t,n,a,T),r=[`M${Y(I(n))},${Y(o[0][1])}`,...D(o,K(R,t,n,a),1)].join(" ");b.appendChild($("path",{class:"tablechart-series",...L[t].attrs,d:r,...e.line&&{"data-line":e.line},...q(n,a),style:`${L[t].ink}${P(n,a)}`}))}})(e)),g||(()=>{const t=o.map((t,e)=>w?X(o,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=C(e,n);return((t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return $("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return $("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}return $("circle",{cx:e,cy:n,r:a,...o})})(t[e].shape,o,r,4*d,{...a,style:`${a.style??""}${s=r,`--rise:${Y(k-s)}px; `}${E(n)}`});var s},a=t=>n.map((t,e)=>e).filter(e=>!S(t,e)),r=o.flatMap((n,o)=>t[o].open?a(o).map(t=>e(o,t,{class:l,"data-row":t+1,...w&&{"data-series":o+1}})):[]);x(b,r,f,u),o.forEach((n,o)=>{for(const r of a(o))b.appendChild(e(o,r,{class:"tablechart-point",...L[o].attrs,"data-marker":t[o].shape,...t[o].open&&{"data-open":""},"data-row":r+1,style:L[o].ink}))})})();const Z=(t,e)=>{let n=e;for(;n<M&&!S(t,n+1)&&N(t,n+1)?.value===N(t,e)?.value;)n++;return n};r.forEach((e,n)=>{e.forEach((e,a)=>{e.style.setProperty("--i",String(Y(g?(_(a)+_(a+1))/2:_(a))));const s=((e,n)=>{const a=N(e,n);if(!a||a.missing)return"none";if(g&&n>0&&!S(e,n-1)&&N(e,n-1)?.value===a.value)return"none";if(y&&!o[e].focus)return"none";if(m)return"middle";const r=a.value<0?"below":"above";if(!w||y||o.length>2)return r;const s=N(1-e,n);return!s||s.missing?r:a.value>s.value||a.value===s.value&&0===e||t&&a.value>=0&&C(e,n)[1]+7*d+h>k?"above":"below"})(n,a);if(e.dataset.place="above"===s?"outside":s,e.toggleAttribute("data-left-out","none"!==s&&((t,e)=>m||g?B(r[t][e]).width*d>(g?Z(t,e)-e+1:1)*A-4*d||!!(m&&t>0&&T(t,e)<z(t,e))||m&&Math.abs(i(z(t,e))-i(T(t,e)))<1.2*h:w&&!y&&o.length>2)(n,a)),g&&"none"!==s?e.dataset.rowEnd=String(Z(n,a)+1):delete e.dataset.rowEnd,"none"===s)return;const l=B(e).width*d/2+4*d;let b=c(a);g?b=(c(a)+c(Z(n,a)))/2:"middle"===s&&0===a?b+=l:"middle"===s&&a===M&&(b-=l);const p=i(T(n,a)),$={middle:(i(z(n,a))-p)/2,above:-7*d,below:7*d};v(e,b,p+$[s],f,u)})});const J=s.map((t,e)=>{let n=M;for(;n>0&&S(e,n);)n--;const[a,o]=C(e,n);return{name:t,x:(g?a+A/2:a)+10*d,y:m?(o+i(z(e,n)))/2:o}}),Q=(s[0]?B(s[0]).height:0)*d;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,a)=>{const o=t[a-1];o&&n.y<o.y+e&&(n.y=o.y+e)}),t))(J,Q))v(t.name,t.x,t.y,f,u);const et=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),nt=t||m||2!==o.length||y||et?k:u-2*d;b.appendChild($("line",{class:a,x1:0,x2:c(M)+c(0),y1:nt,y2:nt}))}}),rt=ot(!1),st=ot(!0),ct=new Set,lt={segments:e=>{let n=0,a=!1;return e.map(e=>{if(e.isTotal)return a&&((e,n)=>{if(Math.abs(e-n)<=Math.abs(n)/100)return;const a=`[${t}] A total reads ${e}, but the steps before it add up to ${Number(n.toFixed(6))}. The chart shows your number.`;ct.has(a)||(ct.add(a),console.warn(a))})(e.value,n),a=!1,n=e.value,{...e,from:0,to:e.value,kind:"total"};const o=n;return n+=e.value,a=!0,{...e,from:o,to:n,kind:e.value>=0?"up":"down"}})},breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+6*a+(n?1.6*e:0),draw({segments:t,cx:e,y:o,barWidth:r,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=o(0),b=W(i,r,c),g=d??"center",w=t.map((e,n)=>{const a=o(Math.max(e.from,e.to)),r=Math.abs(o(e.from)-o(e.to)),s=null!==u&&Math.min(e.from,e.to)<u&&Math.max(e.from,e.to)>u,l="total"===e.kind&&n>0&&n===t.length-1;return{top:a,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!b&&D(i[n],r,c)}}),M=i[0]?B(i[0]).height*c*.56:0;let k=Number.POSITIVE_INFINITY;for(const[n,a]of w.entries())a.inside&&(k=Math.min(k,(r-B(i[n]).width*c)/2));const x=t.length,A=(t,e,n=!1)=>`--start:${(t/x).toFixed(4)}; --span:${(e/x).toFixed(4)}; --ease:${n?m:"linear"};`;t.forEach((n,a)=>{const s=t[a+1];if(!s)return;const c=o(n.to),i=e(a)+r/2,u=e(a+1)-r/2;l.appendChild($("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":a+2,style:`${p("--i",s.slot)}; ${A(a+1,1/3)}`}))}),t.forEach((a,o)=>{const{top:u,length:d,down:h,inside:b}=w[o];l.appendChild($("rect",{class:y(n,a),"data-kind":a.kind,"data-row":o+1,"data-grow":h?"down":"up",x:e(o)-r/2,y:u,width:r,height:Math.max(d,1),style:`${p("--i",a.slot)}; ${A(o,1,o===t.length-1)}`}));const m=i[o];m.style.setProperty("--start",(o/x).toFixed(4)),m.style.setProperty("--span",(1/x).toFixed(4));const N=Math.min(k,(d-M)/2),S="center"===g?u+d/2:"end"===g!==h?u+N+M/2:u+d-N-M/2;m.dataset.place=b?"inside":"outside",m.dataset.kind=a.kind;const H=b?S:"down"===a.kind?u+d+B(m).height*c+3*c:u-3*c;v(m,e(o),H,f,s)}),l.appendChild($("line",{class:a,x1:0,x2:f,y1:h,y2:h}))}},it={enabled:!1,log(...e){it.enabled&&console.log(`[${t}]`,...e)},timed(e,n,a){if(!it.enabled)return a();const o=performance.now(),r=a(),s=performance.now()-o,c=n.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${t}] ${e} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,n):it.log(`${e} took ${s.toFixed(1)} ms for ${c} rows.`,n),r}},ut=t=>{const e=(t?.textContent||"").trim(),n=e.match(/^(.*?)(-?\d+(?:[.,]\d+)?)(.*)$/);return{raw:e,number:n?.[2]??"",prefix:n?.[1]??"",suffix:n?.[3]??"",missing:!n,value:n?Number.parseFloat(n[2].replace(",",".")):0}},dt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),ht=["axis-break","trend","bracket"],ft=t=>{const e=t.plan;if(!e)return;const n=e=>null===e||t.step-e>=1;for(const a of t.figure.querySelectorAll("[data-from]")){const t=Number(a.dataset.from)-1,o=Number(a.dataset.to)-1,r=a.closest("[data-series]")?.dataset.series,s=r?Number(r)-1:0,c=e.series[s],l=t=>e.cells[t]?.[s]?.step??e.rows[t]?.step??null;let i=t-1;if(c&&null!==c.step)i=n(c.step)?o:t-1;else for(;i<o&&n(l(i+1));)i++;const u=a.hasAttribute("data-flat")?(i-t+1)/(o-t+1):o>t?Math.max(0,i-t)/(o-t):0;a.style.setProperty("--reveal",String(u))}},bt=(t,e,n=!1)=>{const a=t.plan;if(!a)return;const o=Math.min(Math.max(Math.round(e),0),a.count),r=o!==t.step;t.step=o,t.figure.style.setProperty("--_step",String(o)),ft(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===o),c&&(c.disabled=o===a.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:o,steps:a.count}}))},mt="tablechart-tooltip",gt=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],pt=null,wt=null,$t=null,yt=0,Mt=()=>{clearTimeout(yt),pt&&wt&&(pt.hidden=!0,wt=null,$t=null)},vt=()=>{clearTimeout(yt),yt=window.setTimeout(Mt,120)},kt=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},xt=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole)`);if(!n)return;const a=getComputedStyle(n);return a.fill&&"none"!==a.fill?a.fill:a.stroke},At=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!kt(t,c[e]))continue;const n=a?t.figure.querySelector(`.tablechart-name[data-series="${s+1}"]`):null;o.push({name:a?n?.textContent??t.series[s].name:"",value:c[e].textContent??"",colour:a?xt(t,s):void 0,sample:n?{marker:n.dataset.marker??null,open:n.hasAttribute("data-open"),line:n.dataset.line??null,box:"box"===n.dataset.swatch}:void 0})}const r=t.totals[e];return o.length>1&&kt(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Nt=(t,e,n)=>{if(clearTimeout(yt),wt===t&&$t===e)return;const a=(t.type.tooltip??At)(t,e,n);if(!a.length)return Mt();wt&&wt!==t&&Mt(),pt??(pt=(()=>{const t=document.createElement("div");return t.className=mt,t.setAttribute("aria-hidden","true"),t.hidden=!0,et=document.createElement("div"),(nt=document.createElement("div")).className=`${mt}-arrow`,t.append(et,nt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(yt)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&vt()),document.addEventListener("keydown",t=>"Escape"===t.key&&Mt()),document.addEventListener("pointerdown",e=>{const n=e.target;!wt||wt.plot.contains(n)||t.contains(n)||Mt()}),window.addEventListener("scroll",Mt,{capture:!0,passive:!0}),window.addEventListener("resize",Mt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${mt}-line`,n){const t=document.createElement("span");t.className=`${mt}-key`,t.style.background=n,o?.box?t.dataset.sample="box":o&&(t.dataset.sample="line",o.marker&&(t.dataset.marker=o.marker),o.line&&(t.dataset.line=o.line),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${mt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${mt}-value`,n.textContent=e,r.append(n)}return r},r=t.categories[e]?.textContent??t.rows[e].label,s=1===a.length&&!a[0].name;et.replaceChildren(o(r,s?a[0].value:"",void 0,!0),...s?[]:a.map(({name:t,value:e,colour:n,sample:a})=>o(t,e,n,!1,a)));const c=getComputedStyle(t.figure);for(const l of gt){const t=c.getPropertyValue(l).trim();t?pt.style.setProperty(l,t):pt.style.removeProperty(l)}pt.style.setProperty("--_color",c.color),pt.style.colorScheme=c.colorScheme,pt.style.fontFamily=c.fontFamily,pt.style.fontSize=c.fontSize,wt=t,$t=e,pt.hidden=!1,pt.style.left="0px",((t,e,n,a=10,o=8,r=12)=>{const{offsetWidth:s,offsetHeight:c}=t,{clientWidth:l,clientHeight:i}=document.documentElement,u=n.top-o,d=i-n.bottom-o,h=c+a<=u||!(c+a<=d)&&u>=d,f=h?n.top-a-c:n.bottom+a,b=n.left+n.width/2,m=Math.max(o,Math.min(b-s/2,l-s-o));t.style.left=`${m}px`,t.style.top=`${Math.max(o,Math.min(f,i-c-o))}px`,t.dataset.side=h?"top":"bottom",e.style.left=`${Math.max(r,Math.min(b-m,s-r))}px`})(pt,nt,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let a=null;for(const i of n){const t=i.getBoundingClientRect();(t.width||t.height)&&(a=a?new DOMRect(Math.min(a.left,t.left),Math.min(a.top,t.top),Math.max(a.right,t.right)-Math.min(a.left,t.left),Math.max(a.bottom,t.bottom)-Math.min(a.top,t.top)):t)}if(a)return a;const o=t.plot.getBoundingClientRect(),[r,s,c,l]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(o.left+o.width*r/100,o.top+o.height*s/100,o.width*c/100,o.height*l/100)})(t,e))},St=t=>{wt===t&&Mt()},Ht={area:st,bar:I,column:G,donut:J,line:rt,waterfall:lt},Tt={"axis-break":N,trend:U,bracket:L},zt=Object.keys(Tt),Ct=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},Lt=["straight","step","smooth"],Ot=(t,e)=>{const n=t.dataset.chartShape;return n&&Lt.includes(n)?n:Lt.includes(e.shape)?e.shape:"straight"},Bt=0,Ut=(n,a,o=null)=>{const r=o??(n.getAttribute("data-chart")||"column"),s=Ht[r];if(!s)return console.warn(`[${t}] Unknown chart type "${r}". Known types: ${Object.keys(Ht).join(", ")}.`),n.setAttribute("data-chart-empty",""),null;const l=((t,e="data-i18n")=>Array.from(t.querySelectorAll("tbody tr")).map((t,n)=>{const a=t.querySelector("th"),o=Array.from(t.querySelectorAll("td")).map(ut);return o.length||o.push(ut(null)),{...o[0],label:(a?.textContent||"").trim(),key:e&&a?.getAttribute(e)||null,cells:o,classes:Array.from(t.classList),isTotal:"total"===t.getAttribute("data-kind"),slot:n}}))(n,a.langattribute);if(!l.length)return console.warn(`[${t}] A chart has no rows in its table, so there is nothing to draw.`),n.setAttribute("data-chart-empty",""),null;(t=>{const e=t.querySelector(":scope > figcaption");if(!e)return;(t=>{for(const e of t.querySelectorAll("br")){if(e.previousElementSibling?.classList.contains("tablechart-sr"))continue;if(/[.!?:;,…]$/.test(Ct(e)))continue;const t=document.createElement("span");t.className=d,t.textContent=". ",e.before(t)}})(e);const n=t=>t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"),a=t=>{e.id||(e.id="tablechart-caption-"+ ++Bt),t.setAttribute("aria-labelledby",e.id)};"FIGURE"!==t.tagName||n(t)||a(t);const o=t.querySelector("table");!o||n(o)||o.querySelector(":scope > caption")||a(o)})(n);let u=((t,e,n="data-i18n")=>{const a=dt(t),o=Math.max(1,S(e.map(t=>t.cells.length)));return Array.from({length:o},(t,e)=>{const o=a[e];return{name:(o?.textContent||"").trim(),key:n&&o?.getAttribute(n)||null,focus:"focus"===o?.getAttribute("data-kind"),marker:o?.getAttribute("data-marker")??null,line:(r=o?.getAttribute("data-line"),"dashed"===r||"dotted"===r?r:null)};var r})})(n,l,a.langattribute);u.length>1&&!s.series&&(console.warn(`[${t}] A ${r} chart uses only the first of its ${u.length} value columns.`),u=u.slice(0,1));const h=u.length>1;h&&n.style.setProperty("--_series-count",String(u.length));const f=n.hasAttribute("data-chart-stack");f&&!s.stackable&&console.warn(`[${t}] A ${r} chart cannot be stacked.`);const b=f&&!!s.stackable&&h,m=document.createElement("div");m.className="tablechart-plot",m.setAttribute("aria-hidden","true");const g=$("svg",{role:"presentation",focusable:"false"});m.appendChild(g),n.appendChild(m);const p=s.centre?l.filter(t=>!t.isTotal):l,w=Math.max(0,S(p.flatMap(t=>t.cells.slice(0,u.length).map(t=>H(t.number))))),y=u.map((t,n)=>l.map((t,a)=>{const o=t.cells[n]??t.cells[0],r=M(e,m);return r.classList.add(...t.classes),r.dataset.value=String(o.value),o.prefix&&(r.dataset.prefix=o.prefix),o.suffix&&(r.dataset.suffix=o.suffix),o.missing&&(r.dataset.missing=o.raw),h&&(r.dataset.series=String(n+1)),r.dataset.row=String(a+1),r.style.setProperty("--i",String(t.slot)),r})),v=y[0],k=b&&s.totals?l.map((t,n)=>{const a=M(e,m);a.classList.add(...t.classes),a.dataset.kind="total",a.dataset.row=String(n+1),a.dataset.value=String(P(t,u.length));const o=t.cells[0];return o.prefix&&(a.dataset.prefix=o.prefix),o.suffix&&(a.dataset.suffix=o.suffix),a.style.setProperty("--i",String(t.slot)),a}):[],x=l[l.length-1],A=u.some(t=>t.focus),N=n.getAttribute("data-chart-legend"),T=h&&(null===N?a.legend||void 0!==s.legend:"false"!==N)?document.createElement("div"):null;T&&(T.className=c,T.setAttribute("aria-hidden","true"),T.inert=!0);const z=h?u.map((t,e)=>{const o=M("tablechart-name",T??m);T&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=t.name,!r&&"step"!==Ot(n,a)){const t=X(u,e);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return t.line&&!r&&(o.dataset.line=t.line),t.key&&a.langattribute&&o.setAttribute(a.langattribute,t.key),o.dataset.series=String(e+1),o.style.setProperty("--n",String(e)),o.style.setProperty("--palette",`var(--tablechart-color-${e+1})`),o.style.setProperty("--m",A&&!t.focus?"1":"0"),o.style.setProperty("--i",String(x.slot)),o}):[],C=s.centre?M(i,m):null;if(C){const t=l.find(t=>t.isTotal),e=t?t.value:l.reduce((t,e)=>t+Math.abs(e.value),0);C.dataset.value=String(e),t&&(C.dataset.decimals=String(H(t.number)))}const L=C&&!l.some(t=>t.isTotal)?((t,e,n)=>{const a=t.querySelector("table");if(!a)return null;const o=a.querySelector("tfoot [data-chart-total]");if(o)return o.dataset.value=e.dataset.value??"0",o;const r=(a.tFoot??a.createTFoot()).insertRow(),s=document.createElement("th");s.scope="row",s.textContent=n.totallabel;const c=t.getAttribute("data-chart-keys");c&&n.langattribute&&s.setAttribute(n.langattribute,`${c}-total`);const l=r.insertCell();return l.setAttribute("data-chart-total",""),l.dataset.value=e.dataset.value??"0",r.prepend(s),l})(n,C,a):null,O="beside"===s.categories,B=document.createElement("div");B.className="tablechart-categories",B.setAttribute("aria-hidden","true"),B.inert=!0,O?B.dataset.place="beside":s.centre&&(B.dataset.place="key"),B.style.setProperty("--_columns",String(l.length));let U=0;for(const[t,e]of l.entries()){const n=document.createElement("span");n.classList.add(...e.classes),n.textContent=e.label,e.key&&a.langattribute&&n.setAttribute(a.langattribute,e.key),s.centre&&(n.dataset.kind=e.isTotal?"total":"slice",e.isTotal||(n.dataset.slice=String(U+1),n.style.setProperty("--n",String(U)),n.style.setProperty("--palette",`var(--tablechart-color-${U+1})`),U+=1)),n.style.setProperty("--i",String(e.slot)),n.dataset.row=String(t+1),B.appendChild(n)}(O?m:n).appendChild(B),T&&n.appendChild(T);const _=a.animate?(t=>{const e=t.hasAttribute("data-fragment"),n=Array.from(t.querySelectorAll("tbody tr")),a=Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),o=Array.from(t.querySelectorAll("[data-annotation]")).filter(t=>ht.includes(t.getAttribute("data-annotation")??"")),r=t=>t.hasAttribute("data-fragment"),s=n.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(e||n.some(r)||a.some(r)||s.flat().some(r)||o.some(r)))return null;const c=[],l=new Map,i=[],u=t=>{let e=null!==t?l.get(t):void 0;return void 0===e&&(e=c.length,c.push(t),i.push(0),null!==t&&l.set(t,e)),e};let d=0;const h="donut"===t.getAttribute("data-chart"),f=t=>h&&"total"===t.getAttribute("data-kind"),b=n.map(t=>{if(f(t))return{step:null,slot:0};if(!e&&!r(t))return{step:null,slot:d++};const n=u(t.getAttribute("data-fragment-index"));return{step:n,slot:i[n]++}}),m=Math.max(-1,...b.map(t=>t.step??-1));if(m>=0)for(const[$,y]of n.entries())f(y)&&(b[$]={step:m,slot:i[m]++});const g=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),p=s.map(t=>t.map(()=>({step:null,slot:0}))),w=Math.max(0,...s.map(t=>t.length));for(let $=0;$<w;$++)for(const[t,e]of s.entries()){const n=e[$];if(!n||!r(n))continue;const a=u(n.getAttribute("data-fragment-index"));p[t][$]={step:a,slot:i[a]++}}return{rows:b,series:g,cells:p,notes:o.map(t=>{const e=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n},[n,a]="bracket"===t.getAttribute("data-annotation")?[e("data-from",0),e("data-to",b.length-1)]:[0,b.length-1];let o=null;for(let r=Math.min(n,a);r<=Math.max(n,a);r++)for(const t of[b[r]?.step??null,...(p[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=g[e("data-series",0)]?.step??null;null!==s&&(null===o||s>o)&&(o=s),r(t)&&(o=u(t.getAttribute("data-fragment-index")));const c=null===o?b.length:b.filter(t=>t.step===o).length;return{step:o,after:c}}),count:c.length,indexes:c}})(n):null;_&&n.setAttribute("data-steps","");const E=n.getAttribute("data-chart-keys"),F=_&&a.controls?((t,e,n)=>{const a=document.createElement("div");a.className="tablechart-controls";const o=a=>{const o=document.createElement("button");o.type="button",o.className=`tablechart-${a}`,o.dataset.go=a;const r=document.createElement("span");r.className="tablechart-control-icon",r.setAttribute("aria-hidden","true");const s=$("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild($("path",{d:"next"===a?"M6 3l5 5-5 5":"M10 3L5 8l5 5"})),r.appendChild(s);const c=document.createElement("span");c.className="tablechart-control-label",c.textContent=t[a];const l=e[a];l&&n&&c.setAttribute(n,l);const i=document.createElement("span");return i.className=d,i.textContent=t.hint,e.hint&&n&&i.setAttribute(n,e.hint),o.append(..."next"===a?[c,i,r]:[r,c,i]),o};return a.append(o("previous"),o("next")),a})({previous:a.previouslabel,next:a.nextlabel,hint:a.stephint},{previous:E&&`${E}-previous`,next:E&&`${E}-next`,hint:E&&`${E}-step`},a.langattribute):null;F&&n.appendChild(F);const j=n.getAttribute("data-chart-table"),q=j&&Et.includes(j)?j:a.table;if("never"===q)n.removeAttribute("data-table");else{n.setAttribute("data-table",q);const t=n.querySelector(":scope > table");t&&n.append(t)}const R=Array.from(n.querySelectorAll("[data-annotation]")).map(e=>{const n=e.getAttribute("data-annotation"),a=Tt[n];if(!a)return console.warn(`[${t}] Unknown annotation "${n}". Known annotations: ${Object.keys(Tt).join(", ")}.`),null;const o=Number.parseInt(e.getAttribute("data-series")??"1",10),r=o>=1&&o<=u.length?o-1:0;return o!==r+1&&console.warn(`[${t}] An annotation reads line ${o}, which is not there; it reads line 1.`),{spec:e,type:a,badge:a.create(e,m),series:r,after:l.length}}).filter(t=>null!==t);a.animate&&n.setAttribute("data-animate",jt(n,r,a,Boolean(_)));const W={figure:n,plot:m,svg:g,rows:l,decimals:w,type:s,values:v,series:u,seriesValues:y,names:T?[]:z,categories:Array.from(B.children),centre:C,stacked:b,totals:k,totalCell:L,rowAt:null,rowBox:null,annotations:R,checks:[],plan:_,step:0,controls:F};F?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&bt(W,W.step+("next"===e?1:-1))}),bt(W,0,!0);const D=n.getAttribute("data-chart-tooltip")??n.getAttribute("data-chart-hover"),V="false"!==D&&("auto"===D?"auto":null!==D||!1!==a.hover&&a.tooltip);return V&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover","");const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return wt===t?Mt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=n.width/a.offsetWidth||1;return t.rowAt((e.clientX-n.left)/o,(e.clientY-n.top)/o)}const n=e.target.closest?.("[data-row]")?.getAttribute("data-row");return n?Number(n)-1:null})(o);if(s=c,null===c||r(c))return wt===t?vt():void 0;Nt(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||Nt(t,c,e)};t.svg.addEventListener("transitionend",i),t.svg.addEventListener("transitioncancel",i),a.addEventListener("pointermove",c),a.addEventListener("pointerdown",c),a.addEventListener("pointerleave",e=>{"mouse"===e.pointerType&&(s=null,wt===t&&vt())})})(W,a,"auto"===V),Wt(W,a),W},_t={grow:"grow",sweep:"sweep"},Et=["never","auto","print","always"],Ft={..._t,up:"grow",across:"sweep"},jt=(t,e,n,a)=>{const o="line"===e||"area"===e,r=o?Ft:_t,s=r[t.getAttribute("data-chart-animate")??""]??r[String(n.animate)];return o?a?"sweep":s??"sweep":"donut"===e||"waterfall"===e?s??"grow":"grow"},Pt=t=>{const e=getComputedStyle(t),n=(e.getPropertyValue("--tablechart-value-align")||e.getPropertyValue("--tablechart-inside-align")).trim();return"start"===n||"center"===n||"end"===n?n:null},qt=(t,e,n,a)=>{const o=getComputedStyle(t),r=(o.getPropertyValue(n).trim()||a).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);if(!r)return null;const s=Number(r[1]);return"%"===r[2]?s/100*f:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},Rt=(t,e)=>qt(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,Wt=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const a of t.centre?[...n,t.centre]:n){const{missing:n,prefix:o="",suffix:r=""}=a.dataset;if(void 0!==n){a.textContent=n;continue}const s=Number.parseFloat(a.dataset.value||"0"),c=a.dataset.decimals?Number(a.dataset.decimals):t.decimals,[l,i]=T(s,c,e.locale);if(a.textContent=o+(o?l:"")+i+r,l&&!o){const t=document.createElement("span");t.className="tablechart-minus",t.textContent=l,a.prepend(t)}}},Dt=(t,e)=>{t.figure.classList.toggle("is-shown",e)},Vt=t=>"id"===t||"style"===t||t.startsWith("data-chart"),Kt=/^\s*(?:Table)?:\s+/,It=t=>"P"===t?.tagName&&Kt.test(t.textContent??""),Gt=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,Zt=t=>{const e=Qt(t);return"P"===e?.tagName?e:t},Jt=t=>{if(!t||"object"!=typeof t)return;const e=Object.entries(t),n=t=>null===t||"string"==typeof t||"number"==typeof t;return e.length&&e.every(([,t])=>n(t)||Array.isArray(t)&&t.every(n))?e.map(([t,e])=>Array.isArray(e)?{label:t,values:e}:{label:t,value:e}):void 0},Qt=t=>{const e=Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&t.textContent?.trim());return 1===e.length&&e[0]instanceof HTMLElement?e[0]:null},Xt="strong, b, span.total",Yt="data-chart-made",te=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,ee=new Set,ne=null,ae=["column","bar"],oe=t=>{const e=t.getAttribute("data-chart")||"column";if(!ae.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return ae.includes(n)?n:e},re=async(e,n)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=It(e)?e:t;if("TABLE"!==n.tagName&&"P"!==n.tagName)return n;const a=document.createElement("div");((t,e)=>{for(const{name:n,value:a}of Array.from(t.attributes))("class"===n||Vt(n))&&(e.setAttribute(n,a),t.removeAttribute(n))})(t,a),t.classList.length||t.removeAttribute("class");const o="TABLE"===n.tagName?n:null,r=n.previousElementSibling;let s=n.nextElementSibling;const c=o?It(r)?r:It(s)?s:null:n;o&&c===s&&(s=s?.nextElementSibling??null);const l=s?.classList.contains("chart-annotations")?s:(t=>{if("UL"!==t?.tagName&&"OL"!==t?.tagName)return null;const e=Array.from(t.children),n=e.map(t=>t.hasAttribute("data-annotation")?null:(t=>{const e=Zt(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Gt.exec(e.textContent??"");if(!n||!zt.includes(n[1]))return null;if(!n[3]&&e.nextSibling)return null;const a=n[2].trim().split(/\s+/).filter(Boolean).map(t=>t.split("="));return{name:n[1],options:a,text:e,length:n[0].length}})(t));return!e.length||e.some((t,e)=>!n[e]&&!t.hasAttribute("data-annotation"))?null:(e.forEach((t,e)=>{const a=n[e],o=Zt(t);if(o!==t&&o.replaceWith(...o.childNodes),a){t.setAttribute("data-annotation",a.name);for(const[e,n]of a.options)t.setAttribute(`data-${e}`,n);a.text.textContent=(a.text.textContent??"").slice(a.length)}t.children.length&&Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.textContent?.trim()).forEach((t,e)=>{const n=document.createElement("span");0===e&&t instanceof HTMLElement&&t.matches("em, i")?(n.className="tablechart-caption",n.append(...t.childNodes),t.replaceWith(n)):t.nodeType===Node.TEXT_NODE&&(n.textContent=(t.textContent??"").trim(),t.replaceWith(n))})}),t.classList.add("chart-annotations"),t)})(s);return n.replaceWith(a),c&&a.append((t=>{const e=document.createElement("figcaption");for(const{name:r,value:s}of Array.from(t.attributes))e.setAttribute(r,s);const n=t.firstChild;n?.nodeType===Node.TEXT_NODE&&(n.textContent=(n.textContent??"").replace(Kt,""),n.textContent||n.remove());const a=Array.from(t.childNodes),o=a.findIndex(t=>"BR"===t.nodeName);if(e.append(...-1===o?a:a.slice(0,o+1)),-1!==o&&o<a.length-1){const t=document.createElement("span");t.append(...a.slice(o+1)),e.append(t)}return t.remove(),e})(c)),o&&a.append(o),l&&a.append(l),it?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(e.filter(t=>!t.hasAttribute(Yt)));return await(async e=>{await Promise.all(e.filter(t=>t.hasAttribute("data-chart-src")).map(async e=>{const n=e.getAttribute("data-chart-src"),a=Array.from(e.querySelectorAll("table")).find(t=>t.tHead)??null;for(const t of e.querySelectorAll("table"))t!==a&&t.remove();try{const t=await fetch(n);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);const o=await t.json(),r=Array.isArray(o)?o:o?.rows?Array.isArray(o.rows)?o.rows:Jt(o.rows):Jt(o);if(!Array.isArray(r))throw new Error("no rows in it: a list of rows, an object with rows, or names with their values");const s=((t,e,n,a=document.createElement("table"))=>{for(const r of a.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr"))r.remove();if(!a.tHead&&(e.length||n)){const t=a.createTHead().insertRow(),o=document.createElement("th");o.textContent=n,t.append(o);for(const n of e){const e=document.createElement("th");e.textContent=n,t.append(e)}}const o=document.createElement("tbody");a.append(o);for(const r of t){const t=o.insertRow();"total"===r.kind&&(t.dataset.kind="total");const e=document.createElement("th");e.textContent=String(r.label??""),t.append(e);for(const n of r.values??[r.value??null])t.insertCell().textContent=null===n?"":String(n)}return a})(r,Array.isArray(o?.series)?o.series.map(String):[],"string"==typeof o?.label?o.label:"",a??void 0);if(!a){const t=e.querySelector(":scope > figcaption");t?t.after(s):e.prepend(s)}s.tHead||it?.log?.(`The table from "${n}" has no header row, so a screen reader cannot name its columns.`),it?.log?.(`Read ${r.length} rows from "${n}"`)}catch(o){const e="file:"===window.location.protocol;console.warn(`[${t}] Could not read the chart data in "${n}": ${o.message}.`+(e?" A page opened as a file cannot fetch files; open it from a server.":""))}}))})(a),(t=>{for(const e of t){for(const n of e.querySelectorAll("tbody tr")){const t=n.cells[0];if("TD"!==t?.tagName||n.cells.length<2)continue;const e=document.createElement("th");for(const{name:n,value:a}of Array.from(t.attributes))e.setAttribute(n,a);e.append(...t.childNodes),t.replaceWith(e);for(let a=Qt(e);a?.matches(Xt);a=Qt(e))n.dataset.kind="total",a.replaceWith(...a.childNodes)}const t=Array.from(e.querySelector("thead tr:last-child")?.children??[]);for(const e of t.slice(1))for(let t=Qt(e);t?.matches(Xt);t=Qt(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(a),((e,n)=>{if(!n)return;const a=new Map;for(const o of e){let e=o.getAttribute("data-chart-keys")||null;if(!e)continue;if(a.has(e)){const n=a.get(e)+1;a.set(e,n),console.warn(`[${t}] Two charts have data-chart-keys="${e}", so this one uses "${e}-${n}" to keep their translations apart.`),e=`${e}-${n}`}else a.set(e,1);o.querySelectorAll("tbody th").forEach((t,a)=>{t.getAttribute(n)||t.setAttribute(n,`${e}-row${a+1}`)});const r=dt(o);r.length>1&&r.forEach((t,a)=>{t.getAttribute(n)||t.setAttribute(n,`${e}-col${a+1}`)}),it?.log?.(`Keys for "${e}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,n.langattribute),a},se=(e,a)=>{const o=it.timed("Building",e,()=>Ut(e,a));return o?(e.setAttribute(Yt,""),((e,a)=>{let o=e,r=oe(o.figure),u=null,d=!1,b=!1;const m=async()=>{if(!a.animate)return Dt(o,!0);const t=o.figure.classList.contains("is-shown");if(!d||null===u||t||b)!d&&a.replay&&t&&Dt(o,!1);else{b=!0;const t=te()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(o.figure);t&&await(e=t,new Promise(t=>{const n=["animationstart","transitionrun"],a=()=>{for(const t of n)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(e)&&a()},r=new MutationObserver(()=>{"0"!==getComputedStyle(e).opacity&&a()});for(const e of n)document.addEventListener(e,o,!0);r.observe(e,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(te())return;await new Promise(requestAnimationFrame);const n=t.getAnimations().filter(t=>t instanceof CSSAnimation);for(let r=t.parentElement;r&&r!==document.body;r=r.parentElement)n.push(...r.getAnimations());let a=0;for(const r of n){const t=r.effect?.getComputedTiming(),n=Number(t?.activeDuration??0);if(!t||!Number.isFinite(n))continue;const o=Number(t.delay??0)+n*e;a=Math.max(a,o-Number(r.currentTime??0))}var o;a>0&&await(o=a,new Promise(t=>setTimeout(t,o)))})(o.figure,((t,e)=>{const n=Number.parseFloat(t.dataset.chartEntrance??""),a=Number.isFinite(n)?n:e.entrance;return Math.min(Math.max(a,0),1)})(o.figure,a)),b=!1,!d&&a.replay||Dt(o,!0)}var e},p=()=>{const t=oe(o.figure);if(!t||t===r)return;const e=it.timed("Building",o.figure,()=>Ut(o.figure,a,t));e&&((t=>{St(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${c}`)?.remove(),t.controls?.remove()})(o),bt(e,o.step,!0),o=e,r=t,u=null)},y=()=>{p();const e=o.plot.clientWidth;e&&e!==u&&it.timed("Layout",o.figure,()=>((e,a)=>{const{plot:o,svg:r,rows:c,type:u,values:d,series:h,seriesValues:b,names:m,annotations:p}=e,y=o.clientWidth;if(!y)return!1;const M=f/y,v=Number.parseFloat(e.figure.dataset.chartAspect??""),k=f*(v>0?v:u.aspect??a.aspect);o.classList.add("is-placed");for(const t of[...b.flat(),...e.totals])delete t.dataset.place;o.style.removeProperty("--_fit"),e.categories[0]?.parentElement?.style.removeProperty("--_beside"),(t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>O.set(t,n[e]))})([...b.flat(),...e.totals,...m,...e.categories,...p.map(t=>t.badge)]);const A=(d[0]?B(d[0]).height:0)*M,N=p[0]?.badge?B(p[0].badge).height*M:0,H=Math.max(k,qt(e.figure,M,"--tablechart-min-height","200px")??0,u.minHeight?.({labelHeight:A,nameHeight:Math.max(0,S(e.categories.map(t=>B(t).height)))*M,unit:M,rows:c.length,series:h.length,stacked:e.stacked})??0),T=e.stacked?c.map(t=>{const e=P(t,h.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):c,z=(u.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(e.stacked?T.map(t=>({...t,cells:[t.cells[0]]})):c),C={labelHeight:A,badgeHeight:N,hasAnnotations:p.length>0,unit:M,series:h.length,focused:h.some(t=>t.focus),stacked:e.stacked},L=Math.max((U=S,e.stacked?U(c.map(t=>j(t,h.length,u.running).top)):U([...z.flatMap(t=>[t.from,t.to,t.value]),...c.flatMap(t=>t.cells.slice(0,h.length).map(t=>t.value))])),0);var U;const _=z.some(t=>"up"===t.kind||"down"===t.kind)?z.flatMap(t=>[t.from,t.to]):e.stacked?c.map(t=>j(t,h.length,u.running).bottom):c.flatMap(t=>t.cells.slice(0,h.length).map(t=>t.value)),E=Math.min(-S(_.map(t=>-t)),0),F=u.headroom?.(C)??A,q=2*M+(u.footroom?.(C)??0)+(E<0?A+4*M:0),R=H-F-q,W=1.02*L,D=1.02*E,V=p.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,I=t=>{const e=Number.parseFloat(V?.getAttribute(t)??"");return Number.isFinite(e)?e:null},G=I("data-from")??I("data-at"),Z=I("data-to");let J=null;if(V&&(null!==G||null!==Z)){const e=G??0,n=Z??W,a=null===Z?e:null===G?n:(e+n)/2,o=V.getAttribute("data-size"),r=o?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===o||r||console.warn(`[${t}] data-size="${o}" is not a percentage, such as 30%. Using the default.`);const s=Math.min(Math.max(r?Number(r[1])/100:null===Z?.22:.3,.05),.8),c=z.filter(t=>("up"===t.kind||"down"===t.kind)&&Math.max(t.from,t.to)>e&&Math.min(t.from,t.to)<n);u.breakable?E<0?console.warn(`[${t}] A chart with values below zero cannot break its scale.`):e<0||n<=e||n>W||0===e&&n===W?console.warn(`[${t}] A break from ${e} to ${n} does not fit a scale that runs from 0 to ${L}.`):c.length?console.warn(`[${t}] A break from ${e} to ${n} would cut a step that floats. Keep it below or above the steps.`):J={lo:e,hi:n,gap:a,share:s}:console.warn(`[${t}] This kind of chart cannot break its scale.`)}const Q=J?J.gap:null,X=(J&&qt(e.figure,M,"--tablechart-break-gap",""))??13,Y=H-q,tt=W-D||1;let et=t=>Y-(t-D)/tt*R;if(J){const{lo:t,hi:e,gap:n,share:a}=J,o=R*a,r=(R-o-X)/(t+(W-e)),s=o/(e-t);et=a=>a<=t?Y-a*r:a<=n?Y-t*r-(a-t)*s:a<=e?Y-t*r-(a-t)*s-X:Y-t*r-o-X-(a-e)*r}const nt=m.length?S(m.map(t=>B(t).width))*M+12*M:0,at=e.categories[0]?.parentElement;at&&(at.style.paddingRight=nt?nt/f*100+"%":"");const ot=(f-nt)/c.length,rt=t=>t>=0&&t<c.length?t:null;e.rowAt=u.centre?null:"beside"===u.categories?(t,e)=>rt(Math.floor(e*M/(H/c.length))):t=>rt(Math.floor(t*M/ot));const st=ot/f*100,ct=100/c.length;e.rowBox="beside"===u.categories?t=>[0,t*ct,100,ct]:t=>[t*st,0,st,100],r.setAttribute("viewBox",`0 0 1000 ${w(H)}`),r.textContent="",e.checks=[];const lt={rows:c,segments:z,cx:t=>(t+.5)*ot,y:et,barWidth:Math.min(ot*a.barfill,Rt(e.figure,M)),barMax:Rt(e.figure,M),height:H,unit:M,labelHeight:A,badgeHeight:N,after:c.length,note:0,labels:"inside"===e.figure.dataset.chartLabels||"outside"!==e.figure.dataset.chartLabels&&"inside"===a.labels?"inside":"outside",insideAlign:Pt(e.figure),breakAt:Q,squeeze:J,breakGap:X,stacked:e.stacked,shape:Ot(e.figure,a),totals:e.totals,svg:r,plot:o,values:d,series:h,seriesValues:b,names:m,categories:e.categories,centre:e.centre,config:a,checks:e.checks};o.style.setProperty("--count",String(Math.max(1,...c.map(t=>t.slot+1)))),u.draw(lt);for(const[t,n]of p.entries()){n.badge?.setAttribute("data-note",String(t+1));const a=n.series,o=t=>({...t,...t.cells[a]??t.cells[0]});n.type.draw(n.spec,n.badge,{...lt,...e.stacked&&{rows:T,...e.totals.length&&{values:e.totals}},...a>0&&!e.stacked&&{rows:c.map(o),segments:z.map(t=>{const e=o(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:b[a]},after:n.after,note:t+1})}(t=>{const e=t.plan;if(!e)return;const a=e.rows.length-1,o=t=>e.series.map((n,a)=>e.cells[t]?.[a]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=o(t);return e.some(t=>null===t)?null:Math.min(...e)},c=new Set(t.totals),l=(t,e,n,a)=>{t.style.setProperty(n,String(a)),t.style.removeProperty("--d"),null===e?t.style.removeProperty("--step"):t.style.setProperty("--step",String(e))};for(const n of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(n.closest("table, .tablechart-controls")||n.hasAttribute("data-from"))continue;const t=Number(n.dataset.note);if(t>0){const a=e.notes[t-1];a&&l(n,a.step,"--after",a.after);continue}const s=n.dataset.row?Number(n.dataset.row)-1:a;if(n.classList.contains("tablechart-connector")){const t=e.rows[s-1],a=e.rows[s];if(t&&a){const e=(t.step??-1)>(a.step??-1);l(n,e?t.step:a.step,"--i",e?t.slot+1:a.slot)}continue}if(c.has(n)){const t=o(s).filter(t=>null!==t);l(n,t.length?Math.max(...t):null,"--i",e.rows[s]?.slot??0);continue}if(n.hasAttribute("data-stack")){l(n,r(s),"--i",e.rows[s]?.slot??0);continue}const i=n.dataset.series?Number(n.dataset.series)-1:0,u=n.dataset.series?e.series[i]:void 0;if(n.classList.contains("tablechart-piece")){const t=o(s)[i]??null,a=e.cells[s]?.[i];l(n,t===r(s)?null:t,"--i",a&&null!==a.step?a.slot:s);continue}if("legend"===n.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(n,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[s]?.[i];d&&null!==d.step?l(n,d.step,"--i",d.slot):u&&null!==u.step?l(n,u.step,"--i",s):e.rows[s]&&l(n,e.rows[s].step,"--i",e.rows[s].slot)}const u=t.figure.querySelector(`.${i}`);if(u){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?l(u,null,"--i",0):l(u,n,"--i",t.filter(t=>t===n).length)}const d=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),h=e.series.some(t=>null!==t.step)?e.rows.length:1;t.plot.style.setProperty("--count",String(Math.max(h,...d)));const f=t.figure.querySelectorAll(`.${n}`),b=f[f.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&f.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${s}`));if(m.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=m.length,o=Math.max(0,m.findIndex((t,n)=>e(t)!==e(m[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=m[(o+t)%a],s=r[r.length-1];s&&e(s[0])===e(n)?s.push(n):r.push([n])}const s=new Map;for(const t of r){const e=t.reduce((t,e)=>t+n(e),0);let a=0;for(const o of t)s.set(o.dataset.row??"",g(a,n(o),e)),a+=n(o)}for(const c of t.figure.querySelectorAll("[data-row]")){const t=s.get(c.dataset.row??"");t&&c.style.getPropertyValue("--start")&&(c.style.setProperty("--start",t.start.toFixed(4)),c.style.setProperty("--span",t.span.toFixed(4)),c.classList.contains("tablechart-slice")&&c.style.setProperty("--ease",t.easing))}}ft(t)})(e);const it=e.categories[0]?.parentElement;it&&"beside"!==u.categories&&!u.centre&&K(it,e.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const ut=p.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*M,n=t.offsetHeight*M,a=Number.parseFloat(t.style.left)/100*f,o=Number.parseFloat(t.style.top)/100*H,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*M;return[$("rect",{class:l,"data-for":"badge","data-note":t.dataset.note??"",x:a-e/2,y:o-n/2,width:e,height:n,rx:null===s?c:e*s,ry:null===s?c:n*s,style:["--after","--step"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ")})]});x(r,ut,f,H);const dt=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return e.figure.toggleAttribute("data-left-out",[...b,e.totals].some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||u.centre&&c[Number(t.dataset.row)-1]?.isTotal)(e)&&!dt(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>dt(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(o,a))&&(u=e,m())};let M=!1;const v=new ResizeObserver(()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,y()}))}),k=new IntersectionObserver(t=>{for(const e of t)d=e.isIntersecting,m()},{threshold:a.threshold}),A=()=>{o.figure.classList.add(h),Dt(o,!0),o.figure.offsetWidth},N=()=>o.figure.classList.remove(h),H=()=>{u=null,y()},T={relabel:()=>Wt(o,a),refresh:H};p(),y(),v.observe(o.figure),k.observe(o.figure),window.addEventListener("beforeprint",A),window.addEventListener("afterprint",N),(t=>{ee.add(t),ne||(ne=new MutationObserver(()=>{for(const t of ee)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of ee)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(T);const z={figure:o.figure,refresh:H,next:()=>bt(o,o.step+1),previous:()=>bt(o,o.step-1),stepTo:t=>bt(o,t),get step(){return o.step},get steps(){return o.plan?.count??0},destroy(){v.disconnect(),k.disconnect(),window.removeEventListener("beforeprint",A),window.removeEventListener("afterprint",N),(t=>{ee.delete(t),!ee.size&&ne&&(ne.disconnect(),ne=null)})(T),St(o),o.figure.tablechart===z&&delete o.figure.tablechart}};return o.figure.tablechart=z,z})(o,a)):null},ce=[["--tablechart-duration","--tablechart-animation-element-duration"],["--tablechart-stagger","--tablechart-animation-stagger, a share of the element time"],["--tablechart-easing","--tablechart-animation-ease"],["--tablechart-category-size","--tablechart-name-size"],["--tablechart-category-padding","--tablechart-name-padding"],["--tablechart-categories-gap","--tablechart-name-gap"],["--tablechart-inside-align","--tablechart-value-align"],["--tablechart-bar-ink","--tablechart-bar-value-color"],["--tablechart-piece-ink","--tablechart-piece-value-color"],["--tablechart-up-ink","--tablechart-up-value-color"],["--tablechart-down-ink","--tablechart-down-value-color"],["--tablechart-total-ink","--tablechart-total-value-color"],["--tablechart-series-ink","--tablechart-series-own-color"],["--tablechart-dash","--tablechart-series-dash"],["--tablechart-dot","--tablechart-series-dot"],["--tablechart-muted-share","--tablechart-series-muted-share"],["--tablechart-rule-color","--tablechart-baseline-color"],["--tablechart-rule-width","--tablechart-baseline-width"],["--tablechart-rule-opacity","--tablechart-baseline-opacity"],["--tablechart-key-size","--tablechart-legend-key-size"],["--tablechart-controls-justify","--tablechart-control-justify"],["--tablechart-controls-gap","--tablechart-control-gap"]],le={up:"grow",across:"sweep"},ie=!1;window.Tablechart={init:async(e={},n=document)=>{const a={...b,...e};a.debug&&(it.enabled=!0);const o=await re(Array.from(n.querySelectorAll(a.selector)),a);((e,n)=>{if(ie)return;const a=t=>{const e=le[String(t)];return e?[`"${t}" is now "${e}"`]:[]},o=new Set(a(n.animate));void 0!==n.hover&&o.add('the "hover" option is now "tooltip"');for(const t of e){t.hasAttribute("data-chart-hover")&&o.add("data-chart-hover is now data-chart-tooltip");const e=getComputedStyle(t);for(const[t,n]of ce)e.getPropertyValue(t).trim()&&o.add(`${t} is now ${n}`);for(const n of a(t.getAttribute("data-chart-animate")))o.add(n)}o.size&&(ie=!0,console.warn(`[${t}] ${[...o].join("; ")}. The old names work until the next minor version.`))})(o,a);const r=o.map(t=>se(t,a)).filter(t=>null!==t);return it.log(`Made ${r.length} chart(s).`),{charts:r,refresh:()=>{for(const t of r)t.refresh()},destroy:()=>{for(const t of r)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...b,...e};n.debug&&(it.enabled=!0);const[a]=await re([t],n);return a?se(a,n):null},defaultConfig:b}}();
1
+ !function(){var t="tablechart",e="tablechart-value",n="tablechart-bar",a="tablechart-rule",o="tablechart-line",r="tablechart-head",s="tablechart-slice",c="tablechart-legend",l="tablechart-hole",i="tablechart-centre",u="tablechart-break",d="tablechart-sr",h="is-printing",f=1e3,b={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",shape:"straight",legend:!1,tooltip:"auto",table:"never",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},m="cubic-bezier(0.3, 0.3, 0.6, 1)",g=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?m:"linear"}),p=(t,e)=>`${t}:${e}`,w=t=>Math.round(100*t)/100,$=(t,e={})=>{const n=document.createElementNS("http://www.w3.org/2000/svg",t);for(const a in e){const t=e[a];n.setAttribute(a,String("number"==typeof t?w(t):t))}return n},y=(t,e)=>[t,...e.classes].join(" "),M=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},v=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},k=0,x=(t,e,n,a)=>{if(!e.length)return;const o="tablechart-cut-"+ ++k,r=$("mask",{id:o,maskUnits:"userSpaceOnUse"});r.appendChild($("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const l of e)l.setAttribute("fill","black"),r.appendChild(l);let s=t.querySelector(":scope > defs");s||(s=$("defs"),t.prepend(s)),s.appendChild(r);const c=$("g",{mask:`url(#${o})`});for(const l of Array.from(t.childNodes))l!==s&&c.appendChild(l);t.appendChild(c)},A=0,N={create:()=>null,draw(t,e,a){const{rows:o,y:r,svg:s,breakAt:c}=a;if(null===c)return;const l="zigzag"===t.getAttribute("data-mark"),i=(t,e)=>{const n=t.sideways?t.height:t.width,a=.09*n,o=n+2*a,r=.3*o,s=.06*o;if(t.sideways){const n=t.y-a;if(!l)return[[e-r/2,n],[e+r/2,n+o]];const c=o/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+o]]}const c=t.x-a;if(!l)return[[c,e+r/2],[c+o,e-r/2]];const i=o/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+o,e-s]]},d=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),h="tablechart-break-"+ ++A,f=$("mask",{id:h,maskUnits:"userSpaceOnUse"});f.appendChild($("rect",{x:-1e3,y:-a.height,width:3e3,height:3*a.height,fill:"white"}));const b=[],m=r(c);for(const M of(t=>Array.from(t.querySelectorAll(`.${n}`)).map(t=>{const e="rect"===t.tagName?[t]:Array.from(t.querySelectorAll("rect")),n=(t,e)=>Number(t.getAttribute(e)),a=Math.min(...e.map(t=>n(t,"x"))),o=Math.min(...e.map(t=>n(t,"y"))),r=Math.max(...e.map(t=>n(t,"x")+n(t,"width"))),s=Math.max(...e.map(t=>n(t,"y")+n(t,"height"))),c=["--start","--span"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ");return{row:Number(t.dataset.row),x:a,y:o,width:r-a,height:s-o,sideways:"right"===t.dataset.grow,part:c}}))(s)){const t=M.sideways?a.breakX:m;if(void 0===t)continue;if(!(M.sideways?M.x<t&&M.x+M.width>t:M.y<m&&M.y+M.height>m))continue;const[e,n]=M.sideways?[i(M,t),i(M,t+a.breakGap)]:[i(M,m-a.breakGap),i(M,m)];f.appendChild($("path",{d:d([...e,...n.slice().reverse()],!0),fill:"black"})),b.push(e,n);const r=[p("--after",o[M.row-1]?.slot??0),M.part].filter(Boolean).join("; ");for(const o of[e,n])s.appendChild($("path",{class:u,"data-part":"edge","data-note":a.note,d:d(o),style:r}))}if(!b.length)return;const g=Array.from(s.querySelectorAll(`.${u}`)),w=$("g",{mask:`url(#${h})`});for(const n of Array.from(s.childNodes))g.includes(n)||w.appendChild(n);const y=$("defs");y.appendChild(f),s.prepend(y,w)}},S=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},H=t=>(t.split(/[.,]/)[1]||"").length,T=(t,e,n)=>{const a=((t,e)=>new Intl.NumberFormat(e||document.documentElement.lang||void 0,{minimumFractionDigits:t,maximumFractionDigits:t}))(e,n).formatToParts(t),o="minusSign"===a[0]?.type?a[0].value:"";return[o,a.slice(o?1:0).map(t=>t.value).join("")]},z=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const a of Array.from(t.children))n.appendChild(a.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},C=(e,n,a,o)=>{const r=(s=e?.textContent||"",Number.parseFloat((s.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")));var s;const c=!!Number.isNaN(r)||Math.abs(n-r)<=.5,l={label:a,computed:n,stated:r,agrees:c};o.checks.push(l),c||console.warn(`[${t}] An annotation reads ${r}%, but ${a} is ${n.toFixed(1)}%. The chart shows your number.`)},L={create:z,draw(e,n,a){const{rows:s,cx:c,y:l,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:b,after:m}=a,[g,w]=((t,e)=>{const n=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n};return[n("data-from",0),n("data-to",e-1)]})(e,s.length),y=s[g],M=s[w];if(!y||!M)return void console.warn(`[${t}] A bracket points at a row that is not there (row ${g+1} to ${w+1}, of ${s.length}).`);const k=7*i,x=4*i,A=c(g),N=c(w),S=Math.min(l(y.value),l(M.value))-u-x-.9*d,H=t=>l(t)-u-x,T=`M ${A} ${H(y.value)} L ${A} ${S} L ${N} ${S} L ${N} ${H(M.value)-k}`,z=(H(y.value)-S+Math.abs(N-A)+(H(M.value)-k-S))/i+1;b.appendChild($("path",{class:o,"data-note":a.note,d:T,style:`--len:${z.toFixed(1)}; ${p("--after",m)}`}));const L=H(M.value);var O;b.appendChild($("polygon",{class:r,"data-note":a.note,points:`${N},${L} ${N-.45*k},${L-k} ${N+.45*k},${L-k}`,style:p("--after",m)})),n&&(v(n,(A+N)/2,S,f,h),n.style.setProperty("--after",String(m))),C(n,(O=y.value,(M.value-O)/Math.abs(O)*100),`${y.value} to ${M.value}`,a)}},O=new WeakMap,B=t=>O.get(t)??{width:t.offsetWidth,height:t.offsetHeight},U={create:z,draw(t,e,n){const{rows:a,cx:s,y:c,unit:l,labelHeight:i,height:u,svg:d,values:h,after:b}=n,m=a[0],g=a[a.length-1];if(!m||!g)return;const w=i+18*l,y=10*l,M=10*l;let k=s(0),x=c(m.value)-w,A=s(a.length-1),N=c(g.value)-w,S=0;a.forEach((t,e)=>{const n=A===k?0:(s(e)-k)/(A-k),a=x+n*(N-x)-(c(t.value)-w);a>S&&(S=a)}),x-=S,N-=S;const H=A-k,T=N-x,z=Math.hypot(H,T)||1,L=H/z,O=T/z;k-=L*y,x-=O*y,A+=L*y,N+=O*y;const U=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=k+(A-k)*U,n=x+(N-x)*U,o=B(e).width*l/2,r=n+B(e).height*l/2+8*l;let u=0;a.forEach((e,n)=>{const a=(h[n]?B(h[n]).width:0)*l/2;if(Math.abs(s(n)-t)>=o+a)return;const d=c(e.value)-7*l-i;u=Math.max(u,r-d)}),x-=u,N-=u}const _=A-L*M,E=N-O*M,F=Math.hypot(_-k,E-x)/l+1;d.appendChild($("line",{class:o,"data-note":n.note,x1:k,y1:x,x2:_,y2:E,style:`--len:${F.toFixed(1)}; ${p("--after",b)}`}));const j=-O,P=L,q=.42*M;d.appendChild($("polygon",{class:r,"data-note":n.note,points:[`${A},${N}`,`${_+j*q},${E+P*q}`,`${_-j*q},${E-P*q}`].join(" "),style:p("--after",b)})),e&&(v(e,k+(A-k)*U,x+(N-x)*U,f,u),e.style.setProperty("--after",String(b)));const R=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(R)&&R>0&&C(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(m.value,g.value,R),`${m.value} to ${g.value} over ${R} years`,n)}},_=(t,e,n)=>{const a=.15,o=Math.min(.7*t/(e+(e-1)*a),n),r=e*o+(e-1)*o*a;return{size:o,gap:o*a,offset:t=>-r/2+t*o*1.15}},E=(t,e,n)=>{const a=t.series[n],o=t.series.some(t=>t.focus)&&!a.focus;return{"data-series":n+1,...o&&{"data-muted":""},style:`--n:${n}; --m:${o?1:0}; --palette:var(--tablechart-color-${n+1}); ${p("--i",e.slot)}`}},F=(t,e,n=!1)=>{let a=0,o=0;return Array.from({length:e},(e,r)=>{const s=t.cells[r]??t.cells[0],c=s.missing?0:s.value;if(n){const t=a;return a+=c,{from:t,to:a,cell:s}}if(c<0){const t=o;return o+=c,{from:t,to:o,cell:s}}const l=a;return a+=c,{from:l,to:a,cell:s}})},j=(t,e,n=!1)=>{const a=F(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},P=(t,e)=>{const{top:n,bottom:a}=j(t,e);return n+a},q=(t,e,n)=>{const a=e.series.some(t=>t.focus);t.style.setProperty("--n",String(n)),t.style.setProperty("--m",a&&!e.series[n].focus?"1":"0"),t.style.setProperty("--palette",`var(--tablechart-color-${n+1})`)},R=(t,e,a,o={},r="")=>{const s={class:y(n,e),"data-kind":"bar","data-row":a+1,...o},c=p("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=$("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(n,r)=>{const s=void 0!==o["data-grow"]?{"data-grow":o["data-grow"]}:{};l.appendChild($("rect",{...s,...r,class:y("tablechart-piece",e),"data-row":a+1,...E(t,e,n)}))}},W=(t,e,n)=>t.some(t=>B(t).width*n>e-6*n),D=(t,e,n)=>e>=B(t).height*n*1.6,V=(t,e,n)=>e>=B(t).width*n*1.5,I=(t,e,n,a,o=.7)=>{t.style.setProperty(a,"1");let r=1;for(const c of e){const{size:t,room:e}=n(c);t>e&&(r=Math.min(r,e/t))}const s=r>=o?r:0;return t.style.setProperty(a,String(s||o)),s},K={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,aspect:.5,minHeight:({labelHeight:t,nameHeight:e,rows:n,series:a,stacked:o})=>{const r=1.1*t,s=a>1&&!o?r*(a+.15*(a-1))/.7:r/.58;return n*Math.max(s,1.2*e)},categories:"beside",headroom:()=>0,draw(t){const{segments:e,height:o,unit:r,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(S(l.map(t=>B(t).width*r)),0),b=Math.min(h+10*r,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((b-8*r)/f*100).toFixed(2)}%`);const m=f-4*r,g=t.stacked?Math.max(S(t.rows.map(e=>j(e,t.series.length).top)),0)||1:Math.max(S(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,w=t.stacked?Math.max(S(t.rows.map(e=>-j(e,t.series.length).bottom)),0):Math.max(S(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),M=Math.max(g,t.squeeze?.hi??0)+w,k=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),M,n,t.squeeze,t.breakGap),x=o/e.length,A=t=>(t+.5)*x,N=Math.min(x*i.barfill,u),H=_(x,t.series.length,u),T=c[0]??t.totals[0],z=T?B(T).height*r*.56:0,C=Math.max(((d&&!t.stacked?H.size:N)-z)/2,5*r),L=t=>B(t).width*r,O=t=>t.length?S(t.map(L))+C+4*r:0,U=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,P=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:U(e,n)}))),W=e=>{const n=j(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let D=t.stacked?O(t.totals.filter((t,e)=>!W(e))):d?O(P.filter(t=>t.value>=0).map(t=>t.label)):0,K=t.stacked?O(t.totals.filter((t,e)=>W(e))):d?O(P.filter(t=>t.value<0).map(t=>t.label)):0;if(!d&&!t.stacked)for(let n=0;n<3;n++){const t=m-b-D-K,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!V(n,k(e.value,t),r)),a=O(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),o=O(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(a<=D&&o<=K)break;D=Math.max(D,a),K=Math.max(K,o)}const G=m-b-D-K,Z=b+K+k(w,G),J=t=>t<0?Z-k(t,G):Z+k(t,G);if(t.squeeze&&(t.breakX=J(t.squeeze.gap)),t.stacked)return t.rows.forEach((e,n)=>{const a=j(e,t.series.length),s=R(t,e,n,{"data-grow":"right"},a.bottom<0?Z-J(a.bottom)+"px center":""),c=A(n)-N/2;F(e,t.series.length).forEach(({from:e,to:a,cell:l},i)=>{const u=t.seriesValues[i][n];if(u.dataset.place="none",l.missing||a===e)return;const d=Math.min(J(e),J(a)),h=Math.max(J(e),J(a));s(i,{x:d,y:c,width:Math.max(h-d,1),height:N,...a<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!V(u,h-d,r)||B(u).height*r>N),q(u,t,i),v(u,(d+h)/2,A(n),f,o)});const i=t.totals[n];i&&(i.dataset.place=W(n)?"before":"after",v(i,W(n)?J(a.bottom)-C:J(a.top)+C,A(n),f,o));const u=l[n];u&&v(u,b-8*r,A(n),f,o)}),void s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=I(t.plot,e,t=>({size:B(t).height*r,room:H.size+.5*H.gap}),"--_fit");return t.rows.forEach((e,a)=>{t.series.forEach((r,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][a];if(i.missing)return void(u.dataset.place="none");const d=J(i.value),h=i.value<0,b=A(a)+H.offset(l);s.appendChild($("rect",{class:y(n,e),"data-kind":"bar","data-row":a+1,"data-grow":h?"left":"right",x:Math.min(d,Z),y:b,width:Math.max(Math.abs(d-Z),1),height:H.size,...E(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),v(u,h?d-C:d+C,b+H.size/2,f,o)});const i=l[a];i&&v(i,b-8*r,A(a),f,o)}),void s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}))}const Q=e.map((t,e)=>V(c[e],Math.abs(J(t.value)-Z),r));e.forEach((e,a)=>{const i=J(e.value),u=A(a),d=e.value<0,h=Math.abs(i-Z);s.appendChild($("rect",{class:y(n,e),"data-kind":e.kind,"data-row":a+1,"data-grow":d?"left":"right",x:Math.min(i,Z),y:u-N/2,width:Math.max(h,1),height:N,style:p("--i",e.slot)}));const m=c[a],g=Math.max(Math.min(C,h-L(m)-6*r),6*r),w=d?1:-1;m.dataset.place=Q[a]?"inside":d?"before":"after",m.dataset.kind=e.kind,v(m,Q[a]?"center"===t.insideAlign?(Z+i)/2:"start"===t.insideAlign?Z-w*(g+L(m)/2):i+w*(g+L(m)/2):i-w*C,u,f,o);const M=l[a];M&&v(M,b-8*r,u,f,o)}),s.appendChild($("line",{class:a,x1:Z,x2:Z,y1:0,y2:o}))}},G={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+4*a+(n?1.6*e:0),draw(t){const{segments:e,cx:o,y:r,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,b=r(0);if(t.stacked)return t.rows.forEach((e,n)=>{const a=j(e,t.series.length),i=R(t,e,n,{},a.bottom<0?`center ${b-r(a.top)}px`:""),u=o(n)-s/2;F(e,t.series.length).forEach(({from:e,to:a,cell:d},h)=>{const b=t.seriesValues[h][n];if(b.dataset.place="none",d.missing||a===e)return;const m=Math.min(r(a),r(e)),g=Math.max(r(a),r(e));i(h,{x:u,y:m,width:s,height:Math.max(g-m,1),...a<e&&{"data-grow":"down"}}),b.dataset.place="inside",b.toggleAttribute("data-left-out",!D(b,g-m,l)||B(b).width*l>s-4*l),q(b,t,h),v(b,o(n),(m+g)/2,f,c)});const d=t.totals[n];if(d){const t=0===a.top&&a.bottom<0;d.dataset.place=t?"below":"outside",v(d,o(n),t?r(a.bottom)+4*l:r(a.top)-4*l,f,c)}}),void i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}));if(t.series.length>1){const e=o(1)-o(0)||2*o(0),s=_(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=I(t.plot,u,t=>({size:B(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,a)=>{t.series.forEach((u,h)=>{const m=e.cells[h]??e.cells[0],g=t.seriesValues[h][a],p=o(a)+s.offset(h);if(m.missing)return void(g.dataset.place="none");const w=r(m.value),M=m.value<0;i.appendChild($("rect",{class:y(n,e),"data-kind":"bar","data-row":a+1,...M&&{"data-grow":"down"},x:p,y:Math.min(w,b),width:s.size,height:Math.max(Math.abs(b-w),1),...E(t,e,h)})),g.dataset.place=M?"below":"outside",g.toggleAttribute("data-left-out",!d),v(g,p+s.size/2,M?w+4*l:w-4*l,f,c)})}),void i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}))}const m=W(u,s,l),g=e.map((t,e)=>"inside"===d&&!m&&!t.missing&&D(u[e],Math.abs(b-r(t.value)),l)),w=u[0]?B(u[0]).height*l*.56:0;let M=Number.POSITIVE_INFINITY;for(const[n,a]of u.entries())g[n]&&(M=Math.min(M,(s-B(a).width*l)/2));e.forEach((t,e)=>{const a=r(t.value),d=t.value<0;if(t.missing)return v(u[e],o(e),b-4*l,f,c),void(u[e].dataset.place="outside");i.appendChild($("rect",{class:y(n,t),"data-kind":t.kind,"data-row":e+1,...d&&{"data-grow":"down"},x:o(e)-s/2,y:Math.min(a,b),width:s,height:Math.max(Math.abs(b-a),1),style:p("--i",t.slot)}));const m=d?-1:1,k=Math.min(M,(Math.abs(b-a)-w)/2),x="center"===h?(a+b)/2:"start"===h?b-m*(k+w/2):a+m*(k+w/2),A=d?a+4*l:a-4*l;v(u[e],o(e),g[e]?x:A,f,c),u[e].dataset.place=g[e]?"inside":d?"below":"outside"}),i.appendChild($("line",{class:a,x1:0,x2:f,y1:b,y2:b}))}},Z=0,J={aspect:.66,centre:!0,headroom:()=>0,segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),draw({rows:t,height:e,unit:n,labelHeight:a,svg:o,values:r,config:c,centre:l}){const i=500,u=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,b=Math.max(Math.min(f,e)/2-h,10),m=b*c.ringfill,w=b-m/2,M=2*Math.PI*w,k=[];let x=0,A=0,N=0;if(t.forEach((t,c)=>{const l=r[c];if(t.isTotal)return void(l.dataset.place="none");const h=Math.abs(t.value)/d,S=g(N,h),H=`--share:${h.toFixed(4)}; --start:${S.start.toFixed(4)}; --span:${S.span.toFixed(4)};`,T=h*M,z=x/M*2*Math.PI-Math.PI/2;k.push(z),o.appendChild($("circle",{class:y(s,t),"data-slice":A+1,"data-row":c+1,cx:i,cy:u,r:w,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${T.toFixed(1)} ${(M-T).toFixed(1)}`,"stroke-dashoffset":(-x).toFixed(1),style:`--n:${A}; --palette:var(--tablechart-color-${A+1}); --arc:${T.toFixed(1)}; --circ:${M.toFixed(1)}; ${H} --ease:${S.easing}; ${p("--i",t.slot)}`}));const C=z+T/M*Math.PI,L=Math.cos(C),O=Math.sin(C);o.appendChild($("line",{class:"tablechart-leader",x1:i+L*(b+2*n),y1:u+O*(b+2*n),x2:i+L*(b+7*n),y2:u+O*(b+7*n),"data-row":c+1,style:`${H} ${p("--i",t.slot)}`})),l.style.setProperty("--start",S.start.toFixed(4)),l.style.setProperty("--span",S.span.toFixed(4));const U=b+9*n,_=B(l).width*n/2;v(l,i+L*(U+Math.abs(L)*_),u+O*(U+Math.abs(O)*a*.7),f,e),l.dataset.place="around",x+=T,N+=h,A+=1}),k.length>1){const t=w-m/2-1,n=w+m/2+1,a="tablechart-slices-"+ ++Z,r=$("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild($("rect",{x:0,y:0,width:f,height:e,fill:"white"}));for(const e of k)r.appendChild($("line",{class:"tablechart-divide",x1:i+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:i+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const c=$("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${s}`)))c.appendChild(e);const l=$("defs");l.appendChild(r),o.prepend(l,c)}l&&v(l,i,u,f,e)}},Q=["circle","square","diamond"],X=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=Q.find(t=>n.includes(t));return{shape:a??Q[Math.floor(e/2)%Q.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},Y=t=>Number(t.toFixed(2));function tt(t,e,n){const a=new Array(t).fill(0);let o=[];const r=()=>{(function(t,e){const n=t.length;if(n<2)return t.map(()=>0);const a=n=>(e[n+1]-e[n])/(t[n+1]-t[n]||1),o=new Array(n).fill(0);for(let s=1;s<n-1;s++){const e=a(s-1),n=a(s);if(e*n<=0)continue;const r=t[s]-t[s-1],c=t[s+1]-t[s],l=(e*c+n*r)/(r+c||1),i=Math.min(2*Math.abs(e),2*Math.abs(n),Math.abs(l));o[s]=Math.sign(e)*i||0}if(2===n)return o[0]=a(0),o[1]=a(0),o;const r=(n,a,o)=>{const r=t[a]-t[n];return r?((e[a]-e[n])/r*3-o)/2:o};return o[0]=r(0,1,o[1]),o[n-1]=r(n-2,n-1,o[n-2]),o})(o.map(t=>n(t)[0]),o.map(t=>n(t)[1])).forEach((t,e)=>{a[o[e]]=t}),o=[]};for(let s=0;s<t;s++)e(s)?r():o.push(s);return r(),a}var et,nt,at=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),ot=t=>({segments:at,series:!0,stackable:!0,running:!0,swatch:t?"box":void 0,headroom:({labelHeight:t,unit:e})=>1.6*t+6*e,footroom:({labelHeight:e,unit:n,series:a,focused:o,stacked:r})=>t||r||2!==a||o?0:e+7*n,draw(e){const{rows:n,series:o,seriesValues:r,names:s,cx:c,y:i,height:u,unit:d,labelHeight:h,svg:b,stacked:m}=e,g="step"===e.shape,p="smooth"===e.shape,w=o.length>1,y=o.some(t=>t.focus),M=n.length-1,k=i(0),A=n.length>1?c(1)-c(0):2*c(0);b.style.setProperty("--_base",`${Y(k)}px`);const N=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],S=(t,e)=>!N(t,e)||!!N(t,e)?.missing,H=n.map(t=>m?F(t,o.length,!0):null),T=(t,e)=>H[e]?.[t].to??N(t,e)?.value??0,z=(t,e)=>H[e]?.[t].from??0,C=(t,e)=>[c(e),i(T(t,e))],L=o.map((t,e)=>{if(!w)return{attrs:{},ink:""};const n=y&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),O=Math.min(M,6);e.plot.style.setProperty("--count",String(O+1));const U=M>0?O/(g?n.length:M):1,_=t=>t*U,E=t=>`--i:${Y(_(t))}`,j=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{S(t,o)||(a<0&&(a=o),(o===M||S(t,o+1))&&((g||o>a)&&e.push([a,o]),a=-1))}),e},P=(t,e)=>`--i:${Y(_(t)+1)}; --d:${Y(_(g?e+1:e)-_(t))}`,q=(t,e)=>({"data-from":t+1,"data-to":e+1,...g&&{"data-flat":""}}),R=p?o.map((t,e)=>tt(n.length,t=>S(e,t),t=>C(e,t))):[],W=p&&t?o.map((t,e)=>tt(n.length,t=>S(e,t),t=>[c(t),i(z(e,t))])):[],D=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{g?(a.push(`H${Y(o+n*A/2)}`),s<t.length-1&&a.push(`V${Y(t[s+1][1])}`)):s>0&&a.push(e?function(t,e,n,a){const[o,r]=function(t,e,n,a){const o=(e[0]-t[0])/3;return[[t[0]+o,t[1]+n*o],[e[0]-o,e[1]-a*o]]}(t,e,n,a),s=([t,e])=>`${Y(t)},${Y(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${Y(o)},${Y(r)}`)}),a},V=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),i(o(t,e+a))]),I=(t,e,n,a)=>p?t[e].slice(n,a+1):null,K=t=>c(t)-(g?A/2:0),G=t=>c(t)+(g?A/2:0);t&&o.forEach((t,e)=>(t=>{const e=$("g",{class:"tablechart-area",...L[t].attrs,...m&&{"data-stacked":""},style:L[t].ink}),n=j(t),a=$("g",{class:"tablechart-area-fill",style:`--rows:${Y(O+1)}; ${n.length?P(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=V(t,o,r,T),n=V(t,o,r,z),s=I(W,t,o,r)?.reverse()??null,c=[`M${Y(K(o))},${Y(n[0][1])}`,`L${Y(K(o))},${Y(e[0][1])}`,...D(e,I(R,t,o,r),1),`L${Y(G(r))},${Y(n[n.length-1][1])}`,...D(n.reverse(),s,-1),"Z"].join(" ");a.appendChild($("path",{d:c,...q(o,r),style:P(o,r)}))}b.appendChild(e)})(e)),o.forEach((t,e)=>(t=>{const e=o[t];for(const[n,a]of j(t)){const o=V(t,n,a,T),r=[`M${Y(K(n))},${Y(o[0][1])}`,...D(o,I(R,t,n,a),1)].join(" ");b.appendChild($("path",{class:"tablechart-series",...L[t].attrs,d:r,...e.line&&{"data-line":e.line},...q(n,a),style:`${L[t].ink}${P(n,a)}`}))}})(e)),g||(()=>{const t=o.map((t,e)=>w?X(o,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=C(e,n);return((t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return $("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return $("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}return $("circle",{cx:e,cy:n,r:a,...o})})(t[e].shape,o,r,4*d,{...a,style:`${a.style??""}${s=r,`--rise:${Y(k-s)}px; `}${E(n)}`});var s},a=t=>n.map((t,e)=>e).filter(e=>!S(t,e)),r=o.flatMap((n,o)=>t[o].open?a(o).map(t=>e(o,t,{class:l,"data-row":t+1,...w&&{"data-series":o+1}})):[]);x(b,r,f,u),o.forEach((n,o)=>{for(const r of a(o))b.appendChild(e(o,r,{class:"tablechart-point",...L[o].attrs,"data-marker":t[o].shape,...t[o].open&&{"data-open":""},"data-row":r+1,style:L[o].ink}))})})();const Z=(t,e)=>{let n=e;for(;n<M&&!S(t,n+1)&&N(t,n+1)?.value===N(t,e)?.value;)n++;return n};r.forEach((e,n)=>{e.forEach((e,a)=>{e.style.setProperty("--i",String(Y(g?(_(a)+_(a+1))/2:_(a))));const s=((e,n)=>{const a=N(e,n);if(!a||a.missing)return"none";if(g&&n>0&&!S(e,n-1)&&N(e,n-1)?.value===a.value)return"none";if(y&&!o[e].focus)return"none";if(m)return"middle";const r=a.value<0?"below":"above";if(!w||y||o.length>2)return r;const s=N(1-e,n);return!s||s.missing?r:a.value>s.value||a.value===s.value&&0===e||t&&a.value>=0&&C(e,n)[1]+7*d+h>k?"above":"below"})(n,a);if(e.dataset.place="above"===s?"outside":s,e.toggleAttribute("data-left-out","none"!==s&&((t,e)=>m||g?B(r[t][e]).width*d>(g?Z(t,e)-e+1:1)*A-4*d||!!(m&&t>0&&T(t,e)<z(t,e))||m&&Math.abs(i(z(t,e))-i(T(t,e)))<1.2*h:w&&!y&&o.length>2)(n,a)),g&&"none"!==s?e.dataset.rowEnd=String(Z(n,a)+1):delete e.dataset.rowEnd,"none"===s)return;const l=B(e).width*d/2+4*d;let b=c(a);g?b=(c(a)+c(Z(n,a)))/2:"middle"===s&&0===a?b+=l:"middle"===s&&a===M&&(b-=l);const p=i(T(n,a)),$={middle:(i(z(n,a))-p)/2,above:-7*d,below:7*d};v(e,b,p+$[s],f,u)})});const J=s.map((t,e)=>{let n=M;for(;n>0&&S(e,n);)n--;const[a,o]=C(e,n);return{name:t,x:(g?a+A/2:a)+10*d,y:m?(o+i(z(e,n)))/2:o}}),Q=(s[0]?B(s[0]).height:0)*d;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,a)=>{const o=t[a-1];o&&n.y<o.y+e&&(n.y=o.y+e)}),t))(J,Q))v(t.name,t.x,t.y,f,u);const et=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),nt=t||m||2!==o.length||y||et?k:u-2*d;b.appendChild($("line",{class:a,x1:0,x2:c(M)+c(0),y1:nt,y2:nt}))}}),rt=ot(!1),st=ot(!0),ct=new Set,lt={segments:e=>{let n=0,a=!1;return e.map(e=>{if(e.isTotal)return a&&((e,n)=>{if(Math.abs(e-n)<=Math.abs(n)/100)return;const a=`[${t}] A total reads ${e}, but the steps before it add up to ${Number(n.toFixed(6))}. The chart shows your number.`;ct.has(a)||(ct.add(a),console.warn(a))})(e.value,n),a=!1,n=e.value,{...e,from:0,to:e.value,kind:"total"};const o=n;return n+=e.value,a=!0,{...e,from:o,to:n,kind:e.value>=0?"up":"down"}})},breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+6*a+(n?1.6*e:0),draw({segments:t,cx:e,y:o,barWidth:r,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=o(0),b=W(i,r,c),g=d??"center",w=t.map((e,n)=>{const a=o(Math.max(e.from,e.to)),r=Math.abs(o(e.from)-o(e.to)),s=null!==u&&Math.min(e.from,e.to)<u&&Math.max(e.from,e.to)>u,l="total"===e.kind&&n>0&&n===t.length-1;return{top:a,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!b&&D(i[n],r,c)}}),M=i[0]?B(i[0]).height*c*.56:0;let k=Number.POSITIVE_INFINITY;for(const[n,a]of w.entries())a.inside&&(k=Math.min(k,(r-B(i[n]).width*c)/2));const x=t.length,A=(t,e,n=!1)=>`--start:${(t/x).toFixed(4)}; --span:${(e/x).toFixed(4)}; --ease:${n?m:"linear"};`;t.forEach((n,a)=>{const s=t[a+1];if(!s)return;const c=o(n.to),i=e(a)+r/2,u=e(a+1)-r/2;l.appendChild($("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":a+2,style:`${p("--i",s.slot)}; ${A(a+1,1/3)}`}))}),t.forEach((a,o)=>{const{top:u,length:d,down:h,inside:b}=w[o];l.appendChild($("rect",{class:y(n,a),"data-kind":a.kind,"data-row":o+1,"data-grow":h?"down":"up",x:e(o)-r/2,y:u,width:r,height:Math.max(d,1),style:`${p("--i",a.slot)}; ${A(o,1,o===t.length-1)}`}));const m=i[o];m.style.setProperty("--start",(o/x).toFixed(4)),m.style.setProperty("--span",(1/x).toFixed(4));const N=Math.min(k,(d-M)/2),S="center"===g?u+d/2:"end"===g!==h?u+N+M/2:u+d-N-M/2;m.dataset.place=b?"inside":"outside",m.dataset.kind=a.kind;const H=b?S:"down"===a.kind?u+d+B(m).height*c+3*c:u-3*c;v(m,e(o),H,f,s)}),l.appendChild($("line",{class:a,x1:0,x2:f,y1:h,y2:h}))}},it={enabled:!1,log(...e){it.enabled&&console.log(`[${t}]`,...e)},timed(e,n,a){if(!it.enabled)return a();const o=performance.now(),r=a(),s=performance.now()-o,c=n.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${t}] ${e} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,n):it.log(`${e} took ${s.toFixed(1)} ms for ${c} rows.`,n),r}},ut=t=>{const e=(t?.textContent||"").trim(),n=e.match(/^(.*?)(-?\d+(?:[.,]\d+)?)(.*)$/);return{raw:e,number:n?.[2]??"",prefix:n?.[1]??"",suffix:n?.[3]??"",missing:!n,value:n?Number.parseFloat(n[2].replace(",",".")):0}},dt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),ht=["axis-break","trend","bracket"],ft=t=>{const e=t.plan;if(!e)return;const n=e=>null===e||t.step-e>=1;for(const a of t.figure.querySelectorAll("[data-from]")){const t=Number(a.dataset.from)-1,o=Number(a.dataset.to)-1,r=a.closest("[data-series]")?.dataset.series,s=r?Number(r)-1:0,c=e.series[s],l=t=>e.cells[t]?.[s]?.step??e.rows[t]?.step??null;let i=t-1;if(c&&null!==c.step)i=n(c.step)?o:t-1;else for(;i<o&&n(l(i+1));)i++;const u=a.hasAttribute("data-flat")?(i-t+1)/(o-t+1):o>t?Math.max(0,i-t)/(o-t):0;a.style.setProperty("--reveal",String(u))}},bt=(t,e,n=!1)=>{const a=t.plan;if(!a)return;const o=Math.min(Math.max(Math.round(e),0),a.count),r=o!==t.step;t.step=o,t.figure.style.setProperty("--_step",String(o)),ft(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===o),c&&(c.disabled=o===a.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:o,steps:a.count}}))},mt="tablechart-tooltip",gt=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],pt=null,wt=null,$t=null,yt=0,Mt=()=>{clearTimeout(yt),pt&&wt&&(pt.hidden=!0,wt=null,$t=null)},vt=!1,kt=!0,xt=NaN,At=NaN,Nt=!1,St=()=>{clearTimeout(yt),yt=window.setTimeout(Mt,120)},Ht=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Tt=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole)`);if(!n)return;const a=getComputedStyle(n);return a.fill&&"none"!==a.fill?a.fill:a.stroke},zt=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Ht(t,c[e]))continue;const n=a?t.figure.querySelector(`.tablechart-name[data-series="${s+1}"]`):null;o.push({name:a?n?.textContent??t.series[s].name:"",value:c[e].textContent??"",colour:a?Tt(t,s):void 0,sample:n?{marker:n.dataset.marker??null,open:n.hasAttribute("data-open"),line:n.dataset.line??null,box:"box"===n.dataset.swatch}:void 0})}const r=t.totals[e];return o.length>1&&Ht(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Ct=(t,e,n)=>{if(clearTimeout(yt),wt===t&&$t===e)return;const a=(t.type.tooltip??zt)(t,e,n);if(!a.length)return Mt();wt&&wt!==t&&Mt(),pt??(pt=(()=>{const t=document.createElement("div");return t.className=mt,t.setAttribute("aria-hidden","true"),t.hidden=!0,et=document.createElement("div"),(nt=document.createElement("div")).className=`${mt}-arrow`,t.append(et,nt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(yt)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&St()),document.addEventListener("pointerdown",e=>{const n=e.target;!wt||wt.plot.contains(n)||t.contains(n)||Mt()}),window.addEventListener("scroll",Mt,{capture:!0,passive:!0}),window.addEventListener("resize",Mt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${mt}-line`,n){const t=document.createElement("span");t.className=`${mt}-key`,t.style.background=n,o?.box?t.dataset.sample="box":o&&(t.dataset.sample="line",o.marker&&(t.dataset.marker=o.marker),o.line&&(t.dataset.line=o.line),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${mt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${mt}-value`,n.textContent=e,r.append(n)}return r},r=t.categories[e]?.textContent??t.rows[e].label,s=1===a.length&&!a[0].name;et.replaceChildren(o(r,s?a[0].value:"",void 0,!0),...s?[]:a.map(({name:t,value:e,colour:n,sample:a})=>o(t,e,n,!1,a)));const c=getComputedStyle(t.figure);for(const l of gt){const t=c.getPropertyValue(l).trim();t?pt.style.setProperty(l,t):pt.style.removeProperty(l)}pt.style.setProperty("--_color",c.color),pt.style.colorScheme=c.colorScheme,pt.style.fontFamily=c.fontFamily,pt.style.fontSize=c.fontSize,wt=t,$t=e,pt.hidden=!1,pt.style.left="0px",((t,e,n,a=10,o=8,r=12)=>{const{offsetWidth:s,offsetHeight:c}=t,{clientWidth:l,clientHeight:i}=document.documentElement,u=n.top-o,d=i-n.bottom-o,h=c+a<=u||!(c+a<=d)&&u>=d,f=h?n.top-a-c:n.bottom+a,b=n.left+n.width/2,m=Math.max(o,Math.min(b-s/2,l-s-o));t.style.left=`${m}px`,t.style.top=`${Math.max(o,Math.min(f,i-c-o))}px`,t.dataset.side=h?"top":"bottom",e.style.left=`${Math.max(r,Math.min(b-m,s-r))}px`})(pt,nt,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let a=null;for(const i of n){const t=i.getBoundingClientRect();(t.width||t.height)&&(a=a?new DOMRect(Math.min(a.left,t.left),Math.min(a.top,t.top),Math.max(a.right,t.right)-Math.min(a.left,t.left),Math.max(a.bottom,t.bottom)-Math.min(a.top,t.top)):t)}if(a)return a;const o=t.plot.getBoundingClientRect(),[r,s,c,l]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(o.left+o.width*r/100,o.top+o.height*s/100,o.width*c/100,o.height*l/100)})(t,e))},Lt=t=>{wt===t&&Mt()},Ot={area:st,bar:K,column:G,donut:J,line:rt,waterfall:lt},Bt={"axis-break":N,trend:U,bracket:L},Ut=Object.keys(Bt),_t=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},Et=["straight","step","smooth"],Ft=(t,e)=>{const n=t.dataset.chartShape;return n&&Et.includes(n)?n:Et.includes(e.shape)?e.shape:"straight"},jt=0,Pt=(n,a,o=null)=>{const r=o??(n.getAttribute("data-chart")||"column"),s=Ot[r];if(!s)return console.warn(`[${t}] Unknown chart type "${r}". Known types: ${Object.keys(Ot).join(", ")}.`),n.setAttribute("data-chart-empty",""),null;const l=((t,e="data-i18n")=>Array.from(t.querySelectorAll("tbody tr")).map((t,n)=>{const a=t.querySelector("th"),o=Array.from(t.querySelectorAll("td")).map(ut);return o.length||o.push(ut(null)),{...o[0],label:(a?.textContent||"").trim(),key:e&&a?.getAttribute(e)||null,cells:o,classes:Array.from(t.classList),isTotal:"total"===t.getAttribute("data-kind"),slot:n}}))(n,a.langattribute);if(!l.length)return console.warn(n.querySelector("table")?`[${t}] A chart has no rows in its table, so there is nothing to draw.`:`[${t}] A chart has no table, so there is nothing to draw.`,n),n.setAttribute("data-chart-empty",""),null;(t=>{const e=t.querySelector(":scope > figcaption");if(!e)return;(t=>{for(const e of t.querySelectorAll("br")){if(e.previousElementSibling?.classList.contains("tablechart-sr"))continue;if(/[.!?:;,…]$/.test(_t(e)))continue;const t=document.createElement("span");t.className=d,t.textContent=". ",e.before(t)}})(e);const n=t=>t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"),a=t=>{e.id||(e.id="tablechart-caption-"+ ++jt),t.setAttribute("aria-labelledby",e.id)};"FIGURE"!==t.tagName||n(t)||a(t);const o=t.querySelector("table");!o||n(o)||o.querySelector(":scope > caption")||a(o)})(n);let u=((t,e,n="data-i18n")=>{const a=dt(t),o=Math.max(1,S(e.map(t=>t.cells.length)));return Array.from({length:o},(t,e)=>{const o=a[e];return{name:(o?.textContent||"").trim(),key:n&&o?.getAttribute(n)||null,focus:"focus"===o?.getAttribute("data-kind"),marker:o?.getAttribute("data-marker")??null,line:(r=o?.getAttribute("data-line"),"dashed"===r||"dotted"===r?r:null)};var r})})(n,l,a.langattribute);u.length>1&&!s.series&&(console.warn(`[${t}] A ${r} chart uses only the first of its ${u.length} value columns.`),u=u.slice(0,1));const h=u.length>1;h&&n.style.setProperty("--_series-count",String(u.length));const f=n.hasAttribute("data-chart-stack");f&&!s.stackable&&console.warn(`[${t}] A ${r} chart cannot be stacked.`);const b=f&&!!s.stackable&&h,m=document.createElement("div");m.className="tablechart-plot",m.setAttribute("aria-hidden","true");const g=$("svg",{role:"presentation",focusable:"false"});m.appendChild(g),n.appendChild(m);const p=s.centre?l.filter(t=>!t.isTotal):l,w=Math.max(0,S(p.flatMap(t=>t.cells.slice(0,u.length).map(t=>H(t.number))))),y=u.map((t,n)=>l.map((t,a)=>{const o=t.cells[n]??t.cells[0],r=M(e,m);return r.classList.add(...t.classes),r.dataset.value=String(o.value),o.prefix&&(r.dataset.prefix=o.prefix),o.suffix&&(r.dataset.suffix=o.suffix),o.missing&&(r.dataset.missing=o.raw),h&&(r.dataset.series=String(n+1)),r.dataset.row=String(a+1),r.style.setProperty("--i",String(t.slot)),r})),v=y[0],k=b&&s.totals?l.map((t,n)=>{const a=M(e,m);a.classList.add(...t.classes),a.dataset.kind="total",a.dataset.row=String(n+1),a.dataset.value=String(P(t,u.length));const o=t.cells[0];return o.prefix&&(a.dataset.prefix=o.prefix),o.suffix&&(a.dataset.suffix=o.suffix),a.style.setProperty("--i",String(t.slot)),a}):[],x=l[l.length-1],A=u.some(t=>t.focus),N=n.getAttribute("data-chart-legend"),T=h&&(null===N?a.legend||void 0!==s.legend:"false"!==N)?document.createElement("div"):null;T&&(T.className=c,T.setAttribute("aria-hidden","true"),T.inert=!0);const z=h?u.map((t,e)=>{const o=M("tablechart-name",T??m);T&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=t.name,!r&&"step"!==Ft(n,a)){const t=X(u,e);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return t.line&&!r&&(o.dataset.line=t.line),t.key&&a.langattribute&&o.setAttribute(a.langattribute,t.key),o.dataset.series=String(e+1),o.style.setProperty("--n",String(e)),o.style.setProperty("--palette",`var(--tablechart-color-${e+1})`),o.style.setProperty("--m",A&&!t.focus?"1":"0"),o.style.setProperty("--i",String(x.slot)),o}):[],C=s.centre?M(i,m):null;if(C){const t=l.find(t=>t.isTotal),e=t?t.value:l.reduce((t,e)=>t+Math.abs(e.value),0);C.dataset.value=String(e),t&&(C.dataset.decimals=String(H(t.number)))}const L=C&&!l.some(t=>t.isTotal)?((t,e,n)=>{const a=t.querySelector("table");if(!a)return null;const o=a.querySelector("tfoot [data-chart-total]");if(o)return o.dataset.value=e.dataset.value??"0",o;const r=(a.tFoot??a.createTFoot()).insertRow(),s=document.createElement("th");s.scope="row",s.textContent=n.totallabel;const c=t.getAttribute("data-chart-keys");c&&n.langattribute&&s.setAttribute(n.langattribute,`${c}-total`);const l=r.insertCell();return l.setAttribute("data-chart-total",""),l.dataset.value=e.dataset.value??"0",r.prepend(s),l})(n,C,a):null,O="beside"===s.categories,B=document.createElement("div");B.className="tablechart-categories",B.setAttribute("aria-hidden","true"),B.inert=!0,O?B.dataset.place="beside":s.centre&&(B.dataset.place="key"),B.style.setProperty("--_columns",String(l.length));let U=0;for(const[t,e]of l.entries()){const n=document.createElement("span");n.classList.add(...e.classes),n.textContent=e.label,e.key&&a.langattribute&&n.setAttribute(a.langattribute,e.key),s.centre&&(n.dataset.kind=e.isTotal?"total":"slice",e.isTotal||(n.dataset.slice=String(U+1),n.style.setProperty("--n",String(U)),n.style.setProperty("--palette",`var(--tablechart-color-${U+1})`),U+=1)),n.style.setProperty("--i",String(e.slot)),n.dataset.row=String(t+1),B.appendChild(n)}(O?m:n).appendChild(B),T&&n.appendChild(T);const _=a.animate?(t=>{const e=t.hasAttribute("data-fragment"),n=Array.from(t.querySelectorAll("tbody tr")),a=Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),o=Array.from(t.querySelectorAll("[data-annotation]")).filter(t=>ht.includes(t.getAttribute("data-annotation")??"")),r=t=>t.hasAttribute("data-fragment"),s=n.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(e||n.some(r)||a.some(r)||s.flat().some(r)||o.some(r)))return null;const c=[],l=new Map,i=[],u=t=>{let e=null!==t?l.get(t):void 0;return void 0===e&&(e=c.length,c.push(t),i.push(0),null!==t&&l.set(t,e)),e};let d=0;const h="donut"===t.getAttribute("data-chart"),f=t=>h&&"total"===t.getAttribute("data-kind"),b=n.map(t=>{if(f(t))return{step:null,slot:0};if(!e&&!r(t))return{step:null,slot:d++};const n=u(t.getAttribute("data-fragment-index"));return{step:n,slot:i[n]++}}),m=Math.max(-1,...b.map(t=>t.step??-1));if(m>=0)for(const[$,y]of n.entries())f(y)&&(b[$]={step:m,slot:i[m]++});const g=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),p=s.map(t=>t.map(()=>({step:null,slot:0}))),w=Math.max(0,...s.map(t=>t.length));for(let $=0;$<w;$++)for(const[t,e]of s.entries()){const n=e[$];if(!n||!r(n))continue;const a=u(n.getAttribute("data-fragment-index"));p[t][$]={step:a,slot:i[a]++}}return{rows:b,series:g,cells:p,notes:o.map(t=>{const e=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n},[n,a]="bracket"===t.getAttribute("data-annotation")?[e("data-from",0),e("data-to",b.length-1)]:[0,b.length-1];let o=null;for(let r=Math.min(n,a);r<=Math.max(n,a);r++)for(const t of[b[r]?.step??null,...(p[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=g[e("data-series",0)]?.step??null;null!==s&&(null===o||s>o)&&(o=s),r(t)&&(o=u(t.getAttribute("data-fragment-index")));const c=null===o?b.length:b.filter(t=>t.step===o).length;return{step:o,after:c}}),count:c.length,indexes:c}})(n):null;_&&n.setAttribute("data-steps","");const E=n.getAttribute("data-chart-keys"),F=_&&a.controls?((t,e,n)=>{const a=document.createElement("div");a.className="tablechart-controls";const o=a=>{const o=document.createElement("button");o.type="button",o.className=`tablechart-${a}`,o.dataset.go=a;const r=document.createElement("span");r.className="tablechart-control-icon",r.setAttribute("aria-hidden","true");const s=$("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild($("path",{d:"next"===a?"M6 3l5 5-5 5":"M10 3L5 8l5 5"})),r.appendChild(s);const c=document.createElement("span");c.className="tablechart-control-label",c.textContent=t[a];const l=e[a];l&&n&&c.setAttribute(n,l);const i=document.createElement("span");return i.className=d,i.textContent=t.hint,e.hint&&n&&i.setAttribute(n,e.hint),o.append(..."next"===a?[c,i,r]:[r,c,i]),o};return a.append(o("previous"),o("next")),a})({previous:a.previouslabel,next:a.nextlabel,hint:a.stephint},{previous:E&&`${E}-previous`,next:E&&`${E}-next`,hint:E&&`${E}-step`},a.langattribute):null;F&&n.appendChild(F);const j=n.getAttribute("data-chart-table"),q=j&&Rt.includes(j)?j:a.table;if("never"===q)n.removeAttribute("data-table");else{n.setAttribute("data-table",q);const t=n.querySelector(":scope > table");t&&n.append(t)}const R=Array.from(n.querySelectorAll("[data-annotation]")).map(e=>{const n=e.getAttribute("data-annotation"),a=Bt[n];if(!a)return console.warn(`[${t}] Unknown annotation "${n}". Known annotations: ${Object.keys(Bt).join(", ")}.`),null;const o=Number.parseInt(e.getAttribute("data-series")??"1",10),r=o>=1&&o<=u.length?o-1:0;return o!==r+1&&console.warn(`[${t}] An annotation reads line ${o}, which is not there; it reads line 1.`),{spec:e,type:a,badge:a.create(e,m),series:r,after:l.length}}).filter(t=>null!==t);a.animate&&n.setAttribute("data-animate",Dt(n,r,a,Boolean(_)));const W={figure:n,plot:m,svg:g,rows:l,decimals:w,type:s,values:v,series:u,seriesValues:y,names:T?[]:z,categories:Array.from(B.children),centre:C,stacked:b,totals:k,totalCell:L,rowAt:null,rowBox:null,annotations:R,checks:[],plan:_,step:0,controls:F};F?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&bt(W,W.step+("next"===e?1:-1))}),bt(W,0,!0);const D=n.getAttribute("data-chart-tooltip")??n.getAttribute("data-chart-hover"),V="false"!==D&&("auto"===D?"auto":null!==D||!1!==a.hover&&a.tooltip);return V&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),Nt||(Nt=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(kt=t.screenX!==xt||t.screenY!==At,xt=t.screenX,At=t.screenY,kt&&(vt=!1))},{capture:!0,passive:!0}),document.addEventListener("keydown",()=>{vt=!0,Mt()},!0));const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if("pointerdown"===o.type)vt=!1;else if("mouse"===o.pointerType&&(!kt||vt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return wt===t?Mt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=n.width/a.offsetWidth||1;return t.rowAt((e.clientX-n.left)/o,(e.clientY-n.top)/o)}const n=e.target.closest?.("[data-row]")?.getAttribute("data-row");return n?Number(n)-1:null})(o);if(s=c,null===c||r(c))return wt===t?St():void 0;Ct(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||vt||Ct(t,c,e)};t.svg.addEventListener("transitionend",i),t.svg.addEventListener("transitioncancel",i),a.addEventListener("pointermove",c),a.addEventListener("pointerdown",c),a.addEventListener("pointerleave",e=>{"mouse"===e.pointerType&&(s=null,wt===t&&St())})})(W,a,"auto"===V),Gt(W,a),W},qt={grow:"grow",sweep:"sweep"},Rt=["never","auto","print","always"],Wt={...qt,up:"grow",across:"sweep"},Dt=(t,e,n,a)=>{const o="line"===e||"area"===e,r=o?Wt:qt,s=r[t.getAttribute("data-chart-animate")??""]??r[String(n.animate)];return o?a?"sweep":s??"sweep":"donut"===e||"waterfall"===e?s??"grow":"grow"},Vt=t=>{const e=getComputedStyle(t),n=(e.getPropertyValue("--tablechart-value-align")||e.getPropertyValue("--tablechart-inside-align")).trim();return"start"===n||"center"===n||"end"===n?n:null},It=(t,e,n,a)=>{const o=getComputedStyle(t),r=(o.getPropertyValue(n).trim()||a).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);if(!r)return null;const s=Number(r[1]);return"%"===r[2]?s/100*f:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},Kt=(t,e)=>It(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,Gt=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const a of t.centre?[...n,t.centre]:n){const{missing:n,prefix:o="",suffix:r=""}=a.dataset;if(void 0!==n){a.textContent=n;continue}const s=Number.parseFloat(a.dataset.value||"0"),c=a.dataset.decimals?Number(a.dataset.decimals):t.decimals,[l,i]=T(s,c,e.locale);if(a.textContent=o+(o?l:"")+i+r,l&&!o){const t=document.createElement("span");t.className="tablechart-minus",t.textContent=l,a.prepend(t)}}},Zt=(t,e)=>{t.figure.classList.toggle("is-shown",e)},Jt=t=>"id"===t||"style"===t||t.startsWith("data-chart"),Qt=/^\s*(?:Table)?:\s+/,Xt=t=>"P"===t?.tagName&&Qt.test(t.textContent??""),Yt=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,te=t=>{const e=ne(t);return"P"===e?.tagName?e:t},ee=t=>{if(!t||"object"!=typeof t)return;const e=Object.entries(t),n=t=>null===t||"string"==typeof t||"number"==typeof t;return e.length&&e.every(([,t])=>n(t)||Array.isArray(t)&&t.every(n))?e.map(([t,e])=>Array.isArray(e)?{label:t,values:e}:{label:t,value:e}):void 0},ne=t=>{const e=Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&t.textContent?.trim());return 1===e.length&&e[0]instanceof HTMLElement?e[0]:null},ae="strong, b, span.total",oe="data-chart-made",re=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,se=new Set,ce=null,le=["column","bar"],ie=t=>{const e=t.getAttribute("data-chart")||"column";if(!le.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return le.includes(n)?n:e},ue=!1,de=async(e,n)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=Xt(e)?e:t;if("TABLE"!==n.tagName&&"P"!==n.tagName)return n;const a=document.createElement("figure");((t,e)=>{for(const{name:n,value:a}of Array.from(t.attributes))("class"===n||Jt(n))&&(e.setAttribute(n,a),t.removeAttribute(n))})(t,a),t.classList.length||t.removeAttribute("class");const o="TABLE"===n.tagName?n:null,r=n.previousElementSibling;let s=n.nextElementSibling;const c=o?Xt(r)?r:Xt(s)?s:null:n;o&&c===s&&(s=s?.nextElementSibling??null);const l=s?.classList.contains("chart-annotations")?s:(t=>{if("UL"!==t?.tagName&&"OL"!==t?.tagName)return null;const e=Array.from(t.children),n=e.map(t=>t.hasAttribute("data-annotation")?null:(t=>{const e=te(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Yt.exec(e.textContent??"");if(!n||!Ut.includes(n[1]))return null;if(!n[3]&&e.nextSibling)return null;const a=n[2].trim().split(/\s+/).filter(Boolean).map(t=>t.split("="));return{name:n[1],options:a,text:e,length:n[0].length}})(t));return!e.length||e.some((t,e)=>!n[e]&&!t.hasAttribute("data-annotation"))?null:(e.forEach((t,e)=>{const a=n[e],o=te(t);if(o!==t&&o.replaceWith(...o.childNodes),a){t.setAttribute("data-annotation",a.name);for(const[e,n]of a.options)t.setAttribute(`data-${e}`,n);a.text.textContent=(a.text.textContent??"").slice(a.length)}t.children.length&&Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.textContent?.trim()).forEach((t,e)=>{const n=document.createElement("span");0===e&&t instanceof HTMLElement&&t.matches("em, i")?(n.className="tablechart-caption",n.append(...t.childNodes),t.replaceWith(n)):t.nodeType===Node.TEXT_NODE&&(n.textContent=(t.textContent??"").trim(),t.replaceWith(n))})}),t.classList.add("chart-annotations"),t)})(s);return n.replaceWith(a),c&&a.append((t=>{const e=document.createElement("figcaption");for(const{name:r,value:s}of Array.from(t.attributes))e.setAttribute(r,s);const n=t.firstChild;n?.nodeType===Node.TEXT_NODE&&(n.textContent=(n.textContent??"").replace(Qt,""),n.textContent||n.remove());const a=Array.from(t.childNodes),o=a.findIndex(t=>"BR"===t.nodeName);if(e.append(...-1===o?a:a.slice(0,o+1)),-1!==o&&o<a.length-1){const t=document.createElement("span");t.append(...a.slice(o+1)),e.append(t)}return t.remove(),e})(c)),o&&a.append(o),l&&a.append(l),it?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(e.filter(t=>!t.hasAttribute(oe)));return(e=>{const n=e.find(t=>"FIGURE"!==t.tagName);!ue&&n&&(ue=!0,console.warn(`[${t}] A chart is a <${n.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`,n))})(a),await(async e=>{await Promise.all(e.filter(t=>t.hasAttribute("data-chart-src")).map(async e=>{const n=e.getAttribute("data-chart-src"),a=Array.from(e.querySelectorAll("table")).find(t=>t.tHead)??null;for(const t of e.querySelectorAll("table"))t!==a&&t.remove();try{const t=await fetch(n);if(!t.ok)throw new Error(`${t.status} ${t.statusText}`);const o=await t.json(),r=Array.isArray(o)?o:o?.rows?Array.isArray(o.rows)?o.rows:ee(o.rows):ee(o);if(!Array.isArray(r))throw new Error("no rows in it: a list of rows, an object with rows, or names with their values");const s=((t,e,n,a=document.createElement("table"))=>{for(const r of a.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr"))r.remove();if(!a.tHead&&(e.length||n)){const t=a.createTHead().insertRow(),o=document.createElement("th");o.textContent=n,t.append(o);for(const n of e){const e=document.createElement("th");e.textContent=n,t.append(e)}}const o=document.createElement("tbody");a.append(o);for(const r of t){const t=o.insertRow();"total"===r.kind&&(t.dataset.kind="total");const e=document.createElement("th");e.textContent=String(r.label??""),t.append(e);for(const n of r.values??[r.value??null])t.insertCell().textContent=null===n?"":String(n)}return a})(r,Array.isArray(o?.series)?o.series.map(String):[],"string"==typeof o?.label?o.label:"",a??void 0);if(!a){const t=e.querySelector(":scope > figcaption");t?t.after(s):e.prepend(s)}s.tHead||it?.log?.(`The table from "${n}" has no header row, so a screen reader cannot name its columns.`),it?.log?.(`Read ${r.length} rows from "${n}"`)}catch(o){const e="file:"===window.location.protocol;console.warn(`[${t}] Could not read the chart data in "${n}": ${o.message}.`+(e?" A page opened as a file cannot fetch files; open it from a server.":""))}}))})(a),(t=>{for(const e of t){for(const n of e.querySelectorAll("tbody tr")){const t=n.cells[0];if("TD"!==t?.tagName||n.cells.length<2)continue;const e=document.createElement("th");for(const{name:n,value:a}of Array.from(t.attributes))e.setAttribute(n,a);e.append(...t.childNodes),t.replaceWith(e);for(let a=ne(e);a?.matches(ae);a=ne(e))n.dataset.kind="total",a.replaceWith(...a.childNodes)}const t=Array.from(e.querySelector("thead tr:last-child")?.children??[]);for(const e of t.slice(1))for(let t=ne(e);t?.matches(ae);t=ne(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(a),((e,n)=>{if(!n)return;const a=new Map;for(const o of e){let e=o.getAttribute("data-chart-keys")||null;if(!e)continue;if(a.has(e)){const n=a.get(e)+1;a.set(e,n),console.warn(`[${t}] Two charts have data-chart-keys="${e}", so this one uses "${e}-${n}" to keep their translations apart.`),e=`${e}-${n}`}else a.set(e,1);o.querySelectorAll("tbody th").forEach((t,a)=>{t.getAttribute(n)||t.setAttribute(n,`${e}-row${a+1}`)});const r=dt(o);r.length>1&&r.forEach((t,a)=>{t.getAttribute(n)||t.setAttribute(n,`${e}-col${a+1}`)}),it?.log?.(`Keys for "${e}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,n.langattribute),a},he=(e,a)=>{const o=it.timed("Building",e,()=>Pt(e,a));return o?(e.setAttribute(oe,""),((e,a)=>{let o=e,r=ie(o.figure),u=null,d=!1,b=!1;const m=async()=>{if(!a.animate)return Zt(o,!0);const t=o.figure.classList.contains("is-shown");if(!d||null===u||t||b)!d&&a.replay&&t&&Zt(o,!1);else{b=!0;const t=re()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(o.figure);t&&await(e=t,new Promise(t=>{const n=["animationstart","transitionrun"],a=()=>{for(const t of n)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(e)&&a()},r=new MutationObserver(()=>{"0"!==getComputedStyle(e).opacity&&a()});for(const e of n)document.addEventListener(e,o,!0);r.observe(e,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(re())return;await new Promise(requestAnimationFrame);const n=t.getAnimations().filter(t=>t instanceof CSSAnimation);for(let r=t.parentElement;r&&r!==document.body;r=r.parentElement)n.push(...r.getAnimations());let a=0;for(const r of n){const t=r.effect?.getComputedTiming(),n=Number(t?.activeDuration??0);if(!t||!Number.isFinite(n))continue;const o=Number(t.delay??0)+n*e;a=Math.max(a,o-Number(r.currentTime??0))}var o;a>0&&await(o=a,new Promise(t=>setTimeout(t,o)))})(o.figure,((t,e)=>{const n=Number.parseFloat(t.dataset.chartEntrance??""),a=Number.isFinite(n)?n:e.entrance;return Math.min(Math.max(a,0),1)})(o.figure,a)),b=!1,!d&&a.replay||Zt(o,!0)}var e},p=()=>{const t=ie(o.figure);if(!t||t===r)return;const e=it.timed("Building",o.figure,()=>Pt(o.figure,a,t));e&&((t=>{Lt(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${c}`)?.remove(),t.controls?.remove()})(o),bt(e,o.step,!0),o=e,r=t,u=null)},y=()=>{p();const e=o.plot.clientWidth;e&&e!==u&&it.timed("Layout",o.figure,()=>((e,a)=>{const{plot:o,svg:r,rows:c,type:u,values:d,series:h,seriesValues:b,names:m,annotations:p}=e,y=o.clientWidth;if(!y)return!1;const M=f/y,v=Number.parseFloat(e.figure.dataset.chartAspect??""),k=f*(v>0?v:u.aspect??a.aspect);o.classList.add("is-placed");for(const t of[...b.flat(),...e.totals])delete t.dataset.place;o.style.removeProperty("--_fit"),e.categories[0]?.parentElement?.style.removeProperty("--_beside"),(t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>O.set(t,n[e]))})([...b.flat(),...e.totals,...m,...e.categories,...p.map(t=>t.badge)]);const A=(d[0]?B(d[0]).height:0)*M,N=p[0]?.badge?B(p[0].badge).height*M:0,H=Math.max(k,It(e.figure,M,"--tablechart-min-height","200px")??0,u.minHeight?.({labelHeight:A,nameHeight:Math.max(0,S(e.categories.map(t=>B(t).height)))*M,unit:M,rows:c.length,series:h.length,stacked:e.stacked})??0),T=e.stacked?c.map(t=>{const e=P(t,h.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):c,z=(u.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(e.stacked?T.map(t=>({...t,cells:[t.cells[0]]})):c),C={labelHeight:A,badgeHeight:N,hasAnnotations:p.length>0,unit:M,series:h.length,focused:h.some(t=>t.focus),stacked:e.stacked},L=Math.max((U=S,e.stacked?U(c.map(t=>j(t,h.length,u.running).top)):U([...z.flatMap(t=>[t.from,t.to,t.value]),...c.flatMap(t=>t.cells.slice(0,h.length).map(t=>t.value))])),0);var U;const _=z.some(t=>"up"===t.kind||"down"===t.kind)?z.flatMap(t=>[t.from,t.to]):e.stacked?c.map(t=>j(t,h.length,u.running).bottom):c.flatMap(t=>t.cells.slice(0,h.length).map(t=>t.value)),E=Math.min(-S(_.map(t=>-t)),0),F=u.headroom?.(C)??A,q=2*M+(u.footroom?.(C)??0)+(E<0?A+4*M:0),R=H-F-q,W=1.02*L,D=1.02*E,V=p.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,K=t=>{const e=Number.parseFloat(V?.getAttribute(t)??"");return Number.isFinite(e)?e:null},G=K("data-from")??K("data-at"),Z=K("data-to");let J=null;if(V&&(null!==G||null!==Z)){const e=G??0,n=Z??W,a=null===Z?e:null===G?n:(e+n)/2,o=V.getAttribute("data-size"),r=o?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===o||r||console.warn(`[${t}] data-size="${o}" is not a percentage, such as 30%. Using the default.`);const s=Math.min(Math.max(r?Number(r[1])/100:null===Z?.22:.3,.05),.8),c=z.filter(t=>("up"===t.kind||"down"===t.kind)&&Math.max(t.from,t.to)>e&&Math.min(t.from,t.to)<n);u.breakable?E<0?console.warn(`[${t}] A chart with values below zero cannot break its scale.`):e<0||n<=e||n>W||0===e&&n===W?console.warn(`[${t}] A break from ${e} to ${n} does not fit a scale that runs from 0 to ${L}.`):c.length?console.warn(`[${t}] A break from ${e} to ${n} would cut a step that floats. Keep it below or above the steps.`):J={lo:e,hi:n,gap:a,share:s}:console.warn(`[${t}] This kind of chart cannot break its scale.`)}const Q=J?J.gap:null,X=(J&&It(e.figure,M,"--tablechart-break-gap",""))??13,Y=H-q,tt=W-D||1;let et=t=>Y-(t-D)/tt*R;if(J){const{lo:t,hi:e,gap:n,share:a}=J,o=R*a,r=(R-o-X)/(t+(W-e)),s=o/(e-t);et=a=>a<=t?Y-a*r:a<=n?Y-t*r-(a-t)*s:a<=e?Y-t*r-(a-t)*s-X:Y-t*r-o-X-(a-e)*r}const nt=m.length?S(m.map(t=>B(t).width))*M+12*M:0,at=e.categories[0]?.parentElement;at&&(at.style.paddingRight=nt?nt/f*100+"%":"");const ot=(f-nt)/c.length,rt=t=>t>=0&&t<c.length?t:null;e.rowAt=u.centre?null:"beside"===u.categories?(t,e)=>rt(Math.floor(e*M/(H/c.length))):t=>rt(Math.floor(t*M/ot));const st=ot/f*100,ct=100/c.length;e.rowBox="beside"===u.categories?t=>[0,t*ct,100,ct]:t=>[t*st,0,st,100],r.setAttribute("viewBox",`0 0 1000 ${w(H)}`),r.textContent="",e.checks=[];const lt={rows:c,segments:z,cx:t=>(t+.5)*ot,y:et,barWidth:Math.min(ot*a.barfill,Kt(e.figure,M)),barMax:Kt(e.figure,M),height:H,unit:M,labelHeight:A,badgeHeight:N,after:c.length,note:0,labels:"inside"===e.figure.dataset.chartLabels||"outside"!==e.figure.dataset.chartLabels&&"inside"===a.labels?"inside":"outside",insideAlign:Vt(e.figure),breakAt:Q,squeeze:J,breakGap:X,stacked:e.stacked,shape:Ft(e.figure,a),totals:e.totals,svg:r,plot:o,values:d,series:h,seriesValues:b,names:m,categories:e.categories,centre:e.centre,config:a,checks:e.checks};o.style.setProperty("--count",String(Math.max(1,...c.map(t=>t.slot+1)))),u.draw(lt);for(const[t,n]of p.entries()){n.badge?.setAttribute("data-note",String(t+1));const a=n.series,o=t=>({...t,...t.cells[a]??t.cells[0]});n.type.draw(n.spec,n.badge,{...lt,...e.stacked&&{rows:T,...e.totals.length&&{values:e.totals}},...a>0&&!e.stacked&&{rows:c.map(o),segments:z.map(t=>{const e=o(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:b[a]},after:n.after,note:t+1})}(t=>{const e=t.plan;if(!e)return;const a=e.rows.length-1,o=t=>e.series.map((n,a)=>e.cells[t]?.[a]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=o(t);return e.some(t=>null===t)?null:Math.min(...e)},c=new Set(t.totals),l=(t,e,n,a)=>{t.style.setProperty(n,String(a)),t.style.removeProperty("--d"),null===e?t.style.removeProperty("--step"):t.style.setProperty("--step",String(e))};for(const n of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(n.closest("table, .tablechart-controls")||n.hasAttribute("data-from"))continue;const t=Number(n.dataset.note);if(t>0){const a=e.notes[t-1];a&&l(n,a.step,"--after",a.after);continue}const s=n.dataset.row?Number(n.dataset.row)-1:a;if(n.classList.contains("tablechart-connector")){const t=e.rows[s-1],a=e.rows[s];if(t&&a){const e=(t.step??-1)>(a.step??-1);l(n,e?t.step:a.step,"--i",e?t.slot+1:a.slot)}continue}if(c.has(n)){const t=o(s).filter(t=>null!==t);l(n,t.length?Math.max(...t):null,"--i",e.rows[s]?.slot??0);continue}if(n.hasAttribute("data-stack")){l(n,r(s),"--i",e.rows[s]?.slot??0);continue}const i=n.dataset.series?Number(n.dataset.series)-1:0,u=n.dataset.series?e.series[i]:void 0;if(n.classList.contains("tablechart-piece")){const t=o(s)[i]??null,a=e.cells[s]?.[i];l(n,t===r(s)?null:t,"--i",a&&null!==a.step?a.slot:s);continue}if("legend"===n.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(n,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[s]?.[i];d&&null!==d.step?l(n,d.step,"--i",d.slot):u&&null!==u.step?l(n,u.step,"--i",s):e.rows[s]&&l(n,e.rows[s].step,"--i",e.rows[s].slot)}const u=t.figure.querySelector(`.${i}`);if(u){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?l(u,null,"--i",0):l(u,n,"--i",t.filter(t=>t===n).length)}const d=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),h=e.series.some(t=>null!==t.step)?e.rows.length:1;t.plot.style.setProperty("--count",String(Math.max(h,...d)));const f=t.figure.querySelectorAll(`.${n}`),b=f[f.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&f.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${s}`));if(m.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=m.length,o=Math.max(0,m.findIndex((t,n)=>e(t)!==e(m[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=m[(o+t)%a],s=r[r.length-1];s&&e(s[0])===e(n)?s.push(n):r.push([n])}const s=new Map;for(const t of r){const e=t.reduce((t,e)=>t+n(e),0);let a=0;for(const o of t)s.set(o.dataset.row??"",g(a,n(o),e)),a+=n(o)}for(const c of t.figure.querySelectorAll("[data-row]")){const t=s.get(c.dataset.row??"");t&&c.style.getPropertyValue("--start")&&(c.style.setProperty("--start",t.start.toFixed(4)),c.style.setProperty("--span",t.span.toFixed(4)),c.classList.contains("tablechart-slice")&&c.style.setProperty("--ease",t.easing))}}ft(t)})(e);const it=e.categories[0]?.parentElement;it&&"beside"!==u.categories&&!u.centre&&I(it,e.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const ut=p.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*M,n=t.offsetHeight*M,a=Number.parseFloat(t.style.left)/100*f,o=Number.parseFloat(t.style.top)/100*H,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*M;return[$("rect",{class:l,"data-for":"badge","data-note":t.dataset.note??"",x:a-e/2,y:o-n/2,width:e,height:n,rx:null===s?c:e*s,ry:null===s?c:n*s,style:["--after","--step"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ")})]});x(r,ut,f,H);const dt=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return e.figure.toggleAttribute("data-left-out",[...b,e.totals].some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||u.centre&&c[Number(t.dataset.row)-1]?.isTotal)(e)&&!dt(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>dt(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(o,a))&&(u=e,m())};let M=!1;const v=new ResizeObserver(()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,y()}))}),k=new IntersectionObserver(t=>{for(const e of t)d=e.isIntersecting,m()},{threshold:a.threshold}),A=()=>{o.figure.classList.add(h),Zt(o,!0),o.figure.offsetWidth},N=()=>o.figure.classList.remove(h),H=()=>{u=null,y()},T={relabel:()=>Gt(o,a),refresh:H};p(),y(),v.observe(o.figure),k.observe(o.figure),window.addEventListener("beforeprint",A),window.addEventListener("afterprint",N),(t=>{se.add(t),ce||(ce=new MutationObserver(()=>{for(const t of se)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of se)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(T);const z={figure:o.figure,refresh:H,next:()=>bt(o,o.step+1),previous:()=>bt(o,o.step-1),stepTo:t=>bt(o,t),get step(){return o.step},get steps(){return o.plan?.count??0},destroy(){v.disconnect(),k.disconnect(),window.removeEventListener("beforeprint",A),window.removeEventListener("afterprint",N),(t=>{se.delete(t),!se.size&&ce&&(ce.disconnect(),ce=null)})(T),Lt(o),o.figure.tablechart===z&&delete o.figure.tablechart}};return o.figure.tablechart=z,z})(o,a)):null},fe=[["--tablechart-duration","--tablechart-animation-element-duration"],["--tablechart-stagger","--tablechart-animation-stagger, a share of the element time"],["--tablechart-easing","--tablechart-animation-ease"],["--tablechart-category-size","--tablechart-name-size"],["--tablechart-category-padding","--tablechart-name-padding"],["--tablechart-categories-gap","--tablechart-name-gap"],["--tablechart-inside-align","--tablechart-value-align"],["--tablechart-bar-ink","--tablechart-bar-value-color"],["--tablechart-piece-ink","--tablechart-piece-value-color"],["--tablechart-up-ink","--tablechart-up-value-color"],["--tablechart-down-ink","--tablechart-down-value-color"],["--tablechart-total-ink","--tablechart-total-value-color"],["--tablechart-series-ink","--tablechart-series-own-color"],["--tablechart-dash","--tablechart-series-dash"],["--tablechart-dot","--tablechart-series-dot"],["--tablechart-muted-share","--tablechart-series-muted-share"],["--tablechart-rule-color","--tablechart-baseline-color"],["--tablechart-rule-width","--tablechart-baseline-width"],["--tablechart-rule-opacity","--tablechart-baseline-opacity"],["--tablechart-key-size","--tablechart-legend-key-size"],["--tablechart-controls-justify","--tablechart-control-justify"],["--tablechart-controls-gap","--tablechart-control-gap"]],be={up:"grow",across:"sweep"},me=!1;window.Tablechart={init:async(e={},n=document)=>{const a={...b,...e};a.debug&&(it.enabled=!0);const o=await de(Array.from(n.querySelectorAll(a.selector)),a);((e,n)=>{if(me)return;const a=t=>{const e=be[String(t)];return e?[`"${t}" is now "${e}"`]:[]},o=new Set(a(n.animate));void 0!==n.hover&&o.add('the "hover" option is now "tooltip"');for(const t of e){t.hasAttribute("data-chart-hover")&&o.add("data-chart-hover is now data-chart-tooltip");const e=getComputedStyle(t);for(const[t,n]of fe)e.getPropertyValue(t).trim()&&o.add(`${t} is now ${n}`);for(const n of a(t.getAttribute("data-chart-animate")))o.add(n)}o.size&&(me=!0,console.warn(`[${t}] ${[...o].join("; ")}. The old names work until the next minor version.`))})(o,a);const r=o.map(t=>he(t,a)).filter(t=>null!==t);return it.log(`Made ${r.length} chart(s).`),{charts:r,refresh:()=>{for(const t of r)t.refresh()},destroy:()=>{for(const t of r)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...b,...e};n.debug&&(it.enabled=!0);const[a]=await de([t],n);return a?he(a,n):null},defaultConfig:b}}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@martinomagnifico/tablechart",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Simple charts from an HTML or Markdown table: column, bar, line, area, waterfall and donut, with annotations. A chart builds when it scrolls into view.",
5
5
  "type": "module",
6
6
  "sideEffects": [