@canplot/react 0.5.10 → 0.5.11
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.cjs +4 -4
- package/dist/canplot.cjs.map +1 -1
- package/dist/canplot.mjs +55 -51
- package/dist/canplot.mjs.map +1 -1
- package/dist/tickUtils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/canplot.mjs
CHANGED
|
@@ -2,8 +2,8 @@ var Be = Object.defineProperty;
|
|
|
2
2
|
var ze = (e, t, n) => t in e ? Be(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var K = (e, t, n) => ze(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
4
|
import { jsxs as pe, jsx as R, Fragment as Ne } from "react/jsx-runtime";
|
|
5
|
-
import D, { version as $e, createContext as ye, forwardRef as je, useRef as
|
|
6
|
-
const re = (e, t, n) => Math.min(Math.max(e, t), n),
|
|
5
|
+
import D, { version as $e, createContext as ye, forwardRef as je, useRef as A, useState as B, useMemo as Q, useLayoutEffect as $, useCallback as He, useContext as G, useEffect as Ae, useId as Ve } from "react";
|
|
6
|
+
const re = (e, t, n) => Math.min(Math.max(e, t), n), At = (e) => e.reduce((t, n) => t + (n ?? 0), 0), Rt = (e, t) => {
|
|
7
7
|
let n = 0;
|
|
8
8
|
for (let s = 0; s < e.length; s++)
|
|
9
9
|
Math.abs(e[s] - t) < Math.abs(e[n] - t) && (n = s);
|
|
@@ -14,7 +14,7 @@ const re = (e, t, n) => Math.min(Math.max(e, t), n), kt = (e) => e.reduce((t, n)
|
|
|
14
14
|
return null;
|
|
15
15
|
const i = s === "canvas" ? e.chartAreaCanvasPX : e.chartAreaCSS, r = (o.origin === "x" ? i.width : i.height) / (o.max - o.min);
|
|
16
16
|
return t / r;
|
|
17
|
-
}, F = (e, t) => e.scales.find((n) => n.id === t) ?? null,
|
|
17
|
+
}, F = (e, t) => e.scales.find((n) => n.id === t) ?? null, _ = (e, t) => {
|
|
18
18
|
const n = window.devicePixelRatio || 1;
|
|
19
19
|
e.lineCap = t?.lineCap ?? "butt", e.lineDashOffset = n * (t?.lineDashOffset ?? 0), e.lineJoin = t?.lineJoin ?? "miter", e.lineWidth = n * (t?.lineWidth ?? 1), e.miterLimit = n * (t?.miterLimit ?? 10), e.strokeStyle = t?.strokeStyle ?? "black", e.fillStyle = t?.fillStyle ?? e.strokeStyle, e.font = t?.font ?? `${10 * n}px sans-serif`, e.textAlign = t?.textAlign ?? "start", e.direction = t?.direction ?? "inherit", e.textBaseline = t?.textBaseline ?? "alphabetic", e.fontKerning = t?.fontKerning ?? "auto";
|
|
20
20
|
}, ge = (e, t, n, s) => {
|
|
@@ -81,7 +81,7 @@ const re = (e, t, n) => Math.min(Math.max(e, t), n), kt = (e) => e.reduce((t, n)
|
|
|
81
81
|
const { ctx: t, scales: n } = e;
|
|
82
82
|
for (const s of n) {
|
|
83
83
|
if (!s.axis) continue;
|
|
84
|
-
t.save(),
|
|
84
|
+
t.save(), _(t, {
|
|
85
85
|
strokeStyle: "black",
|
|
86
86
|
fillStyle: "black",
|
|
87
87
|
lineWidth: 1,
|
|
@@ -170,7 +170,7 @@ class Le {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
173
|
-
const i =
|
|
173
|
+
const i = A(null), r = A(null), c = tt(r), [u, l] = B(null), p = Q(
|
|
174
174
|
() => nt(e, c, u),
|
|
175
175
|
[e, c, u]
|
|
176
176
|
);
|
|
@@ -216,7 +216,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
216
216
|
$(() => {
|
|
217
217
|
e?.ctx.clearRect(0, 0, e.ctx.canvas.width, e.ctx.canvas.height);
|
|
218
218
|
}, [e, s]);
|
|
219
|
-
const i =
|
|
219
|
+
const i = A(null);
|
|
220
220
|
i.current = e, $(() => {
|
|
221
221
|
n.subscribe(() => {
|
|
222
222
|
i.current && qe(i.current);
|
|
@@ -355,9 +355,9 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
355
355
|
throw new Error("useFrame must be used within a CanPlot component");
|
|
356
356
|
const [r] = B(() => new Le());
|
|
357
357
|
r._updateFrame(s);
|
|
358
|
-
const c =
|
|
358
|
+
const c = A(r);
|
|
359
359
|
c.current = r;
|
|
360
|
-
const u =
|
|
360
|
+
const u = A(t);
|
|
361
361
|
u.current = t, $(() => {
|
|
362
362
|
const l = i.subscribe(
|
|
363
363
|
() => {
|
|
@@ -370,7 +370,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
370
370
|
};
|
|
371
371
|
}, [i, e, r]), $(() => {
|
|
372
372
|
o();
|
|
373
|
-
}, [o, ...n]),
|
|
373
|
+
}, [o, ...n]), Ae(() => () => {
|
|
374
374
|
o();
|
|
375
375
|
}, [o]);
|
|
376
376
|
}, Ue = () => {
|
|
@@ -384,7 +384,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
384
384
|
}, st = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o, globalAlpha: i }) => (j(
|
|
385
385
|
e,
|
|
386
386
|
({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: u, valToPos: l }) => {
|
|
387
|
-
r.save(), r.beginPath(),
|
|
387
|
+
r.save(), r.beginPath(), _(r, o), i !== void 0 && (r.globalAlpha = i);
|
|
388
388
|
for (const p of t) {
|
|
389
389
|
const f = c(l(p.x, n, "canvas")), a = u(l(p.y, s, "canvas"));
|
|
390
390
|
f === null || a === null || r.lineTo(f, a);
|
|
@@ -411,7 +411,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
411
411
|
clampXPosToChartArea: a,
|
|
412
412
|
clampYPosToChartArea: g
|
|
413
413
|
}) => {
|
|
414
|
-
l.save(),
|
|
414
|
+
l.save(), _(l, c), u !== void 0 && (l.globalAlpha = u);
|
|
415
415
|
const d = [];
|
|
416
416
|
for (const y of t) {
|
|
417
417
|
let h = null, m = null;
|
|
@@ -489,7 +489,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
489
489
|
height: w
|
|
490
490
|
});
|
|
491
491
|
}
|
|
492
|
-
if (l.save(),
|
|
492
|
+
if (l.save(), _(l, s), r !== void 0 && (l.globalAlpha = r), s?.fillStyle)
|
|
493
493
|
for (const m of h)
|
|
494
494
|
l.beginPath(), c ? l.roundRect(m.x, m.y, m.width, m.height, c) : l.rect(m.x, m.y, m.width, m.height), l.fill();
|
|
495
495
|
if (s?.strokeStyle) {
|
|
@@ -517,7 +517,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
517
517
|
}
|
|
518
518
|
const p = l[0];
|
|
519
519
|
if (p) {
|
|
520
|
-
i.save(), i.beginPath(),
|
|
520
|
+
i.save(), i.beginPath(), _(i, o), i.moveTo(p.x, p.y);
|
|
521
521
|
for (const f of l)
|
|
522
522
|
i.lineTo(f.x, f.y);
|
|
523
523
|
i.closePath(), i.fill(), i.restore();
|
|
@@ -537,7 +537,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
537
537
|
return;
|
|
538
538
|
const g = u(l(0, o));
|
|
539
539
|
if (g !== null) {
|
|
540
|
-
r.save(), r.beginPath(),
|
|
540
|
+
r.save(), r.beginPath(), _(r, i), r.moveTo(f.x, g);
|
|
541
541
|
for (const d of p)
|
|
542
542
|
r.lineTo(d.x, d.y);
|
|
543
543
|
if (r.lineTo(a.x, g), r.closePath(), r.fill(), n) {
|
|
@@ -564,7 +564,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
564
564
|
const f = l(t);
|
|
565
565
|
if (!f || !f.axis || f.origin !== "x") return;
|
|
566
566
|
const a = f.axis, g = a.position === "top" ? a.canvasRect.y + a.canvasRect.height : a.canvasRect.y, d = window.devicePixelRatio || 1, y = g, h = (i ?? 6) * d, m = a.position === "top" ? g - h : g + h, v = (o ?? 12) * d;
|
|
567
|
-
c.save(), c.fontKerning = "auto",
|
|
567
|
+
c.save(), c.fontKerning = "auto", _(c, {
|
|
568
568
|
...n
|
|
569
569
|
}), c.beginPath();
|
|
570
570
|
const x = Array.isArray(r) ? r : r({ ...f, axis: a }, p);
|
|
@@ -572,7 +572,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
572
572
|
const w = u(T, t, "canvas");
|
|
573
573
|
w !== null && (c.moveTo(w, y), c.lineTo(w, m));
|
|
574
574
|
}
|
|
575
|
-
c.stroke(), c.restore(), c.save(),
|
|
575
|
+
c.stroke(), c.restore(), c.save(), _(c, {
|
|
576
576
|
textBaseline: a.position === "top" ? "bottom" : "top",
|
|
577
577
|
textAlign: "center",
|
|
578
578
|
...n,
|
|
@@ -606,12 +606,12 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
606
606
|
const f = l(t);
|
|
607
607
|
if (!f || !f.axis || f.origin !== "y") return;
|
|
608
608
|
const a = f.axis, g = a.position === "left" ? a.canvasRect.x + a.canvasRect.width : a.canvasRect.x, d = g, y = i ?? 6, h = a.position === "left" ? g - y : g + y, m = o ?? 12, v = Array.isArray(r) ? r : r({ ...f, axis: a }, p);
|
|
609
|
-
c.save(), c.fontKerning = "auto",
|
|
609
|
+
c.save(), c.fontKerning = "auto", _(c, { ...n }), c.beginPath();
|
|
610
610
|
for (const { value: x } of v) {
|
|
611
611
|
const T = u(x, t, "canvas");
|
|
612
612
|
T !== null && (c.moveTo(d, T), c.lineTo(h, T));
|
|
613
613
|
}
|
|
614
|
-
c.stroke(), c.restore(), c.save(),
|
|
614
|
+
c.stroke(), c.restore(), c.save(), _(c, {
|
|
615
615
|
textBaseline: "middle",
|
|
616
616
|
textAlign: a.position === "left" ? "right" : "left",
|
|
617
617
|
...n,
|
|
@@ -777,9 +777,9 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
777
777
|
g
|
|
778
778
|
] });
|
|
779
779
|
}, ht = ({ id: e, className: t, style: n, sync: s, children: o }) => {
|
|
780
|
-
const i =
|
|
780
|
+
const i = A(null), r = Ue().frame, c = A(r);
|
|
781
781
|
c.current = r;
|
|
782
|
-
const u = G(we), l = s?.key || u, p =
|
|
782
|
+
const u = G(we), l = s?.key || u, p = A(null), f = A(null), a = A(null), g = () => {
|
|
783
783
|
const h = i.current?.parentElement;
|
|
784
784
|
if (h) {
|
|
785
785
|
if (h.dataset.canplotroot === void 0)
|
|
@@ -806,8 +806,8 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
806
806
|
metaKey: h.metaKey
|
|
807
807
|
}
|
|
808
808
|
);
|
|
809
|
-
}, y =
|
|
810
|
-
return y.current = d,
|
|
809
|
+
}, y = A(d);
|
|
810
|
+
return y.current = d, Ae(() => {
|
|
811
811
|
const h = (w) => {
|
|
812
812
|
const b = f.current;
|
|
813
813
|
b && M.spanselect.dispatchEvent(u, {
|
|
@@ -849,9 +849,9 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
849
849
|
(b, { cssX: S, cssY: E }, C) => {
|
|
850
850
|
const P = p.current;
|
|
851
851
|
if (!P || !b.x || !b.y) return;
|
|
852
|
-
const
|
|
852
|
+
const k = c.current, z = P.xRangeCss.start, ae = S, le = P.yRangeCss.start, ue = E, ee = F(k, b.x.scaleId);
|
|
853
853
|
if (!ee) return;
|
|
854
|
-
const te = F(
|
|
854
|
+
const te = F(k, b.y.scaleId);
|
|
855
855
|
if (!te) return;
|
|
856
856
|
p.current = {
|
|
857
857
|
xRangeCss: { start: z, end: ae },
|
|
@@ -861,28 +861,28 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
861
861
|
const he = Math.abs(le - ue), fe = Math.abs(z - ae);
|
|
862
862
|
he < 10 && fe < 10 ? q = "below_threshold" : he > 30 && fe > 30 ? q = "box" : he > fe ? q = "y" : q = "x";
|
|
863
863
|
const Te = X(
|
|
864
|
-
|
|
864
|
+
k,
|
|
865
865
|
V(c.current, z, "css"),
|
|
866
866
|
ee.id,
|
|
867
867
|
"css"
|
|
868
868
|
);
|
|
869
869
|
if (Te === null) return;
|
|
870
870
|
const Se = X(
|
|
871
|
-
|
|
871
|
+
k,
|
|
872
872
|
V(c.current, ae, "css"),
|
|
873
873
|
ee.id,
|
|
874
874
|
"css"
|
|
875
875
|
);
|
|
876
876
|
if (Se === null) return;
|
|
877
877
|
const Ce = X(
|
|
878
|
-
|
|
878
|
+
k,
|
|
879
879
|
W(c.current, le, "css"),
|
|
880
880
|
te.id,
|
|
881
881
|
"css"
|
|
882
882
|
);
|
|
883
883
|
if (Ce === null) return;
|
|
884
884
|
const Pe = X(
|
|
885
|
-
|
|
885
|
+
k,
|
|
886
886
|
W(c.current, ue, "css"),
|
|
887
887
|
te.id,
|
|
888
888
|
"css"
|
|
@@ -929,16 +929,16 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
|
|
|
929
929
|
c.current
|
|
930
930
|
);
|
|
931
931
|
if (!C) return;
|
|
932
|
-
if (Object.values(E).some((
|
|
932
|
+
if (Object.values(E).some((k) => k)) {
|
|
933
933
|
w.preventDefault();
|
|
934
|
-
const
|
|
934
|
+
const k = Math.abs(w.deltaY) > Math.abs(w.deltaX) ? w.deltaY : w.deltaX;
|
|
935
935
|
M.pressandwheel.dispatchEvent(u, {
|
|
936
936
|
pointer: C,
|
|
937
937
|
frame: c.current,
|
|
938
938
|
keys: E,
|
|
939
939
|
deltaX: w.deltaX,
|
|
940
940
|
deltaY: w.deltaY,
|
|
941
|
-
deltaAbs:
|
|
941
|
+
deltaAbs: k
|
|
942
942
|
});
|
|
943
943
|
}
|
|
944
944
|
});
|
|
@@ -1331,10 +1331,10 @@ const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, J = 60 * be, ce = 24 * J, yt = 30 * c
|
|
|
1331
1331
|
}, St = (e, t) => {
|
|
1332
1332
|
const n = new Date(e);
|
|
1333
1333
|
return n.setUTCDate(n.getUTCDate() + t), n.getTime();
|
|
1334
|
-
},
|
|
1334
|
+
}, ke = (e, t) => {
|
|
1335
1335
|
const n = new Date(e);
|
|
1336
1336
|
return n.setUTCMonth(n.getUTCMonth() + t), n.getTime();
|
|
1337
|
-
},
|
|
1337
|
+
}, U = (e, t) => {
|
|
1338
1338
|
const [n, s] = t;
|
|
1339
1339
|
switch (s) {
|
|
1340
1340
|
case "milliseconds":
|
|
@@ -1348,9 +1348,9 @@ const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, J = 60 * be, ce = 24 * J, yt = 30 * c
|
|
|
1348
1348
|
case "days":
|
|
1349
1349
|
return St(e, n);
|
|
1350
1350
|
case "months":
|
|
1351
|
-
return
|
|
1351
|
+
return ke(e, n);
|
|
1352
1352
|
case "years":
|
|
1353
|
-
return
|
|
1353
|
+
return ke(e, n * 12);
|
|
1354
1354
|
}
|
|
1355
1355
|
};
|
|
1356
1356
|
function H(e, t) {
|
|
@@ -1394,10 +1394,16 @@ const Ct = (e, t, n = "UTC") => {
|
|
|
1394
1394
|
);
|
|
1395
1395
|
break;
|
|
1396
1396
|
}
|
|
1397
|
-
case "days":
|
|
1397
|
+
case "days": {
|
|
1398
|
+
for (r(), i.setUTCDate(
|
|
1399
|
+
1
|
|
1400
|
+
); i.getTime() < e; )
|
|
1401
|
+
i = new Date(U(i, [s, o]));
|
|
1402
|
+
break;
|
|
1403
|
+
}
|
|
1398
1404
|
case "months":
|
|
1399
1405
|
case "years":
|
|
1400
|
-
o === "months" ? i.setUTCDate(1) : o === "years" && i.setUTCMonth(0, 1), r(), i.getTime() < e && (i = new Date(
|
|
1406
|
+
o === "months" ? i.setUTCDate(1) : o === "years" && i.setUTCMonth(0, 1), r(), i.getTime() < e && (i = new Date(U(i, [1, o])));
|
|
1401
1407
|
break;
|
|
1402
1408
|
}
|
|
1403
1409
|
return i.getTime();
|
|
@@ -1416,9 +1422,7 @@ const Ct = (e, t, n = "UTC") => {
|
|
|
1416
1422
|
) ?? [1, "milliseconds"];
|
|
1417
1423
|
if (!a || !g)
|
|
1418
1424
|
return [];
|
|
1419
|
-
const d = Ct(c, [a, g], e), y = H(d, e);
|
|
1420
|
-
console.log(y, new Date(d));
|
|
1421
|
-
const h = [d];
|
|
1425
|
+
const d = Ct(c, [a, g], e), y = H(d, e), h = [d];
|
|
1422
1426
|
let m;
|
|
1423
1427
|
for (; ; ) {
|
|
1424
1428
|
if (h.length > 100)
|
|
@@ -1428,22 +1432,22 @@ const Ct = (e, t, n = "UTC") => {
|
|
|
1428
1432
|
case "seconds":
|
|
1429
1433
|
case "minutes":
|
|
1430
1434
|
case "hours": {
|
|
1431
|
-
const v =
|
|
1435
|
+
const v = U(d, [
|
|
1432
1436
|
h.length * a,
|
|
1433
1437
|
g
|
|
1434
1438
|
]);
|
|
1435
|
-
m =
|
|
1439
|
+
m = U(v, [
|
|
1436
1440
|
y - H(v, e),
|
|
1437
1441
|
"hours"
|
|
1438
1442
|
]);
|
|
1439
1443
|
break;
|
|
1440
1444
|
}
|
|
1441
1445
|
case "days": {
|
|
1442
|
-
const v =
|
|
1446
|
+
const v = U(d, [
|
|
1443
1447
|
h.length * a,
|
|
1444
1448
|
g
|
|
1445
1449
|
]);
|
|
1446
|
-
m =
|
|
1450
|
+
m = U(v, [
|
|
1447
1451
|
y - H(v, e),
|
|
1448
1452
|
"hours"
|
|
1449
1453
|
]);
|
|
@@ -1451,14 +1455,14 @@ const Ct = (e, t, n = "UTC") => {
|
|
|
1451
1455
|
}
|
|
1452
1456
|
case "months":
|
|
1453
1457
|
case "years": {
|
|
1454
|
-
const v =
|
|
1455
|
-
|
|
1458
|
+
const v = U(
|
|
1459
|
+
U(U(d, [y, "hours"]), [
|
|
1456
1460
|
h.length * a,
|
|
1457
1461
|
g
|
|
1458
1462
|
]),
|
|
1459
1463
|
[-y, "hours"]
|
|
1460
1464
|
);
|
|
1461
|
-
m =
|
|
1465
|
+
m = U(v, [
|
|
1462
1466
|
y - H(v, e),
|
|
1463
1467
|
"hours"
|
|
1464
1468
|
]);
|
|
@@ -1499,10 +1503,10 @@ const Ct = (e, t, n = "UTC") => {
|
|
|
1499
1503
|
const b = l.label.find((P) => P.type === "hour")?.value, S = l.label.find((P) => P.type === "minute")?.value, E = l.label.find((P) => P.type === "timeZoneName")?.value;
|
|
1500
1504
|
let C = "";
|
|
1501
1505
|
if (c) {
|
|
1502
|
-
const P = l.label.find((z) => z.type === "second")?.value,
|
|
1506
|
+
const P = l.label.find((z) => z.type === "second")?.value, k = l.label.find(
|
|
1503
1507
|
(z) => z.type === "fractionalSecond"
|
|
1504
1508
|
)?.value;
|
|
1505
|
-
C = `:${P}` + (u ? `.${
|
|
1509
|
+
C = `:${P}` + (u ? `.${k}` : "");
|
|
1506
1510
|
}
|
|
1507
1511
|
w.push(
|
|
1508
1512
|
`${b}:${S}${C}` + (n && m ? ` ${E}` : "")
|
|
@@ -1537,7 +1541,7 @@ export {
|
|
|
1537
1541
|
Yt as TooltipsX,
|
|
1538
1542
|
Ft as XTicks,
|
|
1539
1543
|
Ot as YTicks,
|
|
1540
|
-
|
|
1544
|
+
_ as applyStyles,
|
|
1541
1545
|
re as clamp,
|
|
1542
1546
|
V as clampXPosToChartArea,
|
|
1543
1547
|
W as clampYPosToChartArea,
|
|
@@ -1550,7 +1554,7 @@ export {
|
|
|
1550
1554
|
jt as makeTimeTicks,
|
|
1551
1555
|
X as posToVal,
|
|
1552
1556
|
We as pxToValDistance,
|
|
1553
|
-
|
|
1557
|
+
At as sum,
|
|
1554
1558
|
j as useDrawEffect,
|
|
1555
1559
|
Ue as useFrameState,
|
|
1556
1560
|
xe as useInteractionsEvent,
|