Skip to content

Commit

Permalink
add 'direction' kwargs to rangeslider (#174) (#175)
Browse files Browse the repository at this point in the history
* add 'direction' kwargs to rangeslider

* Fix docstring

Co-authored-by: Pietro Vertechi <pietro.vertechi@protonmail.com>

* function signature updated

---------

Co-authored-by: Pietro Vertechi <pietro.vertechi@protonmail.com>
  • Loading branch information
ujimushi and piever committed Mar 22, 2023
1 parent 564eebc commit 0a91fe6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/slider.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,27 @@ end
```
function rangeslider(vals::AbstractArray;
value=medianelement(vals),
label=nothing, readout=true, kwargs...)
label=nothing, readout=true,
orientation="horizontal",
direction="ltr", kwargs...)
```
Creates a slider widget which can take on the values in `vals` and accepts several "handles".
Pass a vector to `value` with two values if you want to select a range.
Use the `orientation="vertical"` keyword argument to create a vertical slider.
By default the slider is top-to-botom and left-to-right,
but this can be changed using the `direction="rtl"` keyword argument.
"""
function rangeslider(theme::WidgetTheme, vals::AbstractUnitRange{<:Integer}, formatted_vals = format.(vals);
style = Dict(), label = nothing, value = medianelement(vals), orientation = "horizontal", readout = true,
className = "is-primary")
className = "is-primary", direction="ltr")

T = Observables.to_value(value) isa Vector ? Vector{eltype(vals)} : eltype(vals)
value isa AbstractObservable || (value = Observable{T}(value))

index = value
orientation = string(orientation)
direction = string(direction)
preprocess = T<:Vector ? js"unencoded.map(Math.round)" : js"Math.round(unencoded[0])"

scp = Scope(imports = vcat([nouislider_min_js, nouislider_min_css], libraries(theme)))
Expand Down Expand Up @@ -122,6 +128,7 @@ function rangeslider(theme::WidgetTheme, vals::AbstractUnitRange{<:Integer}, for
tooltips: $tooltips,
connect: $connect,
orientation: $orientation,
direction: $direction,
format: {
to: function ( value ) {
var ind = Math.round(value-($min));
Expand Down

0 comments on commit 0a91fe6

Please sign in to comment.