Skip to content

Commit 1701b84

Browse files
committed
Merge branch 'master' into innerLabelProto
2 parents 4d592cd + a8dc07b commit 1701b84

Some content is hidden

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

52 files changed

+1823
-394
lines changed

docs/.vuepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export default defineConfig({
135135
'types/doughnutLabel'
136136
]
137137
},
138+
'developers',
138139
{
139140
title: 'Migration',
140141
collapsable: true,

docs/guide/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The following options are available at the top level. They apply to all annotati
99
| Name | Type | [Scriptable](options.md#scriptable-options) | Default | Notes
1010
| ---- | ---- | :----: | ---- | ----
1111
| [`animations`](#animations) | `object` | No | [see here](#default-animations) | To configure which element properties are animated and how.
12+
| `annnotations` | `object`\|`array` | Yes | `undefined` | To configure all annotations to draw.
1213
| `clip` | `boolean` | No | `true` | Are the annotations clipped to the chartArea.
1314
| [`common`](#common) | `Object` | No | | To configure common options apply to all annotations
1415
| [`interaction`](options.md#interaction) | `Object` | No | `options.interaction` | To configure which events trigger plugin interactions
@@ -65,7 +66,7 @@ The following options apply to all annotations unless they are overwritten on a
6566

6667
| Name | Type | [Scriptable](options.md#scriptable-options) | Default | Notes
6768
| ---- | ---- | :----: | ---- | ----
68-
| `drawTime` | `string` | Yes | `'afterDatasetsDraw'` | See [drawTime](options#draw-time).
69+
| `drawTime` | `string`\|`number` | Yes | `'afterDatasetsDraw'` | See [drawTime](options#draw-time).
6970
| `init` | `boolean` | [See initial animation](#initial-animation) | `false` | Enable the animation to the annotations when they are drawing at chart initialization
7071

7172
### Initial animation

docs/guide/developers.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Developers
2+
3+
## Access to the annotation elements
4+
5+
The annotation plugin uses Chart.js elements to draw the annotation requested by the user. The following APIs allows the user to get the created annotation elements to use in callbacks or for other purposes.
6+
The APIs are available in the annotation plugin instance.
7+
8+
#### Script Tag
9+
10+
```html
11+
<script>
12+
// get annotation plugin instance
13+
const annotationPlugin = window['chartjs-plugin-annotation'];
14+
</script>
15+
```
16+
17+
#### Bundlers (Webpack, Rollup, etc.)
18+
19+
```javascript
20+
// get annotation plugin instance
21+
import annotationPlugin from 'chartjs-plugin-annotation';
22+
```
23+
24+
### `.getAnnotations(chart: Chart): AnnotationElement[]`
25+
26+
It provides all annotation elements configured by the plugin options, even if the annotations are not visible.
27+
28+
```javascript
29+
const myLineChart = new Chart(ctx, config);
30+
// get all annotation elements
31+
const elements = annotationPlugin.getAnnotations(myLineChart);
32+
```
33+

docs/guide/integration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ title: Integration
77
## Script Tag
88

99
```html
10-
<script src="path/to/chartjs/dist/chart.min.js"></script>
10+
<script src="path/to/chartjs/dist/chart.umd.js"></script>
1111
<script src="path/to/chartjs-plugin-annotation/dist/chartjs-plugin-annotation.min.js"></script>
1212
<script>
13-
var myChart = new Chart(ctx, {...});
13+
const myChart = new Chart(ctx, {...});
1414
</script>
1515
```
1616

docs/guide/options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module.exports = {
8383

8484
## Draw Time
8585

86-
The `drawTime` option for an annotation determines where in the chart lifecycle the drawing occurs. Four potential options are available:
86+
The `drawTime` option for an annotation determines where in the chart lifecycle the drawing occurs. Four potential predefined options are available:
8787

8888
| Option | Notes
8989
| ---- | ----
@@ -92,6 +92,8 @@ The `drawTime` option for an annotation determines where in the chart lifecycle
9292
| `'afterDatasetsDraw'` | Occurs after drawing of datasets but before items such as the tooltip
9393
| `'afterDraw'` | After other drawing is completed.
9494

95+
Furthermore, the `drawTime` option can be set as number which represents the dataset index used to draw the annotation, before that dataset will be.
96+
9597
## Option Context
9698

9799
The option context is used to give contextual information when resolving options and only applies to scriptable options. The object is preserved, so it can be used to store and pass information between calls / options.
@@ -116,6 +118,7 @@ In addition to [chart](#chart)
116118

117119
* `id`: the annotation id
118120
* `element`: the annotation element
121+
* `elements`: the array which contains the already created annotation elements.
119122
* `type`: `'annotation'`
120123

121124
The [annotation](#annotation) option context is passed to scriptable options in all other cases, except when resolving `id`, `type` or adjusting scale ranges. The same values resolved in `afterDataLimits` with [chart](#chart) context are again evaluated in `afterUpdate` with [annotation](#annotation) context.

docs/guide/types/_commonInnerLabel.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ All of these options can be [Scriptable](../options.md#scriptable-options)
99
| [`color`](#fonts-and-colors) | [`Color`\|`Color[]`](../options#color) | `'black'` | Text color.
1010
| `content` | `string`\|`string[]`\|[`Image`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image)\|[`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) | `null` | The content to show in the label.
1111
| `display` | `boolean` | `false` | Whether or not the label is shown.
12-
| `drawTime` | `string` | `options.drawTime` | See [drawTime](../options#draw-time). Defaults to the annotation draw time if unset
12+
| `drawTime` | `string`\|`number` | `options.drawTime` | See [drawTime](../options#draw-time). Defaults to the annotation draw time if unset
1313
| [`font`](#fonts-and-colors) | [`Font`\|`Font[]`](../options#font) | `{ weight: 'bold' }` | Label font
1414
| `height` | `number`\|`string` | `undefined` | Overrides the height of the image or canvas element. Could be set in pixel by a number, or in percentage of current height of image or canvas element by a string. If undefined, uses the height of the image or canvas element. It is used only when the content is an image or canvas element.
15+
| `hitTolerance` | `number` | `undefined` | Amount of pixels to interact with annotations within some distance of the mouse point.
1516
| `opacity` | `number` | `undefined` | Overrides the opacity of the image or canvas element. Could be set a number in the range 0.0 to 1.0, inclusive. If undefined, uses the opacity of the image or canvas element. It is used only when the content is an image or canvas element.
1617
| `padding` | [`Padding`](../options.md#padding) | `6` | The padding to add around the text label.
1718
| [`position`](#position) | `string`\|`{x: string, y: string}` | `'center'` | Anchor position of label in the annotation.

docs/guide/types/_commonOptions.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ The following options are available for all annotations.
1111
| [`borderDashOffset`](#styling) | `number` | Yes | `0`
1212
| [`borderShadowColor`](#styling) | [`Color`](../options.md#color) | Yes | `'transparent'`
1313
| [`display`](#general) | `boolean` | Yes | `true`
14-
| [`drawTime`](#general) | `string` | Yes | `'afterDatasetsDraw'`
14+
| [`drawTime`](#general) | `string`\|`number` | Yes | `'afterDatasetsDraw'`
15+
| [`hitTolerance`](#general) | `number` | Yes | `0`
1516
| [`init`](../configuration.html#common) | `boolean` | [See initial animation](../configuration.html#initial-animation) | `undefined`
1617
| [`id`](#general) | `string` | No | `undefined`
1718
| [`shadowBlur`](#styling) | `number` | Yes | `0`

docs/guide/types/box.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ If one of the axes does not match an axis in the chart, the box will take the en
7171
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range.
7272
| `display` | Whether or not this annotation is visible.
7373
| `drawTime` | See [drawTime](../options.md#draw-time).
74+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
7475
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
7576
| `rotation` | Rotation of the box in degrees.
7677
| `xMax` | Right edge of the box in units along the x axis.

docs/guide/types/ellipse.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ If one of the axes does not match an axis in the chart, the ellipse will take th
6868
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range.
6969
| `display` | Whether or not this annotation is visible.
7070
| `drawTime` | See [drawTime](../options.md#draw-time).
71+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
7172
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
7273
| `rotation` | Rotation of the ellipse in degrees, default is 0.
7374
| `xMax` | Right edge of the ellipse in units along the x axis.

docs/guide/types/label.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the bo
9292
| `display` | Whether or not this annotation is visible.
9393
| `drawTime` | See [drawTime](../options.md#draw-time).
9494
| `height` | Overrides the height of the image or canvas element. Could be set in pixel by a number, or in percentage of current height of image or canvas element by a string. If undefined, uses the height of the image or canvas element. It is used only when the content is an image or canvas element.
95+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
9596
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
9697
| `padding` | The padding to add around the text label.
9798
| `rotation` | Rotation of the label in degrees.

docs/guide/types/line.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ If `scaleID` is unset, then `xScaleID` and `yScaleID` are used to draw a line fr
8989
| `display` | Whether or not this annotation is visible.
9090
| `drawTime` | See [drawTime](../options.md#draw-time).
9191
| `endValue` | End two of the line when a single scale is specified.
92+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
93+
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
9294
| `scaleID` | ID of the scale in single scale mode. If unset, `xScaleID` and `yScaleID` are used.
9395
| `value` | End one of the line when a single scale is specified.
9496
| `xMax` | X coordinate of end two of the line in units along the x axis.
@@ -134,9 +136,10 @@ All of these options can be [Scriptable](../options.md#scriptable-options)
134136
| [`color`](#fonts-and-colors) | [`Color`\|`Color[]`](../options#color) | `'#fff'` | Text color.
135137
| `content` | `string`\|`string[]`\|[`Image`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image)\|[`HTMLCanvasElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement) | `null` | The content to show in the label.
136138
| `display` | `boolean` | `false` | Whether or not the label is shown.
137-
| `drawTime` | `string` | `options.drawTime` | See [drawTime](../options#draw-time). Defaults to the line annotation draw time if unset.
139+
| `drawTime` | `string`\|`number` | `options.drawTime` | See [drawTime](../options#draw-time). Defaults to the line annotation draw time if unset.
138140
| [`font`](#fonts-and-colors) | [`Font`\|`Font[]`](../options#font) | `{ weight: 'bold' }` | Label font.
139141
| `height` | `number`\|`string` | `undefined` | Overrides the height of the image or canvas element. Could be set in pixel by a number, or in percentage of current height of image or canvas element by a string. If undefined, uses the height of the image or canvas element. It is used only when the content is an image or canvas element.
142+
| `hitTolerance` | `number` | `undefined` | Amount of pixels to interact with annotations within some distance of the mouse point.
140143
| `opacity` | `number` | `undefined` | Overrides the opacity of the image or canvas element. Could be set a number in the range 0.0 to 1.0, inclusive. If undefined, uses the opacity of the image or canvas element. It is used only when the content is an image or canvas element.
141144
| `padding` | [`Padding`](../options.md#padding) | `6` | The padding to add around the text label.
142145
| `position` | `string` | `'center'` | Anchor position of label on line. Possible options are: `'start'`, `'center'`, `'end'`. It can be set by a string in percentage format `'number%'` which are representing the percentage on the width of the line where the label will be located.

docs/guide/types/point.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the bo
7373
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range.
7474
| `display` | Whether or not this annotation is visible.
7575
| `drawTime` | See [drawTime](../options.md#draw-time).
76+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
7677
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
7778
| `radius` | Size of the point in pixels.
7879
| `rotation` | Rotation of point, in degrees.

docs/guide/types/polygon.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ The 4 coordinates, xMin, xMax, yMin, yMax are optional. If not specified, the bo
7878
| `adjustScaleRange` | Should the scale range be adjusted if this annotation is out of range.
7979
| `display` | Whether or not this annotation is visible.
8080
| `drawTime` | See [drawTime](../options.md#draw-time).
81+
| `hitTolerance` | Amount of pixels to interact with annotations within some distance of the mouse point.
8182
| `id` | Identifies a unique id for the annotation and it will be stored in the element context. When the annotations are defined by an object, the id is automatically set using the key used to store the annotations in the object. When the annotations are configured by an array, the id, passed by this option in the annotation, will be used.
8283
| `radius` | Size of the polygon in pixels.
8384
| `rotation` | Rotation of polygon, in degrees.

0 commit comments

Comments
 (0)