Skip to content

Commit

Permalink
Merge pull request #36 from apertureless/feature/destroy_chartinstance
Browse files Browse the repository at this point in the history
🔨 Change reactiveMixins to fix #35
  • Loading branch information
apertureless authored Feb 14, 2017
2 parents 53fb0d8 + aa76f51 commit e441ed2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
36 changes: 17 additions & 19 deletions src/mixins/reactiveData.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@ module.exports = {
if (oldData) {
let chart = this._chart

let newDataLabels = newData.datasets.map((dataset) => {
// Get new and old DataSet Labels
let newDatasetLabels = newData.datasets.map((dataset) => {
return dataset.label
})

let oldDataLabels = oldData.datasets.map((dataset) => {
let oldDatasetLabels = oldData.datasets.map((dataset) => {
return dataset.label
})

if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
this.forceUpdate(newData, chart)
// Stringify 'em for easier compare
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) {
newData.datasets.forEach((dataset, i) => {
chart.data.datasets[i].data = dataset.data
})

chart.data.labels = newData.labels
chart.update()
} else {
this.forceRender()
chart.destroy()
this.renderChart(this.chartData, this.options)
}
}
}
}
},
methods: {
forceUpdate (newData, chart) {
newData.datasets.forEach((dataset, i) => {
chart.data.datasets[i].data = dataset.data
})

chart.data.labels = newData.labels
chart.update()
},

forceRender () {
this.renderChart(this.chartData, this.options)
}
}
}
16 changes: 12 additions & 4 deletions src/mixins/reactiveProp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,33 @@ module.exports = {
if (oldData) {
let chart = this._chart

let newDataLabels = newData.datasets.map((dataset) => {
// Get new and old DataSet Labels
let newDatasetLabels = newData.datasets.map((dataset) => {
return dataset.label
})

let oldDataLabels = oldData.datasets.map((dataset) => {
let oldDatasetLabels = oldData.datasets.map((dataset) => {
return dataset.label
})

if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
// Stringify 'em for easier compare
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) {
newData.datasets.forEach((dataset, i) => {
chart.data.datasets[i].data = dataset.data
})

chart.data.labels = newData.labels
chart.update()
} else {
chart.destroy()
this.renderChart(this.chartData, this.options)
}
}
}
}
}
},
}

0 comments on commit e441ed2

Please sign in to comment.