[761] | 1 | using System;
|
---|
| 2 | using System.Drawing;
|
---|
[860] | 3 | using System.Collections.Generic;
|
---|
[1194] | 4 | using HeuristicLab.Visualization.LabelProvider;
|
---|
[761] | 5 |
|
---|
| 6 | namespace 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 |
|
---|
| 17 | public class DataRow : IDataRow {
|
---|
| 18 | private string label = "";
|
---|
| 19 | private Color color = Color.Black;
|
---|
| 20 | private int thickness = 2;
|
---|
| 21 | private DrawingStyle style = DrawingStyle.Solid;
|
---|
[1193] | 22 | private DataRowType lineType = DataRowType.Normal;
|
---|
[1233] | 23 | private readonly List<double> dataRow = new List<double>();
|
---|
[761] | 24 |
|
---|
[1194] | 25 | private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
|
---|
[1190] | 26 |
|
---|
[1193] | 27 | public DataRowType LineType{
|
---|
| 28 | get { return lineType; }
|
---|
| 29 | set {
|
---|
| 30 | lineType = value;
|
---|
| 31 | OnDataRowChanged(this);
|
---|
| 32 | }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
[1190] | 35 | public ILabelProvider YAxisLabelProvider {
|
---|
| 36 | get { return labelProvider; }
|
---|
[1191] | 37 | set {
|
---|
| 38 | this.labelProvider = value;
|
---|
| 39 | OnDataRowChanged(this);
|
---|
| 40 | }
|
---|
[1190] | 41 | }
|
---|
| 42 |
|
---|
[868] | 43 | public DataRow() {
|
---|
| 44 | }
|
---|
[1190] | 45 |
|
---|
[867] | 46 | public DataRow(string label) {
|
---|
| 47 | this.Label = label;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public DataRow(string label, Color color, int thickness, DrawingStyle style, List<double> dataRow) {
|
---|
[1190] | 51 | this.Label = label;
|
---|
[867] | 52 | this.Color = color;
|
---|
| 53 | this.Thickness = thickness;
|
---|
| 54 | this.Style = style;
|
---|
| 55 | this.dataRow = dataRow;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[761] | 58 | public event DataRowChangedHandler DataRowChanged;
|
---|
| 59 |
|
---|
| 60 | protected void OnDataRowChanged(IDataRow row) {
|
---|
| 61 | if (DataRowChanged != null) {
|
---|
| 62 | DataRowChanged(this);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | public event ValuesChangedHandler ValuesChanged;
|
---|
| 67 |
|
---|
[867] | 68 | protected void OnValuesChanged(double[] values, int index, Action action) {
|
---|
[761] | 69 | if (ValuesChanged != null) {
|
---|
[867] | 70 | ValuesChanged(this, values, index, action);
|
---|
[761] | 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | public event ValueChangedHandler ValueChanged;
|
---|
| 75 |
|
---|
[867] | 76 | protected void OnValueChanged(double value, int index, Action action) {
|
---|
[761] | 77 | if (ValueChanged != null) {
|
---|
[867] | 78 | ValueChanged(this, value, index, action);
|
---|
[761] | 79 | }
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[1190] | 82 |
|
---|
[761] | 83 | public string Label {
|
---|
| 84 | get { return label; }
|
---|
| 85 | set {
|
---|
| 86 | label = value;
|
---|
| 87 | OnDataRowChanged(this);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
[1190] | 90 |
|
---|
[761] | 91 |
|
---|
| 92 | public Color Color {
|
---|
| 93 | get { return color; }
|
---|
| 94 | set {
|
---|
| 95 | color = value;
|
---|
| 96 | OnDataRowChanged(this);
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | public int Thickness {
|
---|
| 101 | get { return thickness; }
|
---|
| 102 | set {
|
---|
| 103 | thickness = value;
|
---|
| 104 | OnDataRowChanged(this);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | public DrawingStyle Style {
|
---|
| 109 | get { return style; }
|
---|
| 110 | set {
|
---|
| 111 | style = value;
|
---|
| 112 | OnDataRowChanged(this);
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | public void AddValue(double value) {
|
---|
[860] | 117 | dataRow.Add(value);
|
---|
[867] | 118 | OnValueChanged(value, dataRow.Count - 1, Action.Added);
|
---|
[761] | 119 | }
|
---|
| 120 |
|
---|
| 121 | public void AddValue(double value, int index) {
|
---|
[867] | 122 | //check if index is valid
|
---|
| 123 | if (index >= 0 && index < dataRow.Count) {
|
---|
| 124 | dataRow.Insert(index, value);
|
---|
| 125 | OnValueChanged(value, index, Action.Added);
|
---|
| 126 | } else {
|
---|
[1233] | 127 | throw new IndexOutOfRangeException();
|
---|
[867] | 128 | }
|
---|
[761] | 129 | }
|
---|
| 130 |
|
---|
| 131 | public void AddValues(double[] values) {
|
---|
[860] | 132 | int startInd = dataRow.Count;
|
---|
| 133 |
|
---|
| 134 | foreach (double d in values) {
|
---|
| 135 | dataRow.Add(d);
|
---|
| 136 | }
|
---|
[867] | 137 | OnValuesChanged(values, startInd, Action.Added);
|
---|
[761] | 138 | }
|
---|
| 139 |
|
---|
| 140 | public void AddValues(double[] values, int index) {
|
---|
[867] | 141 | int j = index;
|
---|
| 142 |
|
---|
[860] | 143 | //check if index to start changes is valid
|
---|
[867] | 144 | if (index >=0 && (index + values.Length) < dataRow.Count) {
|
---|
[860] | 145 | foreach (double d in values) {
|
---|
[867] | 146 | dataRow.Insert(j, d);
|
---|
| 147 | j++;
|
---|
[860] | 148 | }
|
---|
[867] | 149 | OnValuesChanged(values, index, Action.Added);
|
---|
[860] | 150 | } else {
|
---|
[1233] | 151 | throw new IndexOutOfRangeException();
|
---|
[860] | 152 | }
|
---|
[761] | 153 | }
|
---|
| 154 |
|
---|
| 155 | public void ModifyValue(double value, int index) {
|
---|
[867] | 156 | //check if index is valid
|
---|
| 157 | if (index >= 0 && index < dataRow.Count) {
|
---|
| 158 | dataRow[index] = value;
|
---|
| 159 | OnValueChanged(value, index, Action.Modified);
|
---|
| 160 | } else {
|
---|
[1233] | 161 | throw new IndexOutOfRangeException();
|
---|
[867] | 162 | }
|
---|
[761] | 163 | }
|
---|
| 164 |
|
---|
| 165 | public void ModifyValues(double[] values, int index) {
|
---|
[867] | 166 | int startInd = index;
|
---|
| 167 | int modInd = index;
|
---|
| 168 |
|
---|
| 169 | //check if index to start modification is valid
|
---|
| 170 | if (startInd >=0 && startInd + values.Length < dataRow.Count) {
|
---|
| 171 | foreach (double d in values) {
|
---|
| 172 | dataRow[modInd] = d;
|
---|
| 173 | modInd++;
|
---|
| 174 | }
|
---|
| 175 | OnValuesChanged(values, startInd, Action.Modified);
|
---|
| 176 | } else {
|
---|
[1233] | 177 | throw new IndexOutOfRangeException();
|
---|
[867] | 178 | }
|
---|
[761] | 179 | }
|
---|
| 180 |
|
---|
| 181 | public void RemoveValue(int index) {
|
---|
[867] | 182 | double remVal = dataRow[index];
|
---|
| 183 | //check if index is valid
|
---|
| 184 | if (index >= 0 && index < dataRow.Count) {
|
---|
| 185 | dataRow.RemoveAt(index);
|
---|
| 186 | OnValueChanged(remVal, index, Action.Deleted);
|
---|
| 187 | } else {
|
---|
[1233] | 188 | throw new IndexOutOfRangeException();
|
---|
[867] | 189 | }
|
---|
[761] | 190 | }
|
---|
| 191 |
|
---|
| 192 | public void RemoveValues(int index, int count) {
|
---|
[867] | 193 | double[] remValues = new double[count]; //removed values
|
---|
| 194 | int j = 0;
|
---|
| 195 |
|
---|
| 196 | //check if count is valid
|
---|
| 197 | if (count > 0) {
|
---|
| 198 | //check if index is valid
|
---|
| 199 | if ((index >= 0) && (index + count <= dataRow.Count)) {
|
---|
| 200 | for (int i = index; i < (index + count); i++) {
|
---|
| 201 | remValues.SetValue(i, j);
|
---|
| 202 | dataRow.RemoveAt(i);
|
---|
| 203 | j++;
|
---|
| 204 | }
|
---|
| 205 | OnValuesChanged(remValues, index, Action.Deleted);
|
---|
| 206 | } else {
|
---|
[1233] | 207 | throw new IndexOutOfRangeException();
|
---|
[867] | 208 | }
|
---|
| 209 | } else {
|
---|
[1233] | 210 | throw new Exception("parameter count must be > 0!");
|
---|
[867] | 211 | }
|
---|
[761] | 212 | }
|
---|
| 213 |
|
---|
| 214 | public int Count {
|
---|
[860] | 215 | get { return dataRow.Count; }
|
---|
[761] | 216 | }
|
---|
| 217 |
|
---|
| 218 | public double this[int index] {
|
---|
[860] | 219 | get { return dataRow[index]; }
|
---|
[761] | 220 | set {
|
---|
[860] | 221 | dataRow[index] = value;
|
---|
[867] | 222 | OnValueChanged(value, index, Action.Modified);
|
---|
[761] | 223 | }
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 | } |
---|