Skip to content

Commit 9aca352

Browse files
authored
feat(ticks): Refactor ticks to improve flexibility (#426)
feat(ticks): Refactor ticks to improve flexibility
1 parent edf62b0 commit 9aca352

14 files changed

+249
-152
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
bower_components/
44
temp/
55
tests/coverage/
6+
yarn.lock

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
# 5.6.0 (2016-10-16)
2+
## Features
3+
- Add an `ticksArray` to display ticks at specific positions (#426).
4+
5+
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.
6+
17
# 5.5.1 (2016-09-22)
28
## Fix
39
- Prevent losing focus when slider is rerendered (#415).
410

511
# 5.5.0 (2016-09-06)
612
## Features
7-
- Add an autoHideLimitLabels to disable the auto-hiding of limit labels (#405).
13+
- Add an `autoHideLimitLabels` to disable the auto-hiding of limit labels (#405).
814

915
# 5.4.3 (2016-08-07)
1016
## Fix

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ The default options are:
220220
interval: 350,
221221
showTicks: false,
222222
showTicksValues: false,
223+
ticksArray: null,
223224
ticksTooltip: null,
224225
ticksValuesTooltip: null,
225226
vertical: false,
@@ -340,6 +341,8 @@ Just pass an array with each slider value and that's it; the floor, ceil and ste
340341
341342
**showTicksValues** - _Boolean or Number (defaults to false)_: Set to true to display a tick and the step value for each step of the slider. Set a number to display ticks and the step value at intermediate positions. This number corresponds to the step between each tick.
342343
344+
**ticksArray** - _Array (defaults to null)_: Use to display ticks at specific positions. The array contains the index of the ticks that should be displayed. For example, [0, 1, 5] will display a tick for the first, second and sixth values.
345+
343346
**ticksTooltip** - _Function(value) (defaults to null)_: (requires angular-ui bootstrap) Used to display a tooltip when a tick is hovered. Set to a function that returns the tooltip content for a given value.
344347
345348
**ticksValuesTooltip** - _Function(value) (defaults to null)_: Same as `ticksTooltip` but for ticks values.

demo/demo.js

+43-31
Original file line numberDiff line numberDiff line change
@@ -127,27 +127,6 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
127127
}
128128
};
129129

130-
//Slider with custom tick formatting
131-
$scope.slider_tick_color = {
132-
value: 0,
133-
options: {
134-
ceil: 1200,
135-
floor: 0,
136-
step: 50,
137-
showSelectionBar: true,
138-
showTicks: true,
139-
getTickColor: function(value){
140-
if (value < 300)
141-
return 'red';
142-
if (value < 600)
143-
return 'orange';
144-
if (value < 900)
145-
return 'yellow';
146-
return '#2AE02A';
147-
}
148-
}
149-
};
150-
151130
//Slider config with floor, ceil and step
152131
$scope.slider_floor_ceil = {
153132
value: 12,
@@ -228,15 +207,6 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
228207
}
229208
}
230209
};
231-
//Slider config with angular directive inside custom template
232-
$scope.slider_custom_directive_inside_template = {
233-
minValue: 20,
234-
maxValue: 80,
235-
options: {
236-
floor: 0,
237-
ceil: 100
238-
}
239-
};
240210

241211
//Slider config with steps array of letters
242212
$scope.slider_alphabet = {
@@ -256,6 +226,17 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
256226
}
257227
};
258228

229+
//Slider with ticks at specific positions
230+
$scope.slider_ticks_array = {
231+
value: 5,
232+
options: {
233+
ceil: 10,
234+
floor: 0,
235+
ticksArray: [0, 1, 3, 8, 10],
236+
showTicksValues: true
237+
}
238+
};
239+
259240
//Slider with ticks and tooltip
260241
$scope.slider_ticks_tooltip = {
261242
value: 5,
@@ -332,6 +313,27 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
332313
}
333314
};
334315

316+
//Slider with custom tick formatting
317+
$scope.slider_tick_color = {
318+
value: 0,
319+
options: {
320+
ceil: 1200,
321+
floor: 0,
322+
step: 50,
323+
showSelectionBar: true,
324+
showTicks: true,
325+
getTickColor: function(value){
326+
if (value < 300)
327+
return 'red';
328+
if (value < 600)
329+
return 'orange';
330+
if (value < 900)
331+
return 'yellow';
332+
return '#2AE02A';
333+
}
334+
}
335+
};
336+
335337
//Slider with draggable range
336338
$scope.slider_draggable_range = {
337339
minValue: 1,
@@ -378,7 +380,8 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
378380
floor: 0,
379381
ceil: 10,
380382
vertical: true,
381-
showTicks: true
383+
ticksArray: [0, 1, 5, 10],
384+
showTicksValues: true
382385
}
383386
};
384387
$scope.verticalSlider4 = {
@@ -519,6 +522,15 @@ app.controller('MainCtrl', function($scope, $rootScope, $timeout, $modal) {
519522
});
520523
};
521524

525+
//Slider config with angular directive inside custom template
526+
$scope.slider_custom_directive_inside_template = {
527+
minValue: 20,
528+
maxValue: 80,
529+
options: {
530+
floor: 0,
531+
ceil: 100
532+
}
533+
};
522534

