Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GBT/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs @ 12337

Last change on this file since 12337 was 10992, checked in by rstoll, 10 years ago
  • removed ChartLogic and

moved logic accordingly to PreprocessingChartContent, ScatterPlotContent
modified views etc. to use IFilteredPreprocessingData instead of ChartLogic

  • reordered code
File size: 7.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Linq;
5using System.Windows.Forms;
6using HeuristicLab.Analysis;
7using HeuristicLab.Common;
8using HeuristicLab.Core.Views;
9using HeuristicLab.DataPreprocessing.Implementations;
10using HeuristicLab.MainForm;
11
12namespace HeuristicLab.DataPreprocessing.Views {
13
14  [View("Scatter Plot Multi View")]
15  [Content(typeof(ScatterPlotContent), false)]
16  public partial class ScatterPlotMultiView : ItemView {
17
18    private const int HEADER_WIDTH = 50;
19    private const int HEADER_HEIGHT = 50;
20    private const int MAX_AUTO_SIZE_ELEMENTS = 6;
21    private const int FIXED_CHART_WIDTH = 250;
22    private const int FIXED_CHART_HEIGHT = 150;
23
24    public ScatterPlotMultiView() {
25      InitializeComponent();
26    }
27
28    public new ScatterPlotContent Content {
29      get { return (ScatterPlotContent)base.Content; }
30      set { base.Content = value; }
31    }
32
33    protected override void OnContentChanged() {
34      base.OnContentChanged();
35      if (Content != null) {
36        GenerateMultiLayout();
37      }
38    }
39
40    //Add header elements to the table layout panel
41    private void addHeaderToTableLayoutPanels() {
42
43      List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
44
45      for (int i = 1; i < variables.Count + 1; i++) {
46        // Use buttons for header elements
47        Button xButton = new Button();
48        xButton.Enabled = false;
49        xButton.BackColor = Color.Gainsboro;
50        xButton.Text = variables[i - 1];
51        xButton.Dock = DockStyle.Fill;
52        tableLayoutPanel.Controls.Add(xButton, 0, i);
53        Button yButton = new Button();
54        yButton.Enabled = false;
55        yButton.BackColor = Color.Gainsboro;
56        yButton.Text = variables[i - 1];
57        yButton.Dock = DockStyle.Fill;
58        tableLayoutPanel.Controls.Add(yButton, i, 0);
59      }
60    }
61
62    private void GenerateMultiLayout() {
63      List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
64
65      tableLayoutPanel.Controls.Clear();
66      //Clear out the existing row and column styles
67      tableLayoutPanel.ColumnStyles.Clear();
68      tableLayoutPanel.RowStyles.Clear();
69
70      //Set row and column count
71      tableLayoutPanel.ColumnCount = variables.Count + 1;
72      tableLayoutPanel.RowCount = variables.Count + 1;
73
74      tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, HEADER_WIDTH));
75      tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, HEADER_HEIGHT));
76      // set column and row layout
77      for (int x = 0; x < variables.Count; x++) {
78        // auto size
79        if (variables.Count <= MAX_AUTO_SIZE_ELEMENTS) {
80          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - HEADER_WIDTH) / variables.Count));
81          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, (tableLayoutPanel.Height - HEADER_HEIGHT) / variables.Count));
82        }
83          // fixed size
84        else {
85          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, FIXED_CHART_WIDTH));
86          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, FIXED_CHART_HEIGHT));
87        }
88      }
89
90      addHeaderToTableLayoutPanels();
91      addChartsToTableLayoutPanel();
92
93    }
94
95    private void addChartsToTableLayoutPanel() {
96
97      List<string> variables = Content.PreprocessingData.GetDoubleVariableNames().ToList();
98
99      //set scatter plots and histograms
100      for (int x = 1; x < variables.Count + 1; x++) {
101
102        for (int y = 1; y < variables.Count + 1; y++) {
103          // use historgram if x and y variable are equal
104          if (x == y) {
105            PreprocessingDataTable dataTable = new PreprocessingDataTable();
106            DataRow dataRow = Content.CreateDataRow(variables[x - 1], DataRowVisualProperties.DataRowChartType.Histogram);
107            dataTable.Rows.Add(dataRow);
108            PreprocessingDataTableView pcv = new PreprocessingDataTableView();
109            pcv.ChartDoubleClick += HistogramDoubleClick;
110            pcv.Content = dataTable;
111            tableLayoutPanel.Controls.Add(pcv, y, x);
112          }
113            //scatter plot
114          else {
115            ScatterPlot scatterPlot = Content.CreateScatterPlot(variables[x - 1], variables[y - 1]);
116            PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
117            pspv.ChartDoubleClick += ScatterPlotDoubleClick;
118            pspv.Content = scatterPlot;
119            pspv.Dock = DockStyle.Fill;
120            tableLayoutPanel.Controls.Add(pspv, x, y);
121          }
122        }
123      }
124    }
125
126    //Open scatter plot in new tab with new content when double clicked
127    private void ScatterPlotDoubleClick(object sender, EventArgs e) {
128      PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
129      ScatterPlotContent scatterContent = new ScatterPlotContent(Content, new Cloner());  // create new content
130      ScatterPlot scatterPlot = pspv.Content;
131      setVariablesInContentFromScatterPlot(scatterContent, scatterPlot);
132
133      MainFormManager.MainForm.ShowContent(scatterContent, typeof(ScatterPlotSingleView));  // open in new tab
134    }
135
136    //Extract variable names from scatter plot and set them in content
137    private void setVariablesInContentFromScatterPlot(ScatterPlotContent scatterContent, ScatterPlot scatterPlot) {
138
139      // only one data row should be in scatter plot
140      if (scatterPlot.Rows.Count == 1) {
141        string[] variables = scatterPlot.Rows.ElementAt(0).Name.Split(new string[] { " - " }, StringSplitOptions.None); // extract variable names from string
142        scatterContent.SelectedXVariable = variables[0];
143        scatterContent.SelectedYVariable = variables[1];
144      }
145    }
146
147    //Set variable item list from with variable from data table
148    private void setVariableItemListFromDataTable(HistogramContent histoContent, PreprocessingDataTable dataTable) {
149
150      // only one data row should be in data table
151      if (dataTable.Rows.Count == 1) {
152        string variableName = dataTable.Rows.ElementAt(0).Name;
153
154        // set only variable name checked
155        foreach (var checkedItem in histoContent.VariableItemList) {
156          if (checkedItem.Value == variableName)
157            histoContent.VariableItemList.SetItemCheckedState(checkedItem, true);
158          else
159            histoContent.VariableItemList.SetItemCheckedState(checkedItem, false);
160
161        }
162      }
163    }
164
165    //open histogram in new tab with new content when double clicked
166    private void HistogramDoubleClick(object sender, EventArgs e) {
167      PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
168      HistogramContent histoContent = new HistogramContent(Content.PreprocessingData);  // create new content     
169      histoContent.VariableItemList = Content.CreateVariableItemList();
170      PreprocessingDataTable dataTable = pcv.Content;
171      setVariableItemListFromDataTable(histoContent, dataTable);
172
173      MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
174    }
175
176
177  }
178
179
180}
Note: See TracBrowser for help on using the repository browser.