Skip to content

Commit

Permalink
Make layouts tolerant of having too-few items (#4247)
Browse files Browse the repository at this point in the history
* Make layouts tolerant of fewer items.

* Add tests

* Remove grid kwarg

* format add `plot!` test

Co-authored-by: Simon Christ <[email protected]>
  • Loading branch information
BioTurboNick and BeastyBlacksmith authored Jun 23, 2022
1 parent 772cd51 commit 03d015c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ end

function layout_args(plotattributes::AKW, n_override::Integer)
layout, n = layout_args(n_override, get(plotattributes, :layout, n_override))
if n != n_override
if n < n_override
error(
"When doing layout, n ($n) != n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.",
"When doing layout, n ($n) < n_override ($(n_override)). You're probably trying to force existing plots into a layout that doesn't fit them.",
)
end
layout, n
Expand Down
20 changes: 20 additions & 0 deletions test/test_layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ end
@test p[3][:framestyle] === :none
end

@testset "Allowed subplot counts" begin
p = plot(plot(1:2); layout = grid(2, 2))
@test length(p) == 1
p = plot(plot(1:2), plot(1:2); layout = grid(2, 2))
@test length(p) == 2
p = plot(plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2))
@test length(p) == 3
@test length(plot!(p, plot(1:2))) == 4
p = plot(plot(1:2), plot(1:2), plot(1:2), plot(1:2); layout = grid(2, 2))
@test length(p) == 4
@test_throws ErrorException plot(
plot(1:2),
plot(1:2),
plot(1:2),
plot(1:2),
plot(1:2);
layout = grid(2, 2),
)
end

@testset "Coverage" begin
p = plot((plot(i) for i in 1:4)..., layout = (2, 2))

Expand Down

0 comments on commit 03d015c

Please sign in to comment.