diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 46c25949..dff1e3c2 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -180,8 +180,46 @@ function get_series_html(plt::Plot{PlotlyPackage}) d_out = Dict() # TODO: set the fields for each series - for k in (:x, :y) - d_out[k] = collect(d[k]) + d_out[:x] = collect(d[:x]) + d_out[:y] = collect(d[:y]) + d_out[:name] = d[:label] + + lt = d[:linetype] + if lt in (:line, :path, :scatter, :steppre, :steppost) + d_out[:type] = "scatter" + end + + hasmarker = lt == :scatter || d[:markershape] != :none + hasline = lt != :scatter + d_out[:mode] = if hasmarker + hasline ? "lines+markers" : "markers" + else + hasline ? "lines" : "none" + 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 + end + + if hasline + d_out[:line] = Dict( + :color => webcolor(d[:linecolor], d[:linealpha]), + :width => d[:linewidth], + # :dash => "solid", + ) end d_out diff --git a/src/colors.jl b/src/colors.jl index 9a98ed3c..2de46a89 100644 --- a/src/colors.jl +++ b/src/colors.jl @@ -332,6 +332,7 @@ function webcolor(c::Colorant) @sprintf("rgba(%d, %d, %d, %1.3f)", [make255(f(c)) for f in [red,green,blue]]..., alpha(c)) end webcolor(cs::ColorScheme) = webcolor(getColor(cs)) +webcolor(c, α) = webcolor(convertColor(getColor(c), α)) # ----------------------------------------------------------------------------------