fix ribbons (#2853)

* fix ribbons

* fix tests
This commit is contained in:
Simon Christ 2020-07-09 12:23:27 +02:00 committed by GitHub
parent 0d776fd09d
commit 1ab681f509
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 24 deletions

View File

@ -344,8 +344,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end end
# add fillrange # add fillrange
if sf !== nothing && if sf !== nothing &&
!isfilledcontour(series) && !isfilledcontour(series)
series[:ribbon] === nothing
if sf isa Number || sf isa AVec if sf isa Number || sf isa AVec
pgfx_fillrange_series!( pgfx_fillrange_series!(
axis, axis,
@ -355,6 +354,17 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
_cycle(sf, rng), _cycle(sf, rng),
rng, rng,
) )
elseif sf isa Tuple
for sfi in sf
pgfx_fillrange_series!(
axis,
series,
series_func,
i,
_cycle(sfi, rng),
rng,
)
end
end end
if i == 1 && if i == 1 &&
sp[:legend] != :none && pgfx_should_add_to_legend(series) sp[:legend] != :none && pgfx_should_add_to_legend(series)
@ -384,17 +394,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
), ),
) )
end end
# add ribbons?
ribbon = series[:ribbon]
if ribbon !== nothing
pgfx_add_ribbons!(
axis,
series,
segment_plot,
series_func,
series_index,
)
end
# add to legend? # add to legend?
if sp[:legend] != :none if sp[:legend] != :none
leg_entry = if opt[:label] isa AVec leg_entry = if opt[:label] isa AVec
@ -412,9 +411,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
push!(axis.contents[end].options, "forget plot" => nothing) push!(axis.contents[end].options, "forget plot" => nothing)
else else
leg_opt = PGFPlotsX.Options() leg_opt = PGFPlotsX.Options()
if ribbon !== nothing
pgfx_filllegend!(axis.contents[end - 3].options, opt)
end
legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false) legend = PGFPlotsX.LegendEntry(leg_opt, leg_entry, false)
push!(axis, legend) push!(axis, legend)
end end

View File

@ -314,16 +314,12 @@ end
Plots._update_plot_object(ribbon_plot) Plots._update_plot_object(ribbon_plot)
axis = Plots.pgfx_axes(ribbon_plot.o)[1] axis = Plots.pgfx_axes(ribbon_plot.o)[1]
plots = filter(x -> x isa PGFPlotsX.Plot, axis.contents) plots = filter(x -> x isa PGFPlotsX.Plot, axis.contents)
@test length(plots) == 4 @test length(plots) == 3
@test !haskey(plots[1].options.dict, "fill") @test haskey(plots[1].options.dict, "fill")
@test !haskey(plots[2].options.dict, "fill") @test haskey(plots[2].options.dict, "fill")
@test !haskey(plots[3].options.dict, "fill") @test !haskey(plots[3].options.dict, "fill")
@test haskey(plots[4].options.dict, "fill")
@test ribbon_plot.o !== nothing @test ribbon_plot.o !== nothing
@test ribbon_plot.o.the_plot !== nothing @test ribbon_plot.o.the_plot !== nothing
# mktempdir() do path
# @test_nowarn savefig(ribbon_plot, path*"ribbon.svg")
# end
end # testset end # testset
end # testset end # testset