Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/DataRow.cs @ 1839

Last change on this file since 1839 was 1561, checked in by dwagner, 16 years ago

Added functionality: Checkbox to enable/disable Markers for every datapoint added to OptionsDialog. (#581)

File size: 5.0 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) {
[1561]32      this.Label = label;
[867]33      this.Color = color;
34      this.Thickness = thickness;
35      this.Style = style;
36      this.dataRow = dataRow;
[1561]37      this.ShowMarkers = true;
[867]38    }
39
[1561]40    public DataRow(string label, Color color, int thickness, DrawingStyle style, List<double> dataRow, bool showMarkers) {
41      this.Label = label;
42      this.Color = color;
43      this.Thickness = thickness;
44      this.Style = style;
45      this.ShowMarkers = showMarkers;
46      this.dataRow = dataRow;
47    }
48
[1350]49    public override void AddValue(double value) {
[1285]50      UpdateMinMaxValue(value);
51
[860]52      dataRow.Add(value);
[867]53      OnValueChanged(value, dataRow.Count - 1, Action.Added);
[761]54    }
55
[1350]56    public override void AddValue(double value, int index) {
[867]57      //check if index is valid
58      if (index >= 0 && index < dataRow.Count) {
59        dataRow.Insert(index, value);
60        OnValueChanged(value, index, Action.Added);
61      } else {
[1233]62        throw new IndexOutOfRangeException();
[867]63      }   
[761]64    }
65
[1350]66    public override void AddValues(double[] values) {
[860]67      int startInd = dataRow.Count;
68
69      foreach (double d in values) {
70        dataRow.Add(d);
71      }
[867]72      OnValuesChanged(values, startInd, Action.Added);
[761]73    }
74
[1350]75    public override void AddValues(double[] values, int index) {
[867]76      int j = index;
77
[860]78      //check if index to start changes is valid
[867]79      if (index >=0 && (index + values.Length) < dataRow.Count) {
[860]80        foreach (double d in values) {
[867]81          dataRow.Insert(j, d);
82          j++;
[860]83        }
[867]84        OnValuesChanged(values, index, Action.Added);
[860]85      } else {
[1233]86        throw new IndexOutOfRangeException();
[860]87      }
[761]88    }
89
[1350]90    public override void ModifyValue(double value, int index) {
[867]91      //check if index is valid
92      if (index >= 0 && index < dataRow.Count) {
93        dataRow[index] = value;
94        OnValueChanged(value, index, Action.Modified);
95      } else {
[1233]96        throw new IndexOutOfRangeException();
[867]97      }
[761]98    }
99
[1350]100    public override void ModifyValues(double[] values, int index) {
[867]101      int startInd = index;
102      int modInd = index;
103
104      //check if index to start modification is valid
105      if (startInd >=0 && startInd + values.Length < dataRow.Count) {
106        foreach (double d in values) {
107          dataRow[modInd] = d;
108          modInd++;
109        }
110        OnValuesChanged(values, startInd, Action.Modified);
111      } else {
[1233]112        throw new IndexOutOfRangeException();
[867]113      }
[761]114    }
115
[1350]116    public override void RemoveValue(int index) {
[867]117      double remVal = dataRow[index];
118      //check if index is valid
119      if (index >= 0 && index < dataRow.Count) {
120        dataRow.RemoveAt(index);
121        OnValueChanged(remVal, index, Action.Deleted);
122      } else {
[1233]123        throw new IndexOutOfRangeException();
[867]124      }
[761]125    }
126
[1350]127    public override void RemoveValues(int index, int count) {
[867]128      double[] remValues = new double[count]; //removed values
129      int j = 0;
130
131      //check if count is valid
132      if (count > 0) {
133        //check if index is valid
134        if ((index >= 0) && (index + count <= dataRow.Count)) {
135          for (int i = index; i < (index + count); i++) {
136            remValues.SetValue(i, j);
137            dataRow.RemoveAt(i);
138            j++;
139          }
140          OnValuesChanged(remValues, index, Action.Deleted);
141        } else {
[1233]142          throw new IndexOutOfRangeException();
[867]143        }
144      } else {
[1233]145        throw new Exception("parameter count must be > 0!");
[867]146      }
[761]147    }
148
[1350]149    public override int Count {
[860]150      get { return dataRow.Count; }
[761]151    }
152
[1350]153    public override double this[int index] {
[860]154      get { return dataRow[index]; }
[761]155      set {
[860]156        dataRow[index] = value;
[867]157        OnValueChanged(value, index, Action.Modified);
[761]158      }
159    }
[1285]160
[1350]161    public override double MinValue {
[1285]162      get { return minValue; }
163    }
164
[1350]165    public override double MaxValue {
[1285]166      get { return maxValue; }
167    }
168
169    private void UpdateMinMaxValue(double value) {
170      maxValue = Math.Max(value, maxValue);
171      minValue = Math.Min(value, minValue);
172    }
[761]173  }
174}
Note: See TracBrowser for help on using the repository browser.