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

@ -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