resolvcharts 0.3.0 → 0.4.0
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/README.md +53 -3
- package/dist/index.cjs +569 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +569 -124
- package/dist/index.mjs.map +1 -1
- package/dist/resolvcharts.global.min.js +14 -14
- package/dist/resolvcharts.global.min.js.map +1 -1
- package/package.json +14 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var ResolvCharts=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function i(e,t,n,r,i){let a=t.categories.length;if(a===0)return null;let o=e.plot.w/a,s=Math.min(o*.8,40*t.series.length),c=s/t.series.length,l=e.plot.x+o*n+(o-s)/2+c*r,u=e.yScale(0),d=e.yScale(i);return{x:l,y:Math.min(u,d),w:c,h:Math.abs(u-d)}}function a(e,t,n,r){let{x:i,y:a,w:o,h:s}=t;if(s<=0||o<=0)return;let c=Math.min(n,s/2,o/2);e.beginPath(),r?(e.moveTo(i,a+s),e.lineTo(i,a+c),e.arcTo(i,a,i+c,a,c),e.lineTo(i+o-c,a),e.arcTo(i+o,a,i+o,a+c,c),e.lineTo(i+o,a+s)):(e.moveTo(i,a),e.lineTo(i+o,a),e.lineTo(i+o,a+s-c),e.arcTo(i+o,a+s,i+o-c,a+s,c),e.lineTo(i+c,a+s),e.arcTo(i,a+s,i,a+s-c,c),e.lineTo(i,a)),e.closePath(),e.fill()}function o(e,t,n,r,i){let a=t.categories.length;if(a===0)return null;let o=e.plot.w/a,s=Math.min(o*.8,40),c=e.plot.x+o*n+(o-s)/2,l=e.yScale(Math.max(r,i)),u=e.yScale(Math.min(r,i));return{x:c,y:l,w:s,h:Math.abs(u-l)}}function s(e){if(e.data.kind!==`category`)return;let t=e.data,n=e.ctx;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let r=t.categories.length,i=e.plot.w/Math.max(1,r),o=e.t<1;if(e.opts.stacked){let a=Math.min(i*.8,40);for(let s=0;s<r;s++){let r=e.plot.x+i*s+(i-a)/2,c=0,l=0;for(let i=0;i<t.series.length;i++){let u=t.series[i];if(!u)continue;let d=u.values[s]??0,f=u.prevValues?.[s]??0,p=o?f+(d-f)*e.t:d,m=p>=0?c:l+p,h=p>=0?c+p:l;p>=0?c=h:l=m;let g=e.yScale(Math.max(m,h)),_=Math.abs(e.yScale(Math.min(m,h))-g);_<=0||(n.fillStyle=u.color,n.fillRect(r,g,a,_))}}}else{let s=Math.min(i*.8,40*t.series.length),c=s/t.series.length,l=e.yScale(0);for(let u=0;u<t.series.length;u++){let d=t.series[u];if(d){n.fillStyle=d.color;for(let t=0;t<r;t++){let r=d.values[t]??0,f=d.prevValues?.[t]??0,p=o?f+(r-f)*e.t:r,m=e.plot.x+i*t+(i-s)/2+c*u,h=e.yScale(p),g=Math.min(l,h),_=Math.abs(l-h);_<=0||a(n,{x:m,y:g,w:c,h:_},3,p>=0)}}}}n.restore()}function c(e,t,n){if(e.data.kind!==`category`)return null;let r=e.data,a=r.categories.length;if(a===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let s=Math.min(a-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*a)));if(e.opts.stacked){let i=0,a=0;for(let c=0;c<r.series.length;c++){let l=r.series[c];if(!l)continue;let u=l.values[s]??0,d=u>=0?i:a+u,f=u>=0?i+u:a;u>=0?i=f:a=d;let p=o(e,r,s,d,f);if(p&&t>=p.x&&t<=p.x+p.w&&n>=p.y&&n<=p.y+p.h)return{kind:`bar`,category:r.categories[s]??``,seriesIndex:c,label:l.label,color:l.color,value:u,px:p.x+p.w/2,py:n,rect:p}}let c=r.series[r.series.length-1];if(!c)return null;let l=o(e,r,s,0,i);return l?{kind:`bar`,category:r.categories[s]??``,seriesIndex:r.series.length-1,label:c.label,color:c.color,value:c.values[s]??0,px:l.x+l.w/2,py:l.y,rect:l}:null}for(let a=0;a<r.series.length;a++){let o=r.series[a];if(!o)continue;let c=i(e,r,s,a,o.values[s]??0);if(c&&t>=c.x&&t<=c.x+c.w){let e=n>=c.y&&n<=c.y+c.h;return{kind:`bar`,category:r.categories[s]??``,seriesIndex:a,label:o.label,color:o.color,value:o.values[s]??0,px:c.x+c.w/2,py:e?n:c.y,rect:c}}}let c=r.series[0],l=c?i(e,r,s,0,c.values[s]??0):null;return!c||!l?null:{kind:`bar`,category:r.categories[s]??``,seriesIndex:0,label:c.label,color:c.color,value:c.values[s]??0,px:e.plot.x+e.plot.w/a*(s+.5),py:l.y,rect:l}}function l(e,t){if(e.startsWith(`#`)){let n=e.slice(1);n.length===3&&(n=n.split(``).map(e=>e+e).join(``));let r=Number.parseInt(n,16);return`rgba(${r>>16&255},${r>>8&255},${r&255},${t})`}let n=e.match(/^rgba?\(([^)]+)\)$/);return n?`rgba(${n[1].split(`,`).slice(0,3).join(`,`)},${t})`:e}function u(e,t,n,r,i,a,o,s=0){let c=Math.min(e.length,t.length),l=new Float32Array(Math.max(1,c)*2),u=a.domain,d=a.range,f=(d[1]-d[0])/(u[1]-u[0]||1),p=d[0]-u[0]*f,m=o.domain,h=o.range,g=(h[1]-h[0])/(m[1]-m[0]||1),_=h[0]-m[0]*g,v=r<1,y=c>1?s/(c-1):0,b=1+s,x=0;for(let a=0;a<c;a++){let o=t[a];if(v){let e=s>0?r*b-s+a*y:r;e<0?e=0:e>1&&(e=1);let t=n?n[a]:i;o=t+(o-t)*e}l[x]=p+e[a]*f,l[x+1]=_+o*g,x+=2}return l.subarray(0,x)}let d=/* @__PURE__ */ new Float32Array;function f(e,t,n,r,i,a,o,s,c=0){let l=Math.min(e.length,t.length);if(l===0)return/* @__PURE__ */ new Float32Array;let u=Math.min(l,4*(Math.ceil(s)+8));d.length<u*2&&(d=new Float32Array(Math.max(1,u)*2));let f=d,p=a.domain,m=a.range,h=(m[1]-m[0])/(p[1]-p[0]||1),g=m[0]-p[0]*h,_=o.domain,v=o.range,y=(v[1]-v[0])/(_[1]-_[0]||1),b=v[0]-_[0]*y,x=r<1,S=l>1?c/(l-1):0,C=1+c,w=0,T=t[0];if(x){let e=c>0?r*C-c:r;e<0?e=0:e>1&&(e=1);let t=n?n[0]:i;T=t+(T-t)*e}let E=g+e[0]*h,D=b+T*y,O=Math.floor(E),k=E,A=D,j=E,M=D,N=E,P=D,F=f.length;for(let a=1;a<l;a++){let o=g+e[a]*h;if(T=t[a],x){let e=c>0?r*C-c+a*S:r;e<0?e=0:e>1&&(e=1);let t=n?n[a]:i;T=t+(T-t)*e}let s=b+T*y,l=Math.floor(o);l===O?(s<A&&(A=s,k=o),s>M&&(M=s,j=o),N=o,P=s):(w+8<=F&&(f[w]=E,f[w+1]=D,w+=2,(A!==D||k!==E)&&(f[w]=k,f[w+1]=A,w+=2),(M!==A||j!==k)&&(f[w]=j,f[w+1]=M,w+=2),(N!==j||P!==M)&&(f[w]=N,f[w+1]=P,w+=2)),O=l,E=o,D=s,k=j=N=o,A=M=P=s)}return w+8<=F&&(f[w]=E,f[w+1]=D,w+=2,(A!==D||k!==E)&&(f[w]=k,f[w+1]=A,w+=2),(M!==A||j!==k)&&(f[w]=j,f[w+1]=M,w+=2),(N!==j||P!==M)&&(f[w]=N,f[w+1]=P,w+=2)),f.subarray(0,w)}function p(e,t,n){let r=Math.min(e.length,t.length);if(r===0)return/* @__PURE__ */ new Float32Array;let i=Math.min(r,4*(Math.ceil(n)+8)),a=new Float32Array(Math.max(1,i)*2),o=0,s=Math.floor(e[0]),c=e[0],l=t[0],u=c,d=l,f=c,p=l,m=c,h=l,g=(e,t)=>{o+2<=a.length&&(a[o]=e,a[o+1]=t,o+=2)},_=()=>{g(c,l),(d!==l||u!==c)&&g(u,d),(p!==d||f!==u)&&g(f,p),(m!==f||h!==p)&&g(m,h)};for(let n=1;n<r;n++){let r=e[n],i=t[n],a=Math.floor(r);a===s?(i<d&&(d=i,u=r),i>p&&(p=i,f=r),m=r,h=i):(_(),s=a,c=r,l=i,u=f=m=r,d=p=h=i)}return _(),a.subarray(0,o)}function m(e,t){let n=e.length;if(n===0)return-1;if(t<=e[0])return 0;if(t>=e[n-1])return n-1;let r=0,i=n-1;for(;i-r>1;){let n=r+i>>1;e[n]<t?r=n:i=n}let a=Math.abs(t-e[r]);return Math.abs(t-e[i])<a?i:r}function h(e){return e.kind===`xy`}let g=/* @__PURE__ */ new Float64Array;function _(e,t,n){if(n<3){for(let r=0;r<n;r++){let n=t[2*r],i=t[2*r+1];r===0?e.moveTo(n,i):e.lineTo(n,i)}return}let r=n-1,i=r+n;g.length<i&&(g=new Float64Array(i));let a=g.subarray(0,r),o=g.subarray(r,r+n);for(let e=0;e<r;e++){let n=t[2*(e+1)]-t[2*e];a[e]=n===0?0:(t[2*(e+1)+1]-t[2*e+1])/n}o[0]=a[0];for(let e=1;e<r;e++){let t=a[e-1],n=a[e];o[e]=t*n<=0?0:(t+n)/2}o[n-1]=a[r-1];for(let e=0;e<r;e++){let t=a[e];if(t!==0){let n=o[e],r=o[e+1],i=3*Math.abs(t);Math.abs(n)>i&&(o[e]=Math.sign(n)*i),Math.abs(r)>i&&(o[e+1]=Math.sign(r)*i)}}e.moveTo(t[0],t[1]);for(let n=0;n<r;n++){let r=t[2*n],i=t[2*(n+1)],a=t[2*n+1],s=t[2*(n+1)+1],c=(i-r)/3;e.bezierCurveTo(r+c,a+c*o[n],i-c,s-c*o[n+1],i,s)}}let v=.35;function y(e,t,n){let r=e.data;if(!h(r))throw Error(`unreachable`);let i=r.sortedX.length;if(i===0)return/* @__PURE__ */ new Float32Array;let a=n??e.yScale.domain[0],o=e.opts.flow?v:0;return i>e.plot.w*1.5?f(r.sortedX,t.y,t.prevY,e.t,a,e.xScale,e.yScale,e.plot.w,o):u(r.sortedX,t.y,t.prevY,e.t,a,e.xScale,e.yScale,o)}function b(e,t,n){let r=new Path2D,i=y(e,t,n),a=i.length/2;if(a===0)return{path:r,firstX:0,lastX:0,lastY:0};let o=e.opts.curve??`linear`;if(o===`step`){r.moveTo(i[0],i[1]);for(let e=1;e<a;e++){let t=i[2*e];r.lineTo(t,i[2*e-1]),r.lineTo(t,i[2*e+1])}}else if(o===`smooth`)_(r,i,a);else{r.moveTo(i[0],i[1]);for(let e=1;e<a;e++)r.lineTo(i[2*e],i[2*e+1])}return{path:r,firstX:i[0],lastX:i[2*a-2],lastY:i[2*a-1]}}function x(e,t){if(!h(e.data))return;let n=e.data,r=e.ctx;r.save(),r.beginPath(),r.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),r.clip();for(let i of n.series){let{path:n,firstX:a,lastX:o}=b(e,i);if(t&&o!==a){let t=new Path2D(n),s=e.yScale(Math.max(0,e.yScale.domain[0]));t.lineTo(o,s),t.lineTo(a,s),t.closePath();let c=r.createLinearGradient(0,e.plot.y,0,e.plot.y+e.plot.h);c.addColorStop(0,l(i.color,.16)),c.addColorStop(1,l(i.color,0)),r.fillStyle=c,r.fill(t)}r.strokeStyle=i.color,r.lineWidth=2,r.lineJoin=`round`,r.lineCap=`round`,r.stroke(n)}r.restore()}function S(e,t){if(!h(e.data))return null;let n=e.data,r=m(n.sortedX,e.xScale.invert(t));if(r<0)return null;let i=n.sortedX[r],a=e.xScale(i),o=e.plot.y+e.plot.h,s=n.series.map(t=>{let n=t.y[r],i=e.yScale(n);return i<o&&(o=i),{label:t.label,color:t.color,y:n}});return{kind:`point`,index:r,x:i,px:a,py:o,values:s}}function C(e){if(!h(e.data))return;let t=e.data,n=t.series[0];if(!n||t.sortedX.length===0)return;let r=e.ctx,i=e.opts.baseline??n.y[0],a=Math.max(e.plot.y,Math.min(e.plot.y+e.plot.h,e.yScale(i))),{path:o,firstX:s,lastX:c}=b(e,n,i),u=new Path2D(o);u.lineTo(c,a),u.lineTo(s,a),u.closePath();let d=[{top:e.plot.y,bot:a,color:e.theme.up,gFrom:.28,gTo:.05},{top:a,bot:e.plot.y+e.plot.h,color:e.theme.down,gFrom:.05,gTo:.28}];for(let t of d){if(t.bot-t.top<=0)continue;r.save(),r.beginPath(),r.rect(e.plot.x,t.top,e.plot.w,t.bot-t.top),r.clip();let n=r.createLinearGradient(0,t.top,0,t.bot);n.addColorStop(0,l(t.color,t.gFrom)),n.addColorStop(1,l(t.color,t.gTo)),r.fillStyle=n,r.fill(u),r.strokeStyle=t.color,r.lineWidth=2,r.lineJoin=`round`,r.lineCap=`round`,r.stroke(o),r.restore()}r.strokeStyle=e.theme.axisBaseline,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath();let f=Math.round(a)+.5;r.moveTo(e.plot.x,f),r.lineTo(e.plot.x+e.plot.w,f),r.stroke(),r.setLineDash([])}function w(e,t){if(e.data.kind!==`ohlc`)return;let n=e.data,r=e.ctx,i=n.x.length;if(i===0)return;r.save(),r.beginPath(),r.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),r.clip(),r.globalAlpha=e.t>=1?1:e.t;let a=e.xScale.domain,o=e.xScale.range,s=(o[1]-o[0])/(a[1]-a[0]||1),c=o[0]-a[0]*s,u=e.yScale.domain,d=e.yScale.range,f=(d[1]-d[0])/(u[1]-u[0]||1),p=d[0]-u[0]*f,m=new Path2D,h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=new Path2D,b=n.volume?e.plot.h*.18:0,x=e.plot.y+e.plot.h,S=n.volume;if(i<=e.plot.w){let r=Math.min(e.plot.w/i*.6,14),a=r/2,o=0;if(S)for(let e=0;e<i;e++){let t=S[e];t>o&&(o=t)}let l=o>0?b/o:0;for(let e=0;e<i;e++){let i=n.close[e]>=n.open[e],o=c+n.x[e]*s,u=p+n.high[e]*f,d=p+n.low[e]*f,b=i?m:h;if(b.moveTo(o,u),b.lineTo(o,d),t){let t=p+n.open[e]*f,r=p+n.close[e]*f;b.moveTo(o-a,t),b.lineTo(o,t),b.moveTo(o,r),b.lineTo(o+a,r)}else{let t=p+n.open[e]*f,s=p+n.close[e]*f;(i?g:_).rect(o-a,Math.min(t,s),r,Math.max(1,Math.abs(s-t)))}if(S){let t=S[e];if(t>0){let e=t*l;(i?v:y).rect(o-a,x-e,r,e)}}}}else{let r=Math.min(i,Math.ceil(e.plot.w)+1),a=new Float64Array(r),o=new Float64Array(r),l=new Float64Array(r),u=new Float64Array(r),d=new Float64Array(r),C=new Float64Array(r),w=0,T=-1;for(let e=0;e<i;e++){let t=Math.floor(c+n.x[e]*s);if(t!==T){T=t;let r=w++;a[r]=t+.5,o[r]=n.open[e],l[r]=n.high[e],u[r]=n.low[e],d[r]=n.close[e],C[r]=S?S[e]:0}else{let t=w-1,r=n.high[e],i=n.low[e];r>l[t]&&(l[t]=r),i<u[t]&&(u[t]=i),d[t]=n.close[e],S&&(C[t]=C[t]+S[e])}}let E=e.plot.w/w,D=Math.max(.5,Math.min(E*.6,14)),O=D/2,k=0;if(S)for(let e=0;e<w;e++)C[e]>k&&(k=C[e]);let A=k>0?b/k:0;for(let e=0;e<w;e++){let n=a[e],r=d[e]>=o[e],i=r?m:h;if(i.moveTo(n,p+l[e]*f),i.lineTo(n,p+u[e]*f),t){let t=p+o[e]*f,r=p+d[e]*f;i.moveTo(n-O,t),i.lineTo(n,t),i.moveTo(n,r),i.lineTo(n+O,r)}else{let t=p+o[e]*f,i=p+d[e]*f;(r?g:_).rect(n-O,Math.min(t,i),D,Math.max(1,Math.abs(i-t)))}if(S){let t=C[e];if(t>0){let e=t*A;(r?v:y).rect(n-O,x-e,D,e)}}}}r.lineWidth=1,r.strokeStyle=e.theme.up,r.stroke(m),r.strokeStyle=e.theme.down,r.stroke(h),t||(r.fillStyle=e.theme.up,r.fill(g),r.fillStyle=e.theme.down,r.fill(_)),S&&(r.fillStyle=l(e.theme.up,.35),r.fill(v),r.fillStyle=l(e.theme.down,.35),r.fill(y)),r.restore()}function T(e,t){if(e.data.kind!==`ohlc`)return null;let n=e.data,r=m(n.x,e.xScale.invert(t));return r<0?null:{kind:`candle`,index:r,x:n.x[r],open:n.open[r],high:n.high[r],low:n.low[r],close:n.close[r],px:e.xScale(n.x[r]),py:e.yScale(n.close[r])}}let E=/* @__PURE__ */ new Float64Array;function D(e,t,n){let r=new Path2D;if(n===0)return r;let i=e.opts.curve??`linear`;if(i===`step`){r.moveTo(t[0],t[1]);for(let e=1;e<n;e++){let n=t[2*e];r.lineTo(n,t[2*e-1]),r.lineTo(n,t[2*e+1])}}else if(i===`smooth`)_(r,t,n);else{r.moveTo(t[0],t[1]);for(let e=1;e<n;e++)r.lineTo(t[2*e],t[2*e+1])}return r}function O(e){if(e.data.kind!==`category`)return;let t=e.data,n=e.ctx;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let r=t.categories.length,i=e.plot.w/Math.max(1,r),o=e.t<1,s=(t,n)=>{let r=t.values[n]??0,i=t.prevValues?.[n]??0;return o?i+(r-i)*e.t:r},c=0;for(let e of t.series)e.kind===`column`&&c++;if(e.opts.stacked){let a=Math.min(i*.8,40);for(let o=0;o<r;o++){let r=e.plot.x+i*o+(i-a)/2,c=0,l=0;for(let i of t.series){if(i.kind!==`column`)continue;let t=s(i,o),u=t>=0?c:l+t,d=t>=0?c+t:l;t>=0?c=d:l=u;let f=e.yScale(Math.max(u,d)),p=Math.abs(e.yScale(Math.min(u,d))-f);p<=0||(n.fillStyle=i.color,n.fillRect(r,f,a,p))}}}else{let o=Math.min(i*.8,40*c),l=o/Math.max(1,c),u=e.yScale(0),d=0;for(let c of t.series)if(c.kind===`column`){n.fillStyle=c.color;for(let t=0;t<r;t++){let r=s(c,t),f=e.plot.x+i*t+(i-o)/2+l*d,p=e.yScale(r),m=Math.min(u,p),h=Math.abs(u-p);h<=0||a(n,{x:f,y:m,w:l,h},3,r>=0)}d++}}let u=e.yScale(Math.max(0,e.yScale.domain[0]));E.length<r*2&&(E=new Float64Array(r*2));let d=E;for(let a of t.series){if(a.kind===`column`)continue;for(let t=0;t<r;t++)d[2*t]=e.plot.x+i*(t+.5),d[2*t+1]=e.yScale(s(a,t));let t=D(e,d,r);if(a.kind===`area`&&r>1){let i=new Path2D(t);i.lineTo(d[2*(r-1)],u),i.lineTo(d[0],u),i.closePath();let o=n.createLinearGradient(0,e.plot.y,0,e.plot.y+e.plot.h);o.addColorStop(0,l(a.color,.16)),o.addColorStop(1,l(a.color,0)),n.fillStyle=o,n.fill(i)}n.strokeStyle=a.color,n.lineWidth=2,n.lineJoin=`round`,n.lineCap=`round`,n.stroke(t)}n.restore()}function k(e,t){if(e.data.kind!==`category`)return null;let n=e.data,r=n.categories.length;if(r===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let i=Math.min(r-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*r))),a=e.plot.w/r,o=e.plot.y+e.plot.h,s=n.series.map(t=>{let n=t.values[i]??0,r=e.yScale(n);return r<o&&(o=r),{label:t.label,color:t.color,y:n}});return{kind:`point`,index:i,x:i,px:e.plot.x+a*(i+.5),py:o,values:s,title:n.categories[i]??``}}function A(e){return Number.isFinite(e)?String(Number.isInteger(e)&&Math.abs(e)<0x38d7ea4c68000?e:Number(e.toPrecision(4))):``}let j=[[1e9,`B`],[1e6,`M`],[1e3,`k`]];function M(e){if(!Number.isFinite(e))return``;let t=Math.abs(e);for(let[n,r]of j)if(t>=n){let t=e/n,i=t>=100||Number.isInteger(t)?0:1;return`${t.toFixed(i)}${r}`}return A(e)}let N=.015,P=-Math.PI/2;function F(e,t,n){let r=e.plot.x+e.plot.w/2,i=e.plot.y+e.plot.h/2,a=Math.max(1,Math.min(e.plot.w,e.plot.h)/2),o=a*.65,s=[],c=P,l=Math.PI*2*Math.min(1,Math.max(0,n));for(let e of t.slices){let n=t.total>0?e.value/t.total:0,r=c+n*l;s.push({a0:c,a1:r}),c+=n*Math.PI*2}return{cx:r,cy:i,rOuter:a,rInner:o,angles:s}}function ee(e){if(e.data.kind!==`donut`)return;let t=e.data,n=e.ctx,r=F(e,t,e.t);for(let e=0;e<t.slices.length;e++){let i=t.slices[e],a=r.angles[e];if(!i||!a||a.a1-a.a0<=0)continue;let o=a.a0+N/2,s=a.a1-N/2;s<=o||(n.beginPath(),n.arc(r.cx,r.cy,r.rOuter,o,s),n.arc(r.cx,r.cy,r.rInner,s,o,!0),n.closePath(),n.fillStyle=i.color,n.fill())}t.slices.length>0&&e.t>.5&&(n.fillStyle=e.theme.text,n.font=`600 20px ${e.theme.fontFamily}`,n.textAlign=`center`,n.textBaseline=`middle`,n.fillText(M(t.total),r.cx,r.cy))}function te(e,t,n){if(e.data.kind!==`donut`)return null;let r=e.data,i=F(e,r,1),a=t-i.cx,o=n-i.cy,s=Math.hypot(a,o);if(s<i.rInner||s>i.rOuter)return null;let c=Math.atan2(o,a);for(;c<P;)c+=Math.PI*2;for(;c>=P+Math.PI*2;)c-=Math.PI*2;for(let e=0;e<i.angles.length;e++){let a=i.angles[e],o=r.slices[e];if(a&&o&&c>=a.a0&&c<a.a1)return{kind:`slice`,index:e,label:o.label,color:o.color,value:o.value,share:r.total>0?o.value/r.total:0,px:t,py:n}}return null}function ne(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=e.t,i=r<1,a=e.yScale.domain[0],o=e.plot.x-3,s=e.plot.x+e.plot.w+3;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),n.clip();for(let c of t.series){let u=c.y,d=c.prevY;n.fillStyle=l(c.color,.65),n.beginPath();for(let c=0;c<t.sortedX.length;c++){let l=e.xScale(t.sortedX[c]);if(l<o||l>s)continue;let f=u[c];if(i){let e=d?d[c]:a;f=e+(f-e)*r}let p=e.yScale(f);n.moveTo(l+2.5,p),n.arc(l,p,2.5,0,Math.PI*2)}n.fill()}n.restore()}function re(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=t.series[0];if(!r||t.sortedX.length===0)return;let{path:i,firstX:a,lastX:o,lastY:s}=b(e,r),c=new Path2D(i),u=e.plot.y+e.plot.h;c.lineTo(o,u),c.lineTo(a,u),c.closePath(),n.fillStyle=l(r.color,.1),n.fill(c),n.strokeStyle=r.color,n.lineWidth=1.5,n.lineJoin=`round`,n.lineCap=`round`,n.stroke(i),n.fillStyle=r.color,n.beginPath(),n.arc(o,s,2,0,Math.PI*2),n.fill()}function I(e,t,n,r){let i=t.bars[n];if(!i)return null;let a=t.bars.length,o=e.plot.w/Math.max(1,a),s=Math.min(o*.75,48),c=e.plot.x+o*n+(o-s)/2,l=e.yScale(Math.max(i.start,r)),u=e.yScale(Math.min(i.start,r));return{x:c,y:l,w:s,h:Math.abs(u-l)}}function L(e,t){return t.total?e.theme.series[0]??e.theme.contextGray:t.value>=0?e.theme.up:e.theme.down}function ie(e){if(e.data.kind!==`waterfall`)return;let t=e.data,n=e.ctx,r=t.bars.length,i=e.plot.w/Math.max(1,r);n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let a=Math.min(i*.75,48);n.strokeStyle=e.theme.crosshair,n.lineWidth=1,n.setLineDash([3,3]),n.beginPath();for(let o=1;o<r;o++){let r=t.bars[o-1];if(!r)continue;let s=e.yScale(r.end);n.moveTo(e.plot.x+i*(o-1)+(i+a)/2,s),n.lineTo(e.plot.x+i*o+(i-a)/2,s)}n.stroke(),n.setLineDash([]);for(let i=0;i<r;i++){let r=t.bars[i];if(!r)continue;let a=r.total?r.end*e.t:r.start+(r.end-r.start)*e.t,o=I(e,t,i,a);if(!o)continue;n.fillStyle=L(e,r);let s=Math.min(2,o.h/2,o.w/2);n.beginPath(),o.h<=0?n.rect(o.x,o.y-.5,o.w,1):n.roundRect(o.x,o.y,o.w,o.h,s),n.fill()}n.restore()}function ae(e,t,n){if(e.data.kind!==`waterfall`)return null;let r=e.data,i=r.bars.length;if(i===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let a=Math.min(i-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*i))),o=r.bars[a];if(!o)return null;let s=I(e,r,a,o.end);return s?{kind:`bar`,category:r.categories[a]??``,seriesIndex:0,label:o.total?`Total`:`Δ`,color:L(e,o),value:o.value,px:s.x+s.w/2,py:s.y,rect:s}:null}function oe(e,t){let n=document.createElement(`canvas`);return n.style.cssText=`position:absolute;inset:0;width:100%;height:100%;display:block`,n.width=Math.max(1,Math.round(e)),n.height=Math.max(1,Math.round(t)),n}function R(e,t){let n=e.getContext(`2d`,t);if(!n)throw Error(`resolvcharts: could not get 2d context`);return n}var se=class{constructor(e,t,n,r={}){this.kind=`canvas2d`,this.plot={x:0,y:0,w:0,h:0},this.gridCache=null,this.gridCtx=null,this.container=e,this.settings={alpha:!0,...r},this.dpr=Math.max(1,window.devicePixelRatio||1),this.width=t,this.height=n,this.mainCanvas=oe(t,n),this.overlayCanvas=oe(t,n),this.overlayCanvas.style.pointerEvents=`none`,this.main=R(this.mainCanvas,this.settings),this.overlay=R(this.overlayCanvas,this.settings),e.append(this.mainCanvas,this.overlayCanvas),this.applySize()}applySize(){let e=this.width*this.dpr,t=this.height*this.dpr;for(let n of[this.mainCanvas,this.overlayCanvas])n.width=Math.max(1,Math.round(e)),n.height=Math.max(1,Math.round(t));for(let e of[this.main,this.overlay])e.setTransform(this.dpr,0,0,this.dpr,0,0);this.gridCache&&(this.gridCache.width=Math.max(1,Math.round(e)),this.gridCache.height=Math.max(1,Math.round(t)),this.gridCtx?.setTransform(this.dpr,0,0,this.dpr,0,0))}grid(){this.gridCache||(this.gridCache=document.createElement(`canvas`),this.gridCache.width=Math.max(1,this.width*this.dpr),this.gridCache.height=Math.max(1,this.height*this.dpr),this.gridCtx=R(this.gridCache,this.settings),this.gridCtx.setTransform(this.dpr,0,0,this.dpr,0,0));let e=this.gridCtx;return e.clearRect(0,0,this.width,this.height),e}blitGrid(){this.gridCache&&this.main.drawImage(this.gridCache,0,0,this.width,this.height)}resize(e,t){this.dpr=Math.max(1,window.devicePixelRatio||1),this.width=Math.max(1,e),this.height=Math.max(1,t),this.applySize()}setPlot(e){this.plot=e}begin(){this.main.clearRect(0,0,this.width,this.height)}beginOverlay(){this.overlay.clearRect(0,0,this.width,this.height)}destroy(){this.mainCanvas.remove(),this.overlayCanvas.remove(),this.gridCache=null,this.gridCtx=null,this.container}};function z(e,t,n,r){let i=t-e||1,a=r-n,o=(t=>n+(t-e)/i*a);return o.invert=t=>e+(t-n)/a*i,o.domain=[e,t],o.range=[n,r],o}function B(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){let i=e[r];i<t&&(t=i),i>n&&(n=i)}return t===1/0?[0,1]:t===n?t===0?[0,1]:[t-Math.abs(t)*.1,n+Math.abs(n)*.1]:[t,n]}function V(e,t,n=!1){let r=n?Math.min(0,e):e,i=n?Math.max(0,t):t;r===i&&(i=r+1);let a=(i-r)*.05;return n?(r<0&&(r-=a),i>0&&(i+=a)):(r-=a,i+=a),[r,i]}function H(e,t,n){return[t??e[0],n??e[1]]}let U=typeof requestAnimationFrame==`function`?e=>requestAnimationFrame(e):e=>setTimeout(()=>e(Date.now()),16),ce=typeof cancelAnimationFrame==`function`?e=>cancelAnimationFrame(e):e=>clearTimeout(e),W=new class{constructor(){this.items=/* @__PURE__ */ new Set,this.id=null,this.tick=e=>{this.id=null;for(let t of[...this.items])t(e)||this.items.delete(t);this.items.size>0&&(this.id=U(this.tick))}}add(e){this.items.add(e),this.id===null&&(this.id=U(this.tick))}remove(e){this.items.delete(e)}destroy(){this.items.clear(),this.id!==null&&(ce(this.id),this.id=null)}},le=e=>1-(1-e)**3,G=`Inter, system-ui, -apple-system, "Segoe UI", sans-serif`,K={bg:`#ffffff`,text:`#1f1f1f`,textMuted:`#8a8a8a`,grid:`rgba(0,0,0,0.07)`,axisBaseline:`rgba(0,0,0,0.15)`,crosshair:`rgba(0,0,0,0.25)`,series:[`#0070f3`],contextGray:`#b0b0b0`,up:`#0e9f6e`,down:`#e5484d`,tooltipBg:`#ffffff`,tooltipText:`#1f1f1f`,tooltipMuted:`#8a8a8a`,tooltipBorder:`rgba(0,0,0,0.08)`,tooltipShadow:`0 4px 14px rgba(0,0,0,0.08)`,fontFamily:G},ue={bg:`#0a0a0a`,text:`#ededed`,textMuted:`#8a8a8a`,grid:`rgba(255,255,255,0.07)`,axisBaseline:`rgba(255,255,255,0.18)`,crosshair:`rgba(255,255,255,0.3)`,series:[`#3b9dff`],contextGray:`#5c5c5c`,up:`#34c98e`,down:`#f2555a`,tooltipBg:`#161616`,tooltipText:`#ededed`,tooltipMuted:`#8a8a8a`,tooltipBorder:`rgba(255,255,255,0.1)`,tooltipShadow:`0 4px 14px rgba(0,0,0,0.4)`,fontFamily:G},de=[`#0070f3`,`#0e9f6e`,`#8e4ec6`,`#f5a623`],fe=[`#3b9dff`,`#34c98e`,`#a97ef0`,`#f5b84d`];function pe(e,t){let n=e===`dark`?{...ue,series:[...fe]}:e===`light`||e===void 0?{...K,series:[...de]}:{...K,series:[...de],...e};return t&&(n.series[0]=t),n}function q(e,t,n){return n||e.series[t%e.series.length]}let me=[1,2,2.5,5,10];function he(e,t){let n=Math.abs(e)/Math.max(1,t);if(!Number.isFinite(n)||n===0)return 1;let r=10**Math.floor(Math.log10(n)),i=n/r,a=10;for(let e of me)if(i<=e){a=e;break}return a*r}function J(e,t,n=5){if(!(e<t))return[e];let r=he(t-e,n),i=Math.ceil(e/r)*r,a=[];for(let e=i;e<=t+r*1e-9&&(a.push(Math.abs(e)<r*1e-9?0:e),!(a.length>1e3));e+=r);return a}var ge=class{constructor(e,t){this.theme=t,this.el=document.createElement(`div`),this.el.style.cssText=[`position:absolute`,`pointer-events:none`,`background:${t.tooltipBg}`,`border:1px solid ${t.tooltipBorder}`,`box-shadow:${t.tooltipShadow}`,`border-radius:6px`,`padding:6px 10px`,`font:12px ${t.fontFamily}`,`color:${t.tooltipText}`,`white-space:nowrap`,`opacity:0`,`transition:opacity 80ms ease-out`,`z-index:1`,`left:0`,`top:0`].join(`;`),e.appendChild(this.el)}setTheme(e){this.theme=e;let t=this.el.style;t.background=e.tooltipBg,t.border=`1px solid ${e.tooltipBorder}`,t.boxShadow=e.tooltipShadow,t.color=e.tooltipText}show(e,t,n,r){let i=this.el;if(i.textContent=``,r){let e=document.createElement(`div`);e.style.cssText=`font-weight:600;margin-bottom:2px;color:${this.theme.tooltipText}`,e.textContent=r,i.appendChild(e)}for(let e of n){let t=document.createElement(`div`);if(t.style.cssText=`display:flex;align-items:center;gap:6px;line-height:1.5`,e.color){let n=document.createElement(`span`);n.style.cssText=`width:8px;height:2px;background:${e.color};display:inline-block;border-radius:1px`,t.appendChild(n)}let n=document.createElement(`span`);n.style.color=this.theme.tooltipMuted,n.textContent=e.label;let r=document.createElement(`span`);r.style.cssText=`font-weight:600;margin-left:auto;padding-left:12px`,r.textContent=e.value,t.append(n,r),i.appendChild(t)}i.style.opacity=`1`,this.position(e,t)}position(e,t){let n=this.el,r=n.parentElement;if(!r)return;let i=r.clientWidth,a=r.clientHeight,o=n.offsetWidth,s=n.offsetHeight,c=e+12,l=t+12;c+o>i-4&&(c=e-o-12),l+s>a-4&&(l=t-s-12),n.style.left=`${Math.max(0,c)}px`,n.style.top=`${Math.max(0,l)}px`}hide(){this.el.style.opacity=`0`}destroy(){this.el.remove()}};function _e(e){if(e.startsWith(`#`)){let t=e.slice(1);if(t.length===3)return[parseInt(t[0],16)/15,parseInt(t[1],16)/15,parseInt(t[2],16)/15,1];if(t.length===6)return[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}let t=/rgba?\(([^)]+)\)/.exec(e);if(t){let e=t[1].split(`,`).map(e=>Number.parseFloat(e));return[(e[0]??0)/255,(e[1]??0)/255,(e[2]??0)/255,e[3]??1]}return[0,0,0,1]}var ve=n((()=>{}));function ye(e={}){let t=JSON.stringify(e),n=Y.get(t);return n||(n=(async()=>{try{let n=(typeof navigator>`u`?null:navigator)?.gpu;if(!n)return null;let r={};e.powerPreference&&e.powerPreference!=="default"&&(r.powerPreference=e.powerPreference),e.compat&&(r.featureLevel=`compatibility`);let i=await n.requestAdapter(r);if(!i||!e.allowFallback&&i.isFallbackAdapter)return null;let a=[];e.timing&&i.features.has(`timestamp-query`)&&a.push(`timestamp-query`);let o=await i.requestDevice({requiredFeatures:a});return o.lost.then(()=>Y.delete(t)),o}catch{return null}})(),n.catch(()=>Y.delete(t)),Y.set(t,n)),n}var Y,be=n((()=>{Y=/* @__PURE__ */ new Map})),xe=/* @__PURE__ */ r({GpuSeries:()=>Le}),X,Se,Ce,we,Te,Ee,De,Oe,ke,Ae,je,Z,Me,Ne,Pe,Fe,Q,Ie,Le,Re,ze=n((()=>{ve(),be(),X=`
|
|
1
|
+
var ResolvCharts=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function i(e,t,n,r,i){let a=t.categories.length;if(a===0)return null;let o=e.plot.w/a,s=Math.min(o*.8,40*t.series.length),c=s/t.series.length,l=e.plot.x+o*n+(o-s)/2+c*r,u=e.yScale(0),d=e.yScale(i);return{x:l,y:Math.min(u,d),w:c,h:Math.abs(u-d)}}function a(e,t,n,r){let{x:i,y:a,w:o,h:s}=t;if(s<=0||o<=0)return;let c=Math.min(n,s/2,o/2);e.beginPath(),r?(e.moveTo(i,a+s),e.lineTo(i,a+c),e.arcTo(i,a,i+c,a,c),e.lineTo(i+o-c,a),e.arcTo(i+o,a,i+o,a+c,c),e.lineTo(i+o,a+s)):(e.moveTo(i,a),e.lineTo(i+o,a),e.lineTo(i+o,a+s-c),e.arcTo(i+o,a+s,i+o-c,a+s,c),e.lineTo(i+c,a+s),e.arcTo(i,a+s,i,a+s-c,c),e.lineTo(i,a)),e.closePath(),e.fill()}function o(e,t,n,r,i){let a=t.categories.length;if(a===0)return null;let o=e.plot.w/a,s=Math.min(o*.8,40),c=e.plot.x+o*n+(o-s)/2,l=e.yScale(Math.max(r,i)),u=e.yScale(Math.min(r,i));return{x:c,y:l,w:s,h:Math.abs(u-l)}}function s(e){if(e.data.kind!==`category`)return;let t=e.data,n=e.ctx;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let r=t.categories.length,i=e.plot.w/Math.max(1,r),o=e.t<1;if(e.opts.stacked){let a=Math.min(i*.8,40);for(let s=0;s<r;s++){let r=e.plot.x+i*s+(i-a)/2,c=0,l=0;for(let i=0;i<t.series.length;i++){let u=t.series[i];if(!u)continue;let d=u.values[s]??0,f=u.prevValues?.[s]??0,p=o?f+(d-f)*e.t:d,m=p>=0?c:l+p,h=p>=0?c+p:l;p>=0?c=h:l=m;let g=e.yScale(Math.max(m,h)),_=Math.abs(e.yScale(Math.min(m,h))-g);_<=0||(n.fillStyle=u.color,n.fillRect(r,g,a,_))}}}else{let s=Math.min(i*.8,40*t.series.length),c=s/t.series.length,l=e.yScale(0);for(let u=0;u<t.series.length;u++){let d=t.series[u];if(d){n.fillStyle=d.color;for(let t=0;t<r;t++){let r=d.values[t]??0,f=d.prevValues?.[t]??0,p=o?f+(r-f)*e.t:r,m=e.plot.x+i*t+(i-s)/2+c*u,h=e.yScale(p),g=Math.min(l,h),_=Math.abs(l-h);_<=0||a(n,{x:m,y:g,w:c,h:_},3,p>=0)}}}}n.restore()}function c(e,t,n){if(e.data.kind!==`category`)return null;let r=e.data,a=r.categories.length;if(a===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let s=Math.min(a-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*a)));if(e.opts.stacked){let i=0,a=0;for(let c=0;c<r.series.length;c++){let l=r.series[c];if(!l)continue;let u=l.values[s]??0,d=u>=0?i:a+u,f=u>=0?i+u:a;u>=0?i=f:a=d;let p=o(e,r,s,d,f);if(p&&t>=p.x&&t<=p.x+p.w&&n>=p.y&&n<=p.y+p.h)return{kind:`bar`,category:r.categories[s]??``,seriesIndex:c,label:l.label,color:l.color,value:u,px:p.x+p.w/2,py:n,rect:p}}let c=r.series[r.series.length-1];if(!c)return null;let l=o(e,r,s,0,i);return l?{kind:`bar`,category:r.categories[s]??``,seriesIndex:r.series.length-1,label:c.label,color:c.color,value:c.values[s]??0,px:l.x+l.w/2,py:l.y,rect:l}:null}for(let a=0;a<r.series.length;a++){let o=r.series[a];if(!o)continue;let c=i(e,r,s,a,o.values[s]??0);if(c&&t>=c.x&&t<=c.x+c.w){let e=n>=c.y&&n<=c.y+c.h;return{kind:`bar`,category:r.categories[s]??``,seriesIndex:a,label:o.label,color:o.color,value:o.values[s]??0,px:c.x+c.w/2,py:e?n:c.y,rect:c}}}let c=r.series[0],l=c?i(e,r,s,0,c.values[s]??0):null;return!c||!l?null:{kind:`bar`,category:r.categories[s]??``,seriesIndex:0,label:c.label,color:c.color,value:c.values[s]??0,px:e.plot.x+e.plot.w/a*(s+.5),py:l.y,rect:l}}function l(e,t){if(e.startsWith(`#`)){let n=e.slice(1);n.length===3&&(n=n.split(``).map(e=>e+e).join(``));let r=Number.parseInt(n,16);return`rgba(${r>>16&255},${r>>8&255},${r&255},${t})`}let n=e.match(/^rgba?\(([^)]+)\)$/);return n?`rgba(${n[1].split(`,`).slice(0,3).join(`,`)},${t})`:e}function u(e,t,n,r,i,a,o,s=0){let c=Math.min(e.length,t.length),l=new Float32Array(Math.max(1,c)*2),u=a.domain,d=a.range,f=(d[1]-d[0])/(u[1]-u[0]||1),p=d[0]-u[0]*f,m=o.domain,h=o.range,g=(h[1]-h[0])/(m[1]-m[0]||1),_=h[0]-m[0]*g,v=r<1,y=c>1?s/(c-1):0,b=1+s,x=0;for(let a=0;a<c;a++){let o=t[a];if(v){let e=s>0?r*b-s+a*y:r;e<0?e=0:e>1&&(e=1);let t=n?n[a]:i;o=t+(o-t)*e}l[x]=p+e[a]*f,l[x+1]=_+o*g,x+=2}return l.subarray(0,x)}let d=/* @__PURE__ */ new Float32Array;function f(e,t,n,r,i,a,o,s,c=0){let l=Math.min(e.length,t.length);if(l===0)return/* @__PURE__ */ new Float32Array;let u=Math.min(l,4*(Math.ceil(s)+8));d.length<u*2&&(d=new Float32Array(Math.max(1,u)*2));let f=d,p=a.domain,m=a.range,h=(m[1]-m[0])/(p[1]-p[0]||1),g=m[0]-p[0]*h,_=o.domain,v=o.range,y=(v[1]-v[0])/(_[1]-_[0]||1),b=v[0]-_[0]*y,x=r<1,S=l>1?c/(l-1):0,C=1+c,w=0,T=t[0];if(x){let e=c>0?r*C-c:r;e<0?e=0:e>1&&(e=1);let t=n?n[0]:i;T=t+(T-t)*e}let E=g+e[0]*h,D=b+T*y,O=Math.floor(E),k=E,A=D,j=E,M=D,N=E,P=D,F=f.length;for(let a=1;a<l;a++){let o=g+e[a]*h;if(T=t[a],x){let e=c>0?r*C-c+a*S:r;e<0?e=0:e>1&&(e=1);let t=n?n[a]:i;T=t+(T-t)*e}let s=b+T*y,l=Math.floor(o);l===O?(s<A&&(A=s,k=o),s>M&&(M=s,j=o),N=o,P=s):(w+8<=F&&(f[w]=E,f[w+1]=D,w+=2,(A!==D||k!==E)&&(f[w]=k,f[w+1]=A,w+=2),(M!==A||j!==k)&&(f[w]=j,f[w+1]=M,w+=2),(N!==j||P!==M)&&(f[w]=N,f[w+1]=P,w+=2)),O=l,E=o,D=s,k=j=N=o,A=M=P=s)}return w+8<=F&&(f[w]=E,f[w+1]=D,w+=2,(A!==D||k!==E)&&(f[w]=k,f[w+1]=A,w+=2),(M!==A||j!==k)&&(f[w]=j,f[w+1]=M,w+=2),(N!==j||P!==M)&&(f[w]=N,f[w+1]=P,w+=2)),f.subarray(0,w)}function p(e,t,n){let r=Math.min(e.length,t.length);if(r===0)return/* @__PURE__ */ new Float32Array;let i=Math.min(r,4*(Math.ceil(n)+8)),a=new Float32Array(Math.max(1,i)*2),o=0,s=Math.floor(e[0]),c=e[0],l=t[0],u=c,d=l,f=c,p=l,m=c,h=l,g=(e,t)=>{o+2<=a.length&&(a[o]=e,a[o+1]=t,o+=2)},_=()=>{g(c,l),(d!==l||u!==c)&&g(u,d),(p!==d||f!==u)&&g(f,p),(m!==f||h!==p)&&g(m,h)};for(let n=1;n<r;n++){let r=e[n],i=t[n],a=Math.floor(r);a===s?(i<d&&(d=i,u=r),i>p&&(p=i,f=r),m=r,h=i):(_(),s=a,c=r,l=i,u=f=m=r,d=p=h=i)}return _(),a.subarray(0,o)}function m(e,t){let n=e.length;if(n===0)return-1;if(t<=e[0])return 0;if(t>=e[n-1])return n-1;let r=0,i=n-1;for(;i-r>1;){let n=r+i>>1;e[n]<t?r=n:i=n}let a=Math.abs(t-e[r]);return Math.abs(t-e[i])<a?i:r}function h(e){return e.kind===`xy`}let g=/* @__PURE__ */ new Float64Array;function _(e,t,n,r=!1){if(n<3){for(let i=0;i<n;i++){let n=t[2*i],a=t[2*i+1];i===0&&!r?e.moveTo(n,a):e.lineTo(n,a)}return}let i=n-1,a=i+n;g.length<a&&(g=new Float64Array(a));let o=g.subarray(0,i),s=g.subarray(i,i+n);for(let e=0;e<i;e++){let n=t[2*(e+1)]-t[2*e];o[e]=n===0?0:(t[2*(e+1)+1]-t[2*e+1])/n}s[0]=o[0];for(let e=1;e<i;e++){let t=o[e-1],n=o[e];s[e]=t*n<=0?0:(t+n)/2}s[n-1]=o[i-1];for(let e=0;e<i;e++){let t=o[e];if(t!==0){let n=s[e],r=s[e+1],i=3*Math.abs(t);Math.abs(n)>i&&(s[e]=Math.sign(n)*i),Math.abs(r)>i&&(s[e+1]=Math.sign(r)*i)}}r?e.lineTo(t[0],t[1]):e.moveTo(t[0],t[1]);for(let n=0;n<i;n++){let r=t[2*n],i=t[2*(n+1)],a=t[2*n+1],o=t[2*(n+1)+1],c=(i-r)/3;e.bezierCurveTo(r+c,a+c*s[n],i-c,o-c*s[n+1],i,o)}}function v(e,t,n,r,i=!1){if(n===0)return;let a=(t,n)=>i?e.lineTo(t,n):e.moveTo(t,n);if(r===`step`){a(t[0],t[1]);for(let r=1;r<n;r++){let n=t[2*r];e.lineTo(n,t[2*r-1]),e.lineTo(n,t[2*r+1])}}else if(r===`smooth`)_(e,t,n,i);else{a(t[0],t[1]);for(let r=1;r<n;r++)e.lineTo(t[2*r],t[2*r+1])}}let y=.35;function b(e,t,n){let r=e.data;if(!h(r))throw Error(`unreachable`);let i=r.sortedX.length;if(i===0)return/* @__PURE__ */ new Float32Array;let a=n??e.yScale.domain[0],o=e.opts.flow?y:0;return i>e.plot.w*1.5?f(r.sortedX,t.y,t.prevY,e.t,a,e.xScale,e.yScale,e.plot.w,o):u(r.sortedX,t.y,t.prevY,e.t,a,e.xScale,e.yScale,o)}function x(e,t,n){let r=new Path2D,i=b(e,t,n),a=i.length/2;return a===0?{path:r,firstX:0,lastX:0,lastY:0}:(v(r,i,a,e.opts.curve??`linear`),{path:r,firstX:i[0],lastX:i[2*a-2],lastY:i[2*a-1]})}function S(e,t){if(!h(e.data))return;let n=e.data,r=e.ctx;r.save(),r.beginPath(),r.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),r.clip();for(let i of n.series){let{path:n,firstX:a,lastX:o}=x(e,i);if(t&&o!==a){let t=new Path2D(n),s=e.yScale(Math.max(0,e.yScale.domain[0]));t.lineTo(o,s),t.lineTo(a,s),t.closePath();let c=r.createLinearGradient(0,e.plot.y,0,e.plot.y+e.plot.h);c.addColorStop(0,l(i.color,.16)),c.addColorStop(1,l(i.color,0)),r.fillStyle=c,r.fill(t)}r.strokeStyle=i.color,r.lineWidth=2,r.lineJoin=`round`,r.lineCap=`round`,r.stroke(n)}r.restore()}function C(e,t){if(!h(e.data))return null;let n=e.data,r=m(n.sortedX,e.xScale.invert(t));if(r<0)return null;let i=n.sortedX[r],a=e.xScale(i),o=e.plot.y+e.plot.h,s=n.series.map(t=>{let n=t.y[r],i=e.yScale(n);return i<o&&(o=i),{label:t.label,color:t.color,y:n}});return{kind:`point`,index:r,x:i,px:a,py:o,values:s}}function w(e){if(!h(e.data))return;let t=e.data,n=t.series[0];if(!n||t.sortedX.length===0)return;let r=e.ctx,i=e.opts.baseline??n.y[0],a=Math.max(e.plot.y,Math.min(e.plot.y+e.plot.h,e.yScale(i))),{path:o,firstX:s,lastX:c}=x(e,n,i),u=new Path2D(o);u.lineTo(c,a),u.lineTo(s,a),u.closePath();let d=[{top:e.plot.y,bot:a,color:e.theme.up,gFrom:.28,gTo:.05},{top:a,bot:e.plot.y+e.plot.h,color:e.theme.down,gFrom:.05,gTo:.28}];for(let t of d){if(t.bot-t.top<=0)continue;r.save(),r.beginPath(),r.rect(e.plot.x,t.top,e.plot.w,t.bot-t.top),r.clip();let n=r.createLinearGradient(0,t.top,0,t.bot);n.addColorStop(0,l(t.color,t.gFrom)),n.addColorStop(1,l(t.color,t.gTo)),r.fillStyle=n,r.fill(u),r.strokeStyle=t.color,r.lineWidth=2,r.lineJoin=`round`,r.lineCap=`round`,r.stroke(o),r.restore()}r.strokeStyle=e.theme.axisBaseline,r.lineWidth=1,r.setLineDash([4,4]),r.beginPath();let f=Math.round(a)+.5;r.moveTo(e.plot.x,f),r.lineTo(e.plot.x+e.plot.w,f),r.stroke(),r.setLineDash([])}function T(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=e.t,i=r<1,a=e.yScale.domain[0],o=1/0,s=-1/0;for(let e of t.series){let t=e.r;if(t)for(let e=0;e<t.length;e++){let n=t[e];n<o&&(o=n),n>s&&(s=n)}}o===1/0&&(o=0,s=1);let c=s-o||1,u=i?r:1,d=e=>(3+(e-o)/c*13)*u,f=e.plot.x-16,p=e.plot.x+e.plot.w+16;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),n.clip();for(let s of t.series){let u=s.y,m=s.prevY,h=s.r;n.fillStyle=l(s.color,.45),n.strokeStyle=s.color,n.lineWidth=1.5,n.beginPath();for(let s=0;s<t.sortedX.length;s++){let l=e.xScale(t.sortedX[s]);if(l<f||l>p)continue;let g=u[s];if(i){let e=m?m[s]:a;g=e+(g-e)*r}let _=e.yScale(g),v=d(h?h[s]:o+c/2);v<=0||(n.moveTo(l+v,_),n.arc(l,_,v,0,Math.PI*2))}n.fill(),n.stroke()}n.restore()}function E(e,t){if(e.data.kind!==`ohlc`)return;let n=e.data,r=e.ctx,i=n.x.length;if(i===0)return;r.save(),r.beginPath(),r.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),r.clip(),r.globalAlpha=e.t>=1?1:e.t;let a=e.xScale.domain,o=e.xScale.range,s=(o[1]-o[0])/(a[1]-a[0]||1),c=o[0]-a[0]*s,u=e.yScale.domain,d=e.yScale.range,f=(d[1]-d[0])/(u[1]-u[0]||1),p=d[0]-u[0]*f,m=new Path2D,h=new Path2D,g=new Path2D,_=new Path2D,v=new Path2D,y=new Path2D,b=n.volume?e.plot.h*.18:0,x=e.plot.y+e.plot.h,S=n.volume;if(i<=e.plot.w){let r=Math.min(e.plot.w/i*.6,14),a=r/2,o=0;if(S)for(let e=0;e<i;e++){let t=S[e];t>o&&(o=t)}let l=o>0?b/o:0;for(let e=0;e<i;e++){let i=n.close[e]>=n.open[e],o=c+n.x[e]*s,u=p+n.high[e]*f,d=p+n.low[e]*f,b=i?m:h;if(b.moveTo(o,u),b.lineTo(o,d),t){let t=p+n.open[e]*f,r=p+n.close[e]*f;b.moveTo(o-a,t),b.lineTo(o,t),b.moveTo(o,r),b.lineTo(o+a,r)}else{let t=p+n.open[e]*f,s=p+n.close[e]*f;(i?g:_).rect(o-a,Math.min(t,s),r,Math.max(1,Math.abs(s-t)))}if(S){let t=S[e];if(t>0){let e=t*l;(i?v:y).rect(o-a,x-e,r,e)}}}}else{let r=Math.min(i,Math.ceil(e.plot.w)+1),a=new Float64Array(r),o=new Float64Array(r),l=new Float64Array(r),u=new Float64Array(r),d=new Float64Array(r),C=new Float64Array(r),w=0,T=-1;for(let e=0;e<i;e++){let t=Math.floor(c+n.x[e]*s);if(t!==T){T=t;let r=w++;a[r]=t+.5,o[r]=n.open[e],l[r]=n.high[e],u[r]=n.low[e],d[r]=n.close[e],C[r]=S?S[e]:0}else{let t=w-1,r=n.high[e],i=n.low[e];r>l[t]&&(l[t]=r),i<u[t]&&(u[t]=i),d[t]=n.close[e],S&&(C[t]=C[t]+S[e])}}let E=e.plot.w/w,D=Math.max(.5,Math.min(E*.6,14)),O=D/2,k=0;if(S)for(let e=0;e<w;e++)C[e]>k&&(k=C[e]);let A=k>0?b/k:0;for(let e=0;e<w;e++){let n=a[e],r=d[e]>=o[e],i=r?m:h;if(i.moveTo(n,p+l[e]*f),i.lineTo(n,p+u[e]*f),t){let t=p+o[e]*f,r=p+d[e]*f;i.moveTo(n-O,t),i.lineTo(n,t),i.moveTo(n,r),i.lineTo(n+O,r)}else{let t=p+o[e]*f,i=p+d[e]*f;(r?g:_).rect(n-O,Math.min(t,i),D,Math.max(1,Math.abs(i-t)))}if(S){let t=C[e];if(t>0){let e=t*A;(r?v:y).rect(n-O,x-e,D,e)}}}}r.lineWidth=1,r.strokeStyle=e.theme.up,r.stroke(m),r.strokeStyle=e.theme.down,r.stroke(h),t||(r.fillStyle=e.theme.up,r.fill(g),r.fillStyle=e.theme.down,r.fill(_)),S&&(r.fillStyle=l(e.theme.up,.35),r.fill(v),r.fillStyle=l(e.theme.down,.35),r.fill(y)),r.restore()}function D(e,t){if(e.data.kind!==`ohlc`)return null;let n=e.data,r=m(n.x,e.xScale.invert(t));return r<0?null:{kind:`candle`,index:r,x:n.x[r],open:n.open[r],high:n.high[r],low:n.low[r],close:n.close[r],px:e.xScale(n.x[r]),py:e.yScale(n.close[r])}}let O=/* @__PURE__ */ new Float64Array;function k(e,t,n){let r=new Path2D;return v(r,t,n,e.opts.curve??`linear`),r}function A(e){if(e.data.kind!==`category`)return;let t=e.data,n=e.ctx;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let r=t.categories.length,i=e.plot.w/Math.max(1,r),o=e.t<1,s=(t,n)=>{let r=t.values[n]??0,i=t.prevValues?.[n]??0;return o?i+(r-i)*e.t:r},c=0;for(let e of t.series)e.kind===`column`&&c++;if(e.opts.stacked){let a=Math.min(i*.8,40);for(let o=0;o<r;o++){let r=e.plot.x+i*o+(i-a)/2,c=0,l=0;for(let i of t.series){if(i.kind!==`column`)continue;let t=s(i,o),u=t>=0?c:l+t,d=t>=0?c+t:l;t>=0?c=d:l=u;let f=e.yScale(Math.max(u,d)),p=Math.abs(e.yScale(Math.min(u,d))-f);p<=0||(n.fillStyle=i.color,n.fillRect(r,f,a,p))}}}else{let o=Math.min(i*.8,40*c),l=o/Math.max(1,c),u=e.yScale(0),d=0;for(let c of t.series)if(c.kind===`column`){n.fillStyle=c.color;for(let t=0;t<r;t++){let r=s(c,t),f=e.plot.x+i*t+(i-o)/2+l*d,p=e.yScale(r),m=Math.min(u,p),h=Math.abs(u-p);h<=0||a(n,{x:f,y:m,w:l,h},3,r>=0)}d++}}let u=e.yScale(Math.max(0,e.yScale.domain[0]));O.length<r*2&&(O=new Float64Array(r*2));let d=O;for(let a of t.series){if(a.kind===`column`)continue;for(let t=0;t<r;t++)d[2*t]=e.plot.x+i*(t+.5),d[2*t+1]=e.yScale(s(a,t));let t=k(e,d,r);if(a.kind===`area`&&r>1){let i=new Path2D(t);i.lineTo(d[2*(r-1)],u),i.lineTo(d[0],u),i.closePath();let o=n.createLinearGradient(0,e.plot.y,0,e.plot.y+e.plot.h);o.addColorStop(0,l(a.color,.16)),o.addColorStop(1,l(a.color,0)),n.fillStyle=o,n.fill(i)}n.strokeStyle=a.color,n.lineWidth=2,n.lineJoin=`round`,n.lineCap=`round`,n.stroke(t)}n.restore()}function j(e,t){if(e.data.kind!==`category`)return null;let n=e.data,r=n.categories.length;if(r===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let i=Math.min(r-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*r))),a=e.plot.w/r,o=e.plot.y+e.plot.h,s=n.series.map(t=>{let n=t.values[i]??0,r=e.yScale(n);return r<o&&(o=r),{label:t.label,color:t.color,y:n}});return{kind:`point`,index:i,x:i,px:e.plot.x+a*(i+.5),py:o,values:s,title:n.categories[i]??``}}function M(e){return Number.isFinite(e)?String(Number.isInteger(e)&&Math.abs(e)<0x38d7ea4c68000?e:Number(e.toPrecision(4))):``}let N=[[1e9,`B`],[1e6,`M`],[1e3,`k`]];function P(e){if(!Number.isFinite(e))return``;let t=Math.abs(e);for(let[n,r]of N)if(t>=n){let t=e/n,i=t>=100||Number.isInteger(t)?0:1;return`${t.toFixed(i)}${r}`}return M(e)}let F=.015,I=-Math.PI/2,ee=e=>e.opts.type===`pie`?0:.65;function te(e,t,n){let r=e.plot.x+e.plot.w/2,i=e.plot.y+e.plot.h/2,a=Math.max(1,Math.min(e.plot.w,e.plot.h)/2),o=a*ee(e),s=[],c=I,l=Math.PI*2*Math.min(1,Math.max(0,n));for(let e of t.slices){let n=t.total>0?e.value/t.total:0,r=c+n*l;s.push({a0:c,a1:r}),c+=n*Math.PI*2}return{cx:r,cy:i,rOuter:a,rInner:o,angles:s}}function L(e){if(e.data.kind!==`donut`)return;let t=e.data,n=e.ctx,r=te(e,t,e.t);for(let e=0;e<t.slices.length;e++){let i=t.slices[e],a=r.angles[e];if(!i||!a||a.a1-a.a0<=0)continue;let o=a.a0+F/2,s=a.a1-F/2;s<=o||(n.beginPath(),n.arc(r.cx,r.cy,r.rOuter,o,s),r.rInner>0?n.arc(r.cx,r.cy,r.rInner,s,o,!0):n.lineTo(r.cx,r.cy),n.closePath(),n.fillStyle=i.color,n.fill())}e.opts.type!==`pie`&&t.slices.length>0&&e.t>.5&&(n.fillStyle=e.theme.text,n.font=`600 20px ${e.theme.fontFamily}`,n.textAlign=`center`,n.textBaseline=`middle`,n.fillText(P(t.total),r.cx,r.cy))}function R(e,t,n){if(e.data.kind!==`donut`)return null;let r=e.data,i=te(e,r,1),a=t-i.cx,o=n-i.cy,s=Math.hypot(a,o);if(s<i.rInner||s>i.rOuter)return null;let c=Math.atan2(o,a);for(;c<I;)c+=Math.PI*2;for(;c>=I+Math.PI*2;)c-=Math.PI*2;for(let e=0;e<i.angles.length;e++){let a=i.angles[e],o=r.slices[e];if(a&&o&&c>=a.a0&&c<a.a1)return{kind:`slice`,index:e,label:o.label,color:o.color,value:o.value,share:r.total>0?o.value/r.total:0,px:t,py:n}}return null}let ne=`Inter, system-ui, -apple-system, "Segoe UI", sans-serif`,z={bg:`#ffffff`,text:`#1f1f1f`,textMuted:`#8a8a8a`,grid:`rgba(0,0,0,0.07)`,axisBaseline:`rgba(0,0,0,0.15)`,crosshair:`rgba(0,0,0,0.25)`,series:[`#0070f3`],contextGray:`#b0b0b0`,up:`#0e9f6e`,down:`#e5484d`,tooltipBg:`#ffffff`,tooltipText:`#1f1f1f`,tooltipMuted:`#8a8a8a`,tooltipBorder:`rgba(0,0,0,0.08)`,tooltipShadow:`0 4px 14px rgba(0,0,0,0.08)`,fontFamily:ne},re={bg:`#0a0a0a`,text:`#ededed`,textMuted:`#8a8a8a`,grid:`rgba(255,255,255,0.07)`,axisBaseline:`rgba(255,255,255,0.18)`,crosshair:`rgba(255,255,255,0.3)`,series:[`#3b9dff`],contextGray:`#5c5c5c`,up:`#34c98e`,down:`#f2555a`,tooltipBg:`#161616`,tooltipText:`#ededed`,tooltipMuted:`#8a8a8a`,tooltipBorder:`rgba(255,255,255,0.1)`,tooltipShadow:`0 4px 14px rgba(0,0,0,0.4)`,fontFamily:ne},ie=[`#0070f3`,`#0e9f6e`,`#8e4ec6`,`#f5a623`],ae=[`#3b9dff`,`#34c98e`,`#a97ef0`,`#f5b84d`];function oe(e,t){let n=e===`dark`?{...re,series:[...ae]}:e===`light`||e===void 0?{...z,series:[...ie]}:{...z,series:[...ie],...e};return t&&(n.series[0]=t),n}function B(e,t,n){return n||e.series[t%e.series.length]}function se(e,t,n){let r=t.series[0];if(!r)return[];let i=t.categories.length,a=0;for(let e=0;e<r.values.length;e++){let t=r.values[e];t>a&&(a=t)}a||=1;let o=e.plot.h/Math.max(1,i),s=[];for(let c=0;c<i;c++){let l=r.values[c]??0,u=r.prevValues?.[c]??0,d=n<1?u+(l-u)*n:l,f=r.values[c+1]??l,p=r.prevValues?.[c+1]??0,m=c+1<i?n<1?p+(f-p)*n:f:d;s.push({cat:t.categories[c]??``,value:l,top:e.plot.y+o*c,bot:e.plot.y+o*(c+1)-2,w0:Math.max(0,d)/a*e.plot.w,w1:Math.max(0,m)/a*e.plot.w,color:B(e.theme,c,void 0)})}return s}function ce(e,t){let n=e.plot.x+e.plot.w/2,r=Math.max(t.w0,t.w1);return{x:n-r/2,y:t.top,w:r,h:t.bot-t.top}}function le(e){if(e.data.kind!==`category`)return;let t=e.data,n=e.ctx,r=e.plot.x+e.plot.w/2;for(let i of se(e,t,e.t)){n.beginPath(),n.moveTo(r-i.w0/2,i.top),n.lineTo(r+i.w0/2,i.top),n.lineTo(r+i.w1/2,i.bot),n.lineTo(r-i.w1/2,i.bot),n.closePath(),n.fillStyle=i.color,n.fill();let t=`${i.cat} · ${P(i.value)}`;n.font=`11px ${e.theme.fontFamily}`,n.textBaseline=`middle`,Math.min(i.w0,i.w1)>=72?(n.fillStyle=`#ffffff`,n.textAlign=`center`,n.fillText(t,r,(i.top+i.bot)/2)):(n.fillStyle=e.theme.textMuted,n.textAlign=`left`,n.fillText(t,r+Math.max(i.w0,i.w1)/2+8,(i.top+i.bot)/2))}}function ue(e,t,n){if(e.data.kind!==`category`)return null;let r=e.data,i=r.series[0];if(!i)return null;let a=e.plot.x+e.plot.w/2;for(let o of se(e,r,1)){if(n<o.top||n>o.bot)continue;let r=o.bot-o.top>0?(n-o.top)/(o.bot-o.top):0,s=o.w0+(o.w1-o.w0)*r;if(!(Math.abs(t-a)>s/2+4))return{kind:`bar`,category:o.cat,seriesIndex:0,label:i.label,color:o.color,value:o.value,px:a,py:n,rect:ce(e,o)}}return null}let de=-Math.PI/2;function V(e,t){let n=e.plot.x+e.plot.w/2,r=e.plot.y+e.plot.h/2,i=Math.max(1,Math.min(e.plot.w,e.plot.h)/2-16),a=0;for(let e of t.series)for(let t=0;t<e.values.length;t++){let n=e.values[t];n>a&&(a=n)}return{cx:n,cy:r,radius:i,max:a||1}}let H=(e,t)=>de+e/t*Math.PI*2;function fe(e){if(e.data.kind!==`category`)return;let t=e.data,n=t.categories.length;if(n<3)return;let r=e.ctx,{cx:i,cy:a,radius:o,max:s}=V(e,t),c=e.t<1;r.strokeStyle=e.theme.grid,r.lineWidth=1;for(let e=1;e<=4;e++){let t=o*e/4;r.beginPath();for(let e=0;e<=n;e++){let o=H(e%n,n),s=i+Math.cos(o)*t,c=a+Math.sin(o)*t;e===0?r.moveTo(s,c):r.lineTo(s,c)}r.stroke()}r.beginPath();for(let e=0;e<n;e++){let t=H(e,n);r.moveTo(i,a),r.lineTo(i+Math.cos(t)*o,a+Math.sin(t)*o)}r.stroke();for(let u of t.series){r.beginPath();for(let t=0;t<n;t++){let l=u.values[t]??0,d=u.prevValues?.[t]??0,f=c?d+(l-d)*e.t:l,p=Math.max(0,f)/s*o,m=H(t,n),h=i+Math.cos(m)*p,g=a+Math.sin(m)*p;t===0?r.moveTo(h,g):r.lineTo(h,g)}r.closePath(),r.fillStyle=l(u.color,.16),r.fill(),r.strokeStyle=u.color,r.lineWidth=2,r.lineJoin=`round`,r.stroke(),r.fillStyle=u.color,r.beginPath();for(let t=0;t<n;t++){let l=u.values[t]??0,d=u.prevValues?.[t]??0,f=c?d+(l-d)*e.t:l,p=Math.max(0,f)/s*o,m=H(t,n),h=i+Math.cos(m)*p,g=a+Math.sin(m)*p;r.moveTo(h+2.5,g),r.arc(h,g,2.5,0,Math.PI*2)}r.fill()}r.fillStyle=e.theme.textMuted,r.font=`11px ${e.theme.fontFamily}`;for(let e=0;e<n;e++){let s=H(e,n),c=i+Math.cos(s)*(o+16-4),l=a+Math.sin(s)*(o+16-4);r.textAlign=Math.cos(s)>.3?`left`:Math.cos(s)<-.3?`right`:`center`,r.textBaseline=Math.sin(s)>.3?`top`:Math.sin(s)<-.3?`bottom`:`middle`,r.fillText(t.categories[e]??``,c,l)}}function pe(e,t,n){if(e.data.kind!==`category`)return null;let r=e.data,i=r.categories.length;if(i<3)return null;let{cx:a,cy:o,radius:s}=V(e,r),c=t-a,l=n-o;if(Math.hypot(c,l)>s+16)return null;let u=Math.atan2(l,c)-de;for(;u<0;)u+=Math.PI*2;for(;u>=Math.PI*2;)u-=Math.PI*2;let d=Math.round(u/(Math.PI*2)*i)%i;return{kind:`point`,index:d,x:d,px:t,py:n,values:r.series.map(e=>({label:e.label,color:e.color,y:e.values[d]??0})),title:r.categories[d]??``}}function me(e,t){if(e.data.kind!==`category`||t.kind!==`point`)return;let n=e.data,r=n.categories.length;if(t.index<0||t.index>=r)return;let i=e.backend.overlay,{cx:a,cy:o,radius:s,max:c}=V(e,n),l=H(t.index,r);i.strokeStyle=e.theme.crosshair,i.lineWidth=1,i.beginPath(),i.moveTo(a,o),i.lineTo(a+Math.cos(l)*s,o+Math.sin(l)*s),i.stroke();for(let r of n.series){let n=r.values[t.index]??0,u=Math.max(0,n)/c*s;i.fillStyle=r.color,i.strokeStyle=e.theme.bg,i.lineWidth=2,i.beginPath(),i.arc(a+Math.cos(l)*u,o+Math.sin(l)*u,4,0,Math.PI*2),i.fill(),i.stroke()}}let U=/* @__PURE__ */ new Float64Array;function he(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=e.opts.curve??`linear`;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),n.clip();for(let i of t.series){if(!i.y2)continue;let t=b(e,{y:i.y2,prevY:i.prevY2}),a=b(e,i),o=Math.min(t.length,a.length)/2;if(o===0)continue;U.length<o*2&&(U=new Float64Array(o*2));for(let e=0;e<o;e++)U[2*e]=a[2*(o-1-e)],U[2*e+1]=a[2*(o-1-e)+1];let s=new Path2D;v(s,t,o,r),v(s,U,o,r,!0),s.closePath(),n.fillStyle=l(i.color,.2),n.fill(s),n.strokeStyle=i.color,n.lineWidth=1.5,n.lineJoin=`round`,n.lineCap=`round`;let c=new Path2D;v(c,t,o,r),v(c,a,o,r),n.stroke(c)}n.restore()}function ge(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=e.t,i=r<1,a=e.yScale.domain[0],o=e.plot.x-3,s=e.plot.x+e.plot.w+3;n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h),n.clip();for(let c of t.series){let u=c.y,d=c.prevY;n.fillStyle=l(c.color,.65),n.beginPath();for(let c=0;c<t.sortedX.length;c++){let l=e.xScale(t.sortedX[c]);if(l<o||l>s)continue;let f=u[c];if(i){let e=d?d[c]:a;f=e+(f-e)*r}let p=e.yScale(f);n.moveTo(l+2.5,p),n.arc(l,p,2.5,0,Math.PI*2)}n.fill()}n.restore()}function _e(e){if(!h(e.data))return;let t=e.data,n=e.ctx,r=t.series[0];if(!r||t.sortedX.length===0)return;let{path:i,firstX:a,lastX:o,lastY:s}=x(e,r),c=new Path2D(i),u=e.plot.y+e.plot.h;c.lineTo(o,u),c.lineTo(a,u),c.closePath(),n.fillStyle=l(r.color,.1),n.fill(c),n.strokeStyle=r.color,n.lineWidth=1.5,n.lineJoin=`round`,n.lineCap=`round`,n.stroke(i),n.fillStyle=r.color,n.beginPath(),n.arc(o,s,2,0,Math.PI*2),n.fill()}function ve(e,t,n,r){let i=t.bars[n];if(!i)return null;let a=t.bars.length,o=e.plot.w/Math.max(1,a),s=Math.min(o*.75,48),c=e.plot.x+o*n+(o-s)/2,l=e.yScale(Math.max(i.start,r)),u=e.yScale(Math.min(i.start,r));return{x:c,y:l,w:s,h:Math.abs(u-l)}}function ye(e,t){return t.total?e.theme.series[0]??e.theme.contextGray:t.value>=0?e.theme.up:e.theme.down}function be(e){if(e.data.kind!==`waterfall`)return;let t=e.data,n=e.ctx,r=t.bars.length,i=e.plot.w/Math.max(1,r);n.save(),n.beginPath(),n.rect(e.plot.x,e.plot.y,e.plot.w,e.plot.h+1),n.clip();let a=Math.min(i*.75,48);n.strokeStyle=e.theme.crosshair,n.lineWidth=1,n.setLineDash([3,3]),n.beginPath();for(let o=1;o<r;o++){let r=t.bars[o-1];if(!r)continue;let s=e.yScale(r.end);n.moveTo(e.plot.x+i*(o-1)+(i+a)/2,s),n.lineTo(e.plot.x+i*o+(i-a)/2,s)}n.stroke(),n.setLineDash([]);for(let i=0;i<r;i++){let r=t.bars[i];if(!r)continue;let a=r.total?r.end*e.t:r.start+(r.end-r.start)*e.t,o=ve(e,t,i,a);if(!o)continue;n.fillStyle=ye(e,r);let s=Math.min(2,o.h/2,o.w/2);n.beginPath(),o.h<=0?n.rect(o.x,o.y-.5,o.w,1):n.roundRect(o.x,o.y,o.w,o.h,s),n.fill()}n.restore()}function xe(e,t,n){if(e.data.kind!==`waterfall`)return null;let r=e.data,i=r.bars.length;if(i===0||t<e.plot.x||t>e.plot.x+e.plot.w)return null;let a=Math.min(i-1,Math.max(0,Math.floor((t-e.plot.x)/e.plot.w*i))),o=r.bars[a];if(!o)return null;let s=ve(e,r,a,o.end);return s?{kind:`bar`,category:r.categories[a]??``,seriesIndex:0,label:o.total?`Total`:`Δ`,color:ye(e,o),value:o.value,px:s.x+s.w/2,py:s.y,rect:s}:null}function Se(e,t){let n=document.createElement(`canvas`);return n.style.cssText=`position:absolute;inset:0;width:100%;height:100%;display:block`,n.width=Math.max(1,Math.round(e)),n.height=Math.max(1,Math.round(t)),n}function W(e,t){let n=e.getContext(`2d`,t);if(!n)throw Error(`resolvcharts: could not get 2d context`);return n}var Ce=class{constructor(e,t,n,r={}){this.kind=`canvas2d`,this.plot={x:0,y:0,w:0,h:0},this.gridCache=null,this.gridCtx=null,this.container=e,this.settings={alpha:!0,...r},this.dpr=Math.max(1,window.devicePixelRatio||1),this.width=t,this.height=n,this.mainCanvas=Se(t,n),this.overlayCanvas=Se(t,n),this.overlayCanvas.style.pointerEvents=`none`,this.main=W(this.mainCanvas,this.settings),this.overlay=W(this.overlayCanvas,this.settings),e.append(this.mainCanvas,this.overlayCanvas),this.applySize()}applySize(){let e=this.width*this.dpr,t=this.height*this.dpr;for(let n of[this.mainCanvas,this.overlayCanvas])n.width=Math.max(1,Math.round(e)),n.height=Math.max(1,Math.round(t));for(let e of[this.main,this.overlay])e.setTransform(this.dpr,0,0,this.dpr,0,0);this.gridCache&&(this.gridCache.width=Math.max(1,Math.round(e)),this.gridCache.height=Math.max(1,Math.round(t)),this.gridCtx?.setTransform(this.dpr,0,0,this.dpr,0,0))}grid(){this.gridCache||(this.gridCache=document.createElement(`canvas`),this.gridCache.width=Math.max(1,this.width*this.dpr),this.gridCache.height=Math.max(1,this.height*this.dpr),this.gridCtx=W(this.gridCache,this.settings),this.gridCtx.setTransform(this.dpr,0,0,this.dpr,0,0));let e=this.gridCtx;return e.clearRect(0,0,this.width,this.height),e}blitGrid(){this.gridCache&&this.main.drawImage(this.gridCache,0,0,this.width,this.height)}resize(e,t){this.dpr=Math.max(1,window.devicePixelRatio||1),this.width=Math.max(1,e),this.height=Math.max(1,t),this.applySize()}setPlot(e){this.plot=e}begin(){this.main.clearRect(0,0,this.width,this.height)}beginOverlay(){this.overlay.clearRect(0,0,this.width,this.height)}destroy(){this.mainCanvas.remove(),this.overlayCanvas.remove(),this.gridCache=null,this.gridCtx=null,this.container}};function G(e,t,n,r){let i=t-e||1,a=r-n,o=(t=>n+(t-e)/i*a);return o.invert=t=>e+(t-n)/a*i,o.domain=[e,t],o.range=[n,r],o}function K(e){let t=1/0,n=-1/0;for(let r=0;r<e.length;r++){let i=e[r];i<t&&(t=i),i>n&&(n=i)}return t===1/0?[0,1]:t===n?t===0?[0,1]:[t-Math.abs(t)*.1,n+Math.abs(n)*.1]:[t,n]}function q(e,t,n=!1){let r=n?Math.min(0,e):e,i=n?Math.max(0,t):t;r===i&&(i=r+1);let a=(i-r)*.05;return n?(r<0&&(r-=a),i>0&&(i+=a)):(r-=a,i+=a),[r,i]}function we(e,t,n){return[t??e[0],n??e[1]]}let Te=typeof requestAnimationFrame==`function`?e=>requestAnimationFrame(e):e=>setTimeout(()=>e(Date.now()),16),Ee=typeof cancelAnimationFrame==`function`?e=>cancelAnimationFrame(e):e=>clearTimeout(e),J=new class{constructor(){this.items=/* @__PURE__ */ new Set,this.id=null,this.tick=e=>{this.id=null;for(let t of[...this.items])t(e)||this.items.delete(t);this.items.size>0&&(this.id=Te(this.tick))}}add(e){this.items.add(e),this.id===null&&(this.id=Te(this.tick))}remove(e){this.items.delete(e)}destroy(){this.items.clear(),this.id!==null&&(Ee(this.id),this.id=null)}},De=e=>1-(1-e)**3,Oe=[1,2,2.5,5,10];function ke(e,t){let n=Math.abs(e)/Math.max(1,t);if(!Number.isFinite(n)||n===0)return 1;let r=10**Math.floor(Math.log10(n)),i=n/r,a=10;for(let e of Oe)if(i<=e){a=e;break}return a*r}function Y(e,t,n=5){if(!(e<t))return[e];let r=ke(t-e,n),i=Math.ceil(e/r)*r,a=[];for(let e=i;e<=t+r*1e-9&&(a.push(Math.abs(e)<r*1e-9?0:e),!(a.length>1e3));e+=r);return a}var Ae=class{constructor(e,t){this.theme=t,this.el=document.createElement(`div`),this.el.style.cssText=[`position:absolute`,`pointer-events:none`,`background:${t.tooltipBg}`,`border:1px solid ${t.tooltipBorder}`,`box-shadow:${t.tooltipShadow}`,`border-radius:6px`,`padding:6px 10px`,`font:12px ${t.fontFamily}`,`color:${t.tooltipText}`,`white-space:nowrap`,`opacity:0`,`transition:opacity 80ms ease-out`,`z-index:1`,`left:0`,`top:0`].join(`;`),e.appendChild(this.el)}setTheme(e){this.theme=e;let t=this.el.style;t.background=e.tooltipBg,t.border=`1px solid ${e.tooltipBorder}`,t.boxShadow=e.tooltipShadow,t.color=e.tooltipText}show(e,t,n,r){let i=this.el;if(i.textContent=``,r){let e=document.createElement(`div`);e.style.cssText=`font-weight:600;margin-bottom:2px;color:${this.theme.tooltipText}`,e.textContent=r,i.appendChild(e)}for(let e of n){let t=document.createElement(`div`);if(t.style.cssText=`display:flex;align-items:center;gap:6px;line-height:1.5`,e.color){let n=document.createElement(`span`);n.style.cssText=`width:8px;height:2px;background:${e.color};display:inline-block;border-radius:1px`,t.appendChild(n)}let n=document.createElement(`span`);n.style.color=this.theme.tooltipMuted,n.textContent=e.label;let r=document.createElement(`span`);r.style.cssText=`font-weight:600;margin-left:auto;padding-left:12px`,r.textContent=e.value,t.append(n,r),i.appendChild(t)}i.style.opacity=`1`,this.position(e,t)}position(e,t){let n=this.el,r=n.parentElement;if(!r)return;let i=r.clientWidth,a=r.clientHeight,o=n.offsetWidth,s=n.offsetHeight,c=e+12,l=t+12;c+o>i-4&&(c=e-o-12),l+s>a-4&&(l=t-s-12),n.style.left=`${Math.max(0,c)}px`,n.style.top=`${Math.max(0,l)}px`}hide(){this.el.style.opacity=`0`}destroy(){this.el.remove()}};function je(e){if(e.startsWith(`#`)){let t=e.slice(1);if(t.length===3)return[parseInt(t[0],16)/15,parseInt(t[1],16)/15,parseInt(t[2],16)/15,1];if(t.length===6)return[parseInt(t.slice(0,2),16)/255,parseInt(t.slice(2,4),16)/255,parseInt(t.slice(4,6),16)/255,1]}let t=/rgba?\(([^)]+)\)/.exec(e);if(t){let e=t[1].split(`,`).map(e=>Number.parseFloat(e));return[(e[0]??0)/255,(e[1]??0)/255,(e[2]??0)/255,e[3]??1]}return[0,0,0,1]}var Me=n((()=>{}));function Ne(e={}){let t=JSON.stringify(e),n=X.get(t);return n||(n=(async()=>{try{let n=(typeof navigator>`u`?null:navigator)?.gpu;if(!n)return null;let r={};e.powerPreference&&e.powerPreference!=="default"&&(r.powerPreference=e.powerPreference),e.compat&&(r.featureLevel=`compatibility`);let i=await n.requestAdapter(r);if(!i||!e.allowFallback&&i.isFallbackAdapter)return null;let a=[];e.timing&&i.features.has(`timestamp-query`)&&a.push(`timestamp-query`);let o=await i.requestDevice({requiredFeatures:a});return o.lost.then(()=>X.delete(t)),o}catch{return null}})(),n.catch(()=>X.delete(t)),X.set(t,n)),n}var X,Pe=n((()=>{X=/* @__PURE__ */ new Map})),Fe=/* @__PURE__ */ r({GpuSeries:()=>$}),Z,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Q,Ke,qe,Je,Ye,Xe,Ze,$,Qe,$e=n((()=>{Me(),Pe(),Z=`
|
|
2
2
|
struct U {
|
|
3
3
|
res: vec4f, // canvas w,h (device px), dpr, pad
|
|
4
4
|
color: vec4f,
|
|
@@ -22,8 +22,8 @@ fn animT(i: f32) -> f32 {
|
|
|
22
22
|
u.anim.x * (1.0 + u.anim.y) - u.anim.y + i * u.anim.z, 0.0, 1.0,
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
|
-
`,
|
|
26
|
-
${
|
|
25
|
+
`,Ie=`
|
|
26
|
+
${Z}
|
|
27
27
|
const OFF = array<vec2f, 6>(
|
|
28
28
|
vec2f(0.0, -1.0), vec2f(0.0, 1.0), vec2f(1.0, -1.0),
|
|
29
29
|
vec2f(0.0, 1.0), vec2f(1.0, 1.0), vec2f(1.0, -1.0),
|
|
@@ -67,8 +67,8 @@ fn segQuad(v: vec2f, A: vec2f, B: vec2f) -> VOut {
|
|
|
67
67
|
let a = 1.0 - smoothstep(halfW - 0.5, halfW + 0.9, abs(o.edge));
|
|
68
68
|
return vec4f(u.color.rgb, u.color.a * a);
|
|
69
69
|
}
|
|
70
|
-
`,
|
|
71
|
-
${
|
|
70
|
+
`,Le=`
|
|
71
|
+
${Z}
|
|
72
72
|
const OFF = array<vec2f, 6>(
|
|
73
73
|
vec2f(0.0, -1.0), vec2f(0.0, 1.0), vec2f(1.0, -1.0),
|
|
74
74
|
vec2f(0.0, 1.0), vec2f(1.0, 1.0), vec2f(1.0, -1.0),
|
|
@@ -110,8 +110,8 @@ struct VOut {
|
|
|
110
110
|
let a = 1.0 - smoothstep(halfW - 0.5, halfW + 0.9, abs(o.edge));
|
|
111
111
|
return vec4f(u.color.rgb, u.color.a * a);
|
|
112
112
|
}
|
|
113
|
-
`,
|
|
114
|
-
${
|
|
113
|
+
`,Re=`
|
|
114
|
+
${Z}
|
|
115
115
|
struct VOut {
|
|
116
116
|
@builtin(position) pos: vec4f,
|
|
117
117
|
@location(0) grad: f32,
|
|
@@ -135,8 +135,8 @@ struct VOut {
|
|
|
135
135
|
let a = mix(0.16, 0.0, o.grad) * u.color.a;
|
|
136
136
|
return vec4f(u.color.rgb, a);
|
|
137
137
|
}
|
|
138
|
-
`,
|
|
139
|
-
${
|
|
138
|
+
`,ze=`
|
|
139
|
+
${Z}
|
|
140
140
|
struct VOut {
|
|
141
141
|
@builtin(position) pos: vec4f,
|
|
142
142
|
@location(0) grad: f32,
|
|
@@ -156,8 +156,8 @@ struct VOut {
|
|
|
156
156
|
let a = mix(0.16, 0.0, o.grad) * u.color.a;
|
|
157
157
|
return vec4f(u.color.rgb, a);
|
|
158
158
|
}
|
|
159
|
-
`,
|
|
160
|
-
${
|
|
159
|
+
`,Be=`
|
|
160
|
+
${Z}
|
|
161
161
|
const QUAD = array<vec2f, 6>(
|
|
162
162
|
vec2f(-1.0, -1.0), vec2f(1.0, -1.0), vec2f(-1.0, 1.0),
|
|
163
163
|
vec2f(-1.0, 1.0), vec2f(1.0, 1.0), vec2f(1.0, 1.0),
|
|
@@ -186,8 +186,8 @@ struct VOut {
|
|
|
186
186
|
let a = 1.0 - smoothstep(r - 1.2, r, length(o.local));
|
|
187
187
|
return vec4f(u.color.rgb, u.color.a * a);
|
|
188
188
|
}
|
|
189
|
-
`,
|
|
190
|
-
${
|
|
189
|
+
`,Ve=`
|
|
190
|
+
${Z}
|
|
191
191
|
@group(1) @binding(0) var<storage, read> xy: array<vec2f>;
|
|
192
192
|
@group(1) @binding(1) var<storage, read> prev: array<f32>;
|
|
193
193
|
@group(1) @binding(2) var<storage, read_write> dst: array<vec2f>;
|
|
@@ -267,5 +267,5 @@ fn dec(@builtin(global_invocation_id) gid: vec3u) {
|
|
|
267
267
|
dst[areaBase + 2u * k + 1u] = pt;
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
|
-
`,Oe=40,ke=72,Ae=516,je=9,Z=172,Me=160,Ne=1,Pe=7,Fe=256,Q=262144,Ie=12,Le=class e{get unavailable(){return this.dead||this.recovering}constructor(e,t,n){this.dpr=1,this.slots=[],this.slotCount=0,this.appliedRev=-1,this.draws=[],this.cmps=[],this.uOff=0,this.stamp=0,this.plotR={x:0,y:0,w:1,h:1},this.cols=1,this.t=1,this.flow=0,this.tailScratch=/* @__PURE__ */ new Float32Array(4),this.gpuMs=null,this.querySet=null,this.queryBuf=null,this.readBuf=null,this.reading=!1,this.timing=!1,this.destroyed=!1,this.dead=!1,this.recovering=!1,this.opts=n,this.timing=!!n.timing,this.canvas=t,t.style.cssText=`position:absolute;inset:0;width:100%;height:100%;display:block;pointer-events:none`;let r=t.getContext(`webgpu`);if(!r)throw Error(`resolvcharts: webgpu context unavailable`);this.ctx=r,this.device=e,this.format=navigator.gpu.getPreferredCanvasFormat(),this.setup(e)}static async create(t={}){let n=await ye(t);if(!n)return null;let r=document.createElement(`canvas`);try{return new e(n,r,t)}catch{return null}}setup(e){this.device=e,this.layout=e.createBindGroupLayout({entries:[{binding:0,visibility:Pe,buffer:{type:`uniform`,hasDynamicOffset:!0}}]}),this.decLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:4,buffer:{type:`read-only-storage`}},{binding:1,visibility:4,buffer:{type:`read-only-storage`}},{binding:2,visibility:4,buffer:{type:`storage`}}]}),this.ubuf=e.createBuffer({size:Q,usage:ke}),this.ubiGroup=e.createBindGroup({layout:this.layout,entries:[{binding:0,resource:{buffer:this.ubuf,size:112}}]});let t=e.createPipelineLayout({bindGroupLayouts:[this.layout]}),n=e.createPipelineLayout({bindGroupLayouts:[this.layout,this.decLayout]}),r=(n,r,i)=>e.createRenderPipeline({layout:t,vertex:{module:e.createShaderModule({code:n}),entryPoint:`vs`,buffers:i},fragment:{module:e.createShaderModule({code:n}),entryPoint:`fs`,targets:[{format:this.format,blend:Re}]},primitive:{topology:r}}),i={arrayStride:8,stepMode:`instance`,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},a={arrayStride:8,stepMode:`instance`,attributes:[{shaderLocation:1,offset:0,format:`float32x2`}]},o={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:2,offset:0,format:`float32`}]},s={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:3,offset:0,format:`float32`}]},c={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:1,offset:0,format:`float32`}]},l={arrayStride:8,stepMode:`vertex`,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},u={arrayStride:4,stepMode:`vertex`,attributes:[{shaderLocation:1,offset:0,format:`float32`}]};this.pipes={line:r(Se,`triangle-list`,[i,a,o,s]),lineFlat:r(Ce,`triangle-list`,[i,a]),area:r(we,`triangle-strip`,[l,u]),areaFlat:r(Te,`triangle-strip`,[l]),points:r(Ee,`triangle-list`,[i,c]),dec:e.createComputePipeline({layout:n,compute:{module:e.createShaderModule({code:De}),entryPoint:`dec`}})},this.timing&&e.features.has(`timestamp-query`)&&(this.querySet=e.createQuerySet({type:`timestamp`,count:2}),this.queryBuf=e.createBuffer({size:16,usage:Ae}),this.readBuf=e.createBuffer({size:16,usage:je})),e.lost.then(e=>this.onLost(e))}onLost(e){this.destroyed||(e.reason===`destroyed`?this.dead=!0:(this.recovering=!0,ye(this.opts).then(e=>{if(!e||this.destroyed)this.fail();else try{this.teardownResources(),this.setup(e);try{this.configure()}catch{let e=document.createElement(`canvas`);e.width=this.canvas.width,e.height=this.canvas.height,this.canvas.replaceWith(e),this.canvas=e;let t=e.getContext(`webgpu`);if(!t)throw Error(`webgpu context lost`);this.ctx=t,this.configure()}this.appliedRev=-1,this.recovering=!1}catch{this.fail()}})))}fail(){this.dead=!0,this.recovering=!1,this.destroy()}teardownResources(){for(let e of this.slots)e.xy.destroy(),e.prev.destroy(),e.scratch?.destroy(),e.dec?.destroy();this.slots=[],this.slotCount=0,this.ubuf.destroy(),this.queryBuf?.destroy(),this.readBuf?.destroy(),this.querySet?.destroy(),this.querySet=null,this.queryBuf=null,this.readBuf=null}configure(){this.ctx.configure({device:this.device,format:this.format,alphaMode:`premultiplied`})}setSize(e,t,n){this.dpr=n,this.canvas.width=Math.max(1,Math.round(e*n)),this.canvas.height=Math.max(1,Math.round(t*n)),this.unavailable||this.configure()}upload(e,t,n){let r=Math.min(t.length,n.y.length),i=r>0?t[0]:0,a=1/((r>0?t[r-1]-i:0)||Math.max(1,Math.abs(i),1)),o=1/0,s=-1/0;for(let e=0;e<r;e++){let t=n.y[e];t<o&&(o=t),t>s&&(s=t)}let c=o===1/0?0:o,l=1/(s-o||Math.max(1,Math.abs(c))),u=this.slots[e],d=Math.max(1024,Math.ceil(r*1.25));!u||u.cap<r?(u?.xy.destroy(),u?.prev.destroy(),u?.dec?.destroy(),u={n:r,cap:d,start:0,enc:{xr:i,xu:a,yr:c,yu:l},encXY:new Float32Array(d*2),encPrev:new Float32Array(d),xy:this.device.createBuffer({size:d*8,usage:Z}),prev:this.device.createBuffer({size:d*4,usage:Z}),scratch:null,scratchN:0,dec:null,decCols:0,bg:null,decStamp:-1},this.slots[e]=u):(u.n=r,u.start=0,u.enc={xr:i,xu:a,yr:c,yu:l},u.bg=null,u.decStamp=-1);let{encXY:f,encPrev:p}=u,m=n.prevY;for(let e=0;e<r;e++)f[2*e]=(t[e]-i)*a,f[2*e+1]=(n.y[e]-c)*l,p[e]=m?(m[e]-c)*l:0;this.device.queue.writeBuffer(u.xy,0,f,0,r*2),this.device.queue.writeBuffer(u.prev,0,p,0,r)}syncData(e,t){if(!(this.unavailable||t===this.appliedRev&&this.slotCount===e.series.length)){for(let t=0;t<e.series.length;t++){let n=e.series[t];n&&this.upload(t,e.sortedX,n)}this.slotCount=e.series.length,this.appliedRev=t}}appended(e,t,n,r){if(this.unavailable)return!1;let i=this.device.queue;for(let a=0;a<this.slotCount;a++){let o=this.slots[a];if(!o)return!1;let s=o.n-r+1;s>o.cap&&this.grow(o,s),o.start=(o.start+r)%o.cap,o.n=s;let c=(o.start+o.n-1)%o.cap,{xr:l,xu:u,yr:d,yu:f}=o.enc,p=(e-l)*u,m=((t[a]??0)-d)*f,h=((n[a]??0)-d)*f,g=this.tailScratch;if(g[0]=p,g[1]=m,i.writeBuffer(o.xy,c*8,g,0,2),o.encXY[2*c]=p,o.encXY[2*c+1]=m,g[0]=h,i.writeBuffer(o.prev,c*4,g,0,1),o.encPrev[c]=h,o.n>1){let e=(c+o.cap-1)%o.cap;i.writeBuffer(o.prev,e*4,g,0,1),o.encPrev[e]=h}}return!0}grow(e,t){let n=Math.max(e.cap*2,t+1024),r=e.cap-e.start,i=this.device.createCommandEncoder(),a=this.device.createBuffer({size:n*8,usage:Z}),o=this.device.createBuffer({size:n*4,usage:Z});i.copyBufferToBuffer(e.xy,e.start*8,a,0,r*8),e.start>0&&i.copyBufferToBuffer(e.xy,0,a,r*8,e.start*8),i.copyBufferToBuffer(e.prev,e.start*4,o,0,r*4),e.start>0&&i.copyBufferToBuffer(e.prev,0,o,r*4,e.start*4),this.device.queue.submit([i.finish()]),e.xy.destroy(),e.prev.destroy(),e.xy=a,e.prev=o;let s=new Float32Array(n*2),c=new Float32Array(n);s.set(e.encXY.subarray(e.start*2,e.cap*2),0),s.set(e.encXY.subarray(0,e.start*2),r*2),c.set(e.encPrev.subarray(e.start,e.cap),0),c.set(e.encPrev.subarray(0,e.start),r),e.encXY=s,e.encPrev=c,e.cap=n,e.start=0,e.bg=null}begin(e,t=1,n=0){this.plotR=e,this.t=t,this.flow=n,this.cols=Math.max(1,Math.ceil(e.x+e.w)),this.stamp++,this.draws.length=0,this.cmps.length=0,this.uOff=0}mapFor(e,t){let{xr:n,xu:r,yr:i,yu:a}=e.enc,o=this.plotR,s=(t.x[0]-n)*r,c=(t.x[1]-n)*r,l=o.w/(c-s||1e-30),u=o.x-s*l,d=(t.y[0]-i)*a,f=(t.y[1]-i)*a,p=o.h/(f-d||1e-30);return[l,u,p,o.y+f*p]}writeU(e,t,n,r,i,a){let o=this.uOff;this.uOff+=Fe;let s=/* @__PURE__ */ new Float32Array(28);s.set([this.canvas.width,this.canvas.height,this.dpr,0]);let[c,l,u,d]=_e(e);s.set([c,l,u,d*t],4),s.set(n,8),s.set(r,12);let f=i.n>1?this.flow/(i.n-1):0;return s.set([this.t,this.flow,f,0],16),s.set([i.start,i.cap,i.n,0],20),s.set([a[0],a[1],0,0],24),this.device.queue.writeBuffer(this.ubuf,o,s),o}decimateWanted(e){return e.n>this.cols*2}ensureDec(e){if(e.dec&&e.decCols>=this.cols)return;e.dec?.destroy();let t=Math.max(this.cols,Math.ceil(this.canvas.width/this.dpr));e.dec=this.device.createBuffer({size:t*Ie*8,usage:Me}),e.decCols=t,e.bg=null}dispatchDec(e,t,n){if(e.decStamp===this.stamp)return;e.decStamp=this.stamp,this.ensureDec(e),e.bg||=this.device.createBindGroup({layout:this.decLayout,entries:[{binding:0,resource:{buffer:e.xy}},{binding:1,resource:{buffer:e.prev}},{binding:2,resource:{buffer:e.dec}}]});let r=this.writeU(`#ffffff`,1,[0,0,0,0],t,e,[this.cols,n]);this.cmps.push({slot:e,u:r})}line(e,t,n,r){let i=this.slots[e];if(!i||i.n<2)return;let a=this.mapFor(i,r);if(this.decimateWanted(i)){this.dispatchDec(i,a,0);let e=this.writeU(t,1,[n,0,0,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.lineFlat,vbufs:[{buf:i.dec,off:0},{buf:i.dec,off:8}],u:e,verts:6,insts:4*this.cols-1});return}let o=this.writeU(t,1,[n,0,0,0],a,i,[0,0]),s=(e,t,n)=>({pipe:this.pipes.line,vbufs:[{buf:i.xy,off:e*8},{buf:i.xy,off:t*8},{buf:i.prev,off:e*4},{buf:i.prev,off:t*4}],u:o,verts:6,insts:n});if(i.start+i.n<=i.cap){this.draws.push(s(i.start,i.start+1,i.n-1));return}let c=i.cap-i.start;c>1&&this.draws.push(s(i.start,i.start+1,c-1)),this.draws.push(s(i.cap-1,0,1));let l=i.n-1-c;l>0&&this.draws.push(s(0,1,l))}area(e,t,n,r){let i=this.slots[e];if(!i||i.n<2)return;let a=this.mapFor(i,r),o=(n-i.enc.yr)*i.enc.yu,s=a[3]-o*a[2],c=this.plotR;if(this.decimateWanted(i)){this.dispatchDec(i,a,o);let e=this.writeU(t,1,[s,c.y,c.h,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.areaFlat,vbufs:[{buf:i.dec,off:this.cols*4*8}],u:e,verts:8*this.cols,insts:1});return}let l=i.n,u=new Float32Array(l*4),d=new Float32Array(l*2);for(let e=0;e<l;e++){let t=(i.start+e)%i.cap;u[4*e]=i.encXY[2*t],u[4*e+1]=i.encXY[2*t+1],u[4*e+2]=u[4*e],u[4*e+3]=u[4*e+1],d[2*e]=i.encPrev[t],d[2*e+1]=d[2*e]}(!i.scratch||i.scratchN<l)&&(i.scratch?.destroy(),i.scratch=this.device.createBuffer({size:Math.max(4096,l*24),usage:Oe}),i.scratchN=l);let f=l*16;this.device.queue.writeBuffer(i.scratch,0,u),this.device.queue.writeBuffer(i.scratch,f,d);let p=this.writeU(t,1,[s,c.y,c.h,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.area,vbufs:[{buf:i.scratch,off:0},{buf:i.scratch,off:f}],u:p,verts:l*2,insts:1})}points(e,t,n,r,i){let a=this.slots[e];if(!a||a.n<1)return;let o=this.mapFor(a,i),s=this.writeU(t,r,[n,0,0,0],o,a,[0,0]),c=(e,t)=>({pipe:this.pipes.points,vbufs:[{buf:a.xy,off:e*8},{buf:a.prev,off:e*4}],u:s,verts:6,insts:t});if(a.start+a.n<=a.cap){this.draws.push(c(a.start,a.n));return}let l=a.cap-a.start;this.draws.push(c(a.start,l)),a.n-l>0&&this.draws.push(c(0,a.n-l))}end(){if(!(this.unavailable||!this.draws.length&&!this.cmps.length))try{let e=this.device.createCommandEncoder();if(this.cmps.length){let t=e.beginComputePass();t.setPipeline(this.pipes.dec);for(let e of this.cmps)t.setBindGroup(0,this.ubiGroup,[e.u]),t.setBindGroup(1,e.slot.bg),t.dispatchWorkgroups(Math.ceil(this.cols/64));t.end()}if(this.draws.length){let t=this.ctx.getCurrentTexture().createView(),n=this.dpr,r=this.plotR,i=e.beginRenderPass({colorAttachments:[{view:t,loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:0}}],...this.querySet?{timestampWrites:{querySet:this.querySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}:{}});i.setScissorRect(Math.max(0,Math.floor(r.x*n)),Math.max(0,Math.floor(r.y*n)),Math.max(1,Math.floor(r.w*n)),Math.max(1,Math.floor(r.h*n)));for(let e of this.draws){i.setPipeline(e.pipe),i.setBindGroup(0,this.ubiGroup,[e.u]);for(let t=0;t<e.vbufs.length;t++){let n=e.vbufs[t];n&&i.setVertexBuffer(t,n.buf,n.off)}i.draw(e.verts,e.insts)}i.end()}let t=this.querySet,n=this.queryBuf,r=this.readBuf;t&&n&&r&&!this.reading?(e.resolveQuerySet(t,0,2,n,0),e.copyBufferToBuffer(n,0,r,0,16),this.reading=!0,this.device.queue.submit([e.finish()]),r.mapAsync(Ne).then(()=>{let e=new BigUint64Array(r.getMappedRange()),t=e[0],n=e[1];t!==void 0&&n!==void 0&&(this.gpuMs=Number(n-t)/1e6),r.unmap(),this.reading=!1},()=>{this.reading=!1})):this.device.queue.submit([e.finish()])}catch{}}destroy(){this.destroyed=!0;for(let e of this.slots)e.xy.destroy(),e.prev.destroy(),e.scratch?.destroy(),e.dec?.destroy();this.slots=[],this.ubuf?.destroy(),this.queryBuf?.destroy(),this.readBuf?.destroy(),this.querySet?.destroy();try{this.ctx.unconfigure()}catch{}this.canvas.remove()}},Re={color:{srcFactor:`src-alpha`,dstFactor:`one-minus-src-alpha`,operation:`add`},alpha:{srcFactor:`one`,dstFactor:`one-minus-src-alpha`,operation:`add`}}}));let Be={line:{render:e=>x(e,!1),hit:(e,t)=>S(e,t),axes:!0,defaultTooltip:!0},area:{render:e=>x(e,!0),hit:(e,t)=>S(e,t),axes:!0,defaultTooltip:!0},scatter:{render:ne,hit:(e,t)=>S(e,t),axes:!0,defaultTooltip:!0},bar:{render:s,hit:c,axes:!0,defaultTooltip:!0},combo:{render:O,hit:(e,t)=>k(e,t),axes:!0,defaultTooltip:!0},sparkline:{render:re,hit:(e,t)=>S(e,t),axes:!1,defaultTooltip:!1},donut:{render:ee,hit:te,axes:!1,defaultTooltip:!0},candle:{render:e=>w(e,!1),hit:(e,t)=>T(e,t),axes:!0,defaultTooltip:!0},ohlc:{render:e=>w(e,!0),hit:(e,t)=>T(e,t),axes:!0,defaultTooltip:!0},waterfall:{render:ie,hit:ae,axes:!0,defaultTooltip:!0},baseline:{render:C,hit:(e,t)=>S(e,t),axes:!0,defaultTooltip:!0}},Ve={line:`line`,area:`area`,sparkline:`line`,scatter:`points`};var $=class{constructor(e,t){this.tooltip=null,this.ro=null,this.rect=null,this.pointer=null,this.hover=null,this.animStart=null,this.animDur=0,this.view={x:[0,1],y:[0,1]},this.viewFrom=null,this.viewTo={x:[0,1],y:[0,1]},this.reduced=!1,this.destroyed=!1,this.pendingView=!1,this.gpu=null,this.gpuInit=!1,this.dataRev=0,this.lastAppendAt=0,this.estInterval=400,this.onScroll=()=>{this.rect=null},this.frame=e=>{if(this.destroyed)return!1;this.pendingView&&(this.pendingView=!1,this.viewFrom={x:[this.view.x[0],this.view.x[1]],y:[this.view.y[0],this.view.y[1]]},this.viewTo=this.layout(),this.animDur=this.resolveAnimDur(),this.animStart=-1);let t=!1;if(this.animStart!==null){this.animStart===-1&&(this.animStart=e);let n=this.animDur<=0?1:Math.min(1,(e-this.animStart)/this.animDur),r=le(n);this.lerpView(r),this.render(r),n<1?t=!0:this.animStart=null}return this.pointer&&=(this.applyHover(this.pointer.x,this.pointer.y),null),t},this.onMove=e=>{this.rect||=this.el.getBoundingClientRect(),this.pointer={x:e.clientX-this.rect.left,y:e.clientY-this.rect.top},W.add(this.frame)},this.onLeave=()=>{this.pointer=null,this.hover&&(this.hover=null,this.backend.beginOverlay(),this.tooltip?.hide(),this.options.onHover?.(null))},this.el=e,this.options=t,this.theme=pe(t.theme,t.accent),this.mod=Be[t.type],getComputedStyle(e).position===`static`&&(e.style.position=`relative`),t.height&&(e.style.height=`${t.height}px`);let n=e.clientWidth||320,r=e.clientHeight||(t.type===`sparkline`?32:240);this.backend=new se(e,n,r,t.canvas),this.reduced=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,(t.tooltip??this.mod.defaultTooltip)&&(this.tooltip=new ge(e,this.theme)),this.data=this.normalize(t.data,null),this.maybeInitGpu(),this.bindEvents();let i=this.layout();this.view={x:[...i.x],y:[...i.y]},this.viewTo={x:[...i.x],y:[...i.y]},this.startAnimation(i)}maybeInitGpu(){if(this.gpu||this.gpuInit||this.destroyed||!Ve[this.options.type])return;let e=this.options.renderer??`auto`;if(e===`auto`||e===`webgpu`){if(e===`auto`){let e=this.data;if((e.kind===`xy`?e.sortedX.length*Math.max(1,e.series.length):0)<(this.options.gpuThreshold??1e5))return}this.gpuInit=!0,Promise.resolve().then(()=>(ze(),xe)).then(({GpuSeries:e})=>e.create(this.options.gpu).then(e=>{!e||this.destroyed?e?.destroy():(e.setSize(this.backend.width,this.backend.height,this.backend.dpr),this.backend.overlayCanvas.before(e.canvas),this.gpu=e,W.add(e=>(this.render(1),!1)))}))}}normalize(e,t){let n=this.options.type;if(n===`candle`||n===`ohlc`){let t=e,n=t.candles.length,r=null;for(let e=1;e<n;e++)if((t.candles[e]?.x??e)<(t.candles[e-1]?.x??e-1)){r=new Uint32Array(n);for(let e=0;e<n;e++)r[e]=e;r.sort((e,n)=>(t.candles[e]?.x??0)-(t.candles[n]?.x??0));break}let i=new Float64Array(n),a=new Float64Array(n),o=new Float64Array(n),s=new Float64Array(n),c=new Float64Array(n),l=!1,u=new Float64Array(n);for(let e=0;e<n;e++){let n=t.candles[r?r[e]:e];i[e]=n?.x??e,a[e]=n?.open??0,o[e]=n?.high??0,s[e]=n?.low??0,c[e]=n?.close??0,u[e]=n?.volume??0,n?.volume!=null&&n.volume>0&&(l=!0)}return{kind:`ohlc`,x:i,open:a,high:o,low:s,close:c,volume:l?u:null}}if(n===`waterfall`){let t=e,n=new Set(t.totals??[]),r=0,i=t.categories.map((e,i)=>{let a=t.values[i]??0;if(n.has(i)){let e={start:0,end:a,value:a,total:!0};return r=a,e}let o={start:r,end:r+a,value:a,total:!1};return r+=a,o});return{kind:`waterfall`,categories:[...t.categories],bars:i}}if(n===`donut`){let t=e.slices.map((e,t)=>({label:e.label,value:e.value,color:q(this.theme,t,e.color)}));return{kind:`donut`,slices:t,total:t.reduce((e,t)=>e+Math.max(0,t.value),0)}}if(n===`bar`||n===`combo`){let n=e,r=t?.kind===`category`?t.series:[];return{kind:`category`,categories:[...n.categories],series:n.series.map((e,t)=>({label:e.label??`Series ${t+1}`,color:q(this.theme,t,e.color),kind:e.kind??`column`,values:Float64Array.from(e.values),prevValues:r[t]?.values??null}))}}let r=e,i=Float64Array.from(r.x),a=i.length,o=null;for(let e=1;e<a;e++)if(i[e]<i[e-1]){o=new Uint32Array(a);for(let e=0;e<a;e++)o[e]=e;o.sort((e,t)=>i[e]-i[t]);break}let s=o?new Float64Array(a):i;if(o)for(let e=0;e<a;e++)s[e]=i[o[e]];let c=t?.kind===`xy`?t.series:[];return{kind:`xy`,sortedX:s,series:r.series.map((e,t)=>{let n=new Float64Array(a),r=e.y;if(o)for(let e=0;e<a;e++)n[e]=r[o[e]];else for(let e=0;e<a;e++)n[e]=r[e];return{label:e.label??`Series ${t+1}`,color:q(this.theme,t,e.color),y:n,prevY:c[t]?.y??null,pathCache:null}})}}bindEvents(){this.el.addEventListener(`pointermove`,this.onMove,{passive:!0}),this.el.addEventListener(`pointerleave`,this.onLeave,{passive:!0}),window.addEventListener(`scroll`,this.onScroll,!0),typeof ResizeObserver==`function`&&(this.ro=new ResizeObserver(()=>this.resize()),this.ro.observe(this.el))}layout(){let e=this.backend.width,t=this.backend.height,n=this.mod,r=this.domains();if(!n.axes)return this.backend.setPlot({x:2,y:2,w:e-4,h:t-4}),r;let i=this.backend.main,a=this.options.labels?.y??M,o=Math.max(1,t-8-20),s=this.data.kind===`donut`?[]:J(r.y[0],r.y[1],Math.max(3,Math.floor(o/48))),c=0;if(s.length){i.font=`11px ${this.theme.fontFamily}`;for(let e of s)c=Math.max(c,i.measureText(a(e)).width);c+=10}let l={x:c,y:8,w:Math.max(1,e-c-8),h:o};return this.backend.setPlot(l),r}domains(){let e=this.data;if(e.kind===`xy`){let t=e.sortedX.length,n=this.options.window??this.options.maxPoints,r=n!=null&&t>n?t-n:0,i=t>0?[e.sortedX[r],e.sortedX[t-1]]:[0,1],a=1/0,o=-1/0;for(let t of e.series){let e=t.y;for(let t=Math.min(r,e.length);t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}}a===1/0&&(a=0,o=1);let s=this.options.type===`area`||this.options.type===`sparkline`;return{x:i,y:this.yDomain(V(a,o,s))}}if(e.kind===`category`){let t=1/0,n=-1/0;if(this.options.stacked){for(let r=0;r<e.categories.length;r++){let i=0,a=0;for(let t of e.series){if(t.kind!==`column`)continue;let e=t.values[r]??0;e>=0?i+=e:a+=e}t=Math.min(t,a),n=Math.max(n,i)}for(let r of e.series){if(r.kind===`column`)continue;let e=B(r.values);t=Math.min(t,e[0]),n=Math.max(n,e[1])}}else for(let r of e.series){let e=B(r.values);t=Math.min(t,e[0]),n=Math.max(n,e[1])}return t===1/0&&(t=0,n=1),{x:[0,e.categories.length],y:this.yDomain(V(t,n,!0))}}if(e.kind===`ohlc`){let t=B(e.x),n=1/0,r=-1/0;for(let t=0;t<e.x.length;t++){let i=e.low[t],a=e.high[t];i<n&&(n=i),a>r&&(r=a)}return n===1/0&&(n=0,r=1),{x:t,y:this.yDomain(V(n,r))}}if(e.kind===`waterfall`){let t=1/0,n=-1/0;for(let r of e.bars)t=Math.min(t,r.start,r.end),n=Math.max(n,r.start,r.end);return t===1/0&&(t=0,n=1),{x:[0,e.bars.length],y:this.yDomain(V(t,n,!0))}}return{x:[0,1],y:this.yDomain([0,1])}}yDomain(e){return H(e,this.options.yMin,this.options.yMax)}lerpView(e){let t=this.viewFrom,n=this.viewTo,r=this.view;!t||e>=1?(r.x[0]=n.x[0],r.x[1]=n.x[1],r.y[0]=n.y[0],r.y[1]=n.y[1]):(r.x[0]=t.x[0]+(n.x[0]-t.x[0])*e,r.x[1]=t.x[1]+(n.x[1]-t.x[1])*e,r.y[0]=t.y[0]+(n.y[0]-t.y[0])*e,r.y[1]=t.y[1]+(n.y[1]-t.y[1])*e)}makeScales(){let e=this.backend.plot,t=this.view,n=this.data.kind===`ohlc`&&this.data.volume?e.h*.18:0;return{xScale:z(t.x[0],t.x[1],e.x,e.x+e.w),yScale:z(t.y[0],t.y[1],e.y+e.h-n,e.y)}}renderContext(e,t=this.makeScales()){let{xScale:n,yScale:r}=t;return{backend:this.backend,ctx:this.backend.main,plot:this.backend.plot,theme:this.theme,opts:this.options,data:this.data,xScale:n,yScale:r,t:e}}drawStatic(e=this.makeScales()){if(!this.mod.axes)return;let t=this.backend.grid(),n=this.backend.plot,{xScale:r,yScale:i}=e,a=this.options.labels?.y??M;t.font=`11px ${this.theme.fontFamily}`,t.fillStyle=this.theme.textMuted;let o=this.options.grid??!0,s=J(i.domain[0],i.domain[1],Math.max(3,Math.floor(n.h/48)));if(o){t.strokeStyle=this.theme.grid,t.lineWidth=1,t.beginPath();for(let e of s){let r=Math.round(i(e))+.5;t.moveTo(n.x,r),t.lineTo(n.x+n.w,r)}t.stroke()}t.textAlign=`right`,t.textBaseline=`middle`;for(let e of s)t.fillText(a(e),n.x-10,i(e));t.textBaseline=`top`;let c=this.data;if(c.kind===`category`||c.kind===`waterfall`){t.textAlign=`center`;let e=c.categories,r=c.kind===`category`?e.length:c.bars.length,i=n.w/Math.max(1,r);for(let a=0;a<r;a++)t.fillText(e[a]??``,n.x+i*(a+.5),n.y+n.h+6)}else if(c.kind===`xy`||c.kind===`ohlc`){let e=this.options.labels?.x??M,i=J(r.domain[0],r.domain[1],Math.max(3,Math.floor(n.w/90)));for(let a of i){let i=r(a);t.textAlign=i<n.x+24?`left`:i>n.x+n.w-24?`right`:`center`,t.fillText(e(a),i,n.y+n.h+6)}}if(this.options.type===`bar`||this.options.type===`combo`){let e=Math.round(i(0))+.5;e>=n.y&&e<=n.y+n.h+1&&(t.strokeStyle=this.theme.axisBaseline,t.lineWidth=1,t.beginPath(),t.moveTo(n.x,e),t.lineTo(n.x+n.w,e),t.stroke())}this.backend.blitGrid()}render(e){this.backend.begin();let t=this.makeScales();this.drawStatic(t),this.gpu?this.gpuRender(e,t):this.mod.render(this.renderContext(e,t)),this.hover&&this.drawHover(this.hover,t.yScale)}gpuRender(e,t){let n=this.gpu,r=this.data,i=Ve[this.options.type];if(!n||n.unavailable||!i||r.kind!==`xy`){this.mod.render(this.renderContext(e,t));return}n.syncData(r,this.dataRev);let a={x:t.xScale.domain,y:t.yScale.domain},o=this.options.flow?v:0;n.begin(this.backend.plot,e,o);for(let e=0;e<r.series.length;e++){let o=r.series[e];o&&(i===`points`?n.points(e,o.color,2.5,.65,a):(i===`area`&&n.area(e,o.color,Math.max(0,t.yScale.domain[0]),a),n.line(e,o.color,2,a)))}n.end()}drawHover(e,t=this.makeScales().yScale){let n=this.backend.overlay,r=this.backend.plot;if(this.backend.beginOverlay(),e.kind===`point`||e.kind===`candle`){n.strokeStyle=this.theme.crosshair,n.lineWidth=1,n.beginPath();let i=Math.round(e.px)+.5;n.moveTo(i,r.y),n.lineTo(i,r.y+r.h),n.stroke();let a=this.data;if(e.kind===`point`&&(a.kind===`xy`||a.kind===`category`))for(let r of e.values){let i=a.series.find(e=>e.label===r.label&&e.color===r.color),o=i?`y`in i?i.y[e.index]:i.values[e.index]:r.y;n.fillStyle=r.color,n.strokeStyle=this.theme.bg,n.lineWidth=2,n.beginPath(),n.arc(e.px,t(o),4,0,Math.PI*2),n.fill(),n.stroke()}}else if(e.kind===`bar`)n.fillStyle=l(this.theme.text,.12),n.fillRect(e.rect.x,e.rect.y,e.rect.w,e.rect.h);else{n.fillStyle=l(e.color,.25);let t=this.data;if(t.kind===`donut`){let i=r.x+r.w/2,a=r.y+r.h/2,o=Math.min(r.w,r.h)/2,s=o*.65,c=-Math.PI/2;for(let r=0;r<t.slices.length;r++){let l=t.slices[r];if(!l)continue;let u=t.total>0?l.value/t.total:0,d=c+u*Math.PI*2;r===e.index&&(n.beginPath(),n.arc(i,a,o,c,d),n.arc(i,a,s,d,c,!0),n.closePath(),n.fill()),c=d}}}}applyHover(e,t){let n=this.mod.hit;if(!n)return;let r=n(this.renderContext(1),e,t);if(!r){this.hover&&(this.hover=null,this.backend.beginOverlay(),this.tooltip?.hide(),this.options.onHover?.(null));return}if(this.hover=r,this.drawHover(r),this.options.onHover?.(r),!this.tooltip)return;let i=this.options.labels?.y??M;if(r.kind===`point`){let e=this.options.labels?.x??M;this.tooltip.show(r.px,r.py,r.values.map(e=>({color:e.color,label:e.label,value:i(e.y)})),r.title??e(r.x))}else if(r.kind===`bar`)this.tooltip.show(r.px,r.py,[{color:r.color,label:r.label,value:i(r.value)}],r.category);else if(r.kind===`candle`){let e=this.options.labels?.x??M;this.tooltip.show(r.px,r.py,[{label:`Open`,value:i(r.open)},{label:`High`,value:i(r.high)},{label:`Low`,value:i(r.low)},{label:`Close`,value:i(r.close)}],e(r.x))}else this.tooltip.show(r.px,r.py,[{color:r.color,label:r.label,value:i(r.value)}],`${Math.round(r.share*100)}%`)}resolveAnimDur(){if(this.reduced)return 0;let e=this.options.animate??!0;return typeof e==`number`?Math.max(0,e):e?this.options.flow?Math.min(1e4,Math.max(60,this.estInterval)):400:0}startAnimation(e=this.domains()){this.animDur=this.resolveAnimDur(),this.viewFrom={x:[this.view.x[0],this.view.x[1]],y:[this.view.y[0],this.view.y[1]]},this.viewTo=e,this.animStart=-1,W.add(this.frame)}setData(e){let t=this.data;this.data=this.normalize(e,t),this.dataRev++,this.maybeInitGpu();let n=this.layout();this.startAnimation(n)}append(e,t){let n=this.data;if(n.kind!==`xy`)throw Error(`[resolvcharts] append() requires xy data (line/area/scatter/sparkline)`);let r=typeof performance>`u`?Date.now():performance.now();if(this.lastAppendAt>0){let e=r-this.lastAppendAt;e>0&&e<6e4&&(this.estInterval=this.estInterval*.7+e*.3)}this.lastAppendAt=r;let i=Array.isArray(t)?t:[t],a=n.sortedX.length,o=this.options.window,s=this.options.maxPoints==null?o==null?void 0:o+3:this.options.maxPoints+3,c=s==null?0:Math.max(0,a+1-s),l=a+1-c,u=c===1,d;u?(d=n.sortedX,d.copyWithin(0,1),d[a-1]=e):(d=new Float64Array(l),d.set(n.sortedX.subarray(c)),d[l-1]=e);let f=n.series.map((e,t)=>{let n=i[t]??e.y[a-1]??0,r,o;return u?(e.y.copyWithin(0,1),o=e.y,r=e.prevY&&e.prevY.length===l?e.prevY:new Float64Array(l),r.set(o),r[l-1]=n):(r=new Float64Array(l),r.set(e.y.subarray(c)),r[l-1]=n,o=new Float64Array(l),o.set(e.y.subarray(c)),o[l-1]=l>1?r[l-2]:r[l-1]),{label:e.label,color:e.color,y:r,prevY:o,pathCache:null}}),p={kind:`xy`,sortedX:d,series:f},m=l>1&&e<d[l-2];m&&He(p),this.data=p,m?this.dataRev++:this.gpu&&!this.gpu.unavailable&&(this.gpu.appended(e,n.series.map((e,t)=>i[t]??e.y[a-1]),n.series.map(e=>e.y[a-1]),c)||this.dataRev++),this.maybeInitGpu(),this.pendingView=!0,W.add(this.frame)}resize(){let e=this.el.clientWidth||320,t=this.el.clientHeight||(this.options.type===`sparkline`?32:240);(e!==this.backend.width||t!==this.backend.height||this.backend.dpr!==(window.devicePixelRatio||1))&&(this.backend.resize(e,t),this.gpu?.setSize(e,t,this.backend.dpr),this.rect=null,this.layout(),this.animStart=null,W.add(e=>(this.render(1),!1)))}destroy(){this.destroyed=!0,W.remove(this.frame),this.ro?.disconnect(),this.el.removeEventListener(`pointermove`,this.onMove),this.el.removeEventListener(`pointerleave`,this.onLeave),window.removeEventListener(`scroll`,this.onScroll,!0),this.tooltip?.destroy(),this.gpu?.destroy(),this.backend.destroy()}};function He(e){let t=e.sortedX.length,n=new Uint32Array(t);for(let e=0;e<t;e++)n[e]=e;let r=e.sortedX;n.sort((e,t)=>r[e]-r[t]);let i=new Float64Array(t);for(let e=0;e<t;e++)i[e]=r[n[e]];e.sortedX=i;for(let r of e.series){let e=new Float64Array(t),i=r.prevY?new Float64Array(t):null;for(let a=0;a<t;a++){let t=n[a];e[a]=r.y[t],i&&r.prevY&&(i[a]=r.prevY[t])}r.y=e,r.prevY=i}}function Ue(e,t){return new $(e,t)}return e.Chart=$,e.boundDomain=H,e.computeTicks=J,e.createChart=Ue,e.darkTheme=ue,e.decimateM4=p,e.extent=B,e.formatNumber=A,e.formatSI=M,e.lightTheme=K,e.linearScale=z,e.nearestIndex=m,e.padDomain=V,e.resolveTheme=pe,e})({});
|
|
270
|
+
`,He=40,Ue=72,We=516,Ge=9,Q=172,Ke=160,qe=1,Je=7,Ye=256,Xe=262144,Ze=12,$=class e{get unavailable(){return this.dead||this.recovering}constructor(e,t,n){this.dpr=1,this.slots=[],this.slotCount=0,this.appliedRev=-1,this.draws=[],this.cmps=[],this.uOff=0,this.stamp=0,this.plotR={x:0,y:0,w:1,h:1},this.cols=1,this.t=1,this.flow=0,this.tailScratch=/* @__PURE__ */ new Float32Array(4),this.gpuMs=null,this.querySet=null,this.queryBuf=null,this.readBuf=null,this.reading=!1,this.timing=!1,this.destroyed=!1,this.dead=!1,this.recovering=!1,this.opts=n,this.timing=!!n.timing,this.canvas=t,t.style.cssText=`position:absolute;inset:0;width:100%;height:100%;display:block;pointer-events:none`;let r=t.getContext(`webgpu`);if(!r)throw Error(`resolvcharts: webgpu context unavailable`);this.ctx=r,this.device=e,this.format=navigator.gpu.getPreferredCanvasFormat(),this.setup(e)}static async create(t={}){let n=await Ne(t);if(!n)return null;let r=document.createElement(`canvas`);try{return new e(n,r,t)}catch{return null}}setup(e){this.device=e,this.layout=e.createBindGroupLayout({entries:[{binding:0,visibility:Je,buffer:{type:`uniform`,hasDynamicOffset:!0}}]}),this.decLayout=e.createBindGroupLayout({entries:[{binding:0,visibility:4,buffer:{type:`read-only-storage`}},{binding:1,visibility:4,buffer:{type:`read-only-storage`}},{binding:2,visibility:4,buffer:{type:`storage`}}]}),this.ubuf=e.createBuffer({size:Xe,usage:Ue}),this.ubiGroup=e.createBindGroup({layout:this.layout,entries:[{binding:0,resource:{buffer:this.ubuf,size:112}}]});let t=e.createPipelineLayout({bindGroupLayouts:[this.layout]}),n=e.createPipelineLayout({bindGroupLayouts:[this.layout,this.decLayout]}),r=(n,r,i)=>e.createRenderPipeline({layout:t,vertex:{module:e.createShaderModule({code:n}),entryPoint:`vs`,buffers:i},fragment:{module:e.createShaderModule({code:n}),entryPoint:`fs`,targets:[{format:this.format,blend:Qe}]},primitive:{topology:r}}),i={arrayStride:8,stepMode:`instance`,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},a={arrayStride:8,stepMode:`instance`,attributes:[{shaderLocation:1,offset:0,format:`float32x2`}]},o={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:2,offset:0,format:`float32`}]},s={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:3,offset:0,format:`float32`}]},c={arrayStride:4,stepMode:`instance`,attributes:[{shaderLocation:1,offset:0,format:`float32`}]},l={arrayStride:8,stepMode:`vertex`,attributes:[{shaderLocation:0,offset:0,format:`float32x2`}]},u={arrayStride:4,stepMode:`vertex`,attributes:[{shaderLocation:1,offset:0,format:`float32`}]};this.pipes={line:r(Ie,`triangle-list`,[i,a,o,s]),lineFlat:r(Le,`triangle-list`,[i,a]),area:r(Re,`triangle-strip`,[l,u]),areaFlat:r(ze,`triangle-strip`,[l]),points:r(Be,`triangle-list`,[i,c]),dec:e.createComputePipeline({layout:n,compute:{module:e.createShaderModule({code:Ve}),entryPoint:`dec`}})},this.timing&&e.features.has(`timestamp-query`)&&(this.querySet=e.createQuerySet({type:`timestamp`,count:2}),this.queryBuf=e.createBuffer({size:16,usage:We}),this.readBuf=e.createBuffer({size:16,usage:Ge})),e.lost.then(e=>this.onLost(e))}onLost(e){this.destroyed||(e.reason===`destroyed`?this.dead=!0:(this.recovering=!0,Ne(this.opts).then(e=>{if(!e||this.destroyed)this.fail();else try{this.teardownResources(),this.setup(e);try{this.configure()}catch{let e=document.createElement(`canvas`);e.width=this.canvas.width,e.height=this.canvas.height,this.canvas.replaceWith(e),this.canvas=e;let t=e.getContext(`webgpu`);if(!t)throw Error(`webgpu context lost`);this.ctx=t,this.configure()}this.appliedRev=-1,this.recovering=!1}catch{this.fail()}})))}fail(){this.dead=!0,this.recovering=!1,this.destroy()}teardownResources(){for(let e of this.slots)e.xy.destroy(),e.prev.destroy(),e.scratch?.destroy(),e.dec?.destroy();this.slots=[],this.slotCount=0,this.ubuf.destroy(),this.queryBuf?.destroy(),this.readBuf?.destroy(),this.querySet?.destroy(),this.querySet=null,this.queryBuf=null,this.readBuf=null}configure(){this.ctx.configure({device:this.device,format:this.format,alphaMode:`premultiplied`})}setSize(e,t,n){this.dpr=n,this.canvas.width=Math.max(1,Math.round(e*n)),this.canvas.height=Math.max(1,Math.round(t*n)),this.unavailable||this.configure()}upload(e,t,n){let r=Math.min(t.length,n.y.length),i=r>0?t[0]:0,a=1/((r>0?t[r-1]-i:0)||Math.max(1,Math.abs(i),1)),o=1/0,s=-1/0;for(let e=0;e<r;e++){let t=n.y[e];t<o&&(o=t),t>s&&(s=t)}let c=o===1/0?0:o,l=1/(s-o||Math.max(1,Math.abs(c))),u=this.slots[e],d=Math.max(1024,Math.ceil(r*1.25));!u||u.cap<r?(u?.xy.destroy(),u?.prev.destroy(),u?.dec?.destroy(),u={n:r,cap:d,start:0,enc:{xr:i,xu:a,yr:c,yu:l},encXY:new Float32Array(d*2),encPrev:new Float32Array(d),xy:this.device.createBuffer({size:d*8,usage:Q}),prev:this.device.createBuffer({size:d*4,usage:Q}),scratch:null,scratchN:0,dec:null,decCols:0,bg:null,decStamp:-1},this.slots[e]=u):(u.n=r,u.start=0,u.enc={xr:i,xu:a,yr:c,yu:l},u.bg=null,u.decStamp=-1);let{encXY:f,encPrev:p}=u,m=n.prevY;for(let e=0;e<r;e++)f[2*e]=(t[e]-i)*a,f[2*e+1]=(n.y[e]-c)*l,p[e]=m?(m[e]-c)*l:0;this.device.queue.writeBuffer(u.xy,0,f,0,r*2),this.device.queue.writeBuffer(u.prev,0,p,0,r)}syncData(e,t){if(!(this.unavailable||t===this.appliedRev&&this.slotCount===e.series.length)){for(let t=0;t<e.series.length;t++){let n=e.series[t];n&&this.upload(t,e.sortedX,n)}this.slotCount=e.series.length,this.appliedRev=t}}appended(e,t,n,r){if(this.unavailable)return!1;let i=this.device.queue;for(let a=0;a<this.slotCount;a++){let o=this.slots[a];if(!o)return!1;let s=o.n-r+1;s>o.cap&&this.grow(o,s),o.start=(o.start+r)%o.cap,o.n=s;let c=(o.start+o.n-1)%o.cap,{xr:l,xu:u,yr:d,yu:f}=o.enc,p=(e-l)*u,m=((t[a]??0)-d)*f,h=((n[a]??0)-d)*f,g=this.tailScratch;if(g[0]=p,g[1]=m,i.writeBuffer(o.xy,c*8,g,0,2),o.encXY[2*c]=p,o.encXY[2*c+1]=m,g[0]=h,i.writeBuffer(o.prev,c*4,g,0,1),o.encPrev[c]=h,o.n>1){let e=(c+o.cap-1)%o.cap;i.writeBuffer(o.prev,e*4,g,0,1),o.encPrev[e]=h}}return!0}grow(e,t){let n=Math.max(e.cap*2,t+1024),r=e.cap-e.start,i=this.device.createCommandEncoder(),a=this.device.createBuffer({size:n*8,usage:Q}),o=this.device.createBuffer({size:n*4,usage:Q});i.copyBufferToBuffer(e.xy,e.start*8,a,0,r*8),e.start>0&&i.copyBufferToBuffer(e.xy,0,a,r*8,e.start*8),i.copyBufferToBuffer(e.prev,e.start*4,o,0,r*4),e.start>0&&i.copyBufferToBuffer(e.prev,0,o,r*4,e.start*4),this.device.queue.submit([i.finish()]),e.xy.destroy(),e.prev.destroy(),e.xy=a,e.prev=o;let s=new Float32Array(n*2),c=new Float32Array(n);s.set(e.encXY.subarray(e.start*2,e.cap*2),0),s.set(e.encXY.subarray(0,e.start*2),r*2),c.set(e.encPrev.subarray(e.start,e.cap),0),c.set(e.encPrev.subarray(0,e.start),r),e.encXY=s,e.encPrev=c,e.cap=n,e.start=0,e.bg=null}begin(e,t=1,n=0){this.plotR=e,this.t=t,this.flow=n,this.cols=Math.max(1,Math.ceil(e.x+e.w)),this.stamp++,this.draws.length=0,this.cmps.length=0,this.uOff=0}mapFor(e,t){let{xr:n,xu:r,yr:i,yu:a}=e.enc,o=this.plotR,s=(t.x[0]-n)*r,c=(t.x[1]-n)*r,l=o.w/(c-s||1e-30),u=o.x-s*l,d=(t.y[0]-i)*a,f=(t.y[1]-i)*a,p=o.h/(f-d||1e-30);return[l,u,p,o.y+f*p]}writeU(e,t,n,r,i,a){let o=this.uOff;this.uOff+=Ye;let s=/* @__PURE__ */ new Float32Array(28);s.set([this.canvas.width,this.canvas.height,this.dpr,0]);let[c,l,u,d]=je(e);s.set([c,l,u,d*t],4),s.set(n,8),s.set(r,12);let f=i.n>1?this.flow/(i.n-1):0;return s.set([this.t,this.flow,f,0],16),s.set([i.start,i.cap,i.n,0],20),s.set([a[0],a[1],0,0],24),this.device.queue.writeBuffer(this.ubuf,o,s),o}decimateWanted(e){return e.n>this.cols*2}ensureDec(e){if(e.dec&&e.decCols>=this.cols)return;e.dec?.destroy();let t=Math.max(this.cols,Math.ceil(this.canvas.width/this.dpr));e.dec=this.device.createBuffer({size:t*Ze*8,usage:Ke}),e.decCols=t,e.bg=null}dispatchDec(e,t,n){if(e.decStamp===this.stamp)return;e.decStamp=this.stamp,this.ensureDec(e),e.bg||=this.device.createBindGroup({layout:this.decLayout,entries:[{binding:0,resource:{buffer:e.xy}},{binding:1,resource:{buffer:e.prev}},{binding:2,resource:{buffer:e.dec}}]});let r=this.writeU(`#ffffff`,1,[0,0,0,0],t,e,[this.cols,n]);this.cmps.push({slot:e,u:r})}line(e,t,n,r){let i=this.slots[e];if(!i||i.n<2)return;let a=this.mapFor(i,r);if(this.decimateWanted(i)){this.dispatchDec(i,a,0);let e=this.writeU(t,1,[n,0,0,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.lineFlat,vbufs:[{buf:i.dec,off:0},{buf:i.dec,off:8}],u:e,verts:6,insts:4*this.cols-1});return}let o=this.writeU(t,1,[n,0,0,0],a,i,[0,0]),s=(e,t,n)=>({pipe:this.pipes.line,vbufs:[{buf:i.xy,off:e*8},{buf:i.xy,off:t*8},{buf:i.prev,off:e*4},{buf:i.prev,off:t*4}],u:o,verts:6,insts:n});if(i.start+i.n<=i.cap){this.draws.push(s(i.start,i.start+1,i.n-1));return}let c=i.cap-i.start;c>1&&this.draws.push(s(i.start,i.start+1,c-1)),this.draws.push(s(i.cap-1,0,1));let l=i.n-1-c;l>0&&this.draws.push(s(0,1,l))}area(e,t,n,r){let i=this.slots[e];if(!i||i.n<2)return;let a=this.mapFor(i,r),o=(n-i.enc.yr)*i.enc.yu,s=a[3]-o*a[2],c=this.plotR;if(this.decimateWanted(i)){this.dispatchDec(i,a,o);let e=this.writeU(t,1,[s,c.y,c.h,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.areaFlat,vbufs:[{buf:i.dec,off:this.cols*4*8}],u:e,verts:8*this.cols,insts:1});return}let l=i.n,u=new Float32Array(l*4),d=new Float32Array(l*2);for(let e=0;e<l;e++){let t=(i.start+e)%i.cap;u[4*e]=i.encXY[2*t],u[4*e+1]=i.encXY[2*t+1],u[4*e+2]=u[4*e],u[4*e+3]=u[4*e+1],d[2*e]=i.encPrev[t],d[2*e+1]=d[2*e]}(!i.scratch||i.scratchN<l)&&(i.scratch?.destroy(),i.scratch=this.device.createBuffer({size:Math.max(4096,l*24),usage:He}),i.scratchN=l);let f=l*16;this.device.queue.writeBuffer(i.scratch,0,u),this.device.queue.writeBuffer(i.scratch,f,d);let p=this.writeU(t,1,[s,c.y,c.h,0],a,i,[0,0]);this.draws.push({pipe:this.pipes.area,vbufs:[{buf:i.scratch,off:0},{buf:i.scratch,off:f}],u:p,verts:l*2,insts:1})}points(e,t,n,r,i){let a=this.slots[e];if(!a||a.n<1)return;let o=this.mapFor(a,i),s=this.writeU(t,r,[n,0,0,0],o,a,[0,0]),c=(e,t)=>({pipe:this.pipes.points,vbufs:[{buf:a.xy,off:e*8},{buf:a.prev,off:e*4}],u:s,verts:6,insts:t});if(a.start+a.n<=a.cap){this.draws.push(c(a.start,a.n));return}let l=a.cap-a.start;this.draws.push(c(a.start,l)),a.n-l>0&&this.draws.push(c(0,a.n-l))}end(){if(!(this.unavailable||!this.draws.length&&!this.cmps.length))try{let e=this.device.createCommandEncoder();if(this.cmps.length){let t=e.beginComputePass();t.setPipeline(this.pipes.dec);for(let e of this.cmps)t.setBindGroup(0,this.ubiGroup,[e.u]),t.setBindGroup(1,e.slot.bg),t.dispatchWorkgroups(Math.ceil(this.cols/64));t.end()}if(this.draws.length){let t=this.ctx.getCurrentTexture().createView(),n=this.dpr,r=this.plotR,i=e.beginRenderPass({colorAttachments:[{view:t,loadOp:`clear`,storeOp:`store`,clearValue:{r:0,g:0,b:0,a:0}}],...this.querySet?{timestampWrites:{querySet:this.querySet,beginningOfPassWriteIndex:0,endOfPassWriteIndex:1}}:{}});i.setScissorRect(Math.max(0,Math.floor(r.x*n)),Math.max(0,Math.floor(r.y*n)),Math.max(1,Math.floor(r.w*n)),Math.max(1,Math.floor(r.h*n)));for(let e of this.draws){i.setPipeline(e.pipe),i.setBindGroup(0,this.ubiGroup,[e.u]);for(let t=0;t<e.vbufs.length;t++){let n=e.vbufs[t];n&&i.setVertexBuffer(t,n.buf,n.off)}i.draw(e.verts,e.insts)}i.end()}let t=this.querySet,n=this.queryBuf,r=this.readBuf;t&&n&&r&&!this.reading?(e.resolveQuerySet(t,0,2,n,0),e.copyBufferToBuffer(n,0,r,0,16),this.reading=!0,this.device.queue.submit([e.finish()]),r.mapAsync(qe).then(()=>{let e=new BigUint64Array(r.getMappedRange()),t=e[0],n=e[1];t!==void 0&&n!==void 0&&(this.gpuMs=Number(n-t)/1e6),r.unmap(),this.reading=!1},()=>{this.reading=!1})):this.device.queue.submit([e.finish()])}catch{}}destroy(){this.destroyed=!0;for(let e of this.slots)e.xy.destroy(),e.prev.destroy(),e.scratch?.destroy(),e.dec?.destroy();this.slots=[],this.ubuf?.destroy(),this.queryBuf?.destroy(),this.readBuf?.destroy(),this.querySet?.destroy();try{this.ctx.unconfigure()}catch{}this.canvas.remove()}},Qe={color:{srcFactor:`src-alpha`,dstFactor:`one-minus-src-alpha`,operation:`add`},alpha:{srcFactor:`one`,dstFactor:`one-minus-src-alpha`,operation:`add`}}}));let et={line:{render:e=>S(e,!1),hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0},area:{render:e=>S(e,!0),hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0},scatter:{render:ge,hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0},bubble:{render:T,hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0},rangearea:{render:he,hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0},pie:{render:L,hit:R,axes:!1,defaultTooltip:!0},radar:{render:fe,hit:pe,axes:!1,defaultTooltip:!0},funnel:{render:le,hit:ue,axes:!1,defaultTooltip:!0},bar:{render:s,hit:c,axes:!0,defaultTooltip:!0},combo:{render:A,hit:(e,t)=>j(e,t),axes:!0,defaultTooltip:!0},sparkline:{render:_e,hit:(e,t)=>C(e,t),axes:!1,defaultTooltip:!1},donut:{render:L,hit:R,axes:!1,defaultTooltip:!0},candle:{render:e=>E(e,!1),hit:(e,t)=>D(e,t),axes:!0,defaultTooltip:!0},ohlc:{render:e=>E(e,!0),hit:(e,t)=>D(e,t),axes:!0,defaultTooltip:!0},waterfall:{render:be,hit:xe,axes:!0,defaultTooltip:!0},baseline:{render:w,hit:(e,t)=>C(e,t),axes:!0,defaultTooltip:!0}},tt={line:`line`,area:`area`,sparkline:`line`,scatter:`points`};var nt=class{constructor(e,t){this.tooltip=null,this.ro=null,this.rect=null,this.pointer=null,this.hover=null,this.animStart=null,this.animDur=0,this.view={x:[0,1],y:[0,1]},this.viewFrom=null,this.viewTo={x:[0,1],y:[0,1]},this.reduced=!1,this.destroyed=!1,this.pendingView=!1,this.gpu=null,this.gpuInit=!1,this.dataRev=0,this.lastAppendAt=0,this.estInterval=400,this.onScroll=()=>{this.rect=null},this.frame=e=>{if(this.destroyed)return!1;this.pendingView&&(this.pendingView=!1,this.viewFrom={x:[this.view.x[0],this.view.x[1]],y:[this.view.y[0],this.view.y[1]]},this.viewTo=this.layout(),this.animDur=this.resolveAnimDur(),this.animStart=-1);let t=!1;if(this.animStart!==null){this.animStart===-1&&(this.animStart=e);let n=this.animDur<=0?1:Math.min(1,(e-this.animStart)/this.animDur),r=De(n);this.lerpView(r),this.render(r),n<1?t=!0:this.animStart=null}return this.pointer&&=(this.applyHover(this.pointer.x,this.pointer.y),null),t},this.onMove=e=>{this.rect||=this.el.getBoundingClientRect(),this.pointer={x:e.clientX-this.rect.left,y:e.clientY-this.rect.top},J.add(this.frame)},this.onLeave=()=>{this.pointer=null,this.hover&&(this.hover=null,this.backend.beginOverlay(),this.tooltip?.hide(),this.options.onHover?.(null))},this.el=e,this.options=t,this.theme=oe(t.theme,t.accent),this.mod=et[t.type],getComputedStyle(e).position===`static`&&(e.style.position=`relative`),t.height&&(e.style.height=`${t.height}px`);let n=e.clientWidth||320,r=e.clientHeight||(t.type===`sparkline`?32:240);this.backend=new Ce(e,n,r,t.canvas),this.reduced=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,(t.tooltip??this.mod.defaultTooltip)&&(this.tooltip=new Ae(e,this.theme)),this.data=this.normalize(t.data,null),this.maybeInitGpu(),this.bindEvents();let i=this.layout();this.view={x:[...i.x],y:[...i.y]},this.viewTo={x:[...i.x],y:[...i.y]},this.startAnimation(i)}maybeInitGpu(){if(this.gpu||this.gpuInit||this.destroyed||!tt[this.options.type])return;let e=this.options.renderer??`auto`;if(e===`auto`||e===`webgpu`){if(e===`auto`){let e=this.data;if((e.kind===`xy`?e.sortedX.length*Math.max(1,e.series.length):0)<(this.options.gpuThreshold??1e5))return}this.gpuInit=!0,Promise.resolve().then(()=>($e(),Fe)).then(({GpuSeries:e})=>e.create(this.options.gpu).then(e=>{!e||this.destroyed?e?.destroy():(e.setSize(this.backend.width,this.backend.height,this.backend.dpr),this.backend.overlayCanvas.before(e.canvas),this.gpu=e,J.add(e=>(this.render(1),!1)))}))}}normalize(e,t){let n=this.options.type;if(n===`candle`||n===`ohlc`){let t=e,n=t.candles.length,r=null;for(let e=1;e<n;e++)if((t.candles[e]?.x??e)<(t.candles[e-1]?.x??e-1)){r=new Uint32Array(n);for(let e=0;e<n;e++)r[e]=e;r.sort((e,n)=>(t.candles[e]?.x??0)-(t.candles[n]?.x??0));break}let i=new Float64Array(n),a=new Float64Array(n),o=new Float64Array(n),s=new Float64Array(n),c=new Float64Array(n),l=!1,u=new Float64Array(n);for(let e=0;e<n;e++){let n=t.candles[r?r[e]:e];i[e]=n?.x??e,a[e]=n?.open??0,o[e]=n?.high??0,s[e]=n?.low??0,c[e]=n?.close??0,u[e]=n?.volume??0,n?.volume!=null&&n.volume>0&&(l=!0)}return{kind:`ohlc`,x:i,open:a,high:o,low:s,close:c,volume:l?u:null}}if(n===`waterfall`){let t=e,n=new Set(t.totals??[]),r=0,i=t.categories.map((e,i)=>{let a=t.values[i]??0;if(n.has(i)){let e={start:0,end:a,value:a,total:!0};return r=a,e}let o={start:r,end:r+a,value:a,total:!1};return r+=a,o});return{kind:`waterfall`,categories:[...t.categories],bars:i}}if(n===`donut`||n===`pie`){let t=e.slices.map((e,t)=>({label:e.label,value:e.value,color:B(this.theme,t,e.color)}));return{kind:`donut`,slices:t,total:t.reduce((e,t)=>e+Math.max(0,t.value),0)}}if(n===`bar`||n===`combo`||n===`radar`||n===`funnel`){let n=e,r=t?.kind===`category`?t.series:[];return{kind:`category`,categories:[...n.categories],series:n.series.map((e,t)=>({label:e.label??`Series ${t+1}`,color:B(this.theme,t,e.color),kind:e.kind??`column`,values:Float64Array.from(e.values),prevValues:r[t]?.values??null}))}}let r=e,i=Float64Array.from(r.x),a=i.length,o=null;for(let e=1;e<a;e++)if(i[e]<i[e-1]){o=new Uint32Array(a);for(let e=0;e<a;e++)o[e]=e;o.sort((e,t)=>i[e]-i[t]);break}let s=o?new Float64Array(a):i;if(o)for(let e=0;e<a;e++)s[e]=i[o[e]];let c=t?.kind===`xy`?t.series:[];return{kind:`xy`,sortedX:s,series:r.series.map((e,t)=>{let n=e=>{if(!e)return null;let t=new Float64Array(a);if(o)for(let n=0;n<a;n++)t[n]=e[o[n]];else for(let n=0;n<a;n++)t[n]=e[n];return t},r=n(e.y)??new Float64Array(a);return{label:e.label??`Series ${t+1}`,color:B(this.theme,t,e.color),y:r,prevY:c[t]?.y??null,r:n(e.r),y2:n(e.y2),prevY2:c[t]?.y2??null,pathCache:null}})}}bindEvents(){this.el.addEventListener(`pointermove`,this.onMove,{passive:!0}),this.el.addEventListener(`pointerleave`,this.onLeave,{passive:!0}),window.addEventListener(`scroll`,this.onScroll,!0),typeof ResizeObserver==`function`&&(this.ro=new ResizeObserver(()=>this.resize()),this.ro.observe(this.el))}layout(){let e=this.backend.width,t=this.backend.height,n=this.mod,r=this.domains();if(!n.axes)return this.backend.setPlot({x:2,y:2,w:e-4,h:t-4}),r;let i=this.backend.main,a=this.options.labels?.y??P,o=Math.max(1,t-8-20),s=this.data.kind===`donut`?[]:Y(r.y[0],r.y[1],Math.max(3,Math.floor(o/48))),c=0;if(s.length){i.font=`11px ${this.theme.fontFamily}`;for(let e of s)c=Math.max(c,i.measureText(a(e)).width);c+=10}let l={x:c,y:8,w:Math.max(1,e-c-8),h:o};return this.backend.setPlot(l),r}domains(){let e=this.data;if(e.kind===`xy`){let t=e.sortedX.length,n=this.options.window??this.options.maxPoints,r=n!=null&&t>n?t-n:0,i=t>0?[e.sortedX[r],e.sortedX[t-1]]:[0,1],a=1/0,o=-1/0;for(let t of e.series){let e=t.y;for(let t=Math.min(r,e.length);t<e.length;t++){let n=e[t];n<a&&(a=n),n>o&&(o=n)}let n=t.y2;if(n)for(let e=Math.min(r,n.length);e<n.length;e++){let t=n[e];t<a&&(a=t),t>o&&(o=t)}}a===1/0&&(a=0,o=1);let s=this.options.type===`area`||this.options.type===`sparkline`;return{x:i,y:this.yDomain(q(a,o,s))}}if(e.kind===`category`){let t=1/0,n=-1/0;if(this.options.stacked){for(let r=0;r<e.categories.length;r++){let i=0,a=0;for(let t of e.series){if(t.kind!==`column`)continue;let e=t.values[r]??0;e>=0?i+=e:a+=e}t=Math.min(t,a),n=Math.max(n,i)}for(let r of e.series){if(r.kind===`column`)continue;let e=K(r.values);t=Math.min(t,e[0]),n=Math.max(n,e[1])}}else for(let r of e.series){let e=K(r.values);t=Math.min(t,e[0]),n=Math.max(n,e[1])}return t===1/0&&(t=0,n=1),{x:[0,e.categories.length],y:this.yDomain(q(t,n,!0))}}if(e.kind===`ohlc`){let t=K(e.x),n=1/0,r=-1/0;for(let t=0;t<e.x.length;t++){let i=e.low[t],a=e.high[t];i<n&&(n=i),a>r&&(r=a)}return n===1/0&&(n=0,r=1),{x:t,y:this.yDomain(q(n,r))}}if(e.kind===`waterfall`){let t=1/0,n=-1/0;for(let r of e.bars)t=Math.min(t,r.start,r.end),n=Math.max(n,r.start,r.end);return t===1/0&&(t=0,n=1),{x:[0,e.bars.length],y:this.yDomain(q(t,n,!0))}}return{x:[0,1],y:this.yDomain([0,1])}}yDomain(e){return we(e,this.options.yMin,this.options.yMax)}lerpView(e){let t=this.viewFrom,n=this.viewTo,r=this.view;!t||e>=1?(r.x[0]=n.x[0],r.x[1]=n.x[1],r.y[0]=n.y[0],r.y[1]=n.y[1]):(r.x[0]=t.x[0]+(n.x[0]-t.x[0])*e,r.x[1]=t.x[1]+(n.x[1]-t.x[1])*e,r.y[0]=t.y[0]+(n.y[0]-t.y[0])*e,r.y[1]=t.y[1]+(n.y[1]-t.y[1])*e)}makeScales(){let e=this.backend.plot,t=this.view,n=this.data.kind===`ohlc`&&this.data.volume?e.h*.18:0;return{xScale:G(t.x[0],t.x[1],e.x,e.x+e.w),yScale:G(t.y[0],t.y[1],e.y+e.h-n,e.y)}}renderContext(e,t=this.makeScales()){let{xScale:n,yScale:r}=t;return{backend:this.backend,ctx:this.backend.main,plot:this.backend.plot,theme:this.theme,opts:this.options,data:this.data,xScale:n,yScale:r,t:e}}drawStatic(e=this.makeScales()){if(!this.mod.axes)return;let t=this.backend.grid(),n=this.backend.plot,{xScale:r,yScale:i}=e,a=this.options.labels?.y??P;t.font=`11px ${this.theme.fontFamily}`,t.fillStyle=this.theme.textMuted;let o=this.options.grid??!0,s=Y(i.domain[0],i.domain[1],Math.max(3,Math.floor(n.h/48)));if(o){t.strokeStyle=this.theme.grid,t.lineWidth=1,t.beginPath();for(let e of s){let r=Math.round(i(e))+.5;t.moveTo(n.x,r),t.lineTo(n.x+n.w,r)}t.stroke()}t.textAlign=`right`,t.textBaseline=`middle`;for(let e of s)t.fillText(a(e),n.x-10,i(e));t.textBaseline=`top`;let c=this.data;if(c.kind===`category`||c.kind===`waterfall`){t.textAlign=`center`;let e=c.categories,r=c.kind===`category`?e.length:c.bars.length,i=n.w/Math.max(1,r);for(let a=0;a<r;a++)t.fillText(e[a]??``,n.x+i*(a+.5),n.y+n.h+6)}else if(c.kind===`xy`||c.kind===`ohlc`){let e=this.options.labels?.x??P,i=Y(r.domain[0],r.domain[1],Math.max(3,Math.floor(n.w/90)));for(let a of i){let i=r(a);t.textAlign=i<n.x+24?`left`:i>n.x+n.w-24?`right`:`center`,t.fillText(e(a),i,n.y+n.h+6)}}if(this.options.type===`bar`||this.options.type===`combo`){let e=Math.round(i(0))+.5;e>=n.y&&e<=n.y+n.h+1&&(t.strokeStyle=this.theme.axisBaseline,t.lineWidth=1,t.beginPath(),t.moveTo(n.x,e),t.lineTo(n.x+n.w,e),t.stroke())}this.backend.blitGrid()}render(e){this.backend.begin();let t=this.makeScales();this.drawStatic(t),this.gpu?this.gpuRender(e,t):this.mod.render(this.renderContext(e,t)),this.hover&&this.drawHover(this.hover,t.yScale)}gpuRender(e,t){let n=this.gpu,r=this.data,i=tt[this.options.type];if(!n||n.unavailable||!i||r.kind!==`xy`){this.mod.render(this.renderContext(e,t));return}n.syncData(r,this.dataRev);let a={x:t.xScale.domain,y:t.yScale.domain},o=this.options.flow?y:0;n.begin(this.backend.plot,e,o);for(let e=0;e<r.series.length;e++){let o=r.series[e];o&&(i===`points`?n.points(e,o.color,2.5,.65,a):(i===`area`&&n.area(e,o.color,Math.max(0,t.yScale.domain[0]),a),n.line(e,o.color,2,a)))}n.end()}drawHover(e,t=this.makeScales().yScale){let n=this.backend.overlay,r=this.backend.plot;if(this.backend.beginOverlay(),e.kind===`point`&&this.options.type===`radar`)me(this.renderContext(1),e);else if(e.kind===`point`||e.kind===`candle`){n.strokeStyle=this.theme.crosshair,n.lineWidth=1,n.beginPath();let i=Math.round(e.px)+.5;n.moveTo(i,r.y),n.lineTo(i,r.y+r.h),n.stroke();let a=this.data;if(e.kind===`point`&&(a.kind===`xy`||a.kind===`category`))for(let r of e.values){let i=a.series.find(e=>e.label===r.label&&e.color===r.color),o=i?`y`in i?i.y[e.index]:i.values[e.index]:r.y;n.fillStyle=r.color,n.strokeStyle=this.theme.bg,n.lineWidth=2,n.beginPath(),n.arc(e.px,t(o),4,0,Math.PI*2),n.fill(),n.stroke()}}else if(e.kind===`bar`)n.fillStyle=l(this.theme.text,.12),n.fillRect(e.rect.x,e.rect.y,e.rect.w,e.rect.h);else{n.fillStyle=l(e.color,.25);let t=this.data;if(t.kind===`donut`){let i=r.x+r.w/2,a=r.y+r.h/2,o=Math.min(r.w,r.h)/2,s=this.options.type===`pie`?0:o*.65,c=-Math.PI/2;for(let r=0;r<t.slices.length;r++){let l=t.slices[r];if(!l)continue;let u=t.total>0?l.value/t.total:0,d=c+u*Math.PI*2;r===e.index&&(n.beginPath(),n.arc(i,a,o,c,d),n.arc(i,a,s,d,c,!0),n.closePath(),n.fill()),c=d}}}}applyHover(e,t){let n=this.mod.hit;if(!n)return;let r=n(this.renderContext(1),e,t);if(!r){this.hover&&(this.hover=null,this.backend.beginOverlay(),this.tooltip?.hide(),this.options.onHover?.(null));return}if(this.hover=r,this.drawHover(r),this.options.onHover?.(r),!this.tooltip)return;let i=this.options.labels?.y??P;if(r.kind===`point`){let e=this.options.labels?.x??P;this.tooltip.show(r.px,r.py,r.values.map(e=>({color:e.color,label:e.label,value:i(e.y)})),r.title??e(r.x))}else if(r.kind===`bar`)this.tooltip.show(r.px,r.py,[{color:r.color,label:r.label,value:i(r.value)}],r.category);else if(r.kind===`candle`){let e=this.options.labels?.x??P;this.tooltip.show(r.px,r.py,[{label:`Open`,value:i(r.open)},{label:`High`,value:i(r.high)},{label:`Low`,value:i(r.low)},{label:`Close`,value:i(r.close)}],e(r.x))}else this.tooltip.show(r.px,r.py,[{color:r.color,label:r.label,value:i(r.value)}],`${Math.round(r.share*100)}%`)}resolveAnimDur(){if(this.reduced)return 0;let e=this.options.animate??!0;return typeof e==`number`?Math.max(0,e):e?this.options.flow?Math.min(1e4,Math.max(60,this.estInterval)):400:0}startAnimation(e=this.domains()){this.animDur=this.resolveAnimDur(),this.viewFrom={x:[this.view.x[0],this.view.x[1]],y:[this.view.y[0],this.view.y[1]]},this.viewTo=e,this.animStart=-1,J.add(this.frame)}setData(e){let t=this.data;this.data=this.normalize(e,t),this.dataRev++,this.maybeInitGpu();let n=this.layout();this.startAnimation(n)}append(e,t){let n=this.data;if(n.kind!==`xy`)throw Error(`[resolvcharts] append() requires xy data (line/area/scatter/bubble/rangearea/sparkline)`);let r=typeof performance>`u`?Date.now():performance.now();if(this.lastAppendAt>0){let e=r-this.lastAppendAt;e>0&&e<6e4&&(this.estInterval=this.estInterval*.7+e*.3)}this.lastAppendAt=r;let i=Array.isArray(t)?t:[t],a=n.sortedX.length,o=this.options.window,s=this.options.maxPoints==null?o==null?void 0:o+3:this.options.maxPoints+3,c=s==null?0:Math.max(0,a+1-s),l=a+1-c,u=c===1,d;u?(d=n.sortedX,d.copyWithin(0,1),d[a-1]=e):(d=new Float64Array(l),d.set(n.sortedX.subarray(c)),d[l-1]=e);let f=n.series.map((e,t)=>{let n=i[t]??e.y[a-1]??0,r,o;u?(e.y.copyWithin(0,1),o=e.y,r=e.prevY&&e.prevY.length===l?e.prevY:new Float64Array(l),r.set(o),r[l-1]=n):(r=new Float64Array(l),r.set(e.y.subarray(c)),r[l-1]=n,o=new Float64Array(l),o.set(e.y.subarray(c)),o[l-1]=l>1?r[l-2]:r[l-1]);let s=null;e.r&&(s=new Float64Array(l),s.set(e.r.subarray(c)),s[l-1]=e.r[a-1]);let d=null,f=null;return e.y2&&(d=new Float64Array(l),d.set(e.y2.subarray(c)),d[l-1]=e.y2[a-1],f=new Float64Array(l),f.set(e.y2.subarray(c)),f[l-1]=l>1?d[l-2]:d[l-1]),{label:e.label,color:e.color,y:r,prevY:o,r:s,y2:d,prevY2:f,pathCache:null}}),p={kind:`xy`,sortedX:d,series:f},m=l>1&&e<d[l-2];m&&rt(p),this.data=p,m?this.dataRev++:this.gpu&&!this.gpu.unavailable&&(this.gpu.appended(e,n.series.map((e,t)=>i[t]??e.y[a-1]),n.series.map(e=>e.y[a-1]),c)||this.dataRev++),this.maybeInitGpu(),this.pendingView=!0,J.add(this.frame)}resize(){let e=this.el.clientWidth||320,t=this.el.clientHeight||(this.options.type===`sparkline`?32:240);(e!==this.backend.width||t!==this.backend.height||this.backend.dpr!==(window.devicePixelRatio||1))&&(this.backend.resize(e,t),this.gpu?.setSize(e,t,this.backend.dpr),this.rect=null,this.layout(),this.animStart=null,J.add(e=>(this.render(1),!1)))}destroy(){this.destroyed=!0,J.remove(this.frame),this.ro?.disconnect(),this.el.removeEventListener(`pointermove`,this.onMove),this.el.removeEventListener(`pointerleave`,this.onLeave),window.removeEventListener(`scroll`,this.onScroll,!0),this.tooltip?.destroy(),this.gpu?.destroy(),this.backend.destroy()}};function rt(e){let t=e.sortedX.length,n=new Uint32Array(t);for(let e=0;e<t;e++)n[e]=e;let r=e.sortedX;n.sort((e,t)=>r[e]-r[t]);let i=new Float64Array(t);for(let e=0;e<t;e++)i[e]=r[n[e]];e.sortedX=i;for(let r of e.series){let e=new Float64Array(t),i=r.prevY?new Float64Array(t):null,a=r.r?new Float64Array(t):null,o=r.y2?new Float64Array(t):null,s=r.prevY2?new Float64Array(t):null;for(let c=0;c<t;c++){let t=n[c];e[c]=r.y[t],i&&r.prevY&&(i[c]=r.prevY[t]),a&&r.r&&(a[c]=r.r[t]),o&&r.y2&&(o[c]=r.y2[t]),s&&r.prevY2&&(s[c]=r.prevY2[t])}r.y=e,r.prevY=i,r.r=a,r.y2=o,r.prevY2=s}}function it(e,t){return new nt(e,t)}return e.Chart=nt,e.boundDomain=we,e.computeTicks=Y,e.createChart=it,e.darkTheme=re,e.decimateM4=p,e.extent=K,e.formatNumber=M,e.formatSI=P,e.lightTheme=z,e.linearScale=G,e.nearestIndex=m,e.padDomain=q,e.resolveTheme=oe,e})({});
|
|
271
271
|
//# sourceMappingURL=index.iife.js.map
|