Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Change reactiveMixins to fix #35 #36

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}
}
}
},
}