523535
//Slider with draggable range
524536
$scope.slider_all_options = {

demo/index.html

+26-18
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ <h2>Slider with dynamic pointer color</h2>
111111
></rzslider>
112112
</article>
113113

114-
<article>
115-
<h2>Slider with dynamic tick color</h2>
116-
<rzslider
117-
rz-slider-model="slider_tick_color.value"
118-
rz-slider-options="slider_tick_color.options"
119-
></rzslider>
120-
</article>
121-
122114
<article>
123115
<h2>Slider with custom floor/ceil/step</h2>
124116
<rzslider
@@ -165,16 +157,6 @@ <h2>Slider with custom display function using html formatting</h2>
165157
></rzslider>
166158
</article>
167159

168-
<article>
169-
<h2>Slider with angular directive inside custom template</h2>
170-
<rzslider
171-
rz-slider-model="slider_custom_directive_inside_template.minValue"
172-
rz-slider-high="slider_custom_directive_inside_template.maxValue"
173-
rz-slider-options="slider_custom_directive_inside_template.options"
174-
rz-slider-tpl-url="directiveInCustomTemplate.html"
175-
></rzslider>
176-
</article>
177-
178160
<article>
179161
<h2>Slider with Alphabet</h2>
180162
Current letter: {{ slider_alphabet.value }}
@@ -192,6 +174,14 @@ <h2>Slider with ticks</h2>
192174
></rzslider>
193175
</article>
194176

177+
<article>
178+
<h2>Slider with ticks at specific positions</h2>
179+
<rzslider
180+
rz-slider-model="slider_ticks_array.value"
181+
rz-slider-options="slider_ticks_array.options"
182+
></rzslider>
183+
</article>
184+
195185
<article>
196186
<h2>Slider with ticks and tooltips</h2>
197187
<rzslider
@@ -242,6 +232,14 @@ <h2>Slider with ticks values and legend</h2>
242232
></rzslider>
243233
</article>
244234

235+
<article>
236+
<h2>Slider with dynamic tick color</h2>
237+
<rzslider
238+
rz-slider-model="slider_tick_color.value"
239+
rz-slider-options="slider_tick_color.options"
240+
></rzslider>
241+
</article>
242+
245243
<article>
246244
<h2>Slider with draggable range</h2>
247245
<rzslider
@@ -338,6 +336,16 @@ <h2>Sliders inside tabs</h2>
338336
</tabset>
339337
</article>
340338

339+
<article>
340+
<h2>Slider with angular directive inside custom template</h2>
341+
<rzslider
342+
rz-slider-model="slider_custom_directive_inside_template.minValue"
343+
rz-slider-high="slider_custom_directive_inside_template.maxValue"
344+
rz-slider-options="slider_custom_directive_inside_template.options"
345+
rz-slider-tpl-url="directiveInCustomTemplate.html"
346+
></rzslider>
347+
</article>
348+
341349
<article>
342350
<h2>Slider with all options demo</h2>
343351
<div class="row all-options">

dist/rzslider.css

+10-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*! angularjs-slider - v5.5.1 -
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-
2016-09-22 */
4+
2016-10-16 */
55
.rzslider {
66
position: relative;
77
display: inline-block;
@@ -130,23 +130,20 @@
130130
top: -3px;
131131
left: 0;
132132
z-index: 1;
133-
display: -webkit-flex;
134-
display: -ms-flexbox;
135-
display: flex;
136133
width: 100%;
137134
height: 0;
138-
padding: 0 11px;
139135
margin: 0;
140136
list-style: none;
141137
box-sizing: border-box;
142-
-webkit-justify-content: space-between;
143-
-ms-flex-pack: justify;
144-
justify-content: space-between;
145138
}
146139

147140
.rzslider .rz-ticks .rz-tick {
141+
position: absolute;
142+
top: 0;
143+
left: 0;
148144
width: 10px;
149145
height: 10px;
146+
margin-left: 11px;
150147
text-align: center;
151148
cursor: pointer;
152149
background: #d8e0f3;
@@ -173,7 +170,7 @@
173170

174171
.rzslider .rz-ticks.rz-ticks-values-under .rz-tick-value {
175172
top: initial;
176-
bottom: -40px;
173+
bottom: -32px;
177174
}
178175

179176
.rzslider.rz-vertical {
@@ -230,19 +227,17 @@
230227
z-index: 1;
231228
width: 0;
232229
height: 100%;
233-
padding: 11px 0;
234-
-webkit-flex-direction: column-reverse;
235-
-ms-flex-direction: column-reverse;
236-
flex-direction: column-reverse;
237230
}
238231

239232
.rzslider.rz-vertical .rz-ticks .rz-tick {
233+
margin-top: 11px;
234+
margin-left: auto;
240235
vertical-align: middle;
241236
}
242237

243238
.rzslider.rz-vertical .rz-ticks .rz-tick .rz-tick-value {
244239
top: initial;
245-
left: 22px;
240+
left: 24px;
246241
transform: translate(0, -28%);
247242
}
248243

@@ -255,7 +250,7 @@
255250
}
256251

257252
.rzslider.rz-vertical .rz-ticks.rz-ticks-values-under .rz-tick-value {
258-
right: 12px;
253+
right: 24px;
259254
bottom: initial;
260255
left: initial;
261256
}

0 commit comments

Comments
 (0)