@canplot/react 0.1.15 → 0.1.16

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