Skip to content

Commit da48ed9

Browse files
authored
Do not register the plugin automatically (#24)
This is a breaking change for all projects since, for consistency, this applies to all types of import (i.e. script, require, import).
1 parent 75be707 commit da48ed9

File tree

7 files changed

+115
-10
lines changed

7 files changed

+115
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **3.x**.
1111
## Documentation
1212

1313
- [Introduction](https://chartjs-plugin-deferred.netlify.app/)
14-
- [Installation](https://chartjs-plugin-deferred.netlify.app/installation.html)
14+
- [Getting Started](https://chartjs-plugin-deferred.netlify.app/getting-started.html)
1515
- [Options](https://chartjs-plugin-deferred.netlify.app/options.html)
1616
- [Samples](https://chartjs-plugin-deferred.netlify.app/samples/)
1717

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ module.exports = {
9090
sidebar: {
9191
'/guide/': [
9292
'',
93-
'installation',
93+
'getting-started',
9494
'options',
95+
'migration'
9596
],
9697
'/samples/': [
9798
'delay.md',

docs/guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **3.x**
1212

1313
## Table of Contents
1414

15-
* [Installation](installation.md)
15+
* [Getting Started](getting-started.md)
1616
* [Options](options.md)
1717
* [Samples](../samples)
1818

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
# Installation
1+
# Getting Started
22

3-
## npm
3+
## Installation
4+
5+
### npm
46

57
[![npm](https://img.shields.io/npm/v/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://npmjs.com/package/chartjs-plugin-deferred) [![npm downloads](https://img.shields.io/npm/dm/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://npmjs.com/package/chartjs-plugin-deferred)
68

79
```sh
810
npm install chartjs-plugin-deferred --save
911
```
1012

11-
## Bower
13+
### Bower
1214

1315
[![bower](https://img.shields.io/bower/v/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://libraries.io/bower/chartjs-plugin-deferred)
1416

1517
```sh
1618
bower install chartjs-plugin-deferred --save
1719
```
1820

19-
## CDN
21+
### CDN
2022

2123
[![jsdelivr](https://img.shields.io/npm/v/chartjs-plugin-deferred.svg?label=jsdelivr&style=flat-square&maxAge=600)](https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred@latest/dist/) [![jsdelivr hits](https://data.jsdelivr.com/v1/package/npm/chartjs-plugin-deferred/badge)](https://www.jsdelivr.com/package/npm/chartjs-plugin-deferred)
2224

@@ -29,7 +31,7 @@ https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred@1 // latest 1.x.x
2931

3032
Read more about jsDeliver versioning on their [website](https://www.jsdelivr.com/).
3133

32-
## Download
34+
### Download
3335

3436
[![github](https://img.shields.io/github/release/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest) [![github downloads](https://img.shields.io/github/downloads/chartjs/chartjs-plugin-deferred/total.svg?style=flat-square&maxAge=600)](https://somsubhra.github.io/github-release-stats/?username=chartjs&repository=chartjs-plugin-deferred)
3537

@@ -40,3 +42,51 @@ You can download the latest version of `chartjs-plugin-deferred` from the [GitHu
4042
- `chartjs-plugin-deferred.esm.js`
4143
- `chartjs-plugin-deferred.tgz` (contains all builds)
4244
- `chartjs-plugin-deferred.zip` (contains all builds)
45+
46+
## Integration
47+
48+
### HTML
49+
50+
```html
51+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js"></script>
52+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-plugin-deferred.min.js">
53+
```
54+
55+
::: warning IMPORTANT
56+
`chartjs-plugin-deferred` must be loaded **after** the Chart.js library!
57+
:::
58+
59+
Once loaded, the plugin, available under the global `ChartDeferred` property, needs to be [registered](#registration).
60+
61+
### Module
62+
63+
```javascript
64+
import {Chart} from 'chart.js';
65+
import ChartDeferred from 'chartjs-plugin-deferred';
66+
```
67+
68+
## Registration
69+
70+
Since version 2.x, this plugin **no longer registers itself automatically**. It must be manually registered either globally or locally.
71+
72+
```javascript
73+
// Register the plugin to all charts:
74+
Chart.register(ChartDeferred);
75+
```
76+
77+
```javascript
78+
// OR only to specific charts:
79+
var chart = new Chart(ctx, {
80+
plugins: [ChartDeferred],
81+
options: {
82+
// ...
83+
}
84+
})
85+
```
86+
87+
::: tip
88+
When imported via a [`<script>` tag](#html), use the global property `ChartDeferred`.
89+
:::
90+
91+
See also [Chart.js &rsaquo; Using plugins](https://www.chartjs.org/docs/latest/developers/plugins.html).
92+

docs/guide/migration.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Migration
2+
3+
## Migrating to v2.0.0
4+
5+
### Breaking Changes
6+
7+
Make sure to also read the [Chart.js v3 migration guide](https://www.chartjs.org/docs/latest/getting-started/v3-migration.html) since you may be impacted by more general breaking changes due to this new Chart.js version.
8+
9+
#### Explicit Plugin Registration
10+
11+
As described in the [getting started](getting-started.md#integration), it's now required to manually register this plugin, either globally:
12+
13+
```js
14+
Chart.plugins.register(ChartDeferred);
15+
```
16+
17+
or locally:
18+
19+
```js
20+
new Chart('foo', {
21+
plugins: [ChartDeferred]
22+
})
23+
```
24+
25+
#### Plugin registration
26+
27+
Chart.js v3 changed the way to register plugins and now requires to use `Chart.register(plugin)` instead of `Chart.plugins.register(plugin)`.
28+
29+
```js
30+
import {Chart} from 'chart.js';
31+
import ChartDeferred from 'chartjs-plugin-deferred';
32+
33+
Chart.register(ChartDeferred);
34+
```
35+
36+
See [Getting Started > Registration](getting-started.html#registration) for details.
37+
38+
#### Default options
39+
40+
The plugin default options are now accessible in `Chart.defaults.plugins.deferred.*` instead of `Chart.defaults.global.plugins.deferred.*` and can be modified using:
41+
42+
```js
43+
Chart.defaults.set('plugins.deferred', {
44+
delay: 100,
45+
// ...
46+
})
47+
```
48+
49+
### Notes
50+
51+
#### Chart.js type declaration <Badge text="TS only"/>
52+
53+
Chart.js v3 now provides TypeScript type declaration files bundled in the npm package so it's **not** anymore required to install the `@types/chart.js` package.

rollup.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = [
1313
input: 'src/plugin.js',
1414
output: ['.js', '.min.js'].map((suffix) => {
1515
const config = {
16+
name: 'ChartDeferred',
1617
file: `dist/${pkg.name}${suffix}`,
1718
banner: banner,
1819
format: 'umd',

src/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function unwatch(chart) {
120120
chart[MODEL_KEY].elements = [];
121121
}
122122

123-
Chart.register({
123+
export default {
124124
id: 'deferred',
125125

126126
defaults: {
@@ -180,4 +180,4 @@ Chart.register({
180180
destroy: function(chart) {
181181
unwatch(chart);
182182
}
183-
});
183+
};

0 commit comments

Comments
 (0)