Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert series data to string as fallback. #2519

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ julia = "1"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
RDatasets = "ce6b1742-4840-55fa-b093-852dadbb1d8b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
28 changes: 16 additions & 12 deletions src/series.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# create a new "build_series_args" which converts all inputs into xs = Any[xitems], ys = Any[yitems].
# create a new "build_series_args" which converts all inputs into xs = [xitems], ys = [yitems].
# Special handling for: no args, xmin/xmax, parametric, dataframes
# Then once inputs have been converted, build the series args, map functions, etc.
# This should cut down on boilerplate code and allow more focused dispatch on type
Expand Down Expand Up @@ -35,14 +35,22 @@ series_vector(n::Integer, plotattributes) = [zeros(0) for i in 1:n]
# vector of data points is a single series
series_vector(v::AVec{<:DataPoint}, plotattributes) = [prepareSeriesData(v)]

# vector of arrays
series_vector(v::AVec{<:AbstractArray}, plotattributes) =
vcat((series_vector(vi, plotattributes) for vi in v)...)

# list of things (maybe other vectors, functions, or something else)
function series_vector(v::AVec, plotattributes)
if all(x -> x isa MaybeNumber, v)
series_vector(Vector{MaybeNumber}(v), plotattributes)
elseif all(x -> x isa MaybeString, v)
series_vector(Vector{MaybeString}(v), plotattributes)
else
vcat((series_vector(vi, plotattributes) for vi in v)...)
try
series_vector(string.(v), plotattributes)
catch
vcat((series_vector(vi, plotattributes) for vi in v)...)
end
end
end

Expand All @@ -65,8 +73,10 @@ process_fillrange(range, plotattributes) = series_vector(range, plotattributes)
process_ribbon(ribbon::Number, plotattributes) = [ribbon]
process_ribbon(ribbon, plotattributes) = series_vector(ribbon, plotattributes)
# ribbon as a tuple: (lower_ribbons, upper_ribbons)
process_ribbon(ribbon::Tuple{Any,Any}, plotattributes) = collect(zip(series_vector(ribbon[1], plotattributes),
series_vector(ribbon[2], plotattributes)))
process_ribbon(ribbon::Tuple{S, T}, plotattributes) where {S, T} = collect(zip(
series_vector(ribbon[1], plotattributes),
series_vector(ribbon[2], plotattributes),
))


# --------------------------------------------------------------------
Expand Down Expand Up @@ -166,7 +176,7 @@ struct SliceIt end
end

# this is the default "type recipe"... just pass the object through
@recipe f(::Type{T}, v::T) where {T<:Any} = v
@recipe f(::Type{T}, v::T) where T = v

# this should catch unhandled "series recipes" and error with a nice message
@recipe f(::Type{V}, x, y, z) where {V<:Val} = error("The backend must not support the series type $V, and there isn't a series recipe defined.")
Expand Down Expand Up @@ -572,13 +582,7 @@ end
end
@recipe function f(fs::AbstractArray{F}, xmin::Number, xmax::Number) where F<:Function
xscale, yscale = [get(plotattributes, sym, :identity) for sym=(:xscale,:yscale)]
xs = Array{Any}(undef, length(fs))
ys = Array{Any}(undef, length(fs))
for (i, (x, y)) in enumerate(_scaled_adapted_grid(f, xscale, yscale, xmin, xmax) for f in fs)
xs[i] = x
ys[i] = y
end
xs, ys
unzip(_scaled_adapted_grid.(fs, xscale, yscale, xmin, xmax))
end
@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, u::AVec) where {F<:Function,G<:Function} = mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u)
@recipe f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, umin::Number, umax::Number, n = 200) where {F<:Function,G<:Function} = fx, fy, range(umin, stop = umax, length = n)
Expand Down