From fe385d1558e8604b717d5a185e300d8d73ca82c8 Mon Sep 17 00:00:00 2001 From: meteyou Date: Wed, 18 Nov 2020 11:05:39 +0100 Subject: [PATCH] bugfix: dashboard > tempchart Signed-off-by: meteyou --- src/charts/LineChart.js | 52 +++++++++++----------- src/components/panels/ToolsPanel.vue | 22 +++++---- src/store/printer/tempHistory/mutations.js | 4 +- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/charts/LineChart.js b/src/charts/LineChart.js index 69b1cd11..0db12a87 100644 --- a/src/charts/LineChart.js +++ b/src/charts/LineChart.js @@ -1,4 +1,4 @@ -import store from '../store' +//import store from '../store' import { Line, mixins } from 'vue-chartjs' const { reactiveProp } = mixins; @@ -14,7 +14,7 @@ export default { return { timer: '', options: { - events: ['click'], + events: [], animation: { duration: 0 // general animation time }, @@ -37,10 +37,10 @@ export default { fontColor: 'rgb(203, 203, 203)', fontFamily: 'Roboto,sans-serif', filter: function(item) { - return !item.text.includes('_target'); + return (item && item.text) ? !item.text.includes('_target') : false; } }, - onClick: function(e, legendItem) { + /*onClick: function(e, legendItem) { let ci = this.chart; let index = legendItem.datasetIndex; let index_target = ci.data.datasets.findIndex(dataset => dataset.label === legendItem.text+'_target'); @@ -56,9 +56,9 @@ export default { store.dispatch('gui/setHeaterChartVisibility', { name: legendItem.text, hidden: meta.hidden }); ci.update(); - } + }*/ }, - tooltips: { + /*tooltips: { enabled: false, mode: 'nearest', caretPadding: 20, @@ -68,15 +68,15 @@ export default { let date = new Date(tooltipItem[0].label); return date.getHours()+":"+(date.getMinutes() < 10 ? "0" : "")+date.getMinutes()+":"+(date.getSeconds() < 10 ? "0" : "")+date.getSeconds(); }, - label: function (tooltipItem/*, data*/) { - /*let label_target = data['datasets'][tooltipItem.datasetIndex].label+"_target"; + label: function (tooltipItem/!*, data*!/) { + /!*let label_target = data['datasets'][tooltipItem.datasetIndex].label+"_target"; let target_dataset = data['datasets'].find(dataset => dataset.label === label_target); - if (target_dataset !== undefined && target_dataset.data[tooltipItem.index] !== undefined) return tooltipItem.value+" / "+target_dataset.data[tooltipItem.index].y;*/ + if (target_dataset !== undefined && target_dataset.data[tooltipItem.index] !== undefined) return tooltipItem.value+" / "+target_dataset.data[tooltipItem.index].y;*!/ return tooltipItem.value; }, } - }, + },*/ maintainAspectRatio: false, responsive: true, responsiveAnimationDuration: 0, // animation duration after a resize @@ -129,22 +129,24 @@ export default { } }, created () { - /*this.timer = setInterval(function() { - this.update; - }, 2000);*/ + this.timer = setInterval(() => { + if ( + this.$data._chart.config && + this.$data._chart.config.options && + this.$data._chart.config.options.scales && + this.$data._chart.config.options.scales.xAxes && + this.$data._chart.config.options.scales.xAxes.length && + this.$data._chart.config.options.scales.yAxes && + this.$data._chart.config.options.scales.yAxes.length + ) { + this.$data._chart.config.options.scales.yAxes[0].ticks.max = defaultMaxTemperature + this.$data._chart.config.options.scales.xAxes[0].ticks.min = new Date() - maxSampleTime + this.$data._chart.config.options.scales.xAxes[0].ticks.max = new Date() + this.$data._chart.update() + } + }, 1000) }, mounted () { - //this.renderChart(this.chartData, this.options) + this.renderChart(this.chartData, this.options) }, - methods: { - update() { - this.$data._chart.config.options.scales.yAxes[0].ticks.max = defaultMaxTemperature; - this.$data._chart.config.options.scales.xAxes[0].ticks.min = new Date() - maxSampleTime; - this.$data._chart.config.options.scales.xAxes[0].ticks.max = new Date(); - this.$data._chart.update(); - } - }, - watch: { - - } } \ No newline at end of file diff --git a/src/components/panels/ToolsPanel.vue b/src/components/panels/ToolsPanel.vue index cb1d4206..f4ef2dc3 100644 --- a/src/components/panels/ToolsPanel.vue +++ b/src/components/panels/ToolsPanel.vue @@ -107,21 +107,27 @@ 'heatersCount', 'temperature_fans', 'temperature_sensors', - ]) + ]), + datasets: { + get () { + return this.$store.state.printer.tempHistory.datasets + } + } }, created() { }, methods: { - fillData () { - this.loaded = true; - this.chartdata = { - datasets: this.datasets - } - } + }, mounted () { - this.fillData(); + this.chartdata = { + datasets: this.datasets + } + + setTimeout(() => { + this.loaded = true + }, 1000) }, } diff --git a/src/store/printer/tempHistory/mutations.js b/src/store/printer/tempHistory/mutations.js index 77a3e79f..92c0080b 100644 --- a/src/store/printer/tempHistory/mutations.js +++ b/src/store/printer/tempHistory/mutations.js @@ -28,7 +28,7 @@ export default { }, type: keySplit[0], time: time - }, { root: true}); + }); } } }); @@ -82,7 +82,7 @@ export default { this.commit('printer/tempHistory/addHeater', { name: payload.name, type: payload.type, - }, { root: true }); + }); index = state.datasets.findIndex(element => element.label === payload.name); } let index_target = state.datasets.findIndex(element => element.label === payload.name+'_target');