Let a host page say it saves exported PNGs itself - #78
Merged
Merged
Conversation
In a frame, "Save PNG…" cannot download, so it posts the image to the parent
and shows an in-figure preview captioned "Right-click the image → Save image
as…". A desktop app embedding figures (SpyDE, in Electron) has its own Save
dialog and a webview with no such right-click menu, so the preview left the
user with no way to save at all.
The parent can now post {type: 'anyplotlib_host', savesPng: true}. The page
template records it (from window.parent only) in globalThis.__aplHostSavesPng,
and the figure then only posts the image: no preview, and no "Save as… (choose
folder)" entry, since the host's dialog already chooses the folder.
The listener lives in PNG_HARVEST_LISTENER, so the navigated embed gets it too.
FIGURE_ESM.md: 26 anchors shifted by the diff hunks, every function anchor
checked against its declaration.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #78 +/- ##
=======================================
Coverage 91.20% 91.20%
=======================================
Files 41 41
Lines 4880 4880
=======================================
Hits 4451 4451
Misses 429 429 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The host-save path is documented and tested, with existing behavior preserved.
Pull request overview
Adds an opt-in host-managed PNG export path for framed figures, preserving existing behavior when no host announcement is made.
Changes:
- Handles parent-only host announcements.
- Suppresses preview and folder-picker UI for host-managed saves.
- Adds tests and documentation updates.
File summaries
| File | Description |
|---|---|
upcoming_changes/78.new_feature.rst |
Adds the changelog entry. |
docs/exporting.rst |
Documents the host export protocol. |
anyplotlib/tests/test_embed/test_host_saves_png.py |
Tests announced and unannounced host behavior. |
anyplotlib/FIGURE_ESM.md |
Updates renderer documentation and anchors. |
anyplotlib/figure_esm.js |
Implements host-aware PNG export behavior. |
anyplotlib/_repr_utils.py |
Adds the host announcement listener. |
AGENTS.md |
Updates renderer line-count metadata. |
Review details
- Files reviewed: 7/7 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In an iframe, the export menu's Save PNG… can't download, so it posts the image to the parent and shows an in-figure preview captioned "Right-click the image → Save image as…". A desktop app that embeds figures (SpyDE, on Electron) has its own Save dialog and a webview with no such right-click menu, so that preview left users with no way to save.
Change
{type: 'anyplotlib_host', savesPng: true}to the figure's frame. The page template'sPNG_HARVEST_LISTENERrecords it inglobalThis.__aplHostSavesPng, accepting it fromwindow.parentonly.{type: 'anyplotlib_export_png_result', requestId: null, dataUrl, width, height, filename}. There's no preview, and no Save as… (choose folder) row, because the host's dialog already chooses the folder (_hostSavesPng,_canPickFile).Docs
docs/exporting.rstdocuments the message a framed save posts and the host announcement.FIGURE_ESM.mddescribes the host-save path. The insertion shifted 26 anchors; I shifted them by the diff hunks and checked every function anchor against its declaration line (105 checked, no mismatches).AGENTS.mdis updated to 12,438.Tests
tests/test_embed/test_host_saves_png.py, run in a parent page with the figure in an iframe:main);tests/test_embed,tests/test_plotxyandtests/test_documentationpass locally.