#region License Information
/* HeuristicLab
* Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Data;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Optimization.Views {
[View("Box Plot")]
[Content(typeof(RunCollection), false)]
public partial class RunCollectionBoxPlotView : AsynchronousContentView {
private enum AxisDimension { Color = 0 }
private const string BoxPlotSeriesName = "BoxPlotSeries";
private const string BoxPlotChartAreaName = "BoxPlotChartArea";
private bool suppressUpdates = false;
private string xAxisValue;
private string yAxisValue;
private Dictionary> categoricalMapping;
private SortedDictionary seriesCache;
public RunCollectionBoxPlotView() {
InitializeComponent();
categoricalMapping = new Dictionary>();
seriesCache = new SortedDictionary();
chart.ChartAreas[0].Visible = false;
chart.Series.Clear();
chart.ChartAreas.Add(BoxPlotChartAreaName);
chart.CustomizeAllChartAreas();
chart.ChartAreas[BoxPlotChartAreaName].Axes.ToList().ForEach(x => { x.ScaleView.Zoomable = true; x.ScaleView.MinSize = 0; });
chart.ChartAreas[BoxPlotChartAreaName].CursorX.Interval = 0.5;
chart.ChartAreas[BoxPlotChartAreaName].CursorY.Interval = 1e-5;
}
public new RunCollection Content {
get { return (RunCollection)base.Content; }
set { base.Content = value; }
}
public IStringConvertibleMatrix Matrix {
get { return this.Content; }
}
#region RunCollection and Run events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.Reset += new EventHandler(Content_Reset);
Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded);
Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved);
Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset);
Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
RegisterRunEvents(Content);
}
protected override void DeregisterContentEvents() {
base.DeregisterContentEvents();
Content.Reset -= new EventHandler(Content_Reset);
Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsAdded);
Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_ItemsRemoved);
Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler(Content_CollectionReset);
Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
DeregisterRunEvents(Content);
}
protected virtual void RegisterRunEvents(IEnumerable runs) {
foreach (IRun run in runs)
run.PropertyChanged += run_PropertyChanged;
}
protected virtual void DeregisterRunEvents(IEnumerable runs) {
foreach (IRun run in runs)
run.PropertyChanged -= run_PropertyChanged;
}
private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
DeregisterRunEvents(e.OldItems);
RegisterRunEvents(e.Items);
}
private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
DeregisterRunEvents(e.Items);
}
private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs e) {
RegisterRunEvents(e.Items);
}
private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
else {
suppressUpdates = Content.UpdateOfRunsInProgress;
if (!suppressUpdates) UpdateDataPoints();
}
}
private void Content_Reset(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_Reset), sender, e);
else if (!suppressUpdates) {
UpdateDataPoints();
UpdateAxisLabels();
}
}
private void Content_ColumnNamesChanged(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
else {
UpdateComboBoxes();
}
}
private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (InvokeRequired)
this.Invoke((Action