Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/MultiScatterPlotView.cs @ 10915

Last change on this file since 10915 was 10915, checked in by aesterer, 10 years ago

Splitted scatter plot view in single and multi view

File size: 4.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Linq;
6using System.Text;
7using System.Windows.Forms;
8using HeuristicLab.Analysis;
9using HeuristicLab.Analysis.Views;
10using HeuristicLab.Collections;
11using HeuristicLab.Core;
12using HeuristicLab.Core.Views;
13using HeuristicLab.Data;
14using HeuristicLab.DataPreprocessing.Implementations;
15using HeuristicLab.MainForm;
16
17namespace HeuristicLab.DataPreprocessing.Views {
18
19  [View("Multi Scatter Plot View")]
20  [Content(typeof(ScatterPlotContent), true)]
21  public partial class MultiScatterPlotView : ItemView {
22
23    private IChartLogic logic;
24    private List<string> variables;
25
26    public MultiScatterPlotView() {
27      InitializeComponent();
28    }
29
30    public new ScatterPlotContent Content {
31      get { return (ScatterPlotContent)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public void InitData() {
36
37      variables = new List<string>(logic.GetVariableNames());
38
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43      if (Content != null) {
44        logic = Content.ChartLogic;
45        InitData();
46        GenerateMultiLayout();
47      }
48    }
49
50    private void GenerateMultiLayout()
51    {
52      tableLayoutPanel.Controls.Clear();
53      //Clear out the existing row and column styles
54      tableLayoutPanel.ColumnStyles.Clear();
55      tableLayoutPanel.RowStyles.Clear();
56
57      //Set row and column count
58      tableLayoutPanel.ColumnCount = variables.Count+1;
59      tableLayoutPanel.RowCount = variables.Count+1;
60
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));
67      // set column and row layout
68      for (int x = 0; x < variables.Count; x++)
69      {
70        // 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));
74        }
75        // fixed size
76        else {
77          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, fixedElementSize));
78          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, fixedElementSize));
79        }
80      }
81
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      }
94
95      //set scatter plots and histograms
96      for (int x = 1; x < variables.Count + 1; x++)
97      {
98
99        for (int y = 1; y < variables.Count + 1; y++)
100        {
101          // use historgram if x variable equals y variable
102          if (x == y) {
103            PreprocessingDataTable dataTable = new PreprocessingDataTable();
104            DataRow dataRow = logic.CreateDataRow(variables[x - 1], DataRowVisualProperties.DataRowChartType.Histogram);
105            dataTable.Rows.Add(dataRow);
106            PreprocessingDataTableView pcv = new PreprocessingDataTableView();
107            pcv.DoubleClick += tableLayoutElementDoubleClick;
108            pcv.Content = dataTable;
109            tableLayoutPanel.Controls.Add(pcv, y, x);
110          }
111          //scatter plot
112          else {   
113            ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y-1]);   
114            PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
115            pspv.DoubleClick += tableLayoutElementDoubleClick;
116            pspv.Content = scatterPlot;
117            pspv.Dock = DockStyle.Fill;
118            tableLayoutPanel.Controls.Add(pspv, y, x);
119          }
120        }
121      }
122    }
123
124    private void tableLayoutElementDoubleClick(object sender, EventArgs e) {
125
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       }
138
139       
140    }
141   
142
143  }
144
145 
146}
Note: See TracBrowser for help on using the repository browser.