Skip to content

Pie chart legend size differences between 5.0.43 and latest, legend is getting cut off #4629

@aespitia

Description

@aespitia

Issue: There seems to be a difference in the way legend size was calculated between 5.0.43 and 5.0.44 (onward) for pie charts at least. Some of the legend is getting cut off, where it used to not be cut off. Previously, the pie chart would shrink in size to accomodate all of the legend text, now the pie chart is bigger, but losing part of the legend. Screen shots below to show the difference, the sample code is from LinqPad
5 0 47-sample
5 0 40-sample

ScottPlot Version: 5.0.47

ScottPlot.Plot myPlot = new();

List<PieSlice> slices =
[
			new PieSlice() { Value = 32, Label = "Category 1", LegendText = "Category 1: 32%"},	
			new PieSlice() { Value = 27, Label = "Category 2", LegendText = "Category 2: 27%"},	
			new PieSlice() { Value = 16, Label = "Category 3", LegendText = "Category 3: 16%"},	
			new PieSlice() { Value = 15, Label = "Category 4", LegendText = "Category 4: 15%"},	
			new PieSlice() { Value = 4, Label = "Category 5", LegendText = "Category 5: 4%"},	
			new PieSlice() { Value = 3, Label = "Category 6", LegendText = "Category 6: 3%"},	
			new PieSlice() { Value = 1, Label = "Category 7", LegendText = "Category 7: 1%"},	
			new PieSlice() { Value = 1, Label = "Category 8", LegendText = "Category 8: 1%"},	
			new PieSlice() { Value = 100, Label = "Category 9", LegendText = "Category 9: 100%"},	
			
];

var pie = myPlot.Add.Pie(slices);

foreach (var s in pie.Slices)
{
	s.LabelFontSize = 0;
}

pie.LineStyle.Width =1;
pie.LineStyle.Color = Color.FromHex("#000000");
myPlot.ScaleFactor=1;
pie.SliceLabelDistance = 1.2;
pie.ExplodeFraction = 0;
myPlot.Legend.Orientation = Orientation.Vertical;
myPlot.Legend.FontSize = Convert.ToSingle(10.667);
myPlot.Legend.Alignment = Alignment.UpperLeft;
myPlot.Legend.FontColor = Color.FromHex("#000000");
myPlot.Axes.Frameless();
myPlot.Layout.Frameless();
ScottPlot.Panels.LegendPanel pan = new(myPlot.Legend);
pan.Padding = new(0);
pan.Alignment = Alignment.MiddleCenter;
pan.Edge = Edge.Bottom;


myPlot.HideGrid();
myPlot.ShowLegend(pan.Edge);

var bitmap = myPlot.GetImageBytes(348, 300, ScottPlot.ImageFormat.Bmp);

Util.Image(bitmap).Dump();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions