Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/AvgAggregator.cs @ 1473

Last change on this file since 1473 was 1350, checked in by mstoeger, 16 years ago

Implemented multiple Y-Axes. A LineChart has several Y-Axes and each Y-Axis has several data rows. The same clipping area is set for all data rows belonging to a Y-Axis. (#433)

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