diff --git a/src/args.jl b/src/args.jl index 509c2af3..979361ae 100644 --- a/src/args.jl +++ b/src/args.jl @@ -133,8 +133,9 @@ _seriesDefaults[:x] = nothing _seriesDefaults[:y] = nothing _seriesDefaults[:z] = nothing # depth for contour, surface, etc _seriesDefaults[:zcolor] = nothing # value for color scale -_seriesDefaults[:surface] = nothing +# _seriesDefaults[:surface] = nothing _seriesDefaults[:nlevels] = 15 +_seriesDefaults[:orientation] = :vertical const _plotDefaults = Dict{Symbol, Any}() diff --git a/src/backends/gadfly.jl b/src/backends/gadfly.jl index bcde38a0..f4a4e93e 100644 --- a/src/backends/gadfly.jl +++ b/src/backends/gadfly.jl @@ -120,7 +120,7 @@ function addGadflyLine!(plt::Plot, numlayers::Int, d::Dict, geoms...) kwargs[:xmax] = d[:x] + w elseif lt == :contour # d[:y] = reverse(d[:y]) - kwargs[:z] = d[:surface].surf + kwargs[:z] = d[:z].surf addGadflyContColorScale(plt, d[:linecolor]) end diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index dff1e3c2..ae243f42 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -175,55 +175,87 @@ end # _seriesDefaults[:surface] = nothing # _seriesDefaults[:nlevels] = 15 -function get_series_html(plt::Plot{PlotlyPackage}) - JSON.json([begin - d_out = Dict() +# supportedTypes(::PyPlotPackage) = [:none, :line, :path, :steppre, :steppost, :sticks, +# :scatter, :heatmap, :hexbin, :hist, :density, :bar, +# :hline, :vline, :contour, :path3d, :scatter3d] - # TODO: set the fields for each series - d_out[:x] = collect(d[:x]) - d_out[:y] = collect(d[:y]) - d_out[:name] = d[:label] +# get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict) +function get_series_html(d::Dict) + d_out = Dict() - lt = d[:linetype] - if lt in (:line, :path, :scatter, :steppre, :steppost) - d_out[:type] = "scatter" - end + x, y = collect(d[:x]), collect(d[:y]) + # d_out[:x] = collect(d[:x]) + # d_out[:y] = collect(d[:y]) + d_out[:name] = d[:label] - hasmarker = lt == :scatter || d[:markershape] != :none - hasline = lt != :scatter + lt = d[:linetype] + 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 hasline ? "lines+markers" : "markers" else hasline ? "lines" : "none" 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 - d_out[:marker] = Dict( - # :symbol => "circle", - # :opacity => d[:markeropacity], - :size => d[:markersize], - :color => webcolor(d[:markercolor], d[:markeralpha]), - :line => Dict( - :color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]), - :width => d[:markerstrokewidth], - ), - ) - if d[:zcolor] != nothing - d_out[:marker][:color] = d[:zcolor] - d_out[:marker][:colorscale] = :RdBu # TODO: use the markercolor gradient - end + # add "marker" + if hasmarker + d_out[:marker] = Dict( + # :symbol => "circle", + # :opacity => d[:markeropacity], + :size => d[:markersize], + :color => webcolor(d[:markercolor], d[:markeralpha]), + :line => Dict( + :color => webcolor(d[:markerstrokecolor], d[:markerstrokealpha]), + :width => d[:markerstrokewidth], + ), + ) + if d[:zcolor] != nothing + d_out[:marker][:color] = d[:zcolor] + d_out[:marker][:colorscale] = :RdBu # TODO: use the markercolor gradient end + end - if hasline - d_out[:line] = Dict( - :color => webcolor(d[:linecolor], d[:linealpha]), - :width => d[:linewidth], - # :dash => "solid", - ) - end - - d_out - end for d in plt.seriesargs]) + # add "line" + if hasline + d_out[:line] = Dict( + :color => webcolor(d[:linecolor], d[:linealpha]), + :width => d[:linewidth], + # :dash => "solid", + ) + end + + 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 # ---------------------------------------------------------------- @@ -249,6 +281,12 @@ end function Base.writemime(io::IO, ::MIME"image/png", plt::PlottingObject{PlotlyPackage}) # 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 function Base.display(::PlotsDisplay, plt::Plot{PlotlyPackage}) diff --git a/src/backends/pyplot.jl b/src/backends/pyplot.jl index 4767eeaf..81a4d93c 100644 --- a/src/backends/pyplot.jl +++ b/src/backends/pyplot.jl @@ -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), # and take the transpose of the surface matrix x, y = d[:x], d[:y] - surf = d[:surface].surf' + surf = d[:z].surf' handle = plotfunc(x, y, surf, d[:nlevels]; extra_kwargs...) if d[:fillrange] != nothing handle = ax[:contourf](x, y, surf, d[:nlevels]; cmap = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])) diff --git a/src/backends/supported.jl b/src/backends/supported.jl index a6926f8e..5e11bdb1 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -71,7 +71,7 @@ supportedArgs(::GadflyPackage) = [ :guidefont, :legendfont, :grid, - :surface, + # :surface, :nlevels, ] supportedAxes(::GadflyPackage) = [:auto, :left] @@ -151,7 +151,7 @@ supportedArgs(::PyPlotPackage) = [ :guidefont, :legendfont, :grid, - :surface, + # :surface, :nlevels, :fillalpha, :linealpha, diff --git a/src/backends/web.jl b/src/backends/web.jl index c4fb48c8..a123c2b4 100644 --- a/src/backends/web.jl +++ b/src/backends/web.jl @@ -3,21 +3,6 @@ # CREDIT: parts of this implementation were inspired by @joshday's PlotlyLocal.jl -using JSON - -# const _html_template = mt""" -# -# -# -# {{:title}} -# {{:head}} -# -# -# {{:body}} -# -# -# """ - function standalone_html(plt::PlottingObject; title::AbstractString = get(plt.plotargs, :window_title, "Plots.jl")) """ diff --git a/src/plot.jl b/src/plot.jl index e65556d1..b3d92330 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -369,7 +369,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat:: surf = Surface(convert(Matrix{Float64}, zmat)) # surf = Array(Any,1,1) # 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 function createKWargsList(plt::PlottingObject, surf::Surface; kw...) diff --git a/src/plotter.jl b/src/plotter.jl index 261cfe03..ebbb1f7f 100644 --- a/src/plotter.jl +++ b/src/plotter.jl @@ -48,8 +48,10 @@ include("backends/unicodeplots.jl") include("backends/pyplot.jl") include("backends/immerse.jl") include("backends/winston.jl") + +include("backends/web.jl") include("backends/bokeh.jl") -# include("backends/plotly.jl") +include("backends/plotly.jl") # --------------------------------------------------------- @@ -236,8 +238,9 @@ function backend() elseif currentBackendSymbol == :plotly try - @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", "web.jl")) + # @eval include(joinpath(Pkg.dir("Plots"), "src", "backends", "plotly.jl")) + @eval import JSON catch err warn("Couldn't setup Plotly") rethrow(err)