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

Fixes Too Many Datapoints being hovered #5332

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 5 additions & 1 deletion src/core/core.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function parseVisibleItems(chart, handler) {
for (j = 0, jlen = meta.data.length; j < jlen; ++j) {
var element = meta.data[j];
if (!element._view.skip) {
element.datasetlength = meta.data.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

this line seems unused

handler(element);
}
}
Expand Down Expand Up @@ -281,8 +282,11 @@ module.exports = {
parseVisibleItems(chart, function(element) {
if (element.inXRange(position.x)) {
items.push(element);
// Cleanup extra elements
if (items.length > 1) {
items.splice(1, items.length);
}
}

if (element.inRange(position.x, position.y)) {
intersectsItem = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/element.point.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defaults._set('global', {

function xRange(mouseX) {
var vm = this._view;
return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false;
return vm ? (Math.abs(mouseX - vm.x) < 2) : false;
Copy link
Contributor

Choose a reason for hiding this comment

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

why 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After testing I found 2 to be a reasonable number to have a decent X range without returning too many tooltip items. I found the lower the number the more precise the user has to be to the X coordinate of the datapoint for it to be highlighted which can get tedious if you have say 10 data points and are trying to have one highlighted.

}

function yRange(mouseY) {
Expand Down