From 5ed913ba5e9e4e8b018a0cb79654e78c9b53d1b7 Mon Sep 17 00:00:00 2001 From: Thomas Breloff Date: Fri, 30 Sep 2016 11:25:29 -0400 Subject: [PATCH] plotly: plotly_surface_data and wireframes; closes #479 --- src/backends/plotly.jl | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index d06864af..de30acd3 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -33,7 +33,7 @@ const _plotly_attr = merge_with_base_supported([ const _plotly_seriestype = [ :path, :scatter, :bar, :pie, :heatmap, - :contour, :surface, :path3d, :scatter3d, :shape, :scattergl, + :contour, :surface, :wireframe, :path3d, :scatter3d, :shape, :scattergl, ] const _plotly_style = [:auto, :solid, :dash, :dot, :dashdot] const _plotly_marker = [ @@ -343,6 +343,10 @@ plotly_data(v) = collect(v) plotly_data(surf::Surface) = surf.surf plotly_data{R<:Rational}(v::AbstractArray{R}) = float(v) +plotly_surface_data(series::Series, a::AbstractVector) = a +plotly_surface_data(series::Series, a::AbstractMatrix) = transpose_z(series, a, false) +plotly_surface_data(series::Series, a::Surface) = plotly_surface_data(series, a.surf) + # get a dictionary representing the series params (d is the Plots-dict, d_out is the Plotly-dict) function plotly_series(plt::Plot, series::Series) st = series[:seriestype] @@ -366,6 +370,13 @@ function plotly_series(plt::Plot, series::Series) hasmarker = isscatter || series[:markershape] != :none hasline = st in (:path, :path3d) + # for surface types, set the data + if st in (:heatmap, :contour, :surface, :wireframe) + for letter in [:x,:y,:z] + d_out[letter] = plotly_surface_data(series, series[letter]) + end + end + # set the "type" if st in (:path, :scatter, :scattergl) d_out[:type] = st==:scattergl ? "scattergl" : "scatter" @@ -390,12 +401,12 @@ function plotly_series(plt::Plot, series::Series) elseif st == :heatmap d_out[:type] = "heatmap" - d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) + # d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha]) elseif st == :contour d_out[:type] = "contour" - d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) + # d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) # d_out[:showscale] = series[:colorbar] != :none d_out[:ncontours] = series[:levels] d_out[:contours] = KW(:coloring => series[:fillrange] != nothing ? "fill" : "lines") @@ -403,8 +414,18 @@ function plotly_series(plt::Plot, series::Series) elseif st in (:surface, :wireframe) d_out[:type] = "surface" - d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) - d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha]) + # d_out[:x], d_out[:y], d_out[:z] = series[:x], series[:y], transpose_z(series, series[:z].surf, false) + if st == :wireframe + d_out[:hidesurface] = true + wirelines = KW( + :show => true, + :color => rgba_string(series[:linecolor]), + :highlightwidth => series[:linewidth], + ) + d_out[:contours] = KW(:x => wirelines, :y => wirelines, :z => wirelines) + else + d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha]) + end elseif st == :pie d_out[:type] = "pie"