From e37380fcd21e3476f2e898f025138b507656df9f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 4 Feb 2022 17:24:22 +0100 Subject: [PATCH 1/6] change non-underscore alias --- src/args.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/args.jl b/src/args.jl index 759234368..e15a6bbd3 100644 --- a/src/args.jl +++ b/src/args.jl @@ -8,7 +8,7 @@ end function make_non_underscore(s::Symbol) str = string(s) - str = replace(str, "_" => "") + str = replace(str, "_" => "*") return Symbol(str) end @@ -1059,13 +1059,13 @@ end """ `default(key)` returns the current default value for that key. - + `default(key, value)` sets the current default value for that key. - + `default(; kw...)` will set the current default value for each key/value pair. - + `default(plotattributes, key)` returns the key from plotattributes if it exists, otherwise `default(key)`. - + """ function default(k::Symbol) k = get(_keyAliases, k, k) From 5370d10cff59defb6d66d8270e3356ed827260bc Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 4 Feb 2022 18:01:24 +0100 Subject: [PATCH 2/6] aspect ratio 3d --- src/axes.jl | 64 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index f2298292a..e26e3b8d1 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -642,31 +642,55 @@ function axis_limits( !has_user_lims && consider_aspect && letter in (:x, :y) && - !(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) + sp[:aspect_ratio] in (:none, :auto) ) - aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 - plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) - dist = amax - amin - - if letter == :x - yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) - ydist = yamax - yamin - axis_ratio = aspect_ratio * ydist / dist - factor = axis_ratio / plot_ratio + if !RecipesPipeline.is3d(:sp) + aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 + plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) + dist = amax - amin + + if letter == :x + yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) + ydist = yamax - yamin + axis_ratio = aspect_ratio * ydist / dist + 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 - 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 + if RecipesPipeline.is3d(:sp) + xs = sp[1][:x] + ys = sp[1][:y] + zs = sp[1][:z] + x12, y12, z12 = extrema(xs), extrema(ys), extrema(zs) + d = maximum([diff([x12...]),diff([y12...]),diff([z12...])])[1] / 2 + xm, ym, zm = mean(x12), mean(y12), mean(z12) + amin = if letter == :x + xm-d + elseif letter == :y + ym-d + elseif letter ==:z + zm-d + end + amax = if letter == :x + xm+d + elseif letter == :y + ym+d + elseif letter ==:z + zm+d end end - return amin, amax end From 7d26ba527b1bd7293a7b2d1d275bd845a8e973b7 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 4 Feb 2022 18:01:24 +0100 Subject: [PATCH 3/6] aspect ratio 3d --- src/axes.jl | 64 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index f2298292a..e26e3b8d1 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -642,31 +642,55 @@ function axis_limits( !has_user_lims && consider_aspect && letter in (:x, :y) && - !(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) + sp[:aspect_ratio] in (:none, :auto) ) - aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 - plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) - dist = amax - amin - - if letter == :x - yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) - ydist = yamax - yamin - axis_ratio = aspect_ratio * ydist / dist - factor = axis_ratio / plot_ratio + if !RecipesPipeline.is3d(:sp) + aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 + plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) + dist = amax - amin + + if letter == :x + yamin, yamax = axis_limits(sp, :y, default_should_widen(sp[:yaxis]), false) + ydist = yamax - yamin + axis_ratio = aspect_ratio * ydist / dist + 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 - 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 + if RecipesPipeline.is3d(:sp) + xs = sp[1][:x] + ys = sp[1][:y] + zs = sp[1][:z] + x12, y12, z12 = extrema(xs), extrema(ys), extrema(zs) + d = maximum([diff([x12...]),diff([y12...]),diff([z12...])])[1] / 2 + xm, ym, zm = mean(x12), mean(y12), mean(z12) + amin = if letter == :x + xm-d + elseif letter == :y + ym-d + elseif letter ==:z + zm-d + end + amax = if letter == :x + xm+d + elseif letter == :y + ym+d + elseif letter ==:z + zm+d end end - return amin, amax end From f8f02ce02b5533fb63c06f39327649412200f72d Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 22 Mar 2022 11:45:40 +0100 Subject: [PATCH 4/6] generalize on multiple series --- src/axes.jl | 28 ++++++++++------------------ src/types.jl | 1 + 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index e26e3b8d1..17897f073 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -669,26 +669,18 @@ function axis_limits( else end end - if RecipesPipeline.is3d(:sp) - xs = sp[1][:x] - ys = sp[1][:y] - zs = sp[1][:z] - x12, y12, z12 = extrema(xs), extrema(ys), extrema(zs) - d = maximum([diff([x12...]),diff([y12...]),diff([z12...])])[1] / 2 - xm, ym, zm = mean(x12), mean(y12), mean(z12) - amin = if letter == :x - xm-d + if RecipesPipeline.is3d(:sp) && consider_aspect == true + x12, y12, z12 = extrema(sp, :x), extrema(sp, :y), extrema(sp, :z) + d = maximum((x12[2] - x12[1], y12[2] - y12[1], z12[2] - z12[1])) / 2 + amin, amax = if letter == :x + xm = mean(x12) + xm-d, xm+d elseif letter == :y - ym-d + ym = mean(y12) + ym-d, ym+d elseif letter ==:z - zm-d - end - amax = if letter == :x - xm+d - elseif letter == :y - ym+d - elseif letter ==:z - zm+d + zm = mean(z12) + zm-d, zm+d end end return amin, amax diff --git a/src/types.jl b/src/types.jl index 24d441a27..c319835ef 100644 --- a/src/types.jl +++ b/src/types.jl @@ -43,6 +43,7 @@ mutable struct Subplot{T<:AbstractBackend} <: AbstractLayout end 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))) # ----------------------------------------------------------- From ad3b8f96fd8349ccfdd4646bb5a7c1afed484cb8 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Wed, 23 Mar 2022 16:41:36 +0100 Subject: [PATCH 5/6] simplify logic --- src/axes.jl | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 17897f073..ef4f6b066 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -592,7 +592,7 @@ function axis_limits( sp, letter, 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)] ex = axis[:extrema] @@ -638,14 +638,17 @@ function axis_limits( amin, amax end - if ( - !has_user_lims && - consider_aspect && - letter in (:x, :y) && - sp[:aspect_ratio] in (:none, :auto) - ) - if !RecipesPipeline.is3d(:sp) - aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 + if !has_user_lims && consider_aspect + aspect_ratio = sp[:aspect_ratio] + aspect_ratio = + isa(aspect_ratio, Number) ? aspect_ratio : + aspect_ratio === :equal ? 1 : + throw( + ArgumentError( + "Unsuppported value $aspect_ratio for keyword `aspect_ratio`.", + ), + ) + if !RecipesPipeline.is3d(sp) plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) dist = amax - amin @@ -667,20 +670,21 @@ function axis_limits( amax = center + factor * (amax - center) end else - end - end - if RecipesPipeline.is3d(:sp) && consider_aspect == true - x12, y12, z12 = extrema(sp, :x), extrema(sp, :y), extrema(sp, :z) - d = maximum((x12[2] - x12[1], y12[2] - y12[1], z12[2] - z12[1])) / 2 - amin, amax = if letter == :x - xm = mean(x12) - xm-d, xm+d - elseif letter == :y - ym = mean(y12) - ym-d, ym+d - elseif letter ==:z - zm = mean(z12) - zm-d, zm+d + # TODO: support arbitrary box ratios + if aspect_ratio == 1 + x12, y12, z12 = extrema(sp, :x), extrema(sp, :y), extrema(sp, :z) + d = maximum((x12[2] - x12[1], y12[2] - y12[1], z12[2] - z12[1])) / 2 + amin, amax = if letter == :x + xm = mean(x12) + xm - d, xm + d + elseif letter == :y + ym = mean(y12) + ym - d, ym + d + elseif letter == :z + zm = mean(z12) + zm - d, zm + d + end + end end end return amin, amax From 2bb00d6207ea14e2144eda74a50930c80809b461 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 4 Feb 2022 17:24:22 +0100 Subject: [PATCH 6/6] Revert "change non-underscore alias" This reverts commit e37380fcd21e3476f2e898f025138b507656df9f. --- src/args.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/args.jl b/src/args.jl index e15a6bbd3..759234368 100644 --- a/src/args.jl +++ b/src/args.jl @@ -8,7 +8,7 @@ end function make_non_underscore(s::Symbol) str = string(s) - str = replace(str, "_" => "*") + str = replace(str, "_" => "") return Symbol(str) end @@ -1059,13 +1059,13 @@ end """ `default(key)` returns the current default value for that key. - + `default(key, value)` sets the current default value for that key. - + `default(; kw...)` will set the current default value for each key/value pair. - + `default(plotattributes, key)` returns the key from plotattributes if it exists, otherwise `default(key)`. - + """ function default(k::Symbol) k = get(_keyAliases, k, k)