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