Implement new iterator protocol
This commit is contained in:
parent
0143807515
commit
5205ac38ad
@ -523,9 +523,12 @@ mutable struct EachAnn
|
|||||||
x
|
x
|
||||||
y
|
y
|
||||||
end
|
end
|
||||||
Base.start(ea::EachAnn) = 1
|
|
||||||
Base.done(ea::EachAnn, i) = ea.anns == nothing || isempty(ea.anns.strs) || i > length(ea.y)
|
function Base.iterate(ea::EachAnn, i = 1)
|
||||||
function Base.next(ea::EachAnn, i)
|
if ea.anns == nothing || isempty(ea.anns.strs) || i > length(ea.y)
|
||||||
|
return nothing
|
||||||
|
end
|
||||||
|
|
||||||
tmp = _cycle(ea.anns.strs,i)
|
tmp = _cycle(ea.anns.strs,i)
|
||||||
str,fnt = if isa(tmp, PlotText)
|
str,fnt = if isa(tmp, PlotText)
|
||||||
tmp.str, tmp.font
|
tmp.str, tmp.font
|
||||||
|
|||||||
14
src/utils.jl
14
src/utils.jl
@ -215,15 +215,13 @@ anynan(i::Int, args::Tuple) = any(a -> try isnan(_cycle(a,i)) catch MethodError
|
|||||||
anynan(istart::Int, iend::Int, args::Tuple) = any(i -> anynan(i, args), istart:iend)
|
anynan(istart::Int, iend::Int, args::Tuple) = any(i -> anynan(i, args), istart:iend)
|
||||||
allnan(istart::Int, iend::Int, args::Tuple) = all(i -> anynan(i, args), istart:iend)
|
allnan(istart::Int, iend::Int, args::Tuple) = all(i -> anynan(i, args), istart:iend)
|
||||||
|
|
||||||
function Base.start(itr::SegmentsIterator)
|
Base.iterate(itr::SegmentsIterator, nextidx::Int) =
|
||||||
nextidx = 1
|
function Base.next(itr::SegmentsIterator, nextidx::Int = 1)
|
||||||
if !any(isempty,itr.args) && anynan(1, itr.args)
|
nextidx > itr.n && return nothing
|
||||||
_, nextidx = next(itr, 1)
|
if nextidx == 1 && !any(isempty,itr.args) && anynan(1, itr.args)
|
||||||
|
nextidx = 2
|
||||||
end
|
end
|
||||||
nextidx
|
|
||||||
end
|
|
||||||
Base.done(itr::SegmentsIterator, nextidx::Int) = nextidx > itr.n
|
|
||||||
function Base.next(itr::SegmentsIterator, nextidx::Int)
|
|
||||||
i = istart = iend = nextidx
|
i = istart = iend = nextidx
|
||||||
|
|
||||||
# find the next NaN, and iend is the one before
|
# find the next NaN, and iend is the one before
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user