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