@graphysdk/viz-engine 1.8.1-beta.1786707936521 → 1.8.1-beta.1786950787742
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +248 -247
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Wc=Object.create,ci=Object.defineProperty,Hc=Object.getOwnPropertyDescriptor,zc=Object.getOwnPropertyNames,Kc=Object.getPrototypeOf,Yc=Object.prototype.hasOwnProperty,qc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=zc(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Yc.call(e,o)&&o!==r&&ci(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Hc(t,o))||n.enumerable});return e},Wr=(e,t,r)=>(r=e!=null?Wc(Kc(e)):{},qc(t||!e||!e.__esModule?ci(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-_BpZP1A3.cjs");let ui=require("date-fns"),Ue=require("lodash-es"),ze=require("d3-time"),jc=require("date-fns/differenceInDays"),le=require("d3-regression"),J=require("d3-scale"),Ce=require("d3-interpolate"),D=require("d3-scale-chromatic"),Et=require("lodash-es/merge");Et=Wr(Et,1);let Ar=require("humanize-duration");Ar=Wr(Ar,1);let ge=require("d3-shape"),ra=require("color2k"),Xc=require("d3-delaunay"),Ir=require("lodash-es/isEqual");Ir=Wr(Ir,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1786707936521");var Zc=1e6;function H(e){return String(Math.round(e*Zc))}var na=0;function O(){return na+=1,`${Math.random().toString(36).slice(2,6)}${na.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function E(e){return e[l.POSITION_VARIABLES.y]}function z(e){return e[l.POSITION_VARIABLES.xMin]}function K(e){return e[l.POSITION_VARIABLES.xMax]}function F(e){return e[l.POSITION_VARIABLES.yMin]}function P(e){return e[l.POSITION_VARIABLES.yMax]}function Hr(e){return e[l.POSITION_VARIABLES.yRaw]}function Jc(e,t){return e[l.resolveScaledAestheticVariable(t)]}var Qc={xMin:0,xMax:1,yMin:0,yMax:1},Lr=(e,t)=>{if(t.type==="polar")return null;const r=z(e)??R(e),n=K(e)??R(e),a=F(e)??E(e),i=P(e)??E(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},Ze=(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}}},di=e=>Ze(Qc,e),be=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},mi=(e,t)=>e.yScaleType===t.yScaleType&&wr(e.valueFormat)===wr(t.valueFormat),Tr=e=>`${e.yScaleType} y axis, ${wr(e.valueFormat)}`,wr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,eu=(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 _e(e,t){return e==="x"?t.x:t.y}function Pt(e,t){return e==="x"?t.y:t.x}function tu(e,t){return{main:_e(e,t),cross:Pt(e,t)}}function aa(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function ru(e){return e.type==="cartesian"}var G=e=>e[l.GROUP_VARIABLES.group],Je=(e,t)=>{const r=be(e),n=t[r]??null;if(n===null)return null;const a=r===l.GROUP_VARIABLES.group?null:G(t);return{layerId:e.id,anchorValue:n,...a!==null&&{groupValue:a}}},Pe=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,nu={type:"decimal"};function hi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function pi(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):nu}function fi(e){return pi(e,l.extractVariableName(e.mapping.y))}var au=["stack","dodge","identity","fill"],zr=["solid","dashed","dotted"],gi=e=>zr.includes(e);function M(e){return e==="stack"||e==="fill"}var U=(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},Qe=(e,t)=>U(e,t.x),yi=(e,t)=>U(e,t.y),iu=(e,t)=>U(e,t.label),vi=(e,t)=>U(e,t.color),su=(e,t)=>U(e,t.size),ou=(e,t)=>U(e,t.alpha),lu=(e,t)=>U(e,t.group),cu=(e,t)=>U(e,t.strokeWidth),ia={variable:l.POSITION_VARIABLES.yRaw};function Mt(e,t){return M(e)?ia:t.y??ia}function We(e){return U(e.data,Mt(e.position,e.mapping))}function Nt(e){return e[l.VISUAL_VARIABLES.color]}function Si(e){return e[l.VISUAL_VARIABLES.alpha]}function Kr(e){return e[l.VISUAL_VARIABLES.size]}function Er(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function bi(e){return e[l.VISUAL_VARIABLES.lineType]}var Vr=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},xi=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(be(e)));return n=>({...n,anchorValue:Vr(n.anchorValue,r,t),...n.groupValue!==void 0&&{groupValue:Vr(n.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)}})},Ai=e=>{const t=l.extractVariableName(e.mapping.y),r=We(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},uu=["lt","lte","gt","gte","range"],du={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"}},ee=()=>!1,Le=()=>!0;function Bt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Ai(e),parsingLocale:t}}function me(e,t){if("and"in e){const r=e.and.map(n=>me(n,t)).filter(n=>n!==Le);return r.includes(ee)?ee:r.length===0?Le:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>me(n,t)).filter(n=>n!==ee);return r.includes(Le)?Le:r.length===0?ee:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=me(e.not,t);return r===ee?Le:r===Le?ee:n=>!r(n)}return hu(e,t)}function he(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>he(n,t,r)):"or"in e?e.or.flatMap(n=>he(n,t,r)):"not"in e?he(e.not,t,r):mu(e,t,r)}function mu(e,t,r){const{subject:n,effect:a}=du[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=pu(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 hu(e,t){if(!t.hasVariable(e.variable))return ee;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Vr(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=>Te(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=Te(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Te(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=Te(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=Te(u,s),m=Te(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return ee}function pu(e){for(const t of uu)if(t in e)return t;return null}function Te(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 fu=(e,t,r,n,a,i)=>{const s=Li(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Ii(r.padding),c=o===null?vu(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}},gu=(e,t,r,n,a,i)=>{const s=Li(e,t,r.predicate,n,a,i);return s===null?null:Ze(s,r.align)},Ii=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Li=(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=he(r,u.data,"selection-anchor");if(d.length>0){for(const h of d)c.set(`${h.code}:${h.message}`,h);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const p=me(r,Bt(u,i));if(p!==ee)for(const h of u.data){if(!p(h))continue;const f=m(h,a);f!==null&&(s=s===null?f:yu(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},yu=(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)}),vu=(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}},Vt=(e,t,r)=>{const n=bu(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:xu(n,t.offset,e.coordSystem)},Ti=(e,t)=>t.anchorType==="selection"?fu(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},Yr=(e,t,r)=>Rr(e,t,r)?.point??null,Rr=({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=We(s),u=be(s),{anchorValue:d,groupValue:m}=xi(s,n)(a);let p=-1;for(const h of s.data){if(p+=1,!l.areDataValuesEqual(h[u]??null,d)||m!==void 0&&!l.areDataValuesEqual(G(h),m))continue;const f=o(h,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(f===null)continue;const g=wi(s,h,c);if(g===null)continue;const y=Je(s,h);if(y!==null)return{point:{...f,...g,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id,observationIndex:p}}}return null},Su=(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=oa(t.x,"x",r,i),u=oa(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!Pe(d,m))return null;const p=sa(d,s,Au(e)),h=sa(m,o),f=aa(n.mainAxis,{main:p.min,cross:h.min}),g=aa(n.mainAxis,{main:p.max,cross:h.max});return Ze({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},wi=(e,t,r)=>{const n=r(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:eu(fi(e),t),yScaleType:e.yScaleType,color:Nt(t)}:null},bu=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Su(e,t);case"selection":return gu(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 Yr(e,Iu(t),r)}},xu=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ii(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},sa=(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}},Au=({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},Iu=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align}),oa=(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},Lu=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:Pu(s,t.differenceArrows),shapes:Vu(s,t.shapes),arrows:Cu(s,t.arrows),textAnnotations:ku(s,t.textAnnotations),images:Ru(s,t.images),stickers:Du(s,t.stickers),pinnedNumbers:Ou(s,t.pinnedNumbers),comments:_u(s,t.comments)};return Tu(this.container,o),wu(this.container,o),o}},Ei=(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,Q=(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."})},Tu=(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)}},wu=(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 Eu(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."})},Eu=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},Vu=(e,t)=>{const r=[];for(const n of t){const a=Ti(e,n.region);if(a===null){Q(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},Ru=(e,t)=>{const r=[];for(const n of t){const a=Ti(e,n.region);if(a===null){Q(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},Cu=(e,t)=>{const r=[];for(const n of t){const a=Vt(e,n.start,"pin"),i=Vt(e,n.end,"pin");if(a===null||i===null){Q(e.container,"arrow",n.id,`has ${Vi(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},ku=(e,t)=>{const r=[];for(const n of t){const a=Vt(e,n.at,"pin");if(a===null){Q(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},Du=(e,t)=>{const r=[];for(const n of t){const a=Vt(e,n.at,"pin");if(a===null){Q(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},Ou=(e,t)=>{const r=[];for(const n of t){const a=Yr(e,n.at,"pin");if(a===null){Q(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},_u=(e,t)=>{const r=[];for(const n of t){const a=Yr(e,n.at,"pin");if(a===null){Q(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Pu=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)Q(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Rr(e,n.start,"value"),i=Rr(e,n.end,"value");if(a===null||i===null){Q(e.container,"differenceArrow",n.id,`has ${Vi(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.observationIndex===i.observationIndex){Q(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Mu(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,color:Ei(n.color,a.point,i.point),ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Vi=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Mu=(e,t,r,n)=>{mi(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:Tr(r),actual:Tr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Ri(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 ki(e,t)}function T(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 Ci(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function qr(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 ki(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=ki(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 Ft(e){return{pipe:t=>{const r=t(e);return Ft({...e,...r})},result:()=>e}}function Nu(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:Di(i),values:i};return new l.Dataset(n)}function Di(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 Bu=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,Di(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Fu=(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},xe=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)}},$u=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)}},Gu=class extends xe{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}},Uu=class{constructor(e){this.setupStage=new $u(e),this.transformStage=new Gu(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)}},Wu=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}},Hu=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:Ku(e.scales,e.layers)}}transform(e){return e.layers.map(t=>qu(t))}},zu=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],la=l.prefixInternalVariable("flipSwap"),Ku=(e,t)=>Yu(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Yu=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},qu=e=>{let t=e.data;for(const[r,n]of zu){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,la).renameVariable(n,r).renameVariable(la,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},pe=Math.PI*2,ju=8,Xu=1e-9,Oi=(e,t)=>Math.abs(t-e)>=pe-Xu,Me=e=>(e%pe+pe)%pe,_i=(e,t,r)=>{if(Oi(t,r))return!0;const n=Me(r-t);return Me(e-t)<=n},Rt=(e,t)=>{const r=Math.abs(Me(e)-Me(t));return Math.min(r,pe-r)},Pi=(e,t,r)=>e*pe+t+r,Ct=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Mi=(e,t)=>({angle:Me(Math.atan2(e,t)),radius:Math.hypot(e,t)}),jr=(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}},$t=(e,t)=>{const{x:r,y:n}=jr(e,t);return Mi(r,n)};function Ni(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 Bi=(e,t)=>Ni(t.domain!==null&&t.domain.length>0?t.domain:e),Zu=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=ed(t,e.scales,e.layers),a=rd(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=Qu(r,n),i=nd(t);return e.layers.map(s=>ad(t.theta==="y"?id(s):s,a,i))}},Ju=[[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 Qu(e,t){return r=>Pi(r,e,t)}function ed(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=td(n,e,r);return a===0?0:-Math.PI/a}function td(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 Bi(n,e).length}function rd(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 nd(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function ad(e,t,r){let n=e.data;return n=we(n,l.POSITION_VARIABLES.x,t),n=we(n,l.POSITION_VARIABLES.xMin,t),n=we(n,l.POSITION_VARIABLES.xMax,t),n=we(n,l.POSITION_VARIABLES.y,r),n=we(n,l.POSITION_VARIABLES.yMin,r),n=we(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function we(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 id(e){let t=e.data;for(const[r,n]of Ju){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 sd=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Wu),this.register("flip",new Hu),this.register("polar",new Zu)}},od=new Set(["min","max","scalar"]),ld={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function cd(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 ud(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 dd(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=ld[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 md=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:dd(n.data,r.positionRoles,a)}}},Xr=["x","y"],Fi=new Set(["x","y","ySecondary"]),Gt=new Set(["color","size","alpha","strokeWidth","lineType"]),et=e=>Fi.has(e),Zr=e=>Gt.has(e),hd=e=>et(e)||Zr(e);function ne(e){return e==="secondary"?"ySecondary":"y"}function $i(e,t){return e==="y"?ne(t):"x"}function N(e){return e==="ySecondary"?"y":e}var He=(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 Gt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},Ut=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:He(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),pd=class{compute({data:e,mapping:t}){const r=He(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)}}},fd=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},gd=(e,t,r)=>{const n=ye(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function ye(e,t){const r=N(t);for(const n of Gi(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var Jr=(e,t)=>e===null?null:t[e]??e,yd=(e,t)=>e===null?null:t[String(e)]??null,ve=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return nr(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 Sd(i,t)?i:nr(t)}return nr(t)},vd=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Gi(t,e).some(r=>r.position==="fill");function Gi(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var nr=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Sd=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},bd=[{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}],ca={year:0,quarter:1,month:2,week:3,day:4,hour:5},Ee=40,xd=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Td(r.unit).range(e,new Date(t.valueOf()+1),n)},Ad=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jc.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Ee;case"day":return a/t>Ee;case"week":return a/(7*t)>Ee;case"month":return a/(30*t)>Ee;case"quarter":return a/(90*t)>Ee;case"year":return a/(365*t)>Ee}},Id=(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"}}},Ld=(e,t)=>{const r=wd(t);return r===null?!1:ca[e]>ca[r]},Td=e=>{switch(e){case"hour":return ze.utcHour;case"day":return ze.utcDay;case"week":return ze.utcMonday;case"month":case"quarter":return ze.utcMonth;case"year":return ze.utcYear}},wd=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}},Ui={left:"right",right:"left",top:"bottom",bottom:"top"},Ed={x:!0,y:!0,ySecondary:!1},Vd=20,ua=new Set(["top","bottom"]),Rd={type:"percentage"};function Cd(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(hi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Od(o,a,i.type,n),u=new Set(t.map(p=>p.position)),d=Pd(Wi(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const p of Fi){const h=r[p];if(!l.isDefined(h)||h.kind!=="position")continue;const f=kd({scaleAestheticKey:p,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function kd(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}=_d(t,n,i,s),p=ye(a,t),h=vd(a,t)?Rd:ve({layers:a,scaleType:r.spec.scaleType,variableName:p});return{scaleAestheticKey:t,position:d,geometry:m,label:Dd(u,p,c),isVisible:u.isVisible,tickCandidates:Nd(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Md(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Dd(e,t,r){return e.label?e.label:t?r[t]??null:null}function Od(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:da(i,n.axes.x.grid.isVisible)},y:{gridVisible:da(s,n.axes.y.grid.isVisible)}}}function da(e,t){if(e&&t===null)return!1}function _d(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Wi(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=Ui[n],i=(0,Ue.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 Wi(e,t){return ua.has(e)===ua.has(t)?e:t}function Pd(e,t){return t.has(e)?Ui[e]:e}function Md(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Ed[r]}var Nd=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Fd(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Vd;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Ne(e,u))}))}return i}return e.spec.scaleType==="datetime"?Bd(e,t):[{ticks:e.generateTicks().map(a=>Ne(e,a))}]},Bd=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Ne(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=>Ne(e,d)),valueFormat:c}))};for(const o of bd)Ad({...o,start:r,stop:n})||Ld(o.unit,t)||s(e.generateTicks({interval:o}),Id(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},Fd=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:[Ne(e,r),Ne(e,n)]}},Ne=(e,t)=>({value:t,position:e.map(t)});function Hi({scale:e,aesthetics:t,layers:r}){const n=$d({layers:r,aesthetics:t}),a=zi({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function $d({layers:e,aesthetics:t}){const r=zi({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 zi({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 Qr=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Gd({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!Qr(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=ye(t,"color");if(Ki({colorVariableName:a,xVariableName:ye(t,"x"),mapsColorAcrossMultipleLayers:Wd(t)>1,isMergedWithAnotherAesthetic:Ud(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return Hi({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],p=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:ve({layers:m?[m]:t,scaleType:i,variableName:p}),label:yd(o,r)}})}var Ki=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Ud(e,t,r){if(r===null)return!1;for(const n of Gt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!Qr(a))&&ye(t,n)===r)return!0}return!1}var Wd=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Yi(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Hd(e,t,r,n){const a=r.findIndex(i=>Yi(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Jr(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 ma(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 qi=e=>e==="none"?"first":e,zd=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=ha(e);return n===0?null:r}case"average":{const{sum:r,count:n}=ha(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Kd=(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}},ha=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Yd(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?qd(e,n):jd(e,n)}function qd(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:ve({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function jd(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>Yi(o,d)))return null;const c=Hd(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>Xd({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 Xd({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=ve({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=Qd(i.data,o),p=ve({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),h=em(i.data,o),f=h.getValues(s,{type:"numeric"}),g=o!==null?h.getValues(o):[],y=c!==null?h.getValues(c):null,v=ma(f,y,e.value),x=ma(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:zd(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:p,label:e.label,observationLabel:Zd(t,m,x),comparison:Jd(t,r,m,x,v)}}function Zd(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 Jd(e,t,r,n,a){return e!=="current"||!r?null:Kd(n.map((i,s)=>({main:i,cross:a[s]??null})),qi(t))}function Qd(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function em(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function Y(e,...t){return e?t.includes(e.geom):!1}function k(e,t){return e.find(r=>r.id===t)}function ae(e,...t){return e.find(r=>t.includes(r.geom))}function tm(e,...t){return e.filter(r=>t.includes(r.geom))}function en(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function tn(e){const t=e.filter(r=>!en(r,e));return t.length>0?t:e}function ji({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=tn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var rm=3;function nm({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=dm(om({scales:e,layers:r})),u=ye(r,"x"),d=c.map(y=>{if(cm(y,u,r))return null;const v=hm({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=am(d),p=tn(r),h=Sm(s,t.legend.position,m,p,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&vm(s,m,p,n))return{drawn:[],position:h};const f=bm(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),g=f==="direct"?Lm(p[0]):null;return{drawn:d.map(({built:y})=>im(y,{position:h,display:f,align:t.legend.align},g)),position:h}}function am(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function im(e,t,r){const{position:n,display:a}=t,i=sm(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 sm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function om(e){const{scales:t,layers:r}=e,n=[];for(const a of Gt){const i=t[a];if(i===void 0||i.kind==="identity"||!lm(a,r))continue;const s=ye(r,a),o=Im(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function lm(e,t){const r=N(e);return t.some(n=>l.isDefined(n.mapping[r]))}function cm(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Ki({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:um(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function um(e,t){const r=N(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function dm(e){const t=new Map;for(const r of e){const n=Am(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function mm(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function hm({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>N(c.scaleAestheticKey)),s=Hi({scale:a.scale,aesthetics:i,layers:r}),o=ve({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:Jr(a.variableName,t),items:s.map(c=>pm(c,e,i,o,n))}}function pm(e,t,r,n,a){const i={};for(const o of t)mm(i,o.scaleAestheticKey,o.scale.map(e.value));const s=gm(e,t,r,n,a);return{value:e.value,label:fm(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function fm(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function gm(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=ym(i,r);return i===void 0||s===null?n:ve({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function ym(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 vm(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 Sm(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,M(u.position)&&(o=!0))}const c=r>=rm;return i&&s?"top":i?c?"right":"top":o?xm(a)?"top":c?"right":"top":"top"}function bm(e,t){return e==="pill"?"pill":ji(t)?"direct":"pill"}function xm(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Am(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Im(e,t){return Qr(t)?"discrete":`continuous:${e}`}function Lm(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(P(c))||l.isDefined(E(c)));if(!n)return;const a=G(n);if(!l.isDefined(a))return;const i=F(n),s=P(n)??E(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var Tm=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=fd(e.originalData),r=Gd({scales:e.scales,layers:e.layers,valueLabels:gd(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=Yd(n),i=nm(n),s={...i,drawn:wm(a,i.drawn)};return{axes:Cd(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},wm=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Em=e=>l.getStableKey([G(e)]),rn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Vm=e=>e!=="data-point",kt=(e,t,r)=>{switch(e){case"series":return Em(t);case"x-value":return rn(t,r)}},Rm={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor"};function Xi(e){const t=Rm[e]??null;return t===null?null:{strategy:t,composition:Zi()}}function Zi(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Cm=class extends xe{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=km({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function km({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(L=>{const j=he(L.predicate,e.data);for(const X of j)a.diagnostics.addWarning({...X,message:`${X.message} Dropping this highlight.`});return j.length===0}),s=l.extractVariableName(e.mapping.x),o=Bt(e,r),c=i.map(L=>({predicate:me(L.predicate,o),scope:L.scope})),u=c.some(({scope:L})=>L==="series"),d=c.some(({scope:L})=>L==="x-value"),m=n==="overlay-anchor",p=e.data.size(),h=u?new Array(p):null,f=d?new Array(p):null,g=m?new Array(p):null,y=new Uint8Array(p),v=new Set,x=new Set;let I=!1,A=0;for(const L of e.data){let j,X;h!==null&&(j=kt("series",L,s),h[A]=j),f!==null&&(X=kt("x-value",L,s),f[A]=X),g!==null&&(g[A]=L);for(const{predicate:dt,scope:mt}of c)if(dt(L))switch(mt){case"series":j!==void 0&&v.add(j);break;case"x-value":X!==void 0&&x.add(X);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return Zi();const V=new Uint8Array(p),q=[];let re=0;for(let L=0;L<p;L++){const j=h?.[L],X=f?.[L],dt=j!==void 0&&v.has(j),mt=X!==void 0&&x.has(X),ea=y[L]===1;if(n==="observation-rerender")(dt||ea||mt)&&(V[L]=1,re++);else if(dt)V[L]=1,re++;else if(ea||mt){const ta=g?.[L];ta!==void 0&&q.push({observation:ta,observationIndex:L})}}const W=re>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&W!==null,matchedLayer:W,overlayCandidates:q}}var Dm=l.prefixInternalVariable("__ungrouped__");function Om(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]??Dm;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 _m=()=>({defaults:[],overrides:[],warnings:[]}),Pm=class extends xe{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,pa(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,pa(t))}runLayerPipeline(e,t,r,n){const a=Ft({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:Om(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:Xi(e.geom),styles:_m()}}};function pa(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Ji(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}var Mm=new Set(["label","group"]),Nm=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)}),Ji(this.container.diagnostics,t)}checkPostCompile(e){hi(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(!Ut(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=[...cd(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,p]of Object.entries(a)){if(u.has(m))continue;const h=l.extractVariableName(p);h===null||h===""||d.has(h)||i.hasVariable(h)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${h}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:h}})}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(!od.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 p=i.getType(m);p!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${p}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:p},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([...ud(i),...s.map(p=>p.name)]),u=Mm,d=o,m=[];for(const p of Object.keys(a))l.isDefined(a[p])&&(c.has(p)||u.has(p)||d.has(p)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return m}},ie=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,Ue.merge)({},this.defaultParams,e.params)}},nn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},an=(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}},Bm=class extends ie{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=an}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=nn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},fa=.7,Fm=.1,Qi=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},$m=class extends ie{constructor(...e){super(...e),this.type="bar",this.defaultParams={width:fa},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=Lr,this.resolveDataLabelDefaults=t=>M(t)?{justify:"center"}:{},this.resolveBandFraction=t=>t.width,this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Gm(t);if(i!==void 0){const m=Lr(t,r);return m===null?null:Ze(m,i)}const s=M(n),o={isSolo:!s||Qi(t)==="solo",isNegative:s&&Um(t),purpose:a};if(r.mainAxis==="x"){const m=z(t),p=K(t),h=ga({lowerBound:F(t),upperBound:P(t)??E(t),options:o});return m===null||p===null||h===null?null:{x:(m+p)/2,y:h}}const c=F(t),u=P(t),d=ga({lowerBound:z(t),upperBound:K(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=nn(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:fa;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}},Gm=e=>{const t=z(e),r=K(e),n=F(e),a=P(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)}},Um=e=>{const t=Hr(e);return l.isStrictNumericDataValue(t)&&t<0},ga=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},Wm=class extends ie{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=Lr,this.resolveAnchorPosition=an}compile(e){return{data:nn(e.data,e.mapping),mapping:{}}}},Hm=class extends ie{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=an,this.resolveDefaultLabelSource=t=>{const r=l.extractVariableName(t.size);return r!==null?{variable:r}:null}}compile({data:e}){return{data:e,mapping:{}}}},zm=class extends ie{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=ya(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=ya(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}}}},ya=(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},Km=[new $m,new Hm,new Wm,new Bm,new zm],Wt=class extends l.Registry{constructor(){super("geom");for(const e of Km)this.register(e.type,e)}},Ae=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},Ym=class extends Ae{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,...He(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},qm=class extends Ae{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},jm=class extends Ae{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}}}},Xm=2,es=1440*60*1e3,Zm=class extends Ae{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=He(e,t),u=ah(a,s,i,c,e);return c.length===0?va({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=ih(d,c);va({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},va=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=Jm({data:e,xVariable:t,yVariable:n,xType:r});c.length<Xm||(o?nh({observations:c,spec:a,output:i,groupObservation:s}):th({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},Jm=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Qm(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 p=eh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});p!==null&&o.push({x:p,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},Qm=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},eh=({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)/es+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}`})}},th=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=ts(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?rh(o,r):o;a.push({x:u,y:c,groupObservation:i})}},rh=(e,t)=>t===null?new Date(e):new Date((e-1)*es+t),nh=({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=ts(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=rs(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})}},ts=(e,t)=>e.method==="loess"?(0,le.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):rs(e,t),rs=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,le.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,le.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,le.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,le.regressionQuad)().x(r).y(n)(t);case"power":return(0,le.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,le.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},ah=(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)}}},ih=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},sh=class extends Ae{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],...He(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},oh=[new qm,new Ym,new Zm,new jm,new sh],lh=class extends l.Registry{constructor(){super("stat");for(const e of oh)this.register(e.type,e)}};function ch({geoms:e,stats:t,transforms:r}){const n=new Wt,a=new lh,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 sn(e){if("definition"in e)return e.definition;if(as(e)||is(e)||ss(e))return e}function ns(e){const t=[],r=[],n=[];for(const a of e){const i=sn(a);i&&(as(i)?t.push(i):is(i)?r.push(i):ss(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...ar("geom",t,a=>a.type),...ar("stat",r,a=>a.type),...ar("transform",n,a=>a.transformType),...uh(t)]}}function uh(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 ar(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 as=e=>e instanceof ie,is=e=>e instanceof Ae,ss=e=>"transformType"in e&&typeof e.apply=="function",dh=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Ht=class{},mh=class extends Ht{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=hh(e)??[-.7/2,.7/2],s=r.length>1?Fm:0,o=(0,J.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 p=a[m];if(!l.isDefined(p))continue;const h=o(String(p));l.isDefined(h)&&(u[m]=h,d[m]=h+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},hh=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]},Sa=l.prefixInternalVariable("__ungrouped__"),os=(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?[Sa]: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 p=0;p<d;p++){const h=l.getStableKey(o[p]??null),f=u[p],g=i?Sa:f;if(!l.isDefined(g))continue;let y=m.get(h);y||(y=new Map,m.set(h,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(p)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},ls=(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,p=-1/0;for(const h of i.values())for(const f of h){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>p||y===p&&g<m)&&(d=f,m=g,p=y))}for(const h of s)a[h]=ph(h===o,h===d)}return a},ph=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",fh=class extends Ht{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=os(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,p=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:p-=x)}}let h=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:p;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=h,o[v]=h+=A):(o[v]=f,c[v]=f+=A)}}}const u=ls(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:{}}}},gh=class extends Ht{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},yh=class extends Ht{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=os(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[,p]of a){let h=0,f=0;for(const g of i){const y=p.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]=h,o[v]=h+=x):(o[v]=f,c[v]=f+=x)}}}}const u=ls(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:{}}}},vh=class extends l.Registry{constructor(){super("position"),this.register("identity",new gh),this.register("stack",new yh),this.register("fill",new fh),this.register("dodge",new mh)}},Sh=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)||Zr(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r($i(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}},bh=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)}},xh=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],p=i[d],h=s[d];if(l.isDefined(m)&&l.isDefined(p)&&l.isDefined(h)){const f=n?-h:p,g=n?-p:h;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)}},Ah=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(ne(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)}},Ih=class{map({data:e,layer:t,getPositionScale:r}){const n=r(ne(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)}},Lh=[new bh,new Ah,new xh,new Ih,new Sh];function Th(e,t){const r=e[t];return r?.kind==="position"?r:null}var wh=class extends xe{constructor(e,t=Lh){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=>Th(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}}},Eh=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})}}Ji(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"?ne(n.yScaleType):i,c=a.get(i)??(hd(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)||Zr(n.aes)||t.set(n.aes,$i(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)}},Vh=["rgb","lab","hcl","hsl"],Rh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],cs=["RdBu","BrBG","PuOr","Spectral"],us={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Ch=new Set(cs.map(e=>e.toLowerCase()));function ds(e){const t=e.toLowerCase(),r=us[t];return r?r.toLowerCase():t}function kh(e){return Ch.has(ds(e))}var Dh={rgb:Ce.interpolateRgb,lab:Ce.interpolateLab,hcl:Ce.interpolateHcl,hsl:Ce.interpolateHsl},Oh={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 on(e){const t=Ph(e);return e.reverse?r=>t(1-r):t}function _h(e={},t=2){const r=on({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 Ph(e){const t=Dh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ce.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Oh[ds(e.scheme)];if(r)return r}return(0,Ce.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var tt=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}}},Mh=class extends tt{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=et(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"&&Nh(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,J.scaleLog)():r.transform==="sqrt"?(0,J.scaleSqrt)():(0,J.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=Bh(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=on(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,J.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,J.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]}},Nh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Bh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Fh=class extends tt{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=et(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=$h(e)?e:[],a=(0,J.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?xd(i,s,c.interval):[]:a.ticks(c?.count)})}},$h=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Gh=class extends tt{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=et(e.scaledAesthetic),n=Bi(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,J.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,J.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})}},Uh=class extends tt{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:()=>[]}}},Wh=class extends tt{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=Ni(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,J.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},Hh=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Mh(e)),this.register("discrete",new Gh),this.register("datetime",new Fh),this.register("identity",new Uh),this.register("palette",new Wh)}},bt={color:null,size:"small",labelCrossPosition:.5},ce={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},ir={zOrder:"foreground",fit:"contain",opacity:1},zh={x:8,y:8,unit:"px"},xt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},ue={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Kh={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}},Yh=(e,t,r)=>{const n=qh(e,t),a=Zh(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Qh(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>np(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>sp(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>Jh(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>ep(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>ap(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>tp(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>rp(e,i,r)).filter(l.isDefined)}},qh=(e,t)=>{if(t===void 0)return{};if(!jh(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))}},jh=e=>{const t=new Set;for(const r of Xh(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},Xh=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Zh=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},ln=(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},Jh=(e,t,r,n)=>{const a=Dt(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??xt.align,backgroundColor:t.backgroundColor??xt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??xt.backgroundColorStyle}},Qh=(e,t,r)=>{const n=je(e,t.start,r),a=je(e,t.end,r);return n===null||a===null?null:{id:t.id??O(),start:n,end:a,label:t.label,color:t.color??bt.color,size:t.size??bt.size,labelCrossPosition:t.labelCrossPosition??bt.labelCrossPosition}},je=(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)},Dt=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return ln(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=je(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},ep=(e,t,r,n)=>{const a=Dt(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),at:a,sticker:t.sticker}},tp=(e,t,r)=>{const n=je(e,t.at,r);return n===null?null:{id:t.id??O(),at:n}},rp=(e,t,r)=>{const n=je(e,t.at,r);return n===null?null:{id:t.id??O(),at:n,content:t.content}},np=(e,t,r)=>t.region.anchorType==="annotation"&&!ln(e,t.region.ref,r,t.id)?null:{id:t.id??O(),kind:t.kind??ce.kind,zOrder:t.zOrder??ce.zOrder,region:ip(t.region),fillColor:t.fillColor===void 0?ce.fillColor:t.fillColor,fillOpacity:t.fillOpacity??ce.fillOpacity,strokeWidth:t.strokeWidth??ce.strokeWidth,strokeColor:t.strokeColor??ce.strokeColor},ap=(e,t,r)=>t.region.anchorType==="annotation"&&!ln(e,t.region.ref,r,t.id)?null:{id:t.id??O(),src:t.src,zOrder:t.zOrder??ir.zOrder,region:t.region,fit:t.fit??ir.fit,opacity:t.opacity??ir.opacity},ip=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:zh},ba=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=Kh[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},sp=(e,t,r,n)=>{const a=Dt(e,t.start,r,n,t.id),i=Dt(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??O(),start:ba(a),end:ba(i),color:t.color??ue.color,thickness:t.thickness??ue.thickness,startArrowheadStyle:t.startArrowheadStyle??ue.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??ue.endArrowheadStyle,lineStyle:t.lineStyle??ue.lineStyle,hasStickerStyle:t.hasStickerStyle??ue.hasStickerStyle}},op={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 lp(e){const t=(0,Ue.merge)({},op,e);return t.content=cp(t.content,e?.content),t}var cp=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},up={xLimits:null,yLimits:null},At={theta:"x",startAngle:0,innerRadius:0},zt=(e,t,r)=>Math.min(r,Math.max(t,e));function Cr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Et.default)({},up,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??At.theta,startAngle:t.params?.startAngle??At.startAngle,innerRadius:zt(t.params?.innerRadius??At.innerRadius,0,1)}}}}function dp(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 mp=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=xa(e.filter(n=>n.severity==="error")),r=xa(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},hp=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 xa(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var pp={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 ms(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 rt(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new hp(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=vp({dataLabels:bp(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return yp({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??O(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:ms(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 fp(e,t,r,n,a){const i=n.map((s,o)=>rt(e,t,r,s,a,o));return hs(e,i)}var gp=(e,t,r,n)=>n.label!==void 0?n.label:xp(e,t,r,n),hs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:qr(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,Ue.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},yp=({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&&M(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."})},vp=({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=Sp(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}},Sp=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&M(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,bp=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=gp(e,r.geom,n,i),o=e.get(r.geom);return{...(0,Ue.merge)({},pp,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},xp=(e,t,r,n)=>e.get(t).resolveDefaultLabelSource?.(n)??Mt(r,n);function kr(e,t){const r=Ap(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?ne(n.yScaleType):null,niceZeroAxis:n.position!=="fill"}}function Ap(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 ps={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ip={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function fs(e,t,r,n,a,i){switch(t.scaleType){case"inferred":return fs(e,wp(e,t,r,n,a),r,n,a,i);case"continuous":{const s=ps[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:Ep(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 gs(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 Lp(e,t,r,n,a,i,s){const o=Cp(Rp(r,n)),c=new Map;for(const d of o)c.set(d.scaledAesthetic,d);const u=[...c.values()].map(d=>fs(e,d,t,n,a,s));return i.coordType==="polar"?Tp(u):u}function gs(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 Tp=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t);function wp(e,t,r,n,a){const i=N(t.scaledAesthetic),s=t.scaledAesthetic==="ySecondary"?Vp(n,a):a[i],o=kr(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=ps[t.scaledAesthetic];switch(Ip[u][d]){case"discrete":return l.discrete(t.scaledAesthetic,t.options);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 Ep(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)&&kh(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 Vp(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function Rp(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Cp(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var kp=e=>{const t=new Set;e!==void 0&&ys(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},ys=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])ys(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function Dp(e,t,r){const n=Cr(t.coords),a=fp(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Lp(e,t.data,t.scales,a,t.mapping,n,r),s=lp(t.config),o=dp(e,t.highlights,a),c=Yh(e,t.annotations,a),u=kp(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 vs=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return Dp(this.container,{...e,data:t},r)}},Op=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})}},_p=class extends xe{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Kp(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of Yp(e.styles))this.container.diagnostics.addWarning(r);for(const r of qp(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=ws({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},ke={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ss={bar:{...ke,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...ke,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...ke,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...ke,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Aa=1,Ia=1e3,ht={color:"color",strokeWidth:"pixels",lineType:"lineType"},sr={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},It={panelBorder:{...ht,borderRadius:"pixels"},panelBorderEdge:ht,gridLine:ht,tickLine:{...ht,length:"pixels"},axisLabel:sr,tickLabel:{...sr,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...sr,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"}},Pp=new Set([...Object.keys(ke),...Object.values(Ss).flatMap(e=>Object.keys(e??{})),...Object.values(It).flatMap(e=>Object.keys(e))]),bs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph"],Mp=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Np=(e,t,r="en-US")=>ws({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Bp=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 xs(e.styles)}},xs=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(Kt(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!Fp(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 ${bs.map(h=>`'${h}'`).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 h=m.edge;if(h!==void 0&&!Gp(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(h)}'.`,context:{param:"edge",actual:String(h),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Mp.has(m.target)){const h=m.axis;if(h!==void 0&&!Hp(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(h)}'.`,context:{param:"axis",actual:String(h),...u},suggestion:`Set 'axis' to one of ${Xr.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const h=m.layer;if(h!==void 0&&typeof h!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${Be(h)}.`,context:{param:"layer",actual:Be(h),...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 h=m.role;if(h!==void 0&&!Up(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(h)}'.`,context:{param:"role",actual:String(h),...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(!Wp(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(h===void 0||h==="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 p=cn({declarations:i.declarations,vocabulary:$p(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(p).length!==0&&n[m.target][s].push({select:m,declarations:p,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},Kt=e=>e.select.target==="geom",Fp=e=>{const t=e.select.target;return t!=="geom"&&bs.includes(t)},As=e=>(e!==void 0?Ss[e]:void 0)??ke,$p=e=>e.target==="panelBorder"?e.edge===void 0?It.panelBorder:It.panelBorderEdge:It[e.target],Gp=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),Up=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),Wp=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Hp=e=>typeof e=="string"&&Xr.includes(e),zp=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!Kt(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=cn({declarations:a.declarations,vocabulary:As(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},Is=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},Kp=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Is(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},Yp=e=>{const t=[];return Is(e,(r,n,a)=>{if(!Kt(r))return;const i=r.when?.state;i===void 0||Ls(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},Ls=e=>l.STYLE_STATES.includes(e),qp=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Ts(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Be(n)}.`,context:{param:"tokens",actual:Be(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ts=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,pt=e=>typeof e=="number"&&Number.isFinite(e),Be=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),ws=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Bt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((p,h)=>{if(!Kt(p))return;const f=p.select.kind;if(f!==void 0&&f!==t.geom||p.select.layer!==void 0&&p.select.layer!==t.id)return;const g=p.when?.state;if(g!==void 0&&!Ls(g))return;const y={list:d,index:h,...p.id===void 0?{}:{id:p.id}},v=p.when?.where;if(v!==void 0){const I=he(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${h}]: ${A.message}`,context:{...A.context,layerIndex:r,...p.id===void 0?{}:{styleEntryId:p.id}}});return}}const x=cn({declarations:p.declarations,vocabulary:As(f),tokens:o,location:`${d}[${h}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:me(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...zp(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},cn=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=(h,f)=>{o[h]=f},d=(h,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${h}' ignored: expected ${f}, got ${Be(g)}.`,context:{param:h,expected:f,actual:Be(g),...c},suggestion:`Set '${h}' to ${f}.`})},m=(h,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(h,"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 '${h}' ignored: unknown token '${f.token}'.`,context:{param:h,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Ts(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(h,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},p=h=>{const f=Pp.has(h);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${h}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:h,...c},suggestion:f?`Declare '${h}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${h}'.`})};for(const h of Object.keys(t)){const f=t[h];if(f===void 0)continue;const g=r[h];if(g===void 0){p(h);continue}switch(g){case"color":{const y=m(h,f);y!==void 0&&u(h,y);break}case"unitInterval":pt(f)&&f>=0&&f<=1?u(h,f):d(h,"a number in [0, 1]",f);break;case"pixels":pt(f)&&f>=0?u(h,f):d(h,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(h,f):d(h,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":gi(f)?u(h,f):d(h,`one of ${zr.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(h,f):d(h,"a non-empty CSS font-family list",f);break;case"fontWeight":pt(f)&&f>=Aa&&f<=Ia?u(h,f):d(h,`a number in [${Aa}, ${Ia}]`,f);break;case"multiplier":pt(f)&&f>0?u(h,f):d(h,"a positive multiple of the font size",f);break;default:break}}return o},jp=({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}},Xp=({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=P(a),c=z(a),u=K(a),d=Hr(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 p=rn(a,t),h={yMin:s,yMax:o},f=r.get(p);if(f===void 0){r.set(p,{total:d,topPositive:m?h:null,bottomNegative:m?null:h,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=h):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=h)}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},Zp=class extends xe{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=Xp({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=jp({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Jp=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)}},La={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Qp=["color","size","alpha","strokeWidth","lineType"],ef=class extends xe{dependencies(e){return Qp.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.deriveVariable(i,La[a],()=>s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];if(!c||c.kind!=="visual")continue;const u=tf(o,c);u&&(r=r.deriveVariable(i,La[a],u))}return{...e,data:r}}},tf=(e,t)=>e?r=>l.isDefined(r[e])?t.map(r[e]):null:null;function rf(e=new Wt){return{diagnostics:new mp,geomRegistry:e}}var Es=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,p,h,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=p,this.chromeStylesCompiler=h,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=Fu(e.spec.data,e.spec.mapping);return this.runPipeline({spec:T(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:[Ri(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 Ft({spec:e}).pipe(({spec:t})=>({spec:T(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:T(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()}},nf=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],af=({plugins:e=[]}={})=>{const t=ns(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=ch(t),i=rf(r),s=new Hh(i),o=new Jp(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new Es(i,new l.DataCompiler,new vs(i),o,new Bu,new Nm(i,o,n,new Pm(i,o,new Op(n),new pd,new md(i),new dh(new vh))),new Eh(i,s),new Uu(new sd),new wh(i),new ef,new Tm(i),new Zp(i),new _p(i),new Bp(i),new Cm(i),new Lu(i))};function sf(e,t){return e.geom===t}function Vs(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!of(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>Cs(s,o),i)}function Rs(e,...t){return t.reduce((r,n)=>Cs(r,n),e)}function of(e){return typeof e=="object"&&e!==null&&"type"in e}function Cs(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,Et.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 lf(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function lf(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 cf(e){const t=e?.plugins??[],r=df(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Vs,pipe:Rs,plugins:t}}var uf=e=>(t={})=>l.buildLayerInput(e,t);function df(e){const{geoms:t,stats:r,transforms:n}=ns(e),a={};for(const o of t)a[o.type]=uf(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 mf=24,hf={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}},pf={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},or="…",ks=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(or)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+or)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+or};var B={timeZone:"UTC"},_=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},se=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",un=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ff=Ar.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ds=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>se(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=hn(a,i),{base:o,suffix:c}=mn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),Os=({locale:e,numberFormat:t,intlOptions:r})=>se(n=>{const{base:a,suffix:i}=mn(n,t.abbreviation),s={...hn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),dn=e=>se(t=>ff(t)),_s=({locale:e,intlOptions:t})=>se(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Ps=({locale:e,numberFormat:t,intlOptions:r})=>se(n=>{const a=hn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),mn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=gf(e);return mn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},hn=(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}},gf=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"},yf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).format(r)),vf=({locale:e,intlOptions:t})=>_(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...B,...t}).formatToParts(r);return Sf(n.map(bf))}),Ms=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t}).format(r)),Ns=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"long",...B,...t}).format(r)),pn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...B,...t}).format(r)),fn=e=>_(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Bs=({locale:e,intlOptions:t})=>_(r=>{const n=(0,ui.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t,year:void 0}).formatRange(r,n)}),Fs=({locale:e,intlOptions:t})=>_(r=>{const n=(0,ui.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).formatRange(r,n)}),gn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{year:"numeric",...B,...t}).format(r)),$s=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),Sf=e=>e.map(t=>t.value).join(""),bf=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},Ta=1e3,xf=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>se(a=>{const i={...vn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return yn(a,t,i)}),Af=({locale:e,tickValues:t,intlOptions:r})=>se(n=>{const a={...vn(n,t),notation:"compact",...r};return yn(n,e,a)}),If=({locale:e,tickValues:t,intlOptions:r})=>se(n=>{const a={...vn(n,t),notation:"compact",...r,style:"percent"};return yn(n,e,a)}),yn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Gs=e=>Math.abs(e)>Ta?Gs(e/Ta):Number.isInteger(e),Lf=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},vn=(e,t)=>Gs(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Lf(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Tf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),wf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",...B,...t}).format(r)),Ef=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),Vf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),Sn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return xf(e);case"date":case"datetime":return Tf(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Ef(e);case"decimal":case"integer":return Af(e);case"duration":return dn(e);case"month":return wf(e);case"month_year":return pn(e);case"percentage":return If(e);case"quarter":return fn(e);case"text":return un(e);case"time":return Vf(e);case"year":return gn(e);case"lookup":return Sn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Rf=.9,Cf=1/3,kf=1/4,Df=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Of(e):_f(e),Of=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=Us(e.ticks,n),o=Pf(e.ticks,r.width),c=o*Rf;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=Or(c);return{...e,ticks:Dr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=Or(r.height*Cf);return{...e,ticks:Dr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},_f=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=Us(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=Or(r.width*kf);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Dr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},Pf=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Us=(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}},Dr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:ks(i.formattedLabel,r,a)})},Or=e=>Math.max(0,Math.floor(e)),Mf=(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},Nf=({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 p=s.get(m);if(p)return p;const h=a[m],f=h?Bf(h.ticks,n(h)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;Mf(o(m).map(p=>p.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},Bf=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),wa=.5,nt=e=>({x:0,y:0,width:e.width,height:e.height}),bn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,at=({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,p={anchor:$f(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},h={anchor:Gf(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"?p:h,x=r.valueAxis==="x"?h:p,I=Va(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Va(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:Ff(e,I,A,c,u)}},Ea=(e,t,r,n)=>r-n>=e-wa&&r+n<=t+wa,Ff=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||Ea(e.x,e.x+e.width,t,n/2),s=e.height===0||Ea(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},$f=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",Gf=e=>e==="center"?"center":e==="start"?"min":"max",Va=({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},Uf=(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}}},Wf=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=zf(e.layer);for(const a of e.layer.data){const i=R(a),s=P(a)??E(a);if(i===null||s===null||!Pe(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}=Uf(s,F(a),i,e.panelRect.width,e.panelRect.height),p=at({box:d,panel:nt(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},Hf={place:Wf,getPercentageValueStrategy:e=>e.position==="fill"?"fill":M(e.position)?"stack":"none"},zf=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Ut(e.data,e.mapping)?bn(r):r,align:n}},xn=(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")}}},ft=6,Kf=e=>{const t=[],r=M(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=qf({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"?Zf({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}):Jf(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,nt(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 Qf(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=ng({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},Yf={place:Kf,getPercentageValueStrategy:e=>e.position==="fill"?"fill":M(e.position)?"stack":"absoluteGrandTotal"},qf=({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=Hs(t,d);if(m===null)continue;const p=a(d);if(p==="")continue;const h=xn(n,"observation",p),f=An(m,r);c&&h.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:p,boxes:h,bounds:f})}return{entries:s,shouldRotate:!i&&o}},An=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),Ws=(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}},Hs=(e,t)=>{const r=z(t),n=K(t),a=F(t),i=P(t)??E(t);return r===null||n===null||a===null||i===null?null:Ws(e,r,n,a,i)},jf=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return Ws(e,r,n,a,i)},Xf=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",_r=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Zf=e=>e.isStacked?eg({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):rg({edge:Xf(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),zs=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Jf=(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=at({box:n.bounds,panel:a,frame:zs(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}},Qf=(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=nt(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const p=Hs(c,m);if(p===null)continue;const h=e.formatCategory(m);if(h===null||h==="")continue;const f=xn(e.measureDataLabel,"category",h),g=f[o],y=An(p,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=at({box:y,panel:u,frame:zs(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:h,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},eg=({bounds:e,box:t,isRotated:r})=>{const n=_r(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"}},tg=(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}}},rg=({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:p,outwardSign:h,panelExtent:f}=tg(e,t,a,i),g=_r(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=p-h*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=_r(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=p+h*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},ng=({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=An(jf(t,c),r),d=a(c.total),{width:m,height:p}=n("aggregate","outside",d),h=c.anchor.direction==="positive";let f,g;o?(f=h?u.x+u.width+ft+m/2:u.x-ft-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=h?u.y-ft-p/2:u.y+u.height+ft+p/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:p,isRotated:!1,target:"aggregate",position:"outside"})}return i},ag=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=E(a);if(i===null||s===null||!Pe(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=at({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:nt(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},ig={place:ag,getPercentageValueStrategy:()=>"none"},sg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Ut(e.data,e.mapping)?bn(r):r,align:n}},og={color:Nt,alpha:Si,strokeWidth:Er,lineType:bi,size:Kr,borderWidth:Er},In=(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=ug(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=lg(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=qe(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=qe(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=qe(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const p=Ks(c,u);if(p!==void 0)return{value:p,tier:"data"};const h=qe(o.styles.defaults,c,u,void 0,t);return h!==void 0?{value:h.value,tier:"default",origin:h.origin}:{value:void 0,tier:"unresolved"}}}},lg=(e,t)=>{const r=(o,c)=>({get:d=>{const m=Ra(o.overrides,d,c,t);return m!==void 0?m:Ra(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)}},Ra=(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 cg(s,n)}},cg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,ug=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=gt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=gt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=gt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=Ks(n,a);return o!==void 0?o:gt(e.defaults,n,a,void 0,t)}}),gt=(e,t,r,n,a)=>qe(e,t,r,n,a)?.value,qe=(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&&dg(s,r))return{value:mg(o,a),origin:s.origin}}},dg=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),mg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Ks=(e,t)=>{const r=og[e];if(!(r===void 0||t===void 0))return r(t)??void 0},hg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=fg(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=In().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=E(s);if(o===null||c===null||!Pe(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),p=i.get("size",s)/2,h=at({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:nt(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+p,alignOffset:r+p,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:h.position})}return t},pg={place:hg,getPercentageValueStrategy:()=>"none"},fg=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 Ln(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Tn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var gg=" · ",lr=2,Xe=(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)},yg=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=Xe("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-lr&&t+i<=e.outerRadiusPx+lr)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=Xe("tangential",r,n,a)/t,c=lr/t;return Math.abs(r-e.midAngle)+o<=s+c},vg=({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,Sg=({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+Xe("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},bg=({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+Xe("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=Xe("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:yg({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:p,endAngle:h}=Ln(m),{innerRadius:f,outerRadius:g}=Tn(m);if(p===null||h===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${gg}${y}`,I={startAngle:p,endAngle:h,midAngle:(p+h)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const W=e.measureDataLabel("observation",o,x);V={width:W.width,height:W.height},A=Sg({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const W=xn(e.measureDataLabel,"observation",x),L=W[r];A=bg({wedge:I,placement:r,justify:bn(n),align:a,offset:i,labelWidth:L.width,labelHeight:L.height}),V=W[A.position]}const q=c+Math.sin(A.labelAngle)*A.labelRadius,re=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!vg({x:q,y:re,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:q,y:re,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},Ag={place:xg,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Ig=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 Ds(e);case"date":return yf(e);case"datetime":return vf(e);case"day_month":return Ms(e);case"decimal":return Os(e);case"duration":return dn(e);case"integer":return _s(e);case"month":return Ns(e);case"month_year":return pn(e);case"percentage":return Ps(e);case"quarter":return fn(e);case"text":return un(e);case"weekly_date_range":return Bs(e);case"weekly_date_range_with_year":return Fs(e);case"year":return gn(e);case"time":return $s(e);case"lookup":return Ig({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function wn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:fi(e),locale:r,numberFormat:t})}var Lg=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Qe(e,t),variable:r}:{read:G,variable:l.GROUP_VARIABLES.group}},Ys=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=wn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Rg({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:Tg({layer:e,numberFormat:n,locale:s})}},Tg=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Lg(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)}},wg=(e,t)=>{switch(t){case"stack":return Eg(e);case"fill":return Vg(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Eg=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(rn(a,t));return o===void 0?null:o.total}},Vg=e=>{const t=We(e);return r=>{const n=F(r),a=P(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}},Rg=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=U(e.data,e.dataLabels.labelSource),o=wg(e,i),c=Cg({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&qs(e);return m=>{const p=s(m);if(p===null)return"";if(!d||!l.isStrictNumericDataValue(p))return c(p,m);const h=o(m);return h===null||h===0?c(p,m):u(p/h)}},Cg=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(qs(e))return a;const o=kg(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:Dg(e.data,i),locale:n,numberFormat:t})},qs=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Mt(e.position,e.mapping))},kg=(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})},Dg=(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)},En={bar:{cartesian:Yf,polar:Ag},line:{cartesian:ig},point:{cartesian:pg},area:{cartesian:Hf}},Og=(e,t)=>En[e]?.[t]!==void 0,_g=({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,p=t.type;for(const h of e){if(!h.dataLabels.showDataLabels&&!h.dataLabels.showStackTotals&&!h.dataLabels.showCategoryLabels)continue;const f=h.geom,g=En[f]?.[p];if(g===void 0)continue;const y=Ys({layer:h,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(h)}),v=g.place(y);for(const x of v)Pg(x,p,c,u)||d.push(x)}return{labels:d}},Pg=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Mg({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=En[o.geom]?.cartesian;if(c===void 0)continue;const u=Ys({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 cr={abbreviation:"none",decimals:"auto"},js=({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:cr,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:cr,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:cr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},ur=6,dr=6,mr=15,hr=5,pr=15,Xs=(e,t)=>{switch(e){case"small":return{arrowStartGap:ur,arrowEndGap:dr,offsetFromHigherObservation:mr,arrowheadSize:hr,curveRadius:pr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:ur*1.5,arrowEndGap:dr*1.5,offsetFromHigherObservation:mr*1.25,arrowheadSize:hr*1.5,curveRadius:pr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:ur*2,arrowEndGap:dr*2,offsetFromHigherObservation:mr*1.75,arrowheadSize:hr*2.5,curveRadius:pr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Ng=(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},Bg=(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 Wc=Object.create,ci=Object.defineProperty,Hc=Object.getOwnPropertyDescriptor,zc=Object.getOwnPropertyNames,Kc=Object.getPrototypeOf,Yc=Object.prototype.hasOwnProperty,qc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=zc(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Yc.call(e,o)&&o!==r&&ci(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=Hc(t,o))||n.enumerable});return e},Mt=(e,t,r)=>(r=e!=null?Wc(Kc(e)):{},qc(t||!e||!e.__esModule?ci(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-_BpZP1A3.cjs");let ui=require("date-fns"),We=require("lodash-es"),Ke=require("d3-time"),jc=require("date-fns/differenceInDays"),le=require("d3-regression"),J=require("d3-scale"),Ce=require("d3-interpolate"),D=require("d3-scale-chromatic"),_e=require("lodash-es/clamp");_e=Mt(_e,1);let Vt=require("lodash-es/merge");Vt=Mt(Vt,1);let Ir=require("humanize-duration");Ir=Mt(Ir,1);let ge=require("d3-shape"),ra=require("color2k"),Xc=require("d3-delaunay"),Lr=require("lodash-es/isEqual");Lr=Mt(Lr,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1786950787742");var Zc=1e6;function H(e){return String(Math.round(e*Zc))}var na=0;function O(){return na+=1,`${Math.random().toString(36).slice(2,6)}${na.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function E(e){return e[l.POSITION_VARIABLES.y]}function z(e){return e[l.POSITION_VARIABLES.xMin]}function K(e){return e[l.POSITION_VARIABLES.xMax]}function F(e){return e[l.POSITION_VARIABLES.yMin]}function P(e){return e[l.POSITION_VARIABLES.yMax]}function Hr(e){return e[l.POSITION_VARIABLES.yRaw]}function Jc(e,t){return e[l.resolveScaledAestheticVariable(t)]}var Qc={xMin:0,xMax:1,yMin:0,yMax:1},Tr=(e,t)=>{if(t.type==="polar")return null;const r=z(e)??R(e),n=K(e)??R(e),a=F(e)??E(e),i=P(e)??E(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},Je=(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}}},di=e=>Je(Qc,e),be=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},mi=(e,t)=>e.yScaleType===t.yScaleType&&Er(e.valueFormat)===Er(t.valueFormat),wr=e=>`${e.yScaleType} y axis, ${Er(e.valueFormat)}`,Er=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,eu=(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 Pe(e,t){return e==="x"?t.x:t.y}function Nt(e,t){return e==="x"?t.y:t.x}function tu(e,t){return{main:Pe(e,t),cross:Nt(e,t)}}function aa(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function ru(e){return e.type==="cartesian"}var G=e=>e[l.GROUP_VARIABLES.group],Qe=(e,t)=>{const r=be(e),n=t[r]??null;if(n===null)return null;const a=r===l.GROUP_VARIABLES.group?null:G(t);return{layerId:e.id,anchorValue:n,...a!==null&&{groupValue:a}}},Me=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,nu={type:"decimal"};function hi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function pi(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):nu}function fi(e){return pi(e,l.extractVariableName(e.mapping.y))}var au=["stack","dodge","identity","fill"],zr=["solid","dashed","dotted"],gi=e=>zr.includes(e);function M(e){return e==="stack"||e==="fill"}var U=(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},et=(e,t)=>U(e,t.x),yi=(e,t)=>U(e,t.y),iu=(e,t)=>U(e,t.label),vi=(e,t)=>U(e,t.color),su=(e,t)=>U(e,t.size),ou=(e,t)=>U(e,t.alpha),lu=(e,t)=>U(e,t.group),cu=(e,t)=>U(e,t.strokeWidth),ia={variable:l.POSITION_VARIABLES.yRaw};function Bt(e,t){return M(e)?ia:t.y??ia}function He(e){return U(e.data,Bt(e.position,e.mapping))}function Ft(e){return e[l.VISUAL_VARIABLES.color]}function Si(e){return e[l.VISUAL_VARIABLES.alpha]}function Kr(e){return e[l.VISUAL_VARIABLES.size]}function Vr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function bi(e){return e[l.VISUAL_VARIABLES.lineType]}var Rr=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},xi=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(be(e)));return n=>({...n,anchorValue:Rr(n.anchorValue,r,t),...n.groupValue!==void 0&&{groupValue:Rr(n.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)}})},Ai=e=>{const t=l.extractVariableName(e.mapping.y),r=He(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},uu=["lt","lte","gt","gte","range"],du={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"}},ee=()=>!1,Le=()=>!0;function $t(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Ai(e),parsingLocale:t}}function me(e,t){if("and"in e){const r=e.and.map(n=>me(n,t)).filter(n=>n!==Le);return r.includes(ee)?ee:r.length===0?Le:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>me(n,t)).filter(n=>n!==ee);return r.includes(Le)?Le:r.length===0?ee:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=me(e.not,t);return r===ee?Le:r===Le?ee:n=>!r(n)}return hu(e,t)}function he(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>he(n,t,r)):"or"in e?e.or.flatMap(n=>he(n,t,r)):"not"in e?he(e.not,t,r):mu(e,t,r)}function mu(e,t,r){const{subject:n,effect:a}=du[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=pu(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 hu(e,t){if(!t.hasVariable(e.variable))return ee;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Rr(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=>Te(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=Te(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>Te(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=Te(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=Te(u,s),m=Te(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return ee}function pu(e){for(const t of uu)if(t in e)return t;return null}function Te(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 fu=(e,t,r,n,a,i)=>{const s=Li(e,t,r.predicate,n,a,i);if(s===null)return null;const o=Ii(r.padding),c=o===null?vu(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}},gu=(e,t,r,n,a,i)=>{const s=Li(e,t,r.predicate,n,a,i);return s===null?null:Je(s,r.align)},Ii=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},Li=(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=he(r,u.data,"selection-anchor");if(d.length>0){for(const h of d)c.set(`${h.code}:${h.message}`,h);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const p=me(r,$t(u,i));if(p!==ee)for(const h of u.data){if(!p(h))continue;const f=m(h,a);f!==null&&(s=s===null?f:yu(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},yu=(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)}),vu=(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}},Rt=(e,t,r)=>{const n=bu(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:xu(n,t.offset,e.coordSystem)},Ti=(e,t)=>t.anchorType==="selection"?fu(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},Yr=(e,t,r)=>Cr(e,t,r)?.point??null,Cr=({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=He(s),u=be(s),{anchorValue:d,groupValue:m}=xi(s,n)(a);let p=-1;for(const h of s.data){if(p+=1,!l.areDataValuesEqual(h[u]??null,d)||m!==void 0&&!l.areDataValuesEqual(G(h),m))continue;const f=o(h,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(f===null)continue;const g=wi(s,h,c);if(g===null)continue;const y=Qe(s,h);if(y!==null)return{point:{...f,...g,anchor:a.align===void 0?y:{...y,align:a.align}},layerId:s.id,observationIndex:p}}}return null},Su=(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=oa(t.x,"x",r,i),u=oa(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!Me(d,m))return null;const p=sa(d,s,Au(e)),h=sa(m,o),f=aa(n.mainAxis,{main:p.min,cross:h.min}),g=aa(n.mainAxis,{main:p.max,cross:h.max});return Je({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},wi=(e,t,r)=>{const n=r(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:eu(fi(e),t),yScaleType:e.yScaleType,color:Ft(t)}:null},bu=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Su(e,t);case"selection":return gu(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 Yr(e,Iu(t),r)}},xu=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=Ii(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},sa=(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}},Au=({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},Iu=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align}),oa=(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},Lu=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:Pu(s,t.differenceArrows),shapes:Vu(s,t.shapes),arrows:Cu(s,t.arrows),textAnnotations:ku(s,t.textAnnotations),images:Ru(s,t.images),stickers:Du(s,t.stickers),pinnedNumbers:Ou(s,t.pinnedNumbers),comments:_u(s,t.comments)};return Tu(this.container,o),wu(this.container,o),o}},Ei=(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,Q=(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."})},Tu=(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)}},wu=(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 Eu(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."})},Eu=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},Vu=(e,t)=>{const r=[];for(const n of t){const a=Ti(e,n.region);if(a===null){Q(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},Ru=(e,t)=>{const r=[];for(const n of t){const a=Ti(e,n.region);if(a===null){Q(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},Cu=(e,t)=>{const r=[];for(const n of t){const a=Rt(e,n.start,"pin"),i=Rt(e,n.end,"pin");if(a===null||i===null){Q(e.container,"arrow",n.id,`has ${Vi(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},ku=(e,t)=>{const r=[];for(const n of t){const a=Rt(e,n.at,"pin");if(a===null){Q(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},Du=(e,t)=>{const r=[];for(const n of t){const a=Rt(e,n.at,"pin");if(a===null){Q(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},Ou=(e,t)=>{const r=[];for(const n of t){const a=Yr(e,n.at,"pin");if(a===null){Q(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},_u=(e,t)=>{const r=[];for(const n of t){const a=Yr(e,n.at,"pin");if(a===null){Q(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Pu=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)Q(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Cr(e,n.start,"value"),i=Cr(e,n.end,"value");if(a===null||i===null){Q(e.container,"differenceArrow",n.id,`has ${Vi(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.observationIndex===i.observationIndex){Q(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Mu(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,color:Ei(n.color,a.point,i.point),ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Vi=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Mu=(e,t,r,n)=>{mi(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:wr(r),actual:wr(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Ri(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 ki(e,t)}function T(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 Ci(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function qr(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 ki(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=ki(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 Gt(e){return{pipe:t=>{const r=t(e);return Gt({...e,...r})},result:()=>e}}function Nu(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:Di(i),values:i};return new l.Dataset(n)}function Di(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 Bu=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,Di(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Fu=(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},xe=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)}},$u=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)}},Gu=class extends xe{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}},Uu=class{constructor(e){this.setupStage=new $u(e),this.transformStage=new Gu(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)}},Wu=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}},Hu=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:Ku(e.scales,e.layers)}}transform(e){return e.layers.map(t=>qu(t))}},zu=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],la=l.prefixInternalVariable("flipSwap"),Ku=(e,t)=>Yu(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Yu=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},qu=e=>{let t=e.data;for(const[r,n]of zu){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,la).renameVariable(n,r).renameVariable(la,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},pe=Math.PI*2,ju=8,Xu=1e-9,Oi=(e,t)=>Math.abs(t-e)>=pe-Xu,Ne=e=>(e%pe+pe)%pe,_i=(e,t,r)=>{if(Oi(t,r))return!0;const n=Ne(r-t);return Ne(e-t)<=n},Ct=(e,t)=>{const r=Math.abs(Ne(e)-Ne(t));return Math.min(r,pe-r)},Pi=(e,t,r)=>e*pe+t+r,kt=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),Mi=(e,t)=>({angle:Ne(Math.atan2(e,t)),radius:Math.hypot(e,t)}),jr=(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}},Ut=(e,t)=>{const{x:r,y:n}=jr(e,t);return Mi(r,n)};function Ni(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 Bi=(e,t)=>Ni(t.domain!==null&&t.domain.length>0?t.domain:e),Zu=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=ed(t,e.scales,e.layers),a=rd(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=Qu(r,n),i=nd(t);return e.layers.map(s=>ad(t.theta==="y"?id(s):s,a,i))}},Ju=[[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 Qu(e,t){return r=>Pi(r,e,t)}function ed(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=td(n,e,r);return a===0?0:-Math.PI/a}function td(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 Bi(n,e).length}function rd(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 nd(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function ad(e,t,r){let n=e.data;return n=we(n,l.POSITION_VARIABLES.x,t),n=we(n,l.POSITION_VARIABLES.xMin,t),n=we(n,l.POSITION_VARIABLES.xMax,t),n=we(n,l.POSITION_VARIABLES.y,r),n=we(n,l.POSITION_VARIABLES.yMin,r),n=we(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function we(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 id(e){let t=e.data;for(const[r,n]of Ju){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 sd=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new Wu),this.register("flip",new Hu),this.register("polar",new Zu)}},od=new Set(["min","max","scalar"]),ld={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function cd(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 ud(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 dd(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=ld[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 md=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:dd(n.data,r.positionRoles,a)}}},Xr=["x","y"],Fi=new Set(["x","y","ySecondary"]),Wt=new Set(["color","size","alpha","strokeWidth","lineType"]),tt=e=>Fi.has(e),Zr=e=>Wt.has(e),hd=e=>tt(e)||Zr(e);function ne(e){return e==="secondary"?"ySecondary":"y"}function $i(e,t){return e==="y"?ne(t):"x"}function N(e){return e==="ySecondary"?"y":e}var ze=(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 Wt){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},Ht=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:ze(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),pd=class{compute({data:e,mapping:t}){const r=ze(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)}}},fd=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},gd=(e,t,r)=>{const n=ye(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function ye(e,t){const r=N(t);for(const n of Gi(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var Jr=(e,t)=>e===null?null:t[e]??e,yd=(e,t)=>e===null?null:t[String(e)]??null,ve=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return ar(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 Sd(i,t)?i:ar(t)}return ar(t)},vd=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:Gi(t,e).some(r=>r.position==="fill");function Gi(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var ar=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Sd=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},bd=[{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}],ca={year:0,quarter:1,month:2,week:3,day:4,hour:5},Ee=40,xd=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Td(r.unit).range(e,new Date(t.valueOf()+1),n)},Ad=({unit:e,step:t,start:r,stop:n})=>{const a=(0,jc.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>Ee;case"day":return a/t>Ee;case"week":return a/(7*t)>Ee;case"month":return a/(30*t)>Ee;case"quarter":return a/(90*t)>Ee;case"year":return a/(365*t)>Ee}},Id=(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"}}},Ld=(e,t)=>{const r=wd(t);return r===null?!1:ca[e]>ca[r]},Td=e=>{switch(e){case"hour":return Ke.utcHour;case"day":return Ke.utcDay;case"week":return Ke.utcMonday;case"month":case"quarter":return Ke.utcMonth;case"year":return Ke.utcYear}},wd=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}},Ui={left:"right",right:"left",top:"bottom",bottom:"top"},Ed={x:!0,y:!0,ySecondary:!1},Vd=20,ua=new Set(["top","bottom"]),Rd={type:"percentage"};function Cd(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(hi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Od(o,a,i.type,n),u=new Set(t.map(p=>p.position)),d=Pd(Wi(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const p of Fi){const h=r[p];if(!l.isDefined(h)||h.kind!=="position")continue;const f=kd({scaleAestheticKey:p,scale:h,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function kd(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}=_d(t,n,i,s),p=ye(a,t),h=vd(a,t)?Rd:ve({layers:a,scaleType:r.spec.scaleType,variableName:p});return{scaleAestheticKey:t,position:d,geometry:m,label:Dd(u,p,c),isVisible:u.isVisible,tickCandidates:Nd(r,h,u.ticks.mode),valueFormat:h,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Md(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Dd(e,t,r){return e.label?e.label:t?r[t]??null:null}function Od(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:da(i,n.axes.x.grid.isVisible)},y:{gridVisible:da(s,n.axes.y.grid.isVisible)}}}function da(e,t){if(e&&t===null)return!1}function _d(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:Wi(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=Ui[n],i=(0,We.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 Wi(e,t){return ua.has(e)===ua.has(t)?e:t}function Pd(e,t){return t.has(e)?Ui[e]:e}function Md(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Ed[r]}var Nd=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Fd(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Vd;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Be(e,u))}))}return i}return e.spec.scaleType==="datetime"?Bd(e,t):[{ticks:e.generateTicks().map(a=>Be(e,a))}]},Bd=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Be(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=>Be(e,d)),valueFormat:c}))};for(const o of bd)Ad({...o,start:r,stop:n})||Ld(o.unit,t)||s(e.generateTicks({interval:o}),Id(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},Fd=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:[Be(e,r),Be(e,n)]}},Be=(e,t)=>({value:t,position:e.map(t)});function Hi({scale:e,aesthetics:t,layers:r}){const n=$d({layers:r,aesthetics:t}),a=zi({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function $d({layers:e,aesthetics:t}){const r=zi({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 zi({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 Qr=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Gd({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!Qr(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=ye(t,"color");if(Ki({colorVariableName:a,xVariableName:ye(t,"x"),mapsColorAcrossMultipleLayers:Wd(t)>1,isMergedWithAnotherAesthetic:Ud(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return Hi({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],p=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:ve({layers:m?[m]:t,scaleType:i,variableName:p}),label:yd(o,r)}})}var Ki=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Ud(e,t,r){if(r===null)return!1;for(const n of Wt){if(n==="color")continue;const a=e[n];if(!(a===void 0||!Qr(a))&&ye(t,n)===r)return!0}return!1}var Wd=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function Yi(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Hd(e,t,r,n){const a=r.findIndex(i=>Yi(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Jr(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 ma(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 qi=e=>e==="none"?"first":e,zd=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=ha(e);return n===0?null:r}case"average":{const{sum:r,count:n}=ha(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Kd=(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}},ha=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Yd(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?qd(e,n):jd(e,n)}function qd(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:ve({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function jd(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>Yi(o,d)))return null;const c=Hd(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>Xd({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 Xd({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=ve({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=Qd(i.data,o),p=ve({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),h=em(i.data,o),f=h.getValues(s,{type:"numeric"}),g=o!==null?h.getValues(o):[],y=c!==null?h.getValues(c):null,v=ma(f,y,e.value),x=ma(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:zd(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:p,label:e.label,observationLabel:Zd(t,m,x),comparison:Jd(t,r,m,x,v)}}function Zd(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 Jd(e,t,r,n,a){return e!=="current"||!r?null:Kd(n.map((i,s)=>({main:i,cross:a[s]??null})),qi(t))}function Qd(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function em(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function Y(e,...t){return e?t.includes(e.geom):!1}function k(e,t){return e.find(r=>r.id===t)}function ae(e,...t){return e.find(r=>t.includes(r.geom))}function tm(e,...t){return e.filter(r=>t.includes(r.geom))}function en(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function tn(e){const t=e.filter(r=>!en(r,e));return t.length>0?t:e}function ji({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=tn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var rm=3;function nm({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=dm(om({scales:e,layers:r})),u=ye(r,"x"),d=c.map(y=>{if(cm(y,u,r))return null;const v=hm({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=am(d),p=tn(r),h=Sm(s,t.legend.position,m,p,n);if(d.length===0)return{drawn:[],position:h};if(t.legend.position==="auto"&&vm(s,m,p,n))return{drawn:[],position:h};const f=bm(t.legend.display,{legendPosition:h,coordSystem:n,layers:r}),g=f==="direct"?Lm(p[0]):null;return{drawn:d.map(({built:y})=>im(y,{position:h,display:f,align:t.legend.align},g)),position:h}}function am(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function im(e,t,r){const{position:n,display:a}=t,i=sm(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 sm(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function om(e){const{scales:t,layers:r}=e,n=[];for(const a of Wt){const i=t[a];if(i===void 0||i.kind==="identity"||!lm(a,r))continue;const s=ye(r,a),o=Im(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function lm(e,t){const r=N(e);return t.some(n=>l.isDefined(n.mapping[r]))}function cm(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:Ki({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:um(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function um(e,t){const r=N(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function dm(e){const t=new Map;for(const r of e){const n=Am(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function mm(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function hm({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>N(c.scaleAestheticKey)),s=Hi({scale:a.scale,aesthetics:i,layers:r}),o=ve({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:Jr(a.variableName,t),items:s.map(c=>pm(c,e,i,o,n))}}function pm(e,t,r,n,a){const i={};for(const o of t)mm(i,o.scaleAestheticKey,o.scale.map(e.value));const s=gm(e,t,r,n,a);return{value:e.value,label:fm(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function fm(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function gm(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=ym(i,r);return i===void 0||s===null?n:ve({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function ym(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 vm(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 Sm(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,M(u.position)&&(o=!0))}const c=r>=rm;return i&&s?"top":i?c?"right":"top":o?xm(a)?"top":c?"right":"top":"top"}function bm(e,t){return e==="pill"?"pill":ji(t)?"direct":"pill"}function xm(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Am(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Im(e,t){return Qr(t)?"discrete":`continuous:${e}`}function Lm(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(P(c))||l.isDefined(E(c)));if(!n)return;const a=G(n);if(!l.isDefined(a))return;const i=F(n),s=P(n)??E(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var Tm=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=fd(e.originalData),r=Gd({scales:e.scales,layers:e.layers,valueLabels:gd(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=Yd(n),i=nm(n),s={...i,drawn:wm(a,i.drawn)};return{axes:Cd(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},wm=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Em=e=>l.getStableKey([G(e)]),rn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Vm=e=>e!=="data-point",Dt=(e,t,r)=>{switch(e){case"series":return Em(t);case"x-value":return rn(t,r)}},Rm={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor"};function Xi(e){const t=Rm[e]??null;return t===null?null:{strategy:t,composition:Zi()}}function Zi(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Cm=class extends xe{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=km({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function km({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(L=>{const j=he(L.predicate,e.data);for(const X of j)a.diagnostics.addWarning({...X,message:`${X.message} Dropping this highlight.`});return j.length===0}),s=l.extractVariableName(e.mapping.x),o=$t(e,r),c=i.map(L=>({predicate:me(L.predicate,o),scope:L.scope})),u=c.some(({scope:L})=>L==="series"),d=c.some(({scope:L})=>L==="x-value"),m=n==="overlay-anchor",p=e.data.size(),h=u?new Array(p):null,f=d?new Array(p):null,g=m?new Array(p):null,y=new Uint8Array(p),v=new Set,x=new Set;let I=!1,A=0;for(const L of e.data){let j,X;h!==null&&(j=Dt("series",L,s),h[A]=j),f!==null&&(X=Dt("x-value",L,s),f[A]=X),g!==null&&(g[A]=L);for(const{predicate:mt,scope:ht}of c)if(mt(L))switch(ht){case"series":j!==void 0&&v.add(j);break;case"x-value":X!==void 0&&x.add(X);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return Zi();const V=new Uint8Array(p),q=[];let re=0;for(let L=0;L<p;L++){const j=h?.[L],X=f?.[L],mt=j!==void 0&&v.has(j),ht=X!==void 0&&x.has(X),ea=y[L]===1;if(n==="observation-rerender")(mt||ea||ht)&&(V[L]=1,re++);else if(mt)V[L]=1,re++;else if(ea||ht){const ta=g?.[L];ta!==void 0&&q.push({observation:ta,observationIndex:L})}}const W=re>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&W!==null,matchedLayer:W,overlayCandidates:q}}var Dm=l.prefixInternalVariable("__ungrouped__");function Om(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]??Dm;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 _m=()=>({defaults:[],overrides:[],warnings:[]}),Pm=class extends xe{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,pa(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,pa(t))}runLayerPipeline(e,t,r,n){const a=Gt({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:Om(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:Xi(e.geom),styles:_m()}}};function pa(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Ji(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}var Mm=new Set(["label","group"]),Nm=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)}),Ji(this.container.diagnostics,t)}checkPostCompile(e){hi(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(!Ht(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=[...cd(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,p]of Object.entries(a)){if(u.has(m))continue;const h=l.extractVariableName(p);h===null||h===""||d.has(h)||i.hasVariable(h)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${h}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:h}})}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(!od.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 p=i.getType(m);p!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${p}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:p},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([...ud(i),...s.map(p=>p.name)]),u=Mm,d=o,m=[];for(const p of Object.keys(a))l.isDefined(a[p])&&(c.has(p)||u.has(p)||d.has(p)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${p}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:p}}));return m}},ie=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,We.merge)({},this.defaultParams,e.params)}},nn=(e,t)=>{const r=l.extractVariableName(t.x);return!r||!["numeric","temporal"].includes(e.getType(r))?e:e.orderBy(r,"asc")},an=(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}},Bm=class extends ie{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=an}resolveParams(e){const t=super.resolveParams(e);return t.missingValues==="gap"?{...t,missingValues:"zero"}:t}compile({data:e,mapping:t}){return e=nn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},fa=.7,Fm=.1,Qi=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},$m=class extends ie{constructor(...e){super(...e),this.type="bar",this.defaultParams={width:fa},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=Tr,this.resolveDataLabelDefaults=t=>M(t)?{justify:"center"}:{},this.resolveBandFraction=t=>t.width,this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Gm(t);if(i!==void 0){const m=Tr(t,r);return m===null?null:Je(m,i)}const s=M(n),o={isSolo:!s||Qi(t)==="solo",isNegative:s&&Um(t),purpose:a};if(r.mainAxis==="x"){const m=z(t),p=K(t),h=ga({lowerBound:F(t),upperBound:P(t)??E(t),options:o});return m===null||p===null||h===null?null:{x:(m+p)/2,y:h}}const c=F(t),u=P(t),d=ga({lowerBound:z(t),upperBound:K(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=nn(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:fa;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}},Gm=e=>{const t=z(e),r=K(e),n=F(e),a=P(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)}},Um=e=>{const t=Hr(e);return l.isStrictNumericDataValue(t)&&t<0},ga=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},Wm=class extends ie{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=Tr,this.resolveAnchorPosition=an}compile(e){return{data:nn(e.data,e.mapping),mapping:{}}}},Hm=class extends ie{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=an,this.resolveDefaultLabelSource=t=>{const r=l.extractVariableName(t.size);return r!==null?{variable:r}:null}}compile({data:e}){return{data:e,mapping:{}}}},zm=class extends ie{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=ya(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=ya(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}}}},ya=(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},Km=[new $m,new Hm,new Wm,new Bm,new zm],zt=class extends l.Registry{constructor(){super("geom");for(const e of Km)this.register(e.type,e)}},Ae=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},Ym=class extends Ae{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,...ze(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},qm=class extends Ae{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},jm=class extends Ae{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}}}},Xm=2,es=1440*60*1e3,Zm=class extends Ae{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=ze(e,t),u=ah(a,s,i,c,e);return c.length===0?va({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=ih(d,c);va({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},va=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=Jm({data:e,xVariable:t,yVariable:n,xType:r});c.length<Xm||(o?nh({observations:c,spec:a,output:i,groupObservation:s}):th({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},Jm=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?Qm(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 p=eh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});p!==null&&o.push({x:p,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},Qm=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},eh=({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)/es+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}`})}},th=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=ts(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?rh(o,r):o;a.push({x:u,y:c,groupObservation:i})}},rh=(e,t)=>t===null?new Date(e):new Date((e-1)*es+t),nh=({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=ts(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=rs(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})}},ts=(e,t)=>e.method==="loess"?(0,le.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):rs(e,t),rs=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,le.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,le.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,le.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,le.regressionQuad)().x(r).y(n)(t);case"power":return(0,le.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,le.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},ah=(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)}}},ih=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},sh=class extends Ae{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],...ze(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},oh=[new qm,new Ym,new Zm,new jm,new sh],lh=class extends l.Registry{constructor(){super("stat");for(const e of oh)this.register(e.type,e)}};function ch({geoms:e,stats:t,transforms:r}){const n=new zt,a=new lh,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 sn(e){if("definition"in e)return e.definition;if(as(e)||is(e)||ss(e))return e}function ns(e){const t=[],r=[],n=[];for(const a of e){const i=sn(a);i&&(as(i)?t.push(i):is(i)?r.push(i):ss(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...ir("geom",t,a=>a.type),...ir("stat",r,a=>a.type),...ir("transform",n,a=>a.transformType),...uh(t)]}}function uh(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 ir(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 as=e=>e instanceof ie,is=e=>e instanceof Ae,ss=e=>"transformType"in e&&typeof e.apply=="function",dh=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},Kt=class{},mh=class extends Kt{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=hh(e)??[-.7/2,.7/2],s=r.length>1?Fm:0,o=(0,J.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 p=a[m];if(!l.isDefined(p))continue;const h=o(String(p));l.isDefined(h)&&(u[m]=h,d[m]=h+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},hh=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]},Sa=l.prefixInternalVariable("__ungrouped__"),os=(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?[Sa]: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 p=0;p<d;p++){const h=l.getStableKey(o[p]??null),f=u[p],g=i?Sa:f;if(!l.isDefined(g))continue;let y=m.get(h);y||(y=new Map,m.set(h,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(p)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},ls=(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,p=-1/0;for(const h of i.values())for(const f of h){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>p||y===p&&g<m)&&(d=f,m=g,p=y))}for(const h of s)a[h]=ph(h===o,h===d)}return a},ph=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",fh=class extends Kt{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=os(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,p=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:p-=x)}}let h=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:p;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=h,o[v]=h+=A):(o[v]=f,c[v]=f+=A)}}}const u=ls(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:{}}}},gh=class extends Kt{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},yh=class extends Kt{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=os(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[,p]of a){let h=0,f=0;for(const g of i){const y=p.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]=h,o[v]=h+=x):(o[v]=f,c[v]=f+=x)}}}}const u=ls(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:{}}}},vh=class extends l.Registry{constructor(){super("position"),this.register("identity",new gh),this.register("stack",new yh),this.register("fill",new fh),this.register("dodge",new mh)}},Sh=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)||Zr(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r($i(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}},bh=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)}},xh=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],p=i[d],h=s[d];if(l.isDefined(m)&&l.isDefined(p)&&l.isDefined(h)){const f=n?-h:p,g=n?-p:h;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)}},Ah=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(ne(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)}},Ih=class{map({data:e,layer:t,getPositionScale:r}){const n=r(ne(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)}},Lh=[new bh,new Ah,new xh,new Ih,new Sh];function Th(e,t){const r=e[t];return r?.kind==="position"?r:null}var wh=class extends xe{constructor(e,t=Lh){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=>Th(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}}},Eh=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})}}Ji(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"?ne(n.yScaleType):i,c=a.get(i)??(hd(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)||Zr(n.aes)||t.set(n.aes,$i(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)}},Vh=["rgb","lab","hcl","hsl"],Rh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],cs=["RdBu","BrBG","PuOr","Spectral"],us={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Ch=new Set(cs.map(e=>e.toLowerCase()));function ds(e){const t=e.toLowerCase(),r=us[t];return r?r.toLowerCase():t}function kh(e){return Ch.has(ds(e))}var Dh={rgb:Ce.interpolateRgb,lab:Ce.interpolateLab,hcl:Ce.interpolateHcl,hsl:Ce.interpolateHsl},Oh={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 on(e){const t=Ph(e);return e.reverse?r=>t(1-r):t}function _h(e={},t=2){const r=on({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 Ph(e){const t=Dh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ce.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Oh[ds(e.scheme)];if(r)return r}return(0,Ce.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var rt=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}}},Mh=class extends rt{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=tt(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"&&Nh(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,J.scaleLog)():r.transform==="sqrt"?(0,J.scaleSqrt)():(0,J.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=Bh(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=on(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,J.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,J.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]}},Nh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Bh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Fh=class extends rt{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=tt(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=$h(e)?e:[],a=(0,J.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?xd(i,s,c.interval):[]:a.ticks(c?.count)})}},$h=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),Gh=class extends rt{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=tt(e.scaledAesthetic),n=Bi(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,J.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,J.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})}},Uh=class extends rt{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:()=>[]}}},Wh=class extends rt{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=Ni(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,J.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},Hh=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Mh(e)),this.register("discrete",new Gh),this.register("datetime",new Fh),this.register("identity",new Uh),this.register("palette",new Wh)}},xt={color:null,size:"small",labelCrossPosition:.5},ce={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},sr={zOrder:"foreground",fit:"contain",opacity:1},zh={x:8,y:8,unit:"px"},At={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},ue={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Kh={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}},Yh=(e,t,r)=>{const n=qh(e,t),a=Zh(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>Qh(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>np(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>sp(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>Jh(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>ep(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>ap(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>tp(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>rp(e,i,r)).filter(l.isDefined)}},qh=(e,t)=>{if(t===void 0)return{};if(!jh(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))}},jh=e=>{const t=new Set;for(const r of Xh(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},Xh=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],Zh=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},ln=(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},Jh=(e,t,r,n)=>{const a=Ot(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??At.align,backgroundColor:t.backgroundColor??At.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??At.backgroundColorStyle}},Qh=(e,t,r)=>{const n=Xe(e,t.start,r),a=Xe(e,t.end,r);return n===null||a===null?null:{id:t.id??O(),start:n,end:a,label:t.label,color:t.color??xt.color,size:t.size??xt.size,labelCrossPosition:t.labelCrossPosition??xt.labelCrossPosition}},Xe=(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)},Ot=(e,t,r,n,a)=>{if(t.anchorType==="annotation")return ln(e,t.ref,n,a)?t:null;if(t.anchorType==="panel"||t.anchorType==="axis"||t.anchorType==="selection")return t;const i=Xe(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},ep=(e,t,r,n)=>{const a=Ot(e,t.at,r,n,t.id);return a===null?null:{id:t.id??O(),at:a,sticker:t.sticker}},tp=(e,t,r)=>{const n=Xe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n}},rp=(e,t,r)=>{const n=Xe(e,t.at,r);return n===null?null:{id:t.id??O(),at:n,content:t.content}},np=(e,t,r)=>t.region.anchorType==="annotation"&&!ln(e,t.region.ref,r,t.id)?null:{id:t.id??O(),kind:t.kind??ce.kind,zOrder:t.zOrder??ce.zOrder,region:ip(t.region),fillColor:t.fillColor===void 0?ce.fillColor:t.fillColor,fillOpacity:t.fillOpacity??ce.fillOpacity,strokeWidth:t.strokeWidth??ce.strokeWidth,strokeColor:t.strokeColor??ce.strokeColor},ap=(e,t,r)=>t.region.anchorType==="annotation"&&!ln(e,t.region.ref,r,t.id)?null:{id:t.id??O(),src:t.src,zOrder:t.zOrder??sr.zOrder,region:t.region,fit:t.fit??sr.fit,opacity:t.opacity??sr.opacity},ip=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:zh},ba=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=Kh[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},sp=(e,t,r,n)=>{const a=Ot(e,t.start,r,n,t.id),i=Ot(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??O(),start:ba(a),end:ba(i),color:t.color??ue.color,thickness:t.thickness??ue.thickness,startArrowheadStyle:t.startArrowheadStyle??ue.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??ue.endArrowheadStyle,lineStyle:t.lineStyle??ue.lineStyle,hasStickerStyle:t.hasStickerStyle??ue.hasStickerStyle}},op={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 lp(e){const t=(0,We.merge)({},op,e);return t.content=cp(t.content,e?.content),t}var cp=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},up={xLimits:null,yLimits:null},It={theta:"x",startAngle:0,innerRadius:0};function kr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Vt.default)({},up,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??It.theta,startAngle:t.params?.startAngle??It.startAngle,innerRadius:(0,_e.default)(t.params?.innerRadius??It.innerRadius,0,1)}}}}function dp(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 mp=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=xa(e.filter(n=>n.severity==="error")),r=xa(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},hp=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 xa(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var pp={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 ms(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 nt(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new hp(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=vp({dataLabels:bp(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return yp({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??O(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:ms(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 fp(e,t,r,n,a){const i=n.map((s,o)=>nt(e,t,r,s,a,o));return hs(e,i)}var gp=(e,t,r,n)=>n.label!==void 0?n.label:xp(e,t,r,n),hs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:qr(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,We.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},yp=({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&&M(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."})},vp=({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=Sp(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}},Sp=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&M(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,bp=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=gp(e,r.geom,n,i),o=e.get(r.geom);return{...(0,We.merge)({},pp,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},xp=(e,t,r,n)=>e.get(t).resolveDefaultLabelSource?.(n)??Bt(r,n);function Dr(e,t){const r=Ap(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?ne(n.yScaleType):null,niceZeroAxis:n.position!=="fill"}}function Ap(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 ps={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Ip={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function fs(e,t,r,n,a,i){switch(t.scaleType){case"inferred":return fs(e,wp(e,t,r,n,a),r,n,a,i);case"continuous":{const s=ps[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:Ep(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 gs(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 Lp(e,t,r,n,a,i,s){const o=Cp(Rp(r,n)),c=new Map;for(const d of o)c.set(d.scaledAesthetic,d);const u=[...c.values()].map(d=>fs(e,d,t,n,a,s));return i.coordType==="polar"?Tp(u):u}function gs(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 Tp=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t);function wp(e,t,r,n,a){const i=N(t.scaledAesthetic),s=t.scaledAesthetic==="ySecondary"?Vp(n,a):a[i],o=Dr(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=ps[t.scaledAesthetic];switch(Ip[u][d]){case"discrete":return l.discrete(t.scaledAesthetic,t.options);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 Ep(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)&&kh(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 Vp(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function Rp(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Cp(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var kp=e=>{const t=new Set;e!==void 0&&ys(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},ys=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])ys(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function Dp(e,t,r){const n=kr(t.coords),a=fp(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Lp(e,t.data,t.scales,a,t.mapping,n,r),s=lp(t.config),o=dp(e,t.highlights,a),c=Yh(e,t.annotations,a),u=kp(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 vs=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return Dp(this.container,{...e,data:t},r)}},Op=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})}},_p=class extends xe{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of Kp(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of Yp(e.styles))this.container.diagnostics.addWarning(r);for(const r of qp(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=ws({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},ke={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ss={bar:{...ke,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...ke,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...ke,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...ke,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Aa=1,Ia=1e3,pt={color:"color",strokeWidth:"pixels",lineType:"lineType"},or={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},Lt={panelBorder:{...pt,borderRadius:"pixels"},panelBorderEdge:pt,gridLine:pt,tickLine:{...pt,length:"pixels"},axisLabel:or,tickLabel:{...or,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...or,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"}},Pp=new Set([...Object.keys(ke),...Object.values(Ss).flatMap(e=>Object.keys(e??{})),...Object.values(Lt).flatMap(e=>Object.keys(e))]),bs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph"],Mp=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Np=(e,t,r="en-US")=>ws({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Bp=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 xs(e.styles)}},xs=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(Yt(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!Fp(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 ${bs.map(h=>`'${h}'`).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 h=m.edge;if(h!==void 0&&!Gp(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(h)}'.`,context:{param:"edge",actual:String(h),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Mp.has(m.target)){const h=m.axis;if(h!==void 0&&!Hp(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(h)}'.`,context:{param:"axis",actual:String(h),...u},suggestion:`Set 'axis' to one of ${Xr.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const h=m.layer;if(h!==void 0&&typeof h!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${Fe(h)}.`,context:{param:"layer",actual:Fe(h),...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 h=m.role;if(h!==void 0&&!Up(h)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(h)}'.`,context:{param:"role",actual:String(h),...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(!Wp(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(h===void 0||h==="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 p=cn({declarations:i.declarations,vocabulary:$p(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(p).length!==0&&n[m.target][s].push({select:m,declarations:p,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},Yt=e=>e.select.target==="geom",Fp=e=>{const t=e.select.target;return t!=="geom"&&bs.includes(t)},As=e=>(e!==void 0?Ss[e]:void 0)??ke,$p=e=>e.target==="panelBorder"?e.edge===void 0?Lt.panelBorder:Lt.panelBorderEdge:Lt[e.target],Gp=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),Up=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),Wp=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),Hp=e=>typeof e=="string"&&Xr.includes(e),zp=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!Yt(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=cn({declarations:a.declarations,vocabulary:As(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},Is=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},Kp=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return Is(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},Yp=e=>{const t=[];return Is(e,(r,n,a)=>{if(!Yt(r))return;const i=r.when?.state;i===void 0||Ls(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},Ls=e=>l.STYLE_STATES.includes(e),qp=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Ts(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${Fe(n)}.`,context:{param:"tokens",actual:Fe(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Ts=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,ft=e=>typeof e=="number"&&Number.isFinite(e),Fe=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),ws=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=$t(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((p,h)=>{if(!Yt(p))return;const f=p.select.kind;if(f!==void 0&&f!==t.geom||p.select.layer!==void 0&&p.select.layer!==t.id)return;const g=p.when?.state;if(g!==void 0&&!Ls(g))return;const y={list:d,index:h,...p.id===void 0?{}:{id:p.id}},v=p.when?.where;if(v!==void 0){const I=he(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${h}]: ${A.message}`,context:{...A.context,layerIndex:r,...p.id===void 0?{}:{styleEntryId:p.id}}});return}}const x=cn({declarations:p.declarations,vocabulary:As(f),tokens:o,location:`${d}[${h}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:me(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...zp(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},cn=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=(h,f)=>{o[h]=f},d=(h,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${h}' ignored: expected ${f}, got ${Fe(g)}.`,context:{param:h,expected:f,actual:Fe(g),...c},suggestion:`Set '${h}' to ${f}.`})},m=(h,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(h,"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 '${h}' ignored: unknown token '${f.token}'.`,context:{param:h,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Ts(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(h,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},p=h=>{const f=Pp.has(h);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${h}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:h,...c},suggestion:f?`Declare '${h}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${h}'.`})};for(const h of Object.keys(t)){const f=t[h];if(f===void 0)continue;const g=r[h];if(g===void 0){p(h);continue}switch(g){case"color":{const y=m(h,f);y!==void 0&&u(h,y);break}case"unitInterval":ft(f)&&f>=0&&f<=1?u(h,f):d(h,"a number in [0, 1]",f);break;case"pixels":ft(f)&&f>=0?u(h,f):d(h,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(h,f):d(h,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":gi(f)?u(h,f):d(h,`one of ${zr.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(h,f):d(h,"a non-empty CSS font-family list",f);break;case"fontWeight":ft(f)&&f>=Aa&&f<=Ia?u(h,f):d(h,`a number in [${Aa}, ${Ia}]`,f);break;case"multiplier":ft(f)&&f>0?u(h,f):d(h,"a positive multiple of the font size",f);break;default:break}}return o},jp=({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}},Xp=({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=P(a),c=z(a),u=K(a),d=Hr(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 p=rn(a,t),h={yMin:s,yMax:o},f=r.get(p);if(f===void 0){r.set(p,{total:d,topPositive:m?h:null,bottomNegative:m?null:h,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=h):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=h)}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},Zp=class extends xe{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=Xp({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=jp({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Jp=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)}},La={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},Qp=["color","size","alpha","strokeWidth","lineType"],ef=class extends xe{dependencies(e){return Qp.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.deriveVariable(i,La[a],()=>s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];if(!c||c.kind!=="visual")continue;const u=tf(o,c);u&&(r=r.deriveVariable(i,La[a],u))}return{...e,data:r}}},tf=(e,t)=>e?r=>l.isDefined(r[e])?t.map(r[e]):null:null;function rf(e=new zt){return{diagnostics:new mp,geomRegistry:e}}var Es=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,p,h,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=p,this.chromeStylesCompiler=h,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=Fu(e.spec.data,e.spec.mapping);return this.runPipeline({spec:T(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:[Ri(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 Gt({spec:e}).pipe(({spec:t})=>({spec:T(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:T(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()}},nf=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],af=({plugins:e=[]}={})=>{const t=ns(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=ch(t),i=rf(r),s=new Hh(i),o=new Jp(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new Es(i,new l.DataCompiler,new vs(i),o,new Bu,new Nm(i,o,n,new Pm(i,o,new Op(n),new pd,new md(i),new dh(new vh))),new Eh(i,s),new Uu(new sd),new wh(i),new ef,new Tm(i),new Zp(i),new _p(i),new Bp(i),new Cm(i),new Lu(i))};function sf(e,t){return e.geom===t}function Vs(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!of(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>Cs(s,o),i)}function Rs(e,...t){return t.reduce((r,n)=>Cs(r,n),e)}function of(e){return typeof e=="object"&&e!==null&&"type"in e}function Cs(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,Vt.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 lf(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function lf(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 cf(e){const t=e?.plugins??[],r=df(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:Vs,pipe:Rs,plugins:t}}var uf=e=>(t={})=>l.buildLayerInput(e,t);function df(e){const{geoms:t,stats:r,transforms:n}=ns(e),a={};for(const o of t)a[o.type]=uf(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 mf=24,hf={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}},pf={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},lr="…",ks=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(lr)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+lr)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+lr};var B={timeZone:"UTC"},_=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},se=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",un=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ff=Ir.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ds=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>se(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=hn(a,i),{base:o,suffix:c}=mn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),Os=({locale:e,numberFormat:t,intlOptions:r})=>se(n=>{const{base:a,suffix:i}=mn(n,t.abbreviation),s={...hn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),dn=e=>se(t=>ff(t)),_s=({locale:e,intlOptions:t})=>se(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),Ps=({locale:e,numberFormat:t,intlOptions:r})=>se(n=>{const a=hn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),mn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=gf(e);return mn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},hn=(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}},gf=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"},yf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).format(r)),vf=({locale:e,intlOptions:t})=>_(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...B,...t}).formatToParts(r);return Sf(n.map(bf))}),Ms=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t}).format(r)),Ns=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"long",...B,...t}).format(r)),pn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...B,...t}).format(r)),fn=e=>_(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Bs=({locale:e,intlOptions:t})=>_(r=>{const n=(0,ui.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...B,...t,year:void 0}).formatRange(r,n)}),Fs=({locale:e,intlOptions:t})=>_(r=>{const n=(0,ui.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...B,...t}).formatRange(r,n)}),gn=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{year:"numeric",...B,...t}).format(r)),$s=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),Sf=e=>e.map(t=>t.value).join(""),bf=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},Ta=1e3,xf=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>se(a=>{const i={...vn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return yn(a,t,i)}),Af=({locale:e,tickValues:t,intlOptions:r})=>se(n=>{const a={...vn(n,t),notation:"compact",...r};return yn(n,e,a)}),If=({locale:e,tickValues:t,intlOptions:r})=>se(n=>{const a={...vn(n,t),notation:"compact",...r,style:"percent"};return yn(n,e,a)}),yn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Gs=e=>Math.abs(e)>Ta?Gs(e/Ta):Number.isInteger(e),Lf=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},vn=(e,t)=>Gs(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Lf(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Tf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),wf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{month:"short",...B,...t}).format(r)),Ef=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...B,...t}).format(r)),Vf=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...B,...t}).format(r)),Sn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return xf(e);case"date":case"datetime":return Tf(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Ef(e);case"decimal":case"integer":return Af(e);case"duration":return dn(e);case"month":return wf(e);case"month_year":return pn(e);case"percentage":return If(e);case"quarter":return fn(e);case"text":return un(e);case"time":return Vf(e);case"year":return gn(e);case"lookup":return Sn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Rf=.9,Cf=1/3,kf=1/4,Df=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Of(e):_f(e),Of=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=Us(e.ticks,n),o=Pf(e.ticks,r.width),c=o*Rf;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=_r(c);return{...e,ticks:Or(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=_r(r.height*Cf);return{...e,ticks:Or(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},_f=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=Us(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=_r(r.width*kf);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Or(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},Pf=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Us=(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}},Or=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:ks(i.formattedLabel,r,a)})},_r=e=>Math.max(0,Math.floor(e)),Mf=(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},Nf=({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 p=s.get(m);if(p)return p;const h=a[m],f=h?Bf(h.ticks,n(h)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;Mf(o(m).map(p=>p.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},Bf=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),wa=.5,at=e=>({x:0,y:0,width:e.width,height:e.height}),bn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,it=({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,p={anchor:$f(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},h={anchor:Gf(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"?p:h,x=r.valueAxis==="x"?h:p,I=Va(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=Va(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:Ff(e,I,A,c,u)}},Ea=(e,t,r,n)=>r-n>=e-wa&&r+n<=t+wa,Ff=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||Ea(e.x,e.x+e.width,t,n/2),s=e.height===0||Ea(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},$f=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",Gf=e=>e==="center"?"center":e==="start"?"min":"max",Va=({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},Uf=(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}}},Wf=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=zf(e.layer);for(const a of e.layer.data){const i=R(a),s=P(a)??E(a);if(i===null||s===null||!Me(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}=Uf(s,F(a),i,e.panelRect.width,e.panelRect.height),p=it({box:d,panel:at(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},Hf={place:Wf,getPercentageValueStrategy:e=>e.position==="fill"?"fill":M(e.position)?"stack":"none"},zf=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Ht(e.data,e.mapping)?bn(r):r,align:n}},xn=(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")}}},gt=6,Kf=e=>{const t=[],r=M(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=qf({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"?Zf({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}):Jf(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,at(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 Qf(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=ng({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},Yf={place:Kf,getPercentageValueStrategy:e=>e.position==="fill"?"fill":M(e.position)?"stack":"absoluteGrandTotal"},qf=({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=Hs(t,d);if(m===null)continue;const p=a(d);if(p==="")continue;const h=xn(n,"observation",p),f=An(m,r);c&&h.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:p,boxes:h,bounds:f})}return{entries:s,shouldRotate:!i&&o}},An=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),Ws=(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}},Hs=(e,t)=>{const r=z(t),n=K(t),a=F(t),i=P(t)??E(t);return r===null||n===null||a===null||i===null?null:Ws(e,r,n,a,i)},jf=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return Ws(e,r,n,a,i)},Xf=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",Pr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},Zf=e=>e.isStacked?eg({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):rg({edge:Xf(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),zs=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},Jf=(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=it({box:n.bounds,panel:a,frame:zs(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}},Qf=(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=at(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const p=Hs(c,m);if(p===null)continue;const h=e.formatCategory(m);if(h===null||h==="")continue;const f=xn(e.measureDataLabel,"category",h),g=f[o],y=An(p,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=it({box:y,panel:u,frame:zs(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:h,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},eg=({bounds:e,box:t,isRotated:r})=>{const n=Pr(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"}},tg=(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}}},rg=({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:p,outwardSign:h,panelExtent:f}=tg(e,t,a,i),g=Pr(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=p-h*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=Pr(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=p+h*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},ng=({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=An(jf(t,c),r),d=a(c.total),{width:m,height:p}=n("aggregate","outside",d),h=c.anchor.direction==="positive";let f,g;o?(f=h?u.x+u.width+gt+m/2:u.x-gt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=h?u.y-gt-p/2:u.y+u.height+gt+p/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:p,isRotated:!1,target:"aggregate",position:"outside"})}return i},ag=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=E(a);if(i===null||s===null||!Me(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=it({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:at(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},ig={place:ag,getPercentageValueStrategy:()=>"none"},sg=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:Ht(e.data,e.mapping)?bn(r):r,align:n}},og={color:Ft,alpha:Si,strokeWidth:Vr,lineType:bi,size:Kr,borderWidth:Vr},In=(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=ug(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=lg(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 p=Ks(c,u);if(p!==void 0)return{value:p,tier:"data"};const h=je(o.styles.defaults,c,u,void 0,t);return h!==void 0?{value:h.value,tier:"default",origin:h.origin}:{value:void 0,tier:"unresolved"}}}},lg=(e,t)=>{const r=(o,c)=>({get:d=>{const m=Ra(o.overrides,d,c,t);return m!==void 0?m:Ra(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)}},Ra=(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 cg(s,n)}},cg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,ug=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=yt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=yt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=yt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=Ks(n,a);return o!==void 0?o:yt(e.defaults,n,a,void 0,t)}}),yt=(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&&dg(s,r))return{value:mg(o,a),origin:s.origin}}},dg=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),mg=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Ks=(e,t)=>{const r=og[e];if(!(r===void 0||t===void 0))return r(t)??void 0},hg=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=fg(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=In().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=E(s);if(o===null||c===null||!Me(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),p=i.get("size",s)/2,h=it({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:at(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+p,alignOffset:r+p,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:h.position})}return t},pg={place:hg,getPercentageValueStrategy:()=>"none"},fg=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 Ln(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Tn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var gg=" · ",cr=2,Ze=(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)},yg=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=Ze("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-cr&&t+i<=e.outerRadiusPx+cr)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=Ze("tangential",r,n,a)/t,c=cr/t;return Math.abs(r-e.midAngle)+o<=s+c},vg=({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,Sg=({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+Ze("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},bg=({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+Ze("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=Ze("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:yg({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:p,endAngle:h}=Ln(m),{innerRadius:f,outerRadius:g}=Tn(m);if(p===null||h===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${gg}${y}`,I={startAngle:p,endAngle:h,midAngle:(p+h)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const W=e.measureDataLabel("observation",o,x);V={width:W.width,height:W.height},A=Sg({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const W=xn(e.measureDataLabel,"observation",x),L=W[r];A=bg({wedge:I,placement:r,justify:bn(n),align:a,offset:i,labelWidth:L.width,labelHeight:L.height}),V=W[A.position]}const q=c+Math.sin(A.labelAngle)*A.labelRadius,re=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!vg({x:q,y:re,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:q,y:re,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},Ag={place:xg,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Ig=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 Ds(e);case"date":return yf(e);case"datetime":return vf(e);case"day_month":return Ms(e);case"decimal":return Os(e);case"duration":return dn(e);case"integer":return _s(e);case"month":return Ns(e);case"month_year":return pn(e);case"percentage":return Ps(e);case"quarter":return fn(e);case"text":return un(e);case"weekly_date_range":return Bs(e);case"weekly_date_range_with_year":return Fs(e);case"year":return gn(e);case"time":return $s(e);case"lookup":return Ig({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function wn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:fi(e),locale:r,numberFormat:t})}var Lg=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:et(e,t),variable:r}:{read:G,variable:l.GROUP_VARIABLES.group}},Ys=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=wn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Rg({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:Tg({layer:e,numberFormat:n,locale:s})}},Tg=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Lg(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)}},wg=(e,t)=>{switch(t){case"stack":return Eg(e);case"fill":return Vg(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Eg=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(rn(a,t));return o===void 0?null:o.total}},Vg=e=>{const t=He(e);return r=>{const n=F(r),a=P(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}},Rg=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=U(e.data,e.dataLabels.labelSource),o=wg(e,i),c=Cg({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&qs(e);return m=>{const p=s(m);if(p===null)return"";if(!d||!l.isStrictNumericDataValue(p))return c(p,m);const h=o(m);return h===null||h===0?c(p,m):u(p/h)}},Cg=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(qs(e))return a;const o=kg(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:Dg(e.data,i),locale:n,numberFormat:t})},qs=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Bt(e.position,e.mapping))},kg=(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})},Dg=(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)},En={bar:{cartesian:Yf,polar:Ag},line:{cartesian:ig},point:{cartesian:pg},area:{cartesian:Hf}},Og=(e,t)=>En[e]?.[t]!==void 0,_g=({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,p=t.type;for(const h of e){if(!h.dataLabels.showDataLabels&&!h.dataLabels.showStackTotals&&!h.dataLabels.showCategoryLabels)continue;const f=h.geom,g=En[f]?.[p];if(g===void 0)continue;const y=Ys({layer:h,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(h)}),v=g.place(y);for(const x of v)Pg(x,p,c,u)||d.push(x)}return{labels:d}},Pg=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Mg({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=En[o.geom]?.cartesian;if(c===void 0)continue;const u=Ys({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 ur={abbreviation:"none",decimals:"auto"},js=({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:ur,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:ur,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:ur,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},dr=6,mr=6,hr=15,pr=5,fr=15,Xs=(e,t)=>{switch(e){case"small":return{arrowStartGap:dr,arrowEndGap:mr,offsetFromHigherObservation:hr,arrowheadSize:pr,curveRadius:fr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:dr*1.5,arrowEndGap:mr*1.5,offsetFromHigherObservation:hr*1.25,arrowheadSize:pr*1.5,curveRadius:fr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:dr*2,arrowEndGap:mr*2,offsetFromHigherObservation:hr*1.75,arrowheadSize:pr*2.5,curveRadius:fr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Ng=(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},Bg=(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}
|
|
@@ -20,4 +20,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Wc=Object
|
|
|
20
20
|
M ${t.x-n} ${t.y-r-n}
|
|
21
21
|
L ${t.x} ${t.y-r}
|
|
22
22
|
L ${t.x+n} ${t.y-r-n}
|
|
23
|
-
`,Gg=(e,t,r,n,a,i=.5)=>e?{x:n,y:Math.min(t.y,r.y)+i*a}:{x:Math.min(t.x,r.x)+i*a,y:n},Ug=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),Zs=({arrow:e,mainAxis:t,panelWidth:r,panelHeight:n,textScale:a,locale:i})=>{const s=t==="y",o={x:e.start.x*r,y:(1-e.start.y)*n},c={x:e.end.x*r,y:(1-e.end.y)*n},u=Xs(e.size,a),d=Ng(s,o,c,u),m=(s?Fg:Bg)(o,c,d,u),p=$g(s,c,u),h=Gg(s,o,c,d,Ug(s,o,c),e.labelCrossPosition),f=js({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:o,end:c,linePath:m,arrowheadPath:p,labelPosition:h,labelText:f,color:e.color,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*Wg({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!Pe(s.start.x,s.start.y)||!Pe(s.end.x,s.end.y))continue;const o=Zs({arrow:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,textScale:n,locale:a}),c=i(o.labelText,s.size).width+2*o.labelPaddingX,u=o.labelLineHeight+2*o.labelPaddingY;yield{x:r.x+o.labelPosition.x-c/2,y:r.y+o.labelPosition.y-u/2,width:c,height:u}}}var Hg=e=>{const t=e.padding,r=Ca(e.rows,t?.top??0,t?.bottom??0),n=Ca(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:qg(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},zg=e=>{const t=ka(e.rows,e.height),r=ka(e.cols,e.width),n=Da(t),a=Da(r),i=new Map;for(const s of e.placements){const o=s.rowSpan??1,c=s.colSpan??1,u=a[s.col]??0,d=n[s.row]??0,m=Oa(r,s.col,c),p=Oa(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,p)})}return i},Ca=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let s=0;s<e.length;s++){const o=e[s];if(!o)continue;Pr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(Kg(o));const c=Yg(e,s);if(Pr(o)&&c){const u=o.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},Kg=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Pr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Yg=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Pr(n))return n}},qg=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),s=r.get(a.col);if(i===void 0||s===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):s;o===void 0||c===void 0||n.push({name:a.name,row:i,col:s,rowSpan:Math.max(1,o-i+1),colSpan:Math.max(1,c-s+1)})}return n},ka=(e,t)=>{let r=0,n=0;for(const i of e)i.type==="fixed"?r+=i.pixels:n+=i.weight;const a=Math.max(0,t-r);return e.map(i=>i.type==="fixed"?i.pixels:n===0?0:i.weight/n*a)},Da=e=>{const t=new Array(e.length);let r=0;for(let n=0;n<e.length;n++)t[n]=r,r+=e[n]??0;return t},Oa=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},Fe={top:0,right:0,bottom:0,left:0},Js={outer:Fe,inner:Fe},jg={top:24,right:24,bottom:24,left:24},Xg=(e,t,r,n=Fe,a=Js,i=jg,s={})=>{const o={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=_a(hf,s),d=_a(pf,s);return Hg({rows:[{name:"header",size:t.headerSize.height,gaps:u.header},{name:"topLegend",size:r.legends.top,gaps:u.topLegend},{name:"headline",size:r.headline,gaps:u.headline},{name:"topAxisLabel",size:c,gaps:u.topAxisLabel},{name:"topAxis",size:r.axes.top,gaps:u.topAxis},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:o.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:o.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:u.bottomAxis},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:u.bottomAxisLabel},{name:"bottomLegend",size:r.legends.bottom,gaps:u.bottomLegend},{name:"footer",size:t.footerSize.height,gaps:u.footer}],cols:[{name:"leftLegend",size:r.legends.left,gaps:d.leftLegend},{name:"leftAxis",size:r.axes.left,gaps:d.leftAxis},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:o.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:o.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:d.rightAxis},{name:"rightLegend",size:r.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...Jg(r.axes),...Qg(r.axesLabels,r.axes),...ey(r.legends)],containerSize:e,padding:i})},Zg=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:fr(t,e.after)}:{before:fr(t.before,e.before),after:fr(t.after,e.after)}:e,fr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,_a=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=Zg(e[n],t[n]);return r},Jg=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Qg=(e,t)=>{const r=[];return e.top>0||t.top>0?(e.top>0&&r.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&r.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&r.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&r.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),r},ey=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t};var ty=class{constructor(e){this.outer={...Fe},this.inner={...Fe},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},ry=["top","right","bottom","left"],gr=(e,t)=>{const r={};for(const n of ry){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function Pa(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Mr=["large","medium","small"],ny=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Mr)if(r(n)<=t)return n;return"small"},ay=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:Mr.indexOf(e);for(const a of Mr.slice(n))if(r(a)<=t)return a;return null},iy=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const s=a===0?i:n+t+i;if(s>r)break;n=s,a+=1}return a},sy=({headline:e,containerSize:t,measurer:r})=>{if(Qs(e))return 0;const n=eo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},oy=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(Qs(e)){const o=ly(t.panel,e.innerRadius),c=ay({size:e.size,availableWidth:o.width,measureStripWidth:to(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=eo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=iy({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},Qs=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,ly=(e,t)=>{const r=t*(Math.min(e.width,e.height)/2)*Math.SQRT2,n=e.x+e.width/2,a=e.y+e.height/2;return{x:n-r/2,y:a-r/2,width:r,height:r}},eo=(e,t,r)=>ny({size:e.size,availableWidth:t,measureStripWidth:to(e,r)}),to=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Ve={x:0,y:0,width:0,height:0},cy="0000",uy=3,Ke=e=>typeof e=="number"&&Number.isFinite(e)?e:24,dy=e=>e.plot.y+e.plot.height-e.panel.y,my=e=>{if(typeof e=="object"&&e!==null)return{top:Ke(e.top),right:Ke(e.right),bottom:Ke(e.bottom),left:Ke(e.left)};const t=Ke(e);return{top:t,right:t,bottom:t,left:t}},hy=class{constructor(e){this.measurer=e}compile(e){return Ft({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Js,panelBorder:e.panelBorder??Fe,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:my(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:py(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Ma(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Ma(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:dy(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new ty(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of Wg({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,textScale:e.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(s,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const s of Mg({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(s,e.overflowStrategy.dataLabels);const i=a.resolve();return Pa(i.inner,n.inner)&&Pa(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m}){let p=t,h=s;for(let f=0;f<uy;f++){const g=this.measurePanelOverflow(e,p.panelFrame,u,h);if(g===h)break;h=g,p=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}return p}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,s=a.height-n.vertical*2;return i<=0||s<=0?Na(r,a,0,0):Na(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=N(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const s=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,s.width),a=Math.max(a,s.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:cy}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=N(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=Nf({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:o,...c}=e,u={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?Df({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:s,padding:o,gaps:c}){const u=zg(Xg(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Ve,headline:u.get("headline")??Ve,footer:u.get("footer")??Ve,plot:u.get("plot")??Ve,panelFrame:u.get("panelFrame")??Ve,panel:u.get("panel")??Ve,axes:gr(u,"Axis"),axisLabels:gr(u,"AxisLabel"),legends:gr(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const o of e)o.isVisible&&o.geometry==="linear"&&(a[o.position]=this.measurer.measureAxis(o),o.label!==null&&(i[o.position]=this.measurer.measureAxisLabel(o)));const s={top:0,right:0,bottom:0,left:0};for(const o of t)s[o.position]=this.measurer.measureLegend(o);return{axes:a,axesLabels:i,legends:s,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:sy({headline:e,containerSize:t,measurer:this.measurer})}},Ma=e=>e==="left"||e==="right",Na=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,s=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-s)/2,y:t.y+n+(i-s)/2,width:s,height:s}}},py=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(s=>s.value)),a=new WeakMap;return i=>{const s=a.get(i);if(s)return s;const o=Sn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},fy=(e=[])=>{const t=gy(e);return{resolve:(r,n,a)=>t.has(r)?t.get(r).resolveAnchorPosition?.(n,a)??null:null,hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0}},gy=e=>{const t=new Wt;for(const r of e){const n=sn(r);n instanceof ie&&t.register(n.type,n)}return t};function yy(e){return e}function te(e){return 1-e}var de=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,ro=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:te(e.y)*t.height};const n=Math.min(t.width,t.height),a=(t.width-n)/2,i=(t.height-n)/2;return{x:a+e.x*n,y:i+e.y*n}},vy=class{constructor(e,t,r,n){this.annotations=e,this.panelRect=t,this.coordSystem=r,this.measuredBoxes=n,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return yt(e);const{x:s,y:o}=Nr(e.defer,this.panelRect);return yt({...e,x:e.x+s,y:e.y-o})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=Ze(r,e.defer.align),{x:a,y:i}=Sy(n,e.defer.offset,this.panelRect);return{x:a,y:i}}resolveRegion(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return yt(e);const{x:i,y:s}=Nr(e.defer,this.panelRect);return yt({...e,x:e.x-i,y:e.y-s,width:Math.max(0,e.width+2*i),height:Math.max(0,e.height+2*s)})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=r.xMax-r.xMin,a=r.yMax-r.yMin;return n<=0||a<=0?null:{x:r.xMin,y:r.yMin,width:n,height:a}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:by(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:Ba(r,n)}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=t.annotation.width,i=n.height/this.panelRect.height,s=di(t.annotation.align),o=r.x-s.x*a,c=r.y+(1-s.y)*i;return{xMin:o,xMax:o+a,yMin:c-i,yMax:c}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Fa(r)}case"differenceArrow":return Ba(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return Fa(t.annotation.at)}}},Nr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Sy=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:s}=Nr({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-s}}return{x:e.x+n,y:e.y-a}},by=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),Ba=(e,t)=>({xMin:Math.min(e.x,t.x),xMax:Math.max(e.x,t.x),yMin:Math.min(e.y,t.y),yMax:Math.max(e.y,t.y)}),Fa=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),yt=e=>{const t={...e};return delete t.defer,t},xy=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!Ay(t))return t;const o=new vy(t,r,n,a),c={...t,shapes:Ye(t.shapes,m=>m.region.defer!==void 0,m=>{const p=o.resolveRegion(m.region);return p===null?null:{...m,region:p}}),images:Ye(t.images,m=>m.region.defer!==void 0,m=>{const p=o.resolveRegion(m.region);return p===null?null:{...m,region:p}}),arrows:Ye(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const p=o.resolvePoint(m.start),h=o.resolvePoint(m.end);return p===null||h===null?null:{...m,start:p,end:h}}),textAnnotations:Ye(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const p=o.resolvePoint(m.at);return p===null?null:{...m,at:p}}),stickers:Ye(t.stickers,m=>m.at.defer!==void 0,m=>{const p=o.resolvePoint(m.at);return p===null?null:{...m,at:p}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},Ye=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Ay=e=>e.shapes.some(t=>t.region.defer!==void 0)||e.images.some(t=>t.region.defer!==void 0)||e.arrows.some(t=>t.start.defer!==void 0||t.end.defer!==void 0)||e.textAnnotations.some(t=>t.at.defer!==void 0)||e.stickers.some(t=>t.at.defer!==void 0),Iy=800,$a=400,Ly={thin:{strokeWidth:{minValue:1.5,targetValue:2},arrowheadLength:{minValue:7,targetValue:8}},medium:{strokeWidth:{minValue:3,targetValue:4},arrowheadLength:{minValue:14,targetValue:16}},thick:{strokeWidth:{minValue:6,targetValue:8},arrowheadLength:{minValue:28,targetValue:32}}},Ty=e=>Math.max(1,(e-$a)/(Iy-$a)+1),wy=(e,t)=>{const r=Ty(t),n=Ly[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},vt=Math.PI/4,Br=1.5,Ey=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,Ga=(e,t,r)=>{if(r<=0)return"";const{startX:n,startY:a,endX:i,endY:s}=t,o=e==="start"?n:i,c=e==="start"?a:s,u=e==="start"?Math.atan2(a-s,n-i):Math.atan2(s-a,i-n);return`M ${o} ${c} L ${o-r*Math.cos(u-vt)} ${c-r*Math.sin(u-vt)} M ${o} ${c} L ${o-r*Math.cos(u+vt)} ${c-r*Math.sin(u+vt)}`},Vy=(e,t)=>e==="solid"?null:`${t*Br} ${t*Br*2}`,Ry=(e,t)=>t?e*Br:0,Cy=64,ky=({arrow:e,panelWidth:t,panelHeight:r})=>{const n={startX:e.start.x*t,startY:(1-e.start.y)*r,endX:e.end.x*t,endY:(1-e.end.y)*r};if(n.startX===n.endX&&n.startY===n.endY)return null;const{strokeWidth:a,arrowheadLength:i}=wy(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=Dy(i,s),c=e.startArrowheadStyle==="line-arrow",u=e.endArrowheadStyle==="line-arrow",d=c||u?o*Math.sin(Math.PI/4):0;return{id:e.id,linePath:Ey(n),startArrowheadPath:c?Ga("start",n,o):"",endArrowheadPath:u?Ga("end",n,o):"",color:e.color,strokeWidth:a,dashArray:Vy(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:Ry(a,c),arrowheadExtent:d}},Dy=(e,t)=>Math.min(e,t*e/Cy);function Oy(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(m=>m.transformType==="filter"&&m.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let s,o,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")s="color",o=a.options.variableName,c=a.options.value;else if(i!==null)s="y",o=i,c=i;else continue;const u=_y(e,s,o);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d})}return r}function _y(e,t,r){let n=null;for(const a of e)if(a.geom!=="rule"&&(n===null&&(n=a),l.extractVariableName(a.mapping[t])===r))return a;return n}var no=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),Py=0,My=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:no(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:Py})),Ny=9,By=8,Fy=2,ao=e=>typeof e=="string"?e:io(e),io=e=>e.text!==void 0?e.text:e.content?e.content.map(io).join(""):"",Ua={top:"bottom",bottom:"top",right:"left",left:"right"};function $y(e,t,r){return r.type==="polar"?Wy(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function Fr(e,t,r){const{width:n,height:a}=r;switch(t){case"top":return{x:e.x-n/2,y:e.y-9-a,width:n,height:a};case"bottom":return{x:e.x-n/2,y:e.y+9,width:n,height:a};case"right":return{x:e.x+9,y:e.y-a/2,width:n,height:a};case"left":return{x:e.x-9-n,y:e.y-a/2,width:n,height:a}}}function Wa(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function Gy(e,t){return{...t,x:Math.max(0,Math.min(t.x,e.width-t.width)),y:Math.max(0,Math.min(t.y,e.height-t.height))}}function Uy(e,t,r=2){return e.x<t.x+t.width-r&&e.x+e.width>t.x+r&&e.y<t.y+t.height-r&&e.y+e.height>t.y+r}function Wy(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[s,o]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[s,Ua[s],o,Ua[o]]}function Hy(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:p}=d;return Ha(m,"pinned-number",p,s(d),i,n,a)}),...r.map(({id:d,at:m,content:p})=>Ha(d,"comment",m,ao(p),i,n,a))];o.sort((d,m)=>d.anchorPx.x-m.anchorPx.x||d.anchorPx.y-m.anchorPx.y);const c=[],u=[];for(const d of o){if(!d.inView){c.push(za(n,d,"top"));continue}const m=za(n,d,Ky(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function Ha(e,t,r,n,a,i,s){const o=ro(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:zy(o,i)}}function zy(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function Ky(e,t,r,n){const a=$y(t.anchorPx,e,r);for(const i of a){const s=Fr(t.anchorPx,i,t.mini);if(Wa(s,e)&&!n.some(o=>Uy(s,o)))return i}for(const i of a)if(Wa(Fr(t.anchorPx,i,t.mini),e))return i;return"top"}function za(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:Gy(e,Fr(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var Yy=({labelPosition:e,measuredTextWidth:t,labelLineHeight:r,labelPaddingX:n,labelPaddingY:a})=>{const i=t+2*n,s=r+2*a;return{x:e.x-i/2,y:e.y-s/2,width:i,height:s}},qy=100,jy=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,s=!0,o=0;for(;s;){s=!1,o++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const m=u.y+a,p=d.y-a;if(m>p){s=!0,i=!0;const h=(m-p)/2+1;u.y-=h,d.y+=h,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>qy)break}return{placements:n.filter(c=>c.y>=0&&c.y<=t).map(c=>({y:c.y,anchorY:c.anchorY,payload:c.payload})),hasOverlap:i}},Xy=(e,t)=>{const r=Ai(e),n=Jy(t,Zy(e),r);if(n===null)return null;const a=Qy(e,n,r)?ev(e,t,n,r):n,[i]=a;return i===void 0?null:a.length===1?i:{and:a}},Zy=e=>{const t=He(e.data,e.mapping),r=be(e);return r===l.GROUP_VARIABLES.group?[...new Set(t)]:[...new Set([r,...t])]},Jy=(e,t,r)=>{const n=[];for(const a of t){const i=r(e,a);if(i===null)return null;n.push({variable:a,eq:i})}return n},Qy=(e,t,r)=>{let n=0;for(const a of e.data)if(t.every(i=>l.areDataValuesEqual(r(a,i.variable),i.eq))&&(n+=1,n>1))return!0;return!1},ev=(e,t,r,n)=>{const a=l.extractVariableName(e.mapping.y);if(a===null||r.some(s=>s.variable===a))return r;const i=n(t,a);return i===null?r:[...r,{variable:a,eq:i}]},Vn=(e,t)=>{if(t.kind==="circle"){const n=e.x-t.center.x,a=e.y-t.center.y;return n*n+a*a<=t.radius*t.radius}const{rect:r}=t;return e.x>=r.x&&e.x<=r.x+r.width&&e.y>=r.y&&e.y<=r.y+r.height},tv=(e,t)=>{for(const r of t)if(Vn(e,r.shape))return r;return null},rv=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},nv=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>av(r,t[n])),av=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&iv(e.shape,t.shape)&&sv(e.tooltip,t.tooltip),iv=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="circle"){const n=t;return e.center.x===n.center.x&&e.center.y===n.center.y&&e.radius===n.radius}const{rect:r}=t;return e.rect.x===r.x&&e.rect.y===r.y&&e.rect.width===r.width&&e.rect.height===r.height},sv=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="cursor")return!0;const r=t;return e.point.x===r.point.x&&e.point.y===r.point.y&&e.placement===r.placement&&e.annotationId===r.annotationId},ov=100,lv=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:ov}),cv=(e,t)=>Vn(e,{kind:"circle",center:t.center,radius:t.radius}),uv=(e,t)=>e===t?!0:e===null||t===null?!1:e.center.x===t.center.x&&e.center.y===t.center.y&&e.radius===t.radius&&dv(e.target,t.target),dv=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,mv=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Bt(e,n),i=hv(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||he(s.predicate,e.data).length>0)return!1;const o=me(s.predicate,a);return o(r)?!0:Vm(s.scope)&&i(s.scope).some(o)})},hv=(e,t)=>{const r=l.extractVariableName(e.mapping.x),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const s=kt(a,t,r),o=[];for(const c of e.data)kt(a,c,r)===s&&o.push(c);return n.set(a,o),o}},Lt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const s=e.data.size();for(let o=0;o<s;o+=1){const c=t+o*r,u=i?fv(c,s):c;if(u<0||u>=s)break;const d=e.data.getAt(u);if(d===null||!n(d))continue;const m=Je(e,d);if(m!==null&&!a.some(p=>De(m,p)))return{anchor:m,observation:d}}return null},so=(e,t,r)=>{let n=0;for(const a of e.data){if(pv(a,t,r))return n;n+=1}return-1},pv=(e,t,r)=>l.areDataValuesEqual(e[r]??null,t.anchorValue)?t.groupValue===void 0?!0:l.areDataValuesEqual(G(e),t.groupValue):!1,De=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null),fv=(e,t)=>(e%t+t)%t,oo=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian")return null;const n=be(e),a=so(e,t,n),i=e.data.getAt(a);if(i===null)return null;const s=G(i),o=p=>l.areDataValuesEqual(G(p),s),c=[t],u=Lt({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=Lt({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=Lt({layer:e,excluding:c,from:0,step:1,accepts:p=>!o(p)&&l.areDataValuesEqual(p[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},gv=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers)for(const n of r.data){const a=Je(r,n);if(a===null)continue;const i=oo({layer:r,at:a,coordSystem:e.coordSystem});if(i!==null&&!t.some(s=>yv(s,i)))return i}return null},yv=(e,t)=>De(e.start,t.start)&&De(e.end,t.end)||De(e.start,t.end)&&De(e.end,t.start),vv=({resolver:e,layer:t,observation:r,coordSystem:n,align:a,readSegmentY:i})=>{const s=e.resolve(t.geom,r,{coordSystem:n,position:t.position,purpose:"value",align:a});if(s===null)return null;const o=wi(t,r,i??We(t));if(o===null)return null;const c=Je(t,r);return c===null?null:{...s,...o,anchor:a===void 0?c:{...c,align:a}}},Sv=({layer:e,from:t,partner:r,axis:n,step:a,canLandOn:i})=>{const s=be(e),o=so(e,t,s),c=e.data.getAt(o);if(c===null)return null;const u=bv(c),d=n==="main"?u:m=>!u(m)&&l.areDataValuesEqual(m[s]??null,t.anchorValue);return Lt({layer:e,excluding:[t,r],from:o+a,step:a,accepts:m=>d(m)&&i(m),cycles:n!=="main"})},bv=e=>{const t=G(e);return r=>l.areDataValuesEqual(G(r),t)};function xv({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=C({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Av=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const s=a??n;return e.kind==="grandTotal"?Iv(e,s,r):Lv(e,t,s,r,i)},Iv=(e,t,r)=>({kind:"grandTotal",value:C({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Lv=(e,t,r,n,a)=>{const i=C({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),s=e.items.length>1;return{kind:"perGroup",items:e.items.map(o=>{const c=C({valueFormat:o.valueFormat,locale:r,numberFormat:n}),u=C({valueFormat:o.groupLabelFormat,locale:r,numberFormat:n}),d=Sn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Vv(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:Ev(o.observationLabel,d),comparison:Tv(o.comparison,d,i,a)}})}},Tv=(e,t,r,n)=>e===null?null:{direction:wv(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},wv=e=>e>0?"up":e<0?"down":"flat",Ev=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Vv=(e,t,r,n)=>{switch(e){case"total":return n("graph.headlineMetrics.total",{value:r});case"average":return t?n("graph.headlineMetrics.averageShort",{value:r}):n("graph.headlineMetrics.averageLong",{value:r});case"current":case"conversion":case"none":return r}},Rv=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Cv(i,a,t))},Cv=(e,t,r)=>({...e,items:e.items.map(n=>{const a=C({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function Rn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function kv(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Dv=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,s=(i?yi:Qe)(r.data,r.mapping)(a);return s===null?null:C({valueFormat:Rn(e,i?ne(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},Ov=12,_v=4,Pv=4,Mv=12,Nv=4,Bv=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:yr([St("value","value",t??"–"),St("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:Uv(n),segments:yr([$v(n),Gv(n),St("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:yr([Fv(a),St("label","label",i)])}].filter(s=>s.segments.length>0)},St=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},Fv=e=>e===null?null:{kind:"swatch",swatch:e,size:12},$v=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Gv=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},Uv=e=>{switch(e.direction){case"up":return`Increased ${e.percentage} ${e.reference}`;case"down":return`Decreased ${e.percentage} ${e.reference}`;case"flat":return`No change ${e.reference}`}},yr=e=>e.filter(t=>t!==null),Yt=e=>e==="catmull-rom"?ge.curveCatmullRom:ge.curveLinear,Wv=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Hv=(e,t)=>{const r=Yt(t.interpolate),n=(0,ge.area)().curve(r),a=(0,ge.line)().curve(r);if(e.mainAxis==="y"){const i=c=>te(E(c)??0),s=c=>z(c)??0,o=c=>K(c)??R(c)??0;n.y(i).x0(s).x1(o),a.y(i).x(o)}else{const i=c=>R(c)??0,s=c=>te(F(c)??0),o=c=>te(P(c)??E(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>R(s)!==null&&E(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},zv=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&E(r)!==null),Cn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},lo=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return Cn[e.borderRadius??"sm"]},Kv=e=>{const t=lo(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Yv=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),co=(e,t)=>{const r=z(t),n=K(t),a=F(t),i=P(t)??E(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let s=r,o=n-r;return o<0&&(s+=o,o=-o),{x:s,y:1-i,width:o,height:i-a}},uo=(e,t)=>e==="x"?`${H(t.x)}-${H(t.width)}`:`${H(t.y)}-${H(t.height)}`,qv=e=>{let t=1/0,r=1/0,n=-1/0,a=-1/0;for(const i of e)i.x<t&&(t=i.x),i.y<r&&(r=i.y),i.x+i.width>n&&(n=i.x+i.width),i.y+i.height>a&&(a=i.y+i.height);return{x:t,y:r,width:n-t,height:a-r}},jv=e=>{const t=(0,ge.line)().x(r=>R(r)??0).y(r=>te(E(r)??0)).curve(Yt(e.interpolate));return e.missingValues==="gap"&&t.defined(mo),t},Xv=e=>{const t=(0,ge.area)().x(r=>R(r)??0).y0(()=>1).y1(r=>te(E(r)??0)).curve(Yt(e.interpolate));return e.missingValues==="gap"&&t.defined(mo),t},Zv=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&E(r)!==null),mo=e=>R(e)!==null&&E(e)!==null,ho=(0,ge.arc)().cornerRadius(e=>e.cornerRadius??0);ho.digits(8);var Jv=200,Qv=e=>ho(e)??void 0,eS=(e,t)=>e==="full"?Math.max(0,t)/2:Cn[e??"sm"]/Jv,po=(e,t)=>e==="x"?`${H(t.startAngle)}-${H(t.endAngle)}`:e==="y"?`${H(t.innerRadius)}-${H(t.outerRadius)}`:"sweep",tS=e=>{let t=1/0,r=-1/0,n=1/0,a=-1/0;for(const i of e)t=Math.min(t,i.startAngle,i.endAngle),r=Math.max(r,i.startAngle,i.endAngle),n=Math.min(n,i.innerRadius,i.outerRadius),a=Math.max(a,i.innerRadius,i.outerRadius);return{startAngle:t,endAngle:r,innerRadius:n,outerRadius:a}},Ka="#FFFFFF",vr="#1A1A1A",rS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],nS=e=>{try{return(0,ra.getContrast)(e,Ka)>(0,ra.getContrast)(e,vr)?Ka:vr}catch{return vr}},qt=(e,t,r)=>{const n=Qe(e,t);return a=>{const i=G(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},aS=(e,t,r)=>{const n=Qe(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},iS=()=>(e,t)=>Nt(e)??`default-${t}`;function kn(e,t,r){return Math.hypot(e*r,t)}function Ot(e,t,r){return e<t?t-e:e>r?e-r:0}function oe(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const s=e[i];if(s===void 0)continue;const o=t(s);if(r&&o===0)return s;o<a&&(n=s,a=o)}return n}function sS(e,t,r,n){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const i=a.find(t.x*r,t.y,n??void 0),s=e.points[i];return s?{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:kn(s.x-t.x,s.y-t.y,r)}:null}function oS(e,t){if(e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function fo(e,t){return Dn(e.buckets,t,r=>r.main)}function lS(e,t){return Dn(e.bands,t,r=>r.bandCenter)}function go(e,t){return Dn(e.columns,t,r=>r.mainMid)}function Dn(e,t,r){if(e.length===0)return null;let n=0,a=e.length;for(;n<a;){const o=n+a>>>1,c=e[o];c&&r(c)<t?n=o+1:a=o}const i=e[n-1],s=e[n];return i?s&&Math.abs(r(s)-t)<Math.abs(r(i)-t)?s:i:s??null}function cS(e,t){return{group:uS(e),related:pS(e,t)}}function uS(e){switch(e.kind){case"buckets":{const t=e.match.index;return M(t.position)?dS(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return M(t.position)?mS(t.layerId,r,n.pointIndex):hS(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function dS(e,t,r){const n=[];for(const a of t.entries)a.pointIndex!==r&&n.push({anchored:!0,layerId:e,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation});return n}function mS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(On(e,a));return n}function hS(e,t,r,n){const a=e.find(s=>s.columns.includes(r));if(!a)return[];const i=[];for(const s of a.columns)for(const o of s.rects)o.pointIndex!==n&&i.push(On(t,o));return i}function pS(e,t){const r=new Map;if(e.kind==="render-hit-test"||e.kind==="enclosure")return r;const n=e.match.index,a=n.projection==="polar";for(const i of t){if(i.layerId!==n.layerId){a||gS(r,i,e.match.hit);continue}e.kind==="buckets"&&(M(i.position)||i.kind==="buckets"&&fS(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function fS(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&Tt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function gS(e,t,r){switch(t.kind){case"buckets":{const n=fo(t,_e(t.mainAxis,r));if(!n)return;const a=Tt(e,t.layerId);for(const i of n.entries)a.push({anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation});return}case"banded":{const n=lS(t,_e(t.mainAxis,r));if(!n)return;const a=Tt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(On(t.layerId,s));return}case"points":{const n=oS(t,r);if(!n)return;Tt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function Tt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function On(e,t){return{anchored:!0,layerId:e,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function yo(e,t,r){const{columns:n,bands:a}=yS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function yS(e,t){const r=vS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=H(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=H(o.bandCenter);let m=a.get(d);m||(m={bandCenter:o.bandCenter,columns:[]},a.set(d,m)),m.columns.push(u)}u.rects.push(o.entry)}const i=[...n.values()].sort((o,c)=>o.mainMid-c.mainMid),s=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of s)o.columns.sort((c,u)=>c.mainMid-u.mainMid);return{columns:i,bands:s}}function vS(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let m=0;for(const p of r){const h=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(h+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(h,f),xMax:Math.max(h,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:p}}),m++}return d}var SS=1e-9;function vo(e,t,r){const n=bS(e,t);n.sort((i,s)=>i.main-s.main);const a=[];for(const i of n){const s=a[a.length-1];s&&Math.abs(s.main-i.main)<=SS?s.entries.push(i.entry):a.push({main:i.main,entries:[i.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:a}}function bS(e,t){const r=e.data;if(r.size()===0)return[];const n=r.hasVariable(l.POSITION_VARIABLES.x),a=r.hasVariable(l.POSITION_VARIABLES.y);if(!n||!a)return[];const i=r.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,u=o?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,d=M(e.position),m=d?r.getValues(c,{type:"numeric"}):null,p=d?r.getValues(u,{type:"numeric"}):null,h=r.hasVariable(l.GROUP_VARIABLES.group)?r.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,f=[];let g=0;for(const y of r){const v=i[g],x=s[g];if(!l.isDefined(v)||!l.isDefined(x)){g+=1;continue}const I=h?.[g]??null,A=o?x:v;if(d){const V=m?.[g],q=p?.[g];if(!l.isDefined(V)||!l.isDefined(q)){g+=1;continue}const re=o?q:v,W=o?x:q;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:re,y:W,stackMin:V,stackMax:q,groupKey:I,observation:y}})}else f.push({main:A,entry:{isStacked:d,pointIndex:g,x:v,y:x,groupKey:I,observation:y}});g+=1}return f}function xS(e){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",cells:AS(e)}}function AS(e){const t=e.data;if(t.size()===0)return[];const r=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const u of r)if(!t.hasVariable(u))return[];const n=t.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=t.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=t.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=t.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=[];let c=0;for(const u of t){const d=n[c],m=a[c],p=i[c],h=s[c];if(!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(p)||!l.isDefined(h)){c++;continue}o.push({pointIndex:c,xMin:d,xMax:m,yMin:p,yMax:h,observation:u}),c++}return o}function So(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function IS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:xo(e),delaunay:null,delaunayAspectRatio:null};return bo(r,t),r}function LS(e){const t=xo(e).map(r=>{const n=Ct(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t,delaunay:null,delaunayAspectRatio:null}}function bo(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Xc.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function xo(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const s of t){const o=r[i],c=n[i];i+=1,!(!l.isDefined(o)||!l.isDefined(c))&&a.push({pointIndex:a.length,x:o,y:c,observation:s})}return a}function Ao(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:TS(e)}}function Io(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function TS(e){const t=e.identityKey,r=new Map;if(typeof t=="object"){let n=0;for(const a of e.data){const i=a[t.variable];l.isDefined(i)&&r.set(l.getStableKey(i),{pointIndex:n,observation:a}),n+=1}return r}if(t==="index"){let n=0;for(const a of e.data)r.set(String(n),{pointIndex:n,observation:a}),n+=1}return r}function Ya(e,t,r){return t.type==="polar"?wS(e,t.bandAxis):ES(e,t.mainAxis,r)}function wS(e,t){switch(e.spatialKind){case"points":return LS(e);case"buckets":return vo(e,"x","polar");case"rects":return t===null?xS(e):yo(e,t,"polar");case"noop":return So(e);case"render-hit-test":return Ao(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function ES(e,t,r){switch(e.spatialKind){case"points":return IS(e,r);case"buckets":return vo(e,t,"cartesian");case"rects":return yo(e,t,"cartesian");case"noop":return So(e);case"render-hit-test":return Ao(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function VS(e,t,r){if(e.columns.length===0)return null;const n=go(e,_e(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=M(e.position)?RS(a,t,e.mainAxis):CS(a,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:n,distance:Lo(i,t,r)}}function RS(e,t,r){const n=Pt(r,t);return oe(e,i=>kS(i,r,n),{shortCircuitOnZero:!0})}function CS(e,t,r){return oe(e,a=>Lo(a,t,r))}function Lo(e,t,r){return kn(Ot(t.x,e.xMin,e.xMax),Ot(t.y,e.yMin,e.yMax),r)}function kS(e,t,r){return Ot(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function DS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=tu(e.mainAxis,t),i=fo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=To(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:kn(o.x-t.x,o.y-t.y,r)}}function To(e,t,r){return oe(e,a=>Math.abs(Pt(r,a)-t))}function OS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=$t(t,r),i=e.mainAxis==="x",s=i?_S(e.columns,n):go(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?PS(o,a):MS(o,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:(c.xMin+c.xMax)/2,y:(c.yMin+c.yMax)/2,observation:c.observation},index:e,column:s,distance:0}}function _S(e,t){return l.isNonEmptyArray(e)?oe(e,r=>Rt(t,r.mainMid)):null}function PS(e,t){return oe(e,r=>Ot(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function MS(e,t){return oe(e,r=>_i(t,r.xMin,r.xMax)?0:Math.min(Rt(t,r.xMin),Rt(t,r.xMax)),{shortCircuitOnZero:!0})}function NS(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=$t(t,r),i=BS(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=To(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:0}}function BS(e,t){return l.isNonEmptyArray(e)?oe(e,r=>Rt(r.main,t)):null}function FS(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=$t(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&_i(n,i.xMin,i.xMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e};return null}function $S(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=jr(t,r),i=oe(e.points,s=>qa(s,n,a));return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:Math.sqrt(qa(i,n,a))}}function qa(e,t,r){const n=e.unitX??Ct(e.x,e.y).x,a=e.unitY??Ct(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var GS=.05;function US({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a}){const i={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const o of e){if(o.kind==="render-hit-test"){const u=KS(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=zS(o,t,r);if(u)return u;continue}const c=HS({layer:o,cursor:t,aspectRatio:r,warmStarts:n});if(c){if(c.kind==="banded"){c.match.distance<i.distance&&(i.match=c,i.distance=c.match.distance);continue}c.match.distance<s.distance&&(s.match=c,s.distance=c.match.distance)}}return WS({rect:i,continuous:s})}function WS({rect:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+GS?t.match:e.match:e.match??t.match}function HS({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=DS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=VS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=sS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"noop":return null}}function zS(e,t,r){switch(e.kind){case"enclosure":{const n=FS(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=$S(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=NS(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=OS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function KS(e,t,r){const n=r.get(e.layerId);if(!n)return null;const a=n({x:t.x,y:1-t.y});if(!a)return null;const i=e.byKey.get(a.key);return i?{hit:Io(e.layerId,i)}:null}var Z={primary:null,group:[],related:new Map},YS=1,qS=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=YS,this.warmStarts=new Map,this.cachedState=Z,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=Z,this.layerIndexes=e.map(r=>Ya(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>ja(r,t)),this.nonInteractiveLayerIds=Xa(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const s=this.layerIndexes[i],o=this.layerRefs[i];!s||!o||r.set(s.layerId,{index:s,ref:o})}const n=[],a=[];for(const i of e){const s=r.get(i.id),o=ja(i,t);if(s!==void 0&&jS(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(Ya(i,t,this.aspectRatio)),a.push(o)}for(const i of this.warmStarts.keys())e.some(s=>s.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=Xa(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&bo(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return Z;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=US({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),Z;const n=r.match.hit;this.warmStarts.set(n.layerId,n.pointIndex);const a=`${n.layerId}:${n.pointIndex}`;if(this.cachedKey===a)return this.cachedState;const{group:i,related:s}=cS(r,t);return this.cachedKey=a,this.cachedState={primary:n,group:i,related:s},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return Z;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return Z;const n=r.byKey.get(t);if(!n)return Z;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Io(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=Z,this.cachedByKeyId=null,this.cachedByKeyState=Z}};function ja(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Xa(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function jS(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var XS=Math.PI*2;function ZS(e,t){const r=_e(e.mainAxis,t);if(e.mainAxis==="y"){const a=de(te(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=de(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function JS(e,t,r){const n=e.mainAxis==="y"?E(r.observation):R(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Eo(r):wo(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const s=i/2;return e.mainAxis==="y"?{x:0,y:de(te(n+s)),width:"100%",height:de(i)}:{x:de(n-s),y:0,width:de(i),height:"100%"}}function QS(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=z(t.observation),i=K(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=F(t.observation),n=P(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+XS,innerRadius:r,outerRadius:n}}function wo(e){const t=z(e.observation),r=K(e.observation);return t===null||r===null?null:r-t}function Eo(e){const t=F(e.observation),r=P(e.observation);return t===null||r===null?null:r-t}var jt=.5,eb=.4,tb=10,rb=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?ab(e,t,r,n):ib(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?ob(e,t,n):e.spatialKind==="points"?sb(e,n):null,nb=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},ab=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:jt*n.durationScale,baseline:lb(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?cb(e,t.mainAxis,n):{}}),ib=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:jt*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?mb(e,t,r):{}}},sb=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:jt*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?ub(e,t):{}}),ob=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:jt*r.durationScale,axis:t.mainAxis}),lb=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[ne(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const s=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-s:s},cb=(e,t,r)=>{const n=qt(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=co(t,i);if(!s)continue;const o=uo(t,s),c=n(i),u=a.get(o);u?u.keys.push(c):a.set(o,{position:t==="x"?s.x:s.y,keys:[c]})}return _n([...a.values()],r)},ub=(e,t)=>{const r=qt(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=db(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return _n(n,t)},db=(e,t)=>{if(t==="main-axis")return R(e);const r=Kr(e)??R(e);return r===null?null:t==="value-descending"?-r:r},mb=(e,t,r)=>{const n=qt(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Ln(i),{innerRadius:c,outerRadius:u}=Tn(i);if(s===null||o===null||c===null||u===null)continue;const d=po(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),p=a.get(d);p?p.keys.push(m):a.set(d,{position:s,keys:[m]})}return _n([...a.values()],r)},_n=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((o,c)=>o.position-c.position),a=Math.ceil(n.length/tb),i=Math.ceil(n.length/a),s=eb*t.durationScale/i;return n.forEach((o,c)=>{const u=Math.floor(c/a)*s;for(const d of o.keys)r[d]=u}),r},Re=["top","right","bottom","left"],Za={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},hb={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},pb={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},fb=(e,t)=>{const{edges:r,borderRadius:n}=e,a=Math.max(0,Math.min(n,t.width/2,t.height/2)),i=c=>{const[u,d]=pb[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=yb(t,a),o=vb(t,a,i);return Sb(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:bb(c,s,o,i)}))},gb=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),yb=(e,t)=>{const{x:r,y:n,width:a,height:i}=e;return{topLeft:{cx:r+t,cy:n+t,startAngle:Math.PI,endAngle:Math.PI*1.5,radius:t},topRight:{cx:r+a-t,cy:n+t,startAngle:Math.PI*1.5,endAngle:Math.PI*2,radius:t},bottomRight:{cx:r+a-t,cy:n+i-t,startAngle:0,endAngle:Math.PI*.5,radius:t},bottomLeft:{cx:r+t,cy:n+i-t,startAngle:Math.PI*.5,endAngle:Math.PI,radius:t}}},vb=(e,t,r)=>{const{x:n,y:a,width:i,height:s}=e,o=c=>r(c)?t:0;return{top:{start:{x:n+o("topLeft"),y:a},end:{x:n+i-o("topRight"),y:a}},right:{start:{x:n+i,y:a+o("topRight")},end:{x:n+i,y:a+s-o("bottomRight")}},bottom:{start:{x:n+i-o("bottomRight"),y:a+s},end:{x:n+o("bottomLeft"),y:a+s}},left:{start:{x:n,y:a+s-o("bottomLeft")},end:{x:n,y:a+o("topLeft")}}}},Sb=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Re.indexOf(s)+o+Re.length)%Re.length;return Re[c]},n=s=>{const o=r(s,-1);return!t(o)||e[o].lineType!==e[s].lineType||e[o].strokeWidth!==e[s].strokeWidth||e[o].color!==e[s].color},a=Re.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Re],isClosed:!0}]:i.map(s=>{const o=[s];for(let c=r(s,1);t(c)&&!n(c);c=r(c,1))o.push(c);return{firstEdge:s,edges:o,isClosed:!1}})},bb=(e,t,r,n)=>{const a=(m,p,h)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:p,endAngle:h}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=Za[o];if(!e.isClosed&&n(u)){const m=t[u],p=i(m),h=xb(m,p);s.push({type:"move",x:h.x,y:h.y}),s.push(a(m,p,m.endAngle))}else s.push({type:"move",x:r[o].start.x,y:r[o].start.y});s.push({type:"line",x:r[o].end.x,y:r[o].end.y});for(const m of e.edges.slice(1)){const p=Za[m];if(n(p)){const h=t[p];s.push(a(h,h.startAngle,h.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=hb[c];if(e.isClosed){if(n(d)){const m=t[d];s.push(a(m,m.startAngle,m.endAngle))}s.push({type:"close"})}else if(n(d)){const m=t[d];s.push(a(m,m.startAngle,i(m)))}return s},xb=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Ab=/^(?:https?:|mailto:)/i,Ib=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Ab.test(t)},Lb=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...B,...t}).format(r)),Tb=({locale:e,intlOptions:t})=>_(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...B,...t}).format(r)}),_t=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ds(e);case"date":return Lb(e);case"datetime":return Tb(e);case"day_month":return Ms(e);case"decimal":return Os(e);case"duration":return dn(e);case"integer":return _s(e);case"month":return Ns(e);case"month_year":return pn(e);case"percentage":return Ps(e);case"quarter":return fn(e);case"text":return un(e);case"time":return $s(e);case"weekly_date_range":return Bs(e);case"weekly_date_range_with_year":return Fs(e);case"year":return gn(e);case"lookup":return _t({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},wb=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:s,colorScheme:o,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:m}=s;if(m===null)return null;const p=c??i,h=Eb(u,d);return{header:h===null?Vb({layers:e,coordSystem:t,guides:n,primary:m,locale:p,numberFormat:a}):null,rows:Rb({layers:e,scales:r,guides:n,hover:s,locale:p,numberFormat:a,colorScheme:o}),comment:h}};function Eb(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function Vb(e){if(e.coordSystem.type!=="cartesian")return null;const t=Rn(e.guides,"x");if(!t)return null;const r=e.layers.find(i=>i.id===e.primary.layerId);if(!r)return null;const n=l.extractVariableName(r.mapping.x);if(!l.isDefined(n))return null;const a=e.primary.observation[n];return l.isDefined(a)?_t({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function Rb(e){const t=[],r=e.scales.color??null,n=In({colorScheme:e.colorScheme}),a=Ob({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=kb(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...Cb(i,o,{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=vi(i.data,i.mapping),u=Db(s,i,r,c),d=wn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=_b(e.guides,i),p=We(i),h=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=h?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",I=h&&y!==null?a(y):m,A=p(g.observation),V=A===null?"":d(A,g.observation);t.push({swatchColor:v,geom:i.geom,swatchLineType:x,label:I,value:V,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function Cb(e,t,r){return e.tooltip.map(n=>{const a=e.mapping[n.aes],i=U(e.data,a)(t.observation),s=C({valueFormat:pi(e,l.extractVariableName(a)),locale:r.locale,numberFormat:r.numberFormat});return{swatchColor:null,geom:e.geom,swatchLineType:"solid",label:n.key,value:i===null?"":s(i,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${n.aes}`}})}function kb(e,t){const r=[];return t.primary!==null&&t.primary.layerId===e.id&&r.push(t.primary,...t.group),r.push(...t.related.get(e.id)??[]),r}function Db(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,s)=>{a.set(l.getStableKey(i),s)}),e.map((i,s)=>{const o=n(i.observation),c=o===null?null:l.getStableKey(o);return{hit:i,originalIndex:s,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,s)=>i.rank===s.rank?i.originalIndex-s.originalIndex:i.rank-s.rank).map(i=>i.hit)}function Ob({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:_t({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=_t({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const s=n.get(l.getStableKey(i));return s===void 0?a(i):s.label??s.format(i)}}function _b(e,t){return Jr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function Pb(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function Mb(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var Nb=e=>({edges:{top:Oe(e.panelBorder("top")),right:Oe(e.panelBorder("right")),bottom:Oe(e.panelBorder("bottom")),left:Oe(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),Bb=(e,t)=>Oe(e.gridLine(t)),Fb=(e,t)=>{const r=e.tickLine(t);return{...Oe(r),length:r.get("length")}},$b=e=>{const t=e.graph.get("borderColor");return{background:e.graph.get("background"),...t===void 0?{}:{borderColor:t},borderWidth:e.graph.get("borderWidth"),borderRadius:e.graph.get("borderRadius")}},Gb=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Oe=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),Ub=e=>e.fontSize*e.lineHeight,Wb=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),Xt=(e,t)=>({fontFamily:e.get("fontFamily"),fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),Hb=(e,t,r)=>Xt(e.axisLabel(t),r),zb=(e,t,r)=>{const n=e.tickLabel(t);return{...Xt(n,r),offset:n.get("offset")}},Kb=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...Xt(a,n),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},Yb=(e,t,r)=>{const n=e.ruleLabel(t);return{fontFamily:n.get("fontFamily"),fontSize:n.get("fontSize")*r,fontWeight:n.get("fontWeight"),lineHeight:n.get("lineHeight")}},Zt={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},qb={differenceArrow(e){return{type:"annotation",kind:"differenceArrow",annotation:e}},shape(e){return{type:"annotation",kind:"shape",annotation:e}},arrow(e){return{type:"annotation",kind:"arrow",annotation:e}},text(e){return{type:"annotation",kind:"text",annotation:e}},image(e){return{type:"annotation",kind:"image",annotation:e}},sticker(e){return{type:"annotation",kind:"sticker",annotation:e}},pinnedNumber(e){return{type:"annotation",kind:"pinnedNumber",annotation:e}},comment(e){return{type:"annotation",kind:"comment",annotation:e}}},jb=Object.keys(Zt),Xb=e=>Object.hasOwn(Zt,e),it=(e,t)=>{for(const r of jb){const n=Zb(e,r,t);if(n)return n}return null},st=(e,t)=>e[Zt[t]],Pn=(e,t,r)=>({...e,[Zt[t]]:r}),Vo=(e,t)=>{const r=st(e,t.kind);return Pn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Zb=(e,t,r)=>{const n=st(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},Mn=["sticker","pinnedNumber","comment","image"],Jb=e=>Mn.includes(e),Nn=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?ex(e.annotation.at):null;default:return null}},Ro=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null),Co=(e,t,r=Qb)=>{const n=r(t);for(const a of Mn){const i=st(e,a),s=i.findIndex(c=>{const u=Nn({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return Ro(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},Qb=e=>({...e,anchorValue:Ja(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Ja(e.groupValue)}}),Ja=e=>l.readISOInstant(e)??e,ex=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align});function tx(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var rx=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&Bn(r.predicate,t.predicate))??null,Bn=(e,t)=>"and"in e?"and"in t&&Qa(e.and,t.and):"or"in e?"or"in t&&Qa(e.or,t.or):"not"in e?"not"in t&&Bn(e.not,t.not):nx(t)&&e.variable===t.variable&&ax(e,t),nx=e=>"variable"in e,Qa=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Bn(r,a)}),ax=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ei(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&ei(e.range,t.range),ei=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null));function ix(e){return{type:"mapping",mapping:e}}var Jt=(e,t)=>"and"in e?"and"in t&&ti(e.and,t.and):"or"in e?"or"in t&&ti(e.or,t.or):"not"in e?"not"in t&&Jt(e.not,t.not):sx(t)&&e.variable===t.variable&&ox(e,t),sx=e=>"variable"in e,ti=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Jt(r,a)}),ox=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ri(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&ri(e.range,t.range),ri=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ko=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="identity"&&(l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.y))||l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.x)))),Do=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),Oo=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function _o(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(lx),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function lx(e){return e.scaleType==="palette"?cx(e):e}function cx(e){return{...e,palette:ux(e.palette),overrides:dx(e.overrides)}}function ux(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function dx(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Fn=(e,t)=>{const r=$n(e,t);return r===-1?void 0:e[r]},$n=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&Qt(n,t))return r}return-1},Qt=(e,t)=>mx(e.select,t.select)&&e.when?.state===t.when?.state&&hx(e.when?.where,t.when?.where),Po=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>px(e[r],t[r])),fe=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),Gn=e=>e.select.target==="geom",ot=(e,t)=>{const r=Fn(e,t);if(!(r===void 0||!Gn(r)))return r.declarations},mx=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},hx=(e,t)=>e===void 0||t===void 0?e===t:Jt(e,t),px=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function b(e){return{id:e.id??O(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function $e(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>$e(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>$e(e[a],t[a]))}return!1}var Un=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=b({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=it(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:T(e,{annotations:Vo(e.annotations,t)}),revert:new Wn({kind:r,annotation:a,index:n},this.metadata)}}},fx={type:"remove-annotation",deserialize:(e,t)=>new Un(e,t)},Wn=class Mo{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??O()},...t.index!==void 0&&{index:t.index}},this.metadata=b({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Xb(r)||it(t.annotations,n.id))return null;const i=yx(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:Vo(t.annotations,i),o=st(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:T(t,{annotations:Pn(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new Un({id:n.id},this.metadata):new Mo({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},gx={type:"add-annotation",deserialize:(e,t)=>new Wn({kind:e.kind,annotation:e.annotation,index:e.index},t)},yx=(e,t)=>{const r=Nn(t);return r===null?null:Co(e,r)},vx=(e,t)=>{const r=Hn(e);return r===null?null:No(r.points,t)},Sx=e=>Hn(e)!==null,bx=(e,t)=>{const r=Hn(e);if(r===null)return null;const n=No(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},Hn=e=>{const t=Ax[e.kind];return t===null?null:t(e.annotation)},ni=(e,t)=>e.anchorType!=="panel"?null:{points:[$r(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},ai=(e,t)=>e.anchorType!=="panel"?null:{points:[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},xx=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[$r(e,e.offset),$r(t,t.offset)],createPatch:r=>({start:{...e,x:e.x+r.x,y:e.y+r.y},end:{...t,x:t.x+r.x,y:t.y+r.y}})},Ax={text:e=>ni(e.at,t=>({at:t})),sticker:e=>ni(e.at,t=>({at:t})),shape:e=>ai(e.region,t=>({region:t})),image:e=>ai(e.region,t=>({region:t})),arrow:e=>xx(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},$r=(e,t)=>t===void 0||t.unit==="px"?{x:e.x,y:e.y}:{x:e.x+(t.x??0),y:e.y+(t.y??0)},No=(e,t)=>({x:ii(e.map(r=>r.x),t.x),y:ii(e.map(r=>r.y),t.y)}),ii=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:zt(t,r,n)},Bo=(e,t,r)=>{const n=t.annotation;if(!Tx(n,r))return null;const a=st(e.annotations,t.kind),i=Ix(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:T(e,{annotations:Pn(e.annotations,t.kind,s)}),inverse:Lx(n,r)}},Ix=(e,t)=>{const r=new Set(Object.entries(t).filter(([,n])=>n===void 0).map(([n])=>n));return Object.fromEntries(Object.entries({...e,...t}).filter(([n])=>!r.has(n)))},Lx=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},Tx=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),zn=class Fo{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=b({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=it(t.annotations,n);if(i===null||i.kind!==r)return null;const s=Bo(t,i,a);return s===null?null:{spec:s.spec,revert:new Fo({kind:r,id:n,patch:s.inverse},this.metadata)}}},wx={type:"update-annotation",deserialize:(e,t)=>new zn(e,t)},$o=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=b({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=it(e.annotations,this.params.id);if(t===null)return null;const r=bx(t,this.params.translation);if(r===null)return null;const n=Bo(e,t,r);return n===null?null:{spec:n.spec,revert:new zn({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},Ex={type:"move-annotation",deserialize:(e,t)=>new $o(e,t)},Vx=["cartesian","polar","flip"],Se=new Wt,Go=class Uo{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=b({...r,description:_x(t)})}apply(t){const r="previous"in this.params?this.params.previous:Px(t,this.params);if(r===null)return null;const n=T(t,r);return n===t?null:{spec:n,revert:new Uo({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},Rx={type:"set-chart-type",deserialize:(e,t)=>new Go(e,t)},Cx={type:"sum"},kx={type:"identity"},Dx=["bar","line","area","point"],Ox=e=>{const t=e.layers.filter(zo),[r]=t;if(r===void 0||!t.every(s=>s.geom===r.geom&&s.position===r.position))return null;const{coords:n}=e,{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},_x=e=>"previous"in e?"Restore the previous chart type":`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,Px=(e,t)=>{if(!Bx(t))return null;const r=Wx(e.coords,t),n=Mx(e,t),a=$x({...e,mapping:n},t,n!==e.mapping);return{coords:r,layers:a,scales:zx(e,a,r.coordType),mapping:n}},Mx=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Nx(e,t,r);return n===r?e.mapping:{...e.mapping,x:n}},Nx=(e,t,r)=>Wo(t)?"":r===""?l.inferXVariable(e.data):r,Wo=e=>e.coordType==="polar"&&e.theta==="y",Bx=e=>Vx.includes(e.coordType)&&Ho(e.geom)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),Ho=e=>Dx.includes(e),zo=e=>Ho(e.geom)&&!Fx(e.stat),Fx=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},$x=(e,t,r)=>{const{coordType:n,geom:a,position:i}=t,s=e.coords.coordType!==n;return hs(Se,qr(e.layers,o=>{if(!zo(o))return o;const c=Gx(o.stat,t);return s||r||o.geom!==a||o.position!==i||c!==o.stat?Ux(e,{...o,stat:c},t):o}))},Gx=(e,t)=>Wo(t)?e.type==="identity"?Cx:e:e.type==="sum"?kx:e,Ux=(e,t,{geom:r,position:n,coordType:a})=>{const i={geom:t.geom===r,coordType:e.coords.coordType===a,position:t.position===n},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...rt(Se,e.mapping,a,{type:"layer",id:t.id,geom:r,mapping:t.mapping,stat:t.stat,position:n,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:o},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Wx=(e,t)=>{const r=Hx(e,t);return(0,Ir.default)(r,e)?e:r},Hx=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return Cr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:At;return Cr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},zx=(e,t,r)=>{const n=kr(Se,t),a=kr(Se,e.layers),i=e.coords.coordType==="polar";return qr(e.scales,s=>{const o=Kx(s,n,a);return qx(o,r,i)})},Kx=(e,t,r)=>{if(e.scaledAesthetic===t.discreteAxis&&e.scaleType!=="discrete")return gs(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}));if(e.scaledAesthetic===t.zeroAxis&&e.scaleType==="continuous"){const n=Yx(e.nice,t,r);return e.zero&&e.nice===n?e:{...e,zero:!0,nice:n}}return e},Yx=(e,t,r)=>t.niceZeroAxis===r.niceZeroAxis?e:t.niceZeroAxis?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,qx=(e,t,r)=>{if(e.scaleType!=="discrete"||!et(e.scaledAesthetic))return e;if(t==="polar")return e.padding===0?e:{...e,padding:0};if(!r)return e;const{padding:n}=l.DISCRETE_SCALE_DEFAULTS;return e.padding===n?e:{...e,padding:n}},Ko=class Yo{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=b({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:w(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new Yo({textScale:r},this.metadata)}}},jx={type:"set-appearance-text-scale",deserialize:(e,t)=>new Ko(e,t)},er=e=>e==="both"?["x","y"]:[e],qo=e=>e==="both"?"the":`${e} axis`;function Ge(e,t){return Jx(e)?e[t]:e}function Xx(e,t){return e.config.axes[t]??{}}function Zx(e,t,r){if(t!=="ySecondary")return w(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=jo(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,T(e,{config:T(e.config,{axes:i})})}function Jx(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function jo(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],s=a in t?Qx(i,t[a]):i;s!==i&&(n=!0),s!==void 0&&(r[a]=s)}return n?Object.keys(r).length>0?r:void 0:e}function Qx(e,t){return l.isPlainObject(t)?jo(l.isPlainObject(e)?e:void 0,t):t}var Xo=class Zo{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis label to ${tA(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=Xx(t,r).label;if(a===n)return null;const i=Zx(t,r,{label:n});return i===t?null:{spec:i,revert:new Zo(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},eA={type:"set-axis-label",deserialize:(e,t)=>new Xo(e,t)};function tA(e){return e===void 0?"(inherited)":e??"(none)"}var Jo=class Qo{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:w(t,{config:{axes:{[r]:{position:n}}}}),revert:new Qo({axis:r,position:a},this.metadata)}}},rA={type:"set-axis-position",deserialize:(e,t)=>new Jo(e,t)},el=class tl{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:w(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new tl({axis:r,tickMode:a},this.metadata)}}},nA={type:"set-axis-tick-mode",deserialize:(e,t)=>new el(e,t)},rl=class nl{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new nl({axis:r,isVisible:a},this.metadata)}}},aA={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new rl(e,t)},al=class il{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new il({axis:r,isVisible:a},this.metadata)}}},iA={type:"set-axis-visibility",deserialize:(e,t)=>new al(e,t)},sl=class ol{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=b({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:w(t,{config:{content:{caption:this.params.caption}}}),revert:new ol({caption:r},this.metadata)}}},sA={type:"set-content-caption",deserialize:(e,t)=>new sl(e,t)},ll=class cl{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=b({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if($e(r,this.params.source))return null;const n=T(t.config.content,{source:this.params.source});return{spec:T(t,{config:T(t.config,{content:n})}),revert:new cl({source:r},this.metadata)}}},oA={type:"set-content-source",deserialize:(e,t)=>new ll(e,t)},ul=class dl{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=b({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:w(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new dl({subtitle:r},this.metadata)}}},lA={type:"set-content-subtitle",deserialize:(e,t)=>new ul(e,t)},ml=class hl{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=b({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:w(t,{config:{content:{title:this.params.title}}}),revert:new hl({title:r},this.metadata)}}},cA={type:"set-content-title",deserialize:(e,t)=>new ml(e,t)},pl=class fl{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=b({...r,description:`Set ${qo(t.axis)} grid line style to ${dA(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=er(r),i={x:t.config.axes.x.grid.lineStyle,y:t.config.axes.y.grid.lineStyle};return a.every(s=>i[s]===Ge(n,s))?null:{spec:a.reduce((s,o)=>w(s,{config:{axes:{[o]:{grid:{lineStyle:Ge(n,o)}}}}}),t),revert:new fl({axis:r,lineStyle:r==="both"?i:i[r]},this.metadata)}}},uA={type:"set-grid-line-style",deserialize:(e,t)=>new pl(e,t)},dA=({axis:e,lineStyle:t})=>{const r=er(e).map(n=>Ge(t,n));return[...new Set(r)].join(" and ")},mA={type:"set-grid-line-width",deserialize:(e,t)=>new gl(e,t)},gl=class yl{constructor(t,r={}){this.type="set-grid-line-width";const n=hA(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=b({...r,description:`Set ${qo(t.axis)} grid line width to ${pA(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=er(r),i={x:t.config.axes.x.grid.lineWidth,y:t.config.axes.y.grid.lineWidth};return a.every(s=>i[s]===Ge(n,s))?null:{spec:a.reduce((s,o)=>w(s,{config:{axes:{[o]:{grid:{lineWidth:Ge(n,o)}}}}}),t),revert:new yl({axis:r,lineWidth:r==="both"?i:i[r]},this.metadata)}}},hA=e=>typeof e=="object"&&e!==null?{x:Sr(e.x),y:Sr(e.y)}:Sr(e),Sr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),pA=(e,t)=>{const r=er(e).map(n=>Ge(t,n)??"(theme)");return[...new Set(r)].join(" and ")},vl=class Sl{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new Sl({axis:r,isVisible:a},this.metadata)}}},fA={type:"set-grid-visibility",deserialize:(e,t)=>new vl(e,t)},bl=class xl{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:w(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new xl({compareWith:r},this.metadata)}}},gA={type:"set-headline-compare-with",deserialize:(e,t)=>new bl(e,t)},Al=class Il{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:w(t,{config:{headline:{position:this.params.position}}}),revert:new Il({position:r},this.metadata)}}},yA={type:"set-headline-position",deserialize:(e,t)=>new Al(e,t)},Ll=class Tl{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:w(t,{config:{headline:{show:this.params.show}}}),revert:new Tl({show:r},this.metadata)}}},vA={type:"set-headline-show",deserialize:(e,t)=>new Ll(e,t)},wl=class El{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:w(t,{config:{headline:{size:this.params.size}}}),revert:new El({size:r},this.metadata)}}},SA={type:"set-headline-size",deserialize:(e,t)=>new wl(e,t)},Ie=class wt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=b({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],s=$n(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new wt({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!Qt(y,n));return{spec:br(t,r,g),revert:f}}if(o!==void 0){if(Po(o.declarations,c))return null;const f={...o,declarations:c},g=new wt({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:br(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},p=[...i.slice(0,d),m,...i.slice(d)],h=new wt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:br(t,r,p),revert:h}}},bA=e=>{const{rule:t}=e;if(t==null)throw new l.UserInputError({code:"INVALID_STYLE_RULE",message:"Command 'set-style-rule' is missing its 'rule'.",suggestion:"Send the entry's 'select' (and 'when') with 'declarations: null' to remove it."})},xA={type:"set-style-rule",deserialize:(e,t)=>(bA(e),new Ie(e,t))},br=(e,t,r)=>T(e,{styles:{...e.styles,[t]:r}}),AA={type:"set-highlight-dim-style",deserialize:(e,t)=>new Vl(e,t)},Vl=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=b({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Rl(e)===this.params.dimStyle)return null;const t=new Ie({list:"overrides",rule:LA(this.params.dimStyle)},this.metadata).apply(e);return t||null}},IA={select:{target:"geom"},when:{state:"dimmed"}},Rl=e=>{const t=Fn(e.styles.overrides,IA);return(t!==void 0&&Gn(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},LA=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Cl=class kl{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:w(t,{config:{legend:{align:this.params.align}}}),revert:new kl({align:r},this.metadata)}}},TA={type:"set-legend-align",deserialize:(e,t)=>new Cl(e,t)},Dl=class Ol{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:w(t,{config:{legend:{display:this.params.display}}}),revert:new Ol({display:r},this.metadata)}}},wA={type:"set-legend-display",deserialize:(e,t)=>new Dl(e,t)},_l=class Pl{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:w(t,{config:{legend:{position:this.params.position}}}),revert:new Pl({position:r},this.metadata)}}},EA={type:"set-legend-position",deserialize:(e,t)=>new _l(e,t)},Ml=class Nl{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=b({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:w(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Nl({abbreviation:r},this.metadata)}}},VA={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Ml(e,t)},Bl=class Fl{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=b({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:w(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Fl({decimals:r},this.metadata)}}},RA={type:"set-number-format-decimals",deserialize:(e,t)=>new Bl(e,t)},$l=class Gl{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=kA(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:w(t,{config:{content:{[a]:n}}}),revert:new Gl({slot:r,isVisible:i},this.metadata)}}},CA={type:"toggle-content-visibility",deserialize:(e,t)=>new $l(e,t)},si={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function kA(e){return Object.hasOwn(si,e)?si[e]:void 0}var Ul=class Wl{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=b({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if($e(i.xLimits,a.xLimits)&&$e(i.yLimits,a.yLimits))return null;const s={};r!==void 0&&(s.xLimits=a.xLimits),n!==void 0&&(s.yLimits=a.yLimits);const o=new Wl(s,this.metadata);return{spec:T(t,{coords:OA(t.coords,i)}),revert:o}}},DA={type:"set-coord-limits",deserialize:(e,t)=>new Ul(e,t)};function OA(e,t){switch(e.coordType){case"cartesian":return{...e,params:{...e.params,...t}};case"flip":return{...e,params:{...e.params,...t}};case"polar":return{...e,params:{...e.params,...t}}}}var Hl=class zl{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:zt(t.innerRadius,0,1)},this.metadata=b({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:T(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new zl({innerRadius:n},this.metadata)}}},_A={type:"set-polar-inner-radius",deserialize:(e,t)=>new Hl(e,t)},PA={type:"set-polar-start-angle",deserialize:(e,t)=>new Kl(e,t)},Kl=class Yl{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:oi(t.startAngle)},this.metadata=b({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return oi(n)===this.params.startAngle?null:{spec:T(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Yl({startAngle:n},this.metadata)}}},xr=360,oi=e=>(e%xr+xr)%xr,Kn=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=b({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new Yn({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:T(e,{highlights:n}),revert:a}}},MA={type:"remove-highlight",deserialize:(e,t)=>new Kn(e,t)},Yn=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??O(),scope:e.scope??"data-point"},this.metadata=b({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const s=new Kn({id:r},this.metadata),o={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:T(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},NA={type:"add-highlight",deserialize:(e,t)=>new Yn(e,t)};function qn(e,t){return{...e,params:{...e.params,...t}}}function tr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function jn(e,t){return T(e,{layers:[...e.layers,t]})}function $(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:T(e,{layers:Ci(e.layers,n,r)})}function rr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:T(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Xn=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=b({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=rr(e,this.params.layerId);return n===e?null:{spec:n,revert:new Zn({layer:r,index:t},this.metadata)}}},BA={type:"remove-layer",deserialize:(e,t)=>new Xn(e,t)},Zn=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??O()},...e.index!==void 0&&{index:e.index}},this.metadata=b({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:T(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Xn({layerId:t.id},this.metadata)}}},FA={type:"add-layer",deserialize:(e,t)=>new Zn(e,t)},ql=class jl{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=b({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!Y(k(t.layers,r),"bar"))return null;const a=fe("bar",r),i=ot(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new Ie({list:"overrides",rule:{...a,declarations:GA(i,n)}}).apply(t);if(!o)return null;const c=new jl({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},$A={type:"set-bar-border-radius",deserialize:(e,t)=>new ql(e,t)},GA=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},UA={type:"set-bar-width",deserialize:(e,t)=>new Zl(e,t)},Xl=.05,WA=1,Zl=class Jl{constructor(t,r={}){this.type="set-bar-width";const n=zt(t.width,Xl,1);this.params={...t,width:n},this.metadata=b({...r,description:`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(!Number.isFinite(this.params.width))return null;const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"bar");if(!Y(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:$(t,r.id,qn(r,{width:this.params.width})),revert:new Jl({layerId:r.id,width:n},this.metadata)}}},Ql=class ec{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=b({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:$(t,r.id,tr(r,{format:this.params.format})),revert:new ec({layerId:r.id,format:n},this.metadata)}}},HA={type:"set-data-labels-format",deserialize:(e,t)=>new Ql(e,t)},tc=class rc{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=b({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:$(t,r.id,{...r,position:this.params.position}),revert:new rc({layerId:r.id,position:n},this.metadata)}}},zA={type:"set-layer-position",deserialize:(e,t)=>new tc(e,t)},nc=class ac{constructor(t,r={}){this.type="set-layer-stat";const n=ms(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=b({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return YA(n,this.params.stat)?null:{spec:$(t,r.id,{...r,stat:this.params.stat}),revert:new ac({layerId:r.id,stat:n},this.metadata)}}},KA={type:"set-layer-stat",deserialize:(e,t)=>new nc(e,t)},YA=(e,t)=>{if(e.type!==t.type)return!1;const r=e,n=t,a=new Set([...Object.keys(r),...Object.keys(n)]);for(const i of a)if(!Object.is(r[i],n[i]))return!1;return!0},ic=class sc{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=b({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;return n===this.params.yScaleType?null:{spec:$(t,r.id,{...r,yScaleType:this.params.yScaleType}),revert:new sc({layerId:r.id,yScaleType:n},this.metadata)}}},qA={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ic(e,t)},oc=class lc{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=b({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");if(!Y(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:$(t,r.id,qn(r,{interpolate:this.params.interpolate})),revert:new lc({layerId:r.id,interpolate:n},this.metadata)}}},jA={type:"set-line-interpolation",deserialize:(e,t)=>new oc(e,t)},cc=class uc{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=b({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");if(!Y(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:$(t,r.id,qn(r,{missingValues:this.params.missingValues})),revert:new uc({layerId:r.id,missingValues:n},this.metadata)}}},XA={type:"set-line-missing-values",deserialize:(e,t)=>new cc(e,t)},dc=class mc{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=b({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=k(t.layers,r);if(!Y(a,"line","area"))return null;const i=ot(t.styles.overrides,fe(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=JA(i,n),c=new Ie({list:"overrides",rule:a.geom==="area"?{...fe("area",r),declarations:o}:{...fe("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new mc({layerId:r,lineWidth:s},this.metadata)}:null}},ZA={type:"set-line-width",deserialize:(e,t)=>new dc(e,t)},JA=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},hc=class pc{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=b({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!Y(k(t.layers,r),"point"))return null;const a=fe("point",r),i=ot(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new Ie({list:"overrides",rule:{...a,declarations:eI(i,n)}}).apply(t);return o?{spec:o.spec,revert:new pc({layerId:r,size:s},this.metadata)}:null}},QA={type:"set-point-size",deserialize:(e,t)=>new hc(e,t)},eI=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},fc=class gc{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=b({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"rule");if(!Y(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([s])=>s!=="label")):{...r.params,label:a};return{spec:$(t,r.id,{...r,params:i}),revert:new gc({layerId:r.id,label:n??null},this.metadata)}}},tI={type:"set-rule-label",deserialize:(e,t)=>new fc(e,t)},yc=class vc{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=b({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"rule");if(!Y(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:$(t,r.id,{...r,mapping:i}),revert:new vc({layerId:r.id,value:a},this.metadata)}}},rI={type:"set-rule-value",deserialize:(e,t)=>new yc(e,t)},nI={type:"set-stat-line",deserialize:(e,t)=>new Sc(e,t)},Sc=class bc{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=b({...r,description:uI(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=iI(t),n=this.buildStatLine(t,r?.line===this.params.line?r.layer.id:void 0);if(this.params.line!=="none"&&n===null||r===void 0&&n===null||r!==void 0&&n!==null&&cI(r.layer,n))return null;const a=new bc({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:$(t,r.layer.id,n),revert:a};const i=r===void 0?t:rr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:jn(i,n),revert:a}}buildStatLine(t,r){if(this.params.line==="none")return null;if(this.params.removedLayer!==void 0)return this.params.removedLayer;const n=this.params.line==="trend"?sI(this.params):oI(t,this.params);if(n===null)return null;const a=rt(Se,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},aI="linear",iI=e=>{const t=Do(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=Oo(e.layers);if(r!==void 0)return{line:"average",layer:r}},sI=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??aI}),interactive:!1}),oI=(e,{group:t,label:r})=>{const n=lI(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),s=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:s?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},lI=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),cI=(e,t)=>(0,Ue.isEqual)({...e,id:""},{...t,id:""}),uI=e=>e==="none"?"Hide stat line":`Show ${e} line`,xc=class Ac{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=b({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:$(t,r.id,tr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new Ac({layerId:r.id,showCategoryLabels:n},this.metadata)}}},dI={type:"toggle-category-labels",deserialize:(e,t)=>new xc(e,t)},Ic=class Lc{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=b({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:$(t,r.id,tr(r,{showDataLabels:this.params.showDataLabels})),revert:new Lc({layerId:r.id,showDataLabels:n},this.metadata)}}},mI={type:"toggle-data-labels",deserialize:(e,t)=>new Ic(e,t)},hI={type:"toggle-goal-line",deserialize:(e,t)=>new Tc(e,t)},Tc=class Gr{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=b({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=ko(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=rr(t,r.id);return a===t?null:{spec:a,revert:new Gr({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:jn(t,n),revert:new Gr({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return rt(Se,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??pI}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},pI=0,fI={type:"toggle-line-fill",deserialize:(e,t)=>new wc(e,t)},wc=class Ec{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=b({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!Y(k(t.layers,r),"line"))return null;const i=fe("line",r),s=ot(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new Ie({list:"overrides",rule:{...i,declarations:yI(s,n?a??gI:null)}}).apply(t);if(!u)return null;const d=new Ec({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},gI=.2,yI=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},vI={type:"toggle-line-points",deserialize:(e,t)=>new Vc(e,t)},Vc=class Ur{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=b({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");return Y(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:jn(t,this.params.removedLayer??rt(Se,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new Ur({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:rr(t,n.id),revert:new Ur({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:en(n,[r]))}},Rc=class Cc{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=b({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:$(t,r.id,tr(r,{showStackTotals:this.params.showStackTotals})),revert:new Cc({layerId:r.id,showStackTotals:n},this.metadata)}}},SI={type:"toggle-stack-totals",deserialize:(e,t)=>new Rc(e,t)};function lt(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function ct(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:T(e,{scales:Ci(e.scales,n,r)})}function ut(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}var kc=class Dc{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=b({...r,description:`Set ${ut(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=lt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const s={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},o=ct(t,this.params.scaledAesthetic,s),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:o,revert:new Dc(c,this.metadata)}}},bI={type:"set-scale-domain",deserialize:(e,t)=>new kc(e,t)},Oc=class _c{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=b({...r,description:`Set ${ut(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=lt(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||$e(r.palette,this.params.palette)?null:{spec:ct(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new _c({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},xI={type:"set-scale-palette",deserialize:(e,t)=>new Oc(e,t)},Pc=class Mc{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=b({...r,description:`Set ${ut(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=lt(t,this.params.scaledAesthetic);if(!r||!II(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:ct(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Mc({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},AI={type:"set-scale-reverse",deserialize:(e,t)=>new Pc(e,t)};function II(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Nc=class Bc{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=b({...r,description:`Set ${ut(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=lt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:ct(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Bc({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},LI={type:"set-scale-transform",deserialize:(e,t)=>new Nc(e,t)},Fc=class $c{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=b({...r,description:`Set ${ut(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=lt(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:ct(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new $c({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},TI={type:"set-scale-zero",deserialize:(e,t)=>new Fc(e,t)},Gc=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new Gc;S.register(Rx);S.register(FA);S.register(BA);S.register(HA);S.register(zA);S.register(KA);S.register(qA);S.register(jA);S.register(ZA);S.register($A);S.register(UA);S.register(QA);S.register(XA);S.register(tI);S.register(rI);S.register(nI);S.register(dI);S.register(mI);S.register(hI);S.register(fI);S.register(vI);S.register(SI);S.register(bI);S.register(xI);S.register(AI);S.register(LI);S.register(TI);S.register(jx);S.register(eA);S.register(nA);S.register(rA);S.register(aA);S.register(iA);S.register(sA);S.register(oA);S.register(lA);S.register(cA);S.register(uA);S.register(mA);S.register(fA);S.register(gA);S.register(yA);S.register(vA);S.register(SA);S.register(AA);S.register(TA);S.register(wA);S.register(EA);S.register(VA);S.register(RA);S.register(CA);S.register(NA);S.register(MA);S.register(xA);S.register(gx);S.register(fx);S.register(wx);S.register(Ex);S.register(DA);S.register(_A);S.register(PA);var Uc=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,s=e.apply(t);if(!s)return a||(this.hasOpenRun=!1),i(t,null);const o=r?.({spec:s.spec,command:e})??null,c=o?o.adopted:s.spec;return c?(this.push(e,c,s.revert,a),i(c,o?.value??null)):(a||(this.hasOpenRun=!1),i(t,o?.value??null))})}seal(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"seal"}),!0):!1)}undo(e,t){return this.withReentrancyGuard(()=>{const r=this.undoStack[this.undoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.undoStack.pop(),this.redoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"undo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}redo(e,t){return this.withReentrancyGuard(()=>{const r=this.redoStack[this.redoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.redoStack.pop(),this.undoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"redo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}clear(){this.withReentrancyGuard(()=>{this.hasOpenRun=!1,!(this.undoStack.length===0&&this.redoStack.length===0)&&(this.undoStack=[],this.redoStack=[],this.emit({type:"clear"}))})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null,undoStack:li(this.undoStack),redoStack:li(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],s=this.hasOpenRun&&i!==void 0&&EI(i.command,e);if(n&&s){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},wI=Object.freeze([]),EI=(e,t)=>{if(e.type!==t.type||e.target.kind!==t.target.kind)return!1;const r=e.target,n=t.target;for(const a of new Set([...Object.keys(r),...Object.keys(n)]))if(!Object.is(r[a],n[a]))return!1;return!0},li=e=>e.length===0?wI:e.map(t=>t.command.metadata),VI=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return!1;switch(e.kind){case"annotation":return t.kind==="annotation"&&e.id===t.id;case"highlight":return t.kind==="highlight"&&e.id===t.id;case"styleRule":return t.kind==="styleRule"&&e.list===t.list&&Qt(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observation":return t.kind==="observation"&&e.layerId===t.layerId&&e.index===t.index;case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},RI=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.seal(),t=this.frame;return this.frame=null,e?t:null}},CI=class{constructor(e){this.compiler=e,this.history=new Uc,this.current=null,this.last=null,this.hostInput=null,this.run=new RI(this.history)}get compiled(){return this.current}compile(e){return this.last=e,this.hostInput=e.input,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.input!==this.hostInput&&e.input!==t.input,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes;if(this.hostInput=e.input,!r&&!n&&!a)return null;let i=null;r?this.run.close():i=this.closeAndConvert();const s=this.last,o=s&&!r?s.input:e.input;this.last={input:o,data:e.data,customPalettes:e.customPalettes};const c=this.current,u=r||a||!c?this.absorb(this.compiler.compile({input:o,data:e.data,customPalettes:e.customPalettes})):this.absorb(this.compiler.recompile({spec:c.spec,data:e.data}));return r&&u.ok&&this.history.clear(),{result:u,inputChanged:r,...i&&{sealedInput:i.input}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.sealNotification(!1);c&&n.push(c)}const{current:a,last:i,history:s}=this;if(!a||!i)return n;const o=s.apply(e,a.spec,({spec:c})=>{const u=this.commit(c,i,r,e);return{adopted:u.ok?u.compiled.spec:null,value:u}},t);return o&&n.push(this.renderedNotification(o,e,r)),n}seal(){const e=this.sealNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const s=this.commit(a,r);return{adopted:s.ok?s.compiled.spec:null,value:{result:s,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{compiled:e.compiled}:{compiled:e.compiled,result:e,command:t,...e.input&&{input:e.input}}:{errors:e.errors}}sealNotification(e){const t=this.closeAndConvert();return t?{result:t.result,input:t.input,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{input:this.recordCompiledInput(t.spec,r),result:e.result,command:e.command}}commit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const s={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:s,command:n}),s}this.run.clear();const i=this.recordCompiledInput(a.compiled.spec,t);return{ok:!0,compiled:a.compiled,warnings:a.warnings,input:i}}recordCompiledInput(e,t){const r=_o(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},kI=500,DI="normal",Jn={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},OI=e=>{const t=e.style??"normal",r=e.weight??500,n=e.family.includes(",")?e.family:`'${e.family}'`;return`${t} ${r} ${e.size}px ${n}`},Qn=e=>typeof e!="string"?e??500:Jn[e],_I="\0",PI=class{constructor(e){this.inner=e,this.cache=new Map}measureText(e,t){const r=this.getCacheKey(e,t),n=this.cache.get(r);if(n)return n;const a=this.inner.measureText(e,t);return this.cache.set(r,a),a}getCacheKey(e,t){return[t.family,t.size,Qn(t.weight),t.style??"normal",e].join(_I)}},MI={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56};var NI=1.05,BI=.84,FI=.21,$I=class{measureText(e,t){let r=0;for(const i of e)r+=(MI[i]??.55)*t.size;Qn(t.weight)>=Jn.semiBold&&(r*=NI);const n=BI*t.size,a=FI*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=Ny;exports.ARROW_DEFAULTS=ue;exports.AXIS_KEYS=Xr;exports.AddAnnotationCommand=Wn;exports.AddHighlightCommand=Yn;exports.AddLayerCommand=Zn;exports.BORDER_RADIUS_PX=Cn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Vh;exports.COMPILER_STAGE_KEYS=nf;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=PI;exports.CommandRegistry=Gc;exports.CommandStackManager=Uc;exports.Compiler=Es;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_AREA_ALPHA=l.DEFAULT_AREA_ALPHA;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_BORDER_WIDTH=l.DEFAULT_BORDER_WIDTH;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=DI;exports.DEFAULT_FONT_WEIGHT=kI;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRID_LINE_COLOR=l.DEFAULT_GRID_LINE_COLOR;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DEFAULT_TEXT_PRIMARY=l.DEFAULT_TEXT_PRIMARY;exports.DEFAULT_TEXT_SECONDARY=l.DEFAULT_TEXT_SECONDARY;exports.DEFAULT_TICK_LABEL_OFFSET=l.DEFAULT_TICK_LABEL_OFFSET;exports.DEFAULT_TICK_LINE_COLOR=l.DEFAULT_TICK_LINE_COLOR;exports.DEFAULT_TICK_LINE_LENGTH=l.DEFAULT_TICK_LINE_LENGTH;exports.DIFFERENCE_ARROW_DEFAULTS=bt;exports.DIVERGING_SCHEME_NAMES=cs;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ie;exports.GraphCompilationSession=CI;exports.HEADLINE_SWATCH_GAP=_v;exports.HEADLINE_SWATCH_SIZE=Ov;exports.HEADLINE_TREND_GAP=Nv;exports.HEADLINE_TREND_ICON_SIZE=Mv;exports.HEADLINE_VALUE_LABEL_GAP=Pv;exports.HeuristicTextMeasurer=$I;exports.HoverEngine=qS;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=mf;exports.LINE_STYLE_TYPES=zr;exports.LayoutCompiler=hy;exports.MAX_BAR_WIDTH=WA;exports.MIN_BAR_WIDTH=Xl;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=$o;exports.NAMED_WEIGHTS=Jn;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=Mn;exports.OUT_OF_VIEW_MARGIN_PX=By;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=ju;exports.POSITION_TYPES=au;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=Z;exports.RemoveAnnotationCommand=Un;exports.RemoveHighlightCommand=Kn;exports.RemoveLayerCommand=Xn;exports.SCHEME_ALIASES=us;exports.SEQUENTIAL_SCHEME_NAMES=Rh;exports.SHAPE_DEFAULTS=ce;exports.SIBLING_OVERLAP_THRESHOLD_PX=Fy;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=Ko;exports.SetAxisLabelCommand=Xo;exports.SetAxisPositionCommand=Jo;exports.SetAxisTickModeCommand=el;exports.SetAxisTicksVisibilityCommand=rl;exports.SetAxisVisibilityCommand=al;exports.SetBarBorderRadiusCommand=ql;exports.SetBarWidthCommand=Zl;exports.SetChartTypeCommand=Go;exports.SetContentCaptionCommand=sl;exports.SetContentSourceCommand=ll;exports.SetContentSubtitleCommand=ul;exports.SetContentTitleCommand=ml;exports.SetCoordLimitsCommand=Ul;exports.SetDataLabelsFormatCommand=Ql;exports.SetGridLineStyleCommand=pl;exports.SetGridLineWidthCommand=gl;exports.SetGridVisibilityCommand=vl;exports.SetHeadlineCompareWithCommand=bl;exports.SetHeadlinePositionCommand=Al;exports.SetHeadlineShowCommand=Ll;exports.SetHeadlineSizeCommand=wl;exports.SetHighlightDimStyleCommand=Vl;exports.SetLayerPositionCommand=tc;exports.SetLayerStatCommand=nc;exports.SetLayerYScaleTypeCommand=ic;exports.SetLegendAlignCommand=Cl;exports.SetLegendDisplayCommand=Dl;exports.SetLegendPositionCommand=_l;exports.SetLineInterpolationCommand=oc;exports.SetLineMissingValuesCommand=cc;exports.SetLineWidthCommand=dc;exports.SetNumberFormatAbbreviationCommand=Ml;exports.SetNumberFormatDecimalsCommand=Bl;exports.SetPointSizeCommand=hc;exports.SetPolarInnerRadiusCommand=Hl;exports.SetPolarStartAngleCommand=Kl;exports.SetRuleLabelCommand=fc;exports.SetRuleValueCommand=yc;exports.SetScaleDomainCommand=kc;exports.SetScalePaletteCommand=Oc;exports.SetScaleReverseCommand=Pc;exports.SetScaleTransformCommand=Nc;exports.SetScaleZeroCommand=Fc;exports.SetStatLineCommand=Sc;exports.SetStyleRuleCommand=Ie;exports.SpecResolver=vs;exports.Stat=Ae;exports.TAU=pe;exports.TEXT_ANNOTATION_DEFAULTS=xt;exports.ToggleCategoryLabelsCommand=xc;exports.ToggleContentVisibilityCommand=$l;exports.ToggleDataLabelsCommand=Ic;exports.ToggleGoalLineCommand=Tc;exports.ToggleLineFillCommand=wc;exports.ToggleLinePointsVisibilityCommand=Vc;exports.ToggleStackTotalsCommand=Rc;exports.UpdateAnnotationCommand=zn;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=di;exports.annotation=qb;exports.areAnchorsEqual=De;exports.areEditMenuTriggersEqual=uv;exports.areEditTargetsEqual=VI;exports.areEndpointsComparable=mi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=Ro;exports.arePointerRegionListsEqual=nv;exports.arePredicatesEqual=Jt;exports.areStyleDeclarationsEqual=Po;exports.areStyleRuleAddressesEqual=Qt;exports.buildAverageLineSymbols=Oy;exports.buildCalloutHitRegions=My;exports.buildColumnKey=uo;exports.buildDataLabelsContent=_g;exports.buildDiagnostic=Ri;exports.buildEditMenuTriggerRegion=lv;exports.buildFontString=OI;exports.buildLayerIntroPlan=rb;exports.buildLayerStyleAddress=fe;exports.buildLayerYValueFormatter=wn;exports.buildObservationAnchor=Je;exports.buildObservationPredicate=Xy;exports.buildPinnedNumberValueFormatter=xv;exports.buildPolarBarArcPath=Qv;exports.buildSliceGroupKey=po;exports.buildTooltipContent=wb;exports.canAnchorDirectLabels=ji;exports.canPlaceDataLabels=Og;exports.clampAnnotationTranslation=vx;exports.commandRegistry=S;exports.compileChromeStyles=xs;exports.compileStylesheetForLayer=Np;exports.computeArrow=ky;exports.computeDifferenceArrow=Zs;exports.computeDirectLabelsLayout=jy;exports.computeLineBoxHeight=Ub;exports.computePanelBorderPaths=fb;exports.computePanelBorderSizes=gb;exports.config=l.config;exports.convertSpecToInput=_o;exports.coord=l.coord;exports.countLayerGeoms=nb;exports.createAlphaValueReader=ou;exports.createAnchorResolver=fy;exports.createAreaPathGenerators=Hv;exports.createColorValueReader=vi;exports.createCompiler=af;exports.createDatasetFromKindPartitions=Nu;exports.createEmptyHighlight=Xi;exports.createGraphyBuilder=cf;exports.createGroupValueReader=lu;exports.createHeadlineItemRows=Bv;exports.createLabelValueReader=iu;exports.createLineFillAreaGenerator=Xv;exports.createLinePathGenerator=jv;exports.createObservationAnchorParser=xi;exports.createRawValueReader=U;exports.createSegmentYReader=We;exports.createSizeValueReader=su;exports.createSpec=Vs;exports.createStableBandKeyGenerator=aS;exports.createStableKeyGenerator=qt;exports.createStrokeWidthValueReader=cu;exports.createStyleResolver=In;exports.createValueFormatter=C;exports.createXValueReader=Qe;exports.createYValueReader=yi;exports.cursorToPiePlane=jr;exports.cursorToPolar=$t;exports.describeMeasurementBasis=Tr;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=ao;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=tm;exports.findAnnotation=it;exports.findAverageLineLayer=Oo;exports.findAxisGuide=Rn;exports.findDistinctLayers=tn;exports.findEquivalentHighlight=rx;exports.findGoalLineLayer=ko;exports.findHighlightsAtObservation=mv;exports.findKindStyleDeclarations=ot;exports.findLayerByGeom=ae;exports.findLayerById=k;exports.findLegendForAesthetic=kv;exports.findObservationAttachment=Co;exports.findPointerRegion=tv;exports.findStyleRule=Fn;exports.findStyleRuleIndex=$n;exports.findTrendLineLayer=Do;exports.formatDifferenceLabel=js;exports.formatHeadline=Av;exports.formatLegends=Rv;exports.formatRuleValue=Dv;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=N;exports.getAlpha=Si;exports.getAngleExtent=Ln;exports.getBarRectBounds=co;exports.getBoundingRect=qv;exports.getChromeDashArray=Gb;exports.getColor=Nt;exports.getCrossAxisCoordinate=Pt;exports.getCurve=Yt;exports.getDashArray=Wv;exports.getDifferenceArrowDimensions=Xs;exports.getDifferenceArrowLabelBox=Yy;exports.getGroup=G;exports.getHoverGuideLineProps=ZS;exports.getHoverGuideRectProps=JS;exports.getLineType=bi;exports.getMainAxisCoordinate=_e;exports.getNumericWeight=Qn;exports.getPolarHoverGuideArcProps=QS;exports.getRadiusExtent=Tn;exports.getRuleDashPattern=rS;exports.getRuleLabelTextColor=nS;exports.getScaledAesthetic=Jc;exports.getSize=Kr;exports.getStablePolarBarKeyGenerator=iS;exports.getStackRole=Qi;exports.getStrokeWidth=Er;exports.getUnionExtent=tS;exports.getX=R;exports.getXMax=K;exports.getXMin=z;exports.getY=E;exports.getYMax=P;exports.getYMin=F;exports.getYRaw=Hr;exports.hasMultipleGroups=Ut;exports.highlight=tx;exports.inferDefaultDifferenceArrowEndpoints=gv;exports.inferDifferenceArrowEndpoints=oo;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=Sx;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=ru;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isCompanionLayer=en;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=Oi;exports.isGeomStyleRule=Gn;exports.isLayerOf=sf;exports.isLayerOfType=Y;exports.isLineStyleType=gi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=Jb;exports.isPointWithinEditMenuTrigger=cv;exports.isPointWithinRegionShape=Vn;exports.isSafeUrl=Ib;exports.isStackedPosition=M;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=ix;exports.normalizeAngle=Me;exports.orderPointerRegions=rv;exports.pipe=Rs;exports.placeCallouts=Hy;exports.polarToUnit=Ct;exports.positionToAngle=Pi;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=zv;exports.prepareLineObservations=Zv;exports.projectAnchorToPanel=ro;exports.quantiseKey=H;exports.readAttachedObservation=Nn;exports.readAuthoredNumber=Pb;exports.readAuthoredString=Mb;exports.readChartType=Ox;exports.readHighlightDimStyle=Rl;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readXExtent=wo;exports.readYExtent=Eo;exports.resolveAnchorVariable=be;exports.resolveArrowColor=Ei;exports.resolveAxisLabelStyle=Hb;exports.resolveBarBorderRadiusPx=lo;exports.resolveBarBorderTreatment=Yv;exports.resolveBarCornerRadiiPx=Kv;exports.resolveColorRamp=on;exports.resolveComparisonBasis=qi;exports.resolveDataLabelStyle=Kb;exports.resolveDeferredAnchors=xy;exports.resolveDefinition=sn;exports.resolveGraphChromeStyle=$b;exports.resolveGridLineStyle=Bb;exports.resolveHeadlinePlacement=oy;exports.resolveObservationPoint=vv;exports.resolvePanelBorderStyle=Nb;exports.resolvePolarBarCornerRadiusUnit=eS;exports.resolveRuleLabelStyle=Yb;exports.resolveSegmentYSource=Mt;exports.resolveTextStyle=Xt;exports.resolveTickLabelStyle=zb;exports.resolveTickLineStyle=Fb;exports.resolveYScaleAesthetic=ne;exports.sampleColorScheme=_h;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Sv;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=Wb;exports.toPanelCursor=no;exports.toPercent=de;exports.toViewBoxX=yy;exports.toViewBoxY=te;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=ks;exports.uniqueId=O;exports.unitToPolar=Mi;exports.updateSpec=w;
|
|
23
|
+
`,Gg=(e,t,r,n,a,i=.5)=>e?{x:n,y:Math.min(t.y,r.y)+i*a}:{x:Math.min(t.x,r.x)+i*a,y:n},Ug=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),Zs=({arrow:e,mainAxis:t,panelWidth:r,panelHeight:n,textScale:a,locale:i})=>{const s=t==="y",o={x:e.start.x*r,y:(1-e.start.y)*n},c={x:e.end.x*r,y:(1-e.end.y)*n},u=Xs(e.size,a),d=Ng(s,o,c,u),m=(s?Fg:Bg)(o,c,d,u),p=$g(s,c,u),h=Gg(s,o,c,d,Ug(s,o,c),e.labelCrossPosition),f=js({locale:i,kind:e.label,startValue:e.start.measurementValue,endValue:e.end.measurementValue,valueFormat:e.start.valueFormat});return{id:e.id,start:o,end:c,linePath:m,arrowheadPath:p,labelPosition:h,labelText:f,color:e.color,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*Wg({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!Me(s.start.x,s.start.y)||!Me(s.end.x,s.end.y))continue;const o=Zs({arrow:s,mainAxis:t,panelWidth:r.width,panelHeight:r.height,textScale:n,locale:a}),c=i(o.labelText,s.size).width+2*o.labelPaddingX,u=o.labelLineHeight+2*o.labelPaddingY;yield{x:r.x+o.labelPosition.x-c/2,y:r.y+o.labelPosition.y-u/2,width:c,height:u}}}var Hg=e=>{const t=e.padding,r=Ca(e.rows,t?.top??0,t?.bottom??0),n=Ca(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:qg(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},zg=e=>{const t=ka(e.rows,e.height),r=ka(e.cols,e.width),n=Da(t),a=Da(r),i=new Map;for(const s of e.placements){const o=s.rowSpan??1,c=s.colSpan??1,u=a[s.col]??0,d=n[s.row]??0,m=Oa(r,s.col,c),p=Oa(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,p)})}return i},Ca=(e,t,r)=>{const n=[],a=new Map;t>0&&n.push({type:"fixed",pixels:t});let i=0;for(let s=0;s<e.length;s++){const o=e[s];if(!o)continue;Mr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(Kg(o));const c=Yg(e,s);if(Mr(o)&&c){const u=o.gaps?.after??0,d=c.gaps?.before??0;u>=d?u>0&&n.push({type:"fixed",pixels:u}):i=d}}return r>0&&n.push({type:"fixed",pixels:r}),{tracks:n,nameToIndex:a}},Kg=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Mr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Yg=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Mr(n))return n}},qg=(e,t,r)=>{const n=[];for(const a of e){const i=t.get(a.row),s=r.get(a.col);if(i===void 0||s===void 0)continue;const o=a.rowEnd!==void 0?t.get(a.rowEnd):i,c=a.colEnd!==void 0?r.get(a.colEnd):s;o===void 0||c===void 0||n.push({name:a.name,row:i,col:s,rowSpan:Math.max(1,o-i+1),colSpan:Math.max(1,c-s+1)})}return n},ka=(e,t)=>{let r=0,n=0;for(const i of e)i.type==="fixed"?r+=i.pixels:n+=i.weight;const a=Math.max(0,t-r);return e.map(i=>i.type==="fixed"?i.pixels:n===0?0:i.weight/n*a)},Da=e=>{const t=new Array(e.length);let r=0;for(let n=0;n<e.length;n++)t[n]=r,r+=e[n]??0;return t},Oa=(e,t,r)=>{let n=0;const a=Math.min(t+r,e.length);for(let i=t;i<a;i++)n+=e[i]??0;return n},$e={top:0,right:0,bottom:0,left:0},Js={outer:$e,inner:$e},jg={top:24,right:24,bottom:24,left:24},Xg=(e,t,r,n=$e,a=Js,i=jg,s={})=>{const o={top:a.inner.top+n.top,right:a.inner.right+n.right,bottom:a.inner.bottom+n.bottom,left:a.inner.left+n.left},c=r.axes.top>0||r.axesLabels.top>0?r.axesLabels.top:Math.max(r.axesLabels.top,r.axesLabels.left,r.axesLabels.right),u=_a(hf,s),d=_a(pf,s);return Hg({rows:[{name:"header",size:t.headerSize.height,gaps:u.header},{name:"topLegend",size:r.legends.top,gaps:u.topLegend},{name:"headline",size:r.headline,gaps:u.headline},{name:"topAxisLabel",size:c,gaps:u.topAxisLabel},{name:"topAxis",size:r.axes.top,gaps:u.topAxis},{name:"topPanelOuter",size:a.outer.top},{name:"topPanelInner",size:o.top},{name:"panel",size:{flex:1}},{name:"bottomPanelInner",size:o.bottom},{name:"bottomPanelOuter",size:a.outer.bottom},{name:"bottomAxis",size:r.axes.bottom,gaps:u.bottomAxis},{name:"bottomAxisLabel",size:r.axesLabels.bottom,gaps:u.bottomAxisLabel},{name:"bottomLegend",size:r.legends.bottom,gaps:u.bottomLegend},{name:"footer",size:t.footerSize.height,gaps:u.footer}],cols:[{name:"leftLegend",size:r.legends.left,gaps:d.leftLegend},{name:"leftAxis",size:r.axes.left,gaps:d.leftAxis},{name:"leftPanelOuter",size:a.outer.left},{name:"leftPanelInner",size:o.left},{name:"panel",size:{flex:1}},{name:"rightPanelInner",size:o.right},{name:"rightPanelOuter",size:a.outer.right},{name:"rightAxis",size:r.axes.right,gaps:d.rightAxis},{name:"rightLegend",size:r.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panelFrame",row:"topPanelInner",rowEnd:"bottomPanelInner",col:"leftPanelInner",colEnd:"rightPanelInner"},{name:"panel",row:"panel",col:"panel"},...Jg(r.axes),...Qg(r.axesLabels,r.axes),...ey(r.legends)],containerSize:e,padding:i})},Zg=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:gr(t,e.after)}:{before:gr(t.before,e.before),after:gr(t.after,e.after)}:e,gr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,_a=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=Zg(e[n],t[n]);return r},Jg=e=>{const t=[];return e.top>0&&t.push({name:"topAxis",row:"topAxis",col:"panel"}),e.bottom>0&&t.push({name:"bottomAxis",row:"bottomAxis",col:"panel"}),e.left>0&&t.push({name:"leftAxis",row:"panel",col:"leftAxis"}),e.right>0&&t.push({name:"rightAxis",row:"panel",col:"rightAxis"}),t},Qg=(e,t)=>{const r=[];return e.top>0||t.top>0?(e.top>0&&r.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&r.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&r.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&r.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&r.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),r},ey=e=>{const t=[];return e.top>0&&t.push({name:"topLegend",row:"topLegend",col:"leftAxis",colEnd:"rightAxis"}),e.bottom>0&&t.push({name:"bottomLegend",row:"bottomLegend",col:"leftAxis",colEnd:"rightAxis"}),e.left>0&&t.push({name:"leftLegend",row:"panel",col:"leftLegend"}),e.right>0&&t.push({name:"rightLegend",row:"panel",col:"rightLegend"}),t};var ty=class{constructor(e){this.outer={...$e},this.inner={...$e},this.currentPanelRect=e}resolve(){return{outer:{...this.outer},inner:{...this.inner}}}add(e,t){const r=this.computeEdgeOverflow(e,8),n=this.computeEdgeOverflow(e,0);this.growEdge("left",t.x,r.left,n.left),this.growEdge("right",t.x,r.right,n.right),this.growEdge("top",t.y,r.top,n.top),this.growEdge("bottom",t.y,r.bottom,n.bottom)}computeEdgeOverflow(e,t){const r=this.currentPanelRect;return{top:Math.max(Math.ceil(r.y+t-e.y),0),right:Math.max(Math.ceil(e.x+e.width-(r.x+r.width-t)),0),bottom:Math.max(Math.ceil(e.y+e.height-(r.y+r.height-t)),0),left:Math.max(Math.ceil(r.x+t-e.x),0)}}growEdge(e,t,r,n){t!=="none"&&(t==="outside"?n>0&&(this.outer[e]=Math.max(this.outer[e],n)):r>0&&(this.inner[e]=Math.max(this.inner[e],r)))}},ry=["top","right","bottom","left"],yr=(e,t)=>{const r={};for(const n of ry){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function Pa(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Nr=["large","medium","small"],ny=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Nr)if(r(n)<=t)return n;return"small"},ay=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:Nr.indexOf(e);for(const a of Nr.slice(n))if(r(a)<=t)return a;return null},iy=({itemWidths:e,gap:t,availableWidth:r})=>{let n=0,a=0;for(const i of e){const s=a===0?i:n+t+i;if(s>r)break;n=s,a+=1}return a},sy=({headline:e,containerSize:t,measurer:r})=>{if(Qs(e))return 0;const n=eo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},oy=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(Qs(e)){const o=ly(t.panel,e.innerRadius),c=ay({size:e.size,availableWidth:o.width,measureStripWidth:to(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=eo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=iy({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},Qs=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,ly=(e,t)=>{const r=t*(Math.min(e.width,e.height)/2)*Math.SQRT2,n=e.x+e.width/2,a=e.y+e.height/2;return{x:n-r/2,y:a-r/2,width:r,height:r}},eo=(e,t,r)=>ny({size:e.size,availableWidth:t,measureStripWidth:to(e,r)}),to=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Ve={x:0,y:0,width:0,height:0},cy="0000",uy=3,Ye=e=>typeof e=="number"&&Number.isFinite(e)?e:24,dy=e=>e.plot.y+e.plot.height-e.panel.y,my=e=>{if(typeof e=="object"&&e!==null)return{top:Ye(e.top),right:Ye(e.right),bottom:Ye(e.bottom),left:Ye(e.left)};const t=Ye(e);return{top:t,right:t,bottom:t,left:t}},hy=class{constructor(e){this.measurer=e}compile(e){return Gt({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Js,panelBorder:e.panelBorder??$e,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:my(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:py(a,n,r),formatted:this.seedAxis(a)}))})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({axisBundles:t.map(n=>Ma(n.axis.position)?{...n,formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame)}:n)})).pipe(({axisBundles:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t.map(d=>d.formatted),formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({axisBundles:t,layout:r})=>({formattedAxes:t.map(n=>Ma(n.axis.position)?n.formatted:this.finalizeAxis(n.axis,n.resolveFormatter,r.panelFrame))})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})=>({layout:this.resolveLayout({axes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:i,panelBorder:s,headline:o,padding:c,gaps:u})})).pipe(({formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,layout:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})=>({formattedAxes:t,layout:this.settlePanelOverflow({input:e,layout:i,formattedAxes:t,formattedLegends:r,containerSize:n,externalMeasurements:a,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m})})).pipe(({formattedAxes:t,layout:r})=>{const n=this.applyPolarPanelInset(e,t,r);return{formattedAxes:t,layout:n,plotBottomY:dy(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new ty(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of Wg({annotations:e.annotations,mainAxis:e.coordSystem.mainAxis,panelRect:t,textScale:e.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel}))a.add(s,e.overflowStrategy.differenceArrows);if(e.layers&&e.layers.length>0&&e.overflowStrategy.dataLabels)for(const s of Mg({layers:e.layers,coordSystem:e.coordSystem,axes:e.axes,numberFormat:e.numberFormat,panelRect:t,measureDataLabel:this.measurer.measureDataLabel,locale:r}))a.add(s,e.overflowStrategy.dataLabels);const i=a.resolve();return Pa(i.inner,n.inner)&&Pa(i.outer,n.outer)?n:i}settlePanelOverflow({input:e,layout:t,formattedAxes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:s,panelBorder:o,headline:c,locale:u,padding:d,gaps:m}){let p=t,h=s;for(let f=0;f<uy;f++){const g=this.measurePanelOverflow(e,p.panelFrame,u,h);if(g===h)break;h=g,p=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}return p}applyPolarPanelInset(e,t,r){if(e.coordSystem?.type!=="polar")return r;const n=this.measurePolarRimInset(t),{panel:a}=r,i=a.width-n.horizontal*2,s=a.height-n.vertical*2;return i<=0||s<=0?Na(r,a,0,0):Na(r,a,n.horizontal,n.vertical)}measurePolarRimInset(e){const t=e.find(i=>i.geometry==="circular");if(!t)return{horizontal:0,vertical:0};const r=N(t.scaleAestheticKey);let n=0,a=0;for(const i of t.ticks){const s=this.measurer.measureTickLabel(i.formattedLabel,r);n=Math.max(n,s.width),a=Math.max(a,s.height)}return n===0?{horizontal:0,vertical:0}:{horizontal:n+8,vertical:a+8}}seedAxis(e){const{tickCandidates:t,...r}=e;return{...r,ticks:[{value:0,position:0,formattedLabel:cy}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=N(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=Nf({axis:e,availableSpacePx:n,measureLabel:i,resolveFormatter:t}),{tickCandidates:o,...c}=e,u={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};return e.geometry!=="linear"?u:e.scaleType==="discrete"&&e.bandwidth!==void 0?Df({formattedAxis:u,bandwidthPx:e.bandwidth*n,panelRect:r,measureLabel:i}):u}resolveLayout({axes:e,formattedLegends:t,containerSize:r,externalMeasurements:n,panelOverflow:a,panelBorder:i,headline:s,padding:o,gaps:c}){const u=zg(Xg(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Ve,headline:u.get("headline")??Ve,footer:u.get("footer")??Ve,plot:u.get("plot")??Ve,panelFrame:u.get("panelFrame")??Ve,panel:u.get("panel")??Ve,axes:yr(u,"Axis"),axisLabels:yr(u,"AxisLabel"),legends:yr(u,"Legend")}}measureGuides(e,t,r,n){const a={top:0,right:0,bottom:0,left:0},i={top:0,right:0,bottom:0,left:0};for(const o of e)o.isVisible&&o.geometry==="linear"&&(a[o.position]=this.measurer.measureAxis(o),o.label!==null&&(i[o.position]=this.measurer.measureAxisLabel(o)));const s={top:0,right:0,bottom:0,left:0};for(const o of t)s[o.position]=this.measurer.measureLegend(o);return{axes:a,axesLabels:i,legends:s,headline:this.measureHeadlineBand(r,n)}}measureHeadlineBand(e,t){return e===void 0?0:sy({headline:e,containerSize:t,measurer:this.measurer})}},Ma=e=>e==="left"||e==="right",Na=(e,t,r,n)=>{const a=t.width-r*2,i=t.height-n*2,s=Math.min(a,i);return{...e,panel:{x:t.x+r+(a-s)/2,y:t.y+n+(i-s)/2,width:s,height:s}}},py=(e,t,r)=>{const n=e.tickCandidates.flatMap(i=>i.ticks.map(s=>s.value)),a=new WeakMap;return i=>{const s=a.get(i);if(s)return s;const o=Sn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},fy=(e=[])=>{const t=gy(e);return{resolve:(r,n,a)=>t.has(r)?t.get(r).resolveAnchorPosition?.(n,a)??null:null,hasCapability:r=>t.has(r)&&t.get(r).resolveAnchorPosition!==void 0}},gy=e=>{const t=new zt;for(const r of e){const n=sn(r);n instanceof ie&&t.register(n.type,n)}return t};function yy(e){return e}function te(e){return 1-e}var de=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,ro=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:te(e.y)*t.height};const n=Math.min(t.width,t.height),a=(t.width-n)/2,i=(t.height-n)/2;return{x:a+e.x*n,y:i+e.y*n}},vy=class{constructor(e,t,r,n){this.annotations=e,this.panelRect=t,this.coordSystem=r,this.measuredBoxes=n,this.index=null,this.boxes=new Map,this.resolvingStack=[],this.cyclic=new Set,this.missingRefs=new Set}cyclicIds(){return[...this.cyclic]}missingRefIds(){return[...this.missingRefs]}resolvePoint(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return vt(e);const{x:s,y:o}=Br(e.defer,this.panelRect);return vt({...e,x:e.x+s,y:e.y-o})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=Je(r,e.defer.align),{x:a,y:i}=Sy(n,e.defer.offset,this.panelRect);return{x:a,y:i}}resolveRegion(e){if(e.defer===void 0)return e;const t=this.coordSystem.type==="polar";if(e.defer.type==="px-offset"){if(t)return vt(e);const{x:i,y:s}=Br(e.defer,this.panelRect);return vt({...e,x:e.x-i,y:e.y-s,width:Math.max(0,e.width+2*i),height:Math.max(0,e.height+2*s)})}if(t)return null;const r=this.boxOf(e.defer.ref);if(r===null)return null;const n=r.xMax-r.xMin,a=r.yMax-r.yMin;return n<=0||a<=0?null:{x:r.xMin,y:r.yMin,width:n,height:a}}getTargetIndex(){if(this.index!==null)return this.index;const{annotations:e}=this,t=new Map,r=(n,a)=>{t.has(n)||t.set(n,a)};for(const n of e.shapes)r(n.id,{kind:"shape",annotation:n});for(const n of e.images)r(n.id,{kind:"image",annotation:n});for(const n of e.arrows)r(n.id,{kind:"arrow",annotation:n});for(const n of e.textAnnotations)r(n.id,{kind:"text",annotation:n});for(const n of e.stickers)r(n.id,{kind:"sticker",annotation:n});for(const n of e.differenceArrows)r(n.id,{kind:"differenceArrow",annotation:n});for(const n of e.pinnedNumbers)r(n.id,{kind:"pinnedNumber",annotation:n});for(const n of e.comments)r(n.id,{kind:"comment",annotation:n});return this.index=t,t}boxOf(e){const t=this.boxes.get(e);if(t!==void 0)return t;const r=this.resolvingStack.indexOf(e);if(r!==-1){for(const i of this.resolvingStack.slice(r))this.cyclic.add(i);return null}const n=this.getTargetIndex().get(e);if(n===void 0)return this.missingRefs.add(e),null;this.resolvingStack.push(e);const a=this.deriveBox(e,n);return this.resolvingStack.pop(),this.boxes.set(e,a),a}deriveBox(e,t){switch(t.kind){case"shape":case"image":{const r=this.resolveRegion(t.annotation.region);return r===null?null:by(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:Ba(r,n)}case"text":{const r=this.resolvePoint(t.annotation.at);if(r===null)return null;const n=this.measuredBoxes?.get(e);if(n===void 0||n.height<=0||this.panelRect.height<=0)return null;const a=t.annotation.width,i=n.height/this.panelRect.height,s=di(t.annotation.align),o=r.x-s.x*a,c=r.y+(1-s.y)*i;return{xMin:o,xMax:o+a,yMin:c-i,yMax:c}}case"sticker":{const r=this.resolvePoint(t.annotation.at);return r===null?null:Fa(r)}case"differenceArrow":return Ba(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return Fa(t.annotation.at)}}},Br=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Sy=(e,t,r)=>{if(t===void 0)return e;const n=t.x??0,a=t.y??0;if(t.unit==="px"){const{x:i,y:s}=Br({type:"px-offset",x:n,y:a},r);return{x:e.x+i,y:e.y-s}}return{x:e.x+n,y:e.y-a}},by=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),Ba=(e,t)=>({xMin:Math.min(e.x,t.x),xMax:Math.max(e.x,t.x),yMin:Math.min(e.y,t.y),yMax:Math.max(e.y,t.y)}),Fa=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),vt=e=>{const t={...e};return delete t.defer,t},xy=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!Ay(t))return t;const o=new vy(t,r,n,a),c={...t,shapes:qe(t.shapes,m=>m.region.defer!==void 0,m=>{const p=o.resolveRegion(m.region);return p===null?null:{...m,region:p}}),images:qe(t.images,m=>m.region.defer!==void 0,m=>{const p=o.resolveRegion(m.region);return p===null?null:{...m,region:p}}),arrows:qe(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const p=o.resolvePoint(m.start),h=o.resolvePoint(m.end);return p===null||h===null?null:{...m,start:p,end:h}}),textAnnotations:qe(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const p=o.resolvePoint(m.at);return p===null?null:{...m,at:p}}),stickers:qe(t.stickers,m=>m.at.defer!==void 0,m=>{const p=o.resolvePoint(m.at);return p===null?null:{...m,at:p}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},qe=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Ay=e=>e.shapes.some(t=>t.region.defer!==void 0)||e.images.some(t=>t.region.defer!==void 0)||e.arrows.some(t=>t.start.defer!==void 0||t.end.defer!==void 0)||e.textAnnotations.some(t=>t.at.defer!==void 0)||e.stickers.some(t=>t.at.defer!==void 0),Iy=800,$a=400,Ly={thin:{strokeWidth:{minValue:1.5,targetValue:2},arrowheadLength:{minValue:7,targetValue:8}},medium:{strokeWidth:{minValue:3,targetValue:4},arrowheadLength:{minValue:14,targetValue:16}},thick:{strokeWidth:{minValue:6,targetValue:8},arrowheadLength:{minValue:28,targetValue:32}}},Ty=e=>Math.max(1,(e-$a)/(Iy-$a)+1),wy=(e,t)=>{const r=Ty(t),n=Ly[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},St=Math.PI/4,Fr=1.5,Ey=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,Ga=(e,t,r)=>{if(r<=0)return"";const{startX:n,startY:a,endX:i,endY:s}=t,o=e==="start"?n:i,c=e==="start"?a:s,u=e==="start"?Math.atan2(a-s,n-i):Math.atan2(s-a,i-n);return`M ${o} ${c} L ${o-r*Math.cos(u-St)} ${c-r*Math.sin(u-St)} M ${o} ${c} L ${o-r*Math.cos(u+St)} ${c-r*Math.sin(u+St)}`},Vy=(e,t)=>e==="solid"?null:`${t*Fr} ${t*Fr*2}`,Ry=(e,t)=>t?e*Fr:0,Cy=64,ky=({arrow:e,panelWidth:t,panelHeight:r})=>{const n={startX:e.start.x*t,startY:(1-e.start.y)*r,endX:e.end.x*t,endY:(1-e.end.y)*r};if(n.startX===n.endX&&n.startY===n.endY)return null;const{strokeWidth:a,arrowheadLength:i}=wy(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=Dy(i,s),c=e.startArrowheadStyle==="line-arrow",u=e.endArrowheadStyle==="line-arrow",d=c||u?o*Math.sin(Math.PI/4):0;return{id:e.id,linePath:Ey(n),startArrowheadPath:c?Ga("start",n,o):"",endArrowheadPath:u?Ga("end",n,o):"",color:e.color,strokeWidth:a,dashArray:Vy(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:Ry(a,c),arrowheadExtent:d}},Dy=(e,t)=>Math.min(e,t*e/Cy);function Oy(e,t){const r=new Map;if(!t||t.kind!=="visual"||t.domain.length<=1)return r;for(const n of e){if(n.geom!=="rule"||n.stat.type!=="mean")continue;const a=n.transforms.find(m=>m.transformType==="filter"&&m.options.operator==="eq"),i=l.extractVariableName(n.mapping.y);let s,o,c;if(a?.transformType==="filter"&&typeof a.options.value=="string")s="color",o=a.options.variableName,c=a.options.value;else if(i!==null)s="y",o=i,c=i;else continue;const u=_y(e,s,o);if(u===null)continue;const d=t.map(c);l.isStrictCategoricalDataValue(d)&&r.set(n.id,{geom:u.geom,color:d})}return r}function _y(e,t,r){let n=null;for(const a of e)if(a.geom!=="rule"&&(n===null&&(n=a),l.extractVariableName(a.mapping[t])===r))return a;return n}var no=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),Py=0,My=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:no(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:Py})),Ny=9,By=8,Fy=2,ao=e=>typeof e=="string"?e:io(e),io=e=>e.text!==void 0?e.text:e.content?e.content.map(io).join(""):"",Ua={top:"bottom",bottom:"top",right:"left",left:"right"};function $y(e,t,r){return r.type==="polar"?Wy(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function $r(e,t,r){const{width:n,height:a}=r;switch(t){case"top":return{x:e.x-n/2,y:e.y-9-a,width:n,height:a};case"bottom":return{x:e.x-n/2,y:e.y+9,width:n,height:a};case"right":return{x:e.x+9,y:e.y-a/2,width:n,height:a};case"left":return{x:e.x-9-n,y:e.y-a/2,width:n,height:a}}}function Wa(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function Gy(e,t){return{...t,x:Math.max(0,Math.min(t.x,e.width-t.width)),y:Math.max(0,Math.min(t.y,e.height-t.height))}}function Uy(e,t,r=2){return e.x<t.x+t.width-r&&e.x+e.width>t.x+r&&e.y<t.y+t.height-r&&e.y+e.height>t.y+r}function Wy(e,t){const r=e.x-t.width/2,n=e.y-t.height/2,a=r>=0?"right":"left",i=n>=0?"bottom":"top",[s,o]=Math.abs(r)>=Math.abs(n)?[a,i]:[i,a];return[s,Ua[s],o,Ua[o]]}function Hy(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:p}=d;return Ha(m,"pinned-number",p,s(d),i,n,a)}),...r.map(({id:d,at:m,content:p})=>Ha(d,"comment",m,ao(p),i,n,a))];o.sort((d,m)=>d.anchorPx.x-m.anchorPx.x||d.anchorPx.y-m.anchorPx.y);const c=[],u=[];for(const d of o){if(!d.inView){c.push(za(n,d,"top"));continue}const m=za(n,d,Ky(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function Ha(e,t,r,n,a,i,s){const o=ro(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:zy(o,i)}}function zy(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function Ky(e,t,r,n){const a=$y(t.anchorPx,e,r);for(const i of a){const s=$r(t.anchorPx,i,t.mini);if(Wa(s,e)&&!n.some(o=>Uy(s,o)))return i}for(const i of a)if(Wa($r(t.anchorPx,i,t.mini),e))return i;return"top"}function za(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:Gy(e,$r(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var Yy=({labelPosition:e,measuredTextWidth:t,labelLineHeight:r,labelPaddingX:n,labelPaddingY:a})=>{const i=t+2*n,s=r+2*a;return{x:e.x-i/2,y:e.y-s/2,width:i,height:s}},qy=100,jy=({items:e,containerHeight:t,labelHeight:r})=>{const n=e.map(c=>{const u=(1-c.normalizedY)*t;return{anchorY:u,y:u,payload:c.payload}}).sort((c,u)=>c.y-u.y),a=r/2;let i=!1,s=!0,o=0;for(;s;){s=!1,o++;for(let c=0;c<n.length-1;c++){const u=n[c],d=n[c+1];if(!u||!d)continue;const m=u.y+a,p=d.y-a;if(m>p){s=!0,i=!0;const h=(m-p)/2+1;u.y-=h,d.y+=h,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>qy)break}return{placements:n.filter(c=>c.y>=0&&c.y<=t).map(c=>({y:c.y,anchorY:c.anchorY,payload:c.payload})),hasOverlap:i}},Xy=(e,t)=>{const r=Ai(e),n=Jy(t,Zy(e),r);if(n===null)return null;const a=Qy(e,n,r)?ev(e,t,n,r):n,[i]=a;return i===void 0?null:a.length===1?i:{and:a}},Zy=e=>{const t=ze(e.data,e.mapping),r=be(e);return r===l.GROUP_VARIABLES.group?[...new Set(t)]:[...new Set([r,...t])]},Jy=(e,t,r)=>{const n=[];for(const a of t){const i=r(e,a);if(i===null)return null;n.push({variable:a,eq:i})}return n},Qy=(e,t,r)=>{let n=0;for(const a of e.data)if(t.every(i=>l.areDataValuesEqual(r(a,i.variable),i.eq))&&(n+=1,n>1))return!0;return!1},ev=(e,t,r,n)=>{const a=l.extractVariableName(e.mapping.y);if(a===null||r.some(s=>s.variable===a))return r;const i=n(t,a);return i===null?r:[...r,{variable:a,eq:i}]},Vn=(e,t)=>{if(t.kind==="circle"){const n=e.x-t.center.x,a=e.y-t.center.y;return n*n+a*a<=t.radius*t.radius}const{rect:r}=t;return e.x>=r.x&&e.x<=r.x+r.width&&e.y>=r.y&&e.y<=r.y+r.height},tv=(e,t)=>{for(const r of t)if(Vn(e,r.shape))return r;return null},rv=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},nv=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>av(r,t[n])),av=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&iv(e.shape,t.shape)&&sv(e.tooltip,t.tooltip),iv=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="circle"){const n=t;return e.center.x===n.center.x&&e.center.y===n.center.y&&e.radius===n.radius}const{rect:r}=t;return e.rect.x===r.x&&e.rect.y===r.y&&e.rect.width===r.width&&e.rect.height===r.height},sv=(e,t)=>{if(e.kind!==t.kind)return!1;if(e.kind==="cursor")return!0;const r=t;return e.point.x===r.point.x&&e.point.y===r.point.y&&e.placement===r.placement&&e.annotationId===r.annotationId},ov=100,lv=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:ov}),cv=(e,t)=>Vn(e,{kind:"circle",center:t.center,radius:t.radius}),uv=(e,t)=>e===t?!0:e===null||t===null?!1:e.center.x===t.center.x&&e.center.y===t.center.y&&e.radius===t.radius&&dv(e.target,t.target),dv=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,mv=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=$t(e,n),i=hv(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||he(s.predicate,e.data).length>0)return!1;const o=me(s.predicate,a);return o(r)?!0:Vm(s.scope)&&i(s.scope).some(o)})},hv=(e,t)=>{const r=l.extractVariableName(e.mapping.x),n=new Map;return a=>{const i=n.get(a);if(i!==void 0)return i;const s=Dt(a,t,r),o=[];for(const c of e.data)Dt(a,c,r)===s&&o.push(c);return n.set(a,o),o}},Tt=({layer:e,from:t,step:r,accepts:n,excluding:a,cycles:i=!1})=>{const s=e.data.size();for(let o=0;o<s;o+=1){const c=t+o*r,u=i?fv(c,s):c;if(u<0||u>=s)break;const d=e.data.getAt(u);if(d===null||!n(d))continue;const m=Qe(e,d);if(m!==null&&!a.some(p=>De(m,p)))return{anchor:m,observation:d}}return null},so=(e,t,r)=>{let n=0;for(const a of e.data){if(pv(a,t,r))return n;n+=1}return-1},pv=(e,t,r)=>l.areDataValuesEqual(e[r]??null,t.anchorValue)?t.groupValue===void 0?!0:l.areDataValuesEqual(G(e),t.groupValue):!1,De=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null),fv=(e,t)=>(e%t+t)%t,oo=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian")return null;const n=be(e),a=so(e,t,n),i=e.data.getAt(a);if(i===null)return null;const s=G(i),o=p=>l.areDataValuesEqual(G(p),s),c=[t],u=Tt({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=Tt({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=Tt({layer:e,excluding:c,from:0,step:1,accepts:p=>!o(p)&&l.areDataValuesEqual(p[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},gv=e=>{if(e.coordSystem.type!=="cartesian")return null;const t=e.spec.annotations.differenceArrows;for(const r of e.layers)for(const n of r.data){const a=Qe(r,n);if(a===null)continue;const i=oo({layer:r,at:a,coordSystem:e.coordSystem});if(i!==null&&!t.some(s=>yv(s,i)))return i}return null},yv=(e,t)=>De(e.start,t.start)&&De(e.end,t.end)||De(e.start,t.end)&&De(e.end,t.start),vv=({resolver:e,layer:t,observation:r,coordSystem:n,align:a,readSegmentY:i})=>{const s=e.resolve(t.geom,r,{coordSystem:n,position:t.position,purpose:"value",align:a});if(s===null)return null;const o=wi(t,r,i??He(t));if(o===null)return null;const c=Qe(t,r);return c===null?null:{...s,...o,anchor:a===void 0?c:{...c,align:a}}},Sv=({layer:e,from:t,partner:r,axis:n,step:a,canLandOn:i})=>{const s=be(e),o=so(e,t,s),c=e.data.getAt(o);if(c===null)return null;const u=bv(c),d=n==="main"?u:m=>!u(m)&&l.areDataValuesEqual(m[s]??null,t.anchorValue);return Tt({layer:e,excluding:[t,r],from:o+a,step:a,accepts:m=>d(m)&&i(m),cycles:n!=="main"})},bv=e=>{const t=G(e);return r=>l.areDataValuesEqual(G(r),t)};function xv({numberFormat:e,locale:t}){const r=new Map;return n=>{let a=r.get(n.valueFormat);return a??=C({valueFormat:n.valueFormat,locale:t,numberFormat:e}),r.set(n.valueFormat,a),a(n.measurementValue)}}var Av=({headline:e,show:t,numberFormat:r,parsingLocale:n,formattingLocale:a,t:i})=>{if(e===null)return null;const s=a??n;return e.kind==="grandTotal"?Iv(e,s,r):Lv(e,t,s,r,i)},Iv=(e,t,r)=>({kind:"grandTotal",value:C({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Lv=(e,t,r,n,a)=>{const i=C({valueFormat:{type:"percentage"},locale:r,numberFormat:n}),s=e.items.length>1;return{kind:"perGroup",items:e.items.map(o=>{const c=C({valueFormat:o.valueFormat,locale:r,numberFormat:n}),u=C({valueFormat:o.groupLabelFormat,locale:r,numberFormat:n}),d=Sn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Vv(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:Ev(o.observationLabel,d),comparison:Tv(o.comparison,d,i,a)}})}},Tv=(e,t,r,n)=>e===null?null:{direction:wv(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},wv=e=>e>0?"up":e<0?"down":"flat",Ev=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Vv=(e,t,r,n)=>{switch(e){case"total":return n("graph.headlineMetrics.total",{value:r});case"average":return t?n("graph.headlineMetrics.averageShort",{value:r}):n("graph.headlineMetrics.averageLong",{value:r});case"current":case"conversion":case"none":return r}},Rv=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Cv(i,a,t))},Cv=(e,t,r)=>({...e,items:e.items.map(n=>{const a=C({valueFormat:n.valueFormat,locale:t,numberFormat:r});return{...n,formattedLabel:n.label??a(n.value)}})});function Rn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function kv(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var Dv=({guides:e,numberFormat:t,layer:r,locale:n})=>{const a=r.data.getFirst();if(!a)return null;const i=r.mapping.y!==void 0,s=(i?yi:et)(r.data,r.mapping)(a);return s===null?null:C({valueFormat:Rn(e,i?ne(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},Ov=12,_v=4,Pv=4,Mv=12,Nv=4,Bv=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:vr([bt("value","value",t??"–"),bt("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:Uv(n),segments:vr([$v(n),Gv(n),bt("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:vr([Fv(a),bt("label","label",i)])}].filter(s=>s.segments.length>0)},bt=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},Fv=e=>e===null?null:{kind:"swatch",swatch:e,size:12},$v=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},Gv=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},Uv=e=>{switch(e.direction){case"up":return`Increased ${e.percentage} ${e.reference}`;case"down":return`Decreased ${e.percentage} ${e.reference}`;case"flat":return`No change ${e.reference}`}},vr=e=>e.filter(t=>t!==null),qt=e=>e==="catmull-rom"?ge.curveCatmullRom:ge.curveLinear,Wv=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},Hv=(e,t)=>{const r=qt(t.interpolate),n=(0,ge.area)().curve(r),a=(0,ge.line)().curve(r);if(e.mainAxis==="y"){const i=c=>te(E(c)??0),s=c=>z(c)??0,o=c=>K(c)??R(c)??0;n.y(i).x0(s).x1(o),a.y(i).x(o)}else{const i=c=>R(c)??0,s=c=>te(F(c)??0),o=c=>te(P(c)??E(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>R(s)!==null&&E(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},zv=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&E(r)!==null),Cn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},lo=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return Cn[e.borderRadius??"sm"]},Kv=e=>{const t=lo(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},Yv=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),co=(e,t)=>{const r=z(t),n=K(t),a=F(t),i=P(t)??E(t);if(r===null||n===null||a===null||i===null)return null;if(e==="x"){let c=1-i,u=i-a;return u<0&&(c+=u,u=-u),{x:r,y:c,width:n-r,height:u}}let s=r,o=n-r;return o<0&&(s+=o,o=-o),{x:s,y:1-i,width:o,height:i-a}},uo=(e,t)=>e==="x"?`${H(t.x)}-${H(t.width)}`:`${H(t.y)}-${H(t.height)}`,qv=e=>{let t=1/0,r=1/0,n=-1/0,a=-1/0;for(const i of e)i.x<t&&(t=i.x),i.y<r&&(r=i.y),i.x+i.width>n&&(n=i.x+i.width),i.y+i.height>a&&(a=i.y+i.height);return{x:t,y:r,width:n-t,height:a-r}},jv=e=>{const t=(0,ge.line)().x(r=>R(r)??0).y(r=>te(E(r)??0)).curve(qt(e.interpolate));return e.missingValues==="gap"&&t.defined(mo),t},Xv=e=>{const t=(0,ge.area)().x(r=>R(r)??0).y0(()=>1).y1(r=>te(E(r)??0)).curve(qt(e.interpolate));return e.missingValues==="gap"&&t.defined(mo),t},Zv=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&E(r)!==null),mo=e=>R(e)!==null&&E(e)!==null,ho=(0,ge.arc)().cornerRadius(e=>e.cornerRadius??0);ho.digits(8);var Jv=200,Qv=e=>ho(e)??void 0,eS=(e,t)=>e==="full"?Math.max(0,t)/2:Cn[e??"sm"]/Jv,po=(e,t)=>e==="x"?`${H(t.startAngle)}-${H(t.endAngle)}`:e==="y"?`${H(t.innerRadius)}-${H(t.outerRadius)}`:"sweep",tS=e=>{let t=1/0,r=-1/0,n=1/0,a=-1/0;for(const i of e)t=Math.min(t,i.startAngle,i.endAngle),r=Math.max(r,i.startAngle,i.endAngle),n=Math.min(n,i.innerRadius,i.outerRadius),a=Math.max(a,i.innerRadius,i.outerRadius);return{startAngle:t,endAngle:r,innerRadius:n,outerRadius:a}},Ka="#FFFFFF",Sr="#1A1A1A",rS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],nS=e=>{try{return(0,ra.getContrast)(e,Ka)>(0,ra.getContrast)(e,Sr)?Ka:Sr}catch{return Sr}},jt=(e,t,r)=>{const n=et(e,t);return a=>{const i=G(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},aS=(e,t,r)=>{const n=et(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},iS=()=>(e,t)=>Ft(e)??`default-${t}`;function kn(e,t,r){return Math.hypot(e*r,t)}function _t(e,t,r){return e<t?t-e:e>r?e-r:0}function oe(e,t,{shortCircuitOnZero:r=!1}={}){let n=e[0],a=t(n);if(r&&a===0)return n;for(let i=1;i<e.length;i+=1){const s=e[i];if(s===void 0)continue;const o=t(s);if(r&&o===0)return s;o<a&&(n=s,a=o)}return n}function sS(e,t,r,n){if(e.points.length===0)return null;const a=e.delaunay;if(!a)return null;const i=a.find(t.x*r,t.y,n??void 0),s=e.points[i];return s?{hit:{anchored:!0,layerId:e.layerId,pointIndex:s.pointIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:kn(s.x-t.x,s.y-t.y,r)}:null}function oS(e,t){if(e.points.length===0||!e.delaunay||e.delaunayAspectRatio===null)return null;const r=e.delaunay.find(t.x*e.delaunayAspectRatio,t.y);return e.points[r]??null}function fo(e,t){return Dn(e.buckets,t,r=>r.main)}function lS(e,t){return Dn(e.bands,t,r=>r.bandCenter)}function go(e,t){return Dn(e.columns,t,r=>r.mainMid)}function Dn(e,t,r){if(e.length===0)return null;let n=0,a=e.length;for(;n<a;){const o=n+a>>>1,c=e[o];c&&r(c)<t?n=o+1:a=o}const i=e[n-1],s=e[n];return i?s&&Math.abs(r(s)-t)<Math.abs(r(i)-t)?s:i:s??null}function cS(e,t){return{group:uS(e),related:pS(e,t)}}function uS(e){switch(e.kind){case"buckets":{const t=e.match.index;return M(t.position)?dS(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return M(t.position)?mS(t.layerId,r,n.pointIndex):hS(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function dS(e,t,r){const n=[];for(const a of t.entries)a.pointIndex!==r&&n.push({anchored:!0,layerId:e,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation});return n}function mS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(On(e,a));return n}function hS(e,t,r,n){const a=e.find(s=>s.columns.includes(r));if(!a)return[];const i=[];for(const s of a.columns)for(const o of s.rects)o.pointIndex!==n&&i.push(On(t,o));return i}function pS(e,t){const r=new Map;if(e.kind==="render-hit-test"||e.kind==="enclosure")return r;const n=e.match.index,a=n.projection==="polar";for(const i of t){if(i.layerId!==n.layerId){a||gS(r,i,e.match.hit);continue}e.kind==="buckets"&&(M(i.position)||i.kind==="buckets"&&fS(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function fS(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&wt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function gS(e,t,r){switch(t.kind){case"buckets":{const n=fo(t,Pe(t.mainAxis,r));if(!n)return;const a=wt(e,t.layerId);for(const i of n.entries)a.push({anchored:!0,layerId:t.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation});return}case"banded":{const n=lS(t,Pe(t.mainAxis,r));if(!n)return;const a=wt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(On(t.layerId,s));return}case"points":{const n=oS(t,r);if(!n)return;wt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function wt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function On(e,t){return{anchored:!0,layerId:e,pointIndex:t.pointIndex,x:(t.xMin+t.xMax)/2,y:(t.yMin+t.yMax)/2,observation:t.observation}}function yo(e,t,r){const{columns:n,bands:a}=yS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function yS(e,t){const r=vS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=H(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=H(o.bandCenter);let m=a.get(d);m||(m={bandCenter:o.bandCenter,columns:[]},a.set(d,m)),m.columns.push(u)}u.rects.push(o.entry)}const i=[...n.values()].sort((o,c)=>o.mainMid-c.mainMid),s=[...a.values()].sort((o,c)=>o.bandCenter-c.bandCenter);for(const o of s)o.columns.sort((c,u)=>c.mainMid-u.mainMid);return{columns:i,bands:s}}function vS(e,t){const r=e.data;if(r.size()===0)return[];if(!(r.hasVariable(l.POSITION_VARIABLES.xMin)&&r.hasVariable(l.POSITION_VARIABLES.xMax)&&r.hasVariable(l.POSITION_VARIABLES.yMin)&&r.hasVariable(l.POSITION_VARIABLES.yMax)))return[];const n=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.y:l.POSITION_VARIABLES.x,u=r.hasVariable(c)?r.getValues(c,{type:"numeric"}):null,d=[];let m=0;for(const p of r){const h=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(h)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(h+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(h,f),xMax:Math.max(h,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:p}}),m++}return d}var SS=1e-9;function vo(e,t,r){const n=bS(e,t);n.sort((i,s)=>i.main-s.main);const a=[];for(const i of n){const s=a[a.length-1];s&&Math.abs(s.main-i.main)<=SS?s.entries.push(i.entry):a.push({main:i.main,entries:[i.entry]})}return{kind:"buckets",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,buckets:a}}function bS(e,t){const r=e.data;if(r.size()===0)return[];const n=r.hasVariable(l.POSITION_VARIABLES.x),a=r.hasVariable(l.POSITION_VARIABLES.y);if(!n||!a)return[];const i=r.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),o=t==="y",c=o?l.POSITION_VARIABLES.xMin:l.POSITION_VARIABLES.yMin,u=o?l.POSITION_VARIABLES.xMax:l.POSITION_VARIABLES.yMax,d=M(e.position),m=d?r.getValues(c,{type:"numeric"}):null,p=d?r.getValues(u,{type:"numeric"}):null,h=r.hasVariable(l.GROUP_VARIABLES.group)?r.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}):null,f=[];let g=0;for(const y of r){const v=i[g],x=s[g];if(!l.isDefined(v)||!l.isDefined(x)){g+=1;continue}const I=h?.[g]??null,A=o?x:v;if(d){const V=m?.[g],q=p?.[g];if(!l.isDefined(V)||!l.isDefined(q)){g+=1;continue}const re=o?q:v,W=o?x:q;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:re,y:W,stackMin:V,stackMax:q,groupKey:I,observation:y}})}else f.push({main:A,entry:{isStacked:d,pointIndex:g,x:v,y:x,groupKey:I,observation:y}});g+=1}return f}function xS(e){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",cells:AS(e)}}function AS(e){const t=e.data;if(t.size()===0)return[];const r=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const u of r)if(!t.hasVariable(u))return[];const n=t.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),a=t.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),i=t.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),s=t.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),o=[];let c=0;for(const u of t){const d=n[c],m=a[c],p=i[c],h=s[c];if(!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(p)||!l.isDefined(h)){c++;continue}o.push({pointIndex:c,xMin:d,xMax:m,yMin:p,yMax:h,observation:u}),c++}return o}function So(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function IS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:xo(e),delaunay:null,delaunayAspectRatio:null};return bo(r,t),r}function LS(e){const t=xo(e).map(r=>{const n=kt(r.x,r.y);return{...r,unitX:n.x,unitY:n.y}});return{kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"polar",points:t,delaunay:null,delaunayAspectRatio:null}}function bo(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=Xc.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function xo(e){const t=e.data;if(t.size()===0)return[];if(!t.hasVariable(l.POSITION_VARIABLES.x)||!t.hasVariable(l.POSITION_VARIABLES.y))return[];const r=t.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),n=t.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=[];let i=0;for(const s of t){const o=r[i],c=n[i];i+=1,!(!l.isDefined(o)||!l.isDefined(c))&&a.push({pointIndex:a.length,x:o,y:c,observation:s})}return a}function Ao(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:TS(e)}}function Io(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function TS(e){const t=e.identityKey,r=new Map;if(typeof t=="object"){let n=0;for(const a of e.data){const i=a[t.variable];l.isDefined(i)&&r.set(l.getStableKey(i),{pointIndex:n,observation:a}),n+=1}return r}if(t==="index"){let n=0;for(const a of e.data)r.set(String(n),{pointIndex:n,observation:a}),n+=1}return r}function Ya(e,t,r){return t.type==="polar"?wS(e,t.bandAxis):ES(e,t.mainAxis,r)}function wS(e,t){switch(e.spatialKind){case"points":return LS(e);case"buckets":return vo(e,"x","polar");case"rects":return t===null?xS(e):yo(e,t,"polar");case"noop":return So(e);case"render-hit-test":return Ao(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function ES(e,t,r){switch(e.spatialKind){case"points":return IS(e,r);case"buckets":return vo(e,t,"cartesian");case"rects":return yo(e,t,"cartesian");case"noop":return So(e);case"render-hit-test":return Ao(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function VS(e,t,r){if(e.columns.length===0)return null;const n=go(e,Pe(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=M(e.position)?RS(a,t,e.mainAxis):CS(a,t,r);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e,column:n,distance:Lo(i,t,r)}}function RS(e,t,r){const n=Nt(r,t);return oe(e,i=>kS(i,r,n),{shortCircuitOnZero:!0})}function CS(e,t,r){return oe(e,a=>Lo(a,t,r))}function Lo(e,t,r){return kn(_t(t.x,e.xMin,e.xMax),_t(t.y,e.yMin,e.yMax),r)}function kS(e,t,r){return _t(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function DS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=tu(e.mainAxis,t),i=fo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=To(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:kn(o.x-t.x,o.y-t.y,r)}}function To(e,t,r){return oe(e,a=>Math.abs(Nt(r,a)-t))}function OS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Ut(t,r),i=e.mainAxis==="x",s=i?_S(e.columns,n):go(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?PS(o,a):MS(o,n);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:c.pointIndex,x:(c.xMin+c.xMax)/2,y:(c.yMin+c.yMax)/2,observation:c.observation},index:e,column:s,distance:0}}function _S(e,t){return l.isNonEmptyArray(e)?oe(e,r=>Ct(t,r.mainMid)):null}function PS(e,t){return oe(e,r=>_t(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function MS(e,t){return oe(e,r=>_i(t,r.xMin,r.xMax)?0:Math.min(Ct(t,r.xMin),Ct(t,r.xMax)),{shortCircuitOnZero:!0})}function NS(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Ut(t,r),i=BS(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=To(s,a,e.mainAxis);return{hit:{anchored:!0,layerId:e.layerId,pointIndex:o.pointIndex,x:o.x,y:o.y,observation:o.observation},index:e,bucket:i,distance:0}}function BS(e,t){return l.isNonEmptyArray(e)?oe(e,r=>Ct(r.main,t)):null}function FS(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=Ut(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&_i(n,i.xMin,i.xMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:(i.xMin+i.xMax)/2,y:(i.yMin+i.yMax)/2,observation:i.observation},index:e};return null}function $S(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=jr(t,r),i=oe(e.points,s=>qa(s,n,a));return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:Math.sqrt(qa(i,n,a))}}function qa(e,t,r){const n=e.unitX??kt(e.x,e.y).x,a=e.unitY??kt(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var GS=.05;function US({layers:e,cursor:t,aspectRatio:r,warmStarts:n,hitTesters:a}){const i={match:null,distance:Number.POSITIVE_INFINITY},s={match:null,distance:Number.POSITIVE_INFINITY};for(const o of e){if(o.kind==="render-hit-test"){const u=KS(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=zS(o,t,r);if(u)return u;continue}const c=HS({layer:o,cursor:t,aspectRatio:r,warmStarts:n});if(c){if(c.kind==="banded"){c.match.distance<i.distance&&(i.match=c,i.distance=c.match.distance);continue}c.match.distance<s.distance&&(s.match=c,s.distance=c.match.distance)}}return WS({rect:i,continuous:s})}function WS({rect:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+GS?t.match:e.match:e.match??t.match}function HS({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=DS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=VS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=sS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"noop":return null}}function zS(e,t,r){switch(e.kind){case"enclosure":{const n=FS(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=$S(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=NS(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=OS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function KS(e,t,r){const n=r.get(e.layerId);if(!n)return null;const a=n({x:t.x,y:1-t.y});if(!a)return null;const i=e.byKey.get(a.key);return i?{hit:Io(e.layerId,i)}:null}var Z={primary:null,group:[],related:new Map},YS=1,qS=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=YS,this.warmStarts=new Map,this.cachedState=Z,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=Z,this.layerIndexes=e.map(r=>Ya(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>ja(r,t)),this.nonInteractiveLayerIds=Xa(e)}update({layers:e,coordSystem:t}){const r=new Map;for(let i=0;i<this.layerIndexes.length;i+=1){const s=this.layerIndexes[i],o=this.layerRefs[i];!s||!o||r.set(s.layerId,{index:s,ref:o})}const n=[],a=[];for(const i of e){const s=r.get(i.id),o=ja(i,t);if(s!==void 0&&jS(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(Ya(i,t,this.aspectRatio)),a.push(o)}for(const i of this.warmStarts.keys())e.some(s=>s.id===i)||this.warmStarts.delete(i);this.layerIndexes=n,this.layerRefs=a,this.nonInteractiveLayerIds=Xa(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&bo(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return Z;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=US({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),Z;const n=r.match.hit;this.warmStarts.set(n.layerId,n.pointIndex);const a=`${n.layerId}:${n.pointIndex}`;if(this.cachedKey===a)return this.cachedState;const{group:i,related:s}=cS(r,t);return this.cachedKey=a,this.cachedState={primary:n,group:i,related:s},this.cachedState}registerHitTester(e,t){this.hitTesters.set(e,t)}unregisterHitTester(e){this.hitTesters.delete(e)}resolveHoverByKey(e,t){if(this.nonInteractiveLayerIds.has(e))return Z;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return Z;const n=r.byKey.get(t);if(!n)return Z;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:Io(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=Z,this.cachedByKeyId=null,this.cachedByKeyState=Z}};function ja(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function Xa(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function jS(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var XS=Math.PI*2;function ZS(e,t){const r=Pe(e.mainAxis,t);if(e.mainAxis==="y"){const a=de(te(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=de(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function JS(e,t,r){const n=e.mainAxis==="y"?E(r.observation):R(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?Eo(r):wo(r),i=(t.x?.kind==="position"?t.x:null)?.bandwidth??a;if(i===null||i<=0)return null;const s=i/2;return e.mainAxis==="y"?{x:0,y:de(te(n+s)),width:"100%",height:de(i)}:{x:de(n-s),y:0,width:de(i),height:"100%"}}function QS(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=z(t.observation),i=K(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=F(t.observation),n=P(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+XS,innerRadius:r,outerRadius:n}}function wo(e){const t=z(e.observation),r=K(e.observation);return t===null||r===null?null:r-t}function Eo(e){const t=F(e.observation),r=P(e.observation);return t===null||r===null?null:r-t}var Xt=.5,eb=.4,tb=10,rb=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?ab(e,t,r,n):ib(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?ob(e,t,n):e.spatialKind==="points"?sb(e,n):null,nb=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},ab=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:Xt*n.durationScale,baseline:lb(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?cb(e,t.mainAxis,n):{}}),ib=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:Xt*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?mb(e,t,r):{}}},sb=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:Xt*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?ub(e,t):{}}),ob=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:Xt*r.durationScale,axis:t.mainAxis}),lb=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[ne(e.yScaleType)];if(!a||a.kind!=="position")return n;const i=a.map(0);if(!Number.isFinite(i))return n;const s=Math.min(1,Math.max(0,i));return t.mainAxis==="x"?1-s:s},cb=(e,t,r)=>{const n=jt(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=co(t,i);if(!s)continue;const o=uo(t,s),c=n(i),u=a.get(o);u?u.keys.push(c):a.set(o,{position:t==="x"?s.x:s.y,keys:[c]})}return _n([...a.values()],r)},ub=(e,t)=>{const r=jt(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=db(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return _n(n,t)},db=(e,t)=>{if(t==="main-axis")return R(e);const r=Kr(e)??R(e);return r===null?null:t==="value-descending"?-r:r},mb=(e,t,r)=>{const n=jt(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Ln(i),{innerRadius:c,outerRadius:u}=Tn(i);if(s===null||o===null||c===null||u===null)continue;const d=po(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),p=a.get(d);p?p.keys.push(m):a.set(d,{position:s,keys:[m]})}return _n([...a.values()],r)},_n=(e,t)=>{const r={};if(e.length===0)return r;const n=[...e].sort((o,c)=>o.position-c.position),a=Math.ceil(n.length/tb),i=Math.ceil(n.length/a),s=eb*t.durationScale/i;return n.forEach((o,c)=>{const u=Math.floor(c/a)*s;for(const d of o.keys)r[d]=u}),r},Re=["top","right","bottom","left"],Za={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},hb={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},pb={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},fb=(e,t)=>{const{edges:r,borderRadius:n}=e,a=Math.max(0,Math.min(n,t.width/2,t.height/2)),i=c=>{const[u,d]=pb[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=yb(t,a),o=vb(t,a,i);return Sb(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:bb(c,s,o,i)}))},gb=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),yb=(e,t)=>{const{x:r,y:n,width:a,height:i}=e;return{topLeft:{cx:r+t,cy:n+t,startAngle:Math.PI,endAngle:Math.PI*1.5,radius:t},topRight:{cx:r+a-t,cy:n+t,startAngle:Math.PI*1.5,endAngle:Math.PI*2,radius:t},bottomRight:{cx:r+a-t,cy:n+i-t,startAngle:0,endAngle:Math.PI*.5,radius:t},bottomLeft:{cx:r+t,cy:n+i-t,startAngle:Math.PI*.5,endAngle:Math.PI,radius:t}}},vb=(e,t,r)=>{const{x:n,y:a,width:i,height:s}=e,o=c=>r(c)?t:0;return{top:{start:{x:n+o("topLeft"),y:a},end:{x:n+i-o("topRight"),y:a}},right:{start:{x:n+i,y:a+o("topRight")},end:{x:n+i,y:a+s-o("bottomRight")}},bottom:{start:{x:n+i-o("bottomRight"),y:a+s},end:{x:n+o("bottomLeft"),y:a+s}},left:{start:{x:n,y:a+s-o("bottomLeft")},end:{x:n,y:a+o("topLeft")}}}},Sb=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Re.indexOf(s)+o+Re.length)%Re.length;return Re[c]},n=s=>{const o=r(s,-1);return!t(o)||e[o].lineType!==e[s].lineType||e[o].strokeWidth!==e[s].strokeWidth||e[o].color!==e[s].color},a=Re.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Re],isClosed:!0}]:i.map(s=>{const o=[s];for(let c=r(s,1);t(c)&&!n(c);c=r(c,1))o.push(c);return{firstEdge:s,edges:o,isClosed:!1}})},bb=(e,t,r,n)=>{const a=(m,p,h)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:p,endAngle:h}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=Za[o];if(!e.isClosed&&n(u)){const m=t[u],p=i(m),h=xb(m,p);s.push({type:"move",x:h.x,y:h.y}),s.push(a(m,p,m.endAngle))}else s.push({type:"move",x:r[o].start.x,y:r[o].start.y});s.push({type:"line",x:r[o].end.x,y:r[o].end.y});for(const m of e.edges.slice(1)){const p=Za[m];if(n(p)){const h=t[p];s.push(a(h,h.startAngle,h.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=hb[c];if(e.isClosed){if(n(d)){const m=t[d];s.push(a(m,m.startAngle,m.endAngle))}s.push({type:"close"})}else if(n(d)){const m=t[d];s.push(a(m,m.startAngle,i(m)))}return s},xb=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Ab=/^(?:https?:|mailto:)/i,Ib=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Ab.test(t)},Lb=({locale:e,intlOptions:t})=>_(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...B,...t}).format(r)),Tb=({locale:e,intlOptions:t})=>_(r=>{const n=r.getUTCSeconds()!==0;return Intl.DateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",weekday:"short",hour:"2-digit",minute:"2-digit",second:n?"2-digit":void 0,...B,...t}).format(r)}),Pt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Ds(e);case"date":return Lb(e);case"datetime":return Tb(e);case"day_month":return Ms(e);case"decimal":return Os(e);case"duration":return dn(e);case"integer":return _s(e);case"month":return Ns(e);case"month_year":return pn(e);case"percentage":return Ps(e);case"quarter":return fn(e);case"text":return un(e);case"time":return $s(e);case"weekly_date_range":return Bs(e);case"weekly_date_range_with_year":return Fs(e);case"year":return gn(e);case"lookup":return Pt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},wb=({layers:e,coordSystem:t,scales:r,guides:n,numberFormat:a,parsingLocale:i,hover:s,colorScheme:o,formattingLocale:c,comments:u,activeCalloutId:d})=>{const{primary:m}=s;if(m===null)return null;const p=c??i,h=Eb(u,d);return{header:h===null?Vb({layers:e,coordSystem:t,guides:n,primary:m,locale:p,numberFormat:a}):null,rows:Rb({layers:e,scales:r,guides:n,hover:s,locale:p,numberFormat:a,colorScheme:o}),comment:h}};function Eb(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function Vb(e){if(e.coordSystem.type!=="cartesian")return null;const t=Rn(e.guides,"x");if(!t)return null;const r=e.layers.find(i=>i.id===e.primary.layerId);if(!r)return null;const n=l.extractVariableName(r.mapping.x);if(!l.isDefined(n))return null;const a=e.primary.observation[n];return l.isDefined(a)?Pt({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function Rb(e){const t=[],r=e.scales.color??null,n=In({colorScheme:e.colorScheme}),a=Ob({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=kb(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...Cb(i,o,{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=vi(i.data,i.mapping),u=Db(s,i,r,c),d=wn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=_b(e.guides,i),p=He(i),h=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=h?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",I=h&&y!==null?a(y):m,A=p(g.observation),V=A===null?"":d(A,g.observation);t.push({swatchColor:v,geom:i.geom,swatchLineType:x,label:I,value:V,isPrimary:g===e.hover.primary,key:`${g.layerId}:${g.pointIndex}`})}}return t}function Cb(e,t,r){return e.tooltip.map(n=>{const a=e.mapping[n.aes],i=U(e.data,a)(t.observation),s=C({valueFormat:pi(e,l.extractVariableName(a)),locale:r.locale,numberFormat:r.numberFormat});return{swatchColor:null,geom:e.geom,swatchLineType:"solid",label:n.key,value:i===null?"":s(i,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${n.aes}`}})}function kb(e,t){const r=[];return t.primary!==null&&t.primary.layerId===e.id&&r.push(t.primary,...t.group),r.push(...t.related.get(e.id)??[]),r}function Db(e,t,r,n){if(r===null||t.mapping.color===void 0)return e;const a=new Map;return r.domain.forEach((i,s)=>{a.set(l.getStableKey(i),s)}),e.map((i,s)=>{const o=n(i.observation),c=o===null?null:l.getStableKey(o);return{hit:i,originalIndex:s,rank:c===null?Number.POSITIVE_INFINITY:a.get(c)??Number.POSITIVE_INFINITY}}).sort((i,s)=>i.rank===s.rank?i.originalIndex-s.originalIndex:i.rank-s.rank).map(i=>i.hit)}function Ob({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:Pt({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=Pt({valueFormat:{type:"text"},locale:t,numberFormat:r});return i=>{const s=n.get(l.getStableKey(i));return s===void 0?a(i):s.label??s.format(i)}}function _b(e,t){return Jr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function Pb(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function Mb(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var Nb=e=>({edges:{top:Oe(e.panelBorder("top")),right:Oe(e.panelBorder("right")),bottom:Oe(e.panelBorder("bottom")),left:Oe(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),Bb=(e,t)=>Oe(e.gridLine(t)),Fb=(e,t)=>{const r=e.tickLine(t);return{...Oe(r),length:r.get("length")}},$b=e=>{const t=e.graph.get("borderColor");return{background:e.graph.get("background"),...t===void 0?{}:{borderColor:t},borderWidth:e.graph.get("borderWidth"),borderRadius:e.graph.get("borderRadius")}},Gb=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},Oe=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),Ub=e=>e.fontSize*e.lineHeight,Wb=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),Zt=(e,t)=>({fontFamily:e.get("fontFamily"),fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),Hb=(e,t,r)=>Zt(e.axisLabel(t),r),zb=(e,t,r)=>{const n=e.tickLabel(t);return{...Zt(n,r),offset:n.get("offset")}},Kb=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...Zt(a,n),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},Yb=(e,t,r)=>{const n=e.ruleLabel(t);return{fontFamily:n.get("fontFamily"),fontSize:n.get("fontSize")*r,fontWeight:n.get("fontWeight"),lineHeight:n.get("lineHeight")}},Jt={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},qb={differenceArrow(e){return{type:"annotation",kind:"differenceArrow",annotation:e}},shape(e){return{type:"annotation",kind:"shape",annotation:e}},arrow(e){return{type:"annotation",kind:"arrow",annotation:e}},text(e){return{type:"annotation",kind:"text",annotation:e}},image(e){return{type:"annotation",kind:"image",annotation:e}},sticker(e){return{type:"annotation",kind:"sticker",annotation:e}},pinnedNumber(e){return{type:"annotation",kind:"pinnedNumber",annotation:e}},comment(e){return{type:"annotation",kind:"comment",annotation:e}}},jb=Object.keys(Jt),Xb=e=>Object.hasOwn(Jt,e),st=(e,t)=>{for(const r of jb){const n=Zb(e,r,t);if(n)return n}return null},ot=(e,t)=>e[Jt[t]],Pn=(e,t,r)=>({...e,[Jt[t]]:r}),Vo=(e,t)=>{const r=ot(e,t.kind);return Pn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},Zb=(e,t,r)=>{const n=ot(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},Mn=["sticker","pinnedNumber","comment","image"],Jb=e=>Mn.includes(e),Nn=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?ex(e.annotation.at):null;default:return null}},Ro=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null),Co=(e,t,r=Qb)=>{const n=r(t);for(const a of Mn){const i=ot(e,a),s=i.findIndex(c=>{const u=Nn({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return Ro(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},Qb=e=>({...e,anchorValue:Ja(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Ja(e.groupValue)}}),Ja=e=>l.readISOInstant(e)??e,ex=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,align:e.align});function tx(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var rx=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&Bn(r.predicate,t.predicate))??null,Bn=(e,t)=>"and"in e?"and"in t&&Qa(e.and,t.and):"or"in e?"or"in t&&Qa(e.or,t.or):"not"in e?"not"in t&&Bn(e.not,t.not):nx(t)&&e.variable===t.variable&&ax(e,t),nx=e=>"variable"in e,Qa=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Bn(r,a)}),ax=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ei(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&ei(e.range,t.range),ei=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null));function ix(e){return{type:"mapping",mapping:e}}var Qt=(e,t)=>"and"in e?"and"in t&&ti(e.and,t.and):"or"in e?"or"in t&&ti(e.or,t.or):"not"in e?"not"in t&&Qt(e.not,t.not):sx(t)&&e.variable===t.variable&&ox(e,t),sx=e=>"variable"in e,ti=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&Qt(r,a)}),ox=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&ri(e.oneOf,t.oneOf):"lt"in e?"lt"in t&&l.areDataValuesEqual(e.lt,t.lt):"lte"in e?"lte"in t&&l.areDataValuesEqual(e.lte,t.lte):"gt"in e?"gt"in t&&l.areDataValuesEqual(e.gt,t.gt):"gte"in e?"gte"in t&&l.areDataValuesEqual(e.gte,t.gte):"range"in t&&ri(e.range,t.range),ri=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),ko=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="identity"&&(l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.y))||l.isStrictNumericDataValue(l.extractConstantValue(t.mapping.x)))),Do=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),Oo=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function _o(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(lx),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function lx(e){return e.scaleType==="palette"?cx(e):e}function cx(e){return{...e,palette:ux(e.palette),overrides:dx(e.overrides)}}function ux(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function dx(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var Fn=(e,t)=>{const r=$n(e,t);return r===-1?void 0:e[r]},$n=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&er(n,t))return r}return-1},er=(e,t)=>mx(e.select,t.select)&&e.when?.state===t.when?.state&&hx(e.when?.where,t.when?.where),Po=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>px(e[r],t[r])),fe=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),Gn=e=>e.select.target==="geom",lt=(e,t)=>{const r=Fn(e,t);if(!(r===void 0||!Gn(r)))return r.declarations},mx=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},hx=(e,t)=>e===void 0||t===void 0?e===t:Qt(e,t),px=(e,t)=>e===t?!0:l.isLightDarkColor(e)?l.isLightDarkColor(t)&&e.light===t.light&&e.dark===t.dark:l.isStyleTokenRef(e)?l.isStyleTokenRef(t)&&e.token===t.token:!1;function b(e){return{id:e.id??O(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function Ge(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>Ge(r,t[n]));if(l.isPlainObject(e)&&l.isPlainObject(t)){const r=Object.keys(e).filter(a=>e[a]!==void 0),n=Object.keys(t).filter(a=>t[a]!==void 0);return r.length===n.length&&r.every(a=>Ge(e[a],t[a]))}return!1}var Un=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=b({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=st(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:T(e,{annotations:Vo(e.annotations,t)}),revert:new Wn({kind:r,annotation:a,index:n},this.metadata)}}},fx={type:"remove-annotation",deserialize:(e,t)=>new Un(e,t)},Wn=class Mo{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??O()},...t.index!==void 0&&{index:t.index}},this.metadata=b({...r,description:"Add annotation"})}get target(){return{kind:"annotation",id:this.params.annotation.id}}apply(t){const{kind:r,annotation:n,index:a}=this.params;if(!Xb(r)||st(t.annotations,n.id))return null;const i=yx(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:Vo(t.annotations,i),o=ot(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:T(t,{annotations:Pn(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new Un({id:n.id},this.metadata):new Mo({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},gx={type:"add-annotation",deserialize:(e,t)=>new Wn({kind:e.kind,annotation:e.annotation,index:e.index},t)},yx=(e,t)=>{const r=Nn(t);return r===null?null:Co(e,r)},vx=(e,t)=>{const r=Hn(e);return r===null?null:No(r.points,t)},Sx=e=>Hn(e)!==null,bx=(e,t)=>{const r=Hn(e);if(r===null)return null;const n=No(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},Hn=e=>{const t=Ax[e.kind];return t===null?null:t(e.annotation)},ni=(e,t)=>e.anchorType!=="panel"?null:{points:[Gr(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},ai=(e,t)=>e.anchorType!=="panel"?null:{points:[{x:e.x,y:e.y},{x:e.x+e.width,y:e.y+e.height}],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},xx=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[Gr(e,e.offset),Gr(t,t.offset)],createPatch:r=>({start:{...e,x:e.x+r.x,y:e.y+r.y},end:{...t,x:t.x+r.x,y:t.y+r.y}})},Ax={text:e=>ni(e.at,t=>({at:t})),sticker:e=>ni(e.at,t=>({at:t})),shape:e=>ai(e.region,t=>({region:t})),image:e=>ai(e.region,t=>({region:t})),arrow:e=>xx(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},Gr=(e,t)=>t===void 0||t.unit==="px"?{x:e.x,y:e.y}:{x:e.x+(t.x??0),y:e.y+(t.y??0)},No=(e,t)=>({x:ii(e.map(r=>r.x),t.x),y:ii(e.map(r=>r.y),t.y)}),ii=(e,t)=>{if(!Number.isFinite(t))return 0;const r=Math.min(-Math.min(...e),0),n=Math.max(1-Math.max(...e),0);return!Number.isFinite(r)||!Number.isFinite(n)?0:(0,_e.default)(t,r,n)},Bo=(e,t,r)=>{const n=t.annotation;if(!Tx(n,r))return null;const a=ot(e.annotations,t.kind),i=Ix(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:T(e,{annotations:Pn(e.annotations,t.kind,s)}),inverse:Lx(n,r)}},Ix=(e,t)=>{const r=new Set(Object.entries(t).filter(([,n])=>n===void 0).map(([n])=>n));return Object.fromEntries(Object.entries({...e,...t}).filter(([n])=>!r.has(n)))},Lx=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},Tx=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),zn=class Fo{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=b({...r,description:"Update annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(t){const{kind:r,id:n,patch:a}=this.params,i=st(t.annotations,n);if(i===null||i.kind!==r)return null;const s=Bo(t,i,a);return s===null?null:{spec:s.spec,revert:new Fo({kind:r,id:n,patch:s.inverse},this.metadata)}}},wx={type:"update-annotation",deserialize:(e,t)=>new zn(e,t)},$o=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=b({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=st(e.annotations,this.params.id);if(t===null)return null;const r=bx(t,this.params.translation);if(r===null)return null;const n=Bo(e,t,r);return n===null?null:{spec:n.spec,revert:new zn({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},Ex={type:"move-annotation",deserialize:(e,t)=>new $o(e,t)},Vx=["cartesian","polar","flip"],Se=new zt,Go=class Uo{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=b({...r,description:_x(t)})}apply(t){const r="previous"in this.params?this.params.previous:Px(t,this.params);if(r===null)return null;const n=T(t,r);return n===t?null:{spec:n,revert:new Uo({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},Rx={type:"set-chart-type",deserialize:(e,t)=>new Go(e,t)},Cx={type:"sum"},kx={type:"identity"},Dx=["bar","line","area","point"],Ox=e=>{const t=e.layers.filter(zo),[r]=t;if(r===void 0||!t.every(s=>s.geom===r.geom&&s.position===r.position))return null;const{coords:n}=e,{geom:a,position:i}=r;return n.coordType==="polar"?{coordType:"polar",geom:a,position:i,theta:n.params.theta,innerRadius:n.params.innerRadius}:{coordType:n.coordType,geom:a,position:i}},_x=e=>"previous"in e?"Restore the previous chart type":`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,Px=(e,t)=>{if(!Bx(t))return null;const r=Wx(e.coords,t),n=Mx(e,t),a=$x({...e,mapping:n},t,n!==e.mapping);return{coords:r,layers:a,scales:zx(e,a,r.coordType),mapping:n}},Mx=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=Nx(e,t,r);return n===r?e.mapping:{...e.mapping,x:n}},Nx=(e,t,r)=>Wo(t)?"":r===""?l.inferXVariable(e.data):r,Wo=e=>e.coordType==="polar"&&e.theta==="y",Bx=e=>Vx.includes(e.coordType)&&Ho(e.geom)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),Ho=e=>Dx.includes(e),zo=e=>Ho(e.geom)&&!Fx(e.stat),Fx=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},$x=(e,t,r)=>{const{coordType:n,geom:a,position:i}=t,s=e.coords.coordType!==n;return hs(Se,qr(e.layers,o=>{if(!zo(o))return o;const c=Gx(o.stat,t);return s||r||o.geom!==a||o.position!==i||c!==o.stat?Ux(e,{...o,stat:c},t):o}))},Gx=(e,t)=>Wo(t)?e.type==="identity"?Cx:e:e.type==="sum"?kx:e,Ux=(e,t,{geom:r,position:n,coordType:a})=>{const i={geom:t.geom===r,coordType:e.coords.coordType===a,position:t.position===n},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...nt(Se,e.mapping,a,{type:"layer",id:t.id,geom:r,mapping:t.mapping,stat:t.stat,position:n,params:i.geom?t.params:void 0,yScaleType:t.yScaleType,transforms:t.transforms,interactive:t.interactive,dataLabels:{...d,...i.coordType&&{format:o},...i.geom&&i.coordType&&{offset:c},...i.geom&&i.position&&{justify:u}}}),stat:t.stat}},Wx=(e,t)=>{const r=Hx(e,t);return(0,Lr.default)(r,e)?e:r},Hx=(e,t)=>{const r={xLimits:e.params.xLimits,yLimits:e.params.yLimits};if(t.coordType!=="polar")return kr({type:"coord",coordType:t.coordType,params:r});const n=e.coordType==="polar"?e.params:It;return kr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},zx=(e,t,r)=>{const n=Dr(Se,t),a=Dr(Se,e.layers),i=e.coords.coordType==="polar";return qr(e.scales,s=>{const o=Kx(s,n,a);return qx(o,r,i)})},Kx=(e,t,r)=>{if(e.scaledAesthetic===t.discreteAxis&&e.scaleType!=="discrete")return gs(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}));if(e.scaledAesthetic===t.zeroAxis&&e.scaleType==="continuous"){const n=Yx(e.nice,t,r);return e.zero&&e.nice===n?e:{...e,zero:!0,nice:n}}return e},Yx=(e,t,r)=>t.niceZeroAxis===r.niceZeroAxis?e:t.niceZeroAxis?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,qx=(e,t,r)=>{if(e.scaleType!=="discrete"||!tt(e.scaledAesthetic))return e;if(t==="polar")return e.padding===0?e:{...e,padding:0};if(!r)return e;const{padding:n}=l.DISCRETE_SCALE_DEFAULTS;return e.padding===n?e:{...e,padding:n}},Ko=class Yo{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=b({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:w(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new Yo({textScale:r},this.metadata)}}},jx={type:"set-appearance-text-scale",deserialize:(e,t)=>new Ko(e,t)},tr=e=>e==="both"?["x","y"]:[e],qo=e=>e==="both"?"the":`${e} axis`;function Ue(e,t){return Jx(e)?e[t]:e}function Xx(e,t){return e.config.axes[t]??{}}function Zx(e,t,r){if(t!=="ySecondary")return w(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=jo(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,T(e,{config:T(e.config,{axes:i})})}function Jx(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function jo(e,t){const r={};let n=!1;for(const a of new Set([...Object.keys(e??{}),...Object.keys(t)])){const i=e?.[a],s=a in t?Qx(i,t[a]):i;s!==i&&(n=!0),s!==void 0&&(r[a]=s)}return n?Object.keys(r).length>0?r:void 0:e}function Qx(e,t){return l.isPlainObject(t)?jo(l.isPlainObject(e)?e:void 0,t):t}var Xo=class Zo{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis label to ${tA(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=Xx(t,r).label;if(a===n)return null;const i=Zx(t,r,{label:n});return i===t?null:{spec:i,revert:new Zo(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},eA={type:"set-axis-label",deserialize:(e,t)=>new Xo(e,t)};function tA(e){return e===void 0?"(inherited)":e??"(none)"}var Jo=class Qo{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis position to ${t.position}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,position:n}=this.params,a=t.config.axes[r].position;return a===n?null:{spec:w(t,{config:{axes:{[r]:{position:n}}}}),revert:new Qo({axis:r,position:a},this.metadata)}}},rA={type:"set-axis-position",deserialize:(e,t)=>new Jo(e,t)},el=class tl{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis tick mode to ${t.tickMode}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,tickMode:n}=this.params,a=t.config.axes[r].ticks.mode;return a===n?null:{spec:w(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new tl({axis:r,tickMode:a},this.metadata)}}},nA={type:"set-axis-tick-mode",deserialize:(e,t)=>new el(e,t)},rl=class nl{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis ticks visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].ticks.isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new nl({axis:r,isVisible:a},this.metadata)}}},aA={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new rl(e,t)},al=class il{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis visibility to ${t.isVisible}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new il({axis:r,isVisible:a},this.metadata)}}},iA={type:"set-axis-visibility",deserialize:(e,t)=>new al(e,t)},sl=class ol{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=b({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:w(t,{config:{content:{caption:this.params.caption}}}),revert:new ol({caption:r},this.metadata)}}},sA={type:"set-content-caption",deserialize:(e,t)=>new sl(e,t)},ll=class cl{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=b({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(Ge(r,this.params.source))return null;const n=T(t.config.content,{source:this.params.source});return{spec:T(t,{config:T(t.config,{content:n})}),revert:new cl({source:r},this.metadata)}}},oA={type:"set-content-source",deserialize:(e,t)=>new ll(e,t)},ul=class dl{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=b({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:w(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new dl({subtitle:r},this.metadata)}}},lA={type:"set-content-subtitle",deserialize:(e,t)=>new ul(e,t)},ml=class hl{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=b({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:w(t,{config:{content:{title:this.params.title}}}),revert:new hl({title:r},this.metadata)}}},cA={type:"set-content-title",deserialize:(e,t)=>new ml(e,t)},pl=class fl{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=b({...r,description:`Set ${qo(t.axis)} grid line style to ${dA(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=tr(r),i={x:t.config.axes.x.grid.lineStyle,y:t.config.axes.y.grid.lineStyle};return a.every(s=>i[s]===Ue(n,s))?null:{spec:a.reduce((s,o)=>w(s,{config:{axes:{[o]:{grid:{lineStyle:Ue(n,o)}}}}}),t),revert:new fl({axis:r,lineStyle:r==="both"?i:i[r]},this.metadata)}}},uA={type:"set-grid-line-style",deserialize:(e,t)=>new pl(e,t)},dA=({axis:e,lineStyle:t})=>{const r=tr(e).map(n=>Ue(t,n));return[...new Set(r)].join(" and ")},mA={type:"set-grid-line-width",deserialize:(e,t)=>new gl(e,t)},gl=class yl{constructor(t,r={}){this.type="set-grid-line-width";const n=hA(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=b({...r,description:`Set ${qo(t.axis)} grid line width to ${pA(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=tr(r),i={x:t.config.axes.x.grid.lineWidth,y:t.config.axes.y.grid.lineWidth};return a.every(s=>i[s]===Ue(n,s))?null:{spec:a.reduce((s,o)=>w(s,{config:{axes:{[o]:{grid:{lineWidth:Ue(n,o)}}}}}),t),revert:new yl({axis:r,lineWidth:r==="both"?i:i[r]},this.metadata)}}},hA=e=>typeof e=="object"&&e!==null?{x:br(e.x),y:br(e.y)}:br(e),br=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),pA=(e,t)=>{const r=tr(e).map(n=>Ue(t,n)??"(theme)");return[...new Set(r)].join(" and ")},vl=class Sl{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.axis} axis grid visibility to ${t.isVisible??"(auto)"}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,isVisible:n}=this.params,a=t.config.axes[r].grid.isVisible;return a===n?null:{spec:w(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new Sl({axis:r,isVisible:a},this.metadata)}}},fA={type:"set-grid-visibility",deserialize:(e,t)=>new vl(e,t)},bl=class xl{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:w(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new xl({compareWith:r},this.metadata)}}},gA={type:"set-headline-compare-with",deserialize:(e,t)=>new bl(e,t)},Al=class Il{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:w(t,{config:{headline:{position:this.params.position}}}),revert:new Il({position:r},this.metadata)}}},yA={type:"set-headline-position",deserialize:(e,t)=>new Al(e,t)},Ll=class Tl{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:w(t,{config:{headline:{show:this.params.show}}}),revert:new Tl({show:r},this.metadata)}}},vA={type:"set-headline-show",deserialize:(e,t)=>new Ll(e,t)},wl=class El{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=b({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:w(t,{config:{headline:{size:this.params.size}}}),revert:new El({size:r},this.metadata)}}},SA={type:"set-headline-size",deserialize:(e,t)=>new wl(e,t)},Ie=class Et{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=b({...r,description:t.rule.declarations===null?"Remove style rule":"Set style rule"})}get target(){const{list:t,rule:r}=this.params;return{kind:"styleRule",list:t,select:r.select,...r.when===void 0?{}:{when:r.when}}}apply(t){const{list:r,rule:n,index:a}=this.params,i=t.styles[r],s=$n(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new Et({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!er(y,n));return{spec:xr(t,r,g),revert:f}}if(o!==void 0){if(Po(o.declarations,c))return null;const f={...o,declarations:c},g=new Et({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:xr(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},p=[...i.slice(0,d),m,...i.slice(d)],h=new Et({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:xr(t,r,p),revert:h}}},bA=e=>{const{rule:t}=e;if(t==null)throw new l.UserInputError({code:"INVALID_STYLE_RULE",message:"Command 'set-style-rule' is missing its 'rule'.",suggestion:"Send the entry's 'select' (and 'when') with 'declarations: null' to remove it."})},xA={type:"set-style-rule",deserialize:(e,t)=>(bA(e),new Ie(e,t))},xr=(e,t,r)=>T(e,{styles:{...e.styles,[t]:r}}),AA={type:"set-highlight-dim-style",deserialize:(e,t)=>new Vl(e,t)},Vl=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=b({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Rl(e)===this.params.dimStyle)return null;const t=new Ie({list:"overrides",rule:LA(this.params.dimStyle)},this.metadata).apply(e);return t||null}},IA={select:{target:"geom"},when:{state:"dimmed"}},Rl=e=>{const t=Fn(e.styles.overrides,IA);return(t!==void 0&&Gn(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},LA=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),Cl=class kl{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:w(t,{config:{legend:{align:this.params.align}}}),revert:new kl({align:r},this.metadata)}}},TA={type:"set-legend-align",deserialize:(e,t)=>new Cl(e,t)},Dl=class Ol{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:w(t,{config:{legend:{display:this.params.display}}}),revert:new Ol({display:r},this.metadata)}}},wA={type:"set-legend-display",deserialize:(e,t)=>new Dl(e,t)},_l=class Pl{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=b({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:w(t,{config:{legend:{position:this.params.position}}}),revert:new Pl({position:r},this.metadata)}}},EA={type:"set-legend-position",deserialize:(e,t)=>new _l(e,t)},Ml=class Nl{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=b({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:w(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Nl({abbreviation:r},this.metadata)}}},VA={type:"set-number-format-abbreviation",deserialize:(e,t)=>new Ml(e,t)},Bl=class Fl{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=b({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:w(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Fl({decimals:r},this.metadata)}}},RA={type:"set-number-format-decimals",deserialize:(e,t)=>new Bl(e,t)},$l=class Gl{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=b({...r,description:`Set ${t.slot} visibility to ${t.isVisible}`})}get target(){return{kind:"content",part:this.params.slot}}apply(t){const{slot:r,isVisible:n}=this.params,a=kA(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:w(t,{config:{content:{[a]:n}}}),revert:new Gl({slot:r,isVisible:i},this.metadata)}}},CA={type:"toggle-content-visibility",deserialize:(e,t)=>new $l(e,t)},si={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function kA(e){return Object.hasOwn(si,e)?si[e]:void 0}var Ul=class Wl{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=b({...r,description:"Set coordinate limits"})}apply(t){const{xLimits:r,yLimits:n}=this.params,a=t.coords.params,i={xLimits:r!==void 0?r:a.xLimits,yLimits:n!==void 0?n:a.yLimits};if(Ge(i.xLimits,a.xLimits)&&Ge(i.yLimits,a.yLimits))return null;const s={};r!==void 0&&(s.xLimits=a.xLimits),n!==void 0&&(s.yLimits=a.yLimits);const o=new Wl(s,this.metadata);return{spec:T(t,{coords:OA(t.coords,i)}),revert:o}}},DA={type:"set-coord-limits",deserialize:(e,t)=>new Ul(e,t)};function OA(e,t){switch(e.coordType){case"cartesian":return{...e,params:{...e.params,...t}};case"flip":return{...e,params:{...e.params,...t}};case"polar":return{...e,params:{...e.params,...t}}}}var Hl=class zl{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,_e.default)(t.innerRadius,0,1)},this.metadata=b({...r,description:`Set polar inner radius to ${this.params.innerRadius}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.innerRadius;return n===this.params.innerRadius?null:{spec:T(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new zl({innerRadius:n},this.metadata)}}},_A={type:"set-polar-inner-radius",deserialize:(e,t)=>new Hl(e,t)},PA={type:"set-polar-start-angle",deserialize:(e,t)=>new Kl(e,t)},Kl=class Yl{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:oi(t.startAngle)},this.metadata=b({...r,description:`Set polar start angle to ${this.params.startAngle}`})}apply(t){const r=t.coords;if(r.coordType!=="polar")return null;const n=r.params.startAngle;return oi(n)===this.params.startAngle?null:{spec:T(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Yl({startAngle:n},this.metadata)}}},Ar=360,oi=e=>(e%Ar+Ar)%Ar,Kn=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=b({...t,description:"Remove highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const t=e.highlights.find(i=>i.id===this.params.id);if(!t)return null;const r=e.highlights.indexOf(t),n=e.highlights.filter(i=>i!==t),a=new Yn({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:T(e,{highlights:n}),revert:a}}},MA={type:"remove-highlight",deserialize:(e,t)=>new Kn(e,t)},Yn=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??O(),scope:e.scope??"data-point"},this.metadata=b({...t,description:"Add highlight"})}get target(){return{kind:"highlight",id:this.params.id}}apply(e){const{predicate:t,id:r,scope:n,layerId:a,index:i}=this.params;if(e.highlights.some(d=>d.id===r))return null;const s=new Kn({id:r},this.metadata),o={type:"highlight",id:r,predicate:t,scope:n,...a!==void 0&&{layerId:a}},c=i??e.highlights.length,u=Math.min(Math.max(c,0),e.highlights.length);return{spec:T(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},NA={type:"add-highlight",deserialize:(e,t)=>new Yn(e,t)};function qn(e,t){return{...e,params:{...e.params,...t}}}function rr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function jn(e,t){return T(e,{layers:[...e.layers,t]})}function $(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:T(e,{layers:Ci(e.layers,n,r)})}function nr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:T(e,{layers:e.layers.filter((n,a)=>a!==r)})}var Xn=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=b({...t,description:"Remove layer"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(e){const t=e.layers.findIndex(a=>a.id===this.params.layerId),r=e.layers[t];if(r===void 0)return null;const n=nr(e,this.params.layerId);return n===e?null:{spec:n,revert:new Zn({layer:r,index:t},this.metadata)}}},BA={type:"remove-layer",deserialize:(e,t)=>new Xn(e,t)},Zn=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??O()},...e.index!==void 0&&{index:e.index}},this.metadata=b({...t,description:`Add ${this.params.layer.geom} layer`})}get target(){return{kind:"layer",layerId:this.params.layer.id}}apply(e){const{layer:t,index:r}=this.params;if(e.layers.some(i=>i.id===t.id))return null;const n=r??e.layers.length,a=Math.min(Math.max(n,0),e.layers.length);return{spec:T(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new Xn({layerId:t.id},this.metadata)}}},FA={type:"add-layer",deserialize:(e,t)=>new Zn(e,t)},ql=class jl{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=b({...r,description:`Set bar border radius to ${t.borderRadius??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,borderRadius:n}=this.params;if(!Y(k(t.layers,r),"bar"))return null;const a=fe("bar",r),i=lt(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new Ie({list:"overrides",rule:{...a,declarations:GA(i,n)}}).apply(t);if(!o)return null;const c=new jl({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},$A={type:"set-bar-border-radius",deserialize:(e,t)=>new ql(e,t)},GA=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},UA={type:"set-bar-width",deserialize:(e,t)=>new Zl(e,t)},Xl=.05,WA=1,Zl=class Jl{constructor(t,r={}){this.type="set-bar-width";const n=(0,_e.default)(t.width,Xl,1);this.params={...t,width:n},this.metadata=b({...r,description:`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(!Number.isFinite(this.params.width))return null;const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"bar");if(!Y(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:$(t,r.id,qn(r,{width:this.params.width})),revert:new Jl({layerId:r.id,width:n},this.metadata)}}},Ql=class ec{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=b({...r,description:`Set data labels format to ${t.format}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:$(t,r.id,rr(r,{format:this.params.format})),revert:new ec({layerId:r.id,format:n},this.metadata)}}},HA={type:"set-data-labels-format",deserialize:(e,t)=>new Ql(e,t)},tc=class rc{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=b({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:$(t,r.id,{...r,position:this.params.position}),revert:new rc({layerId:r.id,position:n},this.metadata)}}},zA={type:"set-layer-position",deserialize:(e,t)=>new tc(e,t)},nc=class ac{constructor(t,r={}){this.type="set-layer-stat";const n=ms(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=b({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return YA(n,this.params.stat)?null:{spec:$(t,r.id,{...r,stat:this.params.stat}),revert:new ac({layerId:r.id,stat:n},this.metadata)}}},KA={type:"set-layer-stat",deserialize:(e,t)=>new nc(e,t)},YA=(e,t)=>{if(e.type!==t.type)return!1;const r=e,n=t,a=new Set([...Object.keys(r),...Object.keys(n)]);for(const i of a)if(!Object.is(r[i],n[i]))return!1;return!0},ic=class sc{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=b({...r,description:`Set layer to ${t.yScaleType} y axis`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;return n===this.params.yScaleType?null:{spec:$(t,r.id,{...r,yScaleType:this.params.yScaleType}),revert:new sc({layerId:r.id,yScaleType:n},this.metadata)}}},qA={type:"set-layer-y-scale-type",deserialize:(e,t)=>new ic(e,t)},oc=class lc{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=b({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");if(!Y(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:$(t,r.id,qn(r,{interpolate:this.params.interpolate})),revert:new lc({layerId:r.id,interpolate:n},this.metadata)}}},jA={type:"set-line-interpolation",deserialize:(e,t)=>new oc(e,t)},cc=class uc{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=b({...r,description:`Set missing values handling to ${t.missingValues}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");if(!Y(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:$(t,r.id,qn(r,{missingValues:this.params.missingValues})),revert:new uc({layerId:r.id,missingValues:n},this.metadata)}}},XA={type:"set-line-missing-values",deserialize:(e,t)=>new cc(e,t)},dc=class mc{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=b({...r,description:`Set line width to ${t.lineWidth??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,lineWidth:n}=this.params,a=k(t.layers,r);if(!Y(a,"line","area"))return null;const i=lt(t.styles.overrides,fe(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=JA(i,n),c=new Ie({list:"overrides",rule:a.geom==="area"?{...fe("area",r),declarations:o}:{...fe("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new mc({layerId:r,lineWidth:s},this.metadata)}:null}},ZA={type:"set-line-width",deserialize:(e,t)=>new dc(e,t)},JA=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},hc=class pc{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=b({...r,description:`Set point size to ${t.size??"(themed)"}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,size:n}=this.params;if(!Y(k(t.layers,r),"point"))return null;const a=fe("point",r),i=lt(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new Ie({list:"overrides",rule:{...a,declarations:eI(i,n)}}).apply(t);return o?{spec:o.spec,revert:new pc({layerId:r,size:s},this.metadata)}:null}},QA={type:"set-point-size",deserialize:(e,t)=>new hc(e,t)},eI=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},fc=class gc{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=b({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"rule");if(!Y(r,"rule"))return null;const n=r.params.label,a=this.params.label??void 0;if(n===a)return null;const i=a===void 0?Object.fromEntries(Object.entries(r.params).filter(([s])=>s!=="label")):{...r.params,label:a};return{spec:$(t,r.id,{...r,params:i}),revert:new gc({layerId:r.id,label:n??null},this.metadata)}}},tI={type:"set-rule-label",deserialize:(e,t)=>new fc(e,t)},yc=class vc{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=b({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"rule");if(!Y(r,"rule"))return null;const n=typeof l.extractConstantValue(r.mapping.y)=="number"?"y":"x",a=l.extractConstantValue(r.mapping[n]);if(typeof a!="number"||a===this.params.value)return null;const i={...r.mapping,[n]:{value:this.params.value}};return{spec:$(t,r.id,{...r,mapping:i}),revert:new vc({layerId:r.id,value:a},this.metadata)}}},rI={type:"set-rule-value",deserialize:(e,t)=>new yc(e,t)},nI={type:"set-stat-line",deserialize:(e,t)=>new Sc(e,t)},Sc=class bc{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=b({...r,description:uI(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=iI(t),n=this.buildStatLine(t,r?.line===this.params.line?r.layer.id:void 0);if(this.params.line!=="none"&&n===null||r===void 0&&n===null||r!==void 0&&n!==null&&cI(r.layer,n))return null;const a=new bc({line:r?.line??"none",...r!==void 0&&{removedLayer:r.layer},...r===void 0&&n!==null&&{layerId:n.id}},this.metadata);if(r!==void 0&&n!==null&&r.line===this.params.line)return{spec:$(t,r.layer.id,n),revert:a};const i=r===void 0?t:nr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:jn(i,n),revert:a}}buildStatLine(t,r){if(this.params.line==="none")return null;if(this.params.removedLayer!==void 0)return this.params.removedLayer;const n=this.params.line==="trend"?sI(this.params):oI(t,this.params);if(n===null)return null;const a=nt(Se,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},aI="linear",iI=e=>{const t=Do(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=Oo(e.layers);if(r!==void 0)return{line:"average",layer:r}},sI=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??aI}),interactive:!1}),oI=(e,{group:t,label:r})=>{const n=lI(e),a=l.extractVariableName(n?.mapping.y??e.mapping.y);if(a===null)return null;const i=l.extractVariableName(n?.mapping.color??e.mapping.color),s=i!==null&&t!==void 0;return l.geom.rule({aes:{y:a,color:void 0,group:void 0,lineType:void 0},stat:l.stat.mean(),transforms:s?[l.transform.filter({variableName:i,operator:"eq",value:t})]:[],params:{labelPosition:e.coords.coordType==="flip"?"end":"start",...r!==void 0&&{label:r}},yScaleType:n?.yScaleType,interactive:!1})},lI=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),cI=(e,t)=>(0,We.isEqual)({...e,id:""},{...t,id:""}),uI=e=>e==="none"?"Hide stat line":`Show ${e} line`,xc=class Ac{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=b({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:$(t,r.id,rr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new Ac({layerId:r.id,showCategoryLabels:n},this.metadata)}}},dI={type:"toggle-category-labels",deserialize:(e,t)=>new xc(e,t)},Ic=class Lc{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=b({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:$(t,r.id,rr(r,{showDataLabels:this.params.showDataLabels})),revert:new Lc({layerId:r.id,showDataLabels:n},this.metadata)}}},mI={type:"toggle-data-labels",deserialize:(e,t)=>new Ic(e,t)},hI={type:"toggle-goal-line",deserialize:(e,t)=>new Tc(e,t)},Tc=class Ur{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=b({...r,description:`${t.showGoalLine?"Show":"Hide"} goal line`})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=ko(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=nr(t,r.id);return a===t?null:{spec:a,revert:new Ur({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:jn(t,n),revert:new Ur({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return nt(Se,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??pI}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},pI=0,fI={type:"toggle-line-fill",deserialize:(e,t)=>new wc(e,t)},wc=class Ec{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=b({...r,description:`Set line fill to ${t.showFill}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const{layerId:r,showFill:n,fillAlpha:a}=this.params;if(!Y(k(t.layers,r),"line"))return null;const i=fe("line",r),s=lt(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new Ie({list:"overrides",rule:{...i,declarations:yI(s,n?a??gI:null)}}).apply(t);if(!u)return null;const d=new Ec({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},gI=.2,yI=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},vI={type:"toggle-line-points",deserialize:(e,t)=>new Vc(e,t)},Vc=class Wr{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=b({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):ae(t.layers,"line","area");return Y(r,"line","area")?this.params.showPoints?this.addPointLayer(t,r):this.removePointLayer(t,r):null}addPointLayer(t,r){return this.findAssociatedPointLayer(t,r)?null:{spec:jn(t,this.params.removedLayer??nt(Se,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new Wr({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:nr(t,n.id),revert:new Wr({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:en(n,[r]))}},Rc=class Cc{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=b({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?k(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:$(t,r.id,rr(r,{showStackTotals:this.params.showStackTotals})),revert:new Cc({layerId:r.id,showStackTotals:n},this.metadata)}}},SI={type:"toggle-stack-totals",deserialize:(e,t)=>new Rc(e,t)};function ct(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function ut(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:T(e,{scales:Ci(e.scales,n,r)})}function dt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}var kc=class Dc{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=b({...r,description:`Set ${dt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ct(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous"&&r.scaleType!=="datetime")return null;const n={min:r.domainMin??null,max:r.domainMax??null},a=this.params.domainMin===void 0?n.min:this.params.domainMin,i=this.params.domainMax===void 0?n.max:this.params.domainMax;if(a===n.min&&i===n.max)return null;const s={...r,...this.params.domainMin!==void 0&&{domainMin:this.params.domainMin},...this.params.domainMax!==void 0&&{domainMax:this.params.domainMax}},o=ut(t,this.params.scaledAesthetic,s),c={scaledAesthetic:this.params.scaledAesthetic};return this.params.domainMin!==void 0&&(c.domainMin=n.min),this.params.domainMax!==void 0&&(c.domainMax=n.max),{spec:o,revert:new Dc(c,this.metadata)}}},bI={type:"set-scale-domain",deserialize:(e,t)=>new kc(e,t)},Oc=class _c{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=b({...r,description:`Set ${dt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ct(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||Ge(r.palette,this.params.palette)?null:{spec:ut(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new _c({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},xI={type:"set-scale-palette",deserialize:(e,t)=>new Oc(e,t)},Pc=class Mc{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=b({...r,description:`Set ${dt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ct(t,this.params.scaledAesthetic);if(!r||!II(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:ut(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new Mc({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},AI={type:"set-scale-reverse",deserialize:(e,t)=>new Pc(e,t)};function II(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Nc=class Bc{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=b({...r,description:`Set ${dt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ct(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:ut(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Bc({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},LI={type:"set-scale-transform",deserialize:(e,t)=>new Nc(e,t)},Fc=class $c{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=b({...r,description:`Set ${dt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ct(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:ut(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new $c({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},TI={type:"set-scale-zero",deserialize:(e,t)=>new Fc(e,t)},Gc=class{constructor(){this.descriptors=new Map}register(e){if(this.descriptors.has(e.type))throw new l.InternalError({message:`CommandRegistry: descriptor for type '${e.type}' is already registered`});this.descriptors.set(e.type,e)}serialize(e){return{type:e.type,params:e.params,metadata:e.metadata}}deserialize(e){return this.getDescriptor(e.type).deserialize(e.params,e.metadata)}getRegisteredTypes(){return[...this.descriptors.keys()]}getDescriptor(e){const t=this.descriptors.get(e);if(!t)throw new l.InternalError({message:`CommandRegistry: no descriptor registered for type '${e}'`});return t}},S=new Gc;S.register(Rx);S.register(FA);S.register(BA);S.register(HA);S.register(zA);S.register(KA);S.register(qA);S.register(jA);S.register(ZA);S.register($A);S.register(UA);S.register(QA);S.register(XA);S.register(tI);S.register(rI);S.register(nI);S.register(dI);S.register(mI);S.register(hI);S.register(fI);S.register(vI);S.register(SI);S.register(bI);S.register(xI);S.register(AI);S.register(LI);S.register(TI);S.register(jx);S.register(eA);S.register(nA);S.register(rA);S.register(aA);S.register(iA);S.register(sA);S.register(oA);S.register(lA);S.register(cA);S.register(uA);S.register(mA);S.register(fA);S.register(gA);S.register(yA);S.register(vA);S.register(SA);S.register(AA);S.register(TA);S.register(wA);S.register(EA);S.register(VA);S.register(RA);S.register(CA);S.register(NA);S.register(MA);S.register(xA);S.register(gx);S.register(fx);S.register(wx);S.register(Ex);S.register(DA);S.register(_A);S.register(PA);var Uc=class{constructor(e={}){this.undoStack=[],this.redoStack=[],this.listeners=new Set,this.isEmitting=!1,this.cachedSnapshot=null,this.hasOpenRun=!1,this.maxHistorySize=e.maxHistorySize??100}apply(e,t,r,n={}){return this.withReentrancyGuard(()=>{const a=n.transient??!1,i=(u,d)=>r?d:u,s=e.apply(t);if(!s)return a||(this.hasOpenRun=!1),i(t,null);const o=r?.({spec:s.spec,command:e})??null,c=o?o.adopted:s.spec;return c?(this.push(e,c,s.revert,a),i(c,o?.value??null)):(a||(this.hasOpenRun=!1),i(t,o?.value??null))})}seal(){return this.withReentrancyGuard(()=>this.hasOpenRun?(this.hasOpenRun=!1,this.emit({type:"seal"}),!0):!1)}undo(e,t){return this.withReentrancyGuard(()=>{const r=this.undoStack[this.undoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.undoStack.pop(),this.redoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"undo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}redo(e,t){return this.withReentrancyGuard(()=>{const r=this.redoStack[this.redoStack.length-1];if(!r)return null;const n=this.step(r,e,t);return n?n.adopted?(this.redoStack.pop(),this.undoStack.push({command:r.command,revert:n.revert}),this.hasOpenRun=!1,this.emit({type:"redo",command:r.command,spec:n.adopted}),t?n.value:{spec:n.adopted,command:r.command}):n.value:null})}clear(){this.withReentrancyGuard(()=>{this.hasOpenRun=!1,!(this.undoStack.length===0&&this.redoStack.length===0)&&(this.undoStack=[],this.redoStack=[],this.emit({type:"clear"}))})}getSnapshot(){return this.cachedSnapshot||(this.cachedSnapshot={canUndo:this.undoStack.length>0,canRedo:this.redoStack.length>0,undoDescription:this.undoStack[this.undoStack.length-1]?.command.metadata.description??null,redoDescription:this.redoStack[this.redoStack.length-1]?.command.metadata.description??null,undoStack:li(this.undoStack),redoStack:li(this.redoStack)}),this.cachedSnapshot}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}step(e,t,r){const n=e.revert.apply(t);if(!n)return null;const a=r?.({spec:n.spec,command:e.command})??null;return{adopted:a?a.adopted:n.spec,revert:n.revert,value:a?.value??null}}push(e,t,r,n){const a=this.undoStack.length-1,i=this.undoStack[a],s=this.hasOpenRun&&i!==void 0&&EI(i.command,e);if(n&&s){this.undoStack[a]={command:e,revert:i.revert},this.cachedSnapshot=null;return}this.undoStack.push({command:e,revert:r}),this.undoStack.length>this.maxHistorySize&&this.undoStack.shift(),this.hasOpenRun=n,this.redoStack=[],this.emit({type:"apply",command:e,spec:t})}withReentrancyGuard(e){if(this.isEmitting)throw new l.InternalError({message:"CommandStack: cannot call apply/undo/redo/clear from within a listener"});this.isEmitting=!0;try{return e()}finally{this.isEmitting=!1}}emit(e){this.cachedSnapshot=null;for(const t of this.listeners)try{t(e)}catch(r){console.error("CommandStack listener error:",r)}}},wI=Object.freeze([]),EI=(e,t)=>{if(e.type!==t.type||e.target.kind!==t.target.kind)return!1;const r=e.target,n=t.target;for(const a of new Set([...Object.keys(r),...Object.keys(n)]))if(!Object.is(r[a],n[a]))return!1;return!0},li=e=>e.length===0?wI:e.map(t=>t.command.metadata),VI=(e,t)=>{if(e===t)return!0;if(e===null||t===null)return!1;switch(e.kind){case"annotation":return t.kind==="annotation"&&e.id===t.id;case"highlight":return t.kind==="highlight"&&e.id===t.id;case"styleRule":return t.kind==="styleRule"&&e.list===t.list&&er(e,t);case"content":return t.kind==="content"&&e.part===t.part;case"axis":return t.kind==="axis"&&e.axis===t.axis;case"grid":return t.kind==="grid"&&e.axis===t.axis;case"layer":return t.kind==="layer"&&e.layerId===t.layerId;case"observation":return t.kind==="observation"&&e.layerId===t.layerId&&e.index===t.index;case"mapping":return t.kind==="mapping"&&e.aesthetic===t.aesthetic;case"scale":return t.kind==="scale"&&e.aesthetic===t.aesthetic;case"legend":case"coords":case"appearance":case"headline":case"numberFormat":return e.kind===t.kind;default:throw new l.InternalError({message:`Unhandled edit target kind: ${e.kind}`})}},RI=class{constructor(e){this.history=e,this.frame=null}open(e){this.frame=e}clear(){this.frame=null}close(){const e=this.history.seal(),t=this.frame;return this.frame=null,e?t:null}},CI=class{constructor(e){this.compiler=e,this.history=new Uc,this.current=null,this.last=null,this.hostInput=null,this.run=new RI(this.history)}get compiled(){return this.current}compile(e){return this.last=e,this.hostInput=e.input,this.absorb(this.compiler.compile(e))}update(e){const t=this.last,r=!t||e.input!==this.hostInput&&e.input!==t.input,n=!t||e.data!==t.data,a=!t||e.customPalettes!==t.customPalettes;if(this.hostInput=e.input,!r&&!n&&!a)return null;let i=null;r?this.run.close():i=this.closeAndConvert();const s=this.last,o=s&&!r?s.input:e.input;this.last={input:o,data:e.data,customPalettes:e.customPalettes};const c=this.current,u=r||a||!c?this.absorb(this.compiler.compile({input:o,data:e.data,customPalettes:e.customPalettes})):this.absorb(this.compiler.recompile({spec:c.spec,data:e.data}));return r&&u.ok&&this.history.clear(),{result:u,inputChanged:r,...i&&{sealedInput:i.input}}}applyCommand(e,t={}){const r=t.transient??!1,n=[];if(!r){const c=this.sealNotification(!1);c&&n.push(c)}const{current:a,last:i,history:s}=this;if(!a||!i)return n;const o=s.apply(e,a.spec,({spec:c})=>{const u=this.commit(c,i,r,e);return{adopted:u.ok?u.compiled.spec:null,value:u}},t);return o&&n.push(this.renderedNotification(o,e,r)),n}seal(){const e=this.sealNotification(!0);return e?[e]:[]}undo(){return this.stepHistory((e,t)=>this.history.undo(e,t))}redo(){return this.stepHistory((e,t)=>this.history.redo(e,t))}stepHistory(e){const{current:t,last:r}=this;if(!t||!r)return[];const n=e(t.spec,({spec:a,command:i})=>{const s=this.commit(a,r);return{adopted:s.ok?s.compiled.spec:null,value:{result:s,command:i}}});return n?[this.renderedNotification(n.result,n.command,!1)]:[]}renderedNotification(e,t,r){return e.ok?r?{compiled:e.compiled}:{compiled:e.compiled,result:e,command:t,...e.input&&{input:e.input}}:{errors:e.errors}}sealNotification(e){const t=this.closeAndConvert();return t?{result:t.result,input:t.input,...e&&{command:t.command}}:null}closeAndConvert(){const e=this.run.close(),{current:t,last:r}=this;return!t||!r||!e?null:{input:this.recordCompiledInput(t.spec,r),result:e.result,command:e.command}}commit(e,t,r=!1,n=null){const a=this.compiler.recompile({spec:e});if(!a.ok)return{ok:!1,errors:a.errors};if(this.current=a.compiled,r&&n){const s={ok:!0,compiled:a.compiled,warnings:a.warnings};return this.run.open({result:s,command:n}),s}this.run.clear();const i=this.recordCompiledInput(a.compiled.spec,t);return{ok:!0,compiled:a.compiled,warnings:a.warnings,input:i}}recordCompiledInput(e,t){const r=_o(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},kI=500,DI="normal",Jn={thin:100,hairline:100,extraLight:200,ultraLight:200,light:300,normal:400,regular:400,medium:500,semiBold:600,demiBold:600,bold:700,extraBold:800,ultraBold:800,black:900,heavy:900,extraBlack:950,ultraBlack:950},OI=e=>{const t=e.style??"normal",r=e.weight??500,n=e.family.includes(",")?e.family:`'${e.family}'`;return`${t} ${r} ${e.size}px ${n}`},Qn=e=>typeof e!="string"?e??500:Jn[e],_I="\0",PI=class{constructor(e){this.inner=e,this.cache=new Map}measureText(e,t){const r=this.getCacheKey(e,t),n=this.cache.get(r);if(n)return n;const a=this.inner.measureText(e,t);return this.cache.set(r,a),a}getCacheKey(e,t){return[t.family,t.size,Qn(t.weight),t.style??"normal",e].join(_I)}},MI={" ":.25,"!":.27,'"':.36,"#":.6,$:.56,"%":.78,"&":.66,"'":.21,"(":.31,")":.31,"*":.44,"+":.56,",":.22,"-":.36,".":.22,"/":.35,0:.56,1:.56,2:.56,3:.56,4:.56,5:.56,6:.56,7:.56,8:.56,9:.56,":":.22,";":.22,"<":.56,"=":.56,">":.56,"?":.46,"@":.88,A:.63,B:.63,C:.65,D:.69,E:.56,F:.53,G:.7,H:.7,I:.26,J:.44,K:.62,L:.53,M:.84,N:.7,O:.73,P:.6,Q:.73,R:.62,S:.56,T:.56,U:.69,V:.6,W:.88,X:.58,Y:.56,Z:.58,"[":.29,"\\":.35,"]":.29,"^":.56,_:.44,"`":.33,a:.53,b:.58,c:.48,d:.58,e:.54,f:.31,g:.56,h:.57,i:.23,j:.23,k:.52,l:.23,m:.87,n:.57,o:.57,p:.58,q:.58,r:.35,s:.45,t:.34,u:.57,v:.49,w:.74,x:.49,y:.49,z:.46,"{":.33,"|":.26,"}":.33,"~":.56};var NI=1.05,BI=.84,FI=.21,$I=class{measureText(e,t){let r=0;for(const i of e)r+=(MI[i]??.55)*t.size;Qn(t.weight)>=Jn.semiBold&&(r*=NI);const n=BI*t.size,a=FI*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=Ny;exports.ARROW_DEFAULTS=ue;exports.AXIS_KEYS=Xr;exports.AddAnnotationCommand=Wn;exports.AddHighlightCommand=Yn;exports.AddLayerCommand=Zn;exports.BORDER_RADIUS_PX=Cn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Vh;exports.COMPILER_STAGE_KEYS=nf;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=PI;exports.CommandRegistry=Gc;exports.CommandStackManager=Uc;exports.Compiler=Es;exports.DATA_LABEL_POSITIONS=l.DATA_LABEL_POSITIONS;exports.DATA_LABEL_ROLES=l.DATA_LABEL_ROLES;exports.DEFAULT_AREA_ALPHA=l.DEFAULT_AREA_ALPHA;exports.DEFAULT_BAR_BORDER_RADIUS=l.DEFAULT_BAR_BORDER_RADIUS;exports.DEFAULT_BORDER_WIDTH=l.DEFAULT_BORDER_WIDTH;exports.DEFAULT_COLOR_PALETTE=l.DEFAULT_COLOR_PALETTE;exports.DEFAULT_DIMMED_ALPHA=l.DEFAULT_DIMMED_ALPHA;exports.DEFAULT_FONT_STYLE=DI;exports.DEFAULT_FONT_WEIGHT=kI;exports.DEFAULT_GEOM_COLOR=l.DEFAULT_GEOM_COLOR;exports.DEFAULT_GRAPH_BACKGROUND=l.DEFAULT_GRAPH_BACKGROUND;exports.DEFAULT_GRID_LINE_COLOR=l.DEFAULT_GRID_LINE_COLOR;exports.DEFAULT_HOVER_AFFORDANCE_COLOR=l.DEFAULT_HOVER_AFFORDANCE_COLOR;exports.DEFAULT_LOCALE=l.DEFAULT_LOCALE;exports.DEFAULT_POINT_SIZE=l.DEFAULT_POINT_SIZE;exports.DEFAULT_STROKE_WIDTH=l.DEFAULT_STROKE_WIDTH;exports.DEFAULT_TEXT_PRIMARY=l.DEFAULT_TEXT_PRIMARY;exports.DEFAULT_TEXT_SECONDARY=l.DEFAULT_TEXT_SECONDARY;exports.DEFAULT_TICK_LABEL_OFFSET=l.DEFAULT_TICK_LABEL_OFFSET;exports.DEFAULT_TICK_LINE_COLOR=l.DEFAULT_TICK_LINE_COLOR;exports.DEFAULT_TICK_LINE_LENGTH=l.DEFAULT_TICK_LINE_LENGTH;exports.DIFFERENCE_ARROW_DEFAULTS=xt;exports.DIVERGING_SCHEME_NAMES=cs;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ie;exports.GraphCompilationSession=CI;exports.HEADLINE_SWATCH_GAP=_v;exports.HEADLINE_SWATCH_SIZE=Ov;exports.HEADLINE_TREND_GAP=Nv;exports.HEADLINE_TREND_ICON_SIZE=Mv;exports.HEADLINE_VALUE_LABEL_GAP=Pv;exports.HeuristicTextMeasurer=$I;exports.HoverEngine=qS;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=mf;exports.LINE_STYLE_TYPES=zr;exports.LayoutCompiler=hy;exports.MAX_BAR_WIDTH=WA;exports.MIN_BAR_WIDTH=Xl;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=$o;exports.NAMED_WEIGHTS=Jn;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=Mn;exports.OUT_OF_VIEW_MARGIN_PX=By;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=ju;exports.POSITION_TYPES=au;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=Z;exports.RemoveAnnotationCommand=Un;exports.RemoveHighlightCommand=Kn;exports.RemoveLayerCommand=Xn;exports.SCHEME_ALIASES=us;exports.SEQUENTIAL_SCHEME_NAMES=Rh;exports.SHAPE_DEFAULTS=ce;exports.SIBLING_OVERLAP_THRESHOLD_PX=Fy;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=Ko;exports.SetAxisLabelCommand=Xo;exports.SetAxisPositionCommand=Jo;exports.SetAxisTickModeCommand=el;exports.SetAxisTicksVisibilityCommand=rl;exports.SetAxisVisibilityCommand=al;exports.SetBarBorderRadiusCommand=ql;exports.SetBarWidthCommand=Zl;exports.SetChartTypeCommand=Go;exports.SetContentCaptionCommand=sl;exports.SetContentSourceCommand=ll;exports.SetContentSubtitleCommand=ul;exports.SetContentTitleCommand=ml;exports.SetCoordLimitsCommand=Ul;exports.SetDataLabelsFormatCommand=Ql;exports.SetGridLineStyleCommand=pl;exports.SetGridLineWidthCommand=gl;exports.SetGridVisibilityCommand=vl;exports.SetHeadlineCompareWithCommand=bl;exports.SetHeadlinePositionCommand=Al;exports.SetHeadlineShowCommand=Ll;exports.SetHeadlineSizeCommand=wl;exports.SetHighlightDimStyleCommand=Vl;exports.SetLayerPositionCommand=tc;exports.SetLayerStatCommand=nc;exports.SetLayerYScaleTypeCommand=ic;exports.SetLegendAlignCommand=Cl;exports.SetLegendDisplayCommand=Dl;exports.SetLegendPositionCommand=_l;exports.SetLineInterpolationCommand=oc;exports.SetLineMissingValuesCommand=cc;exports.SetLineWidthCommand=dc;exports.SetNumberFormatAbbreviationCommand=Ml;exports.SetNumberFormatDecimalsCommand=Bl;exports.SetPointSizeCommand=hc;exports.SetPolarInnerRadiusCommand=Hl;exports.SetPolarStartAngleCommand=Kl;exports.SetRuleLabelCommand=fc;exports.SetRuleValueCommand=yc;exports.SetScaleDomainCommand=kc;exports.SetScalePaletteCommand=Oc;exports.SetScaleReverseCommand=Pc;exports.SetScaleTransformCommand=Nc;exports.SetScaleZeroCommand=Fc;exports.SetStatLineCommand=Sc;exports.SetStyleRuleCommand=Ie;exports.SpecResolver=vs;exports.Stat=Ae;exports.TAU=pe;exports.TEXT_ANNOTATION_DEFAULTS=At;exports.ToggleCategoryLabelsCommand=xc;exports.ToggleContentVisibilityCommand=$l;exports.ToggleDataLabelsCommand=Ic;exports.ToggleGoalLineCommand=Tc;exports.ToggleLineFillCommand=wc;exports.ToggleLinePointsVisibilityCommand=Vc;exports.ToggleStackTotalsCommand=Rc;exports.UpdateAnnotationCommand=zn;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=di;exports.annotation=qb;exports.areAnchorsEqual=De;exports.areEditMenuTriggersEqual=uv;exports.areEditTargetsEqual=VI;exports.areEndpointsComparable=mi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=Ro;exports.arePointerRegionListsEqual=nv;exports.arePredicatesEqual=Qt;exports.areStyleDeclarationsEqual=Po;exports.areStyleRuleAddressesEqual=er;exports.buildAverageLineSymbols=Oy;exports.buildCalloutHitRegions=My;exports.buildColumnKey=uo;exports.buildDataLabelsContent=_g;exports.buildDiagnostic=Ri;exports.buildEditMenuTriggerRegion=lv;exports.buildFontString=OI;exports.buildLayerIntroPlan=rb;exports.buildLayerStyleAddress=fe;exports.buildLayerYValueFormatter=wn;exports.buildObservationAnchor=Qe;exports.buildObservationPredicate=Xy;exports.buildPinnedNumberValueFormatter=xv;exports.buildPolarBarArcPath=Qv;exports.buildSliceGroupKey=po;exports.buildTooltipContent=wb;exports.canAnchorDirectLabels=ji;exports.canPlaceDataLabels=Og;exports.clampAnnotationTranslation=vx;exports.commandRegistry=S;exports.compileChromeStyles=xs;exports.compileStylesheetForLayer=Np;exports.computeArrow=ky;exports.computeDifferenceArrow=Zs;exports.computeDirectLabelsLayout=jy;exports.computeLineBoxHeight=Ub;exports.computePanelBorderPaths=fb;exports.computePanelBorderSizes=gb;exports.config=l.config;exports.convertSpecToInput=_o;exports.coord=l.coord;exports.countLayerGeoms=nb;exports.createAlphaValueReader=ou;exports.createAnchorResolver=fy;exports.createAreaPathGenerators=Hv;exports.createColorValueReader=vi;exports.createCompiler=af;exports.createDatasetFromKindPartitions=Nu;exports.createEmptyHighlight=Xi;exports.createGraphyBuilder=cf;exports.createGroupValueReader=lu;exports.createHeadlineItemRows=Bv;exports.createLabelValueReader=iu;exports.createLineFillAreaGenerator=Xv;exports.createLinePathGenerator=jv;exports.createObservationAnchorParser=xi;exports.createRawValueReader=U;exports.createSegmentYReader=He;exports.createSizeValueReader=su;exports.createSpec=Vs;exports.createStableBandKeyGenerator=aS;exports.createStableKeyGenerator=jt;exports.createStrokeWidthValueReader=cu;exports.createStyleResolver=In;exports.createValueFormatter=C;exports.createXValueReader=et;exports.createYValueReader=yi;exports.cursorToPiePlane=jr;exports.cursorToPolar=Ut;exports.describeMeasurementBasis=wr;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=ao;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=tm;exports.findAnnotation=st;exports.findAverageLineLayer=Oo;exports.findAxisGuide=Rn;exports.findDistinctLayers=tn;exports.findEquivalentHighlight=rx;exports.findGoalLineLayer=ko;exports.findHighlightsAtObservation=mv;exports.findKindStyleDeclarations=lt;exports.findLayerByGeom=ae;exports.findLayerById=k;exports.findLegendForAesthetic=kv;exports.findObservationAttachment=Co;exports.findPointerRegion=tv;exports.findStyleRule=Fn;exports.findStyleRuleIndex=$n;exports.findTrendLineLayer=Do;exports.formatDifferenceLabel=js;exports.formatHeadline=Av;exports.formatLegends=Rv;exports.formatRuleValue=Dv;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=N;exports.getAlpha=Si;exports.getAngleExtent=Ln;exports.getBarRectBounds=co;exports.getBoundingRect=qv;exports.getChromeDashArray=Gb;exports.getColor=Ft;exports.getCrossAxisCoordinate=Nt;exports.getCurve=qt;exports.getDashArray=Wv;exports.getDifferenceArrowDimensions=Xs;exports.getDifferenceArrowLabelBox=Yy;exports.getGroup=G;exports.getHoverGuideLineProps=ZS;exports.getHoverGuideRectProps=JS;exports.getLineType=bi;exports.getMainAxisCoordinate=Pe;exports.getNumericWeight=Qn;exports.getPolarHoverGuideArcProps=QS;exports.getRadiusExtent=Tn;exports.getRuleDashPattern=rS;exports.getRuleLabelTextColor=nS;exports.getScaledAesthetic=Jc;exports.getSize=Kr;exports.getStablePolarBarKeyGenerator=iS;exports.getStackRole=Qi;exports.getStrokeWidth=Vr;exports.getUnionExtent=tS;exports.getX=R;exports.getXMax=K;exports.getXMin=z;exports.getY=E;exports.getYMax=P;exports.getYMin=F;exports.getYRaw=Hr;exports.hasMultipleGroups=Ht;exports.highlight=tx;exports.inferDefaultDifferenceArrowEndpoints=gv;exports.inferDifferenceArrowEndpoints=oo;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=Sx;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=ru;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isCompanionLayer=en;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=Oi;exports.isGeomStyleRule=Gn;exports.isLayerOf=sf;exports.isLayerOfType=Y;exports.isLineStyleType=gi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=Jb;exports.isPointWithinEditMenuTrigger=cv;exports.isPointWithinRegionShape=Vn;exports.isSafeUrl=Ib;exports.isStackedPosition=M;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=ix;exports.normalizeAngle=Ne;exports.orderPointerRegions=rv;exports.pipe=Rs;exports.placeCallouts=Hy;exports.polarToUnit=kt;exports.positionToAngle=Pi;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=zv;exports.prepareLineObservations=Zv;exports.projectAnchorToPanel=ro;exports.quantiseKey=H;exports.readAttachedObservation=Nn;exports.readAuthoredNumber=Pb;exports.readAuthoredString=Mb;exports.readChartType=Ox;exports.readHighlightDimStyle=Rl;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readXExtent=wo;exports.readYExtent=Eo;exports.resolveAnchorVariable=be;exports.resolveArrowColor=Ei;exports.resolveAxisLabelStyle=Hb;exports.resolveBarBorderRadiusPx=lo;exports.resolveBarBorderTreatment=Yv;exports.resolveBarCornerRadiiPx=Kv;exports.resolveColorRamp=on;exports.resolveComparisonBasis=qi;exports.resolveDataLabelStyle=Kb;exports.resolveDeferredAnchors=xy;exports.resolveDefinition=sn;exports.resolveGraphChromeStyle=$b;exports.resolveGridLineStyle=Bb;exports.resolveHeadlinePlacement=oy;exports.resolveObservationPoint=vv;exports.resolvePanelBorderStyle=Nb;exports.resolvePolarBarCornerRadiusUnit=eS;exports.resolveRuleLabelStyle=Yb;exports.resolveSegmentYSource=Bt;exports.resolveTextStyle=Zt;exports.resolveTickLabelStyle=zb;exports.resolveTickLineStyle=Fb;exports.resolveYScaleAesthetic=ne;exports.sampleColorScheme=_h;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Sv;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=Wb;exports.toPanelCursor=no;exports.toPercent=de;exports.toViewBoxX=yy;exports.toViewBoxY=te;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=ks;exports.uniqueId=O;exports.unitToPolar=Mi;exports.updateSpec=w;
|