11makeplural (s:: Symbol ) = last (string (s)) == ' s' ? s : Symbol (string (s, " s" ))
2- make_non_underscore (s:: Symbol ) = Symbol (replace (string (s), " _" => " " ))
2+ function make_non_underscore (s:: Symbol )
3+ str = string (s)
4+ n = count (" _" , str)
5+ Tuple (Symbol (replace (str, " _" => " " , count = c)) for c in 1 : n)
6+ end
37
48const _keyAliases = Dict {Symbol,Symbol} ()
59
2226function add_non_underscore_aliases! (aliases:: Dict{Symbol,Symbol} )
2327 for (k, v) in aliases
2428 if ' _' in string (k)
25- aliases[make_non_underscore (k)] = v
29+ for nu in make_non_underscore (k)
30+ aliases[nu] = v
31+ end
2632 end
2733 end
2834end
@@ -547,19 +553,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) =
547553
548554# -----------------------------------------------------------------------------
549555# legend
550- add_aliases (:legend_position , :legend , :leg , :key , :legends )
551- add_aliases (
552- :legend_background_color ,
553- :bg_legend ,
554- :bglegend ,
555- :bgcolor_legend ,
556- :bg_color_legend ,
557- :background_legend ,
558- :background_colour_legend ,
559- :bgcolour_legend ,
560- :bg_colour_legend ,
561- :background_color_legend ,
562- )
563556add_aliases (
564557 :legend_foreground_color ,
565558 :fg_legend ,
@@ -2169,12 +2162,12 @@ Also creates pluralized and non-underscore aliases for these keywords.
21692162"""
21702163macro add_attributes (level, expr, args... )
21712164 match_table = :(:match = ())
2172- alias_dict = :( :aliases = Dict {Symbol, Symbol} () )
2165+ alias_dict = KW ( )
21732166 for arg in args
21742167 if arg. head == :(= ) && arg. args[1 ] == QuoteNode (:match )
21752168 match_table = arg
21762169 elseif arg. head == :(= ) && arg. args[1 ] == QuoteNode (:aliases )
2177- alias_dict = arg
2170+ alias_dict = eval ( arg. args[ 2 ])
21782171 else
21792172 @warn " Unsupported extra argument $arg will be ignored"
21802173 end
@@ -2198,6 +2191,7 @@ macro add_attributes(level, expr, args...)
21982191 value = QuoteNode (:match )
21992192 end
22002193 field = QuoteNode (Symbol (" _" , level, " _defaults" ))
2194+ aliases = get (alias_dict, exp_key, nothing )
22012195 push! (
22022196 insert_block. args,
22032197 Expr (
@@ -2208,13 +2202,21 @@ macro add_attributes(level, expr, args...)
22082202 :(Plots. add_aliases ($ (QuoteNode (exp_key)), $ (QuoteNode (pl_key)))),
22092203 :(Plots. add_aliases (
22102204 $ (QuoteNode (exp_key)),
2211- $ (QuoteNode (Plots. make_non_underscore (exp_key))),
2205+ $ (QuoteNode (Plots. make_non_underscore (exp_key))). .. ,
22122206 )),
22132207 :(Plots. add_aliases (
22142208 $ (QuoteNode (exp_key)),
2215- $ (QuoteNode (Plots. make_non_underscore (pl_key))),
2209+ $ (QuoteNode (Plots. make_non_underscore (pl_key))). .. ,
22162210 )),
22172211 )
2212+ if aliases != = nothing
2213+ pl_aliases = Plots. makeplural .(aliases)
2214+ push! (
2215+ insert_block. args,
2216+ :(Plots. add_aliases ($ (QuoteNode (exp_key)), $ (aliases). .. , $ (pl_aliases). .. , $ (Iterators. flatten (Plots. make_non_underscore .(aliases))). .. , $ (Iterators. flatten (Plots. make_non_underscore .(pl_aliases))). .. ,
2217+ ))
2218+ )
2219+ end
22182220 end
22192221 quote
22202222 Base. @kwdef $ original
0 commit comments