How to trigger an event after rendering in a Bonito app

With this little Bonito app, how can I call update_cam! after the plot is rendered on the client?

julia> App() do session
         button = Button("reset cam")
         fig = Figure()
         ax = LScene(fig[1, 1])
         scatter!(ax, randn(10), randn(10), randn(10))
         on(button.value) do _
           # this should be called after the plot is done rendering:
           update_cam!(ax.scene, Vec3f(1), Vec3f(0), Vec3f(0,0,1))
         end
         return DOM.div(button, fig)
       end

I have tried:

Bonito.on_document_load(session, js"""                             
        __lookup_interpolated('15348605119376789901').notify(true);
""")    

but I don’t know how to get the ID of the element.

Why do you need to call update_cam! after rendering? Does it error if you do it before, or simply not work? Or do you need to update the cam after rendering for another reason?

I have a 3d plot and there are a couple of issues:

  • On my computer the plot doesn’t rotate around the origin after the first load. It is just slightly out of balance and the plot wobbles around when rotating (it is a sphere).
  • On a colleague’s computer the z-Axis is not straight any more after a while. I can observe the same behavior for me but very rarely and usually if there is some kind of reload happening while I rotate the plot.

I’d do it like this:

using Bonito, WGLMakie

App() do session
    button = Button("reset cam")
    fig = Figure()
    ax = LScene(fig[1, 1])
    scatter!(ax, randn(10), randn(10), randn(10))
    reset = Observable(false)
    connect!(reset, button.value)
    on(reset) do _
        # this should be called after the plot is done rendering:
        update_cam!(ax.scene, Vec3f(1), Vec3f(0), Vec3f(0, 0, 1))
    end
    js = js"""
        $(fig.scene).then(s=> $(reset).notify(true))
    """
    return DOM.div(button, fig, js)
end

You can just interpolate the values/observables into javascript.
If you interpolate a scene into js, it returns a promise which will get resolved as soon as the scene is fully loaded.

Thanks I’ll try it out as soon as I can.

Regarding the rotation issue, I think I know what causes it:

  • It is a 3d object with a texture that takes some time to compute and transmit.
  • The texture updates.
  • During the time the texture updates, the 3d graphic is unresponsive and if you drag it, it looses its center and the z-axis does not point upward any more. The more you drag it during the unresponsive phase, the worse it gets.

Oh, that’s an interesting observation.
Can you open an issue with this?
I can see how this happens, but we should certainly fix it.

Opened the issue [1], thanks!

[1] z-Axis and center of rotation change unintendedly · Issue #4246 · MakieOrg/Makie.jl · GitHub