Closed chriddyp closed 6 years ago
👋 hello from QuantStack! I love that you guys are embracing the widgets framework for plotly.
One way to do what (I understand) you want is to hook up to the phosphorjs widgets events. We have one example here: https://github.com/jupyter-widgets/ipyleaflet/blob/master/js/src/jupyter-leaflet.js#L917
ipyleaflet maps need to measure their containers to know how many tiles to display.
Thanks @SylvainCorlay! We'll give it a try. Are these phosphorjs events available in both the classic notebook and JupyterLab?
The widgets framework has been great to work with. It's really exciting to have the tools to build rich Python APIs to existing JavaScript libraries!
Are these phosphorjs events available in both the classic notebook and JupyterLab?
The ones around the creation and destruction of the widgets are.
What you get in JLab which is not in the classic notebook is that the resizing of any tab of the dock area triggers a phosphor resize events to children that were resized.
For some reason the after-show
event, referenced by ipyleaflet in the code snippet above, wasn't being triggered for me. But when I dumped out all of the events I got a before-attach
event followed by an after-attach
event. And the after-attach
event is exactly what we needed.
Thanks!
IIRC you also get resize events in the classic notebook, but only when the window is resized.
IIRC you also get resize events in the classic notebook, but only when the window is resized.
Is that right? (I think that we do not get anything.)
IIRC, but I may be wrong. We could do it by adding a window resize handler if we needed to (probably just once from the widget manager, then loop over all top-level widgets and send them resize messages)
Many thanks everyone 🙇
👋 hello from plotly! we're working on the next version of the Plotly Jupyter widget in https://github.com/plotly/plotly.py/pull/942
There are some methods in our JS library that require a mounted/attached
div
(e.g. to know the size of the mounteddiv
). However, in the widgetsrender
method, we only have access to the unmounted/unattacheddiv
.Are there any component lifecycle methods or events that we can utilize to customize the behaviour of the widget after it has been mounted on the DOM? To start, we would use this behaviour to either resize our plot to fill the container or defer making the plot until the
div
has been attached.Many thanks!
(cc @jmmease)