Skip to content

Commit 7328dc6

Browse files
committed
Refactor logScale feature
1 parent 468ed3d commit 7328dc6

21 files changed

+684
-413
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
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

README.md

Lines changed: 12 additions & 1 deletion
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

demo/demo.js

Lines changed: 31 additions & 6 deletions
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
};
@@ -143,7 +144,32 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
143144
options: {
144145
floor: 1,
145146
ceil: 100,
146-
logScale: true
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+
}
147173
}
148174
};
149175

@@ -242,8 +268,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
242268
options: {
243269
ceil: 10,
244270
floor: 0,
245-
ticksArray: [0, 1, 3, 8, 10],
246-
showTicksValues: true
271+
ticksArray: [0, 1, 3, 8, 10]
247272
}
248273
};
249274

@@ -332,7 +357,7 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
332357
step: 50,
333358
showSelectionBar: true,
334359
showTicks: true,
335-
getTickColor: function(value){
360+
getTickColor: function(value) {
336361
if (value < 300)
337362
return 'red';
338363
if (value < 600)
@@ -574,8 +599,8 @@ app.directive('clickableLabel', function() {
574599
scope: {label: '='},
575600
replace: true,
576601
template: "<button ng-click='onclick(label)' style='cursor: pointer;'>click me - {{label}}</button>",
577-
link: function(scope, elem, attrs){
578-
scope.onclick = function(label){
602+
link: function(scope, elem, attrs) {
603+
scope.onclick = function(label) {
579604
alert("I'm " + label);
580605
};
581606
}

demo/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ <h2>Slider with logarithmic scale</h2>
127127
></rzslider>
128128
</article>
129129

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+
130138
<article>
131139
<h2>Right to left slider with custom floor/ceil/step</h2>
132140
<rzslider

0 commit comments

Comments
 (0)