Skip to content

Commit

Permalink
document defaults for plugins (#10490)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeLenaleee committed Jul 20, 2022
1 parent eeba91e commit 341f903
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/configuration/canvas-background.md
Expand Up @@ -35,7 +35,7 @@ const data = {
const plugin = {
id: 'custom_canvas_background_color',
beforeDraw: (chart) => {
const ctx = chart.canvas.getContext('2d');
const {ctx} = chart;
ctx.save();
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = 'lightGreen';
Expand Down
21 changes: 21 additions & 0 deletions docs/developers/plugins.md
Expand Up @@ -120,6 +120,27 @@ const chart = new Chart(ctx, {
});
```

#### Plugin defaults

You can set default values for your plugin options in the `defaults` entry of your plugin object. In the example below the canvas will always have a lightgreen backgroundColor unless the user overrides this option in `options.plugins.custom_canvas_background_color.color`.

```javascript
const plugin = {
id: 'custom_canvas_background_color',
beforeDraw: (chart, args, options) => {
const {ctx} = chart;
ctx.save();
ctx.globalCompositeOperation = 'destination-over';
ctx.fillStyle = options.color;
ctx.fillRect(0, 0, chart.width, chart.height);
ctx.restore();
},
defaults: {
color: 'lightGreen'
}
}
```

## Plugin Core API

Read more about the [existing plugin extension hooks](../api/interfaces/Plugin).
Expand Down

0 comments on commit 341f903

Please sign in to comment.