Free cookie consent management tool by TermsFeed Policy Generator

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

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

Chart view refactoring

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("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
39      // add variables to combo boxes
40      comboBoxXVariable.Items.Clear();
41      comboBoxYVariable.Items.Clear();
42      comboBoxXVariable.Items.AddRange(variables.ToArray());
43      comboBoxYVariable.Items.AddRange(variables.ToArray());
44
45      // use x and y variable from content
46      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null) {
47        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
48        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
49      } else {
50        if (variables.Count() >= 2) {
51          comboBoxXVariable.SelectedIndex = 0;
52          comboBoxYVariable.SelectedIndex = 1;
53          UpdateScatterPlot();
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        //get scatter plot with selected x and y variable
74        ScatterPlot scatterPlot = logic.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
75        scatterPlotView.Content = scatterPlot;
76
77        //save selected x and y variable in content
78        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
79        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
80      }
81    }
82
83  }
84
85 
86}
Note: See TracBrowser for help on using the repository browser.