Skip to content

Commit 528d80e

Browse files
author
frsa
committed
Refactored to accomodate new Legends Class.
Created abstract Legends class and default implementation. Updated Examples to work after refactoring. Added SeriesGroupName and LegendKey properties to Series. Removed obsolete partial class PlotModel.Legends. Added HitTest to Legends. Added some examples to LegendExamples. Update Contributors list and CHANGELOG.
1 parent 2dd3ae6 commit 528d80e

38 files changed

Lines changed: 1627 additions & 610 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
55

6+
### Changed
7+
- Made legends open for extension (#644)
8+
- Added Oxyplot.Legends namespace
9+
- Added abstract base class LegendBase
10+
- Added default implementation Legend and Legend.Rendering
11+
- Added Legends ElementCollection to PlotModel
12+
- PlotModel now accommodate multiple Legends, although same positions as before. Legends sharing position are placed on top of eachother
13+
- Made Legend Items clickable to toggle series visibility
14+
- Added properties LegendKey and SeriesGroupName to Series, allowing grouping series between multiple legends and/or within same legend
15+
- Remove PlotModel.Legends
16+
- Default behaviour is now plot without Legend.
17+
618
### Added
719
- OxyPlot.ImageSharp (#1188)
820
- WPF ExampleBrowser can display transposed versions of examples (#1402)

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ episage <tilosag@gmail.com>
4343
eric
4444
Federico Coppola <fede@silentman.it>
4545
Francois Botha <igitur@gmail.com>
46+
Frank Tore Sæther <frank.sather@gmail.com>
4647
Garrett
4748
Geert van Horrik <geert@catenalogic.com>
4849
Gimly

Source/Examples/ExampleLibrary/Axes/AxisExamples.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace ExampleLibrary
1616
using OxyPlot;
1717
using OxyPlot.Axes;
1818
using OxyPlot.Series;
19+
using OxyPlot.Legends;
1920

2021
/// <summary>
2122
/// Provides examples for general axis properties.
@@ -800,8 +801,14 @@ public static PlotModel AutoAdjustingMargins()
800801
var model = new PlotModel
801802
{
802803
Title = "Auto adjusting plot margins",
804+
};
805+
806+
Legend l = new Legend
807+
{
803808
LegendPosition = LegendPosition.RightBottom
804809
};
810+
model.Legends.Add(l);
811+
805812
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "X", TickStyle = TickStyle.Outside });
806813
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Y", TickStyle = TickStyle.Outside });
807814
model.Series.Add(new LineSeries { Title = "Butterfly curve", ItemsSource = ButterflyCurve(0, Math.PI * 4, 1000) });
@@ -814,9 +821,15 @@ public static PlotModel AutoAdjustingLeftMargin()
814821
var model = new PlotModel
815822
{
816823
Title = "Auto adjusting left plot margin",
817-
LegendPosition = LegendPosition.RightBottom,
818824
PlotMargins = new OxyThickness(double.NaN, 40, 40, 40)
819825
};
826+
827+
Legend l = new Legend
828+
{
829+
LegendPosition = LegendPosition.RightBottom
830+
};
831+
model.Legends.Add(l);
832+
820833
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "X", TickStyle = TickStyle.Outside });
821834
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Y", TickStyle = TickStyle.Outside });
822835
model.Series.Add(new LineSeries { Title = "Butterfly curve", ItemsSource = ButterflyCurve(0, Math.PI * 4, 1000) });
@@ -830,9 +843,15 @@ public static PlotModel ManualAdjustingMargins()
830843
var model = new PlotModel
831844
{
832845
Title = "Manual plot margins",
833-
LegendPosition = LegendPosition.RightBottom,
834846
PlotMargins = new OxyThickness(60, 4, 4, 40)
835847
};
848+
849+
Legend l = new Legend
850+
{
851+
LegendPosition = LegendPosition.RightBottom
852+
};
853+
model.Legends.Add(l);
854+
836855
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "X", TickStyle = TickStyle.Outside });
837856
model.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = "Y", TickStyle = TickStyle.Outside });
838857
model.Series.Add(new LineSeries { Title = "Butterfly curve", ItemsSource = ButterflyCurve(0, Math.PI * 4, 1000) });
@@ -1248,8 +1267,14 @@ public static PlotModel MultiVerticalAxes()
12481267
var plotModel = new PlotModel()
12491268
{
12501269
Title = "Multi vertical axes with lineSeries",
1251-
LegendBackground = OxyColors.White,
12521270
};
1271+
1272+
Legend l = new Legend
1273+
{
1274+
LegendBackground = OxyColors.White
1275+
};
1276+
plotModel.Legends.Add(l);
1277+
12531278
var axisX_Time = new DateTimeAxis()
12541279
{
12551280
Title = "Time",

Source/Examples/ExampleLibrary/Axes/LogarithmicAxisExamples.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace ExampleLibrary
1111
using OxyPlot;
1212
using OxyPlot.Axes;
1313
using OxyPlot.Series;
14+
using OxyPlot.Legends;
1415

1516
[Examples("LogarithmicAxis"), Tags("Axes")]
1617
public static class LogarithmicAxisExamples
@@ -27,7 +28,13 @@ public static PlotModel DefaultValues()
2728
[Example("Amdahl's Law")]
2829
public static PlotModel AmdahlsLaw()
2930
{
30-
var model = new PlotModel { Title = "Amdahl's law", LegendTitle = "Parallel portion" };
31+
var model = new PlotModel { Title = "Amdahl's law" };
32+
33+
Legend l = new Legend
34+
{
35+
LegendTitle = "Parallel portion"
36+
};
37+
model.Legends.Add(l);
3138

3239
// http://en.wikipedia.org/wiki/Amdahl's_law
3340
Func<double, int, double> maxSpeedup = (p, n) => 1.0 / ((1.0 - p) + (double)p / n);
@@ -57,12 +64,18 @@ public static PlotModel RichterMagnitudes()
5764
{
5865
Title = "The Richter magnitude scale",
5966
PlotMargins = new OxyThickness(80, 0, 80, 40),
67+
};
68+
69+
Legend l = new Legend
70+
{
6071
LegendPlacement = LegendPlacement.Inside,
6172
LegendPosition = LegendPosition.TopCenter,
6273
LegendOrientation = LegendOrientation.Horizontal,
6374
LegendSymbolLength = 24
6475
};
6576

77+
model.Legends.Add(l);
78+
6679
model.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "Richter magnitude scale", MajorGridlineStyle = LineStyle.None, TickStyle = TickStyle.None });
6780

