Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs @ 14441

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

#2709 Copied plugins.

File size: 4.2 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 System.Windows.Forms;
26using HeuristicLab.Analysis;
27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29
30namespace HeuristicLab.DataPreprocessing.Views {
31
32  [View("Scatter Plot Single View")]
33  [Content(typeof(ScatterPlotContent), true)]
34  public partial class ScatterPlotSingleView : ItemView {
35
36    public new ScatterPlotContent Content {
37      get { return (ScatterPlotContent)base.Content; }
38      set { base.Content = value; }
39    }
40
41    public ScatterPlotSingleView() {
42      InitializeComponent();
43    }
44
45    public void InitData() {
46      IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames();
47
48      // add variables to combo boxes
49      comboBoxXVariable.Items.Clear();
50      comboBoxYVariable.Items.Clear();
51      comboBoxColor.Items.Clear();
52      comboBoxXVariable.Items.AddRange(variables.ToArray());
53      comboBoxYVariable.Items.AddRange(variables.ToArray());
54      comboBoxColor.Items.Add("-");
55      for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
56        if (Content.PreprocessingData.VariableHasType<double>(i)) {
57          double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
58          if (distinctValueCount <= 20)
59            comboBoxColor.Items.Add(Content.PreprocessingData.GetVariableName(i));
60        }
61      }
62
63      // use x and y variable from content
64      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null && Content.SelectedColorVariable != null) {
65        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
66        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
67        comboBoxColor.SelectedItem = Content.SelectedColorVariable;
68      } else {
69        if (variables.Count() >= 2) {
70          comboBoxXVariable.SelectedIndex = 0;
71          comboBoxYVariable.SelectedIndex = 1;
72          comboBoxColor.SelectedIndex = 0;
73          UpdateScatterPlot();
74        }
75      }
76    }
77
78    protected override void OnContentChanged() {
79      base.OnContentChanged();
80
81      comboBoxXVariable.Items.Clear();
82      comboBoxYVariable.Items.Clear();
83      comboBoxColor.Items.Clear();
84      if (Content != null) {
85        InitData();
86      }
87    }
88
89    private void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
90      UpdateScatterPlot();
91    }
92
93    private void UpdateScatterPlot() {
94      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxColor.SelectedItem != null) {
95        var xVariable = (string) comboBoxXVariable.SelectedItem;
96        var yVariable = (string) comboBoxYVariable.SelectedItem;
97        var colorVariable = (string) comboBoxColor.SelectedItem;
98
99        ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, colorVariable);
100
101        var vp = scatterPlot.VisualProperties;
102        vp.Title = string.Empty;
103        vp.XAxisTitle = xVariable;
104        vp.YAxisTitle = yVariable;
105
106
107        scatterPlotControl.Content = scatterPlot;
108
109        //save selected x and y variable in content
110        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
111        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
112        this.Content.SelectedColorVariable = (string)comboBoxColor.SelectedItem;
113      }
114    }
115  }
116}
Note: See TracBrowser for help on using the repository browser.