From 89c68d98b07ac6e14fc6af8edd8e8960393c97bb Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 26 Sep 2022 22:03:50 +0200 Subject: [PATCH] fix single `:auto` in `xlims` or `ylims` (#4378) --- src/axes.jl | 15 +++++++++------ test/test_axes.jl | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index db13eb6d2..1118bb9ef 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -585,10 +585,11 @@ function round_limits(amin, amax, scale) amin, amax end -process_limits(lims::Tuple{<:Real,<:Real}) = lims +process_limits(lims::Tuple{<:Union{Symbol,Real},<:Union{Symbol,Real}}) = lims process_limits(lims::Symbol) = lims process_limits(lims::AVec) = - length(lims) == 2 && all(x isa Real for x in lims) ? Tuple(lims) : nothing + length(lims) == 2 && all(map(x -> x isa Union{Symbol,Real}, lims)) ? Tuple(lims) : + nothing process_limits(lims) = nothing warn_invalid_limits(lims, letter) = @warn """ @@ -611,13 +612,15 @@ function axis_limits( has_user_lims = lims isa Tuple if has_user_lims lmin, lmax = lims - if lmin === :auto - elseif isfinite(lmin) + if lmin isa Number && isfinite(lmin) amin = lmin + else + lmin === :auto || @warn "Invalid min limit" lmin end - if lmax === :auto - elseif isfinite(lmax) + if lmax isa Number && isfinite(lmax) amax = lmax + else + lmax === :auto || @warn "Invalid max $(letter)limit" lmax end end if lims === :symmetric diff --git a/test/test_axes.jl b/test/test_axes.jl index 2f416a80b..58df49686 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -72,6 +72,26 @@ end ) @test plims == Plots.widen(1, 5) end + + @testset "JuliaPlots/Plots.jl/issues/4379" begin + for ylims in ((-5, :auto), [-5, :auto]) + pl = plot([-2, 3], ylims = ylims, widen = false) + @test Plots.ylims(pl) == (-5.0, 3.0) + end + for ylims in ((:auto, 4), [:auto, 4]) + pl = plot([-2, 3], ylims = ylims, widen = false) + @test Plots.ylims(pl) == (-2.0, 4.0) + end + + for xlims in ((-3, :auto), [-3, :auto]) + pl = plot([-2, 3], [-1, 1], xlims = xlims, widen = false) + @test Plots.xlims(pl) == (-3.0, 3.0) + end + for xlims in ((:auto, 4), [:auto, 4]) + pl = plot([-2, 3], [-1, 1], xlims = xlims, widen = false) + @test Plots.xlims(pl) == (-2.0, 4.0) + end + end end @testset "3D Axis" begin