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