update SegmentsIterator to allow for generalized arrays
This commit is contained in:
parent
044daf08d4
commit
cde041e977
@ -415,6 +415,7 @@ function plotly_data(series::Series, letter::Symbol, data)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
plotly_data(v) = v !== nothing ? collect(v) : v
|
plotly_data(v) = v !== nothing ? collect(v) : v
|
||||||
|
plotly_data(v::AbstractArray) = v
|
||||||
plotly_data(surf::Surface) = surf.surf
|
plotly_data(surf::Surface) = surf.surf
|
||||||
plotly_data(v::AbstractArray{R}) where {R<:Rational} = float(v)
|
plotly_data(v::AbstractArray{R}) where {R<:Rational} = float(v)
|
||||||
|
|
||||||
|
|||||||
18
src/utils.jl
18
src/utils.jl
@ -182,13 +182,15 @@ end
|
|||||||
|
|
||||||
mutable struct SegmentsIterator
|
mutable struct SegmentsIterator
|
||||||
args::Tuple
|
args::Tuple
|
||||||
n::Int
|
n1::Int
|
||||||
|
n2::Int
|
||||||
end
|
end
|
||||||
|
|
||||||
function iter_segments(args...)
|
function iter_segments(args...)
|
||||||
tup = Plots.wraptuple(args)
|
tup = Plots.wraptuple(args)
|
||||||
n = maximum(map(length, tup))
|
n1 = minimum(map(firstindex, tup))
|
||||||
SegmentsIterator(tup, n)
|
n2 = maximum(map(lastindex, tup))
|
||||||
|
SegmentsIterator(tup, n1, n2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function iter_segments(series::Series)
|
function iter_segments(series::Series)
|
||||||
@ -199,7 +201,7 @@ function iter_segments(series::Series)
|
|||||||
if series[:seriestype] in (:scatter, :scatter3d)
|
if series[:seriestype] in (:scatter, :scatter3d)
|
||||||
return [[i] for i in eachindex(y)]
|
return [[i] for i in eachindex(y)]
|
||||||
else
|
else
|
||||||
return [i:(i + 1) for i in 1:(length(y) - 1)]
|
return [i:(i + 1) for i in firstindex(y):lastindex(y)-1]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
segs = UnitRange{Int}[]
|
segs = UnitRange{Int}[]
|
||||||
@ -217,13 +219,13 @@ anynan(args::Tuple) = i -> anynan(i,args)
|
|||||||
anynan(istart::Int, iend::Int, args::Tuple) = any(anynan(args), istart:iend)
|
anynan(istart::Int, iend::Int, args::Tuple) = any(anynan(args), istart:iend)
|
||||||
allnan(istart::Int, iend::Int, args::Tuple) = all(anynan(args), istart:iend)
|
allnan(istart::Int, iend::Int, args::Tuple) = all(anynan(args), istart:iend)
|
||||||
|
|
||||||
function Base.iterate(itr::SegmentsIterator, nextidx::Int = 1)
|
function Base.iterate(itr::SegmentsIterator, nextidx::Int = itr.n1)
|
||||||
i = findfirst(!anynan(itr.args), nextidx:itr.n)
|
i = findfirst(!anynan(itr.args), nextidx:itr.n2)
|
||||||
i === nothing && return nothing
|
i === nothing && return nothing
|
||||||
nextval = nextidx + i - 1
|
nextval = nextidx + i - 1
|
||||||
|
|
||||||
j = findfirst(anynan(itr.args), nextval:itr.n)
|
j = findfirst(anynan(itr.args), nextval:itr.n2)
|
||||||
nextnan = j === nothing ? itr.n + 1 : nextval + j - 1
|
nextnan = j === nothing ? itr.n2 + 1 : nextval + j - 1
|
||||||
|
|
||||||
nextval:nextnan-1, nextnan
|
nextval:nextnan-1, nextnan
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user