-
-
Notifications
You must be signed in to change notification settings - Fork 786
[WIP] fix: decimal step cause divide not equal #228
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
Conversation
7395d99
to
a132e78
Compare
a132e78
to
d57068d
Compare
ping @benjycui |
src/Range.jsx
Outdated
@@ -176,10 +176,17 @@ class Range extends React.Component { | |||
const { marks, step, min, max } = this.props; | |||
const cache = this._getPointsCache; | |||
if (!cache || cache.marks !== marks || cache.step !== step) { | |||
const decimal = step.toString().split('.')[1] && step.toString().split('.')[1].length; |
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.
Use getPrecision
?
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.
ok
src/Range.jsx
Outdated
const pointsObject = { ...marks }; | ||
if (step !== null) { | ||
for (let point = min; point <= max; point += step) { | ||
let point = min; | ||
while (point <= max) { |
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 loop will cost a lot.
e.g. min = 0 && max = 99999
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.
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.
the performance problem only occur when users set step
to be a very small decimals, I think it's not our worries ?
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.
maybe use something like binary search
+ Array.map
to caculate the point more quickly?
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.
caculate the point more quickly ——> avoid Maximum call stack
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.
Another idea, what if when step
is very small compare to max - min
, we don't calculate the whole points array at first, instead just get the formula,something like: value = f(index)
, then the cost just happen when every time getter
d57068d
to
3ef1197
Compare
3ef1197
to
778c729
Compare
close. going to open a new pr to fix the decimal step problem. |
close #227