Compare commits

..

17 Commits

Author SHA1 Message Date
Jakub Juszczak
4347fe906e chore(release): 3.1.0 2018-01-12 14:08:23 +01:00
Jakub Juszczak
662329846e chore(docs): Update README with section about single file components and reactivemixins options 2018-01-12 13:59:43 +01:00
Jakub Juszczak
ecae747ba3 chore(examples): Update reactive prop examples 2018-01-12 13:52:45 +01:00
Jakub Juszczak
75bfa5ccbc chore(dependencies): Remove nightwatch as not used 2018-01-12 13:47:38 +01:00
Jakub
8f91703e9f Merge pull request #292 from apertureless/feature/remove_defaults
Feature/remove defaults
2018-01-12 13:35:25 +01:00
Jakub Juszczak
ac5d4d824c feat(charts): Remove default styling 2018-01-12 13:30:29 +01:00
Jakub Juszczak
db0040e613 chore(dependencies): Remove lodash-merge 2018-01-12 13:29:59 +01:00
Jakub
3b46bc8f03 Merge pull request #291 from apertureless/feature/fix_reactive_mixins
fix(mixins): Check for chartjs instance before rendering chart
2018-01-12 13:16:43 +01:00
Jakub Juszczak
39ff839d92 fix(mixins): Check for chartjs instance before rendering chart
Closes #288
2018-01-12 13:13:46 +01:00
Jakub
0506b4ee35 Merge pull request #276 from daniel-shuy/develop
Add prop for inline plugins
2017-12-15 09:50:49 +01:00
Daniel Shuy
072724fc6f Fix references to private _plugins data property 2017-12-13 20:58:43 +08:00
Daniel Shuy
dd9a5b855d Fix test cases for inline prop 2017-12-13 20:33:40 +08:00
Daniel Shuy
5486560257 Add prop for inline plugins 2017-12-13 20:10:01 +08:00
Jakub
ae13d71081 Merge pull request #266 from Beomi/develop
Fix typo on readme.md (Three shaking)
2017-12-01 14:35:37 +01:00
Beomi
1902bf0b0e Fix typo on readme.md
`three shaking` > `tree shaking`
2017-12-01 15:05:36 +09:00
Jakub
b0ad387856 Merge pull request #253 from bevingtongroup/fix-windows-node-env
fix NODE_ENV=... on windows
2017-11-14 17:11:27 +01:00
Cormac Relf
b7074e428f windows build: fix NODE_ENV on windows 2017-11-14 17:14:55 +11:00
31 changed files with 925 additions and 1046 deletions

View File

