@spider-analyzer/timeline 5.0.1 → 5.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spider-analyzer/timeline",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "React graphical component to display metric over time with a time selection feature.",
5
5
  "author": "Thibaut Raballand <spider.analyzer@gmail.com> (https://spider-analyzer.io)",
6
6
  "license": "MIT",
package/src/TimeLine.tsx CHANGED
@@ -875,8 +875,9 @@ const TimeLine = forwardRef<TimeLineHandle, any>(function TimeLineWrapper(props,
875
875
  const handleLoadDefault = useCallback(() => {
876
876
  const ret = props.onLoadDefaultDomain?.();
877
877
  const apply = (d: any) => {
878
- if (!d) return;
878
+ if (!d || !d.min || !d.max) return;
879
879
  const m = domainToMoments(d, zone);
880
+ if (!m.min || !m.max) return;
880
881
  setStack([m]);
881
882
  if (props.onDomainChange) {
882
883
  props.onDomainChange({ min: m.min.toDate(), max: m.max.toDate() });
@@ -886,9 +887,15 @@ const TimeLine = forwardRef<TimeLineHandle, any>(function TimeLineWrapper(props,
886
887
  else if (ret) apply(ret);
887
888
  }, [props.onLoadDefaultDomain, props.onDomainChange, zone]);
888
889
 
889
- // Build the moment-typed props the inner expects.
890
+ // Build the moment-typed props the inner expects. Apply the same
891
+ // defaults the inner destructures locally so that ref-path accesses
892
+ // (propsRef.current.xAxis.spaceBetweenTicks etc.) never trip on an
893
+ // undefined consumer prop.
890
894
  const innerProps: any = {
891
895
  ...props,
896
+ xAxis: { ...xAxisDefault, ...(props.xAxis ?? {}) },
897
+ yAxis: props.yAxis ?? {},
898
+ margin: { ...marginDefault, ...(props.margin ?? {}) },
892
899
  domains: stack,
893
900
  timeSpan: props.timeSpan ? timeSpanToMoments(props.timeSpan, zone) : undefined,
894
901
  maxDomain: props.maxDomain ? domainToMoments(props.maxDomain, zone) : undefined,
package/src/time.ts CHANGED
@@ -23,6 +23,14 @@ export function toMoment(x: Instant, zone?: string): Moment {
23
23
  return m;
24
24
  }
25
25
 
26
+ // Null-preserving variant: undefined/null stay undefined instead of
27
+ // becoming `moment()` (= now). Optional domain bounds like maxDomain.min
28
+ // rely on this to remain "unset".
29
+ function toMomentOpt(x: Instant | null | undefined, zone?: string): Moment | undefined {
30
+ if (x == null) return undefined;
31
+ return toMoment(x, zone);
32
+ }
33
+
26
34
  export function toDuration(x: Millis): Duration {
27
35
  if (moment.isDuration(x)) return x as Duration;
28
36
  return moment.duration(x as number);
@@ -35,12 +43,12 @@ export function fromMoment(m: Moment | null | undefined): Date | null {
35
43
  export interface DateDomain { min: Date; max: Date; }
36
44
  export interface DateTimeSpan { start: Date; stop: Date; }
37
45
 
38
- export function domainToMoments(d: { min: Instant; max: Instant }, zone?: string) {
39
- return { min: toMoment(d.min, zone), max: toMoment(d.max, zone) };
46
+ export function domainToMoments(d: { min?: Instant | null; max?: Instant | null }, zone?: string) {
47
+ return { min: toMomentOpt(d.min, zone), max: toMomentOpt(d.max, zone) };
40
48
  }
41
49
 
42
- export function timeSpanToMoments(t: { start: Instant; stop: Instant }, zone?: string) {
43
- return { start: toMoment(t.start, zone), stop: toMoment(t.stop, zone) };
50
+ export function timeSpanToMoments(t: { start?: Instant | null; stop?: Instant | null }, zone?: string) {
51
+ return { start: toMomentOpt(t.start, zone), stop: toMomentOpt(t.stop, zone) };
44
52
  }
45
53
 
46
54
  export function domainToDates(d: { min: Moment; max: Moment }): DateDomain {