-
Notifications
You must be signed in to change notification settings - Fork 146
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
Implement limits #115
base: master
Are you sure you want to change the base?
Implement limits #115
Conversation
I created a branch named "limits" in order to propose one modification in your code: https://github.com/ghusse/jQRangeSlider/tree/limits Take a look at it, and if it seems good to you, merge it in your branch. I removed the option limits in the bar, removed the code in _mouseDrag, and let handles constrain values. The bar just tries to keep the same distance between both handles. |
Conflicts: jQRangeSliderBar.js
Thanks. I merged it with my branch and also updated the other things you reported. |
We need to investigate on this bouncing issue. We also need to make the build to pass, and to add unit tests to verify that:
|
I still need to investigate further but, for the bouncing issue, this seems the root of the issue is that sometimes the offset values in cache are rounded integers instead of floats. |
jQuery offset methods always returns integers (in Chrome at least) whereas we sometimes set the position from a position value based on event.pageX, which is a float. Rounding all the position fixes the issue for me. _applyPosition: function(position){
position = position >> 0;
var offset = {
top: this.cache.offset.top,
left: position
};
this.element.offset({left:position});
this.cache.offset = offset;
} Would that be a problem @ghusse ? |
I'm ok with that. Just a question, do you know how it react when we call offset with a float value ? How does it round the value ? Is it a mathematical rounding, a truncation ? |
I did it to follow your code (in jQDateRangeSlider#_setOption and #values). |
OK. So, this might be not optimal but I found a solution. The issue came some, I think so at least, a matter of js handling the numbers : there were some really really slight difference between two positions (whereas it should not) like between "196" and "195.999999999956". |
Ok, great. It's not JS specific, it's a known limitation of float numbers binary encoding. |
Argh, once again, I did not test enough. This breaks the bar dragging (partially). I guess I did not put it in the good place. PS: indeed, this is not JS specific. |
There are some things I do not understand. For example, I logged the positions I received in several methods. This is what happens when the bar is not expected to move (and the values to change) :
In jQRangeSliderDraggable.js:77 the old position from the first line is this.cache.offset.left. |
What kind of interaction are you doing in this case ? |
I am dragging the bar. Each handle of the bar is stuck to the limits, so the bar is not supposed to move (which is almost the case since) and, the values are not supposed to change (since the bar did not move). |
It seems that constraintValues is not returning exactly the same value + I cannot see a test in the code verifying that before and after values are different before setting new positions. Where position is constrained: https://github.com/ghusse/jQRangeSlider/blob/master/jQRangeSliderDraggable.js#L73 Then applied: https://github.com/ghusse/jQRangeSlider/blob/master/jQRangeSliderDraggable.js#L100 |
See #85