revert legendfont being determant

This commit is contained in:
Simon Christ 2022-02-25 15:31:52 +01:00
parent e31d056820
commit a3451ab507
4 changed files with 26 additions and 29 deletions

View File

@ -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,

View File

@ -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?

View File

@ -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],

View File

@ -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