mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
wip: Refactor mixin in seperate functions
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
/* eslint-disable */
|
||||
|
||||
function dataHandler (newData, oldData) {
|
||||
if (oldData) {
|
||||
let chart = this.$data._chart
|
||||
const chart = this.$data._chart
|
||||
_checkChanges(newData, oldData, chart)
|
||||
} else {
|
||||
_destroyAndRenderChart(chart)
|
||||
}
|
||||
|
||||
function _checkChanges (newData, oldData, chart) {
|
||||
// Get new and old DataSet Labels
|
||||
let newDatasetLabels = newData.datasets.map((dataset) => {
|
||||
return dataset.label
|
||||
@@ -51,16 +58,16 @@ function dataHandler (newData, oldData) {
|
||||
}
|
||||
chart.update()
|
||||
} else {
|
||||
_destroyAndRenderChart(chart)
|
||||
}
|
||||
}
|
||||
|
||||
function _destroyAndRenderChart (chart) {
|
||||
if (chart) {
|
||||
chart.destroy()
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
} else {
|
||||
if (this.$data._chart) {
|
||||
this.$data._chart.destroy()
|
||||
}
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
}
|
||||
|
||||
export const reactiveData = {
|
||||
data () {
|
||||
@@ -77,7 +84,6 @@ export const reactiveData = {
|
||||
export const reactiveProp = {
|
||||
props: {
|
||||
chartData: {
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => {}
|
||||
}
|
||||
@@ -91,3 +97,4 @@ export default {
|
||||
reactiveData,
|
||||
reactiveProp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user