mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
Compare commits
33 Commits
1.0.3
...
release/1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88d2771175 | ||
|
|
b8e7ce11de | ||
|
|
98961547f3 | ||
|
|
c11127e64f | ||
|
|
0f98800b92 | ||
|
|
8eefeeef86 | ||
|
|
d913e9c515 | ||
|
|
377ae5e27a | ||
|
|
9bcffae429 | ||
|
|
086fb1d4e9 | ||
|
|
f241613107 | ||
|
|
af373cf09d | ||
|
|
a7776f8407 | ||
|
|
776f3976ec | ||
|
|
3785e73b43 | ||
|
|
9bf6e6078d | ||
|
|
e62e8c81fb | ||
|
|
9f79fb581d | ||
|
|
45d500d401 | ||
|
|
9f02e95355 | ||
|
|
d80eace435 | ||
|
|
d9f95fd737 | ||
|
|
e3f9936049 | ||
|
|
2f66dd9a44 | ||
|
|
a3bed8b8b6 | ||
|
|
e48f4eaeec | ||
|
|
57f3c651ed | ||
|
|
3c5c572a86 | ||
|
|
c677dcb55a | ||
|
|
f5005fbd67 | ||
|
|
5258ab1a0f | ||
|
|
df7b6ec93e | ||
|
|
9a8e8d6e1e |
10
.github/CONTRIBUTING.md
vendored
Normal file
10
.github/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
Thank you for contributing vue-chartjs!
|
||||
=========================================
|
||||
|
||||
Please follow this steps:
|
||||
|
||||
1. Fork it ( https://github.com/apertureless/vue-chartjs/fork )
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create a new Pull Request
|
||||
14
.github/ISSUE_TEMPLATE.md
vendored
Normal file
14
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
### Expected Behavior
|
||||
|
||||
|
||||
### Actual Behavior
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
### Environment
|
||||
- OS: Write here
|
||||
- NPM Version: Write here
|
||||
|
||||
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
|
||||
### Fix or Enhancement?
|
||||
|
||||
|
||||
- [ ] All tests passed
|
||||
|
||||
|
||||
### Environment
|
||||
- OS: Write here
|
||||
- NPM Version: Write here
|
||||
|
||||
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)
|
||||
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,8 +1,43 @@
|
||||
# Change Log
|
||||
|
||||
## [Unreleased](https://github.com/apertureless/vue-chartjs/tree/HEAD)
|
||||
## [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)
|
||||
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.2...HEAD)
|
||||
**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)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.3...1.1.0)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Use Vue.util.mergeOptions to merge default options with user's options [\#5](https://github.com/apertureless/vue-chartjs/issues/5)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Feature/merge options \#5 [\#6](https://github.com/apertureless/vue-chartjs/pull/6) ([apertureless](https://github.com/apertureless))
|
||||
|
||||
## [1.0.3](https://github.com/apertureless/vue-chartjs/tree/1.0.3) (2016-08-20)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.2...1.0.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
|
||||
13
CODE_OF_CONDUCT.md
Normal file
13
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
||||
|
||||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Jakub Juszczak
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
28
README.md
28
README.md
@@ -1,12 +1,12 @@
|
||||
# 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)
|
||||
|
||||
> VueJS wrapper for ChartJs
|
||||
|
||||
## Install
|
||||
|
||||
Simply run `npm install vue-chartjs`
|
||||
Simply run `npm install vue-chartjs@1.1.3`
|
||||
|
||||
## How to use
|
||||
|
||||
@@ -107,17 +107,9 @@ export default {
|
||||
|
||||

|
||||
|
||||
## Todo
|
||||
|
||||
- [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
|
||||
### Bubble
|
||||
|
||||

|
||||
|
||||
## Build Setup
|
||||
|
||||
@@ -142,3 +134,15 @@ npm test
|
||||
```
|
||||
|
||||
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork it ( https://github.com/apertureless/vue-chartjs/fork )
|
||||
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||
4. Push to the branch (`git push origin my-new-feature`)
|
||||
5. Create a new Pull Request
|
||||
|
||||
## License
|
||||
|
||||
This software is distributed under [MIT license](LICENSE.txt).
|
||||
|
||||
BIN
assets/bubble.png
Normal file
BIN
assets/bubble.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
34
dist/vue-chartjs.js
vendored
34
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
@@ -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>
|
||||
30
package.json
30
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-chartjs",
|
||||
"version": "1.0.3",
|
||||
"version": "1.1.3",
|
||||
"description": "Vue wrapper for chart.js",
|
||||
"author": "Jakub Juszczak <jakub@nextindex.de>",
|
||||
"repository": {
|
||||
@@ -20,8 +20,9 @@
|
||||
"build": "node build/build.js",
|
||||
"unit": "karma start test/unit/karma.conf.js --single-run",
|
||||
"e2e": "node test/e2e/runner.js",
|
||||
"test": "npm run unit && npm run e2e",
|
||||
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
|
||||
"test": "npm run unit",
|
||||
"lint": "eslint --ext .js,.vue src test/unit/specs",
|
||||
"prepublish": "node build/build.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.0.0",
|
||||
@@ -34,13 +35,16 @@
|
||||
"babel-plugin-transform-runtime": "^6.0.0",
|
||||
"babel-preset-es2015": "^6.0.0",
|
||||
"babel-preset-stage-2": "^6.0.0",
|
||||
"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",
|
||||
"eslint-friendly-formatter": "^2.0.5",
|
||||
"eslint-loader": "^1.3.0",
|
||||
"eslint-plugin-html": "^1.3.0",
|
||||
"eslint-config-standard": "^5.1.0",
|
||||
"eslint-plugin-promise": "^1.0.8",
|
||||
"eslint-plugin-standard": "^1.3.2",
|
||||
"eventsource-polyfill": "^0.9.6",
|
||||
@@ -50,6 +54,8 @@
|
||||
"function-bind": "^1.0.2",
|
||||
"html-webpack-plugin": "^2.8.1",
|
||||
"http-proxy-middleware": "^0.12.0",
|
||||
"inject-loader": "^2.0.1",
|
||||
"isparta-loader": "^2.0.0",
|
||||
"json-loader": "^0.5.4",
|
||||
"karma": "^0.13.15",
|
||||
"karma-coverage": "^0.5.5",
|
||||
@@ -59,20 +65,16 @@
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-spec-reporter": "0.0.24",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"lodash": "^4.15.0",
|
||||
"lolex": "^1.4.0",
|
||||
"mocha": "^2.4.5",
|
||||
"chai": "^3.5.0",
|
||||
"nightwatch": "^0.8.18",
|
||||
"ora": "^0.2.0",
|
||||
"phantomjs-prebuilt": "^2.1.3",
|
||||
"selenium-server": "2.53.0",
|
||||
"shelljs": "^0.6.0",
|
||||
"sinon": "^1.17.3",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"inject-loader": "^2.0.1",
|
||||
"isparta-loader": "^2.0.0",
|
||||
"phantomjs-prebuilt": "^2.1.3",
|
||||
"chromedriver": "^2.21.2",
|
||||
"cross-spawn": "^2.1.5",
|
||||
"nightwatch": "^0.8.18",
|
||||
"selenium-server": "2.53.0",
|
||||
"ora": "^0.2.0",
|
||||
"shelljs": "^0.6.0",
|
||||
"url-loader": "^0.5.7",
|
||||
"vue-hot-reload-api": "^1.2.0",
|
||||
"vue-html-loader": "^1.0.0",
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="bar-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width="{{width}}" height="{{height}}" v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'bar-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,7 +26,7 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
@@ -44,12 +49,14 @@ export default Vue.extend({
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'bar',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
51
src/BaseCharts/Bubble.js
Normal file
51
src/BaseCharts/Bubble.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'bubble-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
},
|
||||
height: {
|
||||
default: 400,
|
||||
type: Number
|
||||
}
|
||||
},
|
||||
|
||||
data () {
|
||||
return {
|
||||
defaultOptions: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'bubble',
|
||||
data: data,
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
}
|
||||
},
|
||||
beforeDestroy () {
|
||||
this._chart.destroy()
|
||||
}
|
||||
})
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="doughnut-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'doughnut-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,18 +26,20 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'doughnut',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="line-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'line-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,7 +26,7 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
@@ -42,12 +47,14 @@ export default Vue.extend({
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="pie-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'pie-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,18 +26,20 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'pie',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="polar-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'polar-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,18 +26,20 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'polarArea',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import Vue from 'vue'
|
||||
import Chart from 'chart.js'
|
||||
import { mergeOptions } from '../helpers/options'
|
||||
|
||||
export default Vue.extend({
|
||||
template: `
|
||||
<div>
|
||||
<canvas id="radar-chart" width=width height=height v-el:canvas></canvas>
|
||||
<canvas id="{{chartId}}" width={{width}} height={{height}} v-el:canvas></canvas>
|
||||
</div>
|
||||
`,
|
||||
|
||||
props: {
|
||||
chartId: {
|
||||
default: 'radar-chart',
|
||||
type: String
|
||||
},
|
||||
width: {
|
||||
default: 400,
|
||||
type: Number
|
||||
@@ -21,18 +26,20 @@ export default Vue.extend({
|
||||
|
||||
data () {
|
||||
return {
|
||||
options: {
|
||||
defaultOptions: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
render (data, options = this.options) {
|
||||
render (data, options) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$els.canvas.getContext('2d'), {
|
||||
type: 'radar',
|
||||
data: data,
|
||||
options: options
|
||||
options: chartOptions
|
||||
}
|
||||
)
|
||||
this._chart.generateLegend()
|
||||
|
||||
40
src/examples/App.vue
Normal file
40
src/examples/App.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<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>
|
||||
<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'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
BarExample,
|
||||
LineExample,
|
||||
DoughnutExample,
|
||||
PieExample,
|
||||
RadarExample,
|
||||
PolarAreaExample,
|
||||
BubbleExample
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
</style>
|
||||
@@ -11,6 +11,6 @@ export default BarChart.extend({
|
||||
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({
|
||||
ready () {
|
||||
this.render({
|
||||
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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
5
src/helpers/options.js
Normal file
5
src/helpers/options.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import merge from 'lodash/fp/merge'
|
||||
|
||||
export function mergeOptions (obj, src) {
|
||||
return merge(obj, src)
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import Line from './BaseCharts/Line'
|
||||
import Pie from './BaseCharts/Pie'
|
||||
import PolarArea from './BaseCharts/PolarArea'
|
||||
import Radar from './BaseCharts/Radar'
|
||||
import Bubble from './BaseCharts/Bubble'
|
||||
|
||||
const VueCharts = {
|
||||
Bar,
|
||||
@@ -11,7 +12,8 @@ const VueCharts = {
|
||||
Line,
|
||||
Pie,
|
||||
PolarArea,
|
||||
Radar
|
||||
Radar,
|
||||
Bubble
|
||||
}
|
||||
|
||||
module.exports = VueCharts
|
||||
|
||||
17
test/unit/specs/Bar.spec.js
Normal file
17
test/unit/specs/Bar.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import BarChart from 'src/examples/BarExample'
|
||||
|
||||
describe('BarChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<bar-chart></bar-chart>',
|
||||
components: { BarChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/Bubble.spec.js
Normal file
17
test/unit/specs/Bubble.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import BubbleChart from 'src/examples/BubbleExample'
|
||||
|
||||
describe('BubbleChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<bubble-chart></bubble-chart>',
|
||||
components: { BubbleChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/Doughnut.spec.js
Normal file
17
test/unit/specs/Doughnut.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import DoughnutChart from 'src/examples/DoughnutExample'
|
||||
|
||||
describe('DoughnutChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<doughnut-chart></doughnut-chart>',
|
||||
components: { DoughnutChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
@@ -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!')
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/Line.spec.js
Normal file
17
test/unit/specs/Line.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import LineChart from 'src/examples/LineExample'
|
||||
|
||||
describe('LineChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<line-chart></line-chart>',
|
||||
components: { LineChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/Pie.spec.js
Normal file
17
test/unit/specs/Pie.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import PieChart from 'src/examples/PieExample'
|
||||
|
||||
describe('PieChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<pie-chart></pie-chart>',
|
||||
components: { PieChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/PolarArea.spec.js
Normal file
17
test/unit/specs/PolarArea.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import PolarChart from 'src/examples/PolarAreaExample'
|
||||
|
||||
describe('PolarChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<polar-chart></polar-chart>',
|
||||
components: { PolarChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
17
test/unit/specs/Radar.spec.js
Normal file
17
test/unit/specs/Radar.spec.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import RadarChart from 'src/examples/RadarExample'
|
||||
|
||||
describe('RadarChart', () => {
|
||||
it('should render a canvas', () => {
|
||||
const vm = new Vue({
|
||||
el: 'body',
|
||||
replace: false,
|
||||
template: '<radar-chart></radar-chart>',
|
||||
components: { RadarChart }
|
||||
})
|
||||
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
|
||||
})
|
||||
})
|
||||
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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user