@graphysdk/viz-engine 1.8.1-beta.1787147748310 → 1.8.1-beta.1787149483080

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Tu=Object.create,Ii=Object.defineProperty,Lu=Object.getOwnPropertyDescriptor,wu=Object.getOwnPropertyNames,Eu=Object.getPrototypeOf,Vu=Object.prototype.hasOwnProperty,Ru=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=wu(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Vu.call(e,o)&&o!==r&&Ii(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Lu(t,o))||n.enumerable});return e},Gt=(e,t,r)=>(r=e!=null?Tu(Eu(e)):{},Ru(t||!e||!e.__esModule?Ii(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-CtbBX7qP.cjs");let Ti=require("date-fns"),ze=require("lodash-es"),je=require("d3-time"),Cu=require("date-fns/differenceInDays"),ue=require("d3-regression"),Q=require("d3-scale"),De=require("d3-interpolate"),D=require("d3-scale-chromatic"),Pe=require("lodash-es/clamp");Pe=Gt(Pe,1);let kt=require("lodash-es/merge");kt=Gt(kt,1);let Er=require("humanize-duration");Er=Gt(Er,1);let ve=require("d3-shape"),da=require("color2k"),ku=require("d3-delaunay"),Dt=require("lodash-es/isEqual");Dt=Gt(Dt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787147748310");var Du=1e6;function z(e){return String(Math.round(e*Du))}var ma=0;function O(){return ma+=1,`${Math.random().toString(36).slice(2,6)}${ma.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function E(e){return e[l.POSITION_VARIABLES.y]}function K(e){return e[l.POSITION_VARIABLES.xMin]}function Y(e){return e[l.POSITION_VARIABLES.xMax]}function F(e){return e[l.POSITION_VARIABLES.yMin]}function M(e){return e[l.POSITION_VARIABLES.yMax]}function Yr(e){return e[l.POSITION_VARIABLES.yRaw]}function Ou(e,t){return e[l.resolveScaledAestheticVariable(t)]}var _u={xMin:0,xMax:1,yMin:0,yMax:1},Vr=(e,t)=>{if(t.type==="polar")return null;const r=K(e)??R(e),n=Y(e)??R(e),a=F(e)??E(e),i=M(e)??E(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},tt=(e,t)=>{const r=(e.xMin+e.xMax)/2,n=(e.yMin+e.yMax)/2;switch(t){case"top":return{x:r,y:e.yMax};case"bottom":return{x:r,y:e.yMin};case"left":return{x:e.xMin,y:n};case"right":return{x:e.xMax,y:n};case"top-left":return{x:e.xMin,y:e.yMax};case"top-right":return{x:e.xMax,y:e.yMax};case"bottom-left":return{x:e.xMin,y:e.yMin};case"bottom-right":return{x:e.xMax,y:e.yMin};default:return{x:r,y:n}}},Li=e=>tt(_u,e),xe=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},wi=(e,t)=>e.yScaleType===t.yScaleType&&Cr(e.valueFormat)===Cr(t.valueFormat),Rr=e=>`${e.yScaleType} y axis, ${Cr(e.valueFormat)}`,Cr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Mu=(e,t)=>{if(!l.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[l.getStableKey(r)]??e.fallback};function Ne(e,t){return e==="x"?t.x:t.y}function Ut(e,t){return e==="x"?t.y:t.x}function Pu(e,t){return{main:Ne(e,t),cross:Ut(e,t)}}function pa(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function Nu(e){return e.type==="cartesian"}var U=e=>e[l.GROUP_VARIABLES.group],rt=(e,t)=>{const r=xe(e),n=t[r]??null;if(n===null)return null;const a=r===l.GROUP_VARIABLES.group?null:U(t);return{layerId:e.id,anchorValue:n,...a!==null&&{groupValue:a}}},Be=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,Bu={type:"decimal"};function Ei(e){return e.length>0&&e.every(t=>t.data.size()===0)}function Vi(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):Bu}function Ri(e){return Vi(e,l.extractVariableName(e.mapping.y))}var Fu=["stack","dodge","identity","fill"],qr=["solid","dashed","dotted"],Ci=e=>qr.includes(e);function P(e){return e==="stack"||e==="fill"}var W=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},nt=(e,t)=>W(e,t.x),ki=(e,t)=>W(e,t.y),$u=(e,t)=>W(e,t.label),Di=(e,t)=>W(e,t.color),Gu=(e,t)=>W(e,t.size),Uu=(e,t)=>W(e,t.alpha),Wu=(e,t)=>W(e,t.group),Hu=(e,t)=>W(e,t.strokeWidth),ha={variable:l.POSITION_VARIABLES.yRaw};function Wt(e,t){return P(e)?ha:t.y??ha}function Ke(e){return W(e.data,Wt(e.position,e.mapping))}function Ht(e){return e[l.VISUAL_VARIABLES.color]}function Oi(e){return e[l.VISUAL_VARIABLES.alpha]}function jr(e){return e[l.VISUAL_VARIABLES.size]}function kr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function _i(e){return e[l.VISUAL_VARIABLES.lineType]}var Dr=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Mi=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(xe(e)));return n=>({...n,anchorValue:Dr(n.anchorValue,r,t),...n.groupValue!==void 0&&{groupValue:Dr(n.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)}})},Pi=e=>{const t=l.extractVariableName(e.mapping.y),r=Ke(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},zu=["lt","lte","gt","gte","range"],Ku={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"}},te=()=>!1,we=()=>!0;function zt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Pi(e),parsingLocale:t}}function he(e,t){if("and"in e){const r=e.and.map(n=>he(n,t)).filter(n=>n!==we);return r.includes(te)?te:r.length===0?we:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>he(n,t)).filter(n=>n!==te);return r.includes(we)?we:r.length===0?te:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=he(e.not,t);return r===te?we:r===we?te:n=>!r(n)}return qu(e,t)}function fe(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>fe(n,t,r)):"or"in e?e.or.flatMap(n=>fe(n,t,r)):"not"in e?fe(e.not,t,r):Yu(e,t,r)}function Yu(e,t,r){const{subject:n,effect:a}=Ku[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=ju(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 qu(e,t){if(!t.hasVariable(e.variable))return te;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Dr(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);return i=>{const s=t.readValue(i,e.variable);for(const o of a)if(l.areDataValuesEqual(s,o))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>Ee(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=Ee(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Ee(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=Ee(t.readValue(i,e.variable),a);return s==="greater"||s==="equal"}}if("range"in e){const[a,i]=e.range,s=n(a),o=n(i);return c=>{const u=t.readValue(c,e.variable),d=Ee(u,s),m=Ee(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return te}function ju(e){for(const t of zu)if(t in e)return t;return null}function Ee(e,t){if(e===null||t===null)return"incomparable";if(l.isStrictTemporalDataValue(e)&&l.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return l.isStrictNumericDataValue(e)&&l.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var Xu=(e,t,r,n,a,i)=>{const s=Bi(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Ni(r.padding),c=o===null?Qu(s,r.padding):s,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin)};return o===null?u:{...u,defer:o}},Zu=(e,t,r,n,a,i)=>{const s=Bi(e,t,r.predicate,n,a,i);return s===null?null:tt(s,r.align)},Ni=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Bi=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let s=null,o=!1;const c=new Map;for(const u of n){const d=fe(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=he(r,zt(u,i));if(h!==te)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Ju(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Ju=(e,t)=>({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)}),Qu=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Ot=(e,t,r)=>{const n=td(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:rd(n,t.offset,e.coordSystem)},Fi=(e,t)=>t.anchorType==="selection"?Xu(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale):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},Xr=(e,t,r)=>Or(e,t,r)?.point??null,Or=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const{resolveAnchorPosition:o}=e.geomRegistry.get(s.geom);if(o===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const c=Ke(s),u=xe(s),{anchorValue:d,groupValue:m}=Mi(s,n)(a);let h=-1;for(const p of s.data){if(h+=1,!l.areDataValuesEqual(p[u]??null,d)||m!==void 0&&!l.areDataValuesEqual(U(p),m))continue;const f=o(p,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(f===null)continue;const g=$i(s,p,c);if(g===null)continue;const y=rt(s,p);if(y!==null)return{point:{...f,...g,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id,observationIndex:h}}}return null},ed=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,o=a.y;if(s===void 0||o===void 0||s.kind!=="position"||o.kind!=="position")return null;const c=ga(t.x,"x",r,i),u=ga(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!Be(d,m))return null;const h=fa(d,s,nd(e)),p=fa(m,o),f=pa(n.mainAxis,{main:h.min,cross:p.min}),g=pa(n.mainAxis,{main:h.max,cross:p.max});return tt({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},$i=(e,t,r)=>{const n=r(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:Mu(Ri(e),t),yScaleType:e.yScaleType,color:Ht(t)}:null},td=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return ed(e,t);case"selection":return Zu(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return Xr(e,ad(t),r)}},rd=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ni(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},fa=(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}},nd=({container:e,layers:t})=>{let r=0;for(const n of t){const a=e.geomRegistry.get(n.geom).resolveBandFraction?.(n.params);a!==void 0&&(r=Math.max(r,a))}return r>0?r:1},ad=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align}),ga=(e,t,r,n)=>{for(const a of r){const i=l.extractVariableName(a.mapping[t]);if(!(i===null||i===l.CONSTANT_VARIABLES.x))return l.parseValue(e,l.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},id=class extends l.Stage{constructor(e){super(),this.container=e}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={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:gd(s,t.differenceArrows),shapes:cd(s,t.shapes),arrows:dd(s,t.arrows),textAnnotations:md(s,t.textAnnotations),images:ud(s,t.images),stickers:pd(s,t.stickers),pinnedNumbers:hd(s,t.pinnedNumbers),comments:fd(s,t.comments)};return sd(this.container,o),od(this.container,o),o}},Gi=(e,t,r)=>e!==null?e:!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||t.color===void 0||t.color!==r.color?null:t.color,ee=(e,t,r,n)=>{e.diagnostics.addWarning({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."})},sd=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.diagnostics.addWarning({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)}},od=(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 ld(t))r.has(a)||e.diagnostics.addWarning({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."})},ld=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},cd=(e,t)=>{const r=[];for(const n of t){const a=Fi(e,n.region);if(a===null){ee(e.container,"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,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},ud=(e,t)=>{const r=[];for(const n of t){const a=Fi(e,n.region);if(a===null){ee(e.container,"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,opacity:n.opacity})}return r},dd=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.start,"pin"),i=Ot(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${Ui(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,color:n.color,thickness:n.thickness,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle,lineStyle:n.lineStyle,hasStickerStyle:n.hasStickerStyle})}return r},md=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.at,"pin");if(a===null){ee(e.container,"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,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},pd=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.at,"pin");if(a===null){ee(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},hd=(e,t)=>{const r=[];for(const n of t){const a=Xr(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},fd=(e,t)=>{const r=[];for(const n of t){const a=Xr(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},gd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Or(e,n.start,"value"),i=Or(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${Ui(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.observationIndex===i.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}yd(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,color:Gi(n.color,a.point,i.point),ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ui=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",yd=(e,t,r,n)=>{wi(r,n)||e.container.diagnostics.addWarning({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:Rr(r),actual:Rr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Wi(e){return e instanceof l.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 w(e,t){return zi(e,t)}function L(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 Hi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function at(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 zi(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(l.isPlainObject(i)&&l.isPlainObject(s)){const o=zi(s,i);o!==s&&(n[a]=o,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function Kt(e){return{pipe:t=>{const r=t(e);return Kt({...e,...r})},result:()=>e}}function vd(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,o]of r)o.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Ki(i),values:i};return new l.Dataset(n)}function Ki(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 bd=class extends l.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(l.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:l.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){const a=l.extractConstantValue(r[n]);if(a===void 0)continue;const i=l.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Ki(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Sd=(e,t)=>{let r=t;for(const n of Object.keys(t)){const a=t[n];if(typeof a!="string")continue;const i=e.getConstant(a);i!==void 0&&(r={...r,[n]:a===l.CONSTANT_VARIABLES.x?"":{value:i.value}})}return r},Ae=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.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)}},xd=class extends l.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)}},Ad=class extends Ae{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 l.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},Id=class{constructor(e){this.setupStage=new xd(e),this.transformStage=new Ad(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)}},Td=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new l.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}},Ld=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new l.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:Ed(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Rd(t))}},wd=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],ya=l.prefixInternalVariable("flipSwap"),Ed=(e,t)=>Vd(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Vd=e=>{for(const t of e){const r=l.extractVariableName(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},Rd=e=>{let t=e.data;for(const[r,n]of wd){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,ya).renameVariable(n,r).renameVariable(ya,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},ge=Math.PI*2,Cd=8,kd=1e-9,Yi=(e,t)=>Math.abs(t-e)>=ge-kd,Fe=e=>(e%ge+ge)%ge,qi=(e,t,r)=>{if(Yi(t,r))return!0;const n=Fe(r-t);return Fe(e-t)<=n},_t=(e,t)=>{const r=Math.abs(Fe(e)-Fe(t));return Math.min(r,ge-r)},ji=(e,t,r)=>e*ge+t+r,Mt=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Xi=(e,t)=>({angle:Fe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),Zr=(e,t)=>{const r=e.x-.5,n=e.y-.5;return{x:t>=1?r*2*t:r*2,y:t>=1?n*2:n*2/t}},Yt=(e,t)=>{const{x:r,y:n}=Zr(e,t);return Xi(r,n)};function Zi(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 Ji=(e,t)=>Zi(t.domain!==null&&t.domain.length>0?t.domain:e),Dd=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=Md(t,e.scales,e.layers),a=Nd(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:e.scales}}transform(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new l.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=_d(r,n),i=Bd(t);return e.layers.map(s=>Fd(t.theta==="y"?$d(s):s,a,i))}},Od=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]];function _d(e,t){return r=>ji(r,e,t)}function Md(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Pd(n,e,r);return a===0?0:-Math.PI/a}function Pd(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Ji(n,e).length}function Nd(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 Bd(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Fd(e,t,r){let n=e.data;return n=Ve(n,l.POSITION_VARIABLES.x,t),n=Ve(n,l.POSITION_VARIABLES.xMin,t),n=Ve(n,l.POSITION_VARIABLES.xMax,t),n=Ve(n,l.POSITION_VARIABLES.y,r),n=Ve(n,l.POSITION_VARIABLES.yMin,r),n=Ve(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Ve(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 $d(e){let t=e.data;for(const[r,n]of Od){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,o=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),o&&(t=t.addVariable(r,"numeric",o))}return{...e,data:t}}var Gd=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Td),this.register("flip",new Ld),this.register("polar",new Dd)}},Qi=new Set(["min","max","scalar"]),Ud={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function Wd(e){const t=new Set;for(const r of e)r.role==="point"?t.add(r.axis):(r.role==="min"||r.role==="max")&&l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function Hd(e){const t=new Set;for(const r of e)r.role==="point"&&t.add(r.axis),l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function zd(e,t,r){let n=e;for(const a of t){if(a.role!=="min"&&a.role!=="max"||!l.isDefined(a.aes))continue;const i=Ud[a.axis][a.role];if(n.hasVariable(i))continue;const s=l.extractVariableName(r[a.aes]);!l.isDefined(s)||!n.hasVariable(s)||(n=n.addVariable(i,"numeric",n.getValues(s,{type:"numeric"})))}return n}var Kd=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:zd(n.data,r.positionRoles,a)}}},Jr=["x","y"],Qr=new Set(["x","y","ySecondary"]),it=new Set(["color","size","alpha","strokeWidth","lineType"]),Ye=e=>Qr.has(e),en=e=>it.has(e),es=e=>Ye(e)||en(e);function ae(e){return e==="secondary"?"ySecondary":"y"}function ts(e,t){return e==="y"?ae(t):"x"}function N(e){return e==="ySecondary"?"y":e}var qe=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of it){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},qt=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:qe(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),Yd=class{compute({data:e,mapping:t}){const r=qe(e,t);if(r.length===0)return{data:e.addConstantVariable(l.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]=l.getStableKey(a.map(o=>o[s]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},qd=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},jd=(e,t,r)=>{const n=be(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function be(e,t){const r=N(t);for(const n of rs(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var tn=(e,t)=>e===null?null:t[e]??e,Xd=(e,t)=>e===null?null:t[String(e)]??null,Se=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return lr(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 Jd(i,t)?i:lr(t)}return lr(t)},Zd=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:rs(t,e).some(r=>r.position==="fill");function rs(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var lr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Jd=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Qd=[{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}],va={year:0,quarter:1,month:2,week:3,day:4,hour:5},Re=40,em=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return am(r.unit).range(e,new Date(t.valueOf()+1),n)},tm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Cu.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Re;case"day":return a/t>Re;case"week":return a/(7*t)>Re;case"month":return a/(30*t)>Re;case"quarter":return a/(90*t)>Re;case"year":return a/(365*t)>Re}},rm=(e,t)=>{const r=!l.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"}}},nm=(e,t)=>{const r=im(t);return r===null?!1:va[e]>va[r]},am=e=>{switch(e){case"hour":return je.utcHour;case"day":return je.utcDay;case"week":return je.utcMonday;case"month":case"quarter":return je.utcMonth;case"year":return je.utcYear}},im=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}},ns={left:"right",right:"left",top:"bottom",bottom:"top"},sm={x:!0,y:!0,ySecondary:!1},om=20,ba=new Set(["top","bottom"]),lm={type:"percentage"};function cm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(Ei(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=mm(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=hm(as(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of Qr){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=um({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function um(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:o,variableLabels:c}=e,{axisConfig:u,position:d,geometry:m}=pm(t,n,i,s),h=be(a,t),p=Zd(a,t)?lm:Se({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:dm(u,h,c),isVisible:u.isVisible,tickCandidates:gm(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:fm(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function dm(e,t,r){return e.label?e.label:t?r[t]??null:null}function mm(e,t,r,n){const a=t.flatMap(o=>{const c=e.get(o.geom).grid[r];return c?[c]:[]}),i=a.some(o=>o.hideGridX),s=a.some(o=>o.hideGridY);return{x:{gridVisible:Sa(i,n.axes.x.grid.isVisible)},y:{gridVisible:Sa(s,n.axes.y.grid.isVisible)}}}function Sa(e,t){if(e&&t===null)return!1}function pm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:as(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=ns[n],i=(0,ze.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 as(e,t){return ba.has(e)===ba.has(t)?e:t}function hm(e,t){return t.has(e)?ns[e]:e}function fm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??sm[r]}var gm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=vm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=om;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>$e(e,u))}))}return i}return e.spec.scaleType==="datetime"?ym(e,t):[{ticks:e.generateTicks().map(a=>$e(e,a))}]},ym=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>$e(e,o))}];const a=new Set,i=[],s=(o,c)=>{if(o.length===0)return;const u=l.getStableKey(o);a.has(u)||(a.add(u),i.push({ticks:o.map(d=>$e(e,d)),valueFormat:c}))};for(const o of Qd)tm({...o,start:r,stop:n})||nm(o.unit,t)||s(e.generateTicks({interval:o}),rm(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},vm=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[$e(e,r),$e(e,n)]}},$e=(e,t)=>({value:t,position:e.map(t)});function is({scale:e,aesthetics:t,layers:r}){const n=bm({layers:r,aesthetics:t}),a=ss({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function bm({layers:e,aesthetics:t}){const r=ss({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>l.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function ss({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(c=>l.isDefined(i.mapping[c]));if(s===void 0)continue;const o=l.extractVariableName(i.mapping[s]);if(!(o===null||!i.data.hasVariable(o)))for(const c of i.data.getValues(o,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var rn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Sm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!rn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=be(t,"color");if(os({colorVariableName:a,xVariableName:be(t,"x"),mapsColorAcrossMultipleLayers:Am(t)>1,isMergedWithAnotherAesthetic:xm(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return is({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Se({layers:m?[m]:t,scaleType:i,variableName:h}),label:Xd(o,r)}})}var os=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function xm(e,t,r){if(r===null)return!1;for(const n of it){if(n==="color")continue;const a=e[n];if(!(a===void 0||!rn(a))&&be(t,n)===r)return!0}return!1}var Am=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function ls(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Im(e,t,r,n){const a=r.findIndex(i=>ls(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:tn(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function xa(e,t,r){if(r===null||t===null)return[...e];const n=l.getStableKey(r);return e.filter((a,i)=>l.getStableKey(t[i]??null)===n)}var cs=e=>e==="none"?"first":e,Tm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Aa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Aa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Lm=(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}},Aa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function wm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Em(e,n):Vm(e,n)}function Em(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(o=>o.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=l.extractVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:Se({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Vm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>ls(o,d)))return null;const c=Im(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>Rm({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 Rm({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=l.extractVariableName(i.mapping.y);if(s===null||t==="total"&&i.position==="fill")return null;const o=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Se({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=Dm(i.data,o),h=Se({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=Om(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=xa(f,y,e.value),x=xa(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Tm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:Cm(t,m,x),comparison:km(t,r,m,x,v)}}function Cm(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 km(e,t,r,n,a){return e!=="current"||!r?null:Lm(n.map((i,s)=>({main:i,cross:a[s]??null})),cs(t))}function Dm(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Om(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function q(e,...t){return e?t.includes(e.geom):!1}function k(e,t){return e.find(r=>r.id===t)}function ie(e,...t){return e.find(r=>t.includes(r.geom))}function _m(e,...t){return e.filter(r=>t.includes(r.geom))}function nn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function an(e){const t=e.filter(r=>!nn(r,e));return t.length>0?t:e}function us({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=an(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Mm=3;function Pm({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const o=new Map(i.map(y=>[l.getStableKey(y.value),y])),c=Hm($m({scales:e,layers:r})),u=be(r,"x"),d=c.map(y=>{if(Um(y,u,r))return null;const v=Km({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=Nm(d),h=an(r),p=Jm(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&Zm(s,m,h,n))return{drawn:[],position:p};const f=Qm(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?np(h[0]):null;return{drawn:d.map(({built:y})=>Bm(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function Nm(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function Bm(e,t,r){const{position:n,display:a}=t,i=Fm(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 Fm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function $m(e){const{scales:t,layers:r}=e,n=[];for(const a of it){const i=t[a];if(i===void 0||i.kind==="identity"||!Gm(a,r))continue;const s=be(r,a),o=rp(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function Gm(e,t){const r=N(e);return t.some(n=>l.isDefined(n.mapping[r]))}function Um(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:os({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:Wm(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function Wm(e,t){const r=N(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function Hm(e){const t=new Map;for(const r of e){const n=tp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function zm(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Km({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>N(c.scaleAestheticKey)),s=is({scale:a.scale,aesthetics:i,layers:r}),o=Se({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:tn(a.variableName,t),items:s.map(c=>Ym(c,e,i,o,n))}}function Ym(e,t,r,n,a){const i={};for(const o of t)zm(i,o.scaleAestheticKey,o.scale.map(e.value));const s=jm(e,t,r,n,a);return{value:e.value,label:qm(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function qm(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function jm(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=Xm(i,r);return i===void 0||s===null?n:Se({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function Xm(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=l.extractVariableName(n);if(a!==null)return a}return null}function Zm(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 Jm(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,o=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,P(u.position)&&(o=!0))}const c=r>=Mm;return i&&s?"top":i?c?"right":"top":o?ep(a)?"top":c?"right":"top":"top"}function Qm(e,t){return e==="pill"?"pill":us(t)?"direct":"pill"}function ep(e){return e.type==="cartesian"&&e.mainAxis==="y"}function tp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function rp(e,t){return rn(t)?"discrete":`continuous:${e}`}function np(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(c=>l.isDefined(M(c))||l.isDefined(E(c)));if(!n)return;const a=U(n);if(!l.isDefined(a))return;const i=F(n),s=M(n)??E(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var ap=class extends l.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=qd(e.originalData),r=Sm({scales:e.scales,layers:e.layers,valueLabels:jd(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=wm(n),i=Pm(n),s={...i,drawn:ip(a,i.drawn)};return{axes:cm(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},ip=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],sp=e=>l.getStableKey([U(e)]),sn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),op=e=>e!=="data-point",Pt=(e,t,r)=>{switch(e){case"series":return sp(t);case"x-value":return sn(t,r)}},lp={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor"};function ds(e){const t=lp[e]??null;return t===null?null:{strategy:t,composition:ms()}}function ms(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var cp=class extends Ae{constructor(e){super(),this.container=e}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:i})=>i===void 0||i===e.id);if(n.length===0)return e;const a=up({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function up({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const X=fe(T.predicate,e.data);for(const Z of X)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return X.length===0}),s=l.extractVariableName(e.mapping.x),o=zt(e,r),c=i.map(T=>({predicate:he(T.predicate,o),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let I=!1,A=0;for(const T of e.data){let X,Z;p!==null&&(X=Pt("series",T,s),p[A]=X),f!==null&&(Z=Pt("x-value",T,s),f[A]=Z),g!==null&&(g[A]=T);for(const{predicate:ft,scope:gt}of c)if(ft(T))switch(gt){case"series":X!==void 0&&v.add(X);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return ms();const V=new Uint8Array(h),j=[];let ne=0;for(let T=0;T<h;T++){const X=p?.[T],Z=f?.[T],ft=X!==void 0&&v.has(X),gt=Z!==void 0&&x.has(Z),ca=y[T]===1;if(n==="observation-rerender")(ft||ca||gt)&&(V[T]=1,ne++);else if(ft)V[T]=1,ne++;else if(ca||gt){const ua=g?.[T];ua!==void 0&&j.push({observation:ua,observationIndex:T})}}const H=ne>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&H!==null,matchedLayer:H,overlayCandidates:j}}var dp=l.prefixInternalVariable("__ungrouped__");function mp(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,o=i.map((c,u)=>{if(c===null)return null;const d=r[u]??dp;let m=s.get(d);return m||(m=new l.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",o)}return n}var pp=()=>({defaults:[],overrides:[],warnings:[]}),hp=class extends Ae{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,Ia(e)]}compileLayer(e,t){const r=this.transformCompiler.compile({data:t.data,transforms:e.transforms}),n={...t.mapping,...e.mapping};return this.runLayerPipeline(e,r,n,Ia(t))}runLayerPipeline(e,t,r,n){const a=Kt({data:t,mapping:r}).pipe(({data:s,mapping:o})=>{const c=this.statCompiler.compute(e.stat,{data:s,mapping:o,xScaleIsDiscrete:n});return{data:c.data,mapping:{...o,...c.mapping}}}).pipe(({data:s,mapping:o})=>({data:this.groupCompiler.compute({data:s,mapping:o}).data,mapping:o})).pipe(({data:s,mapping:o})=>({data:mp(s),mapping:o})).pipe(({data:s,mapping:o})=>{const c=this.geomCompiler.compile(e.geom,{data:s,mapping:o,params:e.params});return{data:c.data,mapping:{...o,...c.mapping}}}).pipe(({data:s,mapping:o})=>{const c=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:o});return{data:c.data,mapping:{...o,...c.mapping}}}).result(),i=this.container.geomRegistry.get(e.geom);return{...a,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:i.spatialKind,identityKey:i.identityKey,tooltip:i.tooltip,supportsDirectLabels:i.legend.directLabelSupport?.[e.position]===!0,highlight:ds(e.geom),styles:pp()}}};function Ia(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function ps(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}var fp=new Set(["label","group"]),gp=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,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),ps(this.container.diagnostics,t)}checkPostCompile(e){Ei(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)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!qt(r,t))return[];const c=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 '${c}'.`,context:{layerIndex:n,expected:c,actual:s},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:s,aesthetics:o}=this.container.geomRegistry.get(r),c=[...Wd(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!Qi.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(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(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}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}}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...Hd(i),...s.map(h=>h.name)]),u=fp,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},se=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,ze.merge)({},this.defaultParams,e.params)}},on=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},ln=(e,{coordSystem:t})=>{if(t.type==="polar")return null;const r=R(e),n=E(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},yp=class extends se{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=ln}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=on(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Ta=.7,vp=.1,hs=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},bp=class extends se{constructor(...e){super(...e),this.type="bar",this.defaultParams={width:Ta},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveAnchorBox=Vr,this.resolveDataLabelDefaults=t=>P(t)?{justify:"center"}:{},this.resolveBandFraction=t=>t.width,this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Sp(t);if(i!==void 0){const m=Vr(t,r);return m===null?null:tt(m,i)}const s=P(n),o={isSolo:!s||hs(t)==="solo",isNegative:s&&xp(t),purpose:a};if(r.mainAxis==="x"){const m=K(t),h=Y(t),p=La({lowerBound:F(t),upperBound:M(t)??E(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=F(t),u=M(t),d=La({lowerBound:K(t),upperBound:Y(t)??R(t),options:o});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const t=super.resolveParams(e),{diagnostics:r}=e;return{...t,width:this.resolveWidthParam(t.width,r)}}compile({data:e,mapping:t,params:r}){const{width:n}=r;e=on(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const a=n/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-a).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",a),{data:e,mapping:{}}}resolveWidthParam(e,t){const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return r;const n=r!==null&&r>1?1:Ta;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the category band in (0, 1]."}),n}},Sp=e=>{const t=K(e),r=Y(e),n=F(e),a=M(e);if(t===null||r===null||n===null||a===null)return null;const i=(t+r)/2,s=(n+a)/2;return{x:.5+.5*s*Math.sin(i),y:.5-.5*s*Math.cos(i)}},xp=e=>{const t=Yr(e);return l.isStrictNumericDataValue(t)&&t<0},La=e=>{const{lowerBound:t,upperBound:r,options:n}=e,a=n.isNegative?t:r;if(a===null)return null;if(n.purpose==="value"||n.isSolo)return a;const i=n.isNegative?r:t;return i===null?null:(i+a)/2},Ap=class extends se{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorBox=Vr,this.resolveAnchorPosition=ln}compile(e){return{data:on(e.data,e.mapping),mapping:{}}}},Ip=class extends se{constructor(...e){super(...e),this.type="point",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"size"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.resolveAnchorPosition=ln,this.resolveDefaultLabelSource=t=>{const r=l.extractVariableName(t.size);return r!==null?{variable:r}:null}}compile({data:e}){return{data:e,mapping:{}}}},Tp=class extends se{constructor(...e){super(...e),this.type="rule",this.defaultParams={labelPosition:"start"},this.defaultInteractive=!1,this.positionRoles=[{axis:"y",role:"scalar",valueKind:"value",aes:"y"},{axis:"x",role:"scalar",valueKind:"value",aes:"x"}],this.highlightStrategy=null,this.spatialKind="noop",this.validateMapping=({mapping:t,computedVariables:r})=>{const n=r.has("x")||l.isStrictNumericDataValue(l.extractConstantValue(t.x)),a=r.has("y")||l.isStrictNumericDataValue(l.extractConstantValue(t.y));return n&&a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires exactly one of 'x' or 'y', both were provided"}]:!n&&!a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires a numeric value on 'x' or 'y'"}]:[]}}compile({data:e,mapping:t}){const r=wa(t.y,e);if(r!==null)return{data:new l.Dataset({[l.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:l.RULE_VARIABLES.y,x:void 0}};const n=wa(t.x,e);return n!==null?{data:new l.Dataset({[l.RULE_VARIABLES.x]:{type:"numeric",values:[n.value],valueFormat:n.sourceFormat}}),mapping:{x:l.RULE_VARIABLES.x,y:void 0}}:{data:new l.Dataset,mapping:{x:void 0,y:void 0}}}},wa=(e,t)=>{const r=l.extractConstantValue(e);if(l.isStrictNumericDataValue(r))return{value:r,sourceFormat:void 0};const n=l.extractVariableName(e);if(n===null||!l.isStatVariable(n)||!t.hasVariable(n))return null;const[a]=t.getValues(n);return l.isStrictNumericDataValue(a)?{value:a,sourceFormat:t.getValueFormat(n)}:null},Lp=[new bp,new Ip,new Ap,new yp,new Tp],jt=class extends l.Registry{constructor(){super("geom");for(const e of Lp)this.register(e.type,e)}},Ie=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},wp=class extends Ie{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.x);if(!l.isDefined(r))throw new l.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(l.extractVariableName(t.y)!==null)throw new l.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,...qe(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},Ep=class extends Ie{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Vp=class extends Ie{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});return{data:e.rollup({[l.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:l.STAT_VARIABLES.mean}}}},Rp=2,fs=1440*60*1e3,Cp=class extends Ie{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 l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.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(!l.isDefined(i))throw new l.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),o=e.getType(i);if(o!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${o}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:o}});const c=qe(e,t),u=Np(a,s,i,c,e);return c.length===0?Ea({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=Bp(d,c);Ea({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Ea=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=kp({data:e,xVariable:t,yVariable:n,xType:r});c.length<Rp||(o?Pp({observations:c,spec:a,output:i,groupObservation:s}):_p({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},kp=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Dp(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=Op({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},Dp=e=>{let t=null;for(const r of e){if(!l.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Op=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!l.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!l.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/fs+1}case"categorical":{if(!l.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 l.InternalError({message:`Unexpected xType: ${t}`})}},_p=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=gs(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?Mp(o,r):o;a.push({x:u,y:c,groupObservation:i})}},Mp=(e,t)=>t===null?new Date(e):new Date((e-1)*fs+t),Pp=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const o of e)a.has(o.x)||a.set(o.x,o.originalX);const i=[...a.keys()].sort((o,c)=>o-c);if(t.method==="loess"){const o=gs(t,e),c=new Map;for(const[u,d]of o)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=ys(t,e);for(const o of i){const c=a.get(o),u=s.predict(o);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},gs=(e,t)=>e.method==="loess"?(0,ue.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ys(e,t),ys=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,ue.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,ue.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,ue.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,ue.regressionQuad)().x(r).y(n)(t);case"power":return(0,ue.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,ue.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},Np=(e,t,r,n,a)=>{const i=[],s=[],o=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),s.push(u);for(const m of n)o[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:o[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},Bp=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Fp=class extends Ie{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});const n=l.extractVariableName(t.x),a=[...new Set([...n===null?[]:[n],...qe(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},$p=[new Ep,new wp,new Cp,new Vp,new Fp],Gp=class extends l.Registry{constructor(){super("stat");for(const e of $p)this.register(e.type,e)}};function Up({geoms:e,stats:t,transforms:r}){const n=new jt,a=new Gp,i=new l.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}}function cn(e){if("definition"in e)return e.definition;if(bs(e)||Ss(e)||xs(e))return e}function vs(e){const t=[],r=[],n=[];for(const a of e){const i=cn(a);i&&(bs(i)?t.push(i):Ss(i)?r.push(i):xs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...cr("geom",t,a=>a.type),...cr("stat",r,a=>a.type),...cr("transform",n,a=>a.transformType),...Wp(t)]}}function Wp(e){const t=[];for(const r of e)r.spatialKind!=="render-hit-test"||r.identityKey!=="x-group"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the default 'x-group' identity, which has no meaning for render-owned geometry; its hover lookup will be empty.`,context:{kind:"geom",requested:r.type},suggestion:"Declare 'identityKey' as a column the geom owns (`{ variable: '<column>' }`) or 'index', so a hit-test result resolves to an observation."});return t}function cr(e,t,r){const n=new Map;for(const i of t){const s=r(i),o=n.get(s);o?o.add(i):n.set(s,new Set([i]))}const a=[];for(const[i,s]of n)s.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${s.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var bs=e=>e instanceof se,Ss=e=>e instanceof Ie,xs=e=>"transformType"in e&&typeof e.apply=="function",Hp=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Xt=class{},zp=class extends Xt{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!l.extractVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),i=Kp(e)??[-.7/2,.7/2],s=r.length>1?vp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Kp=e=>{const t=e.getConstant(l.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(l.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},Va=l.prefixInternalVariable("__ungrouped__"),As=(e,t)=>{const r=l.extractVariableName(t.x),n=l.extractVariableName(t.y);if(!r||!n)return null;const a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[Va]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?Va:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},Is=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=Yp(p===o,p===d)}return a},Yp=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",qp=class extends Xt{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=As(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const I=x>=0?m:h;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=Is(c,o,a,s);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},jp=class extends Xt{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Xp=class extends Xt{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=As(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=Is(c,o,a,s);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const m=l.extractVariableName(t.y);return m!==null&&(d=d.addVariable(m,"numeric",o)),{data:d,mapping:{}}}},Zp=class extends l.Registry{constructor(){super("position"),this.register("identity",new jp),this.register("stack",new Xp),this.register("fill",new qp),this.register("dodge",new zp)}},Jp=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"||!l.isDefined(s.aes)||en(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ts(s.axis,t.yScaleType));if(!c)continue;const u=a.getValues(o,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},Qp=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},eh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},th=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(ae(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},rh=class{map({data:e,layer:t,getPositionScale:r}){const n=r(ae(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=e.size(),o=new Array(s),c=new Array(s);for(let u=0;u<s;u++){const d=a[u],m=i[u];l.isDefined(d)&&l.isDefined(m)?(o[u]=n.map(d),c[u]=n.map(m)):(o[u]=null,c[u]=null)}return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",o).addVariable(l.POSITION_VARIABLES.yMax,"numeric",c)}},nh=[new Qp,new th,new eh,new rh,new Jp];function ah(e,t){const r=e[t];return r?.kind==="position"?r:null}var ih=class extends Ae{constructor(e,t=nh){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=>ah(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}}},sh=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const a of e.scales)t.set(a.scaledAesthetic,a);const r=this.collectValues(e.layers,t),n={};for(const[a,i]of t){const s=r.get(a)??[];n[a]=this.registry.get(i.scaleType).compile(i,s)}return n}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=N(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const s=l.extractVariableName(i.mapping[a]);if(!l.isDefined(s)||!i.data.hasVariable(s))continue;const o=i.data.getType(s);if(n.includes(o)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${o})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o}}),r.scaledAesthetic==="lineType"&&o!=="categorical"){const c=o==="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 ${o} variable '${s}'. ${c}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o},suggestion:c})}}ps(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(!l.isDefined(s))continue;const o=i==="y"?ae(n.yScaleType):i,c=a.get(i)??(es(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=this.resolveVariables(i,s,n.data);this.collectFromVariables(n.data,u,c,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"||!l.isDefined(n.aes)||en(n.aes)||t.set(n.aes,ts(n.axis,e.yScaleType));return t}resolveVariables(e,t,r){if(e==="y"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const n=l.extractVariableName(t);return!n||!r.hasVariable(n)?[]:[n]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.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)}},oh=["rgb","lab","hcl","hsl"],lh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],Ts=["RdBu","BrBG","PuOr","Spectral"],Ls={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},ch=new Set(Ts.map(e=>e.toLowerCase()));function ws(e){const t=e.toLowerCase(),r=Ls[t];return r?r.toLowerCase():t}function uh(e){return ch.has(ws(e))}var dh={rgb:De.interpolateRgb,lab:De.interpolateLab,hcl:De.interpolateHcl,hsl:De.interpolateHsl},mh={viridis:D.interpolateViridis,magma:D.interpolateMagma,inferno:D.interpolateInferno,plasma:D.interpolatePlasma,cividis:D.interpolateCividis,turbo:D.interpolateTurbo,blues:D.interpolateBlues,greens:D.interpolateGreens,greys:D.interpolateGreys,oranges:D.interpolateOranges,purples:D.interpolatePurples,reds:D.interpolateReds,rdbu:D.interpolateRdBu,brbg:D.interpolateBrBG,puor:D.interpolatePuOr,spectral:D.interpolateSpectral};function un(e){const t=hh(e);return e.reverse?r=>t(1-r):t}function ph(e={},t=2){const r=un({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??l.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 hh(e){const t=dh[e.interpolate];if(e.range&&e.range.length>=2)return(0,De.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=mh[ws(e.scheme)];if(r)return r}return(0,De.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var st=class{createPositionScale(e,t){return{kind:"position",aesthetic:N(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:N(e.scaledAesthetic),spec:e,...t}}},fh=class extends st{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t){if(e.scaleType!=="continuous")throw new l.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const r=Ye(e.scaledAesthetic),n=e.scaledAesthetic==="color",a=this.computeDataDomain(t,e);return n?this.buildColorScale(a,e):r?this.buildPositionScale(a,e):this.buildVisualScale(a,e)}computeDataDomain(e,t){let r=1/0,n=-1/0;for(const a of e)typeof a=="number"&&(a<r&&(r=a),a>n&&(n=a));return r===1/0?[0,0]:(t.zero&&(r>0&&(r=0),n<0&&(n=0)),[r,n])}createD3Scale(e,t,r){let n=[r.domainMin??e[0],r.domainMax??e[1]];const a=r.transform==="log"&&gh(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:N(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=yh(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=un(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],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,Q.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){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,Q.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},gh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function yh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var vh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new l.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=Ye(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new l.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=bh(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?em(i,s,c.interval):[]:a.ticks(c?.count)})}},bh=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Sh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new l.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=Ye(e.scaledAesthetic),n=Ji(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??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,Q.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})}},xh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:N(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Ah=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const r=Zi(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},Ih=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new fh(e)),this.register("discrete",new Sh),this.register("datetime",new vh),this.register("identity",new xh),this.register("palette",new Ah)}},Tt={color:null,size:"small",labelCrossPosition:.5},de={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},ur={zOrder:"foreground",fit:"contain",opacity:1},Th={x:8,y:8,unit:"px"},Lt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},me={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Lh={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}},wh=(e,t,r)=>{const n=Eh(e,t),a=Ch(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Dh(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Ph(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Fh(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>kh(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>Oh(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Nh(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>_h(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Mh(e,i,r)).filter(l.isDefined)}},Eh=(e,t)=>{if(t===void 0)return{};if(!Vh(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:O()}):(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))}},Vh=e=>{const t=new Set;for(const r of Rh(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},Rh=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Ch=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},dn=(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},kh=(e,t,r,n)=>{const a=Nt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),content:t.content,at:a,width:t.width,align:t.align??Lt.align,backgroundColor:t.backgroundColor??Lt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??Lt.backgroundColorStyle}},Dh=(e,t,r)=>{const n=Qe(e,t.start,r),a=Qe(e,t.end,r);return n===null||a===null?null:{id:t.id??O(),start:n,end:a,label:t.label,color:t.color??Tt.color,size:t.size??Tt.size,labelCrossPosition:t.labelCrossPosition??Tt.labelCrossPosition}},Qe=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,...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)},Nt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return dn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=Qe(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},Oh=(e,t,r,n)=>{const a=Nt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),at:a,sticker:t.sticker}},_h=(e,t,r)=>{const n=Qe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n}},Mh=(e,t,r)=>{const n=Qe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n,content:t.content}},Ph=(e,t,r)=>t.region.anchorType==="annotation"&&!dn(e,t.region.ref,r,t.id)?null:{id:t.id??O(),kind:t.kind??de.kind,zOrder:t.zOrder??de.zOrder,region:Bh(t.region),fillColor:t.fillColor===void 0?de.fillColor:t.fillColor,fillOpacity:t.fillOpacity??de.fillOpacity,strokeWidth:t.strokeWidth??de.strokeWidth,strokeColor:t.strokeColor??de.strokeColor},Nh=(e,t,r)=>t.region.anchorType==="annotation"&&!dn(e,t.region.ref,r,t.id)?null:{id:t.id??O(),src:t.src,zOrder:t.zOrder??ur.zOrder,region:t.region,fit:t.fit??ur.fit,opacity:t.opacity??ur.opacity},Bh=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:Th},Ra=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=Lh[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Fh=(e,t,r,n)=>{const a=Nt(e,t.start,r,n,t.id),i=Nt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??O(),start:Ra(a),end:Ra(i),color:t.color??me.color,thickness:t.thickness??me.thickness,startArrowheadStyle:t.startArrowheadStyle??me.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??me.endArrowheadStyle,lineStyle:t.lineStyle??me.lineStyle,hasStickerStyle:t.hasStickerStyle??me.hasStickerStyle}},$h={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{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},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function Gh(e){const t=(0,ze.merge)({},$h,e);return t.content=Uh(t.content,e?.content),t}var Uh=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Wh={xLimits:null,yLimits:null},wt={theta:"x",startAngle:0,innerRadius:0};function _r(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,kt.default)({},Wh,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??wt.theta,startAngle:t.params?.startAngle??wt.startAngle,innerRadius:(0,Pe.default)(t.params?.innerRadius??wt.innerRadius,0,1)}}}}function Hh(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??O(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var zh=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=Ca(e.filter(n=>n.severity==="error")),r=Ca(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Kh=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 Ca(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Yh={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:l.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4};function Es(e,t){const r=e??t,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 Te(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Kh(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=Xh({dataLabels:Jh(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return jh({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??O(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Es(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:o.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??o.defaultInteractive,dataLabels:u}}function qh(e,t,r,n,a){const i=n.map((s,o)=>Te(e,t,r,s,a,o));return Rs(e,i)}var Vs=(e,t,r,n)=>n.label!==void 0?n.label:Qh(e,t,r,n),Rs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:at(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=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,ze.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},jh=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t==="polar",s=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"&&s&&P(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&&!(s&&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'."}),a.showCategoryLabels&&a.showDataLabels&&!i&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showCategoryLabels only applies to polar bars (pie / donut); it will be ignored.",suggestion:"Turn off showCategoryLabels for this layer."})},Xh=({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 o=Zh(t,r,n);if(o===null)return e;const c=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${o}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Zh=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&P(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Jh=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Vs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,ze.merge)({},Yh,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Qh=(e,t,r,n)=>e.get(t).resolveDefaultLabelSource?.(n)??Wt(r,n);function Mr(e,t){const r=ef(e,t);if(r===null)return{discreteAxis:null,zeroAxis:null,niceZeroAxis:!0};const{layer:n,scaleConstraints:a}=r;return{discreteAxis:a.discreteMainAxis?"x":null,zeroAxis:a.zeroBaseline?ae(n.yScaleType):null,niceZeroAxis:n.position!=="fill"}}function ef(e,t){for(const r of t){if(!e.has(r.geom))continue;const{scaleConstraints:n}=e.get(r.geom);if(n!==void 0)return{layer:r,scaleConstraints:n}}return null}var Cs={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},tf={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 mn(e,t,r,n,a,i){switch(t.scaleType){case"inferred":return mn(e,nf(e,t,r,n,a),r,n,a,i);case"continuous":{const s=Cs[t.scaledAesthetic],o=s==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,c=t.scaledAesthetic==="size"&&s==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??c,reverse:t.reverse??l.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??l.CONTINUOUS_SCALE_DEFAULTS.nice,zero:t.zero??l.CONTINUOUS_SCALE_DEFAULTS.zero,clamp:t.clamp??s!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??o??null,scheme:af(e,t),interpolate:t.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??l.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??l.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??l.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??l.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??l.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return ks(t);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e,t.palette,i),overrides:l.resolvePaletteOverrides(e,t.overrides,t.palette,i)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function rf(e,t,r,n,a,i,s){const o=lf(of(r,n)),c=new Map;for(const d of o)c.set(d.scaledAesthetic,d);const u=[...c.values()].map(d=>mn(e,d,t,n,a,s));return i.coordType==="polar"?u.map(Ds):u}function ks(e){return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??l.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??l.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??l.DISCRETE_SCALE_DEFAULTS.reverse}}var Ds=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function nf(e,t,r,n,a){const i=N(t.scaledAesthetic),s=t.scaledAesthetic==="ySecondary"?sf(n,a):a[i],o=Mr(e.geomRegistry,n);if(t.scaledAesthetic===o.discreteAxis)return l.discrete(t.scaledAesthetic,t.options);if(t.scaledAesthetic===o.zeroAxis){const m=t.options;return l.continuous(t.scaledAesthetic,{...m,zero:!0,...!o.niceZeroAxis&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!r.hasVariable(c))return l.continuous(t.scaledAesthetic,t.options);const u=r.getType(c),d=Cs[t.scaledAesthetic];switch(tf[u][d]){case"discrete":return l.discrete(t.scaledAesthetic,t.options);case"palette":return l.palette(t.scaledAesthetic);case"datetime":return l.datetime(t.scaledAesthetic,t.options);case"continuous":return l.continuous(t.scaledAesthetic,t.options);default:return l.identity(t.scaledAesthetic)}}function af(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.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:N(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&uh(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:N(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function sf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function of(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function lf(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var cf=e=>{const t=new Set;e!==void 0&&Os(e,t,new Set);const r={tokens:{},defaults:[],overrides:[]};for(const n of t)Object.assign(r.tokens,n.tokens),r.defaults.push(...n.defaults??[]),r.overrides.push(...n.overrides??[]);return r},Os=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Os(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function uf(e,t,r){const n=_r(t.coords),a=qh(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=rf(e,t.data,t.scales,a,t.mapping,n,r),s=Gh(t.config),o=Hh(e,t.highlights,a),c=wh(e,t.annotations,a),u=cf(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:o,styles:u,annotations:c,coords:n,config:s}}var _s=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return uf(this.container,{...e,data:t},r)}},df=class{constructor(e){this.registry=e}compute(e,t){return this.registry.get(e.type).compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete})}},mf=class extends Ae{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Tf(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of Lf(e.styles))this.container.diagnostics.addWarning(r);for(const r of wf(e.styles))this.container.diagnostics.addWarning(r);for(const r of t)for(const n of r.styles.warnings)this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=Us({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Oe={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ms={bar:{...Oe,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Oe,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Oe,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Oe,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},ka=1,Da=1e3,yt={color:"color",strokeWidth:"pixels",lineType:"lineType"},dr={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Et={panelBorder:{...yt,borderRadius:"pixels"},panelBorderEdge:yt,gridLine:yt,tickLine:{...yt,length:"pixels"},axisLabel:dr,tickLabel:{...dr,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...dr,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"}},pf=new Set([...Object.keys(Oe),...Object.values(Ms).flatMap(e=>Object.keys(e??{})),...Object.values(Et).flatMap(e=>Object.keys(e))]),Ps=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph"],hf=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),ff=(e,t,r="en-US")=>Us({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),gf=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Ns(e.styles)}},Ns=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(Zt(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!yf(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${Ps.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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 m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!bf(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(hf.has(m.target)){const p=m.axis;if(p!==void 0&&!Af(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${Jr.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${Ge(p)}.`,context:{param:"layer",actual:Ge(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!Sf(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!xf(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=pn({declarations:i.declarations,vocabulary:vf(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.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},Zt=e=>e.select.target==="geom",yf=e=>{const t=e.select.target;return t!=="geom"&&Ps.includes(t)},Bs=e=>(e!==void 0?Ms[e]:void 0)??Oe,vf=e=>e.target==="panelBorder"?e.edge===void 0?Et.panelBorder:Et.panelBorderEdge:Et[e.target],bf=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),Sf=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),xf=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Af=e=>typeof e=="string"&&Jr.includes(e),If=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!Zt(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=pn({declarations:a.declarations,vocabulary:Bs(s),tokens:t,location:`builtin[${i}]`,origin:o,warnings:r});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:o})}),n},Fs=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},Tf=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Fs(e,(a,i,s)=>{const o=a.select;if(o.target!=="geom"&&o.target!=="ruleLabel")return;const c=o.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},Lf=e=>{const t=[];return Fs(e,(r,n,a)=>{if(!Zt(r))return;const i=r.when?.state;i===void 0||$s(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 ${l.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),t},$s=e=>l.STYLE_STATES.includes(e),wf=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Gs(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Ge(n)}.`,context:{param:"tokens",actual:Ge(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Gs=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,vt=e=>typeof e=="number"&&Number.isFinite(e),Ge=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Us=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=zt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!Zt(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!$s(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const I=fe(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=pn({declarations:h.declarations,vocabulary:Bs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:he(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...If(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},pn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${Ge(g)}.`,context:{param:p,expected:f,actual:Ge(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Gs(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=pf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":vt(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":vt(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Ci(f)?u(p,f):d(p,`one of ${qr.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":vt(f)&&f>=ka&&f<=Da?u(p,f):d(p,`a number in [${ka}, ${Da}]`,f);break;case"multiplier":vt(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;default:break}}return o},Ef=({layer:e})=>{if(e.position==="stack")return;const t=l.extractVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];l.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Vf=({layer:e})=>{if(e.position!=="stack")return;const t=l.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const r=new Map;for(const a of e.data){const i=a[t],s=F(a),o=M(a),c=K(a),u=Y(a),d=Yr(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=sn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},Rf=class extends Ae{constructor(e){super(),this.container=e}dependencies(){return[]}compileLayer(e){const t=this.container.geomRegistry.get(e.geom),r={};if(t.summaries.stackTotals){const n=Vf({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=Ef({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Ws=class extends l.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)}},Oa={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Cf=["color","size","alpha","strokeWidth","lineType"],kf=class extends Ae{dependencies(e){return Cf.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Oa[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,Oa[a],Df(c)))}return{...e,data:r}}},Df=e=>t=>l.isDefined(t)?e.map(t):null;function Hs(e=new jt){return{diagnostics:new zh,geomRegistry:e}}var zs=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{if(e.data===void 0)return this.runPipeline({spec:e.spec});this.lastData=e.data;const r=Sd(e.spec.data,e.spec.mapping);return this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data),mapping: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}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,compiled: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:[Wi(e)],warnings:t.warnings}}trackCompile(e){if(!l.IS_DEV)return e();const t=this.getCacheStats(),r=performance.now(),n=e(),a=performance.now()-r,i={};for(const{name:s,getStats:o}of this.stages){const c=o();i[s]={hits:c.hits-t[s].hits,misses:c.misses-t[s].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e}){return Kt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result()}},Of=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],_f=({plugins:e=[]}={})=>{const t=vs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Up(t),i=Hs(r),s=new Ih(i),o=new Ws(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new zs(i,new l.DataCompiler,new _s(i),o,new bd,new gp(i,o,n,new hp(i,o,new df(n),new Yd,new Kd(i),new Hp(new Zp))),new sh(i,s),new Id(new Gd),new ih(i),new kf,new ap(i),new Rf(i),new mf(i),new gf(i),new cp(i),new id(i))};function Mf(e,t){return e.geom===t}function Ks(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Pf(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>qs(s,o),i)}function Ys(e,...t){return t.reduce((r,n)=>qs(r,n),e)}function Pf(e){return typeof e=="object"&&e!==null&&"type"in e}function qs(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:(0,kt.default)({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};case"highlight":return{...e,highlights:[...e.highlights,t]};case"styles":return{...e,styles:e.styles===void 0?t:{...t,extends:[e.styles,...t.extends??[]]}};case"annotation":return Nf(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Nf(e,t){const r={...e.annotations};switch(t.kind){case"differenceArrow":r.differenceArrows=[...r.differenceArrows??[],t.annotation];break;case"shape":r.shapes=[...r.shapes??[],t.annotation];break;case"arrow":r.arrows=[...r.arrows??[],t.annotation];break;case"text":r.textAnnotations=[...r.textAnnotations??[],t.annotation];break;case"image":r.images=[...r.images??[],t.annotation];break;case"sticker":r.stickers=[...r.stickers??[],t.annotation];break;case"pinnedNumber":r.pinnedNumbers=[...r.pinnedNumbers??[],t.annotation];break;case"comment":r.comments=[...r.comments??[],t.annotation];break;default:throw new Error(`Unknown annotation kind: ${t.kind}`)}return{...e,annotations:r}}function Bf(e){const t=e?.plugins??[],r=$f(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Ks,pipe:Ys,plugins:t}}var Ff=e=>(t={})=>l.buildLayerInput(e,t);function $f(e){const{geoms:t,stats:r,transforms:n}=vs(e),a={};for(const o of t)a[o.type]=Ff(o.type);const i={};for(const o of r)i[o.type]=()=>({type:o.type});const s={};for(const o of n)s[o.transformType]=c=>({type:"transform",transformType:o.transformType,options:c?.options});return{geom:a,stat:i,transform:s}}var Gf=24,Uf={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:8,before:0},topAxisLabel:{after:8,before:0},topAxis:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16},footer:{after:0,before:16}},Wf={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},mr="…",js=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(mr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+mr)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+mr};var B={timeZone:"UTC"},_=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},oe=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",hn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Hf=Er.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Xs=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>oe(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=yn(a,i),{base:o,suffix:c}=gn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),Zs=({locale:e,numberFormat:t,intlOptions:r})=>oe(n=>{const{base:a,suffix:i}=gn(n,t.abbreviation),s={...yn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),fn=e=>oe(t=>Hf(t)),Js=({locale:e,intlOptions:t})=>oe(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Qs=({locale:e,numberFormat:t,intlOptions:r})=>oe(n=>{const a=yn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),gn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=zf(e);return gn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},yn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},zf=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},Kf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).format(r)),Yf=({locale:e,intlOptions:t})=>_(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...B,...t}).formatToParts(r);return qf(n.map(jf))}),eo=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t}).format(r)),to=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"long",...B,...t}).format(r)),vn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...B,...t}).format(r)),bn=e=>_(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),ro=({locale:e,intlOptions:t})=>_(r=>{const n=(0,Ti.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t,year:void 0}).formatRange(r,n)}),no=({locale:e,intlOptions:t})=>_(r=>{const n=(0,Ti.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).formatRange(r,n)}),Sn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{year:"numeric",...B,...t}).format(r)),ao=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),qf=e=>e.map(t=>t.value).join(""),jf=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},_a=1e3,Xf=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>oe(a=>{const i={...An(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return xn(a,t,i)}),Zf=({locale:e,tickValues:t,intlOptions:r})=>oe(n=>{const a={...An(n,t),notation:"compact",...r};return xn(n,e,a)}),Jf=({locale:e,tickValues:t,intlOptions:r})=>oe(n=>{const a={...An(n,t),notation:"compact",...r,style:"percent"};return xn(n,e,a)}),xn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),io=e=>Math.abs(e)>_a?io(e/_a):Number.isInteger(e),Qf=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},An=(e,t)=>io(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Qf(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},eg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),tg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",...B,...t}).format(r)),rg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),ng=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),In=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Xf(e);case"date":case"datetime":return eg(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return rg(e);case"decimal":case"integer":return Zf(e);case"duration":return fn(e);case"month":return tg(e);case"month_year":return vn(e);case"percentage":return Jf(e);case"quarter":return bn(e);case"text":return hn(e);case"time":return ng(e);case"year":return Sn(e);case"lookup":return In({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},ag=.9,ig=1/3,sg=1/4,og=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?lg(e):cg(e),lg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=so(e.ticks,n),o=ug(e.ticks,r.width),c=o*ag;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=Nr(c);return{...e,ticks:Pr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Nr(r.height*ig);return{...e,ticks:Pr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},cg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=so(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Nr(r.width*sg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Pr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},ug=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},so=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:s,height:o}=t(i.formattedLabel);r.push(s),s>n&&(n=s),o>a&&(a=o)}return{widths:r,maxWidth:n,maxHeight:a}},Pr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:js(i.formattedLabel,r,a)})},Nr=e=>Math.max(0,Math.floor(e)),dg=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let s=r-(e.length-1)*i;for(const o of e){const{width:c,height:u}=n(o);if(s-=a?c:u,s<0)return!1}return!0},mg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?pg(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;dg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},pg=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),Ma=.5,ot=e=>({x:0,y:0,width:e.width,height:e.height}),Tn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,lt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:fg(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:gg(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,I=Na(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Na(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:hg(e,I,A,c,u)}},Pa=(e,t,r,n)=>r-n>=e-Ma&&r+n<=t+Ma,hg=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||Pa(e.x,e.x+e.width,t,n/2),s=e.height===0||Pa(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},fg=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",gg=e=>e==="center"?"center":e==="start"?"min":"max",Na=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const s=r+i;return e==="min"?t==="inside"?n+s:n-s:t==="inside"?a-s:a+s},yg=(e,t,r,n,a)=>{const i=t??e,s=1-Math.max(e,i);return{box:{x:r*n,y:s*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},vg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Sg(e.layer);for(const a of e.layer.data){const i=R(a),s=M(a)??E(a);if(i===null||s===null||!Be(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),{box:d,frame:m}=yg(s,F(a),i,e.panelRect.width,e.panelRect.height),h=lt({box:d,panel:ot(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},bg={place:vg,getPercentageValueStrategy:e=>e.position==="fill"?"fill":P(e.position)?"stack":"none"},Sg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:qt(e.data,e.mapping)?Tn(r):r,align:n}},Ln=(e,t,r)=>{const n={},a=i=>{const s=n[i];if(s!==void 0)return s;const{width:o,height:c}=e(t,i,r),u={width:o,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},bt=6,xg=e=>{const t=[],r=P(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=Ig({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:n});for(const s of a){const o=e.layer.dataLabels.position==="auto"?wg({mainAxis:e.coordSystem.mainAxis,isStacked:r,isNegativeBar:s.isNegative,shouldRotate:i,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Eg(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,ot(e.panelRect));if(o===null)continue;const c=s.boxes[o.position];t.push({layerId:e.layer.id,x:o.x,y:o.y,text:s.text,width:c.width,height:c.height,isRotated:o.isRotated,target:"observation",position:o.position})}}if(e.layer.dataLabels.showCategoryLabels)for(const a of Vg(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=Dg({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const i of a)t.push(i)}return t},Ag={place:xg,getPercentageValueStrategy:e=>e.position==="fill"?"fill":P(e.position)?"stack":"absoluteGrandTotal"},Ig=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const s=[];let o=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y);for(const d of e.data){const m=lo(t,d);if(m===null)continue;const h=a(d);if(h==="")continue;const p=Ln(n,"observation",h),f=wn(m,r);c&&p.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:h,boxes:p,bounds:f})}return{entries:s,shouldRotate:!i&&o}},wn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),oo=(e,t,r,n,a)=>{if(e==="x"){let o=1-a,c=a-n;return c<0&&(o+=c,c=-c),{x:t,y:o,width:r-t,height:c}}let i=t,s=r-t;return s<0&&(i+=s,s=-s),{x:i,y:1-a,width:s,height:a-n}},lo=(e,t)=>{const r=K(t),n=Y(t),a=F(t),i=M(t)??E(t);return r===null||n===null||a===null||i===null?null:oo(e,r,n,a,i)},Tg=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return oo(e,r,n,a,i)},Lg=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Br=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},wg=e=>e.isStacked?Rg({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):kg({edge:Lg(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),co=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Eg=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,s=n.boxes[i],o=lt({box:n.bounds,panel:a,frame:co(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:s.width,labelHeight:s.height});return{x:o.x,y:o.y,isRotated:!1,position:o.position}},Vg=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:s}=e.layer.dataLabels,o=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=ot(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=lo(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=Ln(e.measureDataLabel,"category",p),g=f[o],y=wn(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=lt({box:y,panel:u,frame:co(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},Rg=({bounds:e,box:t,isRotated:r})=>{const n=Br(t.width,t.height,r);return n.width>e.width||n.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},Cg=(e,t,r,n)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:n};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:n};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:r};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:r}}},kg=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=Cg(e,t,a,i),g=Br(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height;if(y+s<d){if(v>m)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const V=h-p*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=Br(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=h+p*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},Dg=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return i;const o=t==="y";for(const c of s){const u=wn(Tg(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+bt+m/2:u.x-bt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-bt-h/2:u.y+u.height+bt+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},Og=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Mg(e.layer);for(const a of e.layer.data){const i=R(a),s=E(a);if(i===null||s===null||!Be(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=lt({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:ot(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return t},_g={place:Og,getPercentageValueStrategy:()=>"none"},Mg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:qt(e.data,e.mapping)?Tn(r):r,align:n}},Pg={color:Ht,alpha:Oi,strokeWidth:kr,lineType:_i,size:jr,borderWidth:kr},En=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:o=>{const c=r.get(o);if(c!==void 0)return c;const u=Fg(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=Ng(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=Je(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=Je(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=Je(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=uo(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=Je(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},Ng=(e,t)=>{const r=(o,c)=>({get:d=>{const m=Ba(o.overrides,d,c,t);return m!==void 0?m:Ba(o.defaults,d,c,t)}}),n=o=>r(e.panelBorder,c=>{const u=c.select.target==="panelBorder"?c.select.edge:void 0;return u===void 0||u===o}),a=o=>c=>r(e[o],u=>u.select.target!==o?!1:u.select.axis===void 0||u.select.axis===c),i=o=>r(e.ruleLabel,c=>c.select.target!=="ruleLabel"?!1:c.select.layer===void 0||c.select.layer===o),s=(o,c)=>r(e.dataLabel,u=>u.select.target!=="dataLabel"||u.select.role!==void 0&&u.select.role!==o?!1:u.select.position===void 0||u.select.position===c);return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:s,graph:r(e.graph,()=>!0)}},Ba=(e,t,r,n)=>{for(let a=e.length-1;a>=0;a--){const i=e[a];if(i===void 0||!r(i))continue;const s=i.declarations[t];if(s!==void 0)return Bg(s,n)}},Bg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Fg=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=St(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=St(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=St(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=uo(n,a);return o!==void 0?o:St(e.defaults,n,a,void 0,t)}}),St=(e,t,r,n,a)=>Je(e,t,r,n,a)?.value,Je=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(s===void 0||s.state!==n)continue;const o=s.declarations[t];if(o!==void 0&&$g(s,r))return{value:Gg(o,a),origin:s.origin}}},$g=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),Gg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,uo=(e,t)=>{const r=Pg[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Ug=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Hg(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=En().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=E(s);if(o===null||c===null||!Be(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=lt({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:ot(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},Wg={place:Ug,getPercentageValueStrategy:()=>"none"},Hg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:r,align:n}};function Vn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Rn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var zg=" · ",pr=2,et=(e,t,r,n)=>{const a=Math.abs(e==="radial"?Math.sin(t):Math.cos(t)),i=Math.abs(e==="radial"?Math.cos(t):Math.sin(t));return a*(r/2)+i*(n/2)},Kg=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=et("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-pr&&t+i<=e.outerRadiusPx+pr)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=et("tangential",r,n,a)/t,c=pr/t;return Math.abs(r-e.midAngle)+o<=s+c},Yg=({x:e,y:t,labelWidth:r,labelHeight:n,panelRect:a})=>e-r/2>=0&&e+r/2<=a.width&&t-n/2>=0&&t+n/2<=a.height,qg=({wedge:e,position:t,offset:r,labelWidth:n,labelHeight:a})=>t==="inside"?{labelRadius:(e.innerRadiusPx+e.outerRadiusPx)/2,labelAngle:e.midAngle,position:"inside"}:{labelRadius:e.outerRadiusPx+r+et("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},jg=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:s})=>{const o=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+et("radial",o,i,s);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const m=e.innerRadiusPx-c;u=m>=0?m:e.innerRadiusPx+c}let d=o;if(n!=="center"&&u>0){const m=et("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:Kg({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},Xg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const m of e.layer.data){const{startAngle:h,endAngle:p}=Vn(m),{innerRadius:f,outerRadius:g}=Rn(m);if(h===null||p===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${zg}${y}`,I={startAngle:h,endAngle:p,midAngle:(h+p)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const H=e.measureDataLabel("observation",o,x);V={width:H.width,height:H.height},A=qg({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const H=Ln(e.measureDataLabel,"observation",x),T=H[r];A=jg({wedge:I,placement:r,justify:Tn(n),align:a,offset:i,labelWidth:T.width,labelHeight:T.height}),V=H[A.position]}const j=c+Math.sin(A.labelAngle)*A.labelRadius,ne=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!Yg({x:j,y:ne,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:j,y:ne,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},Zg={place:Xg,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Jg=e=>{const t=C({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=C({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const s=l.getStableKey(i[n]),o=r[s];return o!==void 0?o(a,i):t(a)}},C=e=>{switch(e.valueFormat.type){case"currency":return Xs(e);case"date":return Kf(e);case"datetime":return Yf(e);case"day_month":return eo(e);case"decimal":return Zs(e);case"duration":return fn(e);case"integer":return Js(e);case"month":return to(e);case"month_year":return vn(e);case"percentage":return Qs(e);case"quarter":return bn(e);case"text":return hn(e);case"weekly_date_range":return ro(e);case"weekly_date_range_with_year":return no(e);case"year":return Sn(e);case"time":return ao(e);case"lookup":return Jg({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Cn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:Ri(e),locale:r,numberFormat:t})}var Qg=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:nt(e,t),variable:r}:{read:U,variable:l.GROUP_VARIABLES.group}},mo=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Cn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:ay({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:ey({layer:e,numberFormat:n,locale:s})}},ey=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Qg(e.data,e.mapping),i=C({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return s=>{const o=n(s);return o===null?null:i(o,s)}},ty=(e,t)=>{switch(t){case"stack":return ry(e);case"fill":return ny(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},ry=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const s=a[t];if(s==null)return null;const o=r?.get(sn(a,t));return o===void 0?null:o.total}},ny=e=>{const t=Ke(e);return r=>{const n=F(r),a=M(r);if(!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a))return null;const i=Math.abs(a-n);if(i===0)return null;const s=t(r);return l.isStrictNumericDataValue(s)?s/i:null}},ay=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=W(e.data,e.dataLabels.labelSource),o=ty(e,i),c=iy({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&po(e);return m=>{const h=s(m);if(h===null)return"";if(!d||!l.isStrictNumericDataValue(h))return c(h,m);const p=o(m);return p===null||p===0?c(h,m):u(h/p)}},iy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(po(e))return a;const o=sy(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:oy(e.data,i),locale:n,numberFormat:t})},po=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Wt(e.position,e.mapping))},sy=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const s=t.find(o=>o.scaleAestheticKey==="x");return s===void 0?null:C({valueFormat:s.valueFormat,locale:n,numberFormat:r})},oy=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},kn={bar:{cartesian:Ag,polar:Zg},line:{cartesian:_g},point:{cartesian:Wg},area:{cartesian:bg}},ly=(e,t)=>kn[e]?.[t]!==void 0,cy=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=kn[f]?.[h];if(g===void 0)continue;const y=mo({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)uy(x,h,c,u)||d.push(x)}return{labels:d}},uy=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*dy({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=kn[o.geom]?.cartesian;if(c===void 0)continue;const u=mo({layer:o,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:c.getPercentageValueStrategy(o)});for(const d of c.place(u))yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var hr={abbreviation:"none",decimals:"auto"},ho=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return C({valueFormat:a,locale:e,numberFormat:hr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const s=i/r;return s===Number.POSITIVE_INFINITY?"∞":s===Number.NEGATIVE_INFINITY?"-∞":C({valueFormat:{type:"percentage"},locale:e,numberFormat:hr,intlOptions:{signDisplay:"always"}})(s)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${C({valueFormat:{type:"decimal"},locale:e,numberFormat:hr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},fr=6,gr=6,yr=15,vr=5,br=15,fo=(e,t)=>{switch(e){case"small":return{arrowStartGap:fr,arrowEndGap:gr,offsetFromHigherObservation:yr,arrowheadSize:vr,curveRadius:br,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:fr*1.5,arrowEndGap:gr*1.5,offsetFromHigherObservation:yr*1.25,arrowheadSize:vr*1.5,curveRadius:br*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:fr*2,arrowEndGap:gr*2,offsetFromHigherObservation:yr*1.75,arrowheadSize:vr*2.5,curveRadius:br*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},my=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},py=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x,y:e.y-n},o={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Tu=Object.create,Ii=Object.defineProperty,Lu=Object.getOwnPropertyDescriptor,wu=Object.getOwnPropertyNames,Eu=Object.getPrototypeOf,Vu=Object.prototype.hasOwnProperty,Ru=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=wu(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Vu.call(e,o)&&o!==r&&Ii(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Lu(t,o))||n.enumerable});return e},Gt=(e,t,r)=>(r=e!=null?Tu(Eu(e)):{},Ru(t||!e||!e.__esModule?Ii(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-CtbBX7qP.cjs");let Ti=require("date-fns"),ze=require("lodash-es"),je=require("d3-time"),Cu=require("date-fns/differenceInDays"),ue=require("d3-regression"),Q=require("d3-scale"),De=require("d3-interpolate"),D=require("d3-scale-chromatic"),Pe=require("lodash-es/clamp");Pe=Gt(Pe,1);let kt=require("lodash-es/merge");kt=Gt(kt,1);let Er=require("humanize-duration");Er=Gt(Er,1);let ve=require("d3-shape"),da=require("color2k"),ku=require("d3-delaunay"),Dt=require("lodash-es/isEqual");Dt=Gt(Dt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787149483080");var Du=1e6;function z(e){return String(Math.round(e*Du))}var ma=0;function O(){return ma+=1,`${Math.random().toString(36).slice(2,6)}${ma.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function E(e){return e[l.POSITION_VARIABLES.y]}function K(e){return e[l.POSITION_VARIABLES.xMin]}function Y(e){return e[l.POSITION_VARIABLES.xMax]}function F(e){return e[l.POSITION_VARIABLES.yMin]}function M(e){return e[l.POSITION_VARIABLES.yMax]}function Yr(e){return e[l.POSITION_VARIABLES.yRaw]}function Ou(e,t){return e[l.resolveScaledAestheticVariable(t)]}var _u={xMin:0,xMax:1,yMin:0,yMax:1},Vr=(e,t)=>{if(t.type==="polar")return null;const r=K(e)??R(e),n=Y(e)??R(e),a=F(e)??E(e),i=M(e)??E(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},tt=(e,t)=>{const r=(e.xMin+e.xMax)/2,n=(e.yMin+e.yMax)/2;switch(t){case"top":return{x:r,y:e.yMax};case"bottom":return{x:r,y:e.yMin};case"left":return{x:e.xMin,y:n};case"right":return{x:e.xMax,y:n};case"top-left":return{x:e.xMin,y:e.yMax};case"top-right":return{x:e.xMax,y:e.yMax};case"bottom-left":return{x:e.xMin,y:e.yMin};case"bottom-right":return{x:e.xMax,y:e.yMin};default:return{x:r,y:n}}},Li=e=>tt(_u,e),xe=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},wi=(e,t)=>e.yScaleType===t.yScaleType&&Cr(e.valueFormat)===Cr(t.valueFormat),Rr=e=>`${e.yScaleType} y axis, ${Cr(e.valueFormat)}`,Cr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Mu=(e,t)=>{if(!l.isLookupValueFormat(e))return e;const r=t[e.byVariable];return r===void 0?e.fallback:e.cases[l.getStableKey(r)]??e.fallback};function Ne(e,t){return e==="x"?t.x:t.y}function Ut(e,t){return e==="x"?t.y:t.x}function Pu(e,t){return{main:Ne(e,t),cross:Ut(e,t)}}function pa(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function Nu(e){return e.type==="cartesian"}var U=e=>e[l.GROUP_VARIABLES.group],rt=(e,t)=>{const r=xe(e),n=t[r]??null;if(n===null)return null;const a=r===l.GROUP_VARIABLES.group?null:U(t);return{layerId:e.id,anchorValue:n,...a!==null&&{groupValue:a}}},Be=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,Bu={type:"decimal"};function Ei(e){return e.length>0&&e.every(t=>t.data.size()===0)}function Vi(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):Bu}function Ri(e){return Vi(e,l.extractVariableName(e.mapping.y))}var Fu=["stack","dodge","identity","fill"],qr=["solid","dashed","dotted"],Ci=e=>qr.includes(e);function P(e){return e==="stack"||e==="fill"}var W=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},nt=(e,t)=>W(e,t.x),ki=(e,t)=>W(e,t.y),$u=(e,t)=>W(e,t.label),Di=(e,t)=>W(e,t.color),Gu=(e,t)=>W(e,t.size),Uu=(e,t)=>W(e,t.alpha),Wu=(e,t)=>W(e,t.group),Hu=(e,t)=>W(e,t.strokeWidth),ha={variable:l.POSITION_VARIABLES.yRaw};function Wt(e,t){return P(e)?ha:t.y??ha}function Ke(e){return W(e.data,Wt(e.position,e.mapping))}function Ht(e){return e[l.VISUAL_VARIABLES.color]}function Oi(e){return e[l.VISUAL_VARIABLES.alpha]}function jr(e){return e[l.VISUAL_VARIABLES.size]}function kr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function _i(e){return e[l.VISUAL_VARIABLES.lineType]}var Dr=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Mi=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(xe(e)));return n=>({...n,anchorValue:Dr(n.anchorValue,r,t),...n.groupValue!==void 0&&{groupValue:Dr(n.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)}})},Pi=e=>{const t=l.extractVariableName(e.mapping.y),r=Ke(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},zu=["lt","lte","gt","gte","range"],Ku={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"}},te=()=>!1,we=()=>!0;function zt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Pi(e),parsingLocale:t}}function he(e,t){if("and"in e){const r=e.and.map(n=>he(n,t)).filter(n=>n!==we);return r.includes(te)?te:r.length===0?we:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>he(n,t)).filter(n=>n!==te);return r.includes(we)?we:r.length===0?te:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=he(e.not,t);return r===te?we:r===we?te:n=>!r(n)}return qu(e,t)}function fe(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>fe(n,t,r)):"or"in e?e.or.flatMap(n=>fe(n,t,r)):"not"in e?fe(e.not,t,r):Yu(e,t,r)}function Yu(e,t,r){const{subject:n,effect:a}=Ku[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=ju(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 qu(e,t){if(!t.hasVariable(e.variable))return te;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Dr(a,r,t.parsingLocale);if("eq"in e){const a=n(e.eq);return i=>l.areDataValuesEqual(t.readValue(i,e.variable),a)}if("oneOf"in e){const a=e.oneOf.map(n);return i=>{const s=t.readValue(i,e.variable);for(const o of a)if(l.areDataValuesEqual(s,o))return!0;return!1}}if("lt"in e){const a=n(e.lt);return i=>Ee(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=Ee(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Ee(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=Ee(t.readValue(i,e.variable),a);return s==="greater"||s==="equal"}}if("range"in e){const[a,i]=e.range,s=n(a),o=n(i);return c=>{const u=t.readValue(c,e.variable),d=Ee(u,s),m=Ee(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return te}function ju(e){for(const t of zu)if(t in e)return t;return null}function Ee(e,t){if(e===null||t===null)return"incomparable";if(l.isStrictTemporalDataValue(e)&&l.isStrictTemporalDataValue(t)){const r=e.getTime(),n=t.getTime();return r<n?"less":r>n?"greater":"equal"}return l.isStrictNumericDataValue(e)&&l.isStrictNumericDataValue(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}var Xu=(e,t,r,n,a,i)=>{const s=Bi(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Ni(r.padding),c=o===null?Qu(s,r.padding):s,u={x:c.xMin,y:c.yMin,width:Math.max(0,c.xMax-c.xMin),height:Math.max(0,c.yMax-c.yMin)};return o===null?u:{...u,defer:o}},Zu=(e,t,r,n,a,i)=>{const s=Bi(e,t,r.predicate,n,a,i);return s===null?null:tt(s,r.align)},Ni=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Bi=(e,t,r,n,a,i)=>{if(t.has(r))return t.get(r)??null;let s=null,o=!1;const c=new Map;for(const u of n){const d=fe(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=he(r,zt(u,i));if(h!==te)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Ju(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Ju=(e,t)=>({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)}),Qu=(e,t)=>{if(t===void 0)return e;const{x:r=0,y:n=0}=typeof t=="number"?{x:t,y:t}:t;return{xMin:e.xMin-r,xMax:e.xMax+r,yMin:e.yMin-n,yMax:e.yMax+n}},Ot=(e,t,r)=>{const n=td(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:rd(n,t.offset,e.coordSystem)},Fi=(e,t)=>t.anchorType==="selection"?Xu(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale):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},Xr=(e,t,r)=>Or(e,t,r)?.point??null,Or=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const{resolveAnchorPosition:o}=e.geomRegistry.get(s.geom);if(o===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const c=Ke(s),u=xe(s),{anchorValue:d,groupValue:m}=Mi(s,n)(a);let h=-1;for(const p of s.data){if(h+=1,!l.areDataValuesEqual(p[u]??null,d)||m!==void 0&&!l.areDataValuesEqual(U(p),m))continue;const f=o(p,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(f===null)continue;const g=$i(s,p,c);if(g===null)continue;const y=rt(s,p);if(y!==null)return{point:{...f,...g,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id,observationIndex:h}}}return null},ed=(e,t)=>{const{layers:r,coordSystem:n,scales:a,parsingLocale:i}=e;if(n.type!=="cartesian")return null;const s=a.x,o=a.y;if(s===void 0||o===void 0||s.kind!=="position"||o.kind!=="position")return null;const c=ga(t.x,"x",r,i),u=ga(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!Be(d,m))return null;const h=fa(d,s,nd(e)),p=fa(m,o),f=pa(n.mainAxis,{main:h.min,cross:p.min}),g=pa(n.mainAxis,{main:h.max,cross:p.max});return tt({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},$i=(e,t,r)=>{const n=r(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:Mu(Ri(e),t),yScaleType:e.yScaleType,color:Ht(t)}:null},td=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return ed(e,t);case"selection":return Zu(e.container,e.selectionBoxCache,t,e.layers,e.coordSystem,e.parsingLocale);case"annotation":return{x:0,y:0,defer:{type:"annotation-ref",ref:t.ref,align:t.align??"center",offset:t.offset}};case"observation":return Xr(e,ad(t),r)}},rd=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ni(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},fa=(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}},nd=({container:e,layers:t})=>{let r=0;for(const n of t){const a=e.geomRegistry.get(n.geom).resolveBandFraction?.(n.params);a!==void 0&&(r=Math.max(r,a))}return r>0?r:1},ad=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align}),ga=(e,t,r,n)=>{for(const a of r){const i=l.extractVariableName(a.mapping[t]);if(!(i===null||i===l.CONSTANT_VARIABLES.x))return l.parseValue(e,l.toExplicitValueFormat(a.data.getValueFormat(i)),n)}return e},id=class extends l.Stage{constructor(e){super(),this.container=e}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={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:gd(s,t.differenceArrows),shapes:cd(s,t.shapes),arrows:dd(s,t.arrows),textAnnotations:md(s,t.textAnnotations),images:ud(s,t.images),stickers:pd(s,t.stickers),pinnedNumbers:hd(s,t.pinnedNumbers),comments:fd(s,t.comments)};return sd(this.container,o),od(this.container,o),o}},Gi=(e,t,r)=>e!==null?e:!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||t.color===void 0||t.color!==r.color?null:t.color,ee=(e,t,r,n)=>{e.diagnostics.addWarning({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."})},sd=(e,t)=>{const r=new Set;for(const n of Object.values(t))for(const{id:a}of n){if(r.has(a)){e.diagnostics.addWarning({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)}},od=(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 ld(t))r.has(a)||e.diagnostics.addWarning({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."})},ld=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},cd=(e,t)=>{const r=[];for(const n of t){const a=Fi(e,n.region);if(a===null){ee(e.container,"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,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},ud=(e,t)=>{const r=[];for(const n of t){const a=Fi(e,n.region);if(a===null){ee(e.container,"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,opacity:n.opacity})}return r},dd=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.start,"pin"),i=Ot(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${Ui(a,i)} resolving to nothing`);continue}r.push({id:n.id,start:a,end:i,color:n.color,thickness:n.thickness,startArrowheadStyle:n.startArrowheadStyle,endArrowheadStyle:n.endArrowheadStyle,lineStyle:n.lineStyle,hasStickerStyle:n.hasStickerStyle})}return r},md=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.at,"pin");if(a===null){ee(e.container,"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,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},pd=(e,t)=>{const r=[];for(const n of t){const a=Ot(e,n.at,"pin");if(a===null){ee(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},hd=(e,t)=>{const r=[];for(const n of t){const a=Xr(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},fd=(e,t)=>{const r=[];for(const n of t){const a=Xr(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},gd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Or(e,n.start,"value"),i=Or(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${Ui(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.observationIndex===i.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}yd(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,color:Gi(n.color,a.point,i.point),ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ui=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",yd=(e,t,r,n)=>{wi(r,n)||e.container.diagnostics.addWarning({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:Rr(r),actual:Rr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Wi(e){return e instanceof l.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 w(e,t){return zi(e,t)}function L(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 Hi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function at(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 zi(e,t){let r=!1;const n={...e};for(const[a,i]of Object.entries(t)){const s=e[a];if(l.isPlainObject(i)&&l.isPlainObject(s)){const o=zi(s,i);o!==s&&(n[a]=o,r=!0)}else i!==void 0&&i!==s&&(n[a]=i,r=!0)}return r?n:e}function Kt(e){return{pipe:t=>{const r=t(e);return Kt({...e,...r})},result:()=>e}}function vd(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,o]of r)o.push(s===t?a.kind:i[s]??null);const n={};for(const[a,i]of r)n[a]={type:Ki(i),values:i};return new l.Dataset(n)}function Ki(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 bd=class extends l.Stage{dependencies(e){return[e.data,e.mapping]}run(e){let t=e.data,r=e.mapping;r.x===""&&(t=t.addConstantVariable(l.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:l.CONSTANT_VARIABLES.x});for(const n of Object.keys(r)){const a=l.extractConstantValue(r[n]);if(a===void 0)continue;const i=l.prefixInternalVariable(`const_${n}`);t=t.addConstantVariable(i,Ki(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Sd=(e,t)=>{let r=t;for(const n of Object.keys(t)){const a=t[n];if(typeof a!="string")continue;const i=e.getConstant(a);i!==void 0&&(r={...r,[n]:a===l.CONSTANT_VARIABLES.x?"":{value:i.value}})}return r},Ae=class{constructor(){this.perLayerMemo=l.createPerKeyMemo(),this.listMemo=l.createSingleSlotMemo()}get stats(){return l.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)}},xd=class extends l.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)}},Ad=class extends Ae{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 l.InternalError({message:`CoordCompiler: strategy '${t.coordSpec.coordType}' did not return a transformed layer`});return r}},Id=class{constructor(e){this.setupStage=new xd(e),this.transformStage=new Ad(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)}},Td=class{constructor(){this.coordType="cartesian"}setup(e){if(e.coordSpec.coordType!=="cartesian")throw new l.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}},Ld=class{constructor(){this.coordType="flip"}setup(e){if(e.coordSpec.coordType!=="flip")throw new l.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:Ed(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Rd(t))}},wd=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],ya=l.prefixInternalVariable("flipSwap"),Ed=(e,t)=>Vd(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Vd=e=>{for(const t of e){const r=l.extractVariableName(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},Rd=e=>{let t=e.data;for(const[r,n]of wd){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,ya).renameVariable(n,r).renameVariable(ya,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},ge=Math.PI*2,Cd=8,kd=1e-9,Yi=(e,t)=>Math.abs(t-e)>=ge-kd,Fe=e=>(e%ge+ge)%ge,qi=(e,t,r)=>{if(Yi(t,r))return!0;const n=Fe(r-t);return Fe(e-t)<=n},_t=(e,t)=>{const r=Math.abs(Fe(e)-Fe(t));return Math.min(r,ge-r)},ji=(e,t,r)=>e*ge+t+r,Mt=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Xi=(e,t)=>({angle:Fe(Math.atan2(e,t)),radius:Math.hypot(e,t)}),Zr=(e,t)=>{const r=e.x-.5,n=e.y-.5;return{x:t>=1?r*2*t:r*2,y:t>=1?n*2:n*2/t}},Yt=(e,t)=>{const{x:r,y:n}=Zr(e,t);return Xi(r,n)};function Zi(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 Ji=(e,t)=>Zi(t.domain!==null&&t.domain.length>0?t.domain:e),Dd=class{constructor(){this.coordType="polar"}setup(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});const{params:t}=e.coordSpec,r=t.startAngle*(Math.PI/180),n=Md(t,e.scales,e.layers),a=Nd(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:e.scales}}transform(e){if(e.coordSpec.coordType!=="polar")throw new l.InternalError({message:`Invalid coordinate type: ${e.coordSpec.coordType}`});if(e.coordSystem.type!=="polar")throw new l.InternalError({message:"PolarCoord.transform received a non-polar coord system"});const{params:t}=e.coordSpec,{startAngle:r,spokeRotation:n}=e.coordSystem,a=_d(r,n),i=Bd(t);return e.layers.map(s=>Fd(t.theta==="y"?$d(s):s,a,i))}},Od=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]];function _d(e,t){return r=>ji(r,e,t)}function Md(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=Pd(n,e,r);return a===0?0:-Math.PI/a}function Pd(e,t,r){const n=[];for(const a of r){const i=l.extractVariableName(a.mapping[t.theta]);if(!(i===null||!a.data.hasVariable(i)))for(const s of a.data.getValues(i))n.push(s)}return Ji(n,e).length}function Nd(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 Bd(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function Fd(e,t,r){let n=e.data;return n=Ve(n,l.POSITION_VARIABLES.x,t),n=Ve(n,l.POSITION_VARIABLES.xMin,t),n=Ve(n,l.POSITION_VARIABLES.xMax,t),n=Ve(n,l.POSITION_VARIABLES.y,r),n=Ve(n,l.POSITION_VARIABLES.yMin,r),n=Ve(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Ve(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 $d(e){let t=e.data;for(const[r,n]of Od){const a=t.hasVariable(r),i=t.hasVariable(n);if(!a&&!i)continue;const s=a?t.getValues(r):null,o=i?t.getValues(n):null;s&&(t=t.addVariable(n,"numeric",s)),o&&(t=t.addVariable(r,"numeric",o))}return{...e,data:t}}var Gd=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Td),this.register("flip",new Ld),this.register("polar",new Dd)}},Qi=new Set(["min","max","scalar"]),Ud={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function Wd(e){const t=new Set;for(const r of e)r.role==="point"?t.add(r.axis):(r.role==="min"||r.role==="max")&&l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function Hd(e){const t=new Set;for(const r of e)r.role==="point"&&t.add(r.axis),l.isDefined(r.aes)&&t.add(r.aes);return[...t]}function zd(e,t,r){let n=e;for(const a of t){if(a.role!=="min"&&a.role!=="max"||!l.isDefined(a.aes))continue;const i=Ud[a.axis][a.role];if(n.hasVariable(i))continue;const s=l.extractVariableName(r[a.aes]);!l.isDefined(s)||!n.hasVariable(s)||(n=n.addVariable(i,"numeric",n.getValues(s,{type:"numeric"})))}return n}var Kd=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:zd(n.data,r.positionRoles,a)}}},Jr=["x","y"],Qr=new Set(["x","y","ySecondary"]),it=new Set(["color","size","alpha","strokeWidth","lineType"]),Ye=e=>Qr.has(e),en=e=>it.has(e),es=e=>Ye(e)||en(e);function ae(e){return e==="secondary"?"ySecondary":"y"}function ts(e,t){return e==="y"?ae(t):"x"}function N(e){return e==="ySecondary"?"y":e}var qe=(e,t)=>{if(l.isDefined(t.group)){const a=l.extractVariableName(t.group);if(a!==null)return[a]}const r=new Set([l.extractVariableName(t.x),l.extractVariableName(t.y)].filter(l.isDefined)),n=new Set;for(const a of it){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},qt=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:qe(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),Yd=class{compute({data:e,mapping:t}){const r=qe(e,t);if(r.length===0)return{data:e.addConstantVariable(l.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]=l.getStableKey(a.map(o=>o[s]));return{data:e.addVariable(l.GROUP_VARIABLES.group,"categorical",i)}}},qd=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},jd=(e,t,r)=>{const n=be(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function be(e,t){const r=N(t);for(const n of rs(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var tn=(e,t)=>e===null?null:t[e]??e,Xd=(e,t)=>e===null?null:t[String(e)]??null,Se=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return lr(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 Jd(i,t)?i:lr(t)}return lr(t)},Zd=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:rs(t,e).some(r=>r.position==="fill");function rs(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var lr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Jd=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Qd=[{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}],va={year:0,quarter:1,month:2,week:3,day:4,hour:5},Re=40,em=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return am(r.unit).range(e,new Date(t.valueOf()+1),n)},tm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Cu.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Re;case"day":return a/t>Re;case"week":return a/(7*t)>Re;case"month":return a/(30*t)>Re;case"quarter":return a/(90*t)>Re;case"year":return a/(365*t)>Re}},rm=(e,t)=>{const r=!l.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"}}},nm=(e,t)=>{const r=im(t);return r===null?!1:va[e]>va[r]},am=e=>{switch(e){case"hour":return je.utcHour;case"day":return je.utcDay;case"week":return je.utcMonday;case"month":case"quarter":return je.utcMonth;case"year":return je.utcYear}},im=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}},ns={left:"right",right:"left",top:"bottom",bottom:"top"},sm={x:!0,y:!0,ySecondary:!1},om=20,ba=new Set(["top","bottom"]),lm={type:"percentage"};function cm(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(Ei(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=mm(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=hm(as(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of Qr){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=um({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function um(e){const{scaleAestheticKey:t,scale:r,config:n,layers:a,axisMapping:i,resolvedYPosition:s,gridOverrides:o,variableLabels:c}=e,{axisConfig:u,position:d,geometry:m}=pm(t,n,i,s),h=be(a,t),p=Zd(a,t)?lm:Se({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:dm(u,h,c),isVisible:u.isVisible,tickCandidates:gm(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:fm(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function dm(e,t,r){return e.label?e.label:t?r[t]??null:null}function mm(e,t,r,n){const a=t.flatMap(o=>{const c=e.get(o.geom).grid[r];return c?[c]:[]}),i=a.some(o=>o.hideGridX),s=a.some(o=>o.hideGridY);return{x:{gridVisible:Sa(i,n.axes.x.grid.isVisible)},y:{gridVisible:Sa(s,n.axes.y.grid.isVisible)}}}function Sa(e,t){if(e&&t===null)return!1}function pm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:as(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=ns[n],i=(0,ze.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 as(e,t){return ba.has(e)===ba.has(t)?e:t}function hm(e,t){return t.has(e)?ns[e]:e}function fm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??sm[r]}var gm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=vm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=om;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>$e(e,u))}))}return i}return e.spec.scaleType==="datetime"?ym(e,t):[{ticks:e.generateTicks().map(a=>$e(e,a))}]},ym=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>$e(e,o))}];const a=new Set,i=[],s=(o,c)=>{if(o.length===0)return;const u=l.getStableKey(o);a.has(u)||(a.add(u),i.push({ticks:o.map(d=>$e(e,d)),valueFormat:c}))};for(const o of Qd)tm({...o,start:r,stop:n})||nm(o.unit,t)||s(e.generateTicks({interval:o}),rm(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},vm=e=>{const{domain:t}=e,r=t[0],n=t.at(-1);return!l.isDefined(r)||!l.isDefined(n)||l.getStableKey([r])===l.getStableKey([n])?null:{ticks:[$e(e,r),$e(e,n)]}},$e=(e,t)=>({value:t,position:e.map(t)});function is({scale:e,aesthetics:t,layers:r}){const n=bm({layers:r,aesthetics:t}),a=ss({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function bm({layers:e,aesthetics:t}){const r=ss({layers:e,aesthetics:t}),n=e.find(i=>t.some(s=>l.isDefined(i.mapping[s]))),a=n?n.geom:"bar";return i=>{const s=r(i);return s?s.layer.geom:a}}function ss({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(c=>l.isDefined(i.mapping[c]));if(s===void 0)continue;const o=l.extractVariableName(i.mapping[s]);if(!(o===null||!i.data.hasVariable(o)))for(const c of i.data.getValues(o,{distinct:!0})){const u=l.getStableKey(c);n.has(u)||n.set(u,{layer:i,layerIndex:a})}}return a=>n.get(l.getStableKey(a))}var rn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Sm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!rn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=be(t,"color");if(os({colorVariableName:a,xVariableName:be(t,"x"),mapsColorAcrossMultipleLayers:Am(t)>1,isMergedWithAnotherAesthetic:xm(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return is({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Se({layers:m?[m]:t,scaleType:i,variableName:h}),label:Xd(o,r)}})}var os=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function xm(e,t,r){if(r===null)return!1;for(const n of it){if(n==="color")continue;const a=e[n];if(!(a===void 0||!rn(a))&&be(t,n)===r)return!0}return!1}var Am=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function ls(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Im(e,t,r,n){const a=r.findIndex(i=>ls(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:tn(l.extractVariableName(r[a]?.mapping.y),n)}]:t.map(i=>({value:i.value,swatch:{color:i.color,geom:i.geom},layerIndex:i.layerIndex,groupLabelFormat:i.valueFormat,label:i.label}))}function xa(e,t,r){if(r===null||t===null)return[...e];const n=l.getStableKey(r);return e.filter((a,i)=>l.getStableKey(t[i]??null)===n)}var cs=e=>e==="none"?"first":e,Tm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=Aa(e);return n===0?null:r}case"average":{const{sum:r,count:n}=Aa(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Lm=(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}},Aa=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function wm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Em(e,n):Vm(e,n)}function Em(e,t){if(t!=="total")return null;const{scales:r,layers:n}=e,a=n.find(o=>o.summary.grandTotal!==void 0);if(a===void 0)return null;const i=a.summary.grandTotal;if(i===void 0)return null;const s=l.extractVariableName(a.mapping.y);return s===null?null:{kind:"grandTotal",value:i,valueFormat:Se({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Vm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>ls(o,d)))return null;const c=Im(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>Rm({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 Rm({group:e,show:t,compareWith:r,layers:n,scales:a}){const i=n[e.layerIndex];if(i===void 0)return null;const s=l.extractVariableName(i.mapping.y);if(s===null||t==="total"&&i.position==="fill")return null;const o=l.extractVariableName(i.mapping.x),c=l.extractVariableName(i.mapping.color),u=i.yScaleType==="secondary"?a.ySecondary:a.y,d=Se({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=Dm(i.data,o),h=Se({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=Om(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=xa(f,y,e.value),x=xa(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:Tm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:Cm(t,m,x),comparison:km(t,r,m,x,v)}}function Cm(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 km(e,t,r,n,a){return e!=="current"||!r?null:Lm(n.map((i,s)=>({main:i,cross:a[s]??null})),cs(t))}function Dm(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Om(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function q(e,...t){return e?t.includes(e.geom):!1}function k(e,t){return e.find(r=>r.id===t)}function ie(e,...t){return e.find(r=>t.includes(r.geom))}function _m(e,...t){return e.filter(r=>t.includes(r.geom))}function nn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function an(e){const t=e.filter(r=>!nn(r,e));return t.length>0?t:e}function us({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=an(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var Mm=3;function Pm({scales:e,config:t,layers:r,coordSystem:n,variableLabels:a,colorGroups:i,geomRegistry:s}){if(t.legend.position==="none")return{drawn:[],position:"none"};const o=new Map(i.map(y=>[l.getStableKey(y.value),y])),c=Hm($m({scales:e,layers:r})),u=be(r,"x"),d=c.map(y=>{if(Um(y,u,r))return null;const v=Km({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=Nm(d),h=an(r),p=Jm(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&Zm(s,m,h,n))return{drawn:[],position:p};const f=Qm(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?np(h[0]):null;return{drawn:d.map(({built:y})=>Bm(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function Nm(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function Bm(e,t,r){const{position:n,display:a}=t,i=Fm(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 Fm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function $m(e){const{scales:t,layers:r}=e,n=[];for(const a of it){const i=t[a];if(i===void 0||i.kind==="identity"||!Gm(a,r))continue;const s=be(r,a),o=rp(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function Gm(e,t){const r=N(e);return t.some(n=>l.isDefined(n.mapping[r]))}function Um(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:os({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:Wm(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function Wm(e,t){const r=N(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function Hm(e){const t=new Map;for(const r of e){const n=tp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function zm(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function Km({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>N(c.scaleAestheticKey)),s=is({scale:a.scale,aesthetics:i,layers:r}),o=Se({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:tn(a.variableName,t),items:s.map(c=>Ym(c,e,i,o,n))}}function Ym(e,t,r,n,a){const i={};for(const o of t)zm(i,o.scaleAestheticKey,o.scale.map(e.value));const s=jm(e,t,r,n,a);return{value:e.value,label:qm(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function qm(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function jm(e,t,r,n,a){if(t[0].scaleAestheticKey==="color")return a.get(l.getStableKey(e.value))?.valueFormat??n;const i=e.owner?.layer,s=Xm(i,r);return i===void 0||s===null?n:Se({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function Xm(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=l.extractVariableName(n);if(a!==null)return a}return null}function Zm(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 Jm(e,t,r,n,a){if(t!=="auto")return t;if(a.type==="polar")return"top";let i=!1,s=!1,o=!1;for(const u of n){const{sidePlacement:d}=e.get(u.geom).legend;d==="whenCrowded"&&(i=!0),d==="whenStackedVertical"&&(s=!0,P(u.position)&&(o=!0))}const c=r>=Mm;return i&&s?"top":i?c?"right":"top":o?ep(a)?"top":c?"right":"top":"top"}function Qm(e,t){return e==="pill"?"pill":us(t)?"direct":"pill"}function ep(e){return e.type==="cartesian"&&e.mainAxis==="y"}function tp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function rp(e,t){return rn(t)?"discrete":`continuous:${e}`}function np(e){if(!e)return new Map;const t=new Map;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(r=>{const n=r.findLast(c=>l.isDefined(M(c))||l.isDefined(E(c)));if(!n)return;const a=U(n);if(!l.isDefined(a))return;const i=F(n),s=M(n)??E(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var ap=class extends l.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=qd(e.originalData),r=Sm({scales:e.scales,layers:e.layers,valueLabels:jd(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=wm(n),i=Pm(n),s={...i,drawn:ip(a,i.drawn)};return{axes:cm(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},ip=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],sp=e=>l.getStableKey([U(e)]),sn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),op=e=>e!=="data-point",Pt=(e,t,r)=>{switch(e){case"series":return sp(t);case"x-value":return sn(t,r)}},lp={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor"};function ds(e){const t=lp[e]??null;return t===null?null:{strategy:t,composition:ms()}}function ms(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var cp=class extends Ae{constructor(e){super(),this.container=e}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:i})=>i===void 0||i===e.id);if(n.length===0)return e;const a=up({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function up({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const X=fe(T.predicate,e.data);for(const Z of X)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return X.length===0}),s=l.extractVariableName(e.mapping.x),o=zt(e,r),c=i.map(T=>({predicate:he(T.predicate,o),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let I=!1,A=0;for(const T of e.data){let X,Z;p!==null&&(X=Pt("series",T,s),p[A]=X),f!==null&&(Z=Pt("x-value",T,s),f[A]=Z),g!==null&&(g[A]=T);for(const{predicate:ft,scope:gt}of c)if(ft(T))switch(gt){case"series":X!==void 0&&v.add(X);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return ms();const V=new Uint8Array(h),j=[];let ne=0;for(let T=0;T<h;T++){const X=p?.[T],Z=f?.[T],ft=X!==void 0&&v.has(X),gt=Z!==void 0&&x.has(Z),ca=y[T]===1;if(n==="observation-rerender")(ft||ca||gt)&&(V[T]=1,ne++);else if(ft)V[T]=1,ne++;else if(ca||gt){const ua=g?.[T];ua!==void 0&&j.push({observation:ua,observationIndex:T})}}const H=ne>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&H!==null,matchedLayer:H,overlayCandidates:j}}var dp=l.prefixInternalVariable("__ungrouped__");function mp(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,o=i.map((c,u)=>{if(c===null)return null;const d=r[u]??dp;let m=s.get(d);return m||(m=new l.ChronologicalDateManager,s.set(d,m)),m.incrementYearIfNeeded(c)});n=n.addVariable(a,"temporal",o)}return n}var pp=()=>({defaults:[],overrides:[],warnings:[]}),hp=class extends Ae{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,Ia(e)]}compileLayer(e,t){const r=this.transformCompiler.compile({data:t.data,transforms:e.transforms}),n={...t.mapping,...e.mapping};return this.runLayerPipeline(e,r,n,Ia(t))}runLayerPipeline(e,t,r,n){const a=Kt({data:t,mapping:r}).pipe(({data:s,mapping:o})=>{const c=this.statCompiler.compute(e.stat,{data:s,mapping:o,xScaleIsDiscrete:n});return{data:c.data,mapping:{...o,...c.mapping}}}).pipe(({data:s,mapping:o})=>({data:this.groupCompiler.compute({data:s,mapping:o}).data,mapping:o})).pipe(({data:s,mapping:o})=>({data:mp(s),mapping:o})).pipe(({data:s,mapping:o})=>{const c=this.geomCompiler.compile(e.geom,{data:s,mapping:o,params:e.params});return{data:c.data,mapping:{...o,...c.mapping}}}).pipe(({data:s,mapping:o})=>{const c=this.positionAdjusterCompiler.adjust(e.position,{data:s,mapping:o});return{data:c.data,mapping:{...o,...c.mapping}}}).result(),i=this.container.geomRegistry.get(e.geom);return{...a,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:i.spatialKind,identityKey:i.identityKey,tooltip:i.tooltip,supportsDirectLabels:i.legend.directLabelSupport?.[e.position]===!0,highlight:ds(e.geom),styles:pp()}}};function Ia(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function ps(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}var fp=new Set(["label","group"]),gp=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,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),ps(this.container.diagnostics,t)}checkPostCompile(e){Ei(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)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!qt(r,t))return[];const c=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 '${c}'.`,context:{layerIndex:n,expected:c,actual:s},suggestion:`Use justify '${c}' for this layer.`}]}validateRequiredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const i=[],{positionRoles:s,aesthetics:o}=this.container.geomRegistry.get(r),c=[...Wd(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!Qi.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(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(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}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}}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...Hd(i),...s.map(h=>h.name)]),u=fp,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},se=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.defaultInteractive=!0,this.aesthetics=[],this.derivedVariables=[],this.highlightStrategy="overlay-anchor",this.supportedCoordTypes=["cartesian","flip"],this.spatialKind="points",this.grid={},this.legend={},this.dataLabelCoordTypes=[],this.isComposite=!1,this.tooltip=[],this.summaries={}}resolveParams(e){return(0,ze.merge)({},this.defaultParams,e.params)}},on=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},ln=(e,{coordSystem:t})=>{if(t.type==="polar")return null;const r=R(e),n=E(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},yp=class extends se{constructor(...e){super(...e),this.type="area",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"zero"},this.defaultPosition="stack",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorPosition=ln}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=on(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Ta=.7,vp=.1,hs=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},bp=class extends se{constructor(...e){super(...e),this.type="bar",this.defaultParams={width:Ta},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveAnchorBox=Vr,this.resolveDataLabelDefaults=t=>P(t)?{justify:"center"}:{},this.resolveBandFraction=t=>t.width,this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Sp(t);if(i!==void 0){const m=Vr(t,r);return m===null?null:tt(m,i)}const s=P(n),o={isSolo:!s||hs(t)==="solo",isNegative:s&&xp(t),purpose:a};if(r.mainAxis==="x"){const m=K(t),h=Y(t),p=La({lowerBound:F(t),upperBound:M(t)??E(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=F(t),u=M(t),d=La({lowerBound:K(t),upperBound:Y(t)??R(t),options:o});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const t=super.resolveParams(e),{diagnostics:r}=e;return{...t,width:this.resolveWidthParam(t.width,r)}}compile({data:e,mapping:t,params:r}){const{width:n}=r;e=on(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const a=n/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-a).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",a),{data:e,mapping:{}}}resolveWidthParam(e,t){const r=typeof e=="number"&&Number.isFinite(e)?e:null;if(r!==null&&r>0&&r<=1)return r;const n=r!==null&&r>1?1:Ta;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n}.`,context:{geom:this.type,param:"width",expected:"0 < width <= 1",actual:r??String(e)},suggestion:"Set params.width to a fraction of the category band in (0, 1]."}),n}},Sp=e=>{const t=K(e),r=Y(e),n=F(e),a=M(e);if(t===null||r===null||n===null||a===null)return null;const i=(t+r)/2,s=(n+a)/2;return{x:.5+.5*s*Math.sin(i),y:.5-.5*s*Math.cos(i)}},xp=e=>{const t=Yr(e);return l.isStrictNumericDataValue(t)&&t<0},La=e=>{const{lowerBound:t,upperBound:r,options:n}=e,a=n.isNegative?t:r;if(a===null)return null;if(n.purpose==="value"||n.isSolo)return a;const i=n.isNegative?r:t;return i===null?null:(i+a)/2},Ap=class extends se{constructor(...e){super(...e),this.type="line",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={interpolate:"linear",missingValues:"gap"},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"strokeWidth"},{kind:"visual",name:"lineType"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabels={cartesian:{offset:8},flip:{offset:8}},this.dataLabelCoordTypes=["cartesian","flip"],this.isComposite=!0,this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenCrowded",directLabelSupport:{stack:!0,dodge:!0,identity:!0,fill:!0}},this.spatialKind="buckets",this.resolveAnchorBox=Vr,this.resolveAnchorPosition=ln}compile(e){return{data:on(e.data,e.mapping),mapping:{}}}},Ip=class extends se{constructor(...e){super(...e),this.type="point",this.supportedCoordTypes=["cartesian","polar","flip"],this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"size"},{kind:"visual",name:"alpha"}],this.summaries={perGroupHeadline:!0},this.dataLabelCoordTypes=["cartesian","flip"],this.resolveAnchorPosition=ln,this.resolveDefaultLabelSource=t=>{const r=l.extractVariableName(t.size);return r!==null?{variable:r}:null}}compile({data:e}){return{data:e,mapping:{}}}},Tp=class extends se{constructor(...e){super(...e),this.type="rule",this.defaultParams={labelPosition:"start"},this.defaultInteractive=!1,this.positionRoles=[{axis:"y",role:"scalar",valueKind:"value",aes:"y"},{axis:"x",role:"scalar",valueKind:"value",aes:"x"}],this.highlightStrategy=null,this.spatialKind="noop",this.validateMapping=({mapping:t,computedVariables:r})=>{const n=r.has("x")||l.isStrictNumericDataValue(l.extractConstantValue(t.x)),a=r.has("y")||l.isStrictNumericDataValue(l.extractConstantValue(t.y));return n&&a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires exactly one of 'x' or 'y', both were provided"}]:!n&&!a?[{code:"INVALID_RULE_MAPPING",message:"rule geom requires a numeric value on 'x' or 'y'"}]:[]}}compile({data:e,mapping:t}){const r=wa(t.y,e);if(r!==null)return{data:new l.Dataset({[l.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:l.RULE_VARIABLES.y,x:void 0}};const n=wa(t.x,e);return n!==null?{data:new l.Dataset({[l.RULE_VARIABLES.x]:{type:"numeric",values:[n.value],valueFormat:n.sourceFormat}}),mapping:{x:l.RULE_VARIABLES.x,y:void 0}}:{data:new l.Dataset,mapping:{x:void 0,y:void 0}}}},wa=(e,t)=>{const r=l.extractConstantValue(e);if(l.isStrictNumericDataValue(r))return{value:r,sourceFormat:void 0};const n=l.extractVariableName(e);if(n===null||!l.isStatVariable(n)||!t.hasVariable(n))return null;const[a]=t.getValues(n);return l.isStrictNumericDataValue(a)?{value:a,sourceFormat:t.getValueFormat(n)}:null},Lp=[new bp,new Ip,new Ap,new yp,new Tp],jt=class extends l.Registry{constructor(){super("geom");for(const e of Lp)this.register(e.type,e)}},Ie=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},wp=class extends Ie{constructor(...e){super(...e),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.x);if(!l.isDefined(r))throw new l.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(l.extractVariableName(t.y)!==null)throw new l.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,...qe(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},Ep=class extends Ie{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},Vp=class extends Ie{constructor(...e){super(...e),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});return{data:e.rollup({[l.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:l.STAT_VARIABLES.mean}}}},Rp=2,fs=1440*60*1e3,Cp=class extends Ie{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 l.InternalError({message:`SmoothStat received a spec of type '${r.type}'`});const a=l.extractVariableName(t.x),i=l.extractVariableName(t.y);if(!l.isDefined(a))throw new l.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(!l.isDefined(i))throw new l.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),o=e.getType(i);if(o!=="numeric")throw new l.UserInputError({code:"INCOMPATIBLE_TYPE",message:`'smooth' stat requires a numeric 'y' (got '${o}' for variable '${i}')`,context:{aesthetic:"y",variableName:i,variableType:o}});const c=qe(e,t),u=Np(a,s,i,c,e);return c.length===0?Ea({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=Bp(d,c);Ea({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Ea=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=kp({data:e,xVariable:t,yVariable:n,xType:r});c.length<Rp||(o?Pp({observations:c,spec:a,output:i,groupObservation:s}):_p({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},kp=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Dp(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=Op({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},Dp=e=>{let t=null;for(const r of e){if(!l.isStrictTemporalDataValue(r))continue;const n=r.getTime();(t===null||n<t)&&(t=n)}return t},Op=({xValue:e,xType:t,categoryRank:r,temporalOrigin:n})=>{switch(t){case"numeric":return!l.isStrictNumericDataValue(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!l.isStrictTemporalDataValue(e))return null;const a=e.getTime();return n===null?a:(a-n)/fs+1}case"categorical":{if(!l.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 l.InternalError({message:`Unexpected xType: ${t}`})}},_p=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=gs(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?Mp(o,r):o;a.push({x:u,y:c,groupObservation:i})}},Mp=(e,t)=>t===null?new Date(e):new Date((e-1)*fs+t),Pp=({observations:e,spec:t,output:r,groupObservation:n})=>{const a=new Map;for(const o of e)a.has(o.x)||a.set(o.x,o.originalX);const i=[...a.keys()].sort((o,c)=>o-c);if(t.method==="loess"){const o=gs(t,e),c=new Map;for(const[u,d]of o)Number.isFinite(d)&&(c.has(u)||c.set(u,d));for(const u of i){const d=c.get(u),m=a.get(u);d===void 0||m===void 0||r.push({x:m,y:d,groupObservation:n})}return}const s=ys(t,e);for(const o of i){const c=a.get(o),u=s.predict(o);c===void 0||!Number.isFinite(u)||r.push({x:c,y:u,groupObservation:n})}},gs=(e,t)=>e.method==="loess"?(0,ue.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ys(e,t),ys=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,ue.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,ue.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,ue.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,ue.regressionQuad)().x(r).y(n)(t);case"power":return(0,ue.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,ue.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},Np=(e,t,r,n,a)=>{const i=[],s=[],o=Object.fromEntries(n.map(c=>[c,[]]));return{push:({x:c,y:u,groupObservation:d})=>{i.push(c),s.push(u);for(const m of n)o[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:i,valueFormat:a.getValueFormat(e)},[r]:{type:"numeric",values:s,valueFormat:a.getValueFormat(r)}};for(const u of n)c[u]={type:a.getType(u),values:o[u]??[],valueFormat:a.getValueFormat(u)};return new l.Dataset(c)}}},Bp=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},Fp=class extends Ie{constructor(...e){super(...e),this.type="sum",this.computedVariables=new Set(["y"])}computeStat({data:e,mapping:t}){const r=l.extractVariableName(t.y);if(!l.isDefined(r))throw new l.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."});const n=l.extractVariableName(t.x),a=[...new Set([...n===null?[]:[n],...qe(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},$p=[new Ep,new wp,new Cp,new Vp,new Fp],Gp=class extends l.Registry{constructor(){super("stat");for(const e of $p)this.register(e.type,e)}};function Up({geoms:e,stats:t,transforms:r}){const n=new jt,a=new Gp,i=new l.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}}function cn(e){if("definition"in e)return e.definition;if(bs(e)||Ss(e)||xs(e))return e}function vs(e){const t=[],r=[],n=[];for(const a of e){const i=cn(a);i&&(bs(i)?t.push(i):Ss(i)?r.push(i):xs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...cr("geom",t,a=>a.type),...cr("stat",r,a=>a.type),...cr("transform",n,a=>a.transformType),...Wp(t)]}}function Wp(e){const t=[];for(const r of e)r.spatialKind!=="render-hit-test"||r.identityKey!=="x-group"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the default 'x-group' identity, which has no meaning for render-owned geometry; its hover lookup will be empty.`,context:{kind:"geom",requested:r.type},suggestion:"Declare 'identityKey' as a column the geom owns (`{ variable: '<column>' }`) or 'index', so a hit-test result resolves to an observation."});return t}function cr(e,t,r){const n=new Map;for(const i of t){const s=r(i),o=n.get(s);o?o.add(i):n.set(s,new Set([i]))}const a=[];for(const[i,s]of n)s.size<2||a.push({code:"DUPLICATE_REGISTERED_TYPE",message:`Multiple plugins register the ${e} '${i}' (${s.size} definitions); the last in the array wins.`,context:{kind:e,requested:i},suggestion:`Remove the duplicate ${e} plugin(s) named '${i}', or rename them so each registers a distinct ${e}.`});return a}var bs=e=>e instanceof se,Ss=e=>e instanceof Ie,xs=e=>"transformType"in e&&typeof e.apply=="function",Hp=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Xt=class{},zp=class extends Xt{constructor(...e){super(...e),this.type="dodge"}adjust({data:e,mapping:t}){if(!l.extractVariableName(t.x))return{data:e,mapping:{}};const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(r.length===0)return{data:e,mapping:{}};const n=e.size(),a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),i=Kp(e)??[-.7/2,.7/2],s=r.length>1?vp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Kp=e=>{const t=e.getConstant(l.POSITION_VARIABLES.xMin)?.value,r=e.getConstant(l.POSITION_VARIABLES.xMax)?.value;return typeof t!="number"||typeof r!="number"?null:[t,r]},Va=l.prefixInternalVariable("__ungrouped__"),As=(e,t)=>{const r=l.extractVariableName(t.x),n=l.extractVariableName(t.y);if(!r||!n)return null;const a=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=a.length===0,s=i?[Va]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?Va:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},Is=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=Yp(p===o,p===d)}return a},Yp=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",qp=class extends Xt{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=As(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const I=x>=0?m:h;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=Is(c,o,a,s);return{data:e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u),mapping:{}}}},jp=class extends Xt{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Xp=class extends Xt{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=As(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=Is(c,o,a,s);let d=e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",c).addVariable(l.POSITION_VARIABLES.yMax,"numeric",o).addVariable(l.POSITION_VARIABLES.yRaw,"numeric",n).addVariable(l.STACK_VARIABLES.role,"categorical",u);const m=l.extractVariableName(t.y);return m!==null&&(d=d.addVariable(m,"numeric",o)),{data:d,mapping:{}}}},Zp=class extends l.Registry{constructor(){super("position"),this.register("identity",new jp),this.register("stack",new Xp),this.register("fill",new qp),this.register("dodge",new zp)}},Jp=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"||!l.isDefined(s.aes)||en(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ts(s.axis,t.yScaleType));if(!c)continue;const u=a.getValues(o,{type:"numeric"}).map(d=>l.isDefined(d)?c.map(d):null);a=a.addVariable(l.resolveScaledAestheticVariable(s.aes),"numeric",u)}return a}},Qp=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.x),a=r("x");if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.x,"numeric",i)}},eh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},th=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(ae(t.yScaleType));if(!n||!a)return e;const i=e.getValues(n).map(s=>l.isDefined(s)?a.map(s):null);return e.addVariable(l.POSITION_VARIABLES.y,"numeric",i)}},rh=class{map({data:e,layer:t,getPositionScale:r}){const n=r(ae(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s=e.size(),o=new Array(s),c=new Array(s);for(let u=0;u<s;u++){const d=a[u],m=i[u];l.isDefined(d)&&l.isDefined(m)?(o[u]=n.map(d),c[u]=n.map(m)):(o[u]=null,c[u]=null)}return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",o).addVariable(l.POSITION_VARIABLES.yMax,"numeric",c)}},nh=[new Qp,new th,new eh,new rh,new Jp];function ah(e,t){const r=e[t];return r?.kind==="position"?r:null}var ih=class extends Ae{constructor(e,t=nh){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=>ah(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}}},sh=class extends l.Stage{constructor(e,t){super(),this.container=e,this.registry=t}dependencies(e){return[e.layers,e.scales]}run(e){this.validateScaleTypeCompatibility(e);const t=new Map;for(const a of e.scales)t.set(a.scaledAesthetic,a);const r=this.collectValues(e.layers,t),n={};for(const[a,i]of t){const s=r.get(a)??[];n[a]=this.registry.get(i.scaleType).compile(i,s)}return n}validateScaleTypeCompatibility(e){const t=[];for(const r of e.scales){const{compatibleDataTypes:n}=this.registry.get(r.scaleType),a=N(r.scaledAesthetic),i=e.layers.find(c=>l.isDefined(c.mapping[a]));if(!i)continue;const s=l.extractVariableName(i.mapping[a]);if(!l.isDefined(s)||!i.data.hasVariable(s))continue;const o=i.data.getType(s);if(n.includes(o)||t.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${s}' (${o})`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o}}),r.scaledAesthetic==="lineType"&&o!=="categorical"){const c=o==="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 ${o} variable '${s}'. ${c}`,context:{aesthetic:a,variableName:s,scaleType:r.scaleType,variableType:o},suggestion:c})}}ps(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(!l.isDefined(s))continue;const o=i==="y"?ae(n.yScaleType):i,c=a.get(i)??(es(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=this.resolveVariables(i,s,n.data);this.collectFromVariables(n.data,u,c,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"||!l.isDefined(n.aes)||en(n.aes)||t.set(n.aes,ts(n.axis,e.yScaleType));return t}resolveVariables(e,t,r){if(e==="y"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const n=l.extractVariableName(t);return!n||!r.hasVariable(n)?[]:[n]}hasPositionAdjustedY(e){return e.hasVariable(l.POSITION_VARIABLES.yMin)&&e.hasVariable(l.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)}},oh=["rgb","lab","hcl","hsl"],lh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],Ts=["RdBu","BrBG","PuOr","Spectral"],Ls={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},ch=new Set(Ts.map(e=>e.toLowerCase()));function ws(e){const t=e.toLowerCase(),r=Ls[t];return r?r.toLowerCase():t}function uh(e){return ch.has(ws(e))}var dh={rgb:De.interpolateRgb,lab:De.interpolateLab,hcl:De.interpolateHcl,hsl:De.interpolateHsl},mh={viridis:D.interpolateViridis,magma:D.interpolateMagma,inferno:D.interpolateInferno,plasma:D.interpolatePlasma,cividis:D.interpolateCividis,turbo:D.interpolateTurbo,blues:D.interpolateBlues,greens:D.interpolateGreens,greys:D.interpolateGreys,oranges:D.interpolateOranges,purples:D.interpolatePurples,reds:D.interpolateReds,rdbu:D.interpolateRdBu,brbg:D.interpolateBrBG,puor:D.interpolatePuOr,spectral:D.interpolateSpectral};function un(e){const t=hh(e);return e.reverse?r=>t(1-r):t}function ph(e={},t=2){const r=un({range:e.range??null,scheme:e.scheme??null,interpolate:e.interpolate??l.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 hh(e){const t=dh[e.interpolate];if(e.range&&e.range.length>=2)return(0,De.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=mh[ws(e.scheme)];if(r)return r}return(0,De.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var st=class{createPositionScale(e,t){return{kind:"position",aesthetic:N(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:N(e.scaledAesthetic),spec:e,...t}}},fh=class extends st{constructor(e){super(),this.container=e,this.compatibleDataTypes=["numeric"]}compile(e,t){if(e.scaleType!=="continuous")throw new l.InternalError({message:"ContinuousScale.compile received non-continuous spec"});const r=Ye(e.scaledAesthetic),n=e.scaledAesthetic==="color",a=this.computeDataDomain(t,e);return n?this.buildColorScale(a,e):r?this.buildPositionScale(a,e):this.buildVisualScale(a,e)}computeDataDomain(e,t){let r=1/0,n=-1/0;for(const a of e)typeof a=="number"&&(a<r&&(r=a),a>n&&(n=a));return r===1/0?[0,0]:(t.zero&&(r>0&&(r=0),n<0&&(n=0)),[r,n])}createD3Scale(e,t,r){let n=[r.domainMin??e[0],r.domainMax??e[1]];const a=r.transform==="log"&&gh(n);r.transform==="log"&&!a&&this.container.diagnostics.addWarning({code:"INCOMPATIBLE_SCALE_DOMAIN",message:`Log scale on '${r.scaledAesthetic}' needs a strictly positive or negative domain, but the domain is [${e[0]}, ${e[1]}] — rendering a linear scale instead.`,context:{aesthetic:N(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=yh(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=un(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],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,Q.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){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,Q.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},gh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function yh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var vh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["temporal"]}compile(e,t){if(e.scaleType!=="datetime")throw new l.InternalError({message:"DatetimeScale.compile received non-datetime spec"});const r=Ye(e.scaledAesthetic),n=this.computeDataDomain(t);if(!r)throw new l.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=bh(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?em(i,s,c.interval):[]:a.ticks(c?.count)})}},bh=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Sh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(e,t){if(e.scaleType!=="discrete")throw new l.InternalError({message:"DiscreteScale.compile received non-discrete spec"});const r=Ye(e.scaledAesthetic),n=Ji(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??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,Q.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})}},xh=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(e){if(e.scaleType!=="identity")throw new l.InternalError({message:"IdentityScale.compile received non-identity spec"});return{kind:"identity",aesthetic:N(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},Ah=class extends st{constructor(...e){super(...e),this.compatibleDataTypes=["categorical","temporal","numeric"]}compile(e,t){if(e.scaleType!=="palette")throw new l.InternalError({message:"PaletteScale.compile received non-palette spec"});const r=Zi(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},Ih=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new fh(e)),this.register("discrete",new Sh),this.register("datetime",new vh),this.register("identity",new xh),this.register("palette",new Ah)}},Tt={color:null,size:"small",labelCrossPosition:.5},de={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},ur={zOrder:"foreground",fit:"contain",opacity:1},Th={x:8,y:8,unit:"px"},Lt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},me={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Lh={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}},wh=(e,t,r)=>{const n=Eh(e,t),a=Ch(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Dh(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>Ph(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Fh(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>kh(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>Oh(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Nh(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>_h(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>Mh(e,i,r)).filter(l.isDefined)}},Eh=(e,t)=>{if(t===void 0)return{};if(!Vh(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:O()}):(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))}},Vh=e=>{const t=new Set;for(const r of Rh(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},Rh=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Ch=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},dn=(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},kh=(e,t,r,n)=>{const a=Nt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),content:t.content,at:a,width:t.width,align:t.align??Lt.align,backgroundColor:t.backgroundColor??Lt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??Lt.backgroundColorStyle}},Dh=(e,t,r)=>{const n=Qe(e,t.start,r),a=Qe(e,t.end,r);return n===null||a===null?null:{id:t.id??O(),start:n,end:a,label:t.label,color:t.color??Tt.color,size:t.size??Tt.size,labelCrossPosition:t.labelCrossPosition??Tt.labelCrossPosition}},Qe=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,...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)},Nt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return dn(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=Qe(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},Oh=(e,t,r,n)=>{const a=Nt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),at:a,sticker:t.sticker}},_h=(e,t,r)=>{const n=Qe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n}},Mh=(e,t,r)=>{const n=Qe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n,content:t.content}},Ph=(e,t,r)=>t.region.anchorType==="annotation"&&!dn(e,t.region.ref,r,t.id)?null:{id:t.id??O(),kind:t.kind??de.kind,zOrder:t.zOrder??de.zOrder,region:Bh(t.region),fillColor:t.fillColor===void 0?de.fillColor:t.fillColor,fillOpacity:t.fillOpacity??de.fillOpacity,strokeWidth:t.strokeWidth??de.strokeWidth,strokeColor:t.strokeColor??de.strokeColor},Nh=(e,t,r)=>t.region.anchorType==="annotation"&&!dn(e,t.region.ref,r,t.id)?null:{id:t.id??O(),src:t.src,zOrder:t.zOrder??ur.zOrder,region:t.region,fit:t.fit??ur.fit,opacity:t.opacity??ur.opacity},Bh=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:Th},Ra=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=Lh[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Fh=(e,t,r,n)=>{const a=Nt(e,t.start,r,n,t.id),i=Nt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??O(),start:Ra(a),end:Ra(i),color:t.color??me.color,thickness:t.thickness??me.thickness,startArrowheadStyle:t.startArrowheadStyle??me.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??me.endArrowheadStyle,lineStyle:t.lineStyle??me.lineStyle,hasStickerStyle:t.hasStickerStyle??me.hasStickerStyle}},$h={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null,lineStyle:"dashed",lineWidth:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{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},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function Gh(e){const t=(0,ze.merge)({},$h,e);return t.content=Uh(t.content,e?.content),t}var Uh=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Wh={xLimits:null,yLimits:null},wt={theta:"x",startAngle:0,innerRadius:0};function _r(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,kt.default)({},Wh,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??wt.theta,startAngle:t.params?.startAngle??wt.startAngle,innerRadius:(0,Pe.default)(t.params?.innerRadius??wt.innerRadius,0,1)}}}}function Hh(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??O(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var zh=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=Ca(e.filter(n=>n.severity==="error")),r=Ca(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Kh=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 Ca(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Yh={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:l.POSITION_VARIABLES.yRaw},position:"auto",justify:"end",align:"center",offset:4,categoryPosition:"inside",categoryJustify:"start",categoryAlign:"center",categoryOffset:4};function Es(e,t){const r=e??t,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 Te(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Kh(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=Xh({dataLabels:Jh(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return jh({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??O(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Es(n.stat,"identity"),position:c,yScaleType:n.yScaleType??"primary",params:o.resolveParams({params:n.params,diagnostics:s}),transforms:n.transforms??[],interactive:n.interactive??o.defaultInteractive,dataLabels:u}}function qh(e,t,r,n,a){const i=n.map((s,o)=>Te(e,t,r,s,a,o));return Rs(e,i)}var Vs=(e,t,r,n)=>n.label!==void 0?n.label:Qh(e,t,r,n),Rs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:at(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=l.extractConstantValue(n.mapping.y);if(!l.isStrictNumericDataValue(a))return n;const i=(0,ze.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},jh=({diagnostics:e,coordType:t,geom:r,position:n,dataLabels:a})=>{if(e===void 0)return;const i=r.type==="bar"&&t==="polar",s=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"&&s&&P(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&&!(s&&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'."}),a.showCategoryLabels&&a.showDataLabels&&!i&&e.addWarning({code:"DATA_LABEL_SETTING_IGNORED",message:"showCategoryLabels only applies to polar bars (pie / donut); it will be ignored.",suggestion:"Turn off showCategoryLabels for this layer."})},Xh=({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 o=Zh(t,r,n);if(o===null)return e;const c=i==="panel-end"?"end":"start";return s&&a?.addWarning({code:"DATA_LABEL_PLACEMENT_COERCED",message:`${o}; justify '${i}' will render as '${c}'.`,context:{expected:c,actual:i},suggestion:`Use justify '${c}' for this layer.`}),{...e,justify:c}},Zh=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&P(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Jh=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Vs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,ze.merge)({},Yh,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},Qh=(e,t,r,n)=>e.get(t).resolveDefaultLabelSource?.(n)??Wt(r,n);function Mr(e,t){const r=ef(e,t);if(r===null)return{discreteAxis:null,zeroAxis:null,niceZeroAxis:!0};const{layer:n,scaleConstraints:a}=r;return{discreteAxis:a.discreteMainAxis?"x":null,zeroAxis:a.zeroBaseline?ae(n.yScaleType):null,niceZeroAxis:n.position!=="fill"}}function ef(e,t){for(const r of t){if(!e.has(r.geom))continue;const{scaleConstraints:n}=e.get(r.geom);if(n!==void 0)return{layer:r,scaleConstraints:n}}return null}var Cs={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},tf={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 mn(e,t,r,n,a,i){switch(t.scaleType){case"inferred":return mn(e,nf(e,t,r,n,a),r,n,a,i);case"continuous":{const s=Cs[t.scaledAesthetic],o=s==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,c=t.scaledAesthetic==="size"&&s==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??c,reverse:t.reverse??l.CONTINUOUS_SCALE_DEFAULTS.reverse,nice:t.nice??l.CONTINUOUS_SCALE_DEFAULTS.nice,zero:t.zero??l.CONTINUOUS_SCALE_DEFAULTS.zero,clamp:t.clamp??s!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??o??null,scheme:af(e,t),interpolate:t.interpolate??l.CONTINUOUS_SCALE_DEFAULTS.interpolate,domainMid:t.domainMid??l.CONTINUOUS_SCALE_DEFAULTS.domainMid,symmetric:t.symmetric??l.isDefined(t.domainMid)}}case"datetime":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,domainMin:t.domainMin??l.DATETIME_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.DATETIME_SCALE_DEFAULTS.domainMax,nice:t.nice??l.DATETIME_SCALE_DEFAULTS.nice,reverse:t.reverse??l.DATETIME_SCALE_DEFAULTS.reverse,clamp:t.clamp??!1};case"discrete":return ks(t);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e,t.palette,i),overrides:l.resolvePaletteOverrides(e,t.overrides,t.palette,i)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function rf(e,t,r,n,a,i,s){const o=lf(of(r,n)),c=new Map;for(const d of o)c.set(d.scaledAesthetic,d);const u=[...c.values()].map(d=>mn(e,d,t,n,a,s));return i.coordType==="polar"?u.map(Ds):u}function ks(e){return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??l.DISCRETE_SCALE_DEFAULTS.range,domain:e.domain??l.DISCRETE_SCALE_DEFAULTS.domain,padding:e.padding??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??l.DISCRETE_SCALE_DEFAULTS.reverse}}var Ds=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function nf(e,t,r,n,a){const i=N(t.scaledAesthetic),s=t.scaledAesthetic==="ySecondary"?sf(n,a):a[i],o=Mr(e.geomRegistry,n);if(t.scaledAesthetic===o.discreteAxis)return l.discrete(t.scaledAesthetic,t.options);if(t.scaledAesthetic===o.zeroAxis){const m=t.options;return l.continuous(t.scaledAesthetic,{...m,zero:!0,...!o.niceZeroAxis&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!r.hasVariable(c))return l.continuous(t.scaledAesthetic,t.options);const u=r.getType(c),d=Cs[t.scaledAesthetic];switch(tf[u][d]){case"discrete":return l.discrete(t.scaledAesthetic,t.options);case"palette":return l.palette(t.scaledAesthetic);case"datetime":return l.datetime(t.scaledAesthetic,t.options);case"continuous":return l.continuous(t.scaledAesthetic,t.options);default:return l.identity(t.scaledAesthetic)}}function af(e,t){const r=t.scheme??l.CONTINUOUS_SCALE_DEFAULTS.scheme;return r===null?null:l.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:N(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&uh(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:N(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function sf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function of(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function lf(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var cf=e=>{const t=new Set;e!==void 0&&Os(e,t,new Set);const r={tokens:{},defaults:[],overrides:[]};for(const n of t)Object.assign(r.tokens,n.tokens),r.defaults.push(...n.defaults??[]),r.overrides.push(...n.overrides??[]);return r},Os=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Os(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function uf(e,t,r){const n=_r(t.coords),a=qh(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=rf(e,t.data,t.scales,a,t.mapping,n,r),s=Gh(t.config),o=Hh(e,t.highlights,a),c=wh(e,t.annotations,a),u=cf(t.styles);return{data:t.data,mapping:t.mapping,layers:a,scales:i,transforms:t.transforms,highlights:o,styles:u,annotations:c,coords:n,config:s}}var _s=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return uf(this.container,{...e,data:t},r)}},df=class{constructor(e){this.registry=e}compute(e,t){return this.registry.get(e.type).compute({data:t.data,mapping:t.mapping,spec:e,xScaleIsDiscrete:t.xScaleIsDiscrete})}},mf=class extends Ae{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Tf(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of Lf(e.styles))this.container.diagnostics.addWarning(r);for(const r of wf(e.styles))this.container.diagnostics.addWarning(r);for(const r of t)for(const n of r.styles.warnings)this.container.diagnostics.addWarning(n);return t}dependencies(e){return[e.styles,e.config.parsingLocale]}compileLayer(e,t){const r=Us({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Oe={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ms={bar:{...Oe,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Oe,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Oe,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Oe,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},ka=1,Da=1e3,yt={color:"color",strokeWidth:"pixels",lineType:"lineType"},dr={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Et={panelBorder:{...yt,borderRadius:"pixels"},panelBorderEdge:yt,gridLine:yt,tickLine:{...yt,length:"pixels"},axisLabel:dr,tickLabel:{...dr,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...dr,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"}},pf=new Set([...Object.keys(Oe),...Object.values(Ms).flatMap(e=>Object.keys(e??{})),...Object.values(Et).flatMap(e=>Object.keys(e))]),Ps=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph"],hf=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),ff=(e,t,r="en-US")=>Us({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),gf=class extends l.Stage{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of t.warnings)this.container.diagnostics.addWarning(r);return t}dependencies(e){return[e.styles]}run(e){return Ns(e.styles)}},Ns=e=>{const t=[],r={...l.BUILTIN_STYLES.tokens,...e.tokens},n={panelBorder:{defaults:[],overrides:[]},gridLine:{defaults:[],overrides:[]},tickLine:{defaults:[],overrides:[]},axisLabel:{defaults:[],overrides:[]},tickLabel:{defaults:[],overrides:[]},ruleLabel:{defaults:[],overrides:[]},dataLabel:{defaults:[],overrides:[]},graph:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(Zt(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!yf(i)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} targets unknown '${String(d)}'.`,context:{param:"target",actual:String(d),...u},suggestion:`Set 'target' to one of ${Ps.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} 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 m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!bf(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(hf.has(m.target)){const p=m.axis;if(p!==void 0&&!Af(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${Jr.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${Ge(p)}.`,context:{param:"layer",actual:Ge(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!Sf(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!xf(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=pn({declarations:i.declarations,vocabulary:vf(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.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},Zt=e=>e.select.target==="geom",yf=e=>{const t=e.select.target;return t!=="geom"&&Ps.includes(t)},Bs=e=>(e!==void 0?Ms[e]:void 0)??Oe,vf=e=>e.target==="panelBorder"?e.edge===void 0?Et.panelBorder:Et.panelBorderEdge:Et[e.target],bf=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),Sf=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),xf=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Af=e=>typeof e=="string"&&Jr.includes(e),If=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!Zt(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=pn({declarations:a.declarations,vocabulary:Bs(s),tokens:t,location:`builtin[${i}]`,origin:o,warnings:r});Object.keys(c).length!==0&&n.push({declarations:c,...a.when?.state===void 0?{}:{state:a.when.state},origin:o})}),n},Fs=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},Tf=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Fs(e,(a,i,s)=>{const o=a.select;if(o.target!=="geom"&&o.target!=="ruleLabel")return;const c=o.layer;c===void 0||typeof c!="string"||r.has(c)||n.push({code:"INVALID_STYLE_RULE",message:`Style ${i}[${s}] targets unknown layer '${c}'.`,context:{param:"layer",actual:c,...a.id===void 0?{}:{styleEntryId:a.id}},suggestion:"Set 'layer' to the id of a layer in the spec."})}),n},Lf=e=>{const t=[];return Fs(e,(r,n,a)=>{if(!Zt(r))return;const i=r.when?.state;i===void 0||$s(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 ${l.STYLE_STATES.map(s=>`'${s}'`).join(", ")}.`})}),t},$s=e=>l.STYLE_STATES.includes(e),wf=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Gs(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Ge(n)}.`,context:{param:"tokens",actual:Ge(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Gs=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,vt=e=>typeof e=="number"&&Number.isFinite(e),Ge=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Us=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=zt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!Zt(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!$s(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const I=fe(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=pn({declarations:h.declarations,vocabulary:Bs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:he(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...If(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},pn=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${Ge(g)}.`,context:{param:p,expected:f,actual:Ge(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Gs(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=pf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":vt(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":vt(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Ci(f)?u(p,f):d(p,`one of ${qr.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":vt(f)&&f>=ka&&f<=Da?u(p,f):d(p,`a number in [${ka}, ${Da}]`,f);break;case"multiplier":vt(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;default:break}}return o},Ef=({layer:e})=>{if(e.position==="stack")return;const t=l.extractVariableName(e.mapping.y);if(t===null)return;let r=0,n=0;for(const a of e.data){const i=a[t];l.isStrictNumericDataValue(i)&&(r+=i,n+=Math.abs(i))}return{grandTotal:r,absoluteGrandTotal:n}},Vf=({layer:e})=>{if(e.position!=="stack")return;const t=l.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(l.POSITION_VARIABLES.yMin)||!e.data.hasVariable(l.POSITION_VARIABLES.yMax))return;const r=new Map;for(const a of e.data){const i=a[t],s=F(a),o=M(a),c=K(a),u=Y(a),d=Yr(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=sn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},Rf=class extends Ae{constructor(e){super(),this.container=e}dependencies(){return[]}compileLayer(e){const t=this.container.geomRegistry.get(e.geom),r={};if(t.summaries.stackTotals){const n=Vf({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=Ef({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Ws=class extends l.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)}},Oa={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Cf=["color","size","alpha","strokeWidth","lineType"],kf=class extends Ae{dependencies(e){return Cf.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Oa[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,Oa[a],Df(c)))}return{...e,data:r}}},Df=e=>t=>l.isDefined(t)?e.map(t):null;function Hs(e=new jt){return{diagnostics:new zh,geomRegistry:e}}var zs=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{if(e.data===void 0)return this.runPipeline({spec:e.spec});this.lastData=e.data;const r=Sd(e.spec.data,e.spec.mapping);return this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data),mapping: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}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,compiled: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:[Wi(e)],warnings:t.warnings}}trackCompile(e){if(!l.IS_DEV)return e();const t=this.getCacheStats(),r=performance.now(),n=e(),a=performance.now()-r,i={};for(const{name:s,getStats:o}of this.stages){const c=o();i[s]={hits:c.hits-t[s].hits,misses:c.misses-t[s].misses}}return this.lastCompile={stages:i,durationMs:a},n}runPipeline({spec:e}){return Kt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result()}},Of=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],_f=({plugins:e=[]}={})=>{const t=vs(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Up(t),i=Hs(r),s=new Ih(i),o=new Ws(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new zs(i,new l.DataCompiler,new _s(i),o,new bd,new gp(i,o,n,new hp(i,o,new df(n),new Yd,new Kd(i),new Hp(new Zp))),new sh(i,s),new Id(new Gd),new ih(i),new kf,new ap(i),new Rf(i),new mf(i),new gf(i),new cp(i),new id(i))};function Mf(e,t){return e.geom===t}function Ks(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Pf(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>qs(s,o),i)}function Ys(e,...t){return t.reduce((r,n)=>qs(r,n),e)}function Pf(e){return typeof e=="object"&&e!==null&&"type"in e}function qs(e,t){switch(t.type){case"scale":return{...e,scales:[...e.scales,t]};case"coord":return{...e,coords:t};case"config":return{...e,config:(0,kt.default)({},e.config,t.config)};case"layer":return{...e,layers:[...e.layers,t]};case"transform":return{...e,transforms:[...e.transforms,t]};case"mapping":return{...e,mapping:{...e.mapping,...t.mapping}};case"highlight":return{...e,highlights:[...e.highlights,t]};case"styles":return{...e,styles:e.styles===void 0?t:{...t,extends:[e.styles,...t.extends??[]]}};case"annotation":return Nf(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Nf(e,t){const r={...e.annotations};switch(t.kind){case"differenceArrow":r.differenceArrows=[...r.differenceArrows??[],t.annotation];break;case"shape":r.shapes=[...r.shapes??[],t.annotation];break;case"arrow":r.arrows=[...r.arrows??[],t.annotation];break;case"text":r.textAnnotations=[...r.textAnnotations??[],t.annotation];break;case"image":r.images=[...r.images??[],t.annotation];break;case"sticker":r.stickers=[...r.stickers??[],t.annotation];break;case"pinnedNumber":r.pinnedNumbers=[...r.pinnedNumbers??[],t.annotation];break;case"comment":r.comments=[...r.comments??[],t.annotation];break;default:throw new Error(`Unknown annotation kind: ${t.kind}`)}return{...e,annotations:r}}function Bf(e){const t=e?.plugins??[],r=$f(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Ks,pipe:Ys,plugins:t}}var Ff=e=>(t={})=>l.buildLayerInput(e,t);function $f(e){const{geoms:t,stats:r,transforms:n}=vs(e),a={};for(const o of t)a[o.type]=Ff(o.type);const i={};for(const o of r)i[o.type]=()=>({type:o.type});const s={};for(const o of n)s[o.transformType]=c=>({type:"transform",transformType:o.transformType,options:c?.options});return{geom:a,stat:i,transform:s}}var Gf=24,Uf={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:8,before:0},topAxisLabel:{after:8,before:0},topAxis:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16},footer:{after:0,before:16}},Wf={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},mr="…",js=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(mr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+mr)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+mr};var B={timeZone:"UTC"},_=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},oe=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",hn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Hf=Er.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Xs=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>oe(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=yn(a,i),{base:o,suffix:c}=gn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),Zs=({locale:e,numberFormat:t,intlOptions:r})=>oe(n=>{const{base:a,suffix:i}=gn(n,t.abbreviation),s={...yn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),fn=e=>oe(t=>Hf(t)),Js=({locale:e,intlOptions:t})=>oe(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Qs=({locale:e,numberFormat:t,intlOptions:r})=>oe(n=>{const a=yn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),gn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=zf(e);return gn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},yn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},zf=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},Kf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).format(r)),Yf=({locale:e,intlOptions:t})=>_(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...B,...t}).formatToParts(r);return qf(n.map(jf))}),eo=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t}).format(r)),to=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"long",...B,...t}).format(r)),vn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...B,...t}).format(r)),bn=e=>_(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),ro=({locale:e,intlOptions:t})=>_(r=>{const n=(0,Ti.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t,year:void 0}).formatRange(r,n)}),no=({locale:e,intlOptions:t})=>_(r=>{const n=(0,Ti.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).formatRange(r,n)}),Sn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{year:"numeric",...B,...t}).format(r)),ao=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),qf=e=>e.map(t=>t.value).join(""),jf=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},_a=1e3,Xf=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>oe(a=>{const i={...An(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return xn(a,t,i)}),Zf=({locale:e,tickValues:t,intlOptions:r})=>oe(n=>{const a={...An(n,t),notation:"compact",...r};return xn(n,e,a)}),Jf=({locale:e,tickValues:t,intlOptions:r})=>oe(n=>{const a={...An(n,t),notation:"compact",...r,style:"percent"};return xn(n,e,a)}),xn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),io=e=>Math.abs(e)>_a?io(e/_a):Number.isInteger(e),Qf=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},An=(e,t)=>io(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Qf(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},eg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),tg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",...B,...t}).format(r)),rg=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),ng=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),In=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Xf(e);case"date":case"datetime":return eg(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return rg(e);case"decimal":case"integer":return Zf(e);case"duration":return fn(e);case"month":return tg(e);case"month_year":return vn(e);case"percentage":return Jf(e);case"quarter":return bn(e);case"text":return hn(e);case"time":return ng(e);case"year":return Sn(e);case"lookup":return In({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},ag=.9,ig=1/3,sg=1/4,og=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?lg(e):cg(e),lg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=so(e.ticks,n),o=ug(e.ticks,r.width),c=o*ag;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=Nr(c);return{...e,ticks:Pr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Nr(r.height*ig);return{...e,ticks:Pr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},cg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=so(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Nr(r.width*sg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Pr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},ug=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},so=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:s,height:o}=t(i.formattedLabel);r.push(s),s>n&&(n=s),o>a&&(a=o)}return{widths:r,maxWidth:n,maxHeight:a}},Pr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:js(i.formattedLabel,r,a)})},Nr=e=>Math.max(0,Math.floor(e)),dg=(e,t,r,n)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",i=a?60:40;let s=r-(e.length-1)*i;for(const o of e){const{width:c,height:u}=n(o);if(s-=a?c:u,s<0)return!1}return!0},mg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?pg(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;dg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},pg=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),Ma=.5,ot=e=>({x:0,y:0,width:e.width,height:e.height}),Tn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,lt=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:fg(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:gg(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,I=Na(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Na(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:hg(e,I,A,c,u)}},Pa=(e,t,r,n)=>r-n>=e-Ma&&r+n<=t+Ma,hg=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||Pa(e.x,e.x+e.width,t,n/2),s=e.height===0||Pa(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},fg=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",gg=e=>e==="center"?"center":e==="start"?"min":"max",Na=({anchor:e,placement:t,offset:r},{min:n,max:a,halfExtent:i})=>{if(e==="center")return(n+a)/2;if(t==="inside"&&n===a)return n;const s=r+i;return e==="min"?t==="inside"?n+s:n-s:t==="inside"?a-s:a+s},yg=(e,t,r,n,a)=>{const i=t??e,s=1-Math.max(e,i);return{box:{x:r*n,y:s*a,width:0,height:Math.abs(e-i)*a},frame:{valueAxis:"y",valueDirectionSign:e>=i?-1:1}}},vg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Sg(e.layer);for(const a of e.layer.data){const i=R(a),s=M(a)??E(a);if(i===null||s===null||!Be(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),{box:d,frame:m}=yg(s,F(a),i,e.panelRect.width,e.panelRect.height),h=lt({box:d,panel:ot(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},bg={place:vg,getPercentageValueStrategy:e=>e.position==="fill"?"fill":P(e.position)?"stack":"none"},Sg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:qt(e.data,e.mapping)?Tn(r):r,align:n}},Ln=(e,t,r)=>{const n={},a=i=>{const s=n[i];if(s!==void 0)return s;const{width:o,height:c}=e(t,i,r),u={width:o,height:c};return n[i]=u,u};return{get inside(){return a("inside")},get outside(){return a("outside")}}},bt=6,xg=e=>{const t=[],r=P(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=Ig({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:n});for(const s of a){const o=e.layer.dataLabels.position==="auto"?wg({mainAxis:e.coordSystem.mainAxis,isStacked:r,isNegativeBar:s.isNegative,shouldRotate:i,bounds:s.bounds,boxes:s.boxes,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height,offset:e.layer.dataLabels.offset}):Eg(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,ot(e.panelRect));if(o===null)continue;const c=s.boxes[o.position];t.push({layerId:e.layer.id,x:o.x,y:o.y,text:s.text,width:c.width,height:c.height,isRotated:o.isRotated,target:"observation",position:o.position})}}if(e.layer.dataLabels.showCategoryLabels)for(const a of Vg(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=Dg({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const i of a)t.push(i)}return t},Ag={place:xg,getPercentageValueStrategy:e=>e.position==="fill"?"fill":P(e.position)?"stack":"absoluteGrandTotal"},Ig=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatLabel:a,isFlipped:i})=>{const s=[];let o=!1;const c=e.dataLabels.position==="auto",u=l.extractVariableName(e.mapping.y);for(const d of e.data){const m=lo(t,d);if(m===null)continue;const h=a(d);if(h==="")continue;const p=Ln(n,"observation",h),f=wn(m,r);c&&p.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:h,boxes:p,bounds:f})}return{entries:s,shouldRotate:!i&&o}},wn=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),oo=(e,t,r,n,a)=>{if(e==="x"){let o=1-a,c=a-n;return c<0&&(o+=c,c=-c),{x:t,y:o,width:r-t,height:c}}let i=t,s=r-t;return s<0&&(i+=s,s=-s),{x:i,y:1-a,width:s,height:a-n}},lo=(e,t)=>{const r=K(t),n=Y(t),a=F(t),i=M(t)??E(t);return r===null||n===null||a===null||i===null?null:oo(e,r,n,a,i)},Tg=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return oo(e,r,n,a,i)},Lg=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Br=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},wg=e=>e.isStacked?Rg({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):kg({edge:Lg(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),co=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Eg=(e,t,r,n,a)=>{if(e.position==="auto")return null;const i=r&&e.position==="outside"?"inside":e.position,s=n.boxes[i],o=lt({box:n.bounds,panel:a,frame:co(t,n.isNegative),placement:i,justify:e.justify,align:e.align,offset:e.offset,labelWidth:s.width,labelHeight:s.height});return{x:o.x,y:o.y,isRotated:!1,position:o.position}},Vg=(e,t)=>{const r=[],{categoryPosition:n,categoryJustify:a,categoryAlign:i,categoryOffset:s}=e.layer.dataLabels,o=t&&n==="outside"?"inside":n,c=e.coordSystem.mainAxis,u=ot(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=lo(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=Ln(e.measureDataLabel,"category",p),g=f[o],y=wn(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=lt({box:y,panel:u,frame:co(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},Rg=({bounds:e,box:t,isRotated:r})=>{const n=Br(t.width,t.height,r);return n.width>e.width||n.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},Cg=(e,t,r,n)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:n};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:n};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:r};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:r}}},kg=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=Cg(e,t,a,i),g=Br(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height;if(y+s<d){if(v>m)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const V=h-p*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=Br(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=h+p*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},Dg=({layer:e,mainAxis:t,panelRect:r,measureDataLabel:n,formatAbsolute:a})=>{const i=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return i;const o=t==="y";for(const c of s){const u=wn(Tg(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+bt+m/2:u.x-bt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-bt-h/2:u.y+u.height+bt+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},Og=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Mg(e.layer);for(const a of e.layer.data){const i=R(a),s=E(a);if(i===null||s===null||!Be(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=lt({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:ot(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:d.x,y:d.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:d.position})}return t},_g={place:Og,getPercentageValueStrategy:()=>"none"},Mg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:qt(e.data,e.mapping)?Tn(r):r,align:n}},Pg={color:Ht,alpha:Oi,strokeWidth:kr,lineType:_i,size:jr,borderWidth:kr},En=(e={})=>{const t=e.colorScheme??"light",r=new WeakMap,n=new WeakMap;return{geomReaders:o=>{const c=r.get(o);if(c!==void 0)return c;const u=Fg(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=Ng(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=Je(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=Je(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=Je(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=uo(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=Je(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},Ng=(e,t)=>{const r=(o,c)=>({get:d=>{const m=Ba(o.overrides,d,c,t);return m!==void 0?m:Ba(o.defaults,d,c,t)}}),n=o=>r(e.panelBorder,c=>{const u=c.select.target==="panelBorder"?c.select.edge:void 0;return u===void 0||u===o}),a=o=>c=>r(e[o],u=>u.select.target!==o?!1:u.select.axis===void 0||u.select.axis===c),i=o=>r(e.ruleLabel,c=>c.select.target!=="ruleLabel"?!1:c.select.layer===void 0||c.select.layer===o),s=(o,c)=>r(e.dataLabel,u=>u.select.target!=="dataLabel"||u.select.role!==void 0&&u.select.role!==o?!1:u.select.position===void 0||u.select.position===c);return{panelBorder:n,gridLine:a("gridLine"),tickLine:a("tickLine"),axisLabel:a("axisLabel"),tickLabel:a("tickLabel"),ruleLabel:i,dataLabel:s,graph:r(e.graph,()=>!0)}},Ba=(e,t,r,n)=>{for(let a=e.length-1;a>=0;a--){const i=e[a];if(i===void 0||!r(i))continue;const s=i.declarations[t];if(s!==void 0)return Bg(s,n)}},Bg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Fg=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=St(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=St(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=St(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=uo(n,a);return o!==void 0?o:St(e.defaults,n,a,void 0,t)}}),St=(e,t,r,n,a)=>Je(e,t,r,n,a)?.value,Je=(e,t,r,n,a)=>{for(let i=e.length-1;i>=0;i--){const s=e[i];if(s===void 0||s.state!==n)continue;const o=s.declarations[t];if(o!==void 0&&$g(s,r))return{value:Gg(o,a),origin:s.origin}}},$g=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),Gg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,uo=(e,t)=>{const r=Pg[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Ug=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Hg(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=En().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=E(s);if(o===null||c===null||!Be(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=lt({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:ot(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},Wg={place:Ug,getPercentageValueStrategy:()=>"none"},Hg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:r,align:n}};function Vn(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Rn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var zg=" · ",pr=2,et=(e,t,r,n)=>{const a=Math.abs(e==="radial"?Math.sin(t):Math.cos(t)),i=Math.abs(e==="radial"?Math.cos(t):Math.sin(t));return a*(r/2)+i*(n/2)},Kg=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=et("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-pr&&t+i<=e.outerRadiusPx+pr)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=et("tangential",r,n,a)/t,c=pr/t;return Math.abs(r-e.midAngle)+o<=s+c},Yg=({x:e,y:t,labelWidth:r,labelHeight:n,panelRect:a})=>e-r/2>=0&&e+r/2<=a.width&&t-n/2>=0&&t+n/2<=a.height,qg=({wedge:e,position:t,offset:r,labelWidth:n,labelHeight:a})=>t==="inside"?{labelRadius:(e.innerRadiusPx+e.outerRadiusPx)/2,labelAngle:e.midAngle,position:"inside"}:{labelRadius:e.outerRadiusPx+r+et("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},jg=({wedge:e,placement:t,justify:r,align:n,offset:a,labelWidth:i,labelHeight:s})=>{const o=n==="start"?e.startAngle:n==="end"?e.endAngle:e.midAngle,c=a+et("radial",o,i,s);let u;if(r==="center")u=(e.innerRadiusPx+e.outerRadiusPx)/2;else if(r==="end")u=t==="inside"?e.outerRadiusPx-c:e.outerRadiusPx+c;else if(t==="inside")u=e.innerRadiusPx+c;else{const m=e.innerRadiusPx-c;u=m>=0?m:e.innerRadiusPx+c}let d=o;if(n!=="center"&&u>0){const m=et("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:Kg({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},Xg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const m of e.layer.data){const{startAngle:h,endAngle:p}=Vn(m),{innerRadius:f,outerRadius:g}=Rn(m);if(h===null||p===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${zg}${y}`,I={startAngle:h,endAngle:p,midAngle:(h+p)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const H=e.measureDataLabel("observation",o,x);V={width:H.width,height:H.height},A=qg({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const H=Ln(e.measureDataLabel,"observation",x),T=H[r];A=jg({wedge:I,placement:r,justify:Tn(n),align:a,offset:i,labelWidth:T.width,labelHeight:T.height}),V=H[A.position]}const j=c+Math.sin(A.labelAngle)*A.labelRadius,ne=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!Yg({x:j,y:ne,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:j,y:ne,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},Zg={place:Xg,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Jg=e=>{const t=C({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=C({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const s=l.getStableKey(i[n]),o=r[s];return o!==void 0?o(a,i):t(a)}},C=e=>{switch(e.valueFormat.type){case"currency":return Xs(e);case"date":return Kf(e);case"datetime":return Yf(e);case"day_month":return eo(e);case"decimal":return Zs(e);case"duration":return fn(e);case"integer":return Js(e);case"month":return to(e);case"month_year":return vn(e);case"percentage":return Qs(e);case"quarter":return bn(e);case"text":return hn(e);case"weekly_date_range":return ro(e);case"weekly_date_range_with_year":return no(e);case"year":return Sn(e);case"time":return ao(e);case"lookup":return Jg({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Cn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:Ri(e),locale:r,numberFormat:t})}var Qg=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:nt(e,t),variable:r}:{read:U,variable:l.GROUP_VARIABLES.group}},mo=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Cn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:ay({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:ey({layer:e,numberFormat:n,locale:s})}},ey=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Qg(e.data,e.mapping),i=C({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return s=>{const o=n(s);return o===null?null:i(o,s)}},ty=(e,t)=>{switch(t){case"stack":return ry(e);case"fill":return ny(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},ry=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const s=a[t];if(s==null)return null;const o=r?.get(sn(a,t));return o===void 0?null:o.total}},ny=e=>{const t=Ke(e);return r=>{const n=F(r),a=M(r);if(!l.isStrictNumericDataValue(n)||!l.isStrictNumericDataValue(a))return null;const i=Math.abs(a-n);if(i===0)return null;const s=t(r);return l.isStrictNumericDataValue(s)?s/i:null}},ay=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=W(e.data,e.dataLabels.labelSource),o=ty(e,i),c=iy({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&po(e);return m=>{const h=s(m);if(h===null)return"";if(!d||!l.isStrictNumericDataValue(h))return c(h,m);const p=o(m);return p===null||p===0?c(h,m):u(h/p)}},iy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(po(e))return a;const o=sy(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:oy(e.data,i),locale:n,numberFormat:t})},po=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Wt(e.position,e.mapping))},sy=(e,t,r,n,a)=>{const i=l.extractVariableName(e.mapping.x);if(i===null||i!==a)return null;const s=t.find(o=>o.scaleAestheticKey==="x");return s===void 0?null:C({valueFormat:s.valueFormat,locale:n,numberFormat:r})},oy=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},kn={bar:{cartesian:Ag,polar:Zg},line:{cartesian:_g},point:{cartesian:Wg},area:{cartesian:bg}},ly=(e,t)=>kn[e]?.[t]!==void 0,cy=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=kn[f]?.[h];if(g===void 0)continue;const y=mo({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)uy(x,h,c,u)||d.push(x)}return{labels:d}},uy=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*dy({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=kn[o.geom]?.cartesian;if(c===void 0)continue;const u=mo({layer:o,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:c.getPercentageValueStrategy(o)});for(const d of c.place(u))yield{x:a.x+d.x-d.width/2,y:a.y+d.y-d.height/2,width:d.width,height:d.height}}}var hr={abbreviation:"none",decimals:"auto"},ho=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":return C({valueFormat:a,locale:e,numberFormat:hr,intlOptions:{signDisplay:"always"}})(n-r);case"relative-difference":{const i=n-r;if(i===0)return"0%";const s=i/r;return s===Number.POSITIVE_INFINITY?"∞":s===Number.NEGATIVE_INFINITY?"-∞":C({valueFormat:{type:"percentage"},locale:e,numberFormat:hr,intlOptions:{signDisplay:"always"}})(s)}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${C({valueFormat:{type:"decimal"},locale:e,numberFormat:hr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},fr=6,gr=6,yr=15,vr=5,br=15,fo=(e,t)=>{switch(e){case"small":return{arrowStartGap:fr,arrowEndGap:gr,offsetFromHigherObservation:yr,arrowheadSize:vr,curveRadius:br,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:fr*1.5,arrowEndGap:gr*1.5,offsetFromHigherObservation:yr*1.25,arrowheadSize:vr*1.5,curveRadius:br*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:fr*2,arrowEndGap:gr*2,offsetFromHigherObservation:yr*1.75,arrowheadSize:vr*2.5,curveRadius:br*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},my=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},py=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x,y:e.y-n},o={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
2
2
  M ${s.x} ${s.y}
3
3
  L ${o.x} ${o.y+i}
4
4
  Q ${o.x} ${o.y} ${o.x+d*i} ${o.y}
package/dist/index.mjs CHANGED
@@ -14,7 +14,7 @@ import { arc as Wu, area as zi, curveCatmullRom as zu, curveLinear as Hu, line a
14
14
  import { getContrast as ua } from "color2k";
15
15
  import { Delaunay as Uu } from "d3-delaunay";
16
16
  import Ui from "lodash-es/isEqual";
17
- typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.8.1-beta.1787147748310");
17
+ typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.8.1-beta.1787149483080");
18
18
  var Ku = 1e6;
19
19
  function re(e) {
20
20
  return String(Math.round(e * Ku));
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "grammar-of-graphics",
12
12
  "compiler"
13
13
  ],
14
- "version": "1.8.1-beta.1787147748310",
14
+ "version": "1.8.1-beta.1787149483080",
15
15
  "type": "module",
16
16
  "sideEffects": [
17
17
  "**/version.ts"