Merge pull request #837 from floswald/reset

resetfontsizes: fixes #836
This commit is contained in:
Michael Krabbe Borregaard 2017-06-12 13:31:55 +02:00 committed by GitHub
commit cadb0f96e2
2 changed files with 27 additions and 1 deletions

View File

@ -336,6 +336,12 @@ const _all_defaults = KW[
_axis_defaults_byletter
]
# to be able to reset font sizes to initial values
const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefont].pointsize,
:legendfont => _subplot_defaults[:legendfont].pointsize,
:tickfont => _axis_defaults[:tickfont].pointsize,
:guidefont => _axis_defaults[:guidefont].pointsize)
const _all_args = sort(collect(union(map(keys, _all_defaults)...)))
RecipesBase.is_key_supported(k::Symbol) = is_attr_supported(k)
@ -522,7 +528,6 @@ function default(d::KW, k::Symbol)
end
# -----------------------------------------------------------------------------
# if arg is a valid color value, then set d[csym] and return true

View File

@ -297,12 +297,33 @@ function scalefontsize(k::Symbol, factor::Number)
f.pointsize = round(Int, factor * f.pointsize)
default(k, f)
end
"""
scalefontsizes(factor::Number)
Scales all **current** font sizes by `factor`. For example `scalefontsizes(1.1)` increases all current font sizes by 10%. To reset to initial sizes, use `scalefontsizes()`
"""
function scalefontsizes(factor::Number)
for k in (:titlefont, :guidefont, :tickfont, :legendfont)
scalefontsize(k, factor)
end
end
"""
scalefontsizes()
Resets font sizes to initial default values.
"""
function scalefontsizes()
for k in (:titlefont, :guidefont, :tickfont, :legendfont)
f = default(k)
if k in keys(_initial_fontsizes)
factor = f.pointsize / _initial_fontsizes[k]
scalefontsize(k, 1.0/factor)
end
end
end
"Wrap a string with font info"
immutable PlotText
str::AbstractString