Compare commits

...

10 Commits

Author SHA1 Message Date
Jakub Juszczak
1b527e9c67 💎 Release new version 2.6.0-rc1 2017-04-05 16:05:20 +02:00
Jakub Juszczak
3103d5acd9 Add browser full build 2017-04-05 16:04:24 +02:00
Jakub Juszczak
2c8d1169e8 Add version to object 2017-04-05 16:04:07 +02:00
Jakub
6ac651e55a Merge pull request #84 from gcoguiec/develop
Update release build to not include externals.
2017-04-05 14:07:40 +02:00
Guillaume Coguiec
129a52e4d7 Restore lodash as a dependency. 2017-04-03 15:19:20 -04:00
Guillaume Coguiec
11015b4080 Remove lodash from externals. 2017-04-03 15:18:23 -04:00
Jakub Juszczak
56edbf2bd4 Add language select and german translation 2017-04-01 20:07:56 +02:00
Jakub Juszczak
77c63d4dd4 ⬆️ Update docute docs 2017-04-01 19:59:25 +02:00
Jakub Juszczak
14cb2f9e62 📝 Update docs 2017-03-30 16:34:41 +02:00
Guillaume Coguiec
9e6b407a1e Update release build to not include externals. 2017-03-29 14:57:26 -04:00
9 changed files with 481 additions and 14 deletions

View File

@@ -0,0 +1,92 @@
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')
const npmCfg = require('../package.json');
var banner = [
npmCfg.name + ' v' + npmCfg.version,
'(c) ' + (new Date().getFullYear()) + ' ' + npmCfg.author,
npmCfg.homepage
].join('\n')
module.exports = {
entry: {
'vue-chartjs': './src/index.js'
},
output: {
filename: './dist/[name].full.js',
library: 'VueChartJs',
libraryTarget: 'umd',
umdNamedDefine: true
},
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')
},
{
test: /\.json$/, loader: 'json'
}
]
},
eslint: {
formatter: require('eslint-friendly-formatter')
},
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
},
plugins: [
new webpack.BannerPlugin(banner)
]
}
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')
]
}

18
build/webpack.release.full.min.js vendored Normal file
View File

@@ -0,0 +1,18 @@
var config = require('./webpack.release.full.js')
var webpack = require('webpack')
config.output.filename = config.output.filename.replace(/\.js$/, '.min.js')
delete config.devtool
config.plugins = [
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin()
]
module.exports = config

View File

