@canplot/react 0.5.11 → 0.5.12

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,9 +1,9 @@
1
1
  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
- 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 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) => {
4
+ import { jsxs as pe, jsx as A, Fragment as Ne } from "react/jsx-runtime";
5
+ import R, { version as $e, createContext as ye, forwardRef as je, useRef as k, useState as B, useMemo as Q, useLayoutEffect as $, useCallback as He, useContext as G, useEffect as ke, useId as Ve } from "react";
6
+ const re = (e, t, n) => Math.min(Math.max(e, t), n), kt = (e) => e.reduce((t, n) => t + (n ?? 0), 0), At = (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);
@@ -125,7 +125,7 @@ function me(e, t) {
125
125
  e && (e.current = t);
126
126
  }
127
127
  var Ze = parseInt($e.split(".")[0], 10) >= 19 ? Je : Ge;
128
- const Re = ye({
128
+ const Ae = ye({
129
129
  listeners: [],
130
130
  subscribe: () => () => {
131
131
  },
@@ -140,7 +140,7 @@ const Re = ye({
140
140
  for (const [, s] of e)
141
141
  s();
142
142
  } };
143
- }, ve = ye(null), De = ye(() => {
143
+ }, ve = ye(null), Re = ye(() => {
144
144
  }), Ie = {
145
145
  TOP: 400,
146
146
  MIDDLE: 300,
@@ -169,8 +169,8 @@ class Le {
169
169
  return this.frame.ctx;
170
170
  }
171
171
  }
172
- const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
173
- const i = A(null), r = A(null), c = tt(r), [u, l] = B(null), p = Q(
172
+ const Rt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
173
+ const i = k(null), r = k(null), c = tt(r), [u, l] = B(null), p = Q(
174
174
  () => nt(e, c, u),
175
175
  [e, c, u]
176
176
  );
@@ -190,7 +190,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
190
190
  "data-canplotroot": !0,
191
191
  ...s,
192
192
  children: [
193
- /* @__PURE__ */ R(
193
+ /* @__PURE__ */ A(
194
194
  "canvas",
195
195
  {
196
196
  ref: i,
@@ -204,7 +204,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
204
204
  }
205
205
  }
206
206
  ),
207
- p && /* @__PURE__ */ R(et, { frame: p, children: t })
207
+ p && /* @__PURE__ */ A(et, { frame: p, children: t })
208
208
  ]
209
209
  }
210
210
  );
@@ -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 = A(null);
219
+ const i = k(null);
220
220
  i.current = e, $(() => {
221
221
  n.subscribe(() => {
222
222
  i.current && qe(i.current);
@@ -232,7 +232,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
232
232
  const r = He(() => {
233
233
  o((c) => c + 1);
234
234
  }, [o]);
235
- return /* @__PURE__ */ R(Re.Provider, { value: n, children: /* @__PURE__ */ R(De.Provider, { value: r, children: /* @__PURE__ */ R(ve.Provider, { value: e, children: t }) }) });
235
+ return /* @__PURE__ */ A(Ae.Provider, { value: n, children: /* @__PURE__ */ A(Re.Provider, { value: r, children: /* @__PURE__ */ A(ve.Provider, { value: e, children: t }) }) });
236
236
  }, tt = (e) => {
237
237
  const [t, n] = B({
238
238
  width: 0,
@@ -350,14 +350,14 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
350
350
  chartAreaCanvasPX: i
351
351
  };
352
352
  }, j = (e, t, n) => {
353
- const s = G(ve), o = G(De), i = G(Re);
353
+ const s = G(ve), o = G(Re), i = G(Ae);
354
354
  if (!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 = A(r);
358
+ const c = k(r);
359
359
  c.current = r;
360
- const u = A(t);
360
+ const u = k(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]), Ae(() => () => {
373
+ }, [o, ...n]), ke(() => () => {
374
374
  o();
375
375
  }, [o]);
376
376
  }, Ue = () => {
@@ -384,15 +384,17 @@ 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(), _(r, o), i !== void 0 && (r.globalAlpha = i);
388
- for (const p of t) {
389
- const f = c(l(p.x, n, "canvas")), a = u(l(p.y, s, "canvas"));
390
- f === null || a === null || r.lineTo(f, a);
387
+ r.save(), r.beginPath(), _(r, o);
388
+ const p = r.getLineDash();
389
+ o?.lineDash && r.setLineDash(o.lineDash), i !== void 0 && (r.globalAlpha = i);
390
+ for (const f of t) {
391
+ const a = c(l(f.x, n, "canvas")), g = u(l(f.y, s, "canvas"));
392
+ a === null || g === null || r.lineTo(a, g);
391
393
  }
392
- r.stroke(), r.restore();
394
+ r.stroke(), p && r.setLineDash(p), r.restore();
393
395
  },
394
396
  [t, n, s, o, i]
395
- ), null), It = D.memo(st, O), ot = ({
397
+ ), null), It = R.memo(st, O), ot = ({
396
398
  layer: e = "MIDDLE",
397
399
  data: t,
398
400
  xScaleId: n,
@@ -444,7 +446,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
444
446
  l.restore();
445
447
  },
446
448
  [t, n, s, r, c, u]
447
- ), null), Lt = D.memo(ot, O), it = ({
449
+ ), null), Lt = R.memo(ot, O), it = ({
448
450
  data: e,
449
451
  xScaleId: t,
450
452
  yScaleId: n,
@@ -501,7 +503,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
501
503
  l.restore();
502
504
  },
503
505
  [e, t, n, s, o, i, c, r]
504
- ), null), Ut = D.memo(it, O), rt = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (j(
506
+ ), null), Ut = R.memo(it, O), rt = ({ layer: e = "MIDDLE", data: t, xScaleId: n, yScaleId: s, style: o }) => (j(
505
507
  e,
506
508
  ({ ctx: i, clampXPosToChartArea: r, clampYPosToChartArea: c, valToPos: u }) => {
507
509
  const l = [];
@@ -524,7 +526,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
524
526
  }
525
527
  },
526
528
  [t, n, s, o]
527
- ), null), _t = D.memo(rt, O), ct = ({ layer: e = "MIDDLE", data: t, stroked: n, xScaleId: s, yScaleId: o, style: i }) => (j(
529
+ ), null), _t = R.memo(rt, O), ct = ({ layer: e = "MIDDLE", data: t, stroked: n, xScaleId: s, yScaleId: o, style: i }) => (j(
528
530
  e,
529
531
  ({ ctx: r, clampXPosToChartArea: c, clampYPosToChartArea: u, valToPos: l }) => {
530
532
  const p = [];
@@ -550,7 +552,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
550
552
  }
551
553
  },
552
554
  [t, n, s, o, i]
553
- ), null), Xt = D.memo(ct, O), at = ({
555
+ ), null), Xt = R.memo(ct, O), at = ({
554
556
  layer: e = "BOTTOM",
555
557
  scaleId: t,
556
558
  tickStyle: n,
@@ -592,7 +594,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
592
594
  c.restore();
593
595
  },
594
596
  [r, t, n, s]
595
- ), null), Ft = D.memo(at, O), lt = ({
597
+ ), null), Ft = R.memo(at, O), lt = ({
596
598
  layer: e = "BOTTOM",
597
599
  scaleId: t,
598
600
  tickStyle: n,
@@ -631,7 +633,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
631
633
  c.restore();
632
634
  },
633
635
  [r, t, n, s]
634
- ), null), Ot = D.memo(lt, O), _e = (e) => {
636
+ ), null), Ot = R.memo(lt, O), _e = (e) => {
635
637
  if (e)
636
638
  try {
637
639
  return e.replace(/(\d+)px/, (t, n) => `${parseInt(n) * window.devicePixelRatio || 1}px`);
@@ -665,15 +667,15 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
665
667
  pressandwheel: I(),
666
668
  sync_move: I()
667
669
  }, L = (e, t, n) => {
668
- const s = D.useRef(n);
669
- s.current = n, D.useEffect(() => M[e].addEventListener(
670
+ const s = R.useRef(n);
671
+ s.current = n, R.useEffect(() => M[e].addEventListener(
670
672
  t,
671
673
  (i, r) => {
672
674
  s.current(r, i);
673
675
  }
674
676
  ), [t, e, s]);
675
- }, we = D.createContext(""), xe = (e, t) => {
676
- const n = D.useContext(we);
677
+ }, we = R.createContext(""), xe = (e, t) => {
678
+ const n = R.useContext(we);
677
679
  return L(e, n, t);
678
680
  }, ut = (e, t, n, s, o) => {
679
681
  if (!t) return;
@@ -764,7 +766,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
764
766
  }), L("contextmenu", d, (y) => {
765
767
  u?.(y);
766
768
  }), /* @__PURE__ */ pe(we.Provider, { value: d, children: [
767
- /* @__PURE__ */ R(
769
+ /* @__PURE__ */ A(
768
770
  ht,
769
771
  {
770
772
  id: e,
@@ -777,9 +779,9 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
777
779
  g
778
780
  ] });
779
781
  }, ht = ({ id: e, className: t, style: n, sync: s, children: o }) => {
780
- const i = A(null), r = Ue().frame, c = A(r);
782
+ const i = k(null), r = Ue().frame, c = k(r);
781
783
  c.current = r;
782
- const u = G(we), l = s?.key || u, p = A(null), f = A(null), a = A(null), g = () => {
784
+ const u = G(we), l = s?.key || u, p = k(null), f = k(null), a = k(null), g = () => {
783
785
  const h = i.current?.parentElement;
784
786
  if (h) {
785
787
  if (h.dataset.canplotroot === void 0)
@@ -806,8 +808,8 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
806
808
  metaKey: h.metaKey
807
809
  }
808
810
  );
809
- }, y = A(d);
810
- return y.current = d, Ae(() => {
811
+ }, y = k(d);
812
+ return y.current = d, ke(() => {
811
813
  const h = (w) => {
812
814
  const b = f.current;
813
815
  b && M.spanselect.dispatchEvent(u, {
@@ -849,9 +851,9 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
849
851
  (b, { cssX: S, cssY: E }, C) => {
850
852
  const P = p.current;
851
853
  if (!P || !b.x || !b.y) return;
852
- const k = c.current, z = P.xRangeCss.start, ae = S, le = P.yRangeCss.start, ue = E, ee = F(k, b.x.scaleId);
854
+ const D = c.current, z = P.xRangeCss.start, ae = S, le = P.yRangeCss.start, ue = E, ee = F(D, b.x.scaleId);
853
855
  if (!ee) return;
854
- const te = F(k, b.y.scaleId);
856
+ const te = F(D, b.y.scaleId);
855
857
  if (!te) return;
856
858
  p.current = {
857
859
  xRangeCss: { start: z, end: ae },
@@ -861,28 +863,28 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
861
863
  const he = Math.abs(le - ue), fe = Math.abs(z - ae);
862
864
  he < 10 && fe < 10 ? q = "below_threshold" : he > 30 && fe > 30 ? q = "box" : he > fe ? q = "y" : q = "x";
863
865
  const Te = X(
864
- k,
866
+ D,
865
867
  V(c.current, z, "css"),
866
868
  ee.id,
867
869
  "css"
868
870
  );
869
871
  if (Te === null) return;
870
872
  const Se = X(
871
- k,
873
+ D,
872
874
  V(c.current, ae, "css"),
873
875
  ee.id,
874
876
  "css"
875
877
  );
876
878
  if (Se === null) return;
877
879
  const Ce = X(
878
- k,
880
+ D,
879
881
  W(c.current, le, "css"),
880
882
  te.id,
881
883
  "css"
882
884
  );
883
885
  if (Ce === null) return;
884
886
  const Pe = X(
885
- k,
887
+ D,
886
888
  W(c.current, ue, "css"),
887
889
  te.id,
888
890
  "css"
@@ -929,16 +931,16 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
929
931
  c.current
930
932
  );
931
933
  if (!C) return;
932
- if (Object.values(E).some((k) => k)) {
934
+ if (Object.values(E).some((D) => D)) {
933
935
  w.preventDefault();
934
- const k = Math.abs(w.deltaY) > Math.abs(w.deltaX) ? w.deltaY : w.deltaX;
936
+ const D = Math.abs(w.deltaY) > Math.abs(w.deltaX) ? w.deltaY : w.deltaX;
935
937
  M.pressandwheel.dispatchEvent(u, {
936
938
  pointer: C,
937
939
  frame: c.current,
938
940
  keys: E,
939
941
  deltaX: w.deltaX,
940
942
  deltaY: w.deltaY,
941
- deltaAbs: k
943
+ deltaAbs: D
942
944
  });
943
945
  }
944
946
  });
@@ -961,7 +963,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
961
963
  keys: h.keys,
962
964
  source: h.originInteractionsId === u ? "own" : "sync"
963
965
  });
964
- }), /* @__PURE__ */ R(
966
+ }), /* @__PURE__ */ A(
965
967
  "div",
966
968
  {
967
969
  ref: i,
@@ -1129,7 +1131,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
1129
1131
  return null;
1130
1132
  const { frame: r, pointer: c } = o, u = c?.cssX ?? null, l = c?.cssY ?? null, p = u ? V(r, u, "css") : 0, f = l ? W(r, l, "css") : 0;
1131
1133
  return /* @__PURE__ */ pe(Ne, { children: [
1132
- /* @__PURE__ */ R(
1134
+ /* @__PURE__ */ A(
1133
1135
  "div",
1134
1136
  {
1135
1137
  "data-show": !!c,
@@ -1150,7 +1152,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
1150
1152
  }
1151
1153
  }
1152
1154
  ),
1153
- /* @__PURE__ */ R(
1155
+ /* @__PURE__ */ A(
1154
1156
  "div",
1155
1157
  {
1156
1158
  className: s?.(o),
@@ -1184,7 +1186,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
1184
1186
  const i = n.mode === "y" ? -1 / 0 : n.x.css?.from ?? -1 / 0, r = n.mode === "y" ? 1 / 0 : n.x.css?.to ?? 1 / 0, c = n.mode === "x" ? -1 / 0 : n.y.css?.from ?? -1 / 0, u = n.mode === "x" ? 1 / 0 : n.y.css?.to ?? 1 / 0, l = V(n.frame, i, "css"), p = V(n.frame, r, "css"), f = W(n.frame, c, "css"), a = W(n.frame, u, "css"), g = Math.min(l, p), d = Math.min(f, a), y = Math.abs(p - l), h = Math.abs(a - f);
1185
1187
  return { leftPx: g, topPx: d, widthPx: y, heightPx: h };
1186
1188
  }, [n]);
1187
- return /* @__PURE__ */ R(
1189
+ return /* @__PURE__ */ A(
1188
1190
  "div",
1189
1191
  {
1190
1192
  className: n ? e?.(n) : void 0,
@@ -1202,7 +1204,7 @@ const Dt = je(({ configuration: e, children: t, style: n, ...s }, o) => {
1202
1204
  );
1203
1205
  }, Nt = ({ style: e, children: t, scaleId: n, ...s }) => {
1204
1206
  const o = Ue().getScale(n)?.axis;
1205
- return o ? /* @__PURE__ */ R(
1207
+ return o ? /* @__PURE__ */ A(
1206
1208
  "div",
1207
1209
  {
1208
1210
  style: {
@@ -1331,7 +1333,7 @@ const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, J = 60 * be, ce = 24 * J, yt = 30 * c
1331
1333
  }, St = (e, t) => {
1332
1334
  const n = new Date(e);
1333
1335
  return n.setUTCDate(n.getUTCDate() + t), n.getTime();
1334
- }, ke = (e, t) => {
1336
+ }, De = (e, t) => {
1335
1337
  const n = new Date(e);
1336
1338
  return n.setUTCMonth(n.getUTCMonth() + t), n.getTime();
1337
1339
  }, U = (e, t) => {
@@ -1348,9 +1350,9 @@ const pt = 1, Oe = 1e3 * pt, be = 60 * Oe, J = 60 * be, ce = 24 * J, yt = 30 * c
1348
1350
  case "days":
1349
1351
  return St(e, n);
1350
1352
  case "months":
1351
- return ke(e, n);
1353
+ return De(e, n);
1352
1354
  case "years":
1353
- return ke(e, n * 12);
1355
+ return De(e, n * 12);
1354
1356
  }
1355
1357
  };
1356
1358
  function H(e, t) {
@@ -1503,10 +1505,10 @@ const Ct = (e, t, n = "UTC") => {
1503
1505
  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;
1504
1506
  let C = "";
1505
1507
  if (c) {
1506
- const P = l.label.find((z) => z.type === "second")?.value, k = l.label.find(
1508
+ const P = l.label.find((z) => z.type === "second")?.value, D = l.label.find(
1507
1509
  (z) => z.type === "fractionalSecond"
1508
1510
  )?.value;
1509
- C = `:${P}` + (u ? `.${k}` : "");
1511
+ C = `:${P}` + (u ? `.${D}` : "");
1510
1512
  }
1511
1513
  w.push(
1512
1514
  `${b}:${S}${C}` + (n && m ? ` ${E}` : "")
@@ -1530,7 +1532,7 @@ export {
1530
1532
  Nt as AxisOverlay,
1531
1533
  Ut as BarPlot,
1532
1534
  Ie as CANPLOT_LAYER,
1533
- Dt as CanPlot,
1535
+ Rt as CanPlot,
1534
1536
  Kt as ChartAreaInteractions,
1535
1537
  Bt as Crosshair,
1536
1538
  Le as FrameDrawer,
@@ -1547,14 +1549,14 @@ export {
1547
1549
  W as clampYPosToChartArea,
1548
1550
  O as deepEqual,
1549
1551
  mt as defaultNumericalTicksFormatter,
1550
- Rt as findClosestIndex,
1552
+ At as findClosestIndex,
1551
1553
  F as getScale,
1552
1554
  $t as makeLinearTicks,
1553
1555
  Pt as makeTimeTickFormat,
1554
1556
  jt as makeTimeTicks,
1555
1557
  X as posToVal,
1556
1558
  We as pxToValDistance,
1557
- At as sum,
1559
+ kt as sum,
1558
1560
  j as useDrawEffect,
1559
1561
  Ue as useFrameState,
1560
1562
  xe as useInteractionsEvent,