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