[4094] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15583] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[4094] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[11344] | 24 | using System.ComponentModel;
|
---|
[4094] | 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[4652] | 28 | using HeuristicLab.Common;
|
---|
[4094] | 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.Optimization.Views {
|
---|
[9910] | 35 | [View("Box Plot")]
|
---|
[4094] | 36 | [Content(typeof(RunCollection), false)]
|
---|
| 37 | public partial class RunCollectionBoxPlotView : AsynchronousContentView {
|
---|
| 38 | private enum AxisDimension { Color = 0 }
|
---|
| 39 | private const string BoxPlotSeriesName = "BoxPlotSeries";
|
---|
| 40 | private const string BoxPlotChartAreaName = "BoxPlotChartArea";
|
---|
| 41 |
|
---|
[4883] | 42 | private bool suppressUpdates = false;
|
---|
[4094] | 43 | private string xAxisValue;
|
---|
| 44 | private string yAxisValue;
|
---|
| 45 | private Dictionary<int, Dictionary<object, double>> categoricalMapping;
|
---|
[4211] | 46 | private SortedDictionary<double, Series> seriesCache;
|
---|
[4094] | 47 |
|
---|
| 48 | public RunCollectionBoxPlotView() {
|
---|
| 49 | InitializeComponent();
|
---|
[15607] | 50 | chart.ContextMenuStrip.Items.Insert(0, openBubbleChartViewToolStripMenuItem);
|
---|
| 51 |
|
---|
[4883] | 52 | categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
|
---|
| 53 | seriesCache = new SortedDictionary<double, Series>();
|
---|
| 54 | chart.ChartAreas[0].Visible = false;
|
---|
| 55 | chart.Series.Clear();
|
---|
| 56 | chart.ChartAreas.Add(BoxPlotChartAreaName);
|
---|
| 57 | chart.CustomizeAllChartAreas();
|
---|
[6638] | 58 | chart.ChartAreas[BoxPlotChartAreaName].Axes.ToList().ForEach(x => { x.ScaleView.Zoomable = true; x.ScaleView.MinSize = 0; });
|
---|
| 59 | chart.ChartAreas[BoxPlotChartAreaName].CursorX.Interval = 0.5;
|
---|
| 60 | chart.ChartAreas[BoxPlotChartAreaName].CursorY.Interval = 1e-5;
|
---|
[4094] | 61 | }
|
---|
| 62 |
|
---|
| 63 | public new RunCollection Content {
|
---|
| 64 | get { return (RunCollection)base.Content; }
|
---|
| 65 | set { base.Content = value; }
|
---|
| 66 | }
|
---|
| 67 | public IStringConvertibleMatrix Matrix {
|
---|
| 68 | get { return this.Content; }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | #region RunCollection and Run events
|
---|
| 72 | protected override void RegisterContentEvents() {
|
---|
| 73 | base.RegisterContentEvents();
|
---|
| 74 | Content.Reset += new EventHandler(Content_Reset);
|
---|
| 75 | Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
|
---|
| 76 | Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 77 | Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 78 | Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[4888] | 79 | Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
|
---|
[8962] | 80 | Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
|
---|
[4094] | 81 | RegisterRunEvents(Content);
|
---|
| 82 | }
|
---|
| 83 | protected override void DeregisterContentEvents() {
|
---|
| 84 | base.DeregisterContentEvents();
|
---|
| 85 | Content.Reset -= new EventHandler(Content_Reset);
|
---|
| 86 | Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
|
---|
| 87 | Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 88 | Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 89 | Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[4888] | 90 | Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
|
---|
[8962] | 91 | Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
|
---|
[4094] | 92 | DeregisterRunEvents(Content);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
|
---|
| 96 | foreach (IRun run in runs)
|
---|
[11344] | 97 | run.PropertyChanged += run_PropertyChanged;
|
---|
[4094] | 98 | }
|
---|
| 99 | protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
|
---|
| 100 | foreach (IRun run in runs)
|
---|
[11344] | 101 | run.PropertyChanged -= run_PropertyChanged;
|
---|
[4094] | 102 | }
|
---|
| 103 |
|
---|
| 104 | private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 105 | DeregisterRunEvents(e.OldItems);
|
---|
| 106 | RegisterRunEvents(e.Items);
|
---|
| 107 | }
|
---|
| 108 | private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 109 | DeregisterRunEvents(e.Items);
|
---|
| 110 | }
|
---|
| 111 | private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
| 112 | RegisterRunEvents(e.Items);
|
---|
| 113 | }
|
---|
[4888] | 114 | private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
|
---|
[4883] | 115 | if (InvokeRequired)
|
---|
[4888] | 116 | Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
|
---|
[4883] | 117 | else {
|
---|
[4888] | 118 | suppressUpdates = Content.UpdateOfRunsInProgress;
|
---|
[4883] | 119 | if (!suppressUpdates) UpdateDataPoints();
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
[4094] | 122 |
|
---|
| 123 | private void Content_Reset(object sender, EventArgs e) {
|
---|
| 124 | if (InvokeRequired)
|
---|
| 125 | Invoke(new EventHandler(Content_Reset), sender, e);
|
---|
[12077] | 126 | else if (!suppressUpdates) {
|
---|
[4094] | 127 | UpdateDataPoints();
|
---|
[9235] | 128 | UpdateAxisLabels();
|
---|
[4094] | 129 | }
|
---|
| 130 | }
|
---|
| 131 | private void Content_ColumnNamesChanged(object sender, EventArgs e) {
|
---|
| 132 | if (InvokeRequired)
|
---|
| 133 | Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
|
---|
| 134 | else {
|
---|
| 135 | UpdateComboBoxes();
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
[11344] | 138 | private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
[4094] | 139 | if (InvokeRequired)
|
---|
[11344] | 140 | this.Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
|
---|
[4883] | 141 | else if (!suppressUpdates) {
|
---|
[11344] | 142 | if (e.PropertyName == "Visible")
|
---|
| 143 | UpdateDataPoints();
|
---|
[4094] | 144 | }
|
---|
| 145 | }
|
---|
[8738] | 146 |
|
---|
| 147 | private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
|
---|
| 148 | if (InvokeRequired)
|
---|
| 149 | Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
|
---|
| 150 | else UpdateCaption();
|
---|
| 151 | }
|
---|
[4094] | 152 | #endregion
|
---|
| 153 |
|
---|
| 154 | #region update comboboxes, datapoints, runs
|
---|
| 155 | protected override void OnContentChanged() {
|
---|
| 156 | base.OnContentChanged();
|
---|
| 157 | this.categoricalMapping.Clear();
|
---|
| 158 | UpdateComboBoxes();
|
---|
| 159 | UpdateDataPoints();
|
---|
[8738] | 160 | UpdateCaption();
|
---|
[4094] | 161 | }
|
---|
| 162 |
|
---|
[8738] | 163 | private void UpdateCaption() {
|
---|
[9910] | 164 | Caption = Content != null ? Content.OptimizerName + " Box Plot" : ViewAttribute.GetViewName(GetType());
|
---|
[8738] | 165 | }
|
---|
| 166 |
|
---|
[4094] | 167 | private void UpdateComboBoxes() {
|
---|
| 168 | string selectedXAxis = (string)this.xAxisComboBox.SelectedItem;
|
---|
| 169 | string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
|
---|
| 170 | this.xAxisComboBox.Items.Clear();
|
---|
| 171 | this.yAxisComboBox.Items.Clear();
|
---|
| 172 | if (Content != null) {
|
---|
| 173 | string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
|
---|
| 174 | this.xAxisComboBox.Items.AddRange(additionalAxisDimension);
|
---|
| 175 | this.xAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
|
---|
| 176 | this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
|
---|
| 177 | this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
|
---|
| 178 |
|
---|
| 179 | bool changed = false;
|
---|
| 180 | if (selectedXAxis != null && xAxisComboBox.Items.Contains(selectedXAxis)) {
|
---|
| 181 | xAxisComboBox.SelectedItem = selectedXAxis;
|
---|
| 182 | changed = true;
|
---|
| 183 | }
|
---|
| 184 | if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) {
|
---|
| 185 | yAxisComboBox.SelectedItem = selectedYAxis;
|
---|
| 186 | changed = true;
|
---|
| 187 | }
|
---|
| 188 | if (changed)
|
---|
| 189 | UpdateDataPoints();
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | private void UpdateDataPoints() {
|
---|
[11007] | 194 | this.categoricalMapping.Clear();
|
---|
[4094] | 195 | this.chart.Series.Clear();
|
---|
| 196 | this.seriesCache.Clear();
|
---|
| 197 | if (Content != null) {
|
---|
| 198 | foreach (IRun run in this.Content.Where(r => r.Visible))
|
---|
| 199 | this.AddDataPoint(run);
|
---|
| 200 | foreach (Series s in this.seriesCache.Values)
|
---|
| 201 | this.chart.Series.Add(s);
|
---|
| 202 |
|
---|
[4652] | 203 | UpdateStatistics();
|
---|
[4094] | 204 | if (seriesCache.Count > 0) {
|
---|
| 205 | Series boxPlotSeries = CreateBoxPlotSeries();
|
---|
| 206 | this.chart.Series.Add(boxPlotSeries);
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | UpdateAxisLabels();
|
---|
| 210 | }
|
---|
| 211 | UpdateNoRunsVisibleLabel();
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[4652] | 214 | private void UpdateStatistics() {
|
---|
[4768] | 215 | DoubleMatrix matrix = new DoubleMatrix(9, seriesCache.Count);
|
---|
[4652] | 216 | matrix.SortableView = false;
|
---|
| 217 | List<string> columnNames = new List<string>();
|
---|
| 218 | foreach (Series series in seriesCache.Values) {
|
---|
| 219 | DataPoint datapoint = series.Points.FirstOrDefault();
|
---|
| 220 | if (datapoint != null) {
|
---|
| 221 | IRun run = (IRun)datapoint.Tag;
|
---|
[11024] | 222 | string selectedAxis = xAxisValue;
|
---|
[4652] | 223 | IItem value = null;
|
---|
| 224 |
|
---|
| 225 | if (Enum.IsDefined(typeof(AxisDimension), selectedAxis)) {
|
---|
| 226 | AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), selectedAxis);
|
---|
| 227 | switch (axisDimension) {
|
---|
[15607] | 228 | case AxisDimension.Color:
|
---|
| 229 | value = new StringValue(run.Color.ToString());
|
---|
[4652] | 230 | break;
|
---|
| 231 | }
|
---|
| 232 | } else value = Content.GetValue(run, selectedAxis);
|
---|
| 233 | string columnName = string.Empty;
|
---|
| 234 | if (value is DoubleValue || value is IntValue)
|
---|
| 235 | columnName = selectedAxis + ": ";
|
---|
| 236 | columnName += value.ToString();
|
---|
| 237 | columnNames.Add(columnName);
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 | matrix.ColumnNames = columnNames;
|
---|
[10767] | 241 | matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Median", "Average", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile" };
|
---|
[4652] | 242 |
|
---|
| 243 | for (int i = 0; i < seriesCache.Count; i++) {
|
---|
| 244 | Series series = seriesCache.ElementAt(i).Value;
|
---|
| 245 | double[] seriesValues = series.Points.Select(p => p.YValues[0]).OrderBy(d => d).ToArray();
|
---|
[4721] | 246 | matrix[0, i] = seriesValues.Length;
|
---|
[4768] | 247 | matrix[1, i] = seriesValues.Min();
|
---|
| 248 | matrix[2, i] = seriesValues.Max();
|
---|
[10767] | 249 | matrix[3, i] = seriesValues.Median();
|
---|
| 250 | matrix[4, i] = seriesValues.Average();
|
---|
[4768] | 251 | matrix[5, i] = seriesValues.StandardDeviation();
|
---|
| 252 | matrix[6, i] = seriesValues.Variance();
|
---|
[13051] | 253 | matrix[7, i] = seriesValues.Quantile(0.25);
|
---|
| 254 | matrix[8, i] = seriesValues.Quantile(0.75);
|
---|
[4652] | 255 | }
|
---|
| 256 | statisticsMatrixView.Content = matrix;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[4094] | 259 | private Series CreateBoxPlotSeries() {
|
---|
| 260 | Series boxPlotSeries = new Series(BoxPlotSeriesName);
|
---|
| 261 | string seriesNames = string.Concat(seriesCache.Keys.Select(x => x.ToString() + ";").ToArray());
|
---|
| 262 | seriesNames = seriesNames.Remove(seriesNames.Length - 1); //delete last ; from string
|
---|
| 263 |
|
---|
| 264 | boxPlotSeries.ChartArea = BoxPlotChartAreaName;
|
---|
| 265 | boxPlotSeries.ChartType = SeriesChartType.BoxPlot;
|
---|
| 266 | boxPlotSeries["BoxPlotSeries"] = seriesNames;
|
---|
| 267 | boxPlotSeries["BoxPlotShowUnusualValues"] = "true";
|
---|
| 268 | boxPlotSeries["PointWidth"] = "0.4";
|
---|
| 269 | boxPlotSeries.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.VerticalCenter;
|
---|
| 270 | boxPlotSeries.BackSecondaryColor = System.Drawing.Color.FromArgb(130, 224, 64, 10);
|
---|
| 271 | boxPlotSeries.BorderColor = System.Drawing.Color.FromArgb(64, 64, 64);
|
---|
| 272 | boxPlotSeries.Color = System.Drawing.Color.FromArgb(224, 64, 10);
|
---|
| 273 |
|
---|
| 274 | return boxPlotSeries;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | private void AddDataPoint(IRun run) {
|
---|
| 278 | double? xValue;
|
---|
| 279 | double? yValue;
|
---|
| 280 |
|
---|
| 281 | if (!xAxisComboBox.DroppedDown)
|
---|
| 282 | this.xAxisValue = (string)xAxisComboBox.SelectedItem;
|
---|
| 283 | if (!yAxisComboBox.DroppedDown)
|
---|
| 284 | this.yAxisValue = (string)yAxisComboBox.SelectedItem;
|
---|
| 285 |
|
---|
| 286 | xValue = GetValue(run, this.xAxisValue);
|
---|
| 287 | yValue = GetValue(run, this.yAxisValue);
|
---|
| 288 |
|
---|
| 289 | if (xValue.HasValue && yValue.HasValue) {
|
---|
| 290 | if (!this.seriesCache.ContainsKey(xValue.Value))
|
---|
| 291 | seriesCache[xValue.Value] = new Series(xValue.Value.ToString());
|
---|
| 292 |
|
---|
| 293 | Series series = seriesCache[xValue.Value];
|
---|
| 294 | DataPoint point = new DataPoint(xValue.Value, yValue.Value);
|
---|
[4652] | 295 | point.Tag = run;
|
---|
[4094] | 296 | series.Points.Add(point);
|
---|
| 297 | }
|
---|
| 298 | }
|
---|
| 299 | #endregion
|
---|
| 300 |
|
---|
| 301 | #region get values from run
|
---|
| 302 | private double? GetValue(IRun run, string columnName) {
|
---|
| 303 | if (run == null || string.IsNullOrEmpty(columnName))
|
---|
| 304 | return null;
|
---|
| 305 |
|
---|
| 306 | if (Enum.IsDefined(typeof(AxisDimension), columnName)) {
|
---|
| 307 | AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
|
---|
| 308 | return GetValue(run, axisDimension);
|
---|
| 309 | } else {
|
---|
| 310 | int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
|
---|
| 311 | IItem value = Content.GetValue(run, columnIndex);
|
---|
| 312 | if (value == null)
|
---|
| 313 | return null;
|
---|
| 314 |
|
---|
| 315 | DoubleValue doubleValue = value as DoubleValue;
|
---|
| 316 | IntValue intValue = value as IntValue;
|
---|
| 317 | TimeSpanValue timeSpanValue = value as TimeSpanValue;
|
---|
| 318 | double? ret = null;
|
---|
| 319 | if (doubleValue != null) {
|
---|
| 320 | if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
|
---|
| 321 | ret = doubleValue.Value;
|
---|
| 322 | } else if (intValue != null)
|
---|
| 323 | ret = intValue.Value;
|
---|
| 324 | else if (timeSpanValue != null) {
|
---|
| 325 | ret = timeSpanValue.Value.TotalSeconds;
|
---|
| 326 | } else
|
---|
| 327 | ret = GetCategoricalValue(columnIndex, value.ToString());
|
---|
| 328 |
|
---|
| 329 | return ret;
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
[11007] | 332 | private double? GetCategoricalValue(int dimension, string value) {
|
---|
[9235] | 333 | if (!this.categoricalMapping.ContainsKey(dimension)) {
|
---|
[4094] | 334 | this.categoricalMapping[dimension] = new Dictionary<object, double>();
|
---|
[9435] | 335 | var orderedCategories = Content.Where(r => r.Visible && Content.GetValue(r, dimension) != null).Select(r => Content.GetValue(r, dimension).ToString())
|
---|
| 336 | .Distinct().OrderBy(x => x, new NaturalStringComparer());
|
---|
[9235] | 337 | int count = 1;
|
---|
| 338 | foreach (var category in orderedCategories) {
|
---|
| 339 | this.categoricalMapping[dimension].Add(category, count);
|
---|
| 340 | count++;
|
---|
| 341 | }
|
---|
[4094] | 342 | }
|
---|
[11007] | 343 | if (!this.categoricalMapping[dimension].ContainsKey(value)) return null;
|
---|
[4094] | 344 | return this.categoricalMapping[dimension][value];
|
---|
| 345 | }
|
---|
[11007] | 346 | private double? GetValue(IRun run, AxisDimension axisDimension) {
|
---|
| 347 | double? value = double.NaN;
|
---|
[4094] | 348 | switch (axisDimension) {
|
---|
| 349 | case AxisDimension.Color: {
|
---|
[12787] | 350 | const int colorDimension = -1;
|
---|
| 351 | if (!categoricalMapping.ContainsKey(colorDimension)) {
|
---|
| 352 | categoricalMapping[colorDimension] = Content.Where(r => r.Visible)
|
---|
| 353 | .Select(r => r.Color.Name)
|
---|
| 354 | .Distinct()
|
---|
| 355 | .OrderBy(c => c, new NaturalStringComparer())
|
---|
| 356 | .Select((c, i) => new { Color = c, Index = i })
|
---|
| 357 | .ToDictionary(a => (object)a.Color, a => (double)a.Index);
|
---|
| 358 |
|
---|
| 359 | }
|
---|
| 360 | value = GetCategoricalValue(colorDimension, run.Color.Name);
|
---|
[4094] | 361 | break;
|
---|
| 362 | }
|
---|
| 363 | default: {
|
---|
| 364 | throw new ArgumentException("No handling strategy for " + axisDimension.ToString() + " is defined.");
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 | return value;
|
---|
| 368 | }
|
---|
| 369 | #endregion
|
---|
| 370 |
|
---|
| 371 | #region GUI events
|
---|
| 372 | private void UpdateNoRunsVisibleLabel() {
|
---|
[4883] | 373 | if (this.chart.Series.Count > 0) {
|
---|
[4094] | 374 | noRunsLabel.Visible = false;
|
---|
[4888] | 375 | showStatisticsCheckBox.Enabled = true;
|
---|
[4883] | 376 | splitContainer.Panel2Collapsed = !showStatisticsCheckBox.Checked;
|
---|
| 377 | } else {
|
---|
[4094] | 378 | noRunsLabel.Visible = true;
|
---|
[4888] | 379 | showStatisticsCheckBox.Enabled = false;
|
---|
[4883] | 380 | splitContainer.Panel2Collapsed = true;
|
---|
| 381 | }
|
---|
[4094] | 382 | }
|
---|
| 383 |
|
---|
| 384 | private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 385 | UpdateDataPoints();
|
---|
| 386 | }
|
---|
| 387 | private void UpdateAxisLabels() {
|
---|
| 388 | Axis xAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisX;
|
---|
| 389 | Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;
|
---|
| 390 | int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
|
---|
[12077] | 391 | //mkommend: combobox.SelectedIndex could not be used as this changes during hovering over possible values
|
---|
[11024] | 392 | var xSAxisSelectedIndex = xAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(xAxisValue);
|
---|
| 393 | var ySAxisSelectedIndex = yAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(yAxisValue);
|
---|
| 394 | SetCustomAxisLabels(xAxis, xSAxisSelectedIndex - axisDimensionCount);
|
---|
| 395 | SetCustomAxisLabels(yAxis, ySAxisSelectedIndex - axisDimensionCount);
|
---|
| 396 | if (xAxisValue != null)
|
---|
| 397 | xAxis.Title = xAxisValue;
|
---|
| 398 | if (yAxisValue != null)
|
---|
| 399 | yAxis.Title = yAxisValue;
|
---|
[4094] | 400 | }
|
---|
| 401 |
|
---|
| 402 | private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
|
---|
| 403 | this.UpdateAxisLabels();
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | private void SetCustomAxisLabels(Axis axis, int dimension) {
|
---|
| 407 | axis.CustomLabels.Clear();
|
---|
| 408 | if (categoricalMapping.ContainsKey(dimension)) {
|
---|
[9435] | 409 | int position = 1;
|
---|
| 410 | foreach (var pair in categoricalMapping[dimension].Where(x => seriesCache.ContainsKey(x.Value))) {
|
---|
[4094] | 411 | string labelText = pair.Key.ToString();
|
---|
[4211] | 412 | CustomLabel label = new CustomLabel();
|
---|
| 413 | label.ToolTip = labelText;
|
---|
[4094] | 414 | if (labelText.Length > 25)
|
---|
| 415 | labelText = labelText.Substring(0, 25) + " ... ";
|
---|
[4211] | 416 | label.Text = labelText;
|
---|
[4094] | 417 | label.GridTicks = GridTickTypes.TickMark;
|
---|
[9435] | 418 | label.FromPosition = position - 0.5;
|
---|
| 419 | label.ToPosition = position + 0.5;
|
---|
[4211] | 420 | axis.CustomLabels.Add(label);
|
---|
[9435] | 421 | position++;
|
---|
[4094] | 422 | }
|
---|
| 423 | } else if (dimension > 0 && Content.GetValue(0, dimension) is TimeSpanValue) {
|
---|
| 424 | this.chart.ChartAreas[0].RecalculateAxesScale();
|
---|
| 425 | Axis correspondingAxis = this.chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault();
|
---|
| 426 | if (correspondingAxis == null)
|
---|
| 427 | correspondingAxis = axis;
|
---|
| 428 | for (double i = correspondingAxis.Minimum; i <= correspondingAxis.Maximum; i += correspondingAxis.LabelStyle.Interval) {
|
---|
| 429 | TimeSpan time = TimeSpan.FromSeconds(i);
|
---|
| 430 | string x = string.Format("{0:00}:{1:00}:{2:00}", (int)time.Hours, time.Minutes, time.Seconds);
|
---|
| 431 | axis.CustomLabels.Add(i - correspondingAxis.LabelStyle.Interval / 2, i + correspondingAxis.LabelStyle.Interval / 2, x);
|
---|
| 432 | }
|
---|
[4211] | 433 | } else if (chart.ChartAreas[BoxPlotChartAreaName].AxisX == axis) {
|
---|
| 434 | double position = 1.0;
|
---|
| 435 | foreach (Series series in chart.Series) {
|
---|
| 436 | if (series.Name != BoxPlotSeriesName) {
|
---|
| 437 | string labelText = series.Points[0].XValue.ToString();
|
---|
| 438 | CustomLabel label = new CustomLabel();
|
---|
| 439 | label.FromPosition = position - 0.5;
|
---|
| 440 | label.ToPosition = position + 0.5;
|
---|
| 441 | label.GridTicks = GridTickTypes.TickMark;
|
---|
| 442 | label.Text = labelText;
|
---|
| 443 | axis.CustomLabels.Add(label);
|
---|
| 444 | position++;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
[4094] | 447 | }
|
---|
| 448 | }
|
---|
[4652] | 449 |
|
---|
[15607] | 450 | private void openBubbleChartViewToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 451 | RunCollectionBubbleChartView bubbleChartView = new RunCollectionBubbleChartView();
|
---|
| 452 | bubbleChartView.Content = this.Content;
|
---|
| 453 | bubbleChartView.xAxisComboBox.SelectedItem = xAxisComboBox.SelectedItem;
|
---|
| 454 | bubbleChartView.yAxisComboBox.SelectedItem = yAxisComboBox.SelectedItem;
|
---|
| 455 | bubbleChartView.Show();
|
---|
| 456 | }
|
---|
| 457 |
|
---|
[4652] | 458 | private void chart_MouseMove(object sender, MouseEventArgs e) {
|
---|
| 459 | string newTooltipText = string.Empty;
|
---|
| 460 | string oldTooltipText;
|
---|
| 461 | HitTestResult h = this.chart.HitTest(e.X, e.Y);
|
---|
| 462 | if (h.ChartElementType == ChartElementType.AxisLabels) {
|
---|
| 463 | newTooltipText = ((CustomLabel)h.Object).ToolTip;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | oldTooltipText = this.tooltip.GetToolTip(chart);
|
---|
| 467 | if (newTooltipText != oldTooltipText)
|
---|
| 468 | this.tooltip.SetToolTip(chart, newTooltipText);
|
---|
| 469 | }
|
---|
[4094] | 470 | #endregion
|
---|
[4652] | 471 |
|
---|
[4721] | 472 | private void showStatisticsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 473 | splitContainer.Panel2Collapsed = !showStatisticsCheckBox.Checked;
|
---|
| 474 | }
|
---|
| 475 |
|
---|
[15607] | 476 | public bool StatisticsVisible {
|
---|
| 477 | get { return splitContainer.Panel2Collapsed; }
|
---|
| 478 | set { splitContainer.Panel2Collapsed = value; }
|
---|
| 479 | }
|
---|
| 480 |
|
---|
[11715] | 481 | public void SetXAxis(string axisName) {
|
---|
| 482 | xAxisComboBox.SelectedItem = axisName;
|
---|
| 483 | }
|
---|
| 484 |
|
---|
| 485 | public void SetYAxis(string axisName) {
|
---|
| 486 | yAxisComboBox.SelectedItem = axisName;
|
---|
| 487 | }
|
---|
[4094] | 488 | }
|
---|
| 489 | }
|
---|