Free cookie consent management tool by TermsFeed Policy Generator

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