@graphysdk/viz-engine 1.9.0-beta.1791362672521 → 1.9.0-beta.1791369792799
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 +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./annotations-yCWHP5d2.cjs"),d=require("./compiler-BrvFi5ri.cjs"),b=require("./spec-builder-B9z0zfzu.cjs");let St=require("lodash-es"),ne=require("lodash-es/clamp");ne=l.__toESM(ne,1);let at=require("humanize-duration");at=l.__toESM(at,1);let R=require("d3-shape"),al=require("d3-delaunay"),ae=require("lodash-es/isEqual");ae=l.__toESM(ae,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1791362672521");var il=1e6;function O(e){return String(Math.round(e*il))}function z(e,t){return e.geom===t}var We="…",Pn=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(We)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+We)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+We};var L={timeZone:"UTC"},T=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},$=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",bt=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",fe=new Map,ge=new Map,Dn=256,le=(e,t)=>{const r=_n(e,t),n=fe.get(r);if(n!==void 0)return n;fe.size>=Dn&&fe.clear();const a=new Intl.NumberFormat(e,t);return fe.set(r,a),a},E=(e,t)=>{const r=_n(e,t),n=ge.get(r);if(n!==void 0)return n;ge.size>=Dn&&ge.clear();const a=new Intl.DateTimeFormat(e,t);return ge.set(r,a),a},_n=(e,t)=>`${e}\0${JSON.stringify(t)}`,ol=at.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Pe={signDisplay:"negative"},On=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>$(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=It(a,i),{base:s,suffix:c}=At(a,r.abbreviation);return`${le(t,{...o,...Pe,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),kn=({locale:e,numberFormat:t,intlOptions:r})=>$(n=>{const{base:a,suffix:i}=At(n,t.abbreviation);return`${le(e,{...It(a,t.decimals),...Pe,...r}).format(a)}${i}`}),xt=e=>$(t=>{const r=ol(Math.abs(t));return t<0?`-${r}`:r}),Vn=({locale:e,intlOptions:t})=>{const r=le(e,{maximumFractionDigits:0,...Pe,...t});return $(n=>r.format(n))},Nn=({locale:e,numberFormat:t,intlOptions:r})=>$(n=>le(e,{...It(n,t.decimals),...Pe,...r,style:"percent"}).format(n)),At=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=sl(e);return At(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},It=(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}},sl=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"},ll=1440*60*1e3,cl=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.format(n))},ul=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",timeStyle:"medium",...L,...t});return T(n=>dl(r.formatToParts(n)))},Fn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t});return T(n=>r.format(n))},Bn=({locale:e,intlOptions:t})=>{const r=E(e,{month:"long",...L,...t});return T(n=>r.format(n))},Tt=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",year:"numeric",...L,...t});return T(n=>r.format(n))},Lt=e=>T(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Gn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t,year:void 0});return T(n=>r.formatRange(n,Yn(n,6)))},Hn=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.formatRange(n,Yn(n,6)))},Et=({locale:e,intlOptions:t})=>{const r=E(e,{year:"numeric",...L,...t});return T(n=>r.format(n))},$n=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},Yn=(e,t)=>new Date(e.getTime()+t*ll),dl=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("")},gr=1e3,ml=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>$(a=>{const i={...Ct(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Rt(a,t,i)}),hl=({locale:e,tickValues:t,intlOptions:r})=>$(n=>{const a={...Ct(n,t),notation:"compact",...r};return Rt(n,e,a)}),pl=({locale:e,tickValues:t,intlOptions:r})=>$(n=>{const a={...Ct(n,t),notation:"compact",...r,style:"percent"};return Rt(n,e,a)}),Rt=(e,t,r)=>le(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Kn=e=>Math.abs(e)>gr?Kn(e/gr):Number.isInteger(e),fl=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}:fl(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,gl(t))},gl=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))},vl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},yl=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",...L,...t});return T(n=>r.format(n))},Sl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},bl=({locale:e,intlOptions:t,tickValues:r})=>{const n=E(e,{...Al(r),...L,...t});return T(a=>n.format(a))},xl=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},Al=e=>{const t=e.filter(r=>r instanceof Date&&!Number.isNaN(r.getTime()));return t.length===0?{day:"numeric",month:"short"}:Il(t).size>1?{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}:{timeStyle:"short"}},Il=e=>{const t=new Set;for(const r of e)t.add(`${r.getUTCFullYear()}-${r.getUTCMonth()}-${r.getUTCDate()}`);return t},wt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ml(e);case"date":return vl(e);case"datetime":return bl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Sl(e);case"decimal":case"integer":return hl(e);case"duration":return xt(e);case"month":return yl(e);case"month_year":return Tt(e);case"percentage":return pl(e);case"quarter":return Lt(e);case"text":return bt(e);case"time":return xl(e);case"year":return Et(e);case"lookup":return wt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Tl=.9,Ll=1/3,El=1/4,Rl=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Cl(e):wl(e),Cl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=zn(e.ticks,n),s=Ml(e.ticks,r.width),c=s*Tl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const m=ot(c);return{...e,ticks:it(e.ticks,a,m,n),labelRotation:0,labelMaxWidthPx:m}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=ot(r.height*Ll);return{...e,ticks:it(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},wl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=zn(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=ot(r.width*El);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:it(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Ml=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},zn=(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}},it=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Pn(i.formattedLabel,r,a)})},ot=e=>Math.max(0,Math.floor(e)),Pl=(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:m}=a(t(c));if(s-=i?u:m,s<0)return!1}return!0},Dl={ticks:[],labelAt:()=>""},_l=({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?kl(g.ticks,n(g)):Dl;return o.set(p,y),y};let c=0,u=a.length-1,m=-1;for(;c<=u;){const p=c+u>>>1,{ticks:f,labelAt:g}=s(p);Pl(f.length,g,i,t,r)?(m=p,c=p+1):u=p-1}const h=Ol(m,s);return Vl(s(h))},Ol=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Nl(a,i))return n}return 0},kl=(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}}},Vl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Nl=(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},Fl=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 On(e);case"date":return cl(e);case"datetime":return ul(e);case"day_month":return Fn(e);case"decimal":return kn(e);case"duration":return xt(e);case"integer":return Vn(e);case"month":return Bn(e);case"month_year":return Tt(e);case"percentage":return Nn(e);case"quarter":return Lt(e);case"text":return bt(e);case"weekly_date_range":return Gn(e);case"weekly_date_range_with_year":return Hn(e);case"year":return Et(e);case"time":return $n(e);case"lookup":return Fl({...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:d.getLayerYValueFormat(e),locale:r,numberFormat:t})}var Bl=(e,t)=>{const r=l.readVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:d.createXValueReader(e,t),variable:r}:{read:d.getGroup,variable:l.GROUP_VARIABLES.group}},Un=({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}),m=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,styleReaders:o.geom(e),formatLabel:Kl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:m}),formatAbsolute:u,formatCategory:Gl({layer:e,numberFormat:n,locale:s})}},Gl=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Bl(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)}},Hl=(e,t,r)=>{switch(t){case"stack":return $l(e);case"fill":return Yl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},$l=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(d.getObservationXKey(a,t));return s===void 0?null:s.total}},Yl=(e,t)=>{const r=t?l.getXMin:l.getYMin,n=t?l.getXMax:l.getYMax,a=d.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}},Kl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=d.createRawValueReader(e.data,e.dataLabels.labelSource),c=Hl(e,i,o),u=zl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),m=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&Wn(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):m(f/g)}},zl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(Wn(e))return a;const s=Ul(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Wl(e.data,i),locale:n,numberFormat:t})},Wn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(d.resolveSegmentYSource(e.position,e.mapping))},Ul=(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})},Wl=(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)},Xl={cartesian:["cartesian","flip"],polar:["polar"]},ql=null;function Xn(e=[]){const t=jl(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!Xl[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 Pt(){return ql??=Xn()}function jl(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*Zl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Pt()}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const u of e){if(!u.dataLabels.showDataLabels&&!u.dataLabels.showStackTotals)continue;const m=c.resolve(u.geom,"cartesian");if(m===null)continue;const h=Un({layer:u,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:m.getPercentageValueStrategy(u)});for(const p of m.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 Xe={abbreviation:"none",decimals:"auto"},qn=({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:Xe,intlOptions:{signDisplay:"always"}})(i);return vr(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:Xe,intlOptions:{signDisplay:"always"}})(o);return vr(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:Xe,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},vr=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Jl=2,Ql=6,ec=6,tc=15,rc=15,nc=2.5,ac=.5,ic=.25,jn=e=>{const t=e-Jl,r=1+ac*t,n=1+ic*t;return{arrowStartGap:Ql*r,arrowEndGap:ec*r,offsetFromHigherObservation:tc*n,arrowheadSize:nc*e,curveRadius:rc*n,strokeWidth:e}},oc=(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},sc=(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},m=t.x>e.x?1:-1;return`
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./annotations-yCWHP5d2.cjs"),d=require("./compiler-BrvFi5ri.cjs"),b=require("./spec-builder-B9z0zfzu.cjs");let St=require("lodash-es"),ne=require("lodash-es/clamp");ne=l.__toESM(ne,1);let at=require("humanize-duration");at=l.__toESM(at,1);let R=require("d3-shape"),al=require("d3-delaunay"),ae=require("lodash-es/isEqual");ae=l.__toESM(ae,1);typeof window<"u"&&(window.__GRAPHY_SDK__??={},window.__GRAPHY_SDK__.vizEngine="1.9.0-beta.1791369792799");var il=1e6;function O(e){return String(Math.round(e*il))}function z(e,t){return e.geom===t}var We="…",Pn=(e,t,r)=>{if(t<=0||e.length===0)return"";if(r(e)<=t)return e;if(r(We)>t)return"";let n=0,a=e.length-1,i=0;for(;n<=a;){const o=n+a>>>1;r(e.slice(0,o)+We)<=t?(i=o,n=o+1):a=o-1}return e.slice(0,i)+We};var L={timeZone:"UTC"},T=e=>t=>{if(!l.isStrictTemporalDataValue(t))return"–";try{return e(t)}catch{return"n/a"}},$=e=>t=>l.isStrictNumericDataValue(t)?e(t):"–",bt=e=>t=>l.isStrictCategoricalDataValue(t)?t:"–",fe=new Map,ge=new Map,Dn=256,le=(e,t)=>{const r=_n(e,t),n=fe.get(r);if(n!==void 0)return n;fe.size>=Dn&&fe.clear();const a=new Intl.NumberFormat(e,t);return fe.set(r,a),a},E=(e,t)=>{const r=_n(e,t),n=ge.get(r);if(n!==void 0)return n;ge.size>=Dn&&ge.clear();const a=new Intl.DateTimeFormat(e,t);return ge.set(r,a),a},_n=(e,t)=>`${e}\0${JSON.stringify(t)}`,ol=at.default.humanizer({language:"en",spacer:"",delimiter:" ",languages:{en:{y:()=>"y",mo:()=>"mo",w:()=>"w",d:()=>"d",h:()=>"h",m:()=>"m",s:()=>"s",ms:()=>"ms"}}}),Pe={signDisplay:"negative"},On=({valueFormat:e,locale:t,numberFormat:r,intlOptions:n})=>$(a=>{const i=typeof r.decimals=="number"?r.decimals:2,o=It(a,i),{base:s,suffix:c}=At(a,r.abbreviation);return`${le(t,{...o,...Pe,...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n}).format(s)}${c}`}),kn=({locale:e,numberFormat:t,intlOptions:r})=>$(n=>{const{base:a,suffix:i}=At(n,t.abbreviation);return`${le(e,{...It(a,t.decimals),...Pe,...r}).format(a)}${i}`}),xt=e=>$(t=>{const r=ol(Math.abs(t));return t<0?`-${r}`:r}),Vn=({locale:e,intlOptions:t})=>{const r=le(e,{maximumFractionDigits:0,...Pe,...t});return $(n=>r.format(n))},Nn=({locale:e,numberFormat:t,intlOptions:r})=>$(n=>le(e,{...It(n,t.decimals),...Pe,...r,style:"percent"}).format(n)),At=(e,t="none")=>{switch(t){case"none":return{base:e,suffix:""};case"auto":{const r=sl(e);return At(e,r)}default:return{base:e/l.SUFFIX_MULTIPLIERS[t],suffix:t}}},It=(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}},sl=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"},ll=1440*60*1e3,cl=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.format(n))},ul=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",timeStyle:"medium",...L,...t});return T(n=>dl(r.formatToParts(n)))},Fn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t});return T(n=>r.format(n))},Bn=({locale:e,intlOptions:t})=>{const r=E(e,{month:"long",...L,...t});return T(n=>r.format(n))},Tt=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",year:"numeric",...L,...t});return T(n=>r.format(n))},Lt=e=>T(t=>`Q${Math.floor(t.getUTCMonth()/3)+1} ${t.getUTCFullYear()}`),Gn=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"long",...L,...t,year:void 0});return T(n=>r.formatRange(n,Yn(n,6)))},Hn=({locale:e,intlOptions:t})=>{const r=E(e,{dateStyle:"medium",...L,...t});return T(n=>r.formatRange(n,Yn(n,6)))},Et=({locale:e,intlOptions:t})=>{const r=E(e,{year:"numeric",...L,...t});return T(n=>r.format(n))},$n=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},Yn=(e,t)=>new Date(e.getTime()+t*ll),dl=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("")},gr=1e3,ml=({valueFormat:e,locale:t,tickValues:r,intlOptions:n})=>$(a=>{const i={...Ct(a,r),notation:"compact",...l.isCurrencyValueFormat(e)?{style:"currency",currencyDisplay:"narrowSymbol",currency:e.iso}:{},...n};return Rt(a,t,i)}),hl=({locale:e,tickValues:t,intlOptions:r})=>$(n=>{const a={...Ct(n,t),notation:"compact",...r};return Rt(n,e,a)}),pl=({locale:e,tickValues:t,intlOptions:r})=>$(n=>{const a={...Ct(n,t),notation:"compact",...r,style:"percent"};return Rt(n,e,a)}),Rt=(e,t,r)=>le(t,r).formatToParts(e).map(n=>n.type==="compact"?n.value.toLowerCase():n.value).join(""),Kn=e=>Math.abs(e)>gr?Kn(e/gr):Number.isInteger(e),fl=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}:fl(t)?{minimumFractionDigits:0,maximumFractionDigits:4}:{minimumFractionDigits:0,maximumFractionDigits:Math.max(1,gl(t))},gl=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))},vl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},yl=({locale:e,intlOptions:t})=>{const r=E(e,{month:"short",...L,...t});return T(n=>r.format(n))},Sl=({locale:e,intlOptions:t})=>{const r=E(e,{day:"numeric",month:"short",...L,...t});return T(n=>r.format(n))},bl=({locale:e,intlOptions:t,tickValues:r})=>{const n=E(e,{...Al(r),...L,...t});return T(a=>n.format(a))},xl=({locale:e,intlOptions:t})=>{const r=E(e,{timeStyle:"short",...L,...t});return T(n=>r.format(n))},Al=e=>{const t=e.filter(r=>r instanceof Date&&!Number.isNaN(r.getTime()));return t.length===0?{day:"numeric",month:"short"}:Il(t).size>1?{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}:{timeStyle:"short"}},Il=e=>{const t=new Set;for(const r of e)t.add(`${r.getUTCFullYear()}-${r.getUTCMonth()}-${r.getUTCDate()}`);return t},wt=e=>{const{valueFormat:t}=e;switch(t.type){case"currency":return ml(e);case"date":return vl(e);case"datetime":return bl(e);case"day_month":case"weekly_date_range":case"weekly_date_range_with_year":return Sl(e);case"decimal":case"integer":return hl(e);case"duration":return xt(e);case"month":return yl(e);case"month_year":return Tt(e);case"percentage":return pl(e);case"quarter":return Lt(e);case"text":return bt(e);case"time":return xl(e);case"year":return Et(e);case"lookup":return wt({...e,valueFormat:t.fallback});default:throw new l.InternalError({message:`Unhandled value format: ${t.type}`})}},Tl=.9,Ll=1/3,El=1/4,Rl=e=>e.formattedAxis.position==="top"||e.formattedAxis.position==="bottom"?Cl(e):wl(e),Cl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=zn(e.ticks,n),s=Ml(e.ticks,r.width),c=s*Tl;if(i<=c)return{...e,labelRotation:0,labelMaxWidthPx:null};if(s>=50){const m=ot(c);return{...e,ticks:it(e.ticks,a,m,n),labelRotation:0,labelMaxWidthPx:m}}if(o+8>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const u=ot(r.height*Ll);return{...e,ticks:it(e.ticks,a,u,n),labelRotation:-90,labelMaxWidthPx:u}},wl=({formattedAxis:e,bandwidthPx:t,panelRect:r,measureLabel:n})=>{const{widths:a,maxWidth:i,maxHeight:o}=zn(e.ticks,n);if(o>t)return{...e,ticks:[],labelRotation:0,labelMaxWidthPx:null};const s=ot(r.width*El);return i<=s?{...e,labelRotation:0,labelMaxWidthPx:null}:{...e,ticks:it(e.ticks,a,s,n),labelRotation:0,labelMaxWidthPx:s}},Ml=(e,t)=>{const r=e[0],n=e[1];return r===void 0||n===void 0?t:Math.abs(n.position-r.position)*t},zn=(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}},it=(e,t,r,n)=>{const a=i=>n(i).width;return e.map((i,o)=>(t[o]??0)<=r?i:{...i,formattedLabel:Pn(i.formattedLabel,r,a)})},ot=e=>Math.max(0,Math.floor(e)),Pl=(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:m}=a(t(c));if(s-=i?u:m,s<0)return!1}return!0},Dl={ticks:[],labelAt:()=>""},_l=({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?kl(g.ticks,n(g)):Dl;return o.set(p,y),y};let c=0,u=a.length-1,m=-1;for(;c<=u;){const p=c+u>>>1,{ticks:f,labelAt:g}=s(p);Pl(f.length,g,i,t,r)?(m=p,c=p+1):u=p-1}const h=Ol(m,s);return Vl(s(h))},Ol=(e,t)=>{const r=e>=0?e:0;for(let n=r;n>=0;n-=1){const{ticks:a,labelAt:i}=t(n);if(Nl(a,i))return n}return 0},kl=(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}}},Vl=({ticks:e,labelAt:t})=>e.map((r,n)=>({...r,formattedLabel:t(n)})),Nl=(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},Fl=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 On(e);case"date":return cl(e);case"datetime":return ul(e);case"day_month":return Fn(e);case"decimal":return kn(e);case"duration":return xt(e);case"integer":return Vn(e);case"month":return Bn(e);case"month_year":return Tt(e);case"percentage":return Nn(e);case"quarter":return Lt(e);case"text":return bt(e);case"weekly_date_range":return Gn(e);case"weekly_date_range_with_year":return Hn(e);case"year":return Et(e);case"time":return $n(e);case"lookup":return Fl({...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:d.getLayerYValueFormat(e),locale:r,numberFormat:t})}var Bl=(e,t)=>{const r=l.readVariableName(t.x);return r!==null&&r!==l.CONSTANT_VARIABLES.x?{read:d.createXValueReader(e,t),variable:r}:{read:d.getGroup,variable:l.GROUP_VARIABLES.group}},Un=({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}),m=t.type==="cartesian"&&t.mainAxis==="y";return{layer:e,coordSystem:t,panelRect:a,measureDataLabel:i,styleReaders:o.geom(e),formatLabel:Kl({layer:e,numberFormat:n,axes:r,locale:s,absoluteFormatter:u,percentageValueStrategy:c,isFlipped:m}),formatAbsolute:u,formatCategory:Gl({layer:e,numberFormat:n,locale:s})}},Gl=({layer:e,numberFormat:t,locale:r})=>{const{read:n,variable:a}=Bl(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)}},Hl=(e,t,r)=>{switch(t){case"stack":return $l(e);case"fill":return Yl(e,r);case"absoluteGrandTotal":return()=>e.summary.absoluteGrandTotal??null;case"none":return()=>null}},$l=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(d.getObservationXKey(a,t));return s===void 0?null:s.total}},Yl=(e,t)=>{const r=t?l.getXMin:l.getYMin,n=t?l.getXMax:l.getYMax,a=d.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}},Kl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a,percentageValueStrategy:i,isFlipped:o})=>{const s=d.createRawValueReader(e.data,e.dataLabels.labelSource),c=Hl(e,i,o),u=zl({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a}),m=I({valueFormat:{type:"percentage"},locale:n,numberFormat:t}),h=e.dataLabels.format==="percentage"&&Wn(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):m(f/g)}},zl=({layer:e,numberFormat:t,axes:r,locale:n,absoluteFormatter:a})=>{const i=e.dataLabels.labelSource,o=l.readVariableName(i);if(o!==null){if(Wn(e))return a;const s=Ul(e,r,t,n,o);if(s!==null)return s}return I({valueFormat:Wl(e.data,i),locale:n,numberFormat:t})},Wn=e=>{const t=l.readVariableName(e.dataLabels.labelSource);return t===null?!1:t===l.readVariableName(d.resolveSegmentYSource(e.position,e.mapping))},Ul=(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})},Wl=(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)},Xl={cartesian:["cartesian","flip"],polar:["polar"]},ql=null;function Xn(e=[]){const t=jl(e),r=(n,a)=>{if(!t.has(n))return null;const i=t.get(n);return i.getDataLabelPlacements===void 0||!Xl[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 Pt(){return ql??=Xn()}function jl(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*Zl({layers:e,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,locale:s,resolvePlacement:c=Pt()}){if(!(t.type!=="cartesian"||a.width<=0||a.height<=0))for(const u of e){if(!u.dataLabels.showDataLabels&&!u.dataLabels.showStackTotals)continue;const m=c.resolve(u.geom,"cartesian");if(m===null)continue;const h=Un({layer:u,coordSystem:t,axes:r,numberFormat:n,panelRect:a,measureDataLabel:i,readers:o,formattingLocale:s,percentageValueStrategy:m.getPercentageValueStrategy(u)});for(const p of m.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 Xe={abbreviation:"none",decimals:"auto"},qn=({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:Xe,intlOptions:{signDisplay:"always"}})(i);return vr(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:Xe,intlOptions:{signDisplay:"always"}})(o);return vr(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:Xe,intlOptions:{maximumFractionDigits:1}})(i)}x`}}},vr=e=>{const t=e.replace(/[^\d.]/g,"");return t===""||t==="."?!1:Number(t)===0},Jl=2,Ql=6,ec=6,tc=15,rc=15,nc=2.5,ac=.5,ic=.25,jn=e=>{const t=e-Jl,r=1+ac*t,n=1+ic*t;return{arrowStartGap:Ql*r,arrowEndGap:ec*r,offsetFromHigherObservation:tc*n,arrowheadSize:nc*e,curveRadius:rc*n,strokeWidth:e}},oc=(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},sc=(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},m=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+m*i} ${s.y}
|
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import vc from "humanize-duration";
|
|
|
7
7
|
import { area as ti, curveCatmullRom as gc, curveLinear as yc, line as ri, symbol as ni, symbolCircle as xc, symbolCross as bc, symbolDiamond as Sc, symbolSquare as Ac, symbolStar as wc, symbolTriangle as Ic, symbolWye as Tc } from "d3-shape";
|
|
8
8
|
import { Delaunay as Mc } from "d3-delaunay";
|
|
9
9
|
import fr 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.1791369792799");
|
|
11
11
|
var Lc = 1e6;
|
|
12
12
|
function z(e) {
|
|
13
13
|
return String(Math.round(e * Lc));
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"grammar-of-graphics",
|
|
12
12
|
"compiler"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.9.0-beta.
|
|
14
|
+
"version": "1.9.0-beta.1791369792799",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"sideEffects": [
|
|
17
17
|
"**/version.ts"
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"vite": "^8.1.5",
|
|
67
67
|
"vite-plugin-dts": "^4.5.4",
|
|
68
68
|
"vitest": "^4.1.11",
|
|
69
|
-
"@graphytools/eslint-config": "0.0.1",
|
|
70
69
|
"@graphytools/eslint-plugin-graphy": "1.0.0",
|
|
71
70
|
"@graphytools/typescript-config": "0.0.1",
|
|
72
|
-
"@graphytools/vitest-config": "1.0.0"
|
|
71
|
+
"@graphytools/vitest-config": "1.0.0",
|
|
72
|
+
"@graphytools/eslint-config": "0.0.1"
|
|
73
73
|
},
|
|
74
74
|
"publishConfig": {
|
|
75
75
|
"access": "public"
|