From bf0bde624e9baa149bfbca4776f7e1339336757e Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 29 May 2021 23:52:19 +0200 Subject: [PATCH] bugfix: tempchart interval duplicates Signed-off-by: Stefan Dej --- src/components/charts/TempChart.vue | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/charts/TempChart.vue b/src/components/charts/TempChart.vue index 4da37bd5..6ef7e15e 100644 --- a/src/components/charts/TempChart.vue +++ b/src/components/charts/TempChart.vue @@ -15,7 +15,7 @@ export default { let _this = this; return { chart : null, - timerChart: '', + timerChart: null, isVisible: true, chartOptions: { darkMode: true, @@ -229,12 +229,14 @@ export default { if (document.getElementById("tempchart") && this.chart === null) { this.chart = echarts.init(document.getElementById("tempchart"), null, {renderer: 'canvas'}) this.chart.setOption(this.chartOptions) - this.updateChart() + this.timerChart = setInterval(this.updateChart, this.intervalChartUpdate) } else setTimeout(() => { this.createChart() }, 1000) }, updateChart() { + window.console.log("update chart") + if ( this.chart && this.boolTempchart && @@ -294,16 +296,18 @@ export default { } }], }) - - setTimeout(() => { - this.updateChart() - }, this.intervalChartUpdate) } }, visibilityChanged (isVisible) { this.isVisible = isVisible if(isVisible && this.chart !== null) this.chart.resize() - if(this.chart !== null) this.updateChart() + + if (!isVisible && this.timerChart !== null) { + clearTimeout(this.timerChart) + this.timerChart = null + } else if(isVisible && this.chart !== null && this.timerChart === null) { + this.timerChart = setInterval(this.updateChart, this.intervalChartUpdate) + } }, resize() { this.chart?.resize();