MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

Keyboard input isn't capture by Jupyter notebook running on a headless server. #4057

Closed EdsterG closed 3 months ago

EdsterG commented 3 months ago

When plotting the basic example, mouse interactivity works but keyboard input isn't captured.

using WGLMakie, Bonito

Page(listen_url="localhost", listen_port=7778)

scatter(1:4, color=1:4)

I can zoom and pan the plot, but I can't reset with ctrl + leftclick. If I change the default modifier for RectangleZoom to left_super I lose zoom functionality, pressing left super seems to do nothing.

This could be related to the error I get right below the plot, but I'm not completely sure:

An exception was thrown in JS: TypeError: canvas.getContext is not a function
Additional message: error initializing scene
Stack trace:
    TypeError: canvas.getContext is not a function
        at threejs_module
EdsterG commented 3 months ago

If the devs have some thoughts on where to start looking to debug this issue, I'm happy to do the work and push a fix.

SimonDanisch commented 3 months ago

Can you reproduce it reliably? Can you try without IJulia?

EdsterG commented 3 months ago

Can you reproduce it reliably?

Yes.

Can you try without IJulia?

This works in my browser without IJulia.

using WGLMakie, Bonito

App() do session::Session
    scatter(1:4, color=1:4)
end

This displays nothing in a local IJulia:

using WGLMakie, Bonito

App() do session::Session
    scatter(1:4, color=1:4)
end

This also displays nothing in a local IJulia:

using WGLMakie, Bonito

Page()
App() do session::Session
    scatter(1:4, color=1:4)
end

This finally displays the figure in a local IJulia (but the control key still isn't captured):

using WGLMakie, Bonito

Page(listen_url="localhost")
App() do session::Session
    scatter(1:4, color=1:4)
end

After some digging around it seems like some keyboard keys are captured correctly left_alt works, but left_super and left_control don't work.

EdsterG commented 3 months ago

Ok, based on https://github.com/jupyterlab/jupyterlab/issues/16619#issuecomment-2258741457 it seems like there's a missing attribute. I've tried using my browsers element inspector to manually add this attribute. Adding it to the bonito-fragment div elements doesn't work, but adding data-lm-suppress-shortcuts="true" directly to the canvas works! As I'm not a frontend dev, I wasn't able to figure out what generates the canvas element and it's attributes, but it seems like an easy fix. @SimonDanisch if you can point me in the right direction I'd be happy to push a PR.

SimonDanisch commented 3 months ago

Cool, you can add it here: https://github.com/MakieOrg/Makie.jl/blob/4c4eaa1f3a7f7b3777a4b8ab38388a48c0eee6ce/WGLMakie/src/three_plot.jl#L36 Bonito/Hyperscript allows you to pass data-lm-suppress-shortcuts as dataLmSuppressShortcuts as a keyword argument!

EdsterG commented 3 months ago

Tested the fix, I can now use all of the letters along with the shift keys (previously not working). However, control and command/super are still not captured. Might be an upstream issue, will follow up.

EdsterG commented 3 months ago

Opened an issue for lack of control/super capture, https://github.com/jupyterlab/lumino/issues/713.

EdsterG commented 3 months ago

Looks like WGLMakie had a bug regarding the super key, I pushed a fix to https://github.com/MakieOrg/Makie.jl/pull/4068. This also solves capture of super in JupyterLab.

EdsterG commented 3 months ago

Suppressing the context menu in #4068 solves the capture of control.