]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Pass context parameter to custom tooltip (#7579)
authorBen McCann <322311+benmccann@users.noreply.github.com>
Mon, 6 Jul 2020 13:34:06 +0000 (06:34 -0700)
committerGitHub <noreply@github.com>
Mon, 6 Jul 2020 13:34:06 +0000 (09:34 -0400)
docs/docs/configuration/tooltip.md
docs/docs/getting-started/v3-migration.md
src/plugins/plugin.tooltip.js

index 5647095bc0e821fbad4d9944cd3f47ba3fa1dabc..3fb37fc6c8466718e2183e651336c3cd0d2ce4c4 100644 (file)
@@ -194,7 +194,7 @@ The tooltip items passed to the tooltip callbacks implement the following interf
 
 ## External (Custom) Tooltips
 
-Custom tooltips allow you to hook into the tooltip rendering process so that you can render the tooltip in your own custom way. Generally this is used to create an HTML tooltip instead of an oncanvas one. You can enable custom tooltips in the global or chart configuration like so:
+Custom tooltips allow you to hook into the tooltip rendering process so that you can render the tooltip in your own custom way. Generally this is used to create an HTML tooltip instead of an on-canvas tooltip. The `custom` option takes a function which is passed a context parameter containing the `chart` and `tooltip`. You can enable custom tooltips in the global or chart configuration like so:
 
 ```javascript
 var myPieChart = new Chart(ctx, {
@@ -205,7 +205,7 @@ var myPieChart = new Chart(ctx, {
             // Disable the on-canvas tooltip
             enabled: false,
 
-            custom: function(tooltipModel) {
+            custom: function(context) {
                 // Tooltip Element
                 var tooltipEl = document.getElementById('chartjs-tooltip');
 
@@ -218,6 +218,7 @@ var myPieChart = new Chart(ctx, {
                 }
 
                 // Hide if no tooltip
+                var tooltipModel = context.tooltip;
                 if (tooltipModel.opacity === 0) {
                     tooltipEl.style.opacity = 0;
                     return;
index b2be1b28bcc510a48ea7ca5fb303997339f5baac..73cb4d04f40dc503172b9cb436b3682176dab205 100644 (file)
@@ -186,6 +186,7 @@ Animation system was completely rewritten in Chart.js v3. Each property can now
 
 * `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)`
+* The `custom` callback now takes a context object that has `tooltip` and `chart` properties
 
 ## Developer migration
 
index 93b74bcfa44473d325f1ad9ab9d94ebc90d58ba5..ffd08be36b4ef1db70455084e29256d92e7ddcc5 100644 (file)
@@ -669,7 +669,7 @@ export class Tooltip extends Element {
                }
 
                if (changed && options.custom) {
-                       options.custom.call(me, [me]);
+                       options.custom.call(me, {chart: me._chart, tooltip: me});
                }
        }