Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/03/17 10:57:53 (7 years ago)
Author:
pfleck
Message:

#2709: merged branch to trunk

Location:
trunk/sources/HeuristicLab.DataPreprocessing.Views
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataPreprocessing.Views

  • trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs

    r14388 r15110  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Drawing;
     
    526using System.Windows.Forms;
    627using HeuristicLab.Analysis;
     28using HeuristicLab.Analysis.Views;
    729using HeuristicLab.Collections;
    8 using HeuristicLab.Common;
    9 using HeuristicLab.Core.Views;
    1030using HeuristicLab.Data;
    1131using HeuristicLab.MainForm;
    1232using HeuristicLab.MainForm.WindowsForms;
     33using AggregationType = HeuristicLab.Analysis.DataTableVisualProperties.DataTableHistogramAggregation;
     34using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType;
    1335
    1436namespace HeuristicLab.DataPreprocessing.Views {
    1537  [View("Scatter Plot Multi View")]
    16   [Content(typeof(ScatterPlotContent), false)]
    17   public partial class ScatterPlotMultiView : PreprocessingCheckedVariablesView {
    18     private readonly IDictionary<string, Label> columnHeaderCache;
    19     private readonly IDictionary<string, Label> rowHeaderCache;
    20     private readonly IDictionary<Tuple<string/*col*/, string/*row*/>, ItemView> bodyCache;
     38  [Content(typeof(MultiScatterPlotContent), true)]
     39  public sealed partial class ScatterPlotMultiView : PreprocessingCheckedVariablesView {
     40    private readonly IDictionary<string, Label> columnHeaderCache = new Dictionary<string, Label>();
     41    private readonly IDictionary<string, VerticalLabel> rowHeaderCache = new Dictionary<string, VerticalLabel>();
     42    private readonly IDictionary<Tuple<string/*col*/, string/*row*/>, Control> bodyCache = new Dictionary<Tuple<string, string>, Control>();
     43
     44    public new MultiScatterPlotContent Content {
     45      get { return (MultiScatterPlotContent)base.Content; }
     46      set { base.Content = value; }
     47    }
    2148
    2249    public ScatterPlotMultiView() {
    2350      InitializeComponent();
     51
     52      oldWidth = (int)widthNumericUpDown.Value;
     53      oldHeight = (int)heightNumericUpDown.Value;
     54
     55      regressionTypeComboBox.DataSource = Enum.GetValues(typeof(RegressionType));
     56      regressionTypeComboBox.SelectedItem = RegressionType.None;
     57
     58      aggregationComboBox.DataSource = Enum.GetValues(typeof(AggregationType));
     59      aggregationComboBox.SelectedItem = AggregationType.Overlapping;
     60
     61      legendOrderComboBox.DataSource = Enum.GetValues(typeof(PreprocessingChartContent.LegendOrder));
     62      legendOrderComboBox.SelectedItem = PreprocessingChartContent.LegendOrder.Appearance;
    2463
    2564      #region Initialize Scrollbars
     
    4180      #endregion
    4281
    43       columnHeaderCache = new Dictionary<string, Label>();
    44       rowHeaderCache = new Dictionary<string, Label>();
    45       bodyCache = new Dictionary<Tuple<string, string>, ItemView>();
    46 
    4782      bodyScrollPanel.MouseWheel += bodyScrollPanel_MouseWheel;
    48     }
    49 
    50     public new ScatterPlotContent Content {
    51       get { return (ScatterPlotContent)base.Content; }
    52       set { base.Content = value; }
    5383    }
    5484
     
    5686      base.OnContentChanged();
    5787      if (Content != null) {
    58         GenerateCharts();
    59       }
     88        groupingComboBox.Items.Add(string.Empty);
     89        foreach (string var in PreprocessingChartContent.GetVariableNamesForGrouping(Content.PreprocessingData)) {
     90          groupingComboBox.Items.Add(var);
     91        }
     92        SuppressCheckedChangedUpdate = true;
     93        groupingComboBox.SelectedItem = Content.GroupingVariable ?? string.Empty;
     94        SuppressCheckedChangedUpdate = false;
     95
     96        // uncheck variables that max 20 vars are selected initially
     97        var variables = Content.VariableItemList;
     98        int numChecked = variables.CheckedItems.Count();
     99        if (numChecked > 20) {
     100          string message = string.Format("Display all {0} input variables ({1} charts)?" + Environment.NewLine +
     101                                         "Press No to reduce the number of checked variables to 20." + Environment.NewLine +
     102                                         "Press Cancel to uncheck all.",
     103            numChecked, numChecked * numChecked);
     104          var dialogResult = MessageBox.Show(this, message, "Display All Input Variables?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
     105          if (dialogResult == DialogResult.No || dialogResult == DialogResult.Cancel) {
     106            SuppressCheckedChangedUpdate = true;
     107            IEnumerable<StringValue> toUncheck = variables;
     108            if (dialogResult == DialogResult.No) // only show the first 20
     109              toUncheck = variables.CheckedItems.Reverse().Take(numChecked - 20).Select(x => x.Value);
     110            foreach (var var in toUncheck)
     111              Content.VariableItemList.SetItemCheckedState(var, false);
     112            SuppressCheckedChangedUpdate = false;
     113          }
     114        }
     115        GenerateCharts(true);
     116      }
     117    }
     118
     119    protected override void SetEnabledStateOfControls() {
     120      base.SetEnabledStateOfControls();
     121      var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
     122      polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
     123      sizeGroupBox.Enabled = Content != null;
     124      pointsGroupBox.Enabled = Content != null;
     125      groupingComboBox.Enabled = Content != null;
     126      regressionGroupBox.Enabled = Content != null;
    60127    }
    61128
    62129    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
    63130      base.CheckedItemsChanged(sender, checkedItems);
    64       foreach (var variable in checkedItems.Items.Select(i => i.Value.Value)) {
    65         if (IsVariableChecked(variable))
    66           AddChartToTable(variable);
     131      if (SuppressCheckedChangedUpdate) return;
     132
     133      foreach (var variable in checkedItems.Items) {
     134        if (Content.VariableItemList.ItemChecked(variable.Value))
     135          ShowChartOnTable(variable.Value.Value, variable.Index);
    67136        else
    68           RemoveChartFromTable(variable);
    69       }
    70     }
    71 
    72     #region Add and remove charts
     137          HideChartFromTable(variable.Value.Value, variable.Index);
     138      }
     139    }
     140
     141    #region Show and Hide charts
     142    private void ShowChartOnTable(string variable, int idx) {
     143      frameTableLayoutPanel.SuspendLayout();
     144
     145      // show column header
     146      var colH = columnHeaderTableLayoutPanel;
     147      colH.ColumnStyles[idx].Width = GetColumnWidth();
     148      if (colH.GetControlFromPosition(idx, 0) == null)
     149        colH.Controls.Add(GetColumnHeader(variable), idx, 0);
     150      else
     151        colH.GetControlFromPosition(idx, 0).Visible = true;
     152
     153      // show row header
     154      var rowH = rowHeaderTableLayoutPanel;
     155      rowH.RowStyles[idx].Height = GetRowHeight();
     156      if (rowH.GetControlFromPosition(0, idx) == null)
     157        rowH.Controls.Add(GetRowHeader(variable), 0, idx);
     158      else
     159        rowH.GetControlFromPosition(0, idx).Visible = true;
     160
     161      // show body
     162      var body = bodyTableLayoutPanel;
     163      ShowColumnHelper(body, idx, r => GetBody(variable, Content.VariableItemList[r].Value));
     164      ShowRowHelper(body, idx, c => GetBody(Content.VariableItemList[c].Value, variable));
     165
     166      frameTableLayoutPanel.ResumeLayout(true);
     167    }
     168    private void ShowColumnHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
     169      tlp.ColumnStyles[idx].Width = GetColumnWidth();
     170      for (int r = 0; r < tlp.RowCount; r++) {
     171        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[r])) {
     172          var control = tlp.GetControlFromPosition(idx, r);
     173          if (control == null)
     174            tlp.Controls.Add(creatorFunc(r), idx, r);
     175          else
     176            control.Visible = true;
     177        }
     178      }
     179    }
     180    private void ShowRowHelper(TableLayoutPanel tlp, int idx, Func<int, Control> creatorFunc) {
     181      tlp.RowStyles[idx].Height = GetRowHeight();
     182      for (int c = 0; c < tlp.ColumnCount; c++) {
     183        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[c])) {
     184          var control = tlp.GetControlFromPosition(c, idx);
     185          if (control == null)
     186            tlp.Controls.Add(creatorFunc(c), c, idx);
     187          else
     188            tlp.GetControlFromPosition(c, idx).Visible = true;
     189        }
     190      }
     191    }
     192
     193    private void HideChartFromTable(string variable, int idx) {
     194      frameTableLayoutPanel.SuspendLayout();
     195
     196      // hide column header
     197      var colH = columnHeaderTableLayoutPanel;
     198      HideColumnHelper(colH, idx);
     199
     200      // hide row header
     201      var rowH = rowHeaderTableLayoutPanel;
     202      HideRowHelper(rowH, idx);
     203
     204      // hide from body
     205      var body = bodyTableLayoutPanel;
     206      HideColumnHelper(body, idx);
     207      HideRowHelper(body, idx);
     208
     209      frameTableLayoutPanel.ResumeLayout(true);
     210    }
     211    private void HideColumnHelper(TableLayoutPanel tlp, int idx) {
     212      tlp.ColumnStyles[idx].Width = 0;
     213      // hide controls
     214      for (int r = 0; r < tlp.RowCount; r++) {
     215        var control = tlp.GetControlFromPosition(idx, r);
     216        if (control != null)
     217          control.Visible = false;
     218      }
     219    }
     220    private void HideRowHelper(TableLayoutPanel tlp, int idx) {
     221      tlp.RowStyles[idx].Height = 0;
     222      // hide controls
     223      for (int c = 0; c < tlp.ColumnCount; c++) {
     224        var control = tlp.GetControlFromPosition(c, idx);
     225        if (control != null)
     226          control.Visible = false;
     227      }
     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      if (IsVariableChecked(name)) {
     241        RemoveChartFromTable(name);
     242      }
     243
     244      // clear caches
     245      columnHeaderCache[name].Dispose();
     246      columnHeaderCache.Remove(name);
     247      rowHeaderCache[name].Dispose();
     248      rowHeaderCache.Remove(name);
     249      var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
     250      foreach (var key in keys) {
     251        bodyCache[key].Dispose();
     252        bodyCache.Remove(key);
     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);
     262    }
     263
    73264    private void AddChartToTable(string variable) {
    74265      frameTableLayoutPanel.SuspendLayout();
    75266
    76267      // find index to insert
    77       var variables = checkedItemList.Content.Select(v => v.Value).ToList();
     268      var variables = Content.VariableItemList.Select(v => v.Value).ToList();
    78269      int idx = variables              // all variables
    79270        .TakeWhile(t => t != variable) // ... until the variable that was checked
     
    102293      tlp.ColumnStyles.Insert(idx, new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
    103294      // shift right
    104       for (int c = tlp.ColumnCount; c >  idx - 1; c--) {
     295      for (int c = tlp.ColumnCount; c > idx - 1; c--) {
    105296        for (int r = 0; r < tlp.RowCount; r++) {
    106297          var control = tlp.GetControlFromPosition(c, r);
     
    192383    #endregion
    193384
    194     #region Add/Remove/Update Variable
    195     protected override void AddVariable(string name) {
    196       base.AddVariable(name);
    197       if (IsVariableChecked(name))
    198         AddChartToTable(name);
    199     }
    200     protected override void RemoveVariable(string name) {
    201       base.RemoveVariable(name);
    202 
    203       // clear caches
    204       columnHeaderCache.Remove(name);
    205       rowHeaderCache.Remove(name);
    206       var keys = bodyCache.Keys.Where(t => t.Item1 == name || t.Item2 == name).ToList();
    207       foreach (var key in keys)
    208         bodyCache.Remove(key);
    209 
    210       if (IsVariableChecked(name)) {
    211         RemoveChartFromTable(name);
    212       }
    213     }
    214     protected override void UpdateVariable(string name) {
    215       base.UpdateVariable(name);
    216       RemoveVariable(name);
    217       AddVariable(name);
    218     }
    219     protected override void ResetAllVariables() {
    220       GenerateCharts();
    221     }
    222     #endregion
    223 
    224     #region Creating Headers and Body
     385    #region Creating Headers and Body
    225386    private Label GetColumnHeader(string variable) {
    226387      if (!columnHeaderCache.ContainsKey(variable)) {
     
    238399    private Label GetRowHeader(string variable) {
    239400      if (!rowHeaderCache.ContainsKey(variable)) {
    240         rowHeaderCache.Add(variable, new Label() {
     401        rowHeaderCache.Add(variable, new VerticalLabel() {
    241402          Text = variable,
    242403          TextAlign = ContentAlignment.MiddleCenter,
    243404          Name = variable,
    244405          Width = rowHeaderTableLayoutPanel.Width,
     406          Height = columnHeaderScrollPanel.Width,
    245407          Dock = DockStyle.Fill,
    246408          Margin = new Padding(3)
     
    249411      return rowHeaderCache[variable];
    250412    }
    251     private ItemView GetBody(string colVariable, string rowVariable) {
     413    private Control GetBody(string colVariable, string rowVariable) {
    252414      var key = Tuple.Create(colVariable, rowVariable);
    253415      if (!bodyCache.ContainsKey(key)) {
    254416        if (rowVariable == colVariable) { // use historgram if x and y variable are equal
    255           PreprocessingDataTable dataTable = new PreprocessingDataTable();
    256           DataRow dataRow = Content.CreateDataRow(rowVariable, DataRowVisualProperties.DataRowChartType.Histogram);
    257           dataTable.Rows.Add(dataRow);
    258           PreprocessingDataTableView pcv = new PreprocessingDataTableView {
     417          var dataTable = HistogramContent.CreateHistogram(
     418            Content.PreprocessingData,
     419            rowVariable,
     420            (string)groupingComboBox.SelectedItem,
     421            (AggregationType)aggregationComboBox.SelectedItem,
     422            (PreprocessingChartContent.LegendOrder)legendOrderComboBox.SelectedItem);
     423          dataTable.VisualProperties.Title = string.Empty;
     424          foreach (var dataRow in dataTable.Rows) {
     425            dataRow.VisualProperties.IsVisibleInLegend = legendCheckbox.Checked && groupingComboBox.SelectedIndex > 0;
     426          }
     427          var pcv = new DataTableView {
    259428            Name = key.ToString(),
    260429            Content = dataTable,
    261430            Dock = DockStyle.Fill,
    262             ShowLegend = false,
    263             XAxisFormat = "G3"
     431            ShowChartOnly = true
    264432          };
    265           pcv.ChartDoubleClick += HistogramDoubleClick;
     433          //pcv.ChartDoubleClick += HistogramDoubleClick;  // ToDo: not working; double click is already handled by the chart
    266434          bodyCache.Add(key, pcv);
    267435        } else { //scatter plot
    268           ScatterPlot scatterPlot = Content.CreateScatterPlot(colVariable, rowVariable);
    269           PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView {
     436          var scatterPlot = ScatterPlotContent.CreateScatterPlot(Content.PreprocessingData,
     437            colVariable,
     438            rowVariable,
     439            (string)groupingComboBox.SelectedItem,
     440            (PreprocessingChartContent.LegendOrder)legendOrderComboBox.SelectedItem);
     441          var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
     442          int order = (int)polynomialRegressionOrderNumericUpDown.Value;
     443          int i = 0;
     444          var colors = PreprocessingChartView.Colors;
     445          foreach (var row in scatterPlot.Rows) {
     446            row.VisualProperties.PointSize = (int)pointSizeNumericUpDown.Value;
     447            row.VisualProperties.Color = Color.FromArgb((int)(pointOpacityNumericUpDown.Value * 255),
     448              row.VisualProperties.Color.IsEmpty ? colors[i++ % colors.Length] : row.VisualProperties.Color);
     449            row.VisualProperties.IsVisibleInLegend = legendCheckbox.Checked && groupingComboBox.SelectedIndex > 0;
     450            row.VisualProperties.IsRegressionVisibleInLegend = false;
     451            row.VisualProperties.RegressionType = regressionType;
     452            row.VisualProperties.PolynomialRegressionOrder = order;
     453          }
     454          scatterPlot.VisualProperties.Title = string.Empty;
     455          var scatterPlotView = new ScatterPlotView {
    270456            Name = key.ToString(),
    271457            Content = scatterPlot,
    272458            Dock = DockStyle.Fill,
    273             ShowLegend = false,
    274             XAxisFormat = "G3"
     459            ShowName = false
     460            //ShowLegend = false,
     461            //XAxisFormat = "G3"
    275462          };
    276           pspv.ChartDoubleClick += ScatterPlotDoubleClick;
    277           bodyCache.Add(key, pspv);
     463          //scatterPlotView.DoubleClick += ScatterPlotDoubleClick; // ToDo: not working; double click is already handled by the chart
     464          bodyCache.Add(key, scatterPlotView);
    278465        }
    279466      }
     
    282469    #endregion
    283470
     471    protected override void CheckedChangedUpdate() {
     472      GenerateCharts(false); // only checked-changes -> reuse cached values
     473    }
     474
    284475    #region Generate Charts
    285     private void GenerateCharts() {
    286       var variables = GetCheckedVariables();
     476    private void GenerateCharts(bool clearCache) {
     477      if (Content == null || SuppressCheckedChangedUpdate) return;
    287478
    288479      // Clear old layouts and cache
     
    292483        tableLayoutPanel.RowStyles.Clear();
    293484      }
    294       columnHeaderCache.Clear();
    295       rowHeaderCache.Clear();
    296       bodyCache.Clear();
     485
     486      if (clearCache) {
     487        foreach (var control in bodyCache.Values.Concat(columnHeaderCache.Values).Concat(rowHeaderCache.Values)) {
     488          control.Dispose();
     489        }
     490        columnHeaderCache.Clear();
     491        rowHeaderCache.Clear();
     492        bodyCache.Clear();
     493      }
     494
     495      var variables = Content.VariableItemList.Select(x => x.Value).ToList();
    297496
    298497      // Set row and column count
     
    304503      // Set column and row layout
    305504      for (int i = 0; i < variables.Count; i++) {
    306         columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
    307         rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
    308         bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, GetColumnWidth()));
    309         bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, GetRowHeight()));
     505        bool @checked = Content.VariableItemList.ItemChecked(Content.VariableItemList[i]);
     506        columnHeaderTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0));
     507        rowHeaderTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0));
     508        bodyTableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, @checked ? GetColumnWidth() : 0));
     509        bodyTableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, @checked ? GetRowHeight() : 0));
    310510      }
    311511
     
    318518
    319519    private void AddHeaderToTableLayoutPanels() {
    320       int i = 0;
    321       foreach (var variable in GetCheckedVariables()) {
    322         columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable), i, 0);
    323         rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable), 0, i);
    324         i++;
     520      for (int i = 0; i < Content.VariableItemList.Count; i++) {
     521        var variable = Content.VariableItemList[i];
     522        if (Content.VariableItemList.ItemChecked(variable)) {
     523          columnHeaderTableLayoutPanel.Controls.Add(GetColumnHeader(variable.Value), i, 0);
     524          rowHeaderTableLayoutPanel.Controls.Add(GetRowHeader(variable.Value), 0, i);
     525        }
    325526      }
    326527    }
    327528    private void AddChartsToTableLayoutPanel() {
    328       int c = 0;
    329       foreach (var colVar in GetCheckedVariables()) {
     529      for (int c = 0; c < Content.VariableItemList.Count; c++) {
     530        var colVar = Content.VariableItemList[c].Value;
    330531        if (!IsVariableChecked(colVar)) continue;
    331         int r = 0;
    332         foreach (var rowVar in GetCheckedVariables()) {
     532        for (int r = 0; r < Content.VariableItemList.Count; r++) {
     533          var rowVar = Content.VariableItemList[r].Value;
    333534          if (!IsVariableChecked(rowVar)) continue;
    334535          bodyTableLayoutPanel.Controls.Add(GetBody(colVar, rowVar), c, r);
    335           r++;
    336         }
    337         c++;
    338       }
     536        }
     537      }
     538      UpdateRegressionLine();
    339539    }
    340540
     
    344544    //Open scatter plot in new tab with new content when double clicked
    345545    private void ScatterPlotDoubleClick(object sender, EventArgs e) {
    346       PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
    347       ScatterPlotContent scatterContent = new ScatterPlotContent(Content, new Cloner());  // create new content
    348       ScatterPlot scatterPlot = pspv.Content;
     546      var scatterPlotView = (ScatterPlotView)sender;
     547      var scatterContent = new SingleScatterPlotContent(Content.PreprocessingData);
     548      ScatterPlot scatterPlot = scatterPlotView.Content;
    349549
    350550      //Extract variable names from scatter plot and set them in content
     
    355555      }
    356556
    357       MainFormManager.MainForm.ShowContent(scatterContent, typeof(ScatterPlotSingleView));  // open in new tab
     557      MainFormManager.MainForm.ShowContent(scatterContent, typeof(ScatterPlotSingleView)); // open in new tab
    358558    }
    359559
    360560    //open histogram in new tab with new content when double clicked
    361561    private void HistogramDoubleClick(object sender, EventArgs e) {
    362       PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
     562      DataTableView pcv = (DataTableView)sender;
    363563      HistogramContent histoContent = new HistogramContent(Content.PreprocessingData);  // create new content     
    364       histoContent.VariableItemList = Content.CreateVariableItemList();
    365       PreprocessingDataTable dataTable = pcv.Content;
     564                                                                                        //ToDo: histoContent.VariableItemList = Content.CreateVariableItemList();
     565      var dataTable = pcv.Content;
    366566
    367567      //Set variable item list from with variable from data table
     
    374574        }
    375575      }
    376       MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
     576      MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView)); // open in new tab
    377577    }
    378578    #endregion
     
    413613
    414614    #region Sizing of Charts
    415     private int GetColumnWidth() { return (int)(bodyScrollPanel.Width * ((float)widthTrackBar.Value / 100)); }
    416     private int GetRowHeight() { return (int)(bodyScrollPanel.Height * ((float)heightTrackBar.Value / 100)); }
    417     private void widthTrackBar_ValueChanged(object sender, EventArgs e) {
     615    private int oldWidth;
     616    private int oldHeight;
     617    private float AspectRatio {
     618      get {
     619        if (oldWidth == 0 || oldHeight == 0) return 1;
     620        return (float)oldWidth / oldHeight;
     621      }
     622    }
     623    private bool lockChange = false;
     624
     625    private int GetColumnWidth() { return (int)widthNumericUpDown.Value; }
     626    private int GetRowHeight() { return (int)heightNumericUpDown.Value; }
     627
     628    private void widthNumericUpDown_ValueChanged(object sender, EventArgs e) {
    418629      frameTableLayoutPanel.SuspendRepaint();
     630      if (lockAspectCheckBox.Checked && !lockChange) {
     631        lockChange = true;
     632        heightNumericUpDown.Value = (int)((double)widthNumericUpDown.Value / AspectRatio);
     633        lockChange = false;
     634      }
    419635      for (int i = 0; i < columnHeaderTableLayoutPanel.ColumnCount; i++) {
    420         columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
    421         bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
    422       }
     636        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) {
     637          columnHeaderTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
     638          bodyTableLayoutPanel.ColumnStyles[i].Width = GetColumnWidth();
     639        }
     640      }
     641      oldWidth = GetColumnWidth();
     642      oldHeight = GetRowHeight();
    423643      frameTableLayoutPanel.ResumeRepaint(true);
    424644    }
    425     private void heightTrackBar_ValueChanged(object sender, EventArgs e) {
     645    private void heightNumericUpDown_ValueChanged(object sender, EventArgs e) {
    426646      frameTableLayoutPanel.SuspendRepaint();
    427 
     647      if (lockAspectCheckBox.Checked && !lockChange) {
     648        lockChange = true;
     649        widthNumericUpDown.Value = (int)((double)heightNumericUpDown.Value * AspectRatio);
     650        lockChange = false;
     651      }
    428652      for (int i = 0; i < rowHeaderTableLayoutPanel.RowCount; i++) {
    429         rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
    430         bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
    431       }
     653        if (Content.VariableItemList.ItemChecked(Content.VariableItemList[i])) {
     654          rowHeaderTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
     655          bodyTableLayoutPanel.RowStyles[i].Height = GetRowHeight();
     656        }
     657      }
     658      oldWidth = GetColumnWidth();
     659      oldHeight = GetRowHeight();
    432660      frameTableLayoutPanel.ResumeRepaint(true);
     661    }
     662    private void pointSizeNumericUpDown_ValueChanged(object sender, EventArgs e) {
     663      int pointSize = (int)pointSizeNumericUpDown.Value;
     664      foreach (var control in bodyCache.ToList()) {
     665        var scatterPlotView = control.Value as ScatterPlotView;
     666        if (scatterPlotView != null) {
     667          foreach (var row in scatterPlotView.Content.Rows) {
     668            row.VisualProperties.PointSize = pointSize;
     669          }
     670        }
     671      }
     672    }
     673    private void pointOpacityNumericUpDown_ValueChanged(object sender, EventArgs e) {
     674      float opacity = (float)pointOpacityNumericUpDown.Value;
     675      foreach (var control in bodyCache.ToList()) {
     676        var scatterPlotView = control.Value as ScatterPlotView;
     677        if (scatterPlotView != null) {
     678          foreach (var row in scatterPlotView.Content.Rows) {
     679            var color = row.VisualProperties.Color;
     680            if (color.IsEmpty)
     681              color = PreprocessingChartView.Colors.First();
     682            row.VisualProperties.Color = Color.FromArgb((int)(opacity * 255), color);
     683          }
     684        }
     685      }
     686    }
     687    #endregion
     688
     689    #region Regression Line
     690    private void regressionTypeComboBox_SelectedValueChanged(object sender, EventArgs e) {
     691      var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
     692      polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
     693      UpdateRegressionLine();
     694    }
     695
     696    private void polynomialRegressionOrderNumericUpDown_ValueChanged(object sender, EventArgs e) {
     697      UpdateRegressionLine();
     698    }
     699
     700    private void UpdateRegressionLine() {
     701      var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
     702      int order = (int)polynomialRegressionOrderNumericUpDown.Value;
     703
     704      foreach (var control in bodyCache.ToList()) {
     705        // hidden chart => reset cache
     706        if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) {
     707          bodyCache.Remove(control.Key);
     708        }
     709
     710        var scatterPlotView = control.Value as ScatterPlotView;
     711        if (scatterPlotView != null) {
     712          foreach (var row in scatterPlotView.Content.Rows) {
     713            row.VisualProperties.IsRegressionVisibleInLegend = false;
     714            row.VisualProperties.RegressionType = regressionType;
     715            row.VisualProperties.PolynomialRegressionOrder = order;
     716          }
     717        }
     718      }
     719    }
     720    #endregion
     721
     722    #region Grouping
     723    private void groupingComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     724      aggregationLabel.Enabled = groupingComboBox.SelectedIndex > 0;
     725      aggregationComboBox.Enabled = groupingComboBox.SelectedIndex > 0;
     726      legendGroupBox.Enabled = groupingComboBox.SelectedIndex > 0;
     727      GenerateCharts(true); // new series within charts -> clear cache
     728    }
     729
     730    private void aggregationComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     731      var aggregation = (AggregationType)aggregationComboBox.SelectedValue;
     732      foreach (var control in bodyCache.ToList()) {
     733        // hidden chart => reset cache
     734        if (!bodyTableLayoutPanel.Controls.Contains(control.Value)) {
     735          bodyCache.Remove(control.Key);
     736        }
     737
     738        var histogramView = control.Value as DataTableView;
     739        if (histogramView != null) {
     740          histogramView.Content.VisualProperties.HistogramAggregation = aggregation;
     741        }
     742      }
     743    }
     744
     745    private void legendCheckbox_CheckedChanged(object sender, EventArgs e) {
     746      foreach (var control in bodyCache.ToList()) {
     747        var histogramControl = control.Value as DataTableView;
     748        if (histogramControl != null) {
     749          foreach (var row in histogramControl.Content.Rows) {
     750            row.VisualProperties.IsVisibleInLegend = legendCheckbox.Checked && groupingComboBox.SelectedIndex > 0;
     751          }
     752        }
     753        var scatterplotControl = control.Value as ScatterPlotView;
     754        if (scatterplotControl != null) {
     755          foreach (var row in scatterplotControl.Content.Rows) {
     756            row.VisualProperties.IsVisibleInLegend = legendCheckbox.Checked && groupingComboBox.SelectedIndex > 0;
     757          }
     758        }
     759      }
     760    }
     761
     762    private void legendOrderComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     763      GenerateCharts(true);
    433764    }
    434765    #endregion
    435766  }
    436767}
     768
Note: See TracChangeset for help on using the changeset viewer.