Skip to content

Commit 8b166c0

Browse files
ben-henoidaValentinH
ben-henoida
authored andcommitted
feat($compile): adds labelOverlapSeparator as an option (#616)
* 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.
1 parent 9077aac commit 8b166c0

9 files changed

+56
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ bower_components/
44
temp/
55
tests/coverage/
66
yarn.lock
7-
cypress/videos
7+
cypress/videos
8+
npm-debug.log

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ The default options are:
275275
reversedControls: false,
276276
boundPointerLabels: true,
277277
mergeRangeLabelsIfSame: false,
278+
labelOverlapSeparator: ' - ',
278279
customTemplateScope: null,
279280
logScale: false,
280281
customValueToPosition: null,
@@ -413,6 +414,8 @@ Just pass an array with each slider value and that's it; the floor, ceil and ste
413414

414415
**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".
415416

417+
**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: ' .. '`.
418+
416419
**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.
417420

418421
**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.

dist/rzslider.css

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! angularjs-slider - v6.4.3 -
1+
/*! angularjs-slider - v6.4.4 -
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-
2018-01-22 */
4+
2018-02-06 */
55
/*jslint unparam: true */
66
/*global angular: false, console: false, define, module */
77
;(function(root, factory) {
@@ -78,6 +78,7 @@
7878
reversedControls: false,
7979
boundPointerLabels: true,
8080
mergeRangeLabelsIfSame: false,
81+
labelOverlapSeparator: ' - ',
8182
customTemplateScope: null,
8283
logScale: false,
8384
customValueToPosition: null,
@@ -1473,8 +1474,8 @@
14731474
labelVal = lowTr
14741475
} else {
14751476
labelVal = this.options.rightToLeft
1476-
? highTr + ' - ' + lowTr
1477-
: lowTr + ' - ' + highTr
1477+
? highTr + this.options.labelOverlapSeparator + lowTr
1478+
: lowTr + this.options.labelOverlapSeparator + highTr
14781479
}
14791480

14801481
this.translateFn(labelVal, this.cmbLab, 'cmb', false)

dist/rzslider.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rzslider.scss

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

src/rzslider.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
reversedControls: false,
8383
boundPointerLabels: true,
8484
mergeRangeLabelsIfSame: false,
85+
labelOverlapSeparator: ' - ',
8586
customTemplateScope: null,
8687
logScale: false,
8788
customValueToPosition: null,
@@ -1477,8 +1478,8 @@
14771478
labelVal = lowTr
14781479
} else {
14791480
labelVal = this.options.rightToLeft
1480-
? highTr + ' - ' + lowTr
1481-
: lowTr + ' - ' + highTr
1481+
? highTr + this.options.labelOverlapSeparator + lowTr
1482+
: lowTr + this.options.labelOverlapSeparator + highTr
14821483
}
14831484

14841485
this.translateFn(labelVal, this.cmbLab, 'cmb', false)

tests/specs/options-handling-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,39 @@
16461646
parseInt(helper.slider.leftOutSelBar.css('left'))
16471647
)
16481648
})
1649+
1650+
it('should use the default separator when labels overlap', function() {
1651+
helper.scope.slider.min = -1
1652+
helper.scope.slider.max = 1
1653+
helper.scope.slider.options.floor = -100
1654+
helper.scope.slider.options.ceil = +100
1655+
helper.scope.slider.options.step = 1
1656+
helper.scope.slider.options.rightToLeft = false
1657+
helper.scope.$digest()
1658+
expect(helper.slider.cmbLab.text()).to.equal('-1 - 1')
1659+
})
1660+
1661+
it('should use the custom separator when labels overlap, and labelOverlapSeparator is set', function() {
1662+
helper.scope.slider.min = -1
1663+
helper.scope.slider.max = 1
1664+
helper.scope.slider.options.floor = -100
1665+
helper.scope.slider.options.ceil = +100
1666+
helper.scope.slider.options.step = 1
1667+
helper.scope.slider.options.rightToLeft = false
1668+
helper.scope.slider.options.labelOverlapSeparator = ' .. '
1669+
helper.scope.$digest()
1670+
expect(helper.slider.cmbLab.text()).to.equal('-1 .. 1')
1671+
})
1672+
it('should use the custom separator when labels overlap, and labelOverlapSeparator is set, in RTL mode', function() {
1673+
helper.scope.slider.min = -1
1674+
helper.scope.slider.max = 1
1675+
helper.scope.slider.options.floor = -100
1676+
helper.scope.slider.options.ceil = +100
1677+
helper.scope.slider.options.step = 1
1678+
helper.scope.slider.options.labelOverlapSeparator = ' .. '
1679+
helper.scope.$digest()
1680+
expect(helper.slider.cmbLab.text()).to.equal('1 .. -1')
1681+
})
16491682
})
16501683

16511684
describe('options expression specific - ', function() {

0 commit comments

Comments
 (0)