Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Fix floating point equality comparison in layouts #4973

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,11 @@
"name": "Syver Døving Agdestein",
"orcid": "0000-0002-1589-2916",
"type": "Other"
},
{
"affiliation": "The Alan Turing Institute",
"name": "Penelope Yong",
"type": "Other"
}
],
"upload_type": "software"
Expand Down
13 changes: 7 additions & 6 deletions PlotsBase/src/Commons/layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ function GridLayout(
kw...,
)
# Check the values for heights and widths if values are provided
all_between_one(xs) = all(x -> 0 < x < 1, xs)
if heights ≢ nothing
sum(heights) == 1 || error("The sum of heights must be 1 !")
all(x -> 0 < x < 1, heights) ||
error("Values for heights must be in the range (0, 1) !")
sum(heights) 1 || error("The heights provided ($(heights)) must sum to 1.")
all_between_one(heights) ||
error("The heights provided ($(heights)) must be in the range (0, 1).")
else
heights = zeros(dims[1])
end
if widths ≢ nothing
sum(widths) == 1 || error("The sum of widths must be 1 !")
all(x -> 0 < x < 1, widths) ||
error("Values for widths must be in the range (0, 1) !")
sum(widths) 1 || error("The widths provided ($(widths)) must sum to 1.")
all_between_one(widths) ||
error("The widths provided ($(widths)) must be in the range (0, 1).")
else
widths = zeros(dims[2])
end
Expand Down
11 changes: 11 additions & 0 deletions PlotsBase/test/test_layouts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ end
@test_throws ErrorException plot(map(_ -> plot(1:2), 1:5)...; layout = grid(2, 2))
end

@testset "Allowed grid widths/heights" begin
@test_nowarn grid(2, 1, heights = [0.5, 0.5])
@test_nowarn grid(4, 1, heights = [0.3, 0.3, 0.3, 0.1])
@test_nowarn grid(1, 2, widths = [0.5, 0.5])
@test_nowarn grid(1, 4, widths = [0.3, 0.3, 0.3, 0.1])
@test_throws ErrorException grid(2, 1, heights = [0.5, 0.4])
@test_throws ErrorException grid(4, 1, heights = [1.5, -0.5])
@test_throws ErrorException grid(1, 2, widths = [0.5, 0.4])
@test_throws ErrorException grid(1, 4, widths = [1.5, -0.5])
end

@testset "Invalid viewport" begin
# github.com/JuliaPlots/Plots.jl/issues/2804
pl = plot(1, layout = (10, 2))
Expand Down
Loading