mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88cc75c614 | ||
|
|
cba152c7f8 | ||
|
|
b2f0a5ba03 | ||
|
|
b76236cf9b | ||
|
|
2a1377c01d | ||
|
|
c3f10a51f5 | ||
|
|
7ffefe4454 | ||
|
|
ca95e0f146 | ||
|
|
988d8f13b4 | ||
|
|
52c1c50206 | ||
|
|
482048b746 | ||
|
|
bb21a40506 | ||
|
|
e4ba9ea5a3 | ||
|
|
fee32b57df | ||
|
|
c0b854bd83 | ||
|
|
14413e438d | ||
|
|
7ddc385edb | ||
|
|
a62a108318 | ||
|
|
a1633c0d19 | ||
|
|
5ec1f31a4b | ||
|
|
ced81a58cc | ||
|
|
193b5cac33 | ||
|
|
dde366c154 | ||
|
|
4fe9a2bcb6 | ||
|
|
4badb99d84 | ||
|
|
3101945481 | ||
|
|
6e7efb39ae | ||
|
|
5fe11ea5a9 | ||
|
|
015aebfc9f | ||
|
|
49c5bfe238 | ||
|
|
2b75895589 | ||
|
|
ac2be97a10 | ||
|
|
241fdb89d9 | ||
|
|
1f91c96f83 | ||
|
|
d980e32116 | ||
|
|
6732907fc5 | ||
|
|
d2f23156cc | ||
|
|
4d02df581f | ||
|
|
1d6e375e05 | ||
|
|
c827562839 | ||
|
|
720d75b56b | ||
|
|
75925f0d5c | ||
|
|
ddb47ff63a | ||
|
|
2df29e1cf1 | ||
|
|
6f77de832e | ||
|
|
f94b320dfa | ||
|
|
4ec6fa4cae | ||
|
|
ecdb98c4c8 | ||
|
|
c21cf2f3ac | ||
|
|
ef9fbe472a | ||
|
|
06c3148897 | ||
|
|
e716482154 | ||
|
|
59cc74a00d | ||
|
|
a7194b990f | ||
|
|
45e543b636 | ||
|
|
ae93b96b9c | ||
|
|
b3faeb4f2b | ||
|
|
42f552a1f2 | ||
|
|
b847becdc7 | ||
|
|
64e0a60dbf | ||
|
|
1be5149bde | ||
|
|
7d256e6492 | ||
|
|
0a04114eb0 | ||
|
|
b14b107890 | ||
|
|
13ff782ec8 | ||
|
|
975a804570 | ||
|
|
3c252ce904 | ||
|
|
74cedd4ec4 | ||
|
|
d6c3f50ba8 | ||
|
|
d7003306d1 | ||
|
|
b8e7ce11de | ||
|
|
98961547f3 | ||
|
|
c11127e64f | ||
|
|
0f98800b92 | ||
|
|
8eefeeef86 | ||
|
|
d913e9c515 | ||
|
|
377ae5e27a | ||
|
|
9bcffae429 | ||
|
|
086fb1d4e9 | ||
|
|
f241613107 | ||
|
|
af373cf09d | ||
|
|
a7776f8407 | ||
|
|
776f3976ec | ||
|
|
3785e73b43 | ||
|
|
9bf6e6078d | ||
|
|
e62e8c81fb | ||
|
|
9f79fb581d | ||
|
|
45d500d401 | ||
|
|
9f02e95355 | ||
|
|
c0e93cd824 | ||
|
|
d80eace435 | ||
|
|
5d34181e8e | ||
|
|
1323791c52 | ||
|
|
5248534991 | ||
|
|
d3cb01b76c | ||
|
|
b374370706 | ||
|
|
60627650a3 | ||
|
|
92982ef2ac | ||
|
|
012b9a82bf |
5
.travis.yml
Normal file
5
.travis.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "6"
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
78
CHANGELOG.md
78
CHANGELOG.md
@@ -1,5 +1,83 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## [v2.3.1](https://github.com/apertureless/vue-chartjs/tree/v2.3.1) (2016-12-20)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.3.0...v2.3.1)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- Issues after using gulp-- production [\#19](https://github.com/apertureless/vue-chartjs/issues/19)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Error in rendering [\#21](https://github.com/apertureless/vue-chartjs/issues/21)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- ✅ Add tests for chart instance destroying [\#24](https://github.com/apertureless/vue-chartjs/pull/24) ([apertureless](https://github.com/apertureless))
|
||||||
|
- Feature/runtimebuild \#22 [\#23](https://github.com/apertureless/vue-chartjs/pull/23) ([apertureless](https://github.com/apertureless))
|
||||||
|
|
||||||
|
## [v2.3.0](https://github.com/apertureless/vue-chartjs/tree/v2.3.0) (2016-12-17)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.2.1...v2.3.0)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Uncaught TypeError: \_c is not a function [\#20](https://github.com/apertureless/vue-chartjs/issues/20)
|
||||||
|
|
||||||
|
## [v2.2.1](https://github.com/apertureless/vue-chartjs/tree/v2.2.1) (2016-12-07)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.2.0...v2.2.1)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- Uncaught TypeError: Cannot read property 'draw' of null [\#15](https://github.com/apertureless/vue-chartjs/issues/15)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Update README.md [\#16](https://github.com/apertureless/vue-chartjs/pull/16) ([Ag47](https://github.com/Ag47))
|
||||||
|
|
||||||
|
## [v2.2.0](https://github.com/apertureless/vue-chartjs/tree/v2.2.0) (2016-10-24)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.1.1...v2.2.0)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- question:syntax with vue-loader [\#12](https://github.com/apertureless/vue-chartjs/issues/12)
|
||||||
|
- Rerender when data has changed [\#10](https://github.com/apertureless/vue-chartjs/issues/10)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- add horizontal bar parameter [\#14](https://github.com/apertureless/vue-chartjs/pull/14) ([wahaha2012](https://github.com/wahaha2012))
|
||||||
|
- WIP Feature/reactive chart data \#11 [\#11](https://github.com/apertureless/vue-chartjs/pull/11) ([apertureless](https://github.com/apertureless))
|
||||||
|
|
||||||
|
## [v2.1.1](https://github.com/apertureless/vue-chartjs/tree/v2.1.1) (2016-10-02)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v.2.1.0...v2.1.1)
|
||||||
|
|
||||||
|
## [v.2.1.0](https://github.com/apertureless/vue-chartjs/tree/v.2.1.0) (2016-09-23)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v1.1.3...v.2.1.0)
|
||||||
|
|
||||||
|
## [v1.1.3](https://github.com/apertureless/vue-chartjs/tree/v1.1.3) (2016-09-08)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.2...v1.1.3)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Add test [\#1](https://github.com/apertureless/vue-chartjs/issues/1)
|
||||||
|
|
||||||
|
**Fixed bugs:**
|
||||||
|
|
||||||
|
- Passing chart size \(width / height\) as prop doesnt resize the chart [\#8](https://github.com/apertureless/vue-chartjs/issues/8)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Added bubble chart type [\#9](https://github.com/apertureless/vue-chartjs/pull/9) ([jcalonso](https://github.com/jcalonso))
|
||||||
|
|
||||||
|
## [1.1.2](https://github.com/apertureless/vue-chartjs/tree/1.1.2) (2016-09-07)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.1...1.1.2)
|
||||||
|
|
||||||
|
**Implemented enhancements:**
|
||||||
|
|
||||||
|
- Change name of the render method to ensure compatiblity with Vue 2.0 [\#4](https://github.com/apertureless/vue-chartjs/issues/4)
|
||||||
|
|
||||||
|
## [1.1.1](https://github.com/apertureless/vue-chartjs/tree/1.1.1) (2016-08-23)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.0...1.1.1)
|
||||||
|
|
||||||
## [1.1.0](https://github.com/apertureless/vue-chartjs/tree/1.1.0) (2016-08-21)
|
## [1.1.0](https://github.com/apertureless/vue-chartjs/tree/1.1.0) (2016-08-21)
|
||||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.3...1.1.0)
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.3...1.1.0)
|
||||||
|
|
||||||
|
|||||||
115
README.md
115
README.md
@@ -1,8 +1,23 @@
|
|||||||
# Vue-ChartJs
|
# Vue-ChartJs
|
||||||
|
|
||||||
[](https://badge.fury.io/js/vue-chartjs) 
|
[](https://badge.fury.io/js/vue-chartjs)  [](https://codecov.io/gh/apertureless/vue-chartjs) [](https://travis-ci.org/apertureless/vue-chartjs) [](http://packagequality.com/#?package=vue-chartjs) [](https://github.com/apertureless/vue-chartjs/blob/master/LICENSE.txt)
|
||||||
|
|
||||||
> VueJS wrapper for ChartJs
|
Is a vue.js wrapper for chart.js. You can easily create your chart components.
|
||||||
|
|
||||||
|
## Demo
|
||||||
|
|
||||||
|
[Demo](https://apertureless.github.io/vue-chartjs/)
|
||||||
|
|
||||||
|
### Compatibility
|
||||||
|
|
||||||
|
- v1 later
|
||||||
|
- Vue.js 1.x
|
||||||
|
- v2 later
|
||||||
|
- Vue.js 2.x
|
||||||
|
|
||||||
|
After the final release of vue.js 2, you also get the v2 per default if you install vue-chartjs over npm.
|
||||||
|
No need for the @next tag anymore. If you want the v1 you need to define the version.
|
||||||
|
If you're looking for v1 check this [branch](https://github.com/apertureless/vue-chartjs/tree/release/1.1.3)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
@@ -25,10 +40,10 @@ Just create your own component.
|
|||||||
// CommitChart.js
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default BarChart.extend({
|
export default Bar.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -56,10 +71,10 @@ You can overwrite the default chart options. Just pass the options object as a s
|
|||||||
// MonthlyIncome.js
|
// MonthlyIncome.js
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default LineChart.extend({
|
export default Line.extend({
|
||||||
props: [data, options],
|
props: ["data", "options"],
|
||||||
ready () {
|
mounted () {
|
||||||
this.render(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
@@ -81,6 +96,76 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Reactivity
|
||||||
|
|
||||||
|
Chart.js does not update or re-render the chart if new data is passed.
|
||||||
|
However you can simply implement this by your own or use one of the two mixins which are included.
|
||||||
|
|
||||||
|
- `reactiveProp`
|
||||||
|
- `reactiveData`
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// MonthlyIncome.js
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default Line.extend({
|
||||||
|
mixins: [mixins.reactiveProp],
|
||||||
|
props: ["chartData", "options"],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mixins module
|
||||||
|
The `mixins` module is included in the `VueCharts` module and as a seperate module.
|
||||||
|
Some ways to import them:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Load complete module with all charts
|
||||||
|
import VueCharts from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default VueCharts.Line.extend({
|
||||||
|
mixins: [VueCharts.mixins.reactiveProp],
|
||||||
|
props: ["chartData", "options"],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Load speperate modules
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default Line.extend({
|
||||||
|
mixins: [mixins.reactiveProp],
|
||||||
|
props: ["chartData", "options"],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Load speperate modules with destructure assign
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
|
export default Line.extend({
|
||||||
|
mixins: [reactiveProp],
|
||||||
|
props: ["chartData", "options"],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Available Charts
|
## Available Charts
|
||||||
|
|
||||||
### Bar Chart
|
### Bar Chart
|
||||||
@@ -107,17 +192,9 @@ export default {
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## Todo
|
### Bubble
|
||||||
|
|
||||||
- [x] ~~Implement Bar Chart~~
|
|
||||||
- [x] ~~Implement Line Chart~~
|
|
||||||
- [x] ~~Implement Radar Chart~~
|
|
||||||
- [x] ~~Implement Polar Area Chart~~
|
|
||||||
- [x] ~~Implement Pie Chart~~
|
|
||||||
- [x] ~~Implement Doughnut Chart~~
|
|
||||||
- [x] ~~Make npm module~~
|
|
||||||
- [ ] Add tests
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Build Setup
|
## Build Setup
|
||||||
|
|
||||||
|
|||||||
BIN
assets/bubble.png
Normal file
BIN
assets/bubble.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
@@ -17,6 +17,7 @@ module.exports = {
|
|||||||
fallback: [path.join(__dirname, '../node_modules')],
|
fallback: [path.join(__dirname, '../node_modules')],
|
||||||
alias: {
|
alias: {
|
||||||
'src': path.resolve(__dirname, '../src'),
|
'src': path.resolve(__dirname, '../src'),
|
||||||
|
'mixins': path.resolve(__dirname, '../src/mixins'),
|
||||||
'BaseCharts': path.resolve(__dirname, '../src/BaseCharts')
|
'BaseCharts': path.resolve(__dirname, '../src/BaseCharts')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
const webpack = require('webpack')
|
const webpack = require('webpack')
|
||||||
const base = require('./webpack.base.conf')
|
const base = require('./webpack.base.conf')
|
||||||
const config = require('../config')
|
const config = require('../config')
|
||||||
|
var env = process.env.NODE_ENV === 'testing'
|
||||||
|
? require('../config/test.env')
|
||||||
|
: config.build.env
|
||||||
|
|
||||||
base.entry = {
|
base.entry = {
|
||||||
lib: './src/index.js'
|
lib: './src/index.js'
|
||||||
@@ -19,9 +22,7 @@ var webpackConfig = Object.assign({}, base)
|
|||||||
webpackConfig.devtool = '#source-map'
|
webpackConfig.devtool = '#source-map'
|
||||||
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
|
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env.NODE_ENV': env
|
||||||
NODE_ENV: '"production"'
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
compress: { warnings: false }
|
compress: { warnings: false }
|
||||||
|
|||||||
78
build/webpack.release.js
Normal file
78
build/webpack.release.js
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
var vue = require('vue-loader')
|
||||||
|
var path = require('path')
|
||||||
|
var webpack = require("webpack")
|
||||||
|
var ExtractTextPlugin = require("extract-text-webpack-plugin")
|
||||||
|
var projectRoot = path.resolve(__dirname, '../')
|
||||||
|
var cssLoader = ExtractTextPlugin.extract('style-loader', 'css-loader')
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: {
|
||||||
|
'vue-chartjs': './src/index.js'
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
filename: './dist/[name].js',
|
||||||
|
library: 'VueChartJs',
|
||||||
|
libraryTarget: 'umd'
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
preLoaders: [
|
||||||
|
{
|
||||||
|
test: /\.vue$/,
|
||||||
|
loader: 'eslint',
|
||||||
|
include: projectRoot,
|
||||||
|
exclude: /node_modules/
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
loader: 'eslint',
|
||||||
|
include: projectRoot,
|
||||||
|
exclude: /node_modules/
|
||||||
|
}
|
||||||
|
],
|
||||||
|
loaders: [
|
||||||
|
{
|
||||||
|
test: /\.vue$/,
|
||||||
|
loader: 'vue'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: 'babel'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.css$/,
|
||||||
|
loader: cssLoader
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.s[a|c]ss$/,
|
||||||
|
loader: ExtractTextPlugin.extract('style-loader','css-loader!sass-loader')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
eslint: {
|
||||||
|
formatter: require('eslint-friendly-formatter')
|
||||||
|
},
|
||||||
|
babel: {
|
||||||
|
presets: ['es2015'],
|
||||||
|
plugins: ['transform-runtime']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
|
||||||
|
delete module.exports.devtool
|
||||||
|
module.exports.plugins = [
|
||||||
|
new webpack.DefinePlugin({
|
||||||
|
'process.env': {
|
||||||
|
NODE_ENV: '"production"'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compress: {
|
||||||
|
warnings: false
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
new webpack.optimize.OccurenceOrderPlugin()
|
||||||
|
// new ExtractTextPlugin('build.css')
|
||||||
|
]
|
||||||
|
}
|
||||||
34
codecov.yml
Normal file
34
codecov.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
codecov:
|
||||||
|
branch: master
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
precision: 2
|
||||||
|
round: down
|
||||||
|
range: "70...100"
|
||||||
|
|
||||||
|
status:
|
||||||
|
project:
|
||||||
|
default:
|
||||||
|
target: auto
|
||||||
|
threshold: null
|
||||||
|
branches: null
|
||||||
|
|
||||||
|
patch:
|
||||||
|
default:
|
||||||
|
target: auto
|
||||||
|
branches: null
|
||||||
|
|
||||||
|
changes:
|
||||||
|
default:
|
||||||
|
branches: null
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
- "tests/*"
|
||||||
|
- "src/examples/*"
|
||||||
|
- "src/mixins/*"
|
||||||
|
|
||||||
|
|
||||||
|
comment:
|
||||||
|
layout: "header, diff, changes, sunburst, uncovered, tree"
|
||||||
|
branches: null
|
||||||
|
behavior: default
|
||||||
42143
dist/vue-chartjs.js
vendored
42143
dist/vue-chartjs.js
vendored
File diff suppressed because one or more lines are too long
2
dist/vue-chartjs.js.map
vendored
2
dist/vue-chartjs.js.map
vendored
File diff suppressed because one or more lines are too long
0
docs/.nojekyll
Normal file
0
docs/.nojekyll
Normal file
22
docs/dist/vue-chartjs.js
vendored
Normal file
22
docs/dist/vue-chartjs.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
docs/dist/vue-chartjs.js.map
vendored
Normal file
1
docs/dist/vue-chartjs.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
13
docs/index.html
Normal file
13
docs/index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>📊 Vue-ChartJs</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<app></app>
|
||||||
|
</div>
|
||||||
|
<script src="dist/vue-chartjs.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="container">
|
|
||||||
<bar-example></bar-example>
|
|
||||||
<line-example></line-example>
|
|
||||||
<doughnut-example></doughnut-example>
|
|
||||||
<pie-example></pie-example>
|
|
||||||
<radar-example></radar-example>
|
|
||||||
<polar-area-example></polar-area-example>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import BarExample from './examples/BarExample'
|
|
||||||
import LineExample from './examples/LineExample'
|
|
||||||
import DoughnutExample from './examples/DoughnutExample'
|
|
||||||
import PieExample from './examples/PieExample'
|
|
||||||
import RadarExample from './examples/RadarExample'
|
|
||||||
import PolarAreaExample from './examples/PolarAreaExample'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample }
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.container {
|
|
||||||
max-width: 800px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -5,7 +5,9 @@
|
|||||||
<title>Vue-ChartJs</title>
|
<title>Vue-ChartJs</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div id="app">
|
||||||
<app></app>
|
<app></app>
|
||||||
|
</div>
|
||||||
<!-- built files will be auto injected -->
|
<!-- built files will be auto injected -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
72
package.json
72
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-chartjs",
|
"name": "vue-chartjs",
|
||||||
"version": "1.1.1",
|
"version": "2.3.2",
|
||||||
"description": "Vue wrapper for chart.js",
|
"description": "vue.js wrapper for chart.js",
|
||||||
"author": "Jakub Juszczak <jakub@nextindex.de>",
|
"author": "Jakub Juszczak <jakub@nextindex.de>",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -20,68 +20,72 @@
|
|||||||
"build": "node build/build.js",
|
"build": "node build/build.js",
|
||||||
"unit": "karma start test/unit/karma.conf.js --single-run",
|
"unit": "karma start test/unit/karma.conf.js --single-run",
|
||||||
"e2e": "node test/e2e/runner.js",
|
"e2e": "node test/e2e/runner.js",
|
||||||
"test": "npm run unit && npm run e2e",
|
"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"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-runtime": "^6.0.0",
|
"babel-runtime": "^6.11.6",
|
||||||
"chart.js": "^2.1.6",
|
"chart.js": "^2.4.0",
|
||||||
"vue": "^1.0.21"
|
"vue": "^2.1.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "^6.0.0",
|
"babel-core": "^6.10.4",
|
||||||
"babel-loader": "^6.0.0",
|
"babel-loader": "^6.0.0",
|
||||||
"babel-plugin-transform-runtime": "^6.0.0",
|
"babel-plugin-transform-runtime": "^6.12.0",
|
||||||
"babel-preset-es2015": "^6.0.0",
|
"babel-preset-es2015": "^6.0.0",
|
||||||
"babel-preset-stage-2": "^6.0.0",
|
"babel-preset-stage-2": "^6.0.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"chromedriver": "^2.21.2",
|
"chromedriver": "^2.21.2",
|
||||||
"connect-history-api-fallback": "^1.1.0",
|
"connect-history-api-fallback": "^1.1.0",
|
||||||
"cross-spawn": "^2.1.5",
|
"cross-spawn": "^5.0.1",
|
||||||
"css-loader": "^0.23.0",
|
"css-loader": "^0.26.1",
|
||||||
"eslint": "^2.10.2",
|
"eslint": "^3.7.1",
|
||||||
"eslint-config-standard": "^5.1.0",
|
"eslint-config-standard": "^6.2.0",
|
||||||
"eslint-friendly-formatter": "^2.0.5",
|
"eslint-friendly-formatter": "^2.0.5",
|
||||||
"eslint-loader": "^1.3.0",
|
"eslint-loader": "^1.3.0",
|
||||||
"eslint-plugin-html": "^1.3.0",
|
"eslint-plugin-html": "^1.3.0",
|
||||||
"eslint-plugin-promise": "^1.0.8",
|
"eslint-plugin-promise": "^3.4.0",
|
||||||
"eslint-plugin-standard": "^1.3.2",
|
"eslint-plugin-standard": "^2.0.1",
|
||||||
"eventsource-polyfill": "^0.9.6",
|
"eventsource-polyfill": "^0.9.6",
|
||||||
"express": "^4.13.3",
|
"express": "^4.13.3",
|
||||||
"extract-text-webpack-plugin": "^1.0.1",
|
"extract-text-webpack-plugin": "^1.0.1",
|
||||||
"file-loader": "^0.8.4",
|
"file-loader": "^0.9.0",
|
||||||
"function-bind": "^1.0.2",
|
"function-bind": "^1.0.2",
|
||||||
"html-webpack-plugin": "^2.8.1",
|
"html-webpack-plugin": "^2.8.1",
|
||||||
"http-proxy-middleware": "^0.12.0",
|
"http-proxy-middleware": "^0.17.2",
|
||||||
"inject-loader": "^2.0.1",
|
"inject-loader": "^3.0.0-beta2",
|
||||||
"isparta-loader": "^2.0.0",
|
"isparta-loader": "^2.0.0",
|
||||||
|
"jasmine-core": "^2.5.2",
|
||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"karma": "^0.13.15",
|
"karma": "^1.3.0",
|
||||||
"karma-coverage": "^0.5.5",
|
"karma-coverage": "^1.1.1",
|
||||||
"karma-mocha": "^0.2.2",
|
"karma-jasmine": "^1.0.2",
|
||||||
|
"karma-mocha": "^1.2.0",
|
||||||
"karma-phantomjs-launcher": "^1.0.0",
|
"karma-phantomjs-launcher": "^1.0.0",
|
||||||
"karma-sinon-chai": "^1.2.0",
|
"karma-sinon-chai": "^1.2.0",
|
||||||
"karma-sourcemap-loader": "^0.3.7",
|
"karma-sourcemap-loader": "^0.3.7",
|
||||||
"karma-spec-reporter": "0.0.24",
|
"karma-spec-reporter": "0.0.26",
|
||||||
"karma-webpack": "^1.7.0",
|
"karma-webpack": "^1.7.0",
|
||||||
"lodash": "^4.15.0",
|
"lodash": "^4.16.3",
|
||||||
"lolex": "^1.4.0",
|
"lolex": "^1.4.0",
|
||||||
"mocha": "^2.4.5",
|
"mocha": "^3.1.0",
|
||||||
"nightwatch": "^0.8.18",
|
"nightwatch": "^0.9.8",
|
||||||
"ora": "^0.2.0",
|
"ora": "^0.3.0",
|
||||||
"phantomjs-prebuilt": "^2.1.3",
|
"phantomjs-prebuilt": "^2.1.13",
|
||||||
"selenium-server": "2.53.0",
|
"selenium-server": "^3.0.1",
|
||||||
"shelljs": "^0.6.0",
|
"shelljs": "^0.7.4",
|
||||||
"sinon": "^1.17.3",
|
"sinon": "^1.17.3",
|
||||||
"sinon-chai": "^2.8.0",
|
"sinon-chai": "^2.8.0",
|
||||||
"url-loader": "^0.5.7",
|
"url-loader": "^0.5.7",
|
||||||
"vue-hot-reload-api": "^1.2.0",
|
"vue-hot-reload-api": "^2.0.6",
|
||||||
"vue-html-loader": "^1.0.0",
|
"vue-html-loader": "^1.2.3",
|
||||||
"vue-loader": "^8.3.0",
|
"vue-loader": "^10.0.2",
|
||||||
"vue-style-loader": "^1.0.0",
|
"vue-style-loader": "^1.0.0",
|
||||||
"webpack": "^1.12.2",
|
"vue-template-compiler": "^2.1.6",
|
||||||
|
"webpack": "^1.13.2",
|
||||||
"webpack-dev-middleware": "^1.4.0",
|
"webpack-dev-middleware": "^1.4.0",
|
||||||
"webpack-hot-middleware": "^2.6.0",
|
"webpack-hot-middleware": "^2.6.0",
|
||||||
"webpack-merge": "^0.8.3"
|
"webpack-merge": "^1.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="bar-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'bar-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -45,12 +61,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (data, options) {
|
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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'bar',
|
type: type || 'bar',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
}
|
}
|
||||||
|
|||||||
80
src/BaseCharts/Bubble.js
Normal file
80
src/BaseCharts/Bubble.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import Chart from 'chart.js'
|
||||||
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
|
export default Vue.extend({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
'div',
|
||||||
|
[
|
||||||
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'bubble-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
|
width: {
|
||||||
|
default: 400,
|
||||||
|
type: Number
|
||||||
|
},
|
||||||
|
height: {
|
||||||
|
default: 400,
|
||||||
|
type: Number
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
defaultOptions: {
|
||||||
|
scales: {
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero: true
|
||||||
|
},
|
||||||
|
gridLines: {
|
||||||
|
display: false
|
||||||
|
}
|
||||||
|
}],
|
||||||
|
xAxes: [ {
|
||||||
|
gridLines: {
|
||||||
|
display: false
|
||||||
|
},
|
||||||
|
categoryPercentage: 0.5,
|
||||||
|
barPercentage: 0.2
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
renderChart (data, options) {
|
||||||
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
|
this._chart = new Chart(
|
||||||
|
this.$refs.canvas.getContext('2d'), {
|
||||||
|
type: 'bubble',
|
||||||
|
data: data,
|
||||||
|
options: chartOptions
|
||||||
|
}
|
||||||
|
)
|
||||||
|
this._chart.generateLegend()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
this._chart.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="doughnut-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'doughnut-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -28,11 +44,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'doughnut',
|
type: 'doughnut',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="line-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'line-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -43,11 +59,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="pie-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'pie-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -28,11 +44,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="polar-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'polar-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -28,11 +44,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'polarArea',
|
type: 'polarArea',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
|
|||||||
@@ -3,13 +3,29 @@ import Chart from 'chart.js'
|
|||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
template: `
|
render: function (createElement) {
|
||||||
<div>
|
return createElement(
|
||||||
<canvas id="radar-chart" width=width height=height v-el:canvas></canvas>
|
'div',
|
||||||
</div>
|
[
|
||||||
`,
|
createElement(
|
||||||
|
'canvas', {
|
||||||
|
attrs: {
|
||||||
|
id: this.chartId,
|
||||||
|
width: this.width,
|
||||||
|
height: this.height
|
||||||
|
},
|
||||||
|
ref: 'canvas'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
|
chartId: {
|
||||||
|
default: 'radar-chart',
|
||||||
|
type: String
|
||||||
|
},
|
||||||
width: {
|
width: {
|
||||||
default: 400,
|
default: 400,
|
||||||
type: Number
|
type: Number
|
||||||
@@ -28,11 +44,11 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
render (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.$els.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'radar',
|
type: 'radar',
|
||||||
data: data,
|
data: data,
|
||||||
options: chartOptions
|
options: chartOptions
|
||||||
|
|||||||
53
src/examples/App.vue
Normal file
53
src/examples/App.vue
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<div class="container">
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Barchart</h1>
|
||||||
|
<bar-example></bar-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Barchart with reactive mixing for live data</h1>
|
||||||
|
<reactive-example></reactive-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Linechart</h1>
|
||||||
|
<line-example></line-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Doughnutchart</h1>
|
||||||
|
<doughnut-example></doughnut-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Piechart</h1>
|
||||||
|
<pie-example></pie-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Radarchart</h1>
|
||||||
|
<radar-example></radar-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Polararea</h1>
|
||||||
|
<polar-area-example></polar-area-example>
|
||||||
|
<h1 style="text-align:center;margin:40px 0;">Bubblechart</h1>
|
||||||
|
<bubble-example></bubble-example>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import BarExample from './BarExample'
|
||||||
|
import LineExample from './LineExample'
|
||||||
|
import DoughnutExample from './DoughnutExample'
|
||||||
|
import PieExample from './PieExample'
|
||||||
|
import RadarExample from './RadarExample'
|
||||||
|
import PolarAreaExample from './PolarAreaExample'
|
||||||
|
import BubbleExample from './BubbleExample'
|
||||||
|
import ReactiveExample from './ReactiveExample'
|
||||||
|
import ReactivePropExample from './ReactivePropExample'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
BarExample,
|
||||||
|
LineExample,
|
||||||
|
DoughnutExample,
|
||||||
|
PieExample,
|
||||||
|
RadarExample,
|
||||||
|
PolarAreaExample,
|
||||||
|
BubbleExample,
|
||||||
|
ReactiveExample,
|
||||||
|
ReactivePropExample
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import BarChart from '../BaseCharts/Bar'
|
import BarChart from '../BaseCharts/Bar'
|
||||||
|
|
||||||
export default BarChart.extend({
|
export default BarChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -11,6 +11,6 @@ export default BarChart.extend({
|
|||||||
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
52
src/examples/BubbleExample.js
Normal file
52
src/examples/BubbleExample.js
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import BubbleChart from '../BaseCharts/Bubble'
|
||||||
|
|
||||||
|
export default BubbleChart.extend({
|
||||||
|
mounted () {
|
||||||
|
this.renderChart({
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
x: 20,
|
||||||
|
y: 25,
|
||||||
|
r: 5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 40,
|
||||||
|
y: 10,
|
||||||
|
r: 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 30,
|
||||||
|
y: 22,
|
||||||
|
r: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Data Two',
|
||||||
|
backgroundColor: '#7C8CF8',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
x: 10,
|
||||||
|
y: 30,
|
||||||
|
r: 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 20,
|
||||||
|
y: 20,
|
||||||
|
r: 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 15,
|
||||||
|
y: 8,
|
||||||
|
r: 30
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import DoughnutChart from '../BaseCharts/Doughnut'
|
import DoughnutChart from '../BaseCharts/Doughnut'
|
||||||
|
|
||||||
export default DoughnutChart.extend({
|
export default DoughnutChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,6 @@ export default DoughnutChart.extend({
|
|||||||
data: [40, 20, 80, 10]
|
data: [40, 20, 80, 10]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import LineChart from '../BaseCharts/Line'
|
import LineChart from '../BaseCharts/Line'
|
||||||
|
|
||||||
export default LineChart.extend({
|
export default LineChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -11,6 +11,6 @@ export default LineChart.extend({
|
|||||||
data: [40, 39, 10, 40, 39, 80, 40]
|
data: [40, 39, 10, 40, 39, 80, 40]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import PieChart from '../BaseCharts/Pie'
|
import PieChart from '../BaseCharts/Pie'
|
||||||
|
|
||||||
export default PieChart.extend({
|
export default PieChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -15,6 +15,6 @@ export default PieChart.extend({
|
|||||||
data: [40, 20, 80, 10]
|
data: [40, 20, 80, 10]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import PolarAreaChart from '../BaseCharts/PolarArea'
|
import PolarAreaChart from '../BaseCharts/PolarArea'
|
||||||
|
|
||||||
export default PolarAreaChart.extend({
|
export default PolarAreaChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -24,6 +24,6 @@ export default PolarAreaChart.extend({
|
|||||||
data: [28, 48, 40, 19, 96, 27, 100]
|
data: [28, 48, 40, 19, 96, 27, 100]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import RadarChart from '../BaseCharts/Radar'
|
import RadarChart from '../BaseCharts/Radar'
|
||||||
|
|
||||||
export default RadarChart.extend({
|
export default RadarChart.extend({
|
||||||
ready () {
|
mounted () {
|
||||||
this.render({
|
this.renderChart({
|
||||||
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
@@ -26,6 +26,6 @@ export default RadarChart.extend({
|
|||||||
data: [28, 48, 40, 19, 96, 27, 100]
|
data: [28, 48, 40, 19, 96, 27, 100]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
41
src/examples/ReactiveExample.js
Normal file
41
src/examples/ReactiveExample.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import BarChart from '../BaseCharts/Bar'
|
||||||
|
import reactiveData from '../mixins/reactiveData'
|
||||||
|
|
||||||
|
export default BarChart.extend({
|
||||||
|
mixins: [reactiveData],
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
chartData: ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.fillData()
|
||||||
|
},
|
||||||
|
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, {responsive: true, maintainAspectRatio: false})
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
this.fillData()
|
||||||
|
}, 5000)
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
fillData () {
|
||||||
|
this.chartData = {
|
||||||
|
labels: ['January' + this.getRandomInt(), 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
getRandomInt () {
|
||||||
|
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
10
src/examples/ReactivePropExample.js
Normal file
10
src/examples/ReactivePropExample.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import BarChart from '../BaseCharts/Bar'
|
||||||
|
import reactiveData from '../mixins/reactiveProp'
|
||||||
|
|
||||||
|
export default BarChart.extend({
|
||||||
|
mixins: [reactiveData],
|
||||||
|
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData)
|
||||||
|
}
|
||||||
|
})
|
||||||
20
src/index.js
20
src/index.js
@@ -4,6 +4,8 @@ import Line from './BaseCharts/Line'
|
|||||||
import Pie from './BaseCharts/Pie'
|
import Pie from './BaseCharts/Pie'
|
||||||
import PolarArea from './BaseCharts/PolarArea'
|
import PolarArea from './BaseCharts/PolarArea'
|
||||||
import Radar from './BaseCharts/Radar'
|
import Radar from './BaseCharts/Radar'
|
||||||
|
import Bubble from './BaseCharts/Bubble'
|
||||||
|
import mixins from './mixins/index.js'
|
||||||
|
|
||||||
const VueCharts = {
|
const VueCharts = {
|
||||||
Bar,
|
Bar,
|
||||||
@@ -11,7 +13,21 @@ const VueCharts = {
|
|||||||
Line,
|
Line,
|
||||||
Pie,
|
Pie,
|
||||||
PolarArea,
|
PolarArea,
|
||||||
Radar
|
Radar,
|
||||||
|
Bubble,
|
||||||
|
mixins
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = VueCharts
|
export default VueCharts
|
||||||
|
|
||||||
|
export {
|
||||||
|
VueCharts,
|
||||||
|
Bar,
|
||||||
|
Doughnut,
|
||||||
|
Line,
|
||||||
|
Pie,
|
||||||
|
PolarArea,
|
||||||
|
Radar,
|
||||||
|
Bubble,
|
||||||
|
mixins
|
||||||
|
}
|
||||||
|
|||||||
7
src/mixins/index.js
Normal file
7
src/mixins/index.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import reactiveData from './reactiveData.js'
|
||||||
|
import reactiveProp from './reactiveProp.js'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
reactiveData,
|
||||||
|
reactiveProp
|
||||||
|
}
|
||||||
44
src/mixins/reactiveData.js
Normal file
44
src/mixins/reactiveData.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
module.exports = {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
chartData: null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
'chartData': {
|
||||||
|
handler (newData, oldData) {
|
||||||
|
if (oldData) {
|
||||||
|
let chart = this._chart
|
||||||
|
|
||||||
|
let newDataLabels = newData.datasets.map((dataset) => {
|
||||||
|
return dataset.label
|
||||||
|
})
|
||||||
|
|
||||||
|
let oldDataLabels = oldData.datasets.map((dataset) => {
|
||||||
|
return dataset.label
|
||||||
|
})
|
||||||
|
|
||||||
|
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
|
||||||
|
this.forceUpdate(newData, chart)
|
||||||
|
} else {
|
||||||
|
this.forceRender()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
forceUpdate (newData, chart) {
|
||||||
|
newData.datasets.forEach((dataset, i) => {
|
||||||
|
chart.data.datasets[i].data = dataset.data
|
||||||
|
})
|
||||||
|
|
||||||
|
chart.data.labels = newData.labels
|
||||||
|
chart.update()
|
||||||
|
},
|
||||||
|
|
||||||
|
forceRender () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/mixins/reactiveProp.js
Normal file
35
src/mixins/reactiveProp.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
module.exports = {
|
||||||
|
props: {
|
||||||
|
chartData: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
'chartData': {
|
||||||
|
handler (newData, oldData) {
|
||||||
|
if (oldData) {
|
||||||
|
let chart = this._chart
|
||||||
|
|
||||||
|
let newDataLabels = newData.datasets.map((dataset) => {
|
||||||
|
return dataset.label
|
||||||
|
})
|
||||||
|
|
||||||
|
let oldDataLabels = oldData.datasets.map((dataset) => {
|
||||||
|
return dataset.label
|
||||||
|
})
|
||||||
|
|
||||||
|
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
|
||||||
|
newData.datasets.forEach((dataset, i) => {
|
||||||
|
chart.data.datasets[i].data = dataset.data
|
||||||
|
})
|
||||||
|
chart.data.labels = newData.labels
|
||||||
|
chart.update()
|
||||||
|
} else {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"expect": true,
|
"expect": true,
|
||||||
|
"jasmine": true,
|
||||||
"sinon": true
|
"sinon": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module.exports = function (config) {
|
|||||||
// http://karma-runner.github.io/0.13/config/browsers.html
|
// http://karma-runner.github.io/0.13/config/browsers.html
|
||||||
// 2. add it to the `browsers` array below.
|
// 2. add it to the `browsers` array below.
|
||||||
browsers: ['PhantomJS'],
|
browsers: ['PhantomJS'],
|
||||||
frameworks: ['mocha', 'sinon-chai'],
|
frameworks: ['mocha', 'sinon-chai', 'jasmine'],
|
||||||
reporters: ['spec', 'coverage'],
|
reporters: ['spec', 'coverage'],
|
||||||
files: ['./index.js'],
|
files: ['./index.js'],
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
|
|||||||
64
test/unit/specs/Bar.spec.js
Normal file
64
test/unit/specs/Bar.spec.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import BarChart from 'src/examples/BarExample'
|
||||||
|
|
||||||
|
describe('BarChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#bar-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BarChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'barchartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#barchartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
64
test/unit/specs/Bubble.spec.js
Normal file
64
test/unit/specs/Bubble.spec.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import BubbleChart from 'src/examples/BubbleExample'
|
||||||
|
|
||||||
|
describe('BubbleChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BubbleChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BubbleChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#bubble-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BubbleChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'bubblechartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BubbleChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#bubblechartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
BubbleChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { BubbleChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
64
test/unit/specs/Doughnut.spec.js
Normal file
64
test/unit/specs/Doughnut.spec.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import DoughnutChart from 'src/examples/DoughnutExample'
|
||||||
|
|
||||||
|
describe('DoughnutChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
DoughnutChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { DoughnutChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#doughnut-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
DoughnutChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'doughnutchartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { DoughnutChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#doughnutchartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
DoughnutChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { DoughnutChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Hello from 'src/components/Hello'
|
|
||||||
|
|
||||||
describe('Hello.vue', () => {
|
|
||||||
it('should render correct contents', () => {
|
|
||||||
const vm = new Vue({
|
|
||||||
template: '<div><hello></hello></div>',
|
|
||||||
components: { Hello }
|
|
||||||
}).$mount()
|
|
||||||
expect(vm.$el.querySelector('.hello h1').textContent).to.contain('Hello World!')
|
|
||||||
})
|
|
||||||
})
|
|
||||||
64
test/unit/specs/Line.spec.js
Normal file
64
test/unit/specs/Line.spec.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import LineChart from 'src/examples/LineExample'
|
||||||
|
|
||||||
|
describe('LineChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
LineChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { LineChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#line-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
LineChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'linechartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { LineChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#linechartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
LineChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { LineChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
63
test/unit/specs/Pie.spec.js
Normal file
63
test/unit/specs/Pie.spec.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import PieChart from 'src/examples/PieExample'
|
||||||
|
|
||||||
|
describe('PieChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PieChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PieChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#pie-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PieChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'piechartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PieChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#piechartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PieChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PieChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
64
test/unit/specs/PolarArea.spec.js
Normal file
64
test/unit/specs/PolarArea.spec.js
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import PolarChart from 'src/examples/PolarAreaExample'
|
||||||
|
|
||||||
|
describe('PolarChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PolarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PolarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#polar-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PolarChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'polarchartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PolarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#polarchartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
PolarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { PolarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
63
test/unit/specs/Radar.spec.js
Normal file
63
test/unit/specs/Radar.spec.js
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import RadarChart from 'src/examples/RadarExample'
|
||||||
|
|
||||||
|
describe('RadarChart', () => {
|
||||||
|
let el
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
el = document.createElement('div')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should render a canvas', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
RadarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { RadarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#radar-chart')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('undefined')
|
||||||
|
expect(vm.$el.querySelector('canvas')).not.to.be.an('null')
|
||||||
|
expect(vm.$el.querySelector('canvas')).to.exist
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should change id based on prop', () => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
RadarChart, {
|
||||||
|
props: {
|
||||||
|
chartId: 'rodarchartprop'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { RadarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$el.querySelector('#rodarchartprop')).not.to.be.an('undefined')
|
||||||
|
})
|
||||||
|
it('should destroy chart instance', (done) => {
|
||||||
|
const vm = new Vue({
|
||||||
|
render: function (createElement) {
|
||||||
|
return createElement(
|
||||||
|
RadarChart
|
||||||
|
)
|
||||||
|
},
|
||||||
|
components: { RadarChart }
|
||||||
|
}).$mount(el)
|
||||||
|
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
|
vm.$destroy()
|
||||||
|
|
||||||
|
vm.$nextTick(() => {
|
||||||
|
vm.$forceUpdate()
|
||||||
|
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
30
test/unit/specs/helpers/options.spec.js
Normal file
30
test/unit/specs/helpers/options.spec.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import { mergeOptions } from 'src/helpers/options'
|
||||||
|
|
||||||
|
describe('mergeOptions.js', () => {
|
||||||
|
const a = {
|
||||||
|
a: 'a',
|
||||||
|
b: 'a'
|
||||||
|
}
|
||||||
|
|
||||||
|
const b = {
|
||||||
|
a: 'b',
|
||||||
|
b: 'b'
|
||||||
|
}
|
||||||
|
|
||||||
|
const c = {
|
||||||
|
c: 'c'
|
||||||
|
}
|
||||||
|
|
||||||
|
it('should replace old a and b if a and b are new', () => {
|
||||||
|
let 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', () => {
|
||||||
|
let ac = mergeOptions(a, c)
|
||||||
|
expect(ac).to.have.property('a').and.to.equal('a')
|
||||||
|
expect(ac).to.have.property('b').and.to.equal('a')
|
||||||
|
expect(ac).to.have.property('c').and.to.equal('c')
|
||||||
|
})
|
||||||
|
})
|
||||||
0
test/unit/specs/mixins/reactiveData.js
Normal file
0
test/unit/specs/mixins/reactiveData.js
Normal file
Reference in New Issue
Block a user