Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 14521 was 14474, checked in by pfleck, 8 years ago

#2709

  • Improved legend description for grouped histogram and scatterplots.
  • Fixed initial size of points for scatterplots.
  • Added correlation calculation for scatterplots (not used yet).
File size: 3.6 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        foreach (var entry in valuesPerClass) {
68          var classRow = new DataRow(string.Format("{0} ({1})", classifierComboBox.SelectedItem, entry.Key));
69          classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
70          classRow.Values.AddRange(entry.Value);
71          dt.Rows.Add(classRow);
72        }
73      }
74      return dt;
75    }
76
77    public new HistogramContent Content {
78      get { return (HistogramContent)base.Content; }
79      set { base.Content = value; }
80    }
81
82    private void classifierComboBox_SelectedIndexChanged(object sender, EventArgs e) {
83      if (classifierComboBox.SelectedItem == null)
84        return;
85
86      if (classifierComboBox.SelectedIndex != 0) {
87        int columndIndex = Content.PreprocessingData.GetColumnIndex(classifierComboBox.SelectedItem.ToString());
88        Classification = Content.PreprocessingData.GetValues<double>(columndIndex).ToList();
89      } else {
90        Classification = null;
91      }
92
93      Content.ClassifierVariableIndex = classifierComboBox.SelectedIndex;
94
95      // rebuild datatables
96      InitData();
97      GenerateLayout();
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.