Compare commits

...

61 Commits

Author SHA1 Message Date
Jakub Juszczak
3e77f40043 💎 Release new version v2.3.3 2017-01-19 10:25:58 +01:00
Jakub
158f29d5c9 Merge pull request #31 from apertureless/hotfix/vuedep
🐛 Fix #30 type error
2017-01-19 10:19:46 +01:00
Jakub Juszczak
b1ca492b33 🐛 Fix #30 type error 2017-01-19 10:15:44 +01:00
Jakub Juszczak
88cc75c614 💎 Release new version 2.3.2 2016-12-23 12:34:34 +01:00
Jakub
cba152c7f8 Merge pull request #27 from apertureless/develop
 Add minimal release webpack config
2016-12-23 12:32:36 +01:00
Jakub Juszczak
b2f0a5ba03 Add minimal release webpack config without minimize and without production tags 2016-12-23 12:28:28 +01:00
Jakub
b76236cf9b Merge pull request #25 from apertureless/develop
📝 Update README
2016-12-21 13:22:34 +01:00
Jakub Juszczak
2a1377c01d 📝 Update README 2016-12-21 13:10:37 +01:00
Jakub Juszczak
c3f10a51f5 📝 Update README and CHANGELOG
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-20 20:17:56 +01:00
Jakub Juszczak
7ffefe4454 💎 Release new version 2.3.1
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-20 20:15:53 +01:00
Jakub
ca95e0f146 Merge pull request #24 from apertureless/feature/tests
 Add tests for chart instance destroying
2016-12-20 20:07:09 +01:00
Jakub Juszczak
988d8f13b4 Add tests for chart instance destroying 2016-12-20 20:03:17 +01:00
Jakub
52c1c50206 Merge pull request #23 from apertureless/feature/runtimebuild
Feature/runtimebuild #22
2016-12-20 19:07:45 +01:00
Jakub Juszczak
482048b746 🐛 Fix tests 2016-12-20 18:26:49 +01:00
Jakub Juszczak
bb21a40506 Rewrite template option to render function 2016-12-20 14:36:35 +01:00
Jakub Juszczak
e4ba9ea5a3 Add dependency: template-compiler 2016-12-20 14:34:05 +01:00
Jakub Juszczak
fee32b57df 🔥 Remove vue standalone alias from webpack 2016-12-20 14:33:47 +01:00
Jakub Juszczak
c0b854bd83 Merge branch 'develop'
* develop:
  Replace package quality badge with shield like version
   Add license badge
   Add package quality and liscense badge
2016-12-17 18:33:34 +01:00
Jakub Juszczak
14413e438d Replace package quality badge with shield like version 2016-12-17 18:33:11 +01:00
Jakub Juszczak
7ddc385edb Add license badge 2016-12-17 18:31:31 +01:00
Jakub Juszczak
a62a108318 Add package quality and liscense badge 2016-12-17 18:31:13 +01:00
Jakub Juszczak
a1633c0d19 Merge branch 'develop'
* develop:
  📝 Update changelog
2016-12-17 18:22:40 +01:00
Jakub Juszczak
5ec1f31a4b 📝 Update changelog 2016-12-17 18:22:33 +01:00
Jakub Juszczak
ced81a58cc Merge branch 'hotfix/minification'
* hotfix/minification:
  ⬆️ Update npm version
  💎 Release new version v2.3.0
  📝 Update README
   Add mixins to alias
  ⬆️ Update dependencies
  Change mixins exports to be seperate
2016-12-17 18:20:03 +01:00
Jakub Juszczak
193b5cac33 Merge branch 'hotfix/minification' into develop
* hotfix/minification:
  ⬆️ Update npm version
  💎 Release new version v2.3.0
  📝 Update README
   Add mixins to alias
  ⬆️ Update dependencies
  Change mixins exports to be seperate
2016-12-17 18:20:03 +01:00
Jakub Juszczak
dde366c154 ⬆️ Update npm version 2016-12-17 18:19:06 +01:00
Jakub Juszczak
4fe9a2bcb6 💎 Release new version v2.3.0 2016-12-17 18:17:50 +01:00
Jakub Juszczak
4badb99d84 📝 Update README 2016-12-17 18:15:07 +01:00
Jakub Juszczak
3101945481 Add mixins to alias 2016-12-17 17:29:41 +01:00
Jakub Juszczak
6e7efb39ae ⬆️ Update dependencies 2016-12-17 17:29:30 +01:00
Jakub Juszczak
5fe11ea5a9 Change mixins exports to be seperate 2016-12-17 17:29:18 +01:00
Jakub Juszczak
015aebfc9f 📝 Update CHANGELOG
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:54:22 +01:00
Jakub Juszczak
49c5bfe238 📝 Update README
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:53:27 +01:00
Jakub Juszczak
2b75895589 🐛 Fix script naming
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:50:02 +01:00
Jakub Juszczak
ac2be97a10 ⬆️ Update npm package version
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:41:17 +01:00
Jakub Juszczak
241fdb89d9 Rename folder to docs for gh pages
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:40:18 +01:00
Jakub Juszczak
1f91c96f83 Add demo page for github pages
Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:38:30 +01:00
Jakub Juszczak
d980e32116 💎 Release new version 2.2.1
Updated dependencies

Signed-off-by: Jakub Juszczak <netghost03@gmail.com>
2016-12-07 08:23:50 +01:00
Jakub Juszczak
6732907fc5 Merged branch master into develop 2016-12-07 08:16:55 +01:00
Jakub
d2f23156cc Merge pull request #16 from Ag47/master
Update README.md
2016-11-07 10:05:21 +01:00
SILVER PANG
4d02df581f Update README.md
fix the syntax error of the example
2016-11-07 15:37:07 +08:00
Jakub Juszczak
1d6e375e05 🐛 📝 Update CHANGELOG 2016-10-24 11:36:18 +02:00
Jakub Juszczak
c827562839 📝 Update CHANGELOG 2016-10-24 11:34:15 +02:00
Jakub Juszczak
720d75b56b 💎 Release new version 2.2.0 2016-10-24 11:33:36 +02:00
Jakub
75925f0d5c Merge pull request #14 from wahaha2012/feature-horizontal-bar
add horizontal bar parameter
2016-10-23 19:20:17 +02:00
wxwdesign
ddb47ff63a add horizontal bar parameter 2016-10-22 21:17:21 +08:00
Jakub
2df29e1cf1 Merge pull request #11 from apertureless/feature/reactive_chart_data
WIP Feature/reactive chart data #11
2016-10-15 13:37:58 +02:00
Jakub Juszczak
6f77de832e 🐛 Fix missing export 2016-10-15 13:00:24 +02:00
Jakub Juszczak
f94b320dfa Change reactiveDataMixin 2016-10-15 12:58:51 +02:00
Jakub Juszczak
4ec6fa4cae Add codecov yml 2016-10-09 17:17:06 +02:00
Jakub Juszczak
ecdb98c4c8 🐛 Fix paths 2016-10-02 18:30:48 +02:00
Jakub Juszczak
c21cf2f3ac Add export for mixins 2016-10-02 18:26:38 +02:00
Jakub Juszczak
ef9fbe472a 📝 Update README with reactive Data and props example 2016-10-02 18:26:06 +02:00
Jakub Juszczak
06c3148897 ⬆️ Update examples 2016-10-02 18:25:02 +02:00
Jakub Juszczak
e716482154 Add reactiveProperty mixin 2016-10-02 18:10:44 +02:00
Jakub Juszczak
59cc74a00d Add reactiveData Example 2016-10-02 10:34:06 +02:00
Jakub Juszczak
a7194b990f Add reactive Data example 2016-10-02 10:32:30 +02:00
Jakub Juszczak
45e543b636 Add reactiveData mixin 2016-10-02 10:31:14 +02:00
Jakub Juszczak
ae93b96b9c ⬆️ Update dependencies 2016-10-02 09:40:12 +02:00
Jakub Juszczak
b3faeb4f2b 📝 Update Changelog 2016-10-02 09:34:45 +02:00
Jakub Juszczak
42f552a1f2 📝 Update README 2016-10-02 09:29:28 +02:00
44 changed files with 48940 additions and 122 deletions

View File

@@ -1,10 +1,58 @@
# 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)

