@graphysdk/viz-engine 0.0.1-alpha.4 → 0.0.1-alpha.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/dist/index.cjs +2 -2
- package/dist/index.d.ts +56 -12
- package/dist/index.mjs +1833 -1760
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("lodash-es"),T=require("date-fns"),te=require("d3-time"),cr=require("date-fns/differenceInDays"),B=require("d3-scale"),F=require("arquero"),$t=require("lodash-es/merge"),lr=require("humanize-duration"),ur=require("d3-delaunay");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-alpha.4");const Wt=e=>e.length>0;function m(e){return e!=null}const Ht=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],Kt="default";class K{constructor(t){this.label=t,this.items=new Map}register(t,n){return this.items.set(t,n),this}get(t){if(!this.items.has(t)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new Error(`Unknown ${this.label}: '${t}' (available: ${n})`)}return this.items.get(t)}getAll(){return[...this.items.values()]}has(t){return this.items.has(t)}}class dr extends K{constructor(){super("palette")}}function le(e){return{pipe:t=>{const n=t(e);return le({...e,...n})},result:()=>e}}class pr{constructor(t){this.registry=t}setup(t){return this.registry.get(t.coordSpec.coordType).setup(t)}transform(t){return this.registry.get(t.coordSpec.coordType).transform(t)}}class mr{constructor(){this.coordType="cartesian"}setup(t){if(t.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}}}transform(t){return t.layers}}const jt="\0graphy\0_",A=e=>`${jt}${e}`,He=e=>e.startsWith(jt),gt={x:A("constantX")},Ke={count:A("count")},fr={[Ke.count]:{type:"integer"}},V={group:A("group")},u={x:A("x"),y:A("y"),xMin:A("xMin"),xMax:A("xMax"),yMin:A("yMin"),yMax:A("yMax")},j={color:A("color"),size:A("size"),alpha:A("alpha"),strokeWidth:A("strokeWidth")};({...V,...u,...j});class yr{constructor(){this.coordType="flip"}setup(t){if(t.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}}}transform(t){return t.layers.map(n=>gr(n))}}const hr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]],bt=A("flipSwap");function gr(e){let t=e.data;for(const[n,r]of hr){const a=t.hasVariable(n),s=t.hasVariable(r);a&&s?t=t.renameVariable(n,bt).renameVariable(r,n).renameVariable(bt,r):a?t=t.renameVariable(n,r):s&&(t=t.renameVariable(r,n))}return{...e,data:t}}class br{constructor(){this.coordType="polar"}setup(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec;return{type:"polar",axisMapping:n.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}}}}transform(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec,r=xr(n),a=Mr(n);return t.layers.map(s=>{const i=n.theta==="y"?Ar(s):s;return Sr(i,r,a)})}}function xr(e){const t=e.startAngle*(Math.PI/180);return n=>n*2*Math.PI+t}function Mr(e){const{innerRadius:t}=e;return n=>t+n*(1-t)}function Sr(e,t,n){let r=e.data;return r=q(r,u.x,t),r=q(r,u.xMin,t),r=q(r,u.xMax,t),r=q(r,u.y,n),r=q(r,u.yMin,n),r=q(r,u.yMax,n),{...e,data:r}}function q(e,t,n){if(!e.hasVariable(t))return e;const a=e.getValues(t,{type:"numeric"}).map(s=>s===null?null:n(s));return e.addVariable(t,"numeric",a)}const Tr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]];function Ar(e){let t=e.data;for(const[n,r]of Tr){const a=t.hasVariable(n),s=t.hasVariable(r);if(!a&&!s)continue;const i=a?t.getValues(n):null,o=s?t.getValues(r):null;i&&(t=t.addVariable(r,"numeric",i)),o&&(t=t.addVariable(n,"numeric",o))}return{...e,data:t}}class wr extends K{constructor(){super("coord"),this.register("cartesian",new mr),this.register("flip",new yr),this.register("polar",new br)}}class vr{constructor(t){this.registry=t}compile(t,n){return this.registry.get(t).compile(n)}}function Vr(e){return{type:"mapping",mapping:e}}function M(e){return m(e)?typeof e=="string"?e:"variable"in e?e.variable:null:null}function Ir(e){if(!(!m(e)||typeof e=="string")&&"value"in e)return e.value}const qt=(e,t)=>{if(m(t.group)){const a=M(t.group);if(a!==null)return[a]}const n=new Set([M(t.x),M(t.y)].filter(m)),r=new Set;for(const a in t){if(a==="x"||a==="y")continue;const s=M(t[a]);m(s)&&(n.has(s)||e.getType(s)==="categorical"&&r.add(s))}return[...r]};class Le{constructor(){this.requiredAesthetics=[]}}const Xt=(e,t)=>{const n=M(t.x);return!n||!["numeric","temporal"].includes(e.getType(n))?e:e.orderBy(n,"asc")};class Er extends Le{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"]}compile({data:t,mapping:n}){if(t=Xt(t,n),t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const r=M(n.y);m(r)&&t.hasVariable(r)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(r,{type:"numeric"})))}return{data:t,mapping:{}}}}const Qt=.7,_r=.1;class Lr extends Le{constructor(){super(...arguments),this.type="bar"}compile({data:t,mapping:n}){if(t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const a=M(n.y);m(a)&&t.hasVariable(a)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(a,{type:"numeric"})))}const r=Qt/2;return t=t.addConstantVariable(u.xMin,"numeric",-r).addConstantVariable(u.xMax,"numeric",r),{data:t,mapping:{}}}}class kr extends Le{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"]}compile(t){return{data:Xt(t.data,t.mapping),mapping:{}}}}class Dr extends Le{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"]}compile({data:t}){return{data:t,mapping:{}}}}class Cr extends K{constructor(){super("geom"),this.register("bar",new Lr),this.register("point",new Dr),this.register("line",new kr),this.register("area",new Er)}}const $=e=>(Array.isArray(e)?e:[e]).map(n=>n instanceof Date?n.toISOString():String(n??"<null>")).join("\0");class Rr{compute({data:t,mapping:n}){const r=qt(t,n);if(r.length===0)return{data:t.addConstantVariable(V.group,"categorical",null)};const a=t.size(),s=r.map(o=>t.getValues(o)),i=new Array(a);for(let o=0;o<a;o++)i[o]=$(s.map(c=>c[o]));return{data:t.addVariable(V.group,"categorical",i)}}}const Jt=new Set(["x","y","ySecondary"]),Zt=new Set(["color","size","alpha","strokeWidth"]),ke=e=>Jt.has(e),Nr=e=>Zt.has(e),Fr=e=>ke(e)||Nr(e);function ue(e){return e==="secondary"?"ySecondary":"y"}function U(e){return e==="ySecondary"?"y":e}const Z=e=>e instanceof Date&&T.isValid(e),en=e=>typeof e=="string",tn=e=>typeof e=="number"&&!Number.isNaN(e),Or=e=>e.type==="text",de=e=>e.type==="date"||e.type==="datetime"||e.type==="year"||e.type==="month_year"||e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range"||e.type==="weekly_date_range_with_year"||e.type==="quarter"||e.type==="time",nn=e=>e.type==="decimal"||e.type==="integer"||e.type==="percentage"||e.type==="duration"||e.type==="currency",rn=e=>e.type==="currency",an=e=>e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range",Pr=e=>{if(de(e))return"temporal";if(nn(e))return"numeric";if(Or(e))return"categorical";const t=e;throw new Error(`No data type found for value format: ${t.type}`)},xt={year:0,quarter:1,month:2,week:3,day:4,hour:5},Br=[{unit:"year",step:1e3},{unit:"year",step:100},{unit:"year",step:50},{unit:"year",step:20},{unit:"year",step:10},{unit:"year",step:5},{unit:"year",step:2},{unit:"year",step:1},{unit:"month",step:6},{unit:"month",step:3},{unit:"month",step:2},{unit:"month",step:1},{unit:"week",step:2},{unit:"week",step:1},{unit:"day",step:2},{unit:"day",step:1},{unit:"hour",step:12},{unit:"hour",step:6},{unit:"hour",step:3}],X=40,Ur=(e,t,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return $r(n.unit).range(e,new Date(t.valueOf()+1),r)},Yr=({unit:e,step:t,start:n,stop:r})=>{const a=cr.differenceInDays(r,n);switch(e){case"hour":return 24*a/t>X;case"day":return a/t>X;case"week":return a/(7*t)>X;case"month":return a/(30*t)>X;case"quarter":return a/(90*t)>X;case"year":return a/(365*t)>X}},Gr=(e,t)=>{const n=!an(t);switch(e.unit){case"year":return n?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return n?{type:"month_year"}:{type:"month"};case"week":return n?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return n?{type:"date"}:{type:"day_month"};case"hour":return n?{type:"datetime"}:{type:"time"}}},zr=(e,t)=>{const n=Wr(t);return n===null?!1:xt[e]>xt[n]},$r=e=>{switch(e){case"hour":return te.utcHour;case"day":return te.utcDay;case"week":return te.utcMonday;case"month":case"quarter":return te.utcMonth;case"year":return te.utcYear}},Wr=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}};function Ie(e,t){const n=U(t);for(const r of Hr(t,e)){const a=M(r.mapping[n]);if(m(a))return a}return null}const Je=(e,t)=>e===null?null:t.columns[e]?.label??e,sn=(e,t,n)=>{if(e!==null){const r=fr[e];if(r)return r;const a=t.columns[e]?.valueFormat;if(a&&jr(a,n))return a}return Kr(n)};function Hr(e,t){return e==="ySecondary"?t.filter(n=>n.yScaleType==="secondary"):e==="y"?t.filter(n=>n.yScaleType==="primary"):t}const Kr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},jr=(e,t)=>{switch(t){case"continuous":return nn(e);case"datetime":return de(e);case"discrete":case"palette":case"identity":return!0}},on={left:"right",right:"left",top:"bottom",bottom:"top"},qr={x:!0,y:!0,ySecondary:!1},Xr={bar:{cartesian:{hideGridX:!0},flip:{hideGridX:!0},polar:{hideGridX:!0,hideGridY:!0}}},Qr=20;function Jr(e,t){const{scales:n,config:r,layers:a,coordSystem:s,datasetMetadata:i}=e;if(s.type==="polar")return[];const o=ea(a,s.type,r),c=new Set(t.map(d=>d.position)),l=na(s.axisMapping.y.position,c),p=[];for(const d of Jt){const y=n[d];if(!m(y)||y.kind!=="position")continue;const f=Zr({scaleAestheticKey:d,scale:y,config:r,layers:a,axisMapping:s.axisMapping,resolvedYPosition:l,gridOverrides:o,datasetMetadata:i});p.push(f)}return p}function Zr(e){const{scaleAestheticKey:t,scale:n,config:r,layers:a,axisMapping:s,resolvedYPosition:i,gridOverrides:o,datasetMetadata:c}=e,l=U(t),{axisConfig:p,position:d}=ta(t,r,s,i),y=Ie(a,t),f=sn(y,c,n.spec.scaleType),h=Je(y,c);return{scaleAestheticKey:t,aesthetic:l,position:d,label:p.label??h,isVisible:p.isVisible,tickCandidates:aa(n,f),valueFormat:f,tickMode:p.ticks.mode,ticksVisible:p.ticks.isVisible,gridVisible:ra(p,o,t),scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function ea(e,t,n){const r=e.flatMap(o=>{const c=Xr[o.geom]?.[t];return c?[c]:[]}),a=r.some(o=>o.hideGridX),s=r.some(o=>o.hideGridY),i=r.some(o=>o.hideBorder);return{x:{gridVisible:Mt(a,n.axes.x.grid.isVisible)},y:{gridVisible:Mt(s,n.axes.y.grid.isVisible)},borderVisible:i?!1:void 0}}function Mt(e,t){if(e&&t===null)return!1}function ta(e,t,n,r){switch(e){case"x":return{axisConfig:t.axes[e],position:n[e].position};case"y":return{axisConfig:t.axes[e],position:r};case"ySecondary":{const a=on[r],s=ee.merge({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:s,position:s.position}}}}function na(e,t){return t.has(e)?on[e]:e}function ra(e,t,n){const{gridVisible:r}=n==="x"?t.x:t.y;return r??e.grid.isVisible??qr[n]}const aa=(e,t)=>{if(e.spec.scaleType==="continuous"){const r=new Set,a=[];for(let s=1;s<=Qr;s++){const i=e.generateTicks({count:s}),o=$(i);r.has(o)||(r.add(o),a.push({ticks:i.map(c=>Ee(e,c))}))}return a}return e.spec.scaleType==="datetime"?sa(e,t):[{ticks:e.generateTicks().map(r=>Ee(e,r))}]},sa=(e,t)=>{const[n,r]=e.domain;if(!Z(n)||!Z(r))return[{ticks:e.generateTicks().map(c=>Ee(e,c))}];const a=new Set,s=[],i=(o,c)=>{if(o.length===0)return;const l=$(o);a.has(l)||(a.add(l),s.push({ticks:o.map(p=>Ee(e,p)),valueFormat:c}))};for(const o of Br)Yr({...o,start:n,stop:r})||zr(o.unit,t)||i(e.generateTicks({interval:o}),Gr(o,t));return i(e.generateTicks({atInputs:!0})),s.sort((o,c)=>o.ticks.length-c.ticks.length),s},Ee=(e,t)=>({value:t,position:e.map(t)}),cn=e=>e[V.group];function ia(e){return e[u.x]}function je(e){return e[u.y]}function oa(e){return e[u.xMin]}function ca(e){return e[u.xMax]}function ln(e){return e[u.yMin]}function qe(e){return e[u.yMax]}const la={line:{stack:!0,dodge:!0,identity:!0,fill:!0},area:{stack:!0,dodge:!0,identity:!0,fill:!0},bar:{stack:!0,fill:!0}};function ua(e){const{scales:t,config:n,layers:r,coordSystem:a,datasetMetadata:s}=e;if(da(n))return[];const i=pa({scales:t,layers:r}),o=ya(i),c=xa(n.legend.position,r,a,i),l=Sa(n.legend.display,c,r,a),p=l==="direct"?va(r):null,d=Ie(r,"x"),y=Ie(r,"y");return o.map(f=>fa(f,d)?ga({group:f,position:c,display:l,yVariableName:y,datasetMetadata:s}):ha({group:f,position:c,display:l,endpointsBySeries:p,datasetMetadata:s})).filter(f=>!!(f&&f.items.length>0))}function da(e){return e.legend.position==="none"||e.headline.show!=="none"&&e.legend.position==="auto"}function pa(e){const{scales:t,layers:n}=e,r=[];for(const a of Zt){const s=t[a];if(s===void 0||s.kind==="identity"||!ma(a,n))continue;const i=Ie(n,a),o=wa(a,s);r.push({scaleAestheticKey:a,scale:s,variableName:i,guideType:o})}return r}function ma(e,t){const n=U(e);return t.some(r=>m(r.mapping[n]))}function fa(e,t){if(e.length>1)return!1;const[n]=e;return n.scaleAestheticKey!=="color"?!1:n.variableName===null||He(n.variableName)?!0:t!==null&&n.variableName===t}function ya(e){const t=new Map;for(const n of e){const r=Aa(n),a=t.get(r);a?a.push(n):t.set(r,[n])}return[...t.values()]}function ha({group:e,position:t,display:n,endpointsBySeries:r,datasetMetadata:a}){const s=e[0],i=e.find(l=>m(l.variableName))?.variableName??null,o=Je(i,a),c=sn(s.variableName,a,s.scale.spec.scaleType);return{aesthetics:e.map(l=>l.scaleAestheticKey),title:o,position:t,display:n,items:s.scale.domain.map(l=>{const p={};for(const d of e)p[d.scaleAestheticKey]=d.scale.map(l);return{value:l,visual:p,normalizedY:r?.get(l)??null}}),valueFormat:c}}function ga({yVariableName:e,group:t,position:n,display:r,datasetMetadata:a}){const s=ba(t,e,a);if(s===null)return null;const i={};for(const o of t){const c=o.scale.domain.map(l=>String(o.scale.map(l)));i[o.scaleAestheticKey]=c.length===1?c[0]:c}return{aesthetics:t.map(o=>o.scaleAestheticKey),title:s,position:n,display:r,items:[{value:s,visual:i,normalizedY:null}],valueFormat:{type:"text"}}}function ba(e,t,n){const r=e.find(a=>a.scaleAestheticKey==="color");if(m(r?.variableName)&&He(r.variableName)){const[a]=r.scale.domain;if(m(a))return String(a)}return!t||He(t)?null:Je(t,n)}function xa(e,t,n,r){if(e!=="auto")return e;const a=t.some(c=>c.geom==="line"||c.geom==="area"),s=t.some(c=>c.geom==="bar"&&(c.position==="stack"||c.position==="fill")),i=n.type==="polar",o=Math.max(0,...r.map(c=>c.scale.domain.length));return i?"top":(a||s)&&o>=3?"right":"top"}function Ma(e){if(e.length!==1)return!1;const t=e[0];return t?la[t.geom]?.[t.position]===!0:!1}function Sa(e,t,n,r){const a=t==="right"&&!Ta(r);return e==="pill"||!a?"pill":e==="direct"||Ma(n)?"direct":"pill"}function Ta(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Aa(e){const t=e.scale.domain.map($);return JSON.stringify([e.variableName,e.guideType,...t])}function wa(e,t){const n=t.spec.scaleType;return n==="continuous"||n==="datetime"?`continuous:${e}`:"discrete"}function va(e){const t=e[0];if(!t)return new Map;const n=new Map;return t.data.groupBy(V.group).forEach(r=>{const a=r.findLast(l=>m(qe(l))||m(je(l)));if(!a)return;const s=cn(a);if(!m(s))return;const i=ln(a),o=qe(a)??je(a);if(!m(o))return;const c=m(i)?(i+o)/2:o;n.set(String(s),c)}),n}class Va{compile(t){const n=ua(t);return{axes:Jr(t,n),legends:n,panel:{border:{isVisible:t.config.panel.border.isVisible}}}}}class un extends Error{constructor(t){const n=t.map(r=>`- ${r.message}`).join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("lodash-es"),T=require("date-fns"),ne=require("d3-time"),pr=require("date-fns/differenceInDays"),U=require("d3-scale"),P=require("arquero"),Ht=require("lodash-es/merge"),mr=require("humanize-duration"),yr=require("d3-delaunay");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-alpha.5");const jt=e=>e.length>0;function m(e){return e!=null}const qt=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],Xt="default";class j{constructor(t){this.label=t,this.items=new Map}register(t,n){return this.items.set(t,n),this}get(t){if(!this.items.has(t)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new Error(`Unknown ${this.label}: '${t}' (available: ${n})`)}return this.items.get(t)}getAll(){return[...this.items.values()]}has(t){return this.items.has(t)}}class fr extends j{constructor(){super("palette")}}function de(e){return{pipe:t=>{const n=t(e);return de({...e,...n})},result:()=>e}}class hr{constructor(t){this.registry=t}setup(t){return this.registry.get(t.coordSpec.coordType).setup(t)}transform(t){return this.registry.get(t.coordSpec.coordType).transform(t)}}class gr{constructor(){this.coordType="cartesian"}setup(t){if(t.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}}}transform(t){return t.layers}}const Qt="\0graphy\0_",A=e=>`${Qt}${e}`,je=e=>e.startsWith(Qt),Se={x:A("constantX")},qe={count:A("count")},br={[qe.count]:{type:"integer"}},v={group:A("group")},u={x:A("x"),y:A("y"),xMin:A("xMin"),xMax:A("xMax"),yMin:A("yMin"),yMax:A("yMax")},G={color:A("color"),size:A("size"),alpha:A("alpha"),strokeWidth:A("strokeWidth"),lineType:A("lineType")};({...v,...u,...G});class xr{constructor(){this.coordType="flip"}setup(t){if(t.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}}}transform(t){return t.layers.map(n=>Sr(n))}}const Mr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]],St=A("flipSwap");function Sr(e){let t=e.data;for(const[n,r]of Mr){const a=t.hasVariable(n),s=t.hasVariable(r);a&&s?t=t.renameVariable(n,St).renameVariable(r,n).renameVariable(St,r):a?t=t.renameVariable(n,r):s&&(t=t.renameVariable(r,n))}return{...e,data:t}}class Tr{constructor(){this.coordType="polar"}setup(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec;return{type:"polar",axisMapping:n.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}}}}transform(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec,r=Ar(n),a=wr(n);return t.layers.map(s=>{const i=n.theta==="y"?Ir(s):s;return Vr(i,r,a)})}}function Ar(e){const t=e.startAngle*(Math.PI/180);return n=>n*2*Math.PI+t}function wr(e){const{innerRadius:t}=e;return n=>t+n*(1-t)}function Vr(e,t,n){let r=e.data;return r=q(r,u.x,t),r=q(r,u.xMin,t),r=q(r,u.xMax,t),r=q(r,u.y,n),r=q(r,u.yMin,n),r=q(r,u.yMax,n),{...e,data:r}}function q(e,t,n){if(!e.hasVariable(t))return e;const a=e.getValues(t,{type:"numeric"}).map(s=>s===null?null:n(s));return e.addVariable(t,"numeric",a)}const vr=[[u.x,u.y],[u.xMin,u.yMin],[u.xMax,u.yMax]];function Ir(e){let t=e.data;for(const[n,r]of vr){const a=t.hasVariable(n),s=t.hasVariable(r);if(!a&&!s)continue;const i=a?t.getValues(n):null,o=s?t.getValues(r):null;i&&(t=t.addVariable(r,"numeric",i)),o&&(t=t.addVariable(n,"numeric",o))}return{...e,data:t}}class Er extends j{constructor(){super("coord"),this.register("cartesian",new gr),this.register("flip",new xr),this.register("polar",new Tr)}}class Lr{constructor(t){this.registry=t}compile(t,n){return this.registry.get(t).compile(n)}}function _r(e){return{type:"mapping",mapping:e}}function S(e){return m(e)?typeof e=="string"?e:"variable"in e?e.variable:null:null}function kr(e){if(!(!m(e)||typeof e=="string")&&"value"in e)return e.value}const Jt=(e,t)=>{if(m(t.group)){const a=S(t.group);if(a!==null)return[a]}const n=new Set([S(t.x),S(t.y)].filter(m)),r=new Set;for(const a in t){if(a==="x"||a==="y")continue;const s=S(t[a]);m(s)&&(n.has(s)||e.getType(s)==="categorical"&&r.add(s))}return[...r]};class De{constructor(){this.requiredAesthetics=[]}}const Zt=(e,t)=>{const n=S(t.x);return!n||!["numeric","temporal"].includes(e.getType(n))?e:e.orderBy(n,"asc")};class Dr extends De{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"]}compile({data:t,mapping:n}){if(t=Zt(t,n),t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const r=S(n.y);m(r)&&t.hasVariable(r)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(r,{type:"numeric"})))}return{data:t,mapping:{}}}}const en=.7,Cr=.1;class Rr extends De{constructor(){super(...arguments),this.type="bar"}compile({data:t,mapping:n}){if(t.hasVariable(u.yMin)||(t=t.addConstantVariable(u.yMin,"numeric",0)),!t.hasVariable(u.yMax)){const a=S(n.y);m(a)&&t.hasVariable(a)&&(t=t.addVariable(u.yMax,"numeric",t.getValues(a,{type:"numeric"})))}const r=en/2;return t=t.addConstantVariable(u.xMin,"numeric",-r).addConstantVariable(u.xMax,"numeric",r),{data:t,mapping:{}}}}class Nr extends De{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"]}compile(t){return{data:Zt(t.data,t.mapping),mapping:{}}}}class Fr extends De{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"]}compile({data:t}){return{data:t,mapping:{}}}}class Or extends j{constructor(){super("geom"),this.register("bar",new Rr),this.register("point",new Fr),this.register("line",new Nr),this.register("area",new Dr)}}const W=e=>(Array.isArray(e)?e:[e]).map(n=>n instanceof Date?n.toISOString():String(n??"<null>")).join("\0");class Pr{compute({data:t,mapping:n}){const r=Jt(t,n);if(r.length===0)return{data:t.addConstantVariable(v.group,"categorical",null)};const a=t.size(),s=r.map(o=>t.getValues(o)),i=new Array(a);for(let o=0;o<a;o++)i[o]=W(s.map(c=>c[o]));return{data:t.addVariable(v.group,"categorical",i)}}}const tn=new Set(["x","y","ySecondary"]),nn=new Set(["color","size","alpha","strokeWidth","lineType"]),Ce=e=>tn.has(e),Br=e=>nn.has(e),Ur=e=>Ce(e)||Br(e);function pe(e){return e==="secondary"?"ySecondary":"y"}function F(e){return e==="ySecondary"?"y":e}const Z=e=>e instanceof Date&&T.isValid(e),rn=e=>typeof e=="string",an=e=>typeof e=="number"&&!Number.isNaN(e),Yr=e=>e.type==="text",me=e=>e.type==="date"||e.type==="datetime"||e.type==="year"||e.type==="month_year"||e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range"||e.type==="weekly_date_range_with_year"||e.type==="quarter"||e.type==="time",sn=e=>e.type==="decimal"||e.type==="integer"||e.type==="percentage"||e.type==="duration"||e.type==="currency",on=e=>e.type==="currency",cn=e=>e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range",Gr=e=>{if(me(e))return"temporal";if(sn(e))return"numeric";if(Yr(e))return"categorical";const t=e;throw new Error(`No data type found for value format: ${t.type}`)},Tt={year:0,quarter:1,month:2,week:3,day:4,hour:5},zr=[{unit:"year",step:1e3},{unit:"year",step:100},{unit:"year",step:50},{unit:"year",step:20},{unit:"year",step:10},{unit:"year",step:5},{unit:"year",step:2},{unit:"year",step:1},{unit:"month",step:6},{unit:"month",step:3},{unit:"month",step:2},{unit:"month",step:1},{unit:"week",step:2},{unit:"week",step:1},{unit:"day",step:2},{unit:"day",step:1},{unit:"hour",step:12},{unit:"hour",step:6},{unit:"hour",step:3}],X=40,$r=(e,t,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return jr(n.unit).range(e,new Date(t.valueOf()+1),r)},Wr=({unit:e,step:t,start:n,stop:r})=>{const a=pr.differenceInDays(r,n);switch(e){case"hour":return 24*a/t>X;case"day":return a/t>X;case"week":return a/(7*t)>X;case"month":return a/(30*t)>X;case"quarter":return a/(90*t)>X;case"year":return a/(365*t)>X}},Kr=(e,t)=>{const n=!cn(t);switch(e.unit){case"year":return n?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return n?{type:"month_year"}:{type:"month"};case"week":return n?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return n?{type:"date"}:{type:"day_month"};case"hour":return n?{type:"datetime"}:{type:"time"}}},Hr=(e,t)=>{const n=qr(t);return n===null?!1:Tt[e]>Tt[n]},jr=e=>{switch(e){case"hour":return ne.utcHour;case"day":return ne.utcDay;case"week":return ne.utcMonday;case"month":case"quarter":return ne.utcMonth;case"year":return ne.utcYear}},qr=e=>{switch(e.type){case"year":return"year";case"quarter":return"quarter";case"month_year":case"month":return"month";case"weekly_date_range":case"weekly_date_range_with_year":return"week";case"date":case"day_month":case"datetime":return"day";case"time":return"hour";default:return null}};function Le(e,t){const n=F(t);for(const r of Xr(t,e)){const a=S(r.mapping[n]);if(m(a))return a}return null}const tt=(e,t)=>e===null?null:t.columns[e]?.label??e,ln=(e,t,n)=>{if(e!==null){const r=br[e];if(r)return r;const a=t.columns[e]?.valueFormat;if(a&&Jr(a,n))return a}return Qr(n)};function Xr(e,t){return e==="ySecondary"?t.filter(n=>n.yScaleType==="secondary"):e==="y"?t.filter(n=>n.yScaleType==="primary"):t}const Qr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Jr=(e,t)=>{switch(t){case"continuous":return sn(e);case"datetime":return me(e);case"discrete":case"palette":case"identity":return!0}},un={left:"right",right:"left",top:"bottom",bottom:"top"},Zr={x:!0,y:!0,ySecondary:!1},ea={bar:{cartesian:{hideGridX:!0},flip:{hideGridX:!0},polar:{hideGridX:!0,hideGridY:!0}}},ta=20;function na(e,t){const{scales:n,config:r,layers:a,coordSystem:s,datasetMetadata:i}=e;if(s.type==="polar")return[];const o=aa(a,s.type,r),c=new Set(t.map(p=>p.position)),l=ia(s.axisMapping.y.position,c),d=[];for(const p of tn){const f=n[p];if(!m(f)||f.kind!=="position")continue;const y=ra({scaleAestheticKey:p,scale:f,config:r,layers:a,axisMapping:s.axisMapping,resolvedYPosition:l,gridOverrides:o,datasetMetadata:i});d.push(y)}return d}function ra(e){const{scaleAestheticKey:t,scale:n,config:r,layers:a,axisMapping:s,resolvedYPosition:i,gridOverrides:o,datasetMetadata:c}=e,l=F(t),{axisConfig:d,position:p}=sa(t,r,s,i),f=Le(a,t),y=ln(f,c,n.spec.scaleType),g=tt(f,c);return{scaleAestheticKey:t,aesthetic:l,position:p,label:d.label??g,isVisible:d.isVisible,tickCandidates:ca(n,y),valueFormat:y,tickMode:d.ticks.mode,ticksVisible:d.ticks.isVisible,gridVisible:oa(d,o,t),scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function aa(e,t,n){const r=e.flatMap(o=>{const c=ea[o.geom]?.[t];return c?[c]:[]}),a=r.some(o=>o.hideGridX),s=r.some(o=>o.hideGridY),i=r.some(o=>o.hideBorder);return{x:{gridVisible:At(a,n.axes.x.grid.isVisible)},y:{gridVisible:At(s,n.axes.y.grid.isVisible)},borderVisible:i?!1:void 0}}function At(e,t){if(e&&t===null)return!1}function sa(e,t,n,r){switch(e){case"x":return{axisConfig:t.axes[e],position:n[e].position};case"y":return{axisConfig:t.axes[e],position:r};case"ySecondary":{const a=un[r],s=ee.merge({isVisible:t.axes.y.isVisible,label:null,position:a,grid:t.axes.y.grid,ticks:t.axes.y.ticks},t.axes.ySecondary);return{axisConfig:s,position:s.position}}}}function ia(e,t){return t.has(e)?un[e]:e}function oa(e,t,n){const{gridVisible:r}=n==="x"?t.x:t.y;return r??e.grid.isVisible??Zr[n]}const ca=(e,t)=>{if(e.spec.scaleType==="continuous"){const r=new Set,a=[];for(let s=1;s<=ta;s++){const i=e.generateTicks({count:s}),o=W(i);r.has(o)||(r.add(o),a.push({ticks:i.map(c=>_e(e,c))}))}return a}return e.spec.scaleType==="datetime"?la(e,t):[{ticks:e.generateTicks().map(r=>_e(e,r))}]},la=(e,t)=>{const[n,r]=e.domain;if(!Z(n)||!Z(r))return[{ticks:e.generateTicks().map(c=>_e(e,c))}];const a=new Set,s=[],i=(o,c)=>{if(o.length===0)return;const l=W(o);a.has(l)||(a.add(l),s.push({ticks:o.map(d=>_e(e,d)),valueFormat:c}))};for(const o of zr)Wr({...o,start:n,stop:r})||Hr(o.unit,t)||i(e.generateTicks({interval:o}),Kr(o,t));return i(e.generateTicks({atInputs:!0})),s.sort((o,c)=>o.ticks.length-c.ticks.length),s},_e=(e,t)=>({value:t,position:e.map(t)});function dn(e,t){switch(e){case"bar":return t.type==="polar"?"slice":"square";case"line":return"line";case"area":return"area";case"point":return"circle";default:return"square"}}const pn=e=>e[v.group];function ua(e){return e[u.x]}function Xe(e){return e[u.y]}function da(e){return e[u.xMin]}function pa(e){return e[u.xMax]}function mn(e){return e[u.yMin]}function Qe(e){return e[u.yMax]}const ma={line:{stack:!0,dodge:!0,identity:!0,fill:!0},area:{stack:!0,dodge:!0,identity:!0,fill:!0},bar:{stack:!0,fill:!0}};function ya(e){const{scales:t,config:n,layers:r,coordSystem:a,datasetMetadata:s}=e;if(ha(n))return[];const i=ga({scales:t,layers:r}),o=Ma(i),c=wa(n.legend.position,r,a,i),l=va(n.legend.display,c,r,a),d=l==="direct"?_a(r):null,p=Le(r,"x"),f=Le(r,"y");return o.map(y=>{const g=fa(y,r,a);return xa(y,p)?Ta({group:y,position:c,display:l,yVariableName:f,datasetMetadata:s,swatchShape:g}):Sa({group:y,position:c,display:l,endpointsBySeries:d,datasetMetadata:s,swatchShape:g})}).filter(y=>!!(y&&y.items.length>0))}function fa(e,t,n){const r=e.map(s=>F(s.scaleAestheticKey)),a=t.find(s=>r.some(i=>m(s.mapping[i])))??t[0];return a?dn(a.geom,n):"square"}function ha(e){return e.legend.position==="none"||e.headline.show!=="none"&&e.legend.position==="auto"}function ga(e){const{scales:t,layers:n}=e,r=[];for(const a of nn){const s=t[a];if(s===void 0||s.kind==="identity"||!ba(a,n))continue;const i=Le(n,a),o=La(a,s);r.push({scaleAestheticKey:a,scale:s,variableName:i,guideType:o})}return r}function ba(e,t){const n=F(e);return t.some(r=>m(r.mapping[n]))}function xa(e,t){if(e.length>1)return!1;const[n]=e;return n.scaleAestheticKey!=="color"?!1:n.variableName===null||je(n.variableName)?!0:t!==null&&n.variableName===t}function Ma(e){const t=new Map;for(const n of e){const r=Ea(n),a=t.get(r);a?a.push(n):t.set(r,[n])}return[...t.values()]}function Je(e,t,n){if(t==="lineType"){e.lineType=(Array.isArray(n),n);return}if(t==="color"){e.color=Array.isArray(n)?n.map(String):String(n);return}e[t]=n}function Sa({group:e,position:t,display:n,endpointsBySeries:r,datasetMetadata:a,swatchShape:s}){const i=e[0],o=e.find(d=>m(d.variableName))?.variableName??null,c=tt(o,a),l=ln(i.variableName,a,i.scale.spec.scaleType);return{aesthetics:e.map(d=>d.scaleAestheticKey),title:c,position:t,display:n,items:i.scale.domain.map(d=>{const p={};for(const f of e)Je(p,f.scaleAestheticKey,f.scale.map(d));return{value:d,visual:p,normalizedY:r?.get(d)??null}}),valueFormat:l,swatchShape:s}}function Ta({yVariableName:e,group:t,position:n,display:r,datasetMetadata:a,swatchShape:s}){const i=Aa(t,e,a);if(i===null)return null;const o={};for(const c of t){const l=c.scale.domain.map(d=>c.scale.map(d));l.length===1&&l[0]!==void 0?Je(o,c.scaleAestheticKey,l[0]):Je(o,c.scaleAestheticKey,l)}return{aesthetics:t.map(c=>c.scaleAestheticKey),title:i,position:n,display:r,items:[{value:i,visual:o,normalizedY:null}],valueFormat:{type:"text"},swatchShape:s}}function Aa(e,t,n){const r=e.find(a=>a.scaleAestheticKey==="color");if(m(r?.variableName)&&je(r.variableName)){const[a]=r.scale.domain;if(m(a))return String(a)}return!t||je(t)?null:tt(t,n)}function wa(e,t,n,r){if(e!=="auto")return e;const a=t.some(c=>c.geom==="line"||c.geom==="area"),s=t.some(c=>c.geom==="bar"&&(c.position==="stack"||c.position==="fill")),i=n.type==="polar",o=Math.max(0,...r.map(c=>c.scale.domain.length));return i?"top":(a||s)&&o>=3?"right":"top"}function Va(e){if(e.length!==1)return!1;const t=e[0];return t?ma[t.geom]?.[t.position]===!0:!1}function va(e,t,n,r){const a=t==="right"&&!Ia(r);return e==="pill"||!a?"pill":e==="direct"||Va(n)?"direct":"pill"}function Ia(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Ea(e){const t=e.scale.domain.map(W);return JSON.stringify([e.variableName,e.guideType,...t])}function La(e,t){const n=t.spec.scaleType;return n==="continuous"||n==="datetime"?`continuous:${e}`:"discrete"}function _a(e){const t=e[0];if(!t)return new Map;const n=new Map;return t.data.groupBy(v.group).forEach(r=>{const a=r.findLast(l=>m(Qe(l))||m(Xe(l)));if(!a)return;const s=pn(a);if(!m(s))return;const i=mn(a),o=Qe(a)??Xe(a);if(!m(o))return;const c=m(i)?(i+o)/2:o;n.set(String(s),c)}),n}class ka{compile(t){const n=ya(t);return{axes:na(t,n),legends:n,panel:{border:{isVisible:t.config.panel.border.isVisible}}}}}class yn extends Error{constructor(t){const n=t.map(r=>`- ${r.message}`).join(`
|
|
2
2
|
`);super(`Spec validation failed:
|
|
3
|
-
${n}`),this.issues=t,this.name="SpecValidationError"}}class Ia{constructor(t,n,r,a,s,i){this.transformCompiler=t,this.statCompiler=n,this.groupCompiler=r,this.geomCompiler=a,this.positionAdjusterCompiler=s,this.layerValidator=i}compile(t){const n=this.prepareLayers(t);return this.validateLayers(n),n.map(({layer:r,data:a,effectiveMapping:s})=>this.compileLayer(r,a,s))}prepareLayers(t){return t.layers.map(n=>({layer:n,data:this.transformCompiler.compile(t.data,n.transforms),effectiveMapping:{...t.mapping,...n.mapping}}))}validateLayers(t){const n=[];for(const{layer:r,data:a,effectiveMapping:s}of t)n.push(...this.layerValidator.validate({layerId:r.id,geom:r.geom,stat:r.stat,effectiveMapping:s,data:a}));if(n.length>0)throw new un(n)}compileLayer(t,n,r){return{...le({data:n,mapping:r}).pipe(({data:s,mapping:i})=>{const o=this.statCompiler.compute(t.stat,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>({data:this.groupCompiler.compute({data:s,mapping:i}).data,mapping:i})).pipe(({data:s,mapping:i})=>{const o=this.geomCompiler.compile(t.geom,{data:s,mapping:i,params:t.params});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>{const o=this.positionAdjusterCompiler.adjust(t.position,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).result(),id:t.id,geom:t.geom,position:t.position,yScaleType:t.yScaleType,params:t.params,interactive:t.interactive}}}class Ea{constructor(t,n){this.geomRegistry=t,this.statRegistry=n}validate(t){return[...this.validateRequiredAesthetics(t),...this.validateVariableExistence(t)]}validateRequiredAesthetics({layerId:t,geom:n,stat:r,effectiveMapping:a}){const s=[],{requiredAesthetics:i}=this.geomRegistry.get(n),{computedVariables:o}=this.statRegistry.get(r);for(const c of i)o.has(c)||m(a[c])||s.push({code:"MISSING_AESTHETIC",message:`Layer '${t}': geom '${n}' requires aesthetic '${c}'`,layerId:t,aesthetic:c});return s}validateVariableExistence({layerId:t,stat:n,effectiveMapping:r,data:a}){const s=[],{computedVariables:i}=this.statRegistry.get(n);for(const[o,c]of Object.entries(r)){if(i.has(o))continue;const l=M(c);l!==null&&(a.hasVariable(l)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${t}': aesthetic '${o}' references variable '${l}' which does not exist in the dataset`,layerId:t,aesthetic:o}))}return s}}class _a{constructor(t){this.registry=t}adjust(t,n){return this.registry.get(t).adjust(n)}}class De{}class La extends De{constructor(){super(...arguments),this.type="dodge"}adjust({data:t,mapping:n}){if(!M(n.x))return{data:t,mapping:{}};const a=t.getValues(V.group,{type:"categorical",distinct:!0,skipNulls:!0});if(a.length===0)return{data:t,mapping:{}};const s=t.size(),i=t.getValues(V.group,{type:"categorical"}),o=Qt/2,c=a.length>1?_r:0,l=B.scaleBand().domain(a.map(String)).range([-o,o]).paddingInner(c).paddingOuter(0),p=l.bandwidth(),d=new Array(s).fill(null),y=new Array(s).fill(null);for(let h=0;h<s;h++){const b=i[h];if(!m(b))continue;const g=l(String(b));m(g)&&(d[h]=g,y[h]=g+p)}return{data:t.addVariable(u.xMin,"numeric",d).addVariable(u.xMax,"numeric",y),mapping:{}}}}const St=A("__ungrouped__"),dn=(e,t)=>{const n=M(t.x),r=M(t.y);if(!n||!r)return null;const a=e.getValues(V.group,{type:"categorical",distinct:!0,skipNulls:!0}),s=a.length===0,i=s?[St]:a,o=e.getValues(n),c=e.getValues(r,{type:"numeric"}),l=e.getValues(V.group,{type:"categorical"}),p=e.size(),d=new Map;for(let y=0;y<p;y++){const f=o[y]??null,h=l[y],b=s?St:h;if(!m(b))continue;let g=d.get(f);g||(g=new Map,d.set(f,g)),g.set(b,y)}return{yValues:c,observationIndexByXAndGroup:d,uniqueGroupKeys:i,observationCount:p}};class ka extends De{constructor(){super(...arguments),this.type="fill"}adjust({data:t,mapping:n}){const r=dn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,d]of s){let y=0,f=0;for(const g of i){const x=d.get(g);if(x===void 0)continue;const S=a[x];S!=null&&(S>=0?y+=S:f-=S)}let h=0,b=0;for(const g of i){const x=d.get(g);if(x===void 0)continue;const S=a[x];if(S===void 0)continue;if(S===null){l[x]=null,c[x]=null;continue}const k=S>=0?y:f;if(k===0){l[x]=0,c[x]=0;continue}const D=S/k;S>=0?(l[x]=h,c[x]=h+=D):(c[x]=b,l[x]=b+=D)}}return{data:t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c),mapping:{}}}}class Da extends De{constructor(){super(...arguments),this.type="identity"}adjust({data:t}){return{data:t,mapping:{}}}}class Ca extends De{constructor(){super(...arguments),this.type="stack"}adjust({data:t,mapping:n}){const r=dn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,y]of s){let f=0,h=0;for(const b of i){const g=y.get(b);if(g===void 0)continue;const x=a[g];if(x!==void 0){if(x===null){l[g]=null,c[g]=null;continue}x>=0?(l[g]=f,c[g]=f+=x):(c[g]=h,l[g]=h+=x)}}}let p=t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c);const d=M(n.y);return d!==null&&(p=p.addVariable(d,"numeric",c)),{data:p,mapping:{}}}}class Ra extends K{constructor(){super("position"),this.register("identity",new Da),this.register("stack",new Ca),this.register("fill",new ka),this.register("dodge",new La)}}class Na{map({data:t,layer:n,getPositionScale:r}){const a=M(n.mapping.x),s=r("x");if(!a||!s)return t;const o=t.getValues(a).map(c=>m(c)?s.map(c):null);return t.addVariable(u.x,"numeric",o)}}class Fa{map({data:t,getPositionScale:n}){const r=n("x");if(!r?.bandwidth||!t.hasVariable(u.x)||!t.hasVariable(u.xMin)||!t.hasVariable(u.xMax))return t;const a=t.getValues(u.x,{type:"numeric"}),s=t.getValues(u.xMin,{type:"numeric"}),i=t.getValues(u.xMax,{type:"numeric"}),o=t.size(),c=new Array(o),l=new Array(o);for(let p=0;p<o;p++){const d=a[p],y=s[p],f=i[p];m(d)&&m(y)&&m(f)?(c[p]=d+y*r.bandwidth,l[p]=d+f*r.bandwidth):(c[p]=null,l[p]=null)}return t.addVariable(u.xMin,"numeric",c).addVariable(u.xMax,"numeric",l)}}class Oa{map({data:t,layer:n,getPositionScale:r}){const a=M(n.mapping.y),s=ue(n.yScaleType),i=r(s);if(!a||!i)return t;const c=t.getValues(a).map(l=>m(l)?i.map(l):null);return t.addVariable(u.y,"numeric",c)}}class Pa{map({data:t,layer:n,getPositionScale:r}){const a=ue(n.yScaleType),s=r(a);if(!s||!t.hasVariable(u.yMin)||!t.hasVariable(u.yMax))return t;const i=t.getValues(u.yMin,{type:"numeric"}),o=t.getValues(u.yMax,{type:"numeric"}),c=t.size(),l=new Array(c),p=new Array(c);for(let d=0;d<c;d++){const y=i[d],f=o[d];m(y)&&m(f)?(l[d]=s.map(y),p[d]=s.map(f)):(l[d]=null,p[d]=null)}return t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",p)}}const Ba=[new Na,new Oa,new Fa,new Pa];function Ua(e,t){const n=e[t];return n?.kind==="position"?n:null}class Ya{constructor(t=Ba){this.mappers=t}compile(t){const n=r=>Ua(t.scales,r);return t.layers.map(r=>this.compileLayer(r,n))}compileLayer(t,n){let r=t.data;for(const a of this.mappers)r=a.map({data:r,layer:t,getPositionScale:n});return{...t,data:r}}}class Ga{constructor(t){this.registry=t}compile(t){this.validateScaleTypeCompatibility(t);const n=new Map;for(const s of t.scales)n.set(s.scaledAesthetic,s);const r=this.collectValues(t.layers,n),a={};for(const[s,i]of n){const o=r.get(s)??[],c=this.registry.get(i.scaleType);a[s]=c.compile(i,o)}return a}validateScaleTypeCompatibility(t){const n=[];for(const r of t.scales){const{compatibleDataTypes:a}=this.registry.get(r.scaleType),s=U(r.scaledAesthetic),i=t.layers.find(l=>m(l.mapping[s]));if(!i)continue;const o=M(i.mapping[s]);if(!m(o)||!i.data.hasVariable(o))continue;const c=i.data.getType(o);a.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${c})`,aesthetic:s})}if(n.length>0)throw new un(n)}collectValues(t,n){const r=new Map;for(const a of t)for(const[s,i]of Object.entries(a.mapping)){const o=s,c=o==="y"?ue(a.yScaleType):o;if(!Fr(c)||!n.has(c))continue;const l=this.resolveVariables(o,i,a.data);this.collectFromVariables(a.data,l,c,r)}return r}resolveVariables(t,n,r){if(t==="y"&&this.hasPositionAdjustedY(r))return[u.yMin,u.yMax];const a=M(n);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(t){return t.hasVariable(u.yMin)&&t.hasVariable(u.yMax)}collectFromVariables(t,n,r,a){if(n.length===0)return;let s=[];for(const o of n)s=s.concat(t.getValues(o));const i=a.get(r);a.set(r,i?i.concat(s):s)}}class pe{createPositionScale(t,n){return{kind:"position",aesthetic:U(t.scaledAesthetic),spec:t,...n}}createVisualScale(t,n){return{kind:"visual",aesthetic:U(t.scaledAesthetic),spec:t,...n}}}class za extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(t,n){if(t.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){let r=1/0,a=-1/0;for(const s of t)typeof s=="number"&&(s<r&&(r=s),s>a&&(a=s));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),a<0&&(a=0)),[r,a])}createD3Scale(t,n,r){let a=[r.domainMin??t[0],r.domainMax??t[1]];const s=r.transform==="log"&&$a(a),i=s?B.scaleLog():r.transform==="sqrt"?B.scaleSqrt():B.scaleLinear();return r.nice&&!s&&(a=i.copy().domain(a).nice().domain()),i.domain([r.domainMin??a[0],r.domainMax??a[1]]).range(n).clamp(r.clamp)}buildPositionScale(t,n){const r=n.reverse?[1,0]:[0,1],a=this.createD3Scale(t,r,n);return this.createPositionScale(n,{map:a,domain:a.domain(),bandwidth:null,generateTicks:s=>s&&"count"in s?a.ticks(s.count):a.ticks()})}buildVisualScale(t,n){const r=n.range??[0,1],a=n.reverse?[r[1],r[0]]:r,s=this.createD3Scale(t,a,n);return this.createVisualScale(n,{map:s,domain:s.domain(),generateTicks:i=>i&&"count"in i?s.ticks(i.count):s.ticks()})}}const $a=e=>{const[t,n]=e;return t>0&&n>0||t<0&&n<0};class Wa extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(t,n){if(t.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n);if(!r)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(a,t,this.collectInputDates(n))}collectInputDates(t){const n=new Set,r=[];for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();n.has(s)||(n.add(s),r.push(a))}return r.sort((a,s)=>a.getTime()-s.getTime()),r}computeDataDomain(t){let n=1/0,r=-1/0;for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();s<n&&(n=s),s>r&&(r=s)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(t,n,r){const a=Ha(t)?t:[],s=B.scaleUtc().domain(a).range(n).clamp(r.clamp);if(r.nice&&s.nice(),m(r.domainMin)||m(r.domainMax)){const[i,o]=s.domain();i!==void 0&&o!==void 0&&s.domain([r.domainMin??i,r.domainMax??o])}return s}buildScale(t,n,r){const a=n.reverse?[1,0]:[0,1],s=this.createD3Scale(t,a,n),[i,o]=s.domain(),c=i&&o?r.filter(l=>l>=i&&l<=o):[];return this.createPositionScale(n,{map:s,domain:s.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&o?Ur(i,o,l.interval):[]:s.ticks(l?.count)})}}const Ha=e=>e.length===2&&Z(e[0])&&Z(e[1]),Q={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},Tt={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},xe={domainMin:null,domainMax:null,nice:!1,reverse:!1},re={range:null,sort:"none",domain:null,padding:.1},Ka={palette:"default"};class ja extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(t,n){if(t.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const r=ke(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){if(n.domain!==null&&n.domain.length>0)return[...n.domain];const r=new Set,a=[];for(const s of t)r.has(s)||(r.add(s),a.push(s));return n.sort==="ascending"?a.sort((s,i)=>String(s).localeCompare(String(i))):n.sort==="descending"&&a.sort((s,i)=>String(i).localeCompare(String(s))),a}buildPositionScale(t,n){const r=t.map(String),a=n.padding??re.padding,s=B.scaleBand().domain(r).range([0,1]).paddingInner(a).paddingOuter(a/2),i=s.bandwidth()/2;return this.createPositionScale(n,{map:o=>(s(String(o))??0)+i,domain:t,bandwidth:s.bandwidth(),generateTicks:()=>[...t]})}buildVisualScale(t,n){const r=t.map(String),a=n.range&&n.range.length>0?B.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:s=>{const i=String(s);return a?a(i):i},domain:t,generateTicks:()=>t})}}class qa extends pe{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(t){if(t.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:U(t.scaledAesthetic),spec:t,map:n=>n,domain:[],generateTicks:()=>[]}}}class Xa extends pe{constructor(t){super(),this.paletteRegistry=t,this.compatibleDataTypes=["categorical","temporal"]}compile(t,n){if(t.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const r=this.computeDomain(n),a=this.paletteRegistry.get(t.palette),s=B.scaleOrdinal().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(t,{map:i=>s(String(i)),domain:r,generateTicks:()=>r})}computeDomain(t){const n=new Set,r=[];for(const a of t)n.has(a)||(n.add(a),r.push(a));return r}}class Qa extends K{constructor(t){super("scale"),this.paletteRegistry=t,this.register("continuous",new za),this.register("discrete",new ja),this.register("datetime",new Wa),this.register("identity",new qa),this.register("palette",new Xa(this.paletteRegistry))}}const Ja=new Set(["count","sum","mean","median"]);function pn(e,t){return Ja.has(e)?"numeric":t}const Za="key",es="value",ts={eq:(e,t)=>e[t.__variableName]===t.__value,neq:(e,t)=>e[t.__variableName]!==t.__value,gt:(e,t)=>e[t.__variableName]>t.__value,gte:(e,t)=>e[t.__variableName]>=t.__value,lt:(e,t)=>e[t.__variableName]<t.__value,lte:(e,t)=>e[t.__variableName]<=t.__value};class w{constructor(t={}){const{table:n,variableMetadata:r}=this.parseVariableMap(t);this.table=n,this.variableMetadata=r}static merge(...t){if(t.length===0)return w.fromTrusted(F.table({}),{});const n=t.map(o=>o.table),[r,...a]=n,s=a.reduce((o,c)=>o.concat(c),r),i=t.reduce((o,c)=>({...o,...c.variableMetadata}),{});return w.fromTrusted(s,i)}static fromTrusted(t,n){const r=Object.create(w.prototype);return r.table=t,r.variableMetadata=n,r}size(){return this.table.numRows()}getVariableNames(){return this.table.columnNames()}hasVariable(t){return this.table.column(t)!==void 0}toData(){const n=this.getVariableNames().map(a=>({key:a})),r=Array.from({length:this.size()},(a,s)=>this.table.object(s));return{columns:n,rows:r}}addVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},s=this.normalizeRawValues(n,r),i=this.table.assign(F.table({[t]:s}));return w.fromTrusted(i,a)}addConstantVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},[s]=this.normalizeRawValues(n,[r]),i=this.table.assign(F.table({[t]:Array(this.size()).fill(s)}));return w.fromTrusted(i,a)}deriveVariable(t,n,r){const a=Array.from({length:this.size()},(s,i)=>r(this.table.object(i)));return this.addVariable(t,n,a)}renameVariable(t,n){const r=this.variableMetadata[t];if(!r)throw new Error(`Variable ${t} not defined`);const a=this.table.rename({[t]:n}),{[t]:s,...i}=this.variableMetadata,o={...i,[n]:r};return w.fromTrusted(a,o)}selectVariables(...t){const n=this.table.select(...t),r=Object.fromEntries(Object.entries(this.variableMetadata).filter(([a])=>t.includes(a)));return w.fromTrusted(n,r)}getType(t){const n=this.variableMetadata[t];if(!n)throw new Error(`Variable ${t} not defined`);return n.type}groupVariableNamesByType(){const t={numeric:[],categorical:[],temporal:[]};for(const[n,{type:r}]of Object.entries(this.variableMetadata))t[r].push(n);return t}getValues(t,n){if(!this.hasVariable(t))throw new Error(`Variable '${t}' not defined`);const r=this.getType(t);if(n?.type!==void 0&&r!==n.type)throw new Error(`Variable '${t}' has type '${r}', expected '${n.type}'`);let a=this.table.array(t);return n?.distinct&&(a=this.getDistinctValues(r,a)),n?.skipNulls&&(a=this.skipNulls(a)),a}filter(t,n,r){const a=ts[n],s=this.table.params({__variableName:t,__value:r}).filter(a);return w.fromTrusted(s,this.variableMetadata)}orderBy(t,n="asc"){const r=this.table.orderby(n==="asc"?t:F.desc(t));return w.fromTrusted(r,this.variableMetadata)}getFirst(){return this.size()===0?null:this.table.object(0)}getLast(){return this.size()===0?null:this.table.object(this.size()-1)}findLast(t){for(let n=this.size()-1;n>=0;n--){const r=this.table.object(n);if(t(r))return r}return null}groupBy(...t){const n=this.table.groupby(...t);return new ns(t,n,this.variableMetadata)}rollup(t){const n=this.table.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,F.op[s.aggregation](s.variableName)]))),r={};for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=pn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}reshapeFromWideToLong({keep:t,reshape:n,keyName:r=Za,valueName:a=es}={}){const{numeric:s,categorical:i,temporal:o}=this.groupVariableNamesByType(),c=t??[...i,...o],l=n??s.filter(h=>!c.includes(h));if(c.includes(r)||c.includes(a))throw new Error(`The variables to keep includes the variables '${r}' or '${a}' to create the key and value variables`);if(l.length===0){const h={};for(const b of c){const g=this.variableMetadata[b];g&&(h[b]={type:g.type,values:[]})}return h[r]={type:"categorical",values:[]},h[a]={type:"numeric",values:[]},new w(h)}if(l.filter(h=>this.variableMetadata[h]?.type!=="numeric").length>0)throw new Error("Only numeric variables can be reshaped");const y=this.table.select([...c,...l]).fold(l,{as:[r,a]}),f={};for(const h of c){const b=this.variableMetadata[h];b&&(f[h]=b)}return f[r]={type:"categorical"},f[a]={type:"numeric"},w.fromTrusted(y,f)}print(){console.table(this.variableMetadata),this.table.print()}[Symbol.iterator](){return this.table[Symbol.iterator]()}parseVariableMap(t){const n={},r={};for(const[s,{type:i,values:o}]of Object.entries(t))n[s]=o,r[s]={type:i};return{table:F.table(n),variableMetadata:r}}normalizeRawValues(t,n){switch(t){case"numeric":return n.map(r=>typeof r!="number"||Number.isNaN(r)?null:r);case"categorical":return n.map(r=>typeof r!="string"?null:r);case"temporal":return n.map(r=>!(r instanceof Date)||!T.isValid(r)?null:r);default:{const r=t;throw new Error(`Cannot normalize raw value of unknown type: ${r}`)}}}skipNulls(t){return t.filter(n=>n!==null)}getDistinctValues(t,n){const r=t==="temporal",a=new Set,s=[];for(const i of n){const o=r&&i instanceof Date?i.getTime():i;a.has(o)||(a.add(o),s.push(i))}return s}}class ns{constructor(t,n,r){this.groupedBy=t,this.grouped=n,this.variableMetadata=r}forEach(t){const n=this.grouped.partitions(),r=this.grouped.columnNames(),a=this.groupedBy.map(i=>this.grouped.column(i)).filter(i=>i!==void 0);let s=0;for(const i of n){const o=i[0];if(o===void 0)continue;const c=this.getStableKey(a,o),l=Object.fromEntries(r.map(d=>{const y=this.grouped.column(d);return[d,i.map(f=>y?.get(f))]})),p=F.table(l);t(w.fromTrusted(p,this.variableMetadata),c,s++)}}rollup(t){const n=this.grouped.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,F.op[s.aggregation](s.variableName)]))),r=Object.fromEntries(this.groupedBy.map(a=>[a,{type:this.variableMetadata[a]?.type??"categorical"}]));for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=pn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}getStableKey(t,n){return $(t.map(r=>r.get(n)))}}const se={k:1e3,m:1e6,b:1e9,t:1e12},Ze=["k","m","b","t"],rs=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${Ze.join("|")})?$`,"i"),as=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,W=e=>e===null||e instanceof Date||Array.isArray(e)||typeof e=="boolean"?!1:typeof e=="string"?rs.test(e)&&!Number.isNaN(Number(e.replace(new RegExp(`[,${Ze.join("")}]`,"gi"),""))):!Number.isNaN(Number(e)),mn=e=>W(e)?!0:typeof e=="string"?as.test(e):!1,fn={$:"usd","£":"gbp","€":"eur","¥":"jpy","₹":"inr","₱":"php",P:"php","₩":"krw","₪":"ils","₫":"vnd","₽":"rub","฿":"thb",R$:"brl",Rp:"idr",RM:"myr","₦":"ngn",zł:"pln","₺":"try",kr:"dkk",Fr:"chf",R:"zar","د.إ":"aed","﷼":"sar",Ch$:"clp",NT$:"twd",HK$:"hkd",S$:"sgd",A$:"aud",C$:"cad",NZ$:"nzd",MX$:"mxn"},yn=e=>{if(typeof e=="string"){const t=hn(e);return t.length?W(t):!1}return W(e)},ss=e=>{const t=gn(e),n=t?fn[t]:void 0;if(!n)throw new Error("Could not get currency ISO");return n},hn=e=>{const t=gn(e);let n=e;if(t){const r=e.indexOf(t);r===0?n=e.slice(t.length):r===e.length-t.length?n=e.slice(0,e.length-t.length):e[0]==="-"&&r===1&&(n=`-${e.slice(t.length+1)}`)}return W(n)?n.split(",").join(""):""},gn=e=>Object.keys(fn).sort((n,r)=>r.length-n.length).find(n=>e.includes(n)),me="en-GB";class bn{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(t){this.previousYear===null?this.previousYear=t.getUTCFullYear():this.previousDate!==null&&T.isBefore(new Date(this.currentYear,t.getUTCMonth(),t.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(t.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const is=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,os=/^\s*(19\d{2}|2[01]\d{2})\s*$/,cs=[[/\bJan\b/i,"January"],[/\bFeb\b/i,"February"],[/\bMar\b/i,"March"],[/\bApr\b/i,"April"],[/\bJun\b/i,"June"],[/\bJul\b/i,"July"],[/\bAug\b/i,"August"],[/\bSept?\b/i,"September"],[/\bOct\b/i,"October"],[/\bNov\b/i,"November"],[/\bDec\b/i,"December"]],ls={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},xn=["/","-","."," "],At=[["d","M","yy"],["d","MM","yy"],["d","MMMM","yy"],["dd","M","yy"],["dd","MM","yy"],["dd","MMMM","yy"],["do","MMMM","yy"],["d","M","yyyy"],["d","MM","yyyy"],["d","MMMM","yyyy"],["dd","M","yyyy"],["dd","MM","yyyy"],["dd","MMMM","yyyy"],["do","MMMM","yyyy"]],wt=[["M","d","yy"],["M","dd","yy"],["MM","d","yy"],["MM","dd","yy"],["MMMM","d","yy"],["MMMM","dd","yy"],["MMMM","do","yy"],["M","d","yyyy"],["M","dd","yyyy"],["MM","d","yyyy"],["MM","dd","yyyy"],["MMMM","d","yyyy"],["MMMM","dd","yyyy"],["MMMM","do","yyyy"]],vt=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],Mn=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],us=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],Sn=1900,Tn=2199,ds=3,ps=6,ms=5,fs=1,ys=28,hs=/\s*[–—]\s*|\s-\s/,gs=e=>typeof e=="number"?Number.isNaN(e)?!1:e>=Sn&&e<=Tn:typeof e=="string"?os.test(e):!1,An=(e,t)=>{const n=oe(e);return W(n)?Ms(n):typeof n=="string"?!!wn(n)||vn(n)&&T.isValid(new Date(n)):T.isValid(n)},oe=e=>{if(typeof e!="string")return e;let t=e;for(const[n,r]of cs)t=t.replace(n,r);return t},wn=(e,t=me)=>{const n=oe(e);return vn(n)?{type:"datetime"}:In(t).find(r=>!de(r)||r.type==="month"&&n.length<ds?!1:r.dateFormat&&T.isValid(T.parse(n,r.dateFormat,new Date)))},vn=e=>is.test(e.trim()),bs=(e,t=me)=>{const[n,r]=e.split(hs);if(!n||!r)return;const a=oe(n).trim(),s=oe(r).trim();return xs(t).find(i=>{if(!de(i)||!i.dateFormat)return!1;const o=T.parse(a,i.dateFormat,new Date),c=T.parse(s,i.dateFormat,new Date);if(!T.isValid(o)||!T.isValid(c))return!1;const l=new bn,p=l.incrementYearIfNeeded(o),d=l.incrementYearIfNeeded(c),y=T.differenceInDays(d,p);return T.isWithinInterval(new Date(p.getFullYear(),fs,ys),{start:p,end:d})&&y===ms?!0:y===ps})},Vn=e=>ls[e]==="MDY"?[...wt,...At,...vt]:[...At,...wt,...vt],In=e=>{const t={date:Vn(e),year:[["yyyy"]],day_month:Mn,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...us,...Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>xn.map(s=>({dateFormat:a.join(s),type:n}))))]},xs=e=>{const t={weekly_date_range:Mn,weekly_date_range_with_year:Vn(e)};return Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>xn.map(s=>({dateFormat:a.join(s),type:n}))))},Ms=e=>{const t=Number(e);if(!ee.isInteger(t))return!1;const n=new Date(t),r=new Date(t*1e3),a=s=>T.isValid(s)&&s.getFullYear()>=Sn&&s.getFullYear()<=Tn;return a(n)||a(r)},Ss=(e,t)=>{const n=typeof e=="string"?e.trim():e;if(W(n))return{type:"decimal"};const r=typeof n=="string"&&wn(n,t);if(r)return r;const a=typeof n=="string"&&bs(n,t);return a||(An(e)?{type:"date"}:mn(e)?{type:"percentage"}:yn(e)&&typeof e=="string"?{type:"currency",iso:ss(e)}:{type:"text"})},Ts=e=>{const t=Object.entries(e);return!t.length||!t.some(([,n])=>!fe(n))},fe=e=>typeof e=="string"&&e.trim()===""||e===void 0||e===null||e==="-",As=/\s*[–—]\s*|\s-\s/,ws=(e,t,n)=>{if(fe(e))return null;switch(t.type){case"decimal":case"integer":case"duration":return En(e);case"percentage":return vs(e);case"currency":return Vs(e);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return _n(e,t.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return Is(e,t.dateFormat,n);case"text":return Es(e);default:{const r=t;throw new Error(`Unhandled value format: ${r.type}`)}}},En=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;let t=e.trim();if(!W(t))return null;let n=1;for(const r of Ze)if(new RegExp(`${r}$`,"i").test(t)){n=se[r],t=t.slice(0,-1);break}return Number(t.split(",").join(""))*n},vs=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();if(!mn(t))return null;const n=Number(t.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},Vs=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();return yn(t)?En(hn(t)):null},_n=(e,t,n)=>{if(e instanceof Date)return T.isValid(e)?e:null;const r=oe(String(e).trim());if(r.length===0)return null;const a=new Date;if(t){const i=T.parse(r,t,a);return T.isValid(i)?Oe(i):null}for(const i of In(n)){if(!de(i)||!i.dateFormat)continue;const o=T.parse(r,i.dateFormat,a);if(T.isValid(o))return Oe(o)}const s=new Date(r);return An(s)?Oe(s):null},Is=(e,t,n)=>{const r=String(e).trim().split(As),[a,s]=[r[0]?.trim(),r[1]?.trim()];return!a||!s?null:_n(a,t,n)},Es=e=>String(e).trim(),Oe=e=>new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())),_s={type:"year",dateFormat:"yyyy"},Ln=(e,t)=>{const n={},r={},a=Ds(e),s=Ls(e);for(const[i,o]of e.columns.entries()){const c=a.get(o.key);if(fe(c))continue;const l=i===s?_s:Ss(c,t),p=Pr(l);r[o.key]={type:p,valueFormat:l,label:o.label},n[o.key]=ks(o.key,e.rows,l,p,t)}return{dataset:new w(n),datasetMetadata:{columns:r}}},Ls=e=>{const t=Cs(e.rows,5);return e.columns.findIndex(n=>{const r=t.map(a=>a[n.key]).filter(a=>!fe(a));return r.length>=2&&r.every(gs)})},ks=(e,t,n,r,a)=>{const s=new bn,i=t.map(o=>{const c=ws(o[e],n,a);return an(n)&&c instanceof Date?s.incrementYearIfNeeded(c):c});return{type:r,values:i}},Ds=e=>{const t=new Map,n=new Set(e.columns.map(r=>r.key));for(const r of e.rows){for(const a of n){const s=r[a];fe(s)||(t.set(a,s),n.delete(a))}if(n.size===0)break}return t},Cs=(e,t)=>{const n=[];for(const r of e)if(Ts(r)||n.push(r),n.length===t)return n;return n},Rs=e=>"data"in e&&e.data instanceof w,Ns=e=>!("layers"in e);function kn(e){return{type:"config",config:e}}function Fs(e){return kn({legend:Ps(e.legend),axes:Bs(e.axes),headline:Us(e.headlineNumbers),numberFormat:Ys(e.appearance),content:Gs(e.content),appearance:Os(e.appearance)}).config}function Os(e){if(e?.background)return{background:e.background}}function Ps(e){if(e)return{position:e.position}}function Pe(e,t){return!e&&t===void 0?{}:{...e?.isHidden!==void 0?{isVisible:!e.isHidden}:void 0,...e?.label!==void 0?{label:e.label}:void 0,...e?.tickDisplayMode?{labels:{mode:e.tickDisplayMode}}:void 0,...t!==void 0?{grid:{isVisible:t}}:void 0}}function Bs(e){if(e)return{x:Pe(e.x,e.showGridLines),y:Pe(e.y,e.showGridLines),...e.y2?{ySecondary:Pe(e.y2)}:void 0}}function Us(e){if(e)return{show:e.show,compareWith:e.compareWith,size:e.size}}function Ys(e){if(e?.numberFormat)return{decimals:e.numberFormat.decimalPlaces,abbreviation:e.numberFormat.abbreviation}}function Gs(e){if(e)return{...!e.isTitleHidden&&e.title!==void 0?{title:e.title}:void 0,...!e.isSubtitleHidden&&e.subtitle!==void 0?{subtitle:e.subtitle}:void 0,...!e.isCaptionHidden&&e.caption!==void 0?{caption:e.caption}:void 0}}const E={cartesian:(e={})=>({type:"coord",coordType:"cartesian",params:e}),flip:(e={})=>({type:"coord",coordType:"flip",params:e}),polar:(e={})=>({type:"coord",coordType:"polar",params:e})};function zs(e={}){return{type:"layer",geom:"point",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function $s(e={}){return{type:"layer",geom:"line",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Ws(e={}){return{type:"layer",geom:"area",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Hs(e={}){return{type:"layer",geom:"bar",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}const _={point:zs,line:$s,area:Ws,bar:Hs},Te={stat:"identity",position:"identity",params:{size:8}},Be={stat:"identity",position:"identity",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"gap"}},Ue={stat:"identity",position:"stack",params:{lineWidth:"auto",lineType:"solid",interpolate:"linear",missingValues:"zero"}},Ye={stat:"identity",position:"dodge",params:{}},Ce="primary";function v(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"continuous",transform:t.transform,reverse:t.reverse,nice:t.nice,zero:t.zero,clamp:t.clamp,domainMin:t.domainMin??null,domainMax:t.domainMax??null,range:t.range}}function Ae(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"datetime",domainMin:t.domainMin??null,domainMax:t.domainMax??null,nice:t.nice,reverse:t.reverse,clamp:t.clamp}}function R(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"discrete",range:t.range,sort:t.sort,domain:t.domain??null,padding:t.padding}}function we(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"identity"}}function ve(e,t){return{type:"scale",scaledAesthetic:e,scaleType:"inferred",options:t}}function Dn(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"palette",palette:t.palette}}const z={x:Object.assign(e=>ve("x",e),{continuous:e=>v("x",e),discrete:e=>R("x",e),datetime:e=>Ae("x",e),log:e=>v("x",{...e,transform:"log"}),sqrt:e=>v("x",{...e,transform:"sqrt"})}),y:Object.assign(e=>ve("y",e),{continuous:e=>v("y",e),discrete:e=>R("y",e),datetime:e=>Ae("y",e),log:e=>v("y",{...e,transform:"log"}),sqrt:e=>v("y",{...e,transform:"sqrt"})}),ySecondary:Object.assign(e=>ve("ySecondary",e),{continuous:e=>v("ySecondary",e),discrete:e=>R("ySecondary",e),datetime:e=>Ae("ySecondary",e),log:e=>v("ySecondary",{...e,transform:"log"}),sqrt:e=>v("ySecondary",{...e,transform:"sqrt"})}),color:{continuous:e=>v("color",e),discrete:e=>R("color",e),palette:e=>Dn("color",e)},size:{continuous:e=>v("size",e),discrete:e=>R("size",e),identity:e=>we("size",e)},alpha:{continuous:e=>v("alpha",e),discrete:e=>R("alpha",e),identity:e=>we("alpha",e)},strokeWidth:{continuous:e=>v("strokeWidth",e),discrete:e=>R("strokeWidth",e),identity:e=>we("strokeWidth",e)}};function Ks(e={}){return{type:"transform",transformType:"reshape",options:e}}function js(e){return{type:"transform",transformType:"filter",options:e}}function qs(e){return{type:"transform",transformType:"sort",options:e}}function Xs(e){return{type:"transform",transformType:"aggregate",options:e}}function Qs(e){return{type:"transform",transformType:"constant",options:e}}const ie={reshape:Ks,filter:js,sort:qs,aggregate:Xs,constant:Qs},O="key",P="value",Vt=A("lineSeriesLabel"),It=A("barSeriesLabel"),Et=A("constantY"),Cn=e=>{if(m(e.color))return e;const t=M(e.y);return t===null?e:{...e,color:{value:t}}},et=e=>{const{numeric:t,categorical:n,temporal:r}=e.groupVariableNamesByType();return m(r[0])?r[0]:m(n[0])?n[0]:m(t[0])?t[0]:""},tt=e=>{const t=et(e),{numeric:n}=e.groupVariableNamesByType(),r=n.filter(s=>s!==t);return r.length<=1?{dataset:e,mapping:{x:t,y:r[0]??""}}:{dataset:e.reshapeFromWideToLong({keep:[t],keyName:O,valueName:P}),mapping:{x:t,y:P,color:O}}},Js=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType(),a=r[0];if(!m(a))throw new Error("No first numeric variable found");const s=r.slice(1);return s.length===0?{dataset:e.addConstantVariable(Et,"categorical",""),mapping:{x:a,y:Et,label:t[0]}}:s.length===1?{dataset:e,mapping:{x:a,y:s[0]??"",label:t[0]}}:{dataset:e.reshapeFromWideToLong({keep:[a,...t,...n],keyName:O,valueName:P}),mapping:{x:a,y:P,label:t[0],color:O}}},Zs=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType();let a,s;if(m(t[0])&&m(r[0]))a=t[0],s=r[0];else if(m(n[0])&&m(r[0]))a=n[0],s=r[0];else if(m(r[0])&&m(r[1]))a=r[0],s=r[1];else throw new Error("No label or value variable found");return{x:"",y:s,color:a}},ei=(e,t)=>{const{dataset:n,mapping:r}=tt(e.dataset),a=Cn(r),s=[_.line({params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&s.push(_.point({params:{size:Rn(t.pointSize)},interactive:!1})),{dataset:n,layers:s,coords:E.cartesian(),mapping:a,scales:[]}},ti=(e,t)=>{const{dataset:n,mapping:r}=tt(e.dataset),a=Cn(r),s=[_.area({position:"stack",params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&s.push(_.point({params:{size:Rn(t.pointSize)},position:"stack",interactive:!1})),{dataset:n,layers:s,coords:E.cartesian(),mapping:a,scales:[]}},J=(e,t,n,r,a)=>{const{dataset:s,mapping:i}=tt(e.dataset),o=[];if(r?.sortBars&&o.push(z.x.discrete({sort:"descending"})),!a?.useSingleColorForBars){const c=et(e.dataset),{numeric:l}=e.dataset.groupVariableNamesByType();l.filter(d=>d!==c).length===1&&e.dataset.getType(c)==="categorical"&&(i.color=c)}return{dataset:s,layers:[_.bar({position:t})],coords:n,mapping:i,scales:o}},_t=(e,t)=>({dataset:e.dataset,layers:[_.bar({position:"fill"})],coords:E.polar({theta:"y",innerRadius:t==="donut"?.55:0}),mapping:Zs(e.dataset),scales:[]}),ni=e=>{const{dataset:t,mapping:n}=Js(e.dataset);return{dataset:t,layers:[_.point()],coords:E.cartesian(),mapping:n,scales:[]}},ri=e=>{const{numeric:t,categorical:n}=e.dataset.groupVariableNamesByType(),r={x:t[0],y:t[1],size:t[2],label:n[0]},a=[];return m(r.size)&&a.push(z.size.continuous()),{dataset:e.dataset,layers:[_.point()],coords:E.cartesian(),mapping:r,scales:a}},Ge=(e,t)=>_.line({transforms:[ie.constant({variableName:Vt,type:"categorical",value:e})],aes:{y:e,color:Vt},...t?{yScaleType:"secondary"}:void 0}),ai=(e,t)=>{const{numeric:n,categorical:r,temporal:a}=e.dataset.groupVariableNamesByType(),s=et(e.dataset),i=[...r,...a],o=n.filter(h=>h!==s),c=t?.comboType??"grouped-bars",l=e.axes?.hasDualYAxis===!0,p=c==="lines"||o.length<2,d=p?[]:o.slice(0,-1),y=p?o:o.slice(-1),f=[];if(d.length>0){const h=c==="stacked-bars"?"stack":"dodge",b=d.length===1?d[0]:null;m(b)?f.push(_.bar({transforms:[ie.constant({variableName:It,type:"categorical",value:b})],aes:{y:b,color:It},position:h})):f.push(_.bar({transforms:[ie.reshape({keep:i,reshape:d,keyName:O,valueName:P})],aes:{y:P,color:O},position:h}))}if(p&&y.length>=2){const h=l?y.slice(0,-1):y,b=h.length===1?h[0]:null;if(m(b)?f.push(Ge(b,!1)):f.push(_.line({transforms:[ie.reshape({keep:i,reshape:h,keyName:O,valueName:P})],aes:{y:P,color:O}})),l){const g=y[y.length-1];m(g)&&f.push(Ge(g,!0))}}else for(const h of y)f.push(Ge(h,l));return{dataset:e.dataset,layers:f,coords:E.cartesian(),mapping:{x:s},scales:[]}},Rn=(e="auto")=>e==="auto"?Te.params.size:e,ne=e=>()=>{throw new Error(`Unsupported graph type: ${e}`)},si={line:(e,t)=>ei(e,t),areaStacked:(e,t)=>ti(e,t),bar:(e,t,n)=>J(e,"dodge",E.flip(),t,n),barStacked:(e,t,n)=>J(e,"stack",E.flip(),t,n),barStackedFill:(e,t,n)=>J(e,"fill",E.flip(),t,n),column:(e,t,n)=>J(e,"dodge",E.cartesian(),t,n),columnStacked:(e,t,n)=>J(e,"stack",E.cartesian(),t,n),columnStackedFill:(e,t,n)=>J(e,"fill",E.cartesian(),t,n),pie:e=>_t(e,"pie"),donut:e=>_t(e,"donut"),scatter:e=>ni(e),bubble:e=>ri(e),combo:(e,t)=>ai(e,t),funnel:ne("funnel"),heatmap:ne("heatmap"),waterfall:ne("waterfall"),mekko:ne("mekko"),table:ne("table")},ii=(e,t,n,r)=>si[t](e,n,r);function oi(e,t){const n=[];return n.push(Lt("x",e?.x)),n.push(Lt("y",e?.y)),n.push(z.color.palette({palette:t?.paletteId})),n}function Lt(e,t){return t?.scaleType==="logarithmic"||t?.isReversed||t?.min!==void 0||t?.max!==void 0?t.scaleType==="logarithmic"?z[e].log({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):z[e].continuous({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):z[e]()}function ci(e,t,n){const r=n.type??"column",a={dataset:e,axes:n.axes},s=ii(a,r,n.options??void 0,n.appearance??void 0);return{data:s.dataset,datasetMetadata:t,mapping:s.mapping,layers:s.layers,scales:[...oi(n.axes,n.appearance),...s.scales],transforms:[],coords:s.coords,config:Fs(n)}}const li={mode:"readonly",parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{isVisible:!0,title:null,subtitle:null,caption:null},appearance:{background:null}},ui={xLimits:null,yLimits:null},ze={theta:"x",startAngle:0,innerRadius:0};function di(e){const t=e??{type:"coord",coordType:"cartesian"},n=$t({},ui,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:n};case"polar":return{...t,params:{...n,theta:t.params?.theta??ze.theta,startAngle:t.params?.startAngle??ze.startAngle,innerRadius:t.params?.innerRadius??ze.innerRadius}}}}function pi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Te.stat,position:e.position??Te.position,yScaleType:e.yScaleType??Ce,params:ee.merge({},Te.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function mi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Be.stat,position:e.position??Be.position,yScaleType:e.yScaleType??Ce,params:ee.merge({},Be.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function fi(e){const t=ee.merge({},Ue.params,e.params);return t.missingValues==="gap"&&(t.missingValues="zero"),{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ue.stat,position:e.position??Ue.position,yScaleType:e.yScaleType??Ce,params:t,transforms:e.transforms??[],interactive:e.interactive??!0}}function yi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ye.stat,position:e.position??Ye.position,yScaleType:e.yScaleType??Ce,params:{...Ye.params,...e.params},transforms:e.transforms??[],interactive:e.interactive??!0}}function hi(e){switch(e.geom){case"point":return pi(e);case"line":return mi(e);case"area":return fi(e);case"bar":return yi(e)}}function gi(e){return e.map(hi)}function bi(e,...t){return e.find(n=>t.includes(n.geom))}const Nn={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range"},xi={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Fn(e,t,n,r){switch(e.scaleType){case"inferred":{const a=Si(e,t,n,r);return Fn(a,t,n,r)}case"continuous":{const a=Nn[e.scaledAesthetic],s=a==="continuous-range"&&e.scaledAesthetic in Tt?Tt[e.scaledAesthetic]:null,i=e.scaledAesthetic==="size"&&a==="continuous-range"?"sqrt":Q.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??i,reverse:e.reverse??Q.reverse,nice:e.nice??Q.nice,zero:e.zero??Q.zero,clamp:e.clamp??a!=="position",domainMin:e.domainMin??Q.domainMin,domainMax:e.domainMax??Q.domainMax,range:e.range??s??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??xe.domainMin,domainMax:e.domainMax??xe.domainMax,nice:e.nice??xe.nice,reverse:e.reverse??xe.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??re.range,sort:e.sort??re.sort,domain:e.domain??re.domain,padding:e.padding??re.padding};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:e.palette??Ka.palette};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const a=e;throw new Error(`Unknown scale type: ${a.scaleType}`)}}}function Mi(e,t,n,r){const a=Ai(t,n),s=wi(a),i=new Map;for(const o of s)i.set(o.scaledAesthetic,o);return[...i.values()].map(o=>Fn(o,e,n,r))}function Si(e,t,n,r){const a=U(e.scaledAesthetic),s=e.scaledAesthetic==="ySecondary"?Ti(n,r):r[a],i=bi(n,"bar");if(e.scaledAesthetic==="x"&&i)return R(e.scaledAesthetic,e.options);if(i&&e.scaledAesthetic===(i.yScaleType==="secondary"?"ySecondary":"y")){const d=e.options,y=i.position==="fill";return v(e.scaledAesthetic,{...d,zero:!0,...y&&{nice:!1}})}const o=M(s);if(!m(o)||!t.hasVariable(o))return v(e.scaledAesthetic,e.options);const c=t.getType(o),l=Nn[e.scaledAesthetic];switch(xi[c][l]){case"discrete":return R(e.scaledAesthetic,e.options);case"datetime":return Ae(e.scaledAesthetic,e.options);case"continuous":return v(e.scaledAesthetic,e.options);case"identity":default:return we(e.scaledAesthetic)}}function Ti(e,t){const n=e.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??t.y:t.y}function Ai(e,t){return!t.some(a=>a.yScaleType==="secondary")||e.some(a=>a.scaledAesthetic==="ySecondary")?e:[...e,ve("ySecondary")]}function wi(e){return e.some(n=>n.scaledAesthetic==="color")?e:[...e,Dn("color")]}function kt(e){const{data:t,mapping:n}=Vi(e.data,e.mapping),r=di(e.coords),a=gi(e.layers),s=Mi(t,e.scales,a,n);return{data:t,datasetMetadata:e.datasetMetadata,mapping:n,layers:a,scales:r.coordType==="polar"?vi(s):s,transforms:e.transforms,coords:r,config:ee.merge({},li,e.config)}}const vi=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t),Vi=(e,t)=>{let n=e,r=t;r.x===""&&(n=n.addConstantVariable(gt.x,"categorical",""),r={...r,x:gt.x});for(const a of Object.keys(r)){const s=Ir(r[a]);if(s===void 0)continue;const i=A(`const_${a}`);n=n.addConstantVariable(i,Ii(s),s),r={...r,[a]:i}}return{data:n,mapping:r}},Ii=e=>typeof e=="number"?"numeric":e instanceof Date?"temporal":"categorical";class On{compile(t){return le({input:t}).pipe(({input:r})=>Ei(r.data)).pipe(({input:r,dataset:a,datasetMetadata:s})=>({spec:this.resolveFromInput(r,a,s)})).result().spec}resolveFromInput(t,n,r){if(Ns(t)){const{data:a,...s}=t;return kt(ci(n,r,s))}return kt({...t,data:n,datasetMetadata:r})}}const Ei=e=>{const t=e._metadata?.parsingLocale??me;return Ln(e,t)};class _i{constructor(t){this.registry=t}compute(t,n){return this.registry.get(t).compute(n)}}class Pn{compute(t){return t.data.size()===0?{data:t.data,mapping:{}}:this.computeStat(t)}}class Li extends Pn{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=M(n.x);if(!m(r))throw new Error("'x' variable is required for 'count' stat");if(M(n.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const s=[...new Set([r,...qt(t,n)])];return{data:t.groupBy(...s).rollup({[Ke.count]:{variableName:r,aggregation:"count"}}),mapping:{y:Ke.count}}}}class ki extends Pn{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:t}){return{data:t,mapping:{}}}}class Di extends K{constructor(){super("stat"),this.register("identity",new ki),this.register("count",new Li)}}class Ci{constructor(t){this.registry=t}compile(t,n){return n.reduce((r,a)=>this.registry.get(a.transformType).apply(r,a),t)}}class Ri{constructor(){this.transformType="aggregate"}apply(t,n){const{options:r}=n,a={};for(const s of r.operations)a[s.as]={variableName:s.variableName,aggregation:s.op};return t.groupBy(...r.groupby).rollup(a)}}class Ni{constructor(){this.transformType="constant"}apply(t,n){const{options:r}=n;return t.addConstantVariable(r.variableName,r.type,r.value)}}class Fi{constructor(){this.transformType="filter"}apply(t,n){const{options:r}=n;return t.filter(r.variableName,r.operator,r.value)}}class Oi{constructor(){this.transformType="reshape"}apply(t,n){const{options:r}=n;return t.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}}class Pi{constructor(){this.transformType="sort"}apply(t,n){const{options:r}=n;return t.orderBy(r.variableName,r.direction??"asc")}}class Bi extends K{constructor(){super("transform"),this.register("aggregate",new Ri),this.register("constant",new Ni),this.register("filter",new Fi),this.register("reshape",new Oi),this.register("sort",new Pi)}}const Ui={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric"};class Yi{compile(t){return t.layers.map(n=>this.compileLayer(n,t.scales))}compileLayer(t,n){let r=t.data;const a=Object.entries(j);for(const[s,i]of a){const o=M(t.mapping[s]),c=n[s];if(!c||c.kind!=="visual")continue;const l=Gi(s,o,c);l&&(r=r.deriveVariable(i,Ui[s],l))}return{...t,data:r}}}const Gi=(e,t,n)=>{if(!t){if(e!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>m(r[t])?n.map(r[t]):null};class Bn{constructor(t,n,r,a,s,i,o,c){this.specCompiler=t,this.transformCompiler=n,this.layerCompiler=r,this.scaleCompiler=a,this.coordCompiler=s,this.positionMapperCompiler=i,this.visualMapperCompiler=o,this.guideCompiler=c}compile(t){const n=le({input:t}).pipe(({input:r})=>({spec:Rs(r)?r:this.specCompiler.compile(r)})).pipe(({spec:r})=>({spec:{...r,data:this.transformCompiler.compile(r.data,r.transforms)}})).pipe(({spec:r})=>({layers:this.layerCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping})})).pipe(({spec:r,layers:a})=>({scales:this.scaleCompiler.compile({layers:a,scales:r.scales})})).pipe(({spec:r})=>({coordSystem:this.coordCompiler.setup({coordSpec:r.coords})})).pipe(({layers:r,scales:a})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,scales:a,layers:s,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:a,config:r.config,layers:s,coordSystem:i,datasetMetadata:r.datasetMetadata})})).pipe(({layers:r,scales:a})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,layers:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,layers:a})})).result();return{...n,config:n.spec.config}}}const zi=e=>{const t=new dr,n=new Di,r=new Qa(t),a=new Cr,s=new Ci(new Bi);return t.register(Kt,[...Ht]),new Bn(new On,s,new Ia(s,new _i(n),new Rr,new vr(a),new _a(new Ra),new Ea(a,n)),new Ga(r),new pr(new wr),new Ya,new Yi,new Va).compile(e)};function $i(e,t){return e.geom===t}const nt="–",Wi="n/a",L={timeZone:"UTC"},I=e=>t=>{if(!Z(t))return nt;try{return e(t)}catch{return Wi}},Y=e=>t=>tn(t)?e(t):nt,Un=e=>t=>en(t)?t:nt,Hi=2,Ki=3,ji=2,qi=0,Xi=1,Qi=2,Ji=({valueFormat:e,locale:t,numberFormat:n,intlOptions:r})=>Y(a=>{const s=typeof n.decimals=="number"?n.decimals:Hi,i=rt(a,s),{base:o,suffix:c}=at(a,n.abbreviation),l={...i,...rn(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return`${Intl.NumberFormat(t,l).format(o)}${c}`}),Zi=({locale:e,numberFormat:t,intlOptions:n})=>Y(r=>{const{base:a,suffix:s}=at(r,t.abbreviation),o={...rt(a,t.decimals),...n};return`${Intl.NumberFormat(e,o).format(a)}${s}`}),Yn=e=>Y(t=>ro(t)),eo=({locale:e,intlOptions:t})=>Y(n=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(n)),to=({locale:e,numberFormat:t,intlOptions:n})=>Y(r=>{const a=rt(r,t.decimals);return Intl.NumberFormat(e,{...a,...n,style:"percent"}).format(r)}),rt=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const n=Math.ceil(Math.log10(Math.abs(e))),r=n>=Ki?qi:n===ji?Xi:Qi;return{minimumFractionDigits:t==="auto"?0:r,maximumFractionDigits:r}},no=e=>{const t=Math.abs(e);return t>=se.b?"b":t>=se.m?"m":t>=se.k?"k":"none"},at=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const n=no(e);return at(e,n)}default:return{base:e/se[t],suffix:t}}},ro=lr.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),ao=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{dateStyle:"medium",...L,...t}).format(n)),so=({locale:e,intlOptions:t})=>I(n=>{const r=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...L,...t}).formatToParts(n);return po(r.map(mo))}),io=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...L,...t}).format(n)),oo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"long",...L,...t}).format(n)),Gn=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...L,...t}).format(n)),zn=e=>I(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),co=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...L,...t,year:void 0}).formatRange(n,r)}),lo=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...L,...t}).formatRange(n,r)}),$n=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{year:"numeric",...L,...t}).format(n)),uo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...L,...t}).format(n)),po=e=>e.map(t=>t.value).join(""),mo=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},fo=1,yo=4,ho=1,go=({valueFormat:e,locale:t,tickValues:n,intlOptions:r})=>Y(a=>{const i={...it(a,n),notation:"compact",...rn(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return st(a,t,i)}),bo=({locale:e,tickValues:t,intlOptions:n})=>Y(r=>{const s={...it(r,t),notation:"compact",...n};return st(r,e,s)}),xo=({locale:e,tickValues:t,intlOptions:n})=>Y(r=>{const s={...it(r,t),notation:"compact",...n,style:"percent"};return st(r,e,s)}),st=(e,t,n)=>Intl.NumberFormat(t,n).formatToParts(e).map(a=>a.type==="compact"?a.value.toLowerCase():a.value).join(""),Dt=1e3,Wn=e=>Math.abs(e)>Dt?Wn(e/Dt):Number.isInteger(e),Mo=e=>{if(e.length<2)return!1;const[t,n]=e;return typeof t!="number"||typeof n!="number"?!1:Math.abs(n-t)<fo},it=(e,t)=>Wn(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Mo(t)?{minimumFractionDigits:0,maximumFractionDigits:yo}:{minimumFractionDigits:0,maximumFractionDigits:ho},So=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...L,...t}).format(n)),To=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",...L,...t}).format(n)),Ao=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...L,...t}).format(n)),wo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...L,...t}).format(n)),vo=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return go(e);case"date":case"datetime":return So(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Ao(e);case"decimal":case"integer":return bo(e);case"duration":return Yn();case"month":return To(e);case"month_year":return Gn(e);case"percentage":return xo(e);case"quarter":return zn();case"text":return Un();case"time":return wo(e);case"year":return $n(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},Vo=40,Io=60,Ct=8,Eo=50,_o=1/3,Lo=1/4,$e="…",ko=(e,t,n)=>{if(t<=0||e.length===0)return"";if(n(e)<=t)return e;if(n($e)>t)return"";let r=0,a=e.length-1,s=0;for(;r<=a;){const i=r+a>>>1,o=e.slice(0,i)+$e;n(o)<=t?(s=i,r=i+1):a=i-1}return e.slice(0,s)+$e},Do=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Co(e):Ro(e),Co=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=Hn(e.ticks,r),o=t-Ct;if(s<=o)return{...e,labelRotation:0,labelMaxWidthPx:null};if(t>=Eo){const l=Qe(o);return{...e,ticks:Xe(e.ticks,a,l,r),labelRotation:0,labelMaxWidthPx:l}}if(i+Ct>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=Qe(n.height*_o);return{...e,ticks:Xe(e.ticks,a,c,r),labelRotation:-90,labelMaxWidthPx:c}},Ro=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=Hn(e.ticks,r);if(i>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Qe(n.width*Lo);return s<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Xe(e.ticks,a,o,r),labelRotation:0,labelMaxWidthPx:o}},Hn=(e,t)=>{const n=[];let r=0,a=0;for(const s of e){const{width:i,height:o}=t(s.formattedLabel);n.push(i),i>r&&(r=i),o>a&&(a=o)}return{widths:n,maxWidth:r,maxHeight:a}},Xe=(e,t,n,r)=>{const a=s=>r(s).width;return e.map((s,i)=>(t[i]??0)<=n?s:{...s,formattedLabel:ko(s.formattedLabel,n,a)})},Qe=e=>Math.max(0,Math.floor(e)),No=(e,t,n,r)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",s=a?Io:Vo;let i=n-(e.length-1)*s;for(const o of e){const{width:c,height:l}=r(o);if(i-=a?c:l,i<0)return!1}return!0},Fo=({axis:e,availableSpacePx:t,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:a,position:s}=e;if(a.length===0)return[];const i=new Map,o=d=>{const y=i.get(d);if(y)return y;const f=a[d],h=f?Oo(f.ticks,r(f)):[];return i.set(d,h),h};let c=0,l=a.length-1,p=-1;for(;c<=l;){const d=c+l>>>1,f=o(d).map(h=>h.formattedLabel);No(f,s,t,n)?(p=d,c=d+1):l=d-1}return p>=0?o(p):o(0)},Oo=(e,t)=>e.map(n=>({...n,formattedLabel:t(n.value)})),Po=e=>{const t=e.padding??0,n=Rt(e.rows,t),r=Rt(e.cols,t);return{rows:n.tracks,cols:r.tracks,placements:Go(e.placements,n.nameToIndex,r.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Bo=e=>{const t=Nt(e.rows,e.height),n=Nt(e.cols,e.width),r=Ft(t),a=Ft(n),s=new Map;for(const i of e.placements){const o=i.rowSpan??1,c=i.colSpan??1,l=a[i.col]??0,p=r[i.row]??0,d=Ot(n,i.col,c),y=Ot(t,i.row,o);s.set(i.name,{x:l,y:p,width:Math.max(0,d),height:Math.max(0,y)})}return s},Rt=(e,t)=>{const n=[],r=new Map;t>0&&n.push({type:"fixed",pixels:t});for(let a=0;a<e.length;a++){const s=e[a];if(!s)continue;r.set(s.name,n.length),n.push(Uo(s));const i=Yo(e,a);if(Kn(s)&&i){const o=s.gaps?.after??0,c=i.gaps?.before??0,l=Math.max(o,c);l>0&&n.push({type:"fixed",pixels:l})}}return t>0&&n.push({type:"fixed",pixels:t}),{tracks:n,nameToIndex:r}},Uo=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Kn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Yo=(e,t)=>{for(let n=t+1;n<e.length;n++){const r=e[n];if(r&&Kn(r))return r}},Go=(e,t,n)=>{const r=[];for(const a of e){const s=t.get(a.row),i=n.get(a.col);if(s===void 0||i===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):s,c=a.colEnd!==void 0?n.get(a.colEnd):i;o===void 0||c===void 0||r.push({name:a.name,row:s,col:i,rowSpan:Math.max(1,o-s+1),colSpan:Math.max(1,c-i+1)})}return r},Nt=(e,t)=>{let n=0,r=0;for(const s of e)s.type==="fixed"?n+=s.pixels:r+=s.weight;const a=Math.max(0,t-n);return e.map(s=>s.type==="fixed"?s.pixels:r===0?0:s.weight/r*a)},Ft=e=>{const t=new Array(e.length);let n=0;for(let r=0;r<e.length;r++)t[r]=n,n+=e[r]??0;return t},Ot=(e,t,n)=>{let r=0;const a=Math.min(t+n,e.length);for(let s=t;s<a;s++)r+=e[s]??0;return r},zo=["top","right","bottom","left"],We=(e,t)=>{const n={};for(const r of zo){const a=e.get(`${r}${t}`);a&&(n[r]=a)}return n},jn=24,N={header:{after:10,before:0},topLegend:{after:16,before:0},topAxisLabel:{after:4,before:0},topAxis:{after:0,before:0},panel:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},Me={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},panel:{after:4,before:0},rightAxis:{after:10,before:0}},$o=(e,t,n)=>{const a=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return Po({rows:[{name:"header",size:t.headerSize.height,gaps:N.header},{name:"topLegend",size:n.legends.top,gaps:N.topLegend},{name:"topAxisLabel",size:a,gaps:N.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:N.topAxis},{name:"panel",size:{flex:1},gaps:N.panel},{name:"bottomAxis",size:n.axes.bottom,gaps:N.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:N.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:N.bottomLegend},{name:"footer",size:t.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:Me.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:Me.leftAxis},{name:"panel",size:{flex:1},gaps:Me.panel},{name:"rightAxis",size:n.axes.right,gaps:Me.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panel",row:"panel",col:"panel"},...Wo(n.axes),...Ho(n.axesLabels,n.axes),...Ko(n.legends)],containerSize:e,padding:jn})},Wo=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Ho=(e,t)=>{const n=[];return e.top>0||t.top>0?(e.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},Ko=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t},Se={x:0,y:0,width:0,height:0},jo="0000";class qo{constructor(t){this.measurer=t}compile(t){return le({compiled:t.compiled,formattedLegends:t.formattedLegends,containerSize:t.containerSize,externalMeasurements:t.externalMeasurements,locale:t.formattingLocale??t.compiled.config.parsingLocale}).pipe(({compiled:n,locale:r})=>({axisBundles:n.guides.axes.map(a=>({axis:a,resolveFormatter:Xo(a,r,n.config),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({axisBundles:n.map(a=>Pt(a.axis.position)?{...a,formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel)}:a)})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({formattedAxes:n.map(a=>Pt(a.axis.position)?a.formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel))})).pipe(({formattedAxes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})})).result()}seedAxis(t){const{tickCandidates:n,...r}=t;return{...r,ticks:[{value:0,position:0,formattedLabel:jo}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(t,n,r){const s=t.position==="top"||t.position==="bottom"?r.width:r.height,i=Fo({axis:t,availableSpacePx:s,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:o,...c}=t,l={...c,ticks:i,labelRotation:0,labelMaxWidthPx:null};if(t.scaleType==="discrete"&&t.bandwidth!==void 0){const p=t.bandwidth*s;return Do({formattedAxis:l,bandwidthPx:p,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:t,formattedLegends:n,containerSize:r,externalMeasurements:a}){const s=this.measureGuides(t,n),i=$o(r,a,s),o=Bo(i);return{header:o.get("header")??Se,footer:o.get("footer")??Se,plot:o.get("plot")??Se,panel:o.get("panel")??Se,axes:We(o,"Axis"),axisLabels:We(o,"AxisLabel"),legends:We(o,"Legend")}}measureGuides(t,n){const r={top:0,right:0,bottom:0,left:0},a={top:0,right:0,bottom:0,left:0};for(const i of t)i.isVisible&&(r[i.position]=this.measurer.measureAxis(i),i.label!==null&&(a[i.position]=this.measurer.measureAxisLabel()));const s={top:0,right:0,bottom:0,left:0};for(const i of n)s[i.position]=this.measurer.measureLegend(i);return{axes:r,axesLabels:a,legends:s}}}const Pt=e=>e==="left"||e==="right",Xo=(e,t,n)=>{const r=e.tickCandidates.flatMap(s=>s.ticks.map(i=>i.value)),a=new WeakMap;return s=>{const i=a.get(s);if(i)return i;const o=vo({valueFormat:s.valueFormat??e.valueFormat,locale:t,numberFormat:n.numberFormat,tickValues:r});return a.set(s,o),o}};function ce(e,t){return e==="x"?t.x:t.y}function Re(e,t){return e==="x"?t.y:t.x}function Qo(e,t){return{main:ce(e,t),cross:Re(e,t)}}function Jo(e){return e.type==="cartesian"}const Ne=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ji(e);case"date":return ao(e);case"datetime":return so(e);case"day_month":return io(e);case"decimal":return Zi(e);case"duration":return Yn();case"integer":return eo(e);case"month":return oo(e);case"month_year":return Gn(e);case"percentage":return to(e);case"quarter":return zn();case"text":return Un();case"weekly_date_range":return co(e);case"weekly_date_range_with_year":return lo(e);case"year":return $n(e);case"time":return uo(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},Zo=(e,{formattingLocale:t}={})=>{const n=t??e.config.parsingLocale,r=e.config.numberFormat;return e.guides.legends.map(a=>ec(a,n,r))},ec=(e,t,n)=>{const r=Ne({valueFormat:e.valueFormat,locale:t,numberFormat:n});return{...e,items:e.items.map(a=>({...a,formattedLabel:r(a.value)}))}};function H(e){return e==="stack"||e==="fill"}function qn(e,t){return ot(e.buckets,t,n=>n.main)}function tc(e,t){return ot(e.bands,t,n=>n.bandCenter)}function nc(e,t){return ot(e.columns,t,n=>n.mainMid)}function ot(e,t,n){if(e.length===0)return null;let r=0,a=e.length;for(;r<a;){const o=r+a>>>1,c=e[o];c&&n(c)<t?r=o+1:a=o}const s=e[r-1],i=e[r];return s?i&&Math.abs(n(i)-t)<Math.abs(n(s)-t)?i:s:i??null}function ct(e,t,n){return Math.hypot(e*n,t)}function rc(e,t,n,r){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const s=a.find(t.x*n,t.y,r??void 0),i=e.points[s];return i?{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:ct(i.x-t.x,i.y-t.y,n)}:null}function ac(e,t){if(e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const n=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[n]??null}function sc(e,t){return{group:ic(e),related:uc(e,t)}}function ic(e){switch(e.kind){case"buckets":{const t=e.match.index;return H(t.position)?oc(t,e.match):[]}case"rects":{const t=e.match.index;return H(t.position)?cc(t,e.match):lc(t,e.match)}case"points":case"arcs":return[]}}function oc(e,t){const n=[];for(const r of t.bucket.entries)r.pointIndex!==t.hit.pointIndex&&n.push({layerId:e.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return n}function cc(e,t){const n=[];for(const r of t.column.rects)r.pointIndex!==t.hit.pointIndex&&n.push(lt(e,r));return n}function lc(e,t){const n=e.bands.find(a=>a.columns.includes(t.column));if(!n)return[];const r=[];for(const a of n.columns)for(const s of a.rects)s.pointIndex!==t.hit.pointIndex&&r.push(lt(e,s));return r}function uc(e,t){const n=new Map;if(e.kind==="arcs")return n;for(const r of t){if(r.layerId!==e.match.index.layerId){pc(n,r,e.match.hit);continue}e.kind==="buckets"&&(H(r.position)||r.kind==="buckets"&&dc(n,r,e.match))}return n}function dc(e,t,n){for(const r of n.bucket.entries){if(r.pointIndex===n.hit.pointIndex)continue;Ve(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation})}}function pc(e,t,n){switch(t.kind){case"buckets":{const r=qn(t,ce(t.mainAxis,n));if(!r)return;const a=Ve(e,t.layerId);for(const s of r.entries)a.push({layerId:t.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation});return}case"rects":{const r=tc(t,ce(t.mainAxis,n));if(!r)return;const a=Ve(e,t.layerId);for(const s of r.columns)for(const i of s.rects)a.push(lt(t,i));return}case"points":{const r=ac(t,n);if(!r)return;Ve(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return}case"arcs":return}}function Ve(e,t){let n=e.get(t);return n||(n=[],e.set(t,n)),n}function lt(e,t){return{layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function mc(e){const t=fc(e);return{kind:"arcs",layerId:e.id,geom:e.geom,position:e.position,arcs:t}}function fc(e){const t=e.data;if(t.size()===0)return[];const n=[u.xMin,u.xMax,u.yMin,u.yMax];for(const l of n)if(!t.hasVariable(l))return[];const r=t.getValues(u.xMin,{type:"numeric"}),a=t.getValues(u.xMax,{type:"numeric"}),s=t.getValues(u.yMin,{type:"numeric"}),i=t.getValues(u.yMax,{type:"numeric"}),o=[];let c=0;for(const l of t){const p=r[c],d=a[c],y=s[c],f=i[c];if(!m(p)||!m(d)||!m(y)||!m(f)){c++;continue}o.push({pointIndex:c,startAngle:p,endAngle:d,innerRadius:y,outerRadius:f,observation:l}),c++}return o}const yc=1e-9;function hc(e,t){const n=gc(e,t);n.sort((a,s)=>a.main-s.main);const r=[];for(const a of n){const s=r[r.length-1];s&&Math.abs(s.main-a.main)<=yc?s.entries.push(a.entry):r.push({main:a.main,entries:[a.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,buckets:r}}function gc(e,t){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(u.x),s=n.hasVariable(u.y);if(!a||!s)return[];const i=n.getValues(u.x,{type:"numeric"}),o=n.getValues(u.y,{type:"numeric"}),c=t==="y",l=c?u.xMin:u.yMin,p=c?u.xMax:u.yMax,d=H(e.position),y=d?n.getValues(l,{type:"numeric"}):null,f=d?n.getValues(p,{type:"numeric"}):null,h=n.hasVariable(V.group)?n.getValues(V.group,{type:"categorical"}):null,b=[];let g=0;for(const x of n){const S=i[g],k=o[g];if(!m(S)||!m(k)){g+=1;continue}const D=h?.[g]??null,ge=c?k:S;if(d){const ht=y?.[g],be=f?.[g];if(!m(ht)||!m(be)){g+=1;continue}const ir=c?be:S,or=c?k:be;b.push({main:ge,entry:{isStacked:d,pointIndex:g,x:ir,y:or,stackMin:ht,stackMax:be,groupKey:D,observation:x}})}else b.push({main:ge,entry:{isStacked:d,pointIndex:g,x:S,y:k,groupKey:D,observation:x}});g+=1}return b}function bc(e,t){const n={kind:"points",layerId:e.id,geom:e.geom,position:e.position,points:xc(e),delaunay:null,delaunayAspectRatio:null};return Xn(n,t),n}function Xn(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=ur.Delaunay.from(e.points,n=>n.x*t,n=>n.y),e.delaunayAspectRatio=t)}function xc(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(u.x)||!t.hasVariable(u.y))return[];const n=t.getValues(u.x,{type:"numeric"}),r=t.getValues(u.y,{type:"numeric"}),a=[];let s=0;for(const i of t){const o=n[s],c=r[s];s+=1,!(!m(o)||!m(c))&&a.push({pointIndex:a.length,x:o,y:c,observation:i})}return a}const Mc=1e6;function Sc(e,t){const n=Tc(e,t);n.sort((o,c)=>o.mainMid-c.mainMid);const r=new Map,a=new Map;for(const o of n){const c=Bt(o.mainMid);let l=r.get(c);if(!l){l={mainMid:o.mainMid,columnKey:c,rects:[]},r.set(c,l);const p=Bt(o.bandCenter);let d=a.get(p);d||(d={bandCenter:o.bandCenter,bandKey:p,columns:[]},a.set(p,d)),d.columns.push(l)}l.rects.push(o.entry)}const s=[...r.values()].sort((o,c)=>o.mainMid-c.mainMid),i=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of i)o.columns.sort((c,l)=>c.mainMid-l.mainMid);return{kind:"rects",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,columns:s,bands:i}}function Bt(e){return String(Math.round(e*Mc))}function Tc(e,t){const n=e.data;if(n.size()===0)return[];if(!(n.hasVariable(u.xMin)&&n.hasVariable(u.xMax)&&n.hasVariable(u.yMin)&&n.hasVariable(u.yMax)))return[];const a=n.getValues(u.xMin,{type:"numeric"}),s=n.getValues(u.xMax,{type:"numeric"}),i=n.getValues(u.yMin,{type:"numeric"}),o=n.getValues(u.yMax,{type:"numeric"}),c=t==="y",l=c?u.y:u.x,p=n.hasVariable(l)?n.getValues(l,{type:"numeric"}):null,d=n.hasVariable(V.group)?n.getValues(V.group,{type:"categorical"}):null,y=[];let f=0;for(const h of n){const b=a[f],g=s[f],x=i[f],S=o[f];if(!m(b)||!m(g)||!m(x)||!m(S)){f++;continue}const k=c?(x+S)/2:(b+g)/2,D=p?.[f]??k;y.push({mainMid:k,bandCenter:D,entry:{pointIndex:f,xMin:b,xMax:g,yMin:x,yMax:S,segmentKey:d?.[f]??null,observation:h}}),f++}return y}function Ut(e,t,n){if(t.type==="polar")return mc(e);switch(e.geom){case"point":return bc(e,n);case"line":case"area":return hc(e,t.mainAxis);case"bar":return Sc(e,t.mainAxis);default:{const r=e.geom;throw new Error(`buildLayerIndex: unhandled geom ${String(r)}`)}}}const C=Math.PI*2,Ac=1e-9;function wc(e,t,n){if(e.arcs.length===0)return null;const{angle:r,radius:a}=vc(t,n);for(const s of e.arcs)if(!(a<s.innerRadius||a>s.outerRadius)&&Vc(r,s))return{hit:{layerId:e.layerId,pointIndex:s.pointIndex,x:(s.startAngle+s.endAngle)/2,y:(s.innerRadius+s.outerRadius)/2,observation:s.observation},index:e};return null}function vc(e,t){const n=e.x-.5,r=e.y-.5,a=t>=1?n*2*t:n*2,s=t>=1?r*2:r*2/t,i=Math.hypot(a,s);return{angle:(Math.atan2(a,s)%C+C)%C,radius:i}}function Vc(e,t){const n=t.endAngle-t.startAngle;if(Math.abs(n)>=C-Ac)return!0;const r=(n%C+C)%C;return((e-t.startAngle)%C+C)%C<=r}function Ic(e,t,n){if(e.buckets.length===0)return null;const{main:r,cross:a}=Qo(e.mainAxis,t),s=qn(e,r),i=s?.entries??[];if(!s||!Wt(i))return null;const o=H(e.position)?Dc(i,a):kc(i,a,e.mainAxis);return{hit:{layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:s,distance:ct(o.x-t.x,o.y-t.y,n)}}function Ec(e,t,n){if(e.columns.length===0)return null;const r=ce(e.mainAxis,t),a=nc(e,r),s=a?.rects??[];if(!a||!Wt(s))return null;const i=H(e.position)?_c(s,t,e.mainAxis):Lc(s,t,n);return{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:a,distance:Qn(i,t,n)}}function _c(e,t,n){const r=Re(n,t);return Fe(e,s=>Rc(s,n,r),{shortCircuitOnZero:!0})}function Lc(e,t,n){return Fe(e,a=>Qn(a,t,n))}function kc(e,t,n){return Fe(e,a=>Math.abs(Re(n,a)-t))}function Dc(e,t){const n=Cc(e);return Fe(n,a=>Nc(a,t),{shortCircuitOnZero:!0})}function Cc(e){for(const t of e)if(!t.isStacked)throw new Error("pickStackedBucketEntry: expected stacked entries in a stacked bucket index");return e}function Fe(e,t,{shortCircuitOnZero:n=!1}={}){let r=e[0],a=t(r);if(n&&a===0)return r;for(let s=1;s<e.length;s+=1){const i=e[s];if(i===void 0)continue;const o=t(i);if(n&&o===0)return i;o<a&&(r=i,a=o)}return r}function Qn(e,t,n){const r=_e(t.x,e.xMin,e.xMax),a=_e(t.y,e.yMin,e.yMax);return ct(r,a,n)}function Rc(e,t,n){const r=t==="x"?e.yMin:e.xMin,a=t==="x"?e.yMax:e.xMax;return _e(n,r,a)}function Nc(e,t){return _e(t,e.stackMin,e.stackMax)}function _e(e,t,n){return e<t?t-e:e>n?e-n:0}const Fc=.05;function Oc({layers:e,cursor:t,aspectRatio:n,warmStarts:r}){const a={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const i of e){if(i.kind==="arcs"){const c=wc(i,t,n);return c?{kind:"arcs",match:c}:null}const o=Bc({layer:i,cursor:t,aspectRatio:n,warmStarts:r});if(o){if(o.kind==="rects"){o.match.distance<a.distance&&(a.match=o,a.distance=o.match.distance);continue}o.match.distance<s.distance&&(s.match=o,s.distance=o.match.distance)}}return Pc({rect:a,continuous:s})}function Pc({rect:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+Fc?t.match:e.match:e.match??t.match}function Bc({layer:e,cursor:t,aspectRatio:n,warmStarts:r}){switch(e.kind){case"buckets":{const a=Ic(e,t,n);return a?{kind:"buckets",match:a}:null}case"rects":{const a=Ec(e,t,n);return a?{kind:"rects",match:a}:null}case"points":{const a=r.get(e.layerId)??null,s=rc(e,t,n,a);return s?{kind:"points",match:s}:null}}}const Uc=1,ae={primary:null,group:[],related:new Map};class Yc{constructor(t){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=Uc,this.warmStarts=new Map,this.cachedState=ae,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.layerIndexes=t.layers.map(n=>Ut(n,t.coordSystem,this.aspectRatio)),this.layerRefs=t.layers.map(n=>Yt(n,t.coordSystem)),this.nonInteractiveLayerIds=Gt(t.layers)}update(t){const n=new Map;for(let s=0;s<this.layerIndexes.length;s+=1){const i=this.layerIndexes[s],o=this.layerRefs[s];!i||!o||n.set(i.layerId,{index:i,ref:o})}const r=[],a=[];for(const s of t.layers){const i=n.get(s.id),o=Yt(s,t.coordSystem);if(i!==void 0&&Gc(i.ref,o)){r.push(i.index),a.push(i.ref);continue}this.warmStarts.delete(s.id),r.push(Ut(s,t.coordSystem,this.aspectRatio)),a.push(o)}for(const s of this.warmStarts.keys())t.layers.some(i=>i.id===s)||this.warmStarts.delete(s);this.layerIndexes=r,this.layerRefs=a,this.nonInteractiveLayerIds=Gt(t.layers),this.invalidateCache()}setViewport(t){this.aspectRatio=t.width/t.height;for(const n of this.layerIndexes)n.kind==="points"&&Xn(n,this.aspectRatio)}query(t){if(this.layerIndexes.length===0)return ae;const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(c=>!this.nonInteractiveLayerIds.has(c.layerId)),r=Oc({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,cursor:t});if(!r)return this.invalidateCache(),ae;const a=r.match.hit;this.warmStarts.set(a.layerId,a.pointIndex);const s=`${a.layerId}:${a.pointIndex}`;if(this.cachedKey===s)return this.cachedState;const{group:i,related:o}=sc(r,n);return this.cachedKey=s,this.cachedState={primary:a,group:i,related:o},this.cachedState}invalidateCache(){this.cachedKey=null,this.cachedState=ae}}function Yt(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Gt(e){const t=new Set;for(const n of e)n.interactive||t.add(n.id);return t}function Gc(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}const G=(e,t,n)=>{const r=M(t[n]);return a=>{if(!m(r))return null;const s=a[r];if(s===void 0)return null;switch(e.getType(r)){case"numeric":return tn(s)?s:null;case"categorical":return en(s)?s:null;case"temporal":return Z(s)?s:null;default:return null}}},zc=(e,t)=>G(e,t,"x"),Jn=(e,t)=>G(e,t,"y"),$c=(e,t)=>G(e,t,"label"),Zn=(e,t)=>G(e,t,"color"),Wc=(e,t)=>G(e,t,"size"),Hc=(e,t)=>G(e,t,"alpha"),Kc=(e,t)=>G(e,t,"group"),jc=(e,t)=>G(e,t,"strokeWidth");function er(e){return e[j.color]}function qc(e){return e[j.alpha]}function Xc(e){return e[j.size]}function Qc(e){return e[j.strokeWidth]}function ut(e,t){return e.axes.find(n=>n.scaleAestheticKey===t)??null}function Jc(e,t){return e.legends.find(n=>n.aesthetics.includes(t))??null}const Zc=({compiled:e,hover:t,formattingLocale:n})=>{const{primary:r}=t;if(r===null)return null;const a=n??e.config.parsingLocale;return{header:el({compiled:e,primary:r,locale:a,numberFormat:e.config.numberFormat}),rows:tl({compiled:e,hover:t,locale:a,numberFormat:e.config.numberFormat})}};function el({compiled:e,primary:t,locale:n,numberFormat:r}){if(e.coordSystem.type!=="cartesian")return null;const a=e.coordSystem.mainAxis,s=ut(e.guides,a);if(!s)return null;const i=e.layers.find(p=>p.id===t.layerId);if(!i)return null;const o=M(i.mapping[a]);if(!m(o))return null;const c=t.observation[o];return m(c)?Ne({valueFormat:s.valueFormat,locale:n,numberFormat:r})(c):null}function tl({compiled:e,hover:t,locale:n,numberFormat:r}){const a=[],s=e.scales.color??null,i=sl({compiled:e,locale:n,numberFormat:r});for(const o of e.layers){const c=nl(o,t);if(c.length===0)continue;const l=Zn(o.data,o.mapping),p=rl(c,o,s,l),d=al({compiled:e,layer:o,locale:n,numberFormat:r}),y=il(e,o),f=Jn(o.data,o.mapping),h=o.mapping.color!==void 0,b=ol(o,e.coordSystem);for(const g of p){const x=h?l(g.observation):null,S=er(g.observation)??null,k=h&&x!==null?i(x):y,D=f(g.observation),ge=D===null?"":d(D);a.push({swatchColor:S,swatchShape:b,label:k,value:ge,isPrimary:g===t.primary,key:`${g.layerId}:${g.pointIndex}`})}}return a}function nl(e,t){const n=[];return t.primary!==null&&t.primary.layerId===e.id&&n.push(t.primary,...t.group),n.push(...t.related.get(e.id)??[]),n}function rl(e,t,n,r){if(n===null||t.mapping.color===void 0)return e;const a=new Map;return n.domain.forEach((s,i)=>{a.set($(s),i)}),e.map((s,i)=>{const o=r(s.observation),c=o===null?null:$(o),l=c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY;return{hit:s,originalIndex:i,rank:l}}).sort((s,i)=>s.rank===i.rank?s.originalIndex-i.originalIndex:s.rank-i.rank).map(s=>s.hit)}function al({compiled:e,layer:t,locale:n,numberFormat:r}){const a=ue(t.yScaleType),i=ut(e.guides,a)?.valueFormat??{type:"decimal"};return Ne({valueFormat:i,locale:n,numberFormat:r})}function sl({compiled:e,locale:t,numberFormat:n}){const a=Jc(e.guides,"color")?.valueFormat??{type:"text"};return Ne({valueFormat:a,locale:t,numberFormat:n})}function il(e,t){const n=ue(t.yScaleType);return ut(e.guides,n)?.label??""}function ol(e,t){switch(e.geom){case"bar":return t.type==="polar"?"slice":"square";case"line":return"line";case"area":return"area";case"point":return"circle";default:return"square"}}function cl(e){return{startAngle:e[u.xMin],endAngle:e[u.xMax]}}function ll(e){return{innerRadius:e[u.yMin],outerRadius:e[u.yMax]??e[u.y]}}function ul(e){return typeof e=="object"&&e!==null&&"type"in e}function dl(e,...t){let n={},r;const[a,...s]=t;m(a)&&!ul(a)?(n=a,r=s):r=t;const i={data:e,mapping:n,layers:[],scales:[],transforms:[],config:{}};return r.reduce((o,c)=>tr(o,c),i)}function pl(e,...t){return t.reduce((n,r)=>tr(n,r),e)}function tr(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:$t({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};default:{const n=t;throw new Error(`Unknown spec item type: ${n.type}`)}}}class ml{constructor(t={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.maxHistorySize=t.maxHistorySize??100}apply(t,n){return this.withReentrancyGuard(()=>{const r=t.apply(n);return r?(this.undoStack.push({command:t,revert:r.revert}),this.redoStack=[],this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.emit({type:"apply",command:t,spec:r.spec}),r.spec):n})}undo(t){return this.withReentrancyGuard(()=>{const n=this.undoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.redoStack.push({command:n.command,revert:r.revert}),this.emit({type:"undo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.undoStack.push(n),null)})}redo(t){return this.withReentrancyGuard(()=>{const n=this.redoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.undoStack.push({command:n.command,revert:r.revert}),this.emit({type:"redo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.redoStack.push(n),null)})}clear(){this.withReentrancyGuard(()=>{this.undoStack=[],this.redoStack=[],this.emit({type:"clear"})})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null}),this.cachedSnapshot}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}withReentrancyGuard(t){if(this.isEmitting)throw new Error("CommandStack: cannot call apply/undo/redo/clear from within a listener");this.isEmitting=!0;try{return t()}finally{this.isEmitting=!1}}emit(t){this.cachedSnapshot=null;for(const n of this.listeners)try{n(t)}catch(r){console.error("CommandStack listener error:",r)}}}function ye(e,t){return Object.entries(t).reduce((n,[r,a])=>{const s=e[r];return zt(a)&&zt(s)?n[r]=ye(s,a):a!==void 0&&(n[r]=a),n},{...e})}function zt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function he(e){return{id:e.id??crypto.randomUUID(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}class dt{constructor(t,n={}){this.type="set-appearance-background",this.params=t,this.metadata=he({...n,description:`Set background to ${t.background??"(none)"}`})}apply(t){const n=t.config.appearance.background,r=ye(t,{config:{appearance:{background:this.params.background}}}),a=new dt({background:n},this.metadata);return{spec:r,revert:a}}}class pt{constructor(t,n={}){this.type="set-content-visibility",this.params=t,this.metadata=he({...n,description:`Set content visibility to ${t.isVisible}`})}apply(t){const n=t.config.content.isVisible,r=ye(t,{config:{content:{isVisible:this.params.isVisible}}}),a=new pt({isVisible:n},this.metadata);return{spec:r,revert:a}}}class mt{constructor(t,n={}){this.type="set-grid-visibility",this.params=t,this.metadata=he({...n,description:`Set grid visibility to x=${t.xIsVisible}, y=${t.yIsVisible}`})}apply(t){const n=t.config.axes.x.grid.isVisible,r=t.config.axes.y.grid.isVisible,a=ye(t,{config:{axes:{x:{grid:{isVisible:this.params.xIsVisible}},y:{grid:{isVisible:this.params.yIsVisible}}}}}),s=new mt({xIsVisible:n,yIsVisible:r},this.metadata);return{spec:a,revert:s}}}class ft{constructor(t,n={}){this.type="set-legend-position",this.params=t,this.metadata=he({...n,description:`Set legend position to ${t.position}`})}apply(t){const n=t.config.legend.position,r=ye(t,{config:{legend:{position:this.params.position}}}),a=new ft({position:n},this.metadata);return{spec:r,revert:a}}}class yt{constructor(t,n={}){this.type="set-data",this.params=t,this.metadata=he({...n,description:"Set dataset"})}apply(t){const n=t.data,r=fl(this.params.data),a={...t,data:r},s=new yt({data:n},this.metadata);return{spec:a,revert:s}}}const fl=e=>{if(e instanceof w)return e;const t=e._metadata?.parsingLocale??me;return Ln(e,t).dataset},nr=500,rr="normal",ar={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},sr=e=>typeof e!="string"?e??nr:ar[e],yl="\0";class hl{constructor(t){this.inner=t,this.cache=new Map}measureText(t,n){const r=this.getCacheKey(t,n),a=this.cache.get(r);if(a)return a;const s=this.inner.measureText(t,n);return this.cache.set(r,s),s}getCacheKey(t,n){return[n.family,n.size,sr(n.weight),n.style??rr,t].join(yl)}}const gl={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56},bl=.55,xl=1.05,Ml=.84,Sl=.21;class Tl{measureText(t,n){let r=0;for(const o of t)r+=(gl[o]??bl)*n.size;sr(n.weight)>=ar.semiBold&&(r*=xl);const s=Ml*n.size,i=Sl*n.size;return{width:r,height:s+i,ascent:s,descent:i}}}exports.CachedTextMeasurer=hl;exports.CommandStackManager=ml;exports.Compiler=Bn;exports.DEFAULT_COLOR_PALETTE=Ht;exports.DEFAULT_FONT_STYLE=rr;exports.DEFAULT_FONT_WEIGHT=nr;exports.DEFAULT_LOCALE=me;exports.DEFAULT_PALETTE_NAME=Kt;exports.Dataset=w;exports.GROUP_VARIABLES=V;exports.HeuristicTextMeasurer=Tl;exports.HoverEngine=Yc;exports.LAYOUT_PADDING=jn;exports.LayoutCompiler=qo;exports.POSITION_VARIABLES=u;exports.RESTING_HOVER_STATE=ae;exports.SetAppearanceBackgroundCommand=dt;exports.SetContentVisibilityCommand=pt;exports.SetDataCommand=yt;exports.SetGridVisibilityCommand=mt;exports.SetLegendPositionCommand=ft;exports.SpecResolver=On;exports.VISUAL_VARIABLES=j;exports.buildTooltipContent=Zc;exports.compile=zi;exports.config=kn;exports.coord=E;exports.createAlphaValueReader=Hc;exports.createColorValueReader=Zn;exports.createGroupValueReader=Kc;exports.createLabelValueReader=$c;exports.createSizeValueReader=Wc;exports.createSpec=dl;exports.createStrokeWidthValueReader=jc;exports.createXValueReader=zc;exports.createYValueReader=Jn;exports.formatLegends=Zo;exports.geom=_;exports.getAlpha=qc;exports.getAngleExtent=cl;exports.getColor=er;exports.getCrossAxisCoordinate=Re;exports.getGroup=cn;exports.getMainAxisCoordinate=ce;exports.getRadiusExtent=ll;exports.getSize=Xc;exports.getStrokeWidth=Qc;exports.getX=ia;exports.getXMax=ca;exports.getXMin=oa;exports.getY=je;exports.getYMax=qe;exports.getYMin=ln;exports.isCartesian=Jo;exports.isDefined=m;exports.isLayerOf=$i;exports.isStackedPosition=H;exports.mapping=Vr;exports.pipe=pl;exports.prefixInternalVariable=A;exports.scale=z;exports.transform=ie;
|
|
3
|
+
${n}`),this.issues=t,this.name="SpecValidationError"}}class Da{constructor(t,n,r,a,s,i){this.transformCompiler=t,this.statCompiler=n,this.groupCompiler=r,this.geomCompiler=a,this.positionAdjusterCompiler=s,this.layerValidator=i}compile(t){const n=this.prepareLayers(t);return this.validateLayers(n),n.map(({layer:r,data:a,effectiveMapping:s})=>this.compileLayer(r,a,s))}prepareLayers(t){return t.layers.map(n=>({layer:n,data:this.transformCompiler.compile(t.data,n.transforms),effectiveMapping:{...t.mapping,...n.mapping}}))}validateLayers(t){const n=[];for(const{layer:r,data:a,effectiveMapping:s}of t)n.push(...this.layerValidator.validate({layerId:r.id,geom:r.geom,stat:r.stat,effectiveMapping:s,data:a}));if(n.length>0)throw new yn(n)}compileLayer(t,n,r){return{...de({data:n,mapping:r}).pipe(({data:s,mapping:i})=>{const o=this.statCompiler.compute(t.stat,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>({data:this.groupCompiler.compute({data:s,mapping:i}).data,mapping:i})).pipe(({data:s,mapping:i})=>{const o=this.geomCompiler.compile(t.geom,{data:s,mapping:i,params:t.params});return{data:o.data,mapping:{...i,...o.mapping}}}).pipe(({data:s,mapping:i})=>{const o=this.positionAdjusterCompiler.adjust(t.position,{data:s,mapping:i});return{data:o.data,mapping:{...i,...o.mapping}}}).result(),id:t.id,geom:t.geom,position:t.position,yScaleType:t.yScaleType,params:t.params,interactive:t.interactive}}}class Ca{constructor(t,n){this.geomRegistry=t,this.statRegistry=n}validate(t){return[...this.validateRequiredAesthetics(t),...this.validateVariableExistence(t)]}validateRequiredAesthetics({layerId:t,geom:n,stat:r,effectiveMapping:a}){const s=[],{requiredAesthetics:i}=this.geomRegistry.get(n),{computedVariables:o}=this.statRegistry.get(r);for(const c of i)o.has(c)||m(a[c])||s.push({code:"MISSING_AESTHETIC",message:`Layer '${t}': geom '${n}' requires aesthetic '${c}'`,layerId:t,aesthetic:c});return s}validateVariableExistence({layerId:t,stat:n,effectiveMapping:r,data:a}){const s=[],{computedVariables:i}=this.statRegistry.get(n);for(const[o,c]of Object.entries(r)){if(i.has(o))continue;const l=S(c);l!==null&&(a.hasVariable(l)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${t}': aesthetic '${o}' references variable '${l}' which does not exist in the dataset`,layerId:t,aesthetic:o}))}return s}}class Ra{constructor(t){this.registry=t}adjust(t,n){return this.registry.get(t).adjust(n)}}class Re{}class Na extends Re{constructor(){super(...arguments),this.type="dodge"}adjust({data:t,mapping:n}){if(!S(n.x))return{data:t,mapping:{}};const a=t.getValues(v.group,{type:"categorical",distinct:!0,skipNulls:!0});if(a.length===0)return{data:t,mapping:{}};const s=t.size(),i=t.getValues(v.group,{type:"categorical"}),o=en/2,c=a.length>1?Cr:0,l=U.scaleBand().domain(a.map(String)).range([-o,o]).paddingInner(c).paddingOuter(0),d=l.bandwidth(),p=new Array(s).fill(null),f=new Array(s).fill(null);for(let g=0;g<s;g++){const x=i[g];if(!m(x))continue;const h=l(String(x));m(h)&&(p[g]=h,f[g]=h+d)}return{data:t.addVariable(u.xMin,"numeric",p).addVariable(u.xMax,"numeric",f),mapping:{}}}}const wt=A("__ungrouped__"),fn=(e,t)=>{const n=S(t.x),r=S(t.y);if(!n||!r)return null;const a=e.getValues(v.group,{type:"categorical",distinct:!0,skipNulls:!0}),s=a.length===0,i=s?[wt]:a,o=e.getValues(n),c=e.getValues(r,{type:"numeric"}),l=e.getValues(v.group,{type:"categorical"}),d=e.size(),p=new Map;for(let f=0;f<d;f++){const y=o[f]??null,g=l[f],x=s?wt:g;if(!m(x))continue;let h=p.get(y);h||(h=new Map,p.set(y,h)),h.set(x,f)}return{yValues:c,observationIndexByXAndGroup:p,uniqueGroupKeys:i,observationCount:d}};class Fa extends Re{constructor(){super(...arguments),this.type="fill"}adjust({data:t,mapping:n}){const r=fn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,p]of s){let f=0,y=0;for(const h of i){const b=p.get(h);if(b===void 0)continue;const M=a[b];M!=null&&(M>=0?f+=M:y-=M)}let g=0,x=0;for(const h of i){const b=p.get(h);if(b===void 0)continue;const M=a[b];if(M===void 0)continue;if(M===null){l[b]=null,c[b]=null;continue}const k=M>=0?f:y;if(k===0){l[b]=0,c[b]=0;continue}const R=M/k;M>=0?(l[b]=g,c[b]=g+=R):(c[b]=x,l[b]=x+=R)}}return{data:t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c),mapping:{}}}}class Oa extends Re{constructor(){super(...arguments),this.type="identity"}adjust({data:t}){return{data:t,mapping:{}}}}class Pa extends Re{constructor(){super(...arguments),this.type="stack"}adjust({data:t,mapping:n}){const r=fn(t,n);if(r===null)return{data:t,mapping:{}};const{yValues:a,observationIndexByXAndGroup:s,uniqueGroupKeys:i,observationCount:o}=r,c=[...a],l=new Array(o).fill(0);for(const[,f]of s){let y=0,g=0;for(const x of i){const h=f.get(x);if(h===void 0)continue;const b=a[h];if(b!==void 0){if(b===null){l[h]=null,c[h]=null;continue}b>=0?(l[h]=y,c[h]=y+=b):(c[h]=g,l[h]=g+=b)}}}let d=t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",c);const p=S(n.y);return p!==null&&(d=d.addVariable(p,"numeric",c)),{data:d,mapping:{}}}}class Ba extends j{constructor(){super("position"),this.register("identity",new Oa),this.register("stack",new Pa),this.register("fill",new Fa),this.register("dodge",new Na)}}class Ua{map({data:t,layer:n,getPositionScale:r}){const a=S(n.mapping.x),s=r("x");if(!a||!s)return t;const o=t.getValues(a).map(c=>m(c)?s.map(c):null);return t.addVariable(u.x,"numeric",o)}}class Ya{map({data:t,getPositionScale:n}){const r=n("x");if(!r?.bandwidth||!t.hasVariable(u.x)||!t.hasVariable(u.xMin)||!t.hasVariable(u.xMax))return t;const a=t.getValues(u.x,{type:"numeric"}),s=t.getValues(u.xMin,{type:"numeric"}),i=t.getValues(u.xMax,{type:"numeric"}),o=t.size(),c=new Array(o),l=new Array(o);for(let d=0;d<o;d++){const p=a[d],f=s[d],y=i[d];m(p)&&m(f)&&m(y)?(c[d]=p+f*r.bandwidth,l[d]=p+y*r.bandwidth):(c[d]=null,l[d]=null)}return t.addVariable(u.xMin,"numeric",c).addVariable(u.xMax,"numeric",l)}}class Ga{map({data:t,layer:n,getPositionScale:r}){const a=S(n.mapping.y),s=pe(n.yScaleType),i=r(s);if(!a||!i)return t;const c=t.getValues(a).map(l=>m(l)?i.map(l):null);return t.addVariable(u.y,"numeric",c)}}class za{map({data:t,layer:n,getPositionScale:r}){const a=pe(n.yScaleType),s=r(a);if(!s||!t.hasVariable(u.yMin)||!t.hasVariable(u.yMax))return t;const i=t.getValues(u.yMin,{type:"numeric"}),o=t.getValues(u.yMax,{type:"numeric"}),c=t.size(),l=new Array(c),d=new Array(c);for(let p=0;p<c;p++){const f=i[p],y=o[p];m(f)&&m(y)?(l[p]=s.map(f),d[p]=s.map(y)):(l[p]=null,d[p]=null)}return t.addVariable(u.yMin,"numeric",l).addVariable(u.yMax,"numeric",d)}}const $a=[new Ua,new Ga,new Ya,new za];function Wa(e,t){const n=e[t];return n?.kind==="position"?n:null}class Ka{constructor(t=$a){this.mappers=t}compile(t){const n=r=>Wa(t.scales,r);return t.layers.map(r=>this.compileLayer(r,n))}compileLayer(t,n){let r=t.data;for(const a of this.mappers)r=a.map({data:r,layer:t,getPositionScale:n});return{...t,data:r}}}class Ha{constructor(t){this.registry=t}compile(t){this.validateScaleTypeCompatibility(t);const n=new Map;for(const s of t.scales)n.set(s.scaledAesthetic,s);const r=this.collectValues(t.layers,n),a={};for(const[s,i]of n){const o=r.get(s)??[],c=this.registry.get(i.scaleType);a[s]=c.compile(i,o)}return a}validateScaleTypeCompatibility(t){const n=[];for(const r of t.scales){const{compatibleDataTypes:a}=this.registry.get(r.scaleType),s=F(r.scaledAesthetic),i=t.layers.find(l=>m(l.mapping[s]));if(!i)continue;const o=S(i.mapping[s]);if(!m(o)||!i.data.hasVariable(o))continue;const c=i.data.getType(o);if(a.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${o}' (${c})`,aesthetic:s}),r.scaledAesthetic==="lineType"&&c!=="categorical"){const l=c==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";n.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${o}'. ${l}`,aesthetic:s})}}if(n.length>0)throw new yn(n)}collectValues(t,n){const r=new Map;for(const a of t)for(const[s,i]of Object.entries(a.mapping)){const o=s,c=o==="y"?pe(a.yScaleType):o;if(!Ur(c)||!n.has(c))continue;const l=this.resolveVariables(o,i,a.data);this.collectFromVariables(a.data,l,c,r)}return r}resolveVariables(t,n,r){if(t==="y"&&this.hasPositionAdjustedY(r))return[u.yMin,u.yMax];const a=S(n);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(t){return t.hasVariable(u.yMin)&&t.hasVariable(u.yMax)}collectFromVariables(t,n,r,a){if(n.length===0)return;let s=[];for(const o of n)s=s.concat(t.getValues(o));const i=a.get(r);a.set(r,i?i.concat(s):s)}}class ye{createPositionScale(t,n){return{kind:"position",aesthetic:F(t.scaledAesthetic),spec:t,...n}}createVisualScale(t,n){return{kind:"visual",aesthetic:F(t.scaledAesthetic),spec:t,...n}}}class ja extends ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(t,n){if(t.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const r=Ce(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){let r=1/0,a=-1/0;for(const s of t)typeof s=="number"&&(s<r&&(r=s),s>a&&(a=s));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),a<0&&(a=0)),[r,a])}createD3Scale(t,n,r){let a=[r.domainMin??t[0],r.domainMax??t[1]];const s=r.transform==="log"&&qa(a),i=s?U.scaleLog():r.transform==="sqrt"?U.scaleSqrt():U.scaleLinear();return r.nice&&!s&&(a=i.copy().domain(a).nice().domain()),i.domain([r.domainMin??a[0],r.domainMax??a[1]]).range(n).clamp(r.clamp)}buildPositionScale(t,n){const r=n.reverse?[1,0]:[0,1],a=this.createD3Scale(t,r,n);return this.createPositionScale(n,{map:a,domain:a.domain(),bandwidth:null,generateTicks:s=>s&&"count"in s?a.ticks(s.count):a.ticks()})}buildVisualScale(t,n){const r=n.range??[0,1],a=n.reverse?[r[1],r[0]]:r,s=this.createD3Scale(t,a,n);return this.createVisualScale(n,{map:s,domain:s.domain(),generateTicks:i=>i&&"count"in i?s.ticks(i.count):s.ticks()})}}const qa=e=>{const[t,n]=e;return t>0&&n>0||t<0&&n<0};class Xa extends ye{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(t,n){if(t.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const r=Ce(t.scaledAesthetic),a=this.computeDataDomain(n);if(!r)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(a,t,this.collectInputDates(n))}collectInputDates(t){const n=new Set,r=[];for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();n.has(s)||(n.add(s),r.push(a))}return r.sort((a,s)=>a.getTime()-s.getTime()),r}computeDataDomain(t){let n=1/0,r=-1/0;for(const a of t){if(!(a instanceof Date))continue;const s=a.getTime();s<n&&(n=s),s>r&&(r=s)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(t,n,r){const a=Qa(t)?t:[],s=U.scaleUtc().domain(a).range(n).clamp(r.clamp);if(r.nice&&s.nice(),m(r.domainMin)||m(r.domainMax)){const[i,o]=s.domain();i!==void 0&&o!==void 0&&s.domain([r.domainMin??i,r.domainMax??o])}return s}buildScale(t,n,r){const a=n.reverse?[1,0]:[0,1],s=this.createD3Scale(t,a,n),[i,o]=s.domain(),c=i&&o?r.filter(l=>l>=i&&l<=o):[];return this.createPositionScale(n,{map:s,domain:s.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&o?$r(i,o,l.interval):[]:s.ticks(l?.count)})}}const Qa=e=>e.length===2&&Z(e[0])&&Z(e[1]),Q={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},Vt={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},Te={domainMin:null,domainMax:null,nice:!1,reverse:!1},ae={range:null,sort:"none",domain:null,padding:.1},Ja={palette:"default"};class Za extends ye{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(t,n){if(t.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const r=Ce(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){if(n.domain!==null&&n.domain.length>0)return[...n.domain];const r=new Set,a=[];for(const s of t)r.has(s)||(r.add(s),a.push(s));return n.sort==="ascending"?a.sort((s,i)=>String(s).localeCompare(String(i))):n.sort==="descending"&&a.sort((s,i)=>String(i).localeCompare(String(s))),a}buildPositionScale(t,n){const r=t.map(String),a=n.padding??ae.padding,s=U.scaleBand().domain(r).range([0,1]).paddingInner(a).paddingOuter(a/2),i=s.bandwidth()/2;return this.createPositionScale(n,{map:o=>(s(String(o))??0)+i,domain:t,bandwidth:s.bandwidth(),generateTicks:()=>[...t]})}buildVisualScale(t,n){const r=t.map(String),a=n.range&&n.range.length>0?U.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:s=>{const i=String(s);return a?a(i):i},domain:t,generateTicks:()=>t})}}class es extends ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(t){if(t.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:F(t.scaledAesthetic),spec:t,map:n=>n,domain:[],generateTicks:()=>[]}}}class ts extends ye{constructor(t){super(),this.paletteRegistry=t,this.compatibleDataTypes=["categorical","temporal"]}compile(t,n){if(t.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const r=this.computeDomain(n),a=this.paletteRegistry.get(t.palette),s=U.scaleOrdinal().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(t,{map:i=>s(String(i)),domain:r,generateTicks:()=>r})}computeDomain(t){const n=new Set,r=[];for(const a of t)n.has(a)||(n.add(a),r.push(a));return r}}class ns extends j{constructor(t){super("scale"),this.paletteRegistry=t,this.register("continuous",new ja),this.register("discrete",new Za),this.register("datetime",new Xa),this.register("identity",new es),this.register("palette",new ts(this.paletteRegistry))}}const rs=new Set(["count","sum","mean","median"]);function hn(e,t){return rs.has(e)?"numeric":t}const as="key",ss="value",is={eq:(e,t)=>e[t.__variableName]===t.__value,neq:(e,t)=>e[t.__variableName]!==t.__value,gt:(e,t)=>e[t.__variableName]>t.__value,gte:(e,t)=>e[t.__variableName]>=t.__value,lt:(e,t)=>e[t.__variableName]<t.__value,lte:(e,t)=>e[t.__variableName]<=t.__value};class w{constructor(t={}){const{table:n,variableMetadata:r}=this.parseVariableMap(t);this.table=n,this.variableMetadata=r}static merge(...t){if(t.length===0)return w.fromTrusted(P.table({}),{});const n=t.map(o=>o.table),[r,...a]=n,s=a.reduce((o,c)=>o.concat(c),r),i=t.reduce((o,c)=>({...o,...c.variableMetadata}),{});return w.fromTrusted(s,i)}static fromTrusted(t,n){const r=Object.create(w.prototype);return r.table=t,r.variableMetadata=n,r}size(){return this.table.numRows()}getVariableNames(){return this.table.columnNames()}hasVariable(t){return this.table.column(t)!==void 0}toData(){const n=this.getVariableNames().map(a=>({key:a})),r=Array.from({length:this.size()},(a,s)=>this.table.object(s));return{columns:n,rows:r}}addVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},s=this.normalizeRawValues(n,r),i=this.table.assign(P.table({[t]:s}));return w.fromTrusted(i,a)}addConstantVariable(t,n,r){const a={...this.variableMetadata,[t]:{type:n}},[s]=this.normalizeRawValues(n,[r]),i=this.table.assign(P.table({[t]:Array(this.size()).fill(s)}));return w.fromTrusted(i,a)}deriveVariable(t,n,r){const a=Array.from({length:this.size()},(s,i)=>r(this.table.object(i)));return this.addVariable(t,n,a)}renameVariable(t,n){const r=this.variableMetadata[t];if(!r)throw new Error(`Variable ${t} not defined`);const a=this.table.rename({[t]:n}),{[t]:s,...i}=this.variableMetadata,o={...i,[n]:r};return w.fromTrusted(a,o)}selectVariables(...t){const n=this.table.select(...t),r=Object.fromEntries(Object.entries(this.variableMetadata).filter(([a])=>t.includes(a)));return w.fromTrusted(n,r)}getType(t){const n=this.variableMetadata[t];if(!n)throw new Error(`Variable ${t} not defined`);return n.type}groupVariableNamesByType(){const t={numeric:[],categorical:[],temporal:[]};for(const[n,{type:r}]of Object.entries(this.variableMetadata))t[r].push(n);return t}getValues(t,n){if(!this.hasVariable(t))throw new Error(`Variable '${t}' not defined`);const r=this.getType(t);if(n?.type!==void 0&&r!==n.type)throw new Error(`Variable '${t}' has type '${r}', expected '${n.type}'`);let a=this.table.array(t);return n?.distinct&&(a=this.getDistinctValues(r,a)),n?.skipNulls&&(a=this.skipNulls(a)),a}filter(t,n,r){const a=is[n],s=this.table.params({__variableName:t,__value:r}).filter(a);return w.fromTrusted(s,this.variableMetadata)}orderBy(t,n="asc"){const r=this.table.orderby(n==="asc"?t:P.desc(t));return w.fromTrusted(r,this.variableMetadata)}getFirst(){return this.size()===0?null:this.table.object(0)}getLast(){return this.size()===0?null:this.table.object(this.size()-1)}findLast(t){for(let n=this.size()-1;n>=0;n--){const r=this.table.object(n);if(t(r))return r}return null}groupBy(...t){const n=this.table.groupby(...t);return new os(t,n,this.variableMetadata)}rollup(t){const n=this.table.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,P.op[s.aggregation](s.variableName)]))),r={};for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=hn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}reshapeFromWideToLong({keep:t,reshape:n,keyName:r=as,valueName:a=ss}={}){const{numeric:s,categorical:i,temporal:o}=this.groupVariableNamesByType(),c=t??[...i,...o],l=n??s.filter(g=>!c.includes(g));if(c.includes(r)||c.includes(a))throw new Error(`The variables to keep includes the variables '${r}' or '${a}' to create the key and value variables`);if(l.length===0){const g={};for(const x of c){const h=this.variableMetadata[x];h&&(g[x]={type:h.type,values:[]})}return g[r]={type:"categorical",values:[]},g[a]={type:"numeric",values:[]},new w(g)}if(l.filter(g=>this.variableMetadata[g]?.type!=="numeric").length>0)throw new Error("Only numeric variables can be reshaped");const f=this.table.select([...c,...l]).fold(l,{as:[r,a]}),y={};for(const g of c){const x=this.variableMetadata[g];x&&(y[g]=x)}return y[r]={type:"categorical"},y[a]={type:"numeric"},w.fromTrusted(f,y)}print(){console.table(this.variableMetadata),this.table.print()}[Symbol.iterator](){return this.table[Symbol.iterator]()}parseVariableMap(t){const n={},r={};for(const[s,{type:i,values:o}]of Object.entries(t))n[s]=o,r[s]={type:i};return{table:P.table(n),variableMetadata:r}}normalizeRawValues(t,n){switch(t){case"numeric":return n.map(r=>typeof r!="number"||Number.isNaN(r)?null:r);case"categorical":return n.map(r=>typeof r!="string"?null:r);case"temporal":return n.map(r=>!(r instanceof Date)||!T.isValid(r)?null:r);default:{const r=t;throw new Error(`Cannot normalize raw value of unknown type: ${r}`)}}}skipNulls(t){return t.filter(n=>n!==null)}getDistinctValues(t,n){const r=t==="temporal",a=new Set,s=[];for(const i of n){const o=r&&i instanceof Date?i.getTime():i;a.has(o)||(a.add(o),s.push(i))}return s}}class os{constructor(t,n,r){this.groupedBy=t,this.grouped=n,this.variableMetadata=r}forEach(t){const n=this.grouped.partitions(),r=this.grouped.columnNames(),a=this.groupedBy.map(i=>this.grouped.column(i)).filter(i=>i!==void 0);let s=0;for(const i of n){const o=i[0];if(o===void 0)continue;const c=this.getStableKey(a,o),l=Object.fromEntries(r.map(p=>{const f=this.grouped.column(p);return[p,i.map(y=>f?.get(y))]})),d=P.table(l);t(w.fromTrusted(d,this.variableMetadata),c,s++)}}rollup(t){const n=this.grouped.rollup(Object.fromEntries(Object.entries(t).map(([a,s])=>[a,P.op[s.aggregation](s.variableName)]))),r=Object.fromEntries(this.groupedBy.map(a=>[a,{type:this.variableMetadata[a]?.type??"categorical"}]));for(const[a,{variableName:s,aggregation:i}]of Object.entries(t)){const o=this.variableMetadata[s]?.type??"numeric",c=hn(i,o);r[a]={type:c}}return w.fromTrusted(n,r)}getStableKey(t,n){return W(t.map(r=>r.get(n)))}}const oe={k:1e3,m:1e6,b:1e9,t:1e12},nt=["k","m","b","t"],cs=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${nt.join("|")})?$`,"i"),ls=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,K=e=>e===null||e instanceof Date||Array.isArray(e)||typeof e=="boolean"?!1:typeof e=="string"?cs.test(e)&&!Number.isNaN(Number(e.replace(new RegExp(`[,${nt.join("")}]`,"gi"),""))):!Number.isNaN(Number(e)),gn=e=>K(e)?!0:typeof e=="string"?ls.test(e):!1,bn={$:"usd","£":"gbp","€":"eur","¥":"jpy","₹":"inr","₱":"php",P:"php","₩":"krw","₪":"ils","₫":"vnd","₽":"rub","฿":"thb",R$:"brl",Rp:"idr",RM:"myr","₦":"ngn",zł:"pln","₺":"try",kr:"dkk",Fr:"chf",R:"zar","د.إ":"aed","﷼":"sar",Ch$:"clp",NT$:"twd",HK$:"hkd",S$:"sgd",A$:"aud",C$:"cad",NZ$:"nzd",MX$:"mxn"},xn=e=>{if(typeof e=="string"){const t=Mn(e);return t.length?K(t):!1}return K(e)},us=e=>{const t=Sn(e),n=t?bn[t]:void 0;if(!n)throw new Error("Could not get currency ISO");return n},Mn=e=>{const t=Sn(e);let n=e;if(t){const r=e.indexOf(t);r===0?n=e.slice(t.length):r===e.length-t.length?n=e.slice(0,e.length-t.length):e[0]==="-"&&r===1&&(n=`-${e.slice(t.length+1)}`)}return K(n)?n.split(",").join(""):""},Sn=e=>Object.keys(bn).sort((n,r)=>r.length-n.length).find(n=>e.includes(n)),fe="en-GB";class Tn{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(t){this.previousYear===null?this.previousYear=t.getUTCFullYear():this.previousDate!==null&&T.isBefore(new Date(this.currentYear,t.getUTCMonth(),t.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(t.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const ds=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,ps=/^\s*(19\d{2}|2[01]\d{2})\s*$/,ms=[[/\bJan\b/i,"January"],[/\bFeb\b/i,"February"],[/\bMar\b/i,"March"],[/\bApr\b/i,"April"],[/\bJun\b/i,"June"],[/\bJul\b/i,"July"],[/\bAug\b/i,"August"],[/\bSept?\b/i,"September"],[/\bOct\b/i,"October"],[/\bNov\b/i,"November"],[/\bDec\b/i,"December"]],ys={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},An=["/","-","."," "],vt=[["d","M","yy"],["d","MM","yy"],["d","MMMM","yy"],["dd","M","yy"],["dd","MM","yy"],["dd","MMMM","yy"],["do","MMMM","yy"],["d","M","yyyy"],["d","MM","yyyy"],["d","MMMM","yyyy"],["dd","M","yyyy"],["dd","MM","yyyy"],["dd","MMMM","yyyy"],["do","MMMM","yyyy"]],It=[["M","d","yy"],["M","dd","yy"],["MM","d","yy"],["MM","dd","yy"],["MMMM","d","yy"],["MMMM","dd","yy"],["MMMM","do","yy"],["M","d","yyyy"],["M","dd","yyyy"],["MM","d","yyyy"],["MM","dd","yyyy"],["MMMM","d","yyyy"],["MMMM","dd","yyyy"],["MMMM","do","yyyy"]],Et=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],wn=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],fs=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],Vn=1900,vn=2199,hs=3,gs=6,bs=5,xs=1,Ms=28,Ss=/\s*[–—]\s*|\s-\s/,Ts=e=>typeof e=="number"?Number.isNaN(e)?!1:e>=Vn&&e<=vn:typeof e=="string"?ps.test(e):!1,In=(e,t)=>{const n=le(e);return K(n)?Vs(n):typeof n=="string"?!!En(n)||rt(n)&&T.isValid(new Date(n)):T.isValid(n)},le=e=>{if(typeof e!="string")return e;let t=e;for(const[n,r]of ms)t=t.replace(n,r);return t},En=(e,t=fe)=>{const n=le(e);return rt(n)?{type:"datetime"}:_n(t).find(r=>!me(r)||r.type==="month"&&n.length<hs?!1:r.dateFormat&&T.isValid(T.parse(n,r.dateFormat,new Date)))},rt=e=>ds.test(e.trim()),As=(e,t=fe)=>{const[n,r]=e.split(Ss);if(!n||!r)return;const a=le(n).trim(),s=le(r).trim();return ws(t).find(i=>{if(!me(i)||!i.dateFormat)return!1;const o=T.parse(a,i.dateFormat,new Date),c=T.parse(s,i.dateFormat,new Date);if(!T.isValid(o)||!T.isValid(c))return!1;const l=new Tn,d=l.incrementYearIfNeeded(o),p=l.incrementYearIfNeeded(c),f=T.differenceInDays(p,d);return T.isWithinInterval(new Date(d.getFullYear(),xs,Ms),{start:d,end:p})&&f===bs?!0:f===gs})},Ln=e=>ys[e]==="MDY"?[...It,...vt,...Et]:[...vt,...It,...Et],_n=e=>{const t={date:Ln(e),year:[["yyyy"]],day_month:wn,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...fs,...Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>An.map(s=>({dateFormat:a.join(s),type:n}))))]},ws=e=>{const t={weekly_date_range:wn,weekly_date_range_with_year:Ln(e)};return Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>An.map(s=>({dateFormat:a.join(s),type:n}))))},Vs=e=>{const t=Number(e);if(!ee.isInteger(t))return!1;const n=new Date(t),r=new Date(t*1e3),a=s=>T.isValid(s)&&s.getFullYear()>=Vn&&s.getFullYear()<=vn;return a(n)||a(r)},vs=(e,t)=>{const n=typeof e=="string"?e.trim():e;if(K(n))return{type:"decimal"};const r=typeof n=="string"&&En(n,t);if(r)return r;const a=typeof n=="string"&&As(n,t);return a||(In(e)?{type:"date"}:gn(e)?{type:"percentage"}:xn(e)&&typeof e=="string"?{type:"currency",iso:us(e)}:{type:"text"})},Is=e=>{const t=Object.entries(e);return!t.length||!t.some(([,n])=>!he(n))},he=e=>typeof e=="string"&&e.trim()===""||e===void 0||e===null||e==="-",Es=/\s*[–—]\s*|\s-\s/,Ls=(e,t,n)=>{if(he(e))return null;switch(t.type){case"decimal":case"integer":case"duration":return kn(e);case"percentage":return _s(e);case"currency":return ks(e);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return Dn(e,t.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return Ds(e,t.dateFormat,n);case"text":return Cs(e);default:{const r=t;throw new Error(`Unhandled value format: ${r.type}`)}}},kn=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;let t=e.trim();if(!K(t))return null;let n=1;for(const r of nt)if(new RegExp(`${r}$`,"i").test(t)){n=oe[r],t=t.slice(0,-1);break}return Number(t.split(",").join(""))*n},_s=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();if(!gn(t))return null;const n=Number(t.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},ks=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();return xn(t)?kn(Mn(t)):null},Dn=(e,t,n)=>{if(e instanceof Date)return T.isValid(e)?e:null;const r=le(String(e).trim());if(r.length===0)return null;const a=new Date;if(t){const i=T.parse(r,t,a);return T.isValid(i)?Be(i):null}for(const i of _n(n)){if(!me(i)||!i.dateFormat)continue;const o=T.parse(r,i.dateFormat,a);if(T.isValid(o))return Be(o)}const s=new Date(r);return In(s)?rt(r)?s:Be(s):null},Ds=(e,t,n)=>{const r=String(e).trim().split(Es),[a,s]=[r[0]?.trim(),r[1]?.trim()];return!a||!s?null:Dn(a,t,n)},Cs=e=>String(e).trim(),Be=e=>new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())),Rs={type:"year",dateFormat:"yyyy"},Cn=(e,t)=>{const n={},r={},a=Os(e),s=Ns(e);for(const[i,o]of e.columns.entries()){const c=a.get(o.key);if(he(c))continue;const l=i===s?Rs:vs(c,t),d=Gr(l);r[o.key]={type:d,valueFormat:l,label:o.label},n[o.key]=Fs(o.key,e.rows,l,d,t)}return{dataset:new w(n),datasetMetadata:{columns:r}}},Ns=e=>{const t=Ps(e.rows,5);return e.columns.findIndex(n=>{const r=t.map(a=>a[n.key]).filter(a=>!he(a));return r.length>=2&&r.every(Ts)})},Fs=(e,t,n,r,a)=>{const s=new Tn,i=t.map(o=>{const c=Ls(o[e],n,a);return cn(n)&&c instanceof Date?s.incrementYearIfNeeded(c):c});return{type:r,values:i}},Os=e=>{const t=new Map,n=new Set(e.columns.map(r=>r.key));for(const r of e.rows){for(const a of n){const s=r[a];he(s)||(t.set(a,s),n.delete(a))}if(n.size===0)break}return t},Ps=(e,t)=>{const n=[];for(const r of e)if(Is(r)||n.push(r),n.length===t)return n;return n},Bs=e=>"data"in e&&e.data instanceof w,Us=e=>!("layers"in e);function Rn(e){return{type:"config",config:e}}function Ys(e){return Rn({legend:zs(e.legend),axes:$s(e.axes),headline:Ws(e.headlineNumbers),numberFormat:Ks(e.appearance),content:Hs(e.content),appearance:Gs(e.appearance)}).config}function Gs(e){if(e?.background)return{background:e.background}}function zs(e){if(e)return{position:e.position}}function Ue(e,t){return!e&&t===void 0?{}:{...e?.isHidden!==void 0?{isVisible:!e.isHidden}:void 0,...e?.label!==void 0?{label:e.label}:void 0,...e?.tickDisplayMode?{labels:{mode:e.tickDisplayMode}}:void 0,...t!==void 0?{grid:{isVisible:t}}:void 0}}function $s(e){if(e)return{x:Ue(e.x,e.showGridLines),y:Ue(e.y,e.showGridLines),...e.y2?{ySecondary:Ue(e.y2)}:void 0}}function Ws(e){if(e)return{show:e.show,compareWith:e.compareWith,size:e.size}}function Ks(e){if(e?.numberFormat)return{decimals:e.numberFormat.decimalPlaces,abbreviation:e.numberFormat.abbreviation}}function Hs(e){if(e)return{...!e.isTitleHidden&&e.title!==void 0?{title:e.title}:void 0,...!e.isSubtitleHidden&&e.subtitle!==void 0?{subtitle:e.subtitle}:void 0,...!e.isCaptionHidden&&e.caption!==void 0?{caption:e.caption}:void 0}}const E={cartesian:(e={})=>({type:"coord",coordType:"cartesian",params:e}),flip:(e={})=>({type:"coord",coordType:"flip",params:e}),polar:(e={})=>({type:"coord",coordType:"polar",params:e})};function js(e={}){return{type:"layer",geom:"point",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function qs(e={}){return{type:"layer",geom:"line",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Xs(e={}){return{type:"layer",geom:"area",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}function Qs(e={}){return{type:"layer",geom:"bar",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive}}const L={point:js,line:qs,area:Xs,bar:Qs},Ve={stat:"identity",position:"identity",params:{size:8}},Ye={stat:"identity",position:"identity",params:{lineWidth:"auto",interpolate:"linear",missingValues:"gap"}},Ge={stat:"identity",position:"stack",params:{lineWidth:"auto",interpolate:"linear",missingValues:"zero"}},ze={stat:"identity",position:"dodge",params:{}},Ne="primary";function V(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"continuous",transform:t.transform,reverse:t.reverse,nice:t.nice,zero:t.zero,clamp:t.clamp,domainMin:t.domainMin??null,domainMax:t.domainMax??null,range:t.range}}function ve(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"datetime",domainMin:t.domainMin??null,domainMax:t.domainMax??null,nice:t.nice,reverse:t.reverse,clamp:t.clamp}}function D(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"discrete",range:t.range,sort:t.sort,domain:t.domain??null,padding:t.padding}}function se(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"identity"}}function Ie(e,t){return{type:"scale",scaledAesthetic:e,scaleType:"inferred",options:t}}function Nn(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"palette",palette:t.palette}}const Y={x:Object.assign(e=>Ie("x",e),{continuous:e=>V("x",e),discrete:e=>D("x",e),datetime:e=>ve("x",e),log:e=>V("x",{...e,transform:"log"}),sqrt:e=>V("x",{...e,transform:"sqrt"})}),y:Object.assign(e=>Ie("y",e),{continuous:e=>V("y",e),discrete:e=>D("y",e),datetime:e=>ve("y",e),log:e=>V("y",{...e,transform:"log"}),sqrt:e=>V("y",{...e,transform:"sqrt"})}),ySecondary:Object.assign(e=>Ie("ySecondary",e),{continuous:e=>V("ySecondary",e),discrete:e=>D("ySecondary",e),datetime:e=>ve("ySecondary",e),log:e=>V("ySecondary",{...e,transform:"log"}),sqrt:e=>V("ySecondary",{...e,transform:"sqrt"})}),color:{continuous:e=>V("color",e),discrete:e=>D("color",e),palette:e=>Nn("color",e)},size:{continuous:e=>V("size",e),discrete:e=>D("size",e),identity:e=>se("size",e)},alpha:{continuous:e=>V("alpha",e),discrete:e=>D("alpha",e),identity:e=>se("alpha",e)},strokeWidth:{continuous:e=>V("strokeWidth",e),discrete:e=>D("strokeWidth",e),identity:e=>se("strokeWidth",e)},lineType:{discrete:e=>D("lineType",e),identity:e=>se("lineType",e)}};function Js(e={}){return{type:"transform",transformType:"reshape",options:e}}function Zs(e){return{type:"transform",transformType:"filter",options:e}}function ei(e){return{type:"transform",transformType:"sort",options:e}}function ti(e){return{type:"transform",transformType:"aggregate",options:e}}function ni(e){return{type:"transform",transformType:"constant",options:e}}const ce={reshape:Js,filter:Zs,sort:ei,aggregate:ti,constant:ni},N="key",B="value",Lt=A("lineSeriesLabel"),_t=A("barSeriesLabel"),kt=A("constantY"),Fn=e=>{if(m(e.color))return e;const t=S(e.y);return t===null?e:{...e,color:{value:t}}},at=e=>{const{numeric:t,categorical:n,temporal:r}=e.groupVariableNamesByType();return m(r[0])?r[0]:m(n[0])?n[0]:m(t[0])?t[0]:""},st=e=>{const t=at(e),{numeric:n}=e.groupVariableNamesByType(),r=n.filter(s=>s!==t);return r.length<=1?{dataset:e,mapping:{x:t,y:r[0]??""},seriesVariables:r}:{dataset:e.reshapeFromWideToLong({keep:[t],keyName:N,valueName:B}),mapping:{x:t,y:B,color:N},seriesVariables:r}},it=e=>{const t=e.appearance?.seriesStyles;if(!t||e.seriesVariables.length===0)return{mapping:{},scales:[]};if(!e.seriesVariables.some(a=>m(t[a]?.lineStyle)))return{mapping:{},scales:[]};if(e.seriesVariables.length===1){const a=e.seriesVariables[0];if(!a)return{mapping:{},scales:[]};const s=t[a]?.lineStyle;return s?{mapping:{lineType:{value:s}},scales:[]}:{mapping:{},scales:[]}}const r=e.seriesVariables.map(a=>t[a]?.lineStyle??"solid");return{mapping:{lineType:N},scales:[Y.lineType.discrete({domain:e.seriesVariables,range:r})]}},ri=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType(),a=r[0];if(!m(a))throw new Error("No first numeric variable found");const s=r.slice(1);return s.length===0?{dataset:e.addConstantVariable(kt,"categorical",""),mapping:{x:a,y:kt,label:t[0]}}:s.length===1?{dataset:e,mapping:{x:a,y:s[0]??"",label:t[0]}}:{dataset:e.reshapeFromWideToLong({keep:[a,...t,...n],keyName:N,valueName:B}),mapping:{x:a,y:B,label:t[0],color:N}}},ai=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType();let a,s;if(m(t[0])&&m(r[0]))a=t[0],s=r[0];else if(m(n[0])&&m(r[0]))a=n[0],s=r[0];else if(m(r[0])&&m(r[1]))a=r[0],s=r[1];else throw new Error("No label or value variable found");return{x:"",y:s,color:a}},si=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:s}=st(e.dataset),i=Fn(a),o=it({appearance:n,seriesVariables:s}),c=[L.line({params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&c.push(L.point({params:{size:On(t.pointSize)},interactive:!1})),{dataset:r,layers:c,coords:E.cartesian(),mapping:{...i,...o.mapping},scales:o.scales}},ii=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:s}=st(e.dataset),i=Fn(a),o=it({appearance:n,seriesVariables:s}),c=[L.area({position:"stack",params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&c.push(L.point({params:{size:On(t.pointSize)},position:"stack",interactive:!1})),{dataset:r,layers:c,coords:E.cartesian(),mapping:{...i,...o.mapping},scales:o.scales}},J=(e,t,n,r,a)=>{const{dataset:s,mapping:i}=st(e.dataset),o=[];if(r?.sortBars&&o.push(Y.x.discrete({sort:"descending"})),!a?.useSingleColorForBars){const c=at(e.dataset),{numeric:l}=e.dataset.groupVariableNamesByType();l.filter(p=>p!==c).length===1&&e.dataset.getType(c)==="categorical"&&(i.color=c)}return{dataset:s,layers:[L.bar({position:t})],coords:n,mapping:i,scales:o}},Dt=(e,t)=>({dataset:e.dataset,layers:[L.bar({position:"fill"})],coords:E.polar({theta:"y",innerRadius:t==="donut"?.55:0}),mapping:ai(e.dataset),scales:[]}),oi=e=>{const{dataset:t,mapping:n}=ri(e.dataset);return{dataset:t,layers:[L.point()],coords:E.cartesian(),mapping:n,scales:[]}},ci=e=>{const{numeric:t,categorical:n}=e.dataset.groupVariableNamesByType(),r={x:t[0],y:t[1],size:t[2],label:n[0]},a=[];return m(r.size)&&a.push(Y.size.continuous()),{dataset:e.dataset,layers:[L.point()],coords:E.cartesian(),mapping:r,scales:a}},$e=(e,t,n)=>{const r=n?.seriesStyles?.[e]?.lineStyle;return L.line({transforms:[ce.constant({variableName:Lt,type:"categorical",value:e})],aes:{y:e,color:Lt,...r?{lineType:{value:r}}:{}},...t?{yScaleType:"secondary"}:void 0})},li=(e,t,n)=>{const{numeric:r,categorical:a,temporal:s}=e.dataset.groupVariableNamesByType(),i=at(e.dataset),o=[...a,...s],c=r.filter(h=>h!==i),l=t?.comboType??"grouped-bars",d=e.axes?.hasDualYAxis===!0,p=l==="lines"||c.length<2,f=p?[]:c.slice(0,-1),y=p?c:c.slice(-1),g=[],x=[];if(f.length>0){const h=l==="stacked-bars"?"stack":"dodge",b=f.length===1?f[0]:null;m(b)?g.push(L.bar({transforms:[ce.constant({variableName:_t,type:"categorical",value:b})],aes:{y:b,color:_t},position:h})):g.push(L.bar({transforms:[ce.reshape({keep:o,reshape:f,keyName:N,valueName:B})],aes:{y:B,color:N},position:h}))}if(p&&y.length>=2){const h=d?y.slice(0,-1):y,b=h.length===1?h[0]:null;if(m(b))g.push($e(b,!1,n));else{const M=it({appearance:n,seriesVariables:h});g.push(L.line({transforms:[ce.reshape({keep:o,reshape:h,keyName:N,valueName:B})],aes:{y:B,color:N,...M.mapping}})),x.push(...M.scales)}if(d){const M=y[y.length-1];m(M)&&g.push($e(M,!0,n))}}else for(const h of y)g.push($e(h,d,n));return{dataset:e.dataset,layers:g,coords:E.cartesian(),mapping:{x:i},scales:x}},On=(e="auto")=>e==="auto"?Ve.params.size:e,re=e=>()=>{throw new Error(`Unsupported graph type: ${e}`)},ui={line:(e,t,n)=>si(e,t,n),areaStacked:(e,t,n)=>ii(e,t,n),bar:(e,t,n)=>J(e,"dodge",E.flip(),t,n),barStacked:(e,t,n)=>J(e,"stack",E.flip(),t,n),barStackedFill:(e,t,n)=>J(e,"fill",E.flip(),t,n),column:(e,t,n)=>J(e,"dodge",E.cartesian(),t,n),columnStacked:(e,t,n)=>J(e,"stack",E.cartesian(),t,n),columnStackedFill:(e,t,n)=>J(e,"fill",E.cartesian(),t,n),pie:e=>Dt(e,"pie"),donut:e=>Dt(e,"donut"),scatter:e=>oi(e),bubble:e=>ci(e),combo:(e,t,n)=>li(e,t,n),funnel:re("funnel"),heatmap:re("heatmap"),waterfall:re("waterfall"),mekko:re("mekko"),table:re("table")},di=(e,t,n,r)=>ui[t](e,n,r);function pi(e,t){const n=[];return n.push(Ct("x",e?.x)),n.push(Ct("y",e?.y)),n.push(Y.color.palette({palette:t?.paletteId})),n}function Ct(e,t){return t?.scaleType==="logarithmic"||t?.isReversed||t?.min!==void 0||t?.max!==void 0?t.scaleType==="logarithmic"?Y[e].log({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):Y[e].continuous({reverse:t.isReversed||void 0,domainMin:t.min??void 0,domainMax:t.max??void 0}):Y[e]()}function mi(e,t,n){const r=n.type??"column",a={dataset:e,axes:n.axes},s=di(a,r,n.options??void 0,n.appearance??void 0);return{data:s.dataset,datasetMetadata:t,mapping:s.mapping,layers:s.layers,scales:[...pi(n.axes,n.appearance),...s.scales],transforms:[],coords:s.coords,config:Ys(n)}}const yi={mode:"readonly",parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{isVisible:!0,title:null,subtitle:null,caption:null},appearance:{background:null}},fi={xLimits:null,yLimits:null},We={theta:"x",startAngle:0,innerRadius:0};function hi(e){const t=e??{type:"coord",coordType:"cartesian"},n=Ht({},fi,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:n};case"polar":return{...t,params:{...n,theta:t.params?.theta??We.theta,startAngle:t.params?.startAngle??We.startAngle,innerRadius:t.params?.innerRadius??We.innerRadius}}}}function gi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ve.stat,position:e.position??Ve.position,yScaleType:e.yScaleType??Ne,params:ee.merge({},Ve.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function bi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ye.stat,position:e.position??Ye.position,yScaleType:e.yScaleType??Ne,params:ee.merge({},Ye.params,e.params),transforms:e.transforms??[],interactive:e.interactive??!0}}function xi(e){const t=ee.merge({},Ge.params,e.params);return t.missingValues==="gap"&&(t.missingValues="zero"),{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??Ge.stat,position:e.position??Ge.position,yScaleType:e.yScaleType??Ne,params:t,transforms:e.transforms??[],interactive:e.interactive??!0}}function Mi(e){return{id:e.id??crypto.randomUUID(),type:e.type,geom:e.geom,mapping:e.mapping??{},stat:e.stat??ze.stat,position:e.position??ze.position,yScaleType:e.yScaleType??Ne,params:{...ze.params,...e.params},transforms:e.transforms??[],interactive:e.interactive??!0}}function Si(e){switch(e.geom){case"point":return gi(e);case"line":return bi(e);case"area":return xi(e);case"bar":return Mi(e)}}function Ti(e){return e.map(Si)}function Ai(e,...t){return e.find(n=>t.includes(n.geom))}const Pn={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},wi={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Bn(e,t,n,r){switch(e.scaleType){case"inferred":{const a=vi(e,t,n,r);return Bn(a,t,n,r)}case"continuous":{const a=Pn[e.scaledAesthetic],s=a==="continuous-range"&&e.scaledAesthetic in Vt?Vt[e.scaledAesthetic]:null,i=e.scaledAesthetic==="size"&&a==="continuous-range"?"sqrt":Q.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??i,reverse:e.reverse??Q.reverse,nice:e.nice??Q.nice,zero:e.zero??Q.zero,clamp:e.clamp??a!=="position",domainMin:e.domainMin??Q.domainMin,domainMax:e.domainMax??Q.domainMax,range:e.range??s??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??Te.domainMin,domainMax:e.domainMax??Te.domainMax,nice:e.nice??Te.nice,reverse:e.reverse??Te.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??ae.range,sort:e.sort??ae.sort,domain:e.domain??ae.domain,padding:e.padding??ae.padding};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:e.palette??Ja.palette};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const a=e;throw new Error(`Unknown scale type: ${a.scaleType}`)}}}function Vi(e,t,n,r){const a=Ei(t,n),s=Li(a),i=new Map;for(const o of s)i.set(o.scaledAesthetic,o);return[...i.values()].map(o=>Bn(o,e,n,r))}function vi(e,t,n,r){const a=F(e.scaledAesthetic),s=e.scaledAesthetic==="ySecondary"?Ii(n,r):r[a],i=Ai(n,"bar");if(e.scaledAesthetic==="x"&&i)return D(e.scaledAesthetic,e.options);if(i&&e.scaledAesthetic===(i.yScaleType==="secondary"?"ySecondary":"y")){const p=e.options,f=i.position==="fill";return V(e.scaledAesthetic,{...p,zero:!0,...f&&{nice:!1}})}const o=S(s);if(!m(o)||!t.hasVariable(o))return V(e.scaledAesthetic,e.options);const c=t.getType(o),l=Pn[e.scaledAesthetic];switch(wi[c][l]){case"discrete":return D(e.scaledAesthetic,e.options);case"datetime":return ve(e.scaledAesthetic,e.options);case"continuous":return V(e.scaledAesthetic,e.options);case"identity":default:return se(e.scaledAesthetic)}}function Ii(e,t){const n=e.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??t.y:t.y}function Ei(e,t){return!t.some(a=>a.yScaleType==="secondary")||e.some(a=>a.scaledAesthetic==="ySecondary")?e:[...e,Ie("ySecondary")]}function Li(e){return e.some(n=>n.scaledAesthetic==="color")?e:[...e,Nn("color")]}function Rt(e){const{data:t,mapping:n}=ki(e.data,e.mapping),r=hi(e.coords),a=Ti(e.layers),s=Vi(t,e.scales,a,n);return{data:t,datasetMetadata:e.datasetMetadata,mapping:n,layers:a,scales:r.coordType==="polar"?_i(s):s,transforms:e.transforms,coords:r,config:ee.merge({},yi,e.config)}}const _i=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t),ki=(e,t)=>{let n=e,r=t;(r.x===""||r.x===Se.x)&&(n.hasVariable(Se.x)||(n=n.addConstantVariable(Se.x,"categorical","")),r={...r,x:Se.x});for(const a of Object.keys(r)){const s=kr(r[a]);if(s===void 0)continue;const i=A(`const_${a}`);n=n.addConstantVariable(i,Di(s),s),r={...r,[a]:i}}return{data:n,mapping:r}},Di=e=>typeof e=="number"?"numeric":e instanceof Date?"temporal":"categorical";class Un{compile(t){return de({input:t}).pipe(({input:r})=>Ci(r.data)).pipe(({input:r,dataset:a,datasetMetadata:s})=>({spec:this.resolveFromInput(r,a,s)})).result().spec}resolveFromInput(t,n,r){if(Us(t)){const{data:a,...s}=t;return Rt(mi(n,r,s))}return Rt({...t,data:n,datasetMetadata:r})}}const Ci=e=>{const t=e._metadata?.parsingLocale??fe;return Cn(e,t)};class Ri{constructor(t){this.registry=t}compute(t,n){return this.registry.get(t).compute(n)}}class Yn{compute(t){return t.data.size()===0?{data:t.data,mapping:{}}:this.computeStat(t)}}class Ni extends Yn{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=S(n.x);if(!m(r))throw new Error("'x' variable is required for 'count' stat");if(S(n.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const s=[...new Set([r,...Jt(t,n)])];return{data:t.groupBy(...s).rollup({[qe.count]:{variableName:r,aggregation:"count"}}),mapping:{y:qe.count}}}}class Fi extends Yn{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:t}){return{data:t,mapping:{}}}}class Oi extends j{constructor(){super("stat"),this.register("identity",new Fi),this.register("count",new Ni)}}class Pi{constructor(t){this.registry=t}compile(t,n){return n.reduce((r,a)=>this.registry.get(a.transformType).apply(r,a),t)}}class Bi{constructor(){this.transformType="aggregate"}apply(t,n){const{options:r}=n,a={};for(const s of r.operations)a[s.as]={variableName:s.variableName,aggregation:s.op};return t.groupBy(...r.groupby).rollup(a)}}class Ui{constructor(){this.transformType="constant"}apply(t,n){const{options:r}=n;return t.addConstantVariable(r.variableName,r.type,r.value)}}class Yi{constructor(){this.transformType="filter"}apply(t,n){const{options:r}=n;return t.filter(r.variableName,r.operator,r.value)}}class Gi{constructor(){this.transformType="reshape"}apply(t,n){const{options:r}=n;return t.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}}class zi{constructor(){this.transformType="sort"}apply(t,n){const{options:r}=n;return t.orderBy(r.variableName,r.direction??"asc")}}class $i extends j{constructor(){super("transform"),this.register("aggregate",new Bi),this.register("constant",new Ui),this.register("filter",new Yi),this.register("reshape",new Gi),this.register("sort",new zi)}}const Wi={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"};class Ki{compile(t){return t.layers.map(n=>this.compileLayer(n,t.scales))}compileLayer(t,n){let r=t.data;const a=Object.entries(G);for(const[s,i]of a){const o=S(t.mapping[s]),c=n[s];if(!c||c.kind!=="visual")continue;const l=Hi(s,o,c);l&&(r=r.deriveVariable(i,Wi[s],l))}return{...t,data:r}}}const Hi=(e,t,n)=>{if(!t){if(e!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>m(r[t])?n.map(r[t]):null};class Gn{constructor(t,n,r,a,s,i,o,c){this.specCompiler=t,this.transformCompiler=n,this.layerCompiler=r,this.scaleCompiler=a,this.coordCompiler=s,this.positionMapperCompiler=i,this.visualMapperCompiler=o,this.guideCompiler=c}compile(t){const n=de({input:t}).pipe(({input:r})=>({spec:Bs(r)?r:this.specCompiler.compile(r)})).pipe(({spec:r})=>({spec:{...r,data:this.transformCompiler.compile(r.data,r.transforms)}})).pipe(({spec:r})=>({layers:this.layerCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping})})).pipe(({spec:r,layers:a})=>({scales:this.scaleCompiler.compile({layers:a,scales:r.scales})})).pipe(({spec:r})=>({coordSystem:this.coordCompiler.setup({coordSpec:r.coords})})).pipe(({layers:r,scales:a})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,scales:a,layers:s,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:a,config:r.config,layers:s,coordSystem:i,datasetMetadata:r.datasetMetadata})})).pipe(({layers:r,scales:a})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,layers:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,layers:a})})).result();return{...n,config:n.spec.config}}}const ji=e=>{const t=new fr,n=new Oi,r=new ns(t),a=new Or,s=new Pi(new $i);return t.register(Xt,[...qt]),new Gn(new Un,s,new Da(s,new Ri(n),new Pr,new Lr(a),new Ra(new Ba),new Ca(a,n)),new Ha(r),new hr(new Er),new Ka,new Ki,new ka).compile(e)};function qi(e,t){return e.geom===t}const ot="–",Xi="n/a",_={timeZone:"UTC"},I=e=>t=>{if(!Z(t))return ot;try{return e(t)}catch{return Xi}},z=e=>t=>an(t)?e(t):ot,zn=e=>t=>rn(t)?t:ot,Qi=2,Ji=3,Zi=2,eo=0,to=1,no=2,ro=({valueFormat:e,locale:t,numberFormat:n,intlOptions:r})=>z(a=>{const s=typeof n.decimals=="number"?n.decimals:Qi,i=ct(a,s),{base:o,suffix:c}=lt(a,n.abbreviation),l={...i,...on(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return`${Intl.NumberFormat(t,l).format(o)}${c}`}),ao=({locale:e,numberFormat:t,intlOptions:n})=>z(r=>{const{base:a,suffix:s}=lt(r,t.abbreviation),o={...ct(a,t.decimals),...n};return`${Intl.NumberFormat(e,o).format(a)}${s}`}),$n=e=>z(t=>co(t)),so=({locale:e,intlOptions:t})=>z(n=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(n)),io=({locale:e,numberFormat:t,intlOptions:n})=>z(r=>{const a=ct(r,t.decimals);return Intl.NumberFormat(e,{...a,...n,style:"percent"}).format(r)}),ct=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const n=Math.ceil(Math.log10(Math.abs(e))),r=n>=Ji?eo:n===Zi?to:no;return{minimumFractionDigits:t==="auto"?0:r,maximumFractionDigits:r}},oo=e=>{const t=Math.abs(e);return t>=oe.b?"b":t>=oe.m?"m":t>=oe.k?"k":"none"},lt=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const n=oo(e);return lt(e,n)}default:return{base:e/oe[t],suffix:t}}},co=mr.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),lo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{dateStyle:"medium",..._,...t}).format(n)),uo=({locale:e,intlOptions:t})=>I(n=>{const r=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",..._,...t}).formatToParts(n);return go(r.map(bo))}),po=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",..._,...t}).format(n)),mo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"long",..._,...t}).format(n)),Wn=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",..._,...t}).format(n)),Kn=e=>I(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),yo=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",..._,...t,year:void 0}).formatRange(n,r)}),fo=({locale:e,intlOptions:t})=>I(n=>{const r=T.addDays(n,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",..._,...t}).formatRange(n,r)}),Hn=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{year:"numeric",..._,...t}).format(n)),ho=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",..._,...t}).format(n)),go=e=>e.map(t=>t.value).join(""),bo=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},xo=1,Mo=4,So=1,To=({valueFormat:e,locale:t,tickValues:n,intlOptions:r})=>z(a=>{const i={...dt(a,n),notation:"compact",...on(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return ut(a,t,i)}),Ao=({locale:e,tickValues:t,intlOptions:n})=>z(r=>{const s={...dt(r,t),notation:"compact",...n};return ut(r,e,s)}),wo=({locale:e,tickValues:t,intlOptions:n})=>z(r=>{const s={...dt(r,t),notation:"compact",...n,style:"percent"};return ut(r,e,s)}),ut=(e,t,n)=>Intl.NumberFormat(t,n).formatToParts(e).map(a=>a.type==="compact"?a.value.toLowerCase():a.value).join(""),Nt=1e3,jn=e=>Math.abs(e)>Nt?jn(e/Nt):Number.isInteger(e),Vo=e=>{if(e.length<2)return!1;const[t,n]=e;return typeof t!="number"||typeof n!="number"?!1:Math.abs(n-t)<xo},dt=(e,t)=>jn(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Vo(t)?{minimumFractionDigits:0,maximumFractionDigits:Mo}:{minimumFractionDigits:0,maximumFractionDigits:So},vo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",..._,...t}).format(n)),Io=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{month:"short",..._,...t}).format(n)),Eo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",..._,...t}).format(n)),Lo=({locale:e,intlOptions:t})=>I(n=>Intl.DateTimeFormat(e,{timeStyle:"short",..._,...t}).format(n)),_o=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return To(e);case"date":case"datetime":return vo(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Eo(e);case"decimal":case"integer":return Ao(e);case"duration":return $n();case"month":return Io(e);case"month_year":return Wn(e);case"percentage":return wo(e);case"quarter":return Kn();case"text":return zn();case"time":return Lo(e);case"year":return Hn(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},ko=40,Do=60,Ft=8,Co=50,Ro=1/3,No=1/4,Ke="…",Fo=(e,t,n)=>{if(t<=0||e.length===0)return"";if(n(e)<=t)return e;if(n(Ke)>t)return"";let r=0,a=e.length-1,s=0;for(;r<=a;){const i=r+a>>>1,o=e.slice(0,i)+Ke;n(o)<=t?(s=i,r=i+1):a=i-1}return e.slice(0,s)+Ke},Oo=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Po(e):Bo(e),Po=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=qn(e.ticks,r),o=t-Ft;if(s<=o)return{...e,labelRotation:0,labelMaxWidthPx:null};if(t>=Co){const l=et(o);return{...e,ticks:Ze(e.ticks,a,l,r),labelRotation:0,labelMaxWidthPx:l}}if(i+Ft>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=et(n.height*Ro);return{...e,ticks:Ze(e.ticks,a,c,r),labelRotation:-90,labelMaxWidthPx:c}},Bo=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:s,maxHeight:i}=qn(e.ticks,r);if(i>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=et(n.width*No);return s<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Ze(e.ticks,a,o,r),labelRotation:0,labelMaxWidthPx:o}},qn=(e,t)=>{const n=[];let r=0,a=0;for(const s of e){const{width:i,height:o}=t(s.formattedLabel);n.push(i),i>r&&(r=i),o>a&&(a=o)}return{widths:n,maxWidth:r,maxHeight:a}},Ze=(e,t,n,r)=>{const a=s=>r(s).width;return e.map((s,i)=>(t[i]??0)<=n?s:{...s,formattedLabel:Fo(s.formattedLabel,n,a)})},et=e=>Math.max(0,Math.floor(e)),Uo=(e,t,n,r)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",s=a?Do:ko;let i=n-(e.length-1)*s;for(const o of e){const{width:c,height:l}=r(o);if(i-=a?c:l,i<0)return!1}return!0},Yo=({axis:e,availableSpacePx:t,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:a,position:s}=e;if(a.length===0)return[];const i=new Map,o=p=>{const f=i.get(p);if(f)return f;const y=a[p],g=y?Go(y.ticks,r(y)):[];return i.set(p,g),g};let c=0,l=a.length-1,d=-1;for(;c<=l;){const p=c+l>>>1,y=o(p).map(g=>g.formattedLabel);Uo(y,s,t,n)?(d=p,c=p+1):l=p-1}return d>=0?o(d):o(0)},Go=(e,t)=>e.map(n=>({...n,formattedLabel:t(n.value)})),zo=e=>{const t=e.padding??0,n=Ot(e.rows,t),r=Ot(e.cols,t);return{rows:n.tracks,cols:r.tracks,placements:Ho(e.placements,n.nameToIndex,r.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},$o=e=>{const t=Pt(e.rows,e.height),n=Pt(e.cols,e.width),r=Bt(t),a=Bt(n),s=new Map;for(const i of e.placements){const o=i.rowSpan??1,c=i.colSpan??1,l=a[i.col]??0,d=r[i.row]??0,p=Ut(n,i.col,c),f=Ut(t,i.row,o);s.set(i.name,{x:l,y:d,width:Math.max(0,p),height:Math.max(0,f)})}return s},Ot=(e,t)=>{const n=[],r=new Map;t>0&&n.push({type:"fixed",pixels:t});for(let a=0;a<e.length;a++){const s=e[a];if(!s)continue;r.set(s.name,n.length),n.push(Wo(s));const i=Ko(e,a);if(Xn(s)&&i){const o=s.gaps?.after??0,c=i.gaps?.before??0,l=Math.max(o,c);l>0&&n.push({type:"fixed",pixels:l})}}return t>0&&n.push({type:"fixed",pixels:t}),{tracks:n,nameToIndex:r}},Wo=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Xn=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Ko=(e,t)=>{for(let n=t+1;n<e.length;n++){const r=e[n];if(r&&Xn(r))return r}},Ho=(e,t,n)=>{const r=[];for(const a of e){const s=t.get(a.row),i=n.get(a.col);if(s===void 0||i===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):s,c=a.colEnd!==void 0?n.get(a.colEnd):i;o===void 0||c===void 0||r.push({name:a.name,row:s,col:i,rowSpan:Math.max(1,o-s+1),colSpan:Math.max(1,c-i+1)})}return r},Pt=(e,t)=>{let n=0,r=0;for(const s of e)s.type==="fixed"?n+=s.pixels:r+=s.weight;const a=Math.max(0,t-n);return e.map(s=>s.type==="fixed"?s.pixels:r===0?0:s.weight/r*a)},Bt=e=>{const t=new Array(e.length);let n=0;for(let r=0;r<e.length;r++)t[r]=n,n+=e[r]??0;return t},Ut=(e,t,n)=>{let r=0;const a=Math.min(t+n,e.length);for(let s=t;s<a;s++)r+=e[s]??0;return r},jo=["top","right","bottom","left"],He=(e,t)=>{const n={};for(const r of jo){const a=e.get(`${r}${t}`);a&&(n[r]=a)}return n},Qn=24,O={header:{after:10,before:0},topLegend:{after:16,before:0},topAxisLabel:{after:4,before:0},topAxis:{after:0,before:0},panel:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},Ae={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},panel:{after:4,before:0},rightAxis:{after:10,before:0}},qo=(e,t,n)=>{const a=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return zo({rows:[{name:"header",size:t.headerSize.height,gaps:O.header},{name:"topLegend",size:n.legends.top,gaps:O.topLegend},{name:"topAxisLabel",size:a,gaps:O.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:O.topAxis},{name:"panel",size:{flex:1},gaps:O.panel},{name:"bottomAxis",size:n.axes.bottom,gaps:O.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:O.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:O.bottomLegend},{name:"footer",size:t.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:Ae.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:Ae.leftAxis},{name:"panel",size:{flex:1},gaps:Ae.panel},{name:"rightAxis",size:n.axes.right,gaps:Ae.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panel",row:"panel",col:"panel"},...Xo(n.axes),...Qo(n.axesLabels,n.axes),...Jo(n.legends)],containerSize:e,padding:Qn})},Xo=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Qo=(e,t)=>{const n=[];return e.top>0||t.top>0?(e.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},Jo=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t},we={x:0,y:0,width:0,height:0},Zo="0000";class ec{constructor(t){this.measurer=t}compile(t){return de({compiled:t.compiled,formattedLegends:t.formattedLegends,containerSize:t.containerSize,externalMeasurements:t.externalMeasurements,locale:t.formattingLocale??t.compiled.config.parsingLocale}).pipe(({compiled:n,locale:r})=>({axisBundles:n.guides.axes.map(a=>({axis:a,resolveFormatter:tc(a,r,n.config),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({axisBundles:n.map(a=>Yt(a.axis.position)?{...a,formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel)}:a)})).pipe(({axisBundles:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n.map(i=>i.formatted),formattedLegends:r,containerSize:a,externalMeasurements:s})})).pipe(({axisBundles:n,layout:r})=>({formattedAxes:n.map(a=>Yt(a.axis.position)?a.formatted:this.finalizeAxis(a.axis,a.resolveFormatter,r.panel))})).pipe(({formattedAxes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})=>({layout:this.resolveLayout({axes:n,formattedLegends:r,containerSize:a,externalMeasurements:s})})).result()}seedAxis(t){const{tickCandidates:n,...r}=t;return{...r,ticks:[{value:0,position:0,formattedLabel:Zo}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(t,n,r){const s=t.position==="top"||t.position==="bottom"?r.width:r.height,i=Yo({axis:t,availableSpacePx:s,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:o,...c}=t,l={...c,ticks:i,labelRotation:0,labelMaxWidthPx:null};if(t.scaleType==="discrete"&&t.bandwidth!==void 0){const d=t.bandwidth*s;return Oo({formattedAxis:l,bandwidthPx:d,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:t,formattedLegends:n,containerSize:r,externalMeasurements:a}){const s=this.measureGuides(t,n),i=qo(r,a,s),o=$o(i);return{header:o.get("header")??we,footer:o.get("footer")??we,plot:o.get("plot")??we,panel:o.get("panel")??we,axes:He(o,"Axis"),axisLabels:He(o,"AxisLabel"),legends:He(o,"Legend")}}measureGuides(t,n){const r={top:0,right:0,bottom:0,left:0},a={top:0,right:0,bottom:0,left:0};for(const i of t)i.isVisible&&(r[i.position]=this.measurer.measureAxis(i),i.label!==null&&(a[i.position]=this.measurer.measureAxisLabel()));const s={top:0,right:0,bottom:0,left:0};for(const i of n)s[i.position]=this.measurer.measureLegend(i);return{axes:r,axesLabels:a,legends:s}}}const Yt=e=>e==="left"||e==="right",tc=(e,t,n)=>{const r=e.tickCandidates.flatMap(s=>s.ticks.map(i=>i.value)),a=new WeakMap;return s=>{const i=a.get(s);if(i)return i;const o=_o({valueFormat:s.valueFormat??e.valueFormat,locale:t,numberFormat:n.numberFormat,tickValues:r});return a.set(s,o),o}};function ue(e,t){return e==="x"?t.x:t.y}function Fe(e,t){return e==="x"?t.y:t.x}function nc(e,t){return{main:ue(e,t),cross:Fe(e,t)}}function rc(e){return e.type==="cartesian"}const Oe=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ro(e);case"date":return lo(e);case"datetime":return uo(e);case"day_month":return po(e);case"decimal":return ao(e);case"duration":return $n();case"integer":return so(e);case"month":return mo(e);case"month_year":return Wn(e);case"percentage":return io(e);case"quarter":return Kn();case"text":return zn();case"weekly_date_range":return yo(e);case"weekly_date_range_with_year":return fo(e);case"year":return Hn(e);case"time":return ho(e);default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},ac=(e,{formattingLocale:t}={})=>{const n=t??e.config.parsingLocale,r=e.config.numberFormat;return e.guides.legends.map(a=>sc(a,n,r))},sc=(e,t,n)=>{const r=Oe({valueFormat:e.valueFormat,locale:t,numberFormat:n});return{...e,items:e.items.map(a=>({...a,formattedLabel:r(a.value)}))}};function H(e){return e==="stack"||e==="fill"}function Jn(e,t){return pt(e.buckets,t,n=>n.main)}function ic(e,t){return pt(e.bands,t,n=>n.bandCenter)}function oc(e,t){return pt(e.columns,t,n=>n.mainMid)}function pt(e,t,n){if(e.length===0)return null;let r=0,a=e.length;for(;r<a;){const o=r+a>>>1,c=e[o];c&&n(c)<t?r=o+1:a=o}const s=e[r-1],i=e[r];return s?i&&Math.abs(n(i)-t)<Math.abs(n(s)-t)?i:s:i??null}function mt(e,t,n){return Math.hypot(e*n,t)}function cc(e,t,n,r){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const s=a.find(t.x*n,t.y,r??void 0),i=e.points[s];return i?{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:mt(i.x-t.x,i.y-t.y,n)}:null}function lc(e,t){if(e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const n=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[n]??null}function uc(e,t){return{group:dc(e),related:fc(e,t)}}function dc(e){switch(e.kind){case"buckets":{const t=e.match.index;return H(t.position)?pc(t,e.match):[]}case"rects":{const t=e.match.index;return H(t.position)?mc(t,e.match):yc(t,e.match)}case"points":case"arcs":return[]}}function pc(e,t){const n=[];for(const r of t.bucket.entries)r.pointIndex!==t.hit.pointIndex&&n.push({layerId:e.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return n}function mc(e,t){const n=[];for(const r of t.column.rects)r.pointIndex!==t.hit.pointIndex&&n.push(yt(e,r));return n}function yc(e,t){const n=e.bands.find(a=>a.columns.includes(t.column));if(!n)return[];const r=[];for(const a of n.columns)for(const s of a.rects)s.pointIndex!==t.hit.pointIndex&&r.push(yt(e,s));return r}function fc(e,t){const n=new Map;if(e.kind==="arcs")return n;for(const r of t){if(r.layerId!==e.match.index.layerId){gc(n,r,e.match.hit);continue}e.kind==="buckets"&&(H(r.position)||r.kind==="buckets"&&hc(n,r,e.match))}return n}function hc(e,t,n){for(const r of n.bucket.entries){if(r.pointIndex===n.hit.pointIndex)continue;Ee(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation})}}function gc(e,t,n){switch(t.kind){case"buckets":{const r=Jn(t,ue(t.mainAxis,n));if(!r)return;const a=Ee(e,t.layerId);for(const s of r.entries)a.push({layerId:t.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation});return}case"rects":{const r=ic(t,ue(t.mainAxis,n));if(!r)return;const a=Ee(e,t.layerId);for(const s of r.columns)for(const i of s.rects)a.push(yt(t,i));return}case"points":{const r=lc(t,n);if(!r)return;Ee(e,t.layerId).push({layerId:t.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return}case"arcs":return}}function Ee(e,t){let n=e.get(t);return n||(n=[],e.set(t,n)),n}function yt(e,t){return{layerId:e.layerId,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function bc(e){const t=xc(e);return{kind:"arcs",layerId:e.id,geom:e.geom,position:e.position,arcs:t}}function xc(e){const t=e.data;if(t.size()===0)return[];const n=[u.xMin,u.xMax,u.yMin,u.yMax];for(const l of n)if(!t.hasVariable(l))return[];const r=t.getValues(u.xMin,{type:"numeric"}),a=t.getValues(u.xMax,{type:"numeric"}),s=t.getValues(u.yMin,{type:"numeric"}),i=t.getValues(u.yMax,{type:"numeric"}),o=[];let c=0;for(const l of t){const d=r[c],p=a[c],f=s[c],y=i[c];if(!m(d)||!m(p)||!m(f)||!m(y)){c++;continue}o.push({pointIndex:c,startAngle:d,endAngle:p,innerRadius:f,outerRadius:y,observation:l}),c++}return o}const Mc=1e-9;function Sc(e,t){const n=Tc(e,t);n.sort((a,s)=>a.main-s.main);const r=[];for(const a of n){const s=r[r.length-1];s&&Math.abs(s.main-a.main)<=Mc?s.entries.push(a.entry):r.push({main:a.main,entries:[a.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,buckets:r}}function Tc(e,t){const n=e.data;if(n.size()===0)return[];const a=n.hasVariable(u.x),s=n.hasVariable(u.y);if(!a||!s)return[];const i=n.getValues(u.x,{type:"numeric"}),o=n.getValues(u.y,{type:"numeric"}),c=t==="y",l=c?u.xMin:u.yMin,d=c?u.xMax:u.yMax,p=H(e.position),f=p?n.getValues(l,{type:"numeric"}):null,y=p?n.getValues(d,{type:"numeric"}):null,g=n.hasVariable(v.group)?n.getValues(v.group,{type:"categorical"}):null,x=[];let h=0;for(const b of n){const M=i[h],k=o[h];if(!m(M)||!m(k)){h+=1;continue}const R=g?.[h]??null,te=c?k:M;if(p){const xe=f?.[h],Me=y?.[h];if(!m(xe)||!m(Me)){h+=1;continue}const ur=c?Me:M,dr=c?k:Me;x.push({main:te,entry:{isStacked:p,pointIndex:h,x:ur,y:dr,stackMin:xe,stackMax:Me,groupKey:R,observation:b}})}else x.push({main:te,entry:{isStacked:p,pointIndex:h,x:M,y:k,groupKey:R,observation:b}});h+=1}return x}function Ac(e,t){const n={kind:"points",layerId:e.id,geom:e.geom,position:e.position,points:wc(e),delaunay:null,delaunayAspectRatio:null};return Zn(n,t),n}function Zn(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=yr.Delaunay.from(e.points,n=>n.x*t,n=>n.y),e.delaunayAspectRatio=t)}function wc(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(u.x)||!t.hasVariable(u.y))return[];const n=t.getValues(u.x,{type:"numeric"}),r=t.getValues(u.y,{type:"numeric"}),a=[];let s=0;for(const i of t){const o=n[s],c=r[s];s+=1,!(!m(o)||!m(c))&&a.push({pointIndex:a.length,x:o,y:c,observation:i})}return a}const Vc=1e6;function vc(e,t){const n=Ic(e,t);n.sort((o,c)=>o.mainMid-c.mainMid);const r=new Map,a=new Map;for(const o of n){const c=Gt(o.mainMid);let l=r.get(c);if(!l){l={mainMid:o.mainMid,columnKey:c,rects:[]},r.set(c,l);const d=Gt(o.bandCenter);let p=a.get(d);p||(p={bandCenter:o.bandCenter,bandKey:d,columns:[]},a.set(d,p)),p.columns.push(l)}l.rects.push(o.entry)}const s=[...r.values()].sort((o,c)=>o.mainMid-c.mainMid),i=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of i)o.columns.sort((c,l)=>c.mainMid-l.mainMid);return{kind:"rects",layerId:e.id,geom:e.geom,position:e.position,mainAxis:t,columns:s,bands:i}}function Gt(e){return String(Math.round(e*Vc))}function Ic(e,t){const n=e.data;if(n.size()===0)return[];if(!(n.hasVariable(u.xMin)&&n.hasVariable(u.xMax)&&n.hasVariable(u.yMin)&&n.hasVariable(u.yMax)))return[];const a=n.getValues(u.xMin,{type:"numeric"}),s=n.getValues(u.xMax,{type:"numeric"}),i=n.getValues(u.yMin,{type:"numeric"}),o=n.getValues(u.yMax,{type:"numeric"}),c=t==="y",l=c?u.y:u.x,d=n.hasVariable(l)?n.getValues(l,{type:"numeric"}):null,p=n.hasVariable(v.group)?n.getValues(v.group,{type:"categorical"}):null,f=[];let y=0;for(const g of n){const x=a[y],h=s[y],b=i[y],M=o[y];if(!m(x)||!m(h)||!m(b)||!m(M)){y++;continue}const k=c?(b+M)/2:(x+h)/2,R=d?.[y]??k;f.push({mainMid:k,bandCenter:R,entry:{pointIndex:y,xMin:x,xMax:h,yMin:b,yMax:M,segmentKey:p?.[y]??null,observation:g}}),y++}return f}function zt(e,t,n){if(t.type==="polar")return bc(e);switch(e.geom){case"point":return Ac(e,n);case"line":case"area":return Sc(e,t.mainAxis);case"bar":return vc(e,t.mainAxis);default:{const r=e.geom;throw new Error(`buildLayerIndex: unhandled geom ${String(r)}`)}}}const C=Math.PI*2,Ec=1e-9;function Lc(e,t,n){if(e.arcs.length===0)return null;const{angle:r,radius:a}=_c(t,n);for(const s of e.arcs)if(!(a<s.innerRadius||a>s.outerRadius)&&kc(r,s))return{hit:{layerId:e.layerId,pointIndex:s.pointIndex,x:(s.startAngle+s.endAngle)/2,y:(s.innerRadius+s.outerRadius)/2,observation:s.observation},index:e};return null}function _c(e,t){const n=e.x-.5,r=e.y-.5,a=t>=1?n*2*t:n*2,s=t>=1?r*2:r*2/t,i=Math.hypot(a,s);return{angle:(Math.atan2(a,s)%C+C)%C,radius:i}}function kc(e,t){const n=t.endAngle-t.startAngle;if(Math.abs(n)>=C-Ec)return!0;const r=(n%C+C)%C;return((e-t.startAngle)%C+C)%C<=r}function Dc(e,t,n){if(e.buckets.length===0)return null;const{main:r,cross:a}=nc(e.mainAxis,t),s=Jn(e,r),i=s?.entries??[];if(!s||!jt(i))return null;const o=H(e.position)?Oc(i,a):Fc(i,a,e.mainAxis);return{hit:{layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:s,distance:mt(o.x-t.x,o.y-t.y,n)}}function Cc(e,t,n){if(e.columns.length===0)return null;const r=ue(e.mainAxis,t),a=oc(e,r),s=a?.rects??[];if(!a||!jt(s))return null;const i=H(e.position)?Rc(s,t,e.mainAxis):Nc(s,t,n);return{hit:{layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:a,distance:er(i,t,n)}}function Rc(e,t,n){const r=Fe(n,t);return Pe(e,s=>Bc(s,n,r),{shortCircuitOnZero:!0})}function Nc(e,t,n){return Pe(e,a=>er(a,t,n))}function Fc(e,t,n){return Pe(e,a=>Math.abs(Fe(n,a)-t))}function Oc(e,t){const n=Pc(e);return Pe(n,a=>Uc(a,t),{shortCircuitOnZero:!0})}function Pc(e){for(const t of e)if(!t.isStacked)throw new Error("pickStackedBucketEntry: expected stacked entries in a stacked bucket index");return e}function Pe(e,t,{shortCircuitOnZero:n=!1}={}){let r=e[0],a=t(r);if(n&&a===0)return r;for(let s=1;s<e.length;s+=1){const i=e[s];if(i===void 0)continue;const o=t(i);if(n&&o===0)return i;o<a&&(r=i,a=o)}return r}function er(e,t,n){const r=ke(t.x,e.xMin,e.xMax),a=ke(t.y,e.yMin,e.yMax);return mt(r,a,n)}function Bc(e,t,n){const r=t==="x"?e.yMin:e.xMin,a=t==="x"?e.yMax:e.xMax;return ke(n,r,a)}function Uc(e,t){return ke(t,e.stackMin,e.stackMax)}function ke(e,t,n){return e<t?t-e:e>n?e-n:0}const Yc=.05;function Gc({layers:e,cursor:t,aspectRatio:n,warmStarts:r}){const a={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const i of e){if(i.kind==="arcs"){const c=Lc(i,t,n);return c?{kind:"arcs",match:c}:null}const o=$c({layer:i,cursor:t,aspectRatio:n,warmStarts:r});if(o){if(o.kind==="rects"){o.match.distance<a.distance&&(a.match=o,a.distance=o.match.distance);continue}o.match.distance<s.distance&&(s.match=o,s.distance=o.match.distance)}}return zc({rect:a,continuous:s})}function zc({rect:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+Yc?t.match:e.match:e.match??t.match}function $c({layer:e,cursor:t,aspectRatio:n,warmStarts:r}){switch(e.kind){case"buckets":{const a=Dc(e,t,n);return a?{kind:"buckets",match:a}:null}case"rects":{const a=Cc(e,t,n);return a?{kind:"rects",match:a}:null}case"points":{const a=r.get(e.layerId)??null,s=cc(e,t,n,a);return s?{kind:"points",match:s}:null}}}const Wc=1,ie={primary:null,group:[],related:new Map};class Kc{constructor(t){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=Wc,this.warmStarts=new Map,this.cachedState=ie,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.layerIndexes=t.layers.map(n=>zt(n,t.coordSystem,this.aspectRatio)),this.layerRefs=t.layers.map(n=>$t(n,t.coordSystem)),this.nonInteractiveLayerIds=Wt(t.layers)}update(t){const n=new Map;for(let s=0;s<this.layerIndexes.length;s+=1){const i=this.layerIndexes[s],o=this.layerRefs[s];!i||!o||n.set(i.layerId,{index:i,ref:o})}const r=[],a=[];for(const s of t.layers){const i=n.get(s.id),o=$t(s,t.coordSystem);if(i!==void 0&&Hc(i.ref,o)){r.push(i.index),a.push(i.ref);continue}this.warmStarts.delete(s.id),r.push(zt(s,t.coordSystem,this.aspectRatio)),a.push(o)}for(const s of this.warmStarts.keys())t.layers.some(i=>i.id===s)||this.warmStarts.delete(s);this.layerIndexes=r,this.layerRefs=a,this.nonInteractiveLayerIds=Wt(t.layers),this.invalidateCache()}setViewport(t){this.aspectRatio=t.width/t.height;for(const n of this.layerIndexes)n.kind==="points"&&Zn(n,this.aspectRatio)}query(t){if(this.layerIndexes.length===0)return ie;const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(c=>!this.nonInteractiveLayerIds.has(c.layerId)),r=Gc({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,cursor:t});if(!r)return this.invalidateCache(),ie;const a=r.match.hit;this.warmStarts.set(a.layerId,a.pointIndex);const s=`${a.layerId}:${a.pointIndex}`;if(this.cachedKey===s)return this.cachedState;const{group:i,related:o}=uc(r,n);return this.cachedKey=s,this.cachedState={primary:a,group:i,related:o},this.cachedState}invalidateCache(){this.cachedKey=null,this.cachedState=ie}}function $t(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Wt(e){const t=new Set;for(const n of e)n.interactive||t.add(n.id);return t}function Hc(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}const $=(e,t,n)=>{const r=S(t[n]);return a=>{if(!m(r))return null;const s=a[r];if(s===void 0)return null;switch(e.getType(r)){case"numeric":return an(s)?s:null;case"categorical":return rn(s)?s:null;case"temporal":return Z(s)?s:null;default:return null}}},jc=(e,t)=>$(e,t,"x"),tr=(e,t)=>$(e,t,"y"),qc=(e,t)=>$(e,t,"label"),nr=(e,t)=>$(e,t,"color"),Xc=(e,t)=>$(e,t,"size"),Qc=(e,t)=>$(e,t,"alpha"),Jc=(e,t)=>$(e,t,"group"),Zc=(e,t)=>$(e,t,"strokeWidth");function rr(e){return e[G.color]}function el(e){return e[G.alpha]}function tl(e){return e[G.size]}function nl(e){return e[G.strokeWidth]}function ar(e){return e[G.lineType]??"solid"}function ft(e,t){return e.axes.find(n=>n.scaleAestheticKey===t)??null}function rl(e,t){return e.legends.find(n=>n.aesthetics.includes(t))??null}const al=({compiled:e,hover:t,formattingLocale:n})=>{const{primary:r}=t;if(r===null)return null;const a=n??e.config.parsingLocale;return{header:sl({compiled:e,primary:r,locale:a,numberFormat:e.config.numberFormat}),rows:il({compiled:e,hover:t,locale:a,numberFormat:e.config.numberFormat})}};function sl({compiled:e,primary:t,locale:n,numberFormat:r}){if(e.coordSystem.type!=="cartesian")return null;const a=e.coordSystem.mainAxis,s=ft(e.guides,a);if(!s)return null;const i=e.layers.find(d=>d.id===t.layerId);if(!i)return null;const o=S(i.mapping[a]);if(!m(o))return null;const c=t.observation[o];return m(c)?Oe({valueFormat:s.valueFormat,locale:n,numberFormat:r})(c):null}function il({compiled:e,hover:t,locale:n,numberFormat:r}){const a=[],s=e.scales.color??null,i=ul({compiled:e,locale:n,numberFormat:r});for(const o of e.layers){const c=ol(o,t);if(c.length===0)continue;const l=nr(o.data,o.mapping),d=cl(c,o,s,l),p=ll({compiled:e,layer:o,locale:n,numberFormat:r}),f=dl(e,o),y=tr(o.data,o.mapping),g=o.mapping.color!==void 0,x=dn(o.geom,e.coordSystem);for(const h of d){const b=g?l(h.observation):null,M=rr(h.observation)??null,k=ar(h.observation),R=g&&b!==null?i(b):f,te=y(h.observation),xe=te===null?"":p(te);a.push({swatchColor:M,swatchShape:x,swatchLineType:k,label:R,value:xe,isPrimary:h===t.primary,key:`${h.layerId}:${h.pointIndex}`})}}return a}function ol(e,t){const n=[];return t.primary!==null&&t.primary.layerId===e.id&&n.push(t.primary,...t.group),n.push(...t.related.get(e.id)??[]),n}function cl(e,t,n,r){if(n===null||t.mapping.color===void 0)return e;const a=new Map;return n.domain.forEach((s,i)=>{a.set(W(s),i)}),e.map((s,i)=>{const o=r(s.observation),c=o===null?null:W(o),l=c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY;return{hit:s,originalIndex:i,rank:l}}).sort((s,i)=>s.rank===i.rank?s.originalIndex-i.originalIndex:s.rank-i.rank).map(s=>s.hit)}function ll({compiled:e,layer:t,locale:n,numberFormat:r}){const a=pe(t.yScaleType),i=ft(e.guides,a)?.valueFormat??{type:"decimal"};return Oe({valueFormat:i,locale:n,numberFormat:r})}function ul({compiled:e,locale:t,numberFormat:n}){const a=rl(e.guides,"color")?.valueFormat??{type:"text"};return Oe({valueFormat:a,locale:t,numberFormat:n})}function dl(e,t){const n=pe(t.yScaleType);return ft(e.guides,n)?.label??""}function pl(e){return{startAngle:e[u.xMin],endAngle:e[u.xMax]}}function ml(e){return{innerRadius:e[u.yMin],outerRadius:e[u.yMax]??e[u.y]}}function yl(e){return typeof e=="object"&&e!==null&&"type"in e}function fl(e,...t){let n={},r;const[a,...s]=t;m(a)&&!yl(a)?(n=a,r=s):r=t;const i={data:e,mapping:n,layers:[],scales:[],transforms:[],config:{}};return r.reduce((o,c)=>sr(o,c),i)}function hl(e,...t){return t.reduce((n,r)=>sr(n,r),e)}function sr(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:Ht({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};default:{const n=t;throw new Error(`Unknown spec item type: ${n.type}`)}}}class gl{constructor(t={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.maxHistorySize=t.maxHistorySize??100}apply(t,n){return this.withReentrancyGuard(()=>{const r=t.apply(n);return r?(this.undoStack.push({command:t,revert:r.revert}),this.redoStack=[],this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.emit({type:"apply",command:t,spec:r.spec}),r.spec):n})}undo(t){return this.withReentrancyGuard(()=>{const n=this.undoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.redoStack.push({command:n.command,revert:r.revert}),this.emit({type:"undo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.undoStack.push(n),null)})}redo(t){return this.withReentrancyGuard(()=>{const n=this.redoStack.pop();if(!n)return null;const r=n.revert.apply(t);return r?(this.undoStack.push({command:n.command,revert:r.revert}),this.emit({type:"redo",command:n.command,spec:r.spec}),{spec:r.spec,command:n.command}):(this.redoStack.push(n),null)})}clear(){this.withReentrancyGuard(()=>{this.undoStack=[],this.redoStack=[],this.emit({type:"clear"})})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null}),this.cachedSnapshot}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}withReentrancyGuard(t){if(this.isEmitting)throw new Error("CommandStack: cannot call apply/undo/redo/clear from within a listener");this.isEmitting=!0;try{return t()}finally{this.isEmitting=!1}}emit(t){this.cachedSnapshot=null;for(const n of this.listeners)try{n(t)}catch(r){console.error("CommandStack listener error:",r)}}}function ge(e,t){return Object.entries(t).reduce((n,[r,a])=>{const s=e[r];return Kt(a)&&Kt(s)?n[r]=ge(s,a):a!==void 0&&(n[r]=a),n},{...e})}function Kt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function be(e){return{id:e.id??crypto.randomUUID(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}class ht{constructor(t,n={}){this.type="set-appearance-background",this.params=t,this.metadata=be({...n,description:`Set background to ${t.background??"(none)"}`})}apply(t){const n=t.config.appearance.background,r=ge(t,{config:{appearance:{background:this.params.background}}}),a=new ht({background:n},this.metadata);return{spec:r,revert:a}}}class gt{constructor(t,n={}){this.type="set-content-visibility",this.params=t,this.metadata=be({...n,description:`Set content visibility to ${t.isVisible}`})}apply(t){const n=t.config.content.isVisible,r=ge(t,{config:{content:{isVisible:this.params.isVisible}}}),a=new gt({isVisible:n},this.metadata);return{spec:r,revert:a}}}class bt{constructor(t,n={}){this.type="set-grid-visibility",this.params=t,this.metadata=be({...n,description:`Set grid visibility to x=${t.xIsVisible}, y=${t.yIsVisible}`})}apply(t){const n=t.config.axes.x.grid.isVisible,r=t.config.axes.y.grid.isVisible,a=ge(t,{config:{axes:{x:{grid:{isVisible:this.params.xIsVisible}},y:{grid:{isVisible:this.params.yIsVisible}}}}}),s=new bt({xIsVisible:n,yIsVisible:r},this.metadata);return{spec:a,revert:s}}}class xt{constructor(t,n={}){this.type="set-legend-position",this.params=t,this.metadata=be({...n,description:`Set legend position to ${t.position}`})}apply(t){const n=t.config.legend.position,r=ge(t,{config:{legend:{position:this.params.position}}}),a=new xt({position:n},this.metadata);return{spec:r,revert:a}}}class Mt{constructor(t,n={}){this.type="set-data",this.params=t,this.metadata=be({...n,description:"Set dataset"})}apply(t){const n=t.data,r=bl(this.params.data),a={...t,data:r},s=new Mt({data:n},this.metadata);return{spec:a,revert:s}}}const bl=e=>{if(e instanceof w)return e;const t=e._metadata?.parsingLocale??fe;return Cn(e,t).dataset},ir=500,or="normal",cr={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},lr=e=>typeof e!="string"?e??ir:cr[e],xl="\0";class Ml{constructor(t){this.inner=t,this.cache=new Map}measureText(t,n){const r=this.getCacheKey(t,n),a=this.cache.get(r);if(a)return a;const s=this.inner.measureText(t,n);return this.cache.set(r,s),s}getCacheKey(t,n){return[n.family,n.size,lr(n.weight),n.style??or,t].join(xl)}}const Sl={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56},Tl=.55,Al=1.05,wl=.84,Vl=.21;class vl{measureText(t,n){let r=0;for(const o of t)r+=(Sl[o]??Tl)*n.size;lr(n.weight)>=cr.semiBold&&(r*=Al);const s=wl*n.size,i=Vl*n.size;return{width:r,height:s+i,ascent:s,descent:i}}}exports.CachedTextMeasurer=Ml;exports.CommandStackManager=gl;exports.Compiler=Gn;exports.DEFAULT_COLOR_PALETTE=qt;exports.DEFAULT_FONT_STYLE=or;exports.DEFAULT_FONT_WEIGHT=ir;exports.DEFAULT_LOCALE=fe;exports.DEFAULT_PALETTE_NAME=Xt;exports.Dataset=w;exports.GROUP_VARIABLES=v;exports.HeuristicTextMeasurer=vl;exports.HoverEngine=Kc;exports.LAYOUT_PADDING=Qn;exports.LayoutCompiler=ec;exports.POSITION_VARIABLES=u;exports.RESTING_HOVER_STATE=ie;exports.SetAppearanceBackgroundCommand=ht;exports.SetContentVisibilityCommand=gt;exports.SetDataCommand=Mt;exports.SetGridVisibilityCommand=bt;exports.SetLegendPositionCommand=xt;exports.SpecResolver=Un;exports.VISUAL_VARIABLES=G;exports.buildTooltipContent=al;exports.compile=ji;exports.config=Rn;exports.coord=E;exports.createAlphaValueReader=Qc;exports.createColorValueReader=nr;exports.createGroupValueReader=Jc;exports.createLabelValueReader=qc;exports.createSizeValueReader=Xc;exports.createSpec=fl;exports.createStrokeWidthValueReader=Zc;exports.createXValueReader=jc;exports.createYValueReader=tr;exports.formatLegends=ac;exports.geom=L;exports.getAlpha=el;exports.getAngleExtent=pl;exports.getColor=rr;exports.getCrossAxisCoordinate=Fe;exports.getGroup=pn;exports.getLineType=ar;exports.getMainAxisCoordinate=ue;exports.getRadiusExtent=ml;exports.getSize=tl;exports.getStrokeWidth=nl;exports.getX=ua;exports.getXMax=pa;exports.getXMin=da;exports.getY=Xe;exports.getYMax=Qe;exports.getYMin=mn;exports.isCartesian=rc;exports.isDefined=m;exports.isLayerOf=qi;exports.isStackedPosition=H;exports.mapping=_r;exports.pipe=hl;exports.prefixInternalVariable=A;exports.scale=Y;exports.transform=ce;
|