Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/MaxAggregator.cs @ 1325

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

#519 first aggregators: min, max, avg single and avg multiple line

File size: 4.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4
5namespace HeuristicLab.Visualization {
6  public class MaxAggregator : IAggregator {
7   
8   
9    #region IAggregator Members
10
11    public void AddWatch(IDataRow dataRow) {
12      dataRowWatches.Add(dataRow);
13      dataRow.ValueChanged += dataRow_ValueChanged;
14      dataRow.ValuesChanged += dataRow_ValuesChanged;
15      dataRow.DataRowChanged += dataRow_DataRowChanged;
16    }
17
18    public void RemoveWatch(IDataRow dataRow) {
19
20      dataRowWatches.Remove(dataRow);
21      dataRow.DataRowChanged -= dataRow_DataRowChanged;
22      dataRow.ValuesChanged -= dataRow_ValuesChanged;
23      dataRow.ValueChanged -= dataRow_ValueChanged;
24    }
25
26
27    #endregion
28
29    List<IDataRow> dataRowWatches = new List<IDataRow>();
30    double curMaxValue;
31
32    void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
33      refreshValue(value);
34    }
35
36    void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
37      for (int i = 0; i < values.Length; i++) {
38        refreshValue(values[i]);
39      }
40    }
41
42    void dataRow_DataRowChanged(IDataRow row) {
43      refreshValue(double.MinValue);
44    }
45
46    private void refreshValue(double newVal) {
47      //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
48      if (curMaxValue < newVal) {
49        curMaxValue = newVal;
50        OnValueChanged(newVal, 0, Action.Modified);
51      } else {
52        curMaxValue = double.MinValue;
53        foreach (var rows in dataRowWatches) {
54          for (int i = 0; i < rows.Count; i++) {
55            if (rows[i] > curMaxValue) {
56              curMaxValue = rows[i];
57            }
58          }
59        }
60
61      }
62      // evtl nur feuern wenn sich geändert hat (jedes mal?)
63      OnValueChanged(curMaxValue, 0, Action.Modified);
64    }
65
66    #region IDataRow Members
67
68    private string label = "";
69    private Color color = Color.Black;
70    private int thickness = 2;
71    private DrawingStyle style = DrawingStyle.Solid;
72    private DataRowType lineType = DataRowType.Normal;
73
74
75    public string Label {
76      get { return label; }
77      set {
78        label = value;
79        OnDataRowChanged(this);
80      }
81    }
82
83    public Color Color {
84      get { return color; }
85      set {
86        color = value;
87        OnDataRowChanged(this);
88      }
89    }
90
91    public int Thickness {
92      get { return thickness; }
93      set {
94        thickness = value;
95        OnDataRowChanged(this);
96      }
97    }
98
99    public DrawingStyle Style {
100      get { return style; }
101      set {
102        style = value;
103        OnDataRowChanged(this);
104      }
105    }
106
107    public DataRowType LineType {
108      get { return lineType; }
109      set {
110        lineType = value;
111        OnDataRowChanged(this);
112      }
113    }
114
115    public LabelProvider.ILabelProvider YAxisLabelProvider {
116      get {
117        throw new NotImplementedException();
118      }
119      set {
120        throw new NotImplementedException();
121      }
122    }
123
124    public void AddValue(double value) {
125      OnValueChanged(2, 0, Action.Added);
126    }
127
128    public void AddValue(double value, int index) {
129      throw new NotSupportedException();
130    }
131
132    public void AddValues(double[] values) {
133      throw new NotSupportedException();
134    }
135
136    public void AddValues(double[] values, int index) {
137      throw new NotSupportedException();
138    }
139
140    public void ModifyValue(double value, int index) {
141      throw new NotSupportedException();
142    }
143
144    public void ModifyValues(double[] values, int index) {
145      throw new NotSupportedException();
146    }
147
148    public void RemoveValue(int index) {
149      throw new NotSupportedException();
150    }
151
152    public void RemoveValues(int index, int count) {
153      throw new NotSupportedException();
154    }
155
156    public int Count {
157      get { return 1; }
158    }
159
160    public double this[int index] {
161      get {
162        return curMaxValue;
163      }
164      set {
165        throw new NotSupportedException();
166      }
167    }
168
169    public event ValuesChangedHandler ValuesChanged;
170
171    protected void OnValuesChanged(double[] values, int index, Action action) {
172      if (ValuesChanged != null) {
173        ValuesChanged(this, values, index, action);
174      }
175    }
176
177    public event ValueChangedHandler ValueChanged;
178
179    protected void OnValueChanged(double value, int index, Action action) {
180      if (ValueChanged != null) {
181        ValueChanged(this, value, index, action);
182      }
183    }
184
185    public event DataRowChangedHandler DataRowChanged;
186
187    protected void OnDataRowChanged(IDataRow row) {
188      if (DataRowChanged != null) {
189        DataRowChanged(this);
190      }
191    }
192
193    #endregion
194  }
195}
Note: See TracBrowser for help on using the repository browser.