[6118] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Web;
|
---|
| 5 | using HLWebOKBQueryPlugin.OKBQueryService;
|
---|
| 6 | using System.Drawing;
|
---|
| 7 | using System.Web.UI.DataVisualization.Charting;
|
---|
| 8 | using System.Collections;
|
---|
| 9 |
|
---|
[6165] | 10 | namespace HLWebOKBQueryPlugin.Models {
|
---|
[6318] | 11 | public class ChartModel {
|
---|
[6118] | 12 |
|
---|
| 13 |
|
---|
| 14 |
|
---|
[6318] | 15 | private Color DataPointColor = System.Drawing.Color.Black;
|
---|
| 16 | //private String xAxisValue;
|
---|
| 17 | //private String yAxisValue;
|
---|
| 18 | //private String sizeAxisValue;
|
---|
[6118] | 19 |
|
---|
[6318] | 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 | }
|
---|
[6242] | 32 |
|
---|
| 33 |
|
---|
[6318] | 34 | private Dictionary<string, Dictionary<object, double>> CategoricalMap {
|
---|
| 35 | get;
|
---|
| 36 | set;
|
---|
| 37 | }
|
---|
[6118] | 38 |
|
---|
[6318] | 39 | //public Run[] Runs {
|
---|
| 40 | // set;
|
---|
| 41 | // get;
|
---|
| 42 | // // {
|
---|
| 43 | // //UpdateComboBoxValues(value);
|
---|
[6242] | 44 |
|
---|
[6318] | 45 | // //}
|
---|
| 46 | //}
|
---|
[6242] | 47 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 52 |
|
---|
[6318] | 53 | public Series Series { set; get; }
|
---|
[6118] | 54 |
|
---|
[6318] | 55 | public void UpdateRunCollection(Run[] runs) {
|
---|
| 56 | this.Runs = runs;
|
---|
| 57 | UpdateComboBoxValues();
|
---|
| 58 | //
|
---|
| 59 | }
|
---|
[6118] | 60 |
|
---|
[6318] | 61 | public List<string> valuesAxisY { get; set; }
|
---|
| 62 | public List<string> valuesAxisX { get; set; }
|
---|
| 63 | public List<string> bubbleSize { get; set; }
|
---|
[6118] | 64 |
|
---|
| 65 |
|
---|
| 66 |
|
---|
[6318] | 67 | // COnstrucotr
|
---|
| 68 | public ChartModel() {
|
---|
[6118] | 69 |
|
---|
[6318] | 70 | CategoricalMap = new Dictionary<string, Dictionary<object, double>>();
|
---|
[6118] | 71 |
|
---|
[6318] | 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 | }
|
---|
[6165] | 78 |
|
---|
| 79 |
|
---|
| 80 |
|
---|
[6318] | 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];
|
---|
[6118] | 94 | }
|
---|
| 95 |
|
---|
[6318] | 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);
|
---|
[6118] | 101 |
|
---|
[6318] | 102 | if (value == null) {
|
---|
| 103 | return null;
|
---|
| 104 | }
|
---|
[6118] | 105 |
|
---|
[6318] | 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;
|
---|
[6118] | 113 |
|
---|
[6318] | 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;
|
---|
[6118] | 133 | }
|
---|
| 134 |
|
---|
[6318] | 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);
|
---|
[6118] | 144 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 155 | }
|
---|
| 156 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 173 |
|
---|
| 174 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 186 | }
|
---|
| 187 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 198 | }
|
---|
| 199 |
|
---|
[6318] | 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);
|
---|
[6118] | 209 |
|
---|
[6318] | 210 | for (int i = 0; i < sizeValues.Length; i++) {
|
---|
| 211 | DataPoint dataPoint = this.Series.Points[i];
|
---|
[6118] | 212 |
|
---|
[6318] | 213 | double sizeRange = maxSizeValue - minSizeValue;
|
---|
| 214 | double relativeSize = dataPoint.YValues[1] - minSizeValue;
|
---|
[6118] | 215 |
|
---|
[6318] | 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 | }
|
---|
[6118] | 234 | }
|
---|
| 235 |
|
---|
[6318] | 236 | public void UpdateBubbleChart(string yAxisValue, string xAxisValue, string sizeAxisValue) {
|
---|
| 237 | this.yAxisValue = yAxisValue;
|
---|
| 238 | this.xAxisValue = xAxisValue;
|
---|
| 239 | this.sizeAxisValue = sizeAxisValue;
|
---|
[6118] | 240 |
|
---|
[6318] | 241 | UpdateDataPoints();
|
---|
| 242 | }
|
---|
[6118] | 243 |
|
---|
[6318] | 244 | //protected void valuesAxisY_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 245 | //{
|
---|
| 246 | // if (AllAxisSelected())
|
---|
| 247 | // {
|
---|
| 248 | // UpdateBubbleChart();
|
---|
| 249 | // }
|
---|
| 250 | //}
|
---|
[6118] | 251 |
|
---|
[6318] | 252 | //protected void valuesAxisX_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 253 | //{
|
---|
| 254 | // if (AllAxisSelected())
|
---|
| 255 | // {
|
---|
| 256 | // UpdateBubbleChart();
|
---|
| 257 | // }
|
---|
| 258 | //}
|
---|
[6118] | 259 |
|
---|
[6318] | 260 | //protected void bubbleSize_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 261 | //{
|
---|
| 262 | // if (AllAxisSelected())
|
---|
| 263 | // {
|
---|
| 264 | // UpdateBubbleChart();
|
---|
| 265 | // }
|
---|
| 266 | //}
|
---|
[6118] | 267 |
|
---|
[6318] | 268 | //protected void bubbleSizeFactor_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 269 | //{
|
---|
| 270 | // if (AllAxisSelected())
|
---|
| 271 | // {
|
---|
| 272 | // UpdateBubbleChart();
|
---|
| 273 | // }
|
---|
| 274 | //}
|
---|
[6118] | 275 |
|
---|
[6318] | 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 | //}
|
---|
| 282 | }
|
---|
[6118] | 283 | } |
---|