PlutoUI.jl icon indicating copy to clipboard operation
PlutoUI.jl copied to clipboard

Clock limit

Open IgorDouven opened this issue 5 years ago • 3 comments

I like the Clock feature a lot. But is there a possibility to set an end point? Now, when I let the clock run, it will eventually error, given that it tries to go on even when there are no more data to plot. Looping back would be an alternative.

IgorDouven avatar Sep 23 '20 07:09 IgorDouven

You can loop using mod1:

@bind i Clock()
let
	data_index = mod1(i, length(data))
	plot(data[data_index])
end

But a stopping feature would be nice.

fonsp avatar Sep 23 '20 09:09 fonsp

Thanks -- works perfectly!

Op wo 23 sep. 2020 om 11:42 schreef Fons van der Plas < [email protected]>:

You can loop using mod1:

@bind i Clock()

let data_index = mod1(i, length(data)) plot(data[data_index])end

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/fonsp/PlutoUI.jl/issues/45#issuecomment-697254342, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIFACLG3GRMSVP24HNIOQ5LSHG7H5ANCNFSM4RWWH63A .

IgorDouven avatar Sep 23 '20 10:09 IgorDouven

This is a nice solution for now. However, mod1 throws an error until the clock is started, because the bound variable is nothing.

So for my animation in Pluto, I used something like

data_index = mod1( (i |> isnothing) ? 1 : i, length(data))

so that the first frame of the animation is displayed until "Start" is clicked.

rmslp avatar Jul 31 '21 19:07 rmslp