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