update new heme() function

This commit is contained in:
Daniel Schwabeneder 2017-12-04 14:54:35 +01:00
parent 899afd625a
commit b987331b4f
2 changed files with 30 additions and 44 deletions

View File

@ -417,6 +417,7 @@ const _all_defaults = KW[
]
const _initial_defaults = deepcopy(_all_defaults)
const _initial_axis_defaults = deepcopy(_axis_defaults)
# to be able to reset font sizes to initial values
const _initial_fontsizes = Dict(:titlefont => _subplot_defaults[:titlefontsize],
@ -614,7 +615,10 @@ function default(d::KW, k::Symbol)
get(d, k, default(k))
end
reset_defaults() = foreach(merge!, _all_defaults, _initial_defaults)
function reset_defaults()
foreach(merge!, _all_defaults, _initial_defaults)
merge!(_axis_defaults, _initial_axis_defaults)
end
# -----------------------------------------------------------------------------

View File

@ -4,53 +4,35 @@
Specify the colour theme for plots.
"""
function theme(s::Symbol; kw...)
defaults = merge(_initial_defaults..., s.defaults, kw)
if haskey(s.defaults, :gradient)
# Reset to defaults to overwrite active team
reset_defaults()
thm = PlotThemes._themes[s]
# Set the theme's gradient as default
if haskey(thm.defaults, :gradient)
PlotUtils.clibrary(:misc)
PlotUtils.default_cgrad(default = :sequential, sequential = PlotThemes.gradient_name(s))
else
PlotUtils.clibrary(:Plots)
PlotUtils.default_cgrad(default = :sequential, sequential = :inferno)
end
default(; defaults...)
# maybe overwrite the theme's gradient
kw = KW(kw)
if haskey(kw, :gradient)
kwgrad = pop!(kw, :gradient)
for clib in clibraries()
if kwgrad in cgradients(clib)
PlotUtils.clibrary(clib)
PlotUtils.default_cgrad(default = :sequential, sequential = kwgrad)
break
end
end
end
# Set the theme's defaults
default(; thm.defaults..., kw...)
return
end
# function theme(s::Symbol; kw...)
# # reset?
# if s == :none || s == :default
# PlotUtils.clibrary(:Plots)
# PlotUtils.default_cgrad(default = :sequential, sequential = :inferno)
# default(;
# bg = :white,
# bglegend = :match,
# bginside = :match,
# bgoutside = :match,
# fg = :auto,
# fglegend = :match,
# fggrid = :match,
# fgaxis = :match,
# fgtext = :match,
# fgborder = :match,
# fgguide = :match,
# palette = :auto
# )
# return
# end
#
# # update the default gradient and other defaults
# thm = PlotThemes._themes[s]
# if thm.gradient != nothing
# PlotUtils.clibrary(:misc)
# PlotUtils.default_cgrad(default = :sequential, sequential = PlotThemes.gradient_name(s))
# end
# default(;
# bg = thm.bg_secondary,
# bginside = thm.bg_primary,
# fg = thm.lines,
# fgtext = thm.text,
# fgguide = thm.text,
# fglegend = thm.text,
# palette = thm.palette,
# kw...
# )
# end
@deprecate set_theme(s) theme(s)