(function(){"use strict";let s,r,i;onmessage=function(t){t.data.canvas&&(s=t.data.canvas,f()),t.data.opts&&(r=t.data.opts,f()),t.data.tracesData&&(i=t.data.tracesData,f())};function x(t,a){let n=!1;return()=>{n||(n=!0,setTimeout(()=>{n=!1,t()},a))}}const T=1;let l=0;async function D(){if(!s||!r)return;const{margins:t,canvasWidth:a,canvasHeight:n,visibleStartTimeSec:u,visibleEndTimeSec:S,channels:m,samplingFrequency:C}=r,h=m.length;s.width=a,s.height=n;const e=s.getContext("2d");if(!e)return;l+=1;const F=l;if(e.clearRect(0,0,a,n),r.zoomInRequired&&(e.fillStyle="pink",e.textAlign="center",e.font="bold 26px Arial",e.fillText("Zoom in to view traces",a/2,n/2)),!i)return;e.save(),e.beginPath(),e.rect(t.left,t.top,a-t.left-t.right,n-t.top-t.bottom),e.clip();const d=o=>n-t.bottom-(o+.5-0)/(h-0)*(n-t.top-t.bottom),k=o=>t.left+(o/C-u)/(S-u)*(a-t.left-t.right),P=d(1)-d(0);let p=Date.now();for(let o=0;o<h;o++){if(F!==l)return;const g=i.data[o];if(!g)continue;const b=m[o],I=d(o);e.strokeStyle="black",e.beginPath();for(let c=i.startFrame;c<i.endFrame;c++){const w=k(c),v=I-(g[c-i.startFrame]-b.offset)*P/2*T*b.scale;c===i.startFrame?e.moveTo(w,v):e.lineTo(w,v)}e.stroke(),Date.now()-p>100&&(p=Date.now(),await y(0))}}const f=x(D,10);function y(t){return new Promise(a=>{setTimeout(a,t)})}})();
