1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Windows.Forms;
|
---|
8 | using HeuristicLab.Analysis;
|
---|
9 | using HeuristicLab.Analysis.Views;
|
---|
10 | using HeuristicLab.Collections;
|
---|
11 | using HeuristicLab.Core;
|
---|
12 | using HeuristicLab.Core.Views;
|
---|
13 | using HeuristicLab.Data;
|
---|
14 | using HeuristicLab.DataPreprocessing.Implementations;
|
---|
15 | using HeuristicLab.MainForm;
|
---|
16 |
|
---|
17 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
18 |
|
---|
19 | [View("Multi Scatter Plot View")]
|
---|
20 | [Content(typeof(ScatterPlotContent), false)]
|
---|
21 | 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;
|
---|
28 |
|
---|
29 | private IChartLogic logic;
|
---|
30 | private List<string> variables;
|
---|
31 |
|
---|
32 | public MultiScatterPlotView() {
|
---|
33 | InitializeComponent();
|
---|
34 | }
|
---|
35 |
|
---|
36 | public new ScatterPlotContent Content {
|
---|
37 | get { return (ScatterPlotContent)base.Content; }
|
---|
38 | set { base.Content = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void InitData() {
|
---|
42 | variables = new List<string>(logic.GetVariableNames());
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void OnContentChanged() {
|
---|
46 | base.OnContentChanged();
|
---|
47 | if (Content != null) {
|
---|
48 | logic = Content.ChartLogic;
|
---|
49 | InitData();
|
---|
50 | 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);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void GenerateMultiLayout()
|
---|
75 | {
|
---|
76 | tableLayoutPanel.Controls.Clear();
|
---|
77 | //Clear out the existing row and column styles
|
---|
78 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
79 | tableLayoutPanel.RowStyles.Clear();
|
---|
80 |
|
---|
81 | //Set row and column count
|
---|
82 | tableLayoutPanel.ColumnCount = variables.Count+1;
|
---|
83 | tableLayoutPanel.RowCount = variables.Count+1;
|
---|
84 |
|
---|
85 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, HEADER_WIDTH));
|
---|
86 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, HEADER_HEIGHT));
|
---|
87 | // set column and row layout
|
---|
88 | for (int x = 0; x < variables.Count; x++)
|
---|
89 | {
|
---|
90 | // auto size
|
---|
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));
|
---|
94 | }
|
---|
95 | // fixed size
|
---|
96 | else {
|
---|
97 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, FIXED_CHART_WIDTH));
|
---|
98 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, FIXED_CHART_HEIGHT));
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | addHeaderToTableLayoutPanels();
|
---|
103 | addChartsToTableLayoutPanel();
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | private void addChartsToTableLayoutPanel() {
|
---|
108 | //set scatter plots and histograms
|
---|
109 | for (int x = 1; x < variables.Count + 1; x++) {
|
---|
110 |
|
---|
111 | for (int y = 1; y < variables.Count + 1; y++) {
|
---|
112 | // use historgram if x and y variable are equal
|
---|
113 | if (x == y) {
|
---|
114 | PreprocessingDataTable dataTable = new PreprocessingDataTable();
|
---|
115 | DataRow dataRow = logic.CreateDataRow(variables[x - 1], DataRowVisualProperties.DataRowChartType.Histogram);
|
---|
116 | dataTable.Rows.Add(dataRow);
|
---|
117 | PreprocessingDataTableView pcv = new PreprocessingDataTableView();
|
---|
118 | pcv.ChartDoubleClick += HistogramDoubleClick;
|
---|
119 | pcv.Content = dataTable;
|
---|
120 | tableLayoutPanel.Controls.Add(pcv, y, x);
|
---|
121 | }
|
---|
122 | //scatter plot
|
---|
123 | else {
|
---|
124 | ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y - 1]);
|
---|
125 | PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
|
---|
126 | pspv.ChartDoubleClick += ScatterPlotDoubleClick;
|
---|
127 | pspv.Content = scatterPlot;
|
---|
128 | pspv.Dock = DockStyle.Fill;
|
---|
129 | tableLayoutPanel.Controls.Add(pspv, x, y);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
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);
|
---|
141 |
|
---|
142 | MainFormManager.MainForm.ShowContent(scatterContent, typeof(SingleScatterPlotView)); // open in new tab
|
---|
143 | }
|
---|
144 |
|
---|
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
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | }
|
---|