Legend Restore MarkerStyle.Size behavior and fix marker clipping inside rectangle#5031
Merged
swharden merged 6 commits intoScottPlot:mainfrom Aug 22, 2025
Merged
Conversation
- Removed unconditional overwrite of LegendItem.MarkerStyle.Size with LabelFontSize. - Apply MarkerShapeDefault only when no explicit marker shape is provided. - Use label font size as a fallback size iff MarkerStyle.Size <= 0.
- Updated Wrapping.GetLayout() to calculate symbol square as the max of Legend.SymbolWidth and the largest MarkerStyle.Size. - Adjusted row height and per-item symbol rectangles to prevent clipping when markers are larger than the configured symbol width.
Contributor
|
thanks for looking into this, wasn't sure what was going on originally |
Member
|
Thanks @manaruto, this looks great! 🚀 |
Member
Member
|
I think the core issue is that the present logic assumes that the symbol in the legend is always a square. However, for many legends this is not the case (e.g., the one pictured is a line which is wider than high). I think this is fixable though. I'll keep working... hopefully publish a package to NuGet tonight once this last thing is fixed |
Member
|
I think it's solved in #5056 [Test]
public void Test_LargeMarkers_ExpandLegendToFit()
{
Plot plot = new();
var xs = Generate.Consecutive(51);
var ys1 = Generate.Sin(51);
var ys2 = Generate.Cos(51);
var sp1 = plot.Add.Markers(xs, ys1);
sp1.LegendText = "Sine";
sp1.MarkerSize = 15;
var sp2 = plot.Add.Markers(xs, ys2);
sp2.LegendText = "Cosine";
sp2.MarkerSize = 45;
sp2.MarkerShape = MarkerShape.OpenSquare;
plot.ShowLegend(Alignment.LowerRight, Orientation.Horizontal);
plot.SaveTestImage();
}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This PR addresses a regression introduced after PR #5006, where the MarkerStyle.Size property stopped taking effect when a MarkerShapeDefault was set.
Fixes #4999 (marker shape clipping by legend rectangle).
In the original PR, the logic was:
Because item.MarkerStyle.Size was being overwritten unconditionally with LabelFontSize, any explicit size set by the user was ignored.
Changes in this PR
Legend.cs
Wrapping.cs
Code Example: