]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Add parameters to tooltip filter option (#7556)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Mon, 29 Jun 2020 11:51:20 +0000 (04:51 -0700)
committerGitHub <noreply@github.com>
Mon, 29 Jun 2020 11:51:20 +0000 (07:51 -0400)
docs/docs/configuration/tooltip.md
docs/docs/getting-started/v3-migration.md
src/plugins/plugin.tooltip.js
test/specs/plugin.tooltip.tests.js

index cd98fdca9d8f7490a89907142f6f3911268de8a9..5647095bc0e821fbad4d9944cd3f47ba3fa1dabc 100644 (file)
@@ -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
 
index 3f0d3f5f5b5eac9081610fefcd1ffe5f405e131f..a5974aea2067236b18e44bba260a12ace874ee41 100644 (file)
@@ -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
 
index 6f239f64be3b2426029212b945e50f442a037be2..2ca517b5d31a3ef1bb4da5c42251d290bffd0ca1 100644 (file)
@@ -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
index 3478102b2d71e7331b44a44c0856c6b57a76ec5e..1e1aa8c172651cd9f74bd1e5e96a7421579a3ee7 100644 (file)
@@ -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;
                                        }