Skip to content

Fix transparent background frame accumulation with axis rules#5029

Merged
swharden merged 5 commits intoScottPlot:mainfrom
diluculo:fix-5026
Aug 17, 2025
Merged

Fix transparent background frame accumulation with axis rules#5029
swharden merged 5 commits intoScottPlot:mainfrom
diluculo:fix-5026

Conversation

@diluculo
Copy link
Contributor

@diluculo diluculo commented Aug 8, 2025

Fixes #5026

Problem
Transparent backgrounds in WinUI3 cause frame accumulation when using axis rules (SquareZoomOut, SquarePreserveX, etc.) due to improper canvas clearing between iterations.

Solution
Add canvas.Clear() before each render iteration in RenderManager.Render() to force proper clearing of WinUI3's transparent rendering pipeline.

@diluculo
Copy link
Contributor Author

diluculo commented Aug 8, 2025

Update: Fixed SVG test failure

The initial implementation caused the Test_Svg_EmptyRect test to fail because canvas.Clear() was being called unconditionally, generating unwanted empty <rect> elements in SVG output.

Fixed by adding condition:

// Only clear when background is transparent
if (Plot.FigureBackground?.Color.A < 255)
{
    canvas. Clear();
}

@swharden
Copy link
Member

Hi @diluculo, thanks for researching this! I don't know much about WinUI so I really value input from people who are a lot more familiar with it and are able to test it for edge cases like this.

I'm going to extend your PR to add code comments about why clearing is on by default... I'm pretty sure it's to prevent SVGs from containing several overlapping plots when a plot is rendered multiple times and exported as SVG.

A better solution is to add a flag to enable/disable this behavior, and we can disable it by default in the WinUI control. I'll look into it now and follow-up shortly...

@swharden
Copy link
Member

... quick follow-up, I now realize your fix shouldn't affect SVG output. My bad for responding too quickly 😅 Sorry for the noise! I think this fix will be good and I'll merge shortly

Thanks again!
Scott

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.

Transparent background causes double rendering with square axis rules

2 participants