Skip to content

Commit 581cfc6

Browse files
author
Valentin Hervieu
committed
feat(selectionBar): Add a showSelectionBarFromValue
1 parent 7e9c22c commit 581cfc6

File tree

5 files changed

+104
-19
lines changed

5 files changed

+104
-19
lines changed

demo/demo.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
5858
}
5959
};
6060

61+
//Slider with selection bar from value
62+
$scope.slider_visible_bar_from_value = {
63+
value: 10,
64+
options: {
65+
floor: -100,
66+
ceil: 100,
67+
step: 10,
68+
showSelectionBarFromValue: 0
69+
}
70+
};
71+
6172
//Slider with selection bar
6273
$scope.color_slider_bar = {
6374
value: 12,

demo/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ <h2>Slider with visible selection bar at the end</h2>
7070
></rzslider>
7171
</article>
7272

73+
<article>
74+
<h2>Slider with visible selection bar from a value</h2>
75+
<rzslider
76+
rz-slider-model="slider_visible_bar_from_value.value"
77+
rz-slider-options="slider_visible_bar_from_value.options"
78+
></rzslider>
79+
</article>
80+
7381
<article>
7482
<h2>Slider with dynamic selection bar colors</h2>
7583
<rzslider

dist/rzslider.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v2.6.0 -
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-01-31 */
4+
2016-02-03 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
(function(root, factory) {
@@ -39,6 +39,7 @@
3939
draggableRangeOnly: false,
4040
showSelectionBar: false,
4141
showSelectionBarEnd: false,
42+
showSelectionBarFromValue: null,
4243
hideLimitLabels: false,
4344
readOnly: false,
4445
disabled: false,
@@ -406,7 +407,8 @@
406407
this.options.showTicks = this.options.showTicks || this.options.showTicksValues;
407408
this.scope.showTicks = this.options.showTicks; //scope is used in the template
408409

409-
this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd;
410+
this.options.showSelectionBar = this.options.showSelectionBar || this.options.showSelectionBarEnd
411+
|| this.options.showSelectionBarFromValue !== null;
410412

411413
if (this.options.stepsArray) {
412414
this.options.floor = 0;
@@ -762,8 +764,21 @@
762764
},
763765

764766
isTickSelected: function(value) {
765-
if (!this.range && this.options.showSelectionBar && value <= this.scope.rzSliderModel)
766-
return true;
767+
if (!this.range) {
768+
if (this.options.showSelectionBarFromValue !== null) {
769+
var center = this.options.showSelectionBarFromValue;
770+
if (this.scope.rzSliderModel > center && value >= center && value <= this.scope.rzSliderModel)
771+
return true;
772+
else if (this.scope.rzSliderModel < center && value <= center && value >= this.scope.rzSliderModel)
773+
return true;
774+
}
775+
else if (this.options.showSelectionBarEnd) {
776+
if (value >= this.scope.rzSliderModel)
777+
return true;
778+
}
779+
else if (this.options.showSelectionBar && value <= this.scope.rzSliderModel)
780+
return true;
781+
}
767782
if (this.range && value >= this.scope.rzSliderModel && value <= this.scope.rzSliderHigh)
768783
return true;
769784
return false;
@@ -932,13 +947,31 @@
932947
updateSelectionBar: function() {
933948
var position = 0,
934949
dimension = 0;
935-
if (this.range || !this.options.showSelectionBarEnd) {
936-
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim
937-
position = this.range ? this.minH.rzsp + this.handleHalfDim : 0;
938-
} else {
939-
dimension = Math.abs(this.maxPos - this.minH.rzsp) + this.handleHalfDim
950+
if(this.range) {
951+
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim;
940952
position = this.minH.rzsp + this.handleHalfDim;
941953
}
954+
else {
955+
if (this.options.showSelectionBarFromValue !== null) {
956+
var center = this.options.showSelectionBarFromValue,
957+
centerPosition = this.valueToOffset(center);
958+
if (this.scope.rzSliderModel > center) {
959+
dimension = this.minH.rzsp - centerPosition;
960+
position = centerPosition + this.handleHalfDim;
961+
}
962+
else {
963+
dimension = centerPosition - this.minH.rzsp;
964+
position = this.minH.rzsp + this.handleHalfDim;
965+
}
966+
}
967+
else if (this.options.showSelectionBarEnd) {
968+
dimension = Math.abs(this.maxPos - this.minH.rzsp) + this.handleHalfDim;
969+
position = this.minH.rzsp + this.handleHalfDim;
970+
} else {
971+
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim;
972+
position = 0;
973+
}
974+
}
942975
this.setDimension(this.selBar, dimension);
943976
this.setPosition(this.selBar, position);
944977
if (this.options.getSelectionBarColor) {

0 commit comments

Comments
 (0)