Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plugins/plugin.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ export class Tooltip extends Element {
_getActiveElements(e, lastActive, replay, inChartArea) {
const options = this.options;

if (e.type === 'mouseout') {
if (e.type === 'mouseout' || !inChartArea) {
return [];
}

Expand Down
20 changes: 13 additions & 7 deletions test/specs/plugin.tooltip.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ describe('Plugin.Tooltip', function() {
expect(chart.tooltip.getActiveElements().length).toBe(0);
});

it('should not change the active elements on events outside chartArea, except for mouseout', async function() {
it('should change the active elements on events outside chartArea and for mouseout', async function() {
var chart = acquireChart({
type: 'line',
data: {
Expand All @@ -1683,7 +1683,7 @@ describe('Plugin.Tooltip', function() {
expect(chart.tooltip.getActiveElements()).toEqual([{datasetIndex: 0, index: 0, element: point}]);

await jasmine.triggerMouseEvent(chart, 'mousemove', {x: 1, y: 1});
expect(chart.tooltip.getActiveElements()).toEqual([{datasetIndex: 0, index: 0, element: point}]);
expect(chart.tooltip.getActiveElements()).toEqual([]);

await jasmine.triggerMouseEvent(chart, 'mouseout', {x: 1, y: 1});
expect(chart.tooltip.getActiveElements()).toEqual([]);
Expand Down Expand Up @@ -1759,19 +1759,23 @@ describe('Plugin.Tooltip', function() {

const meta = chart.getDatasetMeta(0);
const point = meta.data[1];
const expectedPoints = [jasmine.objectContaining({datasetIndex: 0, index: 1}), jasmine.objectContaining({datasetIndex: 1, index: 1})];

await jasmine.triggerMouseEvent(chart, 'mousemove', point);
await jasmine.triggerMouseEvent(chart, 'mousemove', {x: chart.chartArea.left - 5, y: point.y});

expect(chart.tooltip.getActiveElements()).toEqual(expectedPoints);
// With the change to clear active elements when events are outside the chartArea,
// it expect no active elements after moving the mouse outside,
// and also when clicking ouside the chartArea on mobile devices
expect(chart.tooltip.getActiveElements()).toEqual([]);

chart.data.datasets = [dataset1];
chart.update();

await jasmine.triggerMouseEvent(chart, 'mousemove', {x: 2, y: 1});

expect(chart.tooltip.getActiveElements()).toEqual([expectedPoints[0]]);
// After datasets were removed and an event outside the chartArea is fired,
// active elements remain cleared according to the new behavior
expect(chart.tooltip.getActiveElements()).toEqual([]);
});

it('should tolerate elements removed on events outside chartArea', async function() {
Expand Down Expand Up @@ -1801,12 +1805,14 @@ describe('Plugin.Tooltip', function() {

const meta = chart.getDatasetMeta(0);
const point = meta.data[1];
const expectedPoints = [jasmine.objectContaining({datasetIndex: 0, index: 1}), jasmine.objectContaining({datasetIndex: 1, index: 1})];

await jasmine.triggerMouseEvent(chart, 'mousemove', point);
await jasmine.triggerMouseEvent(chart, 'mousemove', {x: chart.chartArea.left - 5, y: point.y});

expect(chart.tooltip.getActiveElements()).toEqual(expectedPoints);
// With the change to clear active elements when events are outside the chartArea,
// it expect no active elements after moving the mouse outside,
// and also when clicking ouside the chartArea on mobile devices
expect(chart.tooltip.getActiveElements()).toEqual([]);

dataset1.data = dataset1.data.slice(0, 1);
chart.data.datasets = [dataset1];
Expand Down