@@ -1,3 +1,22 @@
# Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
<a name="3.1.0"></a>
# [3.1.0](https://github.com/apertureless/vue-chartjs/compare/v3.0.2...v3.1.0) (2018-01-12)
### Bug Fixes
* **mixins:** Check for chartjs instance before rendering chart ([39ff839](https://github.com/apertureless/vue-chartjs/commit/39ff839)), closes [#288](https://github.com/apertureless/vue-chartjs/issues/288)
### Features
* **charts:** Remove default styling ([ac5d4d8](https://github.com/apertureless/vue-chartjs/commit/ac5d4d8))
# Change Log # Change Log
## [v3.0.1](https://github.com/apertureless/vue-chartjs/tree/v3.0.1) (2017-11-06) ## [v3.0.1](https://github.com/apertureless/vue-chartjs/tree/v3.0.1) (2017-11-06)

View File

@@ -76,7 +76,7 @@ However Chart.js is a `peerDependencies` so you have to install it separately. I
### Webpack 2 ### Webpack 2
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js` If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js`
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you three shaking will work. Like in the bundled version, `Chart.js` is a `peerDependencies` and need to be installed. It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you tree shaking will work. Like in the bundled version, `Chart.js` is a `peerDependencies` and need to be installed.
## How to use ## How to use
@@ -165,7 +165,11 @@ However you can simply implement this on your own or use one of the two mixins w
Both are included in the `mixins` module. Both are included in the `mixins` module.
The mixins automatically create `chartData` as a prop or data. And add a watcher. If data has changed, the chart will update. The mixins automatically create `chartData` as a prop or data. And add a watcher. If data has changed, the chart will update.
However keep in mind the limitations of vue and javascript for mutations on arrays and objects. More info [here](http://vue-chartjs.org/#/home?id=reactive-data) However keep in mind the limitations of vue and javascript for mutations on arrays and objects.
**It is important that you pass your options in a local variable named `options`!**
The reason is that if the mixin re-renders the chart it calls `this.renderChart(this.chartData, this.options`)` so don't pass in the options object directly or it will be ignored.
More info [here](http://vue-chartjs.org/#/home?id=reactive-data)
```javascript ```javascript
// MonthlyIncome.js // MonthlyIncome.js
@@ -229,6 +233,10 @@ export default {
} }
``` ```
## Single File Components
You can create your components in Vues single file components. However it is important that you **do not** have the `<template></template>` included. Because Vue can't merge tempaltes. And the template is included in the mixin. If you leave the template tag in your component, it will overwrite the one which comes from the base chart and you will have a blank screen.
## Available Charts ## Available Charts
### Bar Chart ### Bar Chart

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "vue-chartjs", "name": "vue-chartjs",
"version": "3.0.0", "version": "3.1.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "vue-chartjs", "name": "vue-chartjs",
"version": "3.0.2", "version": "3.1.0",
"description": "Vue.js wrapper for chart.js for creating beautiful charts.", "description": "Vue.js wrapper for chart.js for creating beautiful charts.",
"author": "Jakub Juszczak <jakub@posteo.de>", "author": "Jakub Juszczak <jakub@posteo.de>",
"homepage": "http://vue-chartjs.org", "homepage": "http://vue-chartjs.org",
@@ -53,12 +53,10 @@
"e2e": "node test/e2e/runner.js", "e2e": "node test/e2e/runner.js",
"test": "npm run unit", "test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs", "lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
"release": "webpack --progress --hide-modules --config ./build/webpack.release.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js", "release": "webpack --progress --hide-modules --config ./build/webpack.release.js && cross-env NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js",
"prepublishOnly": "yarn run lint && yarn run test && yarn run build" "prepublishOnly": "yarn run lint && yarn run test && yarn run build"
}, },
"dependencies": { "dependencies": {},
"lodash.merge": "^4.6.0"
},
"peerDependencies": { "peerDependencies": {
"chart.js": "2.7.x" "chart.js": "2.7.x"
}, },
@@ -72,7 +70,7 @@
"chart.js": "2.7.0", "chart.js": "2.7.0",
"chromedriver": "^2.28.0", "chromedriver": "^2.28.0",
"connect-history-api-fallback": "^1.1.0", "connect-history-api-fallback": "^1.1.0",
"cross-env": "^3.2.4", "cross-env": "^5.1.1",
"cross-spawn": "^5.1.0", "cross-spawn": "^5.1.0",
"css-loader": "^0.28.0", "css-loader": "^0.28.0",
"eslint": "^3.19.0", "eslint": "^3.19.0",
@@ -108,7 +106,6 @@
"karma-webpack": "2", "karma-webpack": "2",
"lolex": "^1.6.0", "lolex": "^1.6.0",
"mocha": "^3.1.0", "mocha": "^3.1.0",
"nightwatch": "^0.9.14",
"opn": "^5.1.0", "opn": "^5.1.0",
"ora": "^1.2.0", "ora": "^1.2.0",
"phantomjs-prebuilt": "^2.1.13", "phantomjs-prebuilt": "^2.1.13",

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -41,46 +40,32 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
scales: {
yAxes: [{
ticks: {
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [ {
gridLines: {
display: false
},
categoryPercentage: 0.5,
barPercentage: 0.2
}]
}
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'bar', type: 'bar',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,48 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
scales: {
yAxes: [{
ticks: {
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [ {
gridLines: {
display: false
},
categoryPercentage: 0.5,
barPercentage: 0.2
}]
}
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'bubble', type: 'bubble',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,31 +41,34 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
renderChart (data, options) {
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'doughnut', type: 'doughnut',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,47 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
scales: {
yAxes: [{
ticks: {
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [ {
gridLines: {
display: false
},
categoryPercentage: 0.5,
barPercentage: 0.2
}]
}
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options, type) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'horizontalBar', type: 'horizontalBar',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,46 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
scales: {
yAxes: [{
ticks: {
beginAtZero: true
},
gridLines: {
display: false
}
}],
xAxes: [ {
gridLines: {
display: false
}
}]
}
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'line', type: 'line',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,31 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'pie', type: 'pie',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,31 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'polarArea', type: 'polarArea',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,31 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'radar', type: 'radar',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -1,5 +1,4 @@
import Chart from 'chart.js' import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default { export default {
render: function (createElement) { render: function (createElement) {
@@ -42,37 +41,33 @@ export default {
}, },
styles: { styles: {
type: Object type: Object
},
plugins: {
type: Array,
default () {
return []
}
} }
}, },
data () { data () {
return { return {
_chart: null, _chart: null,
defaultOptions: { _plugins: this.plugins
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}]
}
},
plugins: []
} }
}, },
methods: { methods: {
addPlugin (plugin) { addPlugin (plugin) {
this.plugins.push(plugin) this.$data._plugins.push(plugin)
}, },
renderChart (data, options) { renderChart (data, options) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this.$data._chart = new Chart( this.$data._chart = new Chart(
this.$refs.canvas.getContext('2d'), { this.$refs.canvas.getContext('2d'), {
type: 'scatter', type: 'scatter',
data: data, data: data,
options: chartOptions, options: options,
plugins: this.plugins plugins: this.$data._plugins
} }
) )
} }

View File

@@ -5,6 +5,11 @@
<bar-example></bar-example> <bar-example></bar-example>
</div> </div>
<div class="Chart">
<h1 style="text-align:center;">Horizontal Barchart</h1>
<horizontal-bar-example></horizontal-bar-example>
</div>
<div class="Chart"> <div class="Chart">
<h1 style="text-align:center;">Barchart with reactive mixing for live data</h1> <h1 style="text-align:center;">Barchart with reactive mixing for live data</h1>
<reactive-example></reactive-example> <reactive-example></reactive-example>
@@ -63,6 +68,7 @@
import ReactiveExample from './ReactiveExample' import ReactiveExample from './ReactiveExample'
import ReactivePropExample from './ReactivePropExample' import ReactivePropExample from './ReactivePropExample'
import ScatterExample from './ScatterExample' import ScatterExample from './ScatterExample'
import HorizontalBarExample from './HorizontalBarExample'
export default { export default {
components: { components: {
@@ -75,7 +81,8 @@
BubbleExample, BubbleExample,
ReactiveExample, ReactiveExample,
ReactivePropExample, ReactivePropExample,
ScatterExample ScatterExample,
HorizontalBarExample
}, },
data () { data () {
return { return {

View File

@@ -4,17 +4,19 @@ import reactiveData from '../mixins/reactiveData'
export default { export default {
extends: Bar, extends: Bar,
mixins: [reactiveData], mixins: [reactiveData],
data () { data: () => ({
return { chartData: '',
chartData: '' options: {
responsive: true,
maintainAspectRatio: false
} }
}, }),
created () { created () {
this.fillData() this.fillData()
}, },
mounted () { mounted () {
this.renderChart(this.chartData, {responsive: true, maintainAspectRatio: false}) this.renderChart(this.chartData, this.options)
setInterval(() => { setInterval(() => {
this.fillData() this.fillData()

View File

@@ -4,8 +4,14 @@ import reactiveProp from '../mixins/reactiveProp'
export default { export default {
extends: Bar, extends: Bar,
mixins: [reactiveProp], mixins: [reactiveProp],
data: () => ({
options: {
responsive: true,
maintainAspectRatio: false
}
}),
mounted () { mounted () {
this.renderChart(this.chartData, {responsive: true, maintainAspectRatio: false}) this.renderChart(this.chartData, this.options)
} }
} }

View File

@@ -1,5 +0,0 @@
import merge from 'lodash.merge'
export function mergeOptions (obj, src) {
return merge(obj, src)
}

View File

@@ -63,6 +63,9 @@ module.exports = {
this.renderChart(this.chartData, this.options) this.renderChart(this.chartData, this.options)
} }
} else { } else {
if (this.$data._chart) {
this.$data._chart.destroy()
}
this.renderChart(this.chartData, this.options) this.renderChart(this.chartData, this.options)
} }
} }

View File

@@ -63,6 +63,9 @@ module.exports = {
this.renderChart(this.chartData, this.options) this.renderChart(this.chartData, this.options)
} }
} else { } else {
if (this.$data._chart) {
this.$data._chart.destroy()
}
this.renderChart(this.chartData, this.options) this.renderChart(this.chartData, this.options)
} }
} }

View File

@@ -76,9 +76,31 @@ describe('BarChart', () => {
components: { BarChart } components: { BarChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('BubbleChart', () => {
components: { BubbleChart } components: { BubbleChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
BubbleChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { BubbleChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('DoughnutChart', () => {
components: { DoughnutChart } components: { DoughnutChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
DoughnutChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { DoughnutChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('HorizontalBarChart', () => {
components: { HorizontalBarChart } components: { HorizontalBarChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
HorizontalBarChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { HorizontalBarChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('LineChart', () => {
components: { LineChart } components: { LineChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
LineChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { LineChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -75,9 +75,31 @@ describe('PieChart', () => {
components: { PieChart } components: { PieChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
PieChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { PieChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('PolarChart', () => {
components: { PolarChart } components: { PolarChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
PolarChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { PolarChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -75,9 +75,31 @@ describe('RadarChart', () => {
components: { RadarChart } components: { RadarChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
RadarChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { RadarChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -76,9 +76,31 @@ describe('ScatterChart', () => {
components: { ScatterChart } components: { ScatterChart }
}).$mount(el) }).$mount(el)
expect(vm.$children[0].plugins).to.exist expect(vm.$children[0].$data._plugins).to.exist
vm.$children[0].addPlugin(testPlugin) vm.$children[0].addPlugin(testPlugin)
expect(vm.$children[0].plugins.length).to.equal(1) expect(vm.$children[0].$data._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(
ScatterChart, {
props: {
plugins: [testPlugin]
}
}
)
},
components: { ScatterChart }
}).$mount(el)
expect(vm.$children[0].$data._plugins).to.exist
expect(vm.$children[0].$data._plugins.length).to.equal(1)
}) })
}) })

View File

@@ -1,54 +0,0 @@
import { mergeOptions } from '@/helpers/options'
describe('mergeOptions.js', () => {
const a = {
a: 'a',
b: 'a'
}
const b = {
a: 'b',
b: 'b'
}
const c = {
c: 'c'
}
const an = {
a: {
a: 'a'
},
b: {
b: 'a'
}
}
const bn = {
a: {
a: 'a'
},
b: {
b: 'b'
}
}
it('should replace old a and b if a and b are new', () => {
const ab = mergeOptions(a, b)
expect(ab).to.have.property('a').and.to.equal('b')
expect(ab).to.have.property('b').and.to.equal('b')
})
it('should add c if c is new', () => {
const ac = mergeOptions(a, c)
expect(ac).to.have.property('a').and.to.equal('b')
expect(ac).to.have.property('b').and.to.equal('b')
expect(ac).to.have.property('c').and.to.equal('c')
})
it('should replace old a and b if a and b are new in nested objects', () => {
const ab = mergeOptions(an, bn)
expect(ab).to.have.deep.property('a.a').and.to.equal('a')
expect(ab).to.have.deep.property('b.b').and.to.equal('b')
})
})

1355
yarn.lock

File diff suppressed because it is too large Load Diff