Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12725


Ignore:
Timestamp:
07/11/15 13:37:32 (9 years ago)
Author:
ascheibe
Message:

#2270 and #2354: merged r12173, r12458, r12077, r12599, r12613, r12112, r12116, r12117, r12131, r12631, r12672, r12684, r12690, r12692 into stable

Location:
stable
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/ChartAnalysisView.cs

    r12009 r12725  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using System.Threading;
    2526using System.Threading.Tasks;
    2627using System.Windows.Forms;
     
    5253    private bool valuesAdded = false;
    5354    private bool suppressUpdates = false;
     55    private SemaphoreSlim sem = new SemaphoreSlim(1, 1);
    5456
    5557    public ChartAnalysisView() {
     
    108110
    109111    void Content_RowsChanged(object sender, EventArgs e) {
    110       RebuildDataTableAsync();
     112      if (suppressUpdates) return;
     113      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e);
     114      else {
     115        RebuildDataTableAsync();
     116      }
    111117    }
    112118
    113119    void Content_ColumnsChanged(object sender, EventArgs e) {
    114       RebuildDataTableAsync();
     120      if (suppressUpdates) return;
     121      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
     122      else {
     123        UpdateDataTableComboBox();
     124        RebuildDataTableAsync();
     125      }
    115126    }
    116127
    117128    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    118       UpdateComboboxes();
    119       RebuildDataTableAsync();
     129      if (suppressUpdates) return;
     130      if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e);
     131      else {
     132        UpdateComboboxes();
     133        RebuildDataTableAsync();
     134      }
    120135    }
    121136
    122137    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    123       suppressUpdates = Content.UpdateOfRunsInProgress;
    124 
    125       if (!suppressUpdates && !valuesAdded) {
    126         RebuildDataTableAsync();
    127       }
    128       if (valuesAdded) {
    129         valuesAdded = false;
     138      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_UpdateOfRunsInProgressChanged, sender, e);
     139      else {
     140        suppressUpdates = Content.UpdateOfRunsInProgress;
     141
     142        if (!suppressUpdates && !valuesAdded) {
     143          UpdateDataTableComboBox();
     144          RebuildDataTableAsync();
     145        }
     146        if (valuesAdded) {
     147          valuesAdded = false;
     148        }
    130149      }
    131150    }
     
    149168
    150169    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     170      if (suppressUpdates) return;
    151171      RebuildDataTableAsync();
    152172    }
     
    246266
    247267    private void RebuildDataTableAsync() {
    248       progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
    249 
    250268      string resultName = (string)dataTableComboBox.SelectedItem;
     269      if (string.IsNullOrEmpty(resultName)) return;
     270
    251271      string rowName = (string)dataRowComboBox.SelectedItem;
    252272
    253       var task = Task.Factory.StartNew(() => RebuildDataTable(resultName, rowName));
     273      var task = Task.Factory.StartNew(() => {
     274        sem.Wait();
     275        progress = MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(this, "Calculating values...");
     276        RebuildDataTable(resultName, rowName);
     277      });
    254278
    255279      task.ContinueWith((t) => {
    256280        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    257281        ErrorHandling.ShowErrorDialog("An error occured while calculating values. ", t.Exception);
     282        sem.Release();
    258283      }, TaskContinuationOptions.OnlyOnFaulted);
    259284
    260285      task.ContinueWith((t) => {
    261286        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     287        sem.Release();
    262288      }, TaskContinuationOptions.OnlyOnRanToCompletion);
    263289    }
     
    289315        double percentile25 = values.Percentile(0.25);
    290316        double percentile75 = values.Percentile(0.75);
    291         double lowerAvg = values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average();
    292         double upperAvg = values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average();
    293         double firstAvg = values.Take((int)(values.Count() * 0.25)).Average();
    294         double lastAvg = values.Skip((int)(values.Count() * 0.75)).Average();
     317        double lowerAvg = values.Count() > 4 ? values.OrderBy(x => x).Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     318        double upperAvg = values.Count() > 4 ? values.OrderByDescending(x => x).Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     319        double firstAvg = values.Count() > 4 ? values.Take((int)(values.Count() * 0.25)).Average() : double.NaN;
     320        double lastAvg = values.Count() > 4 ? values.Skip((int)(values.Count() * 0.75)).Average() : double.NaN;
    295321        double slope, intercept, r;
    296322        llsFitting.Calculate(values, out slope, out intercept);
  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/CorrelationView.cs

    r12199 r12725  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Collections;
    2526using HeuristicLab.Core.Views;
    2627using HeuristicLab.Data;
     
    8182      Content.ColumnsChanged += Content_ColumnsChanged;
    8283      Content.RowsChanged += Content_RowsChanged;
    83       Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     84      Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    8485      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
    8586    }
     
    8990      Content.ColumnsChanged -= Content_ColumnsChanged;
    9091      Content.RowsChanged -= Content_RowsChanged;
    91       Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     92      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    9293      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    9394    }
    9495
    9596    void Content_RowsChanged(object sender, EventArgs e) {
    96       UpdateUI();
     97      if (suppressUpdates) return;
     98      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e);
     99      else {
     100        UpdateUI();
     101      }
    97102    }
    98103
    99104    void Content_ColumnsChanged(object sender, EventArgs e) {
    100       UpdateUI();
    101     }
    102 
    103     private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
    104       UpdateUI();
     105      if (suppressUpdates) return;
     106      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
     107      else {
     108        UpdateUI();
     109      }
     110    }
     111
     112    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     113      if (suppressUpdates) return;
     114      if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e);
     115      else {
     116        UpdateUI();
     117      }
    105118    }
    106119
    107120    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    108       suppressUpdates = Content.UpdateOfRunsInProgress;
    109       UpdateUI();
     121      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_UpdateOfRunsInProgressChanged, sender, e);
     122      else {
     123        suppressUpdates = Content.UpdateOfRunsInProgress;
     124        UpdateUI();
     125      }
    110126    }
    111127    #endregion
    112128
    113129    private void UpdateUI() {
    114       if (!suppressUpdates) {
    115         RebuildCorrelationTable();
    116       }
     130      RebuildCorrelationTable();
    117131    }
    118132
  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/SampleSizeInfluenceView.cs

    r12009 r12725  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Windows.Forms;
     
    3334using HeuristicLab.Optimization;
    3435using HeuristicLab.PluginInfrastructure;
     36using ViewEventArgs = System.Windows.Forms.DataVisualization.Charting.ViewEventArgs;
    3537
    3638namespace HeuristicLab.Analysis.Statistics.Views {
     
    4143    private const string BoxPlotSeriesName = "BoxPlotSeries";
    4244    private const string BoxPlotChartAreaName = "BoxPlotChartArea";
    43     private const string delimitor = ";";
    44 
    45     private bool suppressUpdates = false;
     45    private const string delimiter = ";";
     46
     47    private bool suppressUpdates;
    4648    private string yAxisValue;
    4749    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
     
    6668    }
    6769    public IStringConvertibleMatrix Matrix {
    68       get { return this.Content; }
     70      get { return Content; }
    6971    }
    7072
     
    7274    protected override void RegisterContentEvents() {
    7375      base.RegisterContentEvents();
    74       Content.Reset += new EventHandler(Content_Reset);
    75       Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
    76       Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    77       Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    78       Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    79       Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
    80       Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
     76      Content.ColumnNamesChanged += Content_ColumnNamesChanged;
     77      Content.ItemsAdded += Content_ItemsAdded;
     78      Content.ItemsRemoved += Content_ItemsRemoved;
     79      Content.CollectionReset += Content_CollectionReset;
     80      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
     81      Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
    8182      RegisterRunEvents(Content);
    8283    }
    8384    protected override void DeregisterContentEvents() {
    8485      base.DeregisterContentEvents();
    85       Content.Reset -= new EventHandler(Content_Reset);
    86       Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    87       Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    88       Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    89       Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    90       Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
    91       Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
     86      Content.ColumnNamesChanged -= Content_ColumnNamesChanged;
     87      Content.ItemsAdded -= Content_ItemsAdded;
     88      Content.ItemsRemoved -= Content_ItemsRemoved;
     89      Content.CollectionReset -= Content_CollectionReset;
     90      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
     91      Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
    9292      DeregisterRunEvents(Content);
    9393    }
     
    142142      DeregisterRunEvents(e.OldItems);
    143143      RegisterRunEvents(e.Items);
    144       UpdateAll();
     144      if (!suppressUpdates) UpdateAll();
    145145    }
    146146    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    147147      DeregisterRunEvents(e.Items);
    148       UpdateComboBoxes();
     148      if (!suppressUpdates) UpdateComboBoxes();
    149149    }
    150150    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    151151      RegisterRunEvents(e.Items);
    152       UpdateComboBoxes();
     152      if (!suppressUpdates) UpdateComboBoxes();
    153153    }
    154154    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
     
    157157      else {
    158158        suppressUpdates = Content.UpdateOfRunsInProgress;
    159         if (!suppressUpdates) UpdateDataPoints();
    160       }
    161     }
    162 
    163     private void Content_Reset(object sender, EventArgs e) {
    164       if (InvokeRequired)
    165         Invoke(new EventHandler(Content_Reset), sender, e);
    166       else {
    167         this.categoricalMapping.Clear();
    168         UpdateDataPoints();
    169         UpdateAxisLabels();
     159        if (!suppressUpdates) UpdateAll();
    170160      }
    171161    }
     
    174164        Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
    175165      else {
    176         UpdateComboBoxes();
     166        if (!suppressUpdates) UpdateComboBoxes();
    177167      }
    178168    }
    179169    private void run_Changed(object sender, EventArgs e) {
    180170      if (InvokeRequired)
    181         this.Invoke(new EventHandler(run_Changed), sender, e);
    182       else if (!suppressUpdates) {
    183         UpdateDataPoints();
    184       }
     171        Invoke(new EventHandler(run_Changed), sender, e);
     172      else if (!suppressUpdates) UpdateDataPoints();
    185173    }
    186174
     
    188176      if (InvokeRequired)
    189177        Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
    190       else UpdateCaption();
     178      else if (!suppressUpdates) UpdateCaption();
    191179    }
    192180    #endregion
     
    199187
    200188    private void UpdateAll() {
    201       this.categoricalMapping.Clear();
     189      categoricalMapping.Clear();
    202190      UpdateComboBoxes();
    203191      UpdateDataPoints();
     
    210198
    211199    private void UpdateSampleSizes(bool forceUpdate = false) {
    212       string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
     200      string selectedYAxis = (string)yAxisComboBox.SelectedItem;
    213201
    214202      if (selectedYAxis != null && (xAxisTextBox.Text.Trim() == string.Empty || forceUpdate)) {
     
    224212        if (values.Any()) {
    225213          if (hypergeometricCheckBox.Checked) {
    226             xAxisTextBox.Text += ((int)(values.Count() / 16)) + delimitor + " ";
    227             xAxisTextBox.Text += ((int)(values.Count() / 8)) + delimitor + " ";
    228             xAxisTextBox.Text += (int)(values.Count() / 4);
     214            xAxisTextBox.Text += values.Count() / 16 + delimiter + " ";
     215            xAxisTextBox.Text += values.Count() / 8 + delimiter + " ";
     216            xAxisTextBox.Text += values.Count() / 4;
    229217          } else {
    230             xAxisTextBox.Text += ((int)(values.Count() / 4)) + delimitor + " ";
    231             xAxisTextBox.Text += ((int)(values.Count() / 2)) + delimitor + " ";
    232             xAxisTextBox.Text += ((int)(values.Count() / 4 * 3)) + delimitor + " ";
    233             xAxisTextBox.Text += (int)(values.Count());
     218            xAxisTextBox.Text += values.Count() / 4 + delimiter + " ";
     219            xAxisTextBox.Text += values.Count() / 2 + delimiter + " ";
     220            xAxisTextBox.Text += values.Count() / 4 * 3 + delimiter + " ";
     221            xAxisTextBox.Text += values.Count();
    234222          }
    235223        }
     
    238226
    239227    private void UpdateComboBoxes() {
    240       string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
    241       this.xAxisTextBox.Text = string.Empty;
    242       this.yAxisComboBox.Items.Clear();
    243       if (Content != null) {
    244         string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
    245         UpdateSampleSizes();
    246         this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
    247         this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
    248 
    249         if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) {
    250           yAxisComboBox.SelectedItem = selectedYAxis;
    251           UpdateDataPoints();
     228      if (InvokeRequired) {
     229        Invoke((Action)UpdateComboBoxes);
     230      } else {
     231        string selectedYAxis = (string)yAxisComboBox.SelectedItem;
     232        xAxisTextBox.Text = string.Empty;
     233        yAxisComboBox.Items.Clear();
     234        if (Content != null) {
     235          string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
     236          UpdateSampleSizes();
     237          yAxisComboBox.Items.AddRange(additionalAxisDimension);
     238          yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     239
     240          if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) {
     241            yAxisComboBox.SelectedItem = selectedYAxis;
     242            UpdateDataPoints();
     243          }
    252244        }
    253245      }
     
    255247
    256248    private void UpdateDataPoints() {
    257       this.chart.Series.Clear();
    258       this.seriesCache.Clear();
     249      chart.Series.Clear();
     250      seriesCache.Clear();
    259251      if (Content != null) {
    260252        var usableRuns = Content.Where(r => r.Visible).ToList();
     
    267259        }
    268260
    269         foreach (Series s in this.seriesCache.Values)
    270           this.chart.Series.Add(s);
     261        foreach (Series s in seriesCache.Values)
     262          chart.Series.Add(s);
    271263
    272264        UpdateStatistics();
    273265        if (seriesCache.Count > 0) {
    274266          Series boxPlotSeries = CreateBoxPlotSeries();
    275           this.chart.Series.Add(boxPlotSeries);
     267          chart.Series.Add(boxPlotSeries);
    276268        }
    277269
     
    328320
    329321      if (!yAxisComboBox.DroppedDown)
    330         this.yAxisValue = (string)yAxisComboBox.SelectedItem;
    331 
    332       List<double?> yValue = usableRuns.Select(x => GetValue(x, this.yAxisValue)).ToList();
     322        yAxisValue = (string)yAxisComboBox.SelectedItem;
     323
     324      List<double?> yValue = usableRuns.Select(x => GetValue(x, yAxisValue)).ToList();
    333325      if (yValue.Any(x => !x.HasValue)) return;
    334326
     
    338330
    339331    private List<int> ParseGroupSizesFromText(string groupsText, bool verbose = true) {
    340       string[] gs = groupsText.Split(delimitor.ToCharArray());
     332      string[] gs = groupsText.Split(delimiter.ToCharArray());
    341333      List<int> vals = new List<int>();
    342334
     
    352344          catch (Exception ex) {
    353345            if (verbose) {
    354               ErrorHandling.ShowErrorDialog("Can't parse group sizes. Please only use numbers seperated by a " + delimitor + ". ", ex);
     346              ErrorHandling.ShowErrorDialog("Can't parse group sizes. Please only use numbers seperated by a " + delimiter + ". ", ex);
    355347            }
    356348          }
     
    384376      }
    385377      matrix.ColumnNames = columnNames;
    386       matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." };
     378      matrix.RowNames = new[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." };
    387379
    388380      for (int i = 0; i < seriesCache.Count; i++) {
     
    415407      boxPlotSeries["BoxPlotShowUnusualValues"] = "true";
    416408      boxPlotSeries["PointWidth"] = "0.4";
    417       boxPlotSeries.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.VerticalCenter;
    418       boxPlotSeries.BackSecondaryColor = System.Drawing.Color.FromArgb(130, 224, 64, 10);
    419       boxPlotSeries.BorderColor = System.Drawing.Color.FromArgb(64, 64, 64);
    420       boxPlotSeries.Color = System.Drawing.Color.FromArgb(224, 64, 10);
     409      boxPlotSeries.BackGradientStyle = GradientStyle.VerticalCenter;
     410      boxPlotSeries.BackSecondaryColor = Color.FromArgb(130, 224, 64, 10);
     411      boxPlotSeries.BorderColor = Color.FromArgb(64, 64, 64);
     412      boxPlotSeries.Color = Color.FromArgb(224, 64, 10);
    421413
    422414      return boxPlotSeries;
     
    429421
    430422      if (!yAxisComboBox.DroppedDown)
    431         this.yAxisValue = (string)yAxisComboBox.SelectedItem;
     423        yAxisValue = (string)yAxisComboBox.SelectedItem;
    432424
    433425      xValue = idx;
    434       yValue = GetValue(run, this.yAxisValue);
     426      yValue = GetValue(run, yAxisValue);
    435427
    436428      if (yValue.HasValue) {
    437         if (!this.seriesCache.ContainsKey(xValue))
     429        if (!seriesCache.ContainsKey(xValue))
    438430          seriesCache[xValue] = new Series(xValue.ToString());
    439431
     
    454446        AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
    455447        return GetValue(run, axisDimension);
    456       } else {
    457         int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
    458         IItem value = Content.GetValue(run, columnIndex);
    459         if (value == null)
    460           return null;
    461 
    462         DoubleValue doubleValue = value as DoubleValue;
    463         IntValue intValue = value as IntValue;
    464         TimeSpanValue timeSpanValue = value as TimeSpanValue;
    465         double? ret = null;
    466         if (doubleValue != null) {
    467           if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
    468             ret = doubleValue.Value;
    469         } else if (intValue != null)
    470           ret = intValue.Value;
    471         else if (timeSpanValue != null) {
    472           ret = timeSpanValue.Value.TotalSeconds;
    473         } else
    474           ret = GetCategoricalValue(columnIndex, value.ToString());
    475 
    476         return ret;
    477       }
     448      }
     449      int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
     450      IItem value = Content.GetValue(run, columnIndex);
     451      if (value == null)
     452        return null;
     453
     454      DoubleValue doubleValue = value as DoubleValue;
     455      IntValue intValue = value as IntValue;
     456      TimeSpanValue timeSpanValue = value as TimeSpanValue;
     457      double? ret = null;
     458      if (doubleValue != null) {
     459        if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
     460          ret = doubleValue.Value;
     461      } else if (intValue != null)
     462        ret = intValue.Value;
     463      else if (timeSpanValue != null) {
     464        ret = timeSpanValue.Value.TotalSeconds;
     465      } else
     466        ret = GetCategoricalValue(columnIndex, value.ToString());
     467
     468      return ret;
    478469    }
    479470    private double GetCategoricalValue(int dimension, string value) {
    480       if (!this.categoricalMapping.ContainsKey(dimension)) {
    481         this.categoricalMapping[dimension] = new Dictionary<object, double>();
     471      if (!categoricalMapping.ContainsKey(dimension)) {
     472        categoricalMapping[dimension] = new Dictionary<object, double>();
    482473        var orderedCategories = Content.Where(r => r.Visible && Content.GetValue(r, dimension) != null).Select(r => Content.GetValue(r, dimension).ToString())
    483474                                          .Distinct().OrderBy(x => x, new NaturalStringComparer());
    484475        int count = 1;
    485476        foreach (var category in orderedCategories) {
    486           this.categoricalMapping[dimension].Add(category, count);
     477          categoricalMapping[dimension].Add(category, count);
    487478          count++;
    488479        }
    489480      }
    490       return this.categoricalMapping[dimension][value];
     481      return categoricalMapping[dimension][value];
    491482    }
    492483    private double GetValue(IRun run, AxisDimension axisDimension) {
     
    498489          }
    499490        default: {
    500             throw new ArgumentException("No handling strategy for " + axisDimension.ToString() + " is defined.");
     491            throw new ArgumentException("No handling strategy for " + axisDimension + " is defined.");
    501492          }
    502493      }
     
    507498    #region GUI events
    508499    private void UpdateNoRunsVisibleLabel() {
    509       if (this.chart.Series.Count > 0) {
     500      if (chart.Series.Count > 0) {
    510501        noRunsLabel.Visible = false;
    511502        showStatisticsCheckBox.Enabled = true;
     
    532523    }
    533524    private void UpdateAxisLabels() {
    534       Axis xAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisX;
    535       Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;
     525      Axis xAxis = chart.ChartAreas[BoxPlotChartAreaName].AxisX;
     526      Axis yAxis = chart.ChartAreas[BoxPlotChartAreaName].AxisY;
    536527      int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
    537528
     
    544535    }
    545536
    546     private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
    547       this.UpdateAxisLabels();
     537    private void chart_AxisViewChanged(object sender, ViewEventArgs e) {
     538      UpdateAxisLabels();
    548539    }
    549540
     
    566557        }
    567558      } else if (dimension > 0 && Content.GetValue(0, dimension) is TimeSpanValue) {
    568         this.chart.ChartAreas[0].RecalculateAxesScale();
    569         Axis correspondingAxis = this.chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault();
     559        chart.ChartAreas[0].RecalculateAxesScale();
     560        Axis correspondingAxis = chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault();
    570561        if (correspondingAxis == null)
    571562          correspondingAxis = axis;
    572563        for (double i = correspondingAxis.Minimum; i <= correspondingAxis.Maximum; i += correspondingAxis.LabelStyle.Interval) {
    573564          TimeSpan time = TimeSpan.FromSeconds(i);
    574           string x = string.Format("{0:00}:{1:00}:{2:00}", (int)time.Hours, time.Minutes, time.Seconds);
     565          string x = string.Format("{0:00}:{1:00}:{2:00}", time.Hours, time.Minutes, time.Seconds);
    575566          axis.CustomLabels.Add(i - correspondingAxis.LabelStyle.Interval / 2, i + correspondingAxis.LabelStyle.Interval / 2, x);
    576567        }
     
    595586      string newTooltipText = string.Empty;
    596587      string oldTooltipText;
    597       HitTestResult h = this.chart.HitTest(e.X, e.Y);
     588      HitTestResult h = chart.HitTest(e.X, e.Y);
    598589      if (h.ChartElementType == ChartElementType.AxisLabels) {
    599590        newTooltipText = ((CustomLabel)h.Object).ToolTip;
    600591      }
    601592
    602       oldTooltipText = this.tooltip.GetToolTip(chart);
     593      oldTooltipText = tooltip.GetToolTip(chart);
    603594      if (newTooltipText != oldTooltipText)
    604         this.tooltip.SetToolTip(chart, newTooltipText);
     595        tooltip.SetToolTip(chart, newTooltipText);
    605596    }
    606597    #endregion
     
    623614          string newVals = "";
    624615          foreach (int v in values) {
    625             newVals += v + delimitor + " ";
     616            newVals += v + delimiter + " ";
    626617          }
    627618          xAxisTextBox.Text = newVals;
  • stable/HeuristicLab.Analysis.Statistics.Views/3.3/StatisticalTestsView.cs

    r12009 r12725  
    2727using HeuristicLab.Collections;
    2828using HeuristicLab.Common;
     29using HeuristicLab.Common.Resources;
    2930using HeuristicLab.Core.Views;
    3031using HeuristicLab.Data;
     
    4041    private const int requiredSampleSize = 5;
    4142    private double[][] data;
     43    private bool suppressUpdates;
     44    private bool initializing;
    4245
    4346    public double SignificanceLevel {
     
    7679
    7780      if (Content != null) {
    78         UpdateResultComboBox();
    79         UpdateGroupsComboBox();
    80         RebuildDataTable();
     81        UpdateUI();
     82      } else {
     83        ResetUI();
    8184      }
    8285      UpdateCaption();
     86    }
     87
     88    private void UpdateUI() {
     89      initializing = true;
     90      UpdateResultComboBox();
     91      UpdateGroupsComboBox();
     92      RebuildDataTable();
     93      FillCompComboBox();
     94      ResetUI();
     95      CalculateValues();
     96      initializing = false;
    8397    }
    8498
     
    92106      Content.ColumnsChanged += Content_ColumnsChanged;
    93107      Content.RowsChanged += Content_RowsChanged;
    94       Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     108      Content.CollectionReset += Content_CollectionReset;
    95109      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
    96110    }
     
    100114      Content.ColumnsChanged -= Content_ColumnsChanged;
    101115      Content.RowsChanged -= Content_RowsChanged;
    102       Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     116      Content.CollectionReset -= Content_CollectionReset;
    103117      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
    104118    }
    105119
    106120    void Content_RowsChanged(object sender, EventArgs e) {
     121      if (suppressUpdates) return;
     122      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_RowsChanged, sender, e);
     123      else {
     124        UpdateUI();
     125      }
     126    }
     127
     128    void Content_ColumnsChanged(object sender, EventArgs e) {
     129      if (suppressUpdates) return;
     130      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_ColumnsChanged, sender, e);
     131      else {
     132        UpdateUI();
     133      }
     134    }
     135
     136    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     137      if (suppressUpdates) return;
     138      if (InvokeRequired) Invoke((Action<object, CollectionItemsChangedEventArgs<IRun>>)Content_CollectionReset, sender, e);
     139      else {
     140        UpdateUI();
     141      }
     142    }
     143
     144    void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
     145      if (InvokeRequired) Invoke((Action<object, EventArgs>)Content_UpdateOfRunsInProgressChanged, sender, e);
     146      else {
     147        suppressUpdates = Content.UpdateOfRunsInProgress;
     148        if (!suppressUpdates) UpdateUI();
     149      }
     150    }
     151
     152    private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) {
     153      RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();
     154      boxplotView.Content = Content;
     155      boxplotView.SetXAxis(groupComboBox.SelectedItem.ToString());
     156      boxplotView.SetYAxis(resultComboBox.SelectedItem.ToString());
     157
     158      boxplotView.Show();
     159    }
     160
     161    private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) {
     162      if (initializing || suppressUpdates) return;
     163      string curItem = (string)groupCompComboBox.SelectedItem;
     164      CalculatePairwise(curItem);
     165    }
     166
     167    private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {
     168      if (initializing || suppressUpdates) return;
    107169      RebuildDataTable();
    108     }
    109 
    110     void Content_ColumnsChanged(object sender, EventArgs e) {
     170      ResetUI();
     171      CalculateValues();
     172    }
     173
     174    private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) {
     175      if (initializing || suppressUpdates) return;
    111176      RebuildDataTable();
    112     }
    113 
    114     private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
    115       RebuildDataTable();
    116     }
    117 
    118     void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
    119       if (!Content.UpdateOfRunsInProgress) {
    120         RebuildDataTable();
    121       }
     177      FillCompComboBox();
     178      ResetUI();
     179      CalculateValues();
    122180    }
    123181    #endregion
    124182
    125183    private void UpdateGroupsComboBox() {
     184      string selectedItem = (string)groupComboBox.SelectedItem;
     185
    126186      groupComboBox.Items.Clear();
    127 
    128187      var parameters = (from run in Content
    129188                        where run.Visible
     
    154213        }
    155214
    156         if (possibleIndizes.Count > 0) {
     215        if (selectedItem != null && groupComboBox.Items.Contains(selectedItem)) {
     216          groupComboBox.SelectedItem = selectedItem;
     217        } else if (possibleIndizes.Count > 0) {
    157218          groupComboBox.SelectedItem = groupComboBox.Items[possibleIndizes.First()];
    158         } else {
    159           groupComboBox.SelectedItem = groupComboBox.Items[0];
    160219        }
    161220      }
     
    169228
    170229    private void UpdateResultComboBox() {
     230      string selectedItem = (string)resultComboBox.SelectedItem;
     231
    171232      resultComboBox.Items.Clear();
    172233      var results = (from run in Content
     
    177238
    178239      resultComboBox.Items.AddRange(results);
    179       if (resultComboBox.Items.Count > 0) resultComboBox.SelectedItem = resultComboBox.Items[0];
     240
     241      if (selectedItem != null && resultComboBox.Items.Contains(selectedItem)) {
     242        resultComboBox.SelectedItem = selectedItem;
     243      } else if (resultComboBox.Items.Count > 0) {
     244        resultComboBox.SelectedItem = resultComboBox.Items[0];
     245      }
    180246    }
    181247
    182248    private void FillCompComboBox() {
     249      string selectedItem = (string)groupCompComboBox.SelectedItem;
    183250      string parameterName = (string)groupComboBox.SelectedItem;
    184251      if (parameterName != null) {
     
    189256          groupCompComboBox.Items.Clear();
    190257          columnNames.ForEach(x => groupCompComboBox.Items.Add(x));
    191           if (groupCompComboBox.Items.Count > 0) groupCompComboBox.SelectedItem = groupCompComboBox.Items[0];
     258          if (selectedItem != null && groupCompComboBox.Items.Contains(selectedItem)) {
     259            groupCompComboBox.SelectedItem = selectedItem;
     260          } else if (groupCompComboBox.Items.Count > 0) {
     261            groupCompComboBox.SelectedItem = groupCompComboBox.Items[0];
     262          }
    192263        }
    193264      }
     
    259330    }
    260331
    261     private void resultComboBox_SelectedValueChanged(object sender, EventArgs e) {
    262       RebuildDataTable();
    263       ResetUI();
    264       CalculateValues();
    265     }
    266 
    267     private void groupComboBox_SelectedValueChanged(object sender, EventArgs e) {
    268       RebuildDataTable();
    269       FillCompComboBox();
    270       ResetUI();
    271       CalculateValues();
    272     }
    273 
    274332    private bool VerifyDataLength(bool showMessage) {
    275333      if (data == null || data.Length == 0)
     
    277335
    278336      //alglib needs at least 5 samples for computation
    279       if (data.Any(x => x.Length <= requiredSampleSize)) {
     337      if (data.Any(x => x.Length < requiredSampleSize)) {
    280338        if (showMessage)
    281339          MessageBox.Show(this, "You need at least " + requiredSampleSize
     
    291349        return;
    292350
    293       if (data != null) {
    294         MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>()
     351      if (data != null && data.All(x => x != null)) {
     352        MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>()
    295353          .AddOperationProgressToView(this, "Calculating...");
    296354
     
    305363      CalculatePairwiseTest(groupName);
    306364
    307       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
     365      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(this);
    308366    }
    309367
    310368    private void CalculatePairwise(string groupName) {
     369      if (groupName == null) return;
    311370      if (!VerifyDataLength(false))
    312371        return;
    313372
    314       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
     373      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().AddOperationProgressToView(pairwiseTestGroupBox, "Calculating...");
    315374      Task.Factory.StartNew(() => CalculatePairwiseAsync(groupName));
    316375    }
     
    319378      CalculatePairwiseTest(groupName);
    320379
    321       MainFormManager.GetMainForm<HeuristicLab.MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
     380      MainFormManager.GetMainForm<MainForm.WindowsForms.MainForm>().RemoveOperationProgressFromView(pairwiseTestGroupBox);
    322381    }
    323382
    324383    private void CalculateAllGroupsTest() {
    325384      double pval = KruskalWallisTest.Test(data);
    326       pValTextBox.Text = pval.ToString();
    327       if (pval < significanceLevel) {
    328         this.Invoke(new Action(() => {
    329           groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     385      DisplayAllGroupsTextResults(pval);
     386    }
     387
     388    private void DisplayAllGroupsTextResults(double pval) {
     389      if (InvokeRequired) {
     390        Invoke((Action<double>)DisplayAllGroupsTextResults, pval);
     391      } else {
     392        pValTextBox.Text = pval.ToString();
     393        if (pval < significanceLevel) {
     394          groupCompLabel.Image = VSImageLibrary.Default;
    330395          groupComTextLabel.Text = "There are groups with different distributions";
    331         }));
    332       } else {
    333         this.Invoke(new Action(() => {
    334           groupCompLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     396        } else {
     397          groupCompLabel.Image = VSImageLibrary.Warning;
    335398          groupComTextLabel.Text = "Groups have an equal distribution";
    336         }));
     399        }
    337400      }
    338401    }
     
    343406      DoubleMatrix pValsMatrix = new DoubleMatrix(1, stringConvertibleMatrixView.Content.Columns);
    344407      pValsMatrix.ColumnNames = stringConvertibleMatrixView.Content.ColumnNames;
    345       pValsMatrix.RowNames = new string[] { "p-Value" };
     408      pValsMatrix.RowNames = new[] { "p-Value" };
    346409
    347410      for (int i = 0; i < data.Length; i++) {
     
    353416      // p-value is below significance level and thus the null hypothesis (data is normally distributed) is rejected
    354417      if (res.Any(x => x < significanceLevel)) {
    355         this.Invoke(new Action(() => {
    356           normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     418        Invoke(new Action(() => {
     419          normalityLabel.Image = VSImageLibrary.Warning;
    357420          normalityTextLabel.Text = "Some groups may not be normally distributed";
    358421        }));
    359422      } else {
    360         this.Invoke(new Action(() => {
    361           normalityLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     423        Invoke(new Action(() => {
     424          normalityLabel.Image = VSImageLibrary.Default;
    362425          normalityTextLabel.Text = "All sample data is normally distributed";
    363426        }));
    364427      }
    365428
    366       this.Invoke(new Action(() => {
     429      Invoke(new Action(() => {
    367430        normalityStringConvertibleMatrixView.Content = pValsMatrix;
    368431        normalityStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    372435    private void ShowPairwiseResult(int nrOfEqualDistributions) {
    373436      double ratio = ((double)nrOfEqualDistributions) / (data.Length - 1) * 100.0;
    374       equalDistsTextBox.Text = ratio.ToString() + " %";
     437      equalDistsTextBox.Text = ratio + " %";
    375438
    376439      if (nrOfEqualDistributions == 0) {
    377         this.Invoke(new Action(() => {
    378           pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Default;
     440        Invoke(new Action(() => {
     441          pairwiseLabel.Image = VSImageLibrary.Default;
    379442          pairwiseTextLabel.Text = "All groups have different distributions";
    380443        }));
    381444      } else {
    382         this.Invoke(new Action(() => {
    383           pairwiseLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Warning;
     445        Invoke(new Action(() => {
     446          pairwiseLabel.Image = VSImageLibrary.Warning;
    384447          pairwiseTextLabel.Text = "Some groups have equal distributions";
    385448        }));
     
    394457      double[][] newData = FilterDataForPairwiseTest(colIndex);
    395458
    396       var rowNames = new string[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U",
     459      var rowNames = new[] { "p-Value of Mann-Whitney U", "Adjusted p-Value of Mann-Whitney U",
    397460            "p-Value of T-Test", "Adjusted p-Value of T-Test", "Cohen's d", "Hedges' g" };
    398461
     
    433496      }
    434497
    435       this.Invoke(new Action(() => {
     498      Invoke(new Action(() => {
    436499        pairwiseStringConvertibleMatrixView.Content = pValsMatrix;
    437500        pairwiseStringConvertibleMatrixView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
     
    469532      return newData;
    470533    }
    471 
    472     private void openBoxPlotToolStripMenuItem_Click(object sender, EventArgs e) {
    473       RunCollectionBoxPlotView boxplotView = new RunCollectionBoxPlotView();
    474       boxplotView.Content = Content;
    475       boxplotView.SetXAxis(groupComboBox.SelectedItem.ToString());
    476       boxplotView.SetYAxis(resultComboBox.SelectedItem.ToString());
    477 
    478       boxplotView.Show();
    479     }
    480 
    481     private void groupCompComboBox_SelectedValueChanged(object sender, EventArgs e) {
    482       string curItem = (string)groupCompComboBox.SelectedItem;
    483       CalculatePairwise(curItem);
    484     }
    485534  }
    486535}
  • stable/HeuristicLab.Analysis.Views

  • stable/HeuristicLab.Analysis.Views/3.3/HistogramControl.Designer.cs

    r12154 r12725  
    4848    private void InitializeComponent() {
    4949      this.components = new System.ComponentModel.Container();
    50       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    51       System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    52       System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
     50      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
     51      System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
     52      System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
    5353      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    5454      this.binsNumericUpDown = new System.Windows.Forms.NumericUpDown();
     
    5757      this.label2 = new System.Windows.Forms.Label();
    5858      this.bandwidthNumericUpDown = new System.Windows.Forms.NumericUpDown();
     59      this.noDataLabel = new System.Windows.Forms.Label();
    5960      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    6061      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).BeginInit();
     
    6768            | System.Windows.Forms.AnchorStyles.Left)
    6869            | System.Windows.Forms.AnchorStyles.Right)));
    69       chartArea1.Name = "ChartArea1";
    70       this.chart.ChartAreas.Add(chartArea1);
    71       legend1.Alignment = System.Drawing.StringAlignment.Center;
    72       legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    73       legend1.Name = "Default";
    74       this.chart.Legends.Add(legend1);
     70      chartArea2.Name = "ChartArea1";
     71      this.chart.ChartAreas.Add(chartArea2);
     72      legend2.Alignment = System.Drawing.StringAlignment.Center;
     73      legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
     74      legend2.Name = "Default";
     75      this.chart.Legends.Add(legend2);
    7576      this.chart.Location = new System.Drawing.Point(0, 27);
    7677      this.chart.Name = "chart";
    77       series1.ChartArea = "ChartArea1";
    78       series1.Legend = "Default";
    79       series1.Name = "Series1";
    80       this.chart.Series.Add(series1);
     78      series2.ChartArea = "ChartArea1";
     79      series2.Legend = "Default";
     80      series2.Name = "Series1";
     81      this.chart.Series.Add(series2);
    8182      this.chart.Size = new System.Drawing.Size(465, 336);
    8283      this.chart.TabIndex = 0;
     
    159160      this.bandwidthNumericUpDown.ValueChanged += new System.EventHandler(this.bandwidthNumericUpDown_ValueChanged);
    160161      //
     162      // noDataLabel
     163      //
     164      this.noDataLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     165      this.noDataLabel.AutoSize = true;
     166      this.noDataLabel.Location = new System.Drawing.Point(163, 175);
     167      this.noDataLabel.Name = "noDataLabel";
     168      this.noDataLabel.Size = new System.Drawing.Size(139, 13);
     169      this.noDataLabel.TabIndex = 22;
     170      this.noDataLabel.Text = "No data could be displayed.";
     171      //
    161172      // HistogramControl
    162173      //
    163174      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     175      this.Controls.Add(this.noDataLabel);
    164176      this.Controls.Add(this.label2);
    165177      this.Controls.Add(this.bandwidthNumericUpDown);
     
    186198    private System.Windows.Forms.Label label2;
    187199    private System.Windows.Forms.NumericUpDown bandwidthNumericUpDown;
     200    private System.Windows.Forms.Label noDataLabel;
    188201  }
    189202}
  • stable/HeuristicLab.Analysis.Views/3.3/HistogramControl.cs

    r12154 r12725  
    139139        if (!point.Value.Any()) continue;
    140140
    141         Series histogramSeries = new Series(point.Key);
    142         chart.Series.Add(histogramSeries);
    143141        double minValue = point.Value.Min();
    144142        double maxValue = point.Value.Max();
    145143        double intervalWidth = (maxValue - minValue) / bins;
    146144        if (intervalWidth <= 0) continue;
     145
     146        Series histogramSeries = new Series(point.Key);
     147        chart.Series.Add(histogramSeries);
    147148
    148149        if (!exactCheckBox.Checked) {
     
    167168        overallMax = Math.Max(overallMax, maxValue);
    168169        overallMin = Math.Min(overallMin, minValue);
    169       }
    170 
    171       chart.ApplyPaletteColors();
    172 
    173       int i = 0;
    174       foreach (var point in points) {
    175         if (!point.Value.Any()) continue;
    176 
    177         var histogramSeries = chart.Series[i];
     170
     171        chart.ApplyPaletteColors();
    178172        CalculateDensity(histogramSeries, point.Value, bandwith);
    179 
    180         i++;
    181       }
    182 
     173      }
     174
     175      if (chart.Series.Any()) {
     176        noDataLabel.Visible = false;
     177      } else {
     178        noDataLabel.Visible = true;
     179      }
    183180
    184181      ChartArea chartArea = chart.ChartAreas[0];
  • stable/HeuristicLab.Data.Views

  • stable/HeuristicLab.Data.Views/3.3

  • stable/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r12718 r12725  
    124124    }
    125125
    126     private void UpdateData() {
     126    protected virtual void UpdateData() {
    127127      rowsTextBox.Text = Content.Rows.ToString();
    128128      rowsTextBox.Enabled = true;
  • stable/HeuristicLab.Optimization

  • stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.cs

    r12009 r12725  
    122122      if (InvokeRequired)
    123123        Invoke(new EventHandler(Content_Reset), sender, e);
    124       else {
     124      else if (!suppressUpdates) {
    125125        UpdateDataPoints();
    126126        UpdateAxisLabels();
     
    376376      Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;
    377377      int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
    378       //mkommend: combobox.SelectedIndex could not be used as this changes during hoovering over possible values
     378      //mkommend: combobox.SelectedIndex could not be used as this changes during hovering over possible values
    379379      var xSAxisSelectedIndex = xAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(xAxisValue);
    380380      var ySAxisSelectedIndex = yAxisValue == null ? 0 : xAxisComboBox.Items.IndexOf(yAxisValue);
  • stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs

    r12009 r12725  
    262262
    263263    private void Content_Reset(object sender, EventArgs e) {
     264      if (suppressUpdates) return;
    264265      if (InvokeRequired)
    265266        Invoke(new EventHandler(Content_Reset), sender, e);
  • stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionChartAggregationView.cs

    r12009 r12725  
    2424using System.ComponentModel;
    2525using System.Linq;
    26 using System.Windows.Forms;
    2726using HeuristicLab.Analysis;
    2827using HeuristicLab.Collections;
     
    4140    }
    4241
    43     private int rowNumber = 0;
     42    private int rowNumber;
    4443    private bool suppressUpdates;
    4544    private readonly Dictionary<IRun, IEnumerable<DataRow>> runMapping;
     
    6059    protected override void RegisterContentEvents() {
    6160      base.RegisterContentEvents();
    62       Content.ItemsAdded += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    63       Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    64       Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    65       Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
    66       Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
     61      Content.ItemsAdded += Content_ItemsAdded;
     62      Content.ItemsRemoved += Content_ItemsRemoved;
     63      Content.CollectionReset += Content_CollectionReset;
     64      Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
     65      Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
    6766    }
    6867    protected override void DeregisterContentEvents() {
    69       Content.ItemsAdded -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
    70       Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    71       Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
    72       Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
    73       Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
     68      Content.ItemsAdded -= Content_ItemsAdded;
     69      Content.ItemsRemoved -= Content_ItemsRemoved;
     70      Content.CollectionReset -= Content_CollectionReset;
     71      Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
     72      Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
    7473      base.DeregisterContentEvents();
    7574    }
    7675
    7776    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     77      if (suppressUpdates) return;
    7878      if (InvokeRequired) {
    7979        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
    8080        return;
    8181      }
     82      UpdateDataTableComboBox();
     83      UpdateDataRowComboBox();
    8284      AddRuns(e.Items);
    8385    }
    8486    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     87      if (suppressUpdates) return;
    8588      if (InvokeRequired) {
    8689        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
    8790        return;
    8891      }
     92      UpdateDataTableComboBox();
     93      UpdateDataRowComboBox();
    8994      RemoveRuns(e.Items);
    9095    }
    9196    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     97      if (suppressUpdates) return;
    9298      if (InvokeRequired) {
    9399        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
    94100        return;
    95101      }
     102      UpdateDataTableComboBox();
     103      UpdateDataRowComboBox();
    96104      RemoveRuns(e.OldItems);
    97105      AddRuns(e.Items);
     
    108116      }
    109117      suppressUpdates = Content.UpdateOfRunsInProgress;
    110       if (!suppressUpdates) UpdateRuns(Content);
     118      if (!suppressUpdates) {
     119        UpdateDataTableComboBox();
     120        UpdateDataRowComboBox();
     121        UpdateRuns(Content);
     122      }
    111123    }
    112124
     
    124136        var run = (IRun)sender;
    125137        if (e.PropertyName == "Color" || e.PropertyName == "Visible")
    126           UpdateRuns(new IRun[] { run });
     138          UpdateRuns(new[] { run });
    127139      }
    128140    }
     
    168180
    169181    private void UpdateRuns(IEnumerable<IRun> runs) {
    170       if (suppressUpdates) return;
    171182      foreach (var run in runs) {
    172183        //update color
    173         foreach (var dataRow in runMapping[run]) {
    174           dataRow.VisualProperties.Color = run.Color;
     184        if (!runMapping.ContainsKey(run)) {
     185          runMapping[run] = ExtractDataRowsFromRun(run).ToList();
     186          RegisterRunEvents(run);
     187        } else {
     188          foreach (var dataRow in runMapping[run]) {
     189            dataRow.VisualProperties.Color = run.Color;
     190          }
    175191        }
    176         //update visibility - remove and add all rows to keep the same order as before
    177         combinedDataTable.Rows.Clear();
    178         combinedDataTable.Rows.AddRange(runMapping.Where(mapping => mapping.Key.Visible).SelectMany(mapping => mapping.Value));
    179       }
     192      }
     193      //update visibility - remove and add all rows to keep the same order as before
     194      combinedDataTable.Rows.Clear();
     195      combinedDataTable.Rows.AddRange(runMapping.Where(mapping => mapping.Key.Visible).SelectMany(mapping => mapping.Value));
    180196    }
    181197
    182198    private IEnumerable<DataRow> ExtractDataRowsFromRun(IRun run) {
    183199      var resultName = (string)dataTableComboBox.SelectedItem;
     200      if (string.IsNullOrEmpty(resultName)) yield break;
     201
    184202      var rowName = (string)dataRowComboBox.SelectedItem;
    185203      if (!run.Results.ContainsKey(resultName)) yield break;
     
    199217
    200218    private void UpdateDataTableComboBox() {
     219      string selectedItem = (string)dataTableComboBox.SelectedItem;
     220
    201221      dataTableComboBox.Items.Clear();
    202222      var dataTables = (from run in Content
     
    206226
    207227      dataTableComboBox.Items.AddRange(dataTables);
    208       if (dataTableComboBox.Items.Count > 0) dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
     228      if (selectedItem != null && dataTableComboBox.Items.Contains(selectedItem)) {
     229        dataTableComboBox.SelectedItem = selectedItem;
     230      } else if (dataTableComboBox.Items.Count > 0) {
     231        dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
     232      }
    209233    }
    210234
     
    214238
    215239    private void UpdateDataRowComboBox() {
     240      string selectedItem = (string)dataRowComboBox.SelectedItem;
     241
    216242      dataRowComboBox.Items.Clear();
    217243      var resultName = (string)dataTableComboBox.SelectedItem;
     244      if (resultName == null) return;
     245
    218246      var dataTables = from run in Content
    219247                       where run.Results.ContainsKey(resultName)
     
    225253      dataRowComboBox.Items.AddRange(rowNames);
    226254      dataRowComboBox.Items.Add(AllDataRows);
    227       if (dataRowComboBox.Items.Count > 0) dataRowComboBox.SelectedItem = dataRowComboBox.Items[0];
    228     }
    229 
    230     private void dataTableComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
    231       UpdateDataRowComboBox();
    232     }
    233     private void dataRowComboBox_SelectedIndexChanged(object sender, System.EventArgs e) {
     255      if (selectedItem != null && dataRowComboBox.Items.Contains(selectedItem)) {
     256        dataRowComboBox.SelectedItem = selectedItem;
     257      } else if (dataRowComboBox.Items.Count > 0) {
     258        dataRowComboBox.SelectedItem = dataRowComboBox.Items[0];
     259      }
     260    }
     261
     262    private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     263      UpdateDataRowComboBox();
     264    }
     265    private void dataRowComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     266      if (suppressUpdates) return;
    234267      RebuildCombinedDataTable();
    235268    }
  • stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionTableView.cs

    r12009 r12725  
    5353      base.OnContentChanged();
    5454      if (Content != null) {
    55         runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
    5655        UpdateRowAttributes();
    5756      }
     
    117116    }
    118117
     118    protected override void UpdateData() {
     119      if (suppressUpdates) return;
     120      base.UpdateData();
     121    }
     122
    119123    protected override void UpdateColumnHeaders() {
    120124      HashSet<string> visibleColumnNames = new HashSet<string>(dataGridView.Columns.OfType<DataGridViewColumn>()
     
    145149      else {
    146150        suppressUpdates = Content.UpdateOfRunsInProgress;
    147         if (!suppressUpdates) UpdateRowAttributes();
     151        if (!suppressUpdates) {
     152          UpdateData();
     153          UpdateRowAttributes();
     154        }
    148155      }
    149156    }
     
    171178    protected override void ClearSorting() {
    172179      base.ClearSorting();
    173       runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
    174180      UpdateRowAttributes();
    175181    }
     
    190196        i++;
    191197      }
    192       UpdateRowAttributes();
     198      UpdateRowAttributes(rebuild: false);
    193199      return newSortedIndex;
    194200    }
    195201
    196     private void UpdateRowAttributes() {
     202    private void UpdateRowAttributes(bool rebuild = true) {
     203      if (rebuild) runToRowMapping = Enumerable.Range(0, Content.Count).ToArray();
    197204      int runIndex = 0;
    198205      foreach (IRun run in Content) {
  • stable/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionView.cs

    r12009 r12725  
    4141    private Dictionary<IRun, List<ListViewItem>> itemListViewItemMapping;
    4242    private bool validDragOperation;
     43    private bool suppressUpdates;
    4344
    4445    public new IItemCollection<IRun> Content {
     
    6667      Content.ItemsRemoved -= new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    6768      Content.CollectionReset -= new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     69      if (RunCollection != null)
     70        RunCollection.UpdateOfRunsInProgressChanged -= new EventHandler(RunCollection_UpdateOfRunsInProgressChanged);
    6871      foreach (IRun run in itemListViewItemMapping.Keys) {
    6972        DeregisterItemEvents(run);
     
    7679      Content.ItemsRemoved += new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
    7780      Content.CollectionReset += new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     81      if (RunCollection != null)
     82        RunCollection.UpdateOfRunsInProgressChanged += new EventHandler(RunCollection_UpdateOfRunsInProgressChanged);
    7883    }
    7984    private void DeregisterItemEvents(IRun item) {
     
    394399    #region Content Events
    395400    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     401      if (suppressUpdates) return;
    396402      if (InvokeRequired)
    397403        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
     
    407413    }
    408414    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     415      if (suppressUpdates) return;
    409416      if (InvokeRequired)
    410417        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
     
    422429    }
    423430    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
     431      if (suppressUpdates) return;
    424432      if (InvokeRequired)
    425433        Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
     
    440448      }
    441449    }
     450    private void RunCollection_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
     451      if (InvokeRequired) Invoke((Action<object, EventArgs>)RunCollection_UpdateOfRunsInProgressChanged, sender, e);
     452      else {
     453        suppressUpdates = RunCollection.UpdateOfRunsInProgress;
     454        if (!suppressUpdates) {
     455          foreach (IRun item in Content) {
     456            //remove only the first matching ListViewItem, because the IRun could be contained multiple times in the ItemCollection
     457            ListViewItem listViewItem = GetListViewItemsForItem(item).FirstOrDefault();
     458            if (listViewItem != null) RemoveListViewItem(listViewItem);
     459          }
     460          RebuildImageList();
     461          foreach (IRun item in Content)
     462            AddListViewItem(CreateListViewItem(item));
     463
     464          AdjustListViewColumnSizes();
     465          analyzeRunsToolStripDropDownButton.Enabled = itemsListView.Items.Count > 0;
     466          clearButton.Enabled = itemsListView.Items.Count > 0 && !Content.IsReadOnly && !ReadOnly;
     467          runCollectionConstraintCollectionView.ReadOnly = itemsListView.Items.Count == 0;
     468        }
     469      }
     470    }
    442471    #endregion
    443472
    444473    #region Item Events
    445474    private void Item_ItemImageChanged(object sender, EventArgs e) {
     475      if (suppressUpdates) return;
    446476      if (InvokeRequired)
    447477        Invoke(new EventHandler(Item_ItemImageChanged), sender, e);
     
    453483    }
    454484    private void Item_ToStringChanged(object sender, EventArgs e) {
     485      if (suppressUpdates) return;
    455486      if (InvokeRequired)
    456487        Invoke(new EventHandler(Item_ToStringChanged), sender, e);
     
    463494    }
    464495    private void Item_PropertyChanged(object sender, PropertyChangedEventArgs e) {
     496      if (suppressUpdates) return;
    465497      if (InvokeRequired)
    466         this.Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e);
     498        Invoke((Action<object, PropertyChangedEventArgs>)Item_PropertyChanged, sender, e);
    467499      else {
    468500        IRun run = (IRun)sender;
  • stable/HeuristicLab.Optimization/3.3/RunCollection.cs

    r12708 r12725  
    445445      EventHandler<EventArgs<int, int>> handler = ItemChanged;
    446446      if (handler != null) handler(this, new EventArgs<int, int>(rowIndex, columnIndex));
    447       OnToStringChanged();
    448447    }
    449448    public event EventHandler Reset;
     
    451450      EventHandler handler = Reset;
    452451      if (handler != null) handler(this, EventArgs.Empty);
    453       OnToStringChanged();
    454452    }
    455453    public event EventHandler ColumnsChanged;
     
    485483    #region Filtering
    486484    private void UpdateFiltering(bool reset) {
     485      var oldUpateRuns = UpdateOfRunsInProgress;
    487486      UpdateOfRunsInProgress = true;
    488487      if (reset)
     
    490489      foreach (IRunCollectionConstraint constraint in this.constraints)
    491490        constraint.Check();
    492       UpdateOfRunsInProgress = false;
     491      UpdateOfRunsInProgress = oldUpateRuns;
    493492    }
    494493
     
    552551    #region Modification
    553552    public void Modify() {
     553      var oldUpateRuns = UpdateOfRunsInProgress;
    554554      UpdateOfRunsInProgress = true;
    555555      var runs = this.ToList();
     
    566566        }
    567567      }
    568       UpdateOfRunsInProgress = false;
     568      UpdateOfRunsInProgress = oldUpateRuns;
    569569    }
    570570
Note: See TracChangeset for help on using the changeset viewer.