Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2080 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 MinAggregator : 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 MinAggregator() {
27      this.RowSettings.LineType=DataRowType.SingleValue;
28    }
29
[1325]30    readonly List<IDataRow> dataRowWatches = new List<IDataRow>();
31    double curMinValue;
32
33    void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
34      refreshValue(value);
35    }
36
37    void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
38      for (int i = 0; i < values.Length; i++) {
39        refreshValue(values[i]);
40      }
41    }
42
43    void dataRow_DataRowChanged(IDataRow row) {
44      refreshValue(double.MaxValue);
45    }
46
47    private void refreshValue(double newVal) {
48      //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
49      if (curMinValue > newVal) {
50        curMinValue = newVal;
51        OnValueChanged(newVal, 0, Action.Modified);
52      } else {
53        curMinValue = double.MaxValue;
[1350]54        foreach (IDataRow rows in dataRowWatches) {
[1325]55          for (int i = 0; i < rows.Count; i++) {
56            if (rows[i] < curMinValue) {
57              curMinValue = rows[i];
58            }
59          }
60        }
61
62      }
63      // evtl nur feuern wenn sich geändert hat (jedes mal?)
64      OnValueChanged(curMinValue, 0, Action.Modified);
65    }
66
67    #region IDataRow Members
68
[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 curMinValue;
108      }
109      set {
110        throw new NotSupportedException();
111      }
112    }
113
[1350]114    public override double MinValue {
115      get { return curMinValue; }
[1327]116    }
117
[1350]118    public override double MaxValue {
119      get { return curMinValue; }
[1327]120    }
121
[1325]122    #endregion
123  }
124}
Note: See TracBrowser for help on using the repository browser.