Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/MaxAggregator.cs @ 1842

Last change on this file since 1842 was 1607, checked in by cbahner, 16 years ago

#519 test cases + code review

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