@canplot/react 0.4.0 → 0.5.1

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