-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathAnnotation.cs
More file actions
131 lines (111 loc) · 4.25 KB
/
Copy pathAnnotation.cs
File metadata and controls
131 lines (111 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Annotation.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Provides an abstract base class for annotations.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
#nullable enable
namespace OxyPlot.Annotations
{
using OxyPlot.Axes;
/// <summary>
/// Provides an abstract base class for annotations.
/// </summary>
public abstract class Annotation : PlotElement, IXyAxisPlotElement
{
/// <summary>
/// Initializes a new instance of the <see cref="Annotation" /> class.
/// </summary>
protected Annotation()
{
this.Layer = AnnotationLayer.AboveSeries;
this.ClipByXAxis = true;
this.ClipByYAxis = true;
}
/// <summary>
/// Gets or sets the rendering layer of the annotation. The default value is <see cref="AnnotationLayer.AboveSeries" />.
/// </summary>
public AnnotationLayer Layer { get; set; }
/// <summary>
/// Gets the X axis.
/// </summary>
/// <value>The X axis.</value>
public Axis? XAxis { get; private set; }
/// <summary>
/// Gets or sets the X axis key.
/// </summary>
/// <value>The X axis key.</value>
public string? XAxisKey { get; set; }
/// <summary>
/// Gets the Y axis.
/// </summary>
/// <value>The Y axis.</value>
public Axis? YAxis { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether to clip the annotation by the X axis range.
/// </summary>
/// <value><c>true</c> if clipping by the X axis is enabled; otherwise, <c>false</c>.</value>
public bool ClipByXAxis { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to clip the annotation by the Y axis range.
/// </summary>
/// <value><c>true</c> if clipping by the Y axis is enabled; otherwise, <c>false</c>.</value>
public bool ClipByYAxis { get; set; }
/// <summary>
/// Gets or sets the Y axis key.
/// </summary>
/// <value>The Y axis key.</value>
public string? YAxisKey { get; set; }
/// <summary>
/// Ensures that the annotation axes are set.
/// </summary>
public void EnsureAxes()
{
this.XAxis = this.XAxisKey != null ? this.PlotModel.GetAxis(this.XAxisKey) : this.PlotModel.DefaultXAxis;
this.YAxis = this.YAxisKey != null ? this.PlotModel.GetAxis(this.YAxisKey) : this.PlotModel.DefaultYAxis;
}
/// <summary>
/// Renders the annotation on the specified context.
/// </summary>
/// <param name="rc">The render context.</param>
public virtual void Render(IRenderContext rc)
{
}
/// <inheritdoc/>
public override OxyRect GetClippingRect()
{
var rect = this.PlotModel.PlotArea;
var axisRect = PlotElementUtilities.GetClippingRect(this);
var minX = 0d;
var maxX = double.PositiveInfinity;
var minY = 0d;
var maxY = double.PositiveInfinity;
if (this.ClipByXAxis)
{
minX = axisRect.TopLeft.X;
maxX = axisRect.BottomRight.X;
}
if (this.ClipByYAxis)
{
minY = axisRect.TopLeft.Y;
maxY = axisRect.BottomRight.Y;
}
var minPoint = new ScreenPoint(minX, minY);
var maxPoint = new ScreenPoint(maxX, maxY);
var axisClipRect = new OxyRect(minPoint, maxPoint);
return rect.Clip(axisClipRect);
}
/// <inheritdoc/>
public virtual ScreenPoint Transform(DataPoint p)
{
return PlotElementUtilities.Transform(this, p);
}
/// <inheritdoc/>
public virtual DataPoint InverseTransform(ScreenPoint p)
{
return PlotElementUtilities.InverseTransform(this, p);
}
}
}