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