]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
3127 - Modify the itemSort callback for tooltips to accept a third parameter of the... 3128/head
authorCraig Vermeer <craig@vermeers.net>
Wed, 10 Aug 2016 13:54:21 +0000 (09:54 -0400)
committerCraig Vermeer <craig@vermeers.net>
Wed, 10 Aug 2016 13:54:21 +0000 (09:54 -0400)
docs/01-Chart-Configuration.md
src/core/core.tooltip.js

index 7eef8c827928210923bc39850c9a513b9d63827d..edcb882cd4252a31aba7cc127777f0b57d281983 100644 (file)
@@ -212,7 +212,7 @@ Name | Type | Default | Description
 enabled | Boolean | true | Are tooltips enabled
 custom | Function | null | See [section](#chart-configuration-custom-tooltips) below
 mode | String | 'single' | Sets which elements appear in the tooltip. Acceptable options are `'single'`, `'label'` or `'x-axis'`. <br>&nbsp;<br>`single` highlights the closest element. <br>&nbsp;<br>`label` highlights elements in all datasets at the same `X` value. <br>&nbsp;<br>`'x-axis'` also highlights elements in all datasets at the same `X` value, but activates when hovering anywhere within the vertical slice of the x-axis representing that `X` value.
-itemSort | Function | undefined | Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
+itemSort | Function | undefined | Allows sorting of [tooltip items](#chart-configuration-tooltip-item-interface). Must implement at minimum a function that can be passed to [Array.prototype.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).  This function can also accept a third parameter that is the data object passed to the chart.
 backgroundColor | Color | 'rgba(0,0,0,0.8)' | Background color of the tooltip
 titleFontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" | Font family for tooltip title inherited from global font family
 titleFontSize | Number | 12 | Font size for tooltip title inherited from global font size
index 6ab623886ed24abda53429f5adc225985d521f91..8da2fa44e431e14d33a2def1cb3ceed6cfe30ffa 100755 (executable)
@@ -292,7 +292,9 @@ module.exports = function(Chart) {
 
                                // If the user provided a sorting function, use it to modify the tooltip items
                                if (opts.itemSort) {
-                                       tooltipItems = tooltipItems.sort(opts.itemSort);
+                                       tooltipItems = tooltipItems.sort(function(a,b) {
+                                               return opts.itemSort(a,b, data);
+                                       });
                                }
 
                                // If there is more than one item, show color items