Changeset 10952 for branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/MultiScatterPlotView.cs
- Timestamp:
- 06/04/14 15:32:33 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/MultiScatterPlotView.cs
r10915 r10952 18 18 19 19 [View("Multi Scatter Plot View")] 20 [Content(typeof(ScatterPlotContent), true)]20 [Content(typeof(ScatterPlotContent), false)] 21 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; 22 28 23 29 private IChartLogic logic; … … 34 40 35 41 public void InitData() { 36 37 42 variables = new List<string>(logic.GetVariableNames()); 38 39 43 } 40 44 … … 45 49 InitData(); 46 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); 47 71 } 48 72 } … … 59 83 tableLayoutPanel.RowCount = variables.Count+1; 60 84 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)); 67 87 // set column and row layout 68 88 for (int x = 0; x < variables.Count; x++) 69 89 { 70 90 // 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)); 74 94 } 75 95 // fixed size 76 96 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)); 79 99 } 80 100 } 81 101 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 } 94 106 107 private void addChartsToTableLayoutPanel() { 95 108 //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++) { 98 110 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 102 113 if (x == y) { 103 114 PreprocessingDataTable dataTable = new PreprocessingDataTable(); … … 105 116 dataTable.Rows.Add(dataRow); 106 117 PreprocessingDataTableView pcv = new PreprocessingDataTableView(); 107 pcv. DoubleClick += tableLayoutElementDoubleClick;118 pcv.ChartDoubleClick += HistogramDoubleClick; 108 119 pcv.Content = dataTable; 109 120 tableLayoutPanel.Controls.Add(pcv, y, x); 110 121 } 111 122 //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]); 114 125 PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView(); 115 pspv. DoubleClick += tableLayoutElementDoubleClick;126 pspv.ChartDoubleClick += ScatterPlotDoubleClick; 116 127 pspv.Content = scatterPlot; 117 128 pspv.Dock = DockStyle.Fill; 118 tableLayoutPanel.Controls.Add(pspv, y, x);129 tableLayoutPanel.Controls.Add(pspv, x, y); 119 130 } 120 131 } … … 122 133 } 123 134 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); 125 141 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 } 138 144 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 140 185 } 141 186
Note: See TracChangeset
for help on using the changeset viewer.