-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathPointAnnotation.cs
More file actions
113 lines (98 loc) · 3.87 KB
/
Copy pathPointAnnotation.cs
File metadata and controls
113 lines (98 loc) · 3.87 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
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PointAnnotation.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Represents an annotation that shows a point.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
#nullable enable
namespace OxyPlot.Annotations
{
/// <summary>
/// Represents an annotation that shows a point.
/// </summary>
public class PointAnnotation : ShapeAnnotation
{
/// <summary>
/// The position transformed to screen coordinates.
/// </summary>
private ScreenPoint screenPosition;
/// <summary>
/// Initializes a new instance of the <see cref="PointAnnotation" /> class.
/// </summary>
public PointAnnotation()
{
this.Size = 4;
this.TextMargin = 2;
this.Shape = MarkerType.Circle;
this.TextVerticalAlignment = VerticalAlignment.Top;
}
/// <summary>
/// Gets or sets the x-coordinate of the center.
/// </summary>
public double X { get; set; }
/// <summary>
/// Gets or sets the y-coordinate of the center.
/// </summary>
public double Y { get; set; }
/// <summary>
/// Gets or sets the size of the rendered point.
/// </summary>
public double Size { get; set; }
/// <summary>
/// Gets or sets the distance between the rendered point and the text.
/// </summary>
public double TextMargin { get; set; }
/// <summary>
/// Gets or sets the shape of the rendered point.
/// </summary>
/// <value>The shape.</value>
public MarkerType Shape { get; set; }
/// <summary>
/// Gets or sets a custom polygon outline for the point marker. Set <see cref="Shape" /> to <see cref="MarkerType.Custom" /> to use this property.
/// </summary>
/// <value>A polyline. The default is <c>null</c>.</value>
public ScreenPoint[]? CustomOutline { get; set; }
/// <inheritdoc/>
public override void Render(IRenderContext rc)
{
base.Render(rc);
this.screenPosition = this.Transform(this.X, this.Y);
rc.DrawMarker(this.screenPosition, this.Shape, this.CustomOutline, this.Size, this.Fill, this.Stroke, this.StrokeThickness, this.EdgeRenderingMode);
if (this.Text != null &&
!string.IsNullOrEmpty(this.Text))
{
this.GetActualTextAlignment(out var ha, out var va);
var dx = -(int)ha * (this.Size + this.TextMargin);
var dy = -(int)va * (this.Size + this.TextMargin);
var textPosition = this.screenPosition + new ScreenVector(dx, dy);
rc.DrawText(
textPosition,
this.Text,
this.ActualTextColor,
this.ActualFont,
this.ActualFontSize,
this.ActualFontWeight,
this.TextRotation,
ha,
va);
}
}
/// <summary>
/// When overridden in a derived class, tests if the plot element is hit by the specified point.
/// </summary>
/// <param name="args">The hit test arguments.</param>
/// <returns>
/// The result of the hit test.
/// </returns>
protected override HitTestResult? HitTestOverride(HitTestArguments args)
{
if (this.screenPosition.DistanceTo(args.Point) < this.Size)
{
return new HitTestResult(this, this.screenPosition);
}
return null;
}
}
}