Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/DataRow.cs @ 1350

Last change on this file since 1350 was 1350, checked in by mstoeger, 15 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: 4.7 KB
RevLine 
[761]1using System;
2using System.Drawing;
[860]3using System.Collections.Generic;
[1194]4using HeuristicLab.Visualization.LabelProvider;
[761]5
6namespace HeuristicLab.Visualization {
[867]7  public enum Action {
8    Added,
9    Modified,
10    Deleted
11  }
12
[761]13  public delegate void DataRowChangedHandler(IDataRow row);
[867]14  public delegate void ValuesChangedHandler(IDataRow row, double[] values, int index, Action action);
15  public delegate void ValueChangedHandler(IDataRow row, double value, int index, Action action);
[761]16
[1350]17  public class DataRow : DataRowBase {
[1233]18    private readonly List<double> dataRow = new List<double>();
[761]19
[1285]20    // TODO implement calculation of min and max values
21    private double minValue = double.MaxValue;
22    private double maxValue = double.MinValue;
23
[868]24    public DataRow() {
25    }
[1190]26   
[867]27    public DataRow(string label) {
28      this.Label = label;
29    }
30
31    public DataRow(string label, Color color, int thickness, DrawingStyle style, List<double> dataRow) {
[1190]32     this.Label = label;
[867]33      this.Color = color;
34      this.Thickness = thickness;
35      this.Style = style;
36      this.dataRow = dataRow;
37    }
38
[1350]39    public override void AddValue(double value) {
[1285]40      UpdateMinMaxValue(value);
41
[860]42      dataRow.Add(value);
[867]43      OnValueChanged(value, dataRow.Count - 1, Action.Added);
[761]44    }
45
[1350]46    public override void AddValue(double value, int index) {
[867]47      //check if index is valid
48      if (index >= 0 && index < dataRow.Count) {
49        dataRow.Insert(index, value);
50        OnValueChanged(value, index, Action.Added);
51      } else {
[1233]52        throw new IndexOutOfRangeException();
[867]53      }   
[761]54    }
55
[1350]56    public override void AddValues(double[] values) {
[860]57      int startInd = dataRow.Count;
58
59      foreach (double d in values) {
60        dataRow.Add(d);
61      }
[867]62      OnValuesChanged(values, startInd, Action.Added);
[761]63    }
64
[1350]65    public override void AddValues(double[] values, int index) {
[867]66      int j = index;
67
[860]68      //check if index to start changes is valid
[867]69      if (index >=0 && (index + values.Length) < dataRow.Count) {
[860]70        foreach (double d in values) {
[867]71          dataRow.Insert(j, d);
72          j++;
[860]73        }
[867]74        OnValuesChanged(values, index, Action.Added);
[860]75      } else {
[1233]76        throw new IndexOutOfRangeException();
[860]77      }
[761]78    }
79
[1350]80    public override void ModifyValue(double value, int index) {
[867]81      //check if index is valid
82      if (index >= 0 && index < dataRow.Count) {
83        dataRow[index] = value;
84        OnValueChanged(value, index, Action.Modified);
85      } else {
[1233]86        throw new IndexOutOfRangeException();
[867]87      }
[761]88    }
89
[1350]90    public override void ModifyValues(double[] values, int index) {
[867]91      int startInd = index;
92      int modInd = index;
93
94      //check if index to start modification is valid
95      if (startInd >=0 && startInd + values.Length < dataRow.Count) {
96        foreach (double d in values) {
97          dataRow[modInd] = d;
98          modInd++;
99        }
100        OnValuesChanged(values, startInd, Action.Modified);
101      } else {
[1233]102        throw new IndexOutOfRangeException();
[867]103      }
[761]104    }
105
[1350]106    public override void RemoveValue(int index) {
[867]107      double remVal = dataRow[index];
108      //check if index is valid
109      if (index >= 0 && index < dataRow.Count) {
110        dataRow.RemoveAt(index);
111        OnValueChanged(remVal, index, Action.Deleted);
112      } else {
[1233]113        throw new IndexOutOfRangeException();
[867]114      }
[761]115    }
116
[1350]117    public override void RemoveValues(int index, int count) {
[867]118      double[] remValues = new double[count]; //removed values
119      int j = 0;
120
121      //check if count is valid
122      if (count > 0) {
123        //check if index is valid
124        if ((index >= 0) && (index + count <= dataRow.Count)) {
125          for (int i = index; i < (index + count); i++) {
126            remValues.SetValue(i, j);
127            dataRow.RemoveAt(i);
128            j++;
129          }
130          OnValuesChanged(remValues, index, Action.Deleted);
131        } else {
[1233]132          throw new IndexOutOfRangeException();
[867]133        }
134      } else {
[1233]135        throw new Exception("parameter count must be > 0!");
[867]136      }
[761]137    }
138
[1350]139    public override int Count {
[860]140      get { return dataRow.Count; }
[761]141    }
142
[1350]143    public override double this[int index] {
[860]144      get { return dataRow[index]; }
[761]145      set {
[860]146        dataRow[index] = value;
[867]147        OnValueChanged(value, index, Action.Modified);
[761]148      }
149    }
[1285]150
[1350]151    public override double MinValue {
[1285]152      get { return minValue; }
153    }
154
[1350]155    public override double MaxValue {
[1285]156      get { return maxValue; }
157    }
158
159    private void UpdateMinMaxValue(double value) {
160      maxValue = Math.Max(value, maxValue);
161      minValue = Math.Min(value, minValue);
162    }
[761]163  }
164}
Note: See TracBrowser for help on using the repository browser.