How to record interactive visualisation with cursor clicking?

I have an interactive topoplot: clicking on a channel marker shows its name. I want to record it so that I can see how I press a marker with the cursor and its name changes. Do you know how to do this?

I tried, but the animation remains frozen.

let    
    f = Figure(backgroundcolor = RGBf(0.98, 0.98, 0.98))
    data, pos = TopoPlots.example_data()
    N = 1:length(pos)

    positions = Observable(rand(Point2f, 10))
    topo_axis = Axis(f[1, 1],  aspect = DataAspect())
    
	xlims!(low = -0.2, high = 1.2)
	ylims!(low = -0.2, high = 1.2)
    cmap = collect(ColorScheme(range(colorant"black", colorant"black", length=2)))
    
    mark_size = repeat([21], 64)
    mark_color = repeat([1], 64)
    labels = ["s$i" for i in 1:size(data, 1)]
    topo = eeg_topoplot!(topo_axis, data[:, 340, 1], labels;
        mark_color, 
        N, 
        positions=pos, 
        interpolation=NullInterpolator(),
        enlarge=1,
        colormap = cmap,
        markersize = mark_size,
        label_text=false
    ) 
    hidedecorations!(current_axis())
    hidespines!(current_axis())

    i = Observable(1)
    str = lift((i, labels) -> "$(labels[i])", i, labels)
    text!(topo_axis, 1, 1, text = str,  align = (:center, :center))
    on(events(f).mousebutton, priority = 2) do event
        if event.button == Mouse.left && event.action == Mouse.press
            plt, p = pick(topo_axis)
            i[] = p
        end
    end
    record(f, "test.mp4"; framerate = 10) do io
        for i = 1:100
            sleep(1/fps)
            recordframe!(io)
        end
    end
    f
end

If you goal is to record a video where specific markers are selected over time I would just trigger i[] = p in record. (You also don’t need the sleep then)

For recording a figure you’re interacting with you can try this. It’s more or less what record is doing but with a display after VideoStream to reopen the window.

fig, ax, p = scatter(rand(10))
io = VideoStream(fig, format = "mp4", framerate = 10)
display(fig)
for i = 1:100
    sleep(1/10)
    recordframe!(io)
end
save("test.mp4", io)
1 Like

Thank you for trying, but the window did not reopen for me.

Try VideoStream(...; visible=true)

1 Like

Cool! Thanks, now it works!
Cursor is not shown, but still great.

At some point I implemented a little scatter plot that went with the mouse and changed size/color when clicked :wink:
Could have a recipe for that… But I actually started using screen2gif quite a bit for recordings, instead of setting up VideoRecorder etc :wink:

Yeah, screen2gif is great!

Supposedly ffmpeg can also do screen recordings, never tried that though.