Free cookie consent management tool by TermsFeed Policy Generator

source: branches/irace/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs @ 11423

Last change on this file since 11423 was 10998, checked in by psteiner, 10 years ago

Formatting Sourcecode Views

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Windows.Forms;
5using HeuristicLab.Analysis;
6using HeuristicLab.Core.Views;
7using HeuristicLab.MainForm;
8
9namespace HeuristicLab.DataPreprocessing.Views {
10
11  [View("Scatter Plot Single View")]
12  [Content(typeof(ScatterPlotContent), true)]
13  public partial class ScatterPlotSingleView : ItemView {
14
15    public new ScatterPlotContent Content {
16      get { return (ScatterPlotContent)base.Content; }
17      set { base.Content = value; }
18    }
19
20    public ScatterPlotSingleView()
21    {
22      InitializeComponent();
23    }
24
25    public void InitData() {
26
27      IEnumerable<string> variables = Content.PreprocessingData.GetDoubleVariableNames();
28
29      // add variables to combo boxes
30      comboBoxXVariable.Items.Clear();
31      comboBoxYVariable.Items.Clear();
32      comboBoxXVariable.Items.AddRange(variables.ToArray());
33      comboBoxYVariable.Items.AddRange(variables.ToArray());
34
35      // use x and y variable from content
36      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null) {
37        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
38        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
39      } else {
40        if (variables.Count() >= 2) {
41          comboBoxXVariable.SelectedIndex = 0;
42          comboBoxYVariable.SelectedIndex = 1;
43          UpdateScatterPlot();
44
45        }
46      }
47    }
48
49    protected override void OnContentChanged() {
50      base.OnContentChanged();
51      if (Content != null) {
52        InitData();
53      }
54    }
55
56    private void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
57      UpdateScatterPlot();
58    }
59
60    private void UpdateScatterPlot() {
61      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null) {
62        //get scatter plot with selected x and y variable
63        ScatterPlot scatterPlot = Content.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
64        scatterPlotView.Content = scatterPlot;
65
66        //save selected x and y variable in content
67        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
68        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
69      }
70    }
71
72  }
73
74
75}
Note: See TracBrowser for help on using the repository browser.