Skip to content

Commit 2a7b45d

Browse files
authored
feat(logScale): Implement a logScale option (#280)
* feat(logScale): Implement a logScale option to display sliders with logarithmic scale
1 parent 37a4f90 commit 2a7b45d

21 files changed

+705
-384
lines changed

Diff for: CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# 5.7.0 (2016-10-16)
2+
## Features
3+
- Add a `logScale` option to display the slider using a logarithmic scale (#280).
4+
- Add `customValueToPosition` and `customPositionToValue` options to display the slider using a custom scale (#280).
5+
16
# 5.6.0 (2016-10-16)
27
## Features
3-
- Add an `ticksArray` to display ticks at specific positions (#426).
8+
- Add a `ticksArray` option to display ticks at specific positions (#426).
49

510
To enable this new feature, the way the ticks are rendered has been changed. Now each tick is positioned absolutely using a `transform: translate()` instruction.
611

Diff for: README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,10 @@ The default options are:
239239
rightToLeft: false,
240240
boundPointerLabels: true,
241241
mergeRangeLabelsIfSame: false,
242-
customTemplateScope: null
242+
customTemplateScope: null,
243+
logScale: false,
244+
customValueToPosition: null,
245+
customPositionToValue: null
243246
}
244247
````
245248

@@ -382,6 +385,14 @@ _Changing this value at runtime is not currently supported._
382385

383386
**customTemplateScope** - _Object (default to null)_: The properties defined in this object will be exposed in the slider template under `custom.X`.
384387

388+
**logScale** - _Boolean (defaults to false)_: Set to true to use a logarithmic scale to display the slider.
389+
390+
For custom scales:
391+
**customValueToPosition** - _Function(val, minVal, maxVal): percent_: Function that returns the position on the slider for a given value. The position must be a percentage between 0 and 1.
392+
393+
**customPositionToValue** - _Function(percent, minVal, maxVal): value_: Function that returns the value for a given position on the slider. The position is a percentage between 0 and 1.
394+
395+
385396
## Change default options
386397
If you want the change the default options for all the sliders displayed in your application, you can set them using the `RzSliderOptions.options()` method:
387398
```js

Diff for: demo/demo.js

+40-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
1313
options: {
1414
floor: 0,
1515
ceil: 100,
16+
rightToLeft: true,
1617
step: 1
1718
}
1819
};
@@ -137,6 +138,41 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
137138
}
138139
};
139140

141+
//Slider config with logarithmic scale
142+
$scope.slider_log = {
143+
value: 1,
144+
options: {
145+
floor: 1,
146+
ceil: 100,
147+
logScale: true,
148+
showTicks: true
149+
}
150+
};
151+
152+
//Slider config with custom scale
153+
$scope.slider_custom_scale = {
154+
value: 50,
155+
options: {
156+
floor: 0,
157+
ceil: 100,
158+
step: 10,
159+
showTicksValues: true,
160+
customValueToPosition: function(val, minVal, maxVal) {
161+
val = Math.sqrt(val);
162+
minVal = Math.sqrt(minVal);
163+
maxVal = Math.sqrt(maxVal);
164+
var range = maxVal - minVal;
165+
return (val - minVal) / range;
166+
},
167+
customPositionToValue: function(percent, minVal, maxVal) {
168+
minVal = Math.sqrt(minVal);
169+
maxVal = Math.sqrt(maxVal);
170+
var value = percent * (maxVal - minVal) + minVal;
171+
return Math.pow(value, 2);
172+
}
173+
}
174+
};
175+
140176
//Right to left slider with floor, ceil and step
141177
$scope.slider_floor_ceil_rtl = {
142178
value: 12,
@@ -232,8 +268,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
232268
options: {
233269
ceil: 10,
234270
floor: 0,
235-
ticksArray: [0, 1, 3, 8, 10],
236-
showTicksValues: true
271+
ticksArray: [0, 1, 3, 8, 10]
237272
}
238273
};
239274

@@ -322,7 +357,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
322357
step: 50,
323358
showSelectionBar: true,
324359
showTicks: true,
325-
getTickColor: function(value){
360+
getTickColor: function(value) {
326361
if (value < 300)
327362
return 'red';
328363
if (value < 600)
@@ -564,8 +599,8 @@ app.directive('clickableLabel', function() {
564599
scope: {label: '='},
565600
replace: true,
566601
template: "<button ng-click='onclick(label)' style='cursor: pointer;'>click me - {{label}}</button>",
567-
link: function(scope, elem, attrs){
568-
scope.onclick = function(label){
602+
link: function(scope, elem, attrs) {
603+
scope.onclick = function(label) {
569604
alert("I'm " + label);
570605
};
571606
}

Diff for: demo/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ <h2>Slider with custom floor/ceil/step</h2>
119119
></rzslider>
120120
</article>
121121

122+
<article>
123+
<h2>Slider with logarithmic scale</h2>
124+
<rzslider
125+
rz-slider-model="slider_log.value"
126+
rz-slider-options="slider_log.options"
127+
></rzslider>
128+
</article>
129+
130+
<article>
131+
<h2>Slider with custom scale</h2>
132+
<rzslider
133+
rz-slider-model="slider_custom_scale.value"
134+
rz-slider-options="slider_custom_scale.options"
135+
></rzslider>
136+
</article>
137+
122138
<article>
123139
<h2>Right to left slider with custom floor/ceil/step</h2>
124140
<rzslider

0 commit comments

Comments
 (0)