tests, fix for default_should_widen
This commit is contained in:
parent
8cea310217
commit
724ad754ae
28
src/axes.jl
28
src/axes.jl
@ -568,7 +568,8 @@ function default_should_widen(axis::Axis)
|
|||||||
return axis[:widen]
|
return axis[:widen]
|
||||||
end
|
end
|
||||||
# automatic behavior: widen if limits aren't specified and series type is appropriate
|
# 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 sp in axis.sps
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
if series.plotattributes[:seriestype] in _widen_seriestypes
|
if series.plotattributes[:seriestype] in _widen_seriestypes
|
||||||
@ -587,21 +588,15 @@ function round_limits(amin, amax, scale)
|
|||||||
amin, amax
|
amin, amax
|
||||||
end
|
end
|
||||||
|
|
||||||
parse_limits(lims::Tuple{<:Real, <:Real}, letter) = lims
|
parse_limits(lims::Tuple{<:Real,<:Real}) = lims
|
||||||
parse_limits(lims::Symbol, letter) = lims
|
parse_limits(lims::Symbol) = lims
|
||||||
parse_limits(lims::AVec, letter) = if length(lims) == 2 && all(x isa Real for x in lims)
|
parse_limits(lims::AVec) = length(lims) == 2 && all(x isa Real for x in lims) ? Tuple(lims) : nothing
|
||||||
Tuple(lims)
|
parse_limits(lims) = nothing
|
||||||
else
|
|
||||||
limits_err(lims, letter)
|
|
||||||
end
|
|
||||||
parse_limits(lims, letter) = limits_err(lims, letter)
|
|
||||||
|
|
||||||
function limits_err(lims, letter)
|
warn_invalid_limits(lims, letter) = @warn """
|
||||||
@warn """Invalid limits for $letter axis. Limits should be a symbol, or a two-element tuple or vector of numbers.
|
Invalid limits for $letter axis. Limits should be a symbol, or a two-element tuple or vector of numbers.
|
||||||
$(letter)lims = $lims
|
$(letter)lims = $lims
|
||||||
"""
|
"""
|
||||||
nothing
|
|
||||||
end
|
|
||||||
|
|
||||||
# using the axis extrema and limit overrides, return the min/max value for this axis
|
# using the axis extrema and limit overrides, return the min/max value for this axis
|
||||||
function axis_limits(
|
function axis_limits(
|
||||||
@ -613,7 +608,8 @@ function axis_limits(
|
|||||||
axis = sp[get_attr_symbol(letter, :axis)]
|
axis = sp[get_attr_symbol(letter, :axis)]
|
||||||
ex = axis[:extrema]
|
ex = axis[:extrema]
|
||||||
amin, amax = ex.emin, ex.emax
|
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
|
has_user_lims = lims isa Tuple
|
||||||
if has_user_lims
|
if has_user_lims
|
||||||
lmin, lmax = lims
|
lmin, lmax = lims
|
||||||
|
|||||||
@ -370,10 +370,6 @@ ticksType(ticks::Tuple{T,S}) where {T<:Union{AVec,Tuple},S<:Union{AVec,Tuple}} =
|
|||||||
:ticks_and_labels
|
:ticks_and_labels
|
||||||
ticksType(ticks) = :invalid
|
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)
|
# recursively merge kw-dicts, e.g. for merging extra_kwargs / extra_plot_kwargs in plotly)
|
||||||
recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)
|
recursive_merge(x::AbstractDict...) = merge(recursive_merge, x...)
|
||||||
# if values are not AbstractDicts, take the last definition (as does merge)
|
# if values are not AbstractDicts, take the last definition (as does merge)
|
||||||
|
|||||||
@ -42,11 +42,21 @@ end
|
|||||||
pl = plot([1.05, 2.0, 2.95], ylims = :round)
|
pl = plot([1.05, 2.0, 2.95], ylims = :round)
|
||||||
@test Plots.ylims(pl) == (1, 3)
|
@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])
|
||||||
@test Plots.xlims(pl) == (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)
|
pl = plot(1:5, lims = :symmetric, widen = false)
|
||||||
@test Plots.xlims(pl) == Plots.widen(1, 5)
|
@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
|
end
|
||||||
|
|
||||||
@testset "3D Axis" begin
|
@testset "3D Axis" begin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user