Merge pull request #2135 from yha/char-recipe

Replace low-level Char handling with a type recipe.
This commit is contained in:
Yuval 2019-08-11 18:37:31 +03:00 committed by GitHub
commit 3dcc7e5556
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -1101,6 +1101,11 @@ timeformatter(t) = string(Dates.Time(Dates.Nanosecond(t)))
@recipe f(::Type{Dates.Time}, t::Dates.Time) = (t -> Dates.value(t), timeformatter)
@recipe f(::Type{P}, t::P) where P <: Dates.Period = (t -> Dates.value(t), t -> string(P(t)))
# -------------------------------------------------
# Characters
@recipe f(::Type{<:AbstractChar}, ::AbstractChar) = (string, string)
# -------------------------------------------------
# Complex Numbers

View File

@ -7,12 +7,12 @@
# note: returns meta information... mainly for use with automatic labeling from DataFrames for now
const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}}
const DataPoint = Union{Number, AbstractString, AbstractChar, Missing}
const DataPoint = Union{Number, AbstractString, Missing}
const SeriesData = Union{AVec{<:DataPoint}, Function, Surface, Volume}
prepareSeriesData(x) = error("Cannot convert $(typeof(x)) to series data for plotting")
prepareSeriesData(::Nothing) = nothing
prepareSeriesData(s::SeriesData) = handlemissings(handlechars(s))
prepareSeriesData(s::SeriesData) = handlemissings(s)
handlemissings(v) = v
handlemissings(v::AbstractArray{Union{T,Missing}}) where T <: Number = replace(v, missing => NaN)
@ -20,9 +20,6 @@ handlemissings(v::AbstractArray{Union{T,Missing}}) where T <: AbstractString = r
handlemissings(s::Surface) = Surface(handlemissings(s.surf))
handlemissings(v::Volume) = Volume(handlemissings(v.v), v.x_extents, v.y_extents, v.z_extents)
handlechars(x) = x
handlechars(c::AVec{<:AbstractChar}) = string.(c)
# default: assume x represents a single series
convertToAnyVector(x) = Any[prepareSeriesData(x)]