[3349] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[7259] | 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3349] | 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;
|
---|
| 24 | using System.Drawing;
|
---|
| 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[9229] | 28 | using HeuristicLab.Common;
|
---|
| 29 | using HeuristicLab.Core;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[3349] | 33 |
|
---|
| 34 | namespace HeuristicLab.Optimization.Views {
|
---|
| 35 | [View("RunCollection BubbleChart")]
|
---|
| 36 | [Content(typeof(RunCollection), false)]
|
---|
| 37 | public partial class RunCollectionBubbleChartView : AsynchronousContentView {
|
---|
[3524] | 38 | private enum SizeDimension { Constant = 0 }
|
---|
| 39 | private enum AxisDimension { Index = 0 }
|
---|
| 40 |
|
---|
[3726] | 41 | private string xAxisValue;
|
---|
| 42 | private string yAxisValue;
|
---|
| 43 | private string sizeAxisValue;
|
---|
| 44 |
|
---|
[4883] | 45 | private Dictionary<IRun, List<DataPoint>> runToDataPointMapping;
|
---|
[9235] | 46 | private Dictionary<IRun, int> runToIndexMapping;
|
---|
[3349] | 47 | private Dictionary<int, Dictionary<object, double>> categoricalMapping;
|
---|
[3411] | 48 | private Dictionary<IRun, double> xJitter;
|
---|
| 49 | private Dictionary<IRun, double> yJitter;
|
---|
| 50 | private double xJitterFactor = 0.0;
|
---|
| 51 | private double yJitterFactor = 0.0;
|
---|
| 52 | private Random random;
|
---|
| 53 | private bool isSelecting = false;
|
---|
[4883] | 54 | private bool suppressUpdates = false;
|
---|
[3349] | 55 |
|
---|
[9235] | 56 |
|
---|
| 57 |
|
---|
[3349] | 58 | public RunCollectionBubbleChartView() {
|
---|
| 59 | InitializeComponent();
|
---|
[3411] | 60 |
|
---|
[6673] | 61 | chart.ContextMenuStrip.Items.Insert(0, hideRunToolStripMenuItem);
|
---|
| 62 | chart.ContextMenuStrip.Items.Insert(1, openBoxPlotViewToolStripMenuItem);
|
---|
[9190] | 63 | chart.ContextMenuStrip.Items.Add(getDataAsMatrixToolStripMenuItem);
|
---|
[6673] | 64 | chart.ContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(ContextMenuStrip_Opening);
|
---|
| 65 |
|
---|
[4883] | 66 | runToDataPointMapping = new Dictionary<IRun, List<DataPoint>>();
|
---|
[4635] | 67 | categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
|
---|
| 68 | xJitter = new Dictionary<IRun, double>();
|
---|
| 69 | yJitter = new Dictionary<IRun, double>();
|
---|
| 70 | random = new Random();
|
---|
[4846] | 71 |
|
---|
[4635] | 72 | colorDialog.Color = Color.Black;
|
---|
| 73 | colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color);
|
---|
| 74 | isSelecting = false;
|
---|
[4846] | 75 |
|
---|
[4636] | 76 | chart.CustomizeAllChartAreas();
|
---|
[4635] | 77 | chart.ChartAreas[0].CursorX.Interval = 1;
|
---|
| 78 | chart.ChartAreas[0].CursorY.Interval = 1;
|
---|
| 79 | chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !this.isSelecting;
|
---|
| 80 | chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !this.isSelecting;
|
---|
[3349] | 81 | }
|
---|
| 82 |
|
---|
| 83 | public new RunCollection Content {
|
---|
| 84 | get { return (RunCollection)base.Content; }
|
---|
| 85 | set { base.Content = value; }
|
---|
| 86 | }
|
---|
[3447] | 87 | public IStringConvertibleMatrix Matrix {
|
---|
| 88 | get { return this.Content; }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[3349] | 91 | protected override void RegisterContentEvents() {
|
---|
| 92 | base.RegisterContentEvents();
|
---|
| 93 | Content.Reset += new EventHandler(Content_Reset);
|
---|
| 94 | Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
|
---|
[3428] | 95 | Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 96 | Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 97 | Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[4888] | 98 | Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
|
---|
[8962] | 99 | Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
|
---|
[3448] | 100 | RegisterRunEvents(Content);
|
---|
| 101 | }
|
---|
[3349] | 102 | protected override void DeregisterContentEvents() {
|
---|
| 103 | base.DeregisterContentEvents();
|
---|
| 104 | Content.Reset -= new EventHandler(Content_Reset);
|
---|
| 105 | Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
|
---|
[3428] | 106 | Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
|
---|
| 107 | Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
|
---|
| 108 | Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
|
---|
[4888] | 109 | Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
|
---|
[8962] | 110 | Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
|
---|
[3448] | 111 | DeregisterRunEvents(Content);
|
---|
| 112 | }
|
---|
[4094] | 113 | protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
|
---|
| 114 | foreach (IRun run in runs)
|
---|
| 115 | run.Changed += new EventHandler(run_Changed);
|
---|
| 116 | }
|
---|
[3448] | 117 | protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
|
---|
| 118 | foreach (IRun run in runs)
|
---|
[3428] | 119 | run.Changed -= new EventHandler(run_Changed);
|
---|
[3349] | 120 | }
|
---|
[3428] | 121 |
|
---|
| 122 | private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3448] | 123 | DeregisterRunEvents(e.OldItems);
|
---|
| 124 | RegisterRunEvents(e.Items);
|
---|
[3428] | 125 | }
|
---|
| 126 | private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3449] | 127 | DeregisterRunEvents(e.Items);
|
---|
[3428] | 128 | }
|
---|
| 129 | private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[3448] | 130 | RegisterRunEvents(e.Items);
|
---|
[3428] | 131 | }
|
---|
| 132 | private void run_Changed(object sender, EventArgs e) {
|
---|
[3632] | 133 | if (InvokeRequired)
|
---|
| 134 | this.Invoke(new EventHandler(run_Changed), sender, e);
|
---|
| 135 | else {
|
---|
| 136 | IRun run = (IRun)sender;
|
---|
| 137 | UpdateRun(run);
|
---|
| 138 | }
|
---|
[3614] | 139 | }
|
---|
| 140 |
|
---|
| 141 | private void UpdateRun(IRun run) {
|
---|
[4883] | 142 | if (!suppressUpdates) {
|
---|
| 143 | if (runToDataPointMapping.ContainsKey(run)) {
|
---|
| 144 | foreach (DataPoint point in runToDataPointMapping[run]) {
|
---|
| 145 | point.Color = run.Color;
|
---|
| 146 | if (!run.Visible) {
|
---|
| 147 | this.chart.Series[0].Points.Remove(point);
|
---|
| 148 | UpdateCursorInterval();
|
---|
| 149 | chart.ChartAreas[0].RecalculateAxesScale();
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | if (!run.Visible) runToDataPointMapping.Remove(run);
|
---|
| 153 | } else {
|
---|
| 154 | AddDataPoint(run);
|
---|
[4799] | 155 | UpdateCursorInterval();
|
---|
| 156 | chart.ChartAreas[0].RecalculateAxesScale();
|
---|
| 157 | }
|
---|
[4883] | 158 |
|
---|
| 159 | if (this.chart.Series[0].Points.Count == 0)
|
---|
| 160 | noRunsLabel.Visible = true;
|
---|
| 161 | else
|
---|
| 162 | noRunsLabel.Visible = false;
|
---|
[4799] | 163 | }
|
---|
[3428] | 164 | }
|
---|
| 165 |
|
---|
[3349] | 166 | protected override void OnContentChanged() {
|
---|
| 167 | base.OnContentChanged();
|
---|
[3411] | 168 | this.categoricalMapping.Clear();
|
---|
[3499] | 169 | UpdateComboBoxes();
|
---|
| 170 | UpdateDataPoints();
|
---|
[8738] | 171 | UpdateCaption();
|
---|
[9235] | 172 | RebuildInverseIndex();
|
---|
[3349] | 173 | }
|
---|
[9235] | 174 |
|
---|
| 175 | private void RebuildInverseIndex() {
|
---|
| 176 | if (Content != null) {
|
---|
| 177 | runToIndexMapping = new Dictionary<IRun, int>(Content.Count);
|
---|
| 178 | int i = 0;
|
---|
| 179 | foreach (var run in Content) {
|
---|
| 180 | runToIndexMapping.Add(run, i);
|
---|
| 181 | i++;
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
| 185 |
|
---|
[3349] | 186 | private void Content_ColumnNamesChanged(object sender, EventArgs e) {
|
---|
| 187 | if (InvokeRequired)
|
---|
| 188 | Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
|
---|
| 189 | else
|
---|
| 190 | UpdateComboBoxes();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[8738] | 193 | private void UpdateCaption() {
|
---|
[8962] | 194 | Caption = Content != null ? Content.OptimizerName + " Bubble Chart" : ViewAttribute.GetViewName(GetType());
|
---|
[8738] | 195 | }
|
---|
| 196 |
|
---|
[3349] | 197 | private void UpdateComboBoxes() {
|
---|
[3701] | 198 | string selectedXAxis = (string)this.xAxisComboBox.SelectedItem;
|
---|
| 199 | string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
|
---|
| 200 | string selectedSizeAxis = (string)this.sizeComboBox.SelectedItem;
|
---|
[3349] | 201 | this.xAxisComboBox.Items.Clear();
|
---|
| 202 | this.yAxisComboBox.Items.Clear();
|
---|
[3411] | 203 | this.sizeComboBox.Items.Clear();
|
---|
[3499] | 204 | if (Content != null) {
|
---|
[3524] | 205 | string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
|
---|
| 206 | this.xAxisComboBox.Items.AddRange(additionalAxisDimension);
|
---|
[3499] | 207 | this.xAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
|
---|
[3524] | 208 | this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
|
---|
[3499] | 209 | this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
|
---|
[3524] | 210 | string[] additionalSizeDimension = Enum.GetNames(typeof(SizeDimension));
|
---|
| 211 | this.sizeComboBox.Items.AddRange(additionalSizeDimension);
|
---|
[3499] | 212 | this.sizeComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
|
---|
[3524] | 213 | this.sizeComboBox.SelectedItem = SizeDimension.Constant.ToString();
|
---|
[3701] | 214 |
|
---|
| 215 | bool changed = false;
|
---|
| 216 | if (selectedXAxis != null && xAxisComboBox.Items.Contains(selectedXAxis)) {
|
---|
| 217 | xAxisComboBox.SelectedItem = selectedXAxis;
|
---|
| 218 | changed = true;
|
---|
| 219 | }
|
---|
| 220 | if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) {
|
---|
| 221 | yAxisComboBox.SelectedItem = selectedYAxis;
|
---|
| 222 | changed = true;
|
---|
| 223 | }
|
---|
| 224 | if (selectedSizeAxis != null && sizeComboBox.Items.Contains(selectedSizeAxis)) {
|
---|
| 225 | sizeComboBox.SelectedItem = selectedSizeAxis;
|
---|
| 226 | changed = true;
|
---|
| 227 | }
|
---|
[9235] | 228 | if (changed) {
|
---|
[3701] | 229 | UpdateDataPoints();
|
---|
[9235] | 230 | UpdateAxisLabels();
|
---|
| 231 | }
|
---|
[3499] | 232 | }
|
---|
[3349] | 233 | }
|
---|
| 234 |
|
---|
[4883] | 235 |
|
---|
[4888] | 236 | private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
|
---|
[4883] | 237 | if (InvokeRequired)
|
---|
[4888] | 238 | Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
|
---|
[4883] | 239 | else {
|
---|
[4888] | 240 | suppressUpdates = Content.UpdateOfRunsInProgress;
|
---|
[4883] | 241 | if (!suppressUpdates) UpdateDataPoints();
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[8738] | 245 | private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
|
---|
| 246 | if (InvokeRequired)
|
---|
| 247 | Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
|
---|
| 248 | else UpdateCaption();
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[3349] | 251 | private void Content_Reset(object sender, EventArgs e) {
|
---|
| 252 | if (InvokeRequired)
|
---|
| 253 | Invoke(new EventHandler(Content_Reset), sender, e);
|
---|
| 254 | else {
|
---|
| 255 | this.categoricalMapping.Clear();
|
---|
[9235] | 256 | RebuildInverseIndex();
|
---|
[3349] | 257 | UpdateDataPoints();
|
---|
[9235] | 258 | UpdateAxisLabels();
|
---|
[3349] | 259 | }
|
---|
| 260 | }
|
---|
| 261 |
|
---|
| 262 | private void UpdateDataPoints() {
|
---|
| 263 | Series series = this.chart.Series[0];
|
---|
| 264 | series.Points.Clear();
|
---|
[4799] | 265 | runToDataPointMapping.Clear();
|
---|
[6096] | 266 |
|
---|
| 267 | chart.ChartAreas[0].AxisX.IsMarginVisible = xAxisValue != AxisDimension.Index.ToString();
|
---|
| 268 | chart.ChartAreas[0].AxisY.IsMarginVisible = yAxisValue != AxisDimension.Index.ToString();
|
---|
| 269 |
|
---|
[3499] | 270 | if (Content != null) {
|
---|
| 271 | foreach (IRun run in this.Content)
|
---|
| 272 | this.AddDataPoint(run);
|
---|
[3543] | 273 |
|
---|
| 274 | if (this.chart.Series[0].Points.Count == 0)
|
---|
| 275 | noRunsLabel.Visible = true;
|
---|
[4209] | 276 | else {
|
---|
[3543] | 277 | noRunsLabel.Visible = false;
|
---|
[5330] | 278 | UpdateMarkerSizes();
|
---|
[4209] | 279 | UpdateCursorInterval();
|
---|
| 280 | }
|
---|
[3499] | 281 | }
|
---|
[5824] | 282 | xTrackBar.Value = 0;
|
---|
| 283 | yTrackBar.Value = 0;
|
---|
[9068] | 284 |
|
---|
| 285 | //needed to set axis back to automatic and refresh them, otherwise their values may remain NaN
|
---|
| 286 | var xAxis = chart.ChartAreas[0].AxisX;
|
---|
| 287 | var yAxis = chart.ChartAreas[0].AxisY;
|
---|
| 288 | SetAutomaticUpdateOfAxis(xAxis, true);
|
---|
| 289 | SetAutomaticUpdateOfAxis(yAxis, true);
|
---|
| 290 | chart.Refresh();
|
---|
[3428] | 291 | }
|
---|
[5330] | 292 |
|
---|
| 293 | private void UpdateMarkerSizes() {
|
---|
[9229] | 294 | var series = chart.Series[0];
|
---|
| 295 | var sizeValues = series.Points.Select(p => p.YValues[1]);
|
---|
| 296 |
|
---|
[5330] | 297 | double minSizeValue = sizeValues.Min();
|
---|
| 298 | double maxSizeValue = sizeValues.Max();
|
---|
[9229] | 299 | double sizeRange = maxSizeValue - minSizeValue;
|
---|
[5330] | 300 |
|
---|
[9229] | 301 | const int smallestBubbleSize = 5;
|
---|
| 302 |
|
---|
| 303 | foreach (DataPoint point in series.Points) {
|
---|
| 304 | //calculates the relative size of the data point 0 <= relativeSize <= 1
|
---|
[5348] | 305 | double relativeSize = (point.YValues[1] - minSizeValue);
|
---|
[9229] | 306 | if (sizeRange > double.Epsilon) {
|
---|
| 307 | relativeSize /= sizeRange;
|
---|
[5348] | 308 |
|
---|
[9229] | 309 | //invert bubble sizes if the value of the trackbar is negative
|
---|
| 310 | if (sizeTrackBar.Value < 0) relativeSize = Math.Abs(relativeSize - 1);
|
---|
| 311 | } else relativeSize = 1;
|
---|
[5348] | 312 |
|
---|
[9229] | 313 | double sizeChange = Math.Abs(sizeTrackBar.Value) * relativeSize;
|
---|
| 314 | point.MarkerSize = (int)Math.Round(sizeChange + smallestBubbleSize);
|
---|
[5330] | 315 | }
|
---|
| 316 | }
|
---|
| 317 |
|
---|
[5824] | 318 | private void UpdateDataPointJitter() {
|
---|
| 319 | var xAxis = this.chart.ChartAreas[0].AxisX;
|
---|
| 320 | var yAxis = this.chart.ChartAreas[0].AxisY;
|
---|
| 321 |
|
---|
[9068] | 322 | SetAutomaticUpdateOfAxis(xAxis, false);
|
---|
| 323 | SetAutomaticUpdateOfAxis(yAxis, false);
|
---|
| 324 |
|
---|
[8835] | 325 | double xAxisRange = xAxis.Maximum - xAxis.Minimum;
|
---|
| 326 | double yAxisRange = yAxis.Maximum - yAxis.Minimum;
|
---|
[8832] | 327 |
|
---|
[5824] | 328 | foreach (DataPoint point in chart.Series[0].Points) {
|
---|
| 329 | IRun run = (IRun)point.Tag;
|
---|
| 330 | double xValue = GetValue(run, xAxisValue).Value;
|
---|
| 331 | double yValue = GetValue(run, yAxisValue).Value;
|
---|
| 332 |
|
---|
| 333 | if (!xJitterFactor.IsAlmost(0.0))
|
---|
[8835] | 334 | xValue += 0.1 * GetXJitter(run) * xJitterFactor * (xAxisRange);
|
---|
[5824] | 335 | if (!yJitterFactor.IsAlmost(0.0))
|
---|
[8835] | 336 | yValue += 0.1 * GetYJitter(run) * yJitterFactor * (yAxisRange);
|
---|
[5824] | 337 |
|
---|
| 338 | point.XValue = xValue;
|
---|
| 339 | point.YValues[0] = yValue;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[9068] | 344 | // sets an axis to automatic or restrains it to its current values
|
---|
| 345 | // this is used that none of the set values is changed when jitter is applied, so that the chart stays the same
|
---|
| 346 | private void SetAutomaticUpdateOfAxis(Axis axis, bool enabled) {
|
---|
| 347 | if (enabled) {
|
---|
| 348 | axis.Maximum = double.NaN;
|
---|
| 349 | axis.Minimum = double.NaN;
|
---|
| 350 | axis.MajorGrid.Interval = double.NaN;
|
---|
| 351 | axis.MajorTickMark.Interval = double.NaN;
|
---|
| 352 | axis.LabelStyle.Interval = double.NaN;
|
---|
| 353 | } else {
|
---|
| 354 | axis.Minimum = axis.Minimum;
|
---|
| 355 | axis.Maximum = axis.Maximum;
|
---|
| 356 | axis.MajorGrid.Interval = axis.MajorGrid.Interval;
|
---|
| 357 | axis.MajorTickMark.Interval = axis.MajorTickMark.Interval;
|
---|
| 358 | axis.LabelStyle.Interval = axis.LabelStyle.Interval;
|
---|
| 359 | }
|
---|
| 360 | }
|
---|
| 361 |
|
---|
[3428] | 362 | private void AddDataPoint(IRun run) {
|
---|
[3349] | 363 | double? xValue;
|
---|
| 364 | double? yValue;
|
---|
[3411] | 365 | double? sizeValue;
|
---|
[3428] | 366 | Series series = this.chart.Series[0];
|
---|
[3726] | 367 |
|
---|
[4845] | 368 | xValue = GetValue(run, xAxisValue);
|
---|
| 369 | yValue = GetValue(run, yAxisValue);
|
---|
| 370 | sizeValue = GetValue(run, sizeAxisValue);
|
---|
[3726] | 371 |
|
---|
[3543] | 372 | if (xValue.HasValue && yValue.HasValue && sizeValue.HasValue) {
|
---|
[3701] | 373 | xValue = xValue.Value;
|
---|
[5824] | 374 |
|
---|
[3701] | 375 | yValue = yValue.Value;
|
---|
[5824] | 376 |
|
---|
[3428] | 377 | if (run.Visible) {
|
---|
[3411] | 378 | DataPoint point = new DataPoint(xValue.Value, new double[] { yValue.Value, sizeValue.Value });
|
---|
[3428] | 379 | point.Tag = run;
|
---|
| 380 | point.Color = run.Color;
|
---|
[3411] | 381 | series.Points.Add(point);
|
---|
[4883] | 382 | if (!runToDataPointMapping.ContainsKey(run)) runToDataPointMapping.Add(run, new List<DataPoint>());
|
---|
| 383 | runToDataPointMapping[run].Add(point);
|
---|
[3411] | 384 | }
|
---|
[3349] | 385 | }
|
---|
| 386 | }
|
---|
[3524] | 387 | private double? GetValue(IRun run, string columnName) {
|
---|
| 388 | if (run == null || string.IsNullOrEmpty(columnName))
|
---|
[3349] | 389 | return null;
|
---|
| 390 |
|
---|
[3524] | 391 | if (Enum.IsDefined(typeof(AxisDimension), columnName)) {
|
---|
| 392 | AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
|
---|
| 393 | return GetValue(run, axisDimension);
|
---|
| 394 | } else if (Enum.IsDefined(typeof(SizeDimension), columnName)) {
|
---|
| 395 | SizeDimension sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), columnName);
|
---|
| 396 | return GetValue(run, sizeDimension);
|
---|
| 397 | } else {
|
---|
| 398 | int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
|
---|
| 399 | IItem value = Content.GetValue(run, columnIndex);
|
---|
| 400 | if (value == null)
|
---|
| 401 | return null;
|
---|
[3447] | 402 |
|
---|
[3524] | 403 | DoubleValue doubleValue = value as DoubleValue;
|
---|
| 404 | IntValue intValue = value as IntValue;
|
---|
[4049] | 405 | TimeSpanValue timeSpanValue = value as TimeSpanValue;
|
---|
[3543] | 406 | double? ret = null;
|
---|
| 407 | if (doubleValue != null) {
|
---|
| 408 | if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
|
---|
| 409 | ret = doubleValue.Value;
|
---|
| 410 | } else if (intValue != null)
|
---|
[3524] | 411 | ret = intValue.Value;
|
---|
[4049] | 412 | else if (timeSpanValue != null) {
|
---|
| 413 | ret = timeSpanValue.Value.TotalSeconds;
|
---|
| 414 | } else
|
---|
[3524] | 415 | ret = GetCategoricalValue(columnIndex, value.ToString());
|
---|
[3447] | 416 |
|
---|
[3524] | 417 | return ret;
|
---|
| 418 | }
|
---|
[3349] | 419 | }
|
---|
[3524] | 420 | private double GetCategoricalValue(int dimension, string value) {
|
---|
[9235] | 421 | if (!this.categoricalMapping.ContainsKey(dimension)) {
|
---|
[3349] | 422 | this.categoricalMapping[dimension] = new Dictionary<object, double>();
|
---|
[9235] | 423 | var orderedCategories = Content.Select(r => Content.GetValue(r, dimension).ToString())
|
---|
| 424 | .Distinct()
|
---|
| 425 | .OrderBy(x => x, new NaturalStringComparer());
|
---|
| 426 | int count = 1;
|
---|
| 427 | foreach (var category in orderedCategories) {
|
---|
| 428 | this.categoricalMapping[dimension].Add(category, count);
|
---|
| 429 | count++;
|
---|
| 430 | }
|
---|
[3349] | 431 | }
|
---|
[3524] | 432 | return this.categoricalMapping[dimension][value];
|
---|
[3349] | 433 | }
|
---|
[9235] | 434 |
|
---|
[3524] | 435 | private double GetValue(IRun run, AxisDimension axisDimension) {
|
---|
| 436 | double value = double.NaN;
|
---|
| 437 | switch (axisDimension) {
|
---|
| 438 | case AxisDimension.Index: {
|
---|
[9235] | 439 | value = runToIndexMapping[run];
|
---|
[3524] | 440 | break;
|
---|
| 441 | }
|
---|
| 442 | default: {
|
---|
| 443 | throw new ArgumentException("No handling strategy for " + axisDimension.ToString() + " is defined.");
|
---|
| 444 | }
|
---|
| 445 | }
|
---|
| 446 | return value;
|
---|
| 447 | }
|
---|
| 448 | private double GetValue(IRun run, SizeDimension sizeDimension) {
|
---|
| 449 | double value = double.NaN;
|
---|
| 450 | switch (sizeDimension) {
|
---|
| 451 | case SizeDimension.Constant: {
|
---|
| 452 | value = 2;
|
---|
| 453 | break;
|
---|
| 454 | }
|
---|
| 455 | default: {
|
---|
| 456 | throw new ArgumentException("No handling strategy for " + sizeDimension.ToString() + " is defined.");
|
---|
| 457 | }
|
---|
| 458 | }
|
---|
| 459 | return value;
|
---|
| 460 | }
|
---|
[3707] | 461 | private void UpdateCursorInterval() {
|
---|
| 462 | Series series = chart.Series[0];
|
---|
| 463 | double[] xValues = (from point in series.Points
|
---|
| 464 | where !point.IsEmpty
|
---|
| 465 | select point.XValue)
|
---|
| 466 | .DefaultIfEmpty(1.0)
|
---|
| 467 | .ToArray();
|
---|
| 468 | double[] yValues = (from point in series.Points
|
---|
| 469 | where !point.IsEmpty
|
---|
| 470 | select point.YValues[0])
|
---|
| 471 | .DefaultIfEmpty(1.0)
|
---|
| 472 | .ToArray();
|
---|
[3349] | 473 |
|
---|
[3707] | 474 | double xRange = xValues.Max() - xValues.Min();
|
---|
| 475 | double yRange = yValues.Max() - yValues.Min();
|
---|
[4049] | 476 | if (xRange.IsAlmost(0.0)) xRange = 1.0;
|
---|
| 477 | if (yRange.IsAlmost(0.0)) yRange = 1.0;
|
---|
[3707] | 478 | double xDigits = (int)Math.Log10(xRange) - 3;
|
---|
| 479 | double yDigits = (int)Math.Log10(yRange) - 3;
|
---|
| 480 | double xZoomInterval = Math.Pow(10, xDigits);
|
---|
| 481 | double yZoomInterval = Math.Pow(10, yDigits);
|
---|
| 482 | this.chart.ChartAreas[0].CursorX.Interval = xZoomInterval;
|
---|
| 483 | this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
|
---|
[4049] | 484 |
|
---|
| 485 | //code to handle TimeSpanValues correct
|
---|
| 486 | int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
|
---|
| 487 | int columnIndex = xAxisComboBox.SelectedIndex - axisDimensionCount;
|
---|
| 488 | if (columnIndex >= 0 && Content.GetValue(0, columnIndex) is TimeSpanValue)
|
---|
| 489 | this.chart.ChartAreas[0].CursorX.Interval = 1;
|
---|
| 490 | columnIndex = yAxisComboBox.SelectedIndex - axisDimensionCount;
|
---|
| 491 | if (columnIndex >= 0 && Content.GetValue(0, columnIndex) is TimeSpanValue)
|
---|
| 492 | this.chart.ChartAreas[0].CursorY.Interval = 1;
|
---|
[3707] | 493 | }
|
---|
| 494 |
|
---|
[4888] | 495 | #region Drag & drop and tooltip
|
---|
[6026] | 496 | private void chart_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
[6094] | 497 | HitTestResult h = this.chart.HitTest(e.X, e.Y, ChartElementType.DataPoint);
|
---|
[3411] | 498 | if (h.ChartElementType == ChartElementType.DataPoint) {
|
---|
[3459] | 499 | IRun run = (IRun)((DataPoint)h.Object).Tag;
|
---|
[5976] | 500 | IContentView view = MainFormManager.MainForm.ShowContent(run);
|
---|
| 501 | if (view != null) {
|
---|
| 502 | view.ReadOnly = this.ReadOnly;
|
---|
| 503 | view.Locked = this.Locked;
|
---|
| 504 | }
|
---|
[6026] | 505 |
|
---|
| 506 | this.chart.ChartAreas[0].CursorX.SelectionStart = this.chart.ChartAreas[0].CursorX.SelectionEnd;
|
---|
| 507 | this.chart.ChartAreas[0].CursorY.SelectionStart = this.chart.ChartAreas[0].CursorY.SelectionEnd;
|
---|
[3411] | 508 | }
|
---|
[6096] | 509 | UpdateAxisLabels();
|
---|
[3411] | 510 | }
|
---|
| 511 |
|
---|
[3428] | 512 | private void chart_MouseUp(object sender, MouseEventArgs e) {
|
---|
[3459] | 513 | if (isSelecting) {
|
---|
| 514 | System.Windows.Forms.DataVisualization.Charting.Cursor xCursor = chart.ChartAreas[0].CursorX;
|
---|
| 515 | System.Windows.Forms.DataVisualization.Charting.Cursor yCursor = chart.ChartAreas[0].CursorY;
|
---|
[3428] | 516 |
|
---|
[3459] | 517 | double minX = Math.Min(xCursor.SelectionStart, xCursor.SelectionEnd);
|
---|
| 518 | double maxX = Math.Max(xCursor.SelectionStart, xCursor.SelectionEnd);
|
---|
| 519 | double minY = Math.Min(yCursor.SelectionStart, yCursor.SelectionEnd);
|
---|
| 520 | double maxY = Math.Max(yCursor.SelectionStart, yCursor.SelectionEnd);
|
---|
[3428] | 521 |
|
---|
[3459] | 522 | //check for click to select model
|
---|
| 523 | if (minX == maxX && minY == maxY) {
|
---|
| 524 | HitTestResult hitTest = chart.HitTest(e.X, e.Y);
|
---|
| 525 | if (hitTest.ChartElementType == ChartElementType.DataPoint) {
|
---|
| 526 | int pointIndex = hitTest.PointIndex;
|
---|
| 527 | IRun run = (IRun)this.chart.Series[0].Points[pointIndex].Tag;
|
---|
| 528 | run.Color = colorDialog.Color;
|
---|
| 529 | }
|
---|
| 530 | } else {
|
---|
| 531 | List<DataPoint> selectedPoints = new List<DataPoint>();
|
---|
| 532 | foreach (DataPoint p in this.chart.Series[0].Points) {
|
---|
| 533 | if (p.XValue >= minX && p.XValue < maxX &&
|
---|
| 534 | p.YValues[0] >= minY && p.YValues[0] < maxY) {
|
---|
| 535 | selectedPoints.Add(p);
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
| 538 | foreach (DataPoint p in selectedPoints) {
|
---|
| 539 | IRun run = (IRun)p.Tag;
|
---|
| 540 | run.Color = colorDialog.Color;
|
---|
| 541 | }
|
---|
[3428] | 542 | }
|
---|
[3638] | 543 | this.chart.ChartAreas[0].CursorX.SelectionStart = this.chart.ChartAreas[0].CursorX.SelectionEnd;
|
---|
| 544 | this.chart.ChartAreas[0].CursorY.SelectionStart = this.chart.ChartAreas[0].CursorY.SelectionEnd;
|
---|
[3428] | 545 | }
|
---|
| 546 | }
|
---|
| 547 |
|
---|
[3411] | 548 | private void chart_MouseMove(object sender, MouseEventArgs e) {
|
---|
[3487] | 549 | HitTestResult h = this.chart.HitTest(e.X, e.Y);
|
---|
[3524] | 550 | string newTooltipText = string.Empty;
|
---|
[3487] | 551 | string oldTooltipText;
|
---|
| 552 | if (h.ChartElementType == ChartElementType.DataPoint) {
|
---|
| 553 | IRun run = (IRun)((DataPoint)h.Object).Tag;
|
---|
[3524] | 554 | newTooltipText = BuildTooltip(run);
|
---|
[4212] | 555 | } else if (h.ChartElementType == ChartElementType.AxisLabels) {
|
---|
| 556 | newTooltipText = ((CustomLabel)h.Object).ToolTip;
|
---|
[3524] | 557 | }
|
---|
| 558 |
|
---|
[3487] | 559 | oldTooltipText = this.tooltip.GetToolTip(chart);
|
---|
| 560 | if (newTooltipText != oldTooltipText)
|
---|
| 561 | this.tooltip.SetToolTip(chart, newTooltipText);
|
---|
[3411] | 562 | }
|
---|
[3524] | 563 |
|
---|
| 564 | private string BuildTooltip(IRun run) {
|
---|
| 565 | string tooltip;
|
---|
| 566 | tooltip = run.Name + System.Environment.NewLine;
|
---|
| 567 |
|
---|
| 568 | double? xValue = this.GetValue(run, (string)xAxisComboBox.SelectedItem);
|
---|
| 569 | double? yValue = this.GetValue(run, (string)yAxisComboBox.SelectedItem);
|
---|
| 570 | double? sizeValue = this.GetValue(run, (string)sizeComboBox.SelectedItem);
|
---|
| 571 |
|
---|
| 572 | string xString = xValue == null ? string.Empty : xValue.Value.ToString();
|
---|
| 573 | string yString = yValue == null ? string.Empty : yValue.Value.ToString();
|
---|
| 574 | string sizeString = sizeValue == null ? string.Empty : sizeValue.Value.ToString();
|
---|
| 575 |
|
---|
[4049] | 576 | //code to handle TimeSpanValues correct
|
---|
| 577 | int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
|
---|
| 578 | int columnIndex = xAxisComboBox.SelectedIndex - axisDimensionCount;
|
---|
| 579 | if (xValue.HasValue && columnIndex > 0 && Content.GetValue(0, columnIndex) is TimeSpanValue) {
|
---|
| 580 | TimeSpan time = TimeSpan.FromSeconds(xValue.Value);
|
---|
[4212] | 581 | xString = string.Format("{0:00}:{1:00}:{2:00.00}", (int)time.TotalHours, time.Minutes, time.Seconds);
|
---|
[4049] | 582 | }
|
---|
| 583 | columnIndex = yAxisComboBox.SelectedIndex - axisDimensionCount;
|
---|
| 584 | if (yValue.HasValue && columnIndex > 0 && Content.GetValue(0, columnIndex) is TimeSpanValue) {
|
---|
| 585 | TimeSpan time = TimeSpan.FromSeconds(yValue.Value);
|
---|
[4212] | 586 | yString = string.Format("{0:00}:{1:00}:{2:00.00}", (int)time.TotalHours, time.Minutes, time.Seconds);
|
---|
[4049] | 587 | }
|
---|
| 588 |
|
---|
[3524] | 589 | tooltip += xAxisComboBox.SelectedItem + " : " + xString + Environment.NewLine;
|
---|
| 590 | tooltip += yAxisComboBox.SelectedItem + " : " + yString + Environment.NewLine;
|
---|
| 591 | tooltip += sizeComboBox.SelectedItem + " : " + sizeString + Environment.NewLine;
|
---|
| 592 |
|
---|
| 593 | return tooltip;
|
---|
| 594 | }
|
---|
[3411] | 595 | #endregion
|
---|
| 596 |
|
---|
| 597 | #region GUI events and updating
|
---|
| 598 | private double GetXJitter(IRun run) {
|
---|
| 599 | if (!this.xJitter.ContainsKey(run))
|
---|
| 600 | this.xJitter[run] = random.NextDouble() * 2.0 - 1.0;
|
---|
| 601 | return this.xJitter[run];
|
---|
| 602 | }
|
---|
| 603 | private double GetYJitter(IRun run) {
|
---|
| 604 | if (!this.yJitter.ContainsKey(run))
|
---|
| 605 | this.yJitter[run] = random.NextDouble() * 2.0 - 1.0;
|
---|
| 606 | return this.yJitter[run];
|
---|
| 607 | }
|
---|
| 608 | private void jitterTrackBar_ValueChanged(object sender, EventArgs e) {
|
---|
| 609 | this.xJitterFactor = xTrackBar.Value / 100.0;
|
---|
| 610 | this.yJitterFactor = yTrackBar.Value / 100.0;
|
---|
[5824] | 611 | UpdateDataPointJitter();
|
---|
[3411] | 612 | }
|
---|
[5330] | 613 | private void sizeTrackBar_ValueChanged(object sender, EventArgs e) {
|
---|
| 614 | UpdateMarkerSizes();
|
---|
| 615 | }
|
---|
[3411] | 616 |
|
---|
[5330] | 617 | private void AxisComboBox_SelectedValueChanged(object sender, EventArgs e) {
|
---|
[4812] | 618 | bool axisSelected = xAxisComboBox.SelectedIndex != -1 && yAxisComboBox.SelectedIndex != -1;
|
---|
| 619 | xTrackBar.Enabled = yTrackBar.Enabled = axisSelected;
|
---|
| 620 | colorXAxisButton.Enabled = colorYAxisButton.Enabled = axisSelected;
|
---|
[4845] | 621 |
|
---|
[6094] | 622 | xAxisValue = (string)xAxisComboBox.SelectedItem;
|
---|
| 623 | yAxisValue = (string)yAxisComboBox.SelectedItem;
|
---|
| 624 | sizeAxisValue = (string)sizeComboBox.SelectedItem;
|
---|
[4845] | 625 |
|
---|
[3411] | 626 | UpdateDataPoints();
|
---|
| 627 | UpdateAxisLabels();
|
---|
| 628 | }
|
---|
[3349] | 629 | private void UpdateAxisLabels() {
|
---|
| 630 | Axis xAxis = this.chart.ChartAreas[0].AxisX;
|
---|
| 631 | Axis yAxis = this.chart.ChartAreas[0].AxisY;
|
---|
[3536] | 632 | int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
|
---|
| 633 | SetCustomAxisLabels(xAxis, xAxisComboBox.SelectedIndex - axisDimensionCount);
|
---|
| 634 | SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex - axisDimensionCount);
|
---|
[4635] | 635 | if (xAxisComboBox.SelectedItem != null)
|
---|
| 636 | xAxis.Title = xAxisComboBox.SelectedItem.ToString();
|
---|
| 637 | if (yAxisComboBox.SelectedItem != null)
|
---|
| 638 | yAxis.Title = yAxisComboBox.SelectedItem.ToString();
|
---|
[3349] | 639 | }
|
---|
[4049] | 640 |
|
---|
| 641 | private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
|
---|
| 642 | this.UpdateAxisLabels();
|
---|
| 643 | }
|
---|
| 644 |
|
---|
[3411] | 645 | private void SetCustomAxisLabels(Axis axis, int dimension) {
|
---|
| 646 | axis.CustomLabels.Clear();
|
---|
[3349] | 647 | if (categoricalMapping.ContainsKey(dimension)) {
|
---|
| 648 | foreach (var pair in categoricalMapping[dimension]) {
|
---|
[3536] | 649 | string labelText = pair.Key.ToString();
|
---|
[4212] | 650 | CustomLabel label = new CustomLabel();
|
---|
| 651 | label.ToolTip = labelText;
|
---|
[3543] | 652 | if (labelText.Length > 25)
|
---|
| 653 | labelText = labelText.Substring(0, 25) + " ... ";
|
---|
[4212] | 654 | label.Text = labelText;
|
---|
[3349] | 655 | label.GridTicks = GridTickTypes.TickMark;
|
---|
[4212] | 656 | label.FromPosition = pair.Value - 0.5;
|
---|
| 657 | label.ToPosition = pair.Value + 0.5;
|
---|
| 658 | axis.CustomLabels.Add(label);
|
---|
[3349] | 659 | }
|
---|
[4049] | 660 | } else if (dimension > 0 && Content.GetValue(0, dimension) is TimeSpanValue) {
|
---|
| 661 | this.chart.ChartAreas[0].RecalculateAxesScale();
|
---|
| 662 | for (double i = axis.Minimum; i <= axis.Maximum; i += axis.LabelStyle.Interval) {
|
---|
| 663 | TimeSpan time = TimeSpan.FromSeconds(i);
|
---|
[6096] | 664 | string x = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);
|
---|
[4058] | 665 | axis.CustomLabels.Add(i - axis.LabelStyle.Interval / 2, i + axis.LabelStyle.Interval / 2, x);
|
---|
[4049] | 666 | }
|
---|
[3349] | 667 | }
|
---|
| 668 | }
|
---|
[3411] | 669 |
|
---|
| 670 | private void zoomButton_CheckedChanged(object sender, EventArgs e) {
|
---|
| 671 | this.isSelecting = selectButton.Checked;
|
---|
| 672 | this.colorButton.Enabled = this.isSelecting;
|
---|
| 673 | this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting;
|
---|
| 674 | this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting;
|
---|
| 675 | }
|
---|
| 676 | private void colorButton_Click(object sender, EventArgs e) {
|
---|
| 677 | if (colorDialog.ShowDialog(this) == DialogResult.OK) {
|
---|
| 678 | this.colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color);
|
---|
| 679 | }
|
---|
| 680 | }
|
---|
| 681 | private Image GenerateImage(int width, int height, Color fillColor) {
|
---|
| 682 | Image colorImage = new Bitmap(width, height);
|
---|
| 683 | using (Graphics gfx = Graphics.FromImage(colorImage)) {
|
---|
| 684 | using (SolidBrush brush = new SolidBrush(fillColor)) {
|
---|
| 685 | gfx.FillRectangle(brush, 0, 0, width, height);
|
---|
| 686 | }
|
---|
| 687 | }
|
---|
| 688 | return colorImage;
|
---|
| 689 | }
|
---|
[4653] | 690 |
|
---|
[6673] | 691 | private IRun runToHide = null;
|
---|
| 692 | private void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
|
---|
| 693 | var pos = Control.MousePosition;
|
---|
| 694 | var chartPos = chart.PointToClient(pos);
|
---|
| 695 |
|
---|
| 696 | HitTestResult h = this.chart.HitTest(chartPos.X, chartPos.Y);
|
---|
| 697 | if (h.ChartElementType == ChartElementType.DataPoint) {
|
---|
| 698 | runToHide = (IRun)((DataPoint)h.Object).Tag;
|
---|
| 699 | hideRunToolStripMenuItem.Visible = true;
|
---|
| 700 | } else {
|
---|
| 701 | runToHide = null;
|
---|
| 702 | hideRunToolStripMenuItem.Visible = false;
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | }
|
---|
| 706 | private void hideRunToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 707 | var constraint = Content.Constraints.OfType<RunCollectionContentConstraint>().Where(c => c.Active).FirstOrDefault();
|
---|
| 708 | if (constraint == null) {
|
---|
| 709 | constraint = new RunCollectionContentConstraint();
|
---|
| 710 | Content.Constraints.Add(constraint);
|
---|
| 711 | constraint.Active = true;
|
---|
| 712 | }
|
---|
| 713 | constraint.ConstraintData.Add(runToHide);
|
---|
| 714 | }
|
---|
| 715 |
|
---|
[4653] | 716 | private void openBoxPlotViewToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 717 | RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();
|
---|
| 718 | boxplotView.Content = this.Content;
|
---|
| 719 | boxplotView.xAxisComboBox.SelectedItem = xAxisComboBox.SelectedItem;
|
---|
| 720 | boxplotView.yAxisComboBox.SelectedItem = yAxisComboBox.SelectedItem;
|
---|
| 721 | boxplotView.Show();
|
---|
| 722 | }
|
---|
[9190] | 723 |
|
---|
| 724 | private void getDataAsMatrixToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 725 | int xCol = Matrix.ColumnNames.ToList().IndexOf(xAxisValue);
|
---|
| 726 | var grouped = new Dictionary<string, List<string>>();
|
---|
| 727 | Dictionary<double, string> reverseMapping = null;
|
---|
| 728 | if (categoricalMapping.ContainsKey(xCol))
|
---|
| 729 | reverseMapping = categoricalMapping[xCol].ToDictionary(x => x.Value, y => y.Key.ToString());
|
---|
| 730 | foreach (var run in Content.Where(r => r.Visible)) {
|
---|
| 731 | var x = GetValue(run, xAxisValue);
|
---|
| 732 | var y = GetValue(run, yAxisValue);
|
---|
| 733 | if (!(x.HasValue && y.HasValue)) continue;
|
---|
| 734 |
|
---|
| 735 | var category = reverseMapping == null ? x.Value.ToString() : reverseMapping[x.Value];
|
---|
| 736 | if (!grouped.ContainsKey(category)) grouped[category] = new List<string>();
|
---|
| 737 | grouped[category].Add(y.Value.ToString());
|
---|
| 738 | }
|
---|
| 739 |
|
---|
| 740 | if (!grouped.Any()) return;
|
---|
| 741 | var matrix = new StringMatrix(grouped.Values.Max(x => x.Count), grouped.Count) {
|
---|
| 742 | ColumnNames = grouped.Keys.ToArray()
|
---|
| 743 | };
|
---|
| 744 | int i = 0;
|
---|
| 745 | foreach (var col in matrix.ColumnNames) {
|
---|
| 746 | int j = 0;
|
---|
| 747 | foreach (var y in grouped[col])
|
---|
| 748 | matrix[j++, i] = y;
|
---|
| 749 | i++;
|
---|
| 750 | }
|
---|
| 751 |
|
---|
| 752 | MainFormManager.MainForm.ShowContent(matrix);
|
---|
| 753 | }
|
---|
[3411] | 754 | #endregion
|
---|
[4799] | 755 |
|
---|
[4888] | 756 | #region Automatic coloring
|
---|
[4799] | 757 | private void colorXAxisButton_Click(object sender, EventArgs e) {
|
---|
[4845] | 758 | ColorRuns(xAxisValue);
|
---|
[4799] | 759 | }
|
---|
| 760 |
|
---|
| 761 | private void colorYAxisButton_Click(object sender, EventArgs e) {
|
---|
[4845] | 762 | ColorRuns(yAxisValue);
|
---|
| 763 | }
|
---|
| 764 |
|
---|
| 765 | private void ColorRuns(string axisValue) {
|
---|
[9235] | 766 | var runs = Content.Where(r => r.Visible).Select(r => new { Run = r, Value = GetValue(r, axisValue) }).Where(r => r.Value.HasValue).ToList();
|
---|
[4845] | 767 | double minValue = runs.Min(r => r.Value.Value);
|
---|
| 768 | double maxValue = runs.Max(r => r.Value.Value);
|
---|
| 769 | double range = maxValue - minValue;
|
---|
[9236] | 770 | // UpdateOfRunsInProgress has to be set to true, otherwise run_Changed is called all the time (also in other views)
|
---|
| 771 | Content.UpdateOfRunsInProgress = true;
|
---|
[9235] | 772 | if (range.IsAlmost(0)) {
|
---|
| 773 | Color c = ColorGradient.Colors[0];
|
---|
| 774 | runs.ForEach(r => r.Run.Color = c);
|
---|
| 775 | } else {
|
---|
| 776 | int maxColorIndex = ColorGradient.Colors.Count - 1;
|
---|
| 777 | foreach (var r in runs) {
|
---|
| 778 | int colorIndex = (int)(maxColorIndex * (r.Value - minValue) / (range));
|
---|
| 779 | r.Run.Color = ColorGradient.Colors[colorIndex];
|
---|
| 780 | }
|
---|
[4799] | 781 | }
|
---|
[9236] | 782 | Content.UpdateOfRunsInProgress = false;
|
---|
[4799] | 783 | }
|
---|
| 784 | #endregion
|
---|
[3349] | 785 | }
|
---|
| 786 | }
|
---|