Free cookie consent management tool by TermsFeed Policy Generator

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

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

Refactored scatter plot

File size: 2.6 KB
RevLine 
[10882]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
[10987]20  [View("Scatter Plot Single View")]
[10952]21  [Content(typeof(ScatterPlotContent), true)]
[10987]22  public partial class ScatterPlotSingleView : ItemView {
[10882]23
[10987]24    public ScatterPlotSingleView() {
[10882]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
[10987]35      IEnumerable<string> variables = Content.GetVariableNames();
[10972]36
37      // add variables to combo boxes
[10882]38      comboBoxXVariable.Items.Clear();
39      comboBoxYVariable.Items.Clear();
40      comboBoxXVariable.Items.AddRange(variables.ToArray());
41      comboBoxYVariable.Items.AddRange(variables.ToArray());
42
[10952]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        }
[10882]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) {
[10972]70        //get scatter plot with selected x and y variable
[10987]71        ScatterPlot scatterPlot = Content.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
[10882]72        scatterPlotView.Content = scatterPlot;
[10952]73
74        //save selected x and y variable in content
75        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
76        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
[10882]77      }
78    }
79
80  }
81
82 
83}
Note: See TracBrowser for help on using the repository browser.