@martinomagnifico/tablechart 1.1.3 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +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-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}}();
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-quadrant",i="tablechart-head",u="tablechart-slice",d="tablechart-series",h="tablechart-area",f="tablechart-name",b="tablechart-legend",m="tablechart-point",$="tablechart-hole",p="tablechart-centre",g="tablechart-break",w="tablechart-sr",y="is-shown",M="is-printing",v="is-at-once",x="tablechart-axis",k="tablechart-tick",N="tablechart-grid",S=1e3,A={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",values:"auto",ticks:!0,shape:"straight",legend:!1,axis:!1,grid:!1,names:!0,tooltip:"auto",tooltipparent:null,table:"never",tablelimit:15,summary:"auto",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},C="cubic-bezier(0.3, 0.3, 0.6, 1)",H=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?C:"linear"}),T=(t,e)=>`${t}:${e}`,L=t=>Math.round(100*t)/100,O=(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?L(t):t))}return n},_=(t,e)=>[t,...e.classes].join(" "),B=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},E=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},z=0,U=0,F=t=>{let e=t.querySelector(":scope > defs");return e||(e=O("defs"),t.prepend(e)),e},V=t=>{if("circle"===t.tagName){const[e,n,a]=["cx","cy","r"].map(e=>Number(t.getAttribute(e))||0);return`M${L(e-a)},${L(n)}a${L(a)},${L(a)} 0 1 0 ${L(2*a)},0a${L(a)},${L(a)} 0 1 0 ${L(-2*a)},0z`}if("polygon"===t.tagName)return`M${(t.getAttribute("points")??"").trim().split(/\s+/).join("L")}z`;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${L(c)},${L(l)} 0 0 1 ${L(t)},${L(e)}`:"";return`M${L(e+c)},${L(n)}h${L(a-2*c)}${i(c,l)}v${L(o-2*l)}${i(-c,l)}h${L(2*c-a)}${i(-c,-l)}v${L(2*l-o)}${i(c,-l)}z`},R=(t,e,n,a,o)=>{if(!e.length||!o.length)return;const r="tablechart-clip-"+ ++U,s=O("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M${-n},${-a}h${3*n}v${3*a}h${3*-n}z`;s.appendChild(O("path",{d:c+e.map(V).join(""),"clip-rule":"evenodd"})),F(t).appendChild(s);for(const l of o)l.setAttribute("clip-path",`url(#${r})`)},q=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++z,c=O("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(O("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=F(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(O("g",{mask:`url(#${s})`}))),i.appendChild(u)))},I=0,j={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-"+ ++I,h=O("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(O("rect",{x:-1e3,y:-n.height,width:3e3,height:3*n.height,fill:"white"}));const f=[],b=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:b;if(void 0===t)continue;if(!(w.sideways?w.x<t&&w.x+w.width>t:w.y<b&&w.y+w.height>b))continue;const[e,o]=w.sideways?[i(w,t),i(w,t+n.breakGap)]:[i(w,b-n.breakGap),i(w,b)];h.appendChild(O("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[T("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(O("path",{class:g,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const m=Array.from(s.querySelectorAll(`.${g}`)),$=O("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))m.includes(o)||$.appendChild(o);const p=O("defs");p.appendChild(h),s.prepend(p,$)}},P=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},D=t=>(t.split(/[.,]/)[1]||"").length,W=(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("")]},G=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),K=(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},Y=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=G(s),l=r?.5:.5*10**-D(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.`)},X={create:K,draw(t,e,a){const{rows:o,cx:r,y:c,unit:l,labelHeight:u,badgeHeight:d,height:h,svg:f,after:b}=a,[m,$]=((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[m],g=o[$];if(!p||!g)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${m+1} to ${$+1}, of ${o.length}).`);const w=7*l,y=4*l,M=r(m),v=r($),x=Math.min(c(p.value),c(g.value))-u-y-.9*d,k=t=>c(t)-u-y,N=`M ${M} ${k(p.value)} L ${M} ${x} L ${v} ${x} L ${v} ${k(g.value)-w}`,A=(k(p.value)-x+Math.abs(v-M)+(k(g.value)-w-x))/l+1;f.appendChild(O("path",{class:s,"data-note":a.note,d:N,style:`--len:${A.toFixed(1)}; ${T("--after",b)}`}));const C=k(g.value);var H;f.appendChild(O("polygon",{class:i,"data-note":a.note,points:`${v},${C} ${v-.45*w},${C-w} ${v+.45*w},${C-w}`,style:T("--after",b)})),e&&(E(e,(M+v)/2,x,S,h),e.style.setProperty("--after",String(b))),Y(e,(H=p.value,(g.value-H)/Math.abs(H)*100),`${p.value} to ${g.value}`,a)}},Z=(t,e)=>t[0]<e[0]+e[2]&&e[0]<t[0]+t[2]&&t[1]<e[1]+e[3]&&e[1]<t[1]+t[3],Q=(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=>Z(t,e)));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},J=new WeakMap,tt=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]))},et=t=>J.get(t)??{width:t.offsetWidth,height:t.offsetHeight},nt=(t,e,n)=>t.some(t=>et(t).width*n>e-6*n),at=(t,e,n)=>e>=et(t).height*n*1.6,ot=(t,e,n)=>e>=et(t).width*n*1.5,rt=(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},st={outside:[.5,1],below:[.5,0],after:[0,.5],before:[1,.5]},ct=(t,e,n,a,o=[.5,.5])=>{const[r,s]=st[t.dataset.place??""]??o,{width:c,height:l}=et(t);return[Number.parseFloat(t.style.left)/100*n-c*e*r,Number.parseFloat(t.style.top)/100*a-l*e*s,c*e,l*e]},lt=(t,e,n)=>{for(const a of t){if("none"===a.dataset.place||!a.style.left)continue;const[t]=st[a.dataset.place??""]??[.5,.5],o=et(a).width*e,r=Number.parseFloat(a.style.left)/100*n,s=Math.min(Math.max(r,o*t),n-o*(1-t));s!==r&&(a.style.left=s/n*100+"%")}},it=(t,e,n,a)=>{const o=t.filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out")),r=ut(o,e,n,a);o.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")})},ut=(t,e,n,a)=>{if(t.length<2)return 1;const o=t.map(t=>ct(t,e,n,a)),r=2*e;let s=1;for(;s<t.length&&o.some((t,e)=>{return e>=s&&e%s===0&&(a=t,!((n=o[e-s])[0]+n[2]+r<=a[0]||a[0]+a[2]+r<=n[0]||n[1]+n[3]<=a[1]||a[1]+a[3]<=n[1]));var n,a});)s++;return s},dt={create(t,e){if(!t.textContent?.trim())return null;const n=K(t,e);return n.dataset.kind="note",n},draw(t,e,a){const{rows:o,cx:r,y:s,height:l,unit:i,svg:u,after:d,seriesValues:h}=a;if(a.x||a.centre||"beside"===a.categories[0]?.parentElement?.dataset.place)return void console.warn(`[${n}] A note works on a chart with its rows across, such as a line or column chart.`);const f=(t.getAttribute("data-row")??"").trim(),b=/^\d+$/.test(f)?Number(f)-1:o.findIndex(t=>t.label===f);if(b<0||b>=o.length)return void console.warn(`[${n}] A note is for row "${f}", which is not there.`);const $=r(b),p=s(0);if(u.insertBefore(O("line",{class:c,"data-kind":"note","data-note":a.note,x1:$,x2:$,y1:0,y2:p,style:T("--after",d)}),u.querySelector(`:scope > .${m}`)),!e)return;const g=et(e).width*i,w=et(e).height*i,y=4*i,M=h.flat().flatMap(t=>!t.style.left||"none"===t.dataset.place||t.hasAttribute("data-left-out")?[]:[{label:t,box:ct(t,i,S,l)}]),v=[0,w+y/2].flatMap(t=>[[$-g/2,t,g,w],[$+y,t,g,w],[$-y-g,t,g,w]]),[x]=Q([v],[...a.taken,...M.map(t=>t.box)],[0,0,S,l]),k=v[x??0];if(a.taken.push(k),E(e,k[0]+g/2,k[1]+w/2,S,l),e.style.setProperty("--after",String(d)),null===x)for(const n of M)Z(n.box,k)&&n.label.setAttribute("data-left-out","")}},ht=(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},ft={create(t,e){if(!t.textContent?.trim())return null;const n=K(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:h}=a,f=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=f.map(t=>G(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=ht($,t,f.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[f[s],f[s+1]??f[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=ht($,f.map(t=>t.cells[n]?.value??t.value),f.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,x]=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):S,l?i:s(0)];if(d.insertBefore(O("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:x},style:T("--after",h)}),d.querySelector(`:scope > .${m}`)),e){const t=et(e).width*u,n=et(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]=Q([r],a.taken,[0,0,S,i]),c=r[s??0];a.taken.push(c),E(e,c[0]+t/2,c[1]+n/2,S,i),e.style.setProperty("--after",String(h)),"mean"!==$&&"median"!==$||Y(e,w,`the ${$}`,a,"")}}},bt={create:K,draw(t,e,n){const{rows:a,cx:o,y:r,unit:c,labelHeight:l,height:u,svg:d,values:h,after:f}=n,b=a[0],m=a[a.length-1];if(!b||!m)return;const $=l+18*c,p=10*c,g=10*c;let w=o(0),y=r(b.value)-$,M=o(a.length-1),v=r(m.value)-$,x=0;a.forEach((t,e)=>{const n=M===w?0:(o(e)-w)/(M-w),a=y+n*(v-y)-(r(t.value)-$);a>x&&(x=a)}),y-=x,v-=x;const k=M-w,N=v-y,A=Math.hypot(k,N)||1,C=k/A,H=N/A;w-=C*p,y-=H*p,M+=C*p,v+=H*p;const L=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(M-w)*L,n=y+(v-y)*L,s=et(e).width*c/2,i=n+et(e).height*c/2+8*c;let u=0;a.forEach((e,n)=>{const a=(h[n]?et(h[n]).width:0)*c/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*c-l;u=Math.max(u,i-d)}),y-=u,v-=u}const _=M-C*g,B=v-H*g,z=Math.hypot(_-w,B-y)/c+1;d.appendChild(O("line",{class:s,"data-note":n.note,x1:w,y1:y,x2:_,y2:B,style:`--len:${z.toFixed(1)}; ${T("--after",f)}`}));const U=-H,F=C,V=.42*g;d.appendChild(O("polygon",{class:i,"data-note":n.note,points:[`${M},${v}`,`${_+U*V},${B+F*V}`,`${_-U*V},${B-F*V}`].join(" "),style:T("--after",f)})),e&&(E(e,w+(M-w)*L,y+(v-y)*L,S,u),e.style.setProperty("--after",String(f)));const R=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(R)&&R>0&&Y(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,R),`${b.value} to ${m.value} over ${R} years`,n)}},mt=(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}},$t=(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}); ${T("--i",e.slot)}`}},pt=(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}})},gt=(t,e,n=!1)=>{const a=pt(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},wt=(t,e)=>{const{top:n,bottom:a}=gt(t,e);return n+a},yt=(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})`)},Mt=(t,e)=>t.some((n,a)=>a!==e&&!n.cell.missing&&n.to!==n.from&&n.from===t[e].to),vt=(t,e,n,a={},r="")=>{const s={class:_(o,e),"data-kind":"bar","data-row":n+1,...a},c=T("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=O("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(O("rect",{...s,...r,class:_("tablechart-piece",e),"data-row":n+1,...$t(t,e,o)}))}},xt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,groups:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,aspect:.5,minHeight:({labelHeight:t,nameHeight:e,rows:n,series:a,stacked:o,labels:r})=>{const s=1.1*t,c=a>1&&!o?s*(a+.15*(a-1))/.7:o||"inside"===r?s/.58:s;return n*Math.max(c,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=>et(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/S*100).toFixed(2)}%`);const b=S-4*a,m=t.stacked?Math.max(P(t.rows.map(e=>gt(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=>-gt(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(m,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,x=Math.min(M*i.barfill,u),k=mt(M,t.series.length,u),N=c[0]??t.totals[0],A=N?et(N).height*a*.56:0,C=Math.max(((d&&!t.stacked?k.size:x)-A)/2,5*a),H=t=>et(t).width*a,L=t=>t.length?P(t.map(H))+C+4*a:0,B=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,z=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:B(e,n)}))),U=e=>{const n=gt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let F=t.stacked?L(t.totals.filter((t,e)=>!U(e))):d?L(z.filter(t=>t.value>=0).map(t=>t.label)):0,V=t.stacked?L(t.totals.filter((t,e)=>U(e))):d?L(z.filter(t=>t.value<0).map(t=>t.label)):0;const R=(e,n)=>"inside"===t.labels&&ot(e,n,a);if(!d&&!t.stacked)for(let o=0;o<3;o++){const t=b-f-F-V,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!R(n,y(e.value,t))),a=L(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),o=L(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(a<=F&&o<=V)break;F=Math.max(F,a),V=Math.max(V,o)}const q=b-f-F-V,I=f+V+y(g,q),j=t=>t<0?I-y(t,q):I+y(t,q);if(t.squeeze&&(t.breakX=j(t.squeeze.gap)),t.x=j,t.stacked){const e=t.length("--tablechart-stack-gap","1px")??a;return t.rows.forEach((o,r)=>{const s=gt(o,t.series.length),c=vt(t,o,r,{"data-grow":"right"},s.bottom<0?I-j(s.bottom)+"px center":""),i=v(r)-x/2,u=pt(o,t.series.length);u.forEach(({from:o,to:s,cell:l},d)=>{const h=t.seriesValues[d][r];if(h.dataset.place="none",l.missing||s===o)return;const f=Math.min(j(o),j(s)),b=Math.max(j(o),j(s)),m=Mt(u,d)?Math.min(e,(b-f)/2):0,[$,p]=j(s)>j(o)?[f,b-m]:[f+m,b];c(d,{x:$,y:i,width:Math.max(p-$,1),height:x,...s<o&&{"data-grow":"left"}}),h.dataset.place="inside",h.toggleAttribute("data-left-out",!ot(h,b-f,a)||et(h).height*a>x),yt(h,t,d),E(h,(f+b)/2,v(r),S,n)});const d=t.totals[r];d&&(d.dataset.place=U(r)?"before":"after",E(d,U(r)?j(s.bottom)-C:j(s.top)+C,v(r),S,n));const h=l[r];h&&E(h,f-8*a,v(r),S,n)}),void s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}if(d){const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=rt(t.plot,e,t=>({size:et(t).height*a,room:k.size+.5*k.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=j(i.value),h=i.value<0,f=v(r)+k.offset(l),b=Math.max(Math.abs(d-I),1);0!==i.value&&s.appendChild(O("rect",{class:_(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?I-b:I,y:f,width:b,height:k.size,...$t(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),E(u,h?d-C:d+C,f+k.size/2,S,n)});const i=l[r];i&&E(i,f-8*a,v(r),S,n)}),void s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}const D=e.map((t,e)=>R(c[e],Math.abs(j(t.value)-I)));e.forEach((e,r)=>{const i=j(e.value),u=v(r),d=e.value<0,h=Math.abs(i-I),b=Math.max(h,1);0!==e.value&&s.appendChild(O("rect",{class:_(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?I-b:I,y:u-x/2,width:b,height:x,style:T("--i",e.slot)}));const m=c[r],$=Math.max(Math.min(C,h-H(m)-6*a),6*a),p=d?1:-1;m.dataset.place=D[r]?"inside":d?"before":"after",m.dataset.kind=e.kind,E(m,D[r]?"center"===t.insideAlign?(I+i)/2:"start"===t.insideAlign?I-p*($+H(m)/2):i+p*($+H(m)/2):i-p*C,u,S,n);const g=l[r];g&&E(g,f-8*a,u,S,n)}),s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}},kt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,lines:!0,groups:!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){const e=t.length("--tablechart-stack-gap","1px")??l;return t.rows.forEach((o,r)=>{const i=gt(o,t.series.length),u=vt(t,o,r,{},i.bottom<0?`center ${f-a(i.top)}px`:""),d=n(r)-s/2,h=pt(o,t.series.length);h.forEach(({from:o,to:i,cell:f},b)=>{const m=t.seriesValues[b][r];if(m.dataset.place="none",f.missing||i===o)return;const $=Math.min(a(i),a(o)),p=Math.max(a(i),a(o)),g=Mt(h,b)?Math.min(e,(p-$)/2):0,[w,y]=a(i)<a(o)?[$+g,p]:[$,p-g];u(b,{x:d,y:w,width:s,height:Math.max(y-w,1),...i<o&&{"data-grow":"down"}}),m.dataset.place="inside",m.toggleAttribute("data-left-out",!at(m,p-$,l)||et(m).width*l>s-4*l),yt(m,t,b),E(m,n(r),($+p)/2,S,c)});const b=t.totals[r];if(b){const t=0===i.top&&i.bottom<0;b.dataset.place=t?"below":"outside",E(b,n(r),t?a(i.bottom)+4*l:a(i.top)-4*l,S,c)}}),void i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}if(t.own.length>1){const e=n(1)-n(0)||2*n(0),s=mt(e,t.own.length,t.barMax),u=t.own.flatMap(e=>t.seriesValues[e]).filter(t=>void 0===t.dataset.missing),d=rt(t.plot,u,t=>({size:et(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.own.forEach((u,h)=>{const b=e.cells[u]??e.cells[0],m=t.seriesValues[u][r],$=n(r)+s.offset(h);if(b.missing)return void(m.dataset.place="none");const p=a(b.value),g=b.value<0,w=Math.max(Math.abs(f-p),1);0!==b.value&&i.appendChild(O("rect",{class:_(o,e),"data-kind":"bar","data-row":r+1,...g&&{"data-grow":"down"},x:$,y:g?f:f-w,width:s.size,height:w,...$t(t,e,u)})),m.dataset.place=g?"below":"outside",m.toggleAttribute("data-left-out",!d),E(m,$+s.size/2,g?p+4*l:p-4*l,S,c)})}),void i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}const b=t.own[0],m=t.own.length<t.series.length,$=nt(u,s,l),p=e.map((t,e)=>"inside"===d&&!$&&!t.missing&&at(u[e],Math.abs(f-a(t.value)),l)),g=u[0]?et(u[0]).height*l*.56:0;let w=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())p[o]&&(w=Math.min(w,(s-et(r).width*l)/2));e.forEach((e,r)=>{const d=a(e.value),$=e.value<0;if(e.missing)return E(u[r],n(r),f-4*l,S,c),void(u[r].dataset.place="outside");const y=Math.max(Math.abs(f-d),1);0!==e.value&&i.appendChild(O("rect",{class:_(o,e),"data-kind":e.kind,"data-row":r+1,...$&&{"data-grow":"down"},x:n(r)-s/2,y:$?f:f-y,width:s,height:y,style:T("--i",e.slot),...m&&$t(t,e,b)}));const M=$?-1:1,v=Math.min(w,(Math.abs(f-d)-g)/2),x="center"===h?(d+f)/2:"start"===h?f-M*(v+g/2):d+M*(v+g/2),k=$?d+4*l:d-4*l;E(u[r],n(r),p[r]?x:k,S,c),u[r].dataset.place=p[r]?"inside":$?"below":"outside",m&&p[r]&&yt(u[r],t,b)}),i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}},Nt=0,St={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,i=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(S,e)/2-h,10),b=f*s.ringfill,m=f-b/2,$=2*Math.PI*m,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=H(y,h),v=`--share:${h.toFixed(4)}; --start:${M.start.toFixed(4)}; --span:${M.span.toFixed(4)};`,x=h*$,k=g/$*2*Math.PI-Math.PI/2;p.push(k),o.appendChild(O("circle",{class:_(u,t),"data-slice":w+1,"data-row":s+1,cx:l,cy:i,r:m,"stroke-width":b,transform:`rotate(-90 500 ${i})`,"stroke-dasharray":`${x.toFixed(1)} ${($-x).toFixed(1)}`,"stroke-dashoffset":(-g).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${x.toFixed(1)}; --circ:${$.toFixed(1)}; ${v} --ease:${M.easing}; ${T("--i",t.slot)}`}));const N=k+x/$*Math.PI,A=Math.cos(N),C=Math.sin(N);o.appendChild(O("line",{class:"tablechart-leader",x1:l+A*(f+2*n),y1:i+C*(f+2*n),x2:l+A*(f+7*n),y2:i+C*(f+7*n),"data-row":s+1,style:`${v} ${T("--i",t.slot)}`})),c.style.setProperty("--start",M.start.toFixed(4)),c.style.setProperty("--span",M.span.toFixed(4));const L=f+9*n,B=et(c).width*n/2;E(c,l+A*(L+Math.abs(A)*B),i+C*(L+Math.abs(C)*a*.7),S,e),c.dataset.place="around",g+=x,y+=h,w+=1}),p.length>1){const t=m-b/2-1,n=m+b/2+1,a="tablechart-slices-"+ ++Nt,r=O("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(O("rect",{x:0,y:0,width:S,height:e,fill:"white"}));for(const e of p)r.appendChild(O("line",{class:"tablechart-divide",x1:l+Math.cos(e)*t,y1:i+Math.sin(e)*t,x2:l+Math.cos(e)*n,y2:i+Math.sin(e)*n}));const s=O("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${u}`)))s.appendChild(e);const c=O("defs");c.appendChild(r),o.prepend(c,s)}c&&E(c,l,i,S,e)}},At=["circle","square","diamond"],Ct=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=At.find(t=>n.includes(t));return{shape:a??At[Math.floor(e/2)%At.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},Ht=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return O("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return O("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return O("polygon",{points:`${e},${n-.75*t} ${e+.87*t},${n+.75*t} ${e-.87*t},${n+.75*t}`,...o})}return O("circle",{cx:e,cy:n,r:a,...o})},Tt=t=>Number(t.toFixed(2));function Lt(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 Ot,_t,Bt=t=>{const e=t.length,n=t.reduce((t,e)=>t+e.x,0)/e,a=t.reduce((t,e)=>t+e.y,0)/e,o=t.reduce((t,e)=>t+(e.x-n)**2,0),r=o?t.reduce((t,e)=>t+(e.x-n)*(e.y-a),0)/o:0,s=t=>a+r*(t-n),c=e>2?Math.sqrt(t.reduce((t,e)=>t+(e.y-s(e.x))**2,0)/(e-2)):0,l=o?c/Math.sqrt(o):0;return{at:s,spread:c,t:l?r/l:r?Number.POSITIVE_INFINITY:0,n:e}},Et=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13],zt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),Ut=t=>({segments:zt,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,own:o,seriesValues:s,names:c,cx:l,y:i,height:u,unit:f,labelHeight:b,svg:p,stacked:g}=e,w=o.length<a.length,y="step"===e.shape,M="smooth"===e.shape,v=a.length>1,x=a.some(t=>t.focus),k=n.length-1,N=i(0),A=n.length>1?l(1)-l(0):2*l(0);p.style.setProperty("--_base",`${Tt(N)}px`);const C=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],H=(t,e)=>!C(t,e)||!!C(t,e)?.missing,T=n.map(t=>g?pt(t,a.length,!0):null),L=(t,e)=>T[e]?.[t].to??C(t,e)?.value??0,_=(t,e)=>T[e]?.[t].from??0,B=(t,e)=>[l(e),i(L(t,e))],z=a.map((t,e)=>{if(!v)return{attrs:{},ink:""};const n=x&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),U=w?k:Math.min(k,6);e.plot.style.setProperty("--count",String(U+1));const F=k>0?U/(y?n.length:k):1,V=t=>t*F,R=t=>`--i:${Tt(V(t))}`,I=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{H(t,o)||(a<0&&(a=o),(o===k||H(t,o+1))&&((y||o>a)&&e.push([a,o]),a=-1))}),e},j=(t,e)=>`--i:${Tt(V(t)+1)}; --d:${Tt(V(y?e+1:e)-V(t))}`,P=(t,e)=>({"data-from":t+1,"data-to":e+1,...y&&{"data-flat":""}}),D=M?a.map((t,e)=>Lt(n.length,t=>H(e,t),t=>B(e,t))):[],W=M&&t?a.map((t,e)=>Lt(n.length,t=>H(e,t),t=>[l(t),i(_(e,t))])):[],G=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{y?(a.push(`H${Tt(o+n*A/2)}`),s<t.length-1&&a.push(`V${Tt(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])=>`${Tt(t)},${Tt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${Tt(o)},${Tt(r)}`)}),a},K=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[l(e+a),i(o(t,e+a))]),Y=(t,e,n,a)=>M?t[e].slice(n,a+1):null,X=t=>l(t)-(y?A/2:0),J=t=>l(t)+(y?A/2:0);t&&o.forEach(t=>(t=>{const e=O("g",{class:h,...z[t].attrs,...g&&{"data-stacked":""},style:z[t].ink}),n=I(t),a=O("g",{class:"tablechart-area-fill",style:`--rows:${Tt(U+1)}; ${n.length?j(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=K(t,o,r,L),n=K(t,o,r,_),s=Y(W,t,o,r)?.reverse()??null,c=[`M${Tt(X(o))},${Tt(n[0][1])}`,`L${Tt(X(o))},${Tt(e[0][1])}`,...G(e,Y(D,t,o,r),1),`L${Tt(J(r))},${Tt(n[n.length-1][1])}`,...G(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(O("path",{d:c,...P(o,r),style:j(o,r)}))}p.appendChild(e)})(t)),o.forEach(t=>(t=>{const e=a[t];for(const[n,a]of I(t)){const o=K(t,n,a,L),r=[`M${Tt(X(n))},${Tt(o[0][1])}`,...G(o,Y(D,t,n,a),1)].join(" ");p.appendChild(O("path",{class:d,...z[t].attrs,d:r,...e.line&&{"data-line":e.line},...P(n,a),style:`${z[t].ink}${j(n,a)}`}))}})(t));const tt=w?a.flatMap((t,e)=>o.includes(e)?[]:s[e].flatMap(t=>{const e=t.dataset.place;if(!e||"none"===e||t.hasAttribute("data-left-out"))return[];const[n,a,o,r]=ct(t,f,S,u);return[{label:t,box:[n-2*f,a-3*f,o+4*f,r+6*f]}]})):[],nt=y?[]:o.flatMap(t=>n.flatMap((e,n)=>{if(H(t,n))return[];const[a,o]=B(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),at=tt.filter(({label:t,box:e})=>{const n=nt.some(t=>Z(t,e));return n&&t.setAttribute("data-left-out",""),!n}),ot=(t,e)=>{let n=e;for(;n<k&&!H(t,n+1)&&C(t,n+1)?.value===C(t,e)?.value;)n++;return n},rt=t=>"above"===t?"below":"above",st=(t,e,n)=>{const[a,o]=B(t,e),r=et(s[t][e]).width*f,c=[a-r/2,"above"===n?o-7*f-b:o+7*f,r,b];return c[1]+b>u?Number.POSITIVE_INFINITY:[e-1,e+1].filter(e=>e>=0&&e<=k&&!H(t,e)).flatMap(n=>lt(t,e,n,0)).filter(t=>Z(t,c)).length},lt=(t,e,n,a)=>{const[o,r]=B(t,e),[s,c]=B(t,n),l=Math.max(1,Math.ceil(Math.hypot(s-o,c-r)/(3*f)));return Array.from({length:l+1},(t,e)=>{const n=e/l;return[o+(s-o)*n-a,r+(c-r)*n-a,2*a,2*a]})},it=(e,n)=>{const o=C(e,n);if(!o||o.missing)return"none";if(y&&n>0&&!H(e,n-1)&&C(e,n-1)?.value===o.value)return"none";if(x&&!a[e].focus)return"none";if(g)return"middle";const r=o.value<0?"below":"above";if(!v||x||a.length>2)return t||y||st(e,n,r)<=st(e,n,rt(r))?r:rt(r);const s=C(1-e,n);return!s||s.missing?r:o.value>s.value||o.value===s.value&&0===e||t&&o.value>=0&&B(e,n)[1]+7*f+b>N?"above":"below"},dt=(w||v&&!x&&a.length>2&&!g)&&!y,ht=new Map;if(dt){const t=n.flatMap((t,e)=>o.map(t=>({s:t,i:e,value:C(t,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==it(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"],a=t.map(({s:t,i:n,value:a})=>{const o=et(s[t][n]).width*f,[r,c]=B(t,n);return e(a).map(t=>[r-o/2,"above"===t?c-7*f-b:c+7*f,o,b])}),r=o.flatMap(t=>n.flatMap((e,n)=>{if(H(t,n))return[];const[a,o]=B(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),c=Q(a,[...r,...at.map(({box:t})=>t)],[0,0,l(k)+l(0),u]);t.forEach(({s:t,i:n,value:a},o)=>ht.set(s[t][n],null===c[o]?null:e(a)[c[o]]))}o.forEach(t=>{s[t].forEach((e,n)=>{e.style.setProperty("--i",String(Tt(y?(V(n)+V(n+1))/2:V(n))));const a=ht.get(e)??it(t,n);if(e.dataset.place="above"===a?"outside":a,e.toggleAttribute("data-left-out","none"!==a&&((t,e)=>dt?null===ht.get(s[t][e]):!(!g&&!y)&&(et(s[t][e]).width*f>(y?ot(t,e)-e+1:1)*A-4*f||!!(g&&t>0&&L(t,e)<_(t,e))||g&&Math.abs(i(_(t,e))-i(L(t,e)))<1.2*b))(t,n)),y&&"none"!==a?e.dataset.rowEnd=String(ot(t,n)+1):delete e.dataset.rowEnd,"none"===a)return;const o=et(e).width*f/2+4*f;let r=l(n);y?r=(l(n)+l(ot(t,n)))/2:"middle"===a&&0===n?r+=o:"middle"===a&&n===k&&(r-=o);const c=i(L(t,n)),d={middle:(i(_(t,n))-c)/2,above:-7*f,below:7*f};E(e,r,c+d[a],S,u)})});const ft=t=>{const a=n.flatMap((e,n)=>e.pinned&&!H(t,n)?[n]:[]),o=n.map((t,e)=>e).filter(e=>!H(t,e)),r=e=>C(t,e)?.value??0,{keys:c}=e.pick;o.length&&(c.includes("last")&&a.push(o[o.length-1]),c.includes("first")&&a.push(o[0]),c.includes("highest")&&a.push(o.reduce((t,e)=>r(e)>r(t)?e:t)),c.includes("lowest")&&a.push(o.reduce((t,e)=>r(e)<r(t)?e:t)),c.includes("outliers")&&a.push(...((t,e=5,n=25)=>{if(t.length<4)return null;const{mean:a,share:o}=(t=>{const e=t.map(t=>t.y),n=Math.min(...e),a=Math.max(...e),o=n<0&&a>0,r=a-n||1;return{mean:e.reduce((t,e)=>t+e,0)/e.length,share:(t,e)=>t/(o?r:Math.abs(e)||r)*100}})(t),r=e=>t.filter(t=>Math.abs(o(t.y-e(t.x),e(t.x)))>n),s=e=>e.length<=t.length/5;let c=Bt(t),l=r(c.at);l.length&&s(l)&&(c=Bt(t.filter(t=>!l.includes(t))),l=r(c.at)),s(l)||(c=Bt(t),l=[]);const i=c.at,u=t[0],d=t[t.length-1],h=o(i(d.x)-i(u.x),a),f=Math.abs(c.t)>=(b=c.n-2,Et[b-1]??(b<30?2.1:2));var b;const m=Math.abs(o(c.spread,a))<e,$=Math.abs(h)<e?"flat":h>0?"up":"down",p="flat"===$?m?"flat":"unclear":f?$:"unclear";return{course:p,line:i,outside:"unclear"===p?[]:l}})(o.map(t=>({x:t,y:r(t)})))?.outside.map(t=>t.x)??[]));const l=[];for(const e of a){const n=s[t][e];l.includes(e)||"none"===n.dataset.place||l.every(e=>1===ut([s[t][e],n],f,1e3,u))&&l.push(e)}return new Set(l)},bt=t=>{const e=s[t].filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out"));return 1===ut(e,f,S,u)},mt=new Map;for(const t of o){const n="all"===e.pick.mode||"auto"===e.pick.mode&&bt(t)?null:ft(t);mt.set(t,n),n&&s[t].forEach((t,e)=>{"none"===t.dataset.place||n.has(e)||t.setAttribute("data-left-out","")})}if(!g&&!y&&o.some(t=>mt.get(t))){const t=l(k)+l(0),e=2*f,a=o.flatMap(t=>n.flatMap((n,a)=>a===k||H(t,a)||H(t,a+1)?[]:lt(t,a,a+1,e))),r=(c[0]?et(c[0]).height:0)*f,i=o.flatMap(t=>{const e=c[t];if(!e)return[];let n=k;for(;n>0&&H(t,n);)n--;const[a,o]=B(t,n);return[[a+10*f,o-r/2,et(e).width*f,r]]}),d=o.flatMap(t=>[...mt.get(t)??[]].map(e=>({s:t,i:e}))),h=({s:t,i:e})=>{const n=C(t,e)?.value??0,a=e>0&&!H(t,e-1)?C(t,e-1)?.value:void 0,o=e<k&&!H(t,e+1)?C(t,e+1)?.value:void 0;return void 0!==(a??o)&&(void 0===a||n<=a)&&(void 0===o||n<=o)?["below","outside","below far","outside far","after","before"]:["outside","below","outside far","below far","after","before"]},m=({s:e,i:n},a)=>{const o=et(s[e][n]).width*f,r=b,[c,l]=B(e,n),i=Math.min(Math.max(c-o/2,0),t-o);return"outside"===a?[i,l-7*f-r,o,r]:"below"===a?[i,l+7*f,o,r]:"outside far"===a?[i,l-7*f-2*r,o,r]:"below far"===a?[i,l+7*f+r,o,r]:"after"===a?[c+7*f,l-r/2,o,r]:[c-7*f-o,l-r/2,o,r]},$=d.map(h),p=e=>e[0]>=0&&e[1]>=0&&e[0]+e[2]<=t&&e[1]+e[3]<=u-2*f,g=d.map(({s:t,i:e})=>{const[n,a]=B(t,e);return[n-6*f,a-6*f,12*f,12*f]}),w=[],y=new Set,M=d.map((t,e)=>{const n=$[e].map(e=>m(t,e)),o=t=>p(t)&&![...w,...i,...g].some(e=>Z(t,e));let r=n.findIndex(t=>o(t)&&!a.some(e=>Z(t,e)));return r<0&&(r=n.findIndex(o),r>=0&&y.add(e)),r>=0&&w.push(n[r]),r<0?null:r});d.forEach((t,e)=>{const n=s[t.s][t.i];n.toggleAttribute("data-cut",y.has(e));const a=M[e];if(null===a)return n.setAttribute("data-left-out","");const o=$[e][a],[r,c,l,i]=m(t,o),d=o.split(" ")[0];n.dataset.place=d,E(n,"after"===d?r:"before"===d?r+l:r+l/2,"outside"===d?c+i:"below"===d?c:c+i/2,S,u)})}y||(()=>{const t=o.map(t=>a[t]),r=a.map((e,n)=>w?Ct(t,o.indexOf(n)):v?Ct(a,n):{shape:"circle",open:!1}),s=(t,e,n)=>{const[a,o]=B(t,e);return Ht(r[t].shape,a,o,4*f,{...n,style:`${n.style??""}${s=o,`--rise:${Tt(N-s)}px; `}${R(e)}`});var s},c=t=>n.map((t,e)=>e).filter(e=>!H(t,e)&&((t,e)=>{const n=mt.get(t);return n?n.has(e):A>=10*f})(t,e)),l=o.flatMap(t=>r[t].open?c(t).map(e=>s(t,e,{class:$,"data-row":e+1,...v&&{"data-series":t+1}})):[]);"grow"===p.closest("[data-animate]")?.getAttribute("data-animate")?q(p,l,S,u):e.lineHoles.push(...l),o.forEach(t=>{for(const e of c(t))p.appendChild(s(t,e,{class:m,...z[t].attrs,"data-marker":r[t].shape,...r[t].open&&{"data-open":""},"data-row":e+1,style:z[t].ink}))})})(),e.pointOf=t=>{const e=o.filter(e=>!H(e,t)).map(e=>B(e,t));return e.length?e.reduce((t,e)=>e[1]<t[1]?e:t):null};const $t=(w?[]:c).map((t,e)=>{const n=(t=>{let e=k;for(;e>0&&H(t,e);)e--;return e})(e),[a,o]=B(e,n);return{name:t,x:(y?a+A/2:a)+10*f,y:g?(o+i(_(e,n)))/2:o}}),gt=(c[0]?et(c[0]).height:0)*f;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))($t,gt))E(t.name,t.x,t.y,S,u);const wt=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),yt=t||g||2!==a.length||x||wt?N:u-2*f;w||p.appendChild(O("line",{class:r,x1:0,x2:l(k)+l(0),y1:yt,y2:yt}))}}),Ft=Ut(!1),Vt=Ut(!0),Rt=new Set,qt={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.`;Rt.has(a)||(Rt.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=nt(i,a,c),b=d??"center",m=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&&at(i[a],r,c)}}),$=i[0]?et(i[0]).height*c*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of m.entries())r.inside&&(p=Math.min(p,(a-et(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?C:"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(O("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${T("--i",s.slot)}; ${w(r+1,1/3)}`}))}),t.forEach((n,r)=>{const{top:u,length:d,down:h,inside:f}=m[r];l.appendChild(O("rect",{class:_(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:`${T("--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"===b?u+d/2:"end"===b!==h?u+M+$/2:u+d-M-$/2;y.dataset.place=f?"inside":"outside",y.dataset.kind=n.kind;const x=f?v:"down"===n.kind?u+d+et(y).height*c+3*c:u-3*c;E(y,e(r),x,S,s)}),l.appendChild(O("line",{class:r,x1:0,x2:S,y1:h,y2:h}))}},It={enabled:!1,log(...t){It.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!It.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):It.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},jt=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}},Pt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).flatMap((t,e)=>t.hasAttribute("data-note")?[e]:[]),Dt=(t,e="data-i18n")=>{const n=Pt(t);return Array.from(t.querySelectorAll("tbody tr")).map((t,a)=>{const o=t.querySelector("th"),r=Array.from(t.querySelectorAll("td")),s=r.filter((t,e)=>!n.includes(e)).map(jt);s.length||s.push(jt(null));const c=n.map(t=>r[t]).find(t=>t?.textContent?.trim());return{...s[0],label:(o?.textContent||"").trim(),note:c?.textContent?.trim()??null,noteKey:e&&c?.getAttribute(e)||null,short:o?.getAttribute("data-short")||null,pinned:"show"===t.getAttribute("data-value"),key:e&&o?.getAttribute(e)||null,cells:s,classes:Array.from(t.classList),isTotal:"total"===t.getAttribute("data-kind"),slot:a}})},Wt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).filter(t=>!t.hasAttribute("data-note")),Gt=(t,e,n="data-i18n")=>{const a=Wt(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"),chart:"line"===o?.getAttribute("data-chart")?"line":null};var r})},Kt=t=>Number(t.toPrecision(12)),Yt=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return Kt((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},Xt=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(Kt(o*n));return a},Zt=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Kt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},Qt=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},Jt=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=Zt(n,t.step),a=Xt(t.min,t.max,n);return{...t,step:n,ticks:a}},te=null,ee=t=>{if(te??(te=document.createElement("canvas").getContext("2d",{willReadFrequently:!0})),!te)return[0,0,0,1];te.clearRect(0,0,1,1),te.fillStyle=t,te.fillRect(0,0,1,1);const[e,n,a,o]=te.getImageData(0,0,1,1).data;return[e,n,a,o/255]},ne=([t,e,n])=>{const a=t=>{const e=t/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4};return.2126*a(t)+.7152*a(e)+.0722*a(n)},ae=(t,e)=>{const[n,a]=[ne(t),ne(e)].sort((t,e)=>e-t);return(n+.05)/(a+.05)},oe=t=>{const e=document.createElement("span");e.style.color="var(--tablechart-surface, Canvas)",t.append(e);const n=ee(getComputedStyle(e).color);return e.remove(),n},re=(t,e)=>t.querySelector(`:is(.tablechart-bar, .tablechart-piece)[data-row="${e.dataset.row}"]${e.dataset.series?`[data-series="${e.dataset.series}"]`:""}`),se=t=>{const e=t.querySelectorAll(".tablechart-value[data-place='inside']");if(!e.length)return;const n=oe(t);for(const a of e){const e=re(t,a);if(!e||a.hasAttribute("data-left-out"))continue;const o=ee(getComputedStyle(e).fill),r=ne(n)>ne(o),s=r?[255,255,255]:[0,0,0];let c=r?[0,0,0]:[255,255,255];for(let t=0;t<=20;t++){const e=n.slice(0,3).map((e,n)=>Math.round(e+(s[n]-e)*t/20));if(ae(e,o)>=4.5){c=e;break}}a.style.setProperty("--_ink",`rgb(${c.join(" ")})`)}},ce=["axis-break","trend","bracket"],le=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))}},ie=(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)),le(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}}))},ue="tablechart-tooltip",de=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],he=null,fe=null,be=null,me=0,$e=()=>{clearTimeout(me),he&&fe&&(he.hidden=!0,fe=null,be=null)},pe=!1,ge=!0,we=NaN,ye=NaN,Me=!1,ve=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,xe=()=>{clearTimeout(me),me=window.setTimeout($e,120)},ke=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Ne=(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},Se=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!ke(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?Ne(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&&ke(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Ae=(t,e,n)=>{if(clearTimeout(me),fe===t&&be===e)return;const a=(t.type.tooltip??Se)(t,e,n);if(!a.length)return $e();fe&&fe!==t&&$e(),he??(he=(()=>{const t=document.createElement("div");return t.className=ue,t.setAttribute("aria-hidden","true"),t.hidden=!0,Ot=document.createElement("div"),(_t=document.createElement("div")).className=`${ue}-arrow`,t.append(Ot,_t),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(me)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&xe()),document.addEventListener("pointerdown",e=>{const n=e.target;!fe||fe.plot.contains(n)||t.contains(n)||$e()}),window.addEventListener("resize",$e),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${ue}-line`,n){const t=document.createElement("span");t.className=`${ue}-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=`${ue}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${ue}-value`,n.textContent=e,r.append(n)}return r},r=(t.figure.querySelectorAll("tbody tr")[e]?.querySelector("th"))?.textContent?.trim()||t.categories[e]?.textContent||t.rows[e].label,s=1===a.length&&!a[0].name,c=a.every(t=>t.name&&!t.value),l=((t,e)=>{const n=Pt(t),a=t.querySelectorAll("tbody tr")[e]?.querySelectorAll("td")??[];return n.map(t=>a[t]).find(t=>t?.textContent?.trim())??null})(t.figure,e)?.textContent?.trim(),i=l?[Object.assign(document.createElement("div"),{className:`${ue}-note`,textContent:l})]:[];Ot.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)),...i);const u=getComputedStyle(t.figure);for(const m of de){const t=u.getPropertyValue(m).trim();t?he.style.setProperty(m,t):he.style.removeProperty(m)}he.style.setProperty("--_color",u.color),he.style.colorScheme=u.colorScheme,he.style.fontFamily=u.fontFamily;const d=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);he.parentElement!==d&&d.append(he),fe=t,be=e,he.hidden=!1,he.style.left="0px",he.style.top="0px";const h=he.getBoundingClientRect(),f={x:h.left,y:h.top,scale:ve(he,h.width)},b=ve(t.plot,t.plot.getBoundingClientRect().width);he.style.fontSize=Number.parseFloat(u.fontSize)*b/f.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:b}=document.documentElement,m=n.top-r,$=b-n.bottom-r,p=i+d<=m||!(i+d<=$)&&m>=$,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,b-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"})(he,_t,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.pointOf?.(e);if(n){const e=t.svg.getBoundingClientRect(),a=e.width/S,o=4*a*(S/t.plot.clientWidth);return new DOMRect(e.left+n[0]*a-o,e.top+n[1]*a-o,2*o,2*o)}const a=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let o=null;for(const u of a){const t=u.getBoundingClientRect();(t.width||t.height)&&(o=o?new DOMRect(Math.min(o.left,t.left),Math.min(o.top,t.top),Math.max(o.right,t.right)-Math.min(o.left,t.left),Math.max(o.bottom,t.bottom)-Math.min(o.top,t.top)):t)}if(o)return o;const r=t.plot.getBoundingClientRect(),[s,c,l,i]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(r.left+r.width*s/100,r.top+r.height*c/100,r.width*l/100,r.height*i/100)})(t,e),f)},Ce=t=>{fe===t&&$e()},He={area:Vt,bar:xt,column:kt,donut:St,line:Ft,waterfall:qt},Te={"axis-break":j,trend:bt,bracket:X,reference:ft,note:dt},Le=Object.keys(Te),Oe=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},_e=["straight","step","smooth"],Be=(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${L(t)},${L(l)}H${L(e)}`:`M${L(l)},${L(t)}V${L(e)}`).join("")},Ee=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=O("path",{d:Be(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)},ze=t=>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]),Ue=(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${L(Math.max(t,e))},${L(r)}H${L(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${L(t)},${L(Math.max(r,n))}V${L(Math.min(c,n+o))}`:"").join(""),Fe=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},Ve=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),Re=(t,e)=>{const n=t.dataset.chartShape;return n&&_e.includes(n)?n:_e.includes(e.shape)?e.shape:"straight"},qe=0,Ie=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=He[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(He).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=Dt(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(Oe(e)))continue;const t=document.createElement("span");t.className=w,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-"+ ++qe),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=Gt(t,c,e.langattribute);if(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)),l.some(t=>t.chart)){const t=s.lines?l.every(t=>t.chart)?'Every series has data-chart="line", so the chart is a line chart: set data-chart="line" on the figure.':null:`A ${r} chart cannot draw a series as a line.`;t&&(console.warn(`[${n}] ${t}`),l=l.map(t=>({...t,chart:null})))}const i=l.some(t=>t.chart),u=l.length>1;u&&t.style.setProperty("--_series-count",String(l.length));const d=t.hasAttribute("data-chart-stack");d&&!s.stackable&&console.warn(`[${n}] A ${r} chart cannot be stacked.`),d&&i&&console.warn(`[${n}] A chart with a line cannot be stacked.`);const h=d&&!!s.stackable&&u&&!i,m=document.createElement("div");m.className="tablechart-plot",m.setAttribute("aria-hidden","true");const $=O("svg",{role:"presentation",focusable:"false"});m.appendChild($);const g=t.querySelector(":scope > table"),y=e=>g?g.before(e):t.append(e);y(m);const M=s.centre?c.filter(t=>!t.isTotal):c,v=Math.max(0,P(M.flatMap(t=>t.cells.slice(0,l.length).map(t=>D(t.number))))),N=l.map((t,e)=>Math.max(0,P(c.map(t=>D(t.cells[e]?.number??""))))),S=document.createElement("div");S.className="tablechart-values",m.appendChild(S);const A=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=B(a,S);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),u&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(N[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),!1===s.numbers&&(e||n)&&(r.dataset.place="none"),r})),C=A[0],H=h&&s.totals?c.map((t,e)=>{const n=B(a,S);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(wt(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}):[],T=c[c.length-1],L=l.some(t=>t.focus),_=t.getAttribute("data-chart-legend"),E=u&&!s.columns&&(null===_?e.legend||void 0!==s.legend:"false"!==_)?document.createElement("div"):null;E&&(E.className=b,E.setAttribute("aria-hidden","true"),E.inert=!0);const z=l.filter(t=>t.chart),U=u&&!s.columns?l.map((n,a)=>{const o=B(f,E??m);E&&(o.dataset.place="legend");const r=n.chart?void 0:s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==Re(t,e)){const t=n.chart?Ct(z,z.indexOf(n)):Ct(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",L&&!n.focus?"1":"0"),o.style.setProperty("--i",String(T.slot)),o}):[],F=s.centre?B(p,m):null;if(F){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);F.dataset.value=String(e),t&&(F.dataset.decimals=String(D(t.number)))}const V=F&&!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,F,e):null,R="beside"===s.categories,q=document.createElement("div");q.className="tablechart-categories",q.setAttribute("aria-hidden","true"),q.inert=!0,R?q.dataset.place="beside":s.centre&&(q.dataset.place="key"),q.style.setProperty("--_columns",String(c.length));let I=0;for(const[n,a]of c.entries()){const t=document.createElement("span");t.classList.add(...a.classes),t.textContent=a.short??a.label,a.key&&e.langattribute&&t.setAttribute(e.langattribute,a.short?`${a.key}-short`:a.key),s.centre&&(t.dataset.kind=a.isTotal?"total":"slice",a.isTotal||(t.dataset.slice=String(I+1),t.style.setProperty("--n",String(I)),t.style.setProperty("--palette",`var(--tablechart-color-${I+1})`),I+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),q.appendChild(t)}s.centre&&t.style.setProperty("--_slice-count",String(I)),R?m.appendChild(q):y(q),E&&y(E);const j=l.filter(t=>!t.group),W=!s.axes&&!s.centre&&Fe(t,"data-chart-axis",e.axis),G=s.axes?{titles:j.slice(0,2).map((t,n)=>{const a=B(`${x}-title`,m);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:B(`${k}s`,m),numbers:!0}:W||!s.centre&&Fe(t,"data-chart-grid",e.grid)?{titles:[],ticks:B(`${k}s`,m),numbers:W}:null;s.text?.({figure:t,plot:m,rows:c,series:l,config:e});const K=Ve(t,e)?((t,e=!1)=>{const n=t.hasAttribute("data-fragment"),a=Array.from(t.querySelectorAll("tbody tr")),o=Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),r=Array.from(t.querySelectorAll("[data-annotation]")).filter(t=>ce.includes(t.getAttribute("data-annotation")??"")),s=t=>t.hasAttribute("data-fragment"),c=a.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(n||a.some(s)||o.some(s)||c.flat().some(s)||r.some(s)))return null;if(e&&!n)return null;const l=[],i=new Map,u=[],d=t=>{let e=null!==t?i.get(t):void 0;return void 0===e&&(e=l.length,l.push(t),u.push(0),null!==t&&i.set(t,e)),e};let h=0;const f="donut"===t.getAttribute("data-chart"),b=t=>f&&"total"===t.getAttribute("data-kind"),m=e?d(t.getAttribute("data-fragment-index")):-1,$=a.map(t=>{if(b(t))return{step:null,slot:0};if(e)return{step:m,slot:u[m]++};if(!n&&!s(t))return{step:null,slot:h++};const a=d(t.getAttribute("data-fragment-index"));return{step:a,slot:u[a]++}}),p=Math.max(-1,...$.map(t=>t.step??-1));if(p>=0)for(const[M,v]of a.entries())b(v)&&($[M]={step:p,slot:u[p]++});const g=o.map(t=>({step:s(t)?d(t.getAttribute("data-fragment-index")):null})),w=c.map(t=>t.map(()=>({step:null,slot:0}))),y=Math.max(0,...c.map(t=>t.length));for(let M=0;M<y;M++)for(const[t,e]of c.entries()){const n=e[M];if(!n||!s(n))continue;const a=d(n.getAttribute("data-fragment-index"));w[t][M]={step:a,slot:u[a]++}}return{rows:$,series:g,cells:w,notes:r.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",$.length-1)]:[0,$.length-1];let o=null;for(let s=Math.min(n,a);s<=Math.max(n,a);s++)for(const t of[$[s]?.step??null,...(w[s]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const r=g[e("data-series",0)]?.step??null;null!==r&&(null===o||r>o)&&(o=r),s(t)&&(o=d(t.getAttribute("data-fragment-index")));const c=null===o?$.length:$.filter(t=>t.step===o).length;return{step:o,after:c}}),count:l.length,indexes:l}})(t,Boolean(s.axes)):null;s.axes&&t.querySelector("tbody [data-fragment], thead [data-fragment]")&&It.log(`A ${r} chart has one step, with data-fragment on the figure; its rows and columns have no steps of their own.`,t),K&&t.setAttribute("data-steps","");const Y=t.getAttribute("data-chart-keys"),X=K&&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=O("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(O("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=w,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:Y&&`${Y}-previous`,next:Y&&`${Y}-next`,hint:Y&&`${Y}-step`},e.langattribute):null;X&&y(X);const Z=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,m),series:r,after:c.length}}).filter(t=>null!==t);if(!R&&!s.centre&&!s.axes)for(const[n,a]of c.entries()){if(!a.note)continue;const t=document.createElement("span");t.dataset.annotation="note",t.dataset.row=String(n+1),t.textContent=a.note,a.noteKey&&t.setAttribute("data-i18n",a.noteKey),Z.push({spec:t,type:dt,badge:dt.create(t,m),series:0,after:c.length})}Ve(t,e)&&t.setAttribute("data-animate",De(t,r,e,Boolean(K)));const Q={figure:t,plot:m,svg:$,rows:c,decimals:v,type:s,values:C,series:l,seriesValues:A,names:E?[]:U,categories:Array.from(q.children),centre:F,axes:G,stacked:h,totals:H,totalCell:V,rowAt:null,rowBox:null,pointOf:null,annotations:Z,checks:[],plan:K,step:0,controls:X},J=()=>en(t,$);$.addEventListener("transitionend",J),$.addEventListener("transitioncancel",J),X?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&ie(Q,Q.step+("next"===e?1:-1))}),ie(Q,0,!0);const tt=t.getAttribute("data-chart-tooltip"),et="false"!==tt&&("auto"===tt?"auto":null!==tt||e.tooltip);return et&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(Me)return;Me=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(ge=t.screenX!==we||t.screenY!==ye,we=t.screenX,ye=t.screenY,ge&&(pe=!1))},{capture:!0,passive:!0});const t=()=>{pe=!0,$e()};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)pe=!1;else if("mouse"===o.pointerType&&(!ge||pe))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return fe===t?$e():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=ve(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 fe===t?$e():void 0;Ae(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)||pe||Ae(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,fe===t&&xe())})})(Q,e,"auto"===et),Qe(Q,e),Q},je={grow:"grow",sweep:"sweep"},Pe=["never","auto","print","always"],De=(t,e,n,a)=>{const o="line"===e||"area"===e,r=je[t.getAttribute("data-chart-animate")??""]??je[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},We=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},Ge=(t,e,n)=>"inside"===t.dataset.chartLabels||"outside"!==t.dataset.chartLabels&&("inside"===e.labels||n)?"inside":"outside",Ke=(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*S:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},Ye=(t,e)=>Ke(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,Xe=["first","last","highest","lowest","outliers"],Ze=(t,e)=>{const a=(t.getAttribute("data-chart-values")??e.values).trim().toLowerCase().split(/\s+/).filter(Boolean);for(const r of a)["auto","all","none",...Xe].includes(r)||console.warn(`[${n}] data-chart-values knows no "${r}". It takes auto, all, none, ${Xe.join(", ")}.`);const o=a.filter(t=>Xe.includes(t));return a.includes("all")?{mode:"all",keys:[]}:a.includes("none")?{mode:"set",keys:[]}:a.includes("auto")||!o.length?{mode:"auto",keys:o.length?o:Xe}:{mode:"set",keys:o}},Qe=(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:Je(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},Je=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=W(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)}},tn=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||nn(t.svg),n)return t.figure.classList.add(v),t.figure.classList.toggle(y,e),t.figure.offsetWidth,e&&an(t.svg),void requestAnimationFrame(()=>t.figure.classList.remove(v));t.figure.classList.toggle(y,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>en(t.figure,t.svg)))},en=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&an(e)},nn=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},an=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},on=t=>"id"===t||"style"===t||t.startsWith("data-chart"),rn=/^\s*(?:Table)?:\s+/,sn=t=>"P"===t?.tagName&&rn.test(t.textContent??""),cn=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,ln=t=>{const e=dn(t);return"P"===e?.tagName?e:t},un=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},dn=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},hn="strong, b, span.total",fn="data-chart-made",bn=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,mn=new Set,$n=null,pn=["column","bar"],gn=t=>{const e=t.getAttribute("data-chart")||"column";if(!pn.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return pn.includes(n)?n:e},wn=!1,yn=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=sn(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||on(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?sn(r)?r:sn(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=ln(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=cn.exec(e.textContent??"");if(!n||!Le.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=ln(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(rn,""),n.textContent||n.remove());const a=Array.from(t.childNodes),o=a.findIndex(t=>"BR"===t.nodeName);if(e.append(...-1===o?a:a.slice(0,o+1)),-1!==o&&o<a.length-1){const t=document.createElement("span");t.append(...a.slice(o+1)),e.append(t)}return t.remove(),e})(c)),o&&a.append(o),l&&a.append(l),It?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(fn)&&"TH"!==t.tagName));(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!wn&&e&&(wn=!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:un(o.rows):un(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"),o="Note")=>{for(const l of a.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr"))l.remove();const r=t.some(t=>t.note);if(!a.tHead&&(e.length||n||r)){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 s=document.createElement("tbody");a.append(s);for(const l of t){const t=s.insertRow();"total"===l.kind&&(t.dataset.kind="total");const e=document.createElement("th");e.textContent=String(l.label??""),l.short&&(e.dataset.short=l.short),t.append(e);for(const n of l.values??[l.value??null])t.insertCell().textContent=null===n?"":String(n);r&&(t.insertCell().textContent=l.note??"")}const c=a.tHead?.rows[a.tHead.rows.length-1];if(r&&c&&!c.querySelector("[data-note]")){const e=Math.max(...t.map(t=>(t.values??[t.value]).length));for(;c.cells.length<e+1;)c.append(document.createElement("th"));const n=document.createElement("th");n.dataset.note="",n.textContent=o,c.append(n)}return a})(r,Array.isArray(o?.series)?o.series.map(String):[],"string"==typeof o?.label?o.label:"",a??void 0,"string"==typeof o?.note?o.note:void 0);if(!a){const e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||It?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),It?.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=dn(e);a?.matches(hn);a=dn(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=dn(e);t?.matches(hn);t=dn(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=Wt(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}`)})});const s=Pt(o);o.querySelectorAll("tbody tr").forEach((n,a)=>{const o=n.querySelectorAll("td");for(const r of s){const n=o[r];n?.textContent?.trim()&&!n.getAttribute(e)&&n.setAttribute(e,`${t}-note${a+1}`)}}),It?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute);for(const n of a)n.dispatchEvent(new CustomEvent("tablechart:table",{bubbles:!0}));return a},Mn=(t,e)=>{const a=It.timed("Building",t,()=>Ie(t,e));return a?(t.setAttribute(fn,""),xn(),((t,e)=>{let a=t,r=gn(a.figure),m=null,g=!1,w=!1;const y=async()=>{if(!Ve(a.figure,e))return tn(a,!0);const t=a.figure.classList.contains("is-shown");if(!g||null===m||t||w)!g&&e.replay&&t&&tn(a,!1);else{w=!0;const t=bn()?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(bn())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)),w=!1,!g&&e.replay||tn(a,!0)}var n},v=()=>{const t=gn(a.figure);if(!t||t===r)return;const n=It.timed("Building",a.figure,()=>Ie(a.figure,e,t));n&&((t=>{Ce(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${b}`)?.remove(),t.controls?.remove()})(a),ie(n,a.step,!0),a=n,r=t,m=null)},A=()=>{v();const t=a.plot.clientWidth;t&&t!==m&&It.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:m,type:g,values:w,series:y,seriesValues:M,names:v,annotations:A}=t;(({figure:t,rows:e,series:n},a)=>{const o=t.getAttribute("data-chart-table"),r=o&&Pe.includes(o)?o:a.table;"never"===r?t.removeAttribute("data-table"):t.setAttribute("data-table",r);const s=t.getAttribute("data-chart-summary");t.setAttribute("data-summary",s&&Pe.includes(s)?s:a.summary),t.toggleAttribute("data-long",e.length*n.filter(t=>!t.group).length>a.tablelimit)})(t,e);const C=getComputedStyle(t.figure);t.figure.toggleAttribute("data-series-range",!!C.getPropertyValue("--tablechart-series-color-end").trim()),t.figure.toggleAttribute("data-slice-range",!!C.getPropertyValue("--tablechart-slice-color-end").trim());const T=Number.parseFloat(t.figure.dataset.chartAspect??""),_=T>0?T:g.aspect??e.aspect,z="beside"===g.categories,U=t.axes&&!g.axes?t.axes:null,F=z?null:t.categories[0]?.parentElement;let V=null;if(U){a.style.margin="",F&&(F.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=g.segments?.(m)??[],r=t.stacked?m.flatMap(t=>Object.values(gt(t,y.length,g.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):m.flatMap(t=>t.cells.slice(0,y.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:u}=t.figure.dataset,d=Qt(i??u);if(d&&d.length>2)V={min:d[0],max:d[d.length-1],step:0,ticks:d};else{const[t,e]=d??[s,c],a=Yt(e-t,Math.max((z?n/9:n*_/3)/l,2)),o=(t,e)=>d?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);V={min:r,max:i,step:a,ticks:Xt(r,i,a)}}U.ticks.textContent="";const h=m.find(t=>!t.missing),f=P(V.ticks.map(t=>D(String(t))));for(const t of V.ticks){const n=B(k,U.ticks);n.dataset.value=String(t),n.dataset.place="none",h?.prefix&&(n.dataset.prefix=h.prefix),h?.suffix&&(n.dataset.suffix=h.suffix),Je(n,f,e.locale)}if(U.numbers){const t=Array.from(U.ticks.children);for(const e of t)delete e.dataset.place;tt(t),z?a.style.marginBottom=`${(t[0]?et(t[0]).height:0)+6}px`:(a.style.marginLeft=`${P([0,...t.map(t=>et(t).width)])+10}px`,F&&(F.style.marginLeft=a.style.marginLeft))}}const I=a.clientWidth;if(!I)return!1;const j=S/I,W=S*_;a.classList.add("is-placed");const G=!1===g.numbers?w.slice(0,1):[...M.flat(),...t.totals];for(const n of G)delete n.dataset.place,n.removeAttribute("data-left-out"),n.removeAttribute("data-cut");a.style.removeProperty("--_fit"),a.toggleAttribute("data-grouped",!!g.groups&&!t.stacked&&y.filter(t=>!t.chart&&!t.group).length>1),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const K=g.axes?t.axes:null;let Y=[];if(K){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=y.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=m.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:s,chartScaleY:c,chartScale:l}=t.figure.dataset,i=[Qt(s),Qt(c??l)];Y=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=Yt(o-a,e);return{min:a,max:o,step:r,ticks:Xt(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?W/j/(4*n):I/(9*n),4),i[e])),K.ticks.textContent="",Y.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=P(t.ticks.map(t=>D(String(t))));for(const o of t.ticks){const t=B(k,K.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),Je(t,s,e.locale)}})}const X=K?Array.from(K.ticks.children):[];tt([...M.flat(),...t.totals,...v,...t.categories,...A.map(t=>t.badge),...K?.titles??[],...X]);const Z=(w[0]?et(w[0]).height:0)*j;!1===g.numbers&&w[0]&&(w[0].dataset.place="none");const Q=A[0]?.badge?et(A[0].badge).height*j:0,J=Math.max(W,Ke(t.figure,j,"--tablechart-min-height","200px")??0,g.minHeight?.({labelHeight:Z,nameHeight:Math.max(0,P(t.categories.map(t=>et(t).height)))*j,unit:j,rows:m.length,series:y.length,stacked:t.stacked,labels:Ge(t.figure,e,y.some(t=>t.chart))})??0),nt=t.stacked?m.map(t=>{const e=wt(t,y.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):m,at=(g.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?nt.map(t=>({...t,cells:[t.cells[0]]})):m),ot={labelHeight:Z,badgeHeight:Q,hasAnnotations:A.length>0,unit:j,series:y.length,focused:y.some(t=>t.focus),stacked:t.stacked},st=Math.max((ct=P,t.stacked?ct(m.map(t=>gt(t,y.length,g.running).top)):ct([...at.flatMap(t=>[t.from,t.to,t.value]),...m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value))])),0);var ct;const ut=at.some(t=>"up"===t.kind||"down"===t.kind)?at.flatMap(t=>[t.from,t.to]):t.stacked?m.map(t=>gt(t,y.length,g.running).bottom):m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value)),dt=Math.min(-P(ut.map(t=>-t)),0),ht=y.flatMap((t,e)=>t.chart?[e]:[]),ft=m.some(t=>t.note)?Q+4*j:0,bt=Math.max(g.headroom?.(ot)??Z,ht.length?Ft.headroom?.(ot)??0:0)+ft,mt=2*j+(g.footroom?.(ot)??0)+(dt<0?Z+4*j:0),$t=J-bt-mt,pt=V?Math.max(V.max,st):1.02*st,yt=V?Math.min(V.min,dt):1.02*dt,Mt=A.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,vt=t=>{const e=Number.parseFloat(Mt?.getAttribute(t)??"");return Number.isFinite(e)?e:null},xt=vt("data-from")??vt("data-at"),kt=vt("data-to");let Nt=null;if(Mt&&(null!==xt||null!==kt)){const t=xt??0,e=kt??pt,a=null===kt?t:null===xt?e:(t+e)/2,o=Mt.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===kt?.22:.3,.05),.8),c=at.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);g.breakable?dt<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>pt||0===t&&e===pt?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${st}.`):c.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):Nt={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const St=Nt?Nt.gap:null,At=(Nt&&Ke(t.figure,j,"--tablechart-break-gap",""))??13,Ct=J-mt,Ht=pt-yt||1;let Tt,Lt,Ot=t=>Ct-(t-yt)/Ht*$t;if(Nt){const{lo:t,hi:e,gap:n,share:a}=Nt,o=$t*a,r=($t-o-At)/(t+(pt-e)),s=o/(e-t);Ot=a=>a<=t?Ct-a*r:a<=n?Ct-t*r-(a-t)*s:a<=e?Ct-t*r-(a-t)*s-At:Ct-t*r-o-At-(a-e)*r}let _t=[];if(K){const t=6*j,[e,n]=K.titles,a=t=>t?et(t).width*j:0,o=t=>t?et(t).height*j:0,r=X.filter(t=>"x"===t.dataset.axis),s=X.filter(t=>"y"===t.dataset.axis),c=o(X[0]),l=a(n)+P([0,...s.map(a)])+2*t,i=c/2;Lt=[l,i,S-l-P([0,...r.map(a)])/2,J-i-o(e)-c-2*t];const[u,d,h,f]=Lt,[b,m]=Y,$=t=>u+(t-b.min)/(b.max-b.min||1)*h,p=t=>d+f-(t-m.min)/(m.max-m.min||1)*f;Tt=$,Ot=p;const g=t=>a(r.find(e=>Number(e.dataset.value)===t));_t=[Jt(b,e=>e.every((n,a)=>!a||$(n)-$(e[a-1])>(g(n)+g(e[a-1]))/2+t)).ticks,Jt(m,e=>e.every((n,a)=>!a||p(e[a-1])-p(n)>c+t/2)).ticks];for(const w of X){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,a=_t[n].includes(e);w.dataset.place=a?n?"before":"below":"none",a&&E(w,n?u-t:$(e),n?p(e):d+f+t,S,J)}e&&E(e,u+h/2,J-o(e),S,J),n&&E(n,0,d+f/2,S,J)}const Bt=v.length?P(v.map(t=>et(t).width))*j+12*j:0,Et=t.categories[0]?.parentElement;Et&&(Et.style.paddingRight=Bt?Bt/S*100+"%":"");const zt=(S-Bt)/m.length,Ut=t=>t>=0&&t<m.length?t:null;t.rowAt=g.centre?null:"beside"===g.categories?(t,e)=>Ut(Math.floor(e*j/(J/m.length))):t=>Ut(Math.floor(t*j/zt));const Rt=zt/S*100,qt=100/m.length;if(t.rowBox="beside"===g.categories?t=>[0,t*qt,100,qt]:t=>[t*Rt,0,Rt,100],r.setAttribute("viewBox",`0 0 1000 ${L(J)}`),r.textContent="",Lt&&Tt){const[n,a,o,s]=Lt,[c,l]=_t,i=Tt;Fe(t.figure,"data-chart-grid",e.grid)&&r.appendChild(O("path",{class:N,d:[...c.map(t=>`M${L(i(t))},${L(a)}V${L(a+s)}`),...l.map(t=>`M${L(n)},${L(Ot(t))}H${L(n+o)}`)].join("")})),r.appendChild(O("path",{class:x,d:[`M${L(n)},${L(a)}V${L(a+s)}H${L(n+o)}`,...c.map(t=>`M${L(i(t))},${L(a+s)}v${L(4*j)}`),...l.map(t=>`M${L(n)},${L(Ot(t))}h${L(-4*j)}`)].join("")}))}t.checks=[];const It={rows:m,segments:at,cx:t=>(t+.5)*zt,y:Ot,x:Tt,frame:Lt,length:(e,n)=>Ke(t.figure,j,e,n),barWidth:Math.min(zt*e.barfill,Ye(t.figure,j)),barMax:Ye(t.figure,j),height:J,unit:j,labelHeight:Z,badgeHeight:Q,after:m.length,note:0,labels:Ge(t.figure,e,ht.length>0),insideAlign:We(t.figure),breakAt:St,squeeze:Nt,breakGap:At,domain:V?[V.min,V.max]:null,stacked:t.stacked,shape:Re(t.figure,e),pick:Ze(t.figure,e),totals:t.totals,svg:r,plot:a,values:w,series:y,own:y.map((t,e)=>e),seriesValues:M,names:v,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[],lineHoles:[]};a.style.setProperty("--count",String(Math.max(1,...m.map(t=>t.slot+1))));const jt=t=>{const e=e=>({...e,...e.cells[t]??e.cells[0]});return{rows:m.map(e),segments:at.map(t=>{const n=e(t);return"bar"===t.kind?{...n,to:n.value}:n}),values:M[t]}};if(ht.length){const t=y.flatMap((t,e)=>t.chart?[]:[e]);g.draw({...It,own:t,...1===t.length&&jt(t[0])}),Ft.draw({...It,own:ht})}else g.draw(It);It.rowAt&&(t.rowAt=It.rowAt),t.pointOf=It.pointOf??null;const Pt=Number(a.style.getPropertyValue("--count"))||m.length;for(const n of t.figure.querySelectorAll(`.${f}`))n.style.setProperty("--i",String(Math.min(m[m.length-1].slot,Pt-1)));if(!t.stacked&&!a.hasAttribute("data-grouped"))for(const n of M)lt(n,j,S),it(n,j,S,J);if(U&&V){const n=6*j,a=z&&It.x?It.x:Ot,o=Array.from(U.ticks.children),s=t=>et(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Jt(V,t=>t.every((e,o)=>!o||(z?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*j+n:a(t[o-1])-a(e)>s(e).height*j+n/2))).ticks.filter(t=>!Nt||t<=Nt.lo||t>=Nt.hi);for(const t of o){const e=Number(t.dataset.value),o=U.numbers&&c.includes(e);t.dataset.place=o?z?"below":"before":"none",o&&E(t,z?a(e):-n,z?J+n:a(e),S,J)}const l=S-Bt;Fe(t.figure,"data-chart-grid",e.grid)&&r.prepend(O("path",{class:N,d:c.map(t=>z?`M${L(a(t))},0V${L(J)}`:`M0,${L(a(t))}H${L(l)}`).join("")})),U.numbers&&r.appendChild(O("path",{class:x,d:[z?`M${L(a(V.min))},${L(J)}H${L(a(V.max))}`:`M0,${L(a(V.max))}V${L(a(V.min))}`,...c.map(t=>z?`M${L(a(t))},${L(J)}v${L(4*j)}`:`M0,${L(a(t))}h${L(-4*j)}`)].join("")}))}for(const[n,o]of A.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series;o.type.draw(o.spec,o.badge,{...It,...t.stacked&&{rows:nt,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&jt(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=Boolean(t.type.axes),l=(t,e,n,a)=>{c&&"--i"===n||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&&l(o,n.step,"--after",n.after);continue}const c=o.dataset.row?Number(o.dataset.row)-1:n;if(o.classList.contains("tablechart-connector")){const t=e.rows[c-1],n=e.rows[c];if(t&&n){const e=(t.step??-1)>(n.step??-1);l(o,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(s.has(o)){const t=a(c).filter(t=>null!==t);l(o,t.length?Math.max(...t):null,"--i",e.rows[c]?.slot??0);continue}if(o.hasAttribute("data-stack")){l(o,r(c),"--i",e.rows[c]?.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(c)[i]??null,n=e.cells[c]?.[i];l(o,t===r(c)?null:t,"--i",n&&null!==n.step?n.slot:c);continue}if("legend"===o.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(o,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[c]?.[i];d&&null!==d.step?l(o,d.step,"--i",d.slot):u&&null!==u.step?l(o,u.step,"--i",c):e.rows[c]&&l(o,e.rows[c].step,"--i",e.rows[c].slot)}const i=t.figure.querySelector(`.${p}`);if(i){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?l(i,null,"--i",0):l(i,n,"--i",t.filter(t=>t===n).length)}const d=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),h=e.series.some(t=>null!==t.step)?e.rows.length:1;c||t.plot.style.setProperty("--count",String(Math.max(h,...d)));const f=t.figure.querySelectorAll(`.${o}`),b=f[f.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&f.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${u}`));if(m.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=m.length,o=Math.max(0,m.findIndex((t,n)=>e(t)!==e(m[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=m[(o+t)%a],s=r[r.length-1];s&&e(s[0])===e(n)?s.push(n):r.push([n])}const s=new Map;for(const t of r){const e=t.reduce((t,e)=>t+n(e),0);let a=0;for(const o of t)s.set(o.dataset.row??"",H(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))}}le(t)})(t);for(const n of t.figure.querySelectorAll(`.${b}`)){const e=Array.from(n.children);if(t.plan)for(const t of e)t.style.getPropertyValue("--step")||t.style.setProperty("--i","0");const a=e.map(t=>Number.parseFloat(t.style.getPropertyValue("--step")));n.style.setProperty("--i",String(Math.min(...e.map(t=>Number(t.style.getPropertyValue("--i"))||0)))),a.length&&a.every(Number.isFinite)?n.style.setProperty("--step",String(Math.min(...a))):n.style.removeProperty("--step")}const Dt=t.categories[0]?.parentElement;if(Dt&&"beside"!==g.categories&&!g.centre){Dt.style.height=`${Dt.offsetHeight}px`,Dt.removeAttribute("data-thinned");for(const e of t.categories)e.removeAttribute("data-left-out"),e.removeAttribute("data-edge");const n=t.categories.filter(t=>null!==t.offsetParent);if(!rt(Dt,n,t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit")&&n.length>1){const t=getComputedStyle(Dt),e=(Dt.clientWidth-Number.parseFloat(t.paddingLeft)-Number.parseFloat(t.paddingRight))/m.length;Dt.style.setProperty("--_name-fit","1"),Dt.setAttribute("data-thinned","");const a=P(n.map(t=>t.offsetWidth)),o=8,r=Math.max(Math.ceil((a+o)/e),Math.ceil((1.5*a+o)/e-.5),1);n.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")});const s=n.filter(t=>!t.hasAttribute("data-left-out")),c=s[0],l=s.at(-1),i=Dt.getBoundingClientRect(),u=[c,l].map(t=>t?.getBoundingClientRect());if(c&&u[0]&&u[0].left<i.left&&c.setAttribute("data-edge","start"),l&&l!==c&&u[1]&&u[1].right>i.right-Number.parseFloat(t.paddingRight)){l.setAttribute("data-edge","end");const t=s.at(-2);t&&t.getBoundingClientRect().right+o>l.getBoundingClientRect().left&&l.setAttribute("data-left-out","")}}const a=(g===Ft||g===Vt)&&Fe(t.figure,"data-chart-ticks",e.ticks);if(Dt.toggleAttribute("data-ticks",a),Dt.style.removeProperty("--_tick-reach"),a){const e=J-Number(r.querySelector(".tablechart-rule")?.getAttribute("y1")??J);e>0&&e<10*j&&Dt.style.setProperty("--_tick-reach",`${L(e/j)}px`);const n=Dt.getBoundingClientRect(),a=n.width/(Dt.offsetWidth||1),o=getComputedStyle(Dt),s=Number.parseFloat(o.paddingLeft),c=(Dt.clientWidth-s-Number.parseFloat(o.paddingRight))/m.length;t.categories.forEach((t,e)=>{if(t.hasAttribute("data-left-out"))t.style.removeProperty("--_tick");else{const o=(t.getBoundingClientRect().left-n.left)/a-Dt.clientLeft;t.style.setProperty("--_tick",`${L(s+(e+.5)*c-o)}px`)}})}Dt.style.height=""}const Wt=A.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*j,n=t.offsetHeight*j,a=Number.parseFloat(t.style.left)/100*S,o=Number.parseFloat(t.style.top)/100*J,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*j;return[O("rect",{class:$,"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("; ")})]}),Gt=r.querySelector(`.${N}`),Kt=Array.from(r.querySelectorAll(`.${c}`)),Zt=[...Gt?[Gt]:[],...r.querySelectorAll(`:scope > .${l}`)],te=((t,e)=>{const n=t.getBoundingClientRect(),a=S/n.width,o=getComputedStyle(t),r=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2;return t=>{if("none"===t.dataset.place||t.hidden||t.hasAttribute("data-left-out"))return[];const o=t.getBoundingClientRect(),s=o.height*a/r,c=Array.from(t.style).filter(t=>t.startsWith("--")).map(e=>`${e}:${t.style.getPropertyValue(e)}`);return o.width?[O("rect",{class:$,"data-for":"text",x:(o.left-n.left)*a-3*e,y:(o.top-n.top)*a+(o.height*a-s)/2-e,width:o.width*a+6*e,height:s+2*e,style:c.join("; ")})]:[]}})(a,j),ee="grow"===t.figure.getAttribute("data-animate"),ne=M.flat().filter(t=>t.hasAttribute("data-cut")).flatMap(te),ae=[...ht.flatMap(t=>M[t].flatMap(te)),...ee?ne:[]];if(Zt.length||Kt.length){const e=[...M.flat(),...t.totals,..."beside"===g.categories?t.categories:[]].flatMap(te),n=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Kt)Ee(t,[...e,...Wt].map(n));if(Zt.length&&t.plan)q(r,e,S,J,Zt);else for(const t of Zt){const a=[...e,...Wt],o=ze(t);t.setAttribute("d",o.map(([t,e,o,r])=>Be(t,e,o,r,a.map(n))).join(""));for(const e of a){const a=Ue(o,n(e)),r="badge"===e.dataset.for?"badge":"";a&&t.after(O("path",{class:t.getAttribute("class")??"tablechart-grid","data-gap":r,d:a,style:e.getAttribute("style")??""}))}}}if(R(r,Wt,S,J,Array.from(r.querySelectorAll(`.${s}, .${i}`))),!ee&&(It.lineHoles.length||ne.length)){const t=Array.from(r.querySelectorAll(`.${d}`)).map(t=>{const e=O("g",{});return t.before(e),e.append(t),e});R(r,[...It.lineHoles,...ne],S,J,[...t,...r.querySelectorAll(`.${h}`)])}const oe=[c,l,s,i,...t.plan?[]:[N]];q(r,[...Wt,...ae],S,J,void 0,oe.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||nn(r);const re=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(g.columns?[t.categories]:[...M,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||g.centre&&m[Number(t.dataset.row)-1]?.isTotal)(e)&&!re(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>re(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),se(t.figure),!0})(a,e))&&(It.enabled&&!m&&((t=>{const e=oe(t),a=Array.from(t.querySelectorAll("table thead tr:first-child > *")).map(t=>(t.textContent??"").trim()),o=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),r=[[".tablechart-series","Line",t=>getComputedStyle(t).stroke],[".tablechart-slice","Slice",t=>getComputedStyle(t).stroke],[".tablechart-bar, .tablechart-piece","Bar",t=>getComputedStyle(t).fill]],s=new Map;for(const[n,c,l]of r){const r=Array.from(t.querySelectorAll(`${n}:not([data-muted])`));for(const t of r){const n=l(t),[i,u,d,h]=ee(n),f=[i,u,d].map((t,n)=>t*h+e[n]*(1-h)),b=ae(f,e);if(b>=3)continue;const m=t.getAttribute("data-series"),$=o[Number(t.getAttribute("data-row")??0)-1]??"",p="Slice"===c?"":m?a[Number(m)]:"",g=`${c}|${p}|${n}`,w=s.get(g)??{kind:c,column:p,rows:new Set,all:0,contrast:b};w.rows.add($),w.all=r.filter(t=>t.getAttribute("data-series")===m).length,s.set(g,w)}}for(const{kind:c,column:l,rows:i,all:u,contrast:d}of s.values()){const e=Array.from(i).filter(Boolean).map(t=>`"${t}"`),a=e.join(", "),o=e.length>1,r="Line"===c?l?`Line "${l}" has`:"The line has":"Slice"===c?`${o?"Slices":"Slice"} ${a} ${o?"have":"has"}`:i.size>=u||!a?`The bars${l?` of column "${l}"`:""} have`:`${o?"Bars":"Bar"} ${a}${l?` in column "${l}"`:""} ${o?"have":"has"}`;console.warn(`[${n}] ${r} a contrast of ${(Math.floor(100*d)/100).toFixed(2)}:1 with the background. It needs at least 3:1 (WCAG 1.4.11).`,t)}})(a.figure),(t=>{const e=()=>{const e=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),a=new Map;for(const n of t.querySelectorAll(".tablechart-value[data-place='inside'], .tablechart-value[data-place='middle']")){if(n.hasAttribute("data-left-out")||n.hidden)continue;const o=n.dataset.row,r=re(t,n);if(!r)continue;const s=getComputedStyle(n),c=getComputedStyle(r).fill,l=ee(s.color),i=ee(c),u=ae(l,i),d=Number.parseFloat(s.fontSize),h=d>=24||d>=18.66&&Number(s.fontWeight)>=700?3:4.5;if(u>=h)continue;const f=`${s.color}|${c}`,b=a.get(f)??{names:[],contrast:u,needed:h};b.names.push(`"${n.textContent?.trim()}" (${e[Number(o)-1]??""})`),a.set(f,b)}for(const{names:o,contrast:r,needed:s}of a.values())console.warn(`[${n}] ${o.length>1?"Numbers":"Number"} ${o.join(", ")} inside ${o.length>1?"their bars have":"its bar has"} a contrast of ${(Math.floor(100*r)/100).toFixed(2)}:1 with the bar. Text needs at least ${s}:1 (WCAG 1.4.3).`,t)},a=()=>setTimeout(e,3e3);if(t.classList.contains("is-shown"))return void a();const o=new MutationObserver(()=>{t.classList.contains("is-shown")&&(o.disconnect(),a())});o.observe(t,{attributes:!0,attributeFilter:["class"]})})(a.figure)),m=t,y())};let C=!1;const T=new ResizeObserver(()=>{C||(C=!0,requestAnimationFrame(()=>{C=!1,A()}))}),_=new IntersectionObserver(t=>{for(const e of t)g=e.isIntersecting,y()},{threshold:e.threshold}),z=()=>{a.figure.classList.add(M),tn(a,!0),an(a.svg),a.figure.offsetWidth},U=()=>a.figure.classList.remove(M),F=()=>{m=null,A()},V={relabel:()=>Qe(a,e),refresh:F};v(),A(),T.observe(a.figure),_.observe(a.figure),window.addEventListener("beforeprint",z),window.addEventListener("afterprint",U),(t=>{mn.add(t),$n||($n=new MutationObserver(()=>{for(const t of mn)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of mn)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(V);const I={figure:a.figure,refresh:F,next:()=>ie(a,a.step+1),previous:()=>ie(a,a.step-1),stepTo:t=>ie(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){T.disconnect(),_.disconnect(),window.removeEventListener("beforeprint",z),window.removeEventListener("afterprint",U),(t=>{mn.delete(t),!mn.size&&$n&&($n.disconnect(),$n=null)})(V),Ce(a),a.figure.tablechart===I&&delete a.figure.tablechart}};return a.figure.tablechart=I,I})(a,e)):null},vn=!1,xn=()=>{vn||"function"!=typeof matchMedia||(vn=!0,matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{for(const t of document.querySelectorAll(`[${fn}]`))se(t)}))},kn=e({GRID_CLASS:()=>N,LEGEND_CLASS:()=>b,LIBRARY_NAME:()=>n,NAME_CLASS:()=>f,POINT_CLASS:()=>m,QUADRANT_CLASS:()=>l,VIEWBOX_WIDTH:()=>S,avoidCollisions:()=>Q,boxOf:()=>ct,decimalsIn:()=>D,htmlEl:()=>B,largest:()=>P,markerEl:()=>Ht,overlaps:()=>Z,placeAt:()=>E,readSeries:()=>Gt,readTable:()=>Dt,short:()=>L,sizeOf:()=>et,splitSign:()=>W,svgEl:()=>O});window.Tablechart={init:async(t={},e=document)=>{const n={...A,...t};n.debug&&(It.enabled=!0);const a=(await yn(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Mn(t,n)).filter(t=>null!==t);return It.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={...A,...e};n.debug&&(It.enabled=!0);const[a]=await yn([t],n);return a?Mn(a,n):null},defaultConfig:A,addType:(t,e)=>{He[t]=e,Object.assign(Te,e.annotations),Le.splice(0,1/0,...Object.keys(Te))},kit:kn}}();
@@ -1 +1 @@
1
- export { c as addType, t as create, N as defaultConfig, r as init } from "./tablechart-shared.mjs";
1
+ export { c as addType, t as create, G as defaultConfig, r as init } from "./tablechart-shared.mjs";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@martinomagnifico/tablechart",
3
- "version": "1.1.3",
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.",
3
+ "version": "1.2.1",
4
+ "description": "Simple charts from an HTML or Markdown table: column, bar, line, area, waterfall, donut and scatter plot. Accessibility first.",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
7
  "**/*.css",
