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