@canplot/react 0.3.0 → 0.4.1

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