From af56d6f2650fe24fda7beb64a8eab43eba6f0fa3 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Wed, 17 May 2017 15:31:26 +0200 Subject: [PATCH 1/7] added resetfontsizes() --- src/components.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components.jl b/src/components.jl index b20eb3d0..bff21a7c 100644 --- a/src/components.jl +++ b/src/components.jl @@ -303,6 +303,18 @@ function scalefontsizes(factor::Number) end end +function resetfontsize(k::Symbol) + f = default(k) + default(k,f) +end + +"Reset all fonts to default size" +function resetfontsizes() + for k in (:titlefont, :guidefont, :tickfont, :legendfont) + resetfontsize(k, factor) + end +end + "Wrap a string with font info" immutable PlotText str::AbstractString From e3ce1ab1d153859aa4b4c34a4d56ed9498f6a0af Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Wed, 17 May 2017 15:40:47 +0200 Subject: [PATCH 2/7] just calling default(k) does not give back the default value for k --- src/components.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components.jl b/src/components.jl index bff21a7c..116aa86c 100644 --- a/src/components.jl +++ b/src/components.jl @@ -311,7 +311,7 @@ end "Reset all fonts to default size" function resetfontsizes() for k in (:titlefont, :guidefont, :tickfont, :legendfont) - resetfontsize(k, factor) + resetfontsize(k) end end From fdf699bf3537ff3208b0097f8aad43e2956490b4 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Wed, 17 May 2017 16:34:03 +0200 Subject: [PATCH 3/7] added const copies of _all_defaults and _axis_defaults to be able to reset fonts to initial values with new resetfontsizes method --- src/args.jl | 22 ++++++++++++++++++++++ src/components.jl | 9 +++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/args.jl b/src/args.jl index b93e2d98..be5c564c 100644 --- a/src/args.jl +++ b/src/args.jl @@ -335,6 +335,10 @@ const _all_defaults = KW[ _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)...))) 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)) 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 # ----------------------------------------------------------------------------- diff --git a/src/components.jl b/src/components.jl index 116aa86c..e7eb74d6 100644 --- a/src/components.jl +++ b/src/components.jl @@ -304,11 +304,16 @@ function scalefontsizes(factor::Number) end function resetfontsize(k::Symbol) + i = initial(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 -"Reset all fonts to default size" +"Reset all fonts to initial size" function resetfontsizes() for k in (:titlefont, :guidefont, :tickfont, :legendfont) resetfontsize(k) From 9c2c548874f0d782cfe5522ea3aaa9b12ebe31e9 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Wed, 17 May 2017 17:10:21 +0200 Subject: [PATCH 4/7] create dict _initial_fontsizes and copy from that. creates new method scalefontsizes() [no keyword] --- src/args.jl | 8 +++++--- src/components.jl | 24 +++++++++--------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/args.jl b/src/args.jl index be5c564c..f93aeae6 100644 --- a/src/args.jl +++ b/src/args.jl @@ -335,9 +335,11 @@ const _all_defaults = KW[ _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) +# to be able to reset font sizes to initial values +const _initial_fontsizes = Dict(:titlefont => deepcopy(_subplot_defaults[:titlefont]), + :legendfont => deepcopy(_subplot_defaults[:legendfont]), + :tickfont => deepcopy(_axis_defaults[:tickfont]), + :guidefont => deepcopy(_axis_defaults[:guidefont])) const _all_args = sort(collect(union(map(keys, _all_defaults)...))) diff --git a/src/components.jl b/src/components.jl index e7eb74d6..1f53f2d1 100644 --- a/src/components.jl +++ b/src/components.jl @@ -303,21 +303,15 @@ function scalefontsizes(factor::Number) end end -function resetfontsize(k::Symbol) - i = initial(k) - f = default(k) - # some fonts don't have an initial value! - if i != false - f.pointsize = i.pointsize - default(k, i) - end -end - -"Reset all fonts to initial size" -function resetfontsizes() - for k in (:titlefont, :guidefont, :tickfont, :legendfont) - resetfontsize(k) - end +"Resets font sizes to initial default values" +function scalefontsizes() + for k in (:titlefont, :guidefont, :tickfont, :legendfont) + f = default(k) + if haskey(_initial_fontsizes,k) + factor = f.pointsize / _initial_fontsizes[k].pointsize + scalefontsize(k, 1.0/factor) + end + end end "Wrap a string with font info" From 915c41c9d945ce845c77eeba2889f833464f4f69 Mon Sep 17 00:00:00 2001 From: Florian Oswald Date: Wed, 17 May 2017 17:48:03 +0200 Subject: [PATCH 5/7] addressed changes requested --- src/args.jl | 27 ++++----------------------- src/components.jl | 4 ++-- 2 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/args.jl b/src/args.jl index f93aeae6..af791198 100644 --- a/src/args.jl +++ b/src/args.jl @@ -336,10 +336,10 @@ const _all_defaults = KW[ ] # to be able to reset font sizes to initial values -const _initial_fontsizes = Dict(:titlefont => deepcopy(_subplot_defaults[:titlefont]), - :legendfont => deepcopy(_subplot_defaults[:legendfont]), - :tickfont => deepcopy(_axis_defaults[:tickfont]), - :guidefont => deepcopy(_axis_defaults[:guidefont])) +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)...))) @@ -525,25 +525,6 @@ function default(d::KW, k::Symbol) get(d, k, default(k)) 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 - # ----------------------------------------------------------------------------- diff --git a/src/components.jl b/src/components.jl index 1f53f2d1..de3b1197 100644 --- a/src/components.jl +++ b/src/components.jl @@ -307,8 +307,8 @@ end function scalefontsizes() for k in (:titlefont, :guidefont, :tickfont, :legendfont) f = default(k) - if haskey(_initial_fontsizes,k) - factor = f.pointsize / _initial_fontsizes[k].pointsize + for k in keys(_initial_fontsizes) + factor = f.pointsize / _initial_fontsizes[k] scalefontsize(k, 1.0/factor) end end From 6cca7632849c218c122c934134b58588477be32f Mon Sep 17 00:00:00 2001 From: florian oswald Date: Wed, 17 May 2017 21:07:54 +0200 Subject: [PATCH 6/7] removed test for k --- src/components.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components.jl b/src/components.jl index de3b1197..efbe946e 100644 --- a/src/components.jl +++ b/src/components.jl @@ -307,7 +307,7 @@ end function scalefontsizes() for k in (:titlefont, :guidefont, :tickfont, :legendfont) f = default(k) - for k in keys(_initial_fontsizes) + if k in keys(_initial_fontsizes) factor = f.pointsize / _initial_fontsizes[k] scalefontsize(k, 1.0/factor) end From d3b825b49f89f3822da06d3136cee48fba735ca2 Mon Sep 17 00:00:00 2001 From: florian oswald Date: Mon, 12 Jun 2017 12:29:19 +0200 Subject: [PATCH 7/7] fix docstrings. provide 2 methods `scalefontsizes` now, with and without an argument. no argument version resets to initial values, with argument you rescale the current sizes. --- src/components.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components.jl b/src/components.jl index efbe946e..6de1387a 100644 --- a/src/components.jl +++ b/src/components.jl @@ -297,13 +297,23 @@ 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 -"Resets font sizes to initial default values" +""" + scalefontsizes() + +Resets font sizes to initial default values. +""" function scalefontsizes() for k in (:titlefont, :guidefont, :tickfont, :legendfont) f = default(k)