From e3512b0f0d43c4b579dad2c795bd8b1cbdee2985 Mon Sep 17 00:00:00 2001 From: Lakshya Khatri Date: Thu, 2 Jul 2020 20:02:37 +0530 Subject: [PATCH] Add label for `label=0` kwarg (#2837) * Add label for `label=0` kwarg * Fix ambiguous comparision of label with 0 * Add methods for handling plot labels * Remove type annotations for series indexes * Replace label conversion code with shorter version * Handel symbol args for labels in more consistent manner * Broadcast label_to_string to handle Array of labels Co-authored-by: Simon Christ Co-authored-by: Simon Christ --- src/args.jl | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/args.jl b/src/args.jl index 7d1b3ae3..e2051abb 100644 --- a/src/args.jl +++ b/src/args.jl @@ -20,14 +20,14 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}) end end -function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol}) - for arg in args - s = string(arg) - if '_' in s - aliases[Symbol(replace(s, "_" => ""))] = arg - end - end -end +function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol}) + for arg in args + s = string(arg) + if '_' in s + aliases[Symbol(replace(s, "_" => ""))] = arg + end + end +end # ------------------------------------------------------------ const _allAxes = [:auto, :left, :right] @@ -235,7 +235,7 @@ const _bar_width = 0.8 # ----------------------------------------------------------------------------- const _series_defaults = KW( - :label => "AUTO", + :label => :auto, :colorbar_entry => true, :seriescolor => :auto, :seriesalpha => nothing, @@ -1569,6 +1569,20 @@ function _slice_series_args!(plotattributes::AKW, plt::Plot, sp::Subplot, comman return plotattributes end +label_to_string(label::Bool, series_plotindex) = label ? label_to_string(:auto, series_plotindex) : "" +label_to_string(label::Nothing, series_plotindex) = "" +label_to_string(label::Missing, series_plotindex) = "" +function label_to_string(label::Symbol, series_plotindex) + if label==:auto + return string("y", series_plotindex) + elseif label==:none + return "" + else + throw(ArgumentError("unsupported symbol $(label) passed to `label`")) + end +end +label_to_string(label, series_plotindex) = string(label) # Fallback to string promotion + function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) pkg = plt.backend globalIndex = plotattributes[:series_plotindex] @@ -1637,10 +1651,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot) end # set label - label = plotattributes[:label] - label = (label == "AUTO" ? "y$globalIndex" : label) - label = label in (:none, nothing, false) ? "" : label - plotattributes[:label] = label + plotattributes[:label] = label_to_string.(plotattributes[:label], globalIndex) _replace_linewidth(plotattributes) plotattributes