Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiny Cycler fixes #149

Merged
merged 3 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ There are a few built in styles that come with PlotlyJS.jl. More will be added
over time. To see which styles are currently built in look at the unexported
`PlotlyJS.STYLES` variable.

To obtain a built in style use the method `Style(s::Symbol)`, where `s` is one
To obtain a built in style use the method `style(s::Symbol)`, where `s` is one
of the symbols in `PlotlyJS.STYLES`.

To use a built in style globally use the method `use_style!(s::Symbol)`, where
Expand Down
9 changes: 4 additions & 5 deletions src/styles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ struct Cycler
end

Base.isempty(c::Cycler) = isempty(c.vals)
Base.length(c::Cycler) = length(c.vals˚)
Base.length(c::Cycler) = length(c.vals)
Cycler(t::Tuple) = Cycler(collect(t))
Cycler(x::Union{String,Number,Date,Symbol}) = Cycler([x])

function Base.getindex(c::Cycler, ix::Int)
ix < 1 && error("index must be positive")
function Base.getindex(c::Cycler, ix::Integer)
n = length(c.vals)
_i = rem(ix, n)
c.vals[ifelse(_i > 0, _i, n)]
@inbounds v = c.vals[mod1(ix, n)]
v
end

function Base.getindex(c::Cycler, ixs::AbstractVector{<:Integer})
Expand Down
12 changes: 12 additions & 0 deletions test/styles.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
@testset "Cycler" begin
cycl = Cycler([:a, :b, :c])
@test length(cycl) == 3
@test !isempty(cycl)
@test cycl[1] == :a
@test cycl[5] == :b
@test cycl[3:7] == [:c, :a, :b, :c, :a]
@test cycl[0] == :c
@test cycl[-1] == :b
@test cycl[-2:1] == [:a, :b, :c, :a]
end

ps1 = M.Style(layout=M.Layout(font_size=10))
ps2 = M.Style(layout=M.Layout(font_family="Helvetica"))

Expand Down