Skip to content

Commit 5808e4c

Browse files
committed
feat: Add selectionBarGradient option to customize the selection bar
Add selectionBarGradient option which create a linear gradient for the selection bar. The option accepts an object that contains `from` and `to` properties which are colors describing the gradient
1 parent 219df14 commit 5808e4c

File tree

9 files changed

+69
-11
lines changed

9 files changed

+69
-11
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ The default options are:
242242
customTemplateScope: null,
243243
logScale: false,
244244
customValueToPosition: null,
245-
customPositionToValue: null
245+
customPositionToValue: null,
246+
selectionBarGradient: null
246247
}
247248
````
248249

@@ -395,6 +396,7 @@ For custom scales:
395396

396397
**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.
397398

399+
**selectionBarGradient** - _Object (default to null)_: Use to display the selection bar as a gradient. The given object must contain `from` and `to` properties which are colors.
398400

399401
## Change default options
400402
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:

demo/demo.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $uibModal) {
9494
}
9595
};
9696

97+
//Slider with selection bar gradient
98+
$scope.gradient_slider_bar = {
99+
minValue: 0,
100+
maxValue: 33,
101+
options: {
102+
showSelectionBar: true,
103+
selectionBarGradient: {
104+
from: 'white',
105+
to: '#0db9f0'
106+
}
107+
}
108+
};
109+
97110
//Slider with selection bar color
98111
$scope.color_slider_bar = {
99112
value: 12,
@@ -421,7 +434,11 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $uibModal) {
421434
options: {
422435
floor: 0,
423436
ceil: 100,
424-
vertical: true
437+
vertical: true,
438+
selectionBarGradient: {
439+
from: 'white',
440+
to: '#0db9f0'
441+
}
425442
}
426443
};
427444
$scope.verticalSlider3 = {

demo/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ <h2>Slider with visible selection bar from a value</h2>
9595
></rzslider>
9696
</article>
9797

98+
<article>
99+
<h2>Slider with selection bar gradient</h2>
100+
<rzslider
101+
rz-slider-model="gradient_slider_bar.minValue"
102+
rz-slider-high="gradient_slider_bar.maxValue"
103+
rz-slider-options="gradient_slider_bar.options"
104+
></rzslider>
105+
</article>
106+
98107
<article>
99108
<h2>Slider with dynamic selection bar colors</h2>
100109
<rzslider

dist/rzslider.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.7 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-09 */
4+
2016-12-07 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

dist/rzslider.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.7 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-09 */
4+
2016-12-07 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -80,7 +80,8 @@
8080
customTemplateScope: null,
8181
logScale: false,
8282
customValueToPosition: null,
83-
customPositionToValue: null
83+
customPositionToValue: null,
84+
selectionBarGradient: null
8485
};
8586
var globalOptions = {};
8687

@@ -1268,6 +1269,20 @@
12681269
this.scope.barStyle = {
12691270
backgroundColor: color
12701271
};
1272+
} else if (this.options.selectionBarGradient) {
1273+
var offset = this.options.showSelectionBarFromValue !== null ? this.valueToPosition(this.options.showSelectionBarFromValue) : 0,
1274+
reversed = offset - position > 0 ^ isSelectionBarFromRight,
1275+
direction = this.options.vertical ? 'top' : (reversed ? 'left' : 'right');
1276+
this.scope.barStyle = {
1277+
backgroundImage: 'linear-gradient(to ' + direction + ', ' + this.options.selectionBarGradient.from + ' 0%,' + this.options.selectionBarGradient.to + ' 100%)'
1278+
};
1279+
if (this.options.vertical) {
1280+
this.scope.barStyle.backgroundPosition = 'center ' + (offset + dimension + position + (reversed ? this.handleHalfDim : 0)) + 'px';
1281+
this.scope.barStyle.backgroundSize = '100% ' + (this.barDimension - this.handleHalfDim) + 'px';
1282+
} else {
1283+
this.scope.barStyle.backgroundPosition = (offset - position + (reversed ? this.handleHalfDim : 0)) + 'px center';
1284+
this.scope.barStyle.backgroundSize = (this.barDimension - this.handleHalfDim) + 'px 100%';
1285+
}
12711286
}
12721287
},
12731288

dist/rzslider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.8.7 -
22
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
33
https://github.com/angular-slider/angularjs-slider -
4-
2016-11-09 */
4+
2016-12-07 */
55
.rzslider {
66
position: relative;
77
display: inline-block;

src/rzslider.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
customTemplateScope: null,
8585
logScale: false,
8686
customValueToPosition: null,
87-
customPositionToValue: null
87+
customPositionToValue: null,
88+
selectionBarGradient: null
8889
};
8990
var globalOptions = {};
9091

@@ -1272,6 +1273,20 @@
12721273
this.scope.barStyle = {
12731274
backgroundColor: color
12741275
};
1276+
} else if (this.options.selectionBarGradient) {
1277+
var offset = this.options.showSelectionBarFromValue !== null ? this.valueToPosition(this.options.showSelectionBarFromValue) : 0,
1278+
reversed = offset - position > 0 ^ isSelectionBarFromRight,
1279+
direction = this.options.vertical ? 'top' : (reversed ? 'left' : 'right');
1280+
this.scope.barStyle = {
1281+
backgroundImage: 'linear-gradient(to ' + direction + ', ' + this.options.selectionBarGradient.from + ' 0%,' + this.options.selectionBarGradient.to + ' 100%)'
1282+
};
1283+
if (this.options.vertical) {
1284+
this.scope.barStyle.backgroundPosition = 'center ' + (offset + dimension + position + (reversed ? this.handleHalfDim : 0)) + 'px';
1285+
this.scope.barStyle.backgroundSize = '100% ' + (this.barDimension - this.handleHalfDim) + 'px';
1286+
} else {
1287+
this.scope.barStyle.backgroundPosition = (offset - position + (reversed ? this.handleHalfDim : 0)) + 'px center';
1288+
this.scope.barStyle.backgroundSize = (this.barDimension - this.handleHalfDim) + 'px 100%';
1289+
}
12751290
}
12761291
},
12771292

0 commit comments

Comments
 (0)