@graphysdk/node-renderer 2.0.0-beta.1788534616557 → 2.0.0-beta.1788537926468
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.d.ts +5 -2
- package/dist/index.mjs +128 -128
- 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 de=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"),c=require("@graphysdk/viz-engine"),dt=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 ce=!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))},ct=[{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 de.existsSync(e)?(ne({family:t,data:de.readFileSync(e),weight:o}),!0):!1}catch{return!1}},gt=()=>{const e=ht();for(const{file:t,family:o,weight:n}of ct)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=()=>(ce||(ce=!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=>c.getX(o)!==null&&c.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,c.getY(a)??0),l=a=>C(o,c.getXMin(a)??0),d=a=>C(o,c.getXMax(a)??c.getX(a)??0);r.y(i).x0(l).x1(d),s.y(i).x(d)}else{const i=a=>C(o,c.getX(a)??0),l=a=>v(o,c.getYMin(a)??0),d=a=>v(o,c.getYMax(a)??c.getY(a)??0);r.x(i).y0(l).y1(d),s.x(i).y(d)}if(t.missingValues==="gap"){const i=l=>c.getX(l)!==null&&c.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=c.createStyleResolver({colorScheme:r}).geomReaders(t),{areaGenerator:i,lineGenerator:l}=bt(o,t.params,n),d=e;t.data.groupBy(c.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(d)(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(d)(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)),d=Math.PI/2;e.moveTo(t+i,o),e.lineTo(t+n-i,o),e.ellipse(t+n-i,o+l,i,l,0,-d,0),e.lineTo(t+n,o+r-l),e.ellipse(t+n-i,o+r-l,i,l,0,0,d),e.lineTo(t+i,o+r),e.ellipse(t+i,o+r-l,i,l,0,d,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=c.createStyleResolver({colorScheme:r}).geomReaders(t),l=o.mainAxis,d=new Map;for(const a of t.data){const u=c.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=c.buildColumnKey(l,u),p=d.get(m);p?p.bars.push(g):d.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 d.values()){const{borderColor:h,borderRadius:f,borderWidth:g,borderAlpha:m}=u,p=c.resolveBarBorderTreatment(g),b=f==="full"?void 0:c.resolveBarCornerRadiiPx({borderRadius:f,mainAxis:l});if(!(a.length>1)){const[A]=a;if(!A)continue;const w=b??c.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=c.getBoundingRect(a),R=b??c.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),d=Number.parseInt(s.slice(4,6),16);return`rgba(${i}, ${l}, ${d}, ${t})`}const n=/^rgba?\(([^)]+)\)$/i.exec(e.trim());if(n?.[1]!==void 0){const r=n[1].split(",").map(d=>d.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=>c.getX(o)!==null&&c.getY(o)!==null),Tt=(e,t)=>{const{seriesObservations:o,fillGenerator:n,panel:r,color:s,fillAlpha:i}=t,l=o.map(a=>c.getY(a)).filter(a=>a!==null).map(a=>v(r,a));if(l.length===0)return;const d=e.createLinearGradient(0,Math.min(...l),0,r.y+r.height);d.addColorStop(0,s),d.addColorStop(.7,fe(s,0)),d.addColorStop(1,fe(s,0)),e.save(),e.globalAlpha=i,e.fillStyle=d,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=c.createStyleResolver({colorScheme:n}).geomReaders(t),s=I.line().x(l=>C(o,c.getX(l)??0)).y(l=>v(o,c.getY(l)??0)).curve($(t.params.interpolate)),i=I.area().x(l=>C(o,c.getX(l)??0)).y0(o.y+o.height).y1(l=>v(o,c.getY(l)??0)).curve($(t.params.interpolate));if(t.params.missingValues==="gap"){const l=d=>c.getX(d)!==null&&c.getY(d)!==null;s.defined(l),i.defined(l)}t.data.groupBy(c.GROUP_VARIABLES.group).forEach(l=>{const d=St([...l],t.params.missingValues),a=d[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:d,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)(d),e.stroke(),e.restore()})}}),Et=D({geom:"point",coord:"cartesian",draw:(e,{layer:t,panel:o,colorScheme:n})=>{const r=c.createStyleResolver({colorScheme:n}).geomReaders(t);for(const s of t.data){const i=c.getX(s),l=c.getY(s);if(i===null||l===null)continue;const d=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(d,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=c.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 d=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:-(d-x),m=u?g+d-k:g+k-K;e.save(),e.translate(h,f),e.translate(0,-a/2),e.fillStyle=i,_e(e,g,0,d,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 d=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(-d/2,0),e.fillStyle=i,_e(e,0,g,d,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 d=t.data.getFirst();if(!d)return;const a=vt(t,o),u=a?c.getY(d):c.getX(d);if(u===null)return;const h=c.createStyleResolver({colorScheme:l}).geomReaders(t),f=h.get("color",d),g=c.pickReadableTextColor(f),m=h.get("strokeWidth",d);if(e.save(),e.strokeStyle=f,e.lineWidth=m,_t(e,h.get("lineType",d),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,c.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=c.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:d}=V(),a=c.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}=c.getAngleExtent(f),{innerRadius:p,outerRadius:b}=c.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=c.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=c.resolveBarBorderTreatment(b),R=m!==void 0&&l>0,T=c.getUnionExtent(f),A=c.resolvePolarBarCornerRadiusUnit(p,T.outerRadius-T.innerRadius),w=l>0&&(R||A>0);e.save();let L;w&&(L=new d,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??=c.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=c.buildFontString(c.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 d=i?l.position:1-l.position;t.ticksVisible&&fo(e,t.position,d,o,n,s.length),go(e,t.position,d,o,n,l.formattedLabel,t.labelRotation,r.offset)}e.restore()},uo=(e,t,o,n,r)=>{if(e==="bottom"||e==="top"){const d=n.x+t*n.width,a=e==="top"?o.y+o.height:o.y,u=e==="top"?-r:r;return{x1:d,y1:a,x2:d,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:d,y2:a}=uo(t,o,n,r,s);e.beginPath(),e.moveTo(i,l),e.lineTo(d,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 d=ho(t,o,n,r,l);e.textAlign=d.textAlign,e.textBaseline=d.textBaseline,e.fillText(s,d.x,d.y)},mo=(e,t,o,n)=>{if(!t.isVisible||!t.label)return;e.save(),e.font=c.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,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",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=dt.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),d=l==="dark",a={family:xt,size:eo,weight:400},u={...a,weight:to};let h=0;i==="full"&&(e.font=c.buildFontString(a),h=e.measureText("Made with ").width,e.font=c.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",d||(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=d?"#FFFFFF":"#2A2A28",R=i==="mini"?b+(p-Y)/2:b+f,T=y+(B-me)/2;if(e.save(),d&&(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=c.buildFontString(a),e.fillText("Made with ",A,w);const L=e.measureText("Made with ").width;e.font=c.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!==""&&c.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,d=oe(e.brandMark,t,"footer");let a=0;return i&&(a+=Xe),(l||d>0)&&(a>0&&(a+=j),a+=Math.max(Ye,d)),{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=c.buildFontString(Ro),e.fillStyle=n.textPrimary,e.fillText(c.extractPlainText(t.title),o.x,s),s+=Ke+j),t.isSubtitleVisible&&t.subtitle!==null&&(e.font=c.buildFontString(Eo),e.fillStyle=n.textSecondary,e.fillText(c.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 d=o.y;if(s!==null&&(e.font=c.buildFontString(Lo),e.fillStyle=n.textSecondary,e.fillText(c.extractPlainText(s),o.x,d),d+=Xe+j),i!==null){let a=o.x;a=Ae(e,"Source: ",wo,n.textSecondary,a,d),Ae(e,i,vo,n.textSecondary,a,d)}e.restore(),Ve(e,t.brandMark,{x:o.x,y:d,width:o.width,height:Math.max(Ye,l)},n,r,"footer")},Ae=(e,t,o,n,r,s)=>(e.font=c.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 c.computePanelBorderPaths(c.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=c.resolveGridLineStyle(o,c.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 d=s?l.position:1-l.position;if(e.beginPath(),s){const a=n.x+d*n.width;e.moveTo(a,n.y),e.lineTo(a,n.y+n.height)}else{const a=n.y+d*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=c.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 d=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,d,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 d=o.y+Math.max(0,(o.height-l)/2)+s/2;for(const a of r)je(e,a,o.x,d,n),d+=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 d=i[l];d&&(e.fillStyle=d,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=c.getAestheticFromScaleAestheticKey(n.scaleAestheticKey),{offset:i,...l}=t[s],d=n.ticksVisible?Math.max(i,o[s].length):i,a=c.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*d}return Math.max(...u.map(g=>g.height))+d}const f=u.map(g=>g.width);return pe(f,h)+d},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)=>e.measureText(t,c.toFontSpec(o,E)),Vo=(e,t)=>(o,n,r)=>{const s=t[o][n],i=e.measureText(r,c.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=>c.computeLineBoxHeight(t[c.getAestheticFromScaleAestheticKey(s.scaleAestheticKey)]),measureLegend:Go(e),measureTickLabel:(s,i)=>e.measureText(s,c.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=c.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=c.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}},d=t.colorScheme??"light",a=c.createStyleResolver({colorScheme:d}).chromeReaders(e.chrome),u=e.config.appearance.textScale,h={x:c.resolveAxisLabelStyle(a,"x",u),y:c.resolveAxisLabelStyle(a,"y",u)},f={x:c.resolveTickLabelStyle(a,"x",u),y:c.resolveTickLabelStyle(a,"y",u)},g={x:c.resolveTickLineStyle(a,"x"),y:c.resolveTickLineStyle(a,"y")},m={};for(const w of c.DATA_LABEL_ROLES){const L={};for(const N of c.DATA_LABEL_POSITIONS)L[N]=c.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 c.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:d==="dark"?Je:Ze,colorScheme:d,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:d,compiled:a,formattedAxes:u,formattedLegends:h,layout:f,textMeasurer:g,formattingLocale:m})=>{e.fillStyle=t.background,e.fillRect(0,0,l,d),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=c.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[c.getAestheticFromScaleAestheticKey(b.scaleAestheticKey)])}ko(e,h,f.legends,t),Bo(e,a.config.content,f.header,t,{width:l,height:d}),Po(e,a.config.content,f.footer,t,{width:l,height:d})};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,t={})=>{const o=Ie(e);if(!o.ok)return o;if(Mt(e))return P("Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`.");const n=o.input.type??"column";if(!Ot.has(n))return P(`Unsupported chart type for canvas rendering: ${n}.`);try{const r=Be(),s=lt.convertGraphConfig(o.input,o.data),i=r.compile({input:s,data:o.data,colorScheme:t.colorScheme});if(!i.ok)return P(`Chart config failed to compile: ${i.errors.map(l=>l.message).join("; ")}`);for(const l of i.compiled.layers)if(Ce(l,i.compiled.coordSystem)===null)return P(`No canvas geom renderer for ${l.geom} (${i.compiled.coordSystem.type} coord).`);return{ok:!0,compiled:i.compiled}}catch(r){const s=r instanceof Error?r.message:String(r);return P(`Chart config failed to compile: ${s}`)}},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,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",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)=>e.measureText(t,d.toFontSpec(o,E)),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,colorScheme:o.colorScheme});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,{colorScheme:t.colorScheme});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.d.ts
CHANGED
|
@@ -11,9 +11,12 @@ import { TextMeasurer } from '@graphysdk/viz-engine';
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Whether a stored chart config can be rendered with the canvas PNG pipeline.
|
|
14
|
-
* Compiles via viz-engine and checks each layer has a node geom renderer.
|
|
14
|
+
* Compiles via viz-engine and checks each layer has a node geom renderer. The compiled spec is
|
|
15
|
+
* rendered as-is, so it takes the scheme the render will use.
|
|
15
16
|
*/
|
|
16
|
-
export declare const canRenderConfigWithCanvas: (config: unknown
|
|
17
|
+
export declare const canRenderConfigWithCanvas: (config: unknown, options?: {
|
|
18
|
+
colorScheme?: ColorScheme;
|
|
19
|
+
}) => CanvasChartConfigResult;
|
|
17
20
|
|
|
18
21
|
export declare const CANVAS_CAPABILITY_MATRIX: {
|
|
19
22
|
readonly supportedGraphTypes: readonly ["line", "areaStacked", "bar", "barStacked", "barStackedFill", "column", "columnStacked", "columnStackedFill", "combo", "pie", "donut", "scatter", "bubble"];
|
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
|
|
7
|
+
import { createStyleResolver as P, GROUP_VARIABLES as Be, getX as v, getY as B, getXMin as lt, getXMax as ct, getYMin as dt, 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 z, isSafeUrl as Rt, extractPlainText as te, computePanelBorderPaths as wt, resolvePanelBorderStyle as Bt, resolveGridLineStyle as vt, getAestheticFromScaleAestheticKey as U, computeLineBoxHeight as _t, formatLegends as Ct, resolveAxisLabelStyle as fe, resolveTickLabelStyle as ue, resolveTickLineStyle as he, DATA_LABEL_ROLES as Nt, DATA_LABEL_POSITIONS as It, resolveDataLabelStyle as Pt, LayoutCompiler as kt } from "@graphysdk/viz-engine";
|
|
8
8
|
import { Buffer as Dt } from "node:buffer";
|
|
9
9
|
let G, x;
|
|
10
10
|
const Ot = () => G ? Promise.resolve(G) : (x ??= import("@napi-rs/canvas").then((e) => (G = e, e)).catch((e) => {
|
|
@@ -66,11 +66,11 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
66
66
|
}, F = (e) => e, Kt = (e, t) => t !== "connect" ? e : e.filter((o) => v(o) !== null && B(o) !== null), zt = (e, t, o) => {
|
|
67
67
|
const n = ne(t.interpolate), s = Re().curve(n), r = we().curve(n);
|
|
68
68
|
if (e.mainAxis === "y") {
|
|
69
|
-
const i = (a) => _(o, B(a) ?? 0), l = (a) => C(o, lt(a) ?? 0),
|
|
70
|
-
s.y(i).x0(l).x1(
|
|
69
|
+
const i = (a) => _(o, B(a) ?? 0), l = (a) => C(o, lt(a) ?? 0), c = (a) => C(o, ct(a) ?? v(a) ?? 0);
|
|
70
|
+
s.y(i).x0(l).x1(c), r.y(i).x(c);
|
|
71
71
|
} else {
|
|
72
|
-
const i = (a) => C(o, v(a) ?? 0), l = (a) => _(o,
|
|
73
|
-
s.x(i).y0(l).y1(
|
|
72
|
+
const i = (a) => C(o, v(a) ?? 0), l = (a) => _(o, dt(a) ?? 0), c = (a) => _(o, ft(a) ?? B(a) ?? 0);
|
|
73
|
+
s.x(i).y0(l).y1(c), r.x(i).y(c);
|
|
74
74
|
}
|
|
75
75
|
if (t.missingValues === "gap") {
|
|
76
76
|
const i = (l) => v(l) !== null && B(l) !== null;
|
|
@@ -81,34 +81,34 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
81
81
|
geom: "area",
|
|
82
82
|
coord: "cartesian",
|
|
83
83
|
draw: (e, { layer: t, coordSystem: o, panel: n, colorScheme: s }) => {
|
|
84
|
-
const r = P({ colorScheme: s }).geomReaders(t), { areaGenerator: i, lineGenerator: l } = zt(o, t.params, n),
|
|
84
|
+
const r = P({ colorScheme: s }).geomReaders(t), { areaGenerator: i, lineGenerator: l } = zt(o, t.params, n), c = e;
|
|
85
85
|
t.data.groupBy(Be.group).forEach((a) => {
|
|
86
|
-
const
|
|
86
|
+
const d = Kt([...a], t.params.missingValues), u = d[0];
|
|
87
87
|
if (!u) return;
|
|
88
88
|
const f = r.get("color", u), h = r.get("alpha", u), g = r.get("strokeWidth", u), A = Ie(r.get("lineType", u));
|
|
89
|
-
e.save(), e.globalAlpha = h, e.fillStyle = f, e.beginPath(), i.context(
|
|
89
|
+
e.save(), e.globalAlpha = h, e.fillStyle = f, e.beginPath(), i.context(c)(d), e.fill(), e.restore(), e.save(), e.globalAlpha = r.get("strokeAlpha", u), e.strokeStyle = f, e.lineWidth = g, e.setLineDash(A), e.lineJoin = "round", e.lineCap = "round", e.beginPath(), l.context(c)(d), e.stroke(), e.restore();
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
}), me = (e, t, o, n, s, r) => {
|
|
93
|
-
const i = Math.max(0, Math.min(r.rx ?? r.ry ?? 0, n / 2)), l = Math.max(0, Math.min(r.ry ?? r.rx ?? 0, s / 2)),
|
|
94
|
-
e.moveTo(t + i, o), e.lineTo(t + n - i, o), e.ellipse(t + n - i, o + l, i, l, 0, -
|
|
93
|
+
const i = Math.max(0, Math.min(r.rx ?? r.ry ?? 0, n / 2)), l = Math.max(0, Math.min(r.ry ?? r.rx ?? 0, s / 2)), c = Math.PI / 2;
|
|
94
|
+
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 + s - l), e.ellipse(t + n - i, o + s - l, i, l, 0, 0, c), e.lineTo(t + i, o + s), e.ellipse(t + i, o + s - 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();
|
|
95
95
|
}, Yt = F({
|
|
96
96
|
geom: "bar",
|
|
97
97
|
coord: "cartesian",
|
|
98
98
|
draw: (e, { layer: t, coordSystem: o, panel: n, colorScheme: s }) => {
|
|
99
|
-
const { Path2D: r } = X(), i = P({ colorScheme: s }).geomReaders(t), l = o.mainAxis,
|
|
99
|
+
const { Path2D: r } = X(), i = P({ colorScheme: s }).geomReaders(t), l = o.mainAxis, c = /* @__PURE__ */ new Map();
|
|
100
100
|
for (const a of t.data) {
|
|
101
|
-
const
|
|
102
|
-
if (!
|
|
103
|
-
const u = C(n,
|
|
101
|
+
const d = ut(l, a);
|
|
102
|
+
if (!d) continue;
|
|
103
|
+
const u = C(n, d.x), f = n.y + d.y * n.height, h = {
|
|
104
104
|
x: u,
|
|
105
105
|
y: f,
|
|
106
|
-
width:
|
|
107
|
-
height:
|
|
106
|
+
width: d.width * n.width,
|
|
107
|
+
height: d.height * n.height,
|
|
108
108
|
fill: i.get("color", a),
|
|
109
109
|
opacity: i.get("alpha", a)
|
|
110
|
-
}, g = ht(l,
|
|
111
|
-
A ? A.bars.push(h) :
|
|
110
|
+
}, g = ht(l, d), A = c.get(g);
|
|
111
|
+
A ? A.bars.push(h) : c.set(g, {
|
|
112
112
|
bars: [h],
|
|
113
113
|
style: {
|
|
114
114
|
borderColor: i.get("borderColor", a),
|
|
@@ -118,8 +118,8 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
-
for (const { bars: a, style:
|
|
122
|
-
const { borderColor: u, borderRadius: f, borderWidth: h, borderAlpha: g } =
|
|
121
|
+
for (const { bars: a, style: d } of c.values()) {
|
|
122
|
+
const { borderColor: u, borderRadius: f, borderWidth: h, borderAlpha: g } = d, A = ve(h), p = f === "full" ? void 0 : $({ borderRadius: f, mainAxis: l });
|
|
123
123
|
if (!(a.length > 1)) {
|
|
124
124
|
const [m] = a;
|
|
125
125
|
if (!m) continue;
|
|
@@ -137,12 +137,12 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
137
137
|
}), pe = (e, t) => {
|
|
138
138
|
const o = /^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(e.trim());
|
|
139
139
|
if (o?.[1] !== void 0) {
|
|
140
|
-
const s = o[1], r = s.length === 3 ? [...s].map((a) => a + a).join("") : s.slice(0, 6), i = Number.parseInt(r.slice(0, 2), 16), l = Number.parseInt(r.slice(2, 4), 16),
|
|
141
|
-
return `rgba(${i}, ${l}, ${
|
|
140
|
+
const s = o[1], r = s.length === 3 ? [...s].map((a) => a + a).join("") : s.slice(0, 6), i = Number.parseInt(r.slice(0, 2), 16), l = Number.parseInt(r.slice(2, 4), 16), c = Number.parseInt(r.slice(4, 6), 16);
|
|
141
|
+
return `rgba(${i}, ${l}, ${c}, ${t})`;
|
|
142
142
|
}
|
|
143
143
|
const n = /^rgba?\(([^)]+)\)$/i.exec(e.trim());
|
|
144
144
|
if (n?.[1] !== void 0) {
|
|
145
|
-
const s = n[1].split(",").map((
|
|
145
|
+
const s = n[1].split(",").map((c) => c.trim()), [r, i, l] = s;
|
|
146
146
|
if (r !== void 0 && i !== void 0 && l !== void 0)
|
|
147
147
|
return `rgba(${r}, ${i}, ${l}, ${t})`;
|
|
148
148
|
}
|
|
@@ -150,22 +150,22 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
150
150
|
}, qt = (e, t) => t !== "connect" ? e : e.filter((o) => v(o) !== null && B(o) !== null), jt = (e, t) => {
|
|
151
151
|
const { seriesObservations: o, fillGenerator: n, panel: s, color: r, fillAlpha: i } = t, l = o.map((a) => B(a)).filter((a) => a !== null).map((a) => _(s, a));
|
|
152
152
|
if (l.length === 0) return;
|
|
153
|
-
const
|
|
154
|
-
|
|
153
|
+
const c = e.createLinearGradient(0, Math.min(...l), 0, s.y + s.height);
|
|
154
|
+
c.addColorStop(0, r), c.addColorStop(0.7, pe(r, 0)), c.addColorStop(1, pe(r, 0)), e.save(), e.globalAlpha = i, e.fillStyle = c, e.beginPath(), n.context(e)(o), e.fill(), e.restore();
|
|
155
155
|
}, Qt = F({
|
|
156
156
|
geom: "line",
|
|
157
157
|
coord: "cartesian",
|
|
158
158
|
draw: (e, { layer: t, panel: o, colorScheme: n }) => {
|
|
159
159
|
const s = P({ colorScheme: n }).geomReaders(t), r = we().x((l) => C(o, v(l) ?? 0)).y((l) => _(o, B(l) ?? 0)).curve(ne(t.params.interpolate)), i = Re().x((l) => C(o, v(l) ?? 0)).y0(o.y + o.height).y1((l) => _(o, B(l) ?? 0)).curve(ne(t.params.interpolate));
|
|
160
160
|
if (t.params.missingValues === "gap") {
|
|
161
|
-
const l = (
|
|
161
|
+
const l = (c) => v(c) !== null && B(c) !== null;
|
|
162
162
|
r.defined(l), i.defined(l);
|
|
163
163
|
}
|
|
164
164
|
t.data.groupBy(Be.group).forEach((l) => {
|
|
165
|
-
const
|
|
165
|
+
const c = qt([...l], t.params.missingValues), a = c[0];
|
|
166
166
|
if (!a) return;
|
|
167
|
-
const
|
|
168
|
-
h !== void 0 && jt(e, { seriesObservations:
|
|
167
|
+
const d = s.get("strokeWidth", a), u = Ie(s.get("lineType", a)), f = s.get("color", a), h = s.get("fillAlpha", a);
|
|
168
|
+
h !== void 0 && jt(e, { seriesObservations: c, fillGenerator: i, panel: o, color: f, fillAlpha: h }), e.save(), e.globalAlpha = s.get("alpha", a), e.strokeStyle = f, e.lineWidth = d, e.setLineDash(u), e.lineJoin = "round", e.lineCap = "round", e.beginPath(), r.context(e)(c), e.stroke(), e.restore();
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
}), Zt = F({
|
|
@@ -176,8 +176,8 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
176
176
|
for (const r of t.data) {
|
|
177
177
|
const i = v(r), l = B(r);
|
|
178
178
|
if (i === null || l === null) continue;
|
|
179
|
-
const
|
|
180
|
-
e.save(), e.globalAlpha = s.get("alpha", r), e.fillStyle = s.get("color", r), e.strokeStyle = s.get("borderColor", r), e.lineWidth = u, e.beginPath(), e.arc(
|
|
179
|
+
const c = C(o, i), a = _(o, l), d = s.get("size", r) / 2, u = s.get("borderWidth", r);
|
|
180
|
+
e.save(), e.globalAlpha = s.get("alpha", r), e.fillStyle = s.get("color", r), e.strokeStyle = s.get("borderColor", r), e.lineWidth = u, e.beginPath(), e.arc(c, a, d, 0, Math.PI * 2), e.fill(), u > 0 && e.stroke(), e.restore();
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
}), le = 11, Jt = "sans-serif", $t = 500, D = 5, Pe = 5, re = 13, ke = 6, Y = 12, Ae = 21.6, xt = (e, t) => {
|
|
@@ -192,25 +192,25 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
192
192
|
const i = Math.min(r, n / 2, s / 2);
|
|
193
193
|
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 + s - i), e.arcTo(t + n, o + s, t + n - i, o + s, i), e.lineTo(t + i, o + s), e.arcTo(t, o + s, t, o + s - i, i), e.lineTo(t, o + i), e.arcTo(t, o, t + i, o, i), e.closePath(), e.fill();
|
|
194
194
|
}, no = (e, t, o, n, s, r, i, l) => {
|
|
195
|
-
const
|
|
196
|
-
e.save(), e.translate(u, f), e.translate(0, -a / 2), e.fillStyle = i, De(e, h, 0,
|
|
195
|
+
const c = o + D * 2, a = le + Pe * 2, d = n === "start", u = d ? r.x : r.x + r.width, f = _(r, s), h = d ? -re : -(c - re), g = d ? h + c - D : h + D - Y;
|
|
196
|
+
e.save(), e.translate(u, f), e.translate(0, -a / 2), e.fillStyle = i, De(e, h, 0, c, a, ke), e.save(), d || (e.translate(g + Y / 2, a / 2), e.rotate(Math.PI), e.translate(-(g + Y / 2), -a / 2)), e.translate(g, (a - Ae) / 2), e.scale(Y / 10, Ae / 18), e.fillStyle = i, oo(e), e.fill(), e.restore(), e.fillStyle = l, e.textAlign = "left", e.textBaseline = "middle", e.fillText(t, h + D, a / 2), e.restore();
|
|
197
197
|
}, ro = (e, t, o, n, s, r, i, l) => {
|
|
198
|
-
const
|
|
199
|
-
e.save(), e.translate(u, f), e.translate(-
|
|
198
|
+
const c = o + D * 2, a = le + Pe * 2, d = n === "start", u = C(r, s), f = d ? r.y + r.height : r.y, h = d ? -re : -8;
|
|
199
|
+
e.save(), e.translate(u, f), e.translate(-c / 2, 0), e.fillStyle = i, De(e, 0, h, c, a, ke), e.fillStyle = l, e.textAlign = "left", e.textBaseline = "middle", e.fillText(t, D, h + a / 2), e.restore();
|
|
200
200
|
}, so = F({
|
|
201
201
|
geom: "rule",
|
|
202
202
|
coord: "cartesian",
|
|
203
203
|
draw: (e, { layer: t, coordSystem: o, panel: n, compiled: s, textMeasurer: r, formattingLocale: i, colorScheme: l }) => {
|
|
204
|
-
const
|
|
205
|
-
if (!
|
|
206
|
-
const a = xt(t, o),
|
|
207
|
-
if (
|
|
208
|
-
const u = P({ colorScheme: l }).geomReaders(t), f = u.get("color",
|
|
209
|
-
if (e.save(), e.strokeStyle = f, e.lineWidth = g, eo(e, u.get("lineType",
|
|
210
|
-
const T = _(n,
|
|
204
|
+
const c = t.data.getFirst();
|
|
205
|
+
if (!c) return;
|
|
206
|
+
const a = xt(t, o), d = a ? B(c) : v(c);
|
|
207
|
+
if (d === null) return;
|
|
208
|
+
const u = P({ colorScheme: l }).geomReaders(t), f = u.get("color", c), h = pt(f), g = u.get("strokeWidth", c);
|
|
209
|
+
if (e.save(), e.strokeStyle = f, e.lineWidth = g, eo(e, u.get("lineType", c), g), e.beginPath(), a) {
|
|
210
|
+
const T = _(n, d);
|
|
211
211
|
e.moveTo(n.x, T), e.lineTo(n.x + n.width, T);
|
|
212
212
|
} else {
|
|
213
|
-
const T = C(n,
|
|
213
|
+
const T = C(n, d);
|
|
214
214
|
e.moveTo(T, n.y), e.lineTo(T, n.y + n.height);
|
|
215
215
|
}
|
|
216
216
|
e.stroke(), e.restore();
|
|
@@ -231,7 +231,7 @@ const _e = (e) => `${e.family}|${e.weight ?? 400}|${e.style ?? "normal"}`, Ce =
|
|
|
231
231
|
};
|
|
232
232
|
e.font = R(b);
|
|
233
233
|
const y = r.measureText(A, b).width;
|
|
234
|
-
(a ? no : ro)(e, A, y, t.params.labelPosition,
|
|
234
|
+
(a ? no : ro)(e, A, y, t.params.labelPosition, d, n, f, h);
|
|
235
235
|
}
|
|
236
236
|
}), M = at();
|
|
237
237
|
M.digits(8);
|
|
@@ -239,9 +239,9 @@ const io = F({
|
|
|
239
239
|
geom: "bar",
|
|
240
240
|
coord: "polar",
|
|
241
241
|
draw: (e, { layer: t, coordSystem: o, panel: n, colorScheme: s }) => {
|
|
242
|
-
const r = n.x + n.width / 2, i = n.y + n.height / 2, l = Math.min(n.width, n.height) / 2, { Path2D:
|
|
242
|
+
const r = n.x + n.width / 2, i = n.y + n.height / 2, l = Math.min(n.width, n.height) / 2, { Path2D: c } = X(), a = P({ colorScheme: s }).geomReaders(t);
|
|
243
243
|
e.save(), e.translate(r, i), e.scale(l, l);
|
|
244
|
-
const
|
|
244
|
+
const d = e, u = /* @__PURE__ */ new Map();
|
|
245
245
|
for (const f of t.data) {
|
|
246
246
|
const { startAngle: h, endAngle: g } = bt(f), { innerRadius: A, outerRadius: p } = yt(f);
|
|
247
247
|
if (h === null || g === null || A === null || p === null) continue;
|
|
@@ -267,9 +267,9 @@ const io = F({
|
|
|
267
267
|
const { borderColor: g, borderRadius: A, borderWidth: p, borderAlpha: b } = h, y = ve(p), S = g !== void 0 && l > 0, T = St(f), m = Et(A, T.outerRadius - T.innerRadius), w = l > 0 && (S || m > 0);
|
|
268
268
|
e.save();
|
|
269
269
|
let L;
|
|
270
|
-
w && (L = new
|
|
270
|
+
w && (L = new c(), M.cornerRadius(m), M.context(L)(T), e.clip(L)), M.cornerRadius(0);
|
|
271
271
|
for (const k of f)
|
|
272
|
-
e.globalAlpha = k.opacity, e.fillStyle = k.fill, e.beginPath(), M.context(
|
|
272
|
+
e.globalAlpha = k.opacity, e.fillStyle = k.fill, e.beginPath(), M.context(d)(k), e.fill(), S && (e.strokeStyle = g, e.lineWidth = y.separatorWidth / l, e.stroke());
|
|
273
273
|
S && L && (e.globalAlpha = b, e.strokeStyle = g, e.lineWidth = y.outlineWidth / l, e.stroke(L)), e.restore();
|
|
274
274
|
}
|
|
275
275
|
e.restore();
|
|
@@ -330,31 +330,31 @@ const Fe = () => (be ??= Lt(), be), He = [
|
|
|
330
330
|
return I("Chart config is missing a valid `data` object (columns + rows).");
|
|
331
331
|
const { data: t, ...o } = e;
|
|
332
332
|
return { ok: !0, input: o, data: t };
|
|
333
|
-
}, mo = (e) => {
|
|
334
|
-
const
|
|
335
|
-
if (!
|
|
333
|
+
}, mo = (e, t = {}) => {
|
|
334
|
+
const o = go(e);
|
|
335
|
+
if (!o.ok) return o;
|
|
336
336
|
if (ho(e))
|
|
337
337
|
return I(
|
|
338
338
|
"Canvas renderer does not support `_unstable_mapping`, `referenceLines.trendline`, or `referenceLines.averageLine`."
|
|
339
339
|
);
|
|
340
|
-
const
|
|
341
|
-
if (!fo.has(
|
|
342
|
-
return I(`Unsupported chart type for canvas rendering: ${
|
|
340
|
+
const n = o.input.type ?? "column";
|
|
341
|
+
if (!fo.has(n))
|
|
342
|
+
return I(`Unsupported chart type for canvas rendering: ${n}.`);
|
|
343
343
|
try {
|
|
344
|
-
const
|
|
345
|
-
if (!
|
|
344
|
+
const s = Fe(), r = rt(o.input, o.data), i = s.compile({ input: r, data: o.data, colorScheme: t.colorScheme });
|
|
345
|
+
if (!i.ok)
|
|
346
346
|
return I(
|
|
347
|
-
`Chart config failed to compile: ${
|
|
347
|
+
`Chart config failed to compile: ${i.errors.map((l) => l.message).join("; ")}`
|
|
348
348
|
);
|
|
349
|
-
for (const
|
|
350
|
-
if (Oe(
|
|
351
|
-
return I(`No canvas geom renderer for ${
|
|
352
|
-
return { ok: !0, compiled:
|
|
353
|
-
} catch (
|
|
354
|
-
const
|
|
355
|
-
return I(`Chart config failed to compile: ${
|
|
356
|
-
}
|
|
357
|
-
}, Me = E, W = 12,
|
|
349
|
+
for (const l of i.compiled.layers)
|
|
350
|
+
if (Oe(l, i.compiled.coordSystem) === null)
|
|
351
|
+
return I(`No canvas geom renderer for ${l.geom} (${i.compiled.coordSystem.type} coord).`);
|
|
352
|
+
return { ok: !0, compiled: i.compiled };
|
|
353
|
+
} catch (s) {
|
|
354
|
+
const r = s instanceof Error ? s.message : String(s);
|
|
355
|
+
return I(`Chart config failed to compile: ${r}`);
|
|
356
|
+
}
|
|
357
|
+
}, Me = E, W = 12, ce = 1.3, V = 10, K = 12, O = 6, Ge = 16, po = 24, Ue = 6, We = 3, se = 4, Ao = 8, bo = "#9ca3af", Ve = 16, yo = 1.3, Ke = 13, To = 1.4, ze = 12, So = 1.4, J = 8, de = 12, Eo = 1.3, Lo = 200, Ro = 120, wo = 80, Xe = 22, Bo = 9, vo = 11, _o = 10, j = 9, ye = 12, Co = '-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif', No = 11.5, Io = 550, Po = { light: 0.55, mid: 0.75, dark: 0.08 }, ko = { light: 0.62, mid: 0.8, dark: 0.85 }, Do = 0.22, Oo = 0.65, Fo = { family: Me, size: W }, Ho = [2, 3], Mo = [1, 3], ie = (e) => {
|
|
358
358
|
switch (e) {
|
|
359
359
|
case "dashed":
|
|
360
360
|
return Ho;
|
|
@@ -368,11 +368,11 @@ const Fe = () => (be ??= Lt(), be), He = [
|
|
|
368
368
|
const i = t.position === "bottom" || t.position === "top";
|
|
369
369
|
e.save(), e.font = R(z(s, E)), e.fillStyle = s.textColor, e.strokeStyle = r.color, e.lineWidth = r.strokeWidth, e.setLineDash(ie(r.lineType));
|
|
370
370
|
for (const l of t.ticks) {
|
|
371
|
-
const
|
|
372
|
-
t.ticksVisible && Wo(e, t.position,
|
|
371
|
+
const c = i ? l.position : 1 - l.position;
|
|
372
|
+
t.ticksVisible && Wo(e, t.position, c, o, n, r.length), Ko(
|
|
373
373
|
e,
|
|
374
374
|
t.position,
|
|
375
|
-
|
|
375
|
+
c,
|
|
376
376
|
o,
|
|
377
377
|
n,
|
|
378
378
|
l.formattedLabel,
|
|
@@ -383,14 +383,14 @@ const Fe = () => (be ??= Lt(), be), He = [
|
|
|
383
383
|
e.restore();
|
|
384
384
|
}, Uo = (e, t, o, n, s) => {
|
|
385
385
|
if (e === "bottom" || e === "top") {
|
|
386
|
-
const
|
|
387
|
-
return { x1:
|
|
386
|
+
const c = n.x + t * n.width, a = e === "top" ? o.y + o.height : o.y, d = e === "top" ? -s : s;
|
|
387
|
+
return { x1: c, y1: a, x2: c, y2: a + d };
|
|
388
388
|
}
|
|
389
389
|
const r = n.y + t * n.height, i = e === "right" ? o.x : o.x + o.width, l = e === "right" ? s : -s;
|
|
390
390
|
return { x1: i, y1: r, x2: i + l, y2: r };
|
|
391
391
|
}, Wo = (e, t, o, n, s, r) => {
|
|
392
|
-
const { x1: i, y1: l, x2:
|
|
393
|
-
e.beginPath(), e.moveTo(i, l), e.lineTo(
|
|
392
|
+
const { x1: i, y1: l, x2: c, y2: a } = Uo(t, o, n, s, r);
|
|
393
|
+
e.beginPath(), e.moveTo(i, l), e.lineTo(c, a), e.stroke();
|
|
394
394
|
}, Vo = (e, t, o, n, s) => {
|
|
395
395
|
if (e === "bottom" || e === "top") {
|
|
396
396
|
const i = n.x + t * n.width;
|
|
@@ -400,12 +400,12 @@ const Fe = () => (be ??= Lt(), be), He = [
|
|
|
400
400
|
return e === "left" ? { x: o.x + o.width - s, y: r, textAlign: "right", textBaseline: "middle" } : { x: o.x + s, y: r, textAlign: "left", textBaseline: "middle" };
|
|
401
401
|
}, Ko = (e, t, o, n, s, r, i, l) => {
|
|
402
402
|
if (i !== 0 && (t === "top" || t === "bottom")) {
|
|
403
|
-
const a = s.x + o * s.width,
|
|
404
|
-
e.save(), e.translate(a,
|
|
403
|
+
const a = s.x + o * s.width, d = t === "top";
|
|
404
|
+
e.save(), e.translate(a, d ? n.y + n.height - l : n.y + l), e.rotate(i * Math.PI / 180), e.textAlign = d ? "left" : "right", e.textBaseline = "middle", e.fillText(r, 0, 0), e.restore();
|
|
405
405
|
return;
|
|
406
406
|
}
|
|
407
|
-
const
|
|
408
|
-
e.textAlign =
|
|
407
|
+
const c = Vo(t, o, n, s, l);
|
|
408
|
+
e.textAlign = c.textAlign, e.textBaseline = c.textBaseline, e.fillText(r, c.x, c.y);
|
|
409
409
|
}, zo = (e, t, o, n) => {
|
|
410
410
|
if (!t.isVisible || !t.label) return;
|
|
411
411
|
e.save(), e.font = R({
|
|
@@ -433,17 +433,17 @@ const qo = () => {
|
|
|
433
433
|
if (t.placement !== r) return;
|
|
434
434
|
const i = Ye(t.enabled, s, t.variant);
|
|
435
435
|
if (i === "hidden") return;
|
|
436
|
-
const l = jo(n.background),
|
|
436
|
+
const l = jo(n.background), c = l === "dark", a = { family: Co, size: No, weight: 400 }, d = { ...a, weight: Io };
|
|
437
437
|
let u = 0;
|
|
438
|
-
i === "full" && (e.font = R(a), u = e.measureText("Made with ").width, e.font = R(
|
|
438
|
+
i === "full" && (e.font = R(a), u = e.measureText("Made with ").width, e.font = R(d), u += e.measureText("Graphy").width);
|
|
439
439
|
const f = i === "mini" ? 0 : Bo, h = i === "mini" ? 0 : vo, g = i === "mini" ? 0 : _o, A = i === "mini" ? N : f + j + g + u + h, p = o.x + o.width - A, b = o.y + Math.max(0, (o.height || N) / 2 - N / 2);
|
|
440
|
-
e.save(), e.globalAlpha = ko[l], e.textBaseline = "middle", e.textAlign = "left",
|
|
441
|
-
const y =
|
|
442
|
-
if (e.save(),
|
|
440
|
+
e.save(), e.globalAlpha = ko[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(p, b, A, N, N / 2), e.fillStyle = `rgba(255, 255, 255, ${Po[l]})`, e.fill(), e.shadowColor = "transparent", e.shadowBlur = 0, e.shadowOffsetY = 0;
|
|
441
|
+
const y = c ? "#FFFFFF" : "#2A2A28", S = i === "mini" ? p + (A - j) / 2 : p + f, T = b + (N - ye) / 2;
|
|
442
|
+
if (e.save(), c && (e.filter = "invert(1)"), e.drawImage(qo(), S, T, j, ye), e.restore(), i === "full") {
|
|
443
443
|
const m = p + f + j + g, w = b + N / 2;
|
|
444
444
|
e.fillStyle = y, e.font = R(a), e.fillText("Made with ", m, w);
|
|
445
445
|
const L = e.measureText("Made with ").width;
|
|
446
|
-
e.font = R(
|
|
446
|
+
e.font = R(d), e.fillText("Graphy", m + L, w);
|
|
447
447
|
}
|
|
448
448
|
e.restore();
|
|
449
449
|
}, Qo = (e) => {
|
|
@@ -469,7 +469,7 @@ const qo = () => {
|
|
|
469
469
|
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
470
470
|
};
|
|
471
471
|
return 0.2126 * n(e) + 0.7152 * n(t) + 0.0722 * n(o);
|
|
472
|
-
}, Jo = { family: E, size: Ve, weight: 600 }, $o = { family: E, size: Ke }, xo = { family: E, size: ze }, en = { family: E, size:
|
|
472
|
+
}, Jo = { family: E, size: Ve, weight: 600 }, $o = { family: E, size: Ke }, xo = { family: E, size: ze }, en = { family: E, size: de, weight: 500 }, tn = { family: E, size: de }, je = Ve * yo, on = Ke * To, Qe = ze * So, Ze = de * Eo, Je = (e) => {
|
|
473
473
|
if (e === null) return null;
|
|
474
474
|
if (e.label !== void 0 && e.label !== "") return e.label;
|
|
475
475
|
if (e.url !== void 0 && e.url !== "" && Rt(e.url))
|
|
@@ -485,9 +485,9 @@ const qo = () => {
|
|
|
485
485
|
n && (o += je), s && (o > 0 && (o += J), o += on);
|
|
486
486
|
const r = ae(e.brandMark, t, "header");
|
|
487
487
|
!n && !s && r > 0 && (o = r);
|
|
488
|
-
const i = e.isCaptionVisible && e.caption !== null, l = e.isSourceVisible && Je(e.source) !== null,
|
|
488
|
+
const i = e.isCaptionVisible && e.caption !== null, l = e.isSourceVisible && Je(e.source) !== null, c = ae(e.brandMark, t, "footer");
|
|
489
489
|
let a = 0;
|
|
490
|
-
return i && (a += Qe), (l ||
|
|
490
|
+
return i && (a += Qe), (l || c > 0) && (a > 0 && (a += J), a += Math.max(Ze, c)), { headerHeight: o, footerHeight: a };
|
|
491
491
|
}, rn = (e, t, o, n, s) => {
|
|
492
492
|
if (o.height === 0) return;
|
|
493
493
|
e.save(), e.textBaseline = "top", e.textAlign = "left";
|
|
@@ -498,15 +498,15 @@ const qo = () => {
|
|
|
498
498
|
const r = t.isCaptionVisible ? t.caption : null, i = t.isSourceVisible ? Je(t.source) : null, l = ae(t.brandMark, s, "footer");
|
|
499
499
|
if (r === null && i === null && l === 0) return;
|
|
500
500
|
e.save(), e.textBaseline = "top", e.textAlign = "left";
|
|
501
|
-
let
|
|
502
|
-
if (r !== null && (e.font = R(xo), e.fillStyle = n.textSecondary, e.fillText(te(r), o.x,
|
|
501
|
+
let c = o.y;
|
|
502
|
+
if (r !== null && (e.font = R(xo), e.fillStyle = n.textSecondary, e.fillText(te(r), o.x, c), c += Qe + J), i !== null) {
|
|
503
503
|
let a = o.x;
|
|
504
|
-
a = Te(e, "Source: ", en, n.textSecondary, a,
|
|
504
|
+
a = Te(e, "Source: ", en, n.textSecondary, a, c), Te(e, i, tn, n.textSecondary, a, c);
|
|
505
505
|
}
|
|
506
506
|
e.restore(), qe(
|
|
507
507
|
e,
|
|
508
508
|
t.brandMark,
|
|
509
|
-
{ x: o.x, y:
|
|
509
|
+
{ x: o.x, y: c, width: o.width, height: Math.max(Ze, l) },
|
|
510
510
|
n,
|
|
511
511
|
s,
|
|
512
512
|
"footer"
|
|
@@ -521,12 +521,12 @@ const qo = () => {
|
|
|
521
521
|
e.strokeStyle = i.color, e.lineWidth = i.strokeWidth, e.setLineDash(ie(i.lineType));
|
|
522
522
|
for (const l of s.ticks) {
|
|
523
523
|
if (l.position <= 0 || l.position >= 1) continue;
|
|
524
|
-
const
|
|
524
|
+
const c = r ? l.position : 1 - l.position;
|
|
525
525
|
if (e.beginPath(), r) {
|
|
526
|
-
const a = n.x +
|
|
526
|
+
const a = n.x + c * n.width;
|
|
527
527
|
e.moveTo(a, n.y), e.lineTo(a, n.y + n.height);
|
|
528
528
|
} else {
|
|
529
|
-
const a = n.y +
|
|
529
|
+
const a = n.y + c * n.height;
|
|
530
530
|
e.moveTo(n.x, a), e.lineTo(n.x + n.width, a);
|
|
531
531
|
}
|
|
532
532
|
e.stroke();
|
|
@@ -550,10 +550,10 @@ const qo = () => {
|
|
|
550
550
|
e.closePath();
|
|
551
551
|
break;
|
|
552
552
|
}
|
|
553
|
-
},
|
|
553
|
+
}, cn = (e, t, o, n) => {
|
|
554
554
|
e.save(), e.font = R(Fo), e.textBaseline = "middle";
|
|
555
555
|
for (const r of t)
|
|
556
|
-
r.display === "direct" &&
|
|
556
|
+
r.display === "direct" && dn(e, r, o, n);
|
|
557
557
|
const s = /* @__PURE__ */ new Map();
|
|
558
558
|
for (const r of t) {
|
|
559
559
|
if (r.display !== "pill" || r.items.length === 0) continue;
|
|
@@ -565,7 +565,7 @@ const qo = () => {
|
|
|
565
565
|
l && (r === "top" || r === "bottom" ? fn(e, i, l, n) : un(e, i, l, n));
|
|
566
566
|
}
|
|
567
567
|
e.restore();
|
|
568
|
-
},
|
|
568
|
+
}, dn = (e, t, o, n) => {
|
|
569
569
|
const s = o[t.position];
|
|
570
570
|
if (s) {
|
|
571
571
|
e.textAlign = "left";
|
|
@@ -574,20 +574,20 @@ const qo = () => {
|
|
|
574
574
|
}
|
|
575
575
|
}, fn = (e, t, o, n) => {
|
|
576
576
|
const s = $e(t), r = s.reduce(
|
|
577
|
-
(a,
|
|
577
|
+
(a, d, u) => a + gn(d) + e.measureText(d.label).width + (u === 0 ? 0 : Se(d)),
|
|
578
578
|
0
|
|
579
|
-
), i = W *
|
|
579
|
+
), i = W * ce;
|
|
580
580
|
let l = o.x + Math.max(0, (o.width - r) / 2);
|
|
581
|
-
const
|
|
581
|
+
const c = o.y + Ue + Math.max(i, K) / 2;
|
|
582
582
|
for (let a = 0; a < s.length; a++) {
|
|
583
|
-
const
|
|
584
|
-
|
|
583
|
+
const d = s[a];
|
|
584
|
+
d && (a > 0 && (l += Se(d)), l = xe(e, d, l, c, n));
|
|
585
585
|
}
|
|
586
586
|
}, un = (e, t, o, n) => {
|
|
587
|
-
const s = $e(t), r = Math.max(W *
|
|
588
|
-
let
|
|
587
|
+
const s = $e(t), r = Math.max(W * ce, K), i = 4, l = s.length * r + Math.max(0, s.length - 1) * i;
|
|
588
|
+
let c = o.y + Math.max(0, (o.height - l) / 2) + r / 2;
|
|
589
589
|
for (const a of s)
|
|
590
|
-
xe(e, a, o.x,
|
|
590
|
+
xe(e, a, o.x, c, n), c += r + i;
|
|
591
591
|
}, $e = (e) => {
|
|
592
592
|
const t = [];
|
|
593
593
|
for (const o of e) {
|
|
@@ -618,8 +618,8 @@ const qo = () => {
|
|
|
618
618
|
} else if (t.colors.length > 0) {
|
|
619
619
|
const i = t.colors.slice(0, We);
|
|
620
620
|
for (let l = 0; l < i.length; l++) {
|
|
621
|
-
const
|
|
622
|
-
|
|
621
|
+
const c = i[l];
|
|
622
|
+
c && (e.fillStyle = c, e.fillRect(
|
|
623
623
|
r + l * se,
|
|
624
624
|
n - K / 2,
|
|
625
625
|
V,
|
|
@@ -631,21 +631,21 @@ const qo = () => {
|
|
|
631
631
|
return e.fillStyle = s.textPrimary, e.textAlign = "left", e.fillText(t.label, r, n), r + e.measureText(t.label).width;
|
|
632
632
|
}, Ee = (e, t) => Math.min(Math.max(...e), t), mn = (e, t, o) => (n) => {
|
|
633
633
|
if (!n.isVisible || n.ticks.length === 0) return 0;
|
|
634
|
-
const s = n.position === "top" || n.position === "bottom", r = U(n.scaleAestheticKey), { offset: i, ...l } = t[r],
|
|
634
|
+
const s = n.position === "top" || n.position === "bottom", r = U(n.scaleAestheticKey), { offset: i, ...l } = t[r], c = n.ticksVisible ? Math.max(i, o[r].length) : i, a = z(l, E), d = n.ticks.map((h) => e.measureText(h.formattedLabel, a)), u = n.labelMaxWidthPx ?? Number.POSITIVE_INFINITY;
|
|
635
635
|
if (s) {
|
|
636
636
|
if (n.labelRotation !== 0) {
|
|
637
|
-
const h =
|
|
638
|
-
return Ee(h, u) + 2 *
|
|
637
|
+
const h = d.map((g) => g.width);
|
|
638
|
+
return Ee(h, u) + 2 * c;
|
|
639
639
|
}
|
|
640
|
-
return Math.max(...
|
|
640
|
+
return Math.max(...d.map((h) => h.height)) + c;
|
|
641
641
|
}
|
|
642
|
-
const f =
|
|
643
|
-
return Ee(f, u) +
|
|
642
|
+
const f = d.map((h) => h.width);
|
|
643
|
+
return Ee(f, u) + c;
|
|
644
644
|
}, pn = (e) => (t) => {
|
|
645
645
|
if (t.items.length === 0) return 0;
|
|
646
646
|
const o = { family: Me, size: W };
|
|
647
647
|
if (t.position === "top" || t.position === "bottom") {
|
|
648
|
-
const r = W *
|
|
648
|
+
const r = W * ce;
|
|
649
649
|
return Math.max(r, K) + Ue * 2;
|
|
650
650
|
}
|
|
651
651
|
const s = t.items.map((r) => {
|
|
@@ -709,7 +709,7 @@ const Sn = {
|
|
|
709
709
|
legendPillBackground: "rgba(255, 255, 255, 0.06)",
|
|
710
710
|
legendPillBorder: "rgba(255, 255, 255, 0.12)"
|
|
711
711
|
}, Dn = async ({ input: e, data: t }, o) => {
|
|
712
|
-
const s = Fe().compile({ input: e, data: t });
|
|
712
|
+
const s = Fe().compile({ input: e, data: t, colorScheme: o.colorScheme });
|
|
713
713
|
if (!s.ok)
|
|
714
714
|
throw new Error(
|
|
715
715
|
`Failed to compile graph spec: ${s.errors.map((r) => r.message).join("; ")}`
|
|
@@ -727,12 +727,12 @@ const Sn = {
|
|
|
727
727
|
}), s = { width: t.width, height: t.height }, { headerHeight: r, footerHeight: i } = nn(e.config.content, s), l = {
|
|
728
728
|
headerSize: { width: t.width, height: r },
|
|
729
729
|
footerSize: { width: t.width, height: i }
|
|
730
|
-
},
|
|
731
|
-
x: fe(a, "x",
|
|
732
|
-
y: fe(a, "y",
|
|
730
|
+
}, c = t.colorScheme ?? "light", a = P({ colorScheme: c }).chromeReaders(e.chrome), d = e.config.appearance.textScale, u = {
|
|
731
|
+
x: fe(a, "x", d),
|
|
732
|
+
y: fe(a, "y", d)
|
|
733
733
|
}, f = {
|
|
734
|
-
x: ue(a, "x",
|
|
735
|
-
y: ue(a, "y",
|
|
734
|
+
x: ue(a, "x", d),
|
|
735
|
+
y: ue(a, "y", d)
|
|
736
736
|
}, h = {
|
|
737
737
|
x: he(a, "x"),
|
|
738
738
|
y: he(a, "y")
|
|
@@ -740,7 +740,7 @@ const Sn = {
|
|
|
740
740
|
for (const w of Nt) {
|
|
741
741
|
const L = {};
|
|
742
742
|
for (const k of It)
|
|
743
|
-
L[k] = Pt(a, w, k,
|
|
743
|
+
L[k] = Pt(a, w, k, d);
|
|
744
744
|
g[w] = L;
|
|
745
745
|
}
|
|
746
746
|
const A = new Tn(), p = yn({
|
|
@@ -761,8 +761,8 @@ const Sn = {
|
|
|
761
761
|
}), S = t.pixelRatio ?? 2, T = new o(t.width * S, t.height * S), m = T.getContext("2d");
|
|
762
762
|
return m.scale(S, S), Ln({
|
|
763
763
|
ctx: m,
|
|
764
|
-
theme:
|
|
765
|
-
colorScheme:
|
|
764
|
+
theme: c === "dark" ? En : Sn,
|
|
765
|
+
colorScheme: c,
|
|
766
766
|
chromeReaders: a,
|
|
767
767
|
axisLabelStyles: u,
|
|
768
768
|
tickLabelStyles: f,
|
|
@@ -785,15 +785,15 @@ const Sn = {
|
|
|
785
785
|
tickLabelStyles: r,
|
|
786
786
|
tickLineStyles: i,
|
|
787
787
|
width: l,
|
|
788
|
-
height:
|
|
788
|
+
height: c,
|
|
789
789
|
compiled: a,
|
|
790
|
-
formattedAxes:
|
|
790
|
+
formattedAxes: d,
|
|
791
791
|
formattedLegends: u,
|
|
792
792
|
layout: f,
|
|
793
793
|
textMeasurer: h,
|
|
794
794
|
formattingLocale: g
|
|
795
795
|
}) => {
|
|
796
|
-
e.fillStyle = t.background, e.fillRect(0, 0, l,
|
|
796
|
+
e.fillStyle = t.background, e.fillRect(0, 0, l, c), an(e, d, n, f.panel), e.save(), e.beginPath(), e.rect(f.panel.x, f.panel.y, f.panel.width, f.panel.height), e.clip();
|
|
797
797
|
const A = {
|
|
798
798
|
coordSystem: a.coordSystem,
|
|
799
799
|
panel: f.panel,
|
|
@@ -808,7 +808,7 @@ const Sn = {
|
|
|
808
808
|
b && lo(b, e, { ...A, layer: p });
|
|
809
809
|
}
|
|
810
810
|
e.restore();
|
|
811
|
-
for (const p of
|
|
811
|
+
for (const p of d) {
|
|
812
812
|
const b = f.axes[p.position];
|
|
813
813
|
if (b) {
|
|
814
814
|
const y = U(p.scaleAestheticKey);
|
|
@@ -819,7 +819,7 @@ const Sn = {
|
|
|
819
819
|
const b = f.axisLabels[p.position];
|
|
820
820
|
b && zo(e, p, b, s[U(p.scaleAestheticKey)]);
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
cn(e, u, f.legends, t), rn(e, a.config.content, f.header, t, { width: l, height: c }), sn(e, a.config.content, f.footer, t, { width: l, height: c });
|
|
823
823
|
};
|
|
824
824
|
class Rn extends Error {
|
|
825
825
|
constructor(t) {
|
|
@@ -827,7 +827,7 @@ class Rn extends Error {
|
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
829
|
const On = async (e, t) => {
|
|
830
|
-
const o = mo(e);
|
|
830
|
+
const o = mo(e, { colorScheme: t.colorScheme });
|
|
831
831
|
if (!o.ok)
|
|
832
832
|
throw new Rn(o.reason);
|
|
833
833
|
return et(o.compiled, t);
|
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.1788537926468",
|
|
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.1788537926468"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-replace": "^6.0.3",
|