source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HistogramView.cs @ 14467

Last change on this file since 14467 was 14459, checked in by pfleck, 4 years ago

#2709

  • Removed the PreprocessingDataTable and PreprocessingDataTableView and use dhe HL DatatTableControl instead.
  • Moved and refactored some code of PreprocessingChart and moved unnecessary code from base classes to actual derivative classes.
File size: 3.9 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.DataPreprocessing.Views {
29
30  [View("Histogram View")]
31  [Content(typeof(HistogramContent), true)]
32  public partial class HistogramView : PreprocessingChartView {
33
34    public List<double> Classification { get; set; }
35    public bool IsDetailedChartViewEnabled { get; set; }
36
37    public HistogramView() {
38      InitializeComponent();
39    }
40
41    protected override void OnContentChanged() {
42      base.OnContentChanged();
43      if (Content != null) {
44        classifierComboBox.Items.Clear();
45        classifierComboBox.Items.Add("None");
46
47        foreach (string var in Content.GetVariableNamesForHistogramClassification()) {
48          classifierComboBox.Items.Add(var);
49        }
50
51        if (classifierComboBox.SelectedItem == null && Content.ClassifierVariableIndex < classifierComboBox.Items.Count) {
52          classifierComboBox.SelectedIndex = Content.ClassifierVariableIndex;
53        }
54      }
55    }
56
57    protected override DataTable CreateDataTable(string variableName) {
58      var dt = new DataTable();
59      var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram);
60      if (Classification == null) {
61        dt.Rows.Add(row);
62      } else {
63        dt.VisualProperties.Title = variableName;
64        //var valuesPerClass = row.Values.Zip(Classification, (value, @class) => new { value, @class })
65        //                        .GroupBy(x => x.@class)
66        //                        .ToDictionary(x => x.Key, x => x.Select(v => v.value));
67        var valuesPerClass = row.Values.Select((i, index) => new { i, j = Classification.ToList()[index] })
68                                       .GroupBy((x) => x.j)
69                                       .ToDictionary(x => x.Key, x => x.Select(v => v.i)
70                                       .ToList());
71        foreach (var entry in valuesPerClass) {
72          var classRow = new DataRow(entry.Key.ToString());
73          classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
74          classRow.Values.AddRange(entry.Value);
75          dt.Rows.Add(classRow);
76        }
77      }
78      return dt;
79    }
80
81    public new HistogramContent Content {
82      get { return (HistogramContent)base.Content; }
83      set { base.Content = value; }
84    }
85
86    private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) {
87      if (classifierComboBox.SelectedItem == null)
88        return;
89
90      if (classifierComboBox.SelectedIndex != 0) {
91        int columndIndex = Content.PreprocessingData.GetColumnIndex(classifierComboBox.SelectedItem.ToString());
92        Classification = Content.PreprocessingData.GetValues<double>(columndIndex).ToList();
93      } else {
94        Classification = null;
95      }
96
97      Content.ClassifierVariableIndex = classifierComboBox.SelectedIndex;
98
99      // rebuild datatables
100      InitData();
101      GenerateLayout();
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.