@spider-analyzer/timeline 5.0.2 → 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/CHANGELOG.md +12 -0
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/TimeLine.tsx +2 -1
- package/src/time.ts +12 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spider-analyzer/timeline",
|
|
3
|
-
"version": "5.0.
|
|
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() });
|
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
|
|
39
|
-
return { min:
|
|
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
|
|
43
|
-
return { start:
|
|
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 {
|