Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/MinAggregator.cs @ 1591

Last change on this file since 1591 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.2 KB
Line 
1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Visualization {
5  public class MinAggregator : 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    readonly List<IDataRow> dataRowWatches = new List<IDataRow>();
27    double curMinValue;
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.MaxValue);
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 (curMinValue > newVal) {
46        curMinValue = newVal;
47        OnValueChanged(newVal, 0, Action.Modified);
48      } else {
49        curMinValue = double.MaxValue;
50        foreach (IDataRow rows in dataRowWatches) {
51          for (int i = 0; i < rows.Count; i++) {
52            if (rows[i] < curMinValue) {
53              curMinValue = rows[i];
54            }
55          }
56        }
57
58      }
59      // evtl nur feuern wenn sich geändert hat (jedes mal?)
60      OnValueChanged(curMinValue, 0, Action.Modified);
61    }
62
63    #region IDataRow Members
64
65    public override void AddValue(double value) {
66      OnValueChanged(2, 0, Action.Added);
67    }
68
69    public override void AddValue(double value, int index) {
70      throw new NotSupportedException();
71    }
72
73    public override void AddValues(double[] values) {
74      throw new NotSupportedException();
75    }
76
77    public override void AddValues(double[] values, int index) {
78      throw new NotSupportedException();
79    }
80
81    public override void ModifyValue(double value, int index) {
82      throw new NotSupportedException();
83    }
84
85    public override void ModifyValues(double[] values, int index) {
86      throw new NotSupportedException();
87    }
88
89    public override void RemoveValue(int index) {
90      throw new NotSupportedException();
91    }
92
93    public override void RemoveValues(int index, int count) {
94      throw new NotSupportedException();
95    }
96
97    public override int Count {
98      get { return 1; }
99    }
100
101    public override double this[int index] {
102      get {
103        return curMinValue;
104      }
105      set {
106        throw new NotSupportedException();
107      }
108    }
109
110    public override double MinValue {
111      get { return curMinValue; }
112    }
113
114    public override double MaxValue {
115      get { return curMinValue; }
116    }
117
118    #endregion
119  }
120}
Note: See TracBrowser for help on using the repository browser.