Add AxisArea, AxisLineArea and AxisTitleArea property in Axis class (… by ChrisCC6 · Pull Request #1966 · oxyplot/oxyplot · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Carlos Anderson <carlosjanderson@gmail.com>
Carlos Teixeira <karlmtc@gmail.com>
Chase Long <chaselfromal@gmail.com>
Choden Konigsmark <choden.konigsmark@gmail.com>
ChrisCC6 <christian.woempner@gmail.com>
classicboss302
csabar <rumancsabi@gmail.com>
Curt Mullin <curt.mullin@gmail.com>
Expand Down
158 changes: 158 additions & 0 deletions Source/Examples/ExampleLibrary/Axes/AxisAreaExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
using OxyPlot;

Copy link
Copy Markdown
Contributor

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

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;
}
}
}
2 changes: 1 addition & 1 deletion Source/Examples/WPF/WpfExamples/App.xaml
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">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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>
Expand Down
19 changes: 19 additions & 0 deletions Source/OxyPlot/Axes/Axis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ protected Axis()

this.DataMaximum = double.NaN;
this.DataMinimum = double.NaN;

this.TitleArea = new EmptyShape();
this.AxisArea = new EmptyShape();
this.AxisLineArea = new EmptyShape();
}

/// <summary>
Expand Down Expand Up @@ -634,6 +638,21 @@ public double Scale
/// </summary>
public OxyThickness DesiredMargin { get; protected set; }

/// <summary>
/// The area of the axis in screen coordinates.
/// </summary>
public IOxyRegion AxisArea { get; internal protected set; }

/// <summary>
/// The area of the axis line in screen coordinates.
/// </summary>
public IOxyRegion AxisLineArea { get; internal protected set; }

/// <summary>
/// The area of the axis title in screen coordinates.
/// </summary>
public IOxyRegion TitleArea { get; internal protected set; }

/// <summary>
/// Gets or sets the position tier max shift.
/// </summary>
Expand Down
24 changes: 24 additions & 0 deletions Source/OxyPlot/Axes/Rendering/AngleAxisRenderer.cs
Loading