-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'time-slider' into develop
- Loading branch information
Showing
7 changed files
with
415 additions
and
42 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
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,96 @@ | ||
<template> | ||
<v-form> | ||
<v-container> | ||
<v-range-slider v-model="sliderRange" :min="featuresStore.minTime" :max="featuresStore.maxTime" | ||
class="align-center" hide-details @update:modelValue="updateDateRange"> | ||
<template v-slot:prepend> | ||
<v-text-field v-model="dateRange[0]" density="compact" type="date" variant="outlined" hide-details single-line | ||
@update:modelValue="updateSliderRange" :rules="[rules.min,]"></v-text-field> | ||
</template> | ||
<template v-slot:append> | ||
<v-text-field v-model="dateRange[1]" density="compact" type="date" variant="outlined" hide-details single-line | ||
@update:modelValue="updateSliderRange" :rules="[rules.max,]"></v-text-field> | ||
</template> | ||
</v-range-slider> | ||
</v-container> | ||
</v-form> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue' | ||
import { useFeaturesStore } from '../stores/features'; | ||
import { useChartsStore } from '@/stores/charts' | ||
import { addMinutes, subMinutes } from "date-fns"; | ||
import { NODE_DATETIME_VARIATION } from '@/constants' | ||
// define an update event that emits the new range | ||
const emit = defineEmits(['update']) | ||
const featuresStore = useFeaturesStore() | ||
const chartStore = useChartsStore() | ||
const convertSecondsToDateString = (seconds) => { | ||
return new Date(seconds * 1000).toISOString().split('T')[0] | ||
} | ||
const convertDateStringToSeconds = (dateString) => { | ||
return new Date(dateString).getTime() / 1000 | ||
} | ||
// There are two inputs. User can select a range of dates (string) using the date picker, or a range of decimal seconds using the slider. | ||
const sliderRange = ref(featuresStore.timeRange) | ||
const dateRange = ref(featuresStore.timeRange.map((t) => convertSecondsToDateString(t))) | ||
// When the date range changes, update the slider range. | ||
const updateSliderRange = () => { | ||
sliderRange.value = dateRange.value.map((dateString) => { | ||
return convertDateStringToSeconds(dateString) | ||
}) | ||
filterDatasetsToTimeRange() | ||
} | ||
// When the slider range changes, update the date range. | ||
const updateDateRange = () => { | ||
dateRange.value = sliderRange.value.map((seconds) => { | ||
return convertSecondsToDateString(seconds) | ||
}) | ||
filterDatasetsToTimeRange() | ||
} | ||
async function filterDatasetsToTimeRange() { | ||
const startTime = subMinutes(dateRange.value[0], NODE_DATETIME_VARIATION) | ||
const endTime = addMinutes(dateRange.value[1], NODE_DATETIME_VARIATION) | ||
chartStore.filterDatasetsToTimeRange(chartStore.nodeChartData.datasets, startTime, endTime) | ||
emit('update', sliderRange.value) | ||
} | ||
const rules = { | ||
min: (v) => { | ||
if (v === null || v === undefined || v === '') { | ||
return 'Start date is required' | ||
} | ||
if (v > dateRange.value[1]) { | ||
return 'Start date must be before end date' | ||
} | ||
const seconds = convertDateStringToSeconds(v) | ||
if (seconds < featuresStore.minTime) { | ||
return 'Start date must be after the first date in the dataset' | ||
} | ||
return true | ||
}, | ||
max: (v) => { | ||
if (v === null || v === undefined || v === '') { | ||
return 'End date is required' | ||
} | ||
if (v < dateRange.value[0]) { | ||
return 'End date must be after start date' | ||
} | ||
const seconds = convertDateStringToSeconds(v) | ||
if (seconds > featuresStore.maxTime) { | ||
return 'End date must be before the last date in the dataset' | ||
} | ||
return true | ||
}, | ||
} | ||
</script> |
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
Oops, something went wrong.