Skip to content

Make the backgrounds in SVG diagrams be transparent - #8583

Open
mhucka wants to merge 2 commits into
quantumlib:mainfrom
mhucka:svg-transparency
Open

mhucka wants to merge 2 commits into
quantumlib:mainfrom
mhucka:svg-transparency

Conversation

@mhucka

@mhucka mhucka commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Change the SVG output code to specify a transparent background, instead of the current mix of SVG default (black) and some elements having white.

Achieving this turned out to be more involved than simply specifying something like fill=none in the SVG constructs. Previously, the SVG code drew horizontal and vertical wires continuously through the centers of qubit labels and gate boxes, relying on opaque fill="white" <rect> elements (including borderless stroke-width="0" rectangles behind qubit labels) to cover up the overlapping wire sections. To make backgrounds transparent without wires striking through labels or gate text, the new _rect code now defaults to fill="none", qubit labels (xi == 0) omit their backing <rect> altogether, and a new _render_entries helper renders entries first while recording per-row and per-column bounding-box cutouts for every gate box and qubit label. It leaves pass-through symbols @, ×, and '' unclipped. Before emitting <line> elements, tdd_to_svg passes each horizontal and vertical wire span through a new _subtract_intervals helper that splits the wire into segments stopping cleanly at box edges, then places the clipped lines ahead of the entries so paint order is preserved.

This changes the default background to be transparent instead of the
current mix of SVG default (black) and some elements having white.
@mhucka mhucka changed the title Make SVG diagram backgrounds transparent Make the backgrounds in SVG diagrams be transparent Dec 2, 2026
@github-actions github-actions Bot added the size: M 50< lines changed <250 label Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.58%. Comparing base (e6e1221) to head (ecfdb8b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8583   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files        1139     1139           
  Lines      105740   105771   +31     
=======================================
+ Hits       105303   105336   +33     
+ Misses        437      435    -2     

☔ 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.

@mhucka

mhucka commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Here are some before and after examples using checkerboard backgrounds to demonstrate the transparency:

image image image

Using a solid color background just for good measure:

image

@mhucka
mhucka marked this pull request as ready for review December 2, 2026 09:27
@mhucka
mhucka requested a review from a team as a code owner December 2, 2026 09:27
@mpharrigan

Copy link
Copy Markdown
Contributor

I agree that the qubit labels hack should be fixed, but shouldn't the boxes have a background? imagine putting a circuit on a slide with a textured background or something

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/contrib size: M 50< lines changed <250

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants