You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/options.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,8 @@ Fonts use the same format as [chart.js](https://www.chartjs.org/docs/master/gene
10
10
11
11
## Scriptable Options
12
12
13
-
As with most options in chart.js, the annotation plugin options are scriptable. This means that a function can be passed which returns the value as needed. In the example below, the annotation is hidden when the screen is less than 1000px wide
13
+
As with most options in chart.js, the annotation plugin options are scriptable. This means that a function can be passed which returns the value as needed. In the example below, the annotation is hidden when the screen is less than 1000px wide.
14
+
The function receives 2 arguments, first is the [option context](#option-context) representing contextual information. An options resolver is passed as second argumet, which can be used to access other option in the same context.
14
15
15
16
```js chart-editor
16
17
/* <block:options:0> */
@@ -71,3 +72,31 @@ The `drawTime` option for an annotation determines where in the chart lifecycle
71
72
| `'beforeDatasetsDraw'` | Occurs after drawing of axes, but before datasets
72
73
| `'afterDatasetsDraw'` | Occurs after drawing of datasets but before items such as the tooltip
73
74
| `'afterDraw'` | After other drawing is completed.
75
+
76
+
## Option Context
77
+
78
+
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.
79
+
80
+
There are 2 levels of option context objects:
81
+
82
+
*`chart`
83
+
*`annotation`
84
+
85
+
The context object contains the following properties:
86
+
87
+
### chart
88
+
89
+
*`chart`: the associated chart
90
+
*`type`: `'chart'`
91
+
92
+
The [chart](#chart) option context is provided by Chart.js. It is passed to scriptable options when resolving annotation `id`, `type` and `drawTime` or adjusting scale ranges in `afterDataLimits` hook. The options resolved at that time are `scaleID`, `xScaleID`, `yScaleID`, `value`, `endValue`, `xMin`, `xMax`, `yMin`, `yMax`, `xValue` and `yValue`.
93
+
94
+
### annotation
95
+
96
+
In addition to [chart](#chart)
97
+
98
+
*`id`: the annotation id
99
+
*`element`: the annotation element
100
+
*`type`: `'annotation'`
101
+
102
+
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.
0 commit comments