Skip to content

Commit

Permalink
add empty! for plots
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 23, 2022
1 parent eb99990 commit 384f4d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,17 @@ Base.size(plt::Plot) = size(plt.layout)
Base.size(plt::Plot, i::Integer) = size(plt.layout)[i]
Base.ndims(plt::Plot) = 2

# clear out series list, but retain subplots
Base.empty!(plt::Plot) = foreach(sp -> empty!(sp.series_list), plt.subplots)

# attr(plt::Plot, k::Symbol) = plt.attr[k]
# attr!(plt::Plot, v, k::Symbol) = (plt.attr[k] = v)

Base.getindex(sp::Subplot, i::Union{Vector{<:Integer},Integer}) = series_list(sp)[i]
Base.lastindex(sp::Subplot) = length(series_list(sp))

Base.empty!(sp::Subplot) = empty!(sp.series_list)

# -----------------------------------------------------------------------

Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}")
Expand Down
16 changes: 15 additions & 1 deletion test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ end
end
end

@testset "plot" begin
@testset "tex_output_standalone" begin
pl = plot(1:5)
pl2 = plot(pl, tex_output_standalone = true)
@test !pl[:tex_output_standalone]
Expand Down Expand Up @@ -191,6 +191,20 @@ end
@test series[:y] == y2
end

@testset "Empty Plot / Subplots" begin
pl = plot(map(_ -> plot(1:2, [1:2 2:3]), 1:2)...)
empty!(pl)
@test length(pl.subplots) == 2
@test length(first(pl).series_list) == 0
@test length(last(pl).series_list) == 0

pl = plot(map(_ -> plot(1:2, [1:2 2:3]), 1:2)...)
empty!(first(pl)) # clear out only the first subplot
@test length(pl.subplots) == 2
@test length(first(pl).series_list) == 0
@test length(last(pl).series_list) == 2
end

@testset "Measures" begin
@test 1Plots.mm * 0.1Plots.pct == 0.1Plots.mm
@test 0.1Plots.pct * 1Plots.mm == 0.1Plots.mm
Expand Down

0 comments on commit 384f4d7

Please sign in to comment.