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

Fixes for Julia 0.5 #63

Merged
merged 5 commits into from
Aug 11, 2016
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ os:
- osx
julia:
- release
- 0.5
# - nightly
notifications:
email: false
Expand Down
2 changes: 2 additions & 0 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__precompile__()

module PlotlyJS

using Compat; import Compat.String
Expand Down
18 changes: 13 additions & 5 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# -------------------------- #

prep_kwarg(pair::Union{Pair,Tuple}) =
(symbol(replace(string(pair[1]), "_", ".")), pair[2])
(Symbol(replace(string(pair[1]), "_", ".")), pair[2])
prep_kwargs(pairs::Union{Associative,Vector}) = Dict(map(prep_kwarg, pairs))

"""
Expand Down Expand Up @@ -88,8 +88,13 @@ _prep_restyle_vec_setindex(v, N::Int) = v

function _update_fields(hf::GenericTrace, i::Int, update::Dict=Dict(); kwargs...)
# apply updates in the dict w/out `_` processing
map(p -> _apply_restyle_setindex!(hf.fields, p[1], p[2], i), update)
map(p -> _apply_restyle_setindex!(hf, p[1], p[2], i), kwargs)
for (k,v) in update
_apply_restyle_setindex!(hf.fields, k, v, i)
end
for (k,v) in kwargs
_apply_restyle_setindex!(hf, k, v, i)
end
hf
end

"""
Expand All @@ -99,7 +104,10 @@ Update `l` using update dict and/or kwargs
"""
function relayout!(l::Layout, update::Associative=Dict(); kwargs...)
merge!(l.fields, update) # apply updates in the dict w/out `_` processing
map(x -> setindex!(l, x[2], x[1]), kwargs)
for (k,v) in kwargs
setindex!(l, v, k)
end
l
end

"""
Expand Down Expand Up @@ -135,7 +143,7 @@ Update specific traces at `p.data[inds]` using update dict and/or kwargs
function restyle!(p::Plot, inds::AbstractVector{Int},
update::Associative=Dict(); kwargs...)
N = length(inds)
kw = Dict(kwargs)
kw = Dict{Symbol,Any}(kwargs)

# prepare update and kw dicts for vectorized application
for d in (kw, update)
Expand Down
2 changes: 1 addition & 1 deletion src/json.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Base.print{T<:GenericTrace}(io::IO, a::Vector{T}) = print(io, JSON.json(a))
# methods to re-construct a plot from JSON
_symbol_dict(x) = x
_symbol_dict(d::Associative) =
Dict{Symbol,Any}([(symbol(k), _symbol_dict(v)) for (k, v) in d])
Dict{Symbol,Any}([(Symbol(k), _symbol_dict(v)) for (k, v) in d])

GenericTrace(d::Associative{Symbol}) = GenericTrace(pop!(d, :type, "scatter"), d)
GenericTrace{T<:AbstractString}(d::Associative{T}) = GenericTrace(_symbol_dict(d))
Expand Down
8 changes: 4 additions & 4 deletions src/traces_layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ Base.get(hf::HasFields, k::Symbol, default) = get(hf.fields, k, default)

# methods that allow you to do `obj["first.second.third"] = val`
Base.setindex!(gt::HasFields, val, key::String) =
setindex!(gt, val, map(symbol, split(key, ['.', '_']))...)
setindex!(gt, val, map(Symbol, split(key, ['.', '_']))...)

Base.setindex!(gt::HasFields, val, keys::String...) =
setindex!(gt, val, map(symbol, keys)...)
setindex!(gt, val, map(Symbol, keys)...)

# Now for deep setindex. The deepest the json schema ever goes is 4 levels deep
# so we will simply write out the setindex calls for 4 levels by hand. If the
Expand Down Expand Up @@ -199,10 +199,10 @@ end
# now on to the simpler getindex methods. They will try to get the desired
# key, but if it doesn't exist an empty dict is returned
Base.getindex(gt::HasFields, key::String) =
getindex(gt, map(symbol, split(key, ['.', '_']))...)
getindex(gt, map(Symbol, split(key, ['.', '_']))...)

Base.getindex(gt::HasFields, keys::String...) =
getindex(gt, map(symbol, keys)...)
getindex(gt, map(Symbol, keys)...)

function Base.getindex(gt::HasFields, key::Symbol)
if contains(string(key), "_")
Expand Down