@martinomagnifico/tablechart 1.1.2 → 1.1.3
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 +22 -0
- package/dist/tablechart-additional-types.js +1 -1
- package/dist/tablechart-additional-types.mjs +46 -48
- package/dist/tablechart-core.d.mts +2 -2
- package/dist/tablechart-core.mjs +1 -1
- package/dist/tablechart-shared.d.mts +9 -21
- package/dist/tablechart-shared.mjs +751 -721
- 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 +10 -3
package/dist/tablechart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var t=Object.defineProperty,e=(e,n)=>{let a={};for(var o in e)t(a,o,{get:e[o],enumerable:!0});return n||t(a,Symbol.toStringTag,{value:"Module"}),a},n="tablechart",a="tablechart-value",o="tablechart-bar",r="tablechart-rule",s="tablechart-line",c="tablechart-reference",l="tablechart-head",i="tablechart-slice",u="tablechart-name",d="tablechart-legend",h="tablechart-point",f="tablechart-hole",m="tablechart-centre",b="tablechart-break",$="tablechart-sr",p="is-printing",g="tablechart-axis",w="tablechart-tick",y="tablechart-grid",M=1e3,v={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",shape:"straight",legend:!1,axis:!1,grid:!1,names:!0,tooltip:"auto",tooltipparent:null,table:"never",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},x="cubic-bezier(0.3, 0.3, 0.6, 1)",k=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?x:"linear"}),N=(t,e)=>`${t}:${e}`,A=t=>Math.round(100*t)/100,S=(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?A(t):t))}return n},H=(t,e)=>[t,...e.classes].join(" "),C=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},T=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},L=0,O=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++L,c=S("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(S("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const u of e)u.setAttribute("fill","black"),c.appendChild(u);let l=t.querySelector(":scope > defs");if(l||(l=S("defs"),t.prepend(l)),l.appendChild(c),o){for(const t of o)t.setAttribute("mask",`url(#${s})`);return}let i=null;for(const u of Array.from(t.childNodes))u!==l&&(r&&u instanceof Element&&u.matches(r)?(i=null,t.appendChild(u)):(i??(i=t.appendChild(S("g",{mask:`url(#${s})`}))),i.appendChild(u)))},E=0,z={create:()=>null,draw(t,e,n){const{rows:a,y:r,svg:s,breakAt:c}=n;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]]},u=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),d="tablechart-break-"+ ++E,h=S("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(S("rect",{x:-1e3,y:-n.height,width:3e3,height:3*n.height,fill:"white"}));const f=[],m=r(c);for(const w of(t=>Array.from(t.querySelectorAll(`.${o}`)).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=w.sideways?n.breakX:m;if(void 0===t)continue;if(!(w.sideways?w.x<t&&w.x+w.width>t:w.y<m&&w.y+w.height>m))continue;const[e,o]=w.sideways?[i(w,t),i(w,t+n.breakGap)]:[i(w,m-n.breakGap),i(w,m)];h.appendChild(S("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[N("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(S("path",{class:b,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const $=Array.from(s.querySelectorAll(`.${b}`)),p=S("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))$.includes(o)||p.appendChild(o);const g=S("defs");g.appendChild(h),s.prepend(g,p)}},B=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},_=t=>(t.split(/[.,]/)[1]||"").length,U=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),V=(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},F=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=U(s),l=r?.5:.5*10**-_(s.match(/-?[\d.,]+/)?.[0]??""),i=!!Number.isNaN(c)||Math.abs(e-c)<=l+1e-9,u={label:a,computed:e,stated:c,agrees:i};o.checks.push(u),i||console.warn(`[${n}] An annotation reads ${c}${r}, but ${a} is ${Number(e.toFixed(2))}${r}. The chart shows your number.`)},q={create:V,draw(t,e,a){const{rows:o,cx:r,y:c,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:f,after:m}=a,[b,$]=((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)]})(t,o.length),p=o[b],g=o[$];if(!p||!g)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${b+1} to ${$+1}, of ${o.length}).`);const w=7*i,y=4*i,v=r(b),x=r($),k=Math.min(c(p.value),c(g.value))-u-y-.9*d,A=t=>c(t)-u-y,H=`M ${v} ${A(p.value)} L ${v} ${k} L ${x} ${k} L ${x} ${A(g.value)-w}`,C=(A(p.value)-k+Math.abs(x-v)+(A(g.value)-w-k))/i+1;f.appendChild(S("path",{class:s,"data-note":a.note,d:H,style:`--len:${C.toFixed(1)}; ${N("--after",m)}`}));const L=A(g.value);var O;f.appendChild(S("polygon",{class:l,"data-note":a.note,points:`${x},${L} ${x-.45*w},${L-w} ${x+.45*w},${L-w}`,style:N("--after",m)})),e&&(T(e,(v+x)/2,k,M,h),e.style.setProperty("--after",String(m))),F(e,(O=p.value,(g.value-O)/Math.abs(O)*100),`${p.value} to ${g.value}`,a)}},P=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let a=1;for(const l of t)for(const[,,t,e]of l)a=Math.max(a,t,e);const o=new Map,r=([t,e,n,o])=>{const r=[];for(let s=Math.floor(t/a);s<=Math.floor((t+n)/a);s++)for(let t=Math.floor(e/a);t<=Math.floor((e+o)/a);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))o.get(e)?.push(t)??o.set(e,[t])},c=t=>((t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[0]+t[2]<=e[0]+e[2]&&t[1]+t[3]<=e[1]+e[3])(t,n)&&r(t).every(e=>!o.get(e)?.some(e=>{return a=e,(n=t)[0]<a[0]+a[2]&&a[0]<n[0]+n[2]&&n[1]<a[1]+a[3]&&a[1]<n[1]+n[3];var n,a}));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},j=new WeakMap,D=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>j.set(t,n[e]))},I=t=>j.get(t)??{width:t.offsetWidth,height:t.offsetHeight},R=(t,e,n)=>{const a=n.reduce((t,e)=>t+e,0);if("mean"===t)return a?e.reduce((t,e,a)=>t+e*n[a],0)/a:null;if("median"===t){const t=e.map((t,e)=>[t,n[e]]).sort((t,e)=>t[0]-e[0]);let o=0;for(const[e,[n,r]]of t.entries()){if(o+=r,Math.abs(o-a/2)<1e-9&&t[e+1])return(n+t[e+1][0])/2;if(o>a/2)return n}return null}const o=Number.parseFloat(t);return Number.isFinite(o)?o:null},W={create(t,e){if(!t.textContent?.trim())return null;const n=V(t,e);return n.dataset.kind="reference",n},draw(t,e,a){const{rows:o,cx:r,y:s,x:l,height:i,unit:u,svg:d,after:f}=a,m=o.filter(t=>!t.isTotal&&!t.missing),b=t.hasAttribute("data-name"),$=(t.getAttribute(b?"data-name":"data-value")??"").trim();let p,g,w;if(b){const t=m.map(t=>U(t.label));if("beside"===a.categories[0]?.parentElement?.dataset.place||t.some(Number.isNaN))return void console.warn(`[${n}] A reference line among the names needs names that are numbers, under columns or points.`);const e=R($,t,m.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[m[s],m[s+1]??m[s]].map(t=>r(o.indexOf(t))),i=null===e||s<0||void 0===t[s+1]||t[s+1]===t[s]?0:(e-t[s])/(t[s+1]-t[s]);w=e,g=s<0?null:c+i*(l-c),p=!1}else{const e=Boolean(a.frame)&&"y"===t.getAttribute("data-axis"),n=a.frame?a.series.flatMap((t,e)=>t.group?[]:[e])[e?1:0]??0:0;w=R($,m.map(t=>t.cells[n]?.value??t.value),m.map(()=>1)),p=e||!l,g=null===w?null:l&&!e?l(w):s(w)}if(null===g||null===w)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${$}".`);const[y,v,x,k]=a.frame?[a.frame[0],a.frame[1],a.frame[0]+a.frame[2],a.frame[1]+a.frame[3]]:[0,0,o.length>0?r(o.length-1)+r(0):M,l?i:s(0)];if(d.insertBefore(S("line",{class:c,"data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...p?{x1:y,x2:x,y1:g,y2:g}:{x1:g,x2:g,y1:v,y2:k},style:N("--after",f)}),d.querySelector(`:scope > .${h}`)),e){const t=I(e).width*u,n=I(e).height*u,o=4*u,r=p?[[x-t,g-n/2,t,n],[x-t,g-n-o,t,n],[x-t,g+o,t,n]]:[v,v+n,v+2*n].flatMap(e=>[[g-t/2,e,t,n],[g+o,e,t,n],[g-o-t,e,t,n]]),[s]=P([r],a.taken,[0,0,M,i]),c=r[s??0];a.taken.push(c),T(e,c[0]+t/2,c[1]+n/2,M,i),e.style.setProperty("--after",String(f)),"mean"!==$&&"median"!==$||F(e,w,`the ${$}`,a,"")}}},G={create:V,draw(t,e,n){const{rows:a,cx:o,y:r,unit:c,labelHeight:i,height:u,svg:d,values:h,after:f}=n,m=a[0],b=a[a.length-1];if(!m||!b)return;const $=i+18*c,p=10*c,g=10*c;let w=o(0),y=r(m.value)-$,v=o(a.length-1),x=r(b.value)-$,k=0;a.forEach((t,e)=>{const n=v===w?0:(o(e)-w)/(v-w),a=y+n*(x-y)-(r(t.value)-$);a>k&&(k=a)}),y-=k,x-=k;const A=v-w,H=x-y,C=Math.hypot(A,H)||1,L=A/C,O=H/C;w-=L*p,y-=O*p,v+=L*p,x+=O*p;const E=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(v-w)*E,n=y+(x-y)*E,s=I(e).width*c/2,l=n+I(e).height*c/2+8*c;let u=0;a.forEach((e,n)=>{const a=(h[n]?I(h[n]).width:0)*c/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*c-i;u=Math.max(u,l-d)}),y-=u,x-=u}const z=v-L*g,B=x-O*g,_=Math.hypot(z-w,B-y)/c+1;d.appendChild(S("line",{class:s,"data-note":n.note,x1:w,y1:y,x2:z,y2:B,style:`--len:${_.toFixed(1)}; ${N("--after",f)}`}));const U=-O,V=L,q=.42*g;d.appendChild(S("polygon",{class:l,"data-note":n.note,points:[`${v},${x}`,`${z+U*q},${B+V*q}`,`${z-U*q},${B-V*q}`].join(" "),style:N("--after",f)})),e&&(T(e,w+(v-w)*E,y+(x-y)*E,M,u),e.style.setProperty("--after",String(f)));const P=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(P)&&P>0&&F(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(m.value,b.value,P),`${m.value} to ${b.value} over ${P} years`,n)}},K=(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}},X=(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}); ${N("--i",e.slot)}`}},Y=(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}})},Z=(t,e,n=!1)=>{const a=Y(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},J=(t,e)=>{const{top:n,bottom:a}=Z(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})`)},tt=(t,e,n,a={},r="")=>{const s={class:H(o,e),"data-kind":"bar","data-row":n+1,...a},c=N("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=S("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(o,r)=>{const s=void 0!==a["data-grow"]?{"data-grow":a["data-grow"]}:{};l.appendChild(S("rect",{...s,...r,class:H("tablechart-piece",e),"data-row":n+1,...X(t,e,o)}))}},et=(t,e,n)=>t.some(t=>I(t).width*n>e-6*n),nt=(t,e,n)=>e>=I(t).height*n*1.6,at=(t,e,n)=>e>=I(t).width*n*1.5,ot=(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},rt={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:n,unit:a,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(B(l.map(t=>I(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/M*100).toFixed(2)}%`);const m=M-4*a,b=t.stacked?Math.max(B(t.rows.map(e=>Z(e,t.series.length).top)),0)||1:Math.max(B(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(B(t.rows.map(e=>-Z(e,t.series.length).bottom)),0):Math.max(B(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),p=Math.max(b,t.domain?.[1]??0),g=Math.max($,-(t.domain?.[0]??0)),w=Math.max(p,t.squeeze?.hi??0)+g,y=(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),w,n,t.squeeze,t.breakGap),v=n/e.length,x=t=>(t+.5)*v,k=Math.min(v*i.barfill,u),A=K(v,t.series.length,u),C=c[0]??t.totals[0],L=C?I(C).height*a*.56:0,O=Math.max(((d&&!t.stacked?A.size:k)-L)/2,5*a),E=t=>I(t).width*a,z=t=>t.length?B(t.map(E))+O+4*a:0,_=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,U=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:_(e,n)}))),V=e=>{const n=Z(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let F=t.stacked?z(t.totals.filter((t,e)=>!V(e))):d?z(U.filter(t=>t.value>=0).map(t=>t.label)):0,q=t.stacked?z(t.totals.filter((t,e)=>V(e))):d?z(U.filter(t=>t.value<0).map(t=>t.label)):0;if(!d&&!t.stacked)for(let o=0;o<3;o++){const t=m-f-F-q,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!at(n,y(e.value,t),a)),o=z(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),r=z(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(o<=F&&r<=q)break;F=Math.max(F,o),q=Math.max(q,r)}const P=m-f-F-q,j=f+q+y(g,P),D=t=>t<0?j-y(t,P):j+y(t,P);if(t.squeeze&&(t.breakX=D(t.squeeze.gap)),t.x=D,t.stacked)return t.rows.forEach((e,o)=>{const r=Z(e,t.series.length),s=tt(t,e,o,{"data-grow":"right"},r.bottom<0?j-D(r.bottom)+"px center":""),c=x(o)-k/2;Y(e,t.series.length).forEach(({from:e,to:r,cell:l},i)=>{const u=t.seriesValues[i][o];if(u.dataset.place="none",l.missing||r===e)return;const d=Math.min(D(e),D(r)),h=Math.max(D(e),D(r));s(i,{x:d,y:c,width:Math.max(h-d,1),height:k,...r<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!at(u,h-d,a)||I(u).height*a>k),Q(u,t,i),T(u,(d+h)/2,x(o),M,n)});const i=t.totals[o];i&&(i.dataset.place=V(o)?"before":"after",T(i,V(o)?D(r.bottom)-O:D(r.top)+O,x(o),M,n));const u=l[o];u&&T(u,f-8*a,x(o),M,n)}),void s.appendChild(S("line",{class:r,x1:j,x2:j,y1:0,y2:n}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=ot(t.plot,e,t=>({size:I(t).height*a,room:A.size+.5*A.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((a,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][r];if(i.missing)return void(u.dataset.place="none");const d=D(i.value),h=i.value<0,f=x(r)+A.offset(l),m=Math.max(Math.abs(d-j),1);0!==i.value&&s.appendChild(S("rect",{class:H(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?j-m:j,y:f,width:m,height:A.size,...X(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),T(u,h?d-O:d+O,f+A.size/2,M,n)});const i=l[r];i&&T(i,f-8*a,x(r),M,n)}),void s.appendChild(S("line",{class:r,x1:j,x2:j,y1:0,y2:n}))}const R=e.map((t,e)=>at(c[e],Math.abs(D(t.value)-j),a));e.forEach((e,r)=>{const i=D(e.value),u=x(r),d=e.value<0,h=Math.abs(i-j),m=Math.max(h,1);0!==e.value&&s.appendChild(S("rect",{class:H(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?j-m:j,y:u-k/2,width:m,height:k,style:N("--i",e.slot)}));const b=c[r],$=Math.max(Math.min(O,h-E(b)-6*a),6*a),p=d?1:-1;b.dataset.place=R[r]?"inside":d?"before":"after",b.dataset.kind=e.kind,T(b,R[r]?"center"===t.insideAlign?(j+i)/2:"start"===t.insideAlign?j-p*($+E(b)/2):i+p*($+E(b)/2):i-p*O,u,M,n);const g=l[r];g&&T(g,f-8*a,u,M,n)}),s.appendChild(S("line",{class:r,x1:j,x2:j,y1:0,y2:n}))}},st={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:n,y:a,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,f=a(0);if(t.stacked)return t.rows.forEach((e,o)=>{const r=Z(e,t.series.length),i=tt(t,e,o,{},r.bottom<0?`center ${f-a(r.top)}px`:""),u=n(o)-s/2;Y(e,t.series.length).forEach(({from:e,to:r,cell:d},h)=>{const f=t.seriesValues[h][o];if(f.dataset.place="none",d.missing||r===e)return;const m=Math.min(a(r),a(e)),b=Math.max(a(r),a(e));i(h,{x:u,y:m,width:s,height:Math.max(b-m,1),...r<e&&{"data-grow":"down"}}),f.dataset.place="inside",f.toggleAttribute("data-left-out",!nt(f,b-m,l)||I(f).width*l>s-4*l),Q(f,t,h),T(f,n(o),(m+b)/2,M,c)});const d=t.totals[o];if(d){const t=0===r.top&&r.bottom<0;d.dataset.place=t?"below":"outside",T(d,n(o),t?a(r.bottom)+4*l:a(r.top)-4*l,M,c)}}),void i.appendChild(S("line",{class:r,x1:0,x2:M,y1:f,y2:f}));if(t.series.length>1){const e=n(1)-n(0)||2*n(0),s=K(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=ot(t.plot,u,t=>({size:I(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((u,h)=>{const m=e.cells[h]??e.cells[0],b=t.seriesValues[h][r],$=n(r)+s.offset(h);if(m.missing)return void(b.dataset.place="none");const p=a(m.value),g=m.value<0,w=Math.max(Math.abs(f-p),1);0!==m.value&&i.appendChild(S("rect",{class:H(o,e),"data-kind":"bar","data-row":r+1,...g&&{"data-grow":"down"},x:$,y:g?f:f-w,width:s.size,height:w,...X(t,e,h)})),b.dataset.place=g?"below":"outside",b.toggleAttribute("data-left-out",!d),T(b,$+s.size/2,g?p+4*l:p-4*l,M,c)})}),void i.appendChild(S("line",{class:r,x1:0,x2:M,y1:f,y2:f}))}const m=et(u,s,l),b=e.map((t,e)=>"inside"===d&&!m&&!t.missing&&nt(u[e],Math.abs(f-a(t.value)),l)),$=u[0]?I(u[0]).height*l*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())b[o]&&(p=Math.min(p,(s-I(r).width*l)/2));e.forEach((t,e)=>{const r=a(t.value),d=t.value<0;if(t.missing)return T(u[e],n(e),f-4*l,M,c),void(u[e].dataset.place="outside");const m=Math.max(Math.abs(f-r),1);0!==t.value&&i.appendChild(S("rect",{class:H(o,t),"data-kind":t.kind,"data-row":e+1,...d&&{"data-grow":"down"},x:n(e)-s/2,y:d?f:f-m,width:s,height:m,style:N("--i",t.slot)}));const g=d?-1:1,w=Math.min(p,(Math.abs(f-r)-$)/2),y="center"===h?(r+f)/2:"start"===h?f-g*(w+$/2):r+g*(w+$/2),v=d?r+4*l:r-4*l;T(u[e],n(e),b[e]?y:v,M,c),u[e].dataset.place=b[e]?"inside":d?"below":"outside"}),i.appendChild(S("line",{class:r,x1:0,x2:M,y1:f,y2:f}))}},ct=0,lt={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:s,centre:c}){const l=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,f=Math.max(Math.min(M,e)/2-h,10),m=f*s.ringfill,b=f-m/2,$=2*Math.PI*b,p=[];let g=0,w=0,y=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,v=k(y,h),x=`--share:${h.toFixed(4)}; --start:${v.start.toFixed(4)}; --span:${v.span.toFixed(4)};`,A=h*$,C=g/$*2*Math.PI-Math.PI/2;p.push(C),o.appendChild(S("circle",{class:H(i,t),"data-slice":w+1,"data-row":s+1,cx:l,cy:u,r:b,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${A.toFixed(1)} ${($-A).toFixed(1)}`,"stroke-dashoffset":(-g).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${A.toFixed(1)}; --circ:${$.toFixed(1)}; ${x} --ease:${v.easing}; ${N("--i",t.slot)}`}));const L=C+A/$*Math.PI,O=Math.cos(L),E=Math.sin(L);o.appendChild(S("line",{class:"tablechart-leader",x1:l+O*(f+2*n),y1:u+E*(f+2*n),x2:l+O*(f+7*n),y2:u+E*(f+7*n),"data-row":s+1,style:`${x} ${N("--i",t.slot)}`})),c.style.setProperty("--start",v.start.toFixed(4)),c.style.setProperty("--span",v.span.toFixed(4));const z=f+9*n,B=I(c).width*n/2;T(c,l+O*(z+Math.abs(O)*B),u+E*(z+Math.abs(E)*a*.7),M,e),c.dataset.place="around",g+=A,y+=h,w+=1}),p.length>1){const t=b-m/2-1,n=b+m/2+1,a="tablechart-slices-"+ ++ct,r=S("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(S("rect",{x:0,y:0,width:M,height:e,fill:"white"}));for(const e of p)r.appendChild(S("line",{class:"tablechart-divide",x1:l+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:l+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const s=S("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${i}`)))s.appendChild(e);const c=S("defs");c.appendChild(r),o.prepend(c,s)}c&&T(c,l,u,M,e)}},it=["circle","square","diamond"],ut=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=it.find(t=>n.includes(t));return{shape:a??it[Math.floor(e/2)%it.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},dt=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return S("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return S("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return S("polygon",{points:`${e},${n-t} ${e+.87*t},${n+t/2} ${e-.87*t},${n+t/2}`,...o})}return S("circle",{cx:e,cy:n,r:a,...o})},ht=t=>Number(t.toFixed(2));function ft(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 mt,bt,$t=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),pt=t=>({segments:$t,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:a,seriesValues:o,names:s,cx:c,y:l,height:i,unit:u,labelHeight:d,svg:m,stacked:b}=e,$="step"===e.shape,p="smooth"===e.shape,g=a.length>1,w=a.some(t=>t.focus),y=n.length-1,v=l(0),x=n.length>1?c(1)-c(0):2*c(0);m.style.setProperty("--_base",`${ht(v)}px`);const k=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],N=(t,e)=>!k(t,e)||!!k(t,e)?.missing,A=n.map(t=>b?Y(t,a.length,!0):null),H=(t,e)=>A[e]?.[t].to??k(t,e)?.value??0,C=(t,e)=>A[e]?.[t].from??0,L=(t,e)=>[c(e),l(H(t,e))],E=a.map((t,e)=>{if(!g)return{attrs:{},ink:""};const n=w&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),z=Math.min(y,6);e.plot.style.setProperty("--count",String(z+1));const B=y>0?z/($?n.length:y):1,_=t=>t*B,U=t=>`--i:${ht(_(t))}`,V=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{N(t,o)||(a<0&&(a=o),(o===y||N(t,o+1))&&(($||o>a)&&e.push([a,o]),a=-1))}),e},F=(t,e)=>`--i:${ht(_(t)+1)}; --d:${ht(_($?e+1:e)-_(t))}`,q=(t,e)=>({"data-from":t+1,"data-to":e+1,...$&&{"data-flat":""}}),j=p?a.map((t,e)=>ft(n.length,t=>N(e,t),t=>L(e,t))):[],D=p&&t?a.map((t,e)=>ft(n.length,t=>N(e,t),t=>[c(t),l(C(e,t))])):[],R=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{$?(a.push(`H${ht(o+n*x/2)}`),s<t.length-1&&a.push(`V${ht(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])=>`${ht(t)},${ht(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${ht(o)},${ht(r)}`)}),a},W=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),l(o(t,e+a))]),G=(t,e,n,a)=>p?t[e].slice(n,a+1):null,K=t=>c(t)-($?x/2:0),X=t=>c(t)+($?x/2:0);t&&a.forEach((t,e)=>(t=>{const e=S("g",{class:"tablechart-area",...E[t].attrs,...b&&{"data-stacked":""},style:E[t].ink}),n=V(t),a=S("g",{class:"tablechart-area-fill",style:`--rows:${ht(z+1)}; ${n.length?F(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=W(t,o,r,H),n=W(t,o,r,C),s=G(D,t,o,r)?.reverse()??null,c=[`M${ht(K(o))},${ht(n[0][1])}`,`L${ht(K(o))},${ht(e[0][1])}`,...R(e,G(j,t,o,r),1),`L${ht(X(r))},${ht(n[n.length-1][1])}`,...R(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(S("path",{d:c,...q(o,r),style:F(o,r)}))}m.appendChild(e)})(e)),a.forEach((t,e)=>(t=>{const e=a[t];for(const[n,a]of V(t)){const o=W(t,n,a,H),r=[`M${ht(K(n))},${ht(o[0][1])}`,...R(o,G(j,t,n,a),1)].join(" ");m.appendChild(S("path",{class:"tablechart-series",...E[t].attrs,d:r,...e.line&&{"data-line":e.line},...q(n,a),style:`${E[t].ink}${F(n,a)}`}))}})(e)),$||(()=>{const t=a.map((t,e)=>g?ut(a,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=L(e,n);return dt(t[e].shape,o,r,4*u,{...a,style:`${a.style??""}${s=r,`--rise:${ht(v-s)}px; `}${U(n)}`});var s},o=t=>n.map((t,e)=>e).filter(e=>!N(t,e)),r=a.flatMap((n,a)=>t[a].open?o(a).map(t=>e(a,t,{class:f,"data-row":t+1,...g&&{"data-series":a+1}})):[]);O(m,r,M,i),a.forEach((n,a)=>{for(const r of o(a))m.appendChild(e(a,r,{class:h,...E[a].attrs,"data-marker":t[a].shape,...t[a].open&&{"data-open":""},"data-row":r+1,style:E[a].ink}))})})();const Z=(t,e)=>{let n=e;for(;n<y&&!N(t,n+1)&&k(t,n+1)?.value===k(t,e)?.value;)n++;return n},J=(e,n)=>{const o=k(e,n);if(!o||o.missing)return"none";if($&&n>0&&!N(e,n-1)&&k(e,n-1)?.value===o.value)return"none";if(w&&!a[e].focus)return"none";if(b)return"middle";const r=o.value<0?"below":"above";if(!g||w||a.length>2)return r;const s=k(1-e,n);return!s||s.missing?r:o.value>s.value||o.value===s.value&&0===e||t&&o.value>=0&&L(e,n)[1]+7*u+d>v?"above":"below"},Q=g&&!w&&a.length>2&&!b&&!$,tt=new Map;if(Q){const t=n.flatMap((t,e)=>a.map((t,n)=>({s:n,i:e,value:k(n,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==J(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],r=t.map(({s:t,i:n,value:a})=>{const r=I(o[t][n]).width*u,[s,c]=L(t,n);return e(a).map(t=>[s-r/2,"above"===t?c-7*u-d:c+7*u,r,d])}),s=a.flatMap((t,e)=>n.flatMap((t,n)=>{if(N(e,n))return[];const[a,o]=L(e,n);return[[a-4*u,o-4*u,8*u,8*u]]})),l=P(r,s,[0,0,c(y)+c(0),i]);t.forEach(({s:t,i:n,value:a},r)=>tt.set(o[t][n],null===l[r]?null:e(a)[l[r]]))}o.forEach((t,e)=>{t.forEach((t,n)=>{t.style.setProperty("--i",String(ht($?(_(n)+_(n+1))/2:_(n))));const a=tt.get(t)??J(e,n);if(t.dataset.place="above"===a?"outside":a,t.toggleAttribute("data-left-out","none"!==a&&((t,e)=>Q?null===tt.get(o[t][e]):!(!b&&!$)&&(I(o[t][e]).width*u>($?Z(t,e)-e+1:1)*x-4*u||!!(b&&t>0&&H(t,e)<C(t,e))||b&&Math.abs(l(C(t,e))-l(H(t,e)))<1.2*d))(e,n)),$&&"none"!==a?t.dataset.rowEnd=String(Z(e,n)+1):delete t.dataset.rowEnd,"none"===a)return;const r=I(t).width*u/2+4*u;let s=c(n);$?s=(c(n)+c(Z(e,n)))/2:"middle"===a&&0===n?s+=r:"middle"===a&&n===y&&(s-=r);const h=l(H(e,n)),f={middle:(l(C(e,n))-h)/2,above:-7*u,below:7*u};T(t,s,h+f[a],M,i)})});const et=s.map((t,e)=>{let n=y;for(;n>0&&N(e,n);)n--;const[a,o]=L(e,n);return{name:t,x:($?a+x/2:a)+10*u,y:b?(o+l(C(e,n)))/2:o}}),nt=(s[0]?I(s[0]).height:0)*u;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))(et,nt))T(t.name,t.x,t.y,M,i);const at=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),ot=t||b||2!==a.length||w||at?v:i-2*u;m.appendChild(S("line",{class:r,x1:0,x2:c(y)+c(0),y1:ot,y2:ot}))}}),gt=pt(!1),wt=pt(!0),yt=new Set,Mt={segments:t=>{let e=0,a=!1;return t.map(t=>{if(t.isTotal)return a&&((t,e)=>{if(Math.abs(t-e)<=Math.abs(e)/100)return;const a=`[${n}] A total reads ${t}, but the steps before it add up to ${Number(e.toFixed(6))}. The chart shows your number.`;yt.has(a)||(yt.add(a),console.warn(a))})(t.value,e),a=!1,e=t.value,{...t,from:0,to:t.value,kind:"total"};const o=e;return e+=t.value,a=!0,{...t,from:o,to:e,kind:t.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:n,barWidth:a,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=n(0),f=et(i,a,c),m=d??"center",b=t.map((e,a)=>{const o=n(Math.max(e.from,e.to)),r=Math.abs(n(e.from)-n(e.to)),s=null!==u&&Math.min(e.from,e.to)<u&&Math.max(e.from,e.to)>u,l="total"===e.kind&&a>0&&a===t.length-1;return{top:o,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!f&&nt(i[a],r,c)}}),$=i[0]?I(i[0]).height*c*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of b.entries())r.inside&&(p=Math.min(p,(a-I(i[o]).width*c)/2));const g=t.length,w=(t,e,n=!1)=>`--start:${(t/g).toFixed(4)}; --span:${(e/g).toFixed(4)}; --ease:${n?x:"linear"};`;t.forEach((o,r)=>{const s=t[r+1];if(!s)return;const c=n(o.to),i=e(r)+a/2,u=e(r+1)-a/2;l.appendChild(S("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${N("--i",s.slot)}; ${w(r+1,1/3)}`}))}),t.forEach((n,r)=>{const{top:u,length:d,down:h,inside:f}=b[r];l.appendChild(S("rect",{class:H(o,n),"data-kind":n.kind,"data-row":r+1,"data-grow":h?"down":"up",x:e(r)-a/2,y:u,width:a,height:Math.max(d,1),style:`${N("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const y=i[r];y.style.setProperty("--start",(r/g).toFixed(4)),y.style.setProperty("--span",(1/g).toFixed(4));const v=Math.min(p,(d-$)/2),x="center"===m?u+d/2:"end"===m!==h?u+v+$/2:u+d-v-$/2;y.dataset.place=f?"inside":"outside",y.dataset.kind=n.kind;const k=f?x:"down"===n.kind?u+d+I(y).height*c+3*c:u-3*c;T(y,e(r),k,M,s)}),l.appendChild(S("line",{class:r,x1:0,x2:M,y1:h,y2:h}))}},vt={enabled:!1,log(...t){vt.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!vt.enabled)return a();const o=performance.now(),r=a(),s=performance.now()-o,c=e.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${n}] ${t} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,e):vt.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},xt=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}},kt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),Nt=t=>Number(t.toPrecision(12)),At=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return Nt((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},St=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(Nt(o*n));return a},Ht=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Nt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},Ct=t=>{const e=(t??"").trim().split(/\s+/).map(Number.parseFloat);return e.length>1&&e.every(Number.isFinite)?e.sort((t,e)=>t-e):null},Tt=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=Ht(n,t.step),a=St(t.min,t.max,n);return{...t,step:n,ticks:a}},Lt=["axis-break","trend","bracket"],Ot=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))}},Et=(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)),Ot(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}}))},zt="tablechart-tooltip",Bt=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],_t=null,Ut=null,Vt=null,Ft=0,qt=()=>{clearTimeout(Ft),_t&&Ut&&(_t.hidden=!0,Ut=null,Vt=null)},Pt=!1,jt=!0,Dt=NaN,It=NaN,Rt=!1,Wt=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Gt=()=>{clearTimeout(Ft),Ft=window.setTimeout(qt,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},Yt=(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},Zt=(t,e,n)=>{if(clearTimeout(Ft),Ut===t&&Vt===e)return;const a=(t.type.tooltip??Yt)(t,e,n);if(!a.length)return qt();Ut&&Ut!==t&&qt(),_t??(_t=(()=>{const t=document.createElement("div");return t.className=zt,t.setAttribute("aria-hidden","true"),t.hidden=!0,mt=document.createElement("div"),(bt=document.createElement("div")).className=`${zt}-arrow`,t.append(mt,bt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(Ft)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Gt()),document.addEventListener("pointerdown",e=>{const n=e.target;!Ut||Ut.plot.contains(n)||t.contains(n)||qt()}),window.addEventListener("resize",qt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${zt}-line`,n){const t=document.createElement("span");t.className=`${zt}-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=`${zt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${zt}-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,c=a.every(t=>t.name&&!t.value);mt.replaceChildren(...c?[]:[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 l=getComputedStyle(t.figure);for(const f of Bt){const t=l.getPropertyValue(f).trim();t?_t.style.setProperty(f,t):_t.style.removeProperty(f)}_t.style.setProperty("--_color",l.color),_t.style.colorScheme=l.colorScheme,_t.style.fontFamily=l.fontFamily;const i=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);_t.parentElement!==i&&i.append(_t),Ut=t,Vt=e,_t.hidden=!1,_t.style.left="0px",_t.style.top="0px";const u=_t.getBoundingClientRect(),d={x:u.left,y:u.top,scale:Wt(_t,u.width)},h=Wt(t.plot,t.plot.getBoundingClientRect().width);_t.style.fontSize=Number.parseFloat(l.fontSize)*h/d.scale+"px",((t,e,n,a={x:0,y:0,scale:1},o=2,r=8,s=12)=>{const c=t.getBoundingClientRect(),l=c.width,i=c.height,u=Number.parseFloat(getComputedStyle(t).borderLeftWidth)||0,d=e.getBoundingClientRect().height/2+(o-u)*a.scale,h=s*a.scale,{clientWidth:f,clientHeight:m}=document.documentElement,b=n.top-r,$=m-n.bottom-r,p=i+d<=b||!(i+d<=$)&&b>=$,g=p?n.top-d-i:n.bottom+d,w=n.left+n.width/2,y=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(y-a.x)/a.scale+"px",t.style.top=(Math.max(r,Math.min(g,m-i-r))-a.y)/a.scale+"px",t.dataset.side=p?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/a.scale-u+"px"})(_t,bt,((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),d)},Jt=t=>{Ut===t&&qt()},Qt={area:wt,bar:rt,column:st,donut:lt,line:gt,waterfall:Mt},te={"axis-break":z,trend:G,bracket:q,reference:W},ee=Object.keys(te),ne=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},ae=["straight","step","smooth"],oe=(t,e,n,a,o)=>{const r=e===a,[s,c,l]=r?[Math.min(t,n),Math.max(t,n),e]:[Math.min(e,a),Math.max(e,a),t],i=o.filter(([t,e,n,a])=>r?e<=l&&l<=e+a:t<=l&&l<=t+n).map(([t,e,n,a])=>r?[t,t+n]:[e,e+a]).sort((t,e)=>t[0]-e[0]),u=[];let d=s;for(const[h,f]of i)h>d&&u.push([d,Math.min(h,c)]),d=Math.max(d,f);return d<c&&u.push([d,c]),u.map(([t,e])=>r?`M${A(t)},${A(l)}H${A(e)}`:`M${A(l)},${A(t)}V${A(e)}`).join("")},re=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=S("path",{d:oe(n,a,o,r,e)});for(const{name:c,value:l}of Array.from(t.attributes))/^[xy][12]$/.test(c)||s.setAttribute(c,l);t.replaceWith(s)},se=(t,[e,n,a,o])=>t.map(([t,r,s,c])=>r===c?n<=r&&r<=n+o&&Math.max(t,e)<Math.min(s,e+a)?`M${A(Math.max(t,e))},${A(r)}H${A(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${A(t)},${A(Math.max(r,n))}V${A(Math.min(c,n+o))}`:"").join(""),ce=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},le=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),ie=(t,e)=>{const n=t.dataset.chartShape;return n&&ae.includes(n)?n:ae.includes(e.shape)?e.shape:"straight"},ue=0,de=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=Qt[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(Qt).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=((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(xt);return o.length||o.push(xt(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}}))(t,e.langattribute);if(!c.length)return console.warn(t.querySelector("table")?`[${n}] A chart has no rows in its table, so there is nothing to draw.`:`[${n}] A chart has no table, so there is nothing to draw.`,t),t.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(ne(e)))continue;const t=document.createElement("span");t.className=$,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-"+ ++ue),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)})(t);let l=((t,e,n="data-i18n")=>{const a=kt(t),o=Math.max(1,B(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),group:!!o?.hasAttribute("data-group")};var r})})(t,c,e.langattribute);l.length>1&&!s.series&&!s.columns&&(console.warn(`[${n}] A ${r} chart uses only the first of its ${l.length} value columns.`),l=l.slice(0,1));const i=l.length>1;i&&t.style.setProperty("--_series-count",String(l.length));const h=t.hasAttribute("data-chart-stack");h&&!s.stackable&&console.warn(`[${n}] A ${r} chart cannot be stacked.`);const f=h&&!!s.stackable&&i,b=document.createElement("div");b.className="tablechart-plot",b.setAttribute("aria-hidden","true");const p=S("svg",{role:"presentation",focusable:"false"});b.appendChild(p),t.appendChild(b);const y=s.centre?c.filter(t=>!t.isTotal):c,M=Math.max(0,B(y.flatMap(t=>t.cells.slice(0,l.length).map(t=>_(t.number))))),v=l.map((t,e)=>Math.max(0,B(c.map(t=>_(t.cells[e]?.number??""))))),x=document.createElement("div");x.className="tablechart-values",b.appendChild(x);const k=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=C(a,x);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),i&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(v[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),r})),N=k[0],A=f&&s.totals?c.map((t,e)=>{const n=C(a,x);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(J(t,l.length));const o=t.cells[0];return o.prefix&&(n.dataset.prefix=o.prefix),o.suffix&&(n.dataset.suffix=o.suffix),n.style.setProperty("--i",String(t.slot)),n}):[],H=c[c.length-1],T=l.some(t=>t.focus),L=t.getAttribute("data-chart-legend"),O=i&&!s.columns&&(null===L?e.legend||void 0!==s.legend:"false"!==L)?document.createElement("div"):null;O&&(O.className=d,O.setAttribute("aria-hidden","true"),O.inert=!0);const E=i&&!s.columns?l.map((n,a)=>{const o=C(u,O??b);O&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==ie(t,e)){const t=ut(l,a);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return n.line&&!r&&(o.dataset.line=n.line),n.key&&e.langattribute&&o.setAttribute(e.langattribute,n.key),o.dataset.series=String(a+1),o.style.setProperty("--n",String(a)),o.style.setProperty("--palette",`var(--tablechart-color-${a+1})`),o.style.setProperty("--m",T&&!n.focus?"1":"0"),o.style.setProperty("--i",String(H.slot)),o}):[],z=s.centre?C(m,b):null;if(z){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);z.dataset.value=String(e),t&&(z.dataset.decimals=String(_(t.number)))}const U=z&&!c.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})(t,z,e):null,V="beside"===s.categories,F=document.createElement("div");F.className="tablechart-categories",F.setAttribute("aria-hidden","true"),F.inert=!0,V?F.dataset.place="beside":s.centre&&(F.dataset.place="key"),F.style.setProperty("--_columns",String(c.length));let q=0;for(const[n,a]of c.entries()){const t=document.createElement("span");t.classList.add(...a.classes),t.textContent=a.label,a.key&&e.langattribute&&t.setAttribute(e.langattribute,a.key),s.centre&&(t.dataset.kind=a.isTotal?"total":"slice",a.isTotal||(t.dataset.slice=String(q+1),t.style.setProperty("--n",String(q)),t.style.setProperty("--palette",`var(--tablechart-color-${q+1})`),q+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),F.appendChild(t)}(V?b:t).appendChild(F),O&&t.appendChild(O);const P=l.filter(t=>!t.group),j=!s.axes&&!s.centre&&ce(t,"data-chart-axis",e.axis),D=s.axes?{titles:P.slice(0,2).map((t,n)=>{const a=C(`${g}-title`,b);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:C(`${w}s`,b),numbers:!0}:j||!s.centre&&ce(t,"data-chart-grid",e.grid)?{titles:[],ticks:C(`${w}s`,b),numbers:j}:null;s.text?.({figure:t,plot:b,rows:c,series:l,config:e});const I=le(t,e)&&!s.axes?(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=>Lt.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"),m=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]++}}),b=Math.max(-1,...m.map(t=>t.step??-1));if(b>=0)for(const[w,y]of n.entries())f(y)&&(m[w]={step:b,slot:i[b]++});const $=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),p=s.map(t=>t.map(()=>({step:null,slot:0}))),g=Math.max(0,...s.map(t=>t.length));for(let w=0;w<g;w++)for(const[t,e]of s.entries()){const n=e[w];if(!n||!r(n))continue;const a=u(n.getAttribute("data-fragment-index"));p[t][w]={step:a,slot:i[a]++}}return{rows:m,series:$,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",m.length-1)]:[0,m.length-1];let o=null;for(let r=Math.min(n,a);r<=Math.max(n,a);r++)for(const t of[m[r]?.step??null,...(p[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=$[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?m.length:m.filter(t=>t.step===o).length;return{step:o,after:c}}),count:c.length,indexes:c}})(t):null;s.axes&&t.querySelector("[data-fragment]")&&vt.log(`A ${r} chart has no steps, so it is shown whole.`,t),I&&t.setAttribute("data-steps","");const R=t.getAttribute("data-chart-keys"),W=I&&e.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=S("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(S("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=$,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:e.previouslabel,next:e.nextlabel,hint:e.stephint},{previous:R&&`${R}-previous`,next:R&&`${R}-next`,hint:R&&`${R}-step`},e.langattribute):null;W&&t.appendChild(W);const G=t.getAttribute("data-chart-table"),K=G&&fe.includes(G)?G:e.table;if("never"===K)t.removeAttribute("data-table");else{t.setAttribute("data-table",K);const e=t.querySelector(":scope > table");e&&t.append(e)}const X=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),a=te[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(te).join(", ")}.`),null;const o=Number.parseInt(t.getAttribute("data-series")??"1",10),r=o>=1&&o<=l.length?o-1:0;return o!==r+1&&console.warn(`[${n}] An annotation reads line ${o}, which is not there; it reads line 1.`),{spec:t,type:a,badge:a.create(t,b),series:r,after:c.length}}).filter(t=>null!==t);le(t,e)&&t.setAttribute("data-animate",me(t,r,e,Boolean(I)));const Y={figure:t,plot:b,svg:p,rows:c,decimals:M,type:s,values:N,series:l,seriesValues:k,names:O?[]:E,categories:Array.from(F.children),centre:z,axes:D,stacked:f,totals:A,totalCell:U,rowAt:null,rowBox:null,annotations:X,checks:[],plan:I,step:0,controls:W},Z=()=>Me(t,p);p.addEventListener("transitionend",Z),p.addEventListener("transitioncancel",Z),W?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&Et(Y,Y.step+("next"===e?1:-1))}),Et(Y,0,!0);const Q=t.getAttribute("data-chart-tooltip"),tt="false"!==Q&&("auto"===Q?"auto":null!==Q||e.tooltip);return tt&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(Rt)return;Rt=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(jt=t.screenX!==Dt||t.screenY!==It,Dt=t.screenX,It=t.screenY,jt&&(Pt=!1))},{capture:!0,passive:!0});const t=()=>{Pt=!0,qt()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!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)Pt=!1;else if("mouse"===o.pointerType&&(!jt||Pt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return Ut===t?qt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Wt(a,n.width);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 Ut===t?qt():void 0;Zt(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)||Pt||Zt(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,Ut===t&&Gt())})})(Y,e,"auto"===tt),ge(Y,e),Y},he={grow:"grow",sweep:"sweep"},fe=["never","auto","print","always"],me=(t,e,n,a)=>{const o="line"===e||"area"===e,r=he[t.getAttribute("data-chart-animate")??""]??he[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},be=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},$e=(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*M:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},pe=(t,e)=>$e(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,ge=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const a of t.centre?[...n,t.centre]:n)void 0!==a.dataset.missing?a.textContent=a.dataset.missing:we(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},we=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=((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("")]})(Number.parseFloat(t.dataset.value||"0"),e,n);if(t.textContent=a+(a?r:"")+s+o,r&&!a){const e=document.createElement("span");e.className="tablechart-minus",e.textContent=r,t.prepend(e)}},ye=(t,e)=>{e||t.figure.hasAttribute("data-steps")||ve(t.svg),t.figure.classList.toggle("is-shown",e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>Me(t.figure,t.svg)))},Me=(t,e)=>{t.classList.contains("is-shown")&&!e.getAnimations({subtree:!0}).length&&xe(e)},ve=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},xe=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},ke=t=>"id"===t||"style"===t||t.startsWith("data-chart"),Ne=/^\s*(?:Table)?:\s+/,Ae=t=>"P"===t?.tagName&&Ne.test(t.textContent??""),Se=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,He=t=>{const e=Te(t);return"P"===e?.tagName?e:t},Ce=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},Te=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},Le="strong, b, span.total",Oe="data-chart-made",Ee=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,ze=new Set,Be=null,_e=["column","bar"],Ue=t=>{const e=t.getAttribute("data-chart")||"column";if(!_e.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return _e.includes(n)?n:e},Ve=!1,Fe=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=Ae(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||ke(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?Ae(r)?r:Ae(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=He(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Se.exec(e.textContent??"");if(!n||!ee.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=He(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(Ne,""),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),vt?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(Oe)));return(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!Ve&&e&&(Ve=!0,console.warn(`[${n}] A chart is a <${e.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`,e))})(a),await(async t=>{await Promise.all(t.filter(t=>t.hasAttribute("data-chart-src")).map(async t=>{const e=t.getAttribute("data-chart-src"),a=Array.from(t.querySelectorAll("table")).find(t=>t.tHead)??null;for(const n of t.querySelectorAll("table"))n!==a&&n.remove();try{const n=await fetch(e);if(!n.ok)throw new Error(`${n.status} ${n.statusText}`);const o=await n.json(),r=Array.isArray(o)?o:o?.rows?Array.isArray(o.rows)?o.rows:Ce(o.rows):Ce(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 e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||vt?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),vt?.log?.(`Read ${r.length} rows from "${e}"`)}catch(o){const t="file:"===window.location.protocol;console.warn(`[${n}] Could not read the chart data in "${e}": ${o.message}.`+(t?" 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=Te(e);a?.matches(Le);a=Te(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=Te(e);t?.matches(Le);t=Te(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(a),((t,e)=>{if(!e)return;const a=new Map;for(const o of t){let t=o.getAttribute("data-chart-keys")||null;if(!t)continue;if(a.has(t)){const e=a.get(t)+1;a.set(t,e),console.warn(`[${n}] Two charts have data-chart-keys="${t}", so this one uses "${t}-${e}" to keep their translations apart.`),t=`${t}-${e}`}else a.set(t,1);o.querySelectorAll("tbody th").forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-row${a+1}`)});const r=kt(o);r.length>1&&r.forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-col${a+1}`)}),r.forEach((n,a)=>{if(!n.hasAttribute("data-group"))return;const r=[];o.querySelectorAll(`tbody tr > td:nth-of-type(${a+1})`).forEach(n=>{const a=(n.textContent||"").trim();r.includes(a)||r.push(a),n.getAttribute(e)||n.setAttribute(e,`${t}-group${r.indexOf(a)+1}`)})}),vt?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute),a},qe=(t,e)=>{const a=vt.timed("Building",t,()=>de(t,e));return a?(t.setAttribute(Oe,""),((t,e)=>{let a=t,r=Ue(a.figure),s=null,l=!1,u=!1;const h=async()=>{if(!le(a.figure,e))return ye(a,!0);const t=a.figure.classList.contains("is-shown");if(!l||null===s||t||u)!l&&e.replay&&t&&ye(a,!1);else{u=!0;const t=Ee()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(a.figure);t&&await(n=t,new Promise(t=>{const e=["animationstart","transitionrun"],a=()=>{for(const t of e)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(n)&&a()},r=new MutationObserver(()=>{"0"!==getComputedStyle(n).opacity&&a()});for(const n of e)document.addEventListener(n,o,!0);r.observe(n,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(Ee())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)))})(a.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)})(a.figure,e)),u=!1,!l&&e.replay||ye(a,!0)}var n},b=()=>{const t=Ue(a.figure);if(!t||t===r)return;const n=vt.timed("Building",a.figure,()=>de(a.figure,e,t));n&&((t=>{Jt(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${d}`)?.remove(),t.controls?.remove()})(a),Et(n,a.step,!0),a=n,r=t,s=null)},$=()=>{b();const t=a.plot.clientWidth;t&&t!==s&&vt.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:s,type:l,values:u,series:d,seriesValues:h,names:b,annotations:$}=t,p=Number.parseFloat(t.figure.dataset.chartAspect??""),v=p>0?p:l.aspect??e.aspect,x="beside"===l.categories,N=t.axes&&!l.axes?t.axes:null,H=x?null:t.categories[0]?.parentElement;let L=null;if(N){a.style.margin="",H&&(H.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=l.segments?.(s)??[],r=t.stacked?s.flatMap(t=>Object.values(Z(t,d.length,l.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):s.flatMap(t=>t.cells.slice(0,d.length).filter(t=>!t.missing).map(t=>t.value)),c=Math.min(0,-B(r.map(t=>-t))),i=Math.max(0,B(r)),u=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:h,chartScale:f}=t.figure.dataset,m=Ct(h??f);if(m&&m.length>2)L={min:m[0],max:m[m.length-1],step:0,ticks:m};else{const[t,e]=m??[c,i],a=At(e-t,Math.max((x?n/9:n*v/3)/u,2)),o=(t,e)=>m?t:Number(((e?Math.ceil:Math.floor)(t/a-1e-9*(e?1:-1))*a).toPrecision(12)),r=o(t,!1),s=o(e,!0);L={min:r,max:s,step:a,ticks:St(r,s,a)}}N.ticks.textContent="";const b=s.find(t=>!t.missing),$=B(L.ticks.map(t=>_(String(t))));for(const t of L.ticks){const n=C(w,N.ticks);n.dataset.value=String(t),n.dataset.place="none",b?.prefix&&(n.dataset.prefix=b.prefix),b?.suffix&&(n.dataset.suffix=b.suffix),we(n,$,e.locale)}if(N.numbers){const t=Array.from(N.ticks.children);for(const e of t)delete e.dataset.place;D(t),x?a.style.marginBottom=`${(t[0]?I(t[0]).height:0)+6}px`:(a.style.marginLeft=`${B([0,...t.map(t=>I(t).width)])+10}px`,H&&(H.style.marginLeft=a.style.marginLeft))}}const E=a.clientWidth;if(!E)return!1;const z=M/E,U=M*v;a.classList.add("is-placed");for(const n of[...h.flat(),...t.totals])delete n.dataset.place;a.style.removeProperty("--_fit"),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const V=l.axes?t.axes:null;let F=[];if(V){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=d.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=s.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:c,chartScaleY:l,chartScale:i}=t.figure.dataset,u=[Ct(c),Ct(l??i)];F=o.map((t,e)=>((t,e,n)=>{if(n&&n.length>2)return{min:n[0],max:n[n.length-1],step:0,ticks:n};let a=n?.[0]??-B(t.map(t=>-t)),o=n?.[1]??B(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=At(o-a,e);return{min:a,max:o,step:r,ticks:St(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?U/z/(4*n):E/(9*n),4),u[e])),V.ticks.textContent="",F.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=B(t.ticks.map(t=>_(String(t))));for(const o of t.ticks){const t=C(w,V.ticks);t.dataset.axis=n?"y":"x",t.dataset.value=String(o),a?.prefix&&(t.dataset.prefix=a.prefix),a?.suffix&&(t.dataset.suffix=a.suffix),we(t,s,e.locale)}})}const q=V?Array.from(V.ticks.children):[];D([...h.flat(),...t.totals,...b,...t.categories,...$.map(t=>t.badge),...V?.titles??[],...q]);const P=(u[0]?I(u[0]).height:0)*z,j=$[0]?.badge?I($[0].badge).height*z:0,R=Math.max(U,$e(t.figure,z,"--tablechart-min-height","200px")??0,l.minHeight?.({labelHeight:P,nameHeight:Math.max(0,B(t.categories.map(t=>I(t).height)))*z,unit:z,rows:s.length,series:d.length,stacked:t.stacked})??0),W=t.stacked?s.map(t=>{const e=J(t,d.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):s,G=(l.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?W.map(t=>({...t,cells:[t.cells[0]]})):s),K={labelHeight:P,badgeHeight:j,hasAnnotations:$.length>0,unit:z,series:d.length,focused:d.some(t=>t.focus),stacked:t.stacked},X=Math.max((Y=B,t.stacked?Y(s.map(t=>Z(t,d.length,l.running).top)):Y([...G.flatMap(t=>[t.from,t.to,t.value]),...s.flatMap(t=>t.cells.slice(0,d.length).map(t=>t.value))])),0);var Y;const Q=G.some(t=>"up"===t.kind||"down"===t.kind)?G.flatMap(t=>[t.from,t.to]):t.stacked?s.map(t=>Z(t,d.length,l.running).bottom):s.flatMap(t=>t.cells.slice(0,d.length).map(t=>t.value)),tt=Math.min(-B(Q.map(t=>-t)),0),et=l.headroom?.(K)??P,nt=2*z+(l.footroom?.(K)??0)+(tt<0?P+4*z:0),at=R-et-nt,rt=L?Math.max(L.max,X):1.02*X,st=L?Math.min(L.min,tt):1.02*tt,ct=$.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,lt=t=>{const e=Number.parseFloat(ct?.getAttribute(t)??"");return Number.isFinite(e)?e:null},it=lt("data-from")??lt("data-at"),ut=lt("data-to");let dt=null;if(ct&&(null!==it||null!==ut)){const t=it??0,e=ut??rt,a=null===ut?t:null===it?e:(t+e)/2,o=ct.getAttribute("data-size"),r=o?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===o||r||console.warn(`[${n}] 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===ut?.22:.3,.05),.8),c=G.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);l.breakable?tt<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>rt||0===t&&e===rt?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${X}.`):c.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):dt={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const ht=dt?dt.gap:null,ft=(dt&&$e(t.figure,z,"--tablechart-break-gap",""))??13,mt=R-nt,bt=rt-st||1;let $t,pt,gt=t=>mt-(t-st)/bt*at;if(dt){const{lo:t,hi:e,gap:n,share:a}=dt,o=at*a,r=(at-o-ft)/(t+(rt-e)),s=o/(e-t);gt=a=>a<=t?mt-a*r:a<=n?mt-t*r-(a-t)*s:a<=e?mt-t*r-(a-t)*s-ft:mt-t*r-o-ft-(a-e)*r}let wt=[];if(V){const t=6*z,[e,n]=V.titles,a=t=>t?I(t).width*z:0,o=t=>t?I(t).height*z:0,r=q.filter(t=>"x"===t.dataset.axis),s=q.filter(t=>"y"===t.dataset.axis),c=o(q[0]),l=a(n)+B([0,...s.map(a)])+2*t,i=c/2;pt=[l,i,M-l-B([0,...r.map(a)])/2,R-i-o(e)-c-2*t];const[u,d,h,f]=pt,[m,b]=F,$=t=>u+(t-m.min)/(m.max-m.min||1)*h,p=t=>d+f-(t-b.min)/(b.max-b.min||1)*f;$t=$,gt=p;const g=t=>a(r.find(e=>Number(e.dataset.value)===t));wt=[Tt(m,e=>e.every((n,a)=>!a||$(n)-$(e[a-1])>(g(n)+g(e[a-1]))/2+t)).ticks,Tt(b,e=>e.every((n,a)=>!a||p(e[a-1])-p(n)>c+t/2)).ticks];for(const w of q){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,a=wt[n].includes(e);w.dataset.place=a?n?"before":"below":"none",a&&T(w,n?u-t:$(e),n?p(e):d+f+t,M,R)}e&&T(e,u+h/2,R-o(e),M,R),n&&T(n,0,d+f/2,M,R)}const yt=b.length?B(b.map(t=>I(t).width))*z+12*z:0,Mt=t.categories[0]?.parentElement;Mt&&(Mt.style.paddingRight=yt?yt/M*100+"%":"");const vt=(M-yt)/s.length,xt=t=>t>=0&&t<s.length?t:null;t.rowAt=l.centre?null:"beside"===l.categories?(t,e)=>xt(Math.floor(e*z/(R/s.length))):t=>xt(Math.floor(t*z/vt));const kt=vt/M*100,Nt=100/s.length;if(t.rowBox="beside"===l.categories?t=>[0,t*Nt,100,Nt]:t=>[t*kt,0,kt,100],r.setAttribute("viewBox",`0 0 1000 ${A(R)}`),r.textContent="",pt&&$t){const[n,a,o,s]=pt,[c,l]=wt,i=$t;ce(t.figure,"data-chart-grid",e.grid)&&r.appendChild(S("path",{class:y,d:[...c.map(t=>`M${A(i(t))},${A(a)}V${A(a+s)}`),...l.map(t=>`M${A(n)},${A(gt(t))}H${A(n+o)}`)].join("")})),r.appendChild(S("path",{class:g,d:[`M${A(n)},${A(a)}V${A(a+s)}H${A(n+o)}`,...c.map(t=>`M${A(i(t))},${A(a+s)}v${A(4*z)}`),...l.map(t=>`M${A(n)},${A(gt(t))}h${A(-4*z)}`)].join("")}))}t.checks=[];const Ht={rows:s,segments:G,cx:t=>(t+.5)*vt,y:gt,x:$t,frame:pt,length:(e,n)=>$e(t.figure,z,e,n),barWidth:Math.min(vt*e.barfill,pe(t.figure,z)),barMax:pe(t.figure,z),height:R,unit:z,labelHeight:P,badgeHeight:j,after:s.length,note:0,labels:"inside"===t.figure.dataset.chartLabels||"outside"!==t.figure.dataset.chartLabels&&"inside"===e.labels?"inside":"outside",insideAlign:be(t.figure),breakAt:ht,squeeze:dt,breakGap:ft,domain:L?[L.min,L.max]:null,stacked:t.stacked,shape:ie(t.figure,e),totals:t.totals,svg:r,plot:a,values:u,series:d,seriesValues:h,names:b,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[]};if(a.style.setProperty("--count",String(Math.max(1,...s.map(t=>t.slot+1)))),l.draw(Ht),Ht.rowAt&&(t.rowAt=Ht.rowAt),N&&L){const n=6*z,a=x&&Ht.x?Ht.x:gt,o=Array.from(N.ticks.children),s=t=>I(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Tt(L,t=>t.every((e,o)=>!o||(x?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*z+n:a(t[o-1])-a(e)>s(e).height*z+n/2))).ticks.filter(t=>!dt||t<=dt.lo||t>=dt.hi);for(const t of o){const e=Number(t.dataset.value),o=N.numbers&&c.includes(e);t.dataset.place=o?x?"below":"before":"none",o&&T(t,x?a(e):-n,x?R+n:a(e),M,R)}const l=M-yt;ce(t.figure,"data-chart-grid",e.grid)&&r.prepend(S("path",{class:y,d:c.map(t=>x?`M${A(a(t))},0V${A(R)}`:`M0,${A(a(t))}H${A(l)}`).join("")})),N.numbers&&r.appendChild(S("path",{class:g,d:[x?`M${A(a(L.min))},${A(R)}H${A(a(L.max))}`:`M0,${A(a(L.max))}V${A(a(L.min))}`,...c.map(t=>x?`M${A(a(t))},${A(R)}v${A(4*z)}`:`M0,${A(a(t))}h${A(-4*z)}`)].join("")}))}for(const[n,o]of $.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series,r=t=>({...t,...t.cells[e]??t.cells[0]});o.type.draw(o.spec,o.badge,{...Ht,...t.stacked&&{rows:W,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&{rows:s.map(r),segments:G.map(t=>{const e=r(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:h[e]},after:t.plan?o.after:Math.min(o.after,Number(a.style.getPropertyValue("--count"))||o.after),note:n+1})}(t=>{const e=t.plan;if(!e)return;const n=e.rows.length-1,a=t=>e.series.map((n,a)=>e.cells[t]?.[a]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=a(t);return e.some(t=>null===t)?null:Math.min(...e)},s=new Set(t.totals),c=(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 o of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(o.closest("table, .tablechart-controls")||o.hasAttribute("data-from"))continue;const t=Number(o.dataset.note);if(t>0){const n=e.notes[t-1];n&&c(o,n.step,"--after",n.after);continue}const l=o.dataset.row?Number(o.dataset.row)-1:n;if(o.classList.contains("tablechart-connector")){const t=e.rows[l-1],n=e.rows[l];if(t&&n){const e=(t.step??-1)>(n.step??-1);c(o,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(s.has(o)){const t=a(l).filter(t=>null!==t);c(o,t.length?Math.max(...t):null,"--i",e.rows[l]?.slot??0);continue}if(o.hasAttribute("data-stack")){c(o,r(l),"--i",e.rows[l]?.slot??0);continue}const i=o.dataset.series?Number(o.dataset.series)-1:0,u=o.dataset.series?e.series[i]:void 0;if(o.classList.contains("tablechart-piece")){const t=a(l)[i]??null,n=e.cells[l]?.[i];c(o,t===r(l)?null:t,"--i",n&&null!==n.step?n.slot:l);continue}if("legend"===o.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));c(o,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[l]?.[i];d&&null!==d.step?c(o,d.step,"--i",d.slot):u&&null!==u.step?c(o,u.step,"--i",l):e.rows[l]&&c(o,e.rows[l].step,"--i",e.rows[l].slot)}const l=t.figure.querySelector(`.${m}`);if(l){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?c(l,null,"--i",0):c(l,n,"--i",t.filter(t=>t===n).length)}const u=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),d=e.series.some(t=>null!==t.step)?e.rows.length:1;t.plot.style.setProperty("--count",String(Math.max(d,...u)));const h=t.figure.querySelectorAll(`.${o}`),f=h[h.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===f?.dataset.kind&&h.length>1){const t=Number(f.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(f.dataset.grow="down"===f.dataset.grow?"up":"down")}const b=Array.from(t.figure.querySelectorAll(`.${i}`));if(b.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=b.length,o=Math.max(0,b.findIndex((t,n)=>e(t)!==e(b[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=b[(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??"",k(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))}}Ot(t)})(t);const Lt=t.categories[0]?.parentElement;Lt&&"beside"!==l.categories&&!l.centre&&ot(Lt,t.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const Et=$.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*z,n=t.offsetHeight*z,a=Number.parseFloat(t.style.left)/100*M,o=Number.parseFloat(t.style.top)/100*R,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*z;return[S("rect",{class:f,"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("; ")})]}),zt=r.querySelector(`.${y}`),Bt=Array.from(r.querySelectorAll(`.${c}`));if(zt||Bt.length){const e=a.getBoundingClientRect(),n=M/e.width,o=getComputedStyle(a),s=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2,c=[...h.flat(),...t.totals,..."beside"===l.categories?t.categories:[]].flatMap(t=>{if("none"===t.dataset.place||t.hidden||t.hasAttribute("data-left-out"))return[];const a=t.getBoundingClientRect(),o=a.height*n/s,r=Array.from(t.style).filter(t=>t.startsWith("--")).map(e=>`${e}:${t.style.getPropertyValue(e)}`);return a.width?[S("rect",{class:f,"data-for":"text",x:(a.left-e.left)*n-3*z,y:(a.top-e.top)*n+(a.height*n-o)/2-z,width:a.width*n+6*z,height:o+2*z,style:r.join("; ")})]:[]}),i=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Bt)re(t,[...c,...Et].map(i));if(zt&&t.plan)O(r,c,M,R,[zt]);else if(zt){const t=(_t=zt,Array.from((_t.getAttribute("d")??"").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g),([,t,e,n,a])=>"H"===n?[+t,+e,+a,+e]:[+t,+e,+t,+a]));zt.setAttribute("d",t.map(([t,e,n,a])=>oe(t,e,n,a,c.map(i))).join(""));for(const e of c){const n=se(t,i(e));n&&zt.after(S("path",{class:y,"data-gap":"",d:n,style:e.getAttribute("style")??""}))}}}var _t;O(r,Et,M,R,void 0,`.${c}`),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||ve(r);const Ut=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(l.columns?[t.categories]:[...h,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||l.centre&&s[Number(t.dataset.row)-1]?.isTotal)(e)&&!Ut(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>Ut(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(a,e))&&(s=t,h())};let v=!1;const x=new ResizeObserver(()=>{v||(v=!0,requestAnimationFrame(()=>{v=!1,$()}))}),N=new IntersectionObserver(t=>{for(const e of t)l=e.isIntersecting,h()},{threshold:e.threshold}),H=()=>{a.figure.classList.add(p),ye(a,!0),xe(a.svg),a.figure.offsetWidth},L=()=>a.figure.classList.remove(p),E=()=>{s=null,$()},z={relabel:()=>ge(a,e),refresh:E};b(),$(),x.observe(a.figure),N.observe(a.figure),window.addEventListener("beforeprint",H),window.addEventListener("afterprint",L),(t=>{ze.add(t),Be||(Be=new MutationObserver(()=>{for(const t of ze)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of ze)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(z);const U={figure:a.figure,refresh:E,next:()=>Et(a,a.step+1),previous:()=>Et(a,a.step-1),stepTo:t=>Et(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){x.disconnect(),N.disconnect(),window.removeEventListener("beforeprint",H),window.removeEventListener("afterprint",L),(t=>{ze.delete(t),!ze.size&&Be&&(Be.disconnect(),Be=null)})(z),Jt(a),a.figure.tablechart===U&&delete a.figure.tablechart}};return a.figure.tablechart=U,U})(a,e)):null},Pe=e({LEGEND_CLASS:()=>d,NAME_CLASS:()=>u,POINT_CLASS:()=>h,VIEWBOX_WIDTH:()=>M,avoidCollisions:()=>P,htmlEl:()=>C,largest:()=>B,markerEl:()=>dt,placeAt:()=>T,short:()=>A,sizeOf:()=>I});window.Tablechart={init:async(t={},e=document)=>{const n={...v,...t};n.debug&&(vt.enabled=!0);const a=(await Fe(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>qe(t,n)).filter(t=>null!==t);return vt.log(`Made ${a.length} chart(s).`),{charts:a,refresh:()=>{for(const t of a)t.refresh()},destroy:()=>{for(const t of a)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...v,...e};n.debug&&(vt.enabled=!0);const[a]=await Fe([t],n);return a?qe(a,n):null},defaultConfig:v,addType:(t,e)=>{Qt[t]=e},kit:Pe}}();
|
|
1
|
+
!function(){var t=Object.defineProperty,e=(e,n)=>{let a={};for(var o in e)t(a,o,{get:e[o],enumerable:!0});return n||t(a,Symbol.toStringTag,{value:"Module"}),a},n="tablechart",a="tablechart-value",o="tablechart-bar",r="tablechart-rule",s="tablechart-line",c="tablechart-reference",l="tablechart-head",i="tablechart-slice",u="tablechart-name",d="tablechart-legend",h="tablechart-point",f="tablechart-hole",m="tablechart-centre",b="tablechart-break",$="tablechart-sr",p="is-shown",g="is-printing",w="is-at-once",y="tablechart-axis",M="tablechart-tick",v="tablechart-grid",x=1e3,k={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",shape:"straight",legend:!1,axis:!1,grid:!1,names:!0,tooltip:"auto",tooltipparent:null,table:"never",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},N="cubic-bezier(0.3, 0.3, 0.6, 1)",A=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?N:"linear"}),S=(t,e)=>`${t}:${e}`,H=t=>Math.round(100*t)/100,C=(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?H(t):t))}return n},T=(t,e)=>[t,...e.classes].join(" "),L=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},O=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},z=0,E=0,B=t=>{let e=t.querySelector(":scope > defs");return e||(e=C("defs"),t.prepend(e)),e},U=t=>{const[e,n,a,o,r,s]=["x","y","width","height","rx","ry"].map(e=>Number(t.getAttribute(e))||0),c=Math.min(r,a/2),l=Math.min(s,o/2),i=(t,e)=>c&&l?`a${H(c)},${H(l)} 0 0 1 ${H(t)},${H(e)}`:"";return`M${H(e+c)},${H(n)}h${H(a-2*c)}${i(c,l)}v${H(o-2*l)}${i(-c,l)}h${H(2*c-a)}${i(-c,-l)}v${H(2*l-o)}${i(c,-l)}z`},_=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++z,c=C("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(C("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const u of e)u.setAttribute("fill","black"),c.appendChild(u);const l=B(t);if(l.appendChild(c),o){for(const t of o)t.setAttribute("mask",`url(#${s})`);return}let i=null;for(const u of Array.from(t.childNodes))u!==l&&(r&&u instanceof Element&&u.matches(r)?(i=null,t.appendChild(u)):(i??(i=t.appendChild(C("g",{mask:`url(#${s})`}))),i.appendChild(u)))},F=0,V={create:()=>null,draw(t,e,n){const{rows:a,y:r,svg:s,breakAt:c}=n;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]]},u=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),d="tablechart-break-"+ ++F,h=C("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(C("rect",{x:-1e3,y:-n.height,width:3e3,height:3*n.height,fill:"white"}));const f=[],m=r(c);for(const w of(t=>Array.from(t.querySelectorAll(`.${o}`)).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=w.sideways?n.breakX:m;if(void 0===t)continue;if(!(w.sideways?w.x<t&&w.x+w.width>t:w.y<m&&w.y+w.height>m))continue;const[e,o]=w.sideways?[i(w,t),i(w,t+n.breakGap)]:[i(w,m-n.breakGap),i(w,m)];h.appendChild(C("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[S("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(C("path",{class:b,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const $=Array.from(s.querySelectorAll(`.${b}`)),p=C("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))$.includes(o)||p.appendChild(o);const g=C("defs");g.appendChild(h),s.prepend(g,p)}},P=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},q=t=>(t.split(/[.,]/)[1]||"").length,j=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),D=(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},I=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=j(s),l=r?.5:.5*10**-q(s.match(/-?[\d.,]+/)?.[0]??""),i=!!Number.isNaN(c)||Math.abs(e-c)<=l+1e-9,u={label:a,computed:e,stated:c,agrees:i};o.checks.push(u),i||console.warn(`[${n}] An annotation reads ${c}${r}, but ${a} is ${Number(e.toFixed(2))}${r}. The chart shows your number.`)},R={create:D,draw(t,e,a){const{rows:o,cx:r,y:c,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:f,after:m}=a,[b,$]=((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)]})(t,o.length),p=o[b],g=o[$];if(!p||!g)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${b+1} to ${$+1}, of ${o.length}).`);const w=7*i,y=4*i,M=r(b),v=r($),k=Math.min(c(p.value),c(g.value))-u-y-.9*d,N=t=>c(t)-u-y,A=`M ${M} ${N(p.value)} L ${M} ${k} L ${v} ${k} L ${v} ${N(g.value)-w}`,H=(N(p.value)-k+Math.abs(v-M)+(N(g.value)-w-k))/i+1;f.appendChild(C("path",{class:s,"data-note":a.note,d:A,style:`--len:${H.toFixed(1)}; ${S("--after",m)}`}));const T=N(g.value);var L;f.appendChild(C("polygon",{class:l,"data-note":a.note,points:`${v},${T} ${v-.45*w},${T-w} ${v+.45*w},${T-w}`,style:S("--after",m)})),e&&(O(e,(M+v)/2,k,x,h),e.style.setProperty("--after",String(m))),I(e,(L=p.value,(g.value-L)/Math.abs(L)*100),`${p.value} to ${g.value}`,a)}},W=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let a=1;for(const l of t)for(const[,,t,e]of l)a=Math.max(a,t,e);const o=new Map,r=([t,e,n,o])=>{const r=[];for(let s=Math.floor(t/a);s<=Math.floor((t+n)/a);s++)for(let t=Math.floor(e/a);t<=Math.floor((e+o)/a);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))o.get(e)?.push(t)??o.set(e,[t])},c=t=>((t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[0]+t[2]<=e[0]+e[2]&&t[1]+t[3]<=e[1]+e[3])(t,n)&&r(t).every(e=>!o.get(e)?.some(e=>{return a=e,(n=t)[0]<a[0]+a[2]&&a[0]<n[0]+n[2]&&n[1]<a[1]+a[3]&&a[1]<n[1]+n[3];var n,a}));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},G=new WeakMap,K=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>G.set(t,n[e]))},X=t=>G.get(t)??{width:t.offsetWidth,height:t.offsetHeight},Y=(t,e,n)=>{const a=n.reduce((t,e)=>t+e,0);if("mean"===t)return a?e.reduce((t,e,a)=>t+e*n[a],0)/a:null;if("median"===t){const t=e.map((t,e)=>[t,n[e]]).sort((t,e)=>t[0]-e[0]);let o=0;for(const[e,[n,r]]of t.entries()){if(o+=r,Math.abs(o-a/2)<1e-9&&t[e+1])return(n+t[e+1][0])/2;if(o>a/2)return n}return null}const o=Number.parseFloat(t);return Number.isFinite(o)?o:null},Z={create(t,e){if(!t.textContent?.trim())return null;const n=D(t,e);return n.dataset.kind="reference",n},draw(t,e,a){const{rows:o,cx:r,y:s,x:l,height:i,unit:u,svg:d,after:f}=a,m=o.filter(t=>!t.isTotal&&!t.missing),b=t.hasAttribute("data-name"),$=(t.getAttribute(b?"data-name":"data-value")??"").trim();let p,g,w;if(b){const t=m.map(t=>j(t.label));if("beside"===a.categories[0]?.parentElement?.dataset.place||t.some(Number.isNaN))return void console.warn(`[${n}] A reference line among the names needs names that are numbers, under columns or points.`);const e=Y($,t,m.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[m[s],m[s+1]??m[s]].map(t=>r(o.indexOf(t))),i=null===e||s<0||void 0===t[s+1]||t[s+1]===t[s]?0:(e-t[s])/(t[s+1]-t[s]);w=e,g=s<0?null:c+i*(l-c),p=!1}else{const e=Boolean(a.frame)&&"y"===t.getAttribute("data-axis"),n=a.frame?a.series.flatMap((t,e)=>t.group?[]:[e])[e?1:0]??0:0;w=Y($,m.map(t=>t.cells[n]?.value??t.value),m.map(()=>1)),p=e||!l,g=null===w?null:l&&!e?l(w):s(w)}if(null===g||null===w)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${$}".`);const[y,M,v,k]=a.frame?[a.frame[0],a.frame[1],a.frame[0]+a.frame[2],a.frame[1]+a.frame[3]]:[0,0,o.length>0?r(o.length-1)+r(0):x,l?i:s(0)];if(d.insertBefore(C("line",{class:c,"data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...p?{x1:y,x2:v,y1:g,y2:g}:{x1:g,x2:g,y1:M,y2:k},style:S("--after",f)}),d.querySelector(`:scope > .${h}`)),e){const t=X(e).width*u,n=X(e).height*u,o=4*u,r=p?[[v-t,g-n/2,t,n],[v-t,g-n-o,t,n],[v-t,g+o,t,n]]:[M,M+n,M+2*n].flatMap(e=>[[g-t/2,e,t,n],[g+o,e,t,n],[g-o-t,e,t,n]]),[s]=W([r],a.taken,[0,0,x,i]),c=r[s??0];a.taken.push(c),O(e,c[0]+t/2,c[1]+n/2,x,i),e.style.setProperty("--after",String(f)),"mean"!==$&&"median"!==$||I(e,w,`the ${$}`,a,"")}}},J={create:D,draw(t,e,n){const{rows:a,cx:o,y:r,unit:c,labelHeight:i,height:u,svg:d,values:h,after:f}=n,m=a[0],b=a[a.length-1];if(!m||!b)return;const $=i+18*c,p=10*c,g=10*c;let w=o(0),y=r(m.value)-$,M=o(a.length-1),v=r(b.value)-$,k=0;a.forEach((t,e)=>{const n=M===w?0:(o(e)-w)/(M-w),a=y+n*(v-y)-(r(t.value)-$);a>k&&(k=a)}),y-=k,v-=k;const N=M-w,A=v-y,H=Math.hypot(N,A)||1,T=N/H,L=A/H;w-=T*p,y-=L*p,M+=T*p,v+=L*p;const z=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(M-w)*z,n=y+(v-y)*z,s=X(e).width*c/2,l=n+X(e).height*c/2+8*c;let u=0;a.forEach((e,n)=>{const a=(h[n]?X(h[n]).width:0)*c/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*c-i;u=Math.max(u,l-d)}),y-=u,v-=u}const E=M-T*g,B=v-L*g,U=Math.hypot(E-w,B-y)/c+1;d.appendChild(C("line",{class:s,"data-note":n.note,x1:w,y1:y,x2:E,y2:B,style:`--len:${U.toFixed(1)}; ${S("--after",f)}`}));const _=-L,F=T,V=.42*g;d.appendChild(C("polygon",{class:l,"data-note":n.note,points:[`${M},${v}`,`${E+_*V},${B+F*V}`,`${E-_*V},${B-F*V}`].join(" "),style:S("--after",f)})),e&&(O(e,w+(M-w)*z,y+(v-y)*z,x,u),e.style.setProperty("--after",String(f)));const P=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(P)&&P>0&&I(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(m.value,b.value,P),`${m.value} to ${b.value} over ${P} years`,n)}},Q=(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}},tt=(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}); ${S("--i",e.slot)}`}},et=(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}})},nt=(t,e,n=!1)=>{const a=et(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},at=(t,e)=>{const{top:n,bottom:a}=nt(t,e);return n+a},ot=(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})`)},rt=(t,e,n,a={},r="")=>{const s={class:T(o,e),"data-kind":"bar","data-row":n+1,...a},c=S("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=C("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(o,r)=>{const s=void 0!==a["data-grow"]?{"data-grow":a["data-grow"]}:{};l.appendChild(C("rect",{...s,...r,class:T("tablechart-piece",e),"data-row":n+1,...tt(t,e,o)}))}},st=(t,e,n)=>t.some(t=>X(t).width*n>e-6*n),ct=(t,e,n)=>e>=X(t).height*n*1.6,lt=(t,e,n)=>e>=X(t).width*n*1.5,it=(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},ut={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:n,unit:a,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(P(l.map(t=>X(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/x*100).toFixed(2)}%`);const m=x-4*a,b=t.stacked?Math.max(P(t.rows.map(e=>nt(e,t.series.length).top)),0)||1:Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(P(t.rows.map(e=>-nt(e,t.series.length).bottom)),0):Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),p=Math.max(b,t.domain?.[1]??0),g=Math.max($,-(t.domain?.[0]??0)),w=Math.max(p,t.squeeze?.hi??0)+g,y=(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),w,n,t.squeeze,t.breakGap),M=n/e.length,v=t=>(t+.5)*M,k=Math.min(M*i.barfill,u),N=Q(M,t.series.length,u),A=c[0]??t.totals[0],H=A?X(A).height*a*.56:0,L=Math.max(((d&&!t.stacked?N.size:k)-H)/2,5*a),z=t=>X(t).width*a,E=t=>t.length?P(t.map(z))+L+4*a:0,B=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,U=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:B(e,n)}))),_=e=>{const n=nt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let F=t.stacked?E(t.totals.filter((t,e)=>!_(e))):d?E(U.filter(t=>t.value>=0).map(t=>t.label)):0,V=t.stacked?E(t.totals.filter((t,e)=>_(e))):d?E(U.filter(t=>t.value<0).map(t=>t.label)):0;if(!d&&!t.stacked)for(let o=0;o<3;o++){const t=m-f-F-V,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!lt(n,y(e.value,t),a)),o=E(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),r=E(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(o<=F&&r<=V)break;F=Math.max(F,o),V=Math.max(V,r)}const q=m-f-F-V,j=f+V+y(g,q),D=t=>t<0?j-y(t,q):j+y(t,q);if(t.squeeze&&(t.breakX=D(t.squeeze.gap)),t.x=D,t.stacked)return t.rows.forEach((e,o)=>{const r=nt(e,t.series.length),s=rt(t,e,o,{"data-grow":"right"},r.bottom<0?j-D(r.bottom)+"px center":""),c=v(o)-k/2;et(e,t.series.length).forEach(({from:e,to:r,cell:l},i)=>{const u=t.seriesValues[i][o];if(u.dataset.place="none",l.missing||r===e)return;const d=Math.min(D(e),D(r)),h=Math.max(D(e),D(r));s(i,{x:d,y:c,width:Math.max(h-d,1),height:k,...r<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!lt(u,h-d,a)||X(u).height*a>k),ot(u,t,i),O(u,(d+h)/2,v(o),x,n)});const i=t.totals[o];i&&(i.dataset.place=_(o)?"before":"after",O(i,_(o)?D(r.bottom)-L:D(r.top)+L,v(o),x,n));const u=l[o];u&&O(u,f-8*a,v(o),x,n)}),void s.appendChild(C("line",{class:r,x1:j,x2:j,y1:0,y2:n}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=it(t.plot,e,t=>({size:X(t).height*a,room:N.size+.5*N.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((a,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][r];if(i.missing)return void(u.dataset.place="none");const d=D(i.value),h=i.value<0,f=v(r)+N.offset(l),m=Math.max(Math.abs(d-j),1);0!==i.value&&s.appendChild(C("rect",{class:T(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?j-m:j,y:f,width:m,height:N.size,...tt(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),O(u,h?d-L:d+L,f+N.size/2,x,n)});const i=l[r];i&&O(i,f-8*a,v(r),x,n)}),void s.appendChild(C("line",{class:r,x1:j,x2:j,y1:0,y2:n}))}const I=e.map((t,e)=>lt(c[e],Math.abs(D(t.value)-j),a));e.forEach((e,r)=>{const i=D(e.value),u=v(r),d=e.value<0,h=Math.abs(i-j),m=Math.max(h,1);0!==e.value&&s.appendChild(C("rect",{class:T(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?j-m:j,y:u-k/2,width:m,height:k,style:S("--i",e.slot)}));const b=c[r],$=Math.max(Math.min(L,h-z(b)-6*a),6*a),p=d?1:-1;b.dataset.place=I[r]?"inside":d?"before":"after",b.dataset.kind=e.kind,O(b,I[r]?"center"===t.insideAlign?(j+i)/2:"start"===t.insideAlign?j-p*($+z(b)/2):i+p*($+z(b)/2):i-p*L,u,x,n);const g=l[r];g&&O(g,f-8*a,u,x,n)}),s.appendChild(C("line",{class:r,x1:j,x2:j,y1:0,y2:n}))}},dt={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:n,y:a,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,f=a(0);if(t.stacked)return t.rows.forEach((e,o)=>{const r=nt(e,t.series.length),i=rt(t,e,o,{},r.bottom<0?`center ${f-a(r.top)}px`:""),u=n(o)-s/2;et(e,t.series.length).forEach(({from:e,to:r,cell:d},h)=>{const f=t.seriesValues[h][o];if(f.dataset.place="none",d.missing||r===e)return;const m=Math.min(a(r),a(e)),b=Math.max(a(r),a(e));i(h,{x:u,y:m,width:s,height:Math.max(b-m,1),...r<e&&{"data-grow":"down"}}),f.dataset.place="inside",f.toggleAttribute("data-left-out",!ct(f,b-m,l)||X(f).width*l>s-4*l),ot(f,t,h),O(f,n(o),(m+b)/2,x,c)});const d=t.totals[o];if(d){const t=0===r.top&&r.bottom<0;d.dataset.place=t?"below":"outside",O(d,n(o),t?a(r.bottom)+4*l:a(r.top)-4*l,x,c)}}),void i.appendChild(C("line",{class:r,x1:0,x2:x,y1:f,y2:f}));if(t.series.length>1){const e=n(1)-n(0)||2*n(0),s=Q(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=it(t.plot,u,t=>({size:X(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((u,h)=>{const m=e.cells[h]??e.cells[0],b=t.seriesValues[h][r],$=n(r)+s.offset(h);if(m.missing)return void(b.dataset.place="none");const p=a(m.value),g=m.value<0,w=Math.max(Math.abs(f-p),1);0!==m.value&&i.appendChild(C("rect",{class:T(o,e),"data-kind":"bar","data-row":r+1,...g&&{"data-grow":"down"},x:$,y:g?f:f-w,width:s.size,height:w,...tt(t,e,h)})),b.dataset.place=g?"below":"outside",b.toggleAttribute("data-left-out",!d),O(b,$+s.size/2,g?p+4*l:p-4*l,x,c)})}),void i.appendChild(C("line",{class:r,x1:0,x2:x,y1:f,y2:f}))}const m=st(u,s,l),b=e.map((t,e)=>"inside"===d&&!m&&!t.missing&&ct(u[e],Math.abs(f-a(t.value)),l)),$=u[0]?X(u[0]).height*l*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())b[o]&&(p=Math.min(p,(s-X(r).width*l)/2));e.forEach((t,e)=>{const r=a(t.value),d=t.value<0;if(t.missing)return O(u[e],n(e),f-4*l,x,c),void(u[e].dataset.place="outside");const m=Math.max(Math.abs(f-r),1);0!==t.value&&i.appendChild(C("rect",{class:T(o,t),"data-kind":t.kind,"data-row":e+1,...d&&{"data-grow":"down"},x:n(e)-s/2,y:d?f:f-m,width:s,height:m,style:S("--i",t.slot)}));const g=d?-1:1,w=Math.min(p,(Math.abs(f-r)-$)/2),y="center"===h?(r+f)/2:"start"===h?f-g*(w+$/2):r+g*(w+$/2),M=d?r+4*l:r-4*l;O(u[e],n(e),b[e]?y:M,x,c),u[e].dataset.place=b[e]?"inside":d?"below":"outside"}),i.appendChild(C("line",{class:r,x1:0,x2:x,y1:f,y2:f}))}},ht=0,ft={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:s,centre:c}){const l=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,f=Math.max(Math.min(x,e)/2-h,10),m=f*s.ringfill,b=f-m/2,$=2*Math.PI*b,p=[];let g=0,w=0,y=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,M=A(y,h),v=`--share:${h.toFixed(4)}; --start:${M.start.toFixed(4)}; --span:${M.span.toFixed(4)};`,k=h*$,N=g/$*2*Math.PI-Math.PI/2;p.push(N),o.appendChild(C("circle",{class:T(i,t),"data-slice":w+1,"data-row":s+1,cx:l,cy:u,r:b,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${k.toFixed(1)} ${($-k).toFixed(1)}`,"stroke-dashoffset":(-g).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${k.toFixed(1)}; --circ:${$.toFixed(1)}; ${v} --ease:${M.easing}; ${S("--i",t.slot)}`}));const H=N+k/$*Math.PI,L=Math.cos(H),z=Math.sin(H);o.appendChild(C("line",{class:"tablechart-leader",x1:l+L*(f+2*n),y1:u+z*(f+2*n),x2:l+L*(f+7*n),y2:u+z*(f+7*n),"data-row":s+1,style:`${v} ${S("--i",t.slot)}`})),c.style.setProperty("--start",M.start.toFixed(4)),c.style.setProperty("--span",M.span.toFixed(4));const E=f+9*n,B=X(c).width*n/2;O(c,l+L*(E+Math.abs(L)*B),u+z*(E+Math.abs(z)*a*.7),x,e),c.dataset.place="around",g+=k,y+=h,w+=1}),p.length>1){const t=b-m/2-1,n=b+m/2+1,a="tablechart-slices-"+ ++ht,r=C("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(C("rect",{x:0,y:0,width:x,height:e,fill:"white"}));for(const e of p)r.appendChild(C("line",{class:"tablechart-divide",x1:l+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:l+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const s=C("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${i}`)))s.appendChild(e);const c=C("defs");c.appendChild(r),o.prepend(c,s)}c&&O(c,l,u,x,e)}},mt=["circle","square","diamond"],bt=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=mt.find(t=>n.includes(t));return{shape:a??mt[Math.floor(e/2)%mt.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},$t=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return C("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return C("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return C("polygon",{points:`${e},${n-t} ${e+.87*t},${n+t/2} ${e-.87*t},${n+t/2}`,...o})}return C("circle",{cx:e,cy:n,r:a,...o})},pt=t=>Number(t.toFixed(2));function gt(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 wt,yt,Mt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),vt=t=>({segments:Mt,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:a,seriesValues:o,names:s,cx:c,y:l,height:i,unit:u,labelHeight:d,svg:m,stacked:b}=e,$="step"===e.shape,p="smooth"===e.shape,g=a.length>1,w=a.some(t=>t.focus),y=n.length-1,M=l(0),v=n.length>1?c(1)-c(0):2*c(0);m.style.setProperty("--_base",`${pt(M)}px`);const k=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],N=(t,e)=>!k(t,e)||!!k(t,e)?.missing,A=n.map(t=>b?et(t,a.length,!0):null),S=(t,e)=>A[e]?.[t].to??k(t,e)?.value??0,H=(t,e)=>A[e]?.[t].from??0,T=(t,e)=>[c(e),l(S(t,e))],L=a.map((t,e)=>{if(!g)return{attrs:{},ink:""};const n=w&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),z=Math.min(y,6);e.plot.style.setProperty("--count",String(z+1));const E=y>0?z/($?n.length:y):1,B=t=>t*E,U=t=>`--i:${pt(B(t))}`,F=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{N(t,o)||(a<0&&(a=o),(o===y||N(t,o+1))&&(($||o>a)&&e.push([a,o]),a=-1))}),e},V=(t,e)=>`--i:${pt(B(t)+1)}; --d:${pt(B($?e+1:e)-B(t))}`,P=(t,e)=>({"data-from":t+1,"data-to":e+1,...$&&{"data-flat":""}}),q=p?a.map((t,e)=>gt(n.length,t=>N(e,t),t=>T(e,t))):[],j=p&&t?a.map((t,e)=>gt(n.length,t=>N(e,t),t=>[c(t),l(H(e,t))])):[],D=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{$?(a.push(`H${pt(o+n*v/2)}`),s<t.length-1&&a.push(`V${pt(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])=>`${pt(t)},${pt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${pt(o)},${pt(r)}`)}),a},I=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),l(o(t,e+a))]),R=(t,e,n,a)=>p?t[e].slice(n,a+1):null,G=t=>c(t)-($?v/2:0),K=t=>c(t)+($?v/2:0);t&&a.forEach((t,e)=>(t=>{const e=C("g",{class:"tablechart-area",...L[t].attrs,...b&&{"data-stacked":""},style:L[t].ink}),n=F(t),a=C("g",{class:"tablechart-area-fill",style:`--rows:${pt(z+1)}; ${n.length?V(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=I(t,o,r,S),n=I(t,o,r,H),s=R(j,t,o,r)?.reverse()??null,c=[`M${pt(G(o))},${pt(n[0][1])}`,`L${pt(G(o))},${pt(e[0][1])}`,...D(e,R(q,t,o,r),1),`L${pt(K(r))},${pt(n[n.length-1][1])}`,...D(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(C("path",{d:c,...P(o,r),style:V(o,r)}))}m.appendChild(e)})(e)),a.forEach((t,e)=>(t=>{const e=a[t];for(const[n,a]of F(t)){const o=I(t,n,a,S),r=[`M${pt(G(n))},${pt(o[0][1])}`,...D(o,R(q,t,n,a),1)].join(" ");m.appendChild(C("path",{class:"tablechart-series",...L[t].attrs,d:r,...e.line&&{"data-line":e.line},...P(n,a),style:`${L[t].ink}${V(n,a)}`}))}})(e)),$||(()=>{const t=a.map((t,e)=>g?bt(a,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=T(e,n);return $t(t[e].shape,o,r,4*u,{...a,style:`${a.style??""}${s=r,`--rise:${pt(M-s)}px; `}${U(n)}`});var s},o=t=>n.map((t,e)=>e).filter(e=>!N(t,e)),r=a.flatMap((n,a)=>t[a].open?o(a).map(t=>e(a,t,{class:f,"data-row":t+1,...g&&{"data-series":a+1}})):[]);_(m,r,x,i),a.forEach((n,a)=>{for(const r of o(a))m.appendChild(e(a,r,{class:h,...L[a].attrs,"data-marker":t[a].shape,...t[a].open&&{"data-open":""},"data-row":r+1,style:L[a].ink}))})})();const Y=(t,e)=>{let n=e;for(;n<y&&!N(t,n+1)&&k(t,n+1)?.value===k(t,e)?.value;)n++;return n},Z=(e,n)=>{const o=k(e,n);if(!o||o.missing)return"none";if($&&n>0&&!N(e,n-1)&&k(e,n-1)?.value===o.value)return"none";if(w&&!a[e].focus)return"none";if(b)return"middle";const r=o.value<0?"below":"above";if(!g||w||a.length>2)return r;const s=k(1-e,n);return!s||s.missing?r:o.value>s.value||o.value===s.value&&0===e||t&&o.value>=0&&T(e,n)[1]+7*u+d>M?"above":"below"},J=g&&!w&&a.length>2&&!b&&!$,Q=new Map;if(J){const t=n.flatMap((t,e)=>a.map((t,n)=>({s:n,i:e,value:k(n,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==Z(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],r=t.map(({s:t,i:n,value:a})=>{const r=X(o[t][n]).width*u,[s,c]=T(t,n);return e(a).map(t=>[s-r/2,"above"===t?c-7*u-d:c+7*u,r,d])}),s=a.flatMap((t,e)=>n.flatMap((t,n)=>{if(N(e,n))return[];const[a,o]=T(e,n);return[[a-4*u,o-4*u,8*u,8*u]]})),l=W(r,s,[0,0,c(y)+c(0),i]);t.forEach(({s:t,i:n,value:a},r)=>Q.set(o[t][n],null===l[r]?null:e(a)[l[r]]))}o.forEach((t,e)=>{t.forEach((t,n)=>{t.style.setProperty("--i",String(pt($?(B(n)+B(n+1))/2:B(n))));const a=Q.get(t)??Z(e,n);if(t.dataset.place="above"===a?"outside":a,t.toggleAttribute("data-left-out","none"!==a&&((t,e)=>J?null===Q.get(o[t][e]):!(!b&&!$)&&(X(o[t][e]).width*u>($?Y(t,e)-e+1:1)*v-4*u||!!(b&&t>0&&S(t,e)<H(t,e))||b&&Math.abs(l(H(t,e))-l(S(t,e)))<1.2*d))(e,n)),$&&"none"!==a?t.dataset.rowEnd=String(Y(e,n)+1):delete t.dataset.rowEnd,"none"===a)return;const r=X(t).width*u/2+4*u;let s=c(n);$?s=(c(n)+c(Y(e,n)))/2:"middle"===a&&0===n?s+=r:"middle"===a&&n===y&&(s-=r);const h=l(S(e,n)),f={middle:(l(H(e,n))-h)/2,above:-7*u,below:7*u};O(t,s,h+f[a],x,i)})});const tt=s.map((t,e)=>{let n=y;for(;n>0&&N(e,n);)n--;const[a,o]=T(e,n);return{name:t,x:($?a+v/2:a)+10*u,y:b?(o+l(H(e,n)))/2:o}}),nt=(s[0]?X(s[0]).height:0)*u;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))(tt,nt))O(t.name,t.x,t.y,x,i);const at=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),ot=t||b||2!==a.length||w||at?M:i-2*u;m.appendChild(C("line",{class:r,x1:0,x2:c(y)+c(0),y1:ot,y2:ot}))}}),xt=vt(!1),kt=vt(!0),Nt=new Set,At={segments:t=>{let e=0,a=!1;return t.map(t=>{if(t.isTotal)return a&&((t,e)=>{if(Math.abs(t-e)<=Math.abs(e)/100)return;const a=`[${n}] A total reads ${t}, but the steps before it add up to ${Number(e.toFixed(6))}. The chart shows your number.`;Nt.has(a)||(Nt.add(a),console.warn(a))})(t.value,e),a=!1,e=t.value,{...t,from:0,to:t.value,kind:"total"};const o=e;return e+=t.value,a=!0,{...t,from:o,to:e,kind:t.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:n,barWidth:a,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=n(0),f=st(i,a,c),m=d??"center",b=t.map((e,a)=>{const o=n(Math.max(e.from,e.to)),r=Math.abs(n(e.from)-n(e.to)),s=null!==u&&Math.min(e.from,e.to)<u&&Math.max(e.from,e.to)>u,l="total"===e.kind&&a>0&&a===t.length-1;return{top:o,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!f&&ct(i[a],r,c)}}),$=i[0]?X(i[0]).height*c*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of b.entries())r.inside&&(p=Math.min(p,(a-X(i[o]).width*c)/2));const g=t.length,w=(t,e,n=!1)=>`--start:${(t/g).toFixed(4)}; --span:${(e/g).toFixed(4)}; --ease:${n?N:"linear"};`;t.forEach((o,r)=>{const s=t[r+1];if(!s)return;const c=n(o.to),i=e(r)+a/2,u=e(r+1)-a/2;l.appendChild(C("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${S("--i",s.slot)}; ${w(r+1,1/3)}`}))}),t.forEach((n,r)=>{const{top:u,length:d,down:h,inside:f}=b[r];l.appendChild(C("rect",{class:T(o,n),"data-kind":n.kind,"data-row":r+1,"data-grow":h?"down":"up",x:e(r)-a/2,y:u,width:a,height:Math.max(d,1),style:`${S("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const y=i[r];y.style.setProperty("--start",(r/g).toFixed(4)),y.style.setProperty("--span",(1/g).toFixed(4));const M=Math.min(p,(d-$)/2),v="center"===m?u+d/2:"end"===m!==h?u+M+$/2:u+d-M-$/2;y.dataset.place=f?"inside":"outside",y.dataset.kind=n.kind;const k=f?v:"down"===n.kind?u+d+X(y).height*c+3*c:u-3*c;O(y,e(r),k,x,s)}),l.appendChild(C("line",{class:r,x1:0,x2:x,y1:h,y2:h}))}},St={enabled:!1,log(...t){St.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!St.enabled)return a();const o=performance.now(),r=a(),s=performance.now()-o,c=e.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${n}] ${t} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,e):St.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},Ht=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}},Ct=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),Tt=t=>Number(t.toPrecision(12)),Lt=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return Tt((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},Ot=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(Tt(o*n));return a},zt=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Tt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},Et=t=>{const e=(t??"").trim().split(/\s+/).map(Number.parseFloat);return e.length>1&&e.every(Number.isFinite)?e.sort((t,e)=>t-e):null},Bt=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=zt(n,t.step),a=Ot(t.min,t.max,n);return{...t,step:n,ticks:a}},Ut=["axis-break","trend","bracket"],_t=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))}},Ft=(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)),_t(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}}))},Vt="tablechart-tooltip",Pt=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],qt=null,jt=null,Dt=null,It=0,Rt=()=>{clearTimeout(It),qt&&jt&&(qt.hidden=!0,jt=null,Dt=null)},Wt=!1,Gt=!0,Kt=NaN,Xt=NaN,Yt=!1,Zt=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Jt=()=>{clearTimeout(It),It=window.setTimeout(Rt,120)},Qt=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},te=(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},ee=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Qt(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?te(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&&Qt(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},ne=(t,e,n)=>{if(clearTimeout(It),jt===t&&Dt===e)return;const a=(t.type.tooltip??ee)(t,e,n);if(!a.length)return Rt();jt&&jt!==t&&Rt(),qt??(qt=(()=>{const t=document.createElement("div");return t.className=Vt,t.setAttribute("aria-hidden","true"),t.hidden=!0,wt=document.createElement("div"),(yt=document.createElement("div")).className=`${Vt}-arrow`,t.append(wt,yt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(It)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Jt()),document.addEventListener("pointerdown",e=>{const n=e.target;!jt||jt.plot.contains(n)||t.contains(n)||Rt()}),window.addEventListener("resize",Rt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${Vt}-line`,n){const t=document.createElement("span");t.className=`${Vt}-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=`${Vt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${Vt}-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,c=a.every(t=>t.name&&!t.value);wt.replaceChildren(...c?[]:[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 l=getComputedStyle(t.figure);for(const f of Pt){const t=l.getPropertyValue(f).trim();t?qt.style.setProperty(f,t):qt.style.removeProperty(f)}qt.style.setProperty("--_color",l.color),qt.style.colorScheme=l.colorScheme,qt.style.fontFamily=l.fontFamily;const i=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);qt.parentElement!==i&&i.append(qt),jt=t,Dt=e,qt.hidden=!1,qt.style.left="0px",qt.style.top="0px";const u=qt.getBoundingClientRect(),d={x:u.left,y:u.top,scale:Zt(qt,u.width)},h=Zt(t.plot,t.plot.getBoundingClientRect().width);qt.style.fontSize=Number.parseFloat(l.fontSize)*h/d.scale+"px",((t,e,n,a={x:0,y:0,scale:1},o=2,r=8,s=12)=>{const c=t.getBoundingClientRect(),l=c.width,i=c.height,u=Number.parseFloat(getComputedStyle(t).borderLeftWidth)||0,d=e.getBoundingClientRect().height/2+(o-u)*a.scale,h=s*a.scale,{clientWidth:f,clientHeight:m}=document.documentElement,b=n.top-r,$=m-n.bottom-r,p=i+d<=b||!(i+d<=$)&&b>=$,g=p?n.top-d-i:n.bottom+d,w=n.left+n.width/2,y=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(y-a.x)/a.scale+"px",t.style.top=(Math.max(r,Math.min(g,m-i-r))-a.y)/a.scale+"px",t.dataset.side=p?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/a.scale-u+"px"})(qt,yt,((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),d)},ae=t=>{jt===t&&Rt()},oe={area:kt,bar:ut,column:dt,donut:ft,line:xt,waterfall:At},re={"axis-break":V,trend:J,bracket:R,reference:Z},se=Object.keys(re),ce=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},le=["straight","step","smooth"],ie=(t,e,n,a,o)=>{const r=e===a,[s,c,l]=r?[Math.min(t,n),Math.max(t,n),e]:[Math.min(e,a),Math.max(e,a),t],i=o.filter(([t,e,n,a])=>r?e<=l&&l<=e+a:t<=l&&l<=t+n).map(([t,e,n,a])=>r?[t,t+n]:[e,e+a]).sort((t,e)=>t[0]-e[0]),u=[];let d=s;for(const[h,f]of i)h>d&&u.push([d,Math.min(h,c)]),d=Math.max(d,f);return d<c&&u.push([d,c]),u.map(([t,e])=>r?`M${H(t)},${H(l)}H${H(e)}`:`M${H(l)},${H(t)}V${H(e)}`).join("")},ue=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=C("path",{d:ie(n,a,o,r,e)});for(const{name:c,value:l}of Array.from(t.attributes))/^[xy][12]$/.test(c)||s.setAttribute(c,l);t.replaceWith(s)},de=(t,[e,n,a,o])=>t.map(([t,r,s,c])=>r===c?n<=r&&r<=n+o&&Math.max(t,e)<Math.min(s,e+a)?`M${H(Math.max(t,e))},${H(r)}H${H(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${H(t)},${H(Math.max(r,n))}V${H(Math.min(c,n+o))}`:"").join(""),he=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},fe=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),me=(t,e)=>{const n=t.dataset.chartShape;return n&&le.includes(n)?n:le.includes(e.shape)?e.shape:"straight"},be=0,$e=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=oe[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(oe).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=((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(Ht);return o.length||o.push(Ht(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}}))(t,e.langattribute);if(!c.length)return console.warn(t.querySelector("table")?`[${n}] A chart has no rows in its table, so there is nothing to draw.`:`[${n}] A chart has no table, so there is nothing to draw.`,t),t.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(ce(e)))continue;const t=document.createElement("span");t.className=$,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-"+ ++be),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)})(t);let l=((t,e,n="data-i18n")=>{const a=Ct(t),o=Math.max(1,P(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),group:!!o?.hasAttribute("data-group")};var r})})(t,c,e.langattribute);l.length>1&&!s.series&&!s.columns&&(console.warn(`[${n}] A ${r} chart uses only the first of its ${l.length} value columns.`),l=l.slice(0,1));const i=l.length>1;i&&t.style.setProperty("--_series-count",String(l.length));const h=t.hasAttribute("data-chart-stack");h&&!s.stackable&&console.warn(`[${n}] A ${r} chart cannot be stacked.`);const f=h&&!!s.stackable&&i,b=document.createElement("div");b.className="tablechart-plot",b.setAttribute("aria-hidden","true");const p=C("svg",{role:"presentation",focusable:"false"});b.appendChild(p),t.appendChild(b);const g=s.centre?c.filter(t=>!t.isTotal):c,w=Math.max(0,P(g.flatMap(t=>t.cells.slice(0,l.length).map(t=>q(t.number))))),v=l.map((t,e)=>Math.max(0,P(c.map(t=>q(t.cells[e]?.number??""))))),x=document.createElement("div");x.className="tablechart-values",b.appendChild(x);const k=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=L(a,x);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),i&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(v[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),!1===s.numbers&&(e||n)&&(r.dataset.place="none"),r})),N=k[0],A=f&&s.totals?c.map((t,e)=>{const n=L(a,x);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(at(t,l.length));const o=t.cells[0];return o.prefix&&(n.dataset.prefix=o.prefix),o.suffix&&(n.dataset.suffix=o.suffix),n.style.setProperty("--i",String(t.slot)),n}):[],S=c[c.length-1],H=l.some(t=>t.focus),T=t.getAttribute("data-chart-legend"),O=i&&!s.columns&&(null===T?e.legend||void 0!==s.legend:"false"!==T)?document.createElement("div"):null;O&&(O.className=d,O.setAttribute("aria-hidden","true"),O.inert=!0);const z=i&&!s.columns?l.map((n,a)=>{const o=L(u,O??b);O&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==me(t,e)){const t=bt(l,a);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return n.line&&!r&&(o.dataset.line=n.line),n.key&&e.langattribute&&o.setAttribute(e.langattribute,n.key),o.dataset.series=String(a+1),o.style.setProperty("--n",String(a)),o.style.setProperty("--palette",`var(--tablechart-color-${a+1})`),o.style.setProperty("--m",H&&!n.focus?"1":"0"),o.style.setProperty("--i",String(S.slot)),o}):[],E=s.centre?L(m,b):null;if(E){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);E.dataset.value=String(e),t&&(E.dataset.decimals=String(q(t.number)))}const B=E&&!c.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})(t,E,e):null,U="beside"===s.categories,_=document.createElement("div");_.className="tablechart-categories",_.setAttribute("aria-hidden","true"),_.inert=!0,U?_.dataset.place="beside":s.centre&&(_.dataset.place="key"),_.style.setProperty("--_columns",String(c.length));let F=0;for(const[n,a]of c.entries()){const t=document.createElement("span");t.classList.add(...a.classes),t.textContent=a.label,a.key&&e.langattribute&&t.setAttribute(e.langattribute,a.key),s.centre&&(t.dataset.kind=a.isTotal?"total":"slice",a.isTotal||(t.dataset.slice=String(F+1),t.style.setProperty("--n",String(F)),t.style.setProperty("--palette",`var(--tablechart-color-${F+1})`),F+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),_.appendChild(t)}(U?b:t).appendChild(_),O&&t.appendChild(O);const V=l.filter(t=>!t.group),j=!s.axes&&!s.centre&&he(t,"data-chart-axis",e.axis),D=s.axes?{titles:V.slice(0,2).map((t,n)=>{const a=L(`${y}-title`,b);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:L(`${M}s`,b),numbers:!0}:j||!s.centre&&he(t,"data-chart-grid",e.grid)?{titles:[],ticks:L(`${M}s`,b),numbers:j}:null;s.text?.({figure:t,plot:b,rows:c,series:l,config:e});const I=fe(t,e)&&!s.axes?(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=>Ut.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"),m=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]++}}),b=Math.max(-1,...m.map(t=>t.step??-1));if(b>=0)for(const[w,y]of n.entries())f(y)&&(m[w]={step:b,slot:i[b]++});const $=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),p=s.map(t=>t.map(()=>({step:null,slot:0}))),g=Math.max(0,...s.map(t=>t.length));for(let w=0;w<g;w++)for(const[t,e]of s.entries()){const n=e[w];if(!n||!r(n))continue;const a=u(n.getAttribute("data-fragment-index"));p[t][w]={step:a,slot:i[a]++}}return{rows:m,series:$,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",m.length-1)]:[0,m.length-1];let o=null;for(let r=Math.min(n,a);r<=Math.max(n,a);r++)for(const t of[m[r]?.step??null,...(p[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=$[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?m.length:m.filter(t=>t.step===o).length;return{step:o,after:c}}),count:c.length,indexes:c}})(t):null;s.axes&&t.querySelector("[data-fragment]")&&St.log(`A ${r} chart has no steps, so it is shown whole.`,t),I&&t.setAttribute("data-steps","");const R=t.getAttribute("data-chart-keys"),W=I&&e.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=C("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(C("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=$,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:e.previouslabel,next:e.nextlabel,hint:e.stephint},{previous:R&&`${R}-previous`,next:R&&`${R}-next`,hint:R&&`${R}-step`},e.langattribute):null;W&&t.appendChild(W);const G=t.getAttribute("data-chart-table"),K=G&&ge.includes(G)?G:e.table;if("never"===K)t.removeAttribute("data-table");else{t.setAttribute("data-table",K);const e=t.querySelector(":scope > table");e&&t.append(e)}const X=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),a=re[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(re).join(", ")}.`),null;const o=Number.parseInt(t.getAttribute("data-series")??"1",10),r=o>=1&&o<=l.length?o-1:0;return o!==r+1&&console.warn(`[${n}] An annotation reads line ${o}, which is not there; it reads line 1.`),{spec:t,type:a,badge:a.create(t,b),series:r,after:c.length}}).filter(t=>null!==t);fe(t,e)&&t.setAttribute("data-animate",we(t,r,e,Boolean(I)));const Y={figure:t,plot:b,svg:p,rows:c,decimals:w,type:s,values:N,series:l,seriesValues:k,names:O?[]:z,categories:Array.from(_.children),centre:E,axes:D,stacked:f,totals:A,totalCell:B,rowAt:null,rowBox:null,annotations:X,checks:[],plan:I,step:0,controls:W},Z=()=>Ae(t,p);p.addEventListener("transitionend",Z),p.addEventListener("transitioncancel",Z),W?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&Ft(Y,Y.step+("next"===e?1:-1))}),Ft(Y,0,!0);const J=t.getAttribute("data-chart-tooltip"),Q="false"!==J&&("auto"===J?"auto":null!==J||e.tooltip);return Q&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(Yt)return;Yt=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(Gt=t.screenX!==Kt||t.screenY!==Xt,Kt=t.screenX,Xt=t.screenY,Gt&&(Wt=!1))},{capture:!0,passive:!0});const t=()=>{Wt=!0,Rt()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!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)Wt=!1;else if("mouse"===o.pointerType&&(!Gt||Wt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return jt===t?Rt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Zt(a,n.width);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 jt===t?Rt():void 0;ne(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)||Wt||ne(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,jt===t&&Jt())})})(Y,e,"auto"===Q),xe(Y,e),Y},pe={grow:"grow",sweep:"sweep"},ge=["never","auto","print","always"],we=(t,e,n,a)=>{const o="line"===e||"area"===e,r=pe[t.getAttribute("data-chart-animate")??""]??pe[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},ye=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},Me=(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*x:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},ve=(t,e)=>Me(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,xe=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const a of t.centre?[...n,t.centre]:n)void 0!==a.dataset.missing?a.textContent=a.dataset.missing:ke(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},ke=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=((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("")]})(Number.parseFloat(t.dataset.value||"0"),e,n);if(t.textContent=a+(a?r:"")+s+o,r&&!a){const e=document.createElement("span");e.className="tablechart-minus",e.textContent=r,t.prepend(e)}},Ne=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||Se(t.svg),n)return t.figure.classList.add(w),t.figure.classList.toggle(p,e),t.figure.offsetWidth,e&&He(t.svg),void requestAnimationFrame(()=>t.figure.classList.remove(w));t.figure.classList.toggle(p,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>Ae(t.figure,t.svg)))},Ae=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&He(e)},Se=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},He=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},Ce=t=>"id"===t||"style"===t||t.startsWith("data-chart"),Te=/^\s*(?:Table)?:\s+/,Le=t=>"P"===t?.tagName&&Te.test(t.textContent??""),Oe=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,ze=t=>{const e=Be(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},Be=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},Ue="strong, b, span.total",_e="data-chart-made",Fe=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,Ve=new Set,Pe=null,qe=["column","bar"],je=t=>{const e=t.getAttribute("data-chart")||"column";if(!qe.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return qe.includes(n)?n:e},De=!1,Ie=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=Le(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||Ce(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?Le(r)?r:Le(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=ze(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Oe.exec(e.textContent??"");if(!n||!se.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=ze(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(Te,""),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),St?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(_e)));return(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!De&&e&&(De=!0,console.warn(`[${n}] A chart is a <${e.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`,e))})(a),await(async t=>{await Promise.all(t.filter(t=>t.hasAttribute("data-chart-src")).map(async t=>{const e=t.getAttribute("data-chart-src"),a=Array.from(t.querySelectorAll("table")).find(t=>t.tHead)??null;for(const n of t.querySelectorAll("table"))n!==a&&n.remove();try{const n=await fetch(e);if(!n.ok)throw new Error(`${n.status} ${n.statusText}`);const o=await n.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 e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||St?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),St?.log?.(`Read ${r.length} rows from "${e}"`)}catch(o){const t="file:"===window.location.protocol;console.warn(`[${n}] Could not read the chart data in "${e}": ${o.message}.`+(t?" 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=Be(e);a?.matches(Ue);a=Be(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=Be(e);t?.matches(Ue);t=Be(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(a),((t,e)=>{if(!e)return;const a=new Map;for(const o of t){let t=o.getAttribute("data-chart-keys")||null;if(!t)continue;if(a.has(t)){const e=a.get(t)+1;a.set(t,e),console.warn(`[${n}] Two charts have data-chart-keys="${t}", so this one uses "${t}-${e}" to keep their translations apart.`),t=`${t}-${e}`}else a.set(t,1);o.querySelectorAll("tbody th").forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-row${a+1}`)});const r=Ct(o);r.length>1&&r.forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-col${a+1}`)}),r.forEach((n,a)=>{if(!n.hasAttribute("data-group"))return;const r=[];o.querySelectorAll(`tbody tr > td:nth-of-type(${a+1})`).forEach(n=>{const a=(n.textContent||"").trim();r.includes(a)||r.push(a),n.getAttribute(e)||n.setAttribute(e,`${t}-group${r.indexOf(a)+1}`)})}),St?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute),a},Re=(t,e)=>{const a=St.timed("Building",t,()=>$e(t,e));return a?(t.setAttribute(_e,""),((t,e)=>{let a=t,r=je(a.figure),u=null,h=!1,b=!1;const $=async()=>{if(!fe(a.figure,e))return Ne(a,!0);const t=a.figure.classList.contains("is-shown");if(!h||null===u||t||b)!h&&e.replay&&t&&Ne(a,!1);else{b=!0;const t=Fe()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(a.figure);t&&await(n=t,new Promise(t=>{const e=["animationstart","transitionrun"],a=()=>{for(const t of e)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(n)&&a()},r=new MutationObserver(()=>{"0"!==getComputedStyle(n).opacity&&a()});for(const n of e)document.addEventListener(n,o,!0);r.observe(n,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(Fe())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)))})(a.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)})(a.figure,e)),b=!1,!h&&e.replay||Ne(a,!0)}var n},p=()=>{const t=je(a.figure);if(!t||t===r)return;const n=St.timed("Building",a.figure,()=>$e(a.figure,e,t));n&&((t=>{ae(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${d}`)?.remove(),t.controls?.remove()})(a),Ft(n,a.step,!0),a=n,r=t,u=null)},w=()=>{p();const t=a.plot.clientWidth;t&&t!==u&&St.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:u,type:d,values:h,series:b,seriesValues:$,names:p,annotations:g}=t,w=Number.parseFloat(t.figure.dataset.chartAspect??""),k=w>0?w:d.aspect??e.aspect,N="beside"===d.categories,S=t.axes&&!d.axes?t.axes:null,T=N?null:t.categories[0]?.parentElement;let z=null;if(S){a.style.margin="",T&&(T.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=d.segments?.(u)??[],r=t.stacked?u.flatMap(t=>Object.values(nt(t,b.length,d.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):u.flatMap(t=>t.cells.slice(0,b.length).filter(t=>!t.missing).map(t=>t.value)),s=Math.min(0,-P(r.map(t=>-t))),c=Math.max(0,P(r)),l=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:i,chartScale:h}=t.figure.dataset,f=Et(i??h);if(f&&f.length>2)z={min:f[0],max:f[f.length-1],step:0,ticks:f};else{const[t,e]=f??[s,c],a=Lt(e-t,Math.max((N?n/9:n*k/3)/l,2)),o=(t,e)=>f?t:Number(((e?Math.ceil:Math.floor)(t/a-1e-9*(e?1:-1))*a).toPrecision(12)),r=o(t,!1),i=o(e,!0);z={min:r,max:i,step:a,ticks:Ot(r,i,a)}}S.ticks.textContent="";const m=u.find(t=>!t.missing),$=P(z.ticks.map(t=>q(String(t))));for(const t of z.ticks){const n=L(M,S.ticks);n.dataset.value=String(t),n.dataset.place="none",m?.prefix&&(n.dataset.prefix=m.prefix),m?.suffix&&(n.dataset.suffix=m.suffix),ke(n,$,e.locale)}if(S.numbers){const t=Array.from(S.ticks.children);for(const e of t)delete e.dataset.place;K(t),N?a.style.marginBottom=`${(t[0]?X(t[0]).height:0)+6}px`:(a.style.marginLeft=`${P([0,...t.map(t=>X(t).width)])+10}px`,T&&(T.style.marginLeft=a.style.marginLeft))}}const F=a.clientWidth;if(!F)return!1;const V=x/F,j=x*k;a.classList.add("is-placed");const D=!1===d.numbers?h.slice(0,1):[...$.flat(),...t.totals];for(const n of D)delete n.dataset.place;a.style.removeProperty("--_fit"),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const I=d.axes?t.axes:null;let R=[];if(I){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=b.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=u.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:s,chartScaleY:c,chartScale:l}=t.figure.dataset,i=[Et(s),Et(c??l)];R=o.map((t,e)=>((t,e,n)=>{if(n&&n.length>2)return{min:n[0],max:n[n.length-1],step:0,ticks:n};let a=n?.[0]??-P(t.map(t=>-t)),o=n?.[1]??P(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=Lt(o-a,e);return{min:a,max:o,step:r,ticks:Ot(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?j/V/(4*n):F/(9*n),4),i[e])),I.ticks.textContent="",R.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=P(t.ticks.map(t=>q(String(t))));for(const o of t.ticks){const t=L(M,I.ticks);t.dataset.axis=n?"y":"x",t.dataset.value=String(o),a?.prefix&&(t.dataset.prefix=a.prefix),a?.suffix&&(t.dataset.suffix=a.suffix),ke(t,s,e.locale)}})}const W=I?Array.from(I.ticks.children):[];K([...$.flat(),...t.totals,...p,...t.categories,...g.map(t=>t.badge),...I?.titles??[],...W]);const G=(h[0]?X(h[0]).height:0)*V;!1===d.numbers&&h[0]&&(h[0].dataset.place="none");const Y=g[0]?.badge?X(g[0].badge).height*V:0,Z=Math.max(j,Me(t.figure,V,"--tablechart-min-height","200px")??0,d.minHeight?.({labelHeight:G,nameHeight:Math.max(0,P(t.categories.map(t=>X(t).height)))*V,unit:V,rows:u.length,series:b.length,stacked:t.stacked})??0),J=t.stacked?u.map(t=>{const e=at(t,b.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):u,Q=(d.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?J.map(t=>({...t,cells:[t.cells[0]]})):u),tt={labelHeight:G,badgeHeight:Y,hasAnnotations:g.length>0,unit:V,series:b.length,focused:b.some(t=>t.focus),stacked:t.stacked},et=Math.max((ot=P,t.stacked?ot(u.map(t=>nt(t,b.length,d.running).top)):ot([...Q.flatMap(t=>[t.from,t.to,t.value]),...u.flatMap(t=>t.cells.slice(0,b.length).map(t=>t.value))])),0);var ot;const rt=Q.some(t=>"up"===t.kind||"down"===t.kind)?Q.flatMap(t=>[t.from,t.to]):t.stacked?u.map(t=>nt(t,b.length,d.running).bottom):u.flatMap(t=>t.cells.slice(0,b.length).map(t=>t.value)),st=Math.min(-P(rt.map(t=>-t)),0),ct=d.headroom?.(tt)??G,lt=2*V+(d.footroom?.(tt)??0)+(st<0?G+4*V:0),ut=Z-ct-lt,dt=z?Math.max(z.max,et):1.02*et,ht=z?Math.min(z.min,st):1.02*st,ft=g.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,mt=t=>{const e=Number.parseFloat(ft?.getAttribute(t)??"");return Number.isFinite(e)?e:null},bt=mt("data-from")??mt("data-at"),$t=mt("data-to");let pt=null;if(ft&&(null!==bt||null!==$t)){const t=bt??0,e=$t??dt,a=null===$t?t:null===bt?e:(t+e)/2,o=ft.getAttribute("data-size"),r=o?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===o||r||console.warn(`[${n}] 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===$t?.22:.3,.05),.8),c=Q.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);d.breakable?st<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>dt||0===t&&e===dt?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${et}.`):c.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):pt={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const gt=pt?pt.gap:null,wt=(pt&&Me(t.figure,V,"--tablechart-break-gap",""))??13,yt=Z-lt,Mt=dt-ht||1;let vt,xt,kt=t=>yt-(t-ht)/Mt*ut;if(pt){const{lo:t,hi:e,gap:n,share:a}=pt,o=ut*a,r=(ut-o-wt)/(t+(dt-e)),s=o/(e-t);kt=a=>a<=t?yt-a*r:a<=n?yt-t*r-(a-t)*s:a<=e?yt-t*r-(a-t)*s-wt:yt-t*r-o-wt-(a-e)*r}let Nt=[];if(I){const t=6*V,[e,n]=I.titles,a=t=>t?X(t).width*V:0,o=t=>t?X(t).height*V:0,r=W.filter(t=>"x"===t.dataset.axis),s=W.filter(t=>"y"===t.dataset.axis),c=o(W[0]),l=a(n)+P([0,...s.map(a)])+2*t,i=c/2;xt=[l,i,x-l-P([0,...r.map(a)])/2,Z-i-o(e)-c-2*t];const[u,d,h,f]=xt,[m,b]=R,$=t=>u+(t-m.min)/(m.max-m.min||1)*h,p=t=>d+f-(t-b.min)/(b.max-b.min||1)*f;vt=$,kt=p;const g=t=>a(r.find(e=>Number(e.dataset.value)===t));Nt=[Bt(m,e=>e.every((n,a)=>!a||$(n)-$(e[a-1])>(g(n)+g(e[a-1]))/2+t)).ticks,Bt(b,e=>e.every((n,a)=>!a||p(e[a-1])-p(n)>c+t/2)).ticks];for(const w of W){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,a=Nt[n].includes(e);w.dataset.place=a?n?"before":"below":"none",a&&O(w,n?u-t:$(e),n?p(e):d+f+t,x,Z)}e&&O(e,u+h/2,Z-o(e),x,Z),n&&O(n,0,d+f/2,x,Z)}const At=p.length?P(p.map(t=>X(t).width))*V+12*V:0,St=t.categories[0]?.parentElement;St&&(St.style.paddingRight=At?At/x*100+"%":"");const Ht=(x-At)/u.length,Ct=t=>t>=0&&t<u.length?t:null;t.rowAt=d.centre?null:"beside"===d.categories?(t,e)=>Ct(Math.floor(e*V/(Z/u.length))):t=>Ct(Math.floor(t*V/Ht));const Tt=Ht/x*100,zt=100/u.length;if(t.rowBox="beside"===d.categories?t=>[0,t*zt,100,zt]:t=>[t*Tt,0,Tt,100],r.setAttribute("viewBox",`0 0 1000 ${H(Z)}`),r.textContent="",xt&&vt){const[n,a,o,s]=xt,[c,l]=Nt,i=vt;he(t.figure,"data-chart-grid",e.grid)&&r.appendChild(C("path",{class:v,d:[...c.map(t=>`M${H(i(t))},${H(a)}V${H(a+s)}`),...l.map(t=>`M${H(n)},${H(kt(t))}H${H(n+o)}`)].join("")})),r.appendChild(C("path",{class:y,d:[`M${H(n)},${H(a)}V${H(a+s)}H${H(n+o)}`,...c.map(t=>`M${H(i(t))},${H(a+s)}v${H(4*V)}`),...l.map(t=>`M${H(n)},${H(kt(t))}h${H(-4*V)}`)].join("")}))}t.checks=[];const Ut={rows:u,segments:Q,cx:t=>(t+.5)*Ht,y:kt,x:vt,frame:xt,length:(e,n)=>Me(t.figure,V,e,n),barWidth:Math.min(Ht*e.barfill,ve(t.figure,V)),barMax:ve(t.figure,V),height:Z,unit:V,labelHeight:G,badgeHeight:Y,after:u.length,note:0,labels:"inside"===t.figure.dataset.chartLabels||"outside"!==t.figure.dataset.chartLabels&&"inside"===e.labels?"inside":"outside",insideAlign:ye(t.figure),breakAt:gt,squeeze:pt,breakGap:wt,domain:z?[z.min,z.max]:null,stacked:t.stacked,shape:me(t.figure,e),totals:t.totals,svg:r,plot:a,values:h,series:b,seriesValues:$,names:p,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[]};if(a.style.setProperty("--count",String(Math.max(1,...u.map(t=>t.slot+1)))),d.draw(Ut),Ut.rowAt&&(t.rowAt=Ut.rowAt),S&&z){const n=6*V,a=N&&Ut.x?Ut.x:kt,o=Array.from(S.ticks.children),s=t=>X(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Bt(z,t=>t.every((e,o)=>!o||(N?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*V+n:a(t[o-1])-a(e)>s(e).height*V+n/2))).ticks.filter(t=>!pt||t<=pt.lo||t>=pt.hi);for(const t of o){const e=Number(t.dataset.value),o=S.numbers&&c.includes(e);t.dataset.place=o?N?"below":"before":"none",o&&O(t,N?a(e):-n,N?Z+n:a(e),x,Z)}const l=x-At;he(t.figure,"data-chart-grid",e.grid)&&r.prepend(C("path",{class:v,d:c.map(t=>N?`M${H(a(t))},0V${H(Z)}`:`M0,${H(a(t))}H${H(l)}`).join("")})),S.numbers&&r.appendChild(C("path",{class:y,d:[N?`M${H(a(z.min))},${H(Z)}H${H(a(z.max))}`:`M0,${H(a(z.max))}V${H(a(z.min))}`,...c.map(t=>N?`M${H(a(t))},${H(Z)}v${H(4*V)}`:`M0,${H(a(t))}h${H(-4*V)}`)].join("")}))}for(const[n,o]of g.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series,r=t=>({...t,...t.cells[e]??t.cells[0]});o.type.draw(o.spec,o.badge,{...Ut,...t.stacked&&{rows:J,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&{rows:u.map(r),segments:Q.map(t=>{const e=r(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:$[e]},after:t.plan?o.after:Math.min(o.after,Number(a.style.getPropertyValue("--count"))||o.after),note:n+1})}(t=>{const e=t.plan;if(!e)return;const n=e.rows.length-1,a=t=>e.series.map((n,a)=>e.cells[t]?.[a]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=a(t);return e.some(t=>null===t)?null:Math.min(...e)},s=new Set(t.totals),c=(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 o of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(o.closest("table, .tablechart-controls")||o.hasAttribute("data-from"))continue;const t=Number(o.dataset.note);if(t>0){const n=e.notes[t-1];n&&c(o,n.step,"--after",n.after);continue}const l=o.dataset.row?Number(o.dataset.row)-1:n;if(o.classList.contains("tablechart-connector")){const t=e.rows[l-1],n=e.rows[l];if(t&&n){const e=(t.step??-1)>(n.step??-1);c(o,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(s.has(o)){const t=a(l).filter(t=>null!==t);c(o,t.length?Math.max(...t):null,"--i",e.rows[l]?.slot??0);continue}if(o.hasAttribute("data-stack")){c(o,r(l),"--i",e.rows[l]?.slot??0);continue}const i=o.dataset.series?Number(o.dataset.series)-1:0,u=o.dataset.series?e.series[i]:void 0;if(o.classList.contains("tablechart-piece")){const t=a(l)[i]??null,n=e.cells[l]?.[i];c(o,t===r(l)?null:t,"--i",n&&null!==n.step?n.slot:l);continue}if("legend"===o.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));c(o,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[l]?.[i];d&&null!==d.step?c(o,d.step,"--i",d.slot):u&&null!==u.step?c(o,u.step,"--i",l):e.rows[l]&&c(o,e.rows[l].step,"--i",e.rows[l].slot)}const l=t.figure.querySelector(`.${m}`);if(l){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?c(l,null,"--i",0):c(l,n,"--i",t.filter(t=>t===n).length)}const u=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),d=e.series.some(t=>null!==t.step)?e.rows.length:1;t.plot.style.setProperty("--count",String(Math.max(d,...u)));const h=t.figure.querySelectorAll(`.${o}`),f=h[h.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===f?.dataset.kind&&h.length>1){const t=Number(f.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(f.dataset.grow="down"===f.dataset.grow?"up":"down")}const b=Array.from(t.figure.querySelectorAll(`.${i}`));if(b.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=b.length,o=Math.max(0,b.findIndex((t,n)=>e(t)!==e(b[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=b[(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??"",A(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))}}_t(t)})(t);const Ft=t.categories[0]?.parentElement;Ft&&"beside"!==d.categories&&!d.centre&&it(Ft,t.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const Vt=g.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*V,n=t.offsetHeight*V,a=Number.parseFloat(t.style.left)/100*x,o=Number.parseFloat(t.style.top)/100*Z,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*V;return[C("rect",{class:f,"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("; ")})]}),Pt=r.querySelector(`.${v}`),qt=Array.from(r.querySelectorAll(`.${c}`));if(Pt||qt.length){const e=a.getBoundingClientRect(),n=x/e.width,o=getComputedStyle(a),s=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2,c=[...$.flat(),...t.totals,..."beside"===d.categories?t.categories:[]].flatMap(t=>{if("none"===t.dataset.place||t.hidden||t.hasAttribute("data-left-out"))return[];const a=t.getBoundingClientRect(),o=a.height*n/s,r=Array.from(t.style).filter(t=>t.startsWith("--")).map(e=>`${e}:${t.style.getPropertyValue(e)}`);return a.width?[C("rect",{class:f,"data-for":"text",x:(a.left-e.left)*n-3*V,y:(a.top-e.top)*n+(a.height*n-o)/2-V,width:a.width*n+6*V,height:o+2*V,style:r.join("; ")})]:[]}),l=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of qt)ue(t,[...c,...Vt].map(l));if(Pt&&t.plan)_(r,c,x,Z,[Pt]);else if(Pt){const t=[...c,...Vt],e=(jt=Pt,Array.from((jt.getAttribute("d")??"").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g),([,t,e,n,a])=>"H"===n?[+t,+e,+a,+e]:[+t,+e,+t,+a]));Pt.setAttribute("d",e.map(([e,n,a,o])=>ie(e,n,a,o,t.map(l))).join(""));for(const n of t){const t=de(e,l(n)),a="badge"===n.dataset.for?"badge":"";t&&Pt.after(C("path",{class:v,"data-gap":a,d:t,style:n.getAttribute("style")??""}))}}}var jt;((t,e,n,a,o)=>{if(!e.length||!o.length)return;const r="tablechart-clip-"+ ++E,s=C("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M-1000,${-a}h3000v${3*a}h-3000z`;s.appendChild(C("path",{d:c+e.map(U).join(""),"clip-rule":"evenodd"})),B(t).appendChild(s);for(const l of o)l.setAttribute("clip-path",`url(#${r})`)})(r,Vt,0,Z,Array.from(r.querySelectorAll(`.${s}, .${l}`)));const Dt=[c,s,l,...t.plan?[]:[v]];_(r,Vt,x,Z,void 0,Dt.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||Se(r);const It=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(d.columns?[t.categories]:[...$,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||d.centre&&u[Number(t.dataset.row)-1]?.isTotal)(e)&&!It(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>It(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(a,e))&&(u=t,$())};let k=!1;const N=new ResizeObserver(()=>{k||(k=!0,requestAnimationFrame(()=>{k=!1,w()}))}),S=new IntersectionObserver(t=>{for(const e of t)h=e.isIntersecting,$()},{threshold:e.threshold}),T=()=>{a.figure.classList.add(g),Ne(a,!0),He(a.svg),a.figure.offsetWidth},z=()=>a.figure.classList.remove(g),F=()=>{u=null,w()},V={relabel:()=>xe(a,e),refresh:F};p(),w(),N.observe(a.figure),S.observe(a.figure),window.addEventListener("beforeprint",T),window.addEventListener("afterprint",z),(t=>{Ve.add(t),Pe||(Pe=new MutationObserver(()=>{for(const t of Ve)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of Ve)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(V);const j={figure:a.figure,refresh:F,next:()=>Ft(a,a.step+1),previous:()=>Ft(a,a.step-1),stepTo:t=>Ft(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){N.disconnect(),S.disconnect(),window.removeEventListener("beforeprint",T),window.removeEventListener("afterprint",z),(t=>{Ve.delete(t),!Ve.size&&Pe&&(Pe.disconnect(),Pe=null)})(V),ae(a),a.figure.tablechart===j&&delete a.figure.tablechart}};return a.figure.tablechart=j,j})(a,e)):null},We=e({LEGEND_CLASS:()=>d,NAME_CLASS:()=>u,POINT_CLASS:()=>h,VIEWBOX_WIDTH:()=>x,avoidCollisions:()=>W,htmlEl:()=>L,largest:()=>P,markerEl:()=>$t,placeAt:()=>O,short:()=>H,sizeOf:()=>X});window.Tablechart={init:async(t={},e=document)=>{const n={...k,...t};n.debug&&(St.enabled=!0);const a=(await Ie(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Re(t,n)).filter(t=>null!==t);return St.log(`Made ${a.length} chart(s).`),{charts:a,refresh:()=>{for(const t of a)t.refresh()},destroy:()=>{for(const t of a)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...k,...e};n.debug&&(St.enabled=!0);const[a]=await Ie([t],n);return a?Re(a,n):null},defaultConfig:k,addType:(t,e)=>{oe[t]=e},kit:We}}();
|
package/dist/tablechart.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { c as addType, t as create,
|
|
1
|
+
export { c as addType, t as create, N as defaultConfig, r as init } from "./tablechart-shared.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@martinomagnifico/tablechart",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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": [
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"README.md",
|
|
32
32
|
"CHANGELOG.md"
|
|
33
33
|
],
|
|
34
|
+
"workspaces": [
|
|
35
|
+
"docs"
|
|
36
|
+
],
|
|
34
37
|
"scripts": {
|
|
35
38
|
"start": "cd docs && npm start",
|
|
36
39
|
"dev": "vite",
|
|
@@ -45,8 +48,7 @@
|
|
|
45
48
|
"test": "npm run build && node test/speed.test.mjs",
|
|
46
49
|
"test:layout": "node test/layout.test.mjs",
|
|
47
50
|
"prepack": "npm run build",
|
|
48
|
-
"clean": "rm -rf dist"
|
|
49
|
-
"setup": "cd docs && npm install"
|
|
51
|
+
"clean": "rm -rf dist"
|
|
50
52
|
},
|
|
51
53
|
"keywords": [
|
|
52
54
|
"chart",
|
|
@@ -74,5 +76,10 @@
|
|
|
74
76
|
"allowScripts": {
|
|
75
77
|
"@parcel/watcher": false,
|
|
76
78
|
"fsevents": false
|
|
79
|
+
},
|
|
80
|
+
"overrides": {
|
|
81
|
+
"vite-plugin-static-copy": {
|
|
82
|
+
"chokidar": "^4.0.3"
|
|
83
|
+
}
|
|
77
84
|
}
|
|
78
85
|
}
|