[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 {
|
---|
| 11 | public class ChartModel {
|
---|
[6118] | 12 |
|
---|
| 13 |
|
---|
| 14 |
|
---|
[6165] | 15 | private Color DataPointColor = System.Drawing.Color.Black;
|
---|
| 16 | private String xAxisValue;
|
---|
| 17 | private String yAxisValue;
|
---|
| 18 | private String sizeAxisValue;
|
---|
[6118] | 19 |
|
---|
[6165] | 20 | private Dictionary<string, Dictionary<object, double>> CategoricalMap {
|
---|
| 21 | get;
|
---|
| 22 | set;
|
---|
| 23 | }
|
---|
[6118] | 24 |
|
---|
[6165] | 25 | public Run[] Runs {
|
---|
| 26 | set;
|
---|
| 27 | get;
|
---|
| 28 | // {
|
---|
| 29 | //UpdateComboBoxValues(value);
|
---|
[6118] | 30 |
|
---|
[6165] | 31 | //}
|
---|
| 32 | }
|
---|
[6118] | 33 |
|
---|
[6165] | 34 | public Series Series { set; get; }
|
---|
[6118] | 35 |
|
---|
[6165] | 36 | public void UpdateRunCollection(Run[] runs) {
|
---|
| 37 | this.Runs = runs;
|
---|
| 38 | UpdateComboBoxValues();
|
---|
| 39 | //
|
---|
| 40 | }
|
---|
[6118] | 41 |
|
---|
[6165] | 42 | public List<string> valuesAxisY { get; set; }
|
---|
| 43 | public List<string> valuesAxisX { get; set; }
|
---|
| 44 | public List<string> bubbleSize { get; set; }
|
---|
[6118] | 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
[6165] | 48 | // COnstrucotr
|
---|
| 49 | public ChartModel() {
|
---|
[6118] | 50 |
|
---|
[6165] | 51 | CategoricalMap = new Dictionary<string, Dictionary<object, double>>();
|
---|
[6118] | 52 |
|
---|
[6165] | 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;
|
---|
[6118] | 71 | }
|
---|
[6165] | 72 | }
|
---|
| 73 | return this.CategoricalMap[columnName][value];
|
---|
| 74 | }
|
---|
[6118] | 75 |
|
---|
[6165] | 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);
|
---|
[6118] | 81 |
|
---|
[6165] | 82 | if (value == null) {
|
---|
| 83 | return null;
|
---|
| 84 | }
|
---|
[6118] | 85 |
|
---|
[6165] | 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;
|
---|
[6118] | 93 |
|
---|
[6165] | 94 | double? ret = null;
|
---|
| 95 | if (doubleValue != null) {
|
---|
| 96 | if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) {
|
---|
| 97 | ret = doubleValue.Value;
|
---|
[6118] | 98 | }
|
---|
[6165] | 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 | }
|
---|
[6118] | 110 |
|
---|
[6165] | 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);
|
---|
[6118] | 120 |
|
---|
[6165] | 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 | }
|
---|
[6118] | 147 | }
|
---|
[6165] | 148 | }
|
---|
[6118] | 149 |
|
---|
| 150 |
|
---|
[6165] | 151 | this.valuesAxisY.Clear();
|
---|
| 152 | this.valuesAxisX.Clear();
|
---|
| 153 | this.bubbleSize.Clear();
|
---|
[6118] | 154 |
|
---|
[6165] | 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);
|
---|
[6118] | 160 | }
|
---|
[6165] | 161 | }
|
---|
| 162 | }
|
---|
[6118] | 163 |
|
---|
[6165] | 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);
|
---|
[6118] | 171 | }
|
---|
[6165] | 172 | UpdateMarkerSize();
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
[6118] | 175 |
|
---|
[6165] | 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);
|
---|
[6118] | 181 |
|
---|
[6165] | 182 | for (int i = 0; i < sizeValues.Length; i++) {
|
---|
| 183 | DataPoint dataPoint = this.Series.Points[i];
|
---|
[6118] | 184 |
|
---|
[6165] | 185 | double sizeRange = maxSizeValue - minSizeValue;
|
---|
| 186 | double relativeSize = dataPoint.YValues[1] - minSizeValue;
|
---|
[6118] | 187 |
|
---|
[6165] | 188 | if (sizeRange > double.Epsilon) {
|
---|
| 189 | relativeSize /= sizeRange;
|
---|
| 190 | } else {
|
---|
| 191 | relativeSize = 1;
|
---|
[6118] | 192 | }
|
---|
[6165] | 193 | //int markerSize = (int)Math.Round(bubbleSizeFaktor * relativeSize);
|
---|
| 194 | //if (markerSize < 1) {
|
---|
| 195 | // markerSize = 1;
|
---|
| 196 | //}
|
---|
| 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 | }
|
---|
[6118] | 206 |
|
---|
[6165] | 207 | public void UpdateBubbleChart(string yAxisValue, string xAxisValue, string sizeAxisValue) {
|
---|
| 208 | this.yAxisValue = yAxisValue;
|
---|
| 209 | this.xAxisValue = xAxisValue;
|
---|
| 210 | this.sizeAxisValue = sizeAxisValue;
|
---|
[6118] | 211 |
|
---|
[6165] | 212 | UpdateDataPoints();
|
---|
| 213 | }
|
---|
[6118] | 214 |
|
---|
[6165] | 215 | //protected void valuesAxisY_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 216 | //{
|
---|
| 217 | // if (AllAxisSelected())
|
---|
| 218 | // {
|
---|
| 219 | // UpdateBubbleChart();
|
---|
| 220 | // }
|
---|
| 221 | //}
|
---|
[6118] | 222 |
|
---|
[6165] | 223 | //protected void valuesAxisX_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 224 | //{
|
---|
| 225 | // if (AllAxisSelected())
|
---|
| 226 | // {
|
---|
| 227 | // UpdateBubbleChart();
|
---|
| 228 | // }
|
---|
| 229 | //}
|
---|
[6118] | 230 |
|
---|
[6165] | 231 | //protected void bubbleSize_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 232 | //{
|
---|
| 233 | // if (AllAxisSelected())
|
---|
| 234 | // {
|
---|
| 235 | // UpdateBubbleChart();
|
---|
| 236 | // }
|
---|
| 237 | //}
|
---|
[6118] | 238 |
|
---|
[6165] | 239 | //protected void bubbleSizeFactor_SelectedIndexChanged(object sender, EventArgs e)
|
---|
| 240 | //{
|
---|
| 241 | // if (AllAxisSelected())
|
---|
| 242 | // {
|
---|
| 243 | // UpdateBubbleChart();
|
---|
| 244 | // }
|
---|
| 245 | //}
|
---|
[6118] | 246 |
|
---|
[6165] | 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 | }
|
---|
[6118] | 254 | } |
---|