Skip to content

Commit 559780b

Browse files
authored
Add documentation and type for 'common' plugin option (#733)
* Add documentation and type for 'common' plugin option * rephrases sentence about common in migration guide
1 parent 7525265 commit 559780b

File tree

10 files changed

+56
-16
lines changed

10 files changed

+56
-16
lines changed

docs/guide/configuration.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ The following options are available at the top level. They apply to all annotati
1010
| ---- | ---- | :----: | ---- | ----
1111
| [`animations`](#animations) | `object` | No | [see here](#default-animations) | To configure which element properties are animated and how.
1212
| `clip` | `boolean` | No | `true` | Are the annotations clipped to the chartArea.
13-
| `drawTime` | `string` | Yes | `'afterDatasetsDraw'` | See [drawTime](options#draw-time).
14-
| [`interaction`](options#interaction) | `Object` | No | `options.interaction` | To configure which events trigger plugin interactions
13+
| [`common`](#common) | `Object` | No | | To configure common options apply to all annotations
1514

1615
:::warning
1716

1817
Setting `clip` to `false`, you can enable the possibility to draw part of the annotation outside of the chart area.
1918

20-
Nevertheless events are only catched over the chartArea.
19+
Nevertheless events are only caught over the chartArea.
2120

2221
:::
2322

@@ -57,6 +56,15 @@ const options = {
5756
| `numbers` | `properties` | `['x', 'y', 'x2', 'y2', 'width', 'height', 'centerX', 'centerY', 'pointX', 'pointY', 'labelX', 'labelY', 'labelWidth', 'labelHeight', 'radius']`
5857
| `numbers` | `type` | `number`
5958

59+
## Common
60+
61+
The following options apply to all annotations unless they are overwritten on a per-annotation basis.
62+
63+
| Name | Type | [Scriptable](options#scriptable-options) | Default | Notes
64+
| ---- | ---- | :----: | ---- | ----
65+
| `drawTime` | `string` | Yes | `'afterDatasetsDraw'` | See [drawTime](options#draw-time).
66+
| [`interaction`](options#interaction) | `Object` | No | `options.interaction` | To configure which events trigger plugin interactions
67+
6068
## Events
6169

6270
The following options are available for all annotation types. These options can be specified per annotation, or at the top level which apply to all annotations.

docs/guide/migrationV2.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Chart.js version
66

7-
The annotation plugin requires at least version 3.7.0 to work because of some bug fixes that happend within chart.js itself.
7+
The annotation plugin requires at least version 3.7.0 to work because of some bug fixes that happened within chart.js itself.
88

99
## Options
1010

@@ -17,6 +17,20 @@ A number of changes were made to the configuration options passed to the plugin
1717
* `xPadding` and `yPadding` options were merged into a single `padding` object in the label configuration of line annotation to align with Chart.js options.
1818
* `enabled` option was replaced by `display` in the callout configuration of label annotation, in the label configuration of line and box annotations and in the arrow heads configuration of line annotation to have the same option on all elements.
1919
* `dblClickSpeed` option was removed from the plugin options because `dblclick` event hook is not available anymore.
20+
* `drawTime` option at top level plugin configuration is moved to new `common` object in the plugin annotation options, which contains options to apply to all annotations:
21+
22+
```javascript
23+
plugins: {
24+
annotation: {
25+
common: {
26+
drawTime: 'afterDraw'
27+
},
28+
annotations: [
29+
...
30+
]
31+
}
32+
}
33+
```
2034

2135
## Elements
2236

docs/samples/box/quarters.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const config = {
105105
},
106106
plugins: {
107107
annotation: {
108-
drawTime: 'beforeDraw',
108+
common: {
109+
drawTime: 'beforeDraw'
110+
},
109111
annotations: {
110112
annotation1,
111113
annotation2,

docs/samples/line/labelVisibility.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ const config = {
8888
display: false,
8989
},
9090
annotation: {
91-
drawTime: 'beforeDatasetsDraw',
91+
common: {
92+
drawTime: 'beforeDatasetsDraw'
93+
},
9294
annotations: {
9395
annotation1,
9496
annotation2

docs/samples/line/limited.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ const config = {
9595
},
9696
plugins: {
9797
annotation: {
98-
drawTime: 'beforeDraw',
98+
common: {
99+
drawTime: 'beforeDraw'
100+
},
99101
annotations: {
100102
annotation1,
101103
annotation2,

docs/samples/point/combined.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ const config = {
106106
},
107107
plugins: {
108108
annotation: {
109-
drawTime: 'beforeDraw',
109+
common: {
110+
drawTime: 'beforeDraw'
111+
},
110112
annotations: {
111113
annotation1,
112114
annotation2,

docs/samples/point/outsideChartArea.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ const config = {
7373
plugins: {
7474
annotation: {
7575
clip: false,
76-
drawTime: 'afterDraw',
76+
common: {
77+
drawTime: 'afterDraw'
78+
},
7779
annotations: {
7880
annotation1,
7981
annotation2

docs/samples/polygon/outsideChartArea.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ const config = {
8484
plugins: {
8585
annotation: {
8686
clip: false,
87-
drawTime: 'afterDraw',
87+
common: {
88+
drawTime: 'afterDraw'
89+
},
8890
annotations: {
8991
annotation1,
9092
annotation2,

types/options.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,14 @@ interface PolygonAnnotationOptions extends CoreAnnotationOptions, AnnotationPoin
151151
yAdjust?: Scriptable<number, PartialEventContext>,
152152
}
153153

154+
export interface AnnotationPluginCommonOptions {
155+
drawTime?: Scriptable<DrawTime, PartialEventContext>,
156+
interaction?: CoreInteractionOptions
157+
}
158+
154159
export interface AnnotationPluginOptions extends AnnotationEvents {
155160
animations?: Record<string, unknown>,
156161
annotations: AnnotationOptions[] | Record<string, AnnotationOptions>,
157162
clip?: boolean,
158-
drawTime?: Scriptable<DrawTime, PartialEventContext>,
159-
interaction?: CoreInteractionOptions
163+
common?: AnnotationPluginCommonOptions
160164
}

types/tests/exports.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ const chart = new Chart('id', {
1616
plugins: {
1717
annotation: {
1818
clip: false,
19-
interaction: {
20-
mode: 'nearest',
21-
axis: 'xy',
22-
intersect: true
19+
common: {
20+
interaction: {
21+
mode: 'nearest',
22+
axis: 'xy',
23+
intersect: true
24+
}
2325
},
2426
annotations: [{
2527
type: 'line',

0 commit comments

Comments
 (0)