@@ -24,6 +24,10 @@
24
24
  "types": "./dist/tablechart-additional-types.d.mts",
25
25
  "import": "./dist/tablechart-additional-types.mjs"
26
26
  },
27
+ "./summary": {
28
+ "types": "./dist/tablechart-summary.d.mts",
29
+ "import": "./dist/tablechart-summary.mjs"
30
+ },
27
31
  "./style.css": "./dist/tablechart.css"
28
32
  },
29
33
  "files": [
@@ -42,11 +46,14 @@
42
46
  "check:variables": "node scripts/variables.mjs",
43
47
  "docs:preview": "npm run build && cd docs && rm -rf dist && npm run build && npm run preview",
44
48
  "preview": "npm run docs:preview",
49
+ "prebuild": "node scripts/lock-version.mjs",
45
50
  "build": "npm run clean && npm run build:lib",
46
51
  "build:lib": "vite build",
47
52
  "size": "node scripts/size.mjs",
48
53
  "test": "npm run build && node test/speed.test.mjs",
49
54
  "test:layout": "node test/layout.test.mjs",
55
+ "lab": "node lab/pdf/lab.mjs",
56
+ "lab:pdf": "node lab/pdf/lab.mjs --pdf",
50
57
  "prepack": "npm run build",
51
58
  "clean": "rm -rf dist"
52
59
  },
@@ -62,6 +69,7 @@
62
69
  "license": "MIT",
63
70
  "devDependencies": {
64
71
  "@vituum/vite-plugin-pug": "^2.0.1",
72
+ "liquidjs": "^10.30.0",
65
73
  "rolldown-plugin-dts": "^0.28.8",
66
74
  "sass": "^1.97.3",
67
75
  "terser": "^5.46.0",