@canplot/react 0.1.4 → 0.1.6

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