@martinomagnifico/tablechart 1.2.5 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(){var t=Object.defineProperty,e=(e,n)=>{let a={};for(var o in e)t(a,o,{get:e[o],enumerable:!0});return n||t(a,Symbol.toStringTag,{value:"Module"}),a},n="tablechart",a="tablechart-value",o="tablechart-bar",r="tablechart-rule",s="tablechart-line",c="tablechart-reference",l="tablechart-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",M="is-shown",y="is-printing",v="is-at-once",x="is-built",k="tablechart-axis",S="tablechart-tick",N="tablechart-grid",A=1e3,C={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,lines:null,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)",T=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?H:"linear"}),L=(t,e)=>`${t}:${e}`,O=t=>Math.round(100*t)/100,_=(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?O(t):t))}return n},B=(t,e)=>[t,...e.classes].join(" "),z=(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+"%"},R=0,U=0,F=0,q=t=>{let e=t.querySelector(":scope > defs");return e||(e=_("defs"),t.prepend(e)),e},P=t=>{if("circle"===t.tagName){const[e,n,a]=["cx","cy","r"].map(e=>Number(t.getAttribute(e))||0);return`M${O(e-a)},${O(n)}a${O(a)},${O(a)} 0 1 0 ${O(2*a)},0a${O(a)},${O(a)} 0 1 0 ${O(-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${O(c)},${O(l)} 0 0 1 ${O(t)},${O(e)}`:"";return`M${O(e+c)},${O(n)}h${O(a-2*c)}${i(c,l)}v${O(o-2*l)}${i(-c,l)}h${O(2*c-a)}${i(-c,-l)}v${O(2*l-o)}${i(c,-l)}z`},V=(t,e,n,a,o)=>{if(!e.length||!o.length)return;const r="tablechart-clip-"+ ++U,s=_("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M${-n},${-a}h${3*n}v${3*a}h${3*-n}z`;s.appendChild(_("path",{d:c+e.map(P).join(""),"clip-rule":"evenodd"})),q(t).appendChild(s);for(const l of o)l.setAttribute("clip-path",`url(#${r})`)},I=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++R,c=_("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(_("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=q(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(_("g",{mask:`url(#${s})`}))),i.appendChild(u)))},W=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-"+ ++W,h=_("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(_("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(_("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const r=[L("--after",a[w.row-1]?.slot??0),w.part].filter(Boolean).join("; ");for(const a of[e,o])s.appendChild(_("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}`)),$=_("g",{mask:`url(#${d})`});for(const o of Array.from(s.childNodes))m.includes(o)||$.appendChild(o);const p=_("defs");p.appendChild(h),s.prepend(p,$)}},D=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},G=t=>(t.split(/[.,]/)[1]||"").length,K=(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("")]},Y=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),Z=(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},J=(t,e,a,o,r="%")=>{const s=t?.textContent||"",c=Y(s),l=r?.5:.5*10**-G(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:Z,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,M=4*l,y=r(m),v=r($),x=Math.min(c(p.value),c(g.value))-u-M-.9*d,k=t=>c(t)-u-M,S=`M ${y} ${k(p.value)} L ${y} ${x} L ${v} ${x} L ${v} ${k(g.value)-w}`,N=(k(p.value)-x+Math.abs(v-y)+(k(g.value)-w-x))/l+1;f.appendChild(_("path",{class:s,"data-note":a.note,d:S,style:`--len:${N.toFixed(1)}; ${L("--after",b)}`}));const C=k(g.value);var H;f.appendChild(_("polygon",{class:i,"data-note":a.note,points:`${v},${C} ${v-.45*w},${C-w} ${v+.45*w},${C-w}`,style:L("--after",b)})),e&&(E(e,(y+v)/2,x,A,h),e.style.setProperty("--after",String(b))),J(e,(H=p.value,(g.value-H)/Math.abs(H)*100),`${p.value} to ${g.value}`,a)}},Q=(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],tt=(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=>Q(t,e)));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},et=new WeakMap,nt=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>et.set(t,n[e]))},at=t=>et.get(t)??{width:t.offsetWidth,height:t.offsetHeight},ot=(t,e,n)=>t.some(t=>at(t).width*n>e-6*n),rt=(t,e,n)=>e>=at(t).height*n*1.6,st=(t,e,n)=>e>=at(t).width*n*1.5,ct=(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},lt=(t,e)=>{t.sort((t,e)=>t.y-e.y);const n=[],a=t=>t.sum/t.items.length-(t.items.length-1)*e/2;for(const o of t){let t={items:[o],sum:o.y};for(let o=n.at(-1);o&&a(o)+o.items.length*e>a(t);o=n.at(-1))n.pop(),t={items:[...o.items,...t.items],sum:o.sum+t.sum};n.push(t)}for(const o of n)o.items.forEach((t,n)=>t.y=a(o)+n*e);return t},it={outside:[.5,1],below:[.5,0],after:[0,.5],before:[1,.5]},ut=(t,e,n,a,o=[.5,.5])=>{const[r,s]=it[t.dataset.place??""]??o,{width:c,height:l}=at(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]},dt=(t,e,n)=>{for(const a of t){if("none"===a.dataset.place||!a.style.left)continue;const[t]=it[a.dataset.place??""]??[.5,.5],o=at(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+"%")}},ht=(t,e,n,a)=>{const o=t.filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out")),r=ft(o,e,n,a);o.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")})},ft=(t,e,n,a)=>{if(t.length<2)return 1;const o=t.map(t=>ut(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},bt={create(t,e){if(!t.textContent?.trim())return null;const n=Z(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(_("line",{class:c,"data-kind":"note","data-note":a.note,x1:$,x2:$,y1:0,y2:p,style:L("--after",d)}),u.querySelector(`:scope > .${m}`)),!e)return;const g=at(e).width*i,w=at(e).height*i,M=4*i,y=h.flat().flatMap(t=>!t.style.left||"none"===t.dataset.place||t.hasAttribute("data-left-out")?[]:[{label:t,box:ut(t,i,A,l)}]),v=[0,w+M/2].flatMap(t=>[[$-g/2,t,g,w],[$+M,t,g,w],[$-M-g,t,g,w]]),[x]=tt([v],[...a.taken,...y.map(t=>t.box)],[0,0,A,l]),k=v[x??0];if(a.taken.push(k),E(e,k[0]+g/2,k[1]+w/2,A,l),e.style.setProperty("--after",String(d)),null===x)for(const n of y)Q(n.box,k)&&n.label.setAttribute("data-left-out","")}},mt=(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},$t={create(t,e){if(!t.textContent?.trim())return null;const n=Z(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=>Y(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=mt($,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=mt($,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[M,y,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):A,l?i:s(0)];if(d.insertBefore(_("line",{class:c,"data-note":a.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...p?{x1:M,x2:v,y1:g,y2:g}:{x1:g,x2:g,y1:y,y2:x},style:L("--after",h)}),d.querySelector(`:scope > .${m}`)),e){const t=at(e).width*u,n=at(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]]:[y,y+n,y+2*n].flatMap(e=>[[g-t/2,e,t,n],[g+o,e,t,n],[g-o-t,e,t,n]]),[s]=tt([r],a.taken,[0,0,A,i]),c=r[s??0];a.taken.push(c),E(e,c[0]+t/2,c[1]+n/2,A,i),e.style.setProperty("--after",String(h)),"mean"!==$&&"median"!==$||J(e,w,`the ${$}`,a,"")}}},pt={create:Z,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),M=r(b.value)-$,y=o(a.length-1),v=r(m.value)-$,x=0;a.forEach((t,e)=>{const n=y===w?0:(o(e)-w)/(y-w),a=M+n*(v-M)-(r(t.value)-$);a>x&&(x=a)}),M-=x,v-=x;const k=y-w,S=v-M,N=Math.hypot(k,S)||1,C=k/N,H=S/N;w-=C*p,M-=H*p,y+=C*p,v+=H*p;const T=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(y-w)*T,n=M+(v-M)*T,s=at(e).width*c/2,i=n+at(e).height*c/2+8*c;let u=0;a.forEach((e,n)=>{const a=(h[n]?at(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)}),M-=u,v-=u}const O=y-C*g,B=v-H*g,z=Math.hypot(O-w,B-M)/c+1;d.appendChild(_("line",{class:s,"data-note":n.note,x1:w,y1:M,x2:O,y2:B,style:`--len:${z.toFixed(1)}; ${L("--after",f)}`}));const R=-H,U=C,F=.42*g;d.appendChild(_("polygon",{class:i,"data-note":n.note,points:[`${y},${v}`,`${O+R*F},${B+U*F}`,`${O-R*F},${B-U*F}`].join(" "),style:L("--after",f)})),e&&(E(e,w+(y-w)*T,M+(v-M)*T,A,u),e.style.setProperty("--after",String(f)));const q=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(q)&&q>0&&J(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,q),`${b.value} to ${m.value} over ${q} years`,n)}},gt=(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}},wt=(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}); ${L("--i",e.slot)}`}},Mt=(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}})},yt=(t,e,n=!1)=>{const a=Mt(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},vt=(t,e)=>{const{top:n,bottom:a}=yt(t,e);return n+a},xt=(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})`)},kt=(t,e)=>t.barRadius?{"data-end":e}:{},St=(t,e)=>t.some((n,a)=>a!==e&&!n.cell.missing&&n.to!==n.from&&n.from===t[e].to),Nt=(t,e,n,a={},r="")=>{const s={class:B(o,e),"data-kind":"bar","data-row":n+1,...a},c=L("--i",e.slot)+(r?`; transform-origin: ${r}`:""),l=_("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(_("rect",{...s,...r,class:B("tablechart-piece",e),"data-row":n+1,...wt(t,e,o)}))}},At={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(D(l.map(t=>at(t).width*a)),0),f=Math.min(h+10*a,420);l[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/A*100).toFixed(2)}%`);const b=A-4*a,m=t.stacked?Math.max(D(t.rows.map(e=>yt(e,t.series.length).top)),0)||1:Math.max(D(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(D(t.rows.map(e=>-yt(e,t.series.length).bottom)),0):Math.max(D(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,M=(e,n)=>((t,e,n,a,o)=>{if(!a)return t/e*n;const{lo:r,hi:s,gap:c,share:l}=a,i=n*l,u=(n-i-o)/(r+(e-s)),d=i/(s-r);return t<=r?t*u:t<=c?r*u+(t-r)*d:t<=s?r*u+(t-r)*d+o:r*u+i+o+(t-s)*u})(Math.abs(e),w,n,t.squeeze,t.breakGap),y=n/e.length,v=t=>(t+.5)*y,x=Math.min(y*i.barfill,u),k=gt(y,t.series.length,u),S=c[0]??t.totals[0],N=S?at(S).height*a*.56:0,C=Math.max(((d&&!t.stacked?k.size:x)-N)/2,5*a),H=t=>at(t).width*a,T=t=>t.length?D(t.map(H))+C+4*a:0,O=(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:O(e,n)}))),R=e=>{const n=yt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let U=t.stacked?T(t.totals.filter((t,e)=>!R(e))):d?T(z.filter(t=>t.value>=0).map(t=>t.label)):0,F=t.stacked?T(t.totals.filter((t,e)=>R(e))):d?T(z.filter(t=>t.value<0).map(t=>t.label)):0;const q=(e,n)=>"inside"===t.labels&&st(e,n,a),P=d&&!t.stacked&&"inside"===t.labels&&!!S&&at(S).height*a<=k.size;if(P&&(U=F=0),P||!d&&!t.stacked){const t=d?z.filter(({label:t})=>void 0===t.dataset.missing):e.map((t,e)=>({label:c[e],value:t.value}));for(let e=0;e<3;e++){const e=b-f-U-F,n=t.filter(({label:t,value:n})=>!q(t,M(n,e))),a=T(n.filter(({value:t})=>t>=0).map(({label:t})=>t)),o=T(n.filter(({value:t})=>t<0).map(({label:t})=>t));if(a<=U&&o<=F)break;U=Math.max(U,a),F=Math.max(F,o)}}const V=b-f-U-F,I=f+F+M(g,V),W=t=>t<0?I-M(t,V):I+M(t,V);if(t.squeeze&&(t.breakX=W(t.squeeze.gap)),t.x=W,t.stacked){const e=t.length("--tablechart-stack-gap","1px")??a;return t.rows.forEach((o,r)=>{const s=yt(o,t.series.length),c=Nt(t,o,r,{"data-grow":"right"},s.bottom<0?I-W(s.bottom)+"px center":""),i=v(r)-x/2,u=Mt(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(W(o),W(s)),b=Math.max(W(o),W(s)),m=St(u,d)?Math.min(e,(b-f)/2):0,[$,p]=W(s)>W(o)?[f,b-m]:[f+m,b];c(d,{x:$,y:i,width:Math.max(p-$,1),height:x,...s<o&&{"data-grow":"left"},...!St(u,d)&&kt(t,s<o?"left":"right")}),h.dataset.place="inside",h.toggleAttribute("data-left-out",!st(h,b-f,a)||at(h).height*a>x),xt(h,t,d),E(h,(f+b)/2,v(r),A,n)});const d=t.totals[r];d&&(d.dataset.place=R(r)?"before":"after",E(d,R(r)?W(s.bottom)-C:W(s.top)+C,v(r),A,n));const h=l[r];h&&E(h,f-8*a,v(r),A,n)}),void s.appendChild(_("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=ct(t.plot,e,t=>({size:at(t).height*a,room:k.size+.5*k.gap}),"--_fit");return t.rows.forEach((e,r)=>{t.series.forEach((l,i)=>{const u=e.cells[i]??e.cells[0],d=t.seriesValues[i][r];if(u.missing)return void(d.dataset.place="none");const h=W(u.value),f=u.value<0,b=v(r)+k.offset(i),m=Math.max(Math.abs(h-I),1);0!==u.value&&s.appendChild(_("rect",{class:B(o,e),"data-kind":"bar","data-row":r+1,"data-grow":f?"left":"right",x:f?I-m:I,y:b,width:m,height:k.size,...kt(t,f?"left":"right"),...wt(t,e,i)}));const $=P&&q(d,Math.abs(h-I)),p=Math.max(Math.min(C,Math.abs(h-I)-H(d)-6*a),6*a),g=f?1:-1;d.dataset.place=$?"inside":f?"before":"after",d.toggleAttribute("data-left-out",!c),$&&xt(d,t,i),E(d,$?"center"===t.insideAlign?(I+h)/2:"start"===t.insideAlign?I-g*(p+H(d)/2):h+g*(p+H(d)/2):f?h-C:h+C,b+k.size/2,A,n)});const i=l[r];i&&E(i,f-8*a,v(r),A,n)}),void s.appendChild(_("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}const j=e.map((t,e)=>q(c[e],Math.abs(W(t.value)-I)));e.forEach((e,r)=>{const i=W(e.value),u=v(r),d=e.value<0,h=Math.abs(i-I),b=Math.max(h,1);0!==e.value&&s.appendChild(_("rect",{class:B(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,...kt(t,d?"left":"right"),style:L("--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=j[r]?"inside":d?"before":"after",m.dataset.kind=e.kind,E(m,j[r]?"center"===t.insideAlign?(I+i)/2:"start"===t.insideAlign?I-p*($+H(m)/2):i+p*($+H(m)/2):i-p*C,u,A,n);const g=l[r];g&&E(g,f-8*a,u,A,n)}),s.appendChild(_("line",{class:r,x1:I,x2:I,y1:0,y2:n}))}},Ct={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=yt(o,t.series.length),u=Nt(t,o,r,{},i.bottom<0?`center ${f-a(i.top)}px`:""),d=n(r)-s/2,h=Mt(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=St(h,b)?Math.min(e,(p-$)/2):0,[w,M]=a(i)<a(o)?[$+g,p]:[$,p-g];u(b,{x:d,y:w,width:s,height:Math.max(M-w,1),...i<o&&{"data-grow":"down"},...!St(h,b)&&kt(t,i<o?"bottom":"top")}),m.dataset.place="inside",m.toggleAttribute("data-left-out",!rt(m,p-$,l)||at(m).width*l>s-4*l),xt(m,t,b),E(m,n(r),($+p)/2,A,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,A,c)}}),void i.appendChild(_("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=gt(e,t.own.length,t.barMax),u=t.own.flatMap(e=>t.seriesValues[e]).filter(t=>void 0===t.dataset.missing),b=ct(t.plot,u,t=>({size:at(t).width*l,room:s.size+.5*s.gap}),"--_fit"),m="inside"===d&&!ot(u,s.size,l),$=u[0]?at(u[0]).height*l*.56:0,p=Math.min(...u.map(t=>(s.size-at(t).width*l)/2));return t.rows.forEach((e,r)=>{t.own.forEach((u,d)=>{const g=e.cells[u]??e.cells[0],w=t.seriesValues[u][r],M=n(r)+s.offset(d);if(g.missing)return void(w.dataset.place="none");const y=a(g.value),v=g.value<0,x=Math.max(Math.abs(f-y),1);0!==g.value&&i.appendChild(_("rect",{class:B(o,e),"data-kind":"bar","data-row":r+1,...v&&{"data-grow":"down"},x:M,y:v?f:f-x,width:s.size,height:x,...kt(t,v?"bottom":"top"),...wt(t,e,u)}));const k=m&&rt(w,Math.abs(f-y),l),S=v?-1:1,N=Math.min(p,(Math.abs(f-y)-$)/2),C="center"===h?(y+f)/2:"start"===h?f-S*(N+$/2):y+S*(N+$/2);w.dataset.place=k?"inside":v?"below":"outside",w.toggleAttribute("data-left-out",!b),k&&xt(w,t,u),E(w,M+s.size/2,k?C:v?y+4*l:y-4*l,A,c)})}),void i.appendChild(_("line",{class:r,x1:0,x2:A,y1:f,y2:f}))}const b=t.own[0],m=t.own.length<t.series.length,$=ot(u,s,l),p=e.map((t,e)=>"inside"===d&&!$&&!t.missing&&rt(u[e],Math.abs(f-a(t.value)),l)),g=u[0]?at(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-at(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,A,c),void(u[r].dataset.place="outside");const M=Math.max(Math.abs(f-d),1);0!==e.value&&i.appendChild(_("rect",{class:B(o,e),"data-kind":e.kind,"data-row":r+1,...$&&{"data-grow":"down"},x:n(r)-s/2,y:$?f:f-M,width:s,height:M,...kt(t,$?"bottom":"top"),style:L("--i",e.slot),...m&&wt(t,e,b)}));const y=$?-1:1,v=Math.min(w,(Math.abs(f-d)-g)/2),x="center"===h?(d+f)/2:"start"===h?f-y*(v+g/2):d+y*(v+g/2),k=$?d+4*l:d-4*l;E(u[r],n(r),p[r]?x:k,A,c),u[r].dataset.place=p[r]?"inside":$?"below":"outside",m&&p[r]&&xt(u[r],t,b)}),i.appendChild(_("line",{class:r,x1:0,x2:A,y1:f,y2:f}))}},Ht=(t,e,n,a,o,r,s,c)=>{const l=(a,r)=>[t+a*Math.cos(n)-o*r*Math.sin(n),e+a*Math.sin(n)+o*r*Math.cos(n)],i=c?a-s:a+s,u=Math.sqrt(Math.max(i**2-(r+s)**2,0)),d=a/i,h=c?a+8:a-3,f=h/i,b=Math.max(r-1,0),[m,$]=l(u*d,(r+s)*d),[p,g]=l(u,r),[w,M]=l(u,r+s),y=(m-w)*(g-M)-($-M)*(p-w)>0?1:0,v=t=>`${O(t[0])},${O(t[1])}`;return`M${v([m,$])}A${O(s)},${O(s)} 0 0 ${y} ${v([p,g])}L${v(l(u,b))}L${v(l(h,b))}L${v(l(u*f,(r+s)*f))}Z`},Tt=0,Lt={aspect:.66,centre:!0,headroom:()=>0,segments:t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),draw({rows:t,height:e,unit:n,labelHeight:a,svg:o,values:r,config:s,centre:c}){const l=500,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(A,e)/2-h,10),b=f*s.ringfill,m=f-b/2,$=2*Math.PI*m,p=[],g=[];let w=0,M=0,y=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const h=Math.abs(t.value)/d,v=T(y,h),x=`--share:${h.toFixed(4)}; --start:${v.start.toFixed(4)}; --span:${v.span.toFixed(4)};`,k=h*$,S=w/$*2*Math.PI-Math.PI/2;p.push(S),g.push(k/$*2*Math.PI),o.appendChild(_("circle",{class:B(u,t),"data-slice":M+1,"data-row":s+1,cx:l,cy:i,r:m,"stroke-width":b,transform:`rotate(-90 500 ${i})`,"stroke-dasharray":`${k.toFixed(1)} ${($-k).toFixed(1)}`,"stroke-dashoffset":(-w).toFixed(1),style:`--n:${M}; --palette:var(--tablechart-color-${M+1}); --arc:${k.toFixed(1)}; --circ:${$.toFixed(1)}; ${x} --ease:${v.easing}; ${L("--i",t.slot)}`}));const N=S+k/$*Math.PI,C=Math.cos(N),H=Math.sin(N);o.appendChild(_("line",{class:"tablechart-leader",x1:l+C*(f+2*n),y1:i+H*(f+2*n),x2:l+C*(f+7*n),y2:i+H*(f+7*n),"data-row":s+1,style:`${x} ${L("--i",t.slot)}`})),c.style.setProperty("--start",v.start.toFixed(4)),c.style.setProperty("--span",v.span.toFixed(4));const O=f+9*n,z=at(c).width*n/2;E(c,l+C*(O+Math.abs(C)*z),i+H*(O+Math.abs(H)*a*.7),A,e),c.dataset.place="around",w+=k,y+=h,M+=1}),p.length>1){const t=m-b/2-1,n=m+b/2+1,a="tablechart-slices-"+ ++Tt,r=_("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(_("rect",{x:0,y:0,width:A,height:e,fill:"white"}));for(const e of p)r.appendChild(_("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=getComputedStyle(o),c=Number.parseFloat(s.getPropertyValue("--tablechart-slice-radius"))||0;if(c>0){const t=Number.parseFloat(s.getPropertyValue("--tablechart-slice-gap").trim()||"4"),e=[m-b/2,m+b/2],n=n=>Math.min(c,b/2,Math.max((g[n]*e[0]-t)/2,0));p.forEach((a,o)=>{const s=n((o-1+p.length)%p.length);for(const[c,u]of[[1,n(o)],[-1,s]])if(u>0)for(const n of e)r.appendChild(_("path",{d:Ht(l,i,a,n,c,t/2,u,n===e[1]),fill:"black"}))})}const d=_("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${u}`)))d.appendChild(e);const h=_("defs");h.appendChild(r),o.prepend(h,d)}c&&E(c,l,i,A,e)}},Ot=["circle","square","diamond"],_t=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[];if(n.includes("none"))return{shape:"none",open:!1};const a=Ot.find(t=>n.includes(t));return{shape:a??Ot[Math.floor(e/2)%Ot.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},Bt=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return _("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return _("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return _("polygon",{points:`${e},${n-.75*t} ${e+.87*t},${n+.75*t} ${e-.87*t},${n+.75*t}`,...o})}return _("circle",{cx:e,cy:n,r:a,...o})},zt=t=>Number(t.toFixed(2));function Et(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 Rt,Ut,Ft=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}},qt=[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],Pt=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),Vt=t=>({segments:Pt,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,M="step"===e.shape,y="smooth"===e.shape,v=a.length>1,x=a.some(t=>t.focus),k=n.length-1,S=i(0),N=n.length>1?l(1)-l(0):2*l(0);p.style.setProperty("--_base",`${zt(S)}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?Mt(t,a.length,!0):null),L=(t,e)=>T[e]?.[t].to??C(t,e)?.value??0,B=(t,e)=>T[e]?.[t].from??0,z=(t,e)=>[l(e),i(L(t,e))],R=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 P=k>0?U/(M?n.length:k):1,V=t=>t*P,W=t=>`--i:${zt(V(t))}`,j=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{H(t,o)||(a<0&&(a=o),(o===k||H(t,o+1))&&((M||o>a)&&e.push([a,o]),a=-1))}),e},D=(t,e)=>`--i:${zt(V(t)+1)}; --d:${zt(V(M?e+1:e)-V(t))}`,G=(t,e)=>({"data-from":t+1,"data-to":e+1,...M&&{"data-flat":""}}),K=y?a.map((t,e)=>Et(n.length,t=>H(e,t),t=>z(e,t))):[],Y=y&&t?a.map((t,e)=>Et(n.length,t=>H(e,t),t=>[l(t),i(B(e,t))])):[],Z=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{M?(a.push(`H${zt(o+n*N/2)}`),s<t.length-1&&a.push(`V${zt(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])=>`${zt(t)},${zt(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${zt(o)},${zt(r)}`)}),a},J=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[l(e+a),i(o(t,e+a))]),X=(t,e,n,a)=>y?t[e].slice(n,a+1):null,et=t=>l(t)-(M?N/2:0),nt=t=>l(t)+(M?N/2:0),[ot,rt]=(g?[]:o.flatMap(t=>n.flatMap((e,n)=>H(t,n)?[]:[i(L(t,n))]))).reduce(([t,e],n)=>[Math.min(t,n),Math.max(e,n)],[S,S]),st=t=>`fill:url(#${((t,e,n,a,o)=>{const r="tablechart-fade-"+ ++F,s=_("linearGradient",{id:r,gradientUnits:"userSpaceOnUse",x1:0,x2:0,y1:O(e),y2:O(a),...o}),c=[...e<n?[{offset:0,faded:!1}]:[],{offset:a>e?(n-e)/(a-e):0,faded:!0},...a>n?[{offset:1,faded:!1}]:[]];for(const{offset:l,faded:i}of c)s.appendChild(_("stop",{class:"tablechart-area-stop",offset:O(l),...i&&{"data-faded":""}}));return q(t).appendChild(s),r})(p,ot,S,rt,{style:R[t].ink,...x&&!a[t].focus&&{"data-muted":""}})}); `;t&&o.forEach(t=>(t=>{const e=_("g",{class:h,...R[t].attrs,...g&&{"data-stacked":""},style:`${R[t].ink}${g?"":st(t)}`}),n=j(t),a=_("g",{class:"tablechart-area-fill",style:`--rows:${zt(U+1)}; ${n.length?D(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=J(t,o,r,L),n=J(t,o,r,B),s=X(Y,t,o,r)?.reverse()??null,c=[`M${zt(et(o))},${zt(n[0][1])}`,`L${zt(et(o))},${zt(e[0][1])}`,...Z(e,X(K,t,o,r),1),`L${zt(nt(r))},${zt(n[n.length-1][1])}`,...Z(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(_("path",{d:c,...G(o,r),style:D(o,r)}))}p.appendChild(e)})(t)),o.forEach(t=>(t=>{const e=a[t];for(const[n,a]of j(t)){const o=J(t,n,a,L),r=[`M${zt(et(n))},${zt(o[0][1])}`,...Z(o,X(K,t,n,a),1)].join(" ");p.appendChild(_("path",{class:d,...R[t].attrs,d:r,...e.line&&{"data-line":e.line},...G(n,a),style:`${R[t].ink}${D(n,a)}`}))}})(t));const ct=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]=ut(t,f,A,u);return[{label:t,box:[n-2*f,a-3*f,o+4*f,r+6*f]}]})):[],it=M?[]:o.flatMap(t=>n.flatMap((e,n)=>{if(H(t,n))return[];const[a,o]=z(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),dt=ct.filter(({label:t,box:e})=>{const n=it.some(t=>Q(t,e));return n&&t.setAttribute("data-left-out",""),!n}),ht=(t,e)=>{let n=e;for(;n<k&&!H(t,n+1)&&C(t,n+1)?.value===C(t,e)?.value;)n++;return n},bt=t=>"above"===t?"below":"above",mt=(t,e,n)=>{const[a,o]=z(t,e),r=at(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=>$t(t,e,n,0)).filter(t=>Q(t,c)).length},$t=(t,e,n,a)=>{const[o,r]=z(t,e),[s,c]=z(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]})},pt=(e,n)=>{const o=C(e,n);if(!o||o.missing)return"none";if(M&&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||M||mt(e,n,r)<=mt(e,n,bt(r))?r:bt(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&&z(e,n)[1]+7*f+b>S?"above":"below"},gt=t=>{let e=k;for(;e>0&&H(t,e);)e--;return e},wt=M||g?10*f:Math.max(10*f,...o.map(t=>at(s[t][k]).width*f/2+6*f)),yt=e.numbersAtEnd?Math.max(...o.map(t=>at(s[t][gt(t)]).width*f))+11*f:wt,vt=()=>{const t=(c[0]?at(c[0]).height:0)*f,n=2*f,a=o.flatMap(t=>{const e=c[t];if(!e)return[];const[n,a]=z(t,gt(t));return[{name:e,x:n+yt,y:a}]}),r=e.numbersAtEnd?yt-7*f:0;return lt(a,t).map(e=>[e.x-n-r,e.y-t/2-n,at(e.name).width*f+2*n+r,t+2*n])},xt=(w||v&&!x&&a.length>2&&!g)&&!M,kt=new Map;if(xt){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"!==pt(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=at(s[t][n]).width*f,[r,c]=z(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]=z(t,n);return[[a-4*f,o-4*f,8*f,8*f]]})),c=tt(a,[...r,...vt(),...dt.map(({box:t})=>t)],[0,0,l(k)+l(0),u]);t.forEach(({s:t,i:n,value:a},o)=>kt.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(zt(M?(V(n)+V(n+1))/2:V(n))));const a=kt.get(e)??pt(t,n);if(e.dataset.place="above"===a?"outside":a,e.toggleAttribute("data-left-out","none"!==a&&((t,e)=>{if(xt)return null===kt.get(s[t][e]);if(!g&&!M)return!1;const n=at(s[t][e]).width*f;if(n>(M?ht(t,e)-e+1:1)*N-4*f)return!0;if(g&&t>0&&L(t,e)<B(t,e))return!0;if(g&&!M&&e>0&&e<k){const a=(i(B(t,e))+i(L(t,e)))/2,r=[l(e)-n/2,a-b/2,n,b];if(o.some(t=>{const[n,a]=z(t,e);return!H(t,e)&&Q([n-4*f,a-4*f,8*f,8*f],r)}))return!0}return g&&Math.abs(i(B(t,e))-i(L(t,e)))<1.2*b})(t,n)),M&&"none"!==a?e.dataset.rowEnd=String(ht(t,n)+1):delete e.dataset.rowEnd,"none"===a)return;const r=at(e).width*f/2+4*f;let c=l(n);M?c=(l(n)+l(ht(t,n)))/2:"middle"===a&&0===n?c+=r:"middle"===a&&n===k&&(c-=r);const d=i(L(t,n)),h={middle:(i(B(t,n))-d)/2,above:-7*f,below:7*f};E(e,c,d+h[a],A,u)})});const St=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=Ft(t),l=r(c.at);l.length&&s(l)&&(c=Ft(t.filter(t=>!l.includes(t))),l=r(c.at)),s(l)||(c=Ft(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,qt[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===ft([s[t][e],n],f,1e3,u))&&l.push(e)}return new Set(l)},Nt=t=>{const e=s[t].filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out"));return 1===ft(e,f,A,u)},At=new Map;for(const t of o){const n="all"===e.pick.mode||"auto"===e.pick.mode&&Nt(t)?null:St(t);At.set(t,n),n&&s[t].forEach((t,e)=>{"none"===t.dataset.place||n.has(e)||t.setAttribute("data-left-out","")})}if(!g&&!M&&o.some(t=>At.get(t))){const t=l(k)+l(0),a=2*f,r=t=>n.flatMap((e,n)=>n===k||H(t,n)||H(t,n+1)?[]:$t(t,n,n+1,a)),c=o.flatMap(r),i=vt(),d=o.flatMap(t=>[...At.get(t)??[]].map(e=>({s:t,i:e}))),h=({s:t,i:n})=>e.numbersAtEnd&&n===gt(t),m=d.filter(t=>!h(t)),$=({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"]},p=({s:e,i:n},a)=>{const o=at(s[e][n]).width*f,r=b,[c,l]=z(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]},g=m.map($),w=e=>e[0]>=0&&e[1]>=0&&e[0]+e[2]<=t&&e[1]+e[3]<=u-2*f,M=d.map(({s:t,i:e})=>{const[n,a]=z(t,e);return[n-6*f,a-6*f,12*f,12*f]}),y=[],v=new Set,x=m.map((t,e)=>{const n=g[e].map(e=>p(t,e)),a=t=>w(t)&&![...y,...i,...M].some(e=>Q(t,e)),s=o.filter(e=>e!==t.s).flatMap(r),l=n=>!g[e][n].endsWith("far")||!s.some(a=>Q(p(t,g[e][n].split(" ")[0]),a));let u=n.findIndex((t,e)=>a(t)&&l(e)&&!c.some(e=>Q(t,e)));return u<0&&(u=n.findIndex((t,e)=>a(t)&&l(e)),u>=0&&v.add(e)),u>=0&&y.push(n[u]),u<0?null:u});m.forEach((t,e)=>{const n=s[t.s][t.i];n.toggleAttribute("data-cut",v.has(e));const a=x[e];if(n.toggleAttribute("data-left-out",null===a),null===a)return;const o=g[e][a],[r,c,l,i]=p(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,A,u)})}M||(()=>{const t=o.map(t=>a[t]),r=a.map((e,n)=>w?_t(t,o.indexOf(n)):v?_t(a,n):{shape:"circle",open:!1}),s=(t,e,n)=>{const[a,o]=z(t,e);return Bt(r[t].shape,a,o,3*f,{...n,style:`${n.style??""}${s=o,`--rise:${zt(S-s)}px; `}${W(e)}`});var s},c=t=>/\bnone\b/.test(a[t].marker??"")?[]:n.map((t,e)=>e).filter(e=>!H(t,e)&&((t,e)=>{const n=At.get(t);return n?n.has(e):N>=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")?I(p,l,A,u):e.lineHoles.push(...l),o.forEach(t=>{for(const e of c(t))p.appendChild(s(t,e,{class:m,...R[t].attrs,"data-marker":r[t].shape,...r[t].open&&{"data-open":""},"data-row":e+1,style:R[t].ink}))})})(),e.pointOf=t=>{const e=o.filter(e=>!H(e,t)).map(e=>z(e,t));return e.length?e.reduce((t,e)=>e[1]<t[1]?e:t):null};const Ct=(w?[]:c).map((t,e)=>{const n=gt(e),[a,o]=z(e,n);return{name:t,s:e,x:(M?a+N/2:a)+yt,y:g?(o+i(B(e,n)))/2:o}}),Ht=(c[0]?at(c[0]).height:0)*f;for(const t of lt(Ct,Ht)){if(E(t.name,t.x,t.y,A,u),!e.numbersAtEnd)continue;const n=s[t.s][gt(t.s)];n.dataset.place="before",n.removeAttribute("data-left-out"),n.removeAttribute("data-cut"),E(n,t.x-4*f,t.y,A,u)}const Tt=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),Lt=t||g||2!==a.length||x||Tt?S:u-2*f;w||p.appendChild(_("line",{class:r,x1:0,x2:l(k)+l(0),y1:Lt,y2:Lt}))}}),It=Vt(!1),Wt=Vt(!0),jt=new Set,Dt={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.`;jt.has(a)||(jt.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=ot(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&&rt(i[a],r,c)}}),$=i[0]?at(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-at(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?H:"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(_("line",{class:"tablechart-connector",x1:i,x2:u,y1:c,y2:c,"data-row":r+2,style:`${L("--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(_("rect",{class:B(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:`${L("--i",n.slot)}; ${w(r,1,r===t.length-1)}`}));const M=i[r];M.style.setProperty("--start",(r/g).toFixed(4)),M.style.setProperty("--span",(1/g).toFixed(4));const y=Math.min(p,(d-$)/2),v="center"===b?u+d/2:"end"===b!==h?u+y+$/2:u+d-y-$/2;M.dataset.place=f?"inside":"outside",M.dataset.kind=n.kind;const x=f?v:"down"===n.kind?u+d+at(M).height*c+3*c:u-3*c;E(M,e(r),x,A,s)}),l.appendChild(_("line",{class:r,x1:0,x2:A,y1:h,y2:h}))}},Gt={enabled:!1,log(...t){Gt.enabled&&console.log(`[${n}]`,...t)},timed(t,e,a){if(!Gt.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):Gt.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},Kt=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}},Yt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).flatMap((t,e)=>t.hasAttribute("data-note")?[e]:[]),Zt=(t,e="data-i18n")=>{const n=Yt(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(Kt);s.length||s.push(Kt(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}})},Jt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).filter(t=>!t.hasAttribute("data-note")),Xt=(t,e,n="data-i18n")=>{const a=Jt(t),o=Math.max(1,D(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||"dash-dot"===r?r:null),group:!!o?.hasAttribute("data-group"),chart:"line"===o?.getAttribute("data-chart")?"line":null};var r})},Qt=t=>Number(t.toPrecision(12)),te=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return Qt((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},ee=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(Qt(o*n));return a},ne=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=Qt(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},ae=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},oe=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=ne(n,t.step),a=ee(t.min,t.max,n);return{...t,step:n,ticks:a}},re=null,se=t=>{if(re??(re=document.createElement("canvas").getContext("2d",{willReadFrequently:!0})),!re)return[0,0,0,1];re.clearRect(0,0,1,1),re.fillStyle=t,re.fillRect(0,0,1,1);const[e,n,a,o]=re.getImageData(0,0,1,1).data;return[e,n,a,o/255]},ce=([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)},le=t=>"3"===getComputedStyle(t).getPropertyValue("--tablechart-contrast-wcag").trim()?3:2,ie=([t,e,n])=>{const a=.2126729*(t/255)**2.4+.7151522*(e/255)**2.4+.072175*(n/255)**2.4;return a<.022?a+(.022-a)**1.414:a},ue=(t,e,n)=>3===t?((t,e)=>{const n=ie(t),a=ie(e);if(Math.abs(a-n)<5e-4)return 0;const o=a>n?1.14*(a**.56-n**.57):1.14*(a**.65-n**.62);return Math.abs(o)<.1?0:100*(Math.abs(o)-.027)})(e,n):de(e,n),de=(t,e)=>{const[n,a]=[ce(t),ce(e)].sort((t,e)=>e-t);return(n+.05)/(a+.05)},he=(t,e)=>{const n=document.createElement("span");n.style.color=e,t.append(n);const a=se(getComputedStyle(n).color);return n.remove(),a},fe=t=>{const e=[];let n=null;for(let o=t;o&&!n;o=o.parentElement){const{background:t,backgroundColor:a}=o.dataset,r=a||(t&&CSS.supports("color",t)?t:""),s=se(r||getComputedStyle(o).backgroundColor);s[3]>=1?n=s:s[3]>0&&e.push(s)}n??(n=he(t,"Canvas"));for(const[o,r,s,c]of e.reverse())n=[o,r,s].map((t,e)=>t*c+n[e]*(1-c));const a=`rgb(${n.slice(0,3).map(Math.round).join(" ")})`;return t.style.getPropertyValue("--_surface")!==a&&(t.style.setProperty("--_surface",a),!0)},be=t=>he(t,"var(--tablechart-surface, var(--_surface, Canvas))"),me=(t,e)=>t.querySelector(`:is(.tablechart-bar, .tablechart-piece)[data-row="${e.dataset.row}"]${e.dataset.series?`[data-series="${e.dataset.series}"]`:""}`),$e=[255,255,255],pe=[0,0,0],ge=(t,e,n)=>{const a=ue(n,$e,t),o=ue(n,pe,t);return a>=e?$e:o>=e?pe:2===n&&a>=4.5||a>o?$e:pe},we=t=>{const e=t.querySelectorAll(".tablechart-value[data-place='inside']");if(!e.length)return;const n=be(t).slice(0,3),a=ce(n)>.179,o=(e,n)=>{const[a,o,r,s]=he(t,`var(${e}, transparent)`);return s>0?[a,o,r]:n},r=le(t),s=Number.parseFloat(getComputedStyle(t).getPropertyValue("--tablechart-value-contrast"))||(3===r?60:5),c=se(getComputedStyle(t).color).slice(0,3),l=o("--tablechart-value-on-dark",a?n:c),i=o("--tablechart-value-on-light",a?c:n);for(const u of e){const e=me(t,u);if(!e||u.hasAttribute("data-left-out"))continue;const n=se(getComputedStyle(e).fill),a=ue(r,l,n)>ue(r,i,n)?l:i,o=ue(r,a,n)>=s?a:ge(n,s,r);u.style.setProperty("--_ink",`rgb(${o.join(" ")})`)}},Me=t=>{const e=t.querySelectorAll(".tablechart-name:not([data-place='legend'])");if(!e.length)return;const n=le(t),a=3===n?60:4.5,o=be(t).slice(0,3),r=se(getComputedStyle(t).color).slice(0,3);for(const s of e){const e=t.querySelector(`.tablechart-series[data-series="${s.dataset.series}"]:not([data-muted])`);if(s.style.removeProperty("--_ink"),!e)continue;const c=se(getComputedStyle(e).stroke).slice(0,3);for(let t=0;t<=20;t++){const e=c.map((e,n)=>Math.round(e+(r[n]-e)*t/20));if(!(ue(n,e,o)<a&&t<20)){t&&s.style.setProperty("--_ink",`rgb(${e.join(" ")})`);break}}}},ye=["axis-break","trend","bracket"],ve=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))}},xe=(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)),ve(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}}))},ke="tablechart-tooltip",Se=["--tablechart-surface","--_surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],Ne=null,Ae=null,Ce=null,He=0,Te=()=>{clearTimeout(He),Ne&&Ae&&(Ne.hidden=!0,Ae=null,Ce=null)},Le=!1,Oe=!0,_e=NaN,Be=NaN,ze=!1,Ee=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Re=()=>{clearTimeout(He),He=window.setTimeout(Te,120)},Ue=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Fe=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole, .tablechart-area:not([data-stacked]))`);if(!n)return;const a=getComputedStyle(n);return a.fill&&"none"!==a.fill?a.fill:a.stroke},qe=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Ue(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?Fe(t,s):void 0,sample:n?{marker:n.dataset.marker??null,open:n.hasAttribute("data-open"),line:n.dataset.line??null,point:getComputedStyle(n).getPropertyValue("--tablechart-point-color").trim(),box:"box"===n.dataset.swatch}:void 0})}const r=t.totals[e];return o.length>1&&Ue(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Pe=(t,e,n)=>{if(clearTimeout(He),Ae===t&&Ce===e)return;const a=(t.type.tooltip??qe)(t,e,n);if(!a.length)return Te();Ae&&Ae!==t&&Te(),Ne??(Ne=(()=>{const t=document.createElement("div");return t.className=ke,t.setAttribute("aria-hidden","true"),t.hidden=!0,Rt=document.createElement("div"),(Ut=document.createElement("div")).className=`${ke}-arrow`,t.append(Rt,Ut),document.body.append(t),t.addEventListener("pointerenter",()=>clearTimeout(He)),t.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Re()),document.addEventListener("pointerdown",e=>{const n=e.target;!Ae||Ae.plot.contains(n)||t.contains(n)||Te()}),window.addEventListener("resize",Te),t})());const o=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${ke}-line`,n){const t=document.createElement("span");t.className=`${ke}-key`,t.style.backgroundColor=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),o.point&&t.style.setProperty("--tablechart-point-color",o.point),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${ke}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${ke}-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=Yt(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:`${ke}-note`,textContent:l})]:[];Rt.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 Se){const t=u.getPropertyValue(m).trim();t?Ne.style.setProperty(m,t):Ne.style.removeProperty(m)}Ne.style.setProperty("--_color",u.color),Ne.style.colorScheme=u.colorScheme,Ne.style.fontFamily=u.fontFamily;const d=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(n);Ne.parentElement!==d&&d.append(Ne),Ae=t,Ce=e,Ne.hidden=!1,Ne.style.left="0px",Ne.style.top="0px";const h=Ne.getBoundingClientRect(),f={x:h.left,y:h.top,scale:Ee(Ne,h.width)},b=Ee(t.plot,t.plot.getBoundingClientRect().width);Ne.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,M=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(M-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-M,l-h))/a.scale-u+"px"})(Ne,Ut,((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/A,o=4*a*(A/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)},Ve=t=>{Ae===t&&Te()},Ie={area:Wt,bar:At,column:Ct,donut:Lt,line:It,waterfall:Dt},We={"axis-break":j,trend:pt,bracket:X,reference:$t,note:bt},je=Object.keys(We),De=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},Ge=["straight","step","smooth"],Ke=(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${O(t)},${O(l)}H${O(e)}`:`M${O(l)},${O(t)}V${O(e)}`).join("")},Ye=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=_("path",{d:Ke(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]),Je=(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${O(Math.max(t,e))},${O(r)}H${O(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${O(t)},${O(Math.max(r,n))}V${O(Math.min(c,n+o))}`:"").join(""),Xe=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},Qe=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),tn=(t,e)=>{const n=t.dataset.chartShape;return n&&Ge.includes(n)?n:Ge.includes(e.shape)?e.shape:"straight"},en=0,nn=[null,"dashed","dotted","dash-dot"],an=(t,e,o=null)=>{const r=o??(t.getAttribute("data-chart")||"column"),s=Ie[r];if(!s)return console.warn(`[${n}] Unknown chart type "${r}". Known types: ${Object.keys(Ie).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const c=Zt(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(De(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-"+ ++en),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=Xt(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})))}((t,e,a,o)=>{const r=t.closest("[data-chart-lines]")?.getAttribute("data-chart-lines");let s=o.lines;if(r)try{s=JSON.parse(r)}catch{console.warn(`[${n}] data-chart-lines needs a JSON list, such as [{"marker":"none"}].`,t)}("line"===a||"area"===a?e:e.filter(t=>t.chart)).forEach((t,e)=>{if(!s?.length)return void(t.line??(t.line=nn[Math.floor(e/6)%nn.length]));const n=s[e%s.length];t.marker??(t.marker=n.marker||void 0!==n.open?[n.marker,n.open?"open":"filled"].filter(Boolean).join(" "):null),null===t.line&&"solid"!==n.line&&(t.line=n.line??null)})})(t,l,r,e);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 $=_("svg",{role:"presentation",focusable:"false"});m.appendChild($);const g=t.querySelector(":scope > table"),M=e=>g?g.before(e):t.append(e);M(m);const y=s.centre?c.filter(t=>!t.isTotal):c,v=Math.max(0,D(y.flatMap(t=>t.cells.slice(0,l.length).map(t=>G(t.number))))),x=l.map((t,e)=>Math.max(0,D(c.map(t=>G(t.cells[e]?.number??""))))),N=document.createElement("div");N.className="tablechart-values",m.appendChild(N);const A=l.map((t,e)=>c.map((t,n)=>{const o=t.cells[e]??t.cells[0],r=z(a,N);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(x[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=z(a,N);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(vt(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),O=t.getAttribute("data-chart-legend"),B=u&&!s.columns&&(null===O?e.legend||void 0!==s.legend:"false"!==O)?document.createElement("div"):null;B&&(B.className=b,B.setAttribute("aria-hidden","true"),B.inert=!0);const E=l.filter(t=>t.chart),R=u&&!s.columns?l.map((n,a)=>{const o=z(f,B??m);B&&(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"!==tn(t,e)){const t=n.chart?_t(E,E.indexOf(n)):_t(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}):[],U=s.centre?z(p,m):null;if(U){const t=c.find(t=>t.isTotal),e=t?t.value:c.reduce((t,e)=>t+Math.abs(e.value),0);U.dataset.value=String(e),t&&(U.dataset.decimals=String(G(t.number)))}const F=U&&!c.some(t=>t.isTotal)?((t,e,n)=>{const a=t.querySelector("table");if(!a)return null;const o=a.querySelector("tfoot [data-chart-total]");if(o)return o.dataset.value=e.dataset.value??"0",o;const r=(a.tFoot??a.createTFoot()).insertRow(),s=document.createElement("th");s.scope="row",s.textContent=n.totallabel;const c=t.getAttribute("data-chart-keys");c&&n.langattribute&&s.setAttribute(n.langattribute,`${c}-total`);const l=r.insertCell();return l.setAttribute("data-chart-total",""),l.dataset.value=e.dataset.value??"0",r.prepend(s),l})(t,U,e):null,q="beside"===s.categories,P=document.createElement("div");P.className="tablechart-categories",P.setAttribute("aria-hidden","true"),P.inert=!0,q?P.dataset.place="beside":s.centre&&(P.dataset.place="key"),P.style.setProperty("--_columns",String(c.length));let V=0;for(const[n,a]of c.entries()){const t=document.createElement("span");t.classList.add(...a.classes),t.textContent=a.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(V+1),t.style.setProperty("--n",String(V)),t.style.setProperty("--palette",`var(--tablechart-color-${V+1})`),V+=1)),t.style.setProperty("--i",String(a.slot)),t.dataset.row=String(n+1),P.appendChild(t)}s.centre&&t.style.setProperty("--_slice-count",String(V)),q?m.appendChild(P):M(P),B&&M(B);const I=l.filter(t=>!t.group),W=!s.axes&&!s.centre&&Xe(t,"data-chart-axis",e.axis),j=s.axes?{titles:I.slice(0,2).map((t,n)=>{const a=z(`${k}-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:z(`${S}s`,m),numbers:!0}:W||!s.centre&&Xe(t,"data-chart-grid",e.grid)?{titles:[],ticks:z(`${S}s`,m),numbers:W}:null;s.text?.({figure:t,plot:m,rows:c,series:l,config:e});const K=Qe(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=>ye.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[y,v]of a.entries())b(v)&&($[y]={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}))),M=Math.max(0,...c.map(t=>t.length));for(let y=0;y<M;y++)for(const[t,e]of c.entries()){const n=e[y];if(!n||!s(n))continue;const a=d(n.getAttribute("data-fragment-index"));w[t][y]={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]")&&Gt.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"),Z=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=_("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(_("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;Z&&M(Z);const J=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),a=We[e];if(!a)return console.warn(`[${n}] Unknown annotation "${e}". Known annotations: ${Object.keys(We).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(!q&&!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),J.push({spec:t,type:bt,badge:bt.create(t,m),series:0,after:c.length})}Qe(t,e)&&t.setAttribute("data-animate",sn(t,r,e,Boolean(K)));const X={figure:t,plot:m,svg:$,rows:c,decimals:v,type:s,values:C,series:l,seriesValues:A,names:B?[]:R,categories:Array.from(P.children),centre:U,axes:j,stacked:h,totals:H,totalCell:F,rowAt:null,rowBox:null,pointOf:null,annotations:J,checks:[],plan:K,step:0,controls:Z},Q=()=>pn(t,$);$.addEventListener("transitionend",Q),$.addEventListener("transitioncancel",Q),Z?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&xe(X,X.step+("next"===e?1:-1))}),xe(X,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(ze)return;ze=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(Oe=t.screenX!==_e||t.screenY!==Be,_e=t.screenX,Be=t.screenY,Oe&&(Le=!1))},{capture:!0,passive:!0});const t=()=>{Le=!0,Te()};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)Le=!1;else if("mouse"===o.pointerType&&(!Oe||Le))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return Ae===t?Te():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Ee(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 Ae===t?Te():void 0;Pe(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)||Le||Pe(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,Ae===t&&Re())})})(X,e,"auto"===et),fn(X,e),X},on={grow:"grow",sweep:"sweep"},rn=["never","auto","print","always"],sn=(t,e,n,a)=>{const o="line"===e||"area"===e,r=on[t.getAttribute("data-chart-animate")??""]??on[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},cn=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},ln=(t,e,n)=>"inside"===t.dataset.chartLabels||"outside"!==t.dataset.chartLabels&&("inside"===e.labels||n)?"inside":"outside",un=(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*A:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},dn=(t,e)=>un(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,hn=["first","last","highest","lowest","outliers"],fn=(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:bn(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},bn=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=K(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)}},mn=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||gn(t.svg),t.figure.classList.remove(x),n)return t.figure.classList.add(v),t.figure.classList.toggle(M,e),t.figure.offsetWidth,e&&wn(t.svg),t.figure.classList.toggle(x,e),void requestAnimationFrame(()=>t.figure.classList.remove(v));t.figure.classList.toggle(M,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>{pn(t.figure,t.svg),$n(t.figure)}))},$n=t=>{const e=t.getAnimations({subtree:!0}).map(t=>t.finished.catch(()=>{}));Promise.all(e).then(()=>{t.classList.contains("is-shown")&&t.classList.add(x)})},pn=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&wn(e)},gn=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},wn=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},Mn={2:{part:3,text:4.5,large:3,show:t=>`${(Math.floor(100*t)/100).toFixed(2)}:1`,need:t=>`${t}:1`,partRule:"WCAG 1.4.11",textRule:"WCAG 1.4.3"},3:{part:30,text:60,large:45,show:t=>`Lc ${Math.floor(t)}`,need:t=>`Lc ${t}`,partRule:"APCA, WCAG 3 draft",textRule:"APCA, WCAG 3 draft"}},yn=["bar","piece","up","down","total"].map(t=>`--tablechart-${t}-value-color`),vn=new Set,xn=t=>"id"===t||"style"===t||t.startsWith("data-chart"),kn=/^\s*(?:Table)?:\s+/,Sn=t=>"P"===t?.tagName&&kn.test(t.textContent??""),Nn=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,An=t=>{const e=Hn(t);return"P"===e?.tagName?e:t},Cn=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},Hn=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},Tn="strong, b, span.total",Ln="data-chart-made",On=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,_n=new Set,Bn=null,zn=["column","bar"],En=t=>{const e=t.getAttribute("data-chart")||"column";if(!zn.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return zn.includes(n)?n:e},Rn=!1,Un=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||xn(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=An(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Nn.exec(e.textContent??"");if(!n||!je.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=An(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(kn,""),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),Gt?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(Ln)&&"TH"!==t.tagName));(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!Rn&&e&&(Rn=!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:Cn(o.rows):Cn(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||Gt?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),Gt?.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=Hn(e);a?.matches(Tn);a=Hn(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=Hn(e);t?.matches(Tn);t=Hn(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=Jt(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=Yt(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}`)}}),Gt?.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},Fn=(t,e)=>{const a=Gt.timed("Building",t,()=>an(t,e));return a?(t.setAttribute(Ln,""),Vn(),((t,e)=>{let a=t,r=En(a.figure),m=null,g=!1,w=!1,M=!1;const v=async()=>{if(!Qe(a.figure,e))return mn(a,!0);const t=a.figure.classList.contains("is-shown");if(!w||null===m||t||M)!w&&e.replay&&t&&mn(a,!1);else{M=!0;const t=On()?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(On())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)),M=!1,!w&&e.replay||mn(a,!0)}var n},x=()=>{const t=En(a.figure);if(!t||t===r)return;const n=Gt.timed("Building",a.figure,()=>an(a.figure,e,t));n&&((t=>{Ve(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${b}`)?.remove(),t.controls?.remove()})(a),xe(n,a.step,!0),a=n,r=t,m=null)},C=()=>{x();const t=a.plot.clientWidth;t&&t!==m&&Gt.timed("Layout",a.figure,()=>((t,e)=>{const{plot:a,svg:r,rows:m,type:g,values:w,series:M,seriesValues:y,names:v,annotations:x}=t;(({figure:t,rows:e,series:n},a)=>{const o=t.getAttribute("data-chart-table"),r=o&&rn.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&&rn.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 H=Number.parseFloat(t.figure.dataset.chartAspect??""),L=H>0?H:g.aspect??e.aspect,B="beside"===g.categories,R=t.axes&&!g.axes?t.axes:null,U=B?null:t.categories[0]?.parentElement;let F=null;if(R){a.style.margin="",U&&(U.style.marginLeft="");const n=a.clientWidth;if(!n)return!1;const o=g.segments?.(m)??[],r=t.stacked?m.flatMap(t=>Object.values(yt(t,M.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,M.length).filter(t=>!t.missing).map(t=>t.value)),s=Math.min(0,-D(r.map(t=>-t))),c=Math.max(0,D(r)),l=Number.parseFloat(getComputedStyle(a).fontSize)||16,{chartScaleY:i,chartScale:u}=t.figure.dataset,d=ae(i??u);if(d&&d.length>2)F={min:d[0],max:d[d.length-1],step:0,ticks:d};else{const[t,e]=d??[s,c],a=te(e-t,Math.max((B?n/9:n*L/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);F={min:r,max:i,step:a,ticks:ee(r,i,a)}}R.ticks.textContent="";const h=m.find(t=>!t.missing),f=D(F.ticks.map(t=>G(String(t))));for(const t of F.ticks){const n=z(S,R.ticks);n.dataset.value=String(t),n.dataset.place="none",h?.prefix&&(n.dataset.prefix=h.prefix),h?.suffix&&(n.dataset.suffix=h.suffix),bn(n,f,e.locale)}if(R.numbers){const t=Array.from(R.ticks.children);for(const e of t)delete e.dataset.place;nt(t),B?a.style.marginBottom=`${(t[0]?at(t[0]).height:0)+6}px`:(a.style.marginLeft=`${D([0,...t.map(t=>at(t).width)])+10}px`,U&&(U.style.marginLeft=a.style.marginLeft))}}const q=a.clientWidth;if(!q)return!1;const P=A/q,W=A*L;a.classList.add("is-placed");const j=!1===g.numbers?w.slice(0,1):[...y.flat(),...t.totals];for(const n of j)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&&M.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=M.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=[ae(s),ae(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]??-D(t.map(t=>-t)),o=n?.[1]??D(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=te(o-a,e);return{min:a,max:o,step:r,ticks:ee(a,o,r)}})(r.length?r.map(e=>e.cells[t].value):[0,1],Math.max(e?W/P/(4*n):q/(9*n),4),i[e])),K.ticks.textContent="",Y.forEach((t,n)=>{const a=r[0]?.cells[o[n]],s=D(t.ticks.map(t=>G(String(t))));for(const o of t.ticks){const t=z(S,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),bn(t,s,e.locale)}})}const Z=K?Array.from(K.ticks.children):[];nt([...y.flat(),...t.totals,...v,...t.categories,...x.map(t=>t.badge),...K?.titles??[],...Z]);const J=(w[0]?at(w[0]).height:0)*P;!1===g.numbers&&w[0]&&(w[0].dataset.place="none");const X=x[0]?.badge?at(x[0].badge).height*P:0,Q=Math.max(W,un(t.figure,P,"--tablechart-min-height","200px")??0,g.minHeight?.({labelHeight:J,nameHeight:Math.max(0,D(t.categories.map(t=>at(t).height)))*P,unit:P,rows:m.length,series:M.length,stacked:t.stacked,labels:ln(t.figure,e,M.some(t=>t.chart))})??0),tt=t.stacked?m.map(t=>{const e=vt(t,M.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):m,et=(g.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?tt.map(t=>({...t,cells:[t.cells[0]]})):m),ot={labelHeight:J,badgeHeight:X,hasAnnotations:x.length>0,unit:P,series:M.length,focused:M.some(t=>t.focus),stacked:t.stacked},rt=Math.max((e=>t.stacked?e(m.map(t=>yt(t,M.length,g.running).top)):e([...et.flatMap(t=>[t.from,t.to,t.value]),...m.flatMap(t=>t.cells.slice(0,M.length).map(t=>t.value))]))(D),0),st=et.some(t=>"up"===t.kind||"down"===t.kind)?et.flatMap(t=>[t.from,t.to]):t.stacked?m.map(t=>yt(t,M.length,g.running).bottom):m.flatMap(t=>t.cells.slice(0,M.length).map(t=>t.value)),lt=Math.min(-D(st.map(t=>-t)),0),it=M.flatMap((t,e)=>t.chart?[e]:[]),ut=m.some(t=>t.note)?X+4*P:0,ft=Math.max(g.headroom?.(ot)??J,it.length?It.headroom?.(ot)??0:0)+ut,bt=2*P+(g.footroom?.(ot)??0)+(lt<0?J+4*P:0),mt=Q-ft-bt,$t=F?Math.max(F.max,rt):1.02*rt,pt=F?Math.min(F.min,lt):1.02*lt,gt=x.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,wt=t=>{const e=Number.parseFloat(gt?.getAttribute(t)??"");return Number.isFinite(e)?e:null},Mt=wt("data-from")??wt("data-at"),xt=wt("data-to");let kt=null;if(gt&&(null!==Mt||null!==xt)){const t=Mt??0,e=xt??$t,a=null===xt?t:null===Mt?e:(t+e)/2,o=gt.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===xt?.22:.3,.05),.8),c=et.filter(n=>("up"===n.kind||"down"===n.kind)&&Math.max(n.from,n.to)>t&&Math.min(n.from,n.to)<e);g.breakable?lt<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 ${rt}.`):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:a,share:s}:console.warn(`[${n}] This kind of chart cannot break its scale.`)}const St=kt?kt.gap:null,Nt=(kt&&un(t.figure,P,"--tablechart-break-gap",""))??13,At=Q-bt,Ct=$t-pt||1;let Ht,Tt,Lt=t=>At-(t-pt)/Ct*mt;if(kt){const{lo:t,hi:e,gap:n,share:a}=kt,o=mt*a,r=(mt-o-Nt)/(t+($t-e)),s=o/(e-t);Lt=a=>a<=t?At-a*r:a<=n?At-t*r-(a-t)*s:a<=e?At-t*r-(a-t)*s-Nt:At-t*r-o-Nt-(a-e)*r}let Ot=[];if(K){const t=6*P,[e,n]=K.titles,a=t=>t?at(t).width*P:0,o=t=>t?at(t).height*P:0,r=Z.filter(t=>"x"===t.dataset.axis),s=Z.filter(t=>"y"===t.dataset.axis),c=o(Z[0]),l=a(n)+D([0,...s.map(a)])+2*t,i=c/2;Tt=[l,i,A-l-D([0,...r.map(a)])/2,Q-i-o(e)-c-2*t];const[u,d,h,f]=Tt,[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;Ht=$,Lt=p;const g=t=>a(r.find(e=>Number(e.dataset.value)===t));Ot=[oe(b,e=>e.every((n,a)=>!a||$(n)-$(e[a-1])>(g(n)+g(e[a-1]))/2+t)).ticks,oe(m,e=>e.every((n,a)=>!a||p(e[a-1])-p(n)>c+t/2)).ticks];for(const w of Z){const e=Number(w.dataset.value),n="x"===w.dataset.axis?0:1,a=Ot[n].includes(e);w.dataset.place=a?n?"before":"below":"none",a&&E(w,n?u-t:$(e),n?p(e):d+f+t,A,Q)}e&&E(e,u+h/2,Q-o(e),A,Q),n&&E(n,0,d+f/2,A,Q)}const _t=((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",...hn].includes(r)||console.warn(`[${n}] data-chart-values knows no "${r}". It takes auto, all, none, ${hn.join(", ")}.`);const o=a.filter(t=>hn.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:hn}:{mode:"set",keys:o}})(t.figure,e),Bt=tn(t.figure,e),zt=!!g.running&&v.length>0&&!t.stacked&&"step"!==Bt&&"set"===_t.mode&&_t.keys.includes("last"),Et=zt?D(y.flat().map(t=>at(t).width))*P:0,Rt=v.length?D(v.map(t=>at(t).width))*P+12*P+Et:0,Ut=t.categories[0]?.parentElement;Ut&&(Ut.style.paddingRight=Rt?Rt/A*100+"%":"");const Ft=(A-Rt)/m.length,qt=t=>t>=0&&t<m.length?t:null;t.rowAt=g.centre?null:"beside"===g.categories?(t,e)=>qt(Math.floor(e*P/(Q/m.length))):t=>qt(Math.floor(t*P/Ft));const Pt=Ft/A*100,Vt=100/m.length;if(t.rowBox="beside"===g.categories?t=>[0,t*Vt,100,Vt]:t=>[t*Pt,0,Pt,100],r.setAttribute("viewBox",`0 0 1000 ${O(Q)}`),r.textContent="",Tt&&Ht){const[n,a,o,s]=Tt,[c,l]=Ot,i=Ht;Xe(t.figure,"data-chart-grid",e.grid)&&r.appendChild(_("path",{class:N,d:[...c.map(t=>`M${O(i(t))},${O(a)}V${O(a+s)}`),...l.map(t=>`M${O(n)},${O(Lt(t))}H${O(n+o)}`)].join("")})),r.appendChild(_("path",{class:k,d:[`M${O(n)},${O(a)}V${O(a+s)}H${O(n+o)}`,...c.map(t=>`M${O(i(t))},${O(a+s)}v${O(4*P)}`),...l.map(t=>`M${O(n)},${O(Lt(t))}h${O(-4*P)}`)].join("")}))}t.checks=[];const jt={rows:m,segments:et,cx:t=>(t+.5)*Ft,y:Lt,x:Ht,frame:Tt,length:(e,n)=>un(t.figure,P,e,n),barWidth:Math.min(Ft*e.barfill,dn(t.figure,P)),barMax:dn(t.figure,P),barRadius:un(t.figure,P,"--tablechart-bar-radius","0px")??0,height:Q,unit:P,labelHeight:J,badgeHeight:X,after:m.length,note:0,labels:ln(t.figure,e,it.length>0),insideAlign:cn(t.figure),breakAt:St,squeeze:kt,breakGap:Nt,domain:F?[F.min,F.max]:null,stacked:t.stacked,shape:Bt,pick:_t,numbersAtEnd:zt,totals:t.totals,svg:r,plot:a,values:w,series:M,own:M.map((t,e)=>e),seriesValues:y,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 Dt=t=>{const e=e=>({...e,...e.cells[t]??e.cells[0]});return{rows:m.map(e),segments:et.map(t=>{const n=e(t);return"bar"===t.kind?{...n,to:n.value}:n}),values:y[t]}};if(it.length){const t=M.flatMap((t,e)=>t.chart?[]:[e]);g.draw({...jt,own:t,...1===t.length&&Dt(t[0])}),It.draw({...jt,own:it})}else g.draw(jt);jt.rowAt&&(t.rowAt=jt.rowAt),t.pointOf=jt.pointOf??null;const Gt=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,Gt-1)));if(!t.stacked&&!a.hasAttribute("data-grouped"))for(const n of y)dt(n,P,A),ht(n,P,A,Q);if(R&&F){const n=6*P,a=B&&jt.x?jt.x:Lt,o=Array.from(R.ticks.children),s=t=>at(o.find(e=>Number(e.dataset.value)===t)??o[0]),c=oe(F,t=>t.every((e,o)=>!o||(B?a(e)-a(t[o-1])>(s(e).width+s(t[o-1]).width)/2*P+n:a(t[o-1])-a(e)>s(e).height*P+n/2))).ticks.filter(t=>!kt||t<=kt.lo||t>=kt.hi);for(const t of o){const e=Number(t.dataset.value),o=R.numbers&&c.includes(e);t.dataset.place=o?B?"below":"before":"none",o&&E(t,B?a(e):-n,B?Q+n:a(e),A,Q)}const l=A-Rt;Xe(t.figure,"data-chart-grid",e.grid)&&r.prepend(_("path",{class:N,d:c.map(t=>B?`M${O(a(t))},0V${O(Q)}`:`M0,${O(a(t))}H${O(l)}`).join("")})),R.numbers&&r.appendChild(_("path",{class:k,d:[B?`M${O(a(F.min))},${O(Q)}H${O(a(F.max))}`:`M0,${O(a(F.max))}V${O(a(F.min))}`,...c.map(t=>B?`M${O(a(t))},${O(Q)}v${O(4*P)}`:`M0,${O(a(t))}h${O(-4*P)}`)].join("")}))}for(const[n,o]of x.entries()){o.badge?.setAttribute("data-note",String(n+1));const e=o.series;o.type.draw(o.spec,o.badge,{...jt,...t.stacked&&{rows:tt,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&Dt(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??"",T(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))}}ve(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 Kt=t.categories[0]?.parentElement;if(Kt&&"beside"!==g.categories&&!g.centre){Kt.style.height=`${Kt.offsetHeight}px`,Kt.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(!ct(Kt,n,t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit")&&n.length>1){const t=getComputedStyle(Kt),e=(Kt.clientWidth-Number.parseFloat(t.paddingLeft)-Number.parseFloat(t.paddingRight))/m.length;Kt.style.setProperty("--_name-fit","1"),Kt.setAttribute("data-thinned","");const a=D(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=Kt.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===It||g===Wt)&&Xe(t.figure,"data-chart-ticks",e.ticks);if(Kt.toggleAttribute("data-ticks",a),Kt.style.removeProperty("--_tick-reach"),a){const e=Q-Number(r.querySelector(".tablechart-rule")?.getAttribute("y1")??Q);e>0&&e<10*P&&Kt.style.setProperty("--_tick-reach",`${O(e/P)}px`);const n=Kt.getBoundingClientRect(),a=n.width/(Kt.offsetWidth||1),o=getComputedStyle(Kt),s=Number.parseFloat(o.paddingLeft),c=(Kt.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-Kt.clientLeft;t.style.setProperty("--_tick",`${O(s+(e+.5)*c-o)}px`)}})}Kt.style.height=""}const Yt=x.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*P,n=t.offsetHeight*P,a=Number.parseFloat(t.style.left)/100*A,o=Number.parseFloat(t.style.top)/100*Q,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*P;return[_("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("; ")})]}),Zt=r.querySelector(`.${N}`),Jt=Array.from(r.querySelectorAll(`.${c}`)),Xt=[...Zt?[Zt]:[],...r.querySelectorAll(`:scope > .${l}`)],Qt=((t,e)=>{const n=t.getBoundingClientRect(),a=A/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?[_("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,P),ne="grow"===t.figure.getAttribute("data-animate"),re=y.flat().filter(t=>t.hasAttribute("data-cut")).flatMap(Qt),se=[...it.flatMap(t=>y[t].flatMap(Qt)),...ne?re:[]];if(Xt.length||Jt.length){const e=[...y.flat(),...t.totals,..."beside"===g.categories?t.categories:[]].flatMap(Qt),n=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Jt)Ye(t,[...e,...Yt].map(n));for(const t of Xt){const a=[...e,...Yt],o=Ze(t);t.setAttribute("d",o.map(([t,e,o,r])=>Ke(t,e,o,r,a.map(n))).join(""));for(const e of a){const a=Je(o,n(e)),r="badge"===e.dataset.for?"badge":"";a&&t.after(_("path",{class:t.getAttribute("class")??"tablechart-grid","data-gap":r,d:a,style:e.getAttribute("style")??""}))}}}if(V(r,Yt,A,Q,Array.from(r.querySelectorAll(`.${s}, .${i}`))),!ne&&(jt.lineHoles.length||re.length)){const t=Array.from(r.querySelectorAll(`.${d}`)).map(t=>{const e=_("g",{});return t.before(e),e.append(t),e});V(r,[...jt.lineHoles,...re],A,Q,[...t,...r.querySelectorAll(`.${h}`)])}const ce=[c,l,s,i,N];I(r,[...Yt,...se],A,Q,void 0,ce.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||gn(r);const le=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(g.columns?[t.categories]:[...y,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||g.centre&&m[Number(t.dataset.row)-1]?.isTotal)(e)&&!le(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>le(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),jt.barRadius&&((t,e)=>{for(const n of t.querySelectorAll("rect[data-end]")){const[t,a,o,r]=["x","y","width","height"].map(t=>Number(n.getAttribute(t))),s=n.getAttribute("data-end"),c="left"===s||"right"===s,l=O(Math.min(e,c?r/2:o/2,c?o:r)),i=(t,e)=>`a${l},${l} 0 0 1 ${t},${e}`,u={top:`M${t},${O(a+r)}v${O(l-r)}${i(l,-l)}h${O(o-2*l)}${i(l,l)}v${O(r-l)}z`,bottom:`M${O(t+o)},${a}v${O(r-l)}${i(-l,l)}h${O(2*l-o)}${i(-l,-l)}v${O(l-r)}z`,right:`M${t},${a}h${O(o-l)}${i(l,l)}v${O(r-2*l)}${i(-l,l)}h${O(l-o)}z`,left:`M${O(t+o)},${O(a+r)}h${O(l-o)}${i(-l,-l)}v${O(2*l-r)}${i(l,-l)}h${O(o-l)}z`}[s],d=_("path",{d:u});for(const{name:e,value:h}of Array.from(n.attributes))["x","y","width","height"].includes(e)||d.setAttribute(e,h);n.replaceWith(d)}})(r,jt.barRadius),fe(t.figure),we(t.figure),Me(t.figure),!0})(a,e))&&(g||(g=!0,(t=>{const e=be(t),a=Mn[le(t)],o=Array.from(t.querySelectorAll("table thead tr:first-child > *")).map(t=>(t.textContent??"").trim()),r=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),s=[[".tablechart-series","Line",t=>getComputedStyle(t).stroke],[".tablechart-slice","Slice",t=>getComputedStyle(t).stroke],[".tablechart-bar, .tablechart-piece","Bar",t=>getComputedStyle(t).fill]],c=new Map;for(const[n,l,i]of s){const s=Array.from(t.querySelectorAll(`${n}:not([data-muted])`));for(const n of s){const u=i(n),[d,h,f,b]=se(u),m=[d,h,f].map((t,n)=>t*b+e[n]*(1-b)),$=ue(le(t),m,e);if($>=a.part)continue;const p=n.getAttribute("data-series"),g=r[Number(n.getAttribute("data-row")??0)-1]??"",w="Slice"===l?"":p?o[Number(p)]:"",M=`${l}|${w}|${u}`,y=c.get(M)??{kind:l,column:w,rows:new Set,all:0,contrast:$};y.rows.add(g),y.all=s.filter(t=>t.getAttribute("data-series")===p).length,c.set(M,y)}}for(const{kind:l,column:i,rows:u,all:d,contrast:h}of c.values()){const e=Array.from(u).filter(Boolean).map(t=>`"${t}"`),o=e.join(", "),r=e.length>1,s="Line"===l?i?`Line "${i}" has`:"The line has":"Slice"===l?`${r?"Slices":"Slice"} ${o} ${r?"have":"has"}`:u.size>=d||!o?`The bars${i?` of column "${i}"`:""} have`:`${r?"Bars":"Bar"} ${o}${i?` in column "${i}"`:""} ${r?"have":"has"}`;console.warn(`[${n}] ${s} a contrast of ${a.show(h)} with the background. It needs at least ${a.need(a.part)} (${a.partRule}).`,t)}})(a.figure),(t=>{let e=0;const a=()=>{const a=Array.from(t.querySelectorAll(".tablechart-value[data-place='inside'], .tablechart-value[data-place='middle']")).filter(t=>!t.hasAttribute("data-left-out")&&!t.hidden),r=Array.from(t.querySelectorAll(".tablechart-name, .tablechart-value:not([data-place='inside'], [data-place='middle']), .tablechart-categories span, .tablechart-centre, .tablechart-tick, .tablechart-quadrant-name, figcaption b, figcaption span")).filter(t=>!t.hasAttribute("data-left-out")&&!t.hidden&&"1"!==t.style.getPropertyValue("--m")&&(t.textContent??"").trim()&&"hidden"!==getComputedStyle(t).visibility);if([...a,...r].some(t=>0===se(getComputedStyle(t).color)[3]&&e<20))return e++,void setTimeout(o,500);const s=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),c=Mn[le(t)],l="bar"===t.dataset.chart?"bar":"column",i=new Map;for(const e of a){const n=me(t,e);if(!n)continue;const a=getComputedStyle(e),o=getComputedStyle(n).fill,r=ue(le(t),se(a.color),se(o)),u=Number.parseFloat(a.fontSize),d=u>=24||u>=18.66&&Number(a.fontWeight)>=700?c.large:c.text;if(r>=d)continue;const h=n.classList.contains("tablechart-piece")?`${l} part`:l,f=`${a.color}|${o}`,b=i.get(f)??{what:h,names:[],contrast:r,needed:d};b.names.push(`"${s[Number(e.dataset.row)-1]??""}" ("${e.textContent?.trim()}")`),i.set(f,b)}const u=be(t),d=new Map;for(const e of r){const n=getComputedStyle(e),[a,o,r,s]=se(n.color),l=[a,o,r].map((t,e)=>t*s+u[e]*(1-s)),i=ue(le(t),l,u),h=Number.parseFloat(n.fontSize),f=h>=24||h>=18.66&&Number(n.fontWeight)>=700?c.large:c.text;if(i>=f)continue;const b=d.get(n.color)??{names:[],contrast:i,needed:f};b.names.push(`"${e.textContent?.trim()}"`),d.set(n.color,b)}for(const{names:e,contrast:o,needed:h}of d.values())console.warn(`[${n}] The text ${e.join(", ")} has a contrast of ${c.show(o)} with the background. Text needs at least ${c.need(h)} (${c.textRule}).`,t);for(const{what:e,names:o,contrast:h,needed:f}of i.values()){const a=o.length>1;console.warn(`[${n}] The text inside the ${e}${a?"s":""} of ${o.join(", ")} has a contrast of ${c.show(h)} with ${a?"those":"that"} ${e}${a?"s":""}. Text needs at least ${c.need(f)} (${c.textRule}).`,t)}},o=()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{const e=t.getAnimations({subtree:!0}).map(t=>t.finished.catch(()=>{}));Promise.all(e).then(a)}));if(t.classList.contains("is-shown"))return void o();const r=new MutationObserver(()=>{t.classList.contains("is-shown")&&(r.disconnect(),o())});r.observe(t,{attributes:!0,attributeFilter:["class"]})})(a.figure),(t=>{const e=getComputedStyle(t);for(const a of yn)!vn.has(a)&&e.getPropertyValue(a).trim()&&(vn.add(a),console.warn(`[${n}] ${a} is old and goes in 1.3.0. --tablechart-value-on-dark and --tablechart-value-on-light set the colour of the numbers inside bars, with a contrast check.`,t))})(a.figure)),m=t,v())};let H=!1;const L=new ResizeObserver(()=>{C(),L.unobserve(a.figure),requestAnimationFrame(()=>H||L.observe(a.figure))}),B=new IntersectionObserver(t=>{for(const e of t)w=e.isIntersecting,v()},{threshold:e.threshold}),R=()=>{a.figure.classList.add(y),mn(a,!0),wn(a.svg),a.figure.offsetWidth},U=()=>a.figure.classList.remove(y),F=()=>{m=null,C()},q={relabel:()=>fn(a,e),refresh:F};x(),C(),L.observe(a.figure),B.observe(a.figure),window.addEventListener("beforeprint",R),window.addEventListener("afterprint",U),(t=>{_n.add(t),Bn||(Bn=new MutationObserver(()=>{for(const t of _n)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of _n)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(q);const P={figure:a.figure,refresh:F,next:()=>xe(a,a.step+1),previous:()=>xe(a,a.step-1),stepTo:t=>xe(a,t),get step(){return a.step},get steps(){return a.plan?.count??0},destroy(){H=!0,L.disconnect(),B.disconnect(),window.removeEventListener("beforeprint",R),window.removeEventListener("afterprint",U),(t=>{_n.delete(t),!_n.size&&Bn&&(Bn.disconnect(),Bn=null)})(q),Ve(a),a.figure.tablechart===P&&delete a.figure.tablechart}};return a.figure.tablechart=P,P})(a,e)):null},qn=!1,Pn=new WeakMap,Vn=()=>{if(qn||"function"!=typeof matchMedia)return;qn=!0;const t=()=>{for(const t of document.querySelectorAll(`[${Ln}]`)){const e=getComputedStyle(t).color,n=fe(t)||Pn.get(t)!==e;Pn.set(t,e),n&&(we(t),Me(t))}};matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t);const e=new MutationObserver(t);for(const n of[document.documentElement,document.body])e.observe(n,{attributes:!0});document.addEventListener("transitionend",e=>{e.target!==document.documentElement&&e.target!==document.body||t()})},In=e({GRID_CLASS:()=>N,LEGEND_CLASS:()=>b,LIBRARY_NAME:()=>n,NAME_CLASS:()=>f,POINT_CLASS:()=>m,QUADRANT_CLASS:()=>l,VIEWBOX_WIDTH:()=>A,avoidCollisions:()=>tt,boxOf:()=>ut,decimalsIn:()=>G,htmlEl:()=>z,largest:()=>D,markerEl:()=>Bt,overlaps:()=>Q,placeAt:()=>E,readSeries:()=>Xt,readTable:()=>Zt,short:()=>O,sizeOf:()=>at,splitSign:()=>K,svgEl:()=>_});window.Tablechart={init:async(t={},e=document)=>{const n={...C,...t};n.debug&&(Gt.enabled=!0);const a=(await Un(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Fn(t,n)).filter(t=>null!==t);return Gt.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={...C,...e};n.debug&&(Gt.enabled=!0);const[a]=await Un([t],n);return a?Fn(a,n):null},defaultConfig:C,addType:(t,e)=>{Ie[t]=e,Object.assign(We,e.annotations),je.splice(0,1/0,...Object.keys(We))},kit:In}}();
1
+ !function(){var t,e,n=Object.defineProperty,a=(t,e)=>{let a={};for(var o in t)n(a,o,{get:t[o],enumerable:!0});return e||n(a,Symbol.toStringTag,{value:"Module"}),a},o="tablechart",r="tablechart-categories",s="tablechart-value",c="tablechart-bar",l="tablechart-rule",i="tablechart-line",u="tablechart-reference",d="tablechart-quadrant",h="tablechart-head",f="tablechart-slice",b="tablechart-series",m="tablechart-area",$="tablechart-name",p="tablechart-legend",g="tablechart-point",w="tablechart-hole",M="tablechart-centre",y="tablechart-break",v="tablechart-sr",x="is-shown",k="is-printing",S="is-at-once",N="is-built",A="tablechart-axis",C="tablechart-tick",H="tablechart-grid",T=1e3,L={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,lines:null,summary:"auto",totallabel:"Total",controls:!0,previouslabel:"Previous",nextlabel:"Next",stephint:"step of the chart",threshold:.5,replay:!1,langattribute:"data-i18n"},_=(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],O=(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=>_(t,e)));return e.forEach(s),t.map(t=>{const e=t.findIndex(c);return e<0?null:(s(t[e]),e)})},z=new WeakMap,B=t=>{const e=[...t].filter(t=>!!t),n=e.map(t=>({width:t.offsetWidth,height:t.offsetHeight}));e.forEach((t,e)=>z.set(t,n[e]))},E=t=>z.get(t)??{width:t.offsetWidth,height:t.offsetHeight},R=(t,e,n)=>t.some(t=>E(t).width*n>e-6*n),q=(t,e,n)=>e>=E(t).height*n*1.6,F=(t,e,n)=>e>=E(t).width*n*1.5,U=(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},P=(t,e)=>{t.sort((t,e)=>t.y-e.y);const n=[],a=t=>t.sum/t.items.length-(t.items.length-1)*e/2;for(const o of t){let t={items:[o],sum:o.y};for(let o=n.at(-1);o&&a(o)+o.items.length*e>a(t);o=n.at(-1))n.pop(),t={items:[...o.items,...t.items],sum:o.sum+t.sum};n.push(t)}for(const o of n)o.items.forEach((t,n)=>t.y=a(o)+n*e);return t},V={outside:[.5,1],below:[.5,0],after:[0,.5],before:[1,.5]},W=(t,e,n,a,o=[.5,.5])=>{const[r,s]=V[t.dataset.place??""]??o,{width:c,height:l}=E(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]},I=(t,e,n)=>{for(const a of t){if("none"===a.dataset.place||!a.style.left)continue;const[t]=V[a.dataset.place??""]??[.5,.5],o=E(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+"%")}},j=(t,e,n,a)=>{const o=t.filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out")),r=G(o,e,n,a);o.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")})},G=(t,e,n,a)=>{if(t.length<2)return 1;const o=t.map(t=>W(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},D="cubic-bezier(0.3, 0.3, 0.6, 1)",K=(t,e,n=1)=>({start:t,span:e,easing:t+e>=n-1e-4?D:"linear"}),Y=(t,e)=>`${t}:${e}`,Z=t=>Math.round(100*t)/100,J=(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?Z(t):t))}return n},X=(t,e)=>[t,...e.classes].join(" "),Q=(t,e)=>{const n=document.createElement("span");return n.className=t,n.inert=!0,e.appendChild(n),n},tt=(t,e,n,a,o)=>{t.style.left=e/a*100+"%",t.style.top=n/o*100+"%"},et=0,nt=0,at=0,ot=t=>{let e=t.querySelector(":scope > defs");return e||(e=J("defs"),t.prepend(e)),e},rt=t=>{if("circle"===t.tagName){const[e,n,a]=["cx","cy","r"].map(e=>Number(t.getAttribute(e))||0);return`M${Z(e-a)},${Z(n)}a${Z(a)},${Z(a)} 0 1 0 ${Z(2*a)},0a${Z(a)},${Z(a)} 0 1 0 ${Z(-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${Z(c)},${Z(l)} 0 0 1 ${Z(t)},${Z(e)}`:"";return`M${Z(e+c)},${Z(n)}h${Z(a-2*c)}${i(c,l)}v${Z(o-2*l)}${i(-c,l)}h${Z(2*c-a)}${i(-c,-l)}v${Z(2*l-o)}${i(c,-l)}z`},st=(t,e,n,a,o)=>{if(!e.length||!o.length)return;const r="tablechart-clip-"+ ++nt,s=J("clipPath",{id:r,clipPathUnits:"userSpaceOnUse"}),c=`M${-n},${-a}h${3*n}v${3*a}h${3*-n}z`;s.appendChild(J("path",{d:c+e.map(rt).join(""),"clip-rule":"evenodd"})),ot(t).appendChild(s);for(const l of o)l.setAttribute("clip-path",`url(#${r})`)},ct=(t,e,n,a,o,r)=>{if(!e.length)return;const s="tablechart-cut-"+ ++et,c=J("mask",{id:s,maskUnits:"userSpaceOnUse"});c.appendChild(J("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=ot(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(J("g",{mask:`url(#${s})`}))),i.appendChild(u)))},lt=t=>{let e=Number.NEGATIVE_INFINITY;for(const n of t)e=Math.max(e,n);return e},it=t=>(t.split(/[.,]/)[1]||"").length,ut=(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("")]},dt=t=>Number.parseFloat((t.match(/-?[\d.,]+/)||["NaN"])[0].replace(",",".")),ht=(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},ft=(t,e,n,a,r="%")=>{const s=t?.textContent||"",c=dt(s),l=r?.5:.5*10**-it(s.match(/-?[\d.,]+/)?.[0]??""),i=!!Number.isNaN(c)||Math.abs(e-c)<=l+1e-9,u={label:n,computed:e,stated:c,agrees:i};a.checks.push(u),i||console.warn(`[${o}] An annotation reads ${c}${r}, but ${n} is ${Number(e.toFixed(2))}${r}. The chart shows your number.`)},bt={create(t,e){if(!t.textContent?.trim())return null;const n=ht(t,e);return n.dataset.kind="note",n},draw(t,e,n){const{rows:a,cx:r,y:s,height:c,unit:l,svg:i,after:d,seriesValues:h}=n;if(n.x||n.centre||"beside"===n.categories[0]?.parentElement?.dataset.place)return void console.warn(`[${o}] 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(`[${o}] A note is for row "${f}", which is not there.`);const m=r(b),$=s(0);if(i.insertBefore(J("line",{class:u,"data-kind":"note","data-note":n.note,x1:m,x2:m,y1:0,y2:$,style:Y("--after",d)}),i.querySelector(`:scope > .${g}`)),!e)return;const p=E(e).width*l,w=E(e).height*l,M=4*l,y=h.flat().flatMap(t=>!t.style.left||"none"===t.dataset.place||t.hasAttribute("data-left-out")?[]:[{label:t,box:W(t,l,T,c)}]),v=[0,w+M/2].flatMap(t=>[[m-p/2,t,p,w],[m+M,t,p,w],[m-M-p,t,p,w]]),[x]=O([v],[...n.taken,...y.map(t=>t.box)],[0,0,T,c]),k=v[x??0];if(n.taken.push(k),tt(e,k[0]+p/2,k[1]+w/2,T,c),e.style.setProperty("--after",String(d)),null===x)for(const o of y)_(o.box,k)&&o.label.setAttribute("data-left-out","")}},mt=["circle","square","diamond"],$t=(t,e)=>{const n=t[e]?.marker?.toLowerCase().split(/\s+/)??[];if(n.includes("none"))return{shape:"none",open:!1};const a=mt.find(t=>n.includes(t));return{shape:a??mt[Math.floor(e/2)%mt.length],open:n.includes("open")||!n.includes("filled")&&!a&&e%2==1}},pt=(t,e,n,a,o={})=>{if("square"===t){const t=.88*a;return J("rect",{x:e-t,y:n-t,width:2*t,height:2*t,...o})}if("diamond"===t){const t=1.2*a;return J("polygon",{points:`${e},${n-t} ${e+t},${n} ${e},${n+t} ${e-t},${n}`,...o})}if("triangle"===t){const t=1.3*a;return J("polygon",{points:`${e},${n-.75*t} ${e+.87*t},${n+.75*t} ${e-.87*t},${n+.75*t}`,...o})}return J("circle",{cx:e,cy:n,r:a,...o})},gt=(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}},wt=(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}); ${Y("--i",e.slot)}`}},Mt=(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}})},yt=(t,e,n=!1)=>{const a=Mt(t,e,n);return{top:Math.max(0,...a.map(t=>t.to)),bottom:Math.min(0,...a.map(t=>t.to))}},vt=(t,e)=>{const{top:n,bottom:a}=yt(t,e);return n+a},xt=(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})`)},kt=(t,e)=>t.barRadius?{"data-end":e}:{},St=(t,e)=>t.some((n,a)=>a!==e&&!n.cell.missing&&n.to!==n.from&&n.from===t[e].to),Nt=(t,e,n,a={},o="")=>{const r={class:X(c,e),"data-kind":"bar","data-row":n+1,...a},s=Y("--i",e.slot)+(o?`; transform-origin: ${o}`:""),l=J("g",{...r,"data-stack":"",style:s});return t.svg.appendChild(l),(o,r)=>{const s=void 0!==a["data-grow"]?{"data-grow":a["data-grow"]}:{};l.appendChild(J("rect",{...s,...r,class:X("tablechart-piece",e),"data-row":n+1,...wt(t,e,o)}))}},At={enabled:!1,log(...t){At.enabled&&console.log(`[${o}]`,...t)},timed(t,e,n){if(!At.enabled)return n();const a=performance.now(),r=n(),s=performance.now()-a,c=e.querySelectorAll("tbody tr").length;return s>50?console.warn(`[${o}] ${t} took ${s.toFixed(1)} ms for ${c} rows, more than 50 ms.`,e):At.log(`${t} took ${s.toFixed(1)} ms for ${c} rows.`,e),r}},Ct=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}},Ht=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).flatMap((t,e)=>t.hasAttribute("data-note")?[e]:[]),Tt=(t,e="data-i18n")=>{const n=Ht(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(Ct);s.length||s.push(Ct(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}})},Lt=t=>Array.from(t.querySelector("thead tr:last-child")?.children??[]).slice(1).filter(t=>!t.hasAttribute("data-note")),_t=(t,e,n="data-i18n")=>{const a=Lt(t),o=Math.max(1,lt(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||"dash-dot"===r?r:null),group:!!o?.hasAttribute("data-group"),chart:"line"===o?.getAttribute("data-chart")?"line":null};var r})},Ot=["axis-break","trend","bracket"],zt=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))}},Bt=(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)),zt(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}}))},Et="tablechart-tooltip",Rt=["--tablechart-surface","--_surface","--tablechart-tooltip-surface","--tablechart-tooltip-color","--tablechart-tooltip-border","--tablechart-tooltip-radius","--tablechart-tooltip-padding","--tablechart-tooltip-shadow"],qt=null,Ft=null,Ut=null,Pt=0,Vt=()=>{clearTimeout(Pt),qt&&Ft&&(qt.hidden=!0,Ft=null,Ut=null)},Wt=!1,It=!0,jt=NaN,Gt=NaN,Dt=!1,Kt=(t,e)=>e/Number.parseFloat(getComputedStyle(t).width)||1,Yt=()=>{clearTimeout(Pt),Pt=window.setTimeout(Vt,120)},Zt=(t,e)=>{const n=e?e.style.getPropertyValue("--step"):"x";return""===n||Number(n)<t.step},Jt=(t,e)=>{const n=t.svg.querySelector(`[data-series="${e+1}"]:not(.tablechart-hole, .tablechart-area:not([data-stacked]))`);if(!n)return;const a=getComputedStyle(n);return a.fill&&"none"!==a.fill?a.fill:a.stroke},Xt=(t,e,n)=>{const a=t.series.length>1,o=[];for(const[s,c]of t.seriesValues.entries()){if(!Zt(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?Jt(t,s):void 0,sample:n?{marker:n.dataset.marker??null,open:n.hasAttribute("data-open"),line:n.dataset.line??null,point:getComputedStyle(n).getPropertyValue("--tablechart-point-color").trim(),box:"box"===n.dataset.swatch}:void 0})}const r=t.totals[e];return o.length>1&&Zt(t,r)&&o.push({name:n.totallabel,value:r.textContent??""}),o},Qt=(n,a,o)=>{if(clearTimeout(Pt),Ft===n&&Ut===a)return;const r=(n.type.tooltip??Xt)(n,a,o);if(!r.length)return Vt();Ft&&Ft!==n&&Vt(),qt??(qt=(()=>{const n=document.createElement("div");return n.className=Et,n.setAttribute("aria-hidden","true"),n.hidden=!0,t=document.createElement("div"),(e=document.createElement("div")).className=`${Et}-arrow`,n.append(t,e),document.body.append(n),n.addEventListener("pointerenter",()=>clearTimeout(Pt)),n.addEventListener("pointerleave",t=>"mouse"===t.pointerType&&Yt()),document.addEventListener("pointerdown",t=>{const e=t.target;!Ft||Ft.plot.contains(e)||n.contains(e)||Vt()}),window.addEventListener("resize",Vt),n})());const s=(t,e,n,a=!1,o)=>{const r=document.createElement("div");if(r.className=`${Et}-line`,n){const t=document.createElement("span");t.className=`${Et}-key`,t.style.backgroundColor=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),o.point&&t.style.setProperty("--tablechart-point-color",o.point),t.toggleAttribute("data-open",o.open)),r.append(t)}const s=document.createElement("span");if(s.className=`${Et}-${a?"title":"name"}`,s.textContent=t,r.append(s),e){t&&s.append(":");const n=document.createElement("span");n.className=`${Et}-value`,n.textContent=e,r.append(n)}return r},c=(n.figure.querySelectorAll("tbody tr")[a]?.querySelector("th"))?.textContent?.trim()||n.categories[a]?.textContent||n.rows[a].label,l=1===r.length&&!r[0].name,i=r.every(t=>t.name&&!t.value),u=((t,e)=>{const n=Ht(t),a=t.querySelectorAll("tbody tr")[e]?.querySelectorAll("td")??[];return n.map(t=>a[t]).find(t=>t?.textContent?.trim())??null})(n.figure,a)?.textContent?.trim(),d=u?[Object.assign(document.createElement("div"),{className:`${Et}-note`,textContent:u})]:[];t.replaceChildren(...i?[]:[s(c,l?r[0].value:"",void 0,!0)],...l?[]:r.map(({name:t,value:e,colour:n,sample:a})=>s(t,e,n,!1,a)),...d);const h=getComputedStyle(n.figure);for(const t of Rt){const e=h.getPropertyValue(t).trim();e?qt.style.setProperty(t,e):qt.style.removeProperty(t)}qt.style.setProperty("--_color",h.color),qt.style.colorScheme=h.colorScheme,qt.style.fontFamily=h.fontFamily;const f=(t=>{const e=t.tooltipparent;return("string"==typeof e?document.querySelector(e):e)??document.body})(o);qt.parentElement!==f&&f.append(qt),Ft=n,Ut=a,qt.hidden=!1,qt.style.left="0px",qt.style.top="0px";const b=qt.getBoundingClientRect(),m={x:b.left,y:b.top,scale:Kt(qt,b.width)},$=Kt(n.plot,n.plot.getBoundingClientRect().width);qt.style.fontSize=Number.parseFloat(h.fontSize)*$/m.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,M=Math.max(r,Math.min(w-l/2,f-l-r));t.style.left=(M-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-M,l-h))/a.scale-u+"px"})(qt,e,((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/T,o=4*a*(T/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)})(n,a),m)},te=t=>{Ft===t&&Vt()},ee=(t,e,n)=>{const{prefix:a="",suffix:o=""}=t.dataset,[r,s]=ut(Number.parseFloat(t.dataset.value||"0"),e,n);if(t.textContent=a+(a?r:"")+s+o,r&&!a){const e=document.createElement("span");e.className="tablechart-minus",e.textContent=r,t.prepend(e)}},ne=(t,e,n,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*T:s*("em"===r[2]?Number.parseFloat(o.fontSize):"rem"===r[2]?Number.parseFloat(getComputedStyle(document.documentElement).fontSize):1)*e},ae=(t,e)=>{const n=ne(t,e,"--tablechart-height","none");return[n??ne(t,e,"--tablechart-min-height","200px")??0,n??ne(t,e,"--tablechart-max-height","none")??Number.POSITIVE_INFINITY]},oe=(t,e,n)=>ne(t,e,getComputedStyle(t).getPropertyValue(n).trim()?n:"--tablechart-corner-radius","0px")??0,re=(t,e,n)=>{const a=t.getAttribute(e);return null===a?n:"false"!==a},se=["straight","step","smooth"],ce=(t,e)=>{const n=t.dataset.chartShape;return n&&se.includes(n)?n:se.includes(e.shape)?e.shape:"straight"},le=(t,e)=>Boolean(e.animate)&&"false"!==t.getAttribute("data-chart-animate"),ie=0,ue={create:()=>null,draw(t,e,n){const{rows:a,y:o,svg:r,breakAt:s}=n;if(null===s)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-"+ ++ie,h=J("mask",{id:d,maskUnits:"userSpaceOnUse"});h.appendChild(J("rect",{x:-1e3,y:-n.height,width:3e3,height:3*n.height,fill:"white"}));const f=[],b=o(s);for(const g of(t=>Array.from(t.querySelectorAll(`.${c}`)).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}}))(r)){const t=g.sideways?n.breakX:b;if(void 0===t)continue;if(!(g.sideways?g.x<t&&g.x+g.width>t:g.y<b&&g.y+g.height>b))continue;const[e,o]=g.sideways?[i(g,t),i(g,t+n.breakGap)]:[i(g,b-n.breakGap),i(g,b)];h.appendChild(J("path",{d:u([...e,...o.slice().reverse()],!0),fill:"black"})),f.push(e,o);const s=[Y("--after",a[g.row-1]?.slot??0),g.part].filter(Boolean).join("; ");for(const a of[e,o])r.appendChild(J("path",{class:y,"data-part":"edge","data-note":n.note,d:u(a),style:s}))}if(!f.length)return;const m=Array.from(r.querySelectorAll(`.${y}`)),$=J("g",{mask:`url(#${d})`});for(const c of Array.from(r.childNodes))m.includes(c)||$.appendChild(c);const p=J("defs");p.appendChild(h),r.prepend(p,$)}},de={create:ht,draw(t,e,n){const{rows:a,cx:r,y:s,unit:c,labelHeight:l,badgeHeight:u,height:d,svg:f,after:b}=n,[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,a.length),p=a[m],g=a[$];if(!p||!g)return void console.warn(`[${o}] A bracket points at a row that is not there (row ${m+1} to ${$+1}, of ${a.length}).`);const w=7*c,M=4*c,y=r(m),v=r($),x=Math.min(s(p.value),s(g.value))-l-M-.9*u,k=t=>s(t)-l-M,S=`M ${y} ${k(p.value)} L ${y} ${x} L ${v} ${x} L ${v} ${k(g.value)-w}`,N=(k(p.value)-x+Math.abs(v-y)+(k(g.value)-w-x))/c+1;f.appendChild(J("path",{class:i,"data-note":n.note,d:S,style:`--len:${N.toFixed(1)}; ${Y("--after",b)}`}));const A=k(g.value);var C;f.appendChild(J("polygon",{class:h,"data-note":n.note,points:`${v},${A} ${v-.45*w},${A-w} ${v+.45*w},${A-w}`,style:Y("--after",b)})),e&&(tt(e,(y+v)/2,x,T,d),e.style.setProperty("--after",String(b))),ft(e,(C=p.value,(g.value-C)/Math.abs(C)*100),`${p.value} to ${g.value}`,n)}},he=(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},fe={create(t,e){if(!t.textContent?.trim())return null;const n=ht(t,e);return n.dataset.kind="reference",n},draw(t,e,n){const{rows:a,cx:r,y:s,x:c,height:l,unit:i,svg:d,after:h}=n,f=a.filter(t=>!t.isTotal&&!t.missing),b=t.hasAttribute("data-name"),m=(t.getAttribute(b?"data-name":"data-value")??"").trim();let $,p,w;if(b){const t=f.map(t=>dt(t.label));if("beside"===n.categories[0]?.parentElement?.dataset.place||t.some(Number.isNaN))return void console.warn(`[${o}] A reference line among the names needs names that are numbers, under columns or points.`);const e=he(m,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(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,p=s<0?null:c+i*(l-c),$=!1}else{const e=Boolean(n.frame)&&"y"===t.getAttribute("data-axis"),a=n.frame?n.series.flatMap((t,e)=>t.group?[]:[e])[e?1:0]??0:0;w=he(m,f.map(t=>t.cells[a]?.value??t.value),f.map(()=>1)),$=e||!c,p=null===w?null:c&&!e?c(w):s(w)}if(null===p||null===w)return void console.warn(`[${o}] A reference line needs a number, "mean" or "median", not "${m}".`);const[M,y,v,x]=n.frame?[n.frame[0],n.frame[1],n.frame[0]+n.frame[2],n.frame[1]+n.frame[3]]:[0,0,a.length>0?r(a.length-1)+r(0):T,c?l:s(0)];if(d.insertBefore(J("line",{class:u,"data-note":n.note,..."dotted"===t.getAttribute("data-line")&&{"data-line":"dotted"},...$?{x1:M,x2:v,y1:p,y2:p}:{x1:p,x2:p,y1:y,y2:x},style:Y("--after",h)}),d.querySelector(`:scope > .${g}`)),e){const t=E(e).width*i,a=E(e).height*i,o=4*i,r=$?[[v-t,p-a/2,t,a],[v-t,p-a-o,t,a],[v-t,p+o,t,a]]:[y,y+a,y+2*a].flatMap(e=>[[p-t/2,e,t,a],[p+o,e,t,a],[p-o-t,e,t,a]]),[s]=O([r],n.taken,[0,0,T,l]),c=r[s??0];n.taken.push(c),tt(e,c[0]+t/2,c[1]+a/2,T,l),e.style.setProperty("--after",String(h)),"mean"!==m&&"median"!==m||ft(e,w,`the ${m}`,n,"")}}},be={create:ht,draw(t,e,n){const{rows:a,cx:o,y:r,unit:s,labelHeight:c,height:l,svg:u,values:d,after:f}=n,b=a[0],m=a[a.length-1];if(!b||!m)return;const $=c+18*s,p=10*s,g=10*s;let w=o(0),M=r(b.value)-$,y=o(a.length-1),v=r(m.value)-$,x=0;a.forEach((t,e)=>{const n=y===w?0:(o(e)-w)/(y-w),a=M+n*(v-M)-(r(t.value)-$);a>x&&(x=a)}),M-=x,v-=x;const k=y-w,S=v-M,N=Math.hypot(k,S)||1,A=k/N,C=S/N;w-=A*p,M-=C*p,y+=A*p,v+=C*p;const H=Number.parseFloat(t.getAttribute("data-at")||"0.5");if(e){const t=w+(y-w)*H,n=M+(v-M)*H,l=E(e).width*s/2,i=n+E(e).height*s/2+8*s;let u=0;a.forEach((e,n)=>{const a=(d[n]?E(d[n]).width:0)*s/2;if(Math.abs(o(n)-t)>=l+a)return;const h=r(e.value)-7*s-c;u=Math.max(u,i-h)}),M-=u,v-=u}const L=y-A*g,_=v-C*g,O=Math.hypot(L-w,_-M)/s+1;u.appendChild(J("line",{class:i,"data-note":n.note,x1:w,y1:M,x2:L,y2:_,style:`--len:${O.toFixed(1)}; ${Y("--after",f)}`}));const z=-C,B=A,R=.42*g;u.appendChild(J("polygon",{class:h,"data-note":n.note,points:[`${y},${v}`,`${L+z*R},${_+B*R}`,`${L-z*R},${_-B*R}`].join(" "),style:Y("--after",f)})),e&&(tt(e,w+(y-w)*H,M+(v-M)*H,T,l),e.style.setProperty("--after",String(f)));const q=Number.parseFloat(t.getAttribute("data-years")||"");!Number.isNaN(q)&&q>0&&ft(e,((t,e,n)=>100*(Math.pow(e/t,1/n)-1))(b.value,m.value,q),`${b.value} to ${m.value} over ${q} years`,n)}},me=(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},$e={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:o,values:r,categories:s,config:i,barMax:u}=t,d=t.series.length>1,h=Math.max(lt(s.map(t=>E(t).width*a)),0),f=Math.min(h+10*a,420);s[0]?.parentElement?.style.setProperty("--_beside",`${((f-8*a)/T*100).toFixed(2)}%`);const b=T-4*a,m=t.stacked?Math.max(lt(t.rows.map(e=>yt(e,t.series.length).top)),0)||1:Math.max(lt(t.rows.flatMap(e=>e.cells.slice(0,t.series.length).map(t=>Math.abs(t.value)))),0)||1,$=t.stacked?Math.max(lt(t.rows.map(e=>-yt(e,t.series.length).bottom)),0):Math.max(lt(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,M=(e,n)=>me(Math.abs(e),w,n,t.squeeze,t.breakGap),y=n/e.length,v=t=>(t+.5)*y,x=Math.min(y*i.barfill,u),k=gt(y,t.series.length,u),S=r[0]??t.totals[0],N=S?E(S).height*a*.56:0,A=Math.max(((d&&!t.stacked?k.size:x)-N)/2,5*a),C=t=>E(t).width*a,H=t=>t.length?lt(t.map(C))+A+4*a:0,L=(e,n)=>(t.rows[n].cells[e]??t.rows[n].cells[0]).value,_=t.seriesValues.flatMap((t,e)=>t.map((t,n)=>({label:t,value:L(e,n)}))),O=e=>{const n=yt(t.rows[e],t.series.length);return 0===n.top&&n.bottom<0};let z=t.stacked?H(t.totals.filter((t,e)=>!O(e))):d?H(_.filter(t=>t.value>=0).map(t=>t.label)):0,B=t.stacked?H(t.totals.filter((t,e)=>O(e))):d?H(_.filter(t=>t.value<0).map(t=>t.label)):0;const R=(e,n)=>"inside"===t.labels&&F(e,n,a),q=d&&!t.stacked&&"inside"===t.labels&&!!S&&E(S).height*a<=k.size;if(q&&(z=B=0),q||!d&&!t.stacked){const t=d?_.filter(({label:t})=>void 0===t.dataset.missing):e.map((t,e)=>({label:r[e],value:t.value}));for(let e=0;e<3;e++){const e=b-f-z-B,n=t.filter(({label:t,value:n})=>!R(t,M(n,e))),a=H(n.filter(({value:t})=>t>=0).map(({label:t})=>t)),o=H(n.filter(({value:t})=>t<0).map(({label:t})=>t));if(a<=z&&o<=B)break;z=Math.max(z,a),B=Math.max(B,o)}}const P=b-f-z-B,V=f+B+M(g,P),W=t=>t<0?V-M(t,P):V+M(t,P);if(t.squeeze&&(t.breakX=W(t.squeeze.gap)),t.x=W,t.stacked){const e=t.length("--tablechart-stack-gap","1px")??a;return t.rows.forEach((o,r)=>{const c=yt(o,t.series.length),l=Nt(t,o,r,{"data-grow":"right"},c.bottom<0?V-W(c.bottom)+"px center":""),i=v(r)-x/2,u=Mt(o,t.series.length);u.forEach(({from:o,to:s,cell:c},d)=>{const h=t.seriesValues[d][r];if(h.dataset.place="none",c.missing||s===o)return;const f=Math.min(W(o),W(s)),b=Math.max(W(o),W(s)),m=St(u,d)?Math.min(e,(b-f)/2):0,[$,p]=W(s)>W(o)?[f,b-m]:[f+m,b];l(d,{x:$,y:i,width:Math.max(p-$,1),height:x,...s<o&&{"data-grow":"left"},...!St(u,d)&&kt(t,s<o?"left":"right")}),h.dataset.place="inside",h.toggleAttribute("data-left-out",!F(h,b-f,a)||E(h).height*a>x),xt(h,t,d),tt(h,(f+b)/2,v(r),T,n)});const d=t.totals[r];d&&(d.dataset.place=O(r)?"before":"after",tt(d,O(r)?W(c.bottom)-A:W(c.top)+A,v(r),T,n));const h=s[r];h&&tt(h,f-8*a,v(r),T,n)}),void o.appendChild(J("line",{class:l,x1:V,x2:V,y1:0,y2:n}))}if(d){const e=t.seriesValues.flat().filter(t=>void 0===t.dataset.missing),r=U(t.plot,e,t=>({size:E(t).height*a,room:k.size+.5*k.gap}),"--_fit");return t.rows.forEach((e,l)=>{t.series.forEach((s,i)=>{const u=e.cells[i]??e.cells[0],d=t.seriesValues[i][l];if(u.missing)return void(d.dataset.place="none");const h=W(u.value),f=u.value<0,b=v(l)+k.offset(i),m=Math.max(Math.abs(h-V),1);0!==u.value&&o.appendChild(J("rect",{class:X(c,e),"data-kind":"bar","data-row":l+1,"data-grow":f?"left":"right",x:f?V-m:V,y:b,width:m,height:k.size,...kt(t,f?"left":"right"),...wt(t,e,i)}));const $=q&&R(d,Math.abs(h-V)),p=Math.max(Math.min(A,Math.abs(h-V)-C(d)-6*a),6*a),g=f?1:-1;d.dataset.place=$?"inside":f?"before":"after",d.toggleAttribute("data-left-out",!r),$&&xt(d,t,i),tt(d,$?"center"===t.insideAlign?(V+h)/2:"start"===t.insideAlign?V-g*(p+C(d)/2):h+g*(p+C(d)/2):f?h-A:h+A,b+k.size/2,T,n)});const i=s[l];i&&tt(i,f-8*a,v(l),T,n)}),void o.appendChild(J("line",{class:l,x1:V,x2:V,y1:0,y2:n}))}const I=e.map((t,e)=>R(r[e],Math.abs(W(t.value)-V)));e.forEach((e,l)=>{const i=W(e.value),u=v(l),d=e.value<0,h=Math.abs(i-V),b=Math.max(h,1);0!==e.value&&o.appendChild(J("rect",{class:X(c,e),"data-kind":e.kind,"data-row":l+1,"data-grow":d?"left":"right",x:d?V-b:V,y:u-x/2,width:b,height:x,...kt(t,d?"left":"right"),style:Y("--i",e.slot)}));const m=r[l],$=Math.max(Math.min(A,h-C(m)-6*a),6*a),p=d?1:-1;m.dataset.place=I[l]?"inside":d?"before":"after",m.dataset.kind=e.kind,tt(m,I[l]?"center"===t.insideAlign?(V+i)/2:"start"===t.insideAlign?V-p*($+C(m)/2):i+p*($+C(m)/2):i-p*A,u,T,n);const g=s[l];g&&tt(g,f-8*a,u,T,n)}),o.appendChild(J("line",{class:l,x1:V,x2:V,y1:0,y2:n}))}},pe={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:o,height:r,unit:s,svg:i,values:u,labels:d,insideAlign:h}=t,f=a(0);if(t.stacked){const e=t.length("--tablechart-stack-gap","1px")??s;return t.rows.forEach((c,l)=>{const i=yt(c,t.series.length),u=Nt(t,c,l,{},i.bottom<0?`center ${f-a(i.top)}px`:""),d=n(l)-o/2,h=Mt(c,t.series.length);h.forEach(({from:c,to:i,cell:f},b)=>{const m=t.seriesValues[b][l];if(m.dataset.place="none",f.missing||i===c)return;const $=Math.min(a(i),a(c)),p=Math.max(a(i),a(c)),g=St(h,b)?Math.min(e,(p-$)/2):0,[w,M]=a(i)<a(c)?[$+g,p]:[$,p-g];u(b,{x:d,y:w,width:o,height:Math.max(M-w,1),...i<c&&{"data-grow":"down"},...!St(h,b)&&kt(t,i<c?"bottom":"top")}),m.dataset.place="inside",m.toggleAttribute("data-left-out",!q(m,p-$,s)||E(m).width*s>o-4*s),xt(m,t,b),tt(m,n(l),($+p)/2,T,r)});const b=t.totals[l];if(b){const t=0===i.top&&i.bottom<0;b.dataset.place=t?"below":"outside",tt(b,n(l),t?a(i.bottom)+4*s:a(i.top)-4*s,T,r)}}),void i.appendChild(J("line",{class:l,x1:0,x2:T,y1:f,y2:f}))}if(t.own.length>1){const e=n(1)-n(0)||2*n(0),o=gt(e,t.own.length,t.barMax),u=t.own.flatMap(e=>t.seriesValues[e]).filter(t=>void 0===t.dataset.missing),b=U(t.plot,u,t=>({size:E(t).width*s,room:o.size+.5*o.gap}),"--_fit"),m="inside"===d&&!R(u,o.size,s),$=u[0]?E(u[0]).height*s*.56:0,p=Math.min(...u.map(t=>(o.size-E(t).width*s)/2));return t.rows.forEach((e,l)=>{t.own.forEach((u,d)=>{const g=e.cells[u]??e.cells[0],w=t.seriesValues[u][l],M=n(l)+o.offset(d);if(g.missing)return void(w.dataset.place="none");const y=a(g.value),v=g.value<0,x=Math.max(Math.abs(f-y),1);0!==g.value&&i.appendChild(J("rect",{class:X(c,e),"data-kind":"bar","data-row":l+1,...v&&{"data-grow":"down"},x:M,y:v?f:f-x,width:o.size,height:x,...kt(t,v?"bottom":"top"),...wt(t,e,u)}));const k=m&&q(w,Math.abs(f-y),s),S=v?-1:1,N=Math.min(p,(Math.abs(f-y)-$)/2),A="center"===h?(y+f)/2:"start"===h?f-S*(N+$/2):y+S*(N+$/2);w.dataset.place=k?"inside":v?"below":"outside",w.toggleAttribute("data-left-out",!b),k&&xt(w,t,u),tt(w,M+o.size/2,k?A:v?y+4*s:y-4*s,T,r)})}),void i.appendChild(J("line",{class:l,x1:0,x2:T,y1:f,y2:f}))}const b=t.own[0],m=t.own.length<t.series.length,$=R(u,o,s),p=e.map((t,e)=>"inside"===d&&!$&&!t.missing&&q(u[e],Math.abs(f-a(t.value)),s)),g=u[0]?E(u[0]).height*s*.56:0;let w=Number.POSITIVE_INFINITY;for(const[c,l]of u.entries())p[c]&&(w=Math.min(w,(o-E(l).width*s)/2));e.forEach((e,l)=>{const d=a(e.value),$=e.value<0;if(e.missing)return tt(u[l],n(l),f-4*s,T,r),void(u[l].dataset.place="outside");const M=Math.max(Math.abs(f-d),1);0!==e.value&&i.appendChild(J("rect",{class:X(c,e),"data-kind":e.kind,"data-row":l+1,...$&&{"data-grow":"down"},x:n(l)-o/2,y:$?f:f-M,width:o,height:M,...kt(t,$?"bottom":"top"),style:Y("--i",e.slot),...m&&wt(t,e,b)}));const y=$?-1:1,v=Math.min(w,(Math.abs(f-d)-g)/2),x="center"===h?(d+f)/2:"start"===h?f-y*(v+g/2):d+y*(v+g/2),k=$?d+4*s:d-4*s;tt(u[l],n(l),p[l]?x:k,T,r),u[l].dataset.place=p[l]?"inside":$?"below":"outside",m&&p[l]&&xt(u[l],t,b)}),i.appendChild(J("line",{class:l,x1:0,x2:T,y1:f,y2:f}))}},ge=(t,e,n,a,o,r,s,c)=>{const l=(a,r)=>[t+a*Math.cos(n)-o*r*Math.sin(n),e+a*Math.sin(n)+o*r*Math.cos(n)],i=c?a-s:a+s,u=Math.sqrt(Math.max(i**2-(r+s)**2,0)),d=a/i,h=c?a+8:a-3,f=h/i,b=Math.max(r-1,0),[m,$]=l(u*d,(r+s)*d),[p,g]=l(u,r),[w,M]=l(u,r+s),y=(m-w)*(g-M)-($-M)*(p-w)>0?1:0,v=t=>`${Z(t[0])},${Z(t[1])}`;return`M${v([m,$])}A${Z(s)},${Z(s)} 0 0 ${y} ${v([p,g])}L${v(l(u,b))}L${v(l(h,b))}L${v(l(u*f,(r+s)*f))}Z`},we=0,Me={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,sliceRadius:l}){const i=500,u=e/2,d=(t=>t.filter(t=>!t.isTotal))(t).reduce((t,e)=>t+Math.abs(e.value),0);if(!d)return;const h=1.2*a+10*n,b=Math.max(Math.min(T,e)/2-h,10),m=b*s.ringfill,$=b-m/2,p=2*Math.PI*$,g=[],w=[];let M=0,y=0,v=0;if(t.forEach((t,s)=>{const c=r[s];if(t.isTotal)return void(c.dataset.place="none");const l=Math.abs(t.value)/d,h=K(v,l),x=`--share:${l.toFixed(4)}; --start:${h.start.toFixed(4)}; --span:${h.span.toFixed(4)};`,k=l*p,S=M/p*2*Math.PI-Math.PI/2;g.push(S),w.push(k/p*2*Math.PI),o.appendChild(J("circle",{class:X(f,t),"data-slice":y+1,"data-row":s+1,cx:i,cy:u,r:$,"stroke-width":m,transform:`rotate(-90 500 ${u})`,"stroke-dasharray":`${k.toFixed(1)} ${(p-k).toFixed(1)}`,"stroke-dashoffset":(-M).toFixed(1),style:`--n:${y}; --palette:var(--tablechart-color-${y+1}); --arc:${k.toFixed(1)}; --circ:${p.toFixed(1)}; ${x} --ease:${h.easing}; ${Y("--i",t.slot)}`}));const N=S+k/p*Math.PI,A=Math.cos(N),C=Math.sin(N);o.appendChild(J("line",{class:"tablechart-leader",x1:i+A*(b+2*n),y1:u+C*(b+2*n),x2:i+A*(b+7*n),y2:u+C*(b+7*n),"data-row":s+1,style:`${x} ${Y("--i",t.slot)}`})),c.style.setProperty("--start",h.start.toFixed(4)),c.style.setProperty("--span",h.span.toFixed(4));const H=b+9*n,L=E(c).width*n/2;tt(c,i+A*(H+Math.abs(A)*L),u+C*(H+Math.abs(C)*a*.7),T,e),c.dataset.place="around",M+=k,v+=l,y+=1}),g.length>1){const t=$-m/2-1,n=$+m/2+1,a="tablechart-slices-"+ ++we,r=J("mask",{id:a,maskUnits:"userSpaceOnUse"});r.appendChild(J("rect",{x:0,y:0,width:T,height:e,fill:"white"}));for(const e of g)r.appendChild(J("line",{class:"tablechart-divide",x1:i+Math.cos(e)*t,y1:u+Math.sin(e)*t,x2:i+Math.cos(e)*n,y2:u+Math.sin(e)*n}));if(l>0){const t=Number.parseFloat(getComputedStyle(o).getPropertyValue("--tablechart-slice-gap").trim()||"4"),e=[$-m/2,$+m/2],n=n=>Math.min(l,m/2,Math.max((w[n]*e[0]-t)/2,0));g.forEach((a,o)=>{const s=n((o-1+g.length)%g.length);for(const[c,l]of[[1,n(o)],[-1,s]])if(l>0)for(const n of e)r.appendChild(J("path",{d:ge(i,u,a,n,c,t/2,l,n===e[1]),fill:"black"}))})}const s=J("g",{mask:`url(#${a})`});for(const e of Array.from(o.querySelectorAll(`.${f}`)))s.appendChild(e);const c=J("defs");c.appendChild(r),o.prepend(c,s)}c&&tt(c,i,u,T,e)}},ye=t=>Number(t.toFixed(2));function ve(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 xe=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}},ke=[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],Se=t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"})),Ne=t=>({segments:Se,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:r,names:s,cx:c,y:i,height:u,unit:d,labelHeight:h,svg:f,stacked:$}=e,p=o.length<a.length,M="step"===e.shape,y="smooth"===e.shape,v=a.length>1,x=a.some(t=>t.focus),k=n.length-1,S=i(0),N=n.length>1?c(1)-c(0):2*c(0);f.style.setProperty("--_base",`${ye(S)}px`);const A=(t,e)=>n[e]?.cells[t]??n[e]?.cells[0],C=(t,e)=>!A(t,e)||!!A(t,e)?.missing,H=n.map(t=>$?Mt(t,a.length,!0):null),L=(t,e)=>H[e]?.[t].to??A(t,e)?.value??0,z=(t,e)=>H[e]?.[t].from??0,B=(t,e)=>[c(e),i(L(t,e))],R=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}); `}}),q=p?k:Math.min(k,6);e.plot.style.setProperty("--count",String(q+1));const F=k>0?q/(M?n.length:k):1,U=t=>t*F,V=t=>`--i:${ye(U(t))}`,I=t=>{const e=[];let a=-1;return n.forEach((n,o)=>{C(t,o)||(a<0&&(a=o),(o===k||C(t,o+1))&&((M||o>a)&&e.push([a,o]),a=-1))}),e},j=(t,e)=>`--i:${ye(U(t)+1)}; --d:${ye(U(M?e+1:e)-U(t))}`,D=(t,e)=>({"data-from":t+1,"data-to":e+1,...M&&{"data-flat":""}}),K=y?a.map((t,e)=>ve(n.length,t=>C(e,t),t=>B(e,t))):[],Y=y&&t?a.map((t,e)=>ve(n.length,t=>C(e,t),t=>[c(t),i(z(e,t))])):[],X=(t,e,n)=>{const a=[];return t.forEach(([o,r],s)=>{M?(a.push(`H${ye(o+n*N/2)}`),s<t.length-1&&a.push(`V${ye(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])=>`${ye(t)},${ye(e)}`;return`C${s(o)} ${s(r)} ${s(e)}`}(t[s-1],[o,r],e[s-1],e[s]):`L${ye(o)},${ye(r)}`)}),a},Q=(t,e,a,o)=>n.slice(e,a+1).map((n,a)=>[c(e+a),i(o(t,e+a))]),et=(t,e,n,a)=>y?t[e].slice(n,a+1):null,nt=t=>c(t)-(M?N/2:0),rt=t=>c(t)+(M?N/2:0),[st,lt]=($?[]:o.flatMap(t=>n.flatMap((e,n)=>C(t,n)?[]:[i(L(t,n))]))).reduce(([t,e],n)=>[Math.min(t,n),Math.max(e,n)],[S,S]),it=t=>`fill:url(#${((t,e,n,a,o)=>{const r="tablechart-fade-"+ ++at,s=J("linearGradient",{id:r,gradientUnits:"userSpaceOnUse",x1:0,x2:0,y1:Z(e),y2:Z(a),...o}),c=[...e<n?[{offset:0,faded:!1}]:[],{offset:a>e?(n-e)/(a-e):0,faded:!0},...a>n?[{offset:1,faded:!1}]:[]];for(const{offset:l,faded:i}of c)s.appendChild(J("stop",{class:"tablechart-area-stop",offset:Z(l),...i&&{"data-faded":""}}));return ot(t).appendChild(s),r})(f,st,S,lt,{style:R[t].ink,...x&&!a[t].focus&&{"data-muted":""}})}); `;t&&o.forEach(t=>(t=>{const e=J("g",{class:m,...R[t].attrs,...$&&{"data-stacked":""},style:`${R[t].ink}${$?"":it(t)}`}),n=I(t),a=J("g",{class:"tablechart-area-fill",style:`--rows:${ye(q+1)}; ${n.length?j(...n[0]):""}`});e.appendChild(a);for(const[o,r]of n){const e=Q(t,o,r,L),n=Q(t,o,r,z),s=et(Y,t,o,r)?.reverse()??null,c=[`M${ye(nt(o))},${ye(n[0][1])}`,`L${ye(nt(o))},${ye(e[0][1])}`,...X(e,et(K,t,o,r),1),`L${ye(rt(r))},${ye(n[n.length-1][1])}`,...X(n.reverse(),s,-1),"Z"].join(" ");a.appendChild(J("path",{d:c,...D(o,r),style:j(o,r)}))}f.appendChild(e)})(t)),o.forEach(t=>(t=>{const e=a[t];for(const[n,a]of I(t)){const o=Q(t,n,a,L),r=[`M${ye(nt(n))},${ye(o[0][1])}`,...X(o,et(K,t,n,a),1)].join(" ");f.appendChild(J("path",{class:b,...R[t].attrs,d:r,...e.line&&{"data-line":e.line},...D(n,a),style:`${R[t].ink}${j(n,a)}`}))}})(t));const ut=p?a.flatMap((t,e)=>o.includes(e)?[]:r[e].flatMap(t=>{const e=t.dataset.place;if(!e||"none"===e||t.hasAttribute("data-left-out"))return[];const[n,a,o,r]=W(t,d,T,u);return[{label:t,box:[n-2*d,a-3*d,o+4*d,r+6*d]}]})):[],dt=M?[]:o.flatMap(t=>n.flatMap((e,n)=>{if(C(t,n))return[];const[a,o]=B(t,n);return[[a-4*d,o-4*d,8*d,8*d]]})),ht=ut.filter(({label:t,box:e})=>{const n=dt.some(t=>_(t,e));return n&&t.setAttribute("data-left-out",""),!n}),ft=(t,e)=>{let n=e;for(;n<k&&!C(t,n+1)&&A(t,n+1)?.value===A(t,e)?.value;)n++;return n},bt=t=>"above"===t?"below":"above",mt=(t,e,n)=>{const[a,o]=B(t,e),s=E(r[t][e]).width*d,c=[a-s/2,"above"===n?o-7*d-h:o+7*d,s,h];return c[1]+h>u?Number.POSITIVE_INFINITY:[e-1,e+1].filter(e=>e>=0&&e<=k&&!C(t,e)).flatMap(n=>gt(t,e,n,0)).filter(t=>_(t,c)).length},gt=(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*d)));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]})},wt=(e,n)=>{const o=A(e,n);if(!o||o.missing)return"none";if(M&&n>0&&!C(e,n-1)&&A(e,n-1)?.value===o.value)return"none";if(x&&!a[e].focus)return"none";if($)return"middle";const r=o.value<0?"below":"above";if(!v||x||a.length>2)return t||M||mt(e,n,r)<=mt(e,n,bt(r))?r:bt(r);const s=A(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*d+h>S?"above":"below"},yt=t=>{let e=k;for(;e>0&&C(t,e);)e--;return e},vt=M||$?10*d:Math.max(10*d,...o.map(t=>E(r[t][k]).width*d/2+6*d)),xt=e.numbersAtEnd?Math.max(...o.map(t=>E(r[t][yt(t)]).width*d))+11*d:vt,kt=()=>{const t=(s[0]?E(s[0]).height:0)*d,n=2*d,a=o.flatMap(t=>{const e=s[t];if(!e)return[];const[n,a]=B(t,yt(t));return[{name:e,x:n+xt,y:a}]}),r=e.numbersAtEnd?xt-7*d:0;return P(a,t).map(e=>[e.x-n-r,e.y-t/2-n,E(e.name).width*d+2*n+r,t+2*n])},St=(p||v&&!x&&a.length>2&&!$)&&!M,Nt=new Map;if(St){const t=n.flatMap((t,e)=>o.map(t=>({s:t,i:e,value:A(t,e)?.value??0}))).filter(({s:t,i:e})=>"none"!==wt(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=E(r[t][n]).width*d,[s,c]=B(t,n);return e(a).map(t=>[s-o/2,"above"===t?c-7*d-h:c+7*d,o,h])}),s=o.flatMap(t=>n.flatMap((e,n)=>{if(C(t,n))return[];const[a,o]=B(t,n);return[[a-4*d,o-4*d,8*d,8*d]]})),l=O(a,[...s,...kt(),...ht.map(({box:t})=>t)],[0,0,c(k)+c(0),u]);t.forEach(({s:t,i:n,value:a},o)=>Nt.set(r[t][n],null===l[o]?null:e(a)[l[o]]))}o.forEach(t=>{r[t].forEach((e,n)=>{e.style.setProperty("--i",String(ye(M?(U(n)+U(n+1))/2:U(n))));const a=Nt.get(e)??wt(t,n);if(e.dataset.place="above"===a?"outside":a,e.toggleAttribute("data-left-out","none"!==a&&((t,e)=>{if(St)return null===Nt.get(r[t][e]);if(!$&&!M)return!1;const n=E(r[t][e]).width*d;if(n>(M?ft(t,e)-e+1:1)*N-4*d)return!0;if($&&t>0&&L(t,e)<z(t,e))return!0;if($&&!M&&e>0&&e<k){const a=(i(z(t,e))+i(L(t,e)))/2,r=[c(e)-n/2,a-h/2,n,h];if(o.some(t=>{const[n,a]=B(t,e);return!C(t,e)&&_([n-4*d,a-4*d,8*d,8*d],r)}))return!0}return $&&Math.abs(i(z(t,e))-i(L(t,e)))<1.2*h})(t,n)),M&&"none"!==a?e.dataset.rowEnd=String(ft(t,n)+1):delete e.dataset.rowEnd,"none"===a)return;const s=E(e).width*d/2+4*d;let l=c(n);M?l=(c(n)+c(ft(t,n)))/2:"middle"===a&&0===n?l+=s:"middle"===a&&n===k&&(l-=s);const f=i(L(t,n)),b={middle:(i(z(t,n))-f)/2,above:-7*d,below:7*d};tt(e,l,f+b[a],T,u)})});const At=t=>{const a=n.flatMap((e,n)=>e.pinned&&!C(t,n)?[n]:[]),o=n.map((t,e)=>e).filter(e=>!C(t,e)),s=e=>A(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)=>s(e)>s(t)?e:t)),c.includes("lowest")&&a.push(o.reduce((t,e)=>s(e)<s(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=xe(t),l=r(c.at);l.length&&s(l)&&(c=xe(t.filter(t=>!l.includes(t))),l=r(c.at)),s(l)||(c=xe(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,ke[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:s(t)})))?.outside.map(t=>t.x)??[]));const l=[];for(const e of a){const n=r[t][e];l.includes(e)||"none"===n.dataset.place||l.every(e=>1===G([r[t][e],n],d,1e3,u))&&l.push(e)}return new Set(l)},Ct=t=>{const e=r[t].filter(t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out"));return 1===G(e,d,T,u)},Ht=new Map;for(const t of o){const n="all"===e.pick.mode||"auto"===e.pick.mode&&Ct(t)?null:At(t);Ht.set(t,n),n&&r[t].forEach((t,e)=>{"none"===t.dataset.place||n.has(e)||t.setAttribute("data-left-out","")})}if(!$&&!M&&o.some(t=>Ht.get(t))){const t=c(k)+c(0),a=2*d,s=t=>n.flatMap((e,n)=>n===k||C(t,n)||C(t,n+1)?[]:gt(t,n,n+1,a)),l=o.flatMap(s),i=kt(),f=o.flatMap(t=>[...Ht.get(t)??[]].map(e=>({s:t,i:e}))),b=({s:t,i:n})=>e.numbersAtEnd&&n===yt(t),m=f.filter(t=>!b(t)),$=({s:t,i:e})=>{const n=A(t,e)?.value??0,a=e>0&&!C(t,e-1)?A(t,e-1)?.value:void 0,o=e<k&&!C(t,e+1)?A(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"]},p=({s:e,i:n},a)=>{const o=E(r[e][n]).width*d,s=h,[c,l]=B(e,n),i=Math.min(Math.max(c-o/2,0),t-o);return"outside"===a?[i,l-7*d-s,o,s]:"below"===a?[i,l+7*d,o,s]:"outside far"===a?[i,l-7*d-2*s,o,s]:"below far"===a?[i,l+7*d+s,o,s]:"after"===a?[c+7*d,l-s/2,o,s]:[c-7*d-o,l-s/2,o,s]},g=m.map($),w=e=>e[0]>=0&&e[1]>=0&&e[0]+e[2]<=t&&e[1]+e[3]<=u-2*d,M=f.map(({s:t,i:e})=>{const[n,a]=B(t,e);return[n-6*d,a-6*d,12*d,12*d]}),y=[],v=new Set,x=m.map((t,e)=>{const n=g[e].map(e=>p(t,e)),a=t=>w(t)&&![...y,...i,...M].some(e=>_(t,e)),r=o.filter(e=>e!==t.s).flatMap(s),c=n=>!g[e][n].endsWith("far")||!r.some(a=>_(p(t,g[e][n].split(" ")[0]),a));let u=n.findIndex((t,e)=>a(t)&&c(e)&&!l.some(e=>_(t,e)));return u<0&&(u=n.findIndex((t,e)=>a(t)&&c(e)),u>=0&&v.add(e)),u>=0&&y.push(n[u]),u<0?null:u});m.forEach((t,e)=>{const n=r[t.s][t.i];n.toggleAttribute("data-cut",v.has(e));const a=x[e];if(n.toggleAttribute("data-left-out",null===a),null===a)return;const o=g[e][a],[s,c,l,i]=p(t,o),d=o.split(" ")[0];n.dataset.place=d,tt(n,"after"===d?s:"before"===d?s+l:s+l/2,"outside"===d?c+i:"below"===d?c:c+i/2,T,u)})}M||(()=>{const t=o.map(t=>a[t]),r=a.map((e,n)=>p?$t(t,o.indexOf(n)):v?$t(a,n):{shape:"circle",open:!1}),s=(t,e,n)=>{const[a,o]=B(t,e);return pt(r[t].shape,a,o,3*d,{...n,style:`${n.style??""}${s=o,`--rise:${ye(S-s)}px; `}${V(e)}`});var s},c=t=>/\bnone\b/.test(a[t].marker??"")?[]:n.map((t,e)=>e).filter(e=>!C(t,e)&&((t,e)=>{const n=Ht.get(t);return n?n.has(e):N>=10*d})(t,e)),l=o.flatMap(t=>r[t].open?c(t).map(e=>s(t,e,{class:w,"data-row":e+1,...v&&{"data-series":t+1}})):[]);"grow"===f.closest("[data-animate]")?.getAttribute("data-animate")?ct(f,l,T,u):e.lineHoles.push(...l),o.forEach(t=>{for(const e of c(t))f.appendChild(s(t,e,{class:g,...R[t].attrs,"data-marker":r[t].shape,...r[t].open&&{"data-open":""},"data-row":e+1,style:R[t].ink}))})})(),e.pointOf=t=>{const e=o.filter(e=>!C(e,t)).map(e=>B(e,t));return e.length?e.reduce((t,e)=>e[1]<t[1]?e:t):null};const Tt=(p?[]:s).map((t,e)=>{const n=yt(e),[a,o]=B(e,n);return{name:t,s:e,x:(M?a+N/2:a)+xt,y:$?(o+i(z(e,n)))/2:o}}),Lt=(s[0]?E(s[0]).height:0)*d;for(const t of P(Tt,Lt)){if(tt(t.name,t.x,t.y,T,u),!e.numbersAtEnd)continue;const n=r[t.s][yt(t.s)];n.dataset.place="before",n.removeAttribute("data-left-out"),n.removeAttribute("data-cut"),tt(n,t.x-4*d,t.y,T,u)}const _t=n.some(t=>t.cells.some(t=>!t.missing&&t.value<0)),Ot=t||$||2!==a.length||x||_t?S:u-2*d;p||f.appendChild(J("line",{class:l,x1:0,x2:c(k)+c(0),y1:Ot,y2:Ot}))}}),Ae=Ne(!1),Ce=Ne(!0),He=new Set,Te={segments:t=>{let e=0,n=!1;return t.map(t=>{if(t.isTotal)return n&&((t,e)=>{if(Math.abs(t-e)<=Math.abs(e)/100)return;const n=`[${o}] A total reads ${t}, but the steps before it add up to ${Number(e.toFixed(6))}. The chart shows your number.`;He.has(n)||(He.add(n),console.warn(n))})(t.value,e),n=!1,e=t.value,{...t,from:0,to:t.value,kind:"total"};const a=e;return e+=t.value,n=!0,{...t,from:a,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:o,unit:r,svg:s,values:i,breakAt:u,insideAlign:d}){const h=n(0),f=R(i,a,r),b=d??"center",m=t.map((e,a)=>{const o=n(Math.max(e.from,e.to)),s=Math.abs(n(e.from)-n(e.to)),c=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:s,down:"down"===e.kind||"total"===e.kind&&(l?e.to>=0:e.to<0),inside:!c&&!f&&q(i[a],s,r)}}),$=i[0]?E(i[0]).height*r*.56:0;let p=Number.POSITIVE_INFINITY;for(const[c,l]of m.entries())l.inside&&(p=Math.min(p,(a-E(i[c]).width*r)/2));const g=t.length,w=(t,e,n=!1)=>`--start:${(t/g).toFixed(4)}; --span:${(e/g).toFixed(4)}; --ease:${n?D:"linear"};`;t.forEach((o,r)=>{const c=t[r+1];if(!c)return;const l=n(o.to),i=e(r)+a/2,u=e(r+1)-a/2;s.appendChild(J("line",{class:"tablechart-connector",x1:i,x2:u,y1:l,y2:l,"data-row":r+2,style:`${Y("--i",c.slot)}; ${w(r+1,1/3)}`}))}),t.forEach((n,l)=>{const{top:u,length:d,down:h,inside:f}=m[l];s.appendChild(J("rect",{class:X(c,n),"data-kind":n.kind,"data-row":l+1,"data-grow":h?"down":"up",x:e(l)-a/2,y:u,width:a,height:Math.max(d,1),style:`${Y("--i",n.slot)}; ${w(l,1,l===t.length-1)}`}));const M=i[l];M.style.setProperty("--start",(l/g).toFixed(4)),M.style.setProperty("--span",(1/g).toFixed(4));const y=Math.min(p,(d-$)/2),v="center"===b?u+d/2:"end"===b!==h?u+y+$/2:u+d-y-$/2;M.dataset.place=f?"inside":"outside",M.dataset.kind=n.kind;const x=f?v:"down"===n.kind?u+d+E(M).height*r+3*r:u-3*r;tt(M,e(l),x,T,o)}),s.appendChild(J("line",{class:l,x1:0,x2:T,y1:h,y2:h}))}},Le={area:Ce,bar:$e,column:pe,donut:Me,line:Ae,waterfall:Te},_e={"axis-break":ue,trend:be,bracket:de,reference:fe,note:bt},Oe=Object.keys(_e),ze=(t,e,n=!1)=>{if(e||t.figure.hasAttribute("data-steps")||Re(t.svg),t.figure.classList.remove(N),n)return t.figure.classList.add(S),t.figure.classList.toggle(x,e),t.figure.offsetWidth,e&&qe(t.svg),t.figure.classList.toggle(N,e),void requestAnimationFrame(()=>t.figure.classList.remove(S));t.figure.classList.toggle(x,e),e&&requestAnimationFrame(()=>requestAnimationFrame(()=>{Ee(t.figure,t.svg),Be(t.figure)}))},Be=t=>{const e=t.getAnimations({subtree:!0}).map(t=>t.finished.catch(()=>{}));Promise.all(e).then(()=>{t.classList.contains("is-shown")&&t.classList.add(N)})},Ee=(t,e)=>{t.classList.contains("is-shown")&&Array.from(e.querySelectorAll("[data-mask]")).every(t=>!t.getAnimations({subtree:!0}).length)&&qe(e)},Re=t=>{for(const e of t.querySelectorAll('[mask^="url(#tablechart-cut-"]'))e.dataset.mask=e.getAttribute("mask")??"",e.removeAttribute("mask")},qe=t=>{for(const e of t.querySelectorAll("[data-mask]"))e.setAttribute("mask",e.dataset.mask??""),e.removeAttribute("data-mask")},Fe=t=>{let e="";for(let n=t.previousSibling;n&&(e=(n.textContent??"")+e,!e.trim());n=n.previousSibling);return e.trim()},Ue=0,Pe=[null,"dashed","dotted","dash-dot"],Ve=(t,e,n=null)=>{const a=n??(t.getAttribute("data-chart")||"column"),c=Le[a];if(!c)return console.warn(`[${o}] Unknown chart type "${a}". Known types: ${Object.keys(Le).join(", ")}.`),t.setAttribute("data-chart-empty",""),null;const l=Tt(t,e.langattribute);if(!l.length)return console.warn(t.querySelector("table")?`[${o}] A chart has no rows in its table, so there is nothing to draw.`:`[${o}] 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(Fe(e)))continue;const t=document.createElement("span");t.className=v,t.textContent=". ",e.before(t)}})(e);const n=t=>t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby"),a=t=>{e.id||(e.id="tablechart-caption-"+ ++Ue),t.setAttribute("aria-labelledby",e.id)};"FIGURE"!==t.tagName||n(t)||a(t);const o=t.querySelector("table");!o||n(o)||o.querySelector(":scope > caption")||a(o)})(t);let i=_t(t,l,e.langattribute);if(i.length>1&&!c.series&&!c.columns&&(console.warn(`[${o}] A ${a} chart uses only the first of its ${i.length} value columns.`),i=i.slice(0,1)),i.some(t=>t.chart)){const t=c.lines?i.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 ${a} chart cannot draw a series as a line.`;t&&(console.warn(`[${o}] ${t}`),i=i.map(t=>({...t,chart:null})))}((t,e,n,a)=>{const r=t.closest("[data-chart-lines]")?.getAttribute("data-chart-lines");let s=a.lines;if(r)try{s=JSON.parse(r)}catch{console.warn(`[${o}] data-chart-lines needs a JSON list, such as [{"marker":"none"}].`,t)}("line"===n||"area"===n?e:e.filter(t=>t.chart)).forEach((t,e)=>{if(!s?.length)return void(t.line??(t.line=Pe[Math.floor(e/6)%Pe.length]));const n=s[e%s.length];t.marker??(t.marker=n.marker||void 0!==n.open?[n.marker,n.open?"open":"filled"].filter(Boolean).join(" "):null),null===t.line&&"solid"!==n.line&&(t.line=n.line??null)})})(t,i,a,e);const u=i.some(t=>t.chart),d=i.length>1;d&&t.style.setProperty("--_series-count",String(i.length));const h=t.hasAttribute("data-chart-stack");h&&!c.stackable&&console.warn(`[${o}] A ${a} chart cannot be stacked.`),h&&u&&console.warn(`[${o}] A chart with a line cannot be stacked.`);const f=h&&!!c.stackable&&d&&!u,b=document.createElement("div");b.className="tablechart-plot",b.setAttribute("aria-hidden","true");const m=J("svg",{role:"presentation",focusable:"false"});b.appendChild(m);const g=t.querySelector(":scope > table"),w=e=>g?g.before(e):t.append(e);w(b);const y=c.centre?l.filter(t=>!t.isTotal):l,x=Math.max(0,lt(y.flatMap(t=>t.cells.slice(0,i.length).map(t=>it(t.number))))),k=i.map((t,e)=>Math.max(0,lt(l.map(t=>it(t.cells[e]?.number??""))))),S=document.createElement("div");S.className="tablechart-values",b.appendChild(S);const N=i.map((t,e)=>l.map((t,n)=>{const a=t.cells[e]??t.cells[0],o=Q(s,S);return o.classList.add(...t.classes),o.dataset.value=String(a.value),a.prefix&&(o.dataset.prefix=a.prefix),a.suffix&&(o.dataset.suffix=a.suffix),a.missing&&(o.dataset.missing=a.raw),d&&(o.dataset.series=String(e+1)),c.columns&&(o.dataset.decimals=String(k[e])),o.dataset.row=String(n+1),o.style.setProperty("--i",String(t.slot)),!1===c.numbers&&(e||n)&&(o.dataset.place="none"),o})),H=N[0],T=f&&c.totals?l.map((t,e)=>{const n=Q(s,S);n.classList.add(...t.classes),n.dataset.kind="total",n.dataset.row=String(e+1),n.dataset.value=String(vt(t,i.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}):[],L=l[l.length-1],_=i.some(t=>t.focus),O=t.getAttribute("data-chart-legend"),z=d&&!c.columns&&(null===O?e.legend||void 0!==c.legend:"false"!==O)?document.createElement("div"):null;z&&(z.className=p,z.setAttribute("aria-hidden","true"),z.inert=!0);const B=i.filter(t=>t.chart),E=d&&!c.columns?i.map((n,a)=>{const o=Q($,z??b);z&&(o.dataset.place="legend");const r=n.chart?void 0:c.legend??c.swatch;if(r&&(o.dataset.swatch=r),o.textContent=n.name,!r&&"step"!==ce(t,e)){const t=n.chart?$t(B,B.indexOf(n)):$t(i,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",_&&!n.focus?"1":"0"),o.style.setProperty("--i",String(L.slot)),o}):[],R=c.centre?Q(M,b):null;if(R){const t=l.find(t=>t.isTotal),e=t?t.value:l.reduce((t,e)=>t+Math.abs(e.value),0);R.dataset.value=String(e),t&&(R.dataset.decimals=String(it(t.number)))}const q=R&&!l.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,R,e):null,F="beside"===c.categories,U=document.createElement("div");U.className=r,U.setAttribute("aria-hidden","true"),U.inert=!0,F?U.dataset.place="beside":c.centre&&(U.dataset.place="key"),U.style.setProperty("--_columns",String(l.length));let P=0;for(const[o,r]of l.entries()){const t=document.createElement("span");t.classList.add(...r.classes),t.textContent=r.short??r.label,r.key&&e.langattribute&&t.setAttribute(e.langattribute,r.short?`${r.key}-short`:r.key),c.centre&&(t.dataset.kind=r.isTotal?"total":"slice",r.isTotal||(t.dataset.slice=String(P+1),t.style.setProperty("--n",String(P)),t.style.setProperty("--palette",`var(--tablechart-color-${P+1})`),P+=1)),t.style.setProperty("--i",String(r.slot)),t.dataset.row=String(o+1),U.appendChild(t)}c.centre&&t.style.setProperty("--_slice-count",String(P)),F?b.appendChild(U):w(U),z&&w(z);const V=i.filter(t=>!t.group),W=!c.axes&&!c.centre&&re(t,"data-chart-axis",e.axis),I=c.axes?{titles:V.slice(0,2).map((t,n)=>{const a=Q(`${A}-title`,b);return a.dataset.axis=n?"y":"x",a.textContent=t.name,t.key&&e.langattribute&&a.setAttribute(e.langattribute,t.key),a}),ticks:Q(`${C}s`,b),numbers:!0}:W||!c.centre&&re(t,"data-chart-grid",e.grid)?{titles:[],ticks:Q(`${C}s`,b),numbers:W}:null;c.text?.({figure:t,plot:b,rows:l,series:i,config:e});const j=le(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=>Ot.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[y,v]of a.entries())b(v)&&($[y]={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}))),M=Math.max(0,...c.map(t=>t.length));for(let y=0;y<M;y++)for(const[t,e]of c.entries()){const n=e[y];if(!n||!s(n))continue;const a=d(n.getAttribute("data-fragment-index"));w[t][y]={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(c.axes)):null;c.axes&&t.querySelector("tbody [data-fragment], thead [data-fragment]")&&At.log(`A ${a} chart has one step, with data-fragment on the figure; its rows and columns have no steps of their own.`,t),j&&t.setAttribute("data-steps","");const G=t.getAttribute("data-chart-keys"),D=j&&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=J("svg",{viewBox:"0 0 16 16",focusable:"false"});s.appendChild(J("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=v,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:G&&`${G}-previous`,next:G&&`${G}-next`,hint:G&&`${G}-step`},e.langattribute):null;D&&w(D);const K=Array.from(t.querySelectorAll("[data-annotation]")).map(t=>{const e=t.getAttribute("data-annotation"),n=_e[e];if(!n)return console.warn(`[${o}] Unknown annotation "${e}". Known annotations: ${Object.keys(_e).join(", ")}.`),null;const a=Number.parseInt(t.getAttribute("data-series")??"1",10),r=a>=1&&a<=i.length?a-1:0;return a!==r+1&&console.warn(`[${o}] An annotation reads line ${a}, which is not there; it reads line 1.`),{spec:t,type:n,badge:n.create(t,b),series:r,after:l.length}}).filter(t=>null!==t);if(!F&&!c.centre&&!c.axes)for(const[o,r]of l.entries()){if(!r.note)continue;const t=document.createElement("span");t.dataset.annotation="note",t.dataset.row=String(o+1),t.textContent=r.note,r.noteKey&&t.setAttribute("data-i18n",r.noteKey),K.push({spec:t,type:bt,badge:bt.create(t,b),series:0,after:l.length})}le(t,e)&&t.setAttribute("data-animate",Ie(t,a,e,Boolean(j)));const Y={figure:t,plot:b,svg:m,rows:l,decimals:x,type:c,values:H,series:i,seriesValues:N,names:z?[]:E,categories:Array.from(U.children),centre:R,axes:I,stacked:f,totals:T,totalCell:q,rowAt:null,rowBox:null,pointOf:null,annotations:K,checks:[],plan:j,step:0,controls:D},Z=()=>Ee(t,m);m.addEventListener("transitionend",Z),m.addEventListener("transitioncancel",Z),D?.addEventListener("click",t=>{const e=t.target.closest("button")?.dataset.go;e&&Bt(Y,Y.step+("next"===e?1:-1))}),Bt(Y,0,!0);const X=t.getAttribute("data-chart-tooltip"),tt="false"!==X&&("auto"===X?"auto":null!==X||e.tooltip);return tt&&((t,e,n=!1)=>{const{plot:a}=t;a.setAttribute("data-hover",""),(()=>{if(Dt)return;Dt=!0,document.addEventListener("pointermove",t=>{"mouse"===t.pointerType&&(It=t.screenX!==jt||t.screenY!==Gt,jt=t.screenX,Gt=t.screenY,It&&(Wt=!1))},{capture:!0,passive:!0});const t=()=>{Wt=!0,Vt()};document.addEventListener("keydown",t,!0),window.addEventListener("scroll",t,{capture:!0,passive:!0})})();const o=new Set,r=t=>{for(const e of o)if(e.isConnected){if(e.getAttribute("data-row")===String(t+1))return!0}else o.delete(e);return!1};let s=null;const c=o=>{if("pointerdown"===o.type)Wt=!1;else if("mouse"===o.pointerType&&(!It||Wt))return;if(!a.classList.contains("is-placed")||!t.figure.classList.contains("is-shown"))return;if(n&&!t.figure.hasAttribute("data-left-out"))return Ft===t?Vt():void 0;const c=(e=>{if(t.rowAt){const n=a.getBoundingClientRect(),o=Kt(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 Ft===t?Vt():void 0;Qt(t,c,e)},l=e=>{const n=e.target;return t.svg.contains(n)&&n.hasAttribute("data-row")?n:null};t.svg.addEventListener("transitionrun",t=>{const e=l(t);e&&o.add(e)});const i=n=>{const a=l(n);if(!a)return;o.delete(a);const c=Number(a.getAttribute("data-row"))-1;s!==c||r(c)||Wt||Qt(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,Ft===t&&Yt())})})(Y,e,"auto"===tt),je(Y,e),Y},We={grow:"grow",sweep:"sweep"},Ie=(t,e,n,a)=>{const o="line"===e||"area"===e,r=We[t.getAttribute("data-chart-animate")??""]??We[String(n.animate)];return o?a?"sweep":r??"sweep":"donut"===e||"waterfall"===e?r??"grow":"grow"},je=(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:ee(a,a.dataset.decimals?Number(a.dataset.decimals):t.decimals,e.locale)},Ge=null,De=t=>{if(Ge??(Ge=document.createElement("canvas").getContext("2d",{willReadFrequently:!0})),!Ge)return[0,0,0,1];Ge.clearRect(0,0,1,1),Ge.fillStyle=t,Ge.fillRect(0,0,1,1);const[e,n,a,o]=Ge.getImageData(0,0,1,1).data;return[e,n,a,o/255]},Ke=([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)},Ye=t=>"3"===getComputedStyle(t).getPropertyValue("--tablechart-contrast-wcag").trim()?3:2,Ze=([t,e,n])=>{const a=.2126729*(t/255)**2.4+.7151522*(e/255)**2.4+.072175*(n/255)**2.4;return a<.022?a+(.022-a)**1.414:a},Je=(t,e,n)=>3===t?((t,e)=>{const n=Ze(t),a=Ze(e);if(Math.abs(a-n)<5e-4)return 0;const o=a>n?1.14*(a**.56-n**.57):1.14*(a**.65-n**.62);return Math.abs(o)<.1?0:100*(Math.abs(o)-.027)})(e,n):Xe(e,n),Xe=(t,e)=>{const[n,a]=[Ke(t),Ke(e)].sort((t,e)=>e-t);return(n+.05)/(a+.05)},Qe=(t,e)=>{const n=document.createElement("span");n.style.color=e,t.append(n);const a=De(getComputedStyle(n).color);return n.remove(),a},tn=t=>{const e=[];let n=null;for(let o=t;o&&!n;o=o.parentElement){const{background:t,backgroundColor:a}=o.dataset,r=a||(t&&CSS.supports("color",t)?t:""),s=De(r||getComputedStyle(o).backgroundColor);s[3]>=1?n=s:s[3]>0&&e.push(s)}n??(n=Qe(t,"Canvas"));for(const[o,r,s,c]of e.reverse())n=[o,r,s].map((t,e)=>t*c+n[e]*(1-c));const a=`rgb(${n.slice(0,3).map(Math.round).join(" ")})`;return t.style.getPropertyValue("--_surface")!==a&&(t.style.setProperty("--_surface",a),!0)},en=t=>Qe(t,"var(--tablechart-surface, var(--_surface, Canvas))"),nn=(t,e)=>t.querySelector(`:is(.tablechart-bar, .tablechart-piece)[data-row="${e.dataset.row}"]${e.dataset.series?`[data-series="${e.dataset.series}"]`:""}`),an=[255,255,255],on=[0,0,0],rn=(t,e,n)=>{const a=Je(n,an,t),o=Je(n,on,t);return a>=e?an:o>=e?on:2===n&&a>=4.5||a>o?an:on},sn=t=>{const e=t.querySelectorAll(".tablechart-value[data-place='inside']");if(!e.length)return;const n=en(t).slice(0,3),a=Ke(n)>.179,o=(e,n)=>{const[a,o,r,s]=Qe(t,`var(${e}, transparent)`);return s>0?[a,o,r]:n},r=Ye(t),s=Number.parseFloat(getComputedStyle(t).getPropertyValue("--tablechart-value-contrast"))||(3===r?60:5),c=De(getComputedStyle(t).color).slice(0,3),l=o("--tablechart-value-on-dark",a?n:c),i=o("--tablechart-value-on-light",a?c:n);for(const u of e){const e=nn(t,u);if(!e||u.hasAttribute("data-left-out"))continue;const n=De(getComputedStyle(e).fill),a=Je(r,l,n)>Je(r,i,n)?l:i,o=Je(r,a,n)>=s?a:rn(n,s,r);u.style.setProperty("--_ink",`rgb(${o.join(" ")})`)}},cn=t=>{const e=t.querySelectorAll(".tablechart-name:not([data-place='legend'])");if(!e.length)return;const n=Ye(t),a=3===n?60:4.5,o=en(t).slice(0,3),r=De(getComputedStyle(t).color).slice(0,3);for(const s of e){const e=t.querySelector(`.tablechart-series[data-series="${s.dataset.series}"]:not([data-muted])`);if(s.style.removeProperty("--_ink"),!e)continue;const c=De(getComputedStyle(e).stroke).slice(0,3);for(let t=0;t<=20;t++){const e=c.map((e,n)=>Math.round(e+(r[n]-e)*t/20));if(!(Je(n,e,o)<a&&t<20)){t&&s.style.setProperty("--_ink",`rgb(${e.join(" ")})`);break}}}},ln=t=>Number(t.toPrecision(12)),un=(t,e)=>{const n=t/Math.max(1,e)||1,a=10**Math.floor(Math.log10(n)),o=n/a;return ln((o<1.42?1:o<3.17?2:o<7.08?5:10)*a)},dn=(t,e,n)=>{const a=[];for(let o=Math.ceil(t/n-1e-9);o*n<=e+1e-9*n;o++)a.push(ln(o*n));return a},hn=(t,e=t)=>{do{const e=Math.round(t/10**Math.floor(Math.log10(t)+1e-9));t=ln(t*(2===e?2.5:2))}while(Math.abs(t/e-Math.round(t/e))>1e-9);return t},fn=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},bn=(t,e)=>{let{step:n,ticks:a}=t;for(;n&&a.length>2&&!e(a);)n=hn(n,t.step),a=dn(t.min,t.max,n);return{...t,step:n,ticks:a}},mn=new WeakMap,$n=new WeakMap,pn=!1,gn=(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${Z(t)},${Z(l)}H${Z(e)}`:`M${Z(l)},${Z(t)}V${Z(e)}`).join("")},wn=(t,e)=>{const[n,a,o,r]=["x1","y1","x2","y2"].map(e=>Number(t.getAttribute(e))),s=J("path",{d:gn(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)},Mn=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]),yn=(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${Z(Math.max(t,e))},${Z(r)}H${Z(Math.min(s,e+a))}`:"":e<=t&&t<=e+a&&Math.max(r,n)<Math.min(c,n+o)?`M${Z(t)},${Z(Math.max(r,n))}V${Z(Math.min(c,n+o))}`:"").join(""),vn=t=>{const e=getComputedStyle(t).getPropertyValue("--tablechart-value-align").trim();return"start"===e||"center"===e||"end"===e?e:null},xn=(t,e,n)=>"inside"===t.dataset.chartLabels||"outside"!==t.dataset.chartLabels&&("inside"===e.labels||n)?"inside":"outside",kn=(t,e)=>ne(t,e,"--tablechart-bar-max","60px")??Number.POSITIVE_INFINITY,Sn=["first","last","highest","lowest","outliers"],Nn=["never","auto","print","always"],An=(t,e)=>{((t,e)=>{mn.set(t.figure,{state:t,config:e})})(t,e);const n=Cn(t,e);return n&&((t,e)=>{const n=(t=>{const e=t.closest("[data-chart-group]");if(!e)return null;const n=e.getAttribute("data-chart-group"),a=n?Array.from(document.querySelectorAll(`[data-chart-group="${CSS.escape(n)}"]`)):[e];return{figures:a.flatMap(t=>t.matches("figure")?[t]:Array.from(t.querySelectorAll("figure"))),shared:a.some(t=>t.hasAttribute("data-chart-group-scale"))}})(t);if(!n?.shared||pn)return;const a=n.figures.flatMap(t=>mn.get(t)??[]).filter(({state:t})=>t.plot.clientWidth),o=a.map(({state:t})=>`${t.plot.clientWidth}:${t.rows.map(t=>t.cells.map(t=>t.value)).join()}`).join("|"),r=n.figures[0];if($n.get(r)===o)return;$n.set(r,o),pn=!0;for(const{state:i,config:u}of a)i.agreed=void 0,e(i,u);const s=a.flatMap(({state:t})=>t.measured?[{state:t,...t.measured,top:t.figure.getBoundingClientRect().top}]:[]),c=lt(s.map(t=>t.ceiling)),l=-lt(s.map(t=>-t.bottom));for(const i of s){const t=s.filter(t=>Math.abs(t.top-i.top)<4);i.state.agreed={ceiling:c,bottom:l,height:lt(t.map(t=>t.height)),room:lt(t.map(t=>t.room)),floor:lt(t.map(t=>t.floor))}}for(const{state:i,config:u}of a)e(i,u);pn=!1})(t.figure,Cn),n},Cn=(t,e)=>{const{plot:n,svg:a,rows:s,type:l,values:g,series:y,seriesValues:v,names:x,annotations:k}=t;(({figure:t,rows:e,series:n},a)=>{const o=t.getAttribute("data-chart-table"),r=o&&Nn.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&&Nn.includes(s)?s:a.summary),t.toggleAttribute("data-long",e.length*n.filter(t=>!t.group).length>a.tablelimit)})(t,e);const S=getComputedStyle(t.figure);t.figure.toggleAttribute("data-series-range",!!S.getPropertyValue("--tablechart-series-color-end").trim()),t.figure.toggleAttribute("data-slice-range",!!S.getPropertyValue("--tablechart-slice-color-end").trim());const N=Number.parseFloat(t.figure.dataset.chartAspect??""),L=N>0?N:l.aspect??e.aspect,_="beside"===l.categories,O=t.axes&&!l.axes?t.axes:null;let z=null;if(O&&(z=((t,e,n,a)=>{const{plot:o,rows:r,type:s,series:c}=t,l="beside"===s.categories,i=l?null:t.categories[0]?.parentElement;let u;o.style.margin="",i&&(i.style.marginLeft="");const d=o.clientWidth;if(!d)return null;const h=s.segments?.(r)??[],f=t.stacked?r.flatMap(t=>Object.values(yt(t,c.length,s.running))):h.some(t=>"up"===t.kind||"down"===t.kind)?h.flatMap(t=>[t.from,t.to]):r.flatMap(t=>t.cells.slice(0,c.length).filter(t=>!t.missing).map(t=>t.value)),b=Math.min(0,-lt(f.map(t=>-t))),m=Math.max(0,lt(f)),$=Number.parseFloat(getComputedStyle(o).fontSize)||16,{chartScaleY:p,chartScale:g}=t.figure.dataset,w=fn(p??g);if(w&&w.length>2)u={min:w[0],max:w[w.length-1],step:0,ticks:w};else{const[e,n]=w??[Math.min(b,t.agreed?.bottom??b),Math.max(m,t.agreed?.ceiling??m)],o=un(n-e,Math.max((l?d/9:Math.min(d*a,ae(t.figure,1)[1])/3)/$,2)),r=(t,e)=>w?t:Number(((e?Math.ceil:Math.floor)(t/o-1e-9*(e?1:-1))*o).toPrecision(12)),s=r(e,!1),c=r(n,!0);u={min:s,max:c,step:o,ticks:dn(s,c,o)}}n.ticks.textContent="";const M=r.find(t=>!t.missing),y=lt(u.ticks.map(t=>it(String(t))));for(const v of u.ticks){const t=Q(C,n.ticks);t.dataset.value=String(v),t.dataset.place="none",M?.prefix&&(t.dataset.prefix=M.prefix),M?.suffix&&(t.dataset.suffix=M.suffix),ee(t,y,e.locale)}if(n.numbers){const t=Array.from(n.ticks.children);for(const e of t)delete e.dataset.place;B(t),l?o.style.marginBottom=`${(t[0]?E(t[0]).height:0)+6}px`:(o.style.marginLeft=`${lt([0,...t.map(t=>E(t).width)])+10}px`,i&&(i.style.marginLeft=o.style.marginLeft))}return u})(t,e,O,L),!z))return!1;const R=n.clientWidth;if(!R)return!1;const q=T/R,[F,P]=ae(t.figure,q),V=Math.min(T*L,P);n.classList.add("is-placed");const W=!1===l.numbers?g.slice(0,1):[...v.flat(),...t.totals];for(const o of W)delete o.dataset.place,o.removeAttribute("data-left-out"),o.removeAttribute("data-cut");n.style.removeProperty("--_fit"),n.toggleAttribute("data-grouped",!!l.groups&&!t.stacked&&y.filter(t=>!t.chart&&!t.group).length>1),t.categories[0]?.parentElement?.style.removeProperty("--_beside");const G=l.axes?t.axes:null,D=G?((t,e,n,a,o,r)=>{const{plot:s,rows:c,series:l}=t,i=Number.parseFloat(getComputedStyle(s).fontSize)||16,u=l.flatMap((t,e)=>t.group?[]:[e]).slice(0,2),d=c.filter(t=>u.every(e=>t.cells[e]&&!t.cells[e].missing)),{chartScaleX:h,chartScaleY:f,chartScale:b}=t.figure.dataset,m=[fn(h),fn(f??b)],$=u.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]??-lt(t.map(t=>-t)),o=n?.[1]??lt(t);if(!n){const t=.05*(o-a||Math.abs(o)||1);a-=t,o+=t}const r=un(o-a,e);return{min:a,max:o,step:r,ticks:dn(a,o,r)}})(d.length?d.map(e=>e.cells[t].value):[0,1],Math.max(e?a/o/(4*i):r/(9*i),4),m[e]));return n.ticks.textContent="",$.forEach((t,a)=>{const o=d[0]?.cells[u[a]],r=lt(t.ticks.map(t=>it(String(t))));for(const s of t.ticks){const t=Q(C,n.ticks);t.dataset.axis=a?"y":"x",t.dataset.value=String(s),o?.prefix&&(t.dataset.prefix=o.prefix),o?.suffix&&(t.dataset.suffix=o.suffix),ee(t,r,e.locale)}}),$})(t,e,G,V,q,R):[],Y=G?Array.from(G.ticks.children):[];B([...v.flat(),...t.totals,...x,...t.categories,...k.map(t=>t.badge),...G?.titles??[],...Y]);const X=(g[0]?E(g[0]).height:0)*q;!1===l.numbers&&g[0]&&(g[0].dataset.place="none");const et=k[0]?.badge?E(k[0].badge).height*q:0,nt=Math.max(V,F,t.agreed?.height??0,l.minHeight?.({labelHeight:X,nameHeight:Math.max(0,lt(t.categories.map(t=>E(t).height)))*q,unit:q,rows:s.length,series:y.length,stacked:t.stacked,labels:xn(t.figure,e,y.some(t=>t.chart))})??0),at=t.stacked?s.map(t=>{const e=vt(t,y.length);return{...t,value:e,cells:t.cells.map((t,n)=>0===n?{...t,value:e}:t)}}):s,ot=(l.segments??(t=>t.map(t=>({...t,from:0,to:t.value,kind:"bar"}))))(t.stacked?at.map(t=>({...t,cells:[t.cells[0]]})):s),rt={labelHeight:X,badgeHeight:et,hasAnnotations:k.length>0,unit:q,series:y.length,focused:y.some(t=>t.focus),stacked:t.stacked},{extent:ut,depth:dt,steps:ht}=((t,e,n)=>{const a=t.some(t=>"up"===t.kind||"down"===t.kind),o=n?n.map(t=>t.top):[...t.flatMap(t=>[t.from,t.to,t.value]),...e],r=a?t.flatMap(t=>[t.from,t.to]):n?n.map(t=>t.bottom):e;return{extent:Math.max(lt(o),0),depth:Math.min(-lt(r.map(t=>-t)),0),steps:a}})(ot,s.flatMap(t=>t.cells.slice(0,y.length).map(t=>t.value)),t.stacked?s.map(t=>yt(t,y.length,l.running)):null),ft=y.flatMap((t,e)=>t.chart?[e]:[]),bt=s.some(t=>t.note)?et+4*q:0,mt=Math.max(l.headroom?.(rt)??X,ft.length?Ae.headroom?.(rt)??0:0)+bt,$t=2*q+(l.footroom?.(rt)??0)+(dt<0?X+4*q:0),pt=Math.max(mt,t.agreed?.room??0),gt=Math.max($t,t.agreed?.floor??0),wt=nt-pt-gt,Mt=Math.max(z?Math.max(z.max,ut):1.02*ut,t.agreed?.ceiling??0),xt=Math.min(z?Math.min(z.min,dt):1.02*dt,t.agreed?.bottom??0),kt=k.find(t=>"axis-break"===t.spec.getAttribute("data-annotation"))?.spec,St=t=>{const e=Number.parseFloat(kt?.getAttribute(t)??"");return Number.isFinite(e)?e:null},{squeeze:Nt,problems:At}=(t=>{const{from:e,to:n,size:a,ceiling:o,extent:r,depth:s,breakable:c,segments:l}=t,i=[];if(null===e&&null===n)return{squeeze:null,problems:i};const u=e??0,d=n??o,h=null===n?u:null===e?d:(u+d)/2,f=a?.match(/^\s*(\d+(?:\.\d+)?)\s*%\s*$/);null===a||f||i.push(`data-size="${a}" is not a percentage, such as 30%. Using the default.`);const b=Math.min(Math.max(f?Number(f[1])/100:null===n?.22:.3,.05),.8),m=l.some(t=>("up"===t.kind||"down"===t.kind)&&Math.max(t.from,t.to)>u&&Math.min(t.from,t.to)<d);if(c)if(s<0)i.push("A chart with values below zero cannot break its scale.");else if(u<0||d<=u||d>o||0===u&&d===o)i.push(`A break from ${u} to ${d} does not fit a scale that runs from 0 to ${r}.`);else{if(!m)return{squeeze:{lo:u,hi:d,gap:h,share:b},problems:i};i.push(`A break from ${u} to ${d} would cut a step that floats. Keep it below or above the steps.`)}else i.push("This kind of chart cannot break its scale.");return{squeeze:null,problems:i}})({from:St("data-from")??St("data-at"),to:St("data-to"),size:kt?.getAttribute("data-size")??null,ceiling:Mt,extent:ut,depth:dt,breakable:!!l.breakable,segments:ot});for(const r of At)console.warn(`[${o}] ${r}`);const Ct=Nt?Nt.gap:null;t.measured=![pe,$e,Ae,Ce].includes(l)||Nt||ht?null:{height:nt,room:pt,floor:gt,ceiling:Mt,bottom:xt};const Ht=(Nt&&ne(t.figure,q,"--tablechart-break-gap",""))??13,Tt=nt-gt,Lt=Mt-xt||1;let _t,Ot,Bt=Nt?t=>Tt-me(t,Mt,wt,Nt,Ht):t=>Tt-(t-xt)/Lt*wt,Et=[];G&&({frame:Ot,x:_t,y:Bt,shownTicks:Et}=((t,e,n,a,o)=>{const r=6*o,[s,c]=t.titles,l=t=>t?E(t).width*o:0,i=t=>t?E(t).height*o:0,u=e.filter(t=>"x"===t.dataset.axis),d=e.filter(t=>"y"===t.dataset.axis),h=i(e[0]),f=l(c)+lt([0,...d.map(l)])+2*r,b=h/2,m=[f,b,T-f-lt([0,...u.map(l)])/2,a-b-i(s)-h-2*r],[$,p,g,w]=m,[M,y]=n,v=t=>$+(t-M.min)/(M.max-M.min||1)*g,x=t=>p+w-(t-y.min)/(y.max-y.min||1)*w,k=t=>l(u.find(e=>Number(e.dataset.value)===t)),S=[bn(M,t=>t.every((e,n)=>!n||v(e)-v(t[n-1])>(k(e)+k(t[n-1]))/2+r)).ticks,bn(y,t=>t.every((e,n)=>!n||x(t[n-1])-x(e)>h+r/2)).ticks];for(const N of e){const t=Number(N.dataset.value),e="x"===N.dataset.axis?0:1,n=S[e].includes(t);N.dataset.place=n?e?"before":"below":"none",n&&tt(N,e?$-r:v(t),e?x(t):p+w+r,T,a)}return s&&tt(s,$+g/2,a-i(s),T,a),c&&tt(c,0,p+w/2,T,a),{frame:m,x:v,y:x,shownTicks:S}})(G,Y,D,nt,q));const Rt=((t,e)=>{const n=(t.getAttribute("data-chart-values")??e.values).trim().toLowerCase().split(/\s+/).filter(Boolean);for(const r of n)["auto","all","none",...Sn].includes(r)||console.warn(`[${o}] data-chart-values knows no "${r}". It takes auto, all, none, ${Sn.join(", ")}.`);const a=n.filter(t=>Sn.includes(t));return n.includes("all")?{mode:"all",keys:[]}:n.includes("none")?{mode:"set",keys:[]}:n.includes("auto")||!a.length?{mode:"auto",keys:a.length?a:Sn}:{mode:"set",keys:a}})(t.figure,e),qt=ce(t.figure,e),Ft=!!l.running&&x.length>0&&!t.stacked&&"step"!==qt&&"set"===Rt.mode&&Rt.keys.includes("last"),Ut=Ft?lt(v.flat().map(t=>E(t).width))*q:0,Pt=x.length?lt(x.map(t=>E(t).width))*q+12*q+Ut:0,Vt=t.categories[0]?.parentElement;Vt&&(Vt.style.paddingRight=Pt?Pt/T*100+"%":"");const Wt=(T-Pt)/s.length,It=t=>t>=0&&t<s.length?t:null;t.rowAt=l.centre?null:"beside"===l.categories?(t,e)=>It(Math.floor(e*q/(nt/s.length))):t=>It(Math.floor(t*q/Wt));const jt=Wt/T*100,Gt=100/s.length;t.rowBox="beside"===l.categories?t=>[0,t*Gt,100,Gt]:t=>[t*jt,0,jt,100],a.setAttribute("viewBox",`0 0 1000 ${Z(nt)}`),a.textContent="",Ot&&_t&&((t,e,n,a,o,r,s)=>{const{svg:c}=t,[l,i,u,d]=n,[h,f]=r;re(t.figure,"data-chart-grid",e.grid)&&c.appendChild(J("path",{class:H,d:[...h.map(t=>`M${Z(a(t))},${Z(i)}V${Z(i+d)}`),...f.map(t=>`M${Z(l)},${Z(o(t))}H${Z(l+u)}`)].join("")})),c.appendChild(J("path",{class:A,d:[`M${Z(l)},${Z(i)}V${Z(i+d)}H${Z(l+u)}`,...h.map(t=>`M${Z(a(t))},${Z(i+d)}v${Z(4*s)}`),...f.map(t=>`M${Z(l)},${Z(o(t))}h${Z(-4*s)}`)].join("")}))})(t,e,Ot,_t,Bt,Et,q),t.checks=[];const Dt={rows:s,segments:ot,cx:t=>(t+.5)*Wt,y:Bt,x:_t,frame:Ot,length:(e,n)=>ne(t.figure,q,e,n),barWidth:Math.min(Wt*e.barfill,kn(t.figure,q)),barMax:kn(t.figure,q),barRadius:oe(t.figure,q,"--tablechart-bar-radius"),sliceRadius:oe(t.figure,q,"--tablechart-slice-radius"),height:nt,unit:q,labelHeight:X,badgeHeight:et,after:s.length,note:0,labels:xn(t.figure,e,ft.length>0),insideAlign:vn(t.figure),breakAt:Ct,squeeze:Nt,breakGap:Ht,domain:t.agreed?[xt,Mt]:z?[z.min,z.max]:null,stacked:t.stacked,shape:qt,pick:Rt,numbersAtEnd:Ft,totals:t.totals,svg:a,plot:n,values:g,series:y,own:y.map((t,e)=>e),seriesValues:v,names:x,categories:t.categories,centre:t.centre,config:e,checks:t.checks,taken:[],lineHoles:[]};n.style.setProperty("--count",String(Math.max(1,...s.map(t=>t.slot+1))));const Kt=t=>{const e=e=>({...e,...e.cells[t]??e.cells[0]});return{rows:s.map(e),segments:ot.map(t=>{const n=e(t);return"bar"===t.kind?{...n,to:n.value}:n}),values:v[t]}};if(ft.length){const t=y.flatMap((t,e)=>t.chart?[]:[e]);l.draw({...Dt,own:t,...1===t.length&&Kt(t[0])}),Ae.draw({...Dt,own:ft})}else l.draw(Dt);Dt.rowAt&&(t.rowAt=Dt.rowAt),t.pointOf=Dt.pointOf??null;const Yt=Number(n.style.getPropertyValue("--count"))||s.length;for(const o of t.figure.querySelectorAll(`.${$}`))o.style.setProperty("--i",String(Math.min(s[s.length-1].slot,Yt-1)));if(!t.stacked&&!n.hasAttribute("data-grouped"))for(const o of v)I(o,q,T),j(o,q,T,nt);O&&z&&((t,e,n,a,o,r,s,c,l)=>{const{svg:i,type:u}=t,d="beside"===u.categories,h=6*c,f=Array.from(n.ticks.children),b=t=>E(f.find(e=>Number(e.dataset.value)===t)??f[0]),m=bn(a,t=>t.every((e,n)=>!n||(d?o(e)-o(t[n-1])>(b(e).width+b(t[n-1]).width)/2*c+h:o(t[n-1])-o(e)>b(e).height*c+h/2))).ticks.filter(t=>!r||t<=r.lo||t>=r.hi);for(const p of f){const t=Number(p.dataset.value),e=n.numbers&&m.includes(t);p.dataset.place=e?d?"below":"before":"none",e&&tt(p,d?o(t):-h,d?s+h:o(t),T,s)}const $=T-l;re(t.figure,"data-chart-grid",e.grid)&&i.prepend(J("path",{class:H,d:m.map(t=>d?`M${Z(o(t))},0V${Z(s)}`:`M0,${Z(o(t))}H${Z($)}`).join("")})),n.numbers&&i.appendChild(J("path",{class:A,d:[d?`M${Z(o(a.min))},${Z(s)}H${Z(o(a.max))}`:`M0,${Z(o(a.max))}V${Z(o(a.min))}`,...m.map(t=>d?`M${Z(o(t))},${Z(s)}v${Z(4*c)}`:`M0,${Z(o(t))}h${Z(-4*c)}`)].join("")}))})(t,e,O,z,_&&Dt.x?Dt.x:Bt,Nt,nt,q,Pt);for(const[o,r]of k.entries()){r.badge?.setAttribute("data-note",String(o+1));const e=r.series;r.type.draw(r.spec,r.badge,{...Dt,...t.stacked&&{rows:at,...t.totals.length&&{values:t.totals}},...e>0&&!t.stacked&&Kt(e),after:t.plan?r.after:Math.min(r.after,Number(n.style.getPropertyValue("--count"))||r.after),note:o+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),o=t=>{const e=a(t);return e.some(t=>null===t)?null:Math.min(...e)},r=new Set(t.totals),s=Boolean(t.type.axes),l=(t,e,n,a)=>{s&&"--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 c of t.figure.querySelectorAll("[data-row], [data-series], [data-note]")){if(c.closest("table, .tablechart-controls")||c.hasAttribute("data-from"))continue;const t=Number(c.dataset.note);if(t>0){const n=e.notes[t-1];n&&l(c,n.step,"--after",n.after);continue}const s=c.dataset.row?Number(c.dataset.row)-1:n;if(c.classList.contains("tablechart-connector")){const t=e.rows[s-1],n=e.rows[s];if(t&&n){const e=(t.step??-1)>(n.step??-1);l(c,e?t.step:n.step,"--i",e?t.slot+1:n.slot)}continue}if(r.has(c)){const t=a(s).filter(t=>null!==t);l(c,t.length?Math.max(...t):null,"--i",e.rows[s]?.slot??0);continue}if(c.hasAttribute("data-stack")){l(c,o(s),"--i",e.rows[s]?.slot??0);continue}const i=c.dataset.series?Number(c.dataset.series)-1:0,u=c.dataset.series?e.series[i]:void 0;if(c.classList.contains("tablechart-piece")){const t=a(s)[i]??null,n=e.cells[s]?.[i];l(c,t===o(s)?null:t,"--i",n&&null!==n.step?n.slot:s);continue}if("legend"===c.dataset.place){const t=Math.min(...e.cells.map(t=>t[i]?.step??Number.POSITIVE_INFINITY));l(c,u?.step??(Number.isFinite(t)?t:null),"--i",0);continue}const d=e.cells[s]?.[i];d&&null!==d.step?l(c,d.step,"--i",d.slot):u&&null!==u.step?l(c,u.step,"--i",s):e.rows[s]&&l(c,e.rows[s].step,"--i",e.rows[s].slot)}const i=t.figure.querySelector(`.${M}`);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 u=[...e.rows,...e.cells.flat()].map(t=>t.slot+1),d=e.series.some(t=>null!==t.step)?e.rows.length:1;s||t.plot.style.setProperty("--count",String(Math.max(d,...u)));const h=t.figure.querySelectorAll(`.${c}`),b=h[h.length-1];if("waterfall"===t.figure.dataset.chart&&"total"===b?.dataset.kind&&h.length>1){const t=Number(b.dataset.row)-1;(e.rows[t-1]?.step??-1)>(e.rows[t]?.step??-1)&&(b.dataset.grow="down"===b.dataset.grow?"up":"down")}const m=Array.from(t.figure.querySelectorAll(`.${f}`));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??"",K(a,n(o),e)),a+=n(o)}for(const c of t.figure.querySelectorAll("[data-row]")){const t=s.get(c.dataset.row??"");t&&c.style.getPropertyValue("--start")&&(c.style.setProperty("--start",t.start.toFixed(4)),c.style.setProperty("--span",t.span.toFixed(4)),c.classList.contains("tablechart-slice")&&c.style.setProperty("--ease",t.easing))}}zt(t)})(t);for(const o of t.figure.querySelectorAll(`.${p}`)){const e=Array.from(o.children);if(t.plan)for(const t of e)t.style.getPropertyValue("--step")||t.style.setProperty("--i","0");const n=e.map(t=>Number.parseFloat(t.style.getPropertyValue("--step")));o.style.setProperty("--i",String(Math.min(...e.map(t=>Number(t.style.getPropertyValue("--i"))||0)))),n.length&&n.every(Number.isFinite)?o.style.setProperty("--step",String(Math.min(...n))):o.style.removeProperty("--step")}((t,e,n,a)=>{const{rows:o,svg:r,type:s}=t,c=t.categories[0]?.parentElement;if(c&&"beside"!==s.categories&&!s.centre){c.style.height=`${c.offsetHeight}px`,c.removeAttribute("data-thinned");for(const e of t.categories)e.removeAttribute("data-left-out"),e.removeAttribute("data-edge");const l=t.categories.filter(t=>null!==t.offsetParent);if(!U(c,l,t=>({size:t.scrollWidth,room:t.clientWidth}),"--_name-fit")&&l.length>1){const t=getComputedStyle(c),e=(c.clientWidth-Number.parseFloat(t.paddingLeft)-Number.parseFloat(t.paddingRight))/o.length;c.style.setProperty("--_name-fit","1"),c.setAttribute("data-thinned","");const n=lt(l.map(t=>t.offsetWidth)),a=8,r=Math.max(Math.ceil((n+a)/e),Math.ceil((1.5*n+a)/e-.5),1);l.forEach((t,e)=>{e%r&&t.setAttribute("data-left-out","")});const s=l.filter(t=>!t.hasAttribute("data-left-out")),i=s[0],u=s.at(-1),d=c.getBoundingClientRect(),h=[i,u].map(t=>t?.getBoundingClientRect());if(i&&h[0]&&h[0].left<d.left&&i.setAttribute("data-edge","start"),u&&u!==i&&h[1]&&h[1].right>d.right-Number.parseFloat(t.paddingRight)){u.setAttribute("data-edge","end");const t=s.at(-2);t&&t.getBoundingClientRect().right+a>u.getBoundingClientRect().left&&u.setAttribute("data-left-out","")}}const i=(s===Ae||s===Ce)&&re(t.figure,"data-chart-ticks",e.ticks);if(c.toggleAttribute("data-ticks",i),c.style.removeProperty("--_tick-reach"),i){const e=n-Number(r.querySelector(".tablechart-rule")?.getAttribute("y1")??n);e>0&&e<10*a&&c.style.setProperty("--_tick-reach",`${Z(e/a)}px`);const s=c.getBoundingClientRect(),l=s.width/(c.offsetWidth||1),i=getComputedStyle(c),u=Number.parseFloat(i.paddingLeft),d=(c.clientWidth-u-Number.parseFloat(i.paddingRight))/o.length;t.categories.forEach((t,e)=>{if(t.hasAttribute("data-left-out"))t.style.removeProperty("--_tick");else{const n=(t.getBoundingClientRect().left-s.left)/l-c.clientLeft;t.style.setProperty("--_tick",`${Z(u+(e+.5)*d-n)}px`)}})}c.style.height=""}})(t,e,nt,q);const Zt=k.flatMap(({badge:t})=>{if(!(t instanceof HTMLElement&&t.offsetWidth))return[];const e=t.offsetWidth*q,n=t.offsetHeight*q,a=Number.parseFloat(t.style.left)/100*T,o=Number.parseFloat(t.style.top)/100*nt,r=getComputedStyle(t).borderTopLeftRadius,s=r.endsWith("%")?Number.parseFloat(r)/100:null,c=(Number.parseFloat(r)||0)*q;return[J("rect",{class:w,"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("; ")})]}),Jt=a.querySelector(`.${H}`),Xt=Array.from(a.querySelectorAll(`.${u}`)),Qt=[...Jt?[Jt]:[],...a.querySelectorAll(`:scope > .${d}`)],te=((t,e)=>{const n=t.getBoundingClientRect(),a=T/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?[J("rect",{class:w,"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("; ")})]:[]}})(n,q),se="grow"===t.figure.getAttribute("data-animate"),le=v.flat().filter(t=>t.hasAttribute("data-cut")).flatMap(te),ie=[...ft.flatMap(t=>v[t].flatMap(te)),...se?le:[]];if(Qt.length||Xt.length){const e=[...v.flat(),...t.totals,..."beside"===l.categories?t.categories:[]].flatMap(te),n=t=>["x","y","width","height"].map(e=>Number(t.getAttribute(e)));for(const t of Xt)wn(t,[...e,...Zt].map(n));for(const t of Qt){const a=[...e,...Zt],o=Mn(t);t.setAttribute("d",o.map(([t,e,o,r])=>gn(t,e,o,r,a.map(n))).join(""));for(const e of a){const a=yn(o,n(e)),r="badge"===e.dataset.for?"badge":"";a&&t.after(J("path",{class:t.getAttribute("class")??"tablechart-grid","data-gap":r,d:a,style:e.getAttribute("style")??""}))}}}if(st(a,Zt,T,nt,Array.from(a.querySelectorAll(`.${i}, .${h}`))),!se&&(Dt.lineHoles.length||le.length)){const t=Array.from(a.querySelectorAll(`.${b}`)).map(t=>{const e=J("g",{});return t.before(e),e.append(t),e});st(a,[...Dt.lineHoles,...le],T,nt,[...t,...a.querySelectorAll(`.${m}`)])}const ue=[u,d,i,h,H];ct(a,[...Zt,...ie],T,nt,void 0,ue.map(t=>`.${t}`).join(", ")),!t.figure.hasAttribute("data-animate")||t.figure.hasAttribute("data-steps")||t.figure.classList.contains("is-shown")||Re(a);const de=t=>"none"!==t.dataset.place&&!t.hasAttribute("data-left-out");return t.figure.toggleAttribute("data-left-out",(l.columns?[t.categories]:[...v,t.totals]).some(t=>t.some(e=>!(t=>void 0!==t.dataset.missing||l.centre&&s[Number(t.dataset.row)-1]?.isTotal)(e)&&!de(e)&&!((t,e)=>{const n=Number(t.dataset.row);return e.some(t=>de(t)&&Number(t.dataset.row)<=n&&n<=Number(t.dataset.rowEnd??t.dataset.row))})(e,t)))),Dt.barRadius&&((t,e)=>{for(const n of t.querySelectorAll("rect[data-end]")){const[t,a,o,r]=["x","y","width","height"].map(t=>Number(n.getAttribute(t))),s=n.getAttribute("data-end"),c="left"===s||"right"===s,l=Z(Math.min(e,c?r/2:o/2,c?o:r)),i=(t,e)=>`a${l},${l} 0 0 1 ${t},${e}`,u={top:`M${t},${Z(a+r)}v${Z(l-r)}${i(l,-l)}h${Z(o-2*l)}${i(l,l)}v${Z(r-l)}z`,bottom:`M${Z(t+o)},${a}v${Z(r-l)}${i(-l,l)}h${Z(2*l-o)}${i(-l,-l)}v${Z(l-r)}z`,right:`M${t},${a}h${Z(o-l)}${i(l,l)}v${Z(r-2*l)}${i(-l,l)}h${Z(l-o)}z`,left:`M${Z(t+o)},${Z(a+r)}h${Z(l-o)}${i(-l,-l)}v${Z(2*l-r)}${i(l,-l)}h${Z(o-l)}z`}[s],d=J("path",{d:u});for(const{name:e,value:h}of Array.from(n.attributes))["x","y","width","height"].includes(e)||d.setAttribute(e,h);n.replaceWith(d)}})(a,Dt.barRadius),tn(t.figure),sn(t.figure),cn(t.figure),(t=>{const e=t.closest("[data-chart-group]");if(!e)return;const n=e.getAttribute("data-chart-group"),a=(n?Array.from(document.querySelectorAll(`[data-chart-group="${CSS.escape(n)}"]`)):[e]).flatMap(t=>Array.from(t.querySelectorAll(`.${r}:not([data-place])`)));for(const r of a)r.style.minHeight="";const o=a.map(t=>({row:t,tall:t.offsetHeight,top:t.closest("figure")?.getBoundingClientRect().top??0})).filter(({tall:t})=>t>0).sort((t,e)=>t.top-e.top);for(let r=0;r<o.length;){let t=r;for(;t+1<o.length&&o[t+1].top-o[r].top<4;)t++;const e=o.slice(r,t+1),n=lt(e.map(({tall:t})=>t));if(e.length>1)for(const{row:a,tall:o}of e)o<n&&(a.style.minHeight=`${n}px`);r=t+1}})(t.figure),!0},Hn={2:{part:3,text:4.5,large:3,show:t=>`${(Math.floor(100*t)/100).toFixed(2)}:1`,need:t=>`${t}:1`,partRule:"WCAG 1.4.11",textRule:"WCAG 1.4.3"},3:{part:30,text:60,large:45,show:t=>`Lc ${Math.floor(t)}`,need:t=>`Lc ${t}`,partRule:"APCA, WCAG 3 draft",textRule:"APCA, WCAG 3 draft"}},Tn=["bar","piece","up","down","total"].map(t=>`--tablechart-${t}-value-color`),Ln=new Set,_n=t=>"id"===t||"style"===t||t.startsWith("data-chart"),On=/^\s*(?:Table)?:\s+/,zn=t=>"P"===t?.tagName&&On.test(t.textContent??""),Bn=/^\s*([a-z][\w-]*)((?:\s+[\w-]+=[^\s:]+)*)\s*(:\s*|$)/,En=t=>{const e=qn(t);return"P"===e?.tagName?e:t},Rn=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},qn=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},Fn="strong, b, span.total",Un="data-chart-made",Pn="data-tablechart-ready",Vn=()=>window.matchMedia("(prefers-reduced-motion: reduce)").matches,Wn=new Set,In=null,jn=["column","bar"],Gn=t=>{const e=t.getAttribute("data-chart")||"column";if(!jn.includes(e))return null;const n=getComputedStyle(t).getPropertyValue("--tablechart-type").trim();return jn.includes(n)?n:e},Dn=!1,Kn=async(t,e)=>{const n=(t=>t.map(t=>{const e=t.closest("p"),n=zn(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||_n(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?zn(r)?r:zn(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=En(t).firstChild;if(e?.nodeType!==Node.TEXT_NODE)return null;const n=Bn.exec(e.textContent??"");if(!n||!Oe.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=En(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(On,""),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),At?.log?.(`A ${o?"table":"caption"} with chart attributes was wrapped in a figure of its own`),a}))(t.filter(t=>!t.hasAttribute(Un)&&"TH"!==t.tagName));(t=>{const e=t.find(t=>"FIGURE"!==t.tagName);!Dn&&e&&(Dn=!0,console.warn(`[${o}] A chart is a <${e.tagName.toLowerCase()}>. Use a <figure> with a <figcaption>, so the chart has a title, also for screen readers.`,e))})(n);for(const a of n){const t=Number.parseFloat(a.getAttribute("data-chart-aspect")??"");t>0&&a.style.setProperty("--_room",String(t))}await(async t=>{await Promise.all(t.filter(t=>t.hasAttribute("data-chart-src")).map(async t=>{const e=t.getAttribute("data-chart-src"),n=Array.from(t.querySelectorAll("table")).find(t=>t.tHead)??null;for(const o of t.querySelectorAll("table"))o!==n&&o.remove();try{const a=await fetch(e);if(!a.ok)throw new Error(`${a.status} ${a.statusText}`);const o=await a.json(),r=Array.isArray(o)?o:o?.rows?Array.isArray(o.rows)?o.rows:Rn(o.rows):Rn(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:"",n??void 0,"string"==typeof o?.note?o.note:void 0);if(!n){const e=t.querySelector(":scope > figcaption");e?e.after(s):t.prepend(s)}s.tHead||At?.log?.(`The table from "${e}" has no header row, so a screen reader cannot name its columns.`),At?.log?.(`Read ${r.length} rows from "${e}"`)}catch(a){const t="file:"===window.location.protocol;console.warn(`[${o}] 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.":""))}}))})(n),(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=qn(e);a?.matches(Fn);a=qn(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=qn(e);t?.matches(Fn);t=qn(e))e.setAttribute("data-kind","focus"),t.replaceWith(...t.childNodes)}})(n),((t,e)=>{if(!e)return;const n=new Map;for(const a of t){let t=a.getAttribute("data-chart-keys")||null;if(!t)continue;if(n.has(t)){const e=n.get(t)+1;n.set(t,e),console.warn(`[${o}] Two charts have data-chart-keys="${t}", so this one uses "${t}-${e}" to keep their translations apart.`),t=`${t}-${e}`}else n.set(t,1);a.querySelectorAll("tbody th").forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-row${a+1}`)});const r=Lt(a);r.length>1&&r.forEach((n,a)=>{n.getAttribute(e)||n.setAttribute(e,`${t}-col${a+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 a=(n.textContent||"").trim();r.includes(a)||r.push(a),n.getAttribute(e)||n.setAttribute(e,`${t}-group${r.indexOf(a)+1}`)})});const s=Ht(a);a.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}`)}}),At?.log?.(`Keys for "${t}" written onto ${a.querySelectorAll("tbody th").length} rows`)}})(n,e.langattribute);for(const a of n)a.dispatchEvent(new CustomEvent("tablechart:table",{bubbles:!0}));return n},Yn=({figure:t,plot:e,svg:n},a)=>{const o=["aria-labelledby","aria-label"].find(e=>t.hasAttribute(e));"FIGURE"!==t.tagName||!o||t.hasAttribute("role")&&"group"!==t.getAttribute("role")||(a?(t.setAttribute("role","group"),e.removeAttribute("aria-hidden"),n.setAttribute("role","img"),n.setAttribute(o,t.getAttribute(o)??"")):(t.removeAttribute("role"),e.setAttribute("aria-hidden","true"),n.setAttribute("role","presentation"),n.removeAttribute(o)))},Zn=(t,e)=>{const n=At.timed("Building",t,()=>Ve(t,e));return n?(t.setAttribute(Un,""),Qn(),((t,e)=>{let n=t,a=Gn(n.figure),r=null,s=!1,c=!1,l=!1,i=!1;const u=()=>{e.replay||$.unobserve(n.figure)},d=async()=>{if(!le(n.figure,e))return ze(n,!0),u();const t=n.figure.classList.contains("is-shown");if(!c||null===r||t||l)!c&&e.replay&&t&&ze(n,!1);else{l=!0;const t=Vn()?null:(t=>{for(let e=t;e&&e!==document.body;e=e.parentElement)if("0"===getComputedStyle(e).opacity)return e;return null})(n.figure);t&&await(a=t,new Promise(t=>{const e=["animationstart","transitionrun"],n=()=>{for(const t of e)document.removeEventListener(t,o,!0);r.disconnect(),t()},o=t=>{t.target instanceof Node&&t.target.contains(a)&&n()},r=new MutationObserver(()=>{"0"!==getComputedStyle(a).opacity&&n()});for(const a of e)document.addEventListener(a,o,!0);r.observe(a,{attributes:!0,attributeFilter:["class","style"]})})),await(async(t,e)=>{if(Vn())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)))})(n.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)})(n.figure,e)),l=!1,!c&&e.replay||ze(n,!0),u()}var a},h=()=>{const t=Gn(n.figure);if(!t||t===a)return;const o=At.timed("Building",n.figure,()=>Ve(n.figure,e,t));o&&((t=>{te(t),t.plot.remove(),t.categories[0]?.parentElement?.remove(),t.figure.querySelector(`:scope > .${p}`)?.remove(),t.controls?.remove()})(n),Bt(o,n.step,!0),n=o,a=t,r=null)},f=()=>{h();const t=n.plot.clientWidth;t&&t!==r&&At.timed("Layout",n.figure,()=>An(n,e))&&(s||(s=!0,(t=>{const e=en(t),n=Hn[Ye(t)],a=Array.from(t.querySelectorAll("table thead tr:first-child > *")).map(t=>(t.textContent??"").trim()),r=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),s=[[".tablechart-series","Line",t=>getComputedStyle(t).stroke],[".tablechart-slice","Slice",t=>getComputedStyle(t).stroke],[".tablechart-bar, .tablechart-piece","Bar",t=>getComputedStyle(t).fill]],c=new Map;for(const[o,l,i]of s){const s=Array.from(t.querySelectorAll(`${o}:not([data-muted])`));for(const o of s){const u=i(o),[d,h,f,b]=De(u),m=[d,h,f].map((t,n)=>t*b+e[n]*(1-b)),$=Je(Ye(t),m,e);if($>=n.part)continue;const p=o.getAttribute("data-series"),g=r[Number(o.getAttribute("data-row")??0)-1]??"",w="Slice"===l?"":p?a[Number(p)]:"",M=`${l}|${w}|${u}`,y=c.get(M)??{kind:l,column:w,rows:new Set,all:0,contrast:$};y.rows.add(g),y.all=s.filter(t=>t.getAttribute("data-series")===p).length,c.set(M,y)}}for(const{kind:l,column:i,rows:u,all:d,contrast:h}of c.values()){const e=Array.from(u).filter(Boolean).map(t=>`"${t}"`),a=e.join(", "),r=e.length>1,s="Line"===l?i?`Line "${i}" has`:"The line has":"Slice"===l?`${r?"Slices":"Slice"} ${a} ${r?"have":"has"}`:u.size>=d||!a?`The bars${i?` of column "${i}"`:""} have`:`${r?"Bars":"Bar"} ${a}${i?` in column "${i}"`:""} ${r?"have":"has"}`;console.warn(`[${o}] ${s} a contrast of ${n.show(h)} with the background. It needs at least ${n.need(n.part)} (${n.partRule}).`,t)}})(n.figure),(t=>{let e=0;const n=()=>{const n=Array.from(t.querySelectorAll(".tablechart-value[data-place='inside'], .tablechart-value[data-place='middle']")).filter(t=>!t.hasAttribute("data-left-out")&&!t.hidden),r=Array.from(t.querySelectorAll(".tablechart-name, .tablechart-value:not([data-place='inside'], [data-place='middle']), .tablechart-categories span, .tablechart-centre, .tablechart-tick, .tablechart-quadrant-name, figcaption b, figcaption span")).filter(t=>!t.hasAttribute("data-left-out")&&!t.hidden&&"1"!==t.style.getPropertyValue("--m")&&(t.textContent??"").trim()&&"hidden"!==getComputedStyle(t).visibility);if([...n,...r].some(t=>0===De(getComputedStyle(t).color)[3]&&e<20))return e++,void setTimeout(a,500);const s=Array.from(t.querySelectorAll("tbody tr > :first-child")).map(t=>(t.textContent??"").trim()),c=Hn[Ye(t)],l="bar"===t.dataset.chart?"bar":"column",i=new Map;for(const e of n){const n=nn(t,e);if(!n)continue;const a=getComputedStyle(e),o=getComputedStyle(n).fill,r=Je(Ye(t),De(a.color),De(o)),u=Number.parseFloat(a.fontSize),d=u>=24||u>=18.66&&Number(a.fontWeight)>=700?c.large:c.text;if(r>=d)continue;const h=n.classList.contains("tablechart-piece")?`${l} part`:l,f=`${a.color}|${o}`,b=i.get(f)??{what:h,names:[],contrast:r,needed:d};b.names.push(`"${s[Number(e.dataset.row)-1]??""}" ("${e.textContent?.trim()}")`),i.set(f,b)}const u=en(t),d=new Map;for(const e of r){const n=getComputedStyle(e),[a,o,r,s]=De(n.color),l=[a,o,r].map((t,e)=>t*s+u[e]*(1-s)),i=Je(Ye(t),l,u),h=Number.parseFloat(n.fontSize),f=h>=24||h>=18.66&&Number(n.fontWeight)>=700?c.large:c.text;if(i>=f)continue;const b=d.get(n.color)??{names:[],contrast:i,needed:f};b.names.push(`"${e.textContent?.trim()}"`),d.set(n.color,b)}for(const{names:e,contrast:a,needed:h}of d.values())console.warn(`[${o}] The text ${e.join(", ")} has a contrast of ${c.show(a)} with the background. Text needs at least ${c.need(h)} (${c.textRule}).`,t);for(const{what:e,names:a,contrast:h,needed:f}of i.values()){const n=a.length>1;console.warn(`[${o}] The text inside the ${e}${n?"s":""} of ${a.join(", ")} has a contrast of ${c.show(h)} with ${n?"those":"that"} ${e}${n?"s":""}. Text needs at least ${c.need(f)} (${c.textRule}).`,t)}},a=()=>requestAnimationFrame(()=>requestAnimationFrame(()=>{const e=t.getAnimations({subtree:!0}).map(t=>t.finished.catch(()=>{}));Promise.all(e).then(n)}));if(t.classList.contains("is-shown"))return void a();const r=new MutationObserver(()=>{t.classList.contains("is-shown")&&(r.disconnect(),a())});r.observe(t,{attributes:!0,attributeFilter:["class"]})})(n.figure),(t=>{const e=getComputedStyle(t);for(const n of Tn)!Ln.has(n)&&e.getPropertyValue(n).trim()&&(Ln.add(n),console.warn(`[${o}] ${n} is old and goes in 1.3.0. --tablechart-value-on-dark and --tablechart-value-on-light set the colour of the numbers inside bars, with a contrast check.`,t))})(n.figure)),r=t,d())};let b=!1;const m=new ResizeObserver(()=>{f(),m.unobserve(n.figure),requestAnimationFrame(()=>b||m.observe(n.figure))}),$=new IntersectionObserver(t=>{for(const e of t)c=e.isIntersecting,d()},{threshold:e.threshold}),g=()=>{n.figure.classList.add(k),ze(n,!0),qe(n.svg),n.figure.offsetWidth,Yn(n,!0);const t=document.documentElement,a=t.style.width;t.style.width="700px",i=null!==r&&n.plot.clientWidth<.9*r,i&&An(n,e),t.style.width=a},w=()=>{n.figure.classList.remove(k),Yn(n,!1),i&&An(n,e),i=!1},M=()=>{r=null,f()},y={relabel:()=>je(n,e),refresh:M};h(),f(),m.observe(n.figure),$.observe(n.figure),window.addEventListener("beforeprint",g),window.addEventListener("afterprint",w),(t=>{Wn.add(t),In||(In=new MutationObserver(()=>{for(const t of Wn)t.relabel();requestAnimationFrame(()=>requestAnimationFrame(()=>{for(const t of Wn)t.refresh()}))})).observe(document.documentElement,{attributes:!0,attributeFilter:["lang"]})})(y);const v={figure:n.figure,refresh:M,next:()=>Bt(n,n.step+1),previous:()=>Bt(n,n.step-1),stepTo:t=>Bt(n,t),replay(){if(n.plan)return Bt(n,0);le(n.figure,e)&&(ze(n,!1,!0),requestAnimationFrame(()=>b||ze(n,!0)))},reset(){!n.plan&&le(n.figure,e)&&(c=!1,ze(n,!1,!0),$.observe(n.figure))},get step(){return n.step},get steps(){return n.plan?.count??0},destroy(){b=!0,m.disconnect(),$.disconnect(),window.removeEventListener("beforeprint",g),window.removeEventListener("afterprint",w),(t=>{Wn.delete(t),!Wn.size&&In&&(In.disconnect(),In=null)})(y),te(n),n.figure.tablechart===v&&delete n.figure.tablechart}};return n.figure.tablechart=v,v})(n,e)):null},Jn=!1,Xn=new WeakMap,Qn=()=>{if(Jn||"function"!=typeof matchMedia)return;Jn=!0;const t=()=>{for(const t of document.querySelectorAll(`[${Un}]`)){const e=getComputedStyle(t).color,n=tn(t)||Xn.get(t)!==e;Xn.set(t,e),n&&(sn(t),cn(t))}};matchMedia("(prefers-color-scheme: dark)").addEventListener("change",t);const e=new MutationObserver(t);for(const n of[document.documentElement,document.body])e.observe(n,{attributes:!0});document.addEventListener("transitionend",e=>{e.target!==document.documentElement&&e.target!==document.body||t()})},ta=0,ea=a({GRID_CLASS:()=>H,LEGEND_CLASS:()=>p,LIBRARY_NAME:()=>o,NAME_CLASS:()=>$,POINT_CLASS:()=>g,QUADRANT_CLASS:()=>d,VIEWBOX_WIDTH:()=>T,avoidCollisions:()=>O,boxOf:()=>W,decimalsIn:()=>it,htmlEl:()=>Q,largest:()=>lt,markerEl:()=>pt,overlaps:()=>_,placeAt:()=>tt,readSeries:()=>_t,readTable:()=>Tt,short:()=>Z,sizeOf:()=>E,splitSign:()=>ut,svgEl:()=>J});window.Tablechart={init:async(t={},e=document)=>{const n={...L,...t};n.debug&&(At.enabled=!0),ta+=1,document.documentElement.removeAttribute(Pn);const a=(await Kn(Array.from(e.querySelectorAll(n.selector)),n)).map(t=>Zn(t,n)).filter(t=>null!==t);return At.log(`Made ${a.length} chart(s).`),(ta-=1)||(document.documentElement.setAttribute(Pn,""),document.dispatchEvent(new CustomEvent("tablechart:ready"))),{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={...L,...e};n.debug&&(At.enabled=!0);const[a]=await Kn([t],n);return a?Zn(a,n):null},defaultConfig:L,addType:(t,e)=>{Le[t]=e,Object.assign(_e,e.annotations),Oe.splice(0,1/0,...Object.keys(_e))},kit:ea}}();