-
Notifications
You must be signed in to change notification settings - Fork 55
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
Conversation
|
||
return domain[nearestLeftPointIndex]; | ||
if (rangePoints.length <= 1) { |
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.
is there a use case where there is a 0? is the undefined caught in this use case?
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.
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); |
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.
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(); | ||
} |
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.
FWIW I don't think you need this descending/reverse logic anymore since you're not assuming anything about sort order.
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.
that's a good point, will actually opt to update the code above and just use lodash's sortedIndex
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