Skip to content

feat(embed): exportPNG canvas compositor + postMessage export protocol#28

Merged
CSSFrancis merged 1 commit into
mainfrom
feat/export-png
Jul 13, 2026
Merged

feat(embed): exportPNG canvas compositor + postMessage export protocol#28
CSSFrancis merged 1 commit into
mainfrom
feat/export-png

Conversation

@CSSFrancis

Copy link
Copy Markdown
Owner

Summary

  • handle.exportPNG({scale, includeWidgets}) composites the per-panel canvas stack (gpu/plot/axes/colorbar/markers/scalebar/title, insets on top) onto one offscreen canvas at DPR×scale and resolves to a PNG data URL.
  • WebGPU panels are force-redrawn and read back in the same synchronous task — callers need no settling delay.
  • Standalone HTML gains a message listener (anyplotlib_export_pnganyplotlib_export_png_result) so iframe hosts (SpyDE report cells) can harvest WYSIWYG snapshots.
  • Side fix: render() now returns its internal api and mount() captures it — mount().dispose() previously referenced closure state it couldn't reach and silently no-oped.

Branch is based on release/v0.2.0 (main hasn't caught up to the release-prep commits), so those two commits appear in the diff until main is fast-forwarded.

Tests

tests/test_embed/test_export_png.py: 7 passed (basic pixel/LUT checks, multi-panel arrangement, iframe postMessage round-trip, WebGPU readback — skips cleanly without an adapter). Full test_embed/ + test_plot2d/ + test_layouts/ regression: 439 passed, 6 pre-existing baseline skips.

handle.exportPNG({scale, includeWidgets}) composites the per-panel canvas
stack (gpu/plot/axes/colorbar/markers/scalebar/title, insets on top) onto
one offscreen canvas at DPR*scale and returns a PNG data URL. WebGPU
panels are force-redrawn and read back in the same synchronous task, so
callers need no settling delay. Standalone HTML gains a message listener
(anyplotlib_export_png -> anyplotlib_export_png_result) riding the same
channel as awi_state, for iframe hosts.

render() now returns its internal api ({panels, exportPNG, gpu disposers});
mount() captures it — this also fixes mount().dispose(), which previously
referenced closure-scoped state it could not reach and silently no-oped.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.97%. Comparing base (d4d0e1b) to head (0b74e7c).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #28   +/-   ##
=======================================
  Coverage   88.97%   88.97%           
=======================================
  Files          38       38           
  Lines        3511     3511           
=======================================
  Hits         3124     3124           
  Misses        387      387           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@CSSFrancis CSSFrancis merged commit b277444 into main Jul 13, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants