From fc47db0f45375adbec559e19e48ce3279baa65e8 Mon Sep 17 00:00:00 2001 From: Luc Claustres Date: Fri, 25 Oct 2024 18:48:19 +0200 Subject: [PATCH] fix: timeseries labels not correctly updated after default unit settings change (#376) --- src/components/MapActivity.vue | 8 ++++++-- src/components/TimeSeries.vue | 4 ++-- src/utils/utils.time-series.js | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/MapActivity.vue b/src/components/MapActivity.vue index 77625ed4..2a0a3f6b 100644 --- a/src/components/MapActivity.vue +++ b/src/components/MapActivity.vue @@ -321,7 +321,10 @@ export default { this.$engineEvents.on('moveend', this.onMoveEnd) this.$engineEvents.on('forecast-model-changed', this.updateSelection) this.$engineEvents.on('selected-level-changed', this.updateSelection) - this.$events.on('timeseries-group-by-changed', this.updateTimeSeries) + // We use debounce here to avoid multiple refresh when editing settings for instance + this.requestTimeSeriesUpdate = _.debounce(this.updateTimeSeries, 250) + this.$events.on('timeseries-group-by-changed', this.requestTimeSeriesUpdate) + this.$events.on('units-changed', this.requestTimeSeriesUpdate) this.$events.on('time-current-time-changed', this.updateProbedLocationHighlight) }, beforeUnmount () { @@ -334,7 +337,8 @@ export default { this.$engineEvents.off('forecast-model-changed', this.updateSelection) this.$engineEvents.off('selected-level-changed', this.updateSelection) this.$events.off('timeseries-group-by-changed', this.updateTimeSeries) - this.$events.off('time-current-time-changed', this.updateProbedLocationHighlight) + this.$events.off('units-changed', this.requestTimeSeriesUpdate) + this.$events.off('time-current-time-changed', this.requestTimeSeriesUpdate) this.unregisterStyle('point', this.getHighlightMarker) this.unregisterStyle('tooltip', this.getHighlightTooltip) }, diff --git a/src/components/TimeSeries.vue b/src/components/TimeSeries.vue index 7cefad33..8342d771 100644 --- a/src/components/TimeSeries.vue +++ b/src/components/TimeSeries.vue @@ -94,7 +94,7 @@ const isSelectorVisible = computed(() => { return visible && !hasSingleSerie.value }) -// Watch change in time series driavers like time range, format, ... +// Watch change in time series drivers like time range, format, ... watch(Store.get('time.range'), async () => { if (chartRef.value) { // Reset any zoom @@ -125,7 +125,7 @@ async function fetchData () { } function updateChart () { if (!chartRef.value) return - chartRef.value.update() + chartRef.value.requestUpdate() } function isPinned (timeSerie) { timeSerie = _.find(state.timeSeries, { id: timeSerie.id }) diff --git a/src/utils/utils.time-series.js b/src/utils/utils.time-series.js index b39f1236..b2eec665 100644 --- a/src/utils/utils.time-series.js +++ b/src/utils/utils.time-series.js @@ -58,6 +58,7 @@ export function getChartOptions (title) { export async function updateTimeSeries (previousTimeSeries) { const { CurrentActivity, hasSelectedItems, getSelectedItems, hasProbedLocation, getProbedLocation } = kMapComposables.useCurrentActivity() const activity = unref(CurrentActivity) + if (!activity) return // Initialize the time range const span = Store.get('timeseries.span') const start = moment(Time.getCurrentTime()).subtract(span, 'm')