@graphysdk/node-renderer 2.0.0-beta.1787253424098 → 2.0.0-beta.1787305269287
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 +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var et=Object.create;var le=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var st=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ot(t))!rt.call(e,r)&&r!==o&&le(e,r,{get:()=>t[r],enumerable:!(n=tt(t,r))||n.enumerable});return e};var it=(e,t,o)=>(o=e!=null?et(nt(e)):{},st(t||!e||!e.__esModule?le(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("node:fs"),ye=require("node:module"),O=require("node:path"),at=require("node:url"),lt=require("@graphysdk/viz-engine/graph-config"),I=require("d3-shape"),d=require("@graphysdk/viz-engine"),ct=require("node:buffer");var _=typeof document<"u"?document.currentScript:null;let H,Q;const Se=()=>H?Promise.resolve(H):(Q??=import("@napi-rs/canvas").then(e=>(H=e,e)).catch(e=>{throw Q=void 0,e}),Q),V=()=>{if(!H)throw new Error("Canvas runtime is not loaded. Call loadCanvasRuntime() before rendering.");return H},E="Inter",J=new Set;let de=!1,z=!1;const Te=e=>`${e.family}|${e.weight??400}|${e.style??"normal"}`,ne=e=>{const t=Te(e);J.has(t)||(V().GlobalFonts.register(e.data,e.family),J.add(t))},dt=[{file:"Inter-Regular.ttf",family:E,weight:400},{file:"Inter-SemiBold.ttf",family:E,weight:600}],ut=[{file:"inter-latin-400-normal.woff",family:E,weight:400},{file:"inter-latin-600-normal.woff",family:E,weight:600}],ft="@fontsource/inter",ht=()=>{try{const e=ye.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href),t=O.dirname(e.resolve("@graphysdk/node-renderer/package.json"));return O.join(t,"assets")}catch{return O.resolve(O.dirname(at.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href)),"../assets")}},Re=(e,t,o)=>{try{return ce.existsSync(e)?(ne({family:t,data:ce.readFileSync(e),weight:o}),!0):!1}catch{return!1}},gt=()=>{const e=ht();for(const{file:t,family:o,weight:n}of dt)Re(O.join(e,t),o,n)&&(z=!0)},mt=()=>{const e=ye.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href);for(const{file:t,family:o,weight:n}of ut)if(!J.has(Te({family:o,data:Buffer.alloc(0),weight:n})))try{const r=e.resolve(`${ft}/files/${t}`);Re(r,o,n)&&(z=!0)}catch{}},Ee=()=>(de||(de=!0,gt(),mt()),z),C=(e,t)=>e.x+t*e.width,v=(e,t)=>e.y+(1-t)*e.height,$=e=>e==="catmull-rom"?I.curveCatmullRom:I.curveLinear,Le=e=>{switch(e){case"dashed":return[8,4];case"dotted":return[2,2];case"solid":return[]}},D=e=>e,At=(e,t)=>t!=="connect"?e:e.filter(o=>d.getX(o)!==null&&d.getY(o)!==null),bt=(e,t,o)=>{const n=$(t.interpolate),r=I.area().curve(n),s=I.line().curve(n);if(e.mainAxis==="y"){const i=a=>v(o,d.getY(a)??0),l=a=>C(o,d.getXMin(a)??0),c=a=>C(o,d.getXMax(a)??d.getX(a)??0);r.y(i).x0(l).x1(c),s.y(i).x(c)}else{const i=a=>C(o,d.getX(a)??0),l=a=>v(o,d.getYMin(a)??0),c=a=>v(o,d.getYMax(a)??d.getY(a)??0);r.x(i).y0(l).y1(c),s.x(i).y(c)}if(t.missingValues==="gap"){const i=l=>d.getX(l)!==null&&d.getY(l)!==null;r.defined(i),s.defined(i)}return{areaGenerator:r,lineGenerator:s}},pt=D({geom:"area",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const s=d.createStyleResolver({colorScheme:r}).geomReaders(t),{areaGenerator:i,lineGenerator:l}=bt(o,t.params,n),c=e;t.data.groupBy(d.GROUP_VARIABLES.group).forEach(a=>{const u=At([...a],t.params.missingValues),h=u[0];if(!h)return;const f=s.get("color",h),g=s.get("alpha",h),m=s.get("strokeWidth",h),p=Le(s.get("lineType",h));e.save(),e.globalAlpha=g,e.fillStyle=f,e.beginPath(),i.context(c)(u),e.fill(),e.restore(),e.save(),e.globalAlpha=s.get("strokeAlpha",h),e.strokeStyle=f,e.lineWidth=m,e.setLineDash(p),e.lineJoin="round",e.lineCap="round",e.beginPath(),l.context(c)(u),e.stroke(),e.restore()})}}),ue=(e,t,o,n,r,s)=>{const i=Math.max(0,Math.min(s.rx??s.ry??0,n/2)),l=Math.max(0,Math.min(s.ry??s.rx??0,r/2)),c=Math.PI/2;e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.ellipse(t+n-i,o+l,i,l,0,-c,0),e.lineTo(t+n,o+r-l),e.ellipse(t+n-i,o+r-l,i,l,0,0,c),e.lineTo(t+i,o+r),e.ellipse(t+i,o+r-l,i,l,0,c,Math.PI),e.lineTo(t,o+l),e.ellipse(t+i,o+l,i,l,0,Math.PI,Math.PI*1.5),e.closePath()},yt=D({geom:"bar",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const{Path2D:s}=V(),i=d.createStyleResolver({colorScheme:r}).geomReaders(t),l=o.mainAxis,c=new Map;for(const a of t.data){const u=d.getBarRectBounds(l,a);if(!u)continue;const h=C(n,u.x),f=n.y+u.y*n.height,g={x:h,y:f,width:u.width*n.width,height:u.height*n.height,fill:i.get("color",a),opacity:i.get("alpha",a)},m=d.buildColumnKey(l,u),p=c.get(m);p?p.bars.push(g):c.set(m,{bars:[g],style:{borderColor:i.get("borderColor",a),borderWidth:i.get("borderWidth",a),borderRadius:i.get("borderRadius",a),borderAlpha:i.get("alpha",a)}})}for(const{bars:a,style:u}of c.values()){const{borderColor:h,borderRadius:f,borderWidth:g,borderAlpha:m}=u,p=d.resolveBarBorderTreatment(g),b=f==="full"?void 0:d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l});if(!(a.length>1)){const[A]=a;if(!A)continue;const w=b??d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l,bounds:{width:A.width,height:A.height}}),L=new s;ue(L,A.x,A.y,A.width,A.height,w),e.save(),e.globalAlpha=A.opacity,e.fillStyle=A.fill,e.fill(L),h!==void 0&&(e.clip(L),e.strokeStyle=h,e.lineWidth=p.outlineWidth,e.stroke(L)),e.restore();continue}const S=d.getBoundingRect(a),R=b??d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l,bounds:{width:S.width,height:S.height}}),T=new s;ue(T,S.x,S.y,S.width,S.height,R),e.save(),e.clip(T);for(const A of a)e.globalAlpha=A.opacity,e.fillStyle=A.fill,e.fillRect(A.x,A.y,A.width,A.height),h!==void 0&&(e.strokeStyle=h,e.lineWidth=p.separatorWidth,e.strokeRect(A.x,A.y,A.width,A.height));h!==void 0&&(e.globalAlpha=m,e.strokeStyle=h,e.lineWidth=p.outlineWidth,e.stroke(T)),e.restore()}}}),fe=(e,t)=>{const o=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(o?.[1]!==void 0){const r=o[1],s=r.length===3?[...r].map(a=>a+a).join(""):r.slice(0,6),i=Number.parseInt(s.slice(0,2),16),l=Number.parseInt(s.slice(2,4),16),c=Number.parseInt(s.slice(4,6),16);return`rgba(${i}, ${l}, ${c}, ${t})`}const n=/^rgba?\(([^)]+)\)$/i.exec(e.trim());if(n?.[1]!==void 0){const r=n[1].split(",").map(c=>c.trim()),[s,i,l]=r;if(s!==void 0&&i!==void 0&&l!==void 0)return`rgba(${s}, ${i}, ${l}, ${t})`}return t===0?"rgba(0, 0, 0, 0)":e},St=(e,t)=>t!=="connect"?e:e.filter(o=>d.getX(o)!==null&&d.getY(o)!==null),Tt=(e,t)=>{const{seriesObservations:o,fillGenerator:n,panel:r,color:s,fillAlpha:i}=t,l=o.map(a=>d.getY(a)).filter(a=>a!==null).map(a=>v(r,a));if(l.length===0)return;const c=e.createLinearGradient(0,Math.min(...l),0,r.y+r.height);c.addColorStop(0,s),c.addColorStop(.7,fe(s,0)),c.addColorStop(1,fe(s,0)),e.save(),e.globalAlpha=i,e.fillStyle=c,e.beginPath(),n.context(e)(o),e.fill(),e.restore()},Rt=D({geom:"line",coord:"cartesian",draw:(e,{layer:t,panel:o,colorScheme:n})=>{const r=d.createStyleResolver({colorScheme:n}).geomReaders(t),s=I.line().x(l=>C(o,d.getX(l)??0)).y(l=>v(o,d.getY(l)??0)).curve($(t.params.interpolate)),i=I.area().x(l=>C(o,d.getX(l)??0)).y0(o.y+o.height).y1(l=>v(o,d.getY(l)??0)).curve($(t.params.interpolate));if(t.params.missingValues==="gap"){const l=c=>d.getX(c)!==null&&d.getY(c)!==null;s.defined(l),i.defined(l)}t.data.groupBy(d.GROUP_VARIABLES.group).forEach(l=>{const c=St([...l],t.params.missingValues),a=c[0];if(!a)return;const u=r.get("strokeWidth",a),h=Le(r.get("lineType",a)),f=r.get("color",a),g=r.get("fillAlpha",a);g!==void 0&&Tt(e,{seriesObservations:c,fillGenerator:i,panel:o,color:f,fillAlpha:g}),e.save(),e.globalAlpha=r.get("alpha",a),e.strokeStyle=f,e.lineWidth=u,e.setLineDash(h),e.lineJoin="round",e.lineCap="round",e.beginPath(),s.context(e)(c),e.stroke(),e.restore()})}}),Et=D({geom:"point",coord:"cartesian",draw:(e,{layer:t,panel:o,colorScheme:n})=>{const r=d.createStyleResolver({colorScheme:n}).geomReaders(t);for(const s of t.data){const i=d.getX(s),l=d.getY(s);if(i===null||l===null)continue;const c=C(o,i),a=v(o,l),u=r.get("size",s)/2,h=r.get("borderWidth",s);e.save(),e.globalAlpha=r.get("alpha",s),e.fillStyle=r.get("color",s),e.strokeStyle=r.get("borderColor",s),e.lineWidth=h,e.beginPath(),e.arc(c,a,u,0,Math.PI*2),e.fill(),h>0&&e.stroke(),e.restore()}}}),re=11,Lt="sans-serif",wt=500,k=5,we=5,x=13,ve=6,K=12,he=21.6,vt=(e,t)=>{const o=e.mapping.y!==void 0,n=t.mainAxis==="y";return o!==n},_t=(e,t,o)=>{const n=d.getRuleDashPattern(t,o);e.setLineDash(n),n.length>0&&(e.lineCap="round")},Ct=(e,t)=>X(e)&&X(t)?`${e}: ${t}`:X(e)?e:X(t)?t:null,X=e=>e!=null&&e.trim()!=="",Bt=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()},_e=(e,t,o,n,r,s)=>{const i=Math.min(s,n/2,r/2);e.beginPath(),e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.arcTo(t+n,o,t+n,o+i,i),e.lineTo(t+n,o+r-i),e.arcTo(t+n,o+r,t+n-i,o+r,i),e.lineTo(t+i,o+r),e.arcTo(t,o+r,t,o+r-i,i),e.lineTo(t,o+i),e.arcTo(t,o,t+i,o,i),e.closePath(),e.fill()},Pt=(e,t,o,n,r,s,i,l)=>{const c=o+k*2,a=re+we*2,u=n==="start",h=u?s.x:s.x+s.width,f=v(s,r),g=u?-x:-(c-x),m=u?g+c-k:g+k-K;e.save(),e.translate(h,f),e.translate(0,-a/2),e.fillStyle=i,_e(e,g,0,c,a,ve),e.save(),u||(e.translate(m+K/2,a/2),e.rotate(Math.PI),e.translate(-(m+K/2),-a/2)),e.translate(m,(a-he)/2),e.scale(K/10,he/18),e.fillStyle=i,Bt(e),e.fill(),e.restore(),e.fillStyle=l,e.textAlign="left",e.textBaseline="middle",e.fillText(t,g+k,a/2),e.restore()},It=(e,t,o,n,r,s,i,l)=>{const c=o+k*2,a=re+we*2,u=n==="start",h=C(s,r),f=u?s.y+s.height:s.y,g=u?-x:-8;e.save(),e.translate(h,f),e.translate(-c/2,0),e.fillStyle=i,_e(e,0,g,c,a,ve),e.fillStyle=l,e.textAlign="left",e.textBaseline="middle",e.fillText(t,k,g+a/2),e.restore()},Nt=D({geom:"rule",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,compiled:r,textMeasurer:s,formattingLocale:i,colorScheme:l})=>{const c=t.data.getFirst();if(!c)return;const a=vt(t,o),u=a?d.getY(c):d.getX(c);if(u===null)return;const h=d.createStyleResolver({colorScheme:l}).geomReaders(t),f=h.get("color",c),g=d.getRuleLabelTextColor(f),m=h.get("strokeWidth",c);if(e.save(),e.strokeStyle=f,e.lineWidth=m,_t(e,h.get("lineType",c),m),e.beginPath(),a){const T=v(n,u);e.moveTo(n.x,T),e.lineTo(n.x+n.width,T)}else{const T=C(n,u);e.moveTo(T,n.y),e.lineTo(T,n.y+n.height)}e.stroke(),e.restore();const p=Ct(t.params.label,d.formatRuleValue({guides:r.guides,numberFormat:r.config.numberFormat,layer:t,locale:i??r.config.parsingLocale}));if(p===null)return;const b=r.config.appearance.textScale,y={family:Lt,size:re*b,weight:wt};e.font=d.buildFontString(y);const S=s.measureText(p,y).width;(a?Pt:It)(e,p,S,t.params.labelPosition,u,n,f,g)}}),U=I.arc();U.digits(8);const kt=D({geom:"bar",coord:"polar",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const s=n.x+n.width/2,i=n.y+n.height/2,l=Math.min(n.width,n.height)/2,{Path2D:c}=V(),a=d.createStyleResolver({colorScheme:r}).geomReaders(t);e.save(),e.translate(s,i),e.scale(l,l);const u=e,h=new Map;for(const f of t.data){const{startAngle:g,endAngle:m}=d.getAngleExtent(f),{innerRadius:p,outerRadius:b}=d.getRadiusExtent(f);if(g===null||m===null||p===null||b===null)continue;const y={startAngle:g,endAngle:m,innerRadius:p,outerRadius:b,fill:a.get("color",f),opacity:a.get("alpha",f)},S=d.buildSliceGroupKey(o.bandAxis,y),R=h.get(S);R?R.items.push(y):h.set(S,{items:[y],style:{borderColor:a.get("borderColor",f),borderWidth:a.get("borderWidth",f),borderRadius:a.get("borderRadius",f),borderAlpha:a.get("alpha",f)}})}for(const{items:f,style:g}of h.values()){const{borderColor:m,borderRadius:p,borderWidth:b,borderAlpha:y}=g,S=d.resolveBarBorderTreatment(b),R=m!==void 0&&l>0,T=d.getUnionExtent(f),A=d.resolvePolarBarCornerRadiusUnit(p,T.outerRadius-T.innerRadius),w=l>0&&(R||A>0);e.save();let L;w&&(L=new c,U.cornerRadius(A),U.context(L)(T),e.clip(L)),U.cornerRadius(0);for(const N of f)e.globalAlpha=N.opacity,e.fillStyle=N.fill,e.beginPath(),U.context(u)(N),e.fill(),R&&(e.strokeStyle=m,e.lineWidth=S.separatorWidth/l,e.stroke());R&&L&&(e.globalAlpha=y,e.strokeStyle=m,e.lineWidth=S.outlineWidth/l,e.stroke(L)),e.restore()}e.restore()}}),Ft={bar:{cartesian:yt,polar:kt},line:{cartesian:Rt},area:{cartesian:pt},point:{cartesian:Et},rule:{cartesian:Nt}},Ce=(e,t)=>Ft[e.geom]?.[t.type]??null,Dt=(e,t,o)=>{e.draw(t,o)};let ge;const Be=()=>(ge??=d.createCompiler(),ge),se=["line","areaStacked","bar","barStacked","barStackedFill","column","columnStacked","columnStackedFill","combo","pie","donut","scatter","bubble"],Pe=["funnel","heatmap","waterfall","mekko","table"],Ot=new Set(se),Ut={supportedGraphTypes:[...se],unsupportedGraphTypes:[...Pe],supportedGeoms:{cartesian:["bar","line","area","point","rule"],polar:["bar"]}},P=e=>({ok:!1,reason:e}),q=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ht=e=>{if(!q(e))return!1;const{columns:t,rows:o}=e;return!Array.isArray(t)||!Array.isArray(o)?!1:t.every(n=>q(n)&&typeof n.key=="string")},Mt=e=>{if("_unstable_mapping"in e&&e._unstable_mapping!==void 0)return!0;const t=e.referenceLines;return q(t)?t.trendline!==void 0||t.averageLine!==void 0:!1},Ie=e=>{if(!q(e))return P("Chart config must be a plain object.");if(!Ht(e.data))return P("Chart config is missing a valid `data` object (columns + rows).");const{data:t,...o}=e;return{ok:!0,input:o,data:t}},Ne=e=>{const t=Ie(e);if(!t.ok)return t;if(Mt(e))return P("Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`.");const o=t.input.type??"column";if(!Ot.has(o))return P(`Unsupported chart type for canvas rendering: ${o}.`);try{const n=Be(),r=lt.convertGraphConfig(t.input,t.data),s=n.compile({input:r,data:t.data});if(!s.ok)return P(`Chart config failed to compile: ${s.errors.map(i=>i.message).join("; ")}`);for(const i of s.compiled.layers)if(Ce(i,s.compiled.coordSystem)===null)return P(`No canvas geom renderer for ${i.geom} (${s.compiled.coordSystem.type} coord).`);return{ok:!0,compiled:s.compiled}}catch(n){const r=n instanceof Error?n.message:String(n);return P(`Chart config failed to compile: ${r}`)}},ke=E,M=12,ie=1.3,G=10,W=12,F=6,Fe=16,Gt=24,De=6,Oe=3,ee=4,Wt=8,Vt="#9ca3af",Ue=16,Kt=1.3,He=13,Xt=1.4,Me=12,Yt=1.4,j=8,ae=12,zt=1.3,qt=200,jt=120,Qt=80,Ge=22,Zt=9,Jt=11,$t=10,Y=9,me=12,xt='-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',eo=11.5,to=550,oo={light:.55,mid:.75,dark:.08},no={light:.62,mid:.8,dark:.85},ro=.22,so=.65,io={family:ke,size:M},ao=[2,3],lo=[1,3],te=e=>{switch(e){case"dashed":return ao;case"dotted":return lo;case"solid":return[]}},co=(e,t,o,n,r,s)=>{if(!t.isVisible||t.ticks.length===0)return;const i=t.position==="bottom"||t.position==="top";e.save(),e.font=d.buildFontString(d.toFontSpec(r,E)),e.fillStyle=r.textColor,e.strokeStyle=s.color,e.lineWidth=s.strokeWidth,e.setLineDash(te(s.lineType));for(const l of t.ticks){const c=i?l.position:1-l.position;t.ticksVisible&&fo(e,t.position,c,o,n,s.length),go(e,t.position,c,o,n,l.formattedLabel,t.labelRotation,r.offset)}e.restore()},uo=(e,t,o,n,r)=>{if(e==="bottom"||e==="top"){const c=n.x+t*n.width,a=e==="top"?o.y+o.height:o.y,u=e==="top"?-r:r;return{x1:c,y1:a,x2:c,y2:a+u}}const s=n.y+t*n.height,i=e==="right"?o.x:o.x+o.width,l=e==="right"?r:-r;return{x1:i,y1:s,x2:i+l,y2:s}},fo=(e,t,o,n,r,s)=>{const{x1:i,y1:l,x2:c,y2:a}=uo(t,o,n,r,s);e.beginPath(),e.moveTo(i,l),e.lineTo(c,a),e.stroke()},ho=(e,t,o,n,r)=>{if(e==="bottom"||e==="top"){const i=n.x+t*n.width;return e==="bottom"?{x:i,y:o.y+r,textAlign:"center",textBaseline:"top"}:{x:i,y:o.y+o.height-r,textAlign:"center",textBaseline:"alphabetic"}}const s=n.y+t*n.height;return e==="left"?{x:o.x+o.width-r,y:s,textAlign:"right",textBaseline:"middle"}:{x:o.x+r,y:s,textAlign:"left",textBaseline:"middle"}},go=(e,t,o,n,r,s,i,l)=>{if(i!==0&&(t==="top"||t==="bottom")){const a=r.x+o*r.width,u=t==="top";e.save(),e.translate(a,u?n.y+n.height-l:n.y+l),e.rotate(i*Math.PI/180),e.textAlign=u?"left":"right",e.textBaseline="middle",e.fillText(s,0,0),e.restore();return}const c=ho(t,o,n,r,l);e.textAlign=c.textAlign,e.textBaseline=c.textBaseline,e.fillText(s,c.x,c.y)},mo=(e,t,o,n)=>{if(!t.isVisible||!t.label)return;e.save(),e.font=d.buildFontString({family:n.fontFamily??E,size:n.fontSize,weight:n.fontWeight}),e.fillStyle=n.textColor,e.textBaseline="middle";const{x:r,y:s,alignment:i}=Ao(t.position,o);e.textAlign=i,e.fillText(t.label,r,s),e.restore()},Ao=(e,t)=>{const o=t.y+t.height/2;return e==="left"?{x:t.x,y:o,alignment:"start"}:e==="right"?{x:t.x+t.width,y:o,alignment:"end"}:{x:t.x+t.width/2,y:o,alignment:"center"}},bo="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+RKo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v5ZPUTRlqz0q0VxQ4dMgQ5SXSRC1IwPLfVdLdX1mF4Lkr5Ybfii8rLixlLcvlgg2o2JaFCLXevpejXEnm3fLOcR/rTNUizYsU2OCxiP9+EhOUByIcqRxUYtSi595o2/7a00nqwblHiW4t25Jh4mZM5wcpjhxZkUg4qd2/tUKzA/LhyEm1fJvM3v5ynklIVE8gjYgkrdhp67EaZfjTj4XEce8eJFDtUxNFLnrcStNsFBdpNhpRYq2OkOOw8RdtCE7y+3psNSVwUp9ih+2gduU1L2Fmfh/t2jIUUNrJJkbBhxQIU5+Dy3SdSVEpx949JcNpV1NraW7wKxxhWj2ezIi+7VxJrq1o2DivhNr0OS9qUBFCkvN4XgDO6lazdphrvVJUFD5j1jmV5+QdMOFExzD3jGdKOGLcud1Gv0P/rGVyH29B6MiWcmBbARiVAHBNg9srvsqQdV3cDIXuz9ut88Tpp4cSi5I77RSWLGdKOGxUoBXq0Z8cW2C7D8X+n0XFXUtz9nJRhz1lt3xJkFxdvUMV7b7/K5tuAdEStpWgr8MpeVbNGVoHPwG20n6lBs21DhiGVLK9agOrZrwtxq7ePGm48X5PfgeuJWdvN381CG7+pIlBbfryEXCJpxlqRtBG10oHa6NXVx/8Ba+cluUx5B18AAAAASUVORK5CYII=",B=Ge;let Z;const po=()=>{if(Z)return Z;const{Image:e}=V(),t=new e,o=bo.replace(/^data:image\/png;base64,/,"");return t.src=ct.Buffer.from(o,"base64"),Z=t,t},We=(e,t,o="full")=>!e||t.width<jt||t.height<Qt?"hidden":t.width<qt||o==="mini"?"mini":"full",yo=e=>{const t=So(e);if(t===null)return"light";const o=To(t);return o<=ro?"dark":o<=so?"mid":"light"},oe=(e,t,o)=>e.placement!==o||We(e.enabled,t,e.variant)==="hidden"?0:Ge,Ve=(e,t,o,n,r,s)=>{if(t.placement!==s)return;const i=We(t.enabled,r,t.variant);if(i==="hidden")return;const l=yo(n.background),c=l==="dark",a={family:xt,size:eo,weight:400},u={...a,weight:to};let h=0;i==="full"&&(e.font=d.buildFontString(a),h=e.measureText("Made with ").width,e.font=d.buildFontString(u),h+=e.measureText("Graphy").width);const f=i==="mini"?0:Zt,g=i==="mini"?0:Jt,m=i==="mini"?0:$t,p=i==="mini"?B:f+Y+m+h+g,b=o.x+o.width-p,y=o.y+Math.max(0,(o.height||B)/2-B/2);e.save(),e.globalAlpha=no[l],e.textBaseline="middle",e.textAlign="left",c||(e.shadowColor="rgba(0, 0, 0, 0.09)",e.shadowBlur=4,e.shadowOffsetY=1),e.beginPath(),e.roundRect(b,y,p,B,B/2),e.fillStyle=`rgba(255, 255, 255, ${oo[l]})`,e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0;const S=c?"#FFFFFF":"#2A2A28",R=i==="mini"?b+(p-Y)/2:b+f,T=y+(B-me)/2;if(e.save(),c&&(e.filter="invert(1)"),e.drawImage(po(),R,T,Y,me),e.restore(),i==="full"){const A=b+f+Y+m,w=y+B/2;e.fillStyle=S,e.font=d.buildFontString(a),e.fillText("Made with ",A,w);const L=e.measureText("Made with ").width;e.font=d.buildFontString(u),e.fillText("Graphy",A+L,w)}e.restore()},So=e=>{const t=e.trim();if(!t.startsWith("#"))return null;const o=t.slice(1);if(o.length===3){const n=o[0],r=o[1],s=o[2];return n===void 0||r===void 0||s===void 0?null:{red:Number.parseInt(n+n,16),green:Number.parseInt(r+r,16),blue:Number.parseInt(s+s,16)}}return o.length>=6?{red:Number.parseInt(o.slice(0,2),16),green:Number.parseInt(o.slice(2,4),16),blue:Number.parseInt(o.slice(4,6),16)}:null},To=({red:e,green:t,blue:o})=>{const n=r=>{const s=r/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4};return .2126*n(e)+.7152*n(t)+.0722*n(o)},Ro={family:E,size:Ue,weight:600},Eo={family:E,size:He},Lo={family:E,size:Me},wo={family:E,size:ae,weight:500},vo={family:E,size:ae},Ke=Ue*Kt,_o=He*Xt,Xe=Me*Yt,Ye=ae*zt,ze=e=>{if(e===null)return null;if(e.label!==void 0&&e.label!=="")return e.label;if(e.url!==void 0&&e.url!==""&&d.isSafeUrl(e.url))try{return new URL(e.url).hostname}catch{return e.url}return null},Co=(e,t)=>{let o=0;const n=e.isTitleVisible&&e.title!==null,r=e.isSubtitleVisible&&e.subtitle!==null;n&&(o+=Ke),r&&(o>0&&(o+=j),o+=_o);const s=oe(e.brandMark,t,"header");!n&&!r&&s>0&&(o=s);const i=e.isCaptionVisible&&e.caption!==null,l=e.isSourceVisible&&ze(e.source)!==null,c=oe(e.brandMark,t,"footer");let a=0;return i&&(a+=Xe),(l||c>0)&&(a>0&&(a+=j),a+=Math.max(Ye,c)),{headerHeight:o,footerHeight:a}},Bo=(e,t,o,n,r)=>{if(o.height===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let s=o.y;t.isTitleVisible&&t.title!==null&&(e.font=d.buildFontString(Ro),e.fillStyle=n.textPrimary,e.fillText(d.extractPlainText(t.title),o.x,s),s+=Ke+j),t.isSubtitleVisible&&t.subtitle!==null&&(e.font=d.buildFontString(Eo),e.fillStyle=n.textSecondary,e.fillText(d.extractPlainText(t.subtitle),o.x,s)),e.restore(),Ve(e,t.brandMark,o,n,r,"header")},Po=(e,t,o,n,r)=>{if(o.height===0)return;const s=t.isCaptionVisible?t.caption:null,i=t.isSourceVisible?ze(t.source):null,l=oe(t.brandMark,r,"footer");if(s===null&&i===null&&l===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let c=o.y;if(s!==null&&(e.font=d.buildFontString(Lo),e.fillStyle=n.textSecondary,e.fillText(d.extractPlainText(s),o.x,c),c+=Xe+j),i!==null){let a=o.x;a=Ae(e,"Source: ",wo,n.textSecondary,a,c),Ae(e,i,vo,n.textSecondary,a,c)}e.restore(),Ve(e,t.brandMark,{x:o.x,y:c,width:o.width,height:Math.max(Ye,l)},n,r,"footer")},Ae=(e,t,o,n,r,s)=>(e.font=d.buildFontString(o),e.fillStyle=n,e.fillText(t,r,s),r+e.measureText(t).width),Io=(e,t,o,n)=>{e.save(),e.lineCap="round";for(const r of d.computePanelBorderPaths(d.resolvePanelBorderStyle(o),n))e.strokeStyle=r.color,e.lineWidth=r.strokeWidth,e.setLineDash(te(r.lineType)),No(e,r.segments),e.stroke();for(const r of t){if(!r.gridVisible)continue;const s=r.position==="top"||r.position==="bottom",i=d.resolveGridLineStyle(o,d.getAestheticFromScaleAestheticKey(r.scaleAestheticKey));e.strokeStyle=i.color,e.lineWidth=i.strokeWidth,e.setLineDash(te(i.lineType));for(const l of r.ticks){if(l.position<=0||l.position>=1)continue;const c=s?l.position:1-l.position;if(e.beginPath(),s){const a=n.x+c*n.width;e.moveTo(a,n.y),e.lineTo(a,n.y+n.height)}else{const a=n.y+c*n.height;e.moveTo(n.x,a),e.lineTo(n.x+n.width,a)}e.stroke()}}e.restore()},No=(e,t)=>{e.beginPath();for(const o of t)switch(o.type){case"move":e.moveTo(o.x,o.y);break;case"line":e.lineTo(o.x,o.y);break;case"arc":e.arc(o.cx,o.cy,o.radius,o.startAngle,o.endAngle);break;case"close":e.closePath();break}},ko=(e,t,o,n)=>{e.save(),e.font=d.buildFontString(io),e.textBaseline="middle";for(const s of t)s.display==="direct"&&Fo(e,s,o,n);const r=new Map;for(const s of t){if(s.display!=="pill"||s.items.length===0)continue;const i=r.get(s.position);i?i.push(s):r.set(s.position,[s])}for(const[s,i]of r){const l=o[s];l&&(s==="top"||s==="bottom"?Do(e,i,l,n):Oo(e,i,l,n))}e.restore()},Fo=(e,t,o,n)=>{const r=o[t.position];if(r){e.textAlign="left";for(const s of t.items)s.normalizedY!==null&&(e.fillStyle=typeof s.visual.color=="string"?s.visual.color:n.textPrimary,e.fillText(s.formattedLabel,r.x+Wt,v(r,s.normalizedY)))}},Do=(e,t,o,n)=>{const r=qe(t),s=r.reduce((a,u,h)=>a+Ho(u)+e.measureText(u.label).width+(h===0?0:be(u)),0),i=M*ie;let l=o.x+Math.max(0,(o.width-s)/2);const c=o.y+De+Math.max(i,W)/2;for(let a=0;a<r.length;a++){const u=r[a];u&&(a>0&&(l+=be(u)),l=je(e,u,l,c,n))}},Oo=(e,t,o,n)=>{const r=qe(t),s=Math.max(M*ie,W),i=4,l=r.length*s+Math.max(0,r.length-1)*i;let c=o.y+Math.max(0,(o.height-l)/2)+s/2;for(const a of r)je(e,a,o.x,c,n),c+=s+i},qe=e=>{const t=[];for(const o of e){const n=o.aesthetics.includes("size");o.items.forEach((r,s)=>{const i=r.visual.size,l=n&&typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0;t.push({label:r.formattedLabel,colors:Uo(r.visual.color),bubbleSize:l,isFirstInGroup:s===0})})}return t},Uo=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="string"):[],be=e=>e.isFirstInGroup?Gt:Fe,Ho=e=>{if(e.bubbleSize!==void 0)return e.bubbleSize+F;const t=e.colors.length;if(t===0)return 0;if(t===1)return G+F;const o=Math.min(t,Oe);return G+(o-1)*ee+F},je=(e,t,o,n,r)=>{let s=o;if(t.bubbleSize!==void 0){const i=t.bubbleSize/2;e.fillStyle=t.colors[0]??Vt,e.beginPath(),e.arc(s+i,n,i,0,Math.PI*2),e.fill(),s+=t.bubbleSize+F}else if(t.colors.length>0){const i=t.colors.slice(0,Oe);for(let l=0;l<i.length;l++){const c=i[l];c&&(e.fillStyle=c,e.fillRect(s+l*ee,n-W/2,G,W))}s+=G+(i.length-1)*ee+F}return e.fillStyle=r.textPrimary,e.textAlign="left",e.fillText(t.label,s,n),s+e.measureText(t.label).width},pe=(e,t)=>Math.min(Math.max(...e),t),Mo=(e,t,o)=>n=>{if(!n.isVisible||n.ticks.length===0)return 0;const r=n.position==="top"||n.position==="bottom",s=d.getAestheticFromScaleAestheticKey(n.scaleAestheticKey),{offset:i,...l}=t[s],c=n.ticksVisible?Math.max(i,o[s].length):i,a=d.toFontSpec(l,E),u=n.ticks.map(g=>e.measureText(g.formattedLabel,a)),h=n.labelMaxWidthPx??Number.POSITIVE_INFINITY;if(r){if(n.labelRotation!==0){const g=u.map(m=>m.width);return pe(g,h)+2*c}return Math.max(...u.map(g=>g.height))+c}const f=u.map(g=>g.width);return pe(f,h)+c},Go=e=>t=>{if(t.items.length===0)return 0;const o={family:ke,size:M};if(t.position==="top"||t.position==="bottom"){const s=M*ie;return Math.max(s,W)+De*2}const r=t.items.map(s=>{const i=e.measureText(s.formattedLabel,o).width;return G+F+i});return Math.max(...r)+Fe},Wo=e=>(t,o)=>{const{labelLineHeight:n,labelFontWeight:r}=d.getDifferenceArrowDimensions(o,1);return e.measureText(t,{family:E,size:n,weight:r})},Vo=(e,t)=>(o,n,r)=>{const s=t[o][n],i=e.measureText(r,d.toFontSpec(s,E));return{...i,width:i.width+s.paddingInline*2,height:i.height+s.paddingBlock*2}},Ko=({textMeasurer:e,axisLabelStyles:t,dataLabelStyles:o,tickLabelStyles:n,tickLineStyles:r})=>({measureAxis:Mo(e,n,r),measureAxisLabel:s=>d.computeLineBoxHeight(t[d.getAestheticFromScaleAestheticKey(s.scaleAestheticKey)]),measureLegend:Go(e),measureTickLabel:(s,i)=>e.measureText(s,d.toFontSpec(n[i],E)),measureDifferenceArrowLabel:Wo(e),measureDataLabel:Vo(e,o),measureHeadline:()=>({width:0,height:0}),measureHeadlineItemWidths:()=>[]});class Qe{constructor(){this.currentFont="";const t=V().createCanvas(1,1);this.ctx=t.getContext("2d")}measureText(t,o){const n=d.buildFontString(o);this.currentFont!==n&&(this.ctx.font=n,this.currentFont=n);const r=this.ctx.measureText(t);return{width:r.width,height:r.fontBoundingBoxAscent+r.fontBoundingBoxDescent,ascent:r.fontBoundingBoxAscent,descent:r.fontBoundingBoxDescent}}}const Ze={background:"#ffffff",textPrimary:"#111827",textSecondary:"#6b7280",gridLine:"#e5e7eb",legendPillBackground:"rgba(0, 0, 0, 0.04)",legendPillBorder:"rgba(0, 0, 0, 0.08)"},Je={background:"#0b0f17",textPrimary:"#e5e7eb",textSecondary:"#9ca3af",gridLine:"#1f2937",legendPillBackground:"rgba(255, 255, 255, 0.06)",legendPillBorder:"rgba(255, 255, 255, 0.12)"},Xo=async({input:e,data:t},o)=>{const r=Be().compile({input:e,data:t});if(!r.ok)throw new Error(`Failed to compile graph spec: ${r.errors.map(s=>s.message).join("; ")}`);return $e(r.compiled,o)},$e=async(e,t)=>{const{Canvas:o}=await Se();if(Ee(),t.fonts)for(const w of t.fonts)ne(w);const n=d.formatLegends({legends:e.guides.legends.drawn,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattingLocale:t.formattingLocale}),r={width:t.width,height:t.height},{headerHeight:s,footerHeight:i}=Co(e.config.content,r),l={headerSize:{width:t.width,height:s},footerSize:{width:t.width,height:i}},c=t.colorScheme??"light",a=d.createStyleResolver({colorScheme:c}).chromeReaders(e.chrome),u=e.config.appearance.textScale,h={x:d.resolveAxisLabelStyle(a,"x",u),y:d.resolveAxisLabelStyle(a,"y",u)},f={x:d.resolveTickLabelStyle(a,"x",u),y:d.resolveTickLabelStyle(a,"y",u)},g={x:d.resolveTickLineStyle(a,"x"),y:d.resolveTickLineStyle(a,"y")},m={};for(const w of d.DATA_LABEL_ROLES){const L={};for(const N of d.DATA_LABEL_POSITIONS)L[N]=d.resolveDataLabelStyle(a,w,N,u);m[w]=L}const p=new Qe,b=Ko({textMeasurer:p,axisLabelStyles:h,dataLabelStyles:m,tickLabelStyles:f,tickLineStyles:g}),{layout:y,formattedAxes:S}=new d.LayoutCompiler(b).compile({axes:e.guides.axes,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattedLegends:n,containerSize:{width:t.width,height:t.height},externalMeasurements:l,formattingLocale:t.formattingLocale,layout:e.config.layout}),R=t.pixelRatio??2,T=new o(t.width*R,t.height*R),A=T.getContext("2d");return A.scale(R,R),Yo({ctx:A,theme:c==="dark"?Je:Ze,colorScheme:c,chromeReaders:a,axisLabelStyles:h,tickLabelStyles:f,tickLineStyles:g,width:t.width,height:t.height,compiled:e,formattedAxes:S,formattedLegends:n,layout:y,textMeasurer:p,...t.formattingLocale===void 0?{}:{formattingLocale:t.formattingLocale}}),T.encode("png")},Yo=({ctx:e,theme:t,colorScheme:o,chromeReaders:n,axisLabelStyles:r,tickLabelStyles:s,tickLineStyles:i,width:l,height:c,compiled:a,formattedAxes:u,formattedLegends:h,layout:f,textMeasurer:g,formattingLocale:m})=>{e.fillStyle=t.background,e.fillRect(0,0,l,c),Io(e,u,n,f.panel),e.save(),e.beginPath(),e.rect(f.panel.x,f.panel.y,f.panel.width,f.panel.height),e.clip();const p={coordSystem:a.coordSystem,panel:f.panel,compiled:a,theme:t,colorScheme:o,textMeasurer:g,formattingLocale:m};for(const b of a.layers){const y=Ce(b,a.coordSystem);y&&Dt(y,e,{...p,layer:b})}e.restore();for(const b of u){const y=f.axes[b.position];if(y){const S=d.getAestheticFromScaleAestheticKey(b.scaleAestheticKey);co(e,b,y,f.panel,s[S],i[S])}}for(const b of a.guides.axes){const y=f.axisLabels[b.position];y&&mo(e,b,y,r[d.getAestheticFromScaleAestheticKey(b.scaleAestheticKey)])}ko(e,h,f.legends,t),Bo(e,a.config.content,f.header,t,{width:l,height:c}),Po(e,a.config.content,f.footer,t,{width:l,height:c})};class xe extends Error{constructor(t){super(t),this.name="ChartConfigRenderError"}}const zo=async(e,t)=>{const o=Ne(e);if(!o.ok)throw new xe(o.reason);return $e(o.compiled,t)};exports.CANVAS_CAPABILITY_MATRIX=Ut;exports.CANVAS_SUPPORTED_GRAPH_TYPES=se;exports.CANVAS_UNSUPPORTED_GRAPH_TYPES=Pe;exports.ChartConfigRenderError=xe;exports.NodeCanvasTextMeasurer=Qe;exports.canRenderConfigWithCanvas=Ne;exports.darkTheme=Je;exports.ensureDefaultFonts=Ee;exports.lightTheme=Ze;exports.loadCanvasRuntime=Se;exports.parseChartConfig=Ie;exports.registerFont=ne;exports.renderChartConfigToPng=zo;exports.renderGraphToPng=Xo;
|
|
1
|
+
"use strict";var et=Object.create;var le=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var ot=Object.getOwnPropertyNames;var nt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var st=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ot(t))!rt.call(e,r)&&r!==o&&le(e,r,{get:()=>t[r],enumerable:!(n=tt(t,r))||n.enumerable});return e};var it=(e,t,o)=>(o=e!=null?et(nt(e)):{},st(t||!e||!e.__esModule?le(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ce=require("node:fs"),ye=require("node:module"),O=require("node:path"),at=require("node:url"),lt=require("@graphysdk/viz-engine/graph-config"),I=require("d3-shape"),d=require("@graphysdk/viz-engine"),ct=require("node:buffer");var _=typeof document<"u"?document.currentScript:null;let H,Q;const Se=()=>H?Promise.resolve(H):(Q??=import("@napi-rs/canvas").then(e=>(H=e,e)).catch(e=>{throw Q=void 0,e}),Q),V=()=>{if(!H)throw new Error("Canvas runtime is not loaded. Call loadCanvasRuntime() before rendering.");return H},E="Inter",J=new Set;let de=!1,z=!1;const Te=e=>`${e.family}|${e.weight??400}|${e.style??"normal"}`,ne=e=>{const t=Te(e);J.has(t)||(V().GlobalFonts.register(e.data,e.family),J.add(t))},dt=[{file:"Inter-Regular.ttf",family:E,weight:400},{file:"Inter-SemiBold.ttf",family:E,weight:600}],ut=[{file:"inter-latin-400-normal.woff",family:E,weight:400},{file:"inter-latin-600-normal.woff",family:E,weight:600}],ft="@fontsource/inter",ht=()=>{try{const e=ye.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href),t=O.dirname(e.resolve("@graphysdk/node-renderer/package.json"));return O.join(t,"assets")}catch{return O.resolve(O.dirname(at.fileURLToPath(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href)),"../assets")}},Re=(e,t,o)=>{try{return ce.existsSync(e)?(ne({family:t,data:ce.readFileSync(e),weight:o}),!0):!1}catch{return!1}},gt=()=>{const e=ht();for(const{file:t,family:o,weight:n}of dt)Re(O.join(e,t),o,n)&&(z=!0)},mt=()=>{const e=ye.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href);for(const{file:t,family:o,weight:n}of ut)if(!J.has(Te({family:o,data:Buffer.alloc(0),weight:n})))try{const r=e.resolve(`${ft}/files/${t}`);Re(r,o,n)&&(z=!0)}catch{}},Ee=()=>(de||(de=!0,gt(),mt()),z),C=(e,t)=>e.x+t*e.width,v=(e,t)=>e.y+(1-t)*e.height,$=e=>e==="catmull-rom"?I.curveCatmullRom:I.curveLinear,Le=e=>{switch(e){case"dashed":return[8,4];case"dotted":return[2,2];case"solid":return[]}},D=e=>e,At=(e,t)=>t!=="connect"?e:e.filter(o=>d.getX(o)!==null&&d.getY(o)!==null),bt=(e,t,o)=>{const n=$(t.interpolate),r=I.area().curve(n),s=I.line().curve(n);if(e.mainAxis==="y"){const i=a=>v(o,d.getY(a)??0),l=a=>C(o,d.getXMin(a)??0),c=a=>C(o,d.getXMax(a)??d.getX(a)??0);r.y(i).x0(l).x1(c),s.y(i).x(c)}else{const i=a=>C(o,d.getX(a)??0),l=a=>v(o,d.getYMin(a)??0),c=a=>v(o,d.getYMax(a)??d.getY(a)??0);r.x(i).y0(l).y1(c),s.x(i).y(c)}if(t.missingValues==="gap"){const i=l=>d.getX(l)!==null&&d.getY(l)!==null;r.defined(i),s.defined(i)}return{areaGenerator:r,lineGenerator:s}},pt=D({geom:"area",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const s=d.createStyleResolver({colorScheme:r}).geomReaders(t),{areaGenerator:i,lineGenerator:l}=bt(o,t.params,n),c=e;t.data.groupBy(d.GROUP_VARIABLES.group).forEach(a=>{const u=At([...a],t.params.missingValues),h=u[0];if(!h)return;const f=s.get("color",h),g=s.get("alpha",h),m=s.get("strokeWidth",h),p=Le(s.get("lineType",h));e.save(),e.globalAlpha=g,e.fillStyle=f,e.beginPath(),i.context(c)(u),e.fill(),e.restore(),e.save(),e.globalAlpha=s.get("strokeAlpha",h),e.strokeStyle=f,e.lineWidth=m,e.setLineDash(p),e.lineJoin="round",e.lineCap="round",e.beginPath(),l.context(c)(u),e.stroke(),e.restore()})}}),ue=(e,t,o,n,r,s)=>{const i=Math.max(0,Math.min(s.rx??s.ry??0,n/2)),l=Math.max(0,Math.min(s.ry??s.rx??0,r/2)),c=Math.PI/2;e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.ellipse(t+n-i,o+l,i,l,0,-c,0),e.lineTo(t+n,o+r-l),e.ellipse(t+n-i,o+r-l,i,l,0,0,c),e.lineTo(t+i,o+r),e.ellipse(t+i,o+r-l,i,l,0,c,Math.PI),e.lineTo(t,o+l),e.ellipse(t+i,o+l,i,l,0,Math.PI,Math.PI*1.5),e.closePath()},yt=D({geom:"bar",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const{Path2D:s}=V(),i=d.createStyleResolver({colorScheme:r}).geomReaders(t),l=o.mainAxis,c=new Map;for(const a of t.data){const u=d.getBarRectBounds(l,a);if(!u)continue;const h=C(n,u.x),f=n.y+u.y*n.height,g={x:h,y:f,width:u.width*n.width,height:u.height*n.height,fill:i.get("color",a),opacity:i.get("alpha",a)},m=d.buildColumnKey(l,u),p=c.get(m);p?p.bars.push(g):c.set(m,{bars:[g],style:{borderColor:i.get("borderColor",a),borderWidth:i.get("borderWidth",a),borderRadius:i.get("borderRadius",a),borderAlpha:i.get("alpha",a)}})}for(const{bars:a,style:u}of c.values()){const{borderColor:h,borderRadius:f,borderWidth:g,borderAlpha:m}=u,p=d.resolveBarBorderTreatment(g),b=f==="full"?void 0:d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l});if(!(a.length>1)){const[A]=a;if(!A)continue;const w=b??d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l,bounds:{width:A.width,height:A.height}}),L=new s;ue(L,A.x,A.y,A.width,A.height,w),e.save(),e.globalAlpha=A.opacity,e.fillStyle=A.fill,e.fill(L),h!==void 0&&(e.clip(L),e.strokeStyle=h,e.lineWidth=p.outlineWidth,e.stroke(L)),e.restore();continue}const S=d.getBoundingRect(a),R=b??d.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l,bounds:{width:S.width,height:S.height}}),T=new s;ue(T,S.x,S.y,S.width,S.height,R),e.save(),e.clip(T);for(const A of a)e.globalAlpha=A.opacity,e.fillStyle=A.fill,e.fillRect(A.x,A.y,A.width,A.height),h!==void 0&&(e.strokeStyle=h,e.lineWidth=p.separatorWidth,e.strokeRect(A.x,A.y,A.width,A.height));h!==void 0&&(e.globalAlpha=m,e.strokeStyle=h,e.lineWidth=p.outlineWidth,e.stroke(T)),e.restore()}}}),fe=(e,t)=>{const o=/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());if(o?.[1]!==void 0){const r=o[1],s=r.length===3?[...r].map(a=>a+a).join(""):r.slice(0,6),i=Number.parseInt(s.slice(0,2),16),l=Number.parseInt(s.slice(2,4),16),c=Number.parseInt(s.slice(4,6),16);return`rgba(${i}, ${l}, ${c}, ${t})`}const n=/^rgba?\(([^)]+)\)$/i.exec(e.trim());if(n?.[1]!==void 0){const r=n[1].split(",").map(c=>c.trim()),[s,i,l]=r;if(s!==void 0&&i!==void 0&&l!==void 0)return`rgba(${s}, ${i}, ${l}, ${t})`}return t===0?"rgba(0, 0, 0, 0)":e},St=(e,t)=>t!=="connect"?e:e.filter(o=>d.getX(o)!==null&&d.getY(o)!==null),Tt=(e,t)=>{const{seriesObservations:o,fillGenerator:n,panel:r,color:s,fillAlpha:i}=t,l=o.map(a=>d.getY(a)).filter(a=>a!==null).map(a=>v(r,a));if(l.length===0)return;const c=e.createLinearGradient(0,Math.min(...l),0,r.y+r.height);c.addColorStop(0,s),c.addColorStop(.7,fe(s,0)),c.addColorStop(1,fe(s,0)),e.save(),e.globalAlpha=i,e.fillStyle=c,e.beginPath(),n.context(e)(o),e.fill(),e.restore()},Rt=D({geom:"line",coord:"cartesian",draw:(e,{layer:t,panel:o,colorScheme:n})=>{const r=d.createStyleResolver({colorScheme:n}).geomReaders(t),s=I.line().x(l=>C(o,d.getX(l)??0)).y(l=>v(o,d.getY(l)??0)).curve($(t.params.interpolate)),i=I.area().x(l=>C(o,d.getX(l)??0)).y0(o.y+o.height).y1(l=>v(o,d.getY(l)??0)).curve($(t.params.interpolate));if(t.params.missingValues==="gap"){const l=c=>d.getX(c)!==null&&d.getY(c)!==null;s.defined(l),i.defined(l)}t.data.groupBy(d.GROUP_VARIABLES.group).forEach(l=>{const c=St([...l],t.params.missingValues),a=c[0];if(!a)return;const u=r.get("strokeWidth",a),h=Le(r.get("lineType",a)),f=r.get("color",a),g=r.get("fillAlpha",a);g!==void 0&&Tt(e,{seriesObservations:c,fillGenerator:i,panel:o,color:f,fillAlpha:g}),e.save(),e.globalAlpha=r.get("alpha",a),e.strokeStyle=f,e.lineWidth=u,e.setLineDash(h),e.lineJoin="round",e.lineCap="round",e.beginPath(),s.context(e)(c),e.stroke(),e.restore()})}}),Et=D({geom:"point",coord:"cartesian",draw:(e,{layer:t,panel:o,colorScheme:n})=>{const r=d.createStyleResolver({colorScheme:n}).geomReaders(t);for(const s of t.data){const i=d.getX(s),l=d.getY(s);if(i===null||l===null)continue;const c=C(o,i),a=v(o,l),u=r.get("size",s)/2,h=r.get("borderWidth",s);e.save(),e.globalAlpha=r.get("alpha",s),e.fillStyle=r.get("color",s),e.strokeStyle=r.get("borderColor",s),e.lineWidth=h,e.beginPath(),e.arc(c,a,u,0,Math.PI*2),e.fill(),h>0&&e.stroke(),e.restore()}}}),re=11,Lt="sans-serif",wt=500,k=5,we=5,x=13,ve=6,K=12,he=21.6,vt=(e,t)=>{const o=e.mapping.y!==void 0,n=t.mainAxis==="y";return o!==n},_t=(e,t,o)=>{const n=d.getRuleDashPattern(t,o);e.setLineDash(n),n.length>0&&(e.lineCap="round")},Ct=(e,t)=>X(e)&&X(t)?`${e}: ${t}`:X(e)?e:X(t)?t:null,X=e=>e!=null&&e.trim()!=="",Bt=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()},_e=(e,t,o,n,r,s)=>{const i=Math.min(s,n/2,r/2);e.beginPath(),e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.arcTo(t+n,o,t+n,o+i,i),e.lineTo(t+n,o+r-i),e.arcTo(t+n,o+r,t+n-i,o+r,i),e.lineTo(t+i,o+r),e.arcTo(t,o+r,t,o+r-i,i),e.lineTo(t,o+i),e.arcTo(t,o,t+i,o,i),e.closePath(),e.fill()},Pt=(e,t,o,n,r,s,i,l)=>{const c=o+k*2,a=re+we*2,u=n==="start",h=u?s.x:s.x+s.width,f=v(s,r),g=u?-x:-(c-x),m=u?g+c-k:g+k-K;e.save(),e.translate(h,f),e.translate(0,-a/2),e.fillStyle=i,_e(e,g,0,c,a,ve),e.save(),u||(e.translate(m+K/2,a/2),e.rotate(Math.PI),e.translate(-(m+K/2),-a/2)),e.translate(m,(a-he)/2),e.scale(K/10,he/18),e.fillStyle=i,Bt(e),e.fill(),e.restore(),e.fillStyle=l,e.textAlign="left",e.textBaseline="middle",e.fillText(t,g+k,a/2),e.restore()},It=(e,t,o,n,r,s,i,l)=>{const c=o+k*2,a=re+we*2,u=n==="start",h=C(s,r),f=u?s.y+s.height:s.y,g=u?-x:-8;e.save(),e.translate(h,f),e.translate(-c/2,0),e.fillStyle=i,_e(e,0,g,c,a,ve),e.fillStyle=l,e.textAlign="left",e.textBaseline="middle",e.fillText(t,k,g+a/2),e.restore()},Nt=D({geom:"rule",coord:"cartesian",draw:(e,{layer:t,coordSystem:o,panel:n,compiled:r,textMeasurer:s,formattingLocale:i,colorScheme:l})=>{const c=t.data.getFirst();if(!c)return;const a=vt(t,o),u=a?d.getY(c):d.getX(c);if(u===null)return;const h=d.createStyleResolver({colorScheme:l}).geomReaders(t),f=h.get("color",c),g=d.pickReadableTextColor(f),m=h.get("strokeWidth",c);if(e.save(),e.strokeStyle=f,e.lineWidth=m,_t(e,h.get("lineType",c),m),e.beginPath(),a){const T=v(n,u);e.moveTo(n.x,T),e.lineTo(n.x+n.width,T)}else{const T=C(n,u);e.moveTo(T,n.y),e.lineTo(T,n.y+n.height)}e.stroke(),e.restore();const p=Ct(t.params.label,d.formatRuleValue({guides:r.guides,numberFormat:r.config.numberFormat,layer:t,locale:i??r.config.parsingLocale}));if(p===null)return;const b=r.config.appearance.textScale,y={family:Lt,size:re*b,weight:wt};e.font=d.buildFontString(y);const S=s.measureText(p,y).width;(a?Pt:It)(e,p,S,t.params.labelPosition,u,n,f,g)}}),U=I.arc();U.digits(8);const kt=D({geom:"bar",coord:"polar",draw:(e,{layer:t,coordSystem:o,panel:n,colorScheme:r})=>{const s=n.x+n.width/2,i=n.y+n.height/2,l=Math.min(n.width,n.height)/2,{Path2D:c}=V(),a=d.createStyleResolver({colorScheme:r}).geomReaders(t);e.save(),e.translate(s,i),e.scale(l,l);const u=e,h=new Map;for(const f of t.data){const{startAngle:g,endAngle:m}=d.getAngleExtent(f),{innerRadius:p,outerRadius:b}=d.getRadiusExtent(f);if(g===null||m===null||p===null||b===null)continue;const y={startAngle:g,endAngle:m,innerRadius:p,outerRadius:b,fill:a.get("color",f),opacity:a.get("alpha",f)},S=d.buildSliceGroupKey(o.bandAxis,y),R=h.get(S);R?R.items.push(y):h.set(S,{items:[y],style:{borderColor:a.get("borderColor",f),borderWidth:a.get("borderWidth",f),borderRadius:a.get("borderRadius",f),borderAlpha:a.get("alpha",f)}})}for(const{items:f,style:g}of h.values()){const{borderColor:m,borderRadius:p,borderWidth:b,borderAlpha:y}=g,S=d.resolveBarBorderTreatment(b),R=m!==void 0&&l>0,T=d.getUnionExtent(f),A=d.resolvePolarBarCornerRadiusUnit(p,T.outerRadius-T.innerRadius),w=l>0&&(R||A>0);e.save();let L;w&&(L=new c,U.cornerRadius(A),U.context(L)(T),e.clip(L)),U.cornerRadius(0);for(const N of f)e.globalAlpha=N.opacity,e.fillStyle=N.fill,e.beginPath(),U.context(u)(N),e.fill(),R&&(e.strokeStyle=m,e.lineWidth=S.separatorWidth/l,e.stroke());R&&L&&(e.globalAlpha=y,e.strokeStyle=m,e.lineWidth=S.outlineWidth/l,e.stroke(L)),e.restore()}e.restore()}}),Ft={bar:{cartesian:yt,polar:kt},line:{cartesian:Rt},area:{cartesian:pt},point:{cartesian:Et},rule:{cartesian:Nt}},Ce=(e,t)=>Ft[e.geom]?.[t.type]??null,Dt=(e,t,o)=>{e.draw(t,o)};let ge;const Be=()=>(ge??=d.createCompiler(),ge),se=["line","areaStacked","bar","barStacked","barStackedFill","column","columnStacked","columnStackedFill","combo","pie","donut","scatter","bubble"],Pe=["funnel","heatmap","waterfall","mekko","table"],Ot=new Set(se),Ut={supportedGraphTypes:[...se],unsupportedGraphTypes:[...Pe],supportedGeoms:{cartesian:["bar","line","area","point","rule"],polar:["bar"]}},P=e=>({ok:!1,reason:e}),q=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Ht=e=>{if(!q(e))return!1;const{columns:t,rows:o}=e;return!Array.isArray(t)||!Array.isArray(o)?!1:t.every(n=>q(n)&&typeof n.key=="string")},Mt=e=>{if("_unstable_mapping"in e&&e._unstable_mapping!==void 0)return!0;const t=e.referenceLines;return q(t)?t.trendline!==void 0||t.averageLine!==void 0:!1},Ie=e=>{if(!q(e))return P("Chart config must be a plain object.");if(!Ht(e.data))return P("Chart config is missing a valid `data` object (columns + rows).");const{data:t,...o}=e;return{ok:!0,input:o,data:t}},Ne=e=>{const t=Ie(e);if(!t.ok)return t;if(Mt(e))return P("Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`.");const o=t.input.type??"column";if(!Ot.has(o))return P(`Unsupported chart type for canvas rendering: ${o}.`);try{const n=Be(),r=lt.convertGraphConfig(t.input,t.data),s=n.compile({input:r,data:t.data});if(!s.ok)return P(`Chart config failed to compile: ${s.errors.map(i=>i.message).join("; ")}`);for(const i of s.compiled.layers)if(Ce(i,s.compiled.coordSystem)===null)return P(`No canvas geom renderer for ${i.geom} (${s.compiled.coordSystem.type} coord).`);return{ok:!0,compiled:s.compiled}}catch(n){const r=n instanceof Error?n.message:String(n);return P(`Chart config failed to compile: ${r}`)}},ke=E,M=12,ie=1.3,G=10,W=12,F=6,Fe=16,Gt=24,De=6,Oe=3,ee=4,Wt=8,Vt="#9ca3af",Ue=16,Kt=1.3,He=13,Xt=1.4,Me=12,Yt=1.4,j=8,ae=12,zt=1.3,qt=200,jt=120,Qt=80,Ge=22,Zt=9,Jt=11,$t=10,Y=9,me=12,xt='-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif',eo=11.5,to=550,oo={light:.55,mid:.75,dark:.08},no={light:.62,mid:.8,dark:.85},ro=.22,so=.65,io={family:ke,size:M},ao=[2,3],lo=[1,3],te=e=>{switch(e){case"dashed":return ao;case"dotted":return lo;case"solid":return[]}},co=(e,t,o,n,r,s)=>{if(!t.isVisible||t.ticks.length===0)return;const i=t.position==="bottom"||t.position==="top";e.save(),e.font=d.buildFontString(d.toFontSpec(r,E)),e.fillStyle=r.textColor,e.strokeStyle=s.color,e.lineWidth=s.strokeWidth,e.setLineDash(te(s.lineType));for(const l of t.ticks){const c=i?l.position:1-l.position;t.ticksVisible&&fo(e,t.position,c,o,n,s.length),go(e,t.position,c,o,n,l.formattedLabel,t.labelRotation,r.offset)}e.restore()},uo=(e,t,o,n,r)=>{if(e==="bottom"||e==="top"){const c=n.x+t*n.width,a=e==="top"?o.y+o.height:o.y,u=e==="top"?-r:r;return{x1:c,y1:a,x2:c,y2:a+u}}const s=n.y+t*n.height,i=e==="right"?o.x:o.x+o.width,l=e==="right"?r:-r;return{x1:i,y1:s,x2:i+l,y2:s}},fo=(e,t,o,n,r,s)=>{const{x1:i,y1:l,x2:c,y2:a}=uo(t,o,n,r,s);e.beginPath(),e.moveTo(i,l),e.lineTo(c,a),e.stroke()},ho=(e,t,o,n,r)=>{if(e==="bottom"||e==="top"){const i=n.x+t*n.width;return e==="bottom"?{x:i,y:o.y+r,textAlign:"center",textBaseline:"top"}:{x:i,y:o.y+o.height-r,textAlign:"center",textBaseline:"alphabetic"}}const s=n.y+t*n.height;return e==="left"?{x:o.x+o.width-r,y:s,textAlign:"right",textBaseline:"middle"}:{x:o.x+r,y:s,textAlign:"left",textBaseline:"middle"}},go=(e,t,o,n,r,s,i,l)=>{if(i!==0&&(t==="top"||t==="bottom")){const a=r.x+o*r.width,u=t==="top";e.save(),e.translate(a,u?n.y+n.height-l:n.y+l),e.rotate(i*Math.PI/180),e.textAlign=u?"left":"right",e.textBaseline="middle",e.fillText(s,0,0),e.restore();return}const c=ho(t,o,n,r,l);e.textAlign=c.textAlign,e.textBaseline=c.textBaseline,e.fillText(s,c.x,c.y)},mo=(e,t,o,n)=>{if(!t.isVisible||!t.label)return;e.save(),e.font=d.buildFontString({family:n.fontFamily??E,size:n.fontSize,weight:n.fontWeight}),e.fillStyle=n.textColor,e.textBaseline="middle";const{x:r,y:s,alignment:i}=Ao(t.position,o);e.textAlign=i,e.fillText(t.label,r,s),e.restore()},Ao=(e,t)=>{const o=t.y+t.height/2;return e==="left"?{x:t.x,y:o,alignment:"start"}:e==="right"?{x:t.x+t.width,y:o,alignment:"end"}:{x:t.x+t.width/2,y:o,alignment:"center"}},bo="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABgCAYAAAC65+QhAAAKo0lEQVR42u2de4wdVR3HPzN32+oSUQSsikEoosR3iko08oovEkwMpmiIr/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UUNrJJkbBhxQIU5+Dy3SdSVEpx949JcNpV1NraW7wKxxhWj2ezIi+7VxJrq1o2DivhNr0OS9qUBFCkvN4XgDO6lazdphrvVJUFD5j1jmV5+QdMOFExzD3jGdKOGLcud1Gv0P/rGVyH29B6MiWcmBbARiVAHBNg9srvsqQdV3cDIXuz9ut88Tpp4cSi5I77RSWLGdKOGxUoBXq0Z8cW2C7D8X+n0XFXUtz9nJRhz1lt3xJkFxdvUMV7b7/K5tuAdEStpWgr8MpeVbNGVoHPwG20n6lBs21DhiGVLK9agOrZrwtxq7ePGm48X5PfgeuJWdvN381CG7+pIlBbfryEXCJpxlqRtBG10oHa6NXVx/8Ba+cluUx5B18AAAAASUVORK5CYII=",B=Ge;let Z;const po=()=>{if(Z)return Z;const{Image:e}=V(),t=new e,o=bo.replace(/^data:image\/png;base64,/,"");return t.src=ct.Buffer.from(o,"base64"),Z=t,t},We=(e,t,o="full")=>!e||t.width<jt||t.height<Qt?"hidden":t.width<qt||o==="mini"?"mini":"full",yo=e=>{const t=So(e);if(t===null)return"light";const o=To(t);return o<=ro?"dark":o<=so?"mid":"light"},oe=(e,t,o)=>e.placement!==o||We(e.enabled,t,e.variant)==="hidden"?0:Ge,Ve=(e,t,o,n,r,s)=>{if(t.placement!==s)return;const i=We(t.enabled,r,t.variant);if(i==="hidden")return;const l=yo(n.background),c=l==="dark",a={family:xt,size:eo,weight:400},u={...a,weight:to};let h=0;i==="full"&&(e.font=d.buildFontString(a),h=e.measureText("Made with ").width,e.font=d.buildFontString(u),h+=e.measureText("Graphy").width);const f=i==="mini"?0:Zt,g=i==="mini"?0:Jt,m=i==="mini"?0:$t,p=i==="mini"?B:f+Y+m+h+g,b=o.x+o.width-p,y=o.y+Math.max(0,(o.height||B)/2-B/2);e.save(),e.globalAlpha=no[l],e.textBaseline="middle",e.textAlign="left",c||(e.shadowColor="rgba(0, 0, 0, 0.09)",e.shadowBlur=4,e.shadowOffsetY=1),e.beginPath(),e.roundRect(b,y,p,B,B/2),e.fillStyle=`rgba(255, 255, 255, ${oo[l]})`,e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0;const S=c?"#FFFFFF":"#2A2A28",R=i==="mini"?b+(p-Y)/2:b+f,T=y+(B-me)/2;if(e.save(),c&&(e.filter="invert(1)"),e.drawImage(po(),R,T,Y,me),e.restore(),i==="full"){const A=b+f+Y+m,w=y+B/2;e.fillStyle=S,e.font=d.buildFontString(a),e.fillText("Made with ",A,w);const L=e.measureText("Made with ").width;e.font=d.buildFontString(u),e.fillText("Graphy",A+L,w)}e.restore()},So=e=>{const t=e.trim();if(!t.startsWith("#"))return null;const o=t.slice(1);if(o.length===3){const n=o[0],r=o[1],s=o[2];return n===void 0||r===void 0||s===void 0?null:{red:Number.parseInt(n+n,16),green:Number.parseInt(r+r,16),blue:Number.parseInt(s+s,16)}}return o.length>=6?{red:Number.parseInt(o.slice(0,2),16),green:Number.parseInt(o.slice(2,4),16),blue:Number.parseInt(o.slice(4,6),16)}:null},To=({red:e,green:t,blue:o})=>{const n=r=>{const s=r/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4};return .2126*n(e)+.7152*n(t)+.0722*n(o)},Ro={family:E,size:Ue,weight:600},Eo={family:E,size:He},Lo={family:E,size:Me},wo={family:E,size:ae,weight:500},vo={family:E,size:ae},Ke=Ue*Kt,_o=He*Xt,Xe=Me*Yt,Ye=ae*zt,ze=e=>{if(e===null)return null;if(e.label!==void 0&&e.label!=="")return e.label;if(e.url!==void 0&&e.url!==""&&d.isSafeUrl(e.url))try{return new URL(e.url).hostname}catch{return e.url}return null},Co=(e,t)=>{let o=0;const n=e.isTitleVisible&&e.title!==null,r=e.isSubtitleVisible&&e.subtitle!==null;n&&(o+=Ke),r&&(o>0&&(o+=j),o+=_o);const s=oe(e.brandMark,t,"header");!n&&!r&&s>0&&(o=s);const i=e.isCaptionVisible&&e.caption!==null,l=e.isSourceVisible&&ze(e.source)!==null,c=oe(e.brandMark,t,"footer");let a=0;return i&&(a+=Xe),(l||c>0)&&(a>0&&(a+=j),a+=Math.max(Ye,c)),{headerHeight:o,footerHeight:a}},Bo=(e,t,o,n,r)=>{if(o.height===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let s=o.y;t.isTitleVisible&&t.title!==null&&(e.font=d.buildFontString(Ro),e.fillStyle=n.textPrimary,e.fillText(d.extractPlainText(t.title),o.x,s),s+=Ke+j),t.isSubtitleVisible&&t.subtitle!==null&&(e.font=d.buildFontString(Eo),e.fillStyle=n.textSecondary,e.fillText(d.extractPlainText(t.subtitle),o.x,s)),e.restore(),Ve(e,t.brandMark,o,n,r,"header")},Po=(e,t,o,n,r)=>{if(o.height===0)return;const s=t.isCaptionVisible?t.caption:null,i=t.isSourceVisible?ze(t.source):null,l=oe(t.brandMark,r,"footer");if(s===null&&i===null&&l===0)return;e.save(),e.textBaseline="top",e.textAlign="left";let c=o.y;if(s!==null&&(e.font=d.buildFontString(Lo),e.fillStyle=n.textSecondary,e.fillText(d.extractPlainText(s),o.x,c),c+=Xe+j),i!==null){let a=o.x;a=Ae(e,"Source: ",wo,n.textSecondary,a,c),Ae(e,i,vo,n.textSecondary,a,c)}e.restore(),Ve(e,t.brandMark,{x:o.x,y:c,width:o.width,height:Math.max(Ye,l)},n,r,"footer")},Ae=(e,t,o,n,r,s)=>(e.font=d.buildFontString(o),e.fillStyle=n,e.fillText(t,r,s),r+e.measureText(t).width),Io=(e,t,o,n)=>{e.save(),e.lineCap="round";for(const r of d.computePanelBorderPaths(d.resolvePanelBorderStyle(o),n))e.strokeStyle=r.color,e.lineWidth=r.strokeWidth,e.setLineDash(te(r.lineType)),No(e,r.segments),e.stroke();for(const r of t){if(!r.gridVisible)continue;const s=r.position==="top"||r.position==="bottom",i=d.resolveGridLineStyle(o,d.getAestheticFromScaleAestheticKey(r.scaleAestheticKey));e.strokeStyle=i.color,e.lineWidth=i.strokeWidth,e.setLineDash(te(i.lineType));for(const l of r.ticks){if(l.position<=0||l.position>=1)continue;const c=s?l.position:1-l.position;if(e.beginPath(),s){const a=n.x+c*n.width;e.moveTo(a,n.y),e.lineTo(a,n.y+n.height)}else{const a=n.y+c*n.height;e.moveTo(n.x,a),e.lineTo(n.x+n.width,a)}e.stroke()}}e.restore()},No=(e,t)=>{e.beginPath();for(const o of t)switch(o.type){case"move":e.moveTo(o.x,o.y);break;case"line":e.lineTo(o.x,o.y);break;case"arc":e.arc(o.cx,o.cy,o.radius,o.startAngle,o.endAngle);break;case"close":e.closePath();break}},ko=(e,t,o,n)=>{e.save(),e.font=d.buildFontString(io),e.textBaseline="middle";for(const s of t)s.display==="direct"&&Fo(e,s,o,n);const r=new Map;for(const s of t){if(s.display!=="pill"||s.items.length===0)continue;const i=r.get(s.position);i?i.push(s):r.set(s.position,[s])}for(const[s,i]of r){const l=o[s];l&&(s==="top"||s==="bottom"?Do(e,i,l,n):Oo(e,i,l,n))}e.restore()},Fo=(e,t,o,n)=>{const r=o[t.position];if(r){e.textAlign="left";for(const s of t.items)s.normalizedY!==null&&(e.fillStyle=typeof s.visual.color=="string"?s.visual.color:n.textPrimary,e.fillText(s.formattedLabel,r.x+Wt,v(r,s.normalizedY)))}},Do=(e,t,o,n)=>{const r=qe(t),s=r.reduce((a,u,h)=>a+Ho(u)+e.measureText(u.label).width+(h===0?0:be(u)),0),i=M*ie;let l=o.x+Math.max(0,(o.width-s)/2);const c=o.y+De+Math.max(i,W)/2;for(let a=0;a<r.length;a++){const u=r[a];u&&(a>0&&(l+=be(u)),l=je(e,u,l,c,n))}},Oo=(e,t,o,n)=>{const r=qe(t),s=Math.max(M*ie,W),i=4,l=r.length*s+Math.max(0,r.length-1)*i;let c=o.y+Math.max(0,(o.height-l)/2)+s/2;for(const a of r)je(e,a,o.x,c,n),c+=s+i},qe=e=>{const t=[];for(const o of e){const n=o.aesthetics.includes("size");o.items.forEach((r,s)=>{const i=r.visual.size,l=n&&typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0;t.push({label:r.formattedLabel,colors:Uo(r.visual.color),bubbleSize:l,isFirstInGroup:s===0})})}return t},Uo=e=>typeof e=="string"?[e]:Array.isArray(e)?e.filter(t=>typeof t=="string"):[],be=e=>e.isFirstInGroup?Gt:Fe,Ho=e=>{if(e.bubbleSize!==void 0)return e.bubbleSize+F;const t=e.colors.length;if(t===0)return 0;if(t===1)return G+F;const o=Math.min(t,Oe);return G+(o-1)*ee+F},je=(e,t,o,n,r)=>{let s=o;if(t.bubbleSize!==void 0){const i=t.bubbleSize/2;e.fillStyle=t.colors[0]??Vt,e.beginPath(),e.arc(s+i,n,i,0,Math.PI*2),e.fill(),s+=t.bubbleSize+F}else if(t.colors.length>0){const i=t.colors.slice(0,Oe);for(let l=0;l<i.length;l++){const c=i[l];c&&(e.fillStyle=c,e.fillRect(s+l*ee,n-W/2,G,W))}s+=G+(i.length-1)*ee+F}return e.fillStyle=r.textPrimary,e.textAlign="left",e.fillText(t.label,s,n),s+e.measureText(t.label).width},pe=(e,t)=>Math.min(Math.max(...e),t),Mo=(e,t,o)=>n=>{if(!n.isVisible||n.ticks.length===0)return 0;const r=n.position==="top"||n.position==="bottom",s=d.getAestheticFromScaleAestheticKey(n.scaleAestheticKey),{offset:i,...l}=t[s],c=n.ticksVisible?Math.max(i,o[s].length):i,a=d.toFontSpec(l,E),u=n.ticks.map(g=>e.measureText(g.formattedLabel,a)),h=n.labelMaxWidthPx??Number.POSITIVE_INFINITY;if(r){if(n.labelRotation!==0){const g=u.map(m=>m.width);return pe(g,h)+2*c}return Math.max(...u.map(g=>g.height))+c}const f=u.map(g=>g.width);return pe(f,h)+c},Go=e=>t=>{if(t.items.length===0)return 0;const o={family:ke,size:M};if(t.position==="top"||t.position==="bottom"){const s=M*ie;return Math.max(s,W)+De*2}const r=t.items.map(s=>{const i=e.measureText(s.formattedLabel,o).width;return G+F+i});return Math.max(...r)+Fe},Wo=e=>(t,o)=>{const{labelLineHeight:n,labelFontWeight:r}=d.getDifferenceArrowDimensions(o,1);return e.measureText(t,{family:E,size:n,weight:r})},Vo=(e,t)=>(o,n,r)=>{const s=t[o][n],i=e.measureText(r,d.toFontSpec(s,E));return{...i,width:i.width+s.paddingInline*2,height:i.height+s.paddingBlock*2}},Ko=({textMeasurer:e,axisLabelStyles:t,dataLabelStyles:o,tickLabelStyles:n,tickLineStyles:r})=>({measureAxis:Mo(e,n,r),measureAxisLabel:s=>d.computeLineBoxHeight(t[d.getAestheticFromScaleAestheticKey(s.scaleAestheticKey)]),measureLegend:Go(e),measureTickLabel:(s,i)=>e.measureText(s,d.toFontSpec(n[i],E)),measureDifferenceArrowLabel:Wo(e),measureDataLabel:Vo(e,o),measureHeadline:()=>({width:0,height:0}),measureHeadlineItemWidths:()=>[]});class Qe{constructor(){this.currentFont="";const t=V().createCanvas(1,1);this.ctx=t.getContext("2d")}measureText(t,o){const n=d.buildFontString(o);this.currentFont!==n&&(this.ctx.font=n,this.currentFont=n);const r=this.ctx.measureText(t);return{width:r.width,height:r.fontBoundingBoxAscent+r.fontBoundingBoxDescent,ascent:r.fontBoundingBoxAscent,descent:r.fontBoundingBoxDescent}}}const Ze={background:"#ffffff",textPrimary:"#111827",textSecondary:"#6b7280",gridLine:"#e5e7eb",legendPillBackground:"rgba(0, 0, 0, 0.04)",legendPillBorder:"rgba(0, 0, 0, 0.08)"},Je={background:"#0b0f17",textPrimary:"#e5e7eb",textSecondary:"#9ca3af",gridLine:"#1f2937",legendPillBackground:"rgba(255, 255, 255, 0.06)",legendPillBorder:"rgba(255, 255, 255, 0.12)"},Xo=async({input:e,data:t},o)=>{const r=Be().compile({input:e,data:t});if(!r.ok)throw new Error(`Failed to compile graph spec: ${r.errors.map(s=>s.message).join("; ")}`);return $e(r.compiled,o)},$e=async(e,t)=>{const{Canvas:o}=await Se();if(Ee(),t.fonts)for(const w of t.fonts)ne(w);const n=d.formatLegends({legends:e.guides.legends.drawn,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattingLocale:t.formattingLocale}),r={width:t.width,height:t.height},{headerHeight:s,footerHeight:i}=Co(e.config.content,r),l={headerSize:{width:t.width,height:s},footerSize:{width:t.width,height:i}},c=t.colorScheme??"light",a=d.createStyleResolver({colorScheme:c}).chromeReaders(e.chrome),u=e.config.appearance.textScale,h={x:d.resolveAxisLabelStyle(a,"x",u),y:d.resolveAxisLabelStyle(a,"y",u)},f={x:d.resolveTickLabelStyle(a,"x",u),y:d.resolveTickLabelStyle(a,"y",u)},g={x:d.resolveTickLineStyle(a,"x"),y:d.resolveTickLineStyle(a,"y")},m={};for(const w of d.DATA_LABEL_ROLES){const L={};for(const N of d.DATA_LABEL_POSITIONS)L[N]=d.resolveDataLabelStyle(a,w,N,u);m[w]=L}const p=new Qe,b=Ko({textMeasurer:p,axisLabelStyles:h,dataLabelStyles:m,tickLabelStyles:f,tickLineStyles:g}),{layout:y,formattedAxes:S}=new d.LayoutCompiler(b).compile({axes:e.guides.axes,numberFormat:e.config.numberFormat,parsingLocale:e.config.parsingLocale,formattedLegends:n,containerSize:{width:t.width,height:t.height},externalMeasurements:l,formattingLocale:t.formattingLocale,layout:e.config.layout}),R=t.pixelRatio??2,T=new o(t.width*R,t.height*R),A=T.getContext("2d");return A.scale(R,R),Yo({ctx:A,theme:c==="dark"?Je:Ze,colorScheme:c,chromeReaders:a,axisLabelStyles:h,tickLabelStyles:f,tickLineStyles:g,width:t.width,height:t.height,compiled:e,formattedAxes:S,formattedLegends:n,layout:y,textMeasurer:p,...t.formattingLocale===void 0?{}:{formattingLocale:t.formattingLocale}}),T.encode("png")},Yo=({ctx:e,theme:t,colorScheme:o,chromeReaders:n,axisLabelStyles:r,tickLabelStyles:s,tickLineStyles:i,width:l,height:c,compiled:a,formattedAxes:u,formattedLegends:h,layout:f,textMeasurer:g,formattingLocale:m})=>{e.fillStyle=t.background,e.fillRect(0,0,l,c),Io(e,u,n,f.panel),e.save(),e.beginPath(),e.rect(f.panel.x,f.panel.y,f.panel.width,f.panel.height),e.clip();const p={coordSystem:a.coordSystem,panel:f.panel,compiled:a,theme:t,colorScheme:o,textMeasurer:g,formattingLocale:m};for(const b of a.layers){const y=Ce(b,a.coordSystem);y&&Dt(y,e,{...p,layer:b})}e.restore();for(const b of u){const y=f.axes[b.position];if(y){const S=d.getAestheticFromScaleAestheticKey(b.scaleAestheticKey);co(e,b,y,f.panel,s[S],i[S])}}for(const b of a.guides.axes){const y=f.axisLabels[b.position];y&&mo(e,b,y,r[d.getAestheticFromScaleAestheticKey(b.scaleAestheticKey)])}ko(e,h,f.legends,t),Bo(e,a.config.content,f.header,t,{width:l,height:c}),Po(e,a.config.content,f.footer,t,{width:l,height:c})};class xe extends Error{constructor(t){super(t),this.name="ChartConfigRenderError"}}const zo=async(e,t)=>{const o=Ne(e);if(!o.ok)throw new xe(o.reason);return $e(o.compiled,t)};exports.CANVAS_CAPABILITY_MATRIX=Ut;exports.CANVAS_SUPPORTED_GRAPH_TYPES=se;exports.CANVAS_UNSUPPORTED_GRAPH_TYPES=Pe;exports.ChartConfigRenderError=xe;exports.NodeCanvasTextMeasurer=Qe;exports.canRenderConfigWithCanvas=Ne;exports.darkTheme=Je;exports.ensureDefaultFonts=Ee;exports.lightTheme=Ze;exports.loadCanvasRuntime=Se;exports.parseChartConfig=Ie;exports.registerFont=ne;exports.renderChartConfigToPng=zo;exports.renderGraphToPng=Xo;
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import H 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
6
|
import { curveCatmullRom as st, curveLinear as it, area as Re, line as we, arc as at } from "d3-shape";
|
|
7
|
-
import { createStyleResolver as P, GROUP_VARIABLES as Be, getX as v, getY as B, getXMin as lt, getXMax as dt, getYMin as ct, getYMax as ft, getBarRectBounds as ut, buildColumnKey as ht, resolveBarBorderTreatment as ve, resolveBarCornerRadiiPx as $, getBoundingRect as gt, getRuleDashPattern as mt,
|
|
7
|
+
import { createStyleResolver as P, GROUP_VARIABLES as Be, getX as v, getY as B, getXMin as lt, getXMax as dt, getYMin as ct, getYMax as ft, getBarRectBounds as ut, buildColumnKey as ht, resolveBarBorderTreatment as ve, resolveBarCornerRadiiPx as $, getBoundingRect as gt, getRuleDashPattern as mt, pickReadableTextColor as pt, formatRuleValue as At, buildFontString as R, getAngleExtent as bt, getRadiusExtent as yt, buildSliceGroupKey as Tt, getUnionExtent as St, resolvePolarBarCornerRadiusUnit as Et, createCompiler as Lt, toFontSpec as J, isSafeUrl as Rt, extractPlainText as te, computePanelBorderPaths as wt, resolvePanelBorderStyle as Bt, resolveGridLineStyle as vt, getAestheticFromScaleAestheticKey as U, computeLineBoxHeight as _t, getDifferenceArrowDimensions as Ct, formatLegends as Nt, resolveAxisLabelStyle as fe, resolveTickLabelStyle as ue, resolveTickLineStyle as he, DATA_LABEL_ROLES as It, DATA_LABEL_POSITIONS as Pt, resolveDataLabelStyle as kt, LayoutCompiler as Dt } from "@graphysdk/viz-engine";
|
|
8
8
|
import { Buffer as Ot } from "node:buffer";
|
|
9
9
|
let G, x;
|
|
10
10
|
const Ft = () => G ? Promise.resolve(G) : (x ??= import("@napi-rs/canvas").then((e) => (G = e, e)).catch((e) => {
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"headless",
|
|
13
13
|
"renderer"
|
|
14
14
|
],
|
|
15
|
-
"version": "2.0.0-beta.
|
|
15
|
+
"version": "2.0.0-beta.1787305269287",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"sideEffects": [
|
|
18
18
|
"**/version.ts"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@fontsource/inter": "5.2.8",
|
|
41
41
|
"@napi-rs/canvas": "^0.1.76",
|
|
42
42
|
"d3-shape": "^3.2.0",
|
|
43
|
-
"@graphysdk/viz-engine": "2.0.0-beta.
|
|
43
|
+
"@graphysdk/viz-engine": "2.0.0-beta.1787305269287"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-replace": "^6.0.3",
|