Commit 2a7b45d8 authored by Valentin Hervieu's avatar Valentin Hervieu Committed by GitHub

feat(logScale): Implement a logScale option (#280)

*  feat(logScale): Implement a logScale option to display sliders with logarithmic scale
parent 37a4f901
# 5.7.0 (2016-10-16)
## Features
- Add a `logScale` option to display the slider using a logarithmic scale (#280).
- Add `customValueToPosition` and `customPositionToValue` options to display the slider using a custom scale (#280).
# 5.6.0 (2016-10-16) # 5.6.0 (2016-10-16)
## Features ## Features
- Add an `ticksArray` to display ticks at specific positions (#426). - Add a `ticksArray` option to display ticks at specific positions (#426).
To enable this new feature, the way the ticks are rendered has been changed. Now each tick is positioned absolutely using a `transform: translate()` instruction. To enable this new feature, the way the ticks are rendered has been changed. Now each tick is positioned absolutely using a `transform: translate()` instruction.
......
...@@ -239,7 +239,10 @@ The default options are: ...@@ -239,7 +239,10 @@ The default options are:
rightToLeft: false, rightToLeft: false,
boundPointerLabels: true, boundPointerLabels: true,
mergeRangeLabelsIfSame: false, mergeRangeLabelsIfSame: false,
customTemplateScope: null customTemplateScope: null,
logScale: false,
customValueToPosition: null,
customPositionToValue: null
} }
```` ````
...@@ -382,6 +385,14 @@ _Changing this value at runtime is not currently supported._ ...@@ -382,6 +385,14 @@ _Changing this value at runtime is not currently supported._
**customTemplateScope** - _Object (default to null)_: The properties defined in this object will be exposed in the slider template under `custom.X`. **customTemplateScope** - _Object (default to null)_: The properties defined in this object will be exposed in the slider template under `custom.X`.
**logScale** - _Boolean (defaults to false)_: Set to true to use a logarithmic scale to display the slider.
For custom scales:
**customValueToPosition** - _Function(val, minVal, maxVal): percent_: Function that returns the position on the slider for a given value. The position must be a percentage between 0 and 1.
**customPositionToValue** - _Function(percent, minVal, maxVal): value_: Function that returns the value for a given position on the slider. The position is a percentage between 0 and 1.
## Change default options ## Change default options
If you want the change the default options for all the sliders displayed in your application, you can set them using the `RzSliderOptions.options()` method: If you want the change the default options for all the sliders displayed in your application, you can set them using the `RzSliderOptions.options()` method:
```js ```js
......
...@@ -13,6 +13,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -13,6 +13,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
options: { options: {
floor: 0, floor: 0,
ceil: 100, ceil: 100,
rightToLeft: true,
step: 1 step: 1
} }
}; };
...@@ -137,6 +138,41 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -137,6 +138,41 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
} }
}; };
//Slider config with logarithmic scale
$scope.slider_log = {
value: 1,
options: {
floor: 1,
ceil: 100,
logScale: true,
showTicks: true
}
};
//Slider config with custom scale
$scope.slider_custom_scale = {
value: 50,
options: {
floor: 0,
ceil: 100,
step: 10,
showTicksValues: true,
customValueToPosition: function(val, minVal, maxVal) {
val = Math.sqrt(val);
minVal = Math.sqrt(minVal);
maxVal = Math.sqrt(maxVal);
var range = maxVal - minVal;
return (val - minVal) / range;
},
customPositionToValue: function(percent, minVal, maxVal) {
minVal = Math.sqrt(minVal);
maxVal = Math.sqrt(maxVal);
var value = percent * (maxVal - minVal) + minVal;
return Math.pow(value, 2);
}
}
};
//Right to left slider with floor, ceil and step //Right to left slider with floor, ceil and step
$scope.slider_floor_ceil_rtl = { $scope.slider_floor_ceil_rtl = {
value: 12, value: 12,
...@@ -232,8 +268,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -232,8 +268,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
options: { options: {
ceil: 10, ceil: 10,
floor: 0, floor: 0,
ticksArray: [0, 1, 3, 8, 10], ticksArray: [0, 1, 3, 8, 10]
showTicksValues: true
} }
}; };
...@@ -322,7 +357,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) { ...@@ -322,7 +357,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
step: 50, step: 50,
showSelectionBar: true, showSelectionBar: true,
showTicks: true, showTicks: true,
getTickColor: function(value){ getTickColor: function(value) {
if (value < 300) if (value < 300)
return 'red'; return 'red';
if (value < 600) if (value < 600)
...@@ -564,8 +599,8 @@ app.directive('clickableLabel', function() { ...@@ -564,8 +599,8 @@ app.directive('clickableLabel', function() {
scope: {label: '='}, scope: {label: '='},
replace: true, replace: true,
template: "<button ng-click='onclick(label)' style='cursor: pointer;'>click me - {{label}}</button>", template: "<button ng-click='onclick(label)' style='cursor: pointer;'>click me - {{label}}</button>",
link: function(scope, elem, attrs){ link: function(scope, elem, attrs) {
scope.onclick = function(label){ scope.onclick = function(label) {
alert("I'm " + label); alert("I'm " + label);
}; };
} }
......
...@@ -119,6 +119,22 @@ ...@@ -119,6 +119,22 @@
></rzslider> ></rzslider>
</article> </article>
<article>
<h2>Slider with logarithmic scale</h2>
<rzslider
rz-slider-model="slider_log.value"
rz-slider-options="slider_log.options"
></rzslider>
</article>
<article>
<h2>Slider with custom scale</h2>
<rzslider
rz-slider-model="slider_custom_scale.value"
rz-slider-options="slider_custom_scale.options"
></rzslider>
</article>
<article> <article>
<h2>Right to left slider with custom floor/ceil/step</h2> <h2>Right to left slider with custom floor/ceil/step</h2>
<rzslider <rzslider
......
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,11 @@ module.exports = function (config) { ...@@ -8,7 +8,11 @@ module.exports = function (config) {
// testing framework to use (jasmine/mocha/qunit/...) // testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['mocha', 'sinon', 'chai'], frameworks: ['mocha', 'sinon', 'chai'],
reporters: ['dots', 'coverage'], reporters: ['mocha', 'coverage'],
mochaReporter: {
showDiff: true
},
// list of files / patterns to load in the browser // list of files / patterns to load in the browser
files: [ files: [
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
"devDependencies": { "devDependencies": {
"angular": "1.4.7", "angular": "1.4.7",
"angular-mocks": "1.4.8", "angular-mocks": "1.4.8",
"chai": "^3.4.1", "chai": "^3.5.0",
"codecov.io": "^0.1.6", "codecov.io": "^0.1.6",
"commitizen": "^2.4.6", "commitizen": "^2.4.6",
"cz-conventional-changelog": "^1.1.5", "cz-conventional-changelog": "^1.1.5",
...@@ -43,10 +43,11 @@ ...@@ -43,10 +43,11 @@
"karma-chrome-launcher": "^0.2.2", "karma-chrome-launcher": "^0.2.2",
"karma-coverage": "^0.5.3", "karma-coverage": "^0.5.3",
"karma-mocha": "^0.2.1", "karma-mocha": "^0.2.1",
"karma-mocha-reporter": "^2.2.0",
"karma-ng-html2js-preprocessor": "^0.2.0", "karma-ng-html2js-preprocessor": "^0.2.0",
"karma-phantomjs-launcher": "^1.0.2", "karma-phantomjs-launcher": "^1.0.2",
"karma-sinon": "^1.0.4", "karma-sinon": "^1.0.4",
"mocha": "^2.3.4", "mocha": "^3.1.2",
"phantomjs": "^1.9.19", "phantomjs": "^1.9.19",
"recess": "~1.1.9", "recess": "~1.1.9",
"sinon": "^1.17.2" "sinon": "^1.17.2"
......
This diff is collapsed.
...@@ -199,23 +199,23 @@ ...@@ -199,23 +199,23 @@
expect(el.css('height')).to.equal('12px'); expect(el.css('height')).to.equal('12px');
}); });
it('should have a valid valueToOffset for positive sliders', function() { it('should have a valid valueToPosition for positive sliders', function() {
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.valueToOffset(0)).to.equal(0); expect(helper.slider.valueToPosition(0)).to.equal(0);
expect(helper.slider.valueToOffset(50)).to.equal(500); expect(helper.slider.valueToPosition(50)).to.equal(500);
expect(helper.slider.valueToOffset(100)).to.equal(1000); expect(helper.slider.valueToPosition(100)).to.equal(1000);
}); });
it('should have a valid valueToOffset for negative sliders', function() { it('should have a valid valueToPosition for negative sliders', function() {
helper.scope.slider.options.floor = -100; helper.scope.slider.options.floor = -100;
helper.scope.slider.options.ceil = 0; helper.scope.slider.options.ceil = 0;
helper.scope.slider.value = -50; helper.scope.slider.value = -50;
helper.scope.$digest(); helper.scope.$digest();
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.valueToOffset(0)).to.equal(1000); expect(helper.slider.valueToPosition(0)).to.equal(1000);
expect(helper.slider.valueToOffset(-50)).to.equal(500); expect(helper.slider.valueToPosition(-50)).to.equal(500);
expect(helper.slider.valueToOffset(-100)).to.equal(0); expect(helper.slider.valueToPosition(-100)).to.equal(0);
}); });
it('should have a valid sanitizeValue', function() { it('should have a valid sanitizeValue', function() {
...@@ -228,23 +228,23 @@ ...@@ -228,23 +228,23 @@
expect(helper.slider.sanitizeValue(110)).to.equal(100); expect(helper.slider.sanitizeValue(110)).to.equal(100);
}); });
it('should have a valid offsetToValue for positive sliders', function() { it('should have a valid positionToValue for positive sliders', function() {
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.offsetToValue(0)).to.equal(0); expect(helper.slider.positionToValue(0)).to.equal(0);
expect(helper.slider.offsetToValue(1000)).to.equal(100); expect(helper.slider.positionToValue(1000)).to.equal(100);
expect(helper.slider.offsetToValue(500)).to.equal(50); expect(helper.slider.positionToValue(500)).to.equal(50);
}); });
it('should have a valid offsetToValue for for negative sliders', function() { it('should have a valid positionToValue for for negative sliders', function() {
helper.scope.slider.options.floor = -100; helper.scope.slider.options.floor = -100;
helper.scope.slider.options.ceil = 0; helper.scope.slider.options.ceil = 0;
helper.scope.slider.value = -50; helper.scope.slider.value = -50;
helper.scope.$digest(); helper.scope.$digest();
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.offsetToValue(0)).to.equal(-100); expect(helper.slider.positionToValue(0)).to.equal(-100);
expect(helper.slider.offsetToValue(1000)).to.equal(0); expect(helper.slider.positionToValue(1000)).to.equal(0);
expect(helper.slider.offsetToValue(500)).to.equal(-50); expect(helper.slider.positionToValue(500)).to.equal(-50);
}); });
it('should have a valid getEventXY for horizontal sliders on desktop browsers', function() { it('should have a valid getEventXY for horizontal sliders on desktop browsers', function() {
...@@ -668,42 +668,42 @@ ...@@ -668,42 +668,42 @@
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
}); });
it('should have a valid valueToOffset for positive sliders', function() { it('should have a valid valueToPosition for positive sliders', function() {
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.valueToOffset(0)).to.equal(1000); expect(helper.slider.valueToPosition(0)).to.equal(1000);
expect(helper.slider.valueToOffset(50)).to.equal(500); expect(helper.slider.valueToPosition(50)).to.equal(500);
expect(helper.slider.valueToOffset(100)).to.equal(0); expect(helper.slider.valueToPosition(100)).to.equal(0);
}); });
it('should have a valid valueToOffset for negative sliders', function() { it('should have a valid valueToPosition for negative sliders', function() {
helper.scope.slider.options.floor = -100; helper.scope.slider.options.floor = -100;
helper.scope.slider.options.ceil = 0; helper.scope.slider.options.ceil = 0;
helper.scope.slider.value = -50; helper.scope.slider.value = -50;
helper.scope.$digest(); helper.scope.$digest();
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.valueToOffset(0)).to.equal(0); expect(helper.slider.valueToPosition(0)).to.equal(0);
expect(helper.slider.valueToOffset(-50)).to.equal(500); expect(helper.slider.valueToPosition(-50)).to.equal(500);
expect(helper.slider.valueToOffset(-100)).to.equal(1000); expect(helper.slider.valueToPosition(-100)).to.equal(1000);
}); });
it('should have a valid offsetToValue for positive sliders', function() { it('should have a valid positionToValue for positive sliders', function() {
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.offsetToValue(0)).to.equal(100); expect(helper.slider.positionToValue(0)).to.equal(100);
expect(helper.slider.offsetToValue(1000)).to.equal(0); expect(helper.slider.positionToValue(1000)).to.equal(0);
expect(helper.slider.offsetToValue(500)).to.equal(50); expect(helper.slider.positionToValue(500)).to.equal(50);
}); });
it('should have a valid offsetToValue for for negative sliders', function() { it('should have a valid positionToValue for for negative sliders', function() {
helper.scope.slider.options.floor = -100; helper.scope.slider.options.floor = -100;
helper.scope.slider.options.ceil = 0; helper.scope.slider.options.ceil = 0;
helper.scope.slider.value = -50; helper.scope.slider.value = -50;
helper.scope.$digest(); helper.scope.$digest();
helper.slider.maxPos = 1000; helper.slider.maxPos = 1000;
expect(helper.slider.offsetToValue(0)).to.equal(0); expect(helper.slider.positionToValue(0)).to.equal(0);
expect(helper.slider.offsetToValue(1000)).to.equal(-100); expect(helper.slider.positionToValue(1000)).to.equal(-100);
expect(helper.slider.offsetToValue(500)).to.equal(-50); expect(helper.slider.positionToValue(500)).to.equal(-50);
}); });
}); });
}); });
......
...@@ -123,7 +123,7 @@ ...@@ -123,7 +123,7 @@
}; };
h.getMousePosition = function(value) { h.getMousePosition = function(value) {
return h.slider.valueToOffset(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp; return h.slider.valueToPosition(value) + h.slider.handleHalfDim + h.slider.sliderElem.rzsp;
}; };
h.moveMouseToValue = function(value) { h.moveMouseToValue = function(value) {
......
...@@ -84,9 +84,9 @@ ...@@ -84,9 +84,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -103,9 +103,9 @@ ...@@ -103,9 +103,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -124,8 +124,8 @@ ...@@ -124,8 +124,8 @@
helper.fireMousedown(helper.slider.selBar, 0); helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
...@@ -187,14 +187,14 @@ ...@@ -187,14 +187,14 @@
it('should a working positionTrackingBar', function() { it('should a working positionTrackingBar', function() {
var newMin = 50, var newMin = 50,
newMax = 90, newMax = 90,
minOffset = helper.slider.valueToOffset(newMin), minposition = helper.slider.valueToPosition(newMin),
maxOffset = helper.slider.valueToOffset(newMax); maxposition = helper.slider.valueToPosition(newMax);
helper.slider.positionTrackingBar(newMin, newMax, minOffset, maxOffset); helper.slider.positionTrackingBar(newMin, newMax, minposition, maxposition);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(90); expect(helper.scope.slider.max).to.equal(90);
expect(helper.slider.minH.css('left')).to.equal(minOffset + 'px'); expect(helper.slider.minH.css('left')).to.equal(minposition + 'px');
expect(helper.slider.maxH.css('left')).to.equal(maxOffset + 'px'); expect(helper.slider.maxH.css('left')).to.equal(maxposition + 'px');
}); });
it('should respect minLimit option', function() { it('should respect minLimit option', function() {
...@@ -262,8 +262,8 @@ ...@@ -262,8 +262,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -274,8 +274,8 @@ ...@@ -274,8 +274,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0); var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -284,8 +284,8 @@ ...@@ -284,8 +284,8 @@
it('should handle click and drag on minH and switch min/max if needed', function() { it('should handle click and drag on minH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80, var expectedValue = 80,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.min).to.equal(60);
expect(helper.scope.slider.max).to.equal(80); expect(helper.scope.slider.max).to.equal(80);
...@@ -294,8 +294,8 @@ ...@@ -294,8 +294,8 @@
it('should handle click and drag on maxH and switch min/max if needed', function() { it('should handle click and drag on maxH and switch min/max if needed', function() {
var event = helper.fireMousedown(helper.slider.maxH, 0); var event = helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 20, var expectedValue = 20,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(40); expect(helper.scope.slider.max).to.equal(40);
...@@ -308,9 +308,9 @@ ...@@ -308,9 +308,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -327,9 +327,9 @@ ...@@ -327,9 +327,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -348,8 +348,8 @@ ...@@ -348,8 +348,8 @@
helper.fireMousedown(helper.slider.selBar, 0); helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.maxPos - helper.slider.valueToOffset(moveValue); position = helper.slider.maxPos - helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.min).to.equal(30);
expect(helper.scope.slider.max).to.equal(50); expect(helper.scope.slider.max).to.equal(50);
...@@ -411,14 +411,14 @@ ...@@ -411,14 +411,14 @@
it('should a working positionTrackingBar', function() { it('should a working positionTrackingBar', function() {
var newMin = 50, var newMin = 50,
newMax = 90, newMax = 90,
minOffset = helper.slider.valueToOffset(newMin), minposition = helper.slider.valueToPosition(newMin),
maxOffset = helper.slider.valueToOffset(newMax); maxposition = helper.slider.valueToPosition(newMax);
helper.slider.positionTrackingBar(newMin, newMax, minOffset, maxOffset); helper.slider.positionTrackingBar(newMin, newMax, minposition, maxposition);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(90); expect(helper.scope.slider.max).to.equal(90);
expect(helper.slider.minH.css('left')).to.equal(minOffset + 'px'); expect(helper.slider.minH.css('left')).to.equal(minposition + 'px');
expect(helper.slider.maxH.css('left')).to.equal(maxOffset + 'px'); expect(helper.slider.maxH.css('left')).to.equal(maxposition + 'px');
}); });
}); });
}()); }());
......
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
...@@ -57,8 +57,8 @@ ...@@ -57,8 +57,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0); var event = helper.fireMousedown(helper.slider.maxH, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true; helper.slider.positionTrackingBar.called.should.be.true;
...@@ -69,9 +69,9 @@ ...@@ -69,9 +69,9 @@
sinon.spy(helper.slider, 'callOnStart'); sinon.spy(helper.slider, 'callOnStart');
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(40); expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(60); expect(helper.scope.slider.max).to.equal(60);
...@@ -88,8 +88,8 @@ ...@@ -88,8 +88,8 @@
helper.fireMousedown(helper.slider.selBar, 0); helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
...@@ -207,8 +207,8 @@ ...@@ -207,8 +207,8 @@
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
...@@ -221,8 +221,8 @@ ...@@ -221,8 +221,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0); var event = helper.fireMousedown(helper.slider.maxH, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
helper.slider.positionTrackingBar.called.should.be.true; helper.slider.positionTrackingBar.called.should.be.true;
...@@ -233,9 +233,9 @@ ...@@ -233,9 +233,9 @@
sinon.spy(helper.slider, 'callOnStart'); sinon.spy(helper.slider, 'callOnStart');
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(40); expect(helper.scope.slider.min).to.equal(40);
expect(helper.scope.slider.max).to.equal(60); expect(helper.scope.slider.max).to.equal(60);
...@@ -252,8 +252,8 @@ ...@@ -252,8 +252,8 @@
helper.fireMousedown(helper.slider.selBar, 0); helper.fireMousedown(helper.slider.selBar, 0);
var moveValue = 10, var moveValue = 10,
offset = helper.slider.valueToOffset(moveValue); position = helper.slider.valueToPosition(moveValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
......
...@@ -163,16 +163,16 @@ ...@@ -163,16 +163,16 @@
it('should not modify any value if new range would be smaller than minRange when moving minH', function() { it('should not modify any value if new range would be smaller than minRange when moving minH', function() {
helper.fireMousedown(helper.slider.minH, 0); helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(-offset); helper.fireMousemove(-position);
expect(helper.scope.slider.min).to.equal(45); expect(helper.scope.slider.min).to.equal(45);
}); });
it('should not modify any value if new range would be smaller than minRange when moving maxH', function() { it('should not modify any value if new range would be smaller than minRange when moving maxH', function() {
helper.fireMousedown(helper.slider.maxH, 0); helper.fireMousedown(helper.slider.maxH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.maxPos - helper.getMousePosition(expectedValue); position = helper.slider.maxPos - helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.max).to.equal(55); expect(helper.scope.slider.max).to.equal(55);
}); });
...@@ -193,8 +193,8 @@ ...@@ -193,8 +193,8 @@
it('should not switch min/max when moving minH even if the range is large enough', function() { it('should not switch min/max when moving minH even if the range is large enough', function() {
helper.fireMousedown(helper.slider.minH, 0); helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 80, var expectedValue = 80,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(-offset); helper.fireMousemove(-position);
expect(helper.scope.slider.min).to.equal(45); expect(helper.scope.slider.min).to.equal(45);
expect(helper.scope.slider.max).to.equal(55); expect(helper.scope.slider.max).to.equal(55);
}); });
......
...@@ -56,9 +56,9 @@ ...@@ -56,9 +56,9 @@
helper.scope.$digest(); helper.scope.$digest();
var expectedValue = 30, var expectedValue = 30,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.min).to.equal(30);
expect(helper.scope.slider.max).to.equal(50); expect(helper.scope.slider.max).to.equal(50);
...@@ -69,9 +69,9 @@ ...@@ -69,9 +69,9 @@
helper.scope.$digest(); helper.scope.$digest();
var expectedValue = 70, var expectedValue = 70,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
...@@ -134,9 +134,9 @@ ...@@ -134,9 +134,9 @@
helper.scope.$digest(); helper.scope.$digest();
var expectedValue = 30, var expectedValue = 30,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(30); expect(helper.scope.slider.min).to.equal(30);
expect(helper.scope.slider.max).to.equal(50); expect(helper.scope.slider.max).to.equal(50);
...@@ -147,9 +147,9 @@ ...@@ -147,9 +147,9 @@
helper.scope.$digest(); helper.scope.$digest();
var expectedValue = 70, var expectedValue = 70,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(50); expect(helper.scope.slider.min).to.equal(50);
expect(helper.scope.slider.max).to.equal(70); expect(helper.scope.slider.max).to.equal(70);
......
...@@ -197,9 +197,9 @@ ...@@ -197,9 +197,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -216,9 +216,9 @@ ...@@ -216,9 +216,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -235,9 +235,9 @@ ...@@ -235,9 +235,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -254,9 +254,9 @@ ...@@ -254,9 +254,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -464,9 +464,9 @@ ...@@ -464,9 +464,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -483,9 +483,9 @@ ...@@ -483,9 +483,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.fullBar, offset); var event = helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -502,9 +502,9 @@ ...@@ -502,9 +502,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -521,9 +521,9 @@ ...@@ -521,9 +521,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
......
...@@ -112,8 +112,8 @@ ...@@ -112,8 +112,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0, true); var event = helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -124,8 +124,8 @@ ...@@ -124,8 +124,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0, true); var event = helper.fireMousedown(helper.slider.maxH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -138,8 +138,8 @@ ...@@ -138,8 +138,8 @@
var event = helper.fireMousedown(helper.slider.minH, 0, true); var event = helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 80, var expectedValue = 80,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.min).to.equal(60);
expect(helper.scope.slider.max).to.equal(80); expect(helper.scope.slider.max).to.equal(80);
...@@ -152,8 +152,8 @@ ...@@ -152,8 +152,8 @@
var event = helper.fireMousedown(helper.slider.maxH, 0, true); var event = helper.fireMousedown(helper.slider.maxH, 0, true);
var expectedValue = 20, var expectedValue = 20,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(40); expect(helper.scope.slider.max).to.equal(40);
...@@ -166,9 +166,9 @@ ...@@ -166,9 +166,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -185,9 +185,9 @@ ...@@ -185,9 +185,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -204,9 +204,9 @@ ...@@ -204,9 +204,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.selBar, offset, true); var event = helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -223,9 +223,9 @@ ...@@ -223,9 +223,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.selBar, offset, true); var event = helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -348,8 +348,8 @@ ...@@ -348,8 +348,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0, true); var event = helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -360,8 +360,8 @@ ...@@ -360,8 +360,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.maxH, 0, true); var event = helper.fireMousedown(helper.slider.maxH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -374,8 +374,8 @@ ...@@ -374,8 +374,8 @@
var event = helper.fireMousedown(helper.slider.minH, 0, true); var event = helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 80, var expectedValue = 80,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(60); expect(helper.scope.slider.min).to.equal(60);
expect(helper.scope.slider.max).to.equal(80); expect(helper.scope.slider.max).to.equal(80);
...@@ -388,8 +388,8 @@ ...@@ -388,8 +388,8 @@
var event = helper.fireMousedown(helper.slider.maxH, 0, true); var event = helper.fireMousedown(helper.slider.maxH, 0, true);
var expectedValue = 20, var expectedValue = 20,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.min).to.equal(20); expect(helper.scope.slider.min).to.equal(20);
expect(helper.scope.slider.max).to.equal(40); expect(helper.scope.slider.max).to.equal(40);
...@@ -402,9 +402,9 @@ ...@@ -402,9 +402,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -421,9 +421,9 @@ ...@@ -421,9 +421,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
...@@ -440,9 +440,9 @@ ...@@ -440,9 +440,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.selBar, offset, true); var event = helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.min).to.equal(expectedValue); expect(helper.scope.slider.min).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -459,9 +459,9 @@ ...@@ -459,9 +459,9 @@
sinon.spy(helper.slider, 'focusElement'); sinon.spy(helper.slider, 'focusElement');
var expectedValue = 90, var expectedValue = 90,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.selBar, offset, true); var event = helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.max).to.equal(expectedValue); expect(helper.scope.slider.max).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('highValue'); expect(helper.slider.tracking).to.equal('highValue');
......
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -136,9 +136,9 @@ ...@@ -136,9 +136,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -153,9 +153,9 @@ ...@@ -153,9 +153,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -173,9 +173,9 @@ ...@@ -173,9 +173,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.ticks, offset); helper.fireMousedown(helper.slider.ticks, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -193,9 +193,9 @@ ...@@ -193,9 +193,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.ticks, offset); helper.fireMousedown(helper.slider.ticks, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -280,8 +280,8 @@ ...@@ -280,8 +280,8 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var event = helper.fireMousedown(helper.slider.minH, 0); var event = helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50, var expectedValue = 50,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousemove(offset); helper.fireMousemove(position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -340,9 +340,9 @@ ...@@ -340,9 +340,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.fullBar, offset); helper.fireMousedown(helper.slider.fullBar, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -357,9 +357,9 @@ ...@@ -357,9 +357,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
var event = helper.fireMousedown(helper.slider.selBar, offset); var event = helper.fireMousedown(helper.slider.selBar, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -377,9 +377,9 @@ ...@@ -377,9 +377,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.ticks, offset); helper.fireMousedown(helper.slider.ticks, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -397,9 +397,9 @@ ...@@ -397,9 +397,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.getMousePosition(expectedValue); position = helper.getMousePosition(expectedValue);
helper.fireMousedown(helper.slider.ticks, offset); helper.fireMousedown(helper.slider.ticks, position);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
......
...@@ -77,9 +77,9 @@ ...@@ -77,9 +77,9 @@
helper.fireMousedown(helper.slider.minH, 0, true); helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -139,9 +139,9 @@ ...@@ -139,9 +139,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -156,9 +156,9 @@ ...@@ -156,9 +156,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.selBar, offset, true); helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -176,9 +176,9 @@ ...@@ -176,9 +176,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.ticks, offset, true); helper.fireMousedown(helper.slider.ticks, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -196,9 +196,9 @@ ...@@ -196,9 +196,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.ticks, offset, true); helper.fireMousedown(helper.slider.ticks, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -285,9 +285,9 @@ ...@@ -285,9 +285,9 @@
helper.fireMousedown(helper.slider.minH, 0, true); helper.fireMousedown(helper.slider.minH, 0, true);
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousemove(offset, true); helper.fireMousemove(position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
helper.slider.positionTrackingHandle.called.should.be.true; helper.slider.positionTrackingHandle.called.should.be.true;
helper.slider.callOnChange.called.should.be.true; helper.slider.callOnChange.called.should.be.true;
...@@ -347,9 +347,9 @@ ...@@ -347,9 +347,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 50, var expectedValue = 50,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
var event = helper.fireMousedown(helper.slider.fullBar, offset, true); var event = helper.fireMousedown(helper.slider.fullBar, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -364,9 +364,9 @@ ...@@ -364,9 +364,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 12, var expectedValue = 12,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.selBar, offset, true); helper.fireMousedown(helper.slider.selBar, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -384,9 +384,9 @@ ...@@ -384,9 +384,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.ticks, offset, true); helper.fireMousedown(helper.slider.ticks, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
...@@ -404,9 +404,9 @@ ...@@ -404,9 +404,9 @@
sinon.spy(helper.slider, 'callOnChange'); sinon.spy(helper.slider, 'callOnChange');
var expectedValue = 10, var expectedValue = 10,
offset = helper.slider.sliderElem.rzsp - helper.slider.valueToOffset(expectedValue) - helper.slider.handleHalfDim; position = helper.slider.sliderElem.rzsp - helper.slider.valueToPosition(expectedValue) - helper.slider.handleHalfDim;
helper.fireMousedown(helper.slider.ticks, offset, true); helper.fireMousedown(helper.slider.ticks, position, true);
expect(helper.scope.slider.value).to.equal(expectedValue); expect(helper.scope.slider.value).to.equal(expectedValue);
expect(helper.slider.tracking).to.equal('lowValue'); expect(helper.slider.tracking).to.equal('lowValue');
......
...@@ -223,7 +223,7 @@ ...@@ -223,7 +223,7 @@
{value: 'C', 'foo': 'barC'} {value: 'C', 'foo': 'barC'}
]; ];
helper.scope.slider.options.translate = function(value, sliderId, label) { helper.scope.slider.options.translate = function(value, sliderId, label) {
return 'value: '+ value return 'value: ' + value
}; };
helper.scope.$digest(); helper.scope.$digest();
expect(helper.slider.options.step).to.equal(1); expect(helper.slider.options.step).to.equal(1);
...@@ -312,7 +312,7 @@ ...@@ -312,7 +312,7 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; var expectedDimension = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px');
expect(helper.slider.selBar.css('left')).to.equal('0px'); expect(helper.slider.selBar.css('left')).to.equal('0px');
}); });
...@@ -327,9 +327,11 @@ ...@@ -327,9 +327,11 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(8) + helper.slider.handleHalfDim, var expectedDimension = Math.floor(helper.slider.valueToPosition(8) + helper.slider.handleHalfDim),
expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(actualDimension).to.equal(expectedDimension);
var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -343,8 +345,8 @@ ...@@ -343,8 +345,8 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(5), var expectedDimension = helper.slider.valueToPosition(5),
expectedPosition = helper.slider.valueToOffset(10) + helper.slider.handleHalfDim; expectedPosition = helper.slider.valueToPosition(10) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px');
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -359,9 +361,11 @@ ...@@ -359,9 +361,11 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(7), var expectedDimension = Math.floor(helper.slider.valueToPosition(7)),
expectedPosition = helper.slider.valueToOffset(3) + helper.slider.handleHalfDim; actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(actualDimension).to.equal(expectedDimension);
var expectedPosition = helper.slider.valueToPosition(3) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -463,9 +467,12 @@ ...@@ -463,9 +467,12 @@
} }
}; };
helper.createRangeSlider(sliderConf); helper.createRangeSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(6),
expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; var expectedDimension = Math.floor(helper.slider.valueToPosition(6)),
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(actualDimension).to.equal(expectedDimension);
var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -1073,10 +1080,10 @@ ...@@ -1073,10 +1080,10 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = Math.floor(helper.slider.valueToOffset(8) + helper.slider.handleHalfDim), var expectedDimension = Math.floor(helper.slider.valueToPosition(8) + helper.slider.handleHalfDim),
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width); actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(actualDimension).to.equal(expectedDimension); expect(actualDimension).to.equal(expectedDimension);
expect(helper.slider.selBar.css('left')).to.equal(helper.slider.valueToOffset(2) + helper.slider.handleHalfDim + 'px'); expect(helper.slider.selBar.css('left')).to.equal(helper.slider.valueToPosition(2) + helper.slider.handleHalfDim + 'px');
}); });
it('should set the correct dimension/position for selection bar for single slider with showSelectionBarEnd=true', function() { it('should set the correct dimension/position for selection bar for single slider with showSelectionBarEnd=true', function() {
...@@ -1090,8 +1097,9 @@ ...@@ -1090,8 +1097,9 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; var expectedDimension = Math.floor(helper.slider.valueToPosition(2) + helper.slider.handleHalfDim),
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(actualDimension).to.equal(expectedDimension);
expect(helper.slider.selBar.css('left')).to.equal('0px'); expect(helper.slider.selBar.css('left')).to.equal('0px');
}); });
...@@ -1106,8 +1114,8 @@ ...@@ -1106,8 +1114,8 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(15), var expectedDimension = helper.slider.valueToPosition(15),
expectedPosition = helper.slider.valueToOffset(15) + helper.slider.handleHalfDim; expectedPosition = helper.slider.valueToPosition(15) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px');
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -1123,9 +1131,9 @@ ...@@ -1123,9 +1131,9 @@
} }
}; };
helper.createSlider(sliderConf); helper.createSlider(sliderConf);
var expectedDimension = Math.floor(helper.slider.valueToOffset(13)), var expectedDimension = Math.floor(helper.slider.valueToPosition(13)),
actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width), actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width),
expectedPosition = helper.slider.valueToOffset(10) + helper.slider.handleHalfDim; expectedPosition = helper.slider.valueToPosition(10) + helper.slider.handleHalfDim;
expect(actualDimension).to.equal(expectedDimension); expect(actualDimension).to.equal(expectedDimension);
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
...@@ -1164,9 +1172,12 @@ ...@@ -1164,9 +1172,12 @@
rightToLeft: true rightToLeft: true
}; };
helper.createRangeSlider(sliderConf); helper.createRangeSlider(sliderConf);
var expectedDimension = helper.slider.valueToOffset(6),
expectedPosition = helper.slider.valueToOffset(2) + helper.slider.handleHalfDim; var expectedDimension = Math.floor(helper.slider.valueToPosition(6)),
expect(helper.slider.selBar.css('width')).to.equal(expectedDimension + 'px'); actualDimension = Math.floor(helper.slider.selBar[0].getBoundingClientRect().width);
expect(actualDimension).to.equal(expectedDimension);
var expectedPosition = helper.slider.valueToPosition(2) + helper.slider.handleHalfDim;
expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(helper.slider.selBar.css('left')).to.equal(expectedPosition + 'px');
}); });
......
(function() {
"use strict";
describe('Scale test - ', function() {
var helper,
RzSliderOptions,
$rootScope,
$timeout;
beforeEach(module('test-helper'));
beforeEach(inject(function(TestHelper, _RzSliderOptions_, _$rootScope_, _$timeout_) {
helper = TestHelper;
RzSliderOptions = _RzSliderOptions_;
$rootScope = _$rootScope_;
$timeout = _$timeout_;
}));
afterEach(function() {
helper.clean();
});
describe('Linear scale - ', function() {
beforeEach(function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10
}
};
helper.createSlider(sliderConf);
});
it('should have a correct linearValueToPosition', function() {
var actual = helper.slider.linearValueToPosition(0, 0, 50);
expect(actual).to.equal(0);
actual = helper.slider.linearValueToPosition(25, 0, 50);
expect(actual.toFixed(2)).to.equal('0.50');
actual = helper.slider.linearValueToPosition(50, 0, 50);
expect(actual).to.equal(1);
});
it('should have a correct linearPositionToValue', function() {
var actual = helper.slider.linearPositionToValue(0, 0, 50);
expect(actual).to.equal(0);
actual = helper.slider.linearPositionToValue(0.5, 0, 50);
expect(actual).to.equal(25);
actual = Math.round(helper.slider.linearPositionToValue(1, 0, 50));
expect(actual).to.equal(50);
});
});
describe('Logarithm scale - ', function() {
beforeEach(function() {
var sliderConf = {
value: 10,
options: {
floor: 1,
ceil: 100,
step: 10,
logScale: true
}
};
helper.createSlider(sliderConf);
});
it('should throw an error if floor is 0', function() {
var testFn = function() {
helper.scope.slider.options.floor = 0;
helper.scope.$digest();
};
expect(testFn).to.throw("Can't use floor=0 with logarithmic scale");
});
it('should have a correct logValueToPosition', function() {
var actual = helper.slider.logValueToPosition(1, 1, 50);
expect(actual).to.equal(0);
actual = helper.slider.logValueToPosition(25, 1, 50);
expect(actual.toFixed(2)).to.equal('0.82');
actual = helper.slider.logValueToPosition(50, 1, 50);
expect(actual).to.equal(1);
});
it('should have a correct logPositionToValue', function() {
var actual = helper.slider.logPositionToValue(0, 1, 50);
expect(actual).to.equal(1);
actual = helper.slider.logPositionToValue(0.5, 1, 50);
expect(actual.toFixed(2)).to.equal('7.07');
actual = Math.round(helper.slider.logPositionToValue(1, 1, 50));
expect(actual).to.equal(50);
});
it('should handle click and drag on minH correctly', function () {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
position = helper.getMousePosition(expectedValue);
helper.fireMousemove(position);
expect(helper.scope.slider.value).to.equal(expectedValue + 1); // + 1 because we start at 1
});
});
describe('Custom scale (here a x^2 scale)- ', function() {
beforeEach(function() {
var sliderConf = {
value: 50,
options: {
floor: 0,
ceil: 100,
step: 10,
customValueToPosition: function(val, minVal, maxVal) {
val = Math.sqrt(val);
minVal = Math.sqrt(minVal);
maxVal = Math.sqrt(maxVal);
var range = maxVal - minVal;
return (val - minVal) / range;
},
customPositionToValue: function(percent, minVal, maxVal) {
minVal = Math.sqrt(minVal);
maxVal = Math.sqrt(maxVal);
var value = percent * (maxVal - minVal) + minVal;
return Math.pow(value, 2);
}
}
};
helper.createSlider(sliderConf);
});
-
it('should have a correct valueToPosition', function() {
var actual = helper.slider.valueToPosition(0);
expect(actual).to.equal(0);
actual = helper.slider.valueToPosition(25);
expect(actual).to.equal(helper.slider.maxPos / 2);
actual = helper.slider.valueToPosition(100);
expect(actual).to.equal(helper.slider.maxPos);
});
it('should have a correct positionToValue', function() {
var actual = helper.slider.positionToValue(0);
expect(actual).to.equal(0);
actual = helper.slider.positionToValue(helper.slider.maxPos / 2);
expect(actual).to.equal(25);
actual = Math.round(helper.slider.positionToValue(helper.slider.maxPos));
expect(actual).to.equal(100);
});
it('should handle click and drag on minH correctly', function () {
helper.fireMousedown(helper.slider.minH, 0);
var expectedValue = 50,
position = helper.getMousePosition(expectedValue);
helper.fireMousemove(position);
expect(helper.scope.slider.value).to.equal(expectedValue);
});
});
});
}());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment