Skip to content

Feature/restricted range #638

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 4 commits into from
Jun 29, 2018
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 @@ -233,6 +233,7 @@ The default options are:
precision: 0,
minLimit: null,
maxLimit: null,
restrictedRange: null,
minRange: null,
maxRange: null,
pushRange: false,
Expand Down Expand Up @@ -300,6 +301,8 @@ The default options are:

**maxLimit** - _Number (defaults to null)_: The maximum value authorized on the slider.

**restrictedRange** - _Object (defaults to null)_: Has two _Number_ properties, _from_ and _to_ that determine the bounds of an area that is not authorized for values. _Applies to range slider only._

**minRange** - _Number (defaults to null)_: The minimum range authorized on the slider. _Applies to range slider only._

**maxRange** - _Number (defaults to null)_: The maximum range authorized on the slider. _Applies to range slider only._
Expand Down
14 changes: 14 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $uibModal) {
},
}

$scope.restrictedRangeSlider = {
minValue: 10,
maxValue: 90,
options: {
restrictedRange: {
from: 30,
to: 70,
},
floor: 0,
ceil: 100,
step: 1,
},
}

//Range slider with minRange and maxRange config
$scope.minMaxRangeSlider = {
minValue: 40,
Expand Down
9 changes: 9 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ <h2>Range slider with min limit set to 10 and max limit set to 90 </h2>
></rzslider>
</article>

<article>
<h2>Range slider with restricted area from 30 to 70</h2>
<rzslider
data-rz-slider-model="restrictedRangeSlider.minValue"
data-rz-slider-high="restrictedRangeSlider.maxValue"
data-rz-slider-options="restrictedRangeSlider.options"
></rzslider>
</article>

<article>
<h2>Range slider with minimum range of 10 and maximum of 50</h2>
<rzslider
Expand Down
22 changes: 12 additions & 10 deletions dist/rzslider.css

Large diffs are not rendered by default.

83 changes: 69 additions & 14 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v6.5.1 -
(c) Rafal Zajac <rzajac@gmail.com>, Valentin Hervieu <valentin@hervieu.me>, Jussi Saarivirta <jusasi@gmail.com>, Angelin Sirbu <angelin.sirbu@gmail.com> -
https://github.com/angular-slider/angularjs-slider -
2018-03-30 */
2018-06-29 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
;(function(root, factory) {
Expand Down Expand Up @@ -36,6 +36,7 @@
precision: 0,
minRange: null,
maxRange: null,
restrictedRange: null,
pushRange: false,
minLimit: null,
maxLimit: null,
Expand Down Expand Up @@ -371,6 +372,7 @@
this.setDisabledState()
this.calcViewDimensions()
this.setMinAndMax()
this.updateRestrictionBar()
this.addAccessibility()
this.updateCeilLab()
this.updateFloorLab()
Expand Down Expand Up @@ -635,6 +637,7 @@
this.manageEventsBindings()
this.setDisabledState()
this.calcViewDimensions()
this.updateRestrictionBar()
this.refocusPointerIfNeeded()
},

Expand Down Expand Up @@ -676,27 +679,30 @@
this.selBar = jElem
break
case 4:
this.minH = jElem
this.restrictedBar = jElem
break
case 5:
this.maxH = jElem
this.minH = jElem
break
case 6:
this.flrLab = jElem
this.maxH = jElem
break
case 7:
this.ceilLab = jElem
this.flrLab = jElem
break
case 8:
this.minLab = jElem
this.ceilLab = jElem
break
case 9:
this.maxLab = jElem
this.minLab = jElem
break
case 10:
this.cmbLab = jElem
this.maxLab = jElem
break
case 11:
this.cmbLab = jElem
break
case 12:
this.ticks = jElem
break
}
Expand Down Expand Up @@ -753,6 +759,7 @@
this.leftOutSelBar,
!this.range || !this.options.showOuterSelectionBars
)
this.alwaysHide(this.restrictedBar, !this.options.restrictedRange)
this.alwaysHide(
this.rightOutSelBar,
!this.range || !this.options.showOuterSelectionBars
Expand Down Expand Up @@ -1305,6 +1312,26 @@
return isRTL ? pos <= ceilPos + ceilDim + 2 : pos + dim >= ceilPos - 2
},

