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