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