clean up series.jl

This commit is contained in:
Daniel Schwabeneder 2020-03-31 22:13:27 +02:00
parent 22496535d1
commit 945874ca7d

View File

@ -205,21 +205,16 @@ function _apply_type_recipe(plotattributes, v::AbstractArray, letter)
return w return w
end end
# # special handling for Surface... need to properly unwrap and re-wrap # special handling for Surface... need to properly unwrap and re-wrap
# function _apply_type_recipe(plotattributes, v::Surface) _apply_type_recipe(plotattributes, v::Surface{<:AMat{<:DataPoint}}) = v
# T = eltype(v.surf) function _apply_type_recipe(plotattributes, v::Surface)
# @show T ret = _apply_type_recipe(plotattributes, v.surf)
# if T <: Integer || T <: AbstractFloat if typeof(ret) <: Formatted
# v Formatted(Surface(ret.data), ret.formatter)
# else else
# ret = _apply_type_recipe(plotattributes, v.surf) Surface(ret.data)
# if typeof(ret) <: Formatted end
# Formatted(Surface(ret.data), ret.formatter) end
# else
# v
# end
# end
# end
# don't do anything for ints or floats # don't do anything for ints or floats
_apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v _apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v
@ -309,9 +304,9 @@ end
end end
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
# # 1 argument # 1 argument
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
# helper function to ensure relevant attributes are wrapped by Surface # helper function to ensure relevant attributes are wrapped by Surface
function wrap_surfaces(plotattributes::AKW) function wrap_surfaces(plotattributes::AKW)
@ -328,7 +323,7 @@ end
all3D(plotattributes) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :plots_heatmap), get(plotattributes, :seriestype, :none)) all3D(plotattributes) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :plots_heatmap), get(plotattributes, :seriestype, :none))
# return a surface if this is a 3d plot, otherwise let it be sliced up # return a surface if this is a 3d plot, otherwise let it be sliced up
@recipe function f(mat::AMat{T}) where T<:Union{Integer,AbstractFloat,Missing} @recipe function f(mat::AMat{<:MaybeNumber})
if all3D(plotattributes) if all3D(plotattributes)
n,m = axes(mat) n,m = axes(mat)
wrap_surfaces(plotattributes) wrap_surfaces(plotattributes)
@ -339,7 +334,7 @@ all3D(plotattributes) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap
end end
# if a matrix is wrapped by Formatted, do similar logic, but wrap data with Surface # if a matrix is wrapped by Formatted, do similar logic, but wrap data with Surface
@recipe function f(fmt::Formatted{T}) where T<:AbstractMatrix @recipe function f(fmt::Formatted{<:AMat})
if all3D(plotattributes) if all3D(plotattributes)
mat = fmt.data mat = fmt.data
n,m = axes(mat) n,m = axes(mat)
@ -351,14 +346,14 @@ end
end end
# assume this is a Volume, so construct one # assume this is a Volume, so construct one
@recipe function f(vol::AbstractArray{T,3}, args...) where T<:Union{Number,Missing} @recipe function f(vol::AbstractArray{T, 3}, args...) where T<:Union{Number,Missing}
seriestype := :volume seriestype := :volume
SliceIt, nothing, Volume(vol, args...), nothing SliceIt, nothing, Volume(vol, args...), nothing
end end
# # images - grays # images - grays
function clamp_greys!(mat::AMat{T}) where T<:Gray function clamp_greys!(mat::AMat{<:Gray})
for i in eachindex(mat) for i in eachindex(mat)
mat[i].val < 0 && (mat[i] = Gray(0)) mat[i].val < 0 && (mat[i] = Gray(0))
mat[i].val > 1 && (mat[i] = Gray(1)) mat[i].val > 1 && (mat[i] = Gray(1))
@ -366,7 +361,7 @@ function clamp_greys!(mat::AMat{T}) where T<:Gray
mat mat
end end
@recipe function f(mat::AMat{T}) where T<:Gray @recipe function f(mat::AMat{<:Gray})
n, m = axes(mat) n, m = axes(mat)
if is_seriestype_supported(:image) if is_seriestype_supported(:image)
seriestype := :image seriestype := :image
@ -381,8 +376,7 @@ end
end end
end end
# # images - colors # images - colors
@recipe function f(mat::AMat{T}) where T<:Colorant @recipe function f(mat::AMat{T}) where T<:Colorant
n, m = axes(mat) n, m = axes(mat)
@ -400,8 +394,8 @@ end
end end
end end
#
# # plotting arbitrary shapes/polygons # plotting arbitrary shapes/polygons
@recipe function f(shape::Shape) @recipe function f(shape::Shape)
seriestype --> :shape seriestype --> :shape
@ -461,14 +455,14 @@ function tryrange(F, vec)
end end
error("$F is not a Function, or is not defined at any of the values $vec") error("$F is not a Function, or is not defined at any of the values $vec")
end end
#
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
# # 2 arguments # 2 arguments
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
#
#
# # if functions come first, just swap the order (not to be confused with parametric functions... # if functions come first, just swap the order (not to be confused with parametric
# # as there would be more than one function passed in) # functions... as there would be more than one function passed in)
@recipe function f(f::FuncOrFuncs{F}, x) where F<:Function @recipe function f(f::FuncOrFuncs{F}, x) where F<:Function
F2 = typeof(x) F2 = typeof(x)
@ -476,47 +470,33 @@ end
x, f x, f
end end
#
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
# # 3 arguments # 3 arguments
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
#
#
# # 3d line or scatter # 3d line or scatter
@recipe function f(x::AVec, y::AVec, z::AVec) @recipe function f(x::AVec, y::AVec, z::AVec)
# st = get(plotattributes, :seriestype, :none)
# if st == :scatter
# plotattributes[:seriestype] = :scatter3d
# elseif !is3d(st)
# plotattributes[:seriestype] = :path3d
# end
SliceIt, x, y, z SliceIt, x, y, z
end end
@recipe function f(x::AMat, y::AMat, z::AMat) @recipe function f(x::AMat, y::AMat, z::AMat)
# st = get(plotattributes, :seriestype, :none)
# if size(x) == size(y) == size(z)
# if !is3d(st)
# seriestype := :path3d
# end
# end
wrap_surfaces(plotattributes) wrap_surfaces(plotattributes)
SliceIt, x, y, z SliceIt, x, y, z
end end
#
# # surface-like... function # surface-like... function
@recipe function f(x::AVec, y::AVec, zf::Function) @recipe function f(x::AVec, y::AVec, zf::Function)
# x = X <: Number ? sort(x) : x
# y = Y <: Number ? sort(y) : y
wrap_surfaces(plotattributes) wrap_surfaces(plotattributes)
SliceIt, x, y, Surface(zf, x, y) # TODO: replace with SurfaceFunction when supported SliceIt, x, y, Surface(zf, x, y) # TODO: replace with SurfaceFunction when supported
end end
#
# # surface-like... matrix grid # surface-like... matrix grid
@recipe function f(x::AVec, y::AVec, z::AMat) @recipe function f(x::AVec, y::AVec, z::AMat)
if !like_surface(get(plotattributes, :seriestype, :none)) if !like_surface(get(plotattributes, :seriestype, :none))
@ -526,7 +506,7 @@ end
SliceIt, x, y, Surface(z) SliceIt, x, y, Surface(z)
end end
# # images - grays # images - grays
@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Gray @recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Gray
if is_seriestype_supported(:image) if is_seriestype_supported(:image)
@ -542,7 +522,7 @@ end
end end
end end
# # images - colors # images - colors
@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Colorant @recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Colorant
if is_seriestype_supported(:image) if is_seriestype_supported(:image)
@ -558,14 +538,12 @@ end
end end
end end
#
#
# # --------------------------------------------------------------------
# # Parametric functions
# # --------------------------------------------------------------------
# # --------------------------------------------------------------------
# # special handling... xmin/xmax with parametric function(s) # Parametric functions
# --------------------------------------------------------------------
# special handling... xmin/xmax with parametric function(s)
@recipe function f(f::Function, xmin::Number, xmax::Number) @recipe function f(f::Function, xmin::Number, xmax::Number)
xscale, yscale = [get(plotattributes, sym, :identity) for sym=(:xscale,:yscale)] xscale, yscale = [get(plotattributes, sym, :identity) for sym=(:xscale,:yscale)]
_scaled_adapted_grid(f, xscale, yscale, xmin, xmax) _scaled_adapted_grid(f, xscale, yscale, xmin, xmax)
@ -589,8 +567,8 @@ function _scaled_adapted_grid(f, xscale, yscale, xmin, xmax)
xinv.(xs), yinv.(ys) xinv.(xs), yinv.(ys)
end end
#
# # special handling... 3D parametric function(s) # special handling... 3D parametric function(s)
@recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) where {F<:Function,G<:Function,H<:Function} @recipe function f(fx::FuncOrFuncs{F}, fy::FuncOrFuncs{G}, fz::FuncOrFuncs{H}, u::AVec) where {F<:Function,G<:Function,H<:Function}
mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u) mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u)
end end
@ -598,12 +576,12 @@ end
fx, fy, fz, range(umin, stop = umax, length = numPoints) fx, fy, fz, range(umin, stop = umax, length = numPoints)
end end
#
#
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
# # Lists of tuples and GeometryTypes.Points # Lists of tuples and GeometryTypes.Points
# # -------------------------------------------------------------------- # --------------------------------------------------------------------
#
@recipe f(v::AVec{<:Tuple}) = unzip(v) @recipe f(v::AVec{<:Tuple}) = unzip(v)
@recipe f(v::AVec{<:GeometryTypes.Point}) = unzip(v) @recipe f(v::AVec{<:GeometryTypes.Point}) = unzip(v)
@ -613,23 +591,10 @@ end
# Special case for 4-tuples in :ohlc series # Special case for 4-tuples in :ohlc series
@recipe f(xyuv::AVec{<:Tuple{R1,R2,R3,R4}}) where {R1,R2,R3,R4} = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv) @recipe f(xyuv::AVec{<:Tuple{R1,R2,R3,R4}}) where {R1,R2,R3,R4} = get(plotattributes,:seriestype,:path)==:ohlc ? OHLC[OHLC(t...) for t in xyuv] : unzip(xyuv)
#
# # --------------------------------------------------------------------
# # handle grouping
# # --------------------------------------------------------------------
# @recipe function f(groupby::GroupBy, args...) # --------------------------------------------------------------------
# for (i,glab) in enumerate(groupby.groupLabels) # handle grouping
# # create a new series, with the label of the group, and an idxfilter (to be applied in slice_and_dice) # --------------------------------------------------------------------
# # TODO: use @series instead
# @show i, glab, groupby.groupIds[i]
# di = copy(plotattributes)
# get!(di, :label, string(glab))
# get!(di, :idxfilter, groupby.groupIds[i])
# push!(series_list, RecipeData(di, args))
# end
# nothing
# end
splittable_kw(key, val, lengthGroup) = false splittable_kw(key, val, lengthGroup) = false
splittable_kw(key, val::AbstractArray, lengthGroup) = !(key in (:group, :color_palette)) && length(axes(val,1)) == lengthGroup splittable_kw(key, val::AbstractArray, lengthGroup) = !(key in (:group, :color_palette)) && length(axes(val,1)) == lengthGroup