Changeset 14384


Ignore:
Timestamp:
11/11/16 12:26:14 (4 years ago)
Author:
pfleck
Message:

#2698 Implemented unchecking of variables in multi-scatterplot.

Location:
trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r14381 r14384  
    9696
    9797        // not checked -> remove
    98         if (!VariableIsChecked(variableName)) {
     98        if (!IsVariableChecked(variableName)) {
    9999          dataTableView.SetRowEnabled(variableName, false);
    100100          dataTable.SelectedRows.Remove(variableName);
     
    305305      dataTable.SelectedRows.Clear();
    306306      foreach (var selectedRow in selectedDataRows) {
    307         if (VariableIsChecked(selectedRow.Name))
     307        if (IsVariableChecked(selectedRow.Name))
    308308          dataTable.SelectedRows.Add(selectedRow);
    309309      }
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs

    r14382 r14384  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.Linq;
     
    4344    }
    4445
    45     protected bool VariableIsChecked(string name) {
     46    protected bool IsVariableChecked(string name) {
    4647      return Content.VariableItemList.CheckedItems.Any(x => x.Value.Value == name);
    4748    }
    48 
     49    protected IList<string> GetCheckedVariables() {
     50      return checkedItemList.Content.CheckedItems.Select(i => i.Value.Value).ToList();
     51    }
    4952
    5053    protected override void OnContentChanged() {
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.Designer.cs

    r14381 r14384  
    4646    private void InitializeComponent() {
    4747      this.frameTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     48      this.columnHeaderScrollPanel = new System.Windows.Forms.Panel();
    4849      this.columnHeaderTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     50      this.rowHeaderScrollPanel = new System.Windows.Forms.Panel();
    4951      this.rowHeaderTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
     52      this.bodyScrollPanel = new System.Windows.Forms.Panel();
    5053      this.bodyTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
    5154      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    5457      this.splitContainer.SuspendLayout();
    5558      this.frameTableLayoutPanel.SuspendLayout();
     59      this.columnHeaderScrollPanel.SuspendLayout();
     60      this.rowHeaderScrollPanel.SuspendLayout();
     61      this.bodyScrollPanel.SuspendLayout();
    5662      this.SuspendLayout();
    5763      //
     
    6874      this.frameTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 40F));
    6975      this.frameTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
    70       this.frameTableLayoutPanel.Controls.Add(this.columnHeaderTableLayoutPanel, 1, 0);
    71       this.frameTableLayoutPanel.Controls.Add(this.rowHeaderTableLayoutPanel, 0, 1);
    72       this.frameTableLayoutPanel.Controls.Add(this.bodyTableLayoutPanel, 1, 1);
     76      this.frameTableLayoutPanel.Controls.Add(this.columnHeaderScrollPanel, 1, 0);
     77      this.frameTableLayoutPanel.Controls.Add(this.rowHeaderScrollPanel, 0, 1);
     78      this.frameTableLayoutPanel.Controls.Add(this.bodyScrollPanel, 1, 1);
    7379      this.frameTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    7480      this.frameTableLayoutPanel.Location = new System.Drawing.Point(0, 0);
     
    8086      this.frameTableLayoutPanel.TabIndex = 0;
    8187      //
     88      // columnHeaderScrollPanel
     89      //
     90      this.columnHeaderScrollPanel.Controls.Add(this.columnHeaderTableLayoutPanel);
     91      this.columnHeaderScrollPanel.Dock = System.Windows.Forms.DockStyle.Fill;
     92      this.columnHeaderScrollPanel.Location = new System.Drawing.Point(40, 0);
     93      this.columnHeaderScrollPanel.Margin = new System.Windows.Forms.Padding(0);
     94      this.columnHeaderScrollPanel.Name = "columnHeaderScrollPanel";
     95      this.columnHeaderScrollPanel.Size = new System.Drawing.Size(699, 40);
     96      this.columnHeaderScrollPanel.TabIndex = 3;
     97      //
    8298      // columnHeaderTableLayoutPanel
    8399      //
     100      this.columnHeaderTableLayoutPanel.AutoSize = true;
     101      this.columnHeaderTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    84102      this.columnHeaderTableLayoutPanel.ColumnCount = 2;
    85103      this.columnHeaderTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    86104      this.columnHeaderTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    87       this.columnHeaderTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    88       this.columnHeaderTableLayoutPanel.Location = new System.Drawing.Point(43, 3);
     105      this.columnHeaderTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Left;
     106      this.columnHeaderTableLayoutPanel.Location = new System.Drawing.Point(0, 0);
     107      this.columnHeaderTableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
    89108      this.columnHeaderTableLayoutPanel.Name = "columnHeaderTableLayoutPanel";
    90109      this.columnHeaderTableLayoutPanel.RowCount = 1;
    91110      this.columnHeaderTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    92111      this.columnHeaderTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    93       this.columnHeaderTableLayoutPanel.Size = new System.Drawing.Size(693, 34);
     112      this.columnHeaderTableLayoutPanel.Size = new System.Drawing.Size(0, 40);
    94113      this.columnHeaderTableLayoutPanel.TabIndex = 1;
    95114      //
     115      // rowHeaderScrollPanel
     116      //
     117      this.rowHeaderScrollPanel.Controls.Add(this.rowHeaderTableLayoutPanel);
     118      this.rowHeaderScrollPanel.Dock = System.Windows.Forms.DockStyle.Fill;
     119      this.rowHeaderScrollPanel.Location = new System.Drawing.Point(0, 40);
     120      this.rowHeaderScrollPanel.Margin = new System.Windows.Forms.Padding(0);
     121      this.rowHeaderScrollPanel.Name = "rowHeaderScrollPanel";
     122      this.rowHeaderScrollPanel.Size = new System.Drawing.Size(40, 477);
     123      this.rowHeaderScrollPanel.TabIndex = 4;
     124      //
    96125      // rowHeaderTableLayoutPanel
    97126      //
     127      this.rowHeaderTableLayoutPanel.AutoSize = true;
     128      this.rowHeaderTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    98129      this.rowHeaderTableLayoutPanel.ColumnCount = 1;
    99130      this.rowHeaderTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    100131      this.rowHeaderTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    101       this.rowHeaderTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    102       this.rowHeaderTableLayoutPanel.Location = new System.Drawing.Point(3, 43);
     132      this.rowHeaderTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Top;
     133      this.rowHeaderTableLayoutPanel.Location = new System.Drawing.Point(0, 0);
     134      this.rowHeaderTableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
    103135      this.rowHeaderTableLayoutPanel.Name = "rowHeaderTableLayoutPanel";
    104136      this.rowHeaderTableLayoutPanel.RowCount = 2;
    105137      this.rowHeaderTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    106138      this.rowHeaderTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    107       this.rowHeaderTableLayoutPanel.Size = new System.Drawing.Size(34, 471);
     139      this.rowHeaderTableLayoutPanel.Size = new System.Drawing.Size(40, 0);
    108140      this.rowHeaderTableLayoutPanel.TabIndex = 2;
    109141      //
     142      // bodyScrollPanel
     143      //
     144      this.bodyScrollPanel.AutoScroll = true;
     145      this.bodyScrollPanel.Controls.Add(this.bodyTableLayoutPanel);
     146      this.bodyScrollPanel.Dock = System.Windows.Forms.DockStyle.Fill;
     147      this.bodyScrollPanel.Location = new System.Drawing.Point(40, 40);
     148      this.bodyScrollPanel.Margin = new System.Windows.Forms.Padding(0);
     149      this.bodyScrollPanel.Name = "bodyScrollPanel";
     150      this.bodyScrollPanel.Size = new System.Drawing.Size(699, 477);
     151      this.bodyScrollPanel.TabIndex = 5;
     152      this.bodyScrollPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.bodyScrollPanel_Scroll);
     153      //
    110154      // bodyTableLayoutPanel
    111155      //
     156      this.bodyTableLayoutPanel.AutoSize = true;
     157      this.bodyTableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    112158      this.bodyTableLayoutPanel.ColumnCount = 2;
    113159      this.bodyTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    114160      this.bodyTableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
    115       this.bodyTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    116       this.bodyTableLayoutPanel.Location = new System.Drawing.Point(43, 43);
     161      this.bodyTableLayoutPanel.Location = new System.Drawing.Point(0, 0);
     162      this.bodyTableLayoutPanel.Margin = new System.Windows.Forms.Padding(0);
    117163      this.bodyTableLayoutPanel.Name = "bodyTableLayoutPanel";
    118164      this.bodyTableLayoutPanel.RowCount = 2;
    119165      this.bodyTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    120166      this.bodyTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
    121       this.bodyTableLayoutPanel.Size = new System.Drawing.Size(693, 471);
     167      this.bodyTableLayoutPanel.Size = new System.Drawing.Size(0, 0);
    122168      this.bodyTableLayoutPanel.TabIndex = 0;
    123       this.bodyTableLayoutPanel.Scroll += new System.Windows.Forms.ScrollEventHandler(this.bodyTableLayoutPanel_Scroll);
    124169      //
    125170      // ScatterPlotMultiView
     
    134179      this.splitContainer.ResumeLayout(false);
    135180      this.frameTableLayoutPanel.ResumeLayout(false);
     181      this.columnHeaderScrollPanel.ResumeLayout(false);
     182      this.columnHeaderScrollPanel.PerformLayout();
     183      this.rowHeaderScrollPanel.ResumeLayout(false);
     184      this.rowHeaderScrollPanel.PerformLayout();
     185      this.bodyScrollPanel.ResumeLayout(false);
     186      this.bodyScrollPanel.PerformLayout();
    136187      this.ResumeLayout(false);
    137188
     
    144195    private System.Windows.Forms.TableLayoutPanel rowHeaderTableLayoutPanel;
    145196    private System.Windows.Forms.TableLayoutPanel bodyTableLayoutPanel;
     197    private System.Windows.Forms.Panel columnHeaderScrollPanel;
     198    private System.Windows.Forms.Panel rowHeaderScrollPanel;
     199    private System.Windows.Forms.Panel bodyScrollPanel;
    146200  }
    147201}
  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs

    r14381 r14384  
    77using HeuristicLab.Collections;
    88using HeuristicLab.Common;
     9using HeuristicLab.Core.Views;
    910using HeuristicLab.Data;
    1011using HeuristicLab.MainForm;
     
    1516  [Content(typeof(ScatterPlotContent), false)]
    1617  public partial class ScatterPlotMultiView : PreprocessingCheckedVariablesView {
    17     private const int MAX_AUTO_SIZE_ELEMENTS = 6;
    18     private const int FIXED_CHART_WIDTH = 250;
    19     private const int FIXED_CHART_HEIGHT = 150;
     18    private const int MaxAutoSizeElements = 6;
     19    private const int FixedChartWidth = 250;
     20    private const int FixedChartHeight = 150;
     21
     22    private readonly IDictionary<string, Label> columnHeaderCache;
     23    private readonly IDictionary<string, Label> rowHeaderCache;
     24    private readonly IDictionary<Tuple<string/*col*/, string/*row*/>, ItemView> bodyCache;
    2025
    2126    public ScatterPlotMultiView() {
    2227      InitializeComponent();
    2328
    24       columnHeaderTableLayoutPanel.HorizontalScroll.Enabled = true;
    25       columnHeaderTableLayoutPanel.VerticalScroll.Enabled = false;
    26       columnHeaderTableLayoutPanel.HorizontalScroll.Visible = false;
    27       columnHeaderTableLayoutPanel.VerticalScroll.Visible = false;
    28 
    29       rowHeaderTableLayoutPanel.HorizontalScroll.Enabled = false;
    30       rowHeaderTableLayoutPanel.VerticalScroll.Enabled = true;
    31       rowHeaderTableLayoutPanel.HorizontalScroll.Visible = false;
    32       rowHeaderTableLayoutPanel.VerticalScroll.Visible = false;
    33 
    34       bodyTableLayoutPanel.HorizontalScroll.Enabled = true;
    35       bodyTableLayoutPanel.VerticalScroll.Enabled = true;
    36       bodyTableLayoutPanel.HorizontalScroll.Visible = true;
    37       bodyTableLayoutPanel.VerticalScroll.Visible = true;
    38       bodyTableLayoutPanel.AutoScroll = true;
    39 
    40       bodyTableLayoutPanel.MouseWheel += bodyTableLayoutPanel_MouseWheel;
    41 
    42       splitContainer.Panel1Collapsed = true; // ToDo: remove after correctly handling unchecks
     29      columnHeaderScrollPanel.HorizontalScroll.Enabled = true;
     30      columnHeaderScrollPanel.VerticalScroll.Enabled = false;
     31      columnHeaderScrollPanel.HorizontalScroll.Visible = false;
     32      columnHeaderScrollPanel.VerticalScroll.Visible = false;
     33
     34      rowHeaderScrollPanel.HorizontalScroll.Enabled = false;
     35      rowHeaderScrollPanel.VerticalScroll.Enabled = true;
     36      rowHeaderScrollPanel.HorizontalScroll.Visible = false;
     37      rowHeaderScrollPanel.VerticalScroll.Visible = false;
     38
     39      bodyScrollPanel.HorizontalScroll.Enabled = true;
     40      bodyScrollPanel.VerticalScroll.Enabled = true;
     41      bodyScrollPanel.HorizontalScroll.Visible = true;
     42      bodyScrollPanel.VerticalScroll.Visible = true;
     43      bodyScrollPanel.AutoScroll = true;
     44
     45      columnHeaderCache = new Dictionary<string, Label>();
     46      rowHeaderCache = new Dictionary<string, Label>();
     47      bodyCache = new Dictionary<Tuple<string, string>, ItemView>();
     48
     49      bodyScrollPanel.MouseWheel += bodyScrollPanel_MouseWheel;
    4350    }
    4451
     
    5764    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
    5865      base.CheckedItemsChanged(sender, checkedItems);
    59 
     66      foreach (var variable in checkedItems.Items.Select(i => i.Value.Value)) {
     67        if (IsVariableChecked(variable))
     68          AddChartToTable(variable);
     69        else
     70          RemoveChartFromTable(variable);
     71      }
     72    }
     73
     74    private void AddChartToTable(string variable) {
     75
     76    }
     77    // remove from headers and body and shift remaining slots to fill the gap
     78    private void RemoveChartFromTable(string variable) {
     79      frameTableLayoutPanel.SuspendLayout();
     80
     81      // remove column header
     82      var colH = columnHeaderTableLayoutPanel;
     83      int colIdx = colH.GetColumn(colH.Controls[variable]);
     84      RemoveColumnHelper(colH, colIdx);
     85
     86      // remove row header
     87      var rowH = rowHeaderTableLayoutPanel;
     88      int rowIdx = rowH.GetRow(rowH.Controls[variable]);
     89      RemoveRowHelper(rowH, rowIdx);
     90
     91      // remove from body
     92      var body = bodyTableLayoutPanel;
     93      RemoveColumnHelper(body, colIdx);
     94      RemoveRowHelper(body, rowIdx);
     95
     96      frameTableLayoutPanel.ResumeLayout(true);
     97    }
     98
     99    private void RemoveColumnHelper(TableLayoutPanel tlp, int idx) {
     100      for (int r = 0; r < tlp.RowCount; r++)
     101        tlp.Controls.Remove(tlp.GetControlFromPosition(idx, r));
     102      for (int c = idx + 1; c < tlp.ColumnCount; c++) {
     103        for (int r = 0; r < tlp.RowCount; r++) {
     104          var control = tlp.GetControlFromPosition(c, r);
     105          if (control != null) {
     106            tlp.SetColumn(control, c - 1);
     107          }
     108        }
     109      }
     110      tlp.ColumnStyles.RemoveAt(tlp.ColumnCount - 1);
     111      tlp.ColumnCount--;
     112    }
     113    private void RemoveRowHelper(TableLayoutPanel tlp, int idx) {
     114      for (int c = 0; c < tlp.ColumnCount; c++)
     115        tlp.Controls.Remove(tlp.GetControlFromPosition(c, idx));
     116      for (int r = idx + 1; r < tlp.RowCount; r++) {
     117        for (int c = 0; c < tlp.ColumnCount; c++) {
     118          var control = tlp.GetControlFromPosition(c, r);
     119          if (control != null) {
     120            tlp.SetRow(control, r - 1);
     121          }
     122        }
     123      }
     124      tlp.RowStyles.RemoveAt(tlp.RowCount - 1);
     125      tlp.RowCount--;
    60126    }
    61127
     
    64130      base.AddVariable(name);
    65131    }
     132
    66133    protected override void RemoveVariable(string name) {
    67134      base.RemoveVariable(name);
    68135
     136      // clear caches
     137      columnHeaderCache.Remove(name);
     138      rowHeaderCache.Remove(name);
     139      var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
     140      foreach (var key in keys)
     141        bodyCache.Remove(key);
     142
     143      if (IsVariableChecked(name)) {
     144        RemoveChartFromTable(name);
     145      }
    69146    }
    70147    protected override void UpdateVariable(string name) {
    71148      base.UpdateVariable(name);
    72 
    73149    }
    74150    protected override void ResetAllVariables() {
     
    77153    #endregion
    78154
     155
     156    #region Creating Header and Body
     157    private Label GetColumnHeader(string variable) {
     158      if (!columnHeaderCache.ContainsKey(variable)) {
     159        columnHeaderCache.Add(variable, new Label() {
     160          Text = variable,
     161          TextAlign = ContentAlignment.MiddleCenter,
     162          Name = variable,
     163          Height = columnHeaderTableLayoutPanel.Height,
     164          Dock = DockStyle.Fill,
     165          Margin = new Padding(3)
     166        });
     167      }
     168      return columnHeaderCache[variable];
     169    }
     170    private Label GetRowHeader(string variable) {
     171      if (!rowHeaderCache.ContainsKey(variable)) {
     172        rowHeaderCache.Add(variable, new Label() {
     173          Text = variable,
     174          TextAlign = ContentAlignment.MiddleCenter,
     175          Name = variable,
     176          Width = rowHeaderTableLayoutPanel.Width,
     177          Dock = DockStyle.Fill,
     178          Margin = new Padding(3)
     179        });
     180      }
     181      return rowHeaderCache[variable];
     182    }
     183    private ItemView GetBody(string colVariable, string rowVariable) {
     184      var key = Tuple.Create(colVariable, rowVariable);
     185      if (!bodyCache.ContainsKey(key)) {
     186        if (rowVariable == colVariable) { // use historgram if x and y variable are equal
     187          PreprocessingDataTable dataTable = new PreprocessingDataTable();
     188          DataRow dataRow = Content.CreateDataRow(rowVariable, DataRowVisualProperties.DataRowChartType.Histogram);
     189          dataTable.Rows.Add(dataRow);
     190          PreprocessingDataTableView pcv = new PreprocessingDataTableView {
     191            Name = key.ToString(),
     192            Content = dataTable,
     193            Dock = DockStyle.Fill,
     194            ShowLegend = false,
     195            XAxisFormat = "G3"
     196          };
     197          pcv.ChartDoubleClick += HistogramDoubleClick;
     198          bodyCache.Add(key, pcv);
     199        } else { //scatter plot
     200          ScatterPlot scatterPlot = Content.CreateScatterPlot(colVariable, rowVariable);
     201          PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView {
     202            Name = key.ToString(),
     203            Content = scatterPlot,
     204            Dock = DockStyle.Fill,
     205            ShowLegend = false,
     206            XAxisFormat = "G3"
     207          };
     208          pspv.ChartDoubleClick += ScatterPlotDoubleClick;
     209          bodyCache.Add(key, pspv);
     210        }
     211      }
     212      return bodyCache[key];
     213    }
     214    #endregion
     215
     216
     217
     218
    79219    #region Generate Charts
    80220    private void GenerateCharts() {
    81       List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
    82       var contentTableLayoutPanels = new[] { columnHeaderTableLayoutPanel, rowHeaderTableLayoutPanel, bodyTableLayoutPanel };
    83 
    84       // Clear table layouts
    85       foreach (var tlp in contentTableLayoutPanels) {
    86         tlp.Controls.Clear();
    87         //Clear out the existing row and column styles
    88         tlp.ColumnStyles.Clear();
    89         tlp.RowStyles.Clear();
    90       }
     221      var variables = GetCheckedVariables();
     222
     223      // Clear old layouts and cache
     224      foreach (var tableLayoutPanel in new[] { columnHeaderTableLayoutPanel, rowHeaderTableLayoutPanel, bodyTableLayoutPanel }) {
     225        tableLayoutPanel.Controls.Clear();
     226        tableLayoutPanel.ColumnStyles.Clear();
     227        tableLayoutPanel.RowStyles.Clear();
     228      }
     229      columnHeaderCache.Clear();
     230      rowHeaderCache.Clear();
     231      bodyCache.Clear();
    91232
    92233      // Set row and column count
    93       columnHeaderTableLayoutPanel.ColumnCount = variables.Count + 1;
    94       rowHeaderTableLayoutPanel.RowCount = variables.Count + 1;
     234      columnHeaderTableLayoutPanel.ColumnCount = variables.Count;
     235      rowHeaderTableLayoutPanel.RowCount = variables.Count;
    95236      bodyTableLayoutPanel.ColumnCount = variables.Count;
    96237      bodyTableLayoutPanel.RowCount = variables.Count;
    97238
    98239      // Set column and row layout
    99       int width = variables.Count <= MAX_AUTO_SIZE_ELEMENTS ? bodyTableLayoutPanel.Width / variables.Count : FIXED_CHART_WIDTH;
    100       int height = variables.Count <= MAX_AUTO_SIZE_ELEMENTS ? bodyTableLayoutPanel.Height / variables.Count : FIXED_CHART_HEIGHT;
     240      int width = variables.Count <= MaxAutoSizeElements ? bodyTableLayoutPanel.Width / variables.Count : FixedChartWidth;
     241      int height = variables.Count <= MaxAutoSizeElements ? bodyTableLayoutPanel.Height / variables.Count : FixedChartHeight;
    101242      for (int i = 0; i < variables.Count; i++) {
    102243        columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, width));
     
    106247      }
    107248
    108       //frameTableLayoutPanel.SuspendLayout();
     249      frameTableLayoutPanel.SuspendLayout();
    109250      AddHeaderToTableLayoutPanels();
    110251      AddChartsToTableLayoutPanel();
    111       //frameTableLayoutPanel.ResumeLayout(true);
     252      UpdateHeaderMargin();
     253      frameTableLayoutPanel.ResumeLayout(true);
    112254    }
    113255
    114256    private void AddHeaderToTableLayoutPanels() {
    115       List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
    116       int width = variables.Count <= MAX_AUTO_SIZE_ELEMENTS ? bodyTableLayoutPanel.Width / variables.Count : FIXED_CHART_WIDTH;
    117       int height = variables.Count <= MAX_AUTO_SIZE_ELEMENTS ? bodyTableLayoutPanel.Height / variables.Count : FIXED_CHART_HEIGHT;
    118       for (int i = 0; i < variables.Count; i++) {
    119         columnHeaderTableLayoutPanel.Controls.Add(new Label() {
    120           Text = variables[i],
    121           TextAlign = ContentAlignment.MiddleCenter,
    122           Width = width,
    123           Height = columnHeaderTableLayoutPanel.Height,
    124           Dock = DockStyle.Fill,
    125           Margin = new Padding(3)
    126         }, i, 0);
    127         rowHeaderTableLayoutPanel.Controls.Add(new Label() {
    128           Text = variables[i],
    129           TextAlign = ContentAlignment.MiddleCenter,
    130           Width = rowHeaderTableLayoutPanel.Width,
    131           Height = height,
    132           Dock = DockStyle.Fill,
    133           Margin = new Padding(3)
    134         }, 0, i);
    135       }
    136 
    137       // Add empty labels with fixed size to correct scollbar width/height in headers
    138       columnHeaderTableLayoutPanel.Controls.Add(new Panel() {
    139         Width = bodyTableLayoutPanel.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0,
    140         Height = columnHeaderTableLayoutPanel.Height,
    141         Dock = DockStyle.Fill,
    142         //BackColor = Color.DarkRed
    143       }, variables.Count, 0);
    144       rowHeaderTableLayoutPanel.Controls.Add(new Panel() {
    145         Width = rowHeaderTableLayoutPanel.Width,
    146         Height = bodyTableLayoutPanel.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0,
    147         Dock = DockStyle.Fill,
    148         //BackColor = Color.DarkRed
    149       }, 0, variables.Count);
     257      int i = 0;
     258      foreach (var variable in GetCheckedVariables()) {
     259        columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable), i, 0);
     260        rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable), 0, i);
     261        i++;
     262      }
    150263    }
    151264    private void AddChartsToTableLayoutPanel() {
    152       List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
    153 
    154       //set scatter plots and histograms
    155       for (int x = 0; x < variables.Count; x++) {
    156         for (int y = 0; y < variables.Count; y++) {
    157           if (x == y) { // use historgram if x and y variable are equal
    158             PreprocessingDataTable dataTable = new PreprocessingDataTable();
    159             DataRow dataRow = Content.CreateDataRow(variables[x], DataRowVisualProperties.DataRowChartType.Histogram);
    160             dataTable.Rows.Add(dataRow);
    161             PreprocessingDataTableView pcv = new PreprocessingDataTableView {
    162               Content = dataTable,
    163               Dock = DockStyle.Fill,
    164               ShowLegend = false,
    165               XAxisFormat = "G3"
    166             };
    167             pcv.ChartDoubleClick += HistogramDoubleClick;
    168             bodyTableLayoutPanel.Controls.Add(pcv, y, x);
    169           } else { //scatter plot
    170             ScatterPlot scatterPlot = Content.CreateScatterPlot(variables[x], variables[y]);
    171             PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView {
    172               Content = scatterPlot,
    173               Dock = DockStyle.Fill,
    174               ShowLegend = false,
    175               XAxisFormat = "G3"
    176             };
    177             pspv.ChartDoubleClick += ScatterPlotDoubleClick;
    178             bodyTableLayoutPanel.Controls.Add(pspv, x, y);
    179           }
    180         }
     265      int c = 0;
     266      foreach (var colVar in GetCheckedVariables()) {
     267        if (!IsVariableChecked(colVar)) continue;
     268        int r = 0;
     269        foreach (var rowVar in GetCheckedVariables()) {
     270          if (!IsVariableChecked(rowVar)) continue;
     271          bodyTableLayoutPanel.Controls.Add(GetBody(colVar, rowVar), c, r);
     272          r++;
     273        }
     274        c++;
    181275      }
    182276    }
     
    221315    #endregion
    222316
    223     private void bodyTableLayoutPanel_Scroll(object sender, ScrollEventArgs e) {
     317    private void bodyScrollPanel_Scroll(object sender, ScrollEventArgs e) {
    224318      SyncScroll();
    225319
    226       // update "padding labels" after scrollbars are added or removed
    227       var columHeaderPadding = columnHeaderTableLayoutPanel.Controls[columnHeaderTableLayoutPanel.Controls.Count - 1];
    228       var rowHeaderPadding = rowHeaderTableLayoutPanel.Controls[rowHeaderTableLayoutPanel.ColumnCount - 1];
    229       columHeaderPadding.Width = bodyTableLayoutPanel.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0;
    230       rowHeaderPadding.Height = bodyTableLayoutPanel.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0;
    231     }
    232     private void bodyTableLayoutPanel_MouseWheel(object sender, MouseEventArgs e) {
     320      UpdateHeaderMargin();
     321    }
     322    private void bodyScrollPanel_MouseWheel(object sender, MouseEventArgs e) {
    233323      // Scrolling with the mouse wheel is not captured in the Scoll event
    234324      SyncScroll();
    235325    }
    236326    private void SyncScroll() {
    237       //Debug.WriteLine("H: {0} <- {1}", columnHeaderTableLayoutPanel.HorizontalScroll.Value, bodyTableLayoutPanel.HorizontalScroll.Value);
    238       //Debug.WriteLine("V: {0} <- {1}", rowHeaderTableLayoutPanel.VerticalScroll.Value, bodyTableLayoutPanel.VerticalScroll.Value);
     327      //Debug.WriteLine("H: {0} <- {1}", columnHeaderScrollPanel.HorizontalScroll.Value, bodyScrollPanel.HorizontalScroll.Value);
     328      //Debug.WriteLine("V: {0} <- {1}", rowScrollLayoutPanel.VerticalScroll.Value, bodyScrollPanel.VerticalScroll.Value);
    239329
    240330      frameTableLayoutPanel.SuspendRepaint();
    241331
    242       columnHeaderTableLayoutPanel.HorizontalScroll.Minimum = bodyTableLayoutPanel.HorizontalScroll.Minimum;
    243       columnHeaderTableLayoutPanel.HorizontalScroll.Maximum = bodyTableLayoutPanel.HorizontalScroll.Maximum;
    244       rowHeaderTableLayoutPanel.VerticalScroll.Minimum = bodyTableLayoutPanel.VerticalScroll.Minimum;
    245       rowHeaderTableLayoutPanel.VerticalScroll.Maximum = bodyTableLayoutPanel.VerticalScroll.Maximum;
    246 
    247       columnHeaderTableLayoutPanel.HorizontalScroll.Value = Math.Max(bodyTableLayoutPanel.HorizontalScroll.Value, 1);
    248       rowHeaderTableLayoutPanel.VerticalScroll.Value = Math.Max(bodyTableLayoutPanel.VerticalScroll.Value, 1);
     332      columnHeaderScrollPanel.HorizontalScroll.Minimum = bodyScrollPanel.HorizontalScroll.Minimum;
     333      columnHeaderScrollPanel.HorizontalScroll.Maximum = bodyScrollPanel.HorizontalScroll.Maximum;
     334      rowHeaderScrollPanel.VerticalScroll.Minimum = bodyScrollPanel.VerticalScroll.Minimum;
     335      rowHeaderScrollPanel.VerticalScroll.Maximum = bodyScrollPanel.VerticalScroll.Maximum;
     336
     337      columnHeaderScrollPanel.HorizontalScroll.Value = Math.Max(bodyScrollPanel.HorizontalScroll.Value, 1);
     338      rowHeaderScrollPanel.VerticalScroll.Value = Math.Max(bodyScrollPanel.VerticalScroll.Value, 1);
    249339      // minimum 1 is nececary  because of two factors:
    250340      // - setting the Value-property of Horizontal/VerticalScroll updates the internal state but the Value-property stays 0
     
    254344      frameTableLayoutPanel.ResumeRepaint(true);
    255345    }
     346
     347    // add a margin to the header table layouts if the scollbar is visible to account for the width/height of the scrollbar
     348    private void UpdateHeaderMargin() {
     349      columnHeaderScrollPanel.Margin = new Padding(0, 0, bodyScrollPanel.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0, 0);
     350      rowHeaderScrollPanel.Margin = new Padding(0, 0, 0, bodyScrollPanel.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0);
     351    }
    256352  }
    257353}
Note: See TracChangeset for help on using the changeset viewer.