@canplot/react 0.1.3 → 0.1.5

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