added const copies of _all_defaults and _axis_defaults to be able to reset fonts to initial values with new resetfontsizes method

This commit is contained in:
Florian Oswald 2017-05-17 16:34:03 +02:00
parent e3ce1ab1d1
commit fdf699bf35
2 changed files with 29 additions and 2 deletions

View File

@ -335,6 +335,10 @@ const _all_defaults = KW[
_axis_defaults_byletter _axis_defaults_byletter
] ]
# to be able to reset things to initial values
const _all_initial_defaults = deepcopy(_all_defaults)
const _axis_initial_defaults = deepcopy(_axis_defaults)
const _all_args = sort(collect(union(map(keys, _all_defaults)...))) const _all_args = sort(collect(union(map(keys, _all_defaults)...)))
RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k) RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k)
@ -519,6 +523,24 @@ function default(d::KW, k::Symbol)
get(d, k, default(k)) get(d, k, default(k))
end end
# reset the defaults globally to values at startup
"""
`initial(key)` returns the intial value for that key
"""
function initial(k::Symbol)
k = get(_keyAliases, k, k)
for defaults in _all_initial_defaults
if haskey(defaults, k)
return defaults[k]
end
end
if haskey(_axis_initial_defaults, k)
return _axis_initial_defaults[k]
end
k in _suppress_warnings || error("Unknown key: ", k)
end
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------

View File

@ -304,11 +304,16 @@ function scalefontsizes(factor::Number)
end end
function resetfontsize(k::Symbol) function resetfontsize(k::Symbol)
i = initial(k)
f = default(k) f = default(k)
default(k,f) # some fonts don't have an initial value!
if i != false
f.pointsize = i.pointsize
default(k, i)
end
end end
"Reset all fonts to default size" "Reset all fonts to initial size"
function resetfontsizes() function resetfontsizes()
for k in (:titlefont, :guidefont, :tickfont, :legendfont) for k in (:titlefont, :guidefont, :tickfont, :legendfont)
resetfontsize(k) resetfontsize(k)