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