mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-04 23:44:05 +01:00
Add parameters to tooltip filter option (#7556)
This commit is contained in:
committed by
Evert Timberg
parent
aa523da832
commit
49f18c262c
@@ -93,7 +93,7 @@ Allows sorting of [tooltip items](#tooltip-item-interface). Must implement at mi
|
||||
|
||||
### Filter Callback
|
||||
|
||||
Allows filtering of [tooltip items](#tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a second parameter that is the data object passed to the chart.
|
||||
Allows filtering of [tooltip items](#tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.filter](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter). This function can also accept a fourth parameter that is the data object passed to the chart.
|
||||
|
||||
## Tooltip Callbacks
|
||||
|
||||
|
||||
@@ -185,6 +185,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
|
||||
#### Tooltip
|
||||
|
||||
* `xLabel` and `yLabel` were removed. Please use `index` and `value`
|
||||
* The `filter` option will now be passed additional parameters when called and should have the method signature `function(tooltipItem, index, tooltipItems, data)`
|
||||
|
||||
## Developer migration
|
||||
|
||||
|
||||
@@ -602,7 +602,7 @@ export class Tooltip extends Element {
|
||||
|
||||
// If the user provided a filter function, use it to modify the tooltip items
|
||||
if (options.filter) {
|
||||
tooltipItems = tooltipItems.filter((a) => options.filter(a, data));
|
||||
tooltipItems = tooltipItems.filter((element, index, array) => options.filter(element, index, array, data));
|
||||
}
|
||||
|
||||
// If the user provided a sorting function, use it to modify the tooltip items
|
||||
|
||||
@@ -706,7 +706,7 @@ describe('Core.Tooltip', function() {
|
||||
options: {
|
||||
tooltips: {
|
||||
mode: 'index',
|
||||
filter: function(tooltipItem, data) {
|
||||
filter: function(tooltipItem, index, tooltipItems, data) {
|
||||
// For testing purposes remove the first dataset that has a tooltipHidden property
|
||||
return !data.datasets[tooltipItem.datasetIndex].tooltipHidden;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user