@graphysdk/viz-engine 1.9.0-beta.1790776416986 → 1.9.0-beta.1790778920035

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./annotations-6ONVHjKW.cjs"),m=require("./compiler--1GEomjr.cjs"),b=require("./spec-builder-BJG0JDPn.cjs");let el=require("lodash-es"),ie=require("lodash-es/clamp");ie=l.__toESM(ie,1);let ct=require("humanize-duration");ct=l.__toESM(ct,1);let E=require("d3-shape"),tl=require("d3-delaunay"),Ce=require("lodash-es/isEqual");Ce=l.__toESM(Ce,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1790776416986");var rl=1e6;function _(e){return String(Math.round(e*rl))}function W(e,t){return e.geom===t}var Je="…",On=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Je)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Je)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Je};var R={timeZone:"UTC"},L=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Y=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",At=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Se=new Map,be=new Map,_n=256,ue=(e,t)=>{const r=kn(e,t),n=Se.get(r);if(n!==void 0)return n;Se.size>=_n&&Se.clear();const a=new Intl.NumberFormat(e,t);return Se.set(r,a),a},w=(e,t)=>{const r=kn(e,t),n=be.get(r);if(n!==void 0)return n;be.size>=_n&&be.clear();const a=new Intl.DateTimeFormat(e,t);return be.set(r,a),a},kn=(e,t)=>`${e}\0${JSON.stringify(t)}`,nl=ct.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ne={signDisplay:"negative"},Vn=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Y(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Lt(a,i),{base:s,suffix:c}=Tt(a,r.abbreviation);return`${ue(t,{...o,...Ne,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),Nn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>{const{base:a,suffix:i}=Tt(n,t.abbreviation);return`${ue(e,{...Lt(a,t.decimals),...Ne,...r}).format(a)}${i}`}),It=e=>Y(t=>{const r=nl(Math.abs(t));return t<0?`-${r}`:r}),Fn=({locale:e,intlOptions:t})=>{const r=ue(e,{maximumFractionDigits:0,...Ne,...t});return Y(n=>r.format(n))},Bn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>ue(e,{...Lt(n,t.decimals),...Ne,...r,style:"percent"}).format(n)),Tt=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=al(e);return Tt(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Lt=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},al=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},il=1440*60*1e3,ol=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",...R,...t});return L(n=>r.format(n))},sl=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",timeStyle:"medium",...R,...t});return L(n=>ll(r.formatToParts(n)))},Gn=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"long",...R,...t});return L(n=>r.format(n))},Hn=({locale:e,intlOptions:t})=>{const r=w(e,{month:"long",...R,...t});return L(n=>r.format(n))},Et=({locale:e,intlOptions:t})=>{const r=w(e,{month:"short",year:"numeric",...R,...t});return L(n=>r.format(n))},Rt=e=>L(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),$n=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"long",...R,...t,year:void 0});return L(n=>r.formatRange(n,Kn(n,6)))},Yn=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",...R,...t});return L(n=>r.formatRange(n,Kn(n,6)))},wt=({locale:e,intlOptions:t})=>{const r=w(e,{year:"numeric",...R,...t});return L(n=>r.format(n))},zn=({locale:e,intlOptions:t})=>{const r=w(e,{timeStyle:"short",...R,...t});return L(n=>r.format(n))},Kn=(e,t)=>new Date(e.getTime()+t*il),ll=e=>{const t=e.findIndex(n=>n.type==="hour")-1,r=e[t];return e.map((n,a)=>a===t&&r?.type==="literal"&&r.value===", "?" • ":n.value).join("")},br=1e3,cl=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Y(a=>{const i={...Pt(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Ct(a,t,i)}),ul=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Pt(n,t),notation:"compact",...r};return Ct(n,e,a)}),dl=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Pt(n,t),notation:"compact",...r,style:"percent"};return Ct(n,e,a)}),Ct=(e,t,r)=>ue(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Un=e=>Math.abs(e)>br?Un(e/br):Number.isInteger(e),ml=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Pt=(e,t)=>Un(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:ml(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,hl(t))},hl=e=>{const t=e.filter(u=>typeof u=="number"&&Number.isFinite(u)),r=t[0],n=t[1];if(r===void 0||n===void 0)return 0;const a=Math.abs(n-r);if(a===0)return 0;let i=0;for(const u of t)i=Math.max(i,Math.abs(u));if(i===0)return 0;const o=Math.floor(Math.log10(i)/3),s=a/10**(Math.max(0,o)*3);if(s>=1)return 0;const c=Math.ceil(-Math.log10(s)-1e-9);return Math.min(4,Math.max(0,c))},pl=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"short",...R,...t});return L(n=>r.format(n))},fl=({locale:e,intlOptions:t})=>{const r=w(e,{month:"short",...R,...t});return L(n=>r.format(n))},gl=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"short",...R,...t});return L(n=>r.format(n))},vl=({locale:e,intlOptions:t})=>{const r=w(e,{timeStyle:"short",...R,...t});return L(n=>r.format(n))},Mt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return cl(e);case"date":case"datetime":return pl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return gl(e);case"decimal":case"integer":return ul(e);case"duration":return It(e);case"month":return fl(e);case"month_year":return Et(e);case"percentage":return dl(e);case"quarter":return Rt(e);case"text":return At(e);case"time":return vl(e);case"year":return wt(e);case"lookup":return Mt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},yl=.9,Sl=1/3,bl=1/4,xl=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Al(e):Il(e),Al=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Wn(e.ticks,n),s=Tl(e.ticks,r.width),c=s*yl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=dt(c);return{...e,ticks:ut(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=dt(r.height*Sl);return{...e,ticks:ut(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Il=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Wn(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=dt(r.width*bl);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:ut(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Tl=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Wn=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},ut=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:On(i.formattedLabel,r,a)})},dt=e=>Math.max(0,Math.floor(e)),Ll=(e,t,r,n,a)=>{if(e===0)return!0;const i=r==="top"||r==="bottom",o=i?60:40;let s=n-(e-1)*o;for(let c=0;c<e;c+=1){const{width:u,height:d}=a(t(c));if(s-=i?u:d,s<0)return!1}return!0},El={ticks:[],labelAt:()=>""},Rl=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const f=o.get(p);if(f)return f;const g=a[p],y=g?Cl(g.ticks,n(g)):El;return o.set(p,y),y};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1,{ticks:f,labelAt:g}=s(p);Ll(f.length,g,i,t,r)?(d=p,c=p+1):u=p-1}const h=wl(d,s);return Pl(s(h))},wl=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Ml(a,i))return n}return 0},Cl=(e,t)=>{const r=new Array(e.length);return{ticks:e,labelAt:n=>{const a=r[n];if(a!==void 0)return a;const i=t(e[n]?.value??null);return r[n]=i,i}}},Pl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Ml=(e,t)=>{const r=new Set;for(let n=0;n<e.length;n+=1){const a=t(n);if(r.has(a))return!1;r.add(a)}return!0},Dl=e=>{const t=I({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=I({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},I=e=>{switch(e.valueFormat.type){case"currency":return Vn(e);case"date":return ol(e);case"datetime":return sl(e);case"day_month":return Gn(e);case"decimal":return Nn(e);case"duration":return It(e);case"integer":return Fn(e);case"month":return Hn(e);case"month_year":return Et(e);case"percentage":return Bn(e);case"quarter":return Rt(e);case"text":return At(e);case"weekly_date_range":return $n(e);case"weekly_date_range_with_year":return Yn(e);case"year":return wt(e);case"time":return zn(e);case"lookup":return Dl({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Dt({layer:e,numberFormat:t,locale:r}){return I({valueFormat:m.getLayerYValueFormat(e),locale:r,numberFormat:t})}var Ol=(e,t)=>{const r=l.readVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:m.createXValueReader(e,t),variable:r}:{read:m.getGroup,variable:l.GROUP_VARIABLES.group}},Xn=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:c})=>{const u=Dt({layer:e,numberFormat:n,locale:s}),d=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,styleReaders:o.geom(e),formatLabel:Fl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:d}),formatAbsolute:u,formatCategory:_l({layer:e,numberFormat:n,locale:s})}},_l=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Ol(e.data,e.mapping),i=I({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},kl=(e,t,r)=>{switch(t){case"stack":return Vl(e);case"fill":return Nl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Vl=e=>{const t=l.readVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(m.getObservationXKey(a,t));return s===void 0?null:s.total}},Nl=(e,t)=>{const r=t?l.getXMin:l.getYMin,n=t?l.getXMax:l.getYMax,a=m.createSegmentYReader(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Fl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=m.createRawValueReader(e.data,e.dataLabels.labelSource),c=kl(e,i,o),u=Bl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&qn(e);return p=>{const f=s(p);if(f===null)return"";if(!h||!l.isStrictNumericDataValue(f))return u(f,p);const g=c(p);return g===null||g===0?u(f,p):d(f/g)}},Bl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(qn(e))return a;const s=Gl(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Hl(e.data,i),locale:n,numberFormat:t})},qn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(m.resolveSegmentYSource(e.position,e.mapping))},Gl=(e,t,r,n,a)=>{const i=l.readVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:I({valueFormat:o.valueFormat,locale:n,numberFormat:r})},Hl=(e,t)=>{const r=l.readConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.readVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},$l={cartesian:["cartesian","flip"],polar:["polar"]},Yl=null;function jn(e=[]){const t=zl(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!$l[a].some(o=>i.dataLabelCoordTypes.includes(o))?null:{place:i.getDataLabelPlacements.bind(i),getPercentageValueStrategy:o=>i.resolvePercentageValueStrategy?.(o,a)??"none"}};return{resolve:r,hasCapability:(n,a)=>r(n,a)!==null,hasPercentageFormat:(n,a)=>(r(n.geom,a)?.getPercentageValueStrategy(n)??"none")!=="none"}}function Ot(){return Yl??=jn()}function zl(e){const t=new l.GeomRegistry;for(const r of e){const n=l.resolveDefinition(r);n instanceof l.Geom&&t.register(n.type,n)}return t}function*Kl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Ot()}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const u of e){if(!u.dataLabels.showDataLabels&&!u.dataLabels.showStackTotals)continue;const d=c.resolve(u.geom,"cartesian");if(d===null)continue;const h=Xn({layer:u,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:d.getPercentageValueStrategy(u)});for(const p of d.place(h).labels)yield{x:a.x+p.x-p.width/2,y:a.y+p.y-p.height/2,width:p.width,height:p.height}}}var Qe={abbreviation:"none",decimals:"auto"},Zn=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":{const i=n-r,o=I({valueFormat:a,locale:e,numberFormat:Qe,intlOptions:{signDisplay:"always"}})(i);return xr(o)?"0":o}case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/Math.abs(r);if(o===Number.POSITIVE_INFINITY)return"∞";if(o===Number.NEGATIVE_INFINITY)return"-∞";const s=I({valueFormat:{type:"percentage"},locale:e,numberFormat:Qe,intlOptions:{signDisplay:"always"}})(o);return xr(s)?"0%":s}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${I({valueFormat:{type:"decimal"},locale:e,numberFormat:Qe,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},xr=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Ul=2,Wl=6,Xl=6,ql=15,jl=15,Zl=2.5,Jl=.5,Ql=.25,Jn=e=>{const t=e-Ul,r=1+Jl*t,n=1+Ql*t;return{arrowStartGap:Wl*r,arrowEndGap:Xl*r,offsetFromHigherObservation:ql*n,arrowheadSize:Zl*e,curveRadius:jl*n,strokeWidth:e}},ec=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},tc=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./annotations-6ONVHjKW.cjs"),m=require("./compiler--1GEomjr.cjs"),b=require("./spec-builder-BJG0JDPn.cjs");let el=require("lodash-es"),ie=require("lodash-es/clamp");ie=l.__toESM(ie,1);let ct=require("humanize-duration");ct=l.__toESM(ct,1);let E=require("d3-shape"),tl=require("d3-delaunay"),Ce=require("lodash-es/isEqual");Ce=l.__toESM(Ce,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1790778920035");var rl=1e6;function _(e){return String(Math.round(e*rl))}function W(e,t){return e.geom===t}var Je="…",On=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Je)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Je)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Je};var R={timeZone:"UTC"},L=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Y=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",At=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",Se=new Map,be=new Map,_n=256,ue=(e,t)=>{const r=kn(e,t),n=Se.get(r);if(n!==void 0)return n;Se.size>=_n&&Se.clear();const a=new Intl.NumberFormat(e,t);return Se.set(r,a),a},w=(e,t)=>{const r=kn(e,t),n=be.get(r);if(n!==void 0)return n;be.size>=_n&&be.clear();const a=new Intl.DateTimeFormat(e,t);return be.set(r,a),a},kn=(e,t)=>`${e}\0${JSON.stringify(t)}`,nl=ct.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ne={signDisplay:"negative"},Vn=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Y(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Lt(a,i),{base:s,suffix:c}=Tt(a,r.abbreviation);return`${ue(t,{...o,...Ne,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),Nn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>{const{base:a,suffix:i}=Tt(n,t.abbreviation);return`${ue(e,{...Lt(a,t.decimals),...Ne,...r}).format(a)}${i}`}),It=e=>Y(t=>{const r=nl(Math.abs(t));return t<0?`-${r}`:r}),Fn=({locale:e,intlOptions:t})=>{const r=ue(e,{maximumFractionDigits:0,...Ne,...t});return Y(n=>r.format(n))},Bn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>ue(e,{...Lt(n,t.decimals),...Ne,...r,style:"percent"}).format(n)),Tt=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=al(e);return Tt(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Lt=(e,t)=>{if(typeof t=="number")return{minimumFractionDigits:t,maximumFractionDigits:t};const r=Math.ceil(Math.log10(Math.abs(e))),n=r>=3?0:r===2?1:2;return{minimumFractionDigits:t==="auto"?0:n,maximumFractionDigits:n}},al=e=>{const t=Math.abs(e);return t>=l.SUFFIX_MULTIPLIERS.b?"b":t>=l.SUFFIX_MULTIPLIERS.m?"m":t>=l.SUFFIX_MULTIPLIERS.k?"k":"none"},il=1440*60*1e3,ol=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",...R,...t});return L(n=>r.format(n))},sl=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",timeStyle:"medium",...R,...t});return L(n=>ll(r.formatToParts(n)))},Gn=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"long",...R,...t});return L(n=>r.format(n))},Hn=({locale:e,intlOptions:t})=>{const r=w(e,{month:"long",...R,...t});return L(n=>r.format(n))},Et=({locale:e,intlOptions:t})=>{const r=w(e,{month:"short",year:"numeric",...R,...t});return L(n=>r.format(n))},Rt=e=>L(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),$n=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"long",...R,...t,year:void 0});return L(n=>r.formatRange(n,Kn(n,6)))},Yn=({locale:e,intlOptions:t})=>{const r=w(e,{dateStyle:"medium",...R,...t});return L(n=>r.formatRange(n,Kn(n,6)))},wt=({locale:e,intlOptions:t})=>{const r=w(e,{year:"numeric",...R,...t});return L(n=>r.format(n))},zn=({locale:e,intlOptions:t})=>{const r=w(e,{timeStyle:"short",...R,...t});return L(n=>r.format(n))},Kn=(e,t)=>new Date(e.getTime()+t*il),ll=e=>{const t=e.findIndex(n=>n.type==="hour")-1,r=e[t];return e.map((n,a)=>a===t&&r?.type==="literal"&&r.value===", "?" • ":n.value).join("")},br=1e3,cl=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Y(a=>{const i={...Pt(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Ct(a,t,i)}),ul=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Pt(n,t),notation:"compact",...r};return Ct(n,e,a)}),dl=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Pt(n,t),notation:"compact",...r,style:"percent"};return Ct(n,e,a)}),Ct=(e,t,r)=>ue(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Un=e=>Math.abs(e)>br?Un(e/br):Number.isInteger(e),ml=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Pt=(e,t)=>Un(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:ml(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,hl(t))},hl=e=>{const t=e.filter(u=>typeof u=="number"&&Number.isFinite(u)),r=t[0],n=t[1];if(r===void 0||n===void 0)return 0;const a=Math.abs(n-r);if(a===0)return 0;let i=0;for(const u of t)i=Math.max(i,Math.abs(u));if(i===0)return 0;const o=Math.floor(Math.log10(i)/3),s=a/10**(Math.max(0,o)*3);if(s>=1)return 0;const c=Math.ceil(-Math.log10(s)-1e-9);return Math.min(4,Math.max(0,c))},pl=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"short",...R,...t});return L(n=>r.format(n))},fl=({locale:e,intlOptions:t})=>{const r=w(e,{month:"short",...R,...t});return L(n=>r.format(n))},gl=({locale:e,intlOptions:t})=>{const r=w(e,{day:"numeric",month:"short",...R,...t});return L(n=>r.format(n))},vl=({locale:e,intlOptions:t})=>{const r=w(e,{timeStyle:"short",...R,...t});return L(n=>r.format(n))},Mt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return cl(e);case"date":case"datetime":return pl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return gl(e);case"decimal":case"integer":return ul(e);case"duration":return It(e);case"month":return fl(e);case"month_year":return Et(e);case"percentage":return dl(e);case"quarter":return Rt(e);case"text":return At(e);case"time":return vl(e);case"year":return wt(e);case"lookup":return Mt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},yl=.9,Sl=1/3,bl=1/4,xl=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Al(e):Il(e),Al=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Wn(e.ticks,n),s=Tl(e.ticks,r.width),c=s*yl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=dt(c);return{...e,ticks:ut(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=dt(r.height*Sl);return{...e,ticks:ut(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Il=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Wn(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=dt(r.width*bl);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:ut(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Tl=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Wn=(e,t)=>{const r=[];let n=0,a=0;for(const i of e){const{width:o,height:s}=t(i.formattedLabel);r.push(o),o>n&&(n=o),s>a&&(a=s)}return{widths:r,maxWidth:n,maxHeight:a}},ut=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:On(i.formattedLabel,r,a)})},dt=e=>Math.max(0,Math.floor(e)),Ll=(e,t,r,n,a)=>{if(e===0)return!0;const i=r==="top"||r==="bottom",o=i?60:40;let s=n-(e-1)*o;for(let c=0;c<e;c+=1){const{width:u,height:d}=a(t(c));if(s-=i?u:d,s<0)return!1}return!0},El={ticks:[],labelAt:()=>""},Rl=({axis:e,availableSpacePx:t,measureLabel:r,resolveFormatter:n})=>{const{tickCandidates:a,position:i}=e;if(a.length===0)return[];const o=new Map,s=p=>{const f=o.get(p);if(f)return f;const g=a[p],y=g?Cl(g.ticks,n(g)):El;return o.set(p,y),y};let c=0,u=a.length-1,d=-1;for(;c<=u;){const p=c+u>>>1,{ticks:f,labelAt:g}=s(p);Ll(f.length,g,i,t,r)?(d=p,c=p+1):u=p-1}const h=wl(d,s);return Pl(s(h))},wl=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Ml(a,i))return n}return 0},Cl=(e,t)=>{const r=new Array(e.length);return{ticks:e,labelAt:n=>{const a=r[n];if(a!==void 0)return a;const i=t(e[n]?.value??null);return r[n]=i,i}}},Pl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Ml=(e,t)=>{const r=new Set;for(let n=0;n<e.length;n+=1){const a=t(n);if(r.has(a))return!1;r.add(a)}return!0},Dl=e=>{const t=I({...e,valueFormat:e.valueFormat.fallback}),r={};for(const[a,i]of Object.entries(e.valueFormat.cases))r[a]=I({...e,valueFormat:i});const n=e.valueFormat.byVariable;return(a,i)=>{if(i===void 0||i[n]===void 0)return t(a);const o=l.getStableKey(i[n]),s=r[o];return s!==void 0?s(a,i):t(a)}},I=e=>{switch(e.valueFormat.type){case"currency":return Vn(e);case"date":return ol(e);case"datetime":return sl(e);case"day_month":return Gn(e);case"decimal":return Nn(e);case"duration":return It(e);case"integer":return Fn(e);case"month":return Hn(e);case"month_year":return Et(e);case"percentage":return Bn(e);case"quarter":return Rt(e);case"text":return At(e);case"weekly_date_range":return $n(e);case"weekly_date_range_with_year":return Yn(e);case"year":return wt(e);case"time":return zn(e);case"lookup":return Dl({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Dt({layer:e,numberFormat:t,locale:r}){return I({valueFormat:m.getLayerYValueFormat(e),locale:r,numberFormat:t})}var Ol=(e,t)=>{const r=l.readVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:m.createXValueReader(e,t),variable:r}:{read:m.getGroup,variable:l.GROUP_VARIABLES.group}},Xn=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:c})=>{const u=Dt({layer:e,numberFormat:n,locale:s}),d=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,styleReaders:o.geom(e),formatLabel:Fl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:d}),formatAbsolute:u,formatCategory:_l({layer:e,numberFormat:n,locale:s})}},_l=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Ol(e.data,e.mapping),i=I({valueFormat:e.data.hasVariable(a)?e.data.getValueFormat(a):{type:"text"},locale:r,numberFormat:t});return o=>{const s=n(o);return s===null?null:i(s,o)}},kl=(e,t,r)=>{switch(t){case"stack":return Vl(e);case"fill":return Nl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Vl=e=>{const t=l.readVariableName(e.mapping.x);let r=null,n=!1;return a=>{const i=e.summary.stackTotals;if(i===void 0||i.length===0||t===null)return null;if(!n){r=new Map;for(const c of i)r.set(c.xKey,c);n=!0}const o=a[t];if(o==null)return null;const s=r?.get(m.getObservationXKey(a,t));return s===void 0?null:s.total}},Nl=(e,t)=>{const r=t?l.getXMin:l.getYMin,n=t?l.getXMax:l.getYMax,a=m.createSegmentYReader(e);return i=>{const o=r(i),s=n(i);if(!l.isStrictNumericDataValue(o)||!l.isStrictNumericDataValue(s))return null;const c=Math.abs(s-o);if(c===0)return null;const u=a(i);return l.isStrictNumericDataValue(u)?u/c:null}},Fl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=m.createRawValueReader(e.data,e.dataLabels.labelSource),c=kl(e,i,o),u=Bl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&qn(e);return p=>{const f=s(p);if(f===null)return"";if(!h||!l.isStrictNumericDataValue(f))return u(f,p);const g=c(p);return g===null||g===0?u(f,p):d(f/g)}},Bl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(qn(e))return a;const s=Gl(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Hl(e.data,i),locale:n,numberFormat:t})},qn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(m.resolveSegmentYSource(e.position,e.mapping))},Gl=(e,t,r,n,a)=>{const i=l.readVariableName(e.mapping.x);if(i===null||i!==a)return null;const o=t.find(s=>s.scaleAestheticKey==="x");return o===void 0?null:I({valueFormat:o.valueFormat,locale:n,numberFormat:r})},Hl=(e,t)=>{const r=l.readConstantValue(t);if(r!==void 0)return l.isNumericDataValue(r)?{type:"decimal"}:l.isTemporalDataValue(r)?{type:"date"}:{type:"text"};const n=l.readVariableName(t);return n===null||!e.hasVariable(n)?{type:"text"}:e.getValueFormat(n)},$l={cartesian:["cartesian","flip"],polar:["polar"]},Yl=null;function jn(e=[]){const t=zl(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!$l[a].some(o=>i.dataLabelCoordTypes.includes(o))?null:{place:i.getDataLabelPlacements.bind(i),getPercentageValueStrategy:o=>i.resolvePercentageValueStrategy?.(o,a)??"none"}};return{resolve:r,hasCapability:(n,a)=>r(n,a)!==null,hasPercentageFormat:(n,a)=>(r(n.geom,a)?.getPercentageValueStrategy(n)??"none")!=="none"}}function Ot(){return Yl??=jn()}function zl(e){const t=new l.GeomRegistry;for(const r of e){const n=l.resolveDefinition(r);n instanceof l.Geom&&t.register(n.type,n)}return t}function*Kl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Ot()}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const u of e){if(!u.dataLabels.showDataLabels&&!u.dataLabels.showStackTotals)continue;const d=c.resolve(u.geom,"cartesian");if(d===null)continue;const h=Xn({layer:u,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:d.getPercentageValueStrategy(u)});for(const p of d.place(h).labels)yield{x:a.x+p.x-p.width/2,y:a.y+p.y-p.height/2,width:p.width,height:p.height}}}var Qe={abbreviation:"none",decimals:"auto"},Zn=({locale:e,kind:t,startValue:r,endValue:n,valueFormat:a})=>{if(r===null||n===null)return"n/a";switch(t){case"absolute-difference":{const i=n-r,o=I({valueFormat:a,locale:e,numberFormat:Qe,intlOptions:{signDisplay:"always"}})(i);return xr(o)?"0":o}case"relative-difference":{const i=n-r;if(i===0)return"0%";const o=i/Math.abs(r);if(o===Number.POSITIVE_INFINITY)return"∞";if(o===Number.NEGATIVE_INFINITY)return"-∞";const s=I({valueFormat:{type:"percentage"},locale:e,numberFormat:Qe,intlOptions:{signDisplay:"always"}})(o);return xr(s)?"0%":s}case"proportion":{if(n-r===0)return"=";const i=n/r;return i===Number.POSITIVE_INFINITY?"∞":i===Number.NEGATIVE_INFINITY?"-∞":`${I({valueFormat:{type:"decimal"},locale:e,numberFormat:Qe,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},xr=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Ul=2,Wl=6,Xl=6,ql=15,jl=15,Zl=2.5,Jl=.5,Ql=.25,Jn=e=>{const t=e-Ul,r=1+Jl*t,n=1+Ql*t;return{arrowStartGap:Wl*r,arrowEndGap:Xl*r,offsetFromHigherObservation:ql*n,arrowheadSize:Zl*e,curveRadius:jl*n,strokeWidth:e}},ec=(e,t,r,n)=>{const a=n.offsetFromHigherObservation+n.arrowheadSize+n.arrowEndGap;return e?Math.max(t.x,r.x)+a:Math.min(t.y,r.y)-a},tc=(e,t,r,{arrowStartGap:n,arrowEndGap:a,curveRadius:i})=>{const o={x:e.x,y:e.y-n},s={x:e.x,y:r},c={x:t.x,y:r},u={x:t.x,y:t.y-a},d=t.x>e.x?1:-1;return`
2
2
  M ${o.x} ${o.y}
3
3
  L ${s.x} ${s.y+i}
4
4
  Q ${s.x} ${s.y} ${s.x+d*i} ${s.y}
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ import ql from "humanize-duration";
7
7
  import { area as Ua, curveCatmullRom as Zl, curveLinear as Jl, line as ja, symbol as Xa, symbolCircle as Ql, symbolCross as ec, symbolDiamond as tc, symbolSquare as rc, symbolStar as nc, symbolTriangle as ac, symbolWye as ic } from "d3-shape";
8
8
  import { Delaunay as sc } from "d3-delaunay";
9
9
  import qa from "lodash-es/isEqual";
10
- typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.9.0-beta.1790776416986");
10
+ typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.9.0-beta.1790778920035");
11
11
  var oc = 1e6;
12
12
  function z(e) {
13
13
  return String(Math.round(e * oc));
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "grammar-of-graphics",
12
12
  "compiler"
13
13
  ],
14
- "version": "1.9.0-beta.1790776416986",
14
+ "version": "1.9.0-beta.1790778920035",
15
15
  "type": "module",
16
16
  "sideEffects": [
17
17
  "**/version.ts"