-
Notifications
You must be signed in to change notification settings - Fork 0
/
PointControl.cs
119 lines (117 loc) · 3.71 KB
/
PointControl.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.DataVisualization.Charting;
namespace CanSat_Desktop
{
class PointControl
{
private Series curve;
public PointControl(Chart chart, int indx) { curve = chart.Series[0]; }
public PointControl(Series s) { curve = s;}
public void Clear()
{
curve.Points.Clear();
}
public void AddPointsY(double[] dots)
{
foreach (double x in dots)
AddPointY(x);
}
public void AddPointsXY(Dictionary<double, double> dots)
{
foreach (KeyValuePair<double, double> kvp in dots)
AddPointXY(kvp.Key, kvp.Value);
}
public void AddPointY(double x)
{
double xPos = MaximumX;
AddPointXY(++xPos, x);
}
public void AddPointXY(double x, double y)
{
curve.Points.AddXY(x, y);
}
public DataPoint GetPoint(double x)
{
return curve.Points.Where((DataPoint y) => { return y.XValue == x; }).First();
}
public double MaximumAtRange(double leftX, double rightX)
{
return curve.Points.Select((DataPoint x) => { return x.YValues.Max(); }).Where((double x) => { return x >= leftX && x <= rightX; }).Max();
}
public double MinimumAtRange(double leftX, double rightX)
{
return curve.Points.Select((DataPoint x) => { return x.YValues.Min(); }).Where((double x) => { return x >= leftX && x <= rightX; }).Min();
}
public double MaximumX
{
get
{
List<DataPoint> points = curve.Points.ToList();
if (points.Count == 0)
return -1;
double max = points.Max<DataPoint>((DataPoint x) => { return x.XValue; });
return max;
}
}
public double MinimumX
{
get
{
List<DataPoint> points = curve.Points.ToList();
if (points.Count == 0)
return -1;
double min = points.Min<DataPoint>((DataPoint x) => { return x.XValue; });
return min;
}
}
public double MaximumY
{
get
{
List<DataPoint> points = curve.Points.ToList();
if (points.Count == 0)
return 0;
double max = points.Max((DataPoint dp) => { return dp.YValues.Max(); });
return max;
}
}
public double MinimumY
{
get
{
List<DataPoint> points = curve.Points.ToList();
if (points.Count == 0)
return 0;
double min = points.Min((DataPoint dp) => { return dp.YValues.Min(); });
return min;
}
}
public void CopyTo(PointControl target)
{
foreach(DataPoint dp in this.curve.Points.ToArray())
{
target.curve.Points.AddXY(dp.XValue, dp.YValues[0]);
}
ChartType = target.ChartType;
}
public void CopyFrom(PointControl source)
{
source.CopyTo(this);
}
public SeriesChartType ChartType
{
get
{
return curve.ChartType;
}
set
{
curve.ChartType = value;
}
}
}
}