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