From d9fdfe9174f77c588225f4fb9d435f779986d265 Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 22 Aug 2024 23:44:50 +0100 Subject: [PATCH 1/3] Fix floating point equality comparison in layouts --- src/layouts.jl | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/layouts.jl b/src/layouts.jl index 2eed33558..8c98ee165 100644 --- a/src/layouts.jl +++ b/src/layouts.jl @@ -216,23 +216,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 - if sum(heights) != 1 - error("The sum of heights must be 1!") - end - if all(x -> 0 < x < 1, heights) == false - error("Values for heights must be in the range (0, 1)!") - end + 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 - if sum(widths) != 1 - error("The sum of widths must be 1!") - end - if all(x -> 0 < x < 1, widths) == false - error("Values for widths must be in the range (0, 1)!") - end + 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 From 5bedc3ef1a1ebd0fab5640470d59405f751931dc Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 22 Aug 2024 23:45:15 +0100 Subject: [PATCH 2/3] Add tests for grid layout widths/heights --- test/test_layouts.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_layouts.jl b/test/test_layouts.jl index 182720e92..952da4f06 100644 --- a/test/test_layouts.jl +++ b/test/test_layouts.jl @@ -65,6 +65,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)) From e18edd33b8d74c27977e17bb707b82390fcf9dce Mon Sep 17 00:00:00 2001 From: Penelope Yong Date: Thu, 22 Aug 2024 23:45:25 +0100 Subject: [PATCH 3/3] Add myself to .zenodo.json --- .zenodo.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.zenodo.json b/.zenodo.json index 539036d03..42fbc2c8a 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -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"