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

Fix invert point scale logic to get option closest to mouse pointer #150

Merged
merged 1 commit into from
Apr 29, 2019

Conversation

krissalvador27
Copy link
Contributor

@krissalvador27 krissalvador27 commented Apr 29, 2019

Bug fix to get the correct option/datum/category that the user's mouse is hovering over when the chart is using ordinal/point scale

@krissalvador27 krissalvador27 merged commit 642a7ff into master Apr 29, 2019
@krissalvador27 krissalvador27 deleted the fix-invert-pt-scale-logic branch April 29, 2019 15:41

return domain[nearestLeftPointIndex];
if (rangePoints.length <= 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a use case where there is a 0? is the undefined caught in this use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inspecting d3's code domain looks like it'll always return an array https://github.com/d3/d3-scale/blob/master/src/continuous.js#L91

return Math.abs(current - number) < Math.abs(list[closestI] - number)
? i
: closestI;
}, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi! Thanks for keeping the Reactochart dream alive!

Just FYI - the original reason i wrote it <-- that way was because we were assuming the input data would be sorted (by domain, either ascending or descending). With this assumption, you can use _.sortedIndex to do a binary search in O(log n) time. With ^the new method here, it works for all data regardless of sort order, but always searches every data point, so it's O(n) which can get slow for large datasets.

IIRC, the plan was to eventually allow a sorted flag (on the XYPlot i guess?) that would tell Reactochart whether the data was sorted or not - it would default false, but if true would use tricks like this to get better performance for sorted data. Might be a nice enhancement for the future.

Hope all is well with y'all :)

if (isDescending) {
domain.reverse();
rangePoints.reverse();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I don't think you need this descending/reverse logic anymore since you're not assuming anything about sort order.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good point, will actually opt to update the code above and just use lodash's sortedIndex

install pushed a commit that referenced this pull request Feb 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants