Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs @ 1510

Last change on this file since 1510 was 1462, checked in by mstoeger, 16 years ago

Display of X- and Y-Axis-Labels (#556)

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