Skip to content

Pie: Reorganized code and fixed SVG rendering#5020

Merged
swharden merged 4 commits intoScottPlot:mainfrom
CoderPM2011:refactor/Pie
Aug 8, 2025
Merged

Pie: Reorganized code and fixed SVG rendering#5020
swharden merged 4 commits intoScottPlot:mainfrom
CoderPM2011:refactor/Pie

Conversation

@CoderPM2011
Copy link
Contributor

This PR is divided into two parts:

1. Reorganize the Pie class

  1. Replace hard-coded radius with a Radius property
  2. Use Drawing’s static methods for slice rendering
  3. Refactor Render by extracting slice logic into RenderSlice() and RenderDonutSlice()

2. Fix Drawing.FillEllipticalAnnulus() SVG export

  1. Raster ClipPath + Difference works on pixels but most SVG exporters emit a <clipPath> definition with spotty support, leading to missing or malformed rings.
  2. Switched to a single vector path with an Even-Odd fill rule so that the annulus always exports correctly.

Demo image

image

Demo code

Plot plot1 = formsPlot1.Plot;
plot1.HideLegend();
plot1.HideAxesAndGrid();

var pie1 = plot1.Add.Pie([new PieSlice()
{
    Value = 100,
    FillColor = Colors.Red,
    Label = "A"
}]);
pie1.DonutFraction = .5;

File.WriteAllText("./pie.html", $"""
    <html>
    {plot1.GetSvgHtml(300, 300)}
    </html>
    """);

reslove #4692 #4981

- Change the hardcoded radius to a property
- Use the existing method of Drawing to implement drawing
- Reorganize the Render method
- SVG does not support SKCanvas.ClipPath
@swharden
Copy link
Member

swharden commented Aug 8, 2025

Thanks @CoderPM2011! This looks great - merging now! 🚀

Also thanks @aespitia, I really appreciate seeing others are looking over these PRs 😁

@swharden swharden enabled auto-merge (squash) August 8, 2025 00:31
@swharden swharden merged commit 84c53fc into ScottPlot:main Aug 8, 2025
3 checks passed
@CoderPM2011 CoderPM2011 deleted the refactor/Pie branch August 8, 2025 00:34
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.

3 participants