Add interaction options (#7922)

* Add interaction options
* Add migration note
This commit is contained in:
Jukka Kurkela
2020-10-19 14:24:06 +03:00
committed by GitHub
parent 41eb16a650
commit f5c4f97504
13 changed files with 85 additions and 28 deletions

View File

@@ -10,8 +10,8 @@ The tooltip configuration is passed into the `options.tooltips` namespace. The g
| ---- | ---- | ------- | -----------
| `enabled` | `boolean` | `true` | Are on-canvas tooltips enabled?
| `custom` | `function` | `null` | See [custom tooltip](#external-custom-tooltips) section.
| `mode` | `string` | `'nearest'` | Sets which elements appear in the tooltip. [more...](../general/interactions/modes.md#interaction-modes).
| `intersect` | `boolean` | `true` | If true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times.
| `mode` | `string` | | Sets which elements appear in the tooltip. [more...](../general/interactions/modes.md#interaction-modes).
| `intersect` | `boolean` | | If true, the tooltip mode applies only when the mouse position intersects with an element. If false, the mode will be applied at all times.
| `position` | `string` | `'average'` | The mode for positioning the tooltip. [more...](#position-modes)
| `callbacks` | `object` | | See the [callbacks section](#tooltip-callbacks).
| `itemSort` | `function` | | Sort tooltip items. [more...](#sort-callback)

View File

@@ -2,7 +2,7 @@
title: Interactions
---
The hover configuration is passed into the `options.hover` namespace. The global hover configuration is at `Chart.defaults.hover`. To configure which events trigger chart interactions, see [events](./events.md#events).
The interaction configuration is passed into the `options.interaction` namespace. The global interaction configuration is at `Chart.defaults.interaction`. To configure which events trigger chart interactions, see [events](./events.md#events).
| Name | Type | Default | Description
| ---- | ---- | ------- | -----------

View File

@@ -4,6 +4,8 @@ title: Interaction Modes
When configuring interaction with the graph via hover or tooltips, a number of different modes are available.
`options.hover` and `options.tooltips` extend from `options.interaction`. So if `mode`, `intersect` or any other common settings are configured only in `options.interaction`, both hover and tooltips obey that.
The modes are detailed below and how they behave in conjunction with the `intersect` setting.
## point
@@ -15,7 +17,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'point'
}
}
@@ -31,7 +33,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'nearest'
}
}
@@ -47,7 +49,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'index'
}
}
@@ -61,7 +63,7 @@ var chart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
tooltips: {
interaction: {
mode: 'index',
axis: 'y'
}
@@ -77,7 +79,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'dataset'
}
}
@@ -92,7 +94,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'x'
}
}
@@ -107,7 +109,7 @@ var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
tooltips: {
interaction: {
mode: 'y'
}
}

View File

@@ -202,6 +202,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
#### Interactions
* To allow DRY configuration, a root options scope for common interaction options was added. `options.hover` and `options.tooltips` now both extend from `options.interaction`. Defaults are defined at `defaults.interaction` level, so by default hover and tooltip interactions share the same mode etc.
* `interactions` are now limited to the chart area
* `{mode: 'label'}` was replaced with `{mode: 'index'}`
* `{mode: 'single'}` was replaced with `{mode: 'nearest', intersect: true}`