-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
handler(element); | ||
} | ||
} | ||
|
@@ -279,10 +280,19 @@ module.exports = { | |
var intersectsItem = false; | ||
|
||
parseVisibleItems(chart, function(element) { | ||
if (element.inXRange(position.x)) { | ||
items.push(element); | ||
if (element.datasetlength < 40) { | ||
if (element.inXRange(position.x)) { | ||
items.push(element); | ||
} | ||
} else if (element.datasetlength >= 40) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could turn this however, i'm not sure why the check for whether there are more or less than 40 elements is being added. Why not always to do the cleanup of extra elements? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It wants you to combine the else with the next if: I still am not understanding though why we do not always call |
||
if (element.inXRangeSmall(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; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,11 @@ function xRange(mouseX) { | |
return vm ? (Math.abs(mouseX - vm.x) < vm.radius + vm.hitRadius) : false; | ||
} | ||
|
||
function xRangeSmall(mouseX) { | ||
var vm = this._view; | ||
return vm ? (Math.abs(mouseX - vm.x) < 2) : false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
var vm = this._view; | ||
return vm ? (Math.abs(mouseY - vm.y) < vm.radius + vm.hitRadius) : false; | ||
|
@@ -40,6 +45,7 @@ module.exports = Element.extend({ | |
|
||
inLabelRange: xRange, | ||
inXRange: xRange, | ||
inXRangeSmall: xRangeSmall, | ||
inYRange: yRange, | ||
|
||
getCenterPoint: function() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line seems unused