Skip to content

Commit 0506b4e

Browse files
authored
Merge pull request #276 from daniel-shuy/develop
Add prop for inline plugins
2 parents ae13d71 + 072724f commit 0506b4e

18 files changed

+297
-45
lines changed

src/BaseCharts/Bar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export default {
4141
},
4242
styles: {
4343
type: Object
44+
},
45+
plugins: {
46+
type: Array,
47+
default () {
48+
return []
49+
}
4450
}
4551
},
4652
data () {
@@ -65,13 +71,13 @@ export default {
6571
}]
6672
}
6773
},
68-
plugins: []
74+
_plugins: this.plugins
6975
}
7076
},
7177

7278
methods: {
7379
addPlugin (plugin) {
74-
this.plugins.push(plugin)
80+
this.$data._plugins.push(plugin)
7581
},
7682
renderChart (data, options) {
7783
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -80,7 +86,7 @@ export default {
8086
type: 'bar',
8187
data: data,
8288
options: chartOptions,
83-
plugins: this.plugins
89+
plugins: this.$data._plugins
8490
}
8591
)
8692
}

src/BaseCharts/Bubble.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -67,13 +73,13 @@ export default {
6773
}]
6874
}
6975
},
70-
plugins: []
76+
_plugins: this.plugins
7177
}
7278
},
7379

7480
methods: {
7581
addPlugin (plugin) {
76-
this.plugins.push(plugin)
82+
this.$data._plugins.push(plugin)
7783
},
7884
renderChart (data, options) {
7985
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -83,7 +89,7 @@ export default {
8389
type: 'bubble',
8490
data: data,
8591
options: chartOptions,
86-
plugins: this.plugins
92+
plugins: this.$data._plugins
8793
}
8894
)
8995
}

src/BaseCharts/Doughnut.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -50,13 +56,13 @@ export default {
5056
_chart: null,
5157
defaultOptions: {
5258
},
53-
plugins: []
59+
_plugins: this.plugins
5460
}
5561
},
5662

5763
methods: {
5864
addPlugin (plugin) {
59-
this.plugins.push(plugin)
65+
this.$data._plugins.push(plugin)
6066
},
6167
renderChart (data, options) {
6268
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -66,7 +72,7 @@ export default {
6672
type: 'doughnut',
6773
data: data,
6874
options: chartOptions,
69-
plugins: this.plugins
75+
plugins: this.$data._plugins
7076
}
7177
)
7278
}

src/BaseCharts/HorizontalBar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -67,13 +73,13 @@ export default {
6773
}]
6874
}
6975
},
70-
plugins: []
76+
_plugins: this.plugins
7177
}
7278
},
7379

7480
methods: {
7581
addPlugin (plugin) {
76-
this.plugins.push(plugin)
82+
this.$data._plugins.push(plugin)
7783
},
7884
renderChart (data, options, type) {
7985
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -82,7 +88,7 @@ export default {
8288
type: 'horizontalBar',
8389
data: data,
8490
options: chartOptions,
85-
plugins: this.plugins
91+
plugins: this.$data._plugins
8692
}
8793
)
8894
}

src/BaseCharts/Line.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -65,13 +71,13 @@ export default {
6571
}]
6672
}
6773
},
68-
plugins: []
74+
_plugins: this.plugins
6975
}
7076
},
7177

7278
methods: {
7379
addPlugin (plugin) {
74-
this.plugins.push(plugin)
80+
this.$data._plugins.push(plugin)
7581
},
7682
renderChart (data, options) {
7783
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -81,7 +87,7 @@ export default {
8187
type: 'line',
8288
data: data,
8389
options: chartOptions,
84-
plugins: this.plugins
90+
plugins: this.$data._plugins
8591
}
8692
)
8793
}

src/BaseCharts/Pie.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -50,13 +56,13 @@ export default {
5056
_chart: null,
5157
defaultOptions: {
5258
},
53-
plugins: []
59+
_plugins: this.plugins
5460
}
5561
},
5662

