@graphysdk/viz-engine 0.0.1-alpha.4 → 0.0.1-alpha.6
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 +23 -3
- package/dist/index.d.ts +5181 -590
- package/dist/index.mjs +10388 -4491
- package/package.json +9 -4
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
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(`
|
|
2
|
-
|
|
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;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("date-fns"),He=require("lodash-es"),pe=require("arquero"),Qe=require("d3-time"),Da=require("date-fns/differenceInDays"),we=require("d3-regression"),fe=require("d3-scale"),to=require("lodash-es/merge"),Ra=require("humanize-duration");require("@graphysdk/i18n");const Ee=require("d3-shape"),Pa=require("d3-delaunay"),Fa=require("lodash-es/isEqual");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-alpha.6");const be=t=>t.length>0;function h(t){return t!=null}function Zr(t){if(t===null||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e===Object.prototype||e===null}class Un extends Error{constructor(e){super(e.message,e.cause!==void 0?{cause:e.cause}:void 0),this.name=new.target.name,this.code=e.code,this.context=e.context,this.suggestion=e.suggestion}}class O extends Un{constructor(e){super(e),this.kind="user-input"}}class A extends Un{constructor(e){super({...e,code:e.code??"INTERNAL_INVARIANT"}),this.kind="internal"}}function no(t){return t instanceof Un?{severity:"error",kind:t.kind,code:t.code,message:t.message,...t.context!==void 0?{context:t.context}:{},...t.suggestion!==void 0?{suggestion:t.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:t instanceof Error?t.message:String(t)}}function B(t,e){return ro(t,e)}function yn(t,e){for(const n of Object.keys(e)){const r=e[n];if(r!==void 0&&r!==t[n])return{...t,...e}}return t}function ro(t,e){let n=!1;const r={...t};for(const[s,o]of Object.entries(e)){const i=t[s];if(Zr(o)&&Zr(i)){const a=ro(i,o);a!==i&&(r[s]=a,n=!0)}else o!==void 0&&o!==i&&(r[s]=o,n=!0)}return n?r:t}const Le=process.env.NODE_ENV!=="production";function $t(t){return{pipe:e=>{const n=e(t);return $t({...t,...n})},result:()=>t}}let Wt=!0;const Na=t=>{Wt=t},Oa=()=>Wt,Ba=()=>{let t=null;const e={hits:0,misses:0};return Object.assign((r,s)=>{if(!Wt)return Le&&(e.misses+=1),s();if(t&&oo(t.args,r))return Le&&(e.hits+=1),t.out;Le&&(e.misses+=1);const o=s();return t={args:r,out:o},o},{stats:e,reset:()=>{t=null}})},so=()=>{const t=new WeakMap,e={hits:0,misses:0};return Object.assign((r,s,o)=>{if(!Wt)return Le&&(e.misses+=1),o();const i=t.get(r);if(i){for(const c of i)if(oo(c.args,s))return Le&&(e.hits+=1),c.out}Le&&(e.misses+=1);const a=o();return i?i.push({args:s,out:a}):t.set(r,[{args:s,out:a}]),a},{stats:e})},Ga=(...t)=>t.reduce((e,n)=>({hits:e.hits+n.hits,misses:e.misses+n.misses}),{hits:0,misses:0}),oo=(t,e)=>{if(t.length!==e.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==e[n])return!1;return!0};class xe{constructor(){this.memo=so(),this.singletonKey={}}get stats(){return this.memo.stats}compile(e){return this.memo(this.key(e),this.dependencies(e),()=>this.run(e))}key(e){return this.singletonKey}}const io="\0graphy\0_",w=t=>`${io}${t}`,it={x:w("constantX")},at={count:w("count"),mean:w("mean")},z={group:w("group")},g={x:w("x"),y:w("y"),xMin:w("xMin"),xMax:w("xMax"),yMin:w("yMin"),yMax:w("yMax"),yRaw:w("yRaw")},ve={color:w("color"),size:w("size"),alpha:w("alpha"),strokeWidth:w("strokeWidth"),lineType:w("lineType")},yt={y:w("ruleY"),x:w("ruleX")};({...z,...g,...ve});const $a=new Set(Object.values(at)),ao=t=>w(`scaled_${t}`),Wa=t=>t.startsWith(io),za=t=>$a.has(t),X=t=>t instanceof Date&&_.isValid(t),Ha=t=>X(t)||t===null,zt=t=>typeof t=="string",D=t=>typeof t=="number"&&!Number.isNaN(t)&&Number.isFinite(t),Ya=t=>D(t)||t===null,I=t=>(Array.isArray(t)?t:[t]).map(n=>n instanceof Date?n.toISOString():String(n??"<null>")).join("\0"),Vt=(t,e)=>t===e?!0:X(t)&&X(e)?t.getTime()===e.getTime():!1,st={k:1e3,m:1e6,b:1e9,t:1e12},Kn=["k","m","b","t"],Ua=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${Kn.join("|")})?$`,"i"),Ka=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,Ve=t=>t===null||t instanceof Date||Array.isArray(t)||typeof t=="boolean"?!1:typeof t=="string"?Ua.test(t)&&!Number.isNaN(Number(t.replace(new RegExp(`[,${Kn.join("")}]`,"gi"),""))):!Number.isNaN(Number(t)),co=t=>Ve(t)?!0:typeof t=="string"?Ka.test(t):!1,lo={$:"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"},uo=t=>{if(typeof t=="string"){const e=mo(t);return e.length?Ve(e):!1}return Ve(t)},Xa=t=>{const e=po(t),n=e?lo[e]:void 0;if(!n)throw new A({message:"Could not get currency ISO"});return n},mo=t=>{const e=po(t);let n=t;if(e){const r=t.indexOf(e);r===0?n=t.slice(e.length):r===t.length-e.length?n=t.slice(0,t.length-e.length):t[0]==="-"&&r===1&&(n=`-${t.slice(e.length+1)}`)}return Ve(n)?n.split(",").join(""):""},po=t=>Object.keys(lo).sort((n,r)=>r.length-n.length).find(n=>t.includes(n)),fo=t=>{const e=Object.entries(t);return!e.length||!e.some(([,n])=>!mt(n))},mt=t=>typeof t=="string"&&t.trim()===""||t===void 0||t===null||t==="-",Ht="en-GB",Xn=t=>t.type==="lookup",ho=t=>t.type==="text",Ye=t=>t.type==="date"||t.type==="datetime"||t.type==="year"||t.type==="month_year"||t.type==="month"||t.type==="day_month"||t.type==="weekly_date_range"||t.type==="weekly_date_range_with_year"||t.type==="quarter"||t.type==="time",jn=t=>t.type==="decimal"||t.type==="integer"||t.type==="percentage"||t.type==="duration"||t.type==="currency",qn=t=>t.type==="currency",Zn=t=>t.type==="month"||t.type==="day_month"||t.type==="weekly_date_range",go=t=>{if(Xn(t))return go(t.fallback);if(Ye(t))return"temporal";if(jn(t))return"numeric";if(ho(t))return"categorical";const e=t;throw new A({message:`No data type found for value format: ${e.type}`})},Nn=t=>Xn(t)?t.fallback:t;class yo{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(e){this.previousYear===null?this.previousYear=e.getUTCFullYear():this.previousDate!==null&&_.isBefore(new Date(this.currentYear,e.getUTCMonth(),e.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(e.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const ja=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,qa=/^\s*(19\d{2}|2[01]\d{2})\s*$/,Za=[[/\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"]],Qa={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},bo=["/","-","."," "],Qr=[["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"]],Jr=[["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"]],es=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],xo=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],Ja=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],vo=1900,So=2199,ec=3,tc=6,nc=5,rc=1,sc=28,oc=/\s*[–—]\s*|\s-\s/,ic=t=>typeof t=="number"?Number.isNaN(t)?!1:t>=vo&&t<=So:typeof t=="string"?qa.test(t):!1,Ao=(t,e)=>{const n=ct(t);return Ve(n)?lc(n):typeof n=="string"?!!wo(n)||Qn(n)&&_.isValid(new Date(n)):_.isValid(n)},ct=t=>{if(typeof t!="string")return t;let e=t;for(const[n,r]of Za)e=e.replace(n,r);return e},wo=(t,e=Ht)=>{const n=ct(t);return Qn(n)?{type:"datetime"}:To(e).find(r=>!Ye(r)||r.type==="month"&&n.length<ec?!1:r.dateFormat&&_.isValid(_.parse(n,r.dateFormat,new Date)))},Qn=t=>ja.test(t.trim()),ac=(t,e=Ht)=>{const[n,r]=t.split(oc);if(!n||!r)return;const s=ct(n).trim(),o=ct(r).trim();return cc(e).find(i=>{if(!Ye(i)||!i.dateFormat)return!1;const a=_.parse(s,i.dateFormat,new Date),c=_.parse(o,i.dateFormat,new Date);if(!_.isValid(a)||!_.isValid(c))return!1;const l=new yo,d=l.incrementYearIfNeeded(a),u=l.incrementYearIfNeeded(c),m=_.differenceInDays(u,d);return _.isWithinInterval(new Date(d.getFullYear(),rc,sc),{start:d,end:u})&&m===nc?!0:m===tc})},To=t=>{const e={date:Mo(t),year:[["yyyy"]],day_month:xo,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...Ja,...Object.entries(e).flatMap(([n,r])=>r.flatMap(s=>bo.map(o=>({dateFormat:s.join(o),type:n}))))]},Mo=t=>Qa[t]==="MDY"?[...Jr,...Qr,...es]:[...Qr,...Jr,...es],cc=t=>{const e={weekly_date_range:xo,weekly_date_range_with_year:Mo(t)};return Object.entries(e).flatMap(([n,r])=>r.flatMap(s=>bo.map(o=>({dateFormat:s.join(o),type:n}))))},lc=t=>{const e=Number(t);if(!He.isInteger(e))return!1;const n=new Date(e),r=new Date(e*1e3),s=o=>_.isValid(o)&&o.getFullYear()>=vo&&o.getFullYear()<=So;return s(n)||s(r)},uc=/\s*[–—]\s*|\s-\s/,kt=(t,e,n)=>{if(mt(t))return null;switch(e.type){case"decimal":case"integer":case"duration":return Io(t);case"percentage":return dc(t);case"currency":return mc(t);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return Lo(t,e.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return pc(t,e.dateFormat,n);case"text":return fc(t);case"lookup":throw new A({message:"Cannot parse: lookup value formats are produced by transforms, not raw input"});default:{const r=e;throw new A({message:`Unhandled value format: ${r.type}`})}}},Lo=(t,e,n)=>{if(t instanceof Date)return _.isValid(t)?t:null;const r=ct(String(t).trim());if(r.length===0)return null;const s=new Date;if(e){const i=_.parse(r,e,s);return _.isValid(i)?bn(i):null}for(const i of To(n)){if(!Ye(i)||!i.dateFormat)continue;const a=_.parse(r,i.dateFormat,s);if(_.isValid(a))return bn(a)}const o=new Date(r);return Ao(o)?Qn(r)?o:bn(o):null},Io=t=>{if(typeof t=="number")return Number.isNaN(t)?null:t;if(typeof t!="string")return null;let e=t.trim();if(!Ve(e))return null;let n=1;for(const r of Kn)if(new RegExp(`${r}$`,"i").test(e)){n=st[r],e=e.slice(0,-1);break}return Number(e.split(",").join(""))*n},dc=t=>{if(typeof t=="number")return Number.isNaN(t)?null:t;if(typeof t!="string")return null;const e=t.trim();if(!co(e))return null;const n=Number(e.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},mc=t=>{if(typeof t=="number")return Number.isNaN(t)?null:t;if(typeof t!="string")return null;const e=t.trim();return uo(e)?Io(mo(e)):null},pc=(t,e,n)=>{const r=String(t).trim().split(uc),[s,o]=[r[0]?.trim(),r[1]?.trim()];return!s||!o?null:Lo(s,e,n)},fc=t=>String(t).trim(),bn=t=>new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));function hc(t){return{type:"mapping",mapping:t}}function x(t){return h(t)?typeof t=="string"?t:"variable"in t?t.variable:null:null}function ce(t){if(!(!h(t)||typeof t=="string")&&"value"in t)return t.value}const gc={type:"decimal"};function Eo(t,e){return e!==null&&t.data.hasVariable(e)?t.data.getValueFormat(e):gc}function Vo(t){const e=x(t.mapping.y);return Eo(t,e)}const Ue=t=>t[z.group];function Yt(t){return t[ve.color]}function yc(t){return t[ve.alpha]}function ko(t){return t[ve.size]}function _o(t){return t[ve.strokeWidth]}function Co(t){return t[ve.lineType]??"solid"}const _t=(t,e,n,r,s)=>e.anchorType==="panel"?{x:e.x,y:1-e.y}:lt(t,bc(e),n,r,s),Do=(t,e,n)=>({x:t.x,y:1-t.y-t.height,width:t.width,height:t.height}),lt=(t,e,n,r,s)=>{for(const o of n){const{resolveAnchorPosition:i}=t.get(o.geom);if(i===void 0||e.layerId!==void 0&&o.id!==e.layerId)continue;const a=x(o.mapping.x),c=x(o.mapping.y),l=a!==null&&a!==it.x?a:z.group,{anchorValue:d,groupValue:u}=xc(e,l,o,s);for(const m of o.data){if(!Vt(m[l]??null,d)||u!==void 0&&!Vt(Ue(m),u))continue;const p=i(m,r);if(p===null)continue;const f=c!==null?m[c]:null;if(D(f))return{...p,geom:o.geom,measurementValue:f,valueFormat:Vo(o),color:Yt(m)}}}return null},bc=t=>({layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue}),xc=(t,e,n,r)=>{const s=Nn(n.data.getValueFormat(e)),o=kt(t.anchorValue,s,r);if(t.groupValue===void 0)return{anchorValue:o,groupValue:void 0};const i=Nn(n.data.getValueFormat(z.group));return{anchorValue:o,groupValue:kt(t.groupValue,i,r)}};class vc extends xe{constructor(e){super(),this.container=e}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.config.parsingLocale]}run(e){const{geomRegistry:n}=this.container,{annotations:r,layers:s,coordSystem:o,config:i}=e,{parsingLocale:a}=i;return{differenceArrows:Ec(n,e),shapes:Sc(r.shapes),freeformArrows:wc(n,r.freeformArrows,s,o,a),textAnnotations:Tc(n,r.textAnnotations,s,o,a),images:Ac(r.images),stickers:Mc(n,r.stickers,s,o,a),pinnedNumbers:Lc(n,r.pinnedNumbers,s,o,a),comments:Ic(n,r.comments,s,o,a)}}}const Sc=(t,e,n)=>{const r=[];for(const s of t){const o=Do(s.region);o!==null&&r.push({id:s.id,kind:s.kind,zOrder:s.zOrder,region:o,fillColor:s.fillColor,fillOpacity:s.fillOpacity,strokeWidth:s.strokeWidth,strokeColor:s.strokeColor})}return r},Ac=(t,e,n)=>{const r=[];for(const s of t){const o=Do(s.region);o!==null&&r.push({id:s.id,src:s.src,zOrder:s.zOrder,region:o,fit:s.fit,opacity:s.opacity})}return r},wc=(t,e,n,r,s)=>{const o=[];for(const i of e){const a=_t(t,i.start,n,r,s),c=_t(t,i.end,n,r,s);a===null||c===null||o.push({id:i.id,start:a,end:c,color:i.color,thickness:i.thickness,startArrowheadStyle:i.startArrowheadStyle,endArrowheadStyle:i.endArrowheadStyle,lineStyle:i.lineStyle,hasStickerStyle:i.hasStickerStyle})}return o},Tc=(t,e,n,r,s)=>{const o=[];for(const i of e){const a=_t(t,i.at,n,r,s);a!==null&&o.push({id:i.id,content:i.content,at:a,width:i.width,backgroundColor:i.backgroundColor,backgroundColorStyle:i.backgroundColorStyle})}return o},Mc=(t,e,n,r,s)=>{const o=[];for(const i of e){const a=_t(t,i.at,n,r,s);a!==null&&o.push({id:i.id,at:a,sticker:i.sticker})}return o},Lc=(t,e,n,r,s)=>{const o=[];for(const i of e){const a=lt(t,i.at,n,r,s);a!==null&&o.push({id:i.id,at:a})}return o},Ic=(t,e,n,r,s)=>{const o=[];for(const i of e){const a=lt(t,i.at,n,r,s);a!==null&&o.push({id:i.id,at:a,content:i.content})}return o},Ec=(t,{annotations:e,layers:n,coordSystem:r,config:s})=>{if(r.type!=="cartesian")return[];const o=[];for(const i of e.differenceArrows){if(Vc(i.start,i.end))continue;const a=lt(t,i.start,n,r,s.parsingLocale),c=lt(t,i.end,n,r,s.parsingLocale);a===null||c===null||o.push({id:i.id,start:a,end:c,color:kc(i,a,c),size:i.size,label:i.label,labelCrossPosition:i.labelCrossPosition})}return o},Vc=(t,e)=>t.layerId===e.layerId&&t.anchorValue===e.anchorValue&&t.groupValue===e.groupValue,kc=(t,e,n)=>t.color!==null?t.color:t.start.groupValue!==t.end.groupValue||e.color===void 0||e.color!==n.color?null:e.color;function _c(t,e,n){const r=Rc(n);return{...e,background:Cc(t,e.background,r),border:Dc(t,e.border,r)}}function Cc(t,e,n){if(e.type==="tinted"){const r=e.color??n;return r?{type:"tinted",color:r}:(t.diagnostics.addWarning({code:"UNRESOLVABLE_COLOR",message:"Could not resolve a colour for the tinted background — falling back to the theme background.",suggestion:"Set an explicit background colour, or add a colour scale the tint can derive from."}),{type:"theme"})}return e}function Dc(t,e,n){if(e.type==="tinted"||e.type==="gradient"){const r=e.color??n;return r?{...e,color:r}:(t.diagnostics.addWarning({code:"UNRESOLVABLE_COLOR",message:`Could not resolve a colour for the ${e.type} border — dropping the border.`,suggestion:"Set an explicit border colour, or add a colour scale the tint can derive from."}),{type:"none"})}return e}function Rc(t){const e=t.color,n=e?.domain[0];if(!n)return;const r=e.map(n);if(typeof r=="string")return r}class Pc extends xe{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config]}run(e){const{scales:n,config:r}=e;return{...r,appearance:_c(this.container,r.appearance,n)}}}const Fc=new Set(["count","sum","mean","median"]);function Ro(t,e){return Fc.has(t)?"numeric":e}const Po="key",Nc="value",ts="\0__rowMaskIndex",ot={numeric:{type:"decimal"},categorical:{type:"text"},temporal:{type:"datetime"}},Oc={eq:(t,e)=>t[e.__variableName]===e.__value,neq:(t,e)=>t[e.__variableName]!==e.__value,gt:(t,e)=>t[e.__variableName]>e.__value,gte:(t,e)=>t[e.__variableName]>=e.__value,lt:(t,e)=>t[e.__variableName]<e.__value,lte:(t,e)=>t[e.__variableName]<=e.__value},Fo=(t,e)=>t==="count"?{type:"integer"}:e;class k{constructor(e={}){const{table:n,variableMetadata:r}=this.parseVariableMap(e);this.table=n,this.variableMetadata=r}static fromTrusted(e,n){const r=Object.create(k.prototype);return r.table=e,r.variableMetadata=n,r}size(){return this.table.numRows()}getVariableNames(){return this.table.columnNames()}hasVariable(e){return this.table.column(e)!==void 0}addVariable(e,n,r,s){const o={...this.variableMetadata,[e]:{type:n,valueFormat:this.resolveAddedVariableFormat(e,n,s)}},i=this.normalizeRawValues(n,r),a=this.table.assign(pe.table({[e]:i}));return k.fromTrusted(a,o)}addConstantVariable(e,n,r,s){const o={...this.variableMetadata,[e]:{type:n,valueFormat:this.resolveAddedVariableFormat(e,n,s),constant:{value:r}}},[i]=this.normalizeRawValues(n,[r]),a=this.table.assign(pe.table({[e]:Array(this.size()).fill(i)}));return k.fromTrusted(a,o)}getConstant(e){return this.variableMetadata[e]?.constant}deriveVariable(e,n,r,s){const o=Array.from({length:this.size()},(i,a)=>r(this.table.object(a)));return this.addVariable(e,n,o,s)}renameVariable(e,n){const r=this.variableMetadata[e];if(!r)throw new A({message:`Variable ${e} not defined`});const s=this.table.rename({[e]:n}),{[e]:o,...i}=this.variableMetadata,a={...i,[n]:r};return k.fromTrusted(s,a)}selectVariables(...e){const n=this.table.select(...e),r=Object.fromEntries(Object.entries(this.variableMetadata).filter(([s])=>e.includes(s)));return k.fromTrusted(n,r)}getType(e){const n=this.variableMetadata[e];if(!n)throw new A({message:`Variable ${e} not defined`});return n.type}getValueFormat(e){const n=this.variableMetadata[e];if(!n)throw new A({message:`Variable ${e} not defined`});return n.valueFormat}groupVariableNamesByType(){const e={numeric:[],categorical:[],temporal:[]};for(const[n,{type:r}]of Object.entries(this.variableMetadata))e[r].push(n);return e}getValues(e,n){if(!this.hasVariable(e))throw new A({message:`Variable '${e}' not defined`});const r=this.getType(e);if(n?.type!==void 0&&r!==n.type)throw new A({message:`Variable '${e}' has type '${r}', expected '${n.type}'`});let s=this.table.array(e);return n?.distinct&&(s=this.getDistinctValues(r,s)),n?.skipNulls&&(s=this.skipNulls(s)),s}filter(e,n,r){const s=Oc[n],o=this.table.params({__variableName:e,__value:r}).filter(s);return k.fromTrusted(o,this.variableMetadata)}filterByMask(e){if(e.length!==this.size())throw new A({message:`Row mask length ${e.length} does not match dataset size ${this.size()}`});const n=Array.from({length:e.length},(s,o)=>o),r=this.table.assign(pe.table({[ts]:n})).params({__indexColumnName:ts,__mask:e}).filter((s,o)=>o.__mask[s[o.__indexColumnName]]===1).select(...this.table.columnNames());return k.fromTrusted(r,this.variableMetadata)}orderBy(e,n="asc"){const r=this.table.orderby(n==="asc"?e:pe.desc(e));return k.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(e){for(let n=this.size()-1;n>=0;n--){const r=this.table.object(n);if(e(r))return r}return null}groupBy(...e){const n=this.table.groupby(...e);return new Bc(e,n,this.variableMetadata)}rollup(e){const n=this.table.rollup(Object.fromEntries(Object.entries(e).map(([s,o])=>[s,pe.op[o.aggregation](o.variableName)]))),r={};for(const[s,{variableName:o,aggregation:i}]of Object.entries(e)){const a=this.variableMetadata[o],c=a?.type??"numeric",l=a?.valueFormat??ot[c],d=Ro(i,c);r[s]={type:d,valueFormat:Fo(i,l)}}return k.fromTrusted(n,r)}reshapeFromWideToLong({keep:e,reshape:n,keyName:r=Po,valueName:s=Nc}={}){const{numeric:o,categorical:i,temporal:a}=this.groupVariableNamesByType(),c=e??[...i,...a],l=n??o.filter(f=>!c.includes(f));if(c.includes(r)||c.includes(s))throw new O({code:"INVALID_DATA_SHAPE",message:`The variables to keep includes the variables '${r}' or '${s}' to create the key and value variables`});if(l.length===0){const f={};for(const b of c){const y=this.variableMetadata[b];y&&(f[b]={type:y.type,values:[],valueFormat:y.valueFormat})}return f[r]={type:"categorical",values:[],valueFormat:{type:"text"}},f[s]={type:"numeric",values:[],valueFormat:{type:"decimal"}},new k(f)}if(l.filter(f=>this.variableMetadata[f]?.type!=="numeric").length>0)throw new O({code:"INVALID_DATA_SHAPE",message:"Only numeric variables can be reshaped"});const m=this.table.select([...c,...l]).fold(l,{as:[r,s]}),p={};for(const f of c){const b=this.variableMetadata[f];b&&(p[f]=b)}return p[r]={type:"categorical",valueFormat:{type:"text"}},p[s]={type:"numeric",valueFormat:Gc(this.variableMetadata,l,r)},k.fromTrusted(m,p)}print(){console.table(this.variableMetadata),this.table.print()}[Symbol.iterator](){return this.table[Symbol.iterator]()}resolveAddedVariableFormat(e,n,r){if(r!==void 0)return r;const s=this.variableMetadata[e];return s?s.valueFormat:ot[n]}parseVariableMap(e){const n={},r={};for(const[o,{type:i,values:a,valueFormat:c}]of Object.entries(e))n[o]=a,r[o]={type:i,valueFormat:c??ot[i]};return{table:pe.table(n),variableMetadata:r}}normalizeRawValues(e,n){switch(e){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)||!_.isValid(r)?null:r);default:{const r=e;throw new A({message:`Cannot normalize raw value of unknown type: ${r}`})}}}skipNulls(e){return e.filter(n=>n!==null)}getDistinctValues(e,n){const r=e==="temporal",s=new Set,o=[];for(const i of n){const a=r&&i instanceof Date?i.getTime():i;s.has(a)||(s.add(a),o.push(i))}return o}}class Bc{constructor(e,n,r){this.groupedBy=e,this.grouped=n,this.variableMetadata=r}forEach(e){const n=this.grouped.partitions(),r=this.grouped.columnNames(),s=this.groupedBy.map(i=>this.grouped.column(i)).filter(i=>i!==void 0);let o=0;for(const i of n){const a=i[0];if(a===void 0)continue;const c=this.getStableKey(s,a),l=Object.fromEntries(r.map(u=>{const m=this.grouped.column(u);return[u,i.map(p=>m?.get(p))]})),d=pe.table(l);e(k.fromTrusted(d,this.variableMetadata),c,o++)}}rollup(e){const n=this.grouped.rollup(Object.fromEntries(Object.entries(e).map(([s,o])=>[s,pe.op[o.aggregation](o.variableName)]))),r=Object.fromEntries(this.groupedBy.map(s=>{const o=this.variableMetadata[s],i=o?.type??"categorical",a=o?.valueFormat??ot[i];return[s,{type:i,valueFormat:a}]}));for(const[s,{variableName:o,aggregation:i}]of Object.entries(e)){const a=this.variableMetadata[o],c=a?.type??"numeric",l=a?.valueFormat??ot[c],d=Ro(i,c);r[s]={type:d,valueFormat:Fo(i,l)}}return k.fromTrusted(n,r)}getStableKey(e,n){return I(e.map(r=>r.get(n)))}}function Gc(t,e,n){const r=e.map(c=>t[c]?.valueFormat??{type:"decimal"}),[s,...o]=r;if(!s)return{type:"decimal"};for(const c of r)if(c.type==="lookup")throw new O({code:"INVALID_DATA_SHAPE",message:"Cannot reshape: a source column has a lookup format and lookups cannot nest"});if(o.every(c=>He.isEqual(c,s))||s.type==="lookup")return s;const a={};for(const[c,l]of e.entries()){const d=I([l]),u=r[c];u&&u.type!=="lookup"&&(a[d]=u)}return{type:"lookup",byVariable:n,cases:a,fallback:s}}function $c(t,e="kind"){const n=new Map;n.set(e,[]);for(const s of t)for(const o of s.observations)for(const i of Object.keys(o))n.has(i)||n.set(i,[]);for(const s of t)for(const o of s.observations)for(const[i,a]of n)a.push(i===e?s.kind:o[i]??null);const r={};for(const[s,o]of n)r[s]={type:No(o),values:o};return new k(r)}function No(t){const e=Array.isArray(t)?t:[t];for(const n of e)if(n!==null)return typeof n=="number"?"numeric":n instanceof Date?"temporal":"categorical";return"categorical"}class Wc extends xe{dependencies(e){return[e.data,e.mapping]}run(e){let n=e.data,r=e.mapping;r.x===""&&(n=n.addConstantVariable(it.x,"categorical",""),r={...r,x:it.x});for(const s of Object.keys(r)){const o=ce(r[s]);if(o===void 0)continue;const i=w(`const_${s}`);n=n.addConstantVariable(i,No(o),o),r={...r,[s]:i}}return{data:n,mapping:r}}}const zc=(t,e)=>{let n=e;for(const r of Object.keys(e)){const s=e[r];if(typeof s!="string")continue;const o=t.getConstant(s);o!==void 0&&(n={...n,[r]:s===it.x?"":{value:o.value}})}return n};class Ke{constructor(){this.perLayerMemo=so(),this.listMemo=Ba()}get stats(){return Ga(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const n=this.dependencies(e),r=e.layers.map(s=>this.perLayerMemo(s,n,()=>this.compileLayer(s,e)));return this.listMemo(r,()=>r)}}class Hc extends xe{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.scales,e.layers]}run(e){return this.registry.get(e.coordSpec.coordType).setup(e)}}class Yc extends Ke{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,n){const r=this.registry.get(n.coordSpec.coordType),[s]=r.transform({coordSpec:n.coordSpec,coordSystem:n.coordSystem,layers:[e]});if(!s)throw new A({message:`CoordCompiler: strategy '${n.coordSpec.coordType}' did not return a transformed layer`});return s}}class Uc{constructor(e){this.setupStage=new Hc(e),this.transformStage=new Yc(e)}get setupStats(){return this.setupStage.stats}get transformStats(){return this.transformStage.stats}setup(e){return this.setupStage.compile(e)}transform(e){return this.transformStage.compile(e)}}class Xe{constructor(e){this.label=e,this.items=new Map}register(e,n){return this.items.set(e,n),this}get(e){if(!this.items.has(e)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new O({code:"UNKNOWN_REGISTERED_TYPE",message:`Unknown ${this.label}: '${e}' (available: ${n})`,context:{kind:this.label,requested:e,available:[...this.items.keys()]},suggestion:`Register a custom ${this.label} named '${e}' in the \`plugins\` array, or use one of: ${n}.`})}return this.items.get(e)}getAll(){return[...this.items.values()]}has(e){return this.items.has(e)}}class Kc{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new A({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}},scales:e.scales}}transform(e){return e.layers}}class Xc{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new A({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});return{coordSystem:{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"left",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}},scales:qc(e.scales,e.layers)}}transform(e){return e.layers.map(n=>Qc(n))}}const jc=[[g.x,g.y],[g.xMin,g.yMin],[g.xMax,g.yMax]],ns=w("flipSwap"),qc=(t,e)=>Zc(e)?t.map(n=>n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"&&n.scaleType!=="discrete"?n:{...n,reverse:!n.reverse}):t,Zc=t=>{for(const e of t){const n=x(e.mapping.x);if(!n||!e.data.hasVariable(n))continue;const r=e.data.getType(n);if(r==="categorical"||r==="temporal")return!0}return!1},Qc=t=>{let e=t.data;for(const[n,r]of jc){const s=e.hasVariable(n),o=e.hasVariable(r);s&&o?e=e.renameVariable(n,ns).renameVariable(r,n).renameVariable(ns,r):s?e=e.renameVariable(n,r):o&&(e=e.renameVariable(r,n))}return{...t,data:e}},Ie=Math.PI*2,On=8,Jc=1e-9,$e=t=>(t%Ie+Ie)%Ie,Oo=(t,e,n)=>{const r=n-e;if(Math.abs(r)>=Ie-Jc)return!0;const s=$e(r);return $e(t-e)<=s},Ct=(t,e)=>{const n=Math.abs($e(t)-$e(e));return Math.min(n,Ie-n)},Bo=(t,e,n)=>t*Ie+e+n,Dt=(t,e)=>({x:e*Math.sin(t),y:e*Math.cos(t)}),Go=(t,e)=>({angle:$e(Math.atan2(t,e)),radius:Math.hypot(t,e)}),Jn=(t,e)=>{const n=t.x-.5,r=t.y-.5;return{x:e>=1?n*2*e:n*2,y:e>=1?r*2:r*2/e}},Ut=(t,e)=>{const{x:n,y:r}=Jn(t,e);return Go(n,r)};function $o(t){const e=new Set,n=[];for(const r of t){const s=r instanceof Date?r.getTime():String(r);e.has(s)||(e.add(s),n.push(r))}return n}const Wo=(t,e)=>{const n=e.domain!==null&&e.domain.length>0?e.domain:t;return $o(n)};class el{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new A({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:n}=e.coordSpec,r=n.startAngle*(Math.PI/180),s=rl(n,e.scales,e.layers),o=ol(n,e.scales,e.layers);return{coordSystem:{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"}},innerRadius:n.innerRadius,startAngle:r,spokeRotation:s,bandAxis:o},scales:e.scales}}transform(e){if(e.coordSpec.coordType!=="polar")throw new A({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new A({message:"PolarCoord.transform received a non-polar coord system"});const{params:n}=e.coordSpec,{startAngle:r,spokeRotation:s}=e.coordSystem,o=nl(r,s),i=il(n);return e.layers.map(a=>{const c=n.theta==="y"?cl(a):a;return al(c,o,i)})}}const tl=[[g.x,g.y],[g.xMin,g.yMin],[g.xMax,g.yMax]];function nl(t,e){return n=>Bo(n,t,e)}function rl(t,e,n){const r=e.find(o=>o.scaledAesthetic===t.theta);if(r===void 0||r.scaleType!=="discrete")return 0;const s=sl(r,t,n);return s===0?0:-Math.PI/s}function sl(t,e,n){const r=[];for(const o of n){const i=x(o.mapping[e.theta]);if(!(i===null||!o.data.hasVariable(i)))for(const a of o.data.getValues(i))r.push(a)}return Wo(r,t).length}function ol(t,e,n){if(t.theta==="x")return"x";const s=e.find(i=>i.scaledAesthetic==="x")?.scaleType==="discrete",o=n.some(i=>i.position==="fill");return s&&!o?"y":null}function il(t){const{innerRadius:e}=t;return n=>e+n*(1-e)}function al(t,e,n){let r=t.data;return r=De(r,g.x,e),r=De(r,g.xMin,e),r=De(r,g.xMax,e),r=De(r,g.y,n),r=De(r,g.yMin,n),r=De(r,g.yMax,n),{...t,data:r}}function De(t,e,n){if(!t.hasVariable(e))return t;const s=t.getValues(e,{type:"numeric"}).map(o=>o===null?null:n(o));return t.addVariable(e,"numeric",s)}function cl(t){let e=t.data;for(const[n,r]of tl){const s=e.hasVariable(n),o=e.hasVariable(r);if(!s&&!o)continue;const i=s?e.getValues(n):null,a=o?e.getValues(r):null;i&&(e=e.addVariable(r,"numeric",i)),a&&(e=e.addVariable(n,"numeric",a))}return{...t,data:e}}class ll extends Xe{constructor(){super("coord"),this.register("cartesian",new Kc),this.register("flip",new Xc),this.register("polar",new el)}}const ul=(t,e)=>{const n=typeof t=="string"?t.trim():t;if(Ve(n))return{type:"decimal"};const r=typeof n=="string"&&wo(n,e);if(r)return r;const s=typeof n=="string"&&ac(n,e);return s||(Ao(t)?{type:"date"}:co(t)?{type:"percentage"}:uo(t)&&typeof t=="string"?{type:"currency",iso:Xa(t)}:{type:"text"})},dl={type:"year",dateFormat:"yyyy"};class ml extends xe{dependencies(e){return[e]}run(e){const n=e._metadata?.parsingLocale??Ht,r={},s=hl(e),o=pl(e);for(const[i,a]of e.columns.entries()){if(a._metadata?.isHidden)continue;const c=s.get(a.key);if(mt(c))continue;const l=i===o?dl:ul(c,n),d=go(l);r[a.key]=fl(a.key,e.rows,l,d,n)}return new k(r)}}const pl=t=>{const e=gl(t.rows,5);return t.columns.findIndex(n=>{const r=e.map(s=>s[n.key]).filter(s=>!mt(s));return r.length>=2&&r.every(ic)})},fl=(t,e,n,r,s)=>{const o=e.reduce((i,a)=>(fo(a)||i.push(kt(a[t],n,s)),i),[]);return{type:r,values:o,valueFormat:n}},hl=t=>{const e=new Map,n=new Set(t.columns.map(r=>r.key));for(const r of t.rows){for(const s of n){const o=r[s];mt(o)||(e.set(s,o),n.delete(s))}if(n.size===0)break}return e},gl=(t,e)=>{const n=[];for(const r of t)if(fo(r)||n.push(r),n.length===e)return n;return n},yl=new Set(["min","max","scalar"]),bl={x:{min:g.xMin,max:g.xMax},y:{min:g.yMin,max:g.yMax}};function xl(t){const e=new Set;for(const n of t)n.role==="point"?e.add(n.axis):(n.role==="min"||n.role==="max")&&h(n.aes)&&e.add(n.aes);return[...e]}function vl(t){const e=new Set;for(const n of t)n.role==="point"&&e.add(n.axis),h(n.aes)&&e.add(n.aes);return[...e]}function Sl(t,e,n){let r=t;for(const s of e){if(s.role!=="min"&&s.role!=="max"||!h(s.aes))continue;const o=bl[s.axis][s.role];if(r.hasVariable(o))continue;const i=x(n[s.aes]);!h(i)||!r.hasVariable(i)||(r=r.addVariable(o,"numeric",r.getValues(i,{type:"numeric"})))}return r}class Al{constructor(e){this.container=e}compile(e,n){const r=this.container.geomRegistry.get(e),s=r.compile(n),o={...n.mapping,...s.mapping};return{...s,data:Sl(s.data,r.positionRoles,o)}}}const zo=new Set(["x","y","ySecondary"]),Kt=new Set(["color","size","alpha","strokeWidth","lineType"]),Xt=t=>zo.has(t),er=t=>Kt.has(t),wl=t=>Xt(t)||er(t);function je(t){return t==="secondary"?"ySecondary":"y"}function Ho(t,e){return t==="y"?je(e):"x"}function te(t){return t==="ySecondary"?"y":t}const tr=(t,e)=>{if(h(e.group)){const s=x(e.group);if(s!==null)return[s]}const n=new Set([x(e.x),x(e.y)].filter(h)),r=new Set;for(const s of Kt){const o=x(e[s]);h(o)&&(n.has(o)||t.hasVariable(o)&&t.getType(o)==="categorical"&&r.add(o))}return[...r]};class Tl{compute({data:e,mapping:n}){const r=tr(e,n);if(r.length===0)return{data:e.addConstantVariable(z.group,"categorical",null)};const s=e.size(),o=r.map(a=>e.getValues(a)),i=new Array(s);for(let a=0;a<s;a++)i[a]=I(o.map(c=>c[a]));return{data:e.addVariable(z.group,"categorical",i)}}}const Ml=t=>{if(t===void 0)return{};const e={};for(const n of t.columns)n.label!==void 0&&(e[n.key]=n.label);return e},Ll=(t,e,n)=>{const r=ke(e,"color");return r===null?{}:(t?.columns??[]).some(i=>i.key===r)?{}:n};function ke(t,e){const n=te(e);for(const r of Yo(e,t)){const s=x(r.mapping[n]);if(h(s))return s}return null}const nr=(t,e)=>t===null?null:e[t]??t,Il=(t,e)=>t===null?null:e[String(t)]??null,_e=({layers:t,scaleType:e,variableName:n})=>{if(n===null)return xn(e);for(const r of t){if(!r.data.hasVariable(n))continue;const s=r.data.getValueFormat(n),o=s.type==="lookup"?s.fallback:s;return Vl(o,e)?o:xn(e)}return xn(e)},El=(t,e)=>e!=="y"&&e!=="ySecondary"?!1:Yo(e,t).some(n=>n.position==="fill");function Yo(t,e){return t==="ySecondary"?e.filter(n=>n.yScaleType==="secondary"):t==="y"?e.filter(n=>n.yScaleType==="primary"):e}const xn=t=>{switch(t){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Vl=(t,e)=>{switch(e){case"continuous":return jn(t);case"datetime":return Ye(t);case"discrete":case"palette":case"identity":return!0}},kl=[{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}],rs={year:0,quarter:1,month:2,week:3,day:4,hour:5},Re=40,_l=(t,e,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return Pl(n.unit).range(t,new Date(e.valueOf()+1),r)},Cl=({unit:t,step:e,start:n,stop:r})=>{const s=Da.differenceInDays(r,n);switch(t){case"hour":return 24*s/e>Re;case"day":return s/e>Re;case"week":return s/(7*e)>Re;case"month":return s/(30*e)>Re;case"quarter":return s/(90*e)>Re;case"year":return s/(365*e)>Re}},Dl=(t,e)=>{const n=!Zn(e);switch(t.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"}}},Rl=(t,e)=>{const n=Fl(e);return n===null?!1:rs[t]>rs[n]},Pl=t=>{switch(t){case"hour":return Qe.utcHour;case"day":return Qe.utcDay;case"week":return Qe.utcMonday;case"month":case"quarter":return Qe.utcMonth;case"year":return Qe.utcYear}},Fl=t=>{switch(t.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}},Uo={left:"right",right:"left",top:"bottom",bottom:"top"},Nl={x:!0,y:!0,ySecondary:!1},Ol=20,ss=new Set(["top","bottom"]),Bl={type:"percentage"};function Gl(t,e){const{scales:n,config:r,layers:s,coordSystem:o,variableLabels:i,geomRegistry:a}=t;if(o.type==="polar"&&o.bandAxis===null)return[];const c=zl(a,s,o.type,r),l=new Set(e.map(m=>m.position)),d=Yl(Ko(r.axes.y.position,o.axisMapping.y.position),l),u=[];for(const m of zo){const p=n[m];if(!h(p)||p.kind!=="position")continue;const f=$l({scaleAestheticKey:m,scale:p,config:r,layers:s,axisMapping:o.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:i});u.push(f)}return u}function $l(t){const{scaleAestheticKey:e,scale:n,config:r,layers:s,axisMapping:o,resolvedYPosition:i,gridOverrides:a,variableLabels:c}=t,l=te(e),{axisConfig:d,position:u,geometry:m}=Hl(e,r,o,i),p=ke(s,e),f=El(s,e)?Bl:_e({layers:s,scaleType:n.spec.scaleType,variableName:p});return{scaleAestheticKey:e,aesthetic:l,position:u,geometry:m,label:Wl(d,p,c),isVisible:d.isVisible,tickCandidates:Kl(n,f,d.ticks.mode),valueFormat:f,tickMode:d.ticks.mode,ticksVisible:d.ticks.isVisible,gridVisible:Ul(d,a,e),gridLineStyle:d.grid.lineStyle,gridLineWidth:d.grid.lineWidth,scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function Wl(t,e,n){return t.label?t.label:e?n[e]??null:null}function zl(t,e,n,r){const s=e.flatMap(a=>{const c=t.get(a.geom).grid[n];return c?[c]:[]}),o=s.some(a=>a.hideGridX),i=s.some(a=>a.hideGridY);return{x:{gridVisible:os(o,r.axes.x.grid.isVisible)},y:{gridVisible:os(i,r.axes.y.grid.isVisible)}}}function os(t,e){if(t&&e===null)return!1}function Hl(t,e,n,r){switch(t){case"x":return{axisConfig:e.axes[t],position:Ko(e.axes[t].position,n[t].position),geometry:n.x.geometry};case"y":return{axisConfig:e.axes[t],position:r,geometry:n.y.geometry};case"ySecondary":{const s=Uo[r],o=He.merge({isVisible:e.axes.y.isVisible,label:null,position:s,grid:e.axes.y.grid,ticks:e.axes.y.ticks},e.axes.ySecondary);return{axisConfig:o,position:o.position,geometry:n.y.geometry}}}}function Ko(t,e){return ss.has(t)===ss.has(e)?t:e}function Yl(t,e){return e.has(t)?Uo[t]:t}function Ul(t,e,n){const{gridVisible:r}=n==="x"?e.x:e.y;return r??t.grid.isVisible??Nl[n]}const Kl=(t,e,n)=>{const r=t.spec.scaleType==="continuous"||t.spec.scaleType==="datetime";if(n==="edges"&&r){const o=jl(t);if(o)return[o]}if(t.spec.scaleType==="continuous"){const o=new Set,i=[];for(let a=1;a<=Ol;a++){const c=t.generateTicks({count:a}),l=I(c);o.has(l)||(o.add(l),i.push({ticks:c.map(d=>We(t,d))}))}return i}return t.spec.scaleType==="datetime"?Xl(t,e):[{ticks:t.generateTicks().map(o=>We(t,o))}]},Xl=(t,e)=>{const[n,r]=t.domain;if(!X(n)||!X(r))return[{ticks:t.generateTicks().map(c=>We(t,c))}];const s=new Set,o=[],i=(a,c)=>{if(a.length===0)return;const l=I(a);s.has(l)||(s.add(l),o.push({ticks:a.map(d=>We(t,d)),valueFormat:c}))};for(const a of kl)Cl({...a,start:n,stop:r})||Rl(a.unit,e)||i(t.generateTicks({interval:a}),Dl(a,e));return i(t.generateTicks({atInputs:!0})),o.sort((a,c)=>a.ticks.length-c.ticks.length),o},jl=t=>{const{domain:e}=t,n=e[0],r=e.at(-1);return!h(n)||!h(r)||I([n])===I([r])?null:{ticks:[We(t,n),We(t,r)]}},We=(t,e)=>({value:e,position:t.map(e)});function Xo({scale:t,aesthetics:e,layers:n}){const r=ql({layers:n,aesthetics:e}),s=jo({layers:n,aesthetics:e});return t.domain.map(o=>({value:o,geom:r(o),owner:s(o)}))}function ql({layers:t,aesthetics:e}){const n=jo({layers:t,aesthetics:e}),r=t.find(o=>e.some(i=>h(o.mapping[i]))),s=r?r.geom:"bar";return o=>{const i=n(o);return i?i.layer.geom:s}}function jo({layers:t,aesthetics:e,layerFilter:n}){const r=new Map;for(const[s,o]of t.entries()){if(n&&!n(o))continue;const i=e.find(c=>h(o.mapping[c]));if(i===void 0)continue;const a=x(o.mapping[i]);if(!(a===null||!o.data.hasVariable(a)))for(const c of o.data.getValues(a,{distinct:!0})){const l=I(c);r.has(l)||r.set(l,{layer:o,layerIndex:s})}}return s=>r.get(I(s))}const rr=t=>{if(t.kind==="identity")return!1;const e=t.spec.scaleType;return e!=="continuous"&&e!=="datetime"};function Zl({scales:t,layers:e,valueLabels:n}){const r=t.color;if(r===void 0||!rr(r))return[];if(!e.some(l=>h(l.mapping.color)))return[];const s=ke(e,"color");if(qo({colorVariableName:s,xVariableName:ke(e,"x"),mapsColorAcrossMultipleLayers:Jl(e)>1,isMergedWithAnotherAesthetic:Ql(t,e,s)}))return[];const i=r.spec.scaleType,a=e.findIndex(l=>h(l.mapping.color));return Xo({scale:r,aesthetics:["color"],layers:e}).map(({value:l,geom:d,owner:u})=>{const m=u?.layerIndex??a,p=e[m],f=p?x(p.mapping.color):null;return{value:l,color:String(r.map(l)),geom:d,layerIndex:m,valueFormat:_e({layers:p?[p]:e,scaleType:i,variableName:f}),label:Il(l,n)}})}const qo=({colorVariableName:t,xVariableName:e,mapsColorAcrossMultipleLayers:n,isMergedWithAnotherAesthetic:r})=>r?!1:t===null||Wa(t)?!n:e!==null&&t===e;function Ql(t,e,n){if(n===null)return!1;for(const r of Kt){if(r==="color")continue;const s=t[r];if(!(s===void 0||!rr(s))&&ke(e,r)===n)return!0}return!1}const Jl=t=>t.filter(e=>h(e.mapping.color)).length;function Zo(t,e){return t.get(e.geom).summaries.perGroupHeadline===!0}function eu(t,e,n,r){const s=n.findIndex(o=>Zo(t,o));if(s===-1)return[];if(e.length<2){const o=x(n[s]?.mapping.y);return[{value:null,swatch:null,layerIndex:s,groupLabelFormat:{type:"text"},label:nr(o,r)}]}return e.map(o=>({value:o.value,swatch:{color:o.color,geom:o.geom},layerIndex:o.layerIndex,groupLabelFormat:o.valueFormat,label:o.label}))}function is(t,e,n){if(n===null||e===null)return[...t];const r=I(n);return t.filter((s,o)=>I(e[o]??null)===r)}const tu=(t,e)=>{switch(e){case"total":{const{sum:n,count:r}=as(t);return r===0?null:n}case"average":{const{sum:n,count:r}=as(t);return r===0?null:n/r}case"current":return t.at(-1)??null}},nu=(t,e)=>{if(t.length<2)return null;const n=t.at(-1),r=e==="previous"?t.at(-2):t.at(0);return n===void 0||r===void 0||n.cross===null||r.cross===null||r.cross===0?null:{variation:(n.cross-r.cross)/r.cross,against:r.main}},as=t=>t.reduce((e,n)=>n===null?e:{sum:e.sum+n,count:e.count+1},{sum:0,count:0});function ru(t){const{config:e,coordSystem:n}=t,r=e.headline.show;return r==="none"||r==="conversion"?null:n.type==="polar"?su(t,r):ou(t,r)}function su(t,e){if(e!=="total")return null;const{scales:n,layers:r}=t,s=r.find(c=>c.summary.grandTotal!==void 0);if(s===void 0)return null;const o=s.summary.grandTotal;if(o===void 0)return null;const i=x(s.mapping.y);if(i===null)return null;const a=_e({layers:[s],scaleType:n.y?.spec.scaleType??"continuous",variableName:i});return{kind:"grandTotal",value:o,valueFormat:a}}function ou(t,e){const{config:n,scales:r,layers:s,variableLabels:o,colorGroups:i,geomRegistry:a}=t;if(!s.some(d=>Zo(a,d)))return null;const c=eu(a,i,s,o);if(c.length===0)return null;const l=c.map(d=>iu({group:d,show:e,compareWith:n.headline.compareWith,layers:s,scales:r})).filter(d=>d!==null);return l.length===0?null:{kind:"perGroup",items:l}}function iu({group:t,show:e,compareWith:n,layers:r,scales:s}){const o=r[t.layerIndex];if(o===void 0)return null;const i=x(o.mapping.y);if(i===null||e==="total"&&o.position==="fill")return null;const a=x(o.mapping.x),c=x(o.mapping.color),l=o.yScaleType==="secondary"?s.ySecondary:s.y,d=_e({layers:[o],scaleType:l?.spec.scaleType??"continuous",variableName:i}),u=lu(o.data,a),m=_e({layers:[o],scaleType:u?"datetime":s.x?.spec.scaleType??"discrete",variableName:a}),p=uu(o.data,a),f=p.getValues(i,{type:"numeric"}),b=a!==null?p.getValues(a):[],y=c!==null?p.getValues(c):null,v=is(f,y,t.value),S=is(b,y,t.value);return{value:t.value,swatch:t.swatch,aggregate:tu(v,e),valueFormat:d,groupLabelFormat:t.groupLabelFormat,mainValueFormat:m,label:t.label,observationLabel:au(e,u,S),comparison:cu(e,n,u,S,v)}}function au(t,e,n){if(t==="current"){const o=n.at(-1);return o===void 0?null:{kind:"point",value:o}}if(!e)return null;const r=n.at(0),s=n.at(-1);return r===void 0||s===void 0?null:{kind:"range",from:r,to:s}}function cu(t,e,n,r,s){if(t!=="current"||!n)return null;const o=e==="none"?"first":e,i=r.map((a,c)=>({main:a,cross:s[c]??null}));return nu(i,o)}function lu(t,e){return e!==null&&t.hasVariable(e)&&t.getType(e)==="temporal"}function uu(t,e){return e===null||!["numeric","temporal"].includes(t.getType(e))?t:t.orderBy(e)}function j(t){return t==="stack"||t==="fill"}function W(t){return t[g.x]}function C(t){return t[g.y]}function le(t){return t[g.xMin]}function oe(t){return t[g.xMax]}function Z(t){return t[g.yMin]}function Y(t){return t[g.yMax]}function Qo(t){return t[g.yRaw]}function du(t,e){return t[ao(e)]}const mu=3;function pu({scales:t,config:e,layers:n,coordSystem:r,variableLabels:s,colorGroups:o,geomRegistry:i}){if(e.legend.position==="none")return[];const a=new Map(o.map(y=>[I(y.value),y])),c=gu({scales:t,layers:n}),l=vu(c),d=ke(n,"x"),u=l.map(y=>{if(bu(y,d,n))return null;const v=Au({group:y,variableLabels:s,layers:n,colorGroupsByValue:a});return v.items.length===0?null:{group:y,built:v}}).filter(h);if(u.length===0)return[];const m=fu(u);if(e.legend.position==="auto"&&Iu(i,m,n,r))return[];const p=Eu(i,e.legend.position,m,n,r),f=ku(i,e.legend.display,p,n,r),b=f==="direct"?Ru(n):null;return u.map(({built:y})=>hu(y,p,f,b))}function fu(t){return t.reduce((e,{group:n,built:r})=>{const s=n.some(o=>o.guideType!=="discrete");return e+(s?1:r.items.length)},0)}function hu(t,e,n,r){return n!=="direct"||r===null?{...t,position:e,display:n}:{...t,position:e,display:n,items:t.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function gu(t){const{scales:e,layers:n}=t,r=[];for(const s of Kt){const o=e[s];if(o===void 0||o.kind==="identity"||!yu(s,n))continue;const i=ke(n,s),a=Du(s,o);r.push({scaleAestheticKey:s,scale:o,variableName:i,guideType:a})}return r}function yu(t,e){const n=te(t);return e.some(r=>h(r.mapping[n]))}function bu(t,e,n){const[r]=t;return r.scaleAestheticKey!=="color"?!1:qo({colorVariableName:r.variableName,xVariableName:e,mapsColorAcrossMultipleLayers:xu(r.scaleAestheticKey,n),isMergedWithAnotherAesthetic:t.length>1})}function xu(t,e){const n=te(t);return e.filter(r=>h(r.mapping[n])).length>1}function vu(t){const e=new Map;for(const n of t){const r=Cu(n),s=e.get(r);s?s.push(n):e.set(r,[n])}return[...e.values()]}function Su(t,e,n){if(e==="lineType"){t.lineType=n;return}if(e==="color"){t.color=String(n);return}t[e]=n}function Au({group:t,variableLabels:e,layers:n,colorGroupsByValue:r}){const s=t[0],o=t.map(c=>te(c.scaleAestheticKey)),i=Xo({scale:s.scale,aesthetics:o,layers:n}),a=_e({layers:n,scaleType:s.scale.spec.scaleType,variableName:s.variableName});return{aesthetics:t.map(c=>c.scaleAestheticKey),title:nr(s.variableName,e),items:i.map(c=>wu(c,t,o,a,r))}}function wu(t,e,n,r,s){const o={};for(const a of e)Su(o,a.scaleAestheticKey,a.scale.map(t.value));const i=Mu(t,e,n,r,s);return{value:t.value,label:Tu(e,t,s),visual:o,normalizedY:null,geom:t.geom,valueFormat:i}}function Tu(t,e,n){return t[0].scaleAestheticKey!=="color"?null:n.get(I(e.value))?.label??null}function Mu(t,e,n,r,s){if(e[0].scaleAestheticKey==="color")return s.get(I(t.value))?.valueFormat??r;const o=t.owner?.layer,i=Lu(o,n);return o===void 0||i===null?r:_e({layers:[o],scaleType:e[0].scale.spec.scaleType,variableName:i})}function Lu(t,e){if(t===void 0)return null;for(const n of e){const r=t.mapping[n];if(r===void 0)continue;const s=x(r);if(s!==null)return s}return null}function Iu(t,e,n,r){if(e>1)return!1;const s=r.type==="polar";return n.some(o=>t.get(o.geom).legend.suppressWhenSingleItem||s)}function Eu(t,e,n,r,s){if(e!=="auto")return e;if(s.type==="polar")return"top";let o=!1,i=!1,a=!1;for(const l of r){const{sidePlacement:d}=t.get(l.geom).legend;d==="whenCrowded"&&(o=!0),d==="whenStackedVertical"&&(i=!0,j(l.position)&&(a=!0))}const c=n>=mu;return o&&i?"top":o?c?"right":"top":a?_u(s)?"top":c?"right":"top":"top"}function Vu(t,e){if(e.length!==1)return!1;const n=e[0];return n?t.get(n.geom).legend.directLabelSupport?.[n.position]===!0:!1}function ku(t,e,n,r,s){if(!(n==="right"&&s.type==="cartesian"&&s.mainAxis==="x"))return"pill";switch(e){case"pill":return"pill";case"direct":return"direct";case"auto":return Vu(t,r)?"direct":"pill"}}function _u(t){return t.type==="cartesian"&&t.mainAxis==="y"}function Cu(t){const e=t.scale.domain.map(I);return JSON.stringify([t.variableName,t.guideType,...e])}function Du(t,e){return rr(e)?"discrete":`continuous:${t}`}function Ru(t){const e=t[0];if(!e)return new Map;const n=new Map;return e.data.groupBy(z.group).forEach(r=>{const s=r.findLast(l=>h(Y(l))||h(C(l)));if(!s)return;const o=Ue(s);if(!h(o))return;const i=Z(s),a=Y(s)??C(s);if(!h(a))return;const c=h(i)?(i+a)/2:a;n.set(String(o),c)}),n}class Pu extends xe{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config.axes,e.config.legend,e.config.headline,e.config.panel,e.layers,e.coordSystem,e.originalData]}run(e){const n=Ml(e.originalData),r=Zl({scales:e.scales,layers:e.layers,valueLabels:Ll(e.originalData,e.layers,n)}),s={scales:e.scales,config:e.config,layers:e.layers,coordSystem:e.coordSystem,variableLabels:n,colorGroups:r,geomRegistry:this.container.geomRegistry},o=ru(s),i=Nu(o,pu(s));return{axes:Gl(s,i),legends:i,headline:o,panel:{border:Fu(e.config.panel.border)},colorGroups:r,variableLabels:n}}}const Fu=t=>{const e=n=>({isVisible:t[n].isVisible,lineStyle:t[n].lineStyle,lineWidth:t[n].lineWidth});return{top:e("top"),right:e("right"),bottom:e("bottom"),left:e("left")}},Nu=(t,e)=>t?.kind!=="perGroup"||e.some(r=>r.display==="direct")?e:[],Ou=t=>I([Ue(t)]),sr=(t,e)=>{const n=e!==null?t[e]??null:null;return I([n])},Q=(t,e)=>{const n=ce(e);if(n!==void 0)return()=>n;const r=x(e);return h(r)?s=>{const o=s[r];if(o===void 0)return null;switch(t.getType(r)){case"numeric":return D(o)?o:null;case"categorical":return zt(o)?o:null;case"temporal":return X(o)?o:null;default:return null}}:()=>null},jt=(t,e)=>Q(t,e.x),Jo=(t,e)=>Q(t,e.y),Bu=(t,e)=>Q(t,e.label),ei=(t,e)=>Q(t,e.color),Gu=(t,e)=>Q(t,e.size),$u=(t,e)=>Q(t,e.alpha),Wu=(t,e)=>Q(t,e.group),zu=(t,e)=>Q(t,e.strokeWidth),cs={variable:g.yRaw};function qt(t,e){return j(t)?cs:e.y??cs}function Zt(t){return Q(t.data,qt(t.position,t.mapping))}const Hu=["lt","lte","gt","gte","range"];function Tt(t,e){if("and"in t){const n=t.and.map(r=>Tt(r,e));return r=>{for(const s of n)if(!s(r))return!1;return!0}}if("or"in t){const n=t.or.map(r=>Tt(r,e));return r=>{for(const s of n)if(s(r))return!0;return!1}}if("not"in t){const n=Tt(t.not,e);return r=>!n(r)}return Uu(t,e)}function Mt(t,e){return"and"in t?t.and.flatMap(n=>Mt(n,e)):"or"in t?t.or.flatMap(n=>Mt(n,e)):"not"in t?Mt(t.not,e):Yu(t,e)}function Yu(t,e){if(!e.hasVariable(t.variable))return[{code:"UNKNOWN_VARIABLE",message:`Highlight predicate references unknown variable '${t.variable}' — dropping this highlight.`,context:{variableName:t.variable},suggestion:`Map '${t.variable}' in the layer or correct the variable name in the predicate.`}];const n=Ku(t);return n!==null&&e.getType(t.variable)==="categorical"?[{code:"INVALID_HIGHLIGHT_OPERATOR",message:`Highlight predicate uses ordering operator '${n}' on categorical variable '${t.variable}' — dropping this highlight. Use 'eq' or 'oneOf' instead.`,context:{variableName:t.variable},suggestion:"Use 'eq' or 'oneOf' for categorical variables."}]:[]}const ls=()=>!1;function Uu(t,e){if(!e.hasVariable(t.variable))return ls;const n=Nn(e.getValueFormat(t.variable)),r=s=>kt(s,n,e.parsingLocale);if("eq"in t){const s=r(t.eq);return o=>Vt(e.readValue(o,t.variable),s)}if("oneOf"in t){const s=t.oneOf.map(r);return o=>{const i=e.readValue(o,t.variable);for(const a of s)if(Vt(i,a))return!0;return!1}}if("lt"in t){const s=r(t.lt);return o=>Pe(e.readValue(o,t.variable),s)==="less"}if("lte"in t){const s=r(t.lte);return o=>{const i=Pe(e.readValue(o,t.variable),s);return i==="less"||i==="equal"}}if("gt"in t){const s=r(t.gt);return o=>Pe(e.readValue(o,t.variable),s)==="greater"}if("gte"in t){const s=r(t.gte);return o=>{const i=Pe(e.readValue(o,t.variable),s);return i==="greater"||i==="equal"}}if("range"in t){const[s,o]=t.range,i=r(s),a=r(o);return c=>{const l=e.readValue(c,t.variable),d=Pe(l,i),u=Pe(l,a);return d==="incomparable"||u==="incomparable"?!1:(d==="greater"||d==="equal")&&(u==="less"||u==="equal")}}return ls}function Ku(t){for(const e of Hu)if(e in t)return e;return null}function Pe(t,e){if(t===null||e===null)return"incomparable";if(X(t)&&X(e)){const n=t.getTime(),r=e.getTime();return n<r?"less":n>r?"greater":"equal"}return D(t)&&D(e)?t<e?"less":t>e?"greater":"equal":"incomparable"}const Xu={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor"};function ti(t){const e=Xu[t]??null;return e===null?null:{strategy:e,composition:ni()}}function ni(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}class ju extends Ke{constructor(e){super(),this.container=e}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,n){const r=e.highlight;if(r===null)return e;const s=n.highlights.filter(({layerId:i})=>i===void 0||i===e.id);if(s.length===0)return e;const o=qu({layer:e,highlights:s,parsingLocale:n.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:o}}}}function qu({layer:t,highlights:e,parsingLocale:n,strategy:r,container:s}){const o=e.filter(M=>{const U=Mt(M.predicate,t.data);for(const ie of U)s.diagnostics.addWarning(ie);return U.length===0}),i=x(t.mapping.x),a=Zu(t,n),c=o.map(M=>({predicate:Tt(M.predicate,a),scope:M.scope})),l=c.some(({scope:M})=>M==="series"),d=c.some(({scope:M})=>M==="x-value"),u=r==="overlay-anchor",m=t.data.size(),p=l?new Array(m):null,f=d?new Array(m):null,b=u?new Array(m):null,y=new Uint8Array(m),v=new Set,S=new Set;let T=!1,V=0;for(const M of t.data){let U,ie;p!==null&&(U=Ou(M),p[V]=U),f!==null&&(ie=sr(M,i),f[V]=ie),b!==null&&(b[V]=M);for(const{predicate:ht,scope:gt}of c)if(ht(M))switch(gt){case"series":U!==void 0&&v.add(U);break;case"x-value":ie!==void 0&&S.add(ie);break;case"data-point":y[V]=1,T=!0;break}V++}if(v.size===0&&S.size===0&&!T)return ni();const F=new Uint8Array(m),ue=[];let J=0;for(let M=0;M<m;M++){const U=p?.[M],ie=f?.[M],ht=U!==void 0&&v.has(U),gt=ie!==void 0&&S.has(ie),jr=y[M]===1;if(r==="observation-rerender")(ht||jr||gt)&&(F[M]=1,J++);else if(ht)F[M]=1,J++;else if(jr||gt){const qr=b?.[M];qr!==void 0&&ue.push({observation:qr,observationIndex:M})}}const de=J>0?{...t,data:t.data.filterByMask(F)}:null;return{isDimmed:(r==="observation-rerender"||v.size>0)&&de!==null,matchedLayer:de,overlayCandidates:ue}}function Zu(t,e){const n=x(t.mapping.y),r=Zt(t);return{hasVariable:s=>t.data.hasVariable(s),getType:s=>t.data.getType(s),getValueFormat:s=>t.data.getValueFormat(s),readValue:(s,o)=>n!==null&&o===n?r(s):s[o]??null,parsingLocale:e}}const Qu=w("__ungrouped__");function Ju(t){const e=t.getVariableNames().filter(s=>t.getType(s)==="temporal"&&Zn(t.getValueFormat(s)));if(e.length===0)return t;const n=t.getValues(z.group,{type:"categorical"});let r=t;for(const s of e){const o=r.getValues(s,{type:"temporal"}),i=new Map,a=o.map((c,l)=>{if(c===null)return null;const d=n[l]??Qu;let u=i.get(d);return u||(u=new yo,i.set(d,u)),u.incrementYearIfNeeded(c)});r=r.addVariable(s,"temporal",a)}return r}class ed extends Ke{constructor(e,n,r,s,o,i){super(),this.container=e,this.transformCompiler=n,this.statCompiler=r,this.groupCompiler=s,this.geomCompiler=o,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,us(e)]}compileLayer(e,n){const r=this.transformCompiler.compile({data:n.data,transforms:e.transforms}),s={...n.mapping,...e.mapping};return this.runLayerPipeline(e,r,s,us(n))}runLayerPipeline(e,n,r,s){const o=$t({data:n,mapping:r}).pipe(({data:a,mapping:c})=>{const l=this.statCompiler.compute(e.stat,{data:a,mapping:c,xScaleIsDiscrete:s});return{data:l.data,mapping:{...c,...l.mapping}}}).pipe(({data:a,mapping:c})=>({data:this.groupCompiler.compute({data:a,mapping:c}).data,mapping:c})).pipe(({data:a,mapping:c})=>({data:Ju(a),mapping:c})).pipe(({data:a,mapping:c})=>{const l=this.geomCompiler.compile(e.geom,{data:a,mapping:c,params:e.params});return{data:l.data,mapping:{...c,...l.mapping}}}).pipe(({data:a,mapping:c})=>{const l=this.positionAdjusterCompiler.adjust(e.position,{data:a,mapping:c});return{data:l.data,mapping:{...c,...l.mapping}}}).result(),i=this.container.geomRegistry.get(e.geom);return{...o,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:i.spatialKind,identityKey:i.identityKey,tooltip:i.tooltip,highlight:ti(e.geom)}}}function us(t){return t.scales.some(e=>e.scaledAesthetic==="x"&&e.scaleType==="discrete")}function ri(t,e){const[n]=e;if(n){for(const r of e)t.addError(r);throw new O(n)}}const td=new Set(["label","group"]);class nd{constructor(e,n,r,s){this.container=e,this.transformCompiler=n,this.statRegistry=r,this.layerCompiler=s}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const n=this.layerCompiler.compile(e);return this.checkPostCompile(n),n}checkPreCompile(e){const n=[];e.layers.forEach((r,s)=>{const o=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},a={layerId:r.id,layerIndex:s,geom:r.geom,stat:r.stat,effectiveMapping:i,data:o,coordType:e.coords.coordType};n.push(...this.validateLayer(a));for(const c of this.collectUndeclaredAesthetics(a))this.container.diagnostics.addWarning(c)}),ri(this.container.diagnostics,n)}checkPostCompile(e){e.length===0||e.some(n=>n.data.size()>0)||this.container.diagnostics.addWarning({code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."})}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e)]}validateRequiredAesthetics({layerId:e,layerIndex:n,geom:r,stat:s,effectiveMapping:o}){const i=[],{positionRoles:a,aesthetics:c}=this.container.geomRegistry.get(r),l=[...xl(a),...c.filter(m=>m.required).map(m=>m.name)],{computedVariables:d}=this.statRegistry.get(s.type),u=d;for(const m of l)u.has(m)||h(o[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:n,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:n,geom:r,stat:s,effectiveMapping:o,data:i}){const a=[],{computedVariables:c}=this.statRegistry.get(s.type),{derivedVariables:l}=this.container.geomRegistry.get(r),d=c,u=new Set(l);for(const[m,p]of Object.entries(o)){if(d.has(m))continue;const f=x(p);f!==null&&(u.has(f)||i.hasVariable(f)||a.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${f}' which does not exist in the dataset`,context:{layerIndex:n,aesthetic:m,variableName:f}}))}return a}validatePositionalAestheticTypes({layerId:e,layerIndex:n,geom:r,stat:s,effectiveMapping:o,data:i}){const{positionRoles:a}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(s.type),l=c,d=[];for(const u of a){if(!yl.has(u.role)||!h(u.aes)||u.aes===u.axis||l.has(u.aes))continue;const m=x(o[u.aes]);if(m===null||!i.hasVariable(m))continue;const p=i.getType(m);p!=="numeric"&&d.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${u.aes}' must be numeric, but variable '${m}' is ${p}`,context:{layerIndex:n,aesthetic:u.aes,variableName:m,variableType:p},suggestion:`Map '${u.aes}' to a numeric variable.`})}return d}validateGeomMapping({layerId:e,layerIndex:n,geom:r,stat:s,effectiveMapping:o}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:a}=this.statRegistry.get(s.type);return i({mapping:o,computedVariables:a}).map(c=>({...c,message:`Layer '${e}': ${c.message}`,context:{...c.context,layerIndex:n}}))}validateCoordSupport({layerId:e,layerIndex:n,geom:r,coordType:s}){const{supportedCoordTypes:o}=this.container.geomRegistry.get(r);return o.includes(s)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${s} coords`,context:{layerIndex:n}}]}collectUndeclaredAesthetics({layerId:e,layerIndex:n,geom:r,stat:s,effectiveMapping:o}){const{positionRoles:i,aesthetics:a}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(s.type),l=new Set([...vl(i),...a.map(p=>p.name)]),d=td,u=c,m=[];for(const p of Object.keys(o))h(o[p])&&(l.has(p)||d.has(p)||u.has(p)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:n,aesthetic:p}}));return m}}class Ce{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.tooltip=[],this.summaries={}}resolveParams(e){return He.merge({},this.defaultParams,e)}}const or=(t,e)=>{const n=x(e.x);return!n||!["numeric","temporal"].includes(t.getType(n))?t:t.orderBy(n,"asc")};class rd extends Ce{constructor(){super(...arguments),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={lineWidth:"auto",interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets"}resolveParams(e){const n=super.resolveParams(e);return n.missingValues==="gap"?{...n,missingValues:"zero"}:n}compile({data:e,mapping:n}){return e=or(e,n),e.hasVariable(g.yMin)||(e=e.addConstantVariable(g.yMin,"numeric",0)),{data:e,mapping:{}}}}const si=.7,sd=.1;class od extends Ce{constructor(){super(...arguments),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveDataLabelDefaults=e=>j(e)?{justify:"center"}:{},this.resolveAnchorPosition=(e,n)=>{if(n.type==="polar")return id(e);if(n.mainAxis==="x"){const i=le(e),a=oe(e),c=Y(e)??C(e);return i===null||a===null||c===null?null:{x:(i+a)/2,y:c}}const r=Z(e),s=Y(e),o=oe(e)??W(e);return r===null||s===null||o===null?null:{x:o,y:(r+s)/2}}}compile({data:e,mapping:n}){e=or(e,n),e.hasVariable(g.yMin)||(e=e.addConstantVariable(g.yMin,"numeric",0));const r=si/2;return e=e.addConstantVariable(g.xMin,"numeric",-r).addConstantVariable(g.xMax,"numeric",r),{data:e,mapping:{}}}}const id=t=>{const e=le(t),n=oe(t),r=Z(t),s=Y(t);if(e===null||n===null||r===null||s===null)return null;const o=(e+n)/2,i=(r+s)/2,a=.5+.5*i*Math.sin(o),c=.5-.5*i*Math.cos(o);return{x:a,y:c}};class ad extends Ce{constructor(){super(...arguments),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={lineWidth:"auto",interpolate:"linear",missingValues:"gap",showFill:!1},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=(e,n)=>{if(n.type==="polar")return null;const r=W(e),s=C(e);return r===null||s===null?null:{x:r,y:s}}}compile(e){return{data:or(e.data,e.mapping),mapping:{}}}}class cd extends Ce{constructor(){super(...arguments),this.type="point",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={size:8},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"size"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.resolveDefaultLabelSource=e=>{const n=x(e.size);return n!==null?{variable:n}:null}}compile({data:e}){return{data:e,mapping:{}}}}class ld extends Ce{constructor(){super(...arguments),this.type="rule",this.defaultParams={strokeWidth:1,lineType:"dashed",labelPosition:"start"},this.defaultInteractive=!1,this.positionRoles=[{axis:"y",role:"scalar",valueKind:"value",aes:"y"},{axis:"x",role:"scalar",valueKind:"value",aes:"x"}],this.highlightStrategy=null,this.spatialKind="noop",this.validateMapping=({mapping:e,computedVariables:n})=>{const r=n.has("x")||D(ce(e.x)),s=n.has("y")||D(ce(e.y));return r&&s?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires exactly one of 'x' or 'y', both were provided"}]:!r&&!s?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires a numeric value on 'x' or 'y'"}]:[]}}compile({data:e,mapping:n}){const r=ds(n.y,e);if(r!==null)return{data:new k({[yt.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:yt.y,x:void 0}};const s=ds(n.x,e);return s!==null?{data:new k({[yt.x]:{type:"numeric",values:[s.value],valueFormat:s.sourceFormat}}),mapping:{x:yt.x,y:void 0}}:{data:new k,mapping:{x:void 0,y:void 0}}}}const ds=(t,e)=>{const n=ce(t);if(D(n))return{value:n,sourceFormat:void 0};const r=x(t);if(r===null||!za(r)||!e.hasVariable(r))return null;const[s]=e.getValues(r);return D(s)?{value:s,sourceFormat:e.getValueFormat(r)}:null},ud=[new od,new cd,new ad,new rd,new ld];class ir extends Xe{constructor(){super("geom");for(const e of ud)this.register(e.type,e)}}class qe{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}}class dd extends qe{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:n}){const r=x(n.x);if(!h(r))throw new O({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'count' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'count' stat."});if(x(n.y)!==null)throw new O({code:"CONFLICTING_STAT_MAPPING",message:"Cannot map 'y' variable together with 'count' stat",context:{aesthetic:"y"},suggestion:"Remove the 'y' mapping; the 'count' stat computes it."});const o=[...new Set([r,...tr(e,n)])];return{data:e.groupBy(...o).rollup({[at.count]:{variableName:r,aggregation:"count"}}),mapping:{y:at.count}}}}class md extends qe{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}}class pd extends qe{constructor(){super(...arguments),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:n}){const r=x(n.y);if(!h(r))throw new O({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'mean' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."});return{data:e.rollup({[at.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:at.mean}}}}const fd=2,oi=1440*60*1e3;class hd extends qe{constructor(){super(...arguments),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:n,spec:r,xScaleIsDiscrete:s}){if(r.type!=="smooth")throw new A({message:`SmoothStat received a spec of type '${r.type}'`});const o=x(n.x),i=x(n.y);if(!h(o))throw new O({code:"MISSING_STAT_VARIABLE",message:"'x' variable is required for 'smooth' stat",context:{aesthetic:"x"},suggestion:"Map a variable to 'x' when using the 'smooth' stat."});if(!h(i))throw new O({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'smooth' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'smooth' stat."});const a=e.getType(o),c=e.getType(i);if(c!=="numeric")throw new O({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:c}});const l=tr(e,n),d=Ad(o,a,i,l,e);return l.length===0?ms({data:e,xVariable:o,xType:a,yVariable:i,spec:r,output:d,groupObservation:{},xScaleIsDiscrete:s}):e.groupBy(...l).forEach(u=>{const m=wd(u,l);ms({data:u,xVariable:o,xType:a,yVariable:i,spec:r,output:d,groupObservation:m,xScaleIsDiscrete:s})}),{data:d.build(),mapping:{}}}}const ms=({data:t,xVariable:e,xType:n,yVariable:r,spec:s,output:o,groupObservation:i,xScaleIsDiscrete:a})=>{const{observations:c,temporalOrigin:l}=gd({data:t,xVariable:e,yVariable:r,xType:n});c.length<fd||(a?Sd({observations:c,spec:s,output:o,groupObservation:i}):xd({observations:c,xType:n,temporalOrigin:l,spec:s,output:o,groupObservation:i}))},gd=({data:t,xVariable:e,yVariable:n,xType:r})=>{const s=t.getValues(e),o=t.getValues(n,{type:"numeric"}),i=r==="temporal"?yd(s):null,a=[],c=new Map;for(let l=0;l<s.length;l++){const d=s[l],u=o[l];if(!h(d)||!h(u)||!Number.isFinite(u))continue;const m=bd({xValue:d,xType:r,categoryRank:c,temporalOrigin:i});m!==null&&a.push({x:m,y:u,originalX:d})}return{observations:a,temporalOrigin:i}},yd=t=>{let e=null;for(const n of t){if(!X(n))continue;const r=n.getTime();(e===null||r<e)&&(e=r)}return e},bd=({xValue:t,xType:e,categoryRank:n,temporalOrigin:r})=>{switch(e){case"numeric":return!D(t)||!Number.isFinite(t)?null:t;case"temporal":{if(!X(t))return null;const s=t.getTime();return r===null?s:(s-r)/oi+1}case"categorical":{if(!zt(t))return null;const s=n.get(t);if(s!==void 0)return s;const o=n.size+1;return n.set(t,o),o}default:{const s=e;throw new A({message:`Unexpected xType: ${s}`})}}},xd=({observations:t,xType:e,temporalOrigin:n,spec:r,output:s,groupObservation:o})=>{const i=ii(r,t);for(const[a,c]of i){if(!Number.isFinite(a)||!Number.isFinite(c))continue;const l=e==="temporal"?vd(a,n):a;s.push({x:l,y:c,groupObservation:o})}},vd=(t,e)=>e===null?new Date(t):new Date((t-1)*oi+e),Sd=({observations:t,spec:e,output:n,groupObservation:r})=>{const s=new Map;for(const a of t)s.has(a.x)||s.set(a.x,a.originalX);const o=[...s.keys()].sort((a,c)=>a-c);if(e.method==="loess"){const a=ii(e,t),c=new Map;for(const[l,d]of a)Number.isFinite(d)&&(c.has(l)||c.set(l,d));for(const l of o){const d=c.get(l),u=s.get(l);d===void 0||u===void 0||n.push({x:u,y:d,groupObservation:r})}return}const i=ai(e,t);for(const a of o){const c=s.get(a),l=i.predict(a);c===void 0||!Number.isFinite(l)||n.push({x:c,y:l,groupObservation:r})}},ii=(t,e)=>t.method==="loess"?we.regressionLoess().x(r=>r.x).y(r=>r.y).bandwidth(t.bandwidth)(e):ai(t,e),ai=(t,e)=>{const n=s=>s.x,r=s=>s.y;switch(t.method){case"linear":return we.regressionLinear().x(n).y(r)(e);case"exponential":return we.regressionExp().x(n).y(r)(e);case"logarithmic":return we.regressionLog().x(n).y(r)(e);case"quadratic":return we.regressionQuad().x(n).y(r)(e);case"power":return we.regressionPow().x(n).y(r)(e);case"polynomial":return we.regressionPoly().x(n).y(r).order(t.order)(e);case"loess":throw new A({message:"'loess' does not expose a 'predict' function"})}},Ad=(t,e,n,r,s)=>{const o=[],i=[],a=Object.fromEntries(r.map(c=>[c,[]]));return{push:({x:c,y:l,groupObservation:d})=>{o.push(c),i.push(l);for(const u of r)a[u]?.push(d[u]??null)},build:()=>{const c={[t]:{type:e,values:o,valueFormat:s.getValueFormat(t)},[n]:{type:"numeric",values:i,valueFormat:s.getValueFormat(n)}};for(const l of r)c[l]={type:s.getType(l),values:a[l]??[],valueFormat:s.getValueFormat(l)};return new k(c)}}},wd=(t,e)=>{const n={};for(const r of e){const s=t.getValues(r);n[r]=s[0]??null}return n},Td=[new md,new dd,new hd,new pd];class Md extends Xe{constructor(){super("stat");for(const e of Td)this.register(e.type,e)}}class Ld{constructor(){this.transformType="aggregate"}apply(e,n){const{options:r}=n,s={};for(const o of r.operations)s[o.as]={variableName:o.variableName,aggregation:o.op};return e.groupBy(...r.groupby).rollup(s)}}class Id{constructor(){this.transformType="constant"}apply(e,n){const{options:r}=n;return e.addConstantVariable(r.variableName,r.type,r.value)}getIntroducedVariables(e){const{options:n}=e;return[n.variableName]}}class Ed{constructor(){this.transformType="filter"}apply(e,n){const{options:r}=n;return e.filter(r.variableName,r.operator,r.value)}}class Vd{constructor(){this.transformType="reshape"}apply(e,n){const{options:r}=n;return e.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}getIntroducedVariables(e){const{options:n}=e;return[n.keyName??Po]}}class kd{constructor(){this.transformType="sort"}apply(e,n){const{options:r}=n;return e.orderBy(r.variableName,r.direction??"asc")}}const _d=[new Ld,new Id,new Ed,new Vd,new kd];class ci extends Xe{constructor(){super("transform");for(const e of _d)this.register(e.transformType,e)}}function Cd({geoms:t,stats:e,transforms:n}){const r=new ir,s=new Md,o=new ci;for(const i of t)r.register(i.type,i);for(const i of e)s.register(i.type,i);for(const i of n)o.register(i.transformType,i);return{geomRegistry:r,statRegistry:s,transformRegistry:o}}function li(t){if("definition"in t)return t.definition;if(di(t)||mi(t)||pi(t))return t}function ui(t){const e=[],n=[],r=[];for(const o of t){const i=li(o);i&&(di(i)?e.push(i):mi(i)?n.push(i):pi(i)&&r.push(i))}const s=[...vn("geom",e,o=>o.type),...vn("stat",n,o=>o.type),...vn("transform",r,o=>o.transformType),...Dd(e)];return{geoms:e,stats:n,transforms:r,warnings:s}}function Dd(t){const e=[];for(const n of t)n.spatialKind!=="render-hit-test"||n.identityKey!=="x-group"||e.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${n.type}' uses the default 'x-group' identity, which has no meaning for render-owned geometry; its hover lookup will be empty.`,context:{kind:"geom",requested:n.type},suggestion:"Declare 'identityKey' as a column the geom owns (`{ variable: '<column>' }`) or 'index', so a hit-test result resolves to an observation."});return e}function vn(t,e,n){const r=new Map;for(const o of e){const i=n(o),a=r.get(i);a?a.add(o):r.set(i,new Set([o]))}const s=[];for(const[o,i]of r)i.size<2||s.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${t} '${o}' (${i.size} definitions); the last in the array wins.`,context:{kind:t,requested:o},suggestion:`Remove the duplicate ${t} plugin(s) named '${o}', or rename them so each registers a distinct ${t}.`});return s}const di=t=>t instanceof Ce,mi=t=>t instanceof qe,pi=t=>"transformType"in t&&typeof t.apply=="function";class Rd{constructor(e){this.registry=e}adjust(e,n){return this.registry.get(e).adjust(n)}}class Qt{}class Pd extends Qt{constructor(){super(...arguments),this.type="dodge"}adjust({data:e,mapping:n}){if(!x(n.x))return{data:e,mapping:{}};const s=e.getValues(z.group,{type:"categorical",distinct:!0,skipNulls:!0});if(s.length===0)return{data:e,mapping:{}};const o=e.size(),i=e.getValues(z.group,{type:"categorical"}),a=si/2,c=s.length>1?sd:0,l=fe.scaleBand().domain(s.map(String)).range([-a,a]).paddingInner(c).paddingOuter(0),d=l.bandwidth(),u=new Array(o).fill(null),m=new Array(o).fill(null);for(let f=0;f<o;f++){const b=i[f];if(!h(b))continue;const y=l(String(b));h(y)&&(u[f]=y,m[f]=y+d)}return{data:e.addVariable(g.xMin,"numeric",u).addVariable(g.xMax,"numeric",m),mapping:{}}}}const ps=w("__ungrouped__"),fi=(t,e)=>{const n=x(e.x),r=x(e.y);if(!n||!r)return null;const s=t.getValues(z.group,{type:"categorical",distinct:!0,skipNulls:!0}),o=s.length===0,i=o?[ps]:s,a=t.getValues(n),c=t.getValues(r,{type:"numeric"}),l=t.getValues(z.group,{type:"categorical"}),d=t.size(),u=new Map;for(let m=0;m<d;m++){const p=I(a[m]??null),f=l[m],b=o?ps:f;if(!h(b))continue;let y=u.get(p);y||(y=new Map,u.set(p,y));let v=y.get(b);v||(v=[],y.set(b,v)),v.push(m)}return{yValues:c,observationIndicesByXAndGroup:u,uniqueGroupKeys:i,observationCount:d}};class Fd extends Qt{constructor(){super(...arguments),this.type="fill"}adjust({data:e,mapping:n}){const r=fi(e,n);if(r===null)return{data:e,mapping:{}};const{yValues:s,observationIndicesByXAndGroup:o,uniqueGroupKeys:i,observationCount:a}=r,c=[...s],l=new Array(a).fill(0);for(const[,u]of o){let m=0,p=0;for(const y of i){const v=u.get(y);if(v!==void 0)for(const S of v){const T=s[S];T!=null&&(T>=0?m+=T:p-=T)}}let f=0,b=0;for(const y of i){const v=u.get(y);if(v!==void 0)for(const S of v){const T=s[S];if(T===void 0)continue;if(T===null){l[S]=null,c[S]=null;continue}const V=T>=0?m:p;if(V===0){l[S]=0,c[S]=0;continue}const F=T/V;T>=0?(l[S]=f,c[S]=f+=F):(c[S]=b,l[S]=b+=F)}}}return{data:e.addVariable(g.yMin,"numeric",l).addVariable(g.yMax,"numeric",c).addVariable(g.yRaw,"numeric",s),mapping:{}}}}class Nd extends Qt{constructor(){super(...arguments),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}}class Od extends Qt{constructor(){super(...arguments),this.type="stack"}adjust({data:e,mapping:n}){const r=fi(e,n);if(r===null)return{data:e,mapping:{}};const{yValues:s,observationIndicesByXAndGroup:o,uniqueGroupKeys:i,observationCount:a}=r,c=[...s],l=new Array(a).fill(0);for(const[,m]of o){let p=0,f=0;for(const b of i){const y=m.get(b);if(y!==void 0)for(const v of y){const S=s[v];if(S!==void 0){if(S===null){l[v]=null,c[v]=null;continue}S>=0?(l[v]=p,c[v]=p+=S):(c[v]=f,l[v]=f+=S)}}}}let d=e.addVariable(g.yMin,"numeric",l).addVariable(g.yMax,"numeric",c).addVariable(g.yRaw,"numeric",s);const u=x(n.y);return u!==null&&(d=d.addVariable(u,"numeric",c)),{data:d,mapping:{}}}}class Bd extends Xe{constructor(){super("position"),this.register("identity",new Nd),this.register("stack",new Od),this.register("fill",new Fd),this.register("dodge",new Pd)}}class Gd{map({data:e,layer:n,getPositionScale:r,geomRegistry:s}){let o=e;const i=s.get(n.geom);for(const a of i.positionRoles){if(a.role!=="scalar"||!h(a.aes)||er(a.aes))continue;const c=x(n.mapping[a.aes]);if(!h(c)||!o.hasVariable(c))continue;const l=r(Ho(a.axis,n.yScaleType));if(!l)continue;const u=o.getValues(c,{type:"numeric"}).map(m=>h(m)?l.map(m):null);o=o.addVariable(ao(a.aes),"numeric",u)}return o}}class $d{map({data:e,layer:n,getPositionScale:r}){const s=x(n.mapping.x),o=r("x");if(!s||!o)return e;const a=e.getValues(s).map(c=>h(c)?o.map(c):null);return e.addVariable(g.x,"numeric",a)}}class Wd{map({data:e,getPositionScale:n}){const r=n("x");if(!r?.bandwidth||!e.hasVariable(g.x)||!e.hasVariable(g.xMin)||!e.hasVariable(g.xMax))return e;const s="reverse"in r.spec&&r.spec.reverse===!0,o=e.getValues(g.x,{type:"numeric"}),i=e.getValues(g.xMin,{type:"numeric"}),a=e.getValues(g.xMax,{type:"numeric"}),c=e.size(),l=new Array(c),d=new Array(c);for(let u=0;u<c;u++){const m=o[u],p=i[u],f=a[u];if(h(m)&&h(p)&&h(f)){const b=s?-f:p,y=s?-p:f;l[u]=m+b*r.bandwidth,d[u]=m+y*r.bandwidth}else l[u]=null,d[u]=null}return e.addVariable(g.xMin,"numeric",l).addVariable(g.xMax,"numeric",d)}}class zd{map({data:e,layer:n,getPositionScale:r}){const s=x(n.mapping.y),o=je(n.yScaleType),i=r(o);if(!s||!i)return e;const c=e.getValues(s).map(l=>h(l)?i.map(l):null);return e.addVariable(g.y,"numeric",c)}}class Hd{map({data:e,layer:n,getPositionScale:r}){const s=je(n.yScaleType),o=r(s);if(!o||!e.hasVariable(g.yMin)||!e.hasVariable(g.yMax))return e;const i=e.getValues(g.yMin,{type:"numeric"}),a=e.getValues(g.yMax,{type:"numeric"}),c=e.size(),l=new Array(c),d=new Array(c);for(let u=0;u<c;u++){const m=i[u],p=a[u];h(m)&&h(p)?(l[u]=o.map(m),d[u]=o.map(p)):(l[u]=null,d[u]=null)}return e.addVariable(g.yMin,"numeric",l).addVariable(g.yMax,"numeric",d)}}const Yd=[new $d,new zd,new Wd,new Hd,new Gd];function Ud(t,e){const n=t[e];return n?.kind==="position"?n:null}class Kd extends Ke{constructor(e,n=Yd){super(),this.container=e,this.mappers=n}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,n){const r=o=>Ud(n.scales,o);let s=e.data;for(const o of this.mappers)s=o.map({data:s,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:s}}}class Xd extends xe{constructor(e,n){super(),this.container=e,this.registry=n}dependencies(e){return[e.layers,e.scales]}run(e){this.validateScaleTypeCompatibility(e);const n=new Map;for(const o of e.scales)n.set(o.scaledAesthetic,o);const r=this.collectValues(e.layers,n),s={};for(const[o,i]of n){const a=r.get(o)??[],c=this.registry.get(i.scaleType);s[o]=c.compile(i,a)}return s}validateScaleTypeCompatibility(e){const n=[];for(const r of e.scales){const{compatibleDataTypes:s}=this.registry.get(r.scaleType),o=te(r.scaledAesthetic),i=e.layers.find(l=>h(l.mapping[o]));if(!i)continue;const a=x(i.mapping[o]);if(!h(a)||!i.data.hasVariable(a))continue;const c=i.data.getType(a);if(s.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${a}' (${c})`,context:{aesthetic:o,variableName:a,scaleType:r.scaleType,variableType:c}}),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 '${a}'. ${l}`,context:{aesthetic:o,variableName:a,scaleType:r.scaleType,variableType:c},suggestion:l})}}ri(this.container.diagnostics,n)}collectValues(e,n){const r=new Map;for(const s of e){const o=this.resolveCustomPositionalAxes(s);for(const[i,a]of Object.entries(s.mapping)){if(!h(a))continue;const c=i==="y"?je(s.yScaleType):i,l=o.get(i)??(wl(c)?c:void 0);if(!h(l)||!n.has(l))continue;const d=this.resolveVariables(i,a,s.data);this.collectFromVariables(s.data,d,l,r)}}return r}resolveCustomPositionalAxes(e){const n=new Map,r=this.container.geomRegistry.get(e.geom);for(const s of r.positionRoles)s.role!=="scalar"||!h(s.aes)||er(s.aes)||n.set(s.aes,Ho(s.axis,e.yScaleType));return n}resolveVariables(e,n,r){if(e==="y"&&this.hasPositionAdjustedY(r))return[g.yMin,g.yMax];const s=x(n);return!s||!r.hasVariable(s)?[]:[s]}hasPositionAdjustedY(e){return e.hasVariable(g.yMin)&&e.hasVariable(g.yMax)}collectFromVariables(e,n,r,s){if(n.length===0)return;let o=[];for(const a of n)o=o.concat(e.getValues(a));const i=s.get(r);s.set(r,i?i.concat(o):o)}}class pt{createPositionScale(e,n){return{kind:"position",aesthetic:te(e.scaledAesthetic),spec:e,...n}}createVisualScale(e,n){return{kind:"visual",aesthetic:te(e.scaledAesthetic),spec:e,...n}}}class jd extends pt{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,n){if(e.scaleType!=="continuous")throw new A({message:"ContinuousScale.compile received non-continuous spec"});const r=Xt(e.scaledAesthetic),s=this.computeDataDomain(n,e);return r?this.buildPositionScale(s,e):this.buildVisualScale(s,e)}computeDataDomain(e,n){let r=1/0,s=-1/0;for(const o of e)typeof o=="number"&&(o<r&&(r=o),o>s&&(s=o));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),s<0&&(s=0)),[r,s])}createD3Scale(e,n,r){let s=[r.domainMin??e[0],r.domainMax??e[1]];const o=r.transform==="log"&&qd(s);r.transform==="log"&&!o&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:te(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=o?fe.scaleLog():r.transform==="sqrt"?fe.scaleSqrt():fe.scaleLinear();return r.nice&&!o&&(s=i.copy().domain(s).nice().domain()),i.domain([r.domainMin??s[0],r.domainMax??s[1]]).range(n).clamp(r.clamp)}buildPositionScale(e,n){const r=n.reverse?[1,0]:[0,1],s=this.createD3Scale(e,r,n);return this.createPositionScale(n,{map:s,domain:s.domain(),bandwidth:null,generateTicks:o=>o&&"count"in o?s.ticks(o.count):s.ticks()})}buildVisualScale(e,n){const r=n.range??[0,1],s=n.reverse?[r[1],r[0]]:r,o=this.createD3Scale(e,s,n);return this.createVisualScale(n,{map:o,domain:o.domain(),generateTicks:i=>i&&"count"in i?o.ticks(i.count):o.ticks()})}}const qd=t=>{const[e,n]=t;return e>0&&n>0||e<0&&n<0};class Zd extends pt{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(e,n){if(e.scaleType!=="datetime")throw new A({message:"DatetimeScale.compile received non-datetime spec"});const r=Xt(e.scaledAesthetic),s=this.computeDataDomain(n);if(!r)throw new O({code:"INCOMPATIBLE_TYPE",message:"Datetime scale is not supported for non-position aesthetics",context:{aesthetic:e.scaledAesthetic},suggestion:"Use a continuous or discrete scale for non-position aesthetics (color, size, alpha, strokeWidth)."});return this.buildScale(s,e,this.collectInputDates(n))}collectInputDates(e){const n=new Set,r=[];for(const s of e){if(!(s instanceof Date))continue;const o=s.getTime();n.has(o)||(n.add(o),r.push(s))}return r.sort((s,o)=>s.getTime()-o.getTime()),r}computeDataDomain(e){let n=1/0,r=-1/0;for(const s of e){if(!(s instanceof Date))continue;const o=s.getTime();o<n&&(n=o),o>r&&(r=o)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(e,n,r){const s=Qd(e)?e:[],o=fe.scaleUtc().domain(s).range(n).clamp(r.clamp);if(r.nice&&o.nice(),h(r.domainMin)||h(r.domainMax)){const[i,a]=o.domain();i!==void 0&&a!==void 0&&o.domain([r.domainMin??i,r.domainMax??a])}return o}buildScale(e,n,r){const s=n.reverse?[1,0]:[0,1],o=this.createD3Scale(e,s,n),[i,a]=o.domain(),c=i&&a?r.filter(l=>l>=i&&l<=a):[];return this.createPositionScale(n,{map:o,domain:o.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&a?_l(i,a,l.interval):[]:o.ticks(l?.count)})}}const Qd=t=>t.length===2&&X(t[0])&&X(t[1]),Fe={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},fs={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},bt={domainMin:null,domainMax:null,nice:!1,reverse:!1},et={range:null,domain:null,padding:.1,reverse:!1},hs={palette:{type:"default"}};class Jd extends pt{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,n){if(e.scaleType!=="discrete")throw new A({message:"DiscreteScale.compile received non-discrete spec"});const r=Xt(e.scaledAesthetic),s=Wo(n,e);return r?this.buildPositionScale(s,e):this.buildVisualScale(s,e)}buildPositionScale(e,n){const r=e.map(String),s=n.padding??et.padding,o=n.reverse?[1,0]:[0,1],i=fe.scaleBand().domain(r).range(o).paddingInner(s).paddingOuter(s/2),a=i.bandwidth()/2;return this.createPositionScale(n,{map:c=>(i(String(c))??0)+a,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,n){const r=e.map(String),s=n.range&&n.range.length>0?fe.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:o=>{const i=String(o);return s?s(i):i},domain:e,generateTicks:()=>e})}}class em extends pt{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new A({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:te(e.scaledAesthetic),spec:e,map:n=>n,domain:[],generateTicks:()=>[]}}}const hi=["grey","red","orange","yellow","green","cyan","blue","purple","pink"],gi=["cyan","pink","purple","red","orange","yellow","green","blue"],ar=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],ne={red:"#E83562",orange:"#F38650",yellow:"#FBBC30",green:"#31FCB4",cyan:"#40F8FF",blue:"#279EFF",purple:"#B399FD",dark_purple:"#6D48D2",plum:"#C82184",pink:"#FC8497"},tm=[ne.purple,ne.pink,ne.yellow,ne.blue,ne.red,ne.cyan,ne.orange,ne.plum,ne.green,ne.dark_purple],ee={green:"#B2DDC9",cyan:"#A2D5E2",blue:"#AAC4FF",purple:"#B2A4FF",plum:"#DCA8C7",pink:"#FFCCD3",red:"#FFADAD",orange:"#FFDEB4",yellow:"#FDF7C3"},nm=[ee.green,ee.purple,ee.red,ee.cyan,ee.pink,ee.blue,ee.orange,ee.plum,ee.yellow],Bn={grey900:"#1c1917",grey800:"#292524",grey700:"#44403c",grey600:"#57534e",grey500:"#78716c",grey400:"#a8a29e",grey300:"#d6d3d1",grey200:"#e7e5e4",grey100:"#f5f5f4",grey50:"#fafaf9",red900:"#7f1d1d",red800:"#991b1b",red700:"#b91c1c",red600:"#dc2626",red500:"#ef4444",red400:"#f87171",red300:"#fca5a5",red200:"#fecaca",red100:"#fee2e2",red50:"#fef2f2",orange900:"#7c2d12",orange800:"#9a3412",orange700:"#c2410c",orange600:"#ea580c",orange500:"#f97316",orange400:"#fb923c",orange300:"#fdba74",orange200:"#fed7aa",orange100:"#ffedd5",orange50:"#fff7ed",yellow900:"#553B0C",yellow800:"#6F4B08",yellow700:"#8D6300",yellow600:"#BD8A00",yellow500:"#E5B400",yellow400:"#FFC800",yellow300:"#FBDA2B",yellow200:"#FEED72",yellow100:"#FEF8B4",yellow50:"#FEFCE2",green900:"#064e3b",green800:"#065f46",green700:"#047857",green600:"#059669",green500:"#10b981",green400:"#34d399",green300:"#6ee7b7",green200:"#a7f3d0",green100:"#d1fae5",green50:"#ecfdf5",cyan900:"#164e63",cyan800:"#155e75",cyan700:"#0e7490",cyan600:"#0891B2",cyan500:"#06b6d4",cyan400:"#22d3ee",cyan300:"#67e8f9",cyan200:"#a5f3fc",cyan100:"#cffafe",cyan50:"#ecfeff",blue900:"#1e3a8a",blue800:"#1e40af",blue700:"#1d4ed8",blue600:"#2563eb",blue500:"#3b82f6",blue400:"#60a5fa",blue300:"#93c5fd",blue200:"#bfdbfe",blue100:"#dbeafe",blue50:"#eff6ff",purple900:"#4c1d95",purple800:"#5b21b6",purple700:"#6d28d9",purple600:"#7c3aed",purple500:"#8b5cf6",purple400:"#a78bfa",purple300:"#c4b5fd",purple200:"#ddd6fe",purple100:"#ede9fe",purple50:"#f5f3ff",pink900:"#751A5E",pink800:"#8F1972",pink700:"#AF1C8A",pink600:"#D326A8",pink500:"#E845BF",pink400:"#F979D9",pink300:"#FCABE8",pink200:"#FED0F3",pink100:"#FFE8F9",pink50:"#FFF4FC"},rm=[Bn.grey200,ee.green,ee.red,Bn.grey200],gs={dark:{1:[500],2:[600,400],3:[600,400,200],4:[600,500,300,100],5:[700,600,400,200,50],6:[600,500,400,300,200,100],7:[600,500,400,300,200,100,50],default:[700,600,500,400,300,200,100,50]},light:{1:[600],2:[700,500],3:[800,600,400],4:[800,600,400,300],5:[800,700,600,500,400],6:[800,700,600,500,400,300],7:[900,800,700,600,500,400,300],default:[900,800,700,600,500,400,300,200]}},K={cyan:"#22D3EE",pink:"#F377EF",purple:"#6528F7",red:"#FB2576",orange:"#FF9300",yellow:"#FBFF00",green:"#06FF00",blue:"#0079FF"},xt=[K.cyan,K.pink,K.purple,K.red,K.orange,K.yellow,K.green,K.blue],sm=[K.cyan,K.green,K.red,K.cyan],vt={start:"#84D1FC",positive:"#84FC89",negative:"#FC8497",total:"#84D1FC"},om=[vt.start,vt.positive,vt.negative,vt.total];function im(t,e="light",n){return((n!==void 0?gs[e][n]:void 0)??gs[e].default).map(s=>Bn[`${t}${s}`])}function am(t){const e=xt.indexOf(K[t]);return e<=0?xt:[...xt.slice(e),...xt.slice(0,e)]}function cm(t,e){switch(t.type){case"default":return ar;case"graphy":return t.variant==="waterfall"?om:tm;case"pastel":return t.variant==="waterfall"?rm:nm;case"neon":return t.variant==="waterfall"?sm:am(t.base);case"mono":return im(t.base,t.variant??"light",e);case"custom":return t.colors}}function lm(t,e){if(!e)return t;const n=[...t];for(const[r,s]of Object.entries(e)){const o=Number(r);if(!Number.isInteger(o)||o<1)continue;const i=o-1;i<n.length&&(n[i]=s)}return n}function um(t,e,n,r){if(!e)return;const s=n?.type==="custom"?r[n.id]:void 0,o={};for(const[i,a]of Object.entries(e)){const c=Number(i);if(!(!Number.isInteger(c)||c<1)){if(a.hex!==void 0){o[c]=a.hex;continue}if(a.id!==void 0){const l=s?.find(d=>d.id===a.id)?.hex;l!==void 0?o[c]=l:t.diagnostics.addWarning({code:"PALETTE_NOT_FOUND",message:`Palette override at slot ${c} with id '${a.id}' did not resolve against the active palette — falling back to palette color.`,context:{requested:a.id,available:s?.map(d=>d.id)??[]},suggestion:"Define the override id in the active custom palette, or use a hex value instead."})}}}return Object.keys(o).length>0?o:void 0}function dm(t,e,n){if(!e)return hs.palette;if(e.type==="custom"){const r=n[e.id];if(!r)return t.diagnostics.addWarning({code:"PALETTE_NOT_FOUND",message:`Custom palette with id "${e.id}" not found — falling back to the default palette.`,context:{requested:e.id,available:Object.keys(n)},suggestion:"Register the palette in customPalettes, or reference an existing palette id."}),hs.palette;const s=r.map(o=>o.hex);return{type:"custom",id:e.id,colors:s}}return e}class mm extends pt{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,n){if(e.scaleType!=="palette")throw new A({message:"PaletteScale.compile received non-palette spec"});const r=$o(n),s=cm(e.palette,r.length),o=s.length>0?s:[...ar],i=lm(o,e.overrides),a=fe.scaleOrdinal().domain(r.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:c=>a(String(c)),domain:r,generateTicks:()=>r})}}class pm extends Xe{constructor(e){super("scale"),this.register("continuous",new jd(e)),this.register("discrete",new Jd),this.register("datetime",new Zd),this.register("identity",new em),this.register("palette",new mm)}}const yi=t=>!("layers"in t),R={point:fm,line:hm,area:gm,bar:ym,rule:bm};function Ze(t,e){return{type:"layer",geom:t,mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function fm(t={}){return Ze("point",t)}function hm(t={}){return Ze("line",t)}function gm(t={}){return Ze("area",t)}function ym(t={}){return Ze("bar",t)}function bm(t={}){return Ze("rule",t)}const Jt={identity:vm,count:Sm,smooth:xm,mean:Am};function xm(t){return{type:"smooth",method:t.method,order:t.order,bandwidth:t.bandwidth}}function vm(){return{type:"identity"}}function Sm(){return{type:"count"}}function Am(){return{type:"mean"}}const he={reshape:wm,filter:Tm,sort:Mm,aggregate:Lm,constant:Im};function wm(t={}){return{type:"transform",transformType:"reshape",options:t}}function Tm(t){return{type:"transform",transformType:"filter",options:t}}function Mm(t){return{type:"transform",transformType:"sort",options:t}}function Lm(t){return{type:"transform",transformType:"aggregate",options:t}}function Im(t){return{type:"transform",transformType:"constant",options:t}}const $={cartesian:(t={})=>({type:"coord",coordType:"cartesian",params:t}),flip:(t={})=>({type:"coord",coordType:"flip",params:t}),polar:(t={})=>({type:"coord",coordType:"polar",params:t})},Em={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:g.yRaw},position:"auto",justify:"end",align:"center",offset:4},Vm={params:{size:8}},km="primary";function N(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"continuous",transform:e.transform,reverse:e.reverse,nice:e.nice,zero:e.zero,clamp:e.clamp,domainMin:e.domainMin??null,domainMax:e.domainMax??null,range:e.range}}function Lt(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"datetime",domainMin:e.domainMin??null,domainMax:e.domainMax??null,nice:e.nice,reverse:e.reverse,clamp:e.clamp}}function se(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"discrete",range:e.range,domain:e.domain??null,padding:e.padding,reverse:e.reverse}}function tt(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"identity"}}function It(t,e){return{type:"scale",scaledAesthetic:t,scaleType:"inferred",options:e}}function bi(t,e={}){return{type:"scale",scaledAesthetic:t,scaleType:"palette",palette:e.palette,overrides:e.overrides}}const ge={x:Object.assign(t=>It("x",t),{continuous:t=>N("x",t),discrete:t=>se("x",t),datetime:t=>Lt("x",t),log:t=>N("x",{...t,transform:"log"}),sqrt:t=>N("x",{...t,transform:"sqrt"})}),y:Object.assign(t=>It("y",t),{continuous:t=>N("y",t),discrete:t=>se("y",t),datetime:t=>Lt("y",t),log:t=>N("y",{...t,transform:"log"}),sqrt:t=>N("y",{...t,transform:"sqrt"})}),ySecondary:Object.assign(t=>It("ySecondary",t),{continuous:t=>N("ySecondary",t),discrete:t=>se("ySecondary",t),datetime:t=>Lt("ySecondary",t),log:t=>N("ySecondary",{...t,transform:"log"}),sqrt:t=>N("ySecondary",{...t,transform:"sqrt"})}),color:{continuous:t=>N("color",t),discrete:t=>se("color",t),palette:t=>bi("color",t)},size:{continuous:t=>N("size",t),discrete:t=>se("size",t),identity:t=>tt("size",t)},alpha:{continuous:t=>N("alpha",t),discrete:t=>se("alpha",t),identity:t=>tt("alpha",t)},strokeWidth:{continuous:t=>N("strokeWidth",t),discrete:t=>se("strokeWidth",t),identity:t=>tt("strokeWidth",t)},lineType:{discrete:t=>se("lineType",t),identity:t=>tt("lineType",t)}},q="key",ae="value",ys=w("lineSeriesLabel"),bs=w("barSeriesLabel"),Rt=w("constantY"),_m=(t,e,n,r)=>Om[e](t,n,r),cr=t=>{const{numeric:e,categorical:n,temporal:r}=t.groupVariableNamesByType();return h(r[0])?r[0]:h(n[0])?n[0]:h(e[0])?e[0]:""},lr=t=>{const e=cr(t),{numeric:n}=t.groupVariableNamesByType(),r=n.filter(o=>o!==e);return r.length<=1?{dataset:t,mapping:{x:e,y:r[0]??""},seriesVariables:r}:{dataset:t.reshapeFromWideToLong({keep:[e],keyName:q,valueName:ae}),mapping:{x:e,y:ae,color:q},seriesVariables:r}},ur=t=>{const e=t.appearance?.seriesStyles;if(!e||t.seriesVariables.length===0)return{mapping:{},scales:[]};if(!t.seriesVariables.some(s=>h(e[s]?.lineStyle)))return{mapping:{},scales:[]};if(t.seriesVariables.length===1){const s=t.seriesVariables[0];if(!s)return{mapping:{},scales:[]};const o=e[s]?.lineStyle;return o?{mapping:{lineType:{value:o}},scales:[]}:{mapping:{},scales:[]}}const r=t.seriesVariables.map(s=>e[s]?.lineStyle??"solid");return{mapping:{lineType:q},scales:[ge.lineType.discrete({domain:t.seriesVariables,range:r})]}},Cm=t=>{const{categorical:e,temporal:n,numeric:r}=t.groupVariableNamesByType(),s=r[0];if(!h(s))throw new O({code:"INVALID_DATA_SHAPE",message:"No first numeric variable found",suggestion:"Provide at least one numeric column for this chart type."});const o=r.slice(1);return o.length===0?{dataset:t.addConstantVariable(Rt,"categorical",""),mapping:{x:s,y:Rt,label:e[0]}}:o.length===1?{dataset:t,mapping:{x:s,y:o[0]??"",label:e[0]}}:{dataset:t.reshapeFromWideToLong({keep:[s,...e,...n],keyName:q,valueName:ae}),mapping:{x:s,y:ae,label:e[0],color:q}}},Dm=t=>{const{categorical:e,temporal:n,numeric:r}=t.groupVariableNamesByType();let s,o;if(h(e[0])&&h(r[0]))s=e[0],o=r[0];else if(h(n[0])&&h(r[0]))s=n[0],o=r[0];else if(h(r[0])&&h(r[1]))s=r[0],o=r[1];else throw new O({code:"INVALID_DATA_SHAPE",message:"No label or value variable found",suggestion:"Provide a label column and a numeric value column for this chart type."});return{x:"",y:o,color:s}},xi=(t,e,n)=>{const{dataset:r,mapping:s,seriesVariables:o}=lr(t.dataset),i=ur({appearance:n,seriesVariables:o}),a=o.length<=1,c=[R.line({params:{lineWidth:e?.lineThickness,interpolate:e?.isSmoothLine?"catmull-rom":"linear",missingValues:e?.missingValues,showFill:a?e?.showFill??!0:!1}})];return e?.showPoints&&c.push(R.point({params:{size:vi(e.pointSize)},interactive:!1})),{dataset:r,layers:c,coords:$.cartesian(),mapping:{...s,...i.mapping},scales:i.scales,seriesVariables:o}},Rm=(t,e,n)=>{const{dataset:r,mapping:s,seriesVariables:o}=lr(t.dataset),i=ur({appearance:n,seriesVariables:o}),a=[R.area({position:"stack",params:{lineWidth:e?.lineThickness,interpolate:e?.isSmoothLine?"catmull-rom":"linear",missingValues:e?.missingValues}})];return e?.showPoints&&a.push(R.point({params:{size:vi(e.pointSize)},position:"stack",interactive:!1})),{dataset:r,layers:a,coords:$.cartesian(),mapping:{...s,...i.mapping},scales:i.scales,seriesVariables:o}},Te=(t,e,n,r,s)=>{const{dataset:o,mapping:i,seriesVariables:a}=lr(t.dataset),c=[];if(r?.sortBars){const l=x(i.y);l!==null&&l!==""&&c.push(he.sort({variableName:l,direction:"desc"}))}if(!s?.useSingleColorForBars){const l=cr(t.dataset),{numeric:d}=t.dataset.groupVariableNamesByType();d.filter(m=>m!==l).length===1&&t.dataset.getType(l)==="categorical"&&(i.color=l)}return{dataset:o,layers:[R.bar({position:e})],coords:n,mapping:i,scales:[],transforms:c,seriesVariables:a}},xs=(t,e)=>({dataset:t.dataset,layers:[R.bar({position:"fill"})],coords:$.polar({theta:"y",innerRadius:e==="donut"?.55:0}),mapping:Dm(t.dataset),scales:[],seriesVariables:[]}),Pm=t=>{const{dataset:e,mapping:n}=Cm(t.dataset);return{dataset:e,layers:[R.point()],coords:$.cartesian(),mapping:n,scales:[],seriesVariables:[]}},Fm=t=>{const{numeric:e,categorical:n}=t.dataset.groupVariableNamesByType(),r=e[0];if(!h(r))throw new O({code:"INVALID_DATA_SHAPE",message:"No first numeric variable found",suggestion:"Provide at least one numeric column for this chart type."});const o=h(e[1])?t.dataset:t.dataset.addConstantVariable(Rt,"categorical",""),i={x:r,y:e[1]??Rt,size:e[2],label:n[0]},a=[];return h(i.size)&&a.push(ge.size.continuous()),{dataset:o,layers:[R.point()],coords:$.cartesian(),mapping:i,scales:a,seriesVariables:[]}},Sn=(t,e,n)=>{const r=n?.seriesStyles?.[t]?.lineStyle;return R.line({transforms:[he.constant({variableName:ys,type:"categorical",value:t})],aes:{y:t,color:ys,...r?{lineType:{value:r}}:{}},...e?{yScaleType:"secondary"}:void 0})},Nm=(t,e,n)=>{const{numeric:r,categorical:s,temporal:o}=t.dataset.groupVariableNamesByType(),i=cr(t.dataset),a=[...s,...o],c=r.filter(y=>y!==i),l=e?.comboType??"grouped-bars",d=l==="lines";if(c.length===1)return d?xi(t,e,n):Te(t,"dodge",$.cartesian(),e,n);const u=t.axes?.hasDualYAxis===!0,m=d?[]:c.slice(0,-1),p=d?c:c.slice(-1),f=[],b=[];if(m.length>0){const y=l==="stacked-bars"?"stack":"dodge",v=m.length===1?m[0]:null;h(v)?f.push(R.bar({transforms:[he.constant({variableName:bs,type:"categorical",value:v})],aes:{y:v,color:bs},position:y})):f.push(R.bar({transforms:[he.reshape({keep:a,reshape:m,keyName:q,valueName:ae})],aes:{y:ae,color:q},position:y}))}if(d&&p.length>=2){const y=u?p.slice(0,-1):p,v=y.length===1?y[0]:null;if(h(v))f.push(Sn(v,!1,n));else{const S=ur({appearance:n,seriesVariables:y});f.push(R.line({transforms:[he.reshape({keep:a,reshape:y,keyName:q,valueName:ae})],aes:{y:ae,color:q,...S.mapping}})),b.push(...S.scales)}if(u){const S=p[p.length-1];h(S)&&f.push(Sn(S,!0,n))}}else for(const y of p)f.push(Sn(y,u,n));return{dataset:t.dataset,layers:f,coords:$.cartesian(),mapping:{x:i},scales:b,seriesVariables:c}},vi=(t="auto")=>t==="auto"?Vm.params.size:t,Je=t=>()=>{throw new O({code:"UNSUPPORTED_GRAPH_TYPE",message:`Unsupported graph type: ${t}`,context:{requested:t}})},Om={line:(t,e,n)=>xi(t,e,n),areaStacked:(t,e,n)=>Rm(t,e,n),bar:(t,e,n)=>Te(t,"dodge",$.flip(),e,n),barStacked:(t,e,n)=>Te(t,"stack",$.flip(),e,n),barStackedFill:(t,e,n)=>Te(t,"fill",$.flip(),e,n),column:(t,e,n)=>Te(t,"dodge",$.cartesian(),e,n),columnStacked:(t,e,n)=>Te(t,"stack",$.cartesian(),e,n),columnStackedFill:(t,e,n)=>Te(t,"fill",$.cartesian(),e,n),pie:t=>xs(t,"pie"),donut:t=>xs(t,"donut"),scatter:t=>Pm(t),bubble:t=>Fm(t),combo:(t,e,n)=>Nm(t,e,n),funnel:Je("funnel"),heatmap:Je("heatmap"),waterfall:Je("waterfall"),mekko:Je("mekko"),table:Je("table")},vs="#%_ENCODED_%#",Si=t=>{if(!t.startsWith(vs))return t;try{const{value:e}=JSON.parse(t.slice(vs.length));return typeof e=="string"?e:t}catch{return t}},Bm=({annotations:t,dataset:e,mapping:n,seriesVariables:r})=>{const s=[],o=[],i=[],a=[],c=[],l=[],d=[],u=[],m={dataset:e,...Gm(n,r)};for(const p of t??[])switch(p.type){case"difference-arrow":{const f=$m(p,m);f!==null&&s.push(f);break}case"shape":{o.push(Wm(p));break}case"arrow":{i.push(Km(p));break}case"highlight":break;case"text":{a.push(Hm(p));break}case"image":{c.push(zm(p));break}case"sticker":{const f=Ym(p,m);f!==null&&l.push(f);break}case"tooltip":{const f=Um(p,m);if(f===null)break;f.kind==="pinnedNumber"?d.push(f.value):u.push(f.value);break}default:{const f=p;throw new A({message:`Unsupported annotation type: ${f.type}`})}}return{differenceArrows:s,shapes:o,freeformArrows:i,textAnnotations:a,images:c,stickers:l,pinnedNumbers:d,comments:u}},Gm=(t,e)=>{const n=x(t.x),r=x(t.group)??x(t.color),s=n!==null&&n!=="",o=r===q||e.length>=2;return{anchorVariable:s?n:r,groupIsSeriesKey:o}},$m=(t,e)=>{const n=Pt(e,t.start),r=Pt(e,t.end);return n===null||r===null?null:{id:t.id,start:n,end:r,label:t.show,color:t.color??null,size:t.size,labelCrossPosition:t.labelPosition}},Wm=t=>({id:t.id,kind:t.shape,zOrder:t.layer==="abovePlot"?"foreground":"background",region:{anchorType:"panel",x:t.x,y:t.y,width:t.width,height:t.height},fillColor:t.fillColor,fillOpacity:t.fillOpacity,strokeWidth:t.strokeWidth,strokeColor:t.fillColor}),zm=t=>({id:t.id,src:t.src,zOrder:t.layer==="abovePlot"?"foreground":"background",region:{anchorType:"panel",x:t.x,y:t.y,width:t.width,height:t.height},fit:t.fit,opacity:t.opacity}),Hm=t=>({id:t.id,content:t.content,at:{anchorType:"panel",x:t.x,y:t.y},width:t.width,backgroundColor:t.backgroundColor??null,backgroundColorStyle:t.backgroundColorStyle}),Ym=(t,e)=>{const n=Pt(e,t);return n===null?null:{id:t.id,at:{anchorType:"observation",...n},sticker:t.sticker}},Um=(t,e)=>{const n=Pt(e,t);return n===null?null:t.caption===null||t.caption===void 0?{kind:"pinnedNumber",value:{id:t.id,at:n}}:{kind:"comment",value:{id:t.id,at:n,content:t.caption}}},Km=t=>({id:t.id,start:{anchorType:"panel",x:t.startX,y:t.startY},end:{anchorType:"panel",x:t.endX,y:t.endY},color:t.color??null,thickness:t.thickness,startArrowheadStyle:t.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle,lineStyle:t.lineStyle,hasStickerStyle:t.hasStickerStyle}),Pt=(t,e)=>{if(!h(e))return null;const{dataset:n,anchorVariable:r,groupIsSeriesKey:s}=t;if(r===null)return null;const o=Xm(e,r,n);return o===null?null:s?h(e.columnKey)?{anchorValue:o,groupValue:Si(e.columnKey)}:null:{anchorValue:o,groupValue:void 0}},Xm=(t,e,n)=>!h(t.rowIndex)||!n.hasVariable(e)?null:n.getValues(e)[t.rowIndex]??null,Ai=["lilac","neon_pink","blackberry","sun","iceland","sunset","ultraviolet","purple","ice_cream","mint","cool","fresh"];function wi(t){return{type:"config",config:t}}const jm="#E5E5E5",qm={x:"top",y:"left"},Zm=new Set(["pie","donut"]);function Qm(t,e=!1){return wi({legend:rp(t.legend),axes:op(t.axes,e),headline:ip(t),numberFormat:ap(t.appearance),content:cp(t.content),appearance:Jm(t.appearance,t.themeOverrides)}).config}function Jm(t,e){const n=np(t?.border),r=t?.hasRoundedCorners===!1?0:void 0,s=ep(t,e),o={};return t?.textScale!==void 0&&(o.textScale=t.textScale),n!==void 0&&(o.border=n),r!==void 0&&(o.cornerRadius=r),s!==void 0&&(o.background=s),t?.highlightStyle!==void 0&&(o.highlightStyle=t.highlightStyle==="grey"?"desaturate":"dim"),Object.keys(o).length>0?o:void 0}function ep(t,e){if(t?.backgroundModifier==="tint")return{type:"tinted"};const n=e?.graphBackground;if(typeof n=="string")return{type:"solid",color:n}}const tp=t=>Ai.includes(t);function np(t){if(!t?.style)return;if(t.style==="none")return{type:"none"};const e=t.width??0;if(t.style==="grey")return{type:"solid",color:jm,width:e};if(t.style==="preset")return t.color===void 0||!tp(t.color)?void 0:{type:"preset",preset:t.color,width:e};if(t.color!==void 0)return t.style==="custom"?{type:"solid",color:t.color,width:e}:{type:t.style,color:t.color,width:e}}function rp(t){if(t)return{position:t.position}}function Ss(t,e,n){return!e&&n===void 0?{}:{...e?.isHidden!==void 0?{isVisible:!e.isHidden}:void 0,...e?.label!==void 0?{label:e.label}:void 0,...e?.isReversed?{position:qm[t]}:void 0,...e?.tickDisplayMode?{ticks:{mode:e.tickDisplayMode}}:void 0,...n!==void 0?{grid:{isVisible:n}}:void 0}}function sp(t){return{...t.label!==void 0?{label:t.label}:void 0}}function op(t,e=!1){if(!t)return;const n=Ss("x",t.x,t.showGridLines),r=Ss("y",t.y,t.showGridLines);return{x:e?r:n,y:e?n:r,...t.y2?{ySecondary:sp(t.y2)}:void 0}}function ip(t){const{headlineNumbers:e,options:n,type:r}=t,s=r!==void 0&&Zm.has(r)?n?.pieTotalPosition:void 0;if(e===void 0&&s===void 0)return;const o={};return e?.show!==void 0&&(o.show=e.show),e?.compareWith!==void 0&&(o.compareWith=e.compareWith),e?.size!==void 0&&(o.size=e.size),s!==void 0&&(o.show="total",o.position=s==="center"?"center":"above"),o}function ap(t){if(t?.numberFormat)return{decimals:t.numberFormat.decimalPlaces,abbreviation:t.numberFormat.abbreviation}}function cp(t){if(!t)return;const e={};t.title!==void 0&&(e.title=t.title),t.isTitleHidden!==void 0&&(e.isTitleVisible=!t.isTitleHidden),t.subtitle!==void 0&&(e.subtitle=t.subtitle),t.isSubtitleHidden!==void 0&&(e.isSubtitleVisible=!t.isSubtitleHidden),t.caption!==void 0&&(e.caption=t.caption),t.isCaptionHidden!==void 0&&(e.isCaptionVisible=!t.isCaptionHidden);const n=lp(t.source);return n!==void 0&&(e.source=n),t.isSourceHidden!==void 0&&(e.isSourceVisible=!t.isSourceHidden),e}function lp(t){if(!t)return;const e={};return t.label!==void 0&&(e.label=t.label),t.url!==void 0&&(e.url=t.url),Object.keys(e).length===0?void 0:e}const up=new ci,dp=["key",w("lineSeriesLabel"),w("barSeriesLabel")];function mp(t){const e=t.annotations??[],n=fp(t.mapping),r=gp(t.convertedDataset,t.layers),s=[];for(const o of e){if(o.type!=="highlight")continue;const i=hp({annotation:o,rowIdentityVariable:n,dataset:t.dataset,compiledVariableNames:r});i!==null&&s.push({type:"highlight",id:o.id,predicate:i,scope:pp(o.highlight,t.mapping)})}return s}function pp(t,e){const n=x(e.x);return!(n!==null&&n!=="")&&t==="x-value"?"series":t}function fp(t){const e=x(t.x);return e!==null&&e!==""?e:x(t.color)}function hp({annotation:t,rowIdentityVariable:e,dataset:n,compiledVariableNames:r}){switch(t.highlight){case"x-value":return As(t,e,n);case"series":return ws(t,r);case"data-point":{const s=As(t,e,n),o=ws(t,r);return s===null&&o===null?null:s===null?o:o===null?s:{and:[s,o]}}}}function As(t,e,n){if(e===null)return null;const r=yp(t,e,n);return r===null?null:{variable:e,eq:r}}function ws(t,e){const n=t.columnKey;if(!h(n))return null;const r=dp.filter(s=>e.includes(s));return r.length===0?null:{or:r.map(s=>({variable:s,eq:n}))}}function gp(t,e){const n=[...t.getVariableNames()];for(const r of e)for(const s of r.transforms??[]){const{getIntroducedVariables:o}=up.get(s.transformType),i=o?.(s);i&&n.push(...i)}return n}function yp(t,e,n){return t.rowValue!==void 0?t.rowValue:!h(t.rowIndex)||!n.getVariableNames().includes(e)?null:n.getValues(e)[t.rowIndex]??null}function bp(t,e,n){const{theme:r,customPalettes:s}=n;if(s&&t&&s[t])return{type:"custom",id:t};if(t?.startsWith("preset:pastel"))return{type:"pastel",variant:An(e)};if(t?.startsWith("preset:graphy"))return{type:"graphy",variant:An(e)};const a="preset:mono:";if(t?.startsWith(a)){const l=t.slice(a.length);if(xp(l))return{type:"mono",base:l,variant:r}}const c="preset:neon:";if(t?.startsWith(c)){const l=t.slice(c.length);if(vp(l))return{type:"neon",base:l,variant:An(e)}}return{type:"default"}}function An(t){if(t==="waterfall")return"waterfall"}function xp(t){return hi.includes(t)}function vp(t){return gi.includes(t)}function Sp(t){if(!t)return;const e={};for(const[n,r]of Object.entries(t)){if(!n.startsWith("series"))continue;const s=Number.parseInt(n.slice(6));if(Number.isNaN(s))continue;const o={hex:r.customColor,id:r.paletteColorId};(o.hex!==void 0||o.id!==void 0)&&(e[s]=o)}return Object.keys(e).length>0?e:void 0}function Ap({graphType:t,axes:e,appearance:n,ctx:r,isFlipped:s}){const o=[];o.push(Ts("x",s?e?.y:e?.x)),o.push(Ts("y",s?e?.x:e?.y));const i=bp(n?.paletteId,t,r),a=Sp(n?.seriesStyles);return o.push(ge.color.palette({palette:i,overrides:a})),o}function Ts(t,e){return e?.scaleType==="logarithmic"||e?.min!==void 0||e?.max!==void 0?e.scaleType==="logarithmic"?ge[t].log({domainMin:e.min??void 0,domainMax:e.max??void 0}):ge[t]({domainMin:e.min??void 0,domainMax:e.max??void 0}):ge[t]()}const wp=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","scatter","bubble","funnel","combo"]),Tp=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","combo"]);function Mp(t,e,n){const r=e.type??"column",s={dataset:t,axes:e.axes},o=_m(s,r,e.options??void 0,e.appearance??void 0),i=o.coords.coordType==="flip";return{data:o.dataset,mapping:o.mapping,layers:Lp(r,e,o.layers,o.coords,o.mapping,o.seriesVariables),scales:[...Ap({graphType:r,axes:e.axes,appearance:e.appearance,ctx:n,isFlipped:i}),...o.scales],transforms:o.transforms??[],highlights:mp({annotations:e.annotations,dataset:t,mapping:o.mapping,convertedDataset:o.dataset,layers:o.layers}),annotations:Bm({annotations:e.annotations,dataset:t,mapping:o.mapping,seriesVariables:o.seriesVariables}),coords:o.coords,config:Qm(e,i)}}function Lp(t,e,n,r,s,o){const i=_p(e.dataLabels),a=i===void 0?n:n.filter(l=>l.interactive!==!1).map(l=>({...l,dataLabels:{...i,...l.dataLabels}})),c=e.axes?.hasDualYAxis??!1;return[...a,...Ip({type:t,trendline:e.referenceLines?.trendline,coords:r}),...Ep({type:t,hasDualYAxis:c,goalLine:e.referenceLines?.goalLine,coords:r}),...kp({type:t,hasDualYAxis:c,averageLine:e.referenceLines?.averageLine,coords:r,mapping:s,seriesVariables:o})]}function Ip({type:t,trendline:e,coords:n}){return e===void 0?[]:wp.has(t)?n.coordType==="polar"?[]:[R.line({aes:{lineType:{value:"dashed"}},stat:Jt.smooth({method:e}),interactive:!1})]:[]}function Ep({type:t,hasDualYAxis:e,goalLine:n,coords:r}){if(!Vp(n))return[];if(r.coordType==="polar")return[];const s=r.coordType==="flip"?"end":"start";return[R.rule({aes:{y:{value:n.target}},params:{labelPosition:s,label:n.label??"Goal"},yScaleType:t==="combo"&&e?"secondary":"primary",interactive:!1})]}function Vp(t){return t!==void 0&&Number.isFinite(t.target)}function kp({type:t,hasDualYAxis:e,averageLine:n,coords:r,mapping:s,seriesVariables:o}){if(n===void 0)return[];if(!Tp.has(t))return[];if(r.coordType==="polar")return[];const i=Si(n.columnKey);if(!o.includes(i))return[];const a=s.color===q,c=a?ae:i,l=a?[he.filter({variableName:q,operator:"eq",value:i})]:[];return[R.rule({aes:{y:c,color:void 0,group:void 0,lineType:void 0},stat:Jt.mean(),transforms:l,params:{label:"Average",labelPosition:r.coordType==="flip"?"end":"start"},yScaleType:t==="combo"&&e?"secondary":"primary",interactive:!1})]}function _p(t){if(!t)return;const e={};return t.showDataLabels!==void 0&&(e.showDataLabels=t.showDataLabels),t.dataLabelFormat!==void 0&&(e.format=t.dataLabelFormat),t.showStackTotals!==void 0&&(e.showStackTotals=t.showStackTotals),t.showCategoryLabels!==void 0&&(e.showCategoryLabels=t.showCategoryLabels),Object.keys(e).length===0?void 0:e}const wn={color:null,size:"small",labelCrossPosition:.5},Ne={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},Tn={zOrder:"foreground",fit:"contain",opacity:1},Ms={backgroundColor:null,backgroundColorStyle:"opaque"},Oe={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Cp=(t,e,n)=>({differenceArrows:(e?.differenceArrows??[]).map(r=>Rp(t,r,n)).filter(h),shapes:(e?.shapes??[]).map(Op),freeformArrows:(e?.freeformArrows??[]).map(r=>Gp(t,r,n)).filter(h),textAnnotations:(e?.textAnnotations??[]).map(r=>Dp(t,r,n)).filter(h),images:(e?.images??[]).map(Bp),stickers:(e?.stickers??[]).map(r=>Pp(t,r,n)).filter(h),pinnedNumbers:(e?.pinnedNumbers??[]).map(r=>Fp(t,r,n)).filter(h),comments:(e?.comments??[]).map(r=>Np(t,r,n)).filter(h)}),Dp=(t,e,n)=>{const r=Ft(t,e.at,n);return r===null?null:{id:e.id??crypto.randomUUID(),content:e.content,at:r,width:e.width,backgroundColor:e.backgroundColor??Ms.backgroundColor,backgroundColorStyle:e.backgroundColorStyle??Ms.backgroundColorStyle}},Rp=(t,e,n)=>{const r=ut(t,e.start,n),s=ut(t,e.end,n);return r===null||s===null?null:{id:e.id??crypto.randomUUID(),start:r,end:s,label:e.label,color:e.color??wn.color,size:e.size??wn.size,labelCrossPosition:e.labelCrossPosition??wn.labelCrossPosition}},ut=(t,e,n)=>{if(e.layerIndex===void 0)return{anchorValue:e.anchorValue,groupValue:e.groupValue};const r=n[e.layerIndex]?.id;return r===void 0?(t.diagnostics.addWarning({code:"LAYER_INDEX_OUT_OF_RANGE",message:`Annotation references layerIndex ${e.layerIndex} but only ${n.length} layer(s) are defined — dropping this annotation.`,context:{layerIndex:e.layerIndex,available:n.length},suggestion:"Reference a layer index within range, or omit layerIndex to anchor against the data directly."}),null):{layerId:r,anchorValue:e.anchorValue,groupValue:e.groupValue}},Ft=(t,e,n)=>{if(e.anchorType==="panel")return e;const r=ut(t,e,n);return r===null?null:{anchorType:"observation",...r,...e.align!==void 0?{align:e.align}:{},...e.offset!==void 0?{offset:e.offset}:{}}},Pp=(t,e,n)=>{const r=Ft(t,e.at,n);return r===null?null:{id:e.id??crypto.randomUUID(),at:r,sticker:e.sticker}},Fp=(t,e,n)=>{const r=ut(t,e.at,n);return r===null?null:{id:e.id??crypto.randomUUID(),at:r}},Np=(t,e,n)=>{const r=ut(t,e.at,n);return r===null?null:{id:e.id??crypto.randomUUID(),at:r,content:e.content}},Op=t=>({id:t.id??crypto.randomUUID(),kind:t.kind??Ne.kind,zOrder:t.zOrder??Ne.zOrder,region:t.region,fillColor:t.fillColor??Ne.fillColor,fillOpacity:t.fillOpacity??Ne.fillOpacity,strokeWidth:t.strokeWidth??Ne.strokeWidth,strokeColor:t.strokeColor??Ne.strokeColor}),Bp=t=>({id:t.id??crypto.randomUUID(),src:t.src,zOrder:t.zOrder??Tn.zOrder,region:t.region,fit:t.fit??Tn.fit,opacity:t.opacity??Tn.opacity}),Gp=(t,e,n)=>{const r=Ft(t,e.start,n),s=Ft(t,e.end,n);return r===null||s===null?null:{id:e.id??crypto.randomUUID(),start:r,end:s,color:e.color??Oe.color,thickness:e.thickness??Oe.thickness,startArrowheadStyle:e.startArrowheadStyle??Oe.startArrowheadStyle,endArrowheadStyle:e.endArrowheadStyle??Oe.endArrowheadStyle,lineStyle:e.lineStyle??Oe.lineStyle,hasStickerStyle:e.hasStickerStyle??Oe.hasStickerStyle}},$p={parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{top:{isVisible:!0,lineStyle:"dashed",lineWidth:null},right:{isVisible:!0,lineStyle:"dashed",lineWidth:null},bottom:{isVisible:!0,lineStyle:"dashed",lineWidth:null},left:{isVisible:!0,lineStyle:"dashed",lineWidth:null}},overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1},appearance:{textScale:1,background:{type:"theme"},border:{type:"none"},cornerRadius:8,highlightStyle:"dim"}};function Wp(t){return He.merge({},$p,t)}const zp={xLimits:null,yLimits:null},Mn={theta:"x",startAngle:0,innerRadius:0};function Hp(t){const e=t??{type:"coord",coordType:"cartesian"},n=to({},zp,e.params??{});switch(e.coordType){case"cartesian":case"flip":return{...e,params:n};case"polar":return{...e,params:{...n,theta:e.params?.theta??Mn.theta,startAngle:e.params?.startAngle??Mn.startAngle,innerRadius:e.params?.innerRadius??Mn.innerRadius}}}}function Yp(t,e,n){const r=[];for(const s of e){const o=s.layerIndex!==void 0?n[s.layerIndex]?.id:void 0;if(s.layerIndex!==void 0&&o===void 0){t.diagnostics.addWarning({code:"LAYER_INDEX_OUT_OF_RANGE",message:`Highlight references layerIndex ${s.layerIndex} but only ${n.length} layer(s) are defined — dropping this highlight.`,context:{layerIndex:s.layerIndex,available:n.length},suggestion:"Reference a layer index within range, or omit layerIndex to apply the highlight across all layers."});continue}r.push({type:"highlight",id:s.id??crypto.randomUUID(),predicate:s.predicate,scope:s.scope??"data-point",...o!==void 0?{layerId:o}:{}})}return r}const Up="linear",Kp=3,Xp=.3;function jp(t,e){const n=t??e,r=typeof n=="string"?n:n.type;if(r==="smooth"){const s=typeof n=="string"?void 0:n;return{type:"smooth",method:s?.method??Up,order:s?.order??Kp,bandwidth:s?.bandwidth??Xp}}return{type:r}}function Ti(t,e,n,r,s,o){const i=t.get(r.geom),a=r.position??i.defaultPosition,c=Jp(t,e,r,a,n);return Qp({diagnostics:s,coordType:n,geom:i,position:a,dataLabels:c,layerIndex:o}),{id:r.id??crypto.randomUUID(),type:r.type,geom:r.geom,mapping:r.mapping??{},stat:jp(r.stat,"identity"),position:a,yScaleType:r.yScaleType??km,params:i.resolveParams(r.params),transforms:r.transforms??[],interactive:r.interactive??i.defaultInteractive,dataLabels:c}}function qp(t,e,n,r,s){const o=r.map((i,a)=>Ti(t,e,n,i,s,a));return ef(t,o)}const Zp=(t,e,n,r)=>r.label!==void 0?r.label:tf(t,e,n,r),Qp=({diagnostics:t,coordType:e,geom:n,position:r,dataLabels:s,layerIndex:o})=>{if(t===void 0)return;const i=o!==void 0?{layerIndex:o}:{},a=n.type==="bar"&&e==="polar",c=n.type==="bar"&&e!=="polar";if(s.showDataLabels&&!n.dataLabelCoordTypes.includes(e)){t.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${n.type}' under '${e}' coords; none will render.`,context:i,suggestion:"Turn off showDataLabels for this layer."});return}s.showDataLabels&&s.position==="outside"&&c&&j(r)&&t.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{...i,expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),s.showStackTotals&&!(c&&r==="stack")&&t.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",context:i,suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."}),s.showCategoryLabels&&s.showDataLabels&&!a&&t.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showCategoryLabels only applies to polar bars (pie / donut); it will be ignored.",context:i,suggestion:"Turn off showCategoryLabels for this layer."})},Jp=(t,e,n,r,s)=>{const o={...e,...n.mapping},i=Zp(t,n.geom,r,o),a=t.get(n.geom);return{...He.merge({},Em,a.resolveDataLabelDefaults?.(r)??{},a.dataLabels?.[s]??{},n.dataLabels??{}),labelSource:i}},ef=(t,e)=>{const n=new Set;for(const r of e)r.position==="fill"&&n.add(r.yScaleType);return n.size===0?e:e.map(r=>{if(!n.has(r.yScaleType)||!t.get(r.geom).positionRoles.some(c=>c.axis==="y"&&c.role==="scalar"))return r;const i=ce(r.mapping.y);if(!D(i))return r;const a=Math.min(1,Math.max(0,i));return{...r,mapping:{...r.mapping,y:{value:a}}}})},tf=(t,e,n,r)=>t.get(e).resolveDefaultLabelSource?.(r)??qt(n,r),Mi={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},nf={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 Li(t,e,n,r,s,o){switch(e.scaleType){case"inferred":{const i=of(t,e,n,r,s);return Li(t,i,n,r,s,o)}case"continuous":{const i=Mi[e.scaledAesthetic],a=i==="continuous-range"&&e.scaledAesthetic in fs?fs[e.scaledAesthetic]:null,c=e.scaledAesthetic==="size"&&i==="continuous-range"?"sqrt":Fe.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??c,reverse:e.reverse??Fe.reverse,nice:e.nice??Fe.nice,zero:e.zero??Fe.zero,clamp:e.clamp??i!=="position",domainMin:e.domainMin??Fe.domainMin,domainMax:e.domainMax??Fe.domainMax,range:e.range??a??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??bt.domainMin,domainMax:e.domainMax??bt.domainMax,nice:e.nice??bt.nice,reverse:e.reverse??bt.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??et.range,domain:e.domain??et.domain,padding:e.padding??et.padding,reverse:e.reverse??et.reverse};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:dm(t,e.palette,o),overrides:um(t,e.overrides,e.palette,o)};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const i=e;throw new A({message:`Unknown scale type: ${i.scaleType}`})}}}function rf(t,e,n,r,s,o,i){const a=lf(n,r),c=uf(a),l=new Map;for(const u of c)l.set(u.scaledAesthetic,u);const d=[...l.values()].map(u=>Li(t,u,e,r,s,i));return o.coordType==="polar"?sf(d):d}const sf=t=>t.map(e=>e.scaleType==="discrete"?{...e,padding:0}:e);function of(t,e,n,r,s){const o=te(e.scaledAesthetic),i=e.scaledAesthetic==="ySecondary"?cf(r,s):s[o],{layer:a,scaleConstraints:c}=af(t,r);if(e.scaledAesthetic==="x"&&c?.discreteMainAxis)return se(e.scaledAesthetic,e.options);const l=a?.yScaleType==="secondary"?"ySecondary":"y";if(c?.zeroBaseline&&a&&e.scaledAesthetic===l){const f=e.options,b=a.position==="fill";return N(e.scaledAesthetic,{...f,zero:!0,...b&&{nice:!1}})}const d=x(i);if(!h(d)||!n.hasVariable(d))return N(e.scaledAesthetic,e.options);const u=n.getType(d),m=Mi[e.scaledAesthetic];switch(nf[u][m]){case"discrete":return se(e.scaledAesthetic,e.options);case"datetime":return Lt(e.scaledAesthetic,e.options);case"continuous":return N(e.scaledAesthetic,e.options);case"identity":default:return tt(e.scaledAesthetic)}}function af(t,e){for(const n of e){const{scaleConstraints:r}=t.geomRegistry.get(n.geom);if(r!==void 0)return{layer:n,scaleConstraints:r}}return{}}function cf(t,e){const n=t.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??e.y:e.y}function lf(t,e){return!e.some(s=>s.yScaleType==="secondary")||t.some(s=>s.scaledAesthetic==="ySecondary")?t:[...t,It("ySecondary")]}function uf(t){return t.some(n=>n.scaledAesthetic==="color")?t:[...t,bi("color")]}function Ls(t,e,n){const r=Hp(e.coords),s=qp(t.geomRegistry,e.mapping,r.coordType,e.layers,t.diagnostics),o=rf(t,e.data,e.scales,s,e.mapping,r,n),i=Wp(e.config),a=Yp(t,e.highlights,s),c=Cp(t,e.annotations,s);return{data:e.data,mapping:e.mapping,layers:s,scales:o,transforms:e.transforms,highlights:a,annotations:c,coords:r,config:i}}class Ii{constructor(e){this.container=e}compile({input:e,dataset:n,ctx:r}){const s=r.customPalettes??{};return yi(e)?Ls(this.container,Mp(n,e,r),s):Ls(this.container,{...e,data:n},s)}}class df{constructor(e){this.registry=e}compute(e,n){return this.registry.get(e.type).compute({data:n.data,mapping:n.mapping,spec:e,xScaleIsDiscrete:n.xScaleIsDiscrete})}}const mf=({layer:t})=>{if(t.position==="stack")return;const e=x(t.mapping.y);if(e===null)return;let n=0,r=0;for(const s of t.data){const o=s[e];D(o)&&(n+=o,r+=Math.abs(o))}return{grandTotal:n,absoluteGrandTotal:r}},pf=({layer:t})=>{if(t.position!=="stack")return;const e=x(t.mapping.x);if(e===null||!t.data.hasVariable(g.yMin)||!t.data.hasVariable(g.yMax))return;const n=new Map;for(const s of t.data){const o=s[e],i=Z(s),a=Y(s),c=le(s),l=oe(s),d=Qo(s);if(!h(o)||!h(i)||!h(a)||!h(c)||!h(l)||!h(d))continue;const u=d>=0;if(Math.abs(d)===0)continue;const p=sr(s,e),f={yMin:i,yMax:a},b=n.get(p);if(b===void 0){n.set(p,{total:d,topPositive:u?f:null,bottomNegative:u?null:f,anchorXMin:c,anchorXMax:l});continue}b.total+=d,u?(b.topPositive===null||a>b.topPositive.yMax)&&(b.topPositive=f):(b.bottomNegative===null||i<b.bottomNegative.yMin)&&(b.bottomNegative=f)}const r=[];for(const[s,o]of n){const i=o.topPositive??o.bottomNegative;i!==null&&r.push({xKey:s,total:o.total,anchor:{xMin:o.anchorXMin,xMax:o.anchorXMax,yMin:i.yMin,yMax:i.yMax,direction:o.topPositive!==null?"positive":"negative"}})}return r};class ff extends Ke{constructor(e){super(),this.container=e}dependencies(){return[]}compileLayer(e){const n=this.container.geomRegistry.get(e.geom),r={};if(n.summaries.stackTotals){const s=pf({layer:e});s!==void 0&&(r.stackTotals=s)}if(n.summaries.grandTotal){const s=mf({layer:e});s!==void 0&&(r.grandTotal=s.grandTotal,r.absoluteGrandTotal=s.absoluteGrandTotal)}return{...e,summary:r}}}class hf extends xe{constructor(e){super(),this.registry=e}key(e){return e.data}dependencies(e){return[e.transforms]}run(e){return e.transforms.reduce((n,r)=>this.registry.get(r.transformType).apply(n,r),e.data)}}const Is={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},gf=["color","size","alpha","strokeWidth","lineType"];class yf extends Ke{dependencies(e){return gf.map(n=>e.scales[n])}compileLayer(e,n){let r=e.data;const s=Object.entries(ve);for(const[o,i]of s){const a=ce(e.mapping[o]);if(a!==void 0){r=r.deriveVariable(i,Is[o],()=>a);continue}const c=x(e.mapping[o]),l=n.scales[o];if(!l||l.kind!=="visual")continue;const d=bf(o,c,l);d&&(r=r.deriveVariable(i,Is[o],d))}return{...e,data:r}}}const bf=(t,e,n)=>{if(!e){if(t!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>h(r[e])?n.map(r[e]):null};class xf{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,n={}){const r={...e,severity:"warning",kind:"user-input"};n.persistent?this.persistent.push(r):this.diagnostics.push(r)}addError(e){this.diagnostics.push({...e,severity:"error",kind:"user-input"})}reset(){this.diagnostics=[]}drain(){const e=this.persistent.length===0?this.diagnostics:[...this.persistent,...this.diagnostics];if(e.length===0)return{errors:[],warnings:[]};const n=Es(e.filter(s=>s.severity==="error")),r=Es(e.filter(s=>s.severity==="warning"));return this.diagnostics=[],{errors:n,warnings:r}}}function Es(t){const e=new Set;return t.filter(n=>{const r=JSON.stringify(n);return e.has(r)?!1:(e.add(r),!0)})}function vf(t=new ir){return{diagnostics:new xf,geomRegistry:t}}class Ei{constructor(e,n,r,s,o,i,a,c,l,d,u,m,p,f,b){this.container=e,this.dataCompiler=n,this.specCompiler=r,this.transformCompiler=s,this.constantMappingCompiler=o,this.layerPhasedCompiler=i,this.scaleCompiler=a,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=d,this.guideCompiler=u,this.summariseCompiler=m,this.highlightsCompiler=p,this.configCompiler=f,this.annotationsCompiler=b,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"config",getStats:()=>this.configCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const n=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({input:e.input,ctx:e.ctx??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(n)}catch(n){return this.toErrorResult(n)}}recompile(e){try{const n=this.runCompile(()=>{if(e.data===void 0)return this.runPipeline({spec:e.spec});this.lastData=e.data;const r=zc(e.spec.data,e.spec.mapping);return this.runPipeline({spec:yn(e.spec,{data:this.dataCompiler.compile(e.data),mapping:r})})});return this.toOkResult(n)}catch(n){return this.toErrorResult(n)}}getCacheStats(){const e={};for(const{name:n,getStats:r}of this.stages)e[n]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}runCompile(e){this.container.diagnostics.reset();const n=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),n}toOkResult(e){return{ok:!0,compiled:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const n=this.container.diagnostics.drain();return this.lastDiagnostics=n,{ok:!1,errors:n.errors.length>0?n.errors:[no(e)],warnings:n.warnings}}trackCompile(e){if(!Le)return e();const n=this.getCacheStats(),r=performance.now(),s=e(),o=performance.now()-r,i={};for(const{name:a,getStats:c}of this.stages){const l=c();i[a]={hits:l.hits-n[a].hits,misses:l.misses-n[a].misses}}return this.lastCompile={stages:i,durationMs:o},s}runPipeline({spec:e}){return $t({spec:e}).pipe(({spec:r})=>({spec:yn(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const s=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:yn(r,{data:s.data,mapping:s.mapping})}}).pipe(({spec:r})=>({layers:this.layerPhasedCompiler.compile({data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales})})).pipe(({spec:r,layers:s})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:s})).pipe(({layers:r,scales:s})=>({scales:this.scaleCompiler.compile({layers:r,scales:s})})).pipe(({spec:r,scales:s})=>({config:this.configCompiler.compile({config:r.config,scales:s})})).pipe(({layers:r,scales:s})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:s})})).pipe(({layers:r,scales:s})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:s})})).pipe(({spec:r,layers:s,coordSystem:o})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:o,layers:s})})).pipe(({layers:r})=>({layers:this.summariseCompiler.compile({layers:r})})).pipe(({spec:r,scales:s,layers:o,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:s,config:r.config,layers:o,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:s})=>({layers:this.highlightsCompiler.compile({layers:s,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:s,coordSystem:o})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:s,coordSystem:o,config:r.config})})).result()}}const Sf=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","highlights","config","annotations"],Af=({plugins:t=[]}={})=>{const e=ui(t),{geomRegistry:n,statRegistry:r,transformRegistry:s}=Cd(e),o=vf(n),i=new pm(o),a=new hf(s);for(const c of e.warnings)o.diagnostics.addWarning(c,{persistent:!0});return new Ei(o,new ml,new Ii(o),a,new Wc,new nd(o,a,r,new ed(o,a,new df(r),new Tl,new Al(o),new Rd(new Bd))),new Xd(o,i),new Uc(new ll),new Kd(o),new yf,new Pu(o),new ff(o),new ju(o),new Pc(o),new vc(o))};function wf(t,e){return t.geom===e}function Vi(...t){let e={},n;const[r,...s]=t;h(r)&&!Tf(r)?(e=r,n=s):n=t;const o={mapping:e,layers:[],scales:[],transforms:[],highlights:[],config:{}};return n.reduce((i,a)=>_i(i,a),o)}function ki(t,...e){return e.reduce((n,r)=>_i(n,r),t)}function Tf(t){return typeof t=="object"&&t!==null&&"type"in t}function _i(t,e){switch(e.type){case"scale":return{...t,scales:[...t.scales,e]};case"coord":return{...t,coords:e};case"config":return{...t,config:to({},t.config,e.config)};case"layer":return{...t,layers:[...t.layers,e]};case"transform":return{...t,transforms:[...t.transforms,e]};case"mapping":return{...t,mapping:{...t.mapping,...e.mapping}};case"highlight":return{...t,highlights:[...t.highlights,e]};case"annotation":return Mf(t,e);default:{const n=e;throw new A({message:`Unknown spec item type: ${n.type}`})}}}function Mf(t,e){const n={...t.annotations};switch(e.kind){case"differenceArrow":n.differenceArrows=[...n.differenceArrows??[],e.annotation];break;case"shape":n.shapes=[...n.shapes??[],e.annotation];break;case"arrow":n.freeformArrows=[...n.freeformArrows??[],e.annotation];break;case"text":n.textAnnotations=[...n.textAnnotations??[],e.annotation];break;case"image":n.images=[...n.images??[],e.annotation];break;case"sticker":n.stickers=[...n.stickers??[],e.annotation];break;case"pinnedNumber":n.pinnedNumbers=[...n.pinnedNumbers??[],e.annotation];break;case"comment":n.comments=[...n.comments??[],e.annotation];break;default:{const r=e;throw new Error(`Unknown annotation kind: ${r.kind}`)}}return{...t,annotations:n}}function Lf(t){const e=t?.plugins??[],n=Ef(e);return{geom:{...R,...n.geom},stat:{...Jt,...n.stat},transform:{...he,...n.transform},scale:ge,coord:$,createSpec:Vi,pipe:ki,plugins:e}}const If=t=>(e={})=>Ze(t,e);function Ef(t){const{geoms:e,stats:n,transforms:r}=ui(t),s={};for(const a of e)s[a.type]=If(a.type);const o={};for(const a of n)o[a.type]=()=>({type:a.type});const i={};for(const a of r)i[a.transformType]=c=>({type:"transform",transformType:a.transformType,options:c?.options});return{geom:s,stat:o,transform:i}}const dr="–",Ci="n/a",H={timeZone:"UTC"},G=t=>e=>{if(!X(e))return dr;try{return t(e)}catch{return Ci}},Se=t=>e=>D(e)?t(e):dr,mr=t=>e=>zt(e)?e:dr,Vf=2,kf=3,_f=2,Cf=0,Df=1,Rf=2,Pf=Ra.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Di=({valueFormat:t,locale:e,numberFormat:n,intlOptions:r})=>Se(s=>{const o=typeof n.decimals=="number"?n.decimals:Vf,i=hr(s,o),{base:a,suffix:c}=fr(s,n.abbreviation),l={...i,...qn(t)?{style:"currency",currencyDisplay:"narrowSymbol",currency:t.iso}:{},...r};return`${Intl.NumberFormat(e,l).format(a)}${c}`}),Ri=({locale:t,numberFormat:e,intlOptions:n})=>Se(r=>{const{base:s,suffix:o}=fr(r,e.abbreviation),a={...hr(s,e.decimals),...n};return`${Intl.NumberFormat(t,a).format(s)}${o}`}),pr=t=>Se(e=>Pf(e)),Pi=({locale:t,intlOptions:e})=>Se(n=>Intl.NumberFormat(t,{maximumFractionDigits:0,...e}).format(n)),Fi=({locale:t,numberFormat:e,intlOptions:n})=>Se(r=>{const s=hr(r,e.decimals);return Intl.NumberFormat(t,{...s,...n,style:"percent"}).format(r)}),fr=(t,e="none")=>{switch(e){case"none":return{base:t,suffix:""};case"auto":{const n=Ff(t);return fr(t,n)}default:return{base:t/st[e],suffix:e}}},hr=(t,e)=>{if(typeof e=="number")return{minimumFractionDigits:e,maximumFractionDigits:e};const n=Math.ceil(Math.log10(Math.abs(t))),r=n>=kf?Cf:n===_f?Df:Rf;return{minimumFractionDigits:e==="auto"?0:r,maximumFractionDigits:r}},Ff=t=>{const e=Math.abs(t);return e>=st.b?"b":e>=st.m?"m":e>=st.k?"k":"none"},Nf=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{dateStyle:"medium",...H,...e}).format(n)),Of=({locale:t,intlOptions:e})=>G(n=>{const r=Intl.DateTimeFormat(t,{dateStyle:"medium",timeStyle:"medium",...H,...e}).formatToParts(n);return Bf(r.map(Gf))}),Ni=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{day:"numeric",month:"long",...H,...e}).format(n)),Oi=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{month:"long",...H,...e}).format(n)),gr=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{month:"short",year:"numeric",...H,...e}).format(n)),yr=t=>G(e=>`Q${Math.floor(e.getUTCMonth()/3)+1} ${e.getUTCFullYear()}`),Bi=({locale:t,intlOptions:e})=>G(n=>{const r=_.addDays(n,6);return Intl.DateTimeFormat(t,{day:"numeric",month:"long",...H,...e,year:void 0}).formatRange(n,r)}),Gi=({locale:t,intlOptions:e})=>G(n=>{const r=_.addDays(n,6);return Intl.DateTimeFormat(t,{dateStyle:"medium",...H,...e}).formatRange(n,r)}),br=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{year:"numeric",...H,...e}).format(n)),$i=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{timeStyle:"short",...H,...e}).format(n)),Bf=t=>t.map(e=>e.value).join(""),Gf=t=>t.type!=="literal"||t.value!==", "?t:{type:"literal",value:" • "},$f=1,Wf=4,zf=1,Vs=1e3,Hf=({valueFormat:t,locale:e,tickValues:n,intlOptions:r})=>Se(s=>{const i={...vr(s,n),notation:"compact",...qn(t)?{style:"currency",currencyDisplay:"narrowSymbol",currency:t.iso}:{},...r};return xr(s,e,i)}),Yf=({locale:t,tickValues:e,intlOptions:n})=>Se(r=>{const o={...vr(r,e),notation:"compact",...n};return xr(r,t,o)}),Uf=({locale:t,tickValues:e,intlOptions:n})=>Se(r=>{const o={...vr(r,e),notation:"compact",...n,style:"percent"};return xr(r,t,o)}),xr=(t,e,n)=>Intl.NumberFormat(e,n).formatToParts(t).map(s=>s.type==="compact"?s.value.toLowerCase():s.value).join(""),Wi=t=>Math.abs(t)>Vs?Wi(t/Vs):Number.isInteger(t),Kf=t=>{if(t.length<2)return!1;const[e,n]=t;return typeof e!="number"||typeof n!="number"?!1:Math.abs(n-e)<$f},vr=(t,e)=>Wi(t)?{minimumFractionDigits:0,maximumFractionDigits:0}:Kf(e)?{minimumFractionDigits:0,maximumFractionDigits:Wf}:{minimumFractionDigits:0,maximumFractionDigits:zf},Xf=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{day:"numeric",month:"short",...H,...e}).format(n)),jf=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{month:"short",...H,...e}).format(n)),qf=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{day:"numeric",month:"short",...H,...e}).format(n)),Zf=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{timeStyle:"short",...H,...e}).format(n)),Sr=t=>{const{valueFormat:e}=t;switch(e.type){case"currency":return Hf(t);case"date":case"datetime":return Xf(t);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return qf(t);case"decimal":case"integer":return Yf(t);case"duration":return pr();case"month":return jf(t);case"month_year":return gr(t);case"percentage":return Uf(t);case"quarter":return yr();case"text":return mr();case"time":return Zf(t);case"year":return br(t);case"lookup":return Sr({...t,valueFormat:e.fallback});default:{const n=e;throw new A({message:`Unhandled value format: ${n.type}`})}}},Qf=40,Jf=60,ks=8,eh=50,th=1/3,nh=1/4,Ln="…",rh=(t,e,n)=>{if(e<=0||t.length===0)return"";if(n(t)<=e)return t;if(n(Ln)>e)return"";let r=0,s=t.length-1,o=0;for(;r<=s;){const i=r+s>>>1,a=t.slice(0,i)+Ln;n(a)<=e?(o=i,r=i+1):s=i-1}return t.slice(0,o)+Ln},sh=t=>t.formattedAxis.position==="top"||t.formattedAxis.position==="bottom"?oh(t):ih(t),oh=({formattedAxis:t,bandwidthPx:e,panelRect:n,measureLabel:r})=>{const{widths:s,maxWidth:o,maxHeight:i}=zi(t.ticks,r),a=e-ks;if(o<=a)return{...t,labelRotation:0,labelMaxWidthPx:null};if(e>=eh){const l=$n(a);return{...t,ticks:Gn(t.ticks,s,l,r),labelRotation:0,labelMaxWidthPx:l}}if(i+ks>e)return{...t,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=$n(n.height*th);return{...t,ticks:Gn(t.ticks,s,c,r),labelRotation:-90,labelMaxWidthPx:c}},ih=({formattedAxis:t,bandwidthPx:e,panelRect:n,measureLabel:r})=>{const{widths:s,maxWidth:o,maxHeight:i}=zi(t.ticks,r);if(i>e)return{...t,ticks:[],labelRotation:0,labelMaxWidthPx:null};const a=$n(n.width*nh);return o<=a?{...t,labelRotation:0,labelMaxWidthPx:null}:{...t,ticks:Gn(t.ticks,s,a,r),labelRotation:0,labelMaxWidthPx:a}},zi=(t,e)=>{const n=[];let r=0,s=0;for(const o of t){const{width:i,height:a}=e(o.formattedLabel);n.push(i),i>r&&(r=i),a>s&&(s=a)}return{widths:n,maxWidth:r,maxHeight:s}},Gn=(t,e,n,r)=>{const s=o=>r(o).width;return t.map((o,i)=>(e[i]??0)<=n?o:{...o,formattedLabel:rh(o.formattedLabel,n,s)})},$n=t=>Math.max(0,Math.floor(t)),ah=(t,e,n,r)=>{if(t.length===0)return!0;const s=e==="top"||e==="bottom",o=s?Jf:Qf;let i=n-(t.length-1)*o;for(const a of t){const{width:c,height:l}=r(a);if(i-=s?c:l,i<0)return!1}return!0},ch=({axis:t,availableSpacePx:e,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:s,position:o}=t;if(s.length===0)return[];const i=new Map,a=u=>{const m=i.get(u);if(m)return m;const p=s[u],f=p?lh(p.ticks,r(p)):[];return i.set(u,f),f};let c=0,l=s.length-1,d=-1;for(;c<=l;){const u=c+l>>>1,p=a(u).map(f=>f.formattedLabel);ah(p,o,e,n)?(d=u,c=u+1):l=u-1}return d>=0?a(d):a(0)},lh=(t,e)=>t.map(n=>({...n,formattedLabel:e(n.value)})),_s=.5,en=({box:t,frame:e,placement:n,justify:r,align:s,offset:o,labelWidth:i,labelHeight:a})=>{const c=(e.valueAxis==="x"?t.height:t.width)===0,l={anchor:dh(r,e.valueDirectionSign),placement:n,offset:o},d={anchor:mh(s),placement:c?n:"inside",offset:c?o:0},u=e.valueAxis==="x"?l:d,m=e.valueAxis==="x"?d:l,p=Ds(u,{min:t.x,max:t.x+t.width,halfExtent:i/2}),f=Ds(m,{min:t.y,max:t.y+t.height,halfExtent:a/2});return{x:p,y:f,position:uh(t,p,f,i,a)}},Cs=(t,e,n,r)=>n-r>=t-_s&&n+r<=e+_s,uh=(t,e,n,r,s)=>{if(t.width===0&&t.height===0)return"outside";const o=t.width===0||Cs(t.x,t.x+t.width,e,r/2),i=t.height===0||Cs(t.y,t.y+t.height,n,s/2);return o&&i?"inside":"outside"},dh=(t,e)=>t==="center"?"center":t==="end"===(e===1)?"max":"min",mh=t=>t==="center"?"center":t==="start"?"min":"max",Ds=({anchor:t,placement:e,offset:n},{min:r,max:s,halfExtent:o})=>{if(t==="center")return(r+s)/2;if(e==="inside"&&r===s)return r;const i=n+o;return t==="min"?e==="inside"?r+i:r-i:e==="inside"?s-i:s+i},ph=(t,e,n,r,s)=>{const o=e??t,i=1-Math.max(t,o);return{box:{x:n*r,y:i*s,width:0,height:Math.abs(t-o)*s},frame:{valueAxis:"y",valueDirectionSign:t>=o?-1:1}}},fh=t=>{const e=[];if(!t.layer.dataLabels.showDataLabels)return e;const{position:n,justify:r,align:s,offset:o}=t.layer.dataLabels;for(const i of t.layer.data){const a=W(i),c=Y(i)??C(i);if(a===null||c===null||a<0||a>1||c<0||c>1)continue;const l=t.formatLabel(i);if(l==="")continue;const{width:d,height:u}=t.measureDataLabel("dataLabel",l),{box:m,frame:p}=ph(c,Z(i),a,t.panelRect.width,t.panelRect.height),f=en({box:m,frame:p,placement:n==="auto"?"outside":n,justify:n==="auto"?"end":r,align:n==="auto"?"center":s,offset:o,labelWidth:d,labelHeight:u});e.push({layerId:t.layer.id,x:f.x,y:f.y,text:l,width:d,height:u,isRotated:!1,target:"observation",position:"outside"})}return e},hh={place:fh,getPercentageValueStrategy:t=>t.position==="fill"?"fill":j(t.position)?"stack":"none"},St=6,gh=t=>{const e=[],n=j(t.layer.position),r=t.coordSystem.mainAxis==="y";if(t.layer.dataLabels.showDataLabels){const{entries:s,shouldRotate:o}=bh({layer:t.layer,mainAxis:t.coordSystem.mainAxis,panelRect:t.panelRect,measureDataLabel:t.measureDataLabel,formatLabel:t.formatLabel,isFlipped:r});for(const i of s){const a=t.layer.dataLabels.position==="auto"?Ah({mainAxis:t.coordSystem.mainAxis,isStacked:n,isNegativeBar:i.isNegative,shouldRotate:o,bounds:i.bounds,labelWidth:i.labelWidth,labelHeight:i.labelHeight,panelWidth:t.panelRect.width,panelHeight:t.panelRect.height,offset:t.layer.dataLabels.offset}):Th(t.layer.dataLabels,t.coordSystem.mainAxis,n,i);a!==null&&e.push({layerId:t.layer.id,x:a.x,y:a.y,text:i.text,width:i.labelWidth,height:i.labelHeight,isRotated:a.isRotated,target:"observation",position:a.position})}}if(t.layer.dataLabels.showStackTotals){const s=Eh({layer:t.layer,mainAxis:t.coordSystem.mainAxis,panelRect:t.panelRect,measureDataLabel:t.measureDataLabel,formatAbsolute:t.formatAbsolute});for(const o of s)e.push(o)}return e},yh={place:gh,getPercentageValueStrategy:t=>t.position==="fill"?"fill":j(t.position)?"stack":"absoluteGrandTotal"},bh=({layer:t,mainAxis:e,panelRect:n,measureDataLabel:r,formatLabel:s,isFlipped:o})=>{const i=[];let a=!1;const c=x(t.mapping.y);for(const l of t.data){const d=xh(e,l);if(d===null)continue;const u=s(l);if(u==="")continue;const{width:m,height:p}=r("dataLabel",u),f=Hi(d,n);m>f.width&&(a=!0);const b=c===null?null:l[c],y=D(b)&&b<0;i.push({isNegative:y,text:u,labelWidth:m,labelHeight:p,bounds:f})}return{entries:i,shouldRotate:!o&&a}},Hi=(t,e)=>({x:t.x*e.width,y:t.y*e.height,width:t.width*e.width,height:t.height*e.height}),Yi=(t,e,n,r,s)=>{if(t==="x"){let a=1-s,c=s-r;return c<0&&(a+=c,c=-c),{x:e,y:a,width:n-e,height:c}}let o=e,i=n-e;return i<0&&(o+=i,i=-i),{x:o,y:1-s,width:i,height:s-r}},xh=(t,e)=>{const n=le(e),r=oe(e),s=Z(e),o=Y(e)??C(e);return n===null||r===null||s===null||o===null?null:Yi(t,n,r,s,o)},vh=(t,e)=>{const{xMin:n,xMax:r,yMin:s,yMax:o}=e.anchor;return Yi(t,n,r,s,o)},Sh=(t,e)=>t==="x"?e?"bottom":"top":e?"left":"right",Ui=(t,e,n)=>n?{width:e,height:t}:{width:t,height:e},Ah=t=>t.isStacked?Mh({bounds:t.bounds,labelWidth:t.labelWidth,labelHeight:t.labelHeight,isRotated:t.shouldRotate}):Ih({edge:Sh(t.mainAxis,t.isNegativeBar),bounds:t.bounds,labelWidth:t.labelWidth,labelHeight:t.labelHeight,isRotated:t.shouldRotate,panelWidth:t.panelWidth,panelHeight:t.panelHeight,offset:t.offset}),wh=(t,e)=>t==="x"?{valueAxis:"y",valueDirectionSign:e?1:-1}:{valueAxis:"x",valueDirectionSign:e?-1:1},Th=(t,e,n,r)=>{if(t.position==="auto")return null;const s=n&&t.position==="outside"?"inside":t.position,o=en({box:r.bounds,frame:wh(e,r.isNegative),placement:s,justify:t.justify,align:t.align,offset:t.offset,labelWidth:r.labelWidth,labelHeight:r.labelHeight});return{x:o.x,y:o.y,isRotated:!1,position:o.position}},Mh=({bounds:t,labelWidth:e,labelHeight:n,isRotated:r})=>{const s=Ui(e,n,r);return s.width>t.width||s.height>t.height?null:{x:t.x+t.width/2,y:t.y+t.height/2,isRotated:r,position:"inside"}},Lh=(t,e,n,r)=>{switch(t){case"top":return{edgeCoord:e.y,outwardSign:-1,panelExtent:r};case"bottom":return{edgeCoord:e.y+e.height,outwardSign:1,panelExtent:r};case"left":return{edgeCoord:e.x,outwardSign:-1,panelExtent:n};case"right":return{edgeCoord:e.x+e.width,outwardSign:1,panelExtent:n}}},Ih=({edge:t,bounds:e,labelWidth:n,labelHeight:r,isRotated:s,panelWidth:o,panelHeight:i,offset:a})=>{const c=t==="top"||t==="bottom",l=e.x+e.width/2,d=e.y+e.height/2,u=Ui(n,r,s),m=c?u.height:u.width,p=c?u.width:u.height,f=c?e.height:e.width,b=c?e.width:e.height,y=m/2,{edgeCoord:v,outwardSign:S,panelExtent:T}=Lh(t,e,o,i);if(m+a<f){if(p>b)return null;if(s)return{x:l,y:d,isRotated:!0,position:"inside"};const F=v-S*(y+a);return{...c?{x:l,y:F}:{x:F,y:d},isRotated:!1,position:"inside"}}const V=v+S*(y+a);return V-y<0||V+y>T?null:{...c?{x:l,y:V}:{x:V,y:d},isRotated:s,position:"outside"}},Eh=({layer:t,mainAxis:e,panelRect:n,measureDataLabel:r,formatAbsolute:s})=>{const o=[],i=t.summary.stackTotals;if(i===void 0||i.length===0)return o;const a=e==="y";for(const c of i){const l=Hi(vh(e,c),n),d=s(c.total),{width:u,height:m}=r("stackTotal",d),p=c.anchor.direction==="positive";let f,b;a?(f=p?l.x+l.width+St+u/2:l.x-St-u/2,b=l.y+l.height/2):(f=l.x+l.width/2,b=p?l.y-St-m/2:l.y+l.height+St+m/2),o.push({layerId:t.id,x:f,y:b,text:d,width:u,height:m,isRotated:!1,target:"aggregate",position:"outside"})}return o},Vh=t=>{const e=[];if(!t.layer.dataLabels.showDataLabels)return e;const{position:n,justify:r,align:s,offset:o}=t.layer.dataLabels;for(const i of t.layer.data){const a=W(i),c=C(i);if(a===null||c===null||a<0||a>1||c<0||c>1)continue;const l=t.formatLabel(i);if(l==="")continue;const{width:d,height:u}=t.measureDataLabel("dataLabel",l),m=en({box:{x:a*t.panelRect.width,y:(1-c)*t.panelRect.height,width:0,height:0},frame:{valueAxis:"y",valueDirectionSign:-1},placement:n==="auto"?"outside":n,justify:n==="auto"?"end":r,align:n==="auto"?"center":s,offset:o,labelWidth:d,labelHeight:u});e.push({layerId:t.layer.id,x:m.x,y:m.y,text:l,width:d,height:u,isRotated:!1,target:"observation",position:m.position})}return e},kh={place:Vh,getPercentageValueStrategy:()=>"none"},_h=t=>{const e=[];if(!t.layer.dataLabels.showDataLabels)return e;const{position:n,justify:r,align:s,offset:o}=t.layer.dataLabels;for(const i of t.layer.data){const a=W(i),c=C(i);if(a===null||c===null||a<0||a>1||c<0||c>1)continue;const l=t.formatLabel(i);if(l==="")continue;const{width:d,height:u}=t.measureDataLabel("dataLabel",l),m=(ko(i)??t.layer.params.size)/2,p=en({box:{x:a*t.panelRect.width,y:(1-c)*t.panelRect.height,width:0,height:0},frame:{valueAxis:"y",valueDirectionSign:-1},placement:n==="auto"?"outside":n,justify:n==="auto"?"end":r,align:n==="auto"?"center":s,offset:o+m,labelWidth:d,labelHeight:u});e.push({layerId:t.layer.id,x:p.x,y:p.y,text:l,width:d,height:u,isRotated:!1,target:"observation",position:p.position})}return e},Ch={place:_h,getPercentageValueStrategy:()=>"none"};function Ki(t){return{startAngle:t[g.xMin],endAngle:t[g.xMax]}}function Xi(t){return{innerRadius:t[g.yMin],outerRadius:t[g.yMax]??t[g.y]}}const Dh=" · ",In=2,Rh=t=>typeof t=="string"?t:t instanceof Date?t.toISOString():String(t),Ph=(t,e)=>{const n=x(e.x);return n!==null&&n!==it.x?jt(t,e):s=>Ue(s)},dt=(t,e,n,r)=>{const s=Math.abs(t==="radial"?Math.sin(e):Math.cos(e)),o=Math.abs(t==="radial"?Math.cos(e):Math.sin(e));return s*(n/2)+o*(r/2)},Fh=({wedge:t,labelRadius:e,labelAngle:n,labelWidth:r,labelHeight:s})=>{const o=dt("radial",n,r,s);if(!(e-o>=t.innerRadiusPx-In&&e+o<=t.outerRadiusPx+In)||e<=0)return!1;const a=Math.abs(t.endAngle-t.startAngle)/2,c=dt("tangential",n,r,s)/e,l=In/e;return Math.abs(n-t.midAngle)+c<=a+l},Nh=({x:t,y:e,labelWidth:n,labelHeight:r,panelRect:s})=>t-n/2>=0&&t+n/2<=s.width&&e-r/2>=0&&e+r/2<=s.height,Oh=({wedge:t,isRadialBar:e,offset:n,labelWidth:r,labelHeight:s})=>e?{labelRadius:(t.innerRadiusPx+t.outerRadiusPx)/2,labelAngle:t.midAngle,position:"inside"}:{labelRadius:t.outerRadiusPx+n+dt("radial",t.midAngle,r,s),labelAngle:t.midAngle,position:"outside"},Bh=({wedge:t,placement:e,justify:n,align:r,offset:s,labelWidth:o,labelHeight:i})=>{const a=r==="start"?t.startAngle:r==="end"?t.endAngle:t.midAngle,c=s+dt("radial",a,o,i);let l;n==="center"?l=(t.innerRadiusPx+t.outerRadiusPx)/2:n==="end"?l=e==="inside"?t.outerRadiusPx-c:t.outerRadiusPx+c:l=e==="inside"?t.innerRadiusPx+c:t.innerRadiusPx-c;let d=a;if(r!=="center"&&l>0){const u=dt("tangential",a,o,i)/l;d=a+(r==="start"?1:-1)*u}return{labelRadius:l,labelAngle:d,position:Fh({wedge:t,labelRadius:l,labelAngle:d,labelWidth:o,labelHeight:i})?"inside":"outside"}},Gh=t=>{const e=[];if(!t.layer.dataLabels.showDataLabels)return e;const{position:n,justify:r,align:s,offset:o,showCategoryLabels:i}=t.layer.dataLabels,a=i?Ph(t.layer.data,t.layer.mapping):null,c=t.coordSystem.bandAxis==="y",l=t.panelRect.width/2,d=t.panelRect.height/2,u=Math.min(t.panelRect.width,t.panelRect.height)/2;for(const m of t.layer.data){const{startAngle:p,endAngle:f}=Ki(m),{innerRadius:b,outerRadius:y}=Xi(m);if(p===null||f===null||y===null)continue;const v=t.formatLabel(m);if(v==="")continue;const S=a===null?null:a(m),T=S===null?v:`${Rh(S)}${Dh}${v}`,{width:V,height:F}=t.measureDataLabel("dataLabel",T),ue={startAngle:p,endAngle:f,midAngle:(p+f)/2,innerRadiusPx:(b??0)*u,outerRadiusPx:y*u},{labelRadius:J,labelAngle:de,position:ft}=n==="auto"?Oh({wedge:ue,isRadialBar:c,offset:o,labelWidth:V,labelHeight:F}):Bh({wedge:ue,placement:n,justify:r,align:s,offset:o,labelWidth:V,labelHeight:F}),M=l+Math.sin(de)*J,U=d-Math.cos(de)*J;n==="auto"&&!Nh({x:M,y:U,labelWidth:V,labelHeight:F,panelRect:t.panelRect})||e.push({layerId:t.layer.id,x:M,y:U,text:T,width:V,height:F,isRotated:!1,target:"observation",position:ft})}return e},$h={place:Gh,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Wh=t=>{const e=P({...t,valueFormat:t.valueFormat.fallback}),n={};for(const[s,o]of Object.entries(t.valueFormat.cases))n[s]=P({...t,valueFormat:o});const r=t.valueFormat.byVariable;return(s,o)=>{if(o===void 0||o[r]===void 0)return e(s);const i=I(o[r]),a=n[i];return a!==void 0?a(s,o):e(s)}},P=t=>{switch(t.valueFormat.type){case"currency":return Di(t);case"date":return Nf(t);case"datetime":return Of(t);case"day_month":return Ni(t);case"decimal":return Ri(t);case"duration":return pr();case"integer":return Pi(t);case"month":return Oi(t);case"month_year":return gr(t);case"percentage":return Fi(t);case"quarter":return yr();case"text":return mr();case"weekly_date_range":return Bi(t);case"weekly_date_range_with_year":return Gi(t);case"year":return br(t);case"time":return $i(t);case"lookup":return Wh({...t,valueFormat:t.valueFormat});default:{const e=t.valueFormat;throw new A({message:`Unhandled value format: ${e.type}`})}}};function Ar({layer:t,numberFormat:e,locale:n}){return P({valueFormat:Vo(t),locale:n,numberFormat:e})}const ji=({layer:t,coordSystem:e,axes:n,numberFormat:r,panelRect:s,measureDataLabel:o,formattingLocale:i,percentageValueStrategy:a})=>{const c=Ar({layer:t,numberFormat:r,locale:i});return{layer:t,coordSystem:e,panelRect:s,measureDataLabel:o,formatLabel:Uh({layer:t,numberFormat:r,axes:n,locale:i,absoluteFormatter:c,percentageValueStrategy:a}),formatAbsolute:c}},zh=(t,e)=>{switch(e){case"stack":return Hh(t);case"fill":return Yh(t);case"absoluteGrandTotal":return()=>t.summary.absoluteGrandTotal??null;case"none":return()=>null}},Hh=t=>{const e=x(t.mapping.x);let n=null,r=!1;return s=>{const o=t.summary.stackTotals;if(o===void 0||o.length===0||e===null)return null;if(!r){n=new Map;for(const c of o)n.set(c.xKey,c);r=!0}const i=s[e];if(i==null)return null;const a=n?.get(sr(s,e));return a===void 0?null:a.total}},Yh=t=>{const e=Zt(t);return n=>{const r=Z(n),s=Y(n);if(!D(r)||!D(s))return null;const o=Math.abs(s-r);if(o===0)return null;const i=e(n);return D(i)?i/o:null}},Uh=({layer:t,numberFormat:e,axes:n,locale:r,absoluteFormatter:s,percentageValueStrategy:o})=>{const i=Q(t.data,t.dataLabels.labelSource),a=zh(t,o),c=Kh({layer:t,numberFormat:e,axes:n,locale:r,absoluteFormatter:s}),l=P({valueFormat:{type:"percentage"},locale:r,numberFormat:e}),d=t.dataLabels.format==="percentage"&&qi(t);return u=>{const m=i(u);if(m===null)return"";if(!d||!D(m))return c(m,u);const p=a(u);return p===null||p===0?c(m,u):l(m/p)}},Kh=({layer:t,numberFormat:e,axes:n,locale:r,absoluteFormatter:s})=>{const o=t.dataLabels.labelSource,i=x(o);if(i!==null){if(qi(t))return s;const a=Xh(t,n,e,r,i);if(a!==null)return a}return P({valueFormat:jh(t.data,o),locale:r,numberFormat:e})},qi=t=>{const e=x(t.dataLabels.labelSource);return e===null?!1:e===x(qt(t.position,t.mapping))},Xh=(t,e,n,r,s)=>{const o=x(t.mapping.x);if(o===null||o!==s)return null;const i=e.find(a=>a.scaleAestheticKey==="x");return i===void 0?null:P({valueFormat:i.valueFormat,locale:r,numberFormat:n})},jh=(t,e)=>{const n=ce(e);if(n!==void 0)return Ya(n)?{type:"decimal"}:Ha(n)?{type:"date"}:{type:"text"};const r=x(e);return r===null||!t.hasVariable(r)?{type:"text"}:t.getValueFormat(r)},Zi={bar:{cartesian:yh,polar:$h},line:{cartesian:kh},point:{cartesian:Ch},area:{cartesian:hh}},qh=({layers:t,coordSystem:e,axes:n,numberFormat:r,parsingLocale:s,panelRect:o,measureDataLabel:i,formattingLocale:a})=>{const c=[],l=a??s,d=e.type;for(const u of t){if(!u.dataLabels.showDataLabels&&!u.dataLabels.showStackTotals)continue;const m=u.geom,p=Zi[m]?.[d];if(p===void 0)continue;const f=ji({layer:u,coordSystem:e,axes:n,numberFormat:r,panelRect:o,measureDataLabel:i,formattingLocale:l,percentageValueStrategy:p.getPercentageValueStrategy(u)}),b=p.place(f);for(const y of b)c.push(y)}return{labels:c}};function*Zh({layers:t,coordSystem:e,axes:n,numberFormat:r,panelRect:s,measureDataLabel:o,locale:i}){if(!(e.type!=="cartesian"||s.width<=0||s.height<=0))for(const a of t){if(!a.dataLabels.showDataLabels&&!a.dataLabels.showStackTotals)continue;const c=a.geom,l=Zi[c]?.cartesian;if(l===void 0)continue;const d=ji({layer:a,coordSystem:e,axes:n,numberFormat:r,panelRect:s,measureDataLabel:o,formattingLocale:i,percentageValueStrategy:l.getPercentageValueStrategy(a)});for(const u of l.place(d))yield{x:s.x+u.x-u.width/2,y:s.y+u.y-u.height/2,width:u.width,height:u.height}}}const En={abbreviation:"none",decimals:"auto"},Qh=({locale:t,kind:e,startValue:n,endValue:r,valueFormat:s})=>{if(n===null||r===null)return Ci;switch(e){case"absolute-difference":return P({valueFormat:s,locale:t,numberFormat:En,intlOptions:{signDisplay:"always"}})(r-n);case"relative-difference":{const o=r-n;if(o===0)return"0%";const i=o/n;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":P({valueFormat:{type:"percentage"},locale:t,numberFormat:En,intlOptions:{signDisplay:"always"}})(i)}case"proportion":{if(r-n===0)return"=";const o=r/n;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":`${P({valueFormat:{type:"decimal"},locale:t,numberFormat:En,intlOptions:{maximumFractionDigits:1}})(o)}x`}}},Vn=6,kn=6,_n=15,Cn=5,Dn=15,Qi=(t,e)=>{switch(t){case"small":return{arrowStartGap:Vn,arrowEndGap:kn,offsetFromHigherObservation:_n,arrowheadSize:Cn,curveRadius:Dn,strokeWidth:2,labelLineHeight:12*e,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Vn*1.5,arrowEndGap:kn*1.5,offsetFromHigherObservation:_n*1.25,arrowheadSize:Cn*1.5,curveRadius:Dn*1.25,strokeWidth:3,labelLineHeight:16*e,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Vn*2,arrowEndGap:kn*2,offsetFromHigherObservation:_n*1.75,arrowheadSize:Cn*2.5,curveRadius:Dn*1.5,strokeWidth:5,labelLineHeight:20*e,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Jh=(t,e,n,r)=>{const s=r.offsetFromHigherObservation+r.arrowheadSize+r.arrowEndGap;return t?Math.max(e.x,n.x)+s:Math.min(e.y,n.y)-s},eg=(t,e,n,{arrowStartGap:r,arrowEndGap:s,curveRadius:o})=>{const i={x:t.x,y:t.y-r},a={x:t.x,y:n},c={x:e.x,y:n},l={x:e.x,y:e.y-s},d=e.x>t.x?1:-1;return`
|
|
2
|
+
M ${i.x} ${i.y}
|
|
3
|
+
L ${a.x} ${a.y+o}
|
|
4
|
+
Q ${a.x} ${a.y} ${a.x+d*o} ${a.y}
|
|
5
|
+
L ${c.x-d*o} ${c.y}
|
|
6
|
+
Q ${c.x} ${c.y} ${c.x} ${c.y+o}
|
|
7
|
+
L ${l.x} ${l.y}
|
|
8
|
+
`},tg=(t,e,n,{arrowStartGap:r,arrowEndGap:s,curveRadius:o})=>{const i={x:t.x+r,y:t.y},a={x:n,y:t.y},c={x:n,y:e.y},l={x:e.x+s,y:e.y},d=e.y>t.y?1:-1;return`
|
|
9
|
+
M ${i.x} ${i.y}
|
|
10
|
+
L ${a.x-o} ${a.y}
|
|
11
|
+
Q ${a.x} ${a.y} ${a.x} ${a.y+d*o}
|
|
12
|
+
L ${c.x} ${c.y-d*o}
|
|
13
|
+
Q ${c.x} ${c.y} ${c.x-o} ${c.y}
|
|
14
|
+
L ${l.x} ${l.y}
|
|
15
|
+
`},ng=(t,e,{arrowEndGap:n,arrowheadSize:r})=>t?`
|
|
16
|
+
M ${e.x+n+r} ${e.y-r}
|
|
17
|
+
L ${e.x+n} ${e.y}
|
|
18
|
+
L ${e.x+n+r} ${e.y+r}
|
|
19
|
+
`:`
|
|
20
|
+
M ${e.x-r} ${e.y-n-r}
|
|
21
|
+
L ${e.x} ${e.y-n}
|
|
22
|
+
L ${e.x+r} ${e.y-n-r}
|
|
23
|
+
`,rg=(t,e,n,r,s,o=.5)=>{if(t){const a=Math.min(e.y,n.y);return{x:r,y:a+o*s}}return{x:Math.min(e.x,n.x)+o*s,y:r}},sg=(t,e,n)=>Math.abs(t?e.y-n.y:e.x-n.x),Ji=({arrow:t,mainAxis:e,panelWidth:n,panelHeight:r,textScale:s,locale:o})=>{const i=e==="y",a={x:t.start.x*n,y:(1-t.start.y)*r},c={x:t.end.x*n,y:(1-t.end.y)*r},l=Qi(t.size,s),d=Jh(i,a,c,l),u=(i?tg:eg)(a,c,d,l),m=ng(i,c,l),p=sg(i,a,c),f=rg(i,a,c,d,p,t.labelCrossPosition),b=Qh({locale:o,kind:t.label,startValue:t.start.measurementValue,endValue:t.end.measurementValue,valueFormat:t.start.valueFormat});return{id:t.id,linePath:u,arrowheadPath:m,labelPosition:f,labelText:b,color:t.color,strokeWidth:l.strokeWidth,labelLineHeight:l.labelLineHeight,labelPaddingX:l.labelPaddingX,labelPaddingY:l.labelPaddingY,labelStrokeWidth:l.labelStrokeWidth,labelFontWeight:l.labelFontWeight}};function*og({annotations:t,mainAxis:e,panelRect:n,textScale:r,locale:s,measureLabel:o}){for(const i of t.differenceArrows){if(!Rs(i.start.x,i.start.y)||!Rs(i.end.x,i.end.y))continue;const a=Ji({arrow:i,mainAxis:e,panelWidth:n.width,panelHeight:n.height,textScale:r,locale:s}),l=o(a.labelText,i.size).width+2*a.labelPaddingX,d=a.labelLineHeight+2*a.labelPaddingY;yield{x:n.x+a.labelPosition.x-l/2,y:n.y+a.labelPosition.y-d/2,width:l,height:d}}}const Rs=(t,e)=>t>=0&&t<=1&&e>=0&&e<=1,ig=t=>{const e=t.padding??0,n=Ps(t.rows,e),r=Ps(t.cols,e);return{rows:n.tracks,cols:r.tracks,placements:ug(t.placements,n.nameToIndex,r.nameToIndex),width:t.containerSize.width,height:t.containerSize.height}},ag=t=>{const e=Fs(t.rows,t.height),n=Fs(t.cols,t.width),r=Ns(e),s=Ns(n),o=new Map;for(const i of t.placements){const a=i.rowSpan??1,c=i.colSpan??1,l=s[i.col]??0,d=r[i.row]??0,u=Os(n,i.col,c),m=Os(e,i.row,a);o.set(i.name,{x:l,y:d,width:Math.max(0,u),height:Math.max(0,m)})}return o},Ps=(t,e)=>{const n=[],r=new Map;e>0&&n.push({type:"fixed",pixels:e});let s=0;for(let o=0;o<t.length;o++){const i=t[o];if(!i)continue;Wn(i)&&s>0&&(n.push({type:"fixed",pixels:s}),s=0),r.set(i.name,n.length),n.push(cg(i));const a=lg(t,o);if(Wn(i)&&a){const c=i.gaps?.after??0,l=a.gaps?.before??0;c>=l?c>0&&n.push({type:"fixed",pixels:c}):s=l}}return e>0&&n.push({type:"fixed",pixels:e}),{tracks:n,nameToIndex:r}},cg=t=>typeof t.size=="number"?{type:"fixed",pixels:t.size}:{type:"flex",weight:t.size.flex},Wn=t=>typeof t.size=="number"?t.size>0:t.size.flex>0,lg=(t,e)=>{for(let n=e+1;n<t.length;n++){const r=t[n];if(r&&Wn(r))return r}},ug=(t,e,n)=>{const r=[];for(const s of t){const o=e.get(s.row),i=n.get(s.col);if(o===void 0||i===void 0)continue;const a=s.rowEnd!==void 0?e.get(s.rowEnd):o,c=s.colEnd!==void 0?n.get(s.colEnd):i;a===void 0||c===void 0||r.push({name:s.name,row:o,col:i,rowSpan:Math.max(1,a-o+1),colSpan:Math.max(1,c-i+1)})}return r},Fs=(t,e)=>{let n=0,r=0;for(const o of t)o.type==="fixed"?n+=o.pixels:r+=o.weight;const s=Math.max(0,e-n);return t.map(o=>o.type==="fixed"?o.pixels:r===0?0:o.weight/r*s)},Ns=t=>{const e=new Array(t.length);let n=0;for(let r=0;r<t.length;r++)e[r]=n,n+=t[r]??0;return e},Os=(t,e,n)=>{let r=0;const s=Math.min(e+n,t.length);for(let o=e;o<s;o++)r+=t[o]??0;return r},wr=24,me={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:8,before:0},topAxisLabel:{after:8,before:0},topAxis:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},Rn={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},Nt={top:0,right:0,bottom:0,left:0},ea={outer:Nt,inner:Nt},dg=(t,e,n,r=ea,s=wr)=>{const i=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return ig({rows:[{name:"header",size:e.headerSize.height,gaps:me.header},{name:"topLegend",size:n.legends.top,gaps:me.topLegend},{name:"headline",size:n.headline,gaps:me.headline},{name:"topAxisLabel",size:i,gaps:me.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:me.topAxis},{name:"topPanelOuter",size:r.outer.top},{name:"topPanelInner",size:r.inner.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:r.inner.bottom},{name:"bottomPanelOuter",size:r.outer.bottom},{name:"bottomAxis",size:n.axes.bottom,gaps:me.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:me.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:me.bottomLegend},{name:"footer",size:e.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:Rn.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:Rn.leftAxis},{name:"leftPanelOuter",size:r.outer.left},{name:"leftPanelInner",size:r.inner.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:r.inner.right},{name:"rightPanelOuter",size:r.outer.right},{name:"rightAxis",size:n.axes.right,gaps:Rn.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...mg(n.axes),...pg(n.axesLabels,n.axes),...fg(n.legends)],containerSize:t,padding:s})},mg=t=>{const e=[];return t.top>0&&e.push({name:"topAxis",row:"topAxis",col:"panel"}),t.bottom>0&&e.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),t.left>0&&e.push({name:"leftAxis",row:"panel",col:"leftAxis"}),t.right>0&&e.push({name:"rightAxis",row:"panel",col:"rightAxis"}),e},pg=(t,e)=>{const n=[];return t.top>0||e.top>0?(t.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),t.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),t.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(t.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),t.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),t.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},fg=t=>{const e=[];return t.top>0&&e.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),t.bottom>0&&e.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),t.left>0&&e.push({name:"leftLegend",row:"panel",col:"leftLegend"}),t.right>0&&e.push({name:"rightLegend",row:"panel",col:"rightLegend"}),e},hg=8;class gg{constructor(e){this.outer={...Nt},this.inner={...Nt},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,n){const r=this.computeEdgeOverflow(e,hg),s=this.computeEdgeOverflow(e,0);this.growEdge("left",n.x,r.left,s.left),this.growEdge("right",n.x,r.right,s.right),this.growEdge("top",n.y,r.top,s.top),this.growEdge("bottom",n.y,r.bottom,s.bottom)}computeEdgeOverflow(e,n){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+n-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-n)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-n)),0),left:Math.max(Math.ceil(r.x+n-e.x),0)}}growEdge(e,n,r,s){n!=="none"&&(n==="outside"?s>0&&(this.outer[e]=Math.max(this.outer[e],s)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}}const yg=["top","right","bottom","left"],Pn=(t,e)=>{const n={};for(const r of yg){const s=t.get(`${r}${e}`);s&&(n[r]=s)}return n};function Bs(t,e){return t.top===e.top&&t.right===e.right&&t.bottom===e.bottom&&t.left===e.left}const zn=["large","medium","small"],bg=({size:t,availableWidth:e,measureStripWidth:n})=>{if(t!=="auto")return t;for(const r of zn)if(n(r)<=e)return r;return"small"},xg=({size:t,availableWidth:e,measureStripWidth:n})=>{const r=t==="auto"?0:zn.indexOf(t);for(const s of zn.slice(r))if(n(s)<=e)return s;return null},vg=({itemWidths:t,gap:e,availableWidth:n})=>{let r=0,s=0;for(const o of t){const i=s===0?o:r+e+o;if(i>n)break;r=i,s+=1}return s},Sg=({headline:t,containerSize:e,measurer:n})=>{if(ta(t))return 0;const r=na(t,e.width,n);return n.measureHeadline(t.formatted,r).height},Ag=({headline:t,layout:e,containerSize:n,measurer:r,itemGap:s})=>{if(ta(t)){const a=wg(e.panel,t.innerRadius),c=xg({size:t.size,availableWidth:a.width,measureStripWidth:ra(t,r)});return c===null?null:{rect:a,resolvedSize:c,visibleItemCount:1}}const o=na(t,n.width,r);if(t.formatted.kind!=="perGroup")return{rect:e.headline,resolvedSize:o,visibleItemCount:1};const i=vg({itemWidths:r.measureHeadlineItemWidths(t.formatted,o),gap:s,availableWidth:e.headline.width});return i===0?null:{rect:e.headline,resolvedSize:o,visibleItemCount:i}},ta=t=>t.formatted.kind==="grandTotal"&&t.position==="center"&&t.innerRadius>0,wg=(t,e)=>{const n=Math.min(t.width,t.height)/2,r=e*n*Math.SQRT2,s=t.x+t.width/2,o=t.y+t.height/2;return{x:s-r/2,y:o-r/2,width:r,height:r}},na=(t,e,n)=>bg({size:t.size,availableWidth:e,measureStripWidth:ra(t,n)}),ra=(t,e)=>n=>e.measureHeadline(t.formatted,n).width,Be={x:0,y:0,width:0,height:0},Tg="0000",Mg=3;class Lg{constructor(e){this.measurer=e}compile(e){return $t({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:ea,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:e.padding??wr}).pipe(({axes:n,numberFormat:r,locale:s})=>({axisBundles:n.map(o=>({axis:o,resolveFormatter:Ig(o,s,r),formatted:this.seedAxis(o)}))})).pipe(({axisBundles:n,formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})=>({layout:this.resolveLayout({axes:n.map(l=>l.formatted),formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})})).pipe(({axisBundles:n,layout:r})=>({axisBundles:n.map(s=>Gs(s.axis.position)?{...s,formatted:this.finalizeAxis(s.axis,s.resolveFormatter,r.panelFrame)}:s)})).pipe(({axisBundles:n,formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})=>({layout:this.resolveLayout({axes:n.map(l=>l.formatted),formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})})).pipe(({axisBundles:n,layout:r})=>({formattedAxes:n.map(s=>Gs(s.axis.position)?s.formatted:this.finalizeAxis(s.axis,s.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:n,formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})=>({layout:this.resolveLayout({axes:n,formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:i,headline:a,padding:c})})).pipe(({formattedAxes:n,formattedLegends:r,containerSize:s,externalMeasurements:o,layout:i,panelOverflow:a,headline:c,locale:l,padding:d})=>({formattedAxes:n,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:n,formattedLegends:r,containerSize:s,externalMeasurements:o,panelOverflow:a,headline:c,locale:l,padding:d})})).pipe(({formattedAxes:n,layout:r})=>({formattedAxes:n,layout:this.applyPolarPanelInset(e,n,r)})).result()}measurePanelOverflow(e,n,r,s){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return s;const o=new gg(n);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const a of og({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:n,textScale:e.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel}))o.add(a,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const a of Zh({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:n,measureDataLabel:this.measurer.measureDataLabel,locale:r}))o.add(a,e.overflowStrategy.dataLabels);const i=o.resolve();return Bs(i.inner,s.inner)&&Bs(i.outer,s.outer)?s:i}settlePanelOverflow({input:e,layout:n,formattedAxes:r,formattedLegends:s,containerSize:o,externalMeasurements:i,panelOverflow:a,headline:c,locale:l,padding:d}){let u=n,m=a;for(let p=0;p<Mg;p++){const f=this.measurePanelOverflow(e,u.panelFrame,l,m);if(f===m)break;m=f,u=this.resolveLayout({axes:r,formattedLegends:s,containerSize:o,externalMeasurements:i,panelOverflow:f,headline:c,padding:d})}return u}applyPolarPanelInset(e,n,r){if(e.coordSystem?.type!=="polar")return r;const s=this.measurePolarRimInset(n),{panel:o}=r,i=o.width-s.horizontal*2,a=o.height-s.vertical*2;return i<=0||a<=0?$s(r,o,0,0):$s(r,o,s.horizontal,s.vertical)}measurePolarRimInset(e){const n=e.find(o=>o.geometry==="circular");if(!n)return{horizontal:0,vertical:0};let r=0,s=0;for(const o of n.ticks){const i=this.measurer.measureTickLabel(o.formattedLabel);r=Math.max(r,i.width),s=Math.max(s,i.height)}return r===0?{horizontal:0,vertical:0}:{horizontal:r+On,vertical:s+On}}seedAxis(e){const{tickCandidates:n,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:Tg}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,n,r){const o=e.position==="top"||e.position==="bottom"?r.width:r.height,i=ch({axis:e,availableSpacePx:o,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:a,...c}=e,l={...c,ticks:i,labelRotation:0,labelMaxWidthPx:null};if(e.geometry!=="linear")return l;if(e.scaleType==="discrete"&&e.bandwidth!==void 0){const d=e.bandwidth*o;return sh({formattedAxis:l,bandwidthPx:d,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:e,formattedLegends:n,containerSize:r,externalMeasurements:s,panelOverflow:o,headline:i,padding:a}){const c=this.measureGuides(e,n,i,r),l=dg(r,s,c,o,a),d=ag(l);return{header:d.get("header")??Be,headline:d.get("headline")??Be,footer:d.get("footer")??Be,plot:d.get("plot")??Be,panelFrame:d.get("panelFrame")??Be,panel:d.get("panel")??Be,axes:Pn(d,"Axis"),axisLabels:Pn(d,"AxisLabel"),legends:Pn(d,"Legend")}}measureGuides(e,n,r,s){const o={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const c of e)c.isVisible&&c.geometry==="linear"&&(o[c.position]=this.measurer.measureAxis(c),c.label!==null&&(i[c.position]=this.measurer.measureAxisLabel(c)));const a={top:0,right:0,bottom:0,left:0};for(const c of n)a[c.position]=this.measurer.measureLegend(c);return{axes:o,axesLabels:i,legends:a,headline:this.measureHeadlineBand(r,s)}}measureHeadlineBand(e,n){return e===void 0?0:Sg({headline:e,containerSize:n,measurer:this.measurer})}}const Gs=t=>t==="left"||t==="right",$s=(t,e,n,r)=>{const s=e.width-n*2,o=e.height-r*2,i=Math.min(s,o);return{...t,panel:{x:e.x+n+(s-i)/2,y:e.y+r+(o-i)/2,width:i,height:i}}},Ig=(t,e,n)=>{const r=t.tickCandidates.flatMap(o=>o.ticks.map(i=>i.value)),s=new WeakMap;return o=>{const i=s.get(o);if(i)return i;const a=Sr({valueFormat:o.valueFormat??t.valueFormat,locale:e,numberFormat:n,tickValues:r});return s.set(o,a),a}};function Eg(t,e){const n=new Map;if(!e||e.kind!=="visual"||e.domain.length<=1)return n;for(const r of t){if(r.geom!=="rule"||r.stat.type!=="mean")continue;const s=r.transforms.find(u=>u.transformType==="filter"&&u.options.operator==="eq"),o=x(r.mapping.y);let i,a,c;if(s?.transformType==="filter"&&typeof s.options.value=="string")i="color",a=s.options.variableName,c=s.options.value;else if(o!==null)i="y",a=o,c=o;else continue;const l=Vg(t,i,a);if(l===null)continue;const d=e.map(c);zt(d)&&n.set(r.id,{geom:l.geom,color:d})}return n}function Vg(t,e,n){let r=null;for(const s of t)if(s.geom!=="rule"&&(r===null&&(r=s),x(s.mapping[e])===n))return s;return r}const sa=(t,e)=>({x:t.x/e.width,y:1-t.y/e.height}),kg=(t,e)=>{for(const n of e){const{rect:r}=n;if(t.x>=r.x&&t.x<=r.x+r.width&&t.y>=r.y&&t.y<=r.y+r.height)return n}return null},_g=(t,e)=>t.filter(n=>n.inView).map(n=>({rect:n.miniRect,cursor:sa(n.anchorPx,e),markerPx:n.anchorPx,placement:n.placement})),nt=9,rt=8,oa=2,ia="top",aa=t=>typeof t=="string"?t:ca(t),ca=t=>t.text!==void 0?t.text:t.content?t.content.map(ca).join(""):"",Ws={top:"bottom",bottom:"top",right:"left",left:"right"};function Cg(t,e,n){return n.type==="polar"?Rg(t,e):n.mainAxis==="y"?["right","left","top","bottom"]:["top","right","left","bottom"]}function Hn(t,e,n){const{width:r,height:s}=n;switch(e){case"top":return{x:t.x-r/2,y:t.y-nt-s,width:r,height:s};case"bottom":return{x:t.x-r/2,y:t.y+nt,width:r,height:s};case"right":return{x:t.x+nt,y:t.y-s/2,width:r,height:s};case"left":return{x:t.x-nt-r,y:t.y-s/2,width:r,height:s}}}function zs(t,e){return t.x>=0&&t.y>=0&&t.x+t.width<=e.width&&t.y+t.height<=e.height}function Dg(t,e,n=oa){return t.x<e.x+e.width-n&&t.x+t.width>e.x+n&&t.y<e.y+e.height-n&&t.y+t.height>e.y+n}function Rg(t,e){const n=t.x-e.width/2,r=t.y-e.height/2,s=n>=0?"right":"left",o=r>=0?"bottom":"top",[i,a]=Math.abs(n)>=Math.abs(r)?[s,o]:[o,s];return[i,a,Ws[a],Ws[i]]}function Pg(t){const{pinnedNumbers:e,comments:n,panelRect:r,coordSystem:s,measurer:o,formatPinnedNumber:i}=t,a=[...e.map(d=>{const{id:u,at:m}=d;return Hs(u,"pinned-number",m,i(d),o,r,s)}),...n.map(({id:d,at:u,content:m})=>Hs(d,"comment",u,aa(m),o,r,s))];a.sort((d,u)=>d.anchorPx.x-u.anchorPx.x||d.anchorPx.y-u.anchorPx.y);const c=[],l=[];for(const d of a){if(!d.inView){c.push(Ys(d,ia));continue}const u=Bg(d,r,s,l),m=Ys(d,u);c.push(m),l.push(m.miniRect)}return c}function Hs(t,e,n,r,s,o,i){const a=i.type==="polar"?Ng(n,o):Fg(n,o);return{id:t,kind:e,anchor:n,anchorPx:a,miniSize:s(e,r),inView:Og(a,o)}}function Fg(t,e){return{x:t.x*e.width,y:(1-t.y)*e.height}}function Ng(t,e){const n=Math.min(e.width,e.height),r=(e.width-n)/2,s=(e.height-n)/2;return{x:r+t.x*n,y:s+t.y*n}}function Og(t,e){return t.x>=-rt&&t.y>=-rt&&t.x<=e.width+rt&&t.y<=e.height+rt}function Bg(t,e,n,r){const s=Cg(t.anchorPx,e,n);for(const o of s){const i=Hn(t.anchorPx,o,t.miniSize);if(zs(i,e)&&!r.some(a=>Dg(i,a)))return o}for(const o of s)if(zs(Hn(t.anchorPx,o,t.miniSize),e))return o;return ia}function Ys(t,e){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:e,miniRect:Hn(t.anchorPx,e,t.miniSize),inView:t.inView}}const Ge=["top","right","bottom","left"],Us={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},Gg={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},$g={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},Wg=(t,e,n)=>{const r=Math.max(0,Math.min(n,e.width/2,e.height/2)),s=a=>{const[c,l]=$g[a];return r>0&&t[c].isVisible&&t[l].isVisible},o=zg(e,r),i=Hg(e,r,s);return Yg(t).map(a=>({lineStyle:t[a.firstEdge].lineStyle,lineWidth:t[a.firstEdge].lineWidth,segments:Ug(a,o,i,s)}))},zg=(t,e)=>{const{x:n,y:r,width:s,height:o}=t;return{topLeft:{cx:n+e,cy:r+e,startAngle:Math.PI,endAngle:Math.PI*1.5,radius:e},topRight:{cx:n+s-e,cy:r+e,startAngle:Math.PI*1.5,endAngle:Math.PI*2,radius:e},bottomRight:{cx:n+s-e,cy:r+o-e,startAngle:0,endAngle:Math.PI*.5,radius:e},bottomLeft:{cx:n+e,cy:r+o-e,startAngle:Math.PI*.5,endAngle:Math.PI,radius:e}}},Hg=(t,e,n)=>{const{x:r,y:s,width:o,height:i}=t,a=c=>n(c)?e:0;return{top:{start:{x:r+a("topLeft"),y:s},end:{x:r+o-a("topRight"),y:s}},right:{start:{x:r+o,y:s+a("topRight")},end:{x:r+o,y:s+i-a("bottomRight")}},bottom:{start:{x:r+o-a("bottomRight"),y:s+i},end:{x:r+a("bottomLeft"),y:s+i}},left:{start:{x:r,y:s+i-a("bottomLeft")},end:{x:r,y:s+a("topLeft")}}}},Yg=t=>{const e=i=>t[i].isVisible,n=(i,a)=>{const c=(Ge.indexOf(i)+a+Ge.length)%Ge.length;return Ge[c]},r=i=>{const a=n(i,-1);return!e(a)||t[a].lineStyle!==t[i].lineStyle||t[a].lineWidth!==t[i].lineWidth},s=Ge.filter(e);if(s.length===0)return[];const o=s.filter(r);return o.length===0?[{firstEdge:"top",edges:[...Ge],isClosed:!0}]:o.map(i=>{const a=[i];for(let c=n(i,1);e(c)&&!r(c);c=n(c,1))a.push(c);return{firstEdge:i,edges:a,isClosed:!1}})},Ug=(t,e,n,r)=>{const s=(u,m,p)=>({type:"arc",cx:u.cx,cy:u.cy,radius:u.radius,startAngle:m,endAngle:p}),o=u=>(u.startAngle+u.endAngle)/2,i=[],a=t.firstEdge,c=t.edges[t.edges.length-1],l=Us[a];if(!t.isClosed&&r(l)){const u=e[l],m=o(u),p=Kg(u,m);i.push({type:"move",x:p.x,y:p.y}),i.push(s(u,m,u.endAngle))}else i.push({type:"move",x:n[a].start.x,y:n[a].start.y});i.push({type:"line",x:n[a].end.x,y:n[a].end.y});for(const u of t.edges.slice(1)){const m=Us[u];if(r(m)){const p=e[m];i.push(s(p,p.startAngle,p.endAngle))}i.push({type:"line",x:n[u].end.x,y:n[u].end.y})}const d=Gg[c];if(t.isClosed){if(r(d)){const u=e[d];i.push(s(u,u.startAngle,u.endAngle))}i.push({type:"close"})}else if(r(d)){const u=e[d];i.push(s(u,u.startAngle,o(u)))}return i},Kg=(t,e)=>({x:t.cx+t.radius*Math.cos(e),y:t.cy+t.radius*Math.sin(e)});function ze(t,e){return t==="x"?e.x:e.y}function tn(t,e){return t==="x"?e.y:e.x}function Xg(t,e){return{main:ze(t,e),cross:tn(t,e)}}function jg(t){return t.type==="cartesian"}function qg(t){return t}function ye(t){return 1-t}const Me=t=>`${Number.parseFloat((t*100).toFixed(4))}%`,la=6,ua=2,Zg=4,Qg=2,Ks=11,Jg=(t,e)=>{switch(t){case"dataLabel":return{fontSize:Ks*e,fontWeight:500,paddingX:la,paddingY:ua};case"stackTotal":return{fontSize:Ks*e,fontWeight:600,paddingX:Zg,paddingY:Qg}}},ey=100,ty=({items:t,containerHeight:e,labelHeight:n})=>{const r=t.map(l=>{const d=(1-l.normalizedY)*e;return{anchorY:d,y:d,payload:l.payload}}).sort((l,d)=>l.y-d.y),s=n/2;let o=!1,i=!0,a=0;for(;i;){i=!1,a++;for(let l=0;l<r.length-1;l++){const d=r[l],u=r[l+1];if(!d||!u)continue;const m=d.y+s,p=u.y-s;if(m>p){i=!0,o=!0;const b=(m-p)/2+1;d.y-=b,u.y+=b,d.y<0&&(d.y=0),u.y>e&&(u.y=e)}}if(a>ey)break}return{placements:r.filter(l=>l.y>=0&&l.y<=e).map(l=>({y:l.y,anchorY:l.anchorY,payload:l.payload})),hasOverlap:o}};function ny({numberFormat:t,locale:e}){const n=new Map;return r=>{let s=n.get(r.valueFormat);return s??=P({valueFormat:r.valueFormat,locale:e,numberFormat:t}),n.set(r.valueFormat,s),s(r.measurementValue)}}const ry=({headline:t,show:e,numberFormat:n,parsingLocale:r,formattingLocale:s,t:o})=>{if(t===null)return null;const i=s??r;return t.kind==="grandTotal"?sy(t,i,n):oy(t,e,i,n,o)},sy=(t,e,n)=>({kind:"grandTotal",value:P({valueFormat:t.valueFormat,locale:e,numberFormat:n})(t.value)}),oy=(t,e,n,r,s)=>{const o=P({valueFormat:{type:"percentage"},locale:n,numberFormat:r}),i=t.items.length>1;return{kind:"perGroup",items:t.items.map(c=>{const l=P({valueFormat:c.valueFormat,locale:n,numberFormat:r}),d=P({valueFormat:c.groupLabelFormat,locale:n,numberFormat:r}),u=Sr({valueFormat:c.mainValueFormat,locale:n,numberFormat:r,tickValues:[]}),m=c.label??d(c.value);return{swatch:c.swatch,label:ly(e,i,m,s),value:c.aggregate===null?null:l(c.aggregate),observationLabel:cy(c.observationLabel,u),comparison:iy(c.comparison,u,o,s)}})}},iy=(t,e,n,r)=>t===null?null:{direction:ay(t.variation),percentage:n(Math.abs(t.variation)),reference:r("graph.headlineMetrics.comparisonReference",{value:e(t.against)})},ay=t=>t>0?"up":t<0?"down":"flat",cy=(t,e)=>t===null?null:t.kind==="point"?e(t.value):`${e(t.from)} – ${e(t.to)}`,ly=(t,e,n,r)=>{switch(t){case"total":return r("graph.headlineMetrics.total",{value:n});case"average":return e?r("graph.headlineMetrics.averageShort",{value:n}):r("graph.headlineMetrics.averageLong",{value:n});case"current":case"conversion":case"none":return n}},uy=({legends:t,numberFormat:e,parsingLocale:n,formattingLocale:r})=>{const s=r??n;return t.map(o=>dy(o,s,e))},dy=(t,e,n)=>({...t,items:t.items.map(r=>{const s=P({valueFormat:r.valueFormat,locale:e,numberFormat:n});return{...r,formattedLabel:r.label??s(r.value)}})});function Tr(t,e){return t.axes.find(n=>n.scaleAestheticKey===e)??null}function my(t,e){return t.legends.find(n=>n.aesthetics.includes(e))??null}const py=({guides:t,numberFormat:e,layer:n,locale:r})=>{const s=n.data.getFirst();if(!s)return null;const o=n.mapping.y!==void 0,a=(o?Jo:jt)(n.data,n.mapping)(s);if(a===null)return null;const c=o?je(n.yScaleType):"x",l=Tr(t,c)?.valueFormat??{type:"decimal"};return P({valueFormat:l,locale:r,numberFormat:e})(a)},da=12,ma=4,pa=4,fa=12,ha=4,fy=t=>{const{value:e,observationLabel:n,comparison:r,swatch:s,label:o}=t;return[{role:"valueRow",gap:pa,segments:Fn([At("value","value",e??"–"),At("observation","label",n)])},{role:"trendRow",gap:ha,ariaLabel:r===null?void 0:by(r),segments:Fn([gy(r),yy(r),At("trendReference","label",r?.reference??null)])},{role:"groupRow",gap:ma,segments:Fn([hy(s),At("label","label",o)])}].filter(a=>a.segments.length>0)},At=(t,e,n)=>n===null?null:{kind:"text",textRole:t,fontRole:e,text:n},hy=t=>t===null?null:{kind:"swatch",swatch:t,size:da},gy=t=>t===null?null:{kind:"trendArrow",direction:t.direction,size:fa},yy=t=>t===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:t.percentage,trendDirection:t.direction},by=t=>{switch(t.direction){case"up":return`Increased ${t.percentage} ${t.reference}`;case"down":return`Decreased ${t.percentage} ${t.reference}`;case"flat":return`No change ${t.reference}`}},Fn=t=>t.filter(e=>e!==null),xy=800,Xs=400,vy={thin:{strokeWidth:{minValue:1.5,targetValue:2},arrowheadLength:{minValue:7,targetValue:8}},medium:{strokeWidth:{minValue:3,targetValue:4},arrowheadLength:{minValue:14,targetValue:16}},thick:{strokeWidth:{minValue:6,targetValue:8},arrowheadLength:{minValue:28,targetValue:32}}},Sy=t=>Math.max(1,(t-Xs)/(xy-Xs)+1),Ay=(t,e)=>{const n=Sy(e),r=vy[t];return{strokeWidth:Math.min(r.strokeWidth.targetValue,r.strokeWidth.minValue*n),arrowheadLength:Math.min(r.arrowheadLength.targetValue,r.arrowheadLength.minValue*n)}},wt=Math.PI/4,Yn=1.5,wy=({startX:t,startY:e,endX:n,endY:r})=>`M ${t} ${e} L ${n} ${r}`,js=(t,e,n)=>{if(n<=0)return"";const{startX:r,startY:s,endX:o,endY:i}=e,a=t==="start"?r:o,c=t==="start"?s:i,l=t==="start"?Math.atan2(s-i,r-o):Math.atan2(i-s,o-r),d=a-n*Math.cos(l-wt),u=c-n*Math.sin(l-wt),m=a-n*Math.cos(l+wt),p=c-n*Math.sin(l+wt);return`M ${a} ${c} L ${d} ${u} M ${a} ${c} L ${m} ${p}`},Ty=(t,e)=>t==="solid"?null:`${e*Yn} ${e*Yn*2}`,My=(t,e)=>e?t*Yn:0,Ly=64,Iy=({arrow:t,panelWidth:e,panelHeight:n})=>{const r={startX:t.start.x*e,startY:(1-t.start.y)*n,endX:t.end.x*e,endY:(1-t.end.y)*n};if(r.startX===r.endX&&r.startY===r.endY)return null;const{strokeWidth:s,arrowheadLength:o}=Ay(t.thickness,e),i=Math.hypot(r.endX-r.startX,r.endY-r.startY),a=Ey(o,i),c=t.startArrowheadStyle==="line-arrow",l=t.endArrowheadStyle==="line-arrow",u=c||l?a*Math.sin(Math.PI/4):0;return{id:t.id,linePath:wy(r),startArrowheadPath:c?js("start",r,a):"",endArrowheadPath:l?js("end",r,a):"",color:t.color,strokeWidth:s,dashArray:Ty(t.lineStyle,s),hasStickerStyle:t.hasStickerStyle,startX:r.startX,startY:r.startY,endX:r.endX,endY:r.endY,dashOffset:My(s,c),arrowheadExtent:u}},Ey=(t,e)=>Math.min(t,e*t/Ly),ga=2,nn=t=>t==="catmull-rom"?Ee.curveCatmullRom:Ee.curveLinear,Vy=t=>{switch(t){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},ky=(t,e)=>e.lineWidth!=="auto"?e.lineWidth:_o(t)??ga,_y=(t,e)=>{const n=nn(e.interpolate),r=Ee.area().curve(n),s=Ee.line().curve(n);if(t.mainAxis==="y"){const o=c=>ye(C(c)??0),i=c=>le(c)??0,a=c=>oe(c)??W(c)??0;r.y(o).x0(i).x1(a),s.y(o).x(a)}else{const o=c=>W(c)??0,i=c=>ye(Z(c)??0),a=c=>ye(Y(c)??C(c)??0);r.x(o).y0(i).y1(a),s.x(o).y(a)}if(e.missingValues==="gap"){const o=i=>W(i)!==null&&C(i)!==null;r.defined(o),s.defined(o)}return{lineGenerator:s,areaGenerator:r}},Cy=(t,e)=>e!=="connect"?t:t.filter(n=>W(n)!==null&&C(n)!==null),Dy=(t,e)=>{const n=le(e),r=oe(e),s=Z(e),o=Y(e)??C(e);if(n===null||r===null||s===null||o===null)return null;if(t==="x"){let c=1-o,l=o-s;return l<0&&(c+=l,l=-l),{x:n,y:c,width:r-n,height:l}}let i=n,a=r-n;return a<0&&(i+=a,a=-a),{x:i,y:1-o,width:a,height:o-s}},Ry=t=>{const e=Ee.line().x(n=>W(n)??0).y(n=>ye(C(n)??0)).curve(nn(t.interpolate));return t.missingValues==="gap"&&e.defined(ya),e},Py=t=>{const e=Ee.area().x(n=>W(n)??0).y0(()=>1).y1(n=>ye(C(n)??0)).curve(nn(t.interpolate));return t.missingValues==="gap"&&e.defined(ya),e},Fy=(t,e)=>e!=="connect"?t:t.filter(n=>W(n)!==null&&C(n)!==null),ya=t=>W(t)!==null&&C(t)!==null,Ny=Ee.arc(),Oy=t=>Ny(t),By=(t,e,n)=>{const r=jt(t,e);return s=>{const o=Ue(s)??"default",i=r(s);return`${n}-${o}${i!==null&&i!==""?`-${i}`:""}`}},Gy=()=>(t,e)=>Yt(t)??`default-${e}`;function Mr(t,e,n){return Math.hypot(t*n,e)}function Ot(t,e,n){return t<e?e-t:t>n?t-n:0}function Ae(t,e,{shortCircuitOnZero:n=!1}={}){let r=t[0],s=e(r);if(n&&s===0)return r;for(let o=1;o<t.length;o+=1){const i=t[o];if(i===void 0)continue;const a=e(i);if(n&&a===0)return i;a<s&&(r=i,s=a)}return r}function $y(t,e,n,r){if(t.points.length===0)return null;const s=t.delaunay;if(!s)return null;const o=s.find(e.x*n,e.y,r??void 0),i=t.points[o];return i?{hit:{anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:t,distance:Mr(i.x-e.x,i.y-e.y,n)}:null}function Wy(t,e){if(t.points.length===0||!t.delaunay||t.delaunayAspectRatio===null)return null;const n=t.delaunay.find(e.x*t.delaunayAspectRatio,e.y);return t.points[n]??null}function ba(t,e){return Lr(t.buckets,e,n=>n.main)}function zy(t,e){return Lr(t.bands,e,n=>n.bandCenter)}function xa(t,e){return Lr(t.columns,e,n=>n.mainMid)}function Lr(t,e,n){if(t.length===0)return null;let r=0,s=t.length;for(;r<s;){const a=r+s>>>1,c=t[a];c&&n(c)<e?r=a+1:s=a}const o=t[r-1],i=t[r];return o?i&&Math.abs(n(i)-e)<Math.abs(n(o)-e)?i:o:i??null}function Hy(t,e){return{group:Yy(t),related:jy(t,e)}}function Yy(t){switch(t.kind){case"buckets":{const e=t.match.index;return j(e.position)?Uy(e.layerId,t.match.bucket,t.match.hit.pointIndex):[]}case"banded":{const{index:e,column:n,hit:r}=t.match;return j(e.position)?Ky(e.layerId,n,r.pointIndex):Xy(e.bands,e.layerId,n,r.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function Uy(t,e,n){const r=[];for(const s of e.entries)s.pointIndex!==n&&r.push({anchored:!0,layerId:t,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation});return r}function Ky(t,e,n){const r=[];for(const s of e.rects)s.pointIndex!==n&&r.push(Ir(t,s));return r}function Xy(t,e,n,r){const s=t.find(i=>i.columns.includes(n));if(!s)return[];const o=[];for(const i of s.columns)for(const a of i.rects)a.pointIndex!==r&&o.push(Ir(e,a));return o}function jy(t,e){const n=new Map;if(t.kind==="render-hit-test"||t.kind==="enclosure")return n;const r=t.match.index,s=r.projection==="polar";for(const o of e){if(o.layerId!==r.layerId){s||Zy(n,o,t.match.hit);continue}t.kind==="buckets"&&(j(o.position)||o.kind==="buckets"&&qy(n,o.layerId,t.match.bucket,t.match.hit.pointIndex))}return n}function qy(t,e,n,r){for(const s of n.entries){if(s.pointIndex===r)continue;Et(t,e).push({anchored:!0,layerId:e,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation})}}function Zy(t,e,n){switch(e.kind){case"buckets":{const r=ba(e,ze(e.mainAxis,n));if(!r)return;const s=Et(t,e.layerId);for(const o of r.entries)s.push({anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation});return}case"banded":{const r=zy(e,ze(e.mainAxis,n));if(!r)return;const s=Et(t,e.layerId);for(const o of r.columns)for(const i of o.rects)s.push(Ir(e.layerId,i));return}case"points":{const r=Wy(e,n);if(!r)return;Et(t,e.layerId).push({anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:r.x,y:r.y,observation:r.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function Et(t,e){let n=t.get(e);return n||(n=[],t.set(e,n)),n}function Ir(t,e){return{anchored:!0,layerId:t,pointIndex:e.pointIndex,x:(e.xMin+e.xMax)/2,y:(e.yMin+e.yMax)/2,observation:e.observation}}const Qy=1e6;function va(t,e,n){const{columns:r,bands:s}=Jy(t,e);return{kind:"banded",layerId:t.id,geom:t.geom,position:t.position,projection:n,mainAxis:e,columns:r,bands:s}}function Jy(t,e){const n=eb(t,e);n.sort((a,c)=>a.mainMid-c.mainMid);const r=new Map,s=new Map;for(const a of n){const c=qs(a.mainMid);let l=r.get(c);if(!l){l={mainMid:a.mainMid,rects:[]},r.set(c,l);const d=qs(a.bandCenter);let u=s.get(d);u||(u={bandCenter:a.bandCenter,columns:[]},s.set(d,u)),u.columns.push(l)}l.rects.push(a.entry)}const o=[...r.values()].sort((a,c)=>a.mainMid-c.mainMid),i=[...s.values()].sort((a,c)=>a.bandCenter-c.bandCenter);for(const a of i)a.columns.sort((c,l)=>c.mainMid-l.mainMid);return{columns:o,bands:i}}function qs(t){return String(Math.round(t*Qy))}function eb(t,e){const n=t.data;if(n.size()===0)return[];if(!(n.hasVariable(g.xMin)&&n.hasVariable(g.xMax)&&n.hasVariable(g.yMin)&&n.hasVariable(g.yMax)))return[];const s=n.getValues(g.xMin,{type:"numeric"}),o=n.getValues(g.xMax,{type:"numeric"}),i=n.getValues(g.yMin,{type:"numeric"}),a=n.getValues(g.yMax,{type:"numeric"}),c=e==="y",l=c?g.y:g.x,d=n.hasVariable(l)?n.getValues(l,{type:"numeric"}):null,u=[];let m=0;for(const p of n){const f=s[m],b=o[m],y=i[m],v=a[m];if(!h(f)||!h(b)||!h(y)||!h(v)){m++;continue}const S=c?(y+v)/2:(f+b)/2,T=d?.[m]??S;u.push({mainMid:S,bandCenter:T,entry:{pointIndex:m,xMin:f,xMax:b,yMin:y,yMax:v,observation:p}}),m++}return u}const tb=1e-9;function Sa(t,e,n){const r=nb(t,e);r.sort((o,i)=>o.main-i.main);const s=[];for(const o of r){const i=s[s.length-1];i&&Math.abs(i.main-o.main)<=tb?i.entries.push(o.entry):s.push({main:o.main,entries:[o.entry]})}return{kind:"buckets",layerId:t.id,geom:t.geom,position:t.position,projection:n,mainAxis:e,buckets:s}}function nb(t,e){const n=t.data;if(n.size()===0)return[];const s=n.hasVariable(g.x),o=n.hasVariable(g.y);if(!s||!o)return[];const i=n.getValues(g.x,{type:"numeric"}),a=n.getValues(g.y,{type:"numeric"}),c=e==="y",l=c?g.xMin:g.yMin,d=c?g.xMax:g.yMax,u=j(t.position),m=u?n.getValues(l,{type:"numeric"}):null,p=u?n.getValues(d,{type:"numeric"}):null,f=n.hasVariable(z.group)?n.getValues(z.group,{type:"categorical"}):null,b=[];let y=0;for(const v of n){const S=i[y],T=a[y];if(!h(S)||!h(T)){y+=1;continue}const V=f?.[y]??null,F=c?T:S;if(u){const ue=m?.[y],J=p?.[y];if(!h(ue)||!h(J)){y+=1;continue}const de=c?J:S,ft=c?T:J;b.push({main:F,entry:{isStacked:u,pointIndex:y,x:de,y:ft,stackMin:ue,stackMax:J,groupKey:V,observation:v}})}else b.push({main:F,entry:{isStacked:u,pointIndex:y,x:S,y:T,groupKey:V,observation:v}});y+=1}return b}function rb(t){return{kind:"enclosure",layerId:t.id,geom:t.geom,position:t.position,projection:"polar",cells:sb(t)}}function sb(t){const e=t.data;if(e.size()===0)return[];const n=[g.xMin,g.xMax,g.yMin,g.yMax];for(const l of n)if(!e.hasVariable(l))return[];const r=e.getValues(g.xMin,{type:"numeric"}),s=e.getValues(g.xMax,{type:"numeric"}),o=e.getValues(g.yMin,{type:"numeric"}),i=e.getValues(g.yMax,{type:"numeric"}),a=[];let c=0;for(const l of e){const d=r[c],u=s[c],m=o[c],p=i[c];if(!h(d)||!h(u)||!h(m)||!h(p)){c++;continue}a.push({pointIndex:c,xMin:d,xMax:u,yMin:m,yMax:p,observation:l}),c++}return a}function Aa(t){return{kind:"noop",layerId:t.id,geom:t.geom,position:t.position,projection:"cartesian"}}function ob(t,e){const n={kind:"points",layerId:t.id,geom:t.geom,position:t.position,projection:"cartesian",points:Ta(t),delaunay:null,delaunayAspectRatio:null};return wa(n,e),n}function ib(t){const e=Ta(t).map(n=>{const r=Dt(n.x,n.y);return{...n,unitX:r.x,unitY:r.y}});return{kind:"points",layerId:t.id,geom:t.geom,position:t.position,projection:"polar",points:e,delaunay:null,delaunayAspectRatio:null}}function wa(t,e){t.delaunay&&t.delaunayAspectRatio===e||(t.delaunay=Pa.Delaunay.from(t.points,n=>n.x*e,n=>n.y),t.delaunayAspectRatio=e)}function Ta(t){const e=t.data;if(e.size()===0)return[];if(!e.hasVariable(g.x)||!e.hasVariable(g.y))return[];const n=e.getValues(g.x,{type:"numeric"}),r=e.getValues(g.y,{type:"numeric"}),s=[];let o=0;for(const i of e){const a=n[o],c=r[o];o+=1,!(!h(a)||!h(c))&&s.push({pointIndex:s.length,x:a,y:c,observation:i})}return s}function Ma(t){return{kind:"render-hit-test",layerId:t.id,geom:t.geom,position:t.position,projection:"cartesian",byKey:ab(t)}}function La(t,e){return{anchored:!1,layerId:t,pointIndex:e.pointIndex,observation:e.observation}}function ab(t){const e=t.identityKey,n=new Map;if(typeof e=="object"){let r=0;for(const s of t.data){const o=s[e.variable];h(o)&&n.set(I(o),{pointIndex:r,observation:s}),r+=1}return n}if(e==="index"){let r=0;for(const s of t.data)n.set(String(r),{pointIndex:r,observation:s}),r+=1}return n}function Zs(t,e,n){return e.type==="polar"?cb(t,e.bandAxis):lb(t,e.mainAxis,n)}function cb(t,e){switch(t.spatialKind){case"points":return ib(t);case"buckets":return Sa(t,"x","polar");case"rects":return e===null?rb(t):va(t,e,"polar");case"noop":return Aa(t);case"render-hit-test":return Ma(t);default:{const n=t.spatialKind;throw new A({message:`buildPolarLayerIndex: unhandled spatialKind ${String(n)}`})}}}function lb(t,e,n){switch(t.spatialKind){case"points":return ob(t,n);case"buckets":return Sa(t,e,"cartesian");case"rects":return va(t,e,"cartesian");case"noop":return Aa(t);case"render-hit-test":return Ma(t);default:{const r=t.spatialKind;throw new A({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(r)}`})}}}function ub(t,e,n){if(t.columns.length===0)return null;const r=ze(t.mainAxis,e),s=xa(t,r),o=s?.rects??[];if(!s||!be(o))return null;const i=j(t.position)?db(o,e,t.mainAxis):mb(o,e,n);return{hit:{anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:t,column:s,distance:Ia(i,e,n)}}function db(t,e,n){const r=tn(n,e);return Ae(t,o=>pb(o,n,r),{shortCircuitOnZero:!0})}function mb(t,e,n){return Ae(t,s=>Ia(s,e,n))}function Ia(t,e,n){const r=Ot(e.x,t.xMin,t.xMax),s=Ot(e.y,t.yMin,t.yMax);return Mr(r,s,n)}function pb(t,e,n){const r=e==="x"?t.yMin:t.xMin,s=e==="x"?t.yMax:t.xMax;return Ot(n,r,s)}function fb(t,e,n){if(t.buckets.length===0)return null;const{main:r,cross:s}=Xg(t.mainAxis,e),o=ba(t,r),i=o?.entries??[];if(!o||!be(i))return null;const a=Ea(i,s,t.mainAxis);return{hit:{anchored:!0,layerId:t.layerId,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation},index:t,bucket:o,distance:Mr(a.x-e.x,a.y-e.y,n)}}function Ea(t,e,n){return Ae(t,s=>Math.abs(tn(n,s)-e))}function hb(t,e,n){if(t.columns.length===0)return null;const{angle:r,radius:s}=Ut(e,n),o=t.mainAxis==="x",i=o?gb(t.columns,r):xa(t,s),a=i?.rects??[];if(!i||!be(a))return null;const c=o?yb(a,s):bb(a,r);return{hit:{anchored:!0,layerId:t.layerId,pointIndex:c.pointIndex,x:(c.xMin+c.xMax)/2,y:(c.yMin+c.yMax)/2,observation:c.observation},index:t,column:i,distance:0}}function gb(t,e){return be(t)?Ae(t,n=>Ct(e,n.mainMid)):null}function yb(t,e){return Ae(t,n=>Ot(e,n.yMin,n.yMax),{shortCircuitOnZero:!0})}function bb(t,e){return Ae(t,n=>Oo(e,n.xMin,n.xMax)?0:Math.min(Ct(e,n.xMin),Ct(e,n.xMax)),{shortCircuitOnZero:!0})}function xb(t,e,n){if(t.buckets.length===0)return null;const{angle:r,radius:s}=Ut(e,n),o=vb(t.buckets,r),i=o?.entries??[];if(!o||!be(i))return null;const a=Ea(i,s,t.mainAxis);return{hit:{anchored:!0,layerId:t.layerId,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation},index:t,bucket:o,distance:0}}function vb(t,e){return be(t)?Ae(t,n=>Ct(n.main,e)):null}function Sb(t,e,n){if(t.cells.length===0)return null;const{angle:r,radius:s}=Ut(e,n);for(const o of t.cells)if(!(s<o.yMin||s>o.yMax)&&Oo(r,o.xMin,o.xMax))return{hit:{anchored:!0,layerId:t.layerId,pointIndex:o.pointIndex,x:(o.xMin+o.xMax)/2,y:(o.yMin+o.yMax)/2,observation:o.observation},index:t};return null}function Ab(t,e,n){if(!be(t.points))return null;const{x:r,y:s}=Jn(e,n),o=Ae(t.points,i=>Qs(i,r,s));return{hit:{anchored:!0,layerId:t.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:t,distance:Math.sqrt(Qs(o,r,s))}}function Qs(t,e,n){const r=t.unitX??Dt(t.x,t.y).x,s=t.unitY??Dt(t.x,t.y).y,o=r-e,i=s-n;return o*o+i*i}const wb=.05;function Tb({layers:t,cursor:e,aspectRatio:n,warmStarts:r,hitTesters:s}){const o={match:null,distance:Number.POSITIVE_INFINITY},i={match:null,distance:Number.POSITIVE_INFINITY};for(const a of t){if(a.kind==="render-hit-test"){const l=Eb(a,e,s);if(l)return{kind:"render-hit-test",match:l};continue}if(a.projection==="polar"){const l=Ib(a,e,n);if(l)return l;continue}const c=Lb({layer:a,cursor:e,aspectRatio:n,warmStarts:r});if(c){if(c.kind==="banded"){c.match.distance<o.distance&&(o.match=c,o.distance=c.match.distance);continue}c.match.distance<i.distance&&(i.match=c,i.distance=c.match.distance)}}return Mb({rect:o,continuous:i})}function Mb({rect:t,continuous:e}){return t.match&&e.match?e.distance<=t.distance+wb?e.match:t.match:t.match??e.match}function Lb({layer:t,cursor:e,aspectRatio:n,warmStarts:r}){switch(t.kind){case"buckets":{const s=fb(t,e,n);return s?{kind:"buckets",match:s}:null}case"banded":{const s=ub(t,e,n);return s?{kind:"banded",match:s}:null}case"points":{const s=r.get(t.layerId)??null,o=$y(t,e,n,s);return o?{kind:"points",match:o}:null}case"noop":return null}}function Ib(t,e,n){switch(t.kind){case"enclosure":{const r=Sb(t,e,n);return r?{kind:"enclosure",match:r}:null}case"points":{const r=Ab(t,e,n);return r?{kind:"points",match:r}:null}case"buckets":{const r=xb(t,e,n);return r?{kind:"buckets",match:r}:null}case"banded":{const r=hb(t,e,n);return r?{kind:"banded",match:r}:null}case"noop":case"render-hit-test":return null}}function Eb(t,e,n){const r=n.get(t.layerId);if(!r)return null;const s=r({x:e.x,y:1-e.y});if(!s)return null;const o=t.byKey.get(s.key);return o?{hit:La(t.layerId,o)}:null}const re={primary:null,group:[],related:new Map},Vb=1;class kb{constructor({layers:e,coordSystem:n}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=Vb,this.warmStarts=new Map,this.cachedState=re,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=re,this.layerIndexes=e.map(r=>Zs(r,n,this.aspectRatio)),this.layerRefs=e.map(r=>Js(r,n)),this.nonInteractiveLayerIds=eo(e)}update({layers:e,coordSystem:n}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const a=this.layerIndexes[i],c=this.layerRefs[i];!a||!c||r.set(a.layerId,{index:a,ref:c})}const s=[],o=[];for(const i of e){const a=r.get(i.id),c=Js(i,n);if(a!==void 0&&_b(a.ref,c)){s.push(a.index),o.push(a.ref);continue}this.warmStarts.delete(i.id),s.push(Zs(i,n,this.aspectRatio)),o.push(c)}for(const i of this.warmStarts.keys())e.some(a=>a.id===i)||this.warmStarts.delete(i);this.layerIndexes=s,this.layerRefs=o,this.nonInteractiveLayerIds=eo(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const n of this.layerIndexes)n.kind==="points"&&n.projection==="cartesian"&&wa(n,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return re;const n=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(c=>!this.nonInteractiveLayerIds.has(c.layerId)),r=Tb({layers:n,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),re;const s=r.match.hit;this.warmStarts.set(s.layerId,s.pointIndex);const o=`${s.layerId}:${s.pointIndex}`;if(this.cachedKey===o)return this.cachedState;const{group:i,related:a}=Hy(r,n);return this.cachedKey=o,this.cachedState={primary:s,group:i,related:a},this.cachedState}registerHitTester(e,n){this.hitTesters.set(e,n)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,n){if(this.nonInteractiveLayerIds.has(e))return re;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return re;const s=r.byKey.get(n);if(!s)return re;const o=`${e}:${n}`;return this.cachedByKeyId===o?this.cachedByKeyState:(this.cachedByKeyId=o,this.cachedByKeyState={primary:La(e,s),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=re,this.cachedByKeyId=null,this.cachedByKeyState=re}}function Js(t,e){return{data:t.data,geom:t.geom,position:t.position,coord:e}}function eo(t){const e=new Set;for(const n of t)n.interactive||e.add(n.id);return e}function _b(t,e){return t.data===e.data&&t.geom===e.geom&&t.position===e.position&&t.coord===e.coord}const Cb=Math.PI*2;function Db(t,e){const n=ze(t.mainAxis,e);if(t.mainAxis==="y"){const s=Me(ye(n));return{x1:0,x2:"100%",y1:s,y2:s}}const r=Me(n);return{x1:r,x2:r,y1:0,y2:"100%"}}function Rb(t,e,n){const r=t.mainAxis==="y"?C(n.observation):W(n.observation);if(r===null)return null;const s=t.mainAxis==="y"?ka(n):Va(n),i=(e.x?.kind==="position"?e.x:null)?.bandwidth??s;if(i===null||i<=0)return null;const a=i/2;if(t.mainAxis==="y"){const d=Me(ye(r+a)),u=Me(i);return{x:0,y:d,width:"100%",height:u}}const c=Me(r-a),l=Me(i);return{x:c,y:0,width:l,height:"100%"}}function Pb(t,e){if(t.bandAxis===null)return null;if(t.bandAxis==="x"){const s=le(e.observation),o=oe(e.observation);return s===null||o===null?null:{startAngle:s,endAngle:o,innerRadius:t.innerRadius,outerRadius:1}}const n=Z(e.observation),r=Y(e.observation);return n===null||r===null?null:{startAngle:t.startAngle,endAngle:t.startAngle+Cb,innerRadius:n,outerRadius:r}}function Va(t){const e=le(t.observation),n=oe(t.observation);return e===null||n===null?null:n-e}function ka(t){const e=Z(t.observation),n=Y(t.observation);return e===null||n===null?null:n-e}const Fb=/^(?:https?:|mailto:)/i,Nb=t=>{if(typeof t!="string")return!1;const e=t.replace(/^[\x00-\x20]+/,"");return e.length===0?!1:Fb.test(e)},Ob=({locale:t,intlOptions:e})=>G(n=>Intl.DateTimeFormat(t,{day:"numeric",month:"long",year:"numeric",weekday:"long",...H,...e}).format(n)),Bb=({locale:t,intlOptions:e})=>G(n=>{const r=n.getUTCSeconds()!==0;return Intl.DateTimeFormat(t,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:r?"2-digit":void 0,...H,...e}).format(n)}),Bt=t=>{const{valueFormat:e}=t;switch(e.type){case"currency":return Di(t);case"date":return Ob(t);case"datetime":return Bb(t);case"day_month":return Ni(t);case"decimal":return Ri(t);case"duration":return pr();case"integer":return Pi(t);case"month":return Oi(t);case"month_year":return gr(t);case"percentage":return Fi(t);case"quarter":return yr();case"text":return mr();case"time":return $i(t);case"weekly_date_range":return Bi(t);case"weekly_date_range_with_year":return Gi(t);case"year":return br(t);case"lookup":return Bt({...t,valueFormat:e.fallback});default:{const n=e;throw new A({message:`Unhandled value format: ${n.type}`})}}},Gb=({layers:t,coordSystem:e,scales:n,guides:r,numberFormat:s,parsingLocale:o,hover:i,formattingLocale:a})=>{const{primary:c}=i;if(c===null)return null;const l=a??o;return{header:$b({layers:t,coordSystem:e,guides:r,primary:c,locale:l,numberFormat:s}),rows:Wb({layers:t,scales:n,guides:r,hover:i,locale:l,numberFormat:s})}};function $b(t){if(t.coordSystem.type!=="cartesian")return null;const e=Tr(t.guides,"x");if(!e)return null;const n=t.layers.find(i=>i.id===t.primary.layerId);if(!n)return null;const r=x(n.mapping.x);if(!h(r))return null;const s=t.primary.observation[r];return h(s)?Bt({valueFormat:e.valueFormat,locale:t.locale,numberFormat:t.numberFormat})(s):null}function Wb(t){const e=[],n=t.scales.color??null,r=Ub({guides:t.guides,locale:t.locale,numberFormat:t.numberFormat});for(const s of t.layers){const o=Hb(s,t.hover);if(o.length===0)continue;const i=o[0];if(s.tooltip.length>0&&i){e.push(...zb(s,i,{locale:t.locale,numberFormat:t.numberFormat}));continue}const a=ei(s.data,s.mapping),c=Yb(o,s,n,a),l=Ar({layer:s,numberFormat:t.numberFormat,locale:t.locale}),d=Kb(t.guides,s),u=Zt(s),m=s.mapping.color!==void 0;for(const p of c){const f=m?a(p.observation):null,b=Yt(p.observation)??null,y=Co(p.observation),v=m&&f!==null?r(f):d,S=u(p.observation),T=S===null?"":l(S,p.observation);e.push({swatchColor:b,geom:s.geom,swatchLineType:y,label:v,value:T,isPrimary:p===t.hover.primary,key:`${p.layerId}:${p.pointIndex}`})}}return e}function zb(t,e,n){return t.tooltip.map(r=>{const s=t.mapping[r.aes],o=Q(t.data,s)(e.observation),i=P({valueFormat:Eo(t,x(s)),locale:n.locale,numberFormat:n.numberFormat});return{swatchColor:null,geom:t.geom,swatchLineType:"solid",label:r.key,value:o===null?"":i(o,e.observation),isPrimary:!1,key:`${e.layerId}:${e.pointIndex}:${r.aes}`}})}function Hb(t,e){const n=[];return e.primary!==null&&e.primary.layerId===t.id&&n.push(e.primary,...e.group),n.push(...e.related.get(t.id)??[]),n}function Yb(t,e,n,r){if(n===null||e.mapping.color===void 0)return t;const s=new Map;return n.domain.forEach((o,i)=>{s.set(I(o),i)}),t.map((o,i)=>{const a=r(o.observation),c=a===null?null:I(a),l=c===null?Number.POSITIVE_INFINITY:s.get(c)??Number.POSITIVE_INFINITY;return{hit:o,originalIndex:i,rank:l}}).sort((o,i)=>o.rank===i.rank?o.originalIndex-i.originalIndex:o.rank-i.rank).map(o=>o.hit)}function Ub({guides:t,locale:e,numberFormat:n}){const r=new Map(t.colorGroups.map(o=>[I(o.value),{label:o.label,format:Bt({valueFormat:o.valueFormat,locale:e,numberFormat:n})}])),s=Bt({valueFormat:{type:"text"},locale:e,numberFormat:n});return o=>{const i=r.get(I(o));return i===void 0?s(o):i.label??i.format(o)}}function Kb(t,e){const n=x(e.mapping.y);return nr(n,t.variableLabels)??""}function Xb(t,e,n=0){const r=t[e];return typeof r=="number"&&Number.isFinite(r)?r:n}function jb(t,e,n=""){const r=t[e];return typeof r=="string"?r:n}const qb={differenceArrow(t){return{type:"annotation",kind:"differenceArrow",annotation:t}},shape(t){return{type:"annotation",kind:"shape",annotation:t}},arrow(t){return{type:"annotation",kind:"arrow",annotation:t}},text(t){return{type:"annotation",kind:"text",annotation:t}},image(t){return{type:"annotation",kind:"image",annotation:t}},sticker(t){return{type:"annotation",kind:"sticker",annotation:t}},pinnedNumber(t){return{type:"annotation",kind:"pinnedNumber",annotation:t}},comment(t){return{type:"annotation",kind:"comment",annotation:t}}},Zb={lilac:"linear-gradient(94deg, #C9C0F7 -2.94%, #F6E6FD 92.51%)",neon_pink:"linear-gradient(93deg, #E04A95 2.61%, #FD7F92 97.51%)",blackberry:"linear-gradient(132deg, #9F9FED 2.98%, #B9E6FF 97.65%)",sun:"linear-gradient(139deg, #FCDB61 5.51%, #FB9C65 97.21%)",iceland:"linear-gradient(94deg, #29CDA8 -2.94%, #52C9D2 92.51%)",sunset:"linear-gradient(138deg, #FCDB62 5.77%, #FD8091 99.91%)",ultraviolet:"linear-gradient(132deg, #D167D8 2.98%, #6584E6 97.65%)",purple:"linear-gradient(203.63deg, #BBADFD 15.22%, #BE9AF0 81.52%)",ice_cream:"linear-gradient(119.34deg, #FC7E91 3.68%, #FCD1B1 116.76%)",mint:"linear-gradient(93.55deg, #25CDA5 -6.07%, #58C8D8 113.6%)",cool:"linear-gradient(93.55deg, #3F8EEB -6.07%, #58C8D8 113.6%)",fresh:"linear-gradient(114.37deg, #A4A4EE 4.32%, #58C8D8 87.71%)"};function Qb(t,e={}){return{type:"highlight",id:e.id,predicate:t,scope:e.scope,layerIndex:e.layerIndex}}function Jb(t){return{mapping:t.mapping,layers:t.layers,scales:t.scales.map(tx),transforms:t.transforms,highlights:t.highlights.map(e=>ex(e,t.layers)),coords:t.coords,config:t.config}}function ex(t,e){const n=t.layerId?e.findIndex(r=>r.id===t.layerId):-1;return{type:"highlight",id:t.id,predicate:t.predicate,scope:t.scope,layerIndex:n>=0?n:void 0}}function tx(t){return t.scaleType==="palette"?nx(t):t}function nx(t){return{...t,palette:rx(t.palette),overrides:sx(t.overrides)}}function rx(t){return t.type==="custom"?{type:"custom",id:t.id}:t}function sx(t){if(!t)return;const e={};for(const[n,r]of Object.entries(t))e[Number(n)]={hex:r};return e}function E(t){return{id:t.id??crypto.randomUUID(),timestamp:t.timestamp??Date.now(),description:t.description,author:t.author??"unknown"}}class Er{constructor(e,n={}){this.type="set-axis-label",this.params=e,this.metadata=E({...n,description:`Set ${e.axis} axis label to ${e.label??"(none)"}`})}apply(e){const{axis:n,label:r}=this.params,s=e.config.axes[n].label??null,o=B(e,{config:{axes:{[n]:{label:r}}}}),i=new Er({axis:n,label:s},this.metadata);return{spec:o,revert:i}}}const ox={type:"set-axis-label",deserialize:(t,e)=>new Er(t,e)};class rn{constructor(e,n={}){this.type="set-axis-position",this.params=e,this.metadata=E({...n,description:`Set ${e.axis} axis position to ${e.position}`})}apply(e){const{axis:n,position:r}=this.params,s=B(e,{config:{axes:{[n]:{position:r}}}}),o=n==="x"?{axis:"x",position:e.config.axes.x.position}:{axis:"y",position:e.config.axes.y.position},i=new rn(o,this.metadata);return{spec:s,revert:i}}}const ix={type:"set-axis-position",deserialize:(t,e)=>new rn(t,e)};class Vr{constructor(e,n={}){this.type="set-axis-tick-mode",this.params=e,this.metadata=E({...n,description:`Set ${e.axis} axis tick mode to ${e.tickMode}`})}apply(e){const{axis:n,tickMode:r}=this.params,s=e.config.axes[n].ticks.mode,o=B(e,{config:{axes:{[n]:{ticks:{mode:r}}}}}),i=new Vr({axis:n,tickMode:s},this.metadata);return{spec:o,revert:i}}}const ax={type:"set-axis-tick-mode",deserialize:(t,e)=>new Vr(t,e)};class kr{constructor(e,n={}){this.type="set-axis-ticks-visibility",this.params=e,this.metadata=E({...n,description:`Set ${e.axis} axis ticks visibility to ${e.isVisible}`})}apply(e){const{axis:n,isVisible:r}=this.params,s=e.config.axes[n].ticks.isVisible,o=B(e,{config:{axes:{[n]:{ticks:{isVisible:r}}}}}),i=new kr({axis:n,isVisible:s},this.metadata);return{spec:o,revert:i}}}const cx={type:"set-axis-ticks-visibility",deserialize:(t,e)=>new kr(t,e)};class _r{constructor(e,n={}){this.type="set-axis-visibility",this.params=e,this.metadata=E({...n,description:`Set ${e.axis} axis visibility to ${e.isVisible}`})}apply(e){const{axis:n,isVisible:r}=this.params,s=e.config.axes[n].isVisible,o=B(e,{config:{axes:{[n]:{isVisible:r}}}}),i=new _r({axis:n,isVisible:s},this.metadata);return{spec:o,revert:i}}}const lx={type:"set-axis-visibility",deserialize:(t,e)=>new _r(t,e)};class sn{constructor(e,n={}){this.type="set-content-caption",this.params=e,this.metadata=E({...n,description:"Set chart caption"})}apply(e){const n=e.config.content.caption;if(n===this.params.caption)return null;const r=B(e,{config:{content:{caption:this.params.caption}}}),s=new sn({caption:n},this.metadata);return{spec:r,revert:s}}}const ux={type:"set-content-caption",deserialize:(t,e)=>new sn(t,e)};class on{constructor(e,n={}){this.type="set-content-subtitle",this.params=e,this.metadata=E({...n,description:"Set chart subtitle"})}apply(e){const n=e.config.content.subtitle;if(n===this.params.subtitle)return null;const r=B(e,{config:{content:{subtitle:this.params.subtitle}}}),s=new on({subtitle:n},this.metadata);return{spec:r,revert:s}}}const dx={type:"set-content-subtitle",deserialize:(t,e)=>new on(t,e)};class an{constructor(e,n={}){this.type="set-content-title",this.params=e,this.metadata=E({...n,description:"Set chart title"})}apply(e){const n=e.config.content.title;if(n===this.params.title)return null;const r=B(e,{config:{content:{title:this.params.title}}}),s=new an({title:n},this.metadata);return{spec:r,revert:s}}}const mx={type:"set-content-title",deserialize:(t,e)=>new an(t,e)};class Cr{constructor(e,n={}){this.type="set-grid-visibility",this.params=e,this.metadata=E({...n,description:`Set grid visibility to x=${e.xIsVisible}, y=${e.yIsVisible}`})}apply(e){const n=e.config.axes.x.grid.isVisible,r=e.config.axes.y.grid.isVisible,s=B(e,{config:{axes:{x:{grid:{isVisible:this.params.xIsVisible}},y:{grid:{isVisible:this.params.yIsVisible}}}}}),o=new Cr({xIsVisible:n,yIsVisible:r},this.metadata);return{spec:s,revert:o}}}const px={type:"set-grid-visibility",deserialize:(t,e)=>new Cr(t,e)};class Dr{constructor(e,n={}){this.type="set-headline-compare-with",this.params=e,this.metadata=E({...n,description:`Set headline compare with to ${e.compareWith}`})}apply(e){const n=e.config.headline.compareWith,r=B(e,{config:{headline:{compareWith:this.params.compareWith}}}),s=new Dr({compareWith:n},this.metadata);return{spec:r,revert:s}}}const fx={type:"set-headline-compare-with",deserialize:(t,e)=>new Dr(t,e)};class Rr{constructor(e,n={}){this.type="set-headline-position",this.params=e,this.metadata=E({...n,description:`Set headline position to ${e.position}`})}apply(e){const n=e.config.headline.position,r=B(e,{config:{headline:{position:this.params.position}}}),s=new Rr({position:n},this.metadata);return{spec:r,revert:s}}}const hx={type:"set-headline-position",deserialize:(t,e)=>new Rr(t,e)};class cn{constructor(e,n={}){this.type="set-headline-show",this.params=e,this.metadata=E({...n,description:`Set headline show to ${e.show}`})}apply(e){const n=e.config.headline.show,r=B(e,{config:{headline:{show:this.params.show}}}),s=new cn({show:n},this.metadata);return{spec:r,revert:s}}}const gx={type:"set-headline-show",deserialize:(t,e)=>new cn(t,e)};class Pr{constructor(e,n={}){this.type="set-headline-size",this.params=e,this.metadata=E({...n,description:`Set headline size to ${e.size}`})}apply(e){const n=e.config.headline.size,r=B(e,{config:{headline:{size:this.params.size}}}),s=new Pr({size:n},this.metadata);return{spec:r,revert:s}}}const yx={type:"set-headline-size",deserialize:(t,e)=>new Pr(t,e)};class Fr{constructor(e,n={}){this.type="set-legend-position",this.params=e,this.metadata=E({...n,description:`Set legend position to ${e.position}`})}apply(e){const n=e.config.legend.position,r=B(e,{config:{legend:{position:this.params.position}}}),s=new Fr({position:n},this.metadata);return{spec:r,revert:s}}}const bx={type:"set-legend-position",deserialize:(t,e)=>new Fr(t,e)};class Nr{constructor(e,n={}){this.type="set-number-format-abbreviation",this.params=e,this.metadata=E({...n,description:`Set number format abbreviation to ${e.abbreviation}`})}apply(e){const n=e.config.numberFormat.abbreviation,r=B(e,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),s=new Nr({abbreviation:n},this.metadata);return{spec:r,revert:s}}}const xx={type:"set-number-format-abbreviation",deserialize:(t,e)=>new Nr(t,e)};class Or{constructor(e,n={}){this.type="set-number-format-decimals",this.params=e,this.metadata=E({...n,description:`Set number format decimals to ${e.decimals}`})}apply(e){const n=e.config.numberFormat.decimals,r=B(e,{config:{numberFormat:{decimals:this.params.decimals}}}),s=new Or({decimals:n},this.metadata);return{spec:r,revert:s}}}const vx={type:"set-number-format-decimals",deserialize:(t,e)=>new Or(t,e)};function ln(t,...e){return t?e.includes(t.geom):!1}function un(t,e){return t.find(n=>n.id===e)}function dn(t,...e){return t.find(n=>e.some(r=>r===n.geom))}function _a(t,e){return{...t,params:{...t.params,...e}}}function Br(t,e,n){const r=t.layers.findIndex(o=>o.id===e);if(r===-1)return t;const s=t.layers.map((o,i)=>i===r?n:o);return{...t,layers:s}}function Sx(t,e){const n=t.layers.findIndex(s=>s.id===e);if(n===-1||t.layers.length<=1)return t;const r=t.layers.filter((s,o)=>o!==n);return be(r)?{...t,layers:r}:t}class Gr{constructor(e,n={}){this.type="set-line-interpolation",this.params=e,this.metadata=E({...n,description:`Set line interpolation to ${e.interpolate}`})}apply(e){const n=this.params.layerId?un(e.layers,this.params.layerId):dn(e.layers,"line","area");if(!ln(n,"line","area"))return null;const r=n.params.interpolate,s=Br(e,n.id,_a(n,{interpolate:this.params.interpolate})),o=new Gr({layerId:n.id,interpolate:r},this.metadata);return{spec:s,revert:o}}}const Ax={type:"set-line-interpolation",deserialize:(t,e)=>new Gr(t,e)};class mn{constructor(e,n={}){this.type="set-line-width",this.params=e,this.metadata=E({...n,description:`Set line width to ${e.lineWidth}`})}apply(e){const n=this.params.layerId?un(e.layers,this.params.layerId):dn(e.layers,"line","area");if(!ln(n,"line","area"))return null;const r=n.params.lineWidth,s=Br(e,n.id,_a(n,{lineWidth:this.params.lineWidth})),o=new mn({layerId:n.id,lineWidth:r},this.metadata);return{spec:s,revert:o}}}const wx={type:"set-line-width",deserialize:(t,e)=>new mn(t,e)};class $r{constructor(e,n={}){this.type="set-point-size",this.params=e,this.metadata=E({...n,description:`Set point size to ${e.size}`})}apply(e){const n=this.params.layerId?un(e.layers,this.params.layerId):dn(e.layers,"point");if(!ln(n,"point"))return null;const r=n.params.size,s=Br(e,n.id,{...n,params:{...n.params,size:this.params.size}}),o=new $r({layerId:n.id,size:r},this.metadata);return{spec:s,revert:o}}}const Tx={type:"set-point-size",deserialize:(t,e)=>new $r(t,e)},Mx={type:"toggle-line-points",deserialize:(t,e)=>new Gt(t,e)};class Gt{constructor(e,n={}){this.type="toggle-line-points",this.params=e,this.metadata=E({...n,description:`${e.showPoints?"Show":"Hide"} line points`})}apply(e){const n=this.params.layerId?un(e.layers,this.params.layerId):dn(e.layers,"line");return ln(n,"line")?this.params.showPoints?this.addPointLayer(e,n):this.removePointLayer(e,n):null}addPointLayer(e,n){if(this.findAssociatedPointLayer(e,n))return null;const r=this.params.removedLayer??Ti(Lx,e.mapping,e.coords.coordType,R.point({aes:{...n.mapping},interactive:!1})),s={...e,layers:[...e.layers,r]},o=new Gt({layerId:n.id,showPoints:!1},this.metadata);return{spec:s,revert:o}}removePointLayer(e,n){const r=this.findAssociatedPointLayer(e,n);if(!r)return null;const s=Sx(e,r.id),o=new Gt({layerId:n.id,showPoints:!0,removedLayer:r},this.metadata);return{spec:s,revert:o}}findAssociatedPointLayer(e,n){return e.layers.find(r=>r.geom==="point"&&Fa(r.mapping,n.mapping))}}const Lx=new ir;function pn(t,e){return t.scales.find(n=>n.scaledAesthetic===e)}function fn(t,e,n){const r=t.scales.map(s=>s.scaledAesthetic===e?n:s);return{...t,scales:r}}function hn(t){const e=t.replace(/([A-Z])/g," $1").toLowerCase();return e.charAt(0).toUpperCase()+e.slice(1)}class gn{constructor(e,n={}){this.type="set-scale-domain",this.params=e,this.metadata=E({...n,description:`Set ${hn(e.scaledAesthetic)} scale domain`})}apply(e){const n=pn(e,this.params.scaledAesthetic);if(!n||n.scaleType!=="continuous"&&n.scaleType!=="datetime")return null;const r={min:n.domainMin??null,max:n.domainMax??null},s={...n,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},o=fn(e,this.params.scaledAesthetic,s),i={scaledAesthetic:this.params.scaledAesthetic};this.params.domainMin!==void 0&&(i.domainMin=r.min),this.params.domainMax!==void 0&&(i.domainMax=r.max);const a=new gn(i,this.metadata);return{spec:o,revert:a}}}const Ix={type:"set-scale-domain",deserialize:(t,e)=>new gn(t,e)};class Wr{constructor(e,n={}){this.type="set-scale-palette",this.params=e,this.metadata=E({...n,description:`Set ${hn(e.scaledAesthetic)} palette`})}apply(e){const n=pn(e,this.params.scaledAesthetic);if(n?.scaleType!=="palette")return null;const r=fn(e,this.params.scaledAesthetic,{...n,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),s=new Wr({scaledAesthetic:this.params.scaledAesthetic,palette:n.palette},this.metadata);return{spec:r,revert:s}}}const Ex={type:"set-scale-palette",deserialize:(t,e)=>new Wr(t,e)};class zr{constructor(e,n={}){this.type="set-scale-reverse",this.params=e,this.metadata=E({...n,description:`Set ${hn(e.scaledAesthetic)} scale reverse to ${e.reverse}`})}apply(e){const n=pn(e,this.params.scaledAesthetic);if(!n||n.scaleType!=="continuous")return null;const r=n.reverse,s=fn(e,this.params.scaledAesthetic,{...n,reverse:this.params.reverse}),o=new zr({scaledAesthetic:this.params.scaledAesthetic,reverse:r},this.metadata);return{spec:s,revert:o}}}const Vx={type:"set-scale-reverse",deserialize:(t,e)=>new zr(t,e)};class Hr{constructor(e,n={}){this.type="set-scale-transform",this.params=e,this.metadata=E({...n,description:`Set ${hn(e.scaledAesthetic)} scale transform to ${e.transform}`})}apply(e){const n=pn(e,this.params.scaledAesthetic);if(!n||n.scaleType!=="continuous")return null;const r=n.transform,s=fn(e,this.params.scaledAesthetic,{...n,transform:this.params.transform}),o=new Hr({scaledAesthetic:this.params.scaledAesthetic,transform:r},this.metadata);return{spec:s,revert:o}}}const kx={type:"set-scale-transform",deserialize:(t,e)=>new Hr(t,e)};class Ca{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new A({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const n=this.descriptors.get(e);if(!n)throw new A({message:`CommandRegistry: no descriptor registered for type '${e}'`});return n}}const L=new Ca;L.register(Ax);L.register(wx);L.register(Tx);L.register(Mx);L.register(Ix);L.register(Ex);L.register(Vx);L.register(kx);L.register(ox);L.register(ax);L.register(ix);L.register(cx);L.register(lx);L.register(ux);L.register(dx);L.register(mx);L.register(px);L.register(fx);L.register(hx);L.register(gx);L.register(yx);L.register(bx);L.register(xx);L.register(vx);class _x{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.maxHistorySize=e.maxHistorySize??100}apply(e,n){return this.withReentrancyGuard(()=>{const r=e.apply(n);return r?(this.undoStack.push({command:e,revert:r.revert}),this.redoStack=[],this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.emit({type:"apply",command:e,spec:r.spec}),r.spec):n})}undo(e){return this.withReentrancyGuard(()=>{const n=this.undoStack.pop();if(!n)return null;const r=n.revert.apply(e);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(e){return this.withReentrancyGuard(()=>{const n=this.redoStack.pop();if(!n)return null;const r=n.revert.apply(e);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(e){return this.listeners.add(e),()=>this.listeners.delete(e)}withReentrancyGuard(e){if(this.isEmitting)throw new A({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const n of this.listeners)try{n(e)}catch(r){console.error("CommandStack listener error:",r)}}}const Yr=500,Ur="normal",Kr={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},Cx=t=>{const e=t.style??Ur,n=t.weight??Yr,r=t.family.includes(",")?t.family:`'${t.family}'`;return`${e} ${n} ${t.size}px ${r}`},Xr=t=>typeof t!="string"?t??Yr:Kr[t],Dx="\0";class Rx{constructor(e){this.inner=e,this.cache=new Map}measureText(e,n){const r=this.getCacheKey(e,n),s=this.cache.get(r);if(s)return s;const o=this.inner.measureText(e,n);return this.cache.set(r,o),o}getCacheKey(e,n){return[n.family,n.size,Xr(n.weight),n.style??Ur,e].join(Dx)}}const Px={" ":.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},Fx=.55,Nx=1.05,Ox=.84,Bx=.21;class Gx{measureText(e,n){let r=0;for(const a of e)r+=(Px[a]??Fx)*n.size;Xr(n.weight)>=Kr.semiBold&&(r*=Nx);const o=Ox*n.size,i=Bx*n.size;return{width:r,height:o+i,ascent:o,descent:i}}}exports.ANNOTATION_TOOLTIP_MARKER_GAP=nt;exports.BORDER_PRESETS=Ai;exports.BORDER_PRESET_GRADIENTS=Zb;exports.COMPILER_STAGE_KEYS=Sf;exports.CachedTextMeasurer=Rx;exports.CommandRegistry=Ca;exports.CommandStackManager=_x;exports.Compiler=Ei;exports.DATA_LABEL_PADDING_X_PX=la;exports.DATA_LABEL_PADDING_Y_PX=ua;exports.DEFAULT_COLOR_PALETTE=ar;exports.DEFAULT_FONT_STYLE=Ur;exports.DEFAULT_FONT_WEIGHT=Yr;exports.DEFAULT_LINE_WIDTH=ga;exports.DEFAULT_LOCALE=Ht;exports.Dataset=k;exports.GROUP_VARIABLES=z;exports.Geom=Ce;exports.HEADLINE_SWATCH_GAP=ma;exports.HEADLINE_SWATCH_SIZE=da;exports.HEADLINE_TREND_GAP=ha;exports.HEADLINE_TREND_ICON_SIZE=fa;exports.HEADLINE_VALUE_LABEL_GAP=pa;exports.HeuristicTextMeasurer=Gx;exports.HoverEngine=kb;exports.InternalError=A;exports.LAYOUT_PADDING=wr;exports.LayoutCompiler=Lg;exports.MONO_BASES=hi;exports.NAMED_WEIGHTS=Kr;exports.NEON_BASES=gi;exports.OUT_OF_VIEW_MARGIN_PX=rt;exports.POLAR_RIM_LABEL_GAP_PX=On;exports.POSITION_VARIABLES=g;exports.RESTING_HOVER_STATE=re;exports.SIBLING_OVERLAP_THRESHOLD_PX=oa;exports.SetAxisPositionCommand=rn;exports.SetContentCaptionCommand=sn;exports.SetContentSubtitleCommand=on;exports.SetContentTitleCommand=an;exports.SetHeadlineShowCommand=cn;exports.SetLineWidthCommand=mn;exports.SetScaleDomainCommand=gn;exports.SpecResolver=Ii;exports.Stat=qe;exports.TAU=Ie;exports.VISUAL_VARIABLES=ve;exports.annotation=qb;exports.buildAverageLineSymbols=Eg;exports.buildCalloutHitRegions=_g;exports.buildDataLabelsContent=qh;exports.buildDiagnostic=no;exports.buildFontString=Cx;exports.buildLayerYValueFormatter=Ar;exports.buildPinnedNumberValueFormatter=ny;exports.buildPolarBarArcPath=Oy;exports.buildTooltipContent=Gb;exports.commandRegistry=L;exports.computeDifferenceArrow=Ji;exports.computeDirectLabelsLayout=ty;exports.computeFreeformArrow=Iy;exports.computePanelBorderPaths=Wg;exports.config=wi;exports.convertSpecToInput=Jb;exports.coord=$;exports.createAlphaValueReader=$u;exports.createAreaPathGenerators=_y;exports.createColorValueReader=ei;exports.createCompiler=Af;exports.createDatasetFromKindPartitions=$c;exports.createEmptyHighlight=ti;exports.createGraphyBuilder=Lf;exports.createGroupValueReader=Wu;exports.createHeadlineItemRows=fy;exports.createLabelValueReader=Bu;exports.createLineFillAreaGenerator=Py;exports.createLinePathGenerator=Ry;exports.createRawValueReader=Q;exports.createSegmentYReader=Zt;exports.createSizeValueReader=Gu;exports.createSpec=Vi;exports.createStableKeyGenerator=By;exports.createStrokeWidthValueReader=zu;exports.createValueFormatter=P;exports.createXValueReader=jt;exports.createYValueReader=Jo;exports.cursorToPiePlane=Jn;exports.cursorToPolar=Ut;exports.extractConstantValue=ce;exports.extractPlainText=aa;exports.extractVariableName=x;exports.findAxisGuide=Tr;exports.findCalloutHit=kg;exports.findLegendForAesthetic=my;exports.formatHeadline=ry;exports.formatLegends=uy;exports.formatRuleValue=py;exports.geom=R;exports.getAlpha=yc;exports.getAngleExtent=Ki;exports.getBarRectBounds=Dy;exports.getColor=Yt;exports.getCrossAxisCoordinate=tn;exports.getCurve=nn;exports.getDashArray=Vy;exports.getDataLabelDimensions=Jg;exports.getDifferenceArrowDimensions=Qi;exports.getGroup=Ue;exports.getHoverGuideLineProps=Db;exports.getHoverGuideRectProps=Rb;exports.getLineType=Co;exports.getMainAxisCoordinate=ze;exports.getNumericWeight=Xr;exports.getPolarHoverGuideArcProps=Pb;exports.getRadiusExtent=Xi;exports.getScaledAesthetic=du;exports.getSize=ko;exports.getStablePolarBarKeyGenerator=Gy;exports.getStrokeWidth=_o;exports.getX=W;exports.getXMax=oe;exports.getXMin=le;exports.getY=C;exports.getYMax=Y;exports.getYMin=Z;exports.getYRaw=Qo;exports.highlight=Qb;exports.isCartesian=jg;exports.isCategoricalValueFormat=ho;exports.isCompilerCachingEnabled=Oa;exports.isCurrencyValueFormat=qn;exports.isDateWithoutYearValueFormat=Zn;exports.isDefined=h;exports.isGraphConfig=yi;exports.isLayerOf=wf;exports.isLookupValueFormat=Xn;exports.isNumericValueFormat=jn;exports.isSafeUrl=Nb;exports.isStackedPosition=j;exports.isTemporalValueFormat=Ye;exports.mapping=hc;exports.normalizeAngle=$e;exports.pipe=ki;exports.placeCallouts=Pg;exports.polarToUnit=Dt;exports.positionToAngle=Bo;exports.prefixInternalVariable=w;exports.prepareAreaObservations=Cy;exports.prepareLineObservations=Fy;exports.readAuthoredNumber=Xb;exports.readAuthoredString=jb;exports.readXExtent=Va;exports.readYExtent=ka;exports.resolveDefinition=li;exports.resolveHeadlinePlacement=Ag;exports.resolveSegmentYSource=qt;exports.resolveStrokeWidth=ky;exports.resolveYScaleAesthetic=je;exports.scale=ge;exports.setCompilerCachingEnabled=Na;exports.stat=Jt;exports.toPanelCursor=sa;exports.toPercent=Me;exports.toViewBoxX=qg;exports.toViewBoxY=ye;exports.transform=he;exports.unitToPolar=Go;
|