Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/SingleScatterPlotView.cs @ 10952

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

Completed scatter plot view

File size: 2.5 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("Single Scatter Plot View")]
21  [Content(typeof(ScatterPlotContent), true)]
22  public partial class SingleScatterPlotView : ItemView {
23
24    private IChartLogic logic;
25
26    public SingleScatterPlotView() {
27      InitializeComponent();
28    }
29
30    public new ScatterPlotContent Content {
31      get { return (ScatterPlotContent)base.Content; }
32      set { base.Content = value; }
33    }
34
35    public void InitData() {
36
37      IEnumerable<string> variables = logic.GetVariableNames();
38      comboBoxXVariable.Items.Clear();
39      comboBoxYVariable.Items.Clear();
40
41      comboBoxXVariable.Items.AddRange(variables.ToArray());
42      comboBoxYVariable.Items.AddRange(variables.ToArray());
43
44      // use x and y variable from content
45      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null) {
46        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
47        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
48      } else {
49        if (variables.Count() >= 2) {
50          comboBoxXVariable.SelectedIndex = 0;
51          comboBoxYVariable.SelectedIndex = 1;
52          UpdateScatterPlot();
53
54        }
55      }
56
57    }
58
59    protected override void OnContentChanged() {
60      base.OnContentChanged();
61      if (Content != null) {
62        logic = Content.ChartLogic;
63        InitData();
64      }
65    }
66
67    private void comboBox_SelectedIndexChanged(object sender, EventArgs e) {
68      UpdateScatterPlot();
69    }
70
71    private void UpdateScatterPlot() {
72      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null) {
73        ScatterPlot scatterPlot = logic.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
74        scatterPlotView.Content = scatterPlot;
75
76        //save selected x and y variable in content
77        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
78        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
79      }
80    }
81
82  }
83
84 
85}
Note: See TracBrowser for help on using the repository browser.