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