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