-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathTwoColorLineSeries.cs
More file actions
153 lines (133 loc) · 5.06 KB
/
Copy pathTwoColorLineSeries.cs
File metadata and controls
153 lines (133 loc) · 5.06 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TwoColorLineSeries.cs" company="OxyPlot">
// Copyright (c) 2014 OxyPlot contributors
// </copyright>
// <summary>
// Represents a two-color line series.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace OxyPlot.Series
{
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a two-color line series.
/// </summary>
public class TwoColorLineSeries : LineSeries
{
/// <summary>
/// The default second color.
/// </summary>
private OxyColor defaultColor2;
/// <summary>
/// Initializes a new instance of the <see cref = "TwoColorLineSeries" /> class.
/// </summary>
public TwoColorLineSeries()
{
this.Limit = 0.0;
this.Color2 = OxyColors.Blue;
this.LineStyle2 = LineStyle.Solid;
}
/// <summary>
/// Gets or sets the color for the part of the line that is below the limit.
/// </summary>
public OxyColor Color2 { get; set; }
/// <summary>
/// Gets the actual second color.
/// </summary>
/// <value>The actual color.</value>
public OxyColor ActualColor2
{
get { return this.Color2.GetActualColor(this.defaultColor2); }
}
/// <summary>
/// Gets or sets the limit.
/// </summary>
/// <remarks>The parts of the line that is below this limit will be rendered with Color2.
/// The parts of the line that is above the limit will be rendered with Color.</remarks>
public double Limit { get; set; }
/// <summary>
/// Gets or sets the dash array for the rendered line that is below the limit (overrides <see cref="LineStyle" />).
/// </summary>
/// <value>The dash array.</value>
/// <remarks>If this is not <c>null</c> it overrides the <see cref="LineStyle" /> property.</remarks>
public double[] Dashes2 { get; set; }
/// <summary>
/// Gets or sets the line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle LineStyle2 { get; set; }
/// <summary>
/// Gets the actual line style for the part of the line that is below the limit.
/// </summary>
/// <value>The line style.</value>
public LineStyle ActualLineStyle2
{
get
{
return this.LineStyle2 != LineStyle.Automatic ? this.LineStyle2 : LineStyle.Solid;
}
}
/// <summary>
/// Gets the actual dash array for the line that is below the limit.
/// </summary>
protected double[] ActualDashArray2
{
get
{
return this.Dashes2 ?? this.ActualLineStyle2.GetDashArray();
}
}
/// <summary>
/// Sets the default values.
/// </summary>
protected internal override void SetDefaultValues()
{
base.SetDefaultValues();
if (this.Color2.IsAutomatic())
{
this.defaultColor2 = this.PlotModel.GetDefaultColor();
}
if (this.LineStyle2 == LineStyle.Automatic)
{
this.LineStyle2 = this.PlotModel.GetDefaultLineStyle();
}
}
/// <inheritdoc/>
protected override void RenderLine(IRenderContext rc, IList<ScreenPoint> pointsToRender)
{
var clippingRect = this.GetClippingRect();
var p1 = this.InverseTransform(clippingRect.BottomLeft);
var p2 = this.InverseTransform(clippingRect.TopRight);
var clippingRectLo = new OxyRect(
this.Transform(p1.X, Math.Min(p1.Y, p2.Y)),
this.Transform(p2.X, this.Limit)).Clip(clippingRect);
var clippingRectHi = new OxyRect(
this.Transform(p1.X, Math.Max(p1.Y, p2.Y)),
this.Transform(p2.X, this.Limit)).Clip(clippingRect);
if (this.StrokeThickness <= 0 || this.ActualLineStyle == LineStyle.None)
{
return;
}
void RenderLine(OxyColor color)
{
rc.DrawReducedLine(
pointsToRender,
this.MinimumSegmentLength * this.MinimumSegmentLength,
this.GetSelectableColor(color),
this.StrokeThickness,
this.EdgeRenderingMode,
this.ActualDashArray,
this.LineJoin);
}
using (rc.AutoResetClip(clippingRectLo))
{
RenderLine(this.ActualColor2);
}
using (rc.AutoResetClip(clippingRectHi))
{
RenderLine(this.ActualColor);
}
}
}
}