tests, fix for default_should_widen

This commit is contained in:
yha 2021-12-08 19:52:26 +02:00
parent 8cea310217
commit 724ad754ae
3 changed files with 26 additions and 24 deletions

View File

@ -568,7 +568,8 @@ function default_should_widen(axis::Axis)
return axis[:widen]
end
# automatic behavior: widen if limits aren't specified and series type is appropriate
(is_2tuple(axis[:lims]) || axis[:lims] == :round) && return false
lims = parse_limits(axis[:lims])
(lims isa Tuple || lims == :round) && return false
for sp in axis.sps
for series in series_list(sp)
if series.plotattributes[:seriestype] in _widen_seriestypes
@ -587,21 +588,15 @@ function round_limits(amin, amax, scale)
amin, amax
end
parse_limits(lims::Tuple{<:Real, <:Real}, letter) = lims
parse_limits(lims::Symbol, letter) = lims
parse_limits(lims::AVec, letter) = if length(lims) == 2 && all(x isa Real for x in lims)
Tuple(lims)
else
limits_err(lims, letter)
end
parse_limits(lims, letter) = limits_err(lims, letter)
parse_limits(lims::Tuple{<:Real,<:Real}) = lims
parse_limits(lims::Symbol) = lims
parse_limits(lims::AVec) = length(lims) == 2 && all(x isa Real for x in lims) ? Tuple(lims) : nothing
parse_limits(lims) = nothing
function limits_err(lims, letter)
@warn """Invalid limits for $letter axis. Limits should be a symbol, or a two-element tuple or vector of numbers.
$(letter)lims = $lims
"""
nothing
end
warn_invalid_limits(lims, letter) = @warn """
Invalid limits for $letter axis. Limits should be a symbol, or a two-element tuple or vector of numbers.
$(letter)lims = $lims
"""
# using the axis extrema and limit overrides, return the min/max value for this axis
function axis_limits(
@ -613,7 +608,8 @@ function axis_limits(
axis = sp[get_attr_symbol(letter, :axis)]
ex = axis[:extrema]
amin, amax = ex.emin, ex.emax
lims = parse_limits(axis[:lims], letter)
lims = parse_limits(axis[:lims])
lims === nothing && warn_invalid_limits(axis[:lims], letter)
has_user_lims = lims isa Tuple
if has_user_lims
lmin, lmax = lims

View File

@ -370,10 +370,6 @@ ticksType(ticks::Tuple{T,S}) where {T<:Union{AVec,Tuple},S<:Union{AVec,Tuple}} =
:ticks_and_labels
ticksType(ticks) = :invalid
limsType(lims::Tuple{T,S}) where {T<:Real,S<:Real} = :limits
limsType(lims::Symbol) = lims == :auto ? :auto : :invalid
limsType(lims) = :invalid
# recursively merge kw-dicts, e.g. for merging extra_kwargs / extra_plot_kwargs in plotly)
recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)
# if values are not AbstractDicts, take the last definition (as does merge)

View File

@ -42,11 +42,21 @@ end
pl = plot([1.05, 2.0, 2.95], ylims = :round)
@test Plots.ylims(pl) == (1, 3)
pl = plot(1:3, xlims = (1, 5))
@test Plots.xlims(pl) == (1, 5)
for x in (1:3, -10:10), xlims in ((1, 5), [1, 5])
pl = plot(x; xlims)
@test Plots.xlims(pl) == (1, 5)
pl = plot(x; xlims, widen = true)
@test Plots.xlims(pl) == Plots.widen(1, 5)
end
pl = plot(1:3, xlims = (1, 5), widen = true)
@test Plots.xlims(pl) == Plots.widen(1, 5)
pl = plot(1:5, lims = :symmetric, widen = false)
@test Plots.xlims(pl) == Plots.ylims(pl) == (-5, 5)
for xlims in (0, 0.0, false, true, plot())
pl = plot(1:5; xlims)
@test Plots.xlims(pl) == Plots.widen(1, 5)
@test_logs (:warn, r"Invalid limits for x axis") match_mode=:any display(pl)
end
end
@testset "3D Axis" begin