@canplot/react 0.1.25 → 0.3.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.mjs CHANGED
@@ -1,56 +1,58 @@
1
- import { jsxs as mt, jsx as D, Fragment as Xt } from "react/jsx-runtime";
2
- import Q, { createContext as Et, useContext as tt, useRef as I, useLayoutEffect as Y, useEffect as Pt, version as Kt, forwardRef as Ot, useMemo as et, useState as V, useId as Ft } from "react";
3
- import { createStore as Rt, useStore as kt } from "zustand";
4
- const j = (n, e, t) => Math.min(Math.max(n, e), t), pe = (n) => n.reduce((e, t) => e + (t ?? 0), 0), xe = (n, e) => {
5
- let t = 0;
6
- for (let s = 0; s < n.length; s++)
7
- Math.abs(n[s] - e) < Math.abs(n[t] - e) && (t = s);
8
- return t;
9
- }, zt = (n, e, t, s) => {
10
- const { min: o, max: i, origin: r } = U(n, t), c = s === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS, u = (r === "x" ? c.width : c.height) / (i - o);
11
- return e / u;
12
- }, U = (n, e) => {
13
- const t = n.scales.find((s) => s.id === e);
14
- if (!t)
15
- throw new Error(`Scale ${e} not found`);
16
- return t;
17
- }, _ = (n, e) => {
18
- const t = window.devicePixelRatio || 1;
19
- n.lineCap = e?.lineCap ?? "butt", n.lineDashOffset = t * (e?.lineDashOffset ?? 0), n.lineJoin = e?.lineJoin ?? "miter", n.lineWidth = t * (e?.lineWidth ?? 1), n.miterLimit = t * (e?.miterLimit ?? 10), n.strokeStyle = e?.strokeStyle ?? "black", n.fillStyle = e?.fillStyle ?? n.strokeStyle, n.font = e?.font ?? `${10 * t}px sans-serif`, n.textAlign = e?.textAlign ?? "start", n.direction = e?.direction ?? "inherit", n.textBaseline = e?.textBaseline ?? "alphabetic", n.fontKerning = e?.fontKerning ?? "auto";
20
- }, pt = (n, e, t, s) => {
21
- const o = s === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS, { min: i, max: r, origin: c } = U(n, t), u = (c === "x" ? o.width : o.height) / (r - i);
22
- return e * u;
23
- }, H = (n, e, t, s) => {
24
- const { min: o, origin: i } = U(n, t), r = s === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS, c = pt(n, e - o, t, s);
25
- return i === "x" ? j(
1
+ var Xe = Object.defineProperty;
2
+ var Fe = (e, t, n) => t in e ? Xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var X = (e, t, n) => Fe(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as A, jsxs as me, Fragment as Ke } from "react/jsx-runtime";
5
+ import ne, { version as Oe, createContext as pe, useRef as k, useCallback as Ye, forwardRef as ze, useState as O, useLayoutEffect as B, useMemo as G, useContext as H, useId as Be, useEffect as Ne } from "react";
6
+ const W = (e, t, n) => Math.min(Math.max(e, t), n), wt = (e) => e.reduce((t, n) => t + (n ?? 0), 0), bt = (e, t) => {
7
+ let n = 0;
8
+ for (let s = 0; s < e.length; s++)
9
+ Math.abs(e[s] - t) < Math.abs(e[n] - t) && (n = s);
10
+ return n;
11
+ }, $e = (e, t, n, s) => {
12
+ const { min: o, max: i, origin: r } = _(e, n), c = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = (r === "x" ? c.width : c.height) / (i - o);
13
+ return t / a;
14
+ }, _ = (e, t) => {
15
+ const n = e.scales.find((s) => s.id === t);
16
+ if (!n)
17
+ throw new Error(`Scale ${t} not found`);
18
+ return n;
19
+ }, L = (e, t) => {
20
+ const n = window.devicePixelRatio || 1;
21
+ 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";
22
+ }, ye = (e, t, n, s) => {
23
+ const o = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, { min: i, max: r, origin: c } = _(e, n), a = (c === "x" ? o.width : o.height) / (r - i);
24
+ return t * a;
25
+ }, q = (e, t, n, s) => {
26
+ const { min: o, origin: i } = _(e, n), r = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, c = ye(e, t - o, n, s);
27
+ return i === "x" ? W(
26
28
  r.x + c,
27
29
  r.x - 10 * r.width,
28
30
  r.x + 11 * r.width
29
- ) : j(
31
+ ) : W(
30
32
  r.y + r.height - c,
31
33
  r.y - 10 * r.height,
32
34
  r.y + 11 * r.height
33
35
  );
34
- }, ye = (n, e, t) => {
35
- const { min: s, max: o } = U(n, t);
36
- return j(e, s, o);
37
- }, B = (n, e, t) => {
38
- const s = t === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS;
39
- return j(e, s.x, s.x + s.width);
40
- }, N = (n, e, t) => {
41
- const s = t === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS;
42
- return j(e, s.y, s.y + s.height);
43
- }, dt = (n, e, t) => {
44
- const { min: s, max: o } = U(n, t);
45
- return e >= s && e <= o;
46
- }, L = (n, e, t, s) => {
47
- const { min: o, max: i, origin: r } = U(n, t), c = s === "canvas" ? n.chartAreaCanvasPX : n.chartAreaCSS, u = r === "x" ? (e - c.x) / c.width : (c.height - e + c.y) / c.height;
48
- return o + u * (i - o);
49
- }, Yt = (n) => {
50
- const { ctx: e, scales: t } = n;
51
- for (const s of t) {
36
+ }, xt = (e, t, n) => {
37
+ const { min: s, max: o } = _(e, n);
38
+ return W(t, s, o);
39
+ }, $ = (e, t, n) => {
40
+ const s = n === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS;
41
+ return W(t, s.x, s.x + s.width);
42
+ }, V = (e, t, n) => {
43
+ const s = n === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS;
44
+ return W(t, s.y, s.y + s.height);
45
+ }, he = (e, t, n) => {
46
+ const { min: s, max: o } = _(e, n);
47
+ return t >= s && t <= o;
48
+ }, U = (e, t, n, s) => {
49
+ const { min: o, max: i, origin: r } = _(e, n), c = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, a = r === "x" ? (t - c.x) / c.width : (c.height - t + c.y) / c.height;
50
+ return o + a * (i - o);
51
+ }, Ve = (e) => {
52
+ const { ctx: t, scales: n } = e;
53
+ for (const s of n) {
52
54
  if (!s.axis) continue;
53
- e.save(), _(e, {
55
+ t.save(), L(t, {
54
56
  strokeStyle: "black",
55
57
  fillStyle: "black",
56
58
  lineWidth: 1,
@@ -59,149 +61,116 @@ const j = (n, e, t) => Math.min(Math.max(n, e), t), pe = (n) => n.reduce((e, t)
59
61
  const o = s.axis.canvasRect;
60
62
  if (s.origin === "x") {
61
63
  if (s.axis.position === "bottom")
62
- e.beginPath(), e.moveTo(o.x, o.y), e.lineTo(o.x + o.width, o.y), e.stroke();
64
+ t.beginPath(), t.moveTo(o.x, o.y), t.lineTo(o.x + o.width, o.y), t.stroke();
63
65
  else if (s.axis.position === "top") {
64
66
  const i = o.y + o.height;
65
- e.beginPath(), e.moveTo(o.x, i), e.lineTo(o.x + o.width, i), e.stroke();
67
+ t.beginPath(), t.moveTo(o.x, i), t.lineTo(o.x + o.width, i), t.stroke();
66
68
  }
67
69
  } else if (s.axis.position === "left") {
68
70
  const i = o.x + o.width;
69
- e.beginPath(), e.moveTo(i, o.y), e.lineTo(i, o.y + o.height), e.stroke();
70
- } else s.axis.position === "right" && (e.beginPath(), e.moveTo(o.x, o.y), e.lineTo(o.x, o.y + o.height), e.stroke());
71
- e.restore();
71
+ t.beginPath(), t.moveTo(i, o.y), t.lineTo(i, o.y + o.height), t.stroke();
72
+ } else s.axis.position === "right" && (t.beginPath(), t.moveTo(o.x, o.y), t.lineTo(o.x, o.y + o.height), t.stroke());
73
+ t.restore();
72
74
  }
73
- }, ht = {
74
- TOP: 400,
75
- MIDDLE: 300,
76
- BOTTOM: 200,
77
- BACKGROUND: 100
78
- }, Bt = () => Rt((n, e) => {
79
- const t = () => {
80
- const s = e()._frame;
81
- if (!s) throw new Error("No frame set in frame store");
82
- return s;
83
- };
84
- return {
85
- _frame: null,
86
- getFrame: t,
87
- getCtx: () => t().ctx,
88
- clampXPosToChartArea: (s, o) => B(t(), s, o ?? "canvas"),
89
- clampYPosToChartArea: (s, o) => N(t(), s, o ?? "canvas"),
90
- valToPos: (s, o, i) => H(t(), s, o, i ?? "canvas"),
91
- valToPxDistance: (s, o, i) => pt(
92
- t(),
93
- s,
94
- o,
95
- i ?? "canvas"
96
- ),
97
- valFits: (s, o) => dt(t(), s, o),
98
- getScale: (s) => U(t(), s),
99
- _listeners: [],
100
- _subscribe: (s, o) => (e()._listeners.push([o, s]), e()._listeners.sort((i, r) => i[0] - r[0]), () => {
101
- const i = e()._listeners.findIndex(([, r]) => r === s);
102
- i !== -1 && e()._listeners.splice(i, 1);
103
- }),
104
- _notifyListeners: (s) => {
105
- for (const [, o] of e()._listeners)
106
- o(s);
107
- }
108
- };
109
- }), Nt = () => Rt((n) => ({
110
- notify: () => {
111
- n((e) => ({ version: e.version + 1 }));
112
- },
113
- version: 0
114
- })), xt = Et(null), At = Et(null), z = (n, e, t) => {
115
- const s = tt(xt), o = tt(At);
116
- if (!s || !o)
117
- throw new Error("useFrame must be used within a CanPlot component");
118
- const i = I(e);
119
- i.current = e, Y(() => (Promise.resolve().then(() => {
120
- i.current(s.getState());
121
- }), s.getState()._subscribe(
122
- (r) => {
123
- r._frame && i.current(r);
124
- },
125
- typeof n == "number" ? n : ht[n]
126
- )), [s, n]), Pt(() => {
127
- o.getState().notify();
128
- }, [o, ...t]);
129
- }, yt = (n) => {
130
- const e = tt(xt);
131
- if (!e)
132
- throw new Error("useFrame must be used within a CanPlot component");
133
- return kt(
134
- e,
135
- n ?? ((t) => t.getFrame())
136
- );
137
75
  };
138
- function $t(n) {
139
- return (e) => {
140
- for (const t of n) ft(t, e);
76
+ function je(e) {
77
+ return (t) => {
78
+ for (const n of e) fe(n, t);
141
79
  };
142
80
  }
143
- function Vt(n) {
144
- return (e) => {
145
- const t = [];
146
- for (const s of n) {
147
- const o = ft(s, e), i = typeof o == "function";
148
- t.push(i ? o : () => ft(s, null));
81
+ function He(e) {
82
+ return (t) => {
83
+ const n = [];
84
+ for (const s of e) {
85
+ const o = fe(s, t), i = typeof o == "function";
86
+ n.push(i ? o : () => fe(s, null));
149
87
  }
150
88
  return () => {
151
- for (const s of t) s();
89
+ for (const s of n) s();
152
90
  };
153
91
  };
154
92
  }
155
- function ft(n, e) {
156
- if (typeof n == "function")
157
- return n(e);
158
- n && (n.current = e);
93
+ function fe(e, t) {
94
+ if (typeof e == "function")
95
+ return e(t);
96
+ e && (e.current = t);
159
97
  }
160
- var jt = parseInt(Kt.split(".")[0], 10) >= 19 ? Vt : $t;
161
- const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) => {
162
- const i = I(null), r = I(null), c = Wt(r), u = et(Bt, []), d = et(Nt, []);
163
- Y(() => {
164
- u.setState({
165
- _frame: qt(n, c, i.current)
166
- });
167
- const a = u.getState();
168
- a._notifyListeners(a);
169
- }, [n, c, i, u]), Y(() => u.getState()._subscribe((a) => {
170
- const f = a._frame?.ctx;
171
- f && f.clearRect(0, 0, f.canvas.width, f.canvas.height);
172
- }, ht.BACKGROUND), [u]), Y(() => u.getState()._subscribe((a) => {
173
- a._frame && Yt(a._frame);
174
- }, ht.BOTTOM), [u]), Y(() => {
175
- let a = !1;
176
- return d.subscribe(() => {
177
- a || (a = !0, window.requestAnimationFrame(() => {
178
- a = !1, u.setState((l) => ({
179
- _frame: l._frame ? { ...l._frame } : null
180
- }));
181
- const f = u.getState();
182
- f._notifyListeners(f);
183
- }));
184
- });
185
- }, [d, u]);
186
- const h = window.devicePixelRatio || 1;
187
- return /* @__PURE__ */ mt(
98
+ var We = parseInt(Oe.split(".")[0], 10) >= 19 ? He : je;
99
+ const Ee = pe({
100
+ listeners: [],
101
+ subscribe: () => () => {
102
+ },
103
+ notifyListeners: () => {
104
+ }
105
+ }), qe = () => {
106
+ const e = [];
107
+ return { listeners: e, subscribe: (s, o) => (e.push([o, s]), e.sort((i, r) => i[0] - r[0]), () => {
108
+ const i = e.findIndex(([, r]) => r === s);
109
+ i !== -1 && e.splice(i, 1);
110
+ }), notifyListeners: () => {
111
+ for (const [, s] of e)
112
+ s();
113
+ } };
114
+ }, ve = pe(null), Re = pe(() => {
115
+ }), Ge = ({ onRequestUpdate: e, children: t }) => {
116
+ const n = k(e);
117
+ n.current = e;
118
+ const s = Ye(() => {
119
+ n.current();
120
+ }, [n]);
121
+ return /* @__PURE__ */ A(Re.Provider, { value: s, children: t });
122
+ }, ke = {
123
+ TOP: 400,
124
+ MIDDLE: 300,
125
+ BOTTOM: 200,
126
+ BACKGROUND: 100
127
+ };
128
+ class Ae {
129
+ constructor() {
130
+ X(this, "_frame", null);
131
+ X(this, "clampXPosToChartArea", (t, n = "canvas") => $(this.frame, t, n));
132
+ X(this, "clampYPosToChartArea", (t, n = "canvas") => V(this.frame, t, n));
133
+ X(this, "valToPos", (t, n, s = "canvas") => q(this.frame, t, n, s));
134
+ X(this, "valToPxDistance", (t, n, s = "canvas") => ye(this.frame, t, n, s));
135
+ X(this, "valFits", (t, n) => he(this.frame, t, n));
136
+ X(this, "getScale", (t) => _(this.frame, t));
137
+ }
138
+ _updateFrame(t) {
139
+ this._frame = t;
140
+ }
141
+ get frame() {
142
+ if (!this._frame)
143
+ throw new Error("Frame not set in FrameDrawer");
144
+ return this._frame;
145
+ }
146
+ get ctx() {
147
+ return this.frame.ctx;
148
+ }
149
+ }
150
+ const Tt = ze(({ configuration: e, children: t, style: n, className: s }, o) => {
151
+ const i = k(null), r = k(null), c = Je(r), [a, l] = O(() => null);
152
+ B(() => {
153
+ l(Qe(e, c, i.current));
154
+ }, [e, c, i]);
155
+ const d = window.devicePixelRatio || 1;
156
+ return /* @__PURE__ */ me(
188
157
  "div",
189
158
  {
190
- ref: jt([o, r]),
159
+ ref: We([o, r]),
191
160
  className: s,
192
161
  style: {
193
162
  position: "relative",
194
163
  overflow: "hidden",
195
- ...t
164
+ ...n
196
165
  },
197
166
  "data-canplotroot": !0,
198
167
  children: [
199
- /* @__PURE__ */ D(
168
+ /* @__PURE__ */ A(
200
169
  "canvas",
201
170
  {
202
171
  ref: i,
203
- width: c.width * h,
204
- height: c.height * h,
172
+ width: c.width * d,
173
+ height: c.height * d,
205
174
  style: {
206
175
  inset: 0,
207
176
  position: "absolute",
@@ -210,82 +179,104 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
210
179
  }
211
180
  }
212
181
  ),
213
- /* @__PURE__ */ D(
214
- Ht,
215
- {
216
- frameStore: u,
217
- updateRequestStore: d,
218
- children: e
219
- }
220
- )
182
+ a && /* @__PURE__ */ A(Ze, { frame: a, children: t })
221
183
  ]
222
184
  }
223
185
  );
224
- }), Ht = ({ frameStore: n, updateRequestStore: e, children: t }) => kt(n, (o) => !!o._frame) ? /* @__PURE__ */ D(At.Provider, { value: e, children: /* @__PURE__ */ D(xt.Provider, { value: n, children: t }) }) : null, Wt = (n) => {
225
- const [e, t] = V({
186
+ }), Ze = ({
187
+ frame: e,
188
+ children: t
189
+ }) => {
190
+ const n = G(qe, []), [s, o] = O(0);
191
+ B(() => {
192
+ e?.ctx.clearRect(0, 0, e.ctx.canvas.width, e.ctx.canvas.height);
193
+ }, [e, s]);
194
+ const i = k(null);
195
+ return i.current = e, B(() => {
196
+ n.subscribe(() => {
197
+ i.current && Ve(i.current);
198
+ }, ke.BOTTOM);
199
+ }, [n]), B(() => {
200
+ let r = null;
201
+ return r = window.requestAnimationFrame(() => {
202
+ r = null, n.notifyListeners();
203
+ }), () => {
204
+ r && cancelAnimationFrame(r);
205
+ };
206
+ }, [s, e, n]), /* @__PURE__ */ A(Ee.Provider, { value: n, children: /* @__PURE__ */ A(ve.Provider, { value: e, children: /* @__PURE__ */ A(
207
+ Ge,
208
+ {
209
+ onRequestUpdate: () => {
210
+ o((r) => r + 1);
211
+ },
212
+ children: t
213
+ }
214
+ ) }) });
215
+ }, Je = (e) => {
216
+ const [t, n] = O({
226
217
  width: 0,
227
218
  height: 0
228
- }), [s] = V(() => new ResizeObserver((o) => {
219
+ }), [s] = O(() => new ResizeObserver((o) => {
229
220
  for (const i of o) {
230
221
  const r = Math.round(i.contentRect.width), c = Math.round(i.contentRect.height);
231
- t(
232
- (u) => u.width !== r || u.height !== c ? { ...u, width: r, height: c } : u
222
+ n(
223
+ (a) => a.width !== r || a.height !== c ? { ...a, width: r, height: c } : a
233
224
  );
234
225
  }
235
226
  }));
236
- return Y(() => {
237
- if (!n.current) return;
238
- const o = n.current.clientWidth, i = n.current.clientHeight;
239
- return t(
227
+ return B(() => {
228
+ if (!e.current) return;
229
+ const o = e.current.clientWidth, i = e.current.clientHeight;
230
+ return n(
240
231
  (r) => r.width !== o || r.height !== i ? { ...r, width: o, height: i } : r
241
- ), s.observe(n.current, { box: "border-box" }), () => s.disconnect();
242
- }, [s, n]), e;
243
- }, qt = (n, e, t) => {
244
- const s = t?.getContext("2d");
232
+ ), s.observe(e.current, { box: "border-box" }), () => s.disconnect();
233
+ }, [s, e]), t;
234
+ }, Qe = (e, t, n) => {
235
+ const s = n?.getContext("2d");
245
236
  if (!s) return null;
246
237
  const o = window.devicePixelRatio || 1;
247
- if (e.width === 0 || e.height === 0)
238
+ if (t.width === 0 || t.height === 0)
248
239
  return null;
249
240
  const i = {
250
- x: n.padding.left,
251
- y: n.padding.top,
252
- width: e.width - n.padding.left - n.padding.right,
253
- height: e.height - n.padding.top - n.padding.bottom
241
+ x: e.padding.left,
242
+ y: e.padding.top,
243
+ width: t.width - e.padding.left - e.padding.right,
244
+ height: t.height - e.padding.top - e.padding.bottom
254
245
  };
255
- for (const l of n.scales)
256
- l.axis && (l.origin === "x" ? (l.axis.position === "bottom" || l.axis.position === "top") && (i.height = Math.max(
246
+ for (const u of e.scales)
247
+ u.axis && (u.origin === "x" ? (u.axis.position === "bottom" || u.axis.position === "top") && (i.height = Math.max(
257
248
  0,
258
- i.height - l.axis.size
259
- ), l.axis.position === "top" && (i.y += l.axis.size)) : (l.axis.position === "left" || l.axis.position === "right") && (i.width = Math.max(0, i.width - l.axis.size), l.axis.position === "left" && (i.x += l.axis.size)));
249
+ i.height - u.axis.size
250
+ ), 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)));
260
251
  const r = {
261
252
  x: i.x * o,
262
253
  y: i.y * o,
263
254
  width: i.width * o,
264
255
  height: i.height * o
265
256
  }, c = [];
266
- let u = n.padding.left * o, d = s.canvas.width - n.padding.right * o, h = s.canvas.height - n.padding.bottom * o, a = n.padding.top * o;
267
- for (const l of n.scales) {
268
- if (!l.axis) {
269
- c.push({ ...l, axis: null });
257
+ let a = e.padding.left * o, l = s.canvas.width - e.padding.right * o, d = s.canvas.height - e.padding.bottom * o, h = e.padding.top * o;
258
+ for (const u of e.scales) {
259
+ if (!u.axis) {
260
+ c.push({ ...u, axis: null });
270
261
  continue;
271
262
  }
272
- let m;
273
- if (l.origin === "x")
274
- switch (l.axis.position) {
263
+ let f;
264
+ if (u.origin === "x")
265
+ switch (u.axis.position) {
275
266
  case "bottom":
276
- h -= l.axis.size * o, m = {
267
+ d -= u.axis.size * o, f = {
277
268
  x: i.x,
278
- y: h / o,
269
+ y: d / o,
279
270
  width: i.width,
280
- height: l.axis.size
271
+ height: u.axis.size
281
272
  };
282
273
  break;
283
274
  case "top":
284
- a += l.axis.size * o, m = {
275
+ h += u.axis.size * o, f = {
285
276
  x: i.x,
286
- y: a / o - l.axis.size,
277
+ y: h / o - u.axis.size,
287
278
  width: i.width,
288
- height: l.axis.size
279
+ height: u.axis.size
289
280
  };
290
281
  break;
291
282
  case "left":
@@ -293,20 +284,20 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
293
284
  throw new Error("Invalid axis position for x origin");
294
285
  }
295
286
  else
296
- switch (l.axis.position) {
287
+ switch (u.axis.position) {
297
288
  case "left":
298
- u += l.axis.size * o, m = {
299
- x: u / o - l.axis.size,
289
+ a += u.axis.size * o, f = {
290
+ x: a / o - u.axis.size,
300
291
  y: i.y,
301
- width: l.axis.size,
292
+ width: u.axis.size,
302
293
  height: i.height
303
294
  };
304
295
  break;
305
296
  case "right":
306
- d -= l.axis.size * o, m = {
307
- x: d / o,
297
+ l -= u.axis.size * o, f = {
298
+ x: l / o,
308
299
  y: i.y,
309
- width: l.axis.size,
300
+ width: u.axis.size,
310
301
  height: i.height
311
302
  };
312
303
  break;
@@ -314,297 +305,313 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
314
305
  case "bottom":
315
306
  throw new Error("Invalid axis position for y origin");
316
307
  }
317
- const x = {
318
- x: m.x * o,
319
- y: m.y * o,
320
- width: m.width * o,
321
- height: m.height * o
308
+ const v = {
309
+ x: f.x * o,
310
+ y: f.y * o,
311
+ width: f.width * o,
312
+ height: f.height * o
322
313
  };
323
314
  c.push({
324
- ...l,
315
+ ...u,
325
316
  axis: {
326
- ...l.axis,
327
- cssRect: m,
328
- canvasRect: x
317
+ ...u.axis,
318
+ cssRect: f,
319
+ canvasRect: v
329
320
  }
330
321
  });
331
322
  }
332
323
  return {
333
324
  ctx: s,
334
325
  dpr: o,
335
- padding: n.padding,
326
+ padding: e.padding,
336
327
  scales: c,
337
328
  chartAreaCSS: i,
338
329
  chartAreaCanvasPX: r
339
330
  };
340
- }, ge = ({ layer: n = "MIDDLE", data: e, xScaleId: t, yScaleId: s, style: o }) => (z(
341
- n,
342
- ({ getCtx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: u }) => {
343
- const d = i();
344
- d.save(), d.beginPath(), _(d, o);
345
- for (const h of e) {
346
- const a = r(u(h.x, t)), f = c(u(h.y, s));
347
- d.lineTo(a, f);
331
+ }, N = (e, t, n) => {
332
+ const s = H(ve), o = H(Re), i = H(Ee);
333
+ if (!s || !o)
334
+ throw new Error("useFrame must be used within a CanPlot component");
335
+ const [r] = O(() => new Ae());
336
+ r._updateFrame(s);
337
+ const c = k(r);
338
+ c.current = r;
339
+ const a = k(t);
340
+ a.current = t, B(() => i.subscribe(
341
+ () => {
342
+ a.current(r);
343
+ },
344
+ typeof e == "number" ? e : ke[e]
345
+ ), [i, e, r]), B(() => {
346
+ o();
347
+ }, [o, ...n]);
348
+ }, ge = () => {
349
+ const e = H(ve);
350
+ if (!e)
351
+ throw new Error("useFrame must be used within a CanPlot component");
352
+ return G(() => {
353
+ const t = new Ae();
354
+ return t._updateFrame(e), t;
355
+ }, [e]);
356
+ }, St = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (N(
357
+ e,
358
+ ({ ctx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: a }) => {
359
+ i.save(), i.beginPath(), L(i, o);
360
+ for (const l of t) {
361
+ const d = r(a(l.x, n)), h = c(a(l.y, s));
362
+ i.lineTo(d, h);
348
363
  }
349
- d.stroke(), d.restore();
364
+ i.stroke(), i.restore();
350
365
  },
351
- [e, t, s, o]
352
- ), null), we = ({ layer: n = "MIDDLE", data: e, xScaleId: t, yScaleId: s, radius: o = 5, style: i, globalAlpha: r }) => (z(
353
- n,
354
- ({ getCtx: c, valToPos: u, valFits: d }) => {
355
- const h = c();
356
- h.save(), h.beginPath();
357
- const a = new Path2D();
358
- _(h, i), r !== void 0 && (h.globalAlpha = r);
359
- for (const f of e) {
360
- if (!d(f.x, t) || !d(f.y, s))
366
+ [t, n, s, o]
367
+ ), null), Ct = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, radius: o = 5, style: i, globalAlpha: r }) => (N(
368
+ e,
369
+ ({ ctx: c, valToPos: a, valFits: l }) => {
370
+ c.save(), c.beginPath();
371
+ const d = new Path2D();
372
+ L(c, i), r !== void 0 && (c.globalAlpha = r);
373
+ for (const h of t) {
374
+ if (!l(h.x, n) || !l(h.y, s))
361
375
  continue;
362
- const l = u(f.x, t), m = u(f.y, s);
363
- a.moveTo(l + o, m), a.arc(l, m, o, 0, Math.PI * 2);
376
+ const m = a(h.x, n), u = a(h.y, s);
377
+ d.moveTo(m + o, u), d.arc(m, u, o, 0, Math.PI * 2);
364
378
  }
365
- h.fill(a), h.stroke(a), h.restore();
379
+ c.fill(d), c.stroke(d), c.restore();
366
380
  },
367
- [e, t, s, o, i, r]
368
- ), null), be = ({
369
- data: n,
370
- xScaleId: e,
371
- yScaleId: t,
381
+ [t, n, s, o, i, r]
382
+ ), null), Pt = ({
383
+ data: e,
384
+ xScaleId: t,
385
+ yScaleId: n,
372
386
  style: s,
373
387
  barWidth: o,
374
388
  xPositionOffset: i,
375
389
  radius: r,
376
390
  layer: c = "MIDDLE"
377
- }) => (z(
391
+ }) => (N(
378
392
  c,
379
393
  ({
380
- getCtx: u,
381
- valToPxDistance: d,
382
- valToPos: h,
383
- clampXPosToChartArea: a,
384
- clampYPosToChartArea: f
394
+ ctx: a,
395
+ valToPxDistance: l,
396
+ valToPos: d,
397
+ clampXPosToChartArea: h,
398
+ clampYPosToChartArea: m
385
399
  }) => {
386
- if (n.length === 0) return;
387
- const l = u();
388
- l.save(), _(l, s);
389
- const m = d(o, e);
390
- l.beginPath();
391
- for (const x of n) {
392
- const v = h(x.x, e) - m / 2 + i * m, w = f(h(0, t)), b = f(h(x.y, t)), S = w - b, y = a(v), g = a(v + m) - y;
393
- r ? l.roundRect(
394
- y,
400
+ if (e.length === 0) return;
401
+ a.save(), L(a, s);
402
+ const u = l(o, t);
403
+ a.beginPath();
404
+ for (const f of e) {
405
+ const p = d(f.x, t) - u / 2 + i * u, g = m(d(0, n)), w = m(d(f.y, n)), T = g - w, b = h(p), y = h(p + u) - b;
406
+ r ? a.roundRect(
395
407
  b,
396
- g,
397
- S,
408
+ w,
409
+ y,
410
+ T,
398
411
  r
399
- ) : l.rect(y, b, g, S);
412
+ ) : a.rect(b, w, y, T);
400
413
  }
401
- l.closePath(), l.fill(), s?.strokeStyle && l.stroke(), l.restore();
414
+ a.closePath(), a.fill(), s?.strokeStyle && a.stroke(), a.restore();
402
415
  },
403
- [n, e, t, s, o, i, r]
404
- ), null), Se = ({ layer: n = "MIDDLE", data: e, xScaleId: t, yScaleId: s, style: o }) => (z(
405
- n,
406
- ({ getCtx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: u }) => {
407
- const d = [];
408
- for (const a of e) {
409
- const f = r(u(a.x, t)), l = c(u(a.y[0], s)), m = c(u(a.y[1], s));
410
- d.push({ x: f, y: l }), d.unshift({ x: f, y: m });
416
+ [e, t, n, s, o, i, r]
417
+ ), null), Mt = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (N(
418
+ e,
419
+ ({ ctx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: a }) => {
420
+ const l = [];
421
+ for (const d of t) {
422
+ const h = r(a(d.x, n)), m = c(a(d.y[0], s)), u = c(a(d.y[1], s));
423
+ l.push({ x: h, y: m }), l.unshift({ x: h, y: u });
411
424
  }
412
- const h = i();
413
- if (d.length > 0) {
414
- h.save(), h.beginPath(), _(h, o), h.moveTo(d[0].x, d[0].y);
415
- for (const a of d)
416
- h.lineTo(a.x, a.y);
417
- h.closePath(), h.fill(), h.restore();
425
+ if (l.length > 0) {
426
+ i.save(), i.beginPath(), L(i, o), i.moveTo(l[0].x, l[0].y);
427
+ for (const d of l)
428
+ i.lineTo(d.x, d.y);
429
+ i.closePath(), i.fill(), i.restore();
418
430
  }
419
431
  },
420
- [e, t, s, o]
421
- ), null), Te = ({ layer: n = "MIDDLE", data: e, stroked: t, xScaleId: s, yScaleId: o, style: i }) => (z(
422
- n,
423
- ({ getCtx: r, clampXPosToChartArea: c, clampYPosToChartArea: u, valToPos: d }) => {
424
- const h = [], a = r();
425
- for (const x of e) {
426
- const p = c(d(x.x, s)), v = u(d(x.y, o));
427
- h.push({ x: p, y: v });
432
+ [t, n, s, o]
433
+ ), null), Et = ({ layer: e = "MIDDLE", data: t, stroked: n, xScaleId: s, yScaleId: o, style: i }) => (N(
434
+ e,
435
+ ({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: a, valToPos: l }) => {
436
+ const d = [];
437
+ for (const f of t) {
438
+ const v = c(l(f.x, s)), p = a(l(f.y, o));
439
+ d.push({ x: v, y: p });
428
440
  }
429
- const f = h.at(0), l = h.at(-1);
430
- if (!f || !l)
441
+ const h = d.at(0), m = d.at(-1);
442
+ if (!h || !m)
431
443
  return;
432
- const m = u(d(0, o));
433
- a.save(), a.beginPath(), _(a, i), a.moveTo(f.x, m);
434
- for (const x of h)
435
- a.lineTo(x.x, x.y);
436
- if (a.lineTo(l.x, m), a.closePath(), a.fill(), t) {
437
- a.beginPath(), a.moveTo(f.x, f.y);
438
- for (const x of h)
439
- a.lineTo(x.x, x.y);
440
- a.stroke();
444
+ const u = a(l(0, o));
445
+ r.save(), r.beginPath(), L(r, i), r.moveTo(h.x, u);
446
+ for (const f of d)
447
+ r.lineTo(f.x, f.y);
448
+ if (r.lineTo(m.x, u), r.closePath(), r.fill(), n) {
449
+ r.beginPath(), r.moveTo(h.x, h.y);
450
+ for (const f of d)
451
+ r.lineTo(f.x, f.y);
452
+ r.stroke();
441
453
  }
442
- a.restore();
454
+ r.restore();
443
455
  },
444
- [e, t, s, o, i]
445
- ), null), Ce = (n, e) => yt(
446
- ({
447
- clampXPosToChartArea: t,
448
- clampYPosToChartArea: s,
449
- getScale: o,
450
- valToPos: i,
451
- valFits: r
452
- }) => {
453
- const c = {};
454
- for (const u in n) {
455
- const d = n[u];
456
+ [t, n, s, o, i]
457
+ ), null), Rt = (e, t) => {
458
+ const n = ge();
459
+ return G(() => {
460
+ const { valToPos: s, valFits: o, getScale: i, clampXPosToChartArea: r, clampYPosToChartArea: c } = n, a = {};
461
+ for (const l in e) {
462
+ const d = e[l];
456
463
  switch (d.exceeding) {
457
464
  case "discard": {
458
- if (r(d.value, d.scaleId)) {
459
- const h = i(d.value, d.scaleId, e);
460
- c[u] = h;
465
+ if (o(d.value, d.scaleId)) {
466
+ const h = s(d.value, d.scaleId, t);
467
+ a[l] = h;
461
468
  }
462
469
  break;
463
470
  }
464
471
  case "clamp": {
465
- const h = i(d.value, d.scaleId, e);
466
- c[u] = o(d.scaleId)?.origin === "x" ? t(h, e) : s(h, e);
472
+ const h = s(d.value, d.scaleId, t);
473
+ a[l] = i(d.scaleId)?.origin === "x" ? r(h, t) : c(h, t);
467
474
  break;
468
475
  }
469
476
  }
470
477
  }
471
- return c;
472
- }
473
- ), Me = ({ layer: n = "BOTTOM", scaleId: e, tickStyle: t, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (z(
474
- n,
475
- ({ getCtx: c, valToPos: u, getScale: d, getFrame: h }) => {
476
- const a = c(), f = d(e);
477
- if (!f || !f.axis || f.origin !== "x") return;
478
- const l = f.axis, m = l.position === "top" ? l.canvasRect.y + l.canvasRect.height : l.canvasRect.y, x = window.devicePixelRatio || 1, p = m, v = (i ?? 6) * x, w = l.position === "top" ? m - v : m + v, b = (o ?? 12) * x;
479
- a.save(), a.fontKerning = "auto", _(a, {
480
- ...t
481
- }), a.beginPath();
482
- const S = Array.isArray(r) ? r : r({ ...f, axis: l }, h());
483
- for (const { value: y } of S) {
484
- const g = u(y, e, "canvas");
485
- a.moveTo(g, p), a.lineTo(g, w);
478
+ return a;
479
+ }, [e, t, n]);
480
+ }, kt = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (N(
481
+ e,
482
+ ({ ctx: c, valToPos: a, getScale: l, frame: d }) => {
483
+ const h = l(t);
484
+ if (!h || !h.axis || h.origin !== "x") return;
485
+ const m = h.axis, u = m.position === "top" ? m.canvasRect.y + m.canvasRect.height : m.canvasRect.y, f = window.devicePixelRatio || 1, v = u, p = (i ?? 6) * f, g = m.position === "top" ? u - p : u + p, w = (o ?? 12) * f;
486
+ c.save(), c.fontKerning = "auto", L(c, {
487
+ ...n
488
+ }), c.beginPath();
489
+ const T = Array.isArray(r) ? r : r({ ...h, axis: m }, d);
490
+ for (const { value: b } of T) {
491
+ const y = a(b, t, "canvas");
492
+ c.moveTo(y, v), c.lineTo(y, g);
486
493
  }
487
- a.stroke(), a.restore(), a.save(), _(a, {
488
- textBaseline: l.position === "top" ? "bottom" : "top",
494
+ c.stroke(), c.restore(), c.save(), L(c, {
495
+ textBaseline: m.position === "top" ? "bottom" : "top",
489
496
  textAlign: "center",
490
- ...t,
497
+ ...n,
491
498
  ...s
492
499
  });
493
- for (const { value: y, label: g } of S) {
494
- const P = u(y, e, "canvas"), C = g.split(`
500
+ for (const { value: b, label: y } of T) {
501
+ const x = a(b, t, "canvas"), S = y.split(`
495
502
  `);
496
- for (let T = 0; T < C.length; T++)
497
- a.fillText(C[T], P, w + x * 2 + T * b);
503
+ for (let E = 0; E < S.length; E++)
504
+ c.fillText(S[E], x, g + f * 2 + E * w);
498
505
  }
499
- a.restore();
506
+ c.restore();
500
507
  },
501
- [r, e, t, s]
502
- ), null), Ee = ({ layer: n = "BOTTOM", scaleId: e, tickStyle: t, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (z(
503
- n,
504
- ({ getCtx: c, valToPos: u, getScale: d, getFrame: h }) => {
505
- const a = c(), f = d(e);
506
- if (!f || !f.axis || f.origin !== "y") return;
507
- const l = f.axis, m = l.position === "left" ? l.canvasRect.x + l.canvasRect.width : l.canvasRect.x, x = m, p = i ?? 6, v = l.position === "left" ? m - p : m + p, w = o ?? 12, b = Array.isArray(r) ? r : r({ ...f, axis: l }, h());
508
- a.save(), a.fontKerning = "auto", _(a, { ...t }), a.beginPath();
509
- for (const { value: S } of b) {
510
- const y = u(S, e, "canvas");
511
- a.moveTo(x, y), a.lineTo(v, y);
508
+ [r, t, n, s]
509
+ ), null), At = ({ layer: e = "BOTTOM", scaleId: t, tickStyle: n, labelStyle: s, labelGap: o, tickSize: i, ticks: r }) => (N(
510
+ e,
511
+ ({ ctx: c, valToPos: a, getScale: l, frame: d }) => {
512
+ const h = l(t);
513
+ if (!h || !h.axis || h.origin !== "y") return;
514
+ const m = h.axis, u = m.position === "left" ? m.canvasRect.x + m.canvasRect.width : m.canvasRect.x, f = u, v = i ?? 6, p = m.position === "left" ? u - v : u + v, g = o ?? 12, w = Array.isArray(r) ? r : r({ ...h, axis: m }, d);
515
+ c.save(), c.fontKerning = "auto", L(c, { ...n }), c.beginPath();
516
+ for (const { value: T } of w) {
517
+ const b = a(T, t, "canvas");
518
+ c.moveTo(f, b), c.lineTo(p, b);
512
519
  }
513
- a.stroke(), a.restore(), a.save(), _(a, {
520
+ c.stroke(), c.restore(), c.save(), L(c, {
514
521
  textBaseline: "middle",
515
- textAlign: l.position === "left" ? "right" : "left",
516
- ...t,
522
+ textAlign: m.position === "left" ? "right" : "left",
523
+ ...n,
517
524
  ...s
518
525
  });
519
- for (const { value: S, label: y } of b) {
520
- const g = u(S, e, "canvas"), P = y.split(`
526
+ for (const { value: T, label: b } of w) {
527
+ const y = a(T, t, "canvas"), x = b.split(`
521
528
  `);
522
- for (let C = 0; C < P.length; C++)
523
- a.fillText(` ${P[C]} `, v, g + C * w);
529
+ for (let S = 0; S < x.length; S++)
530
+ c.fillText(` ${x[S]} `, p, y + S * g);
524
531
  }
525
- a.restore();
532
+ c.restore();
526
533
  },
527
- [r, e, t, s]
528
- ), null), k = () => {
529
- const n = [];
534
+ [r, t, n, s]
535
+ ), null), D = () => {
536
+ const e = [];
530
537
  return {
531
- addEventListener: (e, t) => (n.push({
532
- syncKey: e,
533
- callback: t
538
+ addEventListener: (t, n) => (e.push({
539
+ syncKey: t,
540
+ callback: n
534
541
  }), () => {
535
- const s = n.findIndex((o) => o.callback === t);
536
- s !== -1 && n.splice(s, 1);
542
+ const s = e.findIndex((o) => o.callback === n);
543
+ s !== -1 && e.splice(s, 1);
537
544
  }),
538
- dispatchEvent: (e, t) => {
539
- for (const s of n)
540
- s.syncKey === e && s.callback(e, t);
545
+ dispatchEvent: (t, n) => {
546
+ for (const s of e)
547
+ s.syncKey === t && s.callback(t, n);
541
548
  }
542
549
  };
543
- }, E = {
544
- dblclick: k(),
545
- click: k(),
546
- contextmenu: k(),
547
- move: k(),
548
- mousedown: k(),
549
- mouseup: k(),
550
- spanselect: k(),
551
- documentmouseup: k(),
552
- pressandwheel: k(),
553
- sync_move: k()
554
- }, A = (n, e, t) => {
555
- const s = Q.useRef(t);
556
- s.current = t, Q.useEffect(() => E[n].addEventListener(
557
- e,
550
+ }, M = {
551
+ dblclick: D(),
552
+ click: D(),
553
+ contextmenu: D(),
554
+ move: D(),
555
+ mousedown: D(),
556
+ mouseup: D(),
557
+ spanselect: D(),
558
+ documentmouseup: D(),
559
+ pressandwheel: D(),
560
+ sync_move: D()
561
+ }, I = (e, t, n) => {
562
+ const s = ne.useRef(n);
563
+ s.current = n, ne.useEffect(() => M[e].addEventListener(
564
+ t,
558
565
  (i, r) => {
559
566
  s.current(r, i);
560
567
  }
561
- ), [e, n, s]);
562
- }, vt = Q.createContext(""), gt = (n, e) => {
563
- const t = Q.useContext(vt);
564
- return A(n, t, e);
565
- }, Gt = (n, e, t, s, o) => {
566
- if (!e) return;
567
- const i = s ?? t.scales.find((a) => a.origin === "x")?.id, r = o ?? t.scales.find((a) => a.origin === "y")?.id, c = n.clientX - e.left, u = i ? {
568
+ ), [t, e, s]);
569
+ }, we = ne.createContext(""), be = (e, t) => {
570
+ const n = ne.useContext(we);
571
+ return I(e, n, t);
572
+ }, et = (e, t, n, s, o) => {
573
+ if (!t) return;
574
+ 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, a = i ? {
568
575
  scaleId: i,
569
- value: L(t, c, i, "css")
570
- } : null, d = n.clientY - e.top, h = r ? {
576
+ value: U(n, c, i, "css")
577
+ } : null, l = e.clientY - t.top, d = r ? {
571
578
  scaleId: r,
572
- value: L(t, d, r, "css")
579
+ value: U(n, l, r, "css")
573
580
  } : null;
574
- return { pointerSyncPosition: { x: u, y: h }, cssX: c, cssY: d };
575
- }, F = (n, e) => {
576
- const { x: t, y: s } = n, o = t && e.scales.some((r) => r.id === t.scaleId) ? H(e, t.value, t.scaleId, "css") : null, i = s && e.scales.some((r) => r.id === s.scaleId) ? H(e, s.value, s.scaleId, "css") : null;
581
+ return { pointerSyncPosition: { x: a, y: d }, cssX: c, cssY: l };
582
+ }, z = (e, t) => {
583
+ const { x: n, y: s } = e, o = n && t.scales.some((r) => r.id === n.scaleId) ? q(t, n.value, n.scaleId, "css") : null, i = s && t.scales.some((r) => r.id === s.scaleId) ? q(t, s.value, s.scaleId, "css") : null;
577
584
  return {
578
585
  cssX: o,
579
586
  cssY: i,
580
587
  scaled: Object.fromEntries(
581
- e.scales.flatMap((r) => {
588
+ t.scales.flatMap((r) => {
582
589
  const c = r.origin === "y" ? i : o;
583
- return c === null ? [] : [[r.id, L(e, c, r.id, "css")]];
590
+ return c === null ? [] : [[r.id, U(t, c, r.id, "css")]];
584
591
  })
585
592
  )
586
593
  };
587
- }, Ct = (n, e, t) => {
588
- const s = H(
589
- t,
590
- e.from,
591
- e.scaleId,
594
+ }, Pe = (e, t, n) => {
595
+ const s = q(
596
+ n,
597
+ t.from,
598
+ t.scaleId,
592
599
  "css"
593
- ), o = H(
594
- t,
595
- e.to,
596
- e.scaleId,
600
+ ), o = q(
601
+ n,
602
+ t.to,
603
+ t.scaleId,
597
604
  "css"
598
- ), i = t.scales.flatMap(
605
+ ), i = n.scales.flatMap(
599
606
  (r) => {
600
- if (r.origin !== n)
607
+ if (r.origin !== e)
601
608
  return [];
602
- const c = L(t, s, r.id, "css"), u = L(t, o, r.id, "css");
609
+ const c = U(n, s, r.id, "css"), a = U(n, o, r.id, "css");
603
610
  return [
604
611
  {
605
612
  scaleId: r.id,
606
613
  from: c,
607
- to: u
614
+ to: a
608
615
  }
609
616
  ];
610
617
  }
@@ -614,56 +621,56 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
614
621
  toCSS: o,
615
622
  scaled: i
616
623
  };
617
- }, Pe = ({
618
- id: n,
619
- onClick: e,
620
- onDblClick: t,
624
+ }, Dt = ({
625
+ id: e,
626
+ onClick: t,
627
+ onDblClick: n,
621
628
  onMouseMove: s,
622
629
  onMouseDown: o,
623
630
  onMouseUp: i,
624
631
  onDocumentMouseUp: r,
625
632
  onSpanSelect: c,
626
- onContextMenu: u,
627
- className: d,
628
- style: h,
629
- sync: a,
630
- innerChildren: f,
631
- children: l
633
+ onContextMenu: a,
634
+ className: l,
635
+ style: d,
636
+ sync: h,
637
+ innerChildren: m,
638
+ children: u
632
639
  }) => {
633
- const m = Ft();
634
- return A("dblclick", m, (x) => {
635
- t?.(x);
636
- }), A("click", m, (x) => {
637
- e?.(x);
638
- }), A("move", m, (x) => {
639
- s?.(x);
640
- }), A("mousedown", m, (x) => {
641
- o?.(x);
642
- }), A("mouseup", m, (x) => {
643
- i?.(x);
644
- }), A("documentmouseup", m, (x) => {
645
- r?.(x);
646
- }), A("spanselect", m, (x) => {
647
- c?.(x);
648
- }), A("contextmenu", m, (x) => {
649
- u?.(x);
650
- }), /* @__PURE__ */ mt(vt.Provider, { value: m, children: [
651
- /* @__PURE__ */ D(
652
- Zt,
640
+ const f = Be();
641
+ return I("dblclick", f, (v) => {
642
+ n?.(v);
643
+ }), I("click", f, (v) => {
644
+ t?.(v);
645
+ }), I("move", f, (v) => {
646
+ s?.(v);
647
+ }), I("mousedown", f, (v) => {
648
+ o?.(v);
649
+ }), I("mouseup", f, (v) => {
650
+ i?.(v);
651
+ }), I("documentmouseup", f, (v) => {
652
+ r?.(v);
653
+ }), I("spanselect", f, (v) => {
654
+ c?.(v);
655
+ }), I("contextmenu", f, (v) => {
656
+ a?.(v);
657
+ }), /* @__PURE__ */ me(we.Provider, { value: f, children: [
658
+ /* @__PURE__ */ A(
659
+ tt,
653
660
  {
654
- id: n,
655
- className: d,
656
- style: h,
657
- sync: a,
658
- children: f
661
+ id: e,
662
+ className: l,
663
+ style: d,
664
+ sync: h,
665
+ children: m
659
666
  }
660
667
  ),
661
- l
668
+ u
662
669
  ] });
663
- }, Zt = ({ id: n, className: e, style: t, sync: s, children: o }) => {
664
- const i = I(null), r = yt(), c = I(r);
670
+ }, tt = ({ id: e, className: t, style: n, sync: s, children: o }) => {
671
+ const i = k(null), r = ge().frame, c = k(r);
665
672
  c.current = r;
666
- const u = tt(vt), d = s?.key || u, h = I(null), a = I(null), f = I(null), l = () => {
673
+ const a = H(we), l = s?.key || a, d = k(null), h = k(null), m = k(null), u = () => {
667
674
  const p = i.current?.parentElement;
668
675
  if (p) {
669
676
  if (p.dataset.canplotroot === void 0)
@@ -672,15 +679,15 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
672
679
  );
673
680
  return p.getBoundingClientRect();
674
681
  }
675
- }, m = (p, v) => {
676
- const w = Gt(
682
+ }, f = (p, g) => {
683
+ const w = et(
677
684
  p,
678
- l(),
685
+ u(),
679
686
  c.current,
680
687
  s?.xViaScaleId,
681
688
  s?.yViaScaleId
682
689
  );
683
- w && v(
690
+ w && g(
684
691
  w.pointerSyncPosition,
685
692
  { cssX: w.cssX, cssY: w.cssY },
686
693
  {
@@ -690,14 +697,14 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
690
697
  metaKey: p.metaKey
691
698
  }
692
699
  );
693
- }, x = I(m);
694
- return x.current = m, Pt(() => {
700
+ }, v = k(f);
701
+ return v.current = f, Ne(() => {
695
702
  const p = (y) => {
696
- const g = a.current;
697
- g && E.spanselect.dispatchEvent(u, {
698
- ...g,
703
+ const x = h.current;
704
+ x && M.spanselect.dispatchEvent(a, {
705
+ ...x,
699
706
  completed: !0
700
- }), E.documentmouseup.dispatchEvent(u, {
707
+ }), M.documentmouseup.dispatchEvent(a, {
701
708
  frame: c.current,
702
709
  keys: {
703
710
  ctrlKey: y.ctrlKey,
@@ -706,109 +713,109 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
706
713
  metaKey: y.metaKey
707
714
  }
708
715
  });
709
- }, v = (y) => {
710
- const g = {
716
+ }, g = (y) => {
717
+ const x = {
711
718
  ctrlKey: y.ctrlKey,
712
719
  altKey: y.altKey,
713
720
  shiftKey: y.shiftKey,
714
721
  metaKey: y.metaKey
715
- }, P = f.current;
716
- if (P && Object.entries(g).some(
717
- ([T, M]) => P.keys[T] !== M
722
+ }, S = m.current;
723
+ if (S && Object.entries(x).some(
724
+ ([C, P]) => S.keys[C] !== P
718
725
  )) {
719
- const T = { ...P, keys: g };
720
- f.current = T, E.sync_move.dispatchEvent(d, T);
726
+ const C = { ...S, keys: x };
727
+ m.current = C, M.sync_move.dispatchEvent(l, C);
721
728
  }
722
- const C = a.current;
723
- if (C && Object.entries(g).some(
724
- ([T, M]) => C.keys[T] !== M
729
+ const E = h.current;
730
+ if (E && Object.entries(x).some(
731
+ ([C, P]) => E.keys[C] !== P
725
732
  )) {
726
733
  y.stopPropagation(), y.preventDefault();
727
- const T = { ...C, keys: g };
728
- a.current = T, E.spanselect.dispatchEvent(u, T);
734
+ const C = { ...E, keys: x };
735
+ h.current = C, M.spanselect.dispatchEvent(a, C);
729
736
  }
730
737
  }, w = (y) => {
731
- x.current(
738
+ v.current(
732
739
  y,
733
- (g, { cssX: P, cssY: C }, T) => {
734
- const M = h.current;
735
- if (!M || !g.x || !g.y) return;
736
- const R = c.current, O = M.xRangeCss.start, ot = P, it = M.yRangeCss.start, rt = C, ct = U(R, g.x.scaleId), at = U(R, g.y.scaleId);
737
- h.current = {
738
- xRangeCss: { start: O, end: ot },
739
- yRangeCss: { start: it, end: rt }
740
+ (x, { cssX: S, cssY: E }, C) => {
741
+ const P = d.current;
742
+ if (!P || !x.x || !x.y) return;
743
+ const R = c.current, Y = P.xRangeCss.start, ie = S, re = P.yRangeCss.start, ce = E, ae = _(R, x.x.scaleId), le = _(R, x.y.scaleId);
744
+ d.current = {
745
+ xRangeCss: { start: Y, end: ie },
746
+ yRangeCss: { start: re, end: ce }
740
747
  };
741
- let $ = "below_threshold";
742
- const lt = Math.abs(it - rt), ut = Math.abs(O - ot);
743
- lt < 10 && ut < 10 ? $ = "below_threshold" : lt > 30 && ut > 30 ? $ = "box" : lt > ut ? $ = "y" : $ = "x";
744
- const bt = {
745
- scaleId: ct.id,
746
- from: L(
748
+ let j = "below_threshold";
749
+ const ue = Math.abs(re - ce), de = Math.abs(Y - ie);
750
+ ue < 10 && de < 10 ? j = "below_threshold" : ue > 30 && de > 30 ? j = "box" : ue > de ? j = "y" : j = "x";
751
+ const Te = {
752
+ scaleId: ae.id,
753
+ from: U(
747
754
  R,
748
- B(c.current, O, "css"),
749
- ct.id,
755
+ $(c.current, Y, "css"),
756
+ ae.id,
750
757
  "css"
751
758
  ),
752
- to: L(
759
+ to: U(
753
760
  R,
754
- B(c.current, ot, "css"),
755
- ct.id,
761
+ $(c.current, ie, "css"),
762
+ ae.id,
756
763
  "css"
757
764
  )
758
- }, St = {
759
- scaleId: at.id,
760
- from: L(
765
+ }, Se = {
766
+ scaleId: le.id,
767
+ from: U(
761
768
  R,
762
- N(c.current, it, "css"),
763
- at.id,
769
+ V(c.current, re, "css"),
770
+ le.id,
764
771
  "css"
765
772
  ),
766
- to: L(
773
+ to: U(
767
774
  R,
768
- N(c.current, rt, "css"),
769
- at.id,
775
+ V(c.current, ce, "css"),
776
+ le.id,
770
777
  "css"
771
778
  )
772
- }, W = bt && Ct("x", bt, c.current), q = St && Ct("y", St, c.current), Lt = W?.scaled, Ut = q?.scaled, Tt = {
773
- mode: $,
779
+ }, Z = Te && Pe("x", Te, c.current), J = Se && Pe("y", Se, c.current), Ue = Z?.scaled, _e = J?.scaled, Ce = {
780
+ mode: j,
774
781
  frame: c.current,
775
782
  completed: !1,
776
783
  x: {
777
- css: W && {
778
- from: W.fromCSS,
779
- to: W.toCSS
784
+ css: Z && {
785
+ from: Z.fromCSS,
786
+ to: Z.toCSS
780
787
  },
781
- scaled: Lt ?? []
788
+ scaled: Ue ?? []
782
789
  },
783
790
  y: {
784
- css: q && {
785
- from: q.fromCSS,
786
- to: q.toCSS
791
+ css: J && {
792
+ from: J.fromCSS,
793
+ to: J.toCSS
787
794
  },
788
- scaled: Ut ?? []
795
+ scaled: _e ?? []
789
796
  },
790
- keys: T
797
+ keys: C
791
798
  };
792
- a.current = Tt, E.spanselect.dispatchEvent(
793
- u,
794
- Tt
799
+ h.current = Ce, M.spanselect.dispatchEvent(
800
+ a,
801
+ Ce
795
802
  );
796
803
  }
797
804
  );
798
- }, b = (y) => {
799
- x.current(y, (g, P, C) => {
800
- const T = F(
801
- g,
805
+ }, T = (y) => {
806
+ v.current(y, (x, S, E) => {
807
+ const C = z(
808
+ x,
802
809
  c.current
803
810
  );
804
- if (!T) return;
805
- if (Object.values(C).some((R) => R)) {
811
+ if (!C) return;
812
+ if (Object.values(E).some((R) => R)) {
806
813
  y.preventDefault();
807
814
  const R = Math.abs(y.deltaY) > Math.abs(y.deltaX) ? y.deltaY : y.deltaX;
808
- E.pressandwheel.dispatchEvent(u, {
809
- pointer: T,
815
+ M.pressandwheel.dispatchEvent(a, {
816
+ pointer: C,
810
817
  frame: c.current,
811
- keys: C,
818
+ keys: E,
812
819
  deltaX: y.deltaX,
813
820
  deltaY: y.deltaY,
814
821
  deltaAbs: R
@@ -816,30 +823,30 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
816
823
  }
817
824
  });
818
825
  };
819
- document.addEventListener("mouseup", p), document.addEventListener("keydown", v), document.addEventListener("keyup", v), document.addEventListener("mousemove", w);
820
- const S = i.current;
821
- return S?.addEventListener("wheel", b, {
826
+ document.addEventListener("mouseup", p), document.addEventListener("keydown", g), document.addEventListener("keyup", g), document.addEventListener("mousemove", w);
827
+ const b = i.current;
828
+ return b?.addEventListener("wheel", T, {
822
829
  passive: !1
823
830
  }), () => {
824
- document.removeEventListener("mouseup", p), document.removeEventListener("keydown", v), document.removeEventListener("keyup", v), document.removeEventListener("mousemove", w), S?.removeEventListener("wheel", b);
831
+ document.removeEventListener("mouseup", p), document.removeEventListener("keydown", g), document.removeEventListener("keyup", g), document.removeEventListener("mousemove", w), b?.removeEventListener("wheel", T);
825
832
  };
826
- }, [c, u, d, x]), A("sync_move", d, (p) => {
827
- const v = p.positions ? F(
833
+ }, [c, a, l, v]), I("sync_move", l, (p) => {
834
+ const g = p.positions ? z(
828
835
  p.positions,
829
836
  c.current
830
837
  ) : null;
831
- f.current = p, E.move.dispatchEvent(u, {
838
+ m.current = p, M.move.dispatchEvent(a, {
832
839
  frame: c.current,
833
- pointer: v ?? null,
840
+ pointer: g ?? null,
834
841
  keys: p.keys,
835
- source: p.originInteractionsId === u ? "own" : "sync"
842
+ source: p.originInteractionsId === a ? "own" : "sync"
836
843
  });
837
- }), /* @__PURE__ */ D(
844
+ }), /* @__PURE__ */ A(
838
845
  "div",
839
846
  {
840
847
  ref: i,
841
- id: n,
842
- className: e,
848
+ id: e,
849
+ className: t,
843
850
  style: {
844
851
  position: "absolute",
845
852
  left: r.chartAreaCSS.x,
@@ -847,170 +854,170 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
847
854
  width: r.chartAreaCSS.width,
848
855
  height: r.chartAreaCSS.height,
849
856
  zIndex: 25,
850
- ...t
857
+ ...n
851
858
  },
852
859
  onDragStart: (p) => {
853
860
  p.preventDefault();
854
861
  },
855
862
  onClick: (p) => {
856
- m(p, (v, w, b) => {
857
- const S = F(
858
- v,
863
+ f(p, (g, w, T) => {
864
+ const b = z(
865
+ g,
859
866
  c.current
860
867
  );
861
- S && E.click.dispatchEvent(u, {
862
- pointer: S,
868
+ b && M.click.dispatchEvent(a, {
869
+ pointer: b,
863
870
  frame: c.current,
864
- keys: b
871
+ keys: T
865
872
  });
866
873
  });
867
874
  },
868
875
  onMouseLeave: (p) => {
869
- m(p, (v, w, b) => {
870
- E.sync_move.dispatchEvent(d, {
876
+ f(p, (g, w, T) => {
877
+ M.sync_move.dispatchEvent(l, {
871
878
  positions: null,
872
- keys: b,
873
- originInteractionsId: u
879
+ keys: T,
880
+ originInteractionsId: a
874
881
  });
875
882
  });
876
883
  },
877
884
  onMouseMove: (p) => {
878
- m(p, (v, w, b) => {
879
- E.sync_move.dispatchEvent(d, {
880
- positions: v,
881
- keys: b,
882
- originInteractionsId: u
885
+ f(p, (g, w, T) => {
886
+ M.sync_move.dispatchEvent(l, {
887
+ positions: g,
888
+ keys: T,
889
+ originInteractionsId: a
883
890
  });
884
891
  });
885
892
  },
886
893
  onMouseDown: (p) => {
887
- m(p, (v, { cssX: w, cssY: b }, S) => {
888
- const y = F(
889
- v,
894
+ f(p, (g, { cssX: w, cssY: T }, b) => {
895
+ const y = z(
896
+ g,
890
897
  c.current
891
898
  );
892
- y && (E.mousedown.dispatchEvent(u, {
899
+ y && (M.mousedown.dispatchEvent(a, {
893
900
  pointer: y,
894
901
  frame: c.current,
895
- keys: S
896
- }), h.current = {
902
+ keys: b
903
+ }), d.current = {
897
904
  xRangeCss: { start: w, end: w },
898
- yRangeCss: { start: b, end: b }
905
+ yRangeCss: { start: T, end: T }
899
906
  });
900
907
  });
901
908
  },
902
909
  onMouseUp: (p) => {
903
- m(p, (v, w, b) => {
904
- const S = F(
905
- v,
910
+ f(p, (g, w, T) => {
911
+ const b = z(
912
+ g,
906
913
  c.current
907
914
  );
908
- if (!S) return;
909
- E.mouseup.dispatchEvent(u, {
915
+ if (!b) return;
916
+ M.mouseup.dispatchEvent(a, {
910
917
  frame: c.current,
911
- pointer: S,
912
- keys: b
918
+ pointer: b,
919
+ keys: T
913
920
  });
914
- const y = a.current;
915
- a.current = null;
916
- const g = h.current;
917
- if (h.current = null, g && y) {
918
- const P = {
921
+ const y = h.current;
922
+ h.current = null;
923
+ const x = d.current;
924
+ if (d.current = null, x && y) {
925
+ const S = {
919
926
  ...y,
920
- keys: b,
927
+ keys: T,
921
928
  completed: !0
922
929
  };
923
- a.current = null, E.spanselect.dispatchEvent(
924
- u,
925
- P
930
+ h.current = null, M.spanselect.dispatchEvent(
931
+ a,
932
+ S
926
933
  );
927
934
  }
928
935
  });
929
936
  },
930
937
  onContextMenu: (p) => {
931
- p.preventDefault(), m(p, (v, w, b) => {
932
- const S = F(
933
- v,
938
+ p.preventDefault(), f(p, (g, w, T) => {
939
+ const b = z(
940
+ g,
934
941
  c.current
935
942
  );
936
- S && E.contextmenu.dispatchEvent(u, {
943
+ b && M.contextmenu.dispatchEvent(a, {
937
944
  frame: c.current,
938
- pointer: S,
939
- keys: b
945
+ pointer: b,
946
+ keys: T
940
947
  });
941
948
  });
942
949
  },
943
950
  onDoubleClick: (p) => {
944
- m(p, (v, w, b) => {
945
- const S = F(
946
- v,
951
+ f(p, (g, w, T) => {
952
+ const b = z(
953
+ g,
947
954
  c.current
948
955
  );
949
- S && E.dblclick.dispatchEvent(u, {
956
+ b && M.dblclick.dispatchEvent(a, {
950
957
  frame: c.current,
951
- pointer: S,
952
- keys: b
958
+ pointer: b,
959
+ keys: T
953
960
  });
954
961
  });
955
962
  },
956
963
  children: o
957
964
  }
958
965
  );
959
- }, Re = ({ data: n, renderTooltip: e, xScaleId: t }) => {
960
- const [s, o] = V(null);
961
- gt("move", (r) => {
966
+ }, It = ({ data: e, renderTooltip: t, xScaleId: n }) => {
967
+ const [s, o] = O(null);
968
+ be("move", (r) => {
962
969
  o(r);
963
970
  });
964
- const i = et(() => {
971
+ const i = G(() => {
965
972
  if (!s)
966
973
  return null;
967
- const { frame: r, pointer: c } = s, u = c?.scaled[t];
968
- if (u === void 0)
974
+ const { frame: r, pointer: c } = s, a = c?.scaled[n];
975
+ if (a === void 0)
969
976
  return null;
970
- const d = [];
971
- let h = u;
972
- for (const a of n) {
973
- let f = null, l = 1 / 0;
974
- for (const [x, p] of a.points.entries()) {
975
- if (!dt(r, p.x, t) || !dt(r, p.y, a.yScaleId))
977
+ const l = [];
978
+ let d = a;
979
+ for (const h of e) {
980
+ let m = null, u = 1 / 0;
981
+ for (const [v, p] of h.points.entries()) {
982
+ if (!he(r, p.x, n) || !he(r, p.y, h.yScaleId))
976
983
  continue;
977
- const v = Math.abs(p.x - u);
978
- v < l && (l = v, f = x);
984
+ const g = Math.abs(p.x - a);
985
+ g < u && (u = g, m = v);
979
986
  }
980
- const m = a.points[f ?? -1];
981
- if (!m || pt(r, l, t, "css") > 30) {
982
- d.push({ seriesId: a.seriesId, y: null });
987
+ const f = h.points[m ?? -1];
988
+ if (!f || ye(r, u, n, "css") > 30) {
989
+ l.push({ seriesId: h.seriesId, y: null });
983
990
  continue;
984
991
  }
985
- h = m.x, d.push({
986
- seriesId: a.seriesId,
987
- y: m.y
992
+ d = f.x, l.push({
993
+ seriesId: h.seriesId,
994
+ y: f.y
988
995
  });
989
996
  }
990
997
  return {
991
998
  frame: r,
992
- x: h,
993
- points: d
999
+ x: d,
1000
+ points: l
994
1001
  };
995
- }, [n, s, t]);
996
- return e(i);
997
- }, ke = ({ makeXStyle: n, makeXClassName: e, makeYStyle: t, makeYClassName: s }) => {
998
- const [o, i] = V(null);
999
- if (gt("move", (f) => {
1000
- i(f);
1002
+ }, [e, s, n]);
1003
+ return t(i);
1004
+ }, Lt = ({ makeXStyle: e, makeXClassName: t, makeYStyle: n, makeYClassName: s }) => {
1005
+ const [o, i] = O(null);
1006
+ if (be("move", (m) => {
1007
+ i(m);
1001
1008
  }), !o)
1002
1009
  return null;
1003
- const { frame: r, pointer: c } = o, u = c?.cssX ?? null, d = c?.cssY ?? null, h = u ? B(r, u, "css") : 0, a = d ? N(r, d, "css") : 0;
1004
- return /* @__PURE__ */ mt(Xt, { children: [
1005
- /* @__PURE__ */ D(
1010
+ const { frame: r, pointer: c } = o, a = c?.cssX ?? null, l = c?.cssY ?? null, d = a ? $(r, a, "css") : 0, h = l ? V(r, l, "css") : 0;
1011
+ return /* @__PURE__ */ me(Ke, { children: [
1012
+ /* @__PURE__ */ A(
1006
1013
  "div",
1007
1014
  {
1008
1015
  "data-show": !!c,
1009
- className: e?.(o),
1016
+ className: t?.(o),
1010
1017
  style: {
1011
1018
  position: "absolute",
1012
1019
  left: 0,
1013
- visibility: u === null ? "hidden" : "visible",
1020
+ visibility: a === null ? "hidden" : "visible",
1014
1021
  top: r.chartAreaCSS.y,
1015
1022
  height: r.chartAreaCSS.height,
1016
1023
  borderColor: "red",
@@ -1018,19 +1025,19 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
1018
1025
  borderLeftStyle: "solid",
1019
1026
  pointerEvents: "none",
1020
1027
  opacity: c ? 1 : 0,
1021
- transform: `translateX(${h}px)`,
1022
- ...n?.(o)
1028
+ transform: `translateX(${d}px)`,
1029
+ ...e?.(o)
1023
1030
  }
1024
1031
  }
1025
1032
  ),
1026
- /* @__PURE__ */ D(
1033
+ /* @__PURE__ */ A(
1027
1034
  "div",
1028
1035
  {
1029
1036
  className: s?.(o),
1030
1037
  "data-show": !!c,
1031
1038
  style: {
1032
1039
  position: "absolute",
1033
- visibility: d === null ? "hidden" : "visible",
1040
+ visibility: l === null ? "hidden" : "visible",
1034
1041
  top: 0,
1035
1042
  height: 0,
1036
1043
  borderTop: "solid 1px red",
@@ -1038,44 +1045,44 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
1038
1045
  width: r.chartAreaCSS.width,
1039
1046
  pointerEvents: "none",
1040
1047
  opacity: c ? 1 : 0,
1041
- transform: `translateY(${a}px)`,
1042
- ...t?.(o)
1048
+ transform: `translateY(${h}px)`,
1049
+ ...n?.(o)
1043
1050
  }
1044
1051
  }
1045
1052
  )
1046
1053
  ] });
1047
- }, Ae = ({ makeClassName: n, makeStyle: e }) => {
1048
- const [t, s] = V(null);
1049
- gt("spanselect", (i) => {
1054
+ }, Ut = ({ makeClassName: e, makeStyle: t }) => {
1055
+ const [n, s] = O(null);
1056
+ be("spanselect", (i) => {
1050
1057
  s(
1051
1058
  i.mode === "below_threshold" || i.completed ? null : i
1052
1059
  );
1053
1060
  });
1054
- const o = et(() => {
1055
- if (!t || t.mode === "below_threshold")
1061
+ const o = G(() => {
1062
+ if (!n || n.mode === "below_threshold")
1056
1063
  return null;
1057
- const i = t.mode === "y" ? -1 / 0 : t.x.css?.from ?? -1 / 0, r = t.mode === "y" ? 1 / 0 : t.x.css?.to ?? 1 / 0, c = t.mode === "x" ? -1 / 0 : t.y.css?.from ?? -1 / 0, u = t.mode === "x" ? 1 / 0 : t.y.css?.to ?? 1 / 0, d = B(t.frame, i, "css"), h = B(t.frame, r, "css"), a = N(t.frame, c, "css"), f = N(t.frame, u, "css"), l = Math.min(d, h), m = Math.min(a, f), x = Math.abs(h - d), p = Math.abs(f - a);
1058
- return { leftPx: l, topPx: m, widthPx: x, heightPx: p };
1059
- }, [t]);
1060
- return /* @__PURE__ */ D(
1064
+ 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, a = n.mode === "x" ? 1 / 0 : n.y.css?.to ?? 1 / 0, l = $(n.frame, i, "css"), d = $(n.frame, r, "css"), h = V(n.frame, c, "css"), m = V(n.frame, a, "css"), u = Math.min(l, d), f = Math.min(h, m), v = Math.abs(d - l), p = Math.abs(m - h);
1065
+ return { leftPx: u, topPx: f, widthPx: v, heightPx: p };
1066
+ }, [n]);
1067
+ return /* @__PURE__ */ A(
1061
1068
  "div",
1062
1069
  {
1063
- className: t ? n?.(t) : void 0,
1070
+ className: n ? e?.(n) : void 0,
1064
1071
  style: {
1065
1072
  position: "absolute",
1066
- visibility: t ? "visible" : "hidden",
1073
+ visibility: n ? "visible" : "hidden",
1067
1074
  left: `${o?.leftPx ?? 0}px`,
1068
1075
  top: `${o?.topPx ?? 0}px`,
1069
1076
  width: `${o?.widthPx ?? 0}px`,
1070
1077
  height: `${o?.heightPx ?? 0}px`,
1071
1078
  pointerEvents: "none",
1072
- ...t ? e?.(t) : void 0
1079
+ ...n ? t?.(n) : void 0
1073
1080
  }
1074
1081
  }
1075
1082
  );
1076
- }, De = ({ style: n, children: e, scaleId: t, ...s }) => {
1077
- const o = yt((i) => i.getScale(t)?.axis);
1078
- return o ? /* @__PURE__ */ D(
1083
+ }, _t = ({ style: e, children: t, scaleId: n, ...s }) => {
1084
+ const o = ge().getScale(n)?.axis;
1085
+ return o ? /* @__PURE__ */ A(
1079
1086
  "div",
1080
1087
  {
1081
1088
  style: {
@@ -1085,38 +1092,38 @@ const ve = Ot(({ configuration: n, children: e, style: t, className: s }, o) =>
1085
1092
  top: o.cssRect.y,
1086
1093
  height: o.cssRect.height,
1087
1094
  width: o.cssRect.width,
1088
- ...n
1095
+ ...e
1089
1096
  },
1090
1097
  ...s,
1091
- children: e
1098
+ children: t
1092
1099
  }
1093
1100
  ) : null;
1094
- }, Dt = 60, Jt = 30, _t = "UTC", Qt = "en-GB", _e = ({
1095
- space: n,
1096
- formatter: e,
1097
- acceptableIncrements: t
1101
+ }, De = 60, nt = 30, Ie = "UTC", st = "en-GB", Xt = ({
1102
+ space: e,
1103
+ formatter: t,
1104
+ acceptableIncrements: n
1098
1105
  } = {}) => (s, o) => {
1099
- const { min: i, max: r } = s, c = [], u = window.devicePixelRatio || 1, d = (n ?? (s.origin === "x" ? Dt : Jt)) * u, h = zt(
1106
+ const { min: i, max: r } = s, c = [], a = window.devicePixelRatio || 1, l = (e ?? (s.origin === "x" ? De : nt)) * a, d = $e(
1100
1107
  o,
1101
- d,
1108
+ l,
1102
1109
  s.id,
1103
1110
  "canvas"
1104
- ), a = t ?? G, f = a.find((m) => m > h) ?? a.at(-1) ?? 1;
1105
- let l = i;
1106
- if (Math.abs(l % f) > Number.EPSILON) {
1107
- const m = (f - l % f) % f;
1108
- l += m;
1111
+ ), h = n ?? Q, m = h.find((f) => f > d) ?? h.at(-1) ?? 1;
1112
+ let u = i;
1113
+ if (Math.abs(u % m) > Number.EPSILON) {
1114
+ const f = (m - u % m) % m;
1115
+ u += f;
1109
1116
  }
1110
- for (; l <= r && c.length < 1e3; )
1111
- c.push(l), l += f;
1112
- return (e ?? te)(c);
1113
- }, te = (n) => {
1114
- const e = Math.max(0, Math.ceil(-Math.log10(n[1] - n[0])));
1115
- return n.map((t) => ({ value: t, label: t.toFixed(e) }));
1116
- }, G = [];
1117
- for (let n = -12; n <= 12; n++)
1118
- G.push(1 * 10 ** n), G.push(2 * 10 ** n), G.push(5 * 10 ** n);
1119
- const ee = 1, It = 1e3 * ee, wt = 60 * It, nt = 60 * wt, st = 24 * nt, ne = 30 * st, se = 365 * st, oe = [
1117
+ for (; u <= r && c.length < 1e3; )
1118
+ c.push(u), u += m;
1119
+ return (t ?? ot)(c);
1120
+ }, ot = (e) => {
1121
+ const t = Math.max(0, Math.ceil(-Math.log10(e[1] - e[0])));
1122
+ return e.map((n) => ({ value: n, label: n.toFixed(t) }));
1123
+ }, Q = [];
1124
+ for (let e = -12; e <= 12; e++)
1125
+ Q.push(1 * 10 ** e), Q.push(2 * 10 ** e), Q.push(5 * 10 ** e);
1126
+ const it = 1, Le = 1e3 * it, xe = 60 * Le, se = 60 * xe, oe = 24 * se, rt = 30 * oe, ct = 365 * oe, at = [
1120
1127
  // second divisors
1121
1128
  [1, "milliseconds"],
1122
1129
  [2, "milliseconds"],
@@ -1168,70 +1175,70 @@ const ee = 1, It = 1e3 * ee, wt = 60 * It, nt = 60 * wt, st = 24 * nt, ne = 30 *
1168
1175
  [25, "years"],
1169
1176
  [50, "years"],
1170
1177
  [100, "years"]
1171
- ], Z = (n) => {
1172
- const [e, t] = n;
1173
- switch (t) {
1178
+ ], ee = (e) => {
1179
+ const [t, n] = e;
1180
+ switch (n) {
1174
1181
  case "milliseconds":
1175
- return e;
1182
+ return t;
1176
1183
  case "seconds":
1177
- return e * It;
1184
+ return t * Le;
1178
1185
  case "minutes":
1179
- return e * wt;
1186
+ return t * xe;
1180
1187
  case "hours":
1181
- return e * nt;
1188
+ return t * se;
1182
1189
  case "days":
1183
- return e * st;
1190
+ return t * oe;
1184
1191
  case "months":
1185
- return e * ne;
1192
+ return t * rt;
1186
1193
  case "years":
1187
- return e * se;
1194
+ return t * ct;
1188
1195
  }
1189
- }, ie = (n, e) => {
1190
- const t = new Date(n);
1191
- return t.setUTCMilliseconds(t.getUTCMilliseconds() + e), t.getTime();
1192
- }, re = (n, e) => {
1193
- const t = new Date(n);
1194
- return t.setUTCSeconds(t.getUTCSeconds() + e), t.getTime();
1195
- }, ce = (n, e) => {
1196
- const t = new Date(n);
1197
- return t.setUTCMinutes(t.getUTCMinutes() + e), t.getTime();
1198
- }, ae = (n, e) => {
1199
- const t = new Date(n);
1200
- return t.setUTCHours(t.getUTCHours() + e), t.getTime();
1201
- }, le = (n, e) => {
1202
- const t = new Date(n);
1203
- return t.setUTCDate(t.getUTCDate() + e), t.getTime();
1204
- }, Mt = (n, e) => {
1205
- const t = new Date(n);
1206
- return t.setUTCMonth(t.getUTCMonth() + e), t.getTime();
1207
- }, K = (n, e) => {
1208
- const [t, s] = e;
1196
+ }, lt = (e, t) => {
1197
+ const n = new Date(e);
1198
+ return n.setUTCMilliseconds(n.getUTCMilliseconds() + t), n.getTime();
1199
+ }, ut = (e, t) => {
1200
+ const n = new Date(e);
1201
+ return n.setUTCSeconds(n.getUTCSeconds() + t), n.getTime();
1202
+ }, dt = (e, t) => {
1203
+ const n = new Date(e);
1204
+ return n.setUTCMinutes(n.getUTCMinutes() + t), n.getTime();
1205
+ }, ht = (e, t) => {
1206
+ const n = new Date(e);
1207
+ return n.setUTCHours(n.getUTCHours() + t), n.getTime();
1208
+ }, ft = (e, t) => {
1209
+ const n = new Date(e);
1210
+ return n.setUTCDate(n.getUTCDate() + t), n.getTime();
1211
+ }, Me = (e, t) => {
1212
+ const n = new Date(e);
1213
+ return n.setUTCMonth(n.getUTCMonth() + t), n.getTime();
1214
+ }, K = (e, t) => {
1215
+ const [n, s] = t;
1209
1216
  switch (s) {
1210
1217
  case "milliseconds":
1211
- return ie(n, t);
1218
+ return lt(e, n);
1212
1219
  case "seconds":
1213
- return re(n, t);
1220
+ return ut(e, n);
1214
1221
  case "minutes":
1215
- return ce(n, t);
1222
+ return dt(e, n);
1216
1223
  case "hours":
1217
- return ae(n, t);
1224
+ return ht(e, n);
1218
1225
  case "days":
1219
- return le(n, t);
1226
+ return ft(e, n);
1220
1227
  case "months":
1221
- return Mt(n, t);
1228
+ return Me(e, n);
1222
1229
  case "years":
1223
- return Mt(n, t * 12);
1230
+ return Me(e, n * 12);
1224
1231
  }
1225
1232
  };
1226
- function J(n, e) {
1227
- const t = new Date(n), s = new Date(t.toLocaleString("en-US", { timeZone: e })), o = new Date(t.toLocaleString("en-US", { timeZone: "UTC" }));
1233
+ function te(e, t) {
1234
+ const n = new Date(e), s = new Date(n.toLocaleString("en-US", { timeZone: t })), o = new Date(n.toLocaleString("en-US", { timeZone: "UTC" }));
1228
1235
  return (s.getTime() - o.getTime()) / (3600 * 1e3);
1229
1236
  }
1230
- const ue = (n, e, t = "UTC") => {
1231
- const [s, o] = e;
1232
- let i = new Date(n);
1237
+ const mt = (e, t, n = "UTC") => {
1238
+ const [s, o] = t;
1239
+ let i = new Date(e);
1233
1240
  const r = () => {
1234
- i.setUTCHours(-J(i, t), 0, 0, 0);
1241
+ i.setUTCHours(-te(i, n), 0, 0, 0);
1235
1242
  };
1236
1243
  switch (o) {
1237
1244
  case "milliseconds":
@@ -1247,14 +1254,14 @@ const ue = (n, e, t = "UTC") => {
1247
1254
  break;
1248
1255
  case "minutes":
1249
1256
  i.setUTCMinutes(
1250
- Math.ceil(i.getTime() % nt / wt / s) * s,
1257
+ Math.ceil(i.getTime() % se / xe / s) * s,
1251
1258
  0,
1252
1259
  0
1253
1260
  );
1254
1261
  break;
1255
1262
  case "hours":
1256
1263
  i.setUTCHours(
1257
- Math.ceil(i.getTime() % st / nt / s) * s,
1264
+ Math.ceil(i.getTime() % oe / se / s) * s,
1258
1265
  0,
1259
1266
  0,
1260
1267
  0
@@ -1263,37 +1270,37 @@ const ue = (n, e, t = "UTC") => {
1263
1270
  case "days":
1264
1271
  case "months":
1265
1272
  case "years":
1266
- o === "months" ? i.setUTCDate(1) : o === "years" && i.setUTCMonth(0, 1), r(), i.getTime() < n && (i = new Date(K(i, [1, o])));
1273
+ o === "months" ? i.setUTCDate(1) : o === "years" && i.setUTCMonth(0, 1), r(), i.getTime() < e && (i = new Date(K(i, [1, o])));
1267
1274
  break;
1268
1275
  }
1269
1276
  return i.getTime();
1270
- }, Ie = ({
1271
- timeZone: n = _t,
1272
- space: e = Dt,
1273
- formatter: t,
1277
+ }, Ft = ({
1278
+ timeZone: e = Ie,
1279
+ space: t = De,
1280
+ formatter: n,
1274
1281
  locale: s,
1275
1282
  showTimezone: o
1276
1283
  } = {}) => (i, r) => {
1277
- const { min: c, max: u } = i, d = Math.floor(r.chartAreaCanvasPX.width / e) + 1, a = (u - c) / d, [f, l] = oe.find(
1278
- (w) => Z(w) >= a
1279
- ) ?? [1, "milliseconds"], m = ue(c, [f, l], n), x = J(m, n), p = [m];
1280
- let v;
1284
+ const { min: c, max: a } = i, l = Math.floor(r.chartAreaCanvasPX.width / t) + 1, h = (a - c) / l, [m, u] = at.find(
1285
+ (w) => ee(w) >= h
1286
+ ) ?? [1, "milliseconds"], f = mt(c, [m, u], e), v = te(f, e), p = [f];
1287
+ let g;
1281
1288
  for (; ; ) {
1282
- switch (l) {
1289
+ switch (u) {
1283
1290
  case "milliseconds":
1284
1291
  case "seconds":
1285
1292
  case "minutes":
1286
1293
  case "hours": {
1287
- v = K(m, [p.length * f, l]);
1294
+ g = K(f, [p.length * m, u]);
1288
1295
  break;
1289
1296
  }
1290
1297
  case "days": {
1291
- const w = K(m, [
1292
- p.length * f,
1293
- l
1298
+ const w = K(f, [
1299
+ p.length * m,
1300
+ u
1294
1301
  ]);
1295
- v = K(w, [
1296
- x - J(w, n),
1302
+ g = K(w, [
1303
+ v - te(w, e),
1297
1304
  "hours"
1298
1305
  ]);
1299
1306
  break;
@@ -1301,34 +1308,34 @@ const ue = (n, e, t = "UTC") => {
1301
1308
  case "months":
1302
1309
  case "years": {
1303
1310
  const w = K(
1304
- K(K(m, [x, "hours"]), [
1305
- p.length * f,
1306
- l
1311
+ K(K(f, [v, "hours"]), [
1312
+ p.length * m,
1313
+ u
1307
1314
  ]),
1308
- [-x, "hours"]
1315
+ [-v, "hours"]
1309
1316
  );
1310
- v = K(w, [
1311
- x - J(w, n),
1317
+ g = K(w, [
1318
+ v - te(w, e),
1312
1319
  "hours"
1313
1320
  ]);
1314
1321
  break;
1315
1322
  }
1316
1323
  }
1317
- if (v > u)
1324
+ if (g > a)
1318
1325
  break;
1319
- p.push(v);
1326
+ p.push(g);
1320
1327
  }
1321
- return (t ?? de({
1328
+ return (n ?? pt({
1322
1329
  locale: s,
1323
1330
  showTimezone: o,
1324
- timeZone: n
1331
+ timeZone: e
1325
1332
  }))(p);
1326
- }, X = (n, e, t) => n.find((s) => s.type === t)?.value !== e.find((s) => s.type === t)?.value, de = ({
1327
- timeZone: n = _t,
1328
- locale: e = Qt,
1329
- showTimezone: t = !0
1333
+ }, F = (e, t, n) => e.find((s) => s.type === n)?.value !== t.find((s) => s.type === n)?.value, pt = ({
1334
+ timeZone: e = Ie,
1335
+ locale: t = st,
1336
+ showTimezone: n = !0
1330
1337
  }) => {
1331
- const s = new Intl.DateTimeFormat(e, {
1338
+ const s = new Intl.DateTimeFormat(t, {
1332
1339
  year: "numeric",
1333
1340
  day: "numeric",
1334
1341
  month: "short",
@@ -1338,73 +1345,74 @@ const ue = (n, e, t = "UTC") => {
1338
1345
  second: "numeric",
1339
1346
  fractionalSecondDigits: 3,
1340
1347
  timeZoneName: "short",
1341
- timeZone: n
1348
+ timeZone: e
1342
1349
  });
1343
1350
  return (o) => {
1344
- const i = o[1] - o[0], r = i < Z([1, "days"]), c = i < Z([1, "minutes"]), u = i < Z([1, "seconds"]);
1345
- return o.map((d) => ({ value: d, label: s.formatToParts(new Date(d)) })).map((d, h, a) => {
1346
- const f = a[h - 1], l = h === 0 || X(d.label, f.label, "year"), m = h === 0 || X(d.label, f.label, "day"), x = h === 0 || X(d.label, f.label, "month"), p = h === 0 || X(d.label, f.label, "hour"), v = h === 0 || X(d.label, f.label, "timeZoneName"), w = h === 0 || X(d.label, f.label, "minute"), b = h === 0 || X(d.label, f.label, "second"), S = h === 0 || X(d.label, f.label, "fractionalSecond"), y = [];
1347
- if (r && (p || w || v || b || S)) {
1348
- const g = d.label.find((M) => M.type === "hour")?.value, P = d.label.find((M) => M.type === "minute")?.value, C = d.label.find((M) => M.type === "timeZoneName")?.value;
1349
- let T = "";
1351
+ const i = o[1] - o[0], r = i < ee([1, "days"]), c = i < ee([1, "minutes"]), a = i < ee([1, "seconds"]);
1352
+ return o.map((l) => ({ value: l, label: s.formatToParts(new Date(l)) })).map((l, d, h) => {
1353
+ const m = h[d - 1], u = d === 0 || F(l.label, m.label, "year"), f = d === 0 || F(l.label, m.label, "day"), v = d === 0 || F(l.label, m.label, "month"), p = d === 0 || F(l.label, m.label, "hour"), g = d === 0 || F(l.label, m.label, "timeZoneName"), w = d === 0 || F(l.label, m.label, "minute"), T = d === 0 || F(l.label, m.label, "second"), b = d === 0 || F(l.label, m.label, "fractionalSecond"), y = [];
1354
+ if (r && (p || w || g || T || b)) {
1355
+ const x = l.label.find((P) => P.type === "hour")?.value, S = l.label.find((P) => P.type === "minute")?.value, E = l.label.find((P) => P.type === "timeZoneName")?.value;
1356
+ let C = "";
1350
1357
  if (c) {
1351
- const M = d.label.find((O) => O.type === "second")?.value, R = d.label.find(
1352
- (O) => O.type === "fractionalSecond"
1358
+ const P = l.label.find((Y) => Y.type === "second")?.value, R = l.label.find(
1359
+ (Y) => Y.type === "fractionalSecond"
1353
1360
  )?.value;
1354
- T = `:${M}` + (u ? `.${R}` : "");
1361
+ C = `:${P}` + (a ? `.${R}` : "");
1355
1362
  }
1356
1363
  y.push(
1357
- `${g}:${P}${T}` + (t && v ? ` ${C}` : "")
1364
+ `${x}:${S}${C}` + (n && g ? ` ${E}` : "")
1358
1365
  );
1359
1366
  }
1360
- return (m || x) && y.push(
1367
+ return (f || v) && y.push(
1361
1368
  [
1362
- d.label.find((g) => g.type === "month")?.value,
1363
- m && d.label.find((g) => g.type === "day")?.value
1369
+ l.label.find((x) => x.type === "month")?.value,
1370
+ f && l.label.find((x) => x.type === "day")?.value
1364
1371
  ].filter(Boolean).join(" ")
1365
- ), l && y.push(d.label.find((g) => g.type === "year")?.value), {
1366
- value: d.value,
1367
- label: y.filter((g) => g).join(`
1372
+ ), u && y.push(l.label.find((x) => x.type === "year")?.value), {
1373
+ value: l.value,
1374
+ label: y.filter((x) => x).join(`
1368
1375
  `)
1369
1376
  };
1370
1377
  });
1371
1378
  };
1372
1379
  };
1373
1380
  export {
1374
- Se as AreaPlot,
1375
- De as AxisOverlay,
1376
- be as BarPlot,
1377
- ht as CANPLOT_LAYER,
1378
- ve as CanPlot,
1379
- Pe as ChartAreaInteractions,
1380
- ke as Crosshair,
1381
- ge as LinePlot,
1382
- we as ScatterPlot,
1383
- Ae as SelectBox,
1384
- Te as SparklinePlot,
1385
- Re as TooltipsX,
1386
- Me as XTicks,
1387
- Ee as YTicks,
1388
- _ as applyStyles,
1389
- j as clamp,
1390
- ye as clampUnfit,
1391
- B as clampXPosToChartArea,
1392
- N as clampYPosToChartArea,
1393
- te as defaultNumericalTicksFormatter,
1394
- xe as findClosestIndex,
1395
- U as getScale,
1396
- _e as makeLinearTicks,
1397
- de as makeTimeTickFormat,
1398
- Ie as makeTimeTicks,
1399
- L as posToVal,
1400
- zt as pxToValDistance,
1401
- pe as sum,
1402
- z as useDrawEffect,
1403
- yt as useFrameState,
1404
- gt as useInteractionsEvent,
1405
- Ce as useXPositioned,
1406
- dt as valFits,
1407
- H as valToPos,
1408
- pt as valToPxDistance
1381
+ Mt as AreaPlot,
1382
+ _t as AxisOverlay,
1383
+ Pt as BarPlot,
1384
+ ke as CANPLOT_LAYER,
1385
+ Tt as CanPlot,
1386
+ Dt as ChartAreaInteractions,
1387
+ Lt as Crosshair,
1388
+ Ae as FrameDrawer,
1389
+ St as LinePlot,
1390
+ Ct as ScatterPlot,
1391
+ Ut as SelectBox,
1392
+ Et as SparklinePlot,
1393
+ It as TooltipsX,
1394
+ kt as XTicks,
1395
+ At as YTicks,
1396
+ L as applyStyles,
1397
+ W as clamp,
1398
+ xt as clampUnfit,
1399
+ $ as clampXPosToChartArea,
1400
+ V as clampYPosToChartArea,
1401
+ ot as defaultNumericalTicksFormatter,
1402
+ bt as findClosestIndex,
1403
+ _ as getScale,
1404
+ Xt as makeLinearTicks,
1405
+ pt as makeTimeTickFormat,
1406
+ Ft as makeTimeTicks,
1407
+ U as posToVal,
1408
+ $e as pxToValDistance,
1409
+ wt as sum,
1410
+ N as useDrawEffect,
1411
+ ge as useFrameState,
1412
+ be as useInteractionsEvent,
1413
+ Rt as useXPositioned,
1414
+ he as valFits,
1415
+ q as valToPos,
1416
+ ye as valToPxDistance
1409
1417
  };
1410
1418
  //# sourceMappingURL=canplot.mjs.map