Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/MinAggregator.cs @ 1343

Last change on this file since 1343 was 1343, checked in by mstoeger, 15 years ago

Display of Y-Axes can be individually switched on and off in the options dialog. (#433)

File size: 5.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using HeuristicLab.Visualization.LabelProvider;
5
6namespace 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
115    private bool showYAxis = false;
116
117    public bool ShowYAxis {
118      get { return showYAxis; }
119      set {
120        showYAxis = value;
121        OnDataRowChanged(this);
122      }
123    }
124
125    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
126    public ILabelProvider YAxisLabelProvider {
127      get { return labelProvider; }
128      set {
129        this.labelProvider = value;
130        OnDataRowChanged(this);
131      }
132    }
133
134    public void AddValue(double value) {
135      OnValueChanged(2, 0, Action.Added);
136    }
137
138    public void AddValue(double value, int index) {
139      throw new NotSupportedException();
140    }
141
142    public void AddValues(double[] values) {
143      throw new NotSupportedException();
144    }
145
146    public void AddValues(double[] values, int index) {
147      throw new NotSupportedException();
148    }
149
150    public void ModifyValue(double value, int index) {
151      throw new NotSupportedException();
152    }
153
154    public void ModifyValues(double[] values, int index) {
155      throw new NotSupportedException();
156    }
157
158    public void RemoveValue(int index) {
159      throw new NotSupportedException();
160    }
161
162    public void RemoveValues(int index, int count) {
163      throw new NotSupportedException();
164    }
165
166    public int Count {
167      get { return 1; }
168    }
169
170    public double this[int index] {
171      get {
172        return curMinValue;
173      }
174      set {
175        throw new NotSupportedException();
176      }
177    }
178
179    public double MinValue {
180      get { throw new System.NotImplementedException(); }
181    }
182
183    public double MaxValue {
184      get { throw new System.NotImplementedException(); }
185    }
186
187    public event ValuesChangedHandler ValuesChanged;
188
189    protected void OnValuesChanged(double[] values, int index, Action action) {
190      if (ValuesChanged != null) {
191        ValuesChanged(this, values, index, action);
192      }
193    }
194
195    public event ValueChangedHandler ValueChanged;
196
197    protected void OnValueChanged(double value, int index, Action action) {
198      if (ValueChanged != null) {
199        ValueChanged(this, value, index, action);
200      }
201    }
202
203    public event DataRowChangedHandler DataRowChanged;
204
205    protected void OnDataRowChanged(IDataRow row) {
206      if (DataRowChanged != null) {
207        DataRowChanged(this);
208      }
209    }
210
211    #endregion
212  }
213}
Note: See TracBrowser for help on using the repository browser.