@graphysdk/viz-engine 1.9.0-beta.1790778920035 → 1.9.0-beta.1790850980247
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/{compiler--1GEomjr.cjs → compiler-CXVRHWRc.cjs} +1 -1
- package/dist/graph-config.d.ts +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +1360 -1337
- package/dist/testing.cjs +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.mjs +1 -1
- package/package.json +1 -1
- package/dist/{compiler-BV6EHLdE.js → compiler-IQIM9hm4.js} +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const o=require("./annotations-6ONVHjKW.cjs");let ce=require("lodash-es"),q=require("d3-time"),jr=require("date-fns/differenceInDays"),D=require("d3-regression"),w=require("d3-scale"),Y=require("d3-interpolate"),A=require("d3-scale-chromatic"),ye=require("lodash-es/clamp");ye=o.__toESM(ye,1);let ve=require("lodash-es/merge");ve=o.__toESM(ve,1);var V=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);return o.isDefined(n)?a=>{const i=a[n];return i===void 0?null:vt(i,e.getType(n))}:()=>null},Gr=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);if(!o.isDefined(n)||!e.hasVariable(n))return()=>null;const a=e.getValues(n),i=e.getType(n);return s=>{const c=a[s];return c===void 0?null:vt(c,i)}},Kr=(e,t)=>V(e,t.x),Yr=(e,t)=>V(e,t.y),zr=(e,t)=>V(e,t.label),Wr=(e,t)=>V(e,t.color),qr=(e,t)=>V(e,t.size),Hr=(e,t)=>V(e,t.alpha),Xr=(e,t)=>V(e,t.group),Jr=(e,t)=>V(e,t.strokeWidth),vt=(e,t)=>{switch(t){case"numeric":return o.isStrictNumericDataValue(e)?e:null;case"categorical":return o.isStrictCategoricalDataValue(e)?e:null;case"temporal":return o.isStrictTemporalDataValue(e)?e:null;default:return null}},Xe={variable:o.POSITION_VARIABLES.yRaw};function le(e,t){return o.isStackedPosition(e)?Xe:t.y??Xe}function we(e){return V(e.data,le(e.position,e.mapping))}function Qr(e){return Gr(e.data,le(e.position,e.mapping))}var ue=e=>{const t=o.readVariableName(e.mapping.x);return t!==null&&t!==o.CONSTANT_VARIABLES.x?t:o.GROUP_VARIABLES.group},Le=e=>Zr(e)?o.readVariableName(e.mapping.y):null,bt=e=>Le(e)===null?null:we(e),Ce=e=>e.spatialKind!=="cells",Zr=e=>e.spatialKind==="points"||e.spatialKind==="cells",St=(e,t)=>e.yScaleType===t.yScaleType&&Se(e.valueFormat)===Se(t.valueFormat),be=e=>`${e.yScaleType} y axis, ${Se(e.valueFormat)}`,Se=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,At=(e,t)=>{const r=o.toExplicitValueFormat(e.data.getValueFormat(ue(e))),n=Le(e);return a=>({...a,anchorValue:o.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:o.parseAddressingValue(a.groupValue,o.toExplicitValueFormat(e.data.getValueFormat(o.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:o.parseAddressingValue(a.crossValue,o.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Tt(e){return e instanceof o.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function en(e,t){return It(e,t)}function H(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function tn(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function _e(e,t){let r=null;for(const[n,a]of e.entries()){const i=t(a,n);if(i===a){r?.push(i);continue}r??=e.slice(0,n),r.push(i)}return r??e}function It(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(o.isPlainObject(i)&&o.isPlainObject(s)){const c=It(s,i);c!==s&&(n[a]=c,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function de(e){return{pipe:t=>{const r=t(e);return de({...e,...r})},result:()=>e}}var rn=(e,t)=>{if(!o.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[o.getStableKey(r)]??e.fallback},Et=e=>e.type==="polar"?"disk":"panel",Vt=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},nn=(e,t)=>{if(e.space!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=Vt(e.space,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function xt(e,t){return e==="x"?t.x:t.y}function Ot(e,t){return e==="x"?t.y:t.x}function an(e,t){return{main:xt(e,t),cross:Ot(e,t)}}function Ae(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function wt(e){return e.type==="cartesian"?e.mainAxis:"x"}function on(e){return e.type==="cartesian"}var Z=e=>e[o.GROUP_VARIABLES.group],Lt=e=>{const t=ue(e),r=bt(e),n=Ce(e)&&t!==o.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const c=n?Z(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...c!==null&&{groupValue:c}}}},sn={type:"decimal"};function Ct(e){return e.length>0&&e.every(t=>t.data.size()===0)}function Pe(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):sn}function cn(e){return Pe(e,o.readVariableName(e.mapping.y))}function _t({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??le(t,r)}function Pt(e,t){const r=_t({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=o.readVariableName(r),a=n===o.POSITION_VARIABLES.yRaw?o.readVariableName(e.mapping.y):n;return{read:V(e.data,r),valueFormat:Pe(e,a)}}var Dt=e=>{const t=ue(e),r=bt(e),n=Ce(e);return(a,i)=>!o.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||o.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:o.areDataValuesEqual(Z(a),i.groupValue)},Nt=e=>{const t=o.readVariableName(e.mapping.y),r=we(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},ln=e=>t=>{if(t===o.readVariableName(e.mapping.y))return Qr(e);const r=e.data.hasVariable(t)?e.data.getValues(t):null;return n=>r?.[n]??null};var un=["lt","lte","gt","gte","range"],dn={highlight:{subject:"Highlight predicate",effect:"dropping this highlight"},"selection-anchor":{subject:"Selection anchor predicate",effect:"dropping this annotation"},"style-rule":{subject:"Style rule predicate",effect:"dropping this rule"}},_=()=>!1,F=()=>!0;function pe(e,t){const r=Nt(e);return{...Rt(e,t),createValueReader:n=>a=>r(a,n)}}function pn(e,t){return{...Rt(e,t),createValueReader:ln(e)}}function ae(e){return"and"in e?[...new Set(e.and.flatMap(ae))]:"or"in e?[...new Set(e.or.flatMap(ae))]:"not"in e?ae(e.not):[e.variable]}function N(e,t){if("and"in e){const r=e.and.map(n=>N(n,t)).filter(n=>n!==F);return r.includes(_)?_:r.length===0?F:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>N(n,t)).filter(n=>n!==_);return r.includes(F)?F:r.length===0?_:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=N(e.not,t);return r===_?F:r===F?_:n=>!r(n)}return fn(e,t)}function R(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>R(n,t,r)):"or"in e?e.or.flatMap(n=>R(n,t,r)):"not"in e?R(e.not,t,r):mn(e,t,r)}function Rt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),parsingLocale:t}}function mn(e,t,r){const{subject:n,effect:a}=dn[r];if(!t.hasVariable(e.variable))return[{code:"UNKNOWN_VARIABLE",message:`${n} references unknown variable '${e.variable}' — ${a}.`,context:{variableName:e.variable},suggestion:`Map '${e.variable}' in the layer or correct the variable name in the predicate.`}];const i=gn(e);return i!==null&&t.getType(e.variable)==="categorical"?[{code:"INVALID_PREDICATE_OPERATOR",message:`${n} uses ordering operator '${i}' on categorical variable '${e.variable}' — ${a}. Use 'eq' or 'oneOf' instead.`,context:{variableName:e.variable},suggestion:"Use 'eq' or 'oneOf' for categorical variables."}]:[]}function fn(e,t){if(!t.hasVariable(e.variable))return _;const r=t.createValueReader(e.variable),n=o.toExplicitValueFormat(t.getValueFormat(e.variable)),a=i=>o.parseAddressingValue(i,n,t.parsingLocale);if("eq"in e){const i=a(e.eq);return s=>o.areDataValuesEqual(r(s),i)}if("oneOf"in e){const i=e.oneOf.map(a);if(i.length>=32){const s=new Set,c=new Set;for(const l of i)o.isStrictTemporalDataValue(l)?c.add(l.getTime()):s.add(l);return l=>{const u=r(l);return o.isStrictTemporalDataValue(u)?c.has(u.getTime()):!Number.isNaN(u)&&s.has(u)}}return s=>{const c=r(s);for(const l of i)if(o.areDataValuesEqual(c,l))return!0;return!1}}if("lt"in e){const i=a(e.lt);return s=>j(r(s),i)==="less"}if("lte"in e){const i=a(e.lte);return s=>{const c=j(r(s),i);return c==="less"||c==="equal"}}if("gt"in e){const i=a(e.gt);return s=>j(r(s),i)==="greater"}if("gte"in e){const i=a(e.gte);return s=>{const c=j(r(s),i);return c==="greater"||c==="equal"}}if("range"in e){const[i,s]=e.range,c=a(i),l=a(s);return u=>{const d=r(u),p=j(d,c),f=j(d,l);return p==="incomparable"||f==="incomparable"?!1:(p==="greater"||p==="equal")&&(f==="less"||f==="equal")}}return _}function gn(e){for(const t of un)if(t in e)return t;return null}function j(e,t){if(e===null||t===null)return"incomparable";if(o.isStrictTemporalDataValue(e)&&o.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return o.isStrictNumericDataValue(e)&&o.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var hn=(e,t,r,n,a,i,s)=>{const c=kt(e,t,r.predicate,n,a,i,s);if(c===null)return null;const l=Mt(r.padding),u=l===null?bn(c,r.padding):c,d={x:u.xMin,y:u.yMin,width:Math.max(0,u.xMax-u.xMin),height:Math.max(0,u.yMax-u.yMin),space:u.space};return l===null?d:{...d,defer:l}},yn=(e,t,r,n,a,i,s)=>{const c=kt(e,t,r.predicate,n,a,i,s);return c===null?null:{...o.alignToBoxPoint(c,r.align),space:c.space}},Mt=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},kt=(e,t,r,n,a,i,s)=>{if(t.has(r))return t.get(r)??null;let c=null,l=!1;const u=new Map;for(const d of n){if(!d.interactive)continue;const p=R(r,d.data,"selection-anchor");if(p.length>0){for(const h of p)u.set(`${h.code}:${h.message}`,h);continue}l=!0;const f=N(r,pe(d,i));if(f!==_)for(const h of d.data){if(!f(h))continue;const m=o.readObservationBox(h,a);m!==null&&(c=c===null?m:vn(c,m))}}if(!l)for(const d of u.values())s?s.push(d):e.diagnostics.addWarning(d);return t.set(r,c),c},vn=(e,t)=>({space:e.space,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),bn=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},oe=(e,t,r)=>{const n=An(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Tn(n,t.offset,e.coordSystem)},Bt=(e,t)=>t.anchorType==="selection"?hn(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale,e.warnings):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotation-ref",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},De=(e,t,r)=>Te(e,t,r)?.point??null,Te=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const c=e.geomRegistry.get(s.geom),{resolveAnchorPosition:l}=c;if(l===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=Pt(s,c),d=Dt(s),p=Lt(s),f=At(s,n)(a);let h=-1;for(const m of s.data){if(h+=1,!d(m,f))continue;const v=l(m,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(v===null)continue;const y=$t(s,m,u);if(y===null)continue;const g=p(m);if(g!==null)return{point:{...v,...y,space:Et(r),observationIndex:h,anchor:a.align===void 0?g:{...g,align:a.align}},layerId:s.id}}}return null},Sn=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,c=a.y;if(s===void 0||c===void 0||s.kind!=="position"||c.kind!=="position")return null;const l=Qe(t.x,"x",r,i),u=Qe(t.y,"y",r,i);if(l===null||u===null)return null;const d=s.map(l),p=c.map(u);if(!o.isPointWithinPanel(d,p))return null;const f=Je(d,s,In(e)),h=Je(p,c),m=Ae(n.mainAxis,{main:f.min,cross:h.min}),v=Ae(n.mainAxis,{main:f.max,cross:h.max});return o.alignToBoxPoint({xMin:m.x,xMax:v.x,yMin:m.y,yMax:v.y},t.align??"center")},$t=(e,t,r)=>{const n=r.read(t);return o.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:rn(r.valueFormat,t),yScaleType:e.yScaleType}:null},An=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Sn(e,t);case"selection":return yn(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale,e.warnings);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return De(e,En(t),r)}},Tn=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Mt(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Je=(e,t,r=1)=>{const{bandwidth:n}=t;if(n===null||n<=0)return{min:e,max:e};const a=n*r/2;return{min:e-a,max:e+a}},In=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},En=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Qe=(e,t,r,n)=>{for(const a of r){const i=o.readVariableName(a.mapping[t]);if(!(i===null||i===o.CONSTANT_VARIABLES.x))return o.parseAddressingValue(e,o.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Vn=class extends o.Stage{constructor(e){super(),this.container=e,this.warningsByOutput=new WeakMap}compile(e){const t=super.compile(e);for(const r of this.warningsByOutput.get(t)??[])this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s=[],c={container:this.container,warnings:s,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},l={differenceArrows:Mn(c,t.differenceArrows),shapes:Ln(c,t.shapes),arrows:_n(c,t.arrows),textAnnotations:Pn(c,t.textAnnotations),images:Cn(c,t.images),stickers:Dn(c,t.stickers),pinnedNumbers:Nn(c,t.pinnedNumbers),comments:Rn(c,t.comments)};return xn(s,l),On(s,l),this.warningsByOutput.set(l,s),l}},L=(e,t,r,n)=>{e.push({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},xn=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.push({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation carries id "${a}" — references to it resolve to the first, and the rest cannot be addressed.`,context:{annotationId:a},suggestion:"Give each annotation its own id."});continue}r.add(a)}},On=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const a of n)r.add(a.id);for(const{id:n,ref:a}of wn(t))r.has(a)||e.push({code:"ANNOTATION_REF_NOT_FOUND",message:`Annotation "${n}" references id "${a}", whose annotation could not be anchored and was dropped.`,context:{annotationId:n,ref:a},suggestion:"Fix the anchor on the target annotation or point this reference at one that resolves."})},wn=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotation-ref"&&t.push({id:n,ref:a.defer.ref})};for(const n of e.shapes)r(n.id,n.region);for(const n of e.images)r(n.id,n.region);for(const n of e.arrows)r(n.id,n.start),r(n.id,n.end);for(const n of e.textAnnotations)r(n.id,n.at);for(const n of e.stickers)r(n.id,n.at);return t},Ln=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.region);if(a===null){L(e.warnings,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},Cn=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.region);if(a===null){L(e.warnings,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},_n=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.start,"pin"),i=oe(e,n.end,"pin");if(a===null||i===null){L(e.warnings,"arrow",n.id,`has ${Ut(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Pn=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.at,"pin");if(a===null){L(e.warnings,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},Dn=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.at,"pin");if(a===null){L(e.warnings,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Nn=(e,t)=>{const r=[];for(const n of t){const a=De(e,n.at,"pin");if(a===null){L(e.warnings,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Rn=(e,t)=>{const r=[];for(const n of t){const a=De(e,n.at,"pin");if(a===null){L(e.warnings,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Mn=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)L(e.warnings,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Te(e,n.start,"value"),i=Te(e,n.end,"value");if(a===null||i===null){L(e.warnings,"differenceArrow",n.id,`has ${Ut(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){L(e.warnings,"differenceArrow",n.id,"has both ends on the same observation");continue}kn(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ut=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",kn=(e,t,r,n)=>{St(r,n)||e.warnings.push({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:be(r),actual:be(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Bn(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,c]of r)c.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Ft(i),values:i};return new o.Dataset(n)}function Ft(e){const t=Array.isArray(e)?e:[e];for(const r of t)if(r!==null)return typeof r=="number"?"numeric":r instanceof Date?"temporal":"categorical";return"categorical"}var $n=class extends o.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(o.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:o.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){if(o.isVisualScale(n))continue;const a=o.readConstantValue(r[n]);if(a===void 0)continue;const i=o.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Ft(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},B=class{constructor(){this.perLayerMemo=o.createPerKeyMemo(),this.listMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},Un=class extends o.Stage{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)}},Fn=class extends B{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,t){const[r]=this.registry.get(t.coordSpec.coordType).transform({coordSpec:t.coordSpec,coordSystem:t.coordSystem,layers:[e]});if(!r)throw new o.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},jn=class{constructor(e){this.setupStage=new Un(e),this.transformStage=new Fn(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)}},Gn=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new o.InternalError({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}},Kn=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new o.InternalError({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:zn(e.scales,e.layers)}}transform(e){return e.layers.map(t=>qn(t))}},Yn=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax]],Ze=o.prefixInternalVariable("flipSwap"),zn=(e,t)=>Wn(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Wn=e=>{for(const t of e){const r=o.readVariableName(t.mapping.x);if(!r||!t.data.hasVariable(r))continue;const n=t.data.getType(r);if(n==="categorical"||n==="temporal")return!0}return!1},qn=e=>{let t=e.data;for(const[r,n]of Yn){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ze).renameVariable(n,r).renameVariable(Ze,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function jt(e){const t=new Set,r=[];for(const n of e){const a=n instanceof Date?n.getTime():String(n);t.has(a)||(t.add(a),r.push(n))}return r}var Gt=(e,t)=>jt(t.domain!==null&&t.domain.length>0?t.domain:e),Hn=e=>{const t=e.length-1,r=e[t];if(r===void 0||t<1)return null;const n=[];for(let i=1;i<=t;i+=1){const s=e[i-1],c=e[i];s===void 0||c===void 0||n.push(c-s)}n.sort((i,s)=>i-s);const a=n[n.length-1>>1];return a===void 0?null:r+a},Xn=e=>[...new Set(e)].sort((t,r)=>t-r),Jn=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=ra(t,e.scales,e.layers),a=aa(t,e.scales,e.layers);return{coordSystem:{type:"polar",axisMapping:t.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:t.innerRadius,startAngle:r,spokeRotation:n,bandAxis:a},scales:ea(t,e.scales,e.layers)}}transform(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new o.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=Zn(r,n),i=ia(t);return e.layers.map(s=>oa(t.theta==="y"?sa(s):s,a,i))}},Qn=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax]];function Zn(e,t){return r=>o.positionToAngle(r,e,t)}function ea(e,t,r){return e.theta!=="x"?t:t.map(n=>{if(n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"||n.scaleType==="continuous"&&n.transform!=="linear"||n.domainMax!==null)return n;const a=ta(e,r),i=Hn(a),s=a[0];return i===null||s===void 0?n:{...n,domainMin:n.domainMin??s,domainMax:i}})}function ta(e,t){const r=[];for(const n of t){const a=o.readVariableName(n.mapping[e.theta]);if(!(a===null||!n.data.hasVariable(a)))for(const i of n.data.getValues(a))i instanceof Date?r.push(i.getTime()):typeof i=="number"&&r.push(i)}return Xn(r)}function ra(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=na(n,e,r);return a===0?0:-Math.PI/a}function na(e,t,r){const n=[];for(const a of r){const i=o.readVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Gt(n,e).length}function aa(e,t,r){if(e.theta==="x")return"x";const n=t.find(i=>i.scaledAesthetic==="x")?.scaleType==="discrete",a=r.some(i=>i.position==="fill");return n&&!a?"y":null}function ia(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function oa(e,t,r){let n=e.data;return n=G(n,o.POSITION_VARIABLES.x,t),n=G(n,o.POSITION_VARIABLES.xMin,t),n=G(n,o.POSITION_VARIABLES.xMax,t),n=G(n,o.POSITION_VARIABLES.y,r),n=G(n,o.POSITION_VARIABLES.yMin,r),n=G(n,o.POSITION_VARIABLES.yMax,r),{...e,data:n}}function G(e,t,r){if(!e.hasVariable(t))return e;const n=e.getValues(t,{type:"numeric"}).map(a=>a===null?null:r(a));return e.addVariable(t,"numeric",n)}function sa(e){let t=e.data;for(const[r,n]of Qn){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,c=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),c&&(t=t.addVariable(r,"numeric",c))}return{...e,data:t}}var ca=class extends o.Registry{constructor(){super("coord"),this.register("cartesian",new Gn),this.register("flip",new Kn),this.register("polar",new Jn)}},la=class{constructor(e){this.container=e}compile(e,t){const r=this.container.geomRegistry.get(e),n=r.compile(t),a={...t.mapping,...n.mapping};return{...n,data:o.fillIntervalAesthetics(n.data,r.positionRoles,a)}}},ua=class{compute({data:e,mapping:t}){const r=o.getGroupVariables(e,t);if(r.length===0)return{data:e.addConstantVariable(o.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=o.getStableKey(a.map(c=>c[s]));return{data:e.addVariable(o.GROUP_VARIABLES.group,"categorical",i)}}},da=e=>{if(e===void 0)return{};const t={};for(const r of e.columns)r.label!==void 0&&(t[r.key]=r.label);return t},pa=(e,t,r)=>{const n=M(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function M(e,t){const r=o.getAestheticFromScaleAestheticKey(t);let n=null;for(const a of Kt(t,e)){const i=o.readVariableName(a.mapping[r]);if(o.isDefined(i)){if(o.isInternalVariable(i)){n??=i;continue}return i}}return n}var Ne=(e,t)=>e===null?null:t[e]??e,ma=(e,t)=>e===null?null:t[String(e)]??null,k=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return he(t);for(const n of e){if(!n.data.hasVariable(r))continue;const a=n.data.getValueFormat(r),i=a.type==="lookup"?a.fallback:a;return ga(i,t)?i:he(t)}return he(t)},fa=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Kt(t,e).some(r=>r.position==="fill");function Kt(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var he=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},ga=(e,t)=>{switch(t){case"continuous":return o.isNumericValueFormat(e);case"datetime":return o.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},ha=[{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}],et={year:0,quarter:1,month:2,week:3,day:4,hour:5},K=40,ya=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Aa(r.unit).range(e,new Date(t.valueOf()+1),n)},va=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jr.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>K;case"day":return a/t>K;case"week":return a/(7*t)>K;case"month":return a/(30*t)>K;case"quarter":return a/(90*t)>K;case"year":return a/(365*t)>K}},ba=(e,t)=>{const r=!o.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"month_year"}:{type:"month"};case"week":return r?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return r?{type:"date"}:{type:"day_month"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Sa=(e,t)=>{const r=Ta(t);return r===null?!1:et[e]>et[r]},Aa=e=>{switch(e){case"hour":return q.utcHour;case"day":return q.utcDay;case"week":return q.utcMonday;case"month":case"quarter":return q.utcMonth;case"year":return q.utcYear}},Ta=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}},Yt={left:"right",right:"left",top:"bottom",bottom:"top"},Ia={x:!0,y:!0,ySecondary:!1},Ea=20,tt=new Set(["top","bottom"]),Va={type:"percentage"};function xa(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:c}=e;if(Ct(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const l=La(c,a,i.type,n),u=new Set(t.map(f=>f.position)),d=_a(zt(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const f of o.SCALED_POSITION_AESTHETIC_KEYS){const h=r[f];if(!o.isDefined(h)||h.kind!=="position")continue;const m=Oa({scaleAestheticKey:f,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:l,variableLabels:s});p.push(m)}return p}function Oa(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:c,variableLabels:l}=e,{axisConfig:u,position:d,geometry:p}=Ca(t,n,i,s),f=M(a,t),h=fa(a,t)?Va:k({layers:a,scaleType:r.spec.scaleType,variableName:f});return{scaleAestheticKey:t,position:d,geometry:p,label:wa(u,f,l),isVisible:u.isVisible,tickCandidates:Da(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Pa(u,c,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function wa(e,t,r){return e.label?e.label:t?r[t]??null:null}function La(e,t,r,n){const a=t.flatMap(c=>{const l=e.get(c.geom).grid[r];return l?[l]:[]}),i=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY);return{x:{gridVisible:rt(i,n.axes.x.grid.isVisible)},y:{gridVisible:rt(s,n.axes.y.grid.isVisible)}}}function rt(e,t){if(e&&t===null)return!1}function Ca(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:zt(t.axes[e].position,r[e].position),geometry:r.x.geometry};case"y":return{axisConfig:t.axes[e],position:n,geometry:r.y.geometry};case"ySecondary":{const a=Yt[n],i=(0,ce.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:i,position:i.position,geometry:r.y.geometry}}}}function zt(e,t){return tt.has(e)===tt.has(t)?e:t}function _a(e,t){return t.has(e)?Yt[e]:e}function Pa(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Ia[r]}var Da=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Ra(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Ea;s++){const c=e.generateTicks({count:s}),l=o.getStableKey(c);a.has(l)||(a.add(l),i.push({ticks:c.map(u=>z(e,u))}))}return i}return e.spec.scaleType==="datetime"?Na(e,t):[{ticks:e.generateTicks().map(a=>z(e,a))}]},Na=(e,t)=>{const[r,n]=e.domain;if(!o.isStrictTemporalDataValue(r)||!o.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(c=>z(e,c))}];const a=new Set,i=[],s=(c,l)=>{if(c.length===0)return;const u=o.getStableKey(c);a.has(u)||(a.add(u),i.push({ticks:c.map(d=>z(e,d)),valueFormat:l}))};for(const c of ha)va({...c,start:r,stop:n})||Sa(c.unit,t)||s(e.generateTicks({interval:c}),ba(c,t));return s(e.generateTicks({atInputs:!0})),i.sort((c,l)=>c.ticks.length-l.ticks.length),i},Ra=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!o.isDefined(r)||!o.isDefined(n)||o.getStableKey([r])===o.getStableKey([n])?null:{ticks:[z(e,r),z(e,n)]}},z=(e,t)=>({value:t,position:e.map(t)});function Wt({scale:e,aesthetics:t,layers:r}){const n=Ma({layers:r,aesthetics:t}),a=qt({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Ma({layers:e,aesthetics:t}){const r=qt({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>o.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function qt({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(l=>o.isDefined(i.mapping[l]));if(s===void 0)continue;const c=o.readVariableName(i.mapping[s]);if(!(c===null||!i.data.hasVariable(c)))for(const l of i.data.getValues(c,{distinct:!0})){const u=o.getStableKey(l);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(o.getStableKey(a))}var Re=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function ka({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!Re(n))return[];if(!t.some(c=>o.isDefined(c.mapping.color)))return[];const a=M(t,"color");if(Ht({colorVariableName:a,xVariableName:M(t,"x"),mapsColorAcrossMultipleLayers:$a(t)>1,isMergedWithAnotherAesthetic:Ba(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(c=>o.isDefined(c.mapping.color));return Wt({scale:n,aesthetics:["color"],layers:t}).map(({value:c,geom:l,owner:u})=>{const d=u?.layerIndex??s,p=t[d],f=p?o.readVariableName(p.mapping.color):null;return{value:c,color:String(n.map(c)),geom:l,layerIndex:d,valueFormat:k({layers:p?[p]:t,scaleType:i,variableName:f}),label:ma(c,r)}})}var Ht=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||o.isInternalVariable(e)?!r:t!==null&&e===t;function Ba(e,t,r){if(r===null)return!1;for(const n of o.SCALED_VISUAL_AESTHETIC_KEYS){if(n==="color")continue;const a=e[n];if(!(a===void 0||!Re(a))&&M(t,n)===r)return!0}return!1}var $a=e=>e.filter(t=>o.isDefined(t.mapping.color)).length;function Xt(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Ua(e,t,r,n){const a=r.findIndex(i=>Xt(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Ne(o.readVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function nt(e,t,r){if(r===null||t===null)return[...e];const n=o.getStableKey(r);return e.filter((a,i)=>o.getStableKey(t[i]??null)===n)}var Jt=e=>e==="none"?"first":e,Fa=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=at(e);return n===0?null:r}case"average":{const{sum:r,count:n}=at(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},ja=(e,t)=>{if(e.length<2)return null;const r=e.at(-1),n=t==="previous"?e.at(-2):e.at(0);return r===void 0||n===void 0||r.cross===null||n.cross===null||n.cross===0?null:{variation:(r.cross-n.cross)/n.cross,against:n.main}},at=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Ga(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Ka(e,n):Ya(e,n)}function Ka(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=o.readVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:k({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Ya(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:c}=e;if(!a.some(d=>Xt(c,d)))return null;const l=Ua(c,s,a,i);if(l.length===0)return null;const u=l.map(d=>za({group:d,show:t,compareWith:r.headline.compareWith,layers:a,scales:n})).filter(d=>d!==null);return u.length===0?null:{kind:"perGroup",items:u}}function za({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=o.readVariableName(i.mapping.y);if(s===null||i.data.getType(s)!=="numeric"||t==="total"&&i.position==="fill")return null;const c=o.readVariableName(i.mapping.x),l=o.readVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=k({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),p=Ha(i.data,c),f=k({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:c}),h=Xa(i.data,c),m=h.getValues(s,{type:"numeric"}),v=c!==null?h.getValues(c):[],y=l!==null?h.getValues(l):null,g=nt(m,y,e.value),b=nt(v,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Fa(g,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:f,label:e.label,caption:Wa(t,p,b),comparison:qa(t,r,p,b,g)}}function Wa(e,t,r){if(e==="current"){const i=r.at(-1);return i===void 0?null:{kind:"point",value:i}}if(!t)return null;const n=r.at(0),a=r.at(-1);return n===void 0||a===void 0?null:{kind:"range",from:n,to:a}}function qa(e,t,r,n,a){return e!=="current"||!r?null:ja(n.map((i,s)=>({main:i,cross:a[s]??null})),Jt(t))}function Ha(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Xa(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function Ja(e,...t){return e?t.includes(e.geom):!1}function Qa(e,t){return e.find(r=>r.id===t)}function Za(e,...t){return e.find(r=>t.includes(r.geom))}function ei(e,...t){return e.filter(r=>t.includes(r.geom))}function Qt(e,t){return e.interactive?!1:t.some(r=>r!==e&&o.areMappingsEquivalent(r.mapping,e.mapping))}function ti(e,t){return t.filter(r=>r!==e&&!r.interactive&&o.areMappingsEquivalent(e.mapping,r.mapping))}function Me(e){const t=e.filter(r=>!Qt(r,e));return t.length>0?t:e}function Zt({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Me(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var ri=3;function ni({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const c=new Map(i.map(y=>[o.getStableKey(y.value),y])),l=di(si({scales:e,layers:r})),u=M(r,"x"),d=l.map(y=>{if(li(y,u,r))return null;const g=mi({group:y,variableLabels:a,layers:r,colorGroupsByValue:c});return g.items.length===0?null:{group:y,built:g}}).filter(o.isDefined),p=ai(d),f=Me(r),h=bi(s,t.legend.position,p,f,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&vi(s,p,f,n))return{drawn:[],position:h};const m=Si(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),v=m==="direct"?Ei(f[0]):null;return{drawn:d.map(({built:y})=>ii(y,{position:h,display:m,align:t.legend.align},v)),position:h}}function ai(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function ii(e,t,r){const{position:n,display:a}=t,i=oi(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function oi(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function si(e){const{scales:t,layers:r}=e,n=[];for(const a of o.SCALED_VISUAL_AESTHETIC_KEYS){const i=t[a];if(i===void 0||i.kind==="identity"||!ci(a,r))continue;const s=M(r,a),c=Ii(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:c})}return n}function ci(e,t){const r=o.getAestheticFromScaleAestheticKey(e);return t.some(n=>o.isDefined(n.mapping[r]))}function li(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Ht({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:ui(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function ui(e,t){const r=o.getAestheticFromScaleAestheticKey(e);return t.filter(n=>o.isDefined(n.mapping[r])).length>1}function di(e){const t=new Map;for(const r of e){const n=Ti(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function pi(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function mi({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>o.getAestheticFromScaleAestheticKey(u.scaleAestheticKey)),s=Wt({scale:a.scale,aesthetics:i,layers:r}),c=k({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),l=r.find(u=>i.some(d=>o.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:Ne(a.variableName,t),items:s.map(u=>fi(u,e,i,c,n,l))}}function fi(e,t,r,n,a,i){const s={};for(const l of t)pi(s,l.scaleAestheticKey,l.scale.map(e.value));if(s.color===void 0&&r.includes("size")&&(s.color=o.DEFAULT_GEOM_COLOR),s.lineType===void 0){const l=o.readConstantValue(e.owner?.layer.mapping.lineType);o.isLineType(l)&&(s.lineType=l)}const c=hi(e,t,r,n,a);return{value:e.value,label:gi(t,e,a),visual:s,normalizedY:null,geom:e.geom,valueFormat:c,layerId:e.owner?.layer.id??i}}function gi(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(o.getStableKey(t.value))?.label??null}function hi(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(o.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=yi(i,r);return i===void 0||s===null?n:k({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function yi(e,t){if(e===void 0)return null;for(const r of t){const n=e.mapping[r];if(n===void 0)continue;const a=o.readVariableName(n);if(a!==null)return a}return null}function vi(e,t,r,n){if(t>1)return!1;const a=n.type==="polar";return r.some(i=>e.get(i.geom).legend.suppressWhenSingleItem||a)}function bi(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,c=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,o.isStackedPosition(u.position)&&(c=!0))}const l=r>=ri;return i&&s?"top":i?l?"right":"top":c?Ai(a)?"top":l?"right":"top":"top"}function Si(e,t){return e==="pill"?"pill":Zt(t)?"direct":"pill"}function Ai(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Ti(e){const t=e.scale.domain.map(o.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Ii(e,t){return Re(t)?"discrete":`continuous:${e}`}function Ei(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(o.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(l=>o.isDefined(o.getYMax(l))||o.isDefined(o.getY(l)));if(!n)return;const a=Z(n);if(!o.isDefined(a))return;const i=o.getYMin(n),s=o.getYMax(n)??o.getY(n);if(!o.isDefined(s))return;const c=o.isDefined(i)?(i+s)/2:s;t.set(String(a),c)}),t}var Vi=class extends o.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config.axes,e.config.legend,e.config.headline,e.layers,e.coordSystem,e.originalData]}run(e){const t=da(e.originalData),r=ka({scales:e.scales,layers:e.layers,valueLabels:pa(e.originalData,e.layers,t)}),n={scales:e.scales,config:e.config,layers:e.layers,coordSystem:e.coordSystem,variableLabels:t,colorGroups:r,geomRegistry:this.container.geomRegistry},a=Ga(n),i=ni(n),s={...i,drawn:xi(a,i.drawn)};return{axes:xa(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},xi=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Ie=(e,t,r)=>{switch(e){case"series":return Oi(t);case"x-value":return ke(t,r)}},er=e=>{const t=o.readMainAxisVariable(e);return t===""?null:t},Oi=e=>o.getStableKey([Z(e)]),ke=(e,t)=>o.getStableKey([t!==null?e[t]??null:null]);function tr(e){return e===null?null:{strategy:e,composition:rr()}}function rr(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var wi=class extends B{constructor(e){super(),this.container=e,this.warningsByLayer=new WeakMap}compile(e){const t=super.compile(e);for(const r of t)for(const n of this.warningsByLayer.get(r)??[])this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,t){const r=e.highlight;if(r===null)return e;const n=t.highlights.filter(({layerId:c})=>c===void 0||c===e.id);if(n.length===0)return e;const a=[],i=Li({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,warnings:a}),s={...e,highlight:{...r,composition:i}};return this.warningsByLayer.set(s,a),s}};function Li({layer:e,highlights:t,parsingLocale:r,strategy:n,warnings:a}){const i=t.filter(S=>{const x=R(S.predicate,e.data);for(const O of x)a.push({...O,message:`${O.message} Dropping this highlight.`});return x.length===0}),s=er(e.mapping),c=pe(e,r),l=i.map(S=>({predicate:N(S.predicate,c),scope:S.scope})),u=l.some(({scope:S})=>S==="series"),d=l.some(({scope:S})=>S==="x-value"),p=n==="overlay-anchor",f=e.data.size(),h=u?new Array(f):null,m=d?new Array(f):null,v=p?new Array(f):null,y=new Uint8Array(f),g=new Set,b=new Set;let C=!1,T=0;for(const S of e.data){let x,O;h!==null&&(x=Ie("series",S,s),h[T]=x),m!==null&&(O=Ie("x-value",S,s),m[T]=O),v!==null&&(v[T]=S);for(const{predicate:re,scope:ne}of l)if(re(S))switch(ne){case"series":x!==void 0&&g.add(x);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":y[T]=1,C=!0;break}T++}if(g.size===0&&b.size===0&&!C)return rr();const E=new Uint8Array(f),W=[];let $=0;for(let S=0;S<f;S++){const x=h?.[S],O=m?.[S],re=x!==void 0&&g.has(x),ne=O!==void 0&&b.has(O),qe=y[S]===1;if(n==="observation-rerender")(re||qe||ne)&&(E[S]=1,$++);else if(re)E[S]=1,$++;else if(qe||ne){const He=v?.[S];He!==void 0&&W.push({observation:He,observationIndex:S})}}const U=$>0?{...e,data:e.data.filterByMask(E)}:null;return{isDimmed:(n==="observation-rerender"||g.size>0)&&U!==null,matchedLayer:U,overlayCandidates:W}}var Ci=o.prefixInternalVariable("__ungrouped__");function _i(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&o.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,c=i.map((l,u)=>{if(l===null)return null;const d=r[u]??Ci;let p=s.get(d);return p||(p=new o.ChronologicalDateManager,s.set(d,p)),p.incrementYearIfNeeded(l)});n=n.addVariable(a,"temporal",c)}return n}var nr=()=>({defaults:[],overrides:[],warnings:[],observation:{vocabulary:o.STYLE_TARGETS.geom.vocabulary,aesthetics:o.STYLE_TARGETS.geom.aesthetics},dashPresets:o.DASH_PRESETS.line,parts:{}}),Pi=class extends B{constructor(e,t,r,n,a,i){super(),this.container=e,this.transformCompiler=t,this.statCompiler=r,this.groupCompiler=n,this.geomCompiler=a,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,it(e),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},xScaleIsDiscrete:it(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=de({data:t,mapping:r}).pipe(({data:c,mapping:l})=>{const u=this.statCompiler.compute(e.stat,{data:c,mapping:l,xScaleIsDiscrete:n,params:{...e.params},requiredAesthetics:o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(e.geom))});return{data:u.data,mapping:u.mapping}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>({data:_i(c),mapping:l})).pipe(({data:c,mapping:l})=>{const u=this.geomCompiler.compile(e.geom,{data:c,mapping:l,params:e.params,coordType:a});return{data:u.data,mapping:{...l,...u.mapping}}}).pipe(({data:c,mapping:l})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:c,mapping:l});return{data:u.data,mapping:{...l,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,scaleConstraints:s.scaleConstraints,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:tr(s.highlightStrategy),styles:nr()}}};function it(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function ar(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new o.UserInputError(r)}}function Be(e,t){return t.map(r=>({...r,scaleConstraints:e.has(r.geom)?e.get(r.geom).scaleConstraints:void 0}))}function Di(e){return e.some(t=>o.isStackedPosition(t.position)||t.scaleConstraints?.bandPadding===0)}function $e(e){const t=ir(e),r={};for(const{layer:a,scaleConstraints:i,crossAxis:s}of t)i.zeroBaseline===!0&&(r[s]={nice:(r[s]?.nice??!0)&&a.position!=="fill"});const n=t.find(({scaleConstraints:a})=>a.discreteCrossAxis===!0);return{discreteAxis:t.some(({scaleConstraints:a})=>a.discreteMainAxis===!0)?"x":null,discreteCrossAxis:n?.crossAxis??null,bandedAxes:Ri(t),zeroAxes:r,bandPadding:Mi(t),inferredColor:t.some(({scaleConstraints:a})=>a.inferredColor===!0)}}function Ni(e){const t=ir(e);for(const r of t){if(r.scaleConstraints.discreteCrossAxis!==!0)continue;const n=t.find(a=>a.scaleConstraints.zeroBaseline===!0&&a.crossAxis===r.crossAxis);if(n!==void 0)return{crossAxis:r.crossAxis,banded:ot(r),zeroAnchored:ot(n)}}return null}var ot=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function ir(e){const t=[];return e.forEach((r,n)=>{const{scaleConstraints:a,yScaleType:i}=r;a!==void 0&&t.push({layer:r,index:n,scaleConstraints:a,crossAxis:o.resolveYScaleAesthetic(i)})}),t}function Ri(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.discreteMainAxis===!0&&t.add("x"),r.discreteCrossAxis===!0&&t.add(n);return[...t]}function Mi(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of ki(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function ki({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var Bi=new Set(["label","group"]),$i=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},s={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const c=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const l of c)this.container.diagnostics.addWarning(l)}),t.push(...this.validateSharedScaleDemands(e.layers)),ar(this.container.diagnostics,t)}checkPostCompile(e){Ct(e)&&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),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:c}=i;if(!c||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!o.hasMultipleGroups(r,t))return[];const l=s==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${s}' will render as '${l}'.`,context:{layerIndex:n,expected:l,actual:s},suggestion:`Use justify '${l}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],s=o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(r)),{computedVariables:c}=this.statRegistry.get(n.type);for(const l of s)c.has(l)||o.isDefined(a[l])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${l}'`,context:{layerIndex:t,aesthetic:l}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:c}=this.statRegistry.get(n.type),{derivedVariables:l}=this.container.geomRegistry.get(r),u=new Set(l);for(const[d,p]of Object.entries(a)){if(c.has(d))continue;const f=o.readVariableName(p);f===null||f===""||u.has(f)||i.hasVariable(f)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${d}' references variable '${f}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:d,variableName:f}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(n.type),l=[];for(const u of s){if(!o.POSITION_NUMERIC_ROLES.has(u.role)||!o.isDefined(u.aes)||c.has(u.aes)||u.role==="scalar"&&u.aes===u.axis)continue;const d=o.readVariableName(a[u.aes]);if(d===null||!i.hasVariable(d)||i.size()===0)continue;const p=i.getType(d);p!=="numeric"&&l.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${u.aes}' must be numeric, but variable '${d}' is ${p}`,context:{layerIndex:t,aesthetic:u.aes,variableName:d,variableType:p},suggestion:this.suggestNumericAestheticFix(u.aes,u.axis,a,i)})}return l}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=o.readVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(c=>({...c,message:`Layer '${e}': ${c.message}`,context:{...c.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Ni(Be(this.container.geomRegistry,e));if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(n.type),l=new Set([...o.deriveDeclaredAesthetics(i),...s.map(p=>p.name)]),u=Bi,d=[];for(const p of Object.keys(a))o.isDefined(a[p])&&(l.has(p)||u.has(p)||c.has(p)||d.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return d}},Ui=class extends o.Stat{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.x);if(!o.isDefined(r))throw new o.UserInputError({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(o.readVariableName(t.y)!==null)throw new o.UserInputError({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 n=[...new Set([r,...o.getGroupVariables(e,t)])];return{data:e.groupBy(...n).rollup({[o.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:o.STAT_VARIABLES.count}}}},Fi=class extends o.Stat{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},ji=class extends o.Stat{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({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."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const n=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'mean' stat requires a numeric 'y' (got '${n}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:n},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."})}return{data:e.size()===0?new o.Dataset({[o.STAT_VARIABLES.mean]:{type:"numeric",values:[]}}):e.rollup({[o.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:o.STAT_VARIABLES.mean}}}},Gi=2,or=1440*60*1e3,Ki=class extends o.Stat{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new o.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=o.readVariableName(t.x),i=o.readVariableName(t.y);if(!o.isDefined(a))throw new o.UserInputError({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(!o.isDefined(i))throw new o.UserInputError({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 s=e.getType(a),c=e.getType(i);if(e.size()>0&&c!=="numeric")throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:c}});const l=o.getGroupVariables(e,t),u=Ji(a,s,i,l,e);return l.length===0?st({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...l).forEach(d=>{const p=Qi(d,l);st({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},st=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:c})=>{const{observations:l,temporalOrigin:u}=Yi({data:e,xVariable:t,yVariable:n,xType:r});l.length<Gi||(c?Xi({observations:l,spec:a,output:i,groupObservation:s}):qi({observations:l,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},Yi=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?zi(a):null,c=[],l=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!o.isDefined(d)||!o.isDefined(p)||!Number.isFinite(p))continue;const f=Wi({xValue:d,xType:n,categoryRank:l,temporalOrigin:s});f!==null&&c.push({x:f,y:p,originalX:d})}return{observations:c,temporalOrigin:s}},zi=e=>{let t=null;for(const r of e){if(!o.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Wi=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!o.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!o.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/or+1}case"categorical":{if(!o.isStrictCategoricalDataValue(e))return null;const a=r.get(e);if(a!==void 0)return a;const i=r.size+1;return r.set(e,i),i}default:throw new o.InternalError({message:`Unexpected xType: ${t}`})}},qi=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=sr(n,e);for(const[c,l]of s){if(!Number.isFinite(c)||!Number.isFinite(l))continue;const u=t==="temporal"?Hi(c,r):c;a.push({x:u,y:l,groupObservation:i})}},Hi=(e,t)=>t===null?new Date(e):new Date((e-1)*or+t),Xi=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const c of e)a.has(c.x)||a.set(c.x,c.originalX);const i=[...a.keys()].sort((c,l)=>c-l);if(t.method==="loess"){const c=sr(t,e),l=new Map;for(const[u,d]of c)Number.isFinite(d)&&(l.has(u)||l.set(u,d));for(const u of i){const d=l.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const s=cr(t,e);for(const c of i){const l=a.get(c),u=s.predict(c);l===void 0||!Number.isFinite(u)||r.push({x:l,y:u,groupObservation:n})}},sr=(e,t)=>e.method==="loess"?(0,D.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):cr(e,t),cr=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,D.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,D.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,D.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,D.regressionQuad)().x(r).y(n)(t);case"power":return(0,D.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,D.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new o.InternalError({message:"'loess' does not expose a 'predict' function"})}},Ji=(e,t,r,n,a)=>{const i=[],s=[],c=Object.fromEntries(n.map(l=>[l,[]]));return{push:({x:l,y:u,groupObservation:d})=>{i.push(l),s.push(u);for(const p of n)c[p]?.push(d[p]??null)},build:()=>{const l={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)l[u]={type:a.getType(u),values:c[u]??[],valueFormat:a.getValueFormat(u)};return new o.Dataset(l)}}},Qi=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Zi=class extends o.Stat{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'sum' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const i=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'sum' stat requires a numeric 'y' (got '${i}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:i},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."})}const n=o.readVariableName(t.x),a=[...new Set([...n===null?[]:[n],...o.getGroupVariables(e,t)])];return{data:e.groupBy(...a).rollup({[o.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:o.STAT_VARIABLES.sum}}}},eo=[new Fi,new Ui,new Ki,new ji,new Zi],to=class extends o.Registry{constructor(){super("stat");for(const e of eo)this.register(e.type,e)}};function ro({geoms:e,stats:t,transforms:r}){const n=new o.GeomRegistry,a=new to,i=new o.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}var no=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},me=class{},ao=class extends me{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!o.readVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),i=io(e)??[-.7/2,.7/2],s=r.length>1?o.BAR_GROUP_SCALE_PADDING_FRACTION:0,c=(0,w.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),l=c.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const f=a[p];if(!o.isDefined(f))continue;const h=c(String(f));o.isDefined(h)&&(u[p]=h,d[p]=h+l)}return{data:e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",u).addVariable(o.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},io=e=>{const t=e.getConstant(o.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(o.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},ct=o.prefixInternalVariable("__ungrouped__"),lr=(e,t)=>{const r=o.readVariableName(t.x),n=o.readVariableName(t.y);if(!r||!n)return null;const a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[ct]:a,c=e.getValues(r),l=e.getValues(n,{type:"numeric"}),u=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let f=0;f<d;f++){const h=o.getStableKey(c[f]??null),m=u[f],v=i?ct:m;if(!o.isDefined(v))continue;let y=p.get(h);y||(y=new Map,p.set(h,y));let g=y.get(v);g||(g=[],y.set(v,g)),g.push(f)}return{yValues:l,observationIndicesByXAndGroup:p,uniqueGroupKeys:s,observationCount:d}},ur=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let c=-1,l=1/0,u=-1/0,d=-1,p=1/0,f=-1/0;for(const h of i.values())for(const m of h){const v=e[m],y=t[m];!o.isDefined(v)||!o.isDefined(y)||(s.push(m),(v<l||v===l&&y>u)&&(c=m,l=v,u=y),(y>f||y===f&&v<p)&&(d=m,p=v,f=y))}for(const h of s)a[h]=oo(h===c,h===d)}return a},oo=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",so=class extends me{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=lr(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,c=[...n],l=new Array(s).fill(0);for(const[,d]of a){let p=0,f=0;for(const v of i){const y=d.get(v);if(y!==void 0)for(const g of y){const b=n[g];b!=null&&(b>=0?p+=b:f-=b)}}let h=0,m=0;for(const v of i){const y=d.get(v);if(y!==void 0)for(const g of y){const b=n[g];if(b===void 0)continue;if(b===null){l[g]=null,c[g]=null;continue}const C=b>=0?p:f;if(C===0){l[g]=0,c[g]=0;continue}const T=b/C;b>=0?(l[g]=h,c[g]=h+=T):(c[g]=m,l[g]=m+=T)}}}const u=ur(l,c,a,s);return{data:e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",l).addVariable(o.POSITION_VARIABLES.yMax,"numeric",c).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(o.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},co=class extends me{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},lo=class extends me{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=lr(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,c=[...n],l=new Array(s).fill(0);for(const[,f]of a){let h=0,m=0;for(const v of i){const y=f.get(v);if(y!==void 0)for(const g of y){const b=n[g];if(b!==void 0){if(b===null){l[g]=null,c[g]=null;continue}b>=0?(l[g]=h,c[g]=h+=b):(c[g]=m,l[g]=m+=b)}}}}const u=ur(l,c,a,s);let d=e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",l).addVariable(o.POSITION_VARIABLES.yMax,"numeric",c).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(o.STACK_VARIABLES.role,"categorical",u);const p=o.readVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",c)),{data:d,mapping:{}}}},uo=class extends o.Registry{constructor(){super("position"),this.register("identity",new co),this.register("stack",new lo),this.register("fill",new so),this.register("dodge",new ao)}},po=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!o.isDefined(s.aes)||o.isVisualScale(s.aes))continue;const c=o.readVariableName(t.mapping[s.aes]);if(!o.isDefined(c)||!a.hasVariable(c))continue;const l=r(o.resolvePositionScaleAesthetic(s.axis,t.yScaleType));if(!l)continue;const u=a.getValues(c,{type:"numeric"}).map(d=>o.isDefined(d)?l.map(d):null);a=a.addVariable(o.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},mo=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.x,"numeric",i)}},fo=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=o.isDefined(n)&&e.hasVariable(o.POSITION_VARIABLES.x)?go(e,r,n):ho(e,r);return e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(o.POSITION_VARIABLES.xMax,"numeric",a.max)}};function go(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=dr(c);for(let u=0;u<c;u++){const d=n[u],p=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||(l.min[u]=d+(s?-f:p)*r,l.max[u]=d+(s?-p:f)*r)}return l}function ho(e,t){const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=dr(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function dr(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var yo=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.y),a=r(o.resolveYScaleAesthetic(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.y,"numeric",i)}},vo=class{map({data:e,layer:t,getPositionScale:r}){const n=r(o.resolveYScaleAesthetic(t.yScaleType));if(!n||!e.hasVariable(o.POSITION_VARIABLES.yMin)||!e.hasVariable(o.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=o.isDefined(a)&&e.hasVariable(o.POSITION_VARIABLES.y)?bo(e,n,a):So(e,n);return e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(o.POSITION_VARIABLES.yMax,"numeric",i.max)}};function bo(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=pr(c);for(let u=0;u<c;u++){const d=n[u],p=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||(l.min[u]=d+(s?-f:p)*r,l.max[u]=d+(s?-p:f)*r)}return l}function So(e,t){const r=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=pr(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function pr(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Ao=[new mo,new yo,new fo,new vo,new po];function To(e,t){const r=e[t];return r?.kind==="position"?r:null}var Io=class extends B{constructor(e,t=Ao){super(),this.container=e,this.mappers=t}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,t){const r=a=>To(t.scales,a);let n=e.data;for(const a of this.mappers)n=a.map({data:n,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:n}}},Eo=class extends o.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:Di(e.layers),zeroAxes:$e(e.layers).zeroAxes},a={};for(const[i,s]of t){const c=r.get(i)??[];a[i]=this.registry.get(s.scaleType).compile(s,c,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=o.getAestheticFromScaleAestheticKey(r.scaledAesthetic);for(const i of e.layers){if((r.scaledAesthetic==="y"||r.scaledAesthetic==="ySecondary")&&o.resolveYScaleAesthetic(i.yScaleType)!==r.scaledAesthetic||!o.isDefined(i.mapping[a]))continue;const s=o.readVariableName(i.mapping[a]);if(!o.isDefined(s)||o.isInternalVariable(s)||!i.data.hasVariable(s)||i.data.size()===0)continue;const c=i.data.getType(s);if(!n.includes(c)){const l=r.scaleType==="continuous"&&c==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${c})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}if(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.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${s}'. ${l}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}}}ar(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!o.isDefined(s))continue;const c=i==="y"?o.resolveYScaleAesthetic(n.yScaleType):i,l=a.get(i)??(o.isScaledAestheticKey(c)?c:void 0);if(!o.isDefined(l)||!t.has(l))continue;const u=t.get(l)?.scaleType,d=this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,l,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!o.isDefined(n.aes)||o.isVisualScale(n.aes)||t.set(n.aes,o.resolvePositionScaleAesthetic(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];const a=o.readVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(o.POSITION_VARIABLES.yMin)&&e.hasVariable(o.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Vo=["rgb","lab","hcl","hsl"],xo=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],mr=["RdBu","BrBG","PuOr","Spectral"],fr={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Oo=new Set(mr.map(e=>e.toLowerCase()));function gr(e){const t=e.toLowerCase(),r=fr[t];return r?r.toLowerCase():t}function wo(e){return Oo.has(gr(e))}var Lo={rgb:Y.interpolateRgb,lab:Y.interpolateLab,hcl:Y.interpolateHcl,hsl:Y.interpolateHsl},Co={viridis:A.interpolateViridis,magma:A.interpolateMagma,inferno:A.interpolateInferno,plasma:A.interpolatePlasma,cividis:A.interpolateCividis,turbo:A.interpolateTurbo,blues:A.interpolateBlues,greens:A.interpolateGreens,greys:A.interpolateGreys,oranges:A.interpolateOranges,purples:A.interpolatePurples,reds:A.interpolateReds,rdbu:A.interpolateRdBu,brbg:A.interpolateBrBG,puor:A.interpolatePuOr,spectral:A.interpolateSpectral};function Ue(e){const t=Po(e);return e.reverse?r=>t(1-r):t}function _o(e={},t=2){const r=Ue({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??o.CONTINUOUS_SCALE_DEFAULTS.interpolate,reverse:e.reverse??!1});return t<2?t===1?[r(0)]:[]:Array.from({length:t},(n,a)=>r(a/(t-1)))}function Po(e){const t=Lo[e.interpolate];if(e.range&&e.range.length>=2)return(0,Y.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Co[gr(e.scheme)];if(r)return r}return(0,Y.piecewise)(t,[...o.DEFAULT_SEQUENTIAL_RAMP])}var ee=class{createPositionScale(e,t){return{kind:"position",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,...t}}},Ee=(e,t,r)=>{const[n,a]=e;return t===0&&r===null&&a<=0?{domain:[n,0],pinnedLow:!1,pinnedHigh:!0}:r===0&&t===null&&n>=0?{domain:[0,a],pinnedLow:!0,pinnedHigh:!1}:{domain:[t??n,r??a],pinnedLow:t!==null,pinnedHigh:r!==null}};function Do(e){const[t,r]=e.domain;return t>0?{...e,domain:[0,r],pinnedLow:!0}:r<0?{...e,domain:[t,0],pinnedHigh:!0}:e}function Ve(e,t){return[t.pinnedLow?t.domain[0]:e[0],t.pinnedHigh?t.domain[1]:e[1]]}var No=class extends ee{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t,r){if(e.scaleType!=="continuous")throw new o.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const n=o.isPositionScale(e.scaledAesthetic),a=e.scaledAesthetic==="color",i=this.computeDataDomain(t);return a?this.buildColorScale(i,e):n?this.buildPositionScale(i,e,r.zeroAxes[e.scaledAesthetic]!==void 0):this.buildVisualScale(i,e)}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e)typeof n!="number"||!Number.isFinite(n)||(n<t&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}createD3Scale(e,t,r,n=!1){const a=Ee(e,r.domainMin,r.domainMax),i=n?Do(a):a;let s=i.domain;n&&Ro(a,i)&&this.warnIncompatibleDomain(r,a.domain,`'${r.scaledAesthetic}' holds zero for the geom drawn on it, so the pin at [${a.domain[0]}, ${a.domain[1]}] gives way to [${s[0]}, ${s[1]}].`,`Pin '${r.scaledAesthetic}' at or past zero, or drop the pin.`);const c=r.transform==="log"&&Mo(s);r.transform==="log"&&!c&&this.warnIncompatibleDomain(r,s,`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${s[0]}, ${s[1]}] — rendering a linear scale instead.`,n?`'${r.scaledAesthetic}' holds zero for the geom drawn on it; use a linear or sqrt transform.`:"Filter out non-positive values or set a positive domainMin so the log scale can apply.");const l=c?(0,w.scaleLog)():r.transform==="sqrt"?(0,w.scaleSqrt)():(0,w.scaleLinear)();return r.nice&&!c&&(s=Ve(l.copy().domain(s).nice().domain(),i)),l.domain(s).range(t).clamp(r.clamp)}warnIncompatibleDomain(e,t,r,n){this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:r,context:{aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),scaleType:e.scaleType,actual:t},suggestion:n})}buildPositionScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t,r);return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildVisualScale(e,t){const r=ko(t.range)??[0,1],n=t.reverse?[r[1],r[0]]:r,a=this.createD3Scale(e,n,t);return this.createVisualScale(t,{map:a,domain:a.domain(),generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildColorScale(e,t){const r=Ue(t),n=t.domainMid;if(n!==null){const a=this.resolveColorDomain(e,t),[i,s]=a.domain;if(n>i&&n<s){const[c,l]=this.symmetrizeDomain(a,t,n);return this.buildDivergingColorScale([c,n,l],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,w.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){const r=Ee(e,t.domainMin,t.domainMax);if(!t.nice)return r;const n=(0,w.scaleLinear)().domain(r.domain).nice().domain();return{...r,domain:Ve(n,r)}}symmetrizeDomain(e,t,r){const{domain:n,pinnedLow:a,pinnedHigh:i}=e;if(!t.symmetric)return n;const s=Math.max(Math.abs(n[0]-r),Math.abs(n[1]-r));return[a?n[0]:r-s,i?n[1]:r+s]}},Ro=(e,t)=>e.pinnedLow&&e.domain[0]!==t.domain[0]||e.pinnedHigh&&e.domain[1]!==t.domain[1],Mo=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function ko(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Bo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new o.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=o.isPositionScale(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new o.UserInputError({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(n,e,this.collectInputDates(t))}collectInputDates(e){const t=new Set,r=[];for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();t.has(a)||(t.add(a),r.push(n))}return r.sort((n,a)=>n.getTime()-a.getTime()),r}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();a<t&&(t=a),a>r&&(r=a)}return t===1/0?[]:[new Date(t),new Date(r)]}createD3Scale(e,t,r){const n=(0,w.scaleUtc)().range(t).clamp(r.clamp);if(!$o(e))return n.domain([]);const a=Ee([e[0].getTime(),e[1].getTime()],r.domainMin,r.domainMax);if(n.domain(a.domain),r.nice){const[i,s]=n.nice().domain();i!==void 0&&s!==void 0&&n.domain(Ve([i.getTime(),s.getTime()],a))}return n}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),c=i&&s?r.filter(l=>l>=i&&l<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&s?ya(i,s,l.interval):[]:a.ticks(l?.count)})}},$o=e=>e.length===2&&o.isStrictTemporalDataValue(e[0])&&o.isStrictTemporalDataValue(e[1]),Uo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new o.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=o.isPositionScale(e.scaledAesthetic),n=Gt(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??o.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,w.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:c=>(i(String(c))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,w.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},Fo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new o.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},jo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new o.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=jt(t),a=o.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=o.applyOverrides(a.length>0?a:[...o.DEFAULT_COLOR_PALETTE],e.overrides),s=(0,w.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:c=>s(String(c)),domain:n,generateTicks:()=>n})}},Go=class extends o.Registry{constructor(e){super("scale"),this.register("continuous",new No(e)),this.register("discrete",new Uo),this.register("datetime",new Bo),this.register("identity",new Fo),this.register("palette",new jo)}},hr={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ko={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Fe(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:$e(Be(e.geomRegistry,n))}}function fe(e,t){switch(t.scaleType){case"inferred":return{...fe(e,qo(e,t)),inferredFrom:t};case"continuous":{const r=hr[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in o.NON_POSITION_RANGE_DEFAULTS?o.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":o.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??o.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??o.CONTINUOUS_SCALE_DEFAULTS.nice,clamp:t.clamp??r!=="position",domainMin:t.domainMin??o.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??o.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:Ho(e.container,t),interpolate:t.interpolate??o.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??o.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??o.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??o.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??o.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??o.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??o.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return yr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:o.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:o.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new o.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Yo(e,t){const{scales:r,layers:n,coords:a}=t,i=Fe(e,t),s=Zo(Qo(r,n),i.demands),c=new Map;for(const u of s)c.set(u.scaledAesthetic,u);const l=[...c.values()].map(u=>{const d=zo(i,u);return fe(i,d)});return a.coordType==="polar"?l.map(je):l}function yr(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??o.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??o.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??r??o.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??Wo(e.scaledAesthetic,t)}}var je=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function zo(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),o.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Wo(e,t){return e===t?.discreteCrossAxis?!0:o.DISCRETE_SCALE_DEFAULTS.reverse}function qo({data:e,layers:t,mapping:r,demands:n},a){const i=Xo(t,r,a.scaledAesthetic);if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return o.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,...!s.nice&&{nice:!1}})}const c=o.readVariableName(i);if(!o.isDefined(c)||!e.hasVariable(c)||e.size()===0)return o.continuous(a.scaledAesthetic,a.options);const l=e.getType(c),u=hr[a.scaledAesthetic];switch(Ko[l][u]){case"discrete":return o.discrete(a.scaledAesthetic,a.options);case"palette":return o.palette(a.scaledAesthetic);case"datetime":return o.datetime(a.scaledAesthetic,a.options);case"continuous":return o.continuous(a.scaledAesthetic,a.options);default:return o.identity(a.scaledAesthetic)}}function Ho(e,t){const r=t.scheme??o.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:o.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!o.isDefined(t.domainMid)&&wo(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Xo(e,t,r){const n=o.getAestheticFromScaleAestheticKey(r);for(const a of Jo(r,e)){const i=a.mapping[n]??t[n];if(o.isDefined(o.readVariableName(i)))return i}return t[n]}function Jo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}function Qo(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,o.inferred("ySecondary")]}function Zo(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?o.inferred("color"):o.palette("color")]}var Ge=class extends o.Stage{constructor(e){super(),this.registry=e}key(e){return e.data}dependencies(e){return[e.transforms]}run(e){return e.transforms.reduce((t,r)=>this.registry.get(r.transformType).apply(t,r),e.data)}},vr=new o.TransformRegistry,es=new Ge(vr),br=(e,t)=>{const r=t.every(n=>vr.has(n.transformType));return t.length===0||!r?e:es.compile({data:e,transforms:t})},lt=0;function I(){return lt+=1,`${Math.random().toString(36).slice(2,6)}${lt.toString(36)}`}var ts={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},"top-left":{x:-1,y:-1},"top-right":{x:1,y:-1},"bottom-left":{x:-1,y:1},"bottom-right":{x:1,y:1}},rs=(e,t,r)=>{const n=ns(e,t),a=os(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>cs(e,i,r)).filter(o.isDefined),shapes:(n.shapes??[]).map(i=>ps(e,i,a)).filter(o.isDefined),arrows:(n.arrows??[]).map(i=>gs(e,i,r,a)).filter(o.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>ss(e,i,r,a)).filter(o.isDefined),stickers:(n.stickers??[]).map(i=>ls(e,i,r,a)).filter(o.isDefined),images:(n.images??[]).map(i=>ms(e,i,a)).filter(o.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>us(e,i,r)).filter(o.isDefined),comments:(n.comments??[]).map(i=>ds(e,i,r)).filter(o.isDefined)}},ns=(e,t)=>{if(t===void 0)return{};if(!as(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:I()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},as=e=>{const t=new Set;for(const r of is(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},is=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],os=e=>{const t=new Set,r=[e.differenceArrows,e.shapes,e.arrows,e.textAnnotations,e.images,e.stickers,e.pinnedNumbers,e.comments];for(const n of r)for(const a of n??[])a.id!==void 0&&t.add(a.id);return t},Ke=(e,t,r,n)=>{if(r.has(t))return!0;const a=n===void 0?"An annotation":`Annotation "${n}"`;return e.diagnostics.addWarning({code:"ANNOTATION_REF_NOT_FOUND",message:`${a} references id "${t}" but no annotation declares that id — dropping this annotation.`,context:{ref:t,...n!==void 0?{annotationId:n}:{}},suggestion:"Reference the explicit id of another annotation in the same spec, or set an id on the target."}),!1},ss=(e,t,r,n)=>{const a=se(e,t.at,r,n,t.id);return a===null?null:{id:t.id??I(),content:t.content,at:a,width:t.width,align:t.align??o.TEXT_ANNOTATION_DEFAULTS.align}},cs=(e,t,r)=>{const n=X(e,t.start,r),a=X(e,t.end,r);return n===null||a===null?null:{id:t.id??I(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??o.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},X=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},se=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return Ke(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=X(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},ls=(e,t,r,n)=>{const a=se(e,t.at,r,n,t.id);return a===null?null:{id:t.id??I(),at:a,sticker:t.sticker}},us=(e,t,r)=>{const n=X(e,t.at,r);return n===null?null:{id:t.id??I(),at:n}},ds=(e,t,r)=>{const n=X(e,t.at,r);return n===null?null:{id:t.id??I(),at:n,content:t.content}},ps=(e,t,r)=>t.region.anchorType==="annotation"&&!Ke(e,t.region.ref,r,t.id)?null:{id:t.id??I(),kind:t.kind??o.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??o.SHAPE_DEFAULTS.zOrder,region:fs(t.region)},ms=(e,t,r)=>t.region.anchorType==="annotation"&&!Ke(e,t.region.ref,r,t.id)?null:{id:t.id??I(),src:t.src,zOrder:t.zOrder??o.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??o.IMAGE_ANNOTATION_DEFAULTS.fit},fs=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:o.SELECTION_PADDING_DEFAULT},ut=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=ts[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},gs=(e,t,r,n)=>{const a=se(e,t.start,r,n,t.id),i=se(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??I(),start:ut(a),end:ut(i),startArrowheadStyle:t.startArrowheadStyle??o.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??o.ARROW_DEFAULTS.endArrowheadStyle}},hs={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"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:{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,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function ys(e){const t=(0,ce.merge)({},hs,e);return t.content=vs(t.content,e?.content),t}var vs=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},bs={xLimits:null,yLimits:null},ie={theta:"x",startAngle:0,innerRadius:0};function Sr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,ve.default)({},bs,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??ie.theta,startAngle:t.params?.startAngle??ie.startAngle,innerRadius:(0,ye.default)(t.params?.innerRadius??ie.innerRadius,0,1)}}}}function Ss(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??I(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var As=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"user-input"};t.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 t=dt(e.filter(n=>n.severity==="error")),r=dt(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Ts=class{constructor(e,t){this.sink=e,this.baseContext=t}addWarning(e,t){this.sink.addWarning(this.stampBaseContext(e),t)}addError(e){this.sink.addError(this.stampBaseContext(e))}stampBaseContext(e){const t=e.context??{};return{...e,context:{...t,...this.baseContext}}}};function dt(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Ar={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:o.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4},Is={stat:{type:"identity"},position:"identity",params:{}},Es={stat:{type:"identity"},position:"identity",params:{curve:"linear",missingValues:"gap"}},Vs={stat:{type:"identity"},position:"stack",params:{curve:"linear",missingValues:"zero"}},xs={stat:{type:"identity"},position:"dodge",params:{}},Os={stat:{type:"identity"},position:"identity",interactive:!1,params:{labelPosition:"start"}},ws={stat:{type:"identity"},position:"identity",params:{}};function Tr(e,t){const r=e??(typeof t=="string"?t:t.type),n=typeof r=="string"?r:r.type;if(n==="smooth"){const a=typeof r=="string"?void 0:r;return{type:"smooth",method:a?.method??"linear",order:a?.order??3,bandwidth:a?.bandwidth??.3}}return{type:n}}function Ir(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Ts(a,{layerIndex:i}):a,c=e.get(n.geom),l=n.position??c.defaultPosition,u=_s({dataLabels:Ds(e,t,n,l,r),geom:c,position:l,coordType:r,diagnostics:s});return Cs({diagnostics:s,coordType:r,geom:c,position:l,dataLabels:u}),{id:n.id??I(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Tr(n.stat,c.defaultStat??"identity"),position:l,yScaleType:n.yScaleType??"primary",params:c.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??c.defaultInteractive,dataLabels:u}}function Ls(e,t,r,n,a){const i=n.map((s,c)=>Ir(e,t,r,s,a,c));return Vr(e,i)}var Er=(e,t,r,n)=>n.label!==void 0?n.label:_t({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Vr=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:_e(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=o.readConstantValue(n.mapping.y);if(!o.isStrictNumericDataValue(a))return n;const i=(0,ce.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Cs=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&o.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},_s=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const c=Ps(t,r,n);if(c===null)return e;const l=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${c}; justify '${i}' will render as '${l}'.`,context:{expected:l,actual:i},suggestion:`Use justify '${l}' for this layer.`}),{...e,justify:l}},Ps=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&o.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Ds=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Er(e,r.geom,n,i),c=e.get(r.geom);return{...(0,ce.merge)({},Ar,c.resolveDataLabelDefaults?.(n)??{},c.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Ns=e=>{const t={tokens:{},defaults:[],overrides:[]};for(const r of Rs(e))Object.assign(t.tokens,r.tokens),t.defaults.push(...r.defaults??[]),t.overrides.push(...r.overrides??[]);return t},Rs=e=>{const t=[],r=new Set,n=e===void 0?[]:[e];for(;n.length>0;){const a=n.pop();if(!(a===void 0||r.has(a))){r.add(a),t.push(a);for(const i of a.extends??[])n.push(i)}}return t.reverse()};function Ms(e,t,r){const n=Sr(t.coords),a=Ls(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Yo(e,{data:br(t.data,t.transforms),scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=ys(t.config),c=Ss(e,t.highlights,a),l=rs(e,t.annotations,a),u=Ns(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:c,styles:u,annotations:l,coords:n,config:s}}var xr=class{constructor(e){this.container=e}compile({spec:e,dataset:t,customPalettes:r}){return Ms(this.container,{...e,data:t},r)}},ks=()=>{let e={},t=null;return{reset:()=>{e={}},getDuration:r=>e[r]??0,wrap:(r,n)=>a=>{const i=t,s={childrenMs:0};t=s;const c=performance.now();try{return n(a)}finally{const l=performance.now()-c;e[r]=(e[r]??0)+l-s.childrenMs,i&&(i.childrenMs+=l),t=i}}}},Bs=class{constructor(e){this.registry=e}compute(e,t){const r=this.registry.get(e.type),n=r.compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete,params:t.params});return Us(r,n,t.requiredAesthetics),{data:n.data,mapping:{...$s(t,n.data),...n.mapping}}}};function $s({data:e,mapping:t},r){const n={};for(const[a,i]of Object.entries(t)){const s=o.readVariableName(i);s!==null&&e.hasVariable(s)&&!r.hasVariable(s)||(n[a]=i)}return n}function Us(e,{data:t,mapping:r},n){for(const a of n){if(!e.computedVariables.has(a))continue;const i=r[a],s=o.readVariableName(i);if(!(o.isDefined(i)&&(s===null||t.hasVariable(s))))throw new o.UserInputError({code:"MISSING_STAT_OUTPUT",message:`Stat '${e.type}' declares it computes '${a}', which the layer's geom requires, but did not map it to a column of its output`,context:{aesthetic:a,requested:e.type},suggestion:`Return '${a}' in the stat's mapping, naming a column the stat writes.`})}}var Or=Object.keys(o.ANNOTATION_BUCKETS),Fs=e=>Object.hasOwn(o.ANNOTATION_BUCKETS,e),js=(e,t)=>{for(const r of Or){const n=Ks(e,r,t);if(n)return n}return null},Ye=(e,t)=>e[o.ANNOTATION_BUCKETS[t]],wr=(e,t,r)=>({...e,[o.ANNOTATION_BUCKETS[t]]:r}),Gs=(e,t)=>{const r=Ye(e,t.kind);return wr(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Ks=(e,t,r)=>{const n=Ye(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},pt=Object.freeze({light:"#898373",dark:"#9F9886"}),Ys={graphBackground:o.DEFAULT_GRAPH_BACKGROUND,graphBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),geom:o.DEFAULT_GEOM_COLOR,geomBorder:Object.freeze({light:"rgba(58, 56, 51, 0.55)",dark:"rgba(237, 231, 218, 0.55)"}),textPrimary:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),textSecondary:pt,ruleLine:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),gridLine:Object.freeze({light:"#E1DAC9",dark:"#373531"}),hoverAffordance:o.DEFAULT_HOVER_AFFORDANCE_COLOR,hoverGuideFill:Object.freeze({light:"#E7E1D2",dark:"#2B2A27"}),hoverGuideLine:Object.freeze({light:"#D5CDBA",dark:"#3B3934"}),editOutlineHover:Object.freeze({light:"#C4C4C4",dark:"rgba(255, 255, 255, 0.5)"}),editOutlineSelected:Object.freeze({light:"#3D70FF",dark:"#3D70FF"}),tooltipBackground:Object.freeze({light:"#FCFCF9",dark:"#262522"}),tooltipBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),tooltipPrimaryRow:Object.freeze({light:"#F5F1E9",dark:"#2E2C29"}),annotationShape:Object.freeze({light:"#3b82f6",dark:"#60a5fa"}),annotationArrow:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),differenceLabelBackground:o.DEFAULT_GRAPH_BACKGROUND,trendPositive:{light:"#06B299",dark:"#0AC600"},trendNegative:{light:"#E14B49",dark:"#CB3333"},trendNeutral:pt},zs=o.freezeWalkedEntries(o.walkStyleTargets()),J=Object.freeze({tokens:Object.freeze(Ys),defaults:Object.freeze(zs),overrides:Object.freeze([])}),Ws=class extends B{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const n of pc(e.styles,t))this.container.diagnostics.addWarning(n);for(const n of fc(e.styles))this.container.diagnostics.addWarning(n);const r=yc(this.container.geomRegistry);for(const n of r(e.styles))this.container.diagnostics.addWarning(n);for(const n of vc(e.styles))this.container.diagnostics.addWarning(n);for(const n of t)for(const a of n.styles.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=Cr({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale,styleTarget:_r(this.container.geomRegistry,e.geom)});return{...e,styles:r}}},qs=class extends o.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of mc(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Lr(e.styles)}},xe=new o.GeomRegistry,Hs=new Set(o.STYLE_PROPERTY_NAMES),Xs=new WeakMap,Js=new WeakMap,mt={stateless:0,dimmed:1,hovered:2},Lr=e=>{const t=[],r={...J.tokens,...e.tokens},n={...tc(),warnings:t},a=(i,s,c,l)=>{if(te(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target,p=rc(i.select);if(p.status==="unknown-target"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${[...ze].map(g=>`'${g}'`).join(", ")}.`});return}if(p.status==="unknown-partition"){const{key:g,value:b,node:C}=p,T=Oe(C,g);t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} addresses unknown ${g} '${b}'.`,context:{param:g,actual:b,...u},suggestion:T.length===0?`Remove '${g}' — this target has none.`:`Set '${g}' to one of ${T.map(E=>`'${E}'`).join(", ")}, or omit it.`});return}if(p.status==="namespace"){const g=Oe(p.node,"part");t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} ignored: ${i.select.target} entries need a part.`,context:{param:"part",actual:String(i.select.part),...u},suggestion:`Set 'part' to one of ${g.map(b=>`'${b}'`).join(", ")}.`});return}const f=p.node;if(i.when!==void 0&&!We(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const h=f.options??[],m=i.select;if(m.layer!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} does not take a layer.`,context:{param:"layer",actual:P(m.layer),...u},suggestion:"Remove 'layer' — this target is not layer-scoped."});return}if(m.annotation!==void 0){if(!h.includes("annotation")){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} does not take an annotation.`,context:{param:"annotation",actual:P(m.annotation),...u},suggestion:"Remove 'annotation' — this target is not annotation-scoped."});return}if(typeof m.annotation!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} addresses an invalid annotation ${P(m.annotation)}.`,context:{param:"annotation",actual:P(m.annotation),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}const v=$r({declarations:i.declarations,vocabulary:f.vocabulary,tokens:r,location:c,origin:l,warnings:t,entryTarget:i.select.target});if(Object.keys(v).length===0)return;const y=f.select.target;Pr(y)&&n[y][s].push({select:i.select,declarations:v,origin:l})};return J.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},Qs=e=>xe.has(e)?xe.get(e).styleTarget:void 0,Cr=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a,styleTarget:i}=e,s=pe(t,a),c=[],l={...J.tokens,...n.tokens},u=p=>p===t.geom?i:void 0,d=(p,f)=>{const h=[];return p.forEach((m,v)=>{if(!te(m))return;const y=m.select.kind;if(y!==void 0&&y!==t.geom||m.select.layer!==void 0&&m.select.layer!==t.id)return;const g=`${f}[${v}]`;if(Br(m,g,u)!==void 0)return;const b=m.when?.state;if(b!==void 0&&!kr(b))return;const C=m.id===void 0?{}:{styleEntryId:m.id},T={list:f,index:v,...m.id===void 0?{}:{id:m.id}},E=m.when?.where;if(E!==void 0){const U=R(E,t.data,"style-rule");if(U.length>0){for(const S of U)c.push({...S,code:"INVALID_STYLE_RULE",message:`Style ${g}: ${S.message}`,context:{...S.context,layerIndex:r,...C}});return}}const W=Mr({select:m.select,declarations:m.declarations,layerGeom:t.geom,styleTarget:i,tokens:l,location:g,origin:T,warnings:c});if(Object.keys(W).length===0)return;const{part:$}=m.select;h.push({declarations:W,...E===void 0?{}:{matches:N(E,s),where:E},...b===void 0?{}:{state:b},...$===void 0?{}:{part:$},origin:T})}),h};return{defaults:[...dc(t.geom,i,l,c),...d(n.defaults,"defaults")],overrides:d(n.overrides,"overrides"),warnings:c,...oc(t.geom,i),dashPresets:i?.observation?.dashPresets??o.DASH_PRESETS.line}},_r=(e,t)=>e.has(t)?e.get(t).styleTarget:void 0,Zs=e=>t=>_r(e,t),ec=()=>{const e=new Set,t=r=>{if(e.add(r.select.target),r.children!==void 0)for(const n of Object.values(r.children))t(n)};for(const r of Object.values(o.STYLE_TARGETS))t(r);return e},ze=ec(),Pr=e=>e!=="geom"&&ze.has(e),tc=()=>{const e={};for(const t of ze)Pr(t)&&(e[t]={defaults:[],overrides:[]});return e},Oe=(e,t)=>{if(e.children===void 0)return[];const r=[];for(const n of Object.values(e.children)){const a=n.select[t];a!==void 0&&r.push(a)}return r},ft=e=>Object.keys(e.vocabulary).length===0&&e.children!==void 0,rc=e=>{const t=o.findStyleTarget(e);if(t!==void 0)return ft(t)?{status:"namespace",node:t}:{status:"found",node:t};const r=o.findStyleTarget({target:e.target});if(r===void 0)return{status:"unknown-target"};let n=r;for(const a of o.STYLE_SELECT_KEYS){const i=e[a];if(i===void 0)continue;const s=n.children===void 0?void 0:Object.values(n.children).find(c=>c.select[a]===i);if(s===void 0)return{status:"unknown-partition",key:a,value:i,node:n};n=s}return ft(n)?{status:"namespace",node:n}:{status:"found",node:n}},We=e=>{const t=e.options??[];return t.includes("where")||t.includes("state")},nc=(e,t)=>{const r=e==="geom"?xe.getAll().find(n=>n.styleTarget!==void 0&&o.readObservationVocabulary(n.styleTarget)[t]!==void 0)?.type:e==="annotation"?Object.entries(o.STYLE_TARGETS.annotation.children).find(([,n])=>n.vocabulary[t]!==void 0)?.[0]:void 0;return r===void 0?void 0:`style.${e}.${r}`},te=e=>e.select.target==="geom",ac=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Dr=(e,t,r,n)=>{const a=e.get(r)??new Map;e.set(r,a);const i=a.get(t);if(i!==void 0)return i;const s=n();return a.set(t,s),s},Nr=(e,t)=>Dr(Xs,e,t,()=>o.createGeomStyleNode(e,t)),Q=(e,t)=>{const{kind:r,part:n}=e;if(r===void 0)return o.findStyleTarget({target:"geom",part:n});const a=t(r);if(a===void 0)return;const i=Nr(r,a);return n===void 0?i:ac(i.children,n)},ic=(e,t)=>{const r=Q(e,()=>t);return r===void 0||We(r)},Rr=(e,t)=>[e,t].filter(r=>r!==void 0).join(" "),oc=(e,t)=>{const r=Q({kind:e},()=>t),n={};for(const a of Object.values(r?.children??{}))a.select.part!==void 0&&(n[a.select.part]={vocabulary:a.vocabulary,aesthetics:a.aesthetics??{}});return{observation:{vocabulary:r?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,aesthetics:r?.aesthetics??o.STYLE_TARGETS.geom.aesthetics},parts:n}},gt=(e,t)=>Q(e,()=>t)?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,sc=(e,t)=>{const r={};for(const n of Object.keys(e)){const a=e[n];a===void 0||t[n]===void 0||(r[n]=a)}return r},Mr=e=>{const t=$r({declarations:e.declarations,vocabulary:gt(e.select,e.styleTarget),tokens:e.tokens,location:e.location,origin:e.origin,warnings:e.warnings,entryTarget:"geom"});return e.select.part!==void 0?t:sc(t,gt({kind:e.layerGeom},e.styleTarget))},cc=(e,t)=>Dr(Js,e,t,()=>o.freezeWalkedEntries(o.walkStyleTargets([Nr(e,t)]))),lc=(e,t)=>mt[e.state??"stateless"]-mt[t.state??"stateless"],uc=(e,t)=>t===void 0?`builtin ${e}`:`builtin ${e}.${t}`,dc=(e,t,r,n)=>{const a=[],i={list:"builtin"},s=(c,l,u,d)=>{if(c.kind!==void 0&&c.kind!==e)return;if(u!==void 0&&!ic(c,t)){const h=Rr(e,c.part);n.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: a ${h} entry takes no conditions.`,context:{param:"state",actual:u},suggestion:`Declare the ${u} paint on 'rest', or add 'state' to the part's options.`});return}const p=Mr({select:c,declarations:l,layerGeom:e,styleTarget:t,tokens:r,location:d,origin:i,warnings:n});if(Object.keys(p).length===0)return;const{part:f}=c;a.push({declarations:p,...u===void 0?{}:{state:u},...f===void 0?{}:{part:f},origin:i})};if(J.defaults.forEach((c,l)=>{te(c)&&s(c.select,c.declarations,c.when?.state,`builtin[${l}]`)}),t===void 0)return a;for(const c of cc(e,t))s(c.select,c.declarations,c.when?.state,uc(e,c.select.part));return a.sort(lc)},ge=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},pc=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return ge(e,(a,i,s)=>{const c=a.select;if(c.target!=="geom")return;const l=c.layer;l===void 0||typeof l!="string"||r.has(l)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown layer '${l}'.`,context:{param:"layer",actual:l,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},mc=(e,t)=>{const r=new Map(Or.flatMap(a=>t[o.ANNOTATION_BUCKETS[a]].map(i=>[i.id,a]))),n=[];return ge(e,(a,i,s)=>{const c=a.select;if(c.target!=="annotation")return;const l=c.annotation;if(l===void 0||typeof l!="string")return;const u={param:"annotation",actual:l,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(l);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown annotation '${l}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets sticker '${l}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=c.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets ${d} '${l}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},fc=e=>{const t=[];return ge(e,(r,n,a)=>{if(!te(r))return;const i=r.when?.state;i===void 0||kr(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${o.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),t},kr=e=>o.STYLE_STATES.includes(e),gc=(e,t,r)=>e===void 0?`Set 'kind' to the geom declaring '${t}' — a part is addressed on the kind that has it.`:r.length===0?`Remove 'part' — ${e} has none.`:`Set 'part' to one of ${r.map(n=>`'${n}'`).join(", ")}, or omit it.`,Br=(e,t,r)=>{const{kind:n,part:a}=e.select;if(a===void 0)return;const i=e.id===void 0?{}:{styleEntryId:e.id},s=Q({kind:n,part:a},r);if(s===void 0){const c=Q({kind:n},r),l=c===void 0?[]:Oe(c,"part");return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown part '${a}'.`,context:{param:"part",actual:a,...i},suggestion:gc(n,a,l)}}if(e.when!==void 0&&!We(s)){const c=Rr(n,a);return{code:"INVALID_STYLE_RULE",message:`Style ${t} ignored: a ${c} entry takes no conditions.`,context:{param:"when",...i},suggestion:`Remove the 'when' clause — the ${c} is styled as a whole.`}}},hc=(e,t,r)=>{const{kind:n}=e.select;if(n===void 0||r.has(n))return;const a=r.getAll().map(i=>`'${i.type}'`);return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown geom kind '${n}'.`,context:{param:"kind",actual:n,...e.id===void 0?{}:{styleEntryId:e.id}},suggestion:`Set 'kind' to one of ${a.join(", ")}, or omit it to reach every geom.`}},yc=e=>{const t=Zs(e);return r=>{const n=[];return ge(r,(a,i,s)=>{if(!te(a))return;const c=`${i}[${s}]`,l=hc(a,c,e)??Br(a,c,t);l!==void 0&&n.push(l)}),n}},vc=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))o.isUsableTokenValue(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${P(n)}.`,context:{param:"tokens",actual:P(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},P=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),$r=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s,entryTarget:c}=e,l={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(m,v)=>{l[m]=v},p=(m,v,y)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: expected ${v}, got ${P(y)}.`,context:{param:m,expected:v,actual:P(y),...u},suggestion:`Set '${m}' to ${v}.`})},f=(m,v)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: unknown token '${v}'.`,context:{param:m,actual:v,...u},suggestion:`Declare '${v}' in the stylesheet's tokens.`})},h=m=>{const v=Hs.has(m),y=nc(c,m),g=y===void 0?`Declare '${m}' on a target whose vocabulary carries it.`:`Declare '${m}' on an entry whose kind supports it (e.g. ${y}).`;s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: ${v?"not in this entry's vocabulary":"not a style property"}.`,context:{param:m,...u},suggestion:v?g:`Remove the unknown declaration '${m}'.`})};for(const m of Object.keys(t)){const v=t[m];if(v===void 0)continue;const y=r[m];if(y===void 0){h(m);continue}const g=o.STYLE_DOMAINS[y](v,n);switch(g.status){case"accepted":d(m,g.value);break;case"rejected":p(m,g.expected,g.actual);break;case"unknownToken":f(m,g.token);break;case"dropped":break;default:break}}return l},bc=({layer:e})=>{if(e.position==="stack")return;const t=o.readVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];o.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Sc=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=o.readVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(o.POSITION_VARIABLES.yMin)||!e.data.hasVariable(o.POSITION_VARIABLES.yMax))return;const n=c=>t==="y"?c.xMax:c.yMax,a=c=>t==="y"?c.xMin:c.yMin,i=new Map;for(const c of e.data){const l=c[r],u=o.getYMin(c),d=o.getYMax(c),p=o.getXMin(c),f=o.getXMax(c),h=o.getYRaw(c);if(!o.isDefined(l)||!o.isDefined(u)||!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||!o.isDefined(h))continue;const m=h>=0;if(Math.abs(h)===0)continue;const v=ke(c,r),y={xMin:p,xMax:f,yMin:u,yMax:d},g=i.get(v);if(g===void 0){i.set(v,{total:h,topPositive:m?y:null,bottomNegative:m?null:y});continue}g.total+=h,m?(g.topPositive===null||n(y)>n(g.topPositive))&&(g.topPositive=y):(g.bottomNegative===null||a(y)<a(g.bottomNegative))&&(g.bottomNegative=y)}const s=[];for(const[c,l]of i){const u=l.topPositive??l.bottomNegative;u!==null&&s.push({xKey:c,total:l.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:l.topPositive!==null?"positive":"negative"}})}return s},Ac=class extends B{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=wt(t.coordSystem);if(r.summaries.stackTotals){const i=Sc({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=bc({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},ht={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Tc=["color","size","alpha","strokeWidth","lineType"],Ic=class extends B{dependencies(e){return Tc.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(o.VISUAL_VARIABLES);for(const[a,i]of n){const s=o.readConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,ht[a],s);continue}const c=o.readVariableName(e.mapping[a]),l=t.scales[a];!c||!l||l.kind!=="visual"||(r=r.deriveVariableFrom(c,i,ht[a],Ec(l)))}return{...e,data:r}}},Ec=e=>t=>o.isDefined(t)?e.map(t):null;function Ur(e=new o.GeomRegistry){return{diagnostics:new As,geomRegistry:e}}var Fr=class{constructor(e,t,r,n,a,i,s,c,l,u,d,p,f,h,m,v){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=p,this.stylesCompiler=f,this.chromeStylesCompiler=h,this.highlightsCompiler=m,this.annotationsCompiler=v,this.stageTimer=o.IS_DEV?ks():null,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},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:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}],o.IS_DEV&&this.setupStageTiming()}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??yt})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??yt;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,H(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=Fe(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return H(t,{scales:_e(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=fe(r,a);return t.coords.coordType==="polar"?je(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[Tt(e)],warnings:t.warnings}}setupStageTiming(){this.stageTimer&&(this.dataCompiler.compile=this.stageTimer.wrap("data",this.dataCompiler.compile.bind(this.dataCompiler)),this.transformCompiler.compile=this.stageTimer.wrap("transform",this.transformCompiler.compile.bind(this.transformCompiler)),this.constantMappingCompiler.compile=this.stageTimer.wrap("constantMapping",this.constantMappingCompiler.compile.bind(this.constantMappingCompiler)),this.layerPhasedCompiler.compile=this.stageTimer.wrap("layer",this.layerPhasedCompiler.compile.bind(this.layerPhasedCompiler)),this.coordCompiler.setup=this.stageTimer.wrap("coordSetup",this.coordCompiler.setup.bind(this.coordCompiler)),this.scaleCompiler.compile=this.stageTimer.wrap("scale",this.scaleCompiler.compile.bind(this.scaleCompiler)),this.positionMapperCompiler.compile=this.stageTimer.wrap("positionMapper",this.positionMapperCompiler.compile.bind(this.positionMapperCompiler)),this.visualMapperCompiler.compile=this.stageTimer.wrap("visualMapper",this.visualMapperCompiler.compile.bind(this.visualMapperCompiler)),this.coordCompiler.transform=this.stageTimer.wrap("coordTransform",this.coordCompiler.transform.bind(this.coordCompiler)),this.summarizeCompiler.compile=this.stageTimer.wrap("summarize",this.summarizeCompiler.compile.bind(this.summarizeCompiler)),this.guideCompiler.compile=this.stageTimer.wrap("guide",this.guideCompiler.compile.bind(this.guideCompiler)),this.stylesCompiler.compile=this.stageTimer.wrap("styles",this.stylesCompiler.compile.bind(this.stylesCompiler)),this.chromeStylesCompiler.compile=this.stageTimer.wrap("chromeStyles",this.chromeStylesCompiler.compile.bind(this.chromeStylesCompiler)),this.highlightsCompiler.compile=this.stageTimer.wrap("highlights",this.highlightsCompiler.compile.bind(this.highlightsCompiler)),this.annotationsCompiler.compile=this.stageTimer.wrap("annotations",this.annotationsCompiler.compile.bind(this.annotationsCompiler)))}trackCompile(e){if(!o.IS_DEV)return e();this.stageTimer?.reset();const t=this.getCacheStats(),r=performance.now();try{return e()}finally{const n=performance.now()-r,a={},i={};for(const{name:s,getStats:c}of this.stages){const l=c();a[s]={hits:l.hits-t[s].hits,misses:l.misses-t[s].misses},i[s]=this.stageTimer?.getDuration(s)??0}this.lastCompile={stages:a,durationMs:n,stageDurationsMs:i}}}runPipeline({spec:e,colorScheme:t}){return{...de({spec:e}).pipe(({spec:r})=>({spec:H(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:H(r,{data:n.data,mapping:n.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:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},Vc=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],yt="light",xc=({plugins:e=[]}={})=>{const t=o.readPlugins(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=ro(t),i=Ur(r),s=new Go(i),c=new Ge(a);for(const l of t.warnings)i.diagnostics.addWarning(l,{persistent:!0});return new Fr(i,new o.DataCompiler,new xr(i),c,new $n,new $i(i,c,n,new Pi(i,c,new Bs(n),new ua,new la(i),new no(new uo))),new Eo(i,s),new jn(new ca),new Io(i),new Ic,new Vi(i),new Ac(i),new Ws(i),new qs(i),new wi(i),new Vn(i))};Object.defineProperty(exports,"AREA_DEFAULTS",{enumerable:!0,get:function(){return Vs}});Object.defineProperty(exports,"BAR_DEFAULTS",{enumerable:!0,get:function(){return xs}});Object.defineProperty(exports,"BUILTIN_STYLES",{enumerable:!0,get:function(){return J}});Object.defineProperty(exports,"COLOR_INTERPOLATION_SPACES",{enumerable:!0,get:function(){return Vo}});Object.defineProperty(exports,"COMPILER_STAGE_KEYS",{enumerable:!0,get:function(){return Vc}});Object.defineProperty(exports,"Compiler",{enumerable:!0,get:function(){return Fr}});Object.defineProperty(exports,"DATA_LABELS_DEFAULTS",{enumerable:!0,get:function(){return Ar}});Object.defineProperty(exports,"DIVERGING_SCHEME_NAMES",{enumerable:!0,get:function(){return mr}});Object.defineProperty(exports,"LINE_DEFAULTS",{enumerable:!0,get:function(){return Es}});Object.defineProperty(exports,"POINT_DEFAULTS",{enumerable:!0,get:function(){return Is}});Object.defineProperty(exports,"POLAR_COORD_DEFAULTS",{enumerable:!0,get:function(){return ie}});Object.defineProperty(exports,"RULE_DEFAULTS",{enumerable:!0,get:function(){return Os}});Object.defineProperty(exports,"SCHEME_ALIASES",{enumerable:!0,get:function(){return fr}});Object.defineProperty(exports,"SEQUENTIAL_SCHEME_NAMES",{enumerable:!0,get:function(){return xo}});Object.defineProperty(exports,"SpecCompiler",{enumerable:!0,get:function(){return xr}});Object.defineProperty(exports,"TILE_DEFAULTS",{enumerable:!0,get:function(){return ws}});Object.defineProperty(exports,"TransformCompiler",{enumerable:!0,get:function(){return Ge}});Object.defineProperty(exports,"applyReplayableTransforms",{enumerable:!0,get:function(){return br}});Object.defineProperty(exports,"areEndpointsComparable",{enumerable:!0,get:function(){return St}});Object.defineProperty(exports,"buildDiagnostic",{enumerable:!0,get:function(){return Tt}});Object.defineProperty(exports,"buildEmptyHighlightForStrategy",{enumerable:!0,get:function(){return tr}});Object.defineProperty(exports,"canAnchorDirectLabels",{enumerable:!0,get:function(){return Zt}});Object.defineProperty(exports,"clampValuesAgainstFillSiblings",{enumerable:!0,get:function(){return Vr}});Object.defineProperty(exports,"compileChromeStyles",{enumerable:!0,get:function(){return Lr}});Object.defineProperty(exports,"compileLayerStyles",{enumerable:!0,get:function(){return Cr}});Object.defineProperty(exports,"compilePredicate",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"composePoint",{enumerable:!0,get:function(){return Ae}});Object.defineProperty(exports,"createAlphaValueReader",{enumerable:!0,get:function(){return Hr}});Object.defineProperty(exports,"createColorValueReader",{enumerable:!0,get:function(){return Wr}});Object.defineProperty(exports,"createCommonContainer",{enumerable:!0,get:function(){return Ur}});Object.defineProperty(exports,"createCompiler",{enumerable:!0,get:function(){return xc}});Object.defineProperty(exports,"createDatasetFromKindPartitions",{enumerable:!0,get:function(){return Bn}});Object.defineProperty(exports,"createEmptyLayerStyles",{enumerable:!0,get:function(){return nr}});Object.defineProperty(exports,"createGroupValueReader",{enumerable:!0,get:function(){return Xr}});Object.defineProperty(exports,"createLabelValueReader",{enumerable:!0,get:function(){return zr}});Object.defineProperty(exports,"createLayerMeasurement",{enumerable:!0,get:function(){return Pt}});Object.defineProperty(exports,"createObservationAnchorBuilder",{enumerable:!0,get:function(){return Lt}});Object.defineProperty(exports,"createObservationAnchorMatcher",{enumerable:!0,get:function(){return Dt}});Object.defineProperty(exports,"createObservationAnchorParser",{enumerable:!0,get:function(){return At}});Object.defineProperty(exports,"createPipeline",{enumerable:!0,get:function(){return de}});Object.defineProperty(exports,"createPredicateCompileContext",{enumerable:!0,get:function(){return pe}});Object.defineProperty(exports,"createPredicateValueReader",{enumerable:!0,get:function(){return Nt}});Object.defineProperty(exports,"createRawValueReader",{enumerable:!0,get:function(){return V}});Object.defineProperty(exports,"createRowPredicateCompileContext",{enumerable:!0,get:function(){return pn}});Object.defineProperty(exports,"createScaleContext",{enumerable:!0,get:function(){return Fe}});Object.defineProperty(exports,"createSegmentYReader",{enumerable:!0,get:function(){return we}});Object.defineProperty(exports,"createSizeValueReader",{enumerable:!0,get:function(){return qr}});Object.defineProperty(exports,"createStrokeWidthValueReader",{enumerable:!0,get:function(){return Jr}});Object.defineProperty(exports,"createXValueReader",{enumerable:!0,get:function(){return Kr}});Object.defineProperty(exports,"createYValueReader",{enumerable:!0,get:function(){return Yr}});Object.defineProperty(exports,"describeMeasurementBasis",{enumerable:!0,get:function(){return be}});Object.defineProperty(exports,"filterLayersByGeoms",{enumerable:!0,get:function(){return ei}});Object.defineProperty(exports,"findAnnotation",{enumerable:!0,get:function(){return js}});Object.defineProperty(exports,"findCompanionLayers",{enumerable:!0,get:function(){return ti}});Object.defineProperty(exports,"findDefaultKitStyleTarget",{enumerable:!0,get:function(){return Qs}});Object.defineProperty(exports,"findDistinctLayers",{enumerable:!0,get:function(){return Me}});Object.defineProperty(exports,"findLayerByGeom",{enumerable:!0,get:function(){return Za}});Object.defineProperty(exports,"findLayerById",{enumerable:!0,get:function(){return Qa}});Object.defineProperty(exports,"findPredicateProblems",{enumerable:!0,get:function(){return R}});Object.defineProperty(exports,"getCoordinates",{enumerable:!0,get:function(){return an}});Object.defineProperty(exports,"getCrossAxisCoordinate",{enumerable:!0,get:function(){return Ot}});Object.defineProperty(exports,"getGroup",{enumerable:!0,get:function(){return Z}});Object.defineProperty(exports,"getLayerVariableValueFormat",{enumerable:!0,get:function(){return Pe}});Object.defineProperty(exports,"getLayerYValueFormat",{enumerable:!0,get:function(){return cn}});Object.defineProperty(exports,"getMainAxisCoordinate",{enumerable:!0,get:function(){return xt}});Object.defineProperty(exports,"getObservationXKey",{enumerable:!0,get:function(){return ke}});Object.defineProperty(exports,"isAnnotationKind",{enumerable:!0,get:function(){return Fs}});Object.defineProperty(exports,"isCartesian",{enumerable:!0,get:function(){return on}});Object.defineProperty(exports,"isCompanionLayer",{enumerable:!0,get:function(){return Qt}});Object.defineProperty(exports,"isLayerSpecOf",{enumerable:!0,get:function(){return Ja}});Object.defineProperty(exports,"mapItems",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"measureAnchorSpace",{enumerable:!0,get:function(){return Vt}});Object.defineProperty(exports,"patchSpec",{enumerable:!0,get:function(){return H}});Object.defineProperty(exports,"readAnnotationBucket",{enumerable:!0,get:function(){return Ye}});Object.defineProperty(exports,"readGeomScaleConstraints",{enumerable:!0,get:function(){return Be}});Object.defineProperty(exports,"readMainAxis",{enumerable:!0,get:function(){return wt}});Object.defineProperty(exports,"readObservationMeasurement",{enumerable:!0,get:function(){return $t}});Object.defineProperty(exports,"readPredicateVariables",{enumerable:!0,get:function(){return ae}});Object.defineProperty(exports,"readScopeKey",{enumerable:!0,get:function(){return Ie}});Object.defineProperty(exports,"readScopeXVariable",{enumerable:!0,get:function(){return er}});Object.defineProperty(exports,"removeDiscreteScalePadding",{enumerable:!0,get:function(){return je}});Object.defineProperty(exports,"removeLocatedAnnotation",{enumerable:!0,get:function(){return Gs}});Object.defineProperty(exports,"replaceAnnotationBucket",{enumerable:!0,get:function(){return wr}});Object.defineProperty(exports,"replaceAtIndex",{enumerable:!0,get:function(){return tn}});Object.defineProperty(exports,"resolveAnchorVariable",{enumerable:!0,get:function(){return ue}});Object.defineProperty(exports,"resolveColorRamp",{enumerable:!0,get:function(){return Ue}});Object.defineProperty(exports,"resolveComparisonBasis",{enumerable:!0,get:function(){return Jt}});Object.defineProperty(exports,"resolveCoord",{enumerable:!0,get:function(){return Sr}});Object.defineProperty(exports,"resolveCrossAnchorVariable",{enumerable:!0,get:function(){return Le}});Object.defineProperty(exports,"resolveDiscreteScale",{enumerable:!0,get:function(){return yr}});Object.defineProperty(exports,"resolveGeomAnchorSpace",{enumerable:!0,get:function(){return Et}});Object.defineProperty(exports,"resolveGeomScaleDemands",{enumerable:!0,get:function(){return $e}});Object.defineProperty(exports,"resolveLabelSource",{enumerable:!0,get:function(){return Er}});Object.defineProperty(exports,"resolveLayer",{enumerable:!0,get:function(){return Ir}});Object.defineProperty(exports,"resolveScale",{enumerable:!0,get:function(){return fe}});Object.defineProperty(exports,"resolveSegmentYSource",{enumerable:!0,get:function(){return le}});Object.defineProperty(exports,"resolveStatSpec",{enumerable:!0,get:function(){return Tr}});Object.defineProperty(exports,"resolveVariableLabel",{enumerable:!0,get:function(){return Ne}});Object.defineProperty(exports,"sampleColorScheme",{enumerable:!0,get:function(){return _o}});Object.defineProperty(exports,"shouldNarrowByGroup",{enumerable:!0,get:function(){return Ce}});Object.defineProperty(exports,"toPanelFraction",{enumerable:!0,get:function(){return nn}});Object.defineProperty(exports,"uniqueId",{enumerable:!0,get:function(){return I}});Object.defineProperty(exports,"updateSpec",{enumerable:!0,get:function(){return en}});
|
|
1
|
+
const o=require("./annotations-6ONVHjKW.cjs");let ce=require("lodash-es"),q=require("d3-time"),jr=require("date-fns/differenceInDays"),D=require("d3-regression"),w=require("d3-scale"),Y=require("d3-interpolate"),A=require("d3-scale-chromatic"),ye=require("lodash-es/clamp");ye=o.__toESM(ye,1);let ve=require("lodash-es/merge");ve=o.__toESM(ve,1);var V=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);return o.isDefined(n)?a=>{const i=a[n];return i===void 0?null:vt(i,e.getType(n))}:()=>null},Gr=(e,t)=>{const r=o.readConstantValue(t);if(r!==void 0)return()=>r;const n=o.readVariableName(t);if(!o.isDefined(n)||!e.hasVariable(n))return()=>null;const a=e.getValues(n),i=e.getType(n);return s=>{const c=a[s];return c===void 0?null:vt(c,i)}},Kr=(e,t)=>V(e,t.x),Yr=(e,t)=>V(e,t.y),zr=(e,t)=>V(e,t.label),Wr=(e,t)=>V(e,t.color),qr=(e,t)=>V(e,t.size),Hr=(e,t)=>V(e,t.alpha),Xr=(e,t)=>V(e,t.group),Jr=(e,t)=>V(e,t.strokeWidth),vt=(e,t)=>{switch(t){case"numeric":return o.isStrictNumericDataValue(e)?e:null;case"categorical":return o.isStrictCategoricalDataValue(e)?e:null;case"temporal":return o.isStrictTemporalDataValue(e)?e:null;default:return null}},Xe={variable:o.POSITION_VARIABLES.yRaw};function le(e,t){return o.isStackedPosition(e)?Xe:t.y??Xe}function we(e){return V(e.data,le(e.position,e.mapping))}function Qr(e){return Gr(e.data,le(e.position,e.mapping))}var ue=e=>{const t=o.readVariableName(e.mapping.x);return t!==null&&t!==o.CONSTANT_VARIABLES.x?t:o.GROUP_VARIABLES.group},Le=e=>Zr(e)?o.readVariableName(e.mapping.y):null,bt=e=>Le(e)===null?null:we(e),Ce=e=>e.spatialKind!=="cells",Zr=e=>e.spatialKind==="points"||e.spatialKind==="cells",St=(e,t)=>e.yScaleType===t.yScaleType&&Se(e.valueFormat)===Se(t.valueFormat),be=e=>`${e.yScaleType} y axis, ${Se(e.valueFormat)}`,Se=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,At=(e,t)=>{const r=o.toExplicitValueFormat(e.data.getValueFormat(ue(e))),n=Le(e);return a=>({...a,anchorValue:o.parseAddressingValue(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:o.parseAddressingValue(a.groupValue,o.toExplicitValueFormat(e.data.getValueFormat(o.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:o.parseAddressingValue(a.crossValue,o.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Tt(e){return e instanceof o.VizError?{severity:"error",kind:e.kind,code:e.code,message:e.message,...e.context!==void 0?{context:e.context}:{},...e.suggestion!==void 0?{suggestion:e.suggestion}:{}}:{severity:"error",kind:"internal",code:"INTERNAL_INVARIANT",message:e instanceof Error?e.message:String(e)}}function en(e,t){return It(e,t)}function H(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function tn(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function _e(e,t){let r=null;for(const[n,a]of e.entries()){const i=t(a,n);if(i===a){r?.push(i);continue}r??=e.slice(0,n),r.push(i)}return r??e}function It(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(o.isPlainObject(i)&&o.isPlainObject(s)){const c=It(s,i);c!==s&&(n[a]=c,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function de(e){return{pipe:t=>{const r=t(e);return de({...e,...r})},result:()=>e}}var rn=(e,t)=>{if(!o.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[o.getStableKey(r)]??e.fallback},Et=e=>e.type==="polar"?"disk":"panel",Vt=(e,t)=>{if(e!=="disk")return{x:0,y:0,width:t.width,height:t.height};const r=Math.min(t.width,t.height);return{x:(t.width-r)/2,y:(t.height-r)/2,width:r,height:r}},nn=(e,t)=>{if(e.space!=="disk")return{x:e.x,y:e.y};if(t.width<=0||t.height<=0)return{x:0,y:0};const r=Vt(e.space,t),n=r.y+(1-e.y)*r.height;return{x:(r.x+e.x*r.width)/t.width,y:1-n/t.height}};function xt(e,t){return e==="x"?t.x:t.y}function Ot(e,t){return e==="x"?t.y:t.x}function an(e,t){return{main:xt(e,t),cross:Ot(e,t)}}function Ae(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function wt(e){return e.type==="cartesian"?e.mainAxis:"x"}function on(e){return e.type==="cartesian"}var Z=e=>e[o.GROUP_VARIABLES.group],Lt=e=>{const t=ue(e),r=bt(e),n=Ce(e)&&t!==o.GROUP_VARIABLES.group;return a=>{const i=a[t]??null;if(i===null)return null;const s=r===null?null:r(a);if(r!==null&&s===null)return null;const c=n?Z(a)??null:null;return{layerId:e.id,anchorValue:i,...s!==null&&{crossValue:s},...c!==null&&{groupValue:c}}}},sn={type:"decimal"};function Ct(e){return e.length>0&&e.every(t=>t.data.size()===0)}function Pe(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):sn}function cn(e){return Pe(e,o.readVariableName(e.mapping.y))}function _t({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??le(t,r)}function Pt(e,t){const r=_t({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=o.readVariableName(r),a=n===o.POSITION_VARIABLES.yRaw?o.readVariableName(e.mapping.y):n;return{read:V(e.data,r),valueFormat:Pe(e,a)}}var Dt=e=>{const t=ue(e),r=bt(e),n=Ce(e);return(a,i)=>!o.areDataValuesEqual(a[t]??null,i.anchorValue)||!(r===null||i.crossValue===void 0||o.areDataValuesEqual(r(a),i.crossValue))?!1:!n||i.groupValue===void 0?!0:o.areDataValuesEqual(Z(a),i.groupValue)},Nt=e=>{const t=o.readVariableName(e.mapping.y),r=we(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},ln=e=>t=>{if(t===o.readVariableName(e.mapping.y))return Qr(e);const r=e.data.hasVariable(t)?e.data.getValues(t):null;return n=>r?.[n]??null};var un=["lt","lte","gt","gte","range"],dn={highlight:{subject:"Highlight predicate",effect:"dropping this highlight"},"selection-anchor":{subject:"Selection anchor predicate",effect:"dropping this annotation"},"style-rule":{subject:"Style rule predicate",effect:"dropping this rule"}},_=()=>!1,F=()=>!0;function pe(e,t){const r=Nt(e);return{...Rt(e,t),createValueReader:n=>a=>r(a,n)}}function pn(e,t){return{...Rt(e,t),createValueReader:ln(e)}}function ae(e){return"and"in e?[...new Set(e.and.flatMap(ae))]:"or"in e?[...new Set(e.or.flatMap(ae))]:"not"in e?ae(e.not):[e.variable]}function N(e,t){if("and"in e){const r=e.and.map(n=>N(n,t)).filter(n=>n!==F);return r.includes(_)?_:r.length===0?F:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>N(n,t)).filter(n=>n!==_);return r.includes(F)?F:r.length===0?_:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=N(e.not,t);return r===_?F:r===F?_:n=>!r(n)}return fn(e,t)}function R(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>R(n,t,r)):"or"in e?e.or.flatMap(n=>R(n,t,r)):"not"in e?R(e.not,t,r):mn(e,t,r)}function Rt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),parsingLocale:t}}function mn(e,t,r){const{subject:n,effect:a}=dn[r];if(!t.hasVariable(e.variable))return[{code:"UNKNOWN_VARIABLE",message:`${n} references unknown variable '${e.variable}' — ${a}.`,context:{variableName:e.variable},suggestion:`Map '${e.variable}' in the layer or correct the variable name in the predicate.`}];const i=gn(e);return i!==null&&t.getType(e.variable)==="categorical"?[{code:"INVALID_PREDICATE_OPERATOR",message:`${n} uses ordering operator '${i}' on categorical variable '${e.variable}' — ${a}. Use 'eq' or 'oneOf' instead.`,context:{variableName:e.variable},suggestion:"Use 'eq' or 'oneOf' for categorical variables."}]:[]}function fn(e,t){if(!t.hasVariable(e.variable))return _;const r=t.createValueReader(e.variable),n=o.toExplicitValueFormat(t.getValueFormat(e.variable)),a=i=>o.parseAddressingValue(i,n,t.parsingLocale);if("eq"in e){const i=a(e.eq);return s=>o.areDataValuesEqual(r(s),i)}if("oneOf"in e){const i=e.oneOf.map(a);if(i.length>=32){const s=new Set,c=new Set;for(const l of i)o.isStrictTemporalDataValue(l)?c.add(l.getTime()):s.add(l);return l=>{const u=r(l);return o.isStrictTemporalDataValue(u)?c.has(u.getTime()):!Number.isNaN(u)&&s.has(u)}}return s=>{const c=r(s);for(const l of i)if(o.areDataValuesEqual(c,l))return!0;return!1}}if("lt"in e){const i=a(e.lt);return s=>j(r(s),i)==="less"}if("lte"in e){const i=a(e.lte);return s=>{const c=j(r(s),i);return c==="less"||c==="equal"}}if("gt"in e){const i=a(e.gt);return s=>j(r(s),i)==="greater"}if("gte"in e){const i=a(e.gte);return s=>{const c=j(r(s),i);return c==="greater"||c==="equal"}}if("range"in e){const[i,s]=e.range,c=a(i),l=a(s);return u=>{const d=r(u),p=j(d,c),f=j(d,l);return p==="incomparable"||f==="incomparable"?!1:(p==="greater"||p==="equal")&&(f==="less"||f==="equal")}}return _}function gn(e){for(const t of un)if(t in e)return t;return null}function j(e,t){if(e===null||t===null)return"incomparable";if(o.isStrictTemporalDataValue(e)&&o.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return o.isStrictNumericDataValue(e)&&o.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var hn=(e,t,r,n,a,i,s)=>{const c=kt(e,t,r.predicate,n,a,i,s);if(c===null)return null;const l=Mt(r.padding),u=l===null?bn(c,r.padding):c,d={x:u.xMin,y:u.yMin,width:Math.max(0,u.xMax-u.xMin),height:Math.max(0,u.yMax-u.yMin),space:u.space};return l===null?d:{...d,defer:l}},yn=(e,t,r,n,a,i,s)=>{const c=kt(e,t,r.predicate,n,a,i,s);return c===null?null:{...o.alignToBoxPoint(c,r.align),space:c.space}},Mt=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},kt=(e,t,r,n,a,i,s)=>{if(t.has(r))return t.get(r)??null;let c=null,l=!1;const u=new Map;for(const d of n){if(!d.interactive)continue;const p=R(r,d.data,"selection-anchor");if(p.length>0){for(const h of p)u.set(`${h.code}:${h.message}`,h);continue}l=!0;const f=N(r,pe(d,i));if(f!==_)for(const h of d.data){if(!f(h))continue;const m=o.readObservationBox(h,a);m!==null&&(c=c===null?m:vn(c,m))}}if(!l)for(const d of u.values())s?s.push(d):e.diagnostics.addWarning(d);return t.set(r,c),c},vn=(e,t)=>({space:e.space,xMin:Math.min(e.xMin,t.xMin),xMax:Math.max(e.xMax,t.xMax),yMin:Math.min(e.yMin,t.yMin),yMax:Math.max(e.yMax,t.yMax)}),bn=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{...e,xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},oe=(e,t,r)=>{const n=An(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Tn(n,t.offset,e.coordSystem)},Bt=(e,t)=>t.anchorType==="selection"?hn(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale,e.warnings):t.anchorType==="annotation"?{x:0,y:0,width:0,height:0,defer:{type:"annotation-ref",ref:t.ref,align:"center"}}:{x:t.x,y:1-t.y-t.height,width:t.width,height:t.height},De=(e,t,r)=>Te(e,t,r)?.point??null,Te=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const c=e.geomRegistry.get(s.geom),{resolveAnchorPosition:l}=c;if(l===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=Pt(s,c),d=Dt(s),p=Lt(s),f=At(s,n)(a);let h=-1;for(const m of s.data){if(h+=1,!d(m,f))continue;const v=l(m,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(v===null)continue;const y=$t(s,m,u);if(y===null)continue;const g=p(m);if(g!==null)return{point:{...v,...y,space:Et(r),observationIndex:h,anchor:a.align===void 0?g:{...g,align:a.align}},layerId:s.id}}}return null},Sn=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,c=a.y;if(s===void 0||c===void 0||s.kind!=="position"||c.kind!=="position")return null;const l=Qe(t.x,"x",r,i),u=Qe(t.y,"y",r,i);if(l===null||u===null)return null;const d=s.map(l),p=c.map(u);if(!o.isPointWithinPanel(d,p))return null;const f=Je(d,s,In(e)),h=Je(p,c),m=Ae(n.mainAxis,{main:f.min,cross:h.min}),v=Ae(n.mainAxis,{main:f.max,cross:h.max});return o.alignToBoxPoint({xMin:m.x,xMax:v.x,yMin:m.y,yMax:v.y},t.align??"center")},$t=(e,t,r)=>{const n=r.read(t);return o.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:rn(r.valueFormat,t),yScaleType:e.yScaleType}:null},An=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Sn(e,t);case"selection":return yn(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale,e.warnings);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return De(e,En(t),r)}},Tn=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Mt(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Je=(e,t,r=1)=>{const{bandwidth:n}=t;if(n===null||n<=0)return{min:e,max:e};const a=n*r/2;return{min:e-a,max:e+a}},In=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},En=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Qe=(e,t,r,n)=>{for(const a of r){const i=o.readVariableName(a.mapping[t]);if(!(i===null||i===o.CONSTANT_VARIABLES.x))return o.parseAddressingValue(e,o.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},Vn=class extends o.Stage{constructor(e){super(),this.container=e,this.warningsByOutput=new WeakMap}compile(e){const t=super.compile(e);for(const r of this.warningsByOutput.get(t)??[])this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s=[],c={container:this.container,warnings:s,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},l={differenceArrows:Mn(c,t.differenceArrows),shapes:Ln(c,t.shapes),arrows:_n(c,t.arrows),textAnnotations:Pn(c,t.textAnnotations),images:Cn(c,t.images),stickers:Dn(c,t.stickers),pinnedNumbers:Nn(c,t.pinnedNumbers),comments:Rn(c,t.comments)};return xn(s,l),On(s,l),this.warningsByOutput.set(l,s),l}},L=(e,t,r,n)=>{e.push({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},xn=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.push({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation carries id "${a}" — references to it resolve to the first, and the rest cannot be addressed.`,context:{annotationId:a},suggestion:"Give each annotation its own id."});continue}r.add(a)}},On=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const a of n)r.add(a.id);for(const{id:n,ref:a}of wn(t))r.has(a)||e.push({code:"ANNOTATION_REF_NOT_FOUND",message:`Annotation "${n}" references id "${a}", whose annotation could not be anchored and was dropped.`,context:{annotationId:n,ref:a},suggestion:"Fix the anchor on the target annotation or point this reference at one that resolves."})},wn=e=>{const t=[],r=(n,a)=>{a.defer?.type==="annotation-ref"&&t.push({id:n,ref:a.defer.ref})};for(const n of e.shapes)r(n.id,n.region);for(const n of e.images)r(n.id,n.region);for(const n of e.arrows)r(n.id,n.start),r(n.id,n.end);for(const n of e.textAnnotations)r(n.id,n.at);for(const n of e.stickers)r(n.id,n.at);return t},Ln=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.region);if(a===null){L(e.warnings,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a})}return r},Cn=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.region);if(a===null){L(e.warnings,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit})}return r},_n=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.start,"pin"),i=oe(e,n.end,"pin");if(a===null||i===null){L(e.warnings,"arrow",n.id,`has ${Ut(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle})}return r},Pn=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.at,"pin");if(a===null){L(e.warnings,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align})}return r},Dn=(e,t)=>{const r=[];for(const n of t){const a=oe(e,n.at,"pin");if(a===null){L(e.warnings,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Nn=(e,t)=>{const r=[];for(const n of t){const a=De(e,n.at,"pin");if(a===null){L(e.warnings,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},Rn=(e,t)=>{const r=[];for(const n of t){const a=De(e,n.at,"pin");if(a===null){L(e.warnings,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Mn=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)L(e.warnings,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Te(e,n.start,"value"),i=Te(e,n.end,"value");if(a===null||i===null){L(e.warnings,"differenceArrow",n.id,`has ${Ut(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){L(e.warnings,"differenceArrow",n.id,"has both ends on the same observation");continue}kn(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ut=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",kn=(e,t,r,n)=>{St(r,n)||e.warnings.push({code:"INCOMPARABLE_ARROW_ENDPOINTS",message:`Difference arrow "${t.id}" measures between endpoints on different bases, so its label reports a quantity that does not exist.`,context:{annotationId:t.id,expected:be(r),actual:be(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Bn(e,t="kind"){const r=new Map;r.set(t,[]);for(const a of e)for(const i of a.observations)for(const s of Object.keys(i))r.has(s)||r.set(s,[]);for(const a of e)for(const i of a.observations)for(const[s,c]of r)c.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Ft(i),values:i};return new o.Dataset(n)}function Ft(e){const t=Array.isArray(e)?e:[e];for(const r of t)if(r!==null)return typeof r=="number"?"numeric":r instanceof Date?"temporal":"categorical";return"categorical"}var $n=class extends o.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(o.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:o.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){if(o.isVisualScale(n))continue;const a=o.readConstantValue(r[n]);if(a===void 0)continue;const i=o.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Ft(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},B=class{constructor(){this.perLayerMemo=o.createPerKeyMemo(),this.listMemo=o.createSingleSlotMemo()}get stats(){return o.sumMemoStats(this.perLayerMemo.stats,this.listMemo.stats)}compile(e){const t=this.dependencies(e),r=e.layers.map(n=>this.perLayerMemo(n,t,()=>this.compileLayer(n,e)));return this.listMemo(r,()=>r)}},Un=class extends o.Stage{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)}},Fn=class extends B{constructor(e){super(),this.registry=e}dependencies(e){return[e.coordSpec,e.coordSystem]}compileLayer(e,t){const[r]=this.registry.get(t.coordSpec.coordType).transform({coordSpec:t.coordSpec,coordSystem:t.coordSystem,layers:[e]});if(!r)throw new o.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},jn=class{constructor(e){this.setupStage=new Un(e),this.transformStage=new Fn(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)}},Gn=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new o.InternalError({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}},Kn=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new o.InternalError({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:zn(e.scales,e.layers)}}transform(e){return e.layers.map(t=>qn(t))}},Yn=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax]],Ze=o.prefixInternalVariable("flipSwap"),zn=(e,t)=>Wn(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Wn=e=>{for(const t of e){const r=o.readVariableName(t.mapping.x);if(!r||!t.data.hasVariable(r))continue;const n=t.data.getType(r);if(n==="categorical"||n==="temporal")return!0}return!1},qn=e=>{let t=e.data;for(const[r,n]of Yn){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ze).renameVariable(n,r).renameVariable(Ze,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}};function jt(e){const t=new Set,r=[];for(const n of e){const a=n instanceof Date?n.getTime():String(n);t.has(a)||(t.add(a),r.push(n))}return r}var Gt=(e,t)=>jt(t.domain!==null&&t.domain.length>0?t.domain:e),Hn=e=>{const t=e.length-1,r=e[t];if(r===void 0||t<1)return null;const n=[];for(let i=1;i<=t;i+=1){const s=e[i-1],c=e[i];s===void 0||c===void 0||n.push(c-s)}n.sort((i,s)=>i-s);const a=n[n.length-1>>1];return a===void 0?null:r+a},Xn=e=>[...new Set(e)].sort((t,r)=>t-r),Jn=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=ra(t,e.scales,e.layers),a=aa(t,e.scales,e.layers);return{coordSystem:{type:"polar",axisMapping:t.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:t.innerRadius,startAngle:r,spokeRotation:n,bandAxis:a},scales:ea(t,e.scales,e.layers)}}transform(e){if(e.coordSpec.coordType!=="polar")throw new o.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new o.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=Zn(r,n),i=ia(t);return e.layers.map(s=>oa(t.theta==="y"?sa(s):s,a,i))}},Qn=[[o.POSITION_VARIABLES.x,o.POSITION_VARIABLES.y],[o.POSITION_VARIABLES.xMin,o.POSITION_VARIABLES.yMin],[o.POSITION_VARIABLES.xMax,o.POSITION_VARIABLES.yMax]];function Zn(e,t){return r=>o.positionToAngle(r,e,t)}function ea(e,t,r){return e.theta!=="x"?t:t.map(n=>{if(n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"||n.scaleType==="continuous"&&n.transform!=="linear"||n.domainMax!==null)return n;const a=ta(e,r),i=Hn(a),s=a[0];return i===null||s===void 0?n:{...n,domainMin:n.domainMin??s,domainMax:i}})}function ta(e,t){const r=[];for(const n of t){const a=o.readVariableName(n.mapping[e.theta]);if(!(a===null||!n.data.hasVariable(a)))for(const i of n.data.getValues(a))i instanceof Date?r.push(i.getTime()):typeof i=="number"&&r.push(i)}return Xn(r)}function ra(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=na(n,e,r);return a===0?0:-Math.PI/a}function na(e,t,r){const n=[];for(const a of r){const i=o.readVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Gt(n,e).length}function aa(e,t,r){if(e.theta==="x")return"x";const n=t.find(i=>i.scaledAesthetic==="x")?.scaleType==="discrete",a=r.some(i=>i.position==="fill");return n&&!a?"y":null}function ia(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function oa(e,t,r){let n=e.data;return n=G(n,o.POSITION_VARIABLES.x,t),n=G(n,o.POSITION_VARIABLES.xMin,t),n=G(n,o.POSITION_VARIABLES.xMax,t),n=G(n,o.POSITION_VARIABLES.y,r),n=G(n,o.POSITION_VARIABLES.yMin,r),n=G(n,o.POSITION_VARIABLES.yMax,r),{...e,data:n}}function G(e,t,r){if(!e.hasVariable(t))return e;const n=e.getValues(t,{type:"numeric"}).map(a=>a===null?null:r(a));return e.addVariable(t,"numeric",n)}function sa(e){let t=e.data;for(const[r,n]of Qn){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,c=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),c&&(t=t.addVariable(r,"numeric",c))}return{...e,data:t}}var ca=class extends o.Registry{constructor(){super("coord"),this.register("cartesian",new Gn),this.register("flip",new Kn),this.register("polar",new Jn)}},la=class{constructor(e){this.container=e}compile(e,t){const r=this.container.geomRegistry.get(e),n=r.compile(t),a={...t.mapping,...n.mapping};return{...n,data:o.fillIntervalAesthetics(n.data,r.positionRoles,a)}}},ua=class{compute({data:e,mapping:t}){const r=o.getGroupVariables(e,t);if(r.length===0)return{data:e.addConstantVariable(o.GROUP_VARIABLES.group,"categorical",null)};const n=e.size(),a=r.map(s=>e.getValues(s)),i=new Array(n);for(let s=0;s<n;s++)i[s]=o.getStableKey(a.map(c=>c[s]));return{data:e.addVariable(o.GROUP_VARIABLES.group,"categorical",i)}}},da=e=>{if(e===void 0)return{};const t={};for(const r of e.columns)r.label!==void 0&&(t[r.key]=r.label);return t},pa=(e,t,r)=>{const n=M(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function M(e,t){const r=o.getAestheticFromScaleAestheticKey(t);let n=null;for(const a of Kt(t,e)){const i=o.readVariableName(a.mapping[r]);if(o.isDefined(i)){if(o.isInternalVariable(i)){n??=i;continue}return i}}return n}var Ne=(e,t)=>e===null?null:t[e]??e,ma=(e,t)=>e===null?null:t[String(e)]??null,k=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return he(t);for(const n of e){if(!n.data.hasVariable(r))continue;const a=n.data.getValueFormat(r),i=a.type==="lookup"?a.fallback:a;return ga(i,t)?i:he(t)}return he(t)},fa=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Kt(t,e).some(r=>r.position==="fill");function Kt(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var he=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},ga=(e,t)=>{switch(t){case"continuous":return o.isNumericValueFormat(e);case"datetime":return o.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},ha=[{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}],et={year:0,quarter:1,month:2,week:3,day:4,hour:5},K=40,ya=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Aa(r.unit).range(e,new Date(t.valueOf()+1),n)},va=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jr.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>K;case"day":return a/t>K;case"week":return a/(7*t)>K;case"month":return a/(30*t)>K;case"quarter":return a/(90*t)>K;case"year":return a/(365*t)>K}},ba=(e,t)=>{const r=!o.isDateWithoutYearValueFormat(t);switch(e.unit){case"year":return r?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return r?{type:"month_year"}:{type:"month"};case"week":return r?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return r?{type:"date"}:{type:"day_month"};case"hour":return r?{type:"datetime"}:{type:"time"}}},Sa=(e,t)=>{const r=Ta(t);return r===null?!1:et[e]>et[r]},Aa=e=>{switch(e){case"hour":return q.utcHour;case"day":return q.utcDay;case"week":return q.utcMonday;case"month":case"quarter":return q.utcMonth;case"year":return q.utcYear}},Ta=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":return"day";case"datetime":case"time":return"hour";default:return null}},Yt={left:"right",right:"left",top:"bottom",bottom:"top"},Ia={x:!0,y:!0,ySecondary:!1},Ea=20,tt=new Set(["top","bottom"]),Va={type:"percentage"};function xa(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:c}=e;if(Ct(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const l=La(c,a,i.type,n),u=new Set(t.map(f=>f.position)),d=_a(zt(n.axes.y.position,i.axisMapping.y.position),u),p=[];for(const f of o.SCALED_POSITION_AESTHETIC_KEYS){const h=r[f];if(!o.isDefined(h)||h.kind!=="position")continue;const m=Oa({scaleAestheticKey:f,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:l,variableLabels:s});p.push(m)}return p}function Oa(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:c,variableLabels:l}=e,{axisConfig:u,position:d,geometry:p}=Ca(t,n,i,s),f=M(a,t),h=fa(a,t)?Va:k({layers:a,scaleType:r.spec.scaleType,variableName:f});return{scaleAestheticKey:t,position:d,geometry:p,label:wa(u,f,l),isVisible:u.isVisible,tickCandidates:Da(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Pa(u,c,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function wa(e,t,r){return e.label?e.label:t?r[t]??null:null}function La(e,t,r,n){const a=t.flatMap(c=>{const l=e.get(c.geom).grid[r];return l?[l]:[]}),i=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY);return{x:{gridVisible:rt(i,n.axes.x.grid.isVisible)},y:{gridVisible:rt(s,n.axes.y.grid.isVisible)}}}function rt(e,t){if(e&&t===null)return!1}function Ca(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:zt(t.axes[e].position,r[e].position),geometry:r.x.geometry};case"y":return{axisConfig:t.axes[e],position:n,geometry:r.y.geometry};case"ySecondary":{const a=Yt[n],i=(0,ce.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:i,position:i.position,geometry:r.y.geometry}}}}function zt(e,t){return tt.has(e)===tt.has(t)?e:t}function _a(e,t){return t.has(e)?Yt[e]:e}function Pa(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Ia[r]}var Da=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Ra(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Ea;s++){const c=e.generateTicks({count:s}),l=o.getStableKey(c);a.has(l)||(a.add(l),i.push({ticks:c.map(u=>z(e,u))}))}return i}return e.spec.scaleType==="datetime"?Na(e,t):[{ticks:e.generateTicks().map(a=>z(e,a))}]},Na=(e,t)=>{const[r,n]=e.domain;if(!o.isStrictTemporalDataValue(r)||!o.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(c=>z(e,c))}];const a=new Set,i=[],s=(c,l)=>{if(c.length===0)return;const u=o.getStableKey(c);a.has(u)||(a.add(u),i.push({ticks:c.map(d=>z(e,d)),valueFormat:l}))};for(const c of ha)va({...c,start:r,stop:n})||Sa(c.unit,t)||s(e.generateTicks({interval:c}),ba(c,t));return s(e.generateTicks({atInputs:!0})),i.sort((c,l)=>c.ticks.length-l.ticks.length),i},Ra=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!o.isDefined(r)||!o.isDefined(n)||o.getStableKey([r])===o.getStableKey([n])?null:{ticks:[z(e,r),z(e,n)]}},z=(e,t)=>({value:t,position:e.map(t)});function Wt({scale:e,aesthetics:t,layers:r}){const n=Ma({layers:r,aesthetics:t}),a=qt({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Ma({layers:e,aesthetics:t}){const r=qt({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>o.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function qt({layers:e,aesthetics:t,layerFilter:r}){const n=new Map;for(const[a,i]of e.entries()){if(r&&!r(i))continue;const s=t.find(l=>o.isDefined(i.mapping[l]));if(s===void 0)continue;const c=o.readVariableName(i.mapping[s]);if(!(c===null||!i.data.hasVariable(c)))for(const l of i.data.getValues(c,{distinct:!0})){const u=o.getStableKey(l);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(o.getStableKey(a))}var Re=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function ka({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!Re(n))return[];if(!t.some(c=>o.isDefined(c.mapping.color)))return[];const a=M(t,"color");if(Ht({colorVariableName:a,xVariableName:M(t,"x"),mapsColorAcrossMultipleLayers:$a(t)>1,isMergedWithAnotherAesthetic:Ba(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(c=>o.isDefined(c.mapping.color));return Wt({scale:n,aesthetics:["color"],layers:t}).map(({value:c,geom:l,owner:u})=>{const d=u?.layerIndex??s,p=t[d],f=p?o.readVariableName(p.mapping.color):null;return{value:c,color:String(n.map(c)),geom:l,layerIndex:d,valueFormat:k({layers:p?[p]:t,scaleType:i,variableName:f}),label:ma(c,r)}})}var Ht=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||o.isInternalVariable(e)?!r:t!==null&&e===t;function Ba(e,t,r){if(r===null)return!1;for(const n of o.SCALED_VISUAL_AESTHETIC_KEYS){if(n==="color")continue;const a=e[n];if(!(a===void 0||!Re(a))&&M(t,n)===r)return!0}return!1}var $a=e=>e.filter(t=>o.isDefined(t.mapping.color)).length;function Xt(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Ua(e,t,r,n){const a=r.findIndex(i=>Xt(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Ne(o.readVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom,layerId:r[i.layerIndex]?.id,value:i.value},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function nt(e,t,r){if(r===null||t===null)return[...e];const n=o.getStableKey(r);return e.filter((a,i)=>o.getStableKey(t[i]??null)===n)}var Jt=e=>e==="none"?"first":e,Fa=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=at(e);return n===0?null:r}case"average":{const{sum:r,count:n}=at(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},ja=(e,t)=>{if(e.length<2)return null;const r=e.at(-1),n=t==="previous"?e.at(-2):e.at(0);return r===void 0||n===void 0||r.cross===null||n.cross===null||n.cross===0?null:{variation:(r.cross-n.cross)/n.cross,against:n.main}},at=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Ga(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Ka(e,n):Ya(e,n)}function Ka(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=o.readVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:k({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Ya(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:c}=e;if(!a.some(d=>Xt(c,d)))return null;const l=Ua(c,s,a,i);if(l.length===0)return null;const u=l.map(d=>za({group:d,show:t,compareWith:r.headline.compareWith,layers:a,scales:n})).filter(d=>d!==null);return u.length===0?null:{kind:"perGroup",items:u}}function za({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=o.readVariableName(i.mapping.y);if(s===null||i.data.getType(s)!=="numeric"||t==="total"&&i.position==="fill")return null;const c=o.readVariableName(i.mapping.x),l=o.readVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=k({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),p=Ha(i.data,c),f=k({layers:[i],scaleType:p?"datetime":a.x?.spec.scaleType??"discrete",variableName:c}),h=Xa(i.data,c),m=h.getValues(s,{type:"numeric"}),v=c!==null?h.getValues(c):[],y=l!==null?h.getValues(l):null,g=nt(m,y,e.value),b=nt(v,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Fa(g,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:f,label:e.label,caption:Wa(t,p,b),comparison:qa(t,r,p,b,g)}}function Wa(e,t,r){if(e==="current"){const i=r.at(-1);return i===void 0?null:{kind:"point",value:i}}if(!t)return null;const n=r.at(0),a=r.at(-1);return n===void 0||a===void 0?null:{kind:"range",from:n,to:a}}function qa(e,t,r,n,a){return e!=="current"||!r?null:ja(n.map((i,s)=>({main:i,cross:a[s]??null})),Jt(t))}function Ha(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Xa(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function Ja(e,...t){return e?t.includes(e.geom):!1}function Qa(e,t){return e.find(r=>r.id===t)}function Za(e,...t){return e.find(r=>t.includes(r.geom))}function ei(e,...t){return e.filter(r=>t.includes(r.geom))}function Qt(e,t){return e.interactive?!1:t.some(r=>r!==e&&o.areMappingsEquivalent(r.mapping,e.mapping))}function ti(e,t){return t.filter(r=>r!==e&&!r.interactive&&o.areMappingsEquivalent(e.mapping,r.mapping))}function Me(e){const t=e.filter(r=>!Qt(r,e));return t.length>0?t:e}function Zt({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=Me(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var ri=3;function ni({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const c=new Map(i.map(y=>[o.getStableKey(y.value),y])),l=di(si({scales:e,layers:r})),u=M(r,"x"),d=l.map(y=>{if(li(y,u,r))return null;const g=mi({group:y,variableLabels:a,layers:r,colorGroupsByValue:c});return g.items.length===0?null:{group:y,built:g}}).filter(o.isDefined),p=ai(d),f=Me(r),h=bi(s,t.legend.position,p,f,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&vi(s,p,f,n))return{drawn:[],position:h};const m=Si(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),v=m==="direct"?Ei(f[0]):null;return{drawn:d.map(({built:y})=>ii(y,{position:h,display:m,align:t.legend.align},v)),position:h}}function ai(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function ii(e,t,r){const{position:n,display:a}=t,i=oi(t.align,n);return a!=="direct"||r===null?{...e,position:n,display:a,align:i}:{...e,position:n,display:a,align:i,items:e.items.map(s=>({...s,normalizedY:r.get(String(s.value))??null}))}}function oi(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function si(e){const{scales:t,layers:r}=e,n=[];for(const a of o.SCALED_VISUAL_AESTHETIC_KEYS){const i=t[a];if(i===void 0||i.kind==="identity"||!ci(a,r))continue;const s=M(r,a),c=Ii(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:c})}return n}function ci(e,t){const r=o.getAestheticFromScaleAestheticKey(e);return t.some(n=>o.isDefined(n.mapping[r]))}function li(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Ht({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:ui(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function ui(e,t){const r=o.getAestheticFromScaleAestheticKey(e);return t.filter(n=>o.isDefined(n.mapping[r])).length>1}function di(e){const t=new Map;for(const r of e){const n=Ti(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function pi(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function mi({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(u=>o.getAestheticFromScaleAestheticKey(u.scaleAestheticKey)),s=Wt({scale:a.scale,aesthetics:i,layers:r}),c=k({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName}),l=r.find(u=>i.some(d=>o.isDefined(u.mapping[d])))?.id;return{aesthetics:e.map(u=>u.scaleAestheticKey),title:Ne(a.variableName,t),items:s.map(u=>fi(u,e,i,c,n,l))}}function fi(e,t,r,n,a,i){const s={};for(const l of t)pi(s,l.scaleAestheticKey,l.scale.map(e.value));if(s.color===void 0&&r.includes("size")&&(s.color=o.DEFAULT_GEOM_COLOR),s.lineType===void 0){const l=o.readConstantValue(e.owner?.layer.mapping.lineType);o.isLineType(l)&&(s.lineType=l)}const c=hi(e,t,r,n,a);return{value:e.value,label:gi(t,e,a),visual:s,normalizedY:null,geom:e.geom,valueFormat:c,layerId:e.owner?.layer.id??i}}function gi(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(o.getStableKey(t.value))?.label??null}function hi(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(o.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=yi(i,r);return i===void 0||s===null?n:k({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function yi(e,t){if(e===void 0)return null;for(const r of t){const n=e.mapping[r];if(n===void 0)continue;const a=o.readVariableName(n);if(a!==null)return a}return null}function vi(e,t,r,n){if(t>1)return!1;const a=n.type==="polar";return r.some(i=>e.get(i.geom).legend.suppressWhenSingleItem||a)}function bi(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,c=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,o.isStackedPosition(u.position)&&(c=!0))}const l=r>=ri;return i&&s?"top":i?l?"right":"top":c?Ai(a)?"top":l?"right":"top":"top"}function Si(e,t){return e==="pill"?"pill":Zt(t)?"direct":"pill"}function Ai(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Ti(e){const t=e.scale.domain.map(o.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Ii(e,t){return Re(t)?"discrete":`continuous:${e}`}function Ei(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(o.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(l=>o.isDefined(o.getYMax(l))||o.isDefined(o.getY(l)));if(!n)return;const a=Z(n);if(!o.isDefined(a))return;const i=o.getYMin(n),s=o.getYMax(n)??o.getY(n);if(!o.isDefined(s))return;const c=o.isDefined(i)?(i+s)/2:s;t.set(String(a),c)}),t}var Vi=class extends o.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.scales,e.config.axes,e.config.legend,e.config.headline,e.layers,e.coordSystem,e.originalData]}run(e){const t=da(e.originalData),r=ka({scales:e.scales,layers:e.layers,valueLabels:pa(e.originalData,e.layers,t)}),n={scales:e.scales,config:e.config,layers:e.layers,coordSystem:e.coordSystem,variableLabels:t,colorGroups:r,geomRegistry:this.container.geomRegistry},a=Ga(n),i=ni(n),s={...i,drawn:xi(a,i.drawn)};return{axes:xa(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},xi=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Ie=(e,t,r)=>{switch(e){case"series":return Oi(t);case"x-value":return ke(t,r)}},er=e=>{const t=o.readMainAxisVariable(e);return t===""?null:t},Oi=e=>o.getStableKey([Z(e)]),ke=(e,t)=>o.getStableKey([t!==null?e[t]??null:null]);function tr(e){return e===null?null:{strategy:e,composition:rr()}}function rr(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var wi=class extends B{constructor(e){super(),this.container=e,this.warningsByLayer=new WeakMap}compile(e){const t=super.compile(e);for(const r of t)for(const n of this.warningsByLayer.get(r)??[])this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.highlights,e.config.parsingLocale]}compileLayer(e,t){const r=e.highlight;if(r===null)return e;const n=t.highlights.filter(({layerId:c})=>c===void 0||c===e.id);if(n.length===0)return e;const a=[],i=Li({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,warnings:a}),s={...e,highlight:{...r,composition:i}};return this.warningsByLayer.set(s,a),s}};function Li({layer:e,highlights:t,parsingLocale:r,strategy:n,warnings:a}){const i=t.filter(S=>{const x=R(S.predicate,e.data);for(const O of x)a.push({...O,message:`${O.message} Dropping this highlight.`});return x.length===0}),s=er(e.mapping),c=pe(e,r),l=i.map(S=>({predicate:N(S.predicate,c),scope:S.scope})),u=l.some(({scope:S})=>S==="series"),d=l.some(({scope:S})=>S==="x-value"),p=n==="overlay-anchor",f=e.data.size(),h=u?new Array(f):null,m=d?new Array(f):null,v=p?new Array(f):null,y=new Uint8Array(f),g=new Set,b=new Set;let C=!1,T=0;for(const S of e.data){let x,O;h!==null&&(x=Ie("series",S,s),h[T]=x),m!==null&&(O=Ie("x-value",S,s),m[T]=O),v!==null&&(v[T]=S);for(const{predicate:re,scope:ne}of l)if(re(S))switch(ne){case"series":x!==void 0&&g.add(x);break;case"x-value":O!==void 0&&b.add(O);break;case"data-point":y[T]=1,C=!0;break}T++}if(g.size===0&&b.size===0&&!C)return rr();const E=new Uint8Array(f),W=[];let $=0;for(let S=0;S<f;S++){const x=h?.[S],O=m?.[S],re=x!==void 0&&g.has(x),ne=O!==void 0&&b.has(O),qe=y[S]===1;if(n==="observation-rerender")(re||qe||ne)&&(E[S]=1,$++);else if(re)E[S]=1,$++;else if(qe||ne){const He=v?.[S];He!==void 0&&W.push({observation:He,observationIndex:S})}}const U=$>0?{...e,data:e.data.filterByMask(E)}:null;return{isDimmed:(n==="observation-rerender"||g.size>0)&&U!==null,matchedLayer:U,overlayCandidates:W}}var Ci=o.prefixInternalVariable("__ungrouped__");function _i(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&o.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,c=i.map((l,u)=>{if(l===null)return null;const d=r[u]??Ci;let p=s.get(d);return p||(p=new o.ChronologicalDateManager,s.set(d,p)),p.incrementYearIfNeeded(l)});n=n.addVariable(a,"temporal",c)}return n}var nr=()=>({defaults:[],overrides:[],warnings:[],observation:{vocabulary:o.STYLE_TARGETS.geom.vocabulary,aesthetics:o.STYLE_TARGETS.geom.aesthetics},dashPresets:o.DASH_PRESETS.line,parts:{}}),Pi=class extends B{constructor(e,t,r,n,a,i){super(),this.container=e,this.transformCompiler=t,this.statCompiler=r,this.groupCompiler=n,this.geomCompiler=a,this.positionAdjusterCompiler=i}dependencies(e){return[e.data,e.mapping,it(e),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},xScaleIsDiscrete:it(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=de({data:t,mapping:r}).pipe(({data:c,mapping:l})=>{const u=this.statCompiler.compute(e.stat,{data:c,mapping:l,xScaleIsDiscrete:n,params:{...e.params},requiredAesthetics:o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(e.geom))});return{data:u.data,mapping:u.mapping}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>({data:_i(c),mapping:l})).pipe(({data:c,mapping:l})=>{const u=this.geomCompiler.compile(e.geom,{data:c,mapping:l,params:e.params,coordType:a});return{data:u.data,mapping:{...l,...u.mapping}}}).pipe(({data:c,mapping:l})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:c,mapping:l});return{data:u.data,mapping:{...l,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,scaleConstraints:s.scaleConstraints,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:tr(s.highlightStrategy),styles:nr()}}};function it(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function ar(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new o.UserInputError(r)}}function Be(e,t){return t.map(r=>({...r,scaleConstraints:e.has(r.geom)?e.get(r.geom).scaleConstraints:void 0}))}function Di(e){return e.some(t=>o.isStackedPosition(t.position)||t.scaleConstraints?.bandPadding===0)}function $e(e){const t=ir(e),r={};for(const{layer:a,scaleConstraints:i,crossAxis:s}of t)i.zeroBaseline===!0&&(r[s]={nice:(r[s]?.nice??!0)&&a.position!=="fill"});const n=t.find(({scaleConstraints:a})=>a.discreteCrossAxis===!0);return{discreteAxis:t.some(({scaleConstraints:a})=>a.discreteMainAxis===!0)?"x":null,discreteCrossAxis:n?.crossAxis??null,bandedAxes:Ri(t),zeroAxes:r,bandPadding:Mi(t),inferredColor:t.some(({scaleConstraints:a})=>a.inferredColor===!0)}}function Ni(e){const t=ir(e);for(const r of t){if(r.scaleConstraints.discreteCrossAxis!==!0)continue;const n=t.find(a=>a.scaleConstraints.zeroBaseline===!0&&a.crossAxis===r.crossAxis);if(n!==void 0)return{crossAxis:r.crossAxis,banded:ot(r),zeroAnchored:ot(n)}}return null}var ot=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function ir(e){const t=[];return e.forEach((r,n)=>{const{scaleConstraints:a,yScaleType:i}=r;a!==void 0&&t.push({layer:r,index:n,scaleConstraints:a,crossAxis:o.resolveYScaleAesthetic(i)})}),t}function Ri(e){const t=new Set;for(const{scaleConstraints:r,crossAxis:n}of e)r.discreteMainAxis===!0&&t.add("x"),r.discreteCrossAxis===!0&&t.add(n);return[...t]}function Mi(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of ki(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function ki({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var Bi=new Set(["label","group"]),$i=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},s={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const c=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const l of c)this.container.diagnostics.addWarning(l)}),t.push(...this.validateSharedScaleDemands(e.layers)),ar(this.container.diagnostics,t)}checkPostCompile(e){Ct(e)&&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),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:c}=i;if(!c||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!o.hasMultipleGroups(r,t))return[];const l=s==="panel-end"?"end":"start";return[{code:"DATA_LABEL_PLACEMENT_COERCED",message:`Multiple ${e} groups would all pin their labels to the same panel edge; justify '${s}' will render as '${l}'.`,context:{layerIndex:n,expected:l,actual:s},suggestion:`Use justify '${l}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],s=o.deriveGeomRequiredAesthetics(this.container.geomRegistry.get(r)),{computedVariables:c}=this.statRegistry.get(n.type);for(const l of s)c.has(l)||o.isDefined(a[l])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${l}'`,context:{layerIndex:t,aesthetic:l}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:c}=this.statRegistry.get(n.type),{derivedVariables:l}=this.container.geomRegistry.get(r),u=new Set(l);for(const[d,p]of Object.entries(a)){if(c.has(d))continue;const f=o.readVariableName(p);f===null||f===""||u.has(f)||i.hasVariable(f)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${d}' references variable '${f}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:d,variableName:f}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(n.type),l=[];for(const u of s){if(!o.POSITION_NUMERIC_ROLES.has(u.role)||!o.isDefined(u.aes)||c.has(u.aes)||u.role==="scalar"&&u.aes===u.axis)continue;const d=o.readVariableName(a[u.aes]);if(d===null||!i.hasVariable(d)||i.size()===0)continue;const p=i.getType(d);p!=="numeric"&&l.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${u.aes}' must be numeric, but variable '${d}' is ${p}`,context:{layerIndex:t,aesthetic:u.aes,variableName:d,variableType:p},suggestion:this.suggestNumericAestheticFix(u.aes,u.axis,a,i)})}return l}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=o.readVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(c=>({...c,message:`Layer '${e}': ${c.message}`,context:{...c.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Ni(Be(this.container.geomRegistry,e));if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:c}=this.statRegistry.get(n.type),l=new Set([...o.deriveDeclaredAesthetics(i),...s.map(p=>p.name)]),u=Bi,d=[];for(const p of Object.keys(a))o.isDefined(a[p])&&(l.has(p)||u.has(p)||c.has(p)||d.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return d}},Ui=class extends o.Stat{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.x);if(!o.isDefined(r))throw new o.UserInputError({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(o.readVariableName(t.y)!==null)throw new o.UserInputError({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 n=[...new Set([r,...o.getGroupVariables(e,t)])];return{data:e.groupBy(...n).rollup({[o.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:o.STAT_VARIABLES.count}}}},Fi=class extends o.Stat{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},ji=class extends o.Stat{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({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."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const n=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'mean' stat requires a numeric 'y' (got '${n}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:n},suggestion:"Map a numeric variable to 'y' when using the 'mean' stat."})}return{data:e.size()===0?new o.Dataset({[o.STAT_VARIABLES.mean]:{type:"numeric",values:[]}}):e.rollup({[o.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:o.STAT_VARIABLES.mean}}}},Gi=2,or=1440*60*1e3,Ki=class extends o.Stat{constructor(...e){super(...e),this.type="smooth",this.computedVariables=new Set}computeStat({data:e,mapping:t,spec:r,xScaleIsDiscrete:n}){if(r.type!=="smooth")throw new o.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=o.readVariableName(t.x),i=o.readVariableName(t.y);if(!o.isDefined(a))throw new o.UserInputError({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(!o.isDefined(i))throw new o.UserInputError({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 s=e.getType(a),c=e.getType(i);if(e.size()>0&&c!=="numeric")throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:c}});const l=o.getGroupVariables(e,t),u=Ji(a,s,i,l,e);return l.length===0?st({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...l).forEach(d=>{const p=Qi(d,l);st({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:p,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},st=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:c})=>{const{observations:l,temporalOrigin:u}=Yi({data:e,xVariable:t,yVariable:n,xType:r});l.length<Gi||(c?Xi({observations:l,spec:a,output:i,groupObservation:s}):qi({observations:l,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},Yi=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?zi(a):null,c=[],l=new Map;for(let u=0;u<a.length;u++){const d=a[u],p=i[u];if(!o.isDefined(d)||!o.isDefined(p)||!Number.isFinite(p))continue;const f=Wi({xValue:d,xType:n,categoryRank:l,temporalOrigin:s});f!==null&&c.push({x:f,y:p,originalX:d})}return{observations:c,temporalOrigin:s}},zi=e=>{let t=null;for(const r of e){if(!o.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Wi=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!o.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!o.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/or+1}case"categorical":{if(!o.isStrictCategoricalDataValue(e))return null;const a=r.get(e);if(a!==void 0)return a;const i=r.size+1;return r.set(e,i),i}default:throw new o.InternalError({message:`Unexpected xType: ${t}`})}},qi=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=sr(n,e);for(const[c,l]of s){if(!Number.isFinite(c)||!Number.isFinite(l))continue;const u=t==="temporal"?Hi(c,r):c;a.push({x:u,y:l,groupObservation:i})}},Hi=(e,t)=>t===null?new Date(e):new Date((e-1)*or+t),Xi=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const c of e)a.has(c.x)||a.set(c.x,c.originalX);const i=[...a.keys()].sort((c,l)=>c-l);if(t.method==="loess"){const c=sr(t,e),l=new Map;for(const[u,d]of c)Number.isFinite(d)&&(l.has(u)||l.set(u,d));for(const u of i){const d=l.get(u),p=a.get(u);d===void 0||p===void 0||r.push({x:p,y:d,groupObservation:n})}return}const s=cr(t,e);for(const c of i){const l=a.get(c),u=s.predict(c);l===void 0||!Number.isFinite(u)||r.push({x:l,y:u,groupObservation:n})}},sr=(e,t)=>e.method==="loess"?(0,D.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):cr(e,t),cr=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,D.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,D.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,D.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,D.regressionQuad)().x(r).y(n)(t);case"power":return(0,D.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,D.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new o.InternalError({message:"'loess' does not expose a 'predict' function"})}},Ji=(e,t,r,n,a)=>{const i=[],s=[],c=Object.fromEntries(n.map(l=>[l,[]]));return{push:({x:l,y:u,groupObservation:d})=>{i.push(l),s.push(u);for(const p of n)c[p]?.push(d[p]??null)},build:()=>{const l={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)l[u]={type:a.getType(u),values:c[u]??[],valueFormat:a.getValueFormat(u)};return new o.Dataset(l)}}},Qi=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Zi=class extends o.Stat{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=o.readVariableName(t.y);if(!o.isDefined(r))throw new o.UserInputError({code:"MISSING_STAT_VARIABLE",message:"'y' variable is required for 'sum' stat",context:{aesthetic:"y"},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."});if(e.size()>0&&e.hasVariable(r)&&e.getType(r)!=="numeric"){const i=e.getType(r);throw new o.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'sum' stat requires a numeric 'y' (got '${i}' for variable '${r}')`,context:{aesthetic:"y",variableName:r,variableType:i},suggestion:"Map a numeric variable to 'y' when using the 'sum' stat."})}const n=o.readVariableName(t.x),a=[...new Set([...n===null?[]:[n],...o.getGroupVariables(e,t)])];return{data:e.groupBy(...a).rollup({[o.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:o.STAT_VARIABLES.sum}}}},eo=[new Fi,new Ui,new Ki,new ji,new Zi],to=class extends o.Registry{constructor(){super("stat");for(const e of eo)this.register(e.type,e)}};function ro({geoms:e,stats:t,transforms:r}){const n=new o.GeomRegistry,a=new to,i=new o.TransformRegistry;for(const s of e)n.register(s.type,s);for(const s of t)a.register(s.type,s);for(const s of r)i.register(s.transformType,s);return{geomRegistry:n,statRegistry:a,transformRegistry:i}}var no=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},me=class{},ao=class extends me{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!o.readVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),i=io(e)??[-.7/2,.7/2],s=r.length>1?o.BAR_GROUP_SCALE_PADDING_FRACTION:0,c=(0,w.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),l=c.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let p=0;p<n;p++){const f=a[p];if(!o.isDefined(f))continue;const h=c(String(f));o.isDefined(h)&&(u[p]=h,d[p]=h+l)}return{data:e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",u).addVariable(o.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},io=e=>{const t=e.getConstant(o.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(o.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},ct=o.prefixInternalVariable("__ungrouped__"),lr=(e,t)=>{const r=o.readVariableName(t.x),n=o.readVariableName(t.y);if(!r||!n)return null;const a=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[ct]:a,c=e.getValues(r),l=e.getValues(n,{type:"numeric"}),u=e.getValues(o.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),p=new Map;for(let f=0;f<d;f++){const h=o.getStableKey(c[f]??null),m=u[f],v=i?ct:m;if(!o.isDefined(v))continue;let y=p.get(h);y||(y=new Map,p.set(h,y));let g=y.get(v);g||(g=[],y.set(v,g)),g.push(f)}return{yValues:l,observationIndicesByXAndGroup:p,uniqueGroupKeys:s,observationCount:d}},ur=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let c=-1,l=1/0,u=-1/0,d=-1,p=1/0,f=-1/0;for(const h of i.values())for(const m of h){const v=e[m],y=t[m];!o.isDefined(v)||!o.isDefined(y)||(s.push(m),(v<l||v===l&&y>u)&&(c=m,l=v,u=y),(y>f||y===f&&v<p)&&(d=m,p=v,f=y))}for(const h of s)a[h]=oo(h===c,h===d)}return a},oo=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",so=class extends me{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=lr(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,c=[...n],l=new Array(s).fill(0);for(const[,d]of a){let p=0,f=0;for(const v of i){const y=d.get(v);if(y!==void 0)for(const g of y){const b=n[g];b!=null&&(b>=0?p+=b:f-=b)}}let h=0,m=0;for(const v of i){const y=d.get(v);if(y!==void 0)for(const g of y){const b=n[g];if(b===void 0)continue;if(b===null){l[g]=null,c[g]=null;continue}const C=b>=0?p:f;if(C===0){l[g]=0,c[g]=0;continue}const T=b/C;b>=0?(l[g]=h,c[g]=h+=T):(c[g]=m,l[g]=m+=T)}}}const u=ur(l,c,a,s);return{data:e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",l).addVariable(o.POSITION_VARIABLES.yMax,"numeric",c).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(o.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},co=class extends me{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},lo=class extends me{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=lr(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,c=[...n],l=new Array(s).fill(0);for(const[,f]of a){let h=0,m=0;for(const v of i){const y=f.get(v);if(y!==void 0)for(const g of y){const b=n[g];if(b!==void 0){if(b===null){l[g]=null,c[g]=null;continue}b>=0?(l[g]=h,c[g]=h+=b):(c[g]=m,l[g]=m+=b)}}}}const u=ur(l,c,a,s);let d=e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",l).addVariable(o.POSITION_VARIABLES.yMax,"numeric",c).addVariable(o.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(o.STACK_VARIABLES.role,"categorical",u);const p=o.readVariableName(t.y);return p!==null&&(d=d.addVariable(p,"numeric",c)),{data:d,mapping:{}}}},uo=class extends o.Registry{constructor(){super("position"),this.register("identity",new co),this.register("stack",new lo),this.register("fill",new so),this.register("dodge",new ao)}},po=class{map({data:e,layer:t,getPositionScale:r,geomRegistry:n}){let a=e;const i=n.get(t.geom);for(const s of i.positionRoles){if(s.role!=="scalar"||!o.isDefined(s.aes)||o.isVisualScale(s.aes))continue;const c=o.readVariableName(t.mapping[s.aes]);if(!o.isDefined(c)||!a.hasVariable(c))continue;const l=r(o.resolvePositionScaleAesthetic(s.axis,t.yScaleType));if(!l)continue;const u=a.getValues(c,{type:"numeric"}).map(d=>o.isDefined(d)?l.map(d):null);a=a.addVariable(o.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},mo=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.x,"numeric",i)}},fo=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r||!e.hasVariable(o.POSITION_VARIABLES.xMin)||!e.hasVariable(o.POSITION_VARIABLES.xMax))return e;const n=r.bandwidth,a=o.isDefined(n)&&e.hasVariable(o.POSITION_VARIABLES.x)?go(e,r,n):ho(e,r);return e.addVariable(o.POSITION_VARIABLES.xMin,"numeric",a.min).addVariable(o.POSITION_VARIABLES.xMax,"numeric",a.max)}};function go(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.x,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=dr(c);for(let u=0;u<c;u++){const d=n[u],p=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||(l.min[u]=d+(s?-f:p)*r,l.max[u]=d+(s?-p:f)*r)}return l}function ho(e,t){const r=e.getValues(o.POSITION_VARIABLES.xMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.xMax,{type:"numeric"}),a=e.size(),i=dr(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function dr(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var yo=class{map({data:e,layer:t,getPositionScale:r}){const n=o.readVariableName(t.mapping.y),a=r(o.resolveYScaleAesthetic(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>o.isDefined(s)?a.map(s):null);return e.addVariable(o.POSITION_VARIABLES.y,"numeric",i)}},vo=class{map({data:e,layer:t,getPositionScale:r}){const n=r(o.resolveYScaleAesthetic(t.yScaleType));if(!n||!e.hasVariable(o.POSITION_VARIABLES.yMin)||!e.hasVariable(o.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=o.isDefined(a)&&e.hasVariable(o.POSITION_VARIABLES.y)?bo(e,n,a):So(e,n);return e.addVariable(o.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(o.POSITION_VARIABLES.yMax,"numeric",i.max)}};function bo(e,t,r){const n=e.getValues(o.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,c=e.size(),l=pr(c);for(let u=0;u<c;u++){const d=n[u],p=a[u],f=i[u];!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||(l.min[u]=d+(s?-f:p)*r,l.max[u]=d+(s?-p:f)*r)}return l}function So(e,t){const r=e.getValues(o.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(o.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=pr(a);for(let s=0;s<a;s++){const c=r[s],l=n[s];!o.isDefined(c)||!o.isDefined(l)||(i.min[s]=t.map(c),i.max[s]=t.map(l))}return i}function pr(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Ao=[new mo,new yo,new fo,new vo,new po];function To(e,t){const r=e[t];return r?.kind==="position"?r:null}var Io=class extends B{constructor(e,t=Ao){super(),this.container=e,this.mappers=t}dependencies(e){return[e.scales.x,e.scales.y,e.scales.ySecondary]}compileLayer(e,t){const r=a=>To(t.scales,a);let n=e.data;for(const a of this.mappers)n=a.map({data:n,layer:e,getPositionScale:r,geomRegistry:this.container.geomRegistry});return{...e,data:n}}},Eo=class extends o.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales,e.colorScheme]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const i of e.scales)t.set(i.scaledAesthetic,i);const r=this.collectValues(e.layers,t),n={colorScheme:e.colorScheme,hasTouchingGeoms:Di(e.layers),zeroAxes:$e(e.layers).zeroAxes},a={};for(const[i,s]of t){const c=r.get(i)??[];a[i]=this.registry.get(s.scaleType).compile(s,c,n)}return a}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=o.getAestheticFromScaleAestheticKey(r.scaledAesthetic);for(const i of e.layers){if((r.scaledAesthetic==="y"||r.scaledAesthetic==="ySecondary")&&o.resolveYScaleAesthetic(i.yScaleType)!==r.scaledAesthetic||!o.isDefined(i.mapping[a]))continue;const s=o.readVariableName(i.mapping[a]);if(!o.isDefined(s)||o.isInternalVariable(s)||!i.data.hasVariable(s)||i.data.size()===0)continue;const c=i.data.getType(s);if(!n.includes(c)){const l=r.scaleType==="continuous"&&c==="temporal"?`Use scale.${r.scaledAesthetic}.datetime() for a time axis or declare the column's valueFormat in data.columns to read it as a number.`:void 0;t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${c})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}if(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.";t.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${s}'. ${l}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:c},suggestion:l})}}}ar(this.container.diagnostics,t)}collectValues(e,t){const r=new Map;for(const n of e){const a=this.resolveCustomPositionalAxes(n);for(const[i,s]of Object.entries(n.mapping)){if(!o.isDefined(s))continue;const c=i==="y"?o.resolveYScaleAesthetic(n.yScaleType):i,l=a.get(i)??(o.isScaledAestheticKey(c)?c:void 0);if(!o.isDefined(l)||!t.has(l))continue;const u=t.get(l)?.scaleType,d=this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,l,r)}}return r}resolveCustomPositionalAxes(e){const t=new Map,r=this.container.geomRegistry.get(e.geom);for(const n of r.positionRoles)n.role!=="scalar"||!o.isDefined(n.aes)||o.isVisualScale(n.aes)||t.set(n.aes,o.resolvePositionScaleAesthetic(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[o.POSITION_VARIABLES.yMin,o.POSITION_VARIABLES.yMax];const a=o.readVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(e){return e.hasVariable(o.POSITION_VARIABLES.yMin)&&e.hasVariable(o.POSITION_VARIABLES.yMax)}collectFromVariables(e,t,r,n){if(t.length===0)return;let a=[];for(const s of t)a=a.concat(e.getValues(s));const i=n.get(r);n.set(r,i?i.concat(a):a)}},Vo=["rgb","lab","hcl","hsl"],xo=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],mr=["RdBu","BrBG","PuOr","Spectral"],fr={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Oo=new Set(mr.map(e=>e.toLowerCase()));function gr(e){const t=e.toLowerCase(),r=fr[t];return r?r.toLowerCase():t}function wo(e){return Oo.has(gr(e))}var Lo={rgb:Y.interpolateRgb,lab:Y.interpolateLab,hcl:Y.interpolateHcl,hsl:Y.interpolateHsl},Co={viridis:A.interpolateViridis,magma:A.interpolateMagma,inferno:A.interpolateInferno,plasma:A.interpolatePlasma,cividis:A.interpolateCividis,turbo:A.interpolateTurbo,blues:A.interpolateBlues,greens:A.interpolateGreens,greys:A.interpolateGreys,oranges:A.interpolateOranges,purples:A.interpolatePurples,reds:A.interpolateReds,rdbu:A.interpolateRdBu,brbg:A.interpolateBrBG,puor:A.interpolatePuOr,spectral:A.interpolateSpectral};function Ue(e){const t=Po(e);return e.reverse?r=>t(1-r):t}function _o(e={},t=2){const r=Ue({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??o.CONTINUOUS_SCALE_DEFAULTS.interpolate,reverse:e.reverse??!1});return t<2?t===1?[r(0)]:[]:Array.from({length:t},(n,a)=>r(a/(t-1)))}function Po(e){const t=Lo[e.interpolate];if(e.range&&e.range.length>=2)return(0,Y.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Co[gr(e.scheme)];if(r)return r}return(0,Y.piecewise)(t,[...o.DEFAULT_SEQUENTIAL_RAMP])}var ee=class{createPositionScale(e,t){return{kind:"position",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,...t}}},Ee=(e,t,r)=>{const[n,a]=e;return t===0&&r===null&&a<=0?{domain:[n,0],pinnedLow:!1,pinnedHigh:!0}:r===0&&t===null&&n>=0?{domain:[0,a],pinnedLow:!0,pinnedHigh:!1}:{domain:[t??n,r??a],pinnedLow:t!==null,pinnedHigh:r!==null}};function Do(e){const[t,r]=e.domain;return t>0?{...e,domain:[0,r],pinnedLow:!0}:r<0?{...e,domain:[t,0],pinnedHigh:!0}:e}function Ve(e,t){return[t.pinnedLow?t.domain[0]:e[0],t.pinnedHigh?t.domain[1]:e[1]]}var No=class extends ee{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t,r){if(e.scaleType!=="continuous")throw new o.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const n=o.isPositionScale(e.scaledAesthetic),a=e.scaledAesthetic==="color",i=this.computeDataDomain(t);return a?this.buildColorScale(i,e):n?this.buildPositionScale(i,e,r.zeroAxes[e.scaledAesthetic]!==void 0):this.buildVisualScale(i,e)}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e)typeof n!="number"||!Number.isFinite(n)||(n<t&&(t=n),n>r&&(r=n));return t===1/0?[0,0]:[t,r]}createD3Scale(e,t,r,n=!1){const a=Ee(e,r.domainMin,r.domainMax),i=n?Do(a):a;let s=i.domain;n&&Ro(a,i)&&this.warnIncompatibleDomain(r,a.domain,`'${r.scaledAesthetic}' holds zero for the geom drawn on it, so the pin at [${a.domain[0]}, ${a.domain[1]}] gives way to [${s[0]}, ${s[1]}].`,`Pin '${r.scaledAesthetic}' at or past zero, or drop the pin.`);const c=r.transform==="log"&&Mo(s);r.transform==="log"&&!c&&this.warnIncompatibleDomain(r,s,`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${s[0]}, ${s[1]}] — rendering a linear scale instead.`,n?`'${r.scaledAesthetic}' holds zero for the geom drawn on it; use a linear or sqrt transform.`:"Filter out non-positive values or set a positive domainMin so the log scale can apply.");const l=c?(0,w.scaleLog)():r.transform==="sqrt"?(0,w.scaleSqrt)():(0,w.scaleLinear)();return r.nice&&!c&&(s=Ve(l.copy().domain(s).nice().domain(),i)),l.domain(s).range(t).clamp(r.clamp)}warnIncompatibleDomain(e,t,r,n){this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:r,context:{aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),scaleType:e.scaleType,actual:t},suggestion:n})}buildPositionScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t,r);return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildVisualScale(e,t){const r=ko(t.range)??[0,1],n=t.reverse?[r[1],r[0]]:r,a=this.createD3Scale(e,n,t);return this.createVisualScale(t,{map:a,domain:a.domain(),generateTicks:i=>i&&"count"in i?a.ticks(i.count):a.ticks()})}buildColorScale(e,t){const r=Ue(t),n=t.domainMid;if(n!==null){const a=this.resolveColorDomain(e,t),[i,s]=a.domain;if(n>i&&n<s){const[c,l]=this.symmetrizeDomain(a,t,n);return this.buildDivergingColorScale([c,n,l],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,w.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){const r=Ee(e,t.domainMin,t.domainMax);if(!t.nice)return r;const n=(0,w.scaleLinear)().domain(r.domain).nice().domain();return{...r,domain:Ve(n,r)}}symmetrizeDomain(e,t,r){const{domain:n,pinnedLow:a,pinnedHigh:i}=e;if(!t.symmetric)return n;const s=Math.max(Math.abs(n[0]-r),Math.abs(n[1]-r));return[a?n[0]:r-s,i?n[1]:r+s]}},Ro=(e,t)=>e.pinnedLow&&e.domain[0]!==t.domain[0]||e.pinnedHigh&&e.domain[1]!==t.domain[1],Mo=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function ko(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Bo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new o.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=o.isPositionScale(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new o.UserInputError({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(n,e,this.collectInputDates(t))}collectInputDates(e){const t=new Set,r=[];for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();t.has(a)||(t.add(a),r.push(n))}return r.sort((n,a)=>n.getTime()-a.getTime()),r}computeDataDomain(e){let t=1/0,r=-1/0;for(const n of e){if(!(n instanceof Date))continue;const a=n.getTime();a<t&&(t=a),a>r&&(r=a)}return t===1/0?[]:[new Date(t),new Date(r)]}createD3Scale(e,t,r){const n=(0,w.scaleUtc)().range(t).clamp(r.clamp);if(!$o(e))return n.domain([]);const a=Ee([e[0].getTime(),e[1].getTime()],r.domainMin,r.domainMax);if(n.domain(a.domain),r.nice){const[i,s]=n.nice().domain();i!==void 0&&s!==void 0&&n.domain(Ve([i.getTime(),s.getTime()],a))}return n}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),c=i&&s?r.filter(l=>l>=i&&l<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?i&&s?ya(i,s,l.interval):[]:a.ticks(l?.count)})}},$o=e=>e.length===2&&o.isStrictTemporalDataValue(e[0])&&o.isStrictTemporalDataValue(e[1]),Uo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new o.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=o.isPositionScale(e.scaledAesthetic),n=Gt(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??o.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,w.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:c=>(i(String(c))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,w.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},Fo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new o.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:o.getAestheticFromScaleAestheticKey(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},jo=class extends ee{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t,r){if(e.scaleType!=="palette")throw new o.InternalError({message:"PaletteScale.compile received non-palette spec"});const n=jt(t),a=o.resolvePaletteRange(e.palette,{groupCount:n.length,...r}),i=o.applyOverrides(a.length>0?a:[...o.DEFAULT_COLOR_PALETTE],e.overrides),s=(0,w.scaleOrdinal)().domain(n.map(String)).range(i).unknown(i[0]);return this.createVisualScale(e,{map:c=>s(String(c)),domain:n,generateTicks:()=>n})}},Go=class extends o.Registry{constructor(e){super("scale"),this.register("continuous",new No(e)),this.register("discrete",new Uo),this.register("datetime",new Bo),this.register("identity",new Fo),this.register("palette",new jo)}},hr={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ko={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Fe(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:$e(Be(e.geomRegistry,n))}}function fe(e,t){switch(t.scaleType){case"inferred":return{...fe(e,qo(e,t)),inferredFrom:t};case"continuous":{const r=hr[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in o.NON_POSITION_RANGE_DEFAULTS?o.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":o.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,reverse:t.reverse??o.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??o.CONTINUOUS_SCALE_DEFAULTS.nice,clamp:t.clamp??r!=="position",domainMin:t.domainMin??o.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??o.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:Ho(e.container,t),interpolate:t.interpolate??o.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??o.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??o.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??o.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??o.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??o.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??o.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return yr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:o.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:o.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new o.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Yo(e,t){const{scales:r,layers:n,coords:a}=t,i=Fe(e,t),s=Zo(Qo(r,n),i.demands),c=new Map;for(const u of s)c.set(u.scaledAesthetic,u);const l=[...c.values()].map(u=>{const d=zo(i,u);return fe(i,d)});return a.coordType==="polar"?l.map(je):l}function yr(e,t){const r=t?.bandPadding[e.scaledAesthetic];return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??o.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??o.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??r??o.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??Wo(e.scaledAesthetic,t)}}var je=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function zo(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),o.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Wo(e,t){return e===t?.discreteCrossAxis?!0:o.DISCRETE_SCALE_DEFAULTS.reverse}function qo({data:e,layers:t,mapping:r,demands:n},a){const i=Xo(t,r,a.scaledAesthetic);if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return o.discrete(a.scaledAesthetic,a.options);const s=n.zeroAxes[a.scaledAesthetic];if(s!==void 0){const d=a.options;return o.continuous(a.scaledAesthetic,{...d,...!s.nice&&{nice:!1}})}const c=o.readVariableName(i);if(!o.isDefined(c)||!e.hasVariable(c)||e.size()===0)return o.continuous(a.scaledAesthetic,a.options);const l=e.getType(c),u=hr[a.scaledAesthetic];switch(Ko[l][u]){case"discrete":return o.discrete(a.scaledAesthetic,a.options);case"palette":return o.palette(a.scaledAesthetic);case"datetime":return o.datetime(a.scaledAesthetic,a.options);case"continuous":return o.continuous(a.scaledAesthetic,a.options);default:return o.identity(a.scaledAesthetic)}}function Ho(e,t){const r=t.scheme??o.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:o.isDefined(t.range)?(e.diagnostics.addWarning({code:"CONFLICTING_COLOR_RAMP",message:`The color scale sets both a 'scheme' ('${r}') and an explicit 'range'; the range wins and the scheme is ignored.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!o.isDefined(t.domainMid)&&wo(r)&&e.diagnostics.addWarning({code:"DIVERGING_SCHEME_WITHOUT_MIDPOINT",message:`The color scale uses a diverging scheme ('${r}') without 'domainMid', so its neutral colour lands at the data midpoint rather than a meaningful centre.`,context:{aesthetic:o.getAestheticFromScaleAestheticKey(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Xo(e,t,r){const n=o.getAestheticFromScaleAestheticKey(r);for(const a of Jo(r,e)){const i=a.mapping[n]??t[n];if(o.isDefined(o.readVariableName(i)))return i}return t[n]}function Jo(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}function Qo(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,o.inferred("ySecondary")]}function Zo(e,t){return e.some(r=>r.scaledAesthetic==="color")?e:[...e,t.inferredColor?o.inferred("color"):o.palette("color")]}var Ge=class extends o.Stage{constructor(e){super(),this.registry=e}key(e){return e.data}dependencies(e){return[e.transforms]}run(e){return e.transforms.reduce((t,r)=>this.registry.get(r.transformType).apply(t,r),e.data)}},vr=new o.TransformRegistry,es=new Ge(vr),br=(e,t)=>{const r=t.every(n=>vr.has(n.transformType));return t.length===0||!r?e:es.compile({data:e,transforms:t})},lt=0;function I(){return lt+=1,`${Math.random().toString(36).slice(2,6)}${lt.toString(36)}`}var ts={top:{x:0,y:-1},bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},"top-left":{x:-1,y:-1},"top-right":{x:1,y:-1},"bottom-left":{x:-1,y:1},"bottom-right":{x:1,y:1}},rs=(e,t,r)=>{const n=ns(e,t),a=os(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>cs(e,i,r)).filter(o.isDefined),shapes:(n.shapes??[]).map(i=>ps(e,i,a)).filter(o.isDefined),arrows:(n.arrows??[]).map(i=>gs(e,i,r,a)).filter(o.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>ss(e,i,r,a)).filter(o.isDefined),stickers:(n.stickers??[]).map(i=>ls(e,i,r,a)).filter(o.isDefined),images:(n.images??[]).map(i=>ms(e,i,a)).filter(o.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>us(e,i,r)).filter(o.isDefined),comments:(n.comments??[]).map(i=>ds(e,i,r)).filter(o.isDefined)}},ns=(e,t)=>{if(t===void 0)return{};if(!as(t))return t;const r=new Set,n=a=>a.id===void 0?a:r.has(a.id)?(e.diagnostics.addWarning({code:"ANNOTATION_DUPLICATE_ID",message:`More than one annotation declares id "${a.id}" — giving this one a generated id, so references to "${a.id}" point at the first.`,context:{annotationId:a.id},suggestion:"Give each annotation its own id."}),{...a,id:I()}):(r.add(a.id),a);return{differenceArrows:t.differenceArrows?.map(a=>n(a)),shapes:t.shapes?.map(a=>n(a)),arrows:t.arrows?.map(a=>n(a)),textAnnotations:t.textAnnotations?.map(a=>n(a)),images:t.images?.map(a=>n(a)),stickers:t.stickers?.map(a=>n(a)),pinnedNumbers:t.pinnedNumbers?.map(a=>n(a)),comments:t.comments?.map(a=>n(a))}},as=e=>{const t=new Set;for(const r of is(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},is=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],os=e=>{const t=new Set,r=[e.differenceArrows,e.shapes,e.arrows,e.textAnnotations,e.images,e.stickers,e.pinnedNumbers,e.comments];for(const n of r)for(const a of n??[])a.id!==void 0&&t.add(a.id);return t},Ke=(e,t,r,n)=>{if(r.has(t))return!0;const a=n===void 0?"An annotation":`Annotation "${n}"`;return e.diagnostics.addWarning({code:"ANNOTATION_REF_NOT_FOUND",message:`${a} references id "${t}" but no annotation declares that id — dropping this annotation.`,context:{ref:t,...n!==void 0?{annotationId:n}:{}},suggestion:"Reference the explicit id of another annotation in the same spec, or set an id on the target."}),!1},ss=(e,t,r,n)=>{const a=se(e,t.at,r,n,t.id);return a===null?null:{id:t.id??I(),content:t.content,at:a,width:t.width,align:t.align??o.TEXT_ANNOTATION_DEFAULTS.align}},cs=(e,t,r)=>{const n=X(e,t.start,r),a=X(e,t.end,r);return n===null||a===null?null:{id:t.id??I(),start:n,end:a,label:t.label,labelCrossPosition:t.labelCrossPosition??o.DIFFERENCE_ARROW_DEFAULTS.labelCrossPosition}},X=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},se=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return Ke(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=X(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},ls=(e,t,r,n)=>{const a=se(e,t.at,r,n,t.id);return a===null?null:{id:t.id??I(),at:a,sticker:t.sticker}},us=(e,t,r)=>{const n=X(e,t.at,r);return n===null?null:{id:t.id??I(),at:n}},ds=(e,t,r)=>{const n=X(e,t.at,r);return n===null?null:{id:t.id??I(),at:n,content:t.content}},ps=(e,t,r)=>t.region.anchorType==="annotation"&&!Ke(e,t.region.ref,r,t.id)?null:{id:t.id??I(),kind:t.kind??o.SHAPE_DEFAULTS.kind,zOrder:t.zOrder??o.SHAPE_DEFAULTS.zOrder,region:fs(t.region)},ms=(e,t,r)=>t.region.anchorType==="annotation"&&!Ke(e,t.region.ref,r,t.id)?null:{id:t.id??I(),src:t.src,zOrder:t.zOrder??o.IMAGE_ANNOTATION_DEFAULTS.zOrder,region:t.region,fit:t.fit??o.IMAGE_ANNOTATION_DEFAULTS.fit},fs=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:o.SELECTION_PADDING_DEFAULT},ut=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=ts[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},gs=(e,t,r,n)=>{const a=se(e,t.start,r,n,t.id),i=se(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??I(),start:ut(a),end:ut(i),startArrowheadStyle:t.startArrowheadStyle??o.ARROW_DEFAULTS.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??o.ARROW_DEFAULTS.endArrowheadStyle}},hs={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"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:{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,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1}};function ys(e){const t=(0,ce.merge)({},hs,e);return t.content=vs(t.content,e?.content),t}var vs=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},bs={xLimits:null,yLimits:null},ie={theta:"x",startAngle:0,innerRadius:0};function Sr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,ve.default)({},bs,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??ie.theta,startAngle:t.params?.startAngle??ie.startAngle,innerRadius:(0,ye.default)(t.params?.innerRadius??ie.innerRadius,0,1)}}}}function Ss(e,t,r){const n=[];for(const a of t){if(a.layerId!==void 0&&!r.some(i=>i.id===a.layerId)){e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Highlight references layerId "${a.layerId}", which no layer carries — dropping this highlight.`,context:{layerId:a.layerId,available:r.map(i=>i.id)},suggestion:"Reference an existing layer id, or omit layerId to apply the highlight across all layers."});continue}n.push({type:"highlight",id:a.id??I(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var As=class{constructor(){this.diagnostics=[],this.persistent=[]}addWarning(e,t={}){const r={...e,severity:"warning",kind:"user-input"};t.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 t=dt(e.filter(n=>n.severity==="error")),r=dt(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Ts=class{constructor(e,t){this.sink=e,this.baseContext=t}addWarning(e,t){this.sink.addWarning(this.stampBaseContext(e),t)}addError(e){this.sink.addError(this.stampBaseContext(e))}stampBaseContext(e){const t=e.context??{};return{...e,context:{...t,...this.baseContext}}}};function dt(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Ar={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:o.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4},Is={stat:{type:"identity"},position:"identity",params:{}},Es={stat:{type:"identity"},position:"identity",params:{curve:"linear",missingValues:"gap"}},Vs={stat:{type:"identity"},position:"stack",params:{curve:"linear",missingValues:"zero"}},xs={stat:{type:"identity"},position:"dodge",params:{}},Os={stat:{type:"identity"},position:"identity",interactive:!1,params:{labelPosition:"start"}},ws={stat:{type:"identity"},position:"identity",params:{}};function Tr(e,t){const r=e??(typeof t=="string"?t:t.type),n=typeof r=="string"?r:r.type;if(n==="smooth"){const a=typeof r=="string"?void 0:r;return{type:"smooth",method:a?.method??"linear",order:a?.order??3,bandwidth:a?.bandwidth??.3}}return{type:n}}function Ir(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Ts(a,{layerIndex:i}):a,c=e.get(n.geom),l=n.position??c.defaultPosition,u=_s({dataLabels:Ds(e,t,n,l,r),geom:c,position:l,coordType:r,diagnostics:s});return Cs({diagnostics:s,coordType:r,geom:c,position:l,dataLabels:u}),{id:n.id??I(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Tr(n.stat,c.defaultStat??"identity"),position:l,yScaleType:n.yScaleType??"primary",params:c.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??c.defaultInteractive,dataLabels:u}}function Ls(e,t,r,n,a){const i=n.map((s,c)=>Ir(e,t,r,s,a,c));return Vr(e,i)}var Er=(e,t,r,n)=>n.label!==void 0?n.label:_t({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Vr=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:_e(t,n=>{if(!r.has(n.yScaleType)||!e.has(n.geom)||!e.get(n.geom).positionRoles.some(s=>s.axis==="y"&&s.role==="scalar"))return n;const a=o.readConstantValue(n.mapping.y);if(!o.isStrictNumericDataValue(a))return n;const i=(0,ce.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Cs=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t!=="polar";if(a.showDataLabels&&!r.dataLabelCoordTypes.includes(t)){e.addWarning({code:"DATA_LABELS_UNSUPPORTED",message:`Data labels are not supported for geom '${r.type}' under '${t}' coords; none will render.`,suggestion:"Turn off showDataLabels for this layer."});return}a.showDataLabels&&a.position==="outside"&&i&&o.isStackedPosition(n)&&e.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:"Stacked bar segments only place data labels inside; position 'outside' will render as 'inside'.",context:{expected:"inside",actual:"outside"},suggestion:"Use position 'inside' or 'auto', or enable showStackTotals for a label above the stack."}),a.showStackTotals&&!(i&&n==="stack")&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showStackTotals only applies to stacked cartesian bars; it will be ignored.",suggestion:"Turn off showStackTotals, or use a bar geom with position 'stack'."})},_s=({dataLabels:e,geom:t,position:r,coordType:n,diagnostics:a})=>{const{justify:i,showDataLabels:s}=e;if(i!=="panel-start"&&i!=="panel-end")return e;const c=Ps(t,r,n);if(c===null)return e;const l=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${c}; justify '${i}' will render as '${l}'.`,context:{expected:l,actual:i},suggestion:`Use justify '${l}' for this layer.`}),{...e,justify:l}},Ps=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&o.isStackedPosition(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Ds=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Er(e,r.geom,n,i),c=e.get(r.geom);return{...(0,ce.merge)({},Ar,c.resolveDataLabelDefaults?.(n)??{},c.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Ns=e=>{const t={tokens:{},defaults:[],overrides:[]};for(const r of Rs(e))Object.assign(t.tokens,r.tokens),t.defaults.push(...r.defaults??[]),t.overrides.push(...r.overrides??[]);return t},Rs=e=>{const t=[],r=new Set,n=e===void 0?[]:[e];for(;n.length>0;){const a=n.pop();if(!(a===void 0||r.has(a))){r.add(a),t.push(a);for(const i of a.extends??[])n.push(i)}}return t.reverse()};function Ms(e,t,r){const n=Sr(t.coords),a=Ls(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Yo(e,{data:br(t.data,t.transforms),scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=ys(t.config),c=Ss(e,t.highlights,a),l=rs(e,t.annotations,a),u=Ns(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:c,styles:u,annotations:l,coords:n,config:s}}var xr=class{constructor(e){this.container=e}compile({spec:e,dataset:t,customPalettes:r}){return Ms(this.container,{...e,data:t},r)}},ks=()=>{let e={},t=null;return{reset:()=>{e={}},getDuration:r=>e[r]??0,wrap:(r,n)=>a=>{const i=t,s={childrenMs:0};t=s;const c=performance.now();try{return n(a)}finally{const l=performance.now()-c;e[r]=(e[r]??0)+l-s.childrenMs,i&&(i.childrenMs+=l),t=i}}}},Bs=class{constructor(e){this.registry=e}compute(e,t){const r=this.registry.get(e.type),n=r.compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete,params:t.params});return Us(r,n,t.requiredAesthetics),{data:n.data,mapping:{...$s(t,n.data),...n.mapping}}}};function $s({data:e,mapping:t},r){const n={};for(const[a,i]of Object.entries(t)){const s=o.readVariableName(i);s!==null&&e.hasVariable(s)&&!r.hasVariable(s)||(n[a]=i)}return n}function Us(e,{data:t,mapping:r},n){for(const a of n){if(!e.computedVariables.has(a))continue;const i=r[a],s=o.readVariableName(i);if(!(o.isDefined(i)&&(s===null||t.hasVariable(s))))throw new o.UserInputError({code:"MISSING_STAT_OUTPUT",message:`Stat '${e.type}' declares it computes '${a}', which the layer's geom requires, but did not map it to a column of its output`,context:{aesthetic:a,requested:e.type},suggestion:`Return '${a}' in the stat's mapping, naming a column the stat writes.`})}}var Or=Object.keys(o.ANNOTATION_BUCKETS),Fs=e=>Object.hasOwn(o.ANNOTATION_BUCKETS,e),js=(e,t)=>{for(const r of Or){const n=Ks(e,r,t);if(n)return n}return null},Ye=(e,t)=>e[o.ANNOTATION_BUCKETS[t]],wr=(e,t,r)=>({...e,[o.ANNOTATION_BUCKETS[t]]:r}),Gs=(e,t)=>{const r=Ye(e,t.kind);return wr(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Ks=(e,t,r)=>{const n=Ye(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},pt=Object.freeze({light:"#898373",dark:"#9F9886"}),Ys={graphBackground:o.DEFAULT_GRAPH_BACKGROUND,graphBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),geom:o.DEFAULT_GEOM_COLOR,geomBorder:Object.freeze({light:"rgba(58, 56, 51, 0.55)",dark:"rgba(237, 231, 218, 0.55)"}),textPrimary:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),textSecondary:pt,ruleLine:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),gridLine:Object.freeze({light:"#E1DAC9",dark:"#373531"}),hoverAffordance:o.DEFAULT_HOVER_AFFORDANCE_COLOR,hoverGuideFill:Object.freeze({light:"#E7E1D2",dark:"#2B2A27"}),hoverGuideLine:Object.freeze({light:"#D5CDBA",dark:"#3B3934"}),editOutlineHover:Object.freeze({light:"#C4C4C4",dark:"rgba(255, 255, 255, 0.5)"}),editOutlineSelected:Object.freeze({light:"#3D70FF",dark:"#3D70FF"}),tooltipBackground:Object.freeze({light:"#FCFCF9",dark:"#262522"}),tooltipBorder:Object.freeze({light:"rgba(58, 56, 51, 0.15)",dark:"rgba(237, 231, 218, 0.15)"}),tooltipPrimaryRow:Object.freeze({light:"#F5F1E9",dark:"#2E2C29"}),annotationShape:Object.freeze({light:"#3b82f6",dark:"#60a5fa"}),annotationArrow:Object.freeze({light:"#3A3833",dark:"#EDE7DA"}),differenceLabelBackground:o.DEFAULT_GRAPH_BACKGROUND,trendPositive:{light:"#06B299",dark:"#0AC600"},trendNegative:{light:"#E14B49",dark:"#CB3333"},trendNeutral:pt},zs=o.freezeWalkedEntries(o.walkStyleTargets()),J=Object.freeze({tokens:Object.freeze(Ys),defaults:Object.freeze(zs),overrides:Object.freeze([])}),Ws=class extends B{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const n of pc(e.styles,t))this.container.diagnostics.addWarning(n);for(const n of fc(e.styles))this.container.diagnostics.addWarning(n);const r=yc(this.container.geomRegistry);for(const n of r(e.styles))this.container.diagnostics.addWarning(n);for(const n of vc(e.styles))this.container.diagnostics.addWarning(n);for(const n of t)for(const a of n.styles.warnings)this.container.diagnostics.addWarning(a);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=Cr({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale,styleTarget:_r(this.container.geomRegistry,e.geom)});return{...e,styles:r}}},qs=class extends o.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of mc(e.styles,e.annotations))this.container.diagnostics.addWarning(r);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Lr(e.styles)}},xe=new o.GeomRegistry,Hs=new Set(o.STYLE_PROPERTY_NAMES),Xs=new WeakMap,Js=new WeakMap,mt={stateless:0,dimmed:1,hovered:2},Lr=e=>{const t=[],r={...J.tokens,...e.tokens},n={...tc(),warnings:t},a=(i,s,c,l)=>{if(te(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target,p=rc(i.select);if(p.status==="unknown-target"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${[...ze].map(g=>`'${g}'`).join(", ")}.`});return}if(p.status==="unknown-partition"){const{key:g,value:b,node:C}=p,T=Oe(C,g);t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} addresses unknown ${g} '${b}'.`,context:{param:g,actual:b,...u},suggestion:T.length===0?`Remove '${g}' — this target has none.`:`Set '${g}' to one of ${T.map(E=>`'${E}'`).join(", ")}, or omit it.`});return}if(p.status==="namespace"){const g=Oe(p.node,"part");t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} ignored: ${i.select.target} entries need a part.`,context:{param:"part",actual:String(i.select.part),...u},suggestion:`Set 'part' to one of ${g.map(b=>`'${b}'`).join(", ")}.`});return}const f=p.node;if(i.when!==void 0&&!We(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const h=f.options??[],m=i.select;if(m.layer!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} does not take a layer.`,context:{param:"layer",actual:P(m.layer),...u},suggestion:"Remove 'layer' — this target is not layer-scoped."});return}if(m.annotation!==void 0){if(!h.includes("annotation")){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} does not take an annotation.`,context:{param:"annotation",actual:P(m.annotation),...u},suggestion:"Remove 'annotation' — this target is not annotation-scoped."});return}if(typeof m.annotation!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${c} addresses an invalid annotation ${P(m.annotation)}.`,context:{param:"annotation",actual:P(m.annotation),...u},suggestion:"Set 'annotation' to the id of an annotation in the spec, or omit it to address every one of the kind."});return}}const v=$r({declarations:i.declarations,vocabulary:f.vocabulary,tokens:r,location:c,origin:l,warnings:t,entryTarget:i.select.target});if(Object.keys(v).length===0)return;const y=f.select.target;Pr(y)&&n[y][s].push({select:i.select,declarations:v,origin:l})};return J.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},Qs=e=>xe.has(e)?xe.get(e).styleTarget:void 0,Cr=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a,styleTarget:i}=e,s=pe(t,a),c=[],l={...J.tokens,...n.tokens},u=p=>p===t.geom?i:void 0,d=(p,f)=>{const h=[];return p.forEach((m,v)=>{if(!te(m))return;const y=m.select.kind;if(y!==void 0&&y!==t.geom||m.select.layer!==void 0&&m.select.layer!==t.id)return;const g=`${f}[${v}]`;if(Br(m,g,u)!==void 0)return;const b=m.when?.state;if(b!==void 0&&!kr(b))return;const C=m.id===void 0?{}:{styleEntryId:m.id},T={list:f,index:v,...m.id===void 0?{}:{id:m.id}},E=m.when?.where;if(E!==void 0){const U=R(E,t.data,"style-rule");if(U.length>0){for(const S of U)c.push({...S,code:"INVALID_STYLE_RULE",message:`Style ${g}: ${S.message}`,context:{...S.context,layerIndex:r,...C}});return}}const W=Mr({select:m.select,declarations:m.declarations,layerGeom:t.geom,styleTarget:i,tokens:l,location:g,origin:T,warnings:c});if(Object.keys(W).length===0)return;const{part:$}=m.select;h.push({declarations:W,...E===void 0?{}:{matches:N(E,s),where:E},...b===void 0?{}:{state:b},...$===void 0?{}:{part:$},origin:T})}),h};return{defaults:[...dc(t.geom,i,l,c),...d(n.defaults,"defaults")],overrides:d(n.overrides,"overrides"),warnings:c,...oc(t.geom,i),dashPresets:i?.observation?.dashPresets??o.DASH_PRESETS.line}},_r=(e,t)=>e.has(t)?e.get(t).styleTarget:void 0,Zs=e=>t=>_r(e,t),ec=()=>{const e=new Set,t=r=>{if(e.add(r.select.target),r.children!==void 0)for(const n of Object.values(r.children))t(n)};for(const r of Object.values(o.STYLE_TARGETS))t(r);return e},ze=ec(),Pr=e=>e!=="geom"&&ze.has(e),tc=()=>{const e={};for(const t of ze)Pr(t)&&(e[t]={defaults:[],overrides:[]});return e},Oe=(e,t)=>{if(e.children===void 0)return[];const r=[];for(const n of Object.values(e.children)){const a=n.select[t];a!==void 0&&r.push(a)}return r},ft=e=>Object.keys(e.vocabulary).length===0&&e.children!==void 0,rc=e=>{const t=o.findStyleTarget(e);if(t!==void 0)return ft(t)?{status:"namespace",node:t}:{status:"found",node:t};const r=o.findStyleTarget({target:e.target});if(r===void 0)return{status:"unknown-target"};let n=r;for(const a of o.STYLE_SELECT_KEYS){const i=e[a];if(i===void 0)continue;const s=n.children===void 0?void 0:Object.values(n.children).find(c=>c.select[a]===i);if(s===void 0)return{status:"unknown-partition",key:a,value:i,node:n};n=s}return ft(n)?{status:"namespace",node:n}:{status:"found",node:n}},We=e=>{const t=e.options??[];return t.includes("where")||t.includes("state")},nc=(e,t)=>{const r=e==="geom"?xe.getAll().find(n=>n.styleTarget!==void 0&&o.readObservationVocabulary(n.styleTarget)[t]!==void 0)?.type:e==="annotation"?Object.entries(o.STYLE_TARGETS.annotation.children).find(([,n])=>n.vocabulary[t]!==void 0)?.[0]:void 0;return r===void 0?void 0:`style.${e}.${r}`},te=e=>e.select.target==="geom",ac=(e,t)=>e!==void 0&&Object.hasOwn(e,t)?e[t]:void 0,Dr=(e,t,r,n)=>{const a=e.get(r)??new Map;e.set(r,a);const i=a.get(t);if(i!==void 0)return i;const s=n();return a.set(t,s),s},Nr=(e,t)=>Dr(Xs,e,t,()=>o.createGeomStyleNode(e,t)),Q=(e,t)=>{const{kind:r,part:n}=e;if(r===void 0)return o.findStyleTarget({target:"geom",part:n});const a=t(r);if(a===void 0)return;const i=Nr(r,a);return n===void 0?i:ac(i.children,n)},ic=(e,t)=>{const r=Q(e,()=>t);return r===void 0||We(r)},Rr=(e,t)=>[e,t].filter(r=>r!==void 0).join(" "),oc=(e,t)=>{const r=Q({kind:e},()=>t),n={};for(const a of Object.values(r?.children??{}))a.select.part!==void 0&&(n[a.select.part]={vocabulary:a.vocabulary,aesthetics:a.aesthetics??{}});return{observation:{vocabulary:r?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,aesthetics:r?.aesthetics??o.STYLE_TARGETS.geom.aesthetics},parts:n}},gt=(e,t)=>Q(e,()=>t)?.vocabulary??o.STYLE_TARGETS.geom.vocabulary,sc=(e,t)=>{const r={};for(const n of Object.keys(e)){const a=e[n];a===void 0||t[n]===void 0||(r[n]=a)}return r},Mr=e=>{const t=$r({declarations:e.declarations,vocabulary:gt(e.select,e.styleTarget),tokens:e.tokens,location:e.location,origin:e.origin,warnings:e.warnings,entryTarget:"geom"});return e.select.part!==void 0?t:sc(t,gt({kind:e.layerGeom},e.styleTarget))},cc=(e,t)=>Dr(Js,e,t,()=>o.freezeWalkedEntries(o.walkStyleTargets([Nr(e,t)]))),lc=(e,t)=>mt[e.state??"stateless"]-mt[t.state??"stateless"],uc=(e,t)=>t===void 0?`builtin ${e}`:`builtin ${e}.${t}`,dc=(e,t,r,n)=>{const a=[],i={list:"builtin"},s=(c,l,u,d)=>{if(c.kind!==void 0&&c.kind!==e)return;if(u!==void 0&&!ic(c,t)){const h=Rr(e,c.part);n.push({code:"INVALID_STYLE_RULE",message:`Style ${d} ignored: a ${h} entry takes no conditions.`,context:{param:"state",actual:u},suggestion:`Declare the ${u} paint on 'rest', or add 'state' to the part's options.`});return}const p=Mr({select:c,declarations:l,layerGeom:e,styleTarget:t,tokens:r,location:d,origin:i,warnings:n});if(Object.keys(p).length===0)return;const{part:f}=c;a.push({declarations:p,...u===void 0?{}:{state:u},...f===void 0?{}:{part:f},origin:i})};if(J.defaults.forEach((c,l)=>{te(c)&&s(c.select,c.declarations,c.when?.state,`builtin[${l}]`)}),t===void 0)return a;for(const c of cc(e,t))s(c.select,c.declarations,c.when?.state,uc(e,c.select.part));return a.sort(lc)},ge=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},pc=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return ge(e,(a,i,s)=>{const c=a.select;if(c.target!=="geom")return;const l=c.layer;l===void 0||typeof l!="string"||r.has(l)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown layer '${l}'.`,context:{param:"layer",actual:l,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},mc=(e,t)=>{const r=new Map(Or.flatMap(a=>t[o.ANNOTATION_BUCKETS[a]].map(i=>[i.id,a]))),n=[];return ge(e,(a,i,s)=>{const c=a.select;if(c.target!=="annotation")return;const l=c.annotation;if(l===void 0||typeof l!="string")return;const u={param:"annotation",actual:l,...a.id===void 0?{}:{styleEntryId:a.id}},d=r.get(l);if(d===void 0){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown annotation '${l}'.`,context:u,suggestion:"Set 'annotation' to the id of an annotation in the spec."});return}if(d==="sticker"){n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets sticker '${l}', which has no style vocabulary.`,context:u,suggestion:"Remove the entry — stickers take no style declarations."});return}const p=c.kind;p!==void 0&&p!==d&&n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets ${d} '${l}' with an entry addressing kind '${String(p)}'.`,context:u,suggestion:`Set 'kind' to '${d}', or omit it to address the annotation with the shared vocabulary.`})}),n},fc=e=>{const t=[];return ge(e,(r,n,a)=>{if(!te(r))return;const i=r.when?.state;i===void 0||kr(i)||t.push({code:"INVALID_STYLE_RULE",message:`Style ${n}[${a}] scopes to unknown state '${i}'.`,context:{param:"state",actual:String(i),...r.id===void 0?{}:{styleEntryId:r.id}},suggestion:`Set 'state' to one of ${o.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),t},kr=e=>o.STYLE_STATES.includes(e),gc=(e,t,r)=>e===void 0?`Set 'kind' to the geom declaring '${t}' — a part is addressed on the kind that has it.`:r.length===0?`Remove 'part' — ${e} has none.`:`Set 'part' to one of ${r.map(n=>`'${n}'`).join(", ")}, or omit it.`,Br=(e,t,r)=>{const{kind:n,part:a}=e.select;if(a===void 0)return;const i=e.id===void 0?{}:{styleEntryId:e.id},s=Q({kind:n,part:a},r);if(s===void 0){const c=Q({kind:n},r),l=c===void 0?[]:Oe(c,"part");return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown part '${a}'.`,context:{param:"part",actual:a,...i},suggestion:gc(n,a,l)}}if(e.when!==void 0&&!We(s)){const c=Rr(n,a);return{code:"INVALID_STYLE_RULE",message:`Style ${t} ignored: a ${c} entry takes no conditions.`,context:{param:"when",...i},suggestion:`Remove the 'when' clause — the ${c} is styled as a whole.`}}},hc=(e,t,r)=>{const{kind:n}=e.select;if(n===void 0||r.has(n))return;const a=r.getAll().map(i=>`'${i.type}'`);return{code:"INVALID_STYLE_RULE",message:`Style ${t} addresses unknown geom kind '${n}'.`,context:{param:"kind",actual:n,...e.id===void 0?{}:{styleEntryId:e.id}},suggestion:`Set 'kind' to one of ${a.join(", ")}, or omit it to reach every geom.`}},yc=e=>{const t=Zs(e);return r=>{const n=[];return ge(r,(a,i,s)=>{if(!te(a))return;const c=`${i}[${s}]`,l=hc(a,c,e)??Br(a,c,t);l!==void 0&&n.push(l)}),n}},vc=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))o.isUsableTokenValue(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${P(n)}.`,context:{param:"tokens",actual:P(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},P=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),$r=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s,entryTarget:c}=e,l={},u=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},d=(m,v)=>{l[m]=v},p=(m,v,y)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: expected ${v}, got ${P(y)}.`,context:{param:m,expected:v,actual:P(y),...u},suggestion:`Set '${m}' to ${v}.`})},f=(m,v)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: unknown token '${v}'.`,context:{param:m,actual:v,...u},suggestion:`Declare '${v}' in the stylesheet's tokens.`})},h=m=>{const v=Hs.has(m),y=nc(c,m),g=y===void 0?`Declare '${m}' on a target whose vocabulary carries it.`:`Declare '${m}' on an entry whose kind supports it (e.g. ${y}).`;s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${m}' ignored: ${v?"not in this entry's vocabulary":"not a style property"}.`,context:{param:m,...u},suggestion:v?g:`Remove the unknown declaration '${m}'.`})};for(const m of Object.keys(t)){const v=t[m];if(v===void 0)continue;const y=r[m];if(y===void 0){h(m);continue}const g=o.STYLE_DOMAINS[y](v,n);switch(g.status){case"accepted":d(m,g.value);break;case"rejected":p(m,g.expected,g.actual);break;case"unknownToken":f(m,g.token);break;case"dropped":break;default:break}}return l},bc=({layer:e})=>{if(e.position==="stack")return;const t=o.readVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];o.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Sc=({layer:e,mainAxis:t})=>{if(e.position!=="stack")return;const r=o.readVariableName(e.mapping.x);if(r===null||!e.data.hasVariable(o.POSITION_VARIABLES.yMin)||!e.data.hasVariable(o.POSITION_VARIABLES.yMax))return;const n=c=>t==="y"?c.xMax:c.yMax,a=c=>t==="y"?c.xMin:c.yMin,i=new Map;for(const c of e.data){const l=c[r],u=o.getYMin(c),d=o.getYMax(c),p=o.getXMin(c),f=o.getXMax(c),h=o.getYRaw(c);if(!o.isDefined(l)||!o.isDefined(u)||!o.isDefined(d)||!o.isDefined(p)||!o.isDefined(f)||!o.isDefined(h))continue;const m=h>=0;if(Math.abs(h)===0)continue;const v=ke(c,r),y={xMin:p,xMax:f,yMin:u,yMax:d},g=i.get(v);if(g===void 0){i.set(v,{total:h,topPositive:m?y:null,bottomNegative:m?null:y});continue}g.total+=h,m?(g.topPositive===null||n(y)>n(g.topPositive))&&(g.topPositive=y):(g.bottomNegative===null||a(y)<a(g.bottomNegative))&&(g.bottomNegative=y)}const s=[];for(const[c,l]of i){const u=l.topPositive??l.bottomNegative;u!==null&&s.push({xKey:c,total:l.total,anchor:{xMin:u.xMin,xMax:u.xMax,yMin:u.yMin,yMax:u.yMax,direction:l.topPositive!==null?"positive":"negative"}})}return s},Ac=class extends B{constructor(e){super(),this.container=e}dependencies(e){return[e.coordSystem]}compileLayer(e,t){const r=this.container.geomRegistry.get(e.geom),n={},a=wt(t.coordSystem);if(r.summaries.stackTotals){const i=Sc({layer:e,mainAxis:a});i!==void 0&&(n.stackTotals=i)}if(r.summaries.grandTotal){const i=bc({layer:e});i!==void 0&&(n.grandTotal=i.grandTotal,n.absoluteGrandTotal=i.absoluteGrandTotal)}return{...e,summary:n}}},ht={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Tc=["color","size","alpha","strokeWidth","lineType"],Ic=class extends B{dependencies(e){return Tc.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(o.VISUAL_VARIABLES);for(const[a,i]of n){const s=o.readConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,ht[a],s);continue}const c=o.readVariableName(e.mapping[a]),l=t.scales[a];!c||!l||l.kind!=="visual"||(r=r.deriveVariableFrom(c,i,ht[a],Ec(l)))}return{...e,data:r}}},Ec=e=>t=>o.isDefined(t)?e.map(t):null;function Ur(e=new o.GeomRegistry){return{diagnostics:new As,geomRegistry:e}}var Fr=class{constructor(e,t,r,n,a,i,s,c,l,u,d,p,f,h,m,v){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=u,this.guideCompiler=d,this.summarizeCompiler=p,this.stylesCompiler=f,this.chromeStylesCompiler=h,this.highlightsCompiler=m,this.annotationsCompiler=v,this.stageTimer=o.IS_DEV?ks():null,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.lastCustomPalettes={},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:"summarize",getStats:()=>this.summarizeCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}],o.IS_DEV&&this.setupStageTiming()}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.lastCustomPalettes=e.customPalettes??{},this.runPipeline({spec:this.specCompiler.compile({spec:e.spec,customPalettes:this.lastCustomPalettes,dataset:this.dataCompiler.compile(e.data)}),colorScheme:e.colorScheme??yt})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{const r=e.colorScheme??yt;if(e.data===void 0)return this.runPipeline({spec:e.spec,colorScheme:r});this.lastData=e.data;const n=this.dataCompiler.compile(e.data),a=this.reResolveInferredScalesIfNeeded(e.spec.data,H(e.spec,{data:n}));return this.runPipeline({spec:a,colorScheme:r})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}reResolveInferredScalesIfNeeded(e,t){if(e.size()!==0||t.data.size()===0||t.scales.filter(n=>n.inferredFrom!==void 0).length===0)return t;const r=Fe(this.container,{data:t.data,layers:t.layers,mapping:t.mapping,customPalettes:this.lastCustomPalettes});return H(t,{scales:_e(t.scales,n=>{const a=n.inferredFrom;if(a===void 0)return n;const i=fe(r,a);return t.coords.coordType==="polar"?je(i):i})})}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,scene:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[Tt(e)],warnings:t.warnings}}setupStageTiming(){this.stageTimer&&(this.dataCompiler.compile=this.stageTimer.wrap("data",this.dataCompiler.compile.bind(this.dataCompiler)),this.transformCompiler.compile=this.stageTimer.wrap("transform",this.transformCompiler.compile.bind(this.transformCompiler)),this.constantMappingCompiler.compile=this.stageTimer.wrap("constantMapping",this.constantMappingCompiler.compile.bind(this.constantMappingCompiler)),this.layerPhasedCompiler.compile=this.stageTimer.wrap("layer",this.layerPhasedCompiler.compile.bind(this.layerPhasedCompiler)),this.coordCompiler.setup=this.stageTimer.wrap("coordSetup",this.coordCompiler.setup.bind(this.coordCompiler)),this.scaleCompiler.compile=this.stageTimer.wrap("scale",this.scaleCompiler.compile.bind(this.scaleCompiler)),this.positionMapperCompiler.compile=this.stageTimer.wrap("positionMapper",this.positionMapperCompiler.compile.bind(this.positionMapperCompiler)),this.visualMapperCompiler.compile=this.stageTimer.wrap("visualMapper",this.visualMapperCompiler.compile.bind(this.visualMapperCompiler)),this.coordCompiler.transform=this.stageTimer.wrap("coordTransform",this.coordCompiler.transform.bind(this.coordCompiler)),this.summarizeCompiler.compile=this.stageTimer.wrap("summarize",this.summarizeCompiler.compile.bind(this.summarizeCompiler)),this.guideCompiler.compile=this.stageTimer.wrap("guide",this.guideCompiler.compile.bind(this.guideCompiler)),this.stylesCompiler.compile=this.stageTimer.wrap("styles",this.stylesCompiler.compile.bind(this.stylesCompiler)),this.chromeStylesCompiler.compile=this.stageTimer.wrap("chromeStyles",this.chromeStylesCompiler.compile.bind(this.chromeStylesCompiler)),this.highlightsCompiler.compile=this.stageTimer.wrap("highlights",this.highlightsCompiler.compile.bind(this.highlightsCompiler)),this.annotationsCompiler.compile=this.stageTimer.wrap("annotations",this.annotationsCompiler.compile.bind(this.annotationsCompiler)))}trackCompile(e){if(!o.IS_DEV)return e();this.stageTimer?.reset();const t=this.getCacheStats(),r=performance.now();try{return e()}finally{const n=performance.now()-r,a={},i={};for(const{name:s,getStats:c}of this.stages){const l=c();a[s]={hits:l.hits-t[s].hits,misses:l.misses-t[s].misses},i[s]=this.stageTimer?.getDuration(s)??0}this.lastCompile={stages:a,durationMs:n,stageDurationsMs:i}}}runPipeline({spec:e,colorScheme:t}){return{...de({spec:e}).pipe(({spec:r})=>({spec:H(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const n=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:H(r,{data:n.data,mapping:n.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:n})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:n})).pipe(({layers:r,scales:n})=>({scales:this.scaleCompiler.compile({layers:r,scales:n,colorScheme:t})})).pipe(({spec:r})=>({config:r.config})).pipe(({layers:r,scales:n})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:n})})).pipe(({layers:r,scales:n})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:n})})).pipe(({spec:r,layers:n,coordSystem:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,coordSystem:a,layers:n})})).pipe(({layers:r,coordSystem:n})=>({layers:this.summarizeCompiler.compile({layers:r,coordSystem:n})})).pipe(({spec:r,scales:n,layers:a,coordSystem:i})=>({guides:this.guideCompiler.compile({scales:n,config:r.config,layers:a,coordSystem:i,originalData:this.lastData})})).pipe(({spec:r,layers:n})=>({layers:this.stylesCompiler.compile({layers:n,styles:r.styles,config:r.config})})).pipe(({spec:r})=>({chrome:this.chromeStylesCompiler.compile({styles:r.styles,annotations:r.annotations})})).pipe(({spec:r,layers:n})=>({layers:this.highlightsCompiler.compile({layers:n,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:n,coordSystem:a,scales:i})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:n,coordSystem:a,scales:i,config:r.config})})).result(),spec:e}}},Vc=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarize","guide","styles","chromeStyles","highlights","annotations"],yt="light",xc=({plugins:e=[]}={})=>{const t=o.readPlugins(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=ro(t),i=Ur(r),s=new Go(i),c=new Ge(a);for(const l of t.warnings)i.diagnostics.addWarning(l,{persistent:!0});return new Fr(i,new o.DataCompiler,new xr(i),c,new $n,new $i(i,c,n,new Pi(i,c,new Bs(n),new ua,new la(i),new no(new uo))),new Eo(i,s),new jn(new ca),new Io(i),new Ic,new Vi(i),new Ac(i),new Ws(i),new qs(i),new wi(i),new Vn(i))};Object.defineProperty(exports,"AREA_DEFAULTS",{enumerable:!0,get:function(){return Vs}});Object.defineProperty(exports,"BAR_DEFAULTS",{enumerable:!0,get:function(){return xs}});Object.defineProperty(exports,"BUILTIN_STYLES",{enumerable:!0,get:function(){return J}});Object.defineProperty(exports,"COLOR_INTERPOLATION_SPACES",{enumerable:!0,get:function(){return Vo}});Object.defineProperty(exports,"COMPILER_STAGE_KEYS",{enumerable:!0,get:function(){return Vc}});Object.defineProperty(exports,"Compiler",{enumerable:!0,get:function(){return Fr}});Object.defineProperty(exports,"DATA_LABELS_DEFAULTS",{enumerable:!0,get:function(){return Ar}});Object.defineProperty(exports,"DIVERGING_SCHEME_NAMES",{enumerable:!0,get:function(){return mr}});Object.defineProperty(exports,"LINE_DEFAULTS",{enumerable:!0,get:function(){return Es}});Object.defineProperty(exports,"POINT_DEFAULTS",{enumerable:!0,get:function(){return Is}});Object.defineProperty(exports,"POLAR_COORD_DEFAULTS",{enumerable:!0,get:function(){return ie}});Object.defineProperty(exports,"RULE_DEFAULTS",{enumerable:!0,get:function(){return Os}});Object.defineProperty(exports,"SCHEME_ALIASES",{enumerable:!0,get:function(){return fr}});Object.defineProperty(exports,"SEQUENTIAL_SCHEME_NAMES",{enumerable:!0,get:function(){return xo}});Object.defineProperty(exports,"SpecCompiler",{enumerable:!0,get:function(){return xr}});Object.defineProperty(exports,"TILE_DEFAULTS",{enumerable:!0,get:function(){return ws}});Object.defineProperty(exports,"TransformCompiler",{enumerable:!0,get:function(){return Ge}});Object.defineProperty(exports,"applyReplayableTransforms",{enumerable:!0,get:function(){return br}});Object.defineProperty(exports,"areEndpointsComparable",{enumerable:!0,get:function(){return St}});Object.defineProperty(exports,"buildDiagnostic",{enumerable:!0,get:function(){return Tt}});Object.defineProperty(exports,"buildEmptyHighlightForStrategy",{enumerable:!0,get:function(){return tr}});Object.defineProperty(exports,"canAnchorDirectLabels",{enumerable:!0,get:function(){return Zt}});Object.defineProperty(exports,"clampValuesAgainstFillSiblings",{enumerable:!0,get:function(){return Vr}});Object.defineProperty(exports,"compileChromeStyles",{enumerable:!0,get:function(){return Lr}});Object.defineProperty(exports,"compileLayerStyles",{enumerable:!0,get:function(){return Cr}});Object.defineProperty(exports,"compilePredicate",{enumerable:!0,get:function(){return N}});Object.defineProperty(exports,"composePoint",{enumerable:!0,get:function(){return Ae}});Object.defineProperty(exports,"createAlphaValueReader",{enumerable:!0,get:function(){return Hr}});Object.defineProperty(exports,"createColorValueReader",{enumerable:!0,get:function(){return Wr}});Object.defineProperty(exports,"createCommonContainer",{enumerable:!0,get:function(){return Ur}});Object.defineProperty(exports,"createCompiler",{enumerable:!0,get:function(){return xc}});Object.defineProperty(exports,"createDatasetFromKindPartitions",{enumerable:!0,get:function(){return Bn}});Object.defineProperty(exports,"createEmptyLayerStyles",{enumerable:!0,get:function(){return nr}});Object.defineProperty(exports,"createGroupValueReader",{enumerable:!0,get:function(){return Xr}});Object.defineProperty(exports,"createLabelValueReader",{enumerable:!0,get:function(){return zr}});Object.defineProperty(exports,"createLayerMeasurement",{enumerable:!0,get:function(){return Pt}});Object.defineProperty(exports,"createObservationAnchorBuilder",{enumerable:!0,get:function(){return Lt}});Object.defineProperty(exports,"createObservationAnchorMatcher",{enumerable:!0,get:function(){return Dt}});Object.defineProperty(exports,"createObservationAnchorParser",{enumerable:!0,get:function(){return At}});Object.defineProperty(exports,"createPipeline",{enumerable:!0,get:function(){return de}});Object.defineProperty(exports,"createPredicateCompileContext",{enumerable:!0,get:function(){return pe}});Object.defineProperty(exports,"createPredicateValueReader",{enumerable:!0,get:function(){return Nt}});Object.defineProperty(exports,"createRawValueReader",{enumerable:!0,get:function(){return V}});Object.defineProperty(exports,"createRowPredicateCompileContext",{enumerable:!0,get:function(){return pn}});Object.defineProperty(exports,"createScaleContext",{enumerable:!0,get:function(){return Fe}});Object.defineProperty(exports,"createSegmentYReader",{enumerable:!0,get:function(){return we}});Object.defineProperty(exports,"createSizeValueReader",{enumerable:!0,get:function(){return qr}});Object.defineProperty(exports,"createStrokeWidthValueReader",{enumerable:!0,get:function(){return Jr}});Object.defineProperty(exports,"createXValueReader",{enumerable:!0,get:function(){return Kr}});Object.defineProperty(exports,"createYValueReader",{enumerable:!0,get:function(){return Yr}});Object.defineProperty(exports,"describeMeasurementBasis",{enumerable:!0,get:function(){return be}});Object.defineProperty(exports,"filterLayersByGeoms",{enumerable:!0,get:function(){return ei}});Object.defineProperty(exports,"findAnnotation",{enumerable:!0,get:function(){return js}});Object.defineProperty(exports,"findCompanionLayers",{enumerable:!0,get:function(){return ti}});Object.defineProperty(exports,"findDefaultKitStyleTarget",{enumerable:!0,get:function(){return Qs}});Object.defineProperty(exports,"findDistinctLayers",{enumerable:!0,get:function(){return Me}});Object.defineProperty(exports,"findLayerByGeom",{enumerable:!0,get:function(){return Za}});Object.defineProperty(exports,"findLayerById",{enumerable:!0,get:function(){return Qa}});Object.defineProperty(exports,"findPredicateProblems",{enumerable:!0,get:function(){return R}});Object.defineProperty(exports,"getCoordinates",{enumerable:!0,get:function(){return an}});Object.defineProperty(exports,"getCrossAxisCoordinate",{enumerable:!0,get:function(){return Ot}});Object.defineProperty(exports,"getGroup",{enumerable:!0,get:function(){return Z}});Object.defineProperty(exports,"getLayerVariableValueFormat",{enumerable:!0,get:function(){return Pe}});Object.defineProperty(exports,"getLayerYValueFormat",{enumerable:!0,get:function(){return cn}});Object.defineProperty(exports,"getMainAxisCoordinate",{enumerable:!0,get:function(){return xt}});Object.defineProperty(exports,"getObservationXKey",{enumerable:!0,get:function(){return ke}});Object.defineProperty(exports,"isAnnotationKind",{enumerable:!0,get:function(){return Fs}});Object.defineProperty(exports,"isCartesian",{enumerable:!0,get:function(){return on}});Object.defineProperty(exports,"isCompanionLayer",{enumerable:!0,get:function(){return Qt}});Object.defineProperty(exports,"isLayerSpecOf",{enumerable:!0,get:function(){return Ja}});Object.defineProperty(exports,"mapItems",{enumerable:!0,get:function(){return _e}});Object.defineProperty(exports,"measureAnchorSpace",{enumerable:!0,get:function(){return Vt}});Object.defineProperty(exports,"patchSpec",{enumerable:!0,get:function(){return H}});Object.defineProperty(exports,"readAnnotationBucket",{enumerable:!0,get:function(){return Ye}});Object.defineProperty(exports,"readGeomScaleConstraints",{enumerable:!0,get:function(){return Be}});Object.defineProperty(exports,"readMainAxis",{enumerable:!0,get:function(){return wt}});Object.defineProperty(exports,"readObservationMeasurement",{enumerable:!0,get:function(){return $t}});Object.defineProperty(exports,"readPredicateVariables",{enumerable:!0,get:function(){return ae}});Object.defineProperty(exports,"readScopeKey",{enumerable:!0,get:function(){return Ie}});Object.defineProperty(exports,"readScopeXVariable",{enumerable:!0,get:function(){return er}});Object.defineProperty(exports,"removeDiscreteScalePadding",{enumerable:!0,get:function(){return je}});Object.defineProperty(exports,"removeLocatedAnnotation",{enumerable:!0,get:function(){return Gs}});Object.defineProperty(exports,"replaceAnnotationBucket",{enumerable:!0,get:function(){return wr}});Object.defineProperty(exports,"replaceAtIndex",{enumerable:!0,get:function(){return tn}});Object.defineProperty(exports,"resolveAnchorVariable",{enumerable:!0,get:function(){return ue}});Object.defineProperty(exports,"resolveColorRamp",{enumerable:!0,get:function(){return Ue}});Object.defineProperty(exports,"resolveComparisonBasis",{enumerable:!0,get:function(){return Jt}});Object.defineProperty(exports,"resolveCoord",{enumerable:!0,get:function(){return Sr}});Object.defineProperty(exports,"resolveCrossAnchorVariable",{enumerable:!0,get:function(){return Le}});Object.defineProperty(exports,"resolveDiscreteScale",{enumerable:!0,get:function(){return yr}});Object.defineProperty(exports,"resolveGeomAnchorSpace",{enumerable:!0,get:function(){return Et}});Object.defineProperty(exports,"resolveGeomScaleDemands",{enumerable:!0,get:function(){return $e}});Object.defineProperty(exports,"resolveLabelSource",{enumerable:!0,get:function(){return Er}});Object.defineProperty(exports,"resolveLayer",{enumerable:!0,get:function(){return Ir}});Object.defineProperty(exports,"resolveScale",{enumerable:!0,get:function(){return fe}});Object.defineProperty(exports,"resolveSegmentYSource",{enumerable:!0,get:function(){return le}});Object.defineProperty(exports,"resolveStatSpec",{enumerable:!0,get:function(){return Tr}});Object.defineProperty(exports,"resolveVariableLabel",{enumerable:!0,get:function(){return Ne}});Object.defineProperty(exports,"sampleColorScheme",{enumerable:!0,get:function(){return _o}});Object.defineProperty(exports,"shouldNarrowByGroup",{enumerable:!0,get:function(){return Ce}});Object.defineProperty(exports,"toPanelFraction",{enumerable:!0,get:function(){return nn}});Object.defineProperty(exports,"uniqueId",{enumerable:!0,get:function(){return I}});Object.defineProperty(exports,"updateSpec",{enumerable:!0,get:function(){return en}});
|