-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement generateMimebundle #300
Conversation
Something I meant to comment on #294: Will this stop widget interaction on a save event? Ideally the interaction will stay open on saving. I know that I regularly save as a matter of habit so that would be a pretty big disruption. Is it the case that this mimebundle will only be displayed if the model state is not available? |
also: hoooooooooooooooorayyyyyyyyyyyyy - I'm so happy y'all are making progress on this |
js/src/mpl_widget.js
Outdated
@@ -240,6 +240,13 @@ export class MPLCanvasModel extends widgets.DOMWidgetModel { | |||
} | |||
} | |||
|
|||
generateMimeBundle() { | |||
return Promise.resolve({ | |||
'text/html': `<img src="${this.offscreen_canvas.toDataURL('image/jpeg', 1.0)}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why jpeg
? FWIW the backend provides a PNG. The data comes from here:
https://github.com/matplotlib/matplotlib/blob/56d9e7cb1718b740dee717ac0a208f7eae9db204/lib/matplotlib/backends/backend_webagg_core.py#L239-L242
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK actually, it's the first idea that came to my mind. We can do PNG then :)
It seems that saving the Notebook does not change the content of the Notebook when looking at it. The widget stays there and doesn't get re-rendered. Not sure I exactly understand how this works. |
@ianhi the fact that Maarten 's PR does not overwrite the widget state from the mimebundle will be a blocker in the case of ipympl. Given the current implementation of ipympl, even if we have a widget model, we are not able to recover the plot image (because it's not part of the model). Also, even if we made the plot image part of the model, when opening a Notebook saved by someone else, the widget will not be interactive anyway, because the new back-end is not aware of the data it should plot if we interact with the buttons. I would be in favor of adding a custom save hook in ipympl for Jupyter Notebook, that would remove the widget repr from the bundle, and only save the static image. What do you think? |
Dear @martinRenou , is there any resolution to the issue yet? I'm really looking forward to the working raster previews saved in NBs. If not, what would you suggest as a temporary workaround for now? Sincerely, |
cc. @ianhi Changing jupyter-widgets/ipywidgets#3107 so that it adds the possibility to completely overwrite the mimebundle gives the most wanted result: Will push the commits soon-ish. ** Edit: ** But we need a similar thing for JupyterLab |
@sin-mike there is no workaround possible as far as I know. But I am hopeful we can fix this soonish. |
@sin-mike it's very much not ideal but if you get a figure to where you want it then there are two options to embed a static version in the notebook:
@martinRenou looking great. I imagine most of the work for this will live on the ipywidgets pr? |
Yeah. After some discussions with @SylvainCorlay we agreed that this was too much of a hack. We're trying a cleaner approach. |
Closing! |
Wow, it's really a quick way to rasterize plots. Thanks! |
Builds on top of jupyter-widgets/ipywidgets#3107