Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/04/14 15:32:33 (10 years ago)
Author:
aesterer
Message:

Completed scatter plot view

File:
1 edited

Legend:

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

    r10915 r10952  
    1818
    1919  [View("Multi Scatter Plot View")]
    20   [Content(typeof(ScatterPlotContent), true)]
     20  [Content(typeof(ScatterPlotContent), false)]
    2121  public partial class MultiScatterPlotView : ItemView {
     22
     23    private const int HEADER_WIDTH = 50;
     24    private const int HEADER_HEIGHT = 50;
     25    private const int MAX_AUTO_SIZE_ELEMENTS = 6;
     26    private const int FIXED_CHART_WIDTH = 250;
     27    private const int FIXED_CHART_HEIGHT = 150;
    2228
    2329    private IChartLogic logic;
     
    3440
    3541    public void InitData() {
    36 
    3742      variables = new List<string>(logic.GetVariableNames());
    38 
    3943    }
    4044
     
    4549        InitData();
    4650        GenerateMultiLayout();
     51      }
     52    }
     53
     54    //Add header elements to the table layout panel
     55    private void addHeaderToTableLayoutPanels() {
     56
     57      for (int i = 1; i < variables.Count + 1; i++) {
     58        // Use buttons for header elements
     59        Button xButton = new Button();
     60        xButton.Enabled = false;
     61        xButton.BackColor = Color.Gainsboro;
     62        xButton.Text = variables[i - 1];
     63        xButton.Dock = DockStyle.Fill;
     64        tableLayoutPanel.Controls.Add(xButton, 0, i);
     65        Button yButton = new Button();
     66        yButton.Enabled = false;
     67        yButton.BackColor = Color.Gainsboro;
     68        yButton.Text = variables[i - 1];
     69        yButton.Dock = DockStyle.Fill;
     70        tableLayoutPanel.Controls.Add(yButton, i, 0);
    4771      }
    4872    }
     
    5983      tableLayoutPanel.RowCount = variables.Count+1;
    6084
    61       int headerSize = 50;
    62       int maxAutoSizeElements = 6;
    63       int fixedElementSize = 200;
    64 
    65       tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, headerSize));
    66       tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, headerSize));
     85      tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, HEADER_WIDTH));
     86      tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, HEADER_HEIGHT));
    6787      // set column and row layout
    6888      for (int x = 0; x < variables.Count; x++)
    6989      {
    7090        // auto size
    71         if (variables.Count <= maxAutoSizeElements) {
    72           tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - headerSize) / variables.Count));
    73           tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, (tableLayoutPanel.Height - headerSize) / variables.Count));
     91        if (variables.Count <= MAX_AUTO_SIZE_ELEMENTS) {
     92          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - HEADER_WIDTH) / variables.Count));
     93          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, (tableLayoutPanel.Height - HEADER_HEIGHT) / variables.Count));
    7494        }
    7595        // fixed size
    7696        else {
    77           tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, fixedElementSize));
    78           tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, fixedElementSize));
     97          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, FIXED_CHART_WIDTH));
     98          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, FIXED_CHART_HEIGHT));
    7999        }
    80100      }
    81101
    82       // set variable header elements
    83       for (int i = 1; i < variables.Count +1; i++)
    84       {
    85          Button b1 = new Button();
    86          b1.Text = variables[i-1];
    87          b1.Dock = DockStyle.Fill;
    88          tableLayoutPanel.Controls.Add(b1,0,i);
    89          Button b2 = new Button();
    90          b2.Text = variables[i - 1];
    91          b2.Dock = DockStyle.Fill;
    92          tableLayoutPanel.Controls.Add(b2, i, 0);
    93       }
     102      addHeaderToTableLayoutPanels();
     103      addChartsToTableLayoutPanel();
     104 
     105    }
    94106
     107    private void addChartsToTableLayoutPanel() {
    95108      //set scatter plots and histograms
    96       for (int x = 1; x < variables.Count + 1; x++)
    97       {
     109      for (int x = 1; x < variables.Count + 1; x++) {
    98110
    99         for (int y = 1; y < variables.Count + 1; y++)
    100         {
    101           // use historgram if x variable equals y variable
     111        for (int y = 1; y < variables.Count + 1; y++) {
     112          // use historgram if x and y variable are equal
    102113          if (x == y) {
    103114            PreprocessingDataTable dataTable = new PreprocessingDataTable();
     
    105116            dataTable.Rows.Add(dataRow);
    106117            PreprocessingDataTableView pcv = new PreprocessingDataTableView();
    107             pcv.DoubleClick += tableLayoutElementDoubleClick;
     118            pcv.ChartDoubleClick += HistogramDoubleClick;
    108119            pcv.Content = dataTable;
    109120            tableLayoutPanel.Controls.Add(pcv, y, x);
    110121          }
    111122          //scatter plot
    112           else {   
    113             ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y-1]);   
     123          else {
     124            ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y - 1]);
    114125            PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
    115             pspv.DoubleClick += tableLayoutElementDoubleClick;
     126            pspv.ChartDoubleClick += ScatterPlotDoubleClick;
    116127            pspv.Content = scatterPlot;
    117128            pspv.Dock = DockStyle.Fill;
    118             tableLayoutPanel.Controls.Add(pspv, y, x);
     129            tableLayoutPanel.Controls.Add(pspv, x, y);
    119130          }
    120131        }
     
    122133    }
    123134
    124     private void tableLayoutElementDoubleClick(object sender, EventArgs e) {
     135    //Open scatter plot in new tab with new content when double clicked
     136    private void ScatterPlotDoubleClick(object sender, EventArgs e) {
     137      PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
     138      ScatterPlotContent scatterContent = new ScatterPlotContent(logic);  // create new content
     139      ScatterPlot scatterPlot = pspv.Content;
     140      setVariablesInContentFromScatterPlot(scatterContent, scatterPlot);
    125141
    126        //histogram clicked
    127        if(sender.GetType() == typeof(PreprocessingDataTableView))
    128        {
    129          PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
    130          //ScatterPlotContent spc = new ScatterPlotContent(
    131          
    132        }
    133        // scatter plot clicked
    134        else if (sender.GetType() == typeof(PreprocessingScatterPlotView)) {
    135          PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
    136          MainFormManager.MainForm.ShowContent(this.Content, typeof(SingleScatterPlotView));
    137        }
     142      MainFormManager.MainForm.ShowContent(scatterContent, typeof(SingleScatterPlotView));  // open in new tab
     143    }
    138144
    139        
     145    //Extract variable names from scatter plot and set them in content
     146    private void setVariablesInContentFromScatterPlot(ScatterPlotContent scatterContent, ScatterPlot scatterPlot) {
     147
     148      // only one data row should be in scatter plot
     149      if (scatterPlot.Rows.Count == 1) {
     150        // TODO -> find better way to get variable names
     151        string[] variables = scatterPlot.Rows.ElementAt(0).Name.Split(new string[]{" - "},StringSplitOptions.None); // extract variable names from string
     152        scatterContent.SelectedXVariable = variables[0];
     153        scatterContent.SelectedYVariable = variables[1];
     154      }
     155    }
     156
     157    //Set variable item list from with variable from data table
     158    private void setVariableItemListFromDataTable(HistogramContent histoContent, PreprocessingDataTable dataTable) {
     159
     160      // only one data row should be in data table
     161      if (dataTable.Rows.Count == 1) {
     162        string variableName = dataTable.Rows.ElementAt(0).Name;
     163
     164        // set only variable name checked
     165        foreach(var checkedItem in histoContent.VariableItemList)
     166        {
     167          if(checkedItem.Value == variableName)
     168            histoContent.VariableItemList.SetItemCheckedState(checkedItem,true);
     169          else
     170            histoContent.VariableItemList.SetItemCheckedState(checkedItem,false);
     171           
     172        }
     173      }
     174    }
     175
     176    //open histogram in new tab with new content when double clicked
     177    private void HistogramDoubleClick(object sender, EventArgs e) {
     178      PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
     179      HistogramContent histoContent = new HistogramContent(logic);  // create new content
     180      histoContent.VariableItemList = logic.CreateVariableItemList();
     181      PreprocessingDataTable dataTable = pcv.Content;
     182      setVariableItemListFromDataTable(histoContent, dataTable);
     183
     184      MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
    140185    }
    141186   
Note: See TracChangeset for help on using the changeset viewer.