Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1350 was 1350, checked in by mstoeger, 15 years ago

Implemented multiple Y-Axes. A LineChart has several Y-Axes and each Y-Axis has several data rows. The same clipping area is set for all data rows belonging to a Y-Axis. (#433)

File size: 11.2 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      row1.Color = Color.Red;
82      row1.Thickness = 3;
83      row1.Style = DrawingStyle.Solid;
84      row1.Label = "Die Rote";
85
86      row2.Color = Color.Green;
87      row2.Thickness = 3;
88      row2.Style = DrawingStyle.Solid;
89      row2.Label = "Die Grüne";
90
91      row3.Color = Color.Blue;
92      row3.Thickness = 3;
93      row3.Style = DrawingStyle.Solid;
94      row3.Label = "Die Blaue";
95      row3.YAxis = new YAxisDescriptor();
96
97      model.AddDataRow(row1);
98      model.AddDataRow(row2);
99      model.AddDataRow(row3);
100
101      Random rand = new Random(42);
102
103      for (int i = 0; i < 10; i++) {
104        row1.AddValue(rand.NextDouble()*10);
105        row2.AddValue(rand.NextDouble()*10);
106        row3.AddValue(rand.NextDouble()*1);
107      }
108
109      f.AddValue += delegate {
110        row1.AddValue(rand.NextDouble()*10);
111        row2.AddValue(rand.NextDouble()*10);
112        row3.AddValue(rand.NextDouble()*1);
113      };
114
115      f.ShowDialog();
116    }
117
118    [Test]
119    public void TestAggregator() {
120      LineChartTestForm f = new LineChartTestForm(model);
121
122      IDataRow row1 = new DataRow();
123      row1.Label = "row";
124      row1.Color = Color.Red;
125      row1.Thickness = 3;
126      row1.Style = DrawingStyle.Solid;
127
128      model.AddDataRow(row1);
129
130
131      MinAggregator aggregator = new MinAggregator();
132      aggregator.Label = "MinAggregator";
133      aggregator.Color = Color.Pink;
134      aggregator.Thickness = 5;
135      aggregator.Style = DrawingStyle.Solid;
136      aggregator.AddValue(2);
137      aggregator.LineType = DataRowType.SingleValue;
138
139      IDataRow lineTest = new DataRow("testline");
140      lineTest.Color = Color.DarkSalmon;
141      lineTest.Thickness = 2;
142      lineTest.Style = DrawingStyle.Dashed;
143      lineTest.LineType = DataRowType.SingleValue;
144      model.AddDataRow(lineTest);
145      lineTest.AddValue(9);
146      lineTest.AddValue(2);
147      lineTest.AddValue(3);
148      lineTest.AddValue(4);
149
150      aggregator.AddWatch(row1);
151
152      model.AddDataRow(aggregator);
153
154
155      row1.AddValue(10);
156      row1.AddValue(5);
157      row1.AddValue(7);
158      row1.AddValue(3);
159      row1.AddValue(10);
160      row1.AddValue(2);
161
162      f.ShowDialog();
163    }
164
165
166    public class Worker {
167      // This method will be called when the thread is started.
168      private ChartDataRowsModel model;
169      public Worker(ChartDataRowsModel model) {
170        this.model = model;
171      }
172     
173      public void DoWork() {
174
175        IDataRow row1 = new DataRow();
176        row1.Color = Color.Red;
177        row1.Thickness = 2;
178        row1.Label = "Simon";
179        row1.Style = DrawingStyle.Solid;
180        model.AddDataRow(row1);
181
182        IDataRow row2 = new DataRow();
183        row2.Color = Color.Red;
184        row2.Thickness = 3;
185        row2.Label = "Simon";
186        row2.Style = DrawingStyle.Solid;
187        model.AddDataRow(row2);
188
189
190        MinAggregator aggregator = new MinAggregator();
191        aggregator.Label = "MinAggregator";
192        aggregator.Color = Color.Pink;
193        aggregator.Thickness = 3;
194        aggregator.Style = DrawingStyle.Solid;
195        aggregator.LineType = DataRowType.SingleValue;
196        aggregator.AddWatch(row1);
197        model.AddDataRow(aggregator);
198
199        MaxAggregator maxAggregator = new MaxAggregator();
200        maxAggregator.Label = "MaxAggregator";
201        maxAggregator.Color = Color.DeepSkyBlue;
202        maxAggregator.Thickness = 3;
203        maxAggregator.Style = DrawingStyle.Solid;
204        maxAggregator.LineType = DataRowType.SingleValue;
205        maxAggregator.AddWatch(row1);
206        model.AddDataRow(maxAggregator);
207       
208       
209        AvgAggregator avgAggregator = new AvgAggregator();
210        avgAggregator.Label = "AvgAggregator";
211        avgAggregator.Color = Color.Violet;
212        avgAggregator.Thickness = 3;
213        avgAggregator.Style = DrawingStyle.Solid;
214        avgAggregator.LineType = DataRowType.SingleValue;
215        avgAggregator.AddWatch(row1);
216        model.AddDataRow(avgAggregator);
217
218        AvgAggregator multiAvgAggregator = new AvgAggregator();
219        multiAvgAggregator.Label = "MultiAvgAggregator";
220        multiAvgAggregator.Color = Color.DarkOliveGreen;
221        multiAvgAggregator.Thickness = 3;
222        multiAvgAggregator.Style = DrawingStyle.Solid;
223        multiAvgAggregator.LineType = DataRowType.SingleValue;
224        multiAvgAggregator.AddWatch(row1);
225        multiAvgAggregator.AddWatch(row2);
226        model.AddDataRow(multiAvgAggregator);
227
228        MaxAggregator multiMaxAggregator = new MaxAggregator();
229        multiMaxAggregator.Label = "MultiMaxAggregator";
230        multiMaxAggregator.Color = Color.DarkKhaki;
231        multiMaxAggregator.Thickness = 3;
232        multiMaxAggregator.Style = DrawingStyle.Solid;
233        multiMaxAggregator.LineType = DataRowType.SingleValue;
234        multiMaxAggregator.AddWatch(row1);
235        multiMaxAggregator.AddWatch(row2);
236        model.AddDataRow(multiMaxAggregator);
237
238        MinAggregator multiMinAggregator = new MinAggregator();
239        multiMinAggregator.Label = "MultiMinAggregator";
240        multiMinAggregator.Color = Color.DarkRed;
241        multiMinAggregator.Thickness = 3;
242        multiMinAggregator.Style = DrawingStyle.Solid;
243        multiMinAggregator.LineType = DataRowType.SingleValue;
244        multiMinAggregator.AddWatch(row1);
245        multiMinAggregator.AddWatch(row2);
246        model.AddDataRow(multiMinAggregator);
247
248        AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator();
249        multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
250        multiLineAvgAggregator.Color = Color.Red;
251        multiLineAvgAggregator.Thickness = 4;
252        multiLineAvgAggregator.Style = DrawingStyle.Solid;
253        multiLineAvgAggregator.LineType = DataRowType.Normal;
254        multiLineAvgAggregator.AddWatch(row1);
255        multiLineAvgAggregator.AddWatch(row2);
256        multiLineAvgAggregator.AddValue(0);
257        model.AddDataRow(multiLineAvgAggregator);
258
259        double i = 0;
260        double newY;
261
262        Random rand = new Random();
263        while (!_shouldStop && i <= 24) {
264          i += 0.2;
265          newY = Math.Sin(i);
266          System.Console.WriteLine("working");
267          //row1.AddValue(rand.NextDouble() * 10);
268          row1.AddValue(newY * 10);
269          row2.AddValue(i*2-15);
270          System.Threading.Thread.Sleep(100);
271        }
272        Console.WriteLine("worker thread: terminating gracefully.");
273      }
274      public void RequestStop() {
275        _shouldStop = true;
276      }
277      // Volatile is used as hint to the compiler that this data
278      // member will be accessed by multiple threads.
279      private volatile bool _shouldStop;
280    }
281
282
283    [Test]
284    public void TestAggregator2() {
285      LineChartTestForm f = new LineChartTestForm(model);
286   
287      // Create the thread object. This does not start the thread.
288      Worker workerObject = new Worker(model);
289      Thread workerThread = new Thread(workerObject.DoWork);
290
291      // Start the worker thread.
292      workerThread.Start();
293
294      f.ShowDialog();
295      workerObject.RequestStop();
296    }
297
298   
299
300    [Test]
301    public void TestAutoZoomInConstructor() {
302      IDataRow row1 = new DataRow();
303
304      row1.Color = Color.Red;
305      row1.Thickness = 3;
306      row1.Style = DrawingStyle.Solid;
307
308      model.AddDataRow(row1);
309
310      row1.AddValue(10);
311      row1.AddValue(5);
312      row1.AddValue(7);
313      row1.AddValue(3);
314      row1.AddValue(10);
315      row1.AddValue(2);
316
317      LineChartTestForm f = new LineChartTestForm(model);
318      f.ShowDialog();
319    }
320
321
322    [Test]
323    public void TestSingleValueDataRows() {
324      LineChartTestForm f = new LineChartTestForm(model);
325
326      IDataRow row1 = new DataRow();
327      IDataRow row2 = new DataRow();
328      IDataRow row3 = new DataRow();
329
330      IDataRow row4 = new DataRow();
331      IDataRow row5 = new DataRow();
332      IDataRow row6 = new DataRow();
333
334      row1.Color = Color.Red;
335      row2.Color = Color.Green;
336      row3.Color = Color.Blue;
337
338      row4.Color = Color.DeepPink;
339      row5.Color = Color.Firebrick;
340      row6.Color = Color.DarkSlateGray;
341
342      row1.Thickness = 3;
343      row2.Thickness = 4;
344      row3.Thickness = 5;
345
346      row4.Thickness = 3;
347      row5.Thickness = 4;
348      row6.Thickness = 5;
349
350      row1.Label = "SingleValue";
351      row2.Label = "Gertschi";
352      row3.Label = "Maxi";
353
354      row4.Label = "Simon";
355      row5.Label = "klausmuellerwesternhagenunddierasperies";
356      row6.Label = "anyways";
357
358      row1.Style = DrawingStyle.Solid;
359      row2.Style = DrawingStyle.Solid;
360      row3.Style = DrawingStyle.Dashed;
361
362      row4.Style = DrawingStyle.Solid;
363      row5.Style = DrawingStyle.Solid;
364      row6.Style = DrawingStyle.Dashed;
365
366      row1.LineType = DataRowType.SingleValue;
367      row2.LineType = DataRowType.SingleValue;
368      row1.AddValue(12);
369
370      row2.AddValue(5);
371     
372
373      row3.AddValue(2);
374      row3.AddValue(5);
375      row3.AddValue(9);
376      row3.AddValue(1);
377      row3.AddValue(3);
378
379
380      row4.AddValue(10);
381      row5.AddValue(11);
382      row6.AddValue(11);
383
384      model.AddDataRow(row1);
385      model.AddDataRow(row2);
386      model.AddDataRow(row3);
387      model.AddDataRow(row4);
388      model.AddDataRow(row5);
389      model.AddDataRow(row6);
390
391      f.ShowDialog();
392    }
393
394
395
396    [Test]
397    public void TestMainForm() {
398      MainForm f = new MainForm();
399      f.ShowDialog();
400    }
401  }
402}
Note: See TracBrowser for help on using the repository browser.