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
@@ -552,19 +558,6 @@ aliases(aliasMap::Dict{Symbol,Symbol}, val) =
552558
553559# -----------------------------------------------------------------------------
554560# legend
555- add_aliases (:legend_position , :legend , :leg , :key , :legends )
556- add_aliases (
557- :legend_background_color ,
558- :bg_legend ,
559- :bglegend ,
560- :bgcolor_legend ,
561- :bg_color_legend ,
562- :background_legend ,
563- :background_colour_legend ,
564- :bgcolour_legend ,
565- :bg_colour_legend ,
566- :background_color_legend ,
567- )
568561add_aliases (
569562 :legend_foreground_color ,
570563 :fg_legend ,
@@ -2166,12 +2159,12 @@ Also creates pluralized and non-underscore aliases for these keywords.
21662159"""
21672160macro add_attributes (level, expr, args... )
21682161 match_table = :(:match = ())
2169- alias_dict = :( :aliases = Dict {Symbol, Symbol} () )
2162+ alias_dict = KW ( )
21702163 for arg in args
21712164 if arg. head == :(= ) && arg. args[1 ] == QuoteNode (:match )
21722165 match_table = arg
21732166 elseif arg. head == :(= ) && arg. args[1 ] == QuoteNode (:aliases )
2174- alias_dict = arg
2167+ alias_dict = eval ( arg. args[ 2 ])
21752168 else
21762169 @warn " Unsupported extra argument $arg will be ignored"
21772170 end
@@ -2195,6 +2188,7 @@ macro add_attributes(level, expr, args...)
21952188 value = QuoteNode (:match )
21962189 end
21972190 field = QuoteNode (Symbol (" _" , level, " _defaults" ))
2191+ aliases = get (alias_dict, exp_key, nothing )
21982192 push! (
21992193 insert_block. args,
22002194 Expr (
@@ -2205,13 +2199,21 @@ macro add_attributes(level, expr, args...)
22052199 :(Plots. add_aliases ($ (QuoteNode (exp_key)), $ (QuoteNode (pl_key)))),
22062200 :(Plots. add_aliases (
22072201 $ (QuoteNode (exp_key)),
2208- $ (QuoteNode (Plots. make_non_underscore (exp_key))),
2202+ $ (QuoteNode (Plots. make_non_underscore (exp_key))). .. ,
22092203 )),
22102204 :(Plots. add_aliases (
22112205 $ (QuoteNode (exp_key)),
2212- $ (QuoteNode (Plots. make_non_underscore (pl_key))),
2206+ $ (QuoteNode (Plots. make_non_underscore (pl_key))). .. ,
22132207 )),
22142208 )
2209+ if aliases != = nothing
2210+ pl_aliases = Plots. makeplural .(aliases)
2211+ push! (
2212+ insert_block. args,
2213+ :(Plots. add_aliases ($ (QuoteNode (exp_key)), $ (aliases). .. , $ (pl_aliases). .. , $ (Iterators. flatten (Plots. make_non_underscore .(aliases))). .. , $ (Iterators. flatten (Plots. make_non_underscore .(pl_aliases))). .. ,
2214+ ))
2215+ )
2216+ end
22152217 end
22162218 quote
22172219 Base. @kwdef $ original
0 commit comments