@graphysdk/viz-engine 1.8.1-beta.1787309684040 → 1.8.1-beta.1787326761356
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 +4 -4
- package/dist/index.mjs +1765 -1782
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Yu=Object.create,Oi=Object.defineProperty,qu=Object.getOwnPropertyDescriptor,ju=Object.getOwnPropertyNames,Xu=Object.getPrototypeOf,Zu=Object.prototype.hasOwnProperty,Ju=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=ju(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Zu.call(e,o)&&o!==r&&Oi(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=qu(t,o))||n.enumerable});return e},zt=(e,t,r)=>(r=e!=null?Yu(Xu(e)):{},Ju(t||!e||!e.__esModule?Oi(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-C50AcoSx.cjs");let ye=require("color2k"),ki=require("date-fns"),je=require("lodash-es"),Qe=require("d3-time"),Qu=require("date-fns/differenceInDays"),pe=require("d3-regression"),Q=require("d3-scale"),Ne=require("d3-interpolate"),O=require("d3-scale-chromatic"),Ge=require("lodash-es/clamp");Ge=zt(Ge,1);let Mt=require("lodash-es/merge");Mt=zt(Mt,1);let Br=require("humanize-duration");Br=zt(Br,1);let Ie=require("d3-shape"),ed=require("d3-delaunay"),Nt=require("lodash-es/isEqual");Nt=zt(Nt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787309684040");var td=1e6;function Y(e){return String(Math.round(e*td))}var Ia="#FFFFFF",vr="#1A1A1A",rd=e=>{try{return(0,ye.getContrast)(e,Ia)>(0,ye.getContrast)(e,vr)?Ia:vr}catch{return vr}},nd=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ye.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ye.parseToRgba)(e);return r>=1?e:(0,ye.parseToRgba)(t)[3]<1?void 0:(0,ye.mix)(t,(0,ye.opacify)(e,1),r)}catch{return}},Ta=0;function M(){return Ta+=1,`${Math.random().toString(36).slice(2,6)}${Ta.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function w(e){return e[l.POSITION_VARIABLES.y]}function G(e){return e[l.POSITION_VARIABLES.xMin]}function U(e){return e[l.POSITION_VARIABLES.xMax]}function k(e){return e[l.POSITION_VARIABLES.yMin]}function _(e){return e[l.POSITION_VARIABLES.yMax]}function ln(e){return e[l.POSITION_VARIABLES.yRaw]}function ad(e,t){return e[l.resolveScaledAestheticVariable(t)]}var id={xMin:0,xMax:1,yMin:0,yMax:1},Fr=(e,t)=>{if(t.type==="polar")return null;const r=G(e)??R(e),n=U(e)??R(e),a=k(e)??w(e),i=_(e)??w(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},it=(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}}},Pi=e=>it(id,e),we=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},Yt=e=>e.identityKey!=="x-y"?null:l.extractVariableName(e.mapping.y),Mi=(e,t)=>e.yScaleType===t.yScaleType&&Gr(e.valueFormat)===Gr(t.valueFormat),$r=e=>`${e.yScaleType} y axis, ${Gr(e.valueFormat)}`,Gr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Rt=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Ni=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(we(e))),n=Yt(e);return a=>({...a,anchorValue:Rt(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:Rt(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:Rt(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Bi(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 E(e,t){return $i(e,t)}function L(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function Fi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Xe(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 $i(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=$i(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 qt(e){return{pipe:t=>{const r=t(e);return qt({...e,...r})},result:()=>e}}var sd=(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 Ue(e,t){return e==="x"?t.x:t.y}function jt(e,t){return e==="x"?t.y:t.x}function od(e,t){return{main:Ue(e,t),cross:jt(e,t)}}function La(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function ld(e){return e.type==="cartesian"}var K=e=>e[l.GROUP_VARIABLES.group],st=(e,t)=>{const r=we(e),n=t[r]??null;if(n===null)return null;const a=Yt(e);if(a!==null){const s=t[a]??null;return s===null?null:{layerId:e.id,anchorValue:n,crossValue:s}}const i=r===l.GROUP_VARIABLES.group?null:K(t);return{layerId:e.id,anchorValue:n,...i!==null&&{groupValue:i}}},We=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,cd={type:"decimal"};function Gi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function cn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):cd}function ud(e){return cn(e,l.extractVariableName(e.mapping.y))}var W=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},Ze=(e,t)=>W(e,t.x),un=(e,t)=>W(e,t.y),dd=(e,t)=>W(e,t.label),Ui=(e,t)=>W(e,t.color),md=(e,t)=>W(e,t.size),pd=(e,t)=>W(e,t.alpha),hd=(e,t)=>W(e,t.group),fd=(e,t)=>W(e,t.strokeWidth),Wi=["stack","dodge","identity","fill"],dn=["solid","dashed","dotted"],Hi=e=>dn.includes(e);function B(e){return e==="stack"||e==="fill"}var wa={variable:l.POSITION_VARIABLES.yRaw};function Xt(e,t){return B(e)?wa:t.y??wa}function Zt(e){return W(e.data,Xt(e.position,e.mapping))}function Ki({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??Xt(t,r)}function zi(e,t){const r=Ki({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:W(e.data,r),valueFormat:cn(e,a)}}var Yi=e=>{const t=l.extractVariableName(e.mapping.y),r=Zt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},gd=["lt","lte","gt","gte","range"],yd={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"}},re=()=>!1,De=()=>!0;function Jt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Yi(e),parsingLocale:t}}function be(e,t){if("and"in e){const r=e.and.map(n=>be(n,t)).filter(n=>n!==De);return r.includes(re)?re:r.length===0?De:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>be(n,t)).filter(n=>n!==re);return r.includes(De)?De:r.length===0?re:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=be(e.not,t);return r===re?De:r===De?re:n=>!r(n)}return bd(e,t)}function Se(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Se(n,t,r)):"or"in e?e.or.flatMap(n=>Se(n,t,r)):"not"in e?Se(e.not,t,r):vd(e,t,r)}function vd(e,t,r){const{subject:n,effect:a}=yd[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=Sd(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 bd(e,t){if(!t.hasVariable(e.variable))return re;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Rt(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=>_e(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>_e(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=_e(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=_e(u,s),m=_e(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return re}function Sd(e){for(const t of gd)if(t in e)return t;return null}function _e(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 xd=(e,t,r,n,a,i)=>{const s=ji(e,t,r.predicate,n,a,i);if(s===null)return null;const o=qi(r.padding),c=o===null?Td(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}},Ad=(e,t,r,n,a,i)=>{const s=ji(e,t,r.predicate,n,a,i);return s===null?null:it(s,r.align)},qi=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},ji=(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=Se(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=be(r,Jt(u,i));if(h!==re)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Id(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Id=(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)}),Td=(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}},Bt=(e,t,r)=>{const n=wd(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Ed(n,t.offset,e.coordSystem)},Xi=(e,t)=>t.anchorType==="selection"?xd(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},mn=(e,t,r)=>Ur(e,t,r)?.point??null,Ur=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const o=e.geomRegistry.get(s.geom),{resolveAnchorPosition:c}=o;if(c===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=zi(s,o),d=we(s),m=Yt(s),{anchorValue:h,groupValue:p,crossValue:f}=Ni(s,n)(a);let g=-1;for(const y of s.data){if(g+=1,!l.areDataValuesEqual(y[d]??null,h))continue;const v=m!==null?f:p;if(v!==void 0&&!l.areDataValuesEqual(m!==null?y[m]??null:K(y),v))continue;const x=c(y,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(x===null)continue;const I=Zi(s,y,u);if(I===null)continue;const A=st(s,y);if(A!==null)return{point:{...x,...I,observationIndex:g,anchor:a.align===void 0?A:{...A,align:a.align}},layerId:s.id}}}return null},Ld=(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=Va(t.x,"x",r,i),u=Va(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!We(d,m))return null;const h=Ea(d,s,Vd(e)),p=Ea(m,o),f=La(n.mainAxis,{main:h.min,cross:p.min}),g=La(n.mainAxis,{main:h.max,cross:p.max});return it({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},Zi=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:sd(r.valueFormat,t),yScaleType:e.yScaleType}:null},wd=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Ld(e,t);case"selection":return Ad(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 mn(e,Rd(t),r)}},Ed=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=qi(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Ea=(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}},Vd=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},Rd=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Va=(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},Cd=class extends l.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:Gd(s,t.differenceArrows),shapes:kd(s,t.shapes),arrows:Md(s,t.arrows),textAnnotations:Nd(s,t.textAnnotations),images:Pd(s,t.images),stickers:Bd(s,t.stickers),pinnedNumbers:Fd(s,t.pinnedNumbers),comments:$d(s,t.comments)};return Dd(this.container,o),_d(this.container,o),o}},ee=(e,t,r,n)=>{e.diagnostics.addWarning({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},Dd=(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)}},_d=(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 Od(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."})},Od=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},kd=(e,t)=>{const r=[];for(const n of t){const a=Xi(e,n.region);if(a===null){ee(e.container,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},Pd=(e,t)=>{const r=[];for(const n of t){const a=Xi(e,n.region);if(a===null){ee(e.container,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit,opacity:n.opacity})}return r},Md=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.start,"pin"),i=Bt(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${Ji(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},Nd=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.at,"pin");if(a===null){ee(e.container,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},Bd=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.at,"pin");if(a===null){ee(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Fd=(e,t)=>{const r=[];for(const n of t){const a=mn(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},$d=(e,t)=>{const r=[];for(const n of t){const a=mn(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Gd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Ur(e,n.start,"value"),i=Ur(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${Ji(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Ud(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ji=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Ud=(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:$r(r),actual:$r(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Wd(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:Qi(i),values:i};return new l.Dataset(n)}function Qi(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 Hd=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,Qi(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Kd=(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},Ee=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)}},zd=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)}},Yd=class extends Ee{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}},qd=class{constructor(e){this.setupStage=new zd(e),this.transformStage=new Yd(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)}},jd=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}},Xd=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:Jd(e.scales,e.layers)}}transform(e){return e.layers.map(t=>em(t))}},Zd=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ra=l.prefixInternalVariable("flipSwap"),Jd=(e,t)=>Qd(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Qd=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},em=e=>{let t=e.data;for(const[r,n]of Zd){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ra).renameVariable(n,r).renameVariable(Ra,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},xe=Math.PI*2,tm=8,rm=1e-9,es=(e,t)=>Math.abs(t-e)>=xe-rm,He=e=>(e%xe+xe)%xe,ts=(e,t,r)=>{if(es(t,r))return!0;const n=He(r-t);return He(e-t)<=n},Ft=(e,t)=>{const r=Math.abs(He(e)-He(t));return Math.min(r,xe-r)},rs=(e,t,r)=>e*xe+t+r,$t=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),ns=(e,t)=>({angle:He(Math.atan2(e,t)),radius:Math.hypot(e,t)}),pn=(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}},Qt=(e,t)=>{const{x:r,y:n}=pn(e,t);return ns(r,n)};function as(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 is=(e,t)=>as(t.domain!==null&&t.domain.length>0?t.domain:e),nm=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=sm(t,e.scales,e.layers),a=lm(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=im(r,n),i=cm(t);return e.layers.map(s=>um(t.theta==="y"?dm(s):s,a,i))}},am=[[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 im(e,t){return r=>rs(r,e,t)}function sm(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=om(n,e,r);return a===0?0:-Math.PI/a}function om(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 is(n,e).length}function lm(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 cm(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function um(e,t,r){let n=e.data;return n=Oe(n,l.POSITION_VARIABLES.x,t),n=Oe(n,l.POSITION_VARIABLES.xMin,t),n=Oe(n,l.POSITION_VARIABLES.xMax,t),n=Oe(n,l.POSITION_VARIABLES.y,r),n=Oe(n,l.POSITION_VARIABLES.yMin,r),n=Oe(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Oe(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 dm(e){let t=e.data;for(const[r,n]of am){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 mm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new jd),this.register("flip",new Xd),this.register("polar",new nm)}},ss=new Set(["min","max","scalar"]),pm={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function hm(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 fm(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 gm(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=pm[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 ym=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:gm(n.data,r.positionRoles,a)}}},hn=["x","y"],fn=new Set(["x","y","ySecondary"]),ot=new Set(["color","size","alpha","strokeWidth","lineType"]),Ve=e=>fn.has(e),gn=e=>ot.has(e),os=e=>Ve(e)||gn(e);function oe(e){return e==="secondary"?"ySecondary":"y"}function ls(e,t){return e==="y"?oe(t):"x"}function P(e){return e==="ySecondary"?"y":e}var Je=(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 ot){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},er=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Je(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),vm=class{compute({data:e,mapping:t}){const r=Je(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)}}},bm=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},Sm=(e,t,r)=>{const n=Te(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Te(e,t){const r=P(t);for(const n of cs(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var tr=(e,t)=>e===null?null:t[e]??e,xm=(e,t)=>e===null?null:t[String(e)]??null,Le=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return br(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 Im(i,t)?i:br(t)}return br(t)},Am=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:cs(t,e).some(r=>r.position==="fill");function cs(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var br=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Im=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Tm=[{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},ke=40,Lm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Rm(r.unit).range(e,new Date(t.valueOf()+1),n)},wm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Qu.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>ke;case"day":return a/t>ke;case"week":return a/(7*t)>ke;case"month":return a/(30*t)>ke;case"quarter":return a/(90*t)>ke;case"year":return a/(365*t)>ke}},Em=(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"}}},Vm=(e,t)=>{const r=Cm(t);return r===null?!1:Ca[e]>Ca[r]},Rm=e=>{switch(e){case"hour":return Qe.utcHour;case"day":return Qe.utcDay;case"week":return Qe.utcMonday;case"month":case"quarter":return Qe.utcMonth;case"year":return Qe.utcYear}},Cm=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}},us={left:"right",right:"left",top:"bottom",bottom:"top"},Dm={x:!0,y:!0,ySecondary:!1},_m=20,Da=new Set(["top","bottom"]),Om={type:"percentage"};function km(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(Gi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Nm(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=Fm(ds(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of fn){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=Pm({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function Pm(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}=Bm(t,n,i,s),h=Te(a,t),p=Am(a,t)?Om:Le({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:Mm(u,h,c),isVisible:u.isVisible,tickCandidates:Gm(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:$m(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Mm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Nm(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:_a(i,n.axes.x.grid.isVisible)},y:{gridVisible:_a(s,n.axes.y.grid.isVisible)}}}function _a(e,t){if(e&&t===null)return!1}function Bm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:ds(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=us[n],i=(0,je.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 ds(e,t){return Da.has(e)===Da.has(t)?e:t}function Fm(e,t){return t.has(e)?us[e]:e}function $m(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Dm[r]}var Gm=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Wm(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=_m;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Ke(e,u))}))}return i}return e.spec.scaleType==="datetime"?Um(e,t):[{ticks:e.generateTicks().map(a=>Ke(e,a))}]},Um=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Ke(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=>Ke(e,d)),valueFormat:c}))};for(const o of Tm)wm({...o,start:r,stop:n})||Vm(o.unit,t)||s(e.generateTicks({interval:o}),Em(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},Wm=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:[Ke(e,r),Ke(e,n)]}},Ke=(e,t)=>({value:t,position:e.map(t)});function ms({scale:e,aesthetics:t,layers:r}){const n=Hm({layers:r,aesthetics:t}),a=ps({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Hm({layers:e,aesthetics:t}){const r=ps({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 ps({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 yn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Km({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!yn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=Te(t,"color");if(hs({colorVariableName:a,xVariableName:Te(t,"x"),mapsColorAcrossMultipleLayers:Ym(t)>1,isMergedWithAnotherAesthetic:zm(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return ms({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Le({layers:m?[m]:t,scaleType:i,variableName:h}),label:xm(o,r)}})}var hs=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function zm(e,t,r){if(r===null)return!1;for(const n of ot){if(n==="color")continue;const a=e[n];if(!(a===void 0||!yn(a))&&Te(t,n)===r)return!0}return!1}var Ym=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function fs(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function qm(e,t,r,n){const a=r.findIndex(i=>fs(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:tr(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 Oa(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 gs=e=>e==="none"?"first":e,jm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=ka(e);return n===0?null:r}case"average":{const{sum:r,count:n}=ka(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},Xm=(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}},ka=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Zm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Jm(e,n):Qm(e,n)}function Jm(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:Le({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Qm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>fs(o,d)))return null;const c=qm(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>ep({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 ep({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=Le({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=np(i.data,o),h=Le({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=ap(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=Oa(f,y,e.value),x=Oa(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:jm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:tp(t,m,x),comparison:rp(t,r,m,x,v)}}function tp(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 rp(e,t,r,n,a){return e!=="current"||!r?null:Xm(n.map((i,s)=>({main:i,cross:a[s]??null})),gs(t))}function np(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function ap(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function q(e,...t){return e?t.includes(e.geom):!1}function D(e,t){return e.find(r=>r.id===t)}function le(e,...t){return e.find(r=>t.includes(r.geom))}function ip(e,...t){return e.filter(r=>t.includes(r.geom))}function vn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function bn(e){const t=e.filter(r=>!vn(r,e));return t.length>0?t:e}function ys({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=bn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var sp=3;function op({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=fp(dp({scales:e,layers:r})),u=Te(r,"x"),d=c.map(y=>{if(pp(y,u,r))return null;const v=yp({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=lp(d),h=bn(r),p=Ip(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&Ap(s,m,h,n))return{drawn:[],position:p};const f=Tp(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?Vp(h[0]):null;return{drawn:d.map(({built:y})=>cp(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function lp(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function cp(e,t,r){const{position:n,display:a}=t,i=up(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 up(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function dp(e){const{scales:t,layers:r}=e,n=[];for(const a of ot){const i=t[a];if(i===void 0||i.kind==="identity"||!mp(a,r))continue;const s=Te(r,a),o=Ep(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function mp(e,t){const r=P(e);return t.some(n=>l.isDefined(n.mapping[r]))}function pp(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:hs({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:hp(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function hp(e,t){const r=P(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function fp(e){const t=new Map;for(const r of e){const n=wp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function gp(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function yp({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>P(c.scaleAestheticKey)),s=ms({scale:a.scale,aesthetics:i,layers:r}),o=Le({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:tr(a.variableName,t),items:s.map(c=>vp(c,e,i,o,n))}}function vp(e,t,r,n,a){const i={};for(const o of t)gp(i,o.scaleAestheticKey,o.scale.map(e.value));const s=Sp(e,t,r,n,a);return{value:e.value,label:bp(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function bp(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function Sp(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=xp(i,r);return i===void 0||s===null?n:Le({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function xp(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 Ap(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 Ip(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,B(u.position)&&(o=!0))}const c=r>=sp;return i&&s?"top":i?c?"right":"top":o?Lp(a)?"top":c?"right":"top":"top"}function Tp(e,t){return e==="pill"?"pill":ys(t)?"direct":"pill"}function Lp(e){return e.type==="cartesian"&&e.mainAxis==="y"}function wp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function Ep(e,t){return yn(t)?"discrete":`continuous:${e}`}function Vp(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(_(c))||l.isDefined(w(c)));if(!n)return;const a=K(n);if(!l.isDefined(a))return;const i=k(n),s=_(n)??w(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var Rp=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=bm(e.originalData),r=Km({scales:e.scales,layers:e.layers,valueLabels:Sm(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=Zm(n),i=op(n),s={...i,drawn:Cp(a,i.drawn)};return{axes:km(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},Cp=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Dp=e=>l.getStableKey([K(e)]),Sn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),_p=e=>e!=="data-point",Gt=(e,t,r)=>{switch(e){case"series":return Dp(t);case"x-value":return Sn(t,r)}},Op={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function vs(e){const t=Op[e]??null;return t===null?null:{strategy:t,composition:bs()}}function bs(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var kp=class extends Ee{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=Pp({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function Pp({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const X=Se(T.predicate,e.data);for(const Z of X)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return X.length===0}),s=l.extractVariableName(e.mapping.x),o=Jt(e,r),c=i.map(T=>({predicate:be(T.predicate,o),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let I=!1,A=0;for(const T of e.data){let X,Z;p!==null&&(X=Gt("series",T,s),p[A]=X),f!==null&&(Z=Gt("x-value",T,s),f[A]=Z),g!==null&&(g[A]=T);for(const{predicate:St,scope:xt}of c)if(St(T))switch(xt){case"series":X!==void 0&&v.add(X);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return bs();const V=new Uint8Array(h),j=[];let ie=0;for(let T=0;T<h;T++){const X=p?.[T],Z=f?.[T],St=X!==void 0&&v.has(X),xt=Z!==void 0&&x.has(Z),xa=y[T]===1;if(n==="observation-rerender")(St||xa||xt)&&(V[T]=1,ie++);else if(St)V[T]=1,ie++;else if(xa||xt){const Aa=g?.[T];Aa!==void 0&&j.push({observation:Aa,observationIndex:T})}}const z=ie>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&z!==null,matchedLayer:z,overlayCandidates:j}}var Mp=l.prefixInternalVariable("__ungrouped__");function Np(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]??Mp;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 Bp=()=>({defaults:[],overrides:[],warnings:[]}),Fp=class extends Ee{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),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},xScaleIsDiscrete:Pa(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=qt({data:t,mapping:r}).pipe(({data:o,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:o,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>({data:this.groupCompiler.compute({data:o,mapping:c}).data,mapping:c})).pipe(({data:o,mapping:c})=>({data:Np(o),mapping:c})).pipe(({data:o,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:o,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:o,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:vs(e.geom),styles:Bp()}}};function Pa(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Ss(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Wr(e,t){const r=xs(e,t),n={};for(const{layer:i,scaleConstraints:s,crossAxis:o}of r)s.zeroBaseline===!0&&(n[o]={nice:(n[o]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:Gp(r),zeroAxes:n,bandPadding:Up(r)}}function $p(e,t){const r=xs(e,t);for(const n of r){if(n.scaleConstraints.discreteCrossAxis!==!0)continue;const a=r.find(i=>i.scaleConstraints.zeroBaseline===!0&&i.crossAxis===n.crossAxis);if(a!==void 0)return{crossAxis:n.crossAxis,banded:Ma(n),zeroAnchored:Ma(a)}}return null}var Ma=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function xs(e,t){const r=[];return t.forEach((n,a)=>{if(!e.has(n.geom))return;const{scaleConstraints:i}=e.get(n.geom);i!==void 0&&r.push({layer:n,index:a,scaleConstraints:i,crossAxis:oe(n.yScaleType)})}),r}function Gp(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of As(r))t.add(n);return[...t]}function Up(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of As(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function As({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var Wp=new Set(["label","group"]),Hp=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},s={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),Ss(this.container.diagnostics,t)}checkPostCompile(e){Gi(e)&&this.container.diagnostics.addWarning({code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."})}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!er(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=[...hm(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!ss.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=$p(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...fm(i),...s.map(h=>h.name)]),u=Wp,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},ae=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=Wi,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,je.merge)({},this.defaultParams,e.params)}},xn=(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=w(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},Kp=class extends ae{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=xn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},zp=.7,Yp=.1,qp=.03,jp=.05,Is=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},Xp=class extends ae{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveAnchorBox=Fr,this.resolveDataLabelDefaults=t=>B(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>Hr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Zp(t);if(i!==void 0){const m=Fr(t,r);return m===null?null:it(m,i)}const s=B(n),o={isSolo:!s||Is(t)==="solo",isNegative:s&&Jp(t),purpose:a};if(r.mainAxis==="x"){const m=G(t),h=U(t),p=Na({lowerBound:k(t),upperBound:_(t)??w(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=k(t),u=_(t),d=Na({lowerBound:G(t),upperBound:U(t)??R(t),options:o});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=Hr(r,n);e=xn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const i=a/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",i),{data:e,mapping:{}}}resolveWidthParam(e,t){if(e===void 0)return;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:void 0;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,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}},Hr=({width:e},t)=>e!==void 0?e:t==="polar"?1:zp,Zp=e=>{const t=G(e),r=U(e),n=k(e),a=_(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)}},Jp=e=>{const t=ln(e);return l.isStrictNumericDataValue(t)&&t<0},Na=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},Qp=class extends ae{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=Fr,this.resolveAnchorPosition=An}compile(e){return{data:xn(e.data,e.mapping),mapping:{}}}},eh=class extends ae{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.resolveValueSource=(t,r)=>{if(r!=="label")return null;const n=l.extractVariableName(t.size);return n!==null?{variable:n}:null}}compile({data:e}){return{data:e,mapping:{}}}},th=class extends ae{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=Ba(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=Ba(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}}}},Ba=(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},rh=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},nh=class extends ae{constructor(...e){super(...e),this.type="tile",this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian"],this.aesthetics=[{kind:"visual",name:"color",required:!0}],this.scaleConstraints={discreteMainAxis:!0,discreteCrossAxis:!0,bandPadding:0},this.grid={cartesian:{hideGridX:!0,hideGridY:!0}},this.legend={suppressWhenSingleItem:!1},this.dataLabels={cartesian:{showDataLabels:!0}},this.dataLabelCoordTypes=["cartesian"],this.highlightStrategy="observation-rerender",this.spatialKind="cells",this.identityKey="x-y",this.tooltip=[{aes:"color"}],this.resolveValueSource=rh,this.resolveAnchorPosition=t=>{const r=G(t),n=U(t),a=k(t),i=_(t);return r===null||n===null||a===null||i===null?null:{x:(r+n)/2,y:(a+i)/2}}}compile({data:e}){return{data:e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",.5).addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.yMax,"numeric",.5),mapping:{}}}},ah=[new Xp,new eh,new Qp,new Kp,new th,new nh],rr=class extends l.Registry{constructor(){super("geom");for(const e of ah)this.register(e.type,e)}},Re=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},ih=class extends Re{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,...Je(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},sh=class extends Re{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},oh=class extends Re{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}}}},lh=2,Ts=1440*60*1e3,ch=class extends Re{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=Je(e,t),u=gh(a,s,i,c,e);return c.length===0?Fa({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=yh(d,c);Fa({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Fa=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=uh({data:e,xVariable:t,yVariable:n,xType:r});c.length<lh||(o?fh({observations:c,spec:a,output:i,groupObservation:s}):ph({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},uh=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?dh(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=mh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},dh=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},mh=({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)/Ts+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}`})}},ph=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Ls(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?hh(o,r):o;a.push({x:u,y:c,groupObservation:i})}},hh=(e,t)=>t===null?new Date(e):new Date((e-1)*Ts+t),fh=({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=Ls(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=ws(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})}},Ls=(e,t)=>e.method==="loess"?(0,pe.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ws(e,t),ws=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,pe.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,pe.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,pe.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,pe.regressionQuad)().x(r).y(n)(t);case"power":return(0,pe.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,pe.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},gh=(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)}}},yh=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},vh=class extends Re{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],...Je(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},bh=[new sh,new ih,new ch,new oh,new vh],Sh=class extends l.Registry{constructor(){super("stat");for(const e of bh)this.register(e.type,e)}};function xh({geoms:e,stats:t,transforms:r}){const n=new rr,a=new Sh,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 In(e){if("definition"in e)return e.definition;if(Vs(e)||Rs(e)||Cs(e))return e}function Es(e){const t=[],r=[],n=[];for(const a of e){const i=In(a);i&&(Vs(i)?t.push(i):Rs(i)?r.push(i):Cs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...Sr("geom",t,a=>a.type),...Sr("stat",r,a=>a.type),...Sr("transform",n,a=>a.transformType),...Ah(t),...Ih(t)]}}function Ah(e){const t=[];for(const r of e)r.spatialKind==="render-hit-test"&&(r.identityKey!=="x-group"&&r.identityKey!=="x-y"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the position-derived '${r.identityKey}' 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 Ih(e){const t=[];for(const r of e)r.spatialKind!=="cells"||!r.supportedCoordTypes.includes("polar")||t.push({code:"SPATIAL_KIND_COORD_UNSUPPORTED",message:`The geom '${r.type}' declares polar support, but its 'cells' hit-test shape has no polar projection; its observations will not respond to hover under polar coords.`,context:{kind:"geom",requested:r.type},suggestion:"Drop 'polar' from 'supportedCoordTypes', or declare 'rects' as the spatial kind so a bandless polar layer hit-tests as an enclosure."});return t}function Sr(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 Vs=e=>e instanceof ae,Rs=e=>e instanceof Re,Cs=e=>"transformType"in e&&typeof e.apply=="function",Th=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},nr=class{},Lh=class extends nr{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=wh(e)??[-.7/2,.7/2],s=r.length>1?Yp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},wh=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]},$a=l.prefixInternalVariable("__ungrouped__"),Ds=(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?[$a]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?$a:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},_s=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=Eh(p===o,p===d)}return a},Eh=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Vh=class extends nr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=Ds(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const I=x>=0?m:h;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=_s(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:{}}}},Rh=class extends nr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Ch=class extends nr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=Ds(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=_s(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:{}}}},Dh=class extends l.Registry{constructor(){super("position"),this.register("identity",new Rh),this.register("stack",new Ch),this.register("fill",new Vh),this.register("dodge",new Lh)}},_h=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)||gn(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ls(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}},Oh=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)}},kh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},Ph=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(oe(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)}},Mh=class{map({data:e,layer:t,getPositionScale:r}){const n=r(oe(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=l.isDefined(a)&&e.hasVariable(l.POSITION_VARIABLES.y)?Nh(e,n,a):Bh(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Nh(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,o=e.size(),c=Os(o);for(let u=0;u<o;u++){const d=n[u],m=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(h)||(c.min[u]=d+(s?-h:m)*r,c.max[u]=d+(s?-m:h)*r)}return c}function Bh(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=Os(a);for(let s=0;s<a;s++){const o=r[s],c=n[s];!l.isDefined(o)||!l.isDefined(c)||(i.min[s]=t.map(o),i.max[s]=t.map(c))}return i}function Os(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Fh=[new Oh,new Ph,new kh,new Mh,new _h];function $h(e,t){const r=e[t];return r?.kind==="position"?r:null}var Gh=class extends Ee{constructor(e,t=Fh){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=>$h(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}}},Uh=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=P(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})}}Ss(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"?oe(n.yScaleType):i,c=a.get(i)??(os(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,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)||gn(n.aes)||t.set(n.aes,ls(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}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)}},Wh=["rgb","lab","hcl","hsl"],Hh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],ks=["RdBu","BrBG","PuOr","Spectral"],Ps={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Kh=new Set(ks.map(e=>e.toLowerCase()));function Ms(e){const t=e.toLowerCase(),r=Ps[t];return r?r.toLowerCase():t}function zh(e){return Kh.has(Ms(e))}var Yh={rgb:Ne.interpolateRgb,lab:Ne.interpolateLab,hcl:Ne.interpolateHcl,hsl:Ne.interpolateHsl},qh={viridis:O.interpolateViridis,magma:O.interpolateMagma,inferno:O.interpolateInferno,plasma:O.interpolatePlasma,cividis:O.interpolateCividis,turbo:O.interpolateTurbo,blues:O.interpolateBlues,greens:O.interpolateGreens,greys:O.interpolateGreys,oranges:O.interpolateOranges,purples:O.interpolatePurples,reds:O.interpolateReds,rdbu:O.interpolateRdBu,brbg:O.interpolateBrBG,puor:O.interpolatePuOr,spectral:O.interpolateSpectral};function Tn(e){const t=Xh(e);return e.reverse?r=>t(1-r):t}function jh(e={},t=2){const r=Tn({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 Xh(e){const t=Yh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ne.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=qh[Ms(e.scheme)];if(r)return r}return(0,Ne.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var lt=class{createPositionScale(e,t){return{kind:"position",aesthetic:P(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:P(e.scaledAesthetic),spec:e,...t}}},Zh=class extends lt{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=Ve(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"&&Jh(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:P(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=Qh(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=Tn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,Q.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,Q.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Jh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Qh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var ef=class extends lt{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=Ve(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=tf(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?Lm(i,s,c.interval):[]:a.ticks(c?.count)})}},tf=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),rf=class extends lt{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=Ve(e.scaledAesthetic),n=is(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,Q.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},nf=class extends lt{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:P(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},af=class extends lt{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=as(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},sf=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Zh(e)),this.register("discrete",new rf),this.register("datetime",new ef),this.register("identity",new nf),this.register("palette",new af)}},Ct={color:null,size:"small",labelCrossPosition:.5},he={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},xr={zOrder:"foreground",fit:"contain",opacity:1},of={x:8,y:8,unit:"px"},Dt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},fe={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},lf={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}},cf=(e,t,r)=>{const n=uf(e,t),a=pf(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>ff(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>bf(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>Af(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>hf(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>gf(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>Sf(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>yf(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>vf(e,i,r)).filter(l.isDefined)}},uf=(e,t)=>{if(t===void 0)return{};if(!df(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:M()}):(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))}},df=e=>{const t=new Set;for(const r of mf(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},mf=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],pf=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},hf=(e,t,r,n)=>{const a=Ut(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),content:t.content,at:a,width:t.width,align:t.align??Dt.align,backgroundColor:t.backgroundColor??Dt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??Dt.backgroundColorStyle}},ff=(e,t,r)=>{const n=nt(e,t.start,r),a=nt(e,t.end,r);return n===null||a===null?null:{id:t.id??M(),start:n,end:a,label:t.label,color:t.color??Ct.color,size:t.size??Ct.size,labelCrossPosition:t.labelCrossPosition??Ct.labelCrossPosition}},nt=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},Ut=(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=nt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},gf=(e,t,r,n)=>{const a=Ut(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),at:a,sticker:t.sticker}},yf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n}},vf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n,content:t.content}},bf=(e,t,r)=>t.region.anchorType==="annotation"&&!Ln(e,t.region.ref,r,t.id)?null:{id:t.id??M(),kind:t.kind??he.kind,zOrder:t.zOrder??he.zOrder,region:xf(t.region),fillColor:t.fillColor===void 0?he.fillColor:t.fillColor,fillOpacity:t.fillOpacity??he.fillOpacity,strokeWidth:t.strokeWidth??he.strokeWidth,strokeColor:t.strokeColor??he.strokeColor},Sf=(e,t,r)=>t.region.anchorType==="annotation"&&!Ln(e,t.region.ref,r,t.id)?null:{id:t.id??M(),src:t.src,zOrder:t.zOrder??xr.zOrder,region:t.region,fit:t.fit??xr.fit,opacity:t.opacity??xr.opacity},xf=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:of},Ga=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=lf[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},Af=(e,t,r,n)=>{const a=Ut(e,t.start,r,n,t.id),i=Ut(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??M(),start:Ga(a),end:Ga(i),color:t.color??fe.color,thickness:t.thickness??fe.thickness,startArrowheadStyle:t.startArrowheadStyle??fe.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??fe.endArrowheadStyle,lineStyle:t.lineStyle??fe.lineStyle,hasStickerStyle:t.hasStickerStyle??fe.hasStickerStyle}},If={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function Tf(e){const t=(0,je.merge)({},If,e);return t.content=Lf(t.content,e?.content),t}var Lf=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},wf={xLimits:null,yLimits:null},_t={theta:"x",startAngle:0,innerRadius:0};function Kr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Mt.default)({},wf,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??_t.theta,startAngle:t.params?.startAngle??_t.startAngle,innerRadius:(0,Ge.default)(t.params?.innerRadius??_t.innerRadius,0,1)}}}}function Ef(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??M(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Vf=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=Ua(e.filter(n=>n.severity==="error")),r=Ua(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Rf=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 Ua(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Cf={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 Ns(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 Ce(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Rf(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=Of({dataLabels:Pf(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return _f({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??M(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Ns(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 Df(e,t,r,n,a){const i=n.map((s,o)=>Ce(e,t,r,s,a,o));return Fs(e,i)}var Bs=(e,t,r,n)=>n.label!==void 0?n.label:Ki({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Fs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Xe(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,je.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},_f=({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&&B(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."})},Of=({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=kf(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}},kf=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&B(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,Pf=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Bs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,je.merge)({},Cf,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},$s={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Mf={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Gs(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Wr(e.geomRegistry,n)}}function wn(e,t){switch(t.scaleType){case"inferred":return wn(e,$f(e,t));case"continuous":{const r=$s[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,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??r!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:Gf(e.container,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 zr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:l.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Nf(e,t){const{scales:r,layers:n,coords:a}=t,i=Hf(Wf(r,n)),s=new Map;for(const u of i)s.set(u.scaledAesthetic,u);const o=Gs(e,t),c=[...s.values()].map(u=>{const d=Bf(o,u);return wn(o,d)});return a.coordType==="polar"?c.map(Us):c}function zr(e,t){const r=t?.bandPadding[e.scaledAesthetic];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??r??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??Ff(e.scaledAesthetic,t)}}var Us=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Bf(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:P(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Ff(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function $f({data:e,layers:t,mapping:r,demands:n},a){const i=P(a.scaledAesthetic),s=a.scaledAesthetic==="ySecondary"?Uf(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const o=n.zeroAxes[a.scaledAesthetic];if(o!==void 0){const m=a.options;return l.continuous(a.scaledAesthetic,{...m,zero:!0,...!o.nice&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!e.hasVariable(c))return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=$s[a.scaledAesthetic];switch(Mf[u][d]){case"discrete":return l.discrete(a.scaledAesthetic,a.options);case"palette":return l.palette(a.scaledAesthetic);case"datetime":return l.datetime(a.scaledAesthetic,a.options);case"continuous":return l.continuous(a.scaledAesthetic,a.options);default:return l.identity(a.scaledAesthetic)}}function Gf(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:P(t.scaledAesthetic),scaleType:t.scaleType},suggestion:"Set either a scheme or a range, not both."}),null):(!l.isDefined(t.domainMid)&&zh(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:P(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Uf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function Wf(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Hf(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var Kf=e=>{const t=new Set;e!==void 0&&Ws(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},Ws=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Ws(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function zf(e,t,r){const n=Kr(t.coords),a=Df(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Nf(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=Tf(t.config),o=Ef(e,t.highlights,a),c=cf(e,t.annotations,a),u=Kf(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 Hs=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return zf(this.container,{...e,data:t},r)}},Yf=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})}},qf=class extends Ee{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of lg(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of cg(e.styles))this.container.diagnostics.addWarning(r);for(const r of ug(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=Js({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Be={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ks={bar:{...Be,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Be,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Be,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Be,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Wa=1,Ha=1e3,jf="'none' or a shadow object { offsetX, offsetY, blur, color }",At={color:"color",strokeWidth:"pixels",lineType:"lineType"},It={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},ge={panelBorder:{...At,borderRadius:"pixels"},panelBorderEdge:At,gridLine:At,tickLine:{...At,length:"pixels"},axisLabel:It,tickLabel:{...It,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...It,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily"},tooltip:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},tooltipText:It,tooltipPrimaryRow:{background:"color"}},Xf=new Set([...Object.keys(Be),...Object.values(Ks).flatMap(e=>Object.keys(e??{})),...Object.values(ge).flatMap(e=>Object.keys(e))]),zs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","tooltip"],Zf=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Jf=(e,t,r="en-US")=>Js({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Qf=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 Ys(e.styles)}},Ys=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:[]},tooltip:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(ar(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!eg(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 ${zs.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!rg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Zf.has(m.target)){const p=m.axis;if(p!==void 0&&!sg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${hn.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${ze(p)}.`,context:{param:"layer",actual:ze(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="tooltip"){const p=m.part;if(p!==void 0&&!ig(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown part '${String(p)}'.`,context:{param:"part",actual:String(p),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!ng(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!ag(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=En({declarations:i.declarations,vocabulary:tg(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},ar=e=>e.select.target==="geom",eg=e=>{const t=e.select.target;return t!=="geom"&&zs.includes(t)},qs=e=>(e!==void 0?Ks[e]:void 0)??Be,tg=e=>e.target==="panelBorder"?e.edge===void 0?ge.panelBorder:ge.panelBorderEdge:e.target==="tooltip"?e.part===void 0?ge.tooltip:e.part==="primaryRow"?ge.tooltipPrimaryRow:ge.tooltipText:ge[e.target],rg=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),ng=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),ag=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),ig=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),sg=e=>typeof e=="string"&&hn.includes(e),og=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!ar(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=En({declarations:a.declarations,vocabulary:qs(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},js=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},lg=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return js(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},cg=e=>{const t=[];return js(e,(r,n,a)=>{if(!ar(r))return;const i=r.when?.state;i===void 0||Xs(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},Xs=e=>l.STYLE_STATES.includes(e),ug=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Zs(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${ze(n)}.`,context:{param:"tokens",actual:ze(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Zs=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,me=e=>typeof e=="number"&&Number.isFinite(e),ze=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Js=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Jt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!ar(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!Xs(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const I=Se(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=En({declarations:h.declarations,vocabulary:qs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:be(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...og(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},En=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${ze(g)}.`,context:{param:p,expected:f,actual:ze(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Zs(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=Xf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":me(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":me(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Hi(f)?u(p,f):d(p,`one of ${dn.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":me(f)&&f>=Wa&&f<=Ha?u(p,f):d(p,`a number in [${Wa}, ${Ha}]`,f);break;case"multiplier":me(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;case"shadow":{if(f==="none"){u(p,f);break}const y=f;if(!me(y.offsetX)||!me(y.offsetY)||!me(y.blur)||y.blur<0){d(p,jf,f);break}const v=m(p,y.color);v!==void 0&&u(p,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:v});break}default:break}}return o},dg=({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}},mg=({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=k(a),o=_(a),c=G(a),u=U(a),d=ln(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=Sn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},pg=class extends Ee{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=mg({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=dg({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Qs=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)}},Ka={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},hg=["color","size","alpha","strokeWidth","lineType"],fg=class extends Ee{dependencies(e){return hg.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Ka[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,Ka[a],gg(c)))}return{...e,data:r}}},gg=e=>t=>l.isDefined(t)?e.map(t):null;function eo(e=new rr){return{diagnostics:new Vf,geomRegistry:e}}var to=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>{if(e.data===void 0)return this.runPipeline({spec:e.spec});this.lastData=e.data;const r=Kd(e.spec.data,e.spec.mapping);return this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data),mapping:r})})});return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}getCacheStats(){const e={};for(const{name:t,getStats:r}of this.stages)e[t]={...r()};return e}getLastCompile(){return this.lastCompile}getDiagnostics(){return this.lastDiagnostics}runCompile(e){this.container.diagnostics.reset();const t=this.trackCompile(e);return this.lastDiagnostics=this.container.diagnostics.drain(),t}toOkResult(e){return{ok:!0,compiled:e,warnings:this.lastDiagnostics?.warnings??[]}}toErrorResult(e){const t=this.container.diagnostics.drain();return this.lastDiagnostics=t,{ok:!1,errors:t.errors.length>0?t.errors:[Bi(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 qt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result()}},yg=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],vg=({plugins:e=[]}={})=>{const t=Es(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=xh(t),i=eo(r),s=new sf(i),o=new Qs(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new to(i,new l.DataCompiler,new Hs(i),o,new Hd,new Hp(i,o,n,new Fp(i,o,new Yf(n),new vm,new ym(i),new Th(new Dh))),new Uh(i,s),new qd(new mm),new Gh(i),new fg,new Rp(i),new pg(i),new qf(i),new Qf(i),new kp(i),new Cd(i))};function bg(e,t){return e.geom===t}function ro(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!Sg(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>ao(s,o),i)}function no(e,...t){return t.reduce((r,n)=>ao(r,n),e)}function Sg(e){return typeof e=="object"&&e!==null&&"type"in e}function ao(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,Mt.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 xg(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function xg(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 Ag(e){const t=e?.plugins??[],r=Tg(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:ro,pipe:no,plugins:t}}var Ig=e=>(t={})=>l.buildLayerInput(e,t);function Tg(e){const{geoms:t,stats:r,transforms:n}=Es(e),a={};for(const o of t)a[o.type]=Ig(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 Lg=24,wg={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}},Eg={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},Ar="…",io=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Ar)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+Ar)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+Ar};var F={timeZone:"UTC"},N=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},ce=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Vn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Vg=Br.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),so=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>ce(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=Dn(a,i),{base:o,suffix:c}=Cn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),oo=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const{base:a,suffix:i}=Cn(n,t.abbreviation),s={...Dn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),Rn=e=>ce(t=>Vg(t)),lo=({locale:e,intlOptions:t})=>ce(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),co=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const a=Dn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Cn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Rg(e);return Cn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Dn=(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}},Rg=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"},Cg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).format(r)),Dg=({locale:e,intlOptions:t})=>N(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...F,...t}).formatToParts(r);return _g(n.map(Og))}),uo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t}).format(r)),mo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"long",...F,...t}).format(r)),_n=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...F,...t}).format(r)),On=e=>N(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),po=({locale:e,intlOptions:t})=>N(r=>{const n=(0,ki.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t,year:void 0}).formatRange(r,n)}),ho=({locale:e,intlOptions:t})=>N(r=>{const n=(0,ki.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).formatRange(r,n)}),kn=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{year:"numeric",...F,...t}).format(r)),fo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),_g=e=>e.map(t=>t.value).join(""),Og=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},za=1e3,kg=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>ce(a=>{const i={...Mn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Pn(a,t,i)}),Pg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Mn(n,t),notation:"compact",...r};return Pn(n,e,a)}),Mg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Mn(n,t),notation:"compact",...r,style:"percent"};return Pn(n,e,a)}),Pn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),go=e=>Math.abs(e)>za?go(e/za):Number.isInteger(e),Ng=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Mn=(e,t)=>go(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Ng(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Bg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),Fg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",...F,...t}).format(r)),$g=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),Gg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),Nn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return kg(e);case"date":case"datetime":return Bg(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return $g(e);case"decimal":case"integer":return Pg(e);case"duration":return Rn(e);case"month":return Fg(e);case"month_year":return _n(e);case"percentage":return Mg(e);case"quarter":return On(e);case"text":return Vn(e);case"time":return Gg(e);case"year":return kn(e);case"lookup":return Nn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Ug=.9,Wg=1/3,Hg=1/4,Kg=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?zg(e):Yg(e),zg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=yo(e.ticks,n),o=qg(e.ticks,r.width),c=o*Ug;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=qr(c);return{...e,ticks:Yr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=qr(r.height*Wg);return{...e,ticks:Yr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Yg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=yo(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=qr(r.width*Hg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Yr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},qg=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},yo=(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}},Yr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:io(i.formattedLabel,r,a)})},qr=e=>Math.max(0,Math.floor(e)),jg=(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},Xg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?Zg(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;jg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},Zg=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),Ya=.5,ct=e=>({x:0,y:0,width:e.width,height:e.height}),Bn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,ut=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:Qg(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:ey(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,I=ja(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=ja(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:Jg(e,I,A,c,u)}},qa=(e,t,r,n)=>r-n>=e-Ya&&r+n<=t+Ya,Jg=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||qa(e.x,e.x+e.width,t,n/2),s=e.height===0||qa(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},Qg=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",ey=e=>e==="center"?"center":e==="start"?"min":"max",ja=({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},ty=(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}}},ry=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=ay(e.layer);for(const a of e.layer.data){const i=R(a),s=_(a)??w(a);if(i===null||s===null||!We(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}=ty(s,k(a),i,e.panelRect.width,e.panelRect.height),h=ut({box:d,panel:ct(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},ny={place:ry,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"none"},ay=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Bn(r):r,align:n}},Fn=(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")}}},Tt=6,iy=e=>{const t=[],r=B(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=oy({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"?uy({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}):dy(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,ct(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 my(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=gy({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},sy={place:iy,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"absoluteGrandTotal"},oy=({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=bo(t,d);if(m===null)continue;const h=a(d);if(h==="")continue;const p=Fn(n,"observation",h),f=$n(m,r);c&&p.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:h,boxes:p,bounds:f})}return{entries:s,shouldRotate:!i&&o}},$n=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),vo=(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}},bo=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(t);return r===null||n===null||a===null||i===null?null:vo(e,r,n,a,i)},ly=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return vo(e,r,n,a,i)},cy=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",jr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},uy=e=>e.isStacked?py({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):fy({edge:cy(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),So=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},dy=(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=ut({box:n.bounds,panel:a,frame:So(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}},my=(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=ct(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=bo(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=Fn(e.measureDataLabel,"category",p),g=f[o],y=$n(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=ut({box:y,panel:u,frame:So(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},py=({bounds:e,box:t,isRotated:r})=>{const n=jr(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"}},hy=(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}}},fy=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=hy(e,t,a,i),g=jr(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height;if(y+s<d){if(v>m)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const V=h-p*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=jr(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=h+p*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},gy=({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=$n(ly(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+Tt+m/2:u.x-Tt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-Tt-h/2:u.y+u.height+Tt+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},yy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=by(e.layer);for(const a of e.layer.data){const i=R(a),s=w(a);if(i===null||s===null||!We(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=ut({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:ct(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},vy={place:yy,getPercentageValueStrategy:()=>"none"},by=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Bn(r):r,align:n}};function dt(e){return e[l.VISUAL_VARIABLES.color]}function xo(e){return e[l.VISUAL_VARIABLES.alpha]}function Gn(e){return e[l.VISUAL_VARIABLES.size]}function Xr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Ao(e){return e[l.VISUAL_VARIABLES.lineType]}var Sy={color:dt,alpha:xo,strokeWidth:Xr,lineType:Ao,size:Gn,borderWidth:Xr},ir=(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=Iy(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=xy(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=rt(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=rt(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=rt(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=Io(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=rt(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},xy=(e,t)=>{const r=(c,u)=>{const d=p=>Xa(c.overrides,p,u)??Xa(c.defaults,p,u);return{get:p=>{const f=d(p)?.declarations[p];if(f!==void 0)return Ay(f,t)},getSource:p=>{const f=d(p);return f===void 0?"unresolved":f.origin.list==="builtin"?"builtin":"authored"}}},n=c=>r(e.panelBorder,u=>{const d=u.select.target==="panelBorder"?u.select.edge:void 0;return d===void 0||d===c}),a=c=>u=>r(e[c],d=>d.select.target!==c?!1:d.select.axis===void 0||d.select.axis===u),i=c=>r(e.ruleLabel,u=>u.select.target!=="ruleLabel"?!1:u.select.layer===void 0||u.select.layer===c),s=(c,u)=>r(e.dataLabel,d=>d.select.target!=="dataLabel"||d.select.role!==void 0&&d.select.role!==c?!1:d.select.position===void 0||d.select.position===u),o=c=>r(e.tooltip,u=>u.select.target==="tooltip"&&u.select.part===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),tooltip:{box:o(void 0),heading:o("heading"),label:o("label"),value:o("value"),primaryRow:o("primaryRow")}}},Xa=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const a=e[n];if(!(a===void 0||!r(a))&&a.declarations[t]!==void 0)return a}},Ay=(e,t)=>{if(l.isLightDarkColor(e))return e[t];if(typeof e=="object"&&"offsetX"in e){const{offsetX:r,offsetY:n,blur:a,color:i}=e;return{offsetX:r,offsetY:n,blur:a,color:l.isLightDarkColor(i)?i[t]:i}}return e},Iy=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=Lt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=Lt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=Lt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=Io(n,a);return o!==void 0?o:Lt(e.defaults,n,a,void 0,t)}}),Lt=(e,t,r,n,a)=>rt(e,t,r,n,a)?.value,rt=(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&&Ty(s,r))return{value:Ly(o,a),origin:s.origin}}},Ty=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),Ly=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Io=(e,t)=>{const r=Sy[e];if(!(r===void 0||t===void 0))return r(t)??void 0},wy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Vy(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=ir().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=w(s);if(o===null||c===null||!We(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=ut({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:ct(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},Ey={place:wy,getPercentageValueStrategy:()=>"none"},Vy=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}},To=e=>{const t=G(e),r=U(e),n=k(e),a=_(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),s=Math.abs(r-t),o=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-o,width:s,height:c}},Lo=e=>{const t=To(e);if(!t)return null;const r=t.width*qp,n=t.height*jp;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},Za=4,Ry=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const r=ir().geomReaders(e.layer);for(const n of e.layer.data){const a=Lo(n);if(a===null||!dt(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:s,height:o}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;s+Za>c||o+Za>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:s,height:o,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return t},Cy={place:Ry,getPercentageValueStrategy:()=>"none"};function Un(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Wn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var Dy=" · ",Ir=2,at=(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)},_y=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=at("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Ir&&t+i<=e.outerRadiusPx+Ir)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=at("tangential",r,n,a)/t,c=Ir/t;return Math.abs(r-e.midAngle)+o<=s+c},Oy=({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,ky=({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+at("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},Py=({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+at("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=at("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:_y({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},My=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const m of e.layer.data){const{startAngle:h,endAngle:p}=Un(m),{innerRadius:f,outerRadius:g}=Wn(m);if(h===null||p===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${Dy}${y}`,I={startAngle:h,endAngle:p,midAngle:(h+p)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const z=e.measureDataLabel("observation",o,x);V={width:z.width,height:z.height},A=ky({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const z=Fn(e.measureDataLabel,"observation",x),T=z[r];A=Py({wedge:I,placement:r,justify:Bn(n),align:a,offset:i,labelWidth:T.width,labelHeight:T.height}),V=z[A.position]}const j=c+Math.sin(A.labelAngle)*A.labelRadius,ie=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!Oy({x:j,y:ie,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:j,y:ie,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},Ny={place:My,getPercentageValueStrategy:()=>"absoluteGrandTotal"},By=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 so(e);case"date":return Cg(e);case"datetime":return Dg(e);case"day_month":return uo(e);case"decimal":return oo(e);case"duration":return Rn(e);case"integer":return lo(e);case"month":return mo(e);case"month_year":return _n(e);case"percentage":return co(e);case"quarter":return On(e);case"text":return Vn(e);case"weekly_date_range":return po(e);case"weekly_date_range_with_year":return ho(e);case"year":return kn(e);case"time":return fo(e);case"lookup":return By({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Hn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:ud(e),locale:r,numberFormat:t})}var Fy=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Ze(e,t),variable:r}:{read:K,variable:l.GROUP_VARIABLES.group}},wo=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Hn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Hy({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:$y({layer:e,numberFormat:n,locale:s})}},$y=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Fy(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)}},Gy=(e,t)=>{switch(t){case"stack":return Uy(e);case"fill":return Wy(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Uy=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const s=a[t];if(s==null)return null;const o=r?.get(Sn(a,t));return o===void 0?null:o.total}},Wy=e=>{const t=Zt(e);return r=>{const n=k(r),a=_(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}},Hy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=W(e.data,e.dataLabels.labelSource),o=Gy(e,i),c=Ky({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&Eo(e);return m=>{const h=s(m);if(h===null)return"";if(!d||!l.isStrictNumericDataValue(h))return c(h,m);const p=o(m);return p===null||p===0?c(h,m):u(h/p)}},Ky=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(Eo(e))return a;const o=zy(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:Yy(e.data,i),locale:n,numberFormat:t})},Eo=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Xt(e.position,e.mapping))},zy=(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})},Yy=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},Kn={bar:{cartesian:sy,polar:Ny},line:{cartesian:vy},point:{cartesian:Ey},area:{cartesian:ny},tile:{cartesian:Cy}},qy=(e,t)=>Kn[e]?.[t]!==void 0,jy=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=Kn[f]?.[h];if(g===void 0)continue;const y=wo({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)Xy(x,h,c,u)||d.push(x)}return{labels:d}},Xy=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Zy({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=Kn[o.geom]?.cartesian;if(c===void 0)continue;const u=wo({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 Tr={abbreviation:"none",decimals:"auto"},Vo=({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:Tr,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:Tr,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:Tr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},Lr=6,wr=6,Er=15,Vr=5,Rr=15,Ro=(e,t)=>{switch(e){case"small":return{arrowStartGap:Lr,arrowEndGap:wr,offsetFromHigherObservation:Er,arrowheadSize:Vr,curveRadius:Rr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Lr*1.5,arrowEndGap:wr*1.5,offsetFromHigherObservation:Er*1.25,arrowheadSize:Vr*1.5,curveRadius:Rr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Lr*2,arrowEndGap:wr*2,offsetFromHigherObservation:Er*1.75,arrowheadSize:Vr*2.5,curveRadius:Rr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Jy=(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},Qy=(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 Yu=Object.create,Oi=Object.defineProperty,qu=Object.getOwnPropertyDescriptor,ju=Object.getOwnPropertyNames,Xu=Object.getPrototypeOf,Zu=Object.prototype.hasOwnProperty,Ju=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(var a=ju(t),i=0,s=a.length,o;i<s;i++)o=a[i],!Zu.call(e,o)&&o!==r&&Oi(e,o,{get:(c=>t[c]).bind(null,o),enumerable:!(n=qu(t,o))||n.enumerable});return e},zt=(e,t,r)=>(r=e!=null?Yu(Xu(e)):{},Ju(t||!e||!e.__esModule?Oi(r,"default",{value:e,enumerable:!0}):r,e));const l=require("./config.types-C50AcoSx.cjs");let ye=require("color2k"),ki=require("date-fns"),je=require("lodash-es"),Qe=require("d3-time"),Qu=require("date-fns/differenceInDays"),pe=require("d3-regression"),Q=require("d3-scale"),Ne=require("d3-interpolate"),O=require("d3-scale-chromatic"),Ge=require("lodash-es/clamp");Ge=zt(Ge,1);let Mt=require("lodash-es/merge");Mt=zt(Mt,1);let Br=require("humanize-duration");Br=zt(Br,1);let Ie=require("d3-shape"),ed=require("d3-delaunay"),Nt=require("lodash-es/isEqual");Nt=zt(Nt,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.8.1-beta.1787326761356");var td=1e6;function Y(e){return String(Math.round(e*td))}var Ia="#FFFFFF",vr="#1A1A1A",rd=e=>{try{return(0,ye.getContrast)(e,Ia)>(0,ye.getContrast)(e,vr)?Ia:vr}catch{return vr}},nd=(e,t)=>{try{if(e===void 0){const[,,,n]=(0,ye.parseToRgba)(t);return n>=1?t:void 0}const[,,,r]=(0,ye.parseToRgba)(e);return r>=1?e:(0,ye.parseToRgba)(t)[3]<1?void 0:(0,ye.mix)(t,(0,ye.opacify)(e,1),r)}catch{return}},Ta=0;function M(){return Ta+=1,`${Math.random().toString(36).slice(2,6)}${Ta.toString(36)}`}function R(e){return e[l.POSITION_VARIABLES.x]}function w(e){return e[l.POSITION_VARIABLES.y]}function G(e){return e[l.POSITION_VARIABLES.xMin]}function U(e){return e[l.POSITION_VARIABLES.xMax]}function k(e){return e[l.POSITION_VARIABLES.yMin]}function _(e){return e[l.POSITION_VARIABLES.yMax]}function ln(e){return e[l.POSITION_VARIABLES.yRaw]}function ad(e,t){return e[l.resolveScaledAestheticVariable(t)]}var id={xMin:0,xMax:1,yMin:0,yMax:1},Fr=(e,t)=>{if(t.type==="polar")return null;const r=G(e)??R(e),n=U(e)??R(e),a=k(e)??w(e),i=_(e)??w(e);return r===null||n===null||a===null||i===null?null:{xMin:r,xMax:n,yMin:a,yMax:i}},it=(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}}},Pi=e=>it(id,e),we=e=>{const t=l.extractVariableName(e.mapping.x);return t!==null&&t!==l.CONSTANT_VARIABLES.x?t:l.GROUP_VARIABLES.group},Yt=e=>e.identityKey!=="x-y"?null:l.extractVariableName(e.mapping.y),Mi=(e,t)=>e.yScaleType===t.yScaleType&&Gr(e.valueFormat)===Gr(t.valueFormat),$r=e=>`${e.yScaleType} y axis, ${Gr(e.valueFormat)}`,Gr=e=>e.type==="currency"?`${e.type}:${e.iso}`:e.type,Rt=(e,t,r)=>{const n=l.parseValue(e,t,r);return n!==null||!l.isTemporalValueFormat(t)?n:l.readISOInstant(e)},Ni=(e,t)=>{const r=l.toExplicitValueFormat(e.data.getValueFormat(we(e))),n=Yt(e);return a=>({...a,anchorValue:Rt(a.anchorValue,r,t),...a.groupValue!==void 0&&{groupValue:Rt(a.groupValue,l.toExplicitValueFormat(e.data.getValueFormat(l.GROUP_VARIABLES.group)),t)},...a.crossValue!==void 0&&n!==null&&{crossValue:Rt(a.crossValue,l.toExplicitValueFormat(e.data.getValueFormat(n)),t)}})};function Bi(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 E(e,t){return $i(e,t)}function L(e,t){for(const r of Object.keys(t)){const n=t[r];if(n!==void 0&&n!==e[r])return{...e,...t}}return e}function Fi(e,t,r){if(e[t]===r)return e;const n=[...e];return n[t]=r,n}function Xe(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 $i(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=$i(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 qt(e){return{pipe:t=>{const r=t(e);return qt({...e,...r})},result:()=>e}}var sd=(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 Ue(e,t){return e==="x"?t.x:t.y}function jt(e,t){return e==="x"?t.y:t.x}function od(e,t){return{main:Ue(e,t),cross:jt(e,t)}}function La(e,t){return e==="x"?{x:t.main,y:t.cross}:{x:t.cross,y:t.main}}function ld(e){return e.type==="cartesian"}var K=e=>e[l.GROUP_VARIABLES.group],st=(e,t)=>{const r=we(e),n=t[r]??null;if(n===null)return null;const a=Yt(e);if(a!==null){const s=t[a]??null;return s===null?null:{layerId:e.id,anchorValue:n,crossValue:s}}const i=r===l.GROUP_VARIABLES.group?null:K(t);return{layerId:e.id,anchorValue:n,...i!==null&&{groupValue:i}}},We=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,cd={type:"decimal"};function Gi(e){return e.length>0&&e.every(t=>t.data.size()===0)}function cn(e,t){return t!==null&&e.data.hasVariable(t)?e.data.getValueFormat(t):cd}function ud(e){return cn(e,l.extractVariableName(e.mapping.y))}var W=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return()=>r;const n=l.extractVariableName(t);return l.isDefined(n)?a=>{const i=a[n];if(i===void 0)return null;switch(e.getType(n)){case"numeric":return l.isStrictNumericDataValue(i)?i:null;case"categorical":return l.isStrictCategoricalDataValue(i)?i:null;case"temporal":return l.isStrictTemporalDataValue(i)?i:null;default:return null}}:()=>null},Ze=(e,t)=>W(e,t.x),un=(e,t)=>W(e,t.y),dd=(e,t)=>W(e,t.label),Ui=(e,t)=>W(e,t.color),md=(e,t)=>W(e,t.size),pd=(e,t)=>W(e,t.alpha),hd=(e,t)=>W(e,t.group),fd=(e,t)=>W(e,t.strokeWidth),Wi=["stack","dodge","identity","fill"],dn=["solid","dashed","dotted"],Hi=e=>dn.includes(e);function B(e){return e==="stack"||e==="fill"}var wa={variable:l.POSITION_VARIABLES.yRaw};function Xt(e,t){return B(e)?wa:t.y??wa}function Zt(e){return W(e.data,Xt(e.position,e.mapping))}function Ki({geom:e,position:t,mapping:r,purpose:n}){return e.resolveValueSource?.(r,n)??Xt(t,r)}function zi(e,t){const r=Ki({geom:t,position:e.position,mapping:e.mapping,purpose:"measurement"}),n=l.extractVariableName(r),a=n===l.POSITION_VARIABLES.yRaw?l.extractVariableName(e.mapping.y):n;return{read:W(e.data,r),valueFormat:cn(e,a)}}var Yi=e=>{const t=l.extractVariableName(e.mapping.y),r=Zt(e);return(n,a)=>t!==null&&a===t?r(n):n[a]??null},gd=["lt","lte","gt","gte","range"],yd={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"}},re=()=>!1,De=()=>!0;function Jt(e,t){return{hasVariable:r=>e.data.hasVariable(r),getType:r=>e.data.getType(r),getValueFormat:r=>e.data.getValueFormat(r),readValue:Yi(e),parsingLocale:t}}function be(e,t){if("and"in e){const r=e.and.map(n=>be(n,t)).filter(n=>n!==De);return r.includes(re)?re:r.length===0?De:n=>{for(const a of r)if(!a(n))return!1;return!0}}if("or"in e){const r=e.or.map(n=>be(n,t)).filter(n=>n!==re);return r.includes(De)?De:r.length===0?re:n=>{for(const a of r)if(a(n))return!0;return!1}}if("not"in e){const r=be(e.not,t);return r===re?De:r===De?re:n=>!r(n)}return bd(e,t)}function Se(e,t,r="highlight"){return"and"in e?e.and.flatMap(n=>Se(n,t,r)):"or"in e?e.or.flatMap(n=>Se(n,t,r)):"not"in e?Se(e.not,t,r):vd(e,t,r)}function vd(e,t,r){const{subject:n,effect:a}=yd[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=Sd(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 bd(e,t){if(!t.hasVariable(e.variable))return re;const r=l.toExplicitValueFormat(t.getValueFormat(e.variable)),n=a=>Rt(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=>_e(t.readValue(i,e.variable),a)==="less"}if("lte"in e){const a=n(e.lte);return i=>{const s=_e(t.readValue(i,e.variable),a);return s==="less"||s==="equal"}}if("gt"in e){const a=n(e.gt);return i=>_e(t.readValue(i,e.variable),a)==="greater"}if("gte"in e){const a=n(e.gte);return i=>{const s=_e(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=_e(u,s),m=_e(u,o);return d==="incomparable"||m==="incomparable"?!1:(d==="greater"||d==="equal")&&(m==="less"||m==="equal")}}return re}function Sd(e){for(const t of gd)if(t in e)return t;return null}function _e(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 xd=(e,t,r,n,a,i)=>{const s=ji(e,t,r.predicate,n,a,i);if(s===null)return null;const o=qi(r.padding),c=o===null?Td(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}},Ad=(e,t,r,n,a,i)=>{const s=ji(e,t,r.predicate,n,a,i);return s===null?null:it(s,r.align)},qi=e=>e===void 0||typeof e=="number"||e.unit!=="px"?null:{type:"px-offset",x:e.x??0,y:e.y??0},ji=(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=Se(r,u.data,"selection-anchor");if(d.length>0){for(const p of d)c.set(`${p.code}:${p.message}`,p);continue}o=!0;const{resolveAnchorBox:m}=e.geomRegistry.get(u.geom);if(m===void 0)continue;const h=be(r,Jt(u,i));if(h!==re)for(const p of u.data){if(!h(p))continue;const f=m(p,a);f!==null&&(s=s===null?f:Id(s,f))}}if(!o)for(const u of c.values())e.diagnostics.addWarning(u);return t.set(r,s),s},Id=(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)}),Td=(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}},Bt=(e,t,r)=>{const n=wd(e,t,r);return n===null?null:n.defer?.type==="annotation-ref"?n:Ed(n,t.offset,e.coordSystem)},Xi=(e,t)=>t.anchorType==="selection"?xd(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},mn=(e,t,r)=>Ur(e,t,r)?.point??null,Ur=({container:e,layers:t,coordSystem:r,parsingLocale:n},a,i)=>{for(const s of t){const o=e.geomRegistry.get(s.geom),{resolveAnchorPosition:c}=o;if(c===void 0||a.layerId!==void 0&&s.id!==a.layerId||a.layerId===void 0&&!s.interactive)continue;const u=zi(s,o),d=we(s),m=Yt(s),{anchorValue:h,groupValue:p,crossValue:f}=Ni(s,n)(a);let g=-1;for(const y of s.data){if(g+=1,!l.areDataValuesEqual(y[d]??null,h))continue;const v=m!==null?f:p;if(v!==void 0&&!l.areDataValuesEqual(m!==null?y[m]??null:K(y),v))continue;const x=c(y,{coordSystem:r,position:s.position,purpose:i,align:a.align});if(x===null)continue;const I=Zi(s,y,u);if(I===null)continue;const A=st(s,y);if(A!==null)return{point:{...x,...I,observationIndex:g,anchor:a.align===void 0?A:{...A,align:a.align}},layerId:s.id}}}return null},Ld=(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=Va(t.x,"x",r,i),u=Va(t.y,"y",r,i);if(c===null||u===null)return null;const d=s.map(c),m=o.map(u);if(!We(d,m))return null;const h=Ea(d,s,Vd(e)),p=Ea(m,o),f=La(n.mainAxis,{main:h.min,cross:p.min}),g=La(n.mainAxis,{main:h.max,cross:p.max});return it({xMin:f.x,xMax:g.x,yMin:f.y,yMax:g.y},t.align??"center")},Zi=(e,t,r)=>{const n=r.read(t);return l.isStrictNumericDataValue(n)?{geom:e.geom,measurementValue:n,valueFormat:sd(r.valueFormat,t),yScaleType:e.yScaleType}:null},wd=(e,t,r)=>{switch(t.anchorType){case"panel":return{x:t.x,y:1-t.y};case"axis":return Ld(e,t);case"selection":return Ad(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 mn(e,Rd(t),r)}},Ed=(e,t,r)=>{if(t===void 0||r.type==="polar")return e;const n=qi(t);return n!==null?{...e,defer:n}:{...e,x:e.x+(t.x??0),y:e.y-(t.y??0)}},Ea=(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}},Vd=({container:e,layers:t,coordSystem:r})=>{let n=0;for(const a of t){const i=e.geomRegistry.get(a.geom).resolveBandFraction?.(a.params,r);i!==void 0&&(n=Math.max(n,i))}return n>0?n:1},Rd=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align}),Va=(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},Cd=class extends l.Stage{constructor(e){super(),this.container=e}dependencies(e){return[e.annotations,e.layers,e.coordSystem,e.scales.x,e.scales.y,e.config.parsingLocale]}run(e){const{annotations:t,layers:r,coordSystem:n,scales:a,config:i}=e,s={container:this.container,layers:r,coordSystem:n,scales:a,selectionBoxCache:new Map,parsingLocale:i.parsingLocale},o={differenceArrows:Gd(s,t.differenceArrows),shapes:kd(s,t.shapes),arrows:Md(s,t.arrows),textAnnotations:Nd(s,t.textAnnotations),images:Pd(s,t.images),stickers:Bd(s,t.stickers),pinnedNumbers:Fd(s,t.pinnedNumbers),comments:$d(s,t.comments)};return Dd(this.container,o),_d(this.container,o),o}},ee=(e,t,r,n)=>{e.diagnostics.addWarning({code:"ANNOTATION_ANCHOR_UNRESOLVED",message:`Annotation "${r}" (${t}) ${n} — dropping this annotation.`,context:{annotationId:r,kind:t},suggestion:"Check that the anchor points at data, an axis value or a panel position that exists."})},Dd=(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)}},_d=(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 Od(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."})},Od=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},kd=(e,t)=>{const r=[];for(const n of t){const a=Xi(e,n.region);if(a===null){ee(e.container,"shape",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,kind:n.kind,zOrder:n.zOrder,region:a,fillColor:n.fillColor,fillOpacity:n.fillOpacity,strokeWidth:n.strokeWidth,strokeColor:n.strokeColor})}return r},Pd=(e,t)=>{const r=[];for(const n of t){const a=Xi(e,n.region);if(a===null){ee(e.container,"image",n.id,"has a region anchor that resolves to nothing");continue}r.push({id:n.id,src:n.src,zOrder:n.zOrder,region:a,fit:n.fit,opacity:n.opacity})}return r},Md=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.start,"pin"),i=Bt(e,n.end,"pin");if(a===null||i===null){ee(e.container,"arrow",n.id,`has ${Ji(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},Nd=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.at,"pin");if(a===null){ee(e.container,"text",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,content:n.content,at:a,width:n.width,align:n.align,backgroundColor:n.backgroundColor,backgroundColorStyle:n.backgroundColorStyle})}return r},Bd=(e,t)=>{const r=[];for(const n of t){const a=Bt(e,n.at,"pin");if(a===null){ee(e.container,"sticker",n.id,"has a point anchor that resolves to nothing");continue}r.push({id:n.id,at:a,sticker:n.sticker})}return r},Fd=(e,t)=>{const r=[];for(const n of t){const a=mn(e,n.at,"pin");if(a===null){ee(e.container,"pinnedNumber",n.id,"matches no observation");continue}r.push({id:n.id,at:a})}return r},$d=(e,t)=>{const r=[];for(const n of t){const a=mn(e,n.at,"pin");if(a===null){ee(e.container,"comment",n.id,"matches no observation");continue}r.push({id:n.id,at:a,content:n.content})}return r},Gd=(e,t)=>{if(e.coordSystem.type!=="cartesian"){for(const n of t)ee(e.container,"differenceArrow",n.id,"needs a cartesian coord system");return[]}const r=[];for(const n of t){const a=Ur(e,n.start,"value"),i=Ur(e,n.end,"value");if(a===null||i===null){ee(e.container,"differenceArrow",n.id,`has ${Ji(a,i)} matching no observation`);continue}if(a.layerId===i.layerId&&a.point.observationIndex===i.point.observationIndex){ee(e.container,"differenceArrow",n.id,"has both ends on the same observation");continue}Ud(e,n,a.point,i.point),r.push({id:n.id,start:a.point,end:i.point,ownColor:n.color,size:n.size,label:n.label,labelCrossPosition:n.labelCrossPosition})}return r},Ji=(e,t)=>e===null&&t===null?"start and end anchors":e===null?"a start anchor":"an end anchor",Ud=(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:$r(r),actual:$r(n)},suggestion:"Point both ends at observations sharing one y scale and one unit, or label the arrow as a proportion."})};function Wd(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:Qi(i),values:i};return new l.Dataset(n)}function Qi(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 Hd=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,Qi(a),a),r={...r,[n]:i}}return{data:t,mapping:r}}},Ee=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)}},Kd=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)}},zd=class extends Ee{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}},Yd=class{constructor(e){this.setupStage=new Kd(e),this.transformStage=new zd(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)}},qd=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}},jd=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:Zd(e.scales,e.layers)}}transform(e){return e.layers.map(t=>Qd(t))}},Xd=[[l.POSITION_VARIABLES.x,l.POSITION_VARIABLES.y],[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.yMin],[l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMax]],Ra=l.prefixInternalVariable("flipSwap"),Zd=(e,t)=>Jd(t)?e.map(r=>r.scaledAesthetic!=="x"||r.scaleType!=="continuous"&&r.scaleType!=="datetime"&&r.scaleType!=="discrete"?r:{...r,reverse:!r.reverse}):e,Jd=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},Qd=e=>{let t=e.data;for(const[r,n]of Xd){const a=t.hasVariable(r),i=t.hasVariable(n);a&&i?t=t.renameVariable(r,Ra).renameVariable(n,r).renameVariable(Ra,n):a?t=t.renameVariable(r,n):i&&(t=t.renameVariable(n,r))}return{...e,data:t}},xe=Math.PI*2,em=8,tm=1e-9,es=(e,t)=>Math.abs(t-e)>=xe-tm,He=e=>(e%xe+xe)%xe,ts=(e,t,r)=>{if(es(t,r))return!0;const n=He(r-t);return He(e-t)<=n},Ft=(e,t)=>{const r=Math.abs(He(e)-He(t));return Math.min(r,xe-r)},rs=(e,t,r)=>e*xe+t+r,$t=(e,t)=>({x:t*Math.sin(e),y:t*Math.cos(e)}),ns=(e,t)=>({angle:He(Math.atan2(e,t)),radius:Math.hypot(e,t)}),pn=(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}},Qt=(e,t)=>{const{x:r,y:n}=pn(e,t);return ns(r,n)};function as(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 is=(e,t)=>as(t.domain!==null&&t.domain.length>0?t.domain:e),rm=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=im(t,e.scales,e.layers),a=om(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=am(r,n),i=lm(t);return e.layers.map(s=>cm(t.theta==="y"?um(s):s,a,i))}},nm=[[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 am(e,t){return r=>rs(r,e,t)}function im(e,t,r){const n=t.find(i=>i.scaledAesthetic===e.theta);if(n===void 0||n.scaleType!=="discrete")return 0;const a=sm(n,e,r);return a===0?0:-Math.PI/a}function sm(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 is(n,e).length}function om(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 lm(e){const{innerRadius:t}=e;return r=>t+r*(1-t)}function cm(e,t,r){let n=e.data;return n=Oe(n,l.POSITION_VARIABLES.x,t),n=Oe(n,l.POSITION_VARIABLES.xMin,t),n=Oe(n,l.POSITION_VARIABLES.xMax,t),n=Oe(n,l.POSITION_VARIABLES.y,r),n=Oe(n,l.POSITION_VARIABLES.yMin,r),n=Oe(n,l.POSITION_VARIABLES.yMax,r),{...e,data:n}}function Oe(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 um(e){let t=e.data;for(const[r,n]of nm){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 dm=class extends l.Registry{constructor(){super("coord"),this.register("cartesian",new qd),this.register("flip",new jd),this.register("polar",new rm)}},ss=new Set(["min","max","scalar"]),mm={x:{min:l.POSITION_VARIABLES.xMin,max:l.POSITION_VARIABLES.xMax},y:{min:l.POSITION_VARIABLES.yMin,max:l.POSITION_VARIABLES.yMax}};function pm(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 hm(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 fm(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=mm[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 gm=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:fm(n.data,r.positionRoles,a)}}},hn=["x","y"],fn=new Set(["x","y","ySecondary"]),ot=new Set(["color","size","alpha","strokeWidth","lineType"]),Ve=e=>fn.has(e),gn=e=>ot.has(e),os=e=>Ve(e)||gn(e);function oe(e){return e==="secondary"?"ySecondary":"y"}function ls(e,t){return e==="y"?oe(t):"x"}function P(e){return e==="ySecondary"?"y":e}var Je=(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 ot){const i=l.extractVariableName(t[a]);l.isDefined(i)&&(r.has(i)||e.hasVariable(i)&&e.getType(i)==="categorical"&&n.add(i))}return[...n]},er=(e,t)=>e.hasVariable(l.GROUP_VARIABLES.group)?e.getValues(l.GROUP_VARIABLES.group,{distinct:!0,skipNulls:!0}).length>1:Je(e,t).some(r=>e.getValues(r,{distinct:!0,skipNulls:!0}).length>1),ym=class{compute({data:e,mapping:t}){const r=Je(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)}}},vm=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},bm=(e,t,r)=>{const n=Te(t,"color");return n===null?{}:(e?.columns??[]).some(a=>a.key===n)?{}:r};function Te(e,t){const r=P(t);for(const n of cs(t,e)){const a=l.extractVariableName(n.mapping[r]);if(l.isDefined(a))return a}return null}var tr=(e,t)=>e===null?null:t[e]??e,Sm=(e,t)=>e===null?null:t[String(e)]??null,Le=({layers:e,scaleType:t,variableName:r})=>{if(r===null)return br(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 Am(i,t)?i:br(t)}return br(t)},xm=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:cs(t,e).some(r=>r.position==="fill");function cs(e,t){return e==="ySecondary"?t.filter(r=>r.yScaleType==="secondary"):e==="y"?t.filter(r=>r.yScaleType==="primary"):t}var br=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},Am=(e,t)=>{switch(t){case"continuous":return l.isNumericValueFormat(e);case"datetime":return l.isTemporalValueFormat(e);case"discrete":case"palette":case"identity":return!0}},Im=[{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},ke=40,Tm=(e,t,r)=>{const n=r.unit==="quarter"?r.step*3:r.step;return Vm(r.unit).range(e,new Date(t.valueOf()+1),n)},Lm=({unit:e,step:t,start:r,stop:n})=>{const a=(0,Qu.differenceInDays)(n,r);switch(e){case"hour":return 24*a/t>ke;case"day":return a/t>ke;case"week":return a/(7*t)>ke;case"month":return a/(30*t)>ke;case"quarter":return a/(90*t)>ke;case"year":return a/(365*t)>ke}},wm=(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"}}},Em=(e,t)=>{const r=Rm(t);return r===null?!1:Ca[e]>Ca[r]},Vm=e=>{switch(e){case"hour":return Qe.utcHour;case"day":return Qe.utcDay;case"week":return Qe.utcMonday;case"month":case"quarter":return Qe.utcMonth;case"year":return Qe.utcYear}},Rm=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}},us={left:"right",right:"left",top:"bottom",bottom:"top"},Cm={x:!0,y:!0,ySecondary:!1},Dm=20,Da=new Set(["top","bottom"]),_m={type:"percentage"};function Om(e,t){const{scales:r,config:n,layers:a,coordSystem:i,variableLabels:s,geomRegistry:o}=e;if(Gi(a))return[];if(i.type==="polar"&&i.bandAxis===null)return[];const c=Mm(o,a,i.type,n),u=new Set(t.map(h=>h.position)),d=Bm(ds(n.axes.y.position,i.axisMapping.y.position),u),m=[];for(const h of fn){const p=r[h];if(!l.isDefined(p)||p.kind!=="position")continue;const f=km({scaleAestheticKey:h,scale:p,config:n,layers:a,axisMapping:i.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(f)}return m}function km(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}=Nm(t,n,i,s),h=Te(a,t),p=xm(a,t)?_m:Le({layers:a,scaleType:r.spec.scaleType,variableName:h});return{scaleAestheticKey:t,position:d,geometry:m,label:Pm(u,h,c),isVisible:u.isVisible,tickCandidates:$m(r,p,u.ticks.mode),valueFormat:p,tickMode:u.ticks.mode,ticksVisible:u.ticks.isVisible,gridVisible:Fm(u,o,t),scaleType:r.spec.scaleType,bandwidth:r.bandwidth??void 0}}function Pm(e,t,r){return e.label?e.label:t?r[t]??null:null}function Mm(e,t,r,n){const a=t.flatMap(o=>{const c=e.get(o.geom).grid[r];return c?[c]:[]}),i=a.some(o=>o.hideGridX),s=a.some(o=>o.hideGridY);return{x:{gridVisible:_a(i,n.axes.x.grid.isVisible)},y:{gridVisible:_a(s,n.axes.y.grid.isVisible)}}}function _a(e,t){if(e&&t===null)return!1}function Nm(e,t,r,n){switch(e){case"x":return{axisConfig:t.axes[e],position:ds(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=us[n],i=(0,je.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 ds(e,t){return Da.has(e)===Da.has(t)?e:t}function Bm(e,t){return t.has(e)?us[e]:e}function Fm(e,t,r){const{gridVisible:n}=r==="x"?t.x:t.y;return n??e.grid.isVisible??Cm[r]}var $m=(e,t,r)=>{const n=e.spec.scaleType==="continuous"||e.spec.scaleType==="datetime";if(r==="edges"&&n){const a=Um(e);if(a)return[a]}if(e.spec.scaleType==="continuous"){const a=new Set,i=[];for(let s=1;s<=Dm;s++){const o=e.generateTicks({count:s}),c=l.getStableKey(o);a.has(c)||(a.add(c),i.push({ticks:o.map(u=>Ke(e,u))}))}return i}return e.spec.scaleType==="datetime"?Gm(e,t):[{ticks:e.generateTicks().map(a=>Ke(e,a))}]},Gm=(e,t)=>{const[r,n]=e.domain;if(!l.isStrictTemporalDataValue(r)||!l.isStrictTemporalDataValue(n))return[{ticks:e.generateTicks().map(o=>Ke(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=>Ke(e,d)),valueFormat:c}))};for(const o of Im)Lm({...o,start:r,stop:n})||Em(o.unit,t)||s(e.generateTicks({interval:o}),wm(o,t));return s(e.generateTicks({atInputs:!0})),i.sort((o,c)=>o.ticks.length-c.ticks.length),i},Um=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:[Ke(e,r),Ke(e,n)]}},Ke=(e,t)=>({value:t,position:e.map(t)});function ms({scale:e,aesthetics:t,layers:r}){const n=Wm({layers:r,aesthetics:t}),a=ps({layers:r,aesthetics:t});return e.domain.map(i=>({value:i,geom:n(i),owner:a(i)}))}function Wm({layers:e,aesthetics:t}){const r=ps({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 ps({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 yn=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function Hm({scales:e,layers:t,valueLabels:r}){const n=e.color;if(n===void 0||!yn(n))return[];if(!t.some(o=>l.isDefined(o.mapping.color)))return[];const a=Te(t,"color");if(hs({colorVariableName:a,xVariableName:Te(t,"x"),mapsColorAcrossMultipleLayers:zm(t)>1,isMergedWithAnotherAesthetic:Km(e,t,a)}))return[];const i=n.spec.scaleType,s=t.findIndex(o=>l.isDefined(o.mapping.color));return ms({scale:n,aesthetics:["color"],layers:t}).map(({value:o,geom:c,owner:u})=>{const d=u?.layerIndex??s,m=t[d],h=m?l.extractVariableName(m.mapping.color):null;return{value:o,color:String(n.map(o)),geom:c,layerIndex:d,valueFormat:Le({layers:m?[m]:t,scaleType:i,variableName:h}),label:Sm(o,r)}})}var hs=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:r,isMergedWithAnotherAesthetic:n})=>n?!1:e===null||l.isInternalVariable(e)?!r:t!==null&&e===t;function Km(e,t,r){if(r===null)return!1;for(const n of ot){if(n==="color")continue;const a=e[n];if(!(a===void 0||!yn(a))&&Te(t,n)===r)return!0}return!1}var zm=e=>e.filter(t=>l.isDefined(t.mapping.color)).length;function fs(e,t){return e.get(t.geom).summaries.perGroupHeadline===!0}function Ym(e,t,r,n){const a=r.findIndex(i=>fs(e,i));return a===-1?[]:t.length<2?[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:tr(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 Oa(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 gs=e=>e==="none"?"first":e,qm=(e,t)=>{switch(t){case"total":{const{sum:r,count:n}=ka(e);return n===0?null:r}case"average":{const{sum:r,count:n}=ka(e);return n===0?null:r/n}case"current":return e.at(-1)??null}},jm=(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}},ka=e=>e.reduce((t,r)=>r===null?t:{sum:t.sum+r,count:t.count+1},{sum:0,count:0});function Xm(e){const{config:t,coordSystem:r}=e,n=t.headline.show;return n==="none"||n==="conversion"?null:r.type==="polar"?Zm(e,n):Jm(e,n)}function Zm(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:Le({layers:[a],scaleType:r.y?.spec.scaleType??"continuous",variableName:s})}}function Jm(e,t){const{config:r,scales:n,layers:a,variableLabels:i,colorGroups:s,geomRegistry:o}=e;if(!a.some(d=>fs(o,d)))return null;const c=Ym(o,s,a,i);if(c.length===0)return null;const u=c.map(d=>Qm({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 Qm({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=Le({layers:[i],scaleType:u?.spec.scaleType??"continuous",variableName:s}),m=rp(i.data,o),h=Le({layers:[i],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:o}),p=np(i.data,o),f=p.getValues(s,{type:"numeric"}),g=o!==null?p.getValues(o):[],y=c!==null?p.getValues(c):null,v=Oa(f,y,e.value),x=Oa(g,y,e.value);return{value:e.value,swatch:e.swatch,aggregate:qm(v,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:h,label:e.label,observationLabel:ep(t,m,x),comparison:tp(t,r,m,x,v)}}function ep(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 tp(e,t,r,n,a){return e!=="current"||!r?null:jm(n.map((i,s)=>({main:i,cross:a[s]??null})),gs(t))}function rp(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function np(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}function q(e,...t){return e?t.includes(e.geom):!1}function D(e,t){return e.find(r=>r.id===t)}function le(e,...t){return e.find(r=>t.includes(r.geom))}function ap(e,...t){return e.filter(r=>t.includes(r.geom))}function vn(e,t){return e.interactive?!1:t.some(r=>r!==e&&l.areMappingsEquivalent(r.mapping,e.mapping))}function bn(e){const t=e.filter(r=>!vn(r,e));return t.length>0?t:e}function ys({legendPosition:e,coordSystem:t,layers:r}){if(e!=="right"||t.type!=="cartesian"||t.mainAxis!=="x")return!1;const n=bn(r);return n.length===1&&n[0]?.supportsDirectLabels===!0}var ip=3;function sp({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=hp(up({scales:e,layers:r})),u=Te(r,"x"),d=c.map(y=>{if(mp(y,u,r))return null;const v=gp({group:y,variableLabels:a,layers:r,colorGroupsByValue:o});return v.items.length===0?null:{group:y,built:v}}).filter(l.isDefined),m=op(d),h=bn(r),p=Ap(s,t.legend.position,m,h,n);if(d.length===0)return{drawn:[],position:p};if(t.legend.position==="auto"&&xp(s,m,h,n))return{drawn:[],position:p};const f=Ip(t.legend.display,{legendPosition:p,coordSystem:n,layers:r}),g=f==="direct"?Ep(h[0]):null;return{drawn:d.map(({built:y})=>lp(y,{position:p,display:f,align:t.legend.align},g)),position:p}}function op(e){return e.reduce((t,{group:r,built:n})=>t+(r.some(a=>a.guideType!=="discrete")?1:n.items.length),0)}function lp(e,t,r){const{position:n,display:a}=t,i=cp(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 cp(e,t){return e!=="auto"?e:t==="top"||t==="bottom"?"start":"center"}function up(e){const{scales:t,layers:r}=e,n=[];for(const a of ot){const i=t[a];if(i===void 0||i.kind==="identity"||!dp(a,r))continue;const s=Te(r,a),o=wp(a,i);n.push({scaleAestheticKey:a,scale:i,variableName:s,guideType:o})}return n}function dp(e,t){const r=P(e);return t.some(n=>l.isDefined(n.mapping[r]))}function mp(e,t,r){const[n]=e;return n.scaleAestheticKey!=="color"?!1:hs({colorVariableName:n.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:pp(n.scaleAestheticKey,r),isMergedWithAnotherAesthetic:e.length>1})}function pp(e,t){const r=P(e);return t.filter(n=>l.isDefined(n.mapping[r])).length>1}function hp(e){const t=new Map;for(const r of e){const n=Lp(r),a=t.get(n);a?a.push(r):t.set(n,[r])}return[...t.values()]}function fp(e,t,r){if(t==="lineType"){e.lineType=r;return}if(t==="color"){e.color=String(r);return}e[t]=r}function gp({group:e,variableLabels:t,layers:r,colorGroupsByValue:n}){const a=e[0],i=e.map(c=>P(c.scaleAestheticKey)),s=ms({scale:a.scale,aesthetics:i,layers:r}),o=Le({layers:r,scaleType:a.scale.spec.scaleType,variableName:a.variableName});return{aesthetics:e.map(c=>c.scaleAestheticKey),title:tr(a.variableName,t),items:s.map(c=>yp(c,e,i,o,n))}}function yp(e,t,r,n,a){const i={};for(const o of t)fp(i,o.scaleAestheticKey,o.scale.map(e.value));const s=bp(e,t,r,n,a);return{value:e.value,label:vp(t,e,a),visual:i,normalizedY:null,geom:e.geom,valueFormat:s}}function vp(e,t,r){return e[0].scaleAestheticKey!=="color"?null:r.get(l.getStableKey(t.value))?.label??null}function bp(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=Sp(i,r);return i===void 0||s===null?n:Le({layers:[i],scaleType:t[0].scale.spec.scaleType,variableName:s})}function Sp(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 xp(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 Ap(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,B(u.position)&&(o=!0))}const c=r>=ip;return i&&s?"top":i?c?"right":"top":o?Tp(a)?"top":c?"right":"top":"top"}function Ip(e,t){return e==="pill"?"pill":ys(t)?"direct":"pill"}function Tp(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Lp(e){const t=e.scale.domain.map(l.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function wp(e,t){return yn(t)?"discrete":`continuous:${e}`}function Ep(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(_(c))||l.isDefined(w(c)));if(!n)return;const a=K(n);if(!l.isDefined(a))return;const i=k(n),s=_(n)??w(n);if(!l.isDefined(s))return;const o=l.isDefined(i)?(i+s)/2:s;t.set(String(a),o)}),t}var Vp=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=vm(e.originalData),r=Hm({scales:e.scales,layers:e.layers,valueLabels:bm(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=Xm(n),i=sp(n),s={...i,drawn:Rp(a,i.drawn)};return{axes:Om(n,s.drawn),legends:s,headline:a,colorGroups:r,variableLabels:t}}},Rp=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],Cp=e=>l.getStableKey([K(e)]),Sn=(e,t)=>l.getStableKey([t!==null?e[t]??null:null]),Dp=e=>e!=="data-point",Gt=(e,t,r)=>{switch(e){case"series":return Cp(t);case"x-value":return Sn(t,r)}},_p={bar:"observation-rerender",rule:null,line:"overlay-anchor",area:"overlay-anchor",point:"overlay-anchor",tile:"observation-rerender"};function vs(e){const t=_p[e]??null;return t===null?null:{strategy:t,composition:bs()}}function bs(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}var Op=class extends Ee{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=kp({layer:e,highlights:n,parsingLocale:t.config.parsingLocale,strategy:r.strategy,container:this.container});return{...e,highlight:{...r,composition:a}}}};function kp({layer:e,highlights:t,parsingLocale:r,strategy:n,container:a}){const i=t.filter(T=>{const X=Se(T.predicate,e.data);for(const Z of X)a.diagnostics.addWarning({...Z,message:`${Z.message} Dropping this highlight.`});return X.length===0}),s=l.extractVariableName(e.mapping.x),o=Jt(e,r),c=i.map(T=>({predicate:be(T.predicate,o),scope:T.scope})),u=c.some(({scope:T})=>T==="series"),d=c.some(({scope:T})=>T==="x-value"),m=n==="overlay-anchor",h=e.data.size(),p=u?new Array(h):null,f=d?new Array(h):null,g=m?new Array(h):null,y=new Uint8Array(h),v=new Set,x=new Set;let I=!1,A=0;for(const T of e.data){let X,Z;p!==null&&(X=Gt("series",T,s),p[A]=X),f!==null&&(Z=Gt("x-value",T,s),f[A]=Z),g!==null&&(g[A]=T);for(const{predicate:St,scope:xt}of c)if(St(T))switch(xt){case"series":X!==void 0&&v.add(X);break;case"x-value":Z!==void 0&&x.add(Z);break;case"data-point":y[A]=1,I=!0;break}A++}if(v.size===0&&x.size===0&&!I)return bs();const V=new Uint8Array(h),j=[];let ie=0;for(let T=0;T<h;T++){const X=p?.[T],Z=f?.[T],St=X!==void 0&&v.has(X),xt=Z!==void 0&&x.has(Z),xa=y[T]===1;if(n==="observation-rerender")(St||xa||xt)&&(V[T]=1,ie++);else if(St)V[T]=1,ie++;else if(xa||xt){const Aa=g?.[T];Aa!==void 0&&j.push({observation:Aa,observationIndex:T})}}const z=ie>0?{...e,data:e.data.filterByMask(V)}:null;return{isDimmed:(n==="observation-rerender"||v.size>0)&&z!==null,matchedLayer:z,overlayCandidates:j}}var Pp=l.prefixInternalVariable("__ungrouped__");function Mp(e){const t=e.getVariableNames().filter(a=>e.getType(a)==="temporal"&&l.isDateWithoutYearValueFormat(e.getValueFormat(a)));if(t.length===0)return e;const r=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"});let n=e;for(const a of t){const i=n.getValues(a,{type:"temporal"}),s=new Map,o=i.map((c,u)=>{if(c===null)return null;const d=r[u]??Pp;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 Np=()=>({defaults:[],overrides:[],warnings:[]}),Bp=class extends Ee{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),e.coords.coordType]}compileLayer(e,t){return this.runLayerPipeline({layer:e,data:this.transformCompiler.compile({data:t.data,transforms:e.transforms}),effectiveMapping:{...t.mapping,...e.mapping},xScaleIsDiscrete:Pa(t),coordType:t.coords.coordType})}runLayerPipeline({layer:e,data:t,effectiveMapping:r,xScaleIsDiscrete:n,coordType:a}){const i=qt({data:t,mapping:r}).pipe(({data:o,mapping:c})=>{const u=this.statCompiler.compute(e.stat,{data:o,mapping:c,xScaleIsDiscrete:n});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>({data:this.groupCompiler.compute({data:o,mapping:c}).data,mapping:c})).pipe(({data:o,mapping:c})=>({data:Mp(o),mapping:c})).pipe(({data:o,mapping:c})=>{const u=this.geomCompiler.compile(e.geom,{data:o,mapping:c,params:e.params,coordType:a});return{data:u.data,mapping:{...c,...u.mapping}}}).pipe(({data:o,mapping:c})=>{const u=this.positionAdjusterCompiler.adjust(e.position,{data:o,mapping:c});return{data:u.data,mapping:{...c,...u.mapping}}}).result(),s=this.container.geomRegistry.get(e.geom);return{...i,id:e.id,geom:e.geom,position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},spatialKind:s.spatialKind,identityKey:s.identityKey,tooltip:s.tooltip,supportsDirectLabels:s.legend.directLabelSupport?.[e.position]===!0,highlight:vs(e.geom),styles:Np()}}};function Pa(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}function Ss(e,t){const[r]=t;if(r){for(const n of t)e.addError(n);throw new l.UserInputError(r)}}function Wr(e,t){const r=xs(e,t),n={};for(const{layer:i,scaleConstraints:s,crossAxis:o}of r)s.zeroBaseline===!0&&(n[o]={nice:(n[o]?.nice??!0)&&i.position!=="fill"});const a=r.find(({scaleConstraints:i})=>i.discreteCrossAxis===!0);return{discreteAxis:r.some(({scaleConstraints:i})=>i.discreteMainAxis===!0)?"x":null,discreteCrossAxis:a?.crossAxis??null,bandedAxes:$p(r),zeroAxes:n,bandPadding:Gp(r)}}function Fp(e,t){const r=xs(e,t);for(const n of r){if(n.scaleConstraints.discreteCrossAxis!==!0)continue;const a=r.find(i=>i.scaleConstraints.zeroBaseline===!0&&i.crossAxis===n.crossAxis);if(a!==void 0)return{crossAxis:n.crossAxis,banded:Ma(n),zeroAnchored:Ma(a)}}return null}var Ma=({layer:e,index:t})=>({layerId:e.id,layerIndex:t,geom:e.geom});function xs(e,t){const r=[];return t.forEach((n,a)=>{if(!e.has(n.geom))return;const{scaleConstraints:i}=e.get(n.geom);i!==void 0&&r.push({layer:n,index:a,scaleConstraints:i,crossAxis:oe(n.yScaleType)})}),r}function $p(e){const t=new Set;for(const r of e)if(r.scaleConstraints.discreteCrossAxis===!0)for(const n of As(r))t.add(n);return[...t]}function Gp(e){const t={};for(const r of e){const n=r.scaleConstraints.bandPadding;if(n!==void 0)for(const a of As(r)){const i=t[a];t[a]=i===void 0?n:Math.min(i,n)}}return t}function As({scaleConstraints:e,crossAxis:t}){return e.discreteCrossAxis!==!0?["x"]:e.discreteMainAxis===!0?["x",t]:[t]}var Up=new Set(["label","group"]),Wp=class{constructor(e,t,r,n){this.container=e,this.transformCompiler=t,this.statRegistry=r,this.layerCompiler=n}get stats(){return this.layerCompiler.stats}compile(e){this.checkPreCompile(e);const t=this.layerCompiler.compile(e);return this.checkPostCompile(t),t}checkPreCompile(e){const t=[];e.layers.forEach((r,n)=>{const a=this.transformCompiler.compile({data:e.data,transforms:r.transforms}),i={...e.mapping,...r.mapping},s={layerId:r.id,layerIndex:n,geom:r.geom,position:r.position,stat:r.stat,effectiveMapping:i,data:a,coordType:e.coords.coordType,dataLabels:r.dataLabels};t.push(...this.validateLayer(s));const o=[...this.collectUndeclaredAesthetics(s),...this.collectPanelJustifyWarnings(s)];for(const c of o)this.container.diagnostics.addWarning(c)}),t.push(...this.validateSharedScaleDemands(e.layers)),Ss(this.container.diagnostics,t)}checkPostCompile(e){Gi(e)&&this.container.diagnostics.addWarning({code:"EMPTY_DATASET",message:"No data to plot — every layer resolved to zero observations.",suggestion:"Check the dataset has rows and that transforms (filters, joins) are not removing them all."})}validateLayer(e){return[...this.validateRequiredAesthetics(e),...this.validateVariableExistence(e),...this.validatePositionalAestheticTypes(e),...this.validateGeomMapping(e),...this.validateCoordSupport(e),...this.validateSupportedPosition(e)]}collectPanelJustifyWarnings({geom:e,effectiveMapping:t,data:r,layerIndex:n,coordType:a,dataLabels:i}){const{justify:s,showDataLabels:o}=i;if(!o||s!=="panel-start"&&s!=="panel-end")return[];if(a==="polar"||!this.container.geomRegistry.get(e).isComposite)return[];if(!er(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=[...pm(s),...o.filter(m=>m.required).map(m=>m.name)],{computedVariables:u}=this.statRegistry.get(n.type),d=u;for(const m of c)d.has(m)||l.isDefined(a[m])||i.push({code:"MISSING_AESTHETIC",message:`Layer '${e}': geom '${r}' requires aesthetic '${m}'`,context:{layerIndex:t,aesthetic:m}});return i}validateVariableExistence({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const s=[],{computedVariables:o}=this.statRegistry.get(n.type),{derivedVariables:c}=this.container.geomRegistry.get(r),u=o,d=new Set(c);for(const[m,h]of Object.entries(a)){if(u.has(m))continue;const p=l.extractVariableName(h);p===null||p===""||d.has(p)||i.hasVariable(p)||s.push({code:"UNKNOWN_VARIABLE",message:`Layer '${e}': aesthetic '${m}' references variable '${p}' which does not exist in the dataset`,context:{layerIndex:t,aesthetic:m,variableName:p}})}return s}validatePositionalAestheticTypes({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a,data:i}){const{positionRoles:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=o,u=[];for(const d of s){if(!ss.has(d.role)||!l.isDefined(d.aes)||c.has(d.aes)||d.role==="scalar"&&d.aes===d.axis)continue;const m=l.extractVariableName(a[d.aes]);if(m===null||!i.hasVariable(m))continue;const h=i.getType(m);h!=="numeric"&&u.push({code:"INCOMPATIBLE_TYPE",message:`Layer '${e}': aesthetic '${d.aes}' must be numeric, but variable '${m}' is ${h}`,context:{layerIndex:t,aesthetic:d.aes,variableName:m,variableType:h},suggestion:this.suggestNumericAestheticFix(d.aes,d.axis,a,i)})}return u}suggestNumericAestheticFix(e,t,r,n){const a=t==="y"?"x":"y";if(e===t){const i=l.extractVariableName(r[a]);if(i!==null&&n.hasVariable(i)&&n.getType(i)==="numeric")return`Swap the '${a}' and '${t}' mappings so the numeric variable is on '${t}'. Add coord.flip() to orient the graph horizontally.`}return`Map '${e}' to a numeric variable.`}validateGeomMapping({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{validateMapping:i}=this.container.geomRegistry.get(r);if(i===void 0)return[];const{computedVariables:s}=this.statRegistry.get(n.type);return i({mapping:a,computedVariables:s}).map(o=>({...o,message:`Layer '${e}': ${o.message}`,context:{...o.context,layerIndex:t}}))}validateSharedScaleDemands(e){const t=Fp(this.container.geomRegistry,e);if(t===null)return[];const{crossAxis:r,banded:n,zeroAnchored:a}=t;return[{code:"CONFLICTING_SCALE_DEMANDS",message:`Layer '${n.layerId}' (geom '${n.geom}') needs '${r}' to be a band scale, but layer '${a.layerId}' (geom '${a.geom}') needs it to be a value axis anchored at zero. One scale cannot be both.`,context:{aesthetic:r,layerId:n.layerId,layerIndex:n.layerIndex},suggestion:"Drop one of the layers, or move one onto the secondary y axis with 'yScaleType'."}]}validateCoordSupport({layerId:e,layerIndex:t,geom:r,coordType:n}){const{supportedCoordTypes:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${e}': geom '${r}' is not supported under ${n} coords`,context:{layerIndex:t}}]}validateSupportedPosition({layerId:e,layerIndex:t,geom:r,position:n}){const{supportedPositions:a}=this.container.geomRegistry.get(r);return a.includes(n)?[]:[{code:"UNSUPPORTED_POSITION",message:`Layer '${e}': geom '${r}' does not support the '${n}' position`,context:{layerIndex:t},suggestion:`Use one of: ${a.join(", ")}.`}]}collectUndeclaredAesthetics({layerId:e,layerIndex:t,geom:r,stat:n,effectiveMapping:a}){const{positionRoles:i,aesthetics:s}=this.container.geomRegistry.get(r),{computedVariables:o}=this.statRegistry.get(n.type),c=new Set([...hm(i),...s.map(h=>h.name)]),u=Up,d=o,m=[];for(const h of Object.keys(a))l.isDefined(a[h])&&(c.has(h)||u.has(h)||d.has(h)||m.push({code:"UNDECLARED_AESTHETIC",message:`Layer '${e}': geom '${r}' does not declare aesthetic '${h}'; the mapping is ignored`,context:{layerIndex:t,aesthetic:h}}));return m}},ae=class{constructor(){this.positionRoles=[],this.identityKey="x-group",this.defaultPosition="identity",this.supportedPositions=Wi,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,je.merge)({},this.defaultParams,e.params)}},xn=(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=w(e);return!l.isStrictNumericDataValue(r)||!l.isStrictNumericDataValue(n)?null:{x:r,y:n}},Hp=class extends ae{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=xn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0)),{data:e,mapping:{}}}},Kp=.7,zp=.1,Yp=.03,qp=.05,Is=e=>{const t=e[l.STACK_VARIABLES.role];return t??"solo"},jp=class extends ae{constructor(...e){super(...e),this.type="bar",this.defaultParams={},this.defaultPosition="dodge",this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value",aes:"y"}],this.aesthetics=[{kind:"visual",name:"color"},{kind:"visual",name:"alpha"}],this.summaries={grandTotal:!0,stackTotals:!0,perGroupHeadline:!0},this.grid={cartesian:{hideGridX:!0},flip:{hideGridX:!0}},this.legend={suppressWhenSingleItem:!0,sidePlacement:"whenStackedVertical",directLabelSupport:{stack:!0,fill:!0}},this.scaleConstraints={discreteMainAxis:!0,zeroBaseline:!0},this.dataLabels={polar:{format:"percentage"}},this.dataLabelCoordTypes=["cartesian","flip","polar"],this.highlightStrategy="observation-rerender",this.supportedCoordTypes=["cartesian","polar","flip"],this.spatialKind="rects",this.resolveAnchorBox=Fr,this.resolveDataLabelDefaults=t=>B(t)?{justify:"center"}:{},this.resolveBandFraction=(t,r)=>Hr(t,r.type),this.resolveAnchorPosition=(t,{coordSystem:r,position:n,purpose:a,align:i})=>{if(r.type==="polar")return Xp(t);if(i!==void 0){const m=Fr(t,r);return m===null?null:it(m,i)}const s=B(n),o={isSolo:!s||Is(t)==="solo",isNegative:s&&Zp(t),purpose:a};if(r.mainAxis==="x"){const m=G(t),h=U(t),p=Na({lowerBound:k(t),upperBound:_(t)??w(t),options:o});return m===null||h===null||p===null?null:{x:(m+h)/2,y:p}}const c=k(t),u=_(t),d=Na({lowerBound:G(t),upperBound:U(t)??R(t),options:o});return c===null||u===null||d===null?null:{x:d,y:(c+u)/2}}}resolveParams(e){const{width:t,...r}=super.resolveParams(e),n=this.resolveWidthParam(t,e.diagnostics);return{...r,...n!==void 0&&{width:n}}}compile({data:e,mapping:t,params:r,coordType:n}){const a=Hr(r,n);e=xn(e,t),e.hasVariable(l.POSITION_VARIABLES.yMin)||(e=e.addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",0));const i=a/2;return e=e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-i).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",i),{data:e,mapping:{}}}resolveWidthParam(e,t){if(e===void 0)return;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:void 0;return t?.addWarning({code:"INVALID_GEOM_PARAM",message:`Bar width must be a fraction in (0, 1], got ${String(e)}; falling back to ${n??"the default band"}.`,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}},Hr=({width:e},t)=>e!==void 0?e:t==="polar"?1:Kp,Xp=e=>{const t=G(e),r=U(e),n=k(e),a=_(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)}},Zp=e=>{const t=ln(e);return l.isStrictNumericDataValue(t)&&t<0},Na=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},Jp=class extends ae{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=Fr,this.resolveAnchorPosition=An}compile(e){return{data:xn(e.data,e.mapping),mapping:{}}}},Qp=class extends ae{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.resolveValueSource=(t,r)=>{if(r!=="label")return null;const n=l.extractVariableName(t.size);return n!==null?{variable:n}:null}}compile({data:e}){return{data:e,mapping:{}}}},eh=class extends ae{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=Ba(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=Ba(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}}}},Ba=(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},th=e=>{const t=l.extractVariableName(e.color);return t!==null?{variable:t}:null},rh=class extends ae{constructor(...e){super(...e),this.type="tile",this.defaultParams={},this.positionRoles=[{axis:"x",role:"point",valueKind:"value"},{axis:"x",role:"min",valueKind:"value"},{axis:"x",role:"max",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"min",valueKind:"value"},{axis:"y",role:"max",valueKind:"value"}],this.supportedPositions=["identity"],this.supportedCoordTypes=["cartesian"],this.aesthetics=[{kind:"visual",name:"color",required:!0}],this.scaleConstraints={discreteMainAxis:!0,discreteCrossAxis:!0,bandPadding:0},this.grid={cartesian:{hideGridX:!0,hideGridY:!0}},this.legend={suppressWhenSingleItem:!1},this.dataLabels={cartesian:{showDataLabels:!0}},this.dataLabelCoordTypes=["cartesian"],this.highlightStrategy="observation-rerender",this.spatialKind="cells",this.identityKey="x-y",this.tooltip=[{aes:"color"}],this.resolveValueSource=th,this.resolveAnchorPosition=t=>{const r=G(t),n=U(t),a=k(t),i=_(t);return r===null||n===null||a===null||i===null?null:{x:(r+n)/2,y:(a+i)/2}}}compile({data:e}){return{data:e.addConstantVariable(l.POSITION_VARIABLES.xMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.xMax,"numeric",.5).addConstantVariable(l.POSITION_VARIABLES.yMin,"numeric",-.5).addConstantVariable(l.POSITION_VARIABLES.yMax,"numeric",.5),mapping:{}}}},nh=[new jp,new Qp,new Jp,new Hp,new eh,new rh],rr=class extends l.Registry{constructor(){super("geom");for(const e of nh)this.register(e.type,e)}},Re=class{compute(e){return e.data.size()===0?{data:e.data,mapping:{}}:this.computeStat(e)}},ah=class extends Re{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,...Je(e,t)])];return{data:e.groupBy(...n).rollup({[l.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:l.STAT_VARIABLES.count}}}},ih=class extends Re{constructor(...e){super(...e),this.type="identity",this.computedVariables=new Set}computeStat({data:e}){return{data:e,mapping:{}}}},sh=class extends Re{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}}}},oh=2,Ts=1440*60*1e3,lh=class extends Re{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=Je(e,t),u=fh(a,s,i,c,e);return c.length===0?Fa({data:e,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:{},xScaleIsDiscrete:n}):e.groupBy(...c).forEach(d=>{const m=gh(d,c);Fa({data:d,xVariable:a,xType:s,yVariable:i,spec:r,output:u,groupObservation:m,xScaleIsDiscrete:n})}),{data:u.build(),mapping:{}}}},Fa=({data:e,xVariable:t,xType:r,yVariable:n,spec:a,output:i,groupObservation:s,xScaleIsDiscrete:o})=>{const{observations:c,temporalOrigin:u}=ch({data:e,xVariable:t,yVariable:n,xType:r});c.length<oh||(o?hh({observations:c,spec:a,output:i,groupObservation:s}):mh({observations:c,xType:r,temporalOrigin:u,spec:a,output:i,groupObservation:s}))},ch=({data:e,xVariable:t,yVariable:r,xType:n})=>{const a=e.getValues(t),i=e.getValues(r,{type:"numeric"}),s=n==="temporal"?uh(a):null,o=[],c=new Map;for(let u=0;u<a.length;u++){const d=a[u],m=i[u];if(!l.isDefined(d)||!l.isDefined(m)||!Number.isFinite(m))continue;const h=dh({xValue:d,xType:n,categoryRank:c,temporalOrigin:s});h!==null&&o.push({x:h,y:m,originalX:d})}return{observations:o,temporalOrigin:s}},uh=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},dh=({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)/Ts+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}`})}},mh=({observations:e,xType:t,temporalOrigin:r,spec:n,output:a,groupObservation:i})=>{const s=Ls(n,e);for(const[o,c]of s){if(!Number.isFinite(o)||!Number.isFinite(c))continue;const u=t==="temporal"?ph(o,r):o;a.push({x:u,y:c,groupObservation:i})}},ph=(e,t)=>t===null?new Date(e):new Date((e-1)*Ts+t),hh=({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=Ls(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=ws(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})}},Ls=(e,t)=>e.method==="loess"?(0,pe.regressionLoess)().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):ws(e,t),ws=(e,t)=>{const r=a=>a.x,n=a=>a.y;switch(e.method){case"linear":return(0,pe.regressionLinear)().x(r).y(n)(t);case"exponential":return(0,pe.regressionExp)().x(r).y(n)(t);case"logarithmic":return(0,pe.regressionLog)().x(r).y(n)(t);case"quadratic":return(0,pe.regressionQuad)().x(r).y(n)(t);case"power":return(0,pe.regressionPow)().x(r).y(n)(t);case"polynomial":return(0,pe.regressionPoly)().x(r).y(n).order(e.order)(t);case"loess":throw new l.InternalError({message:"'loess' does not expose a 'predict' function"})}},fh=(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)}}},gh=(e,t)=>{const r={};for(const n of t)r[n]=e.getValues(n)[0]??null;return r},yh=class extends Re{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],...Je(e,t)])];return{data:e.groupBy(...a).rollup({[l.STAT_VARIABLES.sum]:{variableName:r,aggregation:"sum"}}),mapping:{y:l.STAT_VARIABLES.sum}}}},vh=[new ih,new ah,new lh,new sh,new yh],bh=class extends l.Registry{constructor(){super("stat");for(const e of vh)this.register(e.type,e)}};function Sh({geoms:e,stats:t,transforms:r}){const n=new rr,a=new bh,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 In(e){if("definition"in e)return e.definition;if(Vs(e)||Rs(e)||Cs(e))return e}function Es(e){const t=[],r=[],n=[];for(const a of e){const i=In(a);i&&(Vs(i)?t.push(i):Rs(i)?r.push(i):Cs(i)&&n.push(i))}return{geoms:t,stats:r,transforms:n,warnings:[...Sr("geom",t,a=>a.type),...Sr("stat",r,a=>a.type),...Sr("transform",n,a=>a.transformType),...xh(t),...Ah(t)]}}function xh(e){const t=[];for(const r of e)r.spatialKind==="render-hit-test"&&(r.identityKey!=="x-group"&&r.identityKey!=="x-y"||t.push({code:"RENDER_HIT_TEST_IDENTITY",message:`The render-hit-test geom '${r.type}' uses the position-derived '${r.identityKey}' 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 Ah(e){const t=[];for(const r of e)r.spatialKind!=="cells"||!r.supportedCoordTypes.includes("polar")||t.push({code:"SPATIAL_KIND_COORD_UNSUPPORTED",message:`The geom '${r.type}' declares polar support, but its 'cells' hit-test shape has no polar projection; its observations will not respond to hover under polar coords.`,context:{kind:"geom",requested:r.type},suggestion:"Drop 'polar' from 'supportedCoordTypes', or declare 'rects' as the spatial kind so a bandless polar layer hit-tests as an enclosure."});return t}function Sr(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 Vs=e=>e instanceof ae,Rs=e=>e instanceof Re,Cs=e=>"transformType"in e&&typeof e.apply=="function",Ih=class{constructor(e){this.registry=e}adjust(e,t){return this.registry.get(e).adjust(t)}},nr=class{},Th=class extends nr{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=Lh(e)??[-.7/2,.7/2],s=r.length>1?zp:0,o=(0,Q.scaleBand)().domain(r.map(String)).range(i).paddingInner(s).paddingOuter(0),c=o.bandwidth(),u=new Array(n).fill(null),d=new Array(n).fill(null);for(let m=0;m<n;m++){const h=a[m];if(!l.isDefined(h))continue;const p=o(String(h));l.isDefined(p)&&(u[m]=p,d[m]=p+c)}return{data:e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",u).addVariable(l.POSITION_VARIABLES.xMax,"numeric",d),mapping:{}}}},Lh=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]},$a=l.prefixInternalVariable("__ungrouped__"),Ds=(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?[$a]:a,o=e.getValues(r),c=e.getValues(n,{type:"numeric"}),u=e.getValues(l.GROUP_VARIABLES.group,{type:"categorical"}),d=e.size(),m=new Map;for(let h=0;h<d;h++){const p=l.getStableKey(o[h]??null),f=u[h],g=i?$a:f;if(!l.isDefined(g))continue;let y=m.get(p);y||(y=new Map,m.set(p,y));let v=y.get(g);v||(v=[],y.set(g,v)),v.push(h)}return{yValues:c,observationIndicesByXAndGroup:m,uniqueGroupKeys:s,observationCount:d}},_s=(e,t,r,n)=>{const a=new Array(n).fill(null);for(const[,i]of r){const s=[];let o=-1,c=1/0,u=-1/0,d=-1,m=1/0,h=-1/0;for(const p of i.values())for(const f of p){const g=e[f],y=t[f];!l.isDefined(g)||!l.isDefined(y)||(s.push(f),(g<c||g===c&&y>u)&&(o=f,c=g,u=y),(y>h||y===h&&g<m)&&(d=f,m=g,h=y))}for(const p of s)a[p]=wh(p===o,p===d)}return a},wh=(e,t)=>e&&t?"solo":e?"floor":t?"ceiling":"middle",Eh=class extends nr{constructor(...e){super(...e),this.type="fill"}adjust({data:e,mapping:t}){const r=Ds(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,d]of a){let m=0,h=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];x!=null&&(x>=0?m+=x:h-=x)}}let p=0,f=0;for(const g of i){const y=d.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x===void 0)continue;if(x===null){c[v]=null,o[v]=null;continue}const I=x>=0?m:h;if(I===0){c[v]=0,o[v]=0;continue}const A=x/I;x>=0?(c[v]=p,o[v]=p+=A):(o[v]=f,c[v]=f+=A)}}}const u=_s(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:{}}}},Vh=class extends nr{constructor(...e){super(...e),this.type="identity"}adjust({data:e}){return{data:e,mapping:{}}}},Rh=class extends nr{constructor(...e){super(...e),this.type="stack"}adjust({data:e,mapping:t}){const r=Ds(e,t);if(r===null)return{data:e,mapping:{}};const{yValues:n,observationIndicesByXAndGroup:a,uniqueGroupKeys:i,observationCount:s}=r,o=[...n],c=new Array(s).fill(0);for(const[,h]of a){let p=0,f=0;for(const g of i){const y=h.get(g);if(y!==void 0)for(const v of y){const x=n[v];if(x!==void 0){if(x===null){c[v]=null,o[v]=null;continue}x>=0?(c[v]=p,o[v]=p+=x):(o[v]=f,c[v]=f+=x)}}}}const u=_s(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:{}}}},Ch=class extends l.Registry{constructor(){super("position"),this.register("identity",new Vh),this.register("stack",new Rh),this.register("fill",new Eh),this.register("dodge",new Th)}},Dh=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)||gn(s.aes))continue;const o=l.extractVariableName(t.mapping[s.aes]);if(!l.isDefined(o)||!a.hasVariable(o))continue;const c=r(ls(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}},_h=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)}},Oh=class{map({data:e,getPositionScale:t}){const r=t("x");if(!r?.bandwidth||!e.hasVariable(l.POSITION_VARIABLES.x)||!e.hasVariable(l.POSITION_VARIABLES.xMin)||!e.hasVariable(l.POSITION_VARIABLES.xMax))return e;const n="reverse"in r.spec&&r.spec.reverse===!0,a=e.getValues(l.POSITION_VARIABLES.x,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),s=e.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),o=e.size(),c=new Array(o),u=new Array(o);for(let d=0;d<o;d++){const m=a[d],h=i[d],p=s[d];if(l.isDefined(m)&&l.isDefined(h)&&l.isDefined(p)){const f=n?-p:h,g=n?-h:p;c[d]=m+f*r.bandwidth,u[d]=m+g*r.bandwidth}else c[d]=null,u[d]=null}return e.addVariable(l.POSITION_VARIABLES.xMin,"numeric",c).addVariable(l.POSITION_VARIABLES.xMax,"numeric",u)}},kh=class{map({data:e,layer:t,getPositionScale:r}){const n=l.extractVariableName(t.mapping.y),a=r(oe(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)}},Ph=class{map({data:e,layer:t,getPositionScale:r}){const n=r(oe(t.yScaleType));if(!n||!e.hasVariable(l.POSITION_VARIABLES.yMin)||!e.hasVariable(l.POSITION_VARIABLES.yMax))return e;const a=n.bandwidth,i=l.isDefined(a)&&e.hasVariable(l.POSITION_VARIABLES.y)?Mh(e,n,a):Nh(e,n);return e.addVariable(l.POSITION_VARIABLES.yMin,"numeric",i.min).addVariable(l.POSITION_VARIABLES.yMax,"numeric",i.max)}};function Mh(e,t,r){const n=e.getValues(l.POSITION_VARIABLES.y,{type:"numeric"}),a=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),i=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),s="reverse"in t.spec&&t.spec.reverse===!0,o=e.size(),c=Os(o);for(let u=0;u<o;u++){const d=n[u],m=a[u],h=i[u];!l.isDefined(d)||!l.isDefined(m)||!l.isDefined(h)||(c.min[u]=d+(s?-h:m)*r,c.max[u]=d+(s?-m:h)*r)}return c}function Nh(e,t){const r=e.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),n=e.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),a=e.size(),i=Os(a);for(let s=0;s<a;s++){const o=r[s],c=n[s];!l.isDefined(o)||!l.isDefined(c)||(i.min[s]=t.map(o),i.max[s]=t.map(c))}return i}function Os(e){return{min:new Array(e).fill(null),max:new Array(e).fill(null)}}var Bh=[new _h,new kh,new Oh,new Ph,new Dh];function Fh(e,t){const r=e[t];return r?.kind==="position"?r:null}var $h=class extends Ee{constructor(e,t=Bh){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=>Fh(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}}},Gh=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=P(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})}}Ss(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"?oe(n.yScaleType):i,c=a.get(i)??(os(o)?o:void 0);if(!l.isDefined(c)||!t.has(c))continue;const u=t.get(c)?.scaleType,d=this.resolveVariables(i,s,n.data,u);this.collectFromVariables(n.data,d,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)||gn(n.aes)||t.set(n.aes,ls(n.axis,e.yScaleType));return t}resolveVariables(e,t,r,n){if(e==="y"&&n!=="discrete"&&this.hasPositionAdjustedY(r))return[l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];const a=l.extractVariableName(t);return!a||!r.hasVariable(a)?[]:[a]}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)}},Uh=["rgb","lab","hcl","hsl"],Wh=["viridis","magma","inferno","plasma","cividis","turbo","Blues","Greens","Greys","Oranges","Purples","Reds"],ks=["RdBu","BrBG","PuOr","Spectral"],Ps={"red-blue":"RdBu","brown-teal":"BrBG","purple-orange":"PuOr",spectral:"Spectral"},Hh=new Set(ks.map(e=>e.toLowerCase()));function Ms(e){const t=e.toLowerCase(),r=Ps[t];return r?r.toLowerCase():t}function Kh(e){return Hh.has(Ms(e))}var zh={rgb:Ne.interpolateRgb,lab:Ne.interpolateLab,hcl:Ne.interpolateHcl,hsl:Ne.interpolateHsl},Yh={viridis:O.interpolateViridis,magma:O.interpolateMagma,inferno:O.interpolateInferno,plasma:O.interpolatePlasma,cividis:O.interpolateCividis,turbo:O.interpolateTurbo,blues:O.interpolateBlues,greens:O.interpolateGreens,greys:O.interpolateGreys,oranges:O.interpolateOranges,purples:O.interpolatePurples,reds:O.interpolateReds,rdbu:O.interpolateRdBu,brbg:O.interpolateBrBG,puor:O.interpolatePuOr,spectral:O.interpolateSpectral};function Tn(e){const t=jh(e);return e.reverse?r=>t(1-r):t}function qh(e={},t=2){const r=Tn({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 jh(e){const t=zh[e.interpolate];if(e.range&&e.range.length>=2)return(0,Ne.piecewise)(t,e.range.map(r=>String(r)));if(e.scheme){const r=Yh[Ms(e.scheme)];if(r)return r}return(0,Ne.piecewise)(t,[...l.DEFAULT_SEQUENTIAL_RAMP])}var lt=class{createPositionScale(e,t){return{kind:"position",aesthetic:P(e.scaledAesthetic),spec:e,...t}}createVisualScale(e,t){return{kind:"visual",aesthetic:P(e.scaledAesthetic),spec:e,...t}}},Xh=class extends lt{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=Ve(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"&&Zh(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:P(r.scaledAesthetic),scaleType:r.scaleType,actual:e},suggestion:"Filter out non-positive values or set a positive domainMin so the log scale can apply."});const i=a?(0,Q.scaleLog)():r.transform==="sqrt"?(0,Q.scaleSqrt)():(0,Q.scaleLinear)();r.nice&&!a&&(n=i.copy().domain(n).nice().domain());const s=r.domainMin??n[0],o=r.domainMax??n[1];return i.domain([s,o]).range(t).clamp(r.clamp)}buildPositionScale(e,t){const r=t.reverse?[1,0]:[0,1],n=this.createD3Scale(e,r,t);return this.createPositionScale(t,{map:n,domain:n.domain(),bandwidth:null,generateTicks:a=>a&&"count"in a?n.ticks(a.count):n.ticks()})}buildVisualScale(e,t){const r=Jh(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=Tn(t),n=t.domainMid;if(n!==null){const[a,i]=this.resolveColorDomain(e,t);if(n>a&&n<i){const[s,o]=this.symmetrizeDomain([a,i],t,n);return this.buildDivergingColorScale([s,n,o],t,r)}}return this.buildSequentialColorScale(e,t,r)}buildSequentialColorScale(e,t,r){const n=this.createD3Scale(e,[0,1],t),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:n.domain(),generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}buildDivergingColorScale(e,t,r){const n=(0,Q.scaleLinear)().domain(e).range([0,.5,1]).clamp(t.clamp),a=i=>typeof i!="number"||!Number.isFinite(i)?null:r(n(i));return this.createVisualScale(t,{map:a,domain:e,generateTicks:i=>i&&"count"in i?n.ticks(i.count):n.ticks()})}resolveColorDomain(e,t){let r=t.domainMin??e[0],n=t.domainMax??e[1];if(t.nice){const a=(0,Q.scaleLinear)().domain([r,n]).nice().domain();r=t.domainMin??a[0],n=t.domainMax??a[1]}return[r,n]}symmetrizeDomain(e,t,r){if(!t.symmetric)return e;const n=Math.max(Math.abs(e[0]-r),Math.abs(e[1]-r));return[t.domainMin??r-n,t.domainMax??r+n]}},Zh=e=>{const[t,r]=e;return t>0&&r>0||t<0&&r<0};function Jh(e){if(!e)return null;const[t,r]=e;return typeof t=="number"&&typeof r=="number"?[t,r]:null}var Qh=class extends lt{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=Ve(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=ef(e)?e:[],a=(0,Q.scaleUtc)().domain(n).range(t).clamp(r.clamp);if(r.nice&&a.nice(),l.isDefined(r.domainMin)||l.isDefined(r.domainMax)){const[i,s]=a.domain();i!==void 0&&s!==void 0&&a.domain([r.domainMin??i,r.domainMax??s])}return a}buildScale(e,t,r){const n=t.reverse?[1,0]:[0,1],a=this.createD3Scale(e,n,t),[i,s]=a.domain(),o=i&&s?r.filter(c=>c>=i&&c<=s):[];return this.createPositionScale(t,{map:a,domain:a.domain(),bandwidth:null,generateTicks:c=>c&&"atInputs"in c?o:c&&"interval"in c?i&&s?Tm(i,s,c.interval):[]:a.ticks(c?.count)})}},ef=e=>e.length===2&&l.isStrictTemporalDataValue(e[0])&&l.isStrictTemporalDataValue(e[1]),tf=class extends lt{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=Ve(e.scaledAesthetic),n=is(t,e);return r?this.buildPositionScale(n,e):this.buildVisualScale(n,e)}buildPositionScale(e,t){const r=e.map(String),n=t.padding??l.DISCRETE_SCALE_DEFAULTS.padding,a=t.reverse?[1,0]:[0,1],i=(0,Q.scaleBand)().domain(r).range(a).paddingInner(n).paddingOuter(n/2),s=i.bandwidth()/2;return this.createPositionScale(t,{map:o=>(i(String(o))??NaN)+s,domain:e,bandwidth:i.bandwidth(),generateTicks:()=>[...e]})}buildVisualScale(e,t){const r=e.map(String),n=t.range&&t.range.length>0?(0,Q.scaleOrdinal)().domain(r).range(t.range).unknown(t.range[0]):null;return this.createVisualScale(t,{map:a=>{const i=String(a);return n?n(i):i},domain:e,generateTicks:()=>e})}},rf=class extends lt{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:P(e.scaledAesthetic),spec:e,map:t=>t,domain:[],generateTicks:()=>[]}}},nf=class extends lt{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=as(t),n=l.resolvePaletteRange(e.palette,r.length),a=l.applyOverrides(n.length>0?n:[...l.DEFAULT_COLOR_PALETTE],e.overrides),i=(0,Q.scaleOrdinal)().domain(r.map(String)).range(a).unknown(a[0]);return this.createVisualScale(e,{map:s=>i(String(s)),domain:r,generateTicks:()=>r})}},af=class extends l.Registry{constructor(e){super("scale"),this.register("continuous",new Xh(e)),this.register("discrete",new tf),this.register("datetime",new Qh),this.register("identity",new rf),this.register("palette",new nf)}},Ct={color:null,size:"small",labelCrossPosition:.5},he={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},xr={zOrder:"foreground",fit:"contain",opacity:1},sf={x:8,y:8,unit:"px"},Dt={align:"center",backgroundColor:null,backgroundColorStyle:"opaque"},fe={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},of={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}},lf=(e,t,r)=>{const n=cf(e,t),a=mf(n);return{differenceArrows:(n.differenceArrows??[]).map(i=>hf(e,i,r)).filter(l.isDefined),shapes:(n.shapes??[]).map(i=>vf(e,i,a)).filter(l.isDefined),arrows:(n.arrows??[]).map(i=>xf(e,i,r,a)).filter(l.isDefined),textAnnotations:(n.textAnnotations??[]).map(i=>pf(e,i,r,a)).filter(l.isDefined),stickers:(n.stickers??[]).map(i=>ff(e,i,r,a)).filter(l.isDefined),images:(n.images??[]).map(i=>bf(e,i,a)).filter(l.isDefined),pinnedNumbers:(n.pinnedNumbers??[]).map(i=>gf(e,i,r)).filter(l.isDefined),comments:(n.comments??[]).map(i=>yf(e,i,r)).filter(l.isDefined)}},cf=(e,t)=>{if(t===void 0)return{};if(!uf(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:M()}):(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))}},uf=e=>{const t=new Set;for(const r of df(e))if(r.id!==void 0){if(t.has(r.id))return!0;t.add(r.id)}return!1},df=e=>[...e.differenceArrows??[],...e.shapes??[],...e.arrows??[],...e.textAnnotations??[],...e.images??[],...e.stickers??[],...e.pinnedNumbers??[],...e.comments??[]],mf=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},pf=(e,t,r,n)=>{const a=Ut(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),content:t.content,at:a,width:t.width,align:t.align??Dt.align,backgroundColor:t.backgroundColor??Dt.backgroundColor,backgroundColorStyle:t.backgroundColorStyle??Dt.backgroundColorStyle}},hf=(e,t,r)=>{const n=nt(e,t.start,r),a=nt(e,t.end,r);return n===null||a===null?null:{id:t.id??M(),start:n,end:a,label:t.label,color:t.color??Ct.color,size:t.size??Ct.size,labelCrossPosition:t.labelCrossPosition??Ct.labelCrossPosition}},nt=(e,t,r)=>{const n=t.align!==void 0?{align:t.align}:{};return t.layerId===void 0?{anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:r.some(a=>a.id===t.layerId)?{layerId:t.layerId,anchorValue:t.anchorValue,groupValue:t.groupValue,crossValue:t.crossValue,...n}:(e.diagnostics.addWarning({code:"UNKNOWN_LAYER_ID",message:`Annotation references layerId "${t.layerId}", which no layer carries — dropping this annotation.`,context:{layerId:t.layerId,available:r.map(a=>a.id)},suggestion:"Reference an existing layer id, or omit layerId to anchor against the data directly."}),null)},Ut=(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=nt(e,t,r);return i===null?null:{anchorType:"observation",...i,...t.offset!==void 0?{offset:t.offset}:{}}},ff=(e,t,r,n)=>{const a=Ut(e,t.at,r,n,t.id);return a===null?null:{id:t.id??M(),at:a,sticker:t.sticker}},gf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n}},yf=(e,t,r)=>{const n=nt(e,t.at,r);return n===null?null:{id:t.id??M(),at:n,content:t.content}},vf=(e,t,r)=>t.region.anchorType==="annotation"&&!Ln(e,t.region.ref,r,t.id)?null:{id:t.id??M(),kind:t.kind??he.kind,zOrder:t.zOrder??he.zOrder,region:Sf(t.region),fillColor:t.fillColor===void 0?he.fillColor:t.fillColor,fillOpacity:t.fillOpacity??he.fillOpacity,strokeWidth:t.strokeWidth??he.strokeWidth,strokeColor:t.strokeColor??he.strokeColor},bf=(e,t,r)=>t.region.anchorType==="annotation"&&!Ln(e,t.region.ref,r,t.id)?null:{id:t.id??M(),src:t.src,zOrder:t.zOrder??xr.zOrder,region:t.region,fit:t.fit??xr.fit,opacity:t.opacity??xr.opacity},Sf=e=>e.anchorType!=="selection"||e.padding!==void 0?e:{...e,padding:sf},Ga=e=>{if(e.anchorType==="panel"||e.anchorType==="axis"||e.offset!==void 0||e.align===void 0)return e;const t=of[e.align];return t===void 0?e:{...e,offset:{x:t.x*4,y:t.y*4,unit:"px"}}},xf=(e,t,r,n)=>{const a=Ut(e,t.start,r,n,t.id),i=Ut(e,t.end,r,n,t.id);return a===null||i===null?null:{id:t.id??M(),start:Ga(a),end:Ga(i),color:t.color??fe.color,thickness:t.thickness??fe.thickness,startArrowheadStyle:t.startArrowheadStyle??fe.startArrowheadStyle,endArrowheadStyle:t.endArrowheadStyle??fe.endArrowheadStyle,lineStyle:t.lineStyle??fe.lineStyle,hasStickerStyle:t.hasStickerStyle??fe.hasStickerStyle}},Af={parsingLocale:"en-US",legend:{position:"auto",display:"auto",align:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{overflow:{dataLabels:{x:"inside",y:"inside"},differenceArrows:{x:"outside",y:"outside"}}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1,brandMark:{enabled:!1,placement:"footer",variant:"full"},isBrandMarkVisible:!1},appearance:{textScale:1},layout:{padding:null,gaps:{}}};function If(e){const t=(0,je.merge)({},Af,e);return t.content=Tf(t.content,e?.content),t}var Tf=(e,t)=>{const r=t?.brandMark?.enabled??t?.isBrandMarkVisible??e.brandMark.enabled,n={...e.brandMark,enabled:r};return{...e,brandMark:n,isBrandMarkVisible:r}},Lf={xLimits:null,yLimits:null},_t={theta:"x",startAngle:0,innerRadius:0};function Kr(e){const t=e??{type:"coord",coordType:"cartesian"},r=(0,Mt.default)({},Lf,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:r};case"polar":return{...t,params:{...r,theta:t.params?.theta??_t.theta,startAngle:t.params?.startAngle??_t.startAngle,innerRadius:(0,Ge.default)(t.params?.innerRadius??_t.innerRadius,0,1)}}}}function wf(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??M(),predicate:a.predicate,scope:a.scope??"data-point",...a.layerId!==void 0?{layerId:a.layerId}:{}})}return n}var Ef=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=Ua(e.filter(n=>n.severity==="error")),r=Ua(e.filter(n=>n.severity==="warning"));return this.diagnostics=[],{errors:t,warnings:r}}},Vf=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 Ua(e){const t=new Set;return e.filter(r=>{const n=JSON.stringify(r);return t.has(n)?!1:(t.add(n),!0)})}var Rf={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 Ns(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 Ce(e,t,r,n,a,i){const s=a!==void 0&&i!==void 0?new Vf(a,{layerIndex:i}):a,o=e.get(n.geom),c=n.position??o.defaultPosition,u=_f({dataLabels:kf(e,t,n,c,r),geom:o,position:c,coordType:r,diagnostics:s});return Df({diagnostics:s,coordType:r,geom:o,position:c,dataLabels:u}),{id:n.id??M(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Ns(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 Cf(e,t,r,n,a){const i=n.map((s,o)=>Ce(e,t,r,s,a,o));return Fs(e,i)}var Bs=(e,t,r,n)=>n.label!==void 0?n.label:Ki({geom:e.get(t),position:r,mapping:n,purpose:"label"}),Fs=(e,t)=>{const r=new Set;for(const n of t)n.position==="fill"&&r.add(n.yScaleType);return r.size===0?t:Xe(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,je.clamp)(a,0,1);return i===a?n:{...n,mapping:{...n.mapping,y:{value:i}}}})},Df=({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&&B(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."})},_f=({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=Of(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}},Of=(e,t,r)=>r==="polar"?"Panel-edge anchors do not apply under polar coords":e.type==="bar"&&B(t)?"Stacked bar segments would all pin their labels to the same panel edge":null,kf=(e,t,r,n,a)=>{const i={...t,...r.mapping},s=Bs(e,r.geom,n,i),o=e.get(r.geom);return{...(0,je.merge)({},Rf,o.resolveDataLabelDefaults?.(n)??{},o.dataLabels?.[a]??{},r.dataLabels??{}),labelSource:s}},$s={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},Pf={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"palette","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Gs(e,t){const{data:r,layers:n,mapping:a,customPalettes:i}=t;return{container:e,data:r,layers:n,mapping:a,customPalettes:i,demands:Wr(e.geomRegistry,n)}}function wn(e,t){switch(t.scaleType){case"inferred":return wn(e,Ff(e,t));case"continuous":{const r=$s[t.scaledAesthetic],n=r==="continuous-range"&&t.scaledAesthetic in l.NON_POSITION_RANGE_DEFAULTS?l.NON_POSITION_RANGE_DEFAULTS[t.scaledAesthetic]:null,a=t.scaledAesthetic==="size"&&r==="continuous-range"?"sqrt":l.CONTINUOUS_SCALE_DEFAULTS.transform;return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,transform:t.transform??a,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??r!=="position",domainMin:t.domainMin??l.CONTINUOUS_SCALE_DEFAULTS.domainMin,domainMax:t.domainMax??l.CONTINUOUS_SCALE_DEFAULTS.domainMax,range:t.range??n??null,scheme:$f(e.container,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 zr(t,e.demands);case"palette":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType,palette:l.resolvePaletteConfig(e.container,t.palette,e.customPalettes),overrides:l.resolvePaletteOverrides(e.container,t.overrides,t.palette,e.customPalettes)};case"identity":return{type:t.type,scaledAesthetic:t.scaledAesthetic,scaleType:t.scaleType};default:throw new l.InternalError({message:`Unknown scale type: ${t.scaleType}`})}}function Mf(e,t){const{scales:r,layers:n,coords:a}=t,i=Wf(Uf(r,n)),s=new Map;for(const u of i)s.set(u.scaledAesthetic,u);const o=Gs(e,t),c=[...s.values()].map(u=>{const d=Nf(o,u);return wn(o,d)});return a.coordType==="polar"?c.map(Us):c}function zr(e,t){const r=t?.bandPadding[e.scaledAesthetic];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??r??l.DISCRETE_SCALE_DEFAULTS.padding,reverse:e.reverse??Bf(e.scaledAesthetic,t)}}var Us=e=>e.scaleType==="discrete"?{...e,padding:0}:e;function Nf(e,t){return t.scaleType==="inferred"||t.scaleType==="discrete"||!e.demands.bandedAxes.includes(t.scaledAesthetic)?t:(e.container.diagnostics.addWarning({code:"UNSUPPORTED_SCALE_TYPE",message:`A geom drawn on '${t.scaledAesthetic}' needs it to be a band scale, but the spec declares a '${t.scaleType}' one; the band wins.`,context:{aesthetic:P(t.scaledAesthetic),scaleType:t.scaleType},suggestion:`Declare '${t.scaledAesthetic}' as a discrete scale, or omit it and let the geom's band be inferred.`}),l.discrete(t.scaledAesthetic,{..."reverse"in t&&t.reverse!==void 0&&{reverse:t.reverse}}))}function Bf(e,t){return e===t?.discreteCrossAxis?!0:l.DISCRETE_SCALE_DEFAULTS.reverse}function Ff({data:e,layers:t,mapping:r,demands:n},a){const i=P(a.scaledAesthetic),s=a.scaledAesthetic==="ySecondary"?Gf(t,r):r[i];if(a.scaledAesthetic===n.discreteAxis||a.scaledAesthetic===n.discreteCrossAxis)return l.discrete(a.scaledAesthetic,a.options);const o=n.zeroAxes[a.scaledAesthetic];if(o!==void 0){const m=a.options;return l.continuous(a.scaledAesthetic,{...m,zero:!0,...!o.nice&&{nice:!1}})}const c=l.extractVariableName(s);if(!l.isDefined(c)||!e.hasVariable(c))return l.continuous(a.scaledAesthetic,a.options);const u=e.getType(c),d=$s[a.scaledAesthetic];switch(Pf[u][d]){case"discrete":return l.discrete(a.scaledAesthetic,a.options);case"palette":return l.palette(a.scaledAesthetic);case"datetime":return l.datetime(a.scaledAesthetic,a.options);case"continuous":return l.continuous(a.scaledAesthetic,a.options);default:return l.identity(a.scaledAesthetic)}}function $f(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:P(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:P(t.scaledAesthetic),scaleType:t.scaleType,actual:r},suggestion:"Set 'domainMid' (e.g. 0) to centre the neutral colour."}),r)}function Gf(e,t){const r=e.find(n=>n.yScaleType==="secondary");return r?r.mapping.y??t.y:t.y}function Uf(e,t){return!t.some(r=>r.yScaleType==="secondary")||e.some(r=>r.scaledAesthetic==="ySecondary")?e:[...e,l.inferred("ySecondary")]}function Wf(e){return e.some(t=>t.scaledAesthetic==="color")?e:[...e,l.palette("color")]}var Hf=e=>{const t=new Set;e!==void 0&&Ws(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},Ws=(e,t,r)=>{if(!r.has(e)){r.add(e);for(const n of e.extends??[])Ws(n,t,r);t.delete(e),t.add(e),r.delete(e)}};function Kf(e,t,r){const n=Kr(t.coords),a=Cf(e.geomRegistry,t.mapping,n.coordType,t.layers,e.diagnostics),i=Mf(e,{data:t.data,scales:t.scales,layers:a,mapping:t.mapping,coords:n,customPalettes:r}),s=If(t.config),o=wf(e,t.highlights,a),c=lf(e,t.annotations,a),u=Hf(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 Hs=class{constructor(e){this.container=e}compile({input:e,dataset:t,customPalettes:r}){return Kf(this.container,{...e,data:t},r)}},zf=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})}},Yf=class extends Ee{constructor(e){super(),this.container=e}compile(e){const t=super.compile(e);for(const r of og(e.styles,t))this.container.diagnostics.addWarning(r);for(const r of lg(e.styles))this.container.diagnostics.addWarning(r);for(const r of cg(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=Js({layer:e,layerIndex:t.layers.indexOf(e),styles:t.styles,parsingLocale:t.config.parsingLocale});return{...e,styles:r}}},Be={color:"color",alpha:"unitInterval",saturation:"unitInterval"},Ks={bar:{...Be,borderRadius:"radiusToken",borderColor:"color",borderWidth:"pixels"},line:{...Be,strokeWidth:"pixels",lineType:"lineType",fillAlpha:"unitInterval"},area:{...Be,strokeWidth:"pixels",lineType:"lineType",strokeAlpha:"unitInterval"},point:{...Be,size:"pixels",borderColor:"color",borderWidth:"pixels"},rule:{color:"color",strokeWidth:"pixels",lineType:"lineType"}},Wa=1,Ha=1e3,qf="'none' or a shadow object { offsetX, offsetY, blur, color }",At={color:"color",strokeWidth:"pixels",lineType:"lineType"},It={fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier",textColor:"color"},ge={panelBorder:{...At,borderRadius:"pixels"},panelBorderEdge:At,gridLine:At,tickLine:{...At,length:"pixels"},axisLabel:It,tickLabel:{...It,offset:"pixels"},ruleLabel:{fontFamily:"fontFamily",fontSize:"pixels",fontWeight:"fontWeight",lineHeight:"multiplier"},dataLabel:{...It,paddingInline:"pixels",paddingBlock:"pixels",background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels"},graph:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",fontFamily:"fontFamily"},tooltip:{background:"color",borderColor:"color",borderWidth:"pixels",borderRadius:"pixels",paddingInline:"pixels",paddingBlock:"pixels",shadow:"shadow"},tooltipText:It,tooltipPrimaryRow:{background:"color"}},jf=new Set([...Object.keys(Be),...Object.values(Ks).flatMap(e=>Object.keys(e??{})),...Object.values(ge).flatMap(e=>Object.keys(e))]),zs=["geom","panelBorder","gridLine","tickLine","axisLabel","tickLabel","ruleLabel","dataLabel","graph","tooltip"],Xf=new Set(["gridLine","tickLine","axisLabel","tickLabel"]),Zf=(e,t,r="en-US")=>Js({layer:e,layerIndex:0,styles:{tokens:t.tokens??{},defaults:t.defaults??[],overrides:t.overrides??[]},parsingLocale:r}),Jf=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 Ys(e.styles)}},Ys=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:[]},tooltip:{defaults:[],overrides:[]},warnings:t},a=(i,s,o,c)=>{if(ar(i))return;const u=i.id===void 0?{}:{styleEntryId:i.id},d=i.select.target;if(!Qf(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 ${zs.map(p=>`'${p}'`).join(", ")}.`});return}if(i.when!==void 0){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} ignored: chrome entries take no conditions.`,context:{param:"when",...u},suggestion:"Remove the 'when' clause — chrome is chart-scoped, with no observations or states."});return}const m=i.select;if(m.target==="panelBorder"){const p=m.edge;if(p!==void 0&&!tg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown edge '${String(p)}'.`,context:{param:"edge",actual:String(p),...u},suggestion:`Set 'edge' to one of ${l.PANEL_BORDER_EDGES.map(f=>`'${f}'`).join(", ")}.`});return}}if(Xf.has(m.target)){const p=m.axis;if(p!==void 0&&!ig(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown axis '${String(p)}'.`,context:{param:"axis",actual:String(p),...u},suggestion:`Set 'axis' to one of ${hn.map(f=>`'${f}'`).join(", ")}.`});return}}if(m.target==="ruleLabel"){const p=m.layer;if(p!==void 0&&typeof p!="string"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses an invalid layer ${ze(p)}.`,context:{param:"layer",actual:ze(p),...u},suggestion:"Set 'layer' to the id of a rule layer in the spec, or omit it to address every rule label."});return}}if(m.target==="tooltip"){const p=m.part;if(p!==void 0&&!ag(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown part '${String(p)}'.`,context:{param:"part",actual:String(p),...u},suggestion:`Set 'part' to one of ${l.TOOLTIP_PARTS.map(f=>`'${f}'`).join(", ")}, or omit it to address the box.`});return}}if(m.target==="dataLabel"){const p=m.role;if(p!==void 0&&!rg(p)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown role '${String(p)}'.`,context:{param:"role",actual:String(p),...u},suggestion:`Set 'role' to one of ${l.DATA_LABEL_ROLES.map(g=>`'${g}'`).join(", ")}.`});return}const f=m.position;if(f!==void 0){if(!ng(f)){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses unknown position '${String(f)}'.`,context:{param:"position",actual:String(f),...u},suggestion:`Set 'position' to one of ${l.DATA_LABEL_POSITIONS.map(g=>`'${g}'`).join(", ")}.`});return}if(p===void 0||p==="aggregate"){t.push({code:"INVALID_STYLE_RULE",message:`Style ${o} addresses a position without a positionable role.`,context:{param:"position",actual:String(f),...u},suggestion:"Set 'role' to 'observation' or 'category', or remove 'position'."});return}}}const h=En({declarations:i.declarations,vocabulary:eg(m),tokens:r,location:o,origin:c,warnings:t});Object.keys(h).length!==0&&n[m.target][s].push({select:m,declarations:h,origin:c})};return l.BUILTIN_STYLES.defaults.forEach((i,s)=>{a(i,"defaults",`builtin[${s}]`,{list:"builtin"})}),e.defaults.forEach((i,s)=>{a(i,"defaults",`defaults[${s}]`,{list:"defaults",index:s,...i.id===void 0?{}:{id:i.id}})}),e.overrides.forEach((i,s)=>{a(i,"overrides",`overrides[${s}]`,{list:"overrides",index:s,...i.id===void 0?{}:{id:i.id}})}),n},ar=e=>e.select.target==="geom",Qf=e=>{const t=e.select.target;return t!=="geom"&&zs.includes(t)},qs=e=>(e!==void 0?Ks[e]:void 0)??Be,eg=e=>e.target==="panelBorder"?e.edge===void 0?ge.panelBorder:ge.panelBorderEdge:e.target==="tooltip"?e.part===void 0?ge.tooltip:e.part==="primaryRow"?ge.tooltipPrimaryRow:ge.tooltipText:ge[e.target],tg=e=>typeof e=="string"&&l.PANEL_BORDER_EDGES.includes(e),rg=e=>typeof e=="string"&&l.DATA_LABEL_ROLES.includes(e),ng=e=>typeof e=="string"&&l.DATA_LABEL_POSITIONS.includes(e),ag=e=>typeof e=="string"&&l.TOOLTIP_PARTS.includes(e),ig=e=>typeof e=="string"&&hn.includes(e),sg=(e,t,r)=>{const n=[];return l.BUILTIN_STYLES.defaults.forEach((a,i)=>{if(!ar(a))return;const s=a.select.kind;if(s!==void 0&&s!==e)return;const o={list:"builtin"},c=En({declarations:a.declarations,vocabulary:qs(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},js=(e,t)=>{e.defaults.forEach((r,n)=>t(r,"defaults",n)),e.overrides.forEach((r,n)=>t(r,"overrides",n))},og=(e,t)=>{const r=new Set(t.map(a=>a.id)),n=[];return js(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},lg=e=>{const t=[];return js(e,(r,n,a)=>{if(!ar(r))return;const i=r.when?.state;i===void 0||Xs(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},Xs=e=>l.STYLE_STATES.includes(e),cg=e=>{const t=[];for(const[r,n]of Object.entries(e.tokens))Zs(n)||t.push({code:"INVALID_STYLE_RULE",message:`Style token '${r}' has an invalid value: ${ze(n)}.`,context:{param:"tokens",actual:ze(n)},suggestion:`Set '${r}' to a non-empty color string or a { light, dark } pair of colors.`});return t},Zs=e=>typeof e=="string"?e.trim().length>0:l.isLightDarkColor(e)&&e.light.trim().length>0&&e.dark.trim().length>0,me=e=>typeof e=="number"&&Number.isFinite(e),ze=e=>typeof e=="object"&&e!==null?JSON.stringify(e):String(e),Js=e=>{const{layer:t,layerIndex:r,styles:n,parsingLocale:a}=e,i=Jt(t,a),s=[],o={...l.BUILTIN_STYLES.tokens,...n.tokens},c=(u,d)=>{const m=[];return u.forEach((h,p)=>{if(!ar(h))return;const f=h.select.kind;if(f!==void 0&&f!==t.geom||h.select.layer!==void 0&&h.select.layer!==t.id)return;const g=h.when?.state;if(g!==void 0&&!Xs(g))return;const y={list:d,index:p,...h.id===void 0?{}:{id:h.id}},v=h.when?.where;if(v!==void 0){const I=Se(v,t.data,"style-rule");if(I.length>0){for(const A of I)s.push({...A,code:"INVALID_STYLE_RULE",message:`Style ${d}[${p}]: ${A.message}`,context:{...A.context,layerIndex:r,...h.id===void 0?{}:{styleEntryId:h.id}}});return}}const x=En({declarations:h.declarations,vocabulary:qs(f),tokens:o,location:`${d}[${p}]`,origin:y,warnings:s});Object.keys(x).length!==0&&m.push({declarations:x,...v===void 0?{}:{matches:be(v,i)},...g===void 0?{}:{state:g},origin:y})}),m};return{defaults:[...sg(t.geom,o,s),...c(n.defaults,"defaults")],overrides:c(n.overrides,"overrides"),warnings:s}},En=e=>{const{declarations:t,vocabulary:r,tokens:n,location:a,origin:i,warnings:s}=e,o={},c=i.list==="builtin"||i.id===void 0?{}:{styleEntryId:i.id},u=(p,f)=>{o[p]=f},d=(p,f,g)=>{s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: expected ${f}, got ${ze(g)}.`,context:{param:p,expected:f,actual:ze(g),...c},suggestion:`Set '${p}' to ${f}.`})},m=(p,f)=>{if(typeof f=="string"){if(f.trim().length>0)return f;d(p,"a non-empty color string",f);return}if(l.isStyleTokenRef(f)){const g=n[f.token];if(g===void 0){s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: unknown token '${f.token}'.`,context:{param:p,actual:f.token,...c},suggestion:`Declare '${f.token}' in the stylesheet's tokens.`});return}return Zs(g)?typeof g=="string"?g:{light:g.light,dark:g.dark}:void 0}if(l.isLightDarkColor(f)&&f.light.trim().length>0&&f.dark.trim().length>0)return{light:f.light,dark:f.dark};d(p,"a non-empty color string, a { light, dark } pair, or a token(...) reference",f)},h=p=>{const f=jf.has(p);s.push({code:"INVALID_STYLE_RULE",message:`Style ${a} declaration '${p}' ignored: ${f?"not in this entry's vocabulary":"not a style property"}.`,context:{param:p,...c},suggestion:f?`Declare '${p}' on an entry whose kind supports it (e.g. style.geom.bar).`:`Remove the unknown declaration '${p}'.`})};for(const p of Object.keys(t)){const f=t[p];if(f===void 0)continue;const g=r[p];if(g===void 0){h(p);continue}switch(g){case"color":{const y=m(p,f);y!==void 0&&u(p,y);break}case"unitInterval":me(f)&&f>=0&&f<=1?u(p,f):d(p,"a number in [0, 1]",f);break;case"pixels":me(f)&&f>=0?u(p,f):d(p,"a non-negative number of pixels",f);break;case"radiusToken":l.isBorderRadiusToken(f)?u(p,f):d(p,`one of ${l.BORDER_RADIUS_TOKENS.map(y=>`'${y}'`).join(", ")}`,f);break;case"lineType":Hi(f)?u(p,f):d(p,`one of ${dn.map(y=>`'${y}'`).join(", ")}`,f);break;case"fontFamily":typeof f=="string"&&f.trim().length>0?u(p,f):d(p,"a non-empty CSS font-family list",f);break;case"fontWeight":me(f)&&f>=Wa&&f<=Ha?u(p,f):d(p,`a number in [${Wa}, ${Ha}]`,f);break;case"multiplier":me(f)&&f>0?u(p,f):d(p,"a positive multiple of the font size",f);break;case"shadow":{if(f==="none"){u(p,f);break}const y=f;if(!me(y.offsetX)||!me(y.offsetY)||!me(y.blur)||y.blur<0){d(p,qf,f);break}const v=m(p,y.color);v!==void 0&&u(p,{offsetX:y.offsetX,offsetY:y.offsetY,blur:y.blur,color:v});break}default:break}}return o},ug=({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}},dg=({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=k(a),o=_(a),c=G(a),u=U(a),d=ln(a);if(!l.isDefined(i)||!l.isDefined(s)||!l.isDefined(o)||!l.isDefined(c)||!l.isDefined(u)||!l.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const h=Sn(a,t),p={yMin:s,yMax:o},f=r.get(h);if(f===void 0){r.set(h,{total:d,topPositive:m?p:null,bottomNegative:m?null:p,anchorXMin:c,anchorXMax:u});continue}f.total+=d,m?(f.topPositive===null||o>f.topPositive.yMax)&&(f.topPositive=p):(f.bottomNegative===null||s<f.bottomNegative.yMin)&&(f.bottomNegative=p)}const n=[];for(const[a,i]of r){const s=i.topPositive??i.bottomNegative;s!==null&&n.push({xKey:a,total:i.total,anchor:{xMin:i.anchorXMin,xMax:i.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:i.topPositive!==null?"positive":"negative"}})}return n},mg=class extends Ee{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=dg({layer:e});n!==void 0&&(r.stackTotals=n)}if(t.summaries.grandTotal){const n=ug({layer:e});n!==void 0&&(r.grandTotal=n.grandTotal,r.absoluteGrandTotal=n.absoluteGrandTotal)}return{...e,summary:r}}},Qs=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)}},Ka={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"},pg=["color","size","alpha","strokeWidth","lineType"],hg=class extends Ee{dependencies(e){return pg.map(t=>e.scales[t])}compileLayer(e,t){let r=e.data;const n=Object.entries(l.VISUAL_VARIABLES);for(const[a,i]of n){const s=l.extractConstantValue(e.mapping[a]);if(s!==void 0){r=r.addConstantVariable(i,Ka[a],s);continue}const o=l.extractVariableName(e.mapping[a]),c=t.scales[a];!o||!c||c.kind!=="visual"||(r=r.deriveVariableFrom(o,i,Ka[a],fg(c)))}return{...e,data:r}}},fg=e=>t=>l.isDefined(t)?e.map(t):null;function eo(e=new rr){return{diagnostics:new Ef,geomRegistry:e}}var to=class{constructor(e,t,r,n,a,i,s,o,c,u,d,m,h,p,f,g){this.container=e,this.dataCompiler=t,this.specCompiler=r,this.transformCompiler=n,this.constantMappingCompiler=a,this.layerPhasedCompiler=i,this.scaleCompiler=s,this.coordCompiler=o,this.positionMapperCompiler=c,this.visualMapperCompiler=u,this.guideCompiler=d,this.summariseCompiler=m,this.stylesCompiler=h,this.chromeStylesCompiler=p,this.highlightsCompiler=f,this.annotationsCompiler=g,this.lastCompile=null,this.lastDiagnostics=null,this.lastData=void 0,this.stages=[{name:"data",getStats:()=>this.dataCompiler.stats},{name:"transform",getStats:()=>this.transformCompiler.stats},{name:"constantMapping",getStats:()=>this.constantMappingCompiler.stats},{name:"layer",getStats:()=>this.layerPhasedCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"styles",getStats:()=>this.stylesCompiler.stats},{name:"chromeStyles",getStats:()=>this.chromeStylesCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile(e){try{const t=this.runCompile(()=>(this.lastData=e.data,this.runPipeline({spec:this.specCompiler.compile({input:e.input,customPalettes:e.customPalettes??{},dataset:this.dataCompiler.compile(e.data)})})));return this.toOkResult(t)}catch(t){return this.toErrorResult(t)}}recompile(e){try{const t=this.runCompile(()=>e.data===void 0?this.runPipeline({spec:e.spec}):(this.lastData=e.data,this.runPipeline({spec:L(e.spec,{data:this.dataCompiler.compile(e.data)})})));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:[Bi(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{...qt({spec:e}).pipe(({spec:t})=>({spec:L(t,{data:this.transformCompiler.compile({data:t.data,transforms:t.transforms})})})).pipe(({spec:t})=>{const r=this.constantMappingCompiler.compile({data:t.data,mapping:t.mapping});return{spec:L(t,{data:r.data,mapping:r.mapping})}}).pipe(({spec:t})=>({layers:this.layerPhasedCompiler.compile({data:t.data,layers:t.layers,mapping:t.mapping,coords:t.coords,scales:t.scales})})).pipe(({spec:t,layers:r})=>this.coordCompiler.setup({coordSpec:t.coords,scales:t.scales,layers:r})).pipe(({layers:t,scales:r})=>({scales:this.scaleCompiler.compile({layers:t,scales:r})})).pipe(({spec:t})=>({config:t.config})).pipe(({layers:t,scales:r})=>({layers:this.positionMapperCompiler.compile({layers:t,scales:r})})).pipe(({layers:t,scales:r})=>({layers:this.visualMapperCompiler.compile({layers:t,scales:r})})).pipe(({spec:t,layers:r,coordSystem:n})=>({layers:this.coordCompiler.transform({coordSpec:t.coords,coordSystem:n,layers:r})})).pipe(({layers:t})=>({layers:this.summariseCompiler.compile({layers:t})})).pipe(({spec:t,scales:r,layers:n,coordSystem:a})=>({guides:this.guideCompiler.compile({scales:r,config:t.config,layers:n,coordSystem:a,originalData:this.lastData})})).pipe(({spec:t,layers:r})=>({layers:this.stylesCompiler.compile({layers:r,styles:t.styles,config:t.config})})).pipe(({spec:t})=>({chrome:this.chromeStylesCompiler.compile({styles:t.styles})})).pipe(({spec:t,layers:r})=>({layers:this.highlightsCompiler.compile({layers:r,highlights:t.highlights,config:t.config})})).pipe(({spec:t,layers:r,coordSystem:n,scales:a})=>({annotations:this.annotationsCompiler.compile({annotations:t.annotations,layers:r,coordSystem:n,scales:a,config:t.config})})).result(),spec:e}}},gg=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","styles","chromeStyles","highlights","annotations"],yg=({plugins:e=[]}={})=>{const t=Es(e),{geomRegistry:r,statRegistry:n,transformRegistry:a}=Sh(t),i=eo(r),s=new af(i),o=new Qs(a);for(const c of t.warnings)i.diagnostics.addWarning(c,{persistent:!0});return new to(i,new l.DataCompiler,new Hs(i),o,new Hd,new Wp(i,o,n,new Bp(i,o,new zf(n),new ym,new gm(i),new Ih(new Ch))),new Gh(i,s),new Yd(new dm),new $h(i),new hg,new Vp(i),new mg(i),new Yf(i),new Jf(i),new Op(i),new Cd(i))};function vg(e,t){return e.geom===t}function ro(...e){let t={},r;const[n,...a]=e;l.isDefined(n)&&!bg(n)?(t=n,r=a):r=e;const i={mapping:t,layers:[],scales:[],transforms:[],highlights:[],config:{}};return r.reduce((s,o)=>ao(s,o),i)}function no(e,...t){return t.reduce((r,n)=>ao(r,n),e)}function bg(e){return typeof e=="object"&&e!==null&&"type"in e}function ao(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,Mt.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 Sg(e,t);default:throw new l.InternalError({message:`Unknown spec item type: ${t.type}`})}}function Sg(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 xg(e){const t=e?.plugins??[],r=Ig(t);return{geom:{...l.geom,...r.geom},stat:{...l.stat,...r.stat},transform:{...l.transform,...r.transform},scale:l.scale,coord:l.coord,createSpec:ro,pipe:no,plugins:t}}var Ag=e=>(t={})=>l.buildLayerInput(e,t);function Ig(e){const{geoms:t,stats:r,transforms:n}=Es(e),a={};for(const o of t)a[o.type]=Ag(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 Tg=24,Lg={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}},wg={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},rightAxis:{after:10,before:4}},Ar="…",io=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Ar)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const s=n+a>>>1;r(e.slice(0,s)+Ar)<=t?(i=s,n=s+1):a=s-1}return e.slice(0,i)+Ar};var F={timeZone:"UTC"},N=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},ce=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",Vn=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Eg=Br.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),so=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>ce(a=>{const i=typeof r.decimals=="number"?r.decimals:2,s=Dn(a,i),{base:o,suffix:c}=Cn(a,r.abbreviation),u={...s,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return`${Intl.NumberFormat(t,u).format(o)}${c}`}),oo=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const{base:a,suffix:i}=Cn(n,t.abbreviation),s={...Dn(a,t.decimals),...r};return`${Intl.NumberFormat(e,s).format(a)}${i}`}),Rn=e=>ce(t=>Eg(t)),lo=({locale:e,intlOptions:t})=>ce(r=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(r)),co=({locale:e,numberFormat:t,intlOptions:r})=>ce(n=>{const a=Dn(n,t.decimals);return Intl.NumberFormat(e,{...a,...r,style:"percent"}).format(n)}),Cn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=Vg(e);return Cn(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Dn=(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}},Vg=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"},Rg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).format(r)),Cg=({locale:e,intlOptions:t})=>N(r=>{const n=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...F,...t}).formatToParts(r);return Dg(n.map(_g))}),uo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t}).format(r)),mo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"long",...F,...t}).format(r)),_n=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...F,...t}).format(r)),On=e=>N(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),po=({locale:e,intlOptions:t})=>N(r=>{const n=(0,ki.addDays)(r,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...F,...t,year:void 0}).formatRange(r,n)}),ho=({locale:e,intlOptions:t})=>N(r=>{const n=(0,ki.addDays)(r,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...F,...t}).formatRange(r,n)}),kn=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{year:"numeric",...F,...t}).format(r)),fo=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),Dg=e=>e.map(t=>t.value).join(""),_g=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},za=1e3,Og=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>ce(a=>{const i={...Mn(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Pn(a,t,i)}),kg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Mn(n,t),notation:"compact",...r};return Pn(n,e,a)}),Pg=({locale:e,tickValues:t,intlOptions:r})=>ce(n=>{const a={...Mn(n,t),notation:"compact",...r,style:"percent"};return Pn(n,e,a)}),Pn=(e,t,r)=>Intl.NumberFormat(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),go=e=>Math.abs(e)>za?go(e/za):Number.isInteger(e),Mg=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Mn=(e,t)=>go(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:Mg(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:1},Ng=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),Bg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{month:"short",...F,...t}).format(r)),Fg=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...F,...t}).format(r)),$g=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{timeStyle:"short",...F,...t}).format(r)),Nn=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return Og(e);case"date":case"datetime":return Ng(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Fg(e);case"decimal":case"integer":return kg(e);case"duration":return Rn(e);case"month":return Bg(e);case"month_year":return _n(e);case"percentage":return Pg(e);case"quarter":return On(e);case"text":return Vn(e);case"time":return $g(e);case"year":return kn(e);case"lookup":return Nn({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Gg=.9,Ug=1/3,Wg=1/4,Hg=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Kg(e):zg(e),Kg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=yo(e.ticks,n),o=Yg(e.ticks,r.width),c=o*Gg;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(o>=50){const d=qr(c);return{...e,ticks:Yr(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(s+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=qr(r.height*Ug);return{...e,ticks:Yr(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},zg=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:s}=yo(e.ticks,n);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=qr(r.width*Wg);return i<=o?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:Yr(e.ticks,a,o,n),labelRotation:0,labelMaxWidthPx:o}},Yg=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},yo=(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}},Yr=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,s)=>(t[s]??0)<=r?i:{...i,formattedLabel:io(i.formattedLabel,r,a)})},qr=e=>Math.max(0,Math.floor(e)),qg=(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},jg=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const s=new Map,o=m=>{const h=s.get(m);if(h)return h;const p=a[m],f=p?Xg(p.ticks,n(p)):[];return s.set(m,f),f};let c=0,u=a.length-1,d=-1;for(;c<=u;){const m=c+u>>>1;qg(o(m).map(h=>h.formattedLabel),i,t,r)?(d=m,c=m+1):u=m-1}return d>=0?o(d):o(0)},Xg=(e,t)=>e.map(r=>({...r,formattedLabel:t(r.value)})),Ya=.5,ct=e=>({x:0,y:0,width:e.width,height:e.height}),Bn=e=>e==="panel-end"?"end":e==="panel-start"?"start":e,ut=({box:e,panel:t,frame:r,placement:n,justify:a,align:i,offset:s,alignOffset:o,labelWidth:c,labelHeight:u})=>{const d=a==="panel-start"||a==="panel-end",m=(r.valueAxis==="x"?e.height:e.width)===0,h={anchor:Jg(a,r.valueDirectionSign),placement:d?"inside":n,offset:s},p={anchor:Qg(i),placement:m?n:"inside",offset:m?o??s:0},f=d?t:e,g=r.valueAxis==="x"?f:e,y=r.valueAxis==="y"?f:e,v=r.valueAxis==="x"?h:p,x=r.valueAxis==="x"?p:h,I=ja(v,{min:g.x,max:g.x+g.width,halfExtent:c/2}),A=ja(x,{min:y.y,max:y.y+y.height,halfExtent:u/2});return{x:I,y:A,position:Zg(e,I,A,c,u)}},qa=(e,t,r,n)=>r-n>=e-Ya&&r+n<=t+Ya,Zg=(e,t,r,n,a)=>{if(e.width===0&&e.height===0)return"outside";const i=e.width===0||qa(e.x,e.x+e.width,t,n/2),s=e.height===0||qa(e.y,e.y+e.height,r,a/2);return i&&s?"inside":"outside"},Jg=(e,t)=>e==="center"?"center":(e==="end"||e==="panel-end")==(t===1)?"max":"min",Qg=e=>e==="center"?"center":e==="start"?"min":"max",ja=({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},ey=(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}}},ty=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=ny(e.layer);for(const a of e.layer.data){const i=R(a),s=_(a)??w(a);if(i===null||s===null||!We(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}=ey(s,k(a),i,e.panelRect.width,e.panelRect.height),h=ut({box:d,panel:ct(e.panelRect),frame:m,...n,offset:r,labelWidth:c,labelHeight:u});t.push({layerId:e.layer.id,x:h.x,y:h.y,text:o,width:c,height:u,isRotated:!1,target:"observation",position:"outside"})}return t},ry={place:ty,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"none"},ny=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Bn(r):r,align:n}},Fn=(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")}}},Tt=6,ay=e=>{const t=[],r=B(e.layer.position),n=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:i}=sy({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"?cy({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}):uy(e.layer.dataLabels,e.coordSystem.mainAxis,r,s,ct(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 dy(e,r))t.push(a);if(e.layer.dataLabels.showStackTotals){const a=fy({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},iy={place:ay,getPercentageValueStrategy:e=>e.position==="fill"?"fill":B(e.position)?"stack":"absoluteGrandTotal"},sy=({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=bo(t,d);if(m===null)continue;const h=a(d);if(h==="")continue;const p=Fn(n,"observation",h),f=$n(m,r);c&&p.inside.width>f.width&&(o=!0);const g=u===null?null:d[u],y=l.isStrictNumericDataValue(g)&&g<0;s.push({isNegative:y,text:h,boxes:p,bounds:f})}return{entries:s,shouldRotate:!i&&o}},$n=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),vo=(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}},bo=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(t);return r===null||n===null||a===null||i===null?null:vo(e,r,n,a,i)},oy=(e,t)=>{const{xMin:r,xMax:n,yMin:a,yMax:i}=t.anchor;return vo(e,r,n,a,i)},ly=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",jr=(e,t,r)=>r?{width:t,height:e}:{width:e,height:t},cy=e=>e.isStacked?my({bounds:e.bounds,box:e.boxes.inside,isRotated:e.shouldRotate}):hy({edge:ly(e.mainAxis,e.isNegativeBar),bounds:e.bounds,boxes:e.boxes,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight,offset:e.offset}),So=(e,t)=>e==="x"?{valueAxis:"y",valueDirectionSign:t?1:-1}:{valueAxis:"x",valueDirectionSign:t?-1:1},uy=(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=ut({box:n.bounds,panel:a,frame:So(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}},dy=(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=ct(e.panelRect),d=l.extractVariableName(e.layer.mapping.y);for(const m of e.layer.data){const h=bo(c,m);if(h===null)continue;const p=e.formatCategory(m);if(p===null||p==="")continue;const f=Fn(e.measureDataLabel,"category",p),g=f[o],y=$n(h,e.panelRect),v=d===null?null:m[d],x=l.isStrictNumericDataValue(v)&&v<0,I=ut({box:y,panel:u,frame:So(c,x),placement:o,justify:a,align:i,offset:s,labelWidth:g.width,labelHeight:g.height}),A=f[I.position];r.push({layerId:e.layer.id,x:I.x,y:I.y,text:p,width:A.width,height:A.height,isRotated:!1,target:"category",position:I.position})}return r},my=({bounds:e,box:t,isRotated:r})=>{const n=jr(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"}},py=(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}}},hy=({edge:e,bounds:t,boxes:r,isRotated:n,panelWidth:a,panelHeight:i,offset:s})=>{const o=e==="top"||e==="bottom",c=t.x+t.width/2,u=t.y+t.height/2,d=o?t.height:t.width,m=o?t.width:t.height,{edgeCoord:h,outwardSign:p,panelExtent:f}=py(e,t,a,i),g=jr(r.inside.width,r.inside.height,n),y=o?g.height:g.width,v=o?g.width:g.height;if(y+s<d){if(v>m)return null;if(n)return{x:c,y:u,isRotated:!0,position:"inside"};const V=h-p*(y/2+s);return{...o?{x:c,y:V}:{x:V,y:u},isRotated:!1,position:"inside"}}const x=jr(r.outside.width,r.outside.height,n),I=(o?x.height:x.width)/2,A=h+p*(I+s);return A-I<0||A+I>f?null:{...o?{x:c,y:A}:{x:A,y:u},isRotated:n,position:"outside"}},fy=({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=$n(oy(t,c),r),d=a(c.total),{width:m,height:h}=n("aggregate","outside",d),p=c.anchor.direction==="positive";let f,g;o?(f=p?u.x+u.width+Tt+m/2:u.x-Tt-m/2,g=u.y+u.height/2):(f=u.x+u.width/2,g=p?u.y-Tt-h/2:u.y+u.height+Tt+h/2),i.push({layerId:e.id,x:f,y:g,text:d,width:m,height:h,isRotated:!1,target:"aggregate",position:"outside"})}return i},gy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=vy(e.layer);for(const a of e.layer.data){const i=R(a),s=w(a);if(i===null||s===null||!We(i,s))continue;const o=e.formatLabel(a);if(o==="")continue;const{width:c,height:u}=e.measureDataLabel("observation","outside",o),d=ut({box:{x:i*e.panelRect.width,y:(1-s)*e.panelRect.height,width:0,height:0},panel:ct(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},yy={place:gy,getPercentageValueStrategy:()=>"none"},vy=e=>{const{position:t,justify:r,align:n}=e.dataLabels;return t==="auto"?{placement:"outside",justify:"end",align:"center"}:{placement:t,justify:er(e.data,e.mapping)?Bn(r):r,align:n}};function dt(e){return e[l.VISUAL_VARIABLES.color]}function xo(e){return e[l.VISUAL_VARIABLES.alpha]}function Gn(e){return e[l.VISUAL_VARIABLES.size]}function Xr(e){return e[l.VISUAL_VARIABLES.strokeWidth]}function Ao(e){return e[l.VISUAL_VARIABLES.lineType]}var by={color:dt,alpha:xo,strokeWidth:Xr,lineType:Ao,size:Gn,borderWidth:Xr},ir=(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=Ay(o.styles,t);return r.set(o,u),u},chromeReaders:o=>{const c=n.get(o);if(c!==void 0)return c;const u=Sy(o,t);return n.set(o,u),u},explain:(o,c,u,d)=>{if(d!==void 0){const f=rt(o.styles.overrides,c,u,d,t);if(f!==void 0)return{value:f.value,tier:"override",origin:f.origin,state:d};const g=rt(o.styles.defaults,c,u,d,t);if(g!==void 0)return{value:g.value,tier:"default",origin:g.origin,state:d}}const m=rt(o.styles.overrides,c,u,void 0,t);if(m!==void 0)return{value:m.value,tier:"override",origin:m.origin};const h=Io(c,u);if(h!==void 0)return{value:h,tier:"data"};const p=rt(o.styles.defaults,c,u,void 0,t);return p!==void 0?{value:p.value,tier:"default",origin:p.origin}:{value:void 0,tier:"unresolved"}}}},Sy=(e,t)=>{const r=(c,u)=>{const d=p=>Xa(c.overrides,p,u)??Xa(c.defaults,p,u);return{get:p=>{const f=d(p)?.declarations[p];if(f!==void 0)return xy(f,t)},getSource:p=>{const f=d(p);return f===void 0?"unresolved":f.origin.list==="builtin"?"builtin":"authored"}}},n=c=>r(e.panelBorder,u=>{const d=u.select.target==="panelBorder"?u.select.edge:void 0;return d===void 0||d===c}),a=c=>u=>r(e[c],d=>d.select.target!==c?!1:d.select.axis===void 0||d.select.axis===u),i=c=>r(e.ruleLabel,u=>u.select.target!=="ruleLabel"?!1:u.select.layer===void 0||u.select.layer===c),s=(c,u)=>r(e.dataLabel,d=>d.select.target!=="dataLabel"||d.select.role!==void 0&&d.select.role!==c?!1:d.select.position===void 0||d.select.position===u),o=c=>r(e.tooltip,u=>u.select.target==="tooltip"&&u.select.part===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),tooltip:{box:o(void 0),heading:o("heading"),label:o("label"),value:o("value"),primaryRow:o("primaryRow")}}},Xa=(e,t,r)=>{for(let n=e.length-1;n>=0;n--){const a=e[n];if(!(a===void 0||!r(a))&&a.declarations[t]!==void 0)return a}},xy=(e,t)=>{if(l.isLightDarkColor(e))return e[t];if(typeof e=="object"&&"offsetX"in e){const{offsetX:r,offsetY:n,blur:a,color:i}=e;return{offsetX:r,offsetY:n,blur:a,color:l.isLightDarkColor(i)?i[t]:i}}return e},Ay=(e,t)=>({get:(n,a,i)=>{if(i!==void 0){const c=Lt(e.overrides,n,a,i,t);if(c!==void 0)return c;const u=Lt(e.defaults,n,a,i,t);if(u!==void 0)return u}const s=Lt(e.overrides,n,a,void 0,t);if(s!==void 0)return s;const o=Io(n,a);return o!==void 0?o:Lt(e.defaults,n,a,void 0,t)}}),Lt=(e,t,r,n,a)=>rt(e,t,r,n,a)?.value,rt=(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&&Iy(s,r))return{value:Ty(o,a),origin:s.origin}}},Iy=(e,t)=>e.matches===void 0?!0:t!==void 0&&e.matches(t),Ty=(e,t)=>l.isLightDarkColor(e)?e[t]:e,Io=(e,t)=>{const r=by[e];if(!(r===void 0||t===void 0))return r(t)??void 0},Ly=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{offset:r}=e.layer.dataLabels,n=Ey(e.layer),a=n.justify==="panel-start"||n.justify==="panel-end",i=ir().geomReaders(e.layer);for(const s of e.layer.data){const o=R(s),c=w(s);if(o===null||c===null||!We(o,c))continue;const u=e.formatLabel(s);if(u==="")continue;const{width:d,height:m}=e.measureDataLabel("observation","outside",u),h=i.get("size",s)/2,p=ut({box:{x:o*e.panelRect.width,y:(1-c)*e.panelRect.height,width:0,height:0},panel:ct(e.panelRect),frame:{valueAxis:"y",valueDirectionSign:-1},...n,offset:a?r:r+h,alignOffset:r+h,labelWidth:d,labelHeight:m});t.push({layerId:e.layer.id,x:p.x,y:p.y,text:u,width:d,height:m,isRotated:!1,target:"observation",position:p.position})}return t},wy={place:Ly,getPercentageValueStrategy:()=>"none"},Ey=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}},To=e=>{const t=G(e),r=U(e),n=k(e),a=_(e);if(t===null||r===null||n===null||a===null)return null;const i=Math.min(t,r),s=Math.abs(r-t),o=Math.max(n,a),c=Math.abs(a-n);return{x:i,y:1-o,width:s,height:c}},Lo=e=>{const t=To(e);if(!t)return null;const r=t.width*Yp,n=t.height*qp;return{x:t.x+r,y:t.y+n,width:t.width-r*2,height:t.height-n*2}},Za=4,Vy=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const r=ir().geomReaders(e.layer);for(const n of e.layer.data){const a=Lo(n);if(a===null||!dt(n))continue;const i=e.formatLabel(n);if(i==="")continue;const{width:s,height:o}=e.measureDataLabel("observation","inside",i),c=a.width*e.panelRect.width,u=a.height*e.panelRect.height;s+Za>c||o+Za>u||t.push({layerId:e.layer.id,x:(a.x+a.width/2)*e.panelRect.width,y:(a.y+a.height/2)*e.panelRect.height,text:i,width:s,height:o,isRotated:!1,target:"observation",position:"inside",backdropColor:r.get("color",n)})}return t},Ry={place:Vy,getPercentageValueStrategy:()=>"none"};function Un(e){return{startAngle:e[l.POSITION_VARIABLES.xMin],endAngle:e[l.POSITION_VARIABLES.xMax]}}function Wn(e){return{innerRadius:e[l.POSITION_VARIABLES.yMin],outerRadius:e[l.POSITION_VARIABLES.yMax]??e[l.POSITION_VARIABLES.y]}}var Cy=" · ",Ir=2,at=(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)},Dy=({wedge:e,labelRadius:t,labelAngle:r,labelWidth:n,labelHeight:a})=>{const i=at("radial",r,n,a);if(!(t-i>=e.innerRadiusPx-Ir&&t+i<=e.outerRadiusPx+Ir)||t<=0)return!1;const s=Math.abs(e.endAngle-e.startAngle)/2,o=at("tangential",r,n,a)/t,c=Ir/t;return Math.abs(r-e.midAngle)+o<=s+c},_y=({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,Oy=({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+at("radial",e.midAngle,n,a),labelAngle:e.midAngle,position:"outside"},ky=({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+at("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=at("tangential",o,i,s)/u;d=o+(n==="start"?1:-1)*m}return{labelRadius:u,labelAngle:d,position:Dy({wedge:e,labelRadius:u,labelAngle:d,labelWidth:i,labelHeight:s})?"inside":"outside"}},Py=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const{position:r,justify:n,align:a,offset:i,showCategoryLabels:s}=e.layer.dataLabels,o=e.coordSystem.bandAxis==="y"?"inside":"outside",c=e.panelRect.width/2,u=e.panelRect.height/2,d=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const m of e.layer.data){const{startAngle:h,endAngle:p}=Un(m),{innerRadius:f,outerRadius:g}=Wn(m);if(h===null||p===null||g===null)continue;const y=e.formatLabel(m);if(y==="")continue;const v=s?e.formatCategory(m):null,x=v===null?y:`${v}${Cy}${y}`,I={startAngle:h,endAngle:p,midAngle:(h+p)/2,innerRadiusPx:(f??0)*d,outerRadiusPx:g*d};let A,V;if(r==="auto"){const z=e.measureDataLabel("observation",o,x);V={width:z.width,height:z.height},A=Oy({wedge:I,position:o,offset:i,labelWidth:V.width,labelHeight:V.height})}else{const z=Fn(e.measureDataLabel,"observation",x),T=z[r];A=ky({wedge:I,placement:r,justify:Bn(n),align:a,offset:i,labelWidth:T.width,labelHeight:T.height}),V=z[A.position]}const j=c+Math.sin(A.labelAngle)*A.labelRadius,ie=u-Math.cos(A.labelAngle)*A.labelRadius;r==="auto"&&!_y({x:j,y:ie,labelWidth:V.width,labelHeight:V.height,panelRect:e.panelRect})||t.push({layerId:e.layer.id,x:j,y:ie,text:x,width:V.width,height:V.height,isRotated:!1,target:"observation",position:A.position})}return t},My={place:Py,getPercentageValueStrategy:()=>"absoluteGrandTotal"},Ny=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 so(e);case"date":return Rg(e);case"datetime":return Cg(e);case"day_month":return uo(e);case"decimal":return oo(e);case"duration":return Rn(e);case"integer":return lo(e);case"month":return mo(e);case"month_year":return _n(e);case"percentage":return co(e);case"quarter":return On(e);case"text":return Vn(e);case"weekly_date_range":return po(e);case"weekly_date_range_with_year":return ho(e);case"year":return kn(e);case"time":return fo(e);case"lookup":return Ny({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Hn({layer:e,numberFormat:t,locale:r}){return C({valueFormat:ud(e),locale:r,numberFormat:t})}var By=(e,t)=>{const r=l.extractVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:Ze(e,t),variable:r}:{read:K,variable:l.GROUP_VARIABLES.group}},wo=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,formattingLocale:s,percentageValueStrategy:o})=>{const c=Hn({layer:e,numberFormat:n,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,formatLabel:Wy({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:c,percentageValueStrategy:o}),formatAbsolute:c,formatCategory:Fy({layer:e,numberFormat:n,locale:s})}},Fy=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=By(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)}},$y=(e,t)=>{switch(t){case"stack":return Gy(e);case"fill":return Uy(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Gy=e=>{const t=l.extractVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const s=a[t];if(s==null)return null;const o=r?.get(Sn(a,t));return o===void 0?null:o.total}},Uy=e=>{const t=Zt(e);return r=>{const n=k(r),a=_(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}},Wy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i})=>{const s=W(e.data,e.dataLabels.labelSource),o=$y(e,i),c=Hy({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),u=C({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),d=e.dataLabels.format==="percentage"&&Eo(e);return m=>{const h=s(m);if(h===null)return"";if(!d||!l.isStrictNumericDataValue(h))return c(h,m);const p=o(m);return p===null||p===0?c(h,m):u(h/p)}},Hy=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,s=l.extractVariableName(i);if(s!==null){if(Eo(e))return a;const o=Ky(e,r,t,n,s);if(o!==null)return o}return C({valueFormat:zy(e.data,i),locale:n,numberFormat:t})},Eo=e=>{const t=l.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.extractVariableName(Xt(e.position,e.mapping))},Ky=(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})},zy=(e,t)=>{const r=l.extractConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.extractVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},Kn={bar:{cartesian:iy,polar:My},line:{cartesian:yy},point:{cartesian:wy},area:{cartesian:ry},tile:{cartesian:Ry}},Yy=(e,t)=>Kn[e]?.[t]!==void 0,qy=({layers:e,coordSystem:t,axes:r,numberFormat:n,parsingLocale:a,panelRect:i,measureDataLabel:s,formattingLocale:o,plotBottomY:c,isFooterChromeReserved:u})=>{const d=[],m=o??a,h=t.type;for(const p of e){if(!p.dataLabels.showDataLabels&&!p.dataLabels.showStackTotals&&!p.dataLabels.showCategoryLabels)continue;const f=p.geom,g=Kn[f]?.[h];if(g===void 0)continue;const y=wo({layer:p,coordSystem:t,axes:r,numberFormat:n,panelRect:i,measureDataLabel:s,formattingLocale:m,percentageValueStrategy:g.getPercentageValueStrategy(p)}),v=g.place(y);for(const x of v)jy(x,h,c,u)||d.push(x)}return{labels:d}},jy=(e,t,r,n)=>t==="polar"&&n&&e.position==="outside"&&e.y+e.height/2>r;function*Xy({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,locale:s}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const o of e){if(!o.dataLabels.showDataLabels&&!o.dataLabels.showStackTotals)continue;const c=Kn[o.geom]?.cartesian;if(c===void 0)continue;const u=wo({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 Tr={abbreviation:"none",decimals:"auto"},Vo=({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:Tr,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:Tr,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:Tr,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},Lr=6,wr=6,Er=15,Vr=5,Rr=15,Ro=(e,t)=>{switch(e){case"small":return{arrowStartGap:Lr,arrowEndGap:wr,offsetFromHigherObservation:Er,arrowheadSize:Vr,curveRadius:Rr,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Lr*1.5,arrowEndGap:wr*1.5,offsetFromHigherObservation:Er*1.25,arrowheadSize:Vr*1.5,curveRadius:Rr*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Lr*2,arrowEndGap:wr*2,offsetFromHigherObservation:Er*1.75,arrowheadSize:Vr*2.5,curveRadius:Rr*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Zy=(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},Jy=(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}
|
|
5
5
|
L ${c.x-d*i} ${c.y}
|
|
6
6
|
Q ${c.x} ${c.y} ${c.x} ${c.y+i}
|
|
7
7
|
L ${u.x} ${u.y}
|
|
8
|
-
`},
|
|
8
|
+
`},Qy=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const s={x:e.x+n,y:e.y},o={x:r,y:e.y},c={x:r,y:t.y},u={x:t.x+a,y:t.y},d=t.y>e.y?1:-1;return`
|
|
9
9
|
M ${s.x} ${s.y}
|
|
10
10
|
L ${o.x-i} ${o.y}
|
|
11
11
|
Q ${o.x} ${o.y} ${o.x} ${o.y+d*i}
|
|
12
12
|
L ${c.x} ${c.y-d*i}
|
|
13
13
|
Q ${c.x} ${c.y} ${c.x-i} ${c.y}
|
|
14
14
|
L ${u.x} ${u.y}
|
|
15
|
-
`},
|
|
15
|
+
`},ev=(e,t,{arrowEndGap:r,arrowheadSize:n})=>e?`
|
|
16
16
|
M ${t.x+r+n} ${t.y-n}
|
|
17
17
|
L ${t.x+r} ${t.y}
|
|
18
18
|
L ${t.x+r+n} ${t.y+n}
|
|
@@ -20,4 +20,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Yu=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
|
-
`,rv=(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},nv=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),Co=({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=Ro(e.size,a),d=Jy(s,o,c,u),m=(s?ev:Qy)(o,c,d,u),h=tv(s,c,u),p=rv(s,o,c,d,nv(s,o,c),e.labelCrossPosition),f=Vo({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:h,labelPosition:p,labelText:f,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*av({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!We(s.start.x,s.start.y)||!We(s.end.x,s.end.y))continue;const o=Co({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 iv=e=>{const t=e.padding,r=Ja(e.rows,t?.top??0,t?.bottom??0),n=Ja(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:cv(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},sv=e=>{const t=Qa(e.rows,e.height),r=Qa(e.cols,e.width),n=ei(t),a=ei(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=ti(r,s.col,c),h=ti(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,h)})}return i},Ja=(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;Zr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(ov(o));const c=lv(e,s);if(Zr(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}},ov=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Zr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,lv=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Zr(n))return n}},cv=(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},Qa=(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)},ei=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},ti=(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},Ye={top:0,right:0,bottom:0,left:0},Do={outer:Ye,inner:Ye},uv={top:24,right:24,bottom:24,left:24},dv=(e,t,r,n=Ye,a=Do,i=uv,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=ri(wg,s),d=ri(Eg,s);return iv({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"},...pv(r.axes),...hv(r.axesLabels,r.axes),...fv(r.legends)],containerSize:e,padding:i})},mv=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Cr(t,e.after)}:{before:Cr(t.before,e.before),after:Cr(t.after,e.after)}:e,Cr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,ri=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=mv(e[n],t[n]);return r},pv=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},hv=(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},fv=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 gv=class{constructor(e){this.outer={...Ye},this.inner={...Ye},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)))}},yv=["top","right","bottom","left"],Dr=(e,t)=>{const r={};for(const n of yv){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function ni(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Jr=["large","medium","small"],vv=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Jr)if(r(n)<=t)return n;return"small"},bv=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:Jr.indexOf(e);for(const a of Jr.slice(n))if(r(a)<=t)return a;return null},Sv=({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},xv=({headline:e,containerSize:t,measurer:r})=>{if(_o(e))return 0;const n=Oo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},Av=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(_o(e)){const o=Iv(t.panel,e.innerRadius),c=bv({size:e.size,availableWidth:o.width,measureStripWidth:ko(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=Oo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=Sv({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},_o=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Iv=(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}},Oo=(e,t,r)=>vv({size:e.size,availableWidth:t,measureStripWidth:ko(e,r)}),ko=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Pe={x:0,y:0,width:0,height:0},Tv="0000",Lv=3,et=e=>typeof e=="number"&&Number.isFinite(e)?e:24,wv=e=>e.plot.y+e.plot.height-e.panel.y,Ev=e=>{if(typeof e=="object"&&e!==null)return{top:et(e.top),right:et(e.right),bottom:et(e.bottom),left:et(e.left)};const t=et(e);return{top:t,right:t,bottom:t,left:t}},Vv=class{constructor(e){this.measurer=e}compile(e){return qt({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Do,panelBorder:e.panelBorder??Ye,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:Ev(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:Rv(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=>ai(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=>ai(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:wv(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new gv(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of av({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 Zy({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 ni(i.inner,n.inner)&&ni(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 h=t,p=s;for(let f=0;f<Lv;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,p);if(g===p)break;p=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}return h}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?ii(r,a,0,0):ii(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=P(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:Tv}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=P(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=Xg({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?Kg({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=sv(dv(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Pe,headline:u.get("headline")??Pe,footer:u.get("footer")??Pe,plot:u.get("plot")??Pe,panelFrame:u.get("panelFrame")??Pe,panel:u.get("panel")??Pe,axes:Dr(u,"Axis"),axisLabels:Dr(u,"AxisLabel"),legends:Dr(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:xv({headline:e,containerSize:t,measurer:this.measurer})}},ai=e=>e==="left"||e==="right",ii=(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}}},Rv=(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=Nn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},Cv=(e=[])=>{const t=Dv(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,createLayerMeasurement:r=>t.has(r.geom)?zi(r,t.get(r.geom)):null}},Dv=e=>{const t=new rr;for(const r of e){const n=In(r);n instanceof ae&&t.register(n.type,n)}return t};function _v(e){return e}function ne(e){return 1-e}var ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Po=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:ne(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}},Ov=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 wt(e);const{x:s,y:o}=Qr(e.defer,this.panelRect);return wt({...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=it(r,e.defer.align),{x:a,y:i}=kv(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 wt(e);const{x:i,y:s}=Qr(e.defer,this.panelRect);return wt({...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:Pv(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:si(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=Pi(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:oi(r)}case"differenceArrow":return si(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return oi(t.annotation.at)}}},Qr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),kv=(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}=Qr({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}},Pv=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),si=(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)}),oi=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),wt=e=>{const t={...e};return delete t.defer,t},Mv=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!Nv(t))return t;const o=new Ov(t,r,n,a),c={...t,shapes:tt(t.shapes,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),images:tt(t.images,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),arrows:tt(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const h=o.resolvePoint(m.start),p=o.resolvePoint(m.end);return h===null||p===null?null:{...m,start:h,end:p}}),textAnnotations:tt(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}}),stickers:tt(t.stickers,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},tt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Nv=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),Bv=800,li=400,Fv={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}}},$v=e=>Math.max(1,(e-li)/(Bv-li)+1),Gv=(e,t)=>{const r=$v(t),n=Fv[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},Et=Math.PI/4,en=1.5,Uv=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,ci=(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-Et)} ${c-r*Math.sin(u-Et)} M ${o} ${c} L ${o-r*Math.cos(u+Et)} ${c-r*Math.sin(u+Et)}`},Wv=(e,t)=>e==="solid"?null:`${t*en} ${t*en*2}`,Hv=(e,t)=>t?e*en:0,Kv=64,zv=({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}=Gv(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=Yv(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:Uv(n),startArrowheadPath:c?ci("start",n,o):"",endArrowheadPath:u?ci("end",n,o):"",color:e.color,strokeWidth:a,dashArray:Wv(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:Hv(a,c),arrowheadExtent:d}},Yv=(e,t)=>Math.min(e,t*e/Kv);function qv(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=jv(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 jv(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 Mo=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),Xv=0,Zv=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:Mo(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:Xv})),Jv=9,Qv=8,eb=2,No=e=>typeof e=="string"?e:Bo(e),Bo=e=>e.text!==void 0?e.text:e.content?e.content.map(Bo).join(""):"",ui={top:"bottom",bottom:"top",right:"left",left:"right"};function tb(e,t,r){return r.type==="polar"?ab(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function tn(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 di(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function rb(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 nb(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 ab(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,ui[s],o,ui[o]]}function ib(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:h}=d;return mi(m,"pinned-number",h,s(d),i,n,a)}),...r.map(({id:d,at:m,content:h})=>mi(d,"comment",m,No(h),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(pi(n,d,"top"));continue}const m=pi(n,d,ob(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function mi(e,t,r,n,a,i,s){const o=Po(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:sb(o,i)}}function sb(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function ob(e,t,r,n){const a=tb(t.anchorPx,e,r);for(const i of a){const s=tn(t.anchorPx,i,t.mini);if(di(s,e)&&!n.some(o=>nb(s,o)))return i}for(const i of a)if(di(tn(t.anchorPx,i,t.mini),e))return i;return"top"}function pi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:rb(e,tn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var lb=({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}},cb=(e,t,r,n)=>e!==null?e:t.anchor.layerId!==r.anchor.layerId||!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||n.start===void 0||n.start!==n.end?null:n.start,ub=100,db=({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,h=d.y-a;if(m>h){s=!0,i=!0;const p=(m-h)/2+1;u.y-=p,d.y+=p,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>ub)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}},mb=(e,t)=>{const r=Yi(e),n=hb(t,pb(e),r);if(n===null)return null;const a=fb(e,n,r)?gb(e,t,n,r):n,[i]=a;return i===void 0?null:a.length===1?i:{and:a}},pb=e=>{const t=Je(e.data,e.mapping),r=we(e);return r===l.GROUP_VARIABLES.group?[...new Set(t)]:[...new Set([r,...t])]},hb=(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},fb=(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},gb=(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}]},zn=(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},yb=(e,t)=>{for(const r of t)if(zn(e,r.shape))return r;return null},vb=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},bb=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>Sb(r,t[n])),Sb=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&xb(e.shape,t.shape)&&Ab(e.tooltip,t.tooltip),xb=(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},Ab=(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},Ib=100,Tb=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:Ib}),Lb=(e,t)=>zn(e,{kind:"circle",center:t.center,radius:t.radius}),wb=(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&&Eb(e.target,t.target),Eb=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,Vb=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Jt(e,n),i=Rb(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||Se(s.predicate,e.data).length>0)return!1;const o=be(s.predicate,a);return o(r)?!0:_p(s.scope)&&i(s.scope).some(o)})},Rb=(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=Gt(a,t,r),o=[];for(const c of e.data)Gt(a,c,r)===s&&o.push(c);return n.set(a,o),o}},Ot=({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?Db(c,s):c;if(u<0||u>=s)break;const d=e.data.getAt(u);if(d===null||!n(d,u))continue;const m=st(e,d);if(m!==null&&!a.some(h=>Fe(m,h)))return{anchor:m,observation:d,observationIndex:u}}return null},Fo=(e,t,r)=>{const n=Yt(e);let a=0;for(const i of e.data){if(Cb(i,t,r,n))return a;a+=1}return-1},Cb=(e,t,r,n=null)=>l.areDataValuesEqual(e[r]??null,t.anchorValue)?n!==null?t.crossValue===void 0||l.areDataValuesEqual(e[n]??null,t.crossValue):t.groupValue===void 0?!0:l.areDataValuesEqual(K(e),t.groupValue):!1,Fe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),Db=(e,t)=>(e%t+t)%t,$o=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.identityKey==="x-y")return null;const n=we(e),a=Fo(e,t,n),i=e.data.getAt(a);if(i===null)return null;const s=K(i),o=h=>l.areDataValuesEqual(K(h),s),c=[t],u=Ot({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=Ot({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=Ot({layer:e,excluding:c,from:0,step:1,accepts:h=>!o(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},_b=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=st(r,n);if(a===null)continue;const i=$o({layer:r,at:a,coordSystem:e.coordSystem});if(i!==null&&!t.some(s=>Ob(s,i)))return i}return null},Ob=(e,t)=>Fe(e.start,t.start)&&Fe(e.end,t.end)||Fe(e.start,t.end)&&Fe(e.end,t.start),kb=(e,t)=>{const r=e.find(a=>a.id===t.anchor.layerId);if(r===void 0)return null;const n=r.data.getAt(t.observationIndex);return n===null?null:{layer:r,observation:n}},Pb=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:s})=>{const o=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(o===null)return null;const c=s??e.createLayerMeasurement(t);if(c===null)return null;const u=Zi(t,r,c);if(u===null)return null;const d=st(t,r);return d===null?null:{...o,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Mb=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const s=we(e),o=Fo(e,t,s),c=e.data.getAt(o);if(c===null)return null;const u=Nb(c),d=n==="main"?u:p=>!u(p)&&l.areDataValuesEqual(p[s]??null,t.anchorValue),m=Ot({layer:e,excluding:[t,r],from:o+a,step:a,accepts:(p,f)=>d(p)&&i(p,f)!==null,cycles:n!=="main"});if(m===null)return null;const h=i(m.observation,m.observationIndex);return h===null?null:{...m,point:h}},Nb=e=>{const t=K(e);return r=>l.areDataValuesEqual(K(r),t)};function Bb({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 Fb=({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"?$b(e,s,r):Gb(e,t,s,r,i)},$b=(e,t,r)=>({kind:"grandTotal",value:C({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),Gb=(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=Nn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Kb(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:Hb(o.observationLabel,d),comparison:Ub(o.comparison,d,i,a)}})}},Ub=(e,t,r,n)=>e===null?null:{direction:Wb(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},Wb=e=>e>0?"up":e<0?"down":"flat",Hb=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Kb=(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}},zb=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>Yb(i,a,t))},Yb=(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 Yn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function qb(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var jb=({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?un:Ze)(r.data,r.mapping)(a);return s===null?null:C({valueFormat:Yn(e,i?oe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},Xb=12,Zb=4,Jb=4,Qb=12,eS=4,tS=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:_r([Vt("value","value",t??"–"),Vt("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:iS(n),segments:_r([nS(n),aS(n),Vt("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:_r([rS(a),Vt("label","label",i)])}].filter(s=>s.segments.length>0)},Vt=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},rS=e=>e===null?null:{kind:"swatch",swatch:e,size:12},nS=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},aS=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},iS=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}`}},_r=e=>e.filter(t=>t!==null),sr=e=>e==="catmull-rom"?Ie.curveCatmullRom:Ie.curveLinear,sS=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},oS=(e,t)=>{const r=sr(t.interpolate),n=(0,Ie.area)().curve(r),a=(0,Ie.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ne(w(c)??0),s=c=>G(c)??0,o=c=>U(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=>ne(k(c)??0),o=c=>ne(_(c)??w(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>R(s)!==null&&w(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},lS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),qn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},Go=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return qn[e.borderRadius??"sm"]},cS=e=>{const t=Go(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},uS=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Uo=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(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}},Wo=(e,t)=>e==="x"?`${Y(t.x)}-${Y(t.width)}`:`${Y(t.y)}-${Y(t.height)}`,dS=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}},mS=e=>{const t=(0,Ie.line)().x(r=>R(r)??0).y(r=>ne(w(r)??0)).curve(sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ho),t},pS=e=>{const t=(0,Ie.area)().x(r=>R(r)??0).y0(()=>1).y1(r=>ne(w(r)??0)).curve(sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ho),t},hS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),Ho=e=>R(e)!==null&&w(e)!==null,Ko=(0,Ie.arc)().cornerRadius(e=>e.cornerRadius??0);Ko.digits(8);var fS=200,gS=e=>Ko(e)??void 0,yS=(e,t)=>e==="full"?Math.max(0,t)/2:qn[e??"sm"]/fS,zo=(e,t)=>e==="x"?`${Y(t.startAngle)}-${Y(t.endAngle)}`:e==="y"?`${Y(t.innerRadius)}-${Y(t.outerRadius)}`:"sweep",vS=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}},bS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],or=(e,t,r)=>{const n=Ze(e,t);return a=>{const i=K(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},SS=(e,t,r)=>{const n=Ze(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},xS=(e,t,r)=>{const n=Ze(e,t),a=un(e,t),i=new Map;return s=>{const o=n(s),c=a(s),u=o!==null&&o!==""&&c!==null&&c!==""?`${r}-${o}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},AS=()=>(e,t)=>dt(e)??`default-${t}`;function jn(e,t,r){return Math.hypot(e*r,t)}function Wt(e,t,r){return e<t?t-e:e>r?e-r:0}function ue(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 IS(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,observationIndex:s.observationIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:jn(s.x-t.x,s.y-t.y,r)}:null}function TS(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 Yo(e,t){return Xn(e.buckets,t,r=>r.main)}function LS(e,t){return Xn(e.bands,t,r=>r.bandCenter)}function qo(e,t){return Xn(e.columns,t,r=>r.mainMid)}function Xn(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 wS(e,t){return{group:ES(e),related:DS(e,t)}}function ES(e){switch(e.kind){case"buckets":{const t=e.match.index;return B(t.position)?VS(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return B(t.position)?RS(t.layerId,r,n.pointIndex):CS(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function VS(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 RS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(Zn(e,a));return n}function CS(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(Zn(t,o));return i}function DS(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||OS(r,i,e.match.hit);continue}e.kind==="buckets"&&(B(i.position)||i.kind==="buckets"&&_S(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function _S(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&kt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function OS(e,t,r){switch(t.kind){case"buckets":{const n=Yo(t,Ue(t.mainAxis,r));if(!n)return;const a=kt(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,Ue(t.mainAxis,r));if(!n)return;const a=kt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(Zn(t.layerId,s));return}case"points":{const n=TS(t,r);if(!n)return;kt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,observationIndex:n.observationIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function kt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function Zn(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 jo(e,t,r){const{columns:n,bands:a}=kS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function kS(e,t){const r=PS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=Y(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=Y(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 PS(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 h of r){const p=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(p+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(p,f),xMax:Math.max(p,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:h}}),m++}return d}var MS=1e-9;function Xo(e,t,r){const n=NS(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)<=MS?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 NS(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=B(e.position),m=d?r.getValues(c,{type:"numeric"}):null,h=d?r.getValues(u,{type:"numeric"}):null,p=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=p?.[g]??null,A=o?x:v;if(d){const V=m?.[g],j=h?.[g];if(!l.isDefined(V)||!l.isDefined(j)){g+=1;continue}const ie=o?j:v,z=o?x:j;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:ie,y:z,stackMin:V,stackMax:j,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 Zo(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:BS(e,t)}}function BS(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const m of n)if(!r.hasVariable(m))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const m of r){const h=a[d],p=i[d],f=s[d],g=o[d];if(!l.isDefined(h)||!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!dt(m)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:p,yMin:f,yMax:g,observation:m}),d++}return u}function rn(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function FS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:Qo(e),delaunay:null,delaunayAspectRatio:null};return Jo(r,t),r}function $S(e){const t=Qo(e).map(r=>{const n=$t(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 Jo(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=ed.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function Qo(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];l.isDefined(o)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:o,y:c,observation:s}),i+=1}return a}function el(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:GS(e)}}function tl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function GS(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 hi(e,t,r){return t.type==="polar"?US(e,t.bandAxis):WS(e,t.mainAxis,r)}function US(e,t){switch(e.spatialKind){case"points":return $S(e);case"buckets":return Xo(e,"x","polar");case"rects":return t===null?Zo(e,"polar"):jo(e,t,"polar");case"cells":return rn(e);case"noop":return rn(e);case"render-hit-test":return el(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function WS(e,t,r){switch(e.spatialKind){case"points":return FS(e,r);case"buckets":return Xo(e,t,"cartesian");case"rects":return jo(e,t,"cartesian");case"cells":return Zo(e,"cartesian");case"noop":return rn(e);case"render-hit-test":return el(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function HS(e,t,r){if(e.columns.length===0)return null;const n=qo(e,Ue(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=B(e.position)?KS(a,t,e.mainAxis):zS(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:rl(i,t,r)}}function KS(e,t,r){const n=jt(r,t);return ue(e,i=>YS(i,r,n),{shortCircuitOnZero:!0})}function zS(e,t,r){return ue(e,a=>rl(a,t,r))}function rl(e,t,r){return jn(Wt(t.x,e.xMin,e.xMax),Wt(t.y,e.yMin,e.yMax),r)}function YS(e,t,r){return Wt(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function qS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=od(e.mainAxis,t),i=Yo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=nl(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:jn(o.x-t.x,o.y-t.y,r)}}function nl(e,t,r){return ue(e,a=>Math.abs(jt(r,a)-t))}function jS(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e};return null}function XS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=e.mainAxis==="x",s=i?ZS(e.columns,n):qo(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?JS(o,a):QS(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 ZS(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Ft(t,r.mainMid)):null}function JS(e,t){return ue(e,r=>Wt(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function QS(e,t){return ue(e,r=>ts(t,r.xMin,r.xMax)?0:Math.min(Ft(t,r.xMin),Ft(t,r.xMax)),{shortCircuitOnZero:!0})}function ex(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=tx(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=nl(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 tx(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Ft(r.main,t)):null}function rx(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=Qt(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&ts(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 nx(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=pn(t,r),i=ue(e.points,s=>fi(s,n,a));return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,observationIndex:i.observationIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:Math.sqrt(fi(i,n,a))}}function fi(e,t,r){const n=e.unitX??$t(e.x,e.y).x,a=e.unitY??$t(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var ax=.05;function ix({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=cx(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=lx(o,t,r);if(u)return u;continue}const c=ox({layer:o,cursor:t,aspectRatio:r,warmStarts:n});if(c){if(c.kind==="banded"||c.kind==="enclosure"){const u=c.kind==="banded"?c.match.distance:0;u<i.distance&&(i.match=c,i.distance=u);continue}c.match.distance<s.distance&&(s.match=c,s.distance=c.match.distance)}}return sx({containment:i,continuous:s})}function sx({containment:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+ax?t.match:e.match:e.match??t.match}function ox({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=qS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=HS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=IS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"enclosure":{const a=jS(e,t);return a?{kind:"enclosure",match:a}:null}case"noop":return null}}function lx(e,t,r){switch(e.kind){case"enclosure":{const n=rx(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=nx(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=ex(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=XS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function cx(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:tl(e.layerId,i)}:null}var J={primary:null,group:[],related:new Map},ux=1,dx=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=ux,this.warmStarts=new Map,this.cachedState=J,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=J,this.layerIndexes=e.map(r=>hi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>gi(r,t)),this.nonInteractiveLayerIds=yi(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=gi(i,t);if(s!==void 0&&mx(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(hi(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=yi(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&Jo(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return J;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=ix({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),J;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}=wS(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 J;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return J;const n=r.byKey.get(t);if(!n)return J;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:tl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=J,this.cachedByKeyId=null,this.cachedByKeyState=J}};function gi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function yi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function mx(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var px=Math.PI*2;function hx(e,t){const r=Ue(e.mainAxis,t);if(e.mainAxis==="y"){const a=ve(ne(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function fx(e,t,r){const n=e.mainAxis==="y"?w(r.observation):R(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?il(r):al(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:ve(ne(n+s)),width:"100%",height:ve(i)}:{x:ve(n-s),y:0,width:ve(i),height:"100%"}}function gx(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=G(t.observation),i=U(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=k(t.observation),n=_(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+px,innerRadius:r,outerRadius:n}}function al(e){const t=G(e.observation),r=U(e.observation);return t===null||r===null?null:r-t}function il(e){const t=k(e.observation),r=_(e.observation);return t===null||r===null?null:r-t}function yx(e){return e.observationIndex??e.pointIndex}var lr=.5,vx=.3,bx=.4,Sx=10,xx=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?Ix(e,t,r,n):Tx(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?Ex(e,t,n):e.spatialKind==="cells"?wx(e,n):e.spatialKind==="points"?Lx(e,n):null,Ax=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},Ix=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:lr*n.durationScale,baseline:Vx(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?Rx(e,t.mainAxis,n):{}}),Tx=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:lr*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?_x(e,t,r):{}}},Lx=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:lr*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?Cx(e,t):{}}),wx=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:vx*t.durationScale}),Ex=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:lr*r.durationScale,axis:t.mainAxis}),Vx=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[oe(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},Rx=(e,t,r)=>{const n=or(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=Uo(t,i);if(!s)continue;const o=Wo(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 Jn([...a.values()],r)},Cx=(e,t)=>{const r=or(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=Dx(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return Jn(n,t)},Dx=(e,t)=>{if(t==="main-axis")return R(e);const r=Gn(e)??R(e);return r===null?null:t==="value-descending"?-r:r},_x=(e,t,r)=>{const n=or(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Un(i),{innerRadius:c,outerRadius:u}=Wn(i);if(s===null||o===null||c===null||u===null)continue;const d=zo(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),h=a.get(d);h?h.keys.push(m):a.set(d,{position:s,keys:[m]})}return Jn([...a.values()],r)},Jn=(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/Sx),i=Math.ceil(n.length/a),s=bx*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},Me=["top","right","bottom","left"],vi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},Ox={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},kx={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},Px=(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]=kx[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=Nx(t,a),o=Bx(t,a,i);return Fx(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:$x(c,s,o,i)}))},Mx=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),Nx=(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}}},Bx=(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")}}}},Fx=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Me.indexOf(s)+o+Me.length)%Me.length;return Me[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=Me.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Me],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}})},$x=(e,t,r,n)=>{const a=(m,h,p)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:h,endAngle:p}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=vi[o];if(!e.isClosed&&n(u)){const m=t[u],h=i(m),p=Gx(m,h);s.push({type:"move",x:p.x,y:p.y}),s.push(a(m,h,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 h=vi[m];if(n(h)){const p=t[h];s.push(a(p,p.startAngle,p.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=Ox[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},Gx=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Ux=/^(?:https?:|mailto:)/i,Wx=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Ux.test(t)},Hx=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...F,...t}).format(r)),Kx=({locale:e,intlOptions:t})=>N(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,...F,...t}).format(r)}),Ht=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return so(e);case"date":return Hx(e);case"datetime":return Kx(e);case"day_month":return uo(e);case"decimal":return oo(e);case"duration":return Rn(e);case"integer":return lo(e);case"month":return mo(e);case"month_year":return _n(e);case"percentage":return co(e);case"quarter":return On(e);case"text":return Vn(e);case"time":return fo(e);case"weekly_date_range":return po(e);case"weekly_date_range_with_year":return ho(e);case"year":return kn(e);case"lookup":return Ht({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},zx=({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 h=c??i,p=Yx(u,d);return{header:p===null?qx({layers:e,coordSystem:t,guides:n,primary:m,locale:h,numberFormat:a}):null,rows:jx({layers:e,scales:r,guides:n,hover:s,locale:h,numberFormat:a,colorScheme:o}),comment:p}};function Yx(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function qx(e){if(e.coordSystem.type!=="cartesian")return null;const t=Yn(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)?Ht({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function jx(e){const t=[],r=e.scales.color??null,n=ir({colorScheme:e.colorScheme}),a=Qx({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=Zx(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...Xx(i,o,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Ui(i.data,i.mapping),u=Jx(s,i,r,c),d=Hn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=eA(e.guides,i),h=Zt(i),p=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=p?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",I=p&&y!==null?a(y):m,A=h(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 Xx(e,t,r,n,a){return e.tooltip.map(i=>{const s=e.mapping[i.aes],o=l.extractVariableName(s),c=W(e.data,s)(t.observation),u=C({valueFormat:cn(e,o),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:i.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",label:i.key??tr(o,r.variableLabels)??"",value:c===null?"":u(c,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${i.aes}`}})}function Zx(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 Jx(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 Qx({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:Ht({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=Ht({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 eA(e,t){return tr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function tA(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function rA(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var nA=e=>({edges:{top:$e(e.panelBorder("top")),right:$e(e.panelBorder("right")),bottom:$e(e.panelBorder("bottom")),left:$e(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),aA=(e,t)=>$e(e.gridLine(t)),iA=(e,t)=>{const r=e.tickLine(t);return{...$e(r),length:r.get("length")}},sA=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")}},oA=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},$e=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),lA=e=>e.fontSize*e.lineHeight,cA=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),se=(e,t,r)=>({fontFamily:e.get("fontFamily")??r,fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),uA=(e,t,r)=>se(e.axisLabel(t),r,e.graph.get("fontFamily")),dA=(e,t,r)=>{const n=e.tickLabel(t);return{...se(n,r,e.graph.get("fontFamily")),offset:n.get("offset")}},mA=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...se(a,n,e.graph.get("fontFamily")),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),isTextColorAuthored:a.getSource("textColor")==="authored",...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},pA=(e,t,r)=>{const n=se(e.ruleLabel(t),r,e.graph.get("fontFamily"));return{fontFamily:n.fontFamily,fontSize:n.fontSize,fontWeight:n.fontWeight,lineHeight:n.lineHeight}},hA=(e,t)=>{const r=e.tooltip.box,n=e.graph.get("fontFamily");return{box:{background:r.get("background"),borderColor:r.get("borderColor"),borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock"),shadow:r.get("shadow")},heading:se(e.tooltip.heading,t,n),label:se(e.tooltip.label,t,n),value:se(e.tooltip.value,t,n),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},cr={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},fA={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}}},gA=Object.keys(cr),yA=e=>Object.hasOwn(cr,e),mt=(e,t)=>{for(const r of gA){const n=vA(e,r,t);if(n)return n}return null},pt=(e,t)=>e[cr[t]],Qn=(e,t,r)=>({...e,[cr[t]]:r}),sl=(e,t)=>{const r=pt(e,t.kind);return Qn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},vA=(e,t,r)=>{const n=pt(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},ea=["sticker","pinnedNumber","comment","image"],bA=e=>ea.includes(e),ta=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?xA(e.annotation.at):null;default:return null}},ol=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),ll=(e,t,r=SA)=>{const n=r(t);for(const a of ea){const i=pt(e,a),s=i.findIndex(c=>{const u=ta({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return ol(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},SA=e=>({...e,anchorValue:Or(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Or(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Or(e.crossValue)}}),Or=e=>l.readISOInstant(e)??e,xA=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function AA(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var IA=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ra(r.predicate,t.predicate))??null,ra=(e,t)=>"and"in e?"and"in t&&bi(e.and,t.and):"or"in e?"or"in t&&bi(e.or,t.or):"not"in e?"not"in t&&ra(e.not,t.not):TA(t)&&e.variable===t.variable&&LA(e,t),TA=e=>"variable"in e,bi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ra(r,a)}),LA=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Si(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&&Si(e.range,t.range),Si=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),wA={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},EA=e=>Object.hasOwn(wA,e);function VA(e){return{type:"mapping",mapping:e}}var ur=(e,t)=>"and"in e?"and"in t&&xi(e.and,t.and):"or"in e?"or"in t&&xi(e.or,t.or):"not"in e?"not"in t&&ur(e.not,t.not):RA(t)&&e.variable===t.variable&&CA(e,t),RA=e=>"variable"in e,xi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ur(r,a)}),CA=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ai(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&&Ai(e.range,t.range),Ai=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),cl=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)))),ul=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),dl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function ml(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(DA),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function DA(e){return e.scaleType==="palette"?_A(e):e}function _A(e){return{...e,palette:OA(e.palette),overrides:kA(e.overrides)}}function OA(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function kA(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var dr=(e,t)=>{const r=na(e,t);return r===-1?void 0:e[r]},na=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&mr(n,t))return r}return-1},mr=(e,t)=>PA(e.select,t.select)&&e.when?.state===t.when?.state&&MA(e.when?.where,t.when?.where),pl=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>NA(e[r],t[r])),Ae=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),aa=e=>e.select.target==="geom",ht=(e,t)=>{const r=dr(e,t);if(!(r===void 0||!aa(r)))return r.declarations},PA=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},MA=(e,t)=>e===void 0||t===void 0?e===t:ur(e,t),NA=(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 S(e){return{id:e.id??M(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function qe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>qe(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=>qe(e[a],t[a]))}return!1}var ia=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=S({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=mt(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:L(e,{annotations:sl(e.annotations,t)}),revert:new sa({kind:r,annotation:a,index:n},this.metadata)}}},BA={type:"remove-annotation",deserialize:(e,t)=>new ia(e,t)},sa=class hl{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??M()},...t.index!==void 0&&{index:t.index}},this.metadata=S({...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(!yA(r)||mt(t.annotations,n.id))return null;const i=$A(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:sl(t.annotations,i),o=pt(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:L(t,{annotations:Qn(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new ia({id:n.id},this.metadata):new hl({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},FA={type:"add-annotation",deserialize:(e,t)=>new sa({kind:e.kind,annotation:e.annotation,index:e.index},t)},$A=(e,t)=>{const r=ta(t);return r===null?null:ll(e,r)},GA=(e,t)=>{const r=oa(e);return r===null?null:fl(r.points,t)},UA=e=>oa(e)!==null,WA=(e,t)=>{const r=oa(e);if(r===null)return null;const n=fl(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},oa=e=>{const t=KA[e.kind];return t===null?null:t(e.annotation)},Ii=(e,t)=>e.anchorType!=="panel"?null:{points:[nn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Ti=(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})},HA=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[nn(e,e.offset),nn(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}})},KA={text:e=>Ii(e.at,t=>({at:t})),sticker:e=>Ii(e.at,t=>({at:t})),shape:e=>Ti(e.region,t=>({region:t})),image:e=>Ti(e.region,t=>({region:t})),arrow:e=>HA(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},nn=(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)},fl=(e,t)=>({x:Li(e.map(r=>r.x),t.x),y:Li(e.map(r=>r.y),t.y)}),Li=(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,Ge.default)(t,r,n)},gl=(e,t,r)=>{const n=t.annotation;if(!qA(n,r))return null;const a=pt(e.annotations,t.kind),i=zA(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:L(e,{annotations:Qn(e.annotations,t.kind,s)}),inverse:YA(n,r)}},zA=(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)))},YA=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},qA=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),la=class yl{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=S({...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=mt(t.annotations,n);if(i===null||i.kind!==r)return null;const s=gl(t,i,a);return s===null?null:{spec:s.spec,revert:new yl({kind:r,id:n,patch:s.inverse},this.metadata)}}},jA={type:"update-annotation",deserialize:(e,t)=>new la(e,t)},vl=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=S({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=mt(e.annotations,this.params.id);if(t===null)return null;const r=WA(t,this.params.translation);if(r===null)return null;const n=gl(e,t,r);return n===null?null:{spec:n.spec,revert:new la({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},XA={type:"move-annotation",deserialize:(e,t)=>new vl(e,t)},ZA=["cartesian","polar","flip"],$=new rr,bl=e=>$.has(e)?$.get(e):null,Sl=new l.TransformRegistry,JA=new Qs(Sl),pr=e=>{const t=e.transforms.every(r=>Sl.has(r.transformType));return e.transforms.length===0||!t?e.data:JA.compile({data:e.data,transforms:e.transforms})};function ca(e,t){const r=t.some(i=>i.yScaleType==="secondary"),n=e.find(i=>i.scaledAesthetic==="ySecondary");if(!r)return n===void 0?e:e.filter(i=>i!==n);if(n!==void 0)return e;const a=e.find(i=>i.scaledAesthetic==="y");return a===void 0?e:[...e,{...a,scaledAesthetic:"ySecondary"}]}function ft(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function gt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:L(e,{scales:Fi(e.scales,n,r)})}function yt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function an(e,t,r){const n=wn(Gs(eo($),{data:pr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Us(n):n}var xl=class Al{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=S({...r,description:uI(t)})}apply(t){const r="previous"in this.params?this.params.previous:dI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Al({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},QA={type:"set-chart-type",deserialize:(e,t)=>new xl(e,t)},Il={type:"sum"},eI={type:"identity"},tI=["bar","line","area","point","tile"],ua="tile",rI=["y","color"],nI=Object.values(l.LAYER_LABEL_VARIABLES),aI={coordType:"cartesian",geom:ua,position:"identity"},vt=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),iI=e=>{const t=e.layers.filter(te),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const s=Ll(t);if(s!==null)return{coordType:"cartesian",comboType:s}}if(!t.every(s=>s.geom===r.geom&&s.position===r.position))return null;const{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}},sI=e=>{if(!e)return!1;const t=e.layers.filter(te);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:wl(e,r)?El(e,r).length>=1:hr(e,e.data.groupVariableNamesByType().numeric).length>=2},oI=e=>e?Ol(e,aI)!==null:!1,lI=e=>Tl(e)?.at(-1)?.id??null,Tl=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(te);return Ll(t)===null?null:t},Ll=e=>{const t=e.at(-1);if(e.length<2||t?.geom!=="line")return null;const r=e.slice(0,-1);if(r.every(a=>a.geom==="line"))return cI(e)?"lines":null;if(!r.every(a=>a.geom==="bar"))return null;const[n]=r;return n===void 0||!r.every(a=>a.position===n.position)?null:l.readComboTypeOfBarPosition(n.position)},cI=e=>e.some(t=>t.yScaleType==="secondary"||Kt(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,uI=e=>"previous"in e?"Restore the previous chart type":vt(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,dI=(e,t)=>{const r=Ol(e,t);if(r===null)return null;const n=vt(t)?pI(r,t):mI(r,t,e);return n===null||r===e?n:{...n,scales:wI({...e,...n},n.scales)}},mI=(e,t,r)=>{if(vt(t)||!EI(t))return null;const n={...e,layers:$l(e.layers)},a=CI(n.layers.filter(te),t),i=Ul(n.coords,t),s=Dl(n,t),o=Fl({...n,mapping:s},t,a,s!==n.mapping);return{coords:i,layers:o,scales:ca(Wl(r,o,i.coordType),o),mapping:s}},pI=(e,t)=>{const r=gI(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=DI(r.filter(te),t.comboType),i=Ul(n.coords,t),s=Dl(n,t),o=Fl({...n,mapping:s},t,a,s!==n.mapping),c=hI(e)?o:fI(o);return{coords:i,layers:c,scales:ca(Wl(e,c,i.coordType),c),mapping:s}},hI=e=>Tl(e)!==null,fI=e=>{const t=e.filter(te).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},gI=(e,t)=>{const r=e.layers.filter(te);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:wl(e,n)?yI(e,n):vI(e,n,t)},wl=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},yI=(e,t)=>{const[r]=El(e,t);if(r===void 0)return null;const n=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Vl(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:Il,...Cl(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},hr=(e,t)=>{const r=bt(e);return t.filter(n=>n!==r)},El=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return hr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},bt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),vI=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=hr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const s=l.readFoldKeepVariables(e.data,bt(e)),o=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=bI(t,wi(a.slice(0,-1),s,o)),u=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Vl(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...wi([i],s,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Vl=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},wi=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?Cl(n,r):Rl(e,t)},Rl=(e,t)=>({mapping:{y:l.DEFAULT_RESHAPE_VALUE_NAME,color:"key"},transforms:[l.transform.reshape({keep:t,reshape:e,keyName:"key",valueName:l.DEFAULT_RESHAPE_VALUE_NAME})]}),Cl=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),bI=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Dl=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=_l(t)?"":bt(e);return n===r?e.mapping:{...e.mapping,x:n}},_l=e=>e.coordType==="polar"&&e.theta==="y",SI=e=>!vt(e)&&e.geom===ua,xI=e=>e.layers.filter(te).some(t=>t.geom===ua),Ol=(e,t)=>{const r=SI(t);return r===xI(e)?e:r?AI({...e,layers:$l(e.layers)}):II(e)??e},AI=e=>{const t=Pl(e);if(t===null)return null;const r=TI(e,t)===null?LI(e,t):Ml(e,t);return r===null?null:kl(e,t,r)},II=e=>{const t=Pl(e);if(t===null)return null;const r=Ml(e,t);return r===null?null:kl(e,t,r)},kl=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Pl=e=>{const t=e.layers.filter(te);return t.length===1?t[0]??null:null},Ml=(e,t)=>{const r={...e.mapping,...t.mapping};return r.y===void 0||r.color===void 0?null:{mapping:{...e.mapping,y:r.color,color:r.y},layer:Nl(t)}},Nl=e=>{if(e.mapping.y===void 0&&e.mapping.color===void 0)return e;const{y:t,color:r,...n}=e.mapping;return{...e,mapping:n}},TI=(e,t)=>{const r={...e.mapping,...t.mapping},n=l.extractVariableName(r.color),a=l.extractVariableName(r.y);if(n===null||n===""||a===null||a===""||n===bt(e))return null;const i=pr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},LI=(e,t)=>{const r=hr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,bt(e)),a=Rl(r,n),i=Nl(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},wI=(e,t)=>rI.reduce((r,n)=>{const a=an(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Xe(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),EI=e=>ZA.includes(e.coordType)&&Bl(e.geom)&&VI(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),VI=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=$.get(e);return n.includes(t)&&a.includes(r)},Bl=e=>tI.includes(e),te=e=>Bl(e.geom)&&!RI(e.stat),RI=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},CI=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},DI=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,s)=>n===null||s===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:_I(i,t,n)}]);return new Map(a)},_I=(e,t,r)=>e.geom!=="bar"||Kt(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Fl=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Fs($,Xe(e.layers,i=>{const s=r.get(i.id);if(s===void 0)return i;const o=OI(i.stat,e.coords,t);return a||n||i.geom!==s.geom||i.position!==s.position||o!==i.stat?PI(e,{...i,stat:o},t.coordType,s):i}))},OI=(e,t,r)=>_l(r)?e.type==="identity"?Il:e:kI(t)&&e.type==="sum"?eI:e,kI=e=>e.coordType==="polar"&&e.params.theta==="y",PI=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...Ce($,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,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}},$l=e=>{const t=e.filter(te);if(t.length<2||!e.some(Kt))return e;const[r]=t;return e.flatMap(n=>n===r?[MI(n)]:Kt(n)?[]:[n])},Kt=e=>Gl(e)!==null,Gl=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:nI.includes(t.options.variableName)?t:null},MI=e=>{const t=Gl(e);if(t===null)return e;const{color:r,...n}=e.mapping,a=t.transformType==="reshape"?t.options.reshape?.[0]:void 0;return{...e,mapping:a===void 0?n:{...n,y:a},transforms:e.transforms.slice(0,-1)}},Ul=(e,t)=>{const r=NI(e,t);return(0,Nt.default)(r,e)?e:r},NI=(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:_t;return Kr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},Wl=(e,t,r)=>{const n=Wr($,t),a=Wr($,e.layers),i=e.coords.coordType==="polar";return Xe(e.scales,s=>{const o=BI(s,n,a),c=FI(o,n,a);return GI(c,r,i)})},BI=(e,t,r)=>{if(e.scaleType==="discrete"){const a=t.bandPadding[e.scaledAesthetic];return a===void 0||e.padding===a?e:{...e,padding:a}}if(e.scaledAesthetic===t.discreteAxis)return zr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return zr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=$I(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},FI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(e.scaledAesthetic))return e;const n=t.bandPadding[e.scaledAesthetic];if(n===r.bandPadding[e.scaledAesthetic])return e;const a=n??l.DISCRETE_SCALE_DEFAULTS.padding;return e.padding===a?e:{...e,padding:a}},$I=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,GI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},Hl=class Kl{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=S({...r,description:WI(t)})}apply(t){const r="previous"in this.params?this.params.previous:HI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Kl({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},UI={type:"set-mapping",deserialize:(e,t)=>new Hl(e,t)},zl=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Yl=e=>e===""?null:e,WI=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Yl(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},HI=(e,{aesthetic:t,variable:r})=>{if(!EA(t))return null;const n=Yl(r),a=zI(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:qI(e,t,a,n),layers:KI(e.layers,a)}},KI=(e,t)=>Xe(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&bl(r.geom)===null)return r;const a=Bs($,r.geom,r.position,n);return(0,Nt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),zI=(e,t,r)=>r===null?YI(e,t):zl(e,t)===r?e:{...e,[t]:r},YI=(e,t)=>{if(t==="x")return l.readMainAxisVariable(e)===""?e:{...e,x:""};const r=e[t];if(r===void 0||l.extractVariableName(r)==="")return e;const n={};for(const[a,i]of Object.entries(e))a!==t&&(n[a]=i);return n},qI=(e,t,r,n)=>{if(!os(t))return e.scales;let a=e.scales;for(const i of jI(e,t))a=ZI(e,a,i,r,n);return a},jI=(e,t)=>t==="y"&&XI(e.layers)?["y","ySecondary"]:[t],XI=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},ZI=(e,t,r,n,a)=>{const i=t.find(o=>o.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,an(e,r,n)];if(a===null&&!Ve(r)||a!==null&&!pr(e).hasVariable(a))return t;const s=an(e,r,n);return JI(i,s)?t:Xe(t,o=>o.scaledAesthetic===r?s:o)},JI=(e,t)=>e.scaleType===t.scaleType||Ei(e)&&Ei(t),Ei=e=>e.scaleType==="discrete"||e.scaleType==="palette",ql=class jl{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=S({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:E(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new jl({textScale:r},this.metadata)}}},QI={type:"set-appearance-text-scale",deserialize:(e,t)=>new ql(e,t)},da=e=>e==="both"?["x","y"]:[e],Xl=e=>e==="both"?"the":`${e} axis`;function ma(e,t){return fr(e)?e[t]:e}function eT(e,t){return e.config.axes[t]??{}}function tT(e,t,r){if(t!=="ySecondary")return E(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=Zl(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,L(e,{config:L(e.config,{axes:i})})}function fr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function Zl(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?rT(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 rT(e,t){return l.isPlainObject(t)?Zl(l.isPlainObject(e)?e:void 0,t):t}var Jl=class Ql{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=S({...r,description:`Set ${t.axis} axis label to ${aT(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=eT(t,r).label;if(a===n)return null;const i=tT(t,r,{label:n});return i===t?null:{spec:i,revert:new Ql(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},nT={type:"set-axis-label",deserialize:(e,t)=>new Jl(e,t)};function aT(e){return e===void 0?"(inherited)":e??"(none)"}var ec=class tc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{position:n}}}}),revert:new tc({axis:r,position:a},this.metadata)}}},iT={type:"set-axis-position",deserialize:(e,t)=>new ec(e,t)},rc=class nc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new nc({axis:r,tickMode:a},this.metadata)}}},sT={type:"set-axis-tick-mode",deserialize:(e,t)=>new rc(e,t)},ac=class ic{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new ic({axis:r,isVisible:a},this.metadata)}}},oT={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new ac(e,t)},sc=class oc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new oc({axis:r,isVisible:a},this.metadata)}}},lT={type:"set-axis-visibility",deserialize:(e,t)=>new sc(e,t)},lc=class cc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=S({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:E(t,{config:{content:{caption:this.params.caption}}}),revert:new cc({caption:r},this.metadata)}}},cT={type:"set-content-caption",deserialize:(e,t)=>new lc(e,t)},uc=class dc{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=S({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(qe(r,this.params.source))return null;const n=L(t.config.content,{source:this.params.source});return{spec:L(t,{config:L(t.config,{content:n})}),revert:new dc({source:r},this.metadata)}}},uT={type:"set-content-source",deserialize:(e,t)=>new uc(e,t)},mc=class pc{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=S({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:E(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new pc({subtitle:r},this.metadata)}}},dT={type:"set-content-subtitle",deserialize:(e,t)=>new mc(e,t)},hc=class fc{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=S({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:E(t,{config:{content:{title:this.params.title}}}),revert:new fc({title:r},this.metadata)}}},mT={type:"set-content-title",deserialize:(e,t)=>new hc(e,t)},de=class Pt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=S({...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=na(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new Pt({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!mr(y,n));return{spec:kr(t,r,g),revert:f}}if(o!==void 0){if(pl(o.declarations,c))return null;const f={...o,declarations:c},g=new Pt({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:kr(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},h=[...i.slice(0,d),m,...i.slice(d)],p=new Pt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:kr(t,r,h),revert:p}}},pT=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."})},hT={type:"set-style-rule",deserialize:(e,t)=>(pT(e),new de(e,t))},kr=(e,t,r)=>L(e,{styles:{...e.styles,[t]:r}}),fT="dashed",gT=1,gc=(e,t,r,n)=>{const a=yT(t,r),i=bT(e,a,n);let s=e,o=!1;for(const c of a){const u=xT(s,c,n,ST(n,vT(r,c)));u!==null&&(s=u,o=!0)}return o?{spec:s,previous:i}:null},yT=(e,t)=>e==="both"&&!fr(t)?[void 0]:da(e),vT=(e,t)=>t===void 0?fr(e)?e.x:e:ma(e,t),bT=(e,t,r)=>t.length===1?Pr(e,t[0],r):{x:Pr(e,"x",r),y:Pr(e,"y",r)},Pr=(e,t,r)=>yc(e.styles.overrides,t)?.[r]??null,ST=(e,t)=>t===null||e==="lineType"&&t===fT||e==="strokeWidth"&&t===gT?null:t,xT=(e,t,r,n)=>{const a=yc(e.styles.overrides,t);return(a?.[r]??null)===n?null:new de({list:"overrides",rule:TT(t,IT(a,r,n))}).apply(e)?.spec??null},AT=e=>e.select.target==="gridLine",yc=(e,t)=>{const r=dr(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!AT(r)))return r.declarations},IT=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},TT=(e,t)=>t===null?e===void 0?{select:{target:"gridLine"},declarations:null}:{select:{target:"gridLine",axis:e},declarations:null}:e===void 0?l.style.gridLine(t):e==="x"?l.style.gridLine.x(t):l.style.gridLine.y(t),vc=class bc{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=S({...r,description:`Set ${Xl(t.axis)} grid line style to ${wT(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=gc(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new bc({axis:r,lineStyle:a.previous},this.metadata)}}},LT={type:"set-grid-line-style",deserialize:(e,t)=>new vc(e,t)},wT=({axis:e,lineStyle:t})=>{const r=da(e).map(n=>ma(t,n)??"(theme)");return[...new Set(r)].join(" and ")},ET={type:"set-grid-line-width",deserialize:(e,t)=>new Sc(e,t)},Sc=class xc{constructor(t,r={}){this.type="set-grid-line-width";const n=VT(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=S({...r,description:`Set ${Xl(t.axis)} grid line width to ${RT(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=gc(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new xc({axis:r,lineWidth:a.previous},this.metadata)}}},VT=e=>fr(e)?{x:Mr(e.x),y:Mr(e.y)}:Mr(e),Mr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),RT=(e,t)=>{const r=da(e).map(n=>ma(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Ac=class Ic{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new Ic({axis:r,isVisible:a},this.metadata)}}},CT={type:"set-grid-visibility",deserialize:(e,t)=>new Ac(e,t)},Tc=class Lc{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:E(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Lc({compareWith:r},this.metadata)}}},DT={type:"set-headline-compare-with",deserialize:(e,t)=>new Tc(e,t)},wc=class Ec{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:E(t,{config:{headline:{position:this.params.position}}}),revert:new Ec({position:r},this.metadata)}}},_T={type:"set-headline-position",deserialize:(e,t)=>new wc(e,t)},Vc=class Rc{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:E(t,{config:{headline:{show:this.params.show}}}),revert:new Rc({show:r},this.metadata)}}},OT={type:"set-headline-show",deserialize:(e,t)=>new Vc(e,t)},Cc=class Dc{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:E(t,{config:{headline:{size:this.params.size}}}),revert:new Dc({size:r},this.metadata)}}},kT={type:"set-headline-size",deserialize:(e,t)=>new Cc(e,t)},PT={type:"set-highlight-dim-style",deserialize:(e,t)=>new _c(e,t)},_c=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=S({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Oc(e)===this.params.dimStyle)return null;const t=new de({list:"overrides",rule:NT(this.params.dimStyle)},this.metadata).apply(e);return t||null}},MT={select:{target:"geom"},when:{state:"dimmed"}},Oc=e=>{const t=dr(e.styles.overrides,MT);return(t!==void 0&&aa(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},NT=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),kc=class Pc{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:E(t,{config:{legend:{align:this.params.align}}}),revert:new Pc({align:r},this.metadata)}}},BT={type:"set-legend-align",deserialize:(e,t)=>new kc(e,t)},Mc=class Nc{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:E(t,{config:{legend:{display:this.params.display}}}),revert:new Nc({display:r},this.metadata)}}},FT={type:"set-legend-display",deserialize:(e,t)=>new Mc(e,t)},Bc=class Fc{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:E(t,{config:{legend:{position:this.params.position}}}),revert:new Fc({position:r},this.metadata)}}},$T={type:"set-legend-position",deserialize:(e,t)=>new Bc(e,t)},$c=class Gc{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:E(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Gc({abbreviation:r},this.metadata)}}},GT={type:"set-number-format-abbreviation",deserialize:(e,t)=>new $c(e,t)},Uc=class Wc{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:E(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Wc({decimals:r},this.metadata)}}},UT={type:"set-number-format-decimals",deserialize:(e,t)=>new Uc(e,t)},Hc=class Kc{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=S({...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=HT(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:E(t,{config:{content:{[a]:n}}}),revert:new Kc({slot:r,isVisible:i},this.metadata)}}},WT={type:"toggle-content-visibility",deserialize:(e,t)=>new Hc(e,t)},Vi={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function HT(e){return Object.hasOwn(Vi,e)?Vi[e]:void 0}var zc=class Yc{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=S({...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(qe(i.xLimits,a.xLimits)&&qe(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 Yc(s,this.metadata);return{spec:L(t,{coords:zT(t.coords,i)}),revert:o}}},KT={type:"set-coord-limits",deserialize:(e,t)=>new zc(e,t)};function zT(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 qc=class jc{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Ge.default)(t.innerRadius,0,1)},this.metadata=S({...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:L(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new jc({innerRadius:n},this.metadata)}}},YT={type:"set-polar-inner-radius",deserialize:(e,t)=>new qc(e,t)},qT={type:"set-polar-start-angle",deserialize:(e,t)=>new Xc(e,t)},Xc=class Zc{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:Ri(t.startAngle)},this.metadata=S({...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 Ri(n)===this.params.startAngle?null:{spec:L(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Zc({startAngle:n},this.metadata)}}},Nr=360,Ri=e=>(e%Nr+Nr)%Nr,pa=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=S({...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 ha({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:L(e,{highlights:n}),revert:a}}},jT={type:"remove-highlight",deserialize:(e,t)=>new pa(e,t)},ha=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??M(),scope:e.scope??"data-point"},this.metadata=S({...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 pa({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:L(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},XT={type:"add-highlight",deserialize:(e,t)=>new ha(e,t)};function fa(e,t){return{...e,params:{...e.params,...t}}}function gr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function ga(e,t){return L(e,{layers:[...e.layers,t]})}function H(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:L(e,{layers:Fi(e.layers,n,r)})}function yr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:L(e,{layers:e.layers.filter((n,a)=>a!==r)})}var ya=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=S({...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=yr(e,this.params.layerId);return n===e?null:{spec:n,revert:new va({layer:r,index:t},this.metadata)}}},ZT={type:"remove-layer",deserialize:(e,t)=>new ya(e,t)},va=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??M()},...e.index!==void 0&&{index:e.index}},this.metadata=S({...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:L(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new ya({layerId:t.id},this.metadata)}}},JT={type:"add-layer",deserialize:(e,t)=>new va(e,t)},Jc=class Qc{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"bar"))return null;const a=Ae("bar",r),i=ht(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:eL(i,n)}}).apply(t);if(!o)return null;const c=new Qc({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},QT={type:"set-bar-border-radius",deserialize:(e,t)=>new Jc(e,t)},eL=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},tL={type:"set-bar-width",deserialize:(e,t)=>new tu(e,t)},eu=.05,rL=1,tu=class ru{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Ge.default)(t.width,eu,1);this.params={...t,width:n},this.metadata=S({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"bar");if(!q(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:H(t,r.id,fa(r,{width:this.params.width})),revert:new ru({layerId:r.id,width:n},this.metadata)}}},nu=class au{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:H(t,r.id,gr(r,{format:this.params.format})),revert:new au({layerId:r.id,format:n},this.metadata)}}},nL={type:"set-data-labels-format",deserialize:(e,t)=>new nu(e,t)},iu=class su{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=S({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:H(t,r.id,{...r,position:this.params.position}),revert:new su({layerId:r.id,position:n},this.metadata)}}},aL={type:"set-layer-position",deserialize:(e,t)=>new iu(e,t)},ou=class lu{constructor(t,r={}){this.type="set-layer-stat";const n=Ns(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=S({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return sL(n,this.params.stat)?null:{spec:H(t,r.id,{...r,stat:this.params.stat}),revert:new lu({layerId:r.id,stat:n},this.metadata)}}},iL={type:"set-layer-stat",deserialize:(e,t)=>new ou(e,t)},sL=(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},cu=class uu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=H(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:L(a,{scales:ca(a.scales,a.layers)}),revert:new uu({layerId:r.id,yScaleType:n},this.metadata)}}},oL={type:"set-layer-y-scale-type",deserialize:(e,t)=>new cu(e,t)},du=class mu{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=S({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:H(t,r.id,fa(r,{interpolate:this.params.interpolate})),revert:new mu({layerId:r.id,interpolate:n},this.metadata)}}},lL={type:"set-line-interpolation",deserialize:(e,t)=>new du(e,t)},pu=class hu{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:H(t,r.id,fa(r,{missingValues:this.params.missingValues})),revert:new hu({layerId:r.id,missingValues:n},this.metadata)}}},cL={type:"set-line-missing-values",deserialize:(e,t)=>new pu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=S({...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=D(t.layers,r);if(!q(a,"line","area"))return null;const i=ht(t.styles.overrides,Ae(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=dL(i,n),c=new de({list:"overrides",rule:a.geom==="area"?{...Ae("area",r),declarations:o}:{...Ae("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new gu({layerId:r,lineWidth:s},this.metadata)}:null}},uL={type:"set-line-width",deserialize:(e,t)=>new fu(e,t)},dL=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},yu=class vu{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"point"))return null;const a=Ae("point",r),i=ht(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:pL(i,n)}}).apply(t);return o?{spec:o.spec,revert:new vu({layerId:r,size:s},this.metadata)}:null}},mL={type:"set-point-size",deserialize:(e,t)=>new yu(e,t)},pL=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},bu=class Su{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=S({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"rule");if(!q(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:H(t,r.id,{...r,params:i}),revert:new Su({layerId:r.id,label:n??null},this.metadata)}}},hL={type:"set-rule-label",deserialize:(e,t)=>new bu(e,t)},xu=class Au{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=S({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"rule");if(!q(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:H(t,r.id,{...r,mapping:i}),revert:new Au({layerId:r.id,value:a},this.metadata)}}},fL={type:"set-rule-value",deserialize:(e,t)=>new xu(e,t)},gL={type:"set-stat-line",deserialize:(e,t)=>new Iu(e,t)},Iu=class Tu{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=S({...r,description:IL(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=vL(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&&AL(r.layer,n))return null;const a=new Tu({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:H(t,r.layer.id,n),revert:a};const i=r===void 0?t:yr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:ga(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"?bL(this.params):SL(t,this.params);if(n===null)return null;const a=Ce($,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},yL="linear",vL=e=>{const t=ul(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=dl(e.layers);if(r!==void 0)return{line:"average",layer:r}},bL=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??yL}),interactive:!1}),SL=(e,{group:t,label:r})=>{const n=xL(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})},xL=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),AL=(e,t)=>(0,je.isEqual)({...e,id:""},{...t,id:""}),IL=e=>e==="none"?"Hide stat line":`Show ${e} line`,Lu=class wu{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=S({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:H(t,r.id,gr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new wu({layerId:r.id,showCategoryLabels:n},this.metadata)}}},TL={type:"toggle-category-labels",deserialize:(e,t)=>new Lu(e,t)},Eu=class Vu{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=S({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:H(t,r.id,gr(r,{showDataLabels:this.params.showDataLabels})),revert:new Vu({layerId:r.id,showDataLabels:n},this.metadata)}}},LL={type:"toggle-data-labels",deserialize:(e,t)=>new Eu(e,t)},wL={type:"toggle-goal-line",deserialize:(e,t)=>new Ru(e,t)},Ru=class sn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=S({...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=cl(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=yr(t,r.id);return a===t?null:{spec:a,revert:new sn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:ga(t,n),revert:new sn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ce($,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??EL}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},EL=0,VL={type:"toggle-line-fill",deserialize:(e,t)=>new Cu(e,t)},Cu=class Du{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"line"))return null;const i=Ae("line",r),s=ht(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new de({list:"overrides",rule:{...i,declarations:CL(s,n?a??RL:null)}}).apply(t);if(!u)return null;const d=new Du({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},RL=.2,CL=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},DL={type:"toggle-line-points",deserialize:(e,t)=>new _u(e,t)},_u=class on{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=S({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"line","area");return q(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:ga(t,this.params.removedLayer??Ce($,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new on({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:yr(t,n.id),revert:new on({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:vn(n,[r]))}},Ou=class ku{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=S({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:H(t,r.id,gr(r,{showStackTotals:this.params.showStackTotals})),revert:new ku({layerId:r.id,showStackTotals:n},this.metadata)}}},_L={type:"toggle-stack-totals",deserialize:(e,t)=>new Ou(e,t)},Pu=class Mu{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(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=gt(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 Mu(c,this.metadata)}}},OL={type:"set-scale-domain",deserialize:(e,t)=>new Pu(e,t)},Nu=class Bu{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||qe(r.palette,this.params.palette)?null:{spec:gt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Bu({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},kL={type:"set-scale-palette",deserialize:(e,t)=>new Nu(e,t)},Fu=class $u{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||!ML(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:gt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new $u({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},PL={type:"set-scale-reverse",deserialize:(e,t)=>new Fu(e,t)};function ML(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Gu=class Uu{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:gt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Uu({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},NL={type:"set-scale-transform",deserialize:(e,t)=>new Gu(e,t)},Wu=class Hu{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:gt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Hu({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},BL={type:"set-scale-zero",deserialize:(e,t)=>new Wu(e,t)},Ku=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}},b=new Ku;b.register(QA);b.register(UI);b.register(JT);b.register(ZT);b.register(nL);b.register(aL);b.register(iL);b.register(oL);b.register(lL);b.register(uL);b.register(QT);b.register(tL);b.register(mL);b.register(cL);b.register(hL);b.register(fL);b.register(gL);b.register(TL);b.register(LL);b.register(wL);b.register(VL);b.register(DL);b.register(_L);b.register(OL);b.register(kL);b.register(PL);b.register(NL);b.register(BL);b.register(QI);b.register(nT);b.register(sT);b.register(iT);b.register(oT);b.register(lT);b.register(cT);b.register(uT);b.register(dT);b.register(mT);b.register(LT);b.register(ET);b.register(CT);b.register(DT);b.register(_T);b.register(OT);b.register(kT);b.register(PT);b.register(BT);b.register(FT);b.register($T);b.register(GT);b.register(UT);b.register(WT);b.register(XT);b.register(jT);b.register(hT);b.register(FA);b.register(BA);b.register(jA);b.register(XA);b.register(KT);b.register(YT);b.register(qT);var zu=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:Ci(this.undoStack),redoStack:Ci(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&&$L(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)}}},FL=Object.freeze([]),$L=(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},Ci=e=>e.length===0?FL:e.map(t=>t.command.metadata),GL=(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&&mr(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}`})}},UL=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}},WL=class{constructor(e){this.compiler=e,this.history=new zu,this.current=null,this.last=null,this.hostInput=null,this.run=new UL(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=ml(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},HL=new Set(["x","y"]),Di=["numeric","categorical","temporal"],_i=["numeric"],KL=(e,t)=>{const r=e.layers.map(a=>bl(a.geom)).filter(l.isDefined),n=pr(e);return t.filter(a=>zL(e,r,a)).map(a=>({aesthetic:a,variables:YL(n,r,a),isRequired:HL.has(a)}))},zL=(e,t,r)=>{switch(r){case"x":return!XL(e.coords);case"y":return!0;case"label":return t.some(n=>n.dataLabelCoordTypes.includes(e.coords.coordType));default:return t.some(n=>n.aesthetics.some(a=>a.kind==="visual"&&a.name===r))}},YL=(e,t,r)=>{const n=qL(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},qL=(e,t)=>t==="size"?_i:t!=="x"&&t!=="y"?Di:jL(e,t)?_i:Di,jL=(e,t)=>e.some(r=>r.positionRoles.some(n=>ss.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),XL=e=>e.coordType==="polar"&&e.params.theta==="y",ZL=500,JL="normal",ba={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},QL=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}`},Sa=e=>typeof e!="string"?e??500:ba[e],ew="\0",tw=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,Sa(t.weight),t.style??"normal",e].join(ew)}},rw={" ":.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 nw=1.05,aw=.84,iw=.21,sw=class{measureText(e,t){let r=0;for(const i of e)r+=(rw[i]??.55)*t.size;Sa(t.weight)>=ba.semiBold&&(r*=nw);const n=aw*t.size,a=iw*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=Jv;exports.ARROW_DEFAULTS=fe;exports.AXIS_KEYS=hn;exports.AddAnnotationCommand=sa;exports.AddHighlightCommand=ha;exports.AddLayerCommand=va;exports.BORDER_RADIUS_PX=qn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Wh;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=yg;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=tw;exports.CommandRegistry=Ku;exports.CommandStackManager=zu;exports.Compiler=to;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=JL;exports.DEFAULT_FONT_WEIGHT=ZL;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=Ct;exports.DIVERGING_SCHEME_NAMES=ks;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ae;exports.GraphCompilationSession=WL;exports.HEADLINE_SWATCH_GAP=Zb;exports.HEADLINE_SWATCH_SIZE=Xb;exports.HEADLINE_TREND_GAP=eS;exports.HEADLINE_TREND_ICON_SIZE=Qb;exports.HEADLINE_VALUE_LABEL_GAP=Jb;exports.HeuristicTextMeasurer=sw;exports.HoverEngine=dx;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=Lg;exports.LINE_STYLE_TYPES=dn;exports.LayoutCompiler=Vv;exports.MAX_BAR_WIDTH=rL;exports.MIN_BAR_WIDTH=eu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=vl;exports.NAMED_WEIGHTS=ba;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ea;exports.OUT_OF_VIEW_MARGIN_PX=Qv;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=tm;exports.POSITION_TYPES=Wi;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=J;exports.RemoveAnnotationCommand=ia;exports.RemoveHighlightCommand=pa;exports.RemoveLayerCommand=ya;exports.SCALED_POSITION_AESTHETIC_KEYS=fn;exports.SCALED_VISUAL_AESTHETIC_KEYS=ot;exports.SCHEME_ALIASES=Ps;exports.SEQUENTIAL_SCHEME_NAMES=Hh;exports.SHAPE_DEFAULTS=he;exports.SIBLING_OVERLAP_THRESHOLD_PX=eb;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=ql;exports.SetAxisLabelCommand=Jl;exports.SetAxisPositionCommand=ec;exports.SetAxisTickModeCommand=rc;exports.SetAxisTicksVisibilityCommand=ac;exports.SetAxisVisibilityCommand=sc;exports.SetBarBorderRadiusCommand=Jc;exports.SetBarWidthCommand=tu;exports.SetChartTypeCommand=xl;exports.SetContentCaptionCommand=lc;exports.SetContentSourceCommand=uc;exports.SetContentSubtitleCommand=mc;exports.SetContentTitleCommand=hc;exports.SetCoordLimitsCommand=zc;exports.SetDataLabelsFormatCommand=nu;exports.SetGridLineStyleCommand=vc;exports.SetGridLineWidthCommand=Sc;exports.SetGridVisibilityCommand=Ac;exports.SetHeadlineCompareWithCommand=Tc;exports.SetHeadlinePositionCommand=wc;exports.SetHeadlineShowCommand=Vc;exports.SetHeadlineSizeCommand=Cc;exports.SetHighlightDimStyleCommand=_c;exports.SetLayerPositionCommand=iu;exports.SetLayerStatCommand=ou;exports.SetLayerYScaleTypeCommand=cu;exports.SetLegendAlignCommand=kc;exports.SetLegendDisplayCommand=Mc;exports.SetLegendPositionCommand=Bc;exports.SetLineInterpolationCommand=du;exports.SetLineMissingValuesCommand=pu;exports.SetLineWidthCommand=fu;exports.SetMappingCommand=Hl;exports.SetNumberFormatAbbreviationCommand=$c;exports.SetNumberFormatDecimalsCommand=Uc;exports.SetPointSizeCommand=yu;exports.SetPolarInnerRadiusCommand=qc;exports.SetPolarStartAngleCommand=Xc;exports.SetRuleLabelCommand=bu;exports.SetRuleValueCommand=xu;exports.SetScaleDomainCommand=Pu;exports.SetScalePaletteCommand=Nu;exports.SetScaleReverseCommand=Fu;exports.SetScaleTransformCommand=Gu;exports.SetScaleZeroCommand=Wu;exports.SetStatLineCommand=Iu;exports.SetStyleRuleCommand=de;exports.SpecResolver=Hs;exports.Stat=Re;exports.TAU=xe;exports.TEXT_ANNOTATION_DEFAULTS=Dt;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Lu;exports.ToggleContentVisibilityCommand=Hc;exports.ToggleDataLabelsCommand=Eu;exports.ToggleGoalLineCommand=Ru;exports.ToggleLineFillCommand=Cu;exports.ToggleLinePointsVisibilityCommand=_u;exports.ToggleStackTotalsCommand=Ou;exports.UpdateAnnotationCommand=la;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=Pi;exports.annotation=fA;exports.areAnchorsEqual=Fe;exports.areEditMenuTriggersEqual=wb;exports.areEditTargetsEqual=GL;exports.areEndpointsComparable=Mi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=ol;exports.arePointerRegionListsEqual=bb;exports.arePredicatesEqual=ur;exports.areStyleDeclarationsEqual=pl;exports.areStyleRuleAddressesEqual=mr;exports.buildAverageLineSymbols=qv;exports.buildCalloutHitRegions=Zv;exports.buildColumnKey=Wo;exports.buildDataLabelsContent=jy;exports.buildDiagnostic=Bi;exports.buildEditMenuTriggerRegion=Tb;exports.buildFontString=QL;exports.buildLayerIntroPlan=xx;exports.buildLayerStyleAddress=Ae;exports.buildLayerYValueFormatter=Hn;exports.buildObservationAnchor=st;exports.buildObservationPredicate=mb;exports.buildPinnedNumberValueFormatter=Bb;exports.buildPolarBarArcPath=gS;exports.buildSliceGroupKey=zo;exports.buildTooltipContent=zx;exports.canAnchorDirectLabels=ys;exports.canBecomeCombo=sI;exports.canBecomeHeatmap=oI;exports.canPlaceDataLabels=qy;exports.clampAnnotationTranslation=GA;exports.commandRegistry=b;exports.compileChromeStyles=Ys;exports.compileStylesheetForLayer=Jf;exports.compositeColor=nd;exports.computeArrow=zv;exports.computeDifferenceArrow=Co;exports.computeDirectLabelsLayout=db;exports.computeLineBoxHeight=lA;exports.computePanelBorderPaths=Px;exports.computePanelBorderSizes=Mx;exports.config=l.config;exports.convertSpecToInput=ml;exports.coord=l.coord;exports.countLayerGeoms=Ax;exports.createAlphaValueReader=pd;exports.createAnchorResolver=Cv;exports.createAreaPathGenerators=oS;exports.createColorValueReader=Ui;exports.createCompiler=vg;exports.createDatasetFromKindPartitions=Wd;exports.createEmptyHighlight=vs;exports.createGraphyBuilder=Ag;exports.createGroupValueReader=hd;exports.createHeadlineItemRows=tS;exports.createLabelValueReader=dd;exports.createLineFillAreaGenerator=pS;exports.createLinePathGenerator=mS;exports.createObservationAnchorParser=Ni;exports.createRawValueReader=W;exports.createSegmentYReader=Zt;exports.createSizeValueReader=md;exports.createSpec=ro;exports.createStableBandKeyGenerator=SS;exports.createStableCellKeyGenerator=xS;exports.createStableKeyGenerator=or;exports.createStrokeWidthValueReader=fd;exports.createStyleResolver=ir;exports.createValueFormatter=C;exports.createXValueReader=Ze;exports.createYValueReader=un;exports.cursorToPiePlane=pn;exports.cursorToPolar=Qt;exports.describeMeasurementBasis=$r;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=No;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=ip;exports.findAnnotation=mt;exports.findAverageLineLayer=dl;exports.findAxisGuide=Yn;exports.findDistinctLayers=bn;exports.findEquivalentHighlight=IA;exports.findGoalLineLayer=cl;exports.findHighlightsAtObservation=Vb;exports.findKindStyleDeclarations=ht;exports.findLayerByGeom=le;exports.findLayerById=D;exports.findLegendForAesthetic=qb;exports.findObservationAttachment=ll;exports.findPointerRegion=yb;exports.findStyleRule=dr;exports.findStyleRuleIndex=na;exports.findTrendLineLayer=ul;exports.formatDifferenceLabel=Vo;exports.formatHeadline=Fb;exports.formatLegends=zb;exports.formatRuleValue=jb;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=P;exports.getAlpha=xo;exports.getAngleExtent=Un;exports.getBarRectBounds=Uo;exports.getBoundingRect=dS;exports.getChromeDashArray=oA;exports.getColor=dt;exports.getCrossAxisCoordinate=jt;exports.getCurve=sr;exports.getDashArray=sS;exports.getDifferenceArrowDimensions=Ro;exports.getDifferenceArrowLabelBox=lb;exports.getGroup=K;exports.getHoverGuideLineProps=hx;exports.getHoverGuideRectProps=fx;exports.getInsetTileRect=Lo;exports.getLineType=Ao;exports.getMainAxisCoordinate=Ue;exports.getNumericWeight=Sa;exports.getPolarHoverGuideArcProps=gx;exports.getRadiusExtent=Wn;exports.getRuleDashPattern=bS;exports.getScaledAesthetic=ad;exports.getSize=Gn;exports.getStablePolarBarKeyGenerator=AS;exports.getStackRole=Is;exports.getStrokeWidth=Xr;exports.getTileRectBounds=To;exports.getUnionExtent=vS;exports.getX=R;exports.getXMax=U;exports.getXMin=G;exports.getY=w;exports.getYMax=_;exports.getYMin=k;exports.getYRaw=ln;exports.hasMultipleGroups=er;exports.highlight=AA;exports.inferDefaultDifferenceArrowEndpoints=_b;exports.inferDifferenceArrowEndpoints=$o;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=UA;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=ld;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=vt;exports.isCompanionLayer=vn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=es;exports.isGeomStyleRule=aa;exports.isLayerOf=bg;exports.isLayerOfType=q;exports.isLineStyleType=Hi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=bA;exports.isPointWithinEditMenuTrigger=Lb;exports.isPointWithinRegionShape=zn;exports.isSafeUrl=Wx;exports.isStackedPosition=B;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=VA;exports.normalizeAngle=He;exports.orderPointerRegions=vb;exports.pickReadableTextColor=rd;exports.pipe=no;exports.placeCallouts=ib;exports.polarToUnit=$t;exports.positionToAngle=rs;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=lS;exports.prepareLineObservations=hS;exports.projectAnchorToPanel=Po;exports.quantiseKey=Y;exports.readAnchoredObservation=kb;exports.readAttachedObservation=ta;exports.readAuthoredNumber=tA;exports.readAuthoredString=rA;exports.readChartType=iI;exports.readComboLineLayerId=lI;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Oc;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=KL;exports.readMappedVariable=zl;exports.readObservationIndex=yx;exports.readXExtent=al;exports.readYExtent=il;exports.resolveAnchorVariable=we;exports.resolveArrowColor=cb;exports.resolveAxisLabelStyle=uA;exports.resolveBarBandFraction=Hr;exports.resolveBarBorderRadiusPx=Go;exports.resolveBarBorderTreatment=uS;exports.resolveBarCornerRadiiPx=cS;exports.resolveColorRamp=Tn;exports.resolveComparisonBasis=gs;exports.resolveDataLabelStyle=mA;exports.resolveDeferredAnchors=Mv;exports.resolveDefinition=In;exports.resolveGraphChromeStyle=sA;exports.resolveGridLineStyle=aA;exports.resolveHeadlinePlacement=Av;exports.resolveObservationPoint=Pb;exports.resolvePanelBorderStyle=nA;exports.resolvePolarBarCornerRadiusUnit=yS;exports.resolveRuleLabelStyle=pA;exports.resolveSegmentYSource=Xt;exports.resolveTextStyle=se;exports.resolveTickLabelStyle=dA;exports.resolveTickLineStyle=iA;exports.resolveTooltipStyle=hA;exports.resolveYScaleAesthetic=oe;exports.sampleColorScheme=jh;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Mb;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=cA;exports.toPanelCursor=Mo;exports.toPercent=ve;exports.toViewBoxX=_v;exports.toViewBoxY=ne;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=io;exports.uniqueId=M;exports.unitToPolar=ns;exports.updateSpec=E;
|
|
23
|
+
`,tv=(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},rv=(e,t,r)=>Math.abs(e?t.y-r.y:t.x-r.x),Co=({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=Ro(e.size,a),d=Zy(s,o,c,u),m=(s?Qy:Jy)(o,c,d,u),h=ev(s,c,u),p=tv(s,o,c,d,rv(s,o,c),e.labelCrossPosition),f=Vo({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:h,labelPosition:p,labelText:f,strokeWidth:u.strokeWidth,labelLineHeight:u.labelLineHeight,labelPaddingX:u.labelPaddingX,labelPaddingY:u.labelPaddingY,labelStrokeWidth:u.labelStrokeWidth,labelFontWeight:u.labelFontWeight}};function*nv({annotations:e,mainAxis:t,panelRect:r,textScale:n,locale:a,measureLabel:i}){for(const s of e.differenceArrows){if(!We(s.start.x,s.start.y)||!We(s.end.x,s.end.y))continue;const o=Co({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 av=e=>{const t=e.padding,r=Ja(e.rows,t?.top??0,t?.bottom??0),n=Ja(e.cols,t?.left??0,t?.right??0);return{rows:r.tracks,cols:n.tracks,placements:lv(e.placements,r.nameToIndex,n.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},iv=e=>{const t=Qa(e.rows,e.height),r=Qa(e.cols,e.width),n=ei(t),a=ei(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=ti(r,s.col,c),h=ti(t,s.row,o);i.set(s.name,{x:u,y:d,width:Math.max(0,m),height:Math.max(0,h)})}return i},Ja=(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;Zr(o)&&i>0&&(n.push({type:"fixed",pixels:i}),i=0),a.set(o.name,n.length),n.push(sv(o));const c=ov(e,s);if(Zr(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}},sv=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},Zr=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,ov=(e,t)=>{for(let r=t+1;r<e.length;r++){const n=e[r];if(n&&Zr(n))return n}},lv=(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},Qa=(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)},ei=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},ti=(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},Ye={top:0,right:0,bottom:0,left:0},Do={outer:Ye,inner:Ye},cv={top:24,right:24,bottom:24,left:24},uv=(e,t,r,n=Ye,a=Do,i=cv,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=ri(Lg,s),d=ri(wg,s);return av({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"},...mv(r.axes),...pv(r.axesLabels,r.axes),...hv(r.legends)],containerSize:e,padding:i})},dv=(e,t)=>l.isDefined(t)?typeof t=="number"?{before:e.before,after:Cr(t,e.after)}:{before:Cr(t.before,e.before),after:Cr(t.after,e.after)}:e,Cr=(e,t)=>typeof e=="number"&&Number.isFinite(e)?e:t,ri=(e,t)=>{const r={};for(const n of Object.keys(e))r[n]=dv(e[n],t[n]);return r},mv=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},pv=(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},hv=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 fv=class{constructor(e){this.outer={...Ye},this.inner={...Ye},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)))}},gv=["top","right","bottom","left"],Dr=(e,t)=>{const r={};for(const n of gv){const a=e.get(`${n}${t}`);a&&(r[n]=a)}return r};function ni(e,t){return e.top===t.top&&e.right===t.right&&e.bottom===t.bottom&&e.left===t.left}var Jr=["large","medium","small"],yv=({size:e,availableWidth:t,measureStripWidth:r})=>{if(e!=="auto")return e;for(const n of Jr)if(r(n)<=t)return n;return"small"},vv=({size:e,availableWidth:t,measureStripWidth:r})=>{const n=e==="auto"?0:Jr.indexOf(e);for(const a of Jr.slice(n))if(r(a)<=t)return a;return null},bv=({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},Sv=({headline:e,containerSize:t,measurer:r})=>{if(_o(e))return 0;const n=Oo(e,t.width,r);return r.measureHeadline(e.formatted,n).height},xv=({headline:e,layout:t,containerSize:r,measurer:n,itemGap:a})=>{if(_o(e)){const o=Av(t.panel,e.innerRadius),c=vv({size:e.size,availableWidth:o.width,measureStripWidth:ko(e,n)});return c===null?null:{rect:o,resolvedSize:c,visibleItemCount:1}}const i=Oo(e,r.width,n);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:i,visibleItemCount:1};const s=bv({itemWidths:n.measureHeadlineItemWidths(e.formatted,i),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:i,visibleItemCount:s}},_o=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Av=(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}},Oo=(e,t,r)=>yv({size:e.size,availableWidth:t,measureStripWidth:ko(e,r)}),ko=(e,t)=>r=>t.measureHeadline(e.formatted,r).width,Pe={x:0,y:0,width:0,height:0},Iv="0000",Tv=3,et=e=>typeof e=="number"&&Number.isFinite(e)?e:24,Lv=e=>e.plot.y+e.plot.height-e.panel.y,wv=e=>{if(typeof e=="object"&&e!==null)return{top:et(e.top),right:et(e.right),bottom:et(e.bottom),left:et(e.left)};const t=et(e);return{top:t,right:t,bottom:t,left:t}},Ev=class{constructor(e){this.measurer=e}compile(e){return qt({axes:e.axes,numberFormat:e.numberFormat,formattedLegends:e.formattedLegends,containerSize:e.containerSize,externalMeasurements:e.externalMeasurements,panelOverflow:Do,panelBorder:e.panelBorder??Ye,headline:e.headline,locale:e.formattingLocale??e.parsingLocale,padding:wv(e.layout.padding),gaps:e.layout.gaps}).pipe(({axes:t,numberFormat:r,locale:n})=>({axisBundles:t.map(a=>({axis:a,resolveFormatter:Vv(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=>ai(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=>ai(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:Lv(n)}}).result()}measurePanelOverflow(e,t,r,n){if(!e.overflowStrategy||e.coordSystem?.type!=="cartesian")return n;const a=new fv(t);if(e.annotations&&e.overflowStrategy.differenceArrows)for(const s of nv({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 Xy({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 ni(i.inner,n.inner)&&ni(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 h=t,p=s;for(let f=0;f<Tv;f++){const g=this.measurePanelOverflow(e,h.panelFrame,u,p);if(g===p)break;p=g,h=this.resolveLayout({axes:r,formattedLegends:n,containerSize:a,externalMeasurements:i,panelOverflow:g,panelBorder:o,headline:c,padding:d,gaps:m})}return h}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?ii(r,a,0,0):ii(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=P(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:Iv}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(e,t,r){const n=e.position==="top"||e.position==="bottom"?r.width:r.height,a=P(e.scaleAestheticKey),i=d=>this.measurer.measureTickLabel(d,a),s=jg({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?Hg({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=iv(uv(r,n,this.measureGuides(e,t,s,r),i,a,o,c));return{header:u.get("header")??Pe,headline:u.get("headline")??Pe,footer:u.get("footer")??Pe,plot:u.get("plot")??Pe,panelFrame:u.get("panelFrame")??Pe,panel:u.get("panel")??Pe,axes:Dr(u,"Axis"),axisLabels:Dr(u,"AxisLabel"),legends:Dr(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:Sv({headline:e,containerSize:t,measurer:this.measurer})}},ai=e=>e==="left"||e==="right",ii=(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}}},Vv=(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=Nn({valueFormat:i.valueFormat??e.valueFormat,locale:t,numberFormat:r,tickValues:n});return a.set(i,o),o}},Rv=(e=[])=>{const t=Cv(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,createLayerMeasurement:r=>t.has(r.geom)?zi(r,t.get(r.geom)):null}},Cv=e=>{const t=new rr;for(const r of e){const n=In(r);n instanceof ae&&t.register(n.type,n)}return t};function Dv(e){return e}function ne(e){return 1-e}var ve=e=>`${Number.parseFloat((e*100).toFixed(4))}%`,Po=(e,t,r)=>{if(r.type!=="polar")return{x:e.x*t.width,y:ne(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}},_v=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 wt(e);const{x:s,y:o}=Qr(e.defer,this.panelRect);return wt({...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=it(r,e.defer.align),{x:a,y:i}=Ov(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 wt(e);const{x:i,y:s}=Qr(e.defer,this.panelRect);return wt({...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:kv(r)}case"arrow":{const r=this.resolvePoint(t.annotation.start),n=this.resolvePoint(t.annotation.end);return r===null||n===null?null:si(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=Pi(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:oi(r)}case"differenceArrow":return si(t.annotation.start,t.annotation.end);case"pinnedNumber":case"comment":return oi(t.annotation.at)}}},Qr=(e,t)=>({x:t.width>0?e.x/t.width:0,y:t.height>0?e.y/t.height:0}),Ov=(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}=Qr({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}},kv=e=>({xMin:e.x,xMax:e.x+e.width,yMin:e.y,yMax:e.y+e.height}),si=(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)}),oi=e=>({xMin:e.x,xMax:e.x,yMin:e.y,yMax:e.y}),wt=e=>{const t={...e};return delete t.defer,t},Pv=e=>{const{annotations:t,panelRect:r,coordSystem:n,measuredBoxes:a,onCycle:i,onMissingRef:s}=e;if(!Mv(t))return t;const o=new _v(t,r,n,a),c={...t,shapes:tt(t.shapes,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),images:tt(t.images,m=>m.region.defer!==void 0,m=>{const h=o.resolveRegion(m.region);return h===null?null:{...m,region:h}}),arrows:tt(t.arrows,m=>m.start.defer!==void 0||m.end.defer!==void 0,m=>{const h=o.resolvePoint(m.start),p=o.resolvePoint(m.end);return h===null||p===null?null:{...m,start:h,end:p}}),textAnnotations:tt(t.textAnnotations,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}}),stickers:tt(t.stickers,m=>m.at.defer!==void 0,m=>{const h=o.resolvePoint(m.at);return h===null?null:{...m,at:h}})},u=o.cyclicIds();u.length>0&&i?.(u);const d=o.missingRefIds();return d.length>0&&s?.(d),c},tt=(e,t,r)=>e.some(t)?e.flatMap(n=>{if(!t(n))return[n];const a=r(n);return a===null?[]:[a]}):e,Mv=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),Nv=800,li=400,Bv={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}}},Fv=e=>Math.max(1,(e-li)/(Nv-li)+1),$v=(e,t)=>{const r=Fv(t),n=Bv[e];return{strokeWidth:Math.min(n.strokeWidth.targetValue,n.strokeWidth.minValue*r),arrowheadLength:Math.min(n.arrowheadLength.targetValue,n.arrowheadLength.minValue*r)}},Et=Math.PI/4,en=1.5,Gv=({startX:e,startY:t,endX:r,endY:n})=>`M ${e} ${t} L ${r} ${n}`,ci=(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-Et)} ${c-r*Math.sin(u-Et)} M ${o} ${c} L ${o-r*Math.cos(u+Et)} ${c-r*Math.sin(u+Et)}`},Uv=(e,t)=>e==="solid"?null:`${t*en} ${t*en*2}`,Wv=(e,t)=>t?e*en:0,Hv=64,Kv=({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}=$v(e.thickness,t),s=Math.hypot(n.endX-n.startX,n.endY-n.startY),o=zv(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:Gv(n),startArrowheadPath:c?ci("start",n,o):"",endArrowheadPath:u?ci("end",n,o):"",color:e.color,strokeWidth:a,dashArray:Uv(e.lineStyle,a),hasStickerStyle:e.hasStickerStyle,startX:n.startX,startY:n.startY,endX:n.endX,endY:n.endY,dashOffset:Wv(a,c),arrowheadExtent:d}},zv=(e,t)=>Math.min(e,t*e/Hv);function Yv(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=qv(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 qv(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 Mo=(e,t)=>({x:e.x/t.width,y:1-e.y/t.height}),jv=0,Xv=(e,t)=>e.filter(r=>r.inView).map(r=>({shape:{kind:"rect",rect:r.miniRect},cursor:Mo(r.anchorPx,t),tooltip:{kind:"pinned",point:r.anchorPx,placement:r.placement,annotationId:r.id},priority:jv})),Zv=9,Jv=8,Qv=2,No=e=>typeof e=="string"?e:Bo(e),Bo=e=>e.text!==void 0?e.text:e.content?e.content.map(Bo).join(""):"",ui={top:"bottom",bottom:"top",right:"left",left:"right"};function eb(e,t,r){return r.type==="polar"?nb(e,t):r.mainAxis==="y"?["right","left","top","bottom"]:["top","bottom","right","left"]}function tn(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 di(e,t){return e.x>=0&&e.y>=0&&e.x+e.width<=t.width&&e.y+e.height<=t.height}function tb(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 rb(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 nb(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,ui[s],o,ui[o]]}function ab(e){const{pinnedNumbers:t,comments:r,panelRect:n,coordSystem:a,measurer:i,formatPinnedNumber:s}=e,o=[...t.map(d=>{const{id:m,at:h}=d;return mi(m,"pinned-number",h,s(d),i,n,a)}),...r.map(({id:d,at:m,content:h})=>mi(d,"comment",m,No(h),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(pi(n,d,"top"));continue}const m=pi(n,d,sb(n,d,a,u));c.push(m),u.push(m.miniRect)}return c}function mi(e,t,r,n,a,i,s){const o=Po(r,i,s);return{id:e,kind:t,anchor:r,anchorPx:o,mini:a(t,n),inView:ib(o,i)}}function ib(e,t){return e.x>=-8&&e.y>=-8&&e.x<=t.width+8&&e.y<=t.height+8}function sb(e,t,r,n){const a=eb(t.anchorPx,e,r);for(const i of a){const s=tn(t.anchorPx,i,t.mini);if(di(s,e)&&!n.some(o=>rb(s,o)))return i}for(const i of a)if(di(tn(t.anchorPx,i,t.mini),e))return i;return"top"}function pi(e,t,r){return{id:t.id,kind:t.kind,anchorPx:t.anchorPx,placement:r,miniRect:tb(e,tn(t.anchorPx,r,t.mini)),text:t.mini.text,inView:t.inView}}var ob=({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}},lb=(e,t,r,n)=>e!==null?e:t.anchor.layerId!==r.anchor.layerId||!l.areDataValuesEqual(t.anchor.groupValue??null,r.anchor.groupValue??null)||n.start===void 0||n.start!==n.end?null:n.start,cb=100,ub=({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,h=d.y-a;if(m>h){s=!0,i=!0;const p=(m-h)/2+1;u.y-=p,d.y+=p,u.y<0&&(u.y=0),d.y>t&&(d.y=t)}}if(o>cb)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}},db=(e,t)=>{const r=Yi(e),n=pb(t,mb(e),r);if(n===null)return null;const a=hb(e,n,r)?fb(e,t,n,r):n,[i]=a;return i===void 0?null:a.length===1?i:{and:a}},mb=e=>{const t=Je(e.data,e.mapping),r=we(e);return r===l.GROUP_VARIABLES.group?[...new Set(t)]:[...new Set([r,...t])]},pb=(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},hb=(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},fb=(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}]},zn=(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},gb=(e,t)=>{for(const r of t)if(zn(e,r.shape))return r;return null},yb=e=>{const t=[];for(const r of e.values())t.push(...r);return t.sort((r,n)=>n.priority-r.priority)},vb=(e,t)=>e===t?!0:e.length!==t.length?!1:e.every((r,n)=>bb(r,t[n])),bb=(e,t)=>t===void 0?!1:e.priority===t.priority&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y&&Sb(e.shape,t.shape)&&xb(e.tooltip,t.tooltip),Sb=(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},xb=(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},Ab=100,Ib=e=>({shape:{kind:"circle",center:e.center,radius:e.radius},cursor:e.target.cursor,tooltip:{kind:"cursor"},priority:Ab}),Tb=(e,t)=>zn(e,{kind:"circle",center:t.center,radius:t.radius}),Lb=(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&&wb(e.target,t.target),wb=(e,t)=>e.kind===t.kind&&e.cursor.x===t.cursor.x&&e.cursor.y===t.cursor.y,Eb=({layer:e,highlights:t,observation:r,parsingLocale:n})=>{if(e.highlight===null)return[];const a=Jt(e,n),i=Vb(e,r);return t.filter(s=>{if(s.layerId!==void 0&&s.layerId!==e.id||Se(s.predicate,e.data).length>0)return!1;const o=be(s.predicate,a);return o(r)?!0:Dp(s.scope)&&i(s.scope).some(o)})},Vb=(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=Gt(a,t,r),o=[];for(const c of e.data)Gt(a,c,r)===s&&o.push(c);return n.set(a,o),o}},Ot=({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?Cb(c,s):c;if(u<0||u>=s)break;const d=e.data.getAt(u);if(d===null||!n(d,u))continue;const m=st(e,d);if(m!==null&&!a.some(h=>Fe(m,h)))return{anchor:m,observation:d,observationIndex:u}}return null},Fo=(e,t,r)=>{const n=Yt(e);let a=0;for(const i of e.data){if(Rb(i,t,r,n))return a;a+=1}return-1},Rb=(e,t,r,n=null)=>l.areDataValuesEqual(e[r]??null,t.anchorValue)?n!==null?t.crossValue===void 0||l.areDataValuesEqual(e[n]??null,t.crossValue):t.groupValue===void 0?!0:l.areDataValuesEqual(K(e),t.groupValue):!1,Fe=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),Cb=(e,t)=>(e%t+t)%t,$o=({layer:e,at:t,coordSystem:r})=>{if(r.type!=="cartesian"||e.identityKey==="x-y")return null;const n=we(e),a=Fo(e,t,n),i=e.data.getAt(a);if(i===null)return null;const s=K(i),o=h=>l.areDataValuesEqual(K(h),s),c=[t],u=Ot({layer:e,excluding:c,from:a+1,step:1,accepts:o});if(u!==null)return{start:t,end:u.anchor};const d=Ot({layer:e,excluding:c,from:a-1,step:-1,accepts:o});if(d!==null)return{start:d.anchor,end:t};const m=Ot({layer:e,excluding:c,from:0,step:1,accepts:h=>!o(h)&&l.areDataValuesEqual(h[n]??null,t.anchorValue)});return m!==null?{start:t,end:m.anchor}:null},Db=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=st(r,n);if(a===null)continue;const i=$o({layer:r,at:a,coordSystem:e.coordSystem});if(i!==null&&!t.some(s=>_b(s,i)))return i}return null},_b=(e,t)=>Fe(e.start,t.start)&&Fe(e.end,t.end)||Fe(e.start,t.end)&&Fe(e.end,t.start),Ob=(e,t)=>{const r=e.find(a=>a.id===t.anchor.layerId);if(r===void 0)return null;const n=r.data.getAt(t.observationIndex);return n===null?null:{layer:r,observation:n}},kb=({resolver:e,layer:t,observation:r,observationIndex:n,coordSystem:a,align:i,measurement:s})=>{const o=e.resolve(t.geom,r,{coordSystem:a,position:t.position,purpose:"value",align:i});if(o===null)return null;const c=s??e.createLayerMeasurement(t);if(c===null)return null;const u=Zi(t,r,c);if(u===null)return null;const d=st(t,r);return d===null?null:{...o,...u,observationIndex:n,anchor:i===void 0?d:{...d,align:i}}},Pb=({layer:e,from:t,partner:r,axis:n,step:a,getObservationPoint:i})=>{const s=we(e),o=Fo(e,t,s),c=e.data.getAt(o);if(c===null)return null;const u=Mb(c),d=n==="main"?u:p=>!u(p)&&l.areDataValuesEqual(p[s]??null,t.anchorValue),m=Ot({layer:e,excluding:[t,r],from:o+a,step:a,accepts:(p,f)=>d(p)&&i(p,f)!==null,cycles:n!=="main"});if(m===null)return null;const h=i(m.observation,m.observationIndex);return h===null?null:{...m,point:h}},Mb=e=>{const t=K(e);return r=>l.areDataValuesEqual(K(r),t)};function Nb({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 Bb=({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"?Fb(e,s,r):$b(e,t,s,r,i)},Fb=(e,t,r)=>({kind:"grandTotal",value:C({valueFormat:e.valueFormat,locale:t,numberFormat:r})(e.value)}),$b=(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=Nn({valueFormat:o.mainValueFormat,locale:r,numberFormat:n,tickValues:[]}),m=o.label??u(o.value);return{swatch:o.swatch,label:Hb(t,s,m,a),value:o.aggregate===null?null:c(o.aggregate),observationLabel:Wb(o.observationLabel,d),comparison:Gb(o.comparison,d,i,a)}})}},Gb=(e,t,r,n)=>e===null?null:{direction:Ub(e.variation),percentage:r(Math.abs(e.variation)),reference:n("graph.headlineMetrics.comparisonReference",{value:t(e.against)})},Ub=e=>e>0?"up":e<0?"down":"flat",Wb=(e,t)=>e===null?null:e.kind==="point"?t(e.value):`${t(e.from)} – ${t(e.to)}`,Hb=(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}},Kb=({legends:e,numberFormat:t,parsingLocale:r,formattingLocale:n})=>{const a=n??r;return e.map(i=>zb(i,a,t))},zb=(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 Yn(e,t){return e.axes.find(r=>r.scaleAestheticKey===t)??null}function Yb(e,t){return e.legends.drawn.find(r=>r.aesthetics.includes(t))??null}var qb=({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?un:Ze)(r.data,r.mapping)(a);return s===null?null:C({valueFormat:Yn(e,i?oe(r.yScaleType):"x")?.valueFormat??{type:"decimal"},locale:n,numberFormat:t})(s)},jb=12,Xb=4,Zb=4,Jb=12,Qb=4,eS=e=>{const{value:t,observationLabel:r,comparison:n,swatch:a,label:i}=e;return[{role:"valueRow",gap:4,segments:_r([Vt("value","value",t??"–"),Vt("observation","label",r)])},{role:"trendRow",gap:4,ariaLabel:n===null?void 0:aS(n),segments:_r([rS(n),nS(n),Vt("trendReference","label",n?.reference??null)])},{role:"groupRow",gap:4,segments:_r([tS(a),Vt("label","label",i)])}].filter(s=>s.segments.length>0)},Vt=(e,t,r)=>r===null?null:{kind:"text",textRole:e,fontRole:t,text:r},tS=e=>e===null?null:{kind:"swatch",swatch:e,size:12},rS=e=>e===null?null:{kind:"trendArrow",direction:e.direction,size:12},nS=e=>e===null?null:{kind:"text",textRole:"trendPercentage",fontRole:"label",text:e.percentage,trendDirection:e.direction},aS=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}`}},_r=e=>e.filter(t=>t!==null),sr=e=>e==="catmull-rom"?Ie.curveCatmullRom:Ie.curveLinear,iS=e=>{switch(e){case"dashed":return"8 4";case"dotted":return"2 2";case"solid":return}},sS=(e,t)=>{const r=sr(t.interpolate),n=(0,Ie.area)().curve(r),a=(0,Ie.line)().curve(r);if(e.mainAxis==="y"){const i=c=>ne(w(c)??0),s=c=>G(c)??0,o=c=>U(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=>ne(k(c)??0),o=c=>ne(_(c)??w(c)??0);n.x(i).y0(s).y1(o),a.x(i).y(o)}if(t.missingValues==="gap"){const i=s=>R(s)!==null&&w(s)!==null;n.defined(i),a.defined(i)}return{lineGenerator:a,areaGenerator:n}},oS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),qn={none:0,xs:2,sm:4,md:8,lg:12,xl:16},Go=e=>{if(e.borderRadius==="full"){const{width:t,height:r}=e.bounds;return(e.mainAxis==="x"?t:r)/2}return qn[e.borderRadius??"sm"]},lS=e=>{const t=Go(e);return e.borderRadius==="full"?e.mainAxis==="x"?{rx:t}:{ry:t}:{rx:t}},cS=e=>({outlineWidth:e*2,separatorWidth:e,insetOffset:e/2}),Uo=(e,t)=>{const r=G(t),n=U(t),a=k(t),i=_(t)??w(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}},Wo=(e,t)=>e==="x"?`${Y(t.x)}-${Y(t.width)}`:`${Y(t.y)}-${Y(t.height)}`,uS=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}},dS=e=>{const t=(0,Ie.line)().x(r=>R(r)??0).y(r=>ne(w(r)??0)).curve(sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ho),t},mS=e=>{const t=(0,Ie.area)().x(r=>R(r)??0).y0(()=>1).y1(r=>ne(w(r)??0)).curve(sr(e.interpolate));return e.missingValues==="gap"&&t.defined(Ho),t},pS=(e,t)=>t!=="connect"?e:e.filter(r=>R(r)!==null&&w(r)!==null),Ho=e=>R(e)!==null&&w(e)!==null,Ko=(0,Ie.arc)().cornerRadius(e=>e.cornerRadius??0);Ko.digits(8);var hS=200,fS=e=>Ko(e)??void 0,gS=(e,t)=>e==="full"?Math.max(0,t)/2:qn[e??"sm"]/hS,zo=(e,t)=>e==="x"?`${Y(t.startAngle)}-${Y(t.endAngle)}`:e==="y"?`${Y(t.innerRadius)}-${Y(t.outerRadius)}`:"sweep",yS=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}},vS=(e,t)=>e==="solid"?[]:e==="dotted"?[0,t*2]:[t*2,t*3],or=(e,t,r)=>{const n=Ze(e,t);return a=>{const i=K(a)??"default",s=n(a);return`${r}-${i}${s!==null&&s!==""?`-${s}`:""}`}},bS=(e,t,r)=>{const n=Ze(e,t);return a=>{const i=n(a);return i===null||i===""?null:`${r}-${i}`}},SS=(e,t,r)=>{const n=Ze(e,t),a=un(e,t),i=new Map;return s=>{const o=n(s),c=a(s),u=o!==null&&o!==""&&c!==null&&c!==""?`${r}-${o}-${c}`:`${r}-cell`,d=i.get(u)??0;return i.set(u,d+1),d===0?u:`${u}#${d}`}},xS=()=>(e,t)=>dt(e)??`default-${t}`;function jn(e,t,r){return Math.hypot(e*r,t)}function Wt(e,t,r){return e<t?t-e:e>r?e-r:0}function ue(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 AS(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,observationIndex:s.observationIndex,x:s.x,y:s.y,observation:s.observation},index:e,distance:jn(s.x-t.x,s.y-t.y,r)}:null}function IS(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 Yo(e,t){return Xn(e.buckets,t,r=>r.main)}function TS(e,t){return Xn(e.bands,t,r=>r.bandCenter)}function qo(e,t){return Xn(e.columns,t,r=>r.mainMid)}function Xn(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 LS(e,t){return{group:wS(e),related:CS(e,t)}}function wS(e){switch(e.kind){case"buckets":{const t=e.match.index;return B(t.position)?ES(t.layerId,e.match.bucket,e.match.hit.pointIndex):[]}case"banded":{const{index:t,column:r,hit:n}=e.match;return B(t.position)?VS(t.layerId,r,n.pointIndex):RS(t.bands,t.layerId,r,n.pointIndex)}case"points":case"enclosure":case"render-hit-test":return[]}}function ES(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 VS(e,t,r){const n=[];for(const a of t.rects)a.pointIndex!==r&&n.push(Zn(e,a));return n}function RS(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(Zn(t,o));return i}function CS(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||_S(r,i,e.match.hit);continue}e.kind==="buckets"&&(B(i.position)||i.kind==="buckets"&&DS(r,i.layerId,e.match.bucket,e.match.hit.pointIndex))}return r}function DS(e,t,r,n){for(const a of r.entries)a.pointIndex!==n&&kt(e,t).push({anchored:!0,layerId:t,pointIndex:a.pointIndex,x:a.x,y:a.y,observation:a.observation})}function _S(e,t,r){switch(t.kind){case"buckets":{const n=Yo(t,Ue(t.mainAxis,r));if(!n)return;const a=kt(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=TS(t,Ue(t.mainAxis,r));if(!n)return;const a=kt(e,t.layerId);for(const i of n.columns)for(const s of i.rects)a.push(Zn(t.layerId,s));return}case"points":{const n=IS(t,r);if(!n)return;kt(e,t.layerId).push({anchored:!0,layerId:t.layerId,pointIndex:n.pointIndex,observationIndex:n.observationIndex,x:n.x,y:n.y,observation:n.observation});return}case"enclosure":return;case"noop":return;case"render-hit-test":return}}function kt(e,t){let r=e.get(t);return r||(r=[],e.set(t,r)),r}function Zn(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 jo(e,t,r){const{columns:n,bands:a}=OS(e,t);return{kind:"banded",layerId:e.id,geom:e.geom,position:e.position,projection:r,mainAxis:t,columns:n,bands:a}}function OS(e,t){const r=kS(e,t);r.sort((o,c)=>o.mainMid-c.mainMid);const n=new Map,a=new Map;for(const o of r){const c=Y(o.mainMid);let u=n.get(c);if(!u){u={mainMid:o.mainMid,rects:[]},n.set(c,u);const d=Y(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 kS(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 h of r){const p=n[m],f=a[m],g=i[m],y=s[m];if(!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)||!l.isDefined(y)){m++;continue}const v=o?(g+y)/2:(p+f)/2,x=u?.[m]??v;d.push({mainMid:v,bandCenter:x,entry:{pointIndex:m,xMin:Math.min(p,f),xMax:Math.max(p,f),yMin:Math.min(g,y),yMax:Math.max(g,y),observation:h}}),m++}return d}var PS=1e-9;function Xo(e,t,r){const n=MS(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)<=PS?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 MS(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=B(e.position),m=d?r.getValues(c,{type:"numeric"}):null,h=d?r.getValues(u,{type:"numeric"}):null,p=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=p?.[g]??null,A=o?x:v;if(d){const V=m?.[g],j=h?.[g];if(!l.isDefined(V)||!l.isDefined(j)){g+=1;continue}const ie=o?j:v,z=o?x:j;f.push({main:A,entry:{isStacked:d,pointIndex:g,x:ie,y:z,stackMin:V,stackMax:j,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 Zo(e,t){return{kind:"enclosure",layerId:e.id,geom:e.geom,position:e.position,projection:t,cells:NS(e,t)}}function NS(e,t){const r=e.data;if(r.size()===0)return[];const n=[l.POSITION_VARIABLES.xMin,l.POSITION_VARIABLES.xMax,l.POSITION_VARIABLES.yMin,l.POSITION_VARIABLES.yMax];for(const m of n)if(!r.hasVariable(m))return[];const a=r.getValues(l.POSITION_VARIABLES.xMin,{type:"numeric"}),i=r.getValues(l.POSITION_VARIABLES.xMax,{type:"numeric"}),s=r.getValues(l.POSITION_VARIABLES.yMin,{type:"numeric"}),o=r.getValues(l.POSITION_VARIABLES.yMax,{type:"numeric"}),c=t==="cartesian",u=[];let d=0;for(const m of r){const h=a[d],p=i[d],f=s[d],g=o[d];if(!l.isDefined(h)||!l.isDefined(p)||!l.isDefined(f)||!l.isDefined(g)){d++;continue}if(c&&!dt(m)){d++;continue}u.push({pointIndex:d,xMin:h,xMax:p,yMin:f,yMax:g,observation:m}),d++}return u}function rn(e){return{kind:"noop",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian"}}function BS(e,t){const r={kind:"points",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",points:Qo(e),delaunay:null,delaunayAspectRatio:null};return Jo(r,t),r}function FS(e){const t=Qo(e).map(r=>{const n=$t(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 Jo(e,t){e.delaunay&&e.delaunayAspectRatio===t||(e.delaunay=ed.Delaunay.from(e.points,r=>r.x*t,r=>r.y),e.delaunayAspectRatio=t)}function Qo(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];l.isDefined(o)&&l.isDefined(c)&&a.push({pointIndex:a.length,observationIndex:i,x:o,y:c,observation:s}),i+=1}return a}function el(e){return{kind:"render-hit-test",layerId:e.id,geom:e.geom,position:e.position,projection:"cartesian",byKey:$S(e)}}function tl(e,t){return{anchored:!1,layerId:e,pointIndex:t.pointIndex,observation:t.observation}}function $S(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 hi(e,t,r){return t.type==="polar"?GS(e,t.bandAxis):US(e,t.mainAxis,r)}function GS(e,t){switch(e.spatialKind){case"points":return FS(e);case"buckets":return Xo(e,"x","polar");case"rects":return t===null?Zo(e,"polar"):jo(e,t,"polar");case"cells":return rn(e);case"noop":return rn(e);case"render-hit-test":return el(e);default:{const r=e.spatialKind;throw new l.InternalError({message:`buildPolarLayerIndex: unhandled spatialKind ${String(r)}`})}}}function US(e,t,r){switch(e.spatialKind){case"points":return BS(e,r);case"buckets":return Xo(e,t,"cartesian");case"rects":return jo(e,t,"cartesian");case"cells":return Zo(e,"cartesian");case"noop":return rn(e);case"render-hit-test":return el(e);default:{const n=e.spatialKind;throw new l.InternalError({message:`buildCartesianLayerIndex: unhandled spatialKind ${String(n)}`})}}}function WS(e,t,r){if(e.columns.length===0)return null;const n=qo(e,Ue(e.mainAxis,t)),a=n?.rects??[];if(!n||!l.isNonEmptyArray(a))return null;const i=B(e.position)?HS(a,t,e.mainAxis):KS(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:rl(i,t,r)}}function HS(e,t,r){const n=jt(r,t);return ue(e,i=>zS(i,r,n),{shortCircuitOnZero:!0})}function KS(e,t,r){return ue(e,a=>rl(a,t,r))}function rl(e,t,r){return jn(Wt(t.x,e.xMin,e.xMax),Wt(t.y,e.yMin,e.yMax),r)}function zS(e,t,r){return Wt(r,t==="x"?e.yMin:e.xMin,t==="x"?e.yMax:e.xMax)}function YS(e,t,r){if(e.buckets.length===0)return null;const{main:n,cross:a}=od(e.mainAxis,t),i=Yo(e,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=nl(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:jn(o.x-t.x,o.y-t.y,r)}}function nl(e,t,r){return ue(e,a=>Math.abs(jt(r,a)-t))}function qS(e,t){if(e.cells.length===0)return null;for(const r of e.cells)if(!(t.x<r.xMin||t.x>r.xMax)&&!(t.y<r.yMin||t.y>r.yMax))return{hit:{anchored:!0,layerId:e.layerId,pointIndex:r.pointIndex,x:(r.xMin+r.xMax)/2,y:(r.yMin+r.yMax)/2,observation:r.observation},index:e};return null}function jS(e,t,r){if(e.columns.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=e.mainAxis==="x",s=i?XS(e.columns,n):qo(e,a),o=s?.rects??[];if(!s||!l.isNonEmptyArray(o))return null;const c=i?ZS(o,a):JS(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 XS(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Ft(t,r.mainMid)):null}function ZS(e,t){return ue(e,r=>Wt(t,r.yMin,r.yMax),{shortCircuitOnZero:!0})}function JS(e,t){return ue(e,r=>ts(t,r.xMin,r.xMax)?0:Math.min(Ft(t,r.xMin),Ft(t,r.xMax)),{shortCircuitOnZero:!0})}function QS(e,t,r){if(e.buckets.length===0)return null;const{angle:n,radius:a}=Qt(t,r),i=ex(e.buckets,n),s=i?.entries??[];if(!i||!l.isNonEmptyArray(s))return null;const o=nl(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 ex(e,t){return l.isNonEmptyArray(e)?ue(e,r=>Ft(r.main,t)):null}function tx(e,t,r){if(e.cells.length===0)return null;const{angle:n,radius:a}=Qt(t,r);for(const i of e.cells)if(!(a<i.yMin||a>i.yMax)&&ts(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 rx(e,t,r){if(!l.isNonEmptyArray(e.points))return null;const{x:n,y:a}=pn(t,r),i=ue(e.points,s=>fi(s,n,a));return{hit:{anchored:!0,layerId:e.layerId,pointIndex:i.pointIndex,observationIndex:i.observationIndex,x:i.x,y:i.y,observation:i.observation},index:e,distance:Math.sqrt(fi(i,n,a))}}function fi(e,t,r){const n=e.unitX??$t(e.x,e.y).x,a=e.unitY??$t(e.x,e.y).y,i=n-t,s=a-r;return i*i+s*s}var nx=.05;function ax({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=lx(o,t,a);if(u)return{kind:"render-hit-test",match:u};continue}if(o.projection==="polar"){const u=ox(o,t,r);if(u)return u;continue}const c=sx({layer:o,cursor:t,aspectRatio:r,warmStarts:n});if(c){if(c.kind==="banded"||c.kind==="enclosure"){const u=c.kind==="banded"?c.match.distance:0;u<i.distance&&(i.match=c,i.distance=u);continue}c.match.distance<s.distance&&(s.match=c,s.distance=c.match.distance)}}return ix({containment:i,continuous:s})}function ix({containment:e,continuous:t}){return e.match&&t.match?t.distance<=e.distance+nx?t.match:e.match:e.match??t.match}function sx({layer:e,cursor:t,aspectRatio:r,warmStarts:n}){switch(e.kind){case"buckets":{const a=YS(e,t,r);return a?{kind:"buckets",match:a}:null}case"banded":{const a=WS(e,t,r);return a?{kind:"banded",match:a}:null}case"points":{const a=AS(e,t,r,n.get(e.layerId)??null);return a?{kind:"points",match:a}:null}case"enclosure":{const a=qS(e,t);return a?{kind:"enclosure",match:a}:null}case"noop":return null}}function ox(e,t,r){switch(e.kind){case"enclosure":{const n=tx(e,t,r);return n?{kind:"enclosure",match:n}:null}case"points":{const n=rx(e,t,r);return n?{kind:"points",match:n}:null}case"buckets":{const n=QS(e,t,r);return n?{kind:"buckets",match:n}:null}case"banded":{const n=jS(e,t,r);return n?{kind:"banded",match:n}:null}case"noop":case"render-hit-test":return null}}function lx(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:tl(e.layerId,i)}:null}var J={primary:null,group:[],related:new Map},cx=1,ux=class{constructor({layers:e,coordSystem:t}){this.layerIndexes=[],this.layerRefs=[],this.aspectRatio=cx,this.warmStarts=new Map,this.cachedState=J,this.cachedKey=null,this.nonInteractiveLayerIds=new Set,this.hitTesters=new Map,this.cachedByKeyId=null,this.cachedByKeyState=J,this.layerIndexes=e.map(r=>hi(r,t,this.aspectRatio)),this.layerRefs=e.map(r=>gi(r,t)),this.nonInteractiveLayerIds=yi(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=gi(i,t);if(s!==void 0&&dx(s.ref,o)){n.push(s.index),a.push(s.ref);continue}this.warmStarts.delete(i.id),n.push(hi(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=yi(e),this.invalidateCache()}setViewport(e){this.aspectRatio=e.width/e.height;for(const t of this.layerIndexes)t.kind==="points"&&t.projection==="cartesian"&&Jo(t,this.aspectRatio)}query(e){if(this.layerIndexes.length===0)return J;const t=this.nonInteractiveLayerIds.size===0?this.layerIndexes:this.layerIndexes.filter(o=>!this.nonInteractiveLayerIds.has(o.layerId)),r=ax({layers:t,aspectRatio:this.aspectRatio,warmStarts:this.warmStarts,hitTesters:this.hitTesters,cursor:e});if(!r)return this.invalidateCache(),J;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}=LS(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 J;const r=this.layerIndexes.find(i=>i.layerId===e);if(!r||r.kind!=="render-hit-test")return J;const n=r.byKey.get(t);if(!n)return J;const a=`${e}:${t}`;return this.cachedByKeyId===a?this.cachedByKeyState:(this.cachedByKeyId=a,this.cachedByKeyState={primary:tl(e,n),group:[],related:new Map},this.cachedByKeyState)}invalidateCache(){this.cachedKey=null,this.cachedState=J,this.cachedByKeyId=null,this.cachedByKeyState=J}};function gi(e,t){return{data:e.data,geom:e.geom,position:e.position,coord:t}}function yi(e){const t=new Set;for(const r of e)r.interactive||t.add(r.id);return t}function dx(e,t){return e.data===t.data&&e.geom===t.geom&&e.position===t.position&&e.coord===t.coord}var mx=Math.PI*2;function px(e,t){const r=Ue(e.mainAxis,t);if(e.mainAxis==="y"){const a=ve(ne(r));return{x1:0,x2:"100%",y1:a,y2:a}}const n=ve(r);return{x1:n,x2:n,y1:0,y2:"100%"}}function hx(e,t,r){const n=e.mainAxis==="y"?w(r.observation):R(r.observation);if(n===null)return null;const a=e.mainAxis==="y"?il(r):al(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:ve(ne(n+s)),width:"100%",height:ve(i)}:{x:ve(n-s),y:0,width:ve(i),height:"100%"}}function fx(e,t){if(e.bandAxis===null)return null;if(e.bandAxis==="x"){const a=G(t.observation),i=U(t.observation);return a===null||i===null?null:{startAngle:a,endAngle:i,innerRadius:e.innerRadius,outerRadius:1}}const r=k(t.observation),n=_(t.observation);return r===null||n===null?null:{startAngle:e.startAngle,endAngle:e.startAngle+mx,innerRadius:r,outerRadius:n}}function al(e){const t=G(e.observation),r=U(e.observation);return t===null||r===null?null:r-t}function il(e){const t=k(e.observation),r=_(e.observation);return t===null||r===null?null:r-t}function gx(e){return e.observationIndex??e.pointIndex}var lr=.5,yx=.3,vx=.4,bx=10,Sx=({layer:e,coordSystem:t,scales:r,options:n})=>e.data.size()===0?null:e.spatialKind==="rects"?t.type==="cartesian"?Ax(e,t,r,n):Ix(e,t,n):e.spatialKind==="buckets"&&t.type==="cartesian"?wx(e,t,n):e.spatialKind==="cells"?Lx(e,n):e.spatialKind==="points"?Tx(e,n):null,xx=e=>{if(e.spatialKind==="buckets"){let t=0;return e.data.groupBy(l.GROUP_VARIABLES.group).forEach(()=>{t+=1}),t}return e.data.size()},Ax=(e,t,r,n)=>({type:"grow",layerId:e.id,durationSeconds:lr*n.durationScale,baseline:Ex(e,t,r),growAxis:t.mainAxis==="x"?"y":"x",delayByKey:n.stagger?Vx(e,t.mainAxis,n):{}}),Ix=(e,t,r)=>{const n=t.bandAxis==="x"?"radius":"angle";return{type:"grow",layerId:e.id,durationSeconds:lr*r.durationScale,growAxis:n,baseline:n==="radius"?t.innerRadius:t.startAngle,delayByKey:n==="radius"&&r.stagger?Dx(e,t,r):{}}},Tx=(e,t)=>({type:"grow",layerId:e.id,durationSeconds:lr*t.durationScale,growAxis:"size",baseline:0,delayByKey:t.stagger?Rx(e,t):{}}),Lx=(e,t)=>({type:"fade",layerId:e.id,durationSeconds:yx*t.durationScale}),wx=(e,t,r)=>({type:"wipe",layerId:e.id,durationSeconds:lr*r.durationScale,axis:t.mainAxis}),Ex=(e,t,r)=>{const n=t.mainAxis==="x"?1:0,a=r[oe(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},Vx=(e,t,r)=>{const n=or(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const s=Uo(t,i);if(!s)continue;const o=Wo(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 Jn([...a.values()],r)},Rx=(e,t)=>{const r=or(e.data,e.mapping,e.id),n=[];for(const a of e.data){const i=Cx(a,t.staggerOrder);i!==null&&n.push({position:i,keys:[r(a)]})}return Jn(n,t)},Cx=(e,t)=>{if(t==="main-axis")return R(e);const r=Gn(e)??R(e);return r===null?null:t==="value-descending"?-r:r},Dx=(e,t,r)=>{const n=or(e.data,e.mapping,e.id),a=new Map;for(const i of e.data){const{startAngle:s,endAngle:o}=Un(i),{innerRadius:c,outerRadius:u}=Wn(i);if(s===null||o===null||c===null||u===null)continue;const d=zo(t.bandAxis,{startAngle:s,endAngle:o,innerRadius:c,outerRadius:u}),m=n(i),h=a.get(d);h?h.keys.push(m):a.set(d,{position:s,keys:[m]})}return Jn([...a.values()],r)},Jn=(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/bx),i=Math.ceil(n.length/a),s=vx*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},Me=["top","right","bottom","left"],vi={top:"topLeft",right:"topRight",bottom:"bottomRight",left:"bottomLeft"},_x={top:"topRight",right:"bottomRight",bottom:"bottomLeft",left:"topLeft"},Ox={topLeft:["left","top"],topRight:["top","right"],bottomRight:["right","bottom"],bottomLeft:["bottom","left"]},kx=(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]=Ox[c];return a>0&&r[u].strokeWidth>0&&r[d].strokeWidth>0},s=Mx(t,a),o=Nx(t,a,i);return Bx(r).map(c=>({lineType:r[c.firstEdge].lineType,strokeWidth:r[c.firstEdge].strokeWidth,color:r[c.firstEdge].color,segments:Fx(c,s,o,i)}))},Px=e=>({top:e.edges.top.strokeWidth,right:e.edges.right.strokeWidth,bottom:e.edges.bottom.strokeWidth,left:e.edges.left.strokeWidth}),Mx=(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}}},Nx=(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")}}}},Bx=e=>{const t=s=>e[s].strokeWidth>0,r=(s,o)=>{const c=(Me.indexOf(s)+o+Me.length)%Me.length;return Me[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=Me.filter(t);if(a.length===0)return[];const i=a.filter(n);return i.length===0?[{firstEdge:"top",edges:[...Me],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}})},Fx=(e,t,r,n)=>{const a=(m,h,p)=>({type:"arc",cx:m.cx,cy:m.cy,radius:m.radius,startAngle:h,endAngle:p}),i=m=>(m.startAngle+m.endAngle)/2,s=[],o=e.firstEdge,c=e.edges[e.edges.length-1],u=vi[o];if(!e.isClosed&&n(u)){const m=t[u],h=i(m),p=$x(m,h);s.push({type:"move",x:p.x,y:p.y}),s.push(a(m,h,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 h=vi[m];if(n(h)){const p=t[h];s.push(a(p,p.startAngle,p.endAngle))}s.push({type:"line",x:r[m].end.x,y:r[m].end.y})}const d=_x[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},$x=(e,t)=>({x:e.cx+e.radius*Math.cos(t),y:e.cy+e.radius*Math.sin(t)}),Gx=/^(?:https?:|mailto:)/i,Ux=e=>{if(typeof e!="string")return!1;const t=e.replace(/^[\x00-\x20]+/,"");return t.length===0?!1:Gx.test(t)},Wx=({locale:e,intlOptions:t})=>N(r=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",year:"numeric",weekday:"long",...F,...t}).format(r)),Hx=({locale:e,intlOptions:t})=>N(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,...F,...t}).format(r)}),Ht=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return so(e);case"date":return Wx(e);case"datetime":return Hx(e);case"day_month":return uo(e);case"decimal":return oo(e);case"duration":return Rn(e);case"integer":return lo(e);case"month":return mo(e);case"month_year":return _n(e);case"percentage":return co(e);case"quarter":return On(e);case"text":return Vn(e);case"time":return fo(e);case"weekly_date_range":return po(e);case"weekly_date_range_with_year":return ho(e);case"year":return kn(e);case"lookup":return Ht({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Kx=({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 h=c??i,p=zx(u,d);return{header:p===null?Yx({layers:e,coordSystem:t,guides:n,primary:m,locale:h,numberFormat:a}):null,rows:qx({layers:e,scales:r,guides:n,hover:s,locale:h,numberFormat:a,colorScheme:o}),comment:p}};function zx(e,t){return e===void 0||t===null||t===void 0?null:e.find(r=>r.id===t)?.content??null}function Yx(e){if(e.coordSystem.type!=="cartesian")return null;const t=Yn(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)?Ht({valueFormat:t.valueFormat,locale:e.locale,numberFormat:e.numberFormat})(a):null}function qx(e){const t=[],r=e.scales.color??null,n=ir({colorScheme:e.colorScheme}),a=Jx({guides:e.guides,locale:e.locale,numberFormat:e.numberFormat});for(const i of e.layers){const s=Xx(i,e.hover);if(s.length===0)continue;const o=s[0];if(i.tooltip.length>0&&o){t.push(...jx(i,o,e.guides,n.geomReaders(i),{locale:e.locale,numberFormat:e.numberFormat}));continue}const c=Ui(i.data,i.mapping),u=Zx(s,i,r,c),d=Hn({layer:i,numberFormat:e.numberFormat,locale:e.locale}),m=Qx(e.guides,i),h=Zt(i),p=i.mapping.color!==void 0,f=n.geomReaders(i);for(const g of u){const y=p?c(g.observation):null,v=f.get("color",g.observation),x=f.get("lineType",g.observation)??"solid",I=p&&y!==null?a(y):m,A=h(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 jx(e,t,r,n,a){return e.tooltip.map(i=>{const s=e.mapping[i.aes],o=l.extractVariableName(s),c=W(e.data,s)(t.observation),u=C({valueFormat:cn(e,o),locale:a.locale,numberFormat:a.numberFormat});return{swatchColor:i.aes==="color"?n.get("color",t.observation):null,geom:e.geom,swatchLineType:"solid",label:i.key??tr(o,r.variableLabels)??"",value:c===null?"":u(c,t.observation),isPrimary:!1,key:`${t.layerId}:${t.pointIndex}:${i.aes}`}})}function Xx(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 Zx(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 Jx({guides:e,locale:t,numberFormat:r}){const n=new Map(e.colorGroups.map(i=>[l.getStableKey(i.value),{label:i.label,format:Ht({valueFormat:i.valueFormat,locale:t,numberFormat:r})}])),a=Ht({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 Qx(e,t){return tr(l.extractVariableName(t.mapping.y),e.variableLabels)??""}function eA(e,t,r=0){const n=e[t];return typeof n=="number"&&Number.isFinite(n)?n:r}function tA(e,t,r=""){const n=e[t];return typeof n=="string"?n:r}var rA=e=>({edges:{top:$e(e.panelBorder("top")),right:$e(e.panelBorder("right")),bottom:$e(e.panelBorder("bottom")),left:$e(e.panelBorder("left"))},borderRadius:e.panelBorder().get("borderRadius")}),nA=(e,t)=>$e(e.gridLine(t)),aA=(e,t)=>{const r=e.tickLine(t);return{...$e(r),length:r.get("length")}},iA=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")}},sA=e=>{if(e==="dashed")return"2 3";if(e==="dotted")return"1 3"},$e=e=>({color:e.get("color"),strokeWidth:e.get("strokeWidth"),lineType:e.get("lineType")}),oA=e=>e.fontSize*e.lineHeight,lA=(e,t)=>({family:e.fontFamily??t,size:e.fontSize,weight:e.fontWeight}),se=(e,t,r)=>({fontFamily:e.get("fontFamily")??r,fontSize:e.get("fontSize")*t,fontWeight:e.get("fontWeight"),lineHeight:e.get("lineHeight"),textColor:e.get("textColor")}),cA=(e,t,r)=>se(e.axisLabel(t),r,e.graph.get("fontFamily")),uA=(e,t,r)=>{const n=e.tickLabel(t);return{...se(n,r,e.graph.get("fontFamily")),offset:n.get("offset")}},dA=(e,t,r,n)=>{const a=e.dataLabel(t,r),i=a.get("background"),s=a.get("borderColor"),o=a.get("borderWidth");return{...se(a,n,e.graph.get("fontFamily")),paddingInline:a.get("paddingInline"),paddingBlock:a.get("paddingBlock"),borderRadius:a.get("borderRadius"),isTextColorAuthored:a.getSource("textColor")==="authored",...i===void 0?{}:{background:i},...s===void 0?{}:{borderColor:s},...o===void 0?{}:{borderWidth:o}}},mA=(e,t,r)=>{const n=se(e.ruleLabel(t),r,e.graph.get("fontFamily"));return{fontFamily:n.fontFamily,fontSize:n.fontSize,fontWeight:n.fontWeight,lineHeight:n.lineHeight}},pA=(e,t)=>{const r=e.tooltip.box,n=e.graph.get("fontFamily");return{box:{background:r.get("background"),borderColor:r.get("borderColor"),borderWidth:r.get("borderWidth"),borderRadius:r.get("borderRadius"),paddingInline:r.get("paddingInline"),paddingBlock:r.get("paddingBlock"),shadow:r.get("shadow")},heading:se(e.tooltip.heading,t,n),label:se(e.tooltip.label,t,n),value:se(e.tooltip.value,t,n),primaryRow:{background:e.tooltip.primaryRow.get("background")}}},cr={differenceArrow:"differenceArrows",shape:"shapes",arrow:"arrows",text:"textAnnotations",image:"images",sticker:"stickers",pinnedNumber:"pinnedNumbers",comment:"comments"},hA={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}}},fA=Object.keys(cr),gA=e=>Object.hasOwn(cr,e),mt=(e,t)=>{for(const r of fA){const n=yA(e,r,t);if(n)return n}return null},pt=(e,t)=>e[cr[t]],Qn=(e,t,r)=>({...e,[cr[t]]:r}),sl=(e,t)=>{const r=pt(e,t.kind);return Qn(e,t.kind,[...r.slice(0,t.index),...r.slice(t.index+1)])},yA=(e,t,r)=>{const n=pt(e,t),a=n.findIndex(s=>s.id===r),i=n[a];return i===void 0?null:{kind:t,index:a,annotation:i}},ea=["sticker","pinnedNumber","comment","image"],vA=e=>ea.includes(e),ta=e=>{switch(e.kind){case"pinnedNumber":case"comment":return e.annotation.at;case"sticker":return e.annotation.at.anchorType==="observation"?SA(e.annotation.at):null;default:return null}},ol=(e,t)=>e.layerId===t.layerId&&l.areDataValuesEqual(e.anchorValue,t.anchorValue)&&l.areDataValuesEqual(e.groupValue??null,t.groupValue??null)&&l.areDataValuesEqual(e.crossValue??null,t.crossValue??null),ll=(e,t,r=bA)=>{const n=r(t);for(const a of ea){const i=pt(e,a),s=i.findIndex(c=>{const u=ta({kind:a,annotation:c});if(u===null)return!1;const d=r(u);return ol(d,n)}),o=i[s];if(o!==void 0)return{kind:a,index:s,annotation:o}}return null},bA=e=>({...e,anchorValue:Or(e.anchorValue),...e.groupValue!==void 0&&{groupValue:Or(e.groupValue)},...e.crossValue!==void 0&&{crossValue:Or(e.crossValue)}}),Or=e=>l.readISOInstant(e)??e,SA=e=>({layerId:e.layerId,anchorValue:e.anchorValue,groupValue:e.groupValue,crossValue:e.crossValue,align:e.align});function xA(e,t={}){return{type:"highlight",id:t.id,predicate:e,scope:t.scope,layerId:t.layerId}}var AA=(e,t)=>e.find(r=>r.scope===t.scope&&r.layerId===t.layerId&&ra(r.predicate,t.predicate))??null,ra=(e,t)=>"and"in e?"and"in t&&bi(e.and,t.and):"or"in e?"or"in t&&bi(e.or,t.or):"not"in e?"not"in t&&ra(e.not,t.not):IA(t)&&e.variable===t.variable&&TA(e,t),IA=e=>"variable"in e,bi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ra(r,a)}),TA=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Si(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&&Si(e.range,t.range),Si=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),LA={x:!0,y:!0,label:!0,color:!0,size:!0,alpha:!0,group:!0,strokeWidth:!0,lineType:!0},wA=e=>Object.hasOwn(LA,e);function EA(e){return{type:"mapping",mapping:e}}var ur=(e,t)=>"and"in e?"and"in t&&xi(e.and,t.and):"or"in e?"or"in t&&xi(e.or,t.or):"not"in e?"not"in t&&ur(e.not,t.not):VA(t)&&e.variable===t.variable&&RA(e,t),VA=e=>"variable"in e,xi=(e,t)=>e.length===t.length&&e.every((r,n)=>{const a=t[n];return a!==void 0&&ur(r,a)}),RA=(e,t)=>"eq"in e?"eq"in t&&l.areDataValuesEqual(e.eq,t.eq):"oneOf"in e?"oneOf"in t&&Ai(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&&Ai(e.range,t.range),Ai=(e,t)=>e.length===t.length&&e.every((r,n)=>l.areDataValuesEqual(r,t[n]??null)),cl=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)))),ul=e=>e.find(t=>t.geom==="line"&&t.stat.type==="smooth"),dl=e=>e.find(t=>t.geom==="rule"&&t.stat.type==="mean");function ml(e){return{mapping:e.mapping,layers:e.layers,scales:e.scales.map(CA),transforms:e.transforms,highlights:e.highlights,annotations:e.annotations,coords:e.coords,config:e.config}}function CA(e){return e.scaleType==="palette"?DA(e):e}function DA(e){return{...e,palette:_A(e.palette),overrides:OA(e.overrides)}}function _A(e){return e.type==="custom"?{type:"custom",id:e.id}:e}function OA(e){if(!e)return;const t={};for(const[r,n]of Object.entries(e))t[Number(r)]={hex:n};return t}var dr=(e,t)=>{const r=na(e,t);return r===-1?void 0:e[r]},na=(e,t)=>{for(let r=e.length-1;r>=0;r-=1){const n=e[r];if(n!==void 0&&mr(n,t))return r}return-1},mr=(e,t)=>kA(e.select,t.select)&&e.when?.state===t.when?.state&&PA(e.when?.where,t.when?.where),pl=(e,t)=>[...new Set([...Object.keys(e),...Object.keys(t)])].every(r=>MA(e[r],t[r])),Ae=(e,t)=>({select:{target:"geom",kind:e,layer:t}}),aa=e=>e.select.target==="geom",ht=(e,t)=>{const r=dr(e,t);if(!(r===void 0||!aa(r)))return r.declarations},kA=(e,t)=>{const r=e,n=t;return[...new Set([...Object.keys(e),...Object.keys(t)])].every(a=>r[a]===n[a])},PA=(e,t)=>e===void 0||t===void 0?e===t:ur(e,t),MA=(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 S(e){return{id:e.id??M(),timestamp:e.timestamp??Date.now(),description:e.description,author:e.author??"unknown"}}function qe(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t))return e.length===t.length&&e.every((r,n)=>qe(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=>qe(e[a],t[a]))}return!1}var ia=class{constructor(e,t={}){this.type="remove-annotation",this.params=e,this.metadata=S({...t,description:"Remove annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=mt(e.annotations,this.params.id);if(!t)return null;const{kind:r,index:n,annotation:a}=t;return{spec:L(e,{annotations:sl(e.annotations,t)}),revert:new sa({kind:r,annotation:a,index:n},this.metadata)}}},NA={type:"remove-annotation",deserialize:(e,t)=>new ia(e,t)},sa=class hl{constructor(t,r={}){this.type="add-annotation",this.params={kind:t.kind,annotation:{...t.annotation,id:t.annotation.id??M()},...t.index!==void 0&&{index:t.index}},this.metadata=S({...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(!gA(r)||mt(t.annotations,n.id))return null;const i=FA(t.annotations,{kind:r,annotation:n}),s=i===null?t.annotations:sl(t.annotations,i),o=pt(s,r),c=a??o.length,u=Math.min(Math.max(c,0),o.length);return{spec:L(t,{annotations:Qn(s,r,[...o.slice(0,u),n,...o.slice(u)])}),revert:i===null?new ia({id:n.id},this.metadata):new hl({kind:i.kind,annotation:i.annotation,index:i.index},this.metadata)}}},BA={type:"add-annotation",deserialize:(e,t)=>new sa({kind:e.kind,annotation:e.annotation,index:e.index},t)},FA=(e,t)=>{const r=ta(t);return r===null?null:ll(e,r)},$A=(e,t)=>{const r=oa(e);return r===null?null:fl(r.points,t)},GA=e=>oa(e)!==null,UA=(e,t)=>{const r=oa(e);if(r===null)return null;const n=fl(r.points,t);return n.x===0&&n.y===0?null:r.createPatch(n)},oa=e=>{const t=HA[e.kind];return t===null?null:t(e.annotation)},Ii=(e,t)=>e.anchorType!=="panel"?null:{points:[nn(e,e.offset)],createPatch:r=>t({...e,x:e.x+r.x,y:e.y+r.y})},Ti=(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})},WA=(e,t)=>e.anchorType!=="panel"||t.anchorType!=="panel"?null:{points:[nn(e,e.offset),nn(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}})},HA={text:e=>Ii(e.at,t=>({at:t})),sticker:e=>Ii(e.at,t=>({at:t})),shape:e=>Ti(e.region,t=>({region:t})),image:e=>Ti(e.region,t=>({region:t})),arrow:e=>WA(e.start,e.end),differenceArrow:null,pinnedNumber:null,comment:null},nn=(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)},fl=(e,t)=>({x:Li(e.map(r=>r.x),t.x),y:Li(e.map(r=>r.y),t.y)}),Li=(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,Ge.default)(t,r,n)},gl=(e,t,r)=>{const n=t.annotation;if(!YA(n,r))return null;const a=pt(e.annotations,t.kind),i=KA(t.annotation,r),s=[...a.slice(0,t.index),i,...a.slice(t.index+1)];return{spec:L(e,{annotations:Qn(e.annotations,t.kind,s)}),inverse:zA(n,r)}},KA=(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)))},zA=(e,t)=>{const r={};for(const n of Object.keys(t))r[n]=e[n];return r},YA=(e,t)=>Object.entries(t).some(([r,n])=>!Object.is(e[r],n)),la=class yl{constructor(t,r={}){this.type="update-annotation",this.params=t,this.metadata=S({...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=mt(t.annotations,n);if(i===null||i.kind!==r)return null;const s=gl(t,i,a);return s===null?null:{spec:s.spec,revert:new yl({kind:r,id:n,patch:s.inverse},this.metadata)}}},qA={type:"update-annotation",deserialize:(e,t)=>new la(e,t)},vl=class{constructor(e,t={}){this.type="move-annotation",this.params={id:e.id,translation:{x:e.translation.x,y:e.translation.y}},this.metadata=S({...t,description:"Move annotation"})}get target(){return{kind:"annotation",id:this.params.id}}apply(e){const t=mt(e.annotations,this.params.id);if(t===null)return null;const r=UA(t,this.params.translation);if(r===null)return null;const n=gl(e,t,r);return n===null?null:{spec:n.spec,revert:new la({kind:t.kind,id:t.annotation.id,patch:n.inverse},this.metadata)}}},jA={type:"move-annotation",deserialize:(e,t)=>new vl(e,t)},XA=["cartesian","polar","flip"],$=new rr,bl=e=>$.has(e)?$.get(e):null,Sl=new l.TransformRegistry,ZA=new Qs(Sl),pr=e=>{const t=e.transforms.every(r=>Sl.has(r.transformType));return e.transforms.length===0||!t?e.data:ZA.compile({data:e.data,transforms:e.transforms})};function ca(e,t){const r=t.some(i=>i.yScaleType==="secondary"),n=e.find(i=>i.scaledAesthetic==="ySecondary");if(!r)return n===void 0?e:e.filter(i=>i!==n);if(n!==void 0)return e;const a=e.find(i=>i.scaledAesthetic==="y");return a===void 0?e:[...e,{...a,scaledAesthetic:"ySecondary"}]}function ft(e,t){return e.scales.find(r=>r.scaledAesthetic===t)}function gt(e,t,r){const n=e.scales.findIndex(a=>a.scaledAesthetic===t);return n===-1?e:L(e,{scales:Fi(e.scales,n,r)})}function yt(e){const t=e.replace(/([A-Z])/g," $1").toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)}function an(e,t,r){const n=wn(Gs(eo($),{data:pr(e),layers:e.layers,mapping:r,customPalettes:{}}),l.inferred(t));return e.coords.coordType==="polar"?Us(n):n}var xl=class Al{constructor(t,r={}){this.type="set-chart-type",this.target={kind:"coords"},this.params=t,this.metadata=S({...r,description:cI(t)})}apply(t){const r="previous"in this.params?this.params.previous:uI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Al({previous:{coords:t.coords,layers:t.layers,scales:t.scales,mapping:t.mapping}},this.metadata)}}},JA={type:"set-chart-type",deserialize:(e,t)=>new xl(e,t)},Il={type:"sum"},QA={type:"identity"},eI=["bar","line","area","point","tile"],ua="tile",tI=["y","color"],rI=Object.values(l.LAYER_LABEL_VARIABLES),nI={coordType:"cartesian",geom:ua,position:"identity"},vt=e=>e.coordType==="cartesian"&&"comboType"in e&&l.COMBO_TYPES.includes(e.comboType),aI=e=>{const t=e.layers.filter(te),[r]=t;if(r===void 0)return null;const{coords:n}=e;if(n.coordType==="cartesian"){const s=Ll(t);if(s!==null)return{coordType:"cartesian",comboType:s}}if(!t.every(s=>s.geom===r.geom&&s.position===r.position))return null;const{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}},iI=e=>{if(!e)return!1;const t=e.layers.filter(te);if(t.length>=2)return!0;const[r]=t;return r===void 0?!1:wl(e,r)?El(e,r).length>=1:hr(e,e.data.groupVariableNamesByType().numeric).length>=2},sI=e=>e?Ol(e,nI)!==null:!1,oI=e=>Tl(e)?.at(-1)?.id??null,Tl=e=>{if(e.coords.coordType!=="cartesian")return null;const t=e.layers.filter(te);return Ll(t)===null?null:t},Ll=e=>{const t=e.at(-1);if(e.length<2||t?.geom!=="line")return null;const r=e.slice(0,-1);if(r.every(a=>a.geom==="line"))return lI(e)?"lines":null;if(!r.every(a=>a.geom==="bar"))return null;const[n]=r;return n===void 0||!r.every(a=>a.position===n.position)?null:l.readComboTypeOfBarPosition(n.position)},lI=e=>e.some(t=>t.yScaleType==="secondary"||Kt(t))||new Set(e.map(t=>l.extractVariableName(t.mapping.y))).size>1,cI=e=>"previous"in e?"Restore the previous chart type":vt(e)?`Set chart type to a ${e.comboType} combo`:`Set chart type to ${e.position} ${e.geom} in ${e.coordType} coords`,uI=(e,t)=>{const r=Ol(e,t);if(r===null)return null;const n=vt(t)?mI(r,t):dI(r,t,e);return n===null||r===e?n:{...n,scales:LI({...e,...n},n.scales)}},dI=(e,t,r)=>{if(vt(t)||!wI(t))return null;const n={...e,layers:$l(e.layers)},a=RI(n.layers.filter(te),t),i=Ul(n.coords,t),s=Dl(n,t),o=Fl({...n,mapping:s},t,a,s!==n.mapping);return{coords:i,layers:o,scales:ca(Wl(r,o,i.coordType),o),mapping:s}},mI=(e,t)=>{const r=fI(e,t.comboType);if(r===null)return null;const n={...e,layers:r},a=CI(r.filter(te),t.comboType),i=Ul(n.coords,t),s=Dl(n,t),o=Fl({...n,mapping:s},t,a,s!==n.mapping),c=pI(e)?o:hI(o);return{coords:i,layers:c,scales:ca(Wl(e,c,i.coordType),c),mapping:s}},pI=e=>Tl(e)!==null,hI=e=>{const t=e.filter(te).at(-1);return t===void 0||t.yScaleType==="secondary"?e:e.map(r=>r.id===t.id?{...r,yScaleType:"secondary"}:r)},fI=(e,t)=>{const r=e.layers.filter(te);if(r.length>=2)return e.layers;const[n]=r;return n===void 0?null:wl(e,n)?gI(e,n):yI(e,n,t)},wl=(e,t)=>{const r=l.extractVariableName(t.mapping.color??e.mapping.color);return r!==null&&r!==""},gI=(e,t)=>{const[r]=El(e,t);if(r===void 0)return null;const n=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Vl(r,new Set(e.layers.map(a=>a.id))),geom:"line",stat:Il,...Cl(r,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(a=>a.id===t.id?[a,n]:[a])},hr=(e,t)=>{const r=bt(e);return t.filter(n=>n!==r)},El=(e,t)=>{const r=l.extractVariableName(t.mapping.y??e.mapping.y);return hr(e,e.data.groupVariableNamesByType().numeric).filter(n=>n!==r)},bt=e=>l.readMainAxisVariable(e.mapping)||l.inferXVariable(e.data),yI=(e,t,r)=>{const{numeric:n}=e.data.groupVariableNamesByType(),a=hr(e,n),i=a.at(-1);if(a.length<2||i===void 0)return null;const s=l.readFoldKeepVariables(e.data,bt(e)),o=l.COMBO_BAR_POSITIONS[r]===null?l.LAYER_LABEL_VARIABLES.line:l.LAYER_LABEL_VARIABLES.bar,c=vI(t,wi(a.slice(0,-1),s,o)),u=Ce($,e.mapping,e.coords.coordType,{type:"layer",id:Vl(i,new Set(e.layers.map(d=>d.id))),geom:"line",stat:t.stat,...wi([i],s,l.LAYER_LABEL_VARIABLES.line)});return e.layers.flatMap(d=>d.id===t.id?[c,u]:[d])},Vl=(e,t)=>{const r=`line:${e}`;let n=r;for(let a=2;t.has(n);a+=1)n=`${r}:${a}`;return n},wi=(e,t,r)=>{const[n]=e;return e.length===1&&n!==void 0?Cl(n,r):Rl(e,t)},Rl=(e,t)=>({mapping:{y:l.DEFAULT_RESHAPE_VALUE_NAME,color:"key"},transforms:[l.transform.reshape({keep:t,reshape:e,keyName:"key",valueName:l.DEFAULT_RESHAPE_VALUE_NAME})]}),Cl=(e,t)=>({mapping:{y:e,color:t},transforms:[l.transform.constant({variableName:t,type:"categorical",value:e})]}),vI=(e,t)=>({...e,mapping:{...e.mapping,...t.mapping},transforms:[...e.transforms,...t.transforms]}),Dl=(e,t)=>{const r=l.readMainAxisVariable(e.mapping),n=_l(t)?"":bt(e);return n===r?e.mapping:{...e.mapping,x:n}},_l=e=>e.coordType==="polar"&&e.theta==="y",bI=e=>!vt(e)&&e.geom===ua,SI=e=>e.layers.filter(te).some(t=>t.geom===ua),Ol=(e,t)=>{const r=bI(t);return r===SI(e)?e:r?xI({...e,layers:$l(e.layers)}):AI(e)??e},xI=e=>{const t=Pl(e);if(t===null)return null;const r=II(e,t)===null?TI(e,t):Ml(e,t);return r===null?null:kl(e,t,r)},AI=e=>{const t=Pl(e);if(t===null)return null;const r=Ml(e,t);return r===null?null:kl(e,t,r)},kl=(e,t,r)=>({...e,mapping:r.mapping,layers:e.layers.map(n=>n===t?r.layer:n)}),Pl=e=>{const t=e.layers.filter(te);return t.length===1?t[0]??null:null},Ml=(e,t)=>{const r={...e.mapping,...t.mapping};return r.y===void 0||r.color===void 0?null:{mapping:{...e.mapping,y:r.color,color:r.y},layer:Nl(t)}},Nl=e=>{if(e.mapping.y===void 0&&e.mapping.color===void 0)return e;const{y:t,color:r,...n}=e.mapping;return{...e,mapping:n}},II=(e,t)=>{const r={...e.mapping,...t.mapping},n=l.extractVariableName(r.color),a=l.extractVariableName(r.y);if(n===null||n===""||a===null||a===""||n===bt(e))return null;const i=pr(e);return i.hasVariable(n)&&i.getType(n)==="numeric"?null:n},TI=(e,t)=>{const r=hr(e,e.data.groupVariableNamesByType().numeric);if(r.length<2)return null;const n=l.readFoldKeepVariables(e.data,bt(e)),a=Rl(r,n),i=Nl(t);return{mapping:{...e.mapping,y:a.mapping.color,color:a.mapping.y},layer:{...i,transforms:[...i.transforms,...a.transforms]}}},LI=(e,t)=>tI.reduce((r,n)=>{const a=an(e,n,e.mapping);return r.some(i=>i.scaledAesthetic===n)?Xe(r,i=>i.scaledAesthetic===n?a:i):[...r,a]},t),wI=e=>XA.includes(e.coordType)&&Bl(e.geom)&&EI(e)&&(e.coordType!=="polar"||Number.isFinite(e.innerRadius)),EI=({geom:e,coordType:t,position:r})=>{const{supportedCoordTypes:n,supportedPositions:a}=$.get(e);return n.includes(t)&&a.includes(r)},Bl=e=>eI.includes(e),te=e=>Bl(e.geom)&&!VI(e.stat),VI=e=>{switch(e.type){case"smooth":return!0;case"identity":case"count":case"mean":case"sum":return!1;default:return!0}},RI=(e,{geom:t,position:r})=>{const n={geom:t,position:r};return new Map(e.map(a=>[a.id,n]))},CI=(e,t)=>{const r={geom:"line",position:"identity"},n=l.COMBO_BAR_POSITIONS[t],a=e.map((i,s)=>n===null||s===e.length-1?[i.id,r]:[i.id,{geom:"bar",position:DI(i,t,n)}]);return new Map(a)},DI=(e,t,r)=>e.geom!=="bar"||Kt(e)?r:l.readComboTypeOfBarPosition(e.position)===t?e.position:r,Fl=(e,t,r,n)=>{const a=e.coords.coordType!==t.coordType;return Fs($,Xe(e.layers,i=>{const s=r.get(i.id);if(s===void 0)return i;const o=_I(i.stat,e.coords,t);return a||n||i.geom!==s.geom||i.position!==s.position||o!==i.stat?kI(e,{...i,stat:o},t.coordType,s):i}))},_I=(e,t,r)=>_l(r)?e.type==="identity"?Il:e:OI(t)&&e.type==="sum"?QA:e,OI=e=>e.coordType==="polar"&&e.params.theta==="y",kI=(e,t,r,{geom:n,position:a})=>{const i={geom:t.geom===n,coordType:e.coords.coordType===r,position:t.position===a},{labelSource:s,format:o,offset:c,justify:u,...d}=t.dataLabels;return{...Ce($,e.mapping,r,{type:"layer",id:t.id,geom:n,mapping:t.mapping,stat:t.stat,position:a,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}},$l=e=>{const t=e.filter(te);if(t.length<2||!e.some(Kt))return e;const[r]=t;return e.flatMap(n=>n===r?[PI(n)]:Kt(n)?[]:[n])},Kt=e=>Gl(e)!==null,Gl=e=>{const t=e.transforms.at(-1);return t?.transformType==="reshape"?t.options.keyName==="key"?t:null:t?.transformType!=="constant"?null:rI.includes(t.options.variableName)?t:null},PI=e=>{const t=Gl(e);if(t===null)return e;const{color:r,...n}=e.mapping,a=t.transformType==="reshape"?t.options.reshape?.[0]:void 0;return{...e,mapping:a===void 0?n:{...n,y:a},transforms:e.transforms.slice(0,-1)}},Ul=(e,t)=>{const r=MI(e,t);return(0,Nt.default)(r,e)?e:r},MI=(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:_t;return Kr({type:"coord",coordType:"polar",params:{...r,theta:t.theta,startAngle:n.startAngle,innerRadius:t.innerRadius}})},Wl=(e,t,r)=>{const n=Wr($,t),a=Wr($,e.layers),i=e.coords.coordType==="polar";return Xe(e.scales,s=>{const o=NI(s,n,a),c=BI(o,n,a);return $I(c,r,i)})},NI=(e,t,r)=>{if(e.scaleType==="discrete"){const a=t.bandPadding[e.scaledAesthetic];return a===void 0||e.padding===a?e:{...e,padding:a}}if(e.scaledAesthetic===t.discreteAxis)return zr(l.discrete(e.scaledAesthetic,{..."reverse"in e&&{reverse:e.reverse}}),t);if(e.scaledAesthetic===t.discreteCrossAxis)return zr(l.discrete(e.scaledAesthetic),t);const n=t.zeroAxes[e.scaledAesthetic];if(n!==void 0&&e.scaleType==="continuous"){const a=FI(e.nice,n,r.zeroAxes[e.scaledAesthetic]);return e.zero&&e.nice===a?e:{...e,zero:!0,nice:a}}return e},BI=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(e.scaledAesthetic))return e;const n=t.bandPadding[e.scaledAesthetic];if(n===r.bandPadding[e.scaledAesthetic])return e;const a=n??l.DISCRETE_SCALE_DEFAULTS.padding;return e.padding===a?e:{...e,padding:a}},FI=(e,t,r)=>t.nice===(r?.nice??!0)?e:t.nice?l.CONTINUOUS_SCALE_DEFAULTS.nice:!1,$I=(e,t,r)=>{if(e.scaleType!=="discrete"||!Ve(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}},Hl=class Kl{constructor(t,r={}){this.type="set-mapping",this.params=t,this.target={kind:"mapping",aesthetic:t.aesthetic},this.metadata=S({...r,description:UI(t)})}apply(t){const r="previous"in this.params?this.params.previous:WI(t,this.params);if(r===null)return null;const n=L(t,r);return n===t?null:{spec:n,revert:new Kl({aesthetic:this.params.aesthetic,previous:{mapping:t.mapping,scales:t.scales,layers:t.layers}},this.metadata)}}},GI={type:"set-mapping",deserialize:(e,t)=>new Hl(e,t)},zl=(e,t)=>{const r=l.extractVariableName(e[t]);return r===null||r===""||l.isInternalVariable(r)?null:r},Yl=e=>e===""?null:e,UI=e=>{if("previous"in e)return`Restore the previous ${e.aesthetic} mapping`;const t=Yl(e.variable);return t===null?`Clear the ${e.aesthetic} mapping`:`Map ${e.aesthetic} to ${t}`},WI=(e,{aesthetic:t,variable:r})=>{if(!wA(t))return null;const n=Yl(r),a=KI(e.mapping,t,n);return a===e.mapping?null:{mapping:a,scales:YI(e,t,a,n),layers:HI(e.layers,a)}},HI=(e,t)=>Xe(e,r=>{const n={...t,...r.mapping};if(n.label===void 0&&bl(r.geom)===null)return r;const a=Bs($,r.geom,r.position,n);return(0,Nt.default)(a,r.dataLabels.labelSource)?r:{...r,dataLabels:{...r.dataLabels,labelSource:a}}}),KI=(e,t,r)=>r===null?zI(e,t):zl(e,t)===r?e:{...e,[t]:r},zI=(e,t)=>{if(t==="x")return l.readMainAxisVariable(e)===""?e:{...e,x:""};const r=e[t];if(r===void 0||l.extractVariableName(r)==="")return e;const n={};for(const[a,i]of Object.entries(e))a!==t&&(n[a]=i);return n},YI=(e,t,r,n)=>{if(!os(t))return e.scales;let a=e.scales;for(const i of qI(e,t))a=XI(e,a,i,r,n);return a},qI=(e,t)=>t==="y"&&jI(e.layers)?["y","ySecondary"]:[t],jI=e=>{const t=e.find(r=>r.yScaleType==="secondary");return t!==void 0&&t.mapping.y===void 0},XI=(e,t,r,n,a)=>{const i=t.find(o=>o.scaledAesthetic===r);if(i===void 0)return a===null?t:[...t,an(e,r,n)];if(a===null&&!Ve(r)||a!==null&&!pr(e).hasVariable(a))return t;const s=an(e,r,n);return ZI(i,s)?t:Xe(t,o=>o.scaledAesthetic===r?s:o)},ZI=(e,t)=>e.scaleType===t.scaleType||Ei(e)&&Ei(t),Ei=e=>e.scaleType==="discrete"||e.scaleType==="palette",ql=class jl{constructor(t,r={}){this.type="set-appearance-text-scale",this.target={kind:"appearance"},this.params=t,this.metadata=S({...r,description:`Set text scale to ${t.textScale}`})}apply(t){const r=t.config.appearance.textScale;return r===this.params.textScale?null:{spec:E(t,{config:{appearance:{textScale:this.params.textScale}}}),revert:new jl({textScale:r},this.metadata)}}},JI={type:"set-appearance-text-scale",deserialize:(e,t)=>new ql(e,t)},da=e=>e==="both"?["x","y"]:[e],Xl=e=>e==="both"?"the":`${e} axis`;function ma(e,t){return fr(e)?e[t]:e}function QI(e,t){return e.config.axes[t]??{}}function eT(e,t,r){if(t!=="ySecondary")return E(e,{config:{axes:{[t]:r}}});const n=e.config.axes.ySecondary,a=Zl(n,r);if(a===n)return e;const i={...e.config.axes,ySecondary:a};return a===void 0&&delete i.ySecondary,L(e,{config:L(e.config,{axes:i})})}function fr(e){return l.isPlainObject(e)&&"x"in e&&"y"in e}function Zl(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?tT(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 tT(e,t){return l.isPlainObject(t)?Zl(l.isPlainObject(e)?e:void 0,t):t}var Jl=class Ql{constructor(t,r={}){this.type="set-axis-label",this.params=t,this.metadata=S({...r,description:`Set ${t.axis} axis label to ${nT(t.label)}`})}get target(){return{kind:"axis",axis:this.params.axis}}apply(t){const{axis:r,label:n}=this.params,a=QI(t,r).label;if(a===n)return null;const i=eT(t,r,{label:n});return i===t?null:{spec:i,revert:new Ql(r==="ySecondary"?{axis:r,label:a}:{axis:r,label:a??null},this.metadata)}}},rT={type:"set-axis-label",deserialize:(e,t)=>new Jl(e,t)};function nT(e){return e===void 0?"(inherited)":e??"(none)"}var ec=class tc{constructor(t,r={}){this.type="set-axis-position",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{position:n}}}}),revert:new tc({axis:r,position:a},this.metadata)}}},aT={type:"set-axis-position",deserialize:(e,t)=>new ec(e,t)},rc=class nc{constructor(t,r={}){this.type="set-axis-tick-mode",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{mode:n}}}}}),revert:new nc({axis:r,tickMode:a},this.metadata)}}},iT={type:"set-axis-tick-mode",deserialize:(e,t)=>new rc(e,t)},ac=class ic{constructor(t,r={}){this.type="set-axis-ticks-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{ticks:{isVisible:n}}}}}),revert:new ic({axis:r,isVisible:a},this.metadata)}}},sT={type:"set-axis-ticks-visibility",deserialize:(e,t)=>new ac(e,t)},sc=class oc{constructor(t,r={}){this.type="set-axis-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{isVisible:n}}}}),revert:new oc({axis:r,isVisible:a},this.metadata)}}},oT={type:"set-axis-visibility",deserialize:(e,t)=>new sc(e,t)},lc=class cc{constructor(t,r={}){this.type="set-content-caption",this.target={kind:"content",part:"caption"},this.params=t,this.metadata=S({...r,description:"Set chart caption"})}apply(t){const r=t.config.content.caption;return r===this.params.caption?null:{spec:E(t,{config:{content:{caption:this.params.caption}}}),revert:new cc({caption:r},this.metadata)}}},lT={type:"set-content-caption",deserialize:(e,t)=>new lc(e,t)},uc=class dc{constructor(t,r={}){this.type="set-content-source",this.target={kind:"content",part:"source"},this.params=t,this.metadata=S({...r,description:`Set content source to ${t.source?.label??t.source?.url??"(none)"}`})}apply(t){const r=t.config.content.source;if(qe(r,this.params.source))return null;const n=L(t.config.content,{source:this.params.source});return{spec:L(t,{config:L(t.config,{content:n})}),revert:new dc({source:r},this.metadata)}}},cT={type:"set-content-source",deserialize:(e,t)=>new uc(e,t)},mc=class pc{constructor(t,r={}){this.type="set-content-subtitle",this.target={kind:"content",part:"subtitle"},this.params=t,this.metadata=S({...r,description:"Set chart subtitle"})}apply(t){const r=t.config.content.subtitle;return r===this.params.subtitle?null:{spec:E(t,{config:{content:{subtitle:this.params.subtitle}}}),revert:new pc({subtitle:r},this.metadata)}}},uT={type:"set-content-subtitle",deserialize:(e,t)=>new mc(e,t)},hc=class fc{constructor(t,r={}){this.type="set-content-title",this.target={kind:"content",part:"title"},this.params=t,this.metadata=S({...r,description:"Set chart title"})}apply(t){const r=t.config.content.title;return r===this.params.title?null:{spec:E(t,{config:{content:{title:this.params.title}}}),revert:new fc({title:r},this.metadata)}}},dT={type:"set-content-title",deserialize:(e,t)=>new hc(e,t)},de=class Pt{constructor(t,r={}){this.type="set-style-rule",this.params=t,this.metadata=S({...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=na(i,n),o=s===-1?void 0:i[s],{declarations:c}=n;if(c===null){if(o===void 0)return null;const f=new Pt({list:r,rule:o,index:s},this.metadata),g=i.filter(y=>!mr(y,n));return{spec:kr(t,r,g),revert:f}}if(o!==void 0){if(pl(o.declarations,c))return null;const f={...o,declarations:c},g=new Pt({list:r,rule:o,index:s},this.metadata),y=i.map(v=>v===o?f:v);return{spec:kr(t,r,y),revert:g}}const u=a??i.length,d=Math.min(Math.max(u,0),i.length),m={...n,declarations:c},h=[...i.slice(0,d),m,...i.slice(d)],p=new Pt({list:r,rule:{...n,declarations:null}},this.metadata);return{spec:kr(t,r,h),revert:p}}},mT=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."})},pT={type:"set-style-rule",deserialize:(e,t)=>(mT(e),new de(e,t))},kr=(e,t,r)=>L(e,{styles:{...e.styles,[t]:r}}),hT="dashed",fT=1,gc=(e,t,r,n)=>{const a=gT(t,r),i=vT(e,a,n);let s=e,o=!1;for(const c of a){const u=ST(s,c,n,bT(n,yT(r,c)));u!==null&&(s=u,o=!0)}return o?{spec:s,previous:i}:null},gT=(e,t)=>e==="both"&&!fr(t)?[void 0]:da(e),yT=(e,t)=>t===void 0?fr(e)?e.x:e:ma(e,t),vT=(e,t,r)=>t.length===1?Pr(e,t[0],r):{x:Pr(e,"x",r),y:Pr(e,"y",r)},Pr=(e,t,r)=>yc(e.styles.overrides,t)?.[r]??null,bT=(e,t)=>t===null||e==="lineType"&&t===hT||e==="strokeWidth"&&t===fT?null:t,ST=(e,t,r,n)=>{const a=yc(e.styles.overrides,t);return(a?.[r]??null)===n?null:new de({list:"overrides",rule:IT(t,AT(a,r,n))}).apply(e)?.spec??null},xT=e=>e.select.target==="gridLine",yc=(e,t)=>{const r=dr(e,{select:t===void 0?{target:"gridLine"}:{target:"gridLine",axis:t}});if(!(r===void 0||!xT(r)))return r.declarations},AT=(e,t,r)=>{const{[t]:n,...a}=e??{};return r!==null?{...a,[t]:r}:Object.keys(a).length===0?null:a},IT=(e,t)=>t===null?e===void 0?{select:{target:"gridLine"},declarations:null}:{select:{target:"gridLine",axis:e},declarations:null}:e===void 0?l.style.gridLine(t):e==="x"?l.style.gridLine.x(t):l.style.gridLine.y(t),vc=class bc{constructor(t,r={}){this.type="set-grid-line-style",this.params=t,this.metadata=S({...r,description:`Set ${Xl(t.axis)} grid line style to ${LT(t)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineStyle:n}=this.params,a=gc(t,r,n,"lineType");return a===null?null:{spec:a.spec,revert:new bc({axis:r,lineStyle:a.previous},this.metadata)}}},TT={type:"set-grid-line-style",deserialize:(e,t)=>new vc(e,t)},LT=({axis:e,lineStyle:t})=>{const r=da(e).map(n=>ma(t,n)??"(theme)");return[...new Set(r)].join(" and ")},wT={type:"set-grid-line-width",deserialize:(e,t)=>new Sc(e,t)},Sc=class xc{constructor(t,r={}){this.type="set-grid-line-width";const n=ET(t.lineWidth);this.params={...t,lineWidth:n},this.metadata=S({...r,description:`Set ${Xl(t.axis)} grid line width to ${VT(t.axis,n)}`})}get target(){return{kind:"grid",axis:this.params.axis}}apply(t){const{axis:r,lineWidth:n}=this.params,a=gc(t,r,n,"strokeWidth");return a===null?null:{spec:a.spec,revert:new xc({axis:r,lineWidth:a.previous},this.metadata)}}},ET=e=>fr(e)?{x:Mr(e.x),y:Mr(e.y)}:Mr(e),Mr=e=>e===null||!Number.isFinite(e)?null:Math.max(0,e),VT=(e,t)=>{const r=da(e).map(n=>ma(t,n)??"(theme)");return[...new Set(r)].join(" and ")},Ac=class Ic{constructor(t,r={}){this.type="set-grid-visibility",this.params=t,this.metadata=S({...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:E(t,{config:{axes:{[r]:{grid:{isVisible:n}}}}}),revert:new Ic({axis:r,isVisible:a},this.metadata)}}},RT={type:"set-grid-visibility",deserialize:(e,t)=>new Ac(e,t)},Tc=class Lc{constructor(t,r={}){this.type="set-headline-compare-with",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline compare with to ${t.compareWith}`})}apply(t){const r=t.config.headline.compareWith;return r===this.params.compareWith?null:{spec:E(t,{config:{headline:{compareWith:this.params.compareWith}}}),revert:new Lc({compareWith:r},this.metadata)}}},CT={type:"set-headline-compare-with",deserialize:(e,t)=>new Tc(e,t)},wc=class Ec{constructor(t,r={}){this.type="set-headline-position",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline position to ${t.position}`})}apply(t){const r=t.config.headline.position;return r===this.params.position?null:{spec:E(t,{config:{headline:{position:this.params.position}}}),revert:new Ec({position:r},this.metadata)}}},DT={type:"set-headline-position",deserialize:(e,t)=>new wc(e,t)},Vc=class Rc{constructor(t,r={}){this.type="set-headline-show",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline show to ${t.show}`})}apply(t){const r=t.config.headline.show;return r===this.params.show?null:{spec:E(t,{config:{headline:{show:this.params.show}}}),revert:new Rc({show:r},this.metadata)}}},_T={type:"set-headline-show",deserialize:(e,t)=>new Vc(e,t)},Cc=class Dc{constructor(t,r={}){this.type="set-headline-size",this.target={kind:"headline"},this.params=t,this.metadata=S({...r,description:`Set headline size to ${t.size}`})}apply(t){const r=t.config.headline.size;return r===this.params.size?null:{spec:E(t,{config:{headline:{size:this.params.size}}}),revert:new Dc({size:r},this.metadata)}}},OT={type:"set-headline-size",deserialize:(e,t)=>new Cc(e,t)},kT={type:"set-highlight-dim-style",deserialize:(e,t)=>new _c(e,t)},_c=class{constructor(e,t={}){this.type="set-highlight-dim-style",this.params=e,this.metadata=S({...t,description:`Set highlight style to ${e.dimStyle}`})}get target(){return{kind:"appearance"}}apply(e){if(Oc(e)===this.params.dimStyle)return null;const t=new de({list:"overrides",rule:MT(this.params.dimStyle)},this.metadata).apply(e);return t||null}},PT={select:{target:"geom"},when:{state:"dimmed"}},Oc=e=>{const t=dr(e.styles.overrides,PT);return(t!==void 0&&aa(t)?t.declarations:void 0)?.saturation===0?"desaturate":"dim"},MT=e=>e==="desaturate"?l.style.geom({saturation:0,alpha:.6},{state:"dimmed"}):l.style.geom({alpha:l.DEFAULT_DIMMED_ALPHA},{state:"dimmed"}),kc=class Pc{constructor(t,r={}){this.type="set-legend-align",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend align to ${t.align}`})}apply(t){const r=t.config.legend.align;return r===this.params.align?null:{spec:E(t,{config:{legend:{align:this.params.align}}}),revert:new Pc({align:r},this.metadata)}}},NT={type:"set-legend-align",deserialize:(e,t)=>new kc(e,t)},Mc=class Nc{constructor(t,r={}){this.type="set-legend-display",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend display to ${t.display}`})}apply(t){const r=t.config.legend.display;return r===this.params.display?null:{spec:E(t,{config:{legend:{display:this.params.display}}}),revert:new Nc({display:r},this.metadata)}}},BT={type:"set-legend-display",deserialize:(e,t)=>new Mc(e,t)},Bc=class Fc{constructor(t,r={}){this.type="set-legend-position",this.target={kind:"legend"},this.params=t,this.metadata=S({...r,description:`Set legend position to ${t.position}`})}apply(t){const r=t.config.legend.position;return r===this.params.position?null:{spec:E(t,{config:{legend:{position:this.params.position}}}),revert:new Fc({position:r},this.metadata)}}},FT={type:"set-legend-position",deserialize:(e,t)=>new Bc(e,t)},$c=class Gc{constructor(t,r={}){this.type="set-number-format-abbreviation",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format abbreviation to ${t.abbreviation}`})}apply(t){const r=t.config.numberFormat.abbreviation;return r===this.params.abbreviation?null:{spec:E(t,{config:{numberFormat:{abbreviation:this.params.abbreviation}}}),revert:new Gc({abbreviation:r},this.metadata)}}},$T={type:"set-number-format-abbreviation",deserialize:(e,t)=>new $c(e,t)},Uc=class Wc{constructor(t,r={}){this.type="set-number-format-decimals",this.target={kind:"numberFormat"},this.params=t,this.metadata=S({...r,description:`Set number format decimals to ${t.decimals}`})}apply(t){const r=t.config.numberFormat.decimals;return r===this.params.decimals?null:{spec:E(t,{config:{numberFormat:{decimals:this.params.decimals}}}),revert:new Wc({decimals:r},this.metadata)}}},GT={type:"set-number-format-decimals",deserialize:(e,t)=>new Uc(e,t)},Hc=class Kc{constructor(t,r={}){this.type="toggle-content-visibility",this.params=t,this.metadata=S({...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=WT(r);if(!a)return null;const i=t.config.content[a];return i===n?null:{spec:E(t,{config:{content:{[a]:n}}}),revert:new Kc({slot:r,isVisible:i},this.metadata)}}},UT={type:"toggle-content-visibility",deserialize:(e,t)=>new Hc(e,t)},Vi={title:"isTitleVisible",subtitle:"isSubtitleVisible",caption:"isCaptionVisible",source:"isSourceVisible"};function WT(e){return Object.hasOwn(Vi,e)?Vi[e]:void 0}var zc=class Yc{constructor(t,r={}){this.type="set-coord-limits",this.target={kind:"coords"},this.params=t,this.metadata=S({...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(qe(i.xLimits,a.xLimits)&&qe(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 Yc(s,this.metadata);return{spec:L(t,{coords:KT(t.coords,i)}),revert:o}}},HT={type:"set-coord-limits",deserialize:(e,t)=>new zc(e,t)};function KT(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 qc=class jc{constructor(t,r={}){this.type="set-polar-inner-radius",this.target={kind:"coords"},this.params={innerRadius:(0,Ge.default)(t.innerRadius,0,1)},this.metadata=S({...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:L(t,{coords:{...r,params:{...r.params,innerRadius:this.params.innerRadius}}}),revert:new jc({innerRadius:n},this.metadata)}}},zT={type:"set-polar-inner-radius",deserialize:(e,t)=>new qc(e,t)},YT={type:"set-polar-start-angle",deserialize:(e,t)=>new Xc(e,t)},Xc=class Zc{constructor(t,r={}){this.type="set-polar-start-angle",this.target={kind:"coords"},this.params={startAngle:Ri(t.startAngle)},this.metadata=S({...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 Ri(n)===this.params.startAngle?null:{spec:L(t,{coords:{...r,params:{...r.params,startAngle:this.params.startAngle}}}),revert:new Zc({startAngle:n},this.metadata)}}},Nr=360,Ri=e=>(e%Nr+Nr)%Nr,pa=class{constructor(e,t={}){this.type="remove-highlight",this.params=e,this.metadata=S({...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 ha({predicate:t.predicate,id:t.id,scope:t.scope,layerId:t.layerId,index:r},this.metadata);return{spec:L(e,{highlights:n}),revert:a}}},qT={type:"remove-highlight",deserialize:(e,t)=>new pa(e,t)},ha=class{constructor(e,t={}){this.type="add-highlight",this.params={...e,id:e.id??M(),scope:e.scope??"data-point"},this.metadata=S({...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 pa({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:L(e,{highlights:[...e.highlights.slice(0,u),o,...e.highlights.slice(u)]}),revert:s}}},jT={type:"add-highlight",deserialize:(e,t)=>new ha(e,t)};function fa(e,t){return{...e,params:{...e.params,...t}}}function gr(e,t){return{...e,dataLabels:{...e.dataLabels,...t}}}function ga(e,t){return L(e,{layers:[...e.layers,t]})}function H(e,t,r){const n=e.layers.findIndex(a=>a.id===t);return n===-1?e:L(e,{layers:Fi(e.layers,n,r)})}function yr(e,t){const r=e.layers.findIndex(n=>n.id===t);return r===-1||e.layers.length<=1?e:L(e,{layers:e.layers.filter((n,a)=>a!==r)})}var ya=class{constructor(e,t={}){this.type="remove-layer",this.params=e,this.metadata=S({...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=yr(e,this.params.layerId);return n===e?null:{spec:n,revert:new va({layer:r,index:t},this.metadata)}}},XT={type:"remove-layer",deserialize:(e,t)=>new ya(e,t)},va=class{constructor(e,t={}){this.type="add-layer",this.params={layer:{...e.layer,id:e.layer.id??M()},...e.index!==void 0&&{index:e.index}},this.metadata=S({...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:L(e,{layers:[...e.layers.slice(0,a),t,...e.layers.slice(a)]}),revert:new ya({layerId:t.id},this.metadata)}}},ZT={type:"add-layer",deserialize:(e,t)=>new va(e,t)},Jc=class Qc{constructor(t,r={}){this.type="set-bar-border-radius",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"bar"))return null;const a=Ae("bar",r),i=ht(t.styles.overrides,a),s=i?.borderRadius??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:QT(i,n)}}).apply(t);if(!o)return null;const c=new Qc({layerId:r,borderRadius:s},this.metadata);return{spec:o.spec,revert:c}}},JT={type:"set-bar-border-radius",deserialize:(e,t)=>new Jc(e,t)},QT=(e,t)=>{const{borderRadius:r,...n}=e??{};return t!==null?{...n,borderRadius:t}:Object.keys(n).length===0?null:n},eL={type:"set-bar-width",deserialize:(e,t)=>new tu(e,t)},eu=.05,tL=1,tu=class ru{constructor(t,r={}){this.type="set-bar-width";const n=t.width===void 0?void 0:(0,Ge.default)(t.width,eu,1);this.params={...t,width:n},this.metadata=S({...r,description:n===void 0?"Reset bar width":`Set bar width to ${n}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){if(this.params.width!==void 0&&!Number.isFinite(this.params.width))return null;const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"bar");if(!q(r,"bar"))return null;const n=r.params.width;return n===this.params.width?null:{spec:H(t,r.id,fa(r,{width:this.params.width})),revert:new ru({layerId:r.id,width:n},this.metadata)}}},nu=class au{constructor(t,r={}){this.type="set-data-labels-format",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.format;return n===this.params.format?null:{spec:H(t,r.id,gr(r,{format:this.params.format})),revert:new au({layerId:r.id,format:n},this.metadata)}}},rL={type:"set-data-labels-format",deserialize:(e,t)=>new nu(e,t)},iu=class su{constructor(t,r={}){this.type="set-layer-position",this.params=t,this.metadata=S({...r,description:`Set layer position to ${t.position}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"bar","area");if(!r)return null;const n=r.position;return n===this.params.position?null:{spec:H(t,r.id,{...r,position:this.params.position}),revert:new su({layerId:r.id,position:n},this.metadata)}}},nL={type:"set-layer-position",deserialize:(e,t)=>new iu(e,t)},ou=class lu{constructor(t,r={}){this.type="set-layer-stat";const n=Ns(t.stat,"identity");this.params={...t.layerId!==void 0&&{layerId:t.layerId},stat:n},this.metadata=S({...r,description:`Set layer stat to ${n.type}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.stat;return iL(n,this.params.stat)?null:{spec:H(t,r.id,{...r,stat:this.params.stat}),revert:new lu({layerId:r.id,stat:n},this.metadata)}}},aL={type:"set-layer-stat",deserialize:(e,t)=>new ou(e,t)},iL=(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},cu=class uu{constructor(t,r={}){this.type="set-layer-y-scale-type",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.yScaleType;if(n===this.params.yScaleType)return null;const a=H(t,r.id,{...r,yScaleType:this.params.yScaleType});return{spec:L(a,{scales:ca(a.scales,a.layers)}),revert:new uu({layerId:r.id,yScaleType:n},this.metadata)}}},sL={type:"set-layer-y-scale-type",deserialize:(e,t)=>new cu(e,t)},du=class mu{constructor(t,r={}){this.type="set-line-interpolation",this.params=t,this.metadata=S({...r,description:`Set line interpolation to ${t.interpolate}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.interpolate;return n===this.params.interpolate?null:{spec:H(t,r.id,fa(r,{interpolate:this.params.interpolate})),revert:new mu({layerId:r.id,interpolate:n},this.metadata)}}},oL={type:"set-line-interpolation",deserialize:(e,t)=>new du(e,t)},pu=class hu{constructor(t,r={}){this.type="set-line-missing-values",this.params=t,this.metadata=S({...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?D(t.layers,this.params.layerId):le(t.layers,"line","area");if(!q(r,"line","area"))return null;const n=r.params.missingValues;return n===this.params.missingValues?null:{spec:H(t,r.id,fa(r,{missingValues:this.params.missingValues})),revert:new hu({layerId:r.id,missingValues:n},this.metadata)}}},lL={type:"set-line-missing-values",deserialize:(e,t)=>new pu(e,t)},fu=class gu{constructor(t,r={}){this.type="set-line-width",this.params=t,this.metadata=S({...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=D(t.layers,r);if(!q(a,"line","area"))return null;const i=ht(t.styles.overrides,Ae(a.geom,r)),s=i?.strokeWidth??null;if(s===n)return null;const o=uL(i,n),c=new de({list:"overrides",rule:a.geom==="area"?{...Ae("area",r),declarations:o}:{...Ae("line",r),declarations:o}}).apply(t);return c?{spec:c.spec,revert:new gu({layerId:r,lineWidth:s},this.metadata)}:null}},cL={type:"set-line-width",deserialize:(e,t)=>new fu(e,t)},uL=(e,t)=>{const{strokeWidth:r,...n}=e??{};return t!==null?{...n,strokeWidth:t}:Object.keys(n).length===0?null:n},yu=class vu{constructor(t,r={}){this.type="set-point-size",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"point"))return null;const a=Ae("point",r),i=ht(t.styles.overrides,a),s=i?.size??null;if(s===n)return null;const o=new de({list:"overrides",rule:{...a,declarations:mL(i,n)}}).apply(t);return o?{spec:o.spec,revert:new vu({layerId:r,size:s},this.metadata)}:null}},dL={type:"set-point-size",deserialize:(e,t)=>new yu(e,t)},mL=(e,t)=>{const{size:r,...n}=e??{};return t!==null?{...n,size:t}:Object.keys(n).length===0?null:n},bu=class Su{constructor(t,r={}){this.type="set-rule-label",this.params=t,this.metadata=S({...r,description:"Set reference line label"})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"rule");if(!q(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:H(t,r.id,{...r,params:i}),revert:new Su({layerId:r.id,label:n??null},this.metadata)}}},pL={type:"set-rule-label",deserialize:(e,t)=>new bu(e,t)},xu=class Au{constructor(t,r={}){this.type="set-rule-value",this.params=t,this.metadata=S({...r,description:`Set reference line to ${t.value}`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"rule");if(!q(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:H(t,r.id,{...r,mapping:i}),revert:new Au({layerId:r.id,value:a},this.metadata)}}},hL={type:"set-rule-value",deserialize:(e,t)=>new xu(e,t)},fL={type:"set-stat-line",deserialize:(e,t)=>new Iu(e,t)},Iu=class Tu{constructor(t,r={}){this.type="set-stat-line",this.params=t,this.metadata=S({...r,description:AL(t.line)})}get target(){return{kind:"layer",layerId:this.params.removedLayer?.id??this.params.layerId}}apply(t){const r=yL(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&&xL(r.layer,n))return null;const a=new Tu({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:H(t,r.layer.id,n),revert:a};const i=r===void 0?t:yr(t,r.layer.id);return n===null&&i===t?null:{spec:n===null?i:ga(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"?vL(this.params):bL(t,this.params);if(n===null)return null;const a=Ce($,t.mapping,t.coords.coordType,n);return r===void 0?a:{...a,id:r}}},gL="linear",yL=e=>{const t=ul(e.layers);if(t!==void 0)return{line:"trend",layer:t};const r=dl(e.layers);if(r!==void 0)return{line:"average",layer:r}},vL=({method:e})=>l.geom.line({aes:{lineType:{value:"dashed"}},stat:l.stat.smooth({method:e??gL}),interactive:!1}),bL=(e,{group:t,label:r})=>{const n=SL(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})},SL=e=>e.layers.find(t=>t.geom!=="rule"&&t.stat.type!=="smooth"),xL=(e,t)=>(0,je.isEqual)({...e,id:""},{...t,id:""}),AL=e=>e==="none"?"Hide stat line":`Show ${e} line`,Lu=class wu{constructor(t,r={}){this.type="toggle-category-labels",this.params=t,this.metadata=S({...r,description:`${t.showCategoryLabels?"Show":"Hide"} category labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showCategoryLabels;return n===this.params.showCategoryLabels?null:{spec:H(t,r.id,gr(r,{showCategoryLabels:this.params.showCategoryLabels})),revert:new wu({layerId:r.id,showCategoryLabels:n},this.metadata)}}},IL={type:"toggle-category-labels",deserialize:(e,t)=>new Lu(e,t)},Eu=class Vu{constructor(t,r={}){this.type="toggle-data-labels",this.params=t,this.metadata=S({...r,description:`${t.showDataLabels?"Show":"Hide"} data labels`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showDataLabels;return n===this.params.showDataLabels?null:{spec:H(t,r.id,gr(r,{showDataLabels:this.params.showDataLabels})),revert:new Vu({layerId:r.id,showDataLabels:n},this.metadata)}}},TL={type:"toggle-data-labels",deserialize:(e,t)=>new Eu(e,t)},LL={type:"toggle-goal-line",deserialize:(e,t)=>new Ru(e,t)},Ru=class sn{constructor(t,r={}){this.type="toggle-goal-line",this.params=t,this.metadata=S({...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=cl(t.layers);if(!this.params.showGoalLine){if(r===void 0)return null;const a=yr(t,r.id);return a===t?null:{spec:a,revert:new sn({showGoalLine:!0,removedLayer:r},this.metadata)}}if(r!==void 0)return null;const n=this.params.removedLayer??this.buildGoalLine(t);return{spec:ga(t,n),revert:new sn({showGoalLine:!1,layerId:n.id},this.metadata)}}buildGoalLine(t){const r=t.coords.coordType==="flip"?"end":"start";return Ce($,t.mapping,t.coords.coordType,l.geom.rule({aes:{y:{value:this.params.value??wL}},params:{labelPosition:r,...this.params.label!==void 0&&{label:this.params.label}},interactive:!1}))}},wL=0,EL={type:"toggle-line-fill",deserialize:(e,t)=>new Cu(e,t)},Cu=class Du{constructor(t,r={}){this.type="toggle-line-fill",this.params=t,this.metadata=S({...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(!q(D(t.layers,r),"line"))return null;const i=Ae("line",r),s=ht(t.styles.overrides,i),o=s?.fillAlpha,c=o!==void 0;if(c===n)return null;const u=new de({list:"overrides",rule:{...i,declarations:RL(s,n?a??VL:null)}}).apply(t);if(!u)return null;const d=new Du({layerId:r,showFill:c,...o===void 0?{}:{fillAlpha:o}},this.metadata);return{spec:u.spec,revert:d}}},VL=.2,RL=(e,t)=>{const{fillAlpha:r,...n}=e??{};return t!==null?{...n,fillAlpha:t}:Object.keys(n).length===0?null:n},CL={type:"toggle-line-points",deserialize:(e,t)=>new _u(e,t)},_u=class on{constructor(t,r={}){this.type="toggle-line-points",this.params=t,this.metadata=S({...r,description:`${t.showPoints?"Show":"Hide"} points`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):le(t.layers,"line","area");return q(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:ga(t,this.params.removedLayer??Ce($,t.mapping,t.coords.coordType,l.geom.point({aes:{...r.mapping},position:r.position,yScaleType:r.yScaleType,transforms:[...r.transforms],interactive:!1}))),revert:new on({layerId:r.id,showPoints:!1},this.metadata)}}removePointLayer(t,r){const n=this.findAssociatedPointLayer(t,r);return n?{spec:yr(t,n.id),revert:new on({layerId:r.id,showPoints:!0,removedLayer:n},this.metadata)}:null}findAssociatedPointLayer(t,r){return t.layers.find(n=>n.geom!=="point"?!1:vn(n,[r]))}},Ou=class ku{constructor(t,r={}){this.type="toggle-stack-totals",this.params=t,this.metadata=S({...r,description:`${t.showStackTotals?"Show":"Hide"} stack totals`})}get target(){return{kind:"layer",layerId:this.params.layerId}}apply(t){const r=this.params.layerId?D(t.layers,this.params.layerId):t.layers[0];if(!r)return null;const n=r.dataLabels.showStackTotals;return n===this.params.showStackTotals?null:{spec:H(t,r.id,gr(r,{showStackTotals:this.params.showStackTotals})),revert:new ku({layerId:r.id,showStackTotals:n},this.metadata)}}},DL={type:"toggle-stack-totals",deserialize:(e,t)=>new Ou(e,t)},Pu=class Mu{constructor(t,r={}){this.type="set-scale-domain",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale domain`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(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=gt(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 Mu(c,this.metadata)}}},_L={type:"set-scale-domain",deserialize:(e,t)=>new Pu(e,t)},Nu=class Bu{constructor(t,r={}){this.type="set-scale-palette",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} palette`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);return r?.scaleType!=="palette"||qe(r.palette,this.params.palette)?null:{spec:gt(t,this.params.scaledAesthetic,{...r,scaledAesthetic:this.params.scaledAesthetic,palette:this.params.palette}),revert:new Bu({scaledAesthetic:this.params.scaledAesthetic,palette:r.palette},this.metadata)}}},OL={type:"set-scale-palette",deserialize:(e,t)=>new Nu(e,t)},Fu=class $u{constructor(t,r={}){this.type="set-scale-reverse",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale reverse to ${t.reverse}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||!PL(r))return null;const n=r.reverse;return n===this.params.reverse?null:{spec:gt(t,this.params.scaledAesthetic,{...r,reverse:this.params.reverse}),revert:new $u({scaledAesthetic:this.params.scaledAesthetic,reverse:n},this.metadata)}}},kL={type:"set-scale-reverse",deserialize:(e,t)=>new Fu(e,t)};function PL(e){return e.scaleType==="continuous"||e.scaleType==="datetime"||e.scaleType==="discrete"}var Gu=class Uu{constructor(t,r={}){this.type="set-scale-transform",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale transform to ${t.transform}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.transform;return n===this.params.transform?null:{spec:gt(t,this.params.scaledAesthetic,{...r,transform:this.params.transform}),revert:new Uu({scaledAesthetic:this.params.scaledAesthetic,transform:n},this.metadata)}}},ML={type:"set-scale-transform",deserialize:(e,t)=>new Gu(e,t)},Wu=class Hu{constructor(t,r={}){this.type="set-scale-zero",this.params=t,this.metadata=S({...r,description:`Set ${yt(t.scaledAesthetic)} scale zero to ${t.zero}`})}get target(){return{kind:"scale",aesthetic:this.params.scaledAesthetic}}apply(t){const r=ft(t,this.params.scaledAesthetic);if(!r||r.scaleType!=="continuous")return null;const n=r.zero;return n===this.params.zero?null:{spec:gt(t,this.params.scaledAesthetic,{...r,zero:this.params.zero}),revert:new Hu({scaledAesthetic:this.params.scaledAesthetic,zero:n},this.metadata)}}},NL={type:"set-scale-zero",deserialize:(e,t)=>new Wu(e,t)},Ku=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}},b=new Ku;b.register(JA);b.register(GI);b.register(ZT);b.register(XT);b.register(rL);b.register(nL);b.register(aL);b.register(sL);b.register(oL);b.register(cL);b.register(JT);b.register(eL);b.register(dL);b.register(lL);b.register(pL);b.register(hL);b.register(fL);b.register(IL);b.register(TL);b.register(LL);b.register(EL);b.register(CL);b.register(DL);b.register(_L);b.register(OL);b.register(kL);b.register(ML);b.register(NL);b.register(JI);b.register(rT);b.register(iT);b.register(aT);b.register(sT);b.register(oT);b.register(lT);b.register(cT);b.register(uT);b.register(dT);b.register(TT);b.register(wT);b.register(RT);b.register(CT);b.register(DT);b.register(_T);b.register(OT);b.register(kT);b.register(NT);b.register(BT);b.register(FT);b.register($T);b.register(GT);b.register(UT);b.register(jT);b.register(qT);b.register(pT);b.register(BA);b.register(NA);b.register(qA);b.register(jA);b.register(HT);b.register(zT);b.register(YT);var zu=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:Ci(this.undoStack),redoStack:Ci(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&&FL(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)}}},BL=Object.freeze([]),FL=(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},Ci=e=>e.length===0?BL:e.map(t=>t.command.metadata),$L=(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&&mr(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}`})}},GL=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}},UL=class{constructor(e){this.compiler=e,this.history=new zu,this.current=null,this.last=null,this.hostInput=null,this.run=new GL(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=ml(e);return this.last={input:r,data:t.data,customPalettes:t.customPalettes},r}absorb(e){return e.ok&&(this.current=e.compiled),e}},WL=new Set(["x","y"]),Di=["numeric","categorical","temporal"],_i=["numeric"],HL=(e,t)=>{const r=e.layers.map(a=>bl(a.geom)).filter(l.isDefined),n=pr(e);return t.filter(a=>KL(e,r,a)).map(a=>({aesthetic:a,variables:zL(n,r,a),isRequired:WL.has(a)}))},KL=(e,t,r)=>{switch(r){case"x":return!jL(e.coords);case"y":return!0;case"label":return t.some(n=>n.dataLabelCoordTypes.includes(e.coords.coordType));default:return t.some(n=>n.aesthetics.some(a=>a.kind==="visual"&&a.name===r))}},zL=(e,t,r)=>{const n=YL(t,r);return e.getVariableNames().filter(a=>!l.isInternalVariable(a)&&n.includes(e.getType(a)))},YL=(e,t)=>t==="size"?_i:t!=="x"&&t!=="y"?Di:qL(e,t)?_i:Di,qL=(e,t)=>e.some(r=>r.positionRoles.some(n=>ss.has(n.role)&&n.aes===t&&!(n.role==="scalar"&&n.aes===n.axis))),jL=e=>e.coordType==="polar"&&e.params.theta==="y",XL=500,ZL="normal",ba={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},JL=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}`},Sa=e=>typeof e!="string"?e??500:ba[e],QL="\0",ew=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,Sa(t.weight),t.style??"normal",e].join(QL)}},tw={" ":.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 rw=1.05,nw=.84,aw=.21,iw=class{measureText(e,t){let r=0;for(const i of e)r+=(tw[i]??.55)*t.size;Sa(t.weight)>=ba.semiBold&&(r*=rw);const n=nw*t.size,a=aw*t.size;return{width:r,height:n+a,ascent:n,descent:a}}};exports.ANNOTATION_TOOLTIP_MARKER_GAP=Zv;exports.ARROW_DEFAULTS=fe;exports.AXIS_KEYS=hn;exports.AddAnnotationCommand=sa;exports.AddHighlightCommand=ha;exports.AddLayerCommand=va;exports.BORDER_RADIUS_PX=qn;exports.BORDER_RADIUS_TOKENS=l.BORDER_RADIUS_TOKENS;exports.BUILTIN_STYLES=l.BUILTIN_STYLES;exports.COLOR_INTERPOLATION_SPACES=Uh;exports.COMBO_TYPES=l.COMBO_TYPES;exports.COMPILER_STAGE_KEYS=gg;exports.CONSTANT_VARIABLES=l.CONSTANT_VARIABLES;exports.CachedTextMeasurer=ew;exports.CommandRegistry=Ku;exports.CommandStackManager=zu;exports.Compiler=to;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=ZL;exports.DEFAULT_FONT_WEIGHT=XL;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=Ct;exports.DIVERGING_SCHEME_NAMES=ks;exports.Dataset=l.Dataset;exports.GROUP_VARIABLES=l.GROUP_VARIABLES;exports.Geom=ae;exports.GraphCompilationSession=UL;exports.HEADLINE_SWATCH_GAP=Xb;exports.HEADLINE_SWATCH_SIZE=jb;exports.HEADLINE_TREND_GAP=Qb;exports.HEADLINE_TREND_ICON_SIZE=Jb;exports.HEADLINE_VALUE_LABEL_GAP=Zb;exports.HeuristicTextMeasurer=iw;exports.HoverEngine=ux;exports.InternalError=l.InternalError;exports.LAYOUT_PADDING=Tg;exports.LINE_STYLE_TYPES=dn;exports.LayoutCompiler=Ev;exports.MAX_BAR_WIDTH=tL;exports.MIN_BAR_WIDTH=eu;exports.MONO_BASES=l.MONO_BASES;exports.MoveAnnotationCommand=vl;exports.NAMED_WEIGHTS=ba;exports.NEON_BASES=l.NEON_BASES;exports.OBSERVATION_ATTACHMENT_KINDS=ea;exports.OUT_OF_VIEW_MARGIN_PX=Jv;exports.PANEL_BORDER_EDGES=l.PANEL_BORDER_EDGES;exports.POLAR_RIM_LABEL_GAP_PX=em;exports.POSITION_TYPES=Wi;exports.POSITION_VARIABLES=l.POSITION_VARIABLES;exports.RESTING_HOVER_STATE=J;exports.RemoveAnnotationCommand=ia;exports.RemoveHighlightCommand=pa;exports.RemoveLayerCommand=ya;exports.SCALED_POSITION_AESTHETIC_KEYS=fn;exports.SCALED_VISUAL_AESTHETIC_KEYS=ot;exports.SCHEME_ALIASES=Ps;exports.SEQUENTIAL_SCHEME_NAMES=Wh;exports.SHAPE_DEFAULTS=he;exports.SIBLING_OVERLAP_THRESHOLD_PX=Qv;exports.STACK_VARIABLES=l.STACK_VARIABLES;exports.STYLE_STATES=l.STYLE_STATES;exports.SetAppearanceTextScaleCommand=ql;exports.SetAxisLabelCommand=Jl;exports.SetAxisPositionCommand=ec;exports.SetAxisTickModeCommand=rc;exports.SetAxisTicksVisibilityCommand=ac;exports.SetAxisVisibilityCommand=sc;exports.SetBarBorderRadiusCommand=Jc;exports.SetBarWidthCommand=tu;exports.SetChartTypeCommand=xl;exports.SetContentCaptionCommand=lc;exports.SetContentSourceCommand=uc;exports.SetContentSubtitleCommand=mc;exports.SetContentTitleCommand=hc;exports.SetCoordLimitsCommand=zc;exports.SetDataLabelsFormatCommand=nu;exports.SetGridLineStyleCommand=vc;exports.SetGridLineWidthCommand=Sc;exports.SetGridVisibilityCommand=Ac;exports.SetHeadlineCompareWithCommand=Tc;exports.SetHeadlinePositionCommand=wc;exports.SetHeadlineShowCommand=Vc;exports.SetHeadlineSizeCommand=Cc;exports.SetHighlightDimStyleCommand=_c;exports.SetLayerPositionCommand=iu;exports.SetLayerStatCommand=ou;exports.SetLayerYScaleTypeCommand=cu;exports.SetLegendAlignCommand=kc;exports.SetLegendDisplayCommand=Mc;exports.SetLegendPositionCommand=Bc;exports.SetLineInterpolationCommand=du;exports.SetLineMissingValuesCommand=pu;exports.SetLineWidthCommand=fu;exports.SetMappingCommand=Hl;exports.SetNumberFormatAbbreviationCommand=$c;exports.SetNumberFormatDecimalsCommand=Uc;exports.SetPointSizeCommand=yu;exports.SetPolarInnerRadiusCommand=qc;exports.SetPolarStartAngleCommand=Xc;exports.SetRuleLabelCommand=bu;exports.SetRuleValueCommand=xu;exports.SetScaleDomainCommand=Pu;exports.SetScalePaletteCommand=Nu;exports.SetScaleReverseCommand=Fu;exports.SetScaleTransformCommand=Gu;exports.SetScaleZeroCommand=Wu;exports.SetStatLineCommand=Iu;exports.SetStyleRuleCommand=de;exports.SpecResolver=Hs;exports.Stat=Re;exports.TAU=xe;exports.TEXT_ANNOTATION_DEFAULTS=Dt;exports.TOOLTIP_PARTS=l.TOOLTIP_PARTS;exports.ToggleCategoryLabelsCommand=Lu;exports.ToggleContentVisibilityCommand=Hc;exports.ToggleDataLabelsCommand=Eu;exports.ToggleGoalLineCommand=Ru;exports.ToggleLineFillCommand=Cu;exports.ToggleLinePointsVisibilityCommand=_u;exports.ToggleStackTotalsCommand=Ou;exports.UpdateAnnotationCommand=la;exports.VISUAL_VARIABLES=l.VISUAL_VARIABLES;exports.alignUnitFractions=Pi;exports.annotation=hA;exports.areAnchorsEqual=Fe;exports.areEditMenuTriggersEqual=Lb;exports.areEditTargetsEqual=$L;exports.areEndpointsComparable=Mi;exports.areMappingsEquivalent=l.areMappingsEquivalent;exports.areObservationAnchorsEqual=ol;exports.arePointerRegionListsEqual=vb;exports.arePredicatesEqual=ur;exports.areStyleDeclarationsEqual=pl;exports.areStyleRuleAddressesEqual=mr;exports.buildAverageLineSymbols=Yv;exports.buildCalloutHitRegions=Xv;exports.buildColumnKey=Wo;exports.buildDataLabelsContent=qy;exports.buildDiagnostic=Bi;exports.buildEditMenuTriggerRegion=Ib;exports.buildFontString=JL;exports.buildLayerIntroPlan=Sx;exports.buildLayerStyleAddress=Ae;exports.buildLayerYValueFormatter=Hn;exports.buildObservationAnchor=st;exports.buildObservationPredicate=db;exports.buildPinnedNumberValueFormatter=Nb;exports.buildPolarBarArcPath=fS;exports.buildSliceGroupKey=zo;exports.buildTooltipContent=Kx;exports.canAnchorDirectLabels=ys;exports.canBecomeCombo=iI;exports.canBecomeHeatmap=sI;exports.canPlaceDataLabels=Yy;exports.clampAnnotationTranslation=$A;exports.commandRegistry=b;exports.compileChromeStyles=Ys;exports.compileStylesheetForLayer=Zf;exports.compositeColor=nd;exports.computeArrow=Kv;exports.computeDifferenceArrow=Co;exports.computeDirectLabelsLayout=ub;exports.computeLineBoxHeight=oA;exports.computePanelBorderPaths=kx;exports.computePanelBorderSizes=Px;exports.config=l.config;exports.convertSpecToInput=ml;exports.coord=l.coord;exports.countLayerGeoms=xx;exports.createAlphaValueReader=pd;exports.createAnchorResolver=Rv;exports.createAreaPathGenerators=sS;exports.createColorValueReader=Ui;exports.createCompiler=yg;exports.createDatasetFromKindPartitions=Wd;exports.createEmptyHighlight=vs;exports.createGraphyBuilder=xg;exports.createGroupValueReader=hd;exports.createHeadlineItemRows=eS;exports.createLabelValueReader=dd;exports.createLineFillAreaGenerator=mS;exports.createLinePathGenerator=dS;exports.createObservationAnchorParser=Ni;exports.createRawValueReader=W;exports.createSegmentYReader=Zt;exports.createSizeValueReader=md;exports.createSpec=ro;exports.createStableBandKeyGenerator=bS;exports.createStableCellKeyGenerator=SS;exports.createStableKeyGenerator=or;exports.createStrokeWidthValueReader=fd;exports.createStyleResolver=ir;exports.createValueFormatter=C;exports.createXValueReader=Ze;exports.createYValueReader=un;exports.cursorToPiePlane=pn;exports.cursorToPolar=Qt;exports.describeMeasurementBasis=$r;exports.extractConstantValue=l.extractConstantValue;exports.extractPlainText=No;exports.extractVariableName=l.extractVariableName;exports.filterLayersByGeoms=ap;exports.findAnnotation=mt;exports.findAverageLineLayer=dl;exports.findAxisGuide=Yn;exports.findDistinctLayers=bn;exports.findEquivalentHighlight=AA;exports.findGoalLineLayer=cl;exports.findHighlightsAtObservation=Eb;exports.findKindStyleDeclarations=ht;exports.findLayerByGeom=le;exports.findLayerById=D;exports.findLegendForAesthetic=Yb;exports.findObservationAttachment=ll;exports.findPointerRegion=gb;exports.findStyleRule=dr;exports.findStyleRuleIndex=na;exports.findTrendLineLayer=ul;exports.formatDifferenceLabel=Vo;exports.formatHeadline=Bb;exports.formatLegends=Kb;exports.formatRuleValue=qb;exports.geom=l.geom;exports.getAestheticFromScaleAestheticKey=P;exports.getAlpha=xo;exports.getAngleExtent=Un;exports.getBarRectBounds=Uo;exports.getBoundingRect=uS;exports.getChromeDashArray=sA;exports.getColor=dt;exports.getCrossAxisCoordinate=jt;exports.getCurve=sr;exports.getDashArray=iS;exports.getDifferenceArrowDimensions=Ro;exports.getDifferenceArrowLabelBox=ob;exports.getGroup=K;exports.getHoverGuideLineProps=px;exports.getHoverGuideRectProps=hx;exports.getInsetTileRect=Lo;exports.getLineType=Ao;exports.getMainAxisCoordinate=Ue;exports.getNumericWeight=Sa;exports.getPolarHoverGuideArcProps=fx;exports.getRadiusExtent=Wn;exports.getRuleDashPattern=vS;exports.getScaledAesthetic=ad;exports.getSize=Gn;exports.getStablePolarBarKeyGenerator=xS;exports.getStackRole=Is;exports.getStrokeWidth=Xr;exports.getTileRectBounds=To;exports.getUnionExtent=yS;exports.getX=R;exports.getXMax=U;exports.getXMin=G;exports.getY=w;exports.getYMax=_;exports.getYMin=k;exports.getYRaw=ln;exports.hasMultipleGroups=er;exports.highlight=xA;exports.inferDefaultDifferenceArrowEndpoints=Db;exports.inferDifferenceArrowEndpoints=$o;exports.inferXVariable=l.inferXVariable;exports.isAnnotationMovable=GA;exports.isBorderRadiusToken=l.isBorderRadiusToken;exports.isCartesian=ld;exports.isCategoricalValueFormat=l.isCategoricalValueFormat;exports.isComboChartType=vt;exports.isCompanionLayer=vn;exports.isCompilerCachingEnabled=l.isCompilerCachingEnabled;exports.isCurrencyValueFormat=l.isCurrencyValueFormat;exports.isDateWithoutYearValueFormat=l.isDateWithoutYearValueFormat;exports.isDefined=l.isDefined;exports.isFullTurnSweep=es;exports.isGeomStyleRule=aa;exports.isLayerOf=vg;exports.isLayerOfType=q;exports.isLineStyleType=Hi;exports.isLookupValueFormat=l.isLookupValueFormat;exports.isNumericValueFormat=l.isNumericValueFormat;exports.isObservationAttachmentKind=vA;exports.isPointWithinEditMenuTrigger=Tb;exports.isPointWithinRegionShape=zn;exports.isSafeUrl=Ux;exports.isStackedPosition=B;exports.isTemporalValueFormat=l.isTemporalValueFormat;exports.mapping=EA;exports.normalizeAngle=He;exports.orderPointerRegions=yb;exports.pickReadableTextColor=rd;exports.pipe=no;exports.placeCallouts=ab;exports.polarToUnit=$t;exports.positionToAngle=rs;exports.prefixInternalVariable=l.prefixInternalVariable;exports.prepareAreaObservations=oS;exports.prepareLineObservations=pS;exports.projectAnchorToPanel=Po;exports.quantiseKey=Y;exports.readAnchoredObservation=Ob;exports.readAttachedObservation=ta;exports.readAuthoredNumber=eA;exports.readAuthoredString=tA;exports.readChartType=aI;exports.readComboLineLayerId=oI;exports.readFoldKeepVariables=l.readFoldKeepVariables;exports.readHighlightDimStyle=Oc;exports.readMainAxisVariable=l.readMainAxisVariable;exports.readMappableAesthetics=HL;exports.readMappedVariable=zl;exports.readObservationIndex=gx;exports.readXExtent=al;exports.readYExtent=il;exports.resolveAnchorVariable=we;exports.resolveArrowColor=lb;exports.resolveAxisLabelStyle=cA;exports.resolveBarBandFraction=Hr;exports.resolveBarBorderRadiusPx=Go;exports.resolveBarBorderTreatment=cS;exports.resolveBarCornerRadiiPx=lS;exports.resolveColorRamp=Tn;exports.resolveComparisonBasis=gs;exports.resolveDataLabelStyle=dA;exports.resolveDeferredAnchors=Pv;exports.resolveDefinition=In;exports.resolveGraphChromeStyle=iA;exports.resolveGridLineStyle=nA;exports.resolveHeadlinePlacement=xv;exports.resolveObservationPoint=kb;exports.resolvePanelBorderStyle=rA;exports.resolvePolarBarCornerRadiusUnit=gS;exports.resolveRuleLabelStyle=mA;exports.resolveSegmentYSource=Xt;exports.resolveTextStyle=se;exports.resolveTickLabelStyle=uA;exports.resolveTickLineStyle=aA;exports.resolveTooltipStyle=pA;exports.resolveYScaleAesthetic=oe;exports.sampleColorScheme=qh;exports.scale=l.scale;exports.setCompilerCachingEnabled=l.setCompilerCachingEnabled;exports.stat=l.stat;exports.stepDifferenceArrowEndpoint=Pb;exports.style=l.style;exports.styles=l.styles;exports.toFontSpec=lA;exports.toPanelCursor=Mo;exports.toPercent=ve;exports.toViewBoxX=Dv;exports.toViewBoxY=ne;exports.token=l.token;exports.transform=l.transform;exports.truncateToWidth=io;exports.uniqueId=M;exports.unitToPolar=ns;exports.updateSpec=E;
|