Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14583 was 14583, checked in by pfleck, 7 years ago

#2709

  • Added histogram aggregation option.
  • Show all columns in data grid per default.
File size: 4.4 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.Linq;
24using HeuristicLab.Analysis;
25using HeuristicLab.MainForm;
26
27namespace HeuristicLab.DataPreprocessing.Views {
28  [View("Histogram View")]
29  [Content(typeof(HistogramContent), true)]
30  public partial class HistogramView : PreprocessingChartView {
31    public new HistogramContent Content {
32      get { return (HistogramContent)base.Content; }
33      set { base.Content = value; }
34    }
35
36    public HistogramView() {
37      InitializeComponent();
38      aggregationComboBox.DataSource = Enum.GetValues(typeof(DataRowVisualProperties.DataRowHistogramAggregation));
39      aggregationComboBox.SelectedItem = DataRowVisualProperties.DataRowHistogramAggregation.Overlapping;
40    }
41
42    protected override void OnContentChanged() {
43      base.OnContentChanged();
44      classifierComboBox.Items.Clear();
45      classifierComboBox.Items.Add("");
46
47      if (Content != null) {
48        foreach (string var in GetVariableNamesForGrouping(Content.PreprocessingData)) {
49          classifierComboBox.Items.Add(var);
50        }
51
52        classifierComboBox.SelectedItem = Content.GroupingVariableName;
53      }
54    }
55
56    protected override DataTable CreateDataTable(string variableName) {
57      var dataTable = new DataTable();
58
59      if (string.IsNullOrEmpty(Content.GroupingVariableName)) {
60        var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Histogram);
61        dataTable.Rows.Add(row);
62        return dataTable;
63      }
64
65      dataTable.VisualProperties.Title = variableName;
66
67      int variableIndex = Content.PreprocessingData.GetColumnIndex(variableName);
68      var variableValues = Content.PreprocessingData.GetValues<double>(variableIndex);
69      int groupVariableIndex = Content.PreprocessingData.GetColumnIndex(Content.GroupingVariableName);
70      var groupingValues = Enumerable.Empty<string>();
71
72      if (Content.PreprocessingData.VariableHasType<double>(groupVariableIndex)) {
73        groupingValues = Content.PreprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
74      } else if (Content.PreprocessingData.VariableHasType<string>(groupVariableIndex)) {
75        groupingValues = Content.PreprocessingData.GetValues<string>(groupVariableIndex);
76      } else if (Content.PreprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
77        groupingValues = Content.PreprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
78      }
79
80      var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
81
82      foreach (var group in groups) {
83        var classRow = new DataRow();
84        classRow.Name = group.Key;
85        classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
86        classRow.VisualProperties.Aggregation = (DataRowVisualProperties.DataRowHistogramAggregation)aggregationComboBox.SelectedItem;
87        classRow.Values.AddRange(group);
88        dataTable.Rows.Add(classRow);
89      }
90      return dataTable;
91    }
92
93
94    private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) {
95      Content.GroupingVariableName = classifierComboBox.SelectedItem.ToString();
96
97      // rebuild datatables
98      InitData();
99      GenerateLayout();
100    }
101
102    private void aggregationComboBox_SelectedIndexChanged(object sender, EventArgs e) {
103      foreach (var dt in dataTables.Values) {
104        foreach (var row in dt.Rows) {
105          row.VisualProperties.Aggregation = (DataRowVisualProperties.DataRowHistogramAggregation)aggregationComboBox.SelectedItem;
106        }
107      }
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.