Code
·
284 lines
·
9385 bytes
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284//============================================================================
//ZedGraph Class Library - A Flexible Charting Library for .Net
//Copyright � 2005 John Champion and Jerry Vos
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//=============================================================================
using System;
using System.Collections;
using System.Text;
using System.Drawing;
namespace ZedGraph
{
/// <summary>
/// An enum used to specify the X or Y data type of interest -- see
/// <see cref="SampleMultiPointList.XData" /> and <see cref="SampleMultiPointList.YData" />.
/// </summary>
public enum PerfDataType
{
/// <summary>
/// The time (seconds) at which these data are measured
/// </summary>
Time,
/// <summary>
/// The distance traveled, meters
/// </summary>
Distance,
/// <summary>
/// The instantaneous velocity, meters per second
/// </summary>
Velocity,
/// <summary>
/// The instantaneous acceleration, meters per second squared
/// </summary>
Acceleration
};
/// <summary>
/// Sample data structure containing a variety of data values, in this case the values
/// are related in that they correspond to the same time value.
/// </summary>
public class PerformanceData
{
/// <summary>
/// The time (seconds) at which these data are measured
/// </summary>
public double time;
/// <summary>
/// The distance traveled, meters
/// </summary>
public double distance;
/// <summary>
/// The instantaneous velocity, meters per second
/// </summary>
public double velocity;
/// <summary>
/// The instantaneous acceleration, meters per second squared
/// </summary>
public double acceleration;
/// <summary>
/// Constructor that specifies each data value in the PerformanceData struct
/// </summary>
/// <param name="time">The time (seconds) at which these data are measured</param>
/// <param name="distance">The distance traveled, meters</param>
/// <param name="velocity">The instantaneous velocity, meters per second</param>
/// <param name="acceleration">The instantaneous acceleration, meters per second squared</param>
public PerformanceData( double time, double distance, double velocity, double acceleration )
{
this.time = time;
this.distance = distance;
this.velocity = velocity;
this.acceleration = acceleration;
}
/// <summary>
/// Gets or sets the data value as specified by the <see cref="PerfDataType" /> enum
/// </summary>
/// <param name="type">The required data value type</param>
public double this[ PerfDataType type ]
{
get
{
switch( type )
{
default:
case PerfDataType.Time:
return time;
case PerfDataType.Distance:
return distance;
case PerfDataType.Velocity:
return velocity;
case PerfDataType.Acceleration:
return acceleration;
}
}
set
{
switch( type )
{
case PerfDataType.Time:
time = value;
break;
case PerfDataType.Distance:
distance = value;
break;
case PerfDataType.Velocity:
velocity = value;
break;
case PerfDataType.Acceleration:
acceleration = value;
break;
}
}
}
}
/// <summary>
/// A sample class that holds an internal collection, and implements the
/// <see cref="IPointList" /> interface so that it can be used by ZedGraph as curve data.
/// </summary>
/// <remarks>
/// This particular class efficiently implements the data storage so that the class
/// can be cloned without duplicating the data points. For example, you can create
/// a <see cref="SampleMultiPointList" />, populate it with values, and set
/// <see cref="XData" /> = <see cref="PerfDataType.Time" /> and
/// <see cref="YData" /> = <see cref="PerfDataType.Distance" />.
/// You can then clone this <see cref="SampleMultiPointList" /> to a new one, and set
/// <see cref="YData" /> = <see cref="PerfDataType.Velocity" />.
/// Each of these <see cref="SampleMultiPointList" />'s can then be used as an
/// <see cref="ZedGraph.GraphPane.AddCurve(string,IPointList,Color)" /> argument,
/// thereby plotting a distance vs time curve and a velocity vs time curve. There
/// will still be only one copy of the data in memory.
/// </remarks>
[Serializable]
public class SampleMultiPointList : IPointList
{
/// <summary>
/// This is where the data are stored. Duplicating the <see cref="SampleMultiPointList" />
/// copies the reference to this <see cref="ArrayList" />, but does not actually duplicate
/// the data.
/// </summary>
private ArrayList DataCollection;
/// <summary>
/// Determines what X data will be returned by the indexer of this list.
/// </summary>
public PerfDataType XData;
/// <summary>
/// Determines what Y data will be returned by the indexer of this list.
/// </summary>
public PerfDataType YData;
/// <summary>
/// Default constructor
/// </summary>
public SampleMultiPointList()
{
XData = PerfDataType.Time;
YData = PerfDataType.Distance;
DataCollection = new ArrayList();
}
/// <summary>
/// The Copy Constructor. This method does NOT duplicate the data, it merely makes
/// another "Window" into the same collection. You can make multiple copies and
/// set the <see cref="XData" /> and/or <see cref="YData" /> properties to different
/// values to plot different data, while maintaining only one copy of the original values.
/// </summary>
/// <param name="rhs">The <see cref="SampleMultiPointList" /> from which to copy</param>
public SampleMultiPointList( SampleMultiPointList rhs )
{
DataCollection = rhs.DataCollection;
XData = rhs.XData;
YData = rhs.YData;
}
/// <summary>
/// Implement the <see cref="ICloneable" /> interface in a typesafe manner by just
/// calling the typed version of <see cref="Clone" />
/// </summary>
/// <returns>A deep copy of this object</returns>
object ICloneable.Clone()
{
return this.Clone();
}
/// <summary>
/// Typesafe, deep-copy clone method.
/// </summary>
/// <returns>A new, independent copy of this class</returns>
public SampleMultiPointList Clone()
{
return new SampleMultiPointList( this );
}
/// <summary>
/// Indexer to access the data. This gets the appropriate data and converts to
/// the <see cref="PointPair" /> struct that is compatible with ZedGraph. The
/// actual data returned depends on the values of <see cref="XData" /> and
/// <see cref="YData" />.
/// </summary>
/// <param name="index">The ordinal position of the desired point in the list</param>
/// <returns>A <see cref="PointPair" /> corresponding to the specified ordinal data position</returns>
public PointPair this[ int index ]
{
get
{
double xVal, yVal;
if ( index >= 0 && index < this.Count )
{
// grab the specified PerformanceData struct
PerformanceData perfData = (PerformanceData) DataCollection[index];
// extract the values from the struct according to the user-set
// enum values of XData and YData
xVal = perfData[XData];
yVal = perfData[YData];
}
else
{
xVal = PointPair.Missing;
yVal = PointPair.Missing;
}
// insert the values into a pointpair and return
return new PointPair( xVal, yVal, PointPair.Missing, null );
}
}
/// <summary>
/// Gets the number of data points in the collection
/// </summary>
public int Count
{
get { return DataCollection.Count; }
}
/// <summary>
/// Adds the specified <see cref="PerformanceData" /> struct to the end of the collection.
/// </summary>
/// <param name="perfData">A <see cref="PerformanceData" /> struct to be added</param>
/// <returns>The ordinal position in the collection where the values were added</returns>
public int Add( PerformanceData perfData )
{
return DataCollection.Add( perfData );
}
/// <summary>
/// Remove the <see cref="PerformanceData" /> struct from the list at the specified
/// ordinal location.
/// </summary>
/// <param name="index">The ordinal location of the <see cref="PerformanceData" />
/// struct to be removed</param>
public void RemoveAt( int index )
{
DataCollection.RemoveAt( index );
}
/// <summary>
/// Insert the specified <see cref="PerformanceData" /> struct into the list at
/// the specified ordinal location.
/// </summary>
/// <param name="index">The ordinal location at which to insert</param>
/// <param name="perfData">The <see cref="PerformanceData" /> struct to be inserted</param>
public void Insert( int index, PerformanceData perfData )
{
DataCollection.Insert( index, perfData );
}
}
}