Free cookie consent management tool by TermsFeed Policy Generator

source: branches/crossvalidation-2434/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs @ 15296

Last change on this file since 15296 was 14029, checked in by gkronber, 8 years ago

#2434: merged trunk changes r12934:14026 from trunk to branch

File size: 3.9 KB
RevLine 
[14029]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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;
[10882]23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.DataPreprocessing.Views {
30
[10987]31  [View("Scatter Plot Single View")]
[10952]32  [Content(typeof(ScatterPlotContent), true)]
[10987]33  public partial class ScatterPlotSingleView : ItemView {
[10882]34
35    public new ScatterPlotContent Content {
36      get { return (ScatterPlotContent)base.Content; }
37      set { base.Content = value; }
38    }
39
[14029]40    public ScatterPlotSingleView() {
[10998]41      InitializeComponent();
42    }
43
[10882]44    public void InitData() {
[10992]45      IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames();
[10972]46
47      // add variables to combo boxes
[10882]48      comboBoxXVariable.Items.Clear();
49      comboBoxYVariable.Items.Clear();
[14029]50      comboBoxColor.Items.Clear();
[10882]51      comboBoxXVariable.Items.AddRange(variables.ToArray());
52      comboBoxYVariable.Items.AddRange(variables.ToArray());
[14029]53      comboBoxColor.Items.Add("-");
54      for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
55        if (Content.PreprocessingData.VariableHasType<double>(i)) {
56          double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
57          if (distinctValueCount <= 20)
58            comboBoxColor.Items.Add(Content.PreprocessingData.GetVariableName(i));
59        }
60      }
[10882]61
[10952]62      // use x and y variable from content
[14029]63      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null && Content.SelectedColorVariable != null) {
[10952]64        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
65        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
[14029]66        comboBoxColor.SelectedItem = Content.SelectedColorVariable;
[10952]67      } else {
68        if (variables.Count() >= 2) {
69          comboBoxXVariable.SelectedIndex = 0;
70          comboBoxYVariable.SelectedIndex = 1;
[14029]71          comboBoxColor.SelectedIndex = 0;
[10952]72          UpdateScatterPlot();
73        }
[10882]74      }
75    }
76
77    protected override void OnContentChanged() {
78      base.OnContentChanged();
79      if (Content != null) {
80        InitData();
81      }
82    }
83
84    private void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
85      UpdateScatterPlot();
86    }
87
88    private void UpdateScatterPlot() {
[14029]89      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxColor.SelectedItem != null) {
[10972]90        //get scatter plot with selected x and y variable
[14029]91        ScatterPlot scatterPlot = Content.CreateScatterPlot(
92          (string)comboBoxXVariable.SelectedItem,
93          (string)comboBoxYVariable.SelectedItem,
94          (string)comboBoxColor.SelectedItem);
[10882]95        scatterPlotView.Content = scatterPlot;
[10952]96
97        //save selected x and y variable in content
98        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
99        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
[14029]100        this.Content.SelectedColorVariable = (string)comboBoxColor.SelectedItem;
[10882]101      }
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.