fix: prevent empty PNG export for large graphs - #95
Open
Mathew Benjamin (mathewtbenjamin) wants to merge 1 commit into
Open
Mathew Benjamin (mathewtbenjamin) wants to merge 1 commit into
Mathew Benjamin (mathewtbenjamin) wants to merge 1 commit into
Conversation
Exporting the graph as PNG used a fixed scale of 2 with full:true. For
large ontologies the resulting canvas exceeds the browser's maximum
canvas size, and toDataURL() silently returns the empty data URI
('data:,'), producing a 0-byte .png file. The silent catch block hid
the failure entirely.
- Add computeExportScale: clamp the export scale so the largest side of
the rendered canvas stays within a conservative 8192px cross-browser
limit (small graphs keep the crisp 2x scale).
- Validate the data URI before downloading and log an actionable error
instead of writing an empty file.
- Replace the silent catch with console.error.
- Unit tests for the new helpers (9 tests).
Addresses the PNG export bug (item 3) in microsoft#87
Author
|
Friendly nudge 🙂 — this PR has been open ~3 weeks, the CLA check is green, and it's currently mergeable with no conflicts. Is there anything I can do to help move it toward review (rebase, split, or extra context)? Happy to help. Thanks! |
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.
Summary
Addresses the PNG export produces an empty file bug (item 3) reported in #87.
handleDownloadinsrc/components/OntologyGraph.tsxexported with a fixedcy.png({ scale: 2, full: true }). For large ontologies the rendered canvas exceeds the browser's maximum canvas size, andtoDataURL()then silently returns the empty data URI (data:,) — which is exactly the 0-byteimported-ontology-graph.pngthe reporter saw. Thecatch { /* ignore */ }block hid the failure completely.Changes
src/lib/graphExport.ts:computeExportScale(width, height)— clamps the export scale so the largest side of the canvas stays within a conservative 8192px cross-browser limit. Small/medium graphs keep the crisp 2× scale; large graphs degrade gracefully instead of failing.isValidPngDataUri(value)— detects the empty-data-URI failure mode.OntologyGraph.tsx: compute the scale from the graph's bounding box, validate the data URI before triggering the download (no more 0-byte files), and log actionable errors instead of swallowing them.src/lib/graphExport.test.ts— 9 unit tests covering clamping, exact-limit, degenerate bounding boxes, and data-URI validation.Validation
npx tsc --noEmit— cleannpx vitest run— 25 files, 403/403 tests pass (394 existing + 9 new)Notes