Skip to content

Slider: Fix max calculation, when step is float #1398

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

Closed
wants to merge 1 commit into from

Conversation

dekajp
Copy link
Contributor

@dekajp dekajp commented Dec 16, 2014

Fixes #10721

new _calculateNewMax method uses while loop, the cost should be very minimum
since this method is called one time in life of control, in create method or
when setOption(max) is called.

below method uses math functions to avoid loop, but this was failing
unit tests of slider_options.

TODO : to avoid while loop in Max Calculation


_calculateNewMax: function() {
  var precision = this._precision();
  var multiplier = Math.pow( 10 , precision );
  var max = this.options.max * multiplier ;
  var min = this._valueMin() * multiplier ;
  var step = this.options.step * multiplier ;
  var remainder = ( max - min ) % step;
  this.max = ( ( max - remainder ) / multiplier ).toFixed(precision);
}

@jzaefferer
Copy link
Member

@dekajp were you going to update this to address your own TODO?

@dekajp
Copy link
Contributor Author

dekajp commented Dec 23, 2014

@jzaefferer I am not planning as of now.

@dekajp
Copy link
Contributor Author

dekajp commented Dec 30, 2014

@jzaefferer i think i now know the reason why the TODO method was not working , this should fix it.
this.max = parseFloat( ( ( max - remainder ) / multiplier ).toFixed(precision) );

i will send a updated PR . i did not know toFixed was returning string. my bad

multiplier = ( Math.pow( 10, precision ) ),
max = ( this.options.max * multiplier ),
min = ( this._valueMin() * multiplier ),
step =( this.options.step * multiplier ),
Copy link
Member

Choose a reason for hiding this comment

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

Please remove all of the extraneous parens.

scottgonzalez pushed a commit that referenced this pull request Feb 9, 2015
Fixes #10721
Closes gh-1398
(cherry picked from commit ae1d6d5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants