From c7f3520ea8fafaffab6e76185e319a73d4e2d9af Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Mon, 23 Nov 2015 22:20:04 -0500 Subject: [PATCH] plotly linestyle/markershape and others --- src/backends/plotly.jl | 34 ++++++++++++++++++++++++++++------ src/backends/supported.jl | 8 +++++--- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 48bb03f0..3771a439 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -105,8 +105,8 @@ function get_plot_html(plt::Plot{PlotlyPackage}) d_out[:title] = d[:title] d_out[:titlefont] = plotlyfont(d[:guidefont]) d_out[:width], d_out[:height] = d[:size] - # d_out[:margin] = Dict(:l=>20, :b=>20, :r=>10, :t=>10) - d_out[:margin] = Dict(:t=>20) + d_out[:margin] = Dict(:l=>30, :b=>30, :r=>15, :t=>15) + # d_out[:margin] = Dict(:t=>20) d_out[:paper_bgcolor] = bgcolor d_out[:plot_bgcolor] = bgcolor @@ -138,7 +138,7 @@ function get_plot_html(plt::Plot{PlotlyPackage}) :bgcolor => bgcolor, :bordercolor => fgcolor, :font => plotlyfont(d[:legendfont]), - :yanchor => "middle", + # :yanchor => "middle", ) end @@ -185,6 +185,14 @@ function plotly_colorscale(grad::ColorGradient) end plotly_colorscale(c) = plotly_colorscale(ColorGradient(:bluesreds)) +const _plotly_markers = Dict( + :rect => "square", + :xcross => "x", + :utriangle => "triangle-up", + :dtriangle => "triangle-down", + :star5 => "star-triangle-up", + ) + # 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() @@ -207,16 +215,20 @@ function get_series_html(d::Dict) 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 @@ -226,11 +238,13 @@ function get_series_html(d::Dict) 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)']] d_out[:colorscale] = plotly_colorscale(d[:linecolor]) + elseif lt == :pie d_out[:type] = "pie" d_out[:labels] = x d_out[:values] = y d_out[:hoverinfo] = "label+percent+name" + else error("Plotly: linetype $lt isn't supported.") end @@ -238,8 +252,8 @@ function get_series_html(d::Dict) # add "marker" if hasmarker d_out[:marker] = Dict( - # :symbol => "circle", - # :opacity => d[:markeropacity], + :symbol => get(_plotly_markers, d[:markershape], string(d[:markershape])), + :opacity => d[:markeralpha], :size => d[:markersize], :color => webcolor(d[:markercolor], d[:markeralpha]), :line => Dict( @@ -249,7 +263,7 @@ function get_series_html(d::Dict) ) if d[:zcolor] != nothing d_out[:marker][:color] = d[:zcolor] - d_out[:marker][:colorscale] = :RdBu # TODO: use the markercolor gradient + d_out[:marker][:colorscale] = plotly_colorscale(d[:markercolor]) end end @@ -258,6 +272,14 @@ function get_series_html(d::Dict) d_out[:line] = Dict( :color => webcolor(d[:linecolor], d[:linealpha]), :width => d[:linewidth], + :shape => if lt == :steppre + "vh" + elseif lt == :steppost + "hv" + else + "linear" + end, + :dash => string(d[:linestyle]), # :dash => "solid", ) end diff --git a/src/backends/supported.jl b/src/backends/supported.jl index 10a8de25..547d95e9 100644 --- a/src/backends/supported.jl +++ b/src/backends/supported.jl @@ -481,9 +481,11 @@ supportedArgs(::PlotlyPackage) = [ :nlevels, ] supportedAxes(::PlotlyPackage) = [:auto, :left] -supportedTypes(::PlotlyPackage) = [:none, :path, :scatter, :heatmap, :hist, :bar, :contour, :pie] #,:steppre, :steppost, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] -supportedStyles(::PlotlyPackage) = [:auto, :solid] #, :dash, :dot, :dashdot, :dashdotdot] -supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse] #, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, :star5] #vcat(_allMarkers, Shape) +supportedTypes(::PlotlyPackage) = [:none, :path, :scatter, :steppre, :steppost, + :heatmap, :hist, :bar, :contour, :pie] #,, :sticks, :heatmap, :hexbin, :hist, :bar, :hline, :vline, :contour] +supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot] +supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross, + :pentagon, :hexagon, :octagon] #vcat(_allMarkers, Shape) supportedScales(::PlotlyPackage) = [:identity, :log] #, :log, :log2, :log10, :asinh, :sqrt] subplotSupported(::PlotlyPackage) = false stringsSupported(::PlotlyPackage) = true