Skip to content

Add Math.round for positions and dimensions #454

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

Merged
merged 7 commits into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/rzslider.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
.rzslider {
position: relative;
display: inline-block;
Expand Down
10 changes: 5 additions & 5 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -977,7 +977,7 @@
var tick = {
selected: self.isTickSelected(value),
style: {
transform: translate + '(' + position + 'px)'
transform: translate + '(' + Math.round(position) + 'px)'
}
};
if (tick.selected && self.options.getSelectionBarColor) {
Expand Down Expand Up @@ -1414,7 +1414,7 @@
setPosition: function(elem, pos) {
elem.rzsp = pos;
var css = {};
css[this.positionProperty] = pos + 'px';
css[this.positionProperty] = Math.round(pos) + 'px';
elem.css(css);
return pos;
},
Expand Down Expand Up @@ -1444,7 +1444,7 @@
setDimension: function(elem, dim) {
elem.rzsd = dim;
var css = {};
css[this.dimensionProperty] = dim + 'px';
css[this.dimensionProperty] = Math.round(dim) + 'px';
elem.css(css);
return dim;
},
Expand Down Expand Up @@ -1476,7 +1476,7 @@
var percent = fn(val, this.minValue, this.maxValue) || 0;
if (this.options.rightToLeft)
percent = 1 - percent;
return percent * this.maxPos;
return Math.round(percent * this.maxPos);
},

linearValueToPosition: function(val, minVal, maxVal) {
Expand Down
2 changes: 1 addition & 1 deletion dist/rzslider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/rzslider.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/rzslider.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.5 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2016-11-05 */
2016-11-08 */
.rzslider {
position: relative;
display: inline-block;
Expand Down
8 changes: 4 additions & 4 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@
var tick = {
selected: self.isTickSelected(value),
style: {
transform: translate + '(' + position + 'px)'
transform: translate + '(' + Math.round(position) + 'px)'
Copy link
Member

Choose a reason for hiding this comment

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

I think that this one is useless because you already patched the valueToPosition method.

}
};
if (tick.selected && self.options.getSelectionBarColor) {
Expand Down Expand Up @@ -1418,7 +1418,7 @@
setPosition: function(elem, pos) {
elem.rzsp = pos;
var css = {};
css[this.positionProperty] = pos + 'px';
css[this.positionProperty] = Math.round(pos) + 'px';
elem.css(css);
return pos;
},
Expand Down Expand Up @@ -1448,7 +1448,7 @@
setDimension: function(elem, dim) {
elem.rzsd = dim;
var css = {};
css[this.dimensionProperty] = dim + 'px';
css[this.dimensionProperty] = Math.round(dim) + 'px';
elem.css(css);
return dim;
},
Expand Down Expand Up @@ -1480,7 +1480,7 @@
var percent = fn(val, this.minValue, this.maxValue) || 0;
if (this.options.rightToLeft)
percent = 1 - percent;
return percent * this.maxPos;
return Math.round(percent * this.maxPos);
},

linearValueToPosition: function(val, minVal, maxVal) {
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/options-handling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@
};
helper.createRangeSlider(sliderConf);

var expectedDimension = Math.floor(helper.slider.valueToPosition(6)),
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
var expectedDimension = helper.slider.valueToPosition(6),
actualDimension = helper.slider.selBar[0].getBoundingClientRect().width + 1;
expect(actualDimension).to.equal(expectedDimension);

var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
Expand Down Expand Up @@ -752,8 +752,8 @@
};

helper.createRangeSlider(sliderConf);
expect(helper.slider.minLab.css('left')).to.equal('-' + (helper.slider.minLab.rzsd / 2 - helper.slider.handleHalfDim) + 'px');
expect(helper.slider.maxLab.css('left')).to.equal((helper.slider.barDimension - (helper.slider.maxLab.rzsd / 2 + helper.slider.handleHalfDim)) + 'px');
expect(helper.slider.minLab.css('left')).to.equal('-' + Math.round(helper.slider.minLab.rzsd / 2 - helper.slider.handleHalfDim) + 'px');
expect(helper.slider.maxLab.css('left')).to.equal(Math.round((helper.slider.barDimension - (helper.slider.maxLab.rzsd / 2 + helper.slider.handleHalfDim))) + 'px');

sliderConf.max = 100000001;
helper.createRangeSlider(sliderConf);
Expand Down Expand Up @@ -1217,8 +1217,8 @@
};
helper.createRangeSlider(sliderConf);

var expectedDimension = Math.floor(helper.slider.valueToPosition(6)),
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
var expectedDimension = helper.slider.valueToPosition(6),
actualDimension = helper.slider.selBar[0].getBoundingClientRect().width + 1;
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to add 1? It seems weird...

expect(actualDimension).to.equal(expectedDimension);

var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
Expand Down