added ribbon to plotly

This commit is contained in:
Pietro Vertechi 2017-08-19 10:34:06 +01:00
parent b585a0ef61
commit eea30fa253
2 changed files with 27 additions and 7 deletions

View File

@ -438,7 +438,8 @@ function plotly_series(plt::Plot, series::Series)
isscatter = st in (:scatter, :scatter3d, :scattergl) isscatter = st in (:scatter, :scatter3d, :scattergl)
hasmarker = isscatter || series[:markershape] != :none hasmarker = isscatter || series[:markershape] != :none
hasline = st in (:path, :path3d) hasline = st in (:path, :path3d)
hasfillrange = st in (:path, :scatter, :scattergl) && isa(series[:fillrange], AbstractVector) hasfillrange = st in (:path, :scatter, :scattergl) &&
(isa(series[:fillrange], AbstractVector) || isa(series[:fillrange], Tuple))
# for surface types, set the data # for surface types, set the data
if st in (:heatmap, :contour, :surface, :wireframe) if st in (:heatmap, :contour, :surface, :wireframe)
@ -462,7 +463,7 @@ function plotly_series(plt::Plot, series::Series)
else else
hasline ? "lines" : "none" hasline ? "lines" : "none"
end end
if series[:fillrange] == true || series[:fillrange] == 0 if series[:fillrange] == true || series[:fillrange] == 0 || isa(series[:fillrange], Tuple)
d_out[:fill] = "tozeroy" d_out[:fill] = "tozeroy"
d_out[:fillcolor] = rgba_string(series[:fillcolor]) d_out[:fillcolor] = rgba_string(series[:fillcolor])
elseif isa(series[:fillrange], AbstractVector) elseif isa(series[:fillrange], AbstractVector)
@ -587,11 +588,22 @@ function plotly_series(plt::Plot, series::Series)
if hasfillrange if hasfillrange
# if hasfillrange is true, return two dictionaries (one for original # if hasfillrange is true, return two dictionaries (one for original
# series, one for series being filled to) instead of one # series, one for series being filled to) instead of one
d_out_fillrange = copy(d_out) d_out_fillrange = deepcopy(d_out)
d_out_fillrange[:y] = series[:fillrange] if isa(series[:fillrange], AbstractVector)
d_out_fillrange[:showlegend] = false d_out_fillrange[:y] = series[:fillrange]
delete!(d_out_fillrange, :fill) d_out_fillrange[:showlegend] = false
delete!(d_out_fillrange, :fillcolor) delete!(d_out_fillrange, :fill)
delete!(d_out_fillrange, :fillcolor)
else
# if fillrange is a tuple with upper and lower limit, d_out_fillrange
# is the series that will do the filling
d_out_fillrange[:x], d_out_fillrange[:y] =
concatenate_fillrange(series[:x], series[:fillrange])
d_out_fillrange[:line][:width] = 0
d_out[:showlegend] = false
delete!(d_out, :fill)
delete!(d_out, :fillcolor)
end
return [d_out_fillrange, d_out] return [d_out_fillrange, d_out]
else else

View File

@ -498,6 +498,14 @@ function make_fillrange_from_ribbon(kw::KW)
kw[:fillrange] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2) kw[:fillrange] = make_fillrange_side(y, rib1), make_fillrange_side(y, rib2)
end end
#turn tuple of fillranges to one path
function concatenate_fillrange(x,y::Tuple)
rib1, rib2 = first(y), last(y)
yline = vcat(rib1,(rib2)[end:-1:1])
xline = vcat(x,x[end:-1:1])
return xline, yline
end
function get_sp_lims(sp::Subplot, letter::Symbol) function get_sp_lims(sp::Subplot, letter::Symbol)
axis_limits(sp[Symbol(letter, :axis)]) axis_limits(sp[Symbol(letter, :axis)])
end end