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