Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3039 was 2040, checked in by dwagner, 15 years ago

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

File size: 3.3 KB
RevLine 
[1325]1using System;
2using System.Collections.Generic;
3
4namespace HeuristicLab.Visualization {
[2040]5  public class MaxAggregator : DataRowBase, IAggregator {
[1325]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
[2040]26    public MaxAggregator() {
27      this.RowSettings.LineType = DataRowType.SingleValue;
28    }
29
30
[1325]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;
[1350]55        foreach (IDataRow rows in dataRowWatches) {
[1325]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
[1350]69    public override void AddValue(double value) {
[1325]70      OnValueChanged(2, 0, Action.Added);
71    }
72
[1350]73    public override void AddValue(double value, int index) {
[1325]74      throw new NotSupportedException();
75    }
76
[1350]77    public override void AddValues(double[] values) {
[1325]78      throw new NotSupportedException();
79    }
80
[1350]81    public override void AddValues(double[] values, int index) {
[1325]82      throw new NotSupportedException();
83    }
84
[1350]85    public override void ModifyValue(double value, int index) {
[1325]86      throw new NotSupportedException();
87    }
88
[1350]89    public override void ModifyValues(double[] values, int index) {
[1325]90      throw new NotSupportedException();
91    }
92
[1350]93    public override void RemoveValue(int index) {
[1325]94      throw new NotSupportedException();
95    }
96
[1350]97    public override void RemoveValues(int index, int count) {
[1325]98      throw new NotSupportedException();
99    }
100
[1350]101    public override int Count {
[1325]102      get { return 1; }
103    }
104
[1350]105    public override double this[int index] {
[1325]106      get {
107        return curMaxValue;
108      }
109      set {
110        throw new NotSupportedException();
111      }
112    }
113
[1350]114    public override double MinValue {
115      get { return curMaxValue; }
[1327]116    }
117
[1350]118    public override double MaxValue {
119      get { return curMaxValue; }
[1327]120    }
121
[1325]122    #endregion
123  }
124}
Note: See TracBrowser for help on using the repository browser.