Add support for inline plugins

This commit is contained in:
Karl Viiburg
2017-07-03 08:12:28 +03:00
parent 6736715895
commit ef127686cd
8 changed files with 56 additions and 16 deletions

View File

@@ -56,18 +56,23 @@ export default Vue.extend({
barPercentage: 0.2 barPercentage: 0.2
}] }]
} }
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
this._chart = new Chart( this._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'bar', type: 'bar',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -56,11 +56,15 @@ export default Vue.extend({
barPercentage: 0.2 barPercentage: 0.2
}] }]
} }
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -68,7 +72,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'bubble', type: 'bubble',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -39,11 +39,15 @@ export default Vue.extend({
data () { data () {
return { return {
defaultOptions: { defaultOptions: {
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -51,7 +55,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'doughnut', type: 'doughnut',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -56,18 +56,23 @@ export default Vue.extend({
barPercentage: 0.2 barPercentage: 0.2
}] }]
} }
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options, type) { renderChart (data, options, type) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
this._chart = new Chart( this._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'horizontalBar', type: 'horizontalBar',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -54,11 +54,15 @@ export default Vue.extend({
} }
}] }]
} }
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -66,7 +70,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'line', type: 'line',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -39,11 +39,15 @@ export default Vue.extend({
data () { data () {
return { return {
defaultOptions: { defaultOptions: {
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -51,7 +55,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'pie', type: 'pie',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -39,11 +39,15 @@ export default Vue.extend({
data () { data () {
return { return {
defaultOptions: { defaultOptions: {
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -51,7 +55,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'polarArea', type: 'polarArea',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()

View File

@@ -39,11 +39,15 @@ export default Vue.extend({
data () { data () {
return { return {
defaultOptions: { defaultOptions: {
} },
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
},
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options) let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -51,7 +55,8 @@ export default Vue.extend({
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'radar', type: 'radar',
data: data, data: data,
options: chartOptions options: chartOptions,
plugins: this.plugins
} }
) )
this._chart.generateLegend() this._chart.generateLegend()