5763
methods: {
5864
addPlugin (plugin) {
59-
this.plugins.push(plugin)
65+
this.$data._plugins.push(plugin)
6066
},
6167
renderChart (data, options) {
6268
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -66,7 +72,7 @@ export default {
6672
type: 'pie',
6773
data: data,
6874
options: chartOptions,
69-
plugins: this.plugins
75+
plugins: this.$data._plugins
7076
}
7177
)
7278
}

src/BaseCharts/PolarArea.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -50,13 +56,13 @@ export default {
5056
_chart: null,
5157
defaultOptions: {
5258
},
53-
plugins: []
59+
_plugins: this.plugins
5460
}
5561
},
5662

5763
methods: {
5864
addPlugin (plugin) {
59-
this.plugins.push(plugin)
65+
this.$data._plugins.push(plugin)
6066
},
6167
renderChart (data, options) {
6268
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -66,7 +72,7 @@ export default {
6672
type: 'polarArea',
6773
data: data,
6874
options: chartOptions,
69-
plugins: this.plugins
75+
plugins: this.$data._plugins
7076
}
7177
)
7278
}

src/BaseCharts/Radar.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -50,13 +56,13 @@ export default {
5056
_chart: null,
5157
defaultOptions: {
5258
},
53-
plugins: []
59+
_plugins: this.plugins
5460
}
5561
},
5662

5763
methods: {
5864
addPlugin (plugin) {
59-
this.plugins.push(plugin)
65+
this.$data._plugins.push(plugin)
6066
},
6167
renderChart (data, options) {
6268
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -66,7 +72,7 @@ export default {
6672
type: 'radar',
6773
data: data,
6874
options: chartOptions,
69-
plugins: this.plugins
75+
plugins: this.$data._plugins
7076
}
7177
)
7278
}

src/BaseCharts/Scatter.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export default {
4242
},
4343
styles: {
4444
type: Object
45+
},
46+
plugins: {
47+
type: Array,
48+
default () {
49+
return []
50+
}
4551
}
4652
},
4753

@@ -56,13 +62,13 @@ export default {
5662
}]
5763
}
5864
},
59-
plugins: []
65+
_plugins: this.plugins
6066
}
6167
},
6268

6369
methods: {
6470
addPlugin (plugin) {
65-
this.plugins.push(plugin)
71+
this.$data._plugins.push(plugin)
6672
},
6773
renderChart (data, options) {
6874
let chartOptions = mergeOptions(this.defaultOptions, options)
@@ -72,7 +78,7 @@ export default {
7278
type: 'scatter',
7379
data: data,
7480
options: chartOptions,
75-
plugins: this.plugins
81+
plugins: this.$data._plugins
7682
}
7783
)
7884
}

test/unit/specs/Bar.spec.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,31 @@ describe('BarChart', () => {
7676
components: { BarChart }
7777
}).$mount(el)
7878

79-
expect(vm.$children[0].plugins).to.exist
79+
expect(vm.$children[0].$data._plugins).to.exist
8080
vm.$children[0].addPlugin(testPlugin)
8181

82-
expect(vm.$children[0].plugins.length).to.equal(1)
82+
expect(vm.$children[0].$data._plugins.length).to.equal(1)
83+
})
84+
85+
it('should add inline plugins based on prop', () => {
86+
const testPlugin = {
87+
id: 'test'
88+
}
89+
90+
const vm = new Vue({
91+
render: function (createElement) {
92+
return createElement(
93+
BarChart, {
94+
props: {
95+
plugins: [testPlugin]
96+
}
97+
}
98+
)
99+
},
100+
components: { BarChart }
101+
}).$mount(el)
102+
103+
expect(vm.$children[0].$data._plugins).to.exist
104+
expect(vm.$children[0].$data._plugins.length).to.equal(1)
83105
})
84106
})

0 commit comments

Comments
 (0)