Skip to content

Commit d1c38c2

Browse files
author
Pietro Vertechi
authored
Merge pull request #143 from piever/pv/slider
Fix slider
2 parents 5bcc557 + 4bcd597 commit d1c38c2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/slider.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,21 @@ function slider(vals::AbstractArray;
4242
Creates a slider widget which can take on the values in `vals`, and updates
4343
observable `value` when the slider is changed.
4444
"""
45-
function slider(::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_vals;
45+
function slider(::WidgetTheme, vals::AbstractUnitRange{<:Integer}, formatted_vals = format.(vals);
4646
className=getclass(:input, "range", "fullwidth"),
4747
readout=true, label=nothing, value=medianelement(vals), orientation = "horizontal", attributes = Dict(), kwargs...)
4848

49+
min, max = extrema(vals)
4950
orientation = string(orientation)
5051
attributes = merge(attributes, Dict("orient" => orientation))
5152
(value isa AbstractObservable) || (value = convert(eltype(vals), value))
5253
format = js"""
5354
function(){
54-
return this.formatted_vals()[parseInt(this.index())-1];
55+
return this.formatted_vals()[parseInt(this.index())-$min];
5556
}
5657
"""
5758
ui = input(value; bindto="index", attributes=attributes, extra_obs = ["formatted_vals" => formatted_vals], computed = ["formatted_val" => format],
58-
typ="range", min=minimum(vals), max=maximum(vals), step=step(vals), className=className, kwargs...)
59+
typ="range", min=min, max=max, step=1, className=className, kwargs...)
5960
if (label != nothing) || readout
6061
if orientation != "vertical"
6162
Widgets.scope(ui).dom = readout ?
@@ -79,7 +80,7 @@ function rangeslider(vals::AbstractArray;
7980
Creates a slider widget which can take on the values in `vals` and accepts several "handles".
8081
Pass a vector to `value` with two values if you want to select a range.
8182
"""
82-
function rangeslider(theme::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_vals = format.(vals);
83+
function rangeslider(theme::WidgetTheme, vals::AbstractUnitRange{<:Integer}, formatted_vals = format.(vals);
8384
style = Dict(), label = nothing, value = medianelement(vals), orientation = "horizontal", readout = true,
8485
className = "is-primary")
8586

@@ -117,13 +118,13 @@ function rangeslider(theme::WidgetTheme, vals::AbstractRange{<:Integer}, formatt
117118
var slider = document.getElementById($id);
118119
noUiSlider.create(slider, {
119120
start: $start,
120-
step: $s,
121+
step: 1,
121122
tooltips: $tooltips,
122123
connect: $connect,
123124
orientation: $orientation,
124125
format: {
125126
to: function ( value ) {
126-
var ind = Math.round((value-$min)/$s);
127+
var ind = Math.round(value-$min);
127128
return ind + 1 > vals.length ? vals[vals.length - 1] : vals[ind];
128129
},
129130
from: function ( value ) {

0 commit comments

Comments
 (0)