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
end
# # special handling for Surface... need to properly unwrap and re-wrap
# function _apply_type_recipe(plotattributes, v::Surface)
# T = eltype(v.surf)
# @show T
# if T <: Integer || T <: AbstractFloat
# v
# else
# ret = _apply_type_recipe(plotattributes, v.surf)
# if typeof(ret) <: Formatted
# Formatted(Surface(ret.data), ret.formatter)
# else
# v
# end
# end
# end
# special handling for Surface... need to properly unwrap and re-wrap
_apply_type_recipe(plotattributes, v::Surface{<:AMat{<:DataPoint}}) = v
function _apply_type_recipe(plotattributes, v::Surface)
ret = _apply_type_recipe(plotattributes, v.surf)
if typeof(ret) <: Formatted
Formatted(Surface(ret.data), ret.formatter)
else
Surface(ret.data)
end
end
# don't do anything for ints or floats
_apply_type_recipe(plotattributes, v::AbstractArray{<:DataPoint}, letter) = v
@ -309,9 +304,9 @@ end
end
# # --------------------------------------------------------------------
# # 1 argument
# # --------------------------------------------------------------------
# --------------------------------------------------------------------
# 1 argument
# --------------------------------------------------------------------
# helper function to ensure relevant attributes are wrapped by Surface
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))
# 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)
n,m = axes(mat)
wrap_surfaces(plotattributes)
@ -339,7 +334,7 @@ all3D(plotattributes) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap
end
# 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)
mat = fmt.data
n,m = axes(mat)
@ -351,14 +346,14 @@ end
end
# 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
SliceIt, nothing, Volume(vol, args...), nothing
end
# # images - grays
function clamp_greys!(mat::AMat{T}) where T<:Gray
# images - grays
function clamp_greys!(mat::AMat{<:Gray})
for i in eachindex(mat)
mat[i].val < 0 && (mat[i] = Gray(0))
mat[i].val > 1 && (mat[i] = Gray(1))
@ -366,7 +361,7 @@ function clamp_greys!(mat::AMat{T}) where T<:Gray
mat
end
@recipe function f(mat::AMat{T}) where T<:Gray
@recipe function f(mat::AMat{<:Gray})
n, m = axes(mat)
if is_seriestype_supported(:image)
seriestype := :image
@ -381,8 +376,7 @@ end
end
end
# # images - colors
# images - colors
@recipe function f(mat::AMat{T}) where T<:Colorant
n, m = axes(mat)
@ -400,8 +394,8 @@ end
end
end
#
# # plotting arbitrary shapes/polygons
# plotting arbitrary shapes/polygons
@recipe function f(shape::Shape)
seriestype --> :shape
@ -461,14 +455,14 @@ function tryrange(F, vec)
end
error("$F is not a Function, or is not defined at any of the values $vec")
end
#
# # --------------------------------------------------------------------
# # 2 arguments
# # --------------------------------------------------------------------
#
#
# # if functions come first, just swap the order (not to be confused with parametric functions...
# # as there would be more than one function passed in)
# --------------------------------------------------------------------
# 2 arguments
# --------------------------------------------------------------------
# if functions come first, just swap the order (not to be confused with parametric
# functions... as there would be more than one function passed in)
@recipe function f(f::FuncOrFuncs{F}, x) where F<:Function
F2 = typeof(x)
@ -476,47 +470,33 @@ end
x, f
end
#
# # --------------------------------------------------------------------
# # 3 arguments
# # --------------------------------------------------------------------
#
#
# # 3d line or scatter
# --------------------------------------------------------------------
# 3 arguments
# --------------------------------------------------------------------
# 3d line or scatter
@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
end
@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)
SliceIt, x, y, z
end
#
# # surface-like... function
# surface-like... 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)
SliceIt, x, y, Surface(zf, x, y) # TODO: replace with SurfaceFunction when supported
end
#
# # surface-like... matrix grid
# surface-like... matrix grid
@recipe function f(x::AVec, y::AVec, z::AMat)
if !like_surface(get(plotattributes, :seriestype, :none))
@ -526,7 +506,7 @@ end
SliceIt, x, y, Surface(z)
end
# # images - grays
# images - grays
@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Gray
if is_seriestype_supported(:image)
@ -542,7 +522,7 @@ end
end
end
# # images - colors
# images - colors
@recipe function f(x::AVec, y::AVec, mat::AMat{T}) where T<:Colorant
if is_seriestype_supported(:image)
@ -558,14 +538,12 @@ 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)
xscale, yscale = [get(plotattributes, sym, :identity) for sym=(:xscale,:yscale)]
_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)
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}
mapFuncOrFuncs(fx, u), mapFuncOrFuncs(fy, u), mapFuncOrFuncs(fz, u)
end
@ -598,12 +576,12 @@ end
fx, fy, fz, range(umin, stop = umax, length = numPoints)
end
#
#
# # --------------------------------------------------------------------
# # Lists of tuples and GeometryTypes.Points
# # --------------------------------------------------------------------
#
# --------------------------------------------------------------------
# Lists of tuples and GeometryTypes.Points
# --------------------------------------------------------------------
@recipe f(v::AVec{<:Tuple}) = unzip(v)
@recipe f(v::AVec{<:GeometryTypes.Point}) = unzip(v)
@ -613,23 +591,10 @@ end
# 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)
#
# # --------------------------------------------------------------------
# # handle grouping
# # --------------------------------------------------------------------
# @recipe function f(groupby::GroupBy, args...)
# for (i,glab) in enumerate(groupby.groupLabels)
# # 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
# --------------------------------------------------------------------
# handle grouping
# --------------------------------------------------------------------
splittable_kw(key, val, lengthGroup) = false
splittable_kw(key, val::AbstractArray, lengthGroup) = !(key in (:group, :color_palette)) && length(axes(val,1)) == lengthGroup