Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1619 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
Line 
1using System;
2using System.Drawing;
3using System.Collections.Generic;
4using HeuristicLab.Visualization.LabelProvider;
5
6namespace HeuristicLab.Visualization {
7  public enum Action {
8    Added,
9    Modified,
10    Deleted
11  }
12
13  public delegate void DataRowChangedHandler(IDataRow row);
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);
16
17  public class DataRow : DataRowBase {
18    private readonly List<double> dataRow = new List<double>();
19
20    // TODO implement calculation of min and max values
21    private double minValue = double.MaxValue;
22    private double maxValue = double.MinValue;
23
24    public DataRow() {
25    }
26   
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) {
32      this.Label = label;
33      this.Color = color;
34      this.Thickness = thickness;
35      this.Style = style;
36      this.dataRow = dataRow;
37      this.ShowMarkers = true;
38    }
39
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
49    public override void AddValue(double value) {
50      UpdateMinMaxValue(value);
51
52      dataRow.Add(value);
53      OnValueChanged(value, dataRow.Count - 1, Action.Added);
54    }
55
56    public override void AddValue(double value, int index) {
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 {
62        throw new IndexOutOfRangeException();
63      }   
64    }
65
66    public override void AddValues(double[] values) {
67      int startInd = dataRow.Count;
68
69      foreach (double d in values) {
70        dataRow.Add(d);
71      }
72      OnValuesChanged(values, startInd, Action.Added);
73    }
74
75    public override void AddValues(double[] values, int index) {
76      int j = index;
77
78      //check if index to start changes is valid
79      if (index >=0 && (index + values.Length) < dataRow.Count) {
80        foreach (double d in values) {
81          dataRow.Insert(j, d);
82          j++;
83        }
84        OnValuesChanged(values, index, Action.Added);
85      } else {
86        throw new IndexOutOfRangeException();
87      }
88    }
89
90    public override void ModifyValue(double value, int index) {
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 {
96        throw new IndexOutOfRangeException();
97      }
98    }
99
100    public override void ModifyValues(double[] values, int index) {
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 {
112        throw new IndexOutOfRangeException();
113      }
114    }
115
116    public override void RemoveValue(int index) {
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 {
123        throw new IndexOutOfRangeException();
124      }
125    }
126
127    public override void RemoveValues(int index, int count) {
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 {
142          throw new IndexOutOfRangeException();
143        }
144      } else {
145        throw new Exception("parameter count must be > 0!");
146      }
147    }
148
149    public override int Count {
150      get { return dataRow.Count; }
151    }
152
153    public override double this[int index] {
154      get { return dataRow[index]; }
155      set {
156        dataRow[index] = value;
157        OnValueChanged(value, index, Action.Modified);
158      }
159    }
160
161    public override double MinValue {
162      get { return minValue; }
163    }
164
165    public override double MaxValue {
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    }
173  }
174}
Note: See TracBrowser for help on using the repository browser.