Changeset 6165 for branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Models
- Timestamp:
- 05/07/11 18:44:15 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Models/ChartModel.cs
r6118 r6165 8 8 using System.Collections; 9 9 10 namespace HLWebOKBQueryPlugin.Models 11 { 12 public class ChartModel 13 { 14 15 16 17 private Color DataPointColor = System.Drawing.Color.Black; 18 private String xAxisValue; 19 private String yAxisValue; 20 private String sizeAxisValue; 21 22 private Dictionary<string, Dictionary<object, double>> CategoricalMap 23 { 24 get; 25 set; 26 } 27 28 public Run[] Runs 29 { 30 set;get; 31 // { 32 //UpdateComboBoxValues(value); 33 34 //} 35 } 36 37 public Series Series { set; get; } 38 39 public void UpdateRunCollection(Run[] runs) 40 { 41 this.Runs = runs; 42 UpdateComboBoxValues(); 43 // 44 } 45 46 public List<string> valuesAxisY { get; set; } 47 public List<string> valuesAxisX { get; set; } 48 public List<string> bubbleSize { get; set; } 49 50 51 52 // COnstrucotr 53 public ChartModel() 54 { 55 56 CategoricalMap = new Dictionary<string, Dictionary<object, double>>(); 57 58 valuesAxisY = new List<string>(); 59 valuesAxisX = new List<string>(); 60 bubbleSize = new List<string>(); 61 Series = new Series(); 62 Series.ChartType = SeriesChartType.Bubble; 63 } 64 65 66 67 private double GetCategoricalValue(string columnName, string value) 68 { 69 if (!this.CategoricalMap.ContainsKey(columnName)) 70 { 71 this.CategoricalMap[columnName] = new Dictionary<object, double>(); 72 } 73 if (!this.CategoricalMap[columnName].ContainsKey(value)) 74 { 75 if (this.CategoricalMap[columnName].Values.Count == 0) 76 { 77 this.CategoricalMap[columnName][value] = 1.0; 78 } 79 else 80 { 81 this.CategoricalMap[columnName][value] = this.CategoricalMap[columnName].Values.Max() + 1.0; 82 } 83 } 84 return this.CategoricalMap[columnName][value]; 85 } 86 87 private double? GetValue(Run run, String columnName) 88 { 89 if ((run == null) || string.IsNullOrEmpty(columnName)) 90 { 91 return null; 92 } 93 Value value = run.ResultValues.FirstOrDefault(x => x.Name == columnName); 94 95 if (value == null) 96 { 97 return null; 98 } 99 100 DoubleValue doubleValue = value as DoubleValue; 101 IntValue intValue = value as IntValue; 102 BoolValue boolValue = value as BoolValue; 103 FloatValue floatValue = value as FloatValue; 104 BinaryValue binaryValue = value as BinaryValue; 105 LongValue longValue = value as LongValue; 106 StringValue stringValue = value as StringValue; 107 108 double? ret = null; 109 if (doubleValue != null) 110 { 111 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) 112 { 113 ret = doubleValue.Value; 114 } 115 } 116 else if (intValue != null) 117 { 118 ret = intValue.Value; 119 } 120 else if (floatValue != null) 121 { 122 ret = floatValue.Value; 123 } 124 else if (longValue != null) 125 { 126 ret = longValue.Value; 127 } 128 else 129 { 130 ret = GetCategoricalValue(columnName, value.ToString()); 131 } 132 return ret; 133 } 134 135 private void AddDataPoint(Run run) 136 {//, int pos) { 137 double? xValue; 138 double? yValue; 139 double? sValue; 140 // Series series = this.BubbleChart.Series[0]; 141 // Series series = new Series(); 142 xValue = GetValue(run, this.xAxisValue); 143 yValue = GetValue(run, this.yAxisValue); 144 sValue = GetValue(run, this.sizeAxisValue); 145 146 if (xValue.HasValue && yValue.HasValue && sValue.HasValue) 147 { 148 xValue = xValue.Value; 149 yValue = yValue.Value; 150 sValue = sValue.Value; 151 double[] yValues = { (double)yValue, (double)sValue }; 152 DataPoint point = new DataPoint(xValue.Value, yValues); 153 point.Tag = run; 154 point.Color = DataPointColor; 155 Series.Points.Add(point); 156 } 157 } 158 159 private void UpdateComboBoxValues() 160 { 161 if (Runs == null) 162 { 163 return; 164 } 165 ArrayList comboBoxValues = new ArrayList(); 166 Value[] resultValues = null; 167 foreach (Run run in Runs) 168 { 169 resultValues = run.ResultValues; 170 //comboBoxValues.Add(selectString); 171 foreach (Value v in resultValues) 172 { 173 String resultValueName = v.Name.ToString(); 174 if (!comboBoxValues.Contains(resultValueName)) 175 { 176 comboBoxValues.Add(resultValueName); 177 } 178 } 179 } 180 181 182 this.valuesAxisY.Clear(); 183 this.valuesAxisX.Clear(); 184 this.bubbleSize.Clear(); 185 186 foreach (String s in comboBoxValues) 187 { 188 if (!valuesAxisY.Contains(s)) 189 { 190 this.valuesAxisY.Add(s); 191 this.valuesAxisX.Add(s); 192 this.bubbleSize.Add(s); 193 } 194 } 195 } 196 197 private void UpdateDataPoints() 198 { 199 Run[] runs = this.Runs; 200 Series series = this.Series; 201 series.Points.Clear(); 202 if (runs != null) 203 { 204 foreach (Run run in runs) 205 { 206 this.AddDataPoint(run); 207 } 208 UpdateMarkerSize(); 209 } 210 } 211 212 private void UpdateMarkerSize() 213 { 214 double[] sizeValues = Series.Points.Select(p => p.YValues[1]).ToArray(); 215 double minSizeValue = sizeValues.Min(); 216 double maxSizeValue = sizeValues.Max(); 217 //int sizeFaktor = int.Parse(bubbleSizeFactor.SelectedItem.Value); 218 219 for (int i = 0; i < sizeValues.Length; i++) 220 { 221 DataPoint dataPoint = this.Series.Points[i]; 222 223 double sizeRange = maxSizeValue - minSizeValue; 224 double relativeSize = dataPoint.YValues[1] - minSizeValue; 225 226 if (sizeRange > double.Epsilon) 227 { 228 relativeSize /= sizeRange; 229 } 230 else 231 { 232 relativeSize = 1; 233 } 234 //int markerSize = (int)Math.Round(bubbleSizeFaktor * relativeSize); 235 //if (markerSize < 1) { 236 // markerSize = 1; 237 //} 238 double[] yValues = dataPoint.YValues; 239 // double minBubbleSizeFactor = double.Parse(bubbleSizeFactor.Items[0].Value); 240 //int markerSize = (int)Math.Round( 241 // (sizeFaktor - minBubbleSizeFactor) * relativeSize + minBubbleSizeFactor); 242 //yValues[1] = markerSize; 243 //dataPoint.MarkerSize = markerSize; 244 dataPoint.YValues = yValues; 245 } 246 } 247 248 public void UpdateBubbleChart(string yAxisValue,string xAxisValue, string sizeAxisValue) 249 { 250 this.yAxisValue = yAxisValue; 251 this.xAxisValue = xAxisValue; 252 this.sizeAxisValue = sizeAxisValue; 253 254 UpdateDataPoints(); 255 } 256 257 //protected void valuesAxisY_SelectedIndexChanged(object sender, EventArgs e) 258 //{ 259 // if (AllAxisSelected()) 260 // { 261 // UpdateBubbleChart(); 262 // } 10 namespace HLWebOKBQueryPlugin.Models { 11 public class ChartModel { 12 13 14 15 private Color DataPointColor = System.Drawing.Color.Black; 16 private String xAxisValue; 17 private String yAxisValue; 18 private String sizeAxisValue; 19 20 private Dictionary<string, Dictionary<object, double>> CategoricalMap { 21 get; 22 set; 23 } 24 25 public Run[] Runs { 26 set; 27 get; 28 // { 29 //UpdateComboBoxValues(value); 30 31 //} 32 } 33 34 public Series Series { set; get; } 35 36 public void UpdateRunCollection(Run[] runs) { 37 this.Runs = runs; 38 UpdateComboBoxValues(); 39 // 40 } 41 42 public List<string> valuesAxisY { get; set; } 43 public List<string> valuesAxisX { get; set; } 44 public List<string> bubbleSize { get; set; } 45 46 47 48 // COnstrucotr 49 public ChartModel() { 50 51 CategoricalMap = new Dictionary<string, Dictionary<object, double>>(); 52 53 valuesAxisY = new List<string>(); 54 valuesAxisX = new List<string>(); 55 bubbleSize = new List<string>(); 56 Series = new Series(); 57 this.Series.ChartType = SeriesChartType.Bubble; 58 } 59 60 61 62 private double GetCategoricalValue(string columnName, string value) { 63 if (!this.CategoricalMap.ContainsKey(columnName)) { 64 this.CategoricalMap[columnName] = new Dictionary<object, double>(); 65 } 66 if (!this.CategoricalMap[columnName].ContainsKey(value)) { 67 if (this.CategoricalMap[columnName].Values.Count == 0) { 68 this.CategoricalMap[columnName][value] = 1.0; 69 } else { 70 this.CategoricalMap[columnName][value] = this.CategoricalMap[columnName].Values.Max() + 1.0; 71 } 72 } 73 return this.CategoricalMap[columnName][value]; 74 } 75 76 private double? GetValue(Run run, String columnName) { 77 if ((run == null) || string.IsNullOrEmpty(columnName)) { 78 return null; 79 } 80 Value value = run.ResultValues.FirstOrDefault(x => x.Name == columnName); 81 82 if (value == null) { 83 return null; 84 } 85 86 DoubleValue doubleValue = value as DoubleValue; 87 IntValue intValue = value as IntValue; 88 BoolValue boolValue = value as BoolValue; 89 FloatValue floatValue = value as FloatValue; 90 BinaryValue binaryValue = value as BinaryValue; 91 LongValue longValue = value as LongValue; 92 StringValue stringValue = value as StringValue; 93 94 double? ret = null; 95 if (doubleValue != null) { 96 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) { 97 ret = doubleValue.Value; 98 } 99 } else if (intValue != null) { 100 ret = intValue.Value; 101 } else if (floatValue != null) { 102 ret = floatValue.Value; 103 } else if (longValue != null) { 104 ret = longValue.Value; 105 } else { 106 ret = GetCategoricalValue(columnName, value.ToString()); 107 } 108 return ret; 109 } 110 111 private void AddDataPoint(Run run) {//, int pos) { 112 double? xValue; 113 double? yValue; 114 double? sValue; 115 // Series series = this.BubbleChart.Series[0]; 116 // Series series = new Series(); 117 xValue = GetValue(run, this.xAxisValue); 118 yValue = GetValue(run, this.yAxisValue); 119 sValue = GetValue(run, this.sizeAxisValue); 120 121 if (xValue.HasValue && yValue.HasValue && sValue.HasValue) { 122 xValue = xValue.Value; 123 yValue = yValue.Value; 124 sValue = sValue.Value; 125 double[] yValues = { (double)yValue, (double)sValue }; 126 DataPoint point = new DataPoint(xValue.Value, yValues); 127 point.Tag = run; 128 point.Color = DataPointColor; 129 this.Series.Points.Add(point); 130 } 131 } 132 133 private void UpdateComboBoxValues() { 134 if (Runs == null) { 135 return; 136 } 137 ArrayList comboBoxValues = new ArrayList(); 138 Value[] resultValues = null; 139 foreach (Run run in Runs) { 140 resultValues = run.ResultValues; 141 //comboBoxValues.Add(selectString); 142 foreach (Value v in resultValues) { 143 String resultValueName = v.Name.ToString(); 144 if (!comboBoxValues.Contains(resultValueName)) { 145 comboBoxValues.Add(resultValueName); 146 } 147 } 148 } 149 150 151 this.valuesAxisY.Clear(); 152 this.valuesAxisX.Clear(); 153 this.bubbleSize.Clear(); 154 155 foreach (String s in comboBoxValues) { 156 if (!valuesAxisY.Contains(s)) { 157 this.valuesAxisY.Add(s); 158 this.valuesAxisX.Add(s); 159 this.bubbleSize.Add(s); 160 } 161 } 162 } 163 164 private void UpdateDataPoints() { 165 Run[] runs = this.Runs; 166 Series series = this.Series; 167 series.Points.Clear(); 168 if (runs != null) { 169 foreach (Run run in runs) { 170 this.AddDataPoint(run); 171 } 172 UpdateMarkerSize(); 173 } 174 } 175 176 private void UpdateMarkerSize() { 177 double[] sizeValues = Series.Points.Select(p => p.YValues[1]).ToArray(); 178 double minSizeValue = sizeValues.Min(); 179 double maxSizeValue = sizeValues.Max(); 180 //int sizeFaktor = int.Parse(bubbleSizeFactor.SelectedItem.Value); 181 182 for (int i = 0; i < sizeValues.Length; i++) { 183 DataPoint dataPoint = this.Series.Points[i]; 184 185 double sizeRange = maxSizeValue - minSizeValue; 186 double relativeSize = dataPoint.YValues[1] - minSizeValue; 187 188 if (sizeRange > double.Epsilon) { 189 relativeSize /= sizeRange; 190 } else { 191 relativeSize = 1; 192 } 193 //int markerSize = (int)Math.Round(bubbleSizeFaktor * relativeSize); 194 //if (markerSize < 1) { 195 // markerSize = 1; 263 196 //} 264 265 //protected void valuesAxisX_SelectedIndexChanged(object sender, EventArgs e) 266 //{ 267 // if (AllAxisSelected()) 268 // { 269 // UpdateBubbleChart(); 270 // } 271 //} 272 273 //protected void bubbleSize_SelectedIndexChanged(object sender, EventArgs e) 274 //{ 275 // if (AllAxisSelected()) 276 // { 277 // UpdateBubbleChart(); 278 // } 279 //} 280 281 //protected void bubbleSizeFactor_SelectedIndexChanged(object sender, EventArgs e) 282 //{ 283 // if (AllAxisSelected()) 284 // { 285 // UpdateBubbleChart(); 286 // } 287 //} 288 289 //private bool AllAxisSelected() 290 //{ 291 // return (((valuesAxisY.SelectedValue).CompareTo(selectString) != 0) && 292 // ((valuesAxisX.SelectedValue).CompareTo(selectString) != 0) && 293 // ((bubbleSize.SelectedValue).CompareTo(selectString) != 0)); 294 //} 295 } 197 double[] yValues = dataPoint.YValues; 198 // double minBubbleSizeFactor = double.Parse(bubbleSizeFactor.Items[0].Value); 199 //int markerSize = (int)Math.Round( 200 // (sizeFaktor - minBubbleSizeFactor) * relativeSize + minBubbleSizeFactor); 201 //yValues[1] = markerSize; 202 //dataPoint.MarkerSize = markerSize; 203 dataPoint.YValues = yValues; 204 } 205 } 206 207 public void UpdateBubbleChart(string yAxisValue, string xAxisValue, string sizeAxisValue) { 208 this.yAxisValue = yAxisValue; 209 this.xAxisValue = xAxisValue; 210 this.sizeAxisValue = sizeAxisValue; 211 212 UpdateDataPoints(); 213 } 214 215 //protected void valuesAxisY_SelectedIndexChanged(object sender, EventArgs e) 216 //{ 217 // if (AllAxisSelected()) 218 // { 219 // UpdateBubbleChart(); 220 // } 221 //} 222 223 //protected void valuesAxisX_SelectedIndexChanged(object sender, EventArgs e) 224 //{ 225 // if (AllAxisSelected()) 226 // { 227 // UpdateBubbleChart(); 228 // } 229 //} 230 231 //protected void bubbleSize_SelectedIndexChanged(object sender, EventArgs e) 232 //{ 233 // if (AllAxisSelected()) 234 // { 235 // UpdateBubbleChart(); 236 // } 237 //} 238 239 //protected void bubbleSizeFactor_SelectedIndexChanged(object sender, EventArgs e) 240 //{ 241 // if (AllAxisSelected()) 242 // { 243 // UpdateBubbleChart(); 244 // } 245 //} 246 247 //private bool AllAxisSelected() 248 //{ 249 // return (((valuesAxisY.SelectedValue).CompareTo(selectString) != 0) && 250 // ((valuesAxisX.SelectedValue).CompareTo(selectString) != 0) && 251 // ((bubbleSize.SelectedValue).CompareTo(selectString) != 0)); 252 //} 253 } 296 254 }
Note: See TracChangeset
for help on using the changeset viewer.