From a3451ab507ad9e7c0351f0cca3054d77e7e0e11f Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 25 Feb 2022 15:31:52 +0100 Subject: [PATCH] revert legendfont being determant --- src/args.jl | 38 ++++++++++++-------------------------- src/pipeline.jl | 1 - src/utils.jl | 9 ++++++++- test/test_defaults.jl | 7 ++++++- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/args.jl b/src/args.jl index da105ea3..309799df 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1347,7 +1347,12 @@ function processFontArg!(plotattributes::AKW, fontname::Symbol, arg) T = typeof(arg) if T <: Font plotattributes[Symbol(fontname, :family)] = arg.family - plotattributes[Symbol(fontname, :size)] = arg.pointsize + # TODO: this is neccessary in the transition from old fontsize to new font_pointsize and should be removed when it is completed + if in(Symbol(fontname, :size), _all_args) + plotattributes[Symbol(fontname, :size)] = arg.pointsize + else + plotattributes[Symbol(fontname, :_pointsize)] = arg.pointsize + end plotattributes[Symbol(fontname, :halign)] = arg.halign plotattributes[Symbol(fontname, :valign)] = arg.valign plotattributes[Symbol(fontname, :rotation)] = arg.rotation @@ -1368,7 +1373,11 @@ function processFontArg!(plotattributes::AKW, fontname::Symbol, arg) plotattributes[Symbol(fontname, :family)] = string(arg) end elseif typeof(arg) <: Integer - plotattributes[Symbol(fontname, :size)] = arg + if in(Symbol(fontname, :size), _all_args) + plotattributes[Symbol(fontname, :size)] = arg + else + plotattributes[Symbol(fontname, :_pointsize)] = arg + end elseif typeof(arg) <: Real plotattributes[Symbol(fontname, :rotation)] = convert(Float64, arg) else @@ -1487,7 +1496,7 @@ function RecipesPipeline.preprocess_attributes!(plotattributes::AKW) end # fonts - for fontname in (:titlefont, :legendtitlefont, :plot_titlefont, :colorbar_titlefont) + for fontname in (:titlefont, :legend_title_font, :plot_titlefont, :colorbar_titlefont, :legend_font) args = RecipesPipeline.pop_kw!(plotattributes, fontname, ()) for arg in wraptuple(args) processFontArg!(plotattributes, fontname, arg) @@ -1957,29 +1966,6 @@ function _update_subplot_colors(sp::Subplot) return end -function _update_subplot_legend(sp::Subplot, plotattributes_in) - f_attr = NamedTuple( - k => plotattributes_in[Symbol(:legend_font_, k)] for - k in (:family, :pointsize, :valign, :halign, :rotation, :color) if - haskey(plotattributes_in, Symbol(:legend_font_, k)) - ) - #! format: off - match_attr = NamedTuple( - ( - lk = Symbol(:legend_font_, k); - k => - haskey(_match_map, lk) ? sp[lk] : - haskey(plotattributes_in, :legend_font) ? - getproperty(plotattributes_in[:legend_font], k) : - haskey(sp.attr, :legend_font) ? - getproperty(sp.attr[:legend_font], k) : - default(plotattributes_in, lk) - ) for k in (:family, :pointsize, :valign, :halign, :rotation, :color) - ) - #! format: on - sp.attr[:legend_font] = font(; merge(match_attr, f_attr)...) -end - function _update_axis( plt::Plot, sp::Subplot, diff --git a/src/pipeline.jl b/src/pipeline.jl index 7874543d..8f8ae8b7 100644 --- a/src/pipeline.jl +++ b/src/pipeline.jl @@ -275,7 +275,6 @@ function _subplot_setup(plt::Plot, plotattributes::AKW, kw_list::Vector{KW}) get(sp_attrs, sp, KW()) end _update_subplot_args(plt, sp, attr, idx, false) - _update_subplot_legend(sp, attr) end # do we need to link any axes together? diff --git a/src/utils.jl b/src/utils.jl index b0ed9e60..325b6053 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -986,7 +986,14 @@ titlefont(sp::Subplot) = font(; color = sp[:titlefontcolor], ) -legendfont(sp::Subplot) = sp[:legend_font] +legendfont(sp::Subplot) = font(; + family = sp[:legend_font_family], + pointsize = sp[:legend_font_pointsize], + valign = sp[:legend_font_valign], + halign = sp[:legend_font_halign], + rotation = sp[:legend_font_rotation], + color = sp[:legend_font_color], +) legendtitlefont(sp::Subplot) = font(; family = sp[:legend_title_font_family], diff --git a/test/test_defaults.jl b/test/test_defaults.jl index e9abd345..492bf7c0 100644 --- a/test/test_defaults.jl +++ b/test/test_defaults.jl @@ -1,4 +1,4 @@ -using Plots, Test, Colors +using Plots, Test, Plots.Colors const PLOTS_DEFAULTS = Dict(:theme => :wong2, :fontfamily => :palantino) Plots.__init__() @@ -93,4 +93,9 @@ end # testset # match mechanism @test sp[:legend_font_color] == sp[:foreground_color_subplot] @test Plots.legendfont(sp).color == sp[:foreground_color_subplot] + + # magic invocation + @test_nowarn sp = plot(;legendfont = 12)[1] + @test sp[:legend_font_pointsize] == 12 + @test Plots.legendfont(sp).pointsize == 12 end # testset