@@ -4,6 +4,13 @@ var webpack = require("webpack")
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var projectRoot = path.resolve(__dirname, '../')
var cssLoader = ExtractTextPlugin.extract('style-loader', 'css-loader')
const npmCfg = require('../package.json');
var banner = [
npmCfg.name + ' v' + npmCfg.version,
'(c) ' + (new Date().getFullYear()) + ' ' + npmCfg.author,
npmCfg.homepage
].join('\n')
module.exports = {
entry: {
@@ -15,6 +22,10 @@ module.exports = {
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: {
'vue': 'vue',
'chart.js': 'chart.js'
},
module: {
preLoaders: [
{
@@ -47,6 +58,9 @@ module.exports = {
{
test: /\.s[a|c]ss$/,
loader: ExtractTextPlugin.extract('style-loader','css-loader!sass-loader')
},
{
test: /\.json$/, loader: 'json'
}
]
},
@@ -56,7 +70,10 @@ module.exports = {
babel: {
presets: ['es2015'],
plugins: ['transform-runtime']
}
},
plugins: [
new webpack.BannerPlugin(banner)
]
}
if (process.env.NODE_ENV === 'production') {

View File

@@ -70,7 +70,7 @@ There are some basic props defined in the BaseCharts. Because you `extend()` the
|---|---|
| width | chart width |
| height | chart height |
| id | id of the canvas |
| chart-id | id of the canvas |
## Examples

View File

@@ -1,12 +1,35 @@
self.$config = {
const langs = [
{title: 'English', path: '/home', matchPath: /^\/(home|changelog)/},
{title: 'Deutsch', path: '/de/', matchPath: /^\/de/}
]
docute.init({
title: 'vue-chartjs docs',
plugins: [
evanyou()
],
landing: true,
// or custom path
landing: '_landing.html',
repo: 'apertureless/vue-chartjs',
twitter: 'apertureless',
'edit-link': 'https://github.com/apertureless/vue-chartjs/blob/master/docs'
tocVisibleDepth: 2,
'edit-link': 'https://github.com/apertureless/vue-chartjs/blob/master/docs',
nav: {
default: [
{
title: 'Home', path: '/home'
},
{
title: 'Changelog', path: '/changelog', source: 'https://raw.githubusercontent.com/apertureless/vue-chartjs/develop/CHANGELOG.md'
},
{
title: 'Languages', type: 'dropdown', items: langs
}
],
'de': [
{
title: 'Startseite', path: '/de/'
}
]
},
plugins: [
evanyou()
],
})

311
docs/de/README.md Normal file
View File

@@ -0,0 +1,311 @@
---
search: deutsch
---
# vue-chartjs
**vue-chartjs** ist ein Wrapper für [Chart.js](https://github.com/chartjs/Chart.js) in vue. Man kann einfach wiederverwendbare Chart Components erstellen.
## Einleitung
`vue-chartjs` let you use chart.js without much hassle inside vue. It's perfect for people who need simple charts up and running as fast as possible.
It abstracts the basic logic but exposes the chart.js object to give you the most possible flexibility.
## Installation
If you are working with Vue.js 2+ simple run:
`yarn add vue-chartjs`
If you are using vue 1.x please use the `legacy` tag. However the vue 1 version is not maintained anymore.
`yarn add vue-chartjs@legacy`
## Schnellstart
You need to import the base chart and extend it. This gives much more flexibility when working with different data.
You can encapsulate your components and use props to pass data or you can directly imput them inside the component. However this way, your component is not reuseable.
You can import the whole package or each module individual.
```javascript
// CommitChart.js
import { Bar } from 'vue-chartjs'
export default Bar.extend({
mounted () {
// Overwriting base render method with actual data.
this.renderChart(data, options)
}
})
```
You can pass the `renderChart()` method, two arguments:
- Data object
- Options object
### Data object
The data object looks like this:
```javascript
{
labels: ['January', 'February'],
datasets: [
{
label: 'GitHub Commits',
backgroundColor: '#f87979',
data: [40, 20]
}
]
}
```
For more information take a look at the [Chart.js](http://www.chartjs.org/docs/#chart-configuration-chart-data) docs.
## Props
There are some basic props defined in the BaseCharts. Because you `extend()` them, they are *invisible*, but you can overwrite them:
| Prop | Description |
|---|---|
| width | chart width |
| height | chart height |
| chart-id | id of the canvas |
## Examples
Here are some exmaples
### Chart with props
You can create the data and options props to pass data to the chart.
```javascript
// LineChart.js
import { Line } from 'vue-chartjs'
export default Line.extend({
props: ['data', 'options'],
mounted () {
this.renderChart(this.data, this.options)
}
})
```
After you add your component you can use it:
```html
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
```
If you want to overwrite the width and height:
```html
<line-chart
:data="{your data object}"
:options="{responsive: false, maintainAspectRatio: false}"
:width="400"
:height="200"
>
</line-chart>
```
<p class="warning">
Please keep in mind, that you have to set `responsive: false` to be able to set a fix `width` and `height.
</p>
### Chart with local data
```javascript
import {Bar} from 'vue-chartjs'
export default Bar.extend({
data () {
return {
datacollection: {
labels: ['January', 'February'],
datasets: [
{
label: 'Data One',
backgroundColor: '#f87979',
data: [40, 20]
}
]
}
}
}
mounted () {
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
}
})
```
### Reusebale Components
If you want to keep your chart components reuseable, it's the best to add a wrapper to them. This way the chart component is only responsable for the pure data representation and the wrapper component for the logic behind it. There are many different usecases and it is different if you're running a Single Page Application or integrate it in for example laravel.
## Reactive Data
Chart.js does not provide a live update if you change the datasets. However `vue-chartjs` provides two mixins to achive this.
- `reactiveProp`
- `reactiveData`
Both mixins to actually the same. Most of the time you will use `reactiveProp`. It extends the logic of your chart component and automatically creates a prop names `chartData` and add a `vue watch` on this prop. On data change, it will either call `update()` if only the data inside the datasets has changed or `renderChart()` if new datasets were added.
`reactiveData` simply creates a local chartData variable which is not a prop! And add a watcher.
This is only usefull, if you need single purpose charts and make an API call inside your chart component.
```javascript
data () {
return {
chartData: null
}
}
```
### Example
**LineChart.js**
```javascript
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default Line.extend({
mixins: [reactiveProp],
props: ['options'],
mounted () {
// this.chartData is created in the mixin
this.renderChart(this.chartData, this.options)
}
})
```
**RandomChart.vue**
```javascript
<template>
<div class="small">
<line-chart :chart-data="datacollection"></line-chart>
<button @click="fillData()">Randomize</button>
</div>
</template>
<script>
import LineChart from './LineChart.js'
export default {
components: {
LineChart
},
data () {
return {
datacollection: null
}
},
mounted () {
this.fillData()
},
methods: {
fillData () {
this.datacollection = {
labels: [this.getRandomInt(), this.getRandomInt()],
datasets: [
{
label: 'Data One',
backgroundColor: '#f87979',
data: [this.getRandomInt(), this.getRandomInt()]
}, {
label: 'Data One',
backgroundColor: '#f87979',
data: [this.getRandomInt(), this.getRandomInt()]
}
]
}
},
getRandomInt () {
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
}
}
}
</script>
<style>
.small {
max-width: 600px;
margin: 150px auto;
}
</style>
```
<p class="warning">
⚠ Attention: If you mutate your data in a parent component and pass it to your child chart component keep in mind the javascript limitiations.
More info in this [issue#44](https://github.com/apertureless/vue-chartjs/issues/44)
</p>
### Limitations
<ul>
<li>[Caveats](https://vuejs.org/v2/guide/list.html#Caveats)</li>
<li>[Change-Detection-Caveats](https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats)</li>
<li>[vm.$watch](https://vuejs.org/v2/api/#vm-watch)</li>
</ul>
## Chart.js object
Sometimes you need more control over chart.js. Thats why you can access the chart.js instance over `this._chart`
## Available Charts
### Bar Chart
<p class="tip">
There are two versions of the Bar chart. `{Bar}` and `{HorizontalBar}`
</p>
![Bar](assets/bar.png)
### Line Chart
![Line](assets/line.png)
### Doughnut
![Doughnut](assets/doughnut.png)
### Pie
![Pie](assets/pie.png)
### Radar
![Pie](assets/radar.png)
### Polar Area
![Pie](assets/polar.png)
### Bubble
![Bubble](assets/bubble.png)
## Webpack, Browserify and dist files.
If you use `import VueCharts from 'vue-chartjs'` you will mostly import the UMD build of vue-chart.js
This is because of compatibility reasons. This approach however has a downside: vue.js and chart.js are bundled into the file.
And you end up with two vue instances.
If you're using webpack 2 or rollup however, it will automatically import the transpiled ES sources.
If you know what you're doing you can import directly from the transpiled es sources:
```
import { Line } from 'vue-chartjs/es'
```
### Browserify
In order for a browserify user to transpile the code, they would need to install `babelify` and `babel-preset-es2015` and add a .babelrc file in the root of their project with the following code:
```
{
"presets": ["es2015"]
}
```

View File

@@ -11,8 +11,8 @@
<!-- don't remove this part start -->
<div id="app"></div>
<script src="https://unpkg.com/docute-evanyou"></script>
<script src="https://unpkg.com/docute/dist/docute.js"></script>
<script src="./config.js"></script>
<script src="https://unpkg.com/docute@2/dist/docute.js"></script>
<!-- don't remove this part end -->
<!-- Google Analytics -->

View File

@@ -1,6 +1,6 @@
{
"name": "vue-chartjs",
"version": "2.5.6",
"version": "2.6.0-rc1",
"description": "vue.js wrapper for chart.js",
"author": "Jakub Juszczak <jakub@posteo.de>",
"homepage": "http://vue-chartjs.org",
@@ -37,7 +37,7 @@
"Charts"
],
"main": "dist/vue-chartjs.js",
"unpkg": "dist/vue-chartjs.min.js",
"unpkg": "dist/vue-chartjs.full.min.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"files": [
@@ -53,12 +53,14 @@
"e2e": "node test/e2e/runner.js",
"test": "npm run unit",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
"release": "webpack --progress --hide-modules --config ./build/webpack.release.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js",
"release": "webpack --progress --hide-modules --config ./build/webpack.release.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.min.js && webpack --progress --hide-modules --config ./build/webpack.release.full.js && NODE_ENV=production webpack --progress --hide-modules --config ./build/webpack.release.full.min.js",
"prepublish": "yarn run lint && yarn run test && yarn run build"
},
"dependencies": {
"lodash": "^4.17.4"
},
"peerDependencies": {
"chart.js": "^2.5.0",
"lodash": "^4.17.4",
"vue": "^2.2.6"
},
"devDependencies": {
@@ -70,6 +72,7 @@
"babel-preset-stage-2": "^6.22.0",
"babel-runtime": "^6.23.0",
"chai": "^3.5.0",
"chart.js": "^2.5.0",
"chromedriver": "^2.28.0",
"connect-history-api-fallback": "^1.1.0",
"cross-env": "^3.2.4",
@@ -112,6 +115,7 @@
"sinon": "^2.1.0",
"sinon-chai": "^2.9.0",
"url-loader": "^0.5.8",
"vue": "^2.2.6",
"vue-hot-reload-api": "^2.0.11",
"vue-html-loader": "^1.2.4",
"vue-loader": "^11.3.4",

View File

@@ -7,8 +7,10 @@ import PolarArea from './BaseCharts/PolarArea'
import Radar from './BaseCharts/Radar'
import Bubble from './BaseCharts/Bubble'
import mixins from './mixins/index.js'
import npmCfg from '../package.json'
const VueCharts = {
version: npmCfg.version,
Bar,
HorizontalBar,
Doughnut,