From 5f1d4709ab773e435d77d939309960e0984badcc Mon Sep 17 00:00:00 2001 From: Saber Sun Date: Tue, 16 Jul 2024 17:54:14 +0800 Subject: [PATCH] bugfix: issue 11801 --- src/plugins/plugin.tooltip.js | 8 ++++---- test/specs/plugin.tooltip.tests.js | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index e76b1479e06..58ad4427674 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -630,13 +630,13 @@ export class Tooltip extends Element { return tooltipItems; } - update(changed, replay) { + update(changed, replay, inChartArea = true) { const options = this.options.setContext(this.getContext()); const active = this._active; let properties; let tooltipItems = []; - if (!active.length) { + if (!active.length || !inChartArea) { if (this.opacity !== 0) { properties = { opacity: 0 @@ -1147,7 +1147,7 @@ export class Tooltip extends Element { const positionChanged = this._positionChanged(active, e); // Remember Last Actives - const changed = replay || !_elementsEqual(active, lastActive) || positionChanged; + const changed = replay || !inChartArea || !_elementsEqual(active, lastActive) || positionChanged; // Only handle target event on tooltip change if (changed) { @@ -1159,7 +1159,7 @@ export class Tooltip extends Element { y: e.y }; - this.update(true, replay); + this.update(true, replay, inChartArea); } } diff --git a/test/specs/plugin.tooltip.tests.js b/test/specs/plugin.tooltip.tests.js index 69e8c7f64c9..922e2b671e6 100644 --- a/test/specs/plugin.tooltip.tests.js +++ b/test/specs/plugin.tooltip.tests.js @@ -965,7 +965,7 @@ describe('Plugin.Tooltip', function() { // First dispatch change event, should update tooltip await jasmine.triggerMouseEvent(chart, 'mousemove', firstPoint); - expect(tooltip.update).toHaveBeenCalledWith(true, undefined); + expect(tooltip.update).toHaveBeenCalledWith(true, undefined, true); // Reset calls tooltip.update.calls.reset(); @@ -1028,7 +1028,7 @@ describe('Plugin.Tooltip', function() { // First dispatch change event, should update tooltip await jasmine.triggerMouseEvent(chart, 'mousemove', firstPoint); - expect(tooltip.update).toHaveBeenCalledWith(true, undefined); + expect(tooltip.update).toHaveBeenCalledWith(true, undefined, true); // Reset calls tooltip.update.calls.reset(); @@ -1036,7 +1036,7 @@ describe('Plugin.Tooltip', function() { // Second dispatch change event (same event), should update tooltip // because position mode is 'nearest' await jasmine.triggerMouseEvent(chart, 'mousemove', secondPoint); - expect(tooltip.update).toHaveBeenCalledWith(true, undefined); + expect(tooltip.update).toHaveBeenCalledWith(true, undefined, true); }); describe('positioners', function() {