Skip to content

Fix: Ensure SVG layout stability by pre-rendering in memory.#4847

Merged
swharden merged 3 commits intoScottPlot:mainfrom
manaruto:fix-svg-duplicate-render
Mar 19, 2025
Merged

Fix: Ensure SVG layout stability by pre-rendering in memory.#4847
swharden merged 3 commits intoScottPlot:mainfrom
manaruto:fix-svg-duplicate-render

Conversation

@manaruto
Copy link
Contributor

@manaruto manaruto commented Mar 10, 2025

Issue

When generating an SVG using GetSvgXml(int width, int height), the first render may loop multiple times to adjust layout properties (e.g., tick label sizes, figure padding). If SaveSvg() is called during this phase, it can result in duplicated elements in the SVG output, check my last comment in this issue, Fix #4842 .

Solution:
-Added RenderInMemory(width, height); before creating the SVG.

public string GetSvgXml(int width, int height)
{
    RenderInMemory(width, height); // Ensures layout is stabilized before rendering
    using SvgImage svg = new(width, height);
    bool originalClearState = RenderManager.ClearCanvasBeforeEachRender;
    RenderManager.ClearCanvasBeforeEachRender = false;
    Render(svg.Canvas, width, height);
    RenderManager.ClearCanvasBeforeEachRender = originalClearState;
    return svg.GetXml();
}

manaruto and others added 3 commits March 10, 2025 13:10
Changes:
-Added RenderInMemory(width, height); before creating the SVG inside GetSvgXml().
-This forces an in-memory render before the actual SVG render
@swharden swharden enabled auto-merge (squash) March 19, 2025 00:30
@swharden swharden merged commit 5b4857c into ScottPlot:main Mar 19, 2025
3 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.

Flickering Issue When Printing to PDF (Render Overlapping)

2 participants