@martinomagnifico/tablechart 1.1.0 → 1.1.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-head",l="tablechart-slice",i="tablechart-name",u="tablechart-legend",d="tablechart-point",h="tablechart-hole",f="tablechart-centre",b="tablechart-break",m="tablechart-sr",p="is-printing",g="tablechart-axis",$="tablechart-tick",w="tablechart-grid",y=1e3,M={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"},v="cubic-bezier(0.3, 0.3, 0.6, 1)",x=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?v:"linear"}),k=(t,e)=>`${t}:${e}`,N=t=>Math.round(100*t)/100,A=(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?N(t):t))}return n},S=(t,e)=>[t,...e.classes].join(" "),H=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},C=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},T=0,L=(t,e,n,a,o)=>{if(!e.length)return;const r="tablechart-cut-"+ ++T,s=A("mask",{id:r,maskUnits:"userSpaceOnUse"});s.appendChild(A("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const i of e)i.setAttribute("fill","black"),s.appendChild(i);let c=t.querySelector(":scope > defs");if(c||(c=A("defs"),t.prepend(c)),c.appendChild(s),o)return o.setAttribute("mask",`url(#${r})`);const l=A("g",{mask:`url(#${r})`});for(const i of Array.from(t.childNodes))i!==c&&l.appendChild(i);t.appendChild(l)},O=0,z={create:()=>null,draw(t,e,n){const{rows:a,y:r,svg:s,breakAt:c}=n;if(null===c)return;const l="zigzag"===t.getAttribute("data-mark"),i=(t,e)=>{const n=t.sideways?t.height:t.width,a=.09*n,o=n+2*a,r=.3*o,s=.06*o;if(t.sideways){const n=t.y-a;if(!l)return[[e-r/2,n],[e+r/2,n+o]];const c=o/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+o]]}const c=t.x-a;if(!l)return[[c,e+r/2],[c+o,e-r/2]];const i=o/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+o,e-s]]},u=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),d="tablechart-break-"+ ++O,h=A("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(A("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(A("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[k("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(A("path",{class:b,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const p=Array.from(s.querySelectorAll(`.${b}`)),g=A("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))p.includes(o)||g.appendChild(o);const $=A("defs");$.appendChild(h),s.prepend($,g)}},E=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},B=t=>(t.split(/[.,]/)[1]||"").length,_=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),U=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const a of Array.from(t.children))n.appendChild(a.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},F=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=_(s),l=r?.5:.5*10**-B(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.`)},V={create:U,draw(t,e,a){const{rows:o,cx:r,y:l,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:f,after:b}=a,[m,p]=((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),g=o[m],$=o[p];if(!g||!$)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${m+1} to ${p+1}, of ${o.length}).`);const w=7*i,M=4*i,v=r(m),x=r(p),N=Math.min(l(g.value),l($.value))-u-M-.9*d,S=t=>l(t)-u-M,H=`M ${v} ${S(g.value)} L ${v} ${N} L ${x} ${N} L ${x} ${S($.value)-w}`,T=(S(g.value)-N+Math.abs(x-v)+(S($.value)-w-N))/i+1;f.appendChild(A("path",{class:s,"data-note":a.note,d:H,style:`--len:${T.toFixed(1)}; ${k("--after",b)}`}));const L=S($.value);var O;f.appendChild(A("polygon",{class:c,"data-note":a.note,points:`${x},${L} ${x-.45*w},${L-w} ${x+.45*w},${L-w}`,style:k("--after",b)})),e&&(C(e,(v+x)/2,N,y,h),e.style.setProperty("--after",String(b))),F(e,(O=g.value,($.value-O)/Math.abs(O)*100),`${g.value} to ${$.value}`,a)}},P=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let a=1;for(const l of t)for(const[,,t,e]of l)a=Math.max(a,t,e);const o=new Map,r=([t,e,n,o])=>{const r=[];for(let s=Math.floor(t/a);s<=Math.floor((t+n)/a);s++)for(let t=Math.floor(e/a);t<=Math.floor((e+o)/a);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))o.get(e)?.push(t)??o.set(e,[t])},c=t=>((t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[0]+t[2]<=e[0]+e[2]&&t[1]+t[3]<=e[1]+e[3])(t,n)&&r(t).every(e=>!o.get(e)?.some(e=>{return a=e,(n=t)[0]<a[0]+a[2]&&a[0]<n[0]+n[2]&&n[1]<a[1]+a[3]&&a[1]<n[1]+n[3];var n,a}));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},j=new WeakMap,q=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]))},D=t=>j.get(t)??{width:t.offsetWidth,height:t.offsetHeight},I=(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},R={create(t,e){if(!t.textContent?.trim())return null;const n=U(t,e);return n.dataset.kind="reference",n},draw(t,e,a){const{rows:o,cx:r,y:s,x:c,height:l,unit:i,svg:u,after:d}=a,h=o.filter(t=>!t.isTotal&&!t.missing),f=t.hasAttribute("data-name"),b=(t.getAttribute(f?"data-name":"data-value")??"").trim();let m,p,g;if(f){const t=h.map(t=>_(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=I(b,t,h.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[h[s],h[s+1]??h[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]);g=e,p=s<0?null:c+i*(l-c),m=!1}else g=I(b,h.map(t=>t.value),h.map(()=>1)),m=!c,p=null===g?null:c?c(g):s(g);if(null===p||null===g)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${b}".`);const $=o.length>0?r(o.length-1)+r(0):y,w=c?l:s(0);if(u.appendChild(A("line",{class:"tablechart-reference","data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...m?{x1:0,x2:$,y1:p,y2:p}:{x1:p,x2:p,y1:0,y2:w},style:k("--after",d)})),e){const t=D(e).width*i,n=D(e).height*i,o=4*i,r=m?[[$-t,p-n/2,t,n],[$-t,p-n-o,t,n],[$-t,p+o,t,n]]:[0,n,2*n].flatMap(e=>[[p-t/2,e,t,n],[p+o,e,t,n],[p-o-t,e,t,n]]),[s]=P([r],a.taken,[0,0,y,l]),c=r[s??0];a.taken.push(c),C(e,c[0]+t/2,c[1]+n/2,y,l),e.style.setProperty("--after",String(d)),"mean"!==b&&"median"!==b||F(e,g,`the ${b}`,a,"")}}},W={create:U,draw(t,e,n){const{rows:a,cx:o,y:r,unit:l,labelHeight:i,height:u,svg:d,values:h,after:f}=n,b=a[0],m=a[a.length-1];if(!b||!m)return;const p=i+18*l,g=10*l,$=10*l;let w=o(0),M=r(b.value)-p,v=o(a.length-1),x=r(m.value)-p,N=0;a.forEach((t,e)=>{const n=v===w?0:(o(e)-w)/(v-w),a=M+n*(x-M)-(r(t.value)-p);a>N&&(N=a)}),M-=N,x-=N;const S=v-w,H=x-M,T=Math.hypot(S,H)||1,L=S/T,O=H/T;w-=L*g,M-=O*g,v+=L*g,x+=O*g;const z=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(v-w)*z,n=M+(x-M)*z,s=D(e).width*l/2,c=n+D(e).height*l/2+8*l;let u=0;a.forEach((e,n)=>{const a=(h[n]?D(h[n]).width:0)*l/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*l-i;u=Math.max(u,c-d)}),M-=u,x-=u}const E=v-L*$,B=x-O*$,_=Math.hypot(E-w,B-M)/l+1;d.appendChild(A("line",{class:s,"data-note":n.note,x1:w,y1:M,x2:E,y2:B,style:`--len:${_.toFixed(1)}; ${k("--after",f)}`}));const U=-O,V=L,P=.42*$;d.appendChild(A("polygon",{class:c,"data-note":n.note,points:[`${v},${x}`,`${E+U*P},${B+V*P}`,`${E-U*P},${B-V*P}`].join(" "),style:k("--after",f)})),e&&(C(e,w+(v-w)*z,M+(x-M)*z,y,u),e.style.setProperty("--after",String(f)));const j=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(j)&&j>0&&F(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,j),`${b.value} to ${m.value} over ${j} years`,n)}},G=(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}},K=(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}); ${k("--i",e.slot)}`}},X=(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}})},Y=(t,e,n=!1)=>{const a=X(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},Z=(t,e)=>{const{top:n,bottom:a}=Y(t,e);return n+a},J=(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})`)},Q=(t,e,n,a={},r="")=>{const s={class:S(o,e),"data-kind":"bar","data-row":n+1,...a},c=k("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=A("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(A("rect",{...s,...r,class:S("tablechart-piece",e),"data-row":n+1,...K(t,e,o)}))}},tt=(t,e,n)=>t.some(t=>D(t).width*n>e-6*n),et=(t,e,n)=>e>=D(t).height*n*1.6,nt=(t,e,n)=>e>=D(t).width*n*1.5,at=(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},ot={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(E(l.map(t=>D(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/y*100).toFixed(2)}%`);const b=y-4*a,m=t.stacked?Math.max(E(t.rows.map(e=>Y(e,t.series.length).top)),0)||1:Math.max(E(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,p=t.stacked?Math.max(E(t.rows.map(e=>-Y(e,t.series.length).bottom)),0):Math.max(E(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),g=Math.max(m,t.domain?.[1]??0),$=Math.max(p,-(t.domain?.[0]??0)),w=Math.max(g,t.squeeze?.hi??0)+$,M=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),w,n,t.squeeze,t.breakGap),v=n/e.length,x=t=>(t+.5)*v,N=Math.min(v*i.barfill,u),H=G(v,t.series.length,u),T=c[0]??t.totals[0],L=T?D(T).height*a*.56:0,O=Math.max(((d&&!t.stacked?H.size:N)-L)/2,5*a),z=t=>D(t).width*a,B=t=>t.length?E(t.map(z))+O+4*a:0,_=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,U=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:_(e,n)}))),F=e=>{const n=Y(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let V=t.stacked?B(t.totals.filter((t,e)=>!F(e))):d?B(U.filter(t=>t.value>=0).map(t=>t.label)):0,P=t.stacked?B(t.totals.filter((t,e)=>F(e))):d?B(U.filter(t=>t.value<0).map(t=>t.label)):0;if(!d&&!t.stacked)for(let o=0;o<3;o++){const t=b-f-V-P,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!nt(n,M(e.value,t),a)),o=B(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),r=B(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(o<=V&&r<=P)break;V=Math.max(V,o),P=Math.max(P,r)}const j=b-f-V-P,q=f+P+M($,j),I=t=>t<0?q-M(t,j):q+M(t,j);if(t.squeeze&&(t.breakX=I(t.squeeze.gap)),t.x=I,t.stacked)return t.rows.forEach((e,o)=>{const r=Y(e,t.series.length),s=Q(t,e,o,{"data-grow":"right"},r.bottom<0?q-I(r.bottom)+"px center":""),c=x(o)-N/2;X(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(I(e),I(r)),h=Math.max(I(e),I(r));s(i,{x:d,y:c,width:Math.max(h-d,1),height:N,...r<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!nt(u,h-d,a)||D(u).height*a>N),J(u,t,i),C(u,(d+h)/2,x(o),y,n)});const i=t.totals[o];i&&(i.dataset.place=F(o)?"before":"after",C(i,F(o)?I(r.bottom)-O:I(r.top)+O,x(o),y,n));const u=l[o];u&&C(u,f-8*a,x(o),y,n)}),void s.appendChild(A("line",{class:r,x1:q,x2:q,y1:0,y2:n}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=at(t.plot,e,t=>({size:D(t).height*a,room:H.size+.5*H.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=I(i.value),h=i.value<0,f=x(r)+H.offset(l);s.appendChild(A("rect",{class:S(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:Math.min(d,q),y:f,width:Math.max(Math.abs(d-q),1),height:H.size,...K(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),C(u,h?d-O:d+O,f+H.size/2,y,n)});const i=l[r];i&&C(i,f-8*a,x(r),y,n)}),void s.appendChild(A("line",{class:r,x1:q,x2:q,y1:0,y2:n}))}const R=e.map((t,e)=>nt(c[e],Math.abs(I(t.value)-q),a));e.forEach((e,r)=>{const i=I(e.value),u=x(r),d=e.value<0,h=Math.abs(i-q);s.appendChild(A("rect",{class:S(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:Math.min(i,q),y:u-N/2,width:Math.max(h,1),height:N,style:k("--i",e.slot)}));const b=c[r],m=Math.max(Math.min(O,h-z(b)-6*a),6*a),p=d?1:-1;b.dataset.place=R[r]?"inside":d?"before":"after",b.dataset.kind=e.kind,C(b,R[r]?"center"===t.insideAlign?(q+i)/2:"start"===t.insideAlign?q-p*(m+z(b)/2):i+p*(m+z(b)/2):i-p*O,u,y,n);const g=l[r];g&&C(g,f-8*a,u,y,n)}),s.appendChild(A("line",{class:r,x1:q,x2:q,y1:0,y2:n}))}},rt={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=Y(e,t.series.length),i=Q(t,e,o,{},r.bottom<0?`center ${f-a(r.top)}px`:""),u=n(o)-s/2;X(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 b=Math.min(a(r),a(e)),m=Math.max(a(r),a(e));i(h,{x:u,y:b,width:s,height:Math.max(m-b,1),...r<e&&{"data-grow":"down"}}),f.dataset.place="inside",f.toggleAttribute("data-left-out",!et(f,m-b,l)||D(f).width*l>s-4*l),J(f,t,h),C(f,n(o),(b+m)/2,y,c)});const d=t.totals[o];if(d){const t=0===r.top&&r.bottom<0;d.dataset.place=t?"below":"outside",C(d,n(o),t?a(r.bottom)+4*l:a(r.top)-4*l,y,c)}}),void i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}));if(t.series.length>1){const e=n(1)-n(0)||2*n(0),s=G(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=at(t.plot,u,t=>({size:D(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((u,h)=>{const b=e.cells[h]??e.cells[0],m=t.seriesValues[h][r],p=n(r)+s.offset(h);if(b.missing)return void(m.dataset.place="none");const g=a(b.value),$=b.value<0;i.appendChild(A("rect",{class:S(o,e),"data-kind":"bar","data-row":r+1,...$&&{"data-grow":"down"},x:p,y:Math.min(g,f),width:s.size,height:Math.max(Math.abs(f-g),1),...K(t,e,h)})),m.dataset.place=$?"below":"outside",m.toggleAttribute("data-left-out",!d),C(m,p+s.size/2,$?g+4*l:g-4*l,y,c)})}),void i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}))}const b=tt(u,s,l),m=e.map((t,e)=>"inside"===d&&!b&&!t.missing&&et(u[e],Math.abs(f-a(t.value)),l)),p=u[0]?D(u[0]).height*l*.56:0;let g=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())m[o]&&(g=Math.min(g,(s-D(r).width*l)/2));e.forEach((t,e)=>{const r=a(t.value),d=t.value<0;if(t.missing)return C(u[e],n(e),f-4*l,y,c),void(u[e].dataset.place="outside");i.appendChild(A("rect",{class:S(o,t),"data-kind":t.kind,"data-row":e+1,...d&&{"data-grow":"down"},x:n(e)-s/2,y:Math.min(r,f),width:s,height:Math.max(Math.abs(f-r),1),style:k("--i",t.slot)}));const b=d?-1:1,$=Math.min(g,(Math.abs(f-r)-p)/2),w="center"===h?(r+f)/2:"start"===h?f-b*($+p/2):r+b*($+p/2),M=d?r+4*l:r-4*l;C(u[e],n(e),m[e]?w:M,y,c),u[e].dataset.place=m[e]?"inside":d?"below":"outside"}),i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}))}},st=0,ct={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 i=500,u=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,f=Math.max(Math.min(y,e)/2-h,10),b=f*s.ringfill,m=f-b/2,p=2*Math.PI*m,g=[];let $=0,w=0,M=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,v=x(M,h),N=`--share:${h.toFixed(4)}; --start:${v.start.toFixed(4)}; --span:${v.span.toFixed(4)};`,H=h*p,T=$/p*2*Math.PI-Math.PI/2;g.push(T),o.appendChild(A("circle",{class:S(l,t),"data-slice":w+1,"data-row":s+1,cx:i,cy:u,r:m,"stroke-width":b,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${H.toFixed(1)} ${(p-H).toFixed(1)}`,"stroke-dashoffset":(-$).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${H.toFixed(1)}; --circ:${p.toFixed(1)}; ${N} --ease:${v.easing}; ${k("--i",t.slot)}`}));const L=T+H/p*Math.PI,O=Math.cos(L),z=Math.sin(L);o.appendChild(A("line",{class:"tablechart-leader",x1:i+O*(f+2*n),y1:u+z*(f+2*n),x2:i+O*(f+7*n),y2:u+z*(f+7*n),"data-row":s+1,style:`${N} ${k("--i",t.slot)}`})),c.style.setProperty("--start",v.start.toFixed(4)),c.style.setProperty("--span",v.span.toFixed(4));const E=f+9*n,B=D(c).width*n/2;C(c,i+O*(E+Math.abs(O)*B),u+z*(E+Math.abs(z)*a*.7),y,e),c.dataset.place="around",$+=H,M+=h,w+=1}),g.length>1){const t=m-b/2-1,n=m+b/2+1,a="tablechart-slices-"+ ++st,r=A("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(A("rect",{x:0,y:0,width:y,height:e,fill:"white"}));for(const e of g)r.appendChild(A("line",{class:"tablechart-divide",x1:i+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:i+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const s=A("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${l}`)))s.appendChild(e);const c=A("defs");c.appendChild(r),o.prepend(c,s)}c&&C(c,i,u,y,e)}},lt=["circle","square","diamond"],it=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=lt.find(t=>n.includes(t));return{shape:a??lt[Math.floor(e/2)%lt.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},ut=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return A("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return A("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return A("polygon",{points:`${e},${n-t} ${e+.87*t},${n+t/2} ${e-.87*t},${n+t/2}`,...o})}return A("circle",{cx:e,cy:n,r:a,...o})},dt=t=>Number(t.toFixed(2));function ht(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 ft,bt,mt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),pt=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:f,svg:b,stacked:m}=e,p="step"===e.shape,g="smooth"===e.shape,$=a.length>1,w=a.some(t=>t.focus),M=n.length-1,v=l(0),x=n.length>1?c(1)-c(0):2*c(0);b.style.setProperty("--_base",`${dt(v)}px`);const k=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],N=(t,e)=>!k(t,e)||!!k(t,e)?.missing,S=n.map(t=>m?X(t,a.length,!0):null),H=(t,e)=>S[e]?.[t].to??k(t,e)?.value??0,T=(t,e)=>S[e]?.[t].from??0,O=(t,e)=>[c(e),l(H(t,e))],z=a.map((t,e)=>{if(!$)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}); `}}),E=Math.min(M,6);e.plot.style.setProperty("--count",String(E+1));const B=M>0?E/(p?n.length:M):1,_=t=>t*B,U=t=>`--i:${dt(_(t))}`,F=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{N(t,o)||(a<0&&(a=o),(o===M||N(t,o+1))&&((p||o>a)&&e.push([a,o]),a=-1))}),e},V=(t,e)=>`--i:${dt(_(t)+1)}; --d:${dt(_(p?e+1:e)-_(t))}`,j=(t,e)=>({"data-from":t+1,"data-to":e+1,...p&&{"data-flat":""}}),q=g?a.map((t,e)=>ht(n.length,t=>N(e,t),t=>O(e,t))):[],I=g&&t?a.map((t,e)=>ht(n.length,t=>N(e,t),t=>[c(t),l(T(e,t))])):[],R=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{p?(a.push(`H${dt(o+n*x/2)}`),s<t.length-1&&a.push(`V${dt(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])=>`${dt(t)},${dt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${dt(o)},${dt(r)}`)}),a},W=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),l(o(t,e+a))]),G=(t,e,n,a)=>g?t[e].slice(n,a+1):null,K=t=>c(t)-(p?x/2:0),Y=t=>c(t)+(p?x/2:0);t&&a.forEach((t,e)=>(t=>{const e=A("g",{class:"tablechart-area",...z[t].attrs,...m&&{"data-stacked":""},style:z[t].ink}),n=F(t),a=A("g",{class:"tablechart-area-fill",style:`--rows:${dt(E+1)}; ${n.length?V(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=W(t,o,r,H),n=W(t,o,r,T),s=G(I,t,o,r)?.reverse()??null,c=[`M${dt(K(o))},${dt(n[0][1])}`,`L${dt(K(o))},${dt(e[0][1])}`,...R(e,G(q,t,o,r),1),`L${dt(Y(r))},${dt(n[n.length-1][1])}`,...R(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(A("path",{d:c,...j(o,r),style:V(o,r)}))}b.appendChild(e)})(e)),a.forEach((t,e)=>(t=>{const e=a[t];for(const[n,a]of F(t)){const o=W(t,n,a,H),r=[`M${dt(K(n))},${dt(o[0][1])}`,...R(o,G(q,t,n,a),1)].join(" ");b.appendChild(A("path",{class:"tablechart-series",...z[t].attrs,d:r,...e.line&&{"data-line":e.line},...j(n,a),style:`${z[t].ink}${V(n,a)}`}))}})(e)),p||(()=>{const t=a.map((t,e)=>$?it(a,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=O(e,n);return ut(t[e].shape,o,r,4*u,{...a,style:`${a.style??""}${s=r,`--rise:${dt(v-s)}px; `}${U(n)}`});var s},o=t=>n.map((t,e)=>e).filter(e=>!N(t,e)),r=a.flatMap((n,a)=>t[a].open?o(a).map(t=>e(a,t,{class:h,"data-row":t+1,...$&&{"data-series":a+1}})):[]);L(b,r,y,i),a.forEach((n,a)=>{for(const r of o(a))b.appendChild(e(a,r,{class:d,...z[a].attrs,"data-marker":t[a].shape,...t[a].open&&{"data-open":""},"data-row":r+1,style:z[a].ink}))})})();const Z=(t,e)=>{let n=e;for(;n<M&&!N(t,n+1)&&k(t,n+1)?.value===k(t,e)?.value;)n++;return n},J=(e,n)=>{const o=k(e,n);if(!o||o.missing)return"none";if(p&&n>0&&!N(e,n-1)&&k(e,n-1)?.value===o.value)return"none";if(w&&!a[e].focus)return"none";if(m)return"middle";const r=o.value<0?"below":"above";if(!$||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&&O(e,n)[1]+7*u+f>v?"above":"below"},Q=$&&!w&&a.length>2&&!m&&!p,tt=new Map;if(Q){const t=n.flatMap((t,e)=>a.map((t,n)=>({s:n,i:e,value:k(n,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==J(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],r=t.map(({s:t,i:n,value:a})=>{const r=D(o[t][n]).width*u,[s,c]=O(t,n);return e(a).map(t=>[s-r/2,"above"===t?c-7*u-f:c+7*u,r,f])}),s=a.flatMap((t,e)=>n.flatMap((t,n)=>{if(N(e,n))return[];const[a,o]=O(e,n);return[[a-4*u,o-4*u,8*u,8*u]]})),l=P(r,s,[0,0,c(M)+c(0),i]);t.forEach(({s:t,i:n,value:a},r)=>tt.set(o[t][n],null===l[r]?null:e(a)[l[r]]))}o.forEach((t,e)=>{t.forEach((t,n)=>{t.style.setProperty("--i",String(dt(p?(_(n)+_(n+1))/2:_(n))));const a=tt.get(t)??J(e,n);if(t.dataset.place="above"===a?"outside":a,t.toggleAttribute("data-left-out","none"!==a&&((t,e)=>Q?null===tt.get(o[t][e]):!(!m&&!p)&&(D(o[t][e]).width*u>(p?Z(t,e)-e+1:1)*x-4*u||!!(m&&t>0&&H(t,e)<T(t,e))||m&&Math.abs(l(T(t,e))-l(H(t,e)))<1.2*f))(e,n)),p&&"none"!==a?t.dataset.rowEnd=String(Z(e,n)+1):delete t.dataset.rowEnd,"none"===a)return;const r=D(t).width*u/2+4*u;let s=c(n);p?s=(c(n)+c(Z(e,n)))/2:"middle"===a&&0===n?s+=r:"middle"===a&&n===M&&(s-=r);const d=l(H(e,n)),h={middle:(l(T(e,n))-d)/2,above:-7*u,below:7*u};C(t,s,d+h[a],y,i)})});const et=s.map((t,e)=>{let n=M;for(;n>0&&N(e,n);)n--;const[a,o]=O(e,n);return{name:t,x:(p?a+x/2:a)+10*u,y:m?(o+l(T(e,n)))/2:o}}),nt=(s[0]?D(s[0]).height:0)*u;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,a)=>{const o=t[a-1];o&&n.y<o.y+e&&(n.y=o.y+e)}),t))(et,nt))C(t.name,t.x,t.y,y,i);const at=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),ot=t||m||2!==a.length||w||at?v:i-2*u;b.appendChild(A("line",{class:r,x1:0,x2:c(M)+c(0),y1:ot,y2:ot}))}}),gt=pt(!1),$t=pt(!0),wt=new Set,yt={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.`;wt.has(a)||(wt.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=tt(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&&et(i[a],r,c)}}),p=i[0]?D(i[0]).height*c*.56:0;let g=Number.POSITIVE_INFINITY;for(const[o,r]of m.entries())r.inside&&(g=Math.min(g,(a-D(i[o]).width*c)/2));const $=t.length,w=(t,e,n=!1)=>`--start:${(t/$).toFixed(4)}; --span:${(e/$).toFixed(4)}; --ease:${n?v:"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(A("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${k("--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(A("rect",{class:S(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:`${k("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const M=i[r];M.style.setProperty("--start",(r/$).toFixed(4)),M.style.setProperty("--span",(1/$).toFixed(4));const v=Math.min(g,(d-p)/2),x="center"===b?u+d/2:"end"===b!==h?u+v+p/2:u+d-v-p/2;M.dataset.place=f?"inside":"outside",M.dataset.kind=n.kind;const N=f?x:"down"===n.kind?u+d+D(M).height*c+3*c:u-3*c;C(M,e(r),N,y,s)}),l.appendChild(A("line",{class:r,x1:0,x2:y,y1:h,y2:h}))}},Mt={enabled:!1,log(...t){Mt.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!Mt.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):Mt.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},vt=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}},xt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),kt=t=>Number(t.toPrecision(12)),Nt=(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)},At=(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},St=(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},Ht=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},Ct=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=St(n,t.step),a=At(t.min,t.max,n);return{...t,step:n,ticks:a}},Tt=["axis-break","trend","bracket"],Lt=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))}},Ot=(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)),Lt(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===o),c&&(c.disabled=o===a.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:o,steps:a.count}}))},zt="tablechart-tooltip",Et=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],Bt=null,_t=null,Ut=null,Ft=0,Vt=()=>{clearTimeout(Ft),Bt&&_t&&(Bt.hidden=!0,_t=null,Ut=null)},Pt=!1,jt=!0,qt=NaN,Dt=NaN,It=!1,Rt=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Wt=()=>{clearTimeout(Ft),Ft=window.setTimeout(Vt,120)},Gt=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Kt=(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},Xt=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Gt(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?Kt(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&&Gt(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Yt=(t,e,n)=>{if(clearTimeout(Ft),_t===t&&Ut===e)return;const a=(t.type.tooltip??Xt)(t,e,n);if(!a.length)return Vt();_t&&_t!==t&&Vt(),Bt??(Bt=(()=>{const t=document.createElement("div");return t.className=zt,t.setAttribute("aria-hidden","true"),t.hidden=!0,ft=document.createElement("div"),(bt=document.createElement("div")).className=`${zt}-arrow`,t.append(ft,bt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(Ft)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Wt()),document.addEventListener("pointerdown",e=>{const n=e.target;!_t||_t.plot.contains(n)||t.contains(n)||Vt()}),window.addEventListener("resize",Vt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${zt}-line`,n){const t=document.createElement("span");t.className=`${zt}-key`,t.style.background=n,o?.box?t.dataset.sample="box":o&&(t.dataset.sample="line",o.marker&&(t.dataset.marker=o.marker),o.line&&(t.dataset.line=o.line),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${zt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${zt}-value`,n.textContent=e,r.append(n)}return r},r=t.categories[e]?.textContent??t.rows[e].label,s=1===a.length&&!a[0].name,c=a.every(t=>t.name&&!t.value);ft.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 Et){const t=l.getPropertyValue(f).trim();t?Bt.style.setProperty(f,t):Bt.style.removeProperty(f)}Bt.style.setProperty("--_color",l.color),Bt.style.colorScheme=l.colorScheme,Bt.style.fontFamily=l.fontFamily;const i=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);Bt.parentElement!==i&&i.append(Bt),_t=t,Ut=e,Bt.hidden=!1,Bt.style.left="0px",Bt.style.top="0px";const u=Bt.getBoundingClientRect(),d={x:u.left,y:u.top,scale:Rt(Bt,u.width)},h=Rt(t.plot,t.plot.getBoundingClientRect().width);Bt.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:b}=document.documentElement,m=n.top-r,p=b-n.bottom-r,g=i+d<=m||!(i+d<=p)&&m>=p,$=g?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($,b-i-r))-a.y)/a.scale+"px",t.dataset.side=g?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/a.scale-u+"px"})(Bt,bt,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let a=null;for(const i of n){const t=i.getBoundingClientRect();(t.width||t.height)&&(a=a?new DOMRect(Math.min(a.left,t.left),Math.min(a.top,t.top),Math.max(a.right,t.right)-Math.min(a.left,t.left),Math.max(a.bottom,t.bottom)-Math.min(a.top,t.top)):t)}if(a)return a;const o=t.plot.getBoundingClientRect(),[r,s,c,l]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(o.left+o.width*r/100,o.top+o.height*s/100,o.width*c/100,o.height*l/100)})(t,e),d)},Zt=t=>{_t===t&&Vt()},Jt={area:$t,bar:ot,column:rt,donut:ct,line:gt,waterfall:yt},Qt={"axis-break":z,trend:W,bracket:V,reference:R},te=Object.keys(Qt),ee=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},ne=["straight","step","smooth"],ae=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},oe=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),re=(t,e)=>{const n=t.dataset.chartShape;return n&&ne.includes(n)?n:ne.includes(e.shape)?e.shape:"straight"},se=0,ce=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=Jt[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(Jt).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(vt);return o.length||o.push(vt(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(ee(e)))continue;const t=document.createElement("span");t.className=m,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-"+ ++se),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=xt(t),o=Math.max(1,E(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 d=l.length>1;d&&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 b=h&&!!s.stackable&&d,p=document.createElement("div");p.className="tablechart-plot",p.setAttribute("aria-hidden","true");const w=A("svg",{role:"presentation",focusable:"false"});p.appendChild(w),t.appendChild(p);const y=s.centre?c.filter(t=>!t.isTotal):c,M=Math.max(0,E(y.flatMap(t=>t.cells.slice(0,l.length).map(t=>B(t.number))))),v=l.map((t,e)=>Math.max(0,E(c.map(t=>B(t.cells[e]?.number??""))))),x=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=H(a,p);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),d&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(v[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),r})),k=x[0],N=b&&s.totals?c.map((t,e)=>{const n=H(a,p);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(Z(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],C=l.some(t=>t.focus),T=t.getAttribute("data-chart-legend"),L=d&&!s.columns&&(null===T?e.legend||void 0!==s.legend:"false"!==T)?document.createElement("div"):null;L&&(L.className=u,L.setAttribute("aria-hidden","true"),L.inert=!0);const O=d&&!s.columns?l.map((n,a)=>{const o=H(i,L??p);L&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==re(t,e)){const t=it(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",C&&!n.focus?"1":"0"),o.style.setProperty("--i",String(S.slot)),o}):[],z=s.centre?H(f,p):null;if(z){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);z.dataset.value=String(e),t&&(z.dataset.decimals=String(B(t.number)))}const _=z&&!c.some(t=>t.isTotal)?((t,e,n)=>{const a=t.querySelector("table");if(!a)return null;const o=a.querySelector("tfoot [data-chart-total]");if(o)return o.dataset.value=e.dataset.value??"0",o;const r=(a.tFoot??a.createTFoot()).insertRow(),s=document.createElement("th");s.scope="row",s.textContent=n.totallabel;const c=t.getAttribute("data-chart-keys");c&&n.langattribute&&s.setAttribute(n.langattribute,`${c}-total`);const l=r.insertCell();return l.setAttribute("data-chart-total",""),l.dataset.value=e.dataset.value??"0",r.prepend(s),l})(t,z,e):null,U="beside"===s.categories,F=document.createElement("div");F.className="tablechart-categories",F.setAttribute("aria-hidden","true"),F.inert=!0,U?F.dataset.place="beside":s.centre&&(F.dataset.place="key"),F.style.setProperty("--_columns",String(c.length));let V=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(V+1),t.style.setProperty("--n",String(V)),t.style.setProperty("--palette",`var(--tablechart-color-${V+1})`),V+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),F.appendChild(t)}(U?p:t).appendChild(F),L&&t.appendChild(L);const P=l.filter(t=>!t.group),j=!s.axes&&!s.centre&&ae(t,"data-chart-axis",e.axis),q=s.axes?{titles:P.slice(0,2).map((t,n)=>{const a=H(`${g}-title`,p);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:H(`${$}s`,p),numbers:!0}:j||!s.centre&&ae(t,"data-chart-grid",e.grid)?{titles:[],ticks:H(`${$}s`,p),numbers:j}:null;s.text?.({figure:t,plot:p,rows:c,series:l,config:e});const D=oe(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=>Tt.includes(t.getAttribute("data-annotation")??"")),r=t=>t.hasAttribute("data-fragment"),s=n.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(e||n.some(r)||a.some(r)||s.flat().some(r)||o.some(r)))return null;const c=[],l=new Map,i=[],u=t=>{let e=null!==t?l.get(t):void 0;return void 0===e&&(e=c.length,c.push(t),i.push(0),null!==t&&l.set(t,e)),e};let d=0;const h="donut"===t.getAttribute("data-chart"),f=t=>h&&"total"===t.getAttribute("data-kind"),b=n.map(t=>{if(f(t))return{step:null,slot:0};if(!e&&!r(t))return{step:null,slot:d++};const n=u(t.getAttribute("data-fragment-index"));return{step:n,slot:i[n]++}}),m=Math.max(-1,...b.map(t=>t.step??-1));if(m>=0)for(const[w,y]of n.entries())f(y)&&(b[w]={step:m,slot:i[m]++});const p=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),g=s.map(t=>t.map(()=>({step:null,slot:0}))),$=Math.max(0,...s.map(t=>t.length));for(let w=0;w<$;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"));g[t][w]={step:a,slot:i[a]++}}return{rows:b,series:p,cells:g,notes:o.map(t=>{const e=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n},[n,a]="bracket"===t.getAttribute("data-annotation")?[e("data-from",0),e("data-to",b.length-1)]:[0,b.length-1];let o=null;for(let r=Math.min(n,a);r<=Math.max(n,a);r++)for(const t of[b[r]?.step??null,...(g[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=p[e("data-series",0)]?.step??null;null!==s&&(null===o||s>o)&&(o=s),r(t)&&(o=u(t.getAttribute("data-fragment-index")));const c=null===o?b.length:b.filter(t=>t.step===o).length;return{step:o,after:c}}),count:c.length,indexes:c}})(t):null;s.axes&&t.querySelector("[data-fragment]")&&Mt.log(`A ${r} chart has no steps, so it is shown whole.`,t),D&&t.setAttribute("data-steps","");const I=t.getAttribute("data-chart-keys"),R=D&&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=A("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(A("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=m,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:I&&`${I}-previous`,next:I&&`${I}-next`,hint:I&&`${I}-step`},e.langattribute):null;R&&t.appendChild(R);const W=t.getAttribute("data-chart-table"),G=W&&ie.includes(W)?W:e.table;if("never"===G)t.removeAttribute("data-table");else{t.setAttribute("data-table",G);const e=t.querySelector(":scope > table");e&&t.append(e)}const K=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),a=Qt[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(Qt).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,p),series:r,after:c.length}}).filter(t=>null!==t);oe(t,e)&&t.setAttribute("data-animate",ue(t,r,e,Boolean(D)));const X={figure:t,plot:p,svg:w,rows:c,decimals:M,type:s,values:k,series:l,seriesValues:x,names:L?[]:O,categories:Array.from(F.children),centre:z,axes:q,stacked:b,totals:N,totalCell:_,rowAt:null,rowBox:null,annotations:K,checks:[],plan:D,step:0,controls:R};R?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&Ot(X,X.step+("next"===e?1:-1))}),Ot(X,0,!0);const Y=t.getAttribute("data-chart-tooltip"),J="false"!==Y&&("auto"===Y?"auto":null!==Y||e.tooltip);return J&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(It)return;It=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(jt=t.screenX!==qt||t.screenY!==Dt,qt=t.screenX,Dt=t.screenY,jt&&(Pt=!1))},{capture:!0,passive:!0});const t=()=>{Pt=!0,Vt()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!0})})();const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if("pointerdown"===o.type)Pt=!1;else if("mouse"===o.pointerType&&(!jt||Pt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return _t===t?Vt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Rt(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 _t===t?Vt():void 0;Yt(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||Pt||Yt(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,_t===t&&Wt())})})(X,e,"auto"===J),be(X,e),X},le={grow:"grow",sweep:"sweep"},ie=["never","auto","print","always"],ue=(t,e,n,a)=>{const o="line"===e||"area"===e,r=le[t.getAttribute("data-chart-animate")??""]??le[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},de=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},he=(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*y:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},fe=(t,e)=>he(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,be=(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:me(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},me=(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)}},pe=(t,e)=>{t.figure.classList.toggle("is-shown",e)},ge=t=>"id"===t||"style"===t||t.startsWith("data-chart"),$e=/^\s*(?:Table)?:\s+/,we=t=>"P"===t?.tagName&&$e.test(t.textContent??""),ye=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,Me=t=>{const e=xe(t);return"P"===e?.tagName?e:t},ve=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},xe=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},ke="strong, b, span.total",Ne="data-chart-made",Ae=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,Se=new Set,He=null,Ce=["column","bar"],Te=t=>{const e=t.getAttribute("data-chart")||"column";if(!Ce.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return Ce.includes(n)?n:e},Le=!1,Oe=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=we(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||ge(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?we(r)?r:we(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=Me(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=ye.exec(e.textContent??"");if(!n||!te.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=Me(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($e,""),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),Mt?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(Ne)));return(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!Le&&e&&(Le=!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:ve(o.rows):ve(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||Mt?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),Mt?.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=xe(e);a?.matches(ke);a=xe(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=xe(e);t?.matches(ke);t=xe(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=xt(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}`)})}),Mt?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute),a},ze=(t,e)=>{const a=Mt.timed("Building",t,()=>ce(t,e));return a?(t.setAttribute(Ne,""),((t,e)=>{let a=t,r=Te(a.figure),s=null,c=!1,i=!1;const d=async()=>{if(!oe(a.figure,e))return pe(a,!0);const t=a.figure.classList.contains("is-shown");if(!c||null===s||t||i)!c&&e.replay&&t&&pe(a,!1);else{i=!0;const t=Ae()?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(Ae())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)),i=!1,!c&&e.replay||pe(a,!0)}var n},b=()=>{const t=Te(a.figure);if(!t||t===r)return;const n=Mt.timed("Building",a.figure,()=>ce(a.figure,e,t));n&&((t=>{Zt(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${u}`)?.remove(),t.controls?.remove()})(a),Ot(n,a.step,!0),a=n,r=t,s=null)},m=()=>{b();const t=a.plot.clientWidth;t&&t!==s&&Mt.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:s,type:c,values:i,series:u,seriesValues:d,names:b,annotations:m}=t,p=Number.parseFloat(t.figure.dataset.chartAspect??""),M=p>0?p:c.aspect??e.aspect,v="beside"===c.categories,k=t.axes&&!c.axes?t.axes:null,S=v?null:t.categories[0]?.parentElement;let T=null;if(k){a.style.margin="",S&&(S.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=c.segments?.(s)??[],r=t.stacked?s.flatMap(t=>Object.values(Y(t,u.length,c.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):s.flatMap(t=>t.cells.slice(0,u.length).filter(t=>!t.missing).map(t=>t.value)),l=Math.min(0,-E(r.map(t=>-t))),i=Math.max(0,E(r)),d=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:h,chartScale:f}=t.figure.dataset,b=Ht(h??f);if(b&&b.length>2)T={min:b[0],max:b[b.length-1],step:0,ticks:b};else{const[t,e]=b??[l,i],a=Nt(e-t,Math.max((v?n/9:n*M/3)/d,2)),o=(t,e)=>b?t:Number(((e?Math.ceil:Math.floor)(t/a-1e-9*(e?1:-1))*a).toPrecision(12)),r=o(t,!1),s=o(e,!0);T={min:r,max:s,step:a,ticks:At(r,s,a)}}k.ticks.textContent="";const m=s.find(t=>!t.missing),p=E(T.ticks.map(t=>B(String(t))));for(const t of T.ticks){const n=H($,k.ticks);n.dataset.value=String(t),n.dataset.place="none",m?.prefix&&(n.dataset.prefix=m.prefix),m?.suffix&&(n.dataset.suffix=m.suffix),me(n,p,e.locale)}if(k.numbers){const t=Array.from(k.ticks.children);for(const e of t)delete e.dataset.place;q(t),v?a.style.marginBottom=`${(t[0]?D(t[0]).height:0)+6}px`:(a.style.marginLeft=`${E([0,...t.map(t=>D(t).width)])+10}px`,S&&(S.style.marginLeft=a.style.marginLeft))}}const O=a.clientWidth;if(!O)return!1;const z=y/O,_=y*M;a.classList.add("is-placed");for(const n of[...d.flat(),...t.totals])delete n.dataset.place;a.style.removeProperty("--_fit"),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const U=c.axes?t.axes:null;let F=[];if(U){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=u.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=s.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:c,chartScaleY:l,chartScale:i}=t.figure.dataset,d=[Ht(c),Ht(l??i)];F=o.map((t,e)=>((t,e,n)=>{if(n&&n.length>2)return{min:n[0],max:n[n.length-1],step:0,ticks:n};let a=n?.[0]??-E(t.map(t=>-t)),o=n?.[1]??E(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=Nt(o-a,e);return{min:a,max:o,step:r,ticks:At(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?_/z/(4*n):O/(9*n),4),d[e])),U.ticks.textContent="",F.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=E(t.ticks.map(t=>B(String(t))));for(const o of t.ticks){const t=H($,U.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),me(t,s,e.locale)}})}const V=U?Array.from(U.ticks.children):[];q([...d.flat(),...t.totals,...b,...t.categories,...m.map(t=>t.badge),...U?.titles??[],...V]);const P=(i[0]?D(i[0]).height:0)*z,j=m[0]?.badge?D(m[0].badge).height*z:0,I=Math.max(_,he(t.figure,z,"--tablechart-min-height","200px")??0,c.minHeight?.({labelHeight:P,nameHeight:Math.max(0,E(t.categories.map(t=>D(t).height)))*z,unit:z,rows:s.length,series:u.length,stacked:t.stacked})??0),R=t.stacked?s.map(t=>{const e=Z(t,u.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):s,W=(c.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?R.map(t=>({...t,cells:[t.cells[0]]})):s),G={labelHeight:P,badgeHeight:j,hasAnnotations:m.length>0,unit:z,series:u.length,focused:u.some(t=>t.focus),stacked:t.stacked},K=Math.max((X=E,t.stacked?X(s.map(t=>Y(t,u.length,c.running).top)):X([...W.flatMap(t=>[t.from,t.to,t.value]),...s.flatMap(t=>t.cells.slice(0,u.length).map(t=>t.value))])),0);var X;const J=W.some(t=>"up"===t.kind||"down"===t.kind)?W.flatMap(t=>[t.from,t.to]):t.stacked?s.map(t=>Y(t,u.length,c.running).bottom):s.flatMap(t=>t.cells.slice(0,u.length).map(t=>t.value)),Q=Math.min(-E(J.map(t=>-t)),0),tt=c.headroom?.(G)??P,et=2*z+(c.footroom?.(G)??0)+(Q<0?P+4*z:0),nt=I-tt-et,ot=T?Math.max(T.max,K):1.02*K,rt=T?Math.min(T.min,Q):1.02*Q,st=m.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,ct=t=>{const e=Number.parseFloat(st?.getAttribute(t)??"");return Number.isFinite(e)?e:null},lt=ct("data-from")??ct("data-at"),it=ct("data-to");let ut=null;if(st&&(null!==lt||null!==it)){const t=lt??0,e=it??ot,a=null===it?t:null===lt?e:(t+e)/2,o=st.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===it?.22:.3,.05),.8),l=W.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);c.breakable?Q<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>ot||0===t&&e===ot?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${K}.`):l.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):ut={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const dt=ut?ut.gap:null,ht=(ut&&he(t.figure,z,"--tablechart-break-gap",""))??13,ft=I-et,bt=ot-rt||1;let mt,pt,gt=t=>ft-(t-rt)/bt*nt;if(ut){const{lo:t,hi:e,gap:n,share:a}=ut,o=nt*a,r=(nt-o-ht)/(t+(ot-e)),s=o/(e-t);gt=a=>a<=t?ft-a*r:a<=n?ft-t*r-(a-t)*s:a<=e?ft-t*r-(a-t)*s-ht:ft-t*r-o-ht-(a-e)*r}let $t=[];if(U){const t=6*z,[e,n]=U.titles,a=t=>t?D(t).width*z:0,o=t=>t?D(t).height*z:0,r=V.filter(t=>"x"===t.dataset.axis),s=V.filter(t=>"y"===t.dataset.axis),c=o(V[0]),l=a(n)+E([0,...s.map(a)])+2*t,i=c/2;pt=[l,i,y-l-E([0,...r.map(a)])/2,I-i-o(e)-c-2*t];const[u,d,h,f]=pt,[b,m]=F,p=t=>u+(t-b.min)/(b.max-b.min||1)*h,g=t=>d+f-(t-m.min)/(m.max-m.min||1)*f;mt=p,gt=g;const $=t=>a(r.find(e=>Number(e.dataset.value)===t));$t=[Ct(b,e=>e.every((n,a)=>!a||p(n)-p(e[a-1])>($(n)+$(e[a-1]))/2+t)).ticks,Ct(m,e=>e.every((n,a)=>!a||g(e[a-1])-g(n)>c+t/2)).ticks];for(const w of V){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&&C(w,n?u-t:p(e),n?g(e):d+f+t,y,I)}e&&C(e,u+h/2,I-o(e),y,I),n&&C(n,0,d+f/2,y,I)}const wt=b.length?E(b.map(t=>D(t).width))*z+12*z:0,yt=t.categories[0]?.parentElement;yt&&(yt.style.paddingRight=wt?wt/y*100+"%":"");const Mt=(y-wt)/s.length,vt=t=>t>=0&&t<s.length?t:null;t.rowAt=c.centre?null:"beside"===c.categories?(t,e)=>vt(Math.floor(e*z/(I/s.length))):t=>vt(Math.floor(t*z/Mt));const xt=Mt/y*100,kt=100/s.length;if(t.rowBox="beside"===c.categories?t=>[0,t*kt,100,kt]:t=>[t*xt,0,xt,100],r.setAttribute("viewBox",`0 0 1000 ${N(I)}`),r.textContent="",pt&&mt){const[n,a,o,s]=pt,[c,l]=$t,i=mt;ae(t.figure,"data-chart-grid",e.grid)&&r.appendChild(A("path",{class:w,d:[...c.map(t=>`M${N(i(t))},${N(a)}V${N(a+s)}`),...l.map(t=>`M${N(n)},${N(gt(t))}H${N(n+o)}`)].join("")})),r.appendChild(A("path",{class:g,d:[`M${N(n)},${N(a)}V${N(a+s)}H${N(n+o)}`,...c.map(t=>`M${N(i(t))},${N(a+s)}v${N(4*z)}`),...l.map(t=>`M${N(n)},${N(gt(t))}h${N(-4*z)}`)].join("")}))}t.checks=[];const St={rows:s,segments:W,cx:t=>(t+.5)*Mt,y:gt,x:mt,frame:pt,length:(e,n)=>he(t.figure,z,e,n),barWidth:Math.min(Mt*e.barfill,fe(t.figure,z)),barMax:fe(t.figure,z),height:I,unit:z,labelHeight:P,badgeHeight:j,after:s.length,note:0,labels:"inside"===t.figure.dataset.chartLabels||"outside"!==t.figure.dataset.chartLabels&&"inside"===e.labels?"inside":"outside",insideAlign:de(t.figure),breakAt:dt,squeeze:ut,breakGap:ht,domain:T?[T.min,T.max]:null,stacked:t.stacked,shape:re(t.figure,e),totals:t.totals,svg:r,plot:a,values:i,series:u,seriesValues:d,names:b,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[]};if(a.style.setProperty("--count",String(Math.max(1,...s.map(t=>t.slot+1)))),c.draw(St),St.rowAt&&(t.rowAt=St.rowAt),k&&T){const n=6*z,a=v&&St.x?St.x:gt,o=Array.from(k.ticks.children),s=t=>D(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Ct(T,t=>t.every((e,o)=>!o||(v?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*z+n:a(t[o-1])-a(e)>s(e).height*z+n/2))).ticks.filter(t=>!ut||t<=ut.lo||t>=ut.hi);for(const t of o){const e=Number(t.dataset.value),o=k.numbers&&c.includes(e);t.dataset.place=o?v?"below":"before":"none",o&&C(t,v?a(e):-n,v?I+n:a(e),y,I)}const l=y-wt;ae(t.figure,"data-chart-grid",e.grid)&&r.prepend(A("path",{class:w,d:c.map(t=>v?`M${N(a(t))},0V${N(I)}`:`M0,${N(a(t))}H${N(l)}`).join("")})),k.numbers&&r.appendChild(A("path",{class:g,d:[v?`M${N(a(T.min))},${N(I)}H${N(a(T.max))}`:`M0,${N(a(T.max))}V${N(a(T.min))}`,...c.map(t=>v?`M${N(a(t))},${N(I)}v${N(4*z)}`:`M0,${N(a(t))}h${N(-4*z)}`)].join("")}))}for(const[n,o]of m.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series,a=t=>({...t,...t.cells[e]??t.cells[0]});o.type.draw(o.spec,o.badge,{...St,...t.stacked&&{rows:R,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&{rows:s.map(a),segments:W.map(t=>{const e=a(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:d[e]},after: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 i=t.figure.querySelector(`.${f}`);if(i){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?c(i,null,"--i",0):c(i,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}`),b=h[h.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&h.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(`.${l}`));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??"",x(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))}}Lt(t)})(t);const Tt=t.categories[0]?.parentElement;Tt&&"beside"!==c.categories&&!c.centre&&at(Tt,t.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const Ot=m.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*z,n=t.offsetHeight*z,a=Number.parseFloat(t.style.left)/100*y,o=Number.parseFloat(t.style.top)/100*I,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*z;return[A("rect",{class:h,"data-for":"badge","data-note":t.dataset.note??"",x:a-e/2,y:o-n/2,width:e,height:n,rx:null===s?c:e*s,ry:null===s?c:n*s,style:["--after","--step"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ")})]}),zt=r.querySelector(`.${w}`);if(zt){const e=a.getBoundingClientRect(),n=y/e.width,o=getComputedStyle(a),s=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2,l=[...d.flat(),...t.totals,..."beside"===c.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?[A("rect",{class:h,"data-for":"text",x:(a.left-e.left)*n-3*z,y:(a.top-e.top)*n+(a.height*n-o)/2-z,width:a.width*n+6*z,height:o+2*z,style:r.join("; ")})]:[]});L(r,l,y,I,zt)}L(r,Ot,y,I);const Et=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(c.columns?[t.categories]:[...d,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||c.centre&&s[Number(t.dataset.row)-1]?.isTotal)(e)&&!Et(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>Et(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(a,e))&&(s=t,d())};let M=!1;const v=new ResizeObserver(()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,m()}))}),k=new IntersectionObserver(t=>{for(const e of t)c=e.isIntersecting,d()},{threshold:e.threshold}),S=()=>{a.figure.classList.add(p),pe(a,!0),a.figure.offsetWidth},T=()=>a.figure.classList.remove(p),O=()=>{s=null,m()},z={relabel:()=>be(a,e),refresh:O};b(),m(),v.observe(a.figure),k.observe(a.figure),window.addEventListener("beforeprint",S),window.addEventListener("afterprint",T),(t=>{Se.add(t),He||(He=new MutationObserver(()=>{for(const t of Se)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of Se)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(z);const _={figure:a.figure,refresh:O,next:()=>Ot(a,a.step+1),previous:()=>Ot(a,a.step-1),stepTo:t=>Ot(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){v.disconnect(),k.disconnect(),window.removeEventListener("beforeprint",S),window.removeEventListener("afterprint",T),(t=>{Se.delete(t),!Se.size&&He&&(He.disconnect(),He=null)})(z),Zt(a),a.figure.tablechart===_&&delete a.figure.tablechart}};return a.figure.tablechart=_,_})(a,e)):null},Ee=e({LEGEND_CLASS:()=>u,NAME_CLASS:()=>i,POINT_CLASS:()=>d,VIEWBOX_WIDTH:()=>y,avoidCollisions:()=>P,htmlEl:()=>H,largest:()=>E,markerEl:()=>ut,placeAt:()=>C,short:()=>N,sizeOf:()=>D});window.Tablechart={init:async(t={},e=document)=>{const n={...M,...t};n.debug&&(Mt.enabled=!0);const a=(await Oe(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>ze(t,n)).filter(t=>null!==t);return Mt.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={...M,...e};n.debug&&(Mt.enabled=!0);const[a]=await Oe([t],n);return a?ze(a,n):null},defaultConfig:M,addType:(t,e)=>{Jt[t]=e},kit:Ee}}();
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-head",l="tablechart-slice",i="tablechart-name",u="tablechart-legend",d="tablechart-point",h="tablechart-hole",f="tablechart-centre",m="tablechart-break",b="tablechart-sr",p="is-printing",g="tablechart-axis",$="tablechart-tick",w="tablechart-grid",y=1e3,M={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"},v="cubic-bezier(0.3, 0.3, 0.6, 1)",x=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?v:"linear"}),k=(t,e)=>`${t}:${e}`,N=t=>Math.round(100*t)/100,A=(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?N(t):t))}return n},S=(t,e)=>[t,...e.classes].join(" "),H=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},C=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},T=0,L=(t,e,n,a,o)=>{if(!e.length)return;const r="tablechart-cut-"+ ++T,s=A("mask",{id:r,maskUnits:"userSpaceOnUse"});s.appendChild(A("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const i of e)i.setAttribute("fill","black"),s.appendChild(i);let c=t.querySelector(":scope > defs");if(c||(c=A("defs"),t.prepend(c)),c.appendChild(s),o)return o.setAttribute("mask",`url(#${r})`);const l=A("g",{mask:`url(#${r})`});for(const i of Array.from(t.childNodes))i!==c&&l.appendChild(i);t.appendChild(l)},O=0,z={create:()=>null,draw(t,e,n){const{rows:a,y:r,svg:s,breakAt:c}=n;if(null===c)return;const l="zigzag"===t.getAttribute("data-mark"),i=(t,e)=>{const n=t.sideways?t.height:t.width,a=.09*n,o=n+2*a,r=.3*o,s=.06*o;if(t.sideways){const n=t.y-a;if(!l)return[[e-r/2,n],[e+r/2,n+o]];const c=o/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+o]]}const c=t.x-a;if(!l)return[[c,e+r/2],[c+o,e-r/2]];const i=o/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+o,e-s]]},u=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),d="tablechart-break-"+ ++O,h=A("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(A("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(A("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[k("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(A("path",{class:m,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const p=Array.from(s.querySelectorAll(`.${m}`)),g=A("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))p.includes(o)||g.appendChild(o);const $=A("defs");$.appendChild(h),s.prepend($,g)}},E=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},B=t=>(t.split(/[.,]/)[1]||"").length,_=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),U=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const a of Array.from(t.children))n.appendChild(a.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},F=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=_(s),l=r?.5:.5*10**-B(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.`)},V={create:U,draw(t,e,a){const{rows:o,cx:r,y:l,unit:i,labelHeight:u,badgeHeight:d,height:h,svg:f,after:m}=a,[b,p]=((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),g=o[b],$=o[p];if(!g||!$)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${b+1} to ${p+1}, of ${o.length}).`);const w=7*i,M=4*i,v=r(b),x=r(p),N=Math.min(l(g.value),l($.value))-u-M-.9*d,S=t=>l(t)-u-M,H=`M ${v} ${S(g.value)} L ${v} ${N} L ${x} ${N} L ${x} ${S($.value)-w}`,T=(S(g.value)-N+Math.abs(x-v)+(S($.value)-w-N))/i+1;f.appendChild(A("path",{class:s,"data-note":a.note,d:H,style:`--len:${T.toFixed(1)}; ${k("--after",m)}`}));const L=S($.value);var O;f.appendChild(A("polygon",{class:c,"data-note":a.note,points:`${x},${L} ${x-.45*w},${L-w} ${x+.45*w},${L-w}`,style:k("--after",m)})),e&&(C(e,(v+x)/2,N,y,h),e.style.setProperty("--after",String(m))),F(e,(O=g.value,($.value-O)/Math.abs(O)*100),`${g.value} to ${$.value}`,a)}},P=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let a=1;for(const l of t)for(const[,,t,e]of l)a=Math.max(a,t,e);const o=new Map,r=([t,e,n,o])=>{const r=[];for(let s=Math.floor(t/a);s<=Math.floor((t+n)/a);s++)for(let t=Math.floor(e/a);t<=Math.floor((e+o)/a);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))o.get(e)?.push(t)??o.set(e,[t])},c=t=>((t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[0]+t[2]<=e[0]+e[2]&&t[1]+t[3]<=e[1]+e[3])(t,n)&&r(t).every(e=>!o.get(e)?.some(e=>{return a=e,(n=t)[0]<a[0]+a[2]&&a[0]<n[0]+n[2]&&n[1]<a[1]+a[3]&&a[1]<n[1]+n[3];var n,a}));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},j=new WeakMap,I=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]))},q=t=>j.get(t)??{width:t.offsetWidth,height:t.offsetHeight},D=(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},R={create(t,e){if(!t.textContent?.trim())return null;const n=U(t,e);return n.dataset.kind="reference",n},draw(t,e,a){const{rows:o,cx:r,y:s,x:c,height:l,unit:i,svg:u,after:d}=a,h=o.filter(t=>!t.isTotal&&!t.missing),f=t.hasAttribute("data-name"),m=(t.getAttribute(f?"data-name":"data-value")??"").trim();let b,p,g;if(f){const t=h.map(t=>_(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=D(m,t,h.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[h[s],h[s+1]??h[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]);g=e,p=s<0?null:c+i*(l-c),b=!1}else g=D(m,h.map(t=>t.value),h.map(()=>1)),b=!c,p=null===g?null:c?c(g):s(g);if(null===p||null===g)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${m}".`);const $=o.length>0?r(o.length-1)+r(0):y,w=c?l:s(0);if(u.appendChild(A("line",{class:"tablechart-reference","data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...b?{x1:0,x2:$,y1:p,y2:p}:{x1:p,x2:p,y1:0,y2:w},style:k("--after",d)})),e){const t=q(e).width*i,n=q(e).height*i,o=4*i,r=b?[[$-t,p-n/2,t,n],[$-t,p-n-o,t,n],[$-t,p+o,t,n]]:[0,n,2*n].flatMap(e=>[[p-t/2,e,t,n],[p+o,e,t,n],[p-o-t,e,t,n]]),[s]=P([r],a.taken,[0,0,y,l]),c=r[s??0];a.taken.push(c),C(e,c[0]+t/2,c[1]+n/2,y,l),e.style.setProperty("--after",String(d)),"mean"!==m&&"median"!==m||F(e,g,`the ${m}`,a,"")}}},W={create:U,draw(t,e,n){const{rows:a,cx:o,y:r,unit:l,labelHeight:i,height:u,svg:d,values:h,after:f}=n,m=a[0],b=a[a.length-1];if(!m||!b)return;const p=i+18*l,g=10*l,$=10*l;let w=o(0),M=r(m.value)-p,v=o(a.length-1),x=r(b.value)-p,N=0;a.forEach((t,e)=>{const n=v===w?0:(o(e)-w)/(v-w),a=M+n*(x-M)-(r(t.value)-p);a>N&&(N=a)}),M-=N,x-=N;const S=v-w,H=x-M,T=Math.hypot(S,H)||1,L=S/T,O=H/T;w-=L*g,M-=O*g,v+=L*g,x+=O*g;const z=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(v-w)*z,n=M+(x-M)*z,s=q(e).width*l/2,c=n+q(e).height*l/2+8*l;let u=0;a.forEach((e,n)=>{const a=(h[n]?q(h[n]).width:0)*l/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*l-i;u=Math.max(u,c-d)}),M-=u,x-=u}const E=v-L*$,B=x-O*$,_=Math.hypot(E-w,B-M)/l+1;d.appendChild(A("line",{class:s,"data-note":n.note,x1:w,y1:M,x2:E,y2:B,style:`--len:${_.toFixed(1)}; ${k("--after",f)}`}));const U=-O,V=L,P=.42*$;d.appendChild(A("polygon",{class:c,"data-note":n.note,points:[`${v},${x}`,`${E+U*P},${B+V*P}`,`${E-U*P},${B-V*P}`].join(" "),style:k("--after",f)})),e&&(C(e,w+(v-w)*z,M+(x-M)*z,y,u),e.style.setProperty("--after",String(f)));const j=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(j)&&j>0&&F(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(m.value,b.value,j),`${m.value} to ${b.value} over ${j} years`,n)}},G=(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}},K=(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}); ${k("--i",e.slot)}`}},X=(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}})},Y=(t,e,n=!1)=>{const a=X(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},Z=(t,e)=>{const{top:n,bottom:a}=Y(t,e);return n+a},J=(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})`)},Q=(t,e,n,a={},r="")=>{const s={class:S(o,e),"data-kind":"bar","data-row":n+1,...a},c=k("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=A("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(A("rect",{...s,...r,class:S("tablechart-piece",e),"data-row":n+1,...K(t,e,o)}))}},tt=(t,e,n)=>t.some(t=>q(t).width*n>e-6*n),et=(t,e,n)=>e>=q(t).height*n*1.6,nt=(t,e,n)=>e>=q(t).width*n*1.5,at=(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},ot={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(E(l.map(t=>q(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/y*100).toFixed(2)}%`);const m=y-4*a,b=t.stacked?Math.max(E(t.rows.map(e=>Y(e,t.series.length).top)),0)||1:Math.max(E(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,p=t.stacked?Math.max(E(t.rows.map(e=>-Y(e,t.series.length).bottom)),0):Math.max(E(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),g=Math.max(b,t.domain?.[1]??0),$=Math.max(p,-(t.domain?.[0]??0)),w=Math.max(g,t.squeeze?.hi??0)+$,M=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),w,n,t.squeeze,t.breakGap),v=n/e.length,x=t=>(t+.5)*v,N=Math.min(v*i.barfill,u),H=G(v,t.series.length,u),T=c[0]??t.totals[0],L=T?q(T).height*a*.56:0,O=Math.max(((d&&!t.stacked?H.size:N)-L)/2,5*a),z=t=>q(t).width*a,B=t=>t.length?E(t.map(z))+O+4*a:0,_=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,U=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:_(e,n)}))),F=e=>{const n=Y(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let V=t.stacked?B(t.totals.filter((t,e)=>!F(e))):d?B(U.filter(t=>t.value>=0).map(t=>t.label)):0,P=t.stacked?B(t.totals.filter((t,e)=>F(e))):d?B(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-V-P,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!nt(n,M(e.value,t),a)),o=B(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),r=B(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(o<=V&&r<=P)break;V=Math.max(V,o),P=Math.max(P,r)}const j=m-f-V-P,I=f+P+M($,j),D=t=>t<0?I-M(t,j):I+M(t,j);if(t.squeeze&&(t.breakX=D(t.squeeze.gap)),t.x=D,t.stacked)return t.rows.forEach((e,o)=>{const r=Y(e,t.series.length),s=Q(t,e,o,{"data-grow":"right"},r.bottom<0?I-D(r.bottom)+"px center":""),c=x(o)-N/2;X(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:N,...r<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!nt(u,h-d,a)||q(u).height*a>N),J(u,t,i),C(u,(d+h)/2,x(o),y,n)});const i=t.totals[o];i&&(i.dataset.place=F(o)?"before":"after",C(i,F(o)?D(r.bottom)-O:D(r.top)+O,x(o),y,n));const u=l[o];u&&C(u,f-8*a,x(o),y,n)}),void s.appendChild(A("line",{class:r,x1:I,x2:I,y1:0,y2:n}));if(d){t.plot.dataset.grouped="";const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=at(t.plot,e,t=>({size:q(t).height*a,room:H.size+.5*H.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((a,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][r];if(i.missing)return void(u.dataset.place="none");const d=D(i.value),h=i.value<0,f=x(r)+H.offset(l),m=Math.max(Math.abs(d-I),1);0!==i.value&&s.appendChild(A("rect",{class:S(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?I-m:I,y:f,width:m,height:H.size,...K(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),C(u,h?d-O:d+O,f+H.size/2,y,n)});const i=l[r];i&&C(i,f-8*a,x(r),y,n)}),void s.appendChild(A("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}const R=e.map((t,e)=>nt(c[e],Math.abs(D(t.value)-I),a));e.forEach((e,r)=>{const i=D(e.value),u=x(r),d=e.value<0,h=Math.abs(i-I),m=Math.max(h,1);0!==e.value&&s.appendChild(A("rect",{class:S(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?I-m:I,y:u-N/2,width:m,height:N,style:k("--i",e.slot)}));const b=c[r],p=Math.max(Math.min(O,h-z(b)-6*a),6*a),g=d?1:-1;b.dataset.place=R[r]?"inside":d?"before":"after",b.dataset.kind=e.kind,C(b,R[r]?"center"===t.insideAlign?(I+i)/2:"start"===t.insideAlign?I-g*(p+z(b)/2):i+g*(p+z(b)/2):i-g*O,u,y,n);const $=l[r];$&&C($,f-8*a,u,y,n)}),s.appendChild(A("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}},rt={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=Y(e,t.series.length),i=Q(t,e,o,{},r.bottom<0?`center ${f-a(r.top)}px`:""),u=n(o)-s/2;X(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",!et(f,b-m,l)||q(f).width*l>s-4*l),J(f,t,h),C(f,n(o),(m+b)/2,y,c)});const d=t.totals[o];if(d){const t=0===r.top&&r.bottom<0;d.dataset.place=t?"below":"outside",C(d,n(o),t?a(r.bottom)+4*l:a(r.top)-4*l,y,c)}}),void i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}));if(t.series.length>1){const e=n(1)-n(0)||2*n(0),s=G(e,t.series.length,t.barMax);t.plot.dataset.grouped="";const u=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),d=at(t.plot,u,t=>({size:q(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],p=n(r)+s.offset(h);if(m.missing)return void(b.dataset.place="none");const g=a(m.value),$=m.value<0,w=Math.max(Math.abs(f-g),1);0!==m.value&&i.appendChild(A("rect",{class:S(o,e),"data-kind":"bar","data-row":r+1,...$&&{"data-grow":"down"},x:p,y:$?f:f-w,width:s.size,height:w,...K(t,e,h)})),b.dataset.place=$?"below":"outside",b.toggleAttribute("data-left-out",!d),C(b,p+s.size/2,$?g+4*l:g-4*l,y,c)})}),void i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}))}const m=tt(u,s,l),b=e.map((t,e)=>"inside"===d&&!m&&!t.missing&&et(u[e],Math.abs(f-a(t.value)),l)),p=u[0]?q(u[0]).height*l*.56:0;let g=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())b[o]&&(g=Math.min(g,(s-q(r).width*l)/2));e.forEach((t,e)=>{const r=a(t.value),d=t.value<0;if(t.missing)return C(u[e],n(e),f-4*l,y,c),void(u[e].dataset.place="outside");const m=Math.max(Math.abs(f-r),1);0!==t.value&&i.appendChild(A("rect",{class:S(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:k("--i",t.slot)}));const $=d?-1:1,w=Math.min(g,(Math.abs(f-r)-p)/2),M="center"===h?(r+f)/2:"start"===h?f-$*(w+p/2):r+$*(w+p/2),v=d?r+4*l:r-4*l;C(u[e],n(e),b[e]?M:v,y,c),u[e].dataset.place=b[e]?"inside":d?"below":"outside"}),i.appendChild(A("line",{class:r,x1:0,x2:y,y1:f,y2:f}))}},st=0,ct={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 i=500,u=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,f=Math.max(Math.min(y,e)/2-h,10),m=f*s.ringfill,b=f-m/2,p=2*Math.PI*b,g=[];let $=0,w=0,M=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,v=x(M,h),N=`--share:${h.toFixed(4)}; --start:${v.start.toFixed(4)}; --span:${v.span.toFixed(4)};`,H=h*p,T=$/p*2*Math.PI-Math.PI/2;g.push(T),o.appendChild(A("circle",{class:S(l,t),"data-slice":w+1,"data-row":s+1,cx:i,cy:u,r:b,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${H.toFixed(1)} ${(p-H).toFixed(1)}`,"stroke-dashoffset":(-$).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${H.toFixed(1)}; --circ:${p.toFixed(1)}; ${N} --ease:${v.easing}; ${k("--i",t.slot)}`}));const L=T+H/p*Math.PI,O=Math.cos(L),z=Math.sin(L);o.appendChild(A("line",{class:"tablechart-leader",x1:i+O*(f+2*n),y1:u+z*(f+2*n),x2:i+O*(f+7*n),y2:u+z*(f+7*n),"data-row":s+1,style:`${N} ${k("--i",t.slot)}`})),c.style.setProperty("--start",v.start.toFixed(4)),c.style.setProperty("--span",v.span.toFixed(4));const E=f+9*n,B=q(c).width*n/2;C(c,i+O*(E+Math.abs(O)*B),u+z*(E+Math.abs(z)*a*.7),y,e),c.dataset.place="around",$+=H,M+=h,w+=1}),g.length>1){const t=b-m/2-1,n=b+m/2+1,a="tablechart-slices-"+ ++st,r=A("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(A("rect",{x:0,y:0,width:y,height:e,fill:"white"}));for(const e of g)r.appendChild(A("line",{class:"tablechart-divide",x1:i+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:i+Math.cos(e)*n,y2:u+Math.sin(e)*n}));const s=A("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${l}`)))s.appendChild(e);const c=A("defs");c.appendChild(r),o.prepend(c,s)}c&&C(c,i,u,y,e)}},lt=["circle","square","diamond"],it=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=lt.find(t=>n.includes(t));return{shape:a??lt[Math.floor(e/2)%lt.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},ut=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return A("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return A("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return A("polygon",{points:`${e},${n-t} ${e+.87*t},${n+t/2} ${e-.87*t},${n+t/2}`,...o})}return A("circle",{cx:e,cy:n,r:a,...o})},dt=t=>Number(t.toFixed(2));function ht(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 ft,mt,bt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),pt=t=>({segments:bt,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:f,svg:m,stacked:b}=e,p="step"===e.shape,g="smooth"===e.shape,$=a.length>1,w=a.some(t=>t.focus),M=n.length-1,v=l(0),x=n.length>1?c(1)-c(0):2*c(0);m.style.setProperty("--_base",`${dt(v)}px`);const k=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],N=(t,e)=>!k(t,e)||!!k(t,e)?.missing,S=n.map(t=>b?X(t,a.length,!0):null),H=(t,e)=>S[e]?.[t].to??k(t,e)?.value??0,T=(t,e)=>S[e]?.[t].from??0,O=(t,e)=>[c(e),l(H(t,e))],z=a.map((t,e)=>{if(!$)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}); `}}),E=Math.min(M,6);e.plot.style.setProperty("--count",String(E+1));const B=M>0?E/(p?n.length:M):1,_=t=>t*B,U=t=>`--i:${dt(_(t))}`,F=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{N(t,o)||(a<0&&(a=o),(o===M||N(t,o+1))&&((p||o>a)&&e.push([a,o]),a=-1))}),e},V=(t,e)=>`--i:${dt(_(t)+1)}; --d:${dt(_(p?e+1:e)-_(t))}`,j=(t,e)=>({"data-from":t+1,"data-to":e+1,...p&&{"data-flat":""}}),I=g?a.map((t,e)=>ht(n.length,t=>N(e,t),t=>O(e,t))):[],D=g&&t?a.map((t,e)=>ht(n.length,t=>N(e,t),t=>[c(t),l(T(e,t))])):[],R=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{p?(a.push(`H${dt(o+n*x/2)}`),s<t.length-1&&a.push(`V${dt(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])=>`${dt(t)},${dt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${dt(o)},${dt(r)}`)}),a},W=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),l(o(t,e+a))]),G=(t,e,n,a)=>g?t[e].slice(n,a+1):null,K=t=>c(t)-(p?x/2:0),Y=t=>c(t)+(p?x/2:0);t&&a.forEach((t,e)=>(t=>{const e=A("g",{class:"tablechart-area",...z[t].attrs,...b&&{"data-stacked":""},style:z[t].ink}),n=F(t),a=A("g",{class:"tablechart-area-fill",style:`--rows:${dt(E+1)}; ${n.length?V(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=W(t,o,r,H),n=W(t,o,r,T),s=G(D,t,o,r)?.reverse()??null,c=[`M${dt(K(o))},${dt(n[0][1])}`,`L${dt(K(o))},${dt(e[0][1])}`,...R(e,G(I,t,o,r),1),`L${dt(Y(r))},${dt(n[n.length-1][1])}`,...R(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(A("path",{d:c,...j(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=W(t,n,a,H),r=[`M${dt(K(n))},${dt(o[0][1])}`,...R(o,G(I,t,n,a),1)].join(" ");m.appendChild(A("path",{class:"tablechart-series",...z[t].attrs,d:r,...e.line&&{"data-line":e.line},...j(n,a),style:`${z[t].ink}${V(n,a)}`}))}})(e)),p||(()=>{const t=a.map((t,e)=>$?it(a,e):{shape:"circle",open:!1}),e=(e,n,a)=>{const[o,r]=O(e,n);return ut(t[e].shape,o,r,4*u,{...a,style:`${a.style??""}${s=r,`--rise:${dt(v-s)}px; `}${U(n)}`});var s},o=t=>n.map((t,e)=>e).filter(e=>!N(t,e)),r=a.flatMap((n,a)=>t[a].open?o(a).map(t=>e(a,t,{class:h,"data-row":t+1,...$&&{"data-series":a+1}})):[]);L(m,r,y,i),a.forEach((n,a)=>{for(const r of o(a))m.appendChild(e(a,r,{class:d,...z[a].attrs,"data-marker":t[a].shape,...t[a].open&&{"data-open":""},"data-row":r+1,style:z[a].ink}))})})();const Z=(t,e)=>{let n=e;for(;n<M&&!N(t,n+1)&&k(t,n+1)?.value===k(t,e)?.value;)n++;return n},J=(e,n)=>{const o=k(e,n);if(!o||o.missing)return"none";if(p&&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(!$||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&&O(e,n)[1]+7*u+f>v?"above":"below"},Q=$&&!w&&a.length>2&&!b&&!p,tt=new Map;if(Q){const t=n.flatMap((t,e)=>a.map((t,n)=>({s:n,i:e,value:k(n,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==J(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],r=t.map(({s:t,i:n,value:a})=>{const r=q(o[t][n]).width*u,[s,c]=O(t,n);return e(a).map(t=>[s-r/2,"above"===t?c-7*u-f:c+7*u,r,f])}),s=a.flatMap((t,e)=>n.flatMap((t,n)=>{if(N(e,n))return[];const[a,o]=O(e,n);return[[a-4*u,o-4*u,8*u,8*u]]})),l=P(r,s,[0,0,c(M)+c(0),i]);t.forEach(({s:t,i:n,value:a},r)=>tt.set(o[t][n],null===l[r]?null:e(a)[l[r]]))}o.forEach((t,e)=>{t.forEach((t,n)=>{t.style.setProperty("--i",String(dt(p?(_(n)+_(n+1))/2:_(n))));const a=tt.get(t)??J(e,n);if(t.dataset.place="above"===a?"outside":a,t.toggleAttribute("data-left-out","none"!==a&&((t,e)=>Q?null===tt.get(o[t][e]):!(!b&&!p)&&(q(o[t][e]).width*u>(p?Z(t,e)-e+1:1)*x-4*u||!!(b&&t>0&&H(t,e)<T(t,e))||b&&Math.abs(l(T(t,e))-l(H(t,e)))<1.2*f))(e,n)),p&&"none"!==a?t.dataset.rowEnd=String(Z(e,n)+1):delete t.dataset.rowEnd,"none"===a)return;const r=q(t).width*u/2+4*u;let s=c(n);p?s=(c(n)+c(Z(e,n)))/2:"middle"===a&&0===n?s+=r:"middle"===a&&n===M&&(s-=r);const d=l(H(e,n)),h={middle:(l(T(e,n))-d)/2,above:-7*u,below:7*u};C(t,s,d+h[a],y,i)})});const et=s.map((t,e)=>{let n=M;for(;n>0&&N(e,n);)n--;const[a,o]=O(e,n);return{name:t,x:(p?a+x/2:a)+10*u,y:b?(o+l(T(e,n)))/2:o}}),nt=(s[0]?q(s[0]).height:0)*u;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,a)=>{const o=t[a-1];o&&n.y<o.y+e&&(n.y=o.y+e)}),t))(et,nt))C(t.name,t.x,t.y,y,i);const at=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),ot=t||b||2!==a.length||w||at?v:i-2*u;m.appendChild(A("line",{class:r,x1:0,x2:c(M)+c(0),y1:ot,y2:ot}))}}),gt=pt(!1),$t=pt(!0),wt=new Set,yt={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.`;wt.has(a)||(wt.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=tt(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&&et(i[a],r,c)}}),p=i[0]?q(i[0]).height*c*.56:0;let g=Number.POSITIVE_INFINITY;for(const[o,r]of b.entries())r.inside&&(g=Math.min(g,(a-q(i[o]).width*c)/2));const $=t.length,w=(t,e,n=!1)=>`--start:${(t/$).toFixed(4)}; --span:${(e/$).toFixed(4)}; --ease:${n?v:"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(A("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${k("--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(A("rect",{class:S(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:`${k("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const M=i[r];M.style.setProperty("--start",(r/$).toFixed(4)),M.style.setProperty("--span",(1/$).toFixed(4));const v=Math.min(g,(d-p)/2),x="center"===m?u+d/2:"end"===m!==h?u+v+p/2:u+d-v-p/2;M.dataset.place=f?"inside":"outside",M.dataset.kind=n.kind;const N=f?x:"down"===n.kind?u+d+q(M).height*c+3*c:u-3*c;C(M,e(r),N,y,s)}),l.appendChild(A("line",{class:r,x1:0,x2:y,y1:h,y2:h}))}},Mt={enabled:!1,log(...t){Mt.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!Mt.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):Mt.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},vt=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}},xt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),kt=t=>Number(t.toPrecision(12)),Nt=(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)},At=(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},St=(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},Ht=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},Ct=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=St(n,t.step),a=At(t.min,t.max,n);return{...t,step:n,ticks:a}},Tt=["axis-break","trend","bracket"],Lt=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))}},Ot=(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)),Lt(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===o),c&&(c.disabled=o===a.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:o,steps:a.count}}))},zt="tablechart-tooltip",Et=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],Bt=null,_t=null,Ut=null,Ft=0,Vt=()=>{clearTimeout(Ft),Bt&&_t&&(Bt.hidden=!0,_t=null,Ut=null)},Pt=!1,jt=!0,It=NaN,qt=NaN,Dt=!1,Rt=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Wt=()=>{clearTimeout(Ft),Ft=window.setTimeout(Vt,120)},Gt=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Kt=(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},Xt=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Gt(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?Kt(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&&Gt(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Yt=(t,e,n)=>{if(clearTimeout(Ft),_t===t&&Ut===e)return;const a=(t.type.tooltip??Xt)(t,e,n);if(!a.length)return Vt();_t&&_t!==t&&Vt(),Bt??(Bt=(()=>{const t=document.createElement("div");return t.className=zt,t.setAttribute("aria-hidden","true"),t.hidden=!0,ft=document.createElement("div"),(mt=document.createElement("div")).className=`${zt}-arrow`,t.append(ft,mt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(Ft)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Wt()),document.addEventListener("pointerdown",e=>{const n=e.target;!_t||_t.plot.contains(n)||t.contains(n)||Vt()}),window.addEventListener("resize",Vt),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${zt}-line`,n){const t=document.createElement("span");t.className=`${zt}-key`,t.style.background=n,o?.box?t.dataset.sample="box":o&&(t.dataset.sample="line",o.marker&&(t.dataset.marker=o.marker),o.line&&(t.dataset.line=o.line),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${zt}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${zt}-value`,n.textContent=e,r.append(n)}return r},r=t.categories[e]?.textContent??t.rows[e].label,s=1===a.length&&!a[0].name,c=a.every(t=>t.name&&!t.value);ft.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 Et){const t=l.getPropertyValue(f).trim();t?Bt.style.setProperty(f,t):Bt.style.removeProperty(f)}Bt.style.setProperty("--_color",l.color),Bt.style.colorScheme=l.colorScheme,Bt.style.fontFamily=l.fontFamily;const i=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);Bt.parentElement!==i&&i.append(Bt),_t=t,Ut=e,Bt.hidden=!1,Bt.style.left="0px",Bt.style.top="0px";const u=Bt.getBoundingClientRect(),d={x:u.left,y:u.top,scale:Rt(Bt,u.width)},h=Rt(t.plot,t.plot.getBoundingClientRect().width);Bt.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,p=m-n.bottom-r,g=i+d<=b||!(i+d<=p)&&b>=p,$=g?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($,m-i-r))-a.y)/a.scale+"px",t.dataset.side=g?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/a.scale-u+"px"})(Bt,mt,((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)},Zt=t=>{_t===t&&Vt()},Jt={area:$t,bar:ot,column:rt,donut:ct,line:gt,waterfall:yt},Qt={"axis-break":z,trend:W,bracket:V,reference:R},te=Object.keys(Qt),ee=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},ne=["straight","step","smooth"],ae=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},oe=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),re=(t,e)=>{const n=t.dataset.chartShape;return n&&ne.includes(n)?n:ne.includes(e.shape)?e.shape:"straight"},se=0,ce=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=Jt[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(Jt).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(vt);return o.length||o.push(vt(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(ee(e)))continue;const t=document.createElement("span");t.className=b,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-"+ ++se),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=xt(t),o=Math.max(1,E(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 d=l.length>1;d&&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 m=h&&!!s.stackable&&d,p=document.createElement("div");p.className="tablechart-plot",p.setAttribute("aria-hidden","true");const w=A("svg",{role:"presentation",focusable:"false"});p.appendChild(w),t.appendChild(p);const y=s.centre?c.filter(t=>!t.isTotal):c,M=Math.max(0,E(y.flatMap(t=>t.cells.slice(0,l.length).map(t=>B(t.number))))),v=l.map((t,e)=>Math.max(0,E(c.map(t=>B(t.cells[e]?.number??""))))),x=document.createElement("div");x.className="tablechart-values",p.appendChild(x);const k=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=H(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),d&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(v[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),r})),N=k[0],S=m&&s.totals?c.map((t,e)=>{const n=H(a,x);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(Z(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}):[],C=c[c.length-1],T=l.some(t=>t.focus),L=t.getAttribute("data-chart-legend"),O=d&&!s.columns&&(null===L?e.legend||void 0!==s.legend:"false"!==L)?document.createElement("div"):null;O&&(O.className=u,O.setAttribute("aria-hidden","true"),O.inert=!0);const z=d&&!s.columns?l.map((n,a)=>{const o=H(i,O??p);O&&(o.dataset.place="legend");const r=s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==re(t,e)){const t=it(l,a);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return n.line&&!r&&(o.dataset.line=n.line),n.key&&e.langattribute&&o.setAttribute(e.langattribute,n.key),o.dataset.series=String(a+1),o.style.setProperty("--n",String(a)),o.style.setProperty("--palette",`var(--tablechart-color-${a+1})`),o.style.setProperty("--m",T&&!n.focus?"1":"0"),o.style.setProperty("--i",String(C.slot)),o}):[],_=s.centre?H(f,p):null;if(_){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);_.dataset.value=String(e),t&&(_.dataset.decimals=String(B(t.number)))}const U=_&&!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):null,F="beside"===s.categories,V=document.createElement("div");V.className="tablechart-categories",V.setAttribute("aria-hidden","true"),V.inert=!0,F?V.dataset.place="beside":s.centre&&(V.dataset.place="key"),V.style.setProperty("--_columns",String(c.length));let P=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(P+1),t.style.setProperty("--n",String(P)),t.style.setProperty("--palette",`var(--tablechart-color-${P+1})`),P+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),V.appendChild(t)}(F?p:t).appendChild(V),O&&t.appendChild(O);const j=l.filter(t=>!t.group),I=!s.axes&&!s.centre&&ae(t,"data-chart-axis",e.axis),q=s.axes?{titles:j.slice(0,2).map((t,n)=>{const a=H(`${g}-title`,p);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:H(`${$}s`,p),numbers:!0}:I||!s.centre&&ae(t,"data-chart-grid",e.grid)?{titles:[],ticks:H(`${$}s`,p),numbers:I}:null;s.text?.({figure:t,plot:p,rows:c,series:l,config:e});const D=oe(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=>Tt.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 p=a.map(t=>({step:r(t)?u(t.getAttribute("data-fragment-index")):null})),g=s.map(t=>t.map(()=>({step:null,slot:0}))),$=Math.max(0,...s.map(t=>t.length));for(let w=0;w<$;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"));g[t][w]={step:a,slot:i[a]++}}return{rows:m,series:p,cells:g,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,...(g[r]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const s=p[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]")&&Mt.log(`A ${r} chart has no steps, so it is shown whole.`,t),D&&t.setAttribute("data-steps","");const R=t.getAttribute("data-chart-keys"),W=D&&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=A("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(A("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=b,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&&ie.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=Qt[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(Qt).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,p),series:r,after:c.length}}).filter(t=>null!==t);oe(t,e)&&t.setAttribute("data-animate",ue(t,r,e,Boolean(D))),t.classList.toggle("is-webkit","Apple Computer, Inc."===navigator.vendor);const Y={figure:t,plot:p,svg:w,rows:c,decimals:M,type:s,values:N,series:l,seriesValues:k,names:O?[]:z,categories:Array.from(V.children),centre:_,axes:q,stacked:m,totals:S,totalCell:U,rowAt:null,rowBox:null,annotations:X,checks:[],plan:D,step:0,controls:W};let J=0;w.addEventListener("transitionrun",()=>J++);const Q=()=>{J=Math.max(0,J-1),!J&&t.classList.contains("is-shown")&&ge(w)};w.addEventListener("transitionend",Q),w.addEventListener("transitioncancel",Q),W?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&Ot(Y,Y.step+("next"===e?1:-1))}),Ot(Y,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(Dt)return;Dt=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(jt=t.screenX!==It||t.screenY!==qt,It=t.screenX,qt=t.screenY,jt&&(Pt=!1))},{capture:!0,passive:!0});const t=()=>{Pt=!0,Vt()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!0})})();const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if("pointerdown"===o.type)Pt=!1;else if("mouse"===o.pointerType&&(!jt||Pt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return _t===t?Vt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Rt(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 _t===t?Vt():void 0;Yt(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||Pt||Yt(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,_t===t&&Wt())})})(Y,e,"auto"===et),me(Y,e),Y},le={grow:"grow",sweep:"sweep"},ie=["never","auto","print","always"],ue=(t,e,n,a)=>{const o="line"===e||"area"===e,r=le[t.getAttribute("data-chart-animate")??""]??le[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},de=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},he=(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*y:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},fe=(t,e)=>he(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,me=(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:be(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},be=(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)}},pe=(t,e)=>{t.figure.classList.toggle("is-shown",e)},ge=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},$e=t=>"id"===t||"style"===t||t.startsWith("data-chart"),we=/^\s*(?:Table)?:\s+/,ye=t=>"P"===t?.tagName&&we.test(t.textContent??""),Me=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,ve=t=>{const e=ke(t);return"P"===e?.tagName?e:t},xe=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},ke=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},Ne="strong, b, span.total",Ae="data-chart-made",Se=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,He=new Set,Ce=null,Te=["column","bar"],Le=t=>{const e=t.getAttribute("data-chart")||"column";if(!Te.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return Te.includes(n)?n:e},Oe=!1,ze=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=ye(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||$e(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?ye(r)?r:ye(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=ve(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Me.exec(e.textContent??"");if(!n||!te.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=ve(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(we,""),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),Mt?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(Ae)));return(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!Oe&&e&&(Oe=!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:xe(o.rows):xe(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||Mt?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),Mt?.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=ke(e);a?.matches(Ne);a=ke(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=ke(e);t?.matches(Ne);t=ke(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=xt(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}`)})}),Mt?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute),a},Ee=(t,e)=>{const a=Mt.timed("Building",t,()=>ce(t,e));return a?(t.setAttribute(Ae,""),((t,e)=>{let a=t,r=Le(a.figure),s=null,c=!1,i=!1;const d=async()=>{if(!oe(a.figure,e))return pe(a,!0);const t=a.figure.classList.contains("is-shown");if(!c||null===s||t||i)!c&&e.replay&&t&&pe(a,!1);else{i=!0;const t=Se()?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(Se())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)),i=!1,!c&&e.replay||pe(a,!0)}var n},m=()=>{const t=Le(a.figure);if(!t||t===r)return;const n=Mt.timed("Building",a.figure,()=>ce(a.figure,e,t));n&&((t=>{Zt(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${u}`)?.remove(),t.controls?.remove()})(a),Ot(n,a.step,!0),a=n,r=t,s=null)},b=()=>{m();const t=a.plot.clientWidth;t&&t!==s&&Mt.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:s,type:c,values:i,series:u,seriesValues:d,names:m,annotations:b}=t,p=Number.parseFloat(t.figure.dataset.chartAspect??""),M=p>0?p:c.aspect??e.aspect,v="beside"===c.categories,k=t.axes&&!c.axes?t.axes:null,S=v?null:t.categories[0]?.parentElement;let T=null;if(k){a.style.margin="",S&&(S.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=c.segments?.(s)??[],r=t.stacked?s.flatMap(t=>Object.values(Y(t,u.length,c.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):s.flatMap(t=>t.cells.slice(0,u.length).filter(t=>!t.missing).map(t=>t.value)),l=Math.min(0,-E(r.map(t=>-t))),i=Math.max(0,E(r)),d=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:h,chartScale:f}=t.figure.dataset,m=Ht(h??f);if(m&&m.length>2)T={min:m[0],max:m[m.length-1],step:0,ticks:m};else{const[t,e]=m??[l,i],a=Nt(e-t,Math.max((v?n/9:n*M/3)/d,2)),o=(t,e)=>m?t:Number(((e?Math.ceil:Math.floor)(t/a-1e-9*(e?1:-1))*a).toPrecision(12)),r=o(t,!1),s=o(e,!0);T={min:r,max:s,step:a,ticks:At(r,s,a)}}k.ticks.textContent="";const b=s.find(t=>!t.missing),p=E(T.ticks.map(t=>B(String(t))));for(const t of T.ticks){const n=H($,k.ticks);n.dataset.value=String(t),n.dataset.place="none",b?.prefix&&(n.dataset.prefix=b.prefix),b?.suffix&&(n.dataset.suffix=b.suffix),be(n,p,e.locale)}if(k.numbers){const t=Array.from(k.ticks.children);for(const e of t)delete e.dataset.place;I(t),v?a.style.marginBottom=`${(t[0]?q(t[0]).height:0)+6}px`:(a.style.marginLeft=`${E([0,...t.map(t=>q(t).width)])+10}px`,S&&(S.style.marginLeft=a.style.marginLeft))}}const O=a.clientWidth;if(!O)return!1;const z=y/O,_=y*M;a.classList.add("is-placed");for(const n of[...d.flat(),...t.totals])delete n.dataset.place;a.style.removeProperty("--_fit"),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const U=c.axes?t.axes:null;let F=[];if(U){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=u.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=s.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:c,chartScaleY:l,chartScale:i}=t.figure.dataset,d=[Ht(c),Ht(l??i)];F=o.map((t,e)=>((t,e,n)=>{if(n&&n.length>2)return{min:n[0],max:n[n.length-1],step:0,ticks:n};let a=n?.[0]??-E(t.map(t=>-t)),o=n?.[1]??E(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=Nt(o-a,e);return{min:a,max:o,step:r,ticks:At(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?_/z/(4*n):O/(9*n),4),d[e])),U.ticks.textContent="",F.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=E(t.ticks.map(t=>B(String(t))));for(const o of t.ticks){const t=H($,U.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),be(t,s,e.locale)}})}const V=U?Array.from(U.ticks.children):[];I([...d.flat(),...t.totals,...m,...t.categories,...b.map(t=>t.badge),...U?.titles??[],...V]);const P=(i[0]?q(i[0]).height:0)*z,j=b[0]?.badge?q(b[0].badge).height*z:0,D=Math.max(_,he(t.figure,z,"--tablechart-min-height","200px")??0,c.minHeight?.({labelHeight:P,nameHeight:Math.max(0,E(t.categories.map(t=>q(t).height)))*z,unit:z,rows:s.length,series:u.length,stacked:t.stacked})??0),R=t.stacked?s.map(t=>{const e=Z(t,u.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):s,W=(c.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?R.map(t=>({...t,cells:[t.cells[0]]})):s),G={labelHeight:P,badgeHeight:j,hasAnnotations:b.length>0,unit:z,series:u.length,focused:u.some(t=>t.focus),stacked:t.stacked},K=Math.max((X=E,t.stacked?X(s.map(t=>Y(t,u.length,c.running).top)):X([...W.flatMap(t=>[t.from,t.to,t.value]),...s.flatMap(t=>t.cells.slice(0,u.length).map(t=>t.value))])),0);var X;const J=W.some(t=>"up"===t.kind||"down"===t.kind)?W.flatMap(t=>[t.from,t.to]):t.stacked?s.map(t=>Y(t,u.length,c.running).bottom):s.flatMap(t=>t.cells.slice(0,u.length).map(t=>t.value)),Q=Math.min(-E(J.map(t=>-t)),0),tt=c.headroom?.(G)??P,et=2*z+(c.footroom?.(G)??0)+(Q<0?P+4*z:0),nt=D-tt-et,ot=T?Math.max(T.max,K):1.02*K,rt=T?Math.min(T.min,Q):1.02*Q,st=b.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,ct=t=>{const e=Number.parseFloat(st?.getAttribute(t)??"");return Number.isFinite(e)?e:null},lt=ct("data-from")??ct("data-at"),it=ct("data-to");let ut=null;if(st&&(null!==lt||null!==it)){const t=lt??0,e=it??ot,a=null===it?t:null===lt?e:(t+e)/2,o=st.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===it?.22:.3,.05),.8),l=W.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);c.breakable?Q<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>ot||0===t&&e===ot?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${K}.`):l.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):ut={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const dt=ut?ut.gap:null,ht=(ut&&he(t.figure,z,"--tablechart-break-gap",""))??13,ft=D-et,mt=ot-rt||1;let bt,pt,gt=t=>ft-(t-rt)/mt*nt;if(ut){const{lo:t,hi:e,gap:n,share:a}=ut,o=nt*a,r=(nt-o-ht)/(t+(ot-e)),s=o/(e-t);gt=a=>a<=t?ft-a*r:a<=n?ft-t*r-(a-t)*s:a<=e?ft-t*r-(a-t)*s-ht:ft-t*r-o-ht-(a-e)*r}let $t=[];if(U){const t=6*z,[e,n]=U.titles,a=t=>t?q(t).width*z:0,o=t=>t?q(t).height*z:0,r=V.filter(t=>"x"===t.dataset.axis),s=V.filter(t=>"y"===t.dataset.axis),c=o(V[0]),l=a(n)+E([0,...s.map(a)])+2*t,i=c/2;pt=[l,i,y-l-E([0,...r.map(a)])/2,D-i-o(e)-c-2*t];const[u,d,h,f]=pt,[m,b]=F,p=t=>u+(t-m.min)/(m.max-m.min||1)*h,g=t=>d+f-(t-b.min)/(b.max-b.min||1)*f;bt=p,gt=g;const $=t=>a(r.find(e=>Number(e.dataset.value)===t));$t=[Ct(m,e=>e.every((n,a)=>!a||p(n)-p(e[a-1])>($(n)+$(e[a-1]))/2+t)).ticks,Ct(b,e=>e.every((n,a)=>!a||g(e[a-1])-g(n)>c+t/2)).ticks];for(const w of V){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&&C(w,n?u-t:p(e),n?g(e):d+f+t,y,D)}e&&C(e,u+h/2,D-o(e),y,D),n&&C(n,0,d+f/2,y,D)}const wt=m.length?E(m.map(t=>q(t).width))*z+12*z:0,yt=t.categories[0]?.parentElement;yt&&(yt.style.paddingRight=wt?wt/y*100+"%":"");const Mt=(y-wt)/s.length,vt=t=>t>=0&&t<s.length?t:null;t.rowAt=c.centre?null:"beside"===c.categories?(t,e)=>vt(Math.floor(e*z/(D/s.length))):t=>vt(Math.floor(t*z/Mt));const xt=Mt/y*100,kt=100/s.length;if(t.rowBox="beside"===c.categories?t=>[0,t*kt,100,kt]:t=>[t*xt,0,xt,100],r.setAttribute("viewBox",`0 0 1000 ${N(D)}`),r.textContent="",pt&&bt){const[n,a,o,s]=pt,[c,l]=$t,i=bt;ae(t.figure,"data-chart-grid",e.grid)&&r.appendChild(A("path",{class:w,d:[...c.map(t=>`M${N(i(t))},${N(a)}V${N(a+s)}`),...l.map(t=>`M${N(n)},${N(gt(t))}H${N(n+o)}`)].join("")})),r.appendChild(A("path",{class:g,d:[`M${N(n)},${N(a)}V${N(a+s)}H${N(n+o)}`,...c.map(t=>`M${N(i(t))},${N(a+s)}v${N(4*z)}`),...l.map(t=>`M${N(n)},${N(gt(t))}h${N(-4*z)}`)].join("")}))}t.checks=[];const St={rows:s,segments:W,cx:t=>(t+.5)*Mt,y:gt,x:bt,frame:pt,length:(e,n)=>he(t.figure,z,e,n),barWidth:Math.min(Mt*e.barfill,fe(t.figure,z)),barMax:fe(t.figure,z),height:D,unit:z,labelHeight:P,badgeHeight:j,after:s.length,note:0,labels:"inside"===t.figure.dataset.chartLabels||"outside"!==t.figure.dataset.chartLabels&&"inside"===e.labels?"inside":"outside",insideAlign:de(t.figure),breakAt:dt,squeeze:ut,breakGap:ht,domain:T?[T.min,T.max]:null,stacked:t.stacked,shape:re(t.figure,e),totals:t.totals,svg:r,plot:a,values:i,series:u,seriesValues:d,names:m,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[]};if(a.style.setProperty("--count",String(Math.max(1,...s.map(t=>t.slot+1)))),c.draw(St),St.rowAt&&(t.rowAt=St.rowAt),k&&T){const n=6*z,a=v&&St.x?St.x:gt,o=Array.from(k.ticks.children),s=t=>q(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Ct(T,t=>t.every((e,o)=>!o||(v?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*z+n:a(t[o-1])-a(e)>s(e).height*z+n/2))).ticks.filter(t=>!ut||t<=ut.lo||t>=ut.hi);for(const t of o){const e=Number(t.dataset.value),o=k.numbers&&c.includes(e);t.dataset.place=o?v?"below":"before":"none",o&&C(t,v?a(e):-n,v?D+n:a(e),y,D)}const l=y-wt;ae(t.figure,"data-chart-grid",e.grid)&&r.prepend(A("path",{class:w,d:c.map(t=>v?`M${N(a(t))},0V${N(D)}`:`M0,${N(a(t))}H${N(l)}`).join("")})),k.numbers&&r.appendChild(A("path",{class:g,d:[v?`M${N(a(T.min))},${N(D)}H${N(a(T.max))}`:`M0,${N(a(T.max))}V${N(a(T.min))}`,...c.map(t=>v?`M${N(a(t))},${N(D)}v${N(4*z)}`:`M0,${N(a(t))}h${N(-4*z)}`)].join("")}))}for(const[n,o]of b.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series,a=t=>({...t,...t.cells[e]??t.cells[0]});o.type.draw(o.spec,o.badge,{...St,...t.stacked&&{rows:R,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&{rows:s.map(a),segments:W.map(t=>{const e=a(t);return"bar"===t.kind?{...e,to:e.value}:e}),values:d[e]},after: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 i=t.figure.querySelector(`.${f}`);if(i){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?c(i,null,"--i",0):c(i,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}`),m=h[h.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===m?.dataset.kind&&h.length>1){const t=Number(m.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(m.dataset.grow="down"===m.dataset.grow?"up":"down")}const b=Array.from(t.figure.querySelectorAll(`.${l}`));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??"",x(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))}}Lt(t)})(t);const Tt=t.categories[0]?.parentElement;Tt&&"beside"!==c.categories&&!c.centre&&at(Tt,t.categories.filter(t=>null!==t.offsetParent),t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit");const Ot=b.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*z,n=t.offsetHeight*z,a=Number.parseFloat(t.style.left)/100*y,o=Number.parseFloat(t.style.top)/100*D,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*z;return[A("rect",{class:h,"data-for":"badge","data-note":t.dataset.note??"",x:a-e/2,y:o-n/2,width:e,height:n,rx:null===s?c:e*s,ry:null===s?c:n*s,style:["--after","--step"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ")})]}),zt=r.querySelector(`.${w}`);if(zt){const e=a.getBoundingClientRect(),n=y/e.width,o=getComputedStyle(a),s=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2,l=[...d.flat(),...t.totals,..."beside"===c.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?[A("rect",{class:h,"data-for":"text",x:(a.left-e.left)*n-3*z,y:(a.top-e.top)*n+(a.height*n-o)/2-z,width:a.width*n+6*z,height:o+2*z,style:r.join("; ")})]:[]});L(r,l,y,D,zt)}L(r,Ot,y,D);const Et=Ot.length?r.lastElementChild:null,Bt=t.figure.hasAttribute("data-animate")&&!t.figure.hasAttribute("data-steps")&&!t.figure.classList.contains("is-shown");Et&&Bt&&(Et.setAttribute("data-mask",Et.getAttribute("mask")??""),Et.removeAttribute("mask"));const _t=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(c.columns?[t.categories]:[...d,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||c.centre&&s[Number(t.dataset.row)-1]?.isTotal)(e)&&!_t(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>_t(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(a,e))&&(s=t,d())};let M=!1;const v=new ResizeObserver(()=>{M||(M=!0,requestAnimationFrame(()=>{M=!1,b()}))}),k=new IntersectionObserver(t=>{for(const e of t)c=e.isIntersecting,d()},{threshold:e.threshold}),S=()=>{a.figure.classList.add(p),pe(a,!0),ge(a.svg),a.figure.offsetWidth},T=()=>a.figure.classList.remove(p),O=()=>{s=null,b()},z={relabel:()=>me(a,e),refresh:O};m(),b(),v.observe(a.figure),k.observe(a.figure),window.addEventListener("beforeprint",S),window.addEventListener("afterprint",T),(t=>{He.add(t),Ce||(Ce=new MutationObserver(()=>{for(const t of He)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of He)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(z);const _={figure:a.figure,refresh:O,next:()=>Ot(a,a.step+1),previous:()=>Ot(a,a.step-1),stepTo:t=>Ot(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){v.disconnect(),k.disconnect(),window.removeEventListener("beforeprint",S),window.removeEventListener("afterprint",T),(t=>{He.delete(t),!He.size&&Ce&&(Ce.disconnect(),Ce=null)})(z),Zt(a),a.figure.tablechart===_&&delete a.figure.tablechart}};return a.figure.tablechart=_,_})(a,e)):null},Be=e({LEGEND_CLASS:()=>u,NAME_CLASS:()=>i,POINT_CLASS:()=>d,VIEWBOX_WIDTH:()=>y,avoidCollisions:()=>P,htmlEl:()=>H,largest:()=>E,markerEl:()=>ut,placeAt:()=>C,short:()=>N,sizeOf:()=>q});window.Tablechart={init:async(t={},e=document)=>{const n={...M,...t};n.debug&&(Mt.enabled=!0);const a=(await ze(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Ee(t,n)).filter(t=>null!==t);return Mt.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={...M,...e};n.debug&&(Mt.enabled=!0);const[a]=await ze([t],n);return a?Ee(a,n):null},defaultConfig:M,addType:(t,e)=>{Jt[t]=e},kit:Be}}();
@@ -1,3 +1 @@
1
- import { c as e, r as t, t as n } from "./tablechart-shared.mjs";
2
- import { Q as r } from "./tablechart-shared2.mjs";
3
- export { e as addType, n as create, r as defaultConfig, t as init };
1
+ export { c as addType, t as create, M as defaultConfig, r as init } from "./tablechart-shared.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@martinomagnifico/tablechart",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Simple charts from an HTML or Markdown table: column, bar, line, area, waterfall and donut, with annotations. A chart builds when it scrolls into view.",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -1,55 +0,0 @@
1
- import { n as ChartType, s as Config, t as ChartState } from "./tablechart-shared.mjs";
2
- //#region src/js/core.d.ts
3
- /** Adds a chart type for `data-chart="name"`, such as one from `@martinomagnifico/tablechart/additional-types`, before `init()`. */
4
- declare const addType: (name: string, type: ChartType) => void;
5
- /** Pass 2: everything a reader will read, before a translation script looks. */
6
- declare const build: (figure: HTMLElement, config: Config, asKind?: string | null) => ChartState | null;
7
- /** Pass 3. Needs layout; makes no text, only places it. */
8
- declare const layout: (state: ChartState, config: Config) => boolean;
9
- /** Numbers are reformatted in place, so a language change costs no redraw. */
10
- declare const relabel: (state: ChartState, config: Config) => void;
11
- /** Removes what `build` added, so the chart can be built again. */
12
- declare const unbuild: (state: ChartState) => void;
13
- /** One class, `is-shown`, starts the whole build. */
14
- declare const setShown: (state: ChartState, shown: boolean) => void;
15
- //#endregion
16
- //#region src/js/init.d.ts
17
- interface TablechartChart {
18
- figure: HTMLElement;
19
- /** Lays the chart out again, for example after a script has changed its text. */
20
- refresh(): void;
21
- /** Stops watching scroll, size and language. The chart stays as it is. */
22
- destroy(): void;
23
- /** On a chart that steps (`data-fragment`): shows one step more. */
24
- next(): void;
25
- /** On a chart that steps: shows one step less. */
26
- previous(): void;
27
- /** On a chart that steps: shows the chart up to `step`, from 0 to `steps`. */
28
- stepTo(step: number): void;
29
- /** How many steps are shown. */
30
- readonly step: number;
31
- /** How many steps the chart has; 0 for a chart that does not step. */
32
- readonly steps: number;
33
- }
34
- interface TablechartInstance {
35
- charts: TablechartChart[];
36
- /** Lays out every chart again, for example after a script has changed its text. */
37
- refresh(): void;
38
- /** Stops watching scroll, size and language. The charts stay as they are. */
39
- destroy(): void;
40
- }
41
- declare global {
42
- interface HTMLElement {
43
- tablechart?: TablechartChart;
44
- }
45
- }
46
- /** How far an animated parent is in before the chart builds: the figure's `data-chart-entrance`, or else the option. */
47
- declare const entranceOf: (figure: HTMLElement, config: Config) => number;
48
- /** Turns elements into figures with a table and translation keys, all at once, so duplicate keys are found. */
49
- declare const prepare: (found: HTMLElement[], config: Config) => Promise<HTMLElement[]>;
50
- /** Makes a chart of one figure; returns the existing chart if there is one, or null without data. */
51
- declare const create: (element: HTMLElement, options?: Partial<Config>) => Promise<TablechartChart | null>;
52
- /** Makes a chart of every figure in `root` that matches the selector, skipping existing charts. */
53
- declare const init: (options?: Partial<Config>, root?: ParentNode) => Promise<TablechartInstance>;
54
- //#endregion
55
- export { init as a, build as c, setShown as d, unbuild as f, entranceOf as i, layout as l, TablechartInstance as n, prepare as o, create as r, addType as s, TablechartChart as t, relabel as u };