@spider-analyzer/timeline 5.0.2 → 5.0.4

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
@@ -1,4 +1,4 @@
1
- import { forwardRef, useRef, useEffect, useState, useCallback, useImperativeHandle } from 'react';
1
+ import { forwardRef, useRef, useEffect, useState, useCallback, useImperativeHandle, useMemo } from 'react';
2
2
  import { DateTime, Duration } from 'luxon';
3
3
  import { scaleLinear, scaleTime } from 'd3-scale';
4
4
  import PropTypes11 from 'prop-types';
@@ -1946,15 +1946,19 @@ function toMoment(x, zone) {
1946
1946
  const m = zone ? moment_shim_default.tz(x, zone) : moment_shim_default(x);
1947
1947
  return m;
1948
1948
  }
1949
+ function toMomentOpt(x, zone) {
1950
+ if (x == null) return void 0;
1951
+ return toMoment(x, zone);
1952
+ }
1949
1953
  function toDuration(x) {
1950
1954
  if (moment_shim_default.isDuration(x)) return x;
1951
1955
  return moment_shim_default.duration(x);
1952
1956
  }
1953
1957
  function domainToMoments(d, zone) {
1954
- return { min: toMoment(d.min, zone), max: toMoment(d.max, zone) };
1958
+ return { min: toMomentOpt(d.min, zone), max: toMomentOpt(d.max, zone) };
1955
1959
  }
1956
1960
  function timeSpanToMoments(t, zone) {
1957
- return { start: toMoment(t.start, zone), stop: toMoment(t.stop, zone) };
1961
+ return { start: toMomentOpt(t.start, zone), stop: toMomentOpt(t.stop, zone) };
1958
1962
  }
1959
1963
  var Cursor2 = Cursor;
1960
1964
  var Histogram2 = Histogram;
@@ -2748,8 +2752,9 @@ var TimeLine2 = forwardRef(function TimeLineWrapper(props, ref) {
2748
2752
  const handleLoadDefault = useCallback(() => {
2749
2753
  const ret = props.onLoadDefaultDomain?.();
2750
2754
  const apply = (d) => {
2751
- if (!d) return;
2755
+ if (!d || !d.min || !d.max) return;
2752
2756
  const m = domainToMoments(d, zone);
2757
+ if (!m.min || !m.max) return;
2753
2758
  setStack([m]);
2754
2759
  if (props.onDomainChange) {
2755
2760
  props.onDomainChange({ min: m.min.toDate(), max: m.max.toDate() });
@@ -2758,19 +2763,55 @@ var TimeLine2 = forwardRef(function TimeLineWrapper(props, ref) {
2758
2763
  if (ret && typeof ret.then === "function") ret.then(apply);
2759
2764
  else if (ret) apply(ret);
2760
2765
  }, [props.onLoadDefaultDomain, props.onDomainChange, zone]);
2766
+ const timeSpanMoments = useMemo(
2767
+ () => props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : void 0,
2768
+ [props.timeSpan, zone]
2769
+ );
2770
+ const maxDomainMoments = useMemo(
2771
+ () => props.maxDomain ? domainToMoments(props.maxDomain, zone) : void 0,
2772
+ [props.maxDomain, zone]
2773
+ );
2774
+ const histoMoments = useMemo(
2775
+ () => props.histo?.items ? { ...props.histo, items: props.histo.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.histo,
2776
+ [props.histo, zone]
2777
+ );
2778
+ const qualityMoments = useMemo(
2779
+ () => props.quality?.items ? { ...props.quality, items: props.quality.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.quality,
2780
+ [props.quality, zone]
2781
+ );
2782
+ const biggestVisibleDomainDur = useMemo(
2783
+ () => props.biggestVisibleDomain != null ? toDuration(props.biggestVisibleDomain) : void 0,
2784
+ [props.biggestVisibleDomain]
2785
+ );
2786
+ const biggestTimeSpanDur = useMemo(
2787
+ () => props.biggestTimeSpan != null ? toDuration(props.biggestTimeSpan) : void 0,
2788
+ [props.biggestTimeSpan]
2789
+ );
2790
+ const smallestResolutionDur = useMemo(
2791
+ () => props.smallestResolution != null ? toDuration(props.smallestResolution) : void 0,
2792
+ [props.smallestResolution]
2793
+ );
2794
+ const xAxisMerged = useMemo(
2795
+ () => ({ ...xAxisDefault, ...props.xAxis ?? {} }),
2796
+ [props.xAxis]
2797
+ );
2798
+ const marginMerged = useMemo(
2799
+ () => ({ ...marginDefault, ...props.margin ?? {} }),
2800
+ [props.margin]
2801
+ );
2761
2802
  const innerProps = {
2762
2803
  ...props,
2763
- xAxis: { ...xAxisDefault, ...props.xAxis ?? {} },
2804
+ xAxis: xAxisMerged,
2764
2805
  yAxis: props.yAxis ?? {},
2765
- margin: { ...marginDefault, ...props.margin ?? {} },
2806
+ margin: marginMerged,
2766
2807
  domains: stack,
2767
- timeSpan: props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : void 0,
2768
- maxDomain: props.maxDomain ? domainToMoments(props.maxDomain, zone) : void 0,
2769
- histo: props.histo?.items ? { ...props.histo, items: props.histo.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.histo,
2770
- quality: props.quality?.items ? { ...props.quality, items: props.quality.items.map((it) => ({ ...it, time: toMoment(it.time, zone) })) } : props.quality,
2771
- biggestVisibleDomain: props.biggestVisibleDomain != null ? toDuration(props.biggestVisibleDomain) : void 0,
2772
- biggestTimeSpan: props.biggestTimeSpan != null ? toDuration(props.biggestTimeSpan) : void 0,
2773
- smallestResolution: props.smallestResolution != null ? toDuration(props.smallestResolution) : void 0,
2808
+ timeSpan: timeSpanMoments,
2809
+ maxDomain: maxDomainMoments,
2810
+ histo: histoMoments,
2811
+ quality: qualityMoments,
2812
+ biggestVisibleDomain: biggestVisibleDomainDur,
2813
+ biggestTimeSpan: biggestTimeSpanDur,
2814
+ smallestResolution: smallestResolutionDur,
2774
2815
  onUpdateDomains: handleUpdateDomains,
2775
2816
  onLoadDefaultDomain: handleLoadDefault,
2776
2817
  // onLoadHisto: object shape + Date instants