Skip to content

Commit

Permalink
fix(labels): Refactor autoHiding algorithm for labels
Browse files Browse the repository at this point in the history
fix #446
  • Loading branch information
ValentinH committed Nov 5, 2016
1 parent e63e4ff commit 3ab3aa3
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 79 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 5.8.4 (2016-11-05)
## Improvement
- Refactor autoHiding algorithm for labels (fix #446)

# 5.8.3 (2016-11-03)
## Improvement
- Generate a SCSS file (simple copy of the css file) in the dist folder so it can be imported (#449)
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-slider",
"version": "5.8.3",
"version": "5.8.4",
"homepage": "https://github.com/angular-slider/angularjs-slider",
"authors": [
"Rafal Zajac <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions demo/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<div class="wrapper">

<article>
<h2>Slider with date values</h2>
<h2>Debug slider</h2>
<rzslider
rz-slider-model="slider_dates.value"
rz-slider-options="slider_dates.options"
data-rz-slider-model="rangeSlider.minValue"
data-rz-slider-options="rangeSlider.options"
></rzslider>
</article>

Expand Down
14 changes: 2 additions & 12 deletions dist/rzslider.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.3 -
/*! angularjs-slider - v5.8.4 -
(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-11-03 */
2016-11-05 */
.rzslider {
position: relative;
display: inline-block;
Expand Down Expand Up @@ -237,16 +237,6 @@
left: 16px !important;
}

.rzslider.rz-vertical .rz-bubble.rz-floor {
bottom: 0;
left: auto;
}

.rzslider.rz-vertical .rz-bubble.rz-ceil {
top: 0;
right: auto;
}

.rzslider.rz-vertical .rz-ticks {
top: 0;
left: -3px;
Expand Down
49 changes: 29 additions & 20 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.3 -
/*! angularjs-slider - v5.8.4 -
(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-11-03 */
2016-11-05 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -1161,24 +1161,11 @@
}
var flHidden = false,
clHidden = false,
isRTL = this.options.rightToLeft,
flrLabPos = this.flrLab.rzsp,
flrLabDim = this.flrLab.rzsd,
minLabPos = this.minLab.rzsp,
minLabDim = this.minLab.rzsd,
maxLabPos = this.maxLab.rzsp,
maxLabDim = this.maxLab.rzsd,
cmbLabPos = this.cmbLab.rzsp,
cmbLabDim = this.cmbLab.rzsd,
ceilLabPos = this.ceilLab.rzsp,
halfHandle = this.handleHalfDim,
isMinLabAtFloor = isRTL ? minLabPos + minLabDim >= flrLabPos - flrLabDim - 5 : minLabPos <= flrLabPos + flrLabDim + 5,
isMinLabAtCeil = isRTL ? minLabPos - minLabDim <= ceilLabPos + halfHandle + 10 : minLabPos + minLabDim >= ceilLabPos - halfHandle - 10,
isMaxLabAtFloor = isRTL ? maxLabPos >= flrLabPos - flrLabDim - halfHandle : maxLabPos <= flrLabPos + flrLabDim + halfHandle,
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10,
isCmbLabAtFloor = isRTL ? cmbLabPos >= flrLabPos - flrLabDim - halfHandle : cmbLabPos <= flrLabPos + flrLabDim + halfHandle,
isCmbLabAtCeil = isRTL ? cmbLabPos - cmbLabDim <= ceilLabPos + 10 : cmbLabPos + cmbLabDim >= ceilLabPos - 10

isMinLabAtFloor = this.isLabelBelowFloorLab(this.minLab),
isMinLabAtCeil = this.isLabelAboveCeilLab(this.minLab),
isMaxLabAtCeil = this.isLabelAboveCeilLab(this.maxLab),
isCmbLabAtFloor = this.isLabelBelowFloorLab(this.cmbLab),
isCmbLabAtCeil = this.isLabelAboveCeilLab(this.cmbLab);

if (isMinLabAtFloor) {
flHidden = true;
Expand Down Expand Up @@ -1215,6 +1202,28 @@
}
},

isLabelBelowFloorLab: function(label) {
var isRTL = this.options.rightToLeft,
pos = label.rzsp,
dim = label.rzsd,
floorPos = this.flrLab.rzsp,
floorDim = this.flrLab.rzsd;
return isRTL ?
pos + dim >= floorPos - 2 :
pos <= floorPos + floorDim + 2;
},

isLabelAboveCeilLab: function(label) {
var isRTL = this.options.rightToLeft,
pos = label.rzsp,
dim = label.rzsd,
ceilPos = this.ceilLab.rzsp,
ceilDim = this.ceilLab.rzsd;
return isRTL ?
pos <= ceilPos + ceilDim + 2 :
pos + dim >= ceilPos - 2;
},

/**
* Update slider selection bar, combined label and range label
*
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.

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

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions dist/rzslider.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v5.8.3 -
/*! angularjs-slider - v5.8.4 -
(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-11-03 */
2016-11-05 */
.rzslider {
position: relative;
display: inline-block;
Expand Down Expand Up @@ -237,16 +237,6 @@
left: 16px !important;
}

.rzslider.rz-vertical .rz-bubble.rz-floor {
bottom: 0;
left: auto;
}

.rzslider.rz-vertical .rz-bubble.rz-ceil {
top: 0;
right: auto;
}

.rzslider.rz-vertical .rz-ticks {
top: 0;
left: -3px;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-slider",
"version": "5.8.3",
"version": "5.8.4",
"description": "AngularJS slider directive with no external dependencies. Mobile friendly!.",
"main": "dist/rzslider.js",
"repository": {
Expand Down
45 changes: 27 additions & 18 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1165,24 +1165,11 @@
}
var flHidden = false,
clHidden = false,
isRTL = this.options.rightToLeft,
flrLabPos = this.flrLab.rzsp,
flrLabDim = this.flrLab.rzsd,
minLabPos = this.minLab.rzsp,
minLabDim = this.minLab.rzsd,
maxLabPos = this.maxLab.rzsp,
maxLabDim = this.maxLab.rzsd,
cmbLabPos = this.cmbLab.rzsp,
cmbLabDim = this.cmbLab.rzsd,
ceilLabPos = this.ceilLab.rzsp,
halfHandle = this.handleHalfDim,
isMinLabAtFloor = isRTL ? minLabPos + minLabDim >= flrLabPos - flrLabDim - 5 : minLabPos <= flrLabPos + flrLabDim + 5,
isMinLabAtCeil = isRTL ? minLabPos - minLabDim <= ceilLabPos + halfHandle + 10 : minLabPos + minLabDim >= ceilLabPos - halfHandle - 10,
isMaxLabAtFloor = isRTL ? maxLabPos >= flrLabPos - flrLabDim - halfHandle : maxLabPos <= flrLabPos + flrLabDim + halfHandle,
isMaxLabAtCeil = isRTL ? maxLabPos - maxLabDim <= ceilLabPos + 10 : maxLabPos + maxLabDim >= ceilLabPos - 10,
isCmbLabAtFloor = isRTL ? cmbLabPos >= flrLabPos - flrLabDim - halfHandle : cmbLabPos <= flrLabPos + flrLabDim + halfHandle,
isCmbLabAtCeil = isRTL ? cmbLabPos - cmbLabDim <= ceilLabPos + 10 : cmbLabPos + cmbLabDim >= ceilLabPos - 10

isMinLabAtFloor = this.isLabelBelowFloorLab(this.minLab),
isMinLabAtCeil = this.isLabelAboveCeilLab(this.minLab),
isMaxLabAtCeil = this.isLabelAboveCeilLab(this.maxLab),
isCmbLabAtFloor = this.isLabelBelowFloorLab(this.cmbLab),
isCmbLabAtCeil = this.isLabelAboveCeilLab(this.cmbLab);

if (isMinLabAtFloor) {
flHidden = true;
Expand Down Expand Up @@ -1219,6 +1206,28 @@
}
},

isLabelBelowFloorLab: function(label) {
var isRTL = this.options.rightToLeft,
pos = label.rzsp,
dim = label.rzsd,
floorPos = this.flrLab.rzsp,
floorDim = this.flrLab.rzsd;
return isRTL ?
pos + dim >= floorPos - 2 :
pos <= floorPos + floorDim + 2;
},

isLabelAboveCeilLab: function(label) {
var isRTL = this.options.rightToLeft,
pos = label.rzsp,
dim = label.rzsd,
ceilPos = this.ceilLab.rzsp,
ceilDim = this.ceilLab.rzsd;
return isRTL ?
pos <= ceilPos + ceilDim + 2 :
pos + dim >= ceilPos - 2;
},

/**
* Update slider selection bar, combined label and range label
*
Expand Down
8 changes: 0 additions & 8 deletions src/rzslider.less
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,6 @@
left: @handleSize/2 !important;
top: auto;
}
&.rz-floor {
left: auto;
bottom: 0;
}
&.rz-ceil {
right: auto;
top: 0;
}
}

.rz-ticks {
Expand Down

0 comments on commit 3ab3aa3

Please sign in to comment.