Repository navigation
Add AxisArea, AxisLineArea and AxisTitleArea property in Axis class (… #1966
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
1959a5f
77d5352
53b2ef2
a7a5db8
284c795
e8e3df6
ac877c1
aa9a369
c3eb7e3
ce40c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| using OxyPlot; | ||
| using OxyPlot.Axes; | ||
| using OxyPlot.Series; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
|
|
||
| namespace ExampleLibrary.Axes | ||
| { | ||
| [Examples("AxisArea"), Tags("Axes")] | ||
| public class AxisAreaExample | ||
| { | ||
| [Example("AxisArea LinearAxis")] | ||
| public static PlotModel AxisAreaLinearAxis() | ||
| { | ||
| var model = GetLinearAxisPlotModel(); | ||
| model.Annotations.Add(new RenderingCapabilities.DelegateAnnotation(context => | ||
| { | ||
| foreach (var axis in model.Axes) | ||
| { | ||
| context.DrawRectangle((OxyRect)axis.AxisArea, OxyColors.Undefined, OxyColor.FromAColor(128, OxyColors.Red), 1, EdgeRenderingMode.Automatic); | ||
| context.DrawRectangle((OxyRect)axis.TitleArea, OxyColors.Undefined, OxyColor.FromAColor(128, OxyColors.Green), 1, EdgeRenderingMode.Automatic); | ||
| context.DrawRectangle((OxyRect)axis.AxisLineArea, OxyColors.Undefined, OxyColor.FromAColor(128, OxyColors.Blue), 1, EdgeRenderingMode.Automatic); | ||
| } | ||
| })); | ||
| // Subscribe to the mouse down event on the line series | ||
| model.MouseDown += (s, e) => | ||
| { | ||
| ResetAxesFormat(model); | ||
| if (e.ChangedButton == OxyMouseButton.Left) | ||
| { | ||
| if (model.Axes.SingleOrDefault(axis => axis.TitleArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis1) | ||
| { | ||
| clickedAxis1.TitleFontWeight = 800; | ||
| clickedAxis1.TitleColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| else if (model.Axes.SingleOrDefault(axis => axis.AxisLineArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis2) | ||
| { | ||
| clickedAxis2.FontWeight = 800; | ||
| clickedAxis2.TextColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| else if (model.Axes.SingleOrDefault(axis => axis.AxisArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis3) | ||
| { | ||
| clickedAxis3.FontWeight = 800; | ||
| clickedAxis3.TitleFontWeight = 800; | ||
| clickedAxis3.TitleColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| clickedAxis3.TextColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| } | ||
| model.InvalidatePlot(false); | ||
| }; | ||
| return model; | ||
| } | ||
|
|
||
| [Example("AxisArea AngleAxis")] | ||
| public static PlotModel AxisAreaAngleAxis() | ||
| { | ||
| var model = GetAngleAxisPlotModel(); | ||
| model.Annotations.Add(new RenderingCapabilities.DelegateAnnotation(context => | ||
| { | ||
| context.DrawRectangle((OxyRect)model.Axes[1].AxisArea, OxyColors.Undefined, OxyColor.FromAColor(255, OxyColors.Red), 1, EdgeRenderingMode.Automatic); | ||
| var annulus = (OxyAnnulus)model.Axes[0].AxisArea; | ||
| context.DrawCircle(annulus.Center, annulus.InnerRadius, OxyColors.Undefined, OxyColor.FromAColor(255, OxyColors.Blue), 1, EdgeRenderingMode.Automatic); | ||
| context.DrawCircle(annulus.Center, annulus.OuterRadius, OxyColors.Undefined, OxyColor.FromAColor(255, OxyColors.Blue), 1, EdgeRenderingMode.Automatic); | ||
| })); | ||
| // Subscribe to the mouse down event on the line series | ||
| model.MouseDown += (s, e) => | ||
| { | ||
| ResetAxesFormat(model); | ||
| if (e.ChangedButton == OxyMouseButton.Left) | ||
| { | ||
| if (model.Axes.SingleOrDefault(axis => axis.TitleArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis1) | ||
| { | ||
| clickedAxis1.TitleFontWeight = 800; | ||
| clickedAxis1.TitleColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| else if (model.Axes.SingleOrDefault(axis => axis.AxisLineArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis2) | ||
| { | ||
| clickedAxis2.FontWeight = 800; | ||
| clickedAxis2.TextColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| else if (model.Axes.SingleOrDefault(axis => axis.AxisArea.Contains(e.Position.X, e.Position.Y)) is Axis clickedAxis3) | ||
| { | ||
| clickedAxis3.FontWeight = 800; | ||
| clickedAxis3.TitleFontWeight = 800; | ||
| clickedAxis3.TitleColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| clickedAxis3.TextColor = OxyColor.FromAColor(255, OxyColors.Purple); | ||
| } | ||
| } | ||
| model.InvalidatePlot(false); | ||
| }; | ||
| return model; | ||
| } | ||
|
|
||
| private static void ResetAxesFormat(PlotModel model) | ||
| { | ||
| foreach (var axis in model.Axes) | ||
| { | ||
| axis.TitleFontWeight = 400; | ||
| axis.FontWeight = 400; | ||
| axis.TitleColor = OxyColor.FromAColor(255, OxyColors.Black); | ||
| axis.TextColor = OxyColor.FromAColor(255, OxyColors.Black); | ||
| } | ||
| } | ||
|
|
||
| private static PlotModel GetLinearAxisPlotModel() | ||
| { | ||
| var model = new PlotModel(); | ||
| model.Axes.Add(new LinearAxis { Maximum = 36, Minimum = 0, Title = "km/h" }); | ||
| model.Axes.Add(new LinearAxis { Maximum = 10, Minimum = 0, Position = AxisPosition.Right, Title = "m/s" }); | ||
| model.Axes.Add(new LinearAxis | ||
| { | ||
| Maximum = 10, | ||
| Minimum = 0, | ||
| Position = AxisPosition.Bottom, | ||
| Title = "meter" | ||
| }); | ||
| model.Axes.Add(new LinearAxis | ||
| { | ||
| Maximum = 10000, | ||
| Minimum = 0, | ||
| Position = AxisPosition.Top, | ||
| Title = "millimeter" | ||
| }); | ||
| return model; | ||
| } | ||
|
|
||
| private static PlotModel GetAngleAxisPlotModel() | ||
| { | ||
| var model = new PlotModel | ||
| { | ||
| PlotType = PlotType.Polar, | ||
| PlotAreaBorderThickness = new OxyThickness(0), | ||
| }; | ||
| model.Axes.Add( | ||
| new AngleAxis | ||
| { | ||
| MajorStep = Math.PI / 4, | ||
| MinorStep = Math.PI / 16, | ||
| MajorGridlineStyle = LineStyle.Solid, | ||
| MinorGridlineStyle = LineStyle.Solid, | ||
| FormatAsFractions = true, | ||
| FractionUnit = Math.PI, | ||
| FractionUnitSymbol = "π", | ||
| Minimum = 0, | ||
| Maximum = 2 * Math.PI | ||
| }); | ||
| model.Axes.Add(new MagnitudeAxis | ||
| { | ||
| MajorGridlineStyle = LineStyle.Solid, | ||
| MinorGridlineStyle = LineStyle.Solid, | ||
| }); | ||
| model.Series.Add(new FunctionSeries(t => t, t => t, 0, Math.PI * 6, 0.01)); | ||
| return model; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| <Application x:Class="WpfExamples.App" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| StartupUri="MainWindow.xaml"> | ||
| StartupUri="Examples/AxisAreaDemo/MainWindow.xaml"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this file didn't make it into the commit |
||
| <Application.Resources> | ||
|
|
||
| </Application.Resources> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,13 +51,18 @@ public override void Render(Axis axis, int pass) | |
|
|
||
| var axisLength = Math.Abs(scaledEndAngle - scaledStartAngle); | ||
| var eps = axis.MinorStep * 1e-3; | ||
|
|
||
| ScreenPoint? innerTangentPoint = null; | ||
| double maxTextLength = double.MinValue; | ||
|
|
||
| if (this.MinorPen != null) | ||
| { | ||
| var tickCount = Math.Abs((int)(axisLength / axis.ActualMinorStep)); | ||
| var screenPoints = this.MinorTickValues | ||
| .Take(tickCount + 1) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| innerTangentPoint = screenPoints.FirstOrDefault(); | ||
| foreach (var screenPoint in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, screenPoint.x, screenPoint.y, this.MinorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -77,6 +82,8 @@ public override void Render(Axis axis, int pass) | |
| .Take(majorTickCount) | ||
| .Select(x => magnitudeAxis.Transform(magnitudeAxis.ClipMaximum, x, axis)); | ||
|
|
||
| if (innerTangentPoint == null && screenPoints.Count() > 0) | ||
| innerTangentPoint = screenPoints.FirstOrDefault(); | ||
| foreach (var point in screenPoints) | ||
| { | ||
| this.RenderContext.DrawLine(magnitudeAxis.MidPoint.x, magnitudeAxis.MidPoint.y, point.x, point.y, this.MajorPen, axis.EdgeRenderingMode); | ||
|
|
@@ -112,9 +119,26 @@ public override void Render(Axis axis, int pass) | |
| ha = HorizontalAlignment.Right; | ||
| } | ||
|
|
||
| maxTextLength = Math.Max(maxTextLength, this.RenderContext.MeasureText(text).Width); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be |
||
|
|
||
| this.RenderContext.DrawMathText( | ||
| pt, text, axis.ActualTextColor, axis.ActualFont, axis.ActualFontSize, axis.ActualFontWeight, angle, ha, va); | ||
| } | ||
|
|
||
| if (innerTangentPoint != null) | ||
| { | ||
| double r1 = magnitudeAxis.MidPoint.DistanceTo(innerTangentPoint.Value); | ||
| double r2 = r1 + maxTextLength + axis.AxisTickToLabelDistance; | ||
| if (r2 < 5) | ||
| r2 = r1 + 5; | ||
| axis.AxisLineArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| axis.AxisArea = new OxyAnnulus(magnitudeAxis.MidPoint, r1, r2); | ||
| } | ||
| else | ||
| { | ||
| axis.AxisLineArea = new EmptyShape(); | ||
| axis.AxisArea = new EmptyShape(); | ||
| } | ||
| } | ||
| } | ||
| } | ||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs copyright header (see AxisExample.cs for example), and filename should be
AxisAreaExamples.cs