fix legends for arrows

This commit is contained in:
Simon Christ 2022-03-29 16:07:37 +02:00
parent 0f4a0c7154
commit da002e34ac
2 changed files with 13 additions and 2 deletions

View File

@ -403,6 +403,11 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o
),
),
)
if opt[:label] == ""
push!(arrow_opt,
"forget plot" => nothing,
)
end
if arrow.side == :head
x_arrow = opt[:x][rng][(end - 1):end]
y_arrow = opt[:y][rng][(end - 1):end]
@ -426,6 +431,9 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o
:v => [y_arrow[i] - y_arrow[i - 1] for i in 2:2:lastindex(y_arrow)],
])
arrow_plot = series_func(merge(series_opt, arrow_opt), coordinates)
push!(series_opt,
"forget plot" => nothing,
)
push!(axis, arrow_plot)
coordinates = PGFPlotsX.Table(x_path, y_path)
segment_plot = series_func(merge(series_opt, segment_opt), coordinates)

View File

@ -21,16 +21,19 @@ end
@test !haskey(axis.contents[1].options.dict, "fill")
@testset "Legends" begin
legends_plot = plot(rand(5, 2), lab = ["1" ""])
legends_plot = plot(rand(5, 2), lab = ["1" ""], arrow = true)
scatter!(legends_plot, rand(5))
Plots._update_plot_object(legends_plot)
axis_contents = Plots.pgfx_axes(legends_plot.o)[1].contents
leg_entries = filter(x -> x isa PGFPlotsX.LegendEntry, axis_contents)
series = filter(x -> x isa PGFPlotsX.Plot, axis_contents)
@test length(leg_entries) == 2
@test length(series) == 5
@test !haskey(series[1].options.dict, "forget plot")
@test haskey(series[2].options.dict, "forget plot")
@test !haskey(series[3].options.dict, "forget plot")
@test haskey(series[3].options.dict, "forget plot")
@test haskey(series[4].options.dict, "forget plot")
@test !haskey(series[5].options.dict, "forget plot")
end # testset
@testset "3D docs example" begin