[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2013 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 |
|
---|
[10717] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[10303] | 24 | using System.Windows.Forms;
|
---|
[10628] | 25 | using HeuristicLab.Analysis;
|
---|
[10717] | 26 | using HeuristicLab.Analysis.Views;
|
---|
[10628] | 27 | using HeuristicLab.Collections;
|
---|
| 28 | using HeuristicLab.Core;
|
---|
[10303] | 29 | using HeuristicLab.Core.Views;
|
---|
[10628] | 30 | using HeuristicLab.Data;
|
---|
[10803] | 31 | using HeuristicLab.DataPreprocessing.Implementations;
|
---|
[10303] | 32 | using HeuristicLab.MainForm;
|
---|
| 33 |
|
---|
| 34 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 35 |
|
---|
[10658] | 36 | [View("Preprocessing Chart View")]
|
---|
| 37 | [Content(typeof(PreprocessingChartContent), false)]
|
---|
| 38 | public partial class PreprocessingChartView : ItemView {
|
---|
[10377] | 39 |
|
---|
[10803] | 40 | private PreprocessingDataTable dataTable;
|
---|
| 41 | private List<PreprocessingDataTable> dataTablePerVariable;
|
---|
[10717] | 42 | private List<DataRow> dataRows;
|
---|
[10847] | 43 | private List<DataRow> selectedDataRows;
|
---|
[10717] | 44 |
|
---|
[10658] | 45 | protected DataRowVisualProperties.DataRowChartType chartType;
|
---|
| 46 | protected string chartTitle;
|
---|
[10867] | 47 | protected IChartLogic logic;
|
---|
[10628] | 48 |
|
---|
[10658] | 49 | private const string DEFAULT_CHART_TITLE = "Chart";
|
---|
| 50 |
|
---|
[10908] | 51 | public IEnumerable<double> Classification { get; set; }
|
---|
[10658] | 52 |
|
---|
| 53 | public PreprocessingChartView() {
|
---|
[10303] | 54 | InitializeComponent();
|
---|
[10658] | 55 | chartType = DataRowVisualProperties.DataRowChartType.Line;
|
---|
| 56 | chartTitle = DEFAULT_CHART_TITLE;
|
---|
[10303] | 57 | }
|
---|
| 58 |
|
---|
[10628] | 59 | private void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
|
---|
[10712] | 60 | foreach (IndexedItem<StringValue> item in checkedItems.Items) {
|
---|
[10628] | 61 | string variableName = item.Value.Value;
|
---|
[10847] | 62 |
|
---|
| 63 | //variable is displayed -> remove
|
---|
[10628] | 64 | if (VariableIsDisplayed(variableName)) {
|
---|
| 65 | dataTable.Rows.Remove(variableName);
|
---|
[10847] | 66 | dataTable.SelectedRows.Remove(variableName);
|
---|
[10804] | 67 | dataTablePerVariable.Remove(dataTablePerVariable.Find(x => (x.Name == variableName)));
|
---|
[10847] | 68 | //variable isnt't displayed -> add
|
---|
[10628] | 69 | } else {
|
---|
[10717] | 70 | DataRow row = GetDataRow(variableName);
|
---|
[10847] | 71 | DataRow selectedRow = GetSelectedDataRow(variableName);
|
---|
[10717] | 72 | dataTable.Rows.Add(row);
|
---|
[10803] | 73 | PreprocessingDataTable d = new PreprocessingDataTable(variableName);
|
---|
[10717] | 74 | d.Rows.Add(row);
|
---|
| 75 | dataTablePerVariable.Add(d);
|
---|
[10847] | 76 | if (selectedRow != null)
|
---|
| 77 | {
|
---|
| 78 | dataTable.SelectedRows.Add(selectedRow);
|
---|
| 79 | d.SelectedRows.Add(selectedRow);
|
---|
[10628] | 80 | }
|
---|
| 81 | }
|
---|
[10847] | 82 | }
|
---|
[10717] | 83 |
|
---|
[10908] | 84 | if (Content != null && !Content.AllInOneMode)
|
---|
[10717] | 85 | GenerateChart();
|
---|
| 86 |
|
---|
[10628] | 87 | }
|
---|
| 88 |
|
---|
[10717] | 89 | private bool VariableIsDisplayed(string name) {
|
---|
| 90 |
|
---|
[10628] | 91 | foreach (var item in dataTable.Rows) {
|
---|
| 92 | if (item.Name == name)
|
---|
| 93 | return true;
|
---|
| 94 | }
|
---|
| 95 | return false;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
[10573] | 98 | protected override void RegisterContentEvents() {
|
---|
| 99 | base.RegisterContentEvents();
|
---|
[10736] | 100 | Content.ChartLogic.Changed += PreprocessingData_Changed;
|
---|
[10847] | 101 | Content.ChartLogic.SelectionChanged += PreprocessingData_SelctionChanged;
|
---|
[10804] | 102 |
|
---|
[10573] | 103 | }
|
---|
| 104 |
|
---|
| 105 | protected override void DeregisterContentEvents() {
|
---|
| 106 | base.DeregisterContentEvents();
|
---|
[10736] | 107 | Content.ChartLogic.Changed -= PreprocessingData_Changed;
|
---|
[10847] | 108 | Content.ChartLogic.SelectionChanged -= PreprocessingData_SelctionChanged;
|
---|
[10573] | 109 | }
|
---|
| 110 |
|
---|
[10658] | 111 | public new PreprocessingChartContent Content {
|
---|
| 112 | get { return (PreprocessingChartContent)base.Content; }
|
---|
[10303] | 113 | set { base.Content = value; }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[10717] | 116 | private void InitData() {
|
---|
[10818] | 117 | if (Content.VariableItemList == null)
|
---|
| 118 | {
|
---|
| 119 | Content.VariableItemList = logic.CreateVariableItemList();
|
---|
| 120 | }
|
---|
| 121 | checkedItemList.Content = Content.VariableItemList;
|
---|
[10717] | 122 | dataRows = logic.CreateAllDataRows(chartType);
|
---|
| 123 |
|
---|
[10803] | 124 | dataTable = new PreprocessingDataTable(chartTitle);
|
---|
[10847] | 125 | dataTablePerVariable = new List<PreprocessingDataTable>();
|
---|
[10717] | 126 |
|
---|
[10847] | 127 | //add data rows to data tables according to checked item list
|
---|
[10818] | 128 | foreach (var checkedItem in Content.VariableItemList.CheckedItems)
|
---|
| 129 | {
|
---|
| 130 | string variableName = Content.VariableItemList[checkedItem.Index].Value;
|
---|
[10803] | 131 | PreprocessingDataTable d = new PreprocessingDataTable(variableName);
|
---|
[10717] | 132 | DataRow row = GetDataRow(variableName);
|
---|
[10804] | 133 |
|
---|
[10847] | 134 | //add row to data table
|
---|
| 135 | dataTable.Rows.Add(row);
|
---|
| 136 |
|
---|
| 137 | //add row to data table per variable
|
---|
[10717] | 138 | d.Rows.Add(row);
|
---|
| 139 | dataTablePerVariable.Add(d);
|
---|
[10847] | 140 | }
|
---|
[10803] | 141 |
|
---|
[10847] | 142 | UpdateSelection();
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | private void UpdateSelection() {
|
---|
| 146 |
|
---|
| 147 | //update data table selection
|
---|
| 148 | selectedDataRows = logic.CreateAllSelectedDataRows(chartType);
|
---|
| 149 | dataTable.SelectedRows.Clear();
|
---|
| 150 | dataTable.SelectedRows.AddRange(selectedDataRows);
|
---|
| 151 |
|
---|
| 152 | //update data table per variable selection
|
---|
| 153 | foreach (PreprocessingDataTable d in dataTablePerVariable) {
|
---|
| 154 | d.SelectedRows.Clear();
|
---|
| 155 | DataRow row = selectedDataRows.Find(x => x.Name == d.Name);
|
---|
| 156 | if (row != null)
|
---|
| 157 | d.SelectedRows.Add(row);
|
---|
[10717] | 158 | }
|
---|
[10847] | 159 |
|
---|
[10717] | 160 | }
|
---|
| 161 |
|
---|
[10847] | 162 | private DataRow GetSelectedDataRow(string variableName) {
|
---|
| 163 | foreach (DataRow row in selectedDataRows) {
|
---|
| 164 | if (row.Name == variableName)
|
---|
| 165 | return row;
|
---|
| 166 | }
|
---|
| 167 | return null;
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[10717] | 170 | private DataRow GetDataRow(string variableName) {
|
---|
| 171 | foreach (DataRow row in dataRows) {
|
---|
| 172 | if (row.Name == variableName)
|
---|
| 173 | return row;
|
---|
| 174 | }
|
---|
| 175 | return null;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[10303] | 178 | protected override void OnContentChanged() {
|
---|
| 179 | base.OnContentChanged();
|
---|
[10377] | 180 | if (Content != null) {
|
---|
[10658] | 181 | logic = Content.ChartLogic;
|
---|
[10804] | 182 | InitData();
|
---|
[10818] | 183 | Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged;
|
---|
[10804] | 184 | GenerateChart();
|
---|
[10377] | 185 | }
|
---|
[10303] | 186 | }
|
---|
[10377] | 187 |
|
---|
[10717] | 188 | // TODO : handle also other changed events
|
---|
[10628] | 189 | void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
|
---|
| 190 | switch (e.Type) {
|
---|
| 191 | case DataPreprocessingChangedEventType.DeleteColumn:
|
---|
[10741] | 192 | RemoveVariable(logic.GetVariableNameByIndex(e.Column));
|
---|
[10628] | 193 | break;
|
---|
| 194 | case DataPreprocessingChangedEventType.AddColumn:
|
---|
[10741] | 195 | AddVariable(logic.GetVariableNameByIndex(e.Column));
|
---|
[10628] | 196 | break;
|
---|
| 197 | case DataPreprocessingChangedEventType.ChangeColumn:
|
---|
| 198 | case DataPreprocessingChangedEventType.ChangeItem:
|
---|
[10736] | 199 | UpdateDataForVariable(logic.GetVariableNameByIndex(e.Column));
|
---|
[10628] | 200 | break;
|
---|
| 201 | case DataPreprocessingChangedEventType.DeleteRow:
|
---|
| 202 | case DataPreprocessingChangedEventType.AddRow:
|
---|
[10736] | 203 | case DataPreprocessingChangedEventType.Any:
|
---|
[10817] | 204 | default:
|
---|
[10847] | 205 | //TODO: test with transform
|
---|
[10736] | 206 | InitData();
|
---|
[10804] | 207 | GenerateChart();
|
---|
[10628] | 208 | break;
|
---|
[10382] | 209 | }
|
---|
[10377] | 210 | }
|
---|
| 211 |
|
---|
[10847] | 212 | private void PreprocessingData_SelctionChanged(object sender, EventArgs e) {
|
---|
| 213 | UpdateSelection();
|
---|
| 214 | }
|
---|
| 215 |
|
---|
[10717] | 216 | private void UpdateDataForVariable(string variableName) {
|
---|
| 217 | DataRow newRow = logic.CreateDataRow(variableName, chartType);
|
---|
| 218 | dataTable.Rows.Remove(variableName);
|
---|
| 219 | dataTable.Rows.Add(newRow);
|
---|
[10736] | 220 | DataTable dt = dataTablePerVariable.Find(x => x.Rows.Find(y => y.Name == variableName) != null);
|
---|
| 221 | if (dt != null) {
|
---|
| 222 | dt.Rows.Remove(variableName);
|
---|
| 223 | dt.Rows.Add(newRow);
|
---|
| 224 | }
|
---|
[10717] | 225 | }
|
---|
| 226 |
|
---|
[10628] | 227 | // add variable to data table and item list
|
---|
| 228 | private void AddVariable(string name) {
|
---|
[10741] | 229 | DataRow row = logic.CreateDataRow(name, chartType);
|
---|
| 230 | dataTable.Rows.Add(row);
|
---|
[10803] | 231 | PreprocessingDataTable d = new PreprocessingDataTable(name);
|
---|
[10741] | 232 | d.Rows.Add(row);
|
---|
| 233 | dataTablePerVariable.Add(d);
|
---|
[10818] | 234 | Content.VariableItemList.Add(new StringValue(name));
|
---|
| 235 | if (!Content.AllInOneMode)
|
---|
[10741] | 236 | GenerateChart();
|
---|
[10628] | 237 | }
|
---|
[10377] | 238 |
|
---|
[10628] | 239 | // remove variable from data table and item list
|
---|
| 240 | private void RemoveVariable(string name) {
|
---|
| 241 | dataTable.Rows.Remove(name);
|
---|
[10741] | 242 | dataTablePerVariable.Remove(dataTablePerVariable.Find(x => (x.Name == name)));
|
---|
[10382] | 243 |
|
---|
[10628] | 244 | StringValue stringValue = FindVariableItemList(name);
|
---|
| 245 | if (stringValue != null)
|
---|
[10818] | 246 | Content.VariableItemList.Remove(stringValue);
|
---|
| 247 | if (!Content.AllInOneMode)
|
---|
[10741] | 248 | GenerateChart();
|
---|
[10377] | 249 | }
|
---|
[10628] | 250 |
|
---|
| 251 | private StringValue FindVariableItemList(string name) {
|
---|
[10818] | 252 | foreach (StringValue stringValue in Content.VariableItemList)
|
---|
| 253 | {
|
---|
[10628] | 254 | if (stringValue.Value == name)
|
---|
| 255 | return stringValue;
|
---|
| 256 | }
|
---|
| 257 | return null;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
[10717] | 260 | protected void GenerateChart() {
|
---|
| 261 |
|
---|
[10804] | 262 | ClearTableLayout();
|
---|
[10736] | 263 |
|
---|
[10818] | 264 | if (Content.AllInOneMode)
|
---|
| 265 | {
|
---|
[10736] | 266 | GenerateSingleChartLayout();
|
---|
| 267 | } else
|
---|
| 268 | GenerateMultiChartLayout();
|
---|
| 269 | }
|
---|
| 270 |
|
---|
| 271 | private void ClearTableLayout() {
|
---|
[10717] | 272 | //Clear out the existing controls
|
---|
| 273 | tableLayoutPanel.Controls.Clear();
|
---|
| 274 |
|
---|
| 275 | //Clear out the existing row and column styles
|
---|
| 276 | tableLayoutPanel.ColumnStyles.Clear();
|
---|
| 277 | tableLayoutPanel.RowStyles.Clear();
|
---|
| 278 | tableLayoutPanel.AutoScroll = false;
|
---|
[10736] | 279 | tableLayoutPanel.AutoScroll = true;
|
---|
[10804] | 280 | }
|
---|
[10717] | 281 |
|
---|
| 282 | private void GenerateSingleChartLayout() {
|
---|
| 283 | tableLayoutPanel.ColumnCount = 1;
|
---|
| 284 | tableLayoutPanel.RowCount = 1;
|
---|
| 285 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
|
---|
| 286 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
|
---|
| 287 | tableLayoutPanel.Controls.Add(dataTableView, 0, 0);
|
---|
| 288 | dataTableView.Content = dataTable;
|
---|
| 289 | }
|
---|
| 290 |
|
---|
| 291 | private void GenerateMultiChartLayout() {
|
---|
| 292 | int checkedItemsCnt = 0;
|
---|
[10818] | 293 | foreach (var item in Content.VariableItemList.CheckedItems)
|
---|
[10717] | 294 | checkedItemsCnt++;
|
---|
| 295 |
|
---|
| 296 | int rows = 0;
|
---|
| 297 | int columns = 0;
|
---|
| 298 |
|
---|
| 299 | // set columns and rows based on number of items
|
---|
| 300 | if (checkedItemsCnt <= 2)
|
---|
| 301 | columns = 1;
|
---|
| 302 | else if (checkedItemsCnt <= 6)
|
---|
| 303 | columns = 2;
|
---|
| 304 | else
|
---|
| 305 | columns = 3;
|
---|
| 306 |
|
---|
| 307 | if (columns == 3)
|
---|
[10804] | 308 | rows = (checkedItemsCnt + 2) / columns;
|
---|
| 309 | else if (columns == 2)
|
---|
[10717] | 310 | rows = (checkedItemsCnt + 1) / columns;
|
---|
| 311 | else
|
---|
| 312 | rows = checkedItemsCnt / columns;
|
---|
| 313 |
|
---|
| 314 | //Now we will generate the table, setting up the row and column counts first
|
---|
| 315 | tableLayoutPanel.ColumnCount = columns;
|
---|
| 316 | tableLayoutPanel.RowCount = rows;
|
---|
| 317 |
|
---|
[10803] | 318 | List<PreprocessingDataTable>.Enumerator enumerator = dataTablePerVariable.GetEnumerator();
|
---|
[10717] | 319 | for (int x = 0; x < columns; x++) {
|
---|
[10804] | 320 |
|
---|
| 321 | if (rows <= 3)
|
---|
[10717] | 322 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columns));
|
---|
| 323 | else
|
---|
| 324 | //scrollbar is shown if there are more than 3 rows -> remove scroll bar width from total width
|
---|
| 325 | tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - System.Windows.Forms.SystemInformation.VerticalScrollBarWidth) / columns));
|
---|
| 326 | for (int y = 0; y < rows; y++) {
|
---|
| 327 | //Add a row only when creating the first column
|
---|
| 328 | if (x == 0) {
|
---|
| 329 | // fixed chart size when there are more than 3 tables
|
---|
| 330 | if (rows > 3)
|
---|
| 331 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 300));
|
---|
| 332 | else
|
---|
| 333 | tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100 / rows));
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[10771] | 336 | PreprocessingDataTableView dataView = new PreprocessingDataTableView();
|
---|
[10908] | 337 | dataView.Classification = Classification;
|
---|
[10717] | 338 | enumerator.MoveNext();
|
---|
[10803] | 339 | PreprocessingDataTable d = enumerator.Current;
|
---|
[10717] | 340 | if (d == null) {
|
---|
| 341 | // dummy panel for empty field
|
---|
| 342 | Panel p = new Panel();
|
---|
| 343 | p.Dock = DockStyle.Fill;
|
---|
| 344 | tableLayoutPanel.Controls.Add(p, y, x);
|
---|
[10804] | 345 | } else {
|
---|
[10717] | 346 | dataView.Content = d;
|
---|
| 347 | dataView.Dock = DockStyle.Fill;
|
---|
| 348 | tableLayoutPanel.Controls.Add(dataView, y, x);
|
---|
| 349 | }
|
---|
| 350 | }
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 | //Remove horizontal scroll bar if visible
|
---|
| 355 | private void tableLayoutPanel_Layout(object sender, LayoutEventArgs e) {
|
---|
| 356 | if (tableLayoutPanel.HorizontalScroll.Visible) {
|
---|
| 357 | // Add padding on the right in order to accomodate the vertical scrollbar
|
---|
| 358 | int vWidth = SystemInformation.VerticalScrollBarWidth;
|
---|
| 359 | tableLayoutPanel.Padding = new Padding(0, 0, vWidth, 0);
|
---|
| 360 | } else {
|
---|
| 361 | // Reset padding
|
---|
| 362 | tableLayoutPanel.Padding = new Padding(0);
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | private void radioButton1_CheckedChanged(object sender, EventArgs e) {
|
---|
[10818] | 367 | if (Content.AllInOneMode == false)
|
---|
| 368 | Content.AllInOneMode = true;
|
---|
[10717] | 369 | else
|
---|
[10818] | 370 | Content.AllInOneMode = false;
|
---|
[10717] | 371 | GenerateChart();
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 |
|
---|
[10303] | 375 | }
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 |
|
---|