6881
var frequencyCurve = new LineSeries
@@ -160,4 +173,4 @@ public static PlotModel TickCalculation()
160173
return model;
161174
}
162175
}
163-
}
176+
}

Source/Examples/ExampleLibrary/CustomSeries/CustomSeriesExamples.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace ExampleLibrary
1111
using OxyPlot;
1212
using OxyPlot.Axes;
1313
using OxyPlot.Series;
14+
using OxyPlot.Legends;
1415

1516
[Examples("Custom series"), Tags("Series")]
1617
public static class CustomSeriesExamples
@@ -20,7 +21,13 @@ public static PlotModel ErrorSeries()
2021
{
2122
int n = 20;
2223

23-
var model = new PlotModel { Title = "ErrorSeries", LegendPosition = LegendPosition.BottomRight };
24+
var model = new PlotModel { Title = "ErrorSeries" };
25+
var l = new Legend
26+
{
27+
LegendPosition = LegendPosition.BottomRight
28+
};
29+
30+
model.Legends.Add(l);
2431

2532
var s1 = new ErrorSeries { Title = "Measurements" };
2633
var random = new Random(31);

Source/Examples/ExampleLibrary/Discussions/DiscussionExamples.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace ExampleLibrary
1313
using OxyPlot;
1414
using OxyPlot.Axes;
1515
using OxyPlot.Series;
16+
using OxyPlot.Legends;
1617

1718
[Examples("Z0 Discussions")]
1819
public class DiscussionExamples
@@ -257,8 +258,12 @@ public static PlotModel PolarPlotWithArrows()
257258
[Example("MarkerType = Circle problem")]
258259
public static PlotModel MarkerTypeCircleProblem()
259260
{
260-
var plotModel = new PlotModel { LegendSymbolLength = 30, PlotType = PlotType.Cartesian, PlotAreaBorderThickness = new OxyThickness(0) };
261+
var plotModel = new PlotModel { PlotType = PlotType.Cartesian, PlotAreaBorderThickness = new OxyThickness(0) };
261262

263+
var l = new Legend
264+
{
265+
LegendSymbolLength = 30
266+
};
262267

263268
var xaxis = new DateTimeAxis
264269
{

0 commit comments

Comments
 (0)