Skip to content

Commit

Permalink
Add prop for inline plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-shuy committed Dec 13, 2017
1 parent ae13d71 commit 5486560
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 45 deletions.
12 changes: 9 additions & 3 deletions src/BaseCharts/Bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},
data () {
Expand All @@ -65,13 +71,13 @@ export default {
}]
}
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -80,7 +86,7 @@ export default {
type: 'bar',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Bubble.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -67,13 +73,13 @@ export default {
}]
}
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -83,7 +89,7 @@ export default {
type: 'bubble',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Doughnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -50,13 +56,13 @@ export default {
_chart: null,
defaultOptions: {
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -66,7 +72,7 @@ export default {
type: 'doughnut',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/HorizontalBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -67,13 +73,13 @@ export default {
}]
}
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options, type) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -82,7 +88,7 @@ export default {
type: 'horizontalBar',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -65,13 +71,13 @@ export default {
}]
}
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -81,7 +87,7 @@ export default {
type: 'line',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -50,13 +56,13 @@ export default {
_chart: null,
defaultOptions: {
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -66,7 +72,7 @@ export default {
type: 'pie',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/PolarArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -50,13 +56,13 @@ export default {
_chart: null,
defaultOptions: {
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -66,7 +72,7 @@ export default {
type: 'polarArea',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -50,13 +56,13 @@ export default {
_chart: null,
defaultOptions: {
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -66,7 +72,7 @@ export default {
type: 'radar',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
12 changes: 9 additions & 3 deletions src/BaseCharts/Scatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export default {
},
styles: {
type: Object
},
plugins: {
type: Array,
default () {
return []
}
}
},

Expand All @@ -56,13 +62,13 @@ export default {
}]
}
},
plugins: []
_plugins: this.plugins
}
},

methods: {
addPlugin (plugin) {
this.plugins.push(plugin)
this._plugins.push(plugin)
},
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
Expand All @@ -72,7 +78,7 @@ export default {
type: 'scatter',
data: data,
options: chartOptions,
plugins: this.plugins
plugins: this._plugins
}
)
}
Expand Down
26 changes: 24 additions & 2 deletions test/unit/specs/Bar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,31 @@ describe('BarChart', () => {
components: { BarChart }
}).$mount(el)

expect(vm.$children[0].plugins).to.exist
expect(vm.$children[0]._plugins).to.exist
vm.$children[0].addPlugin(testPlugin)

expect(vm.$children[0].plugins.length).to.equal(1)
expect(vm.$children[0]._plugins.length).to.equal(1)
})

it('should add inline plugins based on prop', () => {
const testPlugin = {
id: 'test'
}

const vm = new Vue({
render: function (createElement) {
return createElement(
BarChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { BarChart }
}).$mount(el)

expect(vm.$children[0]._plugins).to.exist
expect(vm.$children[0]._plugins.length).to.equal(1)
})
})
Loading

0 comments on commit 5486560

Please sign in to comment.