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