Commit 3afcce95 authored by Valentin Hervieu's avatar Valentin Hervieu

fix(cmbLabel): Improve combined label position and show only one value if min==max

Closes #245
parent 4bff1a84
...@@ -880,7 +880,13 @@ ...@@ -880,7 +880,13 @@
updateLowHandle: function(newOffset) { updateLowHandle: function(newOffset) {
this.setPosition(this.minH, newOffset); this.setPosition(this.minH, newOffset);
this.translateFn(this.scope.rzSliderModel, this.minLab); this.translateFn(this.scope.rzSliderModel, this.minLab);
var pos = Math.min(Math.max(newOffset - this.minLab.rzsd / 2 + this.handleHalfDim, 0), this.barDimension - this.ceilLab.rzsd); var pos = Math.min(
Math.max(
newOffset - this.minLab.rzsd / 2 + this.handleHalfDim,
0
),
this.barDimension - this.ceilLab.rzsd
);
this.setPosition(this.minLab, pos); this.setPosition(this.minLab, pos);
this.shFloorCeil(); this.shFloorCeil();
...@@ -895,7 +901,7 @@ ...@@ -895,7 +901,7 @@
updateHighHandle: function(newOffset) { updateHighHandle: function(newOffset) {
this.setPosition(this.maxH, newOffset); this.setPosition(this.maxH, newOffset);
this.translateFn(this.scope.rzSliderHigh, this.maxLab); this.translateFn(this.scope.rzSliderHigh, this.maxLab);
var pos = Math.min((newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim), (this.barDimension - this.ceilLab.rzsd)); var pos = Math.min(newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim, this.barDimension - this.ceilLab.rzsd);
this.setPosition(this.maxLab, pos); this.setPosition(this.maxLab, pos);
this.shFloorCeil(); this.shFloorCeil();
...@@ -950,8 +956,8 @@ ...@@ -950,8 +956,8 @@
updateSelectionBar: function() { updateSelectionBar: function() {
var position = 0, var position = 0,
dimension = 0; dimension = 0;
if(this.range) { if (this.range) {
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim; dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp);
position = this.minH.rzsp + this.handleHalfDim; position = this.minH.rzsp + this.handleHalfDim;
} }
else { else {
...@@ -1001,14 +1007,20 @@ ...@@ -1001,14 +1007,20 @@
* @returns {undefined} * @returns {undefined}
*/ */
updateCmbLabel: function() { updateCmbLabel: function() {
var lowTr, highTr;
if (this.minLab.rzsp + this.minLab.rzsd + 10 >= this.maxLab.rzsp) { if (this.minLab.rzsp + this.minLab.rzsd + 10 >= this.maxLab.rzsp) {
lowTr = this.getDisplayValue(this.scope.rzSliderModel); var lowTr = this.getDisplayValue(this.scope.rzSliderModel),
highTr = this.getDisplayValue(this.scope.rzSliderHigh); highTr = this.getDisplayValue(this.scope.rzSliderHigh),
labelVal = lowTr === highTr ? lowTr : lowTr + ' - ' + highTr;
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
var pos = Math.min(Math.max((this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2), 0), (this.barDimension - this.cmbLab.rzsd)); this.translateFn(labelVal, this.cmbLab, false);
var pos = Math.min(
Math.max(
this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2,
0
),
this.barDimension - this.cmbLab.rzsd
);
this.setPosition(this.cmbLab, pos); this.setPosition(this.cmbLab, pos);
this.hideEl(this.minLab); this.hideEl(this.minLab);
this.hideEl(this.maxLab); this.hideEl(this.maxLab);
......
This diff is collapsed.
...@@ -884,7 +884,13 @@ ...@@ -884,7 +884,13 @@
updateLowHandle: function(newOffset) { updateLowHandle: function(newOffset) {
this.setPosition(this.minH, newOffset); this.setPosition(this.minH, newOffset);
this.translateFn(this.scope.rzSliderModel, this.minLab); this.translateFn(this.scope.rzSliderModel, this.minLab);
var pos = Math.min(Math.max(newOffset - this.minLab.rzsd / 2 + this.handleHalfDim, 0), this.barDimension - this.ceilLab.rzsd); var pos = Math.min(
Math.max(
newOffset - this.minLab.rzsd / 2 + this.handleHalfDim,
0
),
this.barDimension - this.ceilLab.rzsd
);
this.setPosition(this.minLab, pos); this.setPosition(this.minLab, pos);
this.shFloorCeil(); this.shFloorCeil();
...@@ -899,7 +905,7 @@ ...@@ -899,7 +905,7 @@
updateHighHandle: function(newOffset) { updateHighHandle: function(newOffset) {
this.setPosition(this.maxH, newOffset); this.setPosition(this.maxH, newOffset);
this.translateFn(this.scope.rzSliderHigh, this.maxLab); this.translateFn(this.scope.rzSliderHigh, this.maxLab);
var pos = Math.min((newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim), (this.barDimension - this.ceilLab.rzsd)); var pos = Math.min(newOffset - this.maxLab.rzsd / 2 + this.handleHalfDim, this.barDimension - this.ceilLab.rzsd);
this.setPosition(this.maxLab, pos); this.setPosition(this.maxLab, pos);
this.shFloorCeil(); this.shFloorCeil();
...@@ -954,8 +960,8 @@ ...@@ -954,8 +960,8 @@
updateSelectionBar: function() { updateSelectionBar: function() {
var position = 0, var position = 0,
dimension = 0; dimension = 0;
if(this.range) { if (this.range) {
dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp) + this.handleHalfDim; dimension = Math.abs(this.maxH.rzsp - this.minH.rzsp);
position = this.minH.rzsp + this.handleHalfDim; position = this.minH.rzsp + this.handleHalfDim;
} }
else { else {
...@@ -1005,14 +1011,20 @@ ...@@ -1005,14 +1011,20 @@
* @returns {undefined} * @returns {undefined}
*/ */
updateCmbLabel: function() { updateCmbLabel: function() {
var lowTr, highTr;
if (this.minLab.rzsp + this.minLab.rzsd + 10 >= this.maxLab.rzsp) { if (this.minLab.rzsp + this.minLab.rzsd + 10 >= this.maxLab.rzsp) {
lowTr = this.getDisplayValue(this.scope.rzSliderModel); var lowTr = this.getDisplayValue(this.scope.rzSliderModel),
highTr = this.getDisplayValue(this.scope.rzSliderHigh); highTr = this.getDisplayValue(this.scope.rzSliderHigh),
labelVal = lowTr === highTr ? lowTr : lowTr + ' - ' + highTr;
this.translateFn(lowTr + ' - ' + highTr, this.cmbLab, false);
var pos = Math.min(Math.max((this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2), 0), (this.barDimension - this.cmbLab.rzsd)); this.translateFn(labelVal, this.cmbLab, false);
var pos = Math.min(
Math.max(
this.selBar.rzsp + this.selBar.rzsd / 2 - this.cmbLab.rzsd / 2,
0
),
this.barDimension - this.cmbLab.rzsd
);
this.setPosition(this.cmbLab, pos); this.setPosition(this.cmbLab, pos);
this.hideEl(this.minLab); this.hideEl(this.minLab);
this.hideEl(this.maxLab); this.hideEl(this.maxLab);
......
...@@ -514,7 +514,7 @@ describe('rzslider - ', function() { ...@@ -514,7 +514,7 @@ describe('rzslider - ', function() {
} }
}; };
createRangeSlider(sliderConf); createRangeSlider(sliderConf);
var expectedDimension = slider.valueToOffset(6) + slider.handleHalfDim, var expectedDimension = slider.valueToOffset(6),
expectedPosition = slider.valueToOffset(2) + slider.handleHalfDim; expectedPosition = slider.valueToOffset(2) + slider.handleHalfDim;
expect(slider.selBar.css('width')).to.equal(expectedDimension + 'px'); expect(slider.selBar.css('width')).to.equal(expectedDimension + 'px');
expect(slider.selBar.css('left')).to.equal(expectedPosition + 'px'); expect(slider.selBar.css('left')).to.equal(expectedPosition + 'px');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment