@canplot/react 0.1.3 → 0.1.4

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