Free cookie consent management tool by TermsFeed Policy Generator

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