Skip to content

Commit d498b7c

Browse files
authored
Feature/v3 (apertureless#225)
* Remove Vue dependency and change extends Signed-off-by: Jakub Juszczak <[email protected]> * πŸ’Ž Release new version 3.0.0-rc0 * ⬆️ Update examples * πŸ“ Update README.md * ⬆️ Update examples * ⬆️ Update englishd docs * ⬆️ Update transalted docs with current code examples * πŸ”₯ Remove dist files from gitignore * ⬆️ Update dependencies vue and chartjs * Change private data Implements apertureless#182. The private chart instance is now in the vue.js data model. And can be accessed over `this.$data._chart` Updated unit tests * πŸ“ Update docs with private data * ✨ Add codeclimate ignore * ⬆️ Update codeclimate * ⬆️ Update codeclimate * ⬆️ Update codeclimate Add build and config folders to ignore
1 parent 0fa8261 commit d498b7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3710
-11787
lines changed

β€Ž.codeclimate.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
engines:
2+
eslint:
3+
enabled: true
4+
duplication:
5+
enabled: true
6+
config:
7+
languages:
8+
- javascript:
9+
ratings:
10+
paths:
11+
- "**.js"
12+
exclude_paths:
13+
- "dist/"
14+
- "test/**/*"
15+
- "es/"
16+
- "build/"
17+
- "config/"
18+
- "src/examples/**"

β€ŽREADME.md

+50-25
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Or if you want to use it directly in the browser add
4040
```html
4141
<script src="https://unpkg.com/vue-chartjs/dist/vue-chartjs.full.min.js"></script>
4242
```
43-
to your scripts. See [Codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010)
43+
to your scripts. See [Codepen](https://codepen.io/apertureless/pen/zEvvWM)
4444

4545
## Explanation of Different Builds
4646
There are three different entry points. It depends on which build setup do you have. The dependencies are bundled or required as a peerDependency.
@@ -49,33 +49,52 @@ There are three different entry points. It depends on which build setup do you h
4949
- Browserify / Webpack 1
5050
- Webpack 2
5151

52-
53-
| Build | Chart.js | Vue.js |
52+
| Build | Chart.js |
5453
|---|---|---|
55-
| vue-chartjs.full.js | Bundled | Bundled |
56-
| vue-chartjs.full.min.js | Bundled | Bundled |
57-
| vue-chartjs.js | peerDependency | peerDependency |
58-
| vue-chartjs.min.js | peerDependency | peerDependency |
59-
| es/index* | peerDependency | peerDependency |
54+
| vue-chartjs.full.js | Bundled |
55+
| vue-chartjs.full.min.js | Bundled |
56+
| vue-chartjs.js | peerDependency |
57+
| vue-chartjs.min.js | peerDependency |
58+
| es/index* | peerDependency |
6059

6160
### Browser
62-
You can use `vue-chartjs` directly in the browser without any build setup. Like in this [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). For this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Vue.js and Chart.js bundled into it. And bundled to a UMD Module. So you only need that one file.
61+
You can use `vue-chartjs` directly in the browser without any build setup. Like in this [codepen](https://codepen.io/apertureless/pen/zEvvWM). For this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Chart.js bundled into it. And bundled to a UMD Module. So you only need that one file.
62+
63+
You can then simply register your component:
64+
65+
```js
66+
Vue.component('line-chart', {
67+
extends: VueChartJs.Line,
68+
mounted () {
69+
this.renderChart({
70+
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
71+
datasets: [
72+
{
73+
label: 'Data One',
74+
backgroundColor: '#f87979',
75+
data: [40, 39, 10, 40, 39, 80, 40]
76+
}
77+
]
78+
}, {responsive: true, maintainAspectRatio: false})
79+
}
80+
})
81+
```
6382

6483

6584
### Browserify / Webpack 1
6685

6786
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
6887

69-
However Vue.js and Chart.js are `peerDependencies` so you have to install them separately. In most projects you will have `Vue.js` already installed anyways. This way, you can have different versions of Vue.js and Chart.js then in this package.
88+
However Chart.js is a `peerDependencies` so you have to install it separately. In most projects This way, you can have different versions of Chart.js then in this package.
7089

7190
### Webpack 2
7291
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js`
73-
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you three shaking will work. Like in the bundled version, `Vue.js` and `Chart.js` are `peerDependencies` and need to be installed.
92+
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you three shaking will work. Like in the bundled version, `Chart.js` is a `peerDependencies` and need to be installed.
7493

7594

7695
## How to use
7796

78-
You need to import the base chart class and extend it. This gives much more flexibility when working with different data. You can pass the data over props or vue-resource.
97+
You need to import the component and then either use `extends` or `mixins` and add it.
7998

8099
You can import the whole package or each module individual.
81100

@@ -90,7 +109,8 @@ Just create your own component.
90109
// CommitChart.js
91110
import { Bar } from 'vue-chartjs'
92111

93-
export default Bar.extend({
112+
export default {
113+
extends: Bar,
94114
mounted () {
95115
// Overwriting base render method with actual data.
96116
this.renderChart({
@@ -104,7 +124,7 @@ export default Bar.extend({
104124
]
105125
})
106126
}
107-
})
127+
}
108128
```
109129

110130
Then simply import and use your own extended component and use it like a normal vue component
@@ -118,15 +138,16 @@ import CommitChart from 'path/to/component/CommitChart'
118138
You can overwrite the default chart options. Just pass the options object as a second paramenter to the render method
119139

120140
```javascript
121-
// MonthlyIncome.js
141+
// MonthlyIncome.vue
122142
import { Line } from 'vue-chartjs'
123143

124-
export default Line.extend({
144+
export default {
145+
extends: Line,
125146
props: ['data', 'options'],
126147
mounted () {
127148
this.renderChart(this.data, this.options)
128149
}
129-
})
150+
}
130151
```
131152

132153
Use it in your vue app
@@ -163,13 +184,14 @@ However keep in mind the limitations of vue and javascript for mutations on arra
163184
// MonthlyIncome.js
164185
import { Line, mixins } from 'vue-chartjs'
165186

166-
export default Line.extend({
187+
export default {
188+
extends: Line,
167189
mixins: [mixins.reactiveProp],
168190
props: ['chartData', 'options'],
169191
mounted () {
170192
this.renderChart(this.chartData, this.options)
171193
}
172-
})
194+
}
173195

174196
```
175197

@@ -181,40 +203,43 @@ Some ways to import them:
181203
// Load complete module with all charts
182204
import VueCharts from 'vue-chartjs'
183205

184-
export default VueCharts.Line.extend({
206+
export default {
207+
extends: VueCharts.Line,
185208
mixins: [VueCharts.mixins.reactiveProp],
186209
props: ['chartData', 'options'],
187210
mounted () {
188211
this.renderChart(this.chartData, this.options)
189212
}
190-
})
213+
}
191214
```
192215

193216
```javascript
194217
// Load speperate modules
195218
import { Line, mixins } from 'vue-chartjs'
196219

197-
export default Line.extend({
220+
export default {
221+
extends: Line,
198222
mixins: [mixins.reactiveProp],
199223
props: ['chartData', 'options'],
200224
mounted () {
201225
this.renderChart(this.chartData, this.options)
202226
}
203-
})
227+
}
204228
```
205229

206230
```javascript
207231
// Load speperate modules with destructure assign
208232
import { Line, mixins } from 'vue-chartjs'
209233
const { reactiveProp } = mixins
210234

211-
export default Line.extend({
235+
export default {
236+
extends: Line,
212237
mixins: [reactiveProp],
213238
props: ['chartData', 'options'],
214239
mounted () {
215240
this.renderChart(this.chartData, this.options)
216241
}
217-
})
242+
}
218243
```
219244

220245
## Available Charts

β€Žbuild/webpack.release.js

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module.exports = {
2323
umdNamedDefine: true
2424
},
2525
externals: {
26-
'vue': 'vue',
2726
'chart.js': 'chart.js'
2827
},
2928
module: {

0 commit comments

Comments
Β (0)