[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)]
|
---|
[14725] | 37 | public partial class PreprocessingChartView : PreprocessingCheckedVariablesView {
|
---|
[14459] | 38 | protected Dictionary<string, DataTable> dataTables;
|
---|
| 39 | protected Dictionary<string, DataTableControl> dataTableControls;
|
---|
[14381] | 40 |
|
---|
| 41 | private const int FIXED_CHART_SIZE = 300;
|
---|
| 42 | private const int MAX_TABLE_AUTO_SIZE_ROWS = 3;
|
---|
| 43 |
|
---|
[14459] | 44 | protected static readonly Color[] Colors = {
|
---|
| 45 | Color.FromArgb(59, 136, 239), Color.FromArgb(252, 177, 59), Color.FromArgb(226, 64, 10),
|
---|
| 46 | Color.FromArgb(5, 100, 146), Color.FromArgb(191, 191, 191), Color.FromArgb(26, 59, 105),
|
---|
| 47 | Color.FromArgb(255, 226, 126), Color.FromArgb(18, 156, 221), Color.FromArgb(202, 107, 75),
|
---|
| 48 | Color.FromArgb(0, 92, 219), Color.FromArgb(243, 210, 136), Color.FromArgb(80, 99, 129),
|
---|
| 49 | Color.FromArgb(241, 185, 168), Color.FromArgb(224, 131, 10), Color.FromArgb(120, 147, 190)
|
---|
| 50 | };
|
---|
[14381] | 51 |
|
---|
| 52 |
|
---|
| 53 | public PreprocessingChartView() {
|
---|
| 54 | InitializeComponent();
|
---|
[14459] | 55 | dataTables = new Dictionary<string, DataTable>();
|
---|
[14581] | 56 | dataTableControls = new Dictionary<string, DataTableControl>();
|
---|
[14381] | 57 | }
|
---|
| 58 |
|
---|
| 59 | protected override void OnContentChanged() {
|
---|
| 60 | base.OnContentChanged();
|
---|
| 61 | if (Content != null) {
|
---|
| 62 | InitData();
|
---|
[14459] | 63 | GenerateLayout();
|
---|
[14381] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[14459] | 67 | protected virtual int GetNumberOfVisibleDataTables() {
|
---|
[14511] | 68 | return Content.VariableItemList.CheckedItems.Count();
|
---|
[14459] | 69 | }
|
---|
[14381] | 70 |
|
---|
[14459] | 71 | protected virtual IEnumerable<DataTableControl> GetVisibleDataTables() {
|
---|
| 72 | foreach (var name in Content.VariableItemList.CheckedItems) {
|
---|
| 73 | if (!dataTableControls.ContainsKey(name.Value.Value))
|
---|
| 74 | dataTableControls.Add(name.Value.Value, new DataTableControl() { Content = dataTables[name.Value.Value] });
|
---|
| 75 | yield return dataTableControls[name.Value.Value];
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
[14381] | 78 |
|
---|
[14459] | 79 | protected virtual DataTable CreateDataTable(string variableName) {
|
---|
| 80 | return null;
|
---|
| 81 | }
|
---|
[14381] | 82 |
|
---|
[14459] | 83 | protected virtual void InitData() {
|
---|
| 84 | dataTables.Clear();
|
---|
| 85 | dataTableControls.Clear();
|
---|
| 86 | foreach (var variable in Content.VariableItemList.Select(v => v.Value)) {
|
---|
| 87 | dataTables.Add(variable, CreateDataTable(variable));
|
---|
[14381] | 88 | }
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
| 92 | base.CheckedItemsChanged(sender, checkedItems);
|
---|
| 93 |
|
---|
| 94 | foreach (IndexedItem<StringValue> item in checkedItems.Items) {
|
---|
| 95 | string variableName = item.Value.Value;
|
---|
| 96 |
|
---|
[14384] | 97 | if (!IsVariableChecked(variableName)) {
|
---|
[14418] | 98 | // not checked -> remove
|
---|
[14459] | 99 | //dataTableView.SetRowEnabled(variableName, false);
|
---|
| 100 | //dataTablePerVariable.Remove(dataTablePerVariable.Find(x => (x.Name == variableName)));
|
---|
[14381] | 101 | } else {
|
---|
[14418] | 102 | // checked -> add
|
---|
[14459] | 103 | //DataRow row = GetDataRow(variableName);
|
---|
| 104 | //dataTableView.SetRowEnabled(variableName, true);
|
---|
[14381] | 105 |
|
---|
[14459] | 106 | //var pdt = new DataTable(variableName);
|
---|
| 107 | //pdt.VisualProperties.Title = string.Empty;
|
---|
| 108 | //pdt.Rows.Add(row);
|
---|
[14381] | 109 | // dataTablePerVariable does not contain unchecked variables => reduce insert position by number of uncheckt variables to correct the index
|
---|
[14459] | 110 | //int uncheckedUntilVariable = checkedItemList.Content.TakeWhile(x => x.Value != variableName).Count(x => !checkedItemList.Content.ItemChecked(x));
|
---|
| 111 | //dataTables.Insert(item.Index - uncheckedUntilVariable, pdt);
|
---|
[14381] | 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | // update chart if not in all in one mode
|
---|
[14459] | 116 | //if (Content != null && !Content.AllInOneMode)
|
---|
| 117 | //GenerateChart();??
|
---|
| 118 | GenerateLayout();
|
---|
[14381] | 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | #region Add/Remove/Update Variable, Reset
|
---|
| 123 | protected override void AddVariable(string name) {
|
---|
| 124 | base.AddVariable(name);
|
---|
[14459] | 125 | dataTables.Add(name, CreateDataTable(name));
|
---|
[14381] | 126 |
|
---|
[14459] | 127 | GenerateLayout();
|
---|
[14381] | 128 | }
|
---|
| 129 |
|
---|
| 130 | // remove variable from data table and item list
|
---|
| 131 | protected override void RemoveVariable(string name) {
|
---|
| 132 | base.RemoveVariable(name);
|
---|
[14459] | 133 | dataTables.Remove(name);
|
---|
| 134 | dataTableControls.Remove(name);
|
---|
[14381] | 135 |
|
---|
[14459] | 136 | GenerateLayout();
|
---|
[14381] | 137 | }
|
---|
| 138 |
|
---|
| 139 | protected override void UpdateVariable(string name) {
|
---|
| 140 | base.UpdateVariable(name);
|
---|
[14459] | 141 | dataTables.Remove(name);
|
---|
| 142 | var newDataTable = CreateDataTable(name);
|
---|
| 143 | dataTables.Add(name, newDataTable);
|
---|
| 144 | dataTableControls[name].Content = newDataTable;
|
---|
| 145 | GenerateLayout();
|
---|
[14381] | 146 | }
|
---|
| 147 | protected override void ResetAllVariables() {
|
---|
| 148 | InitData();
|
---|
| 149 | }
|
---|
| 150 | #endregion
|
---|
| 151 |
|
---|
[14511] | 152 | protected override void CheckedChangedUpdate() {
|
---|
| 153 | GenerateLayout();
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[14459] | 156 | #region Generate Layout
|
---|
| 157 | protected void GenerateLayout() {
|
---|
[14511] | 158 | if (suppressCheckedChangedUpdate)
|
---|
| 159 | return;
|
---|
| 160 |
|
---|
[14459] | 161 | tableLayoutPanel.SuspendRepaint();
|
---|
| 162 |
|
---|
[14381] | 163 | ClearTableLayout();
|
---|
| 164 |
|
---|
[14459] | 165 | int nrCharts = GetNumberOfVisibleDataTables();
|
---|
[14381] | 166 |
|
---|
[14459] | 167 | // Set columns and rows based on number of items
|
---|
| 168 | int columns = GetNrOfMultiChartColumns(nrCharts);
|
---|
| 169 | int rows = GetNrOfMultiChartRows(nrCharts, columns);
|
---|
[14381] | 170 |
|
---|
| 171 | tableLayoutPanel.ColumnCount = columns;
|
---|
| 172 | tableLayoutPanel.RowCount = rows;
|
---|
| 173 |
|
---|
[14459] | 174 | using (var enumerator = GetVisibleDataTables().GetEnumerator()) {
|
---|
| 175 | for (int x = 0; x < columns; x++) {
|
---|
| 176 | var columnStyle = rows <= MAX_TABLE_AUTO_SIZE_ROWS
|
---|
| 177 | ? new ColumnStyle(SizeType.Percent, 100 / columns)
|
---|
| 178 | : new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - SystemInformation.VerticalScrollBarWidth) / columns);
|
---|
| 179 | tableLayoutPanel.ColumnStyles.Add(columnStyle);
|
---|
[14381] | 180 |
|
---|
[14459] | 181 | for (int y = 0; y < rows; y++) {
|
---|
| 182 | // Add a row only when creating the first column
|
---|
| 183 | if (x == 0) {
|
---|
| 184 | var rowStyle = rows > MAX_TABLE_AUTO_SIZE_ROWS
|
---|
| 185 | ? new RowStyle(SizeType.Absolute, FIXED_CHART_SIZE)
|
---|
| 186 | : new RowStyle(SizeType.Percent, 100 / rows);
|
---|
| 187 | tableLayoutPanel.RowStyles.Add(rowStyle);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | if (enumerator.MoveNext())
|
---|
| 191 | AddDataTableToTableLayout(enumerator.Current, x, y);
|
---|
[14381] | 192 | }
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
[14459] | 195 |
|
---|
| 196 | tableLayoutPanel.ResumeRepaint(true);
|
---|
[14381] | 197 | }
|
---|
[14459] | 198 |
|
---|
[14381] | 199 | private int GetNrOfMultiChartColumns(int itemCount) {
|
---|
| 200 | int columns = 0;
|
---|
| 201 | if (itemCount <= 2)
|
---|
| 202 | columns = 1;
|
---|
| 203 | else if (itemCount <= 6)
|
---|
| 204 | columns = 2;
|
---|
| 205 | else
|
---|
| 206 | columns = 3;
|
---|
| 207 | return columns;
|
---|
| 208 | }
|
---|
| 209 | private int GetNrOfMultiChartRows(int itemCount, int columns) {
|
---|
| 210 | int rows = 0;
|
---|
| 211 | if (columns == 3)
|
---|
| 212 | rows = (itemCount + 2) / columns;
|
---|
| 213 | else if (columns == 2)
|
---|
| 214 | rows = (itemCount + 1) / columns;
|
---|
| 215 | else
|
---|
| 216 | rows = itemCount / columns;
|
---|
| 217 | return rows;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[14459] | 220 | private void AddDataTableToTableLayout(DataTableControl dataTable, int x, int y) {
|
---|
| 221 | //dataView.Classification = Classification;
|
---|
| 222 | //dataView.IsDetailedChartViewEnabled = IsDetailedChartViewEnabled;
|
---|
[14381] | 223 |
|
---|
| 224 | if (dataTable == null) {
|
---|
| 225 | // dummy panel for empty field
|
---|
[14459] | 226 | Panel p = new Panel { Dock = DockStyle.Fill };
|
---|
[14381] | 227 | tableLayoutPanel.Controls.Add(p, y, x);
|
---|
| 228 | } else {
|
---|
[14459] | 229 | dataTable.Dock = DockStyle.Fill;
|
---|
| 230 | tableLayoutPanel.Controls.Add(dataTable, y, x);
|
---|
[14381] | 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | protected void ClearTableLayout() {
|
---|
| 235 | //Clear out the existing controls
|
---|
| 236 | tableLayoutPanel.Controls.Clear();
|
---|
| 237 |
|
---|
| 238 | //Clear out the existing row and column styles
|
---|
| 239 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
| 240 | tableLayoutPanel.RowStyles.Clear();
|
---|
[14459] | 241 |
|
---|
| 242 | tableLayoutPanel.Width = 0;
|
---|
| 243 | tableLayoutPanel.Height = 0;
|
---|
| 244 |
|
---|
[14381] | 245 | tableLayoutPanel.AutoScroll = false;
|
---|
| 246 | tableLayoutPanel.AutoScroll = true;
|
---|
| 247 | }
|
---|
| 248 | //Remove horizontal scroll bar if visible
|
---|
| 249 | private void tableLayoutPanel_Layout(object sender, LayoutEventArgs e) {
|
---|
| 250 | if (tableLayoutPanel.HorizontalScroll.Visible) {
|
---|
| 251 | // Add padding on the right in order to accomodate the vertical scrollbar
|
---|
| 252 | int vWidth = SystemInformation.VerticalScrollBarWidth;
|
---|
| 253 | tableLayoutPanel.Padding = new Padding(0, 0, vWidth, 0);
|
---|
| 254 | } else {
|
---|
| 255 | // Reset padding
|
---|
| 256 | tableLayoutPanel.Padding = new Padding(0);
|
---|
| 257 | }
|
---|
| 258 | }
|
---|
| 259 | #endregion
|
---|
| 260 | }
|
---|
| 261 | }
|
---|