[14381] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15584] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14381] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[15242] | 24 | using System.Drawing;
|
---|
[14381] | 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Analysis;
|
---|
[15242] | 28 | using HeuristicLab.Analysis.Views;
|
---|
[14381] | 29 | using HeuristicLab.Collections;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
[15242] | 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[14381] | 33 |
|
---|
| 34 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 35 | [View("Preprocessing Chart View")]
|
---|
| 36 | [Content(typeof(PreprocessingChartContent), false)]
|
---|
| 37 | public partial class PreprocessingChartView : PreprocessingCheckedVariablesView {
|
---|
[15242] | 38 | protected Dictionary<string, DataTable> dataTables;
|
---|
| 39 | protected Dictionary<string, DataTableView> dataTableViews;
|
---|
[14381] | 40 |
|
---|
[15242] | 41 | public static readonly Color[] Colors = {
|
---|
| 42 | Color.FromArgb(59, 136, 239), Color.FromArgb(252, 177, 59), Color.FromArgb(226, 64, 10),
|
---|
| 43 | Color.FromArgb(5, 100, 146), Color.FromArgb(191, 191, 191), Color.FromArgb(26, 59, 105),
|
---|
| 44 | Color.FromArgb(255, 226, 126), Color.FromArgb(18, 156, 221), Color.FromArgb(202, 107, 75),
|
---|
| 45 | Color.FromArgb(0, 92, 219), Color.FromArgb(243, 210, 136), Color.FromArgb(80, 99, 129),
|
---|
| 46 | Color.FromArgb(241, 185, 168), Color.FromArgb(224, 131, 10), Color.FromArgb(120, 147, 190)
|
---|
| 47 | };
|
---|
[14381] | 48 |
|
---|
| 49 | public PreprocessingChartView() {
|
---|
| 50 | InitializeComponent();
|
---|
[15242] | 51 | dataTables = new Dictionary<string, DataTable>();
|
---|
| 52 | dataTableViews = new Dictionary<string, DataTableView>();
|
---|
| 53 | scrollPanel.HorizontalScroll.Visible = false;
|
---|
[14381] | 54 | }
|
---|
| 55 |
|
---|
| 56 | protected override void OnContentChanged() {
|
---|
| 57 | base.OnContentChanged();
|
---|
| 58 | if (Content != null) {
|
---|
| 59 | InitData();
|
---|
[15242] | 60 | GenerateLayout();
|
---|
[14381] | 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[15242] | 64 | protected virtual int GetNumberOfVisibleDataTables() {
|
---|
| 65 | return Content.VariableItemList.CheckedItems.Count();
|
---|
| 66 | }
|
---|
[14381] | 67 |
|
---|
[15242] | 68 | protected virtual IEnumerable<DataTableView> GetVisibleDataTables() {
|
---|
| 69 | foreach (var name in Content.VariableItemList.CheckedItems) {
|
---|
| 70 | if (!dataTableViews.ContainsKey(name.Value.Value))
|
---|
| 71 | dataTableViews.Add(name.Value.Value, new DataTableView() { Content = dataTables[name.Value.Value], ShowChartOnly = true });
|
---|
| 72 | yield return dataTableViews[name.Value.Value];
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
[14381] | 75 |
|
---|
[15242] | 76 | protected virtual DataTable CreateDataTable(string variableName) {
|
---|
| 77 | return null;
|
---|
| 78 | }
|
---|
[14381] | 79 |
|
---|
[15242] | 80 | protected virtual void InitData() {
|
---|
| 81 | dataTables.Clear();
|
---|
| 82 | dataTableViews.Clear();
|
---|
| 83 | foreach (var variable in Content.VariableItemList.Select(v => v.Value)) {
|
---|
| 84 | dataTables.Add(variable, CreateDataTable(variable));
|
---|
[14381] | 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
| 89 | base.CheckedItemsChanged(sender, checkedItems);
|
---|
| 90 |
|
---|
[15242] | 91 | GenerateLayout();
|
---|
[14381] | 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
| 95 | #region Add/Remove/Update Variable, Reset
|
---|
| 96 | protected override void AddVariable(string name) {
|
---|
| 97 | base.AddVariable(name);
|
---|
[15242] | 98 | dataTables.Add(name, CreateDataTable(name));
|
---|
[14381] | 99 |
|
---|
[15242] | 100 | GenerateLayout();
|
---|
[14381] | 101 | }
|
---|
| 102 |
|
---|
| 103 | // remove variable from data table and item list
|
---|
| 104 | protected override void RemoveVariable(string name) {
|
---|
| 105 | base.RemoveVariable(name);
|
---|
[15242] | 106 | dataTables.Remove(name);
|
---|
| 107 | dataTableViews.Remove(name);
|
---|
[14381] | 108 |
|
---|
[15242] | 109 | GenerateLayout();
|
---|
[14381] | 110 | }
|
---|
| 111 |
|
---|
| 112 | protected override void UpdateVariable(string name) {
|
---|
| 113 | base.UpdateVariable(name);
|
---|
[15242] | 114 | dataTables.Remove(name);
|
---|
| 115 | var newDataTable = CreateDataTable(name);
|
---|
| 116 | dataTables.Add(name, newDataTable);
|
---|
| 117 | dataTableViews[name].Content = newDataTable;
|
---|
| 118 | GenerateLayout();
|
---|
[14381] | 119 | }
|
---|
| 120 | protected override void ResetAllVariables() {
|
---|
| 121 | InitData();
|
---|
| 122 | }
|
---|
| 123 | #endregion
|
---|
| 124 |
|
---|
[15242] | 125 | protected override void CheckedChangedUpdate() {
|
---|
| 126 | GenerateLayout();
|
---|
[14381] | 127 | }
|
---|
| 128 |
|
---|
[15242] | 129 | #region Generate Layout
|
---|
| 130 | protected void GenerateLayout() {
|
---|
| 131 | if (SuppressCheckedChangedUpdate)
|
---|
| 132 | return;
|
---|
[14381] | 133 |
|
---|
[15242] | 134 | scrollPanel.SuspendRepaint();
|
---|
[14381] | 135 |
|
---|
[15242] | 136 | ClearTableLayout();
|
---|
[14381] | 137 |
|
---|
[15242] | 138 | int nrCharts = GetNumberOfVisibleDataTables();
|
---|
[14381] | 139 |
|
---|
[15242] | 140 | // Set columns and rows based on number of items
|
---|
| 141 | int columns = Math.Min(nrCharts, (int)columnsNumericUpDown.Value);
|
---|
| 142 | int rows = (int)Math.Ceiling((float)nrCharts / columns);
|
---|
[14381] | 143 |
|
---|
[15242] | 144 | tableLayoutPanel.ColumnCount = Math.Max(columns, 0);
|
---|
| 145 | tableLayoutPanel.RowCount = Math.Max(rows, 0);
|
---|
[14381] | 146 |
|
---|
[15242] | 147 | if (columns > 0 && rows > 0) {
|
---|
| 148 | var width = (splitContainer.Panel2.Width - SystemInformation.VerticalScrollBarWidth) / columns;
|
---|
| 149 | var height = width * 0.75f;
|
---|
[14381] | 150 |
|
---|
[15242] | 151 | using (var enumerator = GetVisibleDataTables().GetEnumerator()) {
|
---|
| 152 | for (int row = 0; row < rows; row++) {
|
---|
| 153 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, height));
|
---|
| 154 | for (int col = 0; col < columns; col++) {
|
---|
| 155 | if (row == 0) {
|
---|
| 156 | // Add a column-style only when creating the first row
|
---|
| 157 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, width));
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | if (enumerator.MoveNext())
|
---|
| 161 | AddDataTableToTableLayout(enumerator.Current, row, col);
|
---|
| 162 |
|
---|
| 163 | }
|
---|
| 164 | }
|
---|
[14381] | 165 | }
|
---|
[15242] | 166 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 0));
|
---|
[14381] | 167 | }
|
---|
[15242] | 168 |
|
---|
| 169 | scrollPanel.ResumeRepaint(true);
|
---|
[14381] | 170 | }
|
---|
| 171 |
|
---|
[15242] | 172 | private void AddDataTableToTableLayout(DataTableView dataTable, int row, int col) {
|
---|
[14381] | 173 | if (dataTable == null) {
|
---|
| 174 | // dummy panel for empty field
|
---|
[15242] | 175 | Panel p = new Panel { Dock = DockStyle.Fill };
|
---|
| 176 | tableLayoutPanel.Controls.Add(p, col, row);
|
---|
[14381] | 177 | } else {
|
---|
[15242] | 178 | dataTable.Dock = DockStyle.Fill;
|
---|
| 179 | tableLayoutPanel.Controls.Add(dataTable, col, row);
|
---|
[14381] | 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | protected void ClearTableLayout() {
|
---|
| 184 | //Clear out the existing controls
|
---|
| 185 | tableLayoutPanel.Controls.Clear();
|
---|
| 186 |
|
---|
| 187 | //Clear out the existing row and column styles
|
---|
| 188 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
| 189 | tableLayoutPanel.RowStyles.Clear();
|
---|
| 190 | }
|
---|
| 191 | //Remove horizontal scroll bar if visible
|
---|
| 192 | private void tableLayoutPanel_Layout(object sender, LayoutEventArgs e) {
|
---|
| 193 | if (tableLayoutPanel.HorizontalScroll.Visible) {
|
---|
| 194 | // Add padding on the right in order to accomodate the vertical scrollbar
|
---|
[15242] | 195 | tableLayoutPanel.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);
|
---|
[14381] | 196 | } else {
|
---|
| 197 | // Reset padding
|
---|
| 198 | tableLayoutPanel.Padding = new Padding(0);
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | #endregion
|
---|
| 202 |
|
---|
[15242] | 203 | private void columnsNumericUpDown_ValueChanged(object sender, System.EventArgs e) {
|
---|
| 204 | GenerateLayout();
|
---|
[14381] | 205 | }
|
---|
| 206 |
|
---|
[15242] | 207 | private void splitContainer_Panel2_Resize(object sender, EventArgs e) {
|
---|
| 208 | if (SuppressCheckedChangedUpdate)
|
---|
| 209 | return;
|
---|
| 210 |
|
---|
| 211 | scrollPanel.SuspendRepaint();
|
---|
| 212 |
|
---|
| 213 | if (tableLayoutPanel.ColumnCount > 0 && tableLayoutPanel.RowCount > 0) {
|
---|
| 214 | var width = (splitContainer.Panel2.Width - SystemInformation.VerticalScrollBarWidth) / tableLayoutPanel.ColumnCount;
|
---|
| 215 | var height = width * 0.75f;
|
---|
| 216 |
|
---|
| 217 | for (int i = 0; i < tableLayoutPanel.RowStyles.Count - 1; i++) {
|
---|
| 218 | tableLayoutPanel.RowStyles[i].Height = height;
|
---|
| 219 | }
|
---|
| 220 | for (int i = 0; i < tableLayoutPanel.ColumnStyles.Count; i++) {
|
---|
| 221 | tableLayoutPanel.ColumnStyles[i].Width = width;
|
---|
| 222 | }
|
---|
[14381] | 223 | }
|
---|
| 224 |
|
---|
[15242] | 225 | scrollPanel.ResumeRepaint(true);
|
---|
[14381] | 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|