From a5b58c3b98d618df57bfc7d9cb217552b97c235e Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 4 Aug 2017 15:06:22 -0400 Subject: [PATCH 1/4] Add support for xLabels and yLabels --- src/mixins/reactiveProp.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mixins/reactiveProp.js b/src/mixins/reactiveProp.js index c9da8ff..dc779ea 100644 --- a/src/mixins/reactiveProp.js +++ b/src/mixins/reactiveProp.js @@ -47,8 +47,16 @@ module.exports = { } } }) - - chart.data.labels = newData.labels + + if (newData.hasOwnProperty('labels')) { + chart.data.labels = newData.labels + } + if (newData.hasOwnProperty('xLabels')) { + chart.data.xLabels = newData.xLabels + } + if (newData.hasOwnProperty('yLabels')) { + chart.data.yLabels = newData.yLabels + } chart.update() } else { chart.destroy() From 1e392091eaf49c840944b085e98d06f57c2e15bf Mon Sep 17 00:00:00 2001 From: Dan Date: Fri, 4 Aug 2017 15:06:22 -0400 Subject: [PATCH 2/4] Add support for xLabels and yLabels --- src/mixins/reactiveData.js | 10 +++++++++- src/mixins/reactiveProp.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/mixins/reactiveData.js b/src/mixins/reactiveData.js index b15b49b..6b3ccf8 100644 --- a/src/mixins/reactiveData.js +++ b/src/mixins/reactiveData.js @@ -48,7 +48,15 @@ module.exports = { } }) - chart.data.labels = newData.labels + if (newData.hasOwnProperty('labels')) { + chart.data.labels = newData.labels + } + if (newData.hasOwnProperty('xLabels')) { + chart.data.xLabels = newData.xLabels + } + if (newData.hasOwnProperty('yLabels')) { + chart.data.yLabels = newData.yLabels + } chart.update() } else { chart.destroy() diff --git a/src/mixins/reactiveProp.js b/src/mixins/reactiveProp.js index c9da8ff..e90a27c 100644 --- a/src/mixins/reactiveProp.js +++ b/src/mixins/reactiveProp.js @@ -48,7 +48,15 @@ module.exports = { } }) - chart.data.labels = newData.labels + if (newData.hasOwnProperty('labels')) { + chart.data.labels = newData.labels + } + if (newData.hasOwnProperty('xLabels')) { + chart.data.xLabels = newData.xLabels + } + if (newData.hasOwnProperty('yLabels')) { + chart.data.yLabels = newData.yLabels + } chart.update() } else { chart.destroy() From 0e419886b1659e539d7305d237e3f013c7eb582c Mon Sep 17 00:00:00 2001 From: bertolds Date: Mon, 7 Aug 2017 09:42:16 -0400 Subject: [PATCH 3/4] Add cross-env to all steps of build script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db01e0a..1a6e55f 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "e2e": "node test/e2e/runner.js", "test": "npm run unit", "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs", - "release": "webpack --progress --hide-modules --config ./build/webpack.release.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js && webpack --progress --hide-modules --config ./build/webpack.release.full.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.full.min.js", + "release": "webpack --progress --hide-modules --config ./build/webpack.release.js && cross-env NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js && webpack --progress --hide-modules --config ./build/webpack.release.full.js && cross-env NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.full.min.js", "prepublish": "yarn run lint && yarn run test && yarn run build" }, "dependencies": { From 676a60a363298f71ef2b789c3bf4a4cb0adb5743 Mon Sep 17 00:00:00 2001 From: bertolds Date: Mon, 7 Aug 2017 09:49:46 -0400 Subject: [PATCH 4/4] fix linting errors --- src/mixins/reactiveProp.js | 73 ++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/mixins/reactiveProp.js b/src/mixins/reactiveProp.js index 71ded74..e90a27c 100644 --- a/src/mixins/reactiveProp.js +++ b/src/mixins/reactiveProp.js @@ -1,74 +1,71 @@ module.exports = { props: { chartData: { - required: true, - }, + required: true + } }, watch: { - chartData: { - handler(newData, oldData) { + 'chartData': { + handler (newData, oldData) { if (oldData) { - let chart = this._chart; + let chart = this._chart // Get new and old DataSet Labels - let newDatasetLabels = newData.datasets.map(dataset => { - return dataset.label; - }); + let newDatasetLabels = newData.datasets.map((dataset) => { + return dataset.label + }) - let oldDatasetLabels = oldData.datasets.map(dataset => { - return dataset.label; - }); + let oldDatasetLabels = oldData.datasets.map((dataset) => { + return dataset.label + }) // Stringify 'em for easier compare - const oldLabels = JSON.stringify(oldDatasetLabels); - const newLabels = JSON.stringify(newDatasetLabels); + const oldLabels = JSON.stringify(oldDatasetLabels) + const newLabels = JSON.stringify(newDatasetLabels) // Check if Labels are equal and if dataset length is equal - if ( - newLabels === oldLabels && - oldData.datasets.length === newData.datasets.length - ) { + if (newLabels === oldLabels && oldData.datasets.length === newData.datasets.length) { newData.datasets.forEach((dataset, i) => { // Get new and old dataset keys - const oldDatasetKeys = Object.keys(oldData.datasets[i]); - const newDatasetKeys = Object.keys(dataset); + const oldDatasetKeys = Object.keys(oldData.datasets[i]) + const newDatasetKeys = Object.keys(dataset) // Get keys that aren't present in the new data - const deletionKeys = oldDatasetKeys.filter(key => { - return key !== '_meta' && newDatasetKeys.indexOf(key) === -1; - }); + const deletionKeys = oldDatasetKeys.filter((key) => { + return key !== '_meta' && newDatasetKeys.indexOf(key) === -1 + }) // Remove outdated key-value pairs - deletionKeys.forEach(deletionKey => { - delete chart.data.datasets[i][deletionKey]; - }); + deletionKeys.forEach((deletionKey) => { + delete chart.data.datasets[i][deletionKey] + }) // Update attributes individually to avoid re-rendering the entire chart for (const attribute in dataset) { if (dataset.hasOwnProperty(attribute)) { - chart.data.datasets[i][attribute] = dataset[attribute]; + chart.data.datasets[i][attribute] = dataset[attribute] } } - }); + }) if (newData.hasOwnProperty('labels')) { - chart.data.labels = newData.labels; + chart.data.labels = newData.labels } if (newData.hasOwnProperty('xLabels')) { - chart.data.xLabels = newData.xLabels; + chart.data.xLabels = newData.xLabels } if (newData.hasOwnProperty('yLabels')) { - chart.data.yLabels = newData.yLabels; + chart.data.yLabels = newData.yLabels } - chart.update(); + chart.update() } else { - chart.destroy(); - this.renderChart(this.chartData, this.options); + chart.destroy() + this.renderChart(this.chartData, this.options) } } else { - this.renderChart(this.chartData, this.options); + this.renderChart(this.chartData, this.options) } - }, - }, - }, -}; + } + } + } +}