Skip to content

Commit

Permalink
Add Reexport and Compat dependencies. Some julia 0.7 deprecation fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VPetukhov committed Aug 9, 2018
1 parent bbd1695 commit a2e376b
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 31 deletions.
2 changes: 2 additions & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ Blink 0.3.3
DocStringExtensions
Requires
PlotlyBase 0.1.2
Reexport 0.2.0
Compat 0.69
5 changes: 3 additions & 2 deletions deps/find_attr_groups.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
module AttrGroups

using JSON
using Compat: AbstractDict

_symbol_dict(x) = x
_symbol_dict(d::Associative) =
_symbol_dict(d::AbstractDict) =
Dict{Symbol,Any}([(Symbol(k), _symbol_dict(v)) for (k, v) in d])

function main()

data = _symbol_dict(JSON.parsefile(joinpath(@__DIR__, "plotschema.json")))

nms = Set{Symbol}()
function add_to_names!(d::Associative)
function add_to_names!(d::AbstractDict)
map(add_to_names!, keys(d))
map(add_to_names!, values(d))
nothing
Expand Down
15 changes: 8 additions & 7 deletions deps/make_schema_docs.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module PlotlyJSSchemaDocsGenerator

using Base.Markdown: MD
using Markdown: MD
using JSON
using Compat: AbstractDict

# methods to re-construct a plot from JSON
_symbol_dict(x) = x
_symbol_dict(d::Associative) =
_symbol_dict(d::AbstractDict) =
Dict{Symbol,Any}([(Symbol(k), _symbol_dict(v)) for (k, v) in d])

struct SchemaAttribute
Expand All @@ -16,10 +17,10 @@ struct SchemaAttribute
children::Nullable{Dict{Symbol,SchemaAttribute}}
end

function SchemaAttribute(d::Associative)
function SchemaAttribute(d::AbstractDict)
role = pop!(d, :role, "")

if role == "object" || any(_x->isa(_x, Associative), values(d))
if role == "object" || any(_x->isa(_x, AbstractDict), values(d))
# description and valtype ire empty, but children is not
_desc = pop!(d, :description, "")
desc = isempty(_desc) ? Nullable{MD}() : Nullable{MD}(MD(_desc))
Expand All @@ -29,7 +30,7 @@ function SchemaAttribute(d::Associative)
end
kids = Dict{Symbol,SchemaAttribute}()
for (a_k, v) in d
isa(v, Associative) || continue
isa(v, AbstractDict) || continue
kids[a_k] = SchemaAttribute(v)
end
children = Nullable{Dict{Symbol,SchemaAttribute}}(kids)
Expand Down Expand Up @@ -58,11 +59,11 @@ struct TraceSchema
attributes::Dict{Symbol,SchemaAttribute}
end

function TraceSchema(nm::Symbol, d::Associative, attrs_key=:attributes)
function TraceSchema(nm::Symbol, d::AbstractDict, attrs_key=:attributes)
_attrs = filter!((k, v) -> k != :uid && k != :type, d[attrs_key])
attrs = Dict{Symbol,SchemaAttribute}()
for (k, v) in _attrs
isa(v, Associative) || continue
isa(v, AbstractDict) || continue
attrs[k] = SchemaAttribute(v)
end
desc = get(d, :description, "")
Expand Down
4 changes: 2 additions & 2 deletions docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ two abstract types):
abstract AbstractTrace
abstract AbstractLayout

type GenericTrace{T<:Associative{Symbol,Any}} <: AbstractTrace
type GenericTrace{T<:AbstractDict{Symbol,Any}} <: AbstractTrace
kind::ASCIIString
fields::T
end

type Layout{T<:Associative{Symbol,Any}} <: AbstractLayout
type Layout{T<:AbstractDict{Symbol,Any}} <: AbstractLayout
fields::T
end

Expand Down
6 changes: 3 additions & 3 deletions docs/building_traces_layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ A `Plot` instance will have a vector of `trace`s. These should each be a subtype
PlotlyJS.jl defines one such subtype:

```julia
type GenericTrace{T<:Associative{Symbol,Any}} <: AbstractTrace
type GenericTrace{T<:AbstractDict{Symbol,Any}} <: AbstractTrace
kind::ASCIIString
fields::T
end
```

The `kind` field specifies the type of trace and the `fields` is an Associative object that maps trace attributes to their values.
The `kind` field specifies the type of trace and the `fields` is an AbstractDict object that maps trace attributes to their values.

Let's consider an example. Suppose we would like to build the following JSON
object:
Expand Down Expand Up @@ -239,7 +239,7 @@ julia> println(JSON.json(t1, 2))
The `Layout` type is defined as

```julia
type Layout{T<:Associative{Symbol,Any}} <: AbstractLayout
type Layout{T<:AbstractDict{Symbol,Any}} <: AbstractLayout
fields::T
end
```
Expand Down
1 change: 1 addition & 0 deletions src/PlotlyJS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Reexport
@reexport using PlotlyBase
using JSON
using Base.Iterators
using Compat: AbstractDict

# need to import some functions because methods are meta-generated
import PlotlyBase:
Expand Down
2 changes: 1 addition & 1 deletion src/display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ for f in (:extendtraces!, :prependtraces!)
($f)(p, [ind], maxpoints; update...)
end

function $(f)(p::AbstractPlotlyDisplay, update::Associative, ind::Int,
function $(f)(p::AbstractPlotlyDisplay, update::AbstractDict, ind::Int,
maxpoints=-1)
($f)(p, update, [ind], maxpoints)
end
Expand Down
14 changes: 7 additions & 7 deletions src/displays/electron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,27 +241,27 @@ Blink.js(p::ElectronPlot, code::JSString; callback=true) =
Blink.js(p.view, code; callback=callback)

# Methods from javascript API (docstrings found in api.jl)
function relayout!(p::ElectronDisplay, update::Associative=Dict(); kwargs...)
function relayout!(p::ElectronDisplay, update::AbstractDict=Dict(); kwargs...)
@js_ p begin reset_svg(); Plotly.relayout(this, $(merge(update, prep_kwargs(kwargs)))).then(save_svg) end
end

function restyle!(p::ElectronDisplay, ind::Int, update::Associative=Dict(); kwargs...)
function restyle!(p::ElectronDisplay, ind::Int, update::AbstractDict=Dict(); kwargs...)
@js_ p begin reset_svg(); Plotly.restyle(this, $(merge(update, prep_kwargs(kwargs))), $(ind-1)).then(save_svg) end
end

function restyle!(p::ElectronDisplay, inds::AbstractVector{Int}, update::Associative=Dict(); kwargs...)
function restyle!(p::ElectronDisplay, inds::AbstractVector{Int}, update::AbstractDict=Dict(); kwargs...)
@js_ p begin reset_svg(); Plotly.restyle(this, $(merge(update, prep_kwargs(kwargs))), $(inds-1)).then(save_svg) end
end

function restyle!(p::ElectronDisplay, update=Dict(); kwargs...)
@js_ p begin reset_svg(); Plotly.restyle(this, $(merge(update, prep_kwargs(kwargs)))).then(save_svg) end
end

function update!(p::ElectronDisplay, ind::Int, update::Associative=Dict(); layout::Layout=Layout(), kwargs...)
function update!(p::ElectronDisplay, ind::Int, update::AbstractDict=Dict(); layout::Layout=Layout(), kwargs...)
@js_ p begin reset_svg(); Plotly.update(this, $(merge(update, prep_kwargs(kwargs))), $(layout), $(ind-1)).then(save_svg) end
end

function update!(p::ElectronDisplay, inds::AbstractVector{Int}, update::Associative=Dict(); layout::Layout=Layout(), kwargs...)
function update!(p::ElectronDisplay, inds::AbstractVector{Int}, update::AbstractDict=Dict(); layout::Layout=Layout(), kwargs...)
@js_ p begin reset_svg(); Plotly.update(this, $(merge(update, prep_kwargs(kwargs))), $(layout), $(inds-1)).then(save_svg) end
end

Expand Down Expand Up @@ -306,12 +306,12 @@ function download_image(p::ElectronDisplay; kwargs...)
end

# unexported (by plotly.js) api methods
function extendtraces!(ed::ElectronDisplay, update::Associative=Dict(),
function extendtraces!(ed::ElectronDisplay, update::AbstractDict=Dict(),
indices::Vector{Int}=[1], maxpoints=-1;)
@js_ ed begin reset_svg(); Plotly.extendTraces(this, $(prep_kwargs(update)), $(indices-1), $maxpoints).then(save_svg) end
end

function prependtraces!(ed::ElectronDisplay, update::Associative=Dict(),
function prependtraces!(ed::ElectronDisplay, update::AbstractDict=Dict(),
indices::Vector{Int}=[1], maxpoints=-1;)
@js_ ed begin reset_svg(); Plotly.prependTraces(this, $(prep_kwargs(update)), $(indices-1), $maxpoints).then(save_svg) end
end
18 changes: 9 additions & 9 deletions src/displays/ijulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,36 +148,36 @@ end
# Javascript API methods #
# ---------------------- #

relayout!(jd::JupyterDisplay, update::Associative=Dict(); kwargs...) =
relayout!(jd::JupyterDisplay, update::AbstractDict=Dict(); kwargs...) =
_call_plotlyjs(jd, "relayout", merge(update, prep_kwargs(kwargs)))

restyle!(jd::JupyterDisplay, ind::Int, update::Associative=Dict(); kwargs...) =
restyle!(jd::JupyterDisplay, ind::Int, update::AbstractDict=Dict(); kwargs...) =
_call_plotlyjs(jd, "restyle", merge(update, prep_kwargs(kwargs)), ind-1)

function restyle!(jd::JupyterDisplay, inds::AbstractVector{Int},
update::Associative=Dict(); kwargs...)
update::AbstractDict=Dict(); kwargs...)
_call_plotlyjs(jd, "restyle", merge(update, prep_kwargs(kwargs)), inds-1)
end

restyle!(jd::JupyterDisplay, update::Associative=Dict(); kwargs...) =
restyle!(jd::JupyterDisplay, update::AbstractDict=Dict(); kwargs...) =
_call_plotlyjs(jd, "restyle", merge(update, prep_kwargs(kwargs)))

function update!(
jd::JupyterDisplay, ind::Int, update::Associative=Dict();
jd::JupyterDisplay, ind::Int, update::AbstractDict=Dict();
layout::Layout=Layout(), kwargs...
)
_call_plotlyjs(jd, "update", merge(update, prep_kwargs(kwargs)), layout, ind-1)
end

function update!(
jd::JupyterDisplay, inds::AbstractVector{Int},
update::Associative=Dict(); layout::Layout=Layout(), kwargs...
update::AbstractDict=Dict(); layout::Layout=Layout(), kwargs...
)
_call_plotlyjs(jd, "update", merge(update, prep_kwargs(kwargs)), layout, inds-1)
end

function update!(
jd::JupyterDisplay, update::Associative=Dict();
jd::JupyterDisplay, update::AbstractDict=Dict();
layout::Layout=Layout(), kwargs...
)
_call_plotlyjs(jd, "update", merge(update, prep_kwargs(kwargs)), layout)
Expand Down Expand Up @@ -208,11 +208,11 @@ download_image(jd::JupyterDisplay; kwargs...) =
_call_plotlyjs(jd, "download_image", Dict(kwargs))

# unexported (by plotly.js) api methods
extendtraces!(jd::JupyterDisplay, update::Associative=Dict(),
extendtraces!(jd::JupyterDisplay, update::AbstractDict=Dict(),
indices::Vector{Int}=[1], maxpoints=-1;) =
_call_plotlyjs(jd, "extendTraces", update, indices-1, maxpoints)

prependtraces!(jd::JupyterDisplay, update::Associative=Dict(),
prependtraces!(jd::JupyterDisplay, update::AbstractDict=Dict(),
indices::Vector{Int}=[1], maxpoints=-1;) =
_call_plotlyjs(jd, "prependTraces", update, indices-1, maxpoints)

Expand Down

0 comments on commit a2e376b

Please sign in to comment.