1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 |
|
---|
5 | namespace 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 | public LabelProvider.ILabelProvider YAxisLabelProvider {
|
---|
113 | get {
|
---|
114 | throw new NotImplementedException();
|
---|
115 | }
|
---|
116 | set {
|
---|
117 | throw new NotImplementedException();
|
---|
118 | }
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void AddValue(double value) {
|
---|
122 | throw new NotSupportedException();
|
---|
123 | }
|
---|
124 |
|
---|
125 | public void AddValue(double value, int index) {
|
---|
126 | throw new NotSupportedException();
|
---|
127 | }
|
---|
128 |
|
---|
129 | public void AddValues(double[] values) {
|
---|
130 | throw new NotSupportedException();
|
---|
131 | }
|
---|
132 |
|
---|
133 | public void AddValues(double[] values, int index) {
|
---|
134 | throw new NotSupportedException();
|
---|
135 | }
|
---|
136 |
|
---|
137 | public void ModifyValue(double value, int index) {
|
---|
138 | throw new NotSupportedException();
|
---|
139 | }
|
---|
140 |
|
---|
141 | public void ModifyValues(double[] values, int index) {
|
---|
142 | throw new NotSupportedException();
|
---|
143 | }
|
---|
144 |
|
---|
145 | public void RemoveValue(int index) {
|
---|
146 | throw new NotSupportedException();
|
---|
147 | }
|
---|
148 |
|
---|
149 | public void RemoveValues(int index, int count) {
|
---|
150 | throw new NotSupportedException();
|
---|
151 | }
|
---|
152 |
|
---|
153 | public int Count {
|
---|
154 | get { return 1; }
|
---|
155 | }
|
---|
156 |
|
---|
157 | public double this[int index] {
|
---|
158 | get {
|
---|
159 | return curAvgValue;
|
---|
160 | }
|
---|
161 | set {
|
---|
162 | throw new NotSupportedException();
|
---|
163 | }
|
---|
164 | }
|
---|
165 |
|
---|
166 | public double MinValue {
|
---|
167 | get { throw new System.NotImplementedException(); }
|
---|
168 | }
|
---|
169 |
|
---|
170 | public double MaxValue {
|
---|
171 | get { throw new System.NotImplementedException(); }
|
---|
172 | }
|
---|
173 |
|
---|
174 | public event ValuesChangedHandler ValuesChanged;
|
---|
175 |
|
---|
176 | protected void OnValuesChanged(double[] values, int index, Action action) {
|
---|
177 | if (ValuesChanged != null) {
|
---|
178 | ValuesChanged(this, values, index, action);
|
---|
179 | }
|
---|
180 | }
|
---|
181 |
|
---|
182 | public event ValueChangedHandler ValueChanged;
|
---|
183 |
|
---|
184 | protected void OnValueChanged(double value, int index, Action action) {
|
---|
185 | if (ValueChanged != null) {
|
---|
186 | ValueChanged(this, value, index, action);
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | public event DataRowChangedHandler DataRowChanged;
|
---|
191 |
|
---|
192 | protected void OnDataRowChanged(IDataRow row) {
|
---|
193 | if (DataRowChanged != null) {
|
---|
194 | DataRowChanged(this);
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | #endregion
|
---|
199 | }
|
---|
200 | }
|
---|