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