@canplot/react 0.1.2 → 0.1.3

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,5 +1,5 @@
1
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 vt, useState as N, useId as Dt, useEffect as Xt } from "react";
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
3
  import { createStore as Kt, useStore as Ct } from "zustand";
4
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
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);
@@ -260,22 +260,22 @@ const Wt = (t, s, e = "UTC") => {
260
260
  return i.map((l) => o.formatToParts(new Date(l))).map((l, d, f) => {
261
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
262
  if (r && (y || C || x || S || g)) {
263
- const v = l.find((P) => P.type === "hour")?.value, E = l.find((P) => P.type === "minute")?.value, M = l.find((P) => P.type === "timeZoneName")?.value;
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
264
  let _ = "";
265
265
  if (a) {
266
266
  const P = l.find((F) => F.type === "second")?.value, B = l.find((F) => F.type === "fractionalSecond")?.value;
267
267
  _ = `:${P}` + (u ? `.${B}` : "");
268
268
  }
269
269
  k.push(
270
- `${v}:${E}${_}` + (e && x ? ` ${M}` : "")
270
+ `${w}:${E}${_}` + (e && x ? ` ${M}` : "")
271
271
  );
272
272
  }
273
273
  return (c || p) && k.push(
274
274
  [
275
- l.find((v) => v.type === "month")?.value,
276
- c && l.find((v) => v.type === "day")?.value
275
+ l.find((w) => w.type === "month")?.value,
276
+ c && l.find((w) => w.type === "day")?.value
277
277
  ].filter(Boolean).join(" ")
278
- ), h && k.push(l.find((v) => v.type === "year")?.value), k.filter((v) => v).join(`
278
+ ), h && k.push(l.find((w) => w.type === "year")?.value), k.filter((w) => w).join(`
279
279
  `);
280
280
  });
281
281
  };
@@ -437,7 +437,7 @@ function rt(t, s) {
437
437
  }
438
438
  var oe = parseInt(Ut.split(".")[0], 10) >= 19 ? ne : se;
439
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 = vt(ee, []);
440
+ const n = U(null), r = U(null), a = ce(r), u = wt(ee, []);
441
441
  J(() => {
442
442
  u.setState({
443
443
  _frame: re(t, a, n.current)
@@ -662,7 +662,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
662
662
  l.lineTo(d.x, d.y);
663
663
  l.closePath(), l.fill(), l.restore();
664
664
  }
665
- }, [t, s, e, o]), null), we = ({ data: t, stroked: s, xScaleId: e, yScaleId: o, style: i }) => (j(
665
+ }, [t, s, e, o]), null), ve = ({ data: t, stroked: s, xScaleId: e, yScaleId: o, style: i }) => (j(
666
666
  ({ getCtx: n, clampXPosToChartArea: r, clampYPosToChartArea: a, valToPos: u }) => {
667
667
  const l = [], d = n();
668
668
  for (const c of t) {
@@ -685,7 +685,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
685
685
  d.restore();
686
686
  },
687
687
  [t, s, e, o, i]
688
- ), null), ve = (t, s) => pt(
688
+ ), null), we = (t, s) => pt(
689
689
  ({
690
690
  clampXPosToChartArea: e,
691
691
  clampYPosToChartArea: o,
@@ -728,7 +728,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
728
728
  o.syncKey === s && o.callback(s, e);
729
729
  }
730
730
  };
731
- }, w = {
731
+ }, v = {
732
732
  dblclick: T(),
733
733
  click: T(),
734
734
  move: T(),
@@ -746,7 +746,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
746
746
  sync_pressandwheel: T()
747
747
  }, b = (t, s, e) => {
748
748
  const o = G.useRef(e);
749
- o.current = e, G.useEffect(() => w[t].addEventListener(
749
+ o.current = e, G.useEffect(() => v[t].addEventListener(
750
750
  s,
751
751
  (n, r) => {
752
752
  o.current(r, n);
@@ -790,7 +790,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
790
790
  })
791
791
  )
792
792
  };
793
- }, wt = (t, s, e) => {
793
+ }, vt = (t, s, e) => {
794
794
  if (!s) {
795
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;
796
796
  return {
@@ -862,7 +862,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
862
862
  r?.(c);
863
863
  }), b("spanselect", h, (c) => {
864
864
  a?.(c);
865
- }), /* @__PURE__ */ at(mt, { value: h, children: [
865
+ }), /* @__PURE__ */ at(mt.Provider, { value: h, children: [
866
866
  /* @__PURE__ */ D(
867
867
  ue,
868
868
  {
@@ -907,10 +907,10 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
907
907
  return h.current = m, Xt(() => {
908
908
  const c = (S) => {
909
909
  const g = l.current;
910
- g && w.sync_spanselect.dispatchEvent(a, {
910
+ g && v.sync_spanselect.dispatchEvent(a, {
911
911
  ...g,
912
912
  completed: !0
913
- }), w.documentmouseup.dispatchEvent(a, {
913
+ }), v.documentmouseup.dispatchEvent(a, {
914
914
  frame: n.current,
915
915
  keys: {
916
916
  ctrlKey: S.ctrlKey,
@@ -930,15 +930,15 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
930
930
  ([E, M]) => k.keys[E] !== M
931
931
  )) {
932
932
  const E = { ...k, keys: g };
933
- d.current = E, w.sync_move.dispatchEvent(a, E);
933
+ d.current = E, v.sync_move.dispatchEvent(a, E);
934
934
  }
935
- const v = l.current;
936
- if (v && Object.entries(g).some(
937
- ([E, M]) => v.keys[E] !== M
935
+ const w = l.current;
936
+ if (w && Object.entries(g).some(
937
+ ([E, M]) => w.keys[E] !== M
938
938
  )) {
939
939
  S.stopPropagation(), S.preventDefault();
940
- const E = { ...v, keys: g };
941
- l.current = E, w.sync_spanselect.dispatchEvent(
940
+ const E = { ...w, keys: g };
941
+ l.current = E, v.sync_spanselect.dispatchEvent(
942
942
  a,
943
943
  E
944
944
  );
@@ -946,10 +946,10 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
946
946
  }, y = (S) => {
947
947
  h.current(
948
948
  S,
949
- (g, { cssX: k, cssY: v }, E) => {
949
+ (g, { cssX: k, cssY: w }, E) => {
950
950
  const M = u.current;
951
951
  if (!M || !g.x || !g.y) return;
952
- const _ = n.current, P = M.xRangeCss.start, B = k, F = M.yRangeCss.start, et = v, st = A(_, g.x.scaleId), nt = A(_, g.y.scaleId);
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
953
  u.current = {
954
954
  xRangeCss: { start: P, end: B },
955
955
  yRangeCss: { start: F, end: et }
@@ -992,20 +992,20 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
992
992
  completed: !1,
993
993
  keys: E
994
994
  };
995
- l.current = yt, w.sync_spanselect.dispatchEvent(
995
+ l.current = yt, v.sync_spanselect.dispatchEvent(
996
996
  a,
997
997
  yt
998
998
  );
999
999
  }
1000
1000
  );
1001
1001
  }, x = (S) => {
1002
- h.current(S, (g, k, v) => {
1003
- if (Object.values(v).some((M) => M)) {
1002
+ h.current(S, (g, k, w) => {
1003
+ if (Object.values(w).some((M) => M)) {
1004
1004
  S.preventDefault();
1005
1005
  const M = Math.abs(S.deltaY) > Math.abs(S.deltaX) ? S.deltaY : S.deltaX;
1006
- w.sync_pressandwheel.dispatchEvent(a, {
1006
+ v.sync_pressandwheel.dispatchEvent(a, {
1007
1007
  positions: g,
1008
- keys: v,
1008
+ keys: w,
1009
1009
  deltaX: S.deltaX,
1010
1010
  deltaY: S.deltaY,
1011
1011
  deltaAbs: M
@@ -1025,7 +1025,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1025
1025
  c.positions,
1026
1026
  n.current
1027
1027
  );
1028
- p && w.dblclick.dispatchEvent(r, {
1028
+ p && v.dblclick.dispatchEvent(r, {
1029
1029
  frame: n.current,
1030
1030
  pointer: p,
1031
1031
  keys: c.keys
@@ -1035,7 +1035,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1035
1035
  c.positions,
1036
1036
  n.current
1037
1037
  );
1038
- p && w.click.dispatchEvent(r, {
1038
+ p && v.click.dispatchEvent(r, {
1039
1039
  frame: n.current,
1040
1040
  pointer: p,
1041
1041
  keys: c.keys
@@ -1045,7 +1045,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1045
1045
  c.positions,
1046
1046
  n.current
1047
1047
  ) : null;
1048
- d.current = c, w.move.dispatchEvent(r, {
1048
+ d.current = c, v.move.dispatchEvent(r, {
1049
1049
  frame: n.current,
1050
1050
  pointer: p ?? null,
1051
1051
  keys: c.keys
@@ -1055,7 +1055,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1055
1055
  c.positions,
1056
1056
  n.current
1057
1057
  );
1058
- p && w.mousedown.dispatchEvent(r, {
1058
+ p && v.mousedown.dispatchEvent(r, {
1059
1059
  frame: n.current,
1060
1060
  pointer: p,
1061
1061
  keys: c.keys
@@ -1065,7 +1065,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1065
1065
  c.positions,
1066
1066
  n.current
1067
1067
  );
1068
- p && w.mouseup.dispatchEvent(r, {
1068
+ p && v.mouseup.dispatchEvent(r, {
1069
1069
  frame: n.current,
1070
1070
  pointer: p,
1071
1071
  keys: c.keys
@@ -1078,7 +1078,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1078
1078
  c.positions,
1079
1079
  n.current
1080
1080
  );
1081
- p && w.pressandwheel.dispatchEvent(r, {
1081
+ p && v.pressandwheel.dispatchEvent(r, {
1082
1082
  frame: n.current,
1083
1083
  pointer: p,
1084
1084
  keys: c.keys,
@@ -1088,16 +1088,16 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1088
1088
  });
1089
1089
  }
1090
1090
  ), b("sync_spanselect", a, (c) => {
1091
- const p = wt(
1091
+ const p = vt(
1092
1092
  "x",
1093
1093
  c.xRange,
1094
1094
  n.current
1095
- ), y = wt(
1095
+ ), y = vt(
1096
1096
  "y",
1097
1097
  c.yRange,
1098
1098
  n.current
1099
1099
  ), x = p.scaled, C = y.scaled;
1100
- c.completed && (u.current = null), w.spanselect.dispatchEvent(r, {
1100
+ c.completed && (u.current = null), v.spanselect.dispatchEvent(r, {
1101
1101
  mode: c.mode,
1102
1102
  frame: n.current,
1103
1103
  xRanges: x,
@@ -1124,7 +1124,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1124
1124
  },
1125
1125
  onClick: (c) => {
1126
1126
  m(c, (p, y, x) => {
1127
- w.sync_click.dispatchEvent(a, {
1127
+ v.sync_click.dispatchEvent(a, {
1128
1128
  positions: p,
1129
1129
  keys: x
1130
1130
  });
@@ -1132,7 +1132,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1132
1132
  },
1133
1133
  onMouseLeave: (c) => {
1134
1134
  m(c, (p, y, x) => {
1135
- w.sync_move.dispatchEvent(a, {
1135
+ v.sync_move.dispatchEvent(a, {
1136
1136
  positions: null,
1137
1137
  keys: x
1138
1138
  });
@@ -1140,7 +1140,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1140
1140
  },
1141
1141
  onMouseMove: (c) => {
1142
1142
  m(c, (p, y, x) => {
1143
- w.sync_move.dispatchEvent(a, {
1143
+ v.sync_move.dispatchEvent(a, {
1144
1144
  positions: p,
1145
1145
  keys: x
1146
1146
  });
@@ -1148,7 +1148,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1148
1148
  },
1149
1149
  onMouseDown: (c) => {
1150
1150
  m(c, (p, { cssX: y, cssY: x }, C) => {
1151
- w.sync_mousedown.dispatchEvent(a, {
1151
+ v.sync_mousedown.dispatchEvent(a, {
1152
1152
  positions: p,
1153
1153
  keys: C
1154
1154
  }), l.current = null, u.current = {
@@ -1159,7 +1159,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1159
1159
  },
1160
1160
  onMouseUp: (c) => {
1161
1161
  m(c, (p, y, x) => {
1162
- w.sync_mouseup.dispatchEvent(a, {
1162
+ v.sync_mouseup.dispatchEvent(a, {
1163
1163
  positions: p,
1164
1164
  keys: x
1165
1165
  });
@@ -1172,7 +1172,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1172
1172
  keys: x,
1173
1173
  completed: !0
1174
1174
  };
1175
- w.sync_spanselect.dispatchEvent(
1175
+ v.sync_spanselect.dispatchEvent(
1176
1176
  a,
1177
1177
  g
1178
1178
  );
@@ -1181,7 +1181,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1181
1181
  },
1182
1182
  onDoubleClick: (c) => {
1183
1183
  m(c, (p, y, x) => {
1184
- w.sync_dblclick.dispatchEvent(a, {
1184
+ v.sync_dblclick.dispatchEvent(a, {
1185
1185
  positions: p,
1186
1186
  keys: x
1187
1187
  });
@@ -1194,7 +1194,7 @@ const fe = Lt(({ configuration: t, children: s, style: e, className: o }, i) =>
1194
1194
  ft("move", (r) => {
1195
1195
  i(r);
1196
1196
  });
1197
- const n = vt(() => {
1197
+ const n = wt(() => {
1198
1198
  if (!o)
1199
1199
  return null;
1200
1200
  const { frame: r, pointer: a } = o, u = a?.scaled[e];
@@ -1343,7 +1343,7 @@ export {
1343
1343
  ye as LinePlot,
1344
1344
  xe as ScatterPlot,
1345
1345
  ke as SelectBox,
1346
- we as SparklinePlot,
1346
+ ve as SparklinePlot,
1347
1347
  Te as TooltipsX,
1348
1348
  X as applyStyles,
1349
1349
  O as clampXPosToChartArea,
@@ -1353,7 +1353,7 @@ export {
1353
1353
  me as isYScale,
1354
1354
  L as posToVal,
1355
1355
  Ft as pxToValDistance,
1356
- ve as usePositioned,
1356
+ we as usePositioned,
1357
1357
  ct as valFits,
1358
1358
  K as valToPos,
1359
1359
  ut as valToPxDistance