@martinomagnifico/tablechart 1.2.0 → 1.2.2

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 o={};for(var a in e)t(o,a,{get:e[a],enumerable:!0});return n||t(o,Symbol.toStringTag,{value:"Module"}),o},n="tablechart",o="tablechart-value",a="tablechart-bar",r="tablechart-rule",s="tablechart-line",c="tablechart-reference",l="tablechart-quadrant",i="tablechart-head",u="tablechart-slice",d="tablechart-series",h="tablechart-area",f="tablechart-name",b="tablechart-legend",m="tablechart-point",$="tablechart-hole",p="tablechart-centre",g="tablechart-break",w="tablechart-sr",y="is-shown",M="is-printing",v="is-at-once",x="tablechart-axis",k="tablechart-tick",N="tablechart-grid",A=1e3,S={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",values:"auto",ticks:!0,shape:"straight",legend:!1,axis:!1,grid:!1,names:!0,tooltip:"auto",tooltipparent:null,table:"never",tablelimit:15,summary:"auto",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},H="cubic-bezier(0.3, 0.3, 0.6, 1)",C=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?H:"linear"}),O=(t,e)=>`${t}:${e}`,T=t=>Math.round(100*t)/100,L=(t,e={})=>{const n=document.createElementNS("http://www.w3.org/2000/svg",t);for(const o in e){const t=e[o];n.setAttribute(o,String("number"==typeof t?T(t):t))}return n},_=(t,e)=>[t,...e.classes].join(" "),E=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},z=(t,e,n,o,a)=>{t.style.left=e/o*100+"%",t.style.top=n/a*100+"%"},B=0,U=0,V=t=>{let e=t.querySelector(":scope > defs");return e||(e=L("defs"),t.prepend(e)),e},F=t=>{if("circle"===t.tagName){const[e,n,o]=["cx","cy","r"].map(e=>Number(t.getAttribute(e))||0);return`M${T(e-o)},${T(n)}a${T(o)},${T(o)} 0 1 0 ${T(2*o)},0a${T(o)},${T(o)} 0 1 0 ${T(-2*o)},0z`}if("polygon"===t.tagName)return`M${(t.getAttribute("points")??"").trim().split(/\s+/).join("L")}z`;const[e,n,o,a,r,s]=["x","y","width","height","rx","ry"].map(e=>Number(t.getAttribute(e))||0),c=Math.min(r,o/2),l=Math.min(s,a/2),i=(t,e)=>c&&l?`a${T(c)},${T(l)} 0 0 1 ${T(t)},${T(e)}`:"";return`M${T(e+c)},${T(n)}h${T(o-2*c)}${i(c,l)}v${T(a-2*l)}${i(-c,l)}h${T(2*c-o)}${i(-c,-l)}v${T(2*l-a)}${i(c,-l)}z`},R=(t,e,n,o,a)=>{if(!e.length||!a.length)return;const r="tablechart-clip-"+ ++U,s=L("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M${-n},${-o}h${3*n}v${3*o}h${3*-n}z`;s.appendChild(L("path",{d:c+e.map(F).join(""),"clip-rule":"evenodd"})),V(t).appendChild(s);for(const l of a)l.setAttribute("clip-path",`url(#${r})`)},j=(t,e,n,o,a,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++B,c=L("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(L("rect",{x:-n,y:-o,width:3*n,height:3*o,fill:"white"}));for(const u of e)u.setAttribute("fill","black"),c.appendChild(u);const l=V(t);if(l.appendChild(c),a){for(const t of a)t.setAttribute("mask",`url(#${s})`);return}let i=null;for(const u of Array.from(t.childNodes))u!==l&&(r&&u instanceof Element&&u.matches(r)?(i=null,t.appendChild(u)):(i??(i=t.appendChild(L("g",{mask:`url(#${s})`}))),i.appendChild(u)))},q=0,I={create:()=>null,draw(t,e,n){const{rows:o,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,o=.09*n,a=n+2*o,r=.3*a,s=.06*a;if(t.sideways){const n=t.y-o;if(!l)return[[e-r/2,n],[e+r/2,n+a]];const c=a/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+a]]}const c=t.x-o;if(!l)return[[c,e+r/2],[c+a,e-r/2]];const i=a/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+a,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-"+ ++q,h=L("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(L("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(`.${a}`)).map(t=>{const e="rect"===t.tagName?[t]:Array.from(t.querySelectorAll("rect")),n=(t,e)=>Number(t.getAttribute(e)),o=Math.min(...e.map(t=>n(t,"x"))),a=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:o,y:a,width:r-o,height:s-a,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,a]=w.sideways?[i(w,t),i(w,t+n.breakGap)]:[i(w,b-n.breakGap),i(w,b)];h.appendChild(L("path",{d:u([...e,...a.slice().reverse()],!0),fill:"black"})),f.push(e,a);const r=[O("--after",o[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const o of[e,a])s.appendChild(L("path",{class:g,"data-part":"edge","data-note":n.note,d:u(o),style:r}))}if(!f.length)return;const m=Array.from(s.querySelectorAll(`.${g}`)),$=L("g",{mask:`url(#${d})`});for(const a of Array.from(s.childNodes))m.includes(a)||$.appendChild(a);const p=L("defs");p.appendChild(h),s.prepend(p,$)}},P=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},D=t=>(t.split(/[.,]/)[1]||"").length,W=(t,e,n)=>{const o=((t,e)=>new Intl.NumberFormat(e||document.documentElement.lang||void 0,{minimumFractionDigits:t,maximumFractionDigits:t}))(e,n).formatToParts(t),a="minusSign"===o[0]?.type?o[0].value:"";return[a,o.slice(a?1:0).map(t=>t.value).join("")]},G=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),K=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const o of Array.from(t.children))n.appendChild(o.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},Y=(t,e,o,a,r="%")=>{const s=t?.textContent||"",c=G(s),l=r?.5:.5*10**-D(s.match(/-?[\d.,]+/)?.[0]??""),i=!!Number.isNaN(c)||Math.abs(e-c)<=l+1e-9,u={label:o,computed:e,stated:c,agrees:i};a.checks.push(u),i||console.warn(`[${n}] An annotation reads ${c}${r}, but ${o} is ${Number(e.toFixed(2))}${r}. The chart shows your number.`)},X={create:K,draw(t,e,o){const{rows:a,cx:r,y:c,unit:l,labelHeight:u,badgeHeight:d,height:h,svg:f,after:b}=o,[m,$]=((t,e)=>{const n=(e,n)=>{const o=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(o)?o-1:n};return[n("data-from",0),n("data-to",e-1)]})(t,a.length),p=a[m],g=a[$];if(!p||!g)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${m+1} to ${$+1}, of ${a.length}).`);const w=7*l,y=4*l,M=r(m),v=r($),x=Math.min(c(p.value),c(g.value))-u-y-.9*d,k=t=>c(t)-u-y,N=`M ${M} ${k(p.value)} L ${M} ${x} L ${v} ${x} L ${v} ${k(g.value)-w}`,S=(k(p.value)-x+Math.abs(v-M)+(k(g.value)-w-x))/l+1;f.appendChild(L("path",{class:s,"data-note":o.note,d:N,style:`--len:${S.toFixed(1)}; ${O("--after",b)}`}));const H=k(g.value);var C;f.appendChild(L("polygon",{class:i,"data-note":o.note,points:`${v},${H} ${v-.45*w},${H-w} ${v+.45*w},${H-w}`,style:O("--after",b)})),e&&(z(e,(M+v)/2,x,A,h),e.style.setProperty("--after",String(b))),Y(e,(C=p.value,(g.value-C)/Math.abs(C)*100),`${p.value} to ${g.value}`,o)}},Z=(t,e)=>t[0]<e[0]+e[2]&&e[0]<t[0]+t[2]&&t[1]<e[1]+e[3]&&e[1]<t[1]+t[3],Q=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let o=1;for(const l of t)for(const[,,t,e]of l)o=Math.max(o,t,e);const a=new Map,r=([t,e,n,a])=>{const r=[];for(let s=Math.floor(t/o);s<=Math.floor((t+n)/o);s++)for(let t=Math.floor(e/o);t<=Math.floor((e+a)/o);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))a.get(e)?.push(t)??a.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=>!a.get(e)?.some(e=>Z(t,e)));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},J=new WeakMap,tt=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>J.set(t,n[e]))},et=t=>J.get(t)??{width:t.offsetWidth,height:t.offsetHeight},nt=(t,e,n)=>t.some(t=>et(t).width*n>e-6*n),ot=(t,e,n)=>e>=et(t).height*n*1.6,at=(t,e,n)=>e>=et(t).width*n*1.5,rt=(t,e,n,o,a=.7)=>{t.style.setProperty(o,"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>=a?r:0;return t.style.setProperty(o,String(s||a)),s},st={outside:[.5,1],below:[.5,0],after:[0,.5],before:[1,.5]},ct=(t,e,n,o,a=[.5,.5])=>{const[r,s]=st[t.dataset.place??""]??a,{width:c,height:l}=et(t);return[Number.parseFloat(t.style.left)/100*n-c*e*r,Number.parseFloat(t.style.top)/100*o-l*e*s,c*e,l*e]},lt=(t,e,n)=>{for(const o of t){if("none"===o.dataset.place||!o.style.left)continue;const[t]=st[o.dataset.place??""]??[.5,.5],a=et(o).width*e,r=Number.parseFloat(o.style.left)/100*n,s=Math.min(Math.max(r,a*t),n-a*(1-t));s!==r&&(o.style.left=s/n*100+"%")}},it=(t,e,n,o)=>{const a=t.filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out")),r=ut(a,e,n,o);a.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")})},ut=(t,e,n,o)=>{if(t.length<2)return 1;const a=t.map(t=>ct(t,e,n,o)),r=2*e;let s=1;for(;s<t.length&&a.some((t,e)=>{return e>=s&&e%s===0&&(o=t,!((n=a[e-s])[0]+n[2]+r<=o[0]||o[0]+o[2]+r<=n[0]||n[1]+n[3]<=o[1]||o[1]+o[3]<=n[1]));var n,o});)s++;return s},dt={create(t,e){if(!t.textContent?.trim())return null;const n=K(t,e);return n.dataset.kind="note",n},draw(t,e,o){const{rows:a,cx:r,y:s,height:l,unit:i,svg:u,after:d,seriesValues:h}=o;if(o.x||o.centre||"beside"===o.categories[0]?.parentElement?.dataset.place)return void console.warn(`[${n}] A note works on a chart with its rows across, such as a line or column chart.`);const f=(t.getAttribute("data-row")??"").trim(),b=/^\d+$/.test(f)?Number(f)-1:a.findIndex(t=>t.label===f);if(b<0||b>=a.length)return void console.warn(`[${n}] A note is for row "${f}", which is not there.`);const $=r(b),p=s(0);if(u.insertBefore(L("line",{class:c,"data-kind":"note","data-note":o.note,x1:$,x2:$,y1:0,y2:p,style:O("--after",d)}),u.querySelector(`:scope > .${m}`)),!e)return;const g=et(e).width*i,w=et(e).height*i,y=4*i,M=h.flat().flatMap(t=>!t.style.left||"none"===t.dataset.place||t.hasAttribute("data-left-out")?[]:[{label:t,box:ct(t,i,A,l)}]),v=[0,w+y/2].flatMap(t=>[[$-g/2,t,g,w],[$+y,t,g,w],[$-y-g,t,g,w]]),[x]=Q([v],[...o.taken,...M.map(t=>t.box)],[0,0,A,l]),k=v[x??0];if(o.taken.push(k),z(e,k[0]+g/2,k[1]+w/2,A,l),e.style.setProperty("--after",String(d)),null===x)for(const n of M)Z(n.box,k)&&n.label.setAttribute("data-left-out","")}},ht=(t,e,n)=>{const o=n.reduce((t,e)=>t+e,0);if("mean"===t)return o?e.reduce((t,e,o)=>t+e*n[o],0)/o:null;if("median"===t){const t=e.map((t,e)=>[t,n[e]]).sort((t,e)=>t[0]-e[0]);let a=0;for(const[e,[n,r]]of t.entries()){if(a+=r,Math.abs(a-o/2)<1e-9&&t[e+1])return(n+t[e+1][0])/2;if(a>o/2)return n}return null}const a=Number.parseFloat(t);return Number.isFinite(a)?a:null},ft={create(t,e){if(!t.textContent?.trim())return null;const n=K(t,e);return n.dataset.kind="reference",n},draw(t,e,o){const{rows:a,cx:r,y:s,x:l,height:i,unit:u,svg:d,after:h}=o,f=a.filter(t=>!t.isTotal&&!t.missing),b=t.hasAttribute("data-name"),$=(t.getAttribute(b?"data-name":"data-value")??"").trim();let p,g,w;if(b){const t=f.map(t=>G(t.label));if("beside"===o.categories[0]?.parentElement?.dataset.place||t.some(Number.isNaN))return void console.warn(`[${n}] A reference line among the names needs names that are numbers, under columns or points.`);const e=ht($,t,f.map(t=>t.value)),s=null===e?-1:t.findIndex((n,o)=>n<=e&&e<=(t[o+1]??n)),[c,l]=[f[s],f[s+1]??f[s]].map(t=>r(a.indexOf(t))),i=null===e||s<0||void 0===t[s+1]||t[s+1]===t[s]?0:(e-t[s])/(t[s+1]-t[s]);w=e,g=s<0?null:c+i*(l-c),p=!1}else{const e=Boolean(o.frame)&&"y"===t.getAttribute("data-axis"),n=o.frame?o.series.flatMap((t,e)=>t.group?[]:[e])[e?1:0]??0:0;w=ht($,f.map(t=>t.cells[n]?.value??t.value),f.map(()=>1)),p=e||!l,g=null===w?null:l&&!e?l(w):s(w)}if(null===g||null===w)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${$}".`);const[y,M,v,x]=o.frame?[o.frame[0],o.frame[1],o.frame[0]+o.frame[2],o.frame[1]+o.frame[3]]:[0,0,a.length>0?r(a.length-1)+r(0):A,l?i:s(0)];if(d.insertBefore(L("line",{class:c,"data-note":o.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...p?{x1:y,x2:v,y1:g,y2:g}:{x1:g,x2:g,y1:M,y2:x},style:O("--after",h)}),d.querySelector(`:scope > .${m}`)),e){const t=et(e).width*u,n=et(e).height*u,a=4*u,r=p?[[v-t,g-n/2,t,n],[v-t,g-n-a,t,n],[v-t,g+a,t,n]]:[M,M+n,M+2*n].flatMap(e=>[[g-t/2,e,t,n],[g+a,e,t,n],[g-a-t,e,t,n]]),[s]=Q([r],o.taken,[0,0,A,i]),c=r[s??0];o.taken.push(c),z(e,c[0]+t/2,c[1]+n/2,A,i),e.style.setProperty("--after",String(h)),"mean"!==$&&"median"!==$||Y(e,w,`the ${$}`,o,"")}}},bt={create:K,draw(t,e,n){const{rows:o,cx:a,y:r,unit:c,labelHeight:l,height:u,svg:d,values:h,after:f}=n,b=o[0],m=o[o.length-1];if(!b||!m)return;const $=l+18*c,p=10*c,g=10*c;let w=a(0),y=r(b.value)-$,M=a(o.length-1),v=r(m.value)-$,x=0;o.forEach((t,e)=>{const n=M===w?0:(a(e)-w)/(M-w),o=y+n*(v-y)-(r(t.value)-$);o>x&&(x=o)}),y-=x,v-=x;const k=M-w,N=v-y,S=Math.hypot(k,N)||1,H=k/S,C=N/S;w-=H*p,y-=C*p,M+=H*p,v+=C*p;const T=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(M-w)*T,n=y+(v-y)*T,s=et(e).width*c/2,i=n+et(e).height*c/2+8*c;let u=0;o.forEach((e,n)=>{const o=(h[n]?et(h[n]).width:0)*c/2;if(Math.abs(a(n)-t)>=s+o)return;const d=r(e.value)-7*c-l;u=Math.max(u,i-d)}),y-=u,v-=u}const _=M-H*g,E=v-C*g,B=Math.hypot(_-w,E-y)/c+1;d.appendChild(L("line",{class:s,"data-note":n.note,x1:w,y1:y,x2:_,y2:E,style:`--len:${B.toFixed(1)}; ${O("--after",f)}`}));const U=-C,V=H,F=.42*g;d.appendChild(L("polygon",{class:i,"data-note":n.note,points:[`${M},${v}`,`${_+U*F},${E+V*F}`,`${_-U*F},${E-V*F}`].join(" "),style:O("--after",f)})),e&&(z(e,w+(M-w)*T,y+(v-y)*T,A,u),e.style.setProperty("--after",String(f)));const R=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(R)&&R>0&&Y(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,R),`${b.value} to ${m.value} over ${R} years`,n)}},mt=(t,e,n)=>{const o=.15,a=Math.min(.7*t/(e+(e-1)*o),n),r=e*a+(e-1)*a*o;return{size:a,gap:a*o,offset:t=>-r/2+t*a*1.15}},$t=(t,e,n)=>{const o=t.series[n],a=t.series.some(t=>t.focus)&&!o.focus;return{"data-series":n+1,...a&&{"data-muted":""},style:`--n:${n}; --m:${a?1:0}; --palette:var(--tablechart-color-${n+1}); ${O("--i",e.slot)}`}},pt=(t,e,n=!1)=>{let o=0,a=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=o;return o+=c,{from:t,to:o,cell:s}}if(c<0){const t=a;return a+=c,{from:t,to:a,cell:s}}const l=o;return o+=c,{from:l,to:o,cell:s}})},gt=(t,e,n=!1)=>{const o=pt(t,e,n);return{top:Math.max(0,...o.map(t=>t.to)),bottom:Math.min(0,...o.map(t=>t.to))}},wt=(t,e)=>{const{top:n,bottom:o}=gt(t,e);return n+o},yt=(t,e,n)=>{const o=e.series.some(t=>t.focus);t.style.setProperty("--n",String(n)),t.style.setProperty("--m",o&&!e.series[n].focus?"1":"0"),t.style.setProperty("--palette",`var(--tablechart-color-${n+1})`)},Mt=(t,e,n,o={},r="")=>{const s={class:_(a,e),"data-kind":"bar","data-row":n+1,...o},c=O("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=L("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(a,r)=>{const s=void 0!==o["data-grow"]?{"data-grow":o["data-grow"]}:{};l.appendChild(L("rect",{...s,...r,class:_("tablechart-piece",e),"data-row":n+1,...$t(t,e,a)}))}},vt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,groups:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,aspect:.5,minHeight:({labelHeight:t,nameHeight:e,rows:n,series:o,stacked:a})=>{const r=1.1*t,s=o>1&&!a?r*(o+.15*(o-1))/.7:r/.58;return n*Math.max(s,1.2*e)},categories:"beside",headroom:()=>0,draw(t){const{segments:e,height:n,unit:o,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(P(l.map(t=>et(t).width*o)),0),f=Math.min(h+10*o,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*o)/A*100).toFixed(2)}%`);const b=A-4*o,m=t.stacked?Math.max(P(t.rows.map(e=>gt(e,t.series.length).top)),0)||1:Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(P(t.rows.map(e=>-gt(e,t.series.length).bottom)),0):Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),p=Math.max(m,t.domain?.[1]??0),g=Math.max($,-(t.domain?.[0]??0)),w=Math.max(p,t.squeeze?.hi??0)+g,y=(e,n)=>((t,e,n,o,a)=>{if(!o)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=o,i=n*l,u=(n-i-a)/(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+a:r*u+i+a+(t-s)*u})(Math.abs(e),w,n,t.squeeze,t.breakGap),M=n/e.length,v=t=>(t+.5)*M,x=Math.min(M*i.barfill,u),k=mt(M,t.series.length,u),N=c[0]??t.totals[0],S=N?et(N).height*o*.56:0,H=Math.max(((d&&!t.stacked?k.size:x)-S)/2,5*o),C=t=>et(t).width*o,T=t=>t.length?P(t.map(C))+H+4*o:0,E=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,B=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:E(e,n)}))),U=e=>{const n=gt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let V=t.stacked?T(t.totals.filter((t,e)=>!U(e))):d?T(B.filter(t=>t.value>=0).map(t=>t.label)):0,F=t.stacked?T(t.totals.filter((t,e)=>U(e))):d?T(B.filter(t=>t.value<0).map(t=>t.label)):0;const R=(e,n)=>"inside"===t.labels&&at(e,n,o);if(!d&&!t.stacked)for(let a=0;a<3;a++){const t=b-f-V-F,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!R(n,y(e.value,t))),o=T(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),a=T(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(o<=V&&a<=F)break;V=Math.max(V,o),F=Math.max(F,a)}const j=b-f-V-F,q=f+F+y(g,j),I=t=>t<0?q-y(t,j):q+y(t,j);if(t.squeeze&&(t.breakX=I(t.squeeze.gap)),t.x=I,t.stacked)return t.rows.forEach((e,a)=>{const r=gt(e,t.series.length),s=Mt(t,e,a,{"data-grow":"right"},r.bottom<0?q-I(r.bottom)+"px center":""),c=v(a)-x/2;pt(e,t.series.length).forEach(({from:e,to:r,cell:l},i)=>{const u=t.seriesValues[i][a];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:x,...r<e&&{"data-grow":"left"}}),u.dataset.place="inside",u.toggleAttribute("data-left-out",!at(u,h-d,o)||et(u).height*o>x),yt(u,t,i),z(u,(d+h)/2,v(a),A,n)});const i=t.totals[a];i&&(i.dataset.place=U(a)?"before":"after",z(i,U(a)?I(r.bottom)-H:I(r.top)+H,v(a),A,n));const u=l[a];u&&z(u,f-8*o,v(a),A,n)}),void s.appendChild(L("line",{class:r,x1:q,x2:q,y1:0,y2:n}));if(d){const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=rt(t.plot,e,t=>({size:et(t).height*o,room:k.size+.5*k.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((o,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=v(r)+k.offset(l),b=Math.max(Math.abs(d-q),1);0!==i.value&&s.appendChild(L("rect",{class:_(a,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?q-b:q,y:f,width:b,height:k.size,...$t(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),z(u,h?d-H:d+H,f+k.size/2,A,n)});const i=l[r];i&&z(i,f-8*o,v(r),A,n)}),void s.appendChild(L("line",{class:r,x1:q,x2:q,y1:0,y2:n}))}const D=e.map((t,e)=>R(c[e],Math.abs(I(t.value)-q)));e.forEach((e,r)=>{const i=I(e.value),u=v(r),d=e.value<0,h=Math.abs(i-q),b=Math.max(h,1);0!==e.value&&s.appendChild(L("rect",{class:_(a,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?q-b:q,y:u-x/2,width:b,height:x,style:O("--i",e.slot)}));const m=c[r],$=Math.max(Math.min(H,h-C(m)-6*o),6*o),p=d?1:-1;m.dataset.place=D[r]?"inside":d?"before":"after",m.dataset.kind=e.kind,z(m,D[r]?"center"===t.insideAlign?(q+i)/2:"start"===t.insideAlign?q-p*($+C(m)/2):i+p*($+C(m)/2):i-p*H,u,A,n);const g=l[r];g&&z(g,f-8*o,u,A,n)}),s.appendChild(L("line",{class:r,x1:q,x2:q,y1:0,y2:n}))}},xt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,lines:!0,groups:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:o})=>t+4*o+(n?1.6*e:0),draw(t){const{segments:e,cx:n,y:o,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,f=o(0);if(t.stacked)return t.rows.forEach((e,a)=>{const r=gt(e,t.series.length),i=Mt(t,e,a,{},r.bottom<0?`center ${f-o(r.top)}px`:""),u=n(a)-s/2;pt(e,t.series.length).forEach(({from:e,to:r,cell:d},h)=>{const f=t.seriesValues[h][a];if(f.dataset.place="none",d.missing||r===e)return;const b=Math.min(o(r),o(e)),m=Math.max(o(r),o(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",!ot(f,m-b,l)||et(f).width*l>s-4*l),yt(f,t,h),z(f,n(a),(b+m)/2,A,c)});const d=t.totals[a];if(d){const t=0===r.top&&r.bottom<0;d.dataset.place=t?"below":"outside",z(d,n(a),t?o(r.bottom)+4*l:o(r.top)-4*l,A,c)}}),void i.appendChild(L("line",{class:r,x1:0,x2:A,y1:f,y2:f}));if(t.own.length>1){const e=n(1)-n(0)||2*n(0),s=mt(e,t.own.length,t.barMax),u=t.own.flatMap(e=>t.seriesValues[e]).filter(t=>void 0===t.dataset.missing),d=rt(t.plot,u,t=>({size:et(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.own.forEach((u,h)=>{const b=e.cells[u]??e.cells[0],m=t.seriesValues[u][r],$=n(r)+s.offset(h);if(b.missing)return void(m.dataset.place="none");const p=o(b.value),g=b.value<0,w=Math.max(Math.abs(f-p),1);0!==b.value&&i.appendChild(L("rect",{class:_(a,e),"data-kind":"bar","data-row":r+1,...g&&{"data-grow":"down"},x:$,y:g?f:f-w,width:s.size,height:w,...$t(t,e,u)})),m.dataset.place=g?"below":"outside",m.toggleAttribute("data-left-out",!d),z(m,$+s.size/2,g?p+4*l:p-4*l,A,c)})}),void i.appendChild(L("line",{class:r,x1:0,x2:A,y1:f,y2:f}))}const b=t.own[0],m=t.own.length<t.series.length,$=nt(u,s,l),p=e.map((t,e)=>"inside"===d&&!$&&!t.missing&&ot(u[e],Math.abs(f-o(t.value)),l)),g=u[0]?et(u[0]).height*l*.56:0;let w=Number.POSITIVE_INFINITY;for(const[a,r]of u.entries())p[a]&&(w=Math.min(w,(s-et(r).width*l)/2));e.forEach((e,r)=>{const d=o(e.value),$=e.value<0;if(e.missing)return z(u[r],n(r),f-4*l,A,c),void(u[r].dataset.place="outside");const y=Math.max(Math.abs(f-d),1);0!==e.value&&i.appendChild(L("rect",{class:_(a,e),"data-kind":e.kind,"data-row":r+1,...$&&{"data-grow":"down"},x:n(r)-s/2,y:$?f:f-y,width:s,height:y,style:O("--i",e.slot),...m&&$t(t,e,b)}));const M=$?-1:1,v=Math.min(w,(Math.abs(f-d)-g)/2),x="center"===h?(d+f)/2:"start"===h?f-M*(v+g/2):d+M*(v+g/2),k=$?d+4*l:d-4*l;z(u[r],n(r),p[r]?x:k,A,c),u[r].dataset.place=p[r]?"inside":$?"below":"outside",m&&p[r]&&yt(u[r],t,b)}),i.appendChild(L("line",{class:r,x1:0,x2:A,y1:f,y2:f}))}},kt=0,Nt={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:o,svg:a,values:r,config:s,centre:c}){const l=500,i=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*o+10*n,f=Math.max(Math.min(A,e)/2-h,10),b=f*s.ringfill,m=f-b/2,$=2*Math.PI*m,p=[];let g=0,w=0,y=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,M=C(y,h),v=`--share:${h.toFixed(4)}; --start:${M.start.toFixed(4)}; --span:${M.span.toFixed(4)};`,x=h*$,k=g/$*2*Math.PI-Math.PI/2;p.push(k),a.appendChild(L("circle",{class:_(u,t),"data-slice":w+1,"data-row":s+1,cx:l,cy:i,r:m,"stroke-width":b,transform:`rotate(-90 500 ${i})`,"stroke-dasharray":`${x.toFixed(1)} ${($-x).toFixed(1)}`,"stroke-dashoffset":(-g).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${x.toFixed(1)}; --circ:${$.toFixed(1)}; ${v} --ease:${M.easing}; ${O("--i",t.slot)}`}));const N=k+x/$*Math.PI,S=Math.cos(N),H=Math.sin(N);a.appendChild(L("line",{class:"tablechart-leader",x1:l+S*(f+2*n),y1:i+H*(f+2*n),x2:l+S*(f+7*n),y2:i+H*(f+7*n),"data-row":s+1,style:`${v} ${O("--i",t.slot)}`})),c.style.setProperty("--start",M.start.toFixed(4)),c.style.setProperty("--span",M.span.toFixed(4));const T=f+9*n,E=et(c).width*n/2;z(c,l+S*(T+Math.abs(S)*E),i+H*(T+Math.abs(H)*o*.7),A,e),c.dataset.place="around",g+=x,y+=h,w+=1}),p.length>1){const t=m-b/2-1,n=m+b/2+1,o="tablechart-slices-"+ ++kt,r=L("mask",{id:o,maskUnits:"userSpaceOnUse"});r.appendChild(L("rect",{x:0,y:0,width:A,height:e,fill:"white"}));for(const e of p)r.appendChild(L("line",{class:"tablechart-divide",x1:l+Math.cos(e)*t,y1:i+Math.sin(e)*t,x2:l+Math.cos(e)*n,y2:i+Math.sin(e)*n}));const s=L("g",{mask:`url(#${o})`});for(const e of Array.from(a.querySelectorAll(`.${u}`)))s.appendChild(e);const c=L("defs");c.appendChild(r),a.prepend(c,s)}c&&z(c,l,i,A,e)}},At=["circle","square","diamond"],St=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],o=At.find(t=>n.includes(t));return{shape:o??At[Math.floor(e/2)%At.length],open:n.includes("open")||!n.includes("filled")&&!o&&e%2==1}},Ht=(t,e,n,o,a={})=>{if("square"===t){const t=.88*o;return L("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...a})}if("diamond"===t){const t=1.2*o;return L("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...a})}if("triangle"===t){const t=1.3*o;return L("polygon",{points:`${e},${n-.75*t} ${e+.87*t},${n+.75*t} ${e-.87*t},${n+.75*t}`,...a})}return L("circle",{cx:e,cy:n,r:o,...a})},Ct=t=>Number(t.toFixed(2));function Ot(t,e,n){const o=new Array(t).fill(0);let a=[];const r=()=>{(function(t,e){const n=t.length;if(n<2)return t.map(()=>0);const o=n=>(e[n+1]-e[n])/(t[n+1]-t[n]||1),a=new Array(n).fill(0);for(let s=1;s<n-1;s++){const e=o(s-1),n=o(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));a[s]=Math.sign(e)*i||0}if(2===n)return a[0]=o(0),a[1]=o(0),a;const r=(n,o,a)=>{const r=t[o]-t[n];return r?((e[o]-e[n])/r*3-a)/2:a};return a[0]=r(0,1,a[1]),a[n-1]=r(n-2,n-1,a[n-2]),a})(a.map(t=>n(t)[0]),a.map(t=>n(t)[1])).forEach((t,e)=>{o[a[e]]=t}),a=[]};for(let s=0;s<t;s++)e(s)?r():a.push(s);return r(),o}var Tt,Lt,_t=t=>{const e=t.length,n=t.reduce((t,e)=>t+e.x,0)/e,o=t.reduce((t,e)=>t+e.y,0)/e,a=t.reduce((t,e)=>t+(e.x-n)**2,0),r=a?t.reduce((t,e)=>t+(e.x-n)*(e.y-o),0)/a:0,s=t=>o+r*(t-n),c=e>2?Math.sqrt(t.reduce((t,e)=>t+(e.y-s(e.x))**2,0)/(e-2)):0,l=a?c/Math.sqrt(a):0;return{at:s,spread:c,t:l?r/l:r?Number.POSITIVE_INFINITY:0,n:e}},Et=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13],zt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),Bt=t=>({segments:zt,series:!0,stackable:!0,running:!0,swatch:t?"box":void 0,headroom:({labelHeight:t,unit:e})=>1.6*t+6*e,footroom:({labelHeight:e,unit:n,series:o,focused:a,stacked:r})=>t||r||2!==o||a?0:e+7*n,draw(e){const{rows:n,series:o,own:a,seriesValues:s,names:c,cx:l,y:i,height:u,unit:f,labelHeight:b,svg:p,stacked:g}=e,w=a.length<o.length,y="step"===e.shape,M="smooth"===e.shape,v=o.length>1,x=o.some(t=>t.focus),k=n.length-1,N=i(0),S=n.length>1?l(1)-l(0):2*l(0);p.style.setProperty("--_base",`${Ct(N)}px`);const H=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],C=(t,e)=>!H(t,e)||!!H(t,e)?.missing,O=n.map(t=>g?pt(t,o.length,!0):null),T=(t,e)=>O[e]?.[t].to??H(t,e)?.value??0,_=(t,e)=>O[e]?.[t].from??0,E=(t,e)=>[l(e),i(T(t,e))],B=o.map((t,e)=>{if(!v)return{attrs:{},ink:""};const n=x&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),U=w?k:Math.min(k,6);e.plot.style.setProperty("--count",String(U+1));const V=k>0?U/(y?n.length:k):1,F=t=>t*V,R=t=>`--i:${Ct(F(t))}`,q=t=>{const e=[];let o=-1;return n.forEach((n,a)=>{C(t,a)||(o<0&&(o=a),(a===k||C(t,a+1))&&((y||a>o)&&e.push([o,a]),o=-1))}),e},I=(t,e)=>`--i:${Ct(F(t)+1)}; --d:${Ct(F(y?e+1:e)-F(t))}`,P=(t,e)=>({"data-from":t+1,"data-to":e+1,...y&&{"data-flat":""}}),D=M?o.map((t,e)=>Ot(n.length,t=>C(e,t),t=>E(e,t))):[],W=M&&t?o.map((t,e)=>Ot(n.length,t=>C(e,t),t=>[l(t),i(_(e,t))])):[],G=(t,e,n)=>{const o=[];return t.forEach(([a,r],s)=>{y?(o.push(`H${Ct(a+n*S/2)}`),s<t.length-1&&o.push(`V${Ct(t[s+1][1])}`)):s>0&&o.push(e?function(t,e,n,o){const[a,r]=function(t,e,n,o){const a=(e[0]-t[0])/3;return[[t[0]+a,t[1]+n*a],[e[0]-a,e[1]-o*a]]}(t,e,n,o),s=([t,e])=>`${Ct(t)},${Ct(e)}`;return`C${s(a)} ${s(r)} ${s(e)}`}(t[s-1],[a,r],e[s-1],e[s]):`L${Ct(a)},${Ct(r)}`)}),o},K=(t,e,o,a)=>n.slice(e,o+1).map((n,o)=>[l(e+o),i(a(t,e+o))]),Y=(t,e,n,o)=>M?t[e].slice(n,o+1):null,X=t=>l(t)-(y?S/2:0),J=t=>l(t)+(y?S/2:0);t&&a.forEach(t=>(t=>{const e=L("g",{class:h,...B[t].attrs,...g&&{"data-stacked":""},style:B[t].ink}),n=q(t),o=L("g",{class:"tablechart-area-fill",style:`--rows:${Ct(U+1)}; ${n.length?I(...n[0]):""}`});e.appendChild(o);for(const[a,r]of n){const e=K(t,a,r,T),n=K(t,a,r,_),s=Y(W,t,a,r)?.reverse()??null,c=[`M${Ct(X(a))},${Ct(n[0][1])}`,`L${Ct(X(a))},${Ct(e[0][1])}`,...G(e,Y(D,t,a,r),1),`L${Ct(J(r))},${Ct(n[n.length-1][1])}`,...G(n.reverse(),s,-1),"Z"].join(" ");o.appendChild(L("path",{d:c,...P(a,r),style:I(a,r)}))}p.appendChild(e)})(t)),a.forEach(t=>(t=>{const e=o[t];for(const[n,o]of q(t)){const a=K(t,n,o,T),r=[`M${Ct(X(n))},${Ct(a[0][1])}`,...G(a,Y(D,t,n,o),1)].join(" ");p.appendChild(L("path",{class:d,...B[t].attrs,d:r,...e.line&&{"data-line":e.line},...P(n,o),style:`${B[t].ink}${I(n,o)}`}))}})(t));const tt=w?o.flatMap((t,e)=>a.includes(e)?[]:s[e].flatMap(t=>{const e=t.dataset.place;if(!e||"none"===e||t.hasAttribute("data-left-out"))return[];const[n,o,a,r]=ct(t,f,A,u);return[{label:t,box:[n-2*f,o-3*f,a+4*f,r+6*f]}]})):[],nt=y?[]:a.flatMap(t=>n.flatMap((e,n)=>{if(C(t,n))return[];const[o,a]=E(t,n);return[[o-4*f,a-4*f,8*f,8*f]]})),ot=tt.filter(({label:t,box:e})=>{const n=nt.some(t=>Z(t,e));return n&&t.setAttribute("data-left-out",""),!n}),at=(t,e)=>{let n=e;for(;n<k&&!C(t,n+1)&&H(t,n+1)?.value===H(t,e)?.value;)n++;return n},rt=t=>"above"===t?"below":"above",st=(t,e,n)=>{const[o,a]=E(t,e),r=et(s[t][e]).width*f,c=[o-r/2,"above"===n?a-7*f-b:a+7*f,r,b];return c[1]+b>u?Number.POSITIVE_INFINITY:[e-1,e+1].filter(e=>e>=0&&e<=k&&!C(t,e)).flatMap(n=>lt(t,e,n,0)).filter(t=>Z(t,c)).length},lt=(t,e,n,o)=>{const[a,r]=E(t,e),[s,c]=E(t,n),l=Math.max(1,Math.ceil(Math.hypot(s-a,c-r)/(3*f)));return Array.from({length:l+1},(t,e)=>{const n=e/l;return[a+(s-a)*n-o,r+(c-r)*n-o,2*o,2*o]})},it=(e,n)=>{const a=H(e,n);if(!a||a.missing)return"none";if(y&&n>0&&!C(e,n-1)&&H(e,n-1)?.value===a.value)return"none";if(x&&!o[e].focus)return"none";if(g)return"middle";const r=a.value<0?"below":"above";if(!v||x||o.length>2)return t||y||st(e,n,r)<=st(e,n,rt(r))?r:rt(r);const s=H(1-e,n);return!s||s.missing?r:a.value>s.value||a.value===s.value&&0===e||t&&a.value>=0&&E(e,n)[1]+7*f+b>N?"above":"below"},dt=(w||v&&!x&&o.length>2&&!g)&&!y,ht=new Map;if(dt){const t=n.flatMap((t,e)=>a.map(t=>({s:t,i:e,value:H(t,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==it(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],o=t.map(({s:t,i:n,value:o})=>{const a=et(s[t][n]).width*f,[r,c]=E(t,n);return e(o).map(t=>[r-a/2,"above"===t?c-7*f-b:c+7*f,a,b])}),r=a.flatMap(t=>n.flatMap((e,n)=>{if(C(t,n))return[];const[o,a]=E(t,n);return[[o-4*f,a-4*f,8*f,8*f]]})),c=Q(o,[...r,...ot.map(({box:t})=>t)],[0,0,l(k)+l(0),u]);t.forEach(({s:t,i:n,value:o},a)=>ht.set(s[t][n],null===c[a]?null:e(o)[c[a]]))}a.forEach(t=>{s[t].forEach((e,n)=>{e.style.setProperty("--i",String(Ct(y?(F(n)+F(n+1))/2:F(n))));const o=ht.get(e)??it(t,n);if(e.dataset.place="above"===o?"outside":o,e.toggleAttribute("data-left-out","none"!==o&&((t,e)=>dt?null===ht.get(s[t][e]):!(!g&&!y)&&(et(s[t][e]).width*f>(y?at(t,e)-e+1:1)*S-4*f||!!(g&&t>0&&T(t,e)<_(t,e))||g&&Math.abs(i(_(t,e))-i(T(t,e)))<1.2*b))(t,n)),y&&"none"!==o?e.dataset.rowEnd=String(at(t,n)+1):delete e.dataset.rowEnd,"none"===o)return;const a=et(e).width*f/2+4*f;let r=l(n);y?r=(l(n)+l(at(t,n)))/2:"middle"===o&&0===n?r+=a:"middle"===o&&n===k&&(r-=a);const c=i(T(t,n)),d={middle:(i(_(t,n))-c)/2,above:-7*f,below:7*f};z(e,r,c+d[o],A,u)})});const ft=t=>{const o=n.flatMap((e,n)=>e.pinned&&!C(t,n)?[n]:[]),a=n.map((t,e)=>e).filter(e=>!C(t,e)),r=e=>H(t,e)?.value??0,{keys:c}=e.pick;a.length&&(c.includes("last")&&o.push(a[a.length-1]),c.includes("first")&&o.push(a[0]),c.includes("highest")&&o.push(a.reduce((t,e)=>r(e)>r(t)?e:t)),c.includes("lowest")&&o.push(a.reduce((t,e)=>r(e)<r(t)?e:t)),c.includes("outliers")&&o.push(...((t,e=5,n=25)=>{if(t.length<4)return null;const{mean:o,share:a}=(t=>{const e=t.map(t=>t.y),n=Math.min(...e),o=Math.max(...e),a=n<0&&o>0,r=o-n||1;return{mean:e.reduce((t,e)=>t+e,0)/e.length,share:(t,e)=>t/(a?r:Math.abs(e)||r)*100}})(t),r=e=>t.filter(t=>Math.abs(a(t.y-e(t.x),e(t.x)))>n),s=e=>e.length<=t.length/5;let c=_t(t),l=r(c.at);l.length&&s(l)&&(c=_t(t.filter(t=>!l.includes(t))),l=r(c.at)),s(l)||(c=_t(t),l=[]);const i=c.at,u=t[0],d=t[t.length-1],h=a(i(d.x)-i(u.x),o),f=Math.abs(c.t)>=(b=c.n-2,Et[b-1]??(b<30?2.1:2));var b;const m=Math.abs(a(c.spread,o))<e,$=Math.abs(h)<e?"flat":h>0?"up":"down",p="flat"===$?m?"flat":"unclear":f?$:"unclear";return{course:p,line:i,outside:"unclear"===p?[]:l}})(a.map(t=>({x:t,y:r(t)})))?.outside.map(t=>t.x)??[]));const l=[];for(const e of o){const n=s[t][e];l.includes(e)||"none"===n.dataset.place||l.every(e=>1===ut([s[t][e],n],f,1e3,u))&&l.push(e)}return new Set(l)},bt=t=>{const e=s[t].filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out"));return 1===ut(e,f,A,u)},mt=new Map;for(const t of a){const n="all"===e.pick.mode||"auto"===e.pick.mode&&bt(t)?null:ft(t);mt.set(t,n),n&&s[t].forEach((t,e)=>{"none"===t.dataset.place||n.has(e)||t.setAttribute("data-left-out","")})}if(!g&&!y&&a.some(t=>mt.get(t))){const t=l(k)+l(0),e=2*f,o=a.flatMap(t=>n.flatMap((n,o)=>o===k||C(t,o)||C(t,o+1)?[]:lt(t,o,o+1,e))),r=(c[0]?et(c[0]).height:0)*f,i=a.flatMap(t=>{const e=c[t];if(!e)return[];let n=k;for(;n>0&&C(t,n);)n--;const[o,a]=E(t,n);return[[o+10*f,a-r/2,et(e).width*f,r]]}),d=a.flatMap(t=>[...mt.get(t)??[]].map(e=>({s:t,i:e}))),h=({s:t,i:e})=>{const n=H(t,e)?.value??0,o=e>0&&!C(t,e-1)?H(t,e-1)?.value:void 0,a=e<k&&!C(t,e+1)?H(t,e+1)?.value:void 0;return void 0!==(o??a)&&(void 0===o||n<=o)&&(void 0===a||n<=a)?["below","outside","below far","outside far","after","before"]:["outside","below","outside far","below far","after","before"]},m=({s:e,i:n},o)=>{const a=et(s[e][n]).width*f,r=b,[c,l]=E(e,n),i=Math.min(Math.max(c-a/2,0),t-a);return"outside"===o?[i,l-7*f-r,a,r]:"below"===o?[i,l+7*f,a,r]:"outside far"===o?[i,l-7*f-2*r,a,r]:"below far"===o?[i,l+7*f+r,a,r]:"after"===o?[c+7*f,l-r/2,a,r]:[c-7*f-a,l-r/2,a,r]},$=d.map(h),p=e=>e[0]>=0&&e[1]>=0&&e[0]+e[2]<=t&&e[1]+e[3]<=u-2*f,g=d.map(({s:t,i:e})=>{const[n,o]=E(t,e);return[n-6*f,o-6*f,12*f,12*f]}),w=[],y=new Set,M=d.map((t,e)=>{const n=$[e].map(e=>m(t,e)),a=t=>p(t)&&![...w,...i,...g].some(e=>Z(t,e));let r=n.findIndex(t=>a(t)&&!o.some(e=>Z(t,e)));return r<0&&(r=n.findIndex(a),r>=0&&y.add(e)),r>=0&&w.push(n[r]),r<0?null:r});d.forEach((t,e)=>{const n=s[t.s][t.i];n.toggleAttribute("data-cut",y.has(e));const o=M[e];if(null===o)return n.setAttribute("data-left-out","");const a=$[e][o],[r,c,l,i]=m(t,a),d=a.split(" ")[0];n.dataset.place=d,z(n,"after"===d?r:"before"===d?r+l:r+l/2,"outside"===d?c+i:"below"===d?c:c+i/2,A,u)})}y||(()=>{const t=a.map(t=>o[t]),r=o.map((e,n)=>w?St(t,a.indexOf(n)):v?St(o,n):{shape:"circle",open:!1}),s=(t,e,n)=>{const[o,a]=E(t,e);return Ht(r[t].shape,o,a,4*f,{...n,style:`${n.style??""}${s=a,`--rise:${Ct(N-s)}px; `}${R(e)}`});var s},c=t=>n.map((t,e)=>e).filter(e=>!C(t,e)&&((t,e)=>{const n=mt.get(t);return n?n.has(e):S>=10*f})(t,e)),l=a.flatMap(t=>r[t].open?c(t).map(e=>s(t,e,{class:$,"data-row":e+1,...v&&{"data-series":t+1}})):[]);"grow"===p.closest("[data-animate]")?.getAttribute("data-animate")?j(p,l,A,u):e.lineHoles.push(...l),a.forEach(t=>{for(const e of c(t))p.appendChild(s(t,e,{class:m,...B[t].attrs,"data-marker":r[t].shape,...r[t].open&&{"data-open":""},"data-row":e+1,style:B[t].ink}))})})(),e.pointOf=t=>{const e=a.filter(e=>!C(e,t)).map(e=>E(e,t));return e.length?e.reduce((t,e)=>e[1]<t[1]?e:t):null};const $t=(w?[]:c).map((t,e)=>{const n=(t=>{let e=k;for(;e>0&&C(t,e);)e--;return e})(e),[o,a]=E(e,n);return{name:t,x:(y?o+S/2:o)+10*f,y:g?(a+i(_(e,n)))/2:a}}),gt=(c[0]?et(c[0]).height:0)*f;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,o)=>{const a=t[o-1];a&&n.y<a.y+e&&(n.y=a.y+e)}),t))($t,gt))z(t.name,t.x,t.y,A,u);const wt=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),yt=t||g||2!==o.length||x||wt?N:u-2*f;w||p.appendChild(L("line",{class:r,x1:0,x2:l(k)+l(0),y1:yt,y2:yt}))}}),Ut=Bt(!1),Vt=Bt(!0),Ft=new Set,Rt={segments:t=>{let e=0,o=!1;return t.map(t=>{if(t.isTotal)return o&&((t,e)=>{if(Math.abs(t-e)<=Math.abs(e)/100)return;const o=`[${n}] A total reads ${t}, but the steps before it add up to ${Number(e.toFixed(6))}. The chart shows your number.`;Ft.has(o)||(Ft.add(o),console.warn(o))})(t.value,e),o=!1,e=t.value,{...t,from:0,to:t.value,kind:"total"};const a=e;return e+=t.value,o=!0,{...t,from:a,to:e,kind:t.value>=0?"up":"down"}})},breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:o})=>t+6*o+(n?1.6*e:0),draw({segments:t,cx:e,y:n,barWidth:o,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=n(0),f=nt(i,o,c),b=d??"center",m=t.map((e,o)=>{const a=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&&o>0&&o===t.length-1;return{top:a,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!f&&ot(i[o],r,c)}}),$=i[0]?et(i[0]).height*c*.56:0;let p=Number.POSITIVE_INFINITY;for(const[a,r]of m.entries())r.inside&&(p=Math.min(p,(o-et(i[a]).width*c)/2));const g=t.length,w=(t,e,n=!1)=>`--start:${(t/g).toFixed(4)}; --span:${(e/g).toFixed(4)}; --ease:${n?H:"linear"};`;t.forEach((a,r)=>{const s=t[r+1];if(!s)return;const c=n(a.to),i=e(r)+o/2,u=e(r+1)-o/2;l.appendChild(L("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${O("--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(L("rect",{class:_(a,n),"data-kind":n.kind,"data-row":r+1,"data-grow":h?"down":"up",x:e(r)-o/2,y:u,width:o,height:Math.max(d,1),style:`${O("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const y=i[r];y.style.setProperty("--start",(r/g).toFixed(4)),y.style.setProperty("--span",(1/g).toFixed(4));const M=Math.min(p,(d-$)/2),v="center"===b?u+d/2:"end"===b!==h?u+M+$/2:u+d-M-$/2;y.dataset.place=f?"inside":"outside",y.dataset.kind=n.kind;const x=f?v:"down"===n.kind?u+d+et(y).height*c+3*c:u-3*c;z(y,e(r),x,A,s)}),l.appendChild(L("line",{class:r,x1:0,x2:A,y1:h,y2:h}))}},jt={enabled:!1,log(...t){jt.enabled&&console.log(`[${n}]`,...t)},timed(t,e,o){if(!jt.enabled)return o();const a=performance.now(),r=o(),s=performance.now()-a,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):jt.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},qt=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}},It=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).flatMap((t,e)=>t.hasAttribute("data-note")?[e]:[]),Pt=(t,e="data-i18n")=>{const n=It(t);return Array.from(t.querySelectorAll("tbody tr")).map((t,o)=>{const a=t.querySelector("th"),r=Array.from(t.querySelectorAll("td")),s=r.filter((t,e)=>!n.includes(e)).map(qt);s.length||s.push(qt(null));const c=n.map(t=>r[t]).find(t=>t?.textContent?.trim());return{...s[0],label:(a?.textContent||"").trim(),note:c?.textContent?.trim()??null,noteKey:e&&c?.getAttribute(e)||null,short:a?.getAttribute("data-short")||null,pinned:"show"===t.getAttribute("data-value"),key:e&&a?.getAttribute(e)||null,cells:s,classes:Array.from(t.classList),isTotal:"total"===t.getAttribute("data-kind"),slot:o}})},Dt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).filter(t=>!t.hasAttribute("data-note")),Wt=(t,e,n="data-i18n")=>{const o=Dt(t),a=Math.max(1,P(e.map(t=>t.cells.length)));return Array.from({length:a},(t,e)=>{const a=o[e];return{name:(a?.textContent||"").trim(),key:n&&a?.getAttribute(n)||null,focus:"focus"===a?.getAttribute("data-kind"),marker:a?.getAttribute("data-marker")??null,line:(r=a?.getAttribute("data-line"),"dashed"===r||"dotted"===r?r:null),group:!!a?.hasAttribute("data-group"),chart:"line"===a?.getAttribute("data-chart")?"line":null};var r})},Gt=t=>Number(t.toPrecision(12)),Kt=(t,e)=>{const n=t/Math.max(1,e)||1,o=10**Math.floor(Math.log10(n)),a=n/o;return Gt((a<1.42?1:a<3.17?2:a<7.08?5:10)*o)},Yt=(t,e,n)=>{const o=[];for(let a=Math.ceil(t/n-1e-9);a*n<=e+1e-9*n;a++)o.push(Gt(a*n));return o},Xt=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Gt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},Zt=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},Qt=(t,e)=>{let{step:n,ticks:o}=t;for(;n&&o.length>2&&!e(o);)n=Xt(n,t.step),o=Yt(t.min,t.max,n);return{...t,step:n,ticks:o}},Jt=["axis-break","trend","bracket"],te=t=>{const e=t.plan;if(!e)return;const n=e=>null===e||t.step-e>=1;for(const o of t.figure.querySelectorAll("[data-from]")){const t=Number(o.dataset.from)-1,a=Number(o.dataset.to)-1,r=o.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)?a:t-1;else for(;i<a&&n(l(i+1));)i++;const u=o.hasAttribute("data-flat")?(i-t+1)/(a-t+1):a>t?Math.max(0,i-t)/(a-t):0;o.style.setProperty("--reveal",String(u))}},ee=(t,e,n=!1)=>{const o=t.plan;if(!o)return;const a=Math.min(Math.max(Math.round(e),0),o.count),r=a!==t.step;t.step=a,t.figure.style.setProperty("--_step",String(a)),te(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===a),c&&(c.disabled=a===o.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:a,steps:o.count}}))},ne="tablechart-tooltip",oe=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],ae=null,re=null,se=null,ce=0,le=()=>{clearTimeout(ce),ae&&re&&(ae.hidden=!0,re=null,se=null)},ie=!1,ue=!0,de=NaN,he=NaN,fe=!1,be=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,me=()=>{clearTimeout(ce),ce=window.setTimeout(le,120)},$e=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},pe=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole)`);if(!n)return;const o=getComputedStyle(n);return o.fill&&"none"!==o.fill?o.fill:o.stroke},ge=(t,e,n)=>{const o=t.series.length>1,a=[];for(const[s,c]of t.seriesValues.entries()){if(!$e(t,c[e]))continue;const n=o?t.figure.querySelector(`.tablechart-name[data-series="${s+1}"]`):null;a.push({name:o?n?.textContent??t.series[s].name:"",value:c[e].textContent??"",colour:o?pe(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 a.length>1&&$e(t,r)&&a.push({name:n.totallabel,value:r.textContent??""}),a},we=(t,e,n)=>{if(clearTimeout(ce),re===t&&se===e)return;const o=(t.type.tooltip??ge)(t,e,n);if(!o.length)return le();re&&re!==t&&le(),ae??(ae=(()=>{const t=document.createElement("div");return t.className=ne,t.setAttribute("aria-hidden","true"),t.hidden=!0,Tt=document.createElement("div"),(Lt=document.createElement("div")).className=`${ne}-arrow`,t.append(Tt,Lt),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(ce)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&me()),document.addEventListener("pointerdown",e=>{const n=e.target;!re||re.plot.contains(n)||t.contains(n)||le()}),window.addEventListener("resize",le),t})());const a=(t,e,n,o=!1,a)=>{const r=document.createElement("div");if(r.className=`${ne}-line`,n){const t=document.createElement("span");t.className=`${ne}-key`,t.style.background=n,a?.box?t.dataset.sample="box":a&&(t.dataset.sample="line",a.marker&&(t.dataset.marker=a.marker),a.line&&(t.dataset.line=a.line),t.toggleAttribute("data-open",a.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${ne}-${o?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${ne}-value`,n.textContent=e,r.append(n)}return r},r=(t.figure.querySelectorAll("tbody tr")[e]?.querySelector("th"))?.textContent?.trim()||t.categories[e]?.textContent||t.rows[e].label,s=1===o.length&&!o[0].name,c=o.every(t=>t.name&&!t.value),l=((t,e)=>{const n=It(t),o=t.querySelectorAll("tbody tr")[e]?.querySelectorAll("td")??[];return n.map(t=>o[t]).find(t=>t?.textContent?.trim())??null})(t.figure,e)?.textContent?.trim(),i=l?[Object.assign(document.createElement("div"),{className:`${ne}-note`,textContent:l})]:[];Tt.replaceChildren(...c?[]:[a(r,s?o[0].value:"",void 0,!0)],...s?[]:o.map(({name:t,value:e,colour:n,sample:o})=>a(t,e,n,!1,o)),...i);const u=getComputedStyle(t.figure);for(const m of oe){const t=u.getPropertyValue(m).trim();t?ae.style.setProperty(m,t):ae.style.removeProperty(m)}ae.style.setProperty("--_color",u.color),ae.style.colorScheme=u.colorScheme,ae.style.fontFamily=u.fontFamily;const d=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);ae.parentElement!==d&&d.append(ae),re=t,se=e,ae.hidden=!1,ae.style.left="0px",ae.style.top="0px";const h=ae.getBoundingClientRect(),f={x:h.left,y:h.top,scale:be(ae,h.width)},b=be(t.plot,t.plot.getBoundingClientRect().width);ae.style.fontSize=Number.parseFloat(u.fontSize)*b/f.scale+"px",((t,e,n,o={x:0,y:0,scale:1},a=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+(a-u)*o.scale,h=s*o.scale,{clientWidth:f,clientHeight:b}=document.documentElement,m=n.top-r,$=b-n.bottom-r,p=i+d<=m||!(i+d<=$)&&m>=$,g=p?n.top-d-i:n.bottom+d,w=n.left+n.width/2,y=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(y-o.x)/o.scale+"px",t.style.top=(Math.max(r,Math.min(g,b-i-r))-o.y)/o.scale+"px",t.dataset.side=p?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/o.scale-u+"px"})(ae,Lt,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.pointOf?.(e);if(n){const e=t.svg.getBoundingClientRect(),o=e.width/A,a=4*o*(A/t.plot.clientWidth);return new DOMRect(e.left+n[0]*o-a,e.top+n[1]*o-a,2*a,2*a)}const o=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let a=null;for(const u of o){const t=u.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 r=t.plot.getBoundingClientRect(),[s,c,l,i]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(r.left+r.width*s/100,r.top+r.height*c/100,r.width*l/100,r.height*i/100)})(t,e),f)},ye=t=>{re===t&&le()},Me={area:Vt,bar:vt,column:xt,donut:Nt,line:Ut,waterfall:Rt},ve={"axis-break":I,trend:bt,bracket:X,reference:ft,note:dt},xe=Object.keys(ve),ke=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,o,a)=>{const r=e===o,[s,c,l]=r?[Math.min(t,n),Math.max(t,n),e]:[Math.min(e,o),Math.max(e,o),t],i=a.filter(([t,e,n,o])=>r?e<=l&&l<=e+o:t<=l&&l<=t+n).map(([t,e,n,o])=>r?[t,t+n]:[e,e+o]).sort((t,e)=>t[0]-e[0]),u=[];let d=s;for(const[h,f]of i)h>d&&u.push([d,Math.min(h,c)]),d=Math.max(d,f);return d<c&&u.push([d,c]),u.map(([t,e])=>r?`M${T(t)},${T(l)}H${T(e)}`:`M${T(l)},${T(t)}V${T(e)}`).join("")},Se=(t,e)=>{const[n,o,a,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=L("path",{d:Ae(n,o,a,r,e)});for(const{name:c,value:l}of Array.from(t.attributes))/^[xy][12]$/.test(c)||s.setAttribute(c,l);t.replaceWith(s)},He=t=>Array.from((t.getAttribute("d")??"").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g),([,t,e,n,o])=>"H"===n?[+t,+e,+o,+e]:[+t,+e,+t,+o]),Ce=(t,[e,n,o,a])=>t.map(([t,r,s,c])=>r===c?n<=r&&r<=n+a&&Math.max(t,e)<Math.min(s,e+o)?`M${T(Math.max(t,e))},${T(r)}H${T(Math.min(s,e+o))}`:"":e<=t&&t<=e+o&&Math.max(r,n)<Math.min(c,n+a)?`M${T(t)},${T(Math.max(r,n))}V${T(Math.min(c,n+a))}`:"").join(""),Oe=(t,e,n)=>{const o=t.getAttribute(e);return null===o?n:"false"!==o},Te=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),Le=(t,e)=>{const n=t.dataset.chartShape;return n&&Ne.includes(n)?n:Ne.includes(e.shape)?e.shape:"straight"},_e=0,Ee=(t,e,a=null)=>{const r=a??(t.getAttribute("data-chart")||"column"),s=Me[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(Me).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=Pt(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(ke(e)))continue;const t=document.createElement("span");t.className=w,t.textContent=". ",e.before(t)}})(e);const n=t=>t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"),o=t=>{e.id||(e.id="tablechart-caption-"+ ++_e),t.setAttribute("aria-labelledby",e.id)};"FIGURE"!==t.tagName||n(t)||o(t);const a=t.querySelector("table");!a||n(a)||a.querySelector(":scope > caption")||o(a)})(t);let l=Wt(t,c,e.langattribute);if(l.length>1&&!s.series&&!s.columns&&(console.warn(`[${n}] A ${r} chart uses only the first of its ${l.length} value columns.`),l=l.slice(0,1)),l.some(t=>t.chart)){const t=s.lines?l.every(t=>t.chart)?'Every series has data-chart="line", so the chart is a line chart: set data-chart="line" on the figure.':null:`A ${r} chart cannot draw a series as a line.`;t&&(console.warn(`[${n}] ${t}`),l=l.map(t=>({...t,chart:null})))}const i=l.some(t=>t.chart),u=l.length>1;u&&t.style.setProperty("--_series-count",String(l.length));const d=t.hasAttribute("data-chart-stack");d&&!s.stackable&&console.warn(`[${n}] A ${r} chart cannot be stacked.`),d&&i&&console.warn(`[${n}] A chart with a line cannot be stacked.`);const h=d&&!!s.stackable&&u&&!i,m=document.createElement("div");m.className="tablechart-plot",m.setAttribute("aria-hidden","true");const $=L("svg",{role:"presentation",focusable:"false"});m.appendChild($);const g=t.querySelector(":scope > table"),y=e=>g?g.before(e):t.append(e);y(m);const M=s.centre?c.filter(t=>!t.isTotal):c,v=Math.max(0,P(M.flatMap(t=>t.cells.slice(0,l.length).map(t=>D(t.number))))),N=l.map((t,e)=>Math.max(0,P(c.map(t=>D(t.cells[e]?.number??""))))),A=document.createElement("div");A.className="tablechart-values",m.appendChild(A);const S=l.map((t,e)=>c.map((t,n)=>{const a=t.cells[e]??t.cells[0],r=E(o,A);return r.classList.add(...t.classes),r.dataset.value=String(a.value),a.prefix&&(r.dataset.prefix=a.prefix),a.suffix&&(r.dataset.suffix=a.suffix),a.missing&&(r.dataset.missing=a.raw),u&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(N[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),!1===s.numbers&&(e||n)&&(r.dataset.place="none"),r})),H=S[0],C=h&&s.totals?c.map((t,e)=>{const n=E(o,A);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(wt(t,l.length));const a=t.cells[0];return a.prefix&&(n.dataset.prefix=a.prefix),a.suffix&&(n.dataset.suffix=a.suffix),n.style.setProperty("--i",String(t.slot)),n}):[],O=c[c.length-1],T=l.some(t=>t.focus),_=t.getAttribute("data-chart-legend"),z=u&&!s.columns&&(null===_?e.legend||void 0!==s.legend:"false"!==_)?document.createElement("div"):null;z&&(z.className=b,z.setAttribute("aria-hidden","true"),z.inert=!0);const B=l.filter(t=>t.chart),U=u&&!s.columns?l.map((n,o)=>{const a=E(f,z??m);z&&(a.dataset.place="legend");const r=n.chart?void 0:s.legend??s.swatch;if(r&&(a.dataset.swatch=r),a.textContent=n.name,!r&&"step"!==Le(t,e)){const t=n.chart?St(B,B.indexOf(n)):St(l,o);a.dataset.marker=t.shape,a.toggleAttribute("data-open",t.open)}return n.line&&!r&&(a.dataset.line=n.line),n.key&&e.langattribute&&a.setAttribute(e.langattribute,n.key),a.dataset.series=String(o+1),a.style.setProperty("--n",String(o)),a.style.setProperty("--palette",`var(--tablechart-color-${o+1})`),a.style.setProperty("--m",T&&!n.focus?"1":"0"),a.style.setProperty("--i",String(O.slot)),a}):[],V=s.centre?E(p,m):null;if(V){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);V.dataset.value=String(e),t&&(V.dataset.decimals=String(D(t.number)))}const F=V&&!c.some(t=>t.isTotal)?((t,e,n)=>{const o=t.querySelector("table");if(!o)return null;const a=o.querySelector("tfoot [data-chart-total]");if(a)return a.dataset.value=e.dataset.value??"0",a;const r=(o.tFoot??o.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,V,e):null,R="beside"===s.categories,j=document.createElement("div");j.className="tablechart-categories",j.setAttribute("aria-hidden","true"),j.inert=!0,R?j.dataset.place="beside":s.centre&&(j.dataset.place="key"),j.style.setProperty("--_columns",String(c.length));let q=0;for(const[n,o]of c.entries()){const t=document.createElement("span");t.classList.add(...o.classes),t.textContent=o.short??o.label,o.key&&e.langattribute&&t.setAttribute(e.langattribute,o.short?`${o.key}-short`:o.key),s.centre&&(t.dataset.kind=o.isTotal?"total":"slice",o.isTotal||(t.dataset.slice=String(q+1),t.style.setProperty("--n",String(q)),t.style.setProperty("--palette",`var(--tablechart-color-${q+1})`),q+=1)),t.style.setProperty("--i",String(o.slot)),t.dataset.row=String(n+1),j.appendChild(t)}R?m.appendChild(j):y(j),z&&y(z);const I=l.filter(t=>!t.group),W=!s.axes&&!s.centre&&Oe(t,"data-chart-axis",e.axis),G=s.axes?{titles:I.slice(0,2).map((t,n)=>{const o=E(`${x}-title`,m);return o.dataset.axis=n?"y":"x",o.textContent=t.name,t.key&&e.langattribute&&o.setAttribute(e.langattribute,t.key),o}),ticks:E(`${k}s`,m),numbers:!0}:W||!s.centre&&Oe(t,"data-chart-grid",e.grid)?{titles:[],ticks:E(`${k}s`,m),numbers:W}:null;s.text?.({figure:t,plot:m,rows:c,series:l,config:e});const K=Te(t,e)?((t,e=!1)=>{const n=t.hasAttribute("data-fragment"),o=Array.from(t.querySelectorAll("tbody tr")),a=Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),r=Array.from(t.querySelectorAll("[data-annotation]")).filter(t=>Jt.includes(t.getAttribute("data-annotation")??"")),s=t=>t.hasAttribute("data-fragment"),c=o.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(n||o.some(s)||a.some(s)||c.flat().some(s)||r.some(s)))return null;if(e&&!n)return null;const l=[],i=new Map,u=[],d=t=>{let e=null!==t?i.get(t):void 0;return void 0===e&&(e=l.length,l.push(t),u.push(0),null!==t&&i.set(t,e)),e};let h=0;const f="donut"===t.getAttribute("data-chart"),b=t=>f&&"total"===t.getAttribute("data-kind"),m=e?d(t.getAttribute("data-fragment-index")):-1,$=o.map(t=>{if(b(t))return{step:null,slot:0};if(e)return{step:m,slot:u[m]++};if(!n&&!s(t))return{step:null,slot:h++};const o=d(t.getAttribute("data-fragment-index"));return{step:o,slot:u[o]++}}),p=Math.max(-1,...$.map(t=>t.step??-1));if(p>=0)for(const[M,v]of o.entries())b(v)&&($[M]={step:p,slot:u[p]++});const g=a.map(t=>({step:s(t)?d(t.getAttribute("data-fragment-index")):null})),w=c.map(t=>t.map(()=>({step:null,slot:0}))),y=Math.max(0,...c.map(t=>t.length));for(let M=0;M<y;M++)for(const[t,e]of c.entries()){const n=e[M];if(!n||!s(n))continue;const o=d(n.getAttribute("data-fragment-index"));w[t][M]={step:o,slot:u[o]++}}return{rows:$,series:g,cells:w,notes:r.map(t=>{const e=(e,n)=>{const o=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(o)?o-1:n},[n,o]="bracket"===t.getAttribute("data-annotation")?[e("data-from",0),e("data-to",$.length-1)]:[0,$.length-1];let a=null;for(let s=Math.min(n,o);s<=Math.max(n,o);s++)for(const t of[$[s]?.step??null,...(w[s]??[]).map(t=>t.step)])null!==t&&(null===a||t>a)&&(a=t);const r=g[e("data-series",0)]?.step??null;null!==r&&(null===a||r>a)&&(a=r),s(t)&&(a=d(t.getAttribute("data-fragment-index")));const c=null===a?$.length:$.filter(t=>t.step===a).length;return{step:a,after:c}}),count:l.length,indexes:l}})(t,Boolean(s.axes)):null;s.axes&&t.querySelector("tbody [data-fragment], thead [data-fragment]")&&jt.log(`A ${r} chart has one step, with data-fragment on the figure; its rows and columns have no steps of their own.`,t),K&&t.setAttribute("data-steps","");const Y=t.getAttribute("data-chart-keys"),X=K&&e.controls?((t,e,n)=>{const o=document.createElement("div");o.className="tablechart-controls";const a=o=>{const a=document.createElement("button");a.type="button",a.className=`tablechart-${o}`,a.dataset.go=o;const r=document.createElement("span");r.className="tablechart-control-icon",r.setAttribute("aria-hidden","true");const s=L("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(L("path",{d:"next"===o?"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[o];const l=e[o];l&&n&&c.setAttribute(n,l);const i=document.createElement("span");return i.className=w,i.textContent=t.hint,e.hint&&n&&i.setAttribute(n,e.hint),a.append(..."next"===o?[c,i,r]:[r,c,i]),a};return o.append(a("previous"),a("next")),o})({previous:e.previouslabel,next:e.nextlabel,hint:e.stephint},{previous:Y&&`${Y}-previous`,next:Y&&`${Y}-next`,hint:Y&&`${Y}-step`},e.langattribute):null;X&&y(X);const Z=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),o=ve[e];if(!o)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(ve).join(", ")}.`),null;const a=Number.parseInt(t.getAttribute("data-series")??"1",10),r=a>=1&&a<=l.length?a-1:0;return a!==r+1&&console.warn(`[${n}] An annotation reads line ${a}, which is not there; it reads line 1.`),{spec:t,type:o,badge:o.create(t,m),series:r,after:c.length}}).filter(t=>null!==t);if(!R&&!s.centre&&!s.axes)for(const[n,o]of c.entries()){if(!o.note)continue;const t=document.createElement("span");t.dataset.annotation="note",t.dataset.row=String(n+1),t.textContent=o.note,o.noteKey&&t.setAttribute("data-i18n",o.noteKey),Z.push({spec:t,type:dt,badge:dt.create(t,m),series:0,after:c.length})}Te(t,e)&&t.setAttribute("data-animate",Ue(t,r,e,Boolean(K)));const Q={figure:t,plot:m,svg:$,rows:c,decimals:v,type:s,values:H,series:l,seriesValues:S,names:z?[]:U,categories:Array.from(j.children),centre:V,axes:G,stacked:h,totals:C,totalCell:F,rowAt:null,rowBox:null,pointOf:null,annotations:Z,checks:[],plan:K,step:0,controls:X},J=()=>We(t,$);$.addEventListener("transitionend",J),$.addEventListener("transitioncancel",J),X?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&ee(Q,Q.step+("next"===e?1:-1))}),ee(Q,0,!0);const tt=t.getAttribute("data-chart-tooltip"),et="false"!==tt&&("auto"===tt?"auto":null!==tt||e.tooltip);return et&&((t,e,n=!1)=>{const{plot:o}=t;o.setAttribute("data-hover",""),(()=>{if(fe)return;fe=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(ue=t.screenX!==de||t.screenY!==he,de=t.screenX,he=t.screenY,ue&&(ie=!1))},{capture:!0,passive:!0});const t=()=>{ie=!0,le()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!0})})();const a=new Set,r=t=>{for(const e of a)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else a.delete(e);return!1};let s=null;const c=a=>{if("pointerdown"===a.type)ie=!1;else if("mouse"===a.pointerType&&(!ue||ie))return;if(!o.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return re===t?le():void 0;const c=(e=>{if(t.rowAt){const n=o.getBoundingClientRect(),a=be(o,n.width);return t.rowAt((e.clientX-n.left)/a,(e.clientY-n.top)/a)}const n=e.target.closest?.("[data-row]")?.getAttribute("data-row");return n?Number(n)-1:null})(a);if(s=c,null===c||r(c))return re===t?le():void 0;we(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&&a.add(e)});const i=n=>{const o=l(n);if(!o)return;a.delete(o);const c=Number(o.getAttribute("data-row"))-1;s!==c||r(c)||ie||we(t,c,e)};t.svg.addEventListener("transitionend",i),t.svg.addEventListener("transitioncancel",i),o.addEventListener("pointermove",c),o.addEventListener("pointerdown",c),o.addEventListener("pointerleave",e=>{"mouse"===e.pointerType&&(s=null,re===t&&me())})})(Q,e,"auto"===et),Ie(Q,e),Q},ze={grow:"grow",sweep:"sweep"},Be=["never","auto","print","always"],Ue=(t,e,n,o)=>{const a="line"===e||"area"===e,r=ze[t.getAttribute("data-chart-animate")??""]??ze[String(n.animate)];return a?o?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},Ve=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},Fe=(t,e,n,o)=>{const a=getComputedStyle(t),r=(a.getPropertyValue(n).trim()||o).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);if(!r)return null;const s=Number(r[1]);return"%"===r[2]?s/100*A:s*("em"===r[2]?Number.parseFloat(a.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},Re=(t,e)=>Fe(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,je=["first","last","highest","lowest","outliers"],qe=(t,e)=>{const o=(t.getAttribute("data-chart-values")??e.values).trim().toLowerCase().split(/\s+/).filter(Boolean);for(const r of o)["auto","all","none",...je].includes(r)||console.warn(`[${n}] data-chart-values knows no "${r}". It takes auto, all, none, ${je.join(", ")}.`);const a=o.filter(t=>je.includes(t));return o.includes("all")?{mode:"all",keys:[]}:o.includes("none")?{mode:"set",keys:[]}:o.includes("auto")||!a.length?{mode:"auto",keys:a.length?a:je}:{mode:"set",keys:a}},Ie=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const o of t.centre?[...n,t.centre]:n)void 0!==o.dataset.missing?o.textContent=o.dataset.missing:Pe(o,o.dataset.decimals?Number(o.dataset.decimals):t.decimals,e.locale)},Pe=(t,e,n)=>{const{prefix:o="",suffix:a=""}=t.dataset,[r,s]=W(Number.parseFloat(t.dataset.value||"0"),e,n);if(t.textContent=o+(o?r:"")+s+a,r&&!o){const e=document.createElement("span");e.className="tablechart-minus",e.textContent=r,t.prepend(e)}},De=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||Ge(t.svg),n)return t.figure.classList.add(v),t.figure.classList.toggle(y,e),t.figure.offsetWidth,e&&Ke(t.svg),void requestAnimationFrame(()=>t.figure.classList.remove(v));t.figure.classList.toggle(y,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>We(t.figure,t.svg)))},We=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&Ke(e)},Ge=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},Ke=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},Ye=t=>"id"===t||"style"===t||t.startsWith("data-chart"),Xe=/^\s*(?:Table)?:\s+/,Ze=t=>"P"===t?.tagName&&Xe.test(t.textContent??""),Qe=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,Je=t=>{const e=en(t);return"P"===e?.tagName?e:t},tn=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},en=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},nn="strong, b, span.total",on="data-chart-made",an=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,rn=new Set,sn=null,cn=["column","bar"],ln=t=>{const e=t.getAttribute("data-chart")||"column";if(!cn.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return cn.includes(n)?n:e},un=!1,dn=async(t,e)=>{const o=(t=>t.map(t=>{const e=t.closest("p"),n=Ze(e)?e:t;if("TABLE"!==n.tagName&&"P"!==n.tagName)return n;const o=document.createElement("figure");((t,e)=>{for(const{name:n,value:o}of Array.from(t.attributes))("class"===n||Ye(n))&&(e.setAttribute(n,o),t.removeAttribute(n))})(t,o),t.classList.length||t.removeAttribute("class");const a="TABLE"===n.tagName?n:null,r=n.previousElementSibling;let s=n.nextElementSibling;const c=a?Ze(r)?r:Ze(s)?s:null:n;a&&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=Je(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Qe.exec(e.textContent??"");if(!n||!xe.includes(n[1]))return null;if(!n[3]&&e.nextSibling)return null;const o=n[2].trim().split(/\s+/).filter(Boolean).map(t=>t.split("="));return{name:n[1],options:o,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 o=n[e],a=Je(t);if(a!==t&&a.replaceWith(...a.childNodes),o){t.setAttribute("data-annotation",o.name);for(const[e,n]of o.options)t.setAttribute(`data-${e}`,n);o.text.textContent=(o.text.textContent??"").slice(o.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(o),c&&o.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(Xe,""),n.textContent||n.remove());const o=Array.from(t.childNodes),a=o.findIndex(t=>"BR"===t.nodeName);if(e.append(...-1===a?o:o.slice(0,a+1)),-1!==a&&a<o.length-1){const t=document.createElement("span");t.append(...o.slice(a+1)),e.append(t)}return t.remove(),e})(c)),a&&o.append(a),l&&o.append(l),jt?.log?.(`A ${a?"table":"caption"} with chart attributes was wrapped in a figure of its own`),o}))(t.filter(t=>!t.hasAttribute(on)&&"TH"!==t.tagName));(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!un&&e&&(un=!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))})(o),await(async t=>{await Promise.all(t.filter(t=>t.hasAttribute("data-chart-src")).map(async t=>{const e=t.getAttribute("data-chart-src"),o=Array.from(t.querySelectorAll("table")).find(t=>t.tHead)??null;for(const n of t.querySelectorAll("table"))n!==o&&n.remove();try{const n=await fetch(e);if(!n.ok)throw new Error(`${n.status} ${n.statusText}`);const a=await n.json(),r=Array.isArray(a)?a:a?.rows?Array.isArray(a.rows)?a.rows:tn(a.rows):tn(a);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,o=document.createElement("table"),a="Note")=>{for(const l of o.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr"))l.remove();const r=t.some(t=>t.note);if(!o.tHead&&(e.length||n||r)){const t=o.createTHead().insertRow(),a=document.createElement("th");a.textContent=n,t.append(a);for(const n of e){const e=document.createElement("th");e.textContent=n,t.append(e)}}const s=document.createElement("tbody");o.append(s);for(const l of t){const t=s.insertRow();"total"===l.kind&&(t.dataset.kind="total");const e=document.createElement("th");e.textContent=String(l.label??""),l.short&&(e.dataset.short=l.short),t.append(e);for(const n of l.values??[l.value??null])t.insertCell().textContent=null===n?"":String(n);r&&(t.insertCell().textContent=l.note??"")}const c=o.tHead?.rows[o.tHead.rows.length-1];if(r&&c&&!c.querySelector("[data-note]")){const e=Math.max(...t.map(t=>(t.values??[t.value]).length));for(;c.cells.length<e+1;)c.append(document.createElement("th"));const n=document.createElement("th");n.dataset.note="",n.textContent=a,c.append(n)}return o})(r,Array.isArray(a?.series)?a.series.map(String):[],"string"==typeof a?.label?a.label:"",o??void 0,"string"==typeof a?.note?a.note:void 0);if(!o){const e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||jt?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),jt?.log?.(`Read ${r.length} rows from "${e}"`)}catch(a){const t="file:"===window.location.protocol;console.warn(`[${n}] Could not read the chart data in "${e}": ${a.message}.`+(t?" A page opened as a file cannot fetch files; open it from a server.":""))}}))})(o),(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:o}of Array.from(t.attributes))e.setAttribute(n,o);e.append(...t.childNodes),t.replaceWith(e);for(let o=en(e);o?.matches(nn);o=en(e))n.dataset.kind="total",o.replaceWith(...o.childNodes)}const t=Array.from(e.querySelector("thead tr:last-child")?.children??[]);for(const e of t.slice(1))for(let t=en(e);t?.matches(nn);t=en(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(o),((t,e)=>{if(!e)return;const o=new Map;for(const a of t){let t=a.getAttribute("data-chart-keys")||null;if(!t)continue;if(o.has(t)){const e=o.get(t)+1;o.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 o.set(t,1);a.querySelectorAll("tbody th").forEach((n,o)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-row${o+1}`)});const r=Dt(a);r.length>1&&r.forEach((n,o)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-col${o+1}`)}),r.forEach((n,o)=>{if(!n.hasAttribute("data-group"))return;const r=[];a.querySelectorAll(`tbody tr > td:nth-of-type(${o+1})`).forEach(n=>{const o=(n.textContent||"").trim();r.includes(o)||r.push(o),n.getAttribute(e)||n.setAttribute(e,`${t}-group${r.indexOf(o)+1}`)})});const s=It(a);a.querySelectorAll("tbody tr").forEach((n,o)=>{const a=n.querySelectorAll("td");for(const r of s){const n=a[r];n?.textContent?.trim()&&!n.getAttribute(e)&&n.setAttribute(e,`${t}-note${o+1}`)}}),jt?.log?.(`Keys for "${t}" written onto ${a.querySelectorAll("tbody th").length} rows`)}})(o,e.langattribute);for(const n of o)n.dispatchEvent(new CustomEvent("tablechart:table",{bubbles:!0}));return o},hn=(t,e)=>{const o=jt.timed("Building",t,()=>Ee(t,e));return o?(t.setAttribute(on,""),((t,e)=>{let o=t,r=ln(o.figure),m=null,g=!1,w=!1;const y=async()=>{if(!Te(o.figure,e))return De(o,!0);const t=o.figure.classList.contains("is-shown");if(!g||null===m||t||w)!g&&e.replay&&t&&De(o,!1);else{w=!0;const t=an()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(o.figure);t&&await(n=t,new Promise(t=>{const e=["animationstart","transitionrun"],o=()=>{for(const t of e)document.removeEventListener(t,a,!0);r.disconnect(),t()},a=t=>{t.target instanceof Node&&t.target.contains(n)&&o()},r=new MutationObserver(()=>{"0"!==getComputedStyle(n).opacity&&o()});for(const n of e)document.addEventListener(n,a,!0);r.observe(n,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(an())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 o=0;for(const r of n){const t=r.effect?.getComputedTiming(),n=Number(t?.activeDuration??0);if(!t||!Number.isFinite(n))continue;const a=Number(t.delay??0)+n*e;o=Math.max(o,a-Number(r.currentTime??0))}var a;o>0&&await(a=o,new Promise(t=>setTimeout(t,a)))})(o.figure,((t,e)=>{const n=Number.parseFloat(t.dataset.chartEntrance??""),o=Number.isFinite(n)?n:e.entrance;return Math.min(Math.max(o,0),1)})(o.figure,e)),w=!1,!g&&e.replay||De(o,!0)}var n},v=()=>{const t=ln(o.figure);if(!t||t===r)return;const n=jt.timed("Building",o.figure,()=>Ee(o.figure,e,t));n&&((t=>{ye(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${b}`)?.remove(),t.controls?.remove()})(o),ee(n,o.step,!0),o=n,r=t,m=null)},S=()=>{v();const t=o.plot.clientWidth;t&&t!==m&&jt.timed("Layout",o.figure,()=>((t,e)=>{const{plot:o,svg:r,rows:m,type:g,values:w,series:y,seriesValues:M,names:v,annotations:S}=t;(({figure:t,rows:e,series:n},o)=>{const a=t.getAttribute("data-chart-table"),r=a&&Be.includes(a)?a:o.table;"never"===r?t.removeAttribute("data-table"):t.setAttribute("data-table",r);const s=t.getAttribute("data-chart-summary");t.setAttribute("data-summary",s&&Be.includes(s)?s:o.summary),t.toggleAttribute("data-long",e.length*n.filter(t=>!t.group).length>o.tablelimit)})(t,e);const H=Number.parseFloat(t.figure.dataset.chartAspect??""),O=H>0?H:g.aspect??e.aspect,_="beside"===g.categories,B=t.axes&&!g.axes?t.axes:null,U=_?null:t.categories[0]?.parentElement;let V=null;if(B){o.style.margin="",U&&(U.style.marginLeft="");const n=o.clientWidth;if(!n)return!1;const a=g.segments?.(m)??[],r=t.stacked?m.flatMap(t=>Object.values(gt(t,y.length,g.running))):a.some(t=>"up"===t.kind||"down"===t.kind)?a.flatMap(t=>[t.from,t.to]):m.flatMap(t=>t.cells.slice(0,y.length).filter(t=>!t.missing).map(t=>t.value)),s=Math.min(0,-P(r.map(t=>-t))),c=Math.max(0,P(r)),l=Number.parseFloat(getComputedStyle(o).fontSize)||16,{chartScaleY:i,chartScale:u}=t.figure.dataset,d=Zt(i??u);if(d&&d.length>2)V={min:d[0],max:d[d.length-1],step:0,ticks:d};else{const[t,e]=d??[s,c],o=Kt(e-t,Math.max((_?n/9:n*O/3)/l,2)),a=(t,e)=>d?t:Number(((e?Math.ceil:Math.floor)(t/o-1e-9*(e?1:-1))*o).toPrecision(12)),r=a(t,!1),i=a(e,!0);V={min:r,max:i,step:o,ticks:Yt(r,i,o)}}B.ticks.textContent="";const h=m.find(t=>!t.missing),f=P(V.ticks.map(t=>D(String(t))));for(const t of V.ticks){const n=E(k,B.ticks);n.dataset.value=String(t),n.dataset.place="none",h?.prefix&&(n.dataset.prefix=h.prefix),h?.suffix&&(n.dataset.suffix=h.suffix),Pe(n,f,e.locale)}if(B.numbers){const t=Array.from(B.ticks.children);for(const e of t)delete e.dataset.place;tt(t),_?o.style.marginBottom=`${(t[0]?et(t[0]).height:0)+6}px`:(o.style.marginLeft=`${P([0,...t.map(t=>et(t).width)])+10}px`,U&&(U.style.marginLeft=o.style.marginLeft))}}const F=o.clientWidth;if(!F)return!1;const q=A/F,I=A*O;o.classList.add("is-placed");const W=!1===g.numbers?w.slice(0,1):[...M.flat(),...t.totals];for(const n of W)delete n.dataset.place,n.removeAttribute("data-left-out"),n.removeAttribute("data-cut");o.style.removeProperty("--_fit"),o.toggleAttribute("data-grouped",!!g.groups&&!t.stacked&&y.filter(t=>!t.chart&&!t.group).length>1),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const G=g.axes?t.axes:null;let K=[];if(G){const n=Number.parseFloat(getComputedStyle(o).fontSize)||16,a=y.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=m.filter(t=>a.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:s,chartScaleY:c,chartScale:l}=t.figure.dataset,i=[Zt(s),Zt(c??l)];K=a.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 o=n?.[0]??-P(t.map(t=>-t)),a=n?.[1]??P(t);if(!n){const t=.05*(a-o||Math.abs(a)||1);o-=t,a+=t}const r=Kt(a-o,e);return{min:o,max:a,step:r,ticks:Yt(o,a,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?I/q/(4*n):F/(9*n),4),i[e])),G.ticks.textContent="",K.forEach((t,n)=>{const o=r[0]?.cells[a[n]],s=P(t.ticks.map(t=>D(String(t))));for(const a of t.ticks){const t=E(k,G.ticks);t.dataset.axis=n?"y":"x",t.dataset.value=String(a),o?.prefix&&(t.dataset.prefix=o.prefix),o?.suffix&&(t.dataset.suffix=o.suffix),Pe(t,s,e.locale)}})}const Y=G?Array.from(G.ticks.children):[];tt([...M.flat(),...t.totals,...v,...t.categories,...S.map(t=>t.badge),...G?.titles??[],...Y]);const X=(w[0]?et(w[0]).height:0)*q;!1===g.numbers&&w[0]&&(w[0].dataset.place="none");const Z=S[0]?.badge?et(S[0].badge).height*q:0,Q=Math.max(I,Fe(t.figure,q,"--tablechart-min-height","200px")??0,g.minHeight?.({labelHeight:X,nameHeight:Math.max(0,P(t.categories.map(t=>et(t).height)))*q,unit:q,rows:m.length,series:y.length,stacked:t.stacked})??0),J=t.stacked?m.map(t=>{const e=wt(t,y.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):m,nt=(g.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?J.map(t=>({...t,cells:[t.cells[0]]})):m),ot={labelHeight:X,badgeHeight:Z,hasAnnotations:S.length>0,unit:q,series:y.length,focused:y.some(t=>t.focus),stacked:t.stacked},at=Math.max((st=P,t.stacked?st(m.map(t=>gt(t,y.length,g.running).top)):st([...nt.flatMap(t=>[t.from,t.to,t.value]),...m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value))])),0);var st;const ct=nt.some(t=>"up"===t.kind||"down"===t.kind)?nt.flatMap(t=>[t.from,t.to]):t.stacked?m.map(t=>gt(t,y.length,g.running).bottom):m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value)),ut=Math.min(-P(ct.map(t=>-t)),0),dt=y.flatMap((t,e)=>t.chart?[e]:[]),ht=m.some(t=>t.note)?Z+4*q:0,ft=Math.max(g.headroom?.(ot)??X,dt.length?Ut.headroom?.(ot)??0:0)+ht,bt=2*q+(g.footroom?.(ot)??0)+(ut<0?X+4*q:0),mt=Q-ft-bt,$t=V?Math.max(V.max,at):1.02*at,pt=V?Math.min(V.min,ut):1.02*ut,yt=S.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,Mt=t=>{const e=Number.parseFloat(yt?.getAttribute(t)??"");return Number.isFinite(e)?e:null},vt=Mt("data-from")??Mt("data-at"),xt=Mt("data-to");let kt=null;if(yt&&(null!==vt||null!==xt)){const t=vt??0,e=xt??$t,o=null===xt?t:null===vt?e:(t+e)/2,a=yt.getAttribute("data-size"),r=a?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===a||r||console.warn(`[${n}] data-size="${a}" is not a percentage, such as 30%. Using the default.`);const s=Math.min(Math.max(r?Number(r[1])/100:null===xt?.22:.3,.05),.8),c=nt.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);g.breakable?ut<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>$t||0===t&&e===$t?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${at}.`):c.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):kt={lo:t,hi:e,gap:o,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const Nt=kt?kt.gap:null,At=(kt&&Fe(t.figure,q,"--tablechart-break-gap",""))??13,St=Q-bt,Ht=$t-pt||1;let Ct,Ot,Tt=t=>St-(t-pt)/Ht*mt;if(kt){const{lo:t,hi:e,gap:n,share:o}=kt,a=mt*o,r=(mt-a-At)/(t+($t-e)),s=a/(e-t);Tt=o=>o<=t?St-o*r:o<=n?St-t*r-(o-t)*s:o<=e?St-t*r-(o-t)*s-At:St-t*r-a-At-(o-e)*r}let Lt=[];if(G){const t=6*q,[e,n]=G.titles,o=t=>t?et(t).width*q:0,a=t=>t?et(t).height*q:0,r=Y.filter(t=>"x"===t.dataset.axis),s=Y.filter(t=>"y"===t.dataset.axis),c=a(Y[0]),l=o(n)+P([0,...s.map(o)])+2*t,i=c/2;Ot=[l,i,A-l-P([0,...r.map(o)])/2,Q-i-a(e)-c-2*t];const[u,d,h,f]=Ot,[b,m]=K,$=t=>u+(t-b.min)/(b.max-b.min||1)*h,p=t=>d+f-(t-m.min)/(m.max-m.min||1)*f;Ct=$,Tt=p;const g=t=>o(r.find(e=>Number(e.dataset.value)===t));Lt=[Qt(b,e=>e.every((n,o)=>!o||$(n)-$(e[o-1])>(g(n)+g(e[o-1]))/2+t)).ticks,Qt(m,e=>e.every((n,o)=>!o||p(e[o-1])-p(n)>c+t/2)).ticks];for(const w of Y){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,o=Lt[n].includes(e);w.dataset.place=o?n?"before":"below":"none",o&&z(w,n?u-t:$(e),n?p(e):d+f+t,A,Q)}e&&z(e,u+h/2,Q-a(e),A,Q),n&&z(n,0,d+f/2,A,Q)}const _t=v.length?P(v.map(t=>et(t).width))*q+12*q:0,Et=t.categories[0]?.parentElement;Et&&(Et.style.paddingRight=_t?_t/A*100+"%":"");const zt=(A-_t)/m.length,Bt=t=>t>=0&&t<m.length?t:null;t.rowAt=g.centre?null:"beside"===g.categories?(t,e)=>Bt(Math.floor(e*q/(Q/m.length))):t=>Bt(Math.floor(t*q/zt));const Ft=zt/A*100,Rt=100/m.length;if(t.rowBox="beside"===g.categories?t=>[0,t*Rt,100,Rt]:t=>[t*Ft,0,Ft,100],r.setAttribute("viewBox",`0 0 1000 ${T(Q)}`),r.textContent="",Ot&&Ct){const[n,o,a,s]=Ot,[c,l]=Lt,i=Ct;Oe(t.figure,"data-chart-grid",e.grid)&&r.appendChild(L("path",{class:N,d:[...c.map(t=>`M${T(i(t))},${T(o)}V${T(o+s)}`),...l.map(t=>`M${T(n)},${T(Tt(t))}H${T(n+a)}`)].join("")})),r.appendChild(L("path",{class:x,d:[`M${T(n)},${T(o)}V${T(o+s)}H${T(n+a)}`,...c.map(t=>`M${T(i(t))},${T(o+s)}v${T(4*q)}`),...l.map(t=>`M${T(n)},${T(Tt(t))}h${T(-4*q)}`)].join("")}))}t.checks=[];const jt={rows:m,segments:nt,cx:t=>(t+.5)*zt,y:Tt,x:Ct,frame:Ot,length:(e,n)=>Fe(t.figure,q,e,n),barWidth:Math.min(zt*e.barfill,Re(t.figure,q)),barMax:Re(t.figure,q),height:Q,unit:q,labelHeight:X,badgeHeight:Z,after:m.length,note:0,labels:"inside"===t.figure.dataset.chartLabels||"outside"!==t.figure.dataset.chartLabels&&("inside"===e.labels||dt.length>0)?"inside":"outside",insideAlign:Ve(t.figure),breakAt:Nt,squeeze:kt,breakGap:At,domain:V?[V.min,V.max]:null,stacked:t.stacked,shape:Le(t.figure,e),pick:qe(t.figure,e),totals:t.totals,svg:r,plot:o,values:w,series:y,own:y.map((t,e)=>e),seriesValues:M,names:v,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[],lineHoles:[]};o.style.setProperty("--count",String(Math.max(1,...m.map(t=>t.slot+1))));const qt=t=>{const e=e=>({...e,...e.cells[t]??e.cells[0]});return{rows:m.map(e),segments:nt.map(t=>{const n=e(t);return"bar"===t.kind?{...n,to:n.value}:n}),values:M[t]}};if(dt.length){const t=y.flatMap((t,e)=>t.chart?[]:[e]);g.draw({...jt,own:t,...1===t.length&&qt(t[0])}),Ut.draw({...jt,own:dt})}else g.draw(jt);jt.rowAt&&(t.rowAt=jt.rowAt),t.pointOf=jt.pointOf??null;const It=Number(o.style.getPropertyValue("--count"))||m.length;for(const n of t.figure.querySelectorAll(`.${f}`))n.style.setProperty("--i",String(Math.min(m[m.length-1].slot,It-1)));if(!t.stacked&&!o.hasAttribute("data-grouped"))for(const n of M)lt(n,q,A),it(n,q,A,Q);if(B&&V){const n=6*q,o=_&&jt.x?jt.x:Tt,a=Array.from(B.ticks.children),s=t=>et(a.find(e=>Number(e.dataset.value)===t)??a[0]),c=Qt(V,t=>t.every((e,a)=>!a||(_?o(e)-o(t[a-1])>(s(e).width+s(t[a-1]).width)/2*q+n:o(t[a-1])-o(e)>s(e).height*q+n/2))).ticks.filter(t=>!kt||t<=kt.lo||t>=kt.hi);for(const t of a){const e=Number(t.dataset.value),a=B.numbers&&c.includes(e);t.dataset.place=a?_?"below":"before":"none",a&&z(t,_?o(e):-n,_?Q+n:o(e),A,Q)}const l=A-_t;Oe(t.figure,"data-chart-grid",e.grid)&&r.prepend(L("path",{class:N,d:c.map(t=>_?`M${T(o(t))},0V${T(Q)}`:`M0,${T(o(t))}H${T(l)}`).join("")})),B.numbers&&r.appendChild(L("path",{class:x,d:[_?`M${T(o(V.min))},${T(Q)}H${T(o(V.max))}`:`M0,${T(o(V.max))}V${T(o(V.min))}`,...c.map(t=>_?`M${T(o(t))},${T(Q)}v${T(4*q)}`:`M0,${T(o(t))}h${T(-4*q)}`)].join("")}))}for(const[n,a]of S.entries()){a.badge?.setAttribute("data-note",String(n+1));const e=a.series;a.type.draw(a.spec,a.badge,{...jt,...t.stacked&&{rows:J,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&qt(e),after:t.plan?a.after:Math.min(a.after,Number(o.style.getPropertyValue("--count"))||a.after),note:n+1})}(t=>{const e=t.plan;if(!e)return;const n=e.rows.length-1,o=t=>e.series.map((n,o)=>e.cells[t]?.[o]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=o(t);return e.some(t=>null===t)?null:Math.min(...e)},s=new Set(t.totals),c=Boolean(t.type.axes),l=(t,e,n,o)=>{c&&"--i"===n||t.style.setProperty(n,String(o)),t.style.removeProperty("--d"),null===e?t.style.removeProperty("--step"):t.style.setProperty("--step",String(e))};for(const a of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(a.closest("table, .tablechart-controls")||a.hasAttribute("data-from"))continue;const t=Number(a.dataset.note);if(t>0){const n=e.notes[t-1];n&&l(a,n.step,"--after",n.after);continue}const c=a.dataset.row?Number(a.dataset.row)-1:n;if(a.classList.contains("tablechart-connector")){const t=e.rows[c-1],n=e.rows[c];if(t&&n){const e=(t.step??-1)>(n.step??-1);l(a,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(s.has(a)){const t=o(c).filter(t=>null!==t);l(a,t.length?Math.max(...t):null,"--i",e.rows[c]?.slot??0);continue}if(a.hasAttribute("data-stack")){l(a,r(c),"--i",e.rows[c]?.slot??0);continue}const i=a.dataset.series?Number(a.dataset.series)-1:0,u=a.dataset.series?e.series[i]:void 0;if(a.classList.contains("tablechart-piece")){const t=o(c)[i]??null,n=e.cells[c]?.[i];l(a,t===r(c)?null:t,"--i",n&&null!==n.step?n.slot:c);continue}if("legend"===a.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(a,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[c]?.[i];d&&null!==d.step?l(a,d.step,"--i",d.slot):u&&null!==u.step?l(a,u.step,"--i",c):e.rows[c]&&l(a,e.rows[c].step,"--i",e.rows[c].slot)}const i=t.figure.querySelector(`.${p}`);if(i){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?l(i,null,"--i",0):l(i,n,"--i",t.filter(t=>t===n).length)}const d=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),h=e.series.some(t=>null!==t.step)?e.rows.length:1;c||t.plot.style.setProperty("--count",String(Math.max(h,...d)));const f=t.figure.querySelectorAll(`.${a}`),b=f[f.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&f.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${u}`));if(m.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),o=m.length,a=Math.max(0,m.findIndex((t,n)=>e(t)!==e(m[(n-1+o)%o]))),r=[];for(let t=0;t<o;t++){const n=m[(a+t)%o],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 o=0;for(const a of t)s.set(a.dataset.row??"",C(o,n(a),e)),o+=n(a)}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))}}te(t)})(t);for(const n of t.figure.querySelectorAll(`.${b}`)){const e=Array.from(n.children);if(t.plan)for(const t of e)t.style.getPropertyValue("--step")||t.style.setProperty("--i","0");const o=e.map(t=>Number.parseFloat(t.style.getPropertyValue("--step")));n.style.setProperty("--i",String(Math.min(...e.map(t=>Number(t.style.getPropertyValue("--i"))||0)))),o.length&&o.every(Number.isFinite)?n.style.setProperty("--step",String(Math.min(...o))):n.style.removeProperty("--step")}const Pt=t.categories[0]?.parentElement;if(Pt&&"beside"!==g.categories&&!g.centre){Pt.style.height=`${Pt.offsetHeight}px`,Pt.removeAttribute("data-thinned");for(const e of t.categories)e.removeAttribute("data-left-out"),e.removeAttribute("data-edge");const n=t.categories.filter(t=>null!==t.offsetParent);if(!rt(Pt,n,t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit")&&n.length>1){const t=getComputedStyle(Pt),e=(Pt.clientWidth-Number.parseFloat(t.paddingLeft)-Number.parseFloat(t.paddingRight))/m.length;Pt.style.setProperty("--_name-fit","1"),Pt.setAttribute("data-thinned","");const o=P(n.map(t=>t.offsetWidth)),a=8,r=Math.max(Math.ceil((o+a)/e),Math.ceil((1.5*o+a)/e-.5),1);n.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")});const s=n.filter(t=>!t.hasAttribute("data-left-out")),c=s[0],l=s.at(-1),i=Pt.getBoundingClientRect(),u=[c,l].map(t=>t?.getBoundingClientRect());if(c&&u[0]&&u[0].left<i.left&&c.setAttribute("data-edge","start"),l&&l!==c&&u[1]&&u[1].right>i.right-Number.parseFloat(t.paddingRight)){l.setAttribute("data-edge","end");const t=s.at(-2);t&&t.getBoundingClientRect().right+a>l.getBoundingClientRect().left&&l.setAttribute("data-left-out","")}}const o=(g===Ut||g===Vt)&&Oe(t.figure,"data-chart-ticks",e.ticks);if(Pt.toggleAttribute("data-ticks",o),Pt.style.removeProperty("--_tick-reach"),o){const e=Q-Number(r.querySelector(".tablechart-rule")?.getAttribute("y1")??Q);e>0&&e<10*q&&Pt.style.setProperty("--_tick-reach",`${T(e/q)}px`);const n=Pt.getBoundingClientRect(),o=n.width/(Pt.offsetWidth||1),a=getComputedStyle(Pt),s=Number.parseFloat(a.paddingLeft),c=(Pt.clientWidth-s-Number.parseFloat(a.paddingRight))/m.length;t.categories.forEach((t,e)=>{if(t.hasAttribute("data-left-out"))t.style.removeProperty("--_tick");else{const a=(t.getBoundingClientRect().left-n.left)/o-Pt.clientLeft;t.style.setProperty("--_tick",`${T(s+(e+.5)*c-a)}px`)}})}Pt.style.height=""}const Dt=S.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*q,n=t.offsetHeight*q,o=Number.parseFloat(t.style.left)/100*A,a=Number.parseFloat(t.style.top)/100*Q,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*q;return[L("rect",{class:$,"data-for":"badge","data-note":t.dataset.note??"",x:o-e/2,y:a-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("; ")})]}),Wt=r.querySelector(`.${N}`),Gt=Array.from(r.querySelectorAll(`.${c}`)),Xt=[...Wt?[Wt]:[],...r.querySelectorAll(`:scope > .${l}`)],Jt=((t,e)=>{const n=t.getBoundingClientRect(),o=A/n.width,a=getComputedStyle(t),r=Number.parseFloat(a.lineHeight)/Number.parseFloat(a.fontSize)||1.2;return t=>{if("none"===t.dataset.place||t.hidden||t.hasAttribute("data-left-out"))return[];const a=t.getBoundingClientRect(),s=a.height*o/r,c=Array.from(t.style).filter(t=>t.startsWith("--")).map(e=>`${e}:${t.style.getPropertyValue(e)}`);return a.width?[L("rect",{class:$,"data-for":"text",x:(a.left-n.left)*o-3*e,y:(a.top-n.top)*o+(a.height*o-s)/2-e,width:a.width*o+6*e,height:s+2*e,style:c.join("; ")})]:[]}})(o,q),ee="grow"===t.figure.getAttribute("data-animate"),ne=M.flat().filter(t=>t.hasAttribute("data-cut")).flatMap(Jt),oe=[...dt.flatMap(t=>M[t].flatMap(Jt)),...ee?ne:[]];if(Xt.length||Gt.length){const e=[...M.flat(),...t.totals,..."beside"===g.categories?t.categories:[]].flatMap(Jt),n=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Gt)Se(t,[...e,...Dt].map(n));if(Xt.length&&t.plan)j(r,e,A,Q,Xt);else for(const t of Xt){const o=[...e,...Dt],a=He(t);t.setAttribute("d",a.map(([t,e,a,r])=>Ae(t,e,a,r,o.map(n))).join(""));for(const e of o){const o=Ce(a,n(e)),r="badge"===e.dataset.for?"badge":"";o&&t.after(L("path",{class:t.getAttribute("class")??"tablechart-grid","data-gap":r,d:o,style:e.getAttribute("style")??""}))}}}if(R(r,Dt,A,Q,Array.from(r.querySelectorAll(`.${s}, .${i}`))),!ee&&(jt.lineHoles.length||ne.length)){const t=Array.from(r.querySelectorAll(`.${d}`)).map(t=>{const e=L("g",{});return t.before(e),e.append(t),e});R(r,[...jt.lineHoles,...ne],A,Q,[...t,...r.querySelectorAll(`.${h}`)])}const ae=[c,l,s,i,...t.plan?[]:[N]];j(r,[...Dt,...oe],A,Q,void 0,ae.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||Ge(r);const re=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(g.columns?[t.categories]:[...M,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||g.centre&&m[Number(t.dataset.row)-1]?.isTotal)(e)&&!re(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>re(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),!0})(o,e))&&(m=t,y())};let H=!1;const O=new ResizeObserver(()=>{H||(H=!0,requestAnimationFrame(()=>{H=!1,S()}))}),_=new IntersectionObserver(t=>{for(const e of t)g=e.isIntersecting,y()},{threshold:e.threshold}),B=()=>{o.figure.classList.add(M),De(o,!0),Ke(o.svg),o.figure.offsetWidth},U=()=>o.figure.classList.remove(M),V=()=>{m=null,S()},F={relabel:()=>Ie(o,e),refresh:V};v(),S(),O.observe(o.figure),_.observe(o.figure),window.addEventListener("beforeprint",B),window.addEventListener("afterprint",U),(t=>{rn.add(t),sn||(sn=new MutationObserver(()=>{for(const t of rn)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of rn)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(F);const q={figure:o.figure,refresh:V,next:()=>ee(o,o.step+1),previous:()=>ee(o,o.step-1),stepTo:t=>ee(o,t),get step(){return o.step},get steps(){return o.plan?.count??0},destroy(){O.disconnect(),_.disconnect(),window.removeEventListener("beforeprint",B),window.removeEventListener("afterprint",U),(t=>{rn.delete(t),!rn.size&&sn&&(sn.disconnect(),sn=null)})(F),ye(o),o.figure.tablechart===q&&delete o.figure.tablechart}};return o.figure.tablechart=q,q})(o,e)):null},fn=e({GRID_CLASS:()=>N,LEGEND_CLASS:()=>b,LIBRARY_NAME:()=>n,NAME_CLASS:()=>f,POINT_CLASS:()=>m,QUADRANT_CLASS:()=>l,VIEWBOX_WIDTH:()=>A,avoidCollisions:()=>Q,boxOf:()=>ct,decimalsIn:()=>D,htmlEl:()=>E,largest:()=>P,markerEl:()=>Ht,overlaps:()=>Z,placeAt:()=>z,readSeries:()=>Wt,readTable:()=>Pt,short:()=>T,sizeOf:()=>et,splitSign:()=>W,svgEl:()=>L});window.Tablechart={init:async(t={},e=document)=>{const n={...S,...t};n.debug&&(jt.enabled=!0);const o=(await dn(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>hn(t,n)).filter(t=>null!==t);return jt.log(`Made ${o.length} chart(s).`),{charts:o,refresh:()=>{for(const t of o)t.refresh()},destroy:()=>{for(const t of o)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...S,...e};n.debug&&(jt.enabled=!0);const[o]=await dn([t],n);return o?hn(o,n):null},defaultConfig:S,addType:(t,e)=>{Me[t]=e,Object.assign(ve,e.annotations),xe.splice(0,1/0,...Object.keys(ve))},kit:fn}}();
1
+ !function(){var t=Object.defineProperty,e=(e,n)=>{let a={};for(var o in e)t(a,o,{get:e[o],enumerable:!0});return n||t(a,Symbol.toStringTag,{value:"Module"}),a},n="tablechart",a="tablechart-value",o="tablechart-bar",r="tablechart-rule",s="tablechart-line",c="tablechart-reference",l="tablechart-quadrant",i="tablechart-head",u="tablechart-slice",d="tablechart-series",h="tablechart-area",f="tablechart-name",b="tablechart-legend",m="tablechart-point",$="tablechart-hole",p="tablechart-centre",g="tablechart-break",w="tablechart-sr",y="is-shown",M="is-printing",v="is-at-once",x="tablechart-axis",k="tablechart-tick",N="tablechart-grid",S=1e3,A={selector:"[data-chart]",aspect:.38,barfill:.58,ringfill:.42,animate:!0,entrance:.5,labels:"outside",values:"auto",ticks:!0,shape:"straight",legend:!1,axis:!1,grid:!1,names:!0,tooltip:"auto",tooltipparent:null,table:"never",tablelimit:15,summary:"auto",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},C="cubic-bezier(0.3, 0.3, 0.6, 1)",H=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?C:"linear"}),T=(t,e)=>`${t}:${e}`,L=t=>Math.round(100*t)/100,O=(t,e={})=>{const n=document.createElementNS("http://www.w3.org/2000/svg",t);for(const a in e){const t=e[a];n.setAttribute(a,String("number"==typeof t?L(t):t))}return n},_=(t,e)=>[t,...e.classes].join(" "),B=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},E=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},z=0,U=0,F=t=>{let e=t.querySelector(":scope > defs");return e||(e=O("defs"),t.prepend(e)),e},V=t=>{if("circle"===t.tagName){const[e,n,a]=["cx","cy","r"].map(e=>Number(t.getAttribute(e))||0);return`M${L(e-a)},${L(n)}a${L(a)},${L(a)} 0 1 0 ${L(2*a)},0a${L(a)},${L(a)} 0 1 0 ${L(-2*a)},0z`}if("polygon"===t.tagName)return`M${(t.getAttribute("points")??"").trim().split(/\s+/).join("L")}z`;const[e,n,a,o,r,s]=["x","y","width","height","rx","ry"].map(e=>Number(t.getAttribute(e))||0),c=Math.min(r,a/2),l=Math.min(s,o/2),i=(t,e)=>c&&l?`a${L(c)},${L(l)} 0 0 1 ${L(t)},${L(e)}`:"";return`M${L(e+c)},${L(n)}h${L(a-2*c)}${i(c,l)}v${L(o-2*l)}${i(-c,l)}h${L(2*c-a)}${i(-c,-l)}v${L(2*l-o)}${i(c,-l)}z`},R=(t,e,n,a,o)=>{if(!e.length||!o.length)return;const r="tablechart-clip-"+ ++U,s=O("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M${-n},${-a}h${3*n}v${3*a}h${3*-n}z`;s.appendChild(O("path",{d:c+e.map(V).join(""),"clip-rule":"evenodd"})),F(t).appendChild(s);for(const l of o)l.setAttribute("clip-path",`url(#${r})`)},q=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++z,c=O("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(O("rect",{x:-n,y:-a,width:3*n,height:3*a,fill:"white"}));for(const u of e)u.setAttribute("fill","black"),c.appendChild(u);const l=F(t);if(l.appendChild(c),o){for(const t of o)t.setAttribute("mask",`url(#${s})`);return}let i=null;for(const u of Array.from(t.childNodes))u!==l&&(r&&u instanceof Element&&u.matches(r)?(i=null,t.appendChild(u)):(i??(i=t.appendChild(O("g",{mask:`url(#${s})`}))),i.appendChild(u)))},I=0,j={create:()=>null,draw(t,e,n){const{rows:a,y:r,svg:s,breakAt:c}=n;if(null===c)return;const l="zigzag"===t.getAttribute("data-mark"),i=(t,e)=>{const n=t.sideways?t.height:t.width,a=.09*n,o=n+2*a,r=.3*o,s=.06*o;if(t.sideways){const n=t.y-a;if(!l)return[[e-r/2,n],[e+r/2,n+o]];const c=o/3;return[[e-s,n],[e+s,n+c],[e-s,n+2*c],[e+s,n+o]]}const c=t.x-a;if(!l)return[[c,e+r/2],[c+o,e-r/2]];const i=o/3;return[[c,e+s],[c+i,e-s],[c+2*i,e+s],[c+o,e-s]]},u=(t,e=!1)=>t.map(([t,e],n)=>`${0===n?"M":"L"} ${t.toFixed(1)} ${e.toFixed(1)}`).join(" ")+(e?" Z":""),d="tablechart-break-"+ ++I,h=O("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(O("rect",{x:-1e3,y:-n.height,width:3e3,height:3*n.height,fill:"white"}));const f=[],b=r(c);for(const w of(t=>Array.from(t.querySelectorAll(`.${o}`)).map(t=>{const e="rect"===t.tagName?[t]:Array.from(t.querySelectorAll("rect")),n=(t,e)=>Number(t.getAttribute(e)),a=Math.min(...e.map(t=>n(t,"x"))),o=Math.min(...e.map(t=>n(t,"y"))),r=Math.max(...e.map(t=>n(t,"x")+n(t,"width"))),s=Math.max(...e.map(t=>n(t,"y")+n(t,"height"))),c=["--start","--span"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ");return{row:Number(t.dataset.row),x:a,y:o,width:r-a,height:s-o,sideways:"right"===t.dataset.grow,part:c}}))(s)){const t=w.sideways?n.breakX:b;if(void 0===t)continue;if(!(w.sideways?w.x<t&&w.x+w.width>t:w.y<b&&w.y+w.height>b))continue;const[e,o]=w.sideways?[i(w,t),i(w,t+n.breakGap)]:[i(w,b-n.breakGap),i(w,b)];h.appendChild(O("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[T("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(O("path",{class:g,"data-part":"edge","data-note":n.note,d:u(a),style:r}))}if(!f.length)return;const m=Array.from(s.querySelectorAll(`.${g}`)),$=O("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))m.includes(o)||$.appendChild(o);const p=O("defs");p.appendChild(h),s.prepend(p,$)}},P=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},D=t=>(t.split(/[.,]/)[1]||"").length,W=(t,e,n)=>{const a=((t,e)=>new Intl.NumberFormat(e||document.documentElement.lang||void 0,{minimumFractionDigits:t,maximumFractionDigits:t}))(e,n).formatToParts(t),o="minusSign"===a[0]?.type?a[0].value:"";return[o,a.slice(o?1:0).map(t=>t.value).join("")]},G=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),K=(t,e)=>{const n=document.createElement("span");if(n.className="tablechart-badge",n.inert=!0,t.childElementCount>0)for(const a of Array.from(t.children))n.appendChild(a.cloneNode(!0));else{n.textContent=(t.textContent||"").trim();const e=t.getAttribute("data-i18n");e&&n.setAttribute("data-i18n",e)}return e.appendChild(n),n},Y=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=G(s),l=r?.5:.5*10**-D(s.match(/-?[\d.,]+/)?.[0]??""),i=!!Number.isNaN(c)||Math.abs(e-c)<=l+1e-9,u={label:a,computed:e,stated:c,agrees:i};o.checks.push(u),i||console.warn(`[${n}] An annotation reads ${c}${r}, but ${a} is ${Number(e.toFixed(2))}${r}. The chart shows your number.`)},X={create:K,draw(t,e,a){const{rows:o,cx:r,y:c,unit:l,labelHeight:u,badgeHeight:d,height:h,svg:f,after:b}=a,[m,$]=((t,e)=>{const n=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n};return[n("data-from",0),n("data-to",e-1)]})(t,o.length),p=o[m],g=o[$];if(!p||!g)return void console.warn(`[${n}] A bracket points at a row that is not there (row ${m+1} to ${$+1}, of ${o.length}).`);const w=7*l,y=4*l,M=r(m),v=r($),x=Math.min(c(p.value),c(g.value))-u-y-.9*d,k=t=>c(t)-u-y,N=`M ${M} ${k(p.value)} L ${M} ${x} L ${v} ${x} L ${v} ${k(g.value)-w}`,A=(k(p.value)-x+Math.abs(v-M)+(k(g.value)-w-x))/l+1;f.appendChild(O("path",{class:s,"data-note":a.note,d:N,style:`--len:${A.toFixed(1)}; ${T("--after",b)}`}));const C=k(g.value);var H;f.appendChild(O("polygon",{class:i,"data-note":a.note,points:`${v},${C} ${v-.45*w},${C-w} ${v+.45*w},${C-w}`,style:T("--after",b)})),e&&(E(e,(M+v)/2,x,S,h),e.style.setProperty("--after",String(b))),Y(e,(H=p.value,(g.value-H)/Math.abs(H)*100),`${p.value} to ${g.value}`,a)}},Z=(t,e)=>t[0]<e[0]+e[2]&&e[0]<t[0]+t[2]&&t[1]<e[1]+e[3]&&e[1]<t[1]+t[3],Q=(t,e,n)=>{if(t.length>400)return t.map(()=>null);let a=1;for(const l of t)for(const[,,t,e]of l)a=Math.max(a,t,e);const o=new Map,r=([t,e,n,o])=>{const r=[];for(let s=Math.floor(t/a);s<=Math.floor((t+n)/a);s++)for(let t=Math.floor(e/a);t<=Math.floor((e+o)/a);t++)r.push(`${s} ${t}`);return r},s=t=>{for(const e of r(t))o.get(e)?.push(t)??o.set(e,[t])},c=t=>((t,e)=>t[0]>=e[0]&&t[1]>=e[1]&&t[0]+t[2]<=e[0]+e[2]&&t[1]+t[3]<=e[1]+e[3])(t,n)&&r(t).every(e=>!o.get(e)?.some(e=>Z(t,e)));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},J=new WeakMap,tt=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>J.set(t,n[e]))},et=t=>J.get(t)??{width:t.offsetWidth,height:t.offsetHeight},nt=(t,e,n)=>t.some(t=>et(t).width*n>e-6*n),at=(t,e,n)=>e>=et(t).height*n*1.6,ot=(t,e,n)=>e>=et(t).width*n*1.5,rt=(t,e,n,a,o=.7)=>{t.style.setProperty(a,"1");let r=1;for(const c of e){const{size:t,room:e}=n(c);t>e&&(r=Math.min(r,e/t))}const s=r>=o?r:0;return t.style.setProperty(a,String(s||o)),s},st={outside:[.5,1],below:[.5,0],after:[0,.5],before:[1,.5]},ct=(t,e,n,a,o=[.5,.5])=>{const[r,s]=st[t.dataset.place??""]??o,{width:c,height:l}=et(t);return[Number.parseFloat(t.style.left)/100*n-c*e*r,Number.parseFloat(t.style.top)/100*a-l*e*s,c*e,l*e]},lt=(t,e,n)=>{for(const a of t){if("none"===a.dataset.place||!a.style.left)continue;const[t]=st[a.dataset.place??""]??[.5,.5],o=et(a).width*e,r=Number.parseFloat(a.style.left)/100*n,s=Math.min(Math.max(r,o*t),n-o*(1-t));s!==r&&(a.style.left=s/n*100+"%")}},it=(t,e,n,a)=>{const o=t.filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out")),r=ut(o,e,n,a);o.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")})},ut=(t,e,n,a)=>{if(t.length<2)return 1;const o=t.map(t=>ct(t,e,n,a)),r=2*e;let s=1;for(;s<t.length&&o.some((t,e)=>{return e>=s&&e%s===0&&(a=t,!((n=o[e-s])[0]+n[2]+r<=a[0]||a[0]+a[2]+r<=n[0]||n[1]+n[3]<=a[1]||a[1]+a[3]<=n[1]));var n,a});)s++;return s},dt={create(t,e){if(!t.textContent?.trim())return null;const n=K(t,e);return n.dataset.kind="note",n},draw(t,e,a){const{rows:o,cx:r,y:s,height:l,unit:i,svg:u,after:d,seriesValues:h}=a;if(a.x||a.centre||"beside"===a.categories[0]?.parentElement?.dataset.place)return void console.warn(`[${n}] A note works on a chart with its rows across, such as a line or column chart.`);const f=(t.getAttribute("data-row")??"").trim(),b=/^\d+$/.test(f)?Number(f)-1:o.findIndex(t=>t.label===f);if(b<0||b>=o.length)return void console.warn(`[${n}] A note is for row "${f}", which is not there.`);const $=r(b),p=s(0);if(u.insertBefore(O("line",{class:c,"data-kind":"note","data-note":a.note,x1:$,x2:$,y1:0,y2:p,style:T("--after",d)}),u.querySelector(`:scope > .${m}`)),!e)return;const g=et(e).width*i,w=et(e).height*i,y=4*i,M=h.flat().flatMap(t=>!t.style.left||"none"===t.dataset.place||t.hasAttribute("data-left-out")?[]:[{label:t,box:ct(t,i,S,l)}]),v=[0,w+y/2].flatMap(t=>[[$-g/2,t,g,w],[$+y,t,g,w],[$-y-g,t,g,w]]),[x]=Q([v],[...a.taken,...M.map(t=>t.box)],[0,0,S,l]),k=v[x??0];if(a.taken.push(k),E(e,k[0]+g/2,k[1]+w/2,S,l),e.style.setProperty("--after",String(d)),null===x)for(const n of M)Z(n.box,k)&&n.label.setAttribute("data-left-out","")}},ht=(t,e,n)=>{const a=n.reduce((t,e)=>t+e,0);if("mean"===t)return a?e.reduce((t,e,a)=>t+e*n[a],0)/a:null;if("median"===t){const t=e.map((t,e)=>[t,n[e]]).sort((t,e)=>t[0]-e[0]);let o=0;for(const[e,[n,r]]of t.entries()){if(o+=r,Math.abs(o-a/2)<1e-9&&t[e+1])return(n+t[e+1][0])/2;if(o>a/2)return n}return null}const o=Number.parseFloat(t);return Number.isFinite(o)?o:null},ft={create(t,e){if(!t.textContent?.trim())return null;const n=K(t,e);return n.dataset.kind="reference",n},draw(t,e,a){const{rows:o,cx:r,y:s,x:l,height:i,unit:u,svg:d,after:h}=a,f=o.filter(t=>!t.isTotal&&!t.missing),b=t.hasAttribute("data-name"),$=(t.getAttribute(b?"data-name":"data-value")??"").trim();let p,g,w;if(b){const t=f.map(t=>G(t.label));if("beside"===a.categories[0]?.parentElement?.dataset.place||t.some(Number.isNaN))return void console.warn(`[${n}] A reference line among the names needs names that are numbers, under columns or points.`);const e=ht($,t,f.map(t=>t.value)),s=null===e?-1:t.findIndex((n,a)=>n<=e&&e<=(t[a+1]??n)),[c,l]=[f[s],f[s+1]??f[s]].map(t=>r(o.indexOf(t))),i=null===e||s<0||void 0===t[s+1]||t[s+1]===t[s]?0:(e-t[s])/(t[s+1]-t[s]);w=e,g=s<0?null:c+i*(l-c),p=!1}else{const e=Boolean(a.frame)&&"y"===t.getAttribute("data-axis"),n=a.frame?a.series.flatMap((t,e)=>t.group?[]:[e])[e?1:0]??0:0;w=ht($,f.map(t=>t.cells[n]?.value??t.value),f.map(()=>1)),p=e||!l,g=null===w?null:l&&!e?l(w):s(w)}if(null===g||null===w)return void console.warn(`[${n}] A reference line needs a number, "mean" or "median", not "${$}".`);const[y,M,v,x]=a.frame?[a.frame[0],a.frame[1],a.frame[0]+a.frame[2],a.frame[1]+a.frame[3]]:[0,0,o.length>0?r(o.length-1)+r(0):S,l?i:s(0)];if(d.insertBefore(O("line",{class:c,"data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...p?{x1:y,x2:v,y1:g,y2:g}:{x1:g,x2:g,y1:M,y2:x},style:T("--after",h)}),d.querySelector(`:scope > .${m}`)),e){const t=et(e).width*u,n=et(e).height*u,o=4*u,r=p?[[v-t,g-n/2,t,n],[v-t,g-n-o,t,n],[v-t,g+o,t,n]]:[M,M+n,M+2*n].flatMap(e=>[[g-t/2,e,t,n],[g+o,e,t,n],[g-o-t,e,t,n]]),[s]=Q([r],a.taken,[0,0,S,i]),c=r[s??0];a.taken.push(c),E(e,c[0]+t/2,c[1]+n/2,S,i),e.style.setProperty("--after",String(h)),"mean"!==$&&"median"!==$||Y(e,w,`the ${$}`,a,"")}}},bt={create:K,draw(t,e,n){const{rows:a,cx:o,y:r,unit:c,labelHeight:l,height:u,svg:d,values:h,after:f}=n,b=a[0],m=a[a.length-1];if(!b||!m)return;const $=l+18*c,p=10*c,g=10*c;let w=o(0),y=r(b.value)-$,M=o(a.length-1),v=r(m.value)-$,x=0;a.forEach((t,e)=>{const n=M===w?0:(o(e)-w)/(M-w),a=y+n*(v-y)-(r(t.value)-$);a>x&&(x=a)}),y-=x,v-=x;const k=M-w,N=v-y,A=Math.hypot(k,N)||1,C=k/A,H=N/A;w-=C*p,y-=H*p,M+=C*p,v+=H*p;const L=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(M-w)*L,n=y+(v-y)*L,s=et(e).width*c/2,i=n+et(e).height*c/2+8*c;let u=0;a.forEach((e,n)=>{const a=(h[n]?et(h[n]).width:0)*c/2;if(Math.abs(o(n)-t)>=s+a)return;const d=r(e.value)-7*c-l;u=Math.max(u,i-d)}),y-=u,v-=u}const _=M-C*g,B=v-H*g,z=Math.hypot(_-w,B-y)/c+1;d.appendChild(O("line",{class:s,"data-note":n.note,x1:w,y1:y,x2:_,y2:B,style:`--len:${z.toFixed(1)}; ${T("--after",f)}`}));const U=-H,F=C,V=.42*g;d.appendChild(O("polygon",{class:i,"data-note":n.note,points:[`${M},${v}`,`${_+U*V},${B+F*V}`,`${_-U*V},${B-F*V}`].join(" "),style:T("--after",f)})),e&&(E(e,w+(M-w)*L,y+(v-y)*L,S,u),e.style.setProperty("--after",String(f)));const R=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(R)&&R>0&&Y(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,R),`${b.value} to ${m.value} over ${R} years`,n)}},mt=(t,e,n)=>{const a=.15,o=Math.min(.7*t/(e+(e-1)*a),n),r=e*o+(e-1)*o*a;return{size:o,gap:o*a,offset:t=>-r/2+t*o*1.15}},$t=(t,e,n)=>{const a=t.series[n],o=t.series.some(t=>t.focus)&&!a.focus;return{"data-series":n+1,...o&&{"data-muted":""},style:`--n:${n}; --m:${o?1:0}; --palette:var(--tablechart-color-${n+1}); ${T("--i",e.slot)}`}},pt=(t,e,n=!1)=>{let a=0,o=0;return Array.from({length:e},(e,r)=>{const s=t.cells[r]??t.cells[0],c=s.missing?0:s.value;if(n){const t=a;return a+=c,{from:t,to:a,cell:s}}if(c<0){const t=o;return o+=c,{from:t,to:o,cell:s}}const l=a;return a+=c,{from:l,to:a,cell:s}})},gt=(t,e,n=!1)=>{const a=pt(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},wt=(t,e)=>{const{top:n,bottom:a}=gt(t,e);return n+a},yt=(t,e,n)=>{const a=e.series.some(t=>t.focus);t.style.setProperty("--n",String(n)),t.style.setProperty("--m",a&&!e.series[n].focus?"1":"0"),t.style.setProperty("--palette",`var(--tablechart-color-${n+1})`)},Mt=(t,e)=>t.some((n,a)=>a!==e&&!n.cell.missing&&n.to!==n.from&&n.from===t[e].to),vt=(t,e,n,a={},r="")=>{const s={class:_(o,e),"data-kind":"bar","data-row":n+1,...a},c=T("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=O("g",{...s,"data-stack":"",style:c});return t.svg.appendChild(l),(o,r)=>{const s=void 0!==a["data-grow"]?{"data-grow":a["data-grow"]}:{};l.appendChild(O("rect",{...s,...r,class:_("tablechart-piece",e),"data-row":n+1,...$t(t,e,o)}))}},xt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,groups:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,aspect:.5,minHeight:({labelHeight:t,nameHeight:e,rows:n,series:a,stacked:o,labels:r})=>{const s=1.1*t,c=a>1&&!o?s*(a+.15*(a-1))/.7:o||"inside"===r?s/.58:s;return n*Math.max(c,1.2*e)},categories:"beside",headroom:()=>0,draw(t){const{segments:e,height:n,unit:a,svg:s,values:c,categories:l,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(P(l.map(t=>et(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/S*100).toFixed(2)}%`);const b=S-4*a,m=t.stacked?Math.max(P(t.rows.map(e=>gt(e,t.series.length).top)),0)||1:Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(P(t.rows.map(e=>-gt(e,t.series.length).bottom)),0):Math.max(P(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>-t.value))),0),p=Math.max(m,t.domain?.[1]??0),g=Math.max($,-(t.domain?.[0]??0)),w=Math.max(p,t.squeeze?.hi??0)+g,y=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),w,n,t.squeeze,t.breakGap),M=n/e.length,v=t=>(t+.5)*M,x=Math.min(M*i.barfill,u),k=mt(M,t.series.length,u),N=c[0]??t.totals[0],A=N?et(N).height*a*.56:0,C=Math.max(((d&&!t.stacked?k.size:x)-A)/2,5*a),H=t=>et(t).width*a,L=t=>t.length?P(t.map(H))+C+4*a:0,B=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,z=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:B(e,n)}))),U=e=>{const n=gt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let F=t.stacked?L(t.totals.filter((t,e)=>!U(e))):d?L(z.filter(t=>t.value>=0).map(t=>t.label)):0,V=t.stacked?L(t.totals.filter((t,e)=>U(e))):d?L(z.filter(t=>t.value<0).map(t=>t.label)):0;const R=(e,n)=>"inside"===t.labels&&ot(e,n,a);if(!d&&!t.stacked)for(let o=0;o<3;o++){const t=b-f-F-V,n=e.map((t,e)=>({seg:t,label:c[e]})).filter(({seg:e,label:n})=>!R(n,y(e.value,t))),a=L(n.filter(({seg:t})=>t.value>=0).map(({label:t})=>t)),o=L(n.filter(({seg:t})=>t.value<0).map(({label:t})=>t));if(a<=F&&o<=V)break;F=Math.max(F,a),V=Math.max(V,o)}const q=b-f-F-V,I=f+V+y(g,q),j=t=>t<0?I-y(t,q):I+y(t,q);if(t.squeeze&&(t.breakX=j(t.squeeze.gap)),t.x=j,t.stacked){const e=t.length("--tablechart-stack-gap","1px")??a;return t.rows.forEach((o,r)=>{const s=gt(o,t.series.length),c=vt(t,o,r,{"data-grow":"right"},s.bottom<0?I-j(s.bottom)+"px center":""),i=v(r)-x/2,u=pt(o,t.series.length);u.forEach(({from:o,to:s,cell:l},d)=>{const h=t.seriesValues[d][r];if(h.dataset.place="none",l.missing||s===o)return;const f=Math.min(j(o),j(s)),b=Math.max(j(o),j(s)),m=Mt(u,d)?Math.min(e,(b-f)/2):0,[$,p]=j(s)>j(o)?[f,b-m]:[f+m,b];c(d,{x:$,y:i,width:Math.max(p-$,1),height:x,...s<o&&{"data-grow":"left"}}),h.dataset.place="inside",h.toggleAttribute("data-left-out",!ot(h,b-f,a)||et(h).height*a>x),yt(h,t,d),E(h,(f+b)/2,v(r),S,n)});const d=t.totals[r];d&&(d.dataset.place=U(r)?"before":"after",E(d,U(r)?j(s.bottom)-C:j(s.top)+C,v(r),S,n));const h=l[r];h&&E(h,f-8*a,v(r),S,n)}),void s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}if(d){const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),c=rt(t.plot,e,t=>({size:et(t).height*a,room:k.size+.5*k.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((a,l)=>{const i=e.cells[l]??e.cells[0],u=t.seriesValues[l][r];if(i.missing)return void(u.dataset.place="none");const d=j(i.value),h=i.value<0,f=v(r)+k.offset(l),b=Math.max(Math.abs(d-I),1);0!==i.value&&s.appendChild(O("rect",{class:_(o,e),"data-kind":"bar","data-row":r+1,"data-grow":h?"left":"right",x:h?I-b:I,y:f,width:b,height:k.size,...$t(t,e,l)})),u.dataset.place=h?"before":"after",u.toggleAttribute("data-left-out",!c),E(u,h?d-C:d+C,f+k.size/2,S,n)});const i=l[r];i&&E(i,f-8*a,v(r),S,n)}),void s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}const D=e.map((t,e)=>R(c[e],Math.abs(j(t.value)-I)));e.forEach((e,r)=>{const i=j(e.value),u=v(r),d=e.value<0,h=Math.abs(i-I),b=Math.max(h,1);0!==e.value&&s.appendChild(O("rect",{class:_(o,e),"data-kind":e.kind,"data-row":r+1,"data-grow":d?"left":"right",x:d?I-b:I,y:u-x/2,width:b,height:x,style:T("--i",e.slot)}));const m=c[r],$=Math.max(Math.min(C,h-H(m)-6*a),6*a),p=d?1:-1;m.dataset.place=D[r]?"inside":d?"before":"after",m.dataset.kind=e.kind,E(m,D[r]?"center"===t.insideAlign?(I+i)/2:"start"===t.insideAlign?I-p*($+H(m)/2):i+p*($+H(m)/2):i-p*C,u,S,n);const g=l[r];g&&E(g,f-8*a,u,S,n)}),s.appendChild(O("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}},kt={segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),series:!0,lines:!0,groups:!0,legend:"box",stackable:!0,totals:!0,breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+4*a+(n?1.6*e:0),draw(t){const{segments:e,cx:n,y:a,barWidth:s,height:c,unit:l,svg:i,values:u,labels:d,insideAlign:h}=t,f=a(0);if(t.stacked){const e=t.length("--tablechart-stack-gap","1px")??l;return t.rows.forEach((o,r)=>{const i=gt(o,t.series.length),u=vt(t,o,r,{},i.bottom<0?`center ${f-a(i.top)}px`:""),d=n(r)-s/2,h=pt(o,t.series.length);h.forEach(({from:o,to:i,cell:f},b)=>{const m=t.seriesValues[b][r];if(m.dataset.place="none",f.missing||i===o)return;const $=Math.min(a(i),a(o)),p=Math.max(a(i),a(o)),g=Mt(h,b)?Math.min(e,(p-$)/2):0,[w,y]=a(i)<a(o)?[$+g,p]:[$,p-g];u(b,{x:d,y:w,width:s,height:Math.max(y-w,1),...i<o&&{"data-grow":"down"}}),m.dataset.place="inside",m.toggleAttribute("data-left-out",!at(m,p-$,l)||et(m).width*l>s-4*l),yt(m,t,b),E(m,n(r),($+p)/2,S,c)});const b=t.totals[r];if(b){const t=0===i.top&&i.bottom<0;b.dataset.place=t?"below":"outside",E(b,n(r),t?a(i.bottom)+4*l:a(i.top)-4*l,S,c)}}),void i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}if(t.own.length>1){const e=n(1)-n(0)||2*n(0),s=mt(e,t.own.length,t.barMax),u=t.own.flatMap(e=>t.seriesValues[e]).filter(t=>void 0===t.dataset.missing),d=rt(t.plot,u,t=>({size:et(t).width*l,room:s.size+.5*s.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.own.forEach((u,h)=>{const b=e.cells[u]??e.cells[0],m=t.seriesValues[u][r],$=n(r)+s.offset(h);if(b.missing)return void(m.dataset.place="none");const p=a(b.value),g=b.value<0,w=Math.max(Math.abs(f-p),1);0!==b.value&&i.appendChild(O("rect",{class:_(o,e),"data-kind":"bar","data-row":r+1,...g&&{"data-grow":"down"},x:$,y:g?f:f-w,width:s.size,height:w,...$t(t,e,u)})),m.dataset.place=g?"below":"outside",m.toggleAttribute("data-left-out",!d),E(m,$+s.size/2,g?p+4*l:p-4*l,S,c)})}),void i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}const b=t.own[0],m=t.own.length<t.series.length,$=nt(u,s,l),p=e.map((t,e)=>"inside"===d&&!$&&!t.missing&&at(u[e],Math.abs(f-a(t.value)),l)),g=u[0]?et(u[0]).height*l*.56:0;let w=Number.POSITIVE_INFINITY;for(const[o,r]of u.entries())p[o]&&(w=Math.min(w,(s-et(r).width*l)/2));e.forEach((e,r)=>{const d=a(e.value),$=e.value<0;if(e.missing)return E(u[r],n(r),f-4*l,S,c),void(u[r].dataset.place="outside");const y=Math.max(Math.abs(f-d),1);0!==e.value&&i.appendChild(O("rect",{class:_(o,e),"data-kind":e.kind,"data-row":r+1,...$&&{"data-grow":"down"},x:n(r)-s/2,y:$?f:f-y,width:s,height:y,style:T("--i",e.slot),...m&&$t(t,e,b)}));const M=$?-1:1,v=Math.min(w,(Math.abs(f-d)-g)/2),x="center"===h?(d+f)/2:"start"===h?f-M*(v+g/2):d+M*(v+g/2),k=$?d+4*l:d-4*l;E(u[r],n(r),p[r]?x:k,S,c),u[r].dataset.place=p[r]?"inside":$?"below":"outside",m&&p[r]&&yt(u[r],t,b)}),i.appendChild(O("line",{class:r,x1:0,x2:S,y1:f,y2:f}))}},Nt=0,St={aspect:.66,centre:!0,headroom:()=>0,segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),draw({rows:t,height:e,unit:n,labelHeight:a,svg:o,values:r,config:s,centre:c}){const l=500,i=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,f=Math.max(Math.min(S,e)/2-h,10),b=f*s.ringfill,m=f-b/2,$=2*Math.PI*m,p=[];let g=0,w=0,y=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,M=H(y,h),v=`--share:${h.toFixed(4)}; --start:${M.start.toFixed(4)}; --span:${M.span.toFixed(4)};`,x=h*$,k=g/$*2*Math.PI-Math.PI/2;p.push(k),o.appendChild(O("circle",{class:_(u,t),"data-slice":w+1,"data-row":s+1,cx:l,cy:i,r:m,"stroke-width":b,transform:`rotate(-90 500 ${i})`,"stroke-dasharray":`${x.toFixed(1)} ${($-x).toFixed(1)}`,"stroke-dashoffset":(-g).toFixed(1),style:`--n:${w}; --palette:var(--tablechart-color-${w+1}); --arc:${x.toFixed(1)}; --circ:${$.toFixed(1)}; ${v} --ease:${M.easing}; ${T("--i",t.slot)}`}));const N=k+x/$*Math.PI,A=Math.cos(N),C=Math.sin(N);o.appendChild(O("line",{class:"tablechart-leader",x1:l+A*(f+2*n),y1:i+C*(f+2*n),x2:l+A*(f+7*n),y2:i+C*(f+7*n),"data-row":s+1,style:`${v} ${T("--i",t.slot)}`})),c.style.setProperty("--start",M.start.toFixed(4)),c.style.setProperty("--span",M.span.toFixed(4));const L=f+9*n,B=et(c).width*n/2;E(c,l+A*(L+Math.abs(A)*B),i+C*(L+Math.abs(C)*a*.7),S,e),c.dataset.place="around",g+=x,y+=h,w+=1}),p.length>1){const t=m-b/2-1,n=m+b/2+1,a="tablechart-slices-"+ ++Nt,r=O("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(O("rect",{x:0,y:0,width:S,height:e,fill:"white"}));for(const e of p)r.appendChild(O("line",{class:"tablechart-divide",x1:l+Math.cos(e)*t,y1:i+Math.sin(e)*t,x2:l+Math.cos(e)*n,y2:i+Math.sin(e)*n}));const s=O("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${u}`)))s.appendChild(e);const c=O("defs");c.appendChild(r),o.prepend(c,s)}c&&E(c,l,i,S,e)}},At=["circle","square","diamond"],Ct=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[],a=At.find(t=>n.includes(t));return{shape:a??At[Math.floor(e/2)%At.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},Ht=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return O("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return O("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return O("polygon",{points:`${e},${n-.75*t} ${e+.87*t},${n+.75*t} ${e-.87*t},${n+.75*t}`,...o})}return O("circle",{cx:e,cy:n,r:a,...o})},Tt=t=>Number(t.toFixed(2));function Lt(t,e,n){const a=new Array(t).fill(0);let o=[];const r=()=>{(function(t,e){const n=t.length;if(n<2)return t.map(()=>0);const a=n=>(e[n+1]-e[n])/(t[n+1]-t[n]||1),o=new Array(n).fill(0);for(let s=1;s<n-1;s++){const e=a(s-1),n=a(s);if(e*n<=0)continue;const r=t[s]-t[s-1],c=t[s+1]-t[s],l=(e*c+n*r)/(r+c||1),i=Math.min(2*Math.abs(e),2*Math.abs(n),Math.abs(l));o[s]=Math.sign(e)*i||0}if(2===n)return o[0]=a(0),o[1]=a(0),o;const r=(n,a,o)=>{const r=t[a]-t[n];return r?((e[a]-e[n])/r*3-o)/2:o};return o[0]=r(0,1,o[1]),o[n-1]=r(n-2,n-1,o[n-2]),o})(o.map(t=>n(t)[0]),o.map(t=>n(t)[1])).forEach((t,e)=>{a[o[e]]=t}),o=[]};for(let s=0;s<t;s++)e(s)?r():o.push(s);return r(),a}var Ot,_t,Bt=t=>{const e=t.length,n=t.reduce((t,e)=>t+e.x,0)/e,a=t.reduce((t,e)=>t+e.y,0)/e,o=t.reduce((t,e)=>t+(e.x-n)**2,0),r=o?t.reduce((t,e)=>t+(e.x-n)*(e.y-a),0)/o:0,s=t=>a+r*(t-n),c=e>2?Math.sqrt(t.reduce((t,e)=>t+(e.y-s(e.x))**2,0)/(e-2)):0,l=o?c/Math.sqrt(o):0;return{at:s,spread:c,t:l?r/l:r?Number.POSITIVE_INFINITY:0,n:e}},Et=[12.71,4.3,3.18,2.78,2.57,2.45,2.36,2.31,2.26,2.23,2.2,2.18,2.16,2.14,2.13],zt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),Ut=t=>({segments:zt,series:!0,stackable:!0,running:!0,swatch:t?"box":void 0,headroom:({labelHeight:t,unit:e})=>1.6*t+6*e,footroom:({labelHeight:e,unit:n,series:a,focused:o,stacked:r})=>t||r||2!==a||o?0:e+7*n,draw(e){const{rows:n,series:a,own:o,seriesValues:s,names:c,cx:l,y:i,height:u,unit:f,labelHeight:b,svg:p,stacked:g}=e,w=o.length<a.length,y="step"===e.shape,M="smooth"===e.shape,v=a.length>1,x=a.some(t=>t.focus),k=n.length-1,N=i(0),A=n.length>1?l(1)-l(0):2*l(0);p.style.setProperty("--_base",`${Tt(N)}px`);const C=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],H=(t,e)=>!C(t,e)||!!C(t,e)?.missing,T=n.map(t=>g?pt(t,a.length,!0):null),L=(t,e)=>T[e]?.[t].to??C(t,e)?.value??0,_=(t,e)=>T[e]?.[t].from??0,B=(t,e)=>[l(e),i(L(t,e))],z=a.map((t,e)=>{if(!v)return{attrs:{},ink:""};const n=x&&!t.focus;return{attrs:{"data-series":e+1,...n&&{"data-muted":""}},ink:`--n:${e}; --m:${n?1:0}; --palette:var(--tablechart-color-${e+1}); `}}),U=w?k:Math.min(k,6);e.plot.style.setProperty("--count",String(U+1));const F=k>0?U/(y?n.length:k):1,V=t=>t*F,R=t=>`--i:${Tt(V(t))}`,I=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{H(t,o)||(a<0&&(a=o),(o===k||H(t,o+1))&&((y||o>a)&&e.push([a,o]),a=-1))}),e},j=(t,e)=>`--i:${Tt(V(t)+1)}; --d:${Tt(V(y?e+1:e)-V(t))}`,P=(t,e)=>({"data-from":t+1,"data-to":e+1,...y&&{"data-flat":""}}),D=M?a.map((t,e)=>Lt(n.length,t=>H(e,t),t=>B(e,t))):[],W=M&&t?a.map((t,e)=>Lt(n.length,t=>H(e,t),t=>[l(t),i(_(e,t))])):[],G=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{y?(a.push(`H${Tt(o+n*A/2)}`),s<t.length-1&&a.push(`V${Tt(t[s+1][1])}`)):s>0&&a.push(e?function(t,e,n,a){const[o,r]=function(t,e,n,a){const o=(e[0]-t[0])/3;return[[t[0]+o,t[1]+n*o],[e[0]-o,e[1]-a*o]]}(t,e,n,a),s=([t,e])=>`${Tt(t)},${Tt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${Tt(o)},${Tt(r)}`)}),a},K=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[l(e+a),i(o(t,e+a))]),Y=(t,e,n,a)=>M?t[e].slice(n,a+1):null,X=t=>l(t)-(y?A/2:0),J=t=>l(t)+(y?A/2:0);t&&o.forEach(t=>(t=>{const e=O("g",{class:h,...z[t].attrs,...g&&{"data-stacked":""},style:z[t].ink}),n=I(t),a=O("g",{class:"tablechart-area-fill",style:`--rows:${Tt(U+1)}; ${n.length?j(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=K(t,o,r,L),n=K(t,o,r,_),s=Y(W,t,o,r)?.reverse()??null,c=[`M${Tt(X(o))},${Tt(n[0][1])}`,`L${Tt(X(o))},${Tt(e[0][1])}`,...G(e,Y(D,t,o,r),1),`L${Tt(J(r))},${Tt(n[n.length-1][1])}`,...G(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(O("path",{d:c,...P(o,r),style:j(o,r)}))}p.appendChild(e)})(t)),o.forEach(t=>(t=>{const e=a[t];for(const[n,a]of I(t)){const o=K(t,n,a,L),r=[`M${Tt(X(n))},${Tt(o[0][1])}`,...G(o,Y(D,t,n,a),1)].join(" ");p.appendChild(O("path",{class:d,...z[t].attrs,d:r,...e.line&&{"data-line":e.line},...P(n,a),style:`${z[t].ink}${j(n,a)}`}))}})(t));const tt=w?a.flatMap((t,e)=>o.includes(e)?[]:s[e].flatMap(t=>{const e=t.dataset.place;if(!e||"none"===e||t.hasAttribute("data-left-out"))return[];const[n,a,o,r]=ct(t,f,S,u);return[{label:t,box:[n-2*f,a-3*f,o+4*f,r+6*f]}]})):[],nt=y?[]:o.flatMap(t=>n.flatMap((e,n)=>{if(H(t,n))return[];const[a,o]=B(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),at=tt.filter(({label:t,box:e})=>{const n=nt.some(t=>Z(t,e));return n&&t.setAttribute("data-left-out",""),!n}),ot=(t,e)=>{let n=e;for(;n<k&&!H(t,n+1)&&C(t,n+1)?.value===C(t,e)?.value;)n++;return n},rt=t=>"above"===t?"below":"above",st=(t,e,n)=>{const[a,o]=B(t,e),r=et(s[t][e]).width*f,c=[a-r/2,"above"===n?o-7*f-b:o+7*f,r,b];return c[1]+b>u?Number.POSITIVE_INFINITY:[e-1,e+1].filter(e=>e>=0&&e<=k&&!H(t,e)).flatMap(n=>lt(t,e,n,0)).filter(t=>Z(t,c)).length},lt=(t,e,n,a)=>{const[o,r]=B(t,e),[s,c]=B(t,n),l=Math.max(1,Math.ceil(Math.hypot(s-o,c-r)/(3*f)));return Array.from({length:l+1},(t,e)=>{const n=e/l;return[o+(s-o)*n-a,r+(c-r)*n-a,2*a,2*a]})},it=(e,n)=>{const o=C(e,n);if(!o||o.missing)return"none";if(y&&n>0&&!H(e,n-1)&&C(e,n-1)?.value===o.value)return"none";if(x&&!a[e].focus)return"none";if(g)return"middle";const r=o.value<0?"below":"above";if(!v||x||a.length>2)return t||y||st(e,n,r)<=st(e,n,rt(r))?r:rt(r);const s=C(1-e,n);return!s||s.missing?r:o.value>s.value||o.value===s.value&&0===e||t&&o.value>=0&&B(e,n)[1]+7*f+b>N?"above":"below"},dt=(w||v&&!x&&a.length>2&&!g)&&!y,ht=new Map;if(dt){const t=n.flatMap((t,e)=>o.map(t=>({s:t,i:e,value:C(t,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==it(t,e)).sort((t,e)=>t.i-e.i||e.value-t.value||t.s-e.s),e=t=>t<0?["below","above"]:["above","below"],a=t.map(({s:t,i:n,value:a})=>{const o=et(s[t][n]).width*f,[r,c]=B(t,n);return e(a).map(t=>[r-o/2,"above"===t?c-7*f-b:c+7*f,o,b])}),r=o.flatMap(t=>n.flatMap((e,n)=>{if(H(t,n))return[];const[a,o]=B(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),c=Q(a,[...r,...at.map(({box:t})=>t)],[0,0,l(k)+l(0),u]);t.forEach(({s:t,i:n,value:a},o)=>ht.set(s[t][n],null===c[o]?null:e(a)[c[o]]))}o.forEach(t=>{s[t].forEach((e,n)=>{e.style.setProperty("--i",String(Tt(y?(V(n)+V(n+1))/2:V(n))));const a=ht.get(e)??it(t,n);if(e.dataset.place="above"===a?"outside":a,e.toggleAttribute("data-left-out","none"!==a&&((t,e)=>dt?null===ht.get(s[t][e]):!(!g&&!y)&&(et(s[t][e]).width*f>(y?ot(t,e)-e+1:1)*A-4*f||!!(g&&t>0&&L(t,e)<_(t,e))||g&&Math.abs(i(_(t,e))-i(L(t,e)))<1.2*b))(t,n)),y&&"none"!==a?e.dataset.rowEnd=String(ot(t,n)+1):delete e.dataset.rowEnd,"none"===a)return;const o=et(e).width*f/2+4*f;let r=l(n);y?r=(l(n)+l(ot(t,n)))/2:"middle"===a&&0===n?r+=o:"middle"===a&&n===k&&(r-=o);const c=i(L(t,n)),d={middle:(i(_(t,n))-c)/2,above:-7*f,below:7*f};E(e,r,c+d[a],S,u)})});const ft=t=>{const a=n.flatMap((e,n)=>e.pinned&&!H(t,n)?[n]:[]),o=n.map((t,e)=>e).filter(e=>!H(t,e)),r=e=>C(t,e)?.value??0,{keys:c}=e.pick;o.length&&(c.includes("last")&&a.push(o[o.length-1]),c.includes("first")&&a.push(o[0]),c.includes("highest")&&a.push(o.reduce((t,e)=>r(e)>r(t)?e:t)),c.includes("lowest")&&a.push(o.reduce((t,e)=>r(e)<r(t)?e:t)),c.includes("outliers")&&a.push(...((t,e=5,n=25)=>{if(t.length<4)return null;const{mean:a,share:o}=(t=>{const e=t.map(t=>t.y),n=Math.min(...e),a=Math.max(...e),o=n<0&&a>0,r=a-n||1;return{mean:e.reduce((t,e)=>t+e,0)/e.length,share:(t,e)=>t/(o?r:Math.abs(e)||r)*100}})(t),r=e=>t.filter(t=>Math.abs(o(t.y-e(t.x),e(t.x)))>n),s=e=>e.length<=t.length/5;let c=Bt(t),l=r(c.at);l.length&&s(l)&&(c=Bt(t.filter(t=>!l.includes(t))),l=r(c.at)),s(l)||(c=Bt(t),l=[]);const i=c.at,u=t[0],d=t[t.length-1],h=o(i(d.x)-i(u.x),a),f=Math.abs(c.t)>=(b=c.n-2,Et[b-1]??(b<30?2.1:2));var b;const m=Math.abs(o(c.spread,a))<e,$=Math.abs(h)<e?"flat":h>0?"up":"down",p="flat"===$?m?"flat":"unclear":f?$:"unclear";return{course:p,line:i,outside:"unclear"===p?[]:l}})(o.map(t=>({x:t,y:r(t)})))?.outside.map(t=>t.x)??[]));const l=[];for(const e of a){const n=s[t][e];l.includes(e)||"none"===n.dataset.place||l.every(e=>1===ut([s[t][e],n],f,1e3,u))&&l.push(e)}return new Set(l)},bt=t=>{const e=s[t].filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out"));return 1===ut(e,f,S,u)},mt=new Map;for(const t of o){const n="all"===e.pick.mode||"auto"===e.pick.mode&&bt(t)?null:ft(t);mt.set(t,n),n&&s[t].forEach((t,e)=>{"none"===t.dataset.place||n.has(e)||t.setAttribute("data-left-out","")})}if(!g&&!y&&o.some(t=>mt.get(t))){const t=l(k)+l(0),e=2*f,a=o.flatMap(t=>n.flatMap((n,a)=>a===k||H(t,a)||H(t,a+1)?[]:lt(t,a,a+1,e))),r=(c[0]?et(c[0]).height:0)*f,i=o.flatMap(t=>{const e=c[t];if(!e)return[];let n=k;for(;n>0&&H(t,n);)n--;const[a,o]=B(t,n);return[[a+10*f,o-r/2,et(e).width*f,r]]}),d=o.flatMap(t=>[...mt.get(t)??[]].map(e=>({s:t,i:e}))),h=({s:t,i:e})=>{const n=C(t,e)?.value??0,a=e>0&&!H(t,e-1)?C(t,e-1)?.value:void 0,o=e<k&&!H(t,e+1)?C(t,e+1)?.value:void 0;return void 0!==(a??o)&&(void 0===a||n<=a)&&(void 0===o||n<=o)?["below","outside","below far","outside far","after","before"]:["outside","below","outside far","below far","after","before"]},m=({s:e,i:n},a)=>{const o=et(s[e][n]).width*f,r=b,[c,l]=B(e,n),i=Math.min(Math.max(c-o/2,0),t-o);return"outside"===a?[i,l-7*f-r,o,r]:"below"===a?[i,l+7*f,o,r]:"outside far"===a?[i,l-7*f-2*r,o,r]:"below far"===a?[i,l+7*f+r,o,r]:"after"===a?[c+7*f,l-r/2,o,r]:[c-7*f-o,l-r/2,o,r]},$=d.map(h),p=e=>e[0]>=0&&e[1]>=0&&e[0]+e[2]<=t&&e[1]+e[3]<=u-2*f,g=d.map(({s:t,i:e})=>{const[n,a]=B(t,e);return[n-6*f,a-6*f,12*f,12*f]}),w=[],y=new Set,M=d.map((t,e)=>{const n=$[e].map(e=>m(t,e)),o=t=>p(t)&&![...w,...i,...g].some(e=>Z(t,e));let r=n.findIndex(t=>o(t)&&!a.some(e=>Z(t,e)));return r<0&&(r=n.findIndex(o),r>=0&&y.add(e)),r>=0&&w.push(n[r]),r<0?null:r});d.forEach((t,e)=>{const n=s[t.s][t.i];n.toggleAttribute("data-cut",y.has(e));const a=M[e];if(null===a)return n.setAttribute("data-left-out","");const o=$[e][a],[r,c,l,i]=m(t,o),d=o.split(" ")[0];n.dataset.place=d,E(n,"after"===d?r:"before"===d?r+l:r+l/2,"outside"===d?c+i:"below"===d?c:c+i/2,S,u)})}y||(()=>{const t=o.map(t=>a[t]),r=a.map((e,n)=>w?Ct(t,o.indexOf(n)):v?Ct(a,n):{shape:"circle",open:!1}),s=(t,e,n)=>{const[a,o]=B(t,e);return Ht(r[t].shape,a,o,4*f,{...n,style:`${n.style??""}${s=o,`--rise:${Tt(N-s)}px; `}${R(e)}`});var s},c=t=>n.map((t,e)=>e).filter(e=>!H(t,e)&&((t,e)=>{const n=mt.get(t);return n?n.has(e):A>=10*f})(t,e)),l=o.flatMap(t=>r[t].open?c(t).map(e=>s(t,e,{class:$,"data-row":e+1,...v&&{"data-series":t+1}})):[]);"grow"===p.closest("[data-animate]")?.getAttribute("data-animate")?q(p,l,S,u):e.lineHoles.push(...l),o.forEach(t=>{for(const e of c(t))p.appendChild(s(t,e,{class:m,...z[t].attrs,"data-marker":r[t].shape,...r[t].open&&{"data-open":""},"data-row":e+1,style:z[t].ink}))})})(),e.pointOf=t=>{const e=o.filter(e=>!H(e,t)).map(e=>B(e,t));return e.length?e.reduce((t,e)=>e[1]<t[1]?e:t):null};const $t=(w?[]:c).map((t,e)=>{const n=(t=>{let e=k;for(;e>0&&H(t,e);)e--;return e})(e),[a,o]=B(e,n);return{name:t,x:(y?a+A/2:a)+10*f,y:g?(o+i(_(e,n)))/2:o}}),gt=(c[0]?et(c[0]).height:0)*f;for(const t of((t,e)=>(t.sort((t,e)=>t.y-e.y),t.forEach((n,a)=>{const o=t[a-1];o&&n.y<o.y+e&&(n.y=o.y+e)}),t))($t,gt))E(t.name,t.x,t.y,S,u);const wt=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),yt=t||g||2!==a.length||x||wt?N:u-2*f;w||p.appendChild(O("line",{class:r,x1:0,x2:l(k)+l(0),y1:yt,y2:yt}))}}),Ft=Ut(!1),Vt=Ut(!0),Rt=new Set,qt={segments:t=>{let e=0,a=!1;return t.map(t=>{if(t.isTotal)return a&&((t,e)=>{if(Math.abs(t-e)<=Math.abs(e)/100)return;const a=`[${n}] A total reads ${t}, but the steps before it add up to ${Number(e.toFixed(6))}. The chart shows your number.`;Rt.has(a)||(Rt.add(a),console.warn(a))})(t.value,e),a=!1,e=t.value,{...t,from:0,to:t.value,kind:"total"};const o=e;return e+=t.value,a=!0,{...t,from:o,to:e,kind:t.value>=0?"up":"down"}})},breakable:!0,headroom:({labelHeight:t,badgeHeight:e,hasAnnotations:n,unit:a})=>t+6*a+(n?1.6*e:0),draw({segments:t,cx:e,y:n,barWidth:a,height:s,unit:c,svg:l,values:i,breakAt:u,insideAlign:d}){const h=n(0),f=nt(i,a,c),b=d??"center",m=t.map((e,a)=>{const o=n(Math.max(e.from,e.to)),r=Math.abs(n(e.from)-n(e.to)),s=null!==u&&Math.min(e.from,e.to)<u&&Math.max(e.from,e.to)>u,l="total"===e.kind&&a>0&&a===t.length-1;return{top:o,length:r,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!s&&!f&&at(i[a],r,c)}}),$=i[0]?et(i[0]).height*c*.56:0;let p=Number.POSITIVE_INFINITY;for(const[o,r]of m.entries())r.inside&&(p=Math.min(p,(a-et(i[o]).width*c)/2));const g=t.length,w=(t,e,n=!1)=>`--start:${(t/g).toFixed(4)}; --span:${(e/g).toFixed(4)}; --ease:${n?C:"linear"};`;t.forEach((o,r)=>{const s=t[r+1];if(!s)return;const c=n(o.to),i=e(r)+a/2,u=e(r+1)-a/2;l.appendChild(O("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${T("--i",s.slot)}; ${w(r+1,1/3)}`}))}),t.forEach((n,r)=>{const{top:u,length:d,down:h,inside:f}=m[r];l.appendChild(O("rect",{class:_(o,n),"data-kind":n.kind,"data-row":r+1,"data-grow":h?"down":"up",x:e(r)-a/2,y:u,width:a,height:Math.max(d,1),style:`${T("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const y=i[r];y.style.setProperty("--start",(r/g).toFixed(4)),y.style.setProperty("--span",(1/g).toFixed(4));const M=Math.min(p,(d-$)/2),v="center"===b?u+d/2:"end"===b!==h?u+M+$/2:u+d-M-$/2;y.dataset.place=f?"inside":"outside",y.dataset.kind=n.kind;const x=f?v:"down"===n.kind?u+d+et(y).height*c+3*c:u-3*c;E(y,e(r),x,S,s)}),l.appendChild(O("line",{class:r,x1:0,x2:S,y1:h,y2:h}))}},It={enabled:!1,log(...t){It.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!It.enabled)return a();const o=performance.now(),r=a(),s=performance.now()-o,c=e.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${n}] ${t} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,e):It.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},jt=t=>{const e=(t?.textContent||"").trim(),n=e.match(/^(.*?)(-?\d+(?:[.,]\d+)?)(.*)$/);return{raw:e,number:n?.[2]??"",prefix:n?.[1]??"",suffix:n?.[3]??"",missing:!n,value:n?Number.parseFloat(n[2].replace(",",".")):0}},Pt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).flatMap((t,e)=>t.hasAttribute("data-note")?[e]:[]),Dt=(t,e="data-i18n")=>{const n=Pt(t);return Array.from(t.querySelectorAll("tbody tr")).map((t,a)=>{const o=t.querySelector("th"),r=Array.from(t.querySelectorAll("td")),s=r.filter((t,e)=>!n.includes(e)).map(jt);s.length||s.push(jt(null));const c=n.map(t=>r[t]).find(t=>t?.textContent?.trim());return{...s[0],label:(o?.textContent||"").trim(),note:c?.textContent?.trim()??null,noteKey:e&&c?.getAttribute(e)||null,short:o?.getAttribute("data-short")||null,pinned:"show"===t.getAttribute("data-value"),key:e&&o?.getAttribute(e)||null,cells:s,classes:Array.from(t.classList),isTotal:"total"===t.getAttribute("data-kind"),slot:a}})},Wt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).filter(t=>!t.hasAttribute("data-note")),Gt=(t,e,n="data-i18n")=>{const a=Wt(t),o=Math.max(1,P(e.map(t=>t.cells.length)));return Array.from({length:o},(t,e)=>{const o=a[e];return{name:(o?.textContent||"").trim(),key:n&&o?.getAttribute(n)||null,focus:"focus"===o?.getAttribute("data-kind"),marker:o?.getAttribute("data-marker")??null,line:(r=o?.getAttribute("data-line"),"dashed"===r||"dotted"===r?r:null),group:!!o?.hasAttribute("data-group"),chart:"line"===o?.getAttribute("data-chart")?"line":null};var r})},Kt=t=>Number(t.toPrecision(12)),Yt=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return Kt((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},Xt=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(Kt(o*n));return a},Zt=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Kt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},Qt=t=>{const e=(t??"").trim().split(/\s+/).map(Number.parseFloat);return e.length>1&&e.every(Number.isFinite)?e.sort((t,e)=>t-e):null},Jt=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=Zt(n,t.step),a=Xt(t.min,t.max,n);return{...t,step:n,ticks:a}},te=null,ee=t=>{if(te??(te=document.createElement("canvas").getContext("2d",{willReadFrequently:!0})),!te)return[0,0,0,1];te.clearRect(0,0,1,1),te.fillStyle=t,te.fillRect(0,0,1,1);const[e,n,a,o]=te.getImageData(0,0,1,1).data;return[e,n,a,o/255]},ne=([t,e,n])=>{const a=t=>{const e=t/255;return e<=.03928?e/12.92:((e+.055)/1.055)**2.4};return.2126*a(t)+.7152*a(e)+.0722*a(n)},ae=(t,e)=>{const[n,a]=[ne(t),ne(e)].sort((t,e)=>e-t);return(n+.05)/(a+.05)},oe=t=>{const e=document.createElement("span");e.style.color="var(--tablechart-surface, Canvas)",t.append(e);const n=ee(getComputedStyle(e).color);return e.remove(),n},re=(t,e)=>t.querySelector(`:is(.tablechart-bar, .tablechart-piece)[data-row="${e.dataset.row}"]${e.dataset.series?`[data-series="${e.dataset.series}"]`:""}`),se=t=>{const e=t.querySelectorAll(".tablechart-value[data-place='inside']");if(!e.length)return;const n=oe(t);for(const a of e){const e=re(t,a);if(!e||a.hasAttribute("data-left-out"))continue;const o=ee(getComputedStyle(e).fill),r=ne(n)>ne(o),s=r?[255,255,255]:[0,0,0];let c=r?[0,0,0]:[255,255,255];for(let t=0;t<=20;t++){const e=n.slice(0,3).map((e,n)=>Math.round(e+(s[n]-e)*t/20));if(ae(e,o)>=4.5){c=e;break}}a.style.setProperty("--_ink",`rgb(${c.join(" ")})`)}},ce=["axis-break","trend","bracket"],le=t=>{const e=t.plan;if(!e)return;const n=e=>null===e||t.step-e>=1;for(const a of t.figure.querySelectorAll("[data-from]")){const t=Number(a.dataset.from)-1,o=Number(a.dataset.to)-1,r=a.closest("[data-series]")?.dataset.series,s=r?Number(r)-1:0,c=e.series[s],l=t=>e.cells[t]?.[s]?.step??e.rows[t]?.step??null;let i=t-1;if(c&&null!==c.step)i=n(c.step)?o:t-1;else for(;i<o&&n(l(i+1));)i++;const u=a.hasAttribute("data-flat")?(i-t+1)/(o-t+1):o>t?Math.max(0,i-t)/(o-t):0;a.style.setProperty("--reveal",String(u))}},ie=(t,e,n=!1)=>{const a=t.plan;if(!a)return;const o=Math.min(Math.max(Math.round(e),0),a.count),r=o!==t.step;t.step=o,t.figure.style.setProperty("--_step",String(o)),le(t);const[s,c]=t.controls?.querySelectorAll("button")??[];s&&(s.disabled=0===o),c&&(c.disabled=o===a.count),r&&!n&&t.figure.dispatchEvent(new CustomEvent("tablechart:step",{bubbles:!0,detail:{step:o,steps:a.count}}))},ue="tablechart-tooltip",de=["--tablechart-surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],he=null,fe=null,be=null,me=0,$e=()=>{clearTimeout(me),he&&fe&&(he.hidden=!0,fe=null,be=null)},pe=!1,ge=!0,we=NaN,ye=NaN,Me=!1,ve=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,xe=()=>{clearTimeout(me),me=window.setTimeout($e,120)},ke=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Ne=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole)`);if(!n)return;const a=getComputedStyle(n);return a.fill&&"none"!==a.fill?a.fill:a.stroke},Se=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!ke(t,c[e]))continue;const n=a?t.figure.querySelector(`.tablechart-name[data-series="${s+1}"]`):null;o.push({name:a?n?.textContent??t.series[s].name:"",value:c[e].textContent??"",colour:a?Ne(t,s):void 0,sample:n?{marker:n.dataset.marker??null,open:n.hasAttribute("data-open"),line:n.dataset.line??null,box:"box"===n.dataset.swatch}:void 0})}const r=t.totals[e];return o.length>1&&ke(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Ae=(t,e,n)=>{if(clearTimeout(me),fe===t&&be===e)return;const a=(t.type.tooltip??Se)(t,e,n);if(!a.length)return $e();fe&&fe!==t&&$e(),he??(he=(()=>{const t=document.createElement("div");return t.className=ue,t.setAttribute("aria-hidden","true"),t.hidden=!0,Ot=document.createElement("div"),(_t=document.createElement("div")).className=`${ue}-arrow`,t.append(Ot,_t),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(me)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&xe()),document.addEventListener("pointerdown",e=>{const n=e.target;!fe||fe.plot.contains(n)||t.contains(n)||$e()}),window.addEventListener("resize",$e),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${ue}-line`,n){const t=document.createElement("span");t.className=`${ue}-key`,t.style.background=n,o?.box?t.dataset.sample="box":o&&(t.dataset.sample="line",o.marker&&(t.dataset.marker=o.marker),o.line&&(t.dataset.line=o.line),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${ue}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${ue}-value`,n.textContent=e,r.append(n)}return r},r=(t.figure.querySelectorAll("tbody tr")[e]?.querySelector("th"))?.textContent?.trim()||t.categories[e]?.textContent||t.rows[e].label,s=1===a.length&&!a[0].name,c=a.every(t=>t.name&&!t.value),l=((t,e)=>{const n=Pt(t),a=t.querySelectorAll("tbody tr")[e]?.querySelectorAll("td")??[];return n.map(t=>a[t]).find(t=>t?.textContent?.trim())??null})(t.figure,e)?.textContent?.trim(),i=l?[Object.assign(document.createElement("div"),{className:`${ue}-note`,textContent:l})]:[];Ot.replaceChildren(...c?[]:[o(r,s?a[0].value:"",void 0,!0)],...s?[]:a.map(({name:t,value:e,colour:n,sample:a})=>o(t,e,n,!1,a)),...i);const u=getComputedStyle(t.figure);for(const m of de){const t=u.getPropertyValue(m).trim();t?he.style.setProperty(m,t):he.style.removeProperty(m)}he.style.setProperty("--_color",u.color),he.style.colorScheme=u.colorScheme,he.style.fontFamily=u.fontFamily;const d=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);he.parentElement!==d&&d.append(he),fe=t,be=e,he.hidden=!1,he.style.left="0px",he.style.top="0px";const h=he.getBoundingClientRect(),f={x:h.left,y:h.top,scale:ve(he,h.width)},b=ve(t.plot,t.plot.getBoundingClientRect().width);he.style.fontSize=Number.parseFloat(u.fontSize)*b/f.scale+"px",((t,e,n,a={x:0,y:0,scale:1},o=2,r=8,s=12)=>{const c=t.getBoundingClientRect(),l=c.width,i=c.height,u=Number.parseFloat(getComputedStyle(t).borderLeftWidth)||0,d=e.getBoundingClientRect().height/2+(o-u)*a.scale,h=s*a.scale,{clientWidth:f,clientHeight:b}=document.documentElement,m=n.top-r,$=b-n.bottom-r,p=i+d<=m||!(i+d<=$)&&m>=$,g=p?n.top-d-i:n.bottom+d,w=n.left+n.width/2,y=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(y-a.x)/a.scale+"px",t.style.top=(Math.max(r,Math.min(g,b-i-r))-a.y)/a.scale+"px",t.dataset.side=p?"top":"bottom",e.style.left=Math.max(h,Math.min(w-y,l-h))/a.scale-u+"px"})(he,_t,((t,e)=>{if(t.type.centre&&t.values[e])return t.values[e].getBoundingClientRect();const n=t.pointOf?.(e);if(n){const e=t.svg.getBoundingClientRect(),a=e.width/S,o=4*a*(S/t.plot.clientWidth);return new DOMRect(e.left+n[0]*a-o,e.top+n[1]*a-o,2*o,2*o)}const a=t.svg.querySelectorAll(`[data-row="${e+1}"]:not(.tablechart-connector, .tablechart-leader)`);let o=null;for(const u of a){const t=u.getBoundingClientRect();(t.width||t.height)&&(o=o?new DOMRect(Math.min(o.left,t.left),Math.min(o.top,t.top),Math.max(o.right,t.right)-Math.min(o.left,t.left),Math.max(o.bottom,t.bottom)-Math.min(o.top,t.top)):t)}if(o)return o;const r=t.plot.getBoundingClientRect(),[s,c,l,i]=t.rowBox?.(e)??[0,0,100,100];return new DOMRect(r.left+r.width*s/100,r.top+r.height*c/100,r.width*l/100,r.height*i/100)})(t,e),f)},Ce=t=>{fe===t&&$e()},He={area:Vt,bar:xt,column:kt,donut:St,line:Ft,waterfall:qt},Te={"axis-break":j,trend:bt,bracket:X,reference:ft,note:dt},Le=Object.keys(Te),Oe=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},_e=["straight","step","smooth"],Be=(t,e,n,a,o)=>{const r=e===a,[s,c,l]=r?[Math.min(t,n),Math.max(t,n),e]:[Math.min(e,a),Math.max(e,a),t],i=o.filter(([t,e,n,a])=>r?e<=l&&l<=e+a:t<=l&&l<=t+n).map(([t,e,n,a])=>r?[t,t+n]:[e,e+a]).sort((t,e)=>t[0]-e[0]),u=[];let d=s;for(const[h,f]of i)h>d&&u.push([d,Math.min(h,c)]),d=Math.max(d,f);return d<c&&u.push([d,c]),u.map(([t,e])=>r?`M${L(t)},${L(l)}H${L(e)}`:`M${L(l)},${L(t)}V${L(e)}`).join("")},Ee=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=O("path",{d:Be(n,a,o,r,e)});for(const{name:c,value:l}of Array.from(t.attributes))/^[xy][12]$/.test(c)||s.setAttribute(c,l);t.replaceWith(s)},ze=t=>Array.from((t.getAttribute("d")??"").matchAll(/M(-?[\d.]+),(-?[\d.]+)([HV])(-?[\d.]+)/g),([,t,e,n,a])=>"H"===n?[+t,+e,+a,+e]:[+t,+e,+t,+a]),Ue=(t,[e,n,a,o])=>t.map(([t,r,s,c])=>r===c?n<=r&&r<=n+o&&Math.max(t,e)<Math.min(s,e+a)?`M${L(Math.max(t,e))},${L(r)}H${L(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${L(t)},${L(Math.max(r,n))}V${L(Math.min(c,n+o))}`:"").join(""),Fe=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},Ve=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),Re=(t,e)=>{const n=t.dataset.chartShape;return n&&_e.includes(n)?n:_e.includes(e.shape)?e.shape:"straight"},qe=0,Ie=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=He[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(He).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=Dt(t,e.langattribute);if(!c.length)return console.warn(t.querySelector("table")?`[${n}] A chart has no rows in its table, so there is nothing to draw.`:`[${n}] A chart has no table, so there is nothing to draw.`,t),t.setAttribute("data-chart-empty",""),null;(t=>{const e=t.querySelector(":scope > figcaption");if(!e)return;(t=>{for(const e of t.querySelectorAll("br")){if(e.previousElementSibling?.classList.contains("tablechart-sr"))continue;if(/[.!?:;,…]$/.test(Oe(e)))continue;const t=document.createElement("span");t.className=w,t.textContent=". ",e.before(t)}})(e);const n=t=>t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"),a=t=>{e.id||(e.id="tablechart-caption-"+ ++qe),t.setAttribute("aria-labelledby",e.id)};"FIGURE"!==t.tagName||n(t)||a(t);const o=t.querySelector("table");!o||n(o)||o.querySelector(":scope > caption")||a(o)})(t);let l=Gt(t,c,e.langattribute);if(l.length>1&&!s.series&&!s.columns&&(console.warn(`[${n}] A ${r} chart uses only the first of its ${l.length} value columns.`),l=l.slice(0,1)),l.some(t=>t.chart)){const t=s.lines?l.every(t=>t.chart)?'Every series has data-chart="line", so the chart is a line chart: set data-chart="line" on the figure.':null:`A ${r} chart cannot draw a series as a line.`;t&&(console.warn(`[${n}] ${t}`),l=l.map(t=>({...t,chart:null})))}const i=l.some(t=>t.chart),u=l.length>1;u&&t.style.setProperty("--_series-count",String(l.length));const d=t.hasAttribute("data-chart-stack");d&&!s.stackable&&console.warn(`[${n}] A ${r} chart cannot be stacked.`),d&&i&&console.warn(`[${n}] A chart with a line cannot be stacked.`);const h=d&&!!s.stackable&&u&&!i,m=document.createElement("div");m.className="tablechart-plot",m.setAttribute("aria-hidden","true");const $=O("svg",{role:"presentation",focusable:"false"});m.appendChild($);const g=t.querySelector(":scope > table"),y=e=>g?g.before(e):t.append(e);y(m);const M=s.centre?c.filter(t=>!t.isTotal):c,v=Math.max(0,P(M.flatMap(t=>t.cells.slice(0,l.length).map(t=>D(t.number))))),N=l.map((t,e)=>Math.max(0,P(c.map(t=>D(t.cells[e]?.number??""))))),S=document.createElement("div");S.className="tablechart-values",m.appendChild(S);const A=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=B(a,S);return r.classList.add(...t.classes),r.dataset.value=String(o.value),o.prefix&&(r.dataset.prefix=o.prefix),o.suffix&&(r.dataset.suffix=o.suffix),o.missing&&(r.dataset.missing=o.raw),u&&(r.dataset.series=String(e+1)),s.columns&&(r.dataset.decimals=String(N[e])),r.dataset.row=String(n+1),r.style.setProperty("--i",String(t.slot)),!1===s.numbers&&(e||n)&&(r.dataset.place="none"),r})),C=A[0],H=h&&s.totals?c.map((t,e)=>{const n=B(a,S);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(wt(t,l.length));const o=t.cells[0];return o.prefix&&(n.dataset.prefix=o.prefix),o.suffix&&(n.dataset.suffix=o.suffix),n.style.setProperty("--i",String(t.slot)),n}):[],T=c[c.length-1],L=l.some(t=>t.focus),_=t.getAttribute("data-chart-legend"),E=u&&!s.columns&&(null===_?e.legend||void 0!==s.legend:"false"!==_)?document.createElement("div"):null;E&&(E.className=b,E.setAttribute("aria-hidden","true"),E.inert=!0);const z=l.filter(t=>t.chart),U=u&&!s.columns?l.map((n,a)=>{const o=B(f,E??m);E&&(o.dataset.place="legend");const r=n.chart?void 0:s.legend??s.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==Re(t,e)){const t=n.chart?Ct(z,z.indexOf(n)):Ct(l,a);o.dataset.marker=t.shape,o.toggleAttribute("data-open",t.open)}return n.line&&!r&&(o.dataset.line=n.line),n.key&&e.langattribute&&o.setAttribute(e.langattribute,n.key),o.dataset.series=String(a+1),o.style.setProperty("--n",String(a)),o.style.setProperty("--palette",`var(--tablechart-color-${a+1})`),o.style.setProperty("--m",L&&!n.focus?"1":"0"),o.style.setProperty("--i",String(T.slot)),o}):[],F=s.centre?B(p,m):null;if(F){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);F.dataset.value=String(e),t&&(F.dataset.decimals=String(D(t.number)))}const V=F&&!c.some(t=>t.isTotal)?((t,e,n)=>{const a=t.querySelector("table");if(!a)return null;const o=a.querySelector("tfoot [data-chart-total]");if(o)return o.dataset.value=e.dataset.value??"0",o;const r=(a.tFoot??a.createTFoot()).insertRow(),s=document.createElement("th");s.scope="row",s.textContent=n.totallabel;const c=t.getAttribute("data-chart-keys");c&&n.langattribute&&s.setAttribute(n.langattribute,`${c}-total`);const l=r.insertCell();return l.setAttribute("data-chart-total",""),l.dataset.value=e.dataset.value??"0",r.prepend(s),l})(t,F,e):null,R="beside"===s.categories,q=document.createElement("div");q.className="tablechart-categories",q.setAttribute("aria-hidden","true"),q.inert=!0,R?q.dataset.place="beside":s.centre&&(q.dataset.place="key"),q.style.setProperty("--_columns",String(c.length));let I=0;for(const[n,a]of c.entries()){const t=document.createElement("span");t.classList.add(...a.classes),t.textContent=a.short??a.label,a.key&&e.langattribute&&t.setAttribute(e.langattribute,a.short?`${a.key}-short`:a.key),s.centre&&(t.dataset.kind=a.isTotal?"total":"slice",a.isTotal||(t.dataset.slice=String(I+1),t.style.setProperty("--n",String(I)),t.style.setProperty("--palette",`var(--tablechart-color-${I+1})`),I+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),q.appendChild(t)}s.centre&&t.style.setProperty("--_slice-count",String(I)),R?m.appendChild(q):y(q),E&&y(E);const j=l.filter(t=>!t.group),W=!s.axes&&!s.centre&&Fe(t,"data-chart-axis",e.axis),G=s.axes?{titles:j.slice(0,2).map((t,n)=>{const a=B(`${x}-title`,m);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:B(`${k}s`,m),numbers:!0}:W||!s.centre&&Fe(t,"data-chart-grid",e.grid)?{titles:[],ticks:B(`${k}s`,m),numbers:W}:null;s.text?.({figure:t,plot:m,rows:c,series:l,config:e});const K=Ve(t,e)?((t,e=!1)=>{const n=t.hasAttribute("data-fragment"),a=Array.from(t.querySelectorAll("tbody tr")),o=Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1),r=Array.from(t.querySelectorAll("[data-annotation]")).filter(t=>ce.includes(t.getAttribute("data-annotation")??"")),s=t=>t.hasAttribute("data-fragment"),c=a.map(t=>Array.from(t.querySelectorAll(":scope > td")));if(!(n||a.some(s)||o.some(s)||c.flat().some(s)||r.some(s)))return null;if(e&&!n)return null;const l=[],i=new Map,u=[],d=t=>{let e=null!==t?i.get(t):void 0;return void 0===e&&(e=l.length,l.push(t),u.push(0),null!==t&&i.set(t,e)),e};let h=0;const f="donut"===t.getAttribute("data-chart"),b=t=>f&&"total"===t.getAttribute("data-kind"),m=e?d(t.getAttribute("data-fragment-index")):-1,$=a.map(t=>{if(b(t))return{step:null,slot:0};if(e)return{step:m,slot:u[m]++};if(!n&&!s(t))return{step:null,slot:h++};const a=d(t.getAttribute("data-fragment-index"));return{step:a,slot:u[a]++}}),p=Math.max(-1,...$.map(t=>t.step??-1));if(p>=0)for(const[M,v]of a.entries())b(v)&&($[M]={step:p,slot:u[p]++});const g=o.map(t=>({step:s(t)?d(t.getAttribute("data-fragment-index")):null})),w=c.map(t=>t.map(()=>({step:null,slot:0}))),y=Math.max(0,...c.map(t=>t.length));for(let M=0;M<y;M++)for(const[t,e]of c.entries()){const n=e[M];if(!n||!s(n))continue;const a=d(n.getAttribute("data-fragment-index"));w[t][M]={step:a,slot:u[a]++}}return{rows:$,series:g,cells:w,notes:r.map(t=>{const e=(e,n)=>{const a=Number.parseInt(t.getAttribute(e)??"",10);return Number.isFinite(a)?a-1:n},[n,a]="bracket"===t.getAttribute("data-annotation")?[e("data-from",0),e("data-to",$.length-1)]:[0,$.length-1];let o=null;for(let s=Math.min(n,a);s<=Math.max(n,a);s++)for(const t of[$[s]?.step??null,...(w[s]??[]).map(t=>t.step)])null!==t&&(null===o||t>o)&&(o=t);const r=g[e("data-series",0)]?.step??null;null!==r&&(null===o||r>o)&&(o=r),s(t)&&(o=d(t.getAttribute("data-fragment-index")));const c=null===o?$.length:$.filter(t=>t.step===o).length;return{step:o,after:c}}),count:l.length,indexes:l}})(t,Boolean(s.axes)):null;s.axes&&t.querySelector("tbody [data-fragment], thead [data-fragment]")&&It.log(`A ${r} chart has one step, with data-fragment on the figure; its rows and columns have no steps of their own.`,t),K&&t.setAttribute("data-steps","");const Y=t.getAttribute("data-chart-keys"),X=K&&e.controls?((t,e,n)=>{const a=document.createElement("div");a.className="tablechart-controls";const o=a=>{const o=document.createElement("button");o.type="button",o.className=`tablechart-${a}`,o.dataset.go=a;const r=document.createElement("span");r.className="tablechart-control-icon",r.setAttribute("aria-hidden","true");const s=O("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(O("path",{d:"next"===a?"M6 3l5 5-5 5":"M10 3L5 8l5 5"})),r.appendChild(s);const c=document.createElement("span");c.className="tablechart-control-label",c.textContent=t[a];const l=e[a];l&&n&&c.setAttribute(n,l);const i=document.createElement("span");return i.className=w,i.textContent=t.hint,e.hint&&n&&i.setAttribute(n,e.hint),o.append(..."next"===a?[c,i,r]:[r,c,i]),o};return a.append(o("previous"),o("next")),a})({previous:e.previouslabel,next:e.nextlabel,hint:e.stephint},{previous:Y&&`${Y}-previous`,next:Y&&`${Y}-next`,hint:Y&&`${Y}-step`},e.langattribute):null;X&&y(X);const Z=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),a=Te[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(Te).join(", ")}.`),null;const o=Number.parseInt(t.getAttribute("data-series")??"1",10),r=o>=1&&o<=l.length?o-1:0;return o!==r+1&&console.warn(`[${n}] An annotation reads line ${o}, which is not there; it reads line 1.`),{spec:t,type:a,badge:a.create(t,m),series:r,after:c.length}}).filter(t=>null!==t);if(!R&&!s.centre&&!s.axes)for(const[n,a]of c.entries()){if(!a.note)continue;const t=document.createElement("span");t.dataset.annotation="note",t.dataset.row=String(n+1),t.textContent=a.note,a.noteKey&&t.setAttribute("data-i18n",a.noteKey),Z.push({spec:t,type:dt,badge:dt.create(t,m),series:0,after:c.length})}Ve(t,e)&&t.setAttribute("data-animate",De(t,r,e,Boolean(K)));const Q={figure:t,plot:m,svg:$,rows:c,decimals:v,type:s,values:C,series:l,seriesValues:A,names:E?[]:U,categories:Array.from(q.children),centre:F,axes:G,stacked:h,totals:H,totalCell:V,rowAt:null,rowBox:null,pointOf:null,annotations:Z,checks:[],plan:K,step:0,controls:X},J=()=>en(t,$);$.addEventListener("transitionend",J),$.addEventListener("transitioncancel",J),X?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&ie(Q,Q.step+("next"===e?1:-1))}),ie(Q,0,!0);const tt=t.getAttribute("data-chart-tooltip"),et="false"!==tt&&("auto"===tt?"auto":null!==tt||e.tooltip);return et&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(Me)return;Me=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(ge=t.screenX!==we||t.screenY!==ye,we=t.screenX,ye=t.screenY,ge&&(pe=!1))},{capture:!0,passive:!0});const t=()=>{pe=!0,$e()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!0})})();const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if("pointerdown"===o.type)pe=!1;else if("mouse"===o.pointerType&&(!ge||pe))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return fe===t?$e():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=ve(a,n.width);return t.rowAt((e.clientX-n.left)/o,(e.clientY-n.top)/o)}const n=e.target.closest?.("[data-row]")?.getAttribute("data-row");return n?Number(n)-1:null})(o);if(s=c,null===c||r(c))return fe===t?$e():void 0;Ae(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||pe||Ae(t,c,e)};t.svg.addEventListener("transitionend",i),t.svg.addEventListener("transitioncancel",i),a.addEventListener("pointermove",c),a.addEventListener("pointerdown",c),a.addEventListener("pointerleave",e=>{"mouse"===e.pointerType&&(s=null,fe===t&&xe())})})(Q,e,"auto"===et),Qe(Q,e),Q},je={grow:"grow",sweep:"sweep"},Pe=["never","auto","print","always"],De=(t,e,n,a)=>{const o="line"===e||"area"===e,r=je[t.getAttribute("data-chart-animate")??""]??je[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},We=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},Ge=(t,e,n)=>"inside"===t.dataset.chartLabels||"outside"!==t.dataset.chartLabels&&("inside"===e.labels||n)?"inside":"outside",Ke=(t,e,n,a)=>{const o=getComputedStyle(t),r=(o.getPropertyValue(n).trim()||a).match(/^(\d+(?:\.\d+)?)(px|%|em|rem)$/);if(!r)return null;const s=Number(r[1]);return"%"===r[2]?s/100*S:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},Ye=(t,e)=>Ke(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,Xe=["first","last","highest","lowest","outliers"],Ze=(t,e)=>{const a=(t.getAttribute("data-chart-values")??e.values).trim().toLowerCase().split(/\s+/).filter(Boolean);for(const r of a)["auto","all","none",...Xe].includes(r)||console.warn(`[${n}] data-chart-values knows no "${r}". It takes auto, all, none, ${Xe.join(", ")}.`);const o=a.filter(t=>Xe.includes(t));return a.includes("all")?{mode:"all",keys:[]}:a.includes("none")?{mode:"set",keys:[]}:a.includes("auto")||!o.length?{mode:"auto",keys:o.length?o:Xe}:{mode:"set",keys:o}},Qe=(t,e)=>{const n=[...t.seriesValues.flat(),...t.totals,...t.totalCell?[t.totalCell]:[]];for(const a of t.centre?[...n,t.centre]:n)void 0!==a.dataset.missing?a.textContent=a.dataset.missing:Je(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},Je=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=W(Number.parseFloat(t.dataset.value||"0"),e,n);if(t.textContent=a+(a?r:"")+s+o,r&&!a){const e=document.createElement("span");e.className="tablechart-minus",e.textContent=r,t.prepend(e)}},tn=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||nn(t.svg),n)return t.figure.classList.add(v),t.figure.classList.toggle(y,e),t.figure.offsetWidth,e&&an(t.svg),void requestAnimationFrame(()=>t.figure.classList.remove(v));t.figure.classList.toggle(y,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>en(t.figure,t.svg)))},en=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&an(e)},nn=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},an=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},on=t=>"id"===t||"style"===t||t.startsWith("data-chart"),rn=/^\s*(?:Table)?:\s+/,sn=t=>"P"===t?.tagName&&rn.test(t.textContent??""),cn=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,ln=t=>{const e=dn(t);return"P"===e?.tagName?e:t},un=t=>{if(!t||"object"!=typeof t)return;const e=Object.entries(t),n=t=>null===t||"string"==typeof t||"number"==typeof t;return e.length&&e.every(([,t])=>n(t)||Array.isArray(t)&&t.every(n))?e.map(([t,e])=>Array.isArray(e)?{label:t,values:e}:{label:t,value:e}):void 0},dn=t=>{const e=Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.nodeType===Node.TEXT_NODE&&t.textContent?.trim());return 1===e.length&&e[0]instanceof HTMLElement?e[0]:null},hn="strong, b, span.total",fn="data-chart-made",bn=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,mn=new Set,$n=null,pn=["column","bar"],gn=t=>{const e=t.getAttribute("data-chart")||"column";if(!pn.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return pn.includes(n)?n:e},wn=!1,yn=async(t,e)=>{const a=(t=>t.map(t=>{const e=t.closest("p"),n=sn(e)?e:t;if("TABLE"!==n.tagName&&"P"!==n.tagName)return n;const a=document.createElement("figure");((t,e)=>{for(const{name:n,value:a}of Array.from(t.attributes))("class"===n||on(n))&&(e.setAttribute(n,a),t.removeAttribute(n))})(t,a),t.classList.length||t.removeAttribute("class");const o="TABLE"===n.tagName?n:null,r=n.previousElementSibling;let s=n.nextElementSibling;const c=o?sn(r)?r:sn(s)?s:null:n;o&&c===s&&(s=s?.nextElementSibling??null);const l=s?.classList.contains("chart-annotations")?s:(t=>{if("UL"!==t?.tagName&&"OL"!==t?.tagName)return null;const e=Array.from(t.children),n=e.map(t=>t.hasAttribute("data-annotation")?null:(t=>{const e=ln(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=cn.exec(e.textContent??"");if(!n||!Le.includes(n[1]))return null;if(!n[3]&&e.nextSibling)return null;const a=n[2].trim().split(/\s+/).filter(Boolean).map(t=>t.split("="));return{name:n[1],options:a,text:e,length:n[0].length}})(t));return!e.length||e.some((t,e)=>!n[e]&&!t.hasAttribute("data-annotation"))?null:(e.forEach((t,e)=>{const a=n[e],o=ln(t);if(o!==t&&o.replaceWith(...o.childNodes),a){t.setAttribute("data-annotation",a.name);for(const[e,n]of a.options)t.setAttribute(`data-${e}`,n);a.text.textContent=(a.text.textContent??"").slice(a.length)}t.children.length&&Array.from(t.childNodes).filter(t=>t.nodeType===Node.ELEMENT_NODE||t.textContent?.trim()).forEach((t,e)=>{const n=document.createElement("span");0===e&&t instanceof HTMLElement&&t.matches("em, i")?(n.className="tablechart-caption",n.append(...t.childNodes),t.replaceWith(n)):t.nodeType===Node.TEXT_NODE&&(n.textContent=(t.textContent??"").trim(),t.replaceWith(n))})}),t.classList.add("chart-annotations"),t)})(s);return n.replaceWith(a),c&&a.append((t=>{const e=document.createElement("figcaption");for(const{name:r,value:s}of Array.from(t.attributes))e.setAttribute(r,s);const n=t.firstChild;n?.nodeType===Node.TEXT_NODE&&(n.textContent=(n.textContent??"").replace(rn,""),n.textContent||n.remove());const a=Array.from(t.childNodes),o=a.findIndex(t=>"BR"===t.nodeName);if(e.append(...-1===o?a:a.slice(0,o+1)),-1!==o&&o<a.length-1){const t=document.createElement("span");t.append(...a.slice(o+1)),e.append(t)}return t.remove(),e})(c)),o&&a.append(o),l&&a.append(l),It?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(fn)&&"TH"!==t.tagName));(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!wn&&e&&(wn=!0,console.warn(`[${n}] A chart is a <${e.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`,e))})(a),await(async t=>{await Promise.all(t.filter(t=>t.hasAttribute("data-chart-src")).map(async t=>{const e=t.getAttribute("data-chart-src"),a=Array.from(t.querySelectorAll("table")).find(t=>t.tHead)??null;for(const n of t.querySelectorAll("table"))n!==a&&n.remove();try{const n=await fetch(e);if(!n.ok)throw new Error(`${n.status} ${n.statusText}`);const o=await n.json(),r=Array.isArray(o)?o:o?.rows?Array.isArray(o.rows)?o.rows:un(o.rows):un(o);if(!Array.isArray(r))throw new Error("no rows in it: a list of rows, an object with rows, or names with their values");const s=((t,e,n,a=document.createElement("table"),o="Note")=>{for(const l of a.querySelectorAll(":scope > tbody, :scope > tfoot, :scope > tr"))l.remove();const r=t.some(t=>t.note);if(!a.tHead&&(e.length||n||r)){const t=a.createTHead().insertRow(),o=document.createElement("th");o.textContent=n,t.append(o);for(const n of e){const e=document.createElement("th");e.textContent=n,t.append(e)}}const s=document.createElement("tbody");a.append(s);for(const l of t){const t=s.insertRow();"total"===l.kind&&(t.dataset.kind="total");const e=document.createElement("th");e.textContent=String(l.label??""),l.short&&(e.dataset.short=l.short),t.append(e);for(const n of l.values??[l.value??null])t.insertCell().textContent=null===n?"":String(n);r&&(t.insertCell().textContent=l.note??"")}const c=a.tHead?.rows[a.tHead.rows.length-1];if(r&&c&&!c.querySelector("[data-note]")){const e=Math.max(...t.map(t=>(t.values??[t.value]).length));for(;c.cells.length<e+1;)c.append(document.createElement("th"));const n=document.createElement("th");n.dataset.note="",n.textContent=o,c.append(n)}return a})(r,Array.isArray(o?.series)?o.series.map(String):[],"string"==typeof o?.label?o.label:"",a??void 0,"string"==typeof o?.note?o.note:void 0);if(!a){const e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||It?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),It?.log?.(`Read ${r.length} rows from "${e}"`)}catch(o){const t="file:"===window.location.protocol;console.warn(`[${n}] Could not read the chart data in "${e}": ${o.message}.`+(t?" A page opened as a file cannot fetch files; open it from a server.":""))}}))})(a),(t=>{for(const e of t){for(const n of e.querySelectorAll("tbody tr")){const t=n.cells[0];if("TD"!==t?.tagName||n.cells.length<2)continue;const e=document.createElement("th");for(const{name:n,value:a}of Array.from(t.attributes))e.setAttribute(n,a);e.append(...t.childNodes),t.replaceWith(e);for(let a=dn(e);a?.matches(hn);a=dn(e))n.dataset.kind="total",a.replaceWith(...a.childNodes)}const t=Array.from(e.querySelector("thead tr:last-child")?.children??[]);for(const e of t.slice(1))for(let t=dn(e);t?.matches(hn);t=dn(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(a),((t,e)=>{if(!e)return;const a=new Map;for(const o of t){let t=o.getAttribute("data-chart-keys")||null;if(!t)continue;if(a.has(t)){const e=a.get(t)+1;a.set(t,e),console.warn(`[${n}] Two charts have data-chart-keys="${t}", so this one uses "${t}-${e}" to keep their translations apart.`),t=`${t}-${e}`}else a.set(t,1);o.querySelectorAll("tbody th").forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-row${a+1}`)});const r=Wt(o);r.length>1&&r.forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-col${a+1}`)}),r.forEach((n,a)=>{if(!n.hasAttribute("data-group"))return;const r=[];o.querySelectorAll(`tbody tr > td:nth-of-type(${a+1})`).forEach(n=>{const a=(n.textContent||"").trim();r.includes(a)||r.push(a),n.getAttribute(e)||n.setAttribute(e,`${t}-group${r.indexOf(a)+1}`)})});const s=Pt(o);o.querySelectorAll("tbody tr").forEach((n,a)=>{const o=n.querySelectorAll("td");for(const r of s){const n=o[r];n?.textContent?.trim()&&!n.getAttribute(e)&&n.setAttribute(e,`${t}-note${a+1}`)}}),It?.log?.(`Keys for "${t}" written onto ${o.querySelectorAll("tbody th").length} rows`)}})(a,e.langattribute);for(const n of a)n.dispatchEvent(new CustomEvent("tablechart:table",{bubbles:!0}));return a},Mn=(t,e)=>{const a=It.timed("Building",t,()=>Ie(t,e));return a?(t.setAttribute(fn,""),xn(),((t,e)=>{let a=t,r=gn(a.figure),m=null,g=!1,w=!1;const y=async()=>{if(!Ve(a.figure,e))return tn(a,!0);const t=a.figure.classList.contains("is-shown");if(!g||null===m||t||w)!g&&e.replay&&t&&tn(a,!1);else{w=!0;const t=bn()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(a.figure);t&&await(n=t,new Promise(t=>{const e=["animationstart","transitionrun"],a=()=>{for(const t of e)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(n)&&a()},r=new MutationObserver(()=>{"0"!==getComputedStyle(n).opacity&&a()});for(const n of e)document.addEventListener(n,o,!0);r.observe(n,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(bn())return;await new Promise(requestAnimationFrame);const n=t.getAnimations().filter(t=>t instanceof CSSAnimation);for(let r=t.parentElement;r&&r!==document.body;r=r.parentElement)n.push(...r.getAnimations());let a=0;for(const r of n){const t=r.effect?.getComputedTiming(),n=Number(t?.activeDuration??0);if(!t||!Number.isFinite(n))continue;const o=Number(t.delay??0)+n*e;a=Math.max(a,o-Number(r.currentTime??0))}var o;a>0&&await(o=a,new Promise(t=>setTimeout(t,o)))})(a.figure,((t,e)=>{const n=Number.parseFloat(t.dataset.chartEntrance??""),a=Number.isFinite(n)?n:e.entrance;return Math.min(Math.max(a,0),1)})(a.figure,e)),w=!1,!g&&e.replay||tn(a,!0)}var n},v=()=>{const t=gn(a.figure);if(!t||t===r)return;const n=It.timed("Building",a.figure,()=>Ie(a.figure,e,t));n&&((t=>{Ce(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${b}`)?.remove(),t.controls?.remove()})(a),ie(n,a.step,!0),a=n,r=t,m=null)},A=()=>{v();const t=a.plot.clientWidth;t&&t!==m&&It.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:m,type:g,values:w,series:y,seriesValues:M,names:v,annotations:A}=t;(({figure:t,rows:e,series:n},a)=>{const o=t.getAttribute("data-chart-table"),r=o&&Pe.includes(o)?o:a.table;"never"===r?t.removeAttribute("data-table"):t.setAttribute("data-table",r);const s=t.getAttribute("data-chart-summary");t.setAttribute("data-summary",s&&Pe.includes(s)?s:a.summary),t.toggleAttribute("data-long",e.length*n.filter(t=>!t.group).length>a.tablelimit)})(t,e);const C=getComputedStyle(t.figure);t.figure.toggleAttribute("data-series-range",!!C.getPropertyValue("--tablechart-series-color-end").trim()),t.figure.toggleAttribute("data-slice-range",!!C.getPropertyValue("--tablechart-slice-color-end").trim());const T=Number.parseFloat(t.figure.dataset.chartAspect??""),_=T>0?T:g.aspect??e.aspect,z="beside"===g.categories,U=t.axes&&!g.axes?t.axes:null,F=z?null:t.categories[0]?.parentElement;let V=null;if(U){a.style.margin="",F&&(F.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=g.segments?.(m)??[],r=t.stacked?m.flatMap(t=>Object.values(gt(t,y.length,g.running))):o.some(t=>"up"===t.kind||"down"===t.kind)?o.flatMap(t=>[t.from,t.to]):m.flatMap(t=>t.cells.slice(0,y.length).filter(t=>!t.missing).map(t=>t.value)),s=Math.min(0,-P(r.map(t=>-t))),c=Math.max(0,P(r)),l=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:i,chartScale:u}=t.figure.dataset,d=Qt(i??u);if(d&&d.length>2)V={min:d[0],max:d[d.length-1],step:0,ticks:d};else{const[t,e]=d??[s,c],a=Yt(e-t,Math.max((z?n/9:n*_/3)/l,2)),o=(t,e)=>d?t:Number(((e?Math.ceil:Math.floor)(t/a-1e-9*(e?1:-1))*a).toPrecision(12)),r=o(t,!1),i=o(e,!0);V={min:r,max:i,step:a,ticks:Xt(r,i,a)}}U.ticks.textContent="";const h=m.find(t=>!t.missing),f=P(V.ticks.map(t=>D(String(t))));for(const t of V.ticks){const n=B(k,U.ticks);n.dataset.value=String(t),n.dataset.place="none",h?.prefix&&(n.dataset.prefix=h.prefix),h?.suffix&&(n.dataset.suffix=h.suffix),Je(n,f,e.locale)}if(U.numbers){const t=Array.from(U.ticks.children);for(const e of t)delete e.dataset.place;tt(t),z?a.style.marginBottom=`${(t[0]?et(t[0]).height:0)+6}px`:(a.style.marginLeft=`${P([0,...t.map(t=>et(t).width)])+10}px`,F&&(F.style.marginLeft=a.style.marginLeft))}}const I=a.clientWidth;if(!I)return!1;const j=S/I,W=S*_;a.classList.add("is-placed");const G=!1===g.numbers?w.slice(0,1):[...M.flat(),...t.totals];for(const n of G)delete n.dataset.place,n.removeAttribute("data-left-out"),n.removeAttribute("data-cut");a.style.removeProperty("--_fit"),a.toggleAttribute("data-grouped",!!g.groups&&!t.stacked&&y.filter(t=>!t.chart&&!t.group).length>1),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const K=g.axes?t.axes:null;let Y=[];if(K){const n=Number.parseFloat(getComputedStyle(a).fontSize)||16,o=y.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),r=m.filter(t=>o.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:s,chartScaleY:c,chartScale:l}=t.figure.dataset,i=[Qt(s),Qt(c??l)];Y=o.map((t,e)=>((t,e,n)=>{if(n&&n.length>2)return{min:n[0],max:n[n.length-1],step:0,ticks:n};let a=n?.[0]??-P(t.map(t=>-t)),o=n?.[1]??P(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=Yt(o-a,e);return{min:a,max:o,step:r,ticks:Xt(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?W/j/(4*n):I/(9*n),4),i[e])),K.ticks.textContent="",Y.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=P(t.ticks.map(t=>D(String(t))));for(const o of t.ticks){const t=B(k,K.ticks);t.dataset.axis=n?"y":"x",t.dataset.value=String(o),a?.prefix&&(t.dataset.prefix=a.prefix),a?.suffix&&(t.dataset.suffix=a.suffix),Je(t,s,e.locale)}})}const X=K?Array.from(K.ticks.children):[];tt([...M.flat(),...t.totals,...v,...t.categories,...A.map(t=>t.badge),...K?.titles??[],...X]);const Z=(w[0]?et(w[0]).height:0)*j;!1===g.numbers&&w[0]&&(w[0].dataset.place="none");const Q=A[0]?.badge?et(A[0].badge).height*j:0,J=Math.max(W,Ke(t.figure,j,"--tablechart-min-height","200px")??0,g.minHeight?.({labelHeight:Z,nameHeight:Math.max(0,P(t.categories.map(t=>et(t).height)))*j,unit:j,rows:m.length,series:y.length,stacked:t.stacked,labels:Ge(t.figure,e,y.some(t=>t.chart))})??0),nt=t.stacked?m.map(t=>{const e=wt(t,y.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):m,at=(g.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?nt.map(t=>({...t,cells:[t.cells[0]]})):m),ot={labelHeight:Z,badgeHeight:Q,hasAnnotations:A.length>0,unit:j,series:y.length,focused:y.some(t=>t.focus),stacked:t.stacked},st=Math.max((ct=P,t.stacked?ct(m.map(t=>gt(t,y.length,g.running).top)):ct([...at.flatMap(t=>[t.from,t.to,t.value]),...m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value))])),0);var ct;const ut=at.some(t=>"up"===t.kind||"down"===t.kind)?at.flatMap(t=>[t.from,t.to]):t.stacked?m.map(t=>gt(t,y.length,g.running).bottom):m.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value)),dt=Math.min(-P(ut.map(t=>-t)),0),ht=y.flatMap((t,e)=>t.chart?[e]:[]),ft=m.some(t=>t.note)?Q+4*j:0,bt=Math.max(g.headroom?.(ot)??Z,ht.length?Ft.headroom?.(ot)??0:0)+ft,mt=2*j+(g.footroom?.(ot)??0)+(dt<0?Z+4*j:0),$t=J-bt-mt,pt=V?Math.max(V.max,st):1.02*st,yt=V?Math.min(V.min,dt):1.02*dt,Mt=A.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,vt=t=>{const e=Number.parseFloat(Mt?.getAttribute(t)??"");return Number.isFinite(e)?e:null},xt=vt("data-from")??vt("data-at"),kt=vt("data-to");let Nt=null;if(Mt&&(null!==xt||null!==kt)){const t=xt??0,e=kt??pt,a=null===kt?t:null===xt?e:(t+e)/2,o=Mt.getAttribute("data-size"),r=o?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===o||r||console.warn(`[${n}] data-size="${o}" is not a percentage, such as 30%. Using the default.`);const s=Math.min(Math.max(r?Number(r[1])/100:null===kt?.22:.3,.05),.8),c=at.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);g.breakable?dt<0?console.warn(`[${n}] A chart with values below zero cannot break its scale.`):t<0||e<=t||e>pt||0===t&&e===pt?console.warn(`[${n}] A break from ${t} to ${e} does not fit a scale that runs from 0 to ${st}.`):c.length?console.warn(`[${n}] A break from ${t} to ${e} would cut a step that floats. Keep it below or above the steps.`):Nt={lo:t,hi:e,gap:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const St=Nt?Nt.gap:null,At=(Nt&&Ke(t.figure,j,"--tablechart-break-gap",""))??13,Ct=J-mt,Ht=pt-yt||1;let Tt,Lt,Ot=t=>Ct-(t-yt)/Ht*$t;if(Nt){const{lo:t,hi:e,gap:n,share:a}=Nt,o=$t*a,r=($t-o-At)/(t+(pt-e)),s=o/(e-t);Ot=a=>a<=t?Ct-a*r:a<=n?Ct-t*r-(a-t)*s:a<=e?Ct-t*r-(a-t)*s-At:Ct-t*r-o-At-(a-e)*r}let _t=[];if(K){const t=6*j,[e,n]=K.titles,a=t=>t?et(t).width*j:0,o=t=>t?et(t).height*j:0,r=X.filter(t=>"x"===t.dataset.axis),s=X.filter(t=>"y"===t.dataset.axis),c=o(X[0]),l=a(n)+P([0,...s.map(a)])+2*t,i=c/2;Lt=[l,i,S-l-P([0,...r.map(a)])/2,J-i-o(e)-c-2*t];const[u,d,h,f]=Lt,[b,m]=Y,$=t=>u+(t-b.min)/(b.max-b.min||1)*h,p=t=>d+f-(t-m.min)/(m.max-m.min||1)*f;Tt=$,Ot=p;const g=t=>a(r.find(e=>Number(e.dataset.value)===t));_t=[Jt(b,e=>e.every((n,a)=>!a||$(n)-$(e[a-1])>(g(n)+g(e[a-1]))/2+t)).ticks,Jt(m,e=>e.every((n,a)=>!a||p(e[a-1])-p(n)>c+t/2)).ticks];for(const w of X){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,a=_t[n].includes(e);w.dataset.place=a?n?"before":"below":"none",a&&E(w,n?u-t:$(e),n?p(e):d+f+t,S,J)}e&&E(e,u+h/2,J-o(e),S,J),n&&E(n,0,d+f/2,S,J)}const Bt=v.length?P(v.map(t=>et(t).width))*j+12*j:0,Et=t.categories[0]?.parentElement;Et&&(Et.style.paddingRight=Bt?Bt/S*100+"%":"");const zt=(S-Bt)/m.length,Ut=t=>t>=0&&t<m.length?t:null;t.rowAt=g.centre?null:"beside"===g.categories?(t,e)=>Ut(Math.floor(e*j/(J/m.length))):t=>Ut(Math.floor(t*j/zt));const Rt=zt/S*100,qt=100/m.length;if(t.rowBox="beside"===g.categories?t=>[0,t*qt,100,qt]:t=>[t*Rt,0,Rt,100],r.setAttribute("viewBox",`0 0 1000 ${L(J)}`),r.textContent="",Lt&&Tt){const[n,a,o,s]=Lt,[c,l]=_t,i=Tt;Fe(t.figure,"data-chart-grid",e.grid)&&r.appendChild(O("path",{class:N,d:[...c.map(t=>`M${L(i(t))},${L(a)}V${L(a+s)}`),...l.map(t=>`M${L(n)},${L(Ot(t))}H${L(n+o)}`)].join("")})),r.appendChild(O("path",{class:x,d:[`M${L(n)},${L(a)}V${L(a+s)}H${L(n+o)}`,...c.map(t=>`M${L(i(t))},${L(a+s)}v${L(4*j)}`),...l.map(t=>`M${L(n)},${L(Ot(t))}h${L(-4*j)}`)].join("")}))}t.checks=[];const It={rows:m,segments:at,cx:t=>(t+.5)*zt,y:Ot,x:Tt,frame:Lt,length:(e,n)=>Ke(t.figure,j,e,n),barWidth:Math.min(zt*e.barfill,Ye(t.figure,j)),barMax:Ye(t.figure,j),height:J,unit:j,labelHeight:Z,badgeHeight:Q,after:m.length,note:0,labels:Ge(t.figure,e,ht.length>0),insideAlign:We(t.figure),breakAt:St,squeeze:Nt,breakGap:At,domain:V?[V.min,V.max]:null,stacked:t.stacked,shape:Re(t.figure,e),pick:Ze(t.figure,e),totals:t.totals,svg:r,plot:a,values:w,series:y,own:y.map((t,e)=>e),seriesValues:M,names:v,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[],lineHoles:[]};a.style.setProperty("--count",String(Math.max(1,...m.map(t=>t.slot+1))));const jt=t=>{const e=e=>({...e,...e.cells[t]??e.cells[0]});return{rows:m.map(e),segments:at.map(t=>{const n=e(t);return"bar"===t.kind?{...n,to:n.value}:n}),values:M[t]}};if(ht.length){const t=y.flatMap((t,e)=>t.chart?[]:[e]);g.draw({...It,own:t,...1===t.length&&jt(t[0])}),Ft.draw({...It,own:ht})}else g.draw(It);It.rowAt&&(t.rowAt=It.rowAt),t.pointOf=It.pointOf??null;const Pt=Number(a.style.getPropertyValue("--count"))||m.length;for(const n of t.figure.querySelectorAll(`.${f}`))n.style.setProperty("--i",String(Math.min(m[m.length-1].slot,Pt-1)));if(!t.stacked&&!a.hasAttribute("data-grouped"))for(const n of M)lt(n,j,S),it(n,j,S,J);if(U&&V){const n=6*j,a=z&&It.x?It.x:Ot,o=Array.from(U.ticks.children),s=t=>et(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=Jt(V,t=>t.every((e,o)=>!o||(z?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*j+n:a(t[o-1])-a(e)>s(e).height*j+n/2))).ticks.filter(t=>!Nt||t<=Nt.lo||t>=Nt.hi);for(const t of o){const e=Number(t.dataset.value),o=U.numbers&&c.includes(e);t.dataset.place=o?z?"below":"before":"none",o&&E(t,z?a(e):-n,z?J+n:a(e),S,J)}const l=S-Bt;Fe(t.figure,"data-chart-grid",e.grid)&&r.prepend(O("path",{class:N,d:c.map(t=>z?`M${L(a(t))},0V${L(J)}`:`M0,${L(a(t))}H${L(l)}`).join("")})),U.numbers&&r.appendChild(O("path",{class:x,d:[z?`M${L(a(V.min))},${L(J)}H${L(a(V.max))}`:`M0,${L(a(V.max))}V${L(a(V.min))}`,...c.map(t=>z?`M${L(a(t))},${L(J)}v${L(4*j)}`:`M0,${L(a(t))}h${L(-4*j)}`)].join("")}))}for(const[n,o]of A.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series;o.type.draw(o.spec,o.badge,{...It,...t.stacked&&{rows:nt,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&jt(e),after:t.plan?o.after:Math.min(o.after,Number(a.style.getPropertyValue("--count"))||o.after),note:n+1})}(t=>{const e=t.plan;if(!e)return;const n=e.rows.length-1,a=t=>e.series.map((n,a)=>e.cells[t]?.[a]?.step??n.step??e.rows[t]?.step??null),r=t=>{const e=a(t);return e.some(t=>null===t)?null:Math.min(...e)},s=new Set(t.totals),c=Boolean(t.type.axes),l=(t,e,n,a)=>{c&&"--i"===n||t.style.setProperty(n,String(a)),t.style.removeProperty("--d"),null===e?t.style.removeProperty("--step"):t.style.setProperty("--step",String(e))};for(const o of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(o.closest("table, .tablechart-controls")||o.hasAttribute("data-from"))continue;const t=Number(o.dataset.note);if(t>0){const n=e.notes[t-1];n&&l(o,n.step,"--after",n.after);continue}const c=o.dataset.row?Number(o.dataset.row)-1:n;if(o.classList.contains("tablechart-connector")){const t=e.rows[c-1],n=e.rows[c];if(t&&n){const e=(t.step??-1)>(n.step??-1);l(o,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(s.has(o)){const t=a(c).filter(t=>null!==t);l(o,t.length?Math.max(...t):null,"--i",e.rows[c]?.slot??0);continue}if(o.hasAttribute("data-stack")){l(o,r(c),"--i",e.rows[c]?.slot??0);continue}const i=o.dataset.series?Number(o.dataset.series)-1:0,u=o.dataset.series?e.series[i]:void 0;if(o.classList.contains("tablechart-piece")){const t=a(c)[i]??null,n=e.cells[c]?.[i];l(o,t===r(c)?null:t,"--i",n&&null!==n.step?n.slot:c);continue}if("legend"===o.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(o,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[c]?.[i];d&&null!==d.step?l(o,d.step,"--i",d.slot):u&&null!==u.step?l(o,u.step,"--i",c):e.rows[c]&&l(o,e.rows[c].step,"--i",e.rows[c].slot)}const i=t.figure.querySelector(`.${p}`);if(i){const t=[...e.rows,...e.cells.flat()].map(t=>t.step??-1),n=Math.max(-1,...t);n<0?l(i,null,"--i",0):l(i,n,"--i",t.filter(t=>t===n).length)}const d=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),h=e.series.some(t=>null!==t.step)?e.rows.length:1;c||t.plot.style.setProperty("--count",String(Math.max(h,...d)));const f=t.figure.querySelectorAll(`.${o}`),b=f[f.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&f.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${u}`));if(m.length){const e=t=>t.style.getPropertyValue("--step")||"none",n=t=>Number(t.style.getPropertyValue("--share")||0),a=m.length,o=Math.max(0,m.findIndex((t,n)=>e(t)!==e(m[(n-1+a)%a]))),r=[];for(let t=0;t<a;t++){const n=m[(o+t)%a],s=r[r.length-1];s&&e(s[0])===e(n)?s.push(n):r.push([n])}const s=new Map;for(const t of r){const e=t.reduce((t,e)=>t+n(e),0);let a=0;for(const o of t)s.set(o.dataset.row??"",H(a,n(o),e)),a+=n(o)}for(const c of t.figure.querySelectorAll("[data-row]")){const t=s.get(c.dataset.row??"");t&&c.style.getPropertyValue("--start")&&(c.style.setProperty("--start",t.start.toFixed(4)),c.style.setProperty("--span",t.span.toFixed(4)),c.classList.contains("tablechart-slice")&&c.style.setProperty("--ease",t.easing))}}le(t)})(t);for(const n of t.figure.querySelectorAll(`.${b}`)){const e=Array.from(n.children);if(t.plan)for(const t of e)t.style.getPropertyValue("--step")||t.style.setProperty("--i","0");const a=e.map(t=>Number.parseFloat(t.style.getPropertyValue("--step")));n.style.setProperty("--i",String(Math.min(...e.map(t=>Number(t.style.getPropertyValue("--i"))||0)))),a.length&&a.every(Number.isFinite)?n.style.setProperty("--step",String(Math.min(...a))):n.style.removeProperty("--step")}const Dt=t.categories[0]?.parentElement;if(Dt&&"beside"!==g.categories&&!g.centre){Dt.style.height=`${Dt.offsetHeight}px`,Dt.removeAttribute("data-thinned");for(const e of t.categories)e.removeAttribute("data-left-out"),e.removeAttribute("data-edge");const n=t.categories.filter(t=>null!==t.offsetParent);if(!rt(Dt,n,t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit")&&n.length>1){const t=getComputedStyle(Dt),e=(Dt.clientWidth-Number.parseFloat(t.paddingLeft)-Number.parseFloat(t.paddingRight))/m.length;Dt.style.setProperty("--_name-fit","1"),Dt.setAttribute("data-thinned","");const a=P(n.map(t=>t.offsetWidth)),o=8,r=Math.max(Math.ceil((a+o)/e),Math.ceil((1.5*a+o)/e-.5),1);n.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")});const s=n.filter(t=>!t.hasAttribute("data-left-out")),c=s[0],l=s.at(-1),i=Dt.getBoundingClientRect(),u=[c,l].map(t=>t?.getBoundingClientRect());if(c&&u[0]&&u[0].left<i.left&&c.setAttribute("data-edge","start"),l&&l!==c&&u[1]&&u[1].right>i.right-Number.parseFloat(t.paddingRight)){l.setAttribute("data-edge","end");const t=s.at(-2);t&&t.getBoundingClientRect().right+o>l.getBoundingClientRect().left&&l.setAttribute("data-left-out","")}}const a=(g===Ft||g===Vt)&&Fe(t.figure,"data-chart-ticks",e.ticks);if(Dt.toggleAttribute("data-ticks",a),Dt.style.removeProperty("--_tick-reach"),a){const e=J-Number(r.querySelector(".tablechart-rule")?.getAttribute("y1")??J);e>0&&e<10*j&&Dt.style.setProperty("--_tick-reach",`${L(e/j)}px`);const n=Dt.getBoundingClientRect(),a=n.width/(Dt.offsetWidth||1),o=getComputedStyle(Dt),s=Number.parseFloat(o.paddingLeft),c=(Dt.clientWidth-s-Number.parseFloat(o.paddingRight))/m.length;t.categories.forEach((t,e)=>{if(t.hasAttribute("data-left-out"))t.style.removeProperty("--_tick");else{const o=(t.getBoundingClientRect().left-n.left)/a-Dt.clientLeft;t.style.setProperty("--_tick",`${L(s+(e+.5)*c-o)}px`)}})}Dt.style.height=""}const Wt=A.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*j,n=t.offsetHeight*j,a=Number.parseFloat(t.style.left)/100*S,o=Number.parseFloat(t.style.top)/100*J,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*j;return[O("rect",{class:$,"data-for":"badge","data-note":t.dataset.note??"",x:a-e/2,y:o-n/2,width:e,height:n,rx:null===s?c:e*s,ry:null===s?c:n*s,style:["--after","--step"].map(e=>t.style.getPropertyValue(e)&&`${e}:${t.style.getPropertyValue(e)}`).filter(Boolean).join("; ")})]}),Gt=r.querySelector(`.${N}`),Kt=Array.from(r.querySelectorAll(`.${c}`)),Zt=[...Gt?[Gt]:[],...r.querySelectorAll(`:scope > .${l}`)],te=((t,e)=>{const n=t.getBoundingClientRect(),a=S/n.width,o=getComputedStyle(t),r=Number.parseFloat(o.lineHeight)/Number.parseFloat(o.fontSize)||1.2;return t=>{if("none"===t.dataset.place||t.hidden||t.hasAttribute("data-left-out"))return[];const o=t.getBoundingClientRect(),s=o.height*a/r,c=Array.from(t.style).filter(t=>t.startsWith("--")).map(e=>`${e}:${t.style.getPropertyValue(e)}`);return o.width?[O("rect",{class:$,"data-for":"text",x:(o.left-n.left)*a-3*e,y:(o.top-n.top)*a+(o.height*a-s)/2-e,width:o.width*a+6*e,height:s+2*e,style:c.join("; ")})]:[]}})(a,j),ee="grow"===t.figure.getAttribute("data-animate"),ne=M.flat().filter(t=>t.hasAttribute("data-cut")).flatMap(te),ae=[...ht.flatMap(t=>M[t].flatMap(te)),...ee?ne:[]];if(Zt.length||Kt.length){const e=[...M.flat(),...t.totals,..."beside"===g.categories?t.categories:[]].flatMap(te),n=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Kt)Ee(t,[...e,...Wt].map(n));if(Zt.length&&t.plan)q(r,e,S,J,Zt);else for(const t of Zt){const a=[...e,...Wt],o=ze(t);t.setAttribute("d",o.map(([t,e,o,r])=>Be(t,e,o,r,a.map(n))).join(""));for(const e of a){const a=Ue(o,n(e)),r="badge"===e.dataset.for?"badge":"";a&&t.after(O("path",{class:t.getAttribute("class")??"tablechart-grid","data-gap":r,d:a,style:e.getAttribute("style")??""}))}}}if(R(r,Wt,S,J,Array.from(r.querySelectorAll(`.${s}, .${i}`))),!ee&&(It.lineHoles.length||ne.length)){const t=Array.from(r.querySelectorAll(`.${d}`)).map(t=>{const e=O("g",{});return t.before(e),e.append(t),e});R(r,[...It.lineHoles,...ne],S,J,[...t,...r.querySelectorAll(`.${h}`)])}const oe=[c,l,s,i,...t.plan?[]:[N]];q(r,[...Wt,...ae],S,J,void 0,oe.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||nn(r);const re=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(g.columns?[t.categories]:[...M,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||g.centre&&m[Number(t.dataset.row)-1]?.isTotal)(e)&&!re(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>re(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),se(t.figure),!0})(a,e))&&(It.enabled&&!m&&((t=>{const e=oe(t),a=Array.from(t.querySelectorAll("table thead tr:first-child > *")).map(t=>(t.textContent??"").trim()),o=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),r=[[".tablechart-series","Line",t=>getComputedStyle(t).stroke],[".tablechart-slice","Slice",t=>getComputedStyle(t).stroke],[".tablechart-bar, .tablechart-piece","Bar",t=>getComputedStyle(t).fill]],s=new Map;for(const[n,c,l]of r){const r=Array.from(t.querySelectorAll(`${n}:not([data-muted])`));for(const t of r){const n=l(t),[i,u,d,h]=ee(n),f=[i,u,d].map((t,n)=>t*h+e[n]*(1-h)),b=ae(f,e);if(b>=3)continue;const m=t.getAttribute("data-series"),$=o[Number(t.getAttribute("data-row")??0)-1]??"",p="Slice"===c?"":m?a[Number(m)]:"",g=`${c}|${p}|${n}`,w=s.get(g)??{kind:c,column:p,rows:new Set,all:0,contrast:b};w.rows.add($),w.all=r.filter(t=>t.getAttribute("data-series")===m).length,s.set(g,w)}}for(const{kind:c,column:l,rows:i,all:u,contrast:d}of s.values()){const e=Array.from(i).filter(Boolean).map(t=>`"${t}"`),a=e.join(", "),o=e.length>1,r="Line"===c?l?`Line "${l}" has`:"The line has":"Slice"===c?`${o?"Slices":"Slice"} ${a} ${o?"have":"has"}`:i.size>=u||!a?`The bars${l?` of column "${l}"`:""} have`:`${o?"Bars":"Bar"} ${a}${l?` in column "${l}"`:""} ${o?"have":"has"}`;console.warn(`[${n}] ${r} a contrast of ${(Math.floor(100*d)/100).toFixed(2)}:1 with the background. It needs at least 3:1 (WCAG 1.4.11).`,t)}})(a.figure),(t=>{const e=()=>{const e=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),a=new Map;for(const n of t.querySelectorAll(".tablechart-value[data-place='inside'], .tablechart-value[data-place='middle']")){if(n.hasAttribute("data-left-out")||n.hidden)continue;const o=n.dataset.row,r=re(t,n);if(!r)continue;const s=getComputedStyle(n),c=getComputedStyle(r).fill,l=ee(s.color),i=ee(c),u=ae(l,i),d=Number.parseFloat(s.fontSize),h=d>=24||d>=18.66&&Number(s.fontWeight)>=700?3:4.5;if(u>=h)continue;const f=`${s.color}|${c}`,b=a.get(f)??{names:[],contrast:u,needed:h};b.names.push(`"${n.textContent?.trim()}" (${e[Number(o)-1]??""})`),a.set(f,b)}for(const{names:o,contrast:r,needed:s}of a.values())console.warn(`[${n}] ${o.length>1?"Numbers":"Number"} ${o.join(", ")} inside ${o.length>1?"their bars have":"its bar has"} a contrast of ${(Math.floor(100*r)/100).toFixed(2)}:1 with the bar. Text needs at least ${s}:1 (WCAG 1.4.3).`,t)},a=()=>setTimeout(e,3e3);if(t.classList.contains("is-shown"))return void a();const o=new MutationObserver(()=>{t.classList.contains("is-shown")&&(o.disconnect(),a())});o.observe(t,{attributes:!0,attributeFilter:["class"]})})(a.figure)),m=t,y())};let C=!1;const T=new ResizeObserver(()=>{C||(C=!0,requestAnimationFrame(()=>{C=!1,A()}))}),_=new IntersectionObserver(t=>{for(const e of t)g=e.isIntersecting,y()},{threshold:e.threshold}),z=()=>{a.figure.classList.add(M),tn(a,!0),an(a.svg),a.figure.offsetWidth},U=()=>a.figure.classList.remove(M),F=()=>{m=null,A()},V={relabel:()=>Qe(a,e),refresh:F};v(),A(),T.observe(a.figure),_.observe(a.figure),window.addEventListener("beforeprint",z),window.addEventListener("afterprint",U),(t=>{mn.add(t),$n||($n=new MutationObserver(()=>{for(const t of mn)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of mn)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(V);const I={figure:a.figure,refresh:F,next:()=>ie(a,a.step+1),previous:()=>ie(a,a.step-1),stepTo:t=>ie(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){T.disconnect(),_.disconnect(),window.removeEventListener("beforeprint",z),window.removeEventListener("afterprint",U),(t=>{mn.delete(t),!mn.size&&$n&&($n.disconnect(),$n=null)})(V),Ce(a),a.figure.tablechart===I&&delete a.figure.tablechart}};return a.figure.tablechart=I,I})(a,e)):null},vn=!1,xn=()=>{vn||"function"!=typeof matchMedia||(vn=!0,matchMedia("(prefers-color-scheme: dark)").addEventListener("change",()=>{for(const t of document.querySelectorAll(`[${fn}]`))se(t)}))},kn=e({GRID_CLASS:()=>N,LEGEND_CLASS:()=>b,LIBRARY_NAME:()=>n,NAME_CLASS:()=>f,POINT_CLASS:()=>m,QUADRANT_CLASS:()=>l,VIEWBOX_WIDTH:()=>S,avoidCollisions:()=>Q,boxOf:()=>ct,decimalsIn:()=>D,htmlEl:()=>B,largest:()=>P,markerEl:()=>Ht,overlaps:()=>Z,placeAt:()=>E,readSeries:()=>Gt,readTable:()=>Dt,short:()=>L,sizeOf:()=>et,splitSign:()=>W,svgEl:()=>O});window.Tablechart={init:async(t={},e=document)=>{const n={...A,...t};n.debug&&(It.enabled=!0);const a=(await yn(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Mn(t,n)).filter(t=>null!==t);return It.log(`Made ${a.length} chart(s).`),{charts:a,refresh:()=>{for(const t of a)t.refresh()},destroy:()=>{for(const t of a)t.destroy()}}},create:async(t,e={})=>{if(t.tablechart)return t.tablechart;const n={...A,...e};n.debug&&(It.enabled=!0);const[a]=await yn([t],n);return a?Mn(a,n):null},defaultConfig:A,addType:(t,e)=>{He[t]=e,Object.assign(Te,e.annotations),Le.splice(0,1/0,...Object.keys(Te))},kit:kn}}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@martinomagnifico/tablechart",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Simple charts from an HTML or Markdown table: column, bar, line, area, waterfall, donut and scatter plot. Accessibility first.",
5
5
  "type": "module",
6
6
  "sideEffects": [