Skip to content

Commit

Permalink
feat($compile): adds labelOverlapSeparator as an option (#616)
Browse files Browse the repository at this point in the history
* feat($compile): adds labelOverlapSeparator as an option

The labelOverlapSeparator option allows the user to specify what string to use to separate the
labels when they overlap. The previous hardcoded string ' - ' could indeed be mistaken as a minus
sign. To avoid introducing a breaking change, the default is the previous value: ' - '. Tests and
README.md modified accordingly.
  • Loading branch information
ben-henoida authored and ValentinH committed Feb 6, 2018
1 parent 9077aac commit 8b166c0
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ bower_components/
temp/
tests/coverage/
yarn.lock
cypress/videos
cypress/videos
npm-debug.log
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ The default options are:
reversedControls: false,
boundPointerLabels: true,
mergeRangeLabelsIfSame: false,
labelOverlapSeparator: ' - ',
customTemplateScope: null,
logScale: false,
customValueToPosition: null,
Expand Down Expand Up @@ -413,6 +414,8 @@ Just pass an array with each slider value and that's it; the floor, ceil and ste

**mergeRangeLabelsIfSame** - _Boolean (defaults to false)_: Set to true to merge the range labels if they are the same. For instance, if min and max are 50, the label will be "50 - 50" if `mergeRangeLabelsIfSame: false`, else "50".

**labelOverlapSeparator** - _String (defaults to ' - ')_: Separator to use when the labels overlap. For instance, if min and max are -1 and 1, the label will be "-1 .. 1" if `labelOverlapSeparator: ' .. '`.

**onStart** - _Function(sliderId, modelValue, highValue, pointerType)_: Function to be called when a slider update is started. If an id was set in the options, then it's passed to this callback. This callback is called before any update on the model. `pointerType` is either 'min' or 'max' depending on which handle is used.

**onChange** - _Function(sliderId, modelValue, highValue, pointerType)_: Function to be called when rz-slider-model or rz-slider-high change. If an id was set in the options, then it's passed to this callback. `pointerType` is either 'min' or 'max' depending on which handle is used.
Expand Down
6 changes: 3 additions & 3 deletions dist/rzslider.css

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v6.4.3 -
/*! angularjs-slider - v6.4.4 -
(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-01-22 */
2018-02-06 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
;(function(root, factory) {
Expand Down Expand Up @@ -78,6 +78,7 @@
reversedControls: false,
boundPointerLabels: true,
mergeRangeLabelsIfSame: false,
labelOverlapSeparator: ' - ',
customTemplateScope: null,
logScale: false,
customValueToPosition: null,
Expand Down Expand Up @@ -1473,8 +1474,8 @@
labelVal = lowTr
} else {
labelVal = this.options.rightToLeft
? highTr + ' - ' + lowTr
: lowTr + ' - ' + highTr
? highTr + this.options.labelOverlapSeparator + lowTr
: lowTr + this.options.labelOverlapSeparator + highTr
}

this.translateFn(labelVal, this.cmbLab, 'cmb', false)
Expand Down
2 changes: 1 addition & 1 deletion 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.

6 changes: 3 additions & 3 deletions dist/rzslider.scss

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
reversedControls: false,
boundPointerLabels: true,
mergeRangeLabelsIfSame: false,
labelOverlapSeparator: ' - ',
customTemplateScope: null,
logScale: false,
customValueToPosition: null,
Expand Down Expand Up @@ -1477,8 +1478,8 @@
labelVal = lowTr
} else {
labelVal = this.options.rightToLeft
? highTr + ' - ' + lowTr
: lowTr + ' - ' + highTr
? highTr + this.options.labelOverlapSeparator + lowTr
: lowTr + this.options.labelOverlapSeparator + highTr
}

this.translateFn(labelVal, this.cmbLab, 'cmb', false)
Expand Down
33 changes: 33 additions & 0 deletions tests/specs/options-handling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,39 @@
parseInt(helper.slider.leftOutSelBar.css('left'))
)
})

it('should use the default separator when labels overlap', function() {
helper.scope.slider.min = -1
helper.scope.slider.max = 1
helper.scope.slider.options.floor = -100
helper.scope.slider.options.ceil = +100
helper.scope.slider.options.step = 1
helper.scope.slider.options.rightToLeft = false
helper.scope.$digest()
expect(helper.slider.cmbLab.text()).to.equal('-1 - 1')
})

it('should use the custom separator when labels overlap, and labelOverlapSeparator is set', function() {
helper.scope.slider.min = -1
helper.scope.slider.max = 1
helper.scope.slider.options.floor = -100
helper.scope.slider.options.ceil = +100
helper.scope.slider.options.step = 1
helper.scope.slider.options.rightToLeft = false
helper.scope.slider.options.labelOverlapSeparator = ' .. '
helper.scope.$digest()
expect(helper.slider.cmbLab.text()).to.equal('-1 .. 1')
})
it('should use the custom separator when labels overlap, and labelOverlapSeparator is set, in RTL mode', function() {
helper.scope.slider.min = -1
helper.scope.slider.max = 1
helper.scope.slider.options.floor = -100
helper.scope.slider.options.ceil = +100
helper.scope.slider.options.step = 1
helper.scope.slider.options.labelOverlapSeparator = ' .. '
helper.scope.$digest()
expect(helper.slider.cmbLab.text()).to.equal('1 .. -1')
})
})

describe('options expression specific - ', function() {
Expand Down

0 comments on commit 8b166c0

Please sign in to comment.