-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(time-slider): add ranges and format
- Loading branch information
Showing
4 changed files
with
166 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
$range-height = 5px | ||
|
||
.timeSlider | ||
position: absolute | ||
bottom: 6em | ||
display: flex | ||
justify-content: center | ||
width: 100% | ||
text-align: center | ||
|
||
.input | ||
.container | ||
width: 80% | ||
|
||
.label | ||
display: inline-block | ||
width: 80% | ||
color: white | ||
text-align: left | ||
font-size: 2em | ||
.label | ||
display: flex | ||
justify-content: space-between | ||
align-items: flex-end | ||
color: white | ||
font-size: 2em | ||
|
||
.labelMin, .labelMax | ||
font-size: 0.6em | ||
|
||
.ranges | ||
position: relative | ||
width: 100% | ||
height: $range-height * 2 | ||
|
||
.rangeMain, .rangeCompare | ||
position: absolute | ||
height: $range-height | ||
|
||
.rangeMain | ||
background: yellow | ||
|
||
.rangeCompare | ||
top: $range-height | ||
background: orange | ||
|
||
input | ||
margin: 0 | ||
width: 100% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {SelectedLayersState} from '../reducers/layers/selected'; | ||
import {DetailsById} from '../reducers/layers/details'; | ||
|
||
import {Layer} from '../types/layer'; | ||
import {TimeRange} from '../types/time-range'; | ||
|
||
// eslint-disable-next-line complexity | ||
export function getTimeRanges( | ||
selectedLayers: SelectedLayersState, | ||
detailedLayers: DetailsById | ||
): { | ||
main: TimeRange | null; | ||
compare: TimeRange | null; | ||
combined: TimeRange; | ||
} { | ||
const mainId = selectedLayers.main; | ||
const mainLayer = (mainId && detailedLayers[mainId]) || null; | ||
const mainRange = getLayerTimeRange(mainLayer); | ||
const mainTimestamps = (mainRange && mainRange.timestamps) || []; | ||
|
||
const compareId = selectedLayers.compare; | ||
const compareLayer = (compareId && detailedLayers[compareId]) || null; | ||
const compareRange = getLayerTimeRange(compareLayer); | ||
const compareTimestamps = (compareRange && compareRange.timestamps) || []; | ||
|
||
const combinedRange = getTimeRange([...mainTimestamps, ...compareTimestamps]); | ||
|
||
return { | ||
main: mainRange, | ||
compare: compareRange, | ||
combined: combinedRange | ||
}; | ||
} | ||
|
||
function getLayerTimeRange(layer: Layer | null): TimeRange | null { | ||
if (!layer || layer.timestamps.length < 2) { | ||
return null; | ||
} | ||
|
||
return getTimeRange(layer.timestamps); | ||
} | ||
|
||
function getTimeRange(timestamps: string[]): TimeRange { | ||
const sorted = timestamps | ||
.map((isoString: string) => new Date(isoString)) | ||
.sort((a: Date, b: Date) => Number(a) - Number(b)); | ||
|
||
return { | ||
min: Number(sorted[0]) || 0, | ||
max: Number(sorted[sorted.length - 1]) || 0, | ||
timestamps: sorted.map(date => date.toISOString()) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface TimeRange { | ||
min: number; | ||
max: number; | ||
timestamps: string[]; | ||
} |