1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Visualization {
|
---|
6 | public class MaxAggregator : DataRowBase {
|
---|
7 | #region IAggregator Members
|
---|
8 |
|
---|
9 | public void AddWatch(IDataRow dataRow) {
|
---|
10 | dataRowWatches.Add(dataRow);
|
---|
11 | dataRow.ValueChanged += dataRow_ValueChanged;
|
---|
12 | dataRow.ValuesChanged += dataRow_ValuesChanged;
|
---|
13 | dataRow.DataRowChanged += dataRow_DataRowChanged;
|
---|
14 | }
|
---|
15 |
|
---|
16 | public void RemoveWatch(IDataRow dataRow) {
|
---|
17 |
|
---|
18 | dataRowWatches.Remove(dataRow);
|
---|
19 | dataRow.DataRowChanged -= dataRow_DataRowChanged;
|
---|
20 | dataRow.ValuesChanged -= dataRow_ValuesChanged;
|
---|
21 | dataRow.ValueChanged -= dataRow_ValueChanged;
|
---|
22 | }
|
---|
23 |
|
---|
24 |
|
---|
25 | #endregion
|
---|
26 |
|
---|
27 | List<IDataRow> dataRowWatches = new List<IDataRow>();
|
---|
28 | double curMaxValue;
|
---|
29 |
|
---|
30 | void dataRow_ValueChanged(IDataRow row, double value, int index, Action action) {
|
---|
31 | refreshValue(value);
|
---|
32 | }
|
---|
33 |
|
---|
34 | void dataRow_ValuesChanged(IDataRow row, double[] values, int index, Action action) {
|
---|
35 | for (int i = 0; i < values.Length; i++) {
|
---|
36 | refreshValue(values[i]);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | void dataRow_DataRowChanged(IDataRow row) {
|
---|
41 | refreshValue(double.MinValue);
|
---|
42 | }
|
---|
43 |
|
---|
44 | private void refreshValue(double newVal) {
|
---|
45 | //alle durchlaufen und neues min berechnen; verbesserung: merken in welcher row lowest wert steckt
|
---|
46 | if (curMaxValue < newVal) {
|
---|
47 | curMaxValue = newVal;
|
---|
48 | OnValueChanged(newVal, 0, Action.Modified);
|
---|
49 | } else {
|
---|
50 | curMaxValue = double.MinValue;
|
---|
51 | foreach (IDataRow rows in dataRowWatches) {
|
---|
52 | for (int i = 0; i < rows.Count; i++) {
|
---|
53 | if (rows[i] > curMaxValue) {
|
---|
54 | curMaxValue = rows[i];
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | }
|
---|
60 | // evtl nur feuern wenn sich geändert hat (jedes mal?)
|
---|
61 | OnValueChanged(curMaxValue, 0, Action.Modified);
|
---|
62 | }
|
---|
63 |
|
---|
64 | #region IDataRow Members
|
---|
65 | public override void AddValue(double value) {
|
---|
66 | OnValueChanged(2, 0, Action.Added);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override void AddValue(double value, int index) {
|
---|
70 | throw new NotSupportedException();
|
---|
71 | }
|
---|
72 |
|
---|
73 | public override void AddValues(double[] values) {
|
---|
74 | throw new NotSupportedException();
|
---|
75 | }
|
---|
76 |
|
---|
77 | public override void AddValues(double[] values, int index) {
|
---|
78 | throw new NotSupportedException();
|
---|
79 | }
|
---|
80 |
|
---|
81 | public override void ModifyValue(double value, int index) {
|
---|
82 | throw new NotSupportedException();
|
---|
83 | }
|
---|
84 |
|
---|
85 | public override void ModifyValues(double[] values, int index) {
|
---|
86 | throw new NotSupportedException();
|
---|
87 | }
|
---|
88 |
|
---|
89 | public override void RemoveValue(int index) {
|
---|
90 | throw new NotSupportedException();
|
---|
91 | }
|
---|
92 |
|
---|
93 | public override void RemoveValues(int index, int count) {
|
---|
94 | throw new NotSupportedException();
|
---|
95 | }
|
---|
96 |
|
---|
97 | public override int Count {
|
---|
98 | get { return 1; }
|
---|
99 | }
|
---|
100 |
|
---|
101 | public override double this[int index] {
|
---|
102 | get {
|
---|
103 | return curMaxValue;
|
---|
104 | }
|
---|
105 | set {
|
---|
106 | throw new NotSupportedException();
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | public override double MinValue {
|
---|
111 | get { return curMaxValue; }
|
---|
112 | }
|
---|
113 |
|
---|
114 | public override double MaxValue {
|
---|
115 | get { return curMaxValue; }
|
---|
116 | }
|
---|
117 |
|
---|
118 | #endregion
|
---|
119 | }
|
---|
120 | }
|
---|