From 45e543b636969c7949dcf0a3b7d5d413ac4b7c78 Mon Sep 17 00:00:00 2001 From: Jakub Juszczak Date: Sun, 2 Oct 2016 10:31:14 +0200 Subject: [PATCH 01/11] =?UTF-8?q?=E2=9C=A8=20Add=20reactiveData=20mixin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mixins/reactiveData.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/mixins/reactiveData.js diff --git a/src/mixins/reactiveData.js b/src/mixins/reactiveData.js new file mode 100644 index 00000000..50d9ec63 --- /dev/null +++ b/src/mixins/reactiveData.js @@ -0,0 +1,34 @@ +module.exports = { + data () { + return { + chartData: null + } + }, + watch: { + 'chartData': { + handler (newData, oldData) { + if (oldData) { + let chart = this._chart + + let newDataLabels = newData.datasets.map((dataset) => { + return dataset.label + }) + + let oldDataLabels = oldData.datasets.map((dataset) => { + return dataset.label + }) + + if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) { + newData.datasets.forEach((dataset, i) => { + chart.data.datasets[i].data = dataset.data + }) + chart.data.labels = newData.labels + chart.update() + } else { + this.renderChart(this.chartData, this.options) + } + } + } + } + } +} From a7194b990f28c548ae228517bfe76dff3ae7ce2e Mon Sep 17 00:00:00 2001 From: Jakub Juszczak Date: Sun, 2 Oct 2016 10:32:30 +0200 Subject: [PATCH 02/11] =?UTF-8?q?=E2=9C=A8=20Add=20reactive=20Data=20examp?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/examples/ReactiveExample.js | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/examples/ReactiveExample.js diff --git a/src/examples/ReactiveExample.js b/src/examples/ReactiveExample.js new file mode 100644 index 00000000..1f282b84 --- /dev/null +++ b/src/examples/ReactiveExample.js @@ -0,0 +1,41 @@ +import BarChart from '../BaseCharts/Bar' +import reactiveData from '../mixins/reactiveData' + +export default BarChart.extend({ + mixins: [reactiveData], + data () { + return { + chartData: '' + } + }, + created () { + this.fillData() + }, + + mounted () { + this.renderChart(this.chartData) + + setInterval(() => { + this.fillData() + }, 5000) + }, + + methods: { + fillData () { + this.chartData = { + labels: ['January' + this.getRandomInt(), 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], + datasets: [ + { + label: 'Data One', + backgroundColor: '#f87979', + data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()] + } + ] + } + }, + + getRandomInt () { + return Math.floor(Math.random() * (50 - 5 + 1)) + 5 + } + } +}) From 59cc74a00d050912e03486f4bee21ab8ae4faa59 Mon Sep 17 00:00:00 2001 From: Jakub Juszczak Date: Sun, 2 Oct 2016 10:34:06 +0200 Subject: [PATCH 03/11] =?UTF-8?q?=E2=9C=A8=20Add=20reactiveData=20Example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/examples/App.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/examples/App.vue b/src/examples/App.vue index cfc2c192..8f7abe77 100644 --- a/src/examples/App.vue +++ b/src/examples/App.vue @@ -1,6 +1,7 @@