View File

@@ -1,16 +1,22 @@
# Vue-ChartJs
[![npm version](https://badge.fury.io/js/vue-chartjs.svg)](https://badge.fury.io/js/vue-chartjs) ![npm dependencies](https://david-dm.org/apertureless/vue-chartjs.svg) [![codecov](https://codecov.io/gh/apertureless/vue-chartjs/branch/master/graph/badge.svg)](https://codecov.io/gh/apertureless/vue-chartjs) [![Build Status](https://travis-ci.org/apertureless/vue-chartjs.svg?branch=master)](https://travis-ci.org/apertureless/vue-chartjs)
[![npm version](https://badge.fury.io/js/vue-chartjs.svg)](https://badge.fury.io/js/vue-chartjs) ![npm dependencies](https://david-dm.org/apertureless/vue-chartjs.svg) [![codecov](https://codecov.io/gh/apertureless/vue-chartjs/branch/master/graph/badge.svg)](https://codecov.io/gh/apertureless/vue-chartjs) [![Build Status](https://travis-ci.org/apertureless/vue-chartjs.svg?branch=master)](https://travis-ci.org/apertureless/vue-chartjs) [![Package Quality](http://npm.packagequality.com/shield/vue-chartjs.svg)](http://packagequality.com/#?package=vue-chartjs) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](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
- Vue.js 1.x
- v2 later
-- Vue.js 2.x
- 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
@@ -34,7 +40,7 @@ Just create your own component.
// CommitChart.js
import { Bar } from 'vue-chartjs'
export default BarChart.extend({
export default Bar.extend({
mounted () {
// Overwriting base render method with actual data.
this.renderChart({
@@ -65,8 +71,8 @@ You can overwrite the default chart options. Just pass the options object as a s
// MonthlyIncome.js
import { Line } from 'vue-chartjs'
export default LineChart.extend({
props: [data, options],
export default Line.extend({
props: ["data", "options"],
mounted () {
this.renderChart(this.data, this.options)
}
@@ -90,6 +96,76 @@ export default {
</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
### Bar Chart

View File

@@ -16,8 +16,8 @@ module.exports = {
extensions: ['', '.js', '.vue'],
fallback: [path.join(__dirname, '../node_modules')],
alias: {
'vue': 'vue/dist/vue.js',
'src': path.resolve(__dirname, '../src'),
'mixins': path.resolve(__dirname, '../src/mixins'),
'BaseCharts': path.resolve(__dirname, '../src/BaseCharts')
}
},

View File

@@ -1,6 +1,9 @@
const webpack = require('webpack')
const base = require('./webpack.base.conf')
const config = require('../config')
var env = process.env.NODE_ENV === 'testing'
? require('../config/test.env')
: config.build.env
base.entry = {
lib: './src/index.js'
@@ -19,9 +22,7 @@ var webpackConfig = Object.assign({}, base)
webpackConfig.devtool = '#source-map'
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
'process.env.NODE_ENV': env
}),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false }

78
build/webpack.release.js Normal file
View 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
View 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

42391
dist/vue-chartjs.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

0
docs/.nojekyll Normal file
View 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

File diff suppressed because one or more lines are too long

13
docs/index.html Normal file
View 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>

View File

@@ -1,7 +1,7 @@
{
"name": "vue-chartjs",
"version": "2.1.1",
"description": "Vue wrapper for chart.js",
"version": "2.3.3",
"description": "vue.js wrapper for chart.js",
"author": "Jakub Juszczak <jakub@nextindex.de>",
"repository": {
"type": "git",
@@ -22,12 +22,12 @@
"e2e": "node test/e2e/runner.js",
"test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
"prepublish": "node build/build.js"
"release": "webpack --progress --hide-modules --config ./build/webpack.release.js"
},
"dependencies": {
"babel-runtime": "^6.11.6",
"chart.js": "^2.2.1",
"vue": "^2.0.0-rc.1"
"chart.js": "^2.4.0",
"vue": "^2.1.10"
},
"devDependencies": {
"babel-core": "^6.10.4",
@@ -38,51 +38,54 @@
"chai": "^3.5.0",
"chromedriver": "^2.21.2",
"connect-history-api-fallback": "^1.1.0",
"cross-spawn": "^2.1.5",
"css-loader": "^0.23.0",
"eslint": "^2.10.2",
"eslint-config-standard": "^5.1.0",
"cross-spawn": "^5.0.1",
"css-loader": "^0.26.1",
"eslint": "^3.7.1",
"eslint-config-standard": "^6.2.0",
"eslint-friendly-formatter": "^2.0.5",
"eslint-loader": "^1.3.0",
"eslint-plugin-html": "^1.3.0",
"eslint-plugin-promise": "^1.0.8",
"eslint-plugin-standard": "^1.3.2",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-standard": "^2.0.1",
"eventsource-polyfill": "^0.9.6",
"express": "^4.13.3",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.4",
"file-loader": "^0.9.0",
"function-bind": "^1.0.2",
"html-webpack-plugin": "^2.8.1",
"http-proxy-middleware": "^0.12.0",
"inject-loader": "^2.0.1",
"http-proxy-middleware": "^0.17.2",
"inject-loader": "^3.0.0-beta2",
"isparta-loader": "^2.0.0",
"jasmine-core": "^2.5.2",
"json-loader": "^0.5.4",
"karma": "^0.13.15",
"karma-coverage": "^0.5.5",
"karma-mocha": "^0.2.2",
"karma": "^1.3.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha": "^1.2.0",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sinon-chai": "^1.2.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.24",
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^1.7.0",
"lodash": "^4.15.0",
"lodash": "^4.17.4",
"lolex": "^1.4.0",
"mocha": "^2.4.5",
"nightwatch": "^0.8.18",
"ora": "^0.2.0",
"phantomjs-prebuilt": "^2.1.3",
"selenium-server": "2.53.0",
"shelljs": "^0.6.0",
"mocha": "^3.1.0",
"nightwatch": "^0.9.8",
"ora": "^0.3.0",
"phantomjs-prebuilt": "^2.1.13",
"selenium-server": "^3.0.1",
"shelljs": "^0.7.4",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"url-loader": "^0.5.7",
"vue-hot-reload-api": "^2.0.6",
"vue-html-loader": "^1.2.3",
"vue-loader": "^9.3.0",
"vue-loader": "^10.0.2",
"vue-style-loader": "^1.0.0",
"vue-template-compiler": "^2.1.10",
"webpack": "^1.13.2",
"webpack-dev-middleware": "^1.4.0",
"webpack-hot-middleware": "^2.6.0",
"webpack-merge": "^0.8.3"
"webpack-merge": "^1.1.1"
}
}

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {
@@ -49,12 +61,11 @@ export default Vue.extend({
},
methods: {
renderChart (data, options) {
renderChart (data, options, type) {
let chartOptions = mergeOptions(this.defaultOptions, options)
this._chart = new Chart(
this.$refs.canvas.getContext('2d'), {
type: 'bar',
type: type || 'bar',
data: data,
options: chartOptions
}

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -3,11 +3,23 @@ import Chart from 'chart.js'
import { mergeOptions } from '../helpers/options'
export default Vue.extend({
template: `
<div>
<canvas :id="chartId" :width="width" :height="height" ref="canvas"></canvas>
</div>
`,
render: function (createElement) {
return createElement(
'div',
[
createElement(
'canvas', {
attrs: {
id: this.chartId,
width: this.width,
height: this.height
},
ref: 'canvas'
}
)
]
)
},
props: {
chartId: {

View File

@@ -1,11 +1,20 @@
<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>
@@ -18,9 +27,21 @@
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 }
components: {
BarExample,
LineExample,
DoughnutExample,
PieExample,
RadarExample,
PolarAreaExample,
BubbleExample,
ReactiveExample,
ReactivePropExample
}
}
</script>

View File

@@ -47,6 +47,6 @@ export default BubbleChart.extend({
]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View File

@@ -15,6 +15,6 @@ export default DoughnutChart.extend({
data: [40, 20, 80, 10]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View File

@@ -11,6 +11,6 @@ export default LineChart.extend({
data: [40, 39, 10, 40, 39, 80, 40]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View File

@@ -15,6 +15,6 @@ export default PieChart.extend({
data: [40, 20, 80, 10]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View File

@@ -24,6 +24,6 @@ export default PolarAreaChart.extend({
data: [28, 48, 40, 19, 96, 27, 100]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View File

@@ -26,6 +26,6 @@ export default RadarChart.extend({
data: [28, 48, 40, 19, 96, 27, 100]
}
]
})
}, {responsive: true, maintainAspectRatio: false})
}
})

View 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
}
}
})

View 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)
}
})

View File

@@ -5,6 +5,7 @@ import Pie from './BaseCharts/Pie'
import PolarArea from './BaseCharts/PolarArea'
import Radar from './BaseCharts/Radar'
import Bubble from './BaseCharts/Bubble'
import mixins from './mixins/index.js'
const VueCharts = {
Bar,
@@ -13,7 +14,20 @@ const VueCharts = {
Pie,
PolarArea,
Radar,
Bubble
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
View File

@@ -0,0 +1,7 @@
import reactiveData from './reactiveData.js'
import reactiveProp from './reactiveProp.js'
export default {
reactiveData,
reactiveProp
}

View 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)
}
}
}

View 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)
}
}
}
}
}
}

View File

@@ -4,6 +4,7 @@
},
"globals": {
"expect": true,
"jasmine": true,
"sinon": true
}
}

View File

@@ -54,7 +54,7 @@ module.exports = function (config) {
// http://karma-runner.github.io/0.13/config/browsers.html
// 2. add it to the `browsers` array below.
browsers: ['PhantomJS'],
frameworks: ['mocha', 'sinon-chai'],
frameworks: ['mocha', 'sinon-chai', 'jasmine'],
reporters: ['spec', 'coverage'],
files: ['./index.js'],
preprocessors: {

View File

@@ -10,7 +10,11 @@ describe('BarChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<bar-chart></bar-chart>',
render: function (createElement) {
return createElement(
BarChart
)
},
components: { BarChart }
}).$mount(el)
@@ -22,10 +26,39 @@ describe('BarChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<bar-chart chartId="barchartprop"></bar-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('BubbleChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<bubble-chart></bubble-chart>',
render: function (createElement) {
return createElement(
BubbleChart
)
},
components: { BubbleChart }
}).$mount(el)
@@ -22,10 +26,39 @@ describe('BubbleChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<bubble-chart chartId="bubblechartprop"></bubble-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('DoughnutChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<doughnut-chart></doughnut-chart>',
render: function (createElement) {
return createElement(
DoughnutChart
)
},
components: { DoughnutChart }
}).$mount(el)
@@ -22,10 +26,39 @@ describe('DoughnutChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<doughnut-chart chartId="doughnutchartprop"></doughnut-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('LineChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<line-chart></line-chart>',
render: function (createElement) {
return createElement(
LineChart
)
},
components: { LineChart }
}).$mount(el)
@@ -22,10 +26,39 @@ describe('LineChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<line-chart chartId="linechartprop"></line-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('PieChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<pie-chart></pie-chart>',
render: function (createElement) {
return createElement(
PieChart
)
},
components: { PieChart }
}).$mount(el)
@@ -22,10 +26,38 @@ describe('PieChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<pie-chart chartId="piechartprop"></pie-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('PolarChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<polar-chart></polar-chart>',
render: function (createElement) {
return createElement(
PolarChart
)
},
components: { PolarChart }
}).$mount(el)
@@ -22,10 +26,39 @@ describe('PolarChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<polar-chart chartId="polarchartprop"></polar-chart>',
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()
})
})
})

View File

@@ -10,7 +10,11 @@ describe('RadarChart', () => {
it('should render a canvas', () => {
const vm = new Vue({
template: '<radar-chart></radar-chart>',
render: function (createElement) {
return createElement(
RadarChart
)
},
components: { RadarChart }
}).$mount(el)
@@ -22,10 +26,38 @@ describe('RadarChart', () => {
it('should change id based on prop', () => {
const vm = new Vue({
template: '<radar-chart chartId="rodarchartprop"></radar-chart>',
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()
})
})
})

View File

5704
yarn.lock Normal file

File diff suppressed because it is too large Load Diff