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

Last change on this file since 10987 was 10987, checked in by aesterer, 8 years ago

Refactored scatter plot

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