Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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