Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display tooltips only at points in chart area #10289

Merged
merged 3 commits into from May 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/core.interaction.js
Expand Up @@ -97,6 +97,10 @@ function getIntersectItems(chart, position, axis, useFinalPosition) {
}

const evaluationFunc = function(element, datasetIndex, index) {
const chartArea = chart.chartArea;
if (element.x < chartArea.left || chartArea.right < element.x || element.y < chartArea.top || chartArea.bottom < element.y) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the _isPointInArea helper function here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the only issue here, @t-mangoe will you be able to update this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry. I noticed the comment, but have not yet updated it.
I will try to respond, so I hope you can wait.
(Or, I allow edits by maintainers, so it is ok that maintainers update this PR.)

return;
}
if (element.inRange(position.x, position.y, useFinalPosition)) {
items.push({element, datasetIndex, index});
}
Expand Down
37 changes: 37 additions & 0 deletions test/specs/core.interaction.tests.js
Expand Up @@ -834,4 +834,41 @@ describe('Core.Interaction', function() {
expect(elements).toEqual([meta0.data[1], meta1.data[0], meta1.data[1], meta1.data[2]]);
});
});

describe('tooltip element of scatter chart', function() {
it ('out-of-range datapoints are not shown in tooltip', function() {
let data = [];
for (let i = 0; i < 1000; i++) {
data.push({x: i, y: i});
}

const chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{data}]
},
options: {
scales: {
x: {
min: 1
}
}
}
});

const meta0 = chart.getDatasetMeta(0);
const firstElement = meta0.data[0];

const evt = {
type: 'click',
chart: chart,
native: true, // needed otherwise things its a DOM event
x: firstElement.x,
y: firstElement.y
};

const elements = Chart.Interaction.modes.point(chart, evt, {intersect: true}).map(item => item.element);
expect(elements).not.toContain(firstElement);
});
});
});