@spider-analyzer/timeline 5.0.5 → 5.0.8

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/index.mjs CHANGED
@@ -162,6 +162,25 @@ moment.tz = (x, zone) => {
162
162
  const base = toDT(x);
163
163
  return new MomentLike(base.setZone(zone));
164
164
  };
165
+ function validate(props, propName, componentName) {
166
+ const v = props[propName];
167
+ if (v == null) return null;
168
+ if (moment.isMoment(v)) return null;
169
+ return new Error(
170
+ `Invalid prop \`${propName}\` supplied to \`${componentName}\`, expected a moment-like object.`
171
+ );
172
+ }
173
+ var required = (props, propName, componentName) => {
174
+ const v = props[propName];
175
+ if (v == null) {
176
+ return new Error(
177
+ `The prop \`${propName}\` is marked as required in \`${componentName}\`, but its value is \`${v}\`.`
178
+ );
179
+ }
180
+ return validate(props, propName, componentName);
181
+ };
182
+ var momentType = validate;
183
+ momentType.isRequired = required;
165
184
  var moment_shim_default = moment;
166
185
 
167
186
  // src/utils.ts
@@ -365,8 +384,8 @@ DragOverlay.propTypes = {
365
384
  width: PropTypes11.number.isRequired,
366
385
  marginBottom: PropTypes11.number,
367
386
  items: PropTypes11.arrayOf(PropTypes11.shape({
368
- start: PropTypes11.instanceOf(moment_shim_default).isRequired,
369
- end: PropTypes11.instanceOf(moment_shim_default).isRequired,
387
+ start: momentType.isRequired,
388
+ end: momentType.isRequired,
370
389
  x1: PropTypes11.number,
371
390
  x2: PropTypes11.number,
372
391
  metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
@@ -676,8 +695,8 @@ CursorSelection.propTypes = {
676
695
  showToolTipLeft: PropTypes11.func.isRequired,
677
696
  showToolTipRight: PropTypes11.func.isRequired,
678
697
  items: PropTypes11.arrayOf(PropTypes11.shape({
679
- start: PropTypes11.instanceOf(moment_shim_default).isRequired,
680
- end: PropTypes11.instanceOf(moment_shim_default).isRequired,
698
+ start: momentType.isRequired,
699
+ end: momentType.isRequired,
681
700
  x1: PropTypes11.number,
682
701
  x2: PropTypes11.number,
683
702
  metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
@@ -1263,8 +1282,8 @@ Cursor.propTypes = {
1263
1282
  overlayHeight: PropTypes11.number.isRequired,
1264
1283
  overlayWidth: PropTypes11.number.isRequired,
1265
1284
  items: PropTypes11.arrayOf(PropTypes11.shape({
1266
- start: PropTypes11.instanceOf(moment_shim_default).isRequired,
1267
- end: PropTypes11.instanceOf(moment_shim_default).isRequired,
1285
+ start: momentType.isRequired,
1286
+ end: momentType.isRequired,
1268
1287
  x1: PropTypes11.number,
1269
1288
  x2: PropTypes11.number,
1270
1289
  metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
@@ -1373,8 +1392,8 @@ function Histogram({
1373
1392
  Histogram.propTypes = {
1374
1393
  classes: PropTypes11.object,
1375
1394
  items: PropTypes11.arrayOf(PropTypes11.shape({
1376
- start: PropTypes11.instanceOf(moment_shim_default).isRequired,
1377
- end: PropTypes11.instanceOf(moment_shim_default).isRequired,
1395
+ start: momentType.isRequired,
1396
+ end: momentType.isRequired,
1378
1397
  x1: PropTypes11.number,
1379
1398
  x2: PropTypes11.number,
1380
1399
  metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
@@ -1474,8 +1493,8 @@ function XAxis({ min, max: max2, origin, axisWidth, marks, xAxis, classes, arrow
1474
1493
  XAxis.propTypes = {
1475
1494
  axisWidth: PropTypes11.number.isRequired,
1476
1495
  classes: PropTypes11.object,
1477
- min: PropTypes11.instanceOf(moment_shim_default),
1478
- max: PropTypes11.instanceOf(moment_shim_default),
1496
+ min: momentType,
1497
+ max: momentType,
1479
1498
  origin: PropTypes11.shape({
1480
1499
  x: PropTypes11.number.isRequired,
1481
1500
  y: PropTypes11.number.isRequired
@@ -1800,8 +1819,8 @@ function HistoTooltip({ metricsDefinition, item, onFormatTimeToolTips, onFormatM
1800
1819
  HistoTooltip.propTypes = {
1801
1820
  classes: PropTypes11.object,
1802
1821
  item: PropTypes11.shape({
1803
- start: PropTypes11.instanceOf(moment_shim_default).isRequired,
1804
- end: PropTypes11.instanceOf(moment_shim_default).isRequired,
1822
+ start: momentType.isRequired,
1823
+ end: momentType.isRequired,
1805
1824
  x1: PropTypes11.number,
1806
1825
  x2: PropTypes11.number,
1807
1826
  metrics: PropTypes11.arrayOf(PropTypes11.number).isRequired,
@@ -1869,7 +1888,7 @@ QualityLine.propTypes = {
1869
1888
  xAxis: PropTypes11.func.isRequired,
1870
1889
  quality: PropTypes11.shape({
1871
1890
  items: PropTypes11.arrayOf(PropTypes11.shape({
1872
- time: PropTypes11.instanceOf(moment_shim_default).isRequired,
1891
+ time: momentType.isRequired,
1873
1892
  quality: PropTypes11.number.isRequired,
1874
1893
  tip: PropTypes11.node
1875
1894
  })),
@@ -2079,7 +2098,7 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
2079
2098
  propsRef.current.smallestResolution.asMilliseconds()
2080
2099
  ]);
2081
2100
  patchState({ histoWidth: histoWidth2, isActive: true, ticks: ticks2 });
2082
- if (shouldReload && intervalMs) {
2101
+ if (shouldReload && intervalMs && histoWidth2 > 0) {
2083
2102
  widthOfLastUpdateRef.current = p.width;
2084
2103
  patchState({ waitForLoad: true });
2085
2104
  p.onLoadHisto(intervalMs, domain2.min, domain2.max);
@@ -2109,12 +2128,11 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
2109
2128
  return;
2110
2129
  }
2111
2130
  const s = stateRef.current;
2112
- if (s.isActive) {
2131
+ patchState(computeMarginAndWidth(props));
2132
+ if (s.domain) {
2113
2133
  const big = widthOfLastUpdateRef.current !== null && Math.abs((props.width ?? 0) - (widthOfLastUpdateRef.current ?? 0)) > 30;
2114
- getItems(props, s.domain, big);
2115
- patchState(computeMarginAndWidth(props));
2116
- } else {
2117
- patchState(computeMarginAndWidth(props));
2134
+ const shouldReload = !s.isActive || big || widthOfLastUpdateRef.current === null;
2135
+ getItems(props, s.domain, shouldReload);
2118
2136
  }
2119
2137
  if (stateRef.current.domain) {
2120
2138
  const res = checkAndCorrectDomain({ domain: stateRef.current.domain });
@@ -2555,13 +2573,17 @@ var TimeLineInner = forwardRef(function TimeLine(props, ref) {
2555
2573
  ticks,
2556
2574
  dragging
2557
2575
  } = state;
2576
+ const verticalScaleData = useMemo(() => prepareVerticalScale(), [prepareVerticalScale]);
2577
+ const items = useMemo(
2578
+ () => prepareHistogram({ domain, verticalScale: verticalScaleData.verticalScale }),
2579
+ [prepareHistogram, domain, verticalScaleData, histoWidth]
2580
+ );
2581
+ itemsRef.current = items;
2558
2582
  const xAxisHeight = xAxisProp.height || xAxisDefault.height;
2559
2583
  const pointZero = { x: 0, y: height - margin.bottom - xAxisHeight };
2560
2584
  const originCursor = { x: 0, y: margin.top - 5 };
2561
2585
  if (!isFunction(xAxisRef.current)) return null;
2562
- const { verticalScale, verticalMarks, maxHeight } = prepareVerticalScale();
2563
- const items = prepareHistogram({ domain, verticalScale });
2564
- itemsRef.current = items;
2586
+ const { verticalScale, verticalMarks, maxHeight } = verticalScaleData;
2565
2587
  return /* @__PURE__ */ jsx(
2566
2588
  "svg",
2567
2589
  {