@graphysdk/node-renderer 1.8.1-beta.1786348404060 → 1.8.1-beta.1786354953172
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 +26 -26
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var it=Object.create;var ue=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var lt=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var ct=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of at(t))!dt.call(e,i)&&i!==n&&ue(e,i,{get:()=>t[i],enumerable:!(o=st(t,i))||o.enumerable});return e};var ut=(e,t,n)=>(n=e!=null?it(lt(e)):{},ct(t||!e||!e.__esModule?ue(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("node:fs"),Le=require("node:module"),D=require("node:path"),ft=require("node:url"),gt=require("@graphysdk/viz-engine/graph-config"),N=require("d3-shape"),c=require("@graphysdk/viz-engine"),ht=require("node:buffer");var w=typeof document<"u"?document.currentScript:null;let U,J;const _e=()=>U?Promise.resolve(U):(J??=import("@napi-rs/canvas").then(e=>(U=e,e)).catch(e=>{throw J=void 0,e}),J),W=()=>{if(!U)throw new Error("Canvas runtime is not loaded. Call loadCanvasRuntime() before rendering.");return U},y="Inter",x=new Set;let ge=!1,q=!1;const we=e=>`${e.family}|${e.weight??400}|${e.style??"normal"}`,re=e=>{const t=we(e);x.has(t)||(W().GlobalFonts.register(e.data,e.family),x.add(t))},mt=[{file:"Inter-Regular.ttf",family:y,weight:400},{file:"Inter-SemiBold.ttf",family:y,weight:600}],bt=[{file:"inter-latin-400-normal.woff",family:y,weight:400},{file:"inter-latin-600-normal.woff",family:y,weight:600}],At="@fontsource/inter",pt=()=>{try{const e=Le.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href),t=D.dirname(e.resolve("@graphysdk/node-renderer/package.json"));return D.join(t,"assets")}catch{return D.resolve(D.dirname(ft.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href)),"../assets")}},Ce=(e,t,n)=>{try{return fe.existsSync(e)?(re({family:t,data:fe.readFileSync(e),weight:n}),!0):!1}catch{return!1}},Tt=()=>{const e=pt();for(const{file:t,family:n,weight:o}of mt)Ce(D.join(e,t),n,o)&&(q=!0)},St=()=>{const e=Le.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href);for(const{file:t,family:n,weight:o}of bt)if(!x.has(we({family:n,data:Buffer.alloc(0),weight:o})))try{const i=e.resolve(`${At}/files/${t}`);Ce(i,n,o)&&(q=!0)}catch{}},Ie=()=>(ge||(ge=!0,Tt(),St()),q),C=(e,t)=>e.x+t*e.width,_=(e,t)=>e.y+(1-t)*e.height,ee=e=>e==="catmull-rom"?N.curveCatmullRom:N.curveLinear,Be=e=>{switch(e){case"dashed":return[8,4];case"dotted":return[2,2];case"solid":return[]}},k=e=>e,yt=(e,t)=>t!=="connect"?e:e.filter(n=>c.getX(n)!==null&&c.getY(n)!==null),Rt=(e,t,n)=>{const o=ee(t.interpolate),i=N.area().curve(o),r=N.line().curve(o);if(e.mainAxis==="y"){const s=l=>_(n,c.getY(l)??0),a=l=>C(n,c.getXMin(l)??0),d=l=>C(n,c.getXMax(l)??c.getX(l)??0);i.y(s).x0(a).x1(d),r.y(s).x(d)}else{const s=l=>C(n,c.getX(l)??0),a=l=>_(n,c.getYMin(l)??0),d=l=>_(n,c.getYMax(l)??c.getY(l)??0);i.x(s).y0(a).y1(d),r.x(s).y(d)}if(t.missingValues==="gap"){const s=a=>c.getX(a)!==null&&c.getY(a)!==null;i.defined(s),r.defined(s)}return{areaGenerator:i,lineGenerator:r}},Et=k({geom:"area",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const r=c.createStyleResolver({colorScheme:i}).geomReaders(t),{areaGenerator:s,lineGenerator:a}=Rt(n,t.params,o),d=e;t.data.groupBy(c.GROUP_VARIABLES.group).forEach(l=>{const u=yt([...l],t.params.missingValues),f=u[0];if(!f)return;const g=r.get("color",f),h=r.get("alpha",f),m=r.get("strokeWidth",f),A=Be(r.get("lineType",f));e.save(),e.globalAlpha=h,e.fillStyle=g,e.beginPath(),s.context(d)(u),e.fill(),e.restore(),e.save(),e.globalAlpha=r.get("strokeAlpha",f),e.strokeStyle=g,e.lineWidth=m,e.setLineDash(A),e.lineJoin="round",e.lineCap="round",e.beginPath(),a.context(d)(u),e.stroke(),e.restore()})}}),he=(e,t,n,o,i,r)=>{const s=Math.max(0,Math.min(r.rx??r.ry??0,o/2)),a=Math.max(0,Math.min(r.ry??r.rx??0,i/2)),d=Math.PI/2;e.moveTo(t+s,n),e.lineTo(t+o-s,n),e.ellipse(t+o-s,n+a,s,a,0,-d,0),e.lineTo(t+o,n+i-a),e.ellipse(t+o-s,n+i-a,s,a,0,0,d),e.lineTo(t+s,n+i),e.ellipse(t+s,n+i-a,s,a,0,d,Math.PI),e.lineTo(t,n+a),e.ellipse(t+s,n+a,s,a,0,Math.PI,Math.PI*1.5),e.closePath()},Lt=k({geom:"bar",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const{Path2D:r}=W(),s=c.createStyleResolver({colorScheme:i}).geomReaders(t),a=n.mainAxis,d=new Map;for(const l of t.data){const u=c.getBarRectBounds(a,l);if(!u)continue;const f=C(o,u.x),g=o.y+u.y*o.height,h={x:f,y:g,width:u.width*o.width,height:u.height*o.height,fill:s.get("color",l),opacity:s.get("alpha",l)},m=c.buildColumnKey(a,u),A=d.get(m);A?A.bars.push(h):d.set(m,{bars:[h],style:{borderColor:s.get("borderColor",l),borderWidth:s.get("borderWidth",l),borderRadius:s.get("borderRadius",l),borderAlpha:s.get("alpha",l)}})}for(const{bars:l,style:u}of d.values()){const{borderColor:f,borderRadius:g,borderWidth:h,borderAlpha:m}=u,A=c.resolveBarBorderTreatment(h),p=g==="full"?void 0:c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a});if(!(l.length>1)){const[b]=l;if(!b)continue;const v=p??c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a,bounds:{width:b.width,height:b.height}}),E=new r;he(E,b.x,b.y,b.width,b.height,v),e.save(),e.globalAlpha=b.opacity,e.fillStyle=b.fill,e.fill(E),f!==void 0&&(e.clip(E),e.strokeStyle=f,e.lineWidth=A.outlineWidth,e.stroke(E)),e.restore();continue}const T=c.getBoundingRect(l),L=p??c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a,bounds:{width:T.width,height:T.height}}),S=new r;he(S,T.x,T.y,T.width,T.height,L),e.save(),e.clip(S);for(const b of l)e.globalAlpha=b.opacity,e.fillStyle=b.fill,e.fillRect(b.x,b.y,b.width,b.height),f!==void 0&&(e.strokeStyle=f,e.lineWidth=A.separatorWidth,e.strokeRect(b.x,b.y,b.width,b.height));f!==void 0&&(e.globalAlpha=m,e.strokeStyle=f,e.lineWidth=A.outlineWidth,e.stroke(S)),e.restore()}}}),me=(e,t)=>{const n=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(n?.[1]!==void 0){const i=n[1],r=i.length===3?[...i].map(l=>l+l).join(""):i.slice(0,6),s=Number.parseInt(r.slice(0,2),16),a=Number.parseInt(r.slice(2,4),16),d=Number.parseInt(r.slice(4,6),16);return`rgba(${s}, ${a}, ${d}, ${t})`}const o=/^rgba?\(([^)]+)\)$/i.exec(e.trim());if(o?.[1]!==void 0){const i=o[1].split(",").map(d=>d.trim()),[r,s,a]=i;if(r!==void 0&&s!==void 0&&a!==void 0)return`rgba(${r}, ${s}, ${a}, ${t})`}return t===0?"rgba(0, 0, 0, 0)":e},_t=(e,t)=>t!=="connect"?e:e.filter(n=>c.getX(n)!==null&&c.getY(n)!==null),wt=(e,t)=>{const{seriesObservations:n,fillGenerator:o,panel:i,color:r,fillAlpha:s}=t,a=n.map(l=>c.getY(l)).filter(l=>l!==null).map(l=>_(i,l));if(a.length===0)return;const d=e.createLinearGradient(0,Math.min(...a),0,i.y+i.height);d.addColorStop(0,r),d.addColorStop(.7,me(r,0)),d.addColorStop(1,me(r,0)),e.save(),e.globalAlpha=s,e.fillStyle=d,e.beginPath(),o.context(e)(n),e.fill(),e.restore()},Ct=k({geom:"line",coord:"cartesian",draw:(e,{layer:t,panel:n,colorScheme:o})=>{const i=c.createStyleResolver({colorScheme:o}).geomReaders(t),r=N.line().x(a=>C(n,c.getX(a)??0)).y(a=>_(n,c.getY(a)??0)).curve(ee(t.params.interpolate)),s=N.area().x(a=>C(n,c.getX(a)??0)).y0(n.y+n.height).y1(a=>_(n,c.getY(a)??0)).curve(ee(t.params.interpolate));if(t.params.missingValues==="gap"){const a=d=>c.getX(d)!==null&&c.getY(d)!==null;r.defined(a),s.defined(a)}t.data.groupBy(c.GROUP_VARIABLES.group).forEach(a=>{const d=_t([...a],t.params.missingValues),l=d[0];if(!l)return;const u=i.get("strokeWidth",l),f=Be(i.get("lineType",l)),g=i.get("color",l),h=i.get("fillAlpha",l);h!==void 0&&wt(e,{seriesObservations:d,fillGenerator:s,panel:n,color:g,fillAlpha:h}),e.save(),e.globalAlpha=i.get("alpha",l),e.strokeStyle=g,e.lineWidth=u,e.setLineDash(f),e.lineJoin="round",e.lineCap="round",e.beginPath(),r.context(e)(d),e.stroke(),e.restore()})}}),It=k({geom:"point",coord:"cartesian",draw:(e,{layer:t,panel:n,colorScheme:o})=>{const i=c.createStyleResolver({colorScheme:o}).geomReaders(t);for(const r of t.data){const s=c.getX(r),a=c.getY(r);if(s===null||a===null)continue;const d=C(n,s),l=_(n,a),u=i.get("size",r)/2,f=i.get("borderWidth",r);e.save(),e.globalAlpha=i.get("alpha",r),e.fillStyle=i.get("color",r),e.strokeStyle=i.get("borderColor",r),e.lineWidth=f,e.beginPath(),e.arc(d,l,u,0,Math.PI*2),e.fill(),f>0&&e.stroke(),e.restore()}}}),ie=11,Bt="sans-serif",Nt=500,P=5,Ne=5,te=13,ve=6,V=12,be=21.6,vt=(e,t)=>{const n=e.mapping.y!==void 0,o=t.mainAxis==="y";return n!==o},Pt=(e,t,n)=>{const o=c.getRuleDashPattern(t,n);e.setLineDash(o),o.length>0&&(e.lineCap="round")},Ft=(e,t)=>X(e)&&X(t)?`${e}: ${t}`:X(e)?e:X(t)?t:null,X=e=>e!=null&&e.trim()!=="",kt=e=>{e.beginPath(),e.moveTo(2.48935,16.9323),e.lineTo(9.07098,9.82964),e.bezierCurveTo(9.51595,9.34944,9.51504,8.60728,9.0689,8.12818),e.lineTo(2.48866,1.06172),e.bezierCurveTo(1.85811,.384586,.974477,0,.049217,0),e.lineTo(0,0),e.lineTo(0,18),e.lineTo(.0443689,18),e.bezierCurveTo(.972463,18,1.85854,17.6131,2.48935,16.9323),e.closePath()},Pe=(e,t,n,o,i,r)=>{const s=Math.min(r,o/2,i/2);e.beginPath(),e.moveTo(t+s,n),e.lineTo(t+o-s,n),e.arcTo(t+o,n,t+o,n+s,s),e.lineTo(t+o,n+i-s),e.arcTo(t+o,n+i,t+o-s,n+i,s),e.lineTo(t+s,n+i),e.arcTo(t,n+i,t,n+i-s,s),e.lineTo(t,n+s),e.arcTo(t,n,t+s,n,s),e.closePath(),e.fill()},Dt=(e,t,n,o,i,r,s,a)=>{const d=n+P*2,l=ie+Ne*2,u=o==="start",f=u?r.x:r.x+r.width,g=_(r,i),h=u?-te:-(d-te),m=u?h+d-P:h+P-V;e.save(),e.translate(f,g),e.translate(0,-l/2),e.fillStyle=s,Pe(e,h,0,d,l,ve),e.save(),u||(e.translate(m+V/2,l/2),e.rotate(Math.PI),e.translate(-(m+V/2),-l/2)),e.translate(m,(l-be)/2),e.scale(V/10,be/18),e.fillStyle=s,kt(e),e.fill(),e.restore(),e.fillStyle=a,e.textAlign="left",e.textBaseline="middle",e.fillText(t,h+P,l/2),e.restore()},Ot=(e,t,n,o,i,r,s,a)=>{const d=n+P*2,l=ie+Ne*2,u=o==="start",f=C(r,i),g=u?r.y+r.height:r.y,h=u?-te:-8;e.save(),e.translate(f,g),e.translate(-d/2,0),e.fillStyle=s,Pe(e,0,h,d,l,ve),e.fillStyle=a,e.textAlign="left",e.textBaseline="middle",e.fillText(t,P,h+l/2),e.restore()},Ut=k({geom:"rule",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,compiled:i,textMeasurer:r,formattingLocale:s,colorScheme:a})=>{const d=t.data.getFirst();if(!d)return;const l=vt(t,n),u=l?c.getY(d):c.getX(d);if(u===null)return;const f=c.createStyleResolver({colorScheme:a}).geomReaders(t),g=f.get("color",d),h=c.getRuleLabelTextColor(g),m=f.get("strokeWidth",d);if(e.save(),e.strokeStyle=g,e.lineWidth=m,Pt(e,f.get("lineType",d),m),e.beginPath(),l){const S=_(o,u);e.moveTo(o.x,S),e.lineTo(o.x+o.width,S)}else{const S=C(o,u);e.moveTo(S,o.y),e.lineTo(S,o.y+o.height)}e.stroke(),e.restore();const A=Ft(t.params.label,c.formatRuleValue({guides:i.guides,numberFormat:i.config.numberFormat,layer:t,locale:s??i.config.parsingLocale}));if(A===null)return;const p=i.config.appearance.textScale,R={family:Bt,size:ie*p,weight:Nt};e.font=c.buildFontString(R);const T=r.measureText(A,R).width;(l?Dt:Ot)(e,A,T,t.params.labelPosition,u,o,g,h)}}),O=N.arc();O.digits(8);const Ht=k({geom:"bar",coord:"polar",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const r=o.x+o.width/2,s=o.y+o.height/2,a=Math.min(o.width,o.height)/2,{Path2D:d}=W(),l=c.createStyleResolver({colorScheme:i}).geomReaders(t);e.save(),e.translate(r,s),e.scale(a,a);const u=e,f=new Map;for(const g of t.data){const{startAngle:h,endAngle:m}=c.getAngleExtent(g),{innerRadius:A,outerRadius:p}=c.getRadiusExtent(g);if(h===null||m===null||A===null||p===null)continue;const R={startAngle:h,endAngle:m,innerRadius:A,outerRadius:p,fill:l.get("color",g),opacity:l.get("alpha",g)},T=c.buildSliceGroupKey(n.bandAxis,R),L=f.get(T);L?L.items.push(R):f.set(T,{items:[R],style:{borderColor:l.get("borderColor",g),borderWidth:l.get("borderWidth",g),borderRadius:l.get("borderRadius",g),borderAlpha:l.get("alpha",g)}})}for(const{items:g,style:h}of f.values()){const{borderColor:m,borderRadius:A,borderWidth:p,borderAlpha:R}=h,T=c.resolveBarBorderTreatment(p),L=m!==void 0&&a>0,S=c.getUnionExtent(g),b=c.resolvePolarBarCornerRadiusUnit(A,S.outerRadius-S.innerRadius),v=a>0&&(L||b>0);e.save();let E;v&&(E=new d,O.cornerRadius(b),O.context(E)(S),e.clip(E)),O.cornerRadius(0);for(const Q of g)e.globalAlpha=Q.opacity,e.fillStyle=Q.fill,e.beginPath(),O.context(u)(Q),e.fill(),L&&(e.strokeStyle=m,e.lineWidth=T.separatorWidth/a,e.stroke());L&&E&&(e.globalAlpha=R,e.strokeStyle=m,e.lineWidth=T.outlineWidth/a,e.stroke(E)),e.restore()}e.restore()}}),Mt={bar:{cartesian:Lt,polar:Ht},line:{cartesian:Ct},area:{cartesian:Et},point:{cartesian:It},rule:{cartesian:Ut}},Fe=(e,t)=>Mt[e.geom]?.[t.type]??null,Gt=(e,t,n)=>{e.draw(t,n)};let Ae;const ke=()=>(Ae??=c.createCompiler(),Ae),se=["line","areaStacked","bar","barStacked","barStackedFill","column","columnStacked","columnStackedFill","combo","pie","donut","scatter","bubble"],De=["funnel","heatmap","waterfall","mekko","table"],Wt=new Set(se),Vt={supportedGraphTypes:[...se],unsupportedGraphTypes:[...De],supportedGeoms:{cartesian:["bar","line","area","point","rule"],polar:["bar"]}},B=e=>({ok:!1,reason:e}),j=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Xt=e=>{if(!j(e))return!1;const{columns:t,rows:n}=e;return!Array.isArray(t)||!Array.isArray(n)?!1:t.every(o=>j(o)&&typeof o.key=="string")},Kt=e=>{if("_unstable_mapping"in e&&e._unstable_mapping!==void 0)return!0;const t=e.referenceLines;return j(t)?t.trendline!==void 0||t.averageLine!==void 0:!1},Oe=e=>{if(!j(e))return B("Chart config must be a plain object.");if(!Xt(e.data))return B("Chart config is missing a valid `data` object (columns + rows).");const{data:t,...n}=e;return{ok:!0,input:n,data:t}},Ue=e=>{const t=Oe(e);if(!t.ok)return t;if(Kt(e))return B("Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`.");const n=t.input.type??"column";if(!Wt.has(n))return B(`Unsupported chart type for canvas rendering: ${n}.`);try{const o=ke(),i=gt.convertGraphConfig(t.input,t.data),r=o.compile({input:i,data:t.data});if(!r.ok)return B(`Chart config failed to compile: ${r.errors.map(s=>s.message).join("; ")}`);for(const s of r.compiled.layers)if(Fe(s,r.compiled.coordSystem)===null)return B(`No canvas geom renderer for ${s.geom} (${r.compiled.coordSystem.type} coord).`);return{ok:!0,compiled:r.compiled}}catch(o){const i=o instanceof Error?o.message:String(o);return B(`Chart config failed to compile: ${i}`)}},K=6,z=10,Yt=20,ae=y,le=12,He=y,H=12,de=1.3,M=10,G=12,F=6,Me=16,zt=24,Ge=6,We=3,ne=4,qt=8,jt="#9ca3af",Ve=16,Zt=1.3,Xe=13,Qt=1.4,Ke=12,Jt=1.4,Z=8,ce=12,$t=1.3,xt=200,en=120,tn=80,Ye=22,nn=9,on=11,rn=10,Y=9,pe=12,sn='-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',an=11.5,ln=550,dn={light:.55,mid:.75,dark:.08},cn={light:.62,mid:.8,dark:.85},un=.22,fn=.65,gn=y,hn=12,mn={family:ae,size:le},bn={family:gn,size:hn},An={family:He,size:H},pn=8,Te=1,Tn=[2,3],Sn=[1,3],yn=(e,t,n,o,i)=>{if(!t.isVisible||t.ticks.length===0)return;const r=t.position==="bottom"||t.position==="top",s=t.ticksVisible?1:0;e.save(),e.font=c.buildFontString(mn),e.fillStyle=i.textSecondary,e.strokeStyle=i.gridLine,e.lineWidth=1,e.setLineDash([]);for(const a of t.ticks){const d=r?a.position:1-a.position;t.ticksVisible&&En(e,t.position,d,n,o),_n(e,t.position,d,n,o,a.formattedLabel,t.labelRotation,s)}e.restore()},Rn=(e,t,n,o)=>{if(e==="bottom"||e==="top"){const a=o.x+t*o.width,d=e==="top"?n.y+n.height:n.y,l=e==="top"?-K:K;return{x1:a,y1:d,x2:a,y2:d+l}}const i=o.y+t*o.height,r=e==="right"?n.x:n.x+n.width,s=e==="right"?K:-K;return{x1:r,y1:i,x2:r+s,y2:i}},En=(e,t,n,o,i)=>{const{x1:r,y1:s,x2:a,y2:d}=Rn(t,n,o,i);e.beginPath(),e.moveTo(r,s),e.lineTo(a,d),e.stroke()},Ln=(e,t,n,o,i)=>{if(e==="bottom"||e==="top"){const s=o.x+t*o.width;return e==="bottom"?{x:s,y:n.y+i,textAlign:"center",textBaseline:"top"}:{x:s,y:n.y+n.height-i,textAlign:"center",textBaseline:"alphabetic"}}const r=o.y+t*o.height;return e==="left"?{x:n.x+n.width-i,y:r,textAlign:"right",textBaseline:"middle"}:{x:n.x+i,y:r,textAlign:"left",textBaseline:"middle"}},_n=(e,t,n,o,i,r,s,a)=>{const d=z*a;if(s!==0&&(t==="top"||t==="bottom")){const u=i.x+n*i.width,f=t==="top";e.save(),e.translate(u,f?o.y+o.height-d:o.y+d),e.rotate(s*Math.PI/180),e.textAlign=f?"left":"right",e.textBaseline="middle",e.fillText(r,0,0),e.restore();return}const l=Ln(t,n,o,i,d);e.textAlign=l.textAlign,e.textBaseline=l.textBaseline,e.fillText(r,l.x,l.y)},wn=(e,t,n,o)=>{if(!t.isVisible||!t.label)return;e.save(),e.font=c.buildFontString(bn),e.fillStyle=o.textPrimary,e.textBaseline="middle";const{x:i,y:r,alignment:s}=Cn(t.position,n);e.textAlign=s,e.fillText(t.label,i,r),e.restore()},Cn=(e,t)=>{const n=t.y+t.height/2;return e==="left"?{x:t.x,y:n,alignment:"start"}:e==="right"?{x:t.x+t.width,y:n,alignment:"end"}:{x:t.x+t.width/2,y:n,alignment:"center"}},In="data:image/png;base64,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",I=Ye;let $;const Bn=()=>{if($)return $;const{Image:e}=W(),t=new e,n=In.replace(/^data:image\/png;base64,/,"");return t.src=ht.Buffer.from(n,"base64"),$=t,t},ze=(e,t,n="full")=>!e||t.width<en||t.height<tn?"hidden":t.width<xt||n==="mini"?"mini":"full",Nn=e=>{const t=vn(e);if(t===null)return"light";const n=Pn(t);return n<=un?"dark":n<=fn?"mid":"light"},oe=(e,t,n)=>e.placement!==n||ze(e.enabled,t,e.variant)==="hidden"?0:Ye,qe=(e,t,n,o,i,r)=>{if(t.placement!==r)return;const s=ze(t.enabled,i,t.variant);if(s==="hidden")return;const a=Nn(o.background),d=a==="dark",l={family:sn,size:an,weight:400},u={...l,weight:ln};let f=0;s==="full"&&(e.font=c.buildFontString(l),f=e.measureText("Made with ").width,e.font=c.buildFontString(u),f+=e.measureText("Graphy").width);const g=s==="mini"?0:nn,h=s==="mini"?0:on,m=s==="mini"?0:rn,A=s==="mini"?I:g+Y+m+f+h,p=n.x+n.width-A,R=n.y+Math.max(0,(n.height||I)/2-I/2);e.save(),e.globalAlpha=cn[a],e.textBaseline="middle",e.textAlign="left",d||(e.shadowColor="rgba(0, 0, 0, 0.09)",e.shadowBlur=4,e.shadowOffsetY=1),e.beginPath(),e.roundRect(p,R,A,I,I/2),e.fillStyle=`rgba(255, 255, 255, ${dn[a]})`,e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0;const T=d?"#FFFFFF":"#2A2A28",L=s==="mini"?p+(A-Y)/2:p+g,S=R+(I-pe)/2;if(e.save(),d&&(e.filter="invert(1)"),e.drawImage(Bn(),L,S,Y,pe),e.restore(),s==="full"){const b=p+g+Y+m,v=R+I/2;e.fillStyle=T,e.font=c.buildFontString(l),e.fillText("Made with ",b,v);const E=e.measureText("Made with ").width;e.font=c.buildFontString(u),e.fillText("Graphy",b+E,v)}e.restore()},vn=e=>{const t=e.trim();if(!t.startsWith("#"))return null;const n=t.slice(1);if(n.length===3){const o=n[0],i=n[1],r=n[2];return o===void 0||i===void 0||r===void 0?null:{red:Number.parseInt(o+o,16),green:Number.parseInt(i+i,16),blue:Number.parseInt(r+r,16)}}return n.length>=6?{red:Number.parseInt(n.slice(0,2),16),green:Number.parseInt(n.slice(2,4),16),blue:Number.parseInt(n.slice(4,6),16)}:null},Pn=({red:e,green:t,blue:n})=>{const o=i=>{const r=i/255;return r<=.03928?r/12.92:((r+.055)/1.055)**2.4};return .2126*o(e)+.7152*o(t)+.0722*o(n)},Fn={family:y,size:Ve,weight:600},kn={family:y,size:Xe},Dn={family:y,size:Ke},On={family:y,size:ce,weight:500},Un={family:y,size:ce},je=Ve*Zt,Hn=Xe*Qt,Ze=Ke*Jt,Qe=ce*$t,Je=e=>{if(e===null)return null;if(e.label!==void 0&&e.label!=="")return e.label;if(e.url!==void 0&&e.url!==""&&c.isSafeUrl(e.url))try{return new URL(e.url).hostname}catch{return e.url}return null},Mn=(e,t)=>{let n=0;const o=e.isTitleVisible&&e.title!==null,i=e.isSubtitleVisible&&e.subtitle!==null;o&&(n+=je),i&&(n>0&&(n+=Z),n+=Hn);const r=oe(e.brandMark,t,"header");!o&&!i&&r>0&&(n=r);const s=e.isCaptionVisible&&e.caption!==null,a=e.isSourceVisible&&Je(e.source)!==null,d=oe(e.brandMark,t,"footer");let l=0;return s&&(l+=Ze),(a||d>0)&&(l>0&&(l+=Z),l+=Math.max(Qe,d)),{headerHeight:n,footerHeight:l}},Gn=(e,t,n,o,i)=>{if(n.height===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let r=n.y;t.isTitleVisible&&t.title!==null&&(e.font=c.buildFontString(Fn),e.fillStyle=o.textPrimary,e.fillText(c.extractPlainText(t.title),n.x,r),r+=je+Z),t.isSubtitleVisible&&t.subtitle!==null&&(e.font=c.buildFontString(kn),e.fillStyle=o.textSecondary,e.fillText(c.extractPlainText(t.subtitle),n.x,r)),e.restore(),qe(e,t.brandMark,n,o,i,"header")},Wn=(e,t,n,o,i)=>{if(n.height===0)return;const r=t.isCaptionVisible?t.caption:null,s=t.isSourceVisible?Je(t.source):null,a=oe(t.brandMark,i,"footer");if(r===null&&s===null&&a===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let d=n.y;if(r!==null&&(e.font=c.buildFontString(Dn),e.fillStyle=o.textSecondary,e.fillText(c.extractPlainText(r),n.x,d),d+=Ze+Z),s!==null){let l=n.x;l=Se(e,"Source: ",On,o.textSecondary,l,d),Se(e,s,Un,o.textSecondary,l,d)}e.restore(),qe(e,t.brandMark,{x:n.x,y:d,width:n.width,height:Math.max(Qe,a)},o,i,"footer")},Se=(e,t,n,o,i,r)=>(e.font=c.buildFontString(n),e.fillStyle=o,e.fillText(t,i,r),i+e.measureText(t).width),Vn=(e,t,n,o,i)=>{e.save(),e.lineCap="round",e.strokeStyle=i.gridLine;for(const r of c.computePanelBorderPaths(n.border,o,pn))e.lineWidth=r.lineWidth??Te,e.setLineDash(ye(r.lineStyle)),Xn(e,r.segments),e.stroke();for(const r of t){if(!r.gridVisible)continue;const s=r.position==="top"||r.position==="bottom";e.lineWidth=r.gridLineWidth??Te,e.setLineDash(ye(r.gridLineStyle));for(const a of r.ticks){if(a.position<=0||a.position>=1)continue;const d=s?a.position:1-a.position;if(e.beginPath(),s){const l=o.x+d*o.width;e.moveTo(l,o.y),e.lineTo(l,o.y+o.height)}else{const l=o.y+d*o.height;e.moveTo(o.x,l),e.lineTo(o.x+o.width,l)}e.stroke()}}e.restore()},ye=e=>{switch(e){case"dashed":return Tn;case"dotted":return Sn;case"solid":return[]}},Xn=(e,t)=>{e.beginPath();for(const n of t)switch(n.type){case"move":e.moveTo(n.x,n.y);break;case"line":e.lineTo(n.x,n.y);break;case"arc":e.arc(n.cx,n.cy,n.radius,n.startAngle,n.endAngle);break;case"close":e.closePath();break}},Kn=(e,t,n,o)=>{e.save(),e.font=c.buildFontString(An),e.textBaseline="middle";for(const r of t)r.display==="direct"&&Yn(e,r,n,o);const i=new Map;for(const r of t){if(r.display!=="pill"||r.items.length===0)continue;const s=i.get(r.position);s?s.push(r):i.set(r.position,[r])}for(const[r,s]of i){const a=n[r];a&&(r==="top"||r==="bottom"?zn(e,s,a,o):qn(e,s,a,o))}e.restore()},Yn=(e,t,n,o)=>{const i=n[t.position];if(i){e.textAlign="left";for(const r of t.items)r.normalizedY!==null&&(e.fillStyle=typeof r.visual.color=="string"?r.visual.color:o.textPrimary,e.fillText(r.formattedLabel,i.x+qt,_(i,r.normalizedY)))}},zn=(e,t,n,o)=>{const i=$e(t),r=i.reduce((l,u,f)=>l+Zn(u)+e.measureText(u.label).width+(f===0?0:Re(u)),0),s=H*de;let a=n.x+Math.max(0,(n.width-r)/2);const d=n.y+Ge+Math.max(s,G)/2;for(let l=0;l<i.length;l++){const u=i[l];u&&(l>0&&(a+=Re(u)),a=xe(e,u,a,d,o))}},qn=(e,t,n,o)=>{const i=$e(t),r=Math.max(H*de,G),s=4,a=i.length*r+Math.max(0,i.length-1)*s;let d=n.y+Math.max(0,(n.height-a)/2)+r/2;for(const l of i)xe(e,l,n.x,d,o),d+=r+s},$e=e=>{const t=[];for(const n of e){const o=n.aesthetics.includes("size");n.items.forEach((i,r)=>{const s=i.visual.size,a=o&&typeof s=="number"&&Number.isFinite(s)&&s>0?s:void 0;t.push({label:i.formattedLabel,colors:jn(i.visual.color),bubbleSize:a,isFirstInGroup:r===0})})}return t},jn=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="string"):[],Re=e=>e.isFirstInGroup?zt:Me,Zn=e=>{if(e.bubbleSize!==void 0)return e.bubbleSize+F;const t=e.colors.length;if(t===0)return 0;if(t===1)return M+F;const n=Math.min(t,We);return M+(n-1)*ne+F},xe=(e,t,n,o,i)=>{let r=n;if(t.bubbleSize!==void 0){const s=t.bubbleSize/2;e.fillStyle=t.colors[0]??jt,e.beginPath(),e.arc(r+s,o,s,0,Math.PI*2),e.fill(),r+=t.bubbleSize+F}else if(t.colors.length>0){const s=t.colors.slice(0,We);for(let a=0;a<s.length;a++){const d=s[a];d&&(e.fillStyle=d,e.fillRect(r+a*ne,o-G/2,M,G))}r+=M+(s.length-1)*ne+F}return e.fillStyle=i.textPrimary,e.textAlign="left",e.fillText(t.label,r,o),r+e.measureText(t.label).width},Ee=(e,t)=>Math.min(Math.max(...e),t),Qn=e=>t=>{if(!t.isVisible||t.ticks.length===0)return 0;const n=t.position==="top"||t.position==="bottom",o=t.ticks.map(s=>e.measureText(s.formattedLabel,{family:ae,size:le})),i=t.labelMaxWidthPx??Number.POSITIVE_INFINITY;if(n){if(t.labelRotation!==0){const s=o.map(a=>a.width);return Ee(s,i)+2*z}return Math.max(...o.map(s=>s.height))+z}const r=o.map(s=>s.width);return Ee(r,i)+z},Jn=e=>t=>{if(t.items.length===0)return 0;const n={family:He,size:H};if(t.position==="top"||t.position==="bottom"){const r=H*de;return Math.max(r,G)+Ge*2}const i=t.items.map(r=>{const s=e.measureText(r.formattedLabel,n).width;return M+F+s});return Math.max(...i)+Me},$n=e=>(t,n)=>{const{labelLineHeight:o,labelFontWeight:i}=c.getDifferenceArrowDimensions(n,1);return e.measureText(t,{family:y,size:o,weight:i})},xn=e=>(t,n)=>{const{fontSize:o,fontWeight:i}=c.getDataLabelDimensions(t,1);return e.measureText(n,{family:y,size:o,weight:i})},eo=e=>({measureAxis:Qn(e),measureAxisLabel:()=>Yt,measureLegend:Jn(e),measureTickLabel:t=>e.measureText(t,{family:ae,size:le}),measureDifferenceArrowLabel:$n(e),measureDataLabel:xn(e),measureHeadline:()=>({width:0,height:0}),measureHeadlineItemWidths:()=>[]});class et{constructor(){this.currentFont="";const t=W().createCanvas(1,1);this.ctx=t.getContext("2d")}measureText(t,n){const o=c.buildFontString(n);this.currentFont!==o&&(this.ctx.font=o,this.currentFont=o);const i=this.ctx.measureText(t);return{width:i.width,height:i.fontBoundingBoxAscent+i.fontBoundingBoxDescent,ascent:i.fontBoundingBoxAscent,descent:i.fontBoundingBoxDescent}}}const tt={background:"#ffffff",textPrimary:"#111827",textSecondary:"#6b7280",gridLine:"#e5e7eb",panelBorder:"#d1d5db",legendPillBackground:"rgba(0, 0, 0, 0.04)",legendPillBorder:"rgba(0, 0, 0, 0.08)"},nt={background:"#0b0f17",textPrimary:"#e5e7eb",textSecondary:"#9ca3af",gridLine:"#1f2937",panelBorder:"#374151",legendPillBackground:"rgba(255, 255, 255, 0.06)",legendPillBorder:"rgba(255, 255, 255, 0.12)"},to=async({input:e,data:t},n)=>{const i=ke().compile({input:e,data:t});if(!i.ok)throw new Error(`Failed to compile graph spec: ${i.errors.map(r=>r.message).join("; ")}`);return ot(i.compiled,n)},ot=async(e,t)=>{const{Canvas:n}=await _e();if(Ie(),t.fonts)for(const p of t.fonts)re(p);const o=c.formatLegends({legends:e.guides.legends,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattingLocale:t.formattingLocale}),i={width:t.width,height:t.height},{headerHeight:r,footerHeight:s}=Mn(e.config.content,i),a={headerSize:{width:t.width,height:r},footerSize:{width:t.width,height:s}},d=new et,{layout:l,formattedAxes:u}=new c.LayoutCompiler(eo(d)).compile({axes:e.guides.axes,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattedLegends:o,containerSize:{width:t.width,height:t.height},externalMeasurements:a,formattingLocale:t.formattingLocale,layout:e.config.layout}),f=t.pixelRatio??2,g=new n(t.width*f,t.height*f),h=g.getContext("2d");h.scale(f,f);const m=t.colorScheme??"light";return no(h,m==="dark"?nt:tt,m,t.width,t.height,e,u,o,l,d,t.formattingLocale),g.encode("png")},no=(e,t,n,o,i,r,s,a,d,l,u)=>{e.fillStyle=t.background,e.fillRect(0,0,o,i),Vn(e,s,r.guides.panel,d.panel,t),e.save(),e.beginPath(),e.rect(d.panel.x,d.panel.y,d.panel.width,d.panel.height),e.clip();const f={coordSystem:r.coordSystem,panel:d.panel,compiled:r,theme:t,colorScheme:n,textMeasurer:l,formattingLocale:u};for(const g of r.layers){const h=Fe(g,r.coordSystem);h&&Gt(h,e,{...f,layer:g})}e.restore();for(const g of s){const h=d.axes[g.position];h&&yn(e,g,h,d.panel,t)}for(const g of r.guides.axes){const h=d.axisLabels[g.position];h&&wn(e,g,h,t)}Kn(e,a,d.legends,t),Gn(e,r.config.content,d.header,t,{width:o,height:i}),Wn(e,r.config.content,d.footer,t,{width:o,height:i})};class rt extends Error{constructor(t){super(t),this.name="ChartConfigRenderError"}}const oo=async(e,t)=>{const n=Ue(e);if(!n.ok)throw new rt(n.reason);return ot(n.compiled,t)};exports.CANVAS_CAPABILITY_MATRIX=Vt;exports.CANVAS_SUPPORTED_GRAPH_TYPES=se;exports.CANVAS_UNSUPPORTED_GRAPH_TYPES=De;exports.ChartConfigRenderError=rt;exports.NodeCanvasTextMeasurer=et;exports.canRenderConfigWithCanvas=Ue;exports.darkTheme=nt;exports.ensureDefaultFonts=Ie;exports.lightTheme=tt;exports.loadCanvasRuntime=_e;exports.parseChartConfig=Oe;exports.registerFont=re;exports.renderChartConfigToPng=oo;exports.renderGraphToPng=to;
|
|
1
|
+
"use strict";var it=Object.create;var ue=Object.defineProperty;var st=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var lt=Object.getPrototypeOf,dt=Object.prototype.hasOwnProperty;var ct=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of at(t))!dt.call(e,i)&&i!==n&&ue(e,i,{get:()=>t[i],enumerable:!(o=st(t,i))||o.enumerable});return e};var ut=(e,t,n)=>(n=e!=null?it(lt(e)):{},ct(t||!e||!e.__esModule?ue(n,"default",{value:e,enumerable:!0}):n,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const fe=require("node:fs"),Le=require("node:module"),D=require("node:path"),ft=require("node:url"),gt=require("@graphysdk/viz-engine/graph-config"),N=require("d3-shape"),c=require("@graphysdk/viz-engine"),ht=require("node:buffer");var w=typeof document<"u"?document.currentScript:null;let U,J;const _e=()=>U?Promise.resolve(U):(J??=import("@napi-rs/canvas").then(e=>(U=e,e)).catch(e=>{throw J=void 0,e}),J),W=()=>{if(!U)throw new Error("Canvas runtime is not loaded. Call loadCanvasRuntime() before rendering.");return U},y="Inter",x=new Set;let ge=!1,q=!1;const we=e=>`${e.family}|${e.weight??400}|${e.style??"normal"}`,re=e=>{const t=we(e);x.has(t)||(W().GlobalFonts.register(e.data,e.family),x.add(t))},mt=[{file:"Inter-Regular.ttf",family:y,weight:400},{file:"Inter-SemiBold.ttf",family:y,weight:600}],bt=[{file:"inter-latin-400-normal.woff",family:y,weight:400},{file:"inter-latin-600-normal.woff",family:y,weight:600}],At="@fontsource/inter",pt=()=>{try{const e=Le.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href),t=D.dirname(e.resolve("@graphysdk/node-renderer/package.json"));return D.join(t,"assets")}catch{return D.resolve(D.dirname(ft.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href)),"../assets")}},Ce=(e,t,n)=>{try{return fe.existsSync(e)?(re({family:t,data:fe.readFileSync(e),weight:n}),!0):!1}catch{return!1}},Tt=()=>{const e=pt();for(const{file:t,family:n,weight:o}of mt)Ce(D.join(e,t),n,o)&&(q=!0)},St=()=>{const e=Le.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:w&&w.tagName.toUpperCase()==="SCRIPT"&&w.src||new URL("index.cjs",document.baseURI).href);for(const{file:t,family:n,weight:o}of bt)if(!x.has(we({family:n,data:Buffer.alloc(0),weight:o})))try{const i=e.resolve(`${At}/files/${t}`);Ce(i,n,o)&&(q=!0)}catch{}},Ie=()=>(ge||(ge=!0,Tt(),St()),q),C=(e,t)=>e.x+t*e.width,_=(e,t)=>e.y+(1-t)*e.height,ee=e=>e==="catmull-rom"?N.curveCatmullRom:N.curveLinear,Be=e=>{switch(e){case"dashed":return[8,4];case"dotted":return[2,2];case"solid":return[]}},k=e=>e,yt=(e,t)=>t!=="connect"?e:e.filter(n=>c.getX(n)!==null&&c.getY(n)!==null),Rt=(e,t,n)=>{const o=ee(t.interpolate),i=N.area().curve(o),r=N.line().curve(o);if(e.mainAxis==="y"){const s=l=>_(n,c.getY(l)??0),a=l=>C(n,c.getXMin(l)??0),d=l=>C(n,c.getXMax(l)??c.getX(l)??0);i.y(s).x0(a).x1(d),r.y(s).x(d)}else{const s=l=>C(n,c.getX(l)??0),a=l=>_(n,c.getYMin(l)??0),d=l=>_(n,c.getYMax(l)??c.getY(l)??0);i.x(s).y0(a).y1(d),r.x(s).y(d)}if(t.missingValues==="gap"){const s=a=>c.getX(a)!==null&&c.getY(a)!==null;i.defined(s),r.defined(s)}return{areaGenerator:i,lineGenerator:r}},Et=k({geom:"area",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const r=c.createStyleResolver({colorScheme:i}).geomReaders(t),{areaGenerator:s,lineGenerator:a}=Rt(n,t.params,o),d=e;t.data.groupBy(c.GROUP_VARIABLES.group).forEach(l=>{const u=yt([...l],t.params.missingValues),f=u[0];if(!f)return;const g=r.get("color",f),h=r.get("alpha",f),m=r.get("strokeWidth",f),A=Be(r.get("lineType",f));e.save(),e.globalAlpha=h,e.fillStyle=g,e.beginPath(),s.context(d)(u),e.fill(),e.restore(),e.save(),e.globalAlpha=r.get("strokeAlpha",f),e.strokeStyle=g,e.lineWidth=m,e.setLineDash(A),e.lineJoin="round",e.lineCap="round",e.beginPath(),a.context(d)(u),e.stroke(),e.restore()})}}),he=(e,t,n,o,i,r)=>{const s=Math.max(0,Math.min(r.rx??r.ry??0,o/2)),a=Math.max(0,Math.min(r.ry??r.rx??0,i/2)),d=Math.PI/2;e.moveTo(t+s,n),e.lineTo(t+o-s,n),e.ellipse(t+o-s,n+a,s,a,0,-d,0),e.lineTo(t+o,n+i-a),e.ellipse(t+o-s,n+i-a,s,a,0,0,d),e.lineTo(t+s,n+i),e.ellipse(t+s,n+i-a,s,a,0,d,Math.PI),e.lineTo(t,n+a),e.ellipse(t+s,n+a,s,a,0,Math.PI,Math.PI*1.5),e.closePath()},Lt=k({geom:"bar",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const{Path2D:r}=W(),s=c.createStyleResolver({colorScheme:i}).geomReaders(t),a=n.mainAxis,d=new Map;for(const l of t.data){const u=c.getBarRectBounds(a,l);if(!u)continue;const f=C(o,u.x),g=o.y+u.y*o.height,h={x:f,y:g,width:u.width*o.width,height:u.height*o.height,fill:s.get("color",l),opacity:s.get("alpha",l)},m=c.buildColumnKey(a,u),A=d.get(m);A?A.bars.push(h):d.set(m,{bars:[h],style:{borderColor:s.get("borderColor",l),borderWidth:s.get("borderWidth",l),borderRadius:s.get("borderRadius",l),borderAlpha:s.get("alpha",l)}})}for(const{bars:l,style:u}of d.values()){const{borderColor:f,borderRadius:g,borderWidth:h,borderAlpha:m}=u,A=c.resolveBarBorderTreatment(h),p=g==="full"?void 0:c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a});if(!(l.length>1)){const[b]=l;if(!b)continue;const v=p??c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a,bounds:{width:b.width,height:b.height}}),E=new r;he(E,b.x,b.y,b.width,b.height,v),e.save(),e.globalAlpha=b.opacity,e.fillStyle=b.fill,e.fill(E),f!==void 0&&(e.clip(E),e.strokeStyle=f,e.lineWidth=A.outlineWidth,e.stroke(E)),e.restore();continue}const T=c.getBoundingRect(l),L=p??c.resolveBarCornerRadiiPx({borderRadius:g,mainAxis:a,bounds:{width:T.width,height:T.height}}),S=new r;he(S,T.x,T.y,T.width,T.height,L),e.save(),e.clip(S);for(const b of l)e.globalAlpha=b.opacity,e.fillStyle=b.fill,e.fillRect(b.x,b.y,b.width,b.height),f!==void 0&&(e.strokeStyle=f,e.lineWidth=A.separatorWidth,e.strokeRect(b.x,b.y,b.width,b.height));f!==void 0&&(e.globalAlpha=m,e.strokeStyle=f,e.lineWidth=A.outlineWidth,e.stroke(S)),e.restore()}}}),me=(e,t)=>{const n=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(n?.[1]!==void 0){const i=n[1],r=i.length===3?[...i].map(l=>l+l).join(""):i.slice(0,6),s=Number.parseInt(r.slice(0,2),16),a=Number.parseInt(r.slice(2,4),16),d=Number.parseInt(r.slice(4,6),16);return`rgba(${s}, ${a}, ${d}, ${t})`}const o=/^rgba?\(([^)]+)\)$/i.exec(e.trim());if(o?.[1]!==void 0){const i=o[1].split(",").map(d=>d.trim()),[r,s,a]=i;if(r!==void 0&&s!==void 0&&a!==void 0)return`rgba(${r}, ${s}, ${a}, ${t})`}return t===0?"rgba(0, 0, 0, 0)":e},_t=(e,t)=>t!=="connect"?e:e.filter(n=>c.getX(n)!==null&&c.getY(n)!==null),wt=(e,t)=>{const{seriesObservations:n,fillGenerator:o,panel:i,color:r,fillAlpha:s}=t,a=n.map(l=>c.getY(l)).filter(l=>l!==null).map(l=>_(i,l));if(a.length===0)return;const d=e.createLinearGradient(0,Math.min(...a),0,i.y+i.height);d.addColorStop(0,r),d.addColorStop(.7,me(r,0)),d.addColorStop(1,me(r,0)),e.save(),e.globalAlpha=s,e.fillStyle=d,e.beginPath(),o.context(e)(n),e.fill(),e.restore()},Ct=k({geom:"line",coord:"cartesian",draw:(e,{layer:t,panel:n,colorScheme:o})=>{const i=c.createStyleResolver({colorScheme:o}).geomReaders(t),r=N.line().x(a=>C(n,c.getX(a)??0)).y(a=>_(n,c.getY(a)??0)).curve(ee(t.params.interpolate)),s=N.area().x(a=>C(n,c.getX(a)??0)).y0(n.y+n.height).y1(a=>_(n,c.getY(a)??0)).curve(ee(t.params.interpolate));if(t.params.missingValues==="gap"){const a=d=>c.getX(d)!==null&&c.getY(d)!==null;r.defined(a),s.defined(a)}t.data.groupBy(c.GROUP_VARIABLES.group).forEach(a=>{const d=_t([...a],t.params.missingValues),l=d[0];if(!l)return;const u=i.get("strokeWidth",l),f=Be(i.get("lineType",l)),g=i.get("color",l),h=i.get("fillAlpha",l);h!==void 0&&wt(e,{seriesObservations:d,fillGenerator:s,panel:n,color:g,fillAlpha:h}),e.save(),e.globalAlpha=i.get("alpha",l),e.strokeStyle=g,e.lineWidth=u,e.setLineDash(f),e.lineJoin="round",e.lineCap="round",e.beginPath(),r.context(e)(d),e.stroke(),e.restore()})}}),It=k({geom:"point",coord:"cartesian",draw:(e,{layer:t,panel:n,colorScheme:o})=>{const i=c.createStyleResolver({colorScheme:o}).geomReaders(t);for(const r of t.data){const s=c.getX(r),a=c.getY(r);if(s===null||a===null)continue;const d=C(n,s),l=_(n,a),u=i.get("size",r)/2,f=i.get("borderWidth",r);e.save(),e.globalAlpha=i.get("alpha",r),e.fillStyle=i.get("color",r),e.strokeStyle=i.get("borderColor",r),e.lineWidth=f,e.beginPath(),e.arc(d,l,u,0,Math.PI*2),e.fill(),f>0&&e.stroke(),e.restore()}}}),ie=11,Bt="sans-serif",Nt=500,P=5,Ne=5,te=13,ve=6,V=12,be=21.6,vt=(e,t)=>{const n=e.mapping.y!==void 0,o=t.mainAxis==="y";return n!==o},Pt=(e,t,n)=>{const o=c.getRuleDashPattern(t,n);e.setLineDash(o),o.length>0&&(e.lineCap="round")},Ft=(e,t)=>X(e)&&X(t)?`${e}: ${t}`:X(e)?e:X(t)?t:null,X=e=>e!=null&&e.trim()!=="",kt=e=>{e.beginPath(),e.moveTo(2.48935,16.9323),e.lineTo(9.07098,9.82964),e.bezierCurveTo(9.51595,9.34944,9.51504,8.60728,9.0689,8.12818),e.lineTo(2.48866,1.06172),e.bezierCurveTo(1.85811,.384586,.974477,0,.049217,0),e.lineTo(0,0),e.lineTo(0,18),e.lineTo(.0443689,18),e.bezierCurveTo(.972463,18,1.85854,17.6131,2.48935,16.9323),e.closePath()},Pe=(e,t,n,o,i,r)=>{const s=Math.min(r,o/2,i/2);e.beginPath(),e.moveTo(t+s,n),e.lineTo(t+o-s,n),e.arcTo(t+o,n,t+o,n+s,s),e.lineTo(t+o,n+i-s),e.arcTo(t+o,n+i,t+o-s,n+i,s),e.lineTo(t+s,n+i),e.arcTo(t,n+i,t,n+i-s,s),e.lineTo(t,n+s),e.arcTo(t,n,t+s,n,s),e.closePath(),e.fill()},Dt=(e,t,n,o,i,r,s,a)=>{const d=n+P*2,l=ie+Ne*2,u=o==="start",f=u?r.x:r.x+r.width,g=_(r,i),h=u?-te:-(d-te),m=u?h+d-P:h+P-V;e.save(),e.translate(f,g),e.translate(0,-l/2),e.fillStyle=s,Pe(e,h,0,d,l,ve),e.save(),u||(e.translate(m+V/2,l/2),e.rotate(Math.PI),e.translate(-(m+V/2),-l/2)),e.translate(m,(l-be)/2),e.scale(V/10,be/18),e.fillStyle=s,kt(e),e.fill(),e.restore(),e.fillStyle=a,e.textAlign="left",e.textBaseline="middle",e.fillText(t,h+P,l/2),e.restore()},Ot=(e,t,n,o,i,r,s,a)=>{const d=n+P*2,l=ie+Ne*2,u=o==="start",f=C(r,i),g=u?r.y+r.height:r.y,h=u?-te:-8;e.save(),e.translate(f,g),e.translate(-d/2,0),e.fillStyle=s,Pe(e,0,h,d,l,ve),e.fillStyle=a,e.textAlign="left",e.textBaseline="middle",e.fillText(t,P,h+l/2),e.restore()},Ut=k({geom:"rule",coord:"cartesian",draw:(e,{layer:t,coordSystem:n,panel:o,compiled:i,textMeasurer:r,formattingLocale:s,colorScheme:a})=>{const d=t.data.getFirst();if(!d)return;const l=vt(t,n),u=l?c.getY(d):c.getX(d);if(u===null)return;const f=c.createStyleResolver({colorScheme:a}).geomReaders(t),g=f.get("color",d),h=c.getRuleLabelTextColor(g),m=f.get("strokeWidth",d);if(e.save(),e.strokeStyle=g,e.lineWidth=m,Pt(e,f.get("lineType",d),m),e.beginPath(),l){const S=_(o,u);e.moveTo(o.x,S),e.lineTo(o.x+o.width,S)}else{const S=C(o,u);e.moveTo(S,o.y),e.lineTo(S,o.y+o.height)}e.stroke(),e.restore();const A=Ft(t.params.label,c.formatRuleValue({guides:i.guides,numberFormat:i.config.numberFormat,layer:t,locale:s??i.config.parsingLocale}));if(A===null)return;const p=i.config.appearance.textScale,R={family:Bt,size:ie*p,weight:Nt};e.font=c.buildFontString(R);const T=r.measureText(A,R).width;(l?Dt:Ot)(e,A,T,t.params.labelPosition,u,o,g,h)}}),O=N.arc();O.digits(8);const Ht=k({geom:"bar",coord:"polar",draw:(e,{layer:t,coordSystem:n,panel:o,colorScheme:i})=>{const r=o.x+o.width/2,s=o.y+o.height/2,a=Math.min(o.width,o.height)/2,{Path2D:d}=W(),l=c.createStyleResolver({colorScheme:i}).geomReaders(t);e.save(),e.translate(r,s),e.scale(a,a);const u=e,f=new Map;for(const g of t.data){const{startAngle:h,endAngle:m}=c.getAngleExtent(g),{innerRadius:A,outerRadius:p}=c.getRadiusExtent(g);if(h===null||m===null||A===null||p===null)continue;const R={startAngle:h,endAngle:m,innerRadius:A,outerRadius:p,fill:l.get("color",g),opacity:l.get("alpha",g)},T=c.buildSliceGroupKey(n.bandAxis,R),L=f.get(T);L?L.items.push(R):f.set(T,{items:[R],style:{borderColor:l.get("borderColor",g),borderWidth:l.get("borderWidth",g),borderRadius:l.get("borderRadius",g),borderAlpha:l.get("alpha",g)}})}for(const{items:g,style:h}of f.values()){const{borderColor:m,borderRadius:A,borderWidth:p,borderAlpha:R}=h,T=c.resolveBarBorderTreatment(p),L=m!==void 0&&a>0,S=c.getUnionExtent(g),b=c.resolvePolarBarCornerRadiusUnit(A,S.outerRadius-S.innerRadius),v=a>0&&(L||b>0);e.save();let E;v&&(E=new d,O.cornerRadius(b),O.context(E)(S),e.clip(E)),O.cornerRadius(0);for(const Q of g)e.globalAlpha=Q.opacity,e.fillStyle=Q.fill,e.beginPath(),O.context(u)(Q),e.fill(),L&&(e.strokeStyle=m,e.lineWidth=T.separatorWidth/a,e.stroke());L&&E&&(e.globalAlpha=R,e.strokeStyle=m,e.lineWidth=T.outlineWidth/a,e.stroke(E)),e.restore()}e.restore()}}),Mt={bar:{cartesian:Lt,polar:Ht},line:{cartesian:Ct},area:{cartesian:Et},point:{cartesian:It},rule:{cartesian:Ut}},Fe=(e,t)=>Mt[e.geom]?.[t.type]??null,Gt=(e,t,n)=>{e.draw(t,n)};let Ae;const ke=()=>(Ae??=c.createCompiler(),Ae),se=["line","areaStacked","bar","barStacked","barStackedFill","column","columnStacked","columnStackedFill","combo","pie","donut","scatter","bubble"],De=["funnel","heatmap","waterfall","mekko","table"],Wt=new Set(se),Vt={supportedGraphTypes:[...se],unsupportedGraphTypes:[...De],supportedGeoms:{cartesian:["bar","line","area","point","rule"],polar:["bar"]}},B=e=>({ok:!1,reason:e}),j=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Xt=e=>{if(!j(e))return!1;const{columns:t,rows:n}=e;return!Array.isArray(t)||!Array.isArray(n)?!1:t.every(o=>j(o)&&typeof o.key=="string")},Kt=e=>{if("_unstable_mapping"in e&&e._unstable_mapping!==void 0)return!0;const t=e.referenceLines;return j(t)?t.trendline!==void 0||t.averageLine!==void 0:!1},Oe=e=>{if(!j(e))return B("Chart config must be a plain object.");if(!Xt(e.data))return B("Chart config is missing a valid `data` object (columns + rows).");const{data:t,...n}=e;return{ok:!0,input:n,data:t}},Ue=e=>{const t=Oe(e);if(!t.ok)return t;if(Kt(e))return B("Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`.");const n=t.input.type??"column";if(!Wt.has(n))return B(`Unsupported chart type for canvas rendering: ${n}.`);try{const o=ke(),i=gt.convertGraphConfig(t.input,t.data),r=o.compile({input:i,data:t.data});if(!r.ok)return B(`Chart config failed to compile: ${r.errors.map(s=>s.message).join("; ")}`);for(const s of r.compiled.layers)if(Fe(s,r.compiled.coordSystem)===null)return B(`No canvas geom renderer for ${s.geom} (${r.compiled.coordSystem.type} coord).`);return{ok:!0,compiled:r.compiled}}catch(o){const i=o instanceof Error?o.message:String(o);return B(`Chart config failed to compile: ${i}`)}},K=6,z=10,Yt=20,ae=y,le=12,He=y,H=12,de=1.3,M=10,G=12,F=6,Me=16,zt=24,Ge=6,We=3,ne=4,qt=8,jt="#9ca3af",Ve=16,Zt=1.3,Xe=13,Qt=1.4,Ke=12,Jt=1.4,Z=8,ce=12,$t=1.3,xt=200,en=120,tn=80,Ye=22,nn=9,on=11,rn=10,Y=9,pe=12,sn='-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',an=11.5,ln=550,dn={light:.55,mid:.75,dark:.08},cn={light:.62,mid:.8,dark:.85},un=.22,fn=.65,gn=y,hn=12,mn={family:ae,size:le},bn={family:gn,size:hn},An={family:He,size:H},pn=8,Te=1,Tn=[2,3],Sn=[1,3],yn=(e,t,n,o,i)=>{if(!t.isVisible||t.ticks.length===0)return;const r=t.position==="bottom"||t.position==="top",s=t.ticksVisible?1:0;e.save(),e.font=c.buildFontString(mn),e.fillStyle=i.textSecondary,e.strokeStyle=i.gridLine,e.lineWidth=1,e.setLineDash([]);for(const a of t.ticks){const d=r?a.position:1-a.position;t.ticksVisible&&En(e,t.position,d,n,o),_n(e,t.position,d,n,o,a.formattedLabel,t.labelRotation,s)}e.restore()},Rn=(e,t,n,o)=>{if(e==="bottom"||e==="top"){const a=o.x+t*o.width,d=e==="top"?n.y+n.height:n.y,l=e==="top"?-K:K;return{x1:a,y1:d,x2:a,y2:d+l}}const i=o.y+t*o.height,r=e==="right"?n.x:n.x+n.width,s=e==="right"?K:-K;return{x1:r,y1:i,x2:r+s,y2:i}},En=(e,t,n,o,i)=>{const{x1:r,y1:s,x2:a,y2:d}=Rn(t,n,o,i);e.beginPath(),e.moveTo(r,s),e.lineTo(a,d),e.stroke()},Ln=(e,t,n,o,i)=>{if(e==="bottom"||e==="top"){const s=o.x+t*o.width;return e==="bottom"?{x:s,y:n.y+i,textAlign:"center",textBaseline:"top"}:{x:s,y:n.y+n.height-i,textAlign:"center",textBaseline:"alphabetic"}}const r=o.y+t*o.height;return e==="left"?{x:n.x+n.width-i,y:r,textAlign:"right",textBaseline:"middle"}:{x:n.x+i,y:r,textAlign:"left",textBaseline:"middle"}},_n=(e,t,n,o,i,r,s,a)=>{const d=z*a;if(s!==0&&(t==="top"||t==="bottom")){const u=i.x+n*i.width,f=t==="top";e.save(),e.translate(u,f?o.y+o.height-d:o.y+d),e.rotate(s*Math.PI/180),e.textAlign=f?"left":"right",e.textBaseline="middle",e.fillText(r,0,0),e.restore();return}const l=Ln(t,n,o,i,d);e.textAlign=l.textAlign,e.textBaseline=l.textBaseline,e.fillText(r,l.x,l.y)},wn=(e,t,n,o)=>{if(!t.isVisible||!t.label)return;e.save(),e.font=c.buildFontString(bn),e.fillStyle=o.textPrimary,e.textBaseline="middle";const{x:i,y:r,alignment:s}=Cn(t.position,n);e.textAlign=s,e.fillText(t.label,i,r),e.restore()},Cn=(e,t)=>{const n=t.y+t.height/2;return e==="left"?{x:t.x,y:n,alignment:"start"}:e==="right"?{x:t.x+t.width,y:n,alignment:"end"}:{x:t.x+t.width/2,y:n,alignment:"center"}},In="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABgCAYAAAC65+QhAAAKo0lEQVR42u2de4wdVR3HPzN32+oSUQSsikEoosR3iko08oovEkwMpmiIr/KHIomgUYyPiBofkRjjE+MjEk3RQNIYTdUotKkoaql0Wyympbtl2XbLtrW71n3v3ntnrn+c38n98cvcOzP3tfcud5LJ5u7Ozpz5nt/7nN/3QncfAVBQn18LfBd4GJgFYvm5B/iW/N0fBfn/VX9ogF4K3A0sAhV1xubzIrBFrk+6z6oDyEvCmcBXgTkFRgkoA5E6y/J7f80s8GXg2Uoyw9UCUGhm/wPAYQNQJFJkJUmDpgEbkfusCnW0dujNwM4aAEVGak4aaYvVdRqwHcAbexkwDdCLgZ8mqJgFaBo4BowD/wQOAbuBCSNhsVHJGPgJ8KJesl+hshnPBD4LTKqXLCUANAPsF0CKRvWm5W+Pi6RZwErqXqeA24DBhLF0rZptkhfUUhQbO7QEHBUJmjZqFhl7NQ/sEsCWjf2KjTo+AlzXbeoYAAPq80Zgmxp0McEOxQLOiNiiSsqpATsK3A+MJUhXZCTyd8Cr1dgGVgowLUEvAL6tZrtcww7NAAeAg3VipjTAisAR4CEDtLZfZRV/fQdYbya34+6+ANwiElJRamABmhdVPGxmPStISdefFjUbVfYrrqGO48DNymaFnVSza8QrJalZrGzTmHiz/2UESIOdBbBJ4G/ynCgh/tITcz/wwnaCpdXsEuDeDPHQmLj4YzkkppzyOQ2wIfO8JPt1ADiv1WBpj3EW8BUl5lEdO3RQVK2UUcU0ICeAH4q7zwKYluBFUcW/q7BEA+Zt6G4JX8JWpx2bZQBp7v4A8KgaUBpIkQIhAn4sASrA+RKoxgqsKKN0/Qf4l3jWhRpg3dbKeOhK4IEUd18WEMeAqRx2SEvJdpOKaFv4JklVtHRltV/jIl3HE7RgXLSkKTu0AfhZhrTjvxIEPqEGmEfNRoD3mTGECVIdyHUjOdTRj3NBwFoyOWPFPDt32vEZcb310o5Z4DEBKc6hZrGyY1+UcktauURPoC3PRBnVcU7Mgn2nLY2o2fXAv1PsUEk82R5TbMujZncDL2kggdXXXQzck0MdKzJuO55/5AHo9cAfUtx9JHZo2HijPAHjLuAtTeZgduxvk/tmeX5JeWEP1FCWWVkPfM/8c5IdOi0gjapYJM4YRccSKmwG1rQwq9f3KAAflbQmrjO2OTV+D9SepJnwN14jacdEjbRDu/tDotvlBqTIg/0b4JwaEtGKOC9U3rHe+ObTgApN2vFwStoRiXc5klBlrNBYbjYD3K5qRa2sdQ8IYBubAcoP5myx8PXsUCyx0CMSsMVNAJQkWT59uL7FtaKCsrUNARWoEsjeDPHQqEjSUpPAZPF8f5IXawVgHqjXNQpUKHGRz/CXE9z9skjRvhxpR7PSpSP6HwDPb7LW3TRQSBKrQdJq9oS4+7kOAJSWBN/ahFdsGqgLpAYUmZlcFAk6YYCrrMCpAdsDXNtpiQqBD8qKaiz6H0jqMSo1pfVq5oIVXNbyKnkp8Htgq0TuQSfGFUooUJGH+Z8TYtyfIQB20wqOj+c2ATfKmAudAOpiNSuheLPnSGmh0oVrXqGM1VcjO/bQ5wog/pg1qxb0wGaOjs2OPeKny96iPED1jz5QfaD6QPWB6gPVB6p/9IHqA9UHqg9UH6g+UH2g+gd1FwXbfVRU2abSq91O7QYqEmAKptbVc9LcrsH6NcECrr59B642v1MtM5W7vILaVqD8SokHYxtwGfA54D7grbi2sBHVIRA9nYDya2B+pcT3mbwLtzZYUEtOv8QtOX0Nt4ZWUBK4qoGK1Cb8SeCTuA2pv1WSFSnJKeAWMG7H7Sy511xXWW1AxcpYR7gtzBtxPSVLdSQlUpI3DNwAvB3Xs+JXVrrOfoVNSJHfjbsduBy4CbfVOIvtsbZsO67z82Zzj7iXgfKx0GHg/SINuxqUBu0d/Ub7S3EdWEUZX6UXgfIz/E3cCvOvZPabtS/afp0CPgW8AfizeW7PAOUXRa/Crf2jvF3QQsewDtd68aNuUcFGgApktrdS3REXKZUMWhiLDfa6Mfe25R1in/yOuKiF+Vy7Yqugk0DpuKcAfEyCzFvFZkVd2v1daBT8sEU7bSOqG/cfwu2I8xIx0AUbPvQ41ykV73gKU2tH3CtUuBCsII2Jzww+RHV7eFDHRrY1KQ5MNL4Jx3RxB9VNaZ0CS48lAq4A/gL8ArgoxUuv7VSZRduvQVy72pBIWifqUFq6LwB+jmu6vEI1F9Q7JsRcaMkqhR0YcAm4EHhZm6VKb1kcBD4vE7RZ/b5QY6I8KMumGuvP0YEOqsBym59RptpP+CWxj7WqrBakQLXQbVC/8+eOAVZ2C2SrpHZZ1biuSUjc6wEU4PbZPymee51SzwDXZ7ytU0C165jF7WD+OvARsS1xShuIBmgO198TinkYVKpXxnVJfB+YGuhx/rt3S3lng1Gzem4/UA1Qx3B0AGeZTb4l8X77JOsIB3qYxQxcPT6PHUJU7BSOJeM1CbugPUhHxN7NA2GvL4DqelaaFJ2i2lj9cuBcqv0wvgoSCkh/Ba7GddeHQDzQ5eqVNpFhBju0JCBNSbD5LCNFXhrX4Bo1vwHcqYCL6dBKcaMBaxFH2pC3RKNV87S8/NlUyUxtnDQgoNyFa8ebUOOIk8Q3Unwl+xLaV5ttgd2U4o0sndJVkmDHGceh28qmJNg8noGRbIeydXUZySxQJ+UhnQTK0phsydFEGZtW3kNisBcTSLU0QAdxK0CZe2uWzQt5HpVWNTLWA0rXrHzaMZnAm5J2LovK7DdEXUmsiaclcj8zbyf84+amscxK3EagLK/Be6hyouQlzhrHUYKcSOHhrIikbmi0N3lrAupHzINbBVSgCmfg2lb/2CCV0bxUVZ803FJJduhBsXlNMSNeZwYZKUq142oQjUqYv997eSp74p0JXJlZ7jeDYxCqZYdKhhbuw4Z2pOHYcQ1V1gxLbXRUim/TTXSo+3v5ZPUTRlqz0q0VxQ4dMgQ5SXSRC1IwPLfVdLdX1mF4Lkr5Ybfii8rLixlLcvlgg2o2JaFCLXevpejXEnm3fLOcR/rTNUizYsU2OCxiP9+EhOUByIcqRxUYtSi595o2/7a00nqwblHiW4t25Jh4mZM5wcpjhxZkUg4qd2/tUKzA/LhyEm1fJvM3v5ynklIVE8gjYgkrdhp67EaZfjTj4XEce8eJFDtUxNFLnrcStNsFBdpNhpRYq2OkOOw8RdtCE7y+3psNSVwUp9ih+2gduU1L2Fmfh/t2jIUUNrJJkbBhxQIU5+Dy3SdSVEpx949JcNpV1NraW7wKxxhWj2ezIi+7VxJrq1o2DivhNr0OS9qUBFCkvN4XgDO6lazdphrvVJUFD5j1jmV5+QdMOFExzD3jGdKOGLcud1Gv0P/rGVyH29B6MiWcmBbARiVAHBNg9srvsqQdV3cDIXuz9ut88Tpp4cSi5I77RSWLGdKOGxUoBXq0Z8cW2C7D8X+n0XFXUtz9nJRhz1lt3xJkFxdvUMV7b7/K5tuAdEStpWgr8MpeVbNGVoHPwG20n6lBs21DhiGVLK9agOrZrwtxq7ePGm48X5PfgeuJWdvN381CG7+pIlBbfryEXCJpxlqRtBG10oHa6NXVx/8Ba+cluUx5B18AAAAASUVORK5CYII=",I=Ye;let $;const Bn=()=>{if($)return $;const{Image:e}=W(),t=new e,n=In.replace(/^data:image\/png;base64,/,"");return t.src=ht.Buffer.from(n,"base64"),$=t,t},ze=(e,t,n="full")=>!e||t.width<en||t.height<tn?"hidden":t.width<xt||n==="mini"?"mini":"full",Nn=e=>{const t=vn(e);if(t===null)return"light";const n=Pn(t);return n<=un?"dark":n<=fn?"mid":"light"},oe=(e,t,n)=>e.placement!==n||ze(e.enabled,t,e.variant)==="hidden"?0:Ye,qe=(e,t,n,o,i,r)=>{if(t.placement!==r)return;const s=ze(t.enabled,i,t.variant);if(s==="hidden")return;const a=Nn(o.background),d=a==="dark",l={family:sn,size:an,weight:400},u={...l,weight:ln};let f=0;s==="full"&&(e.font=c.buildFontString(l),f=e.measureText("Made with ").width,e.font=c.buildFontString(u),f+=e.measureText("Graphy").width);const g=s==="mini"?0:nn,h=s==="mini"?0:on,m=s==="mini"?0:rn,A=s==="mini"?I:g+Y+m+f+h,p=n.x+n.width-A,R=n.y+Math.max(0,(n.height||I)/2-I/2);e.save(),e.globalAlpha=cn[a],e.textBaseline="middle",e.textAlign="left",d||(e.shadowColor="rgba(0, 0, 0, 0.09)",e.shadowBlur=4,e.shadowOffsetY=1),e.beginPath(),e.roundRect(p,R,A,I,I/2),e.fillStyle=`rgba(255, 255, 255, ${dn[a]})`,e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0;const T=d?"#FFFFFF":"#2A2A28",L=s==="mini"?p+(A-Y)/2:p+g,S=R+(I-pe)/2;if(e.save(),d&&(e.filter="invert(1)"),e.drawImage(Bn(),L,S,Y,pe),e.restore(),s==="full"){const b=p+g+Y+m,v=R+I/2;e.fillStyle=T,e.font=c.buildFontString(l),e.fillText("Made with ",b,v);const E=e.measureText("Made with ").width;e.font=c.buildFontString(u),e.fillText("Graphy",b+E,v)}e.restore()},vn=e=>{const t=e.trim();if(!t.startsWith("#"))return null;const n=t.slice(1);if(n.length===3){const o=n[0],i=n[1],r=n[2];return o===void 0||i===void 0||r===void 0?null:{red:Number.parseInt(o+o,16),green:Number.parseInt(i+i,16),blue:Number.parseInt(r+r,16)}}return n.length>=6?{red:Number.parseInt(n.slice(0,2),16),green:Number.parseInt(n.slice(2,4),16),blue:Number.parseInt(n.slice(4,6),16)}:null},Pn=({red:e,green:t,blue:n})=>{const o=i=>{const r=i/255;return r<=.03928?r/12.92:((r+.055)/1.055)**2.4};return .2126*o(e)+.7152*o(t)+.0722*o(n)},Fn={family:y,size:Ve,weight:600},kn={family:y,size:Xe},Dn={family:y,size:Ke},On={family:y,size:ce,weight:500},Un={family:y,size:ce},je=Ve*Zt,Hn=Xe*Qt,Ze=Ke*Jt,Qe=ce*$t,Je=e=>{if(e===null)return null;if(e.label!==void 0&&e.label!=="")return e.label;if(e.url!==void 0&&e.url!==""&&c.isSafeUrl(e.url))try{return new URL(e.url).hostname}catch{return e.url}return null},Mn=(e,t)=>{let n=0;const o=e.isTitleVisible&&e.title!==null,i=e.isSubtitleVisible&&e.subtitle!==null;o&&(n+=je),i&&(n>0&&(n+=Z),n+=Hn);const r=oe(e.brandMark,t,"header");!o&&!i&&r>0&&(n=r);const s=e.isCaptionVisible&&e.caption!==null,a=e.isSourceVisible&&Je(e.source)!==null,d=oe(e.brandMark,t,"footer");let l=0;return s&&(l+=Ze),(a||d>0)&&(l>0&&(l+=Z),l+=Math.max(Qe,d)),{headerHeight:n,footerHeight:l}},Gn=(e,t,n,o,i)=>{if(n.height===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let r=n.y;t.isTitleVisible&&t.title!==null&&(e.font=c.buildFontString(Fn),e.fillStyle=o.textPrimary,e.fillText(c.extractPlainText(t.title),n.x,r),r+=je+Z),t.isSubtitleVisible&&t.subtitle!==null&&(e.font=c.buildFontString(kn),e.fillStyle=o.textSecondary,e.fillText(c.extractPlainText(t.subtitle),n.x,r)),e.restore(),qe(e,t.brandMark,n,o,i,"header")},Wn=(e,t,n,o,i)=>{if(n.height===0)return;const r=t.isCaptionVisible?t.caption:null,s=t.isSourceVisible?Je(t.source):null,a=oe(t.brandMark,i,"footer");if(r===null&&s===null&&a===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let d=n.y;if(r!==null&&(e.font=c.buildFontString(Dn),e.fillStyle=o.textSecondary,e.fillText(c.extractPlainText(r),n.x,d),d+=Ze+Z),s!==null){let l=n.x;l=Se(e,"Source: ",On,o.textSecondary,l,d),Se(e,s,Un,o.textSecondary,l,d)}e.restore(),qe(e,t.brandMark,{x:n.x,y:d,width:n.width,height:Math.max(Qe,a)},o,i,"footer")},Se=(e,t,n,o,i,r)=>(e.font=c.buildFontString(n),e.fillStyle=o,e.fillText(t,i,r),i+e.measureText(t).width),Vn=(e,t,n,o,i)=>{e.save(),e.lineCap="round",e.strokeStyle=i.gridLine;for(const r of c.computePanelBorderPaths(n.border,o,pn))e.lineWidth=r.lineWidth??Te,e.setLineDash(ye(r.lineStyle)),Xn(e,r.segments),e.stroke();for(const r of t){if(!r.gridVisible)continue;const s=r.position==="top"||r.position==="bottom";e.lineWidth=r.gridLineWidth??Te,e.setLineDash(ye(r.gridLineStyle));for(const a of r.ticks){if(a.position<=0||a.position>=1)continue;const d=s?a.position:1-a.position;if(e.beginPath(),s){const l=o.x+d*o.width;e.moveTo(l,o.y),e.lineTo(l,o.y+o.height)}else{const l=o.y+d*o.height;e.moveTo(o.x,l),e.lineTo(o.x+o.width,l)}e.stroke()}}e.restore()},ye=e=>{switch(e){case"dashed":return Tn;case"dotted":return Sn;case"solid":return[]}},Xn=(e,t)=>{e.beginPath();for(const n of t)switch(n.type){case"move":e.moveTo(n.x,n.y);break;case"line":e.lineTo(n.x,n.y);break;case"arc":e.arc(n.cx,n.cy,n.radius,n.startAngle,n.endAngle);break;case"close":e.closePath();break}},Kn=(e,t,n,o)=>{e.save(),e.font=c.buildFontString(An),e.textBaseline="middle";for(const r of t)r.display==="direct"&&Yn(e,r,n,o);const i=new Map;for(const r of t){if(r.display!=="pill"||r.items.length===0)continue;const s=i.get(r.position);s?s.push(r):i.set(r.position,[r])}for(const[r,s]of i){const a=n[r];a&&(r==="top"||r==="bottom"?zn(e,s,a,o):qn(e,s,a,o))}e.restore()},Yn=(e,t,n,o)=>{const i=n[t.position];if(i){e.textAlign="left";for(const r of t.items)r.normalizedY!==null&&(e.fillStyle=typeof r.visual.color=="string"?r.visual.color:o.textPrimary,e.fillText(r.formattedLabel,i.x+qt,_(i,r.normalizedY)))}},zn=(e,t,n,o)=>{const i=$e(t),r=i.reduce((l,u,f)=>l+Zn(u)+e.measureText(u.label).width+(f===0?0:Re(u)),0),s=H*de;let a=n.x+Math.max(0,(n.width-r)/2);const d=n.y+Ge+Math.max(s,G)/2;for(let l=0;l<i.length;l++){const u=i[l];u&&(l>0&&(a+=Re(u)),a=xe(e,u,a,d,o))}},qn=(e,t,n,o)=>{const i=$e(t),r=Math.max(H*de,G),s=4,a=i.length*r+Math.max(0,i.length-1)*s;let d=n.y+Math.max(0,(n.height-a)/2)+r/2;for(const l of i)xe(e,l,n.x,d,o),d+=r+s},$e=e=>{const t=[];for(const n of e){const o=n.aesthetics.includes("size");n.items.forEach((i,r)=>{const s=i.visual.size,a=o&&typeof s=="number"&&Number.isFinite(s)&&s>0?s:void 0;t.push({label:i.formattedLabel,colors:jn(i.visual.color),bubbleSize:a,isFirstInGroup:r===0})})}return t},jn=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="string"):[],Re=e=>e.isFirstInGroup?zt:Me,Zn=e=>{if(e.bubbleSize!==void 0)return e.bubbleSize+F;const t=e.colors.length;if(t===0)return 0;if(t===1)return M+F;const n=Math.min(t,We);return M+(n-1)*ne+F},xe=(e,t,n,o,i)=>{let r=n;if(t.bubbleSize!==void 0){const s=t.bubbleSize/2;e.fillStyle=t.colors[0]??jt,e.beginPath(),e.arc(r+s,o,s,0,Math.PI*2),e.fill(),r+=t.bubbleSize+F}else if(t.colors.length>0){const s=t.colors.slice(0,We);for(let a=0;a<s.length;a++){const d=s[a];d&&(e.fillStyle=d,e.fillRect(r+a*ne,o-G/2,M,G))}r+=M+(s.length-1)*ne+F}return e.fillStyle=i.textPrimary,e.textAlign="left",e.fillText(t.label,r,o),r+e.measureText(t.label).width},Ee=(e,t)=>Math.min(Math.max(...e),t),Qn=e=>t=>{if(!t.isVisible||t.ticks.length===0)return 0;const n=t.position==="top"||t.position==="bottom",o=t.ticks.map(s=>e.measureText(s.formattedLabel,{family:ae,size:le})),i=t.labelMaxWidthPx??Number.POSITIVE_INFINITY;if(n){if(t.labelRotation!==0){const s=o.map(a=>a.width);return Ee(s,i)+2*z}return Math.max(...o.map(s=>s.height))+z}const r=o.map(s=>s.width);return Ee(r,i)+z},Jn=e=>t=>{if(t.items.length===0)return 0;const n={family:He,size:H};if(t.position==="top"||t.position==="bottom"){const r=H*de;return Math.max(r,G)+Ge*2}const i=t.items.map(r=>{const s=e.measureText(r.formattedLabel,n).width;return M+F+s});return Math.max(...i)+Me},$n=e=>(t,n)=>{const{labelLineHeight:o,labelFontWeight:i}=c.getDifferenceArrowDimensions(n,1);return e.measureText(t,{family:y,size:o,weight:i})},xn=e=>(t,n)=>{const{fontSize:o,fontWeight:i}=c.getDataLabelDimensions(t,1);return e.measureText(n,{family:y,size:o,weight:i})},eo=e=>({measureAxis:Qn(e),measureAxisLabel:()=>Yt,measureLegend:Jn(e),measureTickLabel:t=>e.measureText(t,{family:ae,size:le}),measureDifferenceArrowLabel:$n(e),measureDataLabel:xn(e),measureHeadline:()=>({width:0,height:0}),measureHeadlineItemWidths:()=>[]});class et{constructor(){this.currentFont="";const t=W().createCanvas(1,1);this.ctx=t.getContext("2d")}measureText(t,n){const o=c.buildFontString(n);this.currentFont!==o&&(this.ctx.font=o,this.currentFont=o);const i=this.ctx.measureText(t);return{width:i.width,height:i.fontBoundingBoxAscent+i.fontBoundingBoxDescent,ascent:i.fontBoundingBoxAscent,descent:i.fontBoundingBoxDescent}}}const tt={background:"#ffffff",textPrimary:"#111827",textSecondary:"#6b7280",gridLine:"#e5e7eb",panelBorder:"#d1d5db",legendPillBackground:"rgba(0, 0, 0, 0.04)",legendPillBorder:"rgba(0, 0, 0, 0.08)"},nt={background:"#0b0f17",textPrimary:"#e5e7eb",textSecondary:"#9ca3af",gridLine:"#1f2937",panelBorder:"#374151",legendPillBackground:"rgba(255, 255, 255, 0.06)",legendPillBorder:"rgba(255, 255, 255, 0.12)"},to=async({input:e,data:t},n)=>{const i=ke().compile({input:e,data:t});if(!i.ok)throw new Error(`Failed to compile graph spec: ${i.errors.map(r=>r.message).join("; ")}`);return ot(i.compiled,n)},ot=async(e,t)=>{const{Canvas:n}=await _e();if(Ie(),t.fonts)for(const p of t.fonts)re(p);const o=c.formatLegends({legends:e.guides.legends.drawn,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattingLocale:t.formattingLocale}),i={width:t.width,height:t.height},{headerHeight:r,footerHeight:s}=Mn(e.config.content,i),a={headerSize:{width:t.width,height:r},footerSize:{width:t.width,height:s}},d=new et,{layout:l,formattedAxes:u}=new c.LayoutCompiler(eo(d)).compile({axes:e.guides.axes,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattedLegends:o,containerSize:{width:t.width,height:t.height},externalMeasurements:a,formattingLocale:t.formattingLocale,layout:e.config.layout}),f=t.pixelRatio??2,g=new n(t.width*f,t.height*f),h=g.getContext("2d");h.scale(f,f);const m=t.colorScheme??"light";return no(h,m==="dark"?nt:tt,m,t.width,t.height,e,u,o,l,d,t.formattingLocale),g.encode("png")},no=(e,t,n,o,i,r,s,a,d,l,u)=>{e.fillStyle=t.background,e.fillRect(0,0,o,i),Vn(e,s,r.guides.panel,d.panel,t),e.save(),e.beginPath(),e.rect(d.panel.x,d.panel.y,d.panel.width,d.panel.height),e.clip();const f={coordSystem:r.coordSystem,panel:d.panel,compiled:r,theme:t,colorScheme:n,textMeasurer:l,formattingLocale:u};for(const g of r.layers){const h=Fe(g,r.coordSystem);h&&Gt(h,e,{...f,layer:g})}e.restore();for(const g of s){const h=d.axes[g.position];h&&yn(e,g,h,d.panel,t)}for(const g of r.guides.axes){const h=d.axisLabels[g.position];h&&wn(e,g,h,t)}Kn(e,a,d.legends,t),Gn(e,r.config.content,d.header,t,{width:o,height:i}),Wn(e,r.config.content,d.footer,t,{width:o,height:i})};class rt extends Error{constructor(t){super(t),this.name="ChartConfigRenderError"}}const oo=async(e,t)=>{const n=Ue(e);if(!n.ok)throw new rt(n.reason);return ot(n.compiled,t)};exports.CANVAS_CAPABILITY_MATRIX=Vt;exports.CANVAS_SUPPORTED_GRAPH_TYPES=se;exports.CANVAS_UNSUPPORTED_GRAPH_TYPES=De;exports.ChartConfigRenderError=rt;exports.NodeCanvasTextMeasurer=et;exports.canRenderConfigWithCanvas=Ue;exports.darkTheme=nt;exports.ensureDefaultFonts=Ie;exports.lightTheme=tt;exports.loadCanvasRuntime=_e;exports.parseChartConfig=Oe;exports.registerFont=re;exports.renderChartConfigToPng=oo;exports.renderGraphToPng=to;
|
package/dist/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { createRequire as Le } from "node:module";
|
|
|
3
3
|
import O from "node:path";
|
|
4
4
|
import { fileURLToPath as nt } from "node:url";
|
|
5
5
|
import { convertGraphConfig as rt } from "@graphysdk/viz-engine/graph-config";
|
|
6
|
-
import { curveCatmullRom as st, curveLinear as it, area as Re, line as
|
|
7
|
-
import { createStyleResolver as D, GROUP_VARIABLES as
|
|
6
|
+
import { curveCatmullRom as st, curveLinear as it, area as Re, line as we, arc as at } from "d3-shape";
|
|
7
|
+
import { createStyleResolver as D, GROUP_VARIABLES as _e, getX as _, getY as w, getXMin as lt, getXMax as dt, getYMin as ct, getYMax as ft, getBarRectBounds as ut, buildColumnKey as ht, resolveBarBorderTreatment as Ie, resolveBarCornerRadiiPx as $, getBoundingRect as gt, getRuleDashPattern as mt, getRuleLabelTextColor as At, formatRuleValue as bt, buildFontString as S, getAngleExtent as pt, getRadiusExtent as yt, buildSliceGroupKey as Tt, getUnionExtent as Et, resolvePolarBarCornerRadiusUnit as St, createCompiler as Lt, isSafeUrl as Rt, extractPlainText as te, computePanelBorderPaths as wt, getDataLabelDimensions as _t, getDifferenceArrowDimensions as It, formatLegends as Bt, LayoutCompiler as Nt } from "@graphysdk/viz-engine";
|
|
8
8
|
import { Buffer as Ct } from "node:buffer";
|
|
9
9
|
let M, x;
|
|
10
10
|
const vt = () => M ? Promise.resolve(M) : (x ??= import("@napi-rs/canvas").then((e) => (M = e, e)).catch((e) => {
|
|
@@ -63,17 +63,17 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
63
63
|
case "solid":
|
|
64
64
|
return [];
|
|
65
65
|
}
|
|
66
|
-
}, F = (e) => e, Gt = (e, t) => t !== "connect" ? e : e.filter((o) =>
|
|
67
|
-
const n = ne(t.interpolate), s = Re().curve(n), r =
|
|
66
|
+
}, F = (e) => e, Gt = (e, t) => t !== "connect" ? e : e.filter((o) => _(o) !== null && w(o) !== null), Ut = (e, t, o) => {
|
|
67
|
+
const n = ne(t.interpolate), s = Re().curve(n), r = we().curve(n);
|
|
68
68
|
if (e.mainAxis === "y") {
|
|
69
|
-
const i = (l) => I(o,
|
|
69
|
+
const i = (l) => I(o, w(l) ?? 0), a = (l) => B(o, lt(l) ?? 0), d = (l) => B(o, dt(l) ?? _(l) ?? 0);
|
|
70
70
|
s.y(i).x0(a).x1(d), r.y(i).x(d);
|
|
71
71
|
} else {
|
|
72
|
-
const i = (l) => B(o,
|
|
72
|
+
const i = (l) => B(o, _(l) ?? 0), a = (l) => I(o, ct(l) ?? 0), d = (l) => I(o, ft(l) ?? w(l) ?? 0);
|
|
73
73
|
s.x(i).y0(a).y1(d), r.x(i).y(d);
|
|
74
74
|
}
|
|
75
75
|
if (t.missingValues === "gap") {
|
|
76
|
-
const i = (a) =>
|
|
76
|
+
const i = (a) => _(a) !== null && w(a) !== null;
|
|
77
77
|
s.defined(i), r.defined(i);
|
|
78
78
|
}
|
|
79
79
|
return { areaGenerator: s, lineGenerator: r };
|
|
@@ -82,7 +82,7 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
82
82
|
coord: "cartesian",
|
|
83
83
|
draw: (e, { layer: t, coordSystem: o, panel: n, colorScheme: s }) => {
|
|
84
84
|
const r = D({ colorScheme: s }).geomReaders(t), { areaGenerator: i, lineGenerator: a } = Ut(o, t.params, n), d = e;
|
|
85
|
-
t.data.groupBy(
|
|
85
|
+
t.data.groupBy(_e.group).forEach((l) => {
|
|
86
86
|
const c = Gt([...l], t.params.missingValues), f = c[0];
|
|
87
87
|
if (!f) return;
|
|
88
88
|
const u = r.get("color", f), h = r.get("alpha", f), g = r.get("strokeWidth", f), A = ve(r.get("lineType", f));
|
|
@@ -147,8 +147,8 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
147
147
|
return `rgba(${r}, ${i}, ${a}, ${t})`;
|
|
148
148
|
}
|
|
149
149
|
return t === 0 ? "rgba(0, 0, 0, 0)" : e;
|
|
150
|
-
}, Kt = (e, t) => t !== "connect" ? e : e.filter((o) =>
|
|
151
|
-
const { seriesObservations: o, fillGenerator: n, panel: s, color: r, fillAlpha: i } = t, a = o.map((l) =>
|
|
150
|
+
}, Kt = (e, t) => t !== "connect" ? e : e.filter((o) => _(o) !== null && w(o) !== null), Xt = (e, t) => {
|
|
151
|
+
const { seriesObservations: o, fillGenerator: n, panel: s, color: r, fillAlpha: i } = t, a = o.map((l) => w(l)).filter((l) => l !== null).map((l) => I(s, l));
|
|
152
152
|
if (a.length === 0) return;
|
|
153
153
|
const d = e.createLinearGradient(0, Math.min(...a), 0, s.y + s.height);
|
|
154
154
|
d.addColorStop(0, r), d.addColorStop(0.7, ge(r, 0)), d.addColorStop(1, ge(r, 0)), e.save(), e.globalAlpha = i, e.fillStyle = d, e.beginPath(), n.context(e)(o), e.fill(), e.restore();
|
|
@@ -156,12 +156,12 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
156
156
|
geom: "line",
|
|
157
157
|
coord: "cartesian",
|
|
158
158
|
draw: (e, { layer: t, panel: o, colorScheme: n }) => {
|
|
159
|
-
const s = D({ colorScheme: n }).geomReaders(t), r =
|
|
159
|
+
const s = D({ colorScheme: n }).geomReaders(t), r = we().x((a) => B(o, _(a) ?? 0)).y((a) => I(o, w(a) ?? 0)).curve(ne(t.params.interpolate)), i = Re().x((a) => B(o, _(a) ?? 0)).y0(o.y + o.height).y1((a) => I(o, w(a) ?? 0)).curve(ne(t.params.interpolate));
|
|
160
160
|
if (t.params.missingValues === "gap") {
|
|
161
|
-
const a = (d) =>
|
|
161
|
+
const a = (d) => _(d) !== null && w(d) !== null;
|
|
162
162
|
r.defined(a), i.defined(a);
|
|
163
163
|
}
|
|
164
|
-
t.data.groupBy(
|
|
164
|
+
t.data.groupBy(_e.group).forEach((a) => {
|
|
165
165
|
const d = Kt([...a], t.params.missingValues), l = d[0];
|
|
166
166
|
if (!l) return;
|
|
167
167
|
const c = s.get("strokeWidth", l), f = ve(s.get("lineType", l)), u = s.get("color", l), h = s.get("fillAlpha", l);
|
|
@@ -174,7 +174,7 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
174
174
|
draw: (e, { layer: t, panel: o, colorScheme: n }) => {
|
|
175
175
|
const s = D({ colorScheme: n }).geomReaders(t);
|
|
176
176
|
for (const r of t.data) {
|
|
177
|
-
const i =
|
|
177
|
+
const i = _(r), a = w(r);
|
|
178
178
|
if (i === null || a === null) continue;
|
|
179
179
|
const d = B(o, i), l = I(o, a), c = s.get("size", r) / 2, f = s.get("borderWidth", r);
|
|
180
180
|
e.save(), e.globalAlpha = s.get("alpha", r), e.fillStyle = s.get("color", r), e.strokeStyle = s.get("borderColor", r), e.lineWidth = f, e.beginPath(), e.arc(d, l, c, 0, Math.PI * 2), e.fill(), f > 0 && e.stroke(), e.restore();
|
|
@@ -203,7 +203,7 @@ const Be = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ne =
|
|
|
203
203
|
draw: (e, { layer: t, coordSystem: o, panel: n, compiled: s, textMeasurer: r, formattingLocale: i, colorScheme: a }) => {
|
|
204
204
|
const d = t.data.getFirst();
|
|
205
205
|
if (!d) return;
|
|
206
|
-
const l = jt(t, o), c = l ?
|
|
206
|
+
const l = jt(t, o), c = l ? w(d) : _(d);
|
|
207
207
|
if (c === null) return;
|
|
208
208
|
const f = D({ colorScheme: a }).geomReaders(t), u = f.get("color", d), h = At(u), g = f.get("strokeWidth", d);
|
|
209
209
|
if (e.save(), e.strokeStyle = u, e.lineWidth = g, Qt(e, f.get("lineType", d), g), e.beginPath(), l) {
|
|
@@ -354,7 +354,7 @@ const Oe = () => (Ae ??= Lt(), Ae), He = [
|
|
|
354
354
|
const s = n instanceof Error ? n.message : String(n);
|
|
355
355
|
return C(`Chart config failed to compile: ${s}`);
|
|
356
356
|
}
|
|
357
|
-
}, z = 6, q = 10, uo = 20, le = T, de = 12, Me = T, G = 12, ce = 1.3, U = 10, W = 12, k = 6, Ge = 16, ho = 24, Ue = 6, We = 3, se = 4, go = 8, mo = "#9ca3af", Ve = 16, Ao = 1.3, Ke = 13, bo = 1.4, Xe = 12, po = 1.4, Q = 8, fe = 12, yo = 1.3, To = 200, Eo = 120, So = 80, ze = 22, Lo = 9, Ro = 11,
|
|
357
|
+
}, z = 6, q = 10, uo = 20, le = T, de = 12, Me = T, G = 12, ce = 1.3, U = 10, W = 12, k = 6, Ge = 16, ho = 24, Ue = 6, We = 3, se = 4, go = 8, mo = "#9ca3af", Ve = 16, Ao = 1.3, Ke = 13, bo = 1.4, Xe = 12, po = 1.4, Q = 8, fe = 12, yo = 1.3, To = 200, Eo = 120, So = 80, ze = 22, Lo = 9, Ro = 11, wo = 10, Y = 9, be = 12, _o = '-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif', Io = 11.5, Bo = 550, No = { light: 0.55, mid: 0.75, dark: 0.08 }, Co = { light: 0.62, mid: 0.8, dark: 0.85 }, vo = 0.22, Po = 0.65, ko = T, Do = 12, Fo = { family: le, size: de }, Oo = { family: ko, size: Do }, Ho = { family: Me, size: G }, Mo = 8, pe = 1, Go = [2, 3], Uo = [1, 3], Wo = (e, t, o, n, s) => {
|
|
358
358
|
if (!t.isVisible || t.ticks.length === 0) return;
|
|
359
359
|
const r = t.position === "bottom" || t.position === "top", i = t.ticksVisible ? 1 : 0;
|
|
360
360
|
e.save(), e.font = S(Fo), e.fillStyle = s.textSecondary, e.strokeStyle = s.gridLine, e.lineWidth = 1, e.setLineDash([]);
|
|
@@ -421,10 +421,10 @@ const jo = () => {
|
|
|
421
421
|
if (t.placement !== r) return;
|
|
422
422
|
const i = Ye(t.enabled, s, t.variant);
|
|
423
423
|
if (i === "hidden") return;
|
|
424
|
-
const a = Qo(n.background), d = a === "dark", l = { family:
|
|
424
|
+
const a = Qo(n.background), d = a === "dark", l = { family: _o, size: Io, weight: 400 }, c = { ...l, weight: Bo };
|
|
425
425
|
let f = 0;
|
|
426
426
|
i === "full" && (e.font = S(l), f = e.measureText("Made with ").width, e.font = S(c), f += e.measureText("Graphy").width);
|
|
427
|
-
const u = i === "mini" ? 0 : Lo, h = i === "mini" ? 0 : Ro, g = i === "mini" ? 0 :
|
|
427
|
+
const u = i === "mini" ? 0 : Lo, h = i === "mini" ? 0 : Ro, g = i === "mini" ? 0 : wo, A = i === "mini" ? N : u + Y + g + f + h, b = o.x + o.width - A, E = o.y + Math.max(0, (o.height || N) / 2 - N / 2);
|
|
428
428
|
e.save(), e.globalAlpha = Co[a], e.textBaseline = "middle", e.textAlign = "left", d || (e.shadowColor = "rgba(0, 0, 0, 0.09)", e.shadowBlur = 4, e.shadowOffsetY = 1), e.beginPath(), e.roundRect(b, E, A, N, N / 2), e.fillStyle = `rgba(255, 255, 255, ${No[a]})`, e.fill(), e.shadowColor = "transparent", e.shadowBlur = 0, e.shadowOffsetY = 0;
|
|
429
429
|
const p = d ? "#FFFFFF" : "#2A2A28", R = i === "mini" ? b + (A - Y) / 2 : b + u, y = E + (N - be) / 2;
|
|
430
430
|
if (e.save(), d && (e.filter = "invert(1)"), e.drawImage(jo(), R, y, Y, be), e.restore(), i === "full") {
|
|
@@ -501,7 +501,7 @@ const jo = () => {
|
|
|
501
501
|
);
|
|
502
502
|
}, ye = (e, t, o, n, s, r) => (e.font = S(o), e.fillStyle = n, e.fillText(t, s, r), s + e.measureText(t).width), dn = (e, t, o, n, s) => {
|
|
503
503
|
e.save(), e.lineCap = "round", e.strokeStyle = s.gridLine;
|
|
504
|
-
for (const r of
|
|
504
|
+
for (const r of wt(o.border, n, Mo))
|
|
505
505
|
e.lineWidth = r.lineWidth ?? pe, e.setLineDash(Te(r.lineStyle)), cn(e, r.segments), e.stroke();
|
|
506
506
|
for (const r of t) {
|
|
507
507
|
if (!r.gridVisible) continue;
|
|
@@ -663,7 +663,7 @@ const jo = () => {
|
|
|
663
663
|
weight: s
|
|
664
664
|
});
|
|
665
665
|
}, Tn = (e) => (t, o) => {
|
|
666
|
-
const { fontSize: n, fontWeight: s } =
|
|
666
|
+
const { fontSize: n, fontWeight: s } = _t(t, 1);
|
|
667
667
|
return e.measureText(o, {
|
|
668
668
|
family: T,
|
|
669
669
|
size: n,
|
|
@@ -725,7 +725,7 @@ const Ln = {
|
|
|
725
725
|
if (Mt(), t.fonts)
|
|
726
726
|
for (const b of t.fonts) Ne(b);
|
|
727
727
|
const n = Bt({
|
|
728
|
-
legends: e.guides.legends,
|
|
728
|
+
legends: e.guides.legends.drawn,
|
|
729
729
|
numberFormat: e.config.numberFormat,
|
|
730
730
|
parsingLocale: e.config.parsingLocale,
|
|
731
731
|
formattingLocale: t.formattingLocale
|
|
@@ -744,7 +744,7 @@ const Ln = {
|
|
|
744
744
|
}), f = t.pixelRatio ?? 2, u = new o(t.width * f, t.height * f), h = u.getContext("2d");
|
|
745
745
|
h.scale(f, f);
|
|
746
746
|
const g = t.colorScheme ?? "light";
|
|
747
|
-
return
|
|
747
|
+
return wn(
|
|
748
748
|
h,
|
|
749
749
|
g === "dark" ? Rn : Ln,
|
|
750
750
|
g,
|
|
@@ -757,7 +757,7 @@ const Ln = {
|
|
|
757
757
|
d,
|
|
758
758
|
t.formattingLocale
|
|
759
759
|
), u.encode("png");
|
|
760
|
-
},
|
|
760
|
+
}, wn = (e, t, o, n, s, r, i, a, d, l, c) => {
|
|
761
761
|
e.fillStyle = t.background, e.fillRect(0, 0, n, s), dn(e, i, r.guides.panel, d.panel, t), e.save(), e.beginPath(), e.rect(d.panel.x, d.panel.y, d.panel.width, d.panel.height), e.clip();
|
|
762
762
|
const f = {
|
|
763
763
|
coordSystem: r.coordSystem,
|
|
@@ -783,7 +783,7 @@ const Ln = {
|
|
|
783
783
|
}
|
|
784
784
|
fn(e, a, d.legends, t), an(e, r.config.content, d.header, t, { width: n, height: s }), ln(e, r.config.content, d.footer, t, { width: n, height: s });
|
|
785
785
|
};
|
|
786
|
-
class
|
|
786
|
+
class _n extends Error {
|
|
787
787
|
constructor(t) {
|
|
788
788
|
super(t), this.name = "ChartConfigRenderError";
|
|
789
789
|
}
|
|
@@ -791,14 +791,14 @@ class wn extends Error {
|
|
|
791
791
|
const Hn = async (e, t) => {
|
|
792
792
|
const o = fo(e);
|
|
793
793
|
if (!o.ok)
|
|
794
|
-
throw new
|
|
794
|
+
throw new _n(o.reason);
|
|
795
795
|
return et(o.compiled, t);
|
|
796
796
|
};
|
|
797
797
|
export {
|
|
798
798
|
Fn as CANVAS_CAPABILITY_MATRIX,
|
|
799
799
|
He as CANVAS_SUPPORTED_GRAPH_TYPES,
|
|
800
800
|
so as CANVAS_UNSUPPORTED_GRAPH_TYPES,
|
|
801
|
-
|
|
801
|
+
_n as ChartConfigRenderError,
|
|
802
802
|
Sn as NodeCanvasTextMeasurer,
|
|
803
803
|
fo as canRenderConfigWithCanvas,
|
|
804
804
|
Rn as darkTheme,
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"headless",
|
|
13
13
|
"renderer"
|
|
14
14
|
],
|
|
15
|
-
"version": "1.8.1-beta.
|
|
15
|
+
"version": "1.8.1-beta.1786354953172",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"sideEffects": [
|
|
18
18
|
"**/version.ts"
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@fontsource/inter": "5.2.8",
|
|
40
40
|
"@napi-rs/canvas": "^0.1.76",
|
|
41
41
|
"d3-shape": "^3.2.0",
|
|
42
|
-
"@graphysdk/viz-engine": "1.8.1-beta.
|
|
42
|
+
"@graphysdk/viz-engine": "1.8.1-beta.1786354953172"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@rollup/plugin-replace": "^6.0.3",
|