Skip to content

feat(pointerColor): Adding feature for dynamic pointer color based on… #253

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 1 commit into from
Feb 7, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ The default options are:
ticksValuesTooltip: null,
vertical: false,
selectionBarColor: null,
getPointerColor: null,
keyboardSupport: true,
scale: 1,
enforceStep: true,
Expand Down Expand Up @@ -249,6 +250,8 @@ $scope.slider = {

**getSelectionBarColor** - _Function(value) or Function(minVal, maxVal) (defaults to null)_: Function that returns the current color of the selection bar. If the returned color depends on a model value (either `rzScopeModel`or `'rzSliderHigh`), you should use the argument passed to the function. Indeed, when the function is called, there is no certainty that the model has already been updated.

**getPointerColor** - _Function(value, pointerType) (defaults to null)_: Function that returns the current color of a pointer. To handle range slider pointer independently, you should evaluate pointerType within the given function where "min" stands for `rzScopeModel` and "max" for `rzScopeHigh` values. Indeed, when the function is called, there is no certainty that the model has already been updated.

**hideLimitLabels** - _Boolean (defaults to false)_: Set to true to hide min / max labels

**readOnly** - _Boolean (defaults to false)_: Set to true to make the slider read-only.
Expand Down
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 - v2.7.1 -
(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-02-06 */
2016-02-07 */
rzslider {
position: relative;
display: inline-block;
Expand Down
30 changes: 28 additions & 2 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v2.7.1 -
(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-02-06 */
2016-02-07 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -50,6 +50,7 @@
ticksValuesTooltip: null,
vertical: false,
selectionBarColor: null,
getPointerColor: null,
keyboardSupport: true,
scale: 1,
enforceStep: true,
Expand Down Expand Up @@ -889,6 +890,13 @@
);
this.setPosition(this.minLab, pos);

if (this.options.getPointerColor) {
var pointercolor = this.getPointerColor('min');
this.scope.minPointerStyle = {
backgroundColor: pointercolor
};
}

this.shFloorCeil();
},

Expand All @@ -904,6 +912,13 @@
var pos = Math.min(newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim, this.barDimension - this.maxLab.rzsd);
this.setPosition(this.maxLab, pos);

if (this.options.getPointerColor) {
var pointercolor = this.getPointerColor('max');
this.scope.maxPointerStyle = {
backgroundColor: pointercolor
};
}

this.shFloorCeil();
},

Expand Down Expand Up @@ -1001,6 +1016,17 @@
return this.options.getSelectionBarColor(this.scope.rzSliderModel);
},

/**
* Wrapper around the getPointerColor of the user to pass to
* correct parameters
*/
getPointerColor: function(pointerType) {
if ( pointerType === 'max' ) {
return this.options.getPointerColor(this.scope.rzSliderHigh, pointerType);
}
return this.options.getPointerColor(this.scope.rzSliderModel, pointerType);
},

/**
* Update combined label position and value
*
Expand Down Expand Up @@ -1697,7 +1723,7 @@
'use strict';

$templateCache.put('rzSliderTpl.html',
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\" ng-style=barStyle></span></span> <span class=rz-pointer></span> <span class=rz-pointer></span> <span class=\"rz-bubble rz-limit\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=tick ng-class=\"{selected: t.selected}\" ng-style=t.style ng-attr-uib-tooltip=\"{{ t.tooltip }}\" ng-attr-tooltip-placement={{t.tooltipPlacement}} ng-attr-tooltip-append-to-body=\"{{ t.tooltip ? true : undefined}}\"><span ng-if=\"t.value != null\" class=tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span></li></ul>"
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\" ng-style=barStyle></span></span> <span class=\"rz-pointer rz-pointer-min\" ng-style=minPointerStyle></span> <span class=\"rz-pointer rz-pointer-max\" ng-style=maxPointerStyle></span> <span class=\"rz-bubble rz-limit\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=tick ng-class=\"{selected: t.selected}\" ng-style=t.style ng-attr-uib-tooltip=\"{{ t.tooltip }}\" ng-attr-tooltip-placement={{t.tooltipPlacement}} ng-attr-tooltip-append-to-body=\"{{ t.tooltip ? true : undefined}}\"><span ng-if=\"t.value != null\" class=tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span></li></ul>"
);

}]);
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.

4 changes: 2 additions & 2 deletions src/rzSliderTpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<span class="rz-bar-wrapper">
<span class="rz-bar rz-selection" ng-style="barStyle"></span>
</span> <!-- // 1 Highlight between two handles -->
<span class="rz-pointer"></span> <!-- // 2 Left slider handle -->
<span class="rz-pointer"></span> <!-- // 3 Right slider handle -->
<span class="rz-pointer rz-pointer-min" ng-style=minPointerStyle></span> <!-- // 2 Left slider handle -->
<span class="rz-pointer rz-pointer-max" ng-style=maxPointerStyle></span> <!-- // 3 Right slider handle -->
<span class="rz-bubble rz-limit"></span> <!-- // 4 Floor label -->
<span class="rz-bubble rz-limit"></span> <!-- // 5 Ceiling label -->
<span class="rz-bubble"></span> <!-- // 6 Label above left slider handle -->
Expand Down
26 changes: 26 additions & 0 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
ticksValuesTooltip: null,
vertical: false,
selectionBarColor: null,
getPointerColor: null,
keyboardSupport: true,
scale: 1,
enforceStep: true,
Expand Down Expand Up @@ -893,6 +894,13 @@
);
this.setPosition(this.minLab, pos);

if (this.options.getPointerColor) {
var pointercolor = this.getPointerColor('min');
this.scope.minPointerStyle = {
backgroundColor: pointercolor
};
}

this.shFloorCeil();
},

Expand All @@ -908,6 +916,13 @@
var pos = Math.min(newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim, this.barDimension - this.maxLab.rzsd);
this.setPosition(this.maxLab, pos);

if (this.options.getPointerColor) {
var pointercolor = this.getPointerColor('max');
this.scope.maxPointerStyle = {
backgroundColor: pointercolor
};
}

this.shFloorCeil();
},

Expand Down Expand Up @@ -1005,6 +1020,17 @@
return this.options.getSelectionBarColor(this.scope.rzSliderModel);
},

/**
* Wrapper around the getPointerColor of the user to pass to
* correct parameters
*/
getPointerColor: function(pointerType) {
if ( pointerType === 'max' ) {
return this.options.getPointerColor(this.scope.rzSliderHigh, pointerType);
}
return this.options.getPointerColor(this.scope.rzSliderModel, pointerType);
},

/**
* Update combined label position and value
*
Expand Down
112 changes: 112 additions & 0 deletions tests/spec/rz-slider-service-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,118 @@ describe('rzslider - ', function() {
$timeout.flush();
sliderConf.options.onEnd.calledWith('test').should.be.true;
});

it('should set the correct background-color on pointer for single slider', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 10,
showSelectionBar: true,
getPointerColor: function(v) {
if (v < 5) return 'red';
return 'green';
}
}
};
createSlider(sliderConf);
var minHChild = angular.element(slider.minH[0]);
expect(minHChild.css('background-color')).to.equal('green');

scope.slider.value = 2;
scope.$digest();
expect(minHChild.css('background-color')).to.equal('red');
});

it('should set the correct background-color on pointer for range slider (simple rule)', function() {
var sliderConf = {
min: 2,
max: 8,
options: {
floor: 0,
ceil: 10,
getPointerColor: function(v) {
if (v < 5) return 'red';
return 'green';
}
}
};
createRangeSlider(sliderConf);
var minHChild = angular.element(slider.minH[0]),
maxHChild = angular.element(slider.maxH[0]);
expect(minHChild.css('background-color')).to.equal('red');
expect(maxHChild.css('background-color')).to.equal('green');

scope.slider.min = 6;
scope.slider.max = 7;
scope.$digest();
expect(minHChild.css('background-color')).to.equal('green');
expect(maxHChild.css('background-color')).to.equal('green');
});

it('should set the correct background-color on pointer for range slider (min/high independent rule 1)', function() {
var sliderConf = {
min: 2,
max: 8,
options: {
floor: 0,
ceil: 10,
getPointerColor: function(v, type) {
if ( type == 'min' ) {
if (v < 5) return 'red';
return 'green';
}

if ( type == 'max' ) {
if (v < 5) return 'blue';
return 'orange';
}
}
}
};
createRangeSlider(sliderConf);
var minHChild = angular.element(slider.minH[0]),
maxHChild = angular.element(slider.maxH[0]);
expect(minHChild.css('background-color')).to.equal('red');
expect(maxHChild.css('background-color')).to.equal('orange');

scope.slider.min = 6;
scope.$digest();
expect(minHChild.css('background-color')).to.equal('green');
});

it('should set the correct background-color on pointer for range slider (min/high independent rule 2)', function() {
var sliderConf = {
min: 2,
max: 8,
options: {
floor: 0,
ceil: 10,
getPointerColor: function(v, type) {
if ( type == 'min' ) {
if (v < 5) return 'red';
return 'green';
}

if ( type == 'max' ) {
if (v < 5) return 'blue';
return 'orange';
}
}
}
};
createRangeSlider(sliderConf);
var minHChild = angular.element(slider.minH[0]),
maxHChild = angular.element(slider.maxH[0]);
expect(minHChild.css('background-color')).to.equal('red');
expect(maxHChild.css('background-color')).to.equal('orange');

scope.slider.max = 3;
scope.$digest();
expect(minHChild.css('background-color')).to.equal('red');
expect(maxHChild.css('background-color')).to.equal('blue');

});
});
});

Expand Down