Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/AvgAggregator.cs @ 1473

Last change on this file since 1473 was 1350, checked in by mstoeger, 16 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: 3.1 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Visualization {
5  public class AvgAggregator : DataRowBase {
6    #region IAggregator Members
7
8    public void AddWatch(IDataRow dataRow) {
9      dataRowWatches.Add(dataRow);
10      dataRow.ValueChanged += dataRow_ValueChanged;
11      dataRow.ValuesChanged += dataRow_ValuesChanged;
12      dataRow.DataRowChanged += dataRow_DataRowChanged;
13    }
14
15    public void RemoveWatch(IDataRow dataRow) {
16      dataRowWatches.Remove(dataRow);
17      dataRow.DataRowChanged -= dataRow_DataRowChanged;
18      dataRow.ValuesChanged -= dataRow_ValuesChanged;
19      dataRow.ValueChanged -= dataRow_ValueChanged;
20    }
21
22    #endregion
23
24    private List<IDataRow> dataRowWatches = new List<IDataRow>();
25    private double curAvgValue;
26
27    private void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
28      refreshValue(value);
29    }
30
31    private void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
32      for (int i = 0; i < values.Length; i++) {
33        refreshValue(values[i]);
34      }
35    }
36
37    private void dataRow_DataRowChanged(IDataRow row) {
38      refreshValue(double.MinValue);
39    }
40
41    private void refreshValue(double newVal) {
42      //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
43
44      curAvgValue = double.MinValue;
45      double tmpSum = 0;
46      int count = 0;
47      foreach (IDataRow rows in dataRowWatches) {
48        for (int i = 0; i < rows.Count; i++) {
49          tmpSum += rows[i];
50          count++;
51        }
52      }
53      curAvgValue = tmpSum/count;
54      // evtl nur feuern wenn sich geändert hat (jedes mal?)
55      OnValueChanged(curAvgValue, 0, Action.Modified);
56    }
57
58    #region IDataRow Members
59
60    public override void AddValue(double value) {
61      throw new NotSupportedException();
62    }
63
64    public override void AddValue(double value, int index) {
65      throw new NotSupportedException();
66    }
67
68    public override void AddValues(double[] values) {
69      throw new NotSupportedException();
70    }
71
72    public override void AddValues(double[] values, int index) {
73      throw new NotSupportedException();
74    }
75
76    public override void ModifyValue(double value, int index) {
77      throw new NotSupportedException();
78    }
79
80    public override void ModifyValues(double[] values, int index) {
81      throw new NotSupportedException();
82    }
83
84    public override void RemoveValue(int index) {
85      throw new NotSupportedException();
86    }
87
88    public override void RemoveValues(int index, int count) {
89      throw new NotSupportedException();
90    }
91
92    public override int Count {
93      get { return 1; }
94    }
95
96    public override double this[int index] {
97      get { return curAvgValue; }
98      set { throw new NotSupportedException(); }
99    }
100
101    public override double MinValue {
102      get { return curAvgValue; }
103    }
104
105    public override double MaxValue {
106      get { return curAvgValue; }
107    }
108
109    #endregion
110  }
111}
Note: See TracBrowser for help on using the repository browser.