scichart-engine 0.4.1 → 0.4.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(w,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],A):(w=typeof globalThis<"u"?globalThis:w||self,A(w.SciChartEngine={},w.React))})(this,function(w,A){"use strict";var wo=Object.defineProperty;var To=(w,A,$)=>A in w?wo(w,A,{enumerable:!0,configurable:!0,writable:!0,value:$}):w[A]=$;var p=(w,A,$)=>To(w,typeof A!="symbol"?A+"":A,$);const $={top:20,right:30,bottom:55,left:75},We=[{symbol:"p",factor:1e-12},{symbol:"n",factor:1e-9},{symbol:"µ",factor:1e-6},{symbol:"m",factor:.001},{symbol:"",factor:1},{symbol:"k",factor:1e3},{symbol:"M",factor:1e6},{symbol:"G",factor:1e9}];function Te(o){const e=Math.abs(o);if(e===0)return{symbol:"",factor:1};for(let t=We.length-1;t>=0;t--){const i=We[t],n=e/i.factor;if(n>=1&&n<1e3)return i}return{symbol:"",factor:1}}function Xe(o,e,t=2){const i=Te(o);return`${(o/i.factor).toFixed(t)} ${i.symbol}${e}`}function Ne(o,e=3){return Math.abs(o)<.001||Math.abs(o)>=1e6?o.toExponential(e):o.toFixed(e)}function He(o,e=2){return o.toExponential(e)}function qe(o,e=.001){const t=o instanceof Array?new Float32Array(o):o;if(t.length<3)return[];const i=[];let n=0,s=1,r=Math.sign(t[1]-t[0]),a=0;for(let l=2;l<t.length;l++){const c=Math.sign(t[l]-t[l-1]);if(c!==0&&c!==r){if(a++,a>=2){const h=t[n],u=t[l];Math.abs(u-h)<e&&(i.push({number:s,startIndex:n,endIndex:l,direction:t[n+1]>t[n]?1:-1}),s++,n=l,a=0)}r=c}}return n<t.length-1&&i.push({number:s,startIndex:n,endIndex:t.length-1,direction:t[n+1]>t[n]?1:-1}),i}function je(o){const e=[],t=360/Math.max(o,1);for(let i=0;i<o;i++){const n=i*t%360;e.push(`hsl(${n}, 70%, 55%)`)}return e}function Ke(o,e,t={}){const{minProminence:i=0,type:n="both"}=t,s=[],r=o instanceof Array?new Float32Array(o):o,a=e instanceof Array?new Float32Array(e):e;for(let l=1;l<a.length-1;l++){const c=a[l-1],h=a[l],u=a[l+1];if(h>c&&h>u){const d=Math.min(h-c,h-u);d>=i&&(n==="both"||n==="max")&&s.push({index:l,x:r[l],y:h,type:"max",prominence:d})}if(h<c&&h<u){const d=Math.min(c-h,u-h);d>=i&&(n==="both"||n==="min")&&s.push({index:l,x:r[l],y:h,type:"min",prominence:d})}}return s}function Ze(o){let e=0,t=-1;const i=o instanceof Array?o:Array.from(o);for(let n=0;n<i.length;n++)isFinite(i[n])||(e++,t===-1&&(t=n));return{valid:e===0,invalidCount:e,firstInvalidIndex:t}}function Me(o){const e=o instanceof Array?o:Array.from(o),t=e.length;if(t===0)return{min:0,max:0,mean:0,stdDev:0,count:0};let i=e[0],n=e[0],s=0;for(let c=0;c<t;c++){const h=e[c];h<i&&(i=h),h>n&&(n=h),s+=h}const r=s/t;let a=0;for(let c=0;c<t;c++){const h=e[c]-r;a+=h*h}const l=Math.sqrt(a/t);return{min:i,max:n,mean:r,stdDev:l,count:t}}function Je(o,e){const t=o instanceof Array?new Float32Array(o):o,i=new Float32Array(t.length),n=Math.floor(e/2);for(let s=0;s<t.length;s++){let r=0,a=0;for(let l=Math.max(0,s-n);l<=Math.min(t.length-1,s+n);l++)r+=t[l],a++;i[s]=r/a}return i}function Qe(o,e,t){const i=o.length;if(t>=i||t<3)return{x:new Float32Array(o),y:new Float32Array(e)};const n=new Float32Array(t),s=new Float32Array(t);n[0]=o[0],s[0]=e[0];const r=(i-2)/(t-2);let a=0,l=1;for(let c=0;c<t-2;c++){const h=Math.floor((c+1)*r)+1,u=Math.floor((c+2)*r)+1,d=Math.min(Math.floor((c+3)*r)+1,i);let f=0,g=0,m=0;for(let v=u;v<d;v++)f+=o[v],g+=e[v],m++;m>0&&(f/=m,g/=m);let y=-1,b=h;for(let v=h;v<u&&v<i;v++){const S=Math.abs((o[a]-f)*(e[v]-e[a])-(o[a]-o[v])*(g-e[a]));S>y&&(y=S,b=v)}n[l]=o[b],s[l]=e[b],l++,a=b}return n[t-1]=o[i-1],s[t-1]=e[i-1],{x:n,y:s}}function Ot(o,e,t,i){const n=o.length,s=new Float32Array(n);let r=0,a=n-1,l=1/0,c=1/0;for(let g=0;g<n;g++){const m=Math.abs(o[g]-t),y=Math.abs(o[g]-i);m<l&&(l=m,r=g),y<c&&(c=y,a=g)}const h=e[r],d=(e[a]-h)/(o[a]-o[r]),f=h-d*o[r];for(let g=0;g<n;g++)s[g]=e[g]-(d*o[g]+f);return s}function et(o,e){const t=e.length,i=o.map((s,r)=>[...s,e[r]]);for(let s=0;s<t;s++){let r=s;for(let c=s+1;c<t;c++)Math.abs(i[c][s])>Math.abs(i[r][s])&&(r=c);const a=i[s];i[s]=i[r],i[r]=a;const l=i[s][s];if(Math.abs(l)<1e-12)throw new Error("Matrix is singular or near-singular");for(let c=s+1;c<t;c++){const h=i[c][s]/l;for(let u=s;u<=t;u++)i[c][u]-=h*i[s][u]}}const n=new Array(t).fill(0);for(let s=t-1;s>=0;s--){let r=0;for(let a=s+1;a<t;a++)r+=i[s][a]*n[a];n[s]=(i[s][t]-r)/i[s][s]}return n}function j(o,e,t){const i=o.length;if(i===0)return 0;let n=0;for(let l=0;l<i;l++)n+=e[l];const s=n/i;let r=0,a=0;for(let l=0;l<i;l++){const c=e[l],h=t(o[l]);r+=(c-s)*(c-s),a+=(c-h)*(c-h)}return r===0?1:1-a/r}function tt(o,e,t,i){const n=o.length;if(n<2)return 0;let s=0;const r=t!==void 0?t:o[0],a=i!==void 0?i:o[n-1];for(let l=0;l<n-1;l++){const c=o[l],h=o[l+1];if(h<r)continue;if(c>a)break;const u=Math.max(c,r),d=Math.min(h,a);if(u<d){const f=e[l]+(e[l+1]-e[l])*((u-c)/(h-c)),g=e[l]+(e[l+1]-e[l])*((d-c)/(h-c));s+=(d-u)*(f+g)/2}}return s}function Ut(o,e){const t=o.length;if(t<2)return new Float32Array(0);const i=new Float32Array(t);for(let n=0;n<t-1;n++){const s=o[n+1]-o[n];i[n]=s!==0?(e[n+1]-e[n])/s:0}return i[t-1]=i[t-2],i}function $t(o,e){const t=o.length;if(t<1)return new Float32Array(0);const i=new Float32Array(t);i[0]=0;for(let n=0;n<t-1;n++){const r=(o[n+1]-o[n])*(e[n]+e[n+1])/2;i[n+1]=i[n]+r}return i}function it(o,e,t,i={}){if(o.length<2)throw new Error("At least 2 points are required for fitting");switch(t){case"linear":return re(o,e,i);case"polynomial":return Yt(o,e,i.degree??2,i);case"exponential":return Vt(o,e,i);case"logarithmic":return Wt(o,e,i);case"power":return Xt(o,e,i);default:throw new Error(`Unsupported fit type: ${t}`)}}function re(o,e,t){const i=o.length;let n=0,s=0,r=0,a=0;for(let d=0;d<i;d++)n+=o[d],s+=e[d],r+=o[d]*e[d],a+=o[d]*o[d];const l=(i*r-n*s)/(i*a-n*n),c=(s-l*n)/i,h=d=>l*d+c,u=t.precision??4;return{type:"linear",coefficients:[l,c],equation:`y = ${l.toFixed(u)}x ${c>=0?"+":"-"} ${Math.abs(c).toFixed(u)}`,rSquared:j(o,e,h),predict:h}}function Yt(o,e,t,i){const n=o.length,s=t+1,r=Array.from({length:s},()=>new Array(s).fill(0)),a=new Array(s).fill(0);for(let d=0;d<s;d++){for(let g=0;g<s;g++){let m=0;for(let y=0;y<n;y++)m+=Math.pow(o[y],d+g);r[d][g]=m}let f=0;for(let g=0;g<n;g++)f+=e[g]*Math.pow(o[g],d);a[d]=f}const l=et(r,a),c=d=>{let f=0;for(let g=0;g<l.length;g++)f+=l[g]*Math.pow(d,g);return f},h=i.precision??4;let u="y = ";for(let d=l.length-1;d>=0;d--){const f=l[d];d<l.length-1?u+=f>=0?" + ":" - ":f<0&&(u+="-"),u+=`${Math.abs(f).toFixed(h)}${d>0?d>1?`x^${d}`:"x":""}`}return{type:"polynomial",coefficients:l,equation:u,rSquared:j(o,e,c),predict:c}}function Vt(o,e,t){const i=o.length,n=[],s=[];for(let u=0;u<i;u++)e[u]>0&&(n.push(o[u]),s.push(Math.log(e[u])));const r=re(n,s,t),a=r.coefficients[0],l=Math.exp(r.coefficients[1]),c=u=>l*Math.exp(a*u),h=t.precision??4;return{type:"exponential",coefficients:[l,a],equation:`y = ${l.toFixed(h)} * e^(${a.toFixed(h)}x)`,rSquared:j(o,e,c),predict:c}}function Wt(o,e,t){const i=o.length,n=[],s=[];for(let u=0;u<i;u++)o[u]>0&&(n.push(Math.log(o[u])),s.push(e[u]));const r=re(n,s,t),a=r.coefficients[0],l=r.coefficients[1],c=u=>l+a*Math.log(u),h=t.precision??4;return{type:"logarithmic",coefficients:[l,a],equation:`y = ${l.toFixed(h)} ${a>=0?"+":"-"} ${Math.abs(a).toFixed(h)} * ln(x)`,rSquared:j(o,e,c),predict:c}}function Xt(o,e,t){const i=o.length,n=[],s=[];for(let u=0;u<i;u++)o[u]>0&&e[u]>0&&(n.push(Math.log(o[u])),s.push(Math.log(e[u])));const r=re(n,s,t),a=r.coefficients[0],l=Math.exp(r.coefficients[1]),c=u=>l*Math.pow(u,a),h=t.precision??4;return{type:"power",coefficients:[l,a],equation:`y = ${l.toFixed(h)} * x^(${a.toFixed(h)})`,rSquared:j(o,e,c),predict:c}}function Nt(o,e,t,i={}){const n=e.length,s=t.length,r=Math.min(...o),a=Math.max(...o),l=i.levels||Ht(r,a,i.numLevels||10),c=[];for(const h of l){const u=[];for(let d=0;d<s-1;d++)for(let f=0;f<n-1;f++){const g=o[d*n+f],m=o[d*n+(f+1)],y=o[(d+1)*n+(f+1)],b=o[(d+1)*n+f];qt(f,d,g,m,y,b,h,e,t,u)}if(u.length>0){const d=[];for(const f of u)d.push({x:f[0],y:f[1]}),d.push({x:f[2],y:f[3]});c.push({level:h,points:d})}}return c}function Ht(o,e,t){const i=[],n=(e-o)/(t+1);for(let s=1;s<=t;s++)i.push(o+s*n);return i}function qt(o,e,t,i,n,s,r,a,l,c){let h=0;if(t>=r&&(h|=1),i>=r&&(h|=2),n>=r&&(h|=4),s>=r&&(h|=8),h===0||h===15)return;const u=(m,y,b)=>m+(y-m)*b,d=(m,y)=>(r-m)/(y-m),f=m=>{switch(m){case 0:return[u(a[o],a[o+1],d(t,i)),l[e]];case 1:return[a[o+1],u(l[e],l[e+1],d(i,n))];case 2:return[u(a[o],a[o+1],d(s,n)),l[e+1]];case 3:return[a[o],u(l[e],l[e+1],d(t,s))];default:return[0,0]}},g=(m,y)=>{const b=f(m),v=f(y);c.push([b[0],b[1],v[0],v[1]])};switch(h){case 1:case 14:g(0,3);break;case 2:case 13:g(0,1);break;case 3:case 12:g(1,3);break;case 4:case 11:g(1,2);break;case 5:g(0,1),g(2,3);break;case 6:case 9:g(0,2);break;case 7:case 8:g(2,3);break;case 10:g(0,3),g(1,2);break}}const jt=Object.freeze(Object.defineProperty({__proto__:null,calculateR2:j,calculateStats:Me,cumulativeIntegral:$t,derivative:Ut,detectCycles:qe,detectPeaks:Ke,downsampleLTTB:Qe,fitData:it,formatScientific:He,formatValue:Ne,formatWithPrefix:Xe,generateContours:Nt,generateCycleColors:je,getBestPrefix:Te,integrate:tt,movingAverage:Je,solveLinearSystem:et,subtractBaseline:Ot,validateData:Ze},Symbol.toStringTag,{value:"Module"}));class Pe{constructor(){p(this,"listeners",new Map)}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){const i=this.listeners.get(e);i&&i.delete(t)}emit(e,t){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(t)}catch(s){console.error(`[EventEmitter] Error in handler for "${String(e)}":`,s)}})}once(e,t){const i=n=>{this.off(e,i),t(n)};this.on(e,i)}clear(){this.listeners.clear()}listenerCount(e){var t;return((t=this.listeners.get(e))==null?void 0:t.size)??0}}class Kt{constructor(e){p(this,"buffers",new Map);p(this,"bufferSizes",new Map);this.gl=e}createBuffer(e,t){const{gl:i}=this;let n=this.buffers.get(e);const s=this.bufferSizes.get(e)||0;if(n&&t.byteLength<=s){i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferSubData(i.ARRAY_BUFFER,0,t);return}if(n&&i.deleteBuffer(n),n=i.createBuffer(),!n)throw new Error("Failed to create buffer");i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,t,i.DYNAMIC_DRAW),this.buffers.set(e,n),this.bufferSizes.set(e,t.byteLength)}updateBuffer(e,t,i){const{gl:n}=this,s=this.buffers.get(e),r=this.bufferSizes.get(e)||0;return!s||i+t.byteLength>r?!1:(n.bindBuffer(n.ARRAY_BUFFER,s),n.bufferSubData(n.ARRAY_BUFFER,i,t),!0)}getBuffer(e){return this.buffers.get(e)}deleteBuffer(e){const t=this.buffers.get(e);t&&(this.gl.deleteBuffer(t),this.buffers.delete(e),this.bufferSizes.delete(e))}destroy(){this.buffers.forEach(e=>this.gl.deleteBuffer(e)),this.buffers.clear(),this.bufferSizes.clear()}}const Zt=`
|
|
1
|
+
(function(w,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],A):(w=typeof globalThis<"u"?globalThis:w||self,A(w.SciChartEngine={},w.React))})(this,function(w,A){"use strict";var wo=Object.defineProperty;var To=(w,A,$)=>A in w?wo(w,A,{enumerable:!0,configurable:!0,writable:!0,value:$}):w[A]=$;var p=(w,A,$)=>To(w,typeof A!="symbol"?A+"":A,$);const $={top:20,right:30,bottom:55,left:75},We=[{symbol:"p",factor:1e-12},{symbol:"n",factor:1e-9},{symbol:"µ",factor:1e-6},{symbol:"m",factor:.001},{symbol:"",factor:1},{symbol:"k",factor:1e3},{symbol:"M",factor:1e6},{symbol:"G",factor:1e9}];function Te(o){const e=Math.abs(o);if(e===0)return{symbol:"",factor:1};for(let t=We.length-1;t>=0;t--){const i=We[t],n=e/i.factor;if(n>=1&&n<1e3)return i}return{symbol:"",factor:1}}function Xe(o,e,t=2){const i=Te(o);return`${(o/i.factor).toFixed(t)} ${i.symbol}${e}`}function Ne(o,e=3){return Math.abs(o)<.001||Math.abs(o)>=1e6?o.toExponential(e):o.toFixed(e)}function He(o,e=2){return o.toExponential(e)}function qe(o,e=.001){const t=o instanceof Array?new Float32Array(o):o;if(t.length<3)return[];const i=[];let n=0,r=1,s=Math.sign(t[1]-t[0]),a=0;for(let l=2;l<t.length;l++){const c=Math.sign(t[l]-t[l-1]);if(c!==0&&c!==s){if(a++,a>=2){const h=t[n],u=t[l];Math.abs(u-h)<e&&(i.push({number:r,startIndex:n,endIndex:l,direction:t[n+1]>t[n]?1:-1}),r++,n=l,a=0)}s=c}}return n<t.length-1&&i.push({number:r,startIndex:n,endIndex:t.length-1,direction:t[n+1]>t[n]?1:-1}),i}function je(o){const e=[],t=360/Math.max(o,1);for(let i=0;i<o;i++){const n=i*t%360;e.push(`hsl(${n}, 70%, 55%)`)}return e}function Ke(o,e,t={}){const{minProminence:i=0,type:n="both"}=t,r=[],s=o instanceof Array?new Float32Array(o):o,a=e instanceof Array?new Float32Array(e):e;for(let l=1;l<a.length-1;l++){const c=a[l-1],h=a[l],u=a[l+1];if(h>c&&h>u){const d=Math.min(h-c,h-u);d>=i&&(n==="both"||n==="max")&&r.push({index:l,x:s[l],y:h,type:"max",prominence:d})}if(h<c&&h<u){const d=Math.min(c-h,u-h);d>=i&&(n==="both"||n==="min")&&r.push({index:l,x:s[l],y:h,type:"min",prominence:d})}}return r}function Ze(o){let e=0,t=-1;const i=o instanceof Array?o:Array.from(o);for(let n=0;n<i.length;n++)isFinite(i[n])||(e++,t===-1&&(t=n));return{valid:e===0,invalidCount:e,firstInvalidIndex:t}}function Me(o){const e=o instanceof Array?o:Array.from(o),t=e.length;if(t===0)return{min:0,max:0,mean:0,stdDev:0,count:0};let i=e[0],n=e[0],r=0;for(let c=0;c<t;c++){const h=e[c];h<i&&(i=h),h>n&&(n=h),r+=h}const s=r/t;let a=0;for(let c=0;c<t;c++){const h=e[c]-s;a+=h*h}const l=Math.sqrt(a/t);return{min:i,max:n,mean:s,stdDev:l,count:t}}function Je(o,e){const t=o instanceof Array?new Float32Array(o):o,i=new Float32Array(t.length),n=Math.floor(e/2);for(let r=0;r<t.length;r++){let s=0,a=0;for(let l=Math.max(0,r-n);l<=Math.min(t.length-1,r+n);l++)s+=t[l],a++;i[r]=s/a}return i}function Qe(o,e,t){const i=o.length;if(t>=i||t<3)return{x:new Float32Array(o),y:new Float32Array(e)};const n=new Float32Array(t),r=new Float32Array(t);n[0]=o[0],r[0]=e[0];const s=(i-2)/(t-2);let a=0,l=1;for(let c=0;c<t-2;c++){const h=Math.floor((c+1)*s)+1,u=Math.floor((c+2)*s)+1,d=Math.min(Math.floor((c+3)*s)+1,i);let f=0,g=0,m=0;for(let v=u;v<d;v++)f+=o[v],g+=e[v],m++;m>0&&(f/=m,g/=m);let y=-1,b=h;for(let v=h;v<u&&v<i;v++){const S=Math.abs((o[a]-f)*(e[v]-e[a])-(o[a]-o[v])*(g-e[a]));S>y&&(y=S,b=v)}n[l]=o[b],r[l]=e[b],l++,a=b}return n[t-1]=o[i-1],r[t-1]=e[i-1],{x:n,y:r}}function Ot(o,e,t,i){const n=o.length,r=new Float32Array(n);let s=0,a=n-1,l=1/0,c=1/0;for(let g=0;g<n;g++){const m=Math.abs(o[g]-t),y=Math.abs(o[g]-i);m<l&&(l=m,s=g),y<c&&(c=y,a=g)}const h=e[s],d=(e[a]-h)/(o[a]-o[s]),f=h-d*o[s];for(let g=0;g<n;g++)r[g]=e[g]-(d*o[g]+f);return r}function et(o,e){const t=e.length,i=o.map((r,s)=>[...r,e[s]]);for(let r=0;r<t;r++){let s=r;for(let c=r+1;c<t;c++)Math.abs(i[c][r])>Math.abs(i[s][r])&&(s=c);const a=i[r];i[r]=i[s],i[s]=a;const l=i[r][r];if(Math.abs(l)<1e-12)throw new Error("Matrix is singular or near-singular");for(let c=r+1;c<t;c++){const h=i[c][r]/l;for(let u=r;u<=t;u++)i[c][u]-=h*i[r][u]}}const n=new Array(t).fill(0);for(let r=t-1;r>=0;r--){let s=0;for(let a=r+1;a<t;a++)s+=i[r][a]*n[a];n[r]=(i[r][t]-s)/i[r][r]}return n}function j(o,e,t){const i=o.length;if(i===0)return 0;let n=0;for(let l=0;l<i;l++)n+=e[l];const r=n/i;let s=0,a=0;for(let l=0;l<i;l++){const c=e[l],h=t(o[l]);s+=(c-r)*(c-r),a+=(c-h)*(c-h)}return s===0?1:1-a/s}function tt(o,e,t,i){const n=o.length;if(n<2)return 0;let r=0;const s=t!==void 0?t:o[0],a=i!==void 0?i:o[n-1];for(let l=0;l<n-1;l++){const c=o[l],h=o[l+1];if(h<s)continue;if(c>a)break;const u=Math.max(c,s),d=Math.min(h,a);if(u<d){const f=e[l]+(e[l+1]-e[l])*((u-c)/(h-c)),g=e[l]+(e[l+1]-e[l])*((d-c)/(h-c));r+=(d-u)*(f+g)/2}}return r}function Ut(o,e){const t=o.length;if(t<2)return new Float32Array(0);const i=new Float32Array(t);for(let n=0;n<t-1;n++){const r=o[n+1]-o[n];i[n]=r!==0?(e[n+1]-e[n])/r:0}return i[t-1]=i[t-2],i}function $t(o,e){const t=o.length;if(t<1)return new Float32Array(0);const i=new Float32Array(t);i[0]=0;for(let n=0;n<t-1;n++){const s=(o[n+1]-o[n])*(e[n]+e[n+1])/2;i[n+1]=i[n]+s}return i}function it(o,e,t,i={}){if(o.length<2)throw new Error("At least 2 points are required for fitting");switch(t){case"linear":return se(o,e,i);case"polynomial":return Yt(o,e,i.degree??2,i);case"exponential":return Vt(o,e,i);case"logarithmic":return Wt(o,e,i);case"power":return Xt(o,e,i);default:throw new Error(`Unsupported fit type: ${t}`)}}function se(o,e,t){const i=o.length;let n=0,r=0,s=0,a=0;for(let d=0;d<i;d++)n+=o[d],r+=e[d],s+=o[d]*e[d],a+=o[d]*o[d];const l=(i*s-n*r)/(i*a-n*n),c=(r-l*n)/i,h=d=>l*d+c,u=t.precision??4;return{type:"linear",coefficients:[l,c],equation:`y = ${l.toFixed(u)}x ${c>=0?"+":"-"} ${Math.abs(c).toFixed(u)}`,rSquared:j(o,e,h),predict:h}}function Yt(o,e,t,i){const n=o.length,r=t+1,s=Array.from({length:r},()=>new Array(r).fill(0)),a=new Array(r).fill(0);for(let d=0;d<r;d++){for(let g=0;g<r;g++){let m=0;for(let y=0;y<n;y++)m+=Math.pow(o[y],d+g);s[d][g]=m}let f=0;for(let g=0;g<n;g++)f+=e[g]*Math.pow(o[g],d);a[d]=f}const l=et(s,a),c=d=>{let f=0;for(let g=0;g<l.length;g++)f+=l[g]*Math.pow(d,g);return f},h=i.precision??4;let u="y = ";for(let d=l.length-1;d>=0;d--){const f=l[d];d<l.length-1?u+=f>=0?" + ":" - ":f<0&&(u+="-"),u+=`${Math.abs(f).toFixed(h)}${d>0?d>1?`x^${d}`:"x":""}`}return{type:"polynomial",coefficients:l,equation:u,rSquared:j(o,e,c),predict:c}}function Vt(o,e,t){const i=o.length,n=[],r=[];for(let u=0;u<i;u++)e[u]>0&&(n.push(o[u]),r.push(Math.log(e[u])));const s=se(n,r,t),a=s.coefficients[0],l=Math.exp(s.coefficients[1]),c=u=>l*Math.exp(a*u),h=t.precision??4;return{type:"exponential",coefficients:[l,a],equation:`y = ${l.toFixed(h)} * e^(${a.toFixed(h)}x)`,rSquared:j(o,e,c),predict:c}}function Wt(o,e,t){const i=o.length,n=[],r=[];for(let u=0;u<i;u++)o[u]>0&&(n.push(Math.log(o[u])),r.push(e[u]));const s=se(n,r,t),a=s.coefficients[0],l=s.coefficients[1],c=u=>l+a*Math.log(u),h=t.precision??4;return{type:"logarithmic",coefficients:[l,a],equation:`y = ${l.toFixed(h)} ${a>=0?"+":"-"} ${Math.abs(a).toFixed(h)} * ln(x)`,rSquared:j(o,e,c),predict:c}}function Xt(o,e,t){const i=o.length,n=[],r=[];for(let u=0;u<i;u++)o[u]>0&&e[u]>0&&(n.push(Math.log(o[u])),r.push(Math.log(e[u])));const s=se(n,r,t),a=s.coefficients[0],l=Math.exp(s.coefficients[1]),c=u=>l*Math.pow(u,a),h=t.precision??4;return{type:"power",coefficients:[l,a],equation:`y = ${l.toFixed(h)} * x^(${a.toFixed(h)})`,rSquared:j(o,e,c),predict:c}}function Nt(o,e,t,i={}){const n=e.length,r=t.length,s=Math.min(...o),a=Math.max(...o),l=i.levels||Ht(s,a,i.numLevels||10),c=[];for(const h of l){const u=[];for(let d=0;d<r-1;d++)for(let f=0;f<n-1;f++){const g=o[d*n+f],m=o[d*n+(f+1)],y=o[(d+1)*n+(f+1)],b=o[(d+1)*n+f];qt(f,d,g,m,y,b,h,e,t,u)}if(u.length>0){const d=[];for(const f of u)d.push({x:f[0],y:f[1]}),d.push({x:f[2],y:f[3]});c.push({level:h,points:d})}}return c}function Ht(o,e,t){const i=[],n=(e-o)/(t+1);for(let r=1;r<=t;r++)i.push(o+r*n);return i}function qt(o,e,t,i,n,r,s,a,l,c){let h=0;if(t>=s&&(h|=1),i>=s&&(h|=2),n>=s&&(h|=4),r>=s&&(h|=8),h===0||h===15)return;const u=(m,y,b)=>m+(y-m)*b,d=(m,y)=>(s-m)/(y-m),f=m=>{switch(m){case 0:return[u(a[o],a[o+1],d(t,i)),l[e]];case 1:return[a[o+1],u(l[e],l[e+1],d(i,n))];case 2:return[u(a[o],a[o+1],d(r,n)),l[e+1]];case 3:return[a[o],u(l[e],l[e+1],d(t,r))];default:return[0,0]}},g=(m,y)=>{const b=f(m),v=f(y);c.push([b[0],b[1],v[0],v[1]])};switch(h){case 1:case 14:g(0,3);break;case 2:case 13:g(0,1);break;case 3:case 12:g(1,3);break;case 4:case 11:g(1,2);break;case 5:g(0,1),g(2,3);break;case 6:case 9:g(0,2);break;case 7:case 8:g(2,3);break;case 10:g(0,3),g(1,2);break}}const jt=Object.freeze(Object.defineProperty({__proto__:null,calculateR2:j,calculateStats:Me,cumulativeIntegral:$t,derivative:Ut,detectCycles:qe,detectPeaks:Ke,downsampleLTTB:Qe,fitData:it,formatScientific:He,formatValue:Ne,formatWithPrefix:Xe,generateContours:Nt,generateCycleColors:je,getBestPrefix:Te,integrate:tt,movingAverage:Je,solveLinearSystem:et,subtractBaseline:Ot,validateData:Ze},Symbol.toStringTag,{value:"Module"}));class Pe{constructor(){p(this,"listeners",new Map)}on(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}off(e,t){const i=this.listeners.get(e);i&&i.delete(t)}emit(e,t){const i=this.listeners.get(e);i&&i.forEach(n=>{try{n(t)}catch(r){console.error(`[EventEmitter] Error in handler for "${String(e)}":`,r)}})}once(e,t){const i=n=>{this.off(e,i),t(n)};this.on(e,i)}clear(){this.listeners.clear()}listenerCount(e){var t;return((t=this.listeners.get(e))==null?void 0:t.size)??0}}class Kt{constructor(e){p(this,"buffers",new Map);p(this,"bufferSizes",new Map);this.gl=e}createBuffer(e,t){const{gl:i}=this;let n=this.buffers.get(e);const r=this.bufferSizes.get(e)||0;if(n&&t.byteLength<=r){i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferSubData(i.ARRAY_BUFFER,0,t);return}if(n&&i.deleteBuffer(n),n=i.createBuffer(),!n)throw new Error("Failed to create buffer");i.bindBuffer(i.ARRAY_BUFFER,n),i.bufferData(i.ARRAY_BUFFER,t,i.DYNAMIC_DRAW),this.buffers.set(e,n),this.bufferSizes.set(e,t.byteLength)}updateBuffer(e,t,i){const{gl:n}=this,r=this.buffers.get(e),s=this.bufferSizes.get(e)||0;return!r||i+t.byteLength>s?!1:(n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferSubData(n.ARRAY_BUFFER,i,t),!0)}getBuffer(e){return this.buffers.get(e)}deleteBuffer(e){const t=this.buffers.get(e);t&&(this.gl.deleteBuffer(t),this.buffers.delete(e),this.bufferSizes.delete(e))}destroy(){this.buffers.forEach(e=>this.gl.deleteBuffer(e)),this.buffers.clear(),this.bufferSizes.clear()}}const Zt=`
|
|
2
2
|
precision highp float;
|
|
3
3
|
attribute vec2 position;
|
|
4
4
|
uniform vec2 uScale;
|
|
@@ -133,8 +133,8 @@ void main() {
|
|
|
133
133
|
t = clamp(t, 0.0, 1.0);
|
|
134
134
|
gl_FragColor = texture2D(uColormap, vec2(t, 0.5));
|
|
135
135
|
}
|
|
136
|
-
`;function nt(o,e,t){const i=o.createShader(t);if(!i)throw new Error("Failed to create shader");if(o.shaderSource(i,e),o.compileShader(i),!o.getShaderParameter(i,o.COMPILE_STATUS)){const n=o.getShaderInfoLog(i);throw o.deleteShader(i),new Error(`Shader compilation error: ${n}`)}return i}function Ce(o,e,t,i){const n=nt(o,e,o.VERTEX_SHADER),s=nt(o,t,o.FRAGMENT_SHADER),r=o.createProgram();if(!r)throw new Error("Failed to create program");if(o.attachShader(r,n),o.attachShader(r,s),o.linkProgram(r),!o.getProgramParameter(r,o.LINK_STATUS)){const a=o.getProgramInfoLog(r);throw new Error(`Program link error: ${a}`)}return o.deleteShader(n),o.deleteShader(s),{program:r,attributes:{position:o.getAttribLocation(r,i==="heatmap"?"aPosition":"position"),value:i==="heatmap"?o.getAttribLocation(r,"aValue"):-1},uniforms:{uScale:o.getUniformLocation(r,"uScale"),uTranslate:o.getUniformLocation(r,"uTranslate"),uColor:i!=="heatmap"?o.getUniformLocation(r,"uColor"):null,uPointSize:i==="point"?o.getUniformLocation(r,"uPointSize"):null,uSymbol:i==="point"?o.getUniformLocation(r,"uSymbol"):null,uMinValue:i==="heatmap"?o.getUniformLocation(r,"uMinValue"):null,uMaxValue:i==="heatmap"?o.getUniformLocation(r,"uMaxValue"):null,uColormap:i==="heatmap"?o.getUniformLocation(r,"uColormap"):null}}}function ni(o){return{lineProgram:Ce(o,Zt,Jt,"line"),pointProgram:Ce(o,Qt,ei,"point"),heatmapProgram:Ce(o,ti,ii,"heatmap")}}function ae(o){if(!o)return[1,0,1,1];if(o.startsWith("#")){const e=o.slice(1);if(e.length===3){const t=parseInt(e[0]+e[0],16)/255,i=parseInt(e[1]+e[1],16)/255,n=parseInt(e[2]+e[2],16)/255;return[t,i,n,1]}else if(e.length===6){const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16)/255,n=parseInt(e.slice(4,6),16)/255;return[t,i,n,1]}else if(e.length===8){const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16)/255,n=parseInt(e.slice(4,6),16)/255,s=parseInt(e.slice(6,8),16)/255;return[t,i,n,s]}}if(o.startsWith("rgb")){const e=o.match(/[\d.]+/g);if(e&&e.length>=3){const t=parseFloat(e[0])/255,i=parseFloat(e[1])/255,n=parseFloat(e[2])/255,s=e.length>=4?parseFloat(e[3]):1;return[t,i,n,s]}}return[1,0,1,1]}function ke(o,e){const t=Math.min(o.length,e.length),i=new Float32Array(t*2);for(let n=0;n<t;n++)i[n*2]=o[n],i[n*2+1]=e[n];return i}function oi(o,e,t="after"){const i=Math.min(o.length,e.length);if(i<2)return ke(o,e);const n=t==="center"?1+(i-1)*3:i*2-1,s=new Float32Array(n*2);let r=0;for(let a=0;a<i;a++)if(a===0)s[r++]=o[0],s[r++]=e[0];else{const l=o[a-1],c=e[a-1],h=o[a],u=e[a];if(t==="after")s[r++]=h,s[r++]=c,s[r++]=h,s[r++]=u;else if(t==="before")s[r++]=l,s[r++]=u,s[r++]=h,s[r++]=u;else{const d=(l+h)/2;s[r++]=d,s[r++]=c,s[r++]=d,s[r++]=u,s[r++]=h,s[r++]=u}}return s.subarray(0,r)}function ot(o,e,t){const i=Math.min(o.length,e.length,t.length),n=new Float32Array(i*2*2);for(let s=0;s<i;s++){const r=s*4,a=o[s];n[r+0]=a,n[r+1]=e[s],n[r+2]=a,n[r+3]=t[s]}return n}function si(o){const e=o.xMax-o.xMin,t=o.yMax-o.yMin,i=e>0?2/e:1,n=t>0?2/t:1,s=-1-o.xMin*i,r=-1-o.yMin*n;return{scale:[i,n],translate:[s,r]}}function le(o,e,t,i,n,s){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,s[0],s[1],s[2],s[3]),o.drawArrays(o.LINE_STRIP,0,i),o.disableVertexAttribArray(e.attributes.position)}function ri(o,e,t,i,n,s){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]);const r=s[3]*.4;o.uniform4f(e.uniforms.uColor,s[0],s[1],s[2],r),o.drawArrays(o.TRIANGLE_STRIP,0,i),o.disableVertexAttribArray(e.attributes.position)}function Ee(o,e,t,i,n,s,r,a="circle"){if(o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,s[0],s[1],s[2],s[3]),e.uniforms.uPointSize&&o.uniform1f(e.uniforms.uPointSize,r),e.uniforms.uSymbol){const l={circle:0,square:1,diamond:2,triangle:3,triangleDown:4,cross:5,x:6,star:7};o.uniform1i(e.uniforms.uSymbol,l[a]??0)}o.drawArrays(o.POINTS,0,i),o.disableVertexAttribArray(e.attributes.position)}function ai(o,e,t,i,n,s={min:0,max:1},r){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,12,0),e.attributes.value!==void 0&&e.attributes.value!==-1&&(o.enableVertexAttribArray(e.attributes.value),o.vertexAttribPointer(e.attributes.value,1,o.FLOAT,!1,12,8)),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),e.uniforms.uMinValue&&o.uniform1f(e.uniforms.uMinValue,s.min),e.uniforms.uMaxValue&&o.uniform1f(e.uniforms.uMaxValue,s.max),r&&e.uniforms.uColormap?(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,r),o.uniform1i(e.uniforms.uColormap,0)):e.uniforms.uColormap&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,null)),o.drawArrays(o.TRIANGLES,0,i),o.disableVertexAttribArray(e.attributes.position),e.attributes.value!==void 0&&e.attributes.value!==-1&&o.disableVertexAttribArray(e.attributes.value)}function li(o,e,t,i,n,s){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,s[0],s[1],s[2],s[3]),o.drawArrays(o.TRIANGLES,0,i),o.disableVertexAttribArray(e.attributes.position)}function ci(o){const e=ae(o.color??"#ff0055");return e[3]=o.opacity??1,e}function hi(o,e,t,i,n,s){const{bounds:r,backgroundColor:a=[.1,.1,.18,1],plotArea:l}=s,c=e.height,h=e.width,u=l?{x:l.x*t,y:c-(l.y+l.height)*t,width:l.width*t,height:l.height*t}:{x:0,y:0,width:h,height:c};o.viewport(0,0,h,c),o.disable(o.SCISSOR_TEST),o.clearColor(a[0],a[1],a[2],a[3]),o.clear(o.COLOR_BUFFER_BIT),o.viewport(u.x,u.y,u.width,u.height),o.enable(o.SCISSOR_TEST),o.scissor(u.x,u.y,u.width,u.height);const d=si(r);for(const f of n){if(!f.visible||f.count===0)continue;const g=f.yBounds?f.yBounds.min:r.yMin,y=(f.yBounds?f.yBounds.max:r.yMax)-g,b=y>0?2/y:1,v=-1-g*b,S={scale:[d.scale[0],b],translate:[d.translate[0],v]},T=ci(f.style);f.type==="scatter"?Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol):f.type==="line"?le(o,i.lineProgram,f.buffer,f.count,S,T):f.type==="line+scatter"?(le(o,i.lineProgram,f.buffer,f.count,S,T),Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol)):f.type==="step"||f.type==="step+scatter"?(f.stepBuffer&&f.stepCount?le(o,i.lineProgram,f.stepBuffer,f.stepCount,S,T):le(o,i.lineProgram,f.buffer,f.count,S,T),f.type==="step+scatter"&&Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol)):f.type==="band"?ri(o,i.lineProgram,f.buffer,f.count,S,T):f.type==="heatmap"?ai(o,i.heatmapProgram,f.buffer,f.count,S,f.zBounds,f.colormapTexture):f.type==="bar"&&li(o,i.lineProgram,f.buffer,f.count,S,T)}}class ui{constructor(e){p(this,"textures",new Map);this.gl=e}createColormapTexture(e,t){const{gl:i}=this;let n=this.textures.get(e);return n||(n=i.createTexture(),this.textures.set(e,n)),i.bindTexture(i.TEXTURE_2D,n),i.pixelStorei(i.UNPACK_ALIGNMENT,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t.length/4,1,0,i.RGBA,i.UNSIGNED_BYTE,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),n}getTexture(e){return this.textures.get(e)}destroy(){this.textures.forEach(e=>this.gl.deleteTexture(e)),this.textures.clear()}}class ce{constructor(e){p(this,"canvas");p(this,"gl");p(this,"dpr");p(this,"programs");p(this,"buffers");p(this,"textures");p(this,"isInitialized",!1);this.canvas=e,this.dpr=window.devicePixelRatio||1;const t=e.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"});if(!t)throw new Error("WebGL not supported");this.gl=t,this.programs=ni(t),this.buffers=new Kt(t),this.textures=new ui(t),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),this.isInitialized=!0}setDPR(e){this.dpr=e,this.resize()}get available(){return this.isInitialized}createBuffer(e,t){this.buffers.createBuffer(e,t)}updateBuffer(e,t,i){return this.buffers.updateBuffer(e,t,i)}getBuffer(e){return this.buffers.getBuffer(e)}deleteBuffer(e){this.buffers.deleteBuffer(e)}createColormapTexture(e,t){return this.textures.createColormapTexture(e,t)}getTexture(e){return this.textures.getTexture(e)}render(e,t){this.isInitialized&&hi(this.gl,this.canvas,this.dpr,this.programs,e,t)}resize(){const e=this.canvas.getBoundingClientRect(),t=e.width*this.dpr,i=e.height*this.dpr;(this.canvas.width!==t||this.canvas.height!==i)&&(this.canvas.width=t,this.canvas.height=i,this.gl.viewport(0,0,t,i))}getLimits(){const{gl:e}=this;return{maxTextureSize:e.getParameter(e.MAX_TEXTURE_SIZE),maxViewportDims:e.getParameter(e.MAX_VIEWPORT_DIMS),renderer:e.getParameter(e.RENDERER),vendor:e.getParameter(e.VENDOR)}}destroy(){const{gl:e}=this;this.buffers.destroy(),this.textures.destroy(),e.deleteProgram(this.programs.lineProgram.program),e.deleteProgram(this.programs.pointProgram.program),e.deleteProgram(this.programs.heatmapProgram.program),this.isInitialized=!1}}const X={lineColor:"#666666",lineWidth:1,tickColor:"#888888",tickLength:6,labelColor:"#cccccc",labelSize:12,titleColor:"#ffffff",titleSize:14,fontFamily:"Inter, system-ui, sans-serif"},he={visible:!0,majorColor:"rgba(255, 255, 255, 0.12)",minorColor:"rgba(255, 255, 255, 0.05)",majorWidth:1,minorWidth:.5,majorDash:[4,4],minorDash:[2,4],showMinor:!0,minorDivisions:5},ue={visible:!0,position:"top-right",backgroundColor:"rgba(20, 20, 30, 0.9)",borderColor:"rgba(255, 255, 255, 0.15)",borderRadius:6,textColor:"#ffffff",fontSize:11,fontFamily:"Inter, system-ui, sans-serif",padding:5,itemGap:3,swatchSize:12},de={lineColor:"rgba(255, 255, 255, 0.5)",lineWidth:1,lineDash:[5,5],tooltipBackground:"rgba(20, 20, 30, 0.95)",tooltipBorder:"rgba(255, 255, 255, 0.2)",tooltipColor:"#ffffff",tooltipSize:11},fe={name:"dark",backgroundColor:"#0b0e14",plotBorderColor:"#444c56",grid:{...he,majorColor:"rgba(255, 255, 255, 0.12)",minorColor:"rgba(255, 255, 255, 0.04)"},xAxis:{...X,labelColor:"#adbac7",titleColor:"#cdd9e5",lineColor:"#444c56",tickColor:"#444c56"},yAxis:{...X,labelColor:"#adbac7",titleColor:"#cdd9e5",lineColor:"#444c56",tickColor:"#444c56"},legend:ue,cursor:de},st={name:"midnight",backgroundColor:"#05050a",plotBorderColor:"#3a3a5a",grid:{...he,majorColor:"rgba(150, 150, 255, 0.2)",minorColor:"rgba(150, 150, 255, 0.08)"},xAxis:{...X,lineColor:"#5a5a8a",labelColor:"#b0b0e0",titleColor:"#d0d0f0",tickColor:"#5a5a8a"},yAxis:{...X,lineColor:"#5a5a8a",labelColor:"#b0b0e0",titleColor:"#d0d0f0",tickColor:"#5a5a8a"},legend:{...ue,backgroundColor:"rgba(15, 15, 30, 0.95)",borderColor:"rgba(100, 100, 255, 0.4)"},cursor:{...de,lineColor:"rgba(150, 150, 255, 0.7)"}},rt={name:"light",backgroundColor:"#ffffff",plotBorderColor:"#cccccc",grid:{...he,majorColor:"rgba(0, 0, 0, 0.1)",minorColor:"rgba(0, 0, 0, 0.04)"},xAxis:{...X,lineColor:"#888888",tickColor:"#888888",labelColor:"#444444",titleColor:"#222222"},yAxis:{...X,lineColor:"#888888",tickColor:"#888888",labelColor:"#444444",titleColor:"#222222"},legend:{...ue,backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"rgba(0, 0, 0, 0.15)",textColor:"#222222"},cursor:{...de,lineColor:"rgba(0, 0, 0, 0.4)",tooltipBackground:"rgba(50, 50, 60, 0.95)"}},at={name:"electrochemistry",backgroundColor:"#0a1628",plotBorderColor:"#1e3a5f",grid:{...he,majorColor:"rgba(30, 136, 229, 0.15)",minorColor:"rgba(30, 136, 229, 0.06)",showMinor:!0,minorDivisions:2},xAxis:{...X,lineColor:"#1e88e5",tickColor:"#42a5f5",labelColor:"#90caf9",titleColor:"#bbdefb"},yAxis:{...X,lineColor:"#1e88e5",tickColor:"#42a5f5",labelColor:"#90caf9",titleColor:"#bbdefb"},legend:{...ue,backgroundColor:"rgba(10, 22, 40, 0.95)",borderColor:"rgba(30, 136, 229, 0.3)"},cursor:{...de,lineColor:"rgba(100, 180, 255, 0.6)"}};function di(o,e){return{...o,...e,grid:{...o.grid,...e.grid},xAxis:{...o.xAxis,...e.xAxis},yAxis:{...o.yAxis,...e.yAxis},legend:{...o.legend,...e.legend},cursor:{...o.cursor,...e.cursor}}}function Be(o){switch(o){case"dark":return fe;case"midnight":return st;case"light":return rt;case"electrochemistry":case"electrochem":return at;default:return console.warn(`[Theme] Unknown theme "${o}", using dark`),fe}}const lt=fe;class ct{constructor(e,t){p(this,"ctx");p(this,"theme");this.ctx=e,this.theme=t}setTheme(e){this.theme=e}clear(e,t){this.ctx.clearRect(0,0,e,t)}drawGrid(e,t,i){if(!this.theme.grid.visible)return;const{ctx:n}=this,s=this.theme.grid,r=t.ticks(8),a=i.ticks(6);if(n.strokeStyle=s.majorColor,n.lineWidth=s.majorWidth,n.setLineDash(s.majorDash),r.forEach(l=>{const c=t.transform(l);c>=e.x&&c<=e.x+e.width&&(n.beginPath(),n.moveTo(c,e.y),n.lineTo(c,e.y+e.height),n.stroke())}),a.forEach(l=>{const c=i.transform(l);c>=e.y&&c<=e.y+e.height&&(n.beginPath(),n.moveTo(e.x,c),n.lineTo(e.x+e.width,c),n.stroke())}),s.showMinor){n.strokeStyle=s.minorColor,n.lineWidth=s.minorWidth,n.setLineDash(s.minorDash);const l=this.generateMinorTicks(r,s.minorDivisions),c=this.generateMinorTicks(a,s.minorDivisions);l.forEach(h=>{const u=t.transform(h);u>=e.x&&u<=e.x+e.width&&(n.beginPath(),n.moveTo(u,e.y),n.lineTo(u,e.y+e.height),n.stroke())}),c.forEach(h=>{const u=i.transform(h);u>=e.y&&u<=e.y+e.height&&(n.beginPath(),n.moveTo(e.x,u),n.lineTo(e.x+e.width,u),n.stroke())})}n.setLineDash([])}drawXAxis(e,t,i){const{ctx:n}=this,s=this.theme.xAxis,r=t.ticks(8),a=e.y+e.height;n.strokeStyle=s.lineColor,n.lineWidth=s.lineWidth,n.beginPath(),n.moveTo(e.x,a),n.lineTo(e.x+e.width,a),n.stroke(),n.fillStyle=s.labelColor,n.font=`${s.labelSize}px ${s.fontFamily}`,n.textAlign="center",n.textBaseline="top",r.forEach(l=>{const c=t.transform(l);c>=e.x&&c<=e.x+e.width&&(n.strokeStyle=s.tickColor,n.beginPath(),n.moveTo(c,a),n.lineTo(c,a+s.tickLength),n.stroke(),n.fillText(this.formatXTick(l),c,a+s.tickLength+3))}),i&&(n.fillStyle=s.titleColor,n.font=`${s.titleSize}px ${s.fontFamily}`,n.textAlign="center",n.textBaseline="bottom",n.fillText(i,e.x+e.width/2,e.y+e.height+45))}drawYAxis(e,t,i,n="left",s=0){const{ctx:r}=this,a=this.theme.yAxis,l=t.ticks(6),c=n==="left"?e.x-s:e.x+e.width+s,h=n==="left"?-1:1;if(r.strokeStyle=a.lineColor,r.lineWidth=a.lineWidth,r.beginPath(),r.moveTo(c,e.y),r.lineTo(c,e.y+e.height),r.stroke(),r.fillStyle=a.labelColor,r.font=`${a.labelSize}px ${a.fontFamily}`,r.textAlign=n==="left"?"right":"left",r.textBaseline="middle",l.forEach(u=>{const d=t.transform(u);if(d>=e.y&&d<=e.y+e.height){r.strokeStyle=a.tickColor,r.beginPath(),r.moveTo(c,d),r.lineTo(c+a.tickLength*h,d),r.stroke();const f=c+(a.tickLength+3)*h;r.fillText(this.formatYTick(u),f,d)}}),i){r.save(),r.fillStyle=a.titleColor,r.font=`${a.titleSize}px ${a.fontFamily}`,r.textAlign="center",r.textBaseline="top";const u=n==="left"?c-40:c+40,d=e.y+e.height/2;r.translate(u,d),r.rotate(n==="left"?-Math.PI/2:Math.PI/2),r.fillText(i,0,0),r.restore()}}drawPlotBorder(e){const{ctx:t}=this;t.strokeStyle=this.theme.plotBorderColor,t.lineWidth=1,t.strokeRect(e.x,e.y,e.width,e.height)}drawLegend(e,t){if(t.length===0)return;const{ctx:i}=this,n=this.theme.legend;i.font=`${n.fontSize}px ${n.fontFamily}`;let s=0;const r=t.map(d=>{const f=d.getId(),g=d.getStyle(),m=i.measureText(f).width;return s=Math.max(s,m),{id:d.getId(),color:g.color??"#ff0055",label:f,type:d.getType(),symbol:g.symbol,opacity:g.opacity??1}}),a=n.swatchSize+8+s+n.padding*2,l=r.length*(n.swatchSize+n.itemGap)-n.itemGap+n.padding*2;let c,h;switch(n.position){case"top-left":c=e.x+10,h=e.y+10;break;case"bottom-left":c=e.x+10,h=e.y+10;break;case"bottom-right":c=e.x+e.width-a-10,h=e.y+e.height-l-10;break;case"top-right":default:c=e.x+e.width-a-10,h=e.y+10;break}i.fillStyle=n.backgroundColor,i.strokeStyle=n.borderColor,i.lineWidth=1,i.beginPath();const u=n.borderRadius;i.moveTo(c+u,h),i.lineTo(c+a-u,h),i.arcTo(c+a,h,c+a,h+u,u),i.lineTo(c+a,h+l-u),i.arcTo(c+a,h+l,c+a-u,h+l,u),i.lineTo(c+u,h+l),i.arcTo(c,h+l,c,h+l-u,u),i.lineTo(c,h+u),i.arcTo(c,h,c+u,h,u),i.closePath(),i.fill(),i.stroke(),i.textAlign="left",i.textBaseline="middle",r.forEach((d,f)=>{const g=h+n.padding+f*(n.swatchSize+n.itemGap),m=c+n.padding,y=g+n.swatchSize/2,b=m+n.swatchSize/2;i.save(),i.globalAlpha=d.opacity,i.fillStyle=d.color,i.strokeStyle=d.color,i.lineWidth=2;const v=n.swatchSize,S=String(d.type).toLowerCase(),T=!!d.symbol&&d.symbol!=="circle",P=S==="scatter"||S==="1"||S==="line"&&T,M=S.includes("scatter")||S==="2";P?this.drawLegendSymbol(i,d.symbol??"circle",b,y,v*.9):M?(i.beginPath(),i.moveTo(m,y),i.lineTo(m+v,y),i.stroke(),this.drawLegendSymbol(i,d.symbol??"circle",b,y,v*.6)):(i.beginPath(),i.moveTo(m,y),i.lineTo(m+v,y),i.stroke()),i.restore(),i.fillStyle=n.textColor,i.fillText(d.label,c+n.padding+n.swatchSize+8,y)})}drawLegendSymbol(e,t,i,n,s){const r=s/2;switch(e.beginPath(),t){case"circle":e.arc(i,n,r,0,Math.PI*2),e.fill();break;case"square":e.rect(i-r,n-r,s,s),e.fill();break;case"diamond":e.moveTo(i,n-r),e.lineTo(i+r,n),e.lineTo(i,n+r),e.lineTo(i-r,n),e.closePath(),e.fill();break;case"triangle":e.moveTo(i,n-r),e.lineTo(i+r,n+r),e.lineTo(i-r,n+r),e.closePath(),e.fill();break;case"triangleDown":e.moveTo(i,n+r),e.lineTo(i+r,n-r),e.lineTo(i-r,n-r),e.closePath(),e.fill();break;case"cross":e.moveTo(i-r,n),e.lineTo(i+r,n),e.moveTo(i,n-r),e.lineTo(i,n+r),e.stroke();break;case"x":const a=r*.707;e.moveTo(i-a,n-a),e.lineTo(i+a,n+a),e.moveTo(i+a,n-a),e.lineTo(i-a,n+a),e.stroke();break;case"star":for(let l=0;l<5;l++)e.lineTo(i+r*Math.cos((18+l*72)/180*Math.PI),n-r*Math.sin((18+l*72)/180*Math.PI)),e.lineTo(i+r/2*Math.cos((54+l*72)/180*Math.PI),n-r/2*Math.sin((54+l*72)/180*Math.PI));e.closePath(),e.fill();break}}drawCursor(e,t){if(!t.enabled)return;const{ctx:i}=this,n=this.theme.cursor;t.x<e.x||t.x>e.x+e.width||t.y<e.y||t.y>e.y+e.height||(i.save(),i.beginPath(),i.rect(e.x,e.y,e.width,e.height),i.clip(),i.strokeStyle=n.lineColor,i.lineWidth=n.lineWidth,i.setLineDash(n.lineDash),t.crosshair?(i.beginPath(),i.moveTo(t.x,e.y),i.lineTo(t.x,e.y+e.height),i.stroke(),i.beginPath(),i.moveTo(e.x,t.y),i.lineTo(e.x+e.width,t.y),i.stroke()):(i.beginPath(),i.moveTo(t.x,e.y),i.lineTo(t.x,e.y+e.height),i.stroke()),i.restore(),t.tooltipText&&this.drawTooltip(t.x,t.y,t.tooltipText,e))}drawTooltip(e,t,i,n){const{ctx:s}=this,r=this.theme.cursor,a=i.split(`
|
|
137
|
-
`),l=
|
|
136
|
+
`;function nt(o,e,t){const i=o.createShader(t);if(!i)throw new Error("Failed to create shader");if(o.shaderSource(i,e),o.compileShader(i),!o.getShaderParameter(i,o.COMPILE_STATUS)){const n=o.getShaderInfoLog(i);throw o.deleteShader(i),new Error(`Shader compilation error: ${n}`)}return i}function Ce(o,e,t,i){const n=nt(o,e,o.VERTEX_SHADER),r=nt(o,t,o.FRAGMENT_SHADER),s=o.createProgram();if(!s)throw new Error("Failed to create program");if(o.attachShader(s,n),o.attachShader(s,r),o.linkProgram(s),!o.getProgramParameter(s,o.LINK_STATUS)){const a=o.getProgramInfoLog(s);throw new Error(`Program link error: ${a}`)}return o.deleteShader(n),o.deleteShader(r),{program:s,attributes:{position:o.getAttribLocation(s,i==="heatmap"?"aPosition":"position"),value:i==="heatmap"?o.getAttribLocation(s,"aValue"):-1},uniforms:{uScale:o.getUniformLocation(s,"uScale"),uTranslate:o.getUniformLocation(s,"uTranslate"),uColor:i!=="heatmap"?o.getUniformLocation(s,"uColor"):null,uPointSize:i==="point"?o.getUniformLocation(s,"uPointSize"):null,uSymbol:i==="point"?o.getUniformLocation(s,"uSymbol"):null,uMinValue:i==="heatmap"?o.getUniformLocation(s,"uMinValue"):null,uMaxValue:i==="heatmap"?o.getUniformLocation(s,"uMaxValue"):null,uColormap:i==="heatmap"?o.getUniformLocation(s,"uColormap"):null}}}function ni(o){return{lineProgram:Ce(o,Zt,Jt,"line"),pointProgram:Ce(o,Qt,ei,"point"),heatmapProgram:Ce(o,ti,ii,"heatmap")}}function ae(o){if(!o)return[1,0,1,1];if(o.startsWith("#")){const e=o.slice(1);if(e.length===3){const t=parseInt(e[0]+e[0],16)/255,i=parseInt(e[1]+e[1],16)/255,n=parseInt(e[2]+e[2],16)/255;return[t,i,n,1]}else if(e.length===6){const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16)/255,n=parseInt(e.slice(4,6),16)/255;return[t,i,n,1]}else if(e.length===8){const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16)/255,n=parseInt(e.slice(4,6),16)/255,r=parseInt(e.slice(6,8),16)/255;return[t,i,n,r]}}if(o.startsWith("rgb")){const e=o.match(/[\d.]+/g);if(e&&e.length>=3){const t=parseFloat(e[0])/255,i=parseFloat(e[1])/255,n=parseFloat(e[2])/255,r=e.length>=4?parseFloat(e[3]):1;return[t,i,n,r]}}return[1,0,1,1]}function ke(o,e){const t=Math.min(o.length,e.length),i=new Float32Array(t*2);for(let n=0;n<t;n++)i[n*2]=o[n],i[n*2+1]=e[n];return i}function oi(o,e,t="after"){const i=Math.min(o.length,e.length);if(i<2)return ke(o,e);const n=t==="center"?1+(i-1)*3:i*2-1,r=new Float32Array(n*2);let s=0;for(let a=0;a<i;a++)if(a===0)r[s++]=o[0],r[s++]=e[0];else{const l=o[a-1],c=e[a-1],h=o[a],u=e[a];if(t==="after")r[s++]=h,r[s++]=c,r[s++]=h,r[s++]=u;else if(t==="before")r[s++]=l,r[s++]=u,r[s++]=h,r[s++]=u;else{const d=(l+h)/2;r[s++]=d,r[s++]=c,r[s++]=d,r[s++]=u,r[s++]=h,r[s++]=u}}return r.subarray(0,s)}function ot(o,e,t){const i=Math.min(o.length,e.length,t.length),n=new Float32Array(i*2*2);for(let r=0;r<i;r++){const s=r*4,a=o[r];n[s+0]=a,n[s+1]=e[r],n[s+2]=a,n[s+3]=t[r]}return n}function ri(o){const e=o.xMax-o.xMin,t=o.yMax-o.yMin,i=e>0?2/e:1,n=t>0?2/t:1,r=-1-o.xMin*i,s=-1-o.yMin*n;return{scale:[i,n],translate:[r,s]}}function le(o,e,t,i,n,r){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,r[0],r[1],r[2],r[3]),o.drawArrays(o.LINE_STRIP,0,i),o.disableVertexAttribArray(e.attributes.position)}function si(o,e,t,i,n,r){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]);const s=r[3]*.4;o.uniform4f(e.uniforms.uColor,r[0],r[1],r[2],s),o.drawArrays(o.TRIANGLE_STRIP,0,i),o.disableVertexAttribArray(e.attributes.position)}function Ee(o,e,t,i,n,r,s,a="circle"){if(o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,r[0],r[1],r[2],r[3]),e.uniforms.uPointSize&&o.uniform1f(e.uniforms.uPointSize,s),e.uniforms.uSymbol){const l={circle:0,square:1,diamond:2,triangle:3,triangleDown:4,cross:5,x:6,star:7};o.uniform1i(e.uniforms.uSymbol,l[a]??0)}o.drawArrays(o.POINTS,0,i),o.disableVertexAttribArray(e.attributes.position)}function ai(o,e,t,i,n,r={min:0,max:1},s){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,12,0),e.attributes.value!==void 0&&e.attributes.value!==-1&&(o.enableVertexAttribArray(e.attributes.value),o.vertexAttribPointer(e.attributes.value,1,o.FLOAT,!1,12,8)),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),e.uniforms.uMinValue&&o.uniform1f(e.uniforms.uMinValue,r.min),e.uniforms.uMaxValue&&o.uniform1f(e.uniforms.uMaxValue,r.max),s&&e.uniforms.uColormap?(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,s),o.uniform1i(e.uniforms.uColormap,0)):e.uniforms.uColormap&&(o.activeTexture(o.TEXTURE0),o.bindTexture(o.TEXTURE_2D,null)),o.drawArrays(o.TRIANGLES,0,i),o.disableVertexAttribArray(e.attributes.position),e.attributes.value!==void 0&&e.attributes.value!==-1&&o.disableVertexAttribArray(e.attributes.value)}function li(o,e,t,i,n,r){o.useProgram(e.program),o.bindBuffer(o.ARRAY_BUFFER,t),o.enableVertexAttribArray(e.attributes.position),o.vertexAttribPointer(e.attributes.position,2,o.FLOAT,!1,0,0),o.uniform2f(e.uniforms.uScale,n.scale[0],n.scale[1]),o.uniform2f(e.uniforms.uTranslate,n.translate[0],n.translate[1]),o.uniform4f(e.uniforms.uColor,r[0],r[1],r[2],r[3]),o.drawArrays(o.TRIANGLES,0,i),o.disableVertexAttribArray(e.attributes.position)}function ci(o){const e=ae(o.color??"#ff0055");return e[3]=o.opacity??1,e}function hi(o,e,t,i,n,r){const{bounds:s,backgroundColor:a=[.1,.1,.18,1],plotArea:l}=r,c=e.height,h=e.width,u=l?{x:l.x*t,y:c-(l.y+l.height)*t,width:l.width*t,height:l.height*t}:{x:0,y:0,width:h,height:c};o.viewport(0,0,h,c),o.disable(o.SCISSOR_TEST),o.clearColor(a[0],a[1],a[2],a[3]),o.clear(o.COLOR_BUFFER_BIT),o.viewport(u.x,u.y,u.width,u.height),o.enable(o.SCISSOR_TEST),o.scissor(u.x,u.y,u.width,u.height);const d=ri(s);for(const f of n){if(!f.visible||f.count===0)continue;const g=f.yBounds?f.yBounds.min:s.yMin,y=(f.yBounds?f.yBounds.max:s.yMax)-g,b=y>0?2/y:1,v=-1-g*b,S={scale:[d.scale[0],b],translate:[d.translate[0],v]},T=ci(f.style);f.type==="scatter"?Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol):f.type==="line"?le(o,i.lineProgram,f.buffer,f.count,S,T):f.type==="line+scatter"?(le(o,i.lineProgram,f.buffer,f.count,S,T),Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol)):f.type==="step"||f.type==="step+scatter"?(f.stepBuffer&&f.stepCount?le(o,i.lineProgram,f.stepBuffer,f.stepCount,S,T):le(o,i.lineProgram,f.buffer,f.count,S,T),f.type==="step+scatter"&&Ee(o,i.pointProgram,f.buffer,f.count,S,T,(f.style.pointSize??4)*t,f.style.symbol)):f.type==="band"?si(o,i.lineProgram,f.buffer,f.count,S,T):f.type==="heatmap"?ai(o,i.heatmapProgram,f.buffer,f.count,S,f.zBounds,f.colormapTexture):f.type==="bar"&&li(o,i.lineProgram,f.buffer,f.count,S,T)}}class ui{constructor(e){p(this,"textures",new Map);this.gl=e}createColormapTexture(e,t){const{gl:i}=this;let n=this.textures.get(e);return n||(n=i.createTexture(),this.textures.set(e,n)),i.bindTexture(i.TEXTURE_2D,n),i.pixelStorei(i.UNPACK_ALIGNMENT,1),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t.length/4,1,0,i.RGBA,i.UNSIGNED_BYTE,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),n}getTexture(e){return this.textures.get(e)}destroy(){this.textures.forEach(e=>this.gl.deleteTexture(e)),this.textures.clear()}}class ce{constructor(e){p(this,"canvas");p(this,"gl");p(this,"dpr");p(this,"programs");p(this,"buffers");p(this,"textures");p(this,"isInitialized",!1);this.canvas=e,this.dpr=window.devicePixelRatio||1;const t=e.getContext("webgl",{alpha:!0,antialias:!0,preserveDrawingBuffer:!0,powerPreference:"high-performance"});if(!t)throw new Error("WebGL not supported");this.gl=t,this.programs=ni(t),this.buffers=new Kt(t),this.textures=new ui(t),t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),this.isInitialized=!0}setDPR(e){this.dpr=e,this.resize()}get available(){return this.isInitialized}createBuffer(e,t){this.buffers.createBuffer(e,t)}updateBuffer(e,t,i){return this.buffers.updateBuffer(e,t,i)}getBuffer(e){return this.buffers.getBuffer(e)}deleteBuffer(e){this.buffers.deleteBuffer(e)}createColormapTexture(e,t){return this.textures.createColormapTexture(e,t)}getTexture(e){return this.textures.getTexture(e)}render(e,t){this.isInitialized&&hi(this.gl,this.canvas,this.dpr,this.programs,e,t)}resize(){const e=this.canvas.getBoundingClientRect(),t=e.width*this.dpr,i=e.height*this.dpr;(this.canvas.width!==t||this.canvas.height!==i)&&(this.canvas.width=t,this.canvas.height=i,this.gl.viewport(0,0,t,i))}getLimits(){const{gl:e}=this;return{maxTextureSize:e.getParameter(e.MAX_TEXTURE_SIZE),maxViewportDims:e.getParameter(e.MAX_VIEWPORT_DIMS),renderer:e.getParameter(e.RENDERER),vendor:e.getParameter(e.VENDOR)}}destroy(){const{gl:e}=this;this.buffers.destroy(),this.textures.destroy(),e.deleteProgram(this.programs.lineProgram.program),e.deleteProgram(this.programs.pointProgram.program),e.deleteProgram(this.programs.heatmapProgram.program),this.isInitialized=!1}}const X={lineColor:"#666666",lineWidth:1,tickColor:"#888888",tickLength:6,labelColor:"#cccccc",labelSize:12,titleColor:"#ffffff",titleSize:14,fontFamily:"Inter, system-ui, sans-serif"},he={visible:!0,majorColor:"rgba(255, 255, 255, 0.12)",minorColor:"rgba(255, 255, 255, 0.05)",majorWidth:1,minorWidth:.5,majorDash:[4,4],minorDash:[2,4],showMinor:!0,minorDivisions:5},ue={visible:!0,position:"top-right",backgroundColor:"rgba(20, 20, 30, 0.9)",borderColor:"rgba(255, 255, 255, 0.15)",borderRadius:6,textColor:"#ffffff",fontSize:11,fontFamily:"Inter, system-ui, sans-serif",padding:5,itemGap:3,swatchSize:12},de={lineColor:"rgba(255, 255, 255, 0.5)",lineWidth:1,lineDash:[5,5],tooltipBackground:"rgba(20, 20, 30, 0.95)",tooltipBorder:"rgba(255, 255, 255, 0.2)",tooltipColor:"#ffffff",tooltipSize:11},fe={name:"dark",backgroundColor:"#0b0e14",plotBorderColor:"#444c56",grid:{...he,majorColor:"rgba(255, 255, 255, 0.12)",minorColor:"rgba(255, 255, 255, 0.04)"},xAxis:{...X,labelColor:"#adbac7",titleColor:"#cdd9e5",lineColor:"#444c56",tickColor:"#444c56"},yAxis:{...X,labelColor:"#adbac7",titleColor:"#cdd9e5",lineColor:"#444c56",tickColor:"#444c56"},legend:ue,cursor:de},rt={name:"midnight",backgroundColor:"#05050a",plotBorderColor:"#3a3a5a",grid:{...he,majorColor:"rgba(150, 150, 255, 0.2)",minorColor:"rgba(150, 150, 255, 0.08)"},xAxis:{...X,lineColor:"#5a5a8a",labelColor:"#b0b0e0",titleColor:"#d0d0f0",tickColor:"#5a5a8a"},yAxis:{...X,lineColor:"#5a5a8a",labelColor:"#b0b0e0",titleColor:"#d0d0f0",tickColor:"#5a5a8a"},legend:{...ue,backgroundColor:"rgba(15, 15, 30, 0.95)",borderColor:"rgba(100, 100, 255, 0.4)"},cursor:{...de,lineColor:"rgba(150, 150, 255, 0.7)"}},st={name:"light",backgroundColor:"#ffffff",plotBorderColor:"#cccccc",grid:{...he,majorColor:"rgba(0, 0, 0, 0.1)",minorColor:"rgba(0, 0, 0, 0.04)"},xAxis:{...X,lineColor:"#888888",tickColor:"#888888",labelColor:"#444444",titleColor:"#222222"},yAxis:{...X,lineColor:"#888888",tickColor:"#888888",labelColor:"#444444",titleColor:"#222222"},legend:{...ue,backgroundColor:"rgba(255, 255, 255, 0.95)",borderColor:"rgba(0, 0, 0, 0.15)",textColor:"#222222"},cursor:{...de,lineColor:"rgba(0, 0, 0, 0.4)",tooltipBackground:"rgba(50, 50, 60, 0.95)"}},at={name:"electrochemistry",backgroundColor:"#0a1628",plotBorderColor:"#1e3a5f",grid:{...he,majorColor:"rgba(30, 136, 229, 0.15)",minorColor:"rgba(30, 136, 229, 0.06)",showMinor:!0,minorDivisions:2},xAxis:{...X,lineColor:"#1e88e5",tickColor:"#42a5f5",labelColor:"#90caf9",titleColor:"#bbdefb"},yAxis:{...X,lineColor:"#1e88e5",tickColor:"#42a5f5",labelColor:"#90caf9",titleColor:"#bbdefb"},legend:{...ue,backgroundColor:"rgba(10, 22, 40, 0.95)",borderColor:"rgba(30, 136, 229, 0.3)"},cursor:{...de,lineColor:"rgba(100, 180, 255, 0.6)"}};function di(o,e){return{...o,...e,grid:{...o.grid,...e.grid},xAxis:{...o.xAxis,...e.xAxis},yAxis:{...o.yAxis,...e.yAxis},legend:{...o.legend,...e.legend},cursor:{...o.cursor,...e.cursor}}}function Be(o){switch(o){case"dark":return fe;case"midnight":return rt;case"light":return st;case"electrochemistry":case"electrochem":return at;default:return console.warn(`[Theme] Unknown theme "${o}", using dark`),fe}}const lt=fe;class ct{constructor(e,t){p(this,"ctx");p(this,"theme");this.ctx=e,this.theme=t}setTheme(e){this.theme=e}clear(e,t){this.ctx.clearRect(0,0,e,t)}drawGrid(e,t,i){if(!this.theme.grid.visible)return;const{ctx:n}=this,r=this.theme.grid,s=t.ticks(8),a=i.ticks(6);if(n.strokeStyle=r.majorColor,n.lineWidth=r.majorWidth,n.setLineDash(r.majorDash),s.forEach(l=>{const c=t.transform(l);c>=e.x&&c<=e.x+e.width&&(n.beginPath(),n.moveTo(c,e.y),n.lineTo(c,e.y+e.height),n.stroke())}),a.forEach(l=>{const c=i.transform(l);c>=e.y&&c<=e.y+e.height&&(n.beginPath(),n.moveTo(e.x,c),n.lineTo(e.x+e.width,c),n.stroke())}),r.showMinor){n.strokeStyle=r.minorColor,n.lineWidth=r.minorWidth,n.setLineDash(r.minorDash);const l=this.generateMinorTicks(s,r.minorDivisions),c=this.generateMinorTicks(a,r.minorDivisions);l.forEach(h=>{const u=t.transform(h);u>=e.x&&u<=e.x+e.width&&(n.beginPath(),n.moveTo(u,e.y),n.lineTo(u,e.y+e.height),n.stroke())}),c.forEach(h=>{const u=i.transform(h);u>=e.y&&u<=e.y+e.height&&(n.beginPath(),n.moveTo(e.x,u),n.lineTo(e.x+e.width,u),n.stroke())})}n.setLineDash([])}drawXAxis(e,t,i){const{ctx:n}=this,r=this.theme.xAxis,s=t.ticks(8),a=e.y+e.height,l=i==null?void 0:i.label;n.strokeStyle=r.lineColor,n.lineWidth=r.lineWidth,n.beginPath(),n.moveTo(e.x,a),n.lineTo(e.x+e.width,a),n.stroke(),n.fillStyle=r.labelColor,n.font=`${r.labelSize}px ${r.fontFamily}`,n.textAlign="center",n.textBaseline="top",s.forEach(c=>{const h=t.transform(c);h>=e.x&&h<=e.x+e.width&&(n.strokeStyle=r.tickColor,n.beginPath(),n.moveTo(h,a),n.lineTo(h,a+r.tickLength),n.stroke(),n.fillText(this.formatXTick(c,i),h,a+r.tickLength+3))}),l&&(n.fillStyle=r.titleColor,n.font=`${r.titleSize}px ${r.fontFamily}`,n.textAlign="center",n.textBaseline="bottom",n.fillText(l,e.x+e.width/2,e.y+e.height+45))}drawYAxis(e,t,i,n="left",r=0){const{ctx:s}=this,a=this.theme.yAxis,l=t.ticks(6),c=i==null?void 0:i.label,h=n==="left"?e.x-r:e.x+e.width+r,u=n==="left"?-1:1;if(s.strokeStyle=a.lineColor,s.lineWidth=a.lineWidth,s.beginPath(),s.moveTo(h,e.y),s.lineTo(h,e.y+e.height),s.stroke(),s.fillStyle=a.labelColor,s.font=`${a.labelSize}px ${a.fontFamily}`,s.textAlign=n==="left"?"right":"left",s.textBaseline="middle",l.forEach(d=>{const f=t.transform(d);if(f>=e.y&&f<=e.y+e.height){s.strokeStyle=a.tickColor,s.beginPath(),s.moveTo(h,f),s.lineTo(h+a.tickLength*u,f),s.stroke();const g=h+(a.tickLength+3)*u;s.fillText(this.formatYTick(d,i),g,f)}}),c){s.save(),s.fillStyle=a.titleColor,s.font=`${a.titleSize}px ${a.fontFamily}`,s.textAlign="center",s.textBaseline="top";const d=n==="left"?h-40:h+40,f=e.y+e.height/2;s.translate(d,f),s.rotate(n==="left"?-Math.PI/2:Math.PI/2),s.fillText(c,0,0),s.restore()}}drawPlotBorder(e){const{ctx:t}=this;t.strokeStyle=this.theme.plotBorderColor,t.lineWidth=1,t.strokeRect(e.x,e.y,e.width,e.height)}drawLegend(e,t){if(t.length===0)return;const{ctx:i}=this,n=this.theme.legend;i.font=`${n.fontSize}px ${n.fontFamily}`;let r=0;const s=t.map(d=>{const f=d.getId(),g=d.getStyle(),m=i.measureText(f).width;return r=Math.max(r,m),{id:d.getId(),color:g.color??"#ff0055",label:f,type:d.getType(),symbol:g.symbol,opacity:g.opacity??1}}),a=n.swatchSize+8+r+n.padding*2,l=s.length*(n.swatchSize+n.itemGap)-n.itemGap+n.padding*2;let c,h;switch(n.position){case"top-left":c=e.x+10,h=e.y+10;break;case"bottom-left":c=e.x+10,h=e.y+10;break;case"bottom-right":c=e.x+e.width-a-10,h=e.y+e.height-l-10;break;case"top-right":default:c=e.x+e.width-a-10,h=e.y+10;break}i.fillStyle=n.backgroundColor,i.strokeStyle=n.borderColor,i.lineWidth=1,i.beginPath();const u=n.borderRadius;i.moveTo(c+u,h),i.lineTo(c+a-u,h),i.arcTo(c+a,h,c+a,h+u,u),i.lineTo(c+a,h+l-u),i.arcTo(c+a,h+l,c+a-u,h+l,u),i.lineTo(c+u,h+l),i.arcTo(c,h+l,c,h+l-u,u),i.lineTo(c,h+u),i.arcTo(c,h,c+u,h,u),i.closePath(),i.fill(),i.stroke(),i.textAlign="left",i.textBaseline="middle",s.forEach((d,f)=>{const g=h+n.padding+f*(n.swatchSize+n.itemGap),m=c+n.padding,y=g+n.swatchSize/2,b=m+n.swatchSize/2;i.save(),i.globalAlpha=d.opacity,i.fillStyle=d.color,i.strokeStyle=d.color,i.lineWidth=2;const v=n.swatchSize,S=String(d.type).toLowerCase(),T=!!d.symbol&&d.symbol!=="circle",P=S==="scatter"||S==="1"||S==="line"&&T,M=S.includes("scatter")||S==="2";P?this.drawLegendSymbol(i,d.symbol??"circle",b,y,v*.9):M?(i.beginPath(),i.moveTo(m,y),i.lineTo(m+v,y),i.stroke(),this.drawLegendSymbol(i,d.symbol??"circle",b,y,v*.6)):(i.beginPath(),i.moveTo(m,y),i.lineTo(m+v,y),i.stroke()),i.restore(),i.fillStyle=n.textColor,i.fillText(d.label,c+n.padding+n.swatchSize+8,y)})}drawLegendSymbol(e,t,i,n,r){const s=r/2;switch(e.beginPath(),t){case"circle":e.arc(i,n,s,0,Math.PI*2),e.fill();break;case"square":e.rect(i-s,n-s,r,r),e.fill();break;case"diamond":e.moveTo(i,n-s),e.lineTo(i+s,n),e.lineTo(i,n+s),e.lineTo(i-s,n),e.closePath(),e.fill();break;case"triangle":e.moveTo(i,n-s),e.lineTo(i+s,n+s),e.lineTo(i-s,n+s),e.closePath(),e.fill();break;case"triangleDown":e.moveTo(i,n+s),e.lineTo(i+s,n-s),e.lineTo(i-s,n-s),e.closePath(),e.fill();break;case"cross":e.moveTo(i-s,n),e.lineTo(i+s,n),e.moveTo(i,n-s),e.lineTo(i,n+s),e.stroke();break;case"x":const a=s*.707;e.moveTo(i-a,n-a),e.lineTo(i+a,n+a),e.moveTo(i+a,n-a),e.lineTo(i-a,n+a),e.stroke();break;case"star":for(let l=0;l<5;l++)e.lineTo(i+s*Math.cos((18+l*72)/180*Math.PI),n-s*Math.sin((18+l*72)/180*Math.PI)),e.lineTo(i+s/2*Math.cos((54+l*72)/180*Math.PI),n-s/2*Math.sin((54+l*72)/180*Math.PI));e.closePath(),e.fill();break}}drawCursor(e,t){if(!t.enabled)return;const{ctx:i}=this,n=this.theme.cursor;t.x<e.x||t.x>e.x+e.width||t.y<e.y||t.y>e.y+e.height||(i.save(),i.beginPath(),i.rect(e.x,e.y,e.width,e.height),i.clip(),i.strokeStyle=n.lineColor,i.lineWidth=n.lineWidth,i.setLineDash(n.lineDash),t.crosshair?(i.beginPath(),i.moveTo(t.x,e.y),i.lineTo(t.x,e.y+e.height),i.stroke(),i.beginPath(),i.moveTo(e.x,t.y),i.lineTo(e.x+e.width,t.y),i.stroke()):(i.beginPath(),i.moveTo(t.x,e.y),i.lineTo(t.x,e.y+e.height),i.stroke()),i.restore(),t.tooltipText&&this.drawTooltip(t.x,t.y,t.tooltipText,e))}drawTooltip(e,t,i,n){const{ctx:r}=this,s=this.theme.cursor,a=i.split(`
|
|
137
|
+
`),l=s.tooltipSize+5,c=8;r.font=`${s.tooltipSize}px ${this.theme.xAxis.fontFamily}`;let h=0;a.forEach(y=>{h=Math.max(h,r.measureText(y).width)});const u=h+c*2,d=a.length*l+c*2-5;let f=e+15,g=t-d-10;f+u>n.x+n.width&&(f=e-u-15),g<n.y&&(g=t+15),r.fillStyle=s.tooltipBackground,r.strokeStyle=s.tooltipBorder,r.lineWidth=1,r.beginPath();const m=4;r.moveTo(f+m,g),r.lineTo(f+u-m,g),r.arcTo(f+u,g,f+u,g+m,m),r.lineTo(f+u,g+d-m),r.arcTo(f+u,g+d,f+u-m,g+d,m),r.lineTo(f+m,g+d),r.arcTo(f,g+d,f,g+d-m,m),r.lineTo(f,g+m),r.arcTo(f,g,f+m,g,m),r.closePath(),r.fill(),r.stroke(),r.fillStyle=s.tooltipColor,r.textAlign="left",r.textBaseline="top",a.forEach((y,b)=>{r.fillText(y,f+c,g+c+b*l)})}drawSelectionRect(e){const{ctx:t}=this,i=this.theme.name.toLowerCase().includes("dark")||this.theme.name.toLowerCase().includes("midnight");t.save(),t.fillStyle=i?"rgba(0, 170, 255, 0.15)":"rgba(0, 100, 255, 0.1)",t.strokeStyle="#00aaff",t.lineWidth=1,t.setLineDash([5,5]),t.beginPath(),t.rect(e.x,e.y,e.width,e.height),t.fill(),t.stroke(),t.restore()}drawErrorBars(e,t,i,n){if(!t.hasErrorData())return;const{ctx:r}=this,s=t.getData(),a=t.getStyle(),l=a.errorBars??{};if(l.visible===!1)return;const c=l.color??a.color??"#ff0055",h=l.width??1,u=l.capWidth??6,d=l.showCaps!==!1,f=l.opacity??.7,g=l.direction??"both";r.save(),r.beginPath(),r.rect(e.x,e.y,e.width,e.height),r.clip(),r.strokeStyle=c,r.lineWidth=h,r.globalAlpha=f;for(let m=0;m<s.x.length;m++){const y=i.transform(s.x[m]),b=n.transform(s.y[m]);if(y<e.x||y>e.x+e.width||b<e.y||b>e.y+e.height)continue;const v=t.getYError(m);if(v){const[T,P]=v,M=s.y[m],_=n.transform(M+P),B=n.transform(M-T);r.beginPath(),(g==="both"||g==="positive")&&(r.moveTo(y,b),r.lineTo(y,_),d&&(r.moveTo(y-u/2,_),r.lineTo(y+u/2,_))),(g==="both"||g==="negative")&&(r.moveTo(y,b),r.lineTo(y,B),d&&(r.moveTo(y-u/2,B),r.lineTo(y+u/2,B))),r.stroke()}const S=t.getXError(m);if(S){const[T,P]=S,M=s.x[m],_=i.transform(M+P),B=i.transform(M-T);r.beginPath(),(g==="both"||g==="positive")&&(r.moveTo(y,b),r.lineTo(_,b),d&&(r.moveTo(_,b-u/2),r.lineTo(_,b+u/2))),(g==="both"||g==="negative")&&(r.moveTo(y,b),r.lineTo(B,b),d&&(r.moveTo(B,b-u/2),r.lineTo(B,b+u/2))),r.stroke()}}r.restore()}generateMinorTicks(e,t){if(e.length<2)return[];const i=[];for(let n=0;n<e.length-1;n++){const r=(e[n+1]-e[n])/t;for(let s=1;s<t;s++)i.push(e[n]+r*s)}return i}formatXTick(e,t){return t!=null&&t.scientific||Math.abs(e)<.001&&e!==0?this.toScientificUnicode(e,1):e.toFixed(3).replace(/\.?0+$/,"")}formatYTick(e,t){if(e===0)return"0";const i=Math.abs(e);return t!=null&&t.scientific||i<1e-4||i>=1e4?this.toScientificUnicode(e,1):e.toPrecision(3)}toScientificUnicode(e,t){const i=e.toExponential(t),[n,r]=i.split("e"),s={0:"⁰",1:"¹",2:"²",3:"³",4:"⁴",5:"⁵",6:"⁶",7:"⁷",8:"⁸",9:"⁹","-":"⁻","+":"⁺"},a=r.replace("+","").replace(/[0-9\-]/g,l=>s[l]||l);return`${n}e${a}`}}class fi{constructor(e,t,i,n,r){p(this,"container");p(this,"callbacks");p(this,"getPlotArea");p(this,"getBounds");p(this,"getAxesLayout");p(this,"isDragging",!1);p(this,"panningAxisId");p(this,"isBoxSelecting",!1);p(this,"selectionStart",{x:0,y:0});p(this,"lastMousePos",{x:0,y:0});p(this,"isPanMode",!0);p(this,"boundWheel");p(this,"boundMouseDown");p(this,"boundMouseMove");p(this,"boundMouseUp");p(this,"boundMouseLeave");p(this,"boundTouchStart");p(this,"boundTouchMove");p(this,"boundTouchEnd");this.container=e,this.callbacks=t,this.getPlotArea=i,this.getBounds=n,this.getAxesLayout=r,this.boundWheel=this.handleWheel.bind(this),this.boundMouseDown=this.handleMouseDown.bind(this),this.boundMouseMove=this.handleMouseMove.bind(this),this.boundMouseUp=this.handleMouseUp.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundTouchStart=this.handleTouchStart.bind(this),this.boundTouchMove=this.handleTouchMove.bind(this),this.boundTouchEnd=this.handleTouchEnd.bind(this),this.attachListeners()}attachListeners(){this.container.addEventListener("wheel",this.boundWheel,{passive:!1}),this.container.addEventListener("mousedown",this.boundMouseDown),this.container.addEventListener("mousemove",this.boundMouseMove),this.container.addEventListener("mouseup",this.boundMouseUp),this.container.addEventListener("mouseleave",this.boundMouseLeave),this.container.addEventListener("touchstart",this.boundTouchStart),this.container.addEventListener("touchmove",this.boundTouchMove),this.container.addEventListener("touchend",this.boundTouchEnd)}detachListeners(){this.container.removeEventListener("wheel",this.boundWheel),this.container.removeEventListener("mousedown",this.boundMouseDown),this.container.removeEventListener("mousemove",this.boundMouseMove),this.container.removeEventListener("mouseup",this.boundMouseUp),this.container.removeEventListener("mouseleave",this.boundMouseLeave),this.container.removeEventListener("touchstart",this.boundTouchStart),this.container.removeEventListener("touchmove",this.boundTouchMove),this.container.removeEventListener("touchend",this.boundTouchEnd)}setPanMode(e){this.isPanMode=e}handleWheel(e){const t=this.getPlotArea();if(t.width<=1||t.height<=1)return;e.preventDefault();const i=this.container.getBoundingClientRect(),n=e.clientX-i.left,r=e.clientY-i.top,s=this.getAxesLayout();let a=!1,l=!1,c;for(const R of s){const G=R.position==="left"?t.x-R.offset:t.x+t.width+R.offset,k=65,F=R.position==="left"?G-k:G;if(n>=F&&n<=F+k&&r>=t.y&&r<=t.y+t.height){c=R.id,l=!0,a=!1;break}}if(!c)if(r>t.y+t.height&&n>=t.x&&n<=t.x+t.width)a=!0;else if(n>=t.x&&n<=t.x+t.width&&r>=t.y&&r<=t.y+t.height)a=!0,l=!0;else return;const h=this.getBounds(c),u=e.deltaY>0?1.1:.9,d=(n-t.x)/t.width,f=1-(r-t.y)/t.height,g=h.xMin+d*(h.xMax-h.xMin),m=h.yMin+f*(h.yMax-h.yMin),y=1e-12,b=1e15;let v=a?g-(g-h.xMin)*u:h.xMin,S=a?g+(h.xMax-g)*u:h.xMax,T=l?m-(m-h.yMin)*u:h.yMin,P=l?m+(h.yMax-m)*u:h.yMax;const M=S-v,_=P-T;(M<y||M>b)&&(v=h.xMin,S=h.xMax),(_<y||_>b)&&(T=h.yMin,P=h.yMax);const B={xMin:v,xMax:S,yMin:T,yMax:P};this.callbacks.onZoom(B,c)}handleMouseDown(e){const t=this.getPlotArea();if(t.width<=1||t.height<=1)return;const i=this.container.getBoundingClientRect(),n=e.clientX-i.left,r=e.clientY-i.top,s=this.getAxesLayout();for(const a of s){const l=a.position==="left"?t.x-a.offset:t.x+t.width+a.offset,c=65,h=a.position==="left"?l-c:l;if(n>=h&&n<=h+c&&r>=t.y&&r<=t.y+t.height){this.isDragging=!0,this.panningAxisId=a.id,this.lastMousePos={x:e.clientX,y:e.clientY},this.container.style.cursor="ns-resize";return}}n>=t.x&&n<=t.x+t.width&&r>=t.y&&r<=t.y+t.height&&(this.isPanMode?(this.isDragging=!0,this.panningAxisId=void 0,this.lastMousePos={x:e.clientX,y:e.clientY},this.container.style.cursor="grabbing"):(this.isBoxSelecting=!0,this.selectionStart={x:n,y:r},this.container.style.cursor="crosshair"))}handleMouseMove(e){const t=this.container.getBoundingClientRect(),i=e.clientX-t.left,n=e.clientY-t.top;if(this.callbacks.onCursorMove(i,n),this.isDragging){const r=e.clientX-this.lastMousePos.x,s=e.clientY-this.lastMousePos.y;this.callbacks.onPan(r,s,this.panningAxisId),this.lastMousePos={x:e.clientX,y:e.clientY}}else if(this.isBoxSelecting){const r=Math.min(this.selectionStart.x,i),s=Math.min(this.selectionStart.y,n),a=Math.abs(i-this.selectionStart.x),l=Math.abs(n-this.selectionStart.y);this.callbacks.onBoxZoom({x:r,y:s,width:a,height:l})}}handleMouseUp(){this.isBoxSelecting&&this.callbacks.onBoxZoom(null),this.isDragging=!1,this.panningAxisId=void 0,this.isBoxSelecting=!1,this.container.style.cursor=""}handleMouseLeave(){this.isDragging=!1,this.panningAxisId=void 0,this.container.style.cursor="",this.callbacks.onCursorLeave()}handleTouchStart(e){if(e.touches.length===1){const t=e.touches[0];this.isDragging=!0,this.panningAxisId=void 0,this.lastMousePos={x:t.clientX,y:t.clientY}}}handleTouchMove(e){if(!this.isDragging||e.touches.length!==1)return;e.preventDefault();const t=e.touches[0],i=t.clientX-this.lastMousePos.x,n=t.clientY-this.lastMousePos.y;this.callbacks.onPan(i,n,this.panningAxisId),this.lastMousePos={x:t.clientX,y:t.clientY}}handleTouchEnd(){this.isDragging=!1,this.panningAxisId=void 0}destroy(){this.detachListeners()}}class pi{constructor(e,t,i){p(this,"container");p(this,"content");p(this,"theme");p(this,"series");p(this,"isExpanded",!1);this.theme=t,this.series=i,this.container=document.createElement("div"),this.container.className="scichart-stats-panel",this.updateContainerStyle();const n=document.createElement("div");n.innerHTML="📊 Statistics",n.style.cssText=`
|
|
138
138
|
font-weight: 600;
|
|
139
139
|
font-size: 11px;
|
|
140
140
|
text-transform: uppercase;
|
|
@@ -144,7 +144,7 @@ void main() {
|
|
|
144
144
|
justify-content: space-between;
|
|
145
145
|
align-items: center;
|
|
146
146
|
cursor: pointer;
|
|
147
|
-
`,n.onclick=()=>this.toggle(),this.content=document.createElement("div"),this.content.style.display="none",this.container.appendChild(n),this.container.appendChild(this.content),e.appendChild(this.container)}isDarkTheme(){const e=this.theme.name.toLowerCase();return e.includes("dark")||e.includes("midnight")||e.includes("electro")}updateContainerStyle(){const e=this.isDarkTheme(),t=e?"rgba(15, 23, 42, 0.85)":"rgba(255, 255, 255, 0.95)",i=e?"#f1f5f9":"#1e293b",n=e?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",
|
|
147
|
+
`,n.onclick=()=>this.toggle(),this.content=document.createElement("div"),this.content.style.display="none",this.container.appendChild(n),this.container.appendChild(this.content),e.appendChild(this.container)}isDarkTheme(){const e=this.theme.name.toLowerCase();return e.includes("dark")||e.includes("midnight")||e.includes("electro")}updateContainerStyle(){const e=this.isDarkTheme(),t=e?"rgba(15, 23, 42, 0.85)":"rgba(255, 255, 255, 0.95)",i=e?"#f1f5f9":"#1e293b",n=e?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.1)",r=e?"0 4px 12px rgba(0, 0, 0, 0.5)":"0 4px 12px rgba(0, 0, 0, 0.1)";this.container.style.cssText=`
|
|
148
148
|
position: absolute;
|
|
149
149
|
bottom: 8px;
|
|
150
150
|
right: 8px;
|
|
@@ -154,7 +154,7 @@ void main() {
|
|
|
154
154
|
-webkit-backdrop-filter: blur(8px);
|
|
155
155
|
border: 1px solid ${n};
|
|
156
156
|
border-radius: 8px;
|
|
157
|
-
box-shadow: ${
|
|
157
|
+
box-shadow: ${r};
|
|
158
158
|
color: ${i};
|
|
159
159
|
font-family: system-ui, -apple-system, sans-serif;
|
|
160
160
|
padding: 8px 12px;
|
|
@@ -162,7 +162,7 @@ void main() {
|
|
|
162
162
|
transition: all 0.3s ease;
|
|
163
163
|
font-size: 12px;
|
|
164
164
|
pointer-events: auto;
|
|
165
|
-
`}update(e){this.isExpanded&&(this.content.innerHTML="",this.series.forEach(t=>{if(!t.getVisible())return;const i=t.getData();if(!i)return;const n=[],
|
|
165
|
+
`}update(e){this.isExpanded&&(this.content.innerHTML="",this.series.forEach(t=>{if(!t.getVisible())return;const i=t.getData();if(!i)return;const n=[],r=[];for(let h=0;h<i.x.length;h++)i.x[h]>=e.xMin&&i.x[h]<=e.xMax&&(r.push(i.x[h]),n.push(i.y[h]));if(n.length===0)return;const s=Me(n),a=tt(r,n),l=t.getStyle(),c=document.createElement("div");c.style.cssText=`
|
|
166
166
|
padding: 8px 0;
|
|
167
167
|
border-top: 1px solid ${this.isDarkTheme()?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.05)"};
|
|
168
168
|
`,c.innerHTML=`
|
|
@@ -171,16 +171,16 @@ void main() {
|
|
|
171
171
|
${t.getId()}
|
|
172
172
|
</div>
|
|
173
173
|
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 4px; opacity: 0.9; font-size: 11px;">
|
|
174
|
-
<span>Min: ${
|
|
175
|
-
<span>Max: ${
|
|
176
|
-
<span>Mean: ${
|
|
177
|
-
<span>Count: ${
|
|
174
|
+
<span>Min: ${s.min.toExponential(3)}</span>
|
|
175
|
+
<span>Max: ${s.max.toExponential(3)}</span>
|
|
176
|
+
<span>Mean: ${s.mean.toExponential(3)}</span>
|
|
177
|
+
<span>Count: ${s.count}</span>
|
|
178
178
|
<span style="grid-column: span 2;">Area: ${a.toExponential(4)}</span>
|
|
179
179
|
</div>
|
|
180
|
-
`,this.content.appendChild(c)}),this.content.innerHTML===""&&(this.content.innerHTML="<div style='opacity: 0.5; font-style: italic;'>No series visible in range</div>"))}toggle(){this.isExpanded=!this.isExpanded,this.content.style.display=this.isExpanded?"block":"none",this.isExpanded}updateTheme(e){this.theme=e,this.updateContainerStyle()}destroy(){this.container.remove()}}const I={line:{color:"rgba(255, 255, 255, 0.7)",lineWidth:1,lineDash:[]},rectangle:{fillColor:"rgba(100, 100, 255, 0.2)",strokeWidth:1},text:{fontSize:12,fontFamily:"Inter, system-ui, sans-serif",color:"#ffffff",padding:4},arrow:{color:"rgba(255, 255, 255, 0.7)",lineWidth:2,headSize:10}};class ht{constructor(){p(this,"annotations",new Map);p(this,"idCounter",0)}add(e){const t=e.id??`annotation-${++this.idCounter}`,i={...e,id:t,visible:e.visible??!0,interactive:e.interactive??!1,zIndex:e.zIndex??0};return this.annotations.set(t,i),t}remove(e){return this.annotations.delete(e)}update(e,t){const i=this.annotations.get(e);i&&this.annotations.set(e,{...i,...t})}get(e){return this.annotations.get(e)}getAll(){return Array.from(this.annotations.values())}clear(){this.annotations.clear()}get count(){return this.annotations.size}render(e,t,i){const n=this.getAll().filter(s=>s.visible!==!1).sort((s,r)=>(s.zIndex??0)-(r.zIndex??0));e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip();for(const s of n)this.renderAnnotation(e,s,t,i);e.restore()}renderAnnotation(e,t,i,n){switch(t.type){case"horizontal-line":this.renderHorizontalLine(e,t,i,n);break;case"vertical-line":this.renderVerticalLine(e,t,i,n);break;case"rectangle":this.renderRectangle(e,t,i,n);break;case"band":this.renderBand(e,t,i,n);break;case"text":this.renderText(e,t,i,n);break;case"arrow":this.renderArrow(e,t,i,n);break}}dataToPixelX(e,t,i){const n=(e-t.xMin)/(t.xMax-t.xMin);return i.x+n*i.width}dataToPixelY(e,t,i){const n=(e-t.yMin)/(t.yMax-t.yMin);return i.y+i.height*(1-n)}renderHorizontalLine(e,t,i,n){const s=this.dataToPixelY(t.y,n,i);if(s<i.y||s>i.y+i.height)return;const r=t.xMin!==void 0?Math.max(this.dataToPixelX(t.xMin,n,i),i.x):i.x,a=t.xMax!==void 0?Math.min(this.dataToPixelX(t.xMax,n,i),i.x+i.width):i.x+i.width;e.save(),e.strokeStyle=t.color??I.line.color,e.lineWidth=t.lineWidth??I.line.lineWidth,e.setLineDash(t.lineDash??I.line.lineDash),e.beginPath(),e.moveTo(r,s),e.lineTo(a,s),e.stroke(),t.label&&this.renderLineLabel(e,t.label,r,a,s,t.labelPosition??"right","horizontal",t.labelBackground),e.restore()}renderVerticalLine(e,t,i,n){const s=this.dataToPixelX(t.x,n,i);if(s<i.x||s>i.x+i.width)return;const r=t.yMin!==void 0?Math.min(this.dataToPixelY(t.yMin,n,i),i.y+i.height):i.y,a=t.yMax!==void 0?Math.max(this.dataToPixelY(t.yMax,n,i),i.y):i.y+i.height;e.save(),e.strokeStyle=t.color??I.line.color,e.lineWidth=t.lineWidth??I.line.lineWidth,e.setLineDash(t.lineDash??I.line.lineDash),e.beginPath(),e.moveTo(s,r),e.lineTo(s,a),e.stroke(),t.label&&this.renderLineLabel(e,t.label,r,a,s,t.labelPosition??"top","vertical",t.labelBackground),e.restore()}renderRectangle(e,t,i,n){const s=this.dataToPixelX(t.xMin,n,i),r=this.dataToPixelX(t.xMax,n,i),a=this.dataToPixelY(t.yMax,n,i),l=this.dataToPixelY(t.yMin,n,i),c=Math.min(s,r),h=Math.min(a,l),u=Math.abs(r-s),d=Math.abs(l-a);e.save(),t.fillColor&&(e.fillStyle=t.fillColor,e.fillRect(c,h,u,d)),t.strokeColor&&(e.strokeStyle=t.strokeColor,e.lineWidth=t.strokeWidth??I.rectangle.strokeWidth,e.setLineDash(t.strokeDash??[]),e.strokeRect(c,h,u,d)),t.label&&this.renderCenteredLabel(e,t.label,c+u/2,h+d/2),e.restore()}renderBand(e,t,i,n){let s,r,a,l;if(t.xMin!==void 0&&t.xMax!==void 0){const c=this.dataToPixelX(t.xMin,n,i),h=this.dataToPixelX(t.xMax,n,i);s=Math.min(c,h),a=Math.abs(h-c),r=i.y,l=i.height,t.yMin!==void 0&&(l=this.dataToPixelY(t.yMin,n,i)-r),t.yMax!==void 0&&(r=this.dataToPixelY(t.yMax,n,i),l=i.y+i.height-r)}else if(t.yMin!==void 0&&t.yMax!==void 0){const c=this.dataToPixelY(t.yMax,n,i),h=this.dataToPixelY(t.yMin,n,i);r=Math.min(c,h),l=Math.abs(h-c),s=i.x,a=i.width}else return;if(e.save(),e.fillStyle=t.fillColor??I.rectangle.fillColor,e.fillRect(s,r,a,l),t.strokeColor&&(e.strokeStyle=t.strokeColor,e.lineWidth=t.strokeWidth??1,e.strokeRect(s,r,a,l)),t.label){let c=s+a/2,h=r+l/2;switch(t.labelPosition){case"top":h=r+15;break;case"bottom":h=r+l-5;break;case"left":c=s+10;break;case"right":c=s+a-10;break}this.renderCenteredLabel(e,t.label,c,h)}e.restore()}renderText(e,t,i,n){const s=this.dataToPixelX(t.x,n,i),r=this.dataToPixelY(t.y,n,i);e.save(),t.rotation&&(e.translate(s,r),e.rotate(t.rotation*Math.PI/180),e.translate(-s,-r));const a=t.fontSize??I.text.fontSize,l=t.fontFamily??I.text.fontFamily,c=t.fontWeight??"normal";e.font=`${c} ${a}px ${l}`,e.textAlign="center",e.textBaseline="middle";const h=e.measureText(t.text),u=t.padding??I.text.padding,d=h.width+u*2,f=a+u*2;let g=s,m=r;switch(t.anchor){case"top-left":g+=d/2,m+=f/2;break;case"top-right":g-=d/2,m+=f/2;break;case"bottom-left":g+=d/2,m-=f/2;break;case"bottom-right":g-=d/2,m-=f/2;break;case"top-center":m+=f/2;break;case"bottom-center":m-=f/2;break;case"left-center":g+=d/2;break;case"right-center":g-=d/2;break}t.backgroundColor&&(e.fillStyle=t.backgroundColor,e.beginPath(),e.roundRect(g-d/2,m-f/2,d,f,4),e.fill()),e.fillStyle=t.color??I.text.color,e.fillText(t.text,g,m),e.restore()}renderArrow(e,t,i,n){const s=this.dataToPixelX(t.x1,n,i),r=this.dataToPixelY(t.y1,n,i),a=this.dataToPixelX(t.x2,n,i),l=this.dataToPixelY(t.y2,n,i);e.save(),e.strokeStyle=t.color??I.arrow.color,e.fillStyle=t.color??I.arrow.color,e.lineWidth=t.lineWidth??I.arrow.lineWidth,e.beginPath(),e.moveTo(s,r),e.lineTo(a,l),e.stroke();const c=t.headSize??I.arrow.headSize,h=Math.atan2(l-r,a-s),u=t.headStyle??"filled";if(u!=="none"&&(e.beginPath(),e.moveTo(a,l),e.lineTo(a-c*Math.cos(h-Math.PI/6),l-c*Math.sin(h-Math.PI/6)),u==="filled"?(e.lineTo(a-c*Math.cos(h+Math.PI/6),l-c*Math.sin(h+Math.PI/6)),e.closePath(),e.fill()):(e.moveTo(a,l),e.lineTo(a-c*Math.cos(h+Math.PI/6),l-c*Math.sin(h+Math.PI/6)),e.stroke())),t.showTail){const d=h+Math.PI;e.beginPath(),e.moveTo(s,r),e.lineTo(s-c*Math.cos(d-Math.PI/6),r-c*Math.sin(d-Math.PI/6)),e.lineTo(s-c*Math.cos(d+Math.PI/6),r-c*Math.sin(d+Math.PI/6)),e.closePath(),e.fill()}if(t.label){const d=(s+a)/2,f=(r+l)/2;this.renderCenteredLabel(e,t.label,d,f-10)}e.restore()}renderLineLabel(e,t,i,n,s,r,a,l){e.save(),e.font=`${I.text.fontSize}px ${I.text.fontFamily}`;const c=e.measureText(t),h=4,u=c.width+h*2,d=I.text.fontSize+h*2;let f,g;if(a==="horizontal"){switch(g=s,r){case"left":f=i+5,e.textAlign="left";break;case"right":f=n-5,e.textAlign="right";break;default:f=(i+n)/2,e.textAlign="center"}e.textBaseline="bottom",g-=4}else{switch(f=s,r){case"top":g=i+d;break;case"bottom":g=n-5;break;default:g=(i+n)/2}e.textAlign="center",e.textBaseline="middle"}if(l??!0){e.fillStyle=l??"rgba(0, 0, 0, 0.7)";const m=e.textAlign==="left"?f-h:e.textAlign==="right"?f-u+h:f-u/2;e.fillRect(m,g-d+h,u,d)}e.fillStyle=I.text.color,e.fillText(t,f,g),e.restore()}renderCenteredLabel(e,t,i,n){e.save(),e.font=`${I.text.fontSize}px ${I.text.fontFamily}`;const s=e.measureText(t),r=4,a=s.width+r*2,l=I.text.fontSize+r*2;e.fillStyle="rgba(0, 0, 0, 0.7)",e.beginPath(),e.roundRect(i-a/2,n-l/2,a,l,3),e.fill(),e.fillStyle=I.text.color,e.textAlign="center",e.textBaseline="middle",e.fillText(t,i,n),e.restore()}}const Ae={top:10,right:12,bottom:10,left:12},pe={backgroundColor:"rgba(15, 18, 25, 0.95)",backgroundGradient:"rgba(25, 30, 40, 0.90)",borderColor:"rgba(255, 255, 255, 0.12)",borderWidth:1,borderRadius:8,backdropBlur:12,shadow:{color:"rgba(0, 0, 0, 0.4)",offsetX:0,offsetY:4,blur:16},fontFamily:"Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",textColor:"#ffffff",textSecondaryColor:"rgba(255, 255, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(255, 255, 255, 0.1)",showArrow:!0,arrowSize:6},ut={backgroundColor:"rgba(255, 255, 255, 0.98)",borderColor:"rgba(0, 0, 0, 0.12)",borderWidth:1,borderRadius:8,backdropBlur:8,shadow:{color:"rgba(0, 0, 0, 0.12)",offsetX:0,offsetY:4,blur:12},fontFamily:"Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",textColor:"#1a1a1a",textSecondaryColor:"rgba(0, 0, 0, 0.55)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(0, 0, 0, 0.08)",showArrow:!0,arrowSize:6},gi={backgroundColor:"rgba(255, 255, 255, 0.08)",backgroundGradient:"rgba(255, 255, 255, 0.04)",borderColor:"rgba(255, 255, 255, 0.2)",borderWidth:1,borderRadius:12,backdropBlur:20,shadow:{color:"rgba(0, 0, 0, 0.3)",offsetX:0,offsetY:8,blur:32},fontFamily:"Inter, system-ui, sans-serif",textColor:"rgba(255, 255, 255, 0.95)",textSecondaryColor:"rgba(255, 255, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.5,padding:{top:12,right:14,bottom:12,left:14},itemGap:5,headerGap:10,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(255, 255, 255, 0.15)",showArrow:!0,arrowSize:7},dt={backgroundColor:"rgba(10, 15, 30, 0.95)",backgroundGradient:"rgba(20, 25, 50, 0.90)",borderColor:"rgba(100, 120, 255, 0.25)",borderWidth:1,borderRadius:8,backdropBlur:15,shadow:{color:"rgba(50, 70, 150, 0.25)",offsetX:0,offsetY:4,blur:20},fontFamily:"Inter, system-ui, sans-serif",textColor:"#e0e8ff",textSecondaryColor:"rgba(180, 190, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(100, 120, 255, 0.15)",showArrow:!0,arrowSize:6},ft={backgroundColor:"rgba(8, 20, 40, 0.96)",backgroundGradient:"rgba(15, 35, 60, 0.92)",borderColor:"rgba(30, 136, 229, 0.35)",borderWidth:1,borderRadius:6,backdropBlur:10,shadow:{color:"rgba(30, 136, 229, 0.2)",offsetX:0,offsetY:4,blur:16},fontFamily:'"JetBrains Mono", "Fira Code", monospace',textColor:"#bbdefb",textSecondaryColor:"rgba(144, 202, 249, 0.7)",titleFontSize:11,titleFontWeight:600,contentFontSize:11,lineHeight:1.5,padding:{top:8,right:10,bottom:8,left:10},itemGap:3,headerGap:6,showSeriesIndicator:!0,seriesIndicatorSize:6,showHeaderSeparator:!0,separatorColor:"rgba(30, 136, 229, 0.2)",showArrow:!0,arrowSize:5},pt={dark:pe,light:ut,glass:gi,midnight:dt,electrochemistry:ft,neon:{backgroundColor:"rgba(0, 0, 0, 0.92)",borderColor:"#00ffff",borderWidth:1,borderRadius:4,backdropBlur:0,shadow:{color:"rgba(0, 255, 255, 0.35)",offsetX:0,offsetY:0,blur:20},fontFamily:'"Orbitron", "Exo 2", sans-serif',textColor:"#00ffff",textSecondaryColor:"rgba(0, 255, 255, 0.6)",titleFontSize:11,titleFontWeight:700,contentFontSize:10,lineHeight:1.4,padding:{top:8,right:12,bottom:8,left:12},itemGap:4,headerGap:6,showSeriesIndicator:!0,seriesIndicatorSize:6,showHeaderSeparator:!0,separatorColor:"rgba(0, 255, 255, 0.3)",showArrow:!1,arrowSize:0},minimal:{backgroundColor:"rgba(30, 35, 45, 0.9)",borderColor:"transparent",borderWidth:0,borderRadius:4,backdropBlur:8,shadow:{color:"rgba(0, 0, 0, 0.3)",offsetX:0,offsetY:2,blur:8},fontFamily:"Inter, system-ui, sans-serif",textColor:"#ffffff",textSecondaryColor:"rgba(255, 255, 255, 0.7)",titleFontSize:10,titleFontWeight:500,contentFontSize:10,lineHeight:1.3,padding:{top:6,right:8,bottom:6,left:8},itemGap:2,headerGap:4,showSeriesIndicator:!1,seriesIndicatorSize:0,showHeaderSeparator:!1,separatorColor:"transparent",showArrow:!1,arrowSize:0}};function mi(o){const e=pt[o];return e||(console.warn(`[Tooltip] Unknown theme "${o}", using dark`),pe)}function yi(o,e){const t=typeof o=="string"?mi(o):o;return{...t,...e,padding:{...t.padding,...e.padding},shadow:{...t.shadow,...e.shadow}}}function te(o){switch(o.toLowerCase()){case"light":return ut;case"midnight":return dt;case"electrochemistry":case"electrochem":return ft;case"dark":default:return pe}}const bi=pe,xi={offset:{x:12,y:12},preferredPosition:"auto",constrainToPlotArea:!0,constrainToContainer:!0,autoFlip:!0,showArrow:!0,arrowSize:6};class vi{constructor(e={}){p(this,"config");p(this,"containerWidth",0);p(this,"containerHeight",0);p(this,"plotArea",null);this.config={...xi,...e}}setContainerSize(e,t){this.containerWidth=e,this.containerHeight=t}setPlotArea(e){this.plotArea=e}configure(e){this.config={...this.config,...e}}calculatePosition(e,t,i){const{offset:n,preferredPosition:s,autoFlip:r,showArrow:a,arrowSize:l}=this.config,c=i.width+i.padding.left+i.padding.right,h=i.height+i.padding.top+i.padding.bottom;let u=this.determinePosition(e,t,c,h,s),{x:d,y:f,arrowPosition:g}=this.calculateCoordinates(e,t,c,h,u,n,a?l:0),m=!1;if(r&&!this.fitsInBounds(d,f,c,h)){const v=this.flipPosition(u),S=this.calculateCoordinates(e,t,c,h,v,n,a?l:0);this.fitsInBounds(S.x,S.y,c,h)&&(d=S.x,f=S.y,g=S.arrowPosition,m=!0)}const y=this.constrainToBounds(d,f,c,h);let b=0;if(a){if(g==="top"||g==="bottom"){const v=e-y.x;b=Math.max(l+4,Math.min(c-l-4,v))}else if(g==="left"||g==="right"){const v=t-y.y;b=Math.max(l+4,Math.min(h-l-4,v))}}return{x:y.x,y:y.y,arrowPosition:a?g:"none",arrowOffset:b,wasFlipped:m}}determinePosition(e,t,i,n,s){if(s!=="auto")return s;const r=this.getConstraintBounds(),a=t-r.top,l=r.bottom-t,c=e-r.left,h=r.right-e,u=a>=n+this.config.offset.y,d=l>=n+this.config.offset.y,f=h>=i+this.config.offset.x,g=c>=i+this.config.offset.x;return u&&a>=l?"top":d?"bottom":f&&h>=c?"right":g?"left":[{pos:"top",space:a},{pos:"bottom",space:l},{pos:"right",space:h},{pos:"left",space:c}].sort((y,b)=>b.space-y.space)[0].pos}calculateCoordinates(e,t,i,n,s,r,a){let l,c,h;switch(s){case"top":l=e-i/2,c=t-n-r.y-a,h="bottom";break;case"bottom":l=e-i/2,c=t+r.y+a,h="top";break;case"right":l=e+r.x+a,c=t-n/2,h="left";break;case"left":l=e-i-r.x-a,c=t-n/2,h="right";break}return{x:l,y:c,arrowPosition:h}}flipPosition(e){switch(e){case"top":return"bottom";case"bottom":return"top";case"left":return"right";case"right":return"left"}}fitsInBounds(e,t,i,n){const s=this.getConstraintBounds();return e>=s.left&&t>=s.top&&e+i<=s.right&&t+n<=s.bottom}constrainToBounds(e,t,i,n){const s=this.getConstraintBounds(),r=4;let a=e,l=t;return a<s.left+r?a=s.left+r:a+i>s.right-r&&(a=s.right-i-r),l<s.top+r?l=s.top+r:l+n>s.bottom-r&&(l=s.bottom-n-r),{x:a,y:l}}getConstraintBounds(){let e={top:0,left:0,right:this.containerWidth,bottom:this.containerHeight};return this.config.constrainToPlotArea&&this.plotArea&&(e={top:Math.max(e.top,this.plotArea.y),left:Math.max(e.left,this.plotArea.x),right:Math.min(e.right,this.plotArea.x+this.plotArea.width),bottom:Math.min(e.bottom,this.plotArea.y+this.plotArea.height)}),e}calculateCrosshairPosition(e,t,i){const{offset:n}=this.config,s=this.getConstraintBounds(),r=i.width+i.padding.left+i.padding.right,a=i.height+i.padding.top+i.padding.bottom;let l=e+n.x,c="left";l+r>s.right-4&&(l=e-r-n.x,c="right");let h=t-a/2;h=Math.max(s.top+4,Math.min(s.bottom-a-4,h));const u=t-h;return{x:l,y:h,arrowPosition:c,arrowOffset:Math.max(8,Math.min(a-8,u)),wasFlipped:c==="right"}}}class Si{constructor(e,t){p(this,"ctx");p(this,"theme");this.ctx=e,this.theme=t}setTheme(e){this.theme=e}render(e,t,i){const n=i.measure(this.ctx,e,this.theme),s=n.width+n.padding.left+n.padding.right,r=n.height+n.padding.top+n.padding.bottom;this.ctx.save(),this.drawBackground(t.x,t.y,s,r,t.arrowPosition||"none"),t.arrowPosition&&t.arrowPosition!=="none"&&this.drawArrow(t.x,t.y,s,r,t.arrowPosition,t.arrowOffset||0),i.render(this.ctx,e,t,this.theme),this.ctx.restore()}drawBackground(e,t,i,n,s){const{ctx:r,theme:a}=this,l=a.borderRadius;if(r.save(),a.shadow.blur>0&&(r.shadowColor=a.shadow.color,r.shadowOffsetX=a.shadow.offsetX,r.shadowOffsetY=a.shadow.offsetY,r.shadowBlur=a.shadow.blur),r.beginPath(),this.roundRect(e,t,i,n,l),a.backgroundGradient){const c=r.createLinearGradient(e,t,e,t+n);c.addColorStop(0,a.backgroundColor),c.addColorStop(1,a.backgroundGradient),r.fillStyle=c}else r.fillStyle=a.backgroundColor;r.fill(),r.shadowColor="transparent",a.borderWidth>0&&(r.strokeStyle=a.borderColor,r.lineWidth=a.borderWidth,r.stroke()),r.restore()}drawArrow(e,t,i,n,s,r){const{ctx:a,theme:l}=this,c=l.arrowSize;if(!(c<=0||s==="none")){switch(a.save(),a.fillStyle=l.backgroundColor,a.strokeStyle=l.borderColor,a.lineWidth=l.borderWidth,a.beginPath(),s){case"top":const h=e+r;a.moveTo(h-c,t),a.lineTo(h,t-c),a.lineTo(h+c,t);break;case"bottom":const u=e+r,d=t+n;a.moveTo(u-c,d),a.lineTo(u,d+c),a.lineTo(u+c,d);break;case"left":const f=t+r;a.moveTo(e,f-c),a.lineTo(e-c,f),a.lineTo(e,f+c);break;case"right":const g=e+i,m=t+r;a.moveTo(g,m-c),a.lineTo(g+c,m),a.lineTo(g,m+c);break}a.closePath(),a.fill(),l.borderWidth>0&&a.stroke(),a.restore()}}roundRect(e,t,i,n,s){const{ctx:r}=this,a=Math.min(s,i/2,n/2);r.moveTo(e+a,t),r.lineTo(e+i-a,t),r.arcTo(e+i,t,e+i,t+a,a),r.lineTo(e+i,t+n-a),r.arcTo(e+i,t+n,e+i-a,t+n,a),r.lineTo(e+a,t+n),r.arcTo(e,t+n,e,t+n-a,a),r.lineTo(e,t+a),r.arcTo(e,t,e+a,t,a),r.closePath()}drawSeparator(e,t,i){const{ctx:n,theme:s}=this;s.showHeaderSeparator&&(n.save(),n.strokeStyle=s.separatorColor,n.lineWidth=1,n.beginPath(),n.moveTo(e,t),n.lineTo(e+i,t),n.stroke(),n.restore())}drawSeriesIndicator(e,t,i){const{ctx:n,theme:s}=this;if(!s.showSeriesIndicator)return;const a=s.seriesIndicatorSize/2;n.save(),n.fillStyle=i,n.beginPath(),n.arc(e+a,t,a,0,Math.PI*2),n.fill(),n.restore()}measureText(e,t,i=400){const{ctx:n,theme:s}=this;return n.font=`${i} ${t}px ${s.fontFamily}`,n.measureText(e).width}drawText(e,t,i,n={}){const{ctx:s,theme:r}=this,{fontSize:a=r.contentFontSize,fontWeight:l=400,color:c=r.textColor,align:h="left",baseline:u="top"}=n;s.save(),s.font=`${l} ${a}px ${r.fontFamily}`,s.fillStyle=c,s.textAlign=h,s.textBaseline=u,s.fillText(e,t,i),s.restore()}drawLabelValue(e,t,i,n,s){const{theme:r}=this;this.drawText(i,e,t,{color:r.textSecondaryColor,fontSize:r.contentFontSize}),this.drawText(n,e+s,t,{color:r.textColor,fontSize:r.contentFontSize,align:"right"})}getTheme(){return this.theme}}function N(o,e=4){const t=Math.abs(o);return t!==0&&(t<1e-4||t>=1e4)?o.toExponential(2):t<.01?o.toPrecision(e):t<1?o.toFixed(4):t<100?o.toFixed(3):o.toFixed(1)}class wi{constructor(){p(this,"id","default");p(this,"name","Default Data Point");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const s=e.measureText(t.seriesName).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const r=35,a=e.measureText(N(t.dataX)).width,l=e.measureText(N(t.dataY)).width;let c=r+Math.max(a,l),h=i.contentFontSize*i.lineHeight*2;if(t.yError){const g=`± ${N(t.yError[0])} / ${N(t.yError[1])}`;c=Math.max(c,e.measureText(g).width),h+=i.contentFontSize*i.lineHeight}if(t.cycle!==void 0){const g=`Cycle: ${t.cycle}`;c=Math.max(c,e.measureText(g).width),h+=i.contentFontSize*i.lineHeight}const u=i.showSeriesIndicator?i.seriesIndicatorSize+6:0,d=Math.max(s+u,c),f=i.titleFontSize*i.lineHeight+i.headerGap+h;return this.cachedMeasurement={width:d+2,height:f+4,padding:i.padding,arrow:i.showArrow?{width:i.arrowSize*2,height:i.arrowSize}:void 0},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n;let l=s+a.left,c=r+a.top;if(e.textAlign="left",e.textBaseline="top",n.showSeriesIndicator){const u=c+n.titleFontSize/2;e.save(),e.fillStyle=t.seriesColor,e.beginPath(),e.arc(l+n.seriesIndicatorSize/2,u,n.seriesIndicatorSize/2,0,Math.PI*2),e.fill(),e.restore(),l+=n.seriesIndicatorSize+6}if(e.save(),e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText(t.seriesName,l,c),e.restore(),c+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const d=this.measure(e,t,n).width;e.save(),e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(s+a.left,c+n.headerGap/2),e.lineTo(s+a.left+d,c+n.headerGap/2),e.stroke(),e.restore()}c+=n.headerGap+2,l=s+a.left,e.save(),e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`,e.fillStyle=n.textSecondaryColor,e.fillText("X:",l,c),e.fillStyle=n.textColor;const h=35;if(e.fillText(N(t.dataX),l+h,c),c+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",l,c),e.fillStyle=n.textColor,e.fillText(N(t.dataY),l+h,c),c+=n.contentFontSize*n.lineHeight+2,t.yError){e.fillStyle=n.textSecondaryColor;const u=`± ${N(t.yError[0])} / +${N(t.yError[1])}`;e.fillText(u,l,c),c+=n.contentFontSize*n.lineHeight}t.cycle!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("Cycle:",l,c),e.fillStyle=n.textColor,e.fillText(String(t.cycle),l+45,c)),e.restore()}}const ge=new wi;function me(o){const e=Math.abs(o);return e===0?"0":e>=1e9?(o/1e9).toFixed(1)+"G":e>=1e6?(o/1e6).toFixed(1)+"M":e>=1e3?(o/1e3).toFixed(1)+"k":e>=1?o.toFixed(2):e>=.001?(o*1e3).toFixed(1)+"m":e>=1e-6?(o*1e6).toFixed(1)+"µ":e>=1e-9?(o*1e9).toFixed(1)+"n":o.toExponential(1)}class Ti{constructor(){p(this,"id","minimal");p(this,"name","Minimal");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}-${i.fontFamily}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.contentFontSize}px ${i.fontFamily}`;const s=`${me(t.dataX)} ▪ ${me(t.dataY)}`,r=e.measureText(s).width;return this.cachedMeasurement={width:r,height:i.contentFontSize*i.lineHeight,padding:{top:6,right:8,bottom:6,left:8}},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const s=i.x+8,r=i.y+6,a=me(t.dataX),l=me(t.dataY);e.save(),e.font=`${n.contentFontSize}px ${n.fontFamily}`,e.textAlign="left",e.textBaseline="top",e.fillStyle=n.textSecondaryColor,e.fillText(a,s,r);const c=e.measureText(a).width;e.fillStyle=t.seriesColor,e.fillText(" ▪ ",s+c,r);const h=e.measureText(" ▪ ").width;e.fillStyle=n.textColor,e.fillText(l,s+c+h,r),e.restore()}}const gt=new Ti;function ye(o){const e=Math.abs(o);return e===0?"0":e!==0&&(e<1e-4||e>=1e4)?o.toExponential(2):e<.01?o.toPrecision(3):e<1?o.toFixed(4):e<100?o.toFixed(3):o.toFixed(1)}class Mi{constructor(){p(this,"id","crosshair");p(this,"name","Multi-Series Crosshair");p(this,"supportedTypes",["crosshair"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.dataX}-${t.interpolatedValues.length}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const s=`⌖ X = ${ye(t.dataX)}`;let r=e.measureText(s).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const a=i.showSeriesIndicator?i.seriesIndicatorSize+8:0,l=60;for(const d of t.interpolatedValues){const f=e.measureText(`${d.seriesName}:`).width,g=e.measureText(ye(d.y)).width,m=a+Math.max(f,l)+g;r=Math.max(r,m)}const c=i.titleFontSize*i.lineHeight,u=t.interpolatedValues.length*(i.contentFontSize*i.lineHeight+2);return this.cachedMeasurement={width:r+4,height:c+i.headerGap+u,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n;let l=r+a.top;const c=s+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=`⌖ X = ${ye(t.dataX)}`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const u=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+u.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;for(const u of t.interpolatedValues){let d=c;if(n.showSeriesIndicator){const m=l+n.contentFontSize/2;e.save(),e.beginPath(),e.arc(d+n.seriesIndicatorSize/2,m,n.seriesIndicatorSize/2,0,Math.PI*2),u.isInterpolated?(e.strokeStyle=u.seriesColor,e.lineWidth=1.5,e.stroke()):(e.fillStyle=u.seriesColor,e.fill()),e.restore(),d+=n.seriesIndicatorSize+8}e.fillStyle=n.textSecondaryColor,e.fillText(`${u.seriesName}:`,d,l);const f=e.measureText(`${u.seriesName}: `).width,g=Math.max(f,60);e.fillStyle=n.textColor,e.fillText(ye(u.y),d+g,l),l+=n.contentFontSize*n.lineHeight+2}e.restore()}}const _e=new Mi;function Y(o){const e=Math.abs(o);return e===0?"0":e!==0&&(e<1e-4||e>=1e4)?o.toExponential(3):e<.01?o.toPrecision(4):e<1?o.toFixed(4):e<100?o.toFixed(3):o.toFixed(2)}class Pi{constructor(){p(this,"id","heatmap");p(this,"name","Heatmap Value");p(this,"supportedTypes",["heatmap"]);p(this,"swatchSize",14);p(this,"swatchGap",8);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.xIndex}-${t.yIndex}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const s=`Grid [${t.xIndex}, ${t.yIndex}]`;let r=e.measureText(s).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const a=`Value: ${Y(t.zValue)}`,l=this.swatchSize+this.swatchGap+e.measureText(a).width;if(r=Math.max(r,l),t.colorScale){const m=`Min: ${Y(t.colorScale.min)} Max: ${Y(t.colorScale.max)}`;r=Math.max(r,this.swatchSize+this.swatchGap+e.measureText(m).width)}const c=25,h=c+e.measureText(Y(t.dataX)).width,u=c+e.measureText(Y(t.dataY)).width;r=Math.max(r,h,u);const d=i.titleFontSize*i.lineHeight,g=(t.colorScale?4:3)*i.contentFontSize*i.lineHeight;return this.cachedMeasurement={width:r+4,height:d+i.headerGap+g+i.itemGap,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n;let l=r+a.top;const c=s+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=`Grid [${t.xIndex}, ${t.yIndex}]`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const f=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+f.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=l+(n.contentFontSize*n.lineHeight-this.swatchSize)/2;e.fillStyle=t.mappedColor||n.textColor,e.fillRect(c,u,this.swatchSize,this.swatchSize),e.strokeStyle=n.separatorColor,e.lineWidth=1,e.strokeRect(c,u,this.swatchSize,this.swatchSize),e.fillStyle=n.textSecondaryColor,e.fillText("Value:",c+this.swatchSize+this.swatchGap,l),e.fillStyle=n.textColor;const d=e.measureText("Value: ").width;if(e.fillText(Y(t.zValue),c+this.swatchSize+this.swatchGap+d,l),l+=n.contentFontSize*n.lineHeight,t.colorScale){e.fillStyle=n.textSecondaryColor,e.font=`400 ${n.contentFontSize-1}px ${n.fontFamily}`;const f=`Min: ${Y(t.colorScale.min)} Max: ${Y(t.colorScale.max)}`;e.fillText(f,c+this.swatchSize+this.swatchGap,l),l+=n.contentFontSize*n.lineHeight}l+=n.itemGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`,e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(Y(t.dataX),c+25,l),l+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor,e.fillText(Y(t.dataY),c+25,l),e.restore()}}const Fe=new Pi;function K(o,e=3){if(o===0)return"0";const t=Math.floor(Math.log10(Math.abs(o))),i=o/Math.pow(10,t);if(Math.abs(t)<=2)return o.toPrecision(e);const n={0:"⁰",1:"¹",2:"²",3:"³",4:"⁴",5:"⁵",6:"⁶",7:"⁷",8:"⁸",9:"⁹","-":"⁻","+":"⁺"},s=t.toString();let r="";for(const a of s)r+=n[a]||a;return`${i.toFixed(e-1)} × 10${r}`}class Ci{constructor(){p(this,"id","scientific");p(this,"name","Scientific Notation");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const s=e.measureText(t.seriesName).width+(i.showSeriesIndicator?i.seriesIndicatorSize+8:0);e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const r=28,a=K(t.dataX);let l=Math.max(s,r+e.measureText(a).width);const c=K(t.dataY);let h=r+e.measureText(c).width;t.yError&&(h+=e.measureText(` ± ${K(t.yError[0])}`).width),l=Math.max(l,h);let u=`Index: ${t.dataIndex}`;t.cycle!==void 0&&(u+=` │ Cycle: ${t.cycle}`),l=Math.max(l,e.measureText(u).width);let d=3;(t.cycle!==void 0||t.yError)&&(d+=1);const f=i.titleFontSize*i.lineHeight+i.headerGap,g=(d-1)*i.contentFontSize*i.lineHeight,m=t.cycle!==void 0?i.itemGap:0;return this.cachedMeasurement={width:l,height:f+g+m,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n;let l=r+a.top,c=s+a.left;if(e.save(),e.textAlign="left",e.textBaseline="top",n.showSeriesIndicator){const d=l+n.titleFontSize/2;e.fillStyle=t.seriesColor,e.beginPath(),e.arc(c+n.seriesIndicatorSize/2,d,n.seriesIndicatorSize/2,0,Math.PI*2),e.fill(),c+=n.seriesIndicatorSize+8}if(e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText(t.seriesName,c,l),l+=n.titleFontSize*n.lineHeight+2,c=s+a.left,n.showHeaderSeparator){const d=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+d.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const h=28;e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(K(t.dataX),c+h,l),l+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor;let u=K(t.dataY);if(e.fillText(u,c+h,l),t.yError){const d=e.measureText(u).width;e.fillStyle=n.textSecondaryColor,e.fillText(` ± ${K(t.yError[0])}`,c+h+d,l)}if(l+=n.contentFontSize*n.lineHeight+2,t.cycle!==void 0){l+=n.itemGap,e.strokeStyle=n.separatorColor,e.globalAlpha=.3,e.beginPath();const d=this.measure(e,t,n);e.moveTo(c,l-n.itemGap/2),e.lineTo(c+d.width,l-n.itemGap/2),e.stroke(),e.globalAlpha=1,e.fillStyle=n.textSecondaryColor,e.font=`400 ${n.contentFontSize-1}px ${n.fontFamily}`;let f=`Index: ${t.dataIndex}`;t.cycle!==void 0&&(f+=` │ Cycle: ${t.cycle}`),e.fillText(f,c,l)}e.restore()}}const mt=new Ci;function Z(o){const e=Math.abs(o);return e===0?"0":e<1e-4||e>=1e4?o.toExponential(2):e<1?o.toFixed(4):o.toFixed(2)}class ki{constructor(){p(this,"id","annotation");p(this,"name","Annotation Info");p(this,"supportedTypes",["annotation"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.annotationId}-${t.label}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const s=t.label||`Annotation: ${t.annotationType}`;let r=e.measureText(s).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;let a=0;const l=50;if(t.value!==void 0){const h=Z(t.value);r=Math.max(r,l+e.measureText(h).width),a+=i.contentFontSize*i.lineHeight}if(t.valueX!==void 0&&t.valueY!==void 0){const h=Z(t.valueX),u=Z(t.valueY);r=Math.max(r,l+e.measureText(h).width,l+e.measureText(u).width),a+=i.contentFontSize*i.lineHeight*2}const c=i.titleFontSize*i.lineHeight+i.headerGap;return this.cachedMeasurement={width:r+10,height:c+a+4,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n;let l=r+a.top;const c=s+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=t.label||`${t.annotationType.toUpperCase()}`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const d=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+d.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=50;t.value!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("Value:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.value),c+u,l),l+=n.contentFontSize*n.lineHeight),t.valueX!==void 0&&t.valueY!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.valueX),c+u,l),l+=n.contentFontSize*n.lineHeight,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.valueY),c+u,l)),e.restore()}}const Ie=new ki;function U(o){const e=Math.abs(o);return e===0?"0":e<1e-4||e>=1e4?o.toExponential(3):e<1?o.toFixed(4):o.toFixed(3)}class Ei{constructor(){p(this,"id","range");p(this,"name","Range Statistics");p(this,"supportedTypes",["range"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=t.statistics,s=`${t.xMin}-${t.xMax}-${n.count}-${n.mean}-${i.fontFamily}`;if(s===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;let a=e.measureText("Range Statistics").width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;let l=i.contentFontSize*i.lineHeight*2;const c=[`Range: ${U(t.xMin)} to ${U(t.xMax)}`,`Count: ${n.count}`];n.min!==void 0&&c.push(`Min: ${U(n.min)}`),n.max!==void 0&&c.push(`Max: ${U(n.max)}`),n.mean!==void 0&&c.push(`Mean: ${U(n.mean)}`),n.area!==void 0&&c.push(`Area: ${U(n.area)}`);for(const u of c)a=Math.max(a,e.measureText(u).width+10);l=c.length*i.contentFontSize*i.lineHeight;const h=i.titleFontSize*i.lineHeight+i.headerGap;return this.cachedMeasurement={width:Math.max(a,140),height:h+l+10,padding:i.padding},this.cachedKey=s,this.cachedMeasurement}render(e,t,i,n){const{x:s,y:r}=i,{padding:a}=n,l=t.statistics;let c=r+a.top;const h=s+a.left;if(e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText("Range Statistics",h,c),c+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const f=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.globalAlpha=.4,e.beginPath(),e.moveTo(h,c+n.headerGap/2),e.lineTo(h+f.width,c+n.headerGap/2),e.stroke(),e.globalAlpha=1}c+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=60,d=(f,g)=>{e.fillStyle=n.textSecondaryColor,e.fillText(f,h,c),e.fillStyle=n.textColor,e.fillText(String(g),h+u,c),c+=n.contentFontSize*n.lineHeight};d("Points:",l.count),l.min!==void 0&&d("Min:",U(l.min)),l.max!==void 0&&d("Max:",U(l.max)),l.mean!==void 0&&d("Mean:",U(l.mean)),l.stdDev!==void 0&&d("StdDev:",U(l.stdDev)),l.area!==void 0&&d("Area:",U(l.area)),l.peakX!==void 0&&(c+=4,e.fillStyle=n.textSecondaryColor,e.font=`italic ${n.contentFontSize-1}px ${n.fontFamily}`,e.fillText(`Peak: ${U(l.peakY??0)} at X=${U(l.peakX)}`,h,c)),e.restore()}}const Re=new Ei,Bi=[ge,gt,_e,Fe,mt,Ie,Re];function Ai(o){return Bi.find(e=>e.id===o)}function yt(o){switch(o){case"datapoint":return ge;case"crosshair":return _e;case"heatmap":return Fe;case"annotation":return Ie;case"range":return Re;default:return ge}}class bt{constructor(e){p(this,"ctx");p(this,"getPlotArea");p(this,"getSeries");p(this,"pixelToDataX");p(this,"pixelToDataY");p(this,"getXScale");p(this,"getYScales");p(this,"options");p(this,"theme");p(this,"positioner");p(this,"renderer");p(this,"templates",new Map);p(this,"events",new Pe);p(this,"activeTooltips",new Map);p(this,"tooltipIdCounter",0);p(this,"showTimeoutId",null);p(this,"hideTimeoutId",null);p(this,"lastCursorX",null);p(this,"lastCursorY",null);p(this,"hoveredSeriesId",null);p(this,"hoveredDataIndex",null);p(this,"cachedNearestResult",null);p(this,"snapMode","auto");p(this,"largeDatasetThreshold",5e4);p(this,"lastKnownDataSize",0);p(this,"hysteresisRatio",2);var t;this.ctx=e.overlayCtx,this.getPlotArea=e.getPlotArea,this.getSeries=e.getSeries,this.pixelToDataX=e.pixelToDataX,this.pixelToDataY=e.pixelToDataY,this.getXScale=e.getXScale,this.getYScales=e.getYScales,this.options={enabled:!0,showDelay:50,hideDelay:100,followCursor:!1,offset:{x:12,y:12},dataPoint:{enabled:!0,templateId:"default",snapToPoint:!0,hitRadius:20},crosshair:{enabled:!1,templateId:"crosshair",interpolate:!0,visibleSeriesOnly:!0},range:{enabled:!1,templateId:"default",calculateStats:!0},annotation:{enabled:!0,templateId:"default"},heatmap:{enabled:!0,templateId:"heatmap",showColorInfo:!0},positioning:"auto",preferredPosition:"auto",constrainToPlotArea:!0,constrainToContainer:!0,autoFlip:!0},e.options&&this.configure(e.options),this.theme=(t=e.options)!=null&&t.theme?typeof e.options.theme=="string"?te(e.options.theme):yi(bi,e.options.theme):te(e.chartTheme.name),this.positioner=new vi({offset:this.options.offset,preferredPosition:this.options.preferredPosition,constrainToPlotArea:this.options.constrainToPlotArea,constrainToContainer:this.options.constrainToContainer,autoFlip:this.options.autoFlip,showArrow:this.theme.showArrow,arrowSize:this.theme.arrowSize}),this.renderer=new Si(this.ctx,this.theme),this.registerBuiltinTemplates()}registerBuiltinTemplates(){this.templates.set("default",ge),this.templates.set("minimal",gt),this.templates.set("crosshair",_e),this.templates.set("heatmap",Fe),this.templates.set("scientific",mt),this.templates.set("annotation",Ie),this.templates.set("range",Re)}configure(e){e.enabled!==void 0&&(this.options.enabled=e.enabled),e.showDelay!==void 0&&(this.options.showDelay=e.showDelay),e.hideDelay!==void 0&&(this.options.hideDelay=e.hideDelay),e.followCursor!==void 0&&(this.options.followCursor=e.followCursor),e.offset&&(this.options.offset={...this.options.offset,...e.offset}),e.dataPoint&&(this.options.dataPoint={...this.options.dataPoint,...e.dataPoint}),e.crosshair&&(this.options.crosshair={...this.options.crosshair,...e.crosshair}),e.heatmap&&(this.options.heatmap={...this.options.heatmap,...e.heatmap}),e.preferredPosition&&(this.options.preferredPosition=e.preferredPosition),e.constrainToPlotArea!==void 0&&(this.options.constrainToPlotArea=e.constrainToPlotArea),e.constrainToContainer!==void 0&&(this.options.constrainToContainer=e.constrainToContainer),e.autoFlip!==void 0&&(this.options.autoFlip=e.autoFlip),e.snapMode!==void 0&&(this.snapMode=e.snapMode),e.largeDatasetThreshold!==void 0&&(this.largeDatasetThreshold=Math.max(1e3,e.largeDatasetThreshold)),this.positioner.configure({offset:this.options.offset,preferredPosition:this.options.preferredPosition,constrainToPlotArea:this.options.constrainToPlotArea,constrainToContainer:this.options.constrainToContainer,autoFlip:this.options.autoFlip})}getOptions(){return{...this.options}}setEnabled(e){this.options.enabled=e,e||this.hideAll()}isEnabled(){return this.options.enabled}setTheme(e){this.theme=typeof e=="string"?te(e):e,this.renderer.setTheme(this.theme),this.positioner.configure({showArrow:this.theme.showArrow,arrowSize:this.theme.arrowSize})}updateChartTheme(e){this.options.theme||(this.theme=te(e.name),this.renderer.setTheme(this.theme))}getTheme(){return this.theme}registerTemplate(e){this.templates.set(e.id,e)}getTemplate(e){return this.templates.get(e)||Ai(e)}handleCursorMove(e,t){if(!this.options.enabled)return;this.lastCursorX=e,this.lastCursorY=t;const i=this.getPlotArea();if(!(e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height)){this.cachedNearestResult=null,this.scheduleHide();return}this.positioner.setContainerSize(this.ctx.canvas.width/(window.devicePixelRatio||1),this.ctx.canvas.height/(window.devicePixelRatio||1)),this.positioner.setPlotArea(i),this.lastKnownDataSize=this.getTotalDataPoints(),this.performTooltipUpdateWithHysteresis(e,t)}handleCursorLeave(){this.lastCursorX=null,this.lastCursorY=null,this.cachedNearestResult=null,this.scheduleHide()}getTotalDataPoints(){let e=0;const t=this.getSeries();for(const i of t){if(!i.isVisible())continue;const n=i.getData();n.x&&(e+=n.x.length)}return e}getEffectiveSnapMode(){return this.snapMode==="x-only"?"x-only":this.snapMode==="nearest"?"nearest":this.lastKnownDataSize>this.largeDatasetThreshold?"x-only":"nearest"}performTooltipUpdateWithHysteresis(e,t){var s;if(!((s=this.options.dataPoint)!=null&&s.enabled)){this.performFallbackTooltipUpdate(e,t);return}const n=this.getEffectiveSnapMode()==="x-only"?this.findDataPointByXOnly(e):this.findNearestDataPointOptimized(e,t);if(!n){this.performFallbackTooltipUpdate(e,t);return}if(this.cachedNearestResult&&this.hoveredSeriesId!==null){const r=this.cachedNearestResult,a=r.pixelX-e,l=r.pixelY-t,c=a*a+l*l,h=n.pixelX-e,u=n.pixelY-t;if((h*h+u*u)*this.hysteresisRatio>=c){this.updateTooltipPosition(this.cachedNearestResult);return}}this.cachedNearestResult=n,this.scheduleShow(n)}performFallbackTooltipUpdate(e,t){var i,n;if((i=this.options.heatmap)!=null&&i.enabled){const s=this.findHeatmapCell(e,t);if(s){this.scheduleShow(s);return}}if((n=this.options.crosshair)!=null&&n.enabled){const s=this.buildCrosshairTooltip(e,t);if(s){this.scheduleShow(s);return}}this.cachedNearestResult=null,this.scheduleHide()}findDataPointByXOnly(e){var l,c;const t=this.getSeries().filter(h=>h.isVisible()&&h.getType()!=="heatmap");if(t.length===0)return null;const i=this.getXScale(),n=this.getYScales(),s=this.pixelToDataX(e);let r=null,a=1/0;for(const h of t){const u=h.getData();if(!u.x||u.x.length===0)continue;const d=n.get(((l=h.getYAxisId)==null?void 0:l.call(h))||"default")||n.values().next().value;if(!d)continue;const f=this.binarySearchClosest(u.x,s),g=Math.abs(u.x[f]-s);if(g<a){a=g;const m=h.getStyle(),y=i.transform(u.x[f]),b=d.transform(u.y[f]);r={type:"datapoint",seriesId:h.getId(),seriesName:h.getId(),seriesColor:m.color||"#ff0055",dataIndex:f,dataX:u.x[f],dataY:u.y[f],pixelX:y,pixelY:b,cycle:(c=h.getCycle)==null?void 0:c.call(h)};const v=h.getYError(f);v&&(r.yError=v)}}return r}findNearestDataPointOptimized(e,t){var h,u,d;const i=this.getSeries().filter(f=>f.isVisible()),n=((h=this.options.dataPoint)==null?void 0:h.hitRadius)??20,s=this.getXScale(),r=this.getYScales();let a=n*n,l=null;const c=this.pixelToDataX(e);for(const f of i){if(f.getType()==="heatmap")continue;const g=f.getData(),m=r.get(((u=f.getYAxisId)==null?void 0:u.call(f))||"default")||r.values().next().value;if(!m||!g.x||g.x.length===0)continue;const y=this.binarySearchClosest(g.x,c),b=g.x.length,v=b>1e5?2:b>1e4?3:5,S=Math.max(0,y-v),T=Math.min(b,y+v+1);for(let P=S;P<T;P++){const M=s.transform(g.x[P]),_=m.transform(g.y[P]),B=M-e,R=_-t,G=B*B+R*R;if(G<a){a=G;const k=f.getStyle();l={type:"datapoint",seriesId:f.getId(),seriesName:f.getId(),seriesColor:k.color||"#ff0055",dataIndex:P,dataX:g.x[P],dataY:g.y[P],pixelX:M,pixelY:_,cycle:(d=f.getCycle)==null?void 0:d.call(f)};const F=f.getYError(P);F&&(l.yError=F)}}}return l}findHeatmapCell(e,t){var l,c;const i=this.getSeries().filter(h=>h.isVisible()&&h.getType()==="heatmap");if(i.length===0)return null;const n=this.getXScale(),s=this.getYScales(),r=this.pixelToDataX(e),a=this.pixelToDataY(t);for(const h of i){const u=h.getHeatmapData();if(!u||!u.xValues||!u.yValues||!u.zValues)continue;const d=this.binarySearchClosest(u.xValues,r),f=this.binarySearchClosest(u.yValues,a),g=u.xValues[d],m=u.yValues[f],y=s.get(((l=h.getYAxisId)==null?void 0:l.call(h))||"default")||s.values().next().value;if(!y)continue;const b=n.transform(g),v=y.transform(m),S=u.zValues[f*u.xValues.length+d],T=((c=h.getHeatmapStyle)==null?void 0:c.call(h))||{};return{type:"heatmap",seriesId:h.getId(),seriesName:h.getId(),xIndex:d,yIndex:f,dataX:g,dataY:m,zValue:S,pixelX:b,pixelY:v,colorScale:T.colorScale}}return null}binarySearchClosest(e,t){let i=0,n=e.length-1;for(;i<n;){const s=Math.floor((i+n)/2);e[s]<t?i=s+1:n=s}return i>0&&Math.abs(e[i-1]-t)<Math.abs(e[i]-t)?i-1:i}buildCrosshairTooltip(e,t){var a,l;const i=this.getSeries().filter(c=>c.isVisible()&&c.getType()!=="heatmap");if(i.length===0)return null;const n=this.pixelToDataX(e),s=this.getYScales(),r=[];for(const c of i){const h=c.getData();if(!h.x||h.x.length===0||!(s.get(((a=c.getYAxisId)==null?void 0:a.call(c))||"default")||s.values().next().value))continue;const d=this.binarySearchClosest(h.x,n);let f,g=!1;if(d===0||d>=h.x.length-1||h.x[d]===n)f=h.y[d];else if((l=this.options.crosshair)!=null&&l.interpolate){const y=h.x[d-1],b=h.x[d],v=h.y[d-1],S=h.y[d],T=(n-y)/(b-y);f=v+T*(S-v),g=!0}else f=h.y[d];const m=c.getStyle();r.push({seriesId:c.getId(),seriesName:c.getId(),seriesColor:m.color||"#ff0055",x:n,y:f,isInterpolated:g})}return r.length===0?null:{type:"crosshair",cursorX:e,cursorY:t,dataX:n,interpolatedValues:r}}scheduleShow(e){if(this.clearHideTimeout(),e.type==="datapoint"){const i=e;if(this.hoveredSeriesId===i.seriesId&&this.hoveredDataIndex===i.dataIndex){this.updateTooltipPosition(e);return}this.hoveredSeriesId=i.seriesId,this.hoveredDataIndex=i.dataIndex}this.clearShowTimeout();const t=this.activeTooltips.size>0?0:this.options.showDelay;t>0?this.showTimeoutId=window.setTimeout(()=>{this.showTooltip(e)},t):this.showTooltip(e)}scheduleHide(){this.clearShowTimeout(),this.hoveredSeriesId=null,this.hoveredDataIndex=null,this.options.hideDelay>0?this.hideTimeoutId=window.setTimeout(()=>{this.hideAll()},this.options.hideDelay):this.hideAll()}clearShowTimeout(){this.showTimeoutId!==null&&(clearTimeout(this.showTimeoutId),this.showTimeoutId=null)}clearHideTimeout(){this.hideTimeoutId!==null&&(clearTimeout(this.hideTimeoutId),this.hideTimeoutId=null)}showTooltip(e){const t=this.getTemplateIdForType(e.type),i=this.templates.get(t)||yt(e.type),n=e.pixelX??this.lastCursorX??0,s=e.pixelY??this.lastCursorY??0,r=i.measure(this.ctx,e,this.theme),a=this.positioner.calculatePosition(n,s,r),l="main";this.activeTooltips.set(l,{id:l,data:e,position:a,template:i})}updateTooltipPosition(e){const t=this.activeTooltips.get("main");if(!t)return;const i=e||t.data,n=i.pixelX??this.lastCursorX??0,s=i.pixelY??this.lastCursorY??0,r=t.template.measure(this.ctx,i,this.theme);t.position=this.positioner.calculatePosition(n,s,r),t.data=i}getTemplateIdForType(e){var t,i,n;switch(e){case"datapoint":return((t=this.options.dataPoint)==null?void 0:t.templateId)||"default";case"crosshair":return((i=this.options.crosshair)==null?void 0:i.templateId)||"crosshair";case"heatmap":return((n=this.options.heatmap)==null?void 0:n.templateId)||"heatmap";default:return"default"}}show(e,t){const i=`tooltip-${++this.tooltipIdCounter}`,n=(t==null?void 0:t.templateId)||this.getTemplateIdForType(e.type),s=this.templates.get(n)||yt(e.type);let r;if(t!=null&&t.position){const a=s.measure(this.ctx,e,this.theme);r=this.positioner.calculatePosition(t.position.x,t.position.y,a)}else{const a=e.pixelX??0,l=e.pixelY??0,c=s.measure(this.ctx,e,this.theme);r=this.positioner.calculatePosition(a,l,c)}return this.activeTooltips.set(i,{id:i,data:e,position:r,template:s}),t!=null&&t.duration&&t.duration>0&&setTimeout(()=>this.hide(i),t.duration),i}hide(e){this.activeTooltips.delete(e)}hideAll(){this.activeTooltips.clear(),this.hoveredSeriesId=null,this.hoveredDataIndex=null}render(){if(!(!this.options.enabled||this.activeTooltips.size===0))for(const e of this.activeTooltips.values())this.renderer.render(e.data,e.position,e.template)}hasActiveTooltip(){return this.activeTooltips.size>0}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}destroy(){this.clearShowTimeout(),this.clearHideTimeout(),this.activeTooltips.clear(),this.templates.clear(),this.events.clear()}}function _i(o,e){const{seriesIds:t,includeHeaders:i=!0,precision:n=6,delimiter:s=","}=e??{},r=t?o.filter(c=>t.includes(c.getId())):o;if(r.length===0)return"";const a=[];if(i){const c=[];r.forEach(h=>{c.push(`${h.getId()}_x`,`${h.getId()}_y`)}),a.push(c.join(s))}const l=Math.max(...r.map(c=>c.getPointCount()));for(let c=0;c<l;c++){const h=[];r.forEach(u=>{const d=u.getData();d&&c<d.x.length?h.push(d.x[c].toFixed(n),d.y[c].toFixed(n)):h.push("","")}),a.push(h.join(s))}return a.join(`
|
|
181
|
-
`)}function Fi(o,e,t){const{seriesIds:i,precision:n=6}=t??{},
|
|
182
|
-
Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor(e,h)}o.tooltip&&o.tooltip.render(),o.stats&&o.showStatistics&&o.stats.update(o.viewBounds)}function Oi(o,e,t){if(o==="heatmap"&&t){const{xValues:d,yValues:f}=t;let g=1/0,m=-1/0,y=1/0,b=-1/0;for(let v=0;v<d.length;v++){const S=d[v];S<g&&(g=S),S>m&&(m=S)}for(let v=0;v<f.length;v++){const S=f[v];S<y&&(y=S),S>b&&(b=S)}return{xMin:g,xMax:m,yMin:y,yMax:b}}const{x:i,y:n,y2:s,high:r,low:a}=e;if(i.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let l=1/0,c=-1/0,h=1/0,u=-1/0;for(let d=0;d<i.length;d++){const f=i[d];if(!isFinite(f))continue;f<l&&(l=f),f>c&&(c=f);const g=[n[d]];s&&isFinite(s[d])&&g.push(s[d]),r&&isFinite(r[d])&&g.push(r[d]),a&&isFinite(a[d])&&g.push(a[d]);for(const m of g)isFinite(m)&&(m<h&&(h=m),m>u&&(u=m))}return l===1/0?{xMin:0,xMax:1,yMin:0,yMax:1}:{xMin:l,xMax:c,yMin:h,yMax:u}}function E(o){return o?o instanceof Float32Array||o instanceof Float64Array?o:new Float32Array(o):new Float32Array(0)}function q(o,e){const t=new o.constructor(o.length+e.length);return t.set(o,0),t.set(e,o.length),t}function Ui(o,e){const{x:t,y:i}=o,n=t.length;if(n<e)return{...o};const s=new Float32Array(n),r=Math.floor(e/2);for(let a=0;a<n;a++){let l=0,c=0;for(let h=a-r;h<=a+r;h++)h>=0&&h<n&&(l+=i[h],c++);s[a]=l/c}return{x:t,y:s}}function $i(o,e){var n,s;if(e<0||e>=o.x.length)return null;if(o.yError&&e<o.yError.length){const r=o.yError[e];return[r,r]}const t=((n=o.yErrorMinus)==null?void 0:n[e])??0,i=((s=o.yErrorPlus)==null?void 0:s[e])??0;return t>0||i>0?[t,i]:null}function Yi(o,e){var n,s;if(e<0||e>=o.x.length)return null;if(o.xError&&e<o.xError.length){const r=o.xError[e];return[r,r]}const t=((n=o.xErrorMinus)==null?void 0:n[e])??0,i=((s=o.xErrorPlus)==null?void 0:s[e])??0;return t>0||i>0?[t,i]:null}const Vi={color:"#ff0055",width:1.5,opacity:1,pointSize:4};class vt{constructor(e){p(this,"id");p(this,"type");p(this,"yAxisId");p(this,"data");p(this,"style");p(this,"visible");p(this,"name");p(this,"stackId");p(this,"cycle");p(this,"maxPoints");p(this,"bullishCount",0);p(this,"bearishCount",0);p(this,"heatmapData");p(this,"heatmapStyle");p(this,"lastAppendCount",0);p(this,"cachedBounds",null);p(this,"boundsNeedsUpdate",!0);p(this,"_needsBufferUpdate",!0);p(this,"smoothedData",null);p(this,"smoothingNeedsUpdate",!0);p(this,"getId",()=>this.id);p(this,"getName",()=>this.name||this.id);p(this,"getType",()=>this.type);p(this,"getYAxisId",()=>this.yAxisId);p(this,"getStackId",()=>this.stackId);p(this,"getVisible",()=>this.visible);p(this,"isVisible",()=>this.visible);p(this,"getStyle",()=>this.style);p(this,"getHeatmapData",()=>this.heatmapData);p(this,"getHeatmapStyle",()=>this.heatmapStyle);p(this,"getCycle",()=>this.cycle);p(this,"getPointCount",()=>this.type==="heatmap"?this.heatmapData.xValues.length*this.heatmapData.yValues.length:this.data.x.length);p(this,"getLastAppendCount",()=>this.lastAppendCount);p(this,"resetLastAppendCount",()=>{this.lastAppendCount=0});p(this,"hasErrorData",()=>!!(this.data.yError||this.data.yErrorPlus||this.data.yErrorMinus||this.data.xError||this.data.xErrorPlus||this.data.xErrorMinus));p(this,"getYError",e=>$i(this.data,e));p(this,"getXError",e=>Yi(this.data,e));if(this.id=e.id,this.name=e.name,this.type=e.type,this.yAxisId=e.yAxisId,this.visible=e.visible??!0,this.stackId=e.stackId,this.cycle=e.cycle,this.maxPoints=e.maxPoints,this.type==="heatmap"){const t=e;this.data={x:new Float32Array(0),y:new Float32Array(0)},this.heatmapData={xValues:E(t.data.xValues),yValues:E(t.data.yValues),zValues:E(t.data.zValues)},this.heatmapStyle=t.style}else{const t=e.data;this.data={x:E(t==null?void 0:t.x),y:E(t==null?void 0:t.y),yError:t!=null&&t.yError?E(t.yError):void 0,yErrorPlus:t!=null&&t.yErrorPlus?E(t.yErrorPlus):void 0,yErrorMinus:t!=null&&t.yErrorMinus?E(t.yErrorMinus):void 0,xError:t!=null&&t.xError?E(t.xError):void 0,xErrorPlus:t!=null&&t.xErrorPlus?E(t.xErrorPlus):void 0,xErrorMinus:t!=null&&t.xErrorMinus?E(t.xErrorMinus):void 0,y2:t!=null&&t.y2?E(t.y2):void 0,open:t!=null&&t.open?E(t.open):void 0,high:t!=null&&t.high?E(t.high):void 0,low:t!=null&&t.low?E(t.low):void 0,close:t!=null&&t.close?E(t.close):void 0}}this.style={...Vi,...e.style},e.color&&(this.style.color=e.color),e.width&&(this.style.width=e.width),e.pointSize&&(this.style.pointSize=e.pointSize)}getData(){return this.style.smoothing&&this.style.smoothing>0?((this.smoothingNeedsUpdate||!this.smoothedData)&&(this.smoothedData=Ui(this.data,5),this.smoothingNeedsUpdate=!1),this.smoothedData):this.data}getBounds(){return this.data.x.length===0&&this.type!=="heatmap"?null:((this.boundsNeedsUpdate||!this.cachedBounds)&&(this.cachedBounds=Oi(this.type,this.data,this.heatmapData),this.boundsNeedsUpdate=!1),this.cachedBounds)}updateData(e){if(e){if(e.append){const t=E(e.x),i=E(e.y);if(t.length>0&&(this.data.x=q(this.data.x,t),this.data.y=q(this.data.y,i),e.y2&&(this.data.y2=this.data.y2?q(this.data.y2,E(e.y2)):E(e.y2)),e.open&&(this.data.open=this.data.open?q(this.data.open,E(e.open)):E(e.open)),e.high&&(this.data.high=this.data.high?q(this.data.high,E(e.high)):E(e.high)),e.low&&(this.data.low=this.data.low?q(this.data.low,E(e.low)):E(e.low)),e.close&&(this.data.close=this.data.close?q(this.data.close,E(e.close)):E(e.close)),this.lastAppendCount+=t.length,this.maxPoints&&this.data.x.length>this.maxPoints)){const n=this.data.x.length-this.maxPoints;this.data.x=this.data.x.slice(n),this.data.y=this.data.y.slice(n),this.data.y2&&(this.data.y2=this.data.y2.slice(n)),this.data.open&&(this.data.open=this.data.open.slice(n)),this.data.high&&(this.data.high=this.data.high.slice(n)),this.data.low&&(this.data.low=this.data.low.slice(n)),this.data.close&&(this.data.close=this.data.close.slice(n)),this.lastAppendCount=0}}else e.x&&(this.data.x=E(e.x)),e.y&&(this.data.y=E(e.y)),e.y2&&(this.data.y2=E(e.y2)),e.open&&(this.data.open=E(e.open)),e.high&&(this.data.high=E(e.high)),e.low&&(this.data.low=E(e.low)),e.close&&(this.data.close=E(e.close)),this.lastAppendCount=0;this.boundsNeedsUpdate=!0,this.smoothingNeedsUpdate=!0,this._needsBufferUpdate=!0}}setStyle(e){const t=this.style.smoothing;this.style={...this.style,...e},this.style.smoothing!==t&&(this.smoothingNeedsUpdate=!0,this._needsBufferUpdate=!0)}setType(e){this.type=e,this._needsBufferUpdate=!0}setVisible(e){this.visible=e}get needsBufferUpdate(){return this._needsBufferUpdate}set needsBufferUpdate(e){this._needsBufferUpdate=e}setMaxPoints(e){if(this.maxPoints=e,this.maxPoints&&this.data.x.length>this.maxPoints){const t=this.data.x.length-this.maxPoints;this.data.x=this.data.x.slice(t),this.data.y=this.data.y.slice(t),this.data.y2&&(this.data.y2=this.data.y2.slice(t)),this.data.open&&(this.data.open=this.data.open.slice(t)),this.data.high&&(this.data.high=this.data.high.slice(t)),this.data.low&&(this.data.low=this.data.low.slice(t)),this.data.close&&(this.data.close=this.data.close.slice(t)),this._needsBufferUpdate=!0}}destroy(){this.data={x:new Float32Array(0),y:new Float32Array(0)},this.cachedBounds=null}}function Wi(o){return new ce(o)}class De{constructor(e,t={}){p(this,"available");p(this,"canvas");p(this,"adapter");p(this,"device");p(this,"context");this.canvas=e,this.available=De.isSupported()}static isSupported(){return typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u"}async init(e={}){if(!this.available)throw new Error("[SciChart] WebGPU is not supported in this environment");const t=globalThis.navigator.gpu;if(this.adapter=await t.requestAdapter({powerPreference:e.powerPreference??"high-performance"}),!this.adapter)throw new Error("[SciChart] Failed to request WebGPU adapter");this.device=await this.adapter.requestDevice();const i=this.canvas.getContext("webgpu");if(!i)throw new Error("[SciChart] Failed to get WebGPU context");this.context=i;const n=e.preferredFormat??(t.getPreferredCanvasFormat?t.getPreferredCanvasFormat():"bgra8unorm");this.context.configure({device:this.device,format:n,alphaMode:"premultiplied"})}destroy(){this.device=void 0,this.adapter=void 0,this.context=void 0}}function Xi(o,e,t){const i=Math.min(o.length,e.length),n=new Float32Array(i*6*2),s=t*.5;for(let r=0;r<i;r++){const a=o[r],l=e[r],c=r*12,h=a-s,u=a+s,d=0,f=l;n[c+0]=h,n[c+1]=d,n[c+2]=u,n[c+3]=d,n[c+4]=h,n[c+5]=f,n[c+6]=h,n[c+7]=f,n[c+8]=u,n[c+9]=d,n[c+10]=u,n[c+11]=f}return n}function St(o){if(o.length<2)return 1;let e=1/0;for(let t=1;t<o.length;t++){const i=Math.abs(o[t]-o[t-1]);i>0&&i<e&&(e=i)}return e===1/0?1:e*.8}function Ni(o,e,t){const i=o.length,n=e.length;i*n>t.length&&console.warn("[Heatmap] Z array is too small for the specified grid dimensions");const s=(i-1)*(n-1),r=new Float32Array(s*6*3);let a=0;for(let l=0;l<n-1;l++)for(let c=0;c<i-1;c++){const h=o[c],u=o[c+1],d=e[l],f=e[l+1],g=t[l*i+c],m=t[l*i+(c+1)],y=t[(l+1)*i+c],b=t[(l+1)*i+(c+1)];r[a++]=h,r[a++]=d,r[a++]=g,r[a++]=u,r[a++]=d,r[a++]=m,r[a++]=h,r[a++]=f,r[a++]=y,r[a++]=h,r[a++]=f,r[a++]=y,r[a++]=u,r[a++]=d,r[a++]=m,r[a++]=u,r[a++]=f,r[a++]=b}return r}function Hi(o="viridis"){const t=new Uint8Array(1024);for(let i=0;i<256;i++){const n=i/255;let s,r,a;o==="jet"?(s=Math.min(Math.max(1.5-Math.abs(n*4-3),0),1),r=Math.min(Math.max(1.5-Math.abs(n*4-2),0),1),a=Math.min(Math.max(1.5-Math.abs(n*4-1),0),1)):o==="grayscale"?s=r=a=n:o==="plasma"?(s=.5+.5*Math.sin(Math.PI*(n-.5)),r=.5+.5*Math.sin(Math.PI*n),a=.8):(s=.267*(1-n)+.993*n,r=.005*(1-n)+.906*n,a=.337*(1-n)+.144*n),t[i*4+0]=s*255,t[i*4+1]=r*255,t[i*4+2]=a*255,t[i*4+3]=255}return t}function qi(o,e,t,i,n,s){const r=o.length,a=[],l=[],c=s/2,u=s/10/2;for(let d=0;d<r;d++){const g=n[d]>=e[d]?a:l,m=Math.max(e[d],n[d]),y=Math.min(e[d],n[d]);wt(g,o[d]-c,y,o[d]+c,m),wt(g,o[d]-u,i[d],o[d]+u,t[d])}return{bullish:new Float32Array(a),bearish:new Float32Array(l)}}function wt(o,e,t,i,n){o.push(e,t,i,t,e,n),o.push(i,t,i,n,e,n)}function be(o,e){const t=e.getStackId();if(t){Ki(o,t);return}const i=e.getData(),n=e.getType();if(n!=="heatmap"&&(!i||i.x.length===0))return;const s=e.getId();if(n==="band"||n==="area"){const r=n==="area"?new Float32Array(i.x.length).fill(0):i.y2||new Float32Array(i.x.length).fill(0);o.renderer.createBuffer(s,ot(i.x,i.y,r))}else if(n==="bar"){const r=e.getStyle().barWidth??St(i.x);o.renderer.createBuffer(s,Xi(i.x,i.y,r))}else if(n==="heatmap")ji(o,e);else if(n==="candlestick"){const r=e.getData();if(r.open&&r.high&&r.low&&r.close){const a=e.getStyle().barWidth??St(r.x),{bullish:l,bearish:c}=qi(r.x,r.open,r.high,r.low,r.close,a);o.renderer.createBuffer(`${s}_bullish`,l),o.renderer.createBuffer(`${s}_bearish`,c),e.bullishCount=l.length/2,e.bearishCount=c.length/2}}else o.renderer.createBuffer(s,ke(i.x,i.y));if(n==="step"||n==="step+scatter"){const r=e.getStyle().stepMode??"after";o.renderer.createBuffer(`${s}_step`,oi(i.x,i.y,r))}e.resetLastAppendCount()}function ji(o,e){var s;const t=e.getHeatmapData(),i=e.getHeatmapStyle();if(!t||t.xValues.length<2)return;o.renderer.createBuffer(e.getId(),Ni(t.xValues,t.yValues,t.zValues));const n=((s=i==null?void 0:i.colorScale)==null?void 0:s.name)||"viridis";o.renderer.createColormapTexture(`${e.getId()}_colormap`,Hi(n))}function Ki(o,e){const t=Array.from(o.series.values()).filter(n=>n.getStackId()===e);let i=null;for(const n of t){const s=n.getData();if(s.x.length===0)continue;i||(i=new Float32Array(s.y.length).fill(0));const r=new Float32Array(i);for(let a=0;a<s.y.length;a++)i[a]+=s.y[a];o.renderer.createBuffer(n.getId(),ot(s.x,i,r)),n.resetLastAppendCount()}}function Zi(o,e){var i;const t=new vt(e);o.series.set(t.getId(),t),be(o,t),(o.xAxisOptions.auto||Array.from(o.yAxisOptionsMap.values()).some(n=>n.auto))&&o.autoScale(),(i=o.updateLegend)==null||i.call(o),o.requestRender()}function Ji(o,e){var i;const t=o.series.get(e);t&&(o.renderer.deleteBuffer(e),o.renderer.deleteBuffer(`${e}_step`),t.destroy(),o.series.delete(e),(i=o.updateLegend)==null||i.call(o),o.requestRender())}function Qi(o,e,t){const i=o.series.get(e);i&&(i.updateData(t),be(o,i),o.requestRender())}function en(o,e,t,i){var r;const n=o.series.get(e);if(!n)return;const s=((r=n.getBounds())==null?void 0:r.xMax)??-1/0;if(n.updateData({x:t,y:i,append:!0}),be(o,n),o.autoScrollEnabled){const a=n.getBounds();if(a){const l=o.viewBounds.xMax-o.viewBounds.xMin;s>=o.viewBounds.xMax-l*.05&&(o.viewBounds.xMax=a.xMax,o.viewBounds.xMin=o.viewBounds.xMax-l)}}(o.xAxisOptions.auto||Array.from(o.yAxisOptionsMap.values()).some(a=>a.auto))&&o.autoScale(),o.requestRender()}function tn(o,e,t){const i=o.series.get(e);i&&(i.setMaxPoints(t),o.requestRender())}function nn(o,e,t,i={}){const n=o.series.get(e);if(!n)throw new Error(`Series ${e} not found`);const s=n.getData();if(!s||s.x.length<2)return"";const r=it(s.x,s.y,t,i),a=n.getBounds(),l=(a==null?void 0:a.xMin)??0,h=((a==null?void 0:a.xMax)??1)-l,u=200,d=new Float32Array(u),f=new Float32Array(u);for(let y=0;y<u;y++){const b=l+y/(u-1)*h;d[y]=b,f[y]=r.predict(b)}const g=`${e}-fit-${Date.now()}`,m=n.getStyle();return o.addSeries({id:g,type:"line",yAxisId:n.getYAxisId(),data:{x:d,y:f},style:{color:m.color,width:(m.width||1)*1.5,opacity:.8,lineDash:[5,5]}}),o.addAnnotation({type:"text",x:l+h*.05,y:r.predict(l+h*.05),text:`${r.equation}
|
|
183
|
-
(R² = ${
|
|
180
|
+
`,this.content.appendChild(c)}),this.content.innerHTML===""&&(this.content.innerHTML="<div style='opacity: 0.5; font-style: italic;'>No series visible in range</div>"))}toggle(){this.isExpanded=!this.isExpanded,this.content.style.display=this.isExpanded?"block":"none",this.isExpanded}updateTheme(e){this.theme=e,this.updateContainerStyle()}destroy(){this.container.remove()}}const I={line:{color:"rgba(255, 255, 255, 0.7)",lineWidth:1,lineDash:[]},rectangle:{fillColor:"rgba(100, 100, 255, 0.2)",strokeWidth:1},text:{fontSize:12,fontFamily:"Inter, system-ui, sans-serif",color:"#ffffff",padding:4},arrow:{color:"rgba(255, 255, 255, 0.7)",lineWidth:2,headSize:10}};class ht{constructor(){p(this,"annotations",new Map);p(this,"idCounter",0)}add(e){const t=e.id??`annotation-${++this.idCounter}`,i={...e,id:t,visible:e.visible??!0,interactive:e.interactive??!1,zIndex:e.zIndex??0};return this.annotations.set(t,i),t}remove(e){return this.annotations.delete(e)}update(e,t){const i=this.annotations.get(e);i&&this.annotations.set(e,{...i,...t})}get(e){return this.annotations.get(e)}getAll(){return Array.from(this.annotations.values())}clear(){this.annotations.clear()}get count(){return this.annotations.size}render(e,t,i){const n=this.getAll().filter(r=>r.visible!==!1).sort((r,s)=>(r.zIndex??0)-(s.zIndex??0));e.save(),e.beginPath(),e.rect(t.x,t.y,t.width,t.height),e.clip();for(const r of n)this.renderAnnotation(e,r,t,i);e.restore()}renderAnnotation(e,t,i,n){switch(t.type){case"horizontal-line":this.renderHorizontalLine(e,t,i,n);break;case"vertical-line":this.renderVerticalLine(e,t,i,n);break;case"rectangle":this.renderRectangle(e,t,i,n);break;case"band":this.renderBand(e,t,i,n);break;case"text":this.renderText(e,t,i,n);break;case"arrow":this.renderArrow(e,t,i,n);break}}dataToPixelX(e,t,i){const n=(e-t.xMin)/(t.xMax-t.xMin);return i.x+n*i.width}dataToPixelY(e,t,i){const n=(e-t.yMin)/(t.yMax-t.yMin);return i.y+i.height*(1-n)}renderHorizontalLine(e,t,i,n){const r=this.dataToPixelY(t.y,n,i);if(r<i.y||r>i.y+i.height)return;const s=t.xMin!==void 0?Math.max(this.dataToPixelX(t.xMin,n,i),i.x):i.x,a=t.xMax!==void 0?Math.min(this.dataToPixelX(t.xMax,n,i),i.x+i.width):i.x+i.width;e.save(),e.strokeStyle=t.color??I.line.color,e.lineWidth=t.lineWidth??I.line.lineWidth,e.setLineDash(t.lineDash??I.line.lineDash),e.beginPath(),e.moveTo(s,r),e.lineTo(a,r),e.stroke(),t.label&&this.renderLineLabel(e,t.label,s,a,r,t.labelPosition??"right","horizontal",t.labelBackground),e.restore()}renderVerticalLine(e,t,i,n){const r=this.dataToPixelX(t.x,n,i);if(r<i.x||r>i.x+i.width)return;const s=t.yMin!==void 0?Math.min(this.dataToPixelY(t.yMin,n,i),i.y+i.height):i.y,a=t.yMax!==void 0?Math.max(this.dataToPixelY(t.yMax,n,i),i.y):i.y+i.height;e.save(),e.strokeStyle=t.color??I.line.color,e.lineWidth=t.lineWidth??I.line.lineWidth,e.setLineDash(t.lineDash??I.line.lineDash),e.beginPath(),e.moveTo(r,s),e.lineTo(r,a),e.stroke(),t.label&&this.renderLineLabel(e,t.label,s,a,r,t.labelPosition??"top","vertical",t.labelBackground),e.restore()}renderRectangle(e,t,i,n){const r=this.dataToPixelX(t.xMin,n,i),s=this.dataToPixelX(t.xMax,n,i),a=this.dataToPixelY(t.yMax,n,i),l=this.dataToPixelY(t.yMin,n,i),c=Math.min(r,s),h=Math.min(a,l),u=Math.abs(s-r),d=Math.abs(l-a);e.save(),t.fillColor&&(e.fillStyle=t.fillColor,e.fillRect(c,h,u,d)),t.strokeColor&&(e.strokeStyle=t.strokeColor,e.lineWidth=t.strokeWidth??I.rectangle.strokeWidth,e.setLineDash(t.strokeDash??[]),e.strokeRect(c,h,u,d)),t.label&&this.renderCenteredLabel(e,t.label,c+u/2,h+d/2),e.restore()}renderBand(e,t,i,n){let r,s,a,l;if(t.xMin!==void 0&&t.xMax!==void 0){const c=this.dataToPixelX(t.xMin,n,i),h=this.dataToPixelX(t.xMax,n,i);r=Math.min(c,h),a=Math.abs(h-c),s=i.y,l=i.height,t.yMin!==void 0&&(l=this.dataToPixelY(t.yMin,n,i)-s),t.yMax!==void 0&&(s=this.dataToPixelY(t.yMax,n,i),l=i.y+i.height-s)}else if(t.yMin!==void 0&&t.yMax!==void 0){const c=this.dataToPixelY(t.yMax,n,i),h=this.dataToPixelY(t.yMin,n,i);s=Math.min(c,h),l=Math.abs(h-c),r=i.x,a=i.width}else return;if(e.save(),e.fillStyle=t.fillColor??I.rectangle.fillColor,e.fillRect(r,s,a,l),t.strokeColor&&(e.strokeStyle=t.strokeColor,e.lineWidth=t.strokeWidth??1,e.strokeRect(r,s,a,l)),t.label){let c=r+a/2,h=s+l/2;switch(t.labelPosition){case"top":h=s+15;break;case"bottom":h=s+l-5;break;case"left":c=r+10;break;case"right":c=r+a-10;break}this.renderCenteredLabel(e,t.label,c,h)}e.restore()}renderText(e,t,i,n){const r=this.dataToPixelX(t.x,n,i),s=this.dataToPixelY(t.y,n,i);e.save(),t.rotation&&(e.translate(r,s),e.rotate(t.rotation*Math.PI/180),e.translate(-r,-s));const a=t.fontSize??I.text.fontSize,l=t.fontFamily??I.text.fontFamily,c=t.fontWeight??"normal";e.font=`${c} ${a}px ${l}`,e.textAlign="center",e.textBaseline="middle";const h=e.measureText(t.text),u=t.padding??I.text.padding,d=h.width+u*2,f=a+u*2;let g=r,m=s;switch(t.anchor){case"top-left":g+=d/2,m+=f/2;break;case"top-right":g-=d/2,m+=f/2;break;case"bottom-left":g+=d/2,m-=f/2;break;case"bottom-right":g-=d/2,m-=f/2;break;case"top-center":m+=f/2;break;case"bottom-center":m-=f/2;break;case"left-center":g+=d/2;break;case"right-center":g-=d/2;break}t.backgroundColor&&(e.fillStyle=t.backgroundColor,e.beginPath(),e.roundRect(g-d/2,m-f/2,d,f,4),e.fill()),e.fillStyle=t.color??I.text.color,e.fillText(t.text,g,m),e.restore()}renderArrow(e,t,i,n){const r=this.dataToPixelX(t.x1,n,i),s=this.dataToPixelY(t.y1,n,i),a=this.dataToPixelX(t.x2,n,i),l=this.dataToPixelY(t.y2,n,i);e.save(),e.strokeStyle=t.color??I.arrow.color,e.fillStyle=t.color??I.arrow.color,e.lineWidth=t.lineWidth??I.arrow.lineWidth,e.beginPath(),e.moveTo(r,s),e.lineTo(a,l),e.stroke();const c=t.headSize??I.arrow.headSize,h=Math.atan2(l-s,a-r),u=t.headStyle??"filled";if(u!=="none"&&(e.beginPath(),e.moveTo(a,l),e.lineTo(a-c*Math.cos(h-Math.PI/6),l-c*Math.sin(h-Math.PI/6)),u==="filled"?(e.lineTo(a-c*Math.cos(h+Math.PI/6),l-c*Math.sin(h+Math.PI/6)),e.closePath(),e.fill()):(e.moveTo(a,l),e.lineTo(a-c*Math.cos(h+Math.PI/6),l-c*Math.sin(h+Math.PI/6)),e.stroke())),t.showTail){const d=h+Math.PI;e.beginPath(),e.moveTo(r,s),e.lineTo(r-c*Math.cos(d-Math.PI/6),s-c*Math.sin(d-Math.PI/6)),e.lineTo(r-c*Math.cos(d+Math.PI/6),s-c*Math.sin(d+Math.PI/6)),e.closePath(),e.fill()}if(t.label){const d=(r+a)/2,f=(s+l)/2;this.renderCenteredLabel(e,t.label,d,f-10)}e.restore()}renderLineLabel(e,t,i,n,r,s,a,l){e.save(),e.font=`${I.text.fontSize}px ${I.text.fontFamily}`;const c=e.measureText(t),h=4,u=c.width+h*2,d=I.text.fontSize+h*2;let f,g;if(a==="horizontal"){switch(g=r,s){case"left":f=i+5,e.textAlign="left";break;case"right":f=n-5,e.textAlign="right";break;default:f=(i+n)/2,e.textAlign="center"}e.textBaseline="bottom",g-=4}else{switch(f=r,s){case"top":g=i+d;break;case"bottom":g=n-5;break;default:g=(i+n)/2}e.textAlign="center",e.textBaseline="middle"}if(l??!0){e.fillStyle=l??"rgba(0, 0, 0, 0.7)";const m=e.textAlign==="left"?f-h:e.textAlign==="right"?f-u+h:f-u/2;e.fillRect(m,g-d+h,u,d)}e.fillStyle=I.text.color,e.fillText(t,f,g),e.restore()}renderCenteredLabel(e,t,i,n){e.save(),e.font=`${I.text.fontSize}px ${I.text.fontFamily}`;const r=e.measureText(t),s=4,a=r.width+s*2,l=I.text.fontSize+s*2;e.fillStyle="rgba(0, 0, 0, 0.7)",e.beginPath(),e.roundRect(i-a/2,n-l/2,a,l,3),e.fill(),e.fillStyle=I.text.color,e.textAlign="center",e.textBaseline="middle",e.fillText(t,i,n),e.restore()}}const Ae={top:10,right:12,bottom:10,left:12},pe={backgroundColor:"rgba(15, 18, 25, 0.95)",backgroundGradient:"rgba(25, 30, 40, 0.90)",borderColor:"rgba(255, 255, 255, 0.12)",borderWidth:1,borderRadius:8,backdropBlur:12,shadow:{color:"rgba(0, 0, 0, 0.4)",offsetX:0,offsetY:4,blur:16},fontFamily:"Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",textColor:"#ffffff",textSecondaryColor:"rgba(255, 255, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(255, 255, 255, 0.1)",showArrow:!0,arrowSize:6},ut={backgroundColor:"rgba(255, 255, 255, 0.98)",borderColor:"rgba(0, 0, 0, 0.12)",borderWidth:1,borderRadius:8,backdropBlur:8,shadow:{color:"rgba(0, 0, 0, 0.12)",offsetX:0,offsetY:4,blur:12},fontFamily:"Inter, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",textColor:"#1a1a1a",textSecondaryColor:"rgba(0, 0, 0, 0.55)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(0, 0, 0, 0.08)",showArrow:!0,arrowSize:6},gi={backgroundColor:"rgba(255, 255, 255, 0.08)",backgroundGradient:"rgba(255, 255, 255, 0.04)",borderColor:"rgba(255, 255, 255, 0.2)",borderWidth:1,borderRadius:12,backdropBlur:20,shadow:{color:"rgba(0, 0, 0, 0.3)",offsetX:0,offsetY:8,blur:32},fontFamily:"Inter, system-ui, sans-serif",textColor:"rgba(255, 255, 255, 0.95)",textSecondaryColor:"rgba(255, 255, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.5,padding:{top:12,right:14,bottom:12,left:14},itemGap:5,headerGap:10,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(255, 255, 255, 0.15)",showArrow:!0,arrowSize:7},dt={backgroundColor:"rgba(10, 15, 30, 0.95)",backgroundGradient:"rgba(20, 25, 50, 0.90)",borderColor:"rgba(100, 120, 255, 0.25)",borderWidth:1,borderRadius:8,backdropBlur:15,shadow:{color:"rgba(50, 70, 150, 0.25)",offsetX:0,offsetY:4,blur:20},fontFamily:"Inter, system-ui, sans-serif",textColor:"#e0e8ff",textSecondaryColor:"rgba(180, 190, 255, 0.6)",titleFontSize:12,titleFontWeight:600,contentFontSize:11,lineHeight:1.4,padding:Ae,itemGap:4,headerGap:8,showSeriesIndicator:!0,seriesIndicatorSize:8,showHeaderSeparator:!0,separatorColor:"rgba(100, 120, 255, 0.15)",showArrow:!0,arrowSize:6},ft={backgroundColor:"rgba(8, 20, 40, 0.96)",backgroundGradient:"rgba(15, 35, 60, 0.92)",borderColor:"rgba(30, 136, 229, 0.35)",borderWidth:1,borderRadius:6,backdropBlur:10,shadow:{color:"rgba(30, 136, 229, 0.2)",offsetX:0,offsetY:4,blur:16},fontFamily:'"JetBrains Mono", "Fira Code", monospace',textColor:"#bbdefb",textSecondaryColor:"rgba(144, 202, 249, 0.7)",titleFontSize:11,titleFontWeight:600,contentFontSize:11,lineHeight:1.5,padding:{top:8,right:10,bottom:8,left:10},itemGap:3,headerGap:6,showSeriesIndicator:!0,seriesIndicatorSize:6,showHeaderSeparator:!0,separatorColor:"rgba(30, 136, 229, 0.2)",showArrow:!0,arrowSize:5},pt={dark:pe,light:ut,glass:gi,midnight:dt,electrochemistry:ft,neon:{backgroundColor:"rgba(0, 0, 0, 0.92)",borderColor:"#00ffff",borderWidth:1,borderRadius:4,backdropBlur:0,shadow:{color:"rgba(0, 255, 255, 0.35)",offsetX:0,offsetY:0,blur:20},fontFamily:'"Orbitron", "Exo 2", sans-serif',textColor:"#00ffff",textSecondaryColor:"rgba(0, 255, 255, 0.6)",titleFontSize:11,titleFontWeight:700,contentFontSize:10,lineHeight:1.4,padding:{top:8,right:12,bottom:8,left:12},itemGap:4,headerGap:6,showSeriesIndicator:!0,seriesIndicatorSize:6,showHeaderSeparator:!0,separatorColor:"rgba(0, 255, 255, 0.3)",showArrow:!1,arrowSize:0},minimal:{backgroundColor:"rgba(30, 35, 45, 0.9)",borderColor:"transparent",borderWidth:0,borderRadius:4,backdropBlur:8,shadow:{color:"rgba(0, 0, 0, 0.3)",offsetX:0,offsetY:2,blur:8},fontFamily:"Inter, system-ui, sans-serif",textColor:"#ffffff",textSecondaryColor:"rgba(255, 255, 255, 0.7)",titleFontSize:10,titleFontWeight:500,contentFontSize:10,lineHeight:1.3,padding:{top:6,right:8,bottom:6,left:8},itemGap:2,headerGap:4,showSeriesIndicator:!1,seriesIndicatorSize:0,showHeaderSeparator:!1,separatorColor:"transparent",showArrow:!1,arrowSize:0}};function mi(o){const e=pt[o];return e||(console.warn(`[Tooltip] Unknown theme "${o}", using dark`),pe)}function yi(o,e){const t=typeof o=="string"?mi(o):o;return{...t,...e,padding:{...t.padding,...e.padding},shadow:{...t.shadow,...e.shadow}}}function te(o){switch(o.toLowerCase()){case"light":return ut;case"midnight":return dt;case"electrochemistry":case"electrochem":return ft;case"dark":default:return pe}}const bi=pe,xi={offset:{x:12,y:12},preferredPosition:"auto",constrainToPlotArea:!0,constrainToContainer:!0,autoFlip:!0,showArrow:!0,arrowSize:6};class vi{constructor(e={}){p(this,"config");p(this,"containerWidth",0);p(this,"containerHeight",0);p(this,"plotArea",null);this.config={...xi,...e}}setContainerSize(e,t){this.containerWidth=e,this.containerHeight=t}setPlotArea(e){this.plotArea=e}configure(e){this.config={...this.config,...e}}calculatePosition(e,t,i){const{offset:n,preferredPosition:r,autoFlip:s,showArrow:a,arrowSize:l}=this.config,c=i.width+i.padding.left+i.padding.right,h=i.height+i.padding.top+i.padding.bottom;let u=this.determinePosition(e,t,c,h,r),{x:d,y:f,arrowPosition:g}=this.calculateCoordinates(e,t,c,h,u,n,a?l:0),m=!1;if(s&&!this.fitsInBounds(d,f,c,h)){const v=this.flipPosition(u),S=this.calculateCoordinates(e,t,c,h,v,n,a?l:0);this.fitsInBounds(S.x,S.y,c,h)&&(d=S.x,f=S.y,g=S.arrowPosition,m=!0)}const y=this.constrainToBounds(d,f,c,h);let b=0;if(a){if(g==="top"||g==="bottom"){const v=e-y.x;b=Math.max(l+4,Math.min(c-l-4,v))}else if(g==="left"||g==="right"){const v=t-y.y;b=Math.max(l+4,Math.min(h-l-4,v))}}return{x:y.x,y:y.y,arrowPosition:a?g:"none",arrowOffset:b,wasFlipped:m}}determinePosition(e,t,i,n,r){if(r!=="auto")return r;const s=this.getConstraintBounds(),a=t-s.top,l=s.bottom-t,c=e-s.left,h=s.right-e,u=a>=n+this.config.offset.y,d=l>=n+this.config.offset.y,f=h>=i+this.config.offset.x,g=c>=i+this.config.offset.x;return u&&a>=l?"top":d?"bottom":f&&h>=c?"right":g?"left":[{pos:"top",space:a},{pos:"bottom",space:l},{pos:"right",space:h},{pos:"left",space:c}].sort((y,b)=>b.space-y.space)[0].pos}calculateCoordinates(e,t,i,n,r,s,a){let l,c,h;switch(r){case"top":l=e-i/2,c=t-n-s.y-a,h="bottom";break;case"bottom":l=e-i/2,c=t+s.y+a,h="top";break;case"right":l=e+s.x+a,c=t-n/2,h="left";break;case"left":l=e-i-s.x-a,c=t-n/2,h="right";break}return{x:l,y:c,arrowPosition:h}}flipPosition(e){switch(e){case"top":return"bottom";case"bottom":return"top";case"left":return"right";case"right":return"left"}}fitsInBounds(e,t,i,n){const r=this.getConstraintBounds();return e>=r.left&&t>=r.top&&e+i<=r.right&&t+n<=r.bottom}constrainToBounds(e,t,i,n){const r=this.getConstraintBounds(),s=4;let a=e,l=t;return a<r.left+s?a=r.left+s:a+i>r.right-s&&(a=r.right-i-s),l<r.top+s?l=r.top+s:l+n>r.bottom-s&&(l=r.bottom-n-s),{x:a,y:l}}getConstraintBounds(){let e={top:0,left:0,right:this.containerWidth,bottom:this.containerHeight};return this.config.constrainToPlotArea&&this.plotArea&&(e={top:Math.max(e.top,this.plotArea.y),left:Math.max(e.left,this.plotArea.x),right:Math.min(e.right,this.plotArea.x+this.plotArea.width),bottom:Math.min(e.bottom,this.plotArea.y+this.plotArea.height)}),e}calculateCrosshairPosition(e,t,i){const{offset:n}=this.config,r=this.getConstraintBounds(),s=i.width+i.padding.left+i.padding.right,a=i.height+i.padding.top+i.padding.bottom;let l=e+n.x,c="left";l+s>r.right-4&&(l=e-s-n.x,c="right");let h=t-a/2;h=Math.max(r.top+4,Math.min(r.bottom-a-4,h));const u=t-h;return{x:l,y:h,arrowPosition:c,arrowOffset:Math.max(8,Math.min(a-8,u)),wasFlipped:c==="right"}}}class Si{constructor(e,t){p(this,"ctx");p(this,"theme");this.ctx=e,this.theme=t}setTheme(e){this.theme=e}render(e,t,i){const n=i.measure(this.ctx,e,this.theme),r=n.width+n.padding.left+n.padding.right,s=n.height+n.padding.top+n.padding.bottom;this.ctx.save(),this.drawBackground(t.x,t.y,r,s,t.arrowPosition||"none"),t.arrowPosition&&t.arrowPosition!=="none"&&this.drawArrow(t.x,t.y,r,s,t.arrowPosition,t.arrowOffset||0),i.render(this.ctx,e,t,this.theme),this.ctx.restore()}drawBackground(e,t,i,n,r){const{ctx:s,theme:a}=this,l=a.borderRadius;if(s.save(),a.shadow.blur>0&&(s.shadowColor=a.shadow.color,s.shadowOffsetX=a.shadow.offsetX,s.shadowOffsetY=a.shadow.offsetY,s.shadowBlur=a.shadow.blur),s.beginPath(),this.roundRect(e,t,i,n,l),a.backgroundGradient){const c=s.createLinearGradient(e,t,e,t+n);c.addColorStop(0,a.backgroundColor),c.addColorStop(1,a.backgroundGradient),s.fillStyle=c}else s.fillStyle=a.backgroundColor;s.fill(),s.shadowColor="transparent",a.borderWidth>0&&(s.strokeStyle=a.borderColor,s.lineWidth=a.borderWidth,s.stroke()),s.restore()}drawArrow(e,t,i,n,r,s){const{ctx:a,theme:l}=this,c=l.arrowSize;if(!(c<=0||r==="none")){switch(a.save(),a.fillStyle=l.backgroundColor,a.strokeStyle=l.borderColor,a.lineWidth=l.borderWidth,a.beginPath(),r){case"top":const h=e+s;a.moveTo(h-c,t),a.lineTo(h,t-c),a.lineTo(h+c,t);break;case"bottom":const u=e+s,d=t+n;a.moveTo(u-c,d),a.lineTo(u,d+c),a.lineTo(u+c,d);break;case"left":const f=t+s;a.moveTo(e,f-c),a.lineTo(e-c,f),a.lineTo(e,f+c);break;case"right":const g=e+i,m=t+s;a.moveTo(g,m-c),a.lineTo(g+c,m),a.lineTo(g,m+c);break}a.closePath(),a.fill(),l.borderWidth>0&&a.stroke(),a.restore()}}roundRect(e,t,i,n,r){const{ctx:s}=this,a=Math.min(r,i/2,n/2);s.moveTo(e+a,t),s.lineTo(e+i-a,t),s.arcTo(e+i,t,e+i,t+a,a),s.lineTo(e+i,t+n-a),s.arcTo(e+i,t+n,e+i-a,t+n,a),s.lineTo(e+a,t+n),s.arcTo(e,t+n,e,t+n-a,a),s.lineTo(e,t+a),s.arcTo(e,t,e+a,t,a),s.closePath()}drawSeparator(e,t,i){const{ctx:n,theme:r}=this;r.showHeaderSeparator&&(n.save(),n.strokeStyle=r.separatorColor,n.lineWidth=1,n.beginPath(),n.moveTo(e,t),n.lineTo(e+i,t),n.stroke(),n.restore())}drawSeriesIndicator(e,t,i){const{ctx:n,theme:r}=this;if(!r.showSeriesIndicator)return;const a=r.seriesIndicatorSize/2;n.save(),n.fillStyle=i,n.beginPath(),n.arc(e+a,t,a,0,Math.PI*2),n.fill(),n.restore()}measureText(e,t,i=400){const{ctx:n,theme:r}=this;return n.font=`${i} ${t}px ${r.fontFamily}`,n.measureText(e).width}drawText(e,t,i,n={}){const{ctx:r,theme:s}=this,{fontSize:a=s.contentFontSize,fontWeight:l=400,color:c=s.textColor,align:h="left",baseline:u="top"}=n;r.save(),r.font=`${l} ${a}px ${s.fontFamily}`,r.fillStyle=c,r.textAlign=h,r.textBaseline=u,r.fillText(e,t,i),r.restore()}drawLabelValue(e,t,i,n,r){const{theme:s}=this;this.drawText(i,e,t,{color:s.textSecondaryColor,fontSize:s.contentFontSize}),this.drawText(n,e+r,t,{color:s.textColor,fontSize:s.contentFontSize,align:"right"})}getTheme(){return this.theme}}function N(o,e=4){const t=Math.abs(o);return t!==0&&(t<1e-4||t>=1e4)?o.toExponential(2):t<.01?o.toPrecision(e):t<1?o.toFixed(4):t<100?o.toFixed(3):o.toFixed(1)}class wi{constructor(){p(this,"id","default");p(this,"name","Default Data Point");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const r=e.measureText(t.seriesName).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const s=35,a=e.measureText(N(t.dataX)).width,l=e.measureText(N(t.dataY)).width;let c=s+Math.max(a,l),h=i.contentFontSize*i.lineHeight*2;if(t.yError){const g=`± ${N(t.yError[0])} / ${N(t.yError[1])}`;c=Math.max(c,e.measureText(g).width),h+=i.contentFontSize*i.lineHeight}if(t.cycle!==void 0){const g=`Cycle: ${t.cycle}`;c=Math.max(c,e.measureText(g).width),h+=i.contentFontSize*i.lineHeight}const u=i.showSeriesIndicator?i.seriesIndicatorSize+6:0,d=Math.max(r+u,c),f=i.titleFontSize*i.lineHeight+i.headerGap+h;return this.cachedMeasurement={width:d+2,height:f+4,padding:i.padding,arrow:i.showArrow?{width:i.arrowSize*2,height:i.arrowSize}:void 0},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n;let l=r+a.left,c=s+a.top;if(e.textAlign="left",e.textBaseline="top",n.showSeriesIndicator){const u=c+n.titleFontSize/2;e.save(),e.fillStyle=t.seriesColor,e.beginPath(),e.arc(l+n.seriesIndicatorSize/2,u,n.seriesIndicatorSize/2,0,Math.PI*2),e.fill(),e.restore(),l+=n.seriesIndicatorSize+6}if(e.save(),e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText(t.seriesName,l,c),e.restore(),c+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const d=this.measure(e,t,n).width;e.save(),e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(r+a.left,c+n.headerGap/2),e.lineTo(r+a.left+d,c+n.headerGap/2),e.stroke(),e.restore()}c+=n.headerGap+2,l=r+a.left,e.save(),e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`,e.fillStyle=n.textSecondaryColor,e.fillText("X:",l,c),e.fillStyle=n.textColor;const h=35;if(e.fillText(N(t.dataX),l+h,c),c+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",l,c),e.fillStyle=n.textColor,e.fillText(N(t.dataY),l+h,c),c+=n.contentFontSize*n.lineHeight+2,t.yError){e.fillStyle=n.textSecondaryColor;const u=`± ${N(t.yError[0])} / +${N(t.yError[1])}`;e.fillText(u,l,c),c+=n.contentFontSize*n.lineHeight}t.cycle!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("Cycle:",l,c),e.fillStyle=n.textColor,e.fillText(String(t.cycle),l+45,c)),e.restore()}}const ge=new wi;function me(o){const e=Math.abs(o);return e===0?"0":e>=1e9?(o/1e9).toFixed(1)+"G":e>=1e6?(o/1e6).toFixed(1)+"M":e>=1e3?(o/1e3).toFixed(1)+"k":e>=1?o.toFixed(2):e>=.001?(o*1e3).toFixed(1)+"m":e>=1e-6?(o*1e6).toFixed(1)+"µ":e>=1e-9?(o*1e9).toFixed(1)+"n":o.toExponential(1)}class Ti{constructor(){p(this,"id","minimal");p(this,"name","Minimal");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}-${i.fontFamily}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.contentFontSize}px ${i.fontFamily}`;const r=`${me(t.dataX)} ▪ ${me(t.dataY)}`,s=e.measureText(r).width;return this.cachedMeasurement={width:s,height:i.contentFontSize*i.lineHeight,padding:{top:6,right:8,bottom:6,left:8}},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const r=i.x+8,s=i.y+6,a=me(t.dataX),l=me(t.dataY);e.save(),e.font=`${n.contentFontSize}px ${n.fontFamily}`,e.textAlign="left",e.textBaseline="top",e.fillStyle=n.textSecondaryColor,e.fillText(a,r,s);const c=e.measureText(a).width;e.fillStyle=t.seriesColor,e.fillText(" ▪ ",r+c,s);const h=e.measureText(" ▪ ").width;e.fillStyle=n.textColor,e.fillText(l,r+c+h,s),e.restore()}}const gt=new Ti;function ye(o){const e=Math.abs(o);return e===0?"0":e!==0&&(e<1e-4||e>=1e4)?o.toExponential(2):e<.01?o.toPrecision(3):e<1?o.toFixed(4):e<100?o.toFixed(3):o.toFixed(1)}class Mi{constructor(){p(this,"id","crosshair");p(this,"name","Multi-Series Crosshair");p(this,"supportedTypes",["crosshair"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.dataX}-${t.interpolatedValues.length}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const r=`⌖ X = ${ye(t.dataX)}`;let s=e.measureText(r).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const a=i.showSeriesIndicator?i.seriesIndicatorSize+8:0,l=60;for(const d of t.interpolatedValues){const f=e.measureText(`${d.seriesName}:`).width,g=e.measureText(ye(d.y)).width,m=a+Math.max(f,l)+g;s=Math.max(s,m)}const c=i.titleFontSize*i.lineHeight,u=t.interpolatedValues.length*(i.contentFontSize*i.lineHeight+2);return this.cachedMeasurement={width:s+4,height:c+i.headerGap+u,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n;let l=s+a.top;const c=r+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=`⌖ X = ${ye(t.dataX)}`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const u=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+u.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;for(const u of t.interpolatedValues){let d=c;if(n.showSeriesIndicator){const m=l+n.contentFontSize/2;e.save(),e.beginPath(),e.arc(d+n.seriesIndicatorSize/2,m,n.seriesIndicatorSize/2,0,Math.PI*2),u.isInterpolated?(e.strokeStyle=u.seriesColor,e.lineWidth=1.5,e.stroke()):(e.fillStyle=u.seriesColor,e.fill()),e.restore(),d+=n.seriesIndicatorSize+8}e.fillStyle=n.textSecondaryColor,e.fillText(`${u.seriesName}:`,d,l);const f=e.measureText(`${u.seriesName}: `).width,g=Math.max(f,60);e.fillStyle=n.textColor,e.fillText(ye(u.y),d+g,l),l+=n.contentFontSize*n.lineHeight+2}e.restore()}}const _e=new Mi;function Y(o){const e=Math.abs(o);return e===0?"0":e!==0&&(e<1e-4||e>=1e4)?o.toExponential(3):e<.01?o.toPrecision(4):e<1?o.toFixed(4):e<100?o.toFixed(3):o.toFixed(2)}class Pi{constructor(){p(this,"id","heatmap");p(this,"name","Heatmap Value");p(this,"supportedTypes",["heatmap"]);p(this,"swatchSize",14);p(this,"swatchGap",8);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.xIndex}-${t.yIndex}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const r=`Grid [${t.xIndex}, ${t.yIndex}]`;let s=e.measureText(r).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const a=`Value: ${Y(t.zValue)}`,l=this.swatchSize+this.swatchGap+e.measureText(a).width;if(s=Math.max(s,l),t.colorScale){const m=`Min: ${Y(t.colorScale.min)} Max: ${Y(t.colorScale.max)}`;s=Math.max(s,this.swatchSize+this.swatchGap+e.measureText(m).width)}const c=25,h=c+e.measureText(Y(t.dataX)).width,u=c+e.measureText(Y(t.dataY)).width;s=Math.max(s,h,u);const d=i.titleFontSize*i.lineHeight,g=(t.colorScale?4:3)*i.contentFontSize*i.lineHeight;return this.cachedMeasurement={width:s+4,height:d+i.headerGap+g+i.itemGap,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n;let l=s+a.top;const c=r+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=`Grid [${t.xIndex}, ${t.yIndex}]`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const f=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+f.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=l+(n.contentFontSize*n.lineHeight-this.swatchSize)/2;e.fillStyle=t.mappedColor||n.textColor,e.fillRect(c,u,this.swatchSize,this.swatchSize),e.strokeStyle=n.separatorColor,e.lineWidth=1,e.strokeRect(c,u,this.swatchSize,this.swatchSize),e.fillStyle=n.textSecondaryColor,e.fillText("Value:",c+this.swatchSize+this.swatchGap,l),e.fillStyle=n.textColor;const d=e.measureText("Value: ").width;if(e.fillText(Y(t.zValue),c+this.swatchSize+this.swatchGap+d,l),l+=n.contentFontSize*n.lineHeight,t.colorScale){e.fillStyle=n.textSecondaryColor,e.font=`400 ${n.contentFontSize-1}px ${n.fontFamily}`;const f=`Min: ${Y(t.colorScale.min)} Max: ${Y(t.colorScale.max)}`;e.fillText(f,c+this.swatchSize+this.swatchGap,l),l+=n.contentFontSize*n.lineHeight}l+=n.itemGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`,e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(Y(t.dataX),c+25,l),l+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor,e.fillText(Y(t.dataY),c+25,l),e.restore()}}const Fe=new Pi;function K(o,e=3){if(o===0)return"0";const t=Math.floor(Math.log10(Math.abs(o))),i=o/Math.pow(10,t);if(Math.abs(t)<=2)return o.toPrecision(e);const n={0:"⁰",1:"¹",2:"²",3:"³",4:"⁴",5:"⁵",6:"⁶",7:"⁷",8:"⁸",9:"⁹","-":"⁻","+":"⁺"},r=t.toString();let s="";for(const a of r)s+=n[a]||a;return`${i.toFixed(e-1)} × 10${s}`}class Ci{constructor(){p(this,"id","scientific");p(this,"name","Scientific Notation");p(this,"supportedTypes",["datapoint"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.seriesId}-${t.dataIndex}-${t.dataX}-${t.dataY}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const r=e.measureText(t.seriesName).width+(i.showSeriesIndicator?i.seriesIndicatorSize+8:0);e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;const s=28,a=K(t.dataX);let l=Math.max(r,s+e.measureText(a).width);const c=K(t.dataY);let h=s+e.measureText(c).width;t.yError&&(h+=e.measureText(` ± ${K(t.yError[0])}`).width),l=Math.max(l,h);let u=`Index: ${t.dataIndex}`;t.cycle!==void 0&&(u+=` │ Cycle: ${t.cycle}`),l=Math.max(l,e.measureText(u).width);let d=3;(t.cycle!==void 0||t.yError)&&(d+=1);const f=i.titleFontSize*i.lineHeight+i.headerGap,g=(d-1)*i.contentFontSize*i.lineHeight,m=t.cycle!==void 0?i.itemGap:0;return this.cachedMeasurement={width:l,height:f+g+m,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n;let l=s+a.top,c=r+a.left;if(e.save(),e.textAlign="left",e.textBaseline="top",n.showSeriesIndicator){const d=l+n.titleFontSize/2;e.fillStyle=t.seriesColor,e.beginPath(),e.arc(c+n.seriesIndicatorSize/2,d,n.seriesIndicatorSize/2,0,Math.PI*2),e.fill(),c+=n.seriesIndicatorSize+8}if(e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText(t.seriesName,c,l),l+=n.titleFontSize*n.lineHeight+2,c=r+a.left,n.showHeaderSeparator){const d=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.lineWidth=1,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+d.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const h=28;e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(K(t.dataX),c+h,l),l+=n.contentFontSize*n.lineHeight+2,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor;let u=K(t.dataY);if(e.fillText(u,c+h,l),t.yError){const d=e.measureText(u).width;e.fillStyle=n.textSecondaryColor,e.fillText(` ± ${K(t.yError[0])}`,c+h+d,l)}if(l+=n.contentFontSize*n.lineHeight+2,t.cycle!==void 0){l+=n.itemGap,e.strokeStyle=n.separatorColor,e.globalAlpha=.3,e.beginPath();const d=this.measure(e,t,n);e.moveTo(c,l-n.itemGap/2),e.lineTo(c+d.width,l-n.itemGap/2),e.stroke(),e.globalAlpha=1,e.fillStyle=n.textSecondaryColor,e.font=`400 ${n.contentFontSize-1}px ${n.fontFamily}`;let f=`Index: ${t.dataIndex}`;t.cycle!==void 0&&(f+=` │ Cycle: ${t.cycle}`),e.fillText(f,c,l)}e.restore()}}const mt=new Ci;function Z(o){const e=Math.abs(o);return e===0?"0":e<1e-4||e>=1e4?o.toExponential(2):e<1?o.toFixed(4):o.toFixed(2)}class ki{constructor(){p(this,"id","annotation");p(this,"name","Annotation Info");p(this,"supportedTypes",["annotation"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=`${t.annotationId}-${t.label}-${i.fontFamily}-${i.titleFontSize}`;if(n===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;const r=t.label||`Annotation: ${t.annotationType}`;let s=e.measureText(r).width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;let a=0;const l=50;if(t.value!==void 0){const h=Z(t.value);s=Math.max(s,l+e.measureText(h).width),a+=i.contentFontSize*i.lineHeight}if(t.valueX!==void 0&&t.valueY!==void 0){const h=Z(t.valueX),u=Z(t.valueY);s=Math.max(s,l+e.measureText(h).width,l+e.measureText(u).width),a+=i.contentFontSize*i.lineHeight*2}const c=i.titleFontSize*i.lineHeight+i.headerGap;return this.cachedMeasurement={width:s+10,height:c+a+4,padding:i.padding},this.cachedKey=n,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n;let l=s+a.top;const c=r+a.left;e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor;const h=t.label||`${t.annotationType.toUpperCase()}`;if(e.fillText(h,c,l),l+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const d=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.globalAlpha=.4,e.beginPath(),e.moveTo(c,l+n.headerGap/2),e.lineTo(c+d.width,l+n.headerGap/2),e.stroke(),e.globalAlpha=1}l+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=50;t.value!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("Value:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.value),c+u,l),l+=n.contentFontSize*n.lineHeight),t.valueX!==void 0&&t.valueY!==void 0&&(e.fillStyle=n.textSecondaryColor,e.fillText("X:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.valueX),c+u,l),l+=n.contentFontSize*n.lineHeight,e.fillStyle=n.textSecondaryColor,e.fillText("Y:",c,l),e.fillStyle=n.textColor,e.fillText(Z(t.valueY),c+u,l)),e.restore()}}const Ie=new ki;function U(o){const e=Math.abs(o);return e===0?"0":e<1e-4||e>=1e4?o.toExponential(3):e<1?o.toFixed(4):o.toFixed(3)}class Ei{constructor(){p(this,"id","range");p(this,"name","Range Statistics");p(this,"supportedTypes",["range"]);p(this,"cachedKey","");p(this,"cachedMeasurement",null)}measure(e,t,i){const n=t.statistics,r=`${t.xMin}-${t.xMax}-${n.count}-${n.mean}-${i.fontFamily}`;if(r===this.cachedKey&&this.cachedMeasurement)return this.cachedMeasurement;e.font=`${i.titleFontWeight} ${i.titleFontSize}px ${i.fontFamily}`;let a=e.measureText("Range Statistics").width;e.font=`400 ${i.contentFontSize}px ${i.fontFamily}`;let l=i.contentFontSize*i.lineHeight*2;const c=[`Range: ${U(t.xMin)} to ${U(t.xMax)}`,`Count: ${n.count}`];n.min!==void 0&&c.push(`Min: ${U(n.min)}`),n.max!==void 0&&c.push(`Max: ${U(n.max)}`),n.mean!==void 0&&c.push(`Mean: ${U(n.mean)}`),n.area!==void 0&&c.push(`Area: ${U(n.area)}`);for(const u of c)a=Math.max(a,e.measureText(u).width+10);l=c.length*i.contentFontSize*i.lineHeight;const h=i.titleFontSize*i.lineHeight+i.headerGap;return this.cachedMeasurement={width:Math.max(a,140),height:h+l+10,padding:i.padding},this.cachedKey=r,this.cachedMeasurement}render(e,t,i,n){const{x:r,y:s}=i,{padding:a}=n,l=t.statistics;let c=s+a.top;const h=r+a.left;if(e.save(),e.textAlign="left",e.textBaseline="top",e.font=`${n.titleFontWeight} ${n.titleFontSize}px ${n.fontFamily}`,e.fillStyle=n.textColor,e.fillText("Range Statistics",h,c),c+=n.titleFontSize*n.lineHeight+2,n.showHeaderSeparator){const f=this.measure(e,t,n);e.strokeStyle=n.separatorColor,e.globalAlpha=.4,e.beginPath(),e.moveTo(h,c+n.headerGap/2),e.lineTo(h+f.width,c+n.headerGap/2),e.stroke(),e.globalAlpha=1}c+=n.headerGap+2,e.font=`400 ${n.contentFontSize}px ${n.fontFamily}`;const u=60,d=(f,g)=>{e.fillStyle=n.textSecondaryColor,e.fillText(f,h,c),e.fillStyle=n.textColor,e.fillText(String(g),h+u,c),c+=n.contentFontSize*n.lineHeight};d("Points:",l.count),l.min!==void 0&&d("Min:",U(l.min)),l.max!==void 0&&d("Max:",U(l.max)),l.mean!==void 0&&d("Mean:",U(l.mean)),l.stdDev!==void 0&&d("StdDev:",U(l.stdDev)),l.area!==void 0&&d("Area:",U(l.area)),l.peakX!==void 0&&(c+=4,e.fillStyle=n.textSecondaryColor,e.font=`italic ${n.contentFontSize-1}px ${n.fontFamily}`,e.fillText(`Peak: ${U(l.peakY??0)} at X=${U(l.peakX)}`,h,c)),e.restore()}}const Re=new Ei,Bi=[ge,gt,_e,Fe,mt,Ie,Re];function Ai(o){return Bi.find(e=>e.id===o)}function yt(o){switch(o){case"datapoint":return ge;case"crosshair":return _e;case"heatmap":return Fe;case"annotation":return Ie;case"range":return Re;default:return ge}}class bt{constructor(e){p(this,"ctx");p(this,"getPlotArea");p(this,"getSeries");p(this,"pixelToDataX");p(this,"pixelToDataY");p(this,"getXScale");p(this,"getYScales");p(this,"options");p(this,"theme");p(this,"positioner");p(this,"renderer");p(this,"templates",new Map);p(this,"events",new Pe);p(this,"activeTooltips",new Map);p(this,"tooltipIdCounter",0);p(this,"showTimeoutId",null);p(this,"hideTimeoutId",null);p(this,"lastCursorX",null);p(this,"lastCursorY",null);p(this,"hoveredSeriesId",null);p(this,"hoveredDataIndex",null);p(this,"cachedNearestResult",null);p(this,"snapMode","auto");p(this,"largeDatasetThreshold",5e4);p(this,"lastKnownDataSize",0);p(this,"hysteresisRatio",2);var t;this.ctx=e.overlayCtx,this.getPlotArea=e.getPlotArea,this.getSeries=e.getSeries,this.pixelToDataX=e.pixelToDataX,this.pixelToDataY=e.pixelToDataY,this.getXScale=e.getXScale,this.getYScales=e.getYScales,this.options={enabled:!0,showDelay:50,hideDelay:100,followCursor:!1,offset:{x:12,y:12},dataPoint:{enabled:!0,templateId:"default",snapToPoint:!0,hitRadius:20},crosshair:{enabled:!1,templateId:"crosshair",interpolate:!0,visibleSeriesOnly:!0},range:{enabled:!1,templateId:"default",calculateStats:!0},annotation:{enabled:!0,templateId:"default"},heatmap:{enabled:!0,templateId:"heatmap",showColorInfo:!0},positioning:"auto",preferredPosition:"auto",constrainToPlotArea:!0,constrainToContainer:!0,autoFlip:!0},e.options&&this.configure(e.options),this.theme=(t=e.options)!=null&&t.theme?typeof e.options.theme=="string"?te(e.options.theme):yi(bi,e.options.theme):te(e.chartTheme.name),this.positioner=new vi({offset:this.options.offset,preferredPosition:this.options.preferredPosition,constrainToPlotArea:this.options.constrainToPlotArea,constrainToContainer:this.options.constrainToContainer,autoFlip:this.options.autoFlip,showArrow:this.theme.showArrow,arrowSize:this.theme.arrowSize}),this.renderer=new Si(this.ctx,this.theme),this.registerBuiltinTemplates()}registerBuiltinTemplates(){this.templates.set("default",ge),this.templates.set("minimal",gt),this.templates.set("crosshair",_e),this.templates.set("heatmap",Fe),this.templates.set("scientific",mt),this.templates.set("annotation",Ie),this.templates.set("range",Re)}configure(e){e.enabled!==void 0&&(this.options.enabled=e.enabled),e.showDelay!==void 0&&(this.options.showDelay=e.showDelay),e.hideDelay!==void 0&&(this.options.hideDelay=e.hideDelay),e.followCursor!==void 0&&(this.options.followCursor=e.followCursor),e.offset&&(this.options.offset={...this.options.offset,...e.offset}),e.dataPoint&&(this.options.dataPoint={...this.options.dataPoint,...e.dataPoint}),e.crosshair&&(this.options.crosshair={...this.options.crosshair,...e.crosshair}),e.heatmap&&(this.options.heatmap={...this.options.heatmap,...e.heatmap}),e.preferredPosition&&(this.options.preferredPosition=e.preferredPosition),e.constrainToPlotArea!==void 0&&(this.options.constrainToPlotArea=e.constrainToPlotArea),e.constrainToContainer!==void 0&&(this.options.constrainToContainer=e.constrainToContainer),e.autoFlip!==void 0&&(this.options.autoFlip=e.autoFlip),e.snapMode!==void 0&&(this.snapMode=e.snapMode),e.largeDatasetThreshold!==void 0&&(this.largeDatasetThreshold=Math.max(1e3,e.largeDatasetThreshold)),this.positioner.configure({offset:this.options.offset,preferredPosition:this.options.preferredPosition,constrainToPlotArea:this.options.constrainToPlotArea,constrainToContainer:this.options.constrainToContainer,autoFlip:this.options.autoFlip})}getOptions(){return{...this.options}}setEnabled(e){this.options.enabled=e,e||this.hideAll()}isEnabled(){return this.options.enabled}setTheme(e){this.theme=typeof e=="string"?te(e):e,this.renderer.setTheme(this.theme),this.positioner.configure({showArrow:this.theme.showArrow,arrowSize:this.theme.arrowSize})}updateChartTheme(e){this.options.theme||(this.theme=te(e.name),this.renderer.setTheme(this.theme))}getTheme(){return this.theme}registerTemplate(e){this.templates.set(e.id,e)}getTemplate(e){return this.templates.get(e)||Ai(e)}handleCursorMove(e,t){if(!this.options.enabled)return;this.lastCursorX=e,this.lastCursorY=t;const i=this.getPlotArea();if(!(e>=i.x&&e<=i.x+i.width&&t>=i.y&&t<=i.y+i.height)){this.cachedNearestResult=null,this.scheduleHide();return}this.positioner.setContainerSize(this.ctx.canvas.width/(window.devicePixelRatio||1),this.ctx.canvas.height/(window.devicePixelRatio||1)),this.positioner.setPlotArea(i),this.lastKnownDataSize=this.getTotalDataPoints(),this.performTooltipUpdateWithHysteresis(e,t)}handleCursorLeave(){this.lastCursorX=null,this.lastCursorY=null,this.cachedNearestResult=null,this.scheduleHide()}getTotalDataPoints(){let e=0;const t=this.getSeries();for(const i of t){if(!i.isVisible())continue;const n=i.getData();n.x&&(e+=n.x.length)}return e}getEffectiveSnapMode(){return this.snapMode==="x-only"?"x-only":this.snapMode==="nearest"?"nearest":this.lastKnownDataSize>this.largeDatasetThreshold?"x-only":"nearest"}performTooltipUpdateWithHysteresis(e,t){var r;if(!((r=this.options.dataPoint)!=null&&r.enabled)){this.performFallbackTooltipUpdate(e,t);return}const n=this.getEffectiveSnapMode()==="x-only"?this.findDataPointByXOnly(e):this.findNearestDataPointOptimized(e,t);if(!n){this.performFallbackTooltipUpdate(e,t);return}if(this.cachedNearestResult&&this.hoveredSeriesId!==null){const s=this.cachedNearestResult,a=s.pixelX-e,l=s.pixelY-t,c=a*a+l*l,h=n.pixelX-e,u=n.pixelY-t;if((h*h+u*u)*this.hysteresisRatio>=c){this.updateTooltipPosition(this.cachedNearestResult);return}}this.cachedNearestResult=n,this.scheduleShow(n)}performFallbackTooltipUpdate(e,t){var i,n;if((i=this.options.heatmap)!=null&&i.enabled){const r=this.findHeatmapCell(e,t);if(r){this.scheduleShow(r);return}}if((n=this.options.crosshair)!=null&&n.enabled){const r=this.buildCrosshairTooltip(e,t);if(r){this.scheduleShow(r);return}}this.cachedNearestResult=null,this.scheduleHide()}findDataPointByXOnly(e){var l,c;const t=this.getSeries().filter(h=>h.isVisible()&&h.getType()!=="heatmap");if(t.length===0)return null;const i=this.getXScale(),n=this.getYScales(),r=this.pixelToDataX(e);let s=null,a=1/0;for(const h of t){const u=h.getData();if(!u.x||u.x.length===0)continue;const d=n.get(((l=h.getYAxisId)==null?void 0:l.call(h))||"default")||n.values().next().value;if(!d)continue;const f=this.binarySearchClosest(u.x,r),g=Math.abs(u.x[f]-r);if(g<a){a=g;const m=h.getStyle(),y=i.transform(u.x[f]),b=d.transform(u.y[f]);s={type:"datapoint",seriesId:h.getId(),seriesName:h.getId(),seriesColor:m.color||"#ff0055",dataIndex:f,dataX:u.x[f],dataY:u.y[f],pixelX:y,pixelY:b,cycle:(c=h.getCycle)==null?void 0:c.call(h)};const v=h.getYError(f);v&&(s.yError=v)}}return s}findNearestDataPointOptimized(e,t){var h,u,d;const i=this.getSeries().filter(f=>f.isVisible()),n=((h=this.options.dataPoint)==null?void 0:h.hitRadius)??20,r=this.getXScale(),s=this.getYScales();let a=n*n,l=null;const c=this.pixelToDataX(e);for(const f of i){if(f.getType()==="heatmap")continue;const g=f.getData(),m=s.get(((u=f.getYAxisId)==null?void 0:u.call(f))||"default")||s.values().next().value;if(!m||!g.x||g.x.length===0)continue;const y=this.binarySearchClosest(g.x,c),b=g.x.length,v=b>1e5?2:b>1e4?3:5,S=Math.max(0,y-v),T=Math.min(b,y+v+1);for(let P=S;P<T;P++){const M=r.transform(g.x[P]),_=m.transform(g.y[P]),B=M-e,R=_-t,G=B*B+R*R;if(G<a){a=G;const k=f.getStyle();l={type:"datapoint",seriesId:f.getId(),seriesName:f.getId(),seriesColor:k.color||"#ff0055",dataIndex:P,dataX:g.x[P],dataY:g.y[P],pixelX:M,pixelY:_,cycle:(d=f.getCycle)==null?void 0:d.call(f)};const F=f.getYError(P);F&&(l.yError=F)}}}return l}findHeatmapCell(e,t){var l,c;const i=this.getSeries().filter(h=>h.isVisible()&&h.getType()==="heatmap");if(i.length===0)return null;const n=this.getXScale(),r=this.getYScales(),s=this.pixelToDataX(e),a=this.pixelToDataY(t);for(const h of i){const u=h.getHeatmapData();if(!u||!u.xValues||!u.yValues||!u.zValues)continue;const d=this.binarySearchClosest(u.xValues,s),f=this.binarySearchClosest(u.yValues,a),g=u.xValues[d],m=u.yValues[f],y=r.get(((l=h.getYAxisId)==null?void 0:l.call(h))||"default")||r.values().next().value;if(!y)continue;const b=n.transform(g),v=y.transform(m),S=u.zValues[f*u.xValues.length+d],T=((c=h.getHeatmapStyle)==null?void 0:c.call(h))||{};return{type:"heatmap",seriesId:h.getId(),seriesName:h.getId(),xIndex:d,yIndex:f,dataX:g,dataY:m,zValue:S,pixelX:b,pixelY:v,colorScale:T.colorScale}}return null}binarySearchClosest(e,t){let i=0,n=e.length-1;for(;i<n;){const r=Math.floor((i+n)/2);e[r]<t?i=r+1:n=r}return i>0&&Math.abs(e[i-1]-t)<Math.abs(e[i]-t)?i-1:i}buildCrosshairTooltip(e,t){var a,l;const i=this.getSeries().filter(c=>c.isVisible()&&c.getType()!=="heatmap");if(i.length===0)return null;const n=this.pixelToDataX(e),r=this.getYScales(),s=[];for(const c of i){const h=c.getData();if(!h.x||h.x.length===0||!(r.get(((a=c.getYAxisId)==null?void 0:a.call(c))||"default")||r.values().next().value))continue;const d=this.binarySearchClosest(h.x,n);let f,g=!1;if(d===0||d>=h.x.length-1||h.x[d]===n)f=h.y[d];else if((l=this.options.crosshair)!=null&&l.interpolate){const y=h.x[d-1],b=h.x[d],v=h.y[d-1],S=h.y[d],T=(n-y)/(b-y);f=v+T*(S-v),g=!0}else f=h.y[d];const m=c.getStyle();s.push({seriesId:c.getId(),seriesName:c.getId(),seriesColor:m.color||"#ff0055",x:n,y:f,isInterpolated:g})}return s.length===0?null:{type:"crosshair",cursorX:e,cursorY:t,dataX:n,interpolatedValues:s}}scheduleShow(e){if(this.clearHideTimeout(),e.type==="datapoint"){const i=e;if(this.hoveredSeriesId===i.seriesId&&this.hoveredDataIndex===i.dataIndex){this.updateTooltipPosition(e);return}this.hoveredSeriesId=i.seriesId,this.hoveredDataIndex=i.dataIndex}this.clearShowTimeout();const t=this.activeTooltips.size>0?0:this.options.showDelay;t>0?this.showTimeoutId=window.setTimeout(()=>{this.showTooltip(e)},t):this.showTooltip(e)}scheduleHide(){this.clearShowTimeout(),this.hoveredSeriesId=null,this.hoveredDataIndex=null,this.options.hideDelay>0?this.hideTimeoutId=window.setTimeout(()=>{this.hideAll()},this.options.hideDelay):this.hideAll()}clearShowTimeout(){this.showTimeoutId!==null&&(clearTimeout(this.showTimeoutId),this.showTimeoutId=null)}clearHideTimeout(){this.hideTimeoutId!==null&&(clearTimeout(this.hideTimeoutId),this.hideTimeoutId=null)}showTooltip(e){const t=this.getTemplateIdForType(e.type),i=this.templates.get(t)||yt(e.type),n=e.pixelX??this.lastCursorX??0,r=e.pixelY??this.lastCursorY??0,s=i.measure(this.ctx,e,this.theme),a=this.positioner.calculatePosition(n,r,s),l="main";this.activeTooltips.set(l,{id:l,data:e,position:a,template:i})}updateTooltipPosition(e){const t=this.activeTooltips.get("main");if(!t)return;const i=e||t.data,n=i.pixelX??this.lastCursorX??0,r=i.pixelY??this.lastCursorY??0,s=t.template.measure(this.ctx,i,this.theme);t.position=this.positioner.calculatePosition(n,r,s),t.data=i}getTemplateIdForType(e){var t,i,n;switch(e){case"datapoint":return((t=this.options.dataPoint)==null?void 0:t.templateId)||"default";case"crosshair":return((i=this.options.crosshair)==null?void 0:i.templateId)||"crosshair";case"heatmap":return((n=this.options.heatmap)==null?void 0:n.templateId)||"heatmap";default:return"default"}}show(e,t){const i=`tooltip-${++this.tooltipIdCounter}`,n=(t==null?void 0:t.templateId)||this.getTemplateIdForType(e.type),r=this.templates.get(n)||yt(e.type);let s;if(t!=null&&t.position){const a=r.measure(this.ctx,e,this.theme);s=this.positioner.calculatePosition(t.position.x,t.position.y,a)}else{const a=e.pixelX??0,l=e.pixelY??0,c=r.measure(this.ctx,e,this.theme);s=this.positioner.calculatePosition(a,l,c)}return this.activeTooltips.set(i,{id:i,data:e,position:s,template:r}),t!=null&&t.duration&&t.duration>0&&setTimeout(()=>this.hide(i),t.duration),i}hide(e){this.activeTooltips.delete(e)}hideAll(){this.activeTooltips.clear(),this.hoveredSeriesId=null,this.hoveredDataIndex=null}render(){if(!(!this.options.enabled||this.activeTooltips.size===0))for(const e of this.activeTooltips.values())this.renderer.render(e.data,e.position,e.template)}hasActiveTooltip(){return this.activeTooltips.size>0}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}destroy(){this.clearShowTimeout(),this.clearHideTimeout(),this.activeTooltips.clear(),this.templates.clear(),this.events.clear()}}function _i(o,e){const{seriesIds:t,includeHeaders:i=!0,precision:n=6,delimiter:r=","}=e??{},s=t?o.filter(c=>t.includes(c.getId())):o;if(s.length===0)return"";const a=[];if(i){const c=[];s.forEach(h=>{c.push(`${h.getId()}_x`,`${h.getId()}_y`)}),a.push(c.join(r))}const l=Math.max(...s.map(c=>c.getPointCount()));for(let c=0;c<l;c++){const h=[];s.forEach(u=>{const d=u.getData();d&&c<d.x.length?h.push(d.x[c].toFixed(n),d.y[c].toFixed(n)):h.push("","")}),a.push(h.join(r))}return a.join(`
|
|
181
|
+
`)}function Fi(o,e,t){const{seriesIds:i,precision:n=6}=t??{},r=i?o.filter(a=>i.includes(a.getId())):o,s={};return r.forEach(a=>{const l=a.getData();s[a.getId()]={id:a.getId(),type:a.getType(),style:a.getStyle(),data:{x:l?Array.from(l.x).map(c=>parseFloat(c.toFixed(n))):[],y:l?Array.from(l.y).map(c=>parseFloat(c.toFixed(n))):[]},pointCount:a.getPointCount()}}),JSON.stringify({exportDate:new Date().toISOString(),chartBounds:e,series:s},null,2)}function Ii(o,e,t,i,n,r,s="png"){const a=document.createElement("canvas");a.width=e.width,a.height=e.height;const l=a.getContext("2d");if(!l)return"";const c=t;return l.fillStyle=`rgba(${Math.round(c[0]*255)}, ${Math.round(c[1]*255)}, ${Math.round(c[2]*255)}, ${c[3]})`,l.fillRect(0,0,a.width,a.height),l.drawImage(o,0,0),l.drawImage(e,0,0),i&&n&&i.draw(l,r),a.toDataURL(`image/${s}`)}function Ri(o,e){e.x&&(o.viewBounds.xMin=e.x[0],o.viewBounds.xMax=e.x[1]);const t=Array.from(o.series.values()).some(n=>n.isVisible()&&n.getType()==="bar"),i=e.y?[...e.y]:null;if(i&&t&&(i[0]=0),i)if(e.axisId){const n=o.yScales.get(e.axisId);n&&(n.setDomain(i[0],i[1]),e.axisId===o.primaryYAxisId&&(o.viewBounds.yMin=i[0],o.viewBounds.yMax=i[1]))}else{const n=o.viewBounds.yMax-o.viewBounds.yMin,r=i[1]-i[0],s=n>0?r/n:1,a=n>0?(i[0]-o.viewBounds.yMin)/n:0;o.yScales.forEach((l,c)=>{if(c===o.primaryYAxisId)return;const h=l.domain[1]-l.domain[0],u=t?0:l.domain[0]+a*h,d=t?l.domain[0]+i[1]/(o.viewBounds.yMax||1)*h:u+s*h;l.setDomain(u,d)}),o.viewBounds.yMin=i[0],o.viewBounds.yMax=i[1]}o.events.emit("zoom",{x:[o.viewBounds.xMin,o.viewBounds.xMax],y:[o.viewBounds.yMin,o.viewBounds.yMax]}),o.requestRender()}function Di(o,e,t,i){const n=o.getPlotArea(),r=e/n.width*(o.viewBounds.xMax-o.viewBounds.xMin);if(o.viewBounds.xMin-=r,o.viewBounds.xMax-=r,i){const a=o.yScales.get(i);if(a){const l=Array.from(o.series.values()).some(f=>f.isVisible()&&f.getType()==="bar"),c=a.domain[1]-a.domain[0],h=t/n.height*c;let u=a.domain[0]+h,d=a.domain[1]+h;l&&(u=0,d=a.domain[1]+h),a.setDomain(u,d),i===o.primaryYAxisId&&(o.viewBounds.yMin=u,o.viewBounds.yMax=d)}}else{const a=Array.from(o.series.values()).some(l=>l.isVisible()&&l.getType()==="bar");o.yScales.forEach((l,c)=>{const h=l.domain[1]-l.domain[0],u=t/n.height*h;let d=l.domain[0]+u,f=l.domain[1]+u;a&&(d=0),l.setDomain(d,f),c===o.primaryYAxisId&&(o.viewBounds.yMin=d,o.viewBounds.yMax=f)})}const s=t/n.height*(o.viewBounds.yMax-o.viewBounds.yMin);o.events.emit("pan",{deltaX:r,deltaY:s}),o.requestRender()}function Li(o){if(o.series.size===0)return;let e=1/0,t=-1/0;const i=new Map;o.yScales.forEach((a,l)=>{i.set(l,{min:1/0,max:-1/0})});let n=!1;if(o.series.forEach(a=>{if(!a.isVisible())return;const l=a.getBounds();if(l&&isFinite(l.xMin)&&isFinite(l.xMax)&&isFinite(l.yMin)&&isFinite(l.yMax)){e=Math.min(e,l.xMin),t=Math.max(t,l.xMax);const c=a.getYAxisId()||o.primaryYAxisId,h=i.get(c);h&&(h.min=Math.min(h.min,l.yMin),h.max=Math.max(h.max,l.yMax)),n=!0}}),!n)return;const r=1e15,s=-1e15;if(o.xAxisOptions.auto){let a=t-e;(a<=0||!isFinite(a))&&(a=Math.abs(e)*.1||1);const l=Math.min(a*.05,1e10);o.viewBounds.xMin=Math.max(s,e-l),o.viewBounds.xMax=Math.min(r,t+l)}i.forEach((a,l)=>{if(a.min===1/0)return;const c=o.yAxisOptionsMap.get(l),h=o.yScales.get(l);if(c&&c.auto&&h){let u=a.max-a.min;(u<=0||!isFinite(u))&&(u=Math.abs(a.min)*.1||1);const d=Math.min(u*.05,1e10);let f=Math.max(s,a.min-d);const g=Math.min(r,a.max+d);h.setDomain(f,g),l===o.primaryYAxisId&&(o.viewBounds.yMin=f,o.viewBounds.yMax=g)}}),o.requestRender()}function zi(o,e,t,i){if(e===null){if(t&&t.width>5&&t.height>5){const n=o.getPlotArea(),r=o.viewBounds,s=(t.x-n.x)/n.width,a=(t.x+t.width-n.x)/n.width,l=1-(t.y-n.y)/n.height,c=1-(t.y+t.height-n.y)/n.height,h=r.xMin+s*(r.xMax-r.xMin),u=r.xMin+a*(r.xMax-r.xMin),d=r.yMin+c*(r.yMax-r.yMin),f=r.yMin+l*(r.yMax-r.yMin);i({x:[h,u],y:[d,f]})}return null}return e}function Gi(o,e){const t=[];return o.xScale.setRange(e.x,e.x+e.width),o.xScale.setDomain(o.viewBounds.xMin,o.viewBounds.xMax),o.yScales.forEach((i,n)=>{i.setRange(e.y+e.height,e.y),n===o.primaryYAxisId&&i.setDomain(o.viewBounds.yMin,o.viewBounds.yMax)}),o.series.forEach(i=>{var s,a;i.needsBufferUpdate&&(o.updateSeriesBuffer(i),i.needsBufferUpdate=!1);const n=o.renderer.getBuffer(i.getId()),r=i.getType();if(n||r==="candlestick"){const l=i.getYAxisId()||o.primaryYAxisId,c=o.yScales.get(l);let h;c&&(h={min:c.domain[0],max:c.domain[1]});const u=r==="area"?"band":r;let d=null;if(n&&(d={id:i.getId(),buffer:n,count:i.getPointCount(),style:i.getStyle(),visible:i.isVisible(),type:u,yBounds:h}),d){if(r==="band"||r==="area"?d.count=i.getPointCount()*2:r==="bar"&&(d.count=i.getPointCount()*6),r==="step"||r==="step+scatter"){const f=o.renderer.getBuffer(`${i.getId()}_step`);if(f){d.stepBuffer=f;const g=i.getStyle().stepMode??"after",m=i.getPointCount();g==="center"?d.stepCount=1+(m-1)*3:d.stepCount=m*2-1}}if(r==="heatmap"){const f=i.getHeatmapData(),g=i.getHeatmapStyle();if(f){const m=f.xValues.length,y=f.yValues.length;d.count=(m-1)*(y-1)*6;let b=1/0,v=-1/0;for(let T=0;T<f.zValues.length;T++){const P=f.zValues[T];P<b&&(b=P),P>v&&(v=P)}b===v&&(b-=1,v+=1),d.zBounds={min:((s=g==null?void 0:g.colorScale)==null?void 0:s.min)??(b===1/0?0:b),max:((a=g==null?void 0:g.colorScale)==null?void 0:a.max)??(v===-1/0?1:v)},d.zBounds.min===d.zBounds.max&&(d.zBounds.max=d.zBounds.min+1);const S=`${i.getId()}_colormap`;d.colormapTexture=o.renderer.getTexture(S)}}}if(r==="candlestick"){const f=o.renderer.getBuffer(`${i.getId()}_bullish`);f&&t.push({id:`${i.getId()}_bullish`,buffer:f,count:i.bullishCount||0,style:{...i.getStyle(),color:i.getStyle().bullishColor||"#26a69a"},visible:i.isVisible(),type:"bar",yBounds:h});const g=o.renderer.getBuffer(`${i.getId()}_bearish`);g&&t.push({id:`${i.getId()}_bearish`,buffer:g,count:i.bearishCount||0,style:{...i.getStyle(),color:i.getStyle().bearishColor||"#ef5350"},visible:i.isVisible(),type:"bar",yBounds:h})}else d&&t.push(d)}}),t}function xt(o,e,t){var s,a,l;const i=o.container.getBoundingClientRect();if(i.width===0||i.height===0){console.warn("[SciChart] Container has zero size in render, skipping overlay");return}o.overlay.clear(i.width,i.height),o.overlay.drawGrid(e,o.xScale,t),o.overlay.drawXAxis(e,o.xScale,o.xAxisOptions);const n=[],r=[];if(o.yAxisOptionsMap.forEach((c,h)=>{c.position==="right"?r.push(h):n.push(h)}),n.forEach((c,h)=>{const u=o.yScales.get(c),d=o.yAxisOptionsMap.get(c);if(u&&d){const f=h*65;o.overlay.drawYAxis(e,u,d,"left",f)}}),r.forEach((c,h)=>{const u=o.yScales.get(c),d=o.yAxisOptionsMap.get(c);if(u&&d){const f=h*65;o.overlay.drawYAxis(e,u,d,"right",f)}}),o.overlay.drawPlotBorder(e),o.series.forEach(c=>{if(c.isVisible()&&c.hasErrorData()){const h=c.getYAxisId()||o.primaryYAxisId,d=o.yScales.get(h)||t;o.overlay.drawErrorBars(e,c,o.xScale,d)}}),o.selectionRect&&o.overlay.drawSelectionRect(o.selectionRect),o.annotationManager.count>0&&o.annotationManager.render(o.overlayCtx,e,o.viewBounds),(s=o.cursorOptions)!=null&&s.enabled&&o.cursorPosition){const c=(l=(a=o.tooltip)==null?void 0:a.hasActiveTooltip)==null?void 0:l.call(a),h={enabled:!0,x:o.cursorPosition.x,y:o.cursorPosition.y,crosshair:o.cursorOptions.crosshair??!1,tooltipText:c?void 0:o.cursorOptions.formatter?o.cursorOptions.formatter(o.pixelToDataX(o.cursorPosition.x),o.pixelToDataY(o.cursorPosition.y),""):`X: ${o.pixelToDataX(o.cursorPosition.x).toFixed(3)}
|
|
182
|
+
Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor(e,h)}o.tooltip&&o.tooltip.render(),o.stats&&o.showStatistics&&o.stats.update(o.viewBounds)}function Oi(o,e,t){if(o==="heatmap"&&t){const{xValues:d,yValues:f}=t;let g=1/0,m=-1/0,y=1/0,b=-1/0;for(let v=0;v<d.length;v++){const S=d[v];S<g&&(g=S),S>m&&(m=S)}for(let v=0;v<f.length;v++){const S=f[v];S<y&&(y=S),S>b&&(b=S)}return{xMin:g,xMax:m,yMin:y,yMax:b}}const{x:i,y:n,y2:r,high:s,low:a}=e;if(i.length===0)return{xMin:0,xMax:1,yMin:0,yMax:1};let l=1/0,c=-1/0,h=1/0,u=-1/0;for(let d=0;d<i.length;d++){const f=i[d];if(!isFinite(f))continue;f<l&&(l=f),f>c&&(c=f);const g=[n[d]];r&&isFinite(r[d])&&g.push(r[d]),s&&isFinite(s[d])&&g.push(s[d]),a&&isFinite(a[d])&&g.push(a[d]);for(const m of g)isFinite(m)&&(m<h&&(h=m),m>u&&(u=m))}return l===1/0?{xMin:0,xMax:1,yMin:0,yMax:1}:{xMin:l,xMax:c,yMin:h,yMax:u}}function E(o){return o?o instanceof Float32Array||o instanceof Float64Array?o:new Float32Array(o):new Float32Array(0)}function q(o,e){const t=new o.constructor(o.length+e.length);return t.set(o,0),t.set(e,o.length),t}function Ui(o,e){const{x:t,y:i}=o,n=t.length;if(n<e)return{...o};const r=new Float32Array(n),s=Math.floor(e/2);for(let a=0;a<n;a++){let l=0,c=0;for(let h=a-s;h<=a+s;h++)h>=0&&h<n&&(l+=i[h],c++);r[a]=l/c}return{x:t,y:r}}function $i(o,e){var n,r;if(e<0||e>=o.x.length)return null;if(o.yError&&e<o.yError.length){const s=o.yError[e];return[s,s]}const t=((n=o.yErrorMinus)==null?void 0:n[e])??0,i=((r=o.yErrorPlus)==null?void 0:r[e])??0;return t>0||i>0?[t,i]:null}function Yi(o,e){var n,r;if(e<0||e>=o.x.length)return null;if(o.xError&&e<o.xError.length){const s=o.xError[e];return[s,s]}const t=((n=o.xErrorMinus)==null?void 0:n[e])??0,i=((r=o.xErrorPlus)==null?void 0:r[e])??0;return t>0||i>0?[t,i]:null}const Vi={color:"#ff0055",width:1.5,opacity:1,pointSize:4};class vt{constructor(e){p(this,"id");p(this,"type");p(this,"yAxisId");p(this,"data");p(this,"style");p(this,"visible");p(this,"name");p(this,"stackId");p(this,"cycle");p(this,"maxPoints");p(this,"bullishCount",0);p(this,"bearishCount",0);p(this,"heatmapData");p(this,"heatmapStyle");p(this,"lastAppendCount",0);p(this,"cachedBounds",null);p(this,"boundsNeedsUpdate",!0);p(this,"_needsBufferUpdate",!0);p(this,"smoothedData",null);p(this,"smoothingNeedsUpdate",!0);p(this,"getId",()=>this.id);p(this,"getName",()=>this.name||this.id);p(this,"getType",()=>this.type);p(this,"getYAxisId",()=>this.yAxisId);p(this,"getStackId",()=>this.stackId);p(this,"getVisible",()=>this.visible);p(this,"isVisible",()=>this.visible);p(this,"getStyle",()=>this.style);p(this,"getHeatmapData",()=>this.heatmapData);p(this,"getHeatmapStyle",()=>this.heatmapStyle);p(this,"getCycle",()=>this.cycle);p(this,"getPointCount",()=>this.type==="heatmap"?this.heatmapData.xValues.length*this.heatmapData.yValues.length:this.data.x.length);p(this,"getLastAppendCount",()=>this.lastAppendCount);p(this,"resetLastAppendCount",()=>{this.lastAppendCount=0});p(this,"hasErrorData",()=>!!(this.data.yError||this.data.yErrorPlus||this.data.yErrorMinus||this.data.xError||this.data.xErrorPlus||this.data.xErrorMinus));p(this,"getYError",e=>$i(this.data,e));p(this,"getXError",e=>Yi(this.data,e));if(this.id=e.id,this.name=e.name,this.type=e.type,this.yAxisId=e.yAxisId,this.visible=e.visible??!0,this.stackId=e.stackId,this.cycle=e.cycle,this.maxPoints=e.maxPoints,this.type==="heatmap"){const t=e;this.data={x:new Float32Array(0),y:new Float32Array(0)},this.heatmapData={xValues:E(t.data.xValues),yValues:E(t.data.yValues),zValues:E(t.data.zValues)},this.heatmapStyle=t.style}else{const t=e.data;this.data={x:E(t==null?void 0:t.x),y:E(t==null?void 0:t.y),yError:t!=null&&t.yError?E(t.yError):void 0,yErrorPlus:t!=null&&t.yErrorPlus?E(t.yErrorPlus):void 0,yErrorMinus:t!=null&&t.yErrorMinus?E(t.yErrorMinus):void 0,xError:t!=null&&t.xError?E(t.xError):void 0,xErrorPlus:t!=null&&t.xErrorPlus?E(t.xErrorPlus):void 0,xErrorMinus:t!=null&&t.xErrorMinus?E(t.xErrorMinus):void 0,y2:t!=null&&t.y2?E(t.y2):void 0,open:t!=null&&t.open?E(t.open):void 0,high:t!=null&&t.high?E(t.high):void 0,low:t!=null&&t.low?E(t.low):void 0,close:t!=null&&t.close?E(t.close):void 0}}this.style={...Vi,...e.style},e.color&&(this.style.color=e.color),e.width&&(this.style.width=e.width),e.pointSize&&(this.style.pointSize=e.pointSize)}getData(){return this.style.smoothing&&this.style.smoothing>0?((this.smoothingNeedsUpdate||!this.smoothedData)&&(this.smoothedData=Ui(this.data,5),this.smoothingNeedsUpdate=!1),this.smoothedData):this.data}getBounds(){return this.data.x.length===0&&this.type!=="heatmap"?null:((this.boundsNeedsUpdate||!this.cachedBounds)&&(this.cachedBounds=Oi(this.type,this.data,this.heatmapData),this.boundsNeedsUpdate=!1),this.cachedBounds)}updateData(e){if(e){if(e.append){const t=E(e.x),i=E(e.y);if(t.length>0&&(this.data.x=q(this.data.x,t),this.data.y=q(this.data.y,i),e.y2&&(this.data.y2=this.data.y2?q(this.data.y2,E(e.y2)):E(e.y2)),e.open&&(this.data.open=this.data.open?q(this.data.open,E(e.open)):E(e.open)),e.high&&(this.data.high=this.data.high?q(this.data.high,E(e.high)):E(e.high)),e.low&&(this.data.low=this.data.low?q(this.data.low,E(e.low)):E(e.low)),e.close&&(this.data.close=this.data.close?q(this.data.close,E(e.close)):E(e.close)),this.lastAppendCount+=t.length,this.maxPoints&&this.data.x.length>this.maxPoints)){const n=this.data.x.length-this.maxPoints;this.data.x=this.data.x.slice(n),this.data.y=this.data.y.slice(n),this.data.y2&&(this.data.y2=this.data.y2.slice(n)),this.data.open&&(this.data.open=this.data.open.slice(n)),this.data.high&&(this.data.high=this.data.high.slice(n)),this.data.low&&(this.data.low=this.data.low.slice(n)),this.data.close&&(this.data.close=this.data.close.slice(n)),this.lastAppendCount=0}}else e.x&&(this.data.x=E(e.x)),e.y&&(this.data.y=E(e.y)),e.y2&&(this.data.y2=E(e.y2)),e.open&&(this.data.open=E(e.open)),e.high&&(this.data.high=E(e.high)),e.low&&(this.data.low=E(e.low)),e.close&&(this.data.close=E(e.close)),this.lastAppendCount=0;this.boundsNeedsUpdate=!0,this.smoothingNeedsUpdate=!0,this._needsBufferUpdate=!0}}setStyle(e){const t=this.style.smoothing;this.style={...this.style,...e},this.style.smoothing!==t&&(this.smoothingNeedsUpdate=!0,this._needsBufferUpdate=!0)}setType(e){this.type=e,this._needsBufferUpdate=!0}setVisible(e){this.visible=e}get needsBufferUpdate(){return this._needsBufferUpdate}set needsBufferUpdate(e){this._needsBufferUpdate=e}setMaxPoints(e){if(this.maxPoints=e,this.maxPoints&&this.data.x.length>this.maxPoints){const t=this.data.x.length-this.maxPoints;this.data.x=this.data.x.slice(t),this.data.y=this.data.y.slice(t),this.data.y2&&(this.data.y2=this.data.y2.slice(t)),this.data.open&&(this.data.open=this.data.open.slice(t)),this.data.high&&(this.data.high=this.data.high.slice(t)),this.data.low&&(this.data.low=this.data.low.slice(t)),this.data.close&&(this.data.close=this.data.close.slice(t)),this._needsBufferUpdate=!0}}destroy(){this.data={x:new Float32Array(0),y:new Float32Array(0)},this.cachedBounds=null}}function Wi(o){return new ce(o)}class De{constructor(e,t={}){p(this,"available");p(this,"canvas");p(this,"adapter");p(this,"device");p(this,"context");this.canvas=e,this.available=De.isSupported()}static isSupported(){return typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u"}async init(e={}){if(!this.available)throw new Error("[SciChart] WebGPU is not supported in this environment");const t=globalThis.navigator.gpu;if(this.adapter=await t.requestAdapter({powerPreference:e.powerPreference??"high-performance"}),!this.adapter)throw new Error("[SciChart] Failed to request WebGPU adapter");this.device=await this.adapter.requestDevice();const i=this.canvas.getContext("webgpu");if(!i)throw new Error("[SciChart] Failed to get WebGPU context");this.context=i;const n=e.preferredFormat??(t.getPreferredCanvasFormat?t.getPreferredCanvasFormat():"bgra8unorm");this.context.configure({device:this.device,format:n,alphaMode:"premultiplied"})}destroy(){this.device=void 0,this.adapter=void 0,this.context=void 0}}function Xi(o,e,t){const i=Math.min(o.length,e.length),n=new Float32Array(i*6*2),r=t*.5;for(let s=0;s<i;s++){const a=o[s],l=e[s],c=s*12,h=a-r,u=a+r,d=0,f=l;n[c+0]=h,n[c+1]=d,n[c+2]=u,n[c+3]=d,n[c+4]=h,n[c+5]=f,n[c+6]=h,n[c+7]=f,n[c+8]=u,n[c+9]=d,n[c+10]=u,n[c+11]=f}return n}function St(o){if(o.length<2)return 1;let e=1/0;for(let t=1;t<o.length;t++){const i=Math.abs(o[t]-o[t-1]);i>0&&i<e&&(e=i)}return e===1/0?1:e*.8}function Ni(o,e,t){const i=o.length,n=e.length;i*n>t.length&&console.warn("[Heatmap] Z array is too small for the specified grid dimensions");const r=(i-1)*(n-1),s=new Float32Array(r*6*3);let a=0;for(let l=0;l<n-1;l++)for(let c=0;c<i-1;c++){const h=o[c],u=o[c+1],d=e[l],f=e[l+1],g=t[l*i+c],m=t[l*i+(c+1)],y=t[(l+1)*i+c],b=t[(l+1)*i+(c+1)];s[a++]=h,s[a++]=d,s[a++]=g,s[a++]=u,s[a++]=d,s[a++]=m,s[a++]=h,s[a++]=f,s[a++]=y,s[a++]=h,s[a++]=f,s[a++]=y,s[a++]=u,s[a++]=d,s[a++]=m,s[a++]=u,s[a++]=f,s[a++]=b}return s}function Hi(o="viridis"){const t=new Uint8Array(1024);for(let i=0;i<256;i++){const n=i/255;let r,s,a;o==="jet"?(r=Math.min(Math.max(1.5-Math.abs(n*4-3),0),1),s=Math.min(Math.max(1.5-Math.abs(n*4-2),0),1),a=Math.min(Math.max(1.5-Math.abs(n*4-1),0),1)):o==="grayscale"?r=s=a=n:o==="plasma"?(r=.5+.5*Math.sin(Math.PI*(n-.5)),s=.5+.5*Math.sin(Math.PI*n),a=.8):(r=.267*(1-n)+.993*n,s=.005*(1-n)+.906*n,a=.337*(1-n)+.144*n),t[i*4+0]=r*255,t[i*4+1]=s*255,t[i*4+2]=a*255,t[i*4+3]=255}return t}function qi(o,e,t,i,n,r){const s=o.length,a=[],l=[],c=r/2,u=r/10/2;for(let d=0;d<s;d++){const g=n[d]>=e[d]?a:l,m=Math.max(e[d],n[d]),y=Math.min(e[d],n[d]);wt(g,o[d]-c,y,o[d]+c,m),wt(g,o[d]-u,i[d],o[d]+u,t[d])}return{bullish:new Float32Array(a),bearish:new Float32Array(l)}}function wt(o,e,t,i,n){o.push(e,t,i,t,e,n),o.push(i,t,i,n,e,n)}function be(o,e){const t=e.getStackId();if(t){Ki(o,t);return}const i=e.getData(),n=e.getType();if(n!=="heatmap"&&(!i||i.x.length===0))return;const r=e.getId();if(n==="band"||n==="area"){const s=n==="area"?new Float32Array(i.x.length).fill(0):i.y2||new Float32Array(i.x.length).fill(0);o.renderer.createBuffer(r,ot(i.x,i.y,s))}else if(n==="bar"){const s=e.getStyle().barWidth??St(i.x);o.renderer.createBuffer(r,Xi(i.x,i.y,s))}else if(n==="heatmap")ji(o,e);else if(n==="candlestick"){const s=e.getData();if(s.open&&s.high&&s.low&&s.close){const a=e.getStyle().barWidth??St(s.x),{bullish:l,bearish:c}=qi(s.x,s.open,s.high,s.low,s.close,a);o.renderer.createBuffer(`${r}_bullish`,l),o.renderer.createBuffer(`${r}_bearish`,c),e.bullishCount=l.length/2,e.bearishCount=c.length/2}}else o.renderer.createBuffer(r,ke(i.x,i.y));if(n==="step"||n==="step+scatter"){const s=e.getStyle().stepMode??"after";o.renderer.createBuffer(`${r}_step`,oi(i.x,i.y,s))}e.resetLastAppendCount()}function ji(o,e){var r;const t=e.getHeatmapData(),i=e.getHeatmapStyle();if(!t||t.xValues.length<2)return;o.renderer.createBuffer(e.getId(),Ni(t.xValues,t.yValues,t.zValues));const n=((r=i==null?void 0:i.colorScale)==null?void 0:r.name)||"viridis";o.renderer.createColormapTexture(`${e.getId()}_colormap`,Hi(n))}function Ki(o,e){const t=Array.from(o.series.values()).filter(n=>n.getStackId()===e);let i=null;for(const n of t){const r=n.getData();if(r.x.length===0)continue;i||(i=new Float32Array(r.y.length).fill(0));const s=new Float32Array(i);for(let a=0;a<r.y.length;a++)i[a]+=r.y[a];o.renderer.createBuffer(n.getId(),ot(r.x,i,s)),n.resetLastAppendCount()}}function Zi(o,e){var i;const t=new vt(e);o.series.set(t.getId(),t),be(o,t),(o.xAxisOptions.auto||Array.from(o.yAxisOptionsMap.values()).some(n=>n.auto))&&o.autoScale(),(i=o.updateLegend)==null||i.call(o),o.requestRender()}function Ji(o,e){var i;const t=o.series.get(e);t&&(o.renderer.deleteBuffer(e),o.renderer.deleteBuffer(`${e}_step`),t.destroy(),o.series.delete(e),(i=o.updateLegend)==null||i.call(o),o.requestRender())}function Qi(o,e,t){const i=o.series.get(e);i&&(i.updateData(t),be(o,i),o.requestRender())}function en(o,e,t,i){var s;const n=o.series.get(e);if(!n)return;const r=((s=n.getBounds())==null?void 0:s.xMax)??-1/0;if(n.updateData({x:t,y:i,append:!0}),be(o,n),o.autoScrollEnabled){const a=n.getBounds();if(a){const l=o.viewBounds.xMax-o.viewBounds.xMin;r>=o.viewBounds.xMax-l*.05&&(o.viewBounds.xMax=a.xMax,o.viewBounds.xMin=o.viewBounds.xMax-l)}}(o.xAxisOptions.auto||Array.from(o.yAxisOptionsMap.values()).some(a=>a.auto))&&o.autoScale(),o.requestRender()}function tn(o,e,t){const i=o.series.get(e);i&&(i.setMaxPoints(t),o.requestRender())}function nn(o,e,t,i={}){const n=o.series.get(e);if(!n)throw new Error(`Series ${e} not found`);const r=n.getData();if(!r||r.x.length<2)return"";const s=it(r.x,r.y,t,i),a=n.getBounds(),l=(a==null?void 0:a.xMin)??0,h=((a==null?void 0:a.xMax)??1)-l,u=200,d=new Float32Array(u),f=new Float32Array(u);for(let y=0;y<u;y++){const b=l+y/(u-1)*h;d[y]=b,f[y]=s.predict(b)}const g=`${e}-fit-${Date.now()}`,m=n.getStyle();return o.addSeries({id:g,type:"line",yAxisId:n.getYAxisId(),data:{x:d,y:f},style:{color:m.color,width:(m.width||1)*1.5,opacity:.8,lineDash:[5,5]}}),o.addAnnotation({type:"text",x:l+h*.05,y:s.predict(l+h*.05),text:`${s.equation}
|
|
183
|
+
(R² = ${s.rSquared.toFixed(4)})`,fontSize:12,backgroundColor:"rgba(0,0,0,0.7)",color:m.color||"#ffffff",padding:4,anchor:"bottom-left",interactive:!0}),g}class xe{constructor(){p(this,"domain",[0,1]);p(this,"range",[0,100]);p(this,"type","linear")}setDomain(e,t){if(!isFinite(e)||!isFinite(t)){this.domain=[0,1];return}if(e===t){this.domain=[e-.5,t+.5];return}this.domain=[e,t]}setRange(e,t){this.range=[e,t]}transform(e){const[t,i]=this.domain,[n,r]=this.range,s=(e-t)/(i-t);return n+s*(r-n)}invert(e){const[t,i]=this.domain,[n,r]=this.range,s=(e-n)/(r-n);return t+s*(i-t)}ticks(e=10){const[t,i]=this.domain;if(!isFinite(t)||!isFinite(i)||t===i)return[];const n=on(t,i,e),r=Math.ceil(t/n)*n,s=[],a=100;let l=r;for(;l<=i+n*.5&&s.length<a;)s.push(Math.round(l*1e12)/1e12),l+=n;return s}}class ve{constructor(){p(this,"domain",[1,1e3]);p(this,"range",[0,100]);p(this,"type","log");p(this,"base",10)}setDomain(e,t){const i=Math.max(e,1e-12),n=Math.max(t,1e-12*10);if(i===n){this.domain=[i/10,n*10];return}this.domain=[i,n]}setRange(e,t){this.range=[e,t]}transform(e){const[t,i]=this.domain,[n,r]=this.range;if(e<=0)return n;const s=Math.log(t)/Math.log(this.base),a=Math.log(i)/Math.log(this.base),c=(Math.log(e)/Math.log(this.base)-s)/(a-s);return n+c*(r-n)}invert(e){const[t,i]=this.domain,[n,r]=this.range,s=Math.log(t)/Math.log(this.base),a=Math.log(i)/Math.log(this.base),l=(e-n)/(r-n),c=s+l*(a-s);return Math.pow(this.base,c)}ticks(e=10){const[t,i]=this.domain,n=Math.floor(Math.log10(t)),r=Math.ceil(Math.log10(i)),s=[];for(let a=n;a<=r&&s.length<e;a++){const l=Math.pow(10,a);l>=t&&l<=i&&s.push(l)}return s}}function on(o,e,t){const i=e-o;if(i<=0||!isFinite(i))return 1;const n=i/t,r=Math.pow(10,Math.floor(Math.log10(n))),s=n/r;let a;return s<1.5?a=1:s<3?a=2:s<7?a=5:a=10,a*r}function rn(o){return o==="log"?new ve:new xe}function sn(o,e){if(!o)throw new Error("[SciChart] Container element is required");const t=e.devicePixelRatio??window.devicePixelRatio,i=typeof e.theme=="string"?Be(e.theme):e.theme??lt,n=ae(e.background??i.backgroundColor),r=[n[0],n[1],n[2],n[3]],s=e.showLegend??i.legend.visible,a=e.showControls??!1,l=e.autoScroll??!1,c=e.showStatistics??!1,h={scale:"linear",auto:!0,...e.xAxis},u=h.scale==="log"?new ve:new xe,d=new Map,f=new Map;let g="default";(e.yAxis?Array.isArray(e.yAxis)?e.yAxis:[e.yAxis]:[{}]).forEach((S,T)=>{const P=T===0,M=P?"default":`y${T}`,_=S.id||M;P&&(g=_);const R={scale:"linear",auto:!0,position:S.position||(P?"left":"right"),...S,id:_};d.set(_,R),f.set(_,R.scale==="log"?new ve:new xe)}),o.style.position="relative",o.style.overflow="hidden",o.style.backgroundColor=e.background??i.backgroundColor;const y=Tt("webgl"),b=Tt("overlay");for(;o.firstChild;)o.removeChild(o.firstChild);o.appendChild(y),o.appendChild(b);const v=b.getContext("2d");if(!v)throw new Error("Failed to get 2D context");return{theme:i,backgroundColor:r,showLegend:s,showControls:a,autoScroll:l,showStatistics:c,dpr:t,xAxisOptions:h,xScale:u,yAxisOptionsMap:d,yScales:f,primaryYAxisId:g,webglCanvas:y,overlayCanvas:b,overlayCtx:v}}function Tt(o){const e=document.createElement("canvas");return e.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;",o==="overlay"&&(e.style.pointerEvents="none"),e}function an(o,e){const t=o.getBoundingClientRect(),i=Array.from(e.values()).filter(a=>a.position!=="right").length,n=Array.from(e.values()).filter(a=>a.position==="right").length,r=$.left+Math.max(0,i-1)*65,s=$.right+n*65;return{x:r,y:$.top,width:Math.max(1,t.width-r-s),height:Math.max(1,t.height-$.top-$.bottom)}}function ln(o){const e=[];let t=0,i=0;return o.forEach((n,r)=>{const s=n.position==="right"?"right":"left",a=s==="left"?t*65:i*65;s==="left"?t++:i++,e.push({id:r,position:s,offset:a})}),e}function cn(o,e,t,i,n){const r=o.getBoundingClientRect();if(r.width===0||r.height===0)return!1;const s=r.width*n,a=r.height*n;return[e,t].forEach(l=>{l.width=s,l.height=a}),i.scale(n,n),!0}function hn(o,e,t){return t.xMin+(o-e.x)/e.width*(t.xMax-t.xMin)}function un(o,e,t){return t.yMin+(1-(o-e.y)/e.height)*(t.yMax-t.yMin)}class dn{constructor(e){p(this,"plugins",new Map);p(this,"chart");this.chart=e}use(e){var t;if(this.plugins.has(e.name)){console.warn(`[SciChart] Plugin "${e.name}" is already registered.`);return}this.plugins.set(e.name,e),(t=e.init)==null||t.call(e,this.chart)}remove(e){var i;const t=this.plugins.get(e);return t?((i=t.destroy)==null||i.call(t),this.plugins.delete(e)):!1}get(e){return this.plugins.get(e)}notify(e,...t){this.plugins.forEach(i=>{const n=i[e];if(typeof n=="function")try{n(...t)}catch(r){console.error(`[SciChart] Error in plugin "${i.name}" hook "${String(e)}":`,r)}})}destroy(){this.plugins.forEach(e=>{var t;return(t=e.destroy)==null?void 0:t.call(e)}),this.plugins.clear()}}const V={PAN:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"></path><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"></path><path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0"></path><path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"></path></svg>',RESET:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><polyline points="23 4 23 10 17 10"></polyline><polyline points="1 20 1 14 7 14"></polyline><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"></path></svg>',LINE:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v18h18"></path><path d="M18.7 8l-5.1 5.2-2.8-2.7L7 14.3"></path></svg>',SCATTER:'<svg viewBox="0 0 24 24" width="14" height="14" fill="currentColor"><circle cx="7" cy="14" r="2"></circle><circle cx="11" cy="10" r="2"></circle><circle cx="15" cy="13" r="2"></circle><circle cx="19" cy="8" r="2"></circle><path d="M3 3v18h18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></svg>',BOTH:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M3 3v18h18"></path><path d="M18.7 8l-5.1 5.2-2.8-2.7L7 14.3"></path><circle cx="7" cy="14.3" r="1" fill="currentColor"></circle><circle cx="10.8" cy="10.5" r="1" fill="currentColor"></circle><circle cx="13.6" cy="13.2" r="1" fill="currentColor"></circle><circle cx="18.7" cy="8" r="1" fill="currentColor"></circle></svg>',SMOOTH:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M2 12c.5 0 .9-.3 1.2-.7l1.6-2.6c.3-.4.7-.7 1.2-.7h2c.5 0 .9.3 1.2.7l1.6 2.6c.3.4.7.7 1.2.7h2c.5 0 .9-.3 1.2-.7l1.6-2.6c.3-.4.7-.7 1.2-.7h2"></path></svg>',AUTOSCALE:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" y1="3" x2="14" y2="10"></line><line x1="3" y1="21" x2="10" y2="14"></line></svg>',EXPORT:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>',LEGEND:'<svg viewBox="0 0 24 24" width="14" height="14" stroke="currentColor" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16M4 12h16M4 18h7"></path></svg>'};class fn{constructor(e,t,i){p(this,"container");p(this,"toolbar");p(this,"callbacks");p(this,"theme");p(this,"isSmoothing",!1);p(this,"isPanMode",!0);p(this,"isLegendVisible",!0);p(this,"currentType","line");this.callbacks=i,this.theme=t,this.container=document.createElement("div"),this.container.style.cssText=`
|
|
184
184
|
position: absolute;
|
|
185
185
|
top: 8px;
|
|
186
186
|
right: 8px;
|
|
@@ -202,7 +202,7 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
202
202
|
border-radius: 8px;
|
|
203
203
|
box-shadow: ${n};
|
|
204
204
|
transition: all 0.3s cubic-bezier(0.4, 0, 0.4, 1);
|
|
205
|
-
`}createButtons(){this.createButton(V.PAN,"Pan Mode",()=>{this.isPanMode=!this.isPanMode,this.updateButtonStates(),this.callbacks.onTogglePan(this.isPanMode)},"pan"),this.createButton(V.RESET,"Reset Zoom",()=>this.callbacks.onResetZoom(),"reset"),this.createButton(V.AUTOSCALE,"Auto Scale",()=>this.callbacks.onAutoScale(),"autoscale");const e=document.createElement("div"),t=this.isDarkTheme();e.style.cssText=`width: 1px; height: 20px; background: ${t?"rgba(255,255,255,0.25)":"rgba(0,0,0,0.2)"}; margin: 0 6px;`,this.toolbar.appendChild(e),this.createButton(V.LINE,"Toggle Line/Scatter/Both",()=>{const
|
|
205
|
+
`}createButtons(){this.createButton(V.PAN,"Pan Mode",()=>{this.isPanMode=!this.isPanMode,this.updateButtonStates(),this.callbacks.onTogglePan(this.isPanMode)},"pan"),this.createButton(V.RESET,"Reset Zoom",()=>this.callbacks.onResetZoom(),"reset"),this.createButton(V.AUTOSCALE,"Auto Scale",()=>this.callbacks.onAutoScale(),"autoscale");const e=document.createElement("div"),t=this.isDarkTheme();e.style.cssText=`width: 1px; height: 20px; background: ${t?"rgba(255,255,255,0.25)":"rgba(0,0,0,0.2)"}; margin: 0 6px;`,this.toolbar.appendChild(e),this.createButton(V.LINE,"Toggle Line/Scatter/Both",()=>{const r=["line","scatter","line+scatter"],s=(r.indexOf(this.currentType)+1)%r.length;this.currentType=r[s],this.callbacks.onSetType(this.currentType),this.updateButtonStates()},"type"),this.createButton(V.SMOOTH,"Automated Smoothing",()=>{this.isSmoothing=!this.isSmoothing,this.updateButtonStates(),this.callbacks.onToggleSmoothing()},"smooth");const i=document.createElement("div");i.style.cssText=`width: 1px; height: 20px; background: ${t?"rgba(255,255,255,0.25)":"rgba(0,0,0,0.2)"}; margin: 0 6px;`,this.toolbar.appendChild(i),this.createButton(V.EXPORT,"Export as PNG",()=>this.callbacks.onExport(),"export");const n=document.createElement("div");n.style.cssText=`width: 1px; height: 20px; background: ${this.isDarkTheme()?"rgba(255,255,255,0.25)":"rgba(0,0,0,0.2)"}; margin: 0 6px;`,this.toolbar.appendChild(n),this.createButton(V.LEGEND,"Toggle Legend",()=>{this.isLegendVisible=!this.isLegendVisible,this.updateButtonStates(),this.callbacks.onToggleLegend(this.isLegendVisible)},"legend"),this.updateButtonStates()}enforceSVGVisibility(e){const t=e.querySelector(".scichart-control-icon");t&&(t.style.display="flex",t.style.alignItems="center",t.style.justifyContent="center",t.style.width="100%",t.style.height="100%",t.style.pointerEvents="none");const i=e.querySelector("svg");i&&(i.setAttribute("width","14"),i.setAttribute("height","14"),i.style.display="block",i.style.overflow="visible",i.style.color="inherit",i.style.stroke="currentColor",i.getAttribute("fill")||(i.style.fill="none"))}createButton(e,t,i,n){const r=document.createElement("button");r.innerHTML=`<span class="scichart-control-icon">${e}</span>`,r.title=t,r.dataset.id=n;const s=this.isDarkTheme(),a=s?"#ffffff":"#1e293b";return r.style.cssText=`
|
|
206
206
|
width: 24px;
|
|
207
207
|
height: 24px;
|
|
208
208
|
display: flex;
|
|
@@ -215,10 +215,10 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
215
215
|
border-radius: 6px;
|
|
216
216
|
transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
|
|
217
217
|
opacity: 0.9;
|
|
218
|
-
`,
|
|
218
|
+
`,r.onmouseenter=()=>{r.style.opacity="1",r.style.background=s?"rgba(255, 255, 255, 0.15)":"rgba(0, 0, 0, 0.1)",r.style.transform="translateY(-1px)",r.style.boxShadow=s?"0 2px 4px rgba(0,0,0,0.4)":"0 2px 4px rgba(0,0,0,0.1)"},r.onmouseleave=()=>{r.style.transform="none",r.style.boxShadow="none",this.updateButtonStates()},r.onclick=i,this.enforceSVGVisibility(r),this.toolbar.appendChild(r),r}updateButtonStates(){const e=this.toolbar.querySelectorAll("button"),t=this.isDarkTheme(),i="#38bdf8",n="#fb7185",r="#4ade80",s=t?"#f1f5f9":"#334155";e.forEach(a=>{const l=a.dataset.id,c=a.matches(":hover");l==="pan"?(a.style.color=this.isPanMode?i:s,a.style.opacity=c||this.isPanMode?"1":"0.8",this.isPanMode&&(a.style.background=t?"rgba(56, 189, 248, 0.15)":"rgba(56, 189, 248, 0.1)")):l==="smooth"?(a.style.color=this.isSmoothing?n:s,a.style.opacity=c||this.isSmoothing?"1":"0.8",this.isSmoothing&&(a.style.background=t?"rgba(251, 113, 133, 0.15)":"rgba(251, 113, 133, 0.1)")):l==="legend"?(a.style.color=this.isLegendVisible?r:s,a.style.opacity=c||this.isLegendVisible?"1":"0.8",this.isLegendVisible&&(a.style.background=t?"rgba(74, 222, 128, 0.15)":"rgba(74, 222, 128, 0.1)")):l==="type"?(a.innerHTML=this.currentType==="line"?V.LINE:this.currentType==="scatter"?V.SCATTER:V.BOTH,this.enforceSVGVisibility(a),a.style.color=s,a.style.opacity=c?"1":"0.8"):(l==="reset"||l==="autoscale"||l==="export")&&(a.style.color=s,a.style.opacity=c?"1":"0.8"),!c&&!(l==="pan"&&this.isPanMode||l==="smooth"&&this.isSmoothing||l==="legend"&&this.isLegendVisible)&&(a.style.background="transparent")})}updateTheme(e){this.theme=e,this.updateToolbarStyle(),this.updateButtonStates()}destroy(){this.container.remove()}}class pn{constructor(e,t,i,n){p(this,"container");p(this,"header");p(this,"content");p(this,"theme");p(this,"series",[]);p(this,"callbacks");p(this,"isDragging",!1);p(this,"startX",0);p(this,"startY",0);p(this,"initialX",0);p(this,"initialY",0);this.theme=t,this.callbacks=n,this.container=document.createElement("div"),this.container.className="scichart-legend";const r=i.x??e.clientWidth-150,s=i.y??55;this.container.style.cssText=`
|
|
219
219
|
position: absolute;
|
|
220
|
-
left: ${
|
|
221
|
-
top: ${
|
|
220
|
+
left: ${r}px;
|
|
221
|
+
top: ${s}px;
|
|
222
222
|
z-index: 90;
|
|
223
223
|
pointer-events: auto;
|
|
224
224
|
min-width: 120px;
|
|
@@ -232,7 +232,7 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
232
232
|
cursor: move;
|
|
233
233
|
background: rgba(255,255,255,0.05);
|
|
234
234
|
border-bottom: 1px solid rgba(255,255,255,0.05);
|
|
235
|
-
`,this.content=document.createElement("div"),this.content.style.padding=`${t.legend.padding}px`,this.container.appendChild(this.header),this.container.appendChild(this.content),e.appendChild(this.container),this.initDragging()}updateStyle(){const e=this.theme.name.toLowerCase().includes("dark")||this.theme.name.toLowerCase().includes("midnight")||this.theme.name.toLowerCase().includes("electro");this.container.style.background=this.theme.legend.backgroundColor,this.container.style.backdropFilter="blur(12px) saturate(180%)",this.container.style.webkitBackdropFilter="blur(12px) saturate(180%)",this.container.style.border=`1px solid ${this.theme.legend.borderColor}`,this.container.style.boxShadow=e?"0 4px 12px rgba(0, 0, 0, 0.6)":"0 4px 12px rgba(0, 0, 0, 0.15)"}initDragging(){let e=null;const t=
|
|
235
|
+
`,this.content=document.createElement("div"),this.content.style.padding=`${t.legend.padding}px`,this.container.appendChild(this.header),this.container.appendChild(this.content),e.appendChild(this.container),this.initDragging()}updateStyle(){const e=this.theme.name.toLowerCase().includes("dark")||this.theme.name.toLowerCase().includes("midnight")||this.theme.name.toLowerCase().includes("electro");this.container.style.background=this.theme.legend.backgroundColor,this.container.style.backdropFilter="blur(12px) saturate(180%)",this.container.style.webkitBackdropFilter="blur(12px) saturate(180%)",this.container.style.border=`1px solid ${this.theme.legend.borderColor}`,this.container.style.boxShadow=e?"0 4px 12px rgba(0, 0, 0, 0.6)":"0 4px 12px rgba(0, 0, 0, 0.15)"}initDragging(){let e=null;const t=s=>{s.button===0&&(s.stopPropagation(),s.preventDefault(),this.isDragging=!0,this.startX=s.clientX,this.startY=s.clientY,this.initialX=this.container.offsetLeft,this.initialY=this.container.offsetTop,this.container.style.transition="none",this.container.style.willChange="transform",this.container.style.boxShadow="0 8px 24px rgba(0,0,0,0.3)",this.container.style.cursor="grabbing",document.addEventListener("mousemove",n),document.addEventListener("mouseup",r))},i=(s,a)=>{const l=s-this.startX,c=a-this.startY;let h=this.initialX+l,u=this.initialY+c;const d=this.container.parentElement;d&&(h=Math.max(0,Math.min(h,d.clientWidth-this.container.clientWidth)),u=Math.max(0,Math.min(u,d.clientHeight-this.container.clientHeight)));const f=h-this.initialX,g=u-this.initialY;this.container.style.transform=`translate3d(${f}px, ${g}px, 0)`},n=s=>{this.isDragging&&(e&&cancelAnimationFrame(e),e=requestAnimationFrame(()=>i(s.clientX,s.clientY)))},r=()=>{var s;if(this.isDragging){this.isDragging=!1,e&&cancelAnimationFrame(e);const a=this.container.getBoundingClientRect(),l=(s=this.container.parentElement)==null?void 0:s.getBoundingClientRect();if(l){const c=a.left-l.left,h=a.top-l.top;this.container.style.transform="none",this.container.style.left=`${c}px`,this.container.style.top=`${h}px`,this.callbacks.onMove(c,h)}this.container.style.willChange="auto",this.container.style.transition="box-shadow 0.2s ease",this.container.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)",this.container.style.cursor="auto"}document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r)};this.container.addEventListener("mousedown",t),this.container.addEventListener("wheel",s=>s.stopPropagation()),this.container.addEventListener("click",s=>s.stopPropagation()),this.container.addEventListener("dblclick",s=>s.stopPropagation())}update(e){this.series=e,this.render()}render(){this.content.innerHTML="";const e=this.theme.legend,t=window.devicePixelRatio||1;this.series.forEach(i=>{const n=document.createElement("div");n.style.cssText=`
|
|
236
236
|
display: flex;
|
|
237
237
|
align-items: center;
|
|
238
238
|
gap: 8px;
|
|
@@ -240,7 +240,7 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
240
240
|
font-family: ${e.fontFamily};
|
|
241
241
|
font-size: ${e.fontSize}px;
|
|
242
242
|
color: ${e.textColor};
|
|
243
|
-
`;const s=document.createElement("canvas"),r=e.swatchSize;s.width=r*t,s.height=r*t,s.style.width=`${r}px`,s.style.height=`${r}px`;const a=s.getContext("2d");if(a){a.scale(t,t);const c=i.getStyle(),h=c.color||"#ff0055",u=i.getType(),d=c.symbol||"circle";a.fillStyle=h,a.strokeStyle=h,a.lineWidth=2;const f=r/2,g=r/2,m=String(u).toLowerCase(),y=m==="scatter"||m==="1"||m==="line"&&!!c.symbol,b=m.includes("scatter")||m==="2",v=m==="area"||m==="band";if(y)this.drawSymbol(a,d,f,g,r*.8);else if(b)a.beginPath(),a.moveTo(0,g),a.lineTo(r,g),a.stroke(),this.drawSymbol(a,d,f,g,r*.6);else if(v)a.globalAlpha=.6,a.fillRect(0,r*.2,r,r*.6),a.globalAlpha=1,a.strokeRect(0,r*.2,r,r*.6);else if(m==="candlestick"){const S=c.bullishColor||"#26a69a";a.fillStyle=S,a.fillRect(r*.3,r*.2,r*.4,r*.6),a.beginPath(),a.moveTo(r*.5,0),a.lineTo(r*.5,r),a.strokeStyle=S,a.stroke()}else a.beginPath(),a.moveTo(0,g),a.lineTo(r,g),a.stroke()}const l=document.createElement("span");l.textContent=i.getName(),n.appendChild(s),n.appendChild(l),this.content.appendChild(n)})}drawSymbol(e,t,i,n,s){const r=s/2;switch(e.beginPath(),t){case"circle":e.arc(i,n,r,0,Math.PI*2),e.fill();break;case"square":e.rect(i-r,n-r,s,s),e.fill();break;case"diamond":e.moveTo(i,n-r),e.lineTo(i+r,n),e.lineTo(i,n+r),e.lineTo(i-r,n),e.closePath(),e.fill();break;case"triangle":e.moveTo(i,n-r),e.lineTo(i+r,n+r),e.lineTo(i-r,n+r),e.closePath(),e.fill();break;case"triangleDown":e.moveTo(i,n+r),e.lineTo(i+r,n-r),e.lineTo(i-r,n-r),e.closePath(),e.fill();break;case"cross":e.moveTo(i-r,n),e.lineTo(i+r,n),e.moveTo(i,n-r),e.lineTo(i,n+r),e.stroke();break;case"x":const a=r*.707;e.moveTo(i-a,n-a),e.lineTo(i+a,n+a),e.moveTo(i+a,n-a),e.lineTo(i-a,n+a),e.stroke();break;case"star":for(let l=0;l<5;l++)e.lineTo(i+r*Math.cos((18+l*72)/180*Math.PI),n-r*Math.sin((18+l*72)/180*Math.PI)),e.lineTo(i+r/2*Math.cos((54+l*72)/180*Math.PI),n-r/2*Math.sin((54+l*72)/180*Math.PI));e.closePath(),e.fill();break}}draw(e,t){if(this.series.length===0)return;const i=this.theme.legend,n=i.padding*t,s=i.itemGap*t,r=i.swatchSize*t,a=8*t,l=this.container.offsetLeft*t,c=this.container.offsetTop*t,h=this.container.clientWidth*t,u=this.container.clientHeight*t;e.save();const d=this.theme.name.toLowerCase().includes("dark")||this.theme.name.toLowerCase().includes("midnight");e.fillStyle=d?i.backgroundColor:"rgba(255, 255, 255, 0.85)",e.strokeStyle=i.borderColor,e.lineWidth=1*t;const f=i.borderRadius*t;e.beginPath(),e.moveTo(l+f,c),e.lineTo(l+h-f,c),e.arcTo(l+h,c,l+h,c+f,f),e.lineTo(l+h,c+u-f),e.arcTo(l+h,c+u,l+h-f,c+u,f),e.lineTo(l+f,c+u),e.arcTo(l,c+u,l,c+u-f,f),e.lineTo(l,c+f),e.arcTo(l,c,l+f,c,f),e.closePath(),e.fill(),e.stroke(),e.textAlign="left",e.textBaseline="middle",e.font=`${i.fontSize*t}px ${i.fontFamily}`,this.series.forEach((g,m)=>{const y=c+a+n+m*(r+s)+r/2,b=l+n+r/2,v=y,S=g.getStyle(),T=g.getType(),P=S.symbol||"circle";e.fillStyle=S.color||"#ff0055",e.strokeStyle=S.color||"#ff0055",e.lineWidth=2*t;const M=String(T).toLowerCase(),_=M==="scatter"||M==="1"||M==="line"&&!!S.symbol,B=M.includes("scatter")||M==="2";_?this.drawSymbol(e,P,b,v,r*.9):B?(e.beginPath(),e.moveTo(l+n,v),e.lineTo(l+n+r,v),e.stroke(),this.drawSymbol(e,P,b,v,r*.6)):(e.beginPath(),e.moveTo(l+n,v),e.lineTo(l+n+r,v),e.stroke()),e.fillStyle=i.textColor,e.fillText(g.getName(),l+n+r+8*t,y)}),e.restore()}updateTheme(e){this.theme=e,this.updateStyle(),this.render()}setVisible(e){this.container.style.display=e?"block":"none"}destroy(){this.container.remove()}}function gn(o){return o.showControls?new fn(o.container,o.theme,{onResetZoom:()=>o.resetZoom(),onSetType:e=>{o.series.forEach(t=>{const i=t.getType(),n=t.getStyle();if(i==="step"||i==="step+scatter"||n.stepMode!==void 0){const r=e==="line"?"step":e==="line+scatter"?"step+scatter":"scatter";t.setType(r)}else(i==="line"||i==="scatter"||i==="line+scatter")&&t.setType(e)}),o.requestRender()},onToggleSmoothing:()=>{o.series.forEach(e=>{const t=e.getStyle();e.setStyle({smoothing:(t.smoothing||0)===0?.5:0})}),o.requestRender()},onTogglePan:e=>o.setPanMode(e),onExport:()=>{const e=document.createElement("a");e.download=`scichart-export-${Date.now()}.png`,e.href=o.exportImage(),e.click()},onAutoScale:()=>{o.autoScale(),o.requestRender()},onToggleLegend:()=>{o.toggleLegend()}}):null}function mn(o,e){if(!o.showLegend)return null;const t=new pn(o.container,o.theme,e.legendPosition||{},{onMove:(i,n)=>o.onLegendMove(i,n)});return t.update(Array.from(o.series.values())),t}class yn{constructor(e){p(this,"container");p(this,"webglCanvas");p(this,"overlayCanvas");p(this,"overlayCtx");p(this,"series",new Map);p(this,"events",new Pe);p(this,"viewBounds",{xMin:-.5,xMax:.5,yMin:-1e-5,yMax:1e-5});p(this,"xAxisOptions");p(this,"yAxisOptionsMap");p(this,"primaryYAxisId");p(this,"dpr");p(this,"backgroundColor");p(this,"renderer");p(this,"overlay");p(this,"interaction");p(this,"xScale");p(this,"yScales");p(this,"theme");p(this,"cursorOptions",null);p(this,"cursorPosition",null);p(this,"showLegend");p(this,"legend",null);p(this,"showControls");p(this,"controls",null);p(this,"animationFrameId",null);p(this,"needsFullRender",!1);p(this,"needsOverlayRender",!1);p(this,"isDestroyed",!1);p(this,"autoScroll",!1);p(this,"showStatistics",!1);p(this,"stats",null);p(this,"selectionRect",null);p(this,"annotationManager",new ht);p(this,"tooltip");p(this,"pluginManager");p(this,"initialOptions");p(this,"analysis",jt);this.initialOptions=e,this.container=e.container;const t=rn(this.container,e);if((e.renderer??"webgl")==="webgpu"){const n=typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u";console.warn(`[SciChart] 'renderer: "webgpu"' requested but WebGPU renderer is experimental and not yet implemented. Falling back to WebGL. WebGPU supported: ${n}`)}this.theme=t.theme,this.backgroundColor=t.backgroundColor,this.showLegend=t.showLegend,this.showControls=t.showControls,this.autoScroll=t.autoScroll,this.showStatistics=t.showStatistics,this.dpr=t.dpr,this.xAxisOptions=t.xAxisOptions,this.xScale=t.xScale,this.yAxisOptionsMap=t.yAxisOptionsMap,this.yScales=t.yScales,this.primaryYAxisId=t.primaryYAxisId,this.webglCanvas=t.webglCanvas,this.overlayCanvas=t.overlayCanvas,this.overlayCtx=t.overlayCtx,this.renderer=new ce(this.webglCanvas),this.renderer.setDPR(this.dpr),this.overlay=new ct(this.overlayCtx,this.theme),this.pluginManager=new dn(this),this.interaction=new fi(this.container,{onZoom:(n,s)=>this.zoom({x:[n.xMin,n.xMax],y:[n.yMin,n.yMax],axisId:s}),onPan:(n,s,r)=>this.pan(n,s,r),onBoxZoom:n=>this.handleBoxZoom(n),onCursorMove:(n,s)=>{this.cursorPosition={x:n,y:s},this.tooltip.handleCursorMove(n,s),this.requestOverlayRender()},onCursorLeave:()=>{this.cursorPosition=null,this.tooltip.handleCursorLeave(),this.requestOverlayRender()}},()=>this.getPlotArea(),n=>this.getInteractedBounds(n),()=>ln(this.yAxisOptionsMap)),this.tooltip=new bt({overlayCtx:this.overlayCtx,chartTheme:this.theme,getPlotArea:()=>this.getPlotArea(),getSeries:()=>this.getAllSeries(),pixelToDataX:n=>this.pixelToDataX(n),pixelToDataY:n=>this.pixelToDataY(n),getXScale:()=>this.xScale,getYScales:()=>this.yScales,getViewBounds:()=>this.viewBounds,options:e.tooltip}),new ResizeObserver(()=>!this.isDestroyed&&this.resize()).observe(this.container),this.initControls(),this.initLegend(e),this.showStatistics&&(this.stats=new pi(this.container,this.theme,this.series)),this.resize(),this.startRenderLoop(),setTimeout(()=>!this.isDestroyed&&this.resize(),100),console.log("[SciChart] Initialized",{dpr:this.dpr,theme:this.theme.name})}get yScale(){return this.yScales.get(this.primaryYAxisId)||this.yScales.values().next().value}initControls(){this.controls=gn({container:this.container,theme:this.theme,showControls:this.showControls,showLegend:this.showLegend,series:this.series,autoScale:()=>this.autoScale(),resetZoom:()=>this.resetZoom(),requestRender:()=>this.requestRender(),exportImage:()=>this.exportImage(),setPanMode:e=>this.interaction.setPanMode(e),onLegendMove:(e,t)=>this.events.emit("legendMove",{x:e,y:t}),toggleLegend:()=>this.toggleLegend()})}toggleLegend(){this.showLegend=!this.showLegend,this.legend?(this.legend.setVisible(this.showLegend),this.legend.update(this.getAllSeries())):this.showLegend&&this.initLegend(this.initialOptions),this.requestRender()}initLegend(e){this.legend=mn({container:this.container,theme:this.theme,showControls:this.showControls,showLegend:this.showLegend,series:this.series,autoScale:()=>this.autoScale(),resetZoom:()=>this.resetZoom(),requestRender:()=>this.requestRender(),exportImage:()=>this.exportImage(),setPanMode:t=>this.interaction.setPanMode(t),onLegendMove:(t,i)=>this.events.emit("legendMove",{x:t,y:i}),toggleLegend:()=>this.toggleLegend()},e)}setTheme(e){this.theme=typeof e=="string"?Be(e):e;const t=ae(this.theme.backgroundColor);this.backgroundColor=[t[0],t[1],t[2],t[3]],this.container.style.backgroundColor=this.theme.backgroundColor,this.overlay.setTheme(this.theme),this.tooltip.updateChartTheme(this.theme),this.controls&&this.controls.updateTheme(this.theme),this.legend&&this.legend.updateTheme(this.theme),this.stats&&this.stats.updateTheme(this.theme),this.requestRender()}getPlotArea(){return an(this.container,this.yAxisOptionsMap)}getInteractedBounds(e){if(e){const t=this.yScales.get(e);if(t)return{...this.viewBounds,yMin:t.domain[0],yMax:t.domain[1]}}return this.viewBounds}exportImage(e="png"){return Ii(this.webglCanvas,this.overlayCanvas,this.backgroundColor,this.legend,this.showLegend,this.dpr,e)}getSeriesContext(){return{series:this.series,renderer:this.renderer,viewBounds:this.viewBounds,autoScale:()=>this.autoScale(),requestRender:()=>this.requestRender(),addAnnotation:e=>this.addAnnotation(e),xAxisOptions:this.xAxisOptions,yAxisOptionsMap:this.yAxisOptionsMap,autoScrollEnabled:this.autoScroll,addSeries:e=>this.addSeries(e),updateLegend:()=>{this.legend&&this.legend.update(this.getAllSeries())}}}addSeries(e){Zi(this.getSeriesContext(),e);const t=this.series.get(e.id);t&&this.pluginManager.notify("onSeriesAdded",t)}addBar(e){this.addSeries({...e,type:"bar"})}addHeatmap(e){this.addSeries({...e,type:"heatmap"})}removeSeries(e){Ji(this.getSeriesContext(),e)}updateSeries(e,t){Qi(this.getSeriesContext(),e,t)}appendData(e,t,i){en(this.getSeriesContext(),e,t,i)}setAutoScroll(e){this.autoScroll=e}setMaxPoints(e,t){tn(this.getSeriesContext(),e,t)}addFitLine(e,t,i={}){return nn(this.getSeriesContext(),e,t,i)}getSeries(e){return this.series.get(e)}getAllSeries(){return Array.from(this.series.values())}getNavContext(){return{viewBounds:this.viewBounds,yScales:this.yScales,yAxisOptionsMap:this.yAxisOptionsMap,xAxisOptions:this.xAxisOptions,primaryYAxisId:this.primaryYAxisId,getPlotArea:()=>this.getPlotArea(),events:this.events,requestRender:()=>this.requestRender(),series:this.series}}zoom(e){Ri(this.getNavContext(),e)}pan(e,t,i){Di(this.getNavContext(),e,t,i)}resetZoom(){this.autoScale(),this.events.emit("zoom",{x:[this.viewBounds.xMin,this.viewBounds.xMax],y:[this.viewBounds.yMin,this.viewBounds.yMax]}),this.requestRender()}getViewBounds(){return{...this.viewBounds}}autoScale(){Li(this.getNavContext())}handleBoxZoom(e){const t=e===null;this.selectionRect=zi(this.getNavContext(),e,this.selectionRect,i=>this.zoom(i)),t?this.requestRender():this.requestOverlayRender()}enableCursor(e){this.cursorOptions={enabled:!0,...e}}disableCursor(){this.cursorOptions=null,this.cursorPosition=null,this.requestOverlayRender()}addAnnotation(e){const t=this.annotationManager.add(e);return this.requestOverlayRender(),t}removeAnnotation(e){const t=this.annotationManager.remove(e);return this.requestOverlayRender(),t}updateAnnotation(e,t){this.annotationManager.update(e,t),this.requestOverlayRender()}getAnnotation(e){return this.annotationManager.get(e)}getAnnotations(){return this.annotationManager.getAll()}clearAnnotations(){this.annotationManager.clear(),this.requestOverlayRender()}exportCSV(e){return _i(this.getAllSeries(),e)}exportJSON(e){return Fi(this.getAllSeries(),this.viewBounds,e)}use(e){this.pluginManager.use(e)}resize(){cn(this.container,this.webglCanvas,this.overlayCanvas,this.overlayCtx,this.dpr)&&(this.renderer.resize(),this.requestRender())}requestRender(){this.needsFullRender=!0}requestOverlayRender(){this.needsOverlayRender=!0}render(e=!0){if(this.isDestroyed)return;const t=performance.now(),i=this.getPlotArea();if(this.webglCanvas.width===0||this.webglCanvas.height===0)return;const n={webglCanvas:this.webglCanvas,overlayCanvas:this.overlayCanvas,overlayCtx:this.overlayCtx,container:this.container,series:this.series,viewBounds:this.viewBounds,xScale:this.xScale,yScales:this.yScales,yAxisOptionsMap:this.yAxisOptionsMap,xAxisOptions:this.xAxisOptions,primaryYAxisId:this.primaryYAxisId,renderer:this.renderer,overlay:this.overlay,annotationManager:this.annotationManager,backgroundColor:this.backgroundColor,cursorOptions:this.cursorOptions,cursorPosition:this.cursorPosition,selectionRect:this.selectionRect,stats:this.stats,showStatistics:this.showStatistics,events:this.events,updateSeriesBuffer:s=>be(this.getSeriesContext(),s),getPlotArea:()=>i,pixelToDataX:s=>this.pixelToDataX(s),pixelToDataY:s=>this.pixelToDataY(s),tooltip:this.tooltip};if(e){const s=Gi(n,i);this.pluginManager.notify("onBeforeRender",this),this.renderer.render(s,{bounds:this.viewBounds,backgroundColor:this.backgroundColor,plotArea:i}),xt(n,i,this.yScale),this.pluginManager.notify("onAfterRender",this)}else xt(n,i,this.yScale);this.events.emit("render",{fps:1e3/(performance.now()-t),frameTime:performance.now()-t})}pixelToDataX(e){return hn(e,this.getPlotArea(),this.viewBounds)}pixelToDataY(e){return un(e,this.getPlotArea(),this.viewBounds)}startRenderLoop(){const e=()=>{this.isDestroyed||(this.needsFullRender?(this.render(!0),this.needsFullRender=!1,this.needsOverlayRender=!1):this.needsOverlayRender&&(this.render(!1),this.needsOverlayRender=!1),this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}destroy(){for(this.isDestroyed=!0,this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.interaction.destroy(),this.series.forEach(e=>{this.renderer.deleteBuffer(e.getId()),e.destroy()}),this.series.clear(),this.renderer.destroy(),this.controls&&this.controls.destroy(),this.legend&&this.legend.destroy(),this.tooltip&&this.tooltip.destroy();this.container.firstChild;)this.container.removeChild(this.container.firstChild);console.log("[SciChart] Destroyed")}}function Mt(o){return new yn(o)}function bn(o,e,t){const i=o.length;if(t>=i||t<=2)return{x:new Float32Array(o),y:new Float32Array(e),indices:new Uint32Array(Array.from({length:i},(h,u)=>u))};const n=new Float32Array(t),s=new Float32Array(t),r=new Uint32Array(t);n[0]=o[0],s[0]=e[0],r[0]=0;const a=(i-2)/(t-2);let l=0,c=1;for(let h=0;h<t-2;h++){const u=Math.floor((h+1)*a)+1,d=Math.floor((h+2)*a)+1,f=Math.min(d,i-1),g=Math.min(Math.floor((h+3)*a)+1,i);let m=0,y=0,b=0;for(let M=f;M<g;M++)m+=o[M],y+=e[M],b++;b>0&&(m/=b,y/=b);let v=-1,S=u;const T=o[l],P=e[l];for(let M=u;M<d&&M<i;M++){const _=Math.abs((T-m)*(e[M]-P)-(T-o[M])*(y-P));_>v&&(v=_,S=M)}n[c]=o[S],s[c]=e[S],r[c]=S,l=S,c++}return n[t-1]=o[i-1],s[t-1]=e[i-1],r[t-1]=i-1,{x:n,y:s,indices:r}}function xn(o,e,t){const i=o.length;if(t>=i/2)return{x:new Float32Array(o),y:new Float32Array(e),indices:new Uint32Array(Array.from({length:i},(l,c)=>c))};const n=i/t,s=[],r=[],a=[];for(let l=0;l<t;l++){const c=Math.floor(l*n),h=Math.floor((l+1)*n);let u=1/0,d=-1/0,f=c,g=c;for(let m=c;m<h&&m<i;m++)e[m]<u&&(u=e[m],f=m),e[m]>d&&(d=e[m],g=m);f<=g?(s.push(o[f],o[g]),r.push(e[f],e[g]),a.push(f,g)):(s.push(o[g],o[f]),r.push(e[g],e[f]),a.push(g,f))}return{x:new Float32Array(s),y:new Float32Array(r),indices:new Uint32Array(a)}}function vn(o,e,t=2){const i=e*t;return Math.min(o,i)}function Sn(o){if(!o||typeof o!="object")return null;if(Array.isArray(o))return o.filter(t=>typeof t=="object"&&t!==null&&typeof t.x=="number"&&typeof t.y=="number");const e=o;return typeof e.x=="number"&&typeof e.y=="number"?{x:e.x,y:e.y,seriesId:typeof e.seriesId=="string"?e.seriesId:void 0}:null}function wn(o){return e=>{try{return o(e)}catch{return null}}}function Tn(o,e,t=["default"]){const i=[];for(const n of t){const s=o.subscribe(n,r=>{if(r.length===0)return;const a=new Float32Array(r.map(c=>c.x)),l=new Float32Array(r.map(c=>c.y));e.appendData(n,{x:a,y:l})});i.push(s)}return()=>{for(const n of i)n()}}function Mn(o){const{url:e,maxReconnectAttempts:t=5,reconnectDelay:i=1e3,bufferSize:n=10,throttleMs:s=16,parseMessage:r=Sn,onConnect:a,onDisconnect:l,onError:c,onReconnect:h}=o;let u=null,d="disconnected",f=0,g=null,m=null;const y=new Map,b=new Map,v={messagesReceived:0,pointsProcessed:0,reconnectCount:0,lastMessageTime:null,connectionUptime:0,bufferSize:0};let S=0,T=!1;function P(){if(!(u&&(u.readyState===WebSocket.OPEN||u.readyState===WebSocket.CONNECTING))){d="connecting";try{u=new WebSocket(e),u.onopen=()=>{d="connected",f=0,m=Date.now(),a==null||a()},u.onmessage=k=>B(k.data),u.onclose=k=>{d="disconnected",m=null,l==null||l(k),!k.wasClean&&f<t&&_()},u.onerror=k=>{d="error",c==null||c(k)}}catch(k){d="error",c==null||c(k)}}}function M(){g&&(clearTimeout(g),g=null),u&&(u.close(1e3,"Client disconnect"),u=null),d="disconnected",f=0,y.clear()}function _(){g||(d="reconnecting",f++,v.reconnectCount++,h==null||h(f),g=setTimeout(()=>{g=null,P()},i*f))}function B(k){v.messagesReceived++,v.lastMessageTime=Date.now();try{const F=typeof k=="string"?JSON.parse(k):k,O=r(F);if(!O)return;const se=Array.isArray(O)?O:[O];for(const W of se){const H=W.seriesId||"default";y.has(H)||y.set(H,[]),y.get(H).push(W),v.pointsProcessed++}v.bufferSize=Array.from(y.values()).reduce((W,H)=>W+H.length,0),R()}catch{}}function R(){if(T)return;const F=performance.now()-S;F>=s?G():(T=!0,setTimeout(()=>{T=!1,G()},s-F))}function G(){S=performance.now();for(const[k,F]of y.entries())if(F.length!==0&&(F.length>=n||performance.now()-S>s*2)){const O=b.get(k);if(O){const se=F.splice(0,F.length);for(const W of O)W(se)}else F.length=0}v.bufferSize=Array.from(y.values()).reduce((k,F)=>k+F.length,0)}return{connect:P,disconnect:M,isConnected:()=>u!==null&&u.readyState===WebSocket.OPEN,getState:()=>d,subscribe:(k,F)=>(b.has(k)||b.set(k,new Set),b.get(k).add(F),()=>{const O=b.get(k);O&&(O.delete(F),O.size===0&&b.delete(k))}),unsubscribeAll:()=>{b.clear(),y.clear()},send:k=>{u&&u.readyState===WebSocket.OPEN&&u.send(typeof k=="string"?k:JSON.stringify(k))},getStats:()=>({...v,connectionUptime:m?Date.now()-m:0})}}function Pn(o){const{interval:e=100,generatePoint:t=Cn}=o;let i=null,n=!1;const s=new Map,r={messagesReceived:0,pointsProcessed:0,reconnectCount:0,lastMessageTime:null,connectionUptime:0,bufferSize:0};let a=null;function l(){i||(a=Date.now(),i=setInterval(()=>{const h=t();r.messagesReceived++,r.pointsProcessed++,r.lastMessageTime=Date.now();const u=h.seriesId||"default",d=s.get(u);if(d)for(const f of d)f([h])},e))}function c(){i&&(clearInterval(i),i=null),a=null}return{connect:()=>{n=!0,l()},disconnect:()=>{n=!1,c()},isConnected:()=>n,getState:()=>n?"connected":"disconnected",subscribe:(h,u)=>(s.has(h)||s.set(h,new Set),s.get(h).add(u),()=>{var d;(d=s.get(h))==null||d.delete(u)}),unsubscribeAll:()=>s.clear(),send:()=>{},getStats:()=>({...r,connectionUptime:a?Date.now()-a:0}),start:l,stop:c}}let Pt=0;function Cn(){return{x:Pt++,y:Math.sin(Pt*.1)+Math.random()*.2}}var Le={exports:{}},ie={};/**
|
|
243
|
+
`;const r=document.createElement("canvas"),s=e.swatchSize;r.width=s*t,r.height=s*t,r.style.width=`${s}px`,r.style.height=`${s}px`;const a=r.getContext("2d");if(a){a.scale(t,t);const c=i.getStyle(),h=c.color||"#ff0055",u=i.getType(),d=c.symbol||"circle";a.fillStyle=h,a.strokeStyle=h,a.lineWidth=2;const f=s/2,g=s/2,m=String(u).toLowerCase(),y=m==="scatter"||m==="1"||m==="line"&&!!c.symbol,b=m.includes("scatter")||m==="2",v=m==="area"||m==="band";if(y)this.drawSymbol(a,d,f,g,s*.8);else if(b)a.beginPath(),a.moveTo(0,g),a.lineTo(s,g),a.stroke(),this.drawSymbol(a,d,f,g,s*.6);else if(v)a.globalAlpha=.6,a.fillRect(0,s*.2,s,s*.6),a.globalAlpha=1,a.strokeRect(0,s*.2,s,s*.6);else if(m==="candlestick"){const S=c.bullishColor||"#26a69a";a.fillStyle=S,a.fillRect(s*.3,s*.2,s*.4,s*.6),a.beginPath(),a.moveTo(s*.5,0),a.lineTo(s*.5,s),a.strokeStyle=S,a.stroke()}else a.beginPath(),a.moveTo(0,g),a.lineTo(s,g),a.stroke()}const l=document.createElement("span");l.textContent=i.getName(),n.appendChild(r),n.appendChild(l),this.content.appendChild(n)})}drawSymbol(e,t,i,n,r){const s=r/2;switch(e.beginPath(),t){case"circle":e.arc(i,n,s,0,Math.PI*2),e.fill();break;case"square":e.rect(i-s,n-s,r,r),e.fill();break;case"diamond":e.moveTo(i,n-s),e.lineTo(i+s,n),e.lineTo(i,n+s),e.lineTo(i-s,n),e.closePath(),e.fill();break;case"triangle":e.moveTo(i,n-s),e.lineTo(i+s,n+s),e.lineTo(i-s,n+s),e.closePath(),e.fill();break;case"triangleDown":e.moveTo(i,n+s),e.lineTo(i+s,n-s),e.lineTo(i-s,n-s),e.closePath(),e.fill();break;case"cross":e.moveTo(i-s,n),e.lineTo(i+s,n),e.moveTo(i,n-s),e.lineTo(i,n+s),e.stroke();break;case"x":const a=s*.707;e.moveTo(i-a,n-a),e.lineTo(i+a,n+a),e.moveTo(i+a,n-a),e.lineTo(i-a,n+a),e.stroke();break;case"star":for(let l=0;l<5;l++)e.lineTo(i+s*Math.cos((18+l*72)/180*Math.PI),n-s*Math.sin((18+l*72)/180*Math.PI)),e.lineTo(i+s/2*Math.cos((54+l*72)/180*Math.PI),n-s/2*Math.sin((54+l*72)/180*Math.PI));e.closePath(),e.fill();break}}draw(e,t){if(this.series.length===0)return;const i=this.theme.legend,n=i.padding*t,r=i.itemGap*t,s=i.swatchSize*t,a=8*t,l=this.container.offsetLeft*t,c=this.container.offsetTop*t,h=this.container.clientWidth*t,u=this.container.clientHeight*t;e.save();const d=this.theme.name.toLowerCase().includes("dark")||this.theme.name.toLowerCase().includes("midnight");e.fillStyle=d?i.backgroundColor:"rgba(255, 255, 255, 0.85)",e.strokeStyle=i.borderColor,e.lineWidth=1*t;const f=i.borderRadius*t;e.beginPath(),e.moveTo(l+f,c),e.lineTo(l+h-f,c),e.arcTo(l+h,c,l+h,c+f,f),e.lineTo(l+h,c+u-f),e.arcTo(l+h,c+u,l+h-f,c+u,f),e.lineTo(l+f,c+u),e.arcTo(l,c+u,l,c+u-f,f),e.lineTo(l,c+f),e.arcTo(l,c,l+f,c,f),e.closePath(),e.fill(),e.stroke(),e.textAlign="left",e.textBaseline="middle",e.font=`${i.fontSize*t}px ${i.fontFamily}`,this.series.forEach((g,m)=>{const y=c+a+n+m*(s+r)+s/2,b=l+n+s/2,v=y,S=g.getStyle(),T=g.getType(),P=S.symbol||"circle";e.fillStyle=S.color||"#ff0055",e.strokeStyle=S.color||"#ff0055",e.lineWidth=2*t;const M=String(T).toLowerCase(),_=M==="scatter"||M==="1"||M==="line"&&!!S.symbol,B=M.includes("scatter")||M==="2";_?this.drawSymbol(e,P,b,v,s*.9):B?(e.beginPath(),e.moveTo(l+n,v),e.lineTo(l+n+s,v),e.stroke(),this.drawSymbol(e,P,b,v,s*.6)):(e.beginPath(),e.moveTo(l+n,v),e.lineTo(l+n+s,v),e.stroke()),e.fillStyle=i.textColor,e.fillText(g.getName(),l+n+s+8*t,y)}),e.restore()}updateTheme(e){this.theme=e,this.updateStyle(),this.render()}setVisible(e){this.container.style.display=e?"block":"none"}destroy(){this.container.remove()}}function gn(o){return o.showControls?new fn(o.container,o.theme,{onResetZoom:()=>o.resetZoom(),onSetType:e=>{o.series.forEach(t=>{const i=t.getType(),n=t.getStyle();if(i==="step"||i==="step+scatter"||n.stepMode!==void 0){const s=e==="line"?"step":e==="line+scatter"?"step+scatter":"scatter";t.setType(s)}else(i==="line"||i==="scatter"||i==="line+scatter")&&t.setType(e)}),o.requestRender()},onToggleSmoothing:()=>{o.series.forEach(e=>{const t=e.getStyle();e.setStyle({smoothing:(t.smoothing||0)===0?.5:0})}),o.requestRender()},onTogglePan:e=>o.setPanMode(e),onExport:()=>{const e=document.createElement("a");e.download=`scichart-export-${Date.now()}.png`,e.href=o.exportImage(),e.click()},onAutoScale:()=>{o.autoScale(),o.requestRender()},onToggleLegend:()=>{o.toggleLegend()}}):null}function mn(o,e){if(!o.showLegend)return null;const t=new pn(o.container,o.theme,e.legendPosition||{},{onMove:(i,n)=>o.onLegendMove(i,n)});return t.update(Array.from(o.series.values())),t}class yn{constructor(e){p(this,"container");p(this,"webglCanvas");p(this,"overlayCanvas");p(this,"overlayCtx");p(this,"series",new Map);p(this,"events",new Pe);p(this,"viewBounds",{xMin:-.5,xMax:.5,yMin:-1e-5,yMax:1e-5});p(this,"xAxisOptions");p(this,"yAxisOptionsMap");p(this,"primaryYAxisId");p(this,"dpr");p(this,"backgroundColor");p(this,"renderer");p(this,"overlay");p(this,"interaction");p(this,"xScale");p(this,"yScales");p(this,"theme");p(this,"cursorOptions",null);p(this,"cursorPosition",null);p(this,"showLegend");p(this,"legend",null);p(this,"showControls");p(this,"controls",null);p(this,"animationFrameId",null);p(this,"needsFullRender",!1);p(this,"needsOverlayRender",!1);p(this,"isDestroyed",!1);p(this,"autoScroll",!1);p(this,"showStatistics",!1);p(this,"stats",null);p(this,"selectionRect",null);p(this,"annotationManager",new ht);p(this,"tooltip");p(this,"pluginManager");p(this,"initialOptions");p(this,"analysis",jt);this.initialOptions=e,this.container=e.container;const t=sn(this.container,e);if((e.renderer??"webgl")==="webgpu"){const n=typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u";console.warn(`[SciChart] 'renderer: "webgpu"' requested but WebGPU renderer is experimental and not yet implemented. Falling back to WebGL. WebGPU supported: ${n}`)}this.theme=t.theme,this.backgroundColor=t.backgroundColor,this.showLegend=t.showLegend,this.showControls=t.showControls,this.autoScroll=t.autoScroll,this.showStatistics=t.showStatistics,this.dpr=t.dpr,this.xAxisOptions=t.xAxisOptions,this.xScale=t.xScale,this.yAxisOptionsMap=t.yAxisOptionsMap,this.yScales=t.yScales,this.primaryYAxisId=t.primaryYAxisId,this.webglCanvas=t.webglCanvas,this.overlayCanvas=t.overlayCanvas,this.overlayCtx=t.overlayCtx,this.renderer=new ce(this.webglCanvas),this.renderer.setDPR(this.dpr),this.overlay=new ct(this.overlayCtx,this.theme),this.pluginManager=new dn(this),this.interaction=new fi(this.container,{onZoom:(n,r)=>this.zoom({x:[n.xMin,n.xMax],y:[n.yMin,n.yMax],axisId:r}),onPan:(n,r,s)=>this.pan(n,r,s),onBoxZoom:n=>this.handleBoxZoom(n),onCursorMove:(n,r)=>{this.cursorPosition={x:n,y:r},this.tooltip.handleCursorMove(n,r),this.requestOverlayRender()},onCursorLeave:()=>{this.cursorPosition=null,this.tooltip.handleCursorLeave(),this.requestOverlayRender()}},()=>this.getPlotArea(),n=>this.getInteractedBounds(n),()=>ln(this.yAxisOptionsMap)),this.tooltip=new bt({overlayCtx:this.overlayCtx,chartTheme:this.theme,getPlotArea:()=>this.getPlotArea(),getSeries:()=>this.getAllSeries(),pixelToDataX:n=>this.pixelToDataX(n),pixelToDataY:n=>this.pixelToDataY(n),getXScale:()=>this.xScale,getYScales:()=>this.yScales,getViewBounds:()=>this.viewBounds,options:e.tooltip}),new ResizeObserver(()=>!this.isDestroyed&&this.resize()).observe(this.container),this.initControls(),this.initLegend(e),this.showStatistics&&(this.stats=new pi(this.container,this.theme,this.series)),this.resize(),this.startRenderLoop(),setTimeout(()=>!this.isDestroyed&&this.resize(),100),console.log("[SciChart] Initialized",{dpr:this.dpr,theme:this.theme.name})}get yScale(){return this.yScales.get(this.primaryYAxisId)||this.yScales.values().next().value}initControls(){this.controls=gn({container:this.container,theme:this.theme,showControls:this.showControls,showLegend:this.showLegend,series:this.series,autoScale:()=>this.autoScale(),resetZoom:()=>this.resetZoom(),requestRender:()=>this.requestRender(),exportImage:()=>this.exportImage(),setPanMode:e=>this.interaction.setPanMode(e),onLegendMove:(e,t)=>this.events.emit("legendMove",{x:e,y:t}),toggleLegend:()=>this.toggleLegend()})}toggleLegend(){this.showLegend=!this.showLegend,this.legend?(this.legend.setVisible(this.showLegend),this.legend.update(this.getAllSeries())):this.showLegend&&this.initLegend(this.initialOptions),this.requestRender()}initLegend(e){this.legend=mn({container:this.container,theme:this.theme,showControls:this.showControls,showLegend:this.showLegend,series:this.series,autoScale:()=>this.autoScale(),resetZoom:()=>this.resetZoom(),requestRender:()=>this.requestRender(),exportImage:()=>this.exportImage(),setPanMode:t=>this.interaction.setPanMode(t),onLegendMove:(t,i)=>this.events.emit("legendMove",{x:t,y:i}),toggleLegend:()=>this.toggleLegend()},e)}setTheme(e){this.theme=typeof e=="string"?Be(e):e;const t=ae(this.theme.backgroundColor);this.backgroundColor=[t[0],t[1],t[2],t[3]],this.container.style.backgroundColor=this.theme.backgroundColor,this.overlay.setTheme(this.theme),this.tooltip.updateChartTheme(this.theme),this.controls&&this.controls.updateTheme(this.theme),this.legend&&this.legend.updateTheme(this.theme),this.stats&&this.stats.updateTheme(this.theme),this.requestRender()}getPlotArea(){return an(this.container,this.yAxisOptionsMap)}getInteractedBounds(e){if(e){const t=this.yScales.get(e);if(t)return{...this.viewBounds,yMin:t.domain[0],yMax:t.domain[1]}}return this.viewBounds}exportImage(e="png"){return Ii(this.webglCanvas,this.overlayCanvas,this.backgroundColor,this.legend,this.showLegend,this.dpr,e)}getSeriesContext(){return{series:this.series,renderer:this.renderer,viewBounds:this.viewBounds,autoScale:()=>this.autoScale(),requestRender:()=>this.requestRender(),addAnnotation:e=>this.addAnnotation(e),xAxisOptions:this.xAxisOptions,yAxisOptionsMap:this.yAxisOptionsMap,autoScrollEnabled:this.autoScroll,addSeries:e=>this.addSeries(e),updateLegend:()=>{this.legend&&this.legend.update(this.getAllSeries())}}}addSeries(e){Zi(this.getSeriesContext(),e);const t=this.series.get(e.id);t&&this.pluginManager.notify("onSeriesAdded",t)}addBar(e){this.addSeries({...e,type:"bar"})}addHeatmap(e){this.addSeries({...e,type:"heatmap"})}removeSeries(e){Ji(this.getSeriesContext(),e)}updateSeries(e,t){Qi(this.getSeriesContext(),e,t)}appendData(e,t,i){en(this.getSeriesContext(),e,t,i)}setAutoScroll(e){this.autoScroll=e}setMaxPoints(e,t){tn(this.getSeriesContext(),e,t)}addFitLine(e,t,i={}){return nn(this.getSeriesContext(),e,t,i)}getSeries(e){return this.series.get(e)}getAllSeries(){return Array.from(this.series.values())}getNavContext(){return{viewBounds:this.viewBounds,yScales:this.yScales,yAxisOptionsMap:this.yAxisOptionsMap,xAxisOptions:this.xAxisOptions,primaryYAxisId:this.primaryYAxisId,getPlotArea:()=>this.getPlotArea(),events:this.events,requestRender:()=>this.requestRender(),series:this.series}}zoom(e){Ri(this.getNavContext(),e)}pan(e,t,i){Di(this.getNavContext(),e,t,i)}resetZoom(){this.autoScale(),this.events.emit("zoom",{x:[this.viewBounds.xMin,this.viewBounds.xMax],y:[this.viewBounds.yMin,this.viewBounds.yMax]}),this.requestRender()}getViewBounds(){return{...this.viewBounds}}autoScale(){Li(this.getNavContext())}handleBoxZoom(e){const t=e===null;this.selectionRect=zi(this.getNavContext(),e,this.selectionRect,i=>this.zoom(i)),t?this.requestRender():this.requestOverlayRender()}enableCursor(e){this.cursorOptions={enabled:!0,...e}}disableCursor(){this.cursorOptions=null,this.cursorPosition=null,this.requestOverlayRender()}addAnnotation(e){const t=this.annotationManager.add(e);return this.requestOverlayRender(),t}removeAnnotation(e){const t=this.annotationManager.remove(e);return this.requestOverlayRender(),t}updateAnnotation(e,t){this.annotationManager.update(e,t),this.requestOverlayRender()}getAnnotation(e){return this.annotationManager.get(e)}getAnnotations(){return this.annotationManager.getAll()}clearAnnotations(){this.annotationManager.clear(),this.requestOverlayRender()}exportCSV(e){return _i(this.getAllSeries(),e)}exportJSON(e){return Fi(this.getAllSeries(),this.viewBounds,e)}use(e){this.pluginManager.use(e)}resize(){cn(this.container,this.webglCanvas,this.overlayCanvas,this.overlayCtx,this.dpr)&&(this.renderer.resize(),this.requestRender())}requestRender(){this.needsFullRender=!0}requestOverlayRender(){this.needsOverlayRender=!0}render(e=!0){if(this.isDestroyed)return;const t=performance.now(),i=this.getPlotArea();if(this.webglCanvas.width===0||this.webglCanvas.height===0)return;const n={webglCanvas:this.webglCanvas,overlayCanvas:this.overlayCanvas,overlayCtx:this.overlayCtx,container:this.container,series:this.series,viewBounds:this.viewBounds,xScale:this.xScale,yScales:this.yScales,yAxisOptionsMap:this.yAxisOptionsMap,xAxisOptions:this.xAxisOptions,primaryYAxisId:this.primaryYAxisId,renderer:this.renderer,overlay:this.overlay,annotationManager:this.annotationManager,backgroundColor:this.backgroundColor,cursorOptions:this.cursorOptions,cursorPosition:this.cursorPosition,selectionRect:this.selectionRect,stats:this.stats,showStatistics:this.showStatistics,events:this.events,updateSeriesBuffer:r=>be(this.getSeriesContext(),r),getPlotArea:()=>i,pixelToDataX:r=>this.pixelToDataX(r),pixelToDataY:r=>this.pixelToDataY(r),tooltip:this.tooltip};if(e){const r=Gi(n,i);this.pluginManager.notify("onBeforeRender",this),this.renderer.render(r,{bounds:this.viewBounds,backgroundColor:this.backgroundColor,plotArea:i}),xt(n,i,this.yScale),this.pluginManager.notify("onAfterRender",this)}else xt(n,i,this.yScale);this.events.emit("render",{fps:1e3/(performance.now()-t),frameTime:performance.now()-t})}pixelToDataX(e){return hn(e,this.getPlotArea(),this.viewBounds)}pixelToDataY(e){return un(e,this.getPlotArea(),this.viewBounds)}startRenderLoop(){const e=()=>{this.isDestroyed||(this.needsFullRender?(this.render(!0),this.needsFullRender=!1,this.needsOverlayRender=!1):this.needsOverlayRender&&(this.render(!1),this.needsOverlayRender=!1),this.animationFrameId=requestAnimationFrame(e))};this.animationFrameId=requestAnimationFrame(e)}on(e,t){this.events.on(e,t)}off(e,t){this.events.off(e,t)}destroy(){for(this.isDestroyed=!0,this.animationFrameId&&cancelAnimationFrame(this.animationFrameId),this.interaction.destroy(),this.series.forEach(e=>{this.renderer.deleteBuffer(e.getId()),e.destroy()}),this.series.clear(),this.renderer.destroy(),this.controls&&this.controls.destroy(),this.legend&&this.legend.destroy(),this.tooltip&&this.tooltip.destroy();this.container.firstChild;)this.container.removeChild(this.container.firstChild);console.log("[SciChart] Destroyed")}}function Mt(o){return new yn(o)}function bn(o,e,t){const i=o.length;if(t>=i||t<=2)return{x:new Float32Array(o),y:new Float32Array(e),indices:new Uint32Array(Array.from({length:i},(h,u)=>u))};const n=new Float32Array(t),r=new Float32Array(t),s=new Uint32Array(t);n[0]=o[0],r[0]=e[0],s[0]=0;const a=(i-2)/(t-2);let l=0,c=1;for(let h=0;h<t-2;h++){const u=Math.floor((h+1)*a)+1,d=Math.floor((h+2)*a)+1,f=Math.min(d,i-1),g=Math.min(Math.floor((h+3)*a)+1,i);let m=0,y=0,b=0;for(let M=f;M<g;M++)m+=o[M],y+=e[M],b++;b>0&&(m/=b,y/=b);let v=-1,S=u;const T=o[l],P=e[l];for(let M=u;M<d&&M<i;M++){const _=Math.abs((T-m)*(e[M]-P)-(T-o[M])*(y-P));_>v&&(v=_,S=M)}n[c]=o[S],r[c]=e[S],s[c]=S,l=S,c++}return n[t-1]=o[i-1],r[t-1]=e[i-1],s[t-1]=i-1,{x:n,y:r,indices:s}}function xn(o,e,t){const i=o.length;if(t>=i/2)return{x:new Float32Array(o),y:new Float32Array(e),indices:new Uint32Array(Array.from({length:i},(l,c)=>c))};const n=i/t,r=[],s=[],a=[];for(let l=0;l<t;l++){const c=Math.floor(l*n),h=Math.floor((l+1)*n);let u=1/0,d=-1/0,f=c,g=c;for(let m=c;m<h&&m<i;m++)e[m]<u&&(u=e[m],f=m),e[m]>d&&(d=e[m],g=m);f<=g?(r.push(o[f],o[g]),s.push(e[f],e[g]),a.push(f,g)):(r.push(o[g],o[f]),s.push(e[g],e[f]),a.push(g,f))}return{x:new Float32Array(r),y:new Float32Array(s),indices:new Uint32Array(a)}}function vn(o,e,t=2){const i=e*t;return Math.min(o,i)}function Sn(o){if(!o||typeof o!="object")return null;if(Array.isArray(o))return o.filter(t=>typeof t=="object"&&t!==null&&typeof t.x=="number"&&typeof t.y=="number");const e=o;return typeof e.x=="number"&&typeof e.y=="number"?{x:e.x,y:e.y,seriesId:typeof e.seriesId=="string"?e.seriesId:void 0}:null}function wn(o){return e=>{try{return o(e)}catch{return null}}}function Tn(o,e,t=["default"]){const i=[];for(const n of t){const r=o.subscribe(n,s=>{if(s.length===0)return;const a=new Float32Array(s.map(c=>c.x)),l=new Float32Array(s.map(c=>c.y));e.appendData(n,{x:a,y:l})});i.push(r)}return()=>{for(const n of i)n()}}function Mn(o){const{url:e,maxReconnectAttempts:t=5,reconnectDelay:i=1e3,bufferSize:n=10,throttleMs:r=16,parseMessage:s=Sn,onConnect:a,onDisconnect:l,onError:c,onReconnect:h}=o;let u=null,d="disconnected",f=0,g=null,m=null;const y=new Map,b=new Map,v={messagesReceived:0,pointsProcessed:0,reconnectCount:0,lastMessageTime:null,connectionUptime:0,bufferSize:0};let S=0,T=!1;function P(){if(!(u&&(u.readyState===WebSocket.OPEN||u.readyState===WebSocket.CONNECTING))){d="connecting";try{u=new WebSocket(e),u.onopen=()=>{d="connected",f=0,m=Date.now(),a==null||a()},u.onmessage=k=>B(k.data),u.onclose=k=>{d="disconnected",m=null,l==null||l(k),!k.wasClean&&f<t&&_()},u.onerror=k=>{d="error",c==null||c(k)}}catch(k){d="error",c==null||c(k)}}}function M(){g&&(clearTimeout(g),g=null),u&&(u.close(1e3,"Client disconnect"),u=null),d="disconnected",f=0,y.clear()}function _(){g||(d="reconnecting",f++,v.reconnectCount++,h==null||h(f),g=setTimeout(()=>{g=null,P()},i*f))}function B(k){v.messagesReceived++,v.lastMessageTime=Date.now();try{const F=typeof k=="string"?JSON.parse(k):k,O=s(F);if(!O)return;const re=Array.isArray(O)?O:[O];for(const W of re){const H=W.seriesId||"default";y.has(H)||y.set(H,[]),y.get(H).push(W),v.pointsProcessed++}v.bufferSize=Array.from(y.values()).reduce((W,H)=>W+H.length,0),R()}catch{}}function R(){if(T)return;const F=performance.now()-S;F>=r?G():(T=!0,setTimeout(()=>{T=!1,G()},r-F))}function G(){S=performance.now();for(const[k,F]of y.entries())if(F.length!==0&&(F.length>=n||performance.now()-S>r*2)){const O=b.get(k);if(O){const re=F.splice(0,F.length);for(const W of O)W(re)}else F.length=0}v.bufferSize=Array.from(y.values()).reduce((k,F)=>k+F.length,0)}return{connect:P,disconnect:M,isConnected:()=>u!==null&&u.readyState===WebSocket.OPEN,getState:()=>d,subscribe:(k,F)=>(b.has(k)||b.set(k,new Set),b.get(k).add(F),()=>{const O=b.get(k);O&&(O.delete(F),O.size===0&&b.delete(k))}),unsubscribeAll:()=>{b.clear(),y.clear()},send:k=>{u&&u.readyState===WebSocket.OPEN&&u.send(typeof k=="string"?k:JSON.stringify(k))},getStats:()=>({...v,connectionUptime:m?Date.now()-m:0})}}function Pn(o){const{interval:e=100,generatePoint:t=Cn}=o;let i=null,n=!1;const r=new Map,s={messagesReceived:0,pointsProcessed:0,reconnectCount:0,lastMessageTime:null,connectionUptime:0,bufferSize:0};let a=null;function l(){i||(a=Date.now(),i=setInterval(()=>{const h=t();s.messagesReceived++,s.pointsProcessed++,s.lastMessageTime=Date.now();const u=h.seriesId||"default",d=r.get(u);if(d)for(const f of d)f([h])},e))}function c(){i&&(clearInterval(i),i=null),a=null}return{connect:()=>{n=!0,l()},disconnect:()=>{n=!1,c()},isConnected:()=>n,getState:()=>n?"connected":"disconnected",subscribe:(h,u)=>(r.has(h)||r.set(h,new Set),r.get(h).add(u),()=>{var d;(d=r.get(h))==null||d.delete(u)}),unsubscribeAll:()=>r.clear(),send:()=>{},getStats:()=>({...s,connectionUptime:a?Date.now()-a:0}),start:l,stop:c}}let Pt=0;function Cn(){return{x:Pt++,y:Math.sin(Pt*.1)+Math.random()*.2}}var Le={exports:{}},ie={};/**
|
|
244
244
|
* @license React
|
|
245
245
|
* react-jsx-runtime.production.js
|
|
246
246
|
*
|
|
@@ -248,7 +248,7 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
248
248
|
*
|
|
249
249
|
* This source code is licensed under the MIT license found in the
|
|
250
250
|
* LICENSE file in the root directory of this source tree.
|
|
251
|
-
*/var Ct;function kn(){if(Ct)return ie;Ct=1;var o=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(i,n,
|
|
251
|
+
*/var Ct;function kn(){if(Ct)return ie;Ct=1;var o=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function t(i,n,r){var s=null;if(r!==void 0&&(s=""+r),n.key!==void 0&&(s=""+n.key),"key"in n){r={};for(var a in n)a!=="key"&&(r[a]=n[a])}else r=n;return n=r.ref,{$$typeof:o,type:i,key:s,ref:n!==void 0?n:null,props:r}}return ie.Fragment=e,ie.jsx=t,ie.jsxs=t,ie}var ne={};/**
|
|
252
252
|
* @license React
|
|
253
253
|
* react-jsx-runtime.development.js
|
|
254
254
|
*
|
|
@@ -256,12 +256,12 @@ Y: ${o.pixelToDataY(o.cursorPosition.y).toExponential(2)}`};o.overlay.drawCursor
|
|
|
256
256
|
*
|
|
257
257
|
* This source code is licensed under the MIT license found in the
|
|
258
258
|
* LICENSE file in the root directory of this source tree.
|
|
259
|
-
*/var kt;function En(){return kt||(kt=1,process.env.NODE_ENV!=="production"&&function(){function o(x){if(x==null)return null;if(typeof x=="function")return x.$$typeof===k?null:x.displayName||x.name||null;if(typeof x=="string")return x;switch(x){case y:return"Fragment";case v:return"Profiler";case b:return"StrictMode";case M:return"Suspense";case _:return"SuspenseList";case G:return"Activity"}if(typeof x=="object")switch(typeof x.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),x.$$typeof){case m:return"Portal";case T:return x.displayName||"Context";case S:return(x._context.displayName||"Context")+".Consumer";case P:var C=x.render;return x=x.displayName,x||(x=C.displayName||C.name||"",x=x!==""?"ForwardRef("+x+")":"ForwardRef"),x;case B:return C=x.displayName||null,C!==null?C:o(x.type)||"Memo";case R:C=x._payload,x=x._init;try{return o(x(C))}catch{}}return null}function e(x){return""+x}function t(x){try{e(x);var C=!1}catch{C=!0}if(C){C=console;var D=C.error,L=typeof Symbol=="function"&&Symbol.toStringTag&&x[Symbol.toStringTag]||x.constructor.name||"Object";return D.call(C,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",L),e(x)}}function i(x){if(x===y)return"<>";if(typeof x=="object"&&x!==null&&x.$$typeof===R)return"<...>";try{var C=o(x);return C?"<"+C+">":"<...>"}catch{return"<...>"}}function n(){var x=F.A;return x===null?null:x.getOwner()}function
|
|
259
|
+
*/var kt;function En(){return kt||(kt=1,process.env.NODE_ENV!=="production"&&function(){function o(x){if(x==null)return null;if(typeof x=="function")return x.$$typeof===k?null:x.displayName||x.name||null;if(typeof x=="string")return x;switch(x){case y:return"Fragment";case v:return"Profiler";case b:return"StrictMode";case M:return"Suspense";case _:return"SuspenseList";case G:return"Activity"}if(typeof x=="object")switch(typeof x.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),x.$$typeof){case m:return"Portal";case T:return x.displayName||"Context";case S:return(x._context.displayName||"Context")+".Consumer";case P:var C=x.render;return x=x.displayName,x||(x=C.displayName||C.name||"",x=x!==""?"ForwardRef("+x+")":"ForwardRef"),x;case B:return C=x.displayName||null,C!==null?C:o(x.type)||"Memo";case R:C=x._payload,x=x._init;try{return o(x(C))}catch{}}return null}function e(x){return""+x}function t(x){try{e(x);var C=!1}catch{C=!0}if(C){C=console;var D=C.error,L=typeof Symbol=="function"&&Symbol.toStringTag&&x[Symbol.toStringTag]||x.constructor.name||"Object";return D.call(C,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",L),e(x)}}function i(x){if(x===y)return"<>";if(typeof x=="object"&&x!==null&&x.$$typeof===R)return"<...>";try{var C=o(x);return C?"<"+C+">":"<...>"}catch{return"<...>"}}function n(){var x=F.A;return x===null?null:x.getOwner()}function r(){return Error("react-stack-top-frame")}function s(x){if(O.call(x,"key")){var C=Object.getOwnPropertyDescriptor(x,"key").get;if(C&&C.isReactWarning)return!1}return x.key!==void 0}function a(x,C){function D(){H||(H=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",C))}D.isReactWarning=!0,Object.defineProperty(x,"key",{get:D,configurable:!0})}function l(){var x=o(this.type);return Dt[x]||(Dt[x]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),x=this.props.ref,x!==void 0?x:null}function c(x,C,D,L,we,Ye){var z=D.ref;return x={$$typeof:g,type:x,key:C,props:D,_owner:L},(z!==void 0?z:null)!==null?Object.defineProperty(x,"ref",{enumerable:!1,get:l}):Object.defineProperty(x,"ref",{enumerable:!1,value:null}),x._store={},Object.defineProperty(x._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(x,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(x,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:we}),Object.defineProperty(x,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:Ye}),Object.freeze&&(Object.freeze(x.props),Object.freeze(x)),x}function h(x,C,D,L,we,Ye){var z=C.children;if(z!==void 0)if(L)if(re(z)){for(L=0;L<z.length;L++)u(z[L]);Object.freeze&&Object.freeze(z)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else u(z);if(O.call(C,"key")){z=o(x);var ee=Object.keys(C).filter(function(So){return So!=="key"});L=0<ee.length?"{key: someKey, "+ee.join(": ..., ")+": ...}":"{key: someKey}",Gt[z+L]||(ee=0<ee.length?"{"+ee.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
260
260
|
let props = %s;
|
|
261
261
|
<%s {...props} />
|
|
262
262
|
React keys must be passed directly to JSX without using spread:
|
|
263
263
|
let props = %s;
|
|
264
|
-
<%s key={someKey} {...props} />`,L,z,ee,z),Gt[z+L]=!0)}if(z=null,D!==void 0&&(t(D),z=""+D),
|
|
264
|
+
<%s key={someKey} {...props} />`,L,z,ee,z),Gt[z+L]=!0)}if(z=null,D!==void 0&&(t(D),z=""+D),s(C)&&(t(C.key),z=""+C.key),"key"in C){D={};for(var Ve in C)Ve!=="key"&&(D[Ve]=C[Ve])}else D=C;return z&&a(D,typeof x=="function"?x.displayName||x.name||"Unknown":x),c(x,z,D,n(),we,Ye)}function u(x){d(x)?x._store&&(x._store.validated=1):typeof x=="object"&&x!==null&&x.$$typeof===R&&(x._payload.status==="fulfilled"?d(x._payload.value)&&x._payload.value._store&&(x._payload.value._store.validated=1):x._store&&(x._store.validated=1))}function d(x){return typeof x=="object"&&x!==null&&x.$$typeof===g}var f=A,g=Symbol.for("react.transitional.element"),m=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),b=Symbol.for("react.strict_mode"),v=Symbol.for("react.profiler"),S=Symbol.for("react.consumer"),T=Symbol.for("react.context"),P=Symbol.for("react.forward_ref"),M=Symbol.for("react.suspense"),_=Symbol.for("react.suspense_list"),B=Symbol.for("react.memo"),R=Symbol.for("react.lazy"),G=Symbol.for("react.activity"),k=Symbol.for("react.client.reference"),F=f.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,O=Object.prototype.hasOwnProperty,re=Array.isArray,W=console.createTask?console.createTask:function(){return null};f={react_stack_bottom_frame:function(x){return x()}};var H,Dt={},Lt=f.react_stack_bottom_frame.bind(f,r)(),zt=W(i(r)),Gt={};ne.Fragment=y,ne.jsx=function(x,C,D){var L=1e4>F.recentlyCreatedOwnerStacks++;return h(x,C,D,!1,L?Error("react-stack-top-frame"):Lt,L?W(i(x)):zt)},ne.jsxs=function(x,C,D){var L=1e4>F.recentlyCreatedOwnerStacks++;return h(x,C,D,!0,L?Error("react-stack-top-frame"):Lt,L?W(i(x)):zt)}}()),ne}process.env.NODE_ENV==="production"?Le.exports=kn():Le.exports=En();var oe=Le.exports;function Et(o,e={}){const[t,i]=A.useState(null),[n,r]=A.useState(!1),[s,a]=A.useState(null),[l,c]=A.useState(null),h=A.useRef(e);h.current=e,A.useEffect(()=>{const y=o.current;if(y){try{const b=Mt({...h.current,container:y});b.on("zoom",()=>{c(b.getViewBounds())}),i(b),r(!0),c(b.getViewBounds()),a(null),console.log("[useSciChart] Chart initialized")}catch(b){console.error("[useSciChart] Failed to initialize chart:",b),a(b instanceof Error?b:new Error(String(b))),r(!1)}return()=>{t&&(t.destroy(),i(null),r(!1))}}},[o]);const u=A.useCallback(y=>{t&&(t.addSeries(y),c(t.getViewBounds()))},[t]),d=A.useCallback((y,b)=>{t&&t.updateSeries(y,b)},[t]),f=A.useCallback(y=>{t&&t.removeSeries(y)},[t]),g=A.useCallback(y=>{t&&t.zoom(y)},[t]),m=A.useCallback(()=>{t&&(t.resetZoom(),c(t.getViewBounds()))},[t]);return{chart:t,isReady:n,error:s,bounds:l,addSeries:u,updateSeries:d,removeSeries:f,zoom:g,resetZoom:m}}const Bn=A.forwardRef(function({series:e=[],zoom:t,onZoomChange:i,cursor:n,width:r="100%",height:s=400,className:a="",style:l={},debug:c=!1,...h},u){const d=A.useRef(null),f=A.useRef(new Map),{chart:g,isReady:m,bounds:y,addSeries:b,updateSeries:v,removeSeries:S,resetZoom:T}=Et(d,h);A.useImperativeHandle(u,()=>({getChart:()=>g,resetZoom:T,getBounds:()=>y}),[g,T,y]),A.useEffect(()=>{if(!m||!g)return;const M=new Map(e.map(B=>[B.id,B])),_=f.current;_.forEach((B,R)=>{M.has(R)||S(R)}),M.forEach((B,R)=>{const G=_.get(R);if(G)(G.x!==B.x||G.y!==B.y)&&v(R,{x:B.x,y:B.y});else{const k={id:B.id,type:"line",data:{x:B.x,y:B.y},style:{color:B.color??"#ff0055",width:B.width??1.5},visible:B.visible??!0};b(k),M.size===1&&g.autoScale()}}),f.current=M},[e,m,g,b,v,S]),A.useEffect(()=>{!m||!g||!t||g.zoom(t)},[m,g,t]),A.useEffect(()=>{!m||!g||!i||g.on("zoom",M=>{i({xMin:M.x[0],xMax:M.x[1],yMin:M.y[0],yMax:M.y[1]})})},[m,g,i]),A.useEffect(()=>{!m||!g||(n!=null&&n.enabled?g.enableCursor(n):g.disableCursor())},[m,g,n]);const P=A.useMemo(()=>({position:"relative",width:typeof r=="number"?`${r}px`:r,height:typeof s=="number"?`${s}px`:s,...l}),[r,s,l]);return oe.jsx("div",{ref:d,className:`scichart-container ${a}`,style:P,children:c&&y&&oe.jsxs("div",{style:{position:"absolute",top:8,right:8,background:"rgba(0,0,0,0.7)",color:"#0f0",padding:"4px 8px",borderRadius:4,fontSize:11,fontFamily:"monospace"},children:[oe.jsxs("div",{children:["X: [",y.xMin.toFixed(3),", ",y.xMax.toFixed(3),"]"]}),oe.jsxs("div",{children:["Y: [",y.yMin.toExponential(2),", ",y.yMax.toExponential(2),"]"]}),oe.jsxs("div",{children:["Series: ",e.length]})]})})});class An{constructor(){p(this,"entries",new Map)}getInfo(e){return this.entries.get(e)}has(e){return this.entries.has(e)}keys(){return this.entries.keys()}get size(){return this.entries.size}}class _n{constructor(){p(this,"entries",new Map)}getInfo(e){return this.entries.get(e)}has(e){return this.entries.has(e)}keys(){return this.entries.keys()}get size(){return this.entries.size}}function ze(o){return o.variant?`${o.kind}:${o.variant}`:o.kind}class Fn{constructor(){p(this,"pipelines",new Map)}getOrCreate(e,t){const i=ze(e);if(!this.pipelines.has(i)){const n=t();this.pipelines.set(i,n)}return this.pipelines.get(i)}has(e){return this.pipelines.has(ze(e))}delete(e){this.pipelines.delete(ze(e))}get size(){return this.pipelines.size}destroy(){this.pipelines.clear()}}function Ge(o){if(!o)return[1,0,.3,1];if(Array.isArray(o))return[o[0],o[1],o[2],o[3]??1];const e=o;if(e.startsWith("#")){const i=e.slice(1);if(i.length===3){const n=parseInt(i[0]+i[0],16)/255,r=parseInt(i[1]+i[1],16)/255,s=parseInt(i[2]+i[2],16)/255;return[n,r,s,1]}if(i.length===6){const n=parseInt(i.slice(0,2),16)/255,r=parseInt(i.slice(2,4),16)/255,s=parseInt(i.slice(4,6),16)/255;return[n,r,s,1]}if(i.length===8){const n=parseInt(i.slice(0,2),16)/255,r=parseInt(i.slice(2,4),16)/255,s=parseInt(i.slice(4,6),16)/255,a=parseInt(i.slice(6,8),16)/255;return[n,r,s,a]}}const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);if(t){const i=parseInt(t[1])/255,n=parseInt(t[2])/255,r=parseInt(t[3])/255,s=t[4]?parseFloat(t[4]):1;return[i,n,r,s]}return[1,0,.3,1]}function Co(o){return o}function In(o,e){const t=Ge(o.color),i=o.opacity??1,n=[t[0],t[1],t[2],t[3]*i];return e==="scatter"||e==="line+scatter"||e==="step+scatter"?{color:n,opacity:i,pointSize:o.pointSize??4,symbol:o.symbol??"circle"}:{color:n,opacity:i,lineWidth:o.lineWidth??1}}class Oe{constructor(e){p(this,"backend");p(this,"seriesBufferMap",new Map);p(this,"seriesStepBufferMap",new Map);p(this,"seriesTextureMap",new Map);this.backend=e}getBufferId(e){return this.seriesBufferMap.has(e)||this.seriesBufferMap.set(e,`series:${e}`),this.seriesBufferMap.get(e)}getStepBufferId(e){return this.seriesStepBufferMap.has(e)||this.seriesStepBufferMap.set(e,`series:${e}:step`),this.seriesStepBufferMap.get(e)}getTextureId(e){return this.seriesTextureMap.has(e)||this.seriesTextureMap.set(e,`texture:${e}`),this.seriesTextureMap.get(e)}updateSeries(e){const t=this.getBufferId(e.id);if(this.backend.createOrUpdateBuffer(t,e.data,{usage:"vertex"}),e.stepData&&(e.type==="step"||e.type==="step+scatter")){const i=this.getStepBufferId(e.id);this.backend.createOrUpdateBuffer(i,e.stepData,{usage:"vertex"})}if(e.type==="heatmap"&&e.colormapData){const i=this.getTextureId(e.id);this.backend.createOrUpdateTexture1D(i,e.colormapData,{width:e.colormapData.length/4})}}removeSeries(e){const t=this.seriesBufferMap.get(e);t&&(this.backend.deleteBuffer(t),this.seriesBufferMap.delete(e));const i=this.seriesStepBufferMap.get(e);i&&(this.backend.deleteBuffer(i),this.seriesStepBufferMap.delete(e));const n=this.seriesTextureMap.get(e);n&&(this.backend.deleteTexture(n),this.seriesTextureMap.delete(e))}buildDrawList(e){const t=[];for(const i of e){this.updateSeries(i);const n=this.getBufferId(i.id),r=i.data.length/2,s={id:i.id,kind:i.type,bufferId:n,count:i.type==="heatmap"?i.data.length/3:r,visible:i.visible,style:In(i.style,i.type),yBounds:i.yBounds};i.stepData&&(i.type==="step"||i.type==="step+scatter")&&(s.stepBufferId=this.getStepBufferId(i.id),s.stepCount=i.stepData.length/2),i.type==="heatmap"&&(s.textureId=this.getTextureId(i.id),s.style={zBounds:i.zBounds,colormap:i.colormap}),t.push(s)}return{items:t}}destroy(){for(const e of this.seriesBufferMap.values())this.backend.deleteBuffer(e);for(const e of this.seriesStepBufferMap.values())this.backend.deleteBuffer(e);for(const e of this.seriesTextureMap.values())this.backend.deleteTexture(e);this.seriesBufferMap.clear(),this.seriesStepBufferMap.clear(),this.seriesTextureMap.clear()}}const Rn=`
|
|
265
265
|
struct VSOut {
|
|
266
266
|
@builtin(position) pos: vec4<f32>,
|
|
267
267
|
@location(0) color: vec4<f32>,
|
|
@@ -313,7 +313,7 @@ fn vs_main(in: VSInput) -> VSOutput {
|
|
|
313
313
|
fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
|
|
314
314
|
return uniforms.color;
|
|
315
315
|
}
|
|
316
|
-
`,Se=2*4,Ln=32;function zn(o,e){const t=o.createShaderModule({code:Bt}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,
|
|
316
|
+
`,Se=2*4,Ln=32;function zn(o,e){const t=o.createShaderModule({code:Bt}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,r=o.createBindGroupLayout({entries:[{binding:0,visibility:i.VERTEX|i.FRAGMENT,buffer:{type:"uniform"}}]}),s=o.createBuffer({size:Ln,usage:n.UNIFORM|n.COPY_DST}),a=o.createBindGroup({layout:r,entries:[{binding:0,resource:{buffer:s}}]}),l=o.createPipelineLayout({bindGroupLayouts:[r]});return{pipeline:o.createRenderPipeline({layout:l,vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:Se,attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"line-strip",stripIndexFormat:void 0}}),bindGroupLayout:r,uniformBuffer:s,bindGroup:a,vertexStride:Se}}function Gn(o,e,t){const i=new Float32Array([t.scale[0],t.scale[1],t.translate[0],t.translate[1],t.color[0],t.color[1],t.color[2],t.color[3]]);o.queue.writeBuffer(e,0,i)}const On=`
|
|
317
317
|
// Uniform buffer for transforms, color, point properties
|
|
318
318
|
struct Uniforms {
|
|
319
319
|
scale: vec2<f32>,
|
|
@@ -442,7 +442,7 @@ fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
|
|
|
442
442
|
let alpha = 1.0 - smoothstep(0.0, 0.02, d);
|
|
443
443
|
return vec4<f32>(uniforms.color.rgb, uniforms.color.a * alpha);
|
|
444
444
|
}
|
|
445
|
-
`,At=2*4,Un=48,_t=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function $n(o,e){const t=o.createShaderModule({code:On}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,
|
|
445
|
+
`,At=2*4,Un=48,_t=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function $n(o,e){const t=o.createShaderModule({code:On}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,r=o.createBindGroupLayout({entries:[{binding:0,visibility:i.VERTEX|i.FRAGMENT,buffer:{type:"uniform"}}]}),s=o.createBuffer({size:Un,usage:n.UNIFORM|n.COPY_DST}),a=o.createBuffer({size:_t.byteLength,usage:n.VERTEX|n.COPY_DST,mappedAtCreation:!0});new Float32Array(a.getMappedRange()).set(_t),a.unmap();const l=o.createBindGroup({layout:r,entries:[{binding:0,resource:{buffer:s}}]}),c=o.createPipelineLayout({bindGroupLayouts:[r]});return{pipeline:o.createRenderPipeline({layout:c,vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:At,stepMode:"instance",attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]},{arrayStride:8,stepMode:"vertex",attributes:[{shaderLocation:1,offset:0,format:"float32x2"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"none"}}),bindGroupLayout:r,uniformBuffer:s,bindGroup:l,quadBuffer:a,vertexStride:At}}function Yn(o,e,t){const i=new Float32Array([t.scale[0],t.scale[1],t.translate[0],t.translate[1],t.color[0],t.color[1],t.color[2],t.color[3],t.pointSize,t.symbol,t.viewport[0],t.viewport[1]]);o.queue.writeBuffer(e,0,i)}const Vn={circle:0,square:1,diamond:2,triangle:3,triangleDown:4,cross:5,x:6,star:7},Wn=32;function Xn(o,e){const t=o.createShaderModule({code:Bt}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,r=o.createBindGroupLayout({entries:[{binding:0,visibility:i.VERTEX|i.FRAGMENT,buffer:{type:"uniform"}}]}),s=o.createBuffer({size:Wn,usage:n.UNIFORM|n.COPY_DST}),a=o.createBindGroup({layout:r,entries:[{binding:0,resource:{buffer:s}}]}),l=o.createPipelineLayout({bindGroupLayouts:[r]});return{pipeline:o.createRenderPipeline({layout:l,vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:Se,attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-strip",stripIndexFormat:void 0}}),bindGroupLayout:r,uniformBuffer:s,bindGroup:a,vertexStride:Se}}function Nn(o,e,t){const i=new Float32Array([t.scale[0],t.scale[1],t.translate[0],t.translate[1],t.color[0],t.color[1],t.color[2],t.color[3]]);o.queue.writeBuffer(e,0,i)}const Hn=`
|
|
446
446
|
// Uniform buffer for transforms and value range
|
|
447
447
|
struct Uniforms {
|
|
448
448
|
scale: vec2<f32>,
|
|
@@ -493,7 +493,7 @@ fn fs_main(in: VSOutput) -> @location(0) vec4<f32> {
|
|
|
493
493
|
|
|
494
494
|
return textureSample(colormapTexture, colormapSampler, t);
|
|
495
495
|
}
|
|
496
|
-
`,Ft=3*4,qn=32;function jn(o,e){const t=o.createShaderModule({code:Hn}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,
|
|
496
|
+
`,Ft=3*4,qn=32;function jn(o,e){const t=o.createShaderModule({code:Hn}),i=globalThis.GPUShaderStage,n=globalThis.GPUBufferUsage,r=o.createBindGroupLayout({entries:[{binding:0,visibility:i.VERTEX|i.FRAGMENT,buffer:{type:"uniform"}},{binding:1,visibility:i.FRAGMENT,sampler:{}},{binding:2,visibility:i.FRAGMENT,texture:{sampleType:"float",viewDimension:"1d"}}]}),s=o.createBuffer({size:qn,usage:n.UNIFORM|n.COPY_DST}),a=o.createSampler({magFilter:"linear",minFilter:"linear",addressModeU:"clamp-to-edge"}),l=o.createPipelineLayout({bindGroupLayouts:[r]});return{pipeline:o.createRenderPipeline({layout:l,vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:Ft,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,offset:8,format:"float32"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:e,blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}}}]},primitive:{topology:"triangle-list",cullMode:"none"}}),bindGroupLayout:r,uniformBuffer:s,sampler:a,vertexStride:Ft}}function Kn(o,e,t,i,n){return o.createBindGroup({layout:e,entries:[{binding:0,resource:{buffer:t}},{binding:1,resource:i},{binding:2,resource:n.createView()}]})}function Zn(o,e,t){const i=new Float32Array([t.scale[0],t.scale[1],t.translate[0],t.translate[1],t.minValue,t.maxValue,0,0]);o.queue.writeBuffer(e,0,i)}function Jn(o){const e=o.xMax-o.xMin,t=o.yMax-o.yMin,i=e>0?2/e:1,n=t>0?2/t:1,r=-1-o.xMin*i,s=-1-o.yMin*n;return{scale:[i,n],translate:[r,s]}}function Qn(o){const e=(o==null?void 0:o.color)??[1,0,.3,1],t=(o==null?void 0:o.opacity)??1;return Array.isArray(e)?[e[0],e[1],e[2],(e[3]??1)*t]:[1,0,.3,t]}class J{constructor(e,t={}){p(this,"info");p(this,"canvas");p(this,"opts");p(this,"viewport",null);p(this,"adapter");p(this,"device");p(this,"context");p(this,"format",null);p(this,"buffers",new Map);p(this,"textures",new Map);p(this,"trianglePipeline",null);p(this,"linePipeline",null);p(this,"pointPipeline",null);p(this,"bandPipeline",null);p(this,"heatmapPipeline",null);p(this,"heatmapBindGroups",new Map);this.canvas=e,this.opts=t,this.info={type:"webgpu",available:J.isSupported()}}static isSupported(){return typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u"}async init(){if(!this.info.available)throw new Error("[gpu] WebGPU not supported");const e=globalThis.navigator.gpu;if(this.adapter=await e.requestAdapter({powerPreference:this.opts.powerPreference??"high-performance"}),!this.adapter)throw new Error("[gpu] Failed to request WebGPU adapter");this.device=await this.adapter.requestDevice();const t=this.canvas.getContext("webgpu");if(!t)throw new Error("[gpu] Failed to get WebGPU canvas context");this.context=t;const i=this.opts.preferredFormat??(e.getPreferredCanvasFormat?e.getPreferredCanvasFormat():"bgra8unorm");this.format=i,this.context.configure({device:this.device,format:i,alphaMode:"premultiplied"})}setViewport(e){this.viewport=e;const t=Math.max(1,Math.floor(e.width*e.dpr)),i=Math.max(1,Math.floor(e.height*e.dpr));this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==i&&(this.canvas.height=i)}createOrUpdateBuffer(e,t,i){if(!this.device)throw new Error("[gpu] WebGPUBackend not initialized");const n=(i==null?void 0:i.usage)??"vertex",r=globalThis.GPUBufferUsage;if(!r)throw new Error("[gpu] GPUBufferUsage not available (missing WebGPU runtime)");const s=n==="index"?r.INDEX|r.COPY_DST:n==="uniform"?r.UNIFORM|r.COPY_DST:r.VERTEX|r.COPY_DST,a=t.byteLength;let l=this.buffers.get(e);if(!l||l.size<a){if(l)try{l.destroy()}catch{}l=this.device.createBuffer({size:Math.max(4,a),usage:s}),this.buffers.set(e,l)}this.device.queue.writeBuffer(l,0,t.buffer,t.byteOffset,t.byteLength)}deleteBuffer(e){const t=this.buffers.get(e);if(t){try{t.destroy()}catch{}this.buffers.delete(e)}}createOrUpdateTexture1D(e,t,i){if(!this.device)throw new Error("[gpu] WebGPUBackend not initialized");const n=(i==null?void 0:i.width)??Math.floor(t.length/4),r=(i==null?void 0:i.format)??"rgba8unorm",s=globalThis.GPUTextureUsage;if(!s)throw new Error("[gpu] GPUTextureUsage not available (missing WebGPU runtime)");let a=this.textures.get(e);a||(a=this.device.createTexture({size:{width:n,height:1,depthOrArrayLayers:1},format:r,dimension:"1d",usage:s.TEXTURE_BINDING|s.COPY_DST}),this.textures.set(e,a),this.heatmapBindGroups.delete(e)),this.device.queue.writeTexture({texture:a},t,{bytesPerRow:n*4},{width:n,height:1,depthOrArrayLayers:1})}deleteTexture(e){const t=this.textures.get(e);if(t){try{t.destroy()}catch{}this.textures.delete(e),this.heatmapBindGroups.delete(e)}}ensurePipelines(){this.trianglePipeline||(this.trianglePipeline=Dn(this.device,this.format)),this.linePipeline||(this.linePipeline=zn(this.device,this.format)),this.pointPipeline||(this.pointPipeline=$n(this.device,this.format)),this.bandPipeline||(this.bandPipeline=Xn(this.device,this.format)),this.heatmapPipeline||(this.heatmapPipeline=jn(this.device,this.format))}render(e,t){if(!this.device||!this.context||!this.format)throw new Error("[gpu] WebGPUBackend not initialized");this.viewport||this.setViewport(t.viewport),this.ensurePipelines();const i=this.device.createCommandEncoder(),n=this.context.getCurrentTexture().createView(),r=i.beginRenderPass({colorAttachments:[{view:n,clearValue:{r:t.clearColor[0],g:t.clearColor[1],b:t.clearColor[2],a:t.clearColor[3]},loadOp:"clear",storeOp:"store"}]}),s={xMin:-1,xMax:1,yMin:-1,yMax:1};for(const a of e.items){if(!a.visible)continue;const l=this.buffers.get(a.bufferId);l&&this.renderDrawCall(r,a,l,s)}r.end(),this.device.queue.submit([i.finish()])}renderWithBounds(e,t,i){if(!this.device||!this.context||!this.format)throw new Error("[gpu] WebGPUBackend not initialized");this.viewport||this.setViewport(t.viewport),this.ensurePipelines();const n=this.device.createCommandEncoder(),r=this.context.getCurrentTexture().createView(),s=n.beginRenderPass({colorAttachments:[{view:r,clearValue:{r:t.clearColor[0],g:t.clearColor[1],b:t.clearColor[2],a:t.clearColor[3]},loadOp:"clear",storeOp:"store"}]});for(const a of e.items){if(!a.visible)continue;const l=this.buffers.get(a.bufferId);if(!l)continue;const c=a.yBounds?{...i,yMin:a.yBounds.min,yMax:a.yBounds.max}:i;this.renderDrawCall(s,a,l,c)}s.end(),this.device.queue.submit([n.finish()])}renderDrawCall(e,t,i,n){const r=Jn(n),s=Qn(t.style);switch(t.kind){case"triangles":case"bar":this.renderTriangles(e,i,t.count);break;case"line":this.renderLine(e,i,t.count,r,s);break;case"scatter":case"points":this.renderPoints(e,i,t.count,r,s,t.style);break;case"line+scatter":this.renderLine(e,i,t.count,r,s),this.renderPoints(e,i,t.count,r,s,t.style);break;case"step":if(t.stepBufferId&&t.stepCount){const l=this.buffers.get(t.stepBufferId);l&&this.renderLine(e,l,t.stepCount,r,s)}else this.renderLine(e,i,t.count,r,s);break;case"step+scatter":if(t.stepBufferId&&t.stepCount){const l=this.buffers.get(t.stepBufferId);l&&this.renderLine(e,l,t.stepCount,r,s)}else this.renderLine(e,i,t.count,r,s);this.renderPoints(e,i,t.count,r,s,t.style);break;case"band":const a=[s[0],s[1],s[2],s[3]*.4];this.renderBand(e,i,t.count,r,a);break;case"heatmap":this.renderHeatmap(e,i,t.count,r,t.style,t.textureId);break}}renderTriangles(e,t,i){e.setPipeline(this.trianglePipeline.pipeline),e.setVertexBuffer(0,t),e.draw(i)}renderLine(e,t,i,n,r){Gn(this.device,this.linePipeline.uniformBuffer,{scale:n.scale,translate:n.translate,color:r}),e.setPipeline(this.linePipeline.pipeline),e.setBindGroup(0,this.linePipeline.bindGroup),e.setVertexBuffer(0,t),e.draw(i)}renderPoints(e,t,i,n,r,s){var h;const a=((s==null?void 0:s.pointSize)??4)*(((h=this.viewport)==null?void 0:h.dpr)??1),l=Vn[(s==null?void 0:s.symbol)??"circle"]??0,c=[this.canvas.width,this.canvas.height];Yn(this.device,this.pointPipeline.uniformBuffer,{scale:n.scale,translate:n.translate,color:r,pointSize:a,symbol:l,viewport:c}),e.setPipeline(this.pointPipeline.pipeline),e.setBindGroup(0,this.pointPipeline.bindGroup),e.setVertexBuffer(0,t),e.setVertexBuffer(1,this.pointPipeline.quadBuffer),e.draw(6,i)}renderBand(e,t,i,n,r){Nn(this.device,this.bandPipeline.uniformBuffer,{scale:n.scale,translate:n.translate,color:r}),e.setPipeline(this.bandPipeline.pipeline),e.setBindGroup(0,this.bandPipeline.bindGroup),e.setVertexBuffer(0,t),e.draw(i)}renderHeatmap(e,t,i,n,r,s){if(!s)return;const a=this.textures.get(s);if(!a)return;const l=(r==null?void 0:r.zBounds)??{min:0,max:1};Zn(this.device,this.heatmapPipeline.uniformBuffer,{scale:n.scale,translate:n.translate,minValue:l.min,maxValue:l.max});let c=this.heatmapBindGroups.get(s);c||(c=Kn(this.device,this.heatmapPipeline.bindGroupLayout,this.heatmapPipeline.uniformBuffer,this.heatmapPipeline.sampler,a),this.heatmapBindGroups.set(s,c)),e.setPipeline(this.heatmapPipeline.pipeline),e.setBindGroup(0,c),e.setVertexBuffer(0,t),e.draw(i)}destroy(){for(const e of Array.from(this.buffers.keys()))this.deleteBuffer(e);for(const e of Array.from(this.textures.keys()))this.deleteTexture(e);this.trianglePipeline=null,this.linePipeline=null,this.pointPipeline=null,this.bandPipeline=null,this.heatmapPipeline=null,this.heatmapBindGroups.clear(),this.device=void 0,this.adapter=void 0,this.context=void 0,this.format=null}}const eo=Object.freeze(Object.defineProperty({__proto__:null,WebGPUBackend:J},Symbol.toStringTag,{value:"Module"})),to=`
|
|
497
497
|
precision highp float;
|
|
498
498
|
attribute vec2 aPosition;
|
|
499
499
|
uniform vec2 uScale;
|
|
@@ -603,7 +603,7 @@ void main() {
|
|
|
603
603
|
float alpha = 1.0 - smoothstep(0.0, 0.02, d);
|
|
604
604
|
gl_FragColor = vec4(uColor.rgb, uColor.a * alpha);
|
|
605
605
|
}
|
|
606
|
-
`,
|
|
606
|
+
`,ro=`
|
|
607
607
|
precision highp float;
|
|
608
608
|
attribute vec2 aPosition;
|
|
609
609
|
attribute float aValue;
|
|
@@ -615,7 +615,7 @@ void main() {
|
|
|
615
615
|
gl_Position = vec4(aPosition * uScale + uTranslate, 0.0, 1.0);
|
|
616
616
|
vValue = aValue;
|
|
617
617
|
}
|
|
618
|
-
`,
|
|
618
|
+
`,so=`
|
|
619
619
|
precision highp float;
|
|
620
620
|
varying float vValue;
|
|
621
621
|
uniform float uMinValue;
|
|
@@ -628,7 +628,7 @@ void main() {
|
|
|
628
628
|
t = clamp(t, 0.0, 1.0);
|
|
629
629
|
gl_FragColor = texture2D(uColormap, vec2(t, 0.5));
|
|
630
630
|
}
|
|
631
|
-
`;function It(o,e,t){const i=o.createShader(e);if(!i)throw new Error("[WebGL] Failed to create shader");if(o.shaderSource(i,t),o.compileShader(i),!o.getShaderParameter(i,o.COMPILE_STATUS)){const n=o.getShaderInfoLog(i);throw o.deleteShader(i),new Error(`[WebGL] Shader compilation error: ${n}`)}return i}function ao(o,e,t){const i=o.createProgram();if(!i)throw new Error("[WebGL] Failed to create program");if(o.attachShader(i,e),o.attachShader(i,t),o.linkProgram(i),!o.getProgramParameter(i,o.LINK_STATUS)){const n=o.getProgramInfoLog(i);throw o.deleteProgram(i),new Error(`[WebGL] Program link error: ${n}`)}return i}function Ue(o,e,t,i,n){const s=It(o,o.VERTEX_SHADER,e),r=It(o,o.FRAGMENT_SHADER,t),a=ao(o,s,r);o.deleteShader(s),o.deleteShader(r);const l={};for(const h of i)l[h]=o.getAttribLocation(a,h);const c={};for(const h of n)c[h]=o.getUniformLocation(a,h);return{program:a,attributes:l,uniforms:c}}function lo(o){const e=Ue(o,to,io,["aPosition"],["uScale","uTranslate","uColor"]),t=Ue(o,no,oo,["aPosition"],["uScale","uTranslate","uColor","uPointSize","uSymbol"]),i=Ue(o,so,ro,["aPosition","aValue"],["uScale","uTranslate","uMinValue","uMaxValue","uColormap"]);return{line:e,point:t,heatmap:i}}function co(o,e){o.deleteProgram(e.line.program),o.deleteProgram(e.point.program),o.deleteProgram(e.heatmap.program)}const ho={circle:0,square:1,diamond:2,triangle:3,triangleDown:4,cross:5,x:6,star:7};function uo(o){const e=o.xMax-o.xMin,t=o.yMax-o.yMin,i=e>0?2/e:1,n=t>0?2/t:1,s=-1-o.xMin*i,r=-1-o.yMin*n;return{scale:[i,n],translate:[s,r]}}function fo(o){const e=(o==null?void 0:o.color)??[1,0,.3,1],t=(o==null?void 0:o.opacity)??1;return Array.isArray(e)?[e[0],e[1],e[2],(e[3]??1)*t]:[1,0,.3,t]}class Q{constructor(e,t={}){p(this,"info");p(this,"canvas");p(this,"opts");p(this,"gl",null);p(this,"viewport",null);p(this,"dpr",1);p(this,"programs",null);p(this,"buffers",new Map);p(this,"textures",new Map);this.canvas=e,this.opts=t,this.info={type:"webgl",available:Q.isSupported()}}static isSupported(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext("webgl")||e.getContext("experimental-webgl"))}catch{return!1}}async init(){if(!this.info.available)throw new Error("[gpu] WebGL not supported");const e=this.canvas.getContext("webgl",{alpha:!0,antialias:this.opts.antialias??!0,preserveDrawingBuffer:this.opts.preserveDrawingBuffer??!0,powerPreference:this.opts.powerPreference??"high-performance"});if(!e)throw new Error("[gpu] Failed to get WebGL context");this.gl=e,e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.programs=lo(e)}setViewport(e){this.viewport=e,this.dpr=e.dpr;const t=Math.max(1,Math.floor(e.width*e.dpr)),i=Math.max(1,Math.floor(e.height*e.dpr));this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==i&&(this.canvas.height=i),this.gl&&this.gl.viewport(0,0,t,i)}createOrUpdateBuffer(e,t,i){if(!this.gl)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl;let s=this.buffers.get(e);s||(s=n.createBuffer(),this.buffers.set(e,s));const r=(i==null?void 0:i.usage)==="index"?n.ELEMENT_ARRAY_BUFFER:n.ARRAY_BUFFER;n.bindBuffer(r,s),n.bufferData(r,t,n.DYNAMIC_DRAW),n.bindBuffer(r,null)}deleteBuffer(e){if(!this.gl)return;const t=this.buffers.get(e);t&&(this.gl.deleteBuffer(t),this.buffers.delete(e))}createOrUpdateTexture1D(e,t,i){if(!this.gl)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl,s=(i==null?void 0:i.width)??Math.floor(t.length/4);let r=this.textures.get(e);r||(r=n.createTexture(),this.textures.set(e,r)),n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,s,1,0,n.RGBA,n.UNSIGNED_BYTE,t),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null)}deleteTexture(e){if(!this.gl)return;const t=this.textures.get(e);t&&(this.gl.deleteTexture(t),this.textures.delete(e))}render(e,t){this.renderWithBounds(e,t,{xMin:-1,xMax:1,yMin:-1,yMax:1})}renderWithBounds(e,t,i){if(!this.gl||!this.programs)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl;this.viewport||this.setViewport(t.viewport),n.clearColor(t.clearColor[0],t.clearColor[1],t.clearColor[2],t.clearColor[3]),n.clear(n.COLOR_BUFFER_BIT);for(const s of e.items){if(!s.visible)continue;const r=this.buffers.get(s.bufferId);if(!r)continue;const a=s.yBounds?{...i,yMin:s.yBounds.min,yMax:s.yBounds.max}:i;this.renderDrawCall(s,r,a)}}renderDrawCall(e,t,i){const n=uo(i),s=fo(e.style);switch(e.kind){case"line":case"step":this.renderLine(t,e.count,n,s);break;case"scatter":case"points":this.renderPoints(t,e.count,n,s,e.style);break;case"line+scatter":this.renderLine(t,e.count,n,s),this.renderPoints(t,e.count,n,s,e.style);break;case"step+scatter":if(e.stepBufferId&&e.stepCount){const a=this.buffers.get(e.stepBufferId);a&&this.renderLine(a,e.stepCount,n,s)}else this.renderLine(t,e.count,n,s);this.renderPoints(t,e.count,n,s,e.style);break;case"band":const r=[s[0],s[1],s[2],s[3]*.4];this.renderBand(t,e.count,n,r);break;case"triangles":case"bar":this.renderTriangles(t,e.count,n,s);break;case"heatmap":this.renderHeatmap(t,e.count,n,e.style,e.textureId);break}}renderLine(e,t,i,n){const s=this.gl,r=this.programs.line;s.useProgram(r.program),s.bindBuffer(s.ARRAY_BUFFER,e),s.enableVertexAttribArray(r.attributes.aPosition),s.vertexAttribPointer(r.attributes.aPosition,2,s.FLOAT,!1,0,0),s.uniform2f(r.uniforms.uScale,i.scale[0],i.scale[1]),s.uniform2f(r.uniforms.uTranslate,i.translate[0],i.translate[1]),s.uniform4f(r.uniforms.uColor,n[0],n[1],n[2],n[3]),s.drawArrays(s.LINE_STRIP,0,t),s.disableVertexAttribArray(r.attributes.aPosition)}renderPoints(e,t,i,n,s){const r=this.gl,a=this.programs.point,l=((s==null?void 0:s.pointSize)??4)*this.dpr,c=ho[(s==null?void 0:s.symbol)??"circle"]??0;r.useProgram(a.program),r.bindBuffer(r.ARRAY_BUFFER,e),r.enableVertexAttribArray(a.attributes.aPosition),r.vertexAttribPointer(a.attributes.aPosition,2,r.FLOAT,!1,0,0),r.uniform2f(a.uniforms.uScale,i.scale[0],i.scale[1]),r.uniform2f(a.uniforms.uTranslate,i.translate[0],i.translate[1]),r.uniform4f(a.uniforms.uColor,n[0],n[1],n[2],n[3]),r.uniform1f(a.uniforms.uPointSize,l),r.uniform1i(a.uniforms.uSymbol,c),r.drawArrays(r.POINTS,0,t),r.disableVertexAttribArray(a.attributes.aPosition)}renderBand(e,t,i,n){const s=this.gl,r=this.programs.line;s.useProgram(r.program),s.bindBuffer(s.ARRAY_BUFFER,e),s.enableVertexAttribArray(r.attributes.aPosition),s.vertexAttribPointer(r.attributes.aPosition,2,s.FLOAT,!1,0,0),s.uniform2f(r.uniforms.uScale,i.scale[0],i.scale[1]),s.uniform2f(r.uniforms.uTranslate,i.translate[0],i.translate[1]),s.uniform4f(r.uniforms.uColor,n[0],n[1],n[2],n[3]),s.drawArrays(s.TRIANGLE_STRIP,0,t),s.disableVertexAttribArray(r.attributes.aPosition)}renderTriangles(e,t,i,n){const s=this.gl,r=this.programs.line;s.useProgram(r.program),s.bindBuffer(s.ARRAY_BUFFER,e),s.enableVertexAttribArray(r.attributes.aPosition),s.vertexAttribPointer(r.attributes.aPosition,2,s.FLOAT,!1,0,0),s.uniform2f(r.uniforms.uScale,i.scale[0],i.scale[1]),s.uniform2f(r.uniforms.uTranslate,i.translate[0],i.translate[1]),s.uniform4f(r.uniforms.uColor,n[0],n[1],n[2],n[3]),s.drawArrays(s.TRIANGLES,0,t),s.disableVertexAttribArray(r.attributes.aPosition)}renderHeatmap(e,t,i,n,s){if(!s)return;const r=this.textures.get(s);if(!r)return;const a=this.gl,l=this.programs.heatmap,c=(n==null?void 0:n.zBounds)??{min:0,max:1};a.useProgram(l.program),a.bindBuffer(a.ARRAY_BUFFER,e),a.enableVertexAttribArray(l.attributes.aPosition),a.vertexAttribPointer(l.attributes.aPosition,2,a.FLOAT,!1,12,0),l.attributes.aValue!==-1&&(a.enableVertexAttribArray(l.attributes.aValue),a.vertexAttribPointer(l.attributes.aValue,1,a.FLOAT,!1,12,8)),a.uniform2f(l.uniforms.uScale,i.scale[0],i.scale[1]),a.uniform2f(l.uniforms.uTranslate,i.translate[0],i.translate[1]),a.uniform1f(l.uniforms.uMinValue,c.min),a.uniform1f(l.uniforms.uMaxValue,c.max),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,r),a.uniform1i(l.uniforms.uColormap,0),a.drawArrays(a.TRIANGLES,0,t),a.disableVertexAttribArray(l.attributes.aPosition),l.attributes.aValue!==-1&&a.disableVertexAttribArray(l.attributes.aValue)}destroy(){if(!this.gl)return;const e=this.gl;for(const t of this.buffers.values())e.deleteBuffer(t);this.buffers.clear();for(const t of this.textures.values())e.deleteTexture(t);this.textures.clear(),this.programs&&(co(e,this.programs),this.programs=null),this.gl=null}}const po=Object.freeze(Object.defineProperty({__proto__:null,WebGLBackend:Q},Symbol.toStringTag,{value:"Module"}));class Rt{constructor(e,t={}){p(this,"canvas");p(this,"options");p(this,"backend",null);p(this,"adapter",null);p(this,"dpr");p(this,"isInitialized",!1);p(this,"backendType",null);p(this,"bufferDataMap",new Map);p(this,"stepBufferDataMap",new Map);p(this,"colormapDataMap",new Map);this.canvas=e,this.options=t,this.dpr=window.devicePixelRatio||1}async init(){const e=this.options.backend??"auto";if((e==="webgpu"||e==="auto")&&J.isSupported())try{const t=new J(this.canvas,{powerPreference:this.options.powerPreference??"high-performance"});return await t.init(),this.backend=t,this.backendType="webgpu",this.adapter=new Oe(t),this.isInitialized=!0,this.resize(),!0}catch(t){console.warn("[GpuRenderer] WebGPU init failed:",t)}if((e==="webgl"||e==="auto")&&Q.isSupported())try{const t=new Q(this.canvas,{powerPreference:this.options.powerPreference??"high-performance"});return await t.init(),this.backend=t,this.backendType="webgl",this.adapter=new Oe(t),this.isInitialized=!0,this.resize(),console.info("[GpuRenderer] Using WebGL backend (WebGPU not available)"),!0}catch(t){console.warn("[GpuRenderer] WebGL init failed:",t)}return!1}get available(){return this.isInitialized}get activeBackend(){return this.backendType}setDPR(e){this.dpr=e,this.resize()}createBuffer(e,t){this.bufferDataMap.set(e,t)}updateBuffer(e,t,i){const n=this.bufferDataMap.get(e);if(!n)return!1;const s=i/4;return n.set(t,s),!0}getBuffer(e){return this.bufferDataMap.get(e)}deleteBuffer(e){this.bufferDataMap.delete(e),this.backend&&this.backend.deleteBuffer(e)}createStepBuffer(e,t){this.stepBufferDataMap.set(e,t)}createColormapTexture(e,t){this.colormapDataMap.set(e,t),this.backend&&this.backend.createOrUpdateTexture1D(e,t,{width:t.length/4})}render(e,t){if(!this.isInitialized||!this.backend)return;const i=this.buildDrawList(e),n={viewport:{width:this.canvas.clientWidth,height:this.canvas.clientHeight,dpr:this.dpr},clearColor:t.backgroundColor??[.1,.1,.18,1],bounds:t.bounds,plotArea:t.plotArea};"renderWithBounds"in this.backend?this.backend.renderWithBounds(i,n,t.bounds):this.backend.render(i,n)}buildDrawList(e){const t=[];for(const i of e){const n=this.bufferDataMap.get(i.id);if(!n)continue;this.backend.createOrUpdateBuffer(i.id,n,{usage:"vertex"});const s=i.type==="heatmap"?n.length/3:n.length/2,r=Ge(i.style.color),a=i.style.opacity??1,l=[r[0],r[1],r[2],r[3]*a],c={id:i.id,kind:i.type,bufferId:i.id,count:s,visible:i.visible,yBounds:i.yBounds};if(i.type==="scatter"||i.type==="line+scatter"||i.type==="step+scatter")c.style={color:l,opacity:a,pointSize:i.style.pointSize??4,symbol:i.style.symbol??"circle"};else if(i.type==="heatmap"){c.textureId=`colormap:${i.id}`,c.style={zBounds:i.zBounds,colormap:i.colormap};const h=this.colormapDataMap.get(i.id);h&&this.backend.createOrUpdateTexture1D(c.textureId,h,{width:h.length/4})}else c.style={color:l,opacity:a,lineWidth:i.style.lineWidth??1};if((i.type==="step"||i.type==="step+scatter")&&this.stepBufferDataMap.has(i.id)){const h=this.stepBufferDataMap.get(i.id),u=`${i.id}:step`;this.backend.createOrUpdateBuffer(u,h,{usage:"vertex"}),c.stepBufferId=u,c.stepCount=h.length/2}t.push(c)}return{items:t}}resize(){if(!this.backend)return;const e=this.canvas.getBoundingClientRect();this.backend.setViewport({width:e.width,height:e.height,dpr:this.dpr})}getLimits(){return{backend:this.backendType,available:this.isInitialized}}destroy(){var e,t;(e=this.adapter)==null||e.destroy(),(t=this.backend)==null||t.destroy(),this.bufferDataMap.clear(),this.stepBufferDataMap.clear(),this.colormapDataMap.clear(),this.adapter=null,this.backend=null,this.isInitialized=!1,this.backendType=null}}async function go(o,e){const t=new Rt(o,e);return await t.init()?t:null}class mo{constructor(e){p(this,"canvas");p(this,"results",[]);this.canvas=e??document.createElement("canvas"),e||(this.canvas.width=800,this.canvas.height=600)}generateLineData(e){const t=new Float32Array(e*2);for(let i=0;i<e;i++)t[i*2]=i/(e-1),t[i*2+1]=Math.random();return t}async measureFrameTimes(e,t,i=10,n){const s=[];let r=performance.now(),a=0;const l=performance.now();return new Promise(c=>{const h=()=>{const u=performance.now(),d=u-l;if(d>=t+i*16){c({frameTimes:s,duration:d-i*16});return}if(e(),a>=i){if(s.push(u-r),n){const f=Math.min(1,d/t);n(f)}}else a++;r=u,requestAnimationFrame(h)};requestAnimationFrame(h)})}async benchmarkWebGPU(e={}){const{WebGPUBackend:t}=await Promise.resolve().then(()=>eo);if(!t.isSupported())return console.warn("[Benchmark] WebGPU not supported"),null;const i=e.pointCount??1e5,n=e.durationMs??5e3,s=e.warmupFrames??30,r=new t(this.canvas);await r.init(),r.setViewport({width:this.canvas.width,height:this.canvas.height,dpr:1});const a=this.generateLineData(i);r.createOrUpdateBuffer("bench-line",a,{usage:"vertex"});const l={items:[{id:"bench-line",kind:"line",bufferId:"bench-line",count:i,visible:!0,style:{color:[0,.9,1,1]}}]},c={viewport:{width:this.canvas.width,height:this.canvas.height,dpr:1},clearColor:[.1,.1,.15,1]},h={xMin:0,xMax:1,yMin:0,yMax:1},u=()=>{r.renderWithBounds(l,c,h)},{frameTimes:d,duration:f}=await this.measureFrameTimes(u,n,s,e.onProgress);r.destroy();const g=this.calculateResult("webgpu",i,d,f);return this.results.push(g),g}async benchmarkWebGL(e={}){const{WebGLBackend:t}=await Promise.resolve().then(()=>po);if(!t.isSupported())return console.warn("[Benchmark] WebGL not supported"),null;const i=e.pointCount??1e5,n=e.durationMs??5e3,s=e.warmupFrames??30,r=new t(this.canvas);await r.init(),r.setViewport({width:this.canvas.width,height:this.canvas.height,dpr:1});const a=this.generateLineData(i);r.createOrUpdateBuffer("bench-line",a,{usage:"vertex"});const l={items:[{id:"bench-line",kind:"line",bufferId:"bench-line",count:i,visible:!0,style:{color:[0,.9,1,1]}}]},c={viewport:{width:this.canvas.width,height:this.canvas.height,dpr:1},clearColor:[.1,.1,.15,1]},h={xMin:0,xMax:1,yMin:0,yMax:1},u=()=>{r.renderWithBounds(l,c,h)},{frameTimes:d,duration:f}=await this.measureFrameTimes(u,n,s,e.onProgress);r.destroy();const g=this.calculateResult("webgl",i,d,f);return this.results.push(g),g}calculateResult(e,t,i,n){if(i.length===0)return{backend:e,pointCount:t,fps:0,avgFrameTime:0,minFrameTime:0,maxFrameTime:0,totalFrames:0,duration:n};const r=i.reduce((c,h)=>c+h,0)/i.length,a=Math.min(...i),l=Math.max(...i);return{backend:e,pointCount:t,fps:Math.round(1e3/r),avgFrameTime:Math.round(r*100)/100,minFrameTime:Math.round(a*100)/100,maxFrameTime:Math.round(l*100)/100,totalFrames:i.length,duration:Math.round(n)}}async runComparison(e={}){const t=await this.benchmarkWebGPU(e),i=await this.benchmarkWebGL(e);let n="unknown",s=1;return t&&i?t.fps>i.fps*1.05?(n="webgpu",s=t.fps/i.fps):i.fps>t.fps*1.05?(n="webgl",s=i.fps/t.fps):(n="tie",s=1):t?n="webgpu":i&&(n="webgl"),{webgpu:t,webgl:i,winner:n,speedup:Math.round(s*100)/100}}getResults(){return[...this.results]}clearResults(){this.results=[]}static formatResult(e){return[`Backend: ${e.backend.toUpperCase()}`,`Points: ${e.pointCount.toLocaleString()}`,`FPS: ${e.fps}`,`Avg Frame: ${e.avgFrameTime}ms`,`Min/Max: ${e.minFrameTime}ms / ${e.maxFrameTime}ms`,`Frames: ${e.totalFrames}`,`Duration: ${e.duration}ms`].join(" | ")}}const yo=`
|
|
631
|
+
`;function It(o,e,t){const i=o.createShader(e);if(!i)throw new Error("[WebGL] Failed to create shader");if(o.shaderSource(i,t),o.compileShader(i),!o.getShaderParameter(i,o.COMPILE_STATUS)){const n=o.getShaderInfoLog(i);throw o.deleteShader(i),new Error(`[WebGL] Shader compilation error: ${n}`)}return i}function ao(o,e,t){const i=o.createProgram();if(!i)throw new Error("[WebGL] Failed to create program");if(o.attachShader(i,e),o.attachShader(i,t),o.linkProgram(i),!o.getProgramParameter(i,o.LINK_STATUS)){const n=o.getProgramInfoLog(i);throw o.deleteProgram(i),new Error(`[WebGL] Program link error: ${n}`)}return i}function Ue(o,e,t,i,n){const r=It(o,o.VERTEX_SHADER,e),s=It(o,o.FRAGMENT_SHADER,t),a=ao(o,r,s);o.deleteShader(r),o.deleteShader(s);const l={};for(const h of i)l[h]=o.getAttribLocation(a,h);const c={};for(const h of n)c[h]=o.getUniformLocation(a,h);return{program:a,attributes:l,uniforms:c}}function lo(o){const e=Ue(o,to,io,["aPosition"],["uScale","uTranslate","uColor"]),t=Ue(o,no,oo,["aPosition"],["uScale","uTranslate","uColor","uPointSize","uSymbol"]),i=Ue(o,ro,so,["aPosition","aValue"],["uScale","uTranslate","uMinValue","uMaxValue","uColormap"]);return{line:e,point:t,heatmap:i}}function co(o,e){o.deleteProgram(e.line.program),o.deleteProgram(e.point.program),o.deleteProgram(e.heatmap.program)}const ho={circle:0,square:1,diamond:2,triangle:3,triangleDown:4,cross:5,x:6,star:7};function uo(o){const e=o.xMax-o.xMin,t=o.yMax-o.yMin,i=e>0?2/e:1,n=t>0?2/t:1,r=-1-o.xMin*i,s=-1-o.yMin*n;return{scale:[i,n],translate:[r,s]}}function fo(o){const e=(o==null?void 0:o.color)??[1,0,.3,1],t=(o==null?void 0:o.opacity)??1;return Array.isArray(e)?[e[0],e[1],e[2],(e[3]??1)*t]:[1,0,.3,t]}class Q{constructor(e,t={}){p(this,"info");p(this,"canvas");p(this,"opts");p(this,"gl",null);p(this,"viewport",null);p(this,"dpr",1);p(this,"programs",null);p(this,"buffers",new Map);p(this,"textures",new Map);this.canvas=e,this.opts=t,this.info={type:"webgl",available:Q.isSupported()}}static isSupported(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext("webgl")||e.getContext("experimental-webgl"))}catch{return!1}}async init(){if(!this.info.available)throw new Error("[gpu] WebGL not supported");const e=this.canvas.getContext("webgl",{alpha:!0,antialias:this.opts.antialias??!0,preserveDrawingBuffer:this.opts.preserveDrawingBuffer??!0,powerPreference:this.opts.powerPreference??"high-performance"});if(!e)throw new Error("[gpu] Failed to get WebGL context");this.gl=e,e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.programs=lo(e)}setViewport(e){this.viewport=e,this.dpr=e.dpr;const t=Math.max(1,Math.floor(e.width*e.dpr)),i=Math.max(1,Math.floor(e.height*e.dpr));this.canvas.width!==t&&(this.canvas.width=t),this.canvas.height!==i&&(this.canvas.height=i),this.gl&&this.gl.viewport(0,0,t,i)}createOrUpdateBuffer(e,t,i){if(!this.gl)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl;let r=this.buffers.get(e);r||(r=n.createBuffer(),this.buffers.set(e,r));const s=(i==null?void 0:i.usage)==="index"?n.ELEMENT_ARRAY_BUFFER:n.ARRAY_BUFFER;n.bindBuffer(s,r),n.bufferData(s,t,n.DYNAMIC_DRAW),n.bindBuffer(s,null)}deleteBuffer(e){if(!this.gl)return;const t=this.buffers.get(e);t&&(this.gl.deleteBuffer(t),this.buffers.delete(e))}createOrUpdateTexture1D(e,t,i){if(!this.gl)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl,r=(i==null?void 0:i.width)??Math.floor(t.length/4);let s=this.textures.get(e);s||(s=n.createTexture(),this.textures.set(e,s)),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,r,1,0,n.RGBA,n.UNSIGNED_BYTE,t),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null)}deleteTexture(e){if(!this.gl)return;const t=this.textures.get(e);t&&(this.gl.deleteTexture(t),this.textures.delete(e))}render(e,t){this.renderWithBounds(e,t,{xMin:-1,xMax:1,yMin:-1,yMax:1})}renderWithBounds(e,t,i){if(!this.gl||!this.programs)throw new Error("[gpu] WebGLBackend not initialized");const n=this.gl;this.viewport||this.setViewport(t.viewport),n.clearColor(t.clearColor[0],t.clearColor[1],t.clearColor[2],t.clearColor[3]),n.clear(n.COLOR_BUFFER_BIT);for(const r of e.items){if(!r.visible)continue;const s=this.buffers.get(r.bufferId);if(!s)continue;const a=r.yBounds?{...i,yMin:r.yBounds.min,yMax:r.yBounds.max}:i;this.renderDrawCall(r,s,a)}}renderDrawCall(e,t,i){const n=uo(i),r=fo(e.style);switch(e.kind){case"line":case"step":this.renderLine(t,e.count,n,r);break;case"scatter":case"points":this.renderPoints(t,e.count,n,r,e.style);break;case"line+scatter":this.renderLine(t,e.count,n,r),this.renderPoints(t,e.count,n,r,e.style);break;case"step+scatter":if(e.stepBufferId&&e.stepCount){const a=this.buffers.get(e.stepBufferId);a&&this.renderLine(a,e.stepCount,n,r)}else this.renderLine(t,e.count,n,r);this.renderPoints(t,e.count,n,r,e.style);break;case"band":const s=[r[0],r[1],r[2],r[3]*.4];this.renderBand(t,e.count,n,s);break;case"triangles":case"bar":this.renderTriangles(t,e.count,n,r);break;case"heatmap":this.renderHeatmap(t,e.count,n,e.style,e.textureId);break}}renderLine(e,t,i,n){const r=this.gl,s=this.programs.line;r.useProgram(s.program),r.bindBuffer(r.ARRAY_BUFFER,e),r.enableVertexAttribArray(s.attributes.aPosition),r.vertexAttribPointer(s.attributes.aPosition,2,r.FLOAT,!1,0,0),r.uniform2f(s.uniforms.uScale,i.scale[0],i.scale[1]),r.uniform2f(s.uniforms.uTranslate,i.translate[0],i.translate[1]),r.uniform4f(s.uniforms.uColor,n[0],n[1],n[2],n[3]),r.drawArrays(r.LINE_STRIP,0,t),r.disableVertexAttribArray(s.attributes.aPosition)}renderPoints(e,t,i,n,r){const s=this.gl,a=this.programs.point,l=((r==null?void 0:r.pointSize)??4)*this.dpr,c=ho[(r==null?void 0:r.symbol)??"circle"]??0;s.useProgram(a.program),s.bindBuffer(s.ARRAY_BUFFER,e),s.enableVertexAttribArray(a.attributes.aPosition),s.vertexAttribPointer(a.attributes.aPosition,2,s.FLOAT,!1,0,0),s.uniform2f(a.uniforms.uScale,i.scale[0],i.scale[1]),s.uniform2f(a.uniforms.uTranslate,i.translate[0],i.translate[1]),s.uniform4f(a.uniforms.uColor,n[0],n[1],n[2],n[3]),s.uniform1f(a.uniforms.uPointSize,l),s.uniform1i(a.uniforms.uSymbol,c),s.drawArrays(s.POINTS,0,t),s.disableVertexAttribArray(a.attributes.aPosition)}renderBand(e,t,i,n){const r=this.gl,s=this.programs.line;r.useProgram(s.program),r.bindBuffer(r.ARRAY_BUFFER,e),r.enableVertexAttribArray(s.attributes.aPosition),r.vertexAttribPointer(s.attributes.aPosition,2,r.FLOAT,!1,0,0),r.uniform2f(s.uniforms.uScale,i.scale[0],i.scale[1]),r.uniform2f(s.uniforms.uTranslate,i.translate[0],i.translate[1]),r.uniform4f(s.uniforms.uColor,n[0],n[1],n[2],n[3]),r.drawArrays(r.TRIANGLE_STRIP,0,t),r.disableVertexAttribArray(s.attributes.aPosition)}renderTriangles(e,t,i,n){const r=this.gl,s=this.programs.line;r.useProgram(s.program),r.bindBuffer(r.ARRAY_BUFFER,e),r.enableVertexAttribArray(s.attributes.aPosition),r.vertexAttribPointer(s.attributes.aPosition,2,r.FLOAT,!1,0,0),r.uniform2f(s.uniforms.uScale,i.scale[0],i.scale[1]),r.uniform2f(s.uniforms.uTranslate,i.translate[0],i.translate[1]),r.uniform4f(s.uniforms.uColor,n[0],n[1],n[2],n[3]),r.drawArrays(r.TRIANGLES,0,t),r.disableVertexAttribArray(s.attributes.aPosition)}renderHeatmap(e,t,i,n,r){if(!r)return;const s=this.textures.get(r);if(!s)return;const a=this.gl,l=this.programs.heatmap,c=(n==null?void 0:n.zBounds)??{min:0,max:1};a.useProgram(l.program),a.bindBuffer(a.ARRAY_BUFFER,e),a.enableVertexAttribArray(l.attributes.aPosition),a.vertexAttribPointer(l.attributes.aPosition,2,a.FLOAT,!1,12,0),l.attributes.aValue!==-1&&(a.enableVertexAttribArray(l.attributes.aValue),a.vertexAttribPointer(l.attributes.aValue,1,a.FLOAT,!1,12,8)),a.uniform2f(l.uniforms.uScale,i.scale[0],i.scale[1]),a.uniform2f(l.uniforms.uTranslate,i.translate[0],i.translate[1]),a.uniform1f(l.uniforms.uMinValue,c.min),a.uniform1f(l.uniforms.uMaxValue,c.max),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,s),a.uniform1i(l.uniforms.uColormap,0),a.drawArrays(a.TRIANGLES,0,t),a.disableVertexAttribArray(l.attributes.aPosition),l.attributes.aValue!==-1&&a.disableVertexAttribArray(l.attributes.aValue)}destroy(){if(!this.gl)return;const e=this.gl;for(const t of this.buffers.values())e.deleteBuffer(t);this.buffers.clear();for(const t of this.textures.values())e.deleteTexture(t);this.textures.clear(),this.programs&&(co(e,this.programs),this.programs=null),this.gl=null}}const po=Object.freeze(Object.defineProperty({__proto__:null,WebGLBackend:Q},Symbol.toStringTag,{value:"Module"}));class Rt{constructor(e,t={}){p(this,"canvas");p(this,"options");p(this,"backend",null);p(this,"adapter",null);p(this,"dpr");p(this,"isInitialized",!1);p(this,"backendType",null);p(this,"bufferDataMap",new Map);p(this,"stepBufferDataMap",new Map);p(this,"colormapDataMap",new Map);this.canvas=e,this.options=t,this.dpr=window.devicePixelRatio||1}async init(){const e=this.options.backend??"auto";if((e==="webgpu"||e==="auto")&&J.isSupported())try{const t=new J(this.canvas,{powerPreference:this.options.powerPreference??"high-performance"});return await t.init(),this.backend=t,this.backendType="webgpu",this.adapter=new Oe(t),this.isInitialized=!0,this.resize(),!0}catch(t){console.warn("[GpuRenderer] WebGPU init failed:",t)}if((e==="webgl"||e==="auto")&&Q.isSupported())try{const t=new Q(this.canvas,{powerPreference:this.options.powerPreference??"high-performance"});return await t.init(),this.backend=t,this.backendType="webgl",this.adapter=new Oe(t),this.isInitialized=!0,this.resize(),console.info("[GpuRenderer] Using WebGL backend (WebGPU not available)"),!0}catch(t){console.warn("[GpuRenderer] WebGL init failed:",t)}return!1}get available(){return this.isInitialized}get activeBackend(){return this.backendType}setDPR(e){this.dpr=e,this.resize()}createBuffer(e,t){this.bufferDataMap.set(e,t)}updateBuffer(e,t,i){const n=this.bufferDataMap.get(e);if(!n)return!1;const r=i/4;return n.set(t,r),!0}getBuffer(e){return this.bufferDataMap.get(e)}deleteBuffer(e){this.bufferDataMap.delete(e),this.backend&&this.backend.deleteBuffer(e)}createStepBuffer(e,t){this.stepBufferDataMap.set(e,t)}createColormapTexture(e,t){this.colormapDataMap.set(e,t),this.backend&&this.backend.createOrUpdateTexture1D(e,t,{width:t.length/4})}render(e,t){if(!this.isInitialized||!this.backend)return;const i=this.buildDrawList(e),n={viewport:{width:this.canvas.clientWidth,height:this.canvas.clientHeight,dpr:this.dpr},clearColor:t.backgroundColor??[.1,.1,.18,1],bounds:t.bounds,plotArea:t.plotArea};"renderWithBounds"in this.backend?this.backend.renderWithBounds(i,n,t.bounds):this.backend.render(i,n)}buildDrawList(e){const t=[];for(const i of e){const n=this.bufferDataMap.get(i.id);if(!n)continue;this.backend.createOrUpdateBuffer(i.id,n,{usage:"vertex"});const r=i.type==="heatmap"?n.length/3:n.length/2,s=Ge(i.style.color),a=i.style.opacity??1,l=[s[0],s[1],s[2],s[3]*a],c={id:i.id,kind:i.type,bufferId:i.id,count:r,visible:i.visible,yBounds:i.yBounds};if(i.type==="scatter"||i.type==="line+scatter"||i.type==="step+scatter")c.style={color:l,opacity:a,pointSize:i.style.pointSize??4,symbol:i.style.symbol??"circle"};else if(i.type==="heatmap"){c.textureId=`colormap:${i.id}`,c.style={zBounds:i.zBounds,colormap:i.colormap};const h=this.colormapDataMap.get(i.id);h&&this.backend.createOrUpdateTexture1D(c.textureId,h,{width:h.length/4})}else c.style={color:l,opacity:a,lineWidth:i.style.lineWidth??1};if((i.type==="step"||i.type==="step+scatter")&&this.stepBufferDataMap.has(i.id)){const h=this.stepBufferDataMap.get(i.id),u=`${i.id}:step`;this.backend.createOrUpdateBuffer(u,h,{usage:"vertex"}),c.stepBufferId=u,c.stepCount=h.length/2}t.push(c)}return{items:t}}resize(){if(!this.backend)return;const e=this.canvas.getBoundingClientRect();this.backend.setViewport({width:e.width,height:e.height,dpr:this.dpr})}getLimits(){return{backend:this.backendType,available:this.isInitialized}}destroy(){var e,t;(e=this.adapter)==null||e.destroy(),(t=this.backend)==null||t.destroy(),this.bufferDataMap.clear(),this.stepBufferDataMap.clear(),this.colormapDataMap.clear(),this.adapter=null,this.backend=null,this.isInitialized=!1,this.backendType=null}}async function go(o,e){const t=new Rt(o,e);return await t.init()?t:null}class mo{constructor(e){p(this,"canvas");p(this,"results",[]);this.canvas=e??document.createElement("canvas"),e||(this.canvas.width=800,this.canvas.height=600)}generateLineData(e){const t=new Float32Array(e*2);for(let i=0;i<e;i++)t[i*2]=i/(e-1),t[i*2+1]=Math.random();return t}async measureFrameTimes(e,t,i=10,n){const r=[];let s=performance.now(),a=0;const l=performance.now();return new Promise(c=>{const h=()=>{const u=performance.now(),d=u-l;if(d>=t+i*16){c({frameTimes:r,duration:d-i*16});return}if(e(),a>=i){if(r.push(u-s),n){const f=Math.min(1,d/t);n(f)}}else a++;s=u,requestAnimationFrame(h)};requestAnimationFrame(h)})}async benchmarkWebGPU(e={}){const{WebGPUBackend:t}=await Promise.resolve().then(()=>eo);if(!t.isSupported())return console.warn("[Benchmark] WebGPU not supported"),null;const i=e.pointCount??1e5,n=e.durationMs??5e3,r=e.warmupFrames??30,s=new t(this.canvas);await s.init(),s.setViewport({width:this.canvas.width,height:this.canvas.height,dpr:1});const a=this.generateLineData(i);s.createOrUpdateBuffer("bench-line",a,{usage:"vertex"});const l={items:[{id:"bench-line",kind:"line",bufferId:"bench-line",count:i,visible:!0,style:{color:[0,.9,1,1]}}]},c={viewport:{width:this.canvas.width,height:this.canvas.height,dpr:1},clearColor:[.1,.1,.15,1]},h={xMin:0,xMax:1,yMin:0,yMax:1},u=()=>{s.renderWithBounds(l,c,h)},{frameTimes:d,duration:f}=await this.measureFrameTimes(u,n,r,e.onProgress);s.destroy();const g=this.calculateResult("webgpu",i,d,f);return this.results.push(g),g}async benchmarkWebGL(e={}){const{WebGLBackend:t}=await Promise.resolve().then(()=>po);if(!t.isSupported())return console.warn("[Benchmark] WebGL not supported"),null;const i=e.pointCount??1e5,n=e.durationMs??5e3,r=e.warmupFrames??30,s=new t(this.canvas);await s.init(),s.setViewport({width:this.canvas.width,height:this.canvas.height,dpr:1});const a=this.generateLineData(i);s.createOrUpdateBuffer("bench-line",a,{usage:"vertex"});const l={items:[{id:"bench-line",kind:"line",bufferId:"bench-line",count:i,visible:!0,style:{color:[0,.9,1,1]}}]},c={viewport:{width:this.canvas.width,height:this.canvas.height,dpr:1},clearColor:[.1,.1,.15,1]},h={xMin:0,xMax:1,yMin:0,yMax:1},u=()=>{s.renderWithBounds(l,c,h)},{frameTimes:d,duration:f}=await this.measureFrameTimes(u,n,r,e.onProgress);s.destroy();const g=this.calculateResult("webgl",i,d,f);return this.results.push(g),g}calculateResult(e,t,i,n){if(i.length===0)return{backend:e,pointCount:t,fps:0,avgFrameTime:0,minFrameTime:0,maxFrameTime:0,totalFrames:0,duration:n};const s=i.reduce((c,h)=>c+h,0)/i.length,a=Math.min(...i),l=Math.max(...i);return{backend:e,pointCount:t,fps:Math.round(1e3/s),avgFrameTime:Math.round(s*100)/100,minFrameTime:Math.round(a*100)/100,maxFrameTime:Math.round(l*100)/100,totalFrames:i.length,duration:Math.round(n)}}async runComparison(e={}){const t=await this.benchmarkWebGPU(e),i=await this.benchmarkWebGL(e);let n="unknown",r=1;return t&&i?t.fps>i.fps*1.05?(n="webgpu",r=t.fps/i.fps):i.fps>t.fps*1.05?(n="webgl",r=i.fps/t.fps):(n="tie",r=1):t?n="webgpu":i&&(n="webgl"),{webgpu:t,webgl:i,winner:n,speedup:Math.round(r*100)/100}}getResults(){return[...this.results]}clearResults(){this.results=[]}static formatResult(e){return[`Backend: ${e.backend.toUpperCase()}`,`Points: ${e.pointCount.toLocaleString()}`,`FPS: ${e.fps}`,`Avg Frame: ${e.avgFrameTime}ms`,`Min/Max: ${e.minFrameTime}ms / ${e.maxFrameTime}ms`,`Frames: ${e.totalFrames}`,`Duration: ${e.duration}ms`].join(" | ")}}const yo=`
|
|
632
632
|
struct StatsResult {
|
|
633
633
|
min_val: f32,
|
|
634
634
|
max_val: f32,
|
|
@@ -867,5 +867,5 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
|
|
|
867
867
|
peaks[idx].is_peak = 1u;
|
|
868
868
|
}
|
|
869
869
|
}
|
|
870
|
-
`;class $e{constructor(e={}){p(this,"device",null);p(this,"statsPipeline",null);p(this,"minmaxPipeline",null);p(this,"downsamplePipeline",null);p(this,"peaksPipeline",null);p(this,"isInitialized",!1);this.options=e}static isSupported(){return typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u"}async init(){if(this.options.device)this.device=this.options.device;else{if(!$e.isSupported())throw new Error("[GpuCompute] WebGPU not supported");const t=await globalThis.navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("[GpuCompute] Failed to get adapter");this.device=await t.requestDevice()}await this.createPipelines(),this.isInitialized=!0}async createPipelines(){const e=this.device.createShaderModule({code:yo});this.statsPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:e,entryPoint:"main"}});const t=this.device.createShaderModule({code:bo});this.minmaxPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:t,entryPoint:"main"}});const i=this.device.createShaderModule({code:xo});this.downsamplePipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:i,entryPoint:"main"}});const n=this.device.createShaderModule({code:vo});this.peaksPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:n,entryPoint:"main"}})}async calculateStats(e){if(!this.isInitialized)throw new Error("[GpuCompute] Not initialized");const t=globalThis.GPUBufferUsage,i=this.device.createBuffer({size:e.byteLength,usage:t.STORAGE|t.COPY_DST});this.device.queue.writeBuffer(i,0,e);const n=this.device.createBuffer({size:32,usage:t.STORAGE|t.COPY_SRC}),
|
|
870
|
+
`;class $e{constructor(e={}){p(this,"device",null);p(this,"statsPipeline",null);p(this,"minmaxPipeline",null);p(this,"downsamplePipeline",null);p(this,"peaksPipeline",null);p(this,"isInitialized",!1);this.options=e}static isSupported(){return typeof globalThis.navigator<"u"&&typeof globalThis.navigator.gpu<"u"}async init(){if(this.options.device)this.device=this.options.device;else{if(!$e.isSupported())throw new Error("[GpuCompute] WebGPU not supported");const t=await globalThis.navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("[GpuCompute] Failed to get adapter");this.device=await t.requestDevice()}await this.createPipelines(),this.isInitialized=!0}async createPipelines(){const e=this.device.createShaderModule({code:yo});this.statsPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:e,entryPoint:"main"}});const t=this.device.createShaderModule({code:bo});this.minmaxPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:t,entryPoint:"main"}});const i=this.device.createShaderModule({code:xo});this.downsamplePipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:i,entryPoint:"main"}});const n=this.device.createShaderModule({code:vo});this.peaksPipeline=await this.device.createComputePipelineAsync({layout:"auto",compute:{module:n,entryPoint:"main"}})}async calculateStats(e){if(!this.isInitialized)throw new Error("[GpuCompute] Not initialized");const t=globalThis.GPUBufferUsage,i=this.device.createBuffer({size:e.byteLength,usage:t.STORAGE|t.COPY_DST});this.device.queue.writeBuffer(i,0,e);const n=this.device.createBuffer({size:32,usage:t.STORAGE|t.COPY_SRC}),r=this.device.createBuffer({size:32,usage:t.MAP_READ|t.COPY_DST}),s=this.device.createBindGroup({layout:this.statsPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:i}},{binding:1,resource:{buffer:n}}]}),a=this.device.createCommandEncoder(),l=a.beginComputePass();l.setPipeline(this.statsPipeline),l.setBindGroup(0,s);const c=Math.ceil(e.length/256);l.dispatchWorkgroups(c),l.end(),a.copyBufferToBuffer(n,0,r,0,32),this.device.queue.submit([a.finish()]),await r.mapAsync(globalThis.GPUMapMode.READ);const h=new Float32Array(r.getMappedRange().slice(0));r.unmap(),i.destroy(),n.destroy(),r.destroy();const[u,d,f,g,m]=h,y=Math.floor(m),b=y>0?f/y:0,v=y>1?(g-f*f/y)/(y-1):0,S=Math.sqrt(Math.max(0,v));return{min:u,max:d,mean:b,std:S,count:y}}async calculateBounds(e){if(!this.isInitialized)throw new Error("[GpuCompute] Not initialized");const t=globalThis.GPUBufferUsage,i=this.device.createBuffer({size:e.byteLength,usage:t.STORAGE|t.COPY_DST});this.device.queue.writeBuffer(i,0,e);const n=this.device.createBuffer({size:16,usage:t.STORAGE|t.COPY_SRC}),r=this.device.createBuffer({size:16,usage:t.MAP_READ|t.COPY_DST}),s=this.device.createBindGroup({layout:this.minmaxPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:i}},{binding:1,resource:{buffer:n}}]}),a=this.device.createCommandEncoder(),l=a.beginComputePass();l.setPipeline(this.minmaxPipeline),l.setBindGroup(0,s);const c=e.length/2,h=Math.ceil(c/256);l.dispatchWorkgroups(h),l.end(),a.copyBufferToBuffer(n,0,r,0,16),this.device.queue.submit([a.finish()]),await r.mapAsync(globalThis.GPUMapMode.READ);const u=new Float32Array(r.getMappedRange().slice(0));return r.unmap(),i.destroy(),n.destroy(),r.destroy(),{xMin:u[0],xMax:u[1],yMin:u[2],yMax:u[3]}}async downsample(e,t){if(!this.isInitialized)throw new Error("[GpuCompute] Not initialized");const i=e.length/2;if(i<=t)return e;const n=globalThis.GPUBufferUsage,r=Math.ceil(t/2),s=Math.ceil(i/r),a=r*2,l=new Uint32Array([i,a,s,0]),c=this.device.createBuffer({size:16,usage:n.UNIFORM|n.COPY_DST});this.device.queue.writeBuffer(c,0,l);const h=this.device.createBuffer({size:e.byteLength,usage:n.STORAGE|n.COPY_DST});this.device.queue.writeBuffer(h,0,e);const u=a*2*4,d=this.device.createBuffer({size:u,usage:n.STORAGE|n.COPY_SRC}),f=this.device.createBuffer({size:u,usage:n.MAP_READ|n.COPY_DST}),g=this.device.createBindGroup({layout:this.downsamplePipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:c}},{binding:1,resource:{buffer:h}},{binding:2,resource:{buffer:d}}]}),m=this.device.createCommandEncoder(),y=m.beginComputePass();y.setPipeline(this.downsamplePipeline),y.setBindGroup(0,g);const b=Math.ceil(r/64);y.dispatchWorkgroups(b),y.end(),m.copyBufferToBuffer(d,0,f,0,u),this.device.queue.submit([m.finish()]),await f.mapAsync(globalThis.GPUMapMode.READ);const v=new Float32Array(f.getMappedRange().slice(0));return f.unmap(),c.destroy(),h.destroy(),d.destroy(),f.destroy(),v}async detectPeaks(e,t={}){if(!this.isInitialized)throw new Error("[GpuCompute] Not initialized");const i=t.threshold??0,n=t.minDistance??1,r=globalThis.GPUBufferUsage,s=new Float32Array([e.length,i,n,0]),a=this.device.createBuffer({size:16,usage:r.UNIFORM|r.COPY_DST});this.device.queue.writeBuffer(a,0,new Uint8Array(s.buffer));const l=this.device.createBuffer({size:e.byteLength,usage:r.STORAGE|r.COPY_DST});this.device.queue.writeBuffer(l,0,e);const c=e.length*16,h=this.device.createBuffer({size:c,usage:r.STORAGE|r.COPY_SRC}),u=this.device.createBuffer({size:c,usage:r.MAP_READ|r.COPY_DST}),d=this.device.createBindGroup({layout:this.peaksPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:a}},{binding:1,resource:{buffer:l}},{binding:2,resource:{buffer:h}}]}),f=this.device.createCommandEncoder(),g=f.beginComputePass();g.setPipeline(this.peaksPipeline),g.setBindGroup(0,d);const m=Math.ceil(e.length/64);g.dispatchWorkgroups(m),g.end(),f.copyBufferToBuffer(h,0,u,0,c),this.device.queue.submit([f.finish()]),await u.mapAsync(globalThis.GPUMapMode.READ);const y=new ArrayBuffer(c);new Uint8Array(y).set(new Uint8Array(u.getMappedRange())),u.unmap();const b=new DataView(y),v=[];for(let S=0;S<e.length;S++){const T=S*16;b.getUint32(T+8,!0)&&v.push({index:b.getUint32(T,!0),value:b.getFloat32(T+4,!0)})}return a.destroy(),l.destroy(),h.destroy(),u.destroy(),v}destroy(){this.device=null,this.statsPipeline=null,this.minmaxPipeline=null,this.downsamplePipeline=null,this.peaksPipeline=null,this.isInitialized=!1}}w.AnnotationManager=ht,w.BaseBufferStore=An,w.BaseTextureStore=_n,w.DARK_THEME=fe,w.DEFAULT_THEME=lt,w.ELECTROCHEM_THEME=at,w.EventEmitter=Pe,w.GpuBenchmark=mo,w.GpuCompute=$e,w.GpuRenderer=Rt,w.LIGHT_THEME=st,w.LinearScale=xe,w.LogScale=ve,w.MIDNIGHT_THEME=rt,w.NativeWebGLRenderer=ce,w.OverlayRenderer=ct,w.PipelineCache=Fn,w.SciChart=Bn,w.Series=vt,w.SeriesAdapter=Oe,w.TOOLTIP_THEMES=pt,w.TooltipManager=bt,w.WebGLBackend=Q,w.WebGPUBackend=J,w.WebGPURenderer=De,w.calculateStats=Me,w.calculateTargetPoints=vn,w.connectStreamToChart=Tn,w.createChart=Mt,w.createGpuRenderer=go,w.createMessageParser=wn,w.createMockStream=Pn,w.createNativeRenderer=ce,w.createRenderer=Wi,w.createScale=rn,w.createTheme=di,w.createWebSocketStream=Mn,w.detectCycles=qe,w.detectPeaks=Ke,w.downsampleLTTB=Qe,w.formatScientific=He,w.formatValue=Ne,w.formatWithPrefix=Xe,w.generateCycleColors=je,w.getBestPrefix=Te,w.getThemeByName=Be,w.getTooltipThemeForChartTheme=te,w.interleaveData=ke,w.lttbDownsample=bn,w.minMaxDownsample=xn,w.movingAverage=Je,w.parseColor=ae,w.parseColorToRGBA=Ge,w.useSciChart=Et,w.validateData=Ze,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
871
871
|
//# sourceMappingURL=scichart-engine.umd.js.map
|