Merge 724ad754aee94eae1c26efee168943d3b5e34418 into 9e92ada61a1b4f0bf41387198ab46ca66170d713

This commit is contained in:
Yuval 2022-04-27 21:07:11 +02:00 committed by GitHub
commit f8059f03a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 11 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,6 +588,16 @@ function round_limits(amin, amax, scale)
amin, amax
end
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
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(
sp,
@ -597,8 +608,9 @@ function axis_limits(
axis = sp[get_attr_symbol(letter, :axis)]
ex = axis[:extrema]
amin, amax = ex.emin, ex.emax
lims = axis[:lims]
has_user_lims = (isa(lims, Tuple) || isa(lims, AVec)) && length(lims) == 2
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
if lmin == :auto

View File

@ -362,10 +362,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,13 +42,23 @@ end
pl = plot([1.05, 2.0, 2.95], ylims = :round)
@test Plots.ylims(pl) == (1, 3)
pl = plot(1:3, xlims = (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(1:3, xlims = (1, 5), widen = true)
pl = plot(x; xlims, widen = true)
@test Plots.xlims(pl) == Plots.widen(1, 5)
end
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
ql = quiver([1, 2], [2, 1], [3, 4], quiver = ([1, -1], [0, 0], [1, -0.5]), arrow = true)
@test ql[1][:projection] == "3d"