1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Threading;
|
---|
4 | using NUnit.Framework;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Visualization.Test {
|
---|
7 | [TestFixture]
|
---|
8 | public class LineChartTests {
|
---|
9 | private ChartDataRowsModel model;
|
---|
10 |
|
---|
11 | [SetUp]
|
---|
12 | public void SetUp() {
|
---|
13 | model = new ChartDataRowsModel();
|
---|
14 | }
|
---|
15 |
|
---|
16 | [Test]
|
---|
17 | public void TestLineChart() {
|
---|
18 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
19 |
|
---|
20 | IDataRow row1 = new DataRow();
|
---|
21 | IDataRow row2 = new DataRow();
|
---|
22 | IDataRow row3 = new DataRow();
|
---|
23 |
|
---|
24 | row1.Color = Color.Red;
|
---|
25 | row2.Color = Color.Green;
|
---|
26 | row3.Color = Color.Blue;
|
---|
27 |
|
---|
28 | row1.Thickness = 3;
|
---|
29 | row2.Thickness = 4;
|
---|
30 | row3.Thickness = 5;
|
---|
31 |
|
---|
32 | row1.Label = "Simon";
|
---|
33 | row2.Label = "Gertschi";
|
---|
34 | row3.Label = "Maxi";
|
---|
35 |
|
---|
36 | row1.Style = DrawingStyle.Solid;
|
---|
37 | row2.Style = DrawingStyle.Solid;
|
---|
38 | row3.Style = DrawingStyle.Dashed;
|
---|
39 |
|
---|
40 |
|
---|
41 | model.AddDataRow(row1);
|
---|
42 | model.AddDataRow(row2);
|
---|
43 | model.AddDataRow(row3);
|
---|
44 |
|
---|
45 | row1.AddValue(10);
|
---|
46 | row1.AddValue(5);
|
---|
47 | row1.AddValue(7);
|
---|
48 | row1.AddValue(3);
|
---|
49 | row1.AddValue(10);
|
---|
50 | row1.AddValue(2);
|
---|
51 |
|
---|
52 | row2.AddValue(5);
|
---|
53 | row2.AddValue(6);
|
---|
54 | row2.AddValue(5);
|
---|
55 |
|
---|
56 | row3.AddValue(2);
|
---|
57 | row3.AddValue(2);
|
---|
58 | row3.AddValue(2);
|
---|
59 | row3.AddValue(2);
|
---|
60 | row3.AddValue(2);
|
---|
61 |
|
---|
62 | Random rand = new Random();
|
---|
63 |
|
---|
64 | for (int i = 0; i < 10000; i++) {
|
---|
65 | row1.AddValue(rand.NextDouble()*10);
|
---|
66 | row2.AddValue(rand.NextDouble()*10);
|
---|
67 | row3.AddValue(rand.NextDouble()*10);
|
---|
68 | }
|
---|
69 |
|
---|
70 | f.ShowDialog();
|
---|
71 | }
|
---|
72 |
|
---|
73 | [Test]
|
---|
74 | public void TestAxes() {
|
---|
75 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
76 |
|
---|
77 | IDataRow row1 = new DataRow();
|
---|
78 | IDataRow row2 = new DataRow();
|
---|
79 | IDataRow row3 = new DataRow();
|
---|
80 |
|
---|
81 | YAxisDescriptor yaxis1 = model.DefaultYAxis;
|
---|
82 | YAxisDescriptor yaxis2 = new YAxisDescriptor();
|
---|
83 |
|
---|
84 | yaxis1.Label = "Y-Axis 1";
|
---|
85 | yaxis2.Label = "Y-Axis 2";
|
---|
86 |
|
---|
87 | row1.Color = Color.Red;
|
---|
88 | row1.Thickness = 3;
|
---|
89 | row1.Style = DrawingStyle.Solid;
|
---|
90 | row1.Label = "Die Rote";
|
---|
91 |
|
---|
92 | row2.Color = Color.Green;
|
---|
93 | row2.Thickness = 3;
|
---|
94 | row2.Style = DrawingStyle.Solid;
|
---|
95 | row2.Label = "Die Grüne";
|
---|
96 |
|
---|
97 | row3.Color = Color.Blue;
|
---|
98 | row3.Thickness = 3;
|
---|
99 | row3.Style = DrawingStyle.Solid;
|
---|
100 | row3.Label = "Die Blaue";
|
---|
101 | row3.YAxis = yaxis2;
|
---|
102 | row3.YAxis.Label = "Die Blaue";
|
---|
103 |
|
---|
104 | model.AddDataRow(row1);
|
---|
105 | model.AddDataRow(row2);
|
---|
106 | model.AddDataRow(row3);
|
---|
107 |
|
---|
108 | row1.YAxis.Label = "Rot und Grün";
|
---|
109 |
|
---|
110 | Random rand = new Random(42);
|
---|
111 |
|
---|
112 | for (int i = 0; i < 10; i++) {
|
---|
113 | row1.AddValue(rand.NextDouble()*10);
|
---|
114 | row2.AddValue(rand.NextDouble()*10);
|
---|
115 | row3.AddValue(rand.NextDouble()*1);
|
---|
116 | }
|
---|
117 |
|
---|
118 | f.AddValue += delegate {
|
---|
119 | row1.AddValue(rand.NextDouble()*10);
|
---|
120 | row2.AddValue(rand.NextDouble()*10);
|
---|
121 | row3.AddValue(rand.NextDouble()*1);
|
---|
122 | };
|
---|
123 |
|
---|
124 | f.ShowDialog();
|
---|
125 | }
|
---|
126 |
|
---|
127 | [Test]
|
---|
128 | public void TestAggregator() {
|
---|
129 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
130 |
|
---|
131 | IDataRow row1 = new DataRow();
|
---|
132 | row1.Label = "row";
|
---|
133 | row1.Color = Color.Red;
|
---|
134 | row1.Thickness = 3;
|
---|
135 | row1.Style = DrawingStyle.Solid;
|
---|
136 |
|
---|
137 | model.AddDataRow(row1);
|
---|
138 |
|
---|
139 |
|
---|
140 | MinAggregator aggregator = new MinAggregator();
|
---|
141 | aggregator.Label = "MinAggregator";
|
---|
142 | aggregator.Color = Color.Pink;
|
---|
143 | aggregator.Thickness = 5;
|
---|
144 | aggregator.Style = DrawingStyle.Solid;
|
---|
145 | aggregator.AddValue(2);
|
---|
146 | aggregator.LineType = DataRowType.SingleValue;
|
---|
147 |
|
---|
148 | IDataRow lineTest = new DataRow("testline");
|
---|
149 | lineTest.Color = Color.DarkSalmon;
|
---|
150 | lineTest.Thickness = 2;
|
---|
151 | lineTest.Style = DrawingStyle.Dashed;
|
---|
152 | lineTest.LineType = DataRowType.SingleValue;
|
---|
153 | model.AddDataRow(lineTest);
|
---|
154 | lineTest.AddValue(9);
|
---|
155 | lineTest.AddValue(2);
|
---|
156 | lineTest.AddValue(3);
|
---|
157 | lineTest.AddValue(4);
|
---|
158 |
|
---|
159 | aggregator.AddWatch(row1);
|
---|
160 |
|
---|
161 | model.AddDataRow(aggregator);
|
---|
162 |
|
---|
163 |
|
---|
164 | row1.AddValue(10);
|
---|
165 | row1.AddValue(5);
|
---|
166 | row1.AddValue(7);
|
---|
167 | row1.AddValue(3);
|
---|
168 | row1.AddValue(10);
|
---|
169 | row1.AddValue(2);
|
---|
170 |
|
---|
171 | f.ShowDialog();
|
---|
172 | }
|
---|
173 |
|
---|
174 |
|
---|
175 | public class Worker {
|
---|
176 | // This method will be called when the thread is started.
|
---|
177 | private ChartDataRowsModel model;
|
---|
178 | public Worker(ChartDataRowsModel model) {
|
---|
179 | this.model = model;
|
---|
180 | }
|
---|
181 |
|
---|
182 | public void DoWorkMultiLine() {
|
---|
183 |
|
---|
184 | IDataRow row1 = new DataRow();
|
---|
185 | row1.Color = Color.Red;
|
---|
186 | row1.Thickness = 2;
|
---|
187 | row1.Label = "Sinus";
|
---|
188 | row1.Style = DrawingStyle.Solid;
|
---|
189 | model.AddDataRow(row1);
|
---|
190 |
|
---|
191 | IDataRow row2 = new DataRow();
|
---|
192 | row2.Color = Color.Red;
|
---|
193 | row2.Thickness = 3;
|
---|
194 | row2.Label = "Growing";
|
---|
195 | row2.Style = DrawingStyle.Solid;
|
---|
196 | model.AddDataRow(row2);
|
---|
197 |
|
---|
198 | AvgAggregator multiAvgAggregator = new AvgAggregator();
|
---|
199 | multiAvgAggregator.Label = "MultiAvgAggregator";
|
---|
200 | multiAvgAggregator.Color = Color.DarkOliveGreen;
|
---|
201 | multiAvgAggregator.Thickness = 3;
|
---|
202 | multiAvgAggregator.Style = DrawingStyle.Solid;
|
---|
203 | multiAvgAggregator.LineType = DataRowType.SingleValue;
|
---|
204 | multiAvgAggregator.AddWatch(row1);
|
---|
205 | multiAvgAggregator.AddWatch(row2);
|
---|
206 | model.AddDataRow(multiAvgAggregator);
|
---|
207 |
|
---|
208 | MaxAggregator multiMaxAggregator = new MaxAggregator();
|
---|
209 | multiMaxAggregator.Label = "MultiMaxAggregator";
|
---|
210 | multiMaxAggregator.Color = Color.DarkKhaki;
|
---|
211 | multiMaxAggregator.Thickness = 3;
|
---|
212 | multiMaxAggregator.Style = DrawingStyle.Solid;
|
---|
213 | multiMaxAggregator.LineType = DataRowType.SingleValue;
|
---|
214 | multiMaxAggregator.AddWatch(row1);
|
---|
215 | multiMaxAggregator.AddWatch(row2);
|
---|
216 | model.AddDataRow(multiMaxAggregator);
|
---|
217 |
|
---|
218 | MinAggregator multiMinAggregator = new MinAggregator();
|
---|
219 | multiMinAggregator.Label = "MultiMinAggregator";
|
---|
220 | multiMinAggregator.Color = Color.DarkRed;
|
---|
221 | multiMinAggregator.Thickness = 3;
|
---|
222 | multiMinAggregator.Style = DrawingStyle.Solid;
|
---|
223 | multiMinAggregator.LineType = DataRowType.SingleValue;
|
---|
224 | multiMinAggregator.AddWatch(row1);
|
---|
225 | multiMinAggregator.AddWatch(row2);
|
---|
226 | model.AddDataRow(multiMinAggregator);
|
---|
227 |
|
---|
228 | AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator();
|
---|
229 | multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
|
---|
230 | multiLineAvgAggregator.Color = Color.Red;
|
---|
231 | multiLineAvgAggregator.Thickness = 4;
|
---|
232 | multiLineAvgAggregator.Style = DrawingStyle.Solid;
|
---|
233 | multiLineAvgAggregator.LineType = DataRowType.Normal;
|
---|
234 | multiLineAvgAggregator.AddWatch(row1);
|
---|
235 | multiLineAvgAggregator.AddWatch(row2);
|
---|
236 | multiLineAvgAggregator.AddValue(0);
|
---|
237 | model.AddDataRow(multiLineAvgAggregator);
|
---|
238 |
|
---|
239 | double i = 0;
|
---|
240 | double newY;
|
---|
241 |
|
---|
242 | Random rand = new Random();
|
---|
243 | while (!_shouldStop && i <= 24) {
|
---|
244 | i += 0.2;
|
---|
245 | newY = Math.Sin(i);
|
---|
246 | System.Console.WriteLine("working");
|
---|
247 | //row1.AddValue(rand.NextDouble() * 10);
|
---|
248 | row1.AddValue(newY * 10);
|
---|
249 | row2.AddValue(i*2-15);
|
---|
250 | System.Threading.Thread.Sleep(100);
|
---|
251 | }
|
---|
252 | Console.WriteLine("worker thread: terminating gracefully.");
|
---|
253 | }
|
---|
254 | public void DoWorkSingleLine() {
|
---|
255 |
|
---|
256 | IDataRow row1 = new DataRow();
|
---|
257 | row1.Color = Color.Red;
|
---|
258 | row1.Thickness = 2;
|
---|
259 | row1.Label = "Sinus";
|
---|
260 | row1.Style = DrawingStyle.Solid;
|
---|
261 | model.AddDataRow(row1);
|
---|
262 |
|
---|
263 | IDataRow row2 = new DataRow();
|
---|
264 | row2.Color = Color.Red;
|
---|
265 | row2.Thickness = 3;
|
---|
266 | row2.Label = "Growing";
|
---|
267 | row2.Style = DrawingStyle.Solid;
|
---|
268 | model.AddDataRow(row2);
|
---|
269 |
|
---|
270 | MinAggregator aggregator = new MinAggregator();
|
---|
271 | aggregator.Label = "MinAggregator";
|
---|
272 | aggregator.Color = Color.Pink;
|
---|
273 | aggregator.Thickness = 3;
|
---|
274 | aggregator.Style = DrawingStyle.Solid;
|
---|
275 | aggregator.LineType = DataRowType.SingleValue;
|
---|
276 | aggregator.AddWatch(row1);
|
---|
277 | model.AddDataRow(aggregator);
|
---|
278 |
|
---|
279 | MaxAggregator maxAggregator = new MaxAggregator();
|
---|
280 | maxAggregator.Label = "MaxAggregator";
|
---|
281 | maxAggregator.Color = Color.DeepSkyBlue;
|
---|
282 | maxAggregator.Thickness = 3;
|
---|
283 | maxAggregator.Style = DrawingStyle.Solid;
|
---|
284 | maxAggregator.LineType = DataRowType.SingleValue;
|
---|
285 | maxAggregator.AddWatch(row1);
|
---|
286 | model.AddDataRow(maxAggregator);
|
---|
287 |
|
---|
288 | AvgAggregator avgAggregator = new AvgAggregator();
|
---|
289 | avgAggregator.Label = "AvgAggregator";
|
---|
290 | avgAggregator.Color = Color.Violet;
|
---|
291 | avgAggregator.Thickness = 3;
|
---|
292 | avgAggregator.Style = DrawingStyle.Solid;
|
---|
293 | avgAggregator.LineType = DataRowType.SingleValue;
|
---|
294 | avgAggregator.AddWatch(row1);
|
---|
295 | model.AddDataRow(avgAggregator);
|
---|
296 |
|
---|
297 | double i = 0;
|
---|
298 | double newY;
|
---|
299 |
|
---|
300 | Random rand = new Random();
|
---|
301 | while (!_shouldStop && i <= 24) {
|
---|
302 | i += 0.2;
|
---|
303 | newY = Math.Sin(i);
|
---|
304 | System.Console.WriteLine("working");
|
---|
305 | //row1.AddValue(rand.NextDouble() * 10);
|
---|
306 | row1.AddValue(newY * 10);
|
---|
307 | row2.AddValue(i * 2 - 15);
|
---|
308 | System.Threading.Thread.Sleep(100);
|
---|
309 | }
|
---|
310 | Console.WriteLine("worker thread: terminating gracefully.");
|
---|
311 | }
|
---|
312 | public void DoWorkAvgLine() {
|
---|
313 |
|
---|
314 | IDataRow row1 = new DataRow();
|
---|
315 | row1.Color = Color.Red;
|
---|
316 | row1.Thickness = 2;
|
---|
317 | row1.Label = "Sinus";
|
---|
318 | row1.Style = DrawingStyle.Solid;
|
---|
319 | model.AddDataRow(row1);
|
---|
320 |
|
---|
321 | IDataRow row2 = new DataRow();
|
---|
322 | row2.Color = Color.Red;
|
---|
323 | row2.Thickness = 3;
|
---|
324 | row2.Label = "Growing";
|
---|
325 | row2.Style = DrawingStyle.Solid;
|
---|
326 | model.AddDataRow(row2);
|
---|
327 |
|
---|
328 | AvgLineAggregator avgLineAggregator = new AvgLineAggregator();
|
---|
329 | avgLineAggregator.Label = "AvgLineAggregator";
|
---|
330 | avgLineAggregator.Color = Color.Violet;
|
---|
331 | avgLineAggregator.Thickness = 3;
|
---|
332 | avgLineAggregator.Style = DrawingStyle.Solid;
|
---|
333 | avgLineAggregator.LineType = DataRowType.Normal;
|
---|
334 | avgLineAggregator.AddWatch(row1);
|
---|
335 | avgLineAggregator.AddWatch(row2);
|
---|
336 | model.AddDataRow(avgLineAggregator);
|
---|
337 |
|
---|
338 | double i = 0;
|
---|
339 | double newY;
|
---|
340 |
|
---|
341 | Random rand = new Random();
|
---|
342 | while (!_shouldStop && i <= 24) {
|
---|
343 | i += 0.2;
|
---|
344 | newY = Math.Sin(i);
|
---|
345 | System.Console.WriteLine("working");
|
---|
346 | //row1.AddValue(rand.NextDouble() * 10);
|
---|
347 | row1.AddValue(newY * 10);
|
---|
348 | row2.AddValue(i * 2 - 15);
|
---|
349 | System.Threading.Thread.Sleep(100);
|
---|
350 | }
|
---|
351 | Console.WriteLine("worker thread: terminating gracefully.");
|
---|
352 | }
|
---|
353 | public void RequestStop() {
|
---|
354 | _shouldStop = true;
|
---|
355 | }
|
---|
356 | // Volatile is used as hint to the compiler that this data
|
---|
357 | // member will be accessed by multiple threads.
|
---|
358 | private volatile bool _shouldStop;
|
---|
359 | }
|
---|
360 |
|
---|
361 |
|
---|
362 | [Test]
|
---|
363 | public void TestAggregatorMultiLine() {
|
---|
364 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
365 |
|
---|
366 | // Create the thread object. This does not start the thread.
|
---|
367 | Worker workerObject = new Worker(model);
|
---|
368 | Thread workerThread = new Thread(workerObject.DoWorkMultiLine);
|
---|
369 |
|
---|
370 | // Start the worker thread.
|
---|
371 | workerThread.Start();
|
---|
372 |
|
---|
373 | f.ShowDialog();
|
---|
374 | workerObject.RequestStop();
|
---|
375 | }
|
---|
376 |
|
---|
377 | [Test]
|
---|
378 | public void TestAggregatorSingleLine() {
|
---|
379 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
380 |
|
---|
381 | // Create the thread object. This does not start the thread.
|
---|
382 | Worker workerObject = new Worker(model);
|
---|
383 | Thread workerThread = new Thread(workerObject.DoWorkSingleLine);
|
---|
384 |
|
---|
385 | // Start the worker thread.
|
---|
386 | workerThread.Start();
|
---|
387 |
|
---|
388 | f.ShowDialog();
|
---|
389 | workerObject.RequestStop();
|
---|
390 | }
|
---|
391 | [Test]
|
---|
392 | public void TestAggregatorAvgLine() {
|
---|
393 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
394 |
|
---|
395 | // Create the thread object. This does not start the thread.
|
---|
396 | Worker workerObject = new Worker(model);
|
---|
397 | Thread workerThread = new Thread(workerObject.DoWorkAvgLine);
|
---|
398 |
|
---|
399 | // Start the worker thread.
|
---|
400 | workerThread.Start();
|
---|
401 |
|
---|
402 | f.ShowDialog();
|
---|
403 | workerObject.RequestStop();
|
---|
404 | }
|
---|
405 |
|
---|
406 |
|
---|
407 |
|
---|
408 | [Test]
|
---|
409 | public void TestAutoZoomInConstructor() {
|
---|
410 | IDataRow row1 = new DataRow();
|
---|
411 |
|
---|
412 | row1.Color = Color.Red;
|
---|
413 | row1.Thickness = 3;
|
---|
414 | row1.Style = DrawingStyle.Solid;
|
---|
415 |
|
---|
416 | model.AddDataRow(row1);
|
---|
417 |
|
---|
418 | row1.AddValue(10);
|
---|
419 | row1.AddValue(5);
|
---|
420 | row1.AddValue(7);
|
---|
421 | row1.AddValue(3);
|
---|
422 | row1.AddValue(10);
|
---|
423 | row1.AddValue(2);
|
---|
424 |
|
---|
425 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
426 | f.ShowDialog();
|
---|
427 | }
|
---|
428 |
|
---|
429 |
|
---|
430 | [Test]
|
---|
431 | public void TestSingleValueDataRows() {
|
---|
432 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
433 |
|
---|
434 | IDataRow row1 = new DataRow();
|
---|
435 | IDataRow row2 = new DataRow();
|
---|
436 | IDataRow row3 = new DataRow();
|
---|
437 |
|
---|
438 | IDataRow row4 = new DataRow();
|
---|
439 | IDataRow row5 = new DataRow();
|
---|
440 | IDataRow row6 = new DataRow();
|
---|
441 |
|
---|
442 | row1.Color = Color.Red;
|
---|
443 | row2.Color = Color.Green;
|
---|
444 | row3.Color = Color.Blue;
|
---|
445 |
|
---|
446 | row4.Color = Color.DeepPink;
|
---|
447 | row5.Color = Color.Firebrick;
|
---|
448 | row6.Color = Color.DarkSlateGray;
|
---|
449 |
|
---|
450 | row1.Thickness = 3;
|
---|
451 | row2.Thickness = 4;
|
---|
452 | row3.Thickness = 5;
|
---|
453 |
|
---|
454 | row4.Thickness = 3;
|
---|
455 | row5.Thickness = 4;
|
---|
456 | row6.Thickness = 5;
|
---|
457 |
|
---|
458 | row1.Label = "SingleValue";
|
---|
459 | row2.Label = "Gertschi";
|
---|
460 | row3.Label = "Maxi";
|
---|
461 |
|
---|
462 | row4.Label = "Simon";
|
---|
463 | row5.Label = "klausmuellerwesternhagenunddierasperies";
|
---|
464 | row6.Label = "anyways";
|
---|
465 |
|
---|
466 | row1.Style = DrawingStyle.Solid;
|
---|
467 | row2.Style = DrawingStyle.Solid;
|
---|
468 | row3.Style = DrawingStyle.Dashed;
|
---|
469 |
|
---|
470 | row4.Style = DrawingStyle.Solid;
|
---|
471 | row5.Style = DrawingStyle.Solid;
|
---|
472 | row6.Style = DrawingStyle.Dashed;
|
---|
473 |
|
---|
474 | row1.LineType = DataRowType.SingleValue;
|
---|
475 | row2.LineType = DataRowType.SingleValue;
|
---|
476 | row1.AddValue(12);
|
---|
477 |
|
---|
478 | row2.AddValue(5);
|
---|
479 |
|
---|
480 |
|
---|
481 | row3.AddValue(2);
|
---|
482 | row3.AddValue(5);
|
---|
483 | row3.AddValue(9);
|
---|
484 | row3.AddValue(1);
|
---|
485 | row3.AddValue(3);
|
---|
486 |
|
---|
487 |
|
---|
488 | row4.AddValue(10);
|
---|
489 | row5.AddValue(11);
|
---|
490 | row6.AddValue(11);
|
---|
491 |
|
---|
492 | model.AddDataRow(row1);
|
---|
493 | model.AddDataRow(row2);
|
---|
494 | model.AddDataRow(row3);
|
---|
495 | model.AddDataRow(row4);
|
---|
496 | model.AddDataRow(row5);
|
---|
497 | model.AddDataRow(row6);
|
---|
498 |
|
---|
499 | f.ShowDialog();
|
---|
500 | }
|
---|
501 |
|
---|
502 |
|
---|
503 |
|
---|
504 | [Test]
|
---|
505 | public void TestMainForm() {
|
---|
506 | MainForm f = new MainForm();
|
---|
507 | f.ShowDialog();
|
---|
508 | }
|
---|
509 | }
|
---|
510 | }
|
---|