[14381] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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 |
|
---|
[14581] | 22 | using System;
|
---|
[14381] | 23 | using System.Collections.Generic;
|
---|
[14459] | 24 | using System.Drawing;
|
---|
[14381] | 25 | using System.Linq;
|
---|
| 26 | using System.Windows.Forms;
|
---|
| 27 | using HeuristicLab.Analysis;
|
---|
[14459] | 28 | using HeuristicLab.Analysis.Views;
|
---|
[14381] | 29 | using HeuristicLab.Collections;
|
---|
| 30 | using HeuristicLab.Data;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
[14459] | 32 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[14381] | 33 |
|
---|
| 34 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 35 | [View("Preprocessing Chart View")]
|
---|
| 36 | [Content(typeof(PreprocessingChartContent), false)]
|
---|
[14902] | 37 | public partial class PreprocessingChartView : PreprocessingCheckedVariablesView {
|
---|
[14459] | 38 | protected Dictionary<string, DataTable> dataTables;
|
---|
[14983] | 39 | protected Dictionary<string, DataTableView> dataTableViews;
|
---|
[14381] | 40 |
|
---|
[14975] | 41 | public static readonly Color[] Colors = {
|
---|
[14459] | 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();
|
---|
[14459] | 51 | dataTables = new Dictionary<string, DataTable>();
|
---|
[14983] | 52 | dataTableViews = new Dictionary<string, DataTableView>();
|
---|
[14381] | 53 | }
|
---|
| 54 |
|
---|
| 55 | protected override void OnContentChanged() {
|
---|
| 56 | base.OnContentChanged();
|
---|
| 57 | if (Content != null) {
|
---|
| 58 | InitData();
|
---|
[14459] | 59 | GenerateLayout();
|
---|
[14381] | 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[14459] | 63 | protected virtual int GetNumberOfVisibleDataTables() {
|
---|
[14511] | 64 | return Content.VariableItemList.CheckedItems.Count();
|
---|
[14459] | 65 | }
|
---|
[14381] | 66 |
|
---|
[14983] | 67 | protected virtual IEnumerable<DataTableView> GetVisibleDataTables() {
|
---|
[14459] | 68 | foreach (var name in Content.VariableItemList.CheckedItems) {
|
---|
[14983] | 69 | if (!dataTableViews.ContainsKey(name.Value.Value))
|
---|
| 70 | dataTableViews.Add(name.Value.Value, new DataTableView() { Content = dataTables[name.Value.Value], ShowName = false });
|
---|
| 71 | yield return dataTableViews[name.Value.Value];
|
---|
[14459] | 72 | }
|
---|
| 73 | }
|
---|
[14381] | 74 |
|
---|
[14459] | 75 | protected virtual DataTable CreateDataTable(string variableName) {
|
---|
| 76 | return null;
|
---|
| 77 | }
|
---|
[14381] | 78 |
|
---|
[14459] | 79 | protected virtual void InitData() {
|
---|
| 80 | dataTables.Clear();
|
---|
[14983] | 81 | dataTableViews.Clear();
|
---|
[14459] | 82 | foreach (var variable in Content.VariableItemList.Select(v => v.Value)) {
|
---|
| 83 | dataTables.Add(variable, CreateDataTable(variable));
|
---|
[14381] | 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
| 88 | base.CheckedItemsChanged(sender, checkedItems);
|
---|
| 89 |
|
---|
[14459] | 90 | GenerateLayout();
|
---|
[14381] | 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | #region Add/Remove/Update Variable, Reset
|
---|
| 95 | protected override void AddVariable(string name) {
|
---|
| 96 | base.AddVariable(name);
|
---|
[14459] | 97 | dataTables.Add(name, CreateDataTable(name));
|
---|
[14381] | 98 |
|
---|
[14459] | 99 | GenerateLayout();
|
---|
[14381] | 100 | }
|
---|
| 101 |
|
---|
| 102 | // remove variable from data table and item list
|
---|
| 103 | protected override void RemoveVariable(string name) {
|
---|
| 104 | base.RemoveVariable(name);
|
---|
[14459] | 105 | dataTables.Remove(name);
|
---|
[14983] | 106 | dataTableViews.Remove(name);
|
---|
[14381] | 107 |
|
---|
[14459] | 108 | GenerateLayout();
|
---|
[14381] | 109 | }
|
---|
| 110 |
|
---|
| 111 | protected override void UpdateVariable(string name) {
|
---|
| 112 | base.UpdateVariable(name);
|
---|
[14459] | 113 | dataTables.Remove(name);
|
---|
| 114 | var newDataTable = CreateDataTable(name);
|
---|
| 115 | dataTables.Add(name, newDataTable);
|
---|
[14983] | 116 | dataTableViews[name].Content = newDataTable;
|
---|
[14459] | 117 | GenerateLayout();
|
---|
[14381] | 118 | }
|
---|
| 119 | protected override void ResetAllVariables() {
|
---|
| 120 | InitData();
|
---|
| 121 | }
|
---|
| 122 | #endregion
|
---|
| 123 |
|
---|
[14511] | 124 | protected override void CheckedChangedUpdate() {
|
---|
| 125 | GenerateLayout();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[14459] | 128 | #region Generate Layout
|
---|
| 129 | protected void GenerateLayout() {
|
---|
[14996] | 130 | if (SuppressCheckedChangedUpdate)
|
---|
[14511] | 131 | return;
|
---|
| 132 |
|
---|
[14902] | 133 | scrollPanel.SuspendRepaint();
|
---|
[14459] | 134 |
|
---|
[14381] | 135 | ClearTableLayout();
|
---|
| 136 |
|
---|
[14459] | 137 | int nrCharts = GetNumberOfVisibleDataTables();
|
---|
[14381] | 138 |
|
---|
[14459] | 139 | // Set columns and rows based on number of items
|
---|
[14902] | 140 | int columns = Math.Min(nrCharts, (int)columnsNumericUpDown.Value);
|
---|
| 141 | int rows = (int)Math.Ceiling((float)nrCharts / columns);
|
---|
[14381] | 142 |
|
---|
| 143 | tableLayoutPanel.ColumnCount = columns;
|
---|
| 144 | tableLayoutPanel.RowCount = rows;
|
---|
| 145 |
|
---|
[14902] | 146 | var width = (splitContainer.Panel2.Width - SystemInformation.VerticalScrollBarWidth) / columns;
|
---|
| 147 | var height = width * 0.75f;
|
---|
| 148 |
|
---|
[14459] | 149 | using (var enumerator = GetVisibleDataTables().GetEnumerator()) {
|
---|
[14902] | 150 | for (int row = 0; row < rows; row++) {
|
---|
| 151 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, height));
|
---|
| 152 | for (int col = 0; col < columns; col++) {
|
---|
| 153 | if (row == 0) { // Add a column-style only when creating the first row
|
---|
| 154 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, width));
|
---|
[14459] | 155 | }
|
---|
| 156 |
|
---|
| 157 | if (enumerator.MoveNext())
|
---|
[14902] | 158 | AddDataTableToTableLayout(enumerator.Current, row, col);
|
---|
| 159 |
|
---|
[14381] | 160 | }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
[14902] | 163 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 0));
|
---|
[14459] | 164 |
|
---|
[14902] | 165 | scrollPanel.ResumeRepaint(true);
|
---|
[14381] | 166 | }
|
---|
[14459] | 167 |
|
---|
[14983] | 168 | private void AddDataTableToTableLayout(DataTableView dataTable, int row, int col) {
|
---|
[14381] | 169 | if (dataTable == null) {
|
---|
| 170 | // dummy panel for empty field
|
---|
[14459] | 171 | Panel p = new Panel { Dock = DockStyle.Fill };
|
---|
[14902] | 172 | tableLayoutPanel.Controls.Add(p, col, row);
|
---|
[14381] | 173 | } else {
|
---|
[14459] | 174 | dataTable.Dock = DockStyle.Fill;
|
---|
[14902] | 175 | tableLayoutPanel.Controls.Add(dataTable, col, row);
|
---|
[14381] | 176 | }
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | protected void ClearTableLayout() {
|
---|
| 180 | //Clear out the existing controls
|
---|
| 181 | tableLayoutPanel.Controls.Clear();
|
---|
| 182 |
|
---|
| 183 | //Clear out the existing row and column styles
|
---|
| 184 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
| 185 | tableLayoutPanel.RowStyles.Clear();
|
---|
| 186 | }
|
---|
| 187 | //Remove horizontal scroll bar if visible
|
---|
| 188 | private void tableLayoutPanel_Layout(object sender, LayoutEventArgs e) {
|
---|
| 189 | if (tableLayoutPanel.HorizontalScroll.Visible) {
|
---|
| 190 | // Add padding on the right in order to accomodate the vertical scrollbar
|
---|
[14902] | 191 | tableLayoutPanel.Padding = new Padding(0, 0, SystemInformation.VerticalScrollBarWidth, 0);
|
---|
[14381] | 192 | } else {
|
---|
| 193 | // Reset padding
|
---|
| 194 | tableLayoutPanel.Padding = new Padding(0);
|
---|
| 195 | }
|
---|
| 196 | }
|
---|
| 197 | #endregion
|
---|
[14902] | 198 |
|
---|
| 199 | private void columnsNumericUpDown_ValueChanged(object sender, System.EventArgs e) {
|
---|
| 200 | GenerateLayout();
|
---|
| 201 | }
|
---|
[14381] | 202 | }
|
---|
| 203 | }
|
---|