Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1988 was 1988, checked in by cbahner, 15 years ago

#639 added color and y axis assignment to persistance

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