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 <SimonChrist@gmx.de>

Co-authored-by: Simon Christ <SimonChrist@gmx.de>
This commit is contained in:
Lakshya Khatri 2020-07-02 20:02:37 +05:30 committed by GitHub
parent 079152a69a
commit e3512b0f0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,14 +20,14 @@ function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol})
end end
end end
function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol}) function add_non_underscore_aliases!(aliases::Dict{Symbol,Symbol}, args::Vector{Symbol})
for arg in args for arg in args
s = string(arg) s = string(arg)
if '_' in s if '_' in s
aliases[Symbol(replace(s, "_" => ""))] = arg aliases[Symbol(replace(s, "_" => ""))] = arg
end end
end end
end end
# ------------------------------------------------------------ # ------------------------------------------------------------
const _allAxes = [:auto, :left, :right] const _allAxes = [:auto, :left, :right]
@ -235,7 +235,7 @@ const _bar_width = 0.8
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
const _series_defaults = KW( const _series_defaults = KW(
:label => "AUTO", :label => :auto,
:colorbar_entry => true, :colorbar_entry => true,
:seriescolor => :auto, :seriescolor => :auto,
:seriesalpha => nothing, :seriesalpha => nothing,
@ -1569,6 +1569,20 @@ function _slice_series_args!(plotattributes::AKW, plt::Plot, sp::Subplot, comman
return plotattributes return plotattributes
end 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) function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot)
pkg = plt.backend pkg = plt.backend
globalIndex = plotattributes[:series_plotindex] globalIndex = plotattributes[:series_plotindex]
@ -1637,10 +1651,7 @@ function _update_series_attributes!(plotattributes::AKW, plt::Plot, sp::Subplot)
end end
# set label # set label
label = plotattributes[:label] plotattributes[:label] = label_to_string.(plotattributes[:label], globalIndex)
label = (label == "AUTO" ? "y$globalIndex" : label)
label = label in (:none, nothing, false) ? "" : label
plotattributes[:label] = label
_replace_linewidth(plotattributes) _replace_linewidth(plotattributes)
plotattributes plotattributes