@canplot/react 0.5.12 → 0.5.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/canplot.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var Fe=Object.defineProperty;var Xe=(e,t,n)=>t in e?Fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var O=(e,t,n)=>Xe(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),g=require("react"),W=(e,t,n)=>Math.min(Math.max(e,t),n),Oe=e=>e.reduce((t,n)=>t+(n??0),0),Ke=(e,t)=>{let n=0;for(let s=0;s<e.length;s++)Math.abs(e[s]-t)<Math.abs(e[n]-t)&&(n=s);return n},Pe=(e,t,n,s)=>{const o=F(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,r=(o.origin==="x"?i.width:i.height)/(o.max-o.min);return t/r},F=(e,t)=>e.scales.find(n=>n.id===t)??null,D=(e,t)=>{const n=window.devicePixelRatio||1;e.lineCap=t?.lineCap??"butt",e.lineDashOffset=n*(t?.lineDashOffset??0),e.lineJoin=t?.lineJoin??"miter",e.lineWidth=n*(t?.lineWidth??1),e.miterLimit=n*(t?.miterLimit??10),e.strokeStyle=t?.strokeStyle??"black",e.fillStyle=t?.fillStyle??e.strokeStyle,e.font=t?.font??`${10*n}px sans-serif`,e.textAlign=t?.textAlign??"start",e.direction=t?.direction??"inherit",e.textBaseline=t?.textBaseline??"alphabetic",e.fontKerning=t?.fontKerning??"auto"},se=(e,t,n,s)=>{const o=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,i=F(e,n);if(!i)return null;const r=(i.origin==="x"?o.width:o.height)/(i.max-i.min);return t*r},V=(e,t,n,s)=>{const o=F(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,r=se(e,t-o.min,n,s);return r===null?null:o.origin==="x"?W(i.x+r,i.x-10*i.width,i.x+11*i.width):W(i.y+i.height-r,i.y-10*i.height,i.y+11*i.height)},z=(e,t,n)=>{if(t===null)return null;const s=n==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS;return W(t,s.x,s.x+s.width)},N=(e,t,n)=>{if(t===null)return null;const s=n==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS;return W(t,s.y,s.y+s.height)},ne=(e,t,n)=>{if(t===null)return!1;const s=F(e,n);return s?t>=s.min&&t<=s.max:!1},_=(e,t,n,s)=>{const o=F(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,r=o.origin==="x"?(t-i.x)/i.width:(i.height-t+i.y)/i.height;return o.min+r*(o.max-o.min)},X=(e,t)=>{if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!X(e[o],t[o]))return!1;return!0}const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!X(e[o],t[o]))return!1;return!0},Ye=e=>{const{ctx:t,scales:n}=e;for(const s of n){if(!s.axis)continue;t.save(),D(t,{strokeStyle:"black",fillStyle:"black",lineWidth:1,...s.axis.style});const o=s.axis.canvasRect;if(s.origin==="x"){if(s.axis.position==="bottom")t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x+o.width,o.y),t.stroke();else if(s.axis.position==="top"){const i=o.y+o.height;t.beginPath(),t.moveTo(o.x,i),t.lineTo(o.x+o.width,i),t.stroke()}}else if(s.axis.position==="left"){const i=o.x+o.width;t.beginPath(),t.moveTo(i,o.y),t.lineTo(i,o.y+o.height),t.stroke()}else s.axis.position==="right"&&(t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x,o.y+o.height),t.stroke());t.restore()}};function je(e){return t=>{for(const n of e)fe(n,t)}}function Be(e){return t=>{const n=[];for(const s of e){const o=fe(s,t),i=typeof o=="function";n.push(i?o:()=>fe(s,null))}return()=>{for(const s of n)s()}}}function fe(e,t){if(typeof e=="function")return e(t);e&&(e.current=t)}var ze=parseInt(g.version.split(".")[0],10)>=19?Be:je;const Ee=g.createContext({listeners:[],subscribe:()=>()=>{},notifyListeners:()=>{}}),Ne=()=>{const e=[];return{listeners:e,subscribe:(s,o)=>(e.push([o,s]),e.sort((i,r)=>i[0]-r[0]),()=>{const i=e.findIndex(([,r])=>r===s);i!==-1&&e.splice(i,1)}),notifyListeners:()=>{for(const[,s]of e)s()}}},he=g.createContext(null),Me=g.createContext(()=>{}),de={TOP:400,MIDDLE:300,BOTTOM:200,BACKGROUND:100};class me{constructor(){O(this,"_frame",null);O(this,"clampXPosToChartArea",(t,n="canvas")=>z(this.frame,t,n));O(this,"clampYPosToChartArea",(t,n="canvas")=>N(this.frame,t,n));O(this,"valToPos",(t,n,s="canvas")=>V(this.frame,t,n,s));O(this,"valToPxDistance",(t,n,s="canvas")=>se(this.frame,t,n,s));O(this,"valFits",(t,n)=>ne(this.frame,t,n));O(this,"getScale",t=>F(this.frame,t))}_updateFrame(t){this._frame=t}get frame(){if(!this._frame)throw new Error("Frame not set in FrameDrawer");return this._frame}get ctx(){return this.frame.ctx}}const $e=g.forwardRef(({configuration:e,children:t,style:n,...s},o)=>{const i=g.useRef(null),r=g.useRef(null),c=He(r),[u,l]=g.useState(null),p=g.useMemo(()=>qe(e,c,u),[e,c,u]);g.useLayoutEffect(()=>{l(i.current?.getContext("2d")||null)},[i]);const h=window.devicePixelRatio||1;return k.jsxs("div",{ref:ze([o,r]),style:{position:"relative",overflow:"hidden",...n},"data-canplotroot":!0,...s,children:[k.jsx("canvas",{ref:i,width:c.width*h,height:c.height*h,style:{inset:0,position:"absolute",width:`${c.width}px`,height:`${c.height}px`}}),p&&k.jsx(Ve,{frame:p,children:t})]})}),Ve=({frame:e,children:t})=>{const n=g.useMemo(Ne,[]),[s,o]=g.useState(0);g.useLayoutEffect(()=>{e?.ctx.clearRect(0,0,e.ctx.canvas.width,e.ctx.canvas.height)},[e,s]);const i=g.useRef(null);i.current=e,g.useLayoutEffect(()=>{n.subscribe(()=>{i.current&&Ye(i.current)},de.BOTTOM)},[n]),g.useLayoutEffect(()=>{let c=null;return c=window.requestAnimationFrame(()=>{c=null,n.notifyListeners()}),()=>{c&&cancelAnimationFrame(c)}},[s,e,n]);const r=g.useCallback(()=>{o(c=>c+1)},[o]);return k.jsx(Ee.Provider,{value:n,children:k.jsx(Me.Provider,{value:r,children:k.jsx(he.Provider,{value:e,children:t})})})},He=e=>{const[t,n]=g.useState({width:0,height:0}),[s]=g.useState(()=>new ResizeObserver(o=>{for(const i of o){const r=Math.round(i.contentRect.width),c=Math.round(i.contentRect.height);n(u=>u.width!==r||u.height!==c?{...u,width:r,height:c}:u)}}));return g.useLayoutEffect(()=>{if(!e.current)return;const o=e.current.clientWidth,i=e.current.clientHeight;return n(r=>r.width!==o||r.height!==i?{...r,width:o,height:i}:r),s.observe(e.current,{box:"border-box"}),()=>s.disconnect()},[s,e]),t},qe=(e,t,n)=>{if(!n)return null;const s=window.devicePixelRatio||1;if(t.width===0||t.height===0)return null;const o={x:e.padding.left,y:e.padding.top,width:t.width-e.padding.left-e.padding.right,height:t.height-e.padding.top-e.padding.bottom};for(const a of e.scales)a.axis&&(a.origin==="x"?(a.axis.position==="bottom"||a.axis.position==="top")&&(o.height=Math.max(0,o.height-a.axis.size),a.axis.position==="top"&&(o.y+=a.axis.size)):(a.axis.position==="left"||a.axis.position==="right")&&(o.width=Math.max(0,o.width-a.axis.size),a.axis.position==="left"&&(o.x+=a.axis.size)));const i={x:o.x*s,y:o.y*s,width:o.width*s,height:o.height*s},r=[];let c=e.padding.left*s,u=t.width*s-e.padding.right*s,l=t.height*s-e.padding.bottom*s,p=e.padding.top*s;for(const a of e.scales){if(!a.axis){r.push({...a,axis:null});continue}let v;if(a.origin==="x")switch(a.axis.position){case"bottom":l-=a.axis.size*s,v={x:o.x,y:l/s,width:o.width,height:a.axis.size};break;case"top":p+=a.axis.size*s,v={x:o.x,y:p/s-a.axis.size,width:o.width,height:a.axis.size};break;case"left":case"right":throw new Error("Invalid axis position for x origin")}else switch(a.axis.position){case"left":c+=a.axis.size*s,v={x:c/s-a.axis.size,y:o.y,width:a.axis.size,height:o.height};break;case"right":u-=a.axis.size*s,v={x:u/s,y:o.y,width:a.axis.size,height:o.height};break;case"top":case"bottom":throw new Error("Invalid axis position for y origin")}const d={x:v.x*s,y:v.y*s,width:v.width*s,height:v.height*s};r.push({...a,axis:{...a.axis,cssRect:v,canvasRect:d}})}return{ctx:n,dpr:s,padding:e.padding,scales:r,chartAreaCSS:o,chartAreaCanvasPX:i}},Y=(e,t,n)=>{const s=g.useContext(he),o=g.useContext(Me),i=g.useContext(Ee);if(!s||!o)throw new Error("useFrame must be used within a CanPlot component");const[r]=g.useState(()=>new me);r._updateFrame(s);const c=g.useRef(r);c.current=r;const u=g.useRef(t);u.current=t,g.useLayoutEffect(()=>{const l=i.subscribe(()=>{u.current(r)},typeof e=="number"?e:de[e]);return()=>{l()}},[i,e,r]),g.useLayoutEffect(()=>{o()},[o,...n]),g.useEffect(()=>()=>{o()},[o])},pe=()=>{const e=g.useContext(he);if(!e)throw new Error("useFrame must be used within a CanPlot component");return g.useMemo(()=>{const t=new me;return t._updateFrame(e),t},[e])},We=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,style:o,globalAlpha:i})=>(Y(e,({ctx:r,clampXPosToChartArea:c,clampYPosToChartArea:u,valToPos:l})=>{r.save(),r.beginPath(),D(r,o);const p=r.getLineDash();o?.lineDash&&r.setLineDash(o.lineDash),i!==void 0&&(r.globalAlpha=i);for(const h of t){const a=c(l(h.x,n,"canvas")),v=u(l(h.y,s,"canvas"));a===null||v===null||r.lineTo(a,v)}r.stroke(),p&&r.setLineDash(p),r.restore()},[t,n,s,o,i]),null),Ge=g.memo(We,X),Je=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,xStrategy:o="clip",yStrategy:i="clip",radius:r=5,style:c,globalAlpha:u})=>(Y(e,({ctx:l,valToPos:p,valFits:h,clampXPosToChartArea:a,clampYPosToChartArea:v})=>{l.save(),D(l,c),u!==void 0&&(l.globalAlpha=u);const d=[];for(const y of t){let f=null,m=null;const w=p(y.x,n);if(w===null)continue;if(o==="clip"){if(!h(y.x,n))continue;f=w}else f=a(w,"canvas");const T=p(y.y,s);if(T!==null){if(i==="clip"){if(!h(y.y,s))continue;m=T}else m=v(T,"canvas");f===null||m===null||d.push({x:f,y:m})}}if(c?.fillStyle)for(const y of d)l.beginPath(),l.arc(y.x,y.y,r,0,Math.PI*2),l.fill();if(c?.strokeStyle){l.beginPath();for(const y of d)l.moveTo(y.x+r,y.y),l.arc(y.x,y.y,r,0,Math.PI*2);l.stroke()}l.restore()},[t,n,s,r,c,u]),null),Ze=g.memo(Je,X),Qe=({data:e,xScaleId:t,yScaleId:n,style:s,barWidth:o,xPositionOffset:i,globalAlpha:r,radius:c,layer:u="MIDDLE"})=>(Y(u,({ctx:l,valToPxDistance:p,valToPos:h,clampXPosToChartArea:a,clampYPosToChartArea:v})=>{if(e.length===0)return;const d=v(h(0,n,"canvas"),"canvas");if(d===null)return;const y=p(o,t,"canvas")??0,f=[];for(const m of e){const w=h(m.x,t,"canvas");if(w===null)continue;const T=w-y/2+i*y,S=v(h(m.y,n,"canvas"),"canvas");if(S===null)continue;const x=d-S,b=a(T,"canvas"),C=a(T+y,"canvas")-b;f.push({x:b,y:S,width:C,height:x})}if(l.save(),D(l,s),r!==void 0&&(l.globalAlpha=r),s?.fillStyle)for(const m of f)l.beginPath(),c?l.roundRect(m.x,m.y,m.width,m.height,c):l.rect(m.x,m.y,m.width,m.height),l.fill();if(s?.strokeStyle){l.beginPath();for(const m of f)c?l.roundRect(m.x,m.y,m.width,m.height,c):l.rect(m.x,m.y,m.width,m.height);l.stroke()}l.restore()},[e,t,n,s,o,i,c,r]),null),et=g.memo(Qe,X),tt=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,style:o})=>(Y(e,({ctx:i,clampXPosToChartArea:r,clampYPosToChartArea:c,valToPos:u})=>{const l=[];for(const h of t){const a=r(u(h.x,n));if(a===null)continue;const v=c(u(h.y[0],s));if(v===null)continue;const d=c(u(h.y[1],s));d!==null&&(l.push({x:a,y:v}),l.unshift({x:a,y:d}))}const p=l[0];if(p){i.save(),i.beginPath(),D(i,o),i.moveTo(p.x,p.y);for(const h of l)i.lineTo(h.x,h.y);i.closePath(),i.fill(),i.restore()}},[t,n,s,o]),null),nt=g.memo(tt,X),st=({layer:e="MIDDLE",data:t,stroked:n,xScaleId:s,yScaleId:o,style:i})=>(Y(e,({ctx:r,clampXPosToChartArea:c,clampYPosToChartArea:u,valToPos:l})=>{const p=[];for(const d of t){const y=c(l(d.x,s)),f=u(l(d.y,o));y===null||f===null||p.push({x:y,y:f})}const h=p.at(0),a=p.at(-1);if(!h||!a)return;const v=u(l(0,o));if(v!==null){r.save(),r.beginPath(),D(r,i),r.moveTo(h.x,v);for(const d of p)r.lineTo(d.x,d.y);if(r.lineTo(a.x,v),r.closePath(),r.fill(),n){r.beginPath(),r.moveTo(h.x,h.y);for(const d of p)r.lineTo(d.x,d.y);r.stroke()}r.restore()}},[t,n,s,o,i]),null),ot=g.memo(st,X),it=({layer:e="BOTTOM",scaleId:t,tickStyle:n,labelStyle:s,labelGap:o,tickSize:i,ticks:r})=>(Y(e,({ctx:c,valToPos:u,getScale:l,frame:p})=>{const h=l(t);if(!h||!h.axis||h.origin!=="x")return;const a=h.axis,v=a.position==="top"?a.canvasRect.y+a.canvasRect.height:a.canvasRect.y,d=window.devicePixelRatio||1,y=v,f=(i??6)*d,m=a.position==="top"?v-f:v+f,w=(o??12)*d;c.save(),c.fontKerning="auto",D(c,{...n}),c.beginPath();const T=Array.isArray(r)?r:r({...h,axis:a},p);for(const{value:S}of T){const x=u(S,t,"canvas");x!==null&&(c.moveTo(x,y),c.lineTo(x,m))}c.stroke(),c.restore(),c.save(),D(c,{textBaseline:a.position==="top"?"bottom":"top",textAlign:"center",...n,...s,font:Re(s?.font??n?.font)});for(const{value:S,label:x}of T){const b=u(S,t,"canvas");if(b===null)continue;const C=x.split(`
2
- `);for(let R=0;R<C.length;R++)c.fillText(C[R],b,m+d*2+R*w)}c.restore()},[r,t,n,s]),null),rt=g.memo(it,X),ct=({layer:e="BOTTOM",scaleId:t,tickStyle:n,labelStyle:s,labelGap:o,tickSize:i,ticks:r})=>(Y(e,({ctx:c,valToPos:u,getScale:l,frame:p})=>{const h=l(t);if(!h||!h.axis||h.origin!=="y")return;const a=h.axis,v=a.position==="left"?a.canvasRect.x+a.canvasRect.width:a.canvasRect.x,d=v,y=i??6,f=a.position==="left"?v-y:v+y,m=o??12,w=Array.isArray(r)?r:r({...h,axis:a},p);c.save(),c.fontKerning="auto",D(c,{...n}),c.beginPath();for(const{value:T}of w){const S=u(T,t,"canvas");S!==null&&(c.moveTo(d,S),c.lineTo(f,S))}c.stroke(),c.restore(),c.save(),D(c,{textBaseline:"middle",textAlign:a.position==="left"?"right":"left",...n,...s,font:Re(s?.font??n?.font)});for(const{value:T,label:S}of w){const x=u(T,t,"canvas");if(x===null)continue;const b=S.split(`
3
- `);for(let C=0;C<b.length;C++)c.fillText(` ${b[C]} `,f,x+C*m)}c.restore()},[r,t,n,s]),null),at=g.memo(ct,X),Re=e=>{if(e)try{return e.replace(/(\d+)px/,(t,n)=>`${parseInt(n)*window.devicePixelRatio||1}px`)}catch{}return e},L=()=>{const e=[];return{addEventListener:(t,n)=>(e.push({syncKey:t,callback:n}),()=>{const s=e.findIndex(o=>o.callback===n);s!==-1&&e.splice(s,1)}),dispatchEvent:(t,n)=>{for(const s of e)s.syncKey===t&&s.callback(t,n)}}},M={dblclick:L(),click:L(),contextmenu:L(),move:L(),mousedown:L(),mouseup:L(),spanselect:L(),documentmouseup:L(),pressandwheel:L(),sync_move:L()},I=(e,t,n)=>{const s=g.useRef(n);s.current=n,g.useEffect(()=>M[e].addEventListener(t,(i,r)=>{s.current(r,i)}),[t,e,s])},ye=g.createContext(""),oe=(e,t)=>{const n=g.useContext(ye);return I(e,n,t)},lt=(e,t,n,s,o)=>{if(!t)return;const i=s??n.scales.find(h=>h.origin==="x")?.id,r=o??n.scales.find(h=>h.origin==="y")?.id,c=e.clientX-t.left,u=i?{scaleId:i,value:_(n,c,i,"css")}:null,l=e.clientY-t.top,p=r?{scaleId:r,value:_(n,l,r,"css")}:null;return{pointerSyncPosition:{x:u,y:p},cssX:c,cssY:l}},B=(e,t)=>{const{x:n,y:s}=e,o=n&&t.scales.some(r=>r.id===n.scaleId)?V(t,n.value,n.scaleId,"css"):null,i=s&&t.scales.some(r=>r.id===s.scaleId)?V(t,s.value,s.scaleId,"css"):null;return{cssX:o,cssY:i,scaled:Object.fromEntries(t.scales.flatMap(r=>{const c=r.origin==="y"?i:o;return c===null?[]:[[r.id,_(t,c,r.id,"css")]]}))}},Se=(e,t,n)=>{const s=V(n,t.from,t.scaleId,"css"),o=V(n,t.to,t.scaleId,"css");if(s===null||o===null)return null;const i=n.scales.flatMap(r=>{if(r.origin!==e)return[];const c=_(n,s,r.id,"css"),u=_(n,o,r.id,"css");return c===null||u===null?[]:[{scaleId:r.id,from:c,to:u}]});return{fromCSS:s,toCSS:o,scaled:i}},ut=({id:e,onClick:t,onDblClick:n,onMouseMove:s,onMouseDown:o,onMouseUp:i,onDocumentMouseUp:r,onSpanSelect:c,onContextMenu:u,className:l,style:p,sync:h,innerChildren:a,children:v})=>{const d=g.useId();return I("dblclick",d,y=>{n?.(y)}),I("click",d,y=>{t?.(y)}),I("move",d,y=>{s?.(y)}),I("mousedown",d,y=>{o?.(y)}),I("mouseup",d,y=>{i?.(y)}),I("documentmouseup",d,y=>{r?.(y)}),I("spanselect",d,y=>{c?.(y)}),I("contextmenu",d,y=>{u?.(y)}),k.jsxs(ye.Provider,{value:d,children:[k.jsx(ft,{id:e,className:l,style:p,sync:h,children:a}),v]})},ft=({id:e,className:t,style:n,sync:s,children:o})=>{const i=g.useRef(null),r=pe().frame,c=g.useRef(r);c.current=r;const u=g.useContext(ye),l=s?.key||u,p=g.useRef(null),h=g.useRef(null),a=g.useRef(null),v=()=>{const f=i.current?.parentElement;if(f){if(f.dataset.canplotroot===void 0)throw new Error("ChartAreaInteractions must be used within a CanPlot component");return f.getBoundingClientRect()}},d=(f,m)=>{const w=lt(f,v(),c.current,s?.xViaScaleId,s?.yViaScaleId);w&&m(w.pointerSyncPosition,{cssX:w.cssX,cssY:w.cssY},{ctrlKey:f.ctrlKey,altKey:f.altKey,shiftKey:f.shiftKey,metaKey:f.metaKey})},y=g.useRef(d);return y.current=d,g.useEffect(()=>{const f=x=>{const b=h.current;b&&M.spanselect.dispatchEvent(u,{...b,completed:!0}),M.documentmouseup.dispatchEvent(u,{frame:c.current,keys:{ctrlKey:x.ctrlKey,altKey:x.altKey,shiftKey:x.shiftKey,metaKey:x.metaKey}})},m=x=>{const b={ctrlKey:x.ctrlKey,altKey:x.altKey,shiftKey:x.shiftKey,metaKey:x.metaKey},C=a.current;if(C&&Object.entries(b).some(([P,E])=>C.keys[P]!==E)){const P={...C,keys:b};a.current=P,M.sync_move.dispatchEvent(l,P)}const R=h.current;if(R&&Object.entries(b).some(([P,E])=>R.keys[P]!==E)){x.stopPropagation(),x.preventDefault();const P={...R,keys:b};h.current=P,M.spanselect.dispatchEvent(u,P)}},w=x=>{y.current(x,(b,{cssX:C,cssY:R},P)=>{const E=p.current;if(!E||!b.x||!b.y)return;const A=c.current,j=E.xRangeCss.start,re=C,ce=E.yRangeCss.start,ae=R,G=F(A,b.x.scaleId);if(!G)return;const J=F(A,b.y.scaleId);if(!J)return;p.current={xRangeCss:{start:j,end:re},yRangeCss:{start:ce,end:ae}};let H="below_threshold";const le=Math.abs(ce-ae),ue=Math.abs(j-re);le<10&&ue<10?H="below_threshold":le>30&&ue>30?H="box":le>ue?H="y":H="x";const ge=_(A,z(c.current,j,"css"),G.id,"css");if(ge===null)return;const we=_(A,z(c.current,re,"css"),G.id,"css");if(we===null)return;const xe=_(A,N(c.current,ce,"css"),J.id,"css");if(xe===null)return;const Te=_(A,N(c.current,ae,"css"),J.id,"css");if(Te===null)return;const Z=Se("x",{scaleId:G.id,from:ge,to:we},c.current),Q=Se("y",{scaleId:J.id,from:xe,to:Te},c.current),Ue=Z?.scaled,_e=Q?.scaled,be={mode:H,frame:c.current,completed:!1,x:{css:Z?{from:Z.fromCSS,to:Z.toCSS}:void 0,scaled:Ue??[]},y:{css:Q?{from:Q.fromCSS,to:Q.toCSS}:void 0,scaled:_e??[]},keys:P};h.current=be,M.spanselect.dispatchEvent(u,be)})},T=x=>{y.current(x,(b,C,R)=>{const P=B(b,c.current);if(!P)return;if(Object.values(R).some(A=>A)){x.preventDefault();const A=Math.abs(x.deltaY)>Math.abs(x.deltaX)?x.deltaY:x.deltaX;M.pressandwheel.dispatchEvent(u,{pointer:P,frame:c.current,keys:R,deltaX:x.deltaX,deltaY:x.deltaY,deltaAbs:A})}})};document.addEventListener("mouseup",f),document.addEventListener("keydown",m),document.addEventListener("keyup",m),document.addEventListener("mousemove",w);const S=i.current;return S?.addEventListener("wheel",T,{passive:!1}),()=>{document.removeEventListener("mouseup",f),document.removeEventListener("keydown",m),document.removeEventListener("keyup",m),document.removeEventListener("mousemove",w),S?.removeEventListener("wheel",T)}},[c,u,l,y]),I("sync_move",l,f=>{const m=f.positions?B(f.positions,c.current):null;a.current=f,M.move.dispatchEvent(u,{frame:c.current,pointer:m??null,keys:f.keys,source:f.originInteractionsId===u?"own":"sync"})}),k.jsx("div",{ref:i,id:e,className:t,style:{position:"absolute",left:r.chartAreaCSS.x,top:r.chartAreaCSS.y,width:r.chartAreaCSS.width,height:r.chartAreaCSS.height,zIndex:25,...n},onDragStart:f=>{f.preventDefault()},onClick:f=>{d(f,(m,w,T)=>{const S=B(m,c.current);S&&M.click.dispatchEvent(u,{pointer:S,frame:c.current,keys:T})})},onMouseLeave:f=>{d(f,(m,w,T)=>{M.sync_move.dispatchEvent(l,{positions:null,keys:T,originInteractionsId:u})})},onMouseMove:f=>{d(f,(m,w,T)=>{M.sync_move.dispatchEvent(l,{positions:m,keys:T,originInteractionsId:u})})},onMouseDown:f=>{d(f,(m,{cssX:w,cssY:T},S)=>{const x=B(m,c.current);x&&(M.mousedown.dispatchEvent(u,{pointer:x,frame:c.current,keys:S}),p.current={xRangeCss:{start:w,end:w},yRangeCss:{start:T,end:T}})})},onMouseUp:f=>{d(f,(m,w,T)=>{const S=B(m,c.current);if(!S)return;M.mouseup.dispatchEvent(u,{frame:c.current,pointer:S,keys:T});const x=h.current;h.current=null;const b=p.current;if(p.current=null,b&&x){const C={...x,keys:T,completed:!0};h.current=null,M.spanselect.dispatchEvent(u,C)}})},onContextMenu:f=>{f.preventDefault(),d(f,(m,w,T)=>{const S=B(m,c.current);S&&M.contextmenu.dispatchEvent(u,{frame:c.current,pointer:S,keys:T})})},onDoubleClick:f=>{d(f,(m,w,T)=>{const S=B(m,c.current);S&&M.dblclick.dispatchEvent(u,{frame:c.current,pointer:S,keys:T})})},children:o})},ht=({data:e,renderTooltip:t,xScaleId:n})=>{const[s,o]=g.useState(null);oe("move",r=>{o(r)});const i=g.useMemo(()=>{if(!s)return null;const{frame:r,pointer:c}=s,u=c?.scaled[n];if(u===void 0||!F(r,n))return null;const p=[];let h=u;for(const a of e){let v=null,d=1/0;for(const[m,w]of a.points.entries()){if(!ne(r,w.x,n)||!ne(r,w.y,a.yScaleId))continue;const T=Math.abs(w.x-u);T<d&&(d=T,v=m)}const y=a.points[v??-1],f=se(r,d,n,"css");if(!y||f===null||f>30){p.push({seriesId:a.seriesId,y:null});continue}h=y.x,p.push({seriesId:a.seriesId,y:y.y})}return{frame:r,x:h,points:p}},[e,s,n]);return t(i)},dt=({makeXStyle:e,makeXClassName:t,makeYStyle:n,makeYClassName:s})=>{const[o,i]=g.useState(null);if(oe("move",a=>{i(a)}),!o)return null;const{frame:r,pointer:c}=o,u=c?.cssX??null,l=c?.cssY??null,p=u?z(r,u,"css"):0,h=l?N(r,l,"css"):0;return k.jsxs(k.Fragment,{children:[k.jsx("div",{"data-show":!!c,className:t?.(o),style:{position:"absolute",left:0,visibility:u===null?"hidden":"visible",top:r.chartAreaCSS.y,height:r.chartAreaCSS.height,borderColor:"red",borderLeftWidth:"1px",borderLeftStyle:"solid",pointerEvents:"none",opacity:c?1:0,transform:`translateX(${p}px)`,...e?.(o)}}),k.jsx("div",{className:s?.(o),"data-show":!!c,style:{position:"absolute",visibility:l===null?"hidden":"visible",top:0,height:0,borderTop:"solid 1px red",left:r.chartAreaCSS.x,width:r.chartAreaCSS.width,pointerEvents:"none",opacity:c?1:0,transform:`translateY(${h}px)`,...n?.(o)}})]})},mt=({makeClassName:e,makeStyle:t})=>{const[n,s]=g.useState(null);oe("spanselect",i=>{s(i.mode==="below_threshold"||i.completed?null:i)});const o=g.useMemo(()=>{if(!n||n.mode==="below_threshold")return null;const i=n.mode==="y"?-1/0:n.x.css?.from??-1/0,r=n.mode==="y"?1/0:n.x.css?.to??1/0,c=n.mode==="x"?-1/0:n.y.css?.from??-1/0,u=n.mode==="x"?1/0:n.y.css?.to??1/0,l=z(n.frame,i,"css"),p=z(n.frame,r,"css"),h=N(n.frame,c,"css"),a=N(n.frame,u,"css"),v=Math.min(l,p),d=Math.min(h,a),y=Math.abs(p-l),f=Math.abs(a-h);return{leftPx:v,topPx:d,widthPx:y,heightPx:f}},[n]);return k.jsx("div",{className:n?e?.(n):void 0,style:{position:"absolute",visibility:n?"visible":"hidden",left:`${o?.leftPx??0}px`,top:`${o?.topPx??0}px`,width:`${o?.widthPx??0}px`,height:`${o?.heightPx??0}px`,pointerEvents:"none",...n?t?.(n):void 0}})},pt=({style:e,children:t,scaleId:n,...s})=>{const o=pe().getScale(n)?.axis;return o?k.jsx("div",{style:{position:"absolute",backgroundColor:"#0000ff11",left:o.cssRect.x,top:o.cssRect.y,height:o.cssRect.height,width:o.cssRect.width,...e},...s,children:t}):null},ke=60,yt=30,Ae="UTC",vt="en-GB",gt=({space:e,formatter:t,acceptableIncrements:n}={})=>(s,o)=>{const{min:i,max:r}=s,c=[],u=window.devicePixelRatio||1,l=(e??(s.origin==="x"?ke:yt))*u,p=Pe(o,l,s.id,"canvas");if(p===null)return[];const h=n??ee,a=h.find(d=>d>p)??h.at(-1)??1;let v=i;if(Math.abs(v%a)>Number.EPSILON){const d=(a-v%a)%a;v+=d}for(;v<=r&&c.length<1e3;)c.push(v),v+=a;return(t??De)(c)},De=e=>{const t=Math.max(0,Math.ceil(-Math.log10(e[1]-e[0])));return e.map(n=>({value:n,label:n.toFixed(t)}))},ee=[];for(let e=-12;e<=12;e++)ee.push(1*10**e),ee.push(2*10**e),ee.push(5*10**e);const wt=1,Le=1e3*wt,ve=60*Le,q=60*ve,ie=24*q,xt=30*ie,Tt=365*ie,bt=[[1,"milliseconds"],[2,"milliseconds"],[5,"milliseconds"],[10,"milliseconds"],[20,"milliseconds"],[50,"milliseconds"],[100,"milliseconds"],[200,"milliseconds"],[500,"milliseconds"],[1,"seconds"],[5,"seconds"],[10,"seconds"],[15,"seconds"],[30,"seconds"],[1,"minutes"],[5,"minutes"],[10,"minutes"],[15,"minutes"],[30,"minutes"],[1,"hours"],[2,"hours"],[3,"hours"],[4,"hours"],[6,"hours"],[8,"hours"],[12,"hours"],[1,"days"],[3,"days"],[5,"days"],[7,"days"],[10,"days"],[15,"days"],[1,"months"],[2,"months"],[3,"months"],[4,"months"],[6,"months"],[1,"years"],[2,"years"],[5,"years"],[10,"years"],[25,"years"],[50,"years"],[100,"years"]],te=e=>{const[t,n]=e;switch(n){case"milliseconds":return t;case"seconds":return t*Le;case"minutes":return t*ve;case"hours":return t*q;case"days":return t*ie;case"months":return t*xt;case"years":return t*Tt}},St=(e,t)=>{const n=new Date(e);return n.setUTCMilliseconds(n.getUTCMilliseconds()+t),n.getTime()},Ct=(e,t)=>{const n=new Date(e);return n.setUTCSeconds(n.getUTCSeconds()+t),n.getTime()},Pt=(e,t)=>{const n=new Date(e);return n.setUTCMinutes(n.getUTCMinutes()+t),n.getTime()},Et=(e,t)=>{const n=new Date(e);return n.setUTCHours(n.getUTCHours()+t),n.getTime()},Mt=(e,t)=>{const n=new Date(e);return n.setUTCDate(n.getUTCDate()+t),n.getTime()},Ce=(e,t)=>{const n=new Date(e);return n.setUTCMonth(n.getUTCMonth()+t),n.getTime()},U=(e,t)=>{const[n,s]=t;switch(s){case"milliseconds":return St(e,n);case"seconds":return Ct(e,n);case"minutes":return Pt(e,n);case"hours":return Et(e,n);case"days":return Mt(e,n);case"months":return Ce(e,n);case"years":return Ce(e,n*12)}};function $(e,t){const n=new Date(e),s=new Date(n.toLocaleString("en-US",{timeZone:t})),o=new Date(n.toLocaleString("en-US",{timeZone:"UTC"}));return(s.getTime()-o.getTime())/(3600*1e3)}const Rt=(e,t,n="UTC")=>{const[s,o]=t;let i=new Date(e);const r=()=>{i.setUTCHours(-$(i,n),0,0,0)};switch(o){case"milliseconds":i.setUTCMilliseconds(Math.ceil(i.getUTCMilliseconds()/s)*s);break;case"seconds":i.setUTCSeconds(Math.ceil(i.getUTCSeconds()/s)*s,0);break;case"minutes":i.setUTCMinutes(Math.ceil(i.getTime()%q/ve/s)*s,0,0);break;case"hours":{const c=$(i,n);i.setUTCHours(Math.ceil((i.getTime()+c*q)%ie/q/s)*s-c,0,0,0);break}case"days":{for(r(),i.setUTCDate(1);i.getTime()<e;)i=new Date(U(i,[s,o]));break}case"months":case"years":o==="months"?i.setUTCDate(1):o==="years"&&i.setUTCMonth(0,1),r(),i.getTime()<e&&(i=new Date(U(i,[1,o])));break}return i.getTime()},kt=({timeZone:e=Ae,space:t=ke,formatter:n,locale:s,showTimezone:o}={})=>(i,r)=>{const{min:c,max:u}=i;if(!Number.isFinite(c)||!Number.isFinite(u))return[];const l=Math.floor(r.chartAreaCanvasPX.width/t)+1,h=(u-c)/l,[a,v]=bt.find(w=>te(w)>=h)??[1,"milliseconds"];if(!a||!v)return[];const d=Rt(c,[a,v],e),y=$(d,e),f=[d];let m;for(;;){if(f.length>100)return[];switch(v){case"milliseconds":case"seconds":case"minutes":case"hours":{const w=U(d,[f.length*a,v]);m=U(w,[y-$(w,e),"hours"]);break}case"days":{const w=U(d,[f.length*a,v]);m=U(w,[y-$(w,e),"hours"]);break}case"months":case"years":{const w=U(U(U(d,[y,"hours"]),[f.length*a,v]),[-y,"hours"]);m=U(w,[y-$(w,e),"hours"]);break}}if(m>u)break;f[f.length-1]!==m&&f.push(m)}return(n??Ie({locale:s,showTimezone:o,timeZone:e}))(f)},K=(e,t,n)=>e.find(s=>s.type===n)?.value!==t.find(s=>s.type===n)?.value,Ie=({timeZone:e=Ae,locale:t=vt,showTimezone:n=!0})=>{const s=new Intl.DateTimeFormat(t,{year:"numeric",day:"numeric",month:"short",hour:"numeric",hourCycle:"h23",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZoneName:"short",timeZone:e});return o=>{const i=o[1]-o[0],r=i<te([1,"days"]),c=i<te([1,"minutes"]),u=i<te([1,"seconds"]);return o.map(l=>({value:l,label:s.formatToParts(new Date(l))})).map((l,p,h)=>{const a=h[p-1],v=p===0||K(l.label,a.label,"year"),d=p===0||K(l.label,a.label,"day"),y=p===0||K(l.label,a.label,"month"),f=p===0||K(l.label,a.label,"hour"),m=p===0||K(l.label,a.label,"timeZoneName"),w=p===0||K(l.label,a.label,"minute"),T=p===0||K(l.label,a.label,"second"),S=p===0||K(l.label,a.label,"fractionalSecond"),x=[];if(r&&(f||w||m||T||S)){const b=l.label.find(E=>E.type==="hour")?.value,C=l.label.find(E=>E.type==="minute")?.value,R=l.label.find(E=>E.type==="timeZoneName")?.value;let P="";if(c){const E=l.label.find(j=>j.type==="second")?.value,A=l.label.find(j=>j.type==="fractionalSecond")?.value;P=`:${E}`+(u?`.${A}`:"")}x.push(`${b}:${C}${P}`+(n&&m?` ${R}`:""))}return(d||y)&&x.push([l.label.find(b=>b.type==="month")?.value,d&&l.label.find(b=>b.type==="day")?.value].filter(Boolean).join(" ")),v&&x.push(l.label.find(b=>b.type==="year")?.value),{value:l.value,label:x.filter(b=>b).join(`
4
- `)}})}};exports.AreaPlot=nt;exports.AxisOverlay=pt;exports.BarPlot=et;exports.CANPLOT_LAYER=de;exports.CanPlot=$e;exports.ChartAreaInteractions=ut;exports.Crosshair=dt;exports.FrameDrawer=me;exports.LinePlot=Ge;exports.ScatterPlot=Ze;exports.SelectBox=mt;exports.SparklinePlot=ot;exports.TooltipsX=ht;exports.XTicks=rt;exports.YTicks=at;exports.applyStyles=D;exports.clamp=W;exports.clampXPosToChartArea=z;exports.clampYPosToChartArea=N;exports.deepEqual=X;exports.defaultNumericalTicksFormatter=De;exports.findClosestIndex=Ke;exports.getScale=F;exports.makeLinearTicks=gt;exports.makeTimeTickFormat=Ie;exports.makeTimeTicks=kt;exports.posToVal=_;exports.pxToValDistance=Pe;exports.sum=Oe;exports.useDrawEffect=Y;exports.useFrameState=pe;exports.useInteractionsEvent=oe;exports.valFits=ne;exports.valToPos=V;exports.valToPxDistance=se;
1
+ "use strict";var _e=Object.defineProperty;var Fe=(e,t,n)=>t in e?_e(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var O=(e,t,n)=>Fe(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("react/jsx-runtime"),g=require("react"),W=(e,t,n)=>Math.min(Math.max(e,t),n),Oe=e=>e.reduce((t,n)=>t+(n??0),0),Ke=(e,t)=>{let n=0;for(let s=0;s<e.length;s++)Math.abs(e[s]-t)<Math.abs(e[n]-t)&&(n=s);return n},Pe=(e,t,n,s)=>{const o=_(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,c=(o.origin==="x"?i.width:i.height)/(o.max-o.min);return t/c},_=(e,t)=>e.scales.find(n=>n.id===t)??null,D=(e,t)=>{const n=window.devicePixelRatio||1;e.lineCap=t?.lineCap??"butt",e.lineDashOffset=n*(t?.lineDashOffset??0),e.lineJoin=t?.lineJoin??"miter",e.lineWidth=n*(t?.lineWidth??1),e.miterLimit=n*(t?.miterLimit??10),e.strokeStyle=t?.strokeStyle??"black",e.fillStyle=t?.fillStyle??e.strokeStyle,e.font=t?.font??`${10*n}px sans-serif`,e.textAlign=t?.textAlign??"start",e.direction=t?.direction??"inherit",e.textBaseline=t?.textBaseline??"alphabetic",e.fontKerning=t?.fontKerning??"auto"},se=(e,t,n,s)=>{const o=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,i=_(e,n);if(!i)return null;const c=(i.origin==="x"?o.width:o.height)/(i.max-i.min);return t*c},V=(e,t,n,s)=>{const o=_(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,c=se(e,t-o.min,n,s);return c===null?null:o.origin==="x"?W(i.x+c,i.x-10*i.width,i.x+11*i.width):W(i.y+i.height-c,i.y-10*i.height,i.y+11*i.height)},z=(e,t,n)=>{if(t===null)return null;const s=n==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS;return W(t,s.x,s.x+s.width)},N=(e,t,n)=>{if(t===null)return null;const s=n==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS;return W(t,s.y,s.y+s.height)},ne=(e,t,n)=>{if(t===null)return!1;const s=_(e,n);return s?t>=s.min&&t<=s.max:!1},X=(e,t,n,s)=>{const o=_(e,n);if(!o)return null;const i=s==="canvas"?e.chartAreaCanvasPX:e.chartAreaCSS,c=o.origin==="x"?(t-i.x)/i.width:(i.height-t+i.y)/i.height;return o.min+c*(o.max-o.min)},F=(e,t)=>{if(e===t)return!0;if(e==null||t==null||typeof e!=typeof t||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;o++)if(!F(e[o],t[o]))return!1;return!0}const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const o of n)if(!Object.prototype.hasOwnProperty.call(t,o)||!F(e[o],t[o]))return!1;return!0},Ye=e=>{const{ctx:t,scales:n}=e;for(const s of n){if(!s.axis)continue;t.save(),D(t,{strokeStyle:"black",fillStyle:"black",lineWidth:1,...s.axis.style});const o=s.axis.canvasRect;if(s.origin==="x"){if(s.axis.position==="bottom")t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x+o.width,o.y),t.stroke();else if(s.axis.position==="top"){const i=o.y+o.height;t.beginPath(),t.moveTo(o.x,i),t.lineTo(o.x+o.width,i),t.stroke()}}else if(s.axis.position==="left"){const i=o.x+o.width;t.beginPath(),t.moveTo(i,o.y),t.lineTo(i,o.y+o.height),t.stroke()}else s.axis.position==="right"&&(t.beginPath(),t.moveTo(o.x,o.y),t.lineTo(o.x,o.y+o.height),t.stroke());t.restore()}};function je(e){return t=>{for(const n of e)fe(n,t)}}function Be(e){return t=>{const n=[];for(const s of e){const o=fe(s,t),i=typeof o=="function";n.push(i?o:()=>fe(s,null))}return()=>{for(const s of n)s()}}}function fe(e,t){if(typeof e=="function")return e(t);e&&(e.current=t)}var ze=parseInt(g.version.split(".")[0],10)>=19?Be:je;const Ee=g.createContext({listeners:[],subscribe:()=>()=>{},notifyListeners:()=>{}}),Ne=()=>{const e=[];return{listeners:e,subscribe:(s,o)=>(e.push([o,s]),e.sort((i,c)=>i[0]-c[0]),()=>{const i=e.findIndex(([,c])=>c===s);i!==-1&&e.splice(i,1)}),notifyListeners:()=>{for(const[,s]of e)s()}}},he=g.createContext(null),Me=g.createContext(()=>{}),de={TOP:400,MIDDLE:300,BOTTOM:200,BACKGROUND:100};class me{constructor(){O(this,"_frame",null);O(this,"clampXPosToChartArea",(t,n="canvas")=>z(this.frame,t,n));O(this,"clampYPosToChartArea",(t,n="canvas")=>N(this.frame,t,n));O(this,"valToPos",(t,n,s="canvas")=>V(this.frame,t,n,s));O(this,"valToPxDistance",(t,n,s="canvas")=>se(this.frame,t,n,s));O(this,"valFits",(t,n)=>ne(this.frame,t,n));O(this,"getScale",t=>_(this.frame,t))}_updateFrame(t){this._frame=t}get frame(){if(!this._frame)throw new Error("Frame not set in FrameDrawer");return this._frame}get ctx(){return this.frame.ctx}}const $e=g.forwardRef(({configuration:e,children:t,style:n,...s},o)=>{const i=g.useRef(null),c=g.useRef(null),r=He(c),[u,l]=g.useState(null),y=g.useMemo(()=>qe(e,r,u),[e,r,u]);g.useLayoutEffect(()=>{l(i.current?.getContext("2d")||null)},[i]);const d=window.devicePixelRatio||1;return k.jsxs("div",{ref:ze([o,c]),style:{position:"relative",overflow:"hidden",...n},"data-canplotroot":!0,...s,children:[k.jsx("canvas",{ref:i,width:r.width*d,height:r.height*d,style:{inset:0,position:"absolute",width:`${r.width}px`,height:`${r.height}px`}}),y&&k.jsx(Ve,{frame:y,children:t})]})}),Ve=({frame:e,children:t})=>{const n=g.useMemo(Ne,[]),[s,o]=g.useState(0);g.useLayoutEffect(()=>{e?.ctx.clearRect(0,0,e.ctx.canvas.width,e.ctx.canvas.height)},[e,s]);const i=g.useRef(null);i.current=e,g.useLayoutEffect(()=>{n.subscribe(()=>{i.current&&Ye(i.current)},de.BOTTOM)},[n]),g.useLayoutEffect(()=>{let r=null;return r=window.requestAnimationFrame(()=>{r=null,n.notifyListeners()}),()=>{r&&cancelAnimationFrame(r)}},[s,e,n]);const c=g.useCallback(()=>{o(r=>r+1)},[o]);return k.jsx(Ee.Provider,{value:n,children:k.jsx(Me.Provider,{value:c,children:k.jsx(he.Provider,{value:e,children:t})})})},He=e=>{const[t,n]=g.useState({width:0,height:0}),[s]=g.useState(()=>new ResizeObserver(o=>{for(const i of o){const c=Math.round(i.contentRect.width),r=Math.round(i.contentRect.height);n(u=>u.width!==c||u.height!==r?{...u,width:c,height:r}:u)}}));return g.useLayoutEffect(()=>{if(!e.current)return;const o=e.current.clientWidth,i=e.current.clientHeight;return n(c=>c.width!==o||c.height!==i?{...c,width:o,height:i}:c),s.observe(e.current,{box:"border-box"}),()=>s.disconnect()},[s,e]),t},qe=(e,t,n)=>{if(!n)return null;const s=window.devicePixelRatio||1;if(t.width===0||t.height===0)return null;const o={x:e.padding.left,y:e.padding.top,width:t.width-e.padding.left-e.padding.right,height:t.height-e.padding.top-e.padding.bottom};for(const a of e.scales)a.axis&&(a.origin==="x"?(a.axis.position==="bottom"||a.axis.position==="top")&&(o.height=Math.max(0,o.height-a.axis.size),a.axis.position==="top"&&(o.y+=a.axis.size)):(a.axis.position==="left"||a.axis.position==="right")&&(o.width=Math.max(0,o.width-a.axis.size),a.axis.position==="left"&&(o.x+=a.axis.size)));const i={x:o.x*s,y:o.y*s,width:o.width*s,height:o.height*s},c=[];let r=e.padding.left*s,u=t.width*s-e.padding.right*s,l=t.height*s-e.padding.bottom*s,y=e.padding.top*s;for(const a of e.scales){if(!a.axis){c.push({...a,axis:null});continue}let v;if(a.origin==="x")switch(a.axis.position){case"bottom":l-=a.axis.size*s,v={x:o.x,y:l/s,width:o.width,height:a.axis.size};break;case"top":y+=a.axis.size*s,v={x:o.x,y:y/s-a.axis.size,width:o.width,height:a.axis.size};break;case"left":case"right":throw new Error("Invalid axis position for x origin")}else switch(a.axis.position){case"left":r+=a.axis.size*s,v={x:r/s-a.axis.size,y:o.y,width:a.axis.size,height:o.height};break;case"right":u-=a.axis.size*s,v={x:u/s,y:o.y,width:a.axis.size,height:o.height};break;case"top":case"bottom":throw new Error("Invalid axis position for y origin")}const f={x:v.x*s,y:v.y*s,width:v.width*s,height:v.height*s};c.push({...a,axis:{...a.axis,cssRect:v,canvasRect:f}})}return{ctx:n,dpr:s,padding:e.padding,scales:c,chartAreaCSS:o,chartAreaCanvasPX:i}},Y=(e,t,n)=>{const s=g.useContext(he),o=g.useContext(Me),i=g.useContext(Ee);if(!s||!o)throw new Error("useFrame must be used within a CanPlot component");const[c]=g.useState(()=>new me);c._updateFrame(s);const r=g.useRef(c);r.current=c;const u=g.useRef(t);u.current=t,g.useLayoutEffect(()=>{const l=i.subscribe(()=>{u.current(c)},typeof e=="number"?e:de[e]);return()=>{l()}},[i,e,c]),g.useLayoutEffect(()=>{o()},[o,...n]),g.useEffect(()=>()=>{o()},[o])},pe=()=>{const e=g.useContext(he);if(!e)throw new Error("useFrame must be used within a CanPlot component");return g.useMemo(()=>{const t=new me;return t._updateFrame(e),t},[e])},We=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,style:o,globalAlpha:i,xGapWidth:c})=>(Y(e,({ctx:r,clampXPosToChartArea:u,clampYPosToChartArea:l,valToPos:y})=>{r.save(),r.beginPath(),D(r,o);const d=r.getLineDash();o?.lineDash&&r.setLineDash(o.lineDash),i!==void 0&&(r.globalAlpha=i);let a=null;for(const v of t){const f=u(y(v.x,n,"canvas")),p=l(y(v.y,s,"canvas"));f===null||p===null||(a!==null&&c!==void 0&&f-a>c?r.moveTo(f,p):r.lineTo(f,p),a=f)}r.stroke(),d&&r.setLineDash(d),r.restore()},[t,n,s,o,i,c]),null),Ge=g.memo(We,F),Je=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,xStrategy:o="clip",yStrategy:i="clip",radius:c=5,style:r,globalAlpha:u})=>(Y(e,({ctx:l,valToPos:y,valFits:d,clampXPosToChartArea:a,clampYPosToChartArea:v})=>{l.save(),D(l,r),u!==void 0&&(l.globalAlpha=u);const f=[];for(const p of t){let h=null,m=null;const w=y(p.x,n);if(w===null)continue;if(o==="clip"){if(!d(p.x,n))continue;h=w}else h=a(w,"canvas");const T=y(p.y,s);if(T!==null){if(i==="clip"){if(!d(p.y,s))continue;m=T}else m=v(T,"canvas");h===null||m===null||f.push({x:h,y:m})}}if(r?.fillStyle)for(const p of f)l.beginPath(),l.arc(p.x,p.y,c,0,Math.PI*2),l.fill();if(r?.strokeStyle){l.beginPath();for(const p of f)l.moveTo(p.x+c,p.y),l.arc(p.x,p.y,c,0,Math.PI*2);l.stroke()}l.restore()},[t,n,s,c,r,u]),null),Ze=g.memo(Je,F),Qe=({data:e,xScaleId:t,yScaleId:n,style:s,barWidth:o,xPositionOffset:i,globalAlpha:c,radius:r,layer:u="MIDDLE"})=>(Y(u,({ctx:l,valToPxDistance:y,valToPos:d,clampXPosToChartArea:a,clampYPosToChartArea:v})=>{if(e.length===0)return;const f=v(d(0,n,"canvas"),"canvas");if(f===null)return;const p=y(o,t,"canvas")??0,h=[];for(const m of e){const w=d(m.x,t,"canvas");if(w===null)continue;const T=w-p/2+i*p,S=v(d(m.y,n,"canvas"),"canvas");if(S===null)continue;const x=f-S,b=a(T,"canvas"),C=a(T+p,"canvas")-b;h.push({x:b,y:S,width:C,height:x})}if(l.save(),D(l,s),c!==void 0&&(l.globalAlpha=c),s?.fillStyle)for(const m of h)l.beginPath(),r?l.roundRect(m.x,m.y,m.width,m.height,r):l.rect(m.x,m.y,m.width,m.height),l.fill();if(s?.strokeStyle){l.beginPath();for(const m of h)r?l.roundRect(m.x,m.y,m.width,m.height,r):l.rect(m.x,m.y,m.width,m.height);l.stroke()}l.restore()},[e,t,n,s,o,i,r,c]),null),et=g.memo(Qe,F),tt=({layer:e="MIDDLE",data:t,xScaleId:n,yScaleId:s,style:o})=>(Y(e,({ctx:i,clampXPosToChartArea:c,clampYPosToChartArea:r,valToPos:u})=>{const l=[];for(const d of t){const a=c(u(d.x,n));if(a===null)continue;const v=r(u(d.y[0],s));if(v===null)continue;const f=r(u(d.y[1],s));f!==null&&(l.push({x:a,y:v}),l.unshift({x:a,y:f}))}const y=l[0];if(y){i.save(),i.beginPath(),D(i,o),i.moveTo(y.x,y.y);for(const d of l)i.lineTo(d.x,d.y);i.closePath(),i.fill(),i.restore()}},[t,n,s,o]),null),nt=g.memo(tt,F),st=({layer:e="MIDDLE",data:t,stroked:n,xScaleId:s,yScaleId:o,style:i})=>(Y(e,({ctx:c,clampXPosToChartArea:r,clampYPosToChartArea:u,valToPos:l})=>{const y=[];for(const f of t){const p=r(l(f.x,s)),h=u(l(f.y,o));p===null||h===null||y.push({x:p,y:h})}const d=y.at(0),a=y.at(-1);if(!d||!a)return;const v=u(l(0,o));if(v!==null){c.save(),c.beginPath(),D(c,i),c.moveTo(d.x,v);for(const f of y)c.lineTo(f.x,f.y);if(c.lineTo(a.x,v),c.closePath(),c.fill(),n){c.beginPath(),c.moveTo(d.x,d.y);for(const f of y)c.lineTo(f.x,f.y);c.stroke()}c.restore()}},[t,n,s,o,i]),null),ot=g.memo(st,F),it=({layer:e="BOTTOM",scaleId:t,tickStyle:n,labelStyle:s,labelGap:o,tickSize:i,ticks:c})=>(Y(e,({ctx:r,valToPos:u,getScale:l,frame:y})=>{const d=l(t);if(!d||!d.axis||d.origin!=="x")return;const a=d.axis,v=a.position==="top"?a.canvasRect.y+a.canvasRect.height:a.canvasRect.y,f=window.devicePixelRatio||1,p=v,h=(i??6)*f,m=a.position==="top"?v-h:v+h,w=(o??12)*f;r.save(),r.fontKerning="auto",D(r,{...n}),r.beginPath();const T=Array.isArray(c)?c:c({...d,axis:a},y);for(const{value:S}of T){const x=u(S,t,"canvas");x!==null&&(r.moveTo(x,p),r.lineTo(x,m))}r.stroke(),r.restore(),r.save(),D(r,{textBaseline:a.position==="top"?"bottom":"top",textAlign:"center",...n,...s,font:Re(s?.font??n?.font)});for(const{value:S,label:x}of T){const b=u(S,t,"canvas");if(b===null)continue;const C=x.split(`
2
+ `);for(let R=0;R<C.length;R++)r.fillText(C[R],b,m+f*2+R*w)}r.restore()},[c,t,n,s]),null),rt=g.memo(it,F),ct=({layer:e="BOTTOM",scaleId:t,tickStyle:n,labelStyle:s,labelGap:o,tickSize:i,ticks:c})=>(Y(e,({ctx:r,valToPos:u,getScale:l,frame:y})=>{const d=l(t);if(!d||!d.axis||d.origin!=="y")return;const a=d.axis,v=a.position==="left"?a.canvasRect.x+a.canvasRect.width:a.canvasRect.x,f=v,p=i??6,h=a.position==="left"?v-p:v+p,m=o??12,w=Array.isArray(c)?c:c({...d,axis:a},y);r.save(),r.fontKerning="auto",D(r,{...n}),r.beginPath();for(const{value:T}of w){const S=u(T,t,"canvas");S!==null&&(r.moveTo(f,S),r.lineTo(h,S))}r.stroke(),r.restore(),r.save(),D(r,{textBaseline:"middle",textAlign:a.position==="left"?"right":"left",...n,...s,font:Re(s?.font??n?.font)});for(const{value:T,label:S}of w){const x=u(T,t,"canvas");if(x===null)continue;const b=S.split(`
3
+ `);for(let C=0;C<b.length;C++)r.fillText(` ${b[C]} `,h,x+C*m)}r.restore()},[c,t,n,s]),null),at=g.memo(ct,F),Re=e=>{if(e)try{return e.replace(/(\d+)px/,(t,n)=>`${parseInt(n)*window.devicePixelRatio||1}px`)}catch{}return e},L=()=>{const e=[];return{addEventListener:(t,n)=>(e.push({syncKey:t,callback:n}),()=>{const s=e.findIndex(o=>o.callback===n);s!==-1&&e.splice(s,1)}),dispatchEvent:(t,n)=>{for(const s of e)s.syncKey===t&&s.callback(t,n)}}},M={dblclick:L(),click:L(),contextmenu:L(),move:L(),mousedown:L(),mouseup:L(),spanselect:L(),documentmouseup:L(),pressandwheel:L(),sync_move:L()},I=(e,t,n)=>{const s=g.useRef(n);s.current=n,g.useEffect(()=>M[e].addEventListener(t,(i,c)=>{s.current(c,i)}),[t,e,s])},ye=g.createContext(""),oe=(e,t)=>{const n=g.useContext(ye);return I(e,n,t)},lt=(e,t,n,s,o)=>{if(!t)return;const i=s??n.scales.find(d=>d.origin==="x")?.id,c=o??n.scales.find(d=>d.origin==="y")?.id,r=e.clientX-t.left,u=i?{scaleId:i,value:X(n,r,i,"css")}:null,l=e.clientY-t.top,y=c?{scaleId:c,value:X(n,l,c,"css")}:null;return{pointerSyncPosition:{x:u,y},cssX:r,cssY:l}},B=(e,t)=>{const{x:n,y:s}=e,o=n&&t.scales.some(c=>c.id===n.scaleId)?V(t,n.value,n.scaleId,"css"):null,i=s&&t.scales.some(c=>c.id===s.scaleId)?V(t,s.value,s.scaleId,"css"):null;return{cssX:o,cssY:i,scaled:Object.fromEntries(t.scales.flatMap(c=>{const r=c.origin==="y"?i:o;return r===null?[]:[[c.id,X(t,r,c.id,"css")]]}))}},Se=(e,t,n)=>{const s=V(n,t.from,t.scaleId,"css"),o=V(n,t.to,t.scaleId,"css");if(s===null||o===null)return null;const i=n.scales.flatMap(c=>{if(c.origin!==e)return[];const r=X(n,s,c.id,"css"),u=X(n,o,c.id,"css");return r===null||u===null?[]:[{scaleId:c.id,from:r,to:u}]});return{fromCSS:s,toCSS:o,scaled:i}},ut=({id:e,onClick:t,onDblClick:n,onMouseMove:s,onMouseDown:o,onMouseUp:i,onDocumentMouseUp:c,onSpanSelect:r,onContextMenu:u,className:l,style:y,sync:d,innerChildren:a,children:v})=>{const f=g.useId();return I("dblclick",f,p=>{n?.(p)}),I("click",f,p=>{t?.(p)}),I("move",f,p=>{s?.(p)}),I("mousedown",f,p=>{o?.(p)}),I("mouseup",f,p=>{i?.(p)}),I("documentmouseup",f,p=>{c?.(p)}),I("spanselect",f,p=>{r?.(p)}),I("contextmenu",f,p=>{u?.(p)}),k.jsxs(ye.Provider,{value:f,children:[k.jsx(ft,{id:e,className:l,style:y,sync:d,children:a}),v]})},ft=({id:e,className:t,style:n,sync:s,children:o})=>{const i=g.useRef(null),c=pe().frame,r=g.useRef(c);r.current=c;const u=g.useContext(ye),l=s?.key||u,y=g.useRef(null),d=g.useRef(null),a=g.useRef(null),v=()=>{const h=i.current?.parentElement;if(h){if(h.dataset.canplotroot===void 0)throw new Error("ChartAreaInteractions must be used within a CanPlot component");return h.getBoundingClientRect()}},f=(h,m)=>{const w=lt(h,v(),r.current,s?.xViaScaleId,s?.yViaScaleId);w&&m(w.pointerSyncPosition,{cssX:w.cssX,cssY:w.cssY},{ctrlKey:h.ctrlKey,altKey:h.altKey,shiftKey:h.shiftKey,metaKey:h.metaKey})},p=g.useRef(f);return p.current=f,g.useEffect(()=>{const h=x=>{const b=d.current;b&&M.spanselect.dispatchEvent(u,{...b,completed:!0}),M.documentmouseup.dispatchEvent(u,{frame:r.current,keys:{ctrlKey:x.ctrlKey,altKey:x.altKey,shiftKey:x.shiftKey,metaKey:x.metaKey}})},m=x=>{const b={ctrlKey:x.ctrlKey,altKey:x.altKey,shiftKey:x.shiftKey,metaKey:x.metaKey},C=a.current;if(C&&Object.entries(b).some(([P,E])=>C.keys[P]!==E)){const P={...C,keys:b};a.current=P,M.sync_move.dispatchEvent(l,P)}const R=d.current;if(R&&Object.entries(b).some(([P,E])=>R.keys[P]!==E)){x.stopPropagation(),x.preventDefault();const P={...R,keys:b};d.current=P,M.spanselect.dispatchEvent(u,P)}},w=x=>{p.current(x,(b,{cssX:C,cssY:R},P)=>{const E=y.current;if(!E||!b.x||!b.y)return;const A=r.current,j=E.xRangeCss.start,re=C,ce=E.yRangeCss.start,ae=R,G=_(A,b.x.scaleId);if(!G)return;const J=_(A,b.y.scaleId);if(!J)return;y.current={xRangeCss:{start:j,end:re},yRangeCss:{start:ce,end:ae}};let H="below_threshold";const le=Math.abs(ce-ae),ue=Math.abs(j-re);le<10&&ue<10?H="below_threshold":le>30&&ue>30?H="box":le>ue?H="y":H="x";const ge=X(A,z(r.current,j,"css"),G.id,"css");if(ge===null)return;const we=X(A,z(r.current,re,"css"),G.id,"css");if(we===null)return;const xe=X(A,N(r.current,ce,"css"),J.id,"css");if(xe===null)return;const Te=X(A,N(r.current,ae,"css"),J.id,"css");if(Te===null)return;const Z=Se("x",{scaleId:G.id,from:ge,to:we},r.current),Q=Se("y",{scaleId:J.id,from:xe,to:Te},r.current),Ue=Z?.scaled,Xe=Q?.scaled,be={mode:H,frame:r.current,completed:!1,x:{css:Z?{from:Z.fromCSS,to:Z.toCSS}:void 0,scaled:Ue??[]},y:{css:Q?{from:Q.fromCSS,to:Q.toCSS}:void 0,scaled:Xe??[]},keys:P};d.current=be,M.spanselect.dispatchEvent(u,be)})},T=x=>{p.current(x,(b,C,R)=>{const P=B(b,r.current);if(!P)return;if(Object.values(R).some(A=>A)){x.preventDefault();const A=Math.abs(x.deltaY)>Math.abs(x.deltaX)?x.deltaY:x.deltaX;M.pressandwheel.dispatchEvent(u,{pointer:P,frame:r.current,keys:R,deltaX:x.deltaX,deltaY:x.deltaY,deltaAbs:A})}})};document.addEventListener("mouseup",h),document.addEventListener("keydown",m),document.addEventListener("keyup",m),document.addEventListener("mousemove",w);const S=i.current;return S?.addEventListener("wheel",T,{passive:!1}),()=>{document.removeEventListener("mouseup",h),document.removeEventListener("keydown",m),document.removeEventListener("keyup",m),document.removeEventListener("mousemove",w),S?.removeEventListener("wheel",T)}},[r,u,l,p]),I("sync_move",l,h=>{const m=h.positions?B(h.positions,r.current):null;a.current=h,M.move.dispatchEvent(u,{frame:r.current,pointer:m??null,keys:h.keys,source:h.originInteractionsId===u?"own":"sync"})}),k.jsx("div",{ref:i,id:e,className:t,style:{position:"absolute",left:c.chartAreaCSS.x,top:c.chartAreaCSS.y,width:c.chartAreaCSS.width,height:c.chartAreaCSS.height,zIndex:25,...n},onDragStart:h=>{h.preventDefault()},onClick:h=>{f(h,(m,w,T)=>{const S=B(m,r.current);S&&M.click.dispatchEvent(u,{pointer:S,frame:r.current,keys:T})})},onMouseLeave:h=>{f(h,(m,w,T)=>{M.sync_move.dispatchEvent(l,{positions:null,keys:T,originInteractionsId:u})})},onMouseMove:h=>{f(h,(m,w,T)=>{M.sync_move.dispatchEvent(l,{positions:m,keys:T,originInteractionsId:u})})},onMouseDown:h=>{f(h,(m,{cssX:w,cssY:T},S)=>{const x=B(m,r.current);x&&(M.mousedown.dispatchEvent(u,{pointer:x,frame:r.current,keys:S}),y.current={xRangeCss:{start:w,end:w},yRangeCss:{start:T,end:T}})})},onMouseUp:h=>{f(h,(m,w,T)=>{const S=B(m,r.current);if(!S)return;M.mouseup.dispatchEvent(u,{frame:r.current,pointer:S,keys:T});const x=d.current;d.current=null;const b=y.current;if(y.current=null,b&&x){const C={...x,keys:T,completed:!0};d.current=null,M.spanselect.dispatchEvent(u,C)}})},onContextMenu:h=>{h.preventDefault(),f(h,(m,w,T)=>{const S=B(m,r.current);S&&M.contextmenu.dispatchEvent(u,{frame:r.current,pointer:S,keys:T})})},onDoubleClick:h=>{f(h,(m,w,T)=>{const S=B(m,r.current);S&&M.dblclick.dispatchEvent(u,{frame:r.current,pointer:S,keys:T})})},children:o})},ht=({data:e,renderTooltip:t,xScaleId:n})=>{const[s,o]=g.useState(null);oe("move",c=>{o(c)});const i=g.useMemo(()=>{if(!s)return null;const{frame:c,pointer:r}=s,u=r?.scaled[n];if(u===void 0||!_(c,n))return null;const y=[];let d=u;for(const a of e){let v=null,f=1/0;for(const[m,w]of a.points.entries()){if(!ne(c,w.x,n)||!ne(c,w.y,a.yScaleId))continue;const T=Math.abs(w.x-u);T<f&&(f=T,v=m)}const p=a.points[v??-1],h=se(c,f,n,"css");if(!p||h===null||h>30){y.push({seriesId:a.seriesId,y:null});continue}d=p.x,y.push({seriesId:a.seriesId,y:p.y})}return{frame:c,x:d,points:y}},[e,s,n]);return t(i)},dt=({makeXStyle:e,makeXClassName:t,makeYStyle:n,makeYClassName:s})=>{const[o,i]=g.useState(null);if(oe("move",a=>{i(a)}),!o)return null;const{frame:c,pointer:r}=o,u=r?.cssX??null,l=r?.cssY??null,y=u?z(c,u,"css"):0,d=l?N(c,l,"css"):0;return k.jsxs(k.Fragment,{children:[k.jsx("div",{"data-show":!!r,className:t?.(o),style:{position:"absolute",left:0,visibility:u===null?"hidden":"visible",top:c.chartAreaCSS.y,height:c.chartAreaCSS.height,borderColor:"red",borderLeftWidth:"1px",borderLeftStyle:"solid",pointerEvents:"none",opacity:r?1:0,transform:`translateX(${y}px)`,...e?.(o)}}),k.jsx("div",{className:s?.(o),"data-show":!!r,style:{position:"absolute",visibility:l===null?"hidden":"visible",top:0,height:0,borderTop:"solid 1px red",left:c.chartAreaCSS.x,width:c.chartAreaCSS.width,pointerEvents:"none",opacity:r?1:0,transform:`translateY(${d}px)`,...n?.(o)}})]})},mt=({makeClassName:e,makeStyle:t})=>{const[n,s]=g.useState(null);oe("spanselect",i=>{s(i.mode==="below_threshold"||i.completed?null:i)});const o=g.useMemo(()=>{if(!n||n.mode==="below_threshold")return null;const i=n.mode==="y"?-1/0:n.x.css?.from??-1/0,c=n.mode==="y"?1/0:n.x.css?.to??1/0,r=n.mode==="x"?-1/0:n.y.css?.from??-1/0,u=n.mode==="x"?1/0:n.y.css?.to??1/0,l=z(n.frame,i,"css"),y=z(n.frame,c,"css"),d=N(n.frame,r,"css"),a=N(n.frame,u,"css"),v=Math.min(l,y),f=Math.min(d,a),p=Math.abs(y-l),h=Math.abs(a-d);return{leftPx:v,topPx:f,widthPx:p,heightPx:h}},[n]);return k.jsx("div",{className:n?e?.(n):void 0,style:{position:"absolute",visibility:n?"visible":"hidden",left:`${o?.leftPx??0}px`,top:`${o?.topPx??0}px`,width:`${o?.widthPx??0}px`,height:`${o?.heightPx??0}px`,pointerEvents:"none",...n?t?.(n):void 0}})},pt=({style:e,children:t,scaleId:n,...s})=>{const o=pe().getScale(n)?.axis;return o?k.jsx("div",{style:{position:"absolute",backgroundColor:"#0000ff11",left:o.cssRect.x,top:o.cssRect.y,height:o.cssRect.height,width:o.cssRect.width,...e},...s,children:t}):null},ke=60,yt=30,Ae="UTC",vt="en-GB",gt=({space:e,formatter:t,acceptableIncrements:n}={})=>(s,o)=>{const{min:i,max:c}=s,r=[],u=window.devicePixelRatio||1,l=(e??(s.origin==="x"?ke:yt))*u,y=Pe(o,l,s.id,"canvas");if(y===null)return[];const d=n??ee,a=d.find(f=>f>y)??d.at(-1)??1;let v=i;if(Math.abs(v%a)>Number.EPSILON){const f=(a-v%a)%a;v+=f}for(;v<=c&&r.length<1e3;)r.push(v),v+=a;return(t??De)(r)},De=e=>{const t=Math.max(0,Math.ceil(-Math.log10(e[1]-e[0])));return e.map(n=>({value:n,label:n.toFixed(t)}))},ee=[];for(let e=-12;e<=12;e++)ee.push(1*10**e),ee.push(2*10**e),ee.push(5*10**e);const wt=1,Le=1e3*wt,ve=60*Le,q=60*ve,ie=24*q,xt=30*ie,Tt=365*ie,bt=[[1,"milliseconds"],[2,"milliseconds"],[5,"milliseconds"],[10,"milliseconds"],[20,"milliseconds"],[50,"milliseconds"],[100,"milliseconds"],[200,"milliseconds"],[500,"milliseconds"],[1,"seconds"],[5,"seconds"],[10,"seconds"],[15,"seconds"],[30,"seconds"],[1,"minutes"],[5,"minutes"],[10,"minutes"],[15,"minutes"],[30,"minutes"],[1,"hours"],[2,"hours"],[3,"hours"],[4,"hours"],[6,"hours"],[8,"hours"],[12,"hours"],[1,"days"],[3,"days"],[5,"days"],[7,"days"],[10,"days"],[15,"days"],[1,"months"],[2,"months"],[3,"months"],[4,"months"],[6,"months"],[1,"years"],[2,"years"],[5,"years"],[10,"years"],[25,"years"],[50,"years"],[100,"years"]],te=e=>{const[t,n]=e;switch(n){case"milliseconds":return t;case"seconds":return t*Le;case"minutes":return t*ve;case"hours":return t*q;case"days":return t*ie;case"months":return t*xt;case"years":return t*Tt}},St=(e,t)=>{const n=new Date(e);return n.setUTCMilliseconds(n.getUTCMilliseconds()+t),n.getTime()},Ct=(e,t)=>{const n=new Date(e);return n.setUTCSeconds(n.getUTCSeconds()+t),n.getTime()},Pt=(e,t)=>{const n=new Date(e);return n.setUTCMinutes(n.getUTCMinutes()+t),n.getTime()},Et=(e,t)=>{const n=new Date(e);return n.setUTCHours(n.getUTCHours()+t),n.getTime()},Mt=(e,t)=>{const n=new Date(e);return n.setUTCDate(n.getUTCDate()+t),n.getTime()},Ce=(e,t)=>{const n=new Date(e);return n.setUTCMonth(n.getUTCMonth()+t),n.getTime()},U=(e,t)=>{const[n,s]=t;switch(s){case"milliseconds":return St(e,n);case"seconds":return Ct(e,n);case"minutes":return Pt(e,n);case"hours":return Et(e,n);case"days":return Mt(e,n);case"months":return Ce(e,n);case"years":return Ce(e,n*12)}};function $(e,t){const n=new Date(e),s=new Date(n.toLocaleString("en-US",{timeZone:t})),o=new Date(n.toLocaleString("en-US",{timeZone:"UTC"}));return(s.getTime()-o.getTime())/(3600*1e3)}const Rt=(e,t,n="UTC")=>{const[s,o]=t;let i=new Date(e);const c=()=>{i.setUTCHours(-$(i,n),0,0,0)};switch(o){case"milliseconds":i.setUTCMilliseconds(Math.ceil(i.getUTCMilliseconds()/s)*s);break;case"seconds":i.setUTCSeconds(Math.ceil(i.getUTCSeconds()/s)*s,0);break;case"minutes":i.setUTCMinutes(Math.ceil(i.getTime()%q/ve/s)*s,0,0);break;case"hours":{const r=$(i,n);i.setUTCHours(Math.ceil((i.getTime()+r*q)%ie/q/s)*s-r,0,0,0);break}case"days":{for(c(),i.setUTCDate(1);i.getTime()<e;)i=new Date(U(i,[s,o]));break}case"months":case"years":o==="months"?i.setUTCDate(1):o==="years"&&i.setUTCMonth(0,1),c(),i.getTime()<e&&(i=new Date(U(i,[1,o])));break}return i.getTime()},kt=({timeZone:e=Ae,space:t=ke,formatter:n,locale:s,showTimezone:o}={})=>(i,c)=>{const{min:r,max:u}=i;if(!Number.isFinite(r)||!Number.isFinite(u))return[];const l=Math.floor(c.chartAreaCanvasPX.width/t)+1,d=(u-r)/l,[a,v]=bt.find(w=>te(w)>=d)??[1,"milliseconds"];if(!a||!v)return[];const f=Rt(r,[a,v],e),p=$(f,e),h=[f];let m;for(;;){if(h.length>100)return[];switch(v){case"milliseconds":case"seconds":case"minutes":case"hours":{const w=U(f,[h.length*a,v]);m=U(w,[p-$(w,e),"hours"]);break}case"days":{const w=U(f,[h.length*a,v]);m=U(w,[p-$(w,e),"hours"]);break}case"months":case"years":{const w=U(U(U(f,[p,"hours"]),[h.length*a,v]),[-p,"hours"]);m=U(w,[p-$(w,e),"hours"]);break}}if(m>u)break;h[h.length-1]!==m&&h.push(m)}return(n??Ie({locale:s,showTimezone:o,timeZone:e}))(h)},K=(e,t,n)=>e.find(s=>s.type===n)?.value!==t.find(s=>s.type===n)?.value,Ie=({timeZone:e=Ae,locale:t=vt,showTimezone:n=!0})=>{const s=new Intl.DateTimeFormat(t,{year:"numeric",day:"numeric",month:"short",hour:"numeric",hourCycle:"h23",minute:"numeric",second:"numeric",fractionalSecondDigits:3,timeZoneName:"short",timeZone:e});return o=>{const i=o[1]-o[0],c=i<te([1,"days"]),r=i<te([1,"minutes"]),u=i<te([1,"seconds"]);return o.map(l=>({value:l,label:s.formatToParts(new Date(l))})).map((l,y,d)=>{const a=d[y-1],v=y===0||K(l.label,a.label,"year"),f=y===0||K(l.label,a.label,"day"),p=y===0||K(l.label,a.label,"month"),h=y===0||K(l.label,a.label,"hour"),m=y===0||K(l.label,a.label,"timeZoneName"),w=y===0||K(l.label,a.label,"minute"),T=y===0||K(l.label,a.label,"second"),S=y===0||K(l.label,a.label,"fractionalSecond"),x=[];if(c&&(h||w||m||T||S)){const b=l.label.find(E=>E.type==="hour")?.value,C=l.label.find(E=>E.type==="minute")?.value,R=l.label.find(E=>E.type==="timeZoneName")?.value;let P="";if(r){const E=l.label.find(j=>j.type==="second")?.value,A=l.label.find(j=>j.type==="fractionalSecond")?.value;P=`:${E}`+(u?`.${A}`:"")}x.push(`${b}:${C}${P}`+(n&&m?` ${R}`:""))}return(f||p)&&x.push([l.label.find(b=>b.type==="month")?.value,f&&l.label.find(b=>b.type==="day")?.value].filter(Boolean).join(" ")),v&&x.push(l.label.find(b=>b.type==="year")?.value),{value:l.value,label:x.filter(b=>b).join(`
4
+ `)}})}};exports.AreaPlot=nt;exports.AxisOverlay=pt;exports.BarPlot=et;exports.CANPLOT_LAYER=de;exports.CanPlot=$e;exports.ChartAreaInteractions=ut;exports.Crosshair=dt;exports.FrameDrawer=me;exports.LinePlot=Ge;exports.ScatterPlot=Ze;exports.SelectBox=mt;exports.SparklinePlot=ot;exports.TooltipsX=ht;exports.XTicks=rt;exports.YTicks=at;exports.applyStyles=D;exports.clamp=W;exports.clampXPosToChartArea=z;exports.clampYPosToChartArea=N;exports.deepEqual=F;exports.defaultNumericalTicksFormatter=De;exports.findClosestIndex=Ke;exports.getScale=_;exports.makeLinearTicks=gt;exports.makeTimeTickFormat=Ie;exports.makeTimeTicks=kt;exports.posToVal=X;exports.pxToValDistance=Pe;exports.sum=Oe;exports.useDrawEffect=Y;exports.useFrameState=pe;exports.useInteractionsEvent=oe;exports.valFits=ne;exports.valToPos=V;exports.valToPxDistance=se;
5
5
  //# sourceMappingURL=canplot.cjs.map