@martinomagnifico/tablechart 1.2.5 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -3
- package/dist/tablechart-additional-types.mjs +60 -60
- package/dist/tablechart-core.d.mts +1 -1
- package/dist/tablechart-core.mjs +1 -1
- package/dist/tablechart-shared.d.mts +25 -4
- package/dist/tablechart-shared.mjs +2660 -2537
- package/dist/tablechart-summary.js +1 -1
- package/dist/tablechart-summary.mjs +149 -130
- package/dist/tablechart.css +1 -1
- package/dist/tablechart.d.mts +1 -1
- package/dist/tablechart.js +1 -1
- package/dist/tablechart.mjs +1 -1
- package/package.json +8 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){var t=e=>{const t=e.length,n=e.reduce((e,t)=>e+t.x,0)/t,a=e.reduce((e,t)=>e+t.y,0)/t,r=e.reduce((e,t)=>e+(t.x-n)**2,0),o=r?e.reduce((e,t)=>e+(t.x-n)*(t.y-a),0)/r:0,s=e=>a+o*(e-n),c=t>2?Math.sqrt(e.reduce((e,t)=>e+(t.y-s(t.x))**2,0)/(t-2)):0,l=r?c/Math.sqrt(r):0;return{at:s,spread:c,t:l?o/l:o?Number.POSITIVE_INFINITY:0,n:t}},n=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13],a=e=>{const t=e.map(e=>e.y),n=Math.min(...t),a=Math.max(...t),r=n<0&&a>0,o=a-n||1;return{mean:t.reduce((e,t)=>e+t,0)/t.length,share:(e,t)=>e/(r?o:Math.abs(t)||o)*100}},r={selector:"[data-chart]:not(th)",delimiters:["{","}"],langattribute:"data-i18n",flat:5,outliers:25,words:{up:"up",down:"down",flat:"flat",unclear:"unclear",above:"above",below:"below"}},o="chart-summary",s="data-summary-
|
|
1
|
+
!function(e){var t=e=>{const t=e.length,n=e.reduce((e,t)=>e+t.x,0)/t,a=e.reduce((e,t)=>e+t.y,0)/t,r=e.reduce((e,t)=>e+(t.x-n)**2,0),o=r?e.reduce((e,t)=>e+(t.x-n)*(t.y-a),0)/r:0,s=e=>a+o*(e-n),c=t>2?Math.sqrt(e.reduce((e,t)=>e+(t.y-s(t.x))**2,0)/(t-2)):0,l=r?c/Math.sqrt(r):0;return{at:s,spread:c,t:l?o/l:o?Number.POSITIVE_INFINITY:0,n:t}},n=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13],a=e=>{const t=e.map(e=>e.y),n=Math.min(...t),a=Math.max(...t),r=n<0&&a>0,o=a-n||1;return{mean:t.reduce((e,t)=>e+t,0)/t.length,share:(e,t)=>e/(r?o:Math.abs(t)||o)*100}},r={selector:"[data-chart]:not(th)",delimiters:["{","}"],langattribute:"data-i18n",flat:5,outliers:25,words:{up:"up",down:"down",flat:"flat",unclear:"unclear",above:"above",below:"below"}},o="chart-summary",s="data-summary-ready",c="data-summary-template",l="data-summary-text",u=["line","area"],i=["extremes","range","change","trend","outliers","notes"],d=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=0,h=new Set,m=t=>{h.has(t)||(h.add(t),console.warn(`[${e.LIBRARY_NAME}] ${t}`))},w=t=>{const n=t.filter(e=>!e.missing),a=n.reduce((t,n)=>(0,e.decimalsIn)(n.number)>(0,e.decimalsIn)(t.number)?n:t,n[0]??t[0]);if(!a)return;const r=n.reduce((e,t)=>e+t.value,0);return{...a,raw:"",number:r.toFixed((0,e.decimalsIn)(a.number)),missing:!n.length,value:r}},g=(r,o,s,c)=>{const l=(0,e.readTable)(r,s.langattribute),i=(0,e.readSeries)(r,l.filter(e=>!e.isTotal),s.langattribute),d=o<0,f=l.filter(e=>!e.isTotal).map(e=>d?{...e,cells:[w(e.cells.slice(0,i.length))].filter(e=>!!e)}:e),h=d?0:o,m=d?void 0:i[o],g=(e,t)=>{if(!t||!s.langattribute)return e;const n=document.createElement("span");return n.setAttribute(s.langattribute,t),n.textContent=e,n},b=Math.max(0,...f.map(t=>(0,e.decimalsIn)(t.cells[h]?.number??""))),p=(t,n,a=b)=>{const[r,o]=(0,e.splitSign)(t,a,c);return n.prefix+r+o+n.suffix},v=e=>new Intl.NumberFormat(c,{style:"percent",maximumFractionDigits:Math.abs(e)<10?1:0}).format(e/100),y=e=>g(e.label,e.key),M=r.querySelector(":scope > figcaption"),$=M?.querySelector("b, strong")??M,x={values:{title:g(($?.textContent??"").trim(),s.langattribute&&$?.getAttribute(s.langattribute)||null),rows:(0,e.splitSign)(f.length,0,c).join(""),series:m?g(m.name,m.key):""},counts:{rows:f.length}},O=f.filter(e=>e.note),j=O.length?{values:{"notes.count":(0,e.splitSign)(O.length,0,c).join("")},counts:{"notes.count":O.length},items:O.map(e=>({name:y(e),note:g(e.note??"",e.noteKey)}))}:null,A=f.flatMap((e,t)=>{const n=e.cells[h];return n&&!n.missing?[{row:e,cell:n,x:t,y:n.value}]:[]});if(!A.length)return{chart:x,notes:j,extremes:null,range:null,change:null,trend:null,outliers:null};let F=A[0],N=A[0];for(const e of A)e.y>F.y&&(F=e),e.y<N.y&&(N=e);const S={values:{"highest.name":y(F.row),"highest.value":p(F.y,F.cell),"lowest.name":y(N.row),"lowest.value":p(N.y,N.cell)}},E=d?void 0:l.find(e=>e.isTotal)?.cells[h],I=E&&!E.missing?E.value:A.reduce((e,t)=>e+t.y,0);S.values.total=p(I,F.cell),I>0&&A.every(e=>e.y>=0)&&(S.values["highest.share"]=v(F.y/I*100),S.values["lowest.share"]=v(N.y/I*100));const k={values:{"range.from":p(N.y,N.cell),"range.to":p(F.y,F.cell),"range.difference":p(F.y-N.y,F.cell)}},D=r.getAttribute("data-chart")||"column";if(!u.includes(D)&&!r.hasAttribute("data-chart-ordered"))return{chart:x,notes:j,extremes:S,range:k};if(A.length<2)return{chart:x,notes:j,extremes:S,range:k,change:null,trend:null,outliers:null};const{share:L}=a(A),T=e=>Math.abs(e)<s.flat?"flat":e>0?"up":"down",q=A[0],B=A[A.length-1],C=L(B.y-q.y,q.y),H={values:{"first.name":y(q.row),"first.value":p(q.y,q.cell),"last.name":y(B.row),"last.value":p(B.y,B.cell),"change.difference":p(Math.abs(B.y-q.y),B.cell),"change.percent":v(Math.abs(C)),change:s.words[T(C)]},when:T(C)},R=((e,r=5,o=25)=>{if(e.length<4)return null;const{mean:s,share:c}=a(e),l=t=>e.filter(e=>Math.abs(c(e.y-t(e.x),t(e.x)))>o),u=t=>t.length<=e.length/5;let i=t(e),d=l(i.at);d.length&&u(d)&&(i=t(e.filter(e=>!d.includes(e))),d=l(i.at)),u(d)||(i=t(e),d=[]);const f=i.at,h=e[0],m=e[e.length-1],w=c(f(m.x)-f(h.x),s),g=Math.abs(i.t)>=(b=i.n-2,n[b-1]??(b<30?2.1:2));var b;const p=Math.abs(c(i.spread,s))<r,v=Math.abs(w)<r?"flat":w>0?"up":"down",y="flat"===v?p?"flat":"unclear":g?v:"unclear";return{course:y,line:f,outside:"unclear"===y?[]:d}})(A,s.flat,s.outliers);if(!R)return{chart:x,notes:j,extremes:S,range:k,change:H,trend:null,outliers:null};const{course:W,line:z,outside:G}=R,J={values:{trend:s.words[W],"trend.percent":v(Math.abs(L(z(B.x)-z(q.x),z(q.x)))),"trend.from":p(z(q.x),q.cell),"trend.to":p(z(B.x),B.cell),"flat.percent":v(s.flat),"outliers.percent":v(s.outliers)},when:W};return"unclear"===W?{chart:x,notes:j,extremes:S,range:k,change:H,trend:J}:{chart:x,notes:j,extremes:S,range:k,change:H,trend:J,outliers:G.length?{values:{"outliers.count":(0,e.splitSign)(G.length,0,c).join("")},counts:{"outliers.count":G.length},items:G.map(e=>({name:y(e.row),value:p(e.y,e.cell),expected:p(z(e.x),e.cell),deviation:v(Math.abs(L(e.y-z(e.x),z(e.x)))),side:s.words[e.y>z(e.x)?"above":"below"]}))}:null}},b=(e,t,n,a,r)=>{const[o,s]=a.delimiters,c=new RegExp(`${d(o)}([\\w.]+)(\\|.*?)?${d(s)}`,"g"),l=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),u=[];for(;l.nextNode();)u.push(l.currentNode);for(const i of u){const e=i.textContent??"",a=[];let o=0;for(const s of e.matchAll(c)){const[c,l,u]=s;let i=t[l];if(void 0!==i){if(u&&void 0!==n[l]){const e=Object.fromEntries(u.slice(1).split("|").map(e=>[e.slice(0,e.indexOf(":")),e.slice(e.indexOf(":")+1)])),t=e[new Intl.PluralRules(r).select(n[l])]??e.other;void 0!==t&&(i=t.replace("#","string"==typeof i?i:i.textContent??""))}a.push(e.slice(o,s.index),"string"==typeof i?i:i.cloneNode(!0)),o=(s.index??0)+c.length}else m(`A summary has the placeholder ${c}, which no analysis fills.`)}a.length&&(a.push(e.slice(o)),i.replaceWith(...a))}},p=(e,t)=>{const n=e.dataset.summary;if(void 0===n)return!0;if(i.includes(n)||m(`A summary asks for the analysis "${n}", which does not exist.`),!(n in t))return!1;const a=t[n],r=e.dataset.when;return e.hasAttribute("data-none")?!a:!(!a||r&&a.when!==r)},v=(e,t,n,a)=>{const r=e.cloneNode(!0);for(const l of[c,"hidden","id","data-summary","data-none","data-when","data-series",...n.langattribute?[n.langattribute]:[]])r.removeAttribute(l);r.setAttribute(l,"");const o=Object.values(t).filter(e=>!!e),s=Object.assign({},...o.map(e=>e.values)),u=Object.assign({},...o.map(e=>e.counts??{}));for(const c of r.querySelectorAll("[data-summary]"))if(p(c,t))for(const e of["data-summary","data-none","data-when"])c.removeAttribute(e);else c.remove();for(const c of r.querySelectorAll("[data-each]")){const e=(t[c.dataset.each??""]?.items??[]).map(e=>{const t=c.cloneNode(!0);return t.removeAttribute("data-each"),b(t,{...s,...e},u,n,a),t}),r=new Intl.ListFormat(a,{type:"conjunction"}).formatToParts(e.map((e,t)=>String(t)));c.replaceWith(...r.map(t=>"element"===t.type?e[Number(t.value)]:t.value))}return b(r,s,u,n,a),r},y=(e,t={})=>{const n={...r,...t},a=n.locale||document.documentElement.lang||void 0,s=e.querySelector(`:scope > .${o}`);if(!s||!e.querySelector("tbody tr"))return;s.id||(s.id="tablechart-summary-"+ ++f);const u=(e.getAttribute("aria-describedby")??"").split(/\s+/).filter(Boolean);u.includes(s.id)||e.setAttribute("aria-describedby",[...u,s.id].join(" "));for(const r of s.querySelectorAll(`:scope > [${l}]`))r.remove();const i=new Map;for(const r of s.querySelectorAll(":scope > *")){r.setAttribute(c,""),r.hidden=!0;const t="total"===r.dataset.series?-1:Math.max(1,Number.parseInt(r.dataset.series??"1",10)||1)-1;i.has(t)||i.set(t,g(e,t,n,a));const o=i.get(t);p(r,o)&&r.after(v(r,o,n,a))}},M=null,$={init:(e={})=>{const t={...r,...e,words:{...r.words,...e.words}};if(M)return;M=t;const n=()=>Array.from(document.querySelectorAll(t.selector)).filter(e=>e.querySelector(`:scope > .${o}`)),a=new Set,l=document.documentElement,u=()=>{a.size||l.hasAttribute(s)||!n().every(e=>e.querySelector("tbody tr"))||(l.setAttribute(s,""),document.dispatchEvent(new CustomEvent("tablechart:summary-ready")))},i=e=>{l.removeAttribute(s),a.size||requestAnimationFrame(()=>{const e=[...a];a.clear();for(const n of e)y(n,t);u()}),a.add(e)},d=new WeakSet,f=e=>{y(e,t),(e=>{const t=[...e.querySelectorAll(`:scope > .${o} > [${c}]`),...e.querySelectorAll(":scope > table")];for(const n of t)d.has(n)||(d.add(n),new MutationObserver(()=>i(e)).observe(n,{subtree:!0,childList:!0,characterData:!0}))})(e)};for(const r of n())f(r);u(),document.addEventListener("tablechart:table",e=>{const n=e.target;n instanceof HTMLElement&&n.matches(t.selector)&&n.querySelector(`:scope > .${o}`)&&(f(n),u())}),t.locale||new MutationObserver(()=>{for(const e of n())i(e)}).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})},fill:y,defaults:r};window.Tablechart.Summary=$}(Tablechart.kit);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as e, L as t, T as n, _ as r, b as i, g as a, x as o } from "./tablechart-shared.mjs";
|
|
2
2
|
// src/js/summary.ts
|
|
3
3
|
var s = {
|
|
4
4
|
selector: "[data-chart]:not(th)",
|
|
@@ -14,42 +14,56 @@ var s = {
|
|
|
14
14
|
above: "above",
|
|
15
15
|
below: "below"
|
|
16
16
|
}
|
|
17
|
-
}, c = "chart-summary", l = "data-summary-
|
|
17
|
+
}, c = "chart-summary", l = "data-summary-ready", u = "data-summary-template", d = "data-summary-text", f = ["line", "area"], p = [
|
|
18
18
|
"extremes",
|
|
19
19
|
"range",
|
|
20
20
|
"change",
|
|
21
21
|
"trend",
|
|
22
22
|
"outliers",
|
|
23
23
|
"notes"
|
|
24
|
-
],
|
|
25
|
-
|
|
26
|
-
},
|
|
27
|
-
let
|
|
24
|
+
], m = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), h = 0, g = /* @__PURE__ */ new Set(), _ = (e) => {
|
|
25
|
+
g.has(e) || (g.add(e), console.warn(`[${t}] ${e}`));
|
|
26
|
+
}, v = (t) => {
|
|
27
|
+
let n = t.filter((e) => !e.missing), r = n.reduce((t, n) => e(n.number) > e(t.number) ? n : t, n[0] ?? t[0]);
|
|
28
|
+
if (!r) return;
|
|
29
|
+
let i = n.reduce((e, t) => e + t.value, 0);
|
|
30
|
+
return {
|
|
31
|
+
...r,
|
|
32
|
+
raw: "",
|
|
33
|
+
number: i.toFixed(e(r.number)),
|
|
34
|
+
missing: !n.length,
|
|
35
|
+
value: i
|
|
36
|
+
};
|
|
37
|
+
}, y = (t, s, c, l) => {
|
|
38
|
+
let u = o(t, c.langattribute), d = i(t, u.filter((e) => !e.isTotal), c.langattribute), p = s < 0, m = u.filter((e) => !e.isTotal).map((e) => p ? {
|
|
39
|
+
...e,
|
|
40
|
+
cells: [v(e.cells.slice(0, d.length))].filter((e) => !!e)
|
|
41
|
+
} : e), h = p ? 0 : s, g = p ? void 0 : d[s], _ = (e, t) => {
|
|
28
42
|
if (!t || !c.langattribute) return e;
|
|
29
43
|
let n = document.createElement("span");
|
|
30
44
|
return n.setAttribute(c.langattribute, t), n.textContent = e, n;
|
|
31
|
-
},
|
|
32
|
-
let [i, a] =
|
|
45
|
+
}, y = Math.max(0, ...m.map((t) => e(t.cells[h]?.number ?? ""))), b = (e, t, r = y) => {
|
|
46
|
+
let [i, a] = n(e, r, l);
|
|
33
47
|
return t.prefix + i + a + t.suffix;
|
|
34
|
-
},
|
|
48
|
+
}, x = (e) => new Intl.NumberFormat(l, {
|
|
35
49
|
style: "percent",
|
|
36
50
|
maximumFractionDigits: +(Math.abs(e) < 10)
|
|
37
|
-
}).format(e / 100),
|
|
51
|
+
}).format(e / 100), S = (e) => _(e.label, e.key), C = t.querySelector(":scope > figcaption"), w = C?.querySelector("b, strong") ?? C, T = {
|
|
38
52
|
values: {
|
|
39
|
-
title:
|
|
40
|
-
rows:
|
|
41
|
-
series:
|
|
53
|
+
title: _((w?.textContent ?? "").trim(), c.langattribute && w?.getAttribute(c.langattribute) || null),
|
|
54
|
+
rows: n(m.length, 0, l).join(""),
|
|
55
|
+
series: g ? _(g.name, g.key) : ""
|
|
42
56
|
},
|
|
43
|
-
counts: { rows:
|
|
44
|
-
},
|
|
45
|
-
values: { "notes.count":
|
|
46
|
-
counts: { "notes.count":
|
|
47
|
-
items:
|
|
48
|
-
name:
|
|
49
|
-
note:
|
|
57
|
+
counts: { rows: m.length }
|
|
58
|
+
}, E = m.filter((e) => e.note), D = E.length ? {
|
|
59
|
+
values: { "notes.count": n(E.length, 0, l).join("") },
|
|
60
|
+
counts: { "notes.count": E.length },
|
|
61
|
+
items: E.map((e) => ({
|
|
62
|
+
name: S(e),
|
|
63
|
+
note: _(e.note ?? "", e.noteKey)
|
|
50
64
|
}))
|
|
51
|
-
} : null,
|
|
52
|
-
let n = e.cells[
|
|
65
|
+
} : null, O = m.flatMap((e, t) => {
|
|
66
|
+
let n = e.cells[h];
|
|
53
67
|
return n && !n.missing ? [{
|
|
54
68
|
row: e,
|
|
55
69
|
cell: n,
|
|
@@ -57,108 +71,110 @@ var s = {
|
|
|
57
71
|
y: n.value
|
|
58
72
|
}] : [];
|
|
59
73
|
});
|
|
60
|
-
if (!
|
|
61
|
-
chart:
|
|
62
|
-
notes:
|
|
74
|
+
if (!O.length) return {
|
|
75
|
+
chart: T,
|
|
76
|
+
notes: D,
|
|
63
77
|
extremes: null,
|
|
64
78
|
range: null,
|
|
65
79
|
change: null,
|
|
66
80
|
trend: null,
|
|
67
81
|
outliers: null
|
|
68
82
|
};
|
|
69
|
-
let
|
|
70
|
-
for (let e of
|
|
71
|
-
let
|
|
72
|
-
"highest.name":
|
|
73
|
-
"highest.value":
|
|
74
|
-
"lowest.name":
|
|
75
|
-
"lowest.value":
|
|
76
|
-
} },
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"range.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
let k = O[0], A = O[0];
|
|
84
|
+
for (let e of O) e.y > k.y && (k = e), e.y < A.y && (A = e);
|
|
85
|
+
let j = { values: {
|
|
86
|
+
"highest.name": S(k.row),
|
|
87
|
+
"highest.value": b(k.y, k.cell),
|
|
88
|
+
"lowest.name": S(A.row),
|
|
89
|
+
"lowest.value": b(A.y, A.cell)
|
|
90
|
+
} }, M = p ? void 0 : u.find((e) => e.isTotal)?.cells[h], N = M && !M.missing ? M.value : O.reduce((e, t) => e + t.y, 0);
|
|
91
|
+
j.values.total = b(N, k.cell), N > 0 && O.every((e) => e.y >= 0) && (j.values["highest.share"] = x(k.y / N * 100), j.values["lowest.share"] = x(A.y / N * 100));
|
|
92
|
+
let P = { values: {
|
|
93
|
+
"range.from": b(A.y, A.cell),
|
|
94
|
+
"range.to": b(k.y, k.cell),
|
|
95
|
+
"range.difference": b(k.y - A.y, k.cell)
|
|
96
|
+
} }, F = t.getAttribute("data-chart") || "column";
|
|
97
|
+
if (!f.includes(F) && !t.hasAttribute("data-chart-ordered")) return {
|
|
98
|
+
chart: T,
|
|
99
|
+
notes: D,
|
|
100
|
+
extremes: j,
|
|
101
|
+
range: P
|
|
86
102
|
};
|
|
87
|
-
if (
|
|
88
|
-
chart:
|
|
89
|
-
notes:
|
|
90
|
-
extremes:
|
|
91
|
-
range:
|
|
103
|
+
if (O.length < 2) return {
|
|
104
|
+
chart: T,
|
|
105
|
+
notes: D,
|
|
106
|
+
extremes: j,
|
|
107
|
+
range: P,
|
|
92
108
|
change: null,
|
|
93
109
|
trend: null,
|
|
94
110
|
outliers: null
|
|
95
111
|
};
|
|
96
|
-
let { share:
|
|
112
|
+
let { share: I } = a(O), L = (e) => Math.abs(e) < c.flat ? "flat" : e > 0 ? "up" : "down", R = O[0], z = O[O.length - 1], B = I(z.y - R.y, R.y), V = {
|
|
97
113
|
values: {
|
|
98
|
-
"first.name":
|
|
99
|
-
"first.value":
|
|
100
|
-
"last.name":
|
|
101
|
-
"last.value":
|
|
102
|
-
"change.difference":
|
|
103
|
-
"change.percent":
|
|
104
|
-
change: c.words[
|
|
114
|
+
"first.name": S(R.row),
|
|
115
|
+
"first.value": b(R.y, R.cell),
|
|
116
|
+
"last.name": S(z.row),
|
|
117
|
+
"last.value": b(z.y, z.cell),
|
|
118
|
+
"change.difference": b(Math.abs(z.y - R.y), z.cell),
|
|
119
|
+
"change.percent": x(Math.abs(B)),
|
|
120
|
+
change: c.words[L(B)]
|
|
105
121
|
},
|
|
106
|
-
when:
|
|
107
|
-
},
|
|
108
|
-
if (!
|
|
109
|
-
chart:
|
|
110
|
-
notes:
|
|
111
|
-
extremes:
|
|
112
|
-
range:
|
|
113
|
-
change:
|
|
122
|
+
when: L(B)
|
|
123
|
+
}, H = r(O, c.flat, c.outliers);
|
|
124
|
+
if (!H) return {
|
|
125
|
+
chart: T,
|
|
126
|
+
notes: D,
|
|
127
|
+
extremes: j,
|
|
128
|
+
range: P,
|
|
129
|
+
change: V,
|
|
114
130
|
trend: null,
|
|
115
131
|
outliers: null
|
|
116
132
|
};
|
|
117
|
-
let { course:
|
|
133
|
+
let { course: U, line: W, outside: G } = H, K = {
|
|
118
134
|
values: {
|
|
119
|
-
trend: c.words[
|
|
120
|
-
"trend.percent":
|
|
121
|
-
"trend.from":
|
|
122
|
-
"trend.to":
|
|
123
|
-
"flat.percent":
|
|
124
|
-
"outliers.percent":
|
|
135
|
+
trend: c.words[U],
|
|
136
|
+
"trend.percent": x(Math.abs(I(W(z.x) - W(R.x), W(R.x)))),
|
|
137
|
+
"trend.from": b(W(R.x), R.cell),
|
|
138
|
+
"trend.to": b(W(z.x), z.cell),
|
|
139
|
+
"flat.percent": x(c.flat),
|
|
140
|
+
"outliers.percent": x(c.outliers)
|
|
125
141
|
},
|
|
126
|
-
when:
|
|
142
|
+
when: U
|
|
127
143
|
};
|
|
128
|
-
return
|
|
129
|
-
chart:
|
|
130
|
-
notes:
|
|
131
|
-
extremes:
|
|
132
|
-
range:
|
|
133
|
-
change:
|
|
134
|
-
trend:
|
|
144
|
+
return U === "unclear" ? {
|
|
145
|
+
chart: T,
|
|
146
|
+
notes: D,
|
|
147
|
+
extremes: j,
|
|
148
|
+
range: P,
|
|
149
|
+
change: V,
|
|
150
|
+
trend: K
|
|
135
151
|
} : {
|
|
136
|
-
chart:
|
|
137
|
-
notes:
|
|
138
|
-
extremes:
|
|
139
|
-
range:
|
|
140
|
-
change:
|
|
141
|
-
trend:
|
|
142
|
-
outliers:
|
|
143
|
-
values: { "outliers.count":
|
|
144
|
-
counts: { "outliers.count":
|
|
145
|
-
items:
|
|
146
|
-
name:
|
|
147
|
-
value:
|
|
148
|
-
expected:
|
|
149
|
-
deviation:
|
|
150
|
-
side: c.words[e.y >
|
|
152
|
+
chart: T,
|
|
153
|
+
notes: D,
|
|
154
|
+
extremes: j,
|
|
155
|
+
range: P,
|
|
156
|
+
change: V,
|
|
157
|
+
trend: K,
|
|
158
|
+
outliers: G.length ? {
|
|
159
|
+
values: { "outliers.count": n(G.length, 0, l).join("") },
|
|
160
|
+
counts: { "outliers.count": G.length },
|
|
161
|
+
items: G.map((e) => ({
|
|
162
|
+
name: S(e.row),
|
|
163
|
+
value: b(e.y, e.cell),
|
|
164
|
+
expected: b(W(e.x), e.cell),
|
|
165
|
+
deviation: x(Math.abs(I(e.y - W(e.x), W(e.x)))),
|
|
166
|
+
side: c.words[e.y > W(e.x) ? "above" : "below"]
|
|
151
167
|
}))
|
|
152
168
|
} : null
|
|
153
169
|
};
|
|
154
|
-
},
|
|
155
|
-
let [a, o] = r.delimiters, s = RegExp(`${
|
|
170
|
+
}, b = (e, t, n, r, i) => {
|
|
171
|
+
let [a, o] = r.delimiters, s = RegExp(`${m(a)}([\\w.]+)(\\|.*?)?${m(o)}`, "g"), c = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), l = [];
|
|
156
172
|
for (; c.nextNode();) l.push(c.currentNode);
|
|
157
173
|
for (let e of l) {
|
|
158
174
|
let r = e.textContent ?? "", a = [], o = 0;
|
|
159
175
|
for (let e of r.matchAll(s)) {
|
|
160
176
|
let [s, c, l] = e, u = t[c];
|
|
161
|
-
if (u === void 0)
|
|
177
|
+
if (u === void 0) _(`A summary has the placeholder ${s}, which no analysis fills.`);
|
|
162
178
|
else {
|
|
163
179
|
if (l && n[c] !== void 0) {
|
|
164
180
|
let e = Object.fromEntries(l.slice(1).split("|").map((e) => [e.slice(0, e.indexOf(":")), e.slice(e.indexOf(":") + 1)])), t = e[new Intl.PluralRules(i).select(n[c])] ?? e.other;
|
|
@@ -169,16 +185,16 @@ var s = {
|
|
|
169
185
|
}
|
|
170
186
|
a.length && (a.push(r.slice(o)), e.replaceWith(...a));
|
|
171
187
|
}
|
|
172
|
-
},
|
|
188
|
+
}, x = (e, t) => {
|
|
173
189
|
let n = e.dataset.summary;
|
|
174
190
|
if (n === void 0) return !0;
|
|
175
|
-
if (
|
|
191
|
+
if (p.includes(n) || _(`A summary asks for the analysis "${n}", which does not exist.`), !(n in t)) return !1;
|
|
176
192
|
let r = t[n], i = e.dataset.when;
|
|
177
193
|
return e.hasAttribute("data-none") ? !r : !!r && (!i || r.when === i);
|
|
178
|
-
},
|
|
194
|
+
}, S = (e, t, n, r) => {
|
|
179
195
|
let i = e.cloneNode(!0);
|
|
180
196
|
for (let e of [
|
|
181
|
-
|
|
197
|
+
u,
|
|
182
198
|
"hidden",
|
|
183
199
|
"id",
|
|
184
200
|
"data-summary",
|
|
@@ -187,9 +203,9 @@ var s = {
|
|
|
187
203
|
"data-series",
|
|
188
204
|
...n.langattribute ? [n.langattribute] : []
|
|
189
205
|
]) i.removeAttribute(e);
|
|
190
|
-
i.setAttribute(
|
|
206
|
+
i.setAttribute(d, "");
|
|
191
207
|
let a = Object.values(t).filter((e) => !!e), o = Object.assign({}, ...a.map((e) => e.values)), s = Object.assign({}, ...a.map((e) => e.counts ?? {}));
|
|
192
|
-
for (let e of i.querySelectorAll("[data-summary]")) if (!
|
|
208
|
+
for (let e of i.querySelectorAll("[data-summary]")) if (!x(e, t)) e.remove();
|
|
193
209
|
else for (let t of [
|
|
194
210
|
"data-summary",
|
|
195
211
|
"data-none",
|
|
@@ -198,33 +214,33 @@ var s = {
|
|
|
198
214
|
for (let e of i.querySelectorAll("[data-each]")) {
|
|
199
215
|
let i = (t[e.dataset.each ?? ""]?.items ?? []).map((t) => {
|
|
200
216
|
let i = e.cloneNode(!0);
|
|
201
|
-
return i.removeAttribute("data-each"),
|
|
217
|
+
return i.removeAttribute("data-each"), b(i, {
|
|
202
218
|
...o,
|
|
203
219
|
...t
|
|
204
220
|
}, s, n, r), i;
|
|
205
221
|
}), a = new Intl.ListFormat(r, { type: "conjunction" }).formatToParts(i.map((e, t) => String(t)));
|
|
206
222
|
e.replaceWith(...a.map((e) => e.type === "element" ? i[Number(e.value)] : e.value));
|
|
207
223
|
}
|
|
208
|
-
return
|
|
209
|
-
},
|
|
224
|
+
return b(i, o, s, n, r), i;
|
|
225
|
+
}, C = (e, t = {}) => {
|
|
210
226
|
let n = {
|
|
211
227
|
...s,
|
|
212
228
|
...t
|
|
213
229
|
}, r = n.locale || document.documentElement.lang || void 0, i = e.querySelector(`:scope > .${c}`);
|
|
214
230
|
if (!i || !e.querySelector("tbody tr")) return;
|
|
215
|
-
i.id || (i.id = `tablechart-summary-${++
|
|
231
|
+
i.id || (i.id = `tablechart-summary-${++h}`);
|
|
216
232
|
let a = (e.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean);
|
|
217
233
|
a.includes(i.id) || e.setAttribute("aria-describedby", [...a, i.id].join(" "));
|
|
218
|
-
for (let e of i.querySelectorAll(`:scope > [${
|
|
234
|
+
for (let e of i.querySelectorAll(`:scope > [${d}]`)) e.remove();
|
|
219
235
|
let o = /* @__PURE__ */ new Map();
|
|
220
236
|
for (let t of i.querySelectorAll(":scope > *")) {
|
|
221
|
-
t.setAttribute(
|
|
222
|
-
let i = Math.max(1, Number.parseInt(t.dataset.series ?? "1", 10) || 1) - 1;
|
|
223
|
-
o.has(i) || o.set(i,
|
|
237
|
+
t.setAttribute(u, ""), t.hidden = !0;
|
|
238
|
+
let i = t.dataset.series === "total" ? -1 : Math.max(1, Number.parseInt(t.dataset.series ?? "1", 10) || 1) - 1;
|
|
239
|
+
o.has(i) || o.set(i, y(e, i, n, r));
|
|
224
240
|
let a = o.get(i);
|
|
225
|
-
|
|
241
|
+
x(t, a) && t.after(S(t, a, n, r));
|
|
226
242
|
}
|
|
227
|
-
},
|
|
243
|
+
}, w = null, T = (e = {}) => {
|
|
228
244
|
let t = {
|
|
229
245
|
...s,
|
|
230
246
|
...e,
|
|
@@ -233,37 +249,40 @@ var s = {
|
|
|
233
249
|
...e.words
|
|
234
250
|
}
|
|
235
251
|
};
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
let n = () => Array.from(document.querySelectorAll(t.selector)).filter((e) => e.querySelector(`:scope > .${c}`)), r = /* @__PURE__ */ new Set(), i = (
|
|
239
|
-
r.size ||
|
|
252
|
+
if (w) return;
|
|
253
|
+
w = t;
|
|
254
|
+
let n = () => Array.from(document.querySelectorAll(t.selector)).filter((e) => e.querySelector(`:scope > .${c}`)), r = /* @__PURE__ */ new Set(), i = document.documentElement, a = () => {
|
|
255
|
+
r.size || i.hasAttribute(l) || !n().every((e) => e.querySelector("tbody tr")) || (i.setAttribute(l, ""), document.dispatchEvent(new CustomEvent("tablechart:summary-ready")));
|
|
256
|
+
}, o = (e) => {
|
|
257
|
+
i.removeAttribute(l), r.size || requestAnimationFrame(() => {
|
|
240
258
|
let e = [...r];
|
|
241
259
|
r.clear();
|
|
242
|
-
for (let n of e)
|
|
260
|
+
for (let n of e) C(n, t);
|
|
261
|
+
a();
|
|
243
262
|
}), r.add(e);
|
|
244
|
-
},
|
|
245
|
-
let t = [...e.querySelectorAll(`:scope > .${c} > [${
|
|
246
|
-
for (let n of t)
|
|
263
|
+
}, d = /* @__PURE__ */ new WeakSet(), f = (e) => {
|
|
264
|
+
let t = [...e.querySelectorAll(`:scope > .${c} > [${u}]`), ...e.querySelectorAll(":scope > table")];
|
|
265
|
+
for (let n of t) d.has(n) || (d.add(n), new MutationObserver(() => o(e)).observe(n, {
|
|
247
266
|
subtree: !0,
|
|
248
267
|
childList: !0,
|
|
249
268
|
characterData: !0
|
|
250
269
|
}));
|
|
251
|
-
},
|
|
252
|
-
|
|
270
|
+
}, p = (e) => {
|
|
271
|
+
C(e, t), f(e);
|
|
253
272
|
};
|
|
254
|
-
for (let e of n())
|
|
255
|
-
document.addEventListener("tablechart:table", (e) => {
|
|
273
|
+
for (let e of n()) p(e);
|
|
274
|
+
a(), document.addEventListener("tablechart:table", (e) => {
|
|
256
275
|
let n = e.target;
|
|
257
|
-
n instanceof HTMLElement && n.matches(t.selector) && n.querySelector(`:scope > .${c}`) &&
|
|
276
|
+
n instanceof HTMLElement && n.matches(t.selector) && n.querySelector(`:scope > .${c}`) && (p(n), a());
|
|
258
277
|
}), t.locale || new MutationObserver(() => {
|
|
259
|
-
for (let e of n())
|
|
278
|
+
for (let e of n()) o(e);
|
|
260
279
|
}).observe(document.documentElement, {
|
|
261
280
|
attributes: !0,
|
|
262
281
|
attributeFilter: ["lang"]
|
|
263
282
|
});
|
|
264
|
-
},
|
|
265
|
-
init:
|
|
266
|
-
fill:
|
|
283
|
+
}, E = {
|
|
284
|
+
init: T,
|
|
285
|
+
fill: C,
|
|
267
286
|
defaults: s
|
|
268
287
|
};
|
|
269
|
-
export {
|
|
288
|
+
export { E as Summary, C as fill, T as init, s as summaryDefaults };
|