/**
* Update restricted area bar
*
* @returns {undefined}
*/
updateRestrictionBar: function() {
var position = 0,
dimension = 0
if (this.options.restrictedRange) {
var from = this.valueToPosition(this.options.restrictedRange.from),
to = this.valueToPosition(this.options.restrictedRange.to)
dimension = Math.abs(to - from)
position = this.options.rightToLeft
? to + this.handleHalfDim
: from + this.handleHalfDim
this.setDimension(this.restrictedBar, dimension)
this.setPosition(this.restrictedBar, position)
}
},

/**
* Update slider selection bar, combined label and range label
*
Expand Down Expand Up @@ -1379,8 +1406,12 @@
: 0,
reversed = (offset - position > 0) ^ isSelectionBarFromRight,
direction = this.options.vertical
? reversed ? 'bottom' : 'top'
: reversed ? 'left' : 'right'
? reversed
? 'bottom'
: 'top'
: reversed
? 'left'
: 'right'
this.scope.barStyle = {
backgroundImage:
'linear-gradient(to ' +
Expand Down Expand Up @@ -1775,9 +1806,8 @@
else if (!this.options.rightToLeft)
//if event is at the same distance from min/max then if it's at left of minH, we return minH else maxH
return position < this.minH.rzsp ? this.minH : this.maxH
else
//reverse in rtl
return position > this.minH.rzsp ? this.minH : this.maxH
//reverse in rtl
else return position > this.minH.rzsp ? this.minH : this.maxH
},

/**
Expand Down Expand Up @@ -2369,6 +2399,7 @@
positionTrackingHandle: function(newValue) {
var valueChanged = false
newValue = this.applyMinMaxLimit(newValue)
newValue = this.applyRestrictedRange(newValue)
if (this.range) {
if (this.options.pushRange) {
newValue = this.applyPushRange(newValue)
Expand Down Expand Up @@ -2456,6 +2487,30 @@
return newValue
},

applyRestrictedRange: function(newValue) {
if (
this.options.restrictedRange != null &&
newValue > this.options.restrictedRange.from &&
newValue < this.options.restrictedRange.to
) {
var halfWidth =
(this.options.restrictedRange.to -
this.options.restrictedRange.from) /
2
if (this.tracking === 'lowValue') {
return newValue > this.options.restrictedRange.from + halfWidth
? this.options.restrictedRange.to
: this.options.restrictedRange.from
}
if (this.tracking === 'highValue') {
return newValue < this.options.restrictedRange.to - halfWidth
? this.options.restrictedRange.from
: this.options.restrictedRange.to
}
}
return newValue
},

applyPushRange: function(newValue) {
var difference =
this.tracking === 'lowValue'
Expand Down Expand Up @@ -2654,7 +2709,7 @@
'use strict';

$templateCache.put('rzSliderTpl.html',
"<div class=rzslider><span class=\"rz-bar-wrapper rz-left-out-selection\"><span class=rz-bar></span></span> <span class=\"rz-bar-wrapper rz-right-out-selection\"><span class=rz-bar></span></span> <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 rz-floor\"></span> <span class=\"rz-bubble rz-limit rz-ceil\"></span> <span class=\"rz-bubble rz-model-value\"></span> <span class=\"rz-bubble rz-model-high\"></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=rz-tick ng-class=\"{'rz-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=rz-tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span> <span ng-if=\"t.legend != null\" class=rz-tick-legend>{{ t.legend }}</span></li></ul></div>"
"<div class=rzslider><span class=\"rz-bar-wrapper rz-left-out-selection\"><span class=rz-bar></span></span> <span class=\"rz-bar-wrapper rz-right-out-selection\"><span class=rz-bar></span></span> <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-bar-wrapper><span class=\"rz-bar rz-restricted\" ng-style=restrictionStyle></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 rz-floor\"></span> <span class=\"rz-bubble rz-limit rz-ceil\"></span> <span class=\"rz-bubble rz-model-value\"></span> <span class=\"rz-bubble rz-model-high\"></span> <span class=rz-bubble></span><ul ng-show=showTicks class=rz-ticks><li ng-repeat=\"t in ticks track by $index\" class=rz-tick ng-class=\"{'rz-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=rz-tick-value ng-attr-uib-tooltip=\"{{ t.valueTooltip }}\" ng-attr-tooltip-placement={{t.valueTooltipPlacement}}>{{ t.value }}</span> <span ng-if=\"t.legend != null\" class=rz-tick-legend>{{ t.legend }}</span></li></ul></div>"
);

}]);
Expand Down
4 changes: 2 additions & 2 deletions dist/rzslider.min.css

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

6 changes: 3 additions & 3 deletions dist/rzslider.min.js

Large diffs are not rendered by default.

Loading