Merge 2bb00d6207ea14e2144eda74a50930c80809b461 into b76dc2d7a36ca5bbde126fbc46e86f28f419fbc2

This commit is contained in:
Simon Christ 2022-05-02 14:25:45 +02:00 committed by GitHub
commit 7a73c7f3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 26 deletions

View File

@ -592,7 +592,7 @@ function axis_limits(
sp, sp,
letter, letter,
should_widen = default_should_widen(sp[get_attr_symbol(letter, :axis)]), should_widen = default_should_widen(sp[get_attr_symbol(letter, :axis)]),
consider_aspect = true, consider_aspect = sp[:aspect_ratio] (:auto, :none),
) )
axis = sp[get_attr_symbol(letter, :axis)] axis = sp[get_attr_symbol(letter, :axis)]
ex = axis[:extrema] ex = axis[:extrema]
@ -638,35 +638,55 @@ function axis_limits(
amin, amax amin, amax
end end
if ( if !has_user_lims && consider_aspect
!has_user_lims && aspect_ratio = sp[:aspect_ratio]
consider_aspect && aspect_ratio =
letter in (:x, :y) && isa(aspect_ratio, Number) ? aspect_ratio :
!(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) aspect_ratio === :equal ? 1 :
) throw(
aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 ArgumentError(
plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) "Unsuppported value $aspect_ratio for keyword `aspect_ratio`.",
dist = amax - amin ),
)
if !RecipesPipeline.is3d(sp)
plot_ratio = height(plotarea(sp)) / width(plotarea(sp))
dist = amax - amin
if letter == :x if letter == :x
yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false)
ydist = yamax - yamin ydist = yamax - yamin
axis_ratio = aspect_ratio * ydist / dist axis_ratio = aspect_ratio * ydist / dist
factor = axis_ratio / plot_ratio factor = axis_ratio / plot_ratio
else
xamin, xamax = axis_limits(sp, :x, default_should_widen(sp[:xaxis]), false)
xdist = xamax - xamin
axis_ratio = aspect_ratio * dist / xdist
factor = plot_ratio / axis_ratio
end
if factor > 1
center = (amin + amax) / 2
amin = center + factor * (amin - center)
amax = center + factor * (amax - center)
end
else else
xamin, xamax = axis_limits(sp, :x, default_should_widen(sp[:xaxis]), false) # TODO: support arbitrary box ratios
xdist = xamax - xamin if aspect_ratio == 1
axis_ratio = aspect_ratio * dist / xdist x12, y12, z12 = extrema(sp, :x), extrema(sp, :y), extrema(sp, :z)
factor = plot_ratio / axis_ratio d = maximum((x12[2] - x12[1], y12[2] - y12[1], z12[2] - z12[1])) / 2
end amin, amax = if letter == :x
xm = mean(x12)
if factor > 1 xm - d, xm + d
center = (amin + amax) / 2 elseif letter == :y
amin = center + factor * (amin - center) ym = mean(y12)
amax = center + factor * (amax - center) ym - d, ym + d
elseif letter == :z
zm = mean(z12)
zm - d, zm + d
end
end
end end
end end
return amin, amax return amin, amax
end end

View File

@ -43,6 +43,7 @@ mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout
end end
Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}") Base.show(io::IO, sp::Subplot) = print(io, "Subplot{$(sp[:subplot_index])}")
Base.extrema(sp::Subplot, letter::Symbol) = minimum(minimum.(getindex.(sp.series_list, letter))), maximum(maximum.(getindex.(sp.series_list, letter)))
# ----------------------------------------------------------- # -----------------------------------------------------------