@graphysdk/viz-engine 0.0.1-plugins.2 → 0.0.1-plugins.3
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 +3 -2
- package/dist/index.d.ts +9 -7
- package/dist/index.mjs +326 -287
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./geom.utils-DbZj1kY1.cjs"),v=require("date-fns"),le=require("lodash-es"),Ve=require("d3-time"),Vo=require("date-fns/differenceInDays"),q=require("d3-scale"),Fr=require("lodash-es/merge"),J=require("d3-regression"),Lo=require("humanize-duration"),Eo=require("d3-delaunay");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-plugins.2");function Fe(e,t){return Pr(e,t)}function xt(e,t){for(const n of Object.keys(t)){const r=t[n];if(r!==void 0&&r!==e[n])return{...e,...t}}return e}function Pr(e,t){let n=!1;const r={...e};for(const[a,o]of Object.entries(t)){const s=e[a];if(u.isPlainObject(o)&&u.isPlainObject(s)){const i=Pr(s,o);i!==s&&(r[a]=i,n=!0)}else o!==void 0&&o!==s&&(r[a]=o,n=!0)}return n?r:e}const ne=process.env.NODE_ENV!=="production";function ut(e){return{pipe:t=>{const n=t(e);return ut({...e,...n})},result:()=>e}}let dt=!0;const Mo=e=>{dt=e},Do=()=>dt,ko=()=>{let e=null;const t={hits:0,misses:0};return Object.assign((r,a)=>{if(!dt)return ne&&(t.misses+=1),a();if(e&&Gr(e.args,r))return ne&&(t.hits+=1),e.out;ne&&(t.misses+=1);const o=a();return e={args:r,out:o},o},{stats:t,reset:()=>{e=null}})},Br=()=>{const e=new WeakMap,t={hits:0,misses:0};return Object.assign((r,a,o)=>{if(!dt)return ne&&(t.misses+=1),o();const s=e.get(r);if(s){for(const c of s)if(Gr(c.args,a))return ne&&(t.hits+=1),c.out}ne&&(t.misses+=1);const i=o();return s?s.push({args:a,out:i}):e.set(r,[{args:a,out:i}]),i},{stats:t})},Ro=(...e)=>e.reduce((t,n)=>({hits:t.hits+n.hits,misses:t.misses+n.misses}),{hits:0,misses:0}),Gr=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0};class j{constructor(){this.memo=Br(),this.singletonKey={}}get stats(){return this.memo.stats}compile(t){return this.memo(this.key(t),this.dependencies(t),()=>this.run(t))}key(t){return this.singletonKey}}const be=e=>e[u.GROUP_VARIABLES.group],Co=e=>{const{coordinate:t,coordSystem:n}=e;return"observation"in t?_o(e):n.type!=="cartesian"?null:"unit"in t?{x:t.unit.x,y:t.unit.y,mode:"unit"}:No(t.data,e)},_o=({coordinate:e,layers:t,coordSystem:n,geomCompiler:r})=>{if(!("observation"in e))return null;const a=e.observation;for(const o of t){if(a.layerId!==void 0&&o.id!==a.layerId)continue;const s=u.extractVariableName(o.mapping.x);if(s!==null)for(const i of o.data){if(i[s]!==a.anchorValue||be(i)!==a.groupValue)continue;const c=r.resolveAnchorPosition(o.geom,i,n);if(c!==null)return{x:c.x,y:1-c.y,mode:"observation",observation:i}}}return null},No=(e,{coordSystem:t,scales:n})=>{const r=Gn(n,"x"),a=Gn(n,"y");if(r===null||a===null)return null;const o=r.map(e.x),s=a.map(e.y);if(!Number.isFinite(o)||!Number.isFinite(s))return null;const i=t.type==="cartesian"&&t.mainAxis==="y";return{x:i?s:o,y:1-(i?o:s),mode:"data"}},Gn=(e,t)=>{const n=e[t];return n!==void 0&&n.kind==="position"?n:null},R=e=>e instanceof Date&&v.isValid(e),Oo=e=>R(e)||e===null,Pe=e=>typeof e=="string",I=e=>typeof e=="number"&&!Number.isNaN(e)&&Number.isFinite(e);function zt(e){return e[u.VISUAL_VARIABLES.color]}function Fo(e){return e[u.VISUAL_VARIABLES.alpha]}function Ur(e){return e[u.VISUAL_VARIABLES.size]}function Po(e){return e[u.VISUAL_VARIABLES.strokeWidth]}function $r(e){return e[u.VISUAL_VARIABLES.lineType]??"solid"}const Gt=(e,t,n,r)=>{for(const a of t){if(e.layerId!==void 0&&a.id!==e.layerId)continue;const o=u.extractVariableName(a.mapping.x);if(o===null)continue;const s=u.extractVariableName(a.mapping.y);for(const i of a.data){if(i[o]!==e.anchorValue||be(i)!==e.groupValue)continue;const c=r.resolveAnchorPosition(a.geom,i,n);if(c===null)continue;const l=s!==null?i[s]??null:null;if(I(l))return{...c,measurementValue:l,color:zt(i)}}}return null};class Bo extends j{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[t.annotations,t.layers,t.coordSystem,t.scales.x,t.scales.y]}run(t){const{geomCompiler:n}=this;return{differenceArrows:Uo(t,n),shapes:t.annotations.shapes,freeformArrows:t.annotations.freeformArrows,textAnnotations:t.annotations.textAnnotations,stickers:At(t.annotations.stickers,t.layers,t.coordSystem,n),pinnedNumbers:At(t.annotations.pinnedNumbers,t.layers,t.coordSystem,n),comments:At(t.annotations.comments,t.layers,t.coordSystem,n),custom:Go(t,n)}}}const Go=({annotations:e,layers:t,coordSystem:n,scales:r},a)=>{const o=[];for(const s of e.custom){const i=[];let c=!1;for(const l of s.coordinates){const d=Co({coordinate:l,layers:t,coordSystem:n,scales:r,geomCompiler:a});if(d===null){c=!0;break}i.push(d)}c||o.push({id:s.id,type:s.type,params:s.params,zOrder:s.zOrder,targets:i})}return o},At=(e,t,n,r)=>{const a=[];for(const o of e){const s=Gt(o.anchor,t,n,r);s!==null&&a.push({...o,anchor:s})}return a},Uo=({annotations:e,layers:t,coordSystem:n},r)=>{if(n.type!=="cartesian")return[];const a=[];for(const o of e.differenceArrows){if($o(o.start,o.end))continue;const s=Gt(o.start,t,n,r),i=Gt(o.end,t,n,r);s===null||i===null||a.push({id:o.id,start:s,end:i,color:Yo(o,s,i),size:o.size,label:o.label,labelCrossPosition:o.labelCrossPosition})}return a},$o=(e,t)=>e.layerId===t.layerId&&e.anchorValue===t.anchorValue&&e.groupValue===t.groupValue,Yo=(e,t,n)=>e.color!==null?e.color:e.start.groupValue!==e.end.groupValue||t.color===void 0||t.color!==n.color?null:t.color;function Ko(e,t){const n=zo(t);return{...e,background:Ho(e.background,n),border:Wo(e.border,n)}}function Ho(e,t){if(e.type==="tinted"){const n=e.color??t;if(!n)throw new Error("could not resolve color for tinted background");return{type:"tinted",color:n}}return e}function Wo(e,t){if(e.type==="tinted"||e.type==="gradient"){const n=e.color??t;if(!n)throw new Error(`could not resolve color for ${e.type} background`);return{...e,color:n}}return e}function zo(e){const t=e.color,n=t?.domain[0];if(!n)return;const r=t.map(n);if(typeof r=="string")return r}class Xo extends j{dependencies(t){return[t.scales,t.config]}run(t){const{scales:n,config:r}=t;return{...r,appearance:Ko(r.appearance,n)}}}class qo extends j{dependencies(t){return[t.data,t.mapping]}run(t){let n=t.data,r=t.mapping;r.x===""&&(n=n.addConstantVariable(u.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:u.CONSTANT_VARIABLES.x});for(const a of Object.keys(r)){const o=u.extractConstantValue(r[a]);if(o===void 0)continue;const s=u.prefixInternalVariable(`const_${a}`);n=n.addConstantVariable(s,jo(o),o),r={...r,[a]:s}}return{data:n,mapping:r}}}const jo=e=>typeof e=="number"?"numeric":e instanceof Date?"temporal":"categorical";class Se{constructor(){this.perLayerMemo=Br(),this.listMemo=ko()}get stats(){return Ro(this.perLayerMemo.stats,this.listMemo.stats)}compile(t){const n=this.dependencies(t),r=t.layers.map(a=>this.perLayerMemo(a,n,()=>this.compileLayer(a,t)));return this.listMemo(r,()=>r)}}class Qo extends j{constructor(t){super(),this.registry=t}dependencies(t){return[t.coordSpec,t.scales,t.layers]}run(t){return this.registry.get(t.coordSpec.coordType).setup(t)}}class Zo extends Se{constructor(t){super(),this.registry=t}dependencies(t){return[t.coordSpec]}compileLayer(t,n){const r=this.registry.get(n.coordSpec.coordType),[a]=r.transform({coordSpec:n.coordSpec,layers:[t]});if(!a)throw new Error(`CoordCompiler: strategy '${n.coordSpec.coordType}' did not return a transformed layer`);return a}}class Jo{constructor(t){this.setupStage=new Qo(t),this.transformStage=new Zo(t)}get setupStats(){return this.setupStage.stats}get transformStats(){return this.transformStage.stats}setup(t){return this.setupStage.compile(t)}transform(t){return this.transformStage.compile(t)}}class xe{constructor(t){this.label=t,this.items=new Map}register(t,n){return this.items.set(t,n),this}get(t){if(!this.items.has(t)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new Error(`Unknown ${this.label}: '${t}' (available: ${n})`)}return this.items.get(t)}getAll(){return[...this.items.values()]}has(t){return this.items.has(t)}}class es{constructor(){this.coordType="cartesian"}setup(t){if(t.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{coordSystem:{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}},scales:t.scales}}transform(t){return t.layers}}class ts{constructor(t){this.geomRegistry=t,this.coordType="flip"}setup(t){if(t.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{coordSystem:{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}},scales:ns(t.scales,t.layers)}}transform(t){return t.layers.map(n=>{const r=this.geomRegistry.get(n.geom),a=u.derivePositionColumnPairs(r.positionChannels);return as(n,a)})}}const Un=u.prefixInternalVariable("flipSwap"),ns=(e,t)=>rs(t)?e.map(n=>n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"&&n.scaleType!=="discrete"?n:{...n,reverse:!n.reverse}):e,rs=e=>{for(const t of e){const n=u.extractVariableName(t.mapping.x);if(!n||!t.data.hasVariable(n))continue;const r=t.data.getType(n);if(r==="categorical"||r==="temporal")return!0}return!1},as=(e,t)=>{let n=e.data;for(const[r,a]of t){const o=n.hasVariable(r),s=n.hasVariable(a);o&&s?n=n.renameVariable(r,Un).renameVariable(a,r).renameVariable(Un,a):o?n=n.renameVariable(r,a):s&&(n=n.renameVariable(a,r))}return{...e,data:n}};class os{constructor(t){this.geomRegistry=t,this.coordType="polar"}setup(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec;return{coordSystem:{type:"polar",axisMapping:n.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:n.innerRadius,startAngle:n.startAngle*(Math.PI/180)},scales:t.scales}}transform(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec,r=ss(n),a=is(n);return t.layers.map(o=>{const s=this.geomRegistry.get(o.geom),i=u.derivePositionColumnPairs(s.positionChannels),c=n.theta==="y"?ls(o,i):o,l=cs(c,i,r,a),d=s.spatialKind==="points"?"polar-points":"arcs";return{...l,spatialMap:{kind:d}}})}}function ss(e){const t=e.startAngle*(Math.PI/180);return n=>n*2*Math.PI+t}function is(e){const{innerRadius:t}=e;return n=>t+n*(1-t)}function cs(e,t,n,r){let a=e.data;for(const[o,s]of t)a=$n(a,o,n),a=$n(a,s,r);return{...e,data:a}}function $n(e,t,n){if(!e.hasVariable(t))return e;const a=e.getValues(t,{type:"numeric"}).map(o=>o===null?null:n(o));return e.addVariable(t,"numeric",a)}function ls(e,t){let n=e.data;for(const[r,a]of t){const o=n.hasVariable(r),s=n.hasVariable(a);if(!o&&!s)continue;const i=o?n.getValues(r):null,c=s?n.getValues(a):null;i&&(n=n.addVariable(a,"numeric",i)),c&&(n=n.addVariable(r,"numeric",c))}return{...e,data:n}}class us extends xe{constructor(t){super("coord"),this.register("cartesian",new es),this.register("flip",new ts(t)),this.register("polar",new os(t))}}class Yr{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(t){this.previousYear===null?this.previousYear=t.getUTCFullYear():this.previousDate!==null&&v.isBefore(new Date(this.currentYear,t.getUTCMonth(),t.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(t.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const Kr=e=>{const t=Object.entries(e);return!t.length||!t.some(([,n])=>!Be(n))},Be=e=>typeof e=="string"&&e.trim()===""||e===void 0||e===null||e==="-",mt="en-GB",ds=e=>e.type==="lookup",ms=e=>e.type==="text",Ge=e=>e.type==="date"||e.type==="datetime"||e.type==="year"||e.type==="month_year"||e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range"||e.type==="weekly_date_range_with_year"||e.type==="quarter"||e.type==="time",Hr=e=>e.type==="decimal"||e.type==="integer"||e.type==="percentage"||e.type==="duration"||e.type==="currency",Wr=e=>e.type==="currency",zr=e=>e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range",Xr=e=>{if(ds(e))return Xr(e.fallback);if(Ge(e))return"temporal";if(Hr(e))return"numeric";if(ms(e))return"categorical";const t=e;throw new Error(`No data type found for value format: ${t.type}`)},Re={k:1e3,m:1e6,b:1e9,t:1e12},Xt=["k","m","b","t"],ps=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${Xt.join("|")})?$`,"i"),fs=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,oe=e=>e===null||e instanceof Date||Array.isArray(e)||typeof e=="boolean"?!1:typeof e=="string"?ps.test(e)&&!Number.isNaN(Number(e.replace(new RegExp(`[,${Xt.join("")}]`,"gi"),""))):!Number.isNaN(Number(e)),qr=e=>oe(e)?!0:typeof e=="string"?fs.test(e):!1,hs=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,ys=/^\s*(19\d{2}|2[01]\d{2})\s*$/,gs=[[/\bJan\b/i,"January"],[/\bFeb\b/i,"February"],[/\bMar\b/i,"March"],[/\bApr\b/i,"April"],[/\bJun\b/i,"June"],[/\bJul\b/i,"July"],[/\bAug\b/i,"August"],[/\bSept?\b/i,"September"],[/\bOct\b/i,"October"],[/\bNov\b/i,"November"],[/\bDec\b/i,"December"]],bs={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},jr=["/","-","."," "],Yn=[["d","M","yy"],["d","MM","yy"],["d","MMMM","yy"],["dd","M","yy"],["dd","MM","yy"],["dd","MMMM","yy"],["do","MMMM","yy"],["d","M","yyyy"],["d","MM","yyyy"],["d","MMMM","yyyy"],["dd","M","yyyy"],["dd","MM","yyyy"],["dd","MMMM","yyyy"],["do","MMMM","yyyy"]],Kn=[["M","d","yy"],["M","dd","yy"],["MM","d","yy"],["MM","dd","yy"],["MMMM","d","yy"],["MMMM","dd","yy"],["MMMM","do","yy"],["M","d","yyyy"],["M","dd","yyyy"],["MM","d","yyyy"],["MM","dd","yyyy"],["MMMM","d","yyyy"],["MMMM","dd","yyyy"],["MMMM","do","yyyy"]],Hn=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],Qr=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],Ss=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],Zr=1900,Jr=2199,xs=3,As=6,vs=5,Ts=1,Is=28,ws=/\s*[–—]\s*|\s-\s/,Vs=e=>typeof e=="number"?Number.isNaN(e)?!1:e>=Zr&&e<=Jr:typeof e=="string"?ys.test(e):!1,ea=(e,t)=>{const n=Ce(e);return oe(n)?Ms(n):typeof n=="string"?!!ta(n)||qt(n)&&v.isValid(new Date(n)):v.isValid(n)},Ce=e=>{if(typeof e!="string")return e;let t=e;for(const[n,r]of gs)t=t.replace(n,r);return t},ta=(e,t=mt)=>{const n=Ce(e);return qt(n)?{type:"datetime"}:na(t).find(r=>!Ge(r)||r.type==="month"&&n.length<xs?!1:r.dateFormat&&v.isValid(v.parse(n,r.dateFormat,new Date)))},qt=e=>hs.test(e.trim()),Ls=(e,t=mt)=>{const[n,r]=e.split(ws);if(!n||!r)return;const a=Ce(n).trim(),o=Ce(r).trim();return Es(t).find(s=>{if(!Ge(s)||!s.dateFormat)return!1;const i=v.parse(a,s.dateFormat,new Date),c=v.parse(o,s.dateFormat,new Date);if(!v.isValid(i)||!v.isValid(c))return!1;const l=new Yr,d=l.incrementYearIfNeeded(i),m=l.incrementYearIfNeeded(c),p=v.differenceInDays(m,d);return v.isWithinInterval(new Date(d.getFullYear(),Ts,Is),{start:d,end:m})&&p===vs?!0:p===As})},na=e=>{const t={date:ra(e),year:[["yyyy"]],day_month:Qr,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...Ss,...Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>jr.map(o=>({dateFormat:a.join(o),type:n}))))]},ra=e=>bs[e]==="MDY"?[...Kn,...Yn,...Hn]:[...Yn,...Kn,...Hn],Es=e=>{const t={weekly_date_range:Qr,weekly_date_range_with_year:ra(e)};return Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>jr.map(o=>({dateFormat:a.join(o),type:n}))))},Ms=e=>{const t=Number(e);if(!le.isInteger(t))return!1;const n=new Date(t),r=new Date(t*1e3),a=o=>v.isValid(o)&&o.getFullYear()>=Zr&&o.getFullYear()<=Jr;return a(n)||a(r)},aa={$:"usd","£":"gbp","€":"eur","¥":"jpy","₹":"inr","₱":"php",P:"php","₩":"krw","₪":"ils","₫":"vnd","₽":"rub","฿":"thb",R$:"brl",Rp:"idr",RM:"myr","₦":"ngn",zł:"pln","₺":"try",kr:"dkk",Fr:"chf",R:"zar","د.إ":"aed","﷼":"sar",Ch$:"clp",NT$:"twd",HK$:"hkd",S$:"sgd",A$:"aud",C$:"cad",NZ$:"nzd",MX$:"mxn"},oa=e=>{if(typeof e=="string"){const t=sa(e);return t.length?oe(t):!1}return oe(e)},Ds=e=>{const t=ia(e),n=t?aa[t]:void 0;if(!n)throw new Error("Could not get currency ISO");return n},sa=e=>{const t=ia(e);let n=e;if(t){const r=e.indexOf(t);r===0?n=e.slice(t.length):r===e.length-t.length?n=e.slice(0,e.length-t.length):e[0]==="-"&&r===1&&(n=`-${e.slice(t.length+1)}`)}return oe(n)?n.split(",").join(""):""},ia=e=>Object.keys(aa).sort((n,r)=>r.length-n.length).find(n=>e.includes(n)),ks=(e,t)=>{const n=typeof e=="string"?e.trim():e;if(oe(n))return{type:"decimal"};const r=typeof n=="string"&&ta(n,t);if(r)return r;const a=typeof n=="string"&&Ls(n,t);return a||(ea(e)?{type:"date"}:qr(e)?{type:"percentage"}:oa(e)&&typeof e=="string"?{type:"currency",iso:Ds(e)}:{type:"text"})},Rs=/\s*[–—]\s*|\s-\s/,Cs=(e,t,n)=>{if(Be(e))return null;switch(t.type){case"decimal":case"integer":case"duration":return ca(e);case"percentage":return _s(e);case"currency":return Ns(e);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return jt(e,t.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return Os(e,t.dateFormat,n);case"text":return Fs(e);case"lookup":throw new Error("Cannot parse: lookup value formats are produced by transforms, not raw input");default:{const r=t;throw new Error(`Unhandled value format: ${r.type}`)}}},jt=(e,t,n)=>{if(e instanceof Date)return v.isValid(e)?e:null;const r=Ce(String(e).trim());if(r.length===0)return null;const a=new Date;if(t){const s=v.parse(r,t,a);return v.isValid(s)?vt(s):null}for(const s of na(n)){if(!Ge(s)||!s.dateFormat)continue;const i=v.parse(r,s.dateFormat,a);if(v.isValid(i))return vt(i)}const o=new Date(r);return ea(o)?qt(r)?o:vt(o):null},ca=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;let t=e.trim();if(!oe(t))return null;let n=1;for(const r of Xt)if(new RegExp(`${r}$`,"i").test(t)){n=Re[r],t=t.slice(0,-1);break}return Number(t.split(",").join(""))*n},_s=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();if(!qr(t))return null;const n=Number(t.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},Ns=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();return oa(t)?ca(sa(t)):null},Os=(e,t,n)=>{const r=String(e).trim().split(Rs),[a,o]=[r[0]?.trim(),r[1]?.trim()];return!a||!o?null:jt(a,t,n)},Fs=e=>String(e).trim(),vt=e=>new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())),Ps={type:"year",dateFormat:"yyyy"};class Bs extends j{dependencies(t){return[t]}run(t){const n=t._metadata?.parsingLocale??mt,r={},a=$s(t),o=Gs(t);for(const[s,i]of t.columns.entries()){if(i._metadata?.isHidden)continue;const c=a.get(i.key);if(Be(c))continue;const l=s===o?Ps:ks(c,n),d=Xr(l);r[i.key]=Us(i.key,t.rows,l,d,n)}return new u.Dataset(r)}}const Gs=e=>{const t=Ys(e.rows,5);return e.columns.findIndex(n=>{const r=t.map(a=>a[n.key]).filter(a=>!Be(a));return r.length>=2&&r.every(Vs)})},Us=(e,t,n,r,a)=>{const o=new Yr,s=t.reduce((i,c)=>{if(Kr(c))return i;const l=Cs(c[e],n,a);return zr(n)&&R(l)?i.push(o.incrementYearIfNeeded(l)):i.push(l),i},[]);return{type:r,values:s,valueFormat:n}},$s=e=>{const t=new Map,n=new Set(e.columns.map(r=>r.key));for(const r of e.rows){for(const a of n){const o=r[a];Be(o)||(t.set(a,o),n.delete(a))}if(n.size===0)break}return t},Ys=(e,t)=>{const n=[];for(const r of e)if(Kr(r)||n.push(r),n.length===t)return n;return n};class Ks{constructor(t){this.registry=t}compile(t,n){return this.registry.get(t).compile(n)}getPositionChannels(t){return this.registry.get(t).positionChannels}getSwatchShape(t){return this.registry.get(t).swatchShape}getSpatialKind(t){return this.registry.get(t).spatialKind}getVisualAesthetics(t){return this.registry.get(t).visualAesthetics}getHighlightStrategy(t){return this.registry.get(t).highlightStrategy}getDirectLabelPositions(t){return this.registry.get(t).directLabelPositions}getGridPolicies(t){return this.registry.get(t).gridPolicies}getIdentityKeyStrategy(t){return this.registry.get(t).identityKeyStrategy}emitsGrandTotal(t){return this.registry.get(t).emitsGrandTotal}emitsStackTotals(t){return this.registry.get(t).emitsStackTotals}supportsPerGroupHeadline(t){return this.registry.get(t).supportsPerGroupHeadline}resolveAnchorPosition(t,n,r){return this.registry.get(t).resolveAnchorPosition(n,r)}}class Hs extends u.Geom{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"lower",valueKind:"value"},{axis:"y",role:"upper",valueKind:"value"}],this.swatchShape="area",this.highlightStrategy="overlay-anchor",this.spatialKind="buckets",this.directLabelPositions=["identity","stack","dodge","fill"],this.supportsPerGroupHeadline=!0}compile({data:t,mapping:n}){if(t=u.sortByXIfContinuous(t,n),t.hasVariable(u.POSITION_VARIABLES.yMin)||(t=t.addConstantVariable(u.POSITION_VARIABLES.yMin,"numeric",0)),!t.hasVariable(u.POSITION_VARIABLES.yMax)){const r=u.extractVariableName(n.y);u.isDefined(r)&&t.hasVariable(r)&&(t=t.addVariable(u.POSITION_VARIABLES.yMax,"numeric",t.getValues(r,{type:"numeric"})))}return{data:t,mapping:{}}}}const la=.7,Ws=.1;function Ae(e){return e[u.POSITION_VARIABLES.x]}function z(e){return e[u.POSITION_VARIABLES.y]}function _e(e){return e[u.POSITION_VARIABLES.xMin]}function ye(e){return e[u.POSITION_VARIABLES.xMax]}function se(e){return e[u.POSITION_VARIABLES.yMin]}function $(e){return e[u.POSITION_VARIABLES.yMax]}function ua(e){return e[u.POSITION_VARIABLES.yRaw]}class zs extends u.Geom{constructor(){super(...arguments),this.type="bar",this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"x",role:"lower",valueKind:"bandOffset"},{axis:"x",role:"upper",valueKind:"bandOffset"},{axis:"y",role:"lower",valueKind:"value"},{axis:"y",role:"upper",valueKind:"value"}],this.swatchShape="square",this.highlightStrategy="observation-rerender",this.spatialKind="rects",this.directLabelPositions=["stack","fill"],this.gridPolicies={cartesian:{hideGridX:!0},flip:{hideGridX:!0},polar:{hideGridX:!0,hideGridY:!0}},this.emitsGrandTotal=!0,this.emitsStackTotals=!0,this.supportsPerGroupHeadline=!0}compile({data:t,mapping:n}){if(t=u.sortByXIfContinuous(t,n),t.hasVariable(u.POSITION_VARIABLES.yMin)||(t=t.addConstantVariable(u.POSITION_VARIABLES.yMin,"numeric",0)),!t.hasVariable(u.POSITION_VARIABLES.yMax)){const a=u.extractVariableName(n.y);u.isDefined(a)&&t.hasVariable(a)&&(t=t.addVariable(u.POSITION_VARIABLES.yMax,"numeric",t.getValues(a,{type:"numeric"})))}const r=la/2;return t=t.addConstantVariable(u.POSITION_VARIABLES.xMin,"numeric",-r).addConstantVariable(u.POSITION_VARIABLES.xMax,"numeric",r),{data:t,mapping:{}}}resolveAnchorPosition(t,n){if(n.type==="polar"){const s=_e(t),i=ye(t),c=se(t),l=$(t);if(s===null||i===null||c===null||l===null)return null;const d=(s+i)/2,m=(c+l)/2;return{x:.5+.5*m*Math.sin(d),y:.5-.5*m*Math.cos(d),geom:"polar-bar"}}if(n.mainAxis==="x"){const s=_e(t),i=ye(t),c=$(t)??z(t);return s===null||i===null||c===null?null:{x:(s+i)/2,y:c,geom:"bar"}}const r=se(t),a=$(t),o=ye(t)??Ae(t);return r===null||a===null||o===null?null:{x:o,y:(r+a)/2,geom:"bar"}}}class Xs extends u.Geom{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.swatchShape="line",this.highlightStrategy="overlay-anchor",this.spatialKind="buckets",this.directLabelPositions=["identity","stack","dodge","fill"],this.supportsPerGroupHeadline=!0}compile(t){return{data:u.sortByXIfContinuous(t.data,t.mapping),mapping:{}}}resolveAnchorPosition(t,n){if(n.type==="polar")return null;const r=Ae(t),a=z(t);return r===null||a===null?null:{x:r,y:a,geom:"line"}}}class qs extends u.Geom{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.swatchShape="circle",this.highlightStrategy="overlay-anchor",this.spatialKind="points",this.identityKeyStrategy="index",this.supportsPerGroupHeadline=!0}compile({data:t}){return{data:t,mapping:{}}}}class js extends u.Geom{constructor(){super(...arguments),this.type="rule",this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.highlightStrategy=null,this.supportedCoordTypes=["cartesian","flip"]}compile({data:t,mapping:n}){const r=Wn(n.y,t);if(r!==null)return{data:new u.Dataset({[u.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:u.RULE_VARIABLES.y,x:void 0}};const a=Wn(n.x,t);return a!==null?{data:new u.Dataset({[u.RULE_VARIABLES.x]:{type:"numeric",values:[a.value],valueFormat:a.sourceFormat}}),mapping:{x:u.RULE_VARIABLES.x,y:void 0}}:{data:new u.Dataset,mapping:{x:void 0,y:void 0}}}validateMapping({layerId:t,mapping:n,computedVariables:r}){const a=r.has("x")||I(u.extractConstantValue(n.x)),o=r.has("y")||I(u.extractConstantValue(n.y));return a&&o?[{code:"INVALID_RULE_MAPPING",message:`Layer '${t}': rule geom requires exactly one of 'x' or 'y', both were provided`,layerId:t}]:!a&&!o?[{code:"INVALID_RULE_MAPPING",message:`Layer '${t}': rule geom requires a numeric value on 'x' or 'y'`,layerId:t}]:[]}}const Wn=(e,t)=>{const n=u.extractConstantValue(e);if(I(n))return{value:n,sourceFormat:void 0};const r=u.extractVariableName(e);if(r===null||!u.isStatVariable(r)||!t.hasVariable(r))return null;const[a]=t.getValues(r);return I(a)?{value:a,sourceFormat:t.getValueFormat(r)}:null};class Qs extends xe{constructor(t){super("geom"),this.register("bar",new zs),this.register("point",new qs),this.register("line",new Xs),this.register("area",new Hs),this.register("rule",new js);for(const n of t?.geoms??[])this.register(n.type,n)}}const Qt=(e,t)=>{if(u.isDefined(t.group)){const a=u.extractVariableName(t.group);if(a!==null)return[a]}const n=new Set([u.extractVariableName(t.x),u.extractVariableName(t.y)].filter(u.isDefined)),r=new Set;for(const a in t){if(a==="x"||a==="y")continue;const o=u.extractVariableName(t[a]);u.isDefined(o)&&(n.has(o)||e.getType(o)==="categorical"&&r.add(o))}return[...r]};class Zs{compute({data:t,mapping:n}){const r=Qt(t,n);if(r.length===0)return{data:t.addConstantVariable(u.GROUP_VARIABLES.group,"categorical",null)};const a=t.size(),o=r.map(i=>t.getValues(i)),s=new Array(a);for(let i=0;i<a;i++)s[i]=u.getStableKey(o.map(c=>c[i]));return{data:t.addVariable(u.GROUP_VARIABLES.group,"categorical",s)}}}const da=new Set(["x","y","ySecondary"]),pt=new Set(["color","size","alpha","strokeWidth","lineType"]),ft=e=>da.has(e),Js=e=>pt.has(e),ei=e=>ft(e)||Js(e);function Ue(e){return e==="secondary"?"ySecondary":"y"}function Y(e){return e==="ySecondary"?"y":e}const ti=e=>{if(e===void 0)return{};const t={};for(const n of e.columns)n.label!==void 0&&(t[n.key]=n.label);return t},ni=(e,t,n)=>{const r=ie(t,"color");return r===null?{}:(e?.columns??[]).some(s=>s.key===r)?{}:n};function ie(e,t){const n=Y(t);for(const r of ma(t,e)){const a=u.extractVariableName(r.mapping[n]);if(u.isDefined(a))return a}return null}const Zt=(e,t)=>e===null?null:t[e]??e,ri=(e,t)=>e===null?null:t[String(e)]??null,ce=({layers:e,scaleType:t,variableName:n})=>{if(n===null)return Tt(t);for(const r of e){if(!r.data.hasVariable(n))continue;const a=r.data.getValueFormat(n),o=a.type==="lookup"?a.fallback:a;return oi(o,t)?o:Tt(t)}return Tt(t)},ai=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:ma(t,e).some(n=>n.position==="fill");function ma(e,t){return e==="ySecondary"?t.filter(n=>n.yScaleType==="secondary"):e==="y"?t.filter(n=>n.yScaleType==="primary"):t}const Tt=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},oi=(e,t)=>{switch(t){case"continuous":return Hr(e);case"datetime":return Ge(e);case"discrete":case"palette":case"identity":return!0}},si=[{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}],zn={year:0,quarter:1,month:2,week:3,day:4,hour:5},de=40,ii=(e,t,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return di(n.unit).range(e,new Date(t.valueOf()+1),r)},ci=({unit:e,step:t,start:n,stop:r})=>{const a=Vo.differenceInDays(r,n);switch(e){case"hour":return 24*a/t>de;case"day":return a/t>de;case"week":return a/(7*t)>de;case"month":return a/(30*t)>de;case"quarter":return a/(90*t)>de;case"year":return a/(365*t)>de}},li=(e,t)=>{const n=!zr(t);switch(e.unit){case"year":return n?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return n?{type:"month_year"}:{type:"month"};case"week":return n?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return n?{type:"date"}:{type:"day_month"};case"hour":return n?{type:"datetime"}:{type:"time"}}},ui=(e,t)=>{const n=mi(t);return n===null?!1:zn[e]>zn[n]},di=e=>{switch(e){case"hour":return Ve.utcHour;case"day":return Ve.utcDay;case"week":return Ve.utcMonday;case"month":case"quarter":return Ve.utcMonth;case"year":return Ve.utcYear}},mi=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}},pa={left:"right",right:"left",top:"bottom",bottom:"top"},pi={x:!0,y:!0,ySecondary:!1},fi=20,Xn=new Set(["top","bottom"]),hi={type:"percentage"};function yi(e,t){const{scales:n,config:r,layers:a,coordSystem:o,variableLabels:s,geomCompiler:i}=e;if(o.type==="polar"&&o.axisMapping.x.geometry!=="circular")return[];const c=bi(a,o.type,r,i),l=new Set(t.map(p=>p.position)),d=xi(fa(r.axes.y.position,o.axisMapping.y.position),l),m=[];for(const p of da){const f=n[p];if(!u.isDefined(f)||f.kind!=="position")continue;const h=gi({scaleAestheticKey:p,scale:f,config:r,layers:a,axisMapping:o.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(h)}return m}function gi(e){const{scaleAestheticKey:t,scale:n,config:r,layers:a,axisMapping:o,resolvedYPosition:s,gridOverrides:i,variableLabels:c}=e,l=Y(t),{axisConfig:d,position:m}=Si(t,r,o,s),p=ie(a,t),f=ai(a,t)?hi:ce({layers:a,scaleType:n.spec.scaleType,variableName:p}),h=Zt(p,c);return{scaleAestheticKey:t,aesthetic:l,position:m,geometry:o[t==="x"?"x":"y"].geometry,label:d.label??h,isVisible:d.isVisible,tickCandidates:vi(n,f),valueFormat:f,tickMode:d.ticks.mode,ticksVisible:d.ticks.isVisible,gridVisible:Ai(d,i,t),scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function bi(e,t,n,r){const a=e.flatMap(c=>{const l=r.getGridPolicies(c.geom)[t];return l?[l]:[]}),o=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY),i=a.some(c=>c.hideBorder);return{x:{gridVisible:qn(o,n.axes.x.grid.isVisible)},y:{gridVisible:qn(s,n.axes.y.grid.isVisible)},borderVisible:i?!1:void 0}}function qn(e,t){if(e&&t===null)return!1}function Si(e,t,n,r){switch(e){case"x":return{axisConfig:t.axes[e],position:fa(t.axes[e].position,n[e].position)};case"y":return{axisConfig:t.axes[e],position:r};case"ySecondary":{const a=pa[r],o=le.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:o,position:o.position}}}}function fa(e,t){return Xn.has(e)===Xn.has(t)?e:t}function xi(e,t){return t.has(e)?pa[e]:e}function Ai(e,t,n){const{gridVisible:r}=n==="x"?t.x:t.y;return r??e.grid.isVisible??pi[n]}const vi=(e,t)=>{if(e.spec.scaleType==="continuous"){const r=new Set,a=[];for(let o=1;o<=fi;o++){const s=e.generateTicks({count:o}),i=u.getStableKey(s);r.has(i)||(r.add(i),a.push({ticks:s.map(c=>st(e,c))}))}return a}return e.spec.scaleType==="datetime"?Ti(e,t):[{ticks:e.generateTicks().map(r=>st(e,r))}]},Ti=(e,t)=>{const[n,r]=e.domain;if(!R(n)||!R(r))return[{ticks:e.generateTicks().map(c=>st(e,c))}];const a=new Set,o=[],s=(i,c)=>{if(i.length===0)return;const l=u.getStableKey(i);a.has(l)||(a.add(l),o.push({ticks:i.map(d=>st(e,d)),valueFormat:c}))};for(const i of si)ci({...i,start:n,stop:r})||ui(i.unit,t)||s(e.generateTicks({interval:i}),li(i,t));return s(e.generateTicks({atInputs:!0})),o.sort((i,c)=>i.ticks.length-c.ticks.length),o},st=(e,t)=>({value:t,position:e.map(t)});function Ne(e,t){return t.type==="polar"&&e==="square"?"slice":e}function ha({scale:e,aesthetics:t,layers:n,coordSystem:r}){const a=Ii({layers:n,coordSystem:r,aesthetics:t}),o=ya({layers:n,aesthetics:t});return e.domain.map(s=>({value:s,swatchShape:a(s),owner:o(s)}))}function Ii({layers:e,coordSystem:t,aesthetics:n}){const r=ya({layers:e,aesthetics:n}),a=e.find(s=>n.some(i=>u.isDefined(s.mapping[i]))),o=a?Ne(a.swatchShape,t):"square";return s=>{const i=r(s);return i?Ne(i.layer.swatchShape,t):o}}function ya({layers:e,aesthetics:t,layerFilter:n}){const r=new Map;for(const[a,o]of e.entries()){if(n&&!n(o))continue;const s=t.find(c=>u.isDefined(o.mapping[c]));if(s===void 0)continue;const i=u.extractVariableName(o.mapping[s]);if(!(i===null||!o.data.hasVariable(i)))for(const c of o.data.getValues(i,{distinct:!0})){const l=u.getStableKey(c);r.has(l)||r.set(l,{layer:o,layerIndex:a})}}return a=>r.get(u.getStableKey(a))}const Jt=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function wi({scales:e,layers:t,coordSystem:n,valueLabels:r}){const a=e.color;if(a===void 0||!Jt(a))return[];if(!t.some(d=>u.isDefined(d.mapping.color)))return[];const o=ie(t,"color");if(ga({colorVariableName:o,xVariableName:ie(t,"x"),mapsColorAcrossMultipleLayers:Li(t)>1,isMergedWithAnotherAesthetic:Vi(e,t,o)}))return[];const i=a.spec.scaleType,c=t.findIndex(d=>u.isDefined(d.mapping.color));return ha({scale:a,aesthetics:["color"],layers:t,coordSystem:n}).map(({value:d,swatchShape:m,owner:p})=>{const f=p?.layerIndex??c,h=t[f],y=h?u.extractVariableName(h.mapping.color):null;return{value:d,color:String(a.map(d)),shape:m,layerIndex:f,valueFormat:ce({layers:h?[h]:t,scaleType:i,variableName:y}),label:ri(d,r)}})}const ga=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:n,isMergedWithAnotherAesthetic:r})=>r?!1:e===null||u.isInternalVariable(e)?!n:t!==null&&e===t;function Vi(e,t,n){if(n===null)return!1;for(const r of pt){if(r==="color")continue;const a=e[r];if(!(a===void 0||!Jt(a))&&ie(t,r)===n)return!0}return!1}const Li=e=>e.filter(t=>u.isDefined(t.mapping.color)).length;function Ei(e,t,n,r){const a=t.findIndex(o=>r.supportsPerGroupHeadline(o.geom));if(a===-1)return[];if(e.length<2){const o=u.extractVariableName(t[a]?.mapping.y);return[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Zt(o,n)}]}return e.map(o=>({value:o.value,swatch:{color:o.color,shape:o.shape},layerIndex:o.layerIndex,groupLabelFormat:o.valueFormat,label:o.label}))}function jn(e,t,n){if(n===null||t===null)return[...e];const r=u.getStableKey(n);return e.filter((a,o)=>u.getStableKey(t[o]??null)===r)}const Mi=(e,t)=>{switch(t){case"total":{const{sum:n,count:r}=Qn(e);return r===0?null:n}case"average":{const{sum:n,count:r}=Qn(e);return r===0?null:n/r}case"current":return e.at(-1)??null}},Di=(e,t)=>{if(e.length<2)return null;const n=e.at(-1),r=t==="previous"?e.at(-2):e.at(0);return n===void 0||r===void 0||n.cross===null||r.cross===null||r.cross===0?null:{variation:(n.cross-r.cross)/r.cross,against:r.main}},Qn=e=>e.reduce((t,n)=>n===null?t:{sum:t.sum+n,count:t.count+1},{sum:0,count:0});function ki(e){const{config:t,coordSystem:n}=e,r=t.headline.show;return r==="none"||r==="conversion"?null:n.type==="polar"?Ri(e,r):Ci(e,r)}function Ri(e,t){if(t!=="total")return null;const{scales:n,layers:r}=e,a=r.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const o=a.summary.grandTotal;if(o===void 0)return null;const s=u.extractVariableName(a.mapping.y);if(s===null)return null;const i=ce({layers:[a],scaleType:n.y?.spec.scaleType??"continuous",variableName:s});return{kind:"grandTotal",value:o,valueFormat:i}}function Ci(e,t){const{config:n,scales:r,layers:a,variableLabels:o,colorGroups:s,geomCompiler:i}=e;if(!a.some(d=>i.supportsPerGroupHeadline(d.geom)))return null;const c=Ei(s,a,o,i);if(c.length===0)return null;const l=c.map(d=>_i({group:d,show:t,compareWith:n.headline.compareWith,layers:a,scales:r})).filter(d=>d!==null);return l.length===0?null:{kind:"perGroup",items:l}}function _i({group:e,show:t,compareWith:n,layers:r,scales:a}){const o=r[e.layerIndex];if(o===void 0)return null;const s=u.extractVariableName(o.mapping.y);if(s===null||t==="total"&&o.position==="fill")return null;const i=u.extractVariableName(o.mapping.x),c=u.extractVariableName(o.mapping.color),l=o.yScaleType==="secondary"?a.ySecondary:a.y,d=ce({layers:[o],scaleType:l?.spec.scaleType??"continuous",variableName:s}),m=Fi(o.data,i),p=ce({layers:[o],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:i}),f=Pi(o.data,i),h=f.getValues(s,{type:"numeric"}),y=i!==null?f.getValues(i):[],g=c!==null?f.getValues(c):null,S=jn(h,g,e.value),b=jn(y,g,e.value);return{value:e.value,swatch:e.swatch,aggregate:Mi(S,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:p,label:e.label,observationLabel:Ni(t,m,b),comparison:Oi(t,n,m,b,S)}}function Ni(e,t,n){if(e==="current"){const o=n.at(-1);return o===void 0?null:{kind:"point",value:o}}if(!t)return null;const r=n.at(0),a=n.at(-1);return r===void 0||a===void 0?null:{kind:"range",from:r,to:a}}function Oi(e,t,n,r,a){if(e!=="current"||!n)return null;const o=t==="none"?"first":t,s=r.map((i,c)=>({main:i,cross:a[c]??null}));return Di(s,o)}function Fi(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Pi(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}const ba=["point","line","area","bar","rule"],Sa=new Set(ba);function xa(e){return Sa.has(e)}function O(e){return e==="stack"||e==="fill"}const Bi=3;function Gi({scales:e,config:t,layers:n,coordSystem:r,variableLabels:a,colorGroups:o,geomCompiler:s}){if(t.legend.position==="none")return[];const i=new Map(o.map(g=>[u.getStableKey(g.value),g])),c=Yi({scales:e,layers:n,geomCompiler:s}),l=Xi(c),d=ie(n,"x"),m=l.map(g=>{if(Wi(g,d,n))return null;const S=ji({group:g,variableLabels:a,layers:n,coordSystem:r,colorGroupsByValue:i});return S.items.length===0?null:{group:g,built:S}}).filter(u.isDefined);if(m.length===0)return[];const p=Ui(m);if(t.legend.position==="auto"&&tc(p,n,r))return[];const f=nc(t.legend.position,p,n,r),h=ac(t.legend.display,f,n,r,s),y=h==="direct"?ic(n):null;return m.map(({built:g})=>$i(g,f,h,y))}function Ui(e){return e.reduce((t,{group:n,built:r})=>{const a=n.some(o=>o.guideType!=="discrete");return t+(a?1:r.items.length)},0)}function $i(e,t,n,r){return n!=="direct"||r===null?{...e,position:t,display:n}:{...e,position:t,display:n,items:e.items.map(a=>({...a,normalizedY:r.get(String(a.value))??null}))}}function Yi(e){const{scales:t,layers:n,geomCompiler:r}=e,a=Ki(n,r),o=[];for(const s of pt){if(!a.has(s))continue;const i=t[s];if(i===void 0||i.kind==="identity"||!Hi(s,n))continue;const c=ie(n,s),l=sc(s,i);o.push({scaleAestheticKey:s,scale:i,variableName:c,guideType:l})}return o}function Ki(e,t){const n=new Set;for(const r of e)for(const a of t.getVisualAesthetics(r.geom))n.add(a);return n}function Hi(e,t){const n=Y(e);return t.some(r=>u.isDefined(r.mapping[n]))}function Wi(e,t,n){const[r]=e;return r.scaleAestheticKey!=="color"?!1:ga({colorVariableName:r.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:zi(r.scaleAestheticKey,n),isMergedWithAnotherAesthetic:e.length>1})}function zi(e,t){const n=Y(e);return t.filter(r=>u.isDefined(r.mapping[n])).length>1}function Xi(e){const t=new Map;for(const n of e){const r=oc(n),a=t.get(r);a?a.push(n):t.set(r,[n])}return[...t.values()]}function qi(e,t,n){if(t==="lineType"){e.lineType=n;return}if(t==="color"){e.color=String(n);return}e[t]=n}function ji({group:e,variableLabels:t,layers:n,coordSystem:r,colorGroupsByValue:a}){const o=e[0],s=e.map(d=>Y(d.scaleAestheticKey)),i=ha({scale:o.scale,aesthetics:s,layers:n,coordSystem:r}),c=Zt(o.variableName,t),l=ce({layers:n,scaleType:o.scale.spec.scaleType,variableName:o.variableName});return{aesthetics:e.map(d=>d.scaleAestheticKey),title:c,items:i.map(d=>Qi(d,e,s,l,a))}}function Qi(e,t,n,r,a){const o={};for(const i of t)qi(o,i.scaleAestheticKey,i.scale.map(e.value));const s=Ji(e,t,n,r,a);return{value:e.value,label:Zi(t,e,a),visual:o,normalizedY:null,swatchShape:e.swatchShape,valueFormat:s}}function Zi(e,t,n){return e[0].scaleAestheticKey!=="color"?null:n.get(u.getStableKey(t.value))?.label??null}function Ji(e,t,n,r,a){if(t[0].scaleAestheticKey==="color")return a.get(u.getStableKey(e.value))?.valueFormat??r;const o=e.owner?.layer,s=ec(o,n);return o===void 0||s===null?r:ce({layers:[o],scaleType:t[0].scale.spec.scaleType,variableName:s})}function ec(e,t){if(e===void 0)return null;for(const n of t){const r=e.mapping[n];if(r===void 0)continue;const a=u.extractVariableName(r);if(a!==null)return a}return null}function tc(e,t,n){if(e>1)return!1;const r=n.type==="polar";return Je(t,["line","area","bar"])||r}function nc(e,t,n,r){if(e!=="auto")return e;if(r.type==="polar")return"top";const a=Je(n,["line","area"]),o=Je(n,["bar"]),s=Je(n,["bar"],c=>O(c.position)),i=t>=Bi;return a&&o?"top":a?i?"right":"top":s?Aa(r)?"top":i?"right":"top":"top"}function rc(e,t){if(e.length!==1)return!1;const n=e[0];return n?t.getDirectLabelPositions(n.geom).includes(n.position):!1}function ac(e,t,n,r,a){if(!(t==="right"&&!Aa(r)))return"pill";switch(e){case"pill":return"pill";case"direct":return"direct";case"auto":return rc(n,a)?"direct":"pill"}}function Aa(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Je(e,t,n){return e.some(r=>t.includes(r.geom)&&(n?.(r)??!0))}function oc(e){const t=e.scale.domain.map(u.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function sc(e,t){return Jt(t)?"discrete":`continuous:${e}`}function ic(e){const t=e[0];if(!t)return new Map;const n=new Map;return t.data.groupBy(u.GROUP_VARIABLES.group).forEach(r=>{const a=r.findLast(l=>u.isDefined($(l))||u.isDefined(z(l)));if(!a)return;const o=be(a);if(!u.isDefined(o))return;const s=se(a),i=$(a)??z(a);if(!u.isDefined(i))return;const c=u.isDefined(s)?(s+i)/2:i;n.set(String(o),c)}),n}class cc extends j{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[t.scales,t.config.axes,t.config.legend,t.config.headline,t.config.panel,t.layers,t.coordSystem,t.originalData]}run(t){const n=ti(t.originalData),r=wi({scales:t.scales,layers:t.layers,coordSystem:t.coordSystem,valueLabels:ni(t.originalData,t.layers,n)}),a={scales:t.scales,config:t.config,layers:t.layers,coordSystem:t.coordSystem,variableLabels:n,colorGroups:r,geomCompiler:this.geomCompiler},o=ki(a),s=lc(o,Gi(a));return{axes:yi(a,s),legends:s,headline:o,panel:{border:{isVisible:t.config.panel.border.isVisible}},colorGroups:r}}}const lc=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],ht=e=>e[u.IDENTITY_VARIABLES.key],uc=e=>u.getStableKey([be(e)]),en=(e,t)=>{const n=t!==null?e[t]??null:null;return u.getStableKey([n])},F=(e,t)=>{const n=u.extractConstantValue(t);if(n!==void 0)return()=>n;const r=u.extractVariableName(t);return u.isDefined(r)?a=>{const o=a[r];if(o===void 0)return null;switch(e.getType(r)){case"numeric":return I(o)?o:null;case"categorical":return Pe(o)?o:null;case"temporal":return R(o)?o:null;default:return null}}:()=>null},tn=(e,t)=>F(e,t.x),va=(e,t)=>F(e,t.y),dc=(e,t)=>F(e,t.label),Ta=(e,t)=>F(e,t.color),mc=(e,t)=>F(e,t.size),pc=(e,t)=>F(e,t.alpha),fc=(e,t)=>F(e,t.group),hc=(e,t)=>F(e,t.strokeWidth),Zn={variable:u.POSITION_VARIABLES.yRaw};function $e(e,t){return O(e)?Zn:t.y??Zn}function nn(e){return F(e.data,$e(e.position,e.mapping))}const yc=["lt","lte","gt","gte","range"];function et(e,t){if("and"in e){const n=e.and.map(r=>et(r,t));return r=>{for(const a of n)if(!a(r))return!1;return!0}}if("or"in e){const n=e.or.map(r=>et(r,t));return r=>{for(const a of n)if(a(r))return!0;return!1}}if("not"in e){const n=et(e.not,t);return r=>!n(r)}return gc(e,t)}function tt(e,t){if("and"in e){for(const r of e.and)tt(r,t);return}if("or"in e){for(const r of e.or)tt(r,t);return}if("not"in e){tt(e.not,t);return}const n=bc(e);if(n!==null&&t.hasVariable(e.variable)&&t.getType(e.variable)==="categorical")throw new Error(`Highlight predicate uses ordering operator '${n}' on categorical variable '${e.variable}'. Use 'eq' or 'oneOf' instead.`)}const Jn=()=>!1;function gc(e,t){if(!t.hasVariable(e.variable))return Jn;const n=t.getType(e.variable);if("eq"in e){const r=X(e.eq,n,t.parsingLocale);return a=>er(t.readValue(a,e.variable),r)}if("oneOf"in e){const r=e.oneOf.map(a=>X(a,n,t.parsingLocale));return a=>{const o=t.readValue(a,e.variable);for(const s of r)if(er(o,s))return!0;return!1}}if("lt"in e){const r=X(e.lt,n,t.parsingLocale);return a=>me(t.readValue(a,e.variable),r)==="less"}if("lte"in e){const r=X(e.lte,n,t.parsingLocale);return a=>{const o=me(t.readValue(a,e.variable),r);return o==="less"||o==="equal"}}if("gt"in e){const r=X(e.gt,n,t.parsingLocale);return a=>me(t.readValue(a,e.variable),r)==="greater"}if("gte"in e){const r=X(e.gte,n,t.parsingLocale);return a=>{const o=me(t.readValue(a,e.variable),r);return o==="greater"||o==="equal"}}if("range"in e){const[r,a]=e.range,o=X(r,n,t.parsingLocale),s=X(a,n,t.parsingLocale);return i=>{const c=t.readValue(i,e.variable),l=me(c,o),d=me(c,s);return l==="incomparable"||d==="incomparable"?!1:(l==="greater"||l==="equal")&&(d==="less"||d==="equal")}}return Jn}function bc(e){for(const t of yc)if(t in e)return t;return null}function me(e,t){if(e===null||t===null)return"incomparable";if(R(e)&&R(t)){const n=e.getTime(),r=t.getTime();return n<r?"less":n>r?"greater":"equal"}return I(e)&&I(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}function er(e,t){return e===t?!0:R(e)&&R(t)?e.getTime()===t.getTime():!1}function X(e,t,n){return t!=="temporal"||!Pe(e)?e:jt(e,void 0,n)}function Ia(e){return e===null?null:{strategy:e,composition:wa()}}function wa(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}class Sc extends Se{dependencies(t){return[t.highlights,t.config.parsingLocale]}compileLayer(t,n){const r=t.highlight;if(r===null)return t;const a=n.highlights.filter(({layerId:s})=>s===void 0||s===t.id);if(a.length===0)return t;const o=xc({layer:t,highlights:a,parsingLocale:n.config.parsingLocale,strategy:r.strategy});return{...t,highlight:{...r,composition:o}}}}function xc({layer:e,highlights:t,parsingLocale:n,strategy:r}){for(const A of t)tt(A.predicate,e.data);const a=u.extractVariableName(e.mapping.x),o=Ac(e,n),s=t.map(A=>({predicate:et(A.predicate,o),scope:A.scope})),i=s.some(({scope:A})=>A==="series"),c=s.some(({scope:A})=>A==="x-value"),l=r==="overlay-anchor",d=e.data.size(),m=i?new Array(d):null,p=c?new Array(d):null,f=l?new Array(d):null,h=new Uint8Array(d),y=new Set,g=new Set;let S=!1,b=0;for(const A of e.data){let K,Z;m!==null&&(K=uc(A),m[b]=K),p!==null&&(Z=en(A,a),p[b]=Z),f!==null&&(f[b]=A);for(const{predicate:Ke,scope:He}of s)if(Ke(A))switch(He){case"series":K!==void 0&&y.add(K);break;case"x-value":Z!==void 0&&g.add(Z);break;case"data-point":h[b]=1,S=!0;break}b++}if(y.size===0&&g.size===0&&!S)return wa();const x=new Uint8Array(d),T=[];let L=0;for(let A=0;A<d;A++){const K=m?.[A],Z=p?.[A],Ke=K!==void 0&&y.has(K),He=Z!==void 0&&g.has(Z),Pn=h[A]===1;if(r==="observation-rerender")(Ke||Pn||He)&&(x[A]=1,L++);else if(Ke)x[A]=1,L++;else if(Pn||He){const Bn=f?.[A];Bn!==void 0&&T.push({observation:Bn,observationIndex:A})}}const P=L>0?{...e,data:e.data.filterByMask(x)}:null;return{isDimmed:(r==="observation-rerender"||y.size>0)&&P!==null,matchedLayer:P,overlayCandidates:T}}function Ac(e,t){const n=u.extractVariableName(e.mapping.y),r=nn(e);return{hasVariable:a=>e.data.hasVariable(a),getType:a=>e.data.getType(a),readValue:(a,o)=>n!==null&&o===n?r(a):a[o]??null,parsingLocale:t}}const vc=["x","y","color","size","alpha","strokeWidth","lineType","label"],Va=(e,t,n,r=[])=>{const a=[];for(const o of vc){const s=wc(o,t,n);s===null||!e.hasVariable(s.valueVariable)||!e.hasVariable(s.formatVariable)||a.push({aesthetic:o,variable:s.valueVariable,valueFormat:e.getValueFormat(s.formatVariable)})}return{encodings:a,detailRows:Ic(e,r)}},Tc=e=>t=>({key:ht(t),encodings:e.encodings.map(({aesthetic:n,variable:r,valueFormat:a})=>({aesthetic:n,value:t[r]??null,valueFormat:a}))});function Ic(e,t){const n=[];for(const r of t)e.hasVariable(r.variable)&&n.push({label:r.label,variable:r.variable,valueFormat:e.getValueFormat(r.variable)});return n}function wc(e,t,n){if(e==="y"){const a=u.extractVariableName($e(n,t));return a===null?null:{valueVariable:a,formatVariable:u.extractVariableName(t.y)??a}}const r=u.extractVariableName(t[e]);return r===null?null:{valueVariable:r,formatVariable:r}}const Vc=Object.values(u.POSITION_VARIABLES);function tr(e){const t=new u.Dataset({});return{id:e.id,data:t,geom:e.geom,mapping:{},position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},highlight:null,semanticMap:Va(t,{},e.position),spatialMap:{kind:"noop"},swatchShape:"square",failed:!0}}function Lc(e,t){let n;try{n=t()}catch{return tr(e)}return Ec(n)?n:tr(e)}function Ec(e){for(const t of Vc)if(e.data.hasVariable(t)&&e.data.getType(t)==="numeric"){for(const n of e.data.getValues(t,{type:"numeric"}))if(n!==null&&!Number.isFinite(n))return!1}return!0}const Mc=e=>e.kind==="index"?(t,n)=>String(n):t=>u.getStableKey(e.variables.map(n=>t[n])),Dc=(e,t)=>{if(e==="index")return{kind:"index"};const n=u.extractVariableName(t.x);return{kind:"fields",variables:n===null?[u.GROUP_VARIABLES.group]:[n,u.GROUP_VARIABLES.group]}},kc=(e,t,n)=>{const r=Mc(Dc(t,n));return e.deriveVariable(u.IDENTITY_VARIABLES.key,"categorical",r)};class Rc extends Se{constructor(t,n,r,a,o){super(),this.transformCompiler=t,this.statCompiler=n,this.groupCompiler=r,this.geomCompiler=a,this.positionAdjusterCompiler=o}dependencies(t){return[t.data,t.mapping,nr(t)]}compileLayer(t,n){return Lc(t,()=>{const r=this.transformCompiler.compile({data:n.data,transforms:t.transforms}),a={...n.mapping,...t.mapping};return this.runLayerPipeline(t,r,a,nr(n))})}runLayerPipeline(t,n,r,a){const o=ut({data:n,mapping:r}).pipe(({data:c,mapping:l})=>{const d=this.statCompiler.compute(t.stat,{data:c,mapping:l,xScaleIsDiscrete:a});return{data:d.data,mapping:{...l,...d.mapping}}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>{const d=this.geomCompiler.compile(t.geom,{data:c,mapping:l,params:t.params});return{data:d.data,mapping:{...l,...d.mapping},tooltipRows:d.tooltipRows??[]}}).pipe(({data:c,mapping:l})=>{const d=this.geomCompiler.getPositionChannels(t.geom),m=this.positionAdjusterCompiler.adjust(t.position,d,{data:c,mapping:l});return{data:m.data,mapping:{...l,...m.mapping}}}).pipe(({data:c,mapping:l})=>({data:kc(c,this.geomCompiler.getIdentityKeyStrategy(t.geom),l),mapping:l})).result(),{tooltipRows:s,...i}=o;return{...i,id:t.id,geom:t.geom,position:t.position,yScaleType:t.yScaleType,params:t.params,interactive:t.interactive,dataLabels:t.dataLabels,summary:{},highlight:Ia(this.geomCompiler.getHighlightStrategy(t.geom)),semanticMap:Va(i.data,i.mapping,t.position,s),spatialMap:{kind:this.geomCompiler.getSpatialKind(t.geom)},swatchShape:this.geomCompiler.getSwatchShape(t.geom),failed:!1}}}function nr(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}class La extends Error{constructor(t){const n=t.map(r=>`- ${r.message}`).join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./geom.utils-DbZj1kY1.cjs"),v=require("date-fns"),le=require("lodash-es"),Ve=require("d3-time"),Vo=require("date-fns/differenceInDays"),q=require("d3-scale"),Fr=require("lodash-es/merge"),J=require("d3-regression"),Lo=require("humanize-duration"),Eo=require("d3-delaunay");typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="0.0.1-plugins.3");function Fe(e,t){return Pr(e,t)}function xt(e,t){for(const n of Object.keys(t)){const r=t[n];if(r!==void 0&&r!==e[n])return{...e,...t}}return e}function Pr(e,t){let n=!1;const r={...e};for(const[a,o]of Object.entries(t)){const s=e[a];if(u.isPlainObject(o)&&u.isPlainObject(s)){const i=Pr(s,o);i!==s&&(r[a]=i,n=!0)}else o!==void 0&&o!==s&&(r[a]=o,n=!0)}return n?r:e}const ne=process.env.NODE_ENV!=="production";function ut(e){return{pipe:t=>{const n=t(e);return ut({...e,...n})},result:()=>e}}let dt=!0;const Mo=e=>{dt=e},Do=()=>dt,ko=()=>{let e=null;const t={hits:0,misses:0};return Object.assign((r,a)=>{if(!dt)return ne&&(t.misses+=1),a();if(e&&Gr(e.args,r))return ne&&(t.hits+=1),e.out;ne&&(t.misses+=1);const o=a();return e={args:r,out:o},o},{stats:t,reset:()=>{e=null}})},Br=()=>{const e=new WeakMap,t={hits:0,misses:0};return Object.assign((r,a,o)=>{if(!dt)return ne&&(t.misses+=1),o();const s=e.get(r);if(s){for(const c of s)if(Gr(c.args,a))return ne&&(t.hits+=1),c.out}ne&&(t.misses+=1);const i=o();return s?s.push({args:a,out:i}):e.set(r,[{args:a,out:i}]),i},{stats:t})},Ro=(...e)=>e.reduce((t,n)=>({hits:t.hits+n.hits,misses:t.misses+n.misses}),{hits:0,misses:0}),Gr=(e,t)=>{if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(e[n]!==t[n])return!1;return!0};class j{constructor(){this.memo=Br(),this.singletonKey={}}get stats(){return this.memo.stats}compile(t){return this.memo(this.key(t),this.dependencies(t),()=>this.run(t))}key(t){return this.singletonKey}}const be=e=>e[u.GROUP_VARIABLES.group],Co=e=>{const{coordinate:t,coordSystem:n}=e;return"observation"in t?_o(e):n.type!=="cartesian"?null:"unit"in t?{x:t.unit.x,y:t.unit.y,mode:"unit"}:No(t.data,e)},_o=({coordinate:e,layers:t,coordSystem:n,geomCompiler:r})=>{if(!("observation"in e))return null;const a=e.observation;for(const o of t){if(a.layerId!==void 0&&o.id!==a.layerId)continue;const s=u.extractVariableName(o.mapping.x);if(s!==null)for(const i of o.data){if(i[s]!==a.anchorValue||be(i)!==a.groupValue)continue;const c=r.resolveAnchorPosition(o.geom,i,n);if(c!==null)return{x:c.x,y:1-c.y,mode:"observation",observation:i}}}return null},No=(e,{coordSystem:t,scales:n})=>{const r=Gn(n,"x"),a=Gn(n,"y");if(r===null||a===null)return null;const o=r.map(e.x),s=a.map(e.y);if(!Number.isFinite(o)||!Number.isFinite(s))return null;const i=t.type==="cartesian"&&t.mainAxis==="y";return{x:i?s:o,y:1-(i?o:s),mode:"data"}},Gn=(e,t)=>{const n=e[t];return n!==void 0&&n.kind==="position"?n:null},R=e=>e instanceof Date&&v.isValid(e),Oo=e=>R(e)||e===null,Pe=e=>typeof e=="string",I=e=>typeof e=="number"&&!Number.isNaN(e)&&Number.isFinite(e);function zt(e){return e[u.VISUAL_VARIABLES.color]}function Fo(e){return e[u.VISUAL_VARIABLES.alpha]}function Ur(e){return e[u.VISUAL_VARIABLES.size]}function Po(e){return e[u.VISUAL_VARIABLES.strokeWidth]}function $r(e){return e[u.VISUAL_VARIABLES.lineType]??"solid"}const Gt=(e,t,n,r)=>{for(const a of t){if(e.layerId!==void 0&&a.id!==e.layerId)continue;const o=u.extractVariableName(a.mapping.x);if(o===null)continue;const s=u.extractVariableName(a.mapping.y);for(const i of a.data){if(i[o]!==e.anchorValue||be(i)!==e.groupValue)continue;const c=r.resolveAnchorPosition(a.geom,i,n);if(c===null)continue;const l=s!==null?i[s]??null:null;if(I(l))return{...c,measurementValue:l,color:zt(i)}}}return null};class Bo extends j{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[t.annotations,t.layers,t.coordSystem,t.scales.x,t.scales.y]}run(t){const{geomCompiler:n}=this;return{differenceArrows:Uo(t,n),shapes:t.annotations.shapes,freeformArrows:t.annotations.freeformArrows,textAnnotations:t.annotations.textAnnotations,stickers:At(t.annotations.stickers,t.layers,t.coordSystem,n),pinnedNumbers:At(t.annotations.pinnedNumbers,t.layers,t.coordSystem,n),comments:At(t.annotations.comments,t.layers,t.coordSystem,n),custom:Go(t,n)}}}const Go=({annotations:e,layers:t,coordSystem:n,scales:r},a)=>{const o=[];for(const s of e.custom){const i=[];let c=!1;for(const l of s.coordinates){const d=Co({coordinate:l,layers:t,coordSystem:n,scales:r,geomCompiler:a});if(d===null){c=!0;break}i.push(d)}c||o.push({id:s.id,type:s.type,params:s.params,zOrder:s.zOrder,targets:i})}return o},At=(e,t,n,r)=>{const a=[];for(const o of e){const s=Gt(o.anchor,t,n,r);s!==null&&a.push({...o,anchor:s})}return a},Uo=({annotations:e,layers:t,coordSystem:n},r)=>{if(n.type!=="cartesian")return[];const a=[];for(const o of e.differenceArrows){if($o(o.start,o.end))continue;const s=Gt(o.start,t,n,r),i=Gt(o.end,t,n,r);s===null||i===null||a.push({id:o.id,start:s,end:i,color:Yo(o,s,i),size:o.size,label:o.label,labelCrossPosition:o.labelCrossPosition})}return a},$o=(e,t)=>e.layerId===t.layerId&&e.anchorValue===t.anchorValue&&e.groupValue===t.groupValue,Yo=(e,t,n)=>e.color!==null?e.color:e.start.groupValue!==e.end.groupValue||t.color===void 0||t.color!==n.color?null:t.color;function Ko(e,t){const n=zo(t);return{...e,background:Ho(e.background,n),border:Wo(e.border,n)}}function Ho(e,t){if(e.type==="tinted"){const n=e.color??t;if(!n)throw new Error("could not resolve color for tinted background");return{type:"tinted",color:n}}return e}function Wo(e,t){if(e.type==="tinted"||e.type==="gradient"){const n=e.color??t;if(!n)throw new Error(`could not resolve color for ${e.type} background`);return{...e,color:n}}return e}function zo(e){const t=e.color,n=t?.domain[0];if(!n)return;const r=t.map(n);if(typeof r=="string")return r}class Xo extends j{dependencies(t){return[t.scales,t.config]}run(t){const{scales:n,config:r}=t;return{...r,appearance:Ko(r.appearance,n)}}}class qo extends j{dependencies(t){return[t.data,t.mapping]}run(t){let n=t.data,r=t.mapping;r.x===""&&(n=n.addConstantVariable(u.CONSTANT_VARIABLES.x,"categorical",""),r={...r,x:u.CONSTANT_VARIABLES.x});for(const a of Object.keys(r)){const o=u.extractConstantValue(r[a]);if(o===void 0)continue;const s=u.prefixInternalVariable(`const_${a}`);n=n.addConstantVariable(s,jo(o),o),r={...r,[a]:s}}return{data:n,mapping:r}}}const jo=e=>typeof e=="number"?"numeric":e instanceof Date?"temporal":"categorical";class Se{constructor(){this.perLayerMemo=Br(),this.listMemo=ko()}get stats(){return Ro(this.perLayerMemo.stats,this.listMemo.stats)}compile(t){const n=this.dependencies(t),r=t.layers.map(a=>this.perLayerMemo(a,n,()=>this.compileLayer(a,t)));return this.listMemo(r,()=>r)}}class Qo extends j{constructor(t){super(),this.registry=t}dependencies(t){return[t.coordSpec,t.scales,t.layers]}run(t){return this.registry.get(t.coordSpec.coordType).setup(t)}}class Zo extends Se{constructor(t){super(),this.registry=t}dependencies(t){return[t.coordSpec]}compileLayer(t,n){const r=this.registry.get(n.coordSpec.coordType),[a]=r.transform({coordSpec:n.coordSpec,layers:[t]});if(!a)throw new Error(`CoordCompiler: strategy '${n.coordSpec.coordType}' did not return a transformed layer`);return a}}class Jo{constructor(t){this.setupStage=new Qo(t),this.transformStage=new Zo(t)}get setupStats(){return this.setupStage.stats}get transformStats(){return this.transformStage.stats}setup(t){return this.setupStage.compile(t)}transform(t){return this.transformStage.compile(t)}}class xe{constructor(t){this.label=t,this.items=new Map}register(t,n){return this.items.set(t,n),this}get(t){if(!this.items.has(t)){const n=[...this.items.keys()].map(r=>`'${r}'`).join(", ");throw new Error(`Unknown ${this.label}: '${t}' (available: ${n})`)}return this.items.get(t)}getAll(){return[...this.items.values()]}has(t){return this.items.has(t)}}class es{constructor(){this.coordType="cartesian"}setup(t){if(t.coordSpec.coordType!=="cartesian")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{coordSystem:{type:"cartesian",mainAxis:"x",axisMapping:{x:{position:"bottom",geometry:"linear"},y:{position:"right",geometry:"linear"}}},scales:t.scales}}transform(t){return t.layers}}class ts{constructor(t){this.geomRegistry=t,this.coordType="flip"}setup(t){if(t.coordSpec.coordType!=="flip")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);return{coordSystem:{type:"cartesian",mainAxis:"y",axisMapping:{x:{position:"right",geometry:"linear"},y:{position:"bottom",geometry:"linear"}}},scales:ns(t.scales,t.layers)}}transform(t){return t.layers.map(n=>{const r=this.geomRegistry.get(n.geom),a=u.derivePositionColumnPairs(r.positionChannels);return as(n,a)})}}const Un=u.prefixInternalVariable("flipSwap"),ns=(e,t)=>rs(t)?e.map(n=>n.scaledAesthetic!=="x"||n.scaleType!=="continuous"&&n.scaleType!=="datetime"&&n.scaleType!=="discrete"?n:{...n,reverse:!n.reverse}):e,rs=e=>{for(const t of e){const n=u.extractVariableName(t.mapping.x);if(!n||!t.data.hasVariable(n))continue;const r=t.data.getType(n);if(r==="categorical"||r==="temporal")return!0}return!1},as=(e,t)=>{let n=e.data;for(const[r,a]of t){const o=n.hasVariable(r),s=n.hasVariable(a);o&&s?n=n.renameVariable(r,Un).renameVariable(a,r).renameVariable(Un,a):o?n=n.renameVariable(r,a):s&&(n=n.renameVariable(a,r))}return{...e,data:n}};class os{constructor(t){this.geomRegistry=t,this.coordType="polar"}setup(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec;return{coordSystem:{type:"polar",axisMapping:n.theta==="x"?{x:{position:"bottom",geometry:"circular"},y:{position:"left",geometry:"radial"}}:{x:{position:"left",geometry:"radial"},y:{position:"bottom",geometry:"circular"}},innerRadius:n.innerRadius,startAngle:n.startAngle*(Math.PI/180)},scales:t.scales}}transform(t){if(t.coordSpec.coordType!=="polar")throw new Error(`Invalid coordinate type: ${t.coordSpec.coordType}`);const{params:n}=t.coordSpec,r=ss(n),a=is(n);return t.layers.map(o=>{const s=this.geomRegistry.get(o.geom),i=u.derivePositionColumnPairs(s.positionChannels),c=n.theta==="y"?ls(o,i):o,l=cs(c,i,r,a),d=s.spatialKind==="points"?"polar-points":"arcs";return{...l,spatialMap:{kind:d}}})}}function ss(e){const t=e.startAngle*(Math.PI/180);return n=>n*2*Math.PI+t}function is(e){const{innerRadius:t}=e;return n=>t+n*(1-t)}function cs(e,t,n,r){let a=e.data;for(const[o,s]of t)a=$n(a,o,n),a=$n(a,s,r);return{...e,data:a}}function $n(e,t,n){if(!e.hasVariable(t))return e;const a=e.getValues(t,{type:"numeric"}).map(o=>o===null?null:n(o));return e.addVariable(t,"numeric",a)}function ls(e,t){let n=e.data;for(const[r,a]of t){const o=n.hasVariable(r),s=n.hasVariable(a);if(!o&&!s)continue;const i=o?n.getValues(r):null,c=s?n.getValues(a):null;i&&(n=n.addVariable(a,"numeric",i)),c&&(n=n.addVariable(r,"numeric",c))}return{...e,data:n}}class us extends xe{constructor(t){super("coord"),this.register("cartesian",new es),this.register("flip",new ts(t)),this.register("polar",new os(t))}}class Yr{constructor(){this.currentYear=new Date().getUTCFullYear(),this.previousDate=null,this.previousYear=null}incrementYearIfNeeded(t){this.previousYear===null?this.previousYear=t.getUTCFullYear():this.previousDate!==null&&v.isBefore(new Date(this.currentYear,t.getUTCMonth(),t.getUTCDate()),new Date(this.currentYear,this.previousDate.getUTCMonth(),this.previousDate.getUTCDate()))&&this.previousYear++;const n=new Date(t.getTime());return n.setUTCFullYear(this.previousYear),this.previousDate=n,n}}const Kr=e=>{const t=Object.entries(e);return!t.length||!t.some(([,n])=>!Be(n))},Be=e=>typeof e=="string"&&e.trim()===""||e===void 0||e===null||e==="-",mt="en-GB",ds=e=>e.type==="lookup",ms=e=>e.type==="text",Ge=e=>e.type==="date"||e.type==="datetime"||e.type==="year"||e.type==="month_year"||e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range"||e.type==="weekly_date_range_with_year"||e.type==="quarter"||e.type==="time",Hr=e=>e.type==="decimal"||e.type==="integer"||e.type==="percentage"||e.type==="duration"||e.type==="currency",Wr=e=>e.type==="currency",zr=e=>e.type==="month"||e.type==="day_month"||e.type==="weekly_date_range",Xr=e=>{if(ds(e))return Xr(e.fallback);if(Ge(e))return"temporal";if(Hr(e))return"numeric";if(ms(e))return"categorical";const t=e;throw new Error(`No data type found for value format: ${t.type}`)},Re={k:1e3,m:1e6,b:1e9,t:1e12},Xt=["k","m","b","t"],ps=new RegExp(`^-?(\\d{1,3}(,\\d{3})*|\\d+)\\.?\\d*(${Xt.join("|")})?$`,"i"),fs=/^-?\d{1,3}(?:,\d{3})*(?:\.\d+)?%?$/,oe=e=>e===null||e instanceof Date||Array.isArray(e)||typeof e=="boolean"?!1:typeof e=="string"?ps.test(e)&&!Number.isNaN(Number(e.replace(new RegExp(`[,${Xt.join("")}]`,"gi"),""))):!Number.isNaN(Number(e)),qr=e=>oe(e)?!0:typeof e=="string"?fs.test(e):!1,hs=/^\d{4}-\d{2}-\d{2}(T|\s)\d{1,2}:\d{2}(:\d{2}(\.\d{3})?)?(Z|\+00:00)?$/,ys=/^\s*(19\d{2}|2[01]\d{2})\s*$/,gs=[[/\bJan\b/i,"January"],[/\bFeb\b/i,"February"],[/\bMar\b/i,"March"],[/\bApr\b/i,"April"],[/\bJun\b/i,"June"],[/\bJul\b/i,"July"],[/\bAug\b/i,"August"],[/\bSept?\b/i,"September"],[/\bOct\b/i,"October"],[/\bNov\b/i,"November"],[/\bDec\b/i,"December"]],bs={"en-US":"MDY","en-GB":"DMY","pt-PT":"DMY",ar:"DMY"},jr=["/","-","."," "],Yn=[["d","M","yy"],["d","MM","yy"],["d","MMMM","yy"],["dd","M","yy"],["dd","MM","yy"],["dd","MMMM","yy"],["do","MMMM","yy"],["d","M","yyyy"],["d","MM","yyyy"],["d","MMMM","yyyy"],["dd","M","yyyy"],["dd","MM","yyyy"],["dd","MMMM","yyyy"],["do","MMMM","yyyy"]],Kn=[["M","d","yy"],["M","dd","yy"],["MM","d","yy"],["MM","dd","yy"],["MMMM","d","yy"],["MMMM","dd","yy"],["MMMM","do","yy"],["M","d","yyyy"],["M","dd","yyyy"],["MM","d","yyyy"],["MM","dd","yyyy"],["MMMM","d","yyyy"],["MMMM","dd","yyyy"],["MMMM","do","yyyy"]],Hn=[["yyyy","M","d"],["yyyy","M","dd"],["yyyy","MM","d"],["yyyy","MM","dd"],["yyyy","MMMM","d"],["yyyy","MMMM","dd"],["yyyy","MMMM","do"]],Qr=[["d","MMMM"],["dd","MMMM"],["do","MMMM"],["MMMM","d"],["MMMM","dd"],["MMMM","do"]],Ss=[{dateFormat:"MMMM d, yyyy",type:"date"},{dateFormat:"MMMM dd, yyyy",type:"date"},{dateFormat:"MMMM do, yyyy",type:"date"},{dateFormat:"yyyy-MM",type:"month_year"}],Zr=1900,Jr=2199,xs=3,As=6,vs=5,Ts=1,Is=28,ws=/\s*[–—]\s*|\s-\s/,Vs=e=>typeof e=="number"?Number.isNaN(e)?!1:e>=Zr&&e<=Jr:typeof e=="string"?ys.test(e):!1,ea=(e,t)=>{const n=Ce(e);return oe(n)?Ms(n):typeof n=="string"?!!ta(n)||qt(n)&&v.isValid(new Date(n)):v.isValid(n)},Ce=e=>{if(typeof e!="string")return e;let t=e;for(const[n,r]of gs)t=t.replace(n,r);return t},ta=(e,t=mt)=>{const n=Ce(e);return qt(n)?{type:"datetime"}:na(t).find(r=>!Ge(r)||r.type==="month"&&n.length<xs?!1:r.dateFormat&&v.isValid(v.parse(n,r.dateFormat,new Date)))},qt=e=>hs.test(e.trim()),Ls=(e,t=mt)=>{const[n,r]=e.split(ws);if(!n||!r)return;const a=Ce(n).trim(),o=Ce(r).trim();return Es(t).find(s=>{if(!Ge(s)||!s.dateFormat)return!1;const i=v.parse(a,s.dateFormat,new Date),c=v.parse(o,s.dateFormat,new Date);if(!v.isValid(i)||!v.isValid(c))return!1;const l=new Yr,d=l.incrementYearIfNeeded(i),m=l.incrementYearIfNeeded(c),p=v.differenceInDays(m,d);return v.isWithinInterval(new Date(d.getFullYear(),Ts,Is),{start:d,end:m})&&p===vs?!0:p===As})},na=e=>{const t={date:ra(e),year:[["yyyy"]],day_month:Qr,month_year:[["MMMM","yyyy"],["yyyy","MMMM"]],month:[["MMMM"]],quarter:[["QQQ","yyyy"],["yyyy","QQQ"]]};return[...Ss,...Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>jr.map(o=>({dateFormat:a.join(o),type:n}))))]},ra=e=>bs[e]==="MDY"?[...Kn,...Yn,...Hn]:[...Yn,...Kn,...Hn],Es=e=>{const t={weekly_date_range:Qr,weekly_date_range_with_year:ra(e)};return Object.entries(t).flatMap(([n,r])=>r.flatMap(a=>jr.map(o=>({dateFormat:a.join(o),type:n}))))},Ms=e=>{const t=Number(e);if(!le.isInteger(t))return!1;const n=new Date(t),r=new Date(t*1e3),a=o=>v.isValid(o)&&o.getFullYear()>=Zr&&o.getFullYear()<=Jr;return a(n)||a(r)},aa={$:"usd","£":"gbp","€":"eur","¥":"jpy","₹":"inr","₱":"php",P:"php","₩":"krw","₪":"ils","₫":"vnd","₽":"rub","฿":"thb",R$:"brl",Rp:"idr",RM:"myr","₦":"ngn",zł:"pln","₺":"try",kr:"dkk",Fr:"chf",R:"zar","د.إ":"aed","﷼":"sar",Ch$:"clp",NT$:"twd",HK$:"hkd",S$:"sgd",A$:"aud",C$:"cad",NZ$:"nzd",MX$:"mxn"},oa=e=>{if(typeof e=="string"){const t=sa(e);return t.length?oe(t):!1}return oe(e)},Ds=e=>{const t=ia(e),n=t?aa[t]:void 0;if(!n)throw new Error("Could not get currency ISO");return n},sa=e=>{const t=ia(e);let n=e;if(t){const r=e.indexOf(t);r===0?n=e.slice(t.length):r===e.length-t.length?n=e.slice(0,e.length-t.length):e[0]==="-"&&r===1&&(n=`-${e.slice(t.length+1)}`)}return oe(n)?n.split(",").join(""):""},ia=e=>Object.keys(aa).sort((n,r)=>r.length-n.length).find(n=>e.includes(n)),ks=(e,t)=>{const n=typeof e=="string"?e.trim():e;if(oe(n))return{type:"decimal"};const r=typeof n=="string"&&ta(n,t);if(r)return r;const a=typeof n=="string"&&Ls(n,t);return a||(ea(e)?{type:"date"}:qr(e)?{type:"percentage"}:oa(e)&&typeof e=="string"?{type:"currency",iso:Ds(e)}:{type:"text"})},Rs=/\s*[–—]\s*|\s-\s/,Cs=(e,t,n)=>{if(Be(e))return null;switch(t.type){case"decimal":case"integer":case"duration":return ca(e);case"percentage":return _s(e);case"currency":return Ns(e);case"datetime":case"date":case"year":case"month_year":case"month":case"day_month":case"quarter":case"time":return jt(e,t.dateFormat,n);case"weekly_date_range":case"weekly_date_range_with_year":return Os(e,t.dateFormat,n);case"text":return Fs(e);case"lookup":throw new Error("Cannot parse: lookup value formats are produced by transforms, not raw input");default:{const r=t;throw new Error(`Unhandled value format: ${r.type}`)}}},jt=(e,t,n)=>{if(e instanceof Date)return v.isValid(e)?e:null;const r=Ce(String(e).trim());if(r.length===0)return null;const a=new Date;if(t){const s=v.parse(r,t,a);return v.isValid(s)?vt(s):null}for(const s of na(n)){if(!Ge(s)||!s.dateFormat)continue;const i=v.parse(r,s.dateFormat,a);if(v.isValid(i))return vt(i)}const o=new Date(r);return ea(o)?qt(r)?o:vt(o):null},ca=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;let t=e.trim();if(!oe(t))return null;let n=1;for(const r of Xt)if(new RegExp(`${r}$`,"i").test(t)){n=Re[r],t=t.slice(0,-1);break}return Number(t.split(",").join(""))*n},_s=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();if(!qr(t))return null;const n=Number(t.replace(/%/g,"").replace(/,/g,""))/100;return Number.isNaN(n)?null:n},Ns=e=>{if(typeof e=="number")return Number.isNaN(e)?null:e;if(typeof e!="string")return null;const t=e.trim();return oa(t)?ca(sa(t)):null},Os=(e,t,n)=>{const r=String(e).trim().split(Rs),[a,o]=[r[0]?.trim(),r[1]?.trim()];return!a||!o?null:jt(a,t,n)},Fs=e=>String(e).trim(),vt=e=>new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds())),Ps={type:"year",dateFormat:"yyyy"};class Bs extends j{dependencies(t){return[t]}run(t){const n=t._metadata?.parsingLocale??mt,r={},a=$s(t),o=Gs(t);for(const[s,i]of t.columns.entries()){if(i._metadata?.isHidden)continue;const c=a.get(i.key);if(Be(c))continue;const l=s===o?Ps:ks(c,n),d=Xr(l);r[i.key]=Us(i.key,t.rows,l,d,n)}return new u.Dataset(r)}}const Gs=e=>{const t=Ys(e.rows,5);return e.columns.findIndex(n=>{const r=t.map(a=>a[n.key]).filter(a=>!Be(a));return r.length>=2&&r.every(Vs)})},Us=(e,t,n,r,a)=>{const o=new Yr,s=t.reduce((i,c)=>{if(Kr(c))return i;const l=Cs(c[e],n,a);return zr(n)&&R(l)?i.push(o.incrementYearIfNeeded(l)):i.push(l),i},[]);return{type:r,values:s,valueFormat:n}},$s=e=>{const t=new Map,n=new Set(e.columns.map(r=>r.key));for(const r of e.rows){for(const a of n){const o=r[a];Be(o)||(t.set(a,o),n.delete(a))}if(n.size===0)break}return t},Ys=(e,t)=>{const n=[];for(const r of e)if(Kr(r)||n.push(r),n.length===t)return n;return n};class Ks{constructor(t){this.registry=t}compile(t,n){return this.registry.get(t).compile(n)}getPositionChannels(t){return this.registry.get(t).positionChannels}getSwatchShape(t){return this.registry.get(t).swatchShape}getSpatialKind(t){return this.registry.get(t).spatialKind}getVisualAesthetics(t){return this.registry.get(t).visualAesthetics}getHighlightStrategy(t){return this.registry.get(t).highlightStrategy}getDirectLabelPositions(t){return this.registry.get(t).directLabelPositions}getGridPolicies(t){return this.registry.get(t).gridPolicies}getIdentityKeyStrategy(t){return this.registry.get(t).identityKeyStrategy}emitsGrandTotal(t){return this.registry.get(t).emitsGrandTotal}emitsStackTotals(t){return this.registry.get(t).emitsStackTotals}supportsPerGroupHeadline(t){return this.registry.get(t).supportsPerGroupHeadline}resolveAnchorPosition(t,n,r){return this.registry.get(t).resolveAnchorPosition(n,r)}}class Hs extends u.Geom{constructor(){super(...arguments),this.type="area",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"y",role:"lower",valueKind:"value"},{axis:"y",role:"upper",valueKind:"value"}],this.swatchShape="area",this.highlightStrategy="overlay-anchor",this.spatialKind="buckets",this.directLabelPositions=["identity","stack","dodge","fill"],this.supportsPerGroupHeadline=!0}compile({data:t,mapping:n}){if(t=u.sortByXIfContinuous(t,n),t.hasVariable(u.POSITION_VARIABLES.yMin)||(t=t.addConstantVariable(u.POSITION_VARIABLES.yMin,"numeric",0)),!t.hasVariable(u.POSITION_VARIABLES.yMax)){const r=u.extractVariableName(n.y);u.isDefined(r)&&t.hasVariable(r)&&(t=t.addVariable(u.POSITION_VARIABLES.yMax,"numeric",t.getValues(r,{type:"numeric"})))}return{data:t,mapping:{}}}}const la=.7,Ws=.1;function Ae(e){return e[u.POSITION_VARIABLES.x]}function z(e){return e[u.POSITION_VARIABLES.y]}function _e(e){return e[u.POSITION_VARIABLES.xMin]}function ye(e){return e[u.POSITION_VARIABLES.xMax]}function se(e){return e[u.POSITION_VARIABLES.yMin]}function $(e){return e[u.POSITION_VARIABLES.yMax]}function ua(e){return e[u.POSITION_VARIABLES.yRaw]}class zs extends u.Geom{constructor(){super(...arguments),this.type="bar",this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"},{axis:"x",role:"lower",valueKind:"bandOffset"},{axis:"x",role:"upper",valueKind:"bandOffset"},{axis:"y",role:"lower",valueKind:"value"},{axis:"y",role:"upper",valueKind:"value"}],this.swatchShape="square",this.highlightStrategy="observation-rerender",this.spatialKind="rects",this.directLabelPositions=["stack","fill"],this.gridPolicies={cartesian:{hideGridX:!0},flip:{hideGridX:!0},polar:{hideGridX:!0,hideGridY:!0}},this.emitsGrandTotal=!0,this.emitsStackTotals=!0,this.supportsPerGroupHeadline=!0}compile({data:t,mapping:n}){if(t=u.sortByXIfContinuous(t,n),t.hasVariable(u.POSITION_VARIABLES.yMin)||(t=t.addConstantVariable(u.POSITION_VARIABLES.yMin,"numeric",0)),!t.hasVariable(u.POSITION_VARIABLES.yMax)){const a=u.extractVariableName(n.y);u.isDefined(a)&&t.hasVariable(a)&&(t=t.addVariable(u.POSITION_VARIABLES.yMax,"numeric",t.getValues(a,{type:"numeric"})))}const r=la/2;return t=t.addConstantVariable(u.POSITION_VARIABLES.xMin,"numeric",-r).addConstantVariable(u.POSITION_VARIABLES.xMax,"numeric",r),{data:t,mapping:{}}}resolveAnchorPosition(t,n){if(n.type==="polar"){const s=_e(t),i=ye(t),c=se(t),l=$(t);if(s===null||i===null||c===null||l===null)return null;const d=(s+i)/2,m=(c+l)/2;return{x:.5+.5*m*Math.sin(d),y:.5-.5*m*Math.cos(d),geom:"polar-bar"}}if(n.mainAxis==="x"){const s=_e(t),i=ye(t),c=$(t)??z(t);return s===null||i===null||c===null?null:{x:(s+i)/2,y:c,geom:"bar"}}const r=se(t),a=$(t),o=ye(t)??Ae(t);return r===null||a===null||o===null?null:{x:o,y:(r+a)/2,geom:"bar"}}}class Xs extends u.Geom{constructor(){super(...arguments),this.type="line",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.swatchShape="line",this.highlightStrategy="overlay-anchor",this.spatialKind="buckets",this.directLabelPositions=["identity","stack","dodge","fill"],this.supportsPerGroupHeadline=!0}compile(t){return{data:u.sortByXIfContinuous(t.data,t.mapping),mapping:{}}}resolveAnchorPosition(t,n){if(n.type==="polar")return null;const r=Ae(t),a=z(t);return r===null||a===null?null:{x:r,y:a,geom:"line"}}}class qs extends u.Geom{constructor(){super(...arguments),this.type="point",this.requiredAesthetics=["x","y"],this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.swatchShape="circle",this.highlightStrategy="overlay-anchor",this.spatialKind="points",this.identityKeyStrategy="index",this.supportsPerGroupHeadline=!0}compile({data:t}){return{data:t,mapping:{}}}}class js extends u.Geom{constructor(){super(...arguments),this.type="rule",this.positionChannels=[{axis:"x",role:"point",valueKind:"value"},{axis:"y",role:"point",valueKind:"value"}],this.highlightStrategy=null,this.supportedCoordTypes=["cartesian","flip"]}compile({data:t,mapping:n}){const r=Wn(n.y,t);if(r!==null)return{data:new u.Dataset({[u.RULE_VARIABLES.y]:{type:"numeric",values:[r.value],valueFormat:r.sourceFormat}}),mapping:{y:u.RULE_VARIABLES.y,x:void 0}};const a=Wn(n.x,t);return a!==null?{data:new u.Dataset({[u.RULE_VARIABLES.x]:{type:"numeric",values:[a.value],valueFormat:a.sourceFormat}}),mapping:{x:u.RULE_VARIABLES.x,y:void 0}}:{data:new u.Dataset,mapping:{x:void 0,y:void 0}}}validateMapping({layerId:t,mapping:n,computedVariables:r}){const a=r.has("x")||I(u.extractConstantValue(n.x)),o=r.has("y")||I(u.extractConstantValue(n.y));return a&&o?[{code:"INVALID_RULE_MAPPING",message:`Layer '${t}': rule geom requires exactly one of 'x' or 'y', both were provided`,layerId:t}]:!a&&!o?[{code:"INVALID_RULE_MAPPING",message:`Layer '${t}': rule geom requires a numeric value on 'x' or 'y'`,layerId:t}]:[]}}const Wn=(e,t)=>{const n=u.extractConstantValue(e);if(I(n))return{value:n,sourceFormat:void 0};const r=u.extractVariableName(e);if(r===null||!u.isStatVariable(r)||!t.hasVariable(r))return null;const[a]=t.getValues(r);return I(a)?{value:a,sourceFormat:t.getValueFormat(r)}:null};class Qs extends xe{constructor(t){super("geom"),this.register("bar",new zs),this.register("point",new qs),this.register("line",new Xs),this.register("area",new Hs),this.register("rule",new js);for(const n of t?.geoms??[])this.register(n.type,n)}}const Qt=(e,t)=>{if(u.isDefined(t.group)){const a=u.extractVariableName(t.group);if(a!==null)return[a]}const n=new Set([u.extractVariableName(t.x),u.extractVariableName(t.y)].filter(u.isDefined)),r=new Set;for(const a in t){if(a==="x"||a==="y")continue;const o=u.extractVariableName(t[a]);u.isDefined(o)&&(n.has(o)||e.getType(o)==="categorical"&&r.add(o))}return[...r]};class Zs{compute({data:t,mapping:n}){const r=Qt(t,n);if(r.length===0)return{data:t.addConstantVariable(u.GROUP_VARIABLES.group,"categorical",null)};const a=t.size(),o=r.map(i=>t.getValues(i)),s=new Array(a);for(let i=0;i<a;i++)s[i]=u.getStableKey(o.map(c=>c[i]));return{data:t.addVariable(u.GROUP_VARIABLES.group,"categorical",s)}}}const da=new Set(["x","y","ySecondary"]),pt=new Set(["color","size","alpha","strokeWidth","lineType"]),ft=e=>da.has(e),Js=e=>pt.has(e),ei=e=>ft(e)||Js(e);function Ue(e){return e==="secondary"?"ySecondary":"y"}function Y(e){return e==="ySecondary"?"y":e}const ti=e=>{if(e===void 0)return{};const t={};for(const n of e.columns)n.label!==void 0&&(t[n.key]=n.label);return t},ni=(e,t,n)=>{const r=ie(t,"color");return r===null?{}:(e?.columns??[]).some(s=>s.key===r)?{}:n};function ie(e,t){const n=Y(t);for(const r of ma(t,e)){const a=u.extractVariableName(r.mapping[n]);if(u.isDefined(a))return a}return null}const Zt=(e,t)=>e===null?null:t[e]??e,ri=(e,t)=>e===null?null:t[String(e)]??null,ce=({layers:e,scaleType:t,variableName:n})=>{if(n===null)return Tt(t);for(const r of e){if(!r.data.hasVariable(n))continue;const a=r.data.getValueFormat(n),o=a.type==="lookup"?a.fallback:a;return oi(o,t)?o:Tt(t)}return Tt(t)},ai=(e,t)=>t!=="y"&&t!=="ySecondary"?!1:ma(t,e).some(n=>n.position==="fill");function ma(e,t){return e==="ySecondary"?t.filter(n=>n.yScaleType==="secondary"):e==="y"?t.filter(n=>n.yScaleType==="primary"):t}const Tt=e=>{switch(e){case"continuous":return{type:"decimal"};case"datetime":return{type:"date"};case"discrete":case"palette":case"identity":return{type:"text"}}},oi=(e,t)=>{switch(t){case"continuous":return Hr(e);case"datetime":return Ge(e);case"discrete":case"palette":case"identity":return!0}},si=[{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}],zn={year:0,quarter:1,month:2,week:3,day:4,hour:5},de=40,ii=(e,t,n)=>{const r=n.unit==="quarter"?n.step*3:n.step;return di(n.unit).range(e,new Date(t.valueOf()+1),r)},ci=({unit:e,step:t,start:n,stop:r})=>{const a=Vo.differenceInDays(r,n);switch(e){case"hour":return 24*a/t>de;case"day":return a/t>de;case"week":return a/(7*t)>de;case"month":return a/(30*t)>de;case"quarter":return a/(90*t)>de;case"year":return a/(365*t)>de}},li=(e,t)=>{const n=!zr(t);switch(e.unit){case"year":return n?{type:"year"}:{type:"month"};case"quarter":return{type:"quarter"};case"month":return n?{type:"month_year"}:{type:"month"};case"week":return n?{type:"weekly_date_range_with_year"}:{type:"weekly_date_range"};case"day":return n?{type:"date"}:{type:"day_month"};case"hour":return n?{type:"datetime"}:{type:"time"}}},ui=(e,t)=>{const n=mi(t);return n===null?!1:zn[e]>zn[n]},di=e=>{switch(e){case"hour":return Ve.utcHour;case"day":return Ve.utcDay;case"week":return Ve.utcMonday;case"month":case"quarter":return Ve.utcMonth;case"year":return Ve.utcYear}},mi=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}},pa={left:"right",right:"left",top:"bottom",bottom:"top"},pi={x:!0,y:!0,ySecondary:!1},fi=20,Xn=new Set(["top","bottom"]),hi={type:"percentage"};function yi(e,t){const{scales:n,config:r,layers:a,coordSystem:o,variableLabels:s,geomCompiler:i}=e;if(o.type==="polar"&&o.axisMapping.x.geometry!=="circular")return[];const c=bi(a,o.type,r,i),l=new Set(t.map(p=>p.position)),d=xi(fa(r.axes.y.position,o.axisMapping.y.position),l),m=[];for(const p of da){const f=n[p];if(!u.isDefined(f)||f.kind!=="position")continue;const h=gi({scaleAestheticKey:p,scale:f,config:r,layers:a,axisMapping:o.axisMapping,resolvedYPosition:d,gridOverrides:c,variableLabels:s});m.push(h)}return m}function gi(e){const{scaleAestheticKey:t,scale:n,config:r,layers:a,axisMapping:o,resolvedYPosition:s,gridOverrides:i,variableLabels:c}=e,l=Y(t),{axisConfig:d,position:m}=Si(t,r,o,s),p=ie(a,t),f=ai(a,t)?hi:ce({layers:a,scaleType:n.spec.scaleType,variableName:p}),h=Zt(p,c);return{scaleAestheticKey:t,aesthetic:l,position:m,geometry:o[t==="x"?"x":"y"].geometry,label:d.label??h,isVisible:d.isVisible,tickCandidates:vi(n,f),valueFormat:f,tickMode:d.ticks.mode,ticksVisible:d.ticks.isVisible,gridVisible:Ai(d,i,t),scaleType:n.spec.scaleType,bandwidth:n.bandwidth??void 0}}function bi(e,t,n,r){const a=e.flatMap(c=>{const l=r.getGridPolicies(c.geom)[t];return l?[l]:[]}),o=a.some(c=>c.hideGridX),s=a.some(c=>c.hideGridY),i=a.some(c=>c.hideBorder);return{x:{gridVisible:qn(o,n.axes.x.grid.isVisible)},y:{gridVisible:qn(s,n.axes.y.grid.isVisible)},borderVisible:i?!1:void 0}}function qn(e,t){if(e&&t===null)return!1}function Si(e,t,n,r){switch(e){case"x":return{axisConfig:t.axes[e],position:fa(t.axes[e].position,n[e].position)};case"y":return{axisConfig:t.axes[e],position:r};case"ySecondary":{const a=pa[r],o=le.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:o,position:o.position}}}}function fa(e,t){return Xn.has(e)===Xn.has(t)?e:t}function xi(e,t){return t.has(e)?pa[e]:e}function Ai(e,t,n){const{gridVisible:r}=n==="x"?t.x:t.y;return r??e.grid.isVisible??pi[n]}const vi=(e,t)=>{if(e.spec.scaleType==="continuous"){const r=new Set,a=[];for(let o=1;o<=fi;o++){const s=e.generateTicks({count:o}),i=u.getStableKey(s);r.has(i)||(r.add(i),a.push({ticks:s.map(c=>st(e,c))}))}return a}return e.spec.scaleType==="datetime"?Ti(e,t):[{ticks:e.generateTicks().map(r=>st(e,r))}]},Ti=(e,t)=>{const[n,r]=e.domain;if(!R(n)||!R(r))return[{ticks:e.generateTicks().map(c=>st(e,c))}];const a=new Set,o=[],s=(i,c)=>{if(i.length===0)return;const l=u.getStableKey(i);a.has(l)||(a.add(l),o.push({ticks:i.map(d=>st(e,d)),valueFormat:c}))};for(const i of si)ci({...i,start:n,stop:r})||ui(i.unit,t)||s(e.generateTicks({interval:i}),li(i,t));return s(e.generateTicks({atInputs:!0})),o.sort((i,c)=>i.ticks.length-c.ticks.length),o},st=(e,t)=>({value:t,position:e.map(t)});function Ne(e,t){return t.type==="polar"&&e==="square"?"slice":e}function ha({scale:e,aesthetics:t,layers:n,coordSystem:r}){const a=Ii({layers:n,coordSystem:r,aesthetics:t}),o=ya({layers:n,aesthetics:t});return e.domain.map(s=>({value:s,swatchShape:a(s),owner:o(s)}))}function Ii({layers:e,coordSystem:t,aesthetics:n}){const r=ya({layers:e,aesthetics:n}),a=e.find(s=>n.some(i=>u.isDefined(s.mapping[i]))),o=a?Ne(a.swatchShape,t):"square";return s=>{const i=r(s);return i?Ne(i.layer.swatchShape,t):o}}function ya({layers:e,aesthetics:t,layerFilter:n}){const r=new Map;for(const[a,o]of e.entries()){if(n&&!n(o))continue;const s=t.find(c=>u.isDefined(o.mapping[c]));if(s===void 0)continue;const i=u.extractVariableName(o.mapping[s]);if(!(i===null||!o.data.hasVariable(i)))for(const c of o.data.getValues(i,{distinct:!0})){const l=u.getStableKey(c);r.has(l)||r.set(l,{layer:o,layerIndex:a})}}return a=>r.get(u.getStableKey(a))}const Jt=e=>{if(e.kind==="identity")return!1;const t=e.spec.scaleType;return t!=="continuous"&&t!=="datetime"};function wi({scales:e,layers:t,coordSystem:n,valueLabels:r}){const a=e.color;if(a===void 0||!Jt(a))return[];if(!t.some(d=>u.isDefined(d.mapping.color)))return[];const o=ie(t,"color");if(ga({colorVariableName:o,xVariableName:ie(t,"x"),mapsColorAcrossMultipleLayers:Li(t)>1,isMergedWithAnotherAesthetic:Vi(e,t,o)}))return[];const i=a.spec.scaleType,c=t.findIndex(d=>u.isDefined(d.mapping.color));return ha({scale:a,aesthetics:["color"],layers:t,coordSystem:n}).map(({value:d,swatchShape:m,owner:p})=>{const f=p?.layerIndex??c,h=t[f],y=h?u.extractVariableName(h.mapping.color):null;return{value:d,color:String(a.map(d)),shape:m,layerIndex:f,valueFormat:ce({layers:h?[h]:t,scaleType:i,variableName:y}),label:ri(d,r)}})}const ga=({colorVariableName:e,xVariableName:t,mapsColorAcrossMultipleLayers:n,isMergedWithAnotherAesthetic:r})=>r?!1:e===null||u.isInternalVariable(e)?!n:t!==null&&e===t;function Vi(e,t,n){if(n===null)return!1;for(const r of pt){if(r==="color")continue;const a=e[r];if(!(a===void 0||!Jt(a))&&ie(t,r)===n)return!0}return!1}const Li=e=>e.filter(t=>u.isDefined(t.mapping.color)).length;function Ei(e,t,n,r){const a=t.findIndex(o=>r.supportsPerGroupHeadline(o.geom));if(a===-1)return[];if(e.length<2){const o=u.extractVariableName(t[a]?.mapping.y);return[{value:null,swatch:null,layerIndex:a,groupLabelFormat:{type:"text"},label:Zt(o,n)}]}return e.map(o=>({value:o.value,swatch:{color:o.color,shape:o.shape},layerIndex:o.layerIndex,groupLabelFormat:o.valueFormat,label:o.label}))}function jn(e,t,n){if(n===null||t===null)return[...e];const r=u.getStableKey(n);return e.filter((a,o)=>u.getStableKey(t[o]??null)===r)}const Mi=(e,t)=>{switch(t){case"total":{const{sum:n,count:r}=Qn(e);return r===0?null:n}case"average":{const{sum:n,count:r}=Qn(e);return r===0?null:n/r}case"current":return e.at(-1)??null}},Di=(e,t)=>{if(e.length<2)return null;const n=e.at(-1),r=t==="previous"?e.at(-2):e.at(0);return n===void 0||r===void 0||n.cross===null||r.cross===null||r.cross===0?null:{variation:(n.cross-r.cross)/r.cross,against:r.main}},Qn=e=>e.reduce((t,n)=>n===null?t:{sum:t.sum+n,count:t.count+1},{sum:0,count:0});function ki(e){const{config:t,coordSystem:n}=e,r=t.headline.show;return r==="none"||r==="conversion"?null:n.type==="polar"?Ri(e,r):Ci(e,r)}function Ri(e,t){if(t!=="total")return null;const{scales:n,layers:r}=e,a=r.find(c=>c.summary.grandTotal!==void 0);if(a===void 0)return null;const o=a.summary.grandTotal;if(o===void 0)return null;const s=u.extractVariableName(a.mapping.y);if(s===null)return null;const i=ce({layers:[a],scaleType:n.y?.spec.scaleType??"continuous",variableName:s});return{kind:"grandTotal",value:o,valueFormat:i}}function Ci(e,t){const{config:n,scales:r,layers:a,variableLabels:o,colorGroups:s,geomCompiler:i}=e;if(!a.some(d=>i.supportsPerGroupHeadline(d.geom)))return null;const c=Ei(s,a,o,i);if(c.length===0)return null;const l=c.map(d=>_i({group:d,show:t,compareWith:n.headline.compareWith,layers:a,scales:r})).filter(d=>d!==null);return l.length===0?null:{kind:"perGroup",items:l}}function _i({group:e,show:t,compareWith:n,layers:r,scales:a}){const o=r[e.layerIndex];if(o===void 0)return null;const s=u.extractVariableName(o.mapping.y);if(s===null||t==="total"&&o.position==="fill")return null;const i=u.extractVariableName(o.mapping.x),c=u.extractVariableName(o.mapping.color),l=o.yScaleType==="secondary"?a.ySecondary:a.y,d=ce({layers:[o],scaleType:l?.spec.scaleType??"continuous",variableName:s}),m=Fi(o.data,i),p=ce({layers:[o],scaleType:m?"datetime":a.x?.spec.scaleType??"discrete",variableName:i}),f=Pi(o.data,i),h=f.getValues(s,{type:"numeric"}),y=i!==null?f.getValues(i):[],g=c!==null?f.getValues(c):null,S=jn(h,g,e.value),b=jn(y,g,e.value);return{value:e.value,swatch:e.swatch,aggregate:Mi(S,t),valueFormat:d,groupLabelFormat:e.groupLabelFormat,mainValueFormat:p,label:e.label,observationLabel:Ni(t,m,b),comparison:Oi(t,n,m,b,S)}}function Ni(e,t,n){if(e==="current"){const o=n.at(-1);return o===void 0?null:{kind:"point",value:o}}if(!t)return null;const r=n.at(0),a=n.at(-1);return r===void 0||a===void 0?null:{kind:"range",from:r,to:a}}function Oi(e,t,n,r,a){if(e!=="current"||!n)return null;const o=t==="none"?"first":t,s=r.map((i,c)=>({main:i,cross:a[c]??null}));return Di(s,o)}function Fi(e,t){return t!==null&&e.hasVariable(t)&&e.getType(t)==="temporal"}function Pi(e,t){return t===null||!["numeric","temporal"].includes(e.getType(t))?e:e.orderBy(t)}const ba=["point","line","area","bar","rule"],Sa=new Set(ba);function xa(e){return Sa.has(e)}function O(e){return e==="stack"||e==="fill"}const Bi=3;function Gi({scales:e,config:t,layers:n,coordSystem:r,variableLabels:a,colorGroups:o,geomCompiler:s}){if(t.legend.position==="none")return[];const i=new Map(o.map(g=>[u.getStableKey(g.value),g])),c=Yi({scales:e,layers:n,geomCompiler:s}),l=Xi(c),d=ie(n,"x"),m=l.map(g=>{if(Wi(g,d,n))return null;const S=ji({group:g,variableLabels:a,layers:n,coordSystem:r,colorGroupsByValue:i});return S.items.length===0?null:{group:g,built:S}}).filter(u.isDefined);if(m.length===0)return[];const p=Ui(m);if(t.legend.position==="auto"&&tc(p,n,r))return[];const f=nc(t.legend.position,p,n,r),h=ac(t.legend.display,f,n,r,s),y=h==="direct"?ic(n):null;return m.map(({built:g})=>$i(g,f,h,y))}function Ui(e){return e.reduce((t,{group:n,built:r})=>{const a=n.some(o=>o.guideType!=="discrete");return t+(a?1:r.items.length)},0)}function $i(e,t,n,r){return n!=="direct"||r===null?{...e,position:t,display:n}:{...e,position:t,display:n,items:e.items.map(a=>({...a,normalizedY:r.get(String(a.value))??null}))}}function Yi(e){const{scales:t,layers:n,geomCompiler:r}=e,a=Ki(n,r),o=[];for(const s of pt){if(!a.has(s))continue;const i=t[s];if(i===void 0||i.kind==="identity"||!Hi(s,n))continue;const c=ie(n,s),l=sc(s,i);o.push({scaleAestheticKey:s,scale:i,variableName:c,guideType:l})}return o}function Ki(e,t){const n=new Set;for(const r of e)for(const a of t.getVisualAesthetics(r.geom))n.add(a);return n}function Hi(e,t){const n=Y(e);return t.some(r=>u.isDefined(r.mapping[n]))}function Wi(e,t,n){const[r]=e;return r.scaleAestheticKey!=="color"?!1:ga({colorVariableName:r.variableName,xVariableName:t,mapsColorAcrossMultipleLayers:zi(r.scaleAestheticKey,n),isMergedWithAnotherAesthetic:e.length>1})}function zi(e,t){const n=Y(e);return t.filter(r=>u.isDefined(r.mapping[n])).length>1}function Xi(e){const t=new Map;for(const n of e){const r=oc(n),a=t.get(r);a?a.push(n):t.set(r,[n])}return[...t.values()]}function qi(e,t,n){if(t==="lineType"){e.lineType=n;return}if(t==="color"){e.color=String(n);return}e[t]=n}function ji({group:e,variableLabels:t,layers:n,coordSystem:r,colorGroupsByValue:a}){const o=e[0],s=e.map(d=>Y(d.scaleAestheticKey)),i=ha({scale:o.scale,aesthetics:s,layers:n,coordSystem:r}),c=Zt(o.variableName,t),l=ce({layers:n,scaleType:o.scale.spec.scaleType,variableName:o.variableName});return{aesthetics:e.map(d=>d.scaleAestheticKey),title:c,items:i.map(d=>Qi(d,e,s,l,a))}}function Qi(e,t,n,r,a){const o={};for(const i of t)qi(o,i.scaleAestheticKey,i.scale.map(e.value));const s=Ji(e,t,n,r,a);return{value:e.value,label:Zi(t,e,a),visual:o,normalizedY:null,swatchShape:e.swatchShape,valueFormat:s}}function Zi(e,t,n){return e[0].scaleAestheticKey!=="color"?null:n.get(u.getStableKey(t.value))?.label??null}function Ji(e,t,n,r,a){if(t[0].scaleAestheticKey==="color")return a.get(u.getStableKey(e.value))?.valueFormat??r;const o=e.owner?.layer,s=ec(o,n);return o===void 0||s===null?r:ce({layers:[o],scaleType:t[0].scale.spec.scaleType,variableName:s})}function ec(e,t){if(e===void 0)return null;for(const n of t){const r=e.mapping[n];if(r===void 0)continue;const a=u.extractVariableName(r);if(a!==null)return a}return null}function tc(e,t,n){if(e>1)return!1;const r=n.type==="polar";return Je(t,["line","area","bar"])||r}function nc(e,t,n,r){if(e!=="auto")return e;if(r.type==="polar")return"top";const a=Je(n,["line","area"]),o=Je(n,["bar"]),s=Je(n,["bar"],c=>O(c.position)),i=t>=Bi;return a&&o?"top":a?i?"right":"top":s?Aa(r)?"top":i?"right":"top":"top"}function rc(e,t){if(e.length!==1)return!1;const n=e[0];return n?t.getDirectLabelPositions(n.geom).includes(n.position):!1}function ac(e,t,n,r,a){if(!(t==="right"&&!Aa(r)))return"pill";switch(e){case"pill":return"pill";case"direct":return"direct";case"auto":return rc(n,a)?"direct":"pill"}}function Aa(e){return e.type==="cartesian"&&e.mainAxis==="y"}function Je(e,t,n){return e.some(r=>t.includes(r.geom)&&(n?.(r)??!0))}function oc(e){const t=e.scale.domain.map(u.getStableKey);return JSON.stringify([e.variableName,e.guideType,...t])}function sc(e,t){return Jt(t)?"discrete":`continuous:${e}`}function ic(e){const t=e[0];if(!t)return new Map;const n=new Map;return t.data.groupBy(u.GROUP_VARIABLES.group).forEach(r=>{const a=r.findLast(l=>u.isDefined($(l))||u.isDefined(z(l)));if(!a)return;const o=be(a);if(!u.isDefined(o))return;const s=se(a),i=$(a)??z(a);if(!u.isDefined(i))return;const c=u.isDefined(s)?(s+i)/2:i;n.set(String(o),c)}),n}class cc extends j{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[t.scales,t.config.axes,t.config.legend,t.config.headline,t.config.panel,t.layers,t.coordSystem,t.originalData]}run(t){const n=ti(t.originalData),r=wi({scales:t.scales,layers:t.layers,coordSystem:t.coordSystem,valueLabels:ni(t.originalData,t.layers,n)}),a={scales:t.scales,config:t.config,layers:t.layers,coordSystem:t.coordSystem,variableLabels:n,colorGroups:r,geomCompiler:this.geomCompiler},o=ki(a),s=lc(o,Gi(a));return{axes:yi(a,s),legends:s,headline:o,panel:{border:{isVisible:t.config.panel.border.isVisible}},colorGroups:r}}}const lc=(e,t)=>e?.kind!=="perGroup"||t.some(r=>r.display==="direct")?t:[],ht=e=>e[u.IDENTITY_VARIABLES.key],uc=e=>u.getStableKey([be(e)]),en=(e,t)=>{const n=t!==null?e[t]??null:null;return u.getStableKey([n])},F=(e,t)=>{const n=u.extractConstantValue(t);if(n!==void 0)return()=>n;const r=u.extractVariableName(t);return u.isDefined(r)?a=>{const o=a[r];if(o===void 0)return null;switch(e.getType(r)){case"numeric":return I(o)?o:null;case"categorical":return Pe(o)?o:null;case"temporal":return R(o)?o:null;default:return null}}:()=>null},tn=(e,t)=>F(e,t.x),va=(e,t)=>F(e,t.y),dc=(e,t)=>F(e,t.label),Ta=(e,t)=>F(e,t.color),mc=(e,t)=>F(e,t.size),pc=(e,t)=>F(e,t.alpha),fc=(e,t)=>F(e,t.group),hc=(e,t)=>F(e,t.strokeWidth),Zn={variable:u.POSITION_VARIABLES.yRaw};function $e(e,t){return O(e)?Zn:t.y??Zn}function nn(e){return F(e.data,$e(e.position,e.mapping))}const yc=["lt","lte","gt","gte","range"];function et(e,t){if("and"in e){const n=e.and.map(r=>et(r,t));return r=>{for(const a of n)if(!a(r))return!1;return!0}}if("or"in e){const n=e.or.map(r=>et(r,t));return r=>{for(const a of n)if(a(r))return!0;return!1}}if("not"in e){const n=et(e.not,t);return r=>!n(r)}return gc(e,t)}function tt(e,t){if("and"in e){for(const r of e.and)tt(r,t);return}if("or"in e){for(const r of e.or)tt(r,t);return}if("not"in e){tt(e.not,t);return}const n=bc(e);if(n!==null&&t.hasVariable(e.variable)&&t.getType(e.variable)==="categorical")throw new Error(`Highlight predicate uses ordering operator '${n}' on categorical variable '${e.variable}'. Use 'eq' or 'oneOf' instead.`)}const Jn=()=>!1;function gc(e,t){if(!t.hasVariable(e.variable))return Jn;const n=t.getType(e.variable);if("eq"in e){const r=X(e.eq,n,t.parsingLocale);return a=>er(t.readValue(a,e.variable),r)}if("oneOf"in e){const r=e.oneOf.map(a=>X(a,n,t.parsingLocale));return a=>{const o=t.readValue(a,e.variable);for(const s of r)if(er(o,s))return!0;return!1}}if("lt"in e){const r=X(e.lt,n,t.parsingLocale);return a=>me(t.readValue(a,e.variable),r)==="less"}if("lte"in e){const r=X(e.lte,n,t.parsingLocale);return a=>{const o=me(t.readValue(a,e.variable),r);return o==="less"||o==="equal"}}if("gt"in e){const r=X(e.gt,n,t.parsingLocale);return a=>me(t.readValue(a,e.variable),r)==="greater"}if("gte"in e){const r=X(e.gte,n,t.parsingLocale);return a=>{const o=me(t.readValue(a,e.variable),r);return o==="greater"||o==="equal"}}if("range"in e){const[r,a]=e.range,o=X(r,n,t.parsingLocale),s=X(a,n,t.parsingLocale);return i=>{const c=t.readValue(i,e.variable),l=me(c,o),d=me(c,s);return l==="incomparable"||d==="incomparable"?!1:(l==="greater"||l==="equal")&&(d==="less"||d==="equal")}}return Jn}function bc(e){for(const t of yc)if(t in e)return t;return null}function me(e,t){if(e===null||t===null)return"incomparable";if(R(e)&&R(t)){const n=e.getTime(),r=t.getTime();return n<r?"less":n>r?"greater":"equal"}return I(e)&&I(t)?e<t?"less":e>t?"greater":"equal":"incomparable"}function er(e,t){return e===t?!0:R(e)&&R(t)?e.getTime()===t.getTime():!1}function X(e,t,n){return t!=="temporal"||!Pe(e)?e:jt(e,void 0,n)}function Ia(e){return e===null?null:{strategy:e,composition:wa()}}function wa(){return{isDimmed:!1,matchedLayer:null,overlayCandidates:[]}}class Sc extends Se{dependencies(t){return[t.highlights,t.config.parsingLocale]}compileLayer(t,n){const r=t.highlight;if(r===null)return t;const a=n.highlights.filter(({layerId:s})=>s===void 0||s===t.id);if(a.length===0)return t;const o=xc({layer:t,highlights:a,parsingLocale:n.config.parsingLocale,strategy:r.strategy});return{...t,highlight:{...r,composition:o}}}}function xc({layer:e,highlights:t,parsingLocale:n,strategy:r}){for(const A of t)tt(A.predicate,e.data);const a=u.extractVariableName(e.mapping.x),o=Ac(e,n),s=t.map(A=>({predicate:et(A.predicate,o),scope:A.scope})),i=s.some(({scope:A})=>A==="series"),c=s.some(({scope:A})=>A==="x-value"),l=r==="overlay-anchor",d=e.data.size(),m=i?new Array(d):null,p=c?new Array(d):null,f=l?new Array(d):null,h=new Uint8Array(d),y=new Set,g=new Set;let S=!1,b=0;for(const A of e.data){let K,Z;m!==null&&(K=uc(A),m[b]=K),p!==null&&(Z=en(A,a),p[b]=Z),f!==null&&(f[b]=A);for(const{predicate:Ke,scope:He}of s)if(Ke(A))switch(He){case"series":K!==void 0&&y.add(K);break;case"x-value":Z!==void 0&&g.add(Z);break;case"data-point":h[b]=1,S=!0;break}b++}if(y.size===0&&g.size===0&&!S)return wa();const x=new Uint8Array(d),T=[];let L=0;for(let A=0;A<d;A++){const K=m?.[A],Z=p?.[A],Ke=K!==void 0&&y.has(K),He=Z!==void 0&&g.has(Z),Pn=h[A]===1;if(r==="observation-rerender")(Ke||Pn||He)&&(x[A]=1,L++);else if(Ke)x[A]=1,L++;else if(Pn||He){const Bn=f?.[A];Bn!==void 0&&T.push({observation:Bn,observationIndex:A})}}const P=L>0?{...e,data:e.data.filterByMask(x)}:null;return{isDimmed:(r==="observation-rerender"||y.size>0)&&P!==null,matchedLayer:P,overlayCandidates:T}}function Ac(e,t){const n=u.extractVariableName(e.mapping.y),r=nn(e);return{hasVariable:a=>e.data.hasVariable(a),getType:a=>e.data.getType(a),readValue:(a,o)=>n!==null&&o===n?r(a):a[o]??null,parsingLocale:t}}const vc=["x","y","color","size","alpha","strokeWidth","lineType","label"],Va=(e,t,n,r=[])=>{const a=[];for(const o of vc){const s=wc(o,t,n);s===null||!e.hasVariable(s.valueVariable)||!e.hasVariable(s.formatVariable)||a.push({aesthetic:o,variable:s.valueVariable,valueFormat:e.getValueFormat(s.formatVariable)})}return{encodings:a,detailRows:Ic(e,r)}},Tc=e=>t=>({key:ht(t),encodings:e.encodings.map(({aesthetic:n,variable:r,valueFormat:a})=>({aesthetic:n,value:t[r]??null,valueFormat:a}))});function Ic(e,t){const n=[];for(const r of t)e.hasVariable(r.variable)&&n.push({label:r.label,variable:r.variable,valueFormat:e.getValueFormat(r.variable)});return n}function wc(e,t,n){if(e==="y"){const a=u.extractVariableName($e(n,t));return a===null?null:{valueVariable:a,formatVariable:u.extractVariableName(t.y)??a}}const r=u.extractVariableName(t[e]);return r===null?null:{valueVariable:r,formatVariable:r}}const Vc=Object.values(u.POSITION_VARIABLES);function tr(e){const t=new u.Dataset({});return{id:e.id,data:t,geom:e.geom,mapping:{},position:e.position,yScaleType:e.yScaleType,params:e.params,interactive:e.interactive,dataLabels:e.dataLabels,summary:{},highlight:null,semanticMap:Va(t,{},e.position),spatialMap:{kind:"noop"},swatchShape:"square",failed:!0}}function Lc(e,t){let n;try{n=t()}catch{return tr(e)}return Ec(n)?n:tr(e)}function Ec(e){for(const t of Vc)if(e.data.hasVariable(t)&&e.data.getType(t)==="numeric"){for(const n of e.data.getValues(t,{type:"numeric"}))if(n!==null&&!Number.isFinite(n))return!1}return!0}const Mc=e=>e.kind==="index"?(t,n)=>String(n):t=>u.getStableKey(e.variables.map(n=>t[n])),Dc=(e,t)=>{if(e==="index")return{kind:"index"};const n=u.extractVariableName(t.x);return{kind:"fields",variables:n===null?[u.GROUP_VARIABLES.group]:[n,u.GROUP_VARIABLES.group]}},kc=(e,t,n)=>{const r=Mc(Dc(t,n));return e.deriveVariable(u.IDENTITY_VARIABLES.key,"categorical",r)};class Rc extends Se{constructor(t,n,r,a,o){super(),this.transformCompiler=t,this.statCompiler=n,this.groupCompiler=r,this.geomCompiler=a,this.positionAdjusterCompiler=o}dependencies(t){return[t.data,t.mapping,nr(t)]}compileLayer(t,n){return Lc(t,()=>{const r=this.transformCompiler.compile({data:n.data,transforms:t.transforms}),a={...n.mapping,...t.mapping};return this.runLayerPipeline(t,r,a,nr(n))})}runLayerPipeline(t,n,r,a){const o=ut({data:n,mapping:r}).pipe(({data:c,mapping:l})=>{const d=this.statCompiler.compute(t.stat,{data:c,mapping:l,xScaleIsDiscrete:a});return{data:d.data,mapping:{...l,...d.mapping}}}).pipe(({data:c,mapping:l})=>({data:this.groupCompiler.compute({data:c,mapping:l}).data,mapping:l})).pipe(({data:c,mapping:l})=>{const d=this.geomCompiler.compile(t.geom,{data:c,mapping:l,params:t.params});return{data:d.data,mapping:{...l,...d.mapping},tooltipRows:d.tooltipRows??[]}}).pipe(({data:c,mapping:l})=>{const d=this.geomCompiler.getPositionChannels(t.geom),m=this.positionAdjusterCompiler.adjust(t.position,d,{data:c,mapping:l});return{data:m.data,mapping:{...l,...m.mapping}}}).pipe(({data:c,mapping:l})=>({data:kc(c,this.geomCompiler.getIdentityKeyStrategy(t.geom),l),mapping:l})).result(),{tooltipRows:s,...i}=o;return{...i,id:t.id,geom:t.geom,position:t.position,yScaleType:t.yScaleType,params:t.params,interactive:t.interactive,dataLabels:t.dataLabels,summary:{},highlight:Ia(this.geomCompiler.getHighlightStrategy(t.geom)),semanticMap:Va(i.data,i.mapping,t.position,s),spatialMap:{kind:this.geomCompiler.getSpatialKind(t.geom)},swatchShape:this.geomCompiler.getSwatchShape(t.geom),failed:!1}}}function nr(e){return e.scales.some(t=>t.scaledAesthetic==="x"&&t.scaleType==="discrete")}class La extends Error{constructor(t){const n=t.map(r=>`- ${r.message}`).join(`
|
|
2
2
|
`);super(`Spec validation failed:
|
|
3
|
-
${n}`),this.issues=t,this.name="SpecValidationError"}}class Cc{constructor(t,n){this.transformCompiler=t,this.validator=n}check(t){const n=[];for(const r of t.layers){const a=this.transformCompiler.compile({data:t.data,transforms:r.transforms}),o={...t.mapping,...r.mapping};n.push(...this.validator.validate({layerId:r.id,geom:r.geom,stat:r.stat,effectiveMapping:o,data:a,coordType:t.coords.coordType}))}if(n.length>0)throw new La(n)}}class _c{constructor(t,n){this.geomRegistry=t,this.statRegistry=n}validate(t){return[...this.validateRequiredAesthetics(t),...this.validateVariableExistence(t),...this.validateGeomMapping(t),...this.validateCoordSupport(t)]}validateRequiredAesthetics({layerId:t,geom:n,stat:r,effectiveMapping:a}){const o=[],{requiredAesthetics:s}=this.geomRegistry.get(n),{computedVariables:i}=this.statRegistry.get(r.type);for(const c of s)i.has(c)||u.isDefined(u.readAesthetic(a,c))||o.push({code:"MISSING_AESTHETIC",message:`Layer '${t}': geom '${n}' requires aesthetic '${c}'`,layerId:t,aesthetic:c});return o}validateVariableExistence({layerId:t,stat:n,effectiveMapping:r,data:a}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type);for(const[i,c]of Object.entries(r)){if(s.has(i))continue;const l=u.extractVariableName(c);l!==null&&(a.hasVariable(l)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${t}': aesthetic '${i}' references variable '${l}' which does not exist in the dataset`,layerId:t,aesthetic:i}))}return o}validateGeomMapping({layerId:t,geom:n,stat:r,effectiveMapping:a}){const o=this.geomRegistry.get(n);if(o.validateMapping===void 0)return[];const{computedVariables:s}=this.statRegistry.get(r.type);return o.validateMapping({layerId:t,mapping:a,computedVariables:s})}validateCoordSupport({layerId:t,geom:n,coordType:r}){const{supportedCoordTypes:a}=this.geomRegistry.get(n);return a.includes(r)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${t}': geom '${n}' is not supported under '${r}' coords`,layerId:t}]}}const rr=u.prefixInternalVariable("__ungrouped__"),Nc=(e,t)=>t===null?!0:e.some(n=>n.axis===t.axis&&n.role===t.role&&n.valueKind===t.valueKind),Ea=(e,t,n="y")=>{const r=n==="y"?"x":"y",a=u.extractVariableName(t[n]),o=u.extractVariableName(t[r]);if(!a||!o)return null;const s=e.getValues(u.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=s.length===0,c=i?[rr]:s,l=e.getValues(o),d=e.getValues(a,{type:"numeric"}),m=e.getValues(u.GROUP_VARIABLES.group,{type:"categorical"}),p=e.size(),f=new Map;for(let h=0;h<p;h++){const y=l[h]??null,g=m[h],S=i?rr:g;if(!u.isDefined(S))continue;let b=f.get(y);b||(b=new Map,f.set(y,b)),b.set(S,h)}return{values:d,observationIndexByPartitionAndGroup:f,uniqueGroupKeys:c,observationCount:p}};class Oc{constructor(t){this.registry=t}adjust(t,n,r){const a=this.registry.get(t),o=a.getConsumedChannel(r.axis??"y");return Nc(n,o)?a.adjust(r):{data:r.data,mapping:{}}}}class yt{getConsumedChannel(t){return null}}class Fc extends yt{constructor(){super(...arguments),this.type="dodge"}getConsumedChannel(t){return{axis:"x",role:"point",valueKind:"value"}}adjust({data:t,mapping:n}){if(!u.extractVariableName(n.x))return{data:t,mapping:{}};const a=t.getValues(u.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(a.length===0)return{data:t,mapping:{}};const o=t.size(),s=t.getValues(u.GROUP_VARIABLES.group,{type:"categorical"}),i=la/2,c=a.length>1?Ws:0,l=q.scaleBand().domain(a.map(String)).range([-i,i]).paddingInner(c).paddingOuter(0),d=l.bandwidth(),m=new Array(o).fill(null),p=new Array(o).fill(null);for(let h=0;h<o;h++){const y=s[h];if(!u.isDefined(y))continue;const g=l(String(y));u.isDefined(g)&&(m[h]=g,p[h]=g+d)}return{data:t.addVariable(u.POSITION_VARIABLES.xMin,"numeric",m).addVariable(u.POSITION_VARIABLES.xMax,"numeric",p),mapping:{}}}}class Pc extends yt{constructor(){super(...arguments),this.type="fill"}getConsumedChannel(t){return{axis:t,role:"point",valueKind:"value"}}adjust({data:t,mapping:n,axis:r="y"}){const a=Ea(t,n,r);if(a===null)return{data:t,mapping:{}};const{values:o,observationIndexByPartitionAndGroup:s,uniqueGroupKeys:i,observationCount:c}=a,l=[...o],d=new Array(c).fill(0);for(const[,p]of s){let f=0,h=0;for(const S of i){const b=p.get(S);if(b===void 0)continue;const x=o[b];x!=null&&(x>=0?f+=x:h-=x)}let y=0,g=0;for(const S of i){const b=p.get(S);if(b===void 0)continue;const x=o[b];if(x===void 0)continue;if(x===null){d[b]=null,l[b]=null;continue}const T=x>=0?f:h;if(T===0){d[b]=0,l[b]=0;continue}const L=x/T;x>=0?(d[b]=y,l[b]=y+=L):(l[b]=g,d[b]=g+=L)}}let m=t.addVariable(u.variableFor(r,"lower"),"numeric",d).addVariable(u.variableFor(r,"upper"),"numeric",l);return r==="y"&&(m=m.addVariable(u.POSITION_VARIABLES.yRaw,"numeric",o)),{data:m,mapping:{}}}}class Bc extends yt{constructor(){super(...arguments),this.type="identity"}adjust({data:t}){return{data:t,mapping:{}}}}class Gc extends yt{constructor(){super(...arguments),this.type="stack"}getConsumedChannel(t){return{axis:t,role:"point",valueKind:"value"}}adjust({data:t,mapping:n,axis:r="y"}){const a=Ea(t,n,r);if(a===null)return{data:t,mapping:{}};const{values:o,observationIndexByPartitionAndGroup:s,uniqueGroupKeys:i,observationCount:c}=a,l=[...o],d=new Array(c).fill(0);for(const[,f]of s){let h=0,y=0;for(const g of i){const S=f.get(g);if(S===void 0)continue;const b=o[S];if(b!==void 0){if(b===null){d[S]=null,l[S]=null;continue}b>=0?(d[S]=h,l[S]=h+=b):(l[S]=y,d[S]=y+=b)}}}let m=t.addVariable(u.variableFor(r,"lower"),"numeric",d).addVariable(u.variableFor(r,"upper"),"numeric",l);r==="y"&&(m=m.addVariable(u.POSITION_VARIABLES.yRaw,"numeric",o));const p=u.extractVariableName(n[r]);return p!==null&&(m=m.addVariable(p,"numeric",l)),{data:m,mapping:{}}}}class Uc extends xe{constructor(){super("position"),this.register("identity",new Bc),this.register("stack",new Gc),this.register("fill",new Pc),this.register("dodge",new Fc)}}function $c(e){let t=e.data;for(const n of e.channels)n.role==="point"&&(t=Yc(n.axis,t,e));for(const n of Hc(e.channels))t=Wc(n,t,e);for(const n of e.channels)n.role==="scalar"&&(t=Kc(n,t,e));return t}function rn(e,t){return e==="x"?"x":Ue(t)}function Yc(e,t,n){const r=u.extractVariableName(n.mapping[e]),a=n.getPositionScale(rn(e,n.yScaleType));if(!r||!a)return t;const s=t.getValues(r).map(i=>u.isDefined(i)?a.map(i):null);return t.addVariable(u.variableFor(e,"point"),"numeric",s)}function Kc(e,t,n){const r=n.getPositionScale(rn(e.axis,n.yScaleType)),o=(e.aes?u.extractVariableName(u.readAesthetic(n.mapping,e.aes)):null)??u.variableFor(e.axis,e.name);if(!r||!t.hasVariable(o))return t;const i=t.getValues(o,{type:"numeric"}).map(c=>u.isDefined(c)?r.map(c):null);return t.addVariable(u.variableFor(e.axis,e.name),"numeric",i)}function Hc(e){const t=new Map;for(const n of e){if(n.role==="point"||n.role==="scalar")continue;const r=`${n.axis}:${n.valueKind}`,a=t.get(r)??{axis:n.axis,valueKind:n.valueKind,hasLower:!1,hasUpper:!1};n.role==="lower"&&(a.hasLower=!0),n.role==="upper"&&(a.hasUpper=!0),t.set(r,a)}return[...t.values()].filter(n=>n.hasLower&&n.hasUpper).map(({axis:n,valueKind:r})=>({axis:n,valueKind:r}))}function Wc(e,t,n){const r=n.getPositionScale(rn(e.axis,n.yScaleType));if(!r)return t;const a=u.variableFor(e.axis,"lower"),o=u.variableFor(e.axis,"upper");return!t.hasVariable(a)||!t.hasVariable(o)?t:e.valueKind==="value"?zc(t,r,a,o):Xc(e.axis,t,r,a,o)}function zc(e,t,n,r){const a=e.getValues(n,{type:"numeric"}),o=e.getValues(r,{type:"numeric"}),s=e.size(),i=new Array(s),c=new Array(s);for(let l=0;l<s;l++){const d=a[l],m=o[l];u.isDefined(d)&&u.isDefined(m)?(i[l]=t.map(d),c[l]=t.map(m)):(i[l]=null,c[l]=null)}return e.addVariable(n,"numeric",i).addVariable(r,"numeric",c)}function Xc(e,t,n,r,a){const o=u.variableFor(e,"point");if(!n.bandwidth||!t.hasVariable(o))return t;const s=n.bandwidth,i=t.getValues(o,{type:"numeric"}),c=t.getValues(r,{type:"numeric"}),l=t.getValues(a,{type:"numeric"}),d=t.size(),m=new Array(d),p=new Array(d);for(let f=0;f<d;f++){const h=i[f],y=c[f],g=l[f];u.isDefined(h)&&u.isDefined(y)&&u.isDefined(g)?(m[f]=h+y*s,p[f]=h+g*s):(m[f]=null,p[f]=null)}return t.addVariable(r,"numeric",m).addVariable(a,"numeric",p)}function qc(e,t){const n=e[t];return n?.kind==="position"?n:null}class jc extends Se{constructor(t){super(),this.geomRegistry=t}dependencies(t){return[t.scales.x,t.scales.y,t.scales.ySecondary]}compileLayer(t,n){const r=this.geomRegistry.get(t.geom),a=$c({channels:r.positionChannels,data:t.data,mapping:t.mapping,yScaleType:t.yScaleType,getPositionScale:o=>qc(n.scales,o)});return{...t,data:a}}}class Qc extends j{constructor(t){super(),this.registry=t}dependencies(t){return[t.layers,t.scales]}run(t){this.validateScaleTypeCompatibility(t);const n=new Map;for(const o of t.scales)n.set(o.scaledAesthetic,o);const r=this.collectValues(t.layers,n),a={};for(const[o,s]of n){const i=r.get(o)??[],c=this.registry.get(s.scaleType);a[o]=c.compile(s,i)}return a}validateScaleTypeCompatibility(t){const n=[];for(const r of t.scales){const{compatibleDataTypes:a}=this.registry.get(r.scaleType),o=Y(r.scaledAesthetic),s=t.layers.find(l=>u.isDefined(l.mapping[o]));if(!s)continue;const i=u.extractVariableName(s.mapping[o]);if(!u.isDefined(i)||!s.data.hasVariable(i))continue;const c=s.data.getType(i);if(a.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${i}' (${c})`,aesthetic:o}),r.scaledAesthetic==="lineType"&&c!=="categorical"){const l=c==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";n.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${i}'. ${l}`,aesthetic:o})}}if(n.length>0)throw new La(n)}collectValues(t,n){const r=new Map;for(const a of t)for(const[o,s]of Object.entries(a.mapping)){const i=o,c=i==="y"?Ue(a.yScaleType):i;if(!ei(c)||!n.has(c))continue;const l=this.resolveVariables(i,s,a.data);this.collectFromVariables(a.data,l,c,r)}return r}resolveVariables(t,n,r){if(t==="y"&&this.hasPositionAdjustedY(r))return[u.POSITION_VARIABLES.yMin,u.POSITION_VARIABLES.yMax];const a=u.extractVariableName(n);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(t){return t.hasVariable(u.POSITION_VARIABLES.yMin)&&t.hasVariable(u.POSITION_VARIABLES.yMax)}collectFromVariables(t,n,r,a){if(n.length===0)return;let o=[];for(const i of n)o=o.concat(t.getValues(i));const s=a.get(r);a.set(r,s?s.concat(o):o)}}class Ye{createPositionScale(t,n){return{kind:"position",aesthetic:Y(t.scaledAesthetic),spec:t,...n}}createVisualScale(t,n){return{kind:"visual",aesthetic:Y(t.scaledAesthetic),spec:t,...n}}}class Zc extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(t,n){if(t.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){let r=1/0,a=-1/0;for(const o of t)typeof o=="number"&&(o<r&&(r=o),o>a&&(a=o));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),a<0&&(a=0)),[r,a])}createD3Scale(t,n,r){let a=[r.domainMin??t[0],r.domainMax??t[1]];const o=r.transform==="log"&&Jc(a),s=o?q.scaleLog():r.transform==="sqrt"?q.scaleSqrt():q.scaleLinear();return r.nice&&!o&&(a=s.copy().domain(a).nice().domain()),s.domain([r.domainMin??a[0],r.domainMax??a[1]]).range(n).clamp(r.clamp)}buildPositionScale(t,n){const r=n.reverse?[1,0]:[0,1],a=this.createD3Scale(t,r,n);return this.createPositionScale(n,{map:a,domain:a.domain(),bandwidth:null,generateTicks:o=>o&&"count"in o?a.ticks(o.count):a.ticks()})}buildVisualScale(t,n){const r=n.range??[0,1],a=n.reverse?[r[1],r[0]]:r,o=this.createD3Scale(t,a,n);return this.createVisualScale(n,{map:o,domain:o.domain(),generateTicks:s=>s&&"count"in s?o.ticks(s.count):o.ticks()})}}const Jc=e=>{const[t,n]=e;return t>0&&n>0||t<0&&n<0};class el extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(t,n){if(t.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n);if(!r)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(a,t,this.collectInputDates(n))}collectInputDates(t){const n=new Set,r=[];for(const a of t){if(!(a instanceof Date))continue;const o=a.getTime();n.has(o)||(n.add(o),r.push(a))}return r.sort((a,o)=>a.getTime()-o.getTime()),r}computeDataDomain(t){let n=1/0,r=-1/0;for(const a of t){if(!(a instanceof Date))continue;const o=a.getTime();o<n&&(n=o),o>r&&(r=o)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(t,n,r){const a=tl(t)?t:[],o=q.scaleUtc().domain(a).range(n).clamp(r.clamp);if(r.nice&&o.nice(),u.isDefined(r.domainMin)||u.isDefined(r.domainMax)){const[s,i]=o.domain();s!==void 0&&i!==void 0&&o.domain([r.domainMin??s,r.domainMax??i])}return o}buildScale(t,n,r){const a=n.reverse?[1,0]:[0,1],o=this.createD3Scale(t,a,n),[s,i]=o.domain(),c=s&&i?r.filter(l=>l>=s&&l<=i):[];return this.createPositionScale(n,{map:o,domain:o.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?s&&i?ii(s,i,l.interval):[]:o.ticks(l?.count)})}}const tl=e=>e.length===2&&R(e[0])&&R(e[1]),pe={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},ar={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},We={domainMin:null,domainMax:null,nice:!1,reverse:!1},De={range:null,domain:null,padding:.1,reverse:!1},nl={palette:{type:"default"}};class rl extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(t,n){if(t.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){if(n.domain!==null&&n.domain.length>0)return[...n.domain];const r=new Set,a=[];for(const o of t)r.has(o)||(r.add(o),a.push(o));return a}buildPositionScale(t,n){const r=t.map(String),a=n.padding??De.padding,o=n.reverse?[1,0]:[0,1],s=q.scaleBand().domain(r).range(o).paddingInner(a).paddingOuter(a/2),i=s.bandwidth()/2;return this.createPositionScale(n,{map:c=>(s(String(c))??0)+i,domain:t,bandwidth:s.bandwidth(),generateTicks:()=>[...t]})}buildVisualScale(t,n){const r=t.map(String),a=n.range&&n.range.length>0?q.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:o=>{const s=String(o);return a?a(s):s},domain:t,generateTicks:()=>t})}}class al extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(t){if(t.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:Y(t.scaledAesthetic),spec:t,map:n=>n,domain:[],generateTicks:()=>[]}}}const Ma=["grey","red","orange","yellow","green","cyan","blue","purple","pink"],Da=["cyan","pink","purple","red","orange","yellow","green","blue"],an=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],B={red:"#E83562",orange:"#F38650",yellow:"#FBBC30",green:"#31FCB4",cyan:"#40F8FF",blue:"#279EFF",purple:"#B399FD",dark_purple:"#6D48D2",plum:"#C82184",pink:"#FC8497"},ol=[B.purple,B.pink,B.yellow,B.blue,B.red,B.cyan,B.orange,B.plum,B.green,B.dark_purple],N={green:"#B2DDC9",cyan:"#A2D5E2",blue:"#AAC4FF",purple:"#B2A4FF",plum:"#DCA8C7",pink:"#FFCCD3",red:"#FFADAD",orange:"#FFDEB4",yellow:"#FDF7C3"},sl=[N.green,N.purple,N.red,N.cyan,N.pink,N.blue,N.orange,N.plum,N.yellow],Ut={grey900:"#1c1917",grey800:"#292524",grey700:"#44403c",grey600:"#57534e",grey500:"#78716c",grey400:"#a8a29e",grey300:"#d6d3d1",grey200:"#e7e5e4",grey100:"#f5f5f4",grey50:"#fafaf9",red900:"#7f1d1d",red800:"#991b1b",red700:"#b91c1c",red600:"#dc2626",red500:"#ef4444",red400:"#f87171",red300:"#fca5a5",red200:"#fecaca",red100:"#fee2e2",red50:"#fef2f2",orange900:"#7c2d12",orange800:"#9a3412",orange700:"#c2410c",orange600:"#ea580c",orange500:"#f97316",orange400:"#fb923c",orange300:"#fdba74",orange200:"#fed7aa",orange100:"#ffedd5",orange50:"#fff7ed",yellow900:"#553B0C",yellow800:"#6F4B08",yellow700:"#8D6300",yellow600:"#BD8A00",yellow500:"#E5B400",yellow400:"#FFC800",yellow300:"#FBDA2B",yellow200:"#FEED72",yellow100:"#FEF8B4",yellow50:"#FEFCE2",green900:"#064e3b",green800:"#065f46",green700:"#047857",green600:"#059669",green500:"#10b981",green400:"#34d399",green300:"#6ee7b7",green200:"#a7f3d0",green100:"#d1fae5",green50:"#ecfdf5",cyan900:"#164e63",cyan800:"#155e75",cyan700:"#0e7490",cyan600:"#0891B2",cyan500:"#06b6d4",cyan400:"#22d3ee",cyan300:"#67e8f9",cyan200:"#a5f3fc",cyan100:"#cffafe",cyan50:"#ecfeff",blue900:"#1e3a8a",blue800:"#1e40af",blue700:"#1d4ed8",blue600:"#2563eb",blue500:"#3b82f6",blue400:"#60a5fa",blue300:"#93c5fd",blue200:"#bfdbfe",blue100:"#dbeafe",blue50:"#eff6ff",purple900:"#4c1d95",purple800:"#5b21b6",purple700:"#6d28d9",purple600:"#7c3aed",purple500:"#8b5cf6",purple400:"#a78bfa",purple300:"#c4b5fd",purple200:"#ddd6fe",purple100:"#ede9fe",purple50:"#f5f3ff",pink900:"#751A5E",pink800:"#8F1972",pink700:"#AF1C8A",pink600:"#D326A8",pink500:"#E845BF",pink400:"#F979D9",pink300:"#FCABE8",pink200:"#FED0F3",pink100:"#FFE8F9",pink50:"#FFF4FC"},il=[Ut.grey200,N.green,N.red,Ut.grey200],or={dark:{1:[500],2:[600,400],3:[600,400,200],4:[600,500,300,100],5:[700,600,400,200,50],6:[600,500,400,300,200,100],7:[600,500,400,300,200,100,50],default:[700,600,500,400,300,200,100,50]},light:{1:[600],2:[700,500],3:[800,600,400],4:[800,600,400,300],5:[800,700,600,500,400],6:[800,700,600,500,400,300],7:[900,800,700,600,500,400,300],default:[900,800,700,600,500,400,300,200]}},C={cyan:"#22D3EE",pink:"#F377EF",purple:"#6528F7",red:"#FB2576",orange:"#FF9300",yellow:"#FBFF00",green:"#06FF00",blue:"#0079FF"},ze=[C.cyan,C.pink,C.purple,C.red,C.orange,C.yellow,C.green,C.blue],cl=[C.cyan,C.green,C.red,C.cyan],Xe={start:"#84D1FC",positive:"#84FC89",negative:"#FC8497",total:"#84D1FC"},ll=[Xe.start,Xe.positive,Xe.negative,Xe.total];function ul(e,t="light",n){return((n!==void 0?or[t][n]:void 0)??or[t].default).map(a=>Ut[`${e}${a}`])}function dl(e){const t=ze.indexOf(C[e]);return t<=0?ze:[...ze.slice(t),...ze.slice(0,t)]}function ml(e,t){switch(e.type){case"default":return an;case"graphy":return e.variant==="waterfall"?ll:ol;case"pastel":return e.variant==="waterfall"?il:sl;case"neon":return e.variant==="waterfall"?cl:dl(e.base);case"mono":return ul(e.base,e.variant??"light",t);case"custom":return e.colors}}function pl(e,t){if(!e)return nl.palette;if(e.type==="custom"){const n=t[e.id];if(!n)throw new Error(`Custom palette with id "${e.id}" not found`);return{type:"custom",id:e.id,colors:n}}return e}class fl extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","temporal"]}compile(t,n){if(t.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const r=this.computeDomain(n),a=ml(t.palette,r.length),o=a.length>0?a:[...an],s=q.scaleOrdinal().domain(r.map(String)).range(o).unknown(o[0]);return this.createVisualScale(t,{map:i=>s(String(i)),domain:r,generateTicks:()=>r})}computeDomain(t){const n=new Set,r=[];for(const a of t)n.has(a)||(n.add(a),r.push(a));return r}}class hl extends xe{constructor(){super("scale"),this.register("continuous",new Zc),this.register("discrete",new rl),this.register("datetime",new el),this.register("identity",new al),this.register("palette",new fl)}}const ka=e=>!("layers"in e),w={point:yl,line:gl,area:bl,bar:Sl,rule:xl};function yl(e={}){return{type:"layer",geom:"point",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function gl(e={}){return{type:"layer",geom:"line",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function bl(e={}){return{type:"layer",geom:"area",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function Sl(e={}){return{type:"layer",geom:"bar",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function xl(e={}){return{type:"layer",geom:"rule",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}const on={identity:vl,count:Tl,smooth:Al,mean:Il};function Al(e){return{type:"smooth",method:e.method,order:e.order,bandwidth:e.bandwidth}}function vl(){return{type:"identity"}}function Tl(){return{type:"count"}}function Il(){return{type:"mean"}}const re={reshape:wl,filter:Vl,sort:Ll,aggregate:El,constant:Ml};function wl(e={}){return{type:"transform",transformType:"reshape",options:e}}function Vl(e){return{type:"transform",transformType:"filter",options:e}}function Ll(e){return{type:"transform",transformType:"sort",options:e}}function El(e){return{type:"transform",transformType:"aggregate",options:e}}function Ml(e){return{type:"transform",transformType:"constant",options:e}}const sr="#%_ENCODED_%#",Ra=e=>{if(!e.startsWith(sr))return e;try{const{value:t}=JSON.parse(e.slice(sr.length));return typeof t=="string"?t:e}catch{return e}},Dl=({annotations:e,dataset:t,mapping:n})=>{const r=[],a=[],o=[],s=[],i=[],c=[],l=[],d=u.extractVariableName(n.x);for(const m of e??[])switch(m.type){case"difference-arrow":{const p=kl(m,d,t);p!==null&&r.push(p);break}case"shape":{a.push(Rl(m));break}case"arrow":{o.push(Ol(m));break}case"highlight":break;case"text":{s.push(Cl(m));break}case"sticker":{const p=_l(m,d,t);p!==null&&i.push(p);break}case"tooltip":{const p=Nl(m,d,t);if(p===null)break;p.kind==="pinnedNumber"?c.push(p.value):l.push(p.value);break}default:{const p=m;throw new Error(`Unsupported annotation type: ${p.type}`)}}return{differenceArrows:r,shapes:a,freeformArrows:o,textAnnotations:s,stickers:i,pinnedNumbers:c,comments:l}},kl=(e,t,n)=>{const r=it({dataset:n,input:e.start,anchorVariable:t}),a=it({dataset:n,input:e.end,anchorVariable:t});return r===null||a===null?null:{id:e.id,start:r,end:a,label:e.show,color:e.color??null,size:e.size,labelCrossPosition:e.labelPosition}},Rl=e=>({id:e.id,kind:e.shape,zOrder:e.layer==="abovePlot"?"foreground":"background",x:e.x,y:e.y,width:e.width,height:e.height,fillColor:e.fillColor,fillOpacity:e.fillOpacity,strokeWidth:e.strokeWidth,strokeColor:e.fillColor}),Cl=e=>({id:e.id,content:e.content,x:e.x,y:e.y,width:e.width,backgroundColor:e.backgroundColor??null,backgroundColorStyle:e.backgroundColorStyle}),_l=(e,t,n)=>{const r=it({dataset:n,input:e,anchorVariable:t});return r===null?null:{id:e.id,anchor:r,sticker:e.sticker}},Nl=(e,t,n)=>{const r=it({dataset:n,input:e,anchorVariable:t});return r===null?null:e.caption===null||e.caption===void 0?{kind:"pinnedNumber",value:{id:e.id,anchor:r}}:{kind:"comment",value:{id:e.id,anchor:r,content:e.caption}}},Ol=e=>({id:e.id,start:{x:e.startX,y:e.startY},end:{x:e.endX,y:e.endY},color:e.color??null,thickness:e.thickness,startArrowheadStyle:e.startArrowheadStyle,endArrowheadStyle:e.endArrowheadStyle,lineStyle:e.lineStyle,hasStickerStyle:e.hasStickerStyle}),it=({dataset:e,input:t,anchorVariable:n})=>{if(!u.isDefined(t)||!u.isDefined(t.columnKey))return null;const r=Fl(t,n,e);return r===null?null:{anchorValue:r,groupValue:Ra(t.columnKey)}},Fl=(e,t,n)=>e.rowValue!==void 0?e.rowValue:t===null||!u.isDefined(e.rowIndex)||!n.hasVariable(t)?null:n.getValues(t)[e.rowIndex]??null,Ca=["lilac","neon_pink","blackberry","sun","iceland","sunset","ultraviolet","purple","ice_cream","mint","cool","fresh"];function _a(e){return{type:"config",config:e}}const Pl="#E5E5E5",Bl={x:"top",y:"left"},Gl=new Set(["pie","donut"]);function Ul(e){return _a({legend:Wl(e.legend),axes:Xl(e.axes),headline:ql(e),numberFormat:jl(e.appearance),content:Ql(e.content),appearance:$l(e.appearance,e.themeOverrides)}).config}function $l(e,t){const n=Hl(e?.border),r=e?.hasRoundedCorners===!1?0:void 0,a=Yl(e,t),o={};return e?.textScale!==void 0&&(o.textScale=e.textScale),n!==void 0&&(o.border=n),r!==void 0&&(o.cornerRadius=r),a!==void 0&&(o.background=a),e?.highlightStyle!==void 0&&(o.highlightStyle=e.highlightStyle==="grey"?"desaturate":"dim"),Object.keys(o).length>0?o:void 0}function Yl(e,t){if(e?.backgroundModifier==="tint")return{type:"tinted"};const n=t?.graphBackground;if(typeof n=="string")return{type:"solid",color:n}}const Kl=e=>Ca.includes(e);function Hl(e){if(!e?.style)return;if(e.style==="none")return{type:"none"};const t=e.width??0;if(e.style==="grey")return{type:"solid",color:Pl,width:t};if(e.style==="preset")return e.color===void 0||!Kl(e.color)?void 0:{type:"preset",preset:e.color,width:t};if(e.color!==void 0)return e.style==="custom"?{type:"solid",color:e.color,width:t}:{type:e.style,color:e.color,width:t}}function Wl(e){if(e)return{position:e.position}}function ir(e,t,n){return!t&&n===void 0?{}:{...t?.isHidden!==void 0?{isVisible:!t.isHidden}:void 0,...t?.label!==void 0?{label:t.label}:void 0,...t?.isReversed?{position:Bl[e]}:void 0,...t?.tickDisplayMode?{labels:{mode:t.tickDisplayMode}}:void 0,...n!==void 0?{grid:{isVisible:n}}:void 0}}function zl(e){return{...e.label!==void 0?{label:e.label}:void 0}}function Xl(e){if(e)return{x:ir("x",e.x,e.showGridLines),y:ir("y",e.y,e.showGridLines),...e.y2?{ySecondary:zl(e.y2)}:void 0}}function ql(e){const{headlineNumbers:t,options:n,type:r}=e,a=r!==void 0&&Gl.has(r)?n?.pieTotalPosition:void 0;if(t===void 0&&a===void 0)return;const o={};return t?.show!==void 0&&(o.show=t.show),t?.compareWith!==void 0&&(o.compareWith=t.compareWith),t?.size!==void 0&&(o.size=t.size),a!==void 0&&(o.show="total",o.position=a==="center"?"center":"above"),o}function jl(e){if(e?.numberFormat)return{decimals:e.numberFormat.decimalPlaces,abbreviation:e.numberFormat.abbreviation}}function Ql(e){if(!e)return;const t={};e.title!==void 0&&(t.title=e.title),e.isTitleHidden!==void 0&&(t.isTitleVisible=!e.isTitleHidden),e.subtitle!==void 0&&(t.subtitle=e.subtitle),e.isSubtitleHidden!==void 0&&(t.isSubtitleVisible=!e.isSubtitleHidden),e.caption!==void 0&&(t.caption=e.caption),e.isCaptionHidden!==void 0&&(t.isCaptionVisible=!e.isCaptionHidden);const n=Zl(e.source);return n!==void 0&&(t.source=n),e.isSourceHidden!==void 0&&(t.isSourceVisible=!e.isSourceHidden),t}function Zl(e){if(!e)return;const t={};return e.label!==void 0&&(t.label=e.label),e.url!==void 0&&(t.url=e.url),Object.keys(t).length===0?void 0:t}const k={cartesian:(e={})=>({type:"coord",coordType:"cartesian",params:e}),flip:(e={})=>({type:"coord",coordType:"flip",params:e}),polar:(e={})=>({type:"coord",coordType:"polar",params:e})},Jl={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:u.POSITION_VARIABLES.yRaw}},nt={stat:{type:"identity"},position:"identity",params:{size:8}},It={stat:{type:"identity"},position:"identity",params:{lineWidth:"auto",interpolate:"linear",missingValues:"gap"}},wt={stat:{type:"identity"},position:"stack",params:{lineWidth:"auto",interpolate:"linear",missingValues:"zero"}},Vt={stat:{type:"identity"},position:"dodge",params:{}},Le={stat:{type:"identity"},position:"identity",interactive:!1,params:{strokeWidth:1,lineType:"dashed",labelPosition:"start"}},ve="primary";function eu(e,t){const n={...Jl};return e==="bar"&&t==="polar"&&(n.format="percentage"),n}function E(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"continuous",transform:t.transform,reverse:t.reverse,nice:t.nice,zero:t.zero,clamp:t.clamp,domainMin:t.domainMin??null,domainMax:t.domainMax??null,range:t.range}}function rt(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"datetime",domainMin:t.domainMin??null,domainMax:t.domainMax??null,nice:t.nice,reverse:t.reverse,clamp:t.clamp}}function G(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"discrete",range:t.range,domain:t.domain??null,padding:t.padding,reverse:t.reverse}}function ke(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"identity"}}function at(e,t){return{type:"scale",scaledAesthetic:e,scaleType:"inferred",options:t}}function Na(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"palette",palette:t.palette}}const ae={x:Object.assign(e=>at("x",e),{continuous:e=>E("x",e),discrete:e=>G("x",e),datetime:e=>rt("x",e),log:e=>E("x",{...e,transform:"log"}),sqrt:e=>E("x",{...e,transform:"sqrt"})}),y:Object.assign(e=>at("y",e),{continuous:e=>E("y",e),discrete:e=>G("y",e),datetime:e=>rt("y",e),log:e=>E("y",{...e,transform:"log"}),sqrt:e=>E("y",{...e,transform:"sqrt"})}),ySecondary:Object.assign(e=>at("ySecondary",e),{continuous:e=>E("ySecondary",e),discrete:e=>G("ySecondary",e),datetime:e=>rt("ySecondary",e),log:e=>E("ySecondary",{...e,transform:"log"}),sqrt:e=>E("ySecondary",{...e,transform:"sqrt"})}),color:{continuous:e=>E("color",e),discrete:e=>G("color",e),palette:e=>Na("color",e)},size:{continuous:e=>E("size",e),discrete:e=>G("size",e),identity:e=>ke("size",e)},alpha:{continuous:e=>E("alpha",e),discrete:e=>G("alpha",e),identity:e=>ke("alpha",e)},strokeWidth:{continuous:e=>E("strokeWidth",e),discrete:e=>G("strokeWidth",e),identity:e=>ke("strokeWidth",e)},lineType:{discrete:e=>G("lineType",e),identity:e=>ke("lineType",e)}},_="key",W="value",cr=u.prefixInternalVariable("lineSeriesLabel"),lr=u.prefixInternalVariable("barSeriesLabel"),ct=u.prefixInternalVariable("constantY"),tu=(e,t,n,r)=>cu[t](e,n,r),sn=e=>{const{numeric:t,categorical:n,temporal:r}=e.groupVariableNamesByType();return u.isDefined(r[0])?r[0]:u.isDefined(n[0])?n[0]:u.isDefined(t[0])?t[0]:""},cn=e=>{const t=sn(e),{numeric:n}=e.groupVariableNamesByType(),r=n.filter(o=>o!==t);return r.length<=1?{dataset:e,mapping:{x:t,y:r[0]??""},seriesVariables:r}:{dataset:e.reshapeFromWideToLong({keep:[t],keyName:_,valueName:W}),mapping:{x:t,y:W,color:_},seriesVariables:r}},ln=e=>{const t=e.appearance?.seriesStyles;if(!t||e.seriesVariables.length===0)return{mapping:{},scales:[]};if(!e.seriesVariables.some(a=>u.isDefined(t[a]?.lineStyle)))return{mapping:{},scales:[]};if(e.seriesVariables.length===1){const a=e.seriesVariables[0];if(!a)return{mapping:{},scales:[]};const o=t[a]?.lineStyle;return o?{mapping:{lineType:{value:o}},scales:[]}:{mapping:{},scales:[]}}const r=e.seriesVariables.map(a=>t[a]?.lineStyle??"solid");return{mapping:{lineType:_},scales:[ae.lineType.discrete({domain:e.seriesVariables,range:r})]}},nu=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType(),a=r[0];if(!u.isDefined(a))throw new Error("No first numeric variable found");const o=r.slice(1);return o.length===0?{dataset:e.addConstantVariable(ct,"categorical",""),mapping:{x:a,y:ct,label:t[0]}}:o.length===1?{dataset:e,mapping:{x:a,y:o[0]??"",label:t[0]}}:{dataset:e.reshapeFromWideToLong({keep:[a,...t,...n],keyName:_,valueName:W}),mapping:{x:a,y:W,label:t[0],color:_}}},ru=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType();let a,o;if(u.isDefined(t[0])&&u.isDefined(r[0]))a=t[0],o=r[0];else if(u.isDefined(n[0])&&u.isDefined(r[0]))a=n[0],o=r[0];else if(u.isDefined(r[0])&&u.isDefined(r[1]))a=r[0],o=r[1];else throw new Error("No label or value variable found");return{x:"",y:o,color:a}},Oa=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:o}=cn(e.dataset),s=ln({appearance:n,seriesVariables:o}),i=[w.line({params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&i.push(w.point({params:{size:Fa(t.pointSize)},interactive:!1})),{dataset:r,layers:i,coords:k.cartesian(),mapping:{...a,...s.mapping},scales:s.scales,seriesVariables:o}},au=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:o}=cn(e.dataset),s=ln({appearance:n,seriesVariables:o}),i=[w.area({position:"stack",params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&i.push(w.point({params:{size:Fa(t.pointSize)},position:"stack",interactive:!1})),{dataset:r,layers:i,coords:k.cartesian(),mapping:{...a,...s.mapping},scales:s.scales,seriesVariables:o}},ee=(e,t,n,r,a)=>{const{dataset:o,mapping:s,seriesVariables:i}=cn(e.dataset),c=[];if(r?.sortBars){const l=u.extractVariableName(s.y);l!==null&&l!==""&&c.push(re.sort({variableName:l,direction:"desc"}))}if(!a?.useSingleColorForBars){const l=sn(e.dataset),{numeric:d}=e.dataset.groupVariableNamesByType();d.filter(p=>p!==l).length===1&&e.dataset.getType(l)==="categorical"&&(s.color=l)}return{dataset:o,layers:[w.bar({position:t})],coords:n,mapping:s,scales:[],transforms:c,seriesVariables:i}},ur=(e,t)=>({dataset:e.dataset,layers:[w.bar({position:"fill"})],coords:k.polar({theta:"y",innerRadius:t==="donut"?.55:0}),mapping:ru(e.dataset),scales:[],seriesVariables:[]}),ou=e=>{const{dataset:t,mapping:n}=nu(e.dataset);return{dataset:t,layers:[w.point()],coords:k.cartesian(),mapping:n,scales:[],seriesVariables:[]}},su=e=>{const{numeric:t,categorical:n}=e.dataset.groupVariableNamesByType(),r=t[0];if(!u.isDefined(r))throw new Error("No first numeric variable found");const o=u.isDefined(t[1])?e.dataset:e.dataset.addConstantVariable(ct,"categorical",""),s={x:r,y:t[1]??ct,size:t[2],label:n[0]},i=[];return u.isDefined(s.size)&&i.push(ae.size.continuous()),{dataset:o,layers:[w.point()],coords:k.cartesian(),mapping:s,scales:i,seriesVariables:[]}},Lt=(e,t,n)=>{const r=n?.seriesStyles?.[e]?.lineStyle;return w.line({transforms:[re.constant({variableName:cr,type:"categorical",value:e})],aes:{y:e,color:cr,...r?{lineType:{value:r}}:{}},...t?{yScaleType:"secondary"}:void 0})},iu=(e,t,n)=>{const{numeric:r,categorical:a,temporal:o}=e.dataset.groupVariableNamesByType(),s=sn(e.dataset),i=[...a,...o],c=r.filter(g=>g!==s),l=t?.comboType??"grouped-bars",d=l==="lines";if(c.length===1)return d?Oa(e,t,n):ee(e,"dodge",k.cartesian(),t,n);const m=e.axes?.hasDualYAxis===!0,p=d?[]:c.slice(0,-1),f=d?c:c.slice(-1),h=[],y=[];if(p.length>0){const g=l==="stacked-bars"?"stack":"dodge",S=p.length===1?p[0]:null;u.isDefined(S)?h.push(w.bar({transforms:[re.constant({variableName:lr,type:"categorical",value:S})],aes:{y:S,color:lr},position:g})):h.push(w.bar({transforms:[re.reshape({keep:i,reshape:p,keyName:_,valueName:W})],aes:{y:W,color:_},position:g}))}if(d&&f.length>=2){const g=m?f.slice(0,-1):f,S=g.length===1?g[0]:null;if(u.isDefined(S))h.push(Lt(S,!1,n));else{const b=ln({appearance:n,seriesVariables:g});h.push(w.line({transforms:[re.reshape({keep:i,reshape:g,keyName:_,valueName:W})],aes:{y:W,color:_,...b.mapping}})),y.push(...b.scales)}if(m){const b=f[f.length-1];u.isDefined(b)&&h.push(Lt(b,!0,n))}}else for(const g of f)h.push(Lt(g,m,n));return{dataset:e.dataset,layers:h,coords:k.cartesian(),mapping:{x:s},scales:y,seriesVariables:c}},Fa=(e="auto")=>e==="auto"?nt.params.size:e,Ee=e=>()=>{throw new Error(`Unsupported graph type: ${e}`)},cu={line:(e,t,n)=>Oa(e,t,n),areaStacked:(e,t,n)=>au(e,t,n),bar:(e,t,n)=>ee(e,"dodge",k.flip(),t,n),barStacked:(e,t,n)=>ee(e,"stack",k.flip(),t,n),barStackedFill:(e,t,n)=>ee(e,"fill",k.flip(),t,n),column:(e,t,n)=>ee(e,"dodge",k.cartesian(),t,n),columnStacked:(e,t,n)=>ee(e,"stack",k.cartesian(),t,n),columnStackedFill:(e,t,n)=>ee(e,"fill",k.cartesian(),t,n),pie:e=>ur(e,"pie"),donut:e=>ur(e,"donut"),scatter:e=>ou(e),bubble:e=>su(e),combo:(e,t,n)=>iu(e,t,n),funnel:Ee("funnel"),heatmap:Ee("heatmap"),waterfall:Ee("waterfall"),mekko:Ee("mekko"),table:Ee("table")},Pa=["key",u.prefixInternalVariable("lineSeriesLabel"),u.prefixInternalVariable("barSeriesLabel")];function lu(e){const t=e.annotations??[],n=uu(e.mapping),r=pu(e.convertedDataset,e.layers),a=[];for(const o of t){if(o.type!=="highlight")continue;const s=du({annotation:o,rowIdentityVariable:n,dataset:e.dataset,compiledVariableNames:r});s!==null&&a.push({type:"highlight",id:o.id,predicate:s,scope:o.highlight})}return a}function uu(e){const t=u.extractVariableName(e.x);return t!==null&&t!==""?t:u.extractVariableName(e.color)}function du({annotation:e,rowIdentityVariable:t,dataset:n,compiledVariableNames:r}){switch(e.highlight){case"x-value":return dr(e,t,n);case"series":return mr(e,r);case"data-point":{const a=dr(e,t,n),o=mr(e,r);return a===null&&o===null?null:a===null?o:o===null?a:{and:[a,o]}}}}function dr(e,t,n){if(t===null)return null;const r=fu(e,t,n);return r===null?null:{variable:t,eq:r}}function mr(e,t){if(!mu(t))return null;const n=e.columnKey;return u.isDefined(n)?{or:Pa.map(r=>({variable:r,eq:n}))}:null}function mu(e){return Pa.some(t=>e.includes(t))}function pu(e,t){const n=[...e.getVariableNames()];for(const r of t)for(const a of r.transforms??[])a.transformType==="reshape"?n.push(a.options.keyName??_):a.transformType==="constant"&&n.push(a.options.variableName);return n}function fu(e,t,n){return e.rowValue!==void 0?e.rowValue:!u.isDefined(e.rowIndex)||!n.getVariableNames().includes(t)?null:n.getValues(t)[e.rowIndex]??null}function hu(e,t,n){const{theme:r,customPalettes:a}=n;if(a&&e&&a[e])return{type:"custom",id:e};if(e?.startsWith("preset:pastel"))return{type:"pastel",variant:Et(t)};if(e?.startsWith("preset:graphy"))return{type:"graphy",variant:Et(t)};const i="preset:mono:";if(e?.startsWith(i)){const l=e.slice(i.length);if(yu(l))return{type:"mono",base:l,variant:r}}const c="preset:neon:";if(e?.startsWith(c)){const l=e.slice(c.length);if(gu(l))return{type:"neon",base:l,variant:Et(t)}}return{type:"default"}}function Et(e){if(e==="waterfall")return"waterfall"}function yu(e){return Ma.includes(e)}function gu(e){return Da.includes(e)}function bu(e,t,n,r={}){const a=[];a.push(pr("x",t?.x)),a.push(pr("y",t?.y));const o=hu(n?.paletteId,e,r);return a.push(ae.color.palette({palette:o})),a}function pr(e,t){return t?.scaleType==="logarithmic"||t?.min!==void 0||t?.max!==void 0?t.scaleType==="logarithmic"?ae[e].log({domainMin:t.min??void 0,domainMax:t.max??void 0}):ae[e]({domainMin:t.min??void 0,domainMax:t.max??void 0}):ae[e]()}const Su=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","scatter","bubble","funnel","combo"]),xu=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","combo"]);function Au(e,t,n){const r=t.type??"column",a={dataset:e,axes:t.axes},o=tu(a,r,t.options??void 0,t.appearance??void 0);return{data:o.dataset,mapping:o.mapping,layers:vu(r,t,o.layers,o.coords,o.mapping,o.seriesVariables),scales:[...bu(r,t.axes,t.appearance,n),...o.scales],transforms:o.transforms??[],highlights:lu({annotations:t.annotations,dataset:e,mapping:o.mapping,convertedDataset:o.dataset,layers:o.layers}),annotations:Dl({annotations:t.annotations,dataset:e,mapping:o.mapping}),coords:o.coords,config:Ul(t)}}function vu(e,t,n,r,a,o){const s=Lu(t.dataLabels),i=s===void 0?n:n.filter(l=>l.interactive!==!1).map(l=>({...l,dataLabels:{...s,...l.dataLabels}})),c=t.axes?.hasDualYAxis??!1;return[...i,...Tu({type:e,trendline:t.referenceLines?.trendline,coords:r}),...Iu({type:e,hasDualYAxis:c,goalLine:t.referenceLines?.goalLine,coords:r}),...Vu({type:e,hasDualYAxis:c,averageLine:t.referenceLines?.averageLine,coords:r,mapping:a,seriesVariables:o})]}function Tu({type:e,trendline:t,coords:n}){return t===void 0?[]:Su.has(e)?n.coordType==="polar"?[]:[w.line({aes:{lineType:{value:"dashed"}},stat:on.smooth({method:t}),interactive:!1})]:[]}function Iu({type:e,hasDualYAxis:t,goalLine:n,coords:r}){if(!wu(n))return[];if(r.coordType==="polar")return[];const a=r.coordType==="flip"?"end":"start";return[w.rule({aes:{y:{value:n.target}},params:{labelPosition:a,label:n.label??"Goal"},yScaleType:e==="combo"&&t?"secondary":"primary",interactive:!1})]}function wu(e){return e!==void 0&&Number.isFinite(e.target)}function Vu({type:e,hasDualYAxis:t,averageLine:n,coords:r,mapping:a,seriesVariables:o}){if(n===void 0)return[];if(!xu.has(e))return[];if(r.coordType==="polar")return[];const s=Ra(n.columnKey);if(!o.includes(s))return[];const i=a.color===_,c=i?W:s,l=i?[re.filter({variableName:_,operator:"eq",value:s})]:[];return[w.rule({aes:{y:c,color:void 0,group:void 0,lineType:void 0},stat:on.mean(),transforms:l,params:{label:"Average",labelPosition:r.coordType==="flip"?"end":"start"},yScaleType:e==="combo"&&t?"secondary":"primary",interactive:!1})]}function Lu(e){if(!e)return;const t={};return e.showDataLabels!==void 0&&(t.showDataLabels=e.showDataLabels),e.dataLabelFormat!==void 0&&(t.format=e.dataLabelFormat),e.showStackTotals!==void 0&&(t.showStackTotals=e.showStackTotals),e.showCategoryLabels!==void 0&&(t.showCategoryLabels=e.showCategoryLabels),Object.keys(t).length===0?void 0:t}const Mt={color:null,size:"small",labelCrossPosition:.5},fe={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},fr={backgroundColor:null,backgroundColorStyle:"opaque"},he={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Eu=(e,t)=>({differenceArrows:(e?.differenceArrows??[]).map(n=>Ru(n,t)),shapes:(e?.shapes??[]).map(Ou),freeformArrows:(e?.freeformArrows??[]).map(Fu),textAnnotations:(e?.textAnnotations??[]).map(ku),stickers:(e?.stickers??[]).map(n=>Cu(n,t)),pinnedNumbers:(e?.pinnedNumbers??[]).map(n=>_u(n,t)),comments:(e?.comments??[]).map(n=>Nu(n,t)),custom:(e?.custom??[]).map(n=>Mu(n,t))}),Mu=(e,t)=>({id:e.id??crypto.randomUUID(),type:e.type,coordinates:e.coordinates.map(n=>Du(n,t)),params:e.params??{},zOrder:e.zOrder??null}),Du=(e,t)=>"observation"in e?{observation:ge(e.observation,t)}:e,ku=e=>({id:e.id??crypto.randomUUID(),content:e.content,x:e.x,y:e.y,width:e.width,backgroundColor:e.backgroundColor??fr.backgroundColor,backgroundColorStyle:e.backgroundColorStyle??fr.backgroundColorStyle}),Ru=(e,t)=>({id:e.id??crypto.randomUUID(),start:ge(e.start,t),end:ge(e.end,t),label:e.label,color:e.color??Mt.color,size:e.size??Mt.size,labelCrossPosition:e.labelCrossPosition??Mt.labelCrossPosition}),ge=(e,t)=>{if(e.layerIndex===void 0)return{anchorValue:e.anchorValue,groupValue:e.groupValue};const n=t[e.layerIndex]?.id;if(n===void 0)throw new Error(`Annotation references layerIndex ${e.layerIndex} but only ${t.length} layer(s) are defined.`);return{layerId:n,anchorValue:e.anchorValue,groupValue:e.groupValue}},Cu=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t),sticker:e.sticker}),_u=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t)}),Nu=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t),content:e.content}),Ou=e=>({id:e.id??crypto.randomUUID(),kind:e.kind??fe.kind,zOrder:e.zOrder??fe.zOrder,x:e.x,y:e.y,width:e.width,height:e.height,fillColor:e.fillColor??fe.fillColor,fillOpacity:e.fillOpacity??fe.fillOpacity,strokeWidth:e.strokeWidth??fe.strokeWidth,strokeColor:e.strokeColor??fe.strokeColor}),Fu=e=>({id:e.id??crypto.randomUUID(),start:e.start,end:e.end,color:e.color??he.color,thickness:e.thickness??he.thickness,startArrowheadStyle:e.startArrowheadStyle??he.startArrowheadStyle,endArrowheadStyle:e.endArrowheadStyle??he.endArrowheadStyle,lineStyle:e.lineStyle??he.lineStyle,hasStickerStyle:e.hasStickerStyle??he.hasStickerStyle}),Pu={parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1},appearance:{textScale:1,background:{type:"theme"},border:{type:"none"},cornerRadius:8,highlightStyle:"dim"}};function Bu(e){return le.merge({},Pu,e)}const Gu={xLimits:null,yLimits:null},Dt={theta:"x",startAngle:0,innerRadius:0};function Uu(e){const t=e??{type:"coord",coordType:"cartesian"},n=Fr({},Gu,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:n};case"polar":return{...t,params:{...n,theta:t.params?.theta??Dt.theta,startAngle:t.params?.startAngle??Dt.startAngle,innerRadius:t.params?.innerRadius??Dt.innerRadius}}}}function $u(e,t){return e.map(n=>{const r=n.layerIndex!==void 0?t[n.layerIndex]?.id:void 0;if(n.layerIndex!==void 0&&r===void 0)throw new Error(`Highlight references layerIndex ${n.layerIndex} but only ${t.length} layer(s) are defined.`);return{type:"highlight",id:n.id??crypto.randomUUID(),predicate:n.predicate,scope:n.scope??"data-point",...r!==void 0?{layerId:r}:{}}})}const Yu="linear",Ku=3,Hu=.3;function Te(e,t){const n=e??t,r=typeof n=="string"?n:n.type;if(r==="smooth"){const a=typeof n=="string"?void 0:n;return{type:"smooth",method:a?.method??Yu,order:a?.order??Ku,bandwidth:a?.bandwidth??Hu}}return{type:r}}function Wu(e,t,n){if(!qu(n))return ju(e,t,n);switch(n.geom){case"point":return Qu(e,t,n);case"line":return Zu(e,t,n);case"area":return Ju(e,t,n);case"bar":return ed(e,t,n);case"rule":return td(e,t,n)}}function zu(e,t,n){const r=n.map(a=>Wu(e,t,a));return nd(r)}const Xu=(e,t,n)=>n.label!==void 0?n.label:rd(e,t,n),qu=e=>xa(e.geom);function ju(e,t,n){const r=n.position??"identity";return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,"identity"),position:r,yScaleType:n.yScaleType??ve,params:n.params??{},transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}const Ie=(e,t,n,r)=>{const a={...e,...t.mapping},o=Xu(t.geom,n,a);return{...eu(t.geom,r),...t.dataLabels,labelSource:o}};function Qu(e,t,n){const r=n.position??nt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,nt.stat.type),position:r,yScaleType:n.yScaleType??ve,params:le.merge({},nt.params,n.params),transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function Zu(e,t,n){const r=n.position??It.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,It.stat.type),position:r,yScaleType:n.yScaleType??ve,params:le.merge({},It.params,n.params),transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function Ju(e,t,n){const r=le.merge({},wt.params,n.params);r.missingValues==="gap"&&(r.missingValues="zero");const a=n.position??wt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,wt.stat.type),position:a,yScaleType:n.yScaleType??ve,params:r,transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,a,t)}}function ed(e,t,n){const r=n.position??Vt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,Vt.stat.type),position:r,yScaleType:n.yScaleType??ve,params:{...Vt.params,...n.params},transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function td(e,t,n){const r=n.position??Le.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,Le.stat.type),position:n.position??Le.position,yScaleType:n.yScaleType??ve,params:le.merge({},Le.params,n.params),transforms:n.transforms??[],interactive:n.interactive??Le.interactive,dataLabels:Ie(e,n,r,t)}}const nd=e=>{const t=new Set;for(const n of e)n.position==="fill"&&t.add(n.yScaleType);return t.size===0?e:e.map(n=>{if(n.geom!=="rule"||!t.has(n.yScaleType))return n;const r=u.extractConstantValue(n.mapping.y);if(!I(r))return n;const a=Math.min(1,Math.max(0,r));return{...n,mapping:{...n.mapping,y:{value:a}}}})},rd=(e,t,n)=>{if(e==="point"){const r=u.extractVariableName(n.size);if(r!==null)return{variable:r}}return $e(t,n)};function ad(e,...t){return e?t.includes(e.geom):!1}function od(e,t){return e.find(n=>n.id===t)}function Ba(e,...t){return e.find(n=>t.includes(n.geom))}function sd(e,t,n){const r=e.layers.findIndex(o=>o.id===t);if(r===-1)return e;const a=e.layers.map((o,s)=>s===r?n:o);return{...e,layers:a}}const Ga={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},id={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Ua(e,t,n,r,a){switch(e.scaleType){case"inferred":{const o=ud(e,t,n,r);return Ua(o,t,n,r,a)}case"continuous":{const o=Ga[e.scaledAesthetic],s=o==="continuous-range"&&e.scaledAesthetic in ar?ar[e.scaledAesthetic]:null,i=e.scaledAesthetic==="size"&&o==="continuous-range"?"sqrt":pe.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??i,reverse:e.reverse??pe.reverse,nice:e.nice??pe.nice,zero:e.zero??pe.zero,clamp:e.clamp??o!=="position",domainMin:e.domainMin??pe.domainMin,domainMax:e.domainMax??pe.domainMax,range:e.range??s??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??We.domainMin,domainMax:e.domainMax??We.domainMax,nice:e.nice??We.nice,reverse:e.reverse??We.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??De.range,domain:e.domain??De.domain,padding:e.padding??De.padding,reverse:e.reverse??De.reverse};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:pl(e.palette,a)};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const o=e;throw new Error(`Unknown scale type: ${o.scaleType}`)}}}function cd(e,t,n,r,a,o){const s=md(t,n),i=pd(s),c=new Map;for(const d of i)c.set(d.scaledAesthetic,d);const l=[...c.values()].map(d=>Ua(d,e,n,r,o));return a.coordType==="polar"?ld(l):l}const ld=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t);function ud(e,t,n,r){const a=Y(e.scaledAesthetic),o=e.scaledAesthetic==="ySecondary"?dd(n,r):r[a],s=Ba(n,"bar");if(e.scaledAesthetic==="x"&&s)return G(e.scaledAesthetic,e.options);if(s&&e.scaledAesthetic===(s.yScaleType==="secondary"?"ySecondary":"y")){const m=e.options,p=s.position==="fill";return E(e.scaledAesthetic,{...m,zero:!0,...p&&{nice:!1}})}const i=u.extractVariableName(o);if(!u.isDefined(i)||!t.hasVariable(i))return E(e.scaledAesthetic,e.options);const c=t.getType(i),l=Ga[e.scaledAesthetic];switch(id[c][l]){case"discrete":return G(e.scaledAesthetic,e.options);case"datetime":return rt(e.scaledAesthetic,e.options);case"continuous":return E(e.scaledAesthetic,e.options);case"identity":default:return ke(e.scaledAesthetic)}}function dd(e,t){const n=e.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??t.y:t.y}function md(e,t){return!t.some(a=>a.yScaleType==="secondary")||e.some(a=>a.scaledAesthetic==="ySecondary")?e:[...e,at("ySecondary")]}function pd(e){return e.some(n=>n.scaledAesthetic==="color")?e:[...e,Na("color")]}function hr(e,t){const n=Uu(e.coords),r=zu(e.mapping,n.coordType,e.layers),a=cd(e.data,e.scales,r,e.mapping,n,t),o=Bu(e.config),s=$u(e.highlights,r),i=Eu(e.annotations,r);return{data:e.data,mapping:e.mapping,layers:r,scales:a,transforms:e.transforms,highlights:s,annotations:i,coords:n,config:o}}class $a{compile({input:t,dataset:n,ctx:r}){const a=r.customPalettes??{};return ka(t)?hr(Au(n,t,r),a):hr({...t,data:n},a)}}class fd{constructor(t){this.registry=t}compute(t,n){return this.registry.get(t.type).compute({data:n.data,mapping:n.mapping,spec:t,xScaleIsDiscrete:n.xScaleIsDiscrete})}}class gt{compute(t){return t.data.size()===0?{data:t.data,mapping:{}}:this.computeStat(t)}}class hd extends gt{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=u.extractVariableName(n.x);if(!u.isDefined(r))throw new Error("'x' variable is required for 'count' stat");if(u.extractVariableName(n.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const o=[...new Set([r,...Qt(t,n)])];return{data:t.groupBy(...o).rollup({[u.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:u.STAT_VARIABLES.count}}}}class yd extends gt{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:t}){return{data:t,mapping:{}}}}class gd extends gt{constructor(){super(...arguments),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=u.extractVariableName(n.y);if(!u.isDefined(r))throw new Error("'y' variable is required for 'mean' stat");return{data:t.rollup({[u.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:u.STAT_VARIABLES.mean}}}}const bd=2,Ya=1440*60*1e3;class Sd extends gt{constructor(){super(...arguments),this.type="smooth",this.computedVariables=new Set}computeStat({data:t,mapping:n,spec:r,xScaleIsDiscrete:a}){if(r.type!=="smooth")throw new Error(`SmoothStat received a spec of type '${r.type}'`);const o=u.extractVariableName(n.x),s=u.extractVariableName(n.y);if(!u.isDefined(o))throw new Error("'x' variable is required for 'smooth' stat");if(!u.isDefined(s))throw new Error("'y' variable is required for 'smooth' stat");const i=t.getType(o),c=t.getType(s);if(c!=="numeric")throw new Error(`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${s}')`);const l=Qt(t,n),d=Vd(o,i,s,l,t);return l.length===0?yr({data:t,xVariable:o,xType:i,yVariable:s,spec:r,output:d,groupObservation:{},xScaleIsDiscrete:a}):t.groupBy(...l).forEach(m=>{const p=Ld(m,l);yr({data:m,xVariable:o,xType:i,yVariable:s,spec:r,output:d,groupObservation:p,xScaleIsDiscrete:a})}),{data:d.build(),mapping:{}}}}const yr=({data:e,xVariable:t,xType:n,yVariable:r,spec:a,output:o,groupObservation:s,xScaleIsDiscrete:i})=>{const{observations:c,temporalOrigin:l}=xd({data:e,xVariable:t,yVariable:r,xType:n});c.length<bd||(i?wd({observations:c,spec:a,output:o,groupObservation:s}):Td({observations:c,xType:n,temporalOrigin:l,spec:a,output:o,groupObservation:s}))},xd=({data:e,xVariable:t,yVariable:n,xType:r})=>{const a=e.getValues(t),o=e.getValues(n,{type:"numeric"}),s=r==="temporal"?Ad(a):null,i=[],c=new Map;for(let l=0;l<a.length;l++){const d=a[l],m=o[l];if(!u.isDefined(d)||!u.isDefined(m)||!Number.isFinite(m))continue;const p=vd({xValue:d,xType:r,categoryRank:c,temporalOrigin:s});p!==null&&i.push({x:p,y:m,originalX:d})}return{observations:i,temporalOrigin:s}},Ad=e=>{let t=null;for(const n of e){if(!R(n))continue;const r=n.getTime();(t===null||r<t)&&(t=r)}return t},vd=({xValue:e,xType:t,categoryRank:n,temporalOrigin:r})=>{switch(t){case"numeric":return!I(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!R(e))return null;const a=e.getTime();return r===null?a:(a-r)/Ya+1}case"categorical":{if(!Pe(e))return null;const a=n.get(e);if(a!==void 0)return a;const o=n.size+1;return n.set(e,o),o}default:{const a=t;throw new Error(`Unexpected xType: ${a}`)}}},Td=({observations:e,xType:t,temporalOrigin:n,spec:r,output:a,groupObservation:o})=>{const s=Ka(r,e);for(const[i,c]of s){if(!Number.isFinite(i)||!Number.isFinite(c))continue;const l=t==="temporal"?Id(i,n):i;a.push({x:l,y:c,groupObservation:o})}},Id=(e,t)=>t===null?new Date(e):new Date((e-1)*Ya+t),wd=({observations:e,spec:t,output:n,groupObservation:r})=>{const a=new Map;for(const i of e)a.has(i.x)||a.set(i.x,i.originalX);const o=[...a.keys()].sort((i,c)=>i-c);if(t.method==="loess"){const i=Ka(t,e),c=new Map;for(const[l,d]of i)Number.isFinite(d)&&(c.has(l)||c.set(l,d));for(const l of o){const d=c.get(l),m=a.get(l);d===void 0||m===void 0||n.push({x:m,y:d,groupObservation:r})}return}const s=Ha(t,e);for(const i of o){const c=a.get(i),l=s.predict(i);c===void 0||!Number.isFinite(l)||n.push({x:c,y:l,groupObservation:r})}},Ka=(e,t)=>e.method==="loess"?J.regressionLoess().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):Ha(e,t),Ha=(e,t)=>{const n=a=>a.x,r=a=>a.y;switch(e.method){case"linear":return J.regressionLinear().x(n).y(r)(t);case"exponential":return J.regressionExp().x(n).y(r)(t);case"logarithmic":return J.regressionLog().x(n).y(r)(t);case"quadratic":return J.regressionQuad().x(n).y(r)(t);case"power":return J.regressionPow().x(n).y(r)(t);case"polynomial":return J.regressionPoly().x(n).y(r).order(e.order)(t);case"loess":throw new Error("'loess' does not expose a 'predict' function")}},Vd=(e,t,n,r,a)=>{const o=[],s=[],i=Object.fromEntries(r.map(c=>[c,[]]));return{push:({x:c,y:l,groupObservation:d})=>{o.push(c),s.push(l);for(const m of r)i[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:o,valueFormat:a.getValueFormat(e)},[n]:{type:"numeric",values:s,valueFormat:a.getValueFormat(n)}};for(const l of r)c[l]={type:a.getType(l),values:i[l]??[],valueFormat:a.getValueFormat(l)};return new u.Dataset(c)}}},Ld=(e,t)=>{const n={};for(const r of t){const a=e.getValues(r);n[r]=a[0]??null}return n};class Ed extends xe{constructor(){super("stat"),this.register("identity",new yd),this.register("count",new hd),this.register("smooth",new Sd),this.register("mean",new gd)}}const Md=({layer:e})=>{if(e.position==="stack")return;const t=u.extractVariableName(e.mapping.y);if(t===null)return;let n=0,r=0;for(const a of e.data){const o=a[t];I(o)&&(n+=o,r+=Math.abs(o))}return{grandTotal:n,absoluteGrandTotal:r}},Dd=({layer:e})=>{if(e.position!=="stack")return;const t=u.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(u.POSITION_VARIABLES.yMin)||!e.data.hasVariable(u.POSITION_VARIABLES.yMax))return;const n=new Map;for(const a of e.data){const o=a[t],s=se(a),i=$(a),c=_e(a),l=ye(a),d=ua(a);if(!u.isDefined(o)||!u.isDefined(s)||!u.isDefined(i)||!u.isDefined(c)||!u.isDefined(l)||!u.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const f=en(a,t),h={yMin:s,yMax:i},y=n.get(f);if(y===void 0){n.set(f,{total:d,topPositive:m?h:null,bottomNegative:m?null:h,anchorXMin:c,anchorXMax:l});continue}y.total+=d,m?(y.topPositive===null||i>y.topPositive.yMax)&&(y.topPositive=h):(y.bottomNegative===null||s<y.bottomNegative.yMin)&&(y.bottomNegative=h)}const r=[];for(const[a,o]of n){const s=o.topPositive??o.bottomNegative;s!==null&&r.push({xKey:a,total:o.total,anchor:{xMin:o.anchorXMin,xMax:o.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:o.topPositive!==null?"positive":"negative"}})}return r};class kd extends Se{constructor(t){super(),this.geomCompiler=t}dependencies(){return[]}compileLayer(t){const n={};if(this.geomCompiler.emitsStackTotals(t.geom)){const r=Dd({layer:t});r!==void 0&&(n.stackTotals=r)}if(this.geomCompiler.emitsGrandTotal(t.geom)){const r=Md({layer:t});r!==void 0&&(n.grandTotal=r.grandTotal,n.absoluteGrandTotal=r.absoluteGrandTotal)}return{...t,summary:n}}}class Rd extends j{constructor(t){super(),this.registry=t}key(t){return t.data}dependencies(t){return[t.transforms]}run(t){return t.transforms.reduce((n,r)=>this.registry.get(r.transformType).apply(n,r),t.data)}}class Cd{constructor(){this.transformType="aggregate"}apply(t,n){const{options:r}=n,a={};for(const o of r.operations)a[o.as]={variableName:o.variableName,aggregation:o.op};return t.groupBy(...r.groupby).rollup(a)}}class _d{constructor(){this.transformType="constant"}apply(t,n){const{options:r}=n;return t.addConstantVariable(r.variableName,r.type,r.value)}}class Nd{constructor(){this.transformType="filter"}apply(t,n){const{options:r}=n;return t.filter(r.variableName,r.operator,r.value)}}class Od{constructor(){this.transformType="reshape"}apply(t,n){const{options:r}=n;return t.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}}class Fd{constructor(){this.transformType="sort"}apply(t,n){const{options:r}=n;return t.orderBy(r.variableName,r.direction??"asc")}}class Pd extends xe{constructor(){super("transform"),this.register("aggregate",new Cd),this.register("constant",new _d),this.register("filter",new Nd),this.register("reshape",new Od),this.register("sort",new Fd)}}const gr={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"};class Bd extends Se{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[...pt].map(n=>t.scales[n])}compileLayer(t,n){const r=this.geomCompiler.getVisualAesthetics(t.geom),a=Gd(t.data,t.mapping,r,n.scales);return{...t,data:a}}}function Gd(e,t,n,r){let a=e;for(const o of n){const s=u.VISUAL_VARIABLES[o],i=u.extractConstantValue(t[o]);if(i!==void 0){a=a.deriveVariable(s,gr[o],()=>i);continue}const c=u.extractVariableName(t[o]),l=r[o];if(!l||l.kind!=="visual")continue;const d=Ud(o,c,l);d&&(a=a.deriveVariable(s,gr[o],d))}return a}const Ud=(e,t,n)=>{if(!t){if(e!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>u.isDefined(r[t])?n.map(r[t]):null},$d=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","highlights","config","annotations"];class Wa{constructor(t,n,r,a,o,s,i,c,l,d,m,p,f,h,y){this.dataCompiler=t,this.specCompiler=n,this.transformCompiler=r,this.constantMappingCompiler=a,this.layerValidationCheck=o,this.layerCompiler=s,this.scaleCompiler=i,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=d,this.guideCompiler=m,this.summariseCompiler=p,this.highlightsCompiler=f,this.configCompiler=h,this.annotationsCompiler=y,this.lastCompile=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.layerCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"config",getStats:()=>this.configCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile({input:t,data:n,ctx:r={}}){return this.trackCompile(()=>(this.lastData=n,this.runPipeline({spec:this.specCompiler.compile({input:t,ctx:r,dataset:this.dataCompiler.compile(n)})})))}recompile({spec:t,data:n}){return this.trackCompile(()=>n===void 0?this.runPipeline({spec:t}):(this.lastData=n,this.runPipeline({spec:xt(t,{data:this.dataCompiler.compile(n)})})))}getCacheStats(){const t={};for(const{name:n,getStats:r}of this.stages)t[n]={...r()};return t}getLastCompile(){return this.lastCompile}trackCompile(t){if(!ne)return t();const n=this.getCacheStats(),r=performance.now(),a=t(),o=performance.now()-r,s={};for(const{name:i,getStats:c}of this.stages){const l=c();s[i]={hits:l.hits-n[i].hits,misses:l.misses-n[i].misses}}return this.lastCompile={stages:s,durationMs:o},a}runPipeline({spec:t}){return ut({spec:t}).pipe(({spec:r})=>({spec:xt(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const a=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:xt(r,{data:a.data,mapping:a.mapping})}}).pipe(({spec:r})=>{const a={data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales};return this.layerValidationCheck.check({...a,coords:r.coords}),{layers:this.layerCompiler.compile(a)}}).pipe(({spec:r,layers:a})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:a})).pipe(({layers:r,scales:a})=>({scales:this.scaleCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,scales:a})=>({config:this.configCompiler.compile({config:r.config,scales:a})})).pipe(({layers:r,scales:a})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:a})})).pipe(({layers:r,scales:a})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,layers:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,layers:a})})).pipe(({layers:r})=>({layers:this.summariseCompiler.compile({layers:r})})).pipe(({spec:r,scales:a,layers:o,coordSystem:s})=>({guides:this.guideCompiler.compile({scales:a,config:r.config,layers:o,coordSystem:s,originalData:this.lastData})})).pipe(({spec:r,layers:a})=>({layers:this.highlightsCompiler.compile({layers:a,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:a,coordSystem:o,scales:s})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:a,coordSystem:o,scales:s})})).result()}}const Yd=e=>{const t=new Qs({geoms:e?.geoms}),n=new Ks(t),r=new Ed,a=new hl,o=new Rd(new Pd);return new Wa(new Bs,new $a,o,new qo,new Cc(o,new _c(t,r)),new Rc(o,new fd(r),new Zs,n,new Oc(new Uc)),new Qc(a),new Jo(new us(t)),new jc(t),new Bd(n),new cc(n),new kd(n),new Sc,new Xo,new Bo(n))};function Kd(e,t){return e.geom===t}const un="–",za="n/a",D={timeZone:"UTC"},M=e=>t=>{if(!R(t))return un;try{return e(t)}catch{return za}},Q=e=>t=>I(t)?e(t):un,dn=e=>t=>Pe(t)?t:un,Hd=2,Wd=3,zd=2,Xd=0,qd=1,jd=2,Qd=Lo.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Xa=({valueFormat:e,locale:t,numberFormat:n,intlOptions:r})=>Q(a=>{const o=typeof n.decimals=="number"?n.decimals:Hd,s=hn(a,o),{base:i,suffix:c}=fn(a,n.abbreviation),l={...s,...Wr(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return`${Intl.NumberFormat(t,l).format(i)}${c}`}),mn=({locale:e,numberFormat:t,intlOptions:n})=>Q(r=>{const{base:a,suffix:o}=fn(r,t.abbreviation),i={...hn(a,t.decimals),...n};return`${Intl.NumberFormat(e,i).format(a)}${o}`}),pn=e=>Q(t=>Qd(t)),qa=({locale:e,intlOptions:t})=>Q(n=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(n)),ja=({locale:e,numberFormat:t,intlOptions:n})=>Q(r=>{const a=hn(r,t.decimals);return Intl.NumberFormat(e,{...a,...n,style:"percent"}).format(r)}),fn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const n=Zd(e);return fn(e,n)}default:return{base:e/Re[t],suffix:t}}},hn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const n=Math.ceil(Math.log10(Math.abs(e))),r=n>=Wd?Xd:n===zd?qd:jd;return{minimumFractionDigits:t==="auto"?0:r,maximumFractionDigits:r}},Zd=e=>{const t=Math.abs(e);return t>=Re.b?"b":t>=Re.m?"m":t>=Re.k?"k":"none"},Jd=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{dateStyle:"medium",...D,...t}).format(n)),em=({locale:e,intlOptions:t})=>M(n=>{const r=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...D,...t}).formatToParts(n);return tm(r.map(nm))}),Qa=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...D,...t}).format(n)),Za=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"long",...D,...t}).format(n)),yn=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...D,...t}).format(n)),gn=e=>M(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Ja=({locale:e,intlOptions:t})=>M(n=>{const r=v.addDays(n,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...D,...t,year:void 0}).formatRange(n,r)}),eo=({locale:e,intlOptions:t})=>M(n=>{const r=v.addDays(n,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...D,...t}).formatRange(n,r)}),bn=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{year:"numeric",...D,...t}).format(n)),to=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...D,...t}).format(n)),tm=e=>e.map(t=>t.value).join(""),nm=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},rm=1,am=4,om=1,br=1e3,sm=({valueFormat:e,locale:t,tickValues:n,intlOptions:r})=>Q(a=>{const s={...xn(a,n),notation:"compact",...Wr(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return Sn(a,t,s)}),im=({locale:e,tickValues:t,intlOptions:n})=>Q(r=>{const o={...xn(r,t),notation:"compact",...n};return Sn(r,e,o)}),cm=({locale:e,tickValues:t,intlOptions:n})=>Q(r=>{const o={...xn(r,t),notation:"compact",...n,style:"percent"};return Sn(r,e,o)}),Sn=(e,t,n)=>Intl.NumberFormat(t,n).formatToParts(e).map(a=>a.type==="compact"?a.value.toLowerCase():a.value).join(""),no=e=>Math.abs(e)>br?no(e/br):Number.isInteger(e),lm=e=>{if(e.length<2)return!1;const[t,n]=e;return typeof t!="number"||typeof n!="number"?!1:Math.abs(n-t)<rm},xn=(e,t)=>no(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:lm(t)?{minimumFractionDigits:0,maximumFractionDigits:am}:{minimumFractionDigits:0,maximumFractionDigits:om},um=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...D,...t}).format(n)),dm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"short",...D,...t}).format(n)),mm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...D,...t}).format(n)),pm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...D,...t}).format(n)),An=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return sm(e);case"date":case"datetime":return um(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return mm(e);case"decimal":case"integer":return im(e);case"duration":return pn();case"month":return dm(e);case"month_year":return yn(e);case"percentage":return cm(e);case"quarter":return gn();case"text":return dn();case"time":return pm(e);case"year":return bn(e);case"lookup":return An({...e,valueFormat:t.fallback});default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},fm=40,hm=60,Sr=8,ym=50,gm=1/3,bm=1/4,kt="…",Sm=(e,t,n)=>{if(t<=0||e.length===0)return"";if(n(e)<=t)return e;if(n(kt)>t)return"";let r=0,a=e.length-1,o=0;for(;r<=a;){const s=r+a>>>1,i=e.slice(0,s)+kt;n(i)<=t?(o=s,r=s+1):a=s-1}return e.slice(0,o)+kt},xm=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Am(e):vm(e),Am=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:o,maxHeight:s}=ro(e.ticks,r),i=t-Sr;if(o<=i)return{...e,labelRotation:0,labelMaxWidthPx:null};if(t>=ym){const l=Yt(i);return{...e,ticks:$t(e.ticks,a,l,r),labelRotation:0,labelMaxWidthPx:l}}if(s+Sr>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=Yt(n.height*gm);return{...e,ticks:$t(e.ticks,a,c,r),labelRotation:-90,labelMaxWidthPx:c}},vm=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:o,maxHeight:s}=ro(e.ticks,r);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const i=Yt(n.width*bm);return o<=i?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:$t(e.ticks,a,i,r),labelRotation:0,labelMaxWidthPx:i}},ro=(e,t)=>{const n=[];let r=0,a=0;for(const o of e){const{width:s,height:i}=t(o.formattedLabel);n.push(s),s>r&&(r=s),i>a&&(a=i)}return{widths:n,maxWidth:r,maxHeight:a}},$t=(e,t,n,r)=>{const a=o=>r(o).width;return e.map((o,s)=>(t[s]??0)<=n?o:{...o,formattedLabel:Sm(o.formattedLabel,n,a)})},Yt=e=>Math.max(0,Math.floor(e)),Tm=(e,t,n,r)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",o=a?hm:fm;let s=n-(e.length-1)*o;for(const i of e){const{width:c,height:l}=r(i);if(s-=a?c:l,s<0)return!1}return!0},Im=({axis:e,availableSpacePx:t,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:a,position:o}=e;if(a.length===0)return[];const s=new Map,i=m=>{const p=s.get(m);if(p)return p;const f=a[m],h=f?wm(f.ticks,r(f)):[];return s.set(m,h),h};let c=0,l=a.length-1,d=-1;for(;c<=l;){const m=c+l>>>1,f=i(m).map(h=>h.formattedLabel);Tm(f,o,t,n)?(d=m,c=m+1):l=m-1}return d>=0?i(d):i(0)},wm=(e,t)=>e.map(n=>({...n,formattedLabel:t(n.value)})),Rt=6,Ct=6,_t=15,Nt=5,Ot=15,vn=(e,t)=>{switch(e){case"small":return{arrowStartGap:Rt,arrowEndGap:Ct,offsetFromHigherObservation:_t,arrowheadSize:Nt,curveRadius:Ot,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Rt*1.5,arrowEndGap:Ct*1.5,offsetFromHigherObservation:_t*1.25,arrowheadSize:Nt*1.5,curveRadius:Ot*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Rt*2,arrowEndGap:Ct*2,offsetFromHigherObservation:_t*1.75,arrowheadSize:Nt*2.5,curveRadius:Ot*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Vm=e=>{const t=V({...e,valueFormat:e.valueFormat.fallback}),n={};for(const[a,o]of Object.entries(e.valueFormat.cases))n[a]=V({...e,valueFormat:o});const r=e.valueFormat.byVariable;return(a,o)=>{if(o===void 0||o[r]===void 0)return t(a);const s=u.getStableKey(o[r]),i=n[s];return i!==void 0?i(a,o):t(a)}},V=e=>{switch(e.valueFormat.type){case"currency":return Xa(e);case"date":return Jd(e);case"datetime":return em(e);case"day_month":return Qa(e);case"decimal":return mn(e);case"duration":return pn();case"integer":return qa(e);case"month":return Za(e);case"month_year":return yn(e);case"percentage":return ja(e);case"quarter":return gn();case"text":return dn();case"weekly_date_range":return Ja(e);case"weekly_date_range_with_year":return eo(e);case"year":return bn(e);case"time":return to(e);case"lookup":return Vm({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new Error(`Unhandled value format: ${t.type}`)}}},Ft={abbreviation:"none",decimals:"auto"},ao=({locale:e,kind:t,startValue:n,endValue:r})=>{if(n===null||r===null)return za;switch(t){case"absolute-difference":return mn({locale:e,numberFormat:Ft,intlOptions:{signDisplay:"always"}})(r-n);case"relative-difference":{const a=r-n;if(a===0)return"0%";const o=a/n;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":V({valueFormat:{type:"percentage"},locale:e,numberFormat:Ft,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(r-n===0)return"=";const a=r/n;return a===Number.POSITIVE_INFINITY?"∞":a===Number.NEGATIVE_INFINITY?"-∞":`${V({valueFormat:{type:"decimal"},locale:e,numberFormat:Ft,intlOptions:{maximumFractionDigits:1}})(a)}x`}}},Lm=e=>{const t=e.padding??0,n=xr(e.rows,t),r=xr(e.cols,t);return{rows:n.tracks,cols:r.tracks,placements:km(e.placements,n.nameToIndex,r.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Em=e=>{const t=Ar(e.rows,e.height),n=Ar(e.cols,e.width),r=vr(t),a=vr(n),o=new Map;for(const s of e.placements){const i=s.rowSpan??1,c=s.colSpan??1,l=a[s.col]??0,d=r[s.row]??0,m=Tr(n,s.col,c),p=Tr(t,s.row,i);o.set(s.name,{x:l,y:d,width:Math.max(0,m),height:Math.max(0,p)})}return o},xr=(e,t)=>{const n=[],r=new Map;t>0&&n.push({type:"fixed",pixels:t});for(let a=0;a<e.length;a++){const o=e[a];if(!o)continue;r.set(o.name,n.length),n.push(Mm(o));const s=Dm(e,a);if(oo(o)&&s){const i=o.gaps?.after??0,c=s.gaps?.before??0,l=Math.max(i,c);l>0&&n.push({type:"fixed",pixels:l})}}return t>0&&n.push({type:"fixed",pixels:t}),{tracks:n,nameToIndex:r}},Mm=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},oo=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Dm=(e,t)=>{for(let n=t+1;n<e.length;n++){const r=e[n];if(r&&oo(r))return r}},km=(e,t,n)=>{const r=[];for(const a of e){const o=t.get(a.row),s=n.get(a.col);if(o===void 0||s===void 0)continue;const i=a.rowEnd!==void 0?t.get(a.rowEnd):o,c=a.colEnd!==void 0?n.get(a.colEnd):s;i===void 0||c===void 0||r.push({name:a.name,row:o,col:s,rowSpan:Math.max(1,i-o+1),colSpan:Math.max(1,c-s+1)})}return r},Ar=(e,t)=>{let n=0,r=0;for(const o of e)o.type==="fixed"?n+=o.pixels:r+=o.weight;const a=Math.max(0,t-n);return e.map(o=>o.type==="fixed"?o.pixels:r===0?0:o.weight/r*a)},vr=e=>{const t=new Array(e.length);let n=0;for(let r=0;r<e.length;r++)t[r]=n,n+=e[r]??0;return t},Tr=(e,t,n)=>{let r=0;const a=Math.min(t+n,e.length);for(let o=t;o<a;o++)r+=e[o]??0;return r},so=24,H={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:16,before:0},topAxisLabel:{after:4,before:0},topAxis:{after:0,before:0},panel:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},qe={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},panel:{after:4,before:0},rightAxis:{after:10,before:0}},Tn={top:0,right:0,bottom:0,left:0},Rm=(e,t,n,r=Tn)=>{const o=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return Lm({rows:[{name:"header",size:t.headerSize.height,gaps:H.header},{name:"topLegend",size:n.legends.top,gaps:H.topLegend},{name:"headline",size:n.headline,gaps:H.headline},{name:"topAxisLabel",size:o,gaps:H.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:H.topAxis},{name:"topAnnotation",size:r.top},{name:"panel",size:{flex:1},gaps:H.panel},{name:"bottomAxis",size:n.axes.bottom,gaps:H.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:H.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:H.bottomLegend},{name:"footer",size:t.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:qe.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:qe.leftAxis},{name:"panel",size:{flex:1},gaps:qe.panel},{name:"rightAnnotation",size:r.right},{name:"rightAxis",size:n.axes.right,gaps:qe.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panel",row:"panel",col:"panel"},...Cm(n.axes),..._m(n.axesLabels,n.axes),...Nm(n.legends)],containerSize:e,padding:so})},Cm=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},_m=(e,t)=>{const n=[];return e.top>0||t.top>0?(e.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},Nm=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},Om=({annotations:e,mainAxis:t,panelRect:n,textScale:r,locale:a,measureLabel:o,currentOverflow:s})=>{if(e.differenceArrows.length===0)return Tn;const i=t==="y",c=n.height+s.top,l=n.width+s.right;let d=0,m=0;for(const p of e.differenceArrows){const{start:f,end:h,size:y,label:g}=p;if(!Ir(f.x,f.y)||!Ir(h.x,h.y))continue;const S=vn(y,r),b=S.offsetFromHigherObservation+S.arrowheadSize+S.arrowEndGap,x=ao({locale:a,kind:g,startValue:f.measurementValue,endValue:h.measurementValue}),T=o(x,y);if(i){const L=Math.max(f.x,h.x),P=b+T.width/2+S.labelPaddingX;m=Math.max(m,wr(P,L,l))}else{const L=Math.max(f.y,h.y),P=b+S.labelLineHeight/2+S.labelPaddingY;d=Math.max(d,wr(P,L,c))}}return{top:Math.ceil(d),right:Math.ceil(m),bottom:0,left:0}},Ir=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,wr=(e,t,n)=>{if(t<=0)return 0;const r=(e-(1-t)*n)/t;return Math.max(0,r)},Fm=["top","right","bottom","left"],Pt=(e,t)=>{const n={};for(const r of Fm){const a=e.get(`${r}${t}`);a&&(n[r]=a)}return n},Kt=["large","medium","small"],Pm=({size:e,availableWidth:t,measureStripWidth:n})=>{if(e!=="auto")return e;for(const r of Kt)if(n(r)<=t)return r;return"small"},Bm=({size:e,availableWidth:t,measureStripWidth:n})=>{const r=e==="auto"?0:Kt.indexOf(e);for(const a of Kt.slice(r))if(n(a)<=t)return a;return null},Gm=({itemWidths:e,gap:t,availableWidth:n})=>{let r=0,a=0;for(const o of e){const s=a===0?o:r+t+o;if(s>n)break;r=s,a+=1}return a},Um=({headline:e,containerSize:t,measurer:n})=>{if(io(e))return 0;const r=co(e,t.width,n);return n.measureHeadline(e.formatted,r).height},$m=({headline:e,layout:t,containerSize:n,measurer:r,itemGap:a})=>{if(io(e)){const i=Ym(t.panel,e.innerRadius),c=Bm({size:e.size,availableWidth:i.width,measureStripWidth:lo(e,r)});return c===null?null:{rect:i,resolvedSize:c,visibleItemCount:1}}const o=co(e,n.width,r);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:o,visibleItemCount:1};const s=Gm({itemWidths:r.measureHeadlineItemWidths(e.formatted,o),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:o,visibleItemCount:s}},io=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Ym=(e,t)=>{const n=Math.min(e.width,e.height)/2,r=t*n*Math.SQRT2,a=e.x+e.width/2,o=e.y+e.height/2;return{x:a-r/2,y:o-r/2,width:r,height:r}},co=(e,t,n)=>Pm({size:e.size,availableWidth:t,measureStripWidth:lo(e,n)}),lo=(e,t)=>n=>t.measureHeadline(e.formatted,n).width,Me={x:0,y:0,width:0,height:0},Km="0000";class Hm{constructor(t){this.measurer=t}compile(t){const n=t.formattingLocale??t.parsingLocale,r=t.axes.filter(l=>l.geometry==="linear"),o=t.axes.filter(l=>l.geometry!=="linear").map(l=>zm(l,Er(l,n,t.numberFormat))),s=Xm(o,this.measurer.measureTickLabel),{formattedAxes:i,layout:c}=ut({axes:r,numberFormat:t.numberFormat,formattedLegends:t.formattedLegends,containerSize:t.containerSize,externalMeasurements:t.externalMeasurements,annotationOverflow:Tn,headline:t.headline,locale:n}).pipe(({axes:l,numberFormat:d,locale:m})=>({axisBundles:l.map(p=>({axis:p,resolveFormatter:Er(p,m,d),formatted:this.seedAxis(p)}))})).pipe(({axisBundles:l,formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h})=>({layout:this.resolveLayout({axes:l.map(y=>y.formatted),formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h,polarMargin:s})})).pipe(({axisBundles:l,layout:d})=>({axisBundles:l.map(m=>Vr(m.axis.position)?{...m,formatted:this.finalizeAxis(m.axis,m.resolveFormatter,d.panel)}:m)})).pipe(({axisBundles:l,formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h})=>({layout:this.resolveLayout({axes:l.map(y=>y.formatted),formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h,polarMargin:s})})).pipe(({axisBundles:l,layout:d})=>({formattedAxes:l.map(m=>Vr(m.axis.position)?m.formatted:this.finalizeAxis(m.axis,m.resolveFormatter,d.panel))})).pipe(({formattedAxes:l,formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h})=>({layout:this.resolveLayout({axes:l,formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:f,headline:h,polarMargin:s})})).pipe(({formattedAxes:l,formattedLegends:d,containerSize:m,externalMeasurements:p,layout:f,annotationOverflow:h,headline:y,locale:g})=>{const S=this.measureAnnotationOverflow(t,f.panel,g,h);return S===h?{formattedAxes:l,layout:f}:{formattedAxes:l,layout:this.resolveLayout({axes:l,formattedLegends:d,containerSize:m,externalMeasurements:p,annotationOverflow:S,headline:y,polarMargin:s})}}).result();return{formattedAxes:i,layout:c,formattedPolarAxes:o}}measureAnnotationOverflow(t,n,r,a){if(!t.annotations||t.annotations.differenceArrows.length===0||t.coordSystem?.type!=="cartesian")return a;const o=Om({annotations:t.annotations,mainAxis:t.coordSystem.mainAxis,panelRect:n,textScale:t.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel,currentOverflow:a});return o.top===a.top&&o.right===a.right?a:o}seedAxis(t){const{tickCandidates:n,...r}=t;return{...r,ticks:[{value:0,position:0,formattedLabel:Km}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(t,n,r){const o=t.position==="top"||t.position==="bottom"?r.width:r.height,s=Im({axis:t,availableSpacePx:o,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:i,...c}=t,l={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};if(t.scaleType==="discrete"&&t.bandwidth!==void 0){const d=t.bandwidth*o;return xm({formattedAxis:l,bandwidthPx:d,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:t,formattedLegends:n,containerSize:r,externalMeasurements:a,annotationOverflow:o,headline:s,polarMargin:i}){const c=this.measureGuides(t,n,s,r,i),l=Rm(r,a,c,o),d=Em(l);return{header:d.get("header")??Me,headline:d.get("headline")??Me,footer:d.get("footer")??Me,plot:d.get("plot")??Me,panel:d.get("panel")??Me,axes:Pt(d,"Axis"),axisLabels:Pt(d,"AxisLabel"),legends:Pt(d,"Legend")}}measureGuides(t,n,r,a,o){const s={...o},i={top:0,right:0,bottom:0,left:0};for(const l of t)l.isVisible&&(s[l.position]=this.measurer.measureAxis(l),l.label!==null&&(i[l.position]=this.measurer.measureAxisLabel(l)));const c={top:0,right:0,bottom:0,left:0};for(const l of n)c[l.position]=this.measurer.measureLegend(l);return{axes:s,axesLabels:i,legends:c,headline:this.measureHeadlineBand(r,a)}}measureHeadlineBand(t,n){return t===void 0?0:Um({headline:t,containerSize:n,measurer:this.measurer})}}const Vr=e=>e==="left"||e==="right",Lr=5,je=8,Wm=e=>{const[t,...n]=e.tickCandidates;if(t)return e.geometry==="circular"?t:n.reduce((r,a)=>Math.abs(a.ticks.length-Lr)<Math.abs(r.ticks.length-Lr)?a:r,t)},zm=(e,t)=>{const{tickCandidates:n,...r}=e,a=Wm(e);if(!a)return{...r,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=t(a),s=a.ticks.map(i=>({...i,formattedLabel:o(i.value)}));return{...r,ticks:s,labelRotation:0,labelMaxWidthPx:null}},Xm=(e,t)=>{const n=e.find(o=>o.geometry==="circular");if(!n||n.ticks.length===0)return{top:0,right:0,bottom:0,left:0};let r=0,a=0;for(const o of n.ticks){const s=t(o.formattedLabel);r=Math.max(r,s.width),a=Math.max(a,s.height)}return{top:a+je,bottom:a+je,left:r+je,right:r+je}},Er=(e,t,n)=>{const r=e.tickCandidates.flatMap(o=>o.ticks.map(s=>s.value)),a=new WeakMap;return o=>{const s=a.get(o);if(s)return s;const i=An({valueFormat:o.valueFormat??e.valueFormat,locale:t,numberFormat:n,tickValues:r});return a.set(o,i),i}};function qm(e,t,n,r){const a=new Map;if(!n||n.kind!=="visual"||n.domain.length<=1)return a;const o=new Map(t.map(s=>[s.id,s.swatchShape]));for(const s of e){if(s.geom!=="rule"||s.stat.type!=="mean")continue;const i=s.transforms.find(y=>y.transformType==="filter"&&y.options.operator==="eq"),c=u.extractVariableName(s.mapping.y);let l,d,m;if(i?.transformType==="filter"&&typeof i.options.value=="string")l="color",d=i.options.variableName,m=i.options.value;else if(c!==null)l="y",d=c,m=c;else continue;const p=jm(e,l,d);if(p===null)continue;const f=o.get(p.id);if(f===void 0)continue;const h=n.map(m);Pe(h)&&a.set(s.id,{shape:Ne(f,r),color:h})}return a}function jm(e,t,n){let r=null;for(const a of e)if(a.geom!=="rule"&&(r===null&&(r=a),u.extractVariableName(a.mapping[t])===n))return a;return r}function Oe(e,t){return e==="x"?t.x:t.y}function bt(e,t){return e==="x"?t.y:t.x}function Qm(e,t){return{main:Oe(e,t),cross:bt(e,t)}}function Zm(e){return e.type==="cartesian"}const In=12,Jm=4,ep=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=$(n)??z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=r*e.panelRect.width,l=(1-a)*e.panelRect.height-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:c,y:l,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},tp={place:ep,getPercentageValueStrategy:e=>e.position==="fill"?"fill":O(e.position)?"stack":"none"},Bt=4,Qe=6,np=e=>{const t=[],n=O(e.layer.position),r=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:o}=ap({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:r,getObservationKey:e.getObservationKey});for(const s of a){const i=cp({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,labelWidth:s.labelWidth,labelHeight:s.labelHeight,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height});i!==null&&t.push({layerId:e.layer.id,key:s.key,x:i.x,y:i.y,text:s.text,width:s.labelWidth,height:s.labelHeight,isRotated:i.isRotated,target:"observation",position:i.position})}}if(e.layer.dataLabels.showStackTotals){const a=mp({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of a)t.push(o)}return t},rp={place:np,getPercentageValueStrategy:e=>e.position==="fill"?"fill":O(e.position)?"stack":"absoluteGrandTotal"},ap=({layer:e,mainAxis:t,panelRect:n,measureDataLabel:r,formatLabel:a,isFlipped:o,getObservationKey:s})=>{const i=[];let c=!1;const l=u.extractVariableName(e.mapping.y);for(const d of e.data){const m=op(t,d);if(m===null)continue;const p=a(d);if(p==="")continue;const{width:f,height:h}=r("dataLabel",p),y=uo(m,n);f>y.width&&(c=!0);const g=l===null?null:d[l],S=I(g)&&g<0;i.push({key:s(d),isNegative:S,text:p,labelWidth:f,labelHeight:h,bounds:y})}return{entries:i,shouldRotate:!o&&c}},uo=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),mo=(e,t,n,r,a)=>{if(e==="x"){let i=1-a,c=a-r;return c<0&&(i+=c,c=-c),{x:t,y:i,width:n-t,height:c}}let o=t,s=n-t;return s<0&&(o+=s,s=-s),{x:o,y:1-a,width:s,height:a-r}},op=(e,t)=>{const n=_e(t),r=ye(t),a=se(t),o=$(t)??z(t);return n===null||r===null||a===null||o===null?null:mo(e,n,r,a,o)},sp=(e,t)=>{const{xMin:n,xMax:r,yMin:a,yMax:o}=t.anchor;return mo(e,n,r,a,o)},ip=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",po=(e,t,n)=>n?{width:t,height:e}:{width:e,height:t},cp=e=>e.isStacked?lp({bounds:e.bounds,labelWidth:e.labelWidth,labelHeight:e.labelHeight,isRotated:e.shouldRotate}):dp({edge:ip(e.mainAxis,e.isNegativeBar),bounds:e.bounds,labelWidth:e.labelWidth,labelHeight:e.labelHeight,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight}),lp=({bounds:e,labelWidth:t,labelHeight:n,isRotated:r})=>{const a=po(t,n,r);return a.width>e.width||a.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},up=(e,t,n,r)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:r};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:r};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:n};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:n}}},dp=({edge:e,bounds:t,labelWidth:n,labelHeight:r,isRotated:a,panelWidth:o,panelHeight:s})=>{const i=e==="top"||e==="bottom",c=t.x+t.width/2,l=t.y+t.height/2,d=po(n,r,a),m=i?d.height:d.width,p=i?d.width:d.height,f=i?t.height:t.width,h=i?t.width:t.height,y=m/2,{edgeCoord:g,outwardSign:S,panelExtent:b}=up(e,t,o,s);if(m+Bt<f){if(p>h)return null;if(a)return{x:c,y:l,isRotated:!0,position:"inside"};const T=g-S*(y+Bt);return{...i?{x:c,y:T}:{x:T,y:l},isRotated:!1,position:"inside"}}const x=g+S*(y+Bt);return x-y<0||x+y>b?null:{...i?{x:c,y:x}:{x,y:l},isRotated:a,position:"outside"}},mp=({layer:e,mainAxis:t,panelRect:n,measureDataLabel:r,formatAbsolute:a})=>{const o=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return o;const i=t==="y";for(const c of s){const l=uo(sp(t,c),n),d=a(c.total),{width:m,height:p}=r("stackTotal",d),f=c.anchor.direction==="positive";let h,y;i?(h=f?l.x+l.width+Qe+m/2:l.x-Qe-m/2,y=l.y+l.height/2):(h=l.x+l.width/2,y=f?l.y-Qe-p/2:l.y+l.height+Qe+p/2),o.push({layerId:e.id,key:`${e.id}:stack:${c.xKey}`,x:h,y,text:d,width:m,height:p,isRotated:!1,target:"aggregate",position:"outside"})}return o},pp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=r*e.panelRect.width,l=(1-a)*e.panelRect.height-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:c,y:l,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},fp={place:pp,getPercentageValueStrategy:()=>"none"},hp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=(Ur(n)??e.layer.params.size)/2,l=r*e.panelRect.width,d=(1-a)*e.panelRect.height-c-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:l,y:d,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},yp={place:hp,getPercentageValueStrategy:()=>"none"};function fo(e){return{startAngle:e[u.POSITION_VARIABLES.xMin],endAngle:e[u.POSITION_VARIABLES.xMax]}}function ho(e){return{innerRadius:e[u.POSITION_VARIABLES.yMin],outerRadius:e[u.POSITION_VARIABLES.yMax]??e[u.POSITION_VARIABLES.y]}}const gp=" · ",bp=e=>typeof e=="string"?e:e instanceof Date?e.toISOString():String(e),Sp=(e,t)=>{const n=u.extractVariableName(t.x);return n!==null&&n!==u.CONSTANT_VARIABLES.x?tn(e,t):a=>be(a)},xp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const n=e.layer.dataLabels.showCategoryLabels?Sp(e.layer.data,e.layer.mapping):null,r=e.panelRect.width/2,a=e.panelRect.height/2,o=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const s of e.layer.data){const{startAngle:i,endAngle:c}=fo(s),{outerRadius:l}=ho(s);if(i===null||c===null||l===null)continue;const d=e.formatLabel(s);if(d==="")continue;const m=n===null?null:n(s),p=m===null?d:`${bp(m)}${gp}${d}`,{width:f,height:h}=e.measureDataLabel("dataLabel",p),y=(i+c)/2,g=Math.abs(Math.sin(y))*(f/2)+Math.abs(Math.cos(y))*(h/2),S=l*o+Jm+g,b=r+Math.sin(y)*S,x=a-Math.cos(y)*S,T=f/2,L=h/2;b-T<0||b+T>e.panelRect.width||x-L<0||x+L>e.panelRect.height||t.push({layerId:e.layer.id,key:e.getObservationKey(s),x:b,y:x,text:p,width:f,height:h,isRotated:!1,target:"observation",position:"outside"})}return t},Ap={place:xp,getPercentageValueStrategy:()=>"absoluteGrandTotal"},vp={type:"decimal"};function yo({layer:e,numberFormat:t,locale:n}){const r=u.extractVariableName(e.mapping.y),a=r!==null&&e.data.hasVariable(r)?e.data.getValueFormat(r):vp;return V({valueFormat:a,locale:n,numberFormat:t})}const Tp=({layer:e,coordSystem:t,axes:n,numberFormat:r,panelRect:a,measureDataLabel:o,formattingLocale:s,percentageValueStrategy:i})=>{const c=yo({layer:e,numberFormat:r,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:o,formatLabel:Ep({layer:e,numberFormat:r,axes:n,locale:s,absoluteFormatter:c,percentageValueStrategy:i}),formatAbsolute:c,getObservationKey:Ip(e)}},Ip=e=>t=>`${e.id}:${ht(t)}`,wp=(e,t)=>{switch(t){case"stack":return Vp(e);case"fill":return Lp(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Vp=e=>{const t=u.extractVariableName(e.mapping.x);let n=null,r=!1;return a=>{const o=e.summary.stackTotals;if(o===void 0||o.length===0||t===null)return null;if(!r){n=new Map;for(const c of o)n.set(c.xKey,c);r=!0}const s=a[t];if(s==null)return null;const i=n?.get(en(a,t));return i===void 0?null:i.total}},Lp=e=>{const t=nn(e);return n=>{const r=se(n),a=$(n);if(!I(r)||!I(a))return null;const o=Math.abs(a-r);if(o===0)return null;const s=t(n);return I(s)?s/o:null}},Ep=({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a,percentageValueStrategy:o})=>{const s=F(e.data,e.dataLabels.labelSource),i=wp(e,o),c=Mp({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a}),l=V({valueFormat:{type:"percentage"},locale:r,numberFormat:t}),d=e.dataLabels.format==="percentage"&&go(e);return m=>{const p=s(m);if(p===null)return"";if(!d||!I(p))return c(p,m);const f=i(m);return f===null||f===0?c(p,m):l(p/f)}},Mp=({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a})=>{const o=e.dataLabels.labelSource,s=u.extractVariableName(o);if(s!==null){if(go(e))return a;const i=Dp(e,n,t,r,s);if(i!==null)return i}return V({valueFormat:kp(e.data,o),locale:r,numberFormat:t})},go=e=>{const t=u.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===u.extractVariableName($e(e.position,e.mapping))},Dp=(e,t,n,r,a)=>{const o=u.extractVariableName(e.mapping.x);if(o===null||o!==a)return null;const s=t.find(i=>i.scaleAestheticKey==="x");return s===void 0?null:V({valueFormat:s.valueFormat,locale:r,numberFormat:n})},kp=(e,t)=>{const n=u.extractConstantValue(t);if(n!==void 0)return typeof n=="number"?{type:"decimal"}:Oo(n)?{type:"date"}:{type:"text"};const r=u.extractVariableName(t);return r===null||!e.hasVariable(r)?{type:"text"}:e.getValueFormat(r)},Rp={bar:{cartesian:rp,polar:Ap},line:{cartesian:fp},point:{cartesian:yp},area:{cartesian:tp}},Cp=({layers:e,coordSystem:t,axes:n,numberFormat:r,parsingLocale:a,panelRect:o,measureDataLabel:s,formattingLocale:i})=>{const c=[],l=i??a,d=t.type;for(const m of e){if(!m.dataLabels.showDataLabels&&!m.dataLabels.showStackTotals)continue;const p=Rp[m.geom]?.[d];if(p===void 0)continue;const f=Tp({layer:m,coordSystem:t,axes:n,numberFormat:r,panelRect:o,measureDataLabel:s,formattingLocale:l,percentageValueStrategy:p.getPercentageValueStrategy(m)}),h=p.place(f);for(const y of h)c.push(y)}return{labels:c}},_p=(e,t,n,r)=>{const a=r.offsetFromHigherObservation+r.arrowheadSize+r.arrowEndGap;return e?Math.max(t.x,n.x)+a:Math.min(t.y,n.y)-a},Np=(e,t,n,{arrowStartGap:r,arrowEndGap:a,curveRadius:o})=>{const s={x:e.x,y:e.y-r},i={x:e.x,y:n},c={x:t.x,y:n},l={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
|
|
3
|
+
${n}`),this.issues=t,this.name="SpecValidationError",console.warn(`Spec validation failed:
|
|
4
|
+
${n}`)}}class Cc{constructor(t,n){this.transformCompiler=t,this.validator=n}check(t){const n=[];for(const r of t.layers){const a=this.transformCompiler.compile({data:t.data,transforms:r.transforms}),o={...t.mapping,...r.mapping};n.push(...this.validator.validate({layerId:r.id,geom:r.geom,stat:r.stat,effectiveMapping:o,data:a,coordType:t.coords.coordType}))}if(n.length>0)throw new La(n)}}class _c{constructor(t,n){this.geomRegistry=t,this.statRegistry=n}validate(t){return[...this.validateRequiredAesthetics(t),...this.validateVariableExistence(t),...this.validateGeomMapping(t),...this.validateCoordSupport(t)]}validateRequiredAesthetics({layerId:t,geom:n,stat:r,effectiveMapping:a}){const o=[],{requiredAesthetics:s}=this.geomRegistry.get(n),{computedVariables:i}=this.statRegistry.get(r.type);for(const c of s)i.has(c)||u.isDefined(u.readAesthetic(a,c))||o.push({code:"MISSING_AESTHETIC",message:`Layer '${t}': geom '${n}' requires aesthetic '${c}'`,layerId:t,aesthetic:c});return o}validateVariableExistence({layerId:t,stat:n,effectiveMapping:r,data:a}){const o=[],{computedVariables:s}=this.statRegistry.get(n.type);for(const[i,c]of Object.entries(r)){if(s.has(i))continue;const l=u.extractVariableName(c);l!==null&&(a.hasVariable(l)||o.push({code:"UNKNOWN_VARIABLE",message:`Layer '${t}': aesthetic '${i}' references variable '${l}' which does not exist in the dataset`,layerId:t,aesthetic:i}))}return o}validateGeomMapping({layerId:t,geom:n,stat:r,effectiveMapping:a}){const o=this.geomRegistry.get(n);if(o.validateMapping===void 0)return[];const{computedVariables:s}=this.statRegistry.get(r.type);return o.validateMapping({layerId:t,mapping:a,computedVariables:s})}validateCoordSupport({layerId:t,geom:n,coordType:r}){const{supportedCoordTypes:a}=this.geomRegistry.get(n);return a.includes(r)?[]:[{code:"UNSUPPORTED_COORD",message:`Layer '${t}': geom '${n}' is not supported under '${r}' coords`,layerId:t}]}}const rr=u.prefixInternalVariable("__ungrouped__"),Nc=(e,t)=>t===null?!0:e.some(n=>n.axis===t.axis&&n.role===t.role&&n.valueKind===t.valueKind),Ea=(e,t,n="y")=>{const r=n==="y"?"x":"y",a=u.extractVariableName(t[n]),o=u.extractVariableName(t[r]);if(!a||!o)return null;const s=e.getValues(u.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0}),i=s.length===0,c=i?[rr]:s,l=e.getValues(o),d=e.getValues(a,{type:"numeric"}),m=e.getValues(u.GROUP_VARIABLES.group,{type:"categorical"}),p=e.size(),f=new Map;for(let h=0;h<p;h++){const y=l[h]??null,g=m[h],S=i?rr:g;if(!u.isDefined(S))continue;let b=f.get(y);b||(b=new Map,f.set(y,b)),b.set(S,h)}return{values:d,observationIndexByPartitionAndGroup:f,uniqueGroupKeys:c,observationCount:p}};class Oc{constructor(t){this.registry=t}adjust(t,n,r){const a=this.registry.get(t),o=a.getConsumedChannel(r.axis??"y");return Nc(n,o)?a.adjust(r):{data:r.data,mapping:{}}}}class yt{getConsumedChannel(t){return null}}class Fc extends yt{constructor(){super(...arguments),this.type="dodge"}getConsumedChannel(t){return{axis:"x",role:"point",valueKind:"value"}}adjust({data:t,mapping:n}){if(!u.extractVariableName(n.x))return{data:t,mapping:{}};const a=t.getValues(u.GROUP_VARIABLES.group,{type:"categorical",distinct:!0,skipNulls:!0});if(a.length===0)return{data:t,mapping:{}};const o=t.size(),s=t.getValues(u.GROUP_VARIABLES.group,{type:"categorical"}),i=la/2,c=a.length>1?Ws:0,l=q.scaleBand().domain(a.map(String)).range([-i,i]).paddingInner(c).paddingOuter(0),d=l.bandwidth(),m=new Array(o).fill(null),p=new Array(o).fill(null);for(let h=0;h<o;h++){const y=s[h];if(!u.isDefined(y))continue;const g=l(String(y));u.isDefined(g)&&(m[h]=g,p[h]=g+d)}return{data:t.addVariable(u.POSITION_VARIABLES.xMin,"numeric",m).addVariable(u.POSITION_VARIABLES.xMax,"numeric",p),mapping:{}}}}class Pc extends yt{constructor(){super(...arguments),this.type="fill"}getConsumedChannel(t){return{axis:t,role:"point",valueKind:"value"}}adjust({data:t,mapping:n,axis:r="y"}){const a=Ea(t,n,r);if(a===null)return{data:t,mapping:{}};const{values:o,observationIndexByPartitionAndGroup:s,uniqueGroupKeys:i,observationCount:c}=a,l=[...o],d=new Array(c).fill(0);for(const[,p]of s){let f=0,h=0;for(const S of i){const b=p.get(S);if(b===void 0)continue;const x=o[b];x!=null&&(x>=0?f+=x:h-=x)}let y=0,g=0;for(const S of i){const b=p.get(S);if(b===void 0)continue;const x=o[b];if(x===void 0)continue;if(x===null){d[b]=null,l[b]=null;continue}const T=x>=0?f:h;if(T===0){d[b]=0,l[b]=0;continue}const L=x/T;x>=0?(d[b]=y,l[b]=y+=L):(l[b]=g,d[b]=g+=L)}}let m=t.addVariable(u.variableFor(r,"lower"),"numeric",d).addVariable(u.variableFor(r,"upper"),"numeric",l);return r==="y"&&(m=m.addVariable(u.POSITION_VARIABLES.yRaw,"numeric",o)),{data:m,mapping:{}}}}class Bc extends yt{constructor(){super(...arguments),this.type="identity"}adjust({data:t}){return{data:t,mapping:{}}}}class Gc extends yt{constructor(){super(...arguments),this.type="stack"}getConsumedChannel(t){return{axis:t,role:"point",valueKind:"value"}}adjust({data:t,mapping:n,axis:r="y"}){const a=Ea(t,n,r);if(a===null)return{data:t,mapping:{}};const{values:o,observationIndexByPartitionAndGroup:s,uniqueGroupKeys:i,observationCount:c}=a,l=[...o],d=new Array(c).fill(0);for(const[,f]of s){let h=0,y=0;for(const g of i){const S=f.get(g);if(S===void 0)continue;const b=o[S];if(b!==void 0){if(b===null){d[S]=null,l[S]=null;continue}b>=0?(d[S]=h,l[S]=h+=b):(l[S]=y,d[S]=y+=b)}}}let m=t.addVariable(u.variableFor(r,"lower"),"numeric",d).addVariable(u.variableFor(r,"upper"),"numeric",l);r==="y"&&(m=m.addVariable(u.POSITION_VARIABLES.yRaw,"numeric",o));const p=u.extractVariableName(n[r]);return p!==null&&(m=m.addVariable(p,"numeric",l)),{data:m,mapping:{}}}}class Uc extends xe{constructor(){super("position"),this.register("identity",new Bc),this.register("stack",new Gc),this.register("fill",new Pc),this.register("dodge",new Fc)}}function $c(e){let t=e.data;for(const n of e.channels)n.role==="point"&&(t=Yc(n.axis,t,e));for(const n of Hc(e.channels))t=Wc(n,t,e);for(const n of e.channels)n.role==="scalar"&&(t=Kc(n,t,e));return t}function rn(e,t){return e==="x"?"x":Ue(t)}function Yc(e,t,n){const r=u.extractVariableName(n.mapping[e]),a=n.getPositionScale(rn(e,n.yScaleType));if(!r||!a)return t;const s=t.getValues(r).map(i=>u.isDefined(i)?a.map(i):null);return t.addVariable(u.variableFor(e,"point"),"numeric",s)}function Kc(e,t,n){const r=n.getPositionScale(rn(e.axis,n.yScaleType)),o=(e.aes?u.extractVariableName(u.readAesthetic(n.mapping,e.aes)):null)??u.variableFor(e.axis,e.name);if(!r||!t.hasVariable(o))return t;const i=t.getValues(o,{type:"numeric"}).map(c=>u.isDefined(c)?r.map(c):null);return t.addVariable(u.variableFor(e.axis,e.name),"numeric",i)}function Hc(e){const t=new Map;for(const n of e){if(n.role==="point"||n.role==="scalar")continue;const r=`${n.axis}:${n.valueKind}`,a=t.get(r)??{axis:n.axis,valueKind:n.valueKind,hasLower:!1,hasUpper:!1};n.role==="lower"&&(a.hasLower=!0),n.role==="upper"&&(a.hasUpper=!0),t.set(r,a)}return[...t.values()].filter(n=>n.hasLower&&n.hasUpper).map(({axis:n,valueKind:r})=>({axis:n,valueKind:r}))}function Wc(e,t,n){const r=n.getPositionScale(rn(e.axis,n.yScaleType));if(!r)return t;const a=u.variableFor(e.axis,"lower"),o=u.variableFor(e.axis,"upper");return!t.hasVariable(a)||!t.hasVariable(o)?t:e.valueKind==="value"?zc(t,r,a,o):Xc(e.axis,t,r,a,o)}function zc(e,t,n,r){const a=e.getValues(n,{type:"numeric"}),o=e.getValues(r,{type:"numeric"}),s=e.size(),i=new Array(s),c=new Array(s);for(let l=0;l<s;l++){const d=a[l],m=o[l];u.isDefined(d)&&u.isDefined(m)?(i[l]=t.map(d),c[l]=t.map(m)):(i[l]=null,c[l]=null)}return e.addVariable(n,"numeric",i).addVariable(r,"numeric",c)}function Xc(e,t,n,r,a){const o=u.variableFor(e,"point");if(!n.bandwidth||!t.hasVariable(o))return t;const s=n.bandwidth,i=t.getValues(o,{type:"numeric"}),c=t.getValues(r,{type:"numeric"}),l=t.getValues(a,{type:"numeric"}),d=t.size(),m=new Array(d),p=new Array(d);for(let f=0;f<d;f++){const h=i[f],y=c[f],g=l[f];u.isDefined(h)&&u.isDefined(y)&&u.isDefined(g)?(m[f]=h+y*s,p[f]=h+g*s):(m[f]=null,p[f]=null)}return t.addVariable(r,"numeric",m).addVariable(a,"numeric",p)}function qc(e,t){const n=e[t];return n?.kind==="position"?n:null}class jc extends Se{constructor(t){super(),this.geomRegistry=t}dependencies(t){return[t.scales.x,t.scales.y,t.scales.ySecondary]}compileLayer(t,n){const r=this.geomRegistry.get(t.geom),a=$c({channels:r.positionChannels,data:t.data,mapping:t.mapping,yScaleType:t.yScaleType,getPositionScale:o=>qc(n.scales,o)});return{...t,data:a}}}class Qc extends j{constructor(t){super(),this.registry=t}dependencies(t){return[t.layers,t.scales]}run(t){this.validateScaleTypeCompatibility(t);const n=new Map;for(const o of t.scales)n.set(o.scaledAesthetic,o);const r=this.collectValues(t.layers,n),a={};for(const[o,s]of n){const i=r.get(o)??[],c=this.registry.get(s.scaleType);a[o]=c.compile(s,i)}return a}validateScaleTypeCompatibility(t){const n=[];for(const r of t.scales){const{compatibleDataTypes:a}=this.registry.get(r.scaleType),o=Y(r.scaledAesthetic),s=t.layers.find(l=>u.isDefined(l.mapping[o]));if(!s)continue;const i=u.extractVariableName(s.mapping[o]);if(!u.isDefined(i)||!s.data.hasVariable(i))continue;const c=s.data.getType(i);if(a.includes(c)||n.push({code:"INCOMPATIBLE_TYPE",message:`Scale '${r.scaledAesthetic}' (${r.scaleType}) is incompatible with variable '${i}' (${c})`,aesthetic:o}),r.scaledAesthetic==="lineType"&&c!=="categorical"){const l=c==="temporal"?"Bucket the variable into categorical periods (e.g. quarter, year) first.":"Bin the variable into categorical buckets first.";n.push({code:"INCOMPATIBLE_TYPE",message:`Scale 'lineType' is discrete-only and cannot be mapped to ${c} variable '${i}'. ${l}`,aesthetic:o})}}if(n.length>0)throw new La(n)}collectValues(t,n){const r=new Map;for(const a of t)for(const[o,s]of Object.entries(a.mapping)){const i=o,c=i==="y"?Ue(a.yScaleType):i;if(!ei(c)||!n.has(c))continue;const l=this.resolveVariables(i,s,a.data);this.collectFromVariables(a.data,l,c,r)}return r}resolveVariables(t,n,r){if(t==="y"&&this.hasPositionAdjustedY(r))return[u.POSITION_VARIABLES.yMin,u.POSITION_VARIABLES.yMax];const a=u.extractVariableName(n);return!a||!r.hasVariable(a)?[]:[a]}hasPositionAdjustedY(t){return t.hasVariable(u.POSITION_VARIABLES.yMin)&&t.hasVariable(u.POSITION_VARIABLES.yMax)}collectFromVariables(t,n,r,a){if(n.length===0)return;let o=[];for(const i of n)o=o.concat(t.getValues(i));const s=a.get(r);a.set(r,s?s.concat(o):o)}}class Ye{createPositionScale(t,n){return{kind:"position",aesthetic:Y(t.scaledAesthetic),spec:t,...n}}createVisualScale(t,n){return{kind:"visual",aesthetic:Y(t.scaledAesthetic),spec:t,...n}}}class Zc extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric"]}compile(t,n){if(t.scaleType!=="continuous")throw new Error("ContinuousScale.compile received non-continuous spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){let r=1/0,a=-1/0;for(const o of t)typeof o=="number"&&(o<r&&(r=o),o>a&&(a=o));return r===1/0?[0,0]:(n.zero&&(r>0&&(r=0),a<0&&(a=0)),[r,a])}createD3Scale(t,n,r){let a=[r.domainMin??t[0],r.domainMax??t[1]];const o=r.transform==="log"&&Jc(a),s=o?q.scaleLog():r.transform==="sqrt"?q.scaleSqrt():q.scaleLinear();return r.nice&&!o&&(a=s.copy().domain(a).nice().domain()),s.domain([r.domainMin??a[0],r.domainMax??a[1]]).range(n).clamp(r.clamp)}buildPositionScale(t,n){const r=n.reverse?[1,0]:[0,1],a=this.createD3Scale(t,r,n);return this.createPositionScale(n,{map:a,domain:a.domain(),bandwidth:null,generateTicks:o=>o&&"count"in o?a.ticks(o.count):a.ticks()})}buildVisualScale(t,n){const r=n.range??[0,1],a=n.reverse?[r[1],r[0]]:r,o=this.createD3Scale(t,a,n);return this.createVisualScale(n,{map:o,domain:o.domain(),generateTicks:s=>s&&"count"in s?o.ticks(s.count):o.ticks()})}}const Jc=e=>{const[t,n]=e;return t>0&&n>0||t<0&&n<0};class el extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["temporal"]}compile(t,n){if(t.scaleType!=="datetime")throw new Error("DatetimeScale.compile received non-datetime spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n);if(!r)throw new Error("Datetime scale is not supported for non-position aesthetics");return this.buildScale(a,t,this.collectInputDates(n))}collectInputDates(t){const n=new Set,r=[];for(const a of t){if(!(a instanceof Date))continue;const o=a.getTime();n.has(o)||(n.add(o),r.push(a))}return r.sort((a,o)=>a.getTime()-o.getTime()),r}computeDataDomain(t){let n=1/0,r=-1/0;for(const a of t){if(!(a instanceof Date))continue;const o=a.getTime();o<n&&(n=o),o>r&&(r=o)}return n===1/0?[]:[new Date(n),new Date(r)]}createD3Scale(t,n,r){const a=tl(t)?t:[],o=q.scaleUtc().domain(a).range(n).clamp(r.clamp);if(r.nice&&o.nice(),u.isDefined(r.domainMin)||u.isDefined(r.domainMax)){const[s,i]=o.domain();s!==void 0&&i!==void 0&&o.domain([r.domainMin??s,r.domainMax??i])}return o}buildScale(t,n,r){const a=n.reverse?[1,0]:[0,1],o=this.createD3Scale(t,a,n),[s,i]=o.domain(),c=s&&i?r.filter(l=>l>=s&&l<=i):[];return this.createPositionScale(n,{map:o,domain:o.domain(),bandwidth:null,generateTicks:l=>l&&"atInputs"in l?c:l&&"interval"in l?s&&i?ii(s,i,l.interval):[]:o.ticks(l?.count)})}}const tl=e=>e.length===2&&R(e[0])&&R(e[1]),pe={transform:"linear",reverse:!1,nice:!0,zero:!1,domainMin:null,domainMax:null},ar={size:[4,20],alpha:[.1,1],strokeWidth:[1,4]},We={domainMin:null,domainMax:null,nice:!1,reverse:!1},De={range:null,domain:null,padding:.1,reverse:!1},nl={palette:{type:"default"}};class rl extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","numeric","temporal"]}compile(t,n){if(t.scaleType!=="discrete")throw new Error("DiscreteScale.compile received non-discrete spec");const r=ft(t.scaledAesthetic),a=this.computeDataDomain(n,t);return r?this.buildPositionScale(a,t):this.buildVisualScale(a,t)}computeDataDomain(t,n){if(n.domain!==null&&n.domain.length>0)return[...n.domain];const r=new Set,a=[];for(const o of t)r.has(o)||(r.add(o),a.push(o));return a}buildPositionScale(t,n){const r=t.map(String),a=n.padding??De.padding,o=n.reverse?[1,0]:[0,1],s=q.scaleBand().domain(r).range(o).paddingInner(a).paddingOuter(a/2),i=s.bandwidth()/2;return this.createPositionScale(n,{map:c=>(s(String(c))??0)+i,domain:t,bandwidth:s.bandwidth(),generateTicks:()=>[...t]})}buildVisualScale(t,n){const r=t.map(String),a=n.range&&n.range.length>0?q.scaleOrdinal().domain(r).range(n.range).unknown(n.range[0]):null;return this.createVisualScale(n,{map:o=>{const s=String(o);return a?a(s):s},domain:t,generateTicks:()=>t})}}class al extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["numeric","categorical","temporal"]}compile(t){if(t.scaleType!=="identity")throw new Error("IdentityScale.compile received non-identity spec");return{kind:"identity",aesthetic:Y(t.scaledAesthetic),spec:t,map:n=>n,domain:[],generateTicks:()=>[]}}}const Ma=["grey","red","orange","yellow","green","cyan","blue","purple","pink"],Da=["cyan","pink","purple","red","orange","yellow","green","blue"],an=["#B399FE","#FC7E91","#33B6E0","#FFC849","#25CDA5","#FA9B65","#D93C95","#845FD8","#3F8EEB","#58C8D8","#F35074","#6EA0DA"],B={red:"#E83562",orange:"#F38650",yellow:"#FBBC30",green:"#31FCB4",cyan:"#40F8FF",blue:"#279EFF",purple:"#B399FD",dark_purple:"#6D48D2",plum:"#C82184",pink:"#FC8497"},ol=[B.purple,B.pink,B.yellow,B.blue,B.red,B.cyan,B.orange,B.plum,B.green,B.dark_purple],N={green:"#B2DDC9",cyan:"#A2D5E2",blue:"#AAC4FF",purple:"#B2A4FF",plum:"#DCA8C7",pink:"#FFCCD3",red:"#FFADAD",orange:"#FFDEB4",yellow:"#FDF7C3"},sl=[N.green,N.purple,N.red,N.cyan,N.pink,N.blue,N.orange,N.plum,N.yellow],Ut={grey900:"#1c1917",grey800:"#292524",grey700:"#44403c",grey600:"#57534e",grey500:"#78716c",grey400:"#a8a29e",grey300:"#d6d3d1",grey200:"#e7e5e4",grey100:"#f5f5f4",grey50:"#fafaf9",red900:"#7f1d1d",red800:"#991b1b",red700:"#b91c1c",red600:"#dc2626",red500:"#ef4444",red400:"#f87171",red300:"#fca5a5",red200:"#fecaca",red100:"#fee2e2",red50:"#fef2f2",orange900:"#7c2d12",orange800:"#9a3412",orange700:"#c2410c",orange600:"#ea580c",orange500:"#f97316",orange400:"#fb923c",orange300:"#fdba74",orange200:"#fed7aa",orange100:"#ffedd5",orange50:"#fff7ed",yellow900:"#553B0C",yellow800:"#6F4B08",yellow700:"#8D6300",yellow600:"#BD8A00",yellow500:"#E5B400",yellow400:"#FFC800",yellow300:"#FBDA2B",yellow200:"#FEED72",yellow100:"#FEF8B4",yellow50:"#FEFCE2",green900:"#064e3b",green800:"#065f46",green700:"#047857",green600:"#059669",green500:"#10b981",green400:"#34d399",green300:"#6ee7b7",green200:"#a7f3d0",green100:"#d1fae5",green50:"#ecfdf5",cyan900:"#164e63",cyan800:"#155e75",cyan700:"#0e7490",cyan600:"#0891B2",cyan500:"#06b6d4",cyan400:"#22d3ee",cyan300:"#67e8f9",cyan200:"#a5f3fc",cyan100:"#cffafe",cyan50:"#ecfeff",blue900:"#1e3a8a",blue800:"#1e40af",blue700:"#1d4ed8",blue600:"#2563eb",blue500:"#3b82f6",blue400:"#60a5fa",blue300:"#93c5fd",blue200:"#bfdbfe",blue100:"#dbeafe",blue50:"#eff6ff",purple900:"#4c1d95",purple800:"#5b21b6",purple700:"#6d28d9",purple600:"#7c3aed",purple500:"#8b5cf6",purple400:"#a78bfa",purple300:"#c4b5fd",purple200:"#ddd6fe",purple100:"#ede9fe",purple50:"#f5f3ff",pink900:"#751A5E",pink800:"#8F1972",pink700:"#AF1C8A",pink600:"#D326A8",pink500:"#E845BF",pink400:"#F979D9",pink300:"#FCABE8",pink200:"#FED0F3",pink100:"#FFE8F9",pink50:"#FFF4FC"},il=[Ut.grey200,N.green,N.red,Ut.grey200],or={dark:{1:[500],2:[600,400],3:[600,400,200],4:[600,500,300,100],5:[700,600,400,200,50],6:[600,500,400,300,200,100],7:[600,500,400,300,200,100,50],default:[700,600,500,400,300,200,100,50]},light:{1:[600],2:[700,500],3:[800,600,400],4:[800,600,400,300],5:[800,700,600,500,400],6:[800,700,600,500,400,300],7:[900,800,700,600,500,400,300],default:[900,800,700,600,500,400,300,200]}},C={cyan:"#22D3EE",pink:"#F377EF",purple:"#6528F7",red:"#FB2576",orange:"#FF9300",yellow:"#FBFF00",green:"#06FF00",blue:"#0079FF"},ze=[C.cyan,C.pink,C.purple,C.red,C.orange,C.yellow,C.green,C.blue],cl=[C.cyan,C.green,C.red,C.cyan],Xe={start:"#84D1FC",positive:"#84FC89",negative:"#FC8497",total:"#84D1FC"},ll=[Xe.start,Xe.positive,Xe.negative,Xe.total];function ul(e,t="light",n){return((n!==void 0?or[t][n]:void 0)??or[t].default).map(a=>Ut[`${e}${a}`])}function dl(e){const t=ze.indexOf(C[e]);return t<=0?ze:[...ze.slice(t),...ze.slice(0,t)]}function ml(e,t){switch(e.type){case"default":return an;case"graphy":return e.variant==="waterfall"?ll:ol;case"pastel":return e.variant==="waterfall"?il:sl;case"neon":return e.variant==="waterfall"?cl:dl(e.base);case"mono":return ul(e.base,e.variant??"light",t);case"custom":return e.colors}}function pl(e,t){if(!e)return nl.palette;if(e.type==="custom"){const n=t[e.id];if(!n)throw new Error(`Custom palette with id "${e.id}" not found`);return{type:"custom",id:e.id,colors:n}}return e}class fl extends Ye{constructor(){super(...arguments),this.compatibleDataTypes=["categorical","temporal"]}compile(t,n){if(t.scaleType!=="palette")throw new Error("PaletteScale.compile received non-palette spec");const r=this.computeDomain(n),a=ml(t.palette,r.length),o=a.length>0?a:[...an],s=q.scaleOrdinal().domain(r.map(String)).range(o).unknown(o[0]);return this.createVisualScale(t,{map:i=>s(String(i)),domain:r,generateTicks:()=>r})}computeDomain(t){const n=new Set,r=[];for(const a of t)n.has(a)||(n.add(a),r.push(a));return r}}class hl extends xe{constructor(){super("scale"),this.register("continuous",new Zc),this.register("discrete",new rl),this.register("datetime",new el),this.register("identity",new al),this.register("palette",new fl)}}const ka=e=>!("layers"in e),w={point:yl,line:gl,area:bl,bar:Sl,rule:xl};function yl(e={}){return{type:"layer",geom:"point",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function gl(e={}){return{type:"layer",geom:"line",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function bl(e={}){return{type:"layer",geom:"area",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function Sl(e={}){return{type:"layer",geom:"bar",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}function xl(e={}){return{type:"layer",geom:"rule",mapping:e.aes,stat:e.stat,params:e.params,position:e.position,yScaleType:e.yScaleType,transforms:e.transforms,interactive:e.interactive,dataLabels:e.dataLabels}}const on={identity:vl,count:Tl,smooth:Al,mean:Il};function Al(e){return{type:"smooth",method:e.method,order:e.order,bandwidth:e.bandwidth}}function vl(){return{type:"identity"}}function Tl(){return{type:"count"}}function Il(){return{type:"mean"}}const re={reshape:wl,filter:Vl,sort:Ll,aggregate:El,constant:Ml};function wl(e={}){return{type:"transform",transformType:"reshape",options:e}}function Vl(e){return{type:"transform",transformType:"filter",options:e}}function Ll(e){return{type:"transform",transformType:"sort",options:e}}function El(e){return{type:"transform",transformType:"aggregate",options:e}}function Ml(e){return{type:"transform",transformType:"constant",options:e}}const sr="#%_ENCODED_%#",Ra=e=>{if(!e.startsWith(sr))return e;try{const{value:t}=JSON.parse(e.slice(sr.length));return typeof t=="string"?t:e}catch{return e}},Dl=({annotations:e,dataset:t,mapping:n})=>{const r=[],a=[],o=[],s=[],i=[],c=[],l=[],d=u.extractVariableName(n.x);for(const m of e??[])switch(m.type){case"difference-arrow":{const p=kl(m,d,t);p!==null&&r.push(p);break}case"shape":{a.push(Rl(m));break}case"arrow":{o.push(Ol(m));break}case"highlight":break;case"text":{s.push(Cl(m));break}case"sticker":{const p=_l(m,d,t);p!==null&&i.push(p);break}case"tooltip":{const p=Nl(m,d,t);if(p===null)break;p.kind==="pinnedNumber"?c.push(p.value):l.push(p.value);break}default:{const p=m;throw new Error(`Unsupported annotation type: ${p.type}`)}}return{differenceArrows:r,shapes:a,freeformArrows:o,textAnnotations:s,stickers:i,pinnedNumbers:c,comments:l}},kl=(e,t,n)=>{const r=it({dataset:n,input:e.start,anchorVariable:t}),a=it({dataset:n,input:e.end,anchorVariable:t});return r===null||a===null?null:{id:e.id,start:r,end:a,label:e.show,color:e.color??null,size:e.size,labelCrossPosition:e.labelPosition}},Rl=e=>({id:e.id,kind:e.shape,zOrder:e.layer==="abovePlot"?"foreground":"background",x:e.x,y:e.y,width:e.width,height:e.height,fillColor:e.fillColor,fillOpacity:e.fillOpacity,strokeWidth:e.strokeWidth,strokeColor:e.fillColor}),Cl=e=>({id:e.id,content:e.content,x:e.x,y:e.y,width:e.width,backgroundColor:e.backgroundColor??null,backgroundColorStyle:e.backgroundColorStyle}),_l=(e,t,n)=>{const r=it({dataset:n,input:e,anchorVariable:t});return r===null?null:{id:e.id,anchor:r,sticker:e.sticker}},Nl=(e,t,n)=>{const r=it({dataset:n,input:e,anchorVariable:t});return r===null?null:e.caption===null||e.caption===void 0?{kind:"pinnedNumber",value:{id:e.id,anchor:r}}:{kind:"comment",value:{id:e.id,anchor:r,content:e.caption}}},Ol=e=>({id:e.id,start:{x:e.startX,y:e.startY},end:{x:e.endX,y:e.endY},color:e.color??null,thickness:e.thickness,startArrowheadStyle:e.startArrowheadStyle,endArrowheadStyle:e.endArrowheadStyle,lineStyle:e.lineStyle,hasStickerStyle:e.hasStickerStyle}),it=({dataset:e,input:t,anchorVariable:n})=>{if(!u.isDefined(t)||!u.isDefined(t.columnKey))return null;const r=Fl(t,n,e);return r===null?null:{anchorValue:r,groupValue:Ra(t.columnKey)}},Fl=(e,t,n)=>e.rowValue!==void 0?e.rowValue:t===null||!u.isDefined(e.rowIndex)||!n.hasVariable(t)?null:n.getValues(t)[e.rowIndex]??null,Ca=["lilac","neon_pink","blackberry","sun","iceland","sunset","ultraviolet","purple","ice_cream","mint","cool","fresh"];function _a(e){return{type:"config",config:e}}const Pl="#E5E5E5",Bl={x:"top",y:"left"},Gl=new Set(["pie","donut"]);function Ul(e){return _a({legend:Wl(e.legend),axes:Xl(e.axes),headline:ql(e),numberFormat:jl(e.appearance),content:Ql(e.content),appearance:$l(e.appearance,e.themeOverrides)}).config}function $l(e,t){const n=Hl(e?.border),r=e?.hasRoundedCorners===!1?0:void 0,a=Yl(e,t),o={};return e?.textScale!==void 0&&(o.textScale=e.textScale),n!==void 0&&(o.border=n),r!==void 0&&(o.cornerRadius=r),a!==void 0&&(o.background=a),e?.highlightStyle!==void 0&&(o.highlightStyle=e.highlightStyle==="grey"?"desaturate":"dim"),Object.keys(o).length>0?o:void 0}function Yl(e,t){if(e?.backgroundModifier==="tint")return{type:"tinted"};const n=t?.graphBackground;if(typeof n=="string")return{type:"solid",color:n}}const Kl=e=>Ca.includes(e);function Hl(e){if(!e?.style)return;if(e.style==="none")return{type:"none"};const t=e.width??0;if(e.style==="grey")return{type:"solid",color:Pl,width:t};if(e.style==="preset")return e.color===void 0||!Kl(e.color)?void 0:{type:"preset",preset:e.color,width:t};if(e.color!==void 0)return e.style==="custom"?{type:"solid",color:e.color,width:t}:{type:e.style,color:e.color,width:t}}function Wl(e){if(e)return{position:e.position}}function ir(e,t,n){return!t&&n===void 0?{}:{...t?.isHidden!==void 0?{isVisible:!t.isHidden}:void 0,...t?.label!==void 0?{label:t.label}:void 0,...t?.isReversed?{position:Bl[e]}:void 0,...t?.tickDisplayMode?{labels:{mode:t.tickDisplayMode}}:void 0,...n!==void 0?{grid:{isVisible:n}}:void 0}}function zl(e){return{...e.label!==void 0?{label:e.label}:void 0}}function Xl(e){if(e)return{x:ir("x",e.x,e.showGridLines),y:ir("y",e.y,e.showGridLines),...e.y2?{ySecondary:zl(e.y2)}:void 0}}function ql(e){const{headlineNumbers:t,options:n,type:r}=e,a=r!==void 0&&Gl.has(r)?n?.pieTotalPosition:void 0;if(t===void 0&&a===void 0)return;const o={};return t?.show!==void 0&&(o.show=t.show),t?.compareWith!==void 0&&(o.compareWith=t.compareWith),t?.size!==void 0&&(o.size=t.size),a!==void 0&&(o.show="total",o.position=a==="center"?"center":"above"),o}function jl(e){if(e?.numberFormat)return{decimals:e.numberFormat.decimalPlaces,abbreviation:e.numberFormat.abbreviation}}function Ql(e){if(!e)return;const t={};e.title!==void 0&&(t.title=e.title),e.isTitleHidden!==void 0&&(t.isTitleVisible=!e.isTitleHidden),e.subtitle!==void 0&&(t.subtitle=e.subtitle),e.isSubtitleHidden!==void 0&&(t.isSubtitleVisible=!e.isSubtitleHidden),e.caption!==void 0&&(t.caption=e.caption),e.isCaptionHidden!==void 0&&(t.isCaptionVisible=!e.isCaptionHidden);const n=Zl(e.source);return n!==void 0&&(t.source=n),e.isSourceHidden!==void 0&&(t.isSourceVisible=!e.isSourceHidden),t}function Zl(e){if(!e)return;const t={};return e.label!==void 0&&(t.label=e.label),e.url!==void 0&&(t.url=e.url),Object.keys(t).length===0?void 0:t}const k={cartesian:(e={})=>({type:"coord",coordType:"cartesian",params:e}),flip:(e={})=>({type:"coord",coordType:"flip",params:e}),polar:(e={})=>({type:"coord",coordType:"polar",params:e})},Jl={showDataLabels:!1,format:"absolute",showStackTotals:!1,showCategoryLabels:!1,labelSource:{variable:u.POSITION_VARIABLES.yRaw}},nt={stat:{type:"identity"},position:"identity",params:{size:8}},It={stat:{type:"identity"},position:"identity",params:{lineWidth:"auto",interpolate:"linear",missingValues:"gap"}},wt={stat:{type:"identity"},position:"stack",params:{lineWidth:"auto",interpolate:"linear",missingValues:"zero"}},Vt={stat:{type:"identity"},position:"dodge",params:{}},Le={stat:{type:"identity"},position:"identity",interactive:!1,params:{strokeWidth:1,lineType:"dashed",labelPosition:"start"}},ve="primary";function eu(e,t){const n={...Jl};return e==="bar"&&t==="polar"&&(n.format="percentage"),n}function E(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"continuous",transform:t.transform,reverse:t.reverse,nice:t.nice,zero:t.zero,clamp:t.clamp,domainMin:t.domainMin??null,domainMax:t.domainMax??null,range:t.range}}function rt(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"datetime",domainMin:t.domainMin??null,domainMax:t.domainMax??null,nice:t.nice,reverse:t.reverse,clamp:t.clamp}}function G(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"discrete",range:t.range,domain:t.domain??null,padding:t.padding,reverse:t.reverse}}function ke(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"identity"}}function at(e,t){return{type:"scale",scaledAesthetic:e,scaleType:"inferred",options:t}}function Na(e,t={}){return{type:"scale",scaledAesthetic:e,scaleType:"palette",palette:t.palette}}const ae={x:Object.assign(e=>at("x",e),{continuous:e=>E("x",e),discrete:e=>G("x",e),datetime:e=>rt("x",e),log:e=>E("x",{...e,transform:"log"}),sqrt:e=>E("x",{...e,transform:"sqrt"})}),y:Object.assign(e=>at("y",e),{continuous:e=>E("y",e),discrete:e=>G("y",e),datetime:e=>rt("y",e),log:e=>E("y",{...e,transform:"log"}),sqrt:e=>E("y",{...e,transform:"sqrt"})}),ySecondary:Object.assign(e=>at("ySecondary",e),{continuous:e=>E("ySecondary",e),discrete:e=>G("ySecondary",e),datetime:e=>rt("ySecondary",e),log:e=>E("ySecondary",{...e,transform:"log"}),sqrt:e=>E("ySecondary",{...e,transform:"sqrt"})}),color:{continuous:e=>E("color",e),discrete:e=>G("color",e),palette:e=>Na("color",e)},size:{continuous:e=>E("size",e),discrete:e=>G("size",e),identity:e=>ke("size",e)},alpha:{continuous:e=>E("alpha",e),discrete:e=>G("alpha",e),identity:e=>ke("alpha",e)},strokeWidth:{continuous:e=>E("strokeWidth",e),discrete:e=>G("strokeWidth",e),identity:e=>ke("strokeWidth",e)},lineType:{discrete:e=>G("lineType",e),identity:e=>ke("lineType",e)}},_="key",W="value",cr=u.prefixInternalVariable("lineSeriesLabel"),lr=u.prefixInternalVariable("barSeriesLabel"),ct=u.prefixInternalVariable("constantY"),tu=(e,t,n,r)=>cu[t](e,n,r),sn=e=>{const{numeric:t,categorical:n,temporal:r}=e.groupVariableNamesByType();return u.isDefined(r[0])?r[0]:u.isDefined(n[0])?n[0]:u.isDefined(t[0])?t[0]:""},cn=e=>{const t=sn(e),{numeric:n}=e.groupVariableNamesByType(),r=n.filter(o=>o!==t);return r.length<=1?{dataset:e,mapping:{x:t,y:r[0]??""},seriesVariables:r}:{dataset:e.reshapeFromWideToLong({keep:[t],keyName:_,valueName:W}),mapping:{x:t,y:W,color:_},seriesVariables:r}},ln=e=>{const t=e.appearance?.seriesStyles;if(!t||e.seriesVariables.length===0)return{mapping:{},scales:[]};if(!e.seriesVariables.some(a=>u.isDefined(t[a]?.lineStyle)))return{mapping:{},scales:[]};if(e.seriesVariables.length===1){const a=e.seriesVariables[0];if(!a)return{mapping:{},scales:[]};const o=t[a]?.lineStyle;return o?{mapping:{lineType:{value:o}},scales:[]}:{mapping:{},scales:[]}}const r=e.seriesVariables.map(a=>t[a]?.lineStyle??"solid");return{mapping:{lineType:_},scales:[ae.lineType.discrete({domain:e.seriesVariables,range:r})]}},nu=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType(),a=r[0];if(!u.isDefined(a))throw new Error("No first numeric variable found");const o=r.slice(1);return o.length===0?{dataset:e.addConstantVariable(ct,"categorical",""),mapping:{x:a,y:ct,label:t[0]}}:o.length===1?{dataset:e,mapping:{x:a,y:o[0]??"",label:t[0]}}:{dataset:e.reshapeFromWideToLong({keep:[a,...t,...n],keyName:_,valueName:W}),mapping:{x:a,y:W,label:t[0],color:_}}},ru=e=>{const{categorical:t,temporal:n,numeric:r}=e.groupVariableNamesByType();let a,o;if(u.isDefined(t[0])&&u.isDefined(r[0]))a=t[0],o=r[0];else if(u.isDefined(n[0])&&u.isDefined(r[0]))a=n[0],o=r[0];else if(u.isDefined(r[0])&&u.isDefined(r[1]))a=r[0],o=r[1];else throw new Error("No label or value variable found");return{x:"",y:o,color:a}},Oa=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:o}=cn(e.dataset),s=ln({appearance:n,seriesVariables:o}),i=[w.line({params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&i.push(w.point({params:{size:Fa(t.pointSize)},interactive:!1})),{dataset:r,layers:i,coords:k.cartesian(),mapping:{...a,...s.mapping},scales:s.scales,seriesVariables:o}},au=(e,t,n)=>{const{dataset:r,mapping:a,seriesVariables:o}=cn(e.dataset),s=ln({appearance:n,seriesVariables:o}),i=[w.area({position:"stack",params:{lineWidth:t?.lineThickness,interpolate:t?.isSmoothLine?"catmull-rom":"linear",missingValues:t?.missingValues}})];return t?.showPoints&&i.push(w.point({params:{size:Fa(t.pointSize)},position:"stack",interactive:!1})),{dataset:r,layers:i,coords:k.cartesian(),mapping:{...a,...s.mapping},scales:s.scales,seriesVariables:o}},ee=(e,t,n,r,a)=>{const{dataset:o,mapping:s,seriesVariables:i}=cn(e.dataset),c=[];if(r?.sortBars){const l=u.extractVariableName(s.y);l!==null&&l!==""&&c.push(re.sort({variableName:l,direction:"desc"}))}if(!a?.useSingleColorForBars){const l=sn(e.dataset),{numeric:d}=e.dataset.groupVariableNamesByType();d.filter(p=>p!==l).length===1&&e.dataset.getType(l)==="categorical"&&(s.color=l)}return{dataset:o,layers:[w.bar({position:t})],coords:n,mapping:s,scales:[],transforms:c,seriesVariables:i}},ur=(e,t)=>({dataset:e.dataset,layers:[w.bar({position:"fill"})],coords:k.polar({theta:"y",innerRadius:t==="donut"?.55:0}),mapping:ru(e.dataset),scales:[],seriesVariables:[]}),ou=e=>{const{dataset:t,mapping:n}=nu(e.dataset);return{dataset:t,layers:[w.point()],coords:k.cartesian(),mapping:n,scales:[],seriesVariables:[]}},su=e=>{const{numeric:t,categorical:n}=e.dataset.groupVariableNamesByType(),r=t[0];if(!u.isDefined(r))throw new Error("No first numeric variable found");const o=u.isDefined(t[1])?e.dataset:e.dataset.addConstantVariable(ct,"categorical",""),s={x:r,y:t[1]??ct,size:t[2],label:n[0]},i=[];return u.isDefined(s.size)&&i.push(ae.size.continuous()),{dataset:o,layers:[w.point()],coords:k.cartesian(),mapping:s,scales:i,seriesVariables:[]}},Lt=(e,t,n)=>{const r=n?.seriesStyles?.[e]?.lineStyle;return w.line({transforms:[re.constant({variableName:cr,type:"categorical",value:e})],aes:{y:e,color:cr,...r?{lineType:{value:r}}:{}},...t?{yScaleType:"secondary"}:void 0})},iu=(e,t,n)=>{const{numeric:r,categorical:a,temporal:o}=e.dataset.groupVariableNamesByType(),s=sn(e.dataset),i=[...a,...o],c=r.filter(g=>g!==s),l=t?.comboType??"grouped-bars",d=l==="lines";if(c.length===1)return d?Oa(e,t,n):ee(e,"dodge",k.cartesian(),t,n);const m=e.axes?.hasDualYAxis===!0,p=d?[]:c.slice(0,-1),f=d?c:c.slice(-1),h=[],y=[];if(p.length>0){const g=l==="stacked-bars"?"stack":"dodge",S=p.length===1?p[0]:null;u.isDefined(S)?h.push(w.bar({transforms:[re.constant({variableName:lr,type:"categorical",value:S})],aes:{y:S,color:lr},position:g})):h.push(w.bar({transforms:[re.reshape({keep:i,reshape:p,keyName:_,valueName:W})],aes:{y:W,color:_},position:g}))}if(d&&f.length>=2){const g=m?f.slice(0,-1):f,S=g.length===1?g[0]:null;if(u.isDefined(S))h.push(Lt(S,!1,n));else{const b=ln({appearance:n,seriesVariables:g});h.push(w.line({transforms:[re.reshape({keep:i,reshape:g,keyName:_,valueName:W})],aes:{y:W,color:_,...b.mapping}})),y.push(...b.scales)}if(m){const b=f[f.length-1];u.isDefined(b)&&h.push(Lt(b,!0,n))}}else for(const g of f)h.push(Lt(g,m,n));return{dataset:e.dataset,layers:h,coords:k.cartesian(),mapping:{x:s},scales:y,seriesVariables:c}},Fa=(e="auto")=>e==="auto"?nt.params.size:e,Ee=e=>()=>{throw new Error(`Unsupported graph type: ${e}`)},cu={line:(e,t,n)=>Oa(e,t,n),areaStacked:(e,t,n)=>au(e,t,n),bar:(e,t,n)=>ee(e,"dodge",k.flip(),t,n),barStacked:(e,t,n)=>ee(e,"stack",k.flip(),t,n),barStackedFill:(e,t,n)=>ee(e,"fill",k.flip(),t,n),column:(e,t,n)=>ee(e,"dodge",k.cartesian(),t,n),columnStacked:(e,t,n)=>ee(e,"stack",k.cartesian(),t,n),columnStackedFill:(e,t,n)=>ee(e,"fill",k.cartesian(),t,n),pie:e=>ur(e,"pie"),donut:e=>ur(e,"donut"),scatter:e=>ou(e),bubble:e=>su(e),combo:(e,t,n)=>iu(e,t,n),funnel:Ee("funnel"),heatmap:Ee("heatmap"),waterfall:Ee("waterfall"),mekko:Ee("mekko"),table:Ee("table")},Pa=["key",u.prefixInternalVariable("lineSeriesLabel"),u.prefixInternalVariable("barSeriesLabel")];function lu(e){const t=e.annotations??[],n=uu(e.mapping),r=pu(e.convertedDataset,e.layers),a=[];for(const o of t){if(o.type!=="highlight")continue;const s=du({annotation:o,rowIdentityVariable:n,dataset:e.dataset,compiledVariableNames:r});s!==null&&a.push({type:"highlight",id:o.id,predicate:s,scope:o.highlight})}return a}function uu(e){const t=u.extractVariableName(e.x);return t!==null&&t!==""?t:u.extractVariableName(e.color)}function du({annotation:e,rowIdentityVariable:t,dataset:n,compiledVariableNames:r}){switch(e.highlight){case"x-value":return dr(e,t,n);case"series":return mr(e,r);case"data-point":{const a=dr(e,t,n),o=mr(e,r);return a===null&&o===null?null:a===null?o:o===null?a:{and:[a,o]}}}}function dr(e,t,n){if(t===null)return null;const r=fu(e,t,n);return r===null?null:{variable:t,eq:r}}function mr(e,t){if(!mu(t))return null;const n=e.columnKey;return u.isDefined(n)?{or:Pa.map(r=>({variable:r,eq:n}))}:null}function mu(e){return Pa.some(t=>e.includes(t))}function pu(e,t){const n=[...e.getVariableNames()];for(const r of t)for(const a of r.transforms??[])a.transformType==="reshape"?n.push(a.options.keyName??_):a.transformType==="constant"&&n.push(a.options.variableName);return n}function fu(e,t,n){return e.rowValue!==void 0?e.rowValue:!u.isDefined(e.rowIndex)||!n.getVariableNames().includes(t)?null:n.getValues(t)[e.rowIndex]??null}function hu(e,t,n){const{theme:r,customPalettes:a}=n;if(a&&e&&a[e])return{type:"custom",id:e};if(e?.startsWith("preset:pastel"))return{type:"pastel",variant:Et(t)};if(e?.startsWith("preset:graphy"))return{type:"graphy",variant:Et(t)};const i="preset:mono:";if(e?.startsWith(i)){const l=e.slice(i.length);if(yu(l))return{type:"mono",base:l,variant:r}}const c="preset:neon:";if(e?.startsWith(c)){const l=e.slice(c.length);if(gu(l))return{type:"neon",base:l,variant:Et(t)}}return{type:"default"}}function Et(e){if(e==="waterfall")return"waterfall"}function yu(e){return Ma.includes(e)}function gu(e){return Da.includes(e)}function bu(e,t,n,r={}){const a=[];a.push(pr("x",t?.x)),a.push(pr("y",t?.y));const o=hu(n?.paletteId,e,r);return a.push(ae.color.palette({palette:o})),a}function pr(e,t){return t?.scaleType==="logarithmic"||t?.min!==void 0||t?.max!==void 0?t.scaleType==="logarithmic"?ae[e].log({domainMin:t.min??void 0,domainMax:t.max??void 0}):ae[e]({domainMin:t.min??void 0,domainMax:t.max??void 0}):ae[e]()}const Su=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","scatter","bubble","funnel","combo"]),xu=new Set(["column","columnStacked","columnStackedFill","bar","barStacked","barStackedFill","line","areaStacked","combo"]);function Au(e,t,n){const r=t.type??"column",a={dataset:e,axes:t.axes},o=tu(a,r,t.options??void 0,t.appearance??void 0);return{data:o.dataset,mapping:o.mapping,layers:vu(r,t,o.layers,o.coords,o.mapping,o.seriesVariables),scales:[...bu(r,t.axes,t.appearance,n),...o.scales],transforms:o.transforms??[],highlights:lu({annotations:t.annotations,dataset:e,mapping:o.mapping,convertedDataset:o.dataset,layers:o.layers}),annotations:Dl({annotations:t.annotations,dataset:e,mapping:o.mapping}),coords:o.coords,config:Ul(t)}}function vu(e,t,n,r,a,o){const s=Lu(t.dataLabels),i=s===void 0?n:n.filter(l=>l.interactive!==!1).map(l=>({...l,dataLabels:{...s,...l.dataLabels}})),c=t.axes?.hasDualYAxis??!1;return[...i,...Tu({type:e,trendline:t.referenceLines?.trendline,coords:r}),...Iu({type:e,hasDualYAxis:c,goalLine:t.referenceLines?.goalLine,coords:r}),...Vu({type:e,hasDualYAxis:c,averageLine:t.referenceLines?.averageLine,coords:r,mapping:a,seriesVariables:o})]}function Tu({type:e,trendline:t,coords:n}){return t===void 0?[]:Su.has(e)?n.coordType==="polar"?[]:[w.line({aes:{lineType:{value:"dashed"}},stat:on.smooth({method:t}),interactive:!1})]:[]}function Iu({type:e,hasDualYAxis:t,goalLine:n,coords:r}){if(!wu(n))return[];if(r.coordType==="polar")return[];const a=r.coordType==="flip"?"end":"start";return[w.rule({aes:{y:{value:n.target}},params:{labelPosition:a,label:n.label??"Goal"},yScaleType:e==="combo"&&t?"secondary":"primary",interactive:!1})]}function wu(e){return e!==void 0&&Number.isFinite(e.target)}function Vu({type:e,hasDualYAxis:t,averageLine:n,coords:r,mapping:a,seriesVariables:o}){if(n===void 0)return[];if(!xu.has(e))return[];if(r.coordType==="polar")return[];const s=Ra(n.columnKey);if(!o.includes(s))return[];const i=a.color===_,c=i?W:s,l=i?[re.filter({variableName:_,operator:"eq",value:s})]:[];return[w.rule({aes:{y:c,color:void 0,group:void 0,lineType:void 0},stat:on.mean(),transforms:l,params:{label:"Average",labelPosition:r.coordType==="flip"?"end":"start"},yScaleType:e==="combo"&&t?"secondary":"primary",interactive:!1})]}function Lu(e){if(!e)return;const t={};return e.showDataLabels!==void 0&&(t.showDataLabels=e.showDataLabels),e.dataLabelFormat!==void 0&&(t.format=e.dataLabelFormat),e.showStackTotals!==void 0&&(t.showStackTotals=e.showStackTotals),e.showCategoryLabels!==void 0&&(t.showCategoryLabels=e.showCategoryLabels),Object.keys(t).length===0?void 0:t}const Mt={color:null,size:"small",labelCrossPosition:.5},fe={kind:"rectangle",zOrder:"foreground",fillColor:"transparent",fillOpacity:1,strokeWidth:1,strokeColor:null},fr={backgroundColor:null,backgroundColorStyle:"opaque"},he={color:null,thickness:"medium",startArrowheadStyle:"none",endArrowheadStyle:"line-arrow",lineStyle:"solid",hasStickerStyle:!1},Eu=(e,t)=>({differenceArrows:(e?.differenceArrows??[]).map(n=>Ru(n,t)),shapes:(e?.shapes??[]).map(Ou),freeformArrows:(e?.freeformArrows??[]).map(Fu),textAnnotations:(e?.textAnnotations??[]).map(ku),stickers:(e?.stickers??[]).map(n=>Cu(n,t)),pinnedNumbers:(e?.pinnedNumbers??[]).map(n=>_u(n,t)),comments:(e?.comments??[]).map(n=>Nu(n,t)),custom:(e?.custom??[]).map(n=>Mu(n,t))}),Mu=(e,t)=>({id:e.id??crypto.randomUUID(),type:e.type,coordinates:e.coordinates.map(n=>Du(n,t)),params:e.params??{},zOrder:e.zOrder??null}),Du=(e,t)=>"observation"in e?{observation:ge(e.observation,t)}:e,ku=e=>({id:e.id??crypto.randomUUID(),content:e.content,x:e.x,y:e.y,width:e.width,backgroundColor:e.backgroundColor??fr.backgroundColor,backgroundColorStyle:e.backgroundColorStyle??fr.backgroundColorStyle}),Ru=(e,t)=>({id:e.id??crypto.randomUUID(),start:ge(e.start,t),end:ge(e.end,t),label:e.label,color:e.color??Mt.color,size:e.size??Mt.size,labelCrossPosition:e.labelCrossPosition??Mt.labelCrossPosition}),ge=(e,t)=>{if(e.layerIndex===void 0)return{anchorValue:e.anchorValue,groupValue:e.groupValue};const n=t[e.layerIndex]?.id;if(n===void 0)throw new Error(`Annotation references layerIndex ${e.layerIndex} but only ${t.length} layer(s) are defined.`);return{layerId:n,anchorValue:e.anchorValue,groupValue:e.groupValue}},Cu=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t),sticker:e.sticker}),_u=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t)}),Nu=(e,t)=>({id:e.id??crypto.randomUUID(),anchor:ge(e.anchor,t),content:e.content}),Ou=e=>({id:e.id??crypto.randomUUID(),kind:e.kind??fe.kind,zOrder:e.zOrder??fe.zOrder,x:e.x,y:e.y,width:e.width,height:e.height,fillColor:e.fillColor??fe.fillColor,fillOpacity:e.fillOpacity??fe.fillOpacity,strokeWidth:e.strokeWidth??fe.strokeWidth,strokeColor:e.strokeColor??fe.strokeColor}),Fu=e=>({id:e.id??crypto.randomUUID(),start:e.start,end:e.end,color:e.color??he.color,thickness:e.thickness??he.thickness,startArrowheadStyle:e.startArrowheadStyle??he.startArrowheadStyle,endArrowheadStyle:e.endArrowheadStyle??he.endArrowheadStyle,lineStyle:e.lineStyle??he.lineStyle,hasStickerStyle:e.hasStickerStyle??he.hasStickerStyle}),Pu={parsingLocale:"en-US",legend:{position:"auto",display:"auto"},axes:{x:{isVisible:!0,label:null,position:"bottom",grid:{isVisible:null},ticks:{isVisible:!0,mode:"auto"}},y:{isVisible:!0,label:null,position:"right",grid:{isVisible:null},ticks:{isVisible:!1,mode:"auto"}}},panel:{border:{isVisible:!0}},headline:{show:"none",compareWith:"none",size:"auto",position:"above"},numberFormat:{decimals:"auto",abbreviation:"auto"},content:{title:null,isTitleVisible:!0,subtitle:null,isSubtitleVisible:!0,caption:null,isCaptionVisible:!1,source:null,isSourceVisible:!1},appearance:{textScale:1,background:{type:"theme"},border:{type:"none"},cornerRadius:8,highlightStyle:"dim"}};function Bu(e){return le.merge({},Pu,e)}const Gu={xLimits:null,yLimits:null},Dt={theta:"x",startAngle:0,innerRadius:0};function Uu(e){const t=e??{type:"coord",coordType:"cartesian"},n=Fr({},Gu,t.params??{});switch(t.coordType){case"cartesian":case"flip":return{...t,params:n};case"polar":return{...t,params:{...n,theta:t.params?.theta??Dt.theta,startAngle:t.params?.startAngle??Dt.startAngle,innerRadius:t.params?.innerRadius??Dt.innerRadius}}}}function $u(e,t){return e.map(n=>{const r=n.layerIndex!==void 0?t[n.layerIndex]?.id:void 0;if(n.layerIndex!==void 0&&r===void 0)throw new Error(`Highlight references layerIndex ${n.layerIndex} but only ${t.length} layer(s) are defined.`);return{type:"highlight",id:n.id??crypto.randomUUID(),predicate:n.predicate,scope:n.scope??"data-point",...r!==void 0?{layerId:r}:{}}})}const Yu="linear",Ku=3,Hu=.3;function Te(e,t){const n=e??t,r=typeof n=="string"?n:n.type;if(r==="smooth"){const a=typeof n=="string"?void 0:n;return{type:"smooth",method:a?.method??Yu,order:a?.order??Ku,bandwidth:a?.bandwidth??Hu}}return{type:r}}function Wu(e,t,n){if(!qu(n))return ju(e,t,n);switch(n.geom){case"point":return Qu(e,t,n);case"line":return Zu(e,t,n);case"area":return Ju(e,t,n);case"bar":return ed(e,t,n);case"rule":return td(e,t,n)}}function zu(e,t,n){const r=n.map(a=>Wu(e,t,a));return nd(r)}const Xu=(e,t,n)=>n.label!==void 0?n.label:rd(e,t,n),qu=e=>xa(e.geom);function ju(e,t,n){const r=n.position??"identity";return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,"identity"),position:r,yScaleType:n.yScaleType??ve,params:n.params??{},transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}const Ie=(e,t,n,r)=>{const a={...e,...t.mapping},o=Xu(t.geom,n,a);return{...eu(t.geom,r),...t.dataLabels,labelSource:o}};function Qu(e,t,n){const r=n.position??nt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,nt.stat.type),position:r,yScaleType:n.yScaleType??ve,params:le.merge({},nt.params,n.params),transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function Zu(e,t,n){const r=n.position??It.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,It.stat.type),position:r,yScaleType:n.yScaleType??ve,params:le.merge({},It.params,n.params),transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function Ju(e,t,n){const r=le.merge({},wt.params,n.params);r.missingValues==="gap"&&(r.missingValues="zero");const a=n.position??wt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,wt.stat.type),position:a,yScaleType:n.yScaleType??ve,params:r,transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,a,t)}}function ed(e,t,n){const r=n.position??Vt.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,Vt.stat.type),position:r,yScaleType:n.yScaleType??ve,params:{...Vt.params,...n.params},transforms:n.transforms??[],interactive:n.interactive??!0,dataLabels:Ie(e,n,r,t)}}function td(e,t,n){const r=n.position??Le.position;return{id:n.id??crypto.randomUUID(),type:n.type,geom:n.geom,mapping:n.mapping??{},stat:Te(n.stat,Le.stat.type),position:n.position??Le.position,yScaleType:n.yScaleType??ve,params:le.merge({},Le.params,n.params),transforms:n.transforms??[],interactive:n.interactive??Le.interactive,dataLabels:Ie(e,n,r,t)}}const nd=e=>{const t=new Set;for(const n of e)n.position==="fill"&&t.add(n.yScaleType);return t.size===0?e:e.map(n=>{if(n.geom!=="rule"||!t.has(n.yScaleType))return n;const r=u.extractConstantValue(n.mapping.y);if(!I(r))return n;const a=Math.min(1,Math.max(0,r));return{...n,mapping:{...n.mapping,y:{value:a}}}})},rd=(e,t,n)=>{if(e==="point"){const r=u.extractVariableName(n.size);if(r!==null)return{variable:r}}return $e(t,n)};function ad(e,...t){return e?t.includes(e.geom):!1}function od(e,t){return e.find(n=>n.id===t)}function Ba(e,...t){return e.find(n=>t.includes(n.geom))}function sd(e,t,n){const r=e.layers.findIndex(o=>o.id===t);if(r===-1)return e;const a=e.layers.map((o,s)=>s===r?n:o);return{...e,layers:a}}const Ga={x:"position",y:"position",ySecondary:"position",color:"color-range",size:"continuous-range",alpha:"continuous-range",strokeWidth:"continuous-range",lineType:"discrete-only"},id={numeric:{position:"continuous","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"},categorical:{position:"discrete","color-range":"discrete","continuous-range":"discrete","discrete-only":"discrete"},temporal:{position:"datetime","color-range":"continuous","continuous-range":"continuous","discrete-only":"discrete"}};function Ua(e,t,n,r,a){switch(e.scaleType){case"inferred":{const o=ud(e,t,n,r);return Ua(o,t,n,r,a)}case"continuous":{const o=Ga[e.scaledAesthetic],s=o==="continuous-range"&&e.scaledAesthetic in ar?ar[e.scaledAesthetic]:null,i=e.scaledAesthetic==="size"&&o==="continuous-range"?"sqrt":pe.transform;return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,transform:e.transform??i,reverse:e.reverse??pe.reverse,nice:e.nice??pe.nice,zero:e.zero??pe.zero,clamp:e.clamp??o!=="position",domainMin:e.domainMin??pe.domainMin,domainMax:e.domainMax??pe.domainMax,range:e.range??s??null}}case"datetime":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,domainMin:e.domainMin??We.domainMin,domainMax:e.domainMax??We.domainMax,nice:e.nice??We.nice,reverse:e.reverse??We.reverse,clamp:e.clamp??!1};case"discrete":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,range:e.range??De.range,domain:e.domain??De.domain,padding:e.padding??De.padding,reverse:e.reverse??De.reverse};case"palette":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType,palette:pl(e.palette,a)};case"identity":return{type:e.type,scaledAesthetic:e.scaledAesthetic,scaleType:e.scaleType};default:{const o=e;throw new Error(`Unknown scale type: ${o.scaleType}`)}}}function cd(e,t,n,r,a,o){const s=md(t,n),i=pd(s),c=new Map;for(const d of i)c.set(d.scaledAesthetic,d);const l=[...c.values()].map(d=>Ua(d,e,n,r,o));return a.coordType==="polar"?ld(l):l}const ld=e=>e.map(t=>t.scaleType==="discrete"?{...t,padding:0}:t);function ud(e,t,n,r){const a=Y(e.scaledAesthetic),o=e.scaledAesthetic==="ySecondary"?dd(n,r):r[a],s=Ba(n,"bar");if(e.scaledAesthetic==="x"&&s)return G(e.scaledAesthetic,e.options);if(s&&e.scaledAesthetic===(s.yScaleType==="secondary"?"ySecondary":"y")){const m=e.options,p=s.position==="fill";return E(e.scaledAesthetic,{...m,zero:!0,...p&&{nice:!1}})}const i=u.extractVariableName(o);if(!u.isDefined(i)||!t.hasVariable(i))return E(e.scaledAesthetic,e.options);const c=t.getType(i),l=Ga[e.scaledAesthetic];switch(id[c][l]){case"discrete":return G(e.scaledAesthetic,e.options);case"datetime":return rt(e.scaledAesthetic,e.options);case"continuous":return E(e.scaledAesthetic,e.options);case"identity":default:return ke(e.scaledAesthetic)}}function dd(e,t){const n=e.find(r=>r.yScaleType==="secondary");return n?n.mapping.y??t.y:t.y}function md(e,t){return!t.some(a=>a.yScaleType==="secondary")||e.some(a=>a.scaledAesthetic==="ySecondary")?e:[...e,at("ySecondary")]}function pd(e){return e.some(n=>n.scaledAesthetic==="color")?e:[...e,Na("color")]}function hr(e,t){const n=Uu(e.coords),r=zu(e.mapping,n.coordType,e.layers),a=cd(e.data,e.scales,r,e.mapping,n,t),o=Bu(e.config),s=$u(e.highlights,r),i=Eu(e.annotations,r);return{data:e.data,mapping:e.mapping,layers:r,scales:a,transforms:e.transforms,highlights:s,annotations:i,coords:n,config:o}}class $a{compile({input:t,dataset:n,ctx:r}){const a=r.customPalettes??{};return ka(t)?hr(Au(n,t,r),a):hr({...t,data:n},a)}}class fd{constructor(t){this.registry=t}compute(t,n){return this.registry.get(t.type).compute({data:n.data,mapping:n.mapping,spec:t,xScaleIsDiscrete:n.xScaleIsDiscrete})}}class gt{compute(t){return t.data.size()===0?{data:t.data,mapping:{}}:this.computeStat(t)}}class hd extends gt{constructor(){super(...arguments),this.type="count",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=u.extractVariableName(n.x);if(!u.isDefined(r))throw new Error("'x' variable is required for 'count' stat");if(u.extractVariableName(n.y)!==null)throw new Error("Cannot map 'y' variable together with 'count' stat");const o=[...new Set([r,...Qt(t,n)])];return{data:t.groupBy(...o).rollup({[u.STAT_VARIABLES.count]:{variableName:r,aggregation:"count"}}),mapping:{y:u.STAT_VARIABLES.count}}}}class yd extends gt{constructor(){super(...arguments),this.type="identity",this.computedVariables=new Set}computeStat({data:t}){return{data:t,mapping:{}}}}class gd extends gt{constructor(){super(...arguments),this.type="mean",this.computedVariables=new Set(["y"])}computeStat({data:t,mapping:n}){const r=u.extractVariableName(n.y);if(!u.isDefined(r))throw new Error("'y' variable is required for 'mean' stat");return{data:t.rollup({[u.STAT_VARIABLES.mean]:{variableName:r,aggregation:"mean"}}),mapping:{y:u.STAT_VARIABLES.mean}}}}const bd=2,Ya=1440*60*1e3;class Sd extends gt{constructor(){super(...arguments),this.type="smooth",this.computedVariables=new Set}computeStat({data:t,mapping:n,spec:r,xScaleIsDiscrete:a}){if(r.type!=="smooth")throw new Error(`SmoothStat received a spec of type '${r.type}'`);const o=u.extractVariableName(n.x),s=u.extractVariableName(n.y);if(!u.isDefined(o))throw new Error("'x' variable is required for 'smooth' stat");if(!u.isDefined(s))throw new Error("'y' variable is required for 'smooth' stat");const i=t.getType(o),c=t.getType(s);if(c!=="numeric")throw new Error(`'smooth' stat requires a numeric 'y' (got '${c}' for variable '${s}')`);const l=Qt(t,n),d=Vd(o,i,s,l,t);return l.length===0?yr({data:t,xVariable:o,xType:i,yVariable:s,spec:r,output:d,groupObservation:{},xScaleIsDiscrete:a}):t.groupBy(...l).forEach(m=>{const p=Ld(m,l);yr({data:m,xVariable:o,xType:i,yVariable:s,spec:r,output:d,groupObservation:p,xScaleIsDiscrete:a})}),{data:d.build(),mapping:{}}}}const yr=({data:e,xVariable:t,xType:n,yVariable:r,spec:a,output:o,groupObservation:s,xScaleIsDiscrete:i})=>{const{observations:c,temporalOrigin:l}=xd({data:e,xVariable:t,yVariable:r,xType:n});c.length<bd||(i?wd({observations:c,spec:a,output:o,groupObservation:s}):Td({observations:c,xType:n,temporalOrigin:l,spec:a,output:o,groupObservation:s}))},xd=({data:e,xVariable:t,yVariable:n,xType:r})=>{const a=e.getValues(t),o=e.getValues(n,{type:"numeric"}),s=r==="temporal"?Ad(a):null,i=[],c=new Map;for(let l=0;l<a.length;l++){const d=a[l],m=o[l];if(!u.isDefined(d)||!u.isDefined(m)||!Number.isFinite(m))continue;const p=vd({xValue:d,xType:r,categoryRank:c,temporalOrigin:s});p!==null&&i.push({x:p,y:m,originalX:d})}return{observations:i,temporalOrigin:s}},Ad=e=>{let t=null;for(const n of e){if(!R(n))continue;const r=n.getTime();(t===null||r<t)&&(t=r)}return t},vd=({xValue:e,xType:t,categoryRank:n,temporalOrigin:r})=>{switch(t){case"numeric":return!I(e)||!Number.isFinite(e)?null:e;case"temporal":{if(!R(e))return null;const a=e.getTime();return r===null?a:(a-r)/Ya+1}case"categorical":{if(!Pe(e))return null;const a=n.get(e);if(a!==void 0)return a;const o=n.size+1;return n.set(e,o),o}default:{const a=t;throw new Error(`Unexpected xType: ${a}`)}}},Td=({observations:e,xType:t,temporalOrigin:n,spec:r,output:a,groupObservation:o})=>{const s=Ka(r,e);for(const[i,c]of s){if(!Number.isFinite(i)||!Number.isFinite(c))continue;const l=t==="temporal"?Id(i,n):i;a.push({x:l,y:c,groupObservation:o})}},Id=(e,t)=>t===null?new Date(e):new Date((e-1)*Ya+t),wd=({observations:e,spec:t,output:n,groupObservation:r})=>{const a=new Map;for(const i of e)a.has(i.x)||a.set(i.x,i.originalX);const o=[...a.keys()].sort((i,c)=>i-c);if(t.method==="loess"){const i=Ka(t,e),c=new Map;for(const[l,d]of i)Number.isFinite(d)&&(c.has(l)||c.set(l,d));for(const l of o){const d=c.get(l),m=a.get(l);d===void 0||m===void 0||n.push({x:m,y:d,groupObservation:r})}return}const s=Ha(t,e);for(const i of o){const c=a.get(i),l=s.predict(i);c===void 0||!Number.isFinite(l)||n.push({x:c,y:l,groupObservation:r})}},Ka=(e,t)=>e.method==="loess"?J.regressionLoess().x(r=>r.x).y(r=>r.y).bandwidth(e.bandwidth)(t):Ha(e,t),Ha=(e,t)=>{const n=a=>a.x,r=a=>a.y;switch(e.method){case"linear":return J.regressionLinear().x(n).y(r)(t);case"exponential":return J.regressionExp().x(n).y(r)(t);case"logarithmic":return J.regressionLog().x(n).y(r)(t);case"quadratic":return J.regressionQuad().x(n).y(r)(t);case"power":return J.regressionPow().x(n).y(r)(t);case"polynomial":return J.regressionPoly().x(n).y(r).order(e.order)(t);case"loess":throw new Error("'loess' does not expose a 'predict' function")}},Vd=(e,t,n,r,a)=>{const o=[],s=[],i=Object.fromEntries(r.map(c=>[c,[]]));return{push:({x:c,y:l,groupObservation:d})=>{o.push(c),s.push(l);for(const m of r)i[m]?.push(d[m]??null)},build:()=>{const c={[e]:{type:t,values:o,valueFormat:a.getValueFormat(e)},[n]:{type:"numeric",values:s,valueFormat:a.getValueFormat(n)}};for(const l of r)c[l]={type:a.getType(l),values:i[l]??[],valueFormat:a.getValueFormat(l)};return new u.Dataset(c)}}},Ld=(e,t)=>{const n={};for(const r of t){const a=e.getValues(r);n[r]=a[0]??null}return n};class Ed extends xe{constructor(){super("stat"),this.register("identity",new yd),this.register("count",new hd),this.register("smooth",new Sd),this.register("mean",new gd)}}const Md=({layer:e})=>{if(e.position==="stack")return;const t=u.extractVariableName(e.mapping.y);if(t===null)return;let n=0,r=0;for(const a of e.data){const o=a[t];I(o)&&(n+=o,r+=Math.abs(o))}return{grandTotal:n,absoluteGrandTotal:r}},Dd=({layer:e})=>{if(e.position!=="stack")return;const t=u.extractVariableName(e.mapping.x);if(t===null||!e.data.hasVariable(u.POSITION_VARIABLES.yMin)||!e.data.hasVariable(u.POSITION_VARIABLES.yMax))return;const n=new Map;for(const a of e.data){const o=a[t],s=se(a),i=$(a),c=_e(a),l=ye(a),d=ua(a);if(!u.isDefined(o)||!u.isDefined(s)||!u.isDefined(i)||!u.isDefined(c)||!u.isDefined(l)||!u.isDefined(d))continue;const m=d>=0;if(Math.abs(d)===0)continue;const f=en(a,t),h={yMin:s,yMax:i},y=n.get(f);if(y===void 0){n.set(f,{total:d,topPositive:m?h:null,bottomNegative:m?null:h,anchorXMin:c,anchorXMax:l});continue}y.total+=d,m?(y.topPositive===null||i>y.topPositive.yMax)&&(y.topPositive=h):(y.bottomNegative===null||s<y.bottomNegative.yMin)&&(y.bottomNegative=h)}const r=[];for(const[a,o]of n){const s=o.topPositive??o.bottomNegative;s!==null&&r.push({xKey:a,total:o.total,anchor:{xMin:o.anchorXMin,xMax:o.anchorXMax,yMin:s.yMin,yMax:s.yMax,direction:o.topPositive!==null?"positive":"negative"}})}return r};class kd extends Se{constructor(t){super(),this.geomCompiler=t}dependencies(){return[]}compileLayer(t){const n={};if(this.geomCompiler.emitsStackTotals(t.geom)){const r=Dd({layer:t});r!==void 0&&(n.stackTotals=r)}if(this.geomCompiler.emitsGrandTotal(t.geom)){const r=Md({layer:t});r!==void 0&&(n.grandTotal=r.grandTotal,n.absoluteGrandTotal=r.absoluteGrandTotal)}return{...t,summary:n}}}class Rd extends j{constructor(t){super(),this.registry=t}key(t){return t.data}dependencies(t){return[t.transforms]}run(t){return t.transforms.reduce((n,r)=>this.registry.get(r.transformType).apply(n,r),t.data)}}class Cd{constructor(){this.transformType="aggregate"}apply(t,n){const{options:r}=n,a={};for(const o of r.operations)a[o.as]={variableName:o.variableName,aggregation:o.op};return t.groupBy(...r.groupby).rollup(a)}}class _d{constructor(){this.transformType="constant"}apply(t,n){const{options:r}=n;return t.addConstantVariable(r.variableName,r.type,r.value)}}class Nd{constructor(){this.transformType="filter"}apply(t,n){const{options:r}=n;return t.filter(r.variableName,r.operator,r.value)}}class Od{constructor(){this.transformType="reshape"}apply(t,n){const{options:r}=n;return t.reshapeFromWideToLong({keep:r.keep,reshape:r.reshape,keyName:r.keyName,valueName:r.valueName})}}class Fd{constructor(){this.transformType="sort"}apply(t,n){const{options:r}=n;return t.orderBy(r.variableName,r.direction??"asc")}}class Pd extends xe{constructor(){super("transform"),this.register("aggregate",new Cd),this.register("constant",new _d),this.register("filter",new Nd),this.register("reshape",new Od),this.register("sort",new Fd)}}const gr={color:"categorical",size:"numeric",alpha:"numeric",strokeWidth:"numeric",lineType:"categorical"};class Bd extends Se{constructor(t){super(),this.geomCompiler=t}dependencies(t){return[...pt].map(n=>t.scales[n])}compileLayer(t,n){const r=this.geomCompiler.getVisualAesthetics(t.geom),a=Gd(t.data,t.mapping,r,n.scales);return{...t,data:a}}}function Gd(e,t,n,r){let a=e;for(const o of n){const s=u.VISUAL_VARIABLES[o],i=u.extractConstantValue(t[o]);if(i!==void 0){a=a.deriveVariable(s,gr[o],()=>i);continue}const c=u.extractVariableName(t[o]),l=r[o];if(!l||l.kind!=="visual")continue;const d=Ud(o,c,l);d&&(a=a.deriveVariable(s,gr[o],d))}return a}const Ud=(e,t,n)=>{if(!t){if(e!=="color"||n.spec.scaleType!=="palette")return null;const r=n.map(null);return()=>r}return r=>u.isDefined(r[t])?n.map(r[t]):null},$d=["data","transform","constantMapping","layer","coordSetup","scale","positionMapper","visualMapper","coordTransform","summarise","guide","highlights","config","annotations"];class Wa{constructor(t,n,r,a,o,s,i,c,l,d,m,p,f,h,y){this.dataCompiler=t,this.specCompiler=n,this.transformCompiler=r,this.constantMappingCompiler=a,this.layerValidationCheck=o,this.layerCompiler=s,this.scaleCompiler=i,this.coordCompiler=c,this.positionMapperCompiler=l,this.visualMapperCompiler=d,this.guideCompiler=m,this.summariseCompiler=p,this.highlightsCompiler=f,this.configCompiler=h,this.annotationsCompiler=y,this.lastCompile=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.layerCompiler.stats},{name:"coordSetup",getStats:()=>this.coordCompiler.setupStats},{name:"scale",getStats:()=>this.scaleCompiler.stats},{name:"positionMapper",getStats:()=>this.positionMapperCompiler.stats},{name:"visualMapper",getStats:()=>this.visualMapperCompiler.stats},{name:"coordTransform",getStats:()=>this.coordCompiler.transformStats},{name:"summarise",getStats:()=>this.summariseCompiler.stats},{name:"guide",getStats:()=>this.guideCompiler.stats},{name:"highlights",getStats:()=>this.highlightsCompiler.stats},{name:"config",getStats:()=>this.configCompiler.stats},{name:"annotations",getStats:()=>this.annotationsCompiler.stats}]}compile({input:t,data:n,ctx:r={}}){return this.trackCompile(()=>(this.lastData=n,this.runPipeline({spec:this.specCompiler.compile({input:t,ctx:r,dataset:this.dataCompiler.compile(n)})})))}recompile({spec:t,data:n}){return this.trackCompile(()=>n===void 0?this.runPipeline({spec:t}):(this.lastData=n,this.runPipeline({spec:xt(t,{data:this.dataCompiler.compile(n)})})))}getCacheStats(){const t={};for(const{name:n,getStats:r}of this.stages)t[n]={...r()};return t}getLastCompile(){return this.lastCompile}trackCompile(t){if(!ne)return t();const n=this.getCacheStats(),r=performance.now(),a=t(),o=performance.now()-r,s={};for(const{name:i,getStats:c}of this.stages){const l=c();s[i]={hits:l.hits-n[i].hits,misses:l.misses-n[i].misses}}return this.lastCompile={stages:s,durationMs:o},a}runPipeline({spec:t}){return ut({spec:t}).pipe(({spec:r})=>({spec:xt(r,{data:this.transformCompiler.compile({data:r.data,transforms:r.transforms})})})).pipe(({spec:r})=>{const a=this.constantMappingCompiler.compile({data:r.data,mapping:r.mapping});return{spec:xt(r,{data:a.data,mapping:a.mapping})}}).pipe(({spec:r})=>{const a={data:r.data,layers:r.layers,mapping:r.mapping,coords:r.coords,scales:r.scales};return this.layerValidationCheck.check({...a,coords:r.coords}),{layers:this.layerCompiler.compile(a)}}).pipe(({spec:r,layers:a})=>this.coordCompiler.setup({coordSpec:r.coords,scales:r.scales,layers:a})).pipe(({layers:r,scales:a})=>({scales:this.scaleCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,scales:a})=>({config:this.configCompiler.compile({config:r.config,scales:a})})).pipe(({layers:r,scales:a})=>({layers:this.positionMapperCompiler.compile({layers:r,scales:a})})).pipe(({layers:r,scales:a})=>({layers:this.visualMapperCompiler.compile({layers:r,scales:a})})).pipe(({spec:r,layers:a})=>({layers:this.coordCompiler.transform({coordSpec:r.coords,layers:a})})).pipe(({layers:r})=>({layers:this.summariseCompiler.compile({layers:r})})).pipe(({spec:r,scales:a,layers:o,coordSystem:s})=>({guides:this.guideCompiler.compile({scales:a,config:r.config,layers:o,coordSystem:s,originalData:this.lastData})})).pipe(({spec:r,layers:a})=>({layers:this.highlightsCompiler.compile({layers:a,highlights:r.highlights,config:r.config})})).pipe(({spec:r,layers:a,coordSystem:o,scales:s})=>({annotations:this.annotationsCompiler.compile({annotations:r.annotations,layers:a,coordSystem:o,scales:s})})).result()}}const Yd=e=>{const t=new Qs({geoms:e?.geoms}),n=new Ks(t),r=new Ed,a=new hl,o=new Rd(new Pd);return new Wa(new Bs,new $a,o,new qo,new Cc(o,new _c(t,r)),new Rc(o,new fd(r),new Zs,n,new Oc(new Uc)),new Qc(a),new Jo(new us(t)),new jc(t),new Bd(n),new cc(n),new kd(n),new Sc,new Xo,new Bo(n))};function Kd(e,t){return e.geom===t}const un="–",za="n/a",D={timeZone:"UTC"},M=e=>t=>{if(!R(t))return un;try{return e(t)}catch{return za}},Q=e=>t=>I(t)?e(t):un,dn=e=>t=>Pe(t)?t:un,Hd=2,Wd=3,zd=2,Xd=0,qd=1,jd=2,Qd=Lo.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Xa=({valueFormat:e,locale:t,numberFormat:n,intlOptions:r})=>Q(a=>{const o=typeof n.decimals=="number"?n.decimals:Hd,s=hn(a,o),{base:i,suffix:c}=fn(a,n.abbreviation),l={...s,...Wr(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return`${Intl.NumberFormat(t,l).format(i)}${c}`}),mn=({locale:e,numberFormat:t,intlOptions:n})=>Q(r=>{const{base:a,suffix:o}=fn(r,t.abbreviation),i={...hn(a,t.decimals),...n};return`${Intl.NumberFormat(e,i).format(a)}${o}`}),pn=e=>Q(t=>Qd(t)),qa=({locale:e,intlOptions:t})=>Q(n=>Intl.NumberFormat(e,{maximumFractionDigits:0,...t}).format(n)),ja=({locale:e,numberFormat:t,intlOptions:n})=>Q(r=>{const a=hn(r,t.decimals);return Intl.NumberFormat(e,{...a,...n,style:"percent"}).format(r)}),fn=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const n=Zd(e);return fn(e,n)}default:return{base:e/Re[t],suffix:t}}},hn=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const n=Math.ceil(Math.log10(Math.abs(e))),r=n>=Wd?Xd:n===zd?qd:jd;return{minimumFractionDigits:t==="auto"?0:r,maximumFractionDigits:r}},Zd=e=>{const t=Math.abs(e);return t>=Re.b?"b":t>=Re.m?"m":t>=Re.k?"k":"none"},Jd=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{dateStyle:"medium",...D,...t}).format(n)),em=({locale:e,intlOptions:t})=>M(n=>{const r=Intl.DateTimeFormat(e,{dateStyle:"medium",timeStyle:"medium",...D,...t}).formatToParts(n);return tm(r.map(nm))}),Qa=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"long",...D,...t}).format(n)),Za=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"long",...D,...t}).format(n)),yn=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"short",year:"numeric",...D,...t}).format(n)),gn=e=>M(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Ja=({locale:e,intlOptions:t})=>M(n=>{const r=v.addDays(n,6);return Intl.DateTimeFormat(e,{day:"numeric",month:"long",...D,...t,year:void 0}).formatRange(n,r)}),eo=({locale:e,intlOptions:t})=>M(n=>{const r=v.addDays(n,6);return Intl.DateTimeFormat(e,{dateStyle:"medium",...D,...t}).formatRange(n,r)}),bn=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{year:"numeric",...D,...t}).format(n)),to=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...D,...t}).format(n)),tm=e=>e.map(t=>t.value).join(""),nm=e=>e.type!=="literal"||e.value!==", "?e:{type:"literal",value:" • "},rm=1,am=4,om=1,br=1e3,sm=({valueFormat:e,locale:t,tickValues:n,intlOptions:r})=>Q(a=>{const s={...xn(a,n),notation:"compact",...Wr(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...r};return Sn(a,t,s)}),im=({locale:e,tickValues:t,intlOptions:n})=>Q(r=>{const o={...xn(r,t),notation:"compact",...n};return Sn(r,e,o)}),cm=({locale:e,tickValues:t,intlOptions:n})=>Q(r=>{const o={...xn(r,t),notation:"compact",...n,style:"percent"};return Sn(r,e,o)}),Sn=(e,t,n)=>Intl.NumberFormat(t,n).formatToParts(e).map(a=>a.type==="compact"?a.value.toLowerCase():a.value).join(""),no=e=>Math.abs(e)>br?no(e/br):Number.isInteger(e),lm=e=>{if(e.length<2)return!1;const[t,n]=e;return typeof t!="number"||typeof n!="number"?!1:Math.abs(n-t)<rm},xn=(e,t)=>no(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:lm(t)?{minimumFractionDigits:0,maximumFractionDigits:am}:{minimumFractionDigits:0,maximumFractionDigits:om},um=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...D,...t}).format(n)),dm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{month:"short",...D,...t}).format(n)),mm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{day:"numeric",month:"short",...D,...t}).format(n)),pm=({locale:e,intlOptions:t})=>M(n=>Intl.DateTimeFormat(e,{timeStyle:"short",...D,...t}).format(n)),An=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return sm(e);case"date":case"datetime":return um(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return mm(e);case"decimal":case"integer":return im(e);case"duration":return pn();case"month":return dm(e);case"month_year":return yn(e);case"percentage":return cm(e);case"quarter":return gn();case"text":return dn();case"time":return pm(e);case"year":return bn(e);case"lookup":return An({...e,valueFormat:t.fallback});default:{const n=t;throw new Error(`Unhandled value format: ${n.type}`)}}},fm=40,hm=60,Sr=8,ym=50,gm=1/3,bm=1/4,kt="…",Sm=(e,t,n)=>{if(t<=0||e.length===0)return"";if(n(e)<=t)return e;if(n(kt)>t)return"";let r=0,a=e.length-1,o=0;for(;r<=a;){const s=r+a>>>1,i=e.slice(0,s)+kt;n(i)<=t?(o=s,r=s+1):a=s-1}return e.slice(0,o)+kt},xm=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Am(e):vm(e),Am=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:o,maxHeight:s}=ro(e.ticks,r),i=t-Sr;if(o<=i)return{...e,labelRotation:0,labelMaxWidthPx:null};if(t>=ym){const l=Yt(i);return{...e,ticks:$t(e.ticks,a,l,r),labelRotation:0,labelMaxWidthPx:l}}if(s+Sr>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const c=Yt(n.height*gm);return{...e,ticks:$t(e.ticks,a,c,r),labelRotation:-90,labelMaxWidthPx:c}},vm=({formattedAxis:e,bandwidthPx:t,panelRect:n,measureLabel:r})=>{const{widths:a,maxWidth:o,maxHeight:s}=ro(e.ticks,r);if(s>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const i=Yt(n.width*bm);return o<=i?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:$t(e.ticks,a,i,r),labelRotation:0,labelMaxWidthPx:i}},ro=(e,t)=>{const n=[];let r=0,a=0;for(const o of e){const{width:s,height:i}=t(o.formattedLabel);n.push(s),s>r&&(r=s),i>a&&(a=i)}return{widths:n,maxWidth:r,maxHeight:a}},$t=(e,t,n,r)=>{const a=o=>r(o).width;return e.map((o,s)=>(t[s]??0)<=n?o:{...o,formattedLabel:Sm(o.formattedLabel,n,a)})},Yt=e=>Math.max(0,Math.floor(e)),Tm=(e,t,n,r)=>{if(e.length===0)return!0;const a=t==="top"||t==="bottom",o=a?hm:fm;let s=n-(e.length-1)*o;for(const i of e){const{width:c,height:l}=r(i);if(s-=a?c:l,s<0)return!1}return!0},Im=({axis:e,availableSpacePx:t,measureLabel:n,resolveFormatter:r})=>{const{tickCandidates:a,position:o}=e;if(a.length===0)return[];const s=new Map,i=m=>{const p=s.get(m);if(p)return p;const f=a[m],h=f?wm(f.ticks,r(f)):[];return s.set(m,h),h};let c=0,l=a.length-1,d=-1;for(;c<=l;){const m=c+l>>>1,f=i(m).map(h=>h.formattedLabel);Tm(f,o,t,n)?(d=m,c=m+1):l=m-1}return d>=0?i(d):i(0)},wm=(e,t)=>e.map(n=>({...n,formattedLabel:t(n.value)})),Rt=6,Ct=6,_t=15,Nt=5,Ot=15,vn=(e,t)=>{switch(e){case"small":return{arrowStartGap:Rt,arrowEndGap:Ct,offsetFromHigherObservation:_t,arrowheadSize:Nt,curveRadius:Ot,strokeWidth:2,labelLineHeight:12*t,labelPaddingX:6,labelPaddingY:3,labelStrokeWidth:1,labelFontWeight:500};case"medium":return{arrowStartGap:Rt*1.5,arrowEndGap:Ct*1.5,offsetFromHigherObservation:_t*1.25,arrowheadSize:Nt*1.5,curveRadius:Ot*1.25,strokeWidth:3,labelLineHeight:16*t,labelPaddingX:8,labelPaddingY:4,labelStrokeWidth:1.5,labelFontWeight:500};case"large":return{arrowStartGap:Rt*2,arrowEndGap:Ct*2,offsetFromHigherObservation:_t*1.75,arrowheadSize:Nt*2.5,curveRadius:Ot*1.5,strokeWidth:5,labelLineHeight:20*t,labelPaddingX:10,labelPaddingY:5,labelStrokeWidth:2,labelFontWeight:600}}},Vm=e=>{const t=V({...e,valueFormat:e.valueFormat.fallback}),n={};for(const[a,o]of Object.entries(e.valueFormat.cases))n[a]=V({...e,valueFormat:o});const r=e.valueFormat.byVariable;return(a,o)=>{if(o===void 0||o[r]===void 0)return t(a);const s=u.getStableKey(o[r]),i=n[s];return i!==void 0?i(a,o):t(a)}},V=e=>{switch(e.valueFormat.type){case"currency":return Xa(e);case"date":return Jd(e);case"datetime":return em(e);case"day_month":return Qa(e);case"decimal":return mn(e);case"duration":return pn();case"integer":return qa(e);case"month":return Za(e);case"month_year":return yn(e);case"percentage":return ja(e);case"quarter":return gn();case"text":return dn();case"weekly_date_range":return Ja(e);case"weekly_date_range_with_year":return eo(e);case"year":return bn(e);case"time":return to(e);case"lookup":return Vm({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new Error(`Unhandled value format: ${t.type}`)}}},Ft={abbreviation:"none",decimals:"auto"},ao=({locale:e,kind:t,startValue:n,endValue:r})=>{if(n===null||r===null)return za;switch(t){case"absolute-difference":return mn({locale:e,numberFormat:Ft,intlOptions:{signDisplay:"always"}})(r-n);case"relative-difference":{const a=r-n;if(a===0)return"0%";const o=a/n;return o===Number.POSITIVE_INFINITY?"∞":o===Number.NEGATIVE_INFINITY?"-∞":V({valueFormat:{type:"percentage"},locale:e,numberFormat:Ft,intlOptions:{signDisplay:"always"}})(o)}case"proportion":{if(r-n===0)return"=";const a=r/n;return a===Number.POSITIVE_INFINITY?"∞":a===Number.NEGATIVE_INFINITY?"-∞":`${V({valueFormat:{type:"decimal"},locale:e,numberFormat:Ft,intlOptions:{maximumFractionDigits:1}})(a)}x`}}},Lm=e=>{const t=e.padding??0,n=xr(e.rows,t),r=xr(e.cols,t);return{rows:n.tracks,cols:r.tracks,placements:km(e.placements,n.nameToIndex,r.nameToIndex),width:e.containerSize.width,height:e.containerSize.height}},Em=e=>{const t=Ar(e.rows,e.height),n=Ar(e.cols,e.width),r=vr(t),a=vr(n),o=new Map;for(const s of e.placements){const i=s.rowSpan??1,c=s.colSpan??1,l=a[s.col]??0,d=r[s.row]??0,m=Tr(n,s.col,c),p=Tr(t,s.row,i);o.set(s.name,{x:l,y:d,width:Math.max(0,m),height:Math.max(0,p)})}return o},xr=(e,t)=>{const n=[],r=new Map;t>0&&n.push({type:"fixed",pixels:t});for(let a=0;a<e.length;a++){const o=e[a];if(!o)continue;r.set(o.name,n.length),n.push(Mm(o));const s=Dm(e,a);if(oo(o)&&s){const i=o.gaps?.after??0,c=s.gaps?.before??0,l=Math.max(i,c);l>0&&n.push({type:"fixed",pixels:l})}}return t>0&&n.push({type:"fixed",pixels:t}),{tracks:n,nameToIndex:r}},Mm=e=>typeof e.size=="number"?{type:"fixed",pixels:e.size}:{type:"flex",weight:e.size.flex},oo=e=>typeof e.size=="number"?e.size>0:e.size.flex>0,Dm=(e,t)=>{for(let n=t+1;n<e.length;n++){const r=e[n];if(r&&oo(r))return r}},km=(e,t,n)=>{const r=[];for(const a of e){const o=t.get(a.row),s=n.get(a.col);if(o===void 0||s===void 0)continue;const i=a.rowEnd!==void 0?t.get(a.rowEnd):o,c=a.colEnd!==void 0?n.get(a.colEnd):s;i===void 0||c===void 0||r.push({name:a.name,row:o,col:s,rowSpan:Math.max(1,i-o+1),colSpan:Math.max(1,c-s+1)})}return r},Ar=(e,t)=>{let n=0,r=0;for(const o of e)o.type==="fixed"?n+=o.pixels:r+=o.weight;const a=Math.max(0,t-n);return e.map(o=>o.type==="fixed"?o.pixels:r===0?0:o.weight/r*a)},vr=e=>{const t=new Array(e.length);let n=0;for(let r=0;r<e.length;r++)t[r]=n,n+=e[r]??0;return t},Tr=(e,t,n)=>{let r=0;const a=Math.min(t+n,e.length);for(let o=t;o<a;o++)r+=e[o]??0;return r},so=24,H={header:{after:10,before:0},headline:{after:4,before:0},topLegend:{after:16,before:0},topAxisLabel:{after:4,before:0},topAxis:{after:0,before:0},panel:{after:0,before:0},bottomAxis:{after:4,before:0},bottomAxisLabel:{after:16,before:0},bottomLegend:{after:10,before:16}},qe={leftLegend:{after:10,before:0},leftAxis:{after:4,before:0},panel:{after:4,before:0},rightAxis:{after:10,before:0}},Tn={top:0,right:0,bottom:0,left:0},Rm=(e,t,n,r=Tn)=>{const o=n.axes.top>0||n.axesLabels.top>0?n.axesLabels.top:Math.max(n.axesLabels.top,n.axesLabels.left,n.axesLabels.right);return Lm({rows:[{name:"header",size:t.headerSize.height,gaps:H.header},{name:"topLegend",size:n.legends.top,gaps:H.topLegend},{name:"headline",size:n.headline,gaps:H.headline},{name:"topAxisLabel",size:o,gaps:H.topAxisLabel},{name:"topAxis",size:n.axes.top,gaps:H.topAxis},{name:"topAnnotation",size:r.top},{name:"panel",size:{flex:1},gaps:H.panel},{name:"bottomAxis",size:n.axes.bottom,gaps:H.bottomAxis},{name:"bottomAxisLabel",size:n.axesLabels.bottom,gaps:H.bottomAxisLabel},{name:"bottomLegend",size:n.legends.bottom,gaps:H.bottomLegend},{name:"footer",size:t.footerSize.height}],cols:[{name:"leftLegend",size:n.legends.left,gaps:qe.leftLegend},{name:"leftAxis",size:n.axes.left,gaps:qe.leftAxis},{name:"panel",size:{flex:1},gaps:qe.panel},{name:"rightAnnotation",size:r.right},{name:"rightAxis",size:n.axes.right,gaps:qe.rightAxis},{name:"rightLegend",size:n.legends.right}],placements:[{name:"header",row:"header",col:"leftLegend",colEnd:"rightLegend"},{name:"headline",row:"headline",col:"leftLegend",colEnd:"rightLegend"},{name:"footer",row:"footer",col:"leftLegend",colEnd:"rightLegend"},{name:"plot",row:"topAxisLabel",rowEnd:"bottomAxisLabel",col:"leftAxis",colEnd:"rightAxis"},{name:"panel",row:"panel",col:"panel"},...Cm(n.axes),..._m(n.axesLabels,n.axes),...Nm(n.legends)],containerSize:e,padding:so})},Cm=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},_m=(e,t)=>{const n=[];return e.top>0||t.top>0?(e.top>0&&n.push({name:"topAxisLabel",row:"topAxisLabel",col:"panel"}),e.left>0&&n.push({name:"leftAxisLabel",row:"topAxis",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxis",col:"rightAxis"})):(e.left>0&&n.push({name:"leftAxisLabel",row:"topAxisLabel",col:"leftAxis"}),e.right>0&&n.push({name:"rightAxisLabel",row:"topAxisLabel",col:"rightAxis"})),e.bottom>0&&n.push({name:"bottomAxisLabel",row:"bottomAxisLabel",col:"panel"}),n},Nm=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},Om=({annotations:e,mainAxis:t,panelRect:n,textScale:r,locale:a,measureLabel:o,currentOverflow:s})=>{if(e.differenceArrows.length===0)return Tn;const i=t==="y",c=n.height+s.top,l=n.width+s.right;let d=0,m=0;for(const p of e.differenceArrows){const{start:f,end:h,size:y,label:g}=p;if(!Ir(f.x,f.y)||!Ir(h.x,h.y))continue;const S=vn(y,r),b=S.offsetFromHigherObservation+S.arrowheadSize+S.arrowEndGap,x=ao({locale:a,kind:g,startValue:f.measurementValue,endValue:h.measurementValue}),T=o(x,y);if(i){const L=Math.max(f.x,h.x),P=b+T.width/2+S.labelPaddingX;m=Math.max(m,wr(P,L,l))}else{const L=Math.max(f.y,h.y),P=b+S.labelLineHeight/2+S.labelPaddingY;d=Math.max(d,wr(P,L,c))}}return{top:Math.ceil(d),right:Math.ceil(m),bottom:0,left:0}},Ir=(e,t)=>e>=0&&e<=1&&t>=0&&t<=1,wr=(e,t,n)=>{if(t<=0)return 0;const r=(e-(1-t)*n)/t;return Math.max(0,r)},Fm=["top","right","bottom","left"],Pt=(e,t)=>{const n={};for(const r of Fm){const a=e.get(`${r}${t}`);a&&(n[r]=a)}return n},Kt=["large","medium","small"],Pm=({size:e,availableWidth:t,measureStripWidth:n})=>{if(e!=="auto")return e;for(const r of Kt)if(n(r)<=t)return r;return"small"},Bm=({size:e,availableWidth:t,measureStripWidth:n})=>{const r=e==="auto"?0:Kt.indexOf(e);for(const a of Kt.slice(r))if(n(a)<=t)return a;return null},Gm=({itemWidths:e,gap:t,availableWidth:n})=>{let r=0,a=0;for(const o of e){const s=a===0?o:r+t+o;if(s>n)break;r=s,a+=1}return a},Um=({headline:e,containerSize:t,measurer:n})=>{if(io(e))return 0;const r=co(e,t.width,n);return n.measureHeadline(e.formatted,r).height},$m=({headline:e,layout:t,containerSize:n,measurer:r,itemGap:a})=>{if(io(e)){const i=Ym(t.panel,e.innerRadius),c=Bm({size:e.size,availableWidth:i.width,measureStripWidth:lo(e,r)});return c===null?null:{rect:i,resolvedSize:c,visibleItemCount:1}}const o=co(e,n.width,r);if(e.formatted.kind!=="perGroup")return{rect:t.headline,resolvedSize:o,visibleItemCount:1};const s=Gm({itemWidths:r.measureHeadlineItemWidths(e.formatted,o),gap:a,availableWidth:t.headline.width});return s===0?null:{rect:t.headline,resolvedSize:o,visibleItemCount:s}},io=e=>e.formatted.kind==="grandTotal"&&e.position==="center"&&e.innerRadius>0,Ym=(e,t)=>{const n=Math.min(e.width,e.height)/2,r=t*n*Math.SQRT2,a=e.x+e.width/2,o=e.y+e.height/2;return{x:a-r/2,y:o-r/2,width:r,height:r}},co=(e,t,n)=>Pm({size:e.size,availableWidth:t,measureStripWidth:lo(e,n)}),lo=(e,t)=>n=>t.measureHeadline(e.formatted,n).width,Me={x:0,y:0,width:0,height:0},Km="0000";class Hm{constructor(t){this.measurer=t}compile(t){const n=ut({axes:t.axes,numberFormat:t.numberFormat,formattedLegends:t.formattedLegends,containerSize:t.containerSize,externalMeasurements:t.externalMeasurements,annotationOverflow:Tn,headline:t.headline,locale:t.formattingLocale??t.parsingLocale}).pipe(({axes:r,numberFormat:a,locale:o})=>{const s=r.filter(i=>i.geometry!=="linear").map(i=>zm(i,Er(i,o,a)));return{cartesianAxes:r.filter(i=>i.geometry==="linear"),formattedPolarAxes:s,polarMargin:Xm(s,this.measurer.measureTickLabel)}}).pipe(({cartesianAxes:r,numberFormat:a,locale:o})=>({axisBundles:r.map(s=>({axis:s,resolveFormatter:Er(s,o,a),formatted:this.seedAxis(s)}))})).pipe(({axisBundles:r,formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})=>({layout:this.resolveLayout({axes:r.map(d=>d.formatted),formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})})).pipe(({axisBundles:r,layout:a})=>({axisBundles:r.map(o=>Lr(o.axis.position)?{...o,formatted:this.finalizeAxis(o.axis,o.resolveFormatter,a.panel)}:o)})).pipe(({axisBundles:r,formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})=>({layout:this.resolveLayout({axes:r.map(d=>d.formatted),formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})})).pipe(({axisBundles:r,layout:a})=>({formattedAxes:r.map(o=>Lr(o.axis.position)?o.formatted:this.finalizeAxis(o.axis,o.resolveFormatter,a.panel))})).pipe(({formattedAxes:r,formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})=>({layout:this.resolveLayout({axes:r,formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:i,headline:c,polarMargin:l})})).pipe(({formattedAxes:r,formattedLegends:a,containerSize:o,externalMeasurements:s,layout:i,annotationOverflow:c,headline:l,polarMargin:d,locale:m})=>{const p=this.measureAnnotationOverflow(t,i.panel,m,c);return p===c?{formattedAxes:r,layout:i}:{formattedAxes:r,layout:this.resolveLayout({axes:r,formattedLegends:a,containerSize:o,externalMeasurements:s,annotationOverflow:p,headline:l,polarMargin:d})}}).result();return{formattedAxes:n.formattedAxes,layout:n.layout,formattedPolarAxes:n.formattedPolarAxes}}measureAnnotationOverflow(t,n,r,a){if(!t.annotations||t.annotations.differenceArrows.length===0||t.coordSystem?.type!=="cartesian")return a;const o=Om({annotations:t.annotations,mainAxis:t.coordSystem.mainAxis,panelRect:n,textScale:t.textScale??1,locale:r,measureLabel:this.measurer.measureDifferenceArrowLabel,currentOverflow:a});return o.top===a.top&&o.right===a.right?a:o}seedAxis(t){const{tickCandidates:n,...r}=t;return{...r,ticks:[{value:0,position:0,formattedLabel:Km}],labelRotation:0,labelMaxWidthPx:null}}finalizeAxis(t,n,r){const o=t.position==="top"||t.position==="bottom"?r.width:r.height,s=Im({axis:t,availableSpacePx:o,measureLabel:this.measurer.measureTickLabel,resolveFormatter:n}),{tickCandidates:i,...c}=t,l={...c,ticks:s,labelRotation:0,labelMaxWidthPx:null};if(t.scaleType==="discrete"&&t.bandwidth!==void 0){const d=t.bandwidth*o;return xm({formattedAxis:l,bandwidthPx:d,panelRect:r,measureLabel:this.measurer.measureTickLabel})}return l}resolveLayout({axes:t,formattedLegends:n,containerSize:r,externalMeasurements:a,annotationOverflow:o,headline:s,polarMargin:i}){const c=this.measureGuides(t,n,s,r,i),l=Rm(r,a,c,o),d=Em(l);return{header:d.get("header")??Me,headline:d.get("headline")??Me,footer:d.get("footer")??Me,plot:d.get("plot")??Me,panel:d.get("panel")??Me,axes:Pt(d,"Axis"),axisLabels:Pt(d,"AxisLabel"),legends:Pt(d,"Legend")}}measureGuides(t,n,r,a,o){const s={...o},i={top:0,right:0,bottom:0,left:0};for(const l of t)l.isVisible&&(s[l.position]=this.measurer.measureAxis(l),l.label!==null&&(i[l.position]=this.measurer.measureAxisLabel(l)));const c={top:0,right:0,bottom:0,left:0};for(const l of n)c[l.position]=this.measurer.measureLegend(l);return{axes:s,axesLabels:i,legends:c,headline:this.measureHeadlineBand(r,a)}}measureHeadlineBand(t,n){return t===void 0?0:Um({headline:t,containerSize:n,measurer:this.measurer})}}const Vr=5,je=8,Lr=e=>e==="left"||e==="right",Wm=e=>{const[t,...n]=e.tickCandidates;if(t)return e.geometry==="circular"?t:n.reduce((r,a)=>Math.abs(a.ticks.length-Vr)<Math.abs(r.ticks.length-Vr)?a:r,t)},zm=(e,t)=>{const{tickCandidates:n,...r}=e,a=Wm(e);if(!a)return{...r,ticks:[],labelRotation:0,labelMaxWidthPx:null};const o=t(a),s=a.ticks.map(i=>({...i,formattedLabel:o(i.value)}));return{...r,ticks:s,labelRotation:0,labelMaxWidthPx:null}},Xm=(e,t)=>{const n=e.find(o=>o.geometry==="circular");if(!n||n.ticks.length===0)return{top:0,right:0,bottom:0,left:0};let r=0,a=0;for(const o of n.ticks){const s=t(o.formattedLabel);r=Math.max(r,s.width),a=Math.max(a,s.height)}return{top:a+je,bottom:a+je,left:r+je,right:r+je}},Er=(e,t,n)=>{const r=e.tickCandidates.flatMap(o=>o.ticks.map(s=>s.value)),a=new WeakMap;return o=>{const s=a.get(o);if(s)return s;const i=An({valueFormat:o.valueFormat??e.valueFormat,locale:t,numberFormat:n,tickValues:r});return a.set(o,i),i}};function qm(e,t,n,r){const a=new Map;if(!n||n.kind!=="visual"||n.domain.length<=1)return a;const o=new Map(t.map(s=>[s.id,s.swatchShape]));for(const s of e){if(s.geom!=="rule"||s.stat.type!=="mean")continue;const i=s.transforms.find(y=>y.transformType==="filter"&&y.options.operator==="eq"),c=u.extractVariableName(s.mapping.y);let l,d,m;if(i?.transformType==="filter"&&typeof i.options.value=="string")l="color",d=i.options.variableName,m=i.options.value;else if(c!==null)l="y",d=c,m=c;else continue;const p=jm(e,l,d);if(p===null)continue;const f=o.get(p.id);if(f===void 0)continue;const h=n.map(m);Pe(h)&&a.set(s.id,{shape:Ne(f,r),color:h})}return a}function jm(e,t,n){let r=null;for(const a of e)if(a.geom!=="rule"&&(r===null&&(r=a),u.extractVariableName(a.mapping[t])===n))return a;return r}function Oe(e,t){return e==="x"?t.x:t.y}function bt(e,t){return e==="x"?t.y:t.x}function Qm(e,t){return{main:Oe(e,t),cross:bt(e,t)}}function Zm(e){return e.type==="cartesian"}const In=12,Jm=4,ep=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=$(n)??z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=r*e.panelRect.width,l=(1-a)*e.panelRect.height-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:c,y:l,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},tp={place:ep,getPercentageValueStrategy:e=>e.position==="fill"?"fill":O(e.position)?"stack":"none"},Bt=4,Qe=6,np=e=>{const t=[],n=O(e.layer.position),r=e.coordSystem.mainAxis==="y";if(e.layer.dataLabels.showDataLabels){const{entries:a,shouldRotate:o}=ap({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatLabel:e.formatLabel,isFlipped:r,getObservationKey:e.getObservationKey});for(const s of a){const i=cp({mainAxis:e.coordSystem.mainAxis,isStacked:n,isNegativeBar:s.isNegative,shouldRotate:o,bounds:s.bounds,labelWidth:s.labelWidth,labelHeight:s.labelHeight,panelWidth:e.panelRect.width,panelHeight:e.panelRect.height});i!==null&&t.push({layerId:e.layer.id,key:s.key,x:i.x,y:i.y,text:s.text,width:s.labelWidth,height:s.labelHeight,isRotated:i.isRotated,target:"observation",position:i.position})}}if(e.layer.dataLabels.showStackTotals){const a=mp({layer:e.layer,mainAxis:e.coordSystem.mainAxis,panelRect:e.panelRect,measureDataLabel:e.measureDataLabel,formatAbsolute:e.formatAbsolute});for(const o of a)t.push(o)}return t},rp={place:np,getPercentageValueStrategy:e=>e.position==="fill"?"fill":O(e.position)?"stack":"absoluteGrandTotal"},ap=({layer:e,mainAxis:t,panelRect:n,measureDataLabel:r,formatLabel:a,isFlipped:o,getObservationKey:s})=>{const i=[];let c=!1;const l=u.extractVariableName(e.mapping.y);for(const d of e.data){const m=op(t,d);if(m===null)continue;const p=a(d);if(p==="")continue;const{width:f,height:h}=r("dataLabel",p),y=uo(m,n);f>y.width&&(c=!0);const g=l===null?null:d[l],S=I(g)&&g<0;i.push({key:s(d),isNegative:S,text:p,labelWidth:f,labelHeight:h,bounds:y})}return{entries:i,shouldRotate:!o&&c}},uo=(e,t)=>({x:e.x*t.width,y:e.y*t.height,width:e.width*t.width,height:e.height*t.height}),mo=(e,t,n,r,a)=>{if(e==="x"){let i=1-a,c=a-r;return c<0&&(i+=c,c=-c),{x:t,y:i,width:n-t,height:c}}let o=t,s=n-t;return s<0&&(o+=s,s=-s),{x:o,y:1-a,width:s,height:a-r}},op=(e,t)=>{const n=_e(t),r=ye(t),a=se(t),o=$(t)??z(t);return n===null||r===null||a===null||o===null?null:mo(e,n,r,a,o)},sp=(e,t)=>{const{xMin:n,xMax:r,yMin:a,yMax:o}=t.anchor;return mo(e,n,r,a,o)},ip=(e,t)=>e==="x"?t?"bottom":"top":t?"left":"right",po=(e,t,n)=>n?{width:t,height:e}:{width:e,height:t},cp=e=>e.isStacked?lp({bounds:e.bounds,labelWidth:e.labelWidth,labelHeight:e.labelHeight,isRotated:e.shouldRotate}):dp({edge:ip(e.mainAxis,e.isNegativeBar),bounds:e.bounds,labelWidth:e.labelWidth,labelHeight:e.labelHeight,isRotated:e.shouldRotate,panelWidth:e.panelWidth,panelHeight:e.panelHeight}),lp=({bounds:e,labelWidth:t,labelHeight:n,isRotated:r})=>{const a=po(t,n,r);return a.width>e.width||a.height>e.height?null:{x:e.x+e.width/2,y:e.y+e.height/2,isRotated:r,position:"inside"}},up=(e,t,n,r)=>{switch(e){case"top":return{edgeCoord:t.y,outwardSign:-1,panelExtent:r};case"bottom":return{edgeCoord:t.y+t.height,outwardSign:1,panelExtent:r};case"left":return{edgeCoord:t.x,outwardSign:-1,panelExtent:n};case"right":return{edgeCoord:t.x+t.width,outwardSign:1,panelExtent:n}}},dp=({edge:e,bounds:t,labelWidth:n,labelHeight:r,isRotated:a,panelWidth:o,panelHeight:s})=>{const i=e==="top"||e==="bottom",c=t.x+t.width/2,l=t.y+t.height/2,d=po(n,r,a),m=i?d.height:d.width,p=i?d.width:d.height,f=i?t.height:t.width,h=i?t.width:t.height,y=m/2,{edgeCoord:g,outwardSign:S,panelExtent:b}=up(e,t,o,s);if(m+Bt<f){if(p>h)return null;if(a)return{x:c,y:l,isRotated:!0,position:"inside"};const T=g-S*(y+Bt);return{...i?{x:c,y:T}:{x:T,y:l},isRotated:!1,position:"inside"}}const x=g+S*(y+Bt);return x-y<0||x+y>b?null:{...i?{x:c,y:x}:{x,y:l},isRotated:a,position:"outside"}},mp=({layer:e,mainAxis:t,panelRect:n,measureDataLabel:r,formatAbsolute:a})=>{const o=[],s=e.summary.stackTotals;if(s===void 0||s.length===0)return o;const i=t==="y";for(const c of s){const l=uo(sp(t,c),n),d=a(c.total),{width:m,height:p}=r("stackTotal",d),f=c.anchor.direction==="positive";let h,y;i?(h=f?l.x+l.width+Qe+m/2:l.x-Qe-m/2,y=l.y+l.height/2):(h=l.x+l.width/2,y=f?l.y-Qe-p/2:l.y+l.height+Qe+p/2),o.push({layerId:e.id,key:`${e.id}:stack:${c.xKey}`,x:h,y,text:d,width:m,height:p,isRotated:!1,target:"aggregate",position:"outside"})}return o},pp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=r*e.panelRect.width,l=(1-a)*e.panelRect.height-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:c,y:l,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},fp={place:pp,getPercentageValueStrategy:()=>"none"},hp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;for(const n of e.layer.data){const r=Ae(n),a=z(n);if(r===null||a===null||r<0||r>1||a<0||a>1)continue;const o=e.formatLabel(n);if(o==="")continue;const{width:s,height:i}=e.measureDataLabel("dataLabel",o),c=(Ur(n)??e.layer.params.size)/2,l=r*e.panelRect.width,d=(1-a)*e.panelRect.height-c-In-i/2;t.push({layerId:e.layer.id,key:e.getObservationKey(n),x:l,y:d,text:o,width:s,height:i,isRotated:!1,target:"observation",position:"outside"})}return t},yp={place:hp,getPercentageValueStrategy:()=>"none"};function fo(e){return{startAngle:e[u.POSITION_VARIABLES.xMin],endAngle:e[u.POSITION_VARIABLES.xMax]}}function ho(e){return{innerRadius:e[u.POSITION_VARIABLES.yMin],outerRadius:e[u.POSITION_VARIABLES.yMax]??e[u.POSITION_VARIABLES.y]}}const gp=" · ",bp=e=>typeof e=="string"?e:e instanceof Date?e.toISOString():String(e),Sp=(e,t)=>{const n=u.extractVariableName(t.x);return n!==null&&n!==u.CONSTANT_VARIABLES.x?tn(e,t):a=>be(a)},xp=e=>{const t=[];if(!e.layer.dataLabels.showDataLabels)return t;const n=e.layer.dataLabels.showCategoryLabels?Sp(e.layer.data,e.layer.mapping):null,r=e.panelRect.width/2,a=e.panelRect.height/2,o=Math.min(e.panelRect.width,e.panelRect.height)/2;for(const s of e.layer.data){const{startAngle:i,endAngle:c}=fo(s),{outerRadius:l}=ho(s);if(i===null||c===null||l===null)continue;const d=e.formatLabel(s);if(d==="")continue;const m=n===null?null:n(s),p=m===null?d:`${bp(m)}${gp}${d}`,{width:f,height:h}=e.measureDataLabel("dataLabel",p),y=(i+c)/2,g=Math.abs(Math.sin(y))*(f/2)+Math.abs(Math.cos(y))*(h/2),S=l*o+Jm+g,b=r+Math.sin(y)*S,x=a-Math.cos(y)*S,T=f/2,L=h/2;b-T<0||b+T>e.panelRect.width||x-L<0||x+L>e.panelRect.height||t.push({layerId:e.layer.id,key:e.getObservationKey(s),x:b,y:x,text:p,width:f,height:h,isRotated:!1,target:"observation",position:"outside"})}return t},Ap={place:xp,getPercentageValueStrategy:()=>"absoluteGrandTotal"},vp={type:"decimal"};function yo({layer:e,numberFormat:t,locale:n}){const r=u.extractVariableName(e.mapping.y),a=r!==null&&e.data.hasVariable(r)?e.data.getValueFormat(r):vp;return V({valueFormat:a,locale:n,numberFormat:t})}const Tp=({layer:e,coordSystem:t,axes:n,numberFormat:r,panelRect:a,measureDataLabel:o,formattingLocale:s,percentageValueStrategy:i})=>{const c=yo({layer:e,numberFormat:r,locale:s});return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:o,formatLabel:Ep({layer:e,numberFormat:r,axes:n,locale:s,absoluteFormatter:c,percentageValueStrategy:i}),formatAbsolute:c,getObservationKey:Ip(e)}},Ip=e=>t=>`${e.id}:${ht(t)}`,wp=(e,t)=>{switch(t){case"stack":return Vp(e);case"fill":return Lp(e);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Vp=e=>{const t=u.extractVariableName(e.mapping.x);let n=null,r=!1;return a=>{const o=e.summary.stackTotals;if(o===void 0||o.length===0||t===null)return null;if(!r){n=new Map;for(const c of o)n.set(c.xKey,c);r=!0}const s=a[t];if(s==null)return null;const i=n?.get(en(a,t));return i===void 0?null:i.total}},Lp=e=>{const t=nn(e);return n=>{const r=se(n),a=$(n);if(!I(r)||!I(a))return null;const o=Math.abs(a-r);if(o===0)return null;const s=t(n);return I(s)?s/o:null}},Ep=({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a,percentageValueStrategy:o})=>{const s=F(e.data,e.dataLabels.labelSource),i=wp(e,o),c=Mp({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a}),l=V({valueFormat:{type:"percentage"},locale:r,numberFormat:t}),d=e.dataLabels.format==="percentage"&&go(e);return m=>{const p=s(m);if(p===null)return"";if(!d||!I(p))return c(p,m);const f=i(m);return f===null||f===0?c(p,m):l(p/f)}},Mp=({layer:e,numberFormat:t,axes:n,locale:r,absoluteFormatter:a})=>{const o=e.dataLabels.labelSource,s=u.extractVariableName(o);if(s!==null){if(go(e))return a;const i=Dp(e,n,t,r,s);if(i!==null)return i}return V({valueFormat:kp(e.data,o),locale:r,numberFormat:t})},go=e=>{const t=u.extractVariableName(e.dataLabels.labelSource);return t===null?!1:t===u.extractVariableName($e(e.position,e.mapping))},Dp=(e,t,n,r,a)=>{const o=u.extractVariableName(e.mapping.x);if(o===null||o!==a)return null;const s=t.find(i=>i.scaleAestheticKey==="x");return s===void 0?null:V({valueFormat:s.valueFormat,locale:r,numberFormat:n})},kp=(e,t)=>{const n=u.extractConstantValue(t);if(n!==void 0)return typeof n=="number"?{type:"decimal"}:Oo(n)?{type:"date"}:{type:"text"};const r=u.extractVariableName(t);return r===null||!e.hasVariable(r)?{type:"text"}:e.getValueFormat(r)},Rp={bar:{cartesian:rp,polar:Ap},line:{cartesian:fp},point:{cartesian:yp},area:{cartesian:tp}},Cp=({layers:e,coordSystem:t,axes:n,numberFormat:r,parsingLocale:a,panelRect:o,measureDataLabel:s,formattingLocale:i})=>{const c=[],l=i??a,d=t.type;for(const m of e){if(!m.dataLabels.showDataLabels&&!m.dataLabels.showStackTotals)continue;const p=Rp[m.geom]?.[d];if(p===void 0)continue;const f=Tp({layer:m,coordSystem:t,axes:n,numberFormat:r,panelRect:o,measureDataLabel:s,formattingLocale:l,percentageValueStrategy:p.getPercentageValueStrategy(m)}),h=p.place(f);for(const y of h)c.push(y)}return{labels:c}},_p=(e,t,n,r)=>{const a=r.offsetFromHigherObservation+r.arrowheadSize+r.arrowEndGap;return e?Math.max(t.x,n.x)+a:Math.min(t.y,n.y)-a},Np=(e,t,n,{arrowStartGap:r,arrowEndGap:a,curveRadius:o})=>{const s={x:e.x,y:e.y-r},i={x:e.x,y:n},c={x:t.x,y:n},l={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
|
|
4
5
|
M ${s.x} ${s.y}
|
|
5
6
|
L ${i.x} ${i.y+o}
|
|
6
7
|
Q ${i.x} ${i.y} ${i.x+d*o} ${i.y}
|