Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/AvgLineAggregator.cs @ 1346

Last change on this file since 1346 was 1343, checked in by mstoeger, 15 years ago

Display of Y-Axes can be individually switched on and off in the options dialog. (#433)

File size: 5.5 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
127    private bool showYAxis = false;
128
129    public bool ShowYAxis {
130      get { return showYAxis; }
131      set {
132        showYAxis = value;
133        OnDataRowChanged(this);
134      }
135    }
136
137    public LabelProvider.ILabelProvider YAxisLabelProvider {
138      get {
139        throw new NotImplementedException();
140      }
141      set {
142        throw new NotImplementedException();
143      }
144    }
145
146    public void AddValue(double value) {
147      dataRow.Add(value);
148      OnValueChanged(value, dataRow.Count - 1, Action.Added);
149    }
150
151    public void AddValue(double value, int index) {
152      throw new System.NotImplementedException();
153    }
154
155    public void AddValues(double[] values) {
156      throw new NotSupportedException();
157    }
158
159    public void AddValues(double[] values, int index) {
160      throw new NotSupportedException();
161    }
162
163    public void ModifyValue(double value, int index) {
164      throw new NotSupportedException();
165    }
166
167    public void ModifyValues(double[] values, int index) {
168      throw new NotSupportedException();
169    }
170
171    public void RemoveValue(int index) {
172      throw new NotSupportedException();
173    }
174
175    public void RemoveValues(int index, int count) {
176      throw new NotSupportedException();
177    }
178
179    public int Count {
180      get { return dataRowWatches.Count; }
181    }
182
183    public double this[int index] {
184      get { return dataRow[index]; }
185      set {
186        dataRow[index] = value;
187        OnValueChanged(value, index, Action.Modified);
188      }
189    }
190
191    public double MinValue {
192      get { throw new System.NotImplementedException(); }
193    }
194
195    public double MaxValue {
196      get { throw new System.NotImplementedException(); }
197    }
198
199    public event ValuesChangedHandler ValuesChanged;
200
201    protected void OnValuesChanged(double[] values, int index, Action action) {
202      if (ValuesChanged != null) {
203        ValuesChanged(this, values, index, action);
204      }
205    }
206
207    public event ValueChangedHandler ValueChanged;
208
209    protected void OnValueChanged(double value, int index, Action action) {
210      if (ValueChanged != null) {
211        ValueChanged(this, value, index, action);
212      }
213    }
214
215    public event DataRowChangedHandler DataRowChanged;
216
217    protected void OnDataRowChanged(IDataRow row) {
218      if (DataRowChanged != null) {
219        DataRowChanged(this);
220      }
221    }
222
223    #endregion
224  }
225}
Note: See TracBrowser for help on using the repository browser.