jupyter-widgets-contrib / ipycanvas

Interactive Canvas in Jupyter
https://ipycanvas.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
686 stars 64 forks source link

Add `scroll` events + allow capturing them #203

Open ianhi opened 3 years ago

ianhi commented 3 years ago

It would be nice to be capture scroll events in order to implement things like scrolling on zoom. This could borrow from how ipympl achieved this:

https://github.com/matplotlib/ipympl/blob/54b2a2213f4941933c00f570f3008bf6db153b99/js/src/mpl_widget.js#L565-L575


For context I've put some work into a purely js canvas implementation of a segmentation library https://github.com/ianhi/ipysegment but was slowed down by writing everything in javascript and am thinking about re-writing it entirely using ipycanvas to make it easier to develop/contribute to and to make it more extensible for users. And scroll to zoom and move around is crucial feature for such a library

martinRenou commented 3 years ago

Thanks for opening an issue! It's a good idea indeed :) Note that you can use ipyevents already (although not yet JupyterLab 3 compatible but should soon be) but having it built-in ipycanvas would be good.

[...] and am thinking about re-writing it entirely using ipycanvas to make it easier to develop/contribute to and to make it more extensible for users

That sounds like a good idea. But I suppose ipycanvas also has multiple disadvantages compared to your implementation (slow server roundtrip for mouse-interaction/redraw). One idea would be to make it a subwidget of ipycanvas, and implement the lasso selection fully in the front-end so that you don't pay the server roundtrip cost.

ianhi commented 3 years ago

but having it built-in ipycanvas would be good.

I think it would also be necessary for https://github.com/martinRenou/ipycanvas/issues/179 to happen.

One idea would be to make it a subwidget of ipycanvas, and implement the lasso selection fully in the front-end so that you don't pay the server roundtrip cost.

oooh that's a good idea. I think this is the probably the best way forward.

ianhi commented 3 years ago

slow server roundtrip for mouse-interaction/redraw).

I was worried about this, but when I tried the hand-drawing example I found that even with the extra latency of binder it was very responsive. Especially in contrast to the equivalent implemented using matplotlib and run locally (https://mybinder.org/v2/gh/ianhi/mpl-interactions/0.17.12?filepath=examples/image-segmentation.ipynb)