@graphysdk/viz-engine 1.9.0-beta.1790931976211 → 1.9.0-beta.1790945154264
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 +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./annotations-XWlM1CVD.cjs"),m=require("./compiler-TKut3jlO.cjs"),b=require("./spec-builder-DY80ERYd.cjs");let Qs=require("lodash-es"),ae=require("lodash-es/clamp");ae=l.__toESM(ae,1);let lt=require("humanize-duration");lt=l.__toESM(lt,1);let R=require("d3-shape"),el=require("d3-delaunay"),we=require("lodash-es/isEqual");we=l.__toESM(we,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1790931976211");var tl=1e6;function k(e){return String(Math.round(e*tl))}function U(e,t){return e.geom===t}var Ze="…",Dn=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Ze)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Ze)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Ze};var L={timeZone:"UTC"},T=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Y=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",xt=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ye=new Map,Se=new Map,On=256,ce=(e,t)=>{const r=_n(e,t),n=ye.get(r);if(n!==void 0)return n;ye.size>=On&&ye.clear();const a=new Intl.NumberFormat(e,t);return ye.set(r,a),a},E=(e,t)=>{const r=_n(e,t),n=Se.get(r);if(n!==void 0)return n;Se.size>=On&&Se.clear();const a=new Intl.DateTimeFormat(e,t);return Se.set(r,a),a},_n=(e,t)=>`${e}\0${JSON.stringify(t)}`,rl=lt.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ve={signDisplay:"negative"},kn=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Y(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Tt(a,i),{base:s,suffix:c}=It(a,r.abbreviation);return`${ce(t,{...o,...Ve,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),Vn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>{const{base:a,suffix:i}=It(n,t.abbreviation);return`${ce(e,{...Tt(a,t.decimals),...Ve,...r}).format(a)}${i}`}),At=e=>Y(t=>{const r=rl(Math.abs(t));return t<0?`-${r}`:r}),Nn=({locale:e,intlOptions:t})=>{const r=ce(e,{maximumFractionDigits:0,...Ve,...t});return Y(n=>r.format(n))},Fn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>ce(e,{...Tt(n,t.decimals),...Ve,...r,style:"percent"}).format(n)),It=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=nl(e);return It(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Tt=(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}},nl=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"},al=1440*60*1e3,il=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.format(n))},ol=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",timeStyle:"medium",...L,...t});return T(n=>sl(r.formatToParts(n)))},Bn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t});return T(n=>r.format(n))},Gn=({locale:e,intlOptions:t})=>{const r=E(e,{month:"long",...L,...t});return T(n=>r.format(n))},Lt=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",year:"numeric",...L,...t});return T(n=>r.format(n))},Et=e=>T(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Hn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t,year:void 0});return T(n=>r.formatRange(n,zn(n,6)))},$n=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.formatRange(n,zn(n,6)))},Rt=({locale:e,intlOptions:t})=>{const r=E(e,{year:"numeric",...L,...t});return T(n=>r.format(n))},Yn=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},zn=(e,t)=>new Date(e.getTime()+t*al),sl=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("")},Sr=1e3,ll=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Y(a=>{const i={...Ct(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return wt(a,t,i)}),cl=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Ct(n,t),notation:"compact",...r};return wt(n,e,a)}),ul=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Ct(n,t),notation:"compact",...r,style:"percent"};return wt(n,e,a)}),wt=(e,t,r)=>ce(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Kn=e=>Math.abs(e)>Sr?Kn(e/Sr):Number.isInteger(e),dl=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Ct=(e,t)=>Kn(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:dl(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,ml(t))},ml=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))},hl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},pl=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",...L,...t});return T(n=>r.format(n))},fl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},gl=({locale:e,intlOptions:t,tickValues:r})=>{const n=E(e,{...yl(r),...L,...t});return T(a=>n.format(a))},vl=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},yl=e=>{const t=e.filter(r=>r instanceof Date&&!Number.isNaN(r.getTime()));return t.length===0?{day:"numeric",month:"short"}:Sl(t).size>1?{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}:{timeStyle:"short"}},Sl=e=>{const t=new Set;for(const r of e)t.add(`${r.getUTCFullYear()}-${r.getUTCMonth()}-${r.getUTCDate()}`);return t},Pt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ll(e);case"date":return hl(e);case"datetime":return gl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return fl(e);case"decimal":case"integer":return cl(e);case"duration":return At(e);case"month":return pl(e);case"month_year":return Lt(e);case"percentage":return ul(e);case"quarter":return Et(e);case"text":return xt(e);case"time":return vl(e);case"year":return Rt(e);case"lookup":return Pt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},bl=.9,xl=1/3,Al=1/4,Il=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Tl(e):Ll(e),Tl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Un(e.ticks,n),s=El(e.ticks,r.width),c=s*bl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=ut(c);return{...e,ticks:ct(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=ut(r.height*xl);return{...e,ticks:ct(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Ll=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Un(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=ut(r.width*Al);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:ct(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},El=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Un=(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}},ct=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Dn(i.formattedLabel,r,a)})},ut=e=>Math.max(0,Math.floor(e)),Rl=(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},wl={ticks:[],labelAt:()=>""},Cl=({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?Ml(g.ticks,n(g)):wl;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);Rl(f.length,g,i,t,r)?(d=p,c=p+1):u=p-1}const h=Pl(d,s);return Dl(s(h))},Pl=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Ol(a,i))return n}return 0},Ml=(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}}},Dl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Ol=(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},_l=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 kn(e);case"date":return il(e);case"datetime":return ol(e);case"day_month":return Bn(e);case"decimal":return Vn(e);case"duration":return At(e);case"integer":return Nn(e);case"month":return Gn(e);case"month_year":return Lt(e);case"percentage":return Fn(e);case"quarter":return Et(e);case"text":return xt(e);case"weekly_date_range":return Hn(e);case"weekly_date_range_with_year":return $n(e);case"year":return Rt(e);case"time":return Yn(e);case"lookup":return _l({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Mt({layer:e,numberFormat:t,locale:r}){return I({valueFormat:m.getLayerYValueFormat(e),locale:r,numberFormat:t})}var kl=(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}},Wn=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:c})=>{const u=Mt({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:Gl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:d}),formatAbsolute:u,formatCategory:Vl({layer:e,numberFormat:n,locale:s})}},Vl=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=kl(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)}},Nl=(e,t,r)=>{switch(t){case"stack":return Fl(e);case"fill":return Bl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Fl=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}},Bl=(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}},Gl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=m.createRawValueReader(e.data,e.dataLabels.labelSource),c=Nl(e,i,o),u=Hl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&Xn(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)}},Hl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(Xn(e))return a;const s=$l(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Yl(e.data,i),locale:n,numberFormat:t})},Xn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(m.resolveSegmentYSource(e.position,e.mapping))},$l=(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})},Yl=(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)},zl={cartesian:["cartesian","flip"],polar:["polar"]},Kl=null;function qn(e=[]){const t=Ul(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!zl[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 Dt(){return Kl??=qn()}function Ul(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*Wl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Dt()}){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=Wn({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 Je={abbreviation:"none",decimals:"auto"},jn=({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:Je,intlOptions:{signDisplay:"always"}})(i);return br(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:Je,intlOptions:{signDisplay:"always"}})(o);return br(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:Je,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},br=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Xl=2,ql=6,jl=6,Zl=15,Jl=15,Ql=2.5,ec=.5,tc=.25,Zn=e=>{const t=e-Xl,r=1+ec*t,n=1+tc*t;return{arrowStartGap:ql*r,arrowEndGap:jl*r,offsetFromHigherObservation:Zl*n,arrowheadSize:Ql*e,curveRadius:Jl*n,strokeWidth:e}},rc=(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},nc=(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-XWlM1CVD.cjs"),m=require("./compiler-TKut3jlO.cjs"),b=require("./spec-builder-DY80ERYd.cjs");let Qs=require("lodash-es"),ae=require("lodash-es/clamp");ae=l.__toESM(ae,1);let lt=require("humanize-duration");lt=l.__toESM(lt,1);let R=require("d3-shape"),el=require("d3-delaunay"),we=require("lodash-es/isEqual");we=l.__toESM(we,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1790945154264");var tl=1e6;function k(e){return String(Math.round(e*tl))}function U(e,t){return e.geom===t}var Ze="…",Dn=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(Ze)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+Ze)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+Ze};var L={timeZone:"UTC"},T=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},Y=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",xt=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",ye=new Map,Se=new Map,On=256,ce=(e,t)=>{const r=_n(e,t),n=ye.get(r);if(n!==void 0)return n;ye.size>=On&&ye.clear();const a=new Intl.NumberFormat(e,t);return ye.set(r,a),a},E=(e,t)=>{const r=_n(e,t),n=Se.get(r);if(n!==void 0)return n;Se.size>=On&&Se.clear();const a=new Intl.DateTimeFormat(e,t);return Se.set(r,a),a},_n=(e,t)=>`${e}\0${JSON.stringify(t)}`,rl=lt.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Ve={signDisplay:"negative"},kn=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>Y(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=Tt(a,i),{base:s,suffix:c}=It(a,r.abbreviation);return`${ce(t,{...o,...Ve,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),Vn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>{const{base:a,suffix:i}=It(n,t.abbreviation);return`${ce(e,{...Tt(a,t.decimals),...Ve,...r}).format(a)}${i}`}),At=e=>Y(t=>{const r=rl(Math.abs(t));return t<0?`-${r}`:r}),Nn=({locale:e,intlOptions:t})=>{const r=ce(e,{maximumFractionDigits:0,...Ve,...t});return Y(n=>r.format(n))},Fn=({locale:e,numberFormat:t,intlOptions:r})=>Y(n=>ce(e,{...Tt(n,t.decimals),...Ve,...r,style:"percent"}).format(n)),It=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=nl(e);return It(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},Tt=(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}},nl=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"},al=1440*60*1e3,il=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.format(n))},ol=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",timeStyle:"medium",...L,...t});return T(n=>sl(r.formatToParts(n)))},Bn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t});return T(n=>r.format(n))},Gn=({locale:e,intlOptions:t})=>{const r=E(e,{month:"long",...L,...t});return T(n=>r.format(n))},Lt=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",year:"numeric",...L,...t});return T(n=>r.format(n))},Et=e=>T(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Hn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t,year:void 0});return T(n=>r.formatRange(n,zn(n,6)))},$n=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.formatRange(n,zn(n,6)))},Rt=({locale:e,intlOptions:t})=>{const r=E(e,{year:"numeric",...L,...t});return T(n=>r.format(n))},Yn=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},zn=(e,t)=>new Date(e.getTime()+t*al),sl=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("")},Sr=1e3,ll=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>Y(a=>{const i={...Ct(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return wt(a,t,i)}),cl=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Ct(n,t),notation:"compact",...r};return wt(n,e,a)}),ul=({locale:e,tickValues:t,intlOptions:r})=>Y(n=>{const a={...Ct(n,t),notation:"compact",...r,style:"percent"};return wt(n,e,a)}),wt=(e,t,r)=>ce(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Kn=e=>Math.abs(e)>Sr?Kn(e/Sr):Number.isInteger(e),dl=e=>{if(e.length<2)return!1;const[t,r]=e;return typeof t!="number"||typeof r!="number"?!1:Math.abs(r-t)<1},Ct=(e,t)=>Kn(e)?{minimumFractionDigits:0,maximumFractionDigits:0}:dl(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,ml(t))},ml=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))},hl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},pl=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",...L,...t});return T(n=>r.format(n))},fl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},gl=({locale:e,intlOptions:t,tickValues:r})=>{const n=E(e,{...yl(r),...L,...t});return T(a=>n.format(a))},vl=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},yl=e=>{const t=e.filter(r=>r instanceof Date&&!Number.isNaN(r.getTime()));return t.length===0?{day:"numeric",month:"short"}:Sl(t).size>1?{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}:{timeStyle:"short"}},Sl=e=>{const t=new Set;for(const r of e)t.add(`${r.getUTCFullYear()}-${r.getUTCMonth()}-${r.getUTCDate()}`);return t},Pt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ll(e);case"date":return hl(e);case"datetime":return gl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return fl(e);case"decimal":case"integer":return cl(e);case"duration":return At(e);case"month":return pl(e);case"month_year":return Lt(e);case"percentage":return ul(e);case"quarter":return Et(e);case"text":return xt(e);case"time":return vl(e);case"year":return Rt(e);case"lookup":return Pt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},bl=.9,xl=1/3,Al=1/4,Il=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Tl(e):Ll(e),Tl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Un(e.ticks,n),s=El(e.ticks,r.width),c=s*bl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const d=ut(c);return{...e,ticks:ct(e.ticks,a,d,n),labelRotation:0,labelMaxWidthPx:d}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=ut(r.height*xl);return{...e,ticks:ct(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},Ll=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=Un(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=ut(r.width*Al);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:ct(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},El=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},Un=(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}},ct=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Dn(i.formattedLabel,r,a)})},ut=e=>Math.max(0,Math.floor(e)),Rl=(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},wl={ticks:[],labelAt:()=>""},Cl=({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?Ml(g.ticks,n(g)):wl;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);Rl(f.length,g,i,t,r)?(d=p,c=p+1):u=p-1}const h=Pl(d,s);return Dl(s(h))},Pl=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Ol(a,i))return n}return 0},Ml=(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}}},Dl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Ol=(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},_l=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 kn(e);case"date":return il(e);case"datetime":return ol(e);case"day_month":return Bn(e);case"decimal":return Vn(e);case"duration":return At(e);case"integer":return Nn(e);case"month":return Gn(e);case"month_year":return Lt(e);case"percentage":return Fn(e);case"quarter":return Et(e);case"text":return xt(e);case"weekly_date_range":return Hn(e);case"weekly_date_range_with_year":return $n(e);case"year":return Rt(e);case"time":return Yn(e);case"lookup":return _l({...e,valueFormat:e.valueFormat});default:{const t=e.valueFormat;throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}}};function Mt({layer:e,numberFormat:t,locale:r}){return I({valueFormat:m.getLayerYValueFormat(e),locale:r,numberFormat:t})}var kl=(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}},Wn=({layer:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:c})=>{const u=Mt({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:Gl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:d}),formatAbsolute:u,formatCategory:Vl({layer:e,numberFormat:n,locale:s})}},Vl=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=kl(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)}},Nl=(e,t,r)=>{switch(t){case"stack":return Fl(e);case"fill":return Bl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},Fl=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}},Bl=(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}},Gl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=m.createRawValueReader(e.data,e.dataLabels.labelSource),c=Nl(e,i,o),u=Hl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),d=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&Xn(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)}},Hl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(Xn(e))return a;const s=$l(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Yl(e.data,i),locale:n,numberFormat:t})},Xn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(m.resolveSegmentYSource(e.position,e.mapping))},$l=(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})},Yl=(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)},zl={cartesian:["cartesian","flip"],polar:["polar"]},Kl=null;function qn(e=[]){const t=Ul(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!zl[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 Dt(){return Kl??=qn()}function Ul(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*Wl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Dt()}){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=Wn({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 Je={abbreviation:"none",decimals:"auto"},jn=({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:Je,intlOptions:{signDisplay:"always"}})(i);return br(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:Je,intlOptions:{signDisplay:"always"}})(o);return br(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:Je,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},br=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Xl=2,ql=6,jl=6,Zl=15,Jl=15,Ql=2.5,ec=.5,tc=.25,Zn=e=>{const t=e-Xl,r=1+ec*t,n=1+tc*t;return{arrowStartGap:ql*r,arrowEndGap:jl*r,offsetFromHigherObservation:Zl*n,arrowheadSize:Ql*e,curveRadius:Jl*n,strokeWidth:e}},rc=(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},nc=(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 Zl from "humanize-duration";
|
|
|
7
7
|
import { area as Ya, curveCatmullRom as Jl, curveLinear as Ql, line as Ua, symbol as ja, symbolCircle as ec, symbolCross as tc, symbolDiamond as rc, symbolSquare as nc, symbolStar as ac, symbolTriangle as ic, symbolWye as sc } from "d3-shape";
|
|
8
8
|
import { Delaunay as oc } from "d3-delaunay";
|
|
9
9
|
import Xa from "lodash-es/isEqual";
|
|
10
|
-
typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.9.0-beta.
|
|
10
|
+
typeof window < "u" && (window.__GRAPHY_SDK__ ??= {}, window.__GRAPHY_SDK__.vizEngine = "1.9.0-beta.1790945154264");
|
|
11
11
|
var lc = 1e6;
|
|
12
12
|
function z(e) {
|
|
13
13
|
return String(Math.round(e * lc));
|