Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/12/17 13:41:46 (7 years ago)
Author:
pfleck
Message:

#2709

  • Improved Check/Uncheck of variables.
    • Instead of removing whole columns/rows from the tablelayout, the tablelayout stays the same with the column/rows width/height set to zero.
    • Hidden charts are not updated to avoid unnessecary calculations.
  • Added a check (messagebox) if >20 variables should be displayed in the multi scatterplot or reduced to 20.
  • Added configuration for point size/opacity and (histogram)aggregation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs

    r14953 r14975  
    3131using HeuristicLab.MainForm;
    3232using HeuristicLab.MainForm.WindowsForms;
     33using AggregationType = HeuristicLab.Analysis.DataRowVisualProperties.DataRowHistogramAggregation;
    3334using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType;
    3435
     
    5051      regressionTypeComboBox.SelectedItem = RegressionType.None;
    5152
     53      aggregationComboBox.DataSource = Enum.GetValues(typeof(AggregationType));
     54      aggregationComboBox.SelectedItem = AggregationType.Overlapping;
     55
    5256      #region Initialize Scrollbars
    5357      columnHeaderScrollPanel.HorizontalScroll.Enabled = true;
     
    8589        groupingComboBox.SelectedItem = Content.GroupingVariable;
    8690
     91        // uncheck variables that max 20 vars are selected initially
     92        var list = Content.VariableItemList;
     93        int numChecked = list.CheckedItems.Count();
     94        if (numChecked > 20) {
     95          string message = string.Format("Displaying {0} variables ({1} charts) can cause HeuristicLab to become instable. " +
     96                                         "Should the number of initially checked variables be reduced to 20?",
     97            numChecked, numChecked * numChecked);
     98          if (MessageBox.Show(this, message, "Reduce befor continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
     99            suppressCheckedChangedUpdate = true;
     100            foreach (var var in list.CheckedItems.Reverse().Take(numChecked - 20)) {
     101              Content.VariableItemList.SetItemCheckedState(var.Value, false);
     102            }
     103            suppressCheckedChangedUpdate = false;
     104          }
     105        }
    87106        GenerateCharts(true);
    88107      }
     
    93112      var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
    94113      polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
     114      sizeGroupBox.Enabled = Content != null;
     115      pointsGroupBox.Enabled = Content != null;
     116      groupingComboBox.Enabled = Content != null;
     117      regressionGroupBox.Enabled = Content != null;
    95118    }
    96119
    97120    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
    98121      base.CheckedItemsChanged(sender, checkedItems);
    99       if (suppressCheckedChangedUpdate)
    100         return;
    101       foreach (var variable in checkedItems.Items.Select(i => i.Value.Value)) {
    102         if (IsVariableChecked(variable))
    103           AddChartToTable(variable);
     122      if (suppressCheckedChangedUpdate) return;
     123
     124      foreach (var variable in checkedItems.Items) {
     125        if (Content.VariableItemList.ItemChecked(variable.Value))
     126          ShowChartOnTable(variable.Value.Value, variable.Index);
    104127        else
    105           RemoveChartFromTable(variable);
    106       }
    107     }
    108 
    109     #region Add and remove charts
     128          HideChartFromTable(variable.Value.Value, variable.Index);
     129      }
     130    }
     131
     132    #region Show and Hide charts
     133    private void ShowChartOnTable(string variable, int idx) {
     134      frameTableLayoutPanel.SuspendLayout();
     135
     136      // show column header
     137      var colH = columnHeaderTableLayoutPanel;
     138      colH.ColumnStyles[idx].Width = GetColumnWidth();
     139      if (colH.GetControlFromPosition(idx, 0) == null)
     140        colH.Controls.Add(GetColumnHeader(variable), idx, 0);
     141      else
     142        colH.GetControlFromPosition(idx, 0).Visible = true;
     143
     144      // show row header
     145      var rowH = rowHeaderTableLayoutPanel;
     146      rowH.RowStyles[idx].Height = GetRowHeight();
     147      if (rowH.GetControlFromPosition(0, idx) == null)
     148        rowH.Controls.Add(GetRowHeader(variable), 0, idx);
     149      else
     150        rowH.GetControlFromPosition(0, idx).Visible = true;
     151
     152      // show body
     153      var body = bodyTableLayoutPanel;
     154      ShowColumnHelper(body, idx, r => GetBody(variable, Content.VariableItemList[r].Value));
     155      ShowRowHelper(body, idx, c => GetBody(Content.VariableItemList[c].Value, variable));
     156
     157      frameTableLayoutPanel.ResumeLayout(true);
     158    }
     159    private void ShowColumnHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
     160      tlp.ColumnStyles[idx].Width = GetColumnWidth();
     161      for (int r = 0; r < tlp.RowCount; r++) {
     162        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[r])) {
     163          var control = tlp.GetControlFromPosition(idx, r);
     164          if (control == null)
     165            tlp.Controls.Add(creatorFunc(r), idx, r);
     166          else
     167            control.Visible = true;
     168        }
     169      }
     170    }
     171    private void ShowRowHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
     172      tlp.RowStyles[idx].Height = GetRowHeight();
     173      for (int c = 0; c < tlp.ColumnCount; c++) {
     174        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[c])) {
     175          var control = tlp.GetControlFromPosition(c, idx);
     176          if (control == null)
     177            tlp.Controls.Add(creatorFunc(c), c, idx);
     178          else
     179            tlp.GetControlFromPosition(c, idx).Visible = true;
     180        }
     181      }
     182    }
     183
     184    private void HideChartFromTable(string variable, int idx) {
     185      frameTableLayoutPanel.SuspendLayout();
     186
     187      // hide column header
     188      var colH = columnHeaderTableLayoutPanel;
     189      HideColumnHelper(colH, idx);
     190
     191      // hide row header
     192      var rowH = rowHeaderTableLayoutPanel;
     193      HideRowHelper(rowH, idx);
     194
     195      // hide from body
     196      var body = bodyTableLayoutPanel;
     197      HideColumnHelper(body, idx);
     198      HideRowHelper(body, idx);
     199
     200      frameTableLayoutPanel.ResumeLayout(true);
     201    }
     202    private void HideColumnHelper(TableLayoutPanel tlp, int idx) {
     203      tlp.ColumnStyles[idx].Width = 0;
     204      // hide controls
     205      for (int r = 0; r < tlp.RowCount; r++) {
     206        //tlp.Controls.Remove(tlp.GetControlFromPosition(idx, r));
     207        var control = tlp.GetControlFromPosition(idx, r);
     208        if (control != null)
     209          control.Visible = false;
     210      }
     211    }
     212    private void HideRowHelper(TableLayoutPanel tlp, int idx) {
     213      tlp.RowStyles[idx].Height = 0;
     214      // hide controls
     215      for (int c = 0; c < tlp.ColumnCount; c++) {
     216        //tlp.Controls.Remove(tlp.GetControlFromPosition(c, idx));
     217        var control = tlp.GetControlFromPosition(c, idx);
     218        if (control != null)
     219          control.Visible = false;
     220      }
     221    }
     222    #endregion
     223
     224    #region Add/Remove/Update Variable
     225    protected override void AddVariable(string name) {
     226      base.AddVariable(name);
     227      if (IsVariableChecked(name))
     228        AddChartToTable(name);
     229    }
     230    protected override void RemoveVariable(string name) {
     231      base.RemoveVariable(name);
     232
     233      if (IsVariableChecked(name)) {
     234        RemoveChartFromTable(name);
     235      }
     236
     237      // clear caches
     238      columnHeaderCache[name].Dispose();
     239      columnHeaderCache.Remove(name);
     240      rowHeaderCache[name].Dispose();
     241      rowHeaderCache.Remove(name);
     242      var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
     243      foreach (var key in keys) {
     244        bodyCache[key].Dispose();
     245        bodyCache.Remove(key);
     246      }
     247    }
     248    protected override void UpdateVariable(string name) {
     249      base.UpdateVariable(name);
     250      RemoveVariable(name);
     251      AddVariable(name);
     252    }
     253    protected override void ResetAllVariables() {
     254      GenerateCharts(true);
     255    }
     256
    110257    private void AddChartToTable(string variable) {
    111258      frameTableLayoutPanel.SuspendLayout();
     
    226373      tlp.RowStyles.RemoveAt(tlp.RowCount - 1);
    227374      tlp.RowCount--;
    228     }
    229     #endregion
    230 
    231     #region Add/Remove/Update Variable
    232     protected override void AddVariable(string name) {
    233       base.AddVariable(name);
    234       if (IsVariableChecked(name))
    235         AddChartToTable(name);
    236     }
    237     protected override void RemoveVariable(string name) {
    238       base.RemoveVariable(name);
    239 
    240       // clear caches
    241       columnHeaderCache[name].Dispose();
    242       columnHeaderCache.Remove(name);
    243       rowHeaderCache[name].Dispose();
    244       rowHeaderCache.Remove(name);
    245       var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
    246       foreach (var key in keys) {
    247         bodyCache[key].Dispose();
    248         bodyCache.Remove(key);
    249       }
    250 
    251       if (IsVariableChecked(name)) {
    252         RemoveChartFromTable(name);
    253       }
    254     }
    255     protected override void UpdateVariable(string name) {
    256       base.UpdateVariable(name);
    257       RemoveVariable(name);
    258       AddVariable(name);
    259     }
    260     protected override void ResetAllVariables() {
    261       GenerateCharts(true);
    262375    }
    263376    #endregion
     
    295408      if (!bodyCache.ContainsKey(key)) {
    296409        if (rowVariable == colVariable) { // use historgram if x and y variable are equal
    297           var dataTable = HistogramContent.CreateHistogram(Content.PreprocessingData, rowVariable, (string)groupingComboBox.SelectedItem, DataRowVisualProperties.DataRowHistogramAggregation.Overlapping);
     410          var dataTable = HistogramContent.CreateHistogram(
     411            Content.PreprocessingData,
     412            rowVariable,
     413            (string)groupingComboBox.SelectedItem,
     414            (AggregationType)aggregationComboBox.SelectedItem);
     415          dataTable.VisualProperties.Title = string.Empty;
    298416          foreach (var dataRow in dataTable.Rows)
    299             dataRow.VisualProperties.IsVisibleInLegend = false;
    300 
     417            dataRow.VisualProperties.IsVisibleInLegend = groupingComboBox.SelectedIndex > 0;
    301418          var pcv = new DataTableControl {
    302419            Name = key.ToString(),
     
    309426          bodyCache.Add(key, pcv);
    310427        } else { //scatter plot
    311           var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData, colVariable, rowVariable, (string)groupingComboBox.SelectedItem);
     428          var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData,
     429            colVariable,
     430            rowVariable,
     431            (string)groupingComboBox.SelectedItem);
    312432          var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
    313433          int order = (int)polynomialRegressionOrderNumericUpDown.Value;
     434          int i = 0;
     435          var colors = PreprocessingChartView.Colors;
    314436          foreach (var row in scatterPlot.Rows) {
    315             row.VisualProperties.PointSize = 3;
     437            row.VisualProperties.PointSize = (int)pointSizeNumericUpDown.Value;
     438            row.VisualProperties.Color = Color.FromArgb((int)(pointOpacityNumericUpDown.Value * 255),
     439              row.VisualProperties.Color.IsEmpty ? colors[i++ % colors.Length] : row.VisualProperties.Color);
     440            //row.VisualProperties.IsVisibleInLegend = true;
    316441            row.VisualProperties.IsRegressionVisibleInLegend = false;
    317442            row.VisualProperties.RegressionType = regressionType;
     
    342467      if (suppressCheckedChangedUpdate) return;
    343468
    344       var variables = GetCheckedVariables();
    345 
    346469      // Clear old layouts and cache
    347470      foreach (var tableLayoutPanel in new[] { columnHeaderTableLayoutPanel, rowHeaderTableLayoutPanel, bodyTableLayoutPanel }) {
     
    362485      }
    363486
     487      var variables = Content.VariableItemList.Select(x => x.Value).ToList();
     488
    364489      // Set row and column count
    365490      columnHeaderTableLayoutPanel.ColumnCount = variables.Count;
     
    370495      // Set column and row layout
    371496      for (int i = 0; i < variables.Count; i++) {
    372         columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
    373         rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
    374         bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
    375         bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
     497        bool @checked = Content.VariableItemList.ItemChecked(Content.VariableItemList[i]);
     498        columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0));
     499        rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0));
     500        bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0));
     501        bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0));
    376502      }
    377503
     
    384510
    385511    private void AddHeaderToTableLayoutPanels() {
    386       int i = 0;
    387       foreach (var variable in GetCheckedVariables()) {
    388         columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable), i, 0);
    389         rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable), 0, i);
    390         i++;
     512      for (int i = 0; i < Content.VariableItemList.Count; i++) {
     513        var variable = Content.VariableItemList[i];
     514        if (Content.VariableItemList.ItemChecked(variable)) {
     515          columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable.Value), i, 0);
     516          rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable.Value), 0, i);
     517        }
    391518      }
    392519    }
    393520    private void AddChartsToTableLayoutPanel() {
    394       int c = 0;
    395       foreach (var colVar in GetCheckedVariables()) {
     521      for (int c = 0; c < Content.VariableItemList.Count; c++) {
     522        var colVar = Content.VariableItemList[c].Value;
    396523        if (!IsVariableChecked(colVar)) continue;
    397         int r = 0;
    398         foreach (var rowVar in GetCheckedVariables()) {
     524        for (int r = 0; r < Content.VariableItemList.Count; r++) {
     525          var rowVar = Content.VariableItemList[r].Value;
    399526          if (!IsVariableChecked(rowVar)) continue;
    400527          bodyTableLayoutPanel.Controls.Add(GetBody(colVar, rowVar), c, r);
    401           r++;
    402         }
    403         c++;
     528        }
    404529      }
    405530      UpdateRegressionLine();
     
    429554      DataTableControl pcv = (DataTableControl)sender;
    430555      HistogramContent histoContent = new HistogramContent(Content.PreprocessingData);  // create new content     
    431       //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList();
     556                                                                                        //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList();
    432557      var dataTable = pcv.Content;
    433558
     
    501626      }
    502627      for (int i = 0; i < columnHeaderTableLayoutPanel.ColumnCount; i++) {
    503         columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
    504         bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
     628        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) {
     629          columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
     630          bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
     631        }
    505632      }
    506633      oldWidth = GetColumnWidth();
     
    516643      }
    517644      for (int i = 0; i < rowHeaderTableLayoutPanel.RowCount; i++) {
    518         rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
    519         bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
     645        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) {
     646          rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
     647          bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
     648        }
    520649      }
    521650      oldWidth = GetColumnWidth();
    522651      oldHeight = GetRowHeight();
    523652      frameTableLayoutPanel.ResumeRepaint(true);
     653    }
     654    private void pointSizeNumericUpDown_ValueChanged(object sender, EventArgs e) {
     655      int pointSize = (int)pointSizeNumericUpDown.Value;
     656      foreach (var control in bodyCache.ToList()) {
     657        var scatterPlotControl = control.Value as ScatterPlotControl;
     658        if (scatterPlotControl != null) {
     659          foreach (var row in scatterPlotControl.Content.Rows) {
     660            row.VisualProperties.PointSize = pointSize;
     661          }
     662        }
     663      }
     664    }
     665    private void pointOpacityNumericUpDown_ValueChanged(object sender, EventArgs e) {
     666      float opacity = (float)pointOpacityNumericUpDown.Value;
     667      foreach (var control in bodyCache.ToList()) {
     668        var scatterPlotControl = control.Value as ScatterPlotControl;
     669        if (scatterPlotControl != null) {
     670          foreach (var row in scatterPlotControl.Content.Rows) {
     671            var color = row.VisualProperties.Color;
     672            if (color.IsEmpty)
     673              color = PreprocessingChartView.Colors.First();
     674            row.VisualProperties.Color = Color.FromArgb((int)(opacity * 255), color);
     675          }
     676        }
     677      }
    524678    }
    525679    #endregion
     
    540694      int order = (int)polynomialRegressionOrderNumericUpDown.Value;
    541695
    542       foreach (var control in bodyCache.Values) {
    543         var scatterPlotControl = control as ScatterPlotControl;
     696      foreach (var control in bodyCache.ToList()) {
     697        // hidden chart => reset cache
     698        if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) {
     699          bodyCache.Remove(control.Key);
     700        }
     701
     702        var scatterPlotControl = control.Value as ScatterPlotControl;
    544703        if (scatterPlotControl != null) {
    545704          foreach (var row in scatterPlotControl.Content.Rows) {
     
    553712    #endregion
    554713
     714    #region Grouping
    555715    private void groupingComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     716      aggregationComboBox.Enabled = groupingComboBox.SelectedIndex > 0;
    556717      GenerateCharts(true); // new series within charts -> clear cache
    557718    }
     719
     720    private void aggregationComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     721      var aggregation = (AggregationType)aggregationComboBox.SelectedValue;
     722      foreach (var control in bodyCache.ToList()) {
     723        // hidden chart => reset cache
     724        if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) {
     725          bodyCache.Remove(control.Key);
     726        }
     727
     728        var histogramControl = control.Value as DataTableControl;
     729        if (histogramControl != null) {
     730          foreach (var row in histogramControl.Content.Rows) {
     731            row.VisualProperties.Aggregation = aggregation;
     732          }
     733        }
     734      }
     735    }
     736    #endregion
    558737  }
    559738}
Note: See TracChangeset for help on using the changeset viewer.