surface arg is now z; added orientation arg; working on plotly
This commit is contained in:
parent
1db2d8d8d8
commit
4b1f127eaf
@ -133,8 +133,9 @@ _seriesDefaults[:x] = nothing
|
|||||||
_seriesDefaults[:y] = nothing
|
_seriesDefaults[:y] = nothing
|
||||||
_seriesDefaults[:z] = nothing # depth for contour, surface, etc
|
_seriesDefaults[:z] = nothing # depth for contour, surface, etc
|
||||||
_seriesDefaults[:zcolor] = nothing # value for color scale
|
_seriesDefaults[:zcolor] = nothing # value for color scale
|
||||||
_seriesDefaults[:surface] = nothing
|
# _seriesDefaults[:surface] = nothing
|
||||||
_seriesDefaults[:nlevels] = 15
|
_seriesDefaults[:nlevels] = 15
|
||||||
|
_seriesDefaults[:orientation] = :vertical
|
||||||
|
|
||||||
|
|
||||||
const _plotDefaults = Dict{Symbol, Any}()
|
const _plotDefaults = Dict{Symbol, Any}()
|
||||||
|
|||||||
@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...)
|
|||||||
kwargs[:xmax] = d[:x] + w
|
kwargs[:xmax] = d[:x] + w
|
||||||
elseif lt == :contour
|
elseif lt == :contour
|
||||||
# d[:y] = reverse(d[:y])
|
# d[:y] = reverse(d[:y])
|
||||||
kwargs[:z] = d[:surface].surf
|
kwargs[:z] = d[:z].surf
|
||||||
addGadflyContColorScale(plt, d[:linecolor])
|
addGadflyContColorScale(plt, d[:linecolor])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -175,55 +175,87 @@ end
|
|||||||
# _seriesDefaults[:surface] = nothing
|
# _seriesDefaults[:surface] = nothing
|
||||||
# _seriesDefaults[:nlevels] = 15
|
# _seriesDefaults[:nlevels] = 15
|
||||||
|
|
||||||
function get_series_html(plt::Plot{PlotlyPackage})
|
# supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks,
|
||||||
JSON.json([begin
|
# :scatter, :heatmap, :hexbin, :hist, :density, :bar,
|
||||||
d_out = Dict()
|
# :hline, :vline, :contour, :path3d, :scatter3d]
|
||||||
|
|
||||||
# TODO: set the fields for each series
|
# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict)
|
||||||
d_out[:x] = collect(d[:x])
|
function get_series_html(d::Dict)
|
||||||
d_out[:y] = collect(d[:y])
|
d_out = Dict()
|
||||||
d_out[:name] = d[:label]
|
|
||||||
|
|
||||||
lt = d[:linetype]
|
x, y = collect(d[:x]), collect(d[:y])
|
||||||
if lt in (:line, :path, :scatter, :steppre, :steppost)
|
# d_out[:x] = collect(d[:x])
|
||||||
d_out[:type] = "scatter"
|
# d_out[:y] = collect(d[:y])
|
||||||
end
|
d_out[:name] = d[:label]
|
||||||
|
|
||||||
hasmarker = lt == :scatter || d[:markershape] != :none
|
lt = d[:linetype]
|
||||||
hasline = lt != :scatter
|
hasmarker = lt == :scatter || d[:markershape] != :none
|
||||||
|
hasline = lt != :scatter
|
||||||
|
|
||||||
|
# set the "type"
|
||||||
|
if lt in (:line, :path, :scatter, :steppre, :steppost)
|
||||||
|
d_out[:type] = "scatter"
|
||||||
d_out[:mode] = if hasmarker
|
d_out[:mode] = if hasmarker
|
||||||
hasline ? "lines+markers" : "markers"
|
hasline ? "lines+markers" : "markers"
|
||||||
else
|
else
|
||||||
hasline ? "lines" : "none"
|
hasline ? "lines" : "none"
|
||||||
end
|
end
|
||||||
|
d_out[:x], d_out[:y] = x, y
|
||||||
|
elseif lt == :bar
|
||||||
|
d_out[:type] = "bar"
|
||||||
|
d_out[:x], d_out[:y] = x, y
|
||||||
|
elseif lt == :heatmap
|
||||||
|
d_out[:type] = "heatmap"
|
||||||
|
d_out[:x], d_out[:y] = x, y
|
||||||
|
elseif lt == :hist
|
||||||
|
d_out[:type] = "histogram"
|
||||||
|
isvert = d[:orientation] in (:vertical, :v, :vert)
|
||||||
|
d_out[isvert ? :x : :y] = y
|
||||||
|
elseif lt == :contour
|
||||||
|
d_out[:type] = "contour"
|
||||||
|
d_out[:x], d_out[:y] = x, y
|
||||||
|
d_out[:z] = d[:z].surf
|
||||||
|
# d_out[:showscale] = d[:legend]
|
||||||
|
d_out[:ncontours] = d[:nlevels]
|
||||||
|
d_out[:contours] = Dict(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||||
|
# TODO: colorscale: [[0, 'rgb(166,206,227)'], [0.25, 'rgb(31,120,180)'], [0.45, 'rgb(178,223,138)'], [0.65, 'rgb(51,160,44)'], [0.85, 'rgb(251,154,153)'], [1, 'rgb(227,26,28)']]
|
||||||
|
else
|
||||||
|
error("Plotly: linetype $lt isn't supported.")
|
||||||
|
end
|
||||||
|
|
||||||
if hasmarker
|
# add "marker"
|
||||||
d_out[:marker] = Dict(
|
if hasmarker
|
||||||
# :symbol => "circle",
|
d_out[:marker] = Dict(
|
||||||
# :opacity => d[:markeropacity],
|
# :symbol => "circle",
|
||||||
:size => d[:markersize],
|
# :opacity => d[:markeropacity],
|
||||||
:color => webcolor(d[:markercolor], d[:markeralpha]),
|
:size => d[:markersize],
|
||||||
:line => Dict(
|
:color => webcolor(d[:markercolor], d[:markeralpha]),
|
||||||
:color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]),
|
:line => Dict(
|
||||||
:width => d[:markerstrokewidth],
|
:color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]),
|
||||||
),
|
:width => d[:markerstrokewidth],
|
||||||
)
|
),
|
||||||
if d[:zcolor] != nothing
|
)
|
||||||
d_out[:marker][:color] = d[:zcolor]
|
if d[:zcolor] != nothing
|
||||||
d_out[:marker][:colorscale] = :RdBu # TODO: use the markercolor gradient
|
d_out[:marker][:color] = d[:zcolor]
|
||||||
end
|
d_out[:marker][:colorscale] = :RdBu # TODO: use the markercolor gradient
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if hasline
|
# add "line"
|
||||||
d_out[:line] = Dict(
|
if hasline
|
||||||
:color => webcolor(d[:linecolor], d[:linealpha]),
|
d_out[:line] = Dict(
|
||||||
:width => d[:linewidth],
|
:color => webcolor(d[:linecolor], d[:linealpha]),
|
||||||
# :dash => "solid",
|
:width => d[:linewidth],
|
||||||
)
|
# :dash => "solid",
|
||||||
end
|
)
|
||||||
|
end
|
||||||
d_out
|
|
||||||
end for d in plt.seriesargs])
|
d_out
|
||||||
|
end
|
||||||
|
|
||||||
|
# get a list of dictionaries, each representing the series params
|
||||||
|
function get_series_html(plt::Plot{PlotlyPackage})
|
||||||
|
JSON.json(map(get_series_html, plt.seriesargs))
|
||||||
end
|
end
|
||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
@ -249,6 +281,12 @@ end
|
|||||||
|
|
||||||
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage})
|
function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage})
|
||||||
# TODO: write a png to io
|
# TODO: write a png to io
|
||||||
|
println("png")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.writemime(io::IO, ::MIME"text/html", plt::PlottingObject{PlotlyPackage})
|
||||||
|
println("html")
|
||||||
|
html_head(plt) * html_body(plt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage})
|
function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage})
|
||||||
|
|||||||
@ -320,7 +320,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
|||||||
# NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed),
|
# NOTE: x/y are backwards in pyplot, so we switch the x and y args (also y is reversed),
|
||||||
# and take the transpose of the surface matrix
|
# and take the transpose of the surface matrix
|
||||||
x, y = d[:x], d[:y]
|
x, y = d[:x], d[:y]
|
||||||
surf = d[:surface].surf'
|
surf = d[:z].surf'
|
||||||
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
|
handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...)
|
||||||
if d[:fillrange] != nothing
|
if d[:fillrange] != nothing
|
||||||
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
|
handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha]))
|
||||||
|
|||||||
@ -71,7 +71,7 @@ supportedArgs(::GadflyPackage) = [
|
|||||||
:guidefont,
|
:guidefont,
|
||||||
:legendfont,
|
:legendfont,
|
||||||
:grid,
|
:grid,
|
||||||
:surface,
|
# :surface,
|
||||||
:nlevels,
|
:nlevels,
|
||||||
]
|
]
|
||||||
supportedAxes(::GadflyPackage) = [:auto, :left]
|
supportedAxes(::GadflyPackage) = [:auto, :left]
|
||||||
@ -151,7 +151,7 @@ supportedArgs(::PyPlotPackage) = [
|
|||||||
:guidefont,
|
:guidefont,
|
||||||
:legendfont,
|
:legendfont,
|
||||||
:grid,
|
:grid,
|
||||||
:surface,
|
# :surface,
|
||||||
:nlevels,
|
:nlevels,
|
||||||
:fillalpha,
|
:fillalpha,
|
||||||
:linealpha,
|
:linealpha,
|
||||||
|
|||||||
@ -3,21 +3,6 @@
|
|||||||
|
|
||||||
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
|
# CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl
|
||||||
|
|
||||||
using JSON
|
|
||||||
|
|
||||||
# const _html_template = mt"""
|
|
||||||
# <!DOCTYPE html>
|
|
||||||
# <html>
|
|
||||||
# <head>
|
|
||||||
# <title>{{:title}}</title>
|
|
||||||
# {{:head}}
|
|
||||||
# </head>
|
|
||||||
# <body>
|
|
||||||
# {{:body}}
|
|
||||||
# </body>
|
|
||||||
# </html>
|
|
||||||
# """
|
|
||||||
|
|
||||||
|
|
||||||
function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl"))
|
function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl"))
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -369,7 +369,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
|
|||||||
surf = Surface(convert(Matrix{Float64}, zmat))
|
surf = Surface(convert(Matrix{Float64}, zmat))
|
||||||
# surf = Array(Any,1,1)
|
# surf = Array(Any,1,1)
|
||||||
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
||||||
createKWargsList(plt, x, y; kw..., surface = surf, linetype = :contour)
|
createKWargsList(plt, x, y; kw..., z = surf, linetype = :contour)
|
||||||
end
|
end
|
||||||
|
|
||||||
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)
|
function createKWargsList(plt::PlottingObject, surf::Surface; kw...)
|
||||||
|
|||||||
@ -48,8 +48,10 @@ include("backends/unicodeplots.jl")
|
|||||||
include("backends/pyplot.jl")
|
include("backends/pyplot.jl")
|
||||||
include("backends/immerse.jl")
|
include("backends/immerse.jl")
|
||||||
include("backends/winston.jl")
|
include("backends/winston.jl")
|
||||||
|
|
||||||
|
include("backends/web.jl")
|
||||||
include("backends/bokeh.jl")
|
include("backends/bokeh.jl")
|
||||||
# include("backends/plotly.jl")
|
include("backends/plotly.jl")
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
@ -236,8 +238,9 @@ function backend()
|
|||||||
|
|
||||||
elseif currentBackendSymbol == :plotly
|
elseif currentBackendSymbol == :plotly
|
||||||
try
|
try
|
||||||
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl"))
|
# @eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "web.jl"))
|
||||||
@eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl"))
|
# @eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl"))
|
||||||
|
@eval import JSON
|
||||||
catch err
|
catch err
|
||||||
warn("Couldn't setup Plotly")
|
warn("Couldn't setup Plotly")
|
||||||
rethrow(err)
|
rethrow(err)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user