Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Visualization/3.2/MaxAggregator.cs @ 4021

Last change on this file since 4021 was 2040, checked in by dwagner, 16 years ago

dw: Added new dialog for adding lines using the options dialog. (#478)

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