Skip to content

Commit b8896c9

Browse files
authored
Fix: Fonts, Legend Markers, and Radar Rotation Direction (ScottPlot#5048)
* Fonts.Reset() * Legend: improve default marker styling extends ScottPlot#5006 * Radar: use new polar plot rotation features
1 parent a69387c commit b8896c9

8 files changed

Lines changed: 56 additions & 43 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ _Not yet on NuGet..._
2727
* Angle: Added `Inverted` property and support for `Angle` comparison using equality operators
2828
* Polar Axis: Added a `Clockwise` property to support clockwise and counter-clockwise translation between Polar and Cartesian coordinates (#5028, #4884, #5046) @CoderPM2011, @mattwelch2000
2929
* WinUI: Improved support for plots with transparent backgrounds (#5026, #5029) @diluculo
30+
* Font: Added `Fonts.Reset()` to restore default styling options (#5013) @aespitia
3031

3132
## ScottPlot 5.0.55
3233
_Published on [NuGet](https://www.nuget.org/profiles/ScottPlot) on 2025-03-22_

src/ScottPlot5/ScottPlot5 Cookbook/RecipeBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void Execute(Plot plot)
4040
public void ResetRandomNumberGenerator()
4141
{
4242
Generate.RandomData.Seed(0);
43+
Fonts.Reset();
4344
}
4445

4546
[TearDown]

src/ScottPlot5/ScottPlot5 Cookbook/Recipes/General/Legend.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,21 @@ public override void Execute()
114114

115115
public class LegendOverrideSymbol : RecipeBase
116116
{
117-
public override string Name => "Legend Default Marker";
118-
public override string Description => @"You can override the default rectangular marker used when rendering the legend. It also maintains the desired marker for manually added items.";
117+
public override string Name => "Legend Marker Shape Override";
118+
public override string Description => "Use the legend shape override " +
119+
"to force all legend items to display using the given marker shape.";
119120

120121
[Test]
121122
public override void Execute()
122123
{
124+
myPlot.Legend.MarkerShapeOverride = MarkerShape.FilledCircle;
125+
123126
var sig1 = myPlot.Add.Signal(Generate.Sin(51));
124127
sig1.LegendText = "Sin";
125128

126129
var sig2 = myPlot.Add.Signal(Generate.Cos(51));
127130
sig2.LegendText = "Cos";
128131

129-
myPlot.Legend.MarkerShapeDefault = MarkerShape.FilledCircle;
130-
131-
132132
LegendItem item1 = new()
133133
{
134134
MarkerColor = Colors.Red,

src/ScottPlot5/ScottPlot5 Cookbook/Recipes/PlotTypes/Radar.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public override void Execute()
9999
};
100100

101101
var radar = myPlot.Add.Radar(values);
102+
radar.Series[0].LegendText = "A";
103+
radar.Series[1].LegendText = "B";
102104

103105
string[] spokeLabels = { "Wins", "Poles", "Podiums", "Points", "DNFs" };
104106
radar.PolarAxis.SetSpokes(spokeLabels, length: 110);

src/ScottPlot5/ScottPlot5/Fonts.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ public static void AddFontFile(string name, string path, bool bold = false, bool
3131
FontResolvers.Add(resolver);
3232
}
3333

34-
/// <summary>
35-
/// This font is used for almost all text rendering.
36-
/// </summary>
37-
public static string Default { get; set; } = SystemFontResolver.InstalledSansFont();
3834
public static FontWeight? DefaultWeight { get; set; }
3935
public static FontSlant? DefaultSlant { get; set; }
4036
public static FontSpacing? DefaultWidth { get; set; }
4137
public static SKTypeface? DefaultFontStyle { get; set; }
4238

39+
/// <summary>
40+
/// This font is used for almost all text rendering.
41+
/// </summary>
42+
public static string Default { get; set; } = SystemFontResolver.InstalledSansFont();
43+
4344
/// <summary>
4445
/// Name of a sans-serif font present on the system
4546
/// </summary>
@@ -289,4 +290,17 @@ public static List<int> GetStandaloneCodePoints(IEnumerable<List<int>> codePoint
289290
}
290291

291292
#endregion
293+
294+
public static void Reset()
295+
{
296+
DefaultWeight = null;
297+
DefaultSlant = null;
298+
DefaultWidth = null;
299+
DefaultFontStyle = null;
300+
301+
Default = SystemFontResolver.InstalledSansFont();
302+
Sans = SystemFontResolver.InstalledSansFont();
303+
Serif = SystemFontResolver.InstalledSerifFont();
304+
Monospace = SystemFontResolver.InstalledMonospaceFont();
305+
}
292306
}

src/ScottPlot5/ScottPlot5/Plottables/Radar.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ public class Radar() : IPlottable, IManagesAxisLimits
55
/// <summary>
66
/// The polar axis drawn beneath each radar series polygon
77
/// </summary>
8-
public PolarAxis PolarAxis { get; set; } = new() { Rotation = Angle.FromDegrees(90) };
8+
public PolarAxis PolarAxis { get; set; } = new()
9+
{
10+
Rotation = Angle.FromDegrees(-90),
11+
Clockwise = true,
12+
};
913

1014
/// <summary>
1115
/// A collection of RadarSeries, each of which hold a set of values and the styling information that controls how the shape is rendered
@@ -59,7 +63,7 @@ public virtual void Render(RenderPack rp)
5963

6064
for (int i = 0; i < Series.Count; i++)
6165
{
62-
Coordinates[] cs1 = PolarAxis.GetCoordinates(Series[i].Values, clockwise: true);
66+
Coordinates[] cs1 = PolarAxis.GetCoordinates(Series[i].Values);
6367
Pixel[] pixels = cs1.Select(Axes.GetPixel).ToArray();
6468
Drawing.FillPath(rp.Canvas, paint, pixels, Series[i].FillStyle);
6569
Drawing.DrawPath(rp.Canvas, paint, pixels, Series[i].LineStyle, close: true);

src/ScottPlot5/ScottPlot5/Plottables/Signal.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ public Color Color
5454

5555
public AxisLimits GetAxisLimits() => Data.GetLimits();
5656

57-
public IEnumerable<LegendItem> LegendItems => LegendItem.Single(this, LegendText, MarkerStyle, LineStyle);
57+
public IEnumerable<LegendItem> LegendItems
58+
{
59+
get
60+
{
61+
return LegendItem.Single(this, LegendText, MarkerStyle, LineStyle);
62+
}
63+
}
5864

5965
private CoordinateRange GetVisibleXRange(PixelRect dataRect)
6066
{

src/ScottPlot5/ScottPlot5/Primitives/Legend.cs

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ public class Legend(Plot plot) : IPlottable, IHasOutline, IHasBackground, IHasSh
114114
public IEnumerable<LegendItem> LegendItems => LegendItem.None;
115115
public AxisLimits GetAxisLimits() => AxisLimits.NoLimits;
116116

117-
public MarkerShape MarkerShapeDefault { get; set; } = MarkerShape.None;
117+
/// <summary>
118+
/// If supplied, always use this marker shape
119+
/// </summary>
120+
public MarkerShape? MarkerShapeOverride { get; set; } = null;
118121

119122
public bool DisplayPlottableLegendItems { get; set; } = true;
120123

@@ -294,10 +297,16 @@ private void RenderLayout(SKCanvas canvas, LegendLayout layout)
294297
PixelRect symbolFillOutlineRect = symbolFillRect.Expand(1 - item.OutlineWidth);
295298
PixelLine symbolLine = new(symbolRect.RightCenter, symbolRect.LeftCenter);
296299

297-
if (item.MarkerShape == MarkerShape.None && item.MarkerStyle.Shape == MarkerShape.None)
300+
if (MarkerShapeOverride.HasValue)
298301
{
299-
item.MarkerShape = MarkerShapeDefault != MarkerShape.None ? MarkerShapeDefault : MarkerShape.None;
300-
item.MarkerColor = item.MarkerColor == Colors.Transparent ? Colors.Black : item.MarkerColor;
302+
item.MarkerShape = MarkerShapeOverride.Value;
303+
304+
if (item.MarkerColor == Colors.Transparent)
305+
item.MarkerColor = Colors.Black;
306+
307+
// NOTE: Some plottables like signal plots have dynamically sized markers that can get very small
308+
if (item.MarkerSize < 5)
309+
item.MarkerSize = item.LabelFontSize;
301310
}
302311

303312
item.LabelStyle.Render(canvas, labelRect.LeftCenter, paint, true);
@@ -308,33 +317,9 @@ private void RenderLayout(SKCanvas canvas, LegendLayout layout)
308317
Drawing.DrawRectangle(canvas, labelRect, Colors.Magenta.WithAlpha(.2));
309318
}
310319

311-
if (MarkerShapeDefault != MarkerShape.None)
312-
{
313-
item.MarkerStyle.Shape = item.MarkerShape != MarkerShape.None ? item.MarkerShape : MarkerShapeDefault;
314-
315-
//NOTE: tried this but size seems to be defaulting something to something small, so you can barely see the shape, defaulting to font size for now
316-
//item.MarkerStyle.Size = item.MarkerStyle.Size != 0 ? item.MarkerStyle.Size : item.LabelFontSize;
317-
item.MarkerStyle.Size = item.LabelFontSize;
318-
}
319-
else
320-
{
321-
item.MarkerStyle.Shape = item.MarkerShape;
322-
323-
// If the marker size is not set, use the label font size as a fallback
324-
//NOTE: Same as above, tried it, but somehow the default is really small, setting to font size for now.
325-
//item.MarkerStyle.Size = item.MarkerStyle.Shape != MarkerShape.None && item.MarkerStyle.Size != 0? item.MarkerStyle.Size : item.LabelFontSize;
326-
327-
item.MarkerStyle.Size = item.LabelFontSize;
328-
329-
if (item.MarkerShape == MarkerShape.None && item.MarkerStyle.Shape == MarkerShape.None)
330-
{
331-
item.LineStyle.Render(canvas, symbolLine, paint);
332-
}
333-
334-
item.FillStyle.Render(canvas, symbolFillRect, paint);
335-
item.OutlineStyle.Render(canvas, symbolFillOutlineRect, paint);
336-
}
337-
320+
item.LineStyle.Render(canvas, symbolLine, paint);
321+
item.FillStyle.Render(canvas, symbolFillRect, paint);
322+
item.OutlineStyle.Render(canvas, symbolFillOutlineRect, paint);
338323
item.MarkerStyle.Render(canvas, symbolRect.Center, paint);
339324
item.ArrowStyle.Render(canvas, symbolLine, paint);
340325

0 commit comments

Comments
 (0)