-
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
Fix nearest interaction mode #5857
Conversation
What's the difference between |
https://codepen.io/kurkle/full/xQWMEr/ (nearest-x) |
I don't think we should introduce a new mode to achieve this use case because it's a duplicate of Changing (fixing?) our @etimberg I think you are the most familiar with that code, what do you think? |
If I recall correctly, I don't think we should change the behaviour of the current API. If anything, I would support a new key |
I don't think we added I really don't know when I don't think that's a consistent behavior, to me The picking logic really depends of the use case, even a return axis === 'xy' ? nearestItems.slice(0, 1) : nearestItems; Anyway, I would not expose a new |
with 'multiple' option: (also fixed that very annoying (bug?)) |
@etimberg What I don't like with the |
@kurkle how the |
|
@simonbrunel good point. Thanks for making those gifs. I'm fine to return all in the axis x or y case but that might be considered a breaking API change for existing users (it's also not great to change the return type but we've done it elsewhere before) |
Removed |
@kurkle In your fiddle, Instead, what do you think of this change, does it fixes your issue and works as expected? // ...
var distanceMetric = getDistanceMetricForAxis(option.axis);
var nearestItems = getNearestItems(chart, position, options.intersect, distanceMetric);
if (axis !== 'xy') {
return nearestItems;
}
// ... else previous picking code
// ...
return nearestItems.slice(0, 1); @etimberg the return type is the same (array) and currently the 'x' | 'y' behavior are not great, so I would consider this change as a bug fix :) If users want the current behavior of |
@simonbrunel In other words, As a side note, sorting by area seems to fail when hover also occurs (point is enlarged). |
Not exactly. For example, you could have two points with large radius, under the mouse cursor, at the same
I'm not sure, from my point of view, the Later, if requested, we can introduce a new option to limit the lookup to 1 item (the closest one) and make it work for all modes currently returning multiple items. |
created some more "tests" updateIn update b9ce414 sorting flicker re-appears (previous version always returned all nearestItems, not a slice after sort) So the sorting problem remains when compared items are of same size and hover enlarges the one chosen by dataset index. Now its larger and the smaller one gets chosen on next iteration (mouse move).. and so on. |
This is only somewhat related, but is there a use case where hover and tooltip modes should be different? This could be for example |
Can you push these changes so we can review it. If we agree, docs and unit tests will need to be updated.
That would have been great but I think it will break external code relying on the presence of |
done. again. |
Linking the following issues:
|
The blinking in 2.7.3 is pretty annoying, so would be fine with merging this |
I tested https://codepen.io/kurkle/full/LXmOaK/ and I like the axis X and Y behaviours. There's still some flickering on the |
two more pens to consider hover ignoring code (true added as parameter when calling from sorting function):
|
@etimberg @kurkle Your thoughts? |
I agree. Saves couple bytes too. Sorting those items could be useful, but that's another story again. |
@simonbrunel I'm onboard with that solution |
@kurkle do you think you can add unit tests for |
Sure. But there's a thing.
|
Return all items that are at the nearest distance to the point. Add unit tests for nearest + axis: 'x' and nearest + axis: 'y'
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.
Thanks @kurkle
Return all items that are at the nearest distance to the point and add unit tests for nearest + axis: 'x' and nearest + axis: 'y'
This is the mode I always seem to need, so thought it could be useful to others too.
Did not use much time with the function itself, just combined nearest and x - so it can probably be improved.
Fixes #3615
Fixes #5371