function X(e,r=5){if(e.lengths.data.map(l=>l[1])),D=r.flatMap(s=>s.data.map(l=>l[0])),p=x!==void 0?x:Math.min(...w),t=a!==void 0?a:Math.max(...w),h=t-p||1,C=Math.min(...D),O=Math.max(...D)-C||1;if(e.clearRect(0,0,n,i),k){e.beginPath(),e.strokeStyle="#aaa",e.lineWidth=1,e.font="15px sans-serif",e.fillStyle=r[0]?.strokeColor||"#000";for(let s=0;s<=y;s++){let l=p+h*s/y,M=c+(1-(l-p)/h)*S;e.moveTo(0,M),e.lineTo(5,M),e.fillText(l.toFixed(2),8,M+5)}e.stroke()}for(let s of r){let l=X(s.data,o.averageData??1),M=s.strokeColor||"#000";e.beginPath(),e.strokeStyle=M,e.lineWidth=1;let g=!1,d=null,F=E||600;for(let b=0;bt){g=!1,d=null;continue}d!=null&&v-d>F&&(g=!1);let f=(v-C)/O*n,T=c+(1-(u-p)/h)*S;g?e.lineTo(f,T):(e.moveTo(f,T),g=!0),d=v}e.stroke()}if(m!==null&&m>=0&&m<=n){let s=C+m/n*O;e.beginPath(),e.strokeStyle="#888",e.lineWidth=1,e.moveTo(m,0),e.lineTo(m,i),e.stroke(),e.font="12px sans-serif";let l=15;e.fillStyle="#fff";let M=o.dateFormat??(g=>new Date(g).toLocaleTimeString());e.fillText(M(s),m+6,l),l+=15;for(let g of r){let{data:d,strokeColor:F="#fff"}=g,b=d[0],v=Math.abs(b[0]-s);for(let u=1;u{t.style.position="absolute",t.style.top=t.style.left="0",t.style.width=t.style.height="100%",o.appendChild(t)}),i.style.pointerEvents="none";let x=n.getContext("2d"),a=i.getContext("2d"),k=e,y={...r},m=null,E=!1,c=()=>{let t=o.clientWidth,h=o.clientHeight;!t||!h||n.width===t&&n.height===h||(n.width=t,n.height=h,i.width=t,i.height=h,S(),w(m))},R=typeof ResizeObserver<"u"?new ResizeObserver(c):null;R?.observe(o),window.addEventListener("resize",c);let S=()=>{z(x,k,{...y,width:n.width,height:n.height})},w=t=>{if(a.clearRect(0,0,i.width,i.height),t==null)return;let h=k.flatMap(f=>f.data.map(T=>T[1])),C=k.flatMap(f=>f.data.map(T=>T[0])),L=y.min??Math.min(...h),s=(y.max??Math.max(...h))-L||1,l=Math.min(...C),g=Math.max(...C)-l||1,d=l+t/n.width*g;a.beginPath(),a.strokeStyle="#888",a.lineWidth=1,a.moveTo(t,0),a.lineTo(t,i.height),a.stroke(),a.font="12px sans-serif",a.fillStyle="#fff";let F=y.dateFormat??(f=>new Date(f).toLocaleTimeString());a.fillText(F(d),t>n.width-100?t-100:t+6,15);let b=10,u=i.height-b-10,P=30;for(let{data:f,strokeColor:T="#fff"}of k){let Y=f[0],V=Math.abs(Y[0]-d);for(let A=1;An.width-100?t-100:t+6,P),P+=15;let N=b+(1-(Y[1]-L)/s)*u;a.beginPath(),a.arc(t,N,3,0,Math.PI*2),a.fill()}},D=t=>{let h=o.getBoundingClientRect(),C=n.width/h.width;m=(t.clientX-h.left)*C,E||(E=!0,requestAnimationFrame(()=>{w(m),E=!1}))},p=()=>{m=null,w(null)};return o.addEventListener("mousemove",D),o.addEventListener("mouseleave",p),setTimeout(c,0),{element:o,setSeries(t){k=t,c(),S(),w(m)},setOptions(t){y={...y,...t},c(),S(),w(m)},destroy(){R?.disconnect(),window.removeEventListener("resize",c),o.removeEventListener("mousemove",D),o.removeEventListener("mouseleave",p)}}}export{H as createChartElement